/**
 * Minified by jsDelivr using Terser v5.37.0.
 * Original file: /npm/htmx-ext-ws@2.0.2/ws.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
!function(){var e;function t(t){return null!=e.getInternalData(t).webSocket}function n(t){if(!e.bodyContains(t)){var n=e.getInternalData(t);return!!n.webSocket&&(n.webSocket.close(),!0)}return!1}function r(e){var t=new WebSocket(e,[]);return t.binaryType=htmx.config.wsBinaryType,t}function s(t,n){var r=[];return(e.hasAttribute(t,n)||e.hasAttribute(t,"hx-ws"))&&r.push(t),t.querySelectorAll("["+n+"], [data-"+n+"], [data-hx-ws], [hx-ws]").forEach((function(e){r.push(e)})),r}function i(e,t){if(e)for(var n=0;n<e.length;n++)t(e[n])}htmx.defineExtension("ws",{init:function(t){e=t,htmx.createWebSocket||(htmx.createWebSocket=r),htmx.config.wsReconnectDelay||(htmx.config.wsReconnectDelay="full-jitter")},onEvent:function(r,a){var o=a.target||a.detail.elt;switch(r){case"htmx:beforeCleanupElement":var c=e.getInternalData(o);return void(c.webSocket&&c.webSocket.close());case"htmx:beforeProcessNode":i(s(o,"ws-connect"),(function(t){!function(t){if(!e.bodyContains(t))return;var r=e.getAttributeValue(t,"ws-connect");if(null==r||""===r){var s=function(t){var n=e.getAttributeValue(t,"hx-ws");if(n)for(var r=n.trim().split(/\s+/),s=0;s<r.length;s++){var i=r[s].split(/:(.+)/);if("connect"===i[0])return i[1]}}(t);if(null==s)return;r=s}if(0===r.indexOf("/")){var i=location.hostname+(location.port?":"+location.port:"");"https:"===location.protocol?r="wss://"+i+r:"http:"===location.protocol&&(r="ws://"+i+r)}var a=function(t,r){var s={socket:null,messageQueue:[],retryCount:0,events:{},addEventListener:function(e,t){this.socket&&this.socket.addEventListener(e,t),this.events[e]||(this.events[e]=[]),this.events[e].push(t)},sendImmediately:function(t,n){this.socket||e.triggerErrorEvent(),n&&!e.triggerEvent(n,"htmx:wsBeforeSend",{message:t,socketWrapper:this.publicInterface})||(this.socket.send(t),n&&e.triggerEvent(n,"htmx:wsAfterSend",{message:t,socketWrapper:this.publicInterface}))},send:function(e,t){this.socket.readyState!==this.socket.OPEN?this.messageQueue.push({message:e,sendElt:t}):this.sendImmediately(e,t)},handleQueuedMessages:function(){for(;this.messageQueue.length>0;){var e=this.messageQueue[0];if(this.socket.readyState!==this.socket.OPEN)break;this.sendImmediately(e.message,e.sendElt),this.messageQueue.shift()}},init:function(){this.socket&&this.socket.readyState===this.socket.OPEN&&this.socket.close();var i=r();e.triggerEvent(t,"htmx:wsConnecting",{event:{type:"connecting"}}),this.socket=i,i.onopen=function(n){s.retryCount=0,e.triggerEvent(t,"htmx:wsOpen",{event:n,socketWrapper:s.publicInterface}),s.handleQueuedMessages()},i.onclose=function(r){if(!n(t)&&[1006,1012,1013].indexOf(r.code)>=0){var i=function(e){var t=htmx.config.wsReconnectDelay;if("function"==typeof t)return t(e);if("full-jitter"===t){var n=Math.min(e,6);return 1e3*Math.pow(2,n)*Math.random()}logError('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"')}(s.retryCount);setTimeout((function(){s.retryCount+=1,s.init()}),i)}e.triggerEvent(t,"htmx:wsClose",{event:r,socketWrapper:s.publicInterface})},i.onerror=function(r){e.triggerErrorEvent(t,"htmx:wsError",{error:r,socketWrapper:s}),n(t)};var a=this.events;Object.keys(a).forEach((function(e){a[e].forEach((function(t){i.addEventListener(e,t)}))}))},close:function(){this.socket.close()}};return s.init(),s.publicInterface={send:s.send.bind(s),sendImmediately:s.sendImmediately.bind(s),queue:s.messageQueue},s}(t,(function(){return htmx.createWebSocket(r)}));a.addEventListener("message",(function(r){if(!n(t)){var s=r.data;if(e.triggerEvent(t,"htmx:wsBeforeMessage",{message:s,socketWrapper:a.publicInterface})){e.withExtensions(t,(function(e){s=e.transformResponse(s,null,t)}));var i=e.makeSettleInfo(t),o=e.makeFragment(s);if(o.children.length)for(var c=Array.from(o.children),u=0;u<c.length;u++)e.oobSwap(e.getAttributeValue(c[u],"hx-swap-oob")||"true",c[u],i);e.settleImmediately(i.tasks),e.triggerEvent(t,"htmx:wsAfterMessage",{message:s,socketWrapper:a.publicInterface})}}})),e.getInternalData(t).webSocket=a}(t)})),i(s(o,"ws-send"),(function(r){!function(r){var s=e.getAttributeValue(r,"hx-ws");if(s&&"send"!==s)return;i=e.getClosestMatch(r,t),a=r,o=e.getInternalData(a),e.getTriggerSpecs(a).forEach((function(t){e.addTriggerHandler(a,t,o,(function(t,r){if(!n(i)){var s=e.getInternalData(i).webSocket,o=e.getHeaders(a,e.getTarget(a)),c=e.getInputValues(a,"post"),u=c.errors,f=Object.assign({},c.values),l=e.getExpressionVars(a),h=e.mergeObjects(f,l),g={parameters:e.filterValues(h,a),unfilteredParameters:h,headers:o,errors:u,triggeringEvent:r,messageBody:void 0,socketWrapper:s.publicInterface};if(e.triggerEvent(t,"htmx:wsConfigSend",g))if(u&&u.length>0)e.triggerEvent(t,"htmx:validation:halted",u);else{var d=g.messageBody;if(void 0===d){var m=Object.assign({},g.parameters);g.headers&&(m.HEADERS=o),d=JSON.stringify(m)}s.send(d,t),r&&e.shouldCancel(r,t)&&r.preventDefault()}}}))}));var i,a,o}(r)}))}}})}();
//# sourceMappingURL=/sm/51e93377ac8a662f5ee4a01cb1c4bf20efa7f8b093c520d0255f9798bdd43224.map