UNPKG

node-red-contrib-uibuilder

Version:

Easily create data-driven web UI's for Node-RED. Single- & Multi-page. Multiple UI's. Work with existing web development workflows or mix and match with no-code/low-code features.

1 lines 122 kB
var Ut=Object.create;var Ee=Object.defineProperty;var Mt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Bt=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty;var Ke=s=>{throw TypeError(s)};var Ht=(s,e,t)=>e in s?Ee(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Xe=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var qt=(s,e)=>{for(var t in e)Ee(s,t,{get:e[t],enumerable:!0})},jt=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Dt(e))!Pt.call(s,r)&&r!==t&&Ee(s,r,{get:()=>e[r],enumerable:!(i=Mt(e,r))||i.enumerable});return s};var Qe=(s,e,t)=>(t=s!=null?Ut(Bt(s)):{},jt(e||!s||!s.__esModule?Ee(t,"default",{value:s,enumerable:!0}):t,s));var h=(s,e,t)=>Ht(s,typeof e!="symbol"?e+"":e,t),Ze=(s,e,t)=>e.has(s)||Ke("Cannot "+t);var p=(s,e,t)=>(Ze(s,e,"read from private field"),t?t.call(s):e.get(s)),v=(s,e,t)=>e.has(s)?Ke("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),_=(s,e,t,i)=>(Ze(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t);var Ce=(s,e,t,i)=>({set _(r){_(s,e,r,t)},get _(){return p(s,e,i)}});var a,Ft=(a=class{constructor(e,t,i){h(this,"version","7.2.0-src");h(this,"sanitiseExtraTags",["uib-var"]);h(this,"sanitiseExtraAttribs",["variable","report","undefined"]);h(this,"ui_md_plugins");if(e)a.win=e;else throw new Error("Ui:constructor. Current environment does not include `window`, UI functions cannot be used.");a.doc=a.win.document,t?a.log=t:a.log=function(){return function(){}},i?this.syntaxHighlight=i:this.syntaxHighlight=function(){},a.win.markdownit&&(a.mdOpts={html:!0,xhtmlOut:!1,linkify:!0,_highlight:!0,_strict:!1,_view:"html",langPrefix:"language-",highlight:function(r,n){if(n&&window.hljs&&window.hljs.getLanguage(n))try{return'<pre class="">\n <code class="hljs border">'.concat(window.hljs.highlight(r,{language:n,ignoreIllegals:!0}).value,"</code></pre>")}finally{}return'<pre class="hljs border"><code>'.concat(a.md.utils.escapeHtml(r).trim(),"</code></pre>")}},a.md=a.win.markdownit(a.mdOpts))}_markDownIt(){if(a.win.markdownit&&(!this.ui_md_plugins&&a.win.uibuilder&&a.win.uibuilder.ui_md_plugins&&(this.ui_md_plugins=a.win.uibuilder.ui_md_plugins),a.mdOpts={html:!0,xhtmlOut:!1,linkify:!0,_highlight:!0,_strict:!1,_view:"html",langPrefix:"language-",highlight:function(e,t){if(window.hljs)if(t&&window.hljs.getLanguage(t))try{return'<pre><code class="hljs border language-'.concat(t,'" data-language="').concat(t,'" title="Source language: \'').concat(t,"'\">").concat(window.hljs.highlight(e,{language:t,ignoreIllegals:!0}).value,"</code></pre>")}finally{}else try{let i=window.hljs.highlightAuto(e);return'<pre><code class="hljs border language-'.concat(i.language,'" data-language="').concat(i.language,'" title="Source language estimated by HighlightJS: \'').concat(i.language,"'\">").concat(i.value,"</code></pre>")}finally{}return'<pre><code class="border">'.concat(a.md.utils.escapeHtml(e).trim(),"</code></pre>")}},a.md=a.win.markdownit(a.mdOpts),this.ui_md_plugins)){if(!Array.isArray(this.ui_md_plugins)){a.log("error","Ui:_markDownIt:plugins","Could not load plugins, ui_md_plugins is not an array")();return}this.ui_md_plugins.forEach(e=>{if(typeof e=="string")a.md.use(a.win[e]);else{let t=Object.keys(e)[0];a.md.use(a.win[t],e[t])}})}}_showNotification(e){e.topic&&!e.title&&(e.title=e.topic),e.title||(e.title="uibuilder notification"),e.payload&&!e.body&&(e.body=e.payload),e.body||(e.body=" No message given.");try{let t=new Notification(e.title,e);return new Promise((i,r)=>{t.addEventListener("close",n=>{n.currentTarget.userAction="close",i(n)}),t.addEventListener("click",n=>{n.currentTarget.userAction="click",i(n)}),t.addEventListener("error",n=>{n.currentTarget.userAction="error",r(n)})})}catch{return Promise.reject(new Error("Browser refused to create a Notification"))}}_uiAdd(e,t){a.log("trace","Ui:_uiManager:add","Starting _uiAdd")(),e.components.forEach((i,r)=>{a.log("trace","Ui:_uiAdd:components-forEach:".concat(r),"Component to add: ",i)();let n;switch(i.type){case"html":{i.ns="html",n=a.doc.createElement("div");break}case"svg":{i.ns="svg",n=a.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{i.ns="dom",n=a.doc.createElement(i.type);break}}!i.slot&&e.payload&&(i.slot=e.payload),this._uiComposeComponent(n,i);let o;i.parentEl?o=i.parentEl:e.parentEl?o=e.parentEl:i.parent?o=a.doc.querySelector(i.parent):e.parent&&(o=a.doc.querySelector(e.parent)),o||(a.log("info","Ui:_uiAdd","No parent found, adding to body")(),o=a.doc.querySelector("body")),i.position&&i.position==="first"?o.insertBefore(n,o.firstChild):i.position&&Number.isInteger(Number(i.position))?o.insertBefore(n,o.children[i.position]):o.appendChild(n),i.components&&this._uiExtendEl(n,i.components,i.ns)})}_uiComposeComponent(e,t){t.attributes&&Object.keys(t.attributes).forEach(i=>{i==="class"&&Array.isArray(t.attributes[i])&&t.attributes[i].join(" "),a.log("trace","_uiComposeComponent:attributes-forEach","Attribute: '".concat(i,"', value: '").concat(t.attributes[i],"'"))(),i==="value"&&(e.value=t.attributes[i]),i.startsWith("xlink:")?e.setAttributeNS("http://www.w3.org/1999/xlink",i,t.attributes[i]):e.setAttribute(i,t.attributes[i])}),t.id&&e.setAttribute("id",t.id),t.type==="svg"&&(e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/svg"),e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink")),t.events&&Object.keys(t.events).forEach(i=>{i.toLowerCase==="onclick"&&(i="click");try{e.addEventListener(i,r=>{new Function("evt","".concat(t.events[i],"(evt)"))(r)})}catch(r){a.log("error","Ui:_uiComposeComponent","Add event '".concat(i,"' for element '").concat(t.type,"': Cannot add event handler. ").concat(r.message))()}}),t.properties&&Object.keys(t.properties).forEach(i=>{e[i]=t.properties[i],["value","checked"].includes(i)&&(e.dispatchEvent(new Event("input")),e.dispatchEvent(new Event("change")))}),t.slot&&this.replaceSlot(e,t.slot),t.slotMarkdown&&this.replaceSlotMarkdown(e,t)}_uiExtendEl(e,t,i=""){t.forEach((r,n)=>{a.log("trace","Ui:_uiExtendEl:components-forEach:".concat(n),r)();let o;r.ns=i,r.ns==="html"?(o=e,this.replaceSlot(e,r.slot)):r.ns==="svg"?(o=a.doc.createElementNS("http://www.w3.org/2000/svg",r.type),this._uiComposeComponent(o,r),e.appendChild(o)):(o=a.doc.createElement(r.type==="html"?"div":r.type),this._uiComposeComponent(o,r),e.appendChild(o)),r.components&&this._uiExtendEl(o,r.components,r.ns)})}_uiLoad(e){e.components&&(Array.isArray(e.components)||(e.components=[e.components]),e.components.forEach(async t=>{Promise.resolve().then(()=>Qe(Xe(t)))})),e.srcScripts&&(Array.isArray(e.srcScripts)||(e.srcScripts=[e.srcScripts]),e.srcScripts.forEach(t=>{this.loadScriptSrc(t)})),e.txtScripts&&(Array.isArray(e.txtScripts)||(e.txtScripts=[e.txtScripts]),this.loadScriptTxt(e.txtScripts.join("\n"))),e.srcStyles&&(Array.isArray(e.srcStyles)||(e.srcStyles=[e.srcStyles]),e.srcStyles.forEach(t=>{this.loadStyleSrc(t)})),e.txtStyles&&(Array.isArray(e.txtStyles)||(e.txtStyles=[e.txtStyles]),this.loadStyleTxt(e.txtStyles.join("\n")))}_uiManager(e){e._ui&&(Array.isArray(e._ui)||(e._ui=[e._ui]),e._ui.forEach((t,i)=>{if(t.mode&&!t.method&&(t.method=t.mode),!t.method){a.log("error","Ui:_uiManager","No method defined for msg._ui[".concat(i,"]. Ignoring. "),t)();return}switch(t.payload=e.payload,t.topic=e.topic,t.method){case"add":{this._uiAdd(t,!1);break}case"remove":{this._uiRemove(t,!1);break}case"removeAll":{this._uiRemove(t,!0);break}case"replace":{this._uiReplace(t);break}case"update":{this._uiUpdate(t);break}case"load":{this._uiLoad(t);break}case"reload":{this._uiReload();break}case"notify":{this.showDialog("notify",t,e);break}case"alert":{this.showDialog("alert",t,e);break}default:{a.log("error","Ui:_uiManager","Invalid msg._ui[".concat(i,"].method (").concat(t.method,"). Ignoring"))();break}}}))}_uiReload(){a.log("trace","Ui:uiManager:reload","reloading")(),location.reload()}_uiRemove(e,t=!1){e.components.forEach(i=>{let r;t!==!0?r=[a.doc.querySelector(i)]:r=a.doc.querySelectorAll(i),r.forEach(n=>{try{n.remove()}catch(o){a.log("trace","Ui:_uiRemove","Could not remove. ".concat(o.message))()}})})}_uiReplace(e){a.log("trace","Ui:_uiReplace","Starting")(),e.components.forEach((t,i)=>{a.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Component to replace: ",t)();let r;if(t.id?r=a.doc.getElementById(t.id):t.selector||t.select?r=a.doc.querySelector(t.selector):t.name?r=a.doc.querySelector('[name="'.concat(t.name,'"]')):t.type&&(r=a.doc.querySelector(t.type)),a.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Element to replace: ",r)(),r==null){a.log("trace","Ui:_uiReplace:components-forEach:".concat(i,":noReplace"),"Cannot find the DOM element. Adding instead.",t)(),this._uiAdd({components:[t]},!1);return}let n;switch(t.type){case"html":{t.ns="html",n=a.doc.createElement("div");break}case"svg":{t.ns="svg",n=a.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{t.ns="dom",n=a.doc.createElement(t.type);break}}this._uiComposeComponent(n,t),r.replaceWith(n),t.components&&this._uiExtendEl(n,t.components,t.ns)})}_uiUpdate(e){a.log("trace","UI:_uiUpdate:update","Starting _uiUpdate",e)(),e.components||(e.components=[Object.assign({},e)]),e.components.forEach((t,i)=>{a.log("trace","_uiUpdate:components-forEach","Start loop #".concat(i),t)();let r;if(t.parentEl?r=t.parentEl:t.id?r=a.doc.querySelectorAll("#".concat(t.id)):t.selector||t.select?r=a.doc.querySelectorAll(t.selector):t.name?r=a.doc.querySelectorAll('[name="'.concat(t.name,'"]')):t.type&&(r=a.doc.querySelectorAll(t.type)),r===void 0||r.length<1){a.log("warn","Ui:_uiManager:update","Cannot find the DOM element. Ignoring.",t)();return}a.log("trace","_uiUpdate:components-forEach","Element(s) to update. Count: ".concat(r.length),r)(),!t.slot&&t.payload&&(t.slot=t.payload),r.forEach((n,o)=>{if(a.log("trace","_uiUpdate:components-forEach","Updating element #".concat(o),n)(),this._uiComposeComponent(n,t),t.components){a.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component"),t,n)();let c={_ui:[]};t.components.forEach((u,d)=>{let f=u.method||t.method||e.method;u.method&&delete u.method,Array.isArray(u)||(u=[u]),a.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component #").concat(d),u)(),c._ui.push({method:f,parentEl:n,components:u})}),a.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component new manager"),c)(),this._uiManager(c)}})})}$(e,t,i){if(i||(i=a.doc),t||(t="el"),!i||!i.nodeType)return a.log(1,"Uib:$","Invalid context element. Must be a valid HTML element.",i)(),null;let r=i.querySelector(e);if(!r||!r.nodeType)return a.log(1,"Uib:$","No element found or element is not an HTML element for CSS selector ".concat(e))(),null;if(r.nodeName==="TEMPLATE"&&(r=r.content.firstElementChild,!r))return a.log(0,"Uib:$","Template selected for CSS selector ".concat(e," but it is empty"))(),null;let n;try{switch(t.toLowerCase()){case"text":{n=r.innerText;break}case"html":{n=r.innerHTML;break}case"attr":case"attributes":{n={};for(let o of r.attributes)n[o.name]=o.value;break}default:{n=r;break}}}catch(o){n=r,a.log(1,"Uib:$",'Could not process output type "'.concat(t,'" for CSS selector ').concat(e,", returned the DOM element. ").concat(o.message),o)()}return n}$$(e,t){return t||(t=a.doc),!t||!t.nodeType?(a.log(1,"Uib:$$","Invalid context element. Must be a valid HTML element.",t)(),null):Array.from(t.querySelectorAll(e))}addClass(e,t){Array.isArray(e)||(e=[e]),t&&t.classList.add(...e)}applyTemplate(e,t,i){var u;i||(i={}),i.onlyOnce||(i.onlyOnce=!1),i.mode||(i.mode="insert");let r=a.doc.getElementById(e);if(!r||r.tagName!=="TEMPLATE"){a.log("error","Ui:applyTemplate","Source must be a <template>. id='".concat(e,"'"))();return}let n=a.doc.getElementById(t);if(!n){a.log("error","Ui:applyTemplate","Target not found: id='".concat(t,"'"))();return}let o=(u=n.innerHTML)!=null?u:"";o&&i.mode==="replace"&&a.log("warn","Ui:applyTemplate","Target element is not empty, content is replaced. id='".concat(t,"'"))();let c;if(i.onceOnly===!0?c=a.doc.adoptNode(r.content):c=a.doc.importNode(r.content,!0),c){if(i.attributes){let d=c.firstElementChild;Object.keys(i.attributes).forEach(f=>{d.setAttribute(f,i.attributes[f])})}if(i.mode==="insert")n.appendChild(c);else if(i.mode==="replace")n.innerHTML="",n.appendChild(c);else if(i.mode==="wrap"&&(n.innerHTML="",n.appendChild(c),o)){let d=n.getElementsByTagName("slot");d.length>0&&(d[0].innerHTML=o)}}else a.log("warn","Ui:applyTemplate","No valid content found in template")()}convertMarkdown(e){if(!e)return"";if(!a.win.markdownit)return e;a.md||this._markDownIt();try{return a.md.render(e.trim())}catch(t){return a.log(0,"uibuilder:convertMarkdown","Could not render Markdown. ".concat(t.message),t)(),'<p class="border error">Could not render Markdown<p>'}}async include(e,t){if(!fetch)return a.log(0,"Ui:include","Current environment does not include `fetch`, skipping.")(),"Current environment does not include `fetch`, skipping.";if(!e)return a.log(0,"Ui:include","url parameter must be provided, skipping.")(),"url parameter must be provided, skipping.";if(!t||!t.id)return a.log(0,"Ui:include","uiOptions parameter MUST be provided and must contain at least an `id` property, skipping.")(),"uiOptions parameter MUST be provided and must contain at least an `id` property, skipping.";let i;try{i=await fetch(e)}catch(d){return a.log(0,"Ui:include","Fetch of file '".concat(e,"' failed. "),d.message)(),d.message}if(!i.ok)return a.log(0,"Ui:include","Fetch of file '".concat(e,"' failed. Status='").concat(i.statusText,"'"))(),i.statusText;let r=await i.headers.get("content-type"),n=null;r&&(r.includes("text/html")?n="html":r.includes("application/json")?n="json":r.includes("multipart/form-data")?n="form":r.includes("image/")?n="image":r.includes("video/")?n="video":r.includes("application/pdf")?n="pdf":r.includes("text/plain")&&(n="text"));let o="",c="Include successful",u;switch(n){case"html":{u=await i.text(),o=u;break}case"json":{u=await i.json(),o='<pre class="syntax-highlight">',o+=this.syntaxHighlight(u),o+="</pre>";break}case"form":{u=await i.formData(),o='<pre class="syntax-highlight">',o+=this.syntaxHighlight(u),o+="</pre>";break}case"image":{u=await i.blob(),o='<img src="'.concat(URL.createObjectURL(u),'">'),a.win.DOMPurify&&(c="Include successful. BUT DOMPurify loaded which may block its use.",a.log("warn","Ui:include:image",c)());break}case"video":{u=await i.blob(),o='<video controls autoplay><source src="'.concat(URL.createObjectURL(u),'"></video>'),a.win.DOMPurify&&(c="Include successful. BUT DOMPurify loaded which may block its use.",a.log("warn","Ui:include:video",c)());break}case"pdf":case"text":default:{u=await i.blob(),o='<iframe style="resize:both;width:inherit;height:inherit;" src="'.concat(URL.createObjectURL(u),'">'),a.win.DOMPurify&&(c="Include successful. BUT DOMPurify loaded which may block its use.",a.log("warn","Ui:include:".concat(n),c)());break}}return t.type="div",t.slot=o,t.parent||(t.parent="body"),t.attributes||(t.attributes={class:"included"}),this._uiReplace({components:[t]}),a.log("trace","Ui:include:".concat(n),c)(),c}loadScriptSrc(e){let t=a.doc.createElement("script");t.src=e,t.async=!1,a.doc.head.appendChild(t)}loadScriptTxt(e){let t=a.doc.createElement("script");t.async=!1,t.textContent=e,a.doc.head.appendChild(t)}loadStyleSrc(e){let t=a.doc.createElement("link");t.href=e,t.rel="stylesheet",t.type="text/css",a.doc.head.appendChild(t)}loadStyleTxt(e){let t=a.doc.createElement("style");t.textContent=e,a.doc.head.appendChild(t)}loadui(e){if(!fetch){a.log(0,"Ui:loadui","Current environment does not include `fetch`, skipping.")();return}if(!e){a.log(0,"Ui:loadui","url parameter must be provided, skipping.")();return}fetch(e).then(t=>{if(t.ok===!1)throw new Error("Could not load '".concat(e,"'. Status ").concat(t.status,", Error: ").concat(t.statusText));a.log("trace","Ui:loadui:then1","Loaded '".concat(e,"'. Status ").concat(t.status,", ").concat(t.statusText))();let i=t.headers.get("content-type");if(!i||!i.includes("application/json"))throw new TypeError("Fetch '".concat(e,"' did not return JSON, ignoring"));return t.json()}).then(t=>t!==void 0?(a.log("trace","Ui:loadui:then2","Parsed JSON successfully obtained")(),this._uiManager({_ui:t}),!0):!1).catch(t=>{a.log("warn","Ui:loadui:catch","Error. ",t)()})}moveElement(e){let{sourceSelector:t,targetSelector:i,moveType:r,position:n}=e;if(!document.querySelector(t)){a.log(0,"Ui:moveElement","Source element not found")();return}if(!document.querySelector(i)){a.log(0,"Ui:moveElement","Target element not found")();return}}nodeGet(e,t){let i={id:e.id===""?void 0:e.id,name:e.name,children:e.childNodes.length,type:e.nodeName,attributes:void 0,isUserInput:!!e.validity,userInput:e.validity?{value:e.value,validity:void 0,willValidate:e.willValidate,valueAsDate:e.valueAsDate,valueAsNumber:e.valueAsNumber,type:e.type}:void 0};if(["UL","OL"].includes(e.nodeName)){let r=a.doc.querySelectorAll("".concat(t," li"));r&&(i.list={entries:r.length})}if(e.nodeName==="DL"){let r=a.doc.querySelectorAll("".concat(t," dt"));r&&(i.list={entries:r.length})}if(e.nodeName==="TABLE"){let r=a.doc.querySelectorAll("".concat(t," > tbody > tr")),n=a.doc.querySelectorAll("".concat(t," > thead > tr")),o=a.doc.querySelectorAll("".concat(t," > tbody > tr:last-child > *"));(r||n||o)&&(i.table={headRows:n?n.length:0,bodyRows:r?r.length:0,columns:o?o.length:0})}if(e.nodeName!=="#text"&&e.attributes&&e.attributes.length>0){i.attributes={};for(let r of e.attributes)r.name!=="id"&&(i.attributes[r.name]=e.attributes[r.name].value),r.name==="class"&&(i.classes=Array.from(e.classList))}e.nodeName==="#text"&&(i.text=e.textContent),e.validity&&(i.userInput.validity={});for(let r in e.validity)i.userInput.validity[r]=e.validity[r];return i}async notification(e){if(typeof e=="string"&&(e={body:e}),typeof Notification>"u")return Promise.reject(new Error("Notifications not available in this browser"));let t=Notification.permission;return t==="denied"?Promise.reject(new Error("Notifications not permitted by user")):t==="granted"?this._showNotification(e):(t=await Notification.requestPermission(),t==="granted"?this._showNotification(e):Promise.reject(new Error("Notifications not permitted by user")))}removeClass(e,t){if(!e){t.removeAttribute("class");return}Array.isArray(e)||(e=[e]),t&&t.classList.remove(...e)}replaceSlot(e,t){if(!e)return;t||(t=""),t=this.sanitiseHTML(t);let i=a.doc.createRange().createContextualFragment(t),r=a.doc.createRange();r.selectNodeContents(e),r.deleteContents(),e.append(i)}replaceSlotMarkdown(e,t){e&&t.slotMarkdown&&(t.slotMarkdown=this.convertMarkdown(t.slotMarkdown),t.slotMarkdown=this.sanitiseHTML(t.slotMarkdown),e.innerHTML=t.slotMarkdown)}sanitiseHTML(e){return a.win.DOMPurify?a.win.DOMPurify.sanitize(e,{ADD_TAGS:this.sanitiseExtraTags,ADD_ATTR:this.sanitiseExtraAttribs}):e}showDialog(e,t,i){let r="";if(i.payload&&typeof i.payload=="string"&&(r+="<div>".concat(i.payload,"</div>")),t.content&&(r+="<div>".concat(t.content,"</div>")),r===""){a.log(1,"Ui:showDialog","Toast content is blank. Not shown.")();return}!t.title&&i.topic&&(t.title=i.topic),t.title&&(r='<p class="toast-head">'.concat(t.title,"</p><p>").concat(r,"</p>")),t.noAutohide&&(t.noAutoHide=t.noAutohide),t.noAutoHide&&(t.autohide=!t.noAutoHide),t.autoHideDelay?(t.autohide||(t.autohide=!0),t.delay=t.autoHideDelay):t.autoHideDelay=1e4,Object.prototype.hasOwnProperty.call(t,"autohide")||(t.autohide=!0),e==="alert"&&(t.modal=!0,t.autohide=!1,r='<svg viewBox="0 0 192.146 192.146" style="width:30;background-color:transparent;"><path d="M108.186 144.372c0 7.054-4.729 12.32-12.037 12.32h-.254c-7.054 0-11.92-5.266-11.92-12.32 0-7.298 5.012-12.31 12.174-12.31s11.91 4.992 12.037 12.31zM88.44 125.301h15.447l2.951-61.298H85.46l2.98 61.298zm101.932 51.733c-2.237 3.664-6.214 5.921-10.493 5.921H12.282c-4.426 0-8.51-2.384-10.698-6.233a12.34 12.34 0 0 1 .147-12.349l84.111-149.22c2.208-3.722 6.204-5.96 10.522-5.96h.332c4.445.107 8.441 2.618 10.513 6.546l83.515 149.229c1.993 3.8 1.905 8.363-.352 12.066zm-10.493-6.4L96.354 21.454l-84.062 149.18h167.587z" /></svg> '.concat(r));let n=a.doc.getElementById("toaster");n===null&&(n=a.doc.createElement("div"),n.id="toaster",n.title="Click to clear all notifcations",n.setAttribute("class","toaster"),n.setAttribute("role","dialog"),n.setAttribute("arial-label","Toast message"),n.onclick=function(){n.remove()},a.doc.body.insertAdjacentElement("afterbegin",n));let o=a.doc.createElement("div");o.title="Click to clear this notifcation",o.setAttribute("class","toast ".concat(t.variant?t.variant:""," ").concat(e)),o.innerHTML=r,o.setAttribute("role","alertdialog"),t.modal&&o.setAttribute("aria-modal",t.modal),o.onclick=function(c){c.stopPropagation(),o.remove(),n.childElementCount<1&&n.remove()},n.insertAdjacentElement(t.appendToast===!0?"beforeend":"afterbegin",o),t.autohide===!0&&setInterval(()=>{o.remove(),n.childElementCount<1&&n.remove()},t.autoHideDelay)}ui(e){let t={};e._ui?t=e:t._ui=e,this._uiManager(t)}uiGet(e,t=null){let i=a.doc.querySelectorAll(e),r=[];return i.forEach(n=>{if(t){t==="classes"&&(t="class");let o=n.getAttribute(t);if(o==null)try{o=n[t]}catch{}if(o==null)t.toLowerCase()==="value"?r.push(n.innerText):r.push("Property '".concat(t,"' not found"));else{let c={},u=o.constructor.name.toLowerCase();if(u==="namednodemap")for(let d of o)c[d.name]=o[d.name].value;else if(!u.includes("map"))c[t]=o;else{let d={};for(let f in o)d[f]=o[f]}c.class&&(c.classes=Array.from(n.classList)),r.push(c)}}else r.push(this.nodeGet(n,e))}),r}uiEnhanceElement(e,t){this._uiComposeComponent(e,t)}createTable(e=[],t={parent:"body"}){if(!t.parent)throw new Error("[ui.js:createTable] opts.parent must be provided");this.buildHtmlTable(e,t)}buildHtmlTable(e,t={}){let i,r=Object.prototype.toString.apply(e);if(r==="[object Array]"||r==="[object Object]")i=Object.keys(e),e=Object.values(e);else{let f=a.doc.createElement("p");return f.textContent="Input data is not an array or an object, cannot create a table.",f}i.length>1e3&&a.log(1,"Uib:buildHtmlTable","Warning, data is ".concat(i.length," rows. Anything over 1,000 can get very slow to complete."))();let n=a.doc.createElement("table"),o=a.doc.createElement("thead"),c=a.doc.createElement("tr");if(!t.cols){if(e.length<1)throw new Error("[ui.js:buildHtmlTable] When no opts.cols is provided, data must contain at least 1 row");let f=Object.prototype.toString.apply(e[0])!=="[object Array]";c.dataset.colReference="",t.cols=[],Object.keys(e[0]).forEach((m,w)=>{t.cols.push({index:w,hasName:f,name:f?m:void 0,key:m!=null?m:w,title:m})})}n.cols=t.cols,t.cols.forEach(f=>{let m=a.doc.createElement("th");m.textContent=f.title,f.hasName===!0&&(m.dataset.colName=name),c.appendChild(m)}),o.appendChild(c),n.appendChild(o);let u=a.doc.createElement("tbody");n.appendChild(u);let d={allowHTML:!0,cols:t.cols};if(e.forEach((f,m)=>{isNaN(Number(i[m]))?d.rowId=i[m]:d.rowId=void 0,this.tblAddRow(n,f,d)}),t.parent){let f;typeof t.parent=="string"?f=a.doc.querySelector(t.parent):f=t.parent;try{f.appendChild(n)}catch(m){throw new Error("[ui.js:buildHtmlTable] Could not add table to parent. ".concat(m.message))}return}return n}tblAddRow(e,t={},i={}){let r=Object.prototype.toString.apply(e);if(Object.prototype.toString.apply(i)!=="[object Object]")throw new Error("[tblAddDataRow] options must be an object");let n=Object.prototype.toString.apply(t);if(n!=="[object Object]"&&n!=="[object Array]")throw new Error("[tblAddDataRow] rowData MUST be an object or an array containing column/cell data for each column");let o;if(r==="[object HTMLTableElement]")o=e;else if(o=a.doc.querySelector(e),!o)throw new Error('[tblAddDataRow] Table with CSS Selector "'.concat(e,'" not found'));i.body||(i.body=0),"allowHTML"in i||(i.allowHTML=!1);let c=o.getElementsByTagName("tbody")[i.body];if(!c)throw new Error("[tblAddDataRow] Table must have a tbody tag, tbody section ".concat(i.body," does not exist"));i.cols||(i.cols=this.tblGetColMeta(o));let u=i.cols,d=a.doc.createElement("tr");i.rowId&&(d.id=i.rowId);let f=[];for(let m of u){let w=a.doc.createElement("td");w.colMeta=m,m.hasName&&(w.dataset.colName=m.name),f.push(w)}if(Object.keys(t).forEach((m,w,G)=>{let J=f.find(R=>{var Ye;return((Ye=R==null?void 0:R.colMeta)==null?void 0:Ye.name)===m}),O;if(J)O=t[m];else{let R=Number(m);isNaN(R)&&(R=w),R<=f.length-1&&(J=f[R],O=Object.values(t)[R])}J&&(i.allowHTML?J.innerHTML=this.sanitiseHTML(O):J.textContent=O)}),d.append(...f),"afterRow"in i){let m=c.rows[i.afterRow];if(m)return m.after(d)}else if("beforeRow"in i){let m=c.rows[i.beforeRow];if(m)return m.before(d)}else if("replaceRow"in i){let m=c.rows[i.replaceRow];if(m)return m.replaceWith(d)}return c.appendChild(d)}tblAddListener(e,t={},i={}){let r=a.doc.querySelector(e);if(!r)throw new Error('Table with CSS Selector "'.concat(e,'" not found'));if(typeof i!="object")throw new Error('The "out" argument MUST be an object');t.eventScope||(t.eventScope="row"),t.returnType||(t.returnType="text"),t.eventType||(t.eventType="click"),t.pad||(t.pad=3),t.logLevel||(t.logLevel=2),"send"in t||(t.send=!0),r.querySelector("tbody").addEventListener(t.eventType,n=>{Object.keys(i).forEach(u=>delete i[u]);let o=n.target.closest("tr"),c=n.target.closest("td");if(o){i.clickType=t.eventScope,i.eventType=t.eventType;let u=i.rowIndex=o.rowIndex,d=i.cellIndex=c.cellIndex+1;if(o.id&&(i.rowId=o.id),t.eventScope==="row")o.querySelectorAll("td").forEach(f=>{let m=this.tblGetCellName(f,t.pad);i[m]=t.returnType==="text"?f.textContent.trim():f.innerHTML});else{let f=this.tblGetCellName(c,t.pad);i[f]=t.returnType==="text"?c.textContent.trim():c.innerHTML}a.log(t.logLevel,"Ui:tblAddClickListener","".concat(t.eventScope," ").concat(t.eventType," on row=").concat(u,", col=").concat(d,", data: "),i)(),t.send===!0&&a.win.uibuilder&&a.win.uibuilder.send({topic:"".concat(e," ").concat(t.eventScope," ").concat(t.eventType),payload:i})}})}tblFindColMeta(e,t,i){if(!t&&!i)throw new Error("[tblFindColMeta] Either the column metadata array or the HTML table element must be provided");!t&&i&&(t=this.tblGetColMeta(i));let r;if(t[e])r=t[e];else{let n=t.find(o=>o.name===e||o.index===Number(e));n&&(r=n)}return r}tblGetCellName(e,t=3){var i;return(i=e.getAttribute("data-col-name"))!=null?i:"C".concat(String(e.cellIndex+1).padStart(t,"0"))}tblGetColMeta(e,t={}){var o,c,u;if(t.pad||(t.pad=3),e.cols)return e.cols;let i=(o=e.querySelector("tr[data-col-reference]"))==null?void 0:o.children;if(i||(i=(c=e.querySelector("thead>tr:first-of-type"))==null?void 0:c.children),i||(i=(u=e.querySelector("tr:first-of-type"))==null?void 0:u.children),!i)return a.log(1,"Ui:tblGetColMeta","No columns found in table")(),[];let r=[],n;for(n of i){let d=!!n.dataset.colName,f=n.dataset.colName,m=n.cellIndex+1,w=d?f:"C".concat(String(n.cellIndex+1).padStart(t.pad,"0"));r.push({index:m,hasName:d,name:f,key:w,title:n.textContent})}return e.cols=r,r}tblRemoveRow(e,t,i={}){let r=Object.prototype.toString.apply(e);if(Object.prototype.toString.apply(i)!=="[object Object]")throw new Error("[tblRemoveRow] options must be an object");let n;if(r==="[object HTMLTableElement]")n=e;else if(n=a.doc.querySelector(e),!n)throw new Error('[tblRemoveRow] Table with CSS Selector "'.concat(e,'" not found'));i.body||(i.body=0);let o=n.getElementsByTagName("tbody")[i.body];if(!o)throw new Error("[tblAddDataRow] Table must have a tbody tag, tbody section ".concat(i.body," does not exist"));o.deleteRow(t)}},h(a,"win"),h(a,"doc"),h(a,"log"),h(a,"mdOpts"),h(a,"md"),a),et=Ft;var x=Object.create(null);x.open="0";x.close="1";x.ping="2";x.pong="3";x.message="4";x.upgrade="5";x.noop="6";var oe=Object.create(null);Object.keys(x).forEach(s=>{oe[x[s]]=s});var ae={type:"error",data:"parser error"};var rt=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",st=typeof ArrayBuffer=="function",nt=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,ce=({type:s,data:e},t,i)=>rt&&e instanceof Blob?t?i(e):tt(e,i):st&&(e instanceof ArrayBuffer||nt(e))?t?i(e):tt(new Blob([e]),i):i(x[s]+(e||"")),tt=(s,e)=>{let t=new FileReader;return t.onload=function(){let i=t.result.split(",")[1];e("b"+(i||""))},t.readAsDataURL(s)};function it(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}var Ie;function ot(s,e){if(rt&&s.data instanceof Blob)return s.data.arrayBuffer().then(it).then(e);if(st&&(s.data instanceof ArrayBuffer||nt(s.data)))return e(it(s.data));ce(s,!1,t=>{Ie||(Ie=new TextEncoder),e(Ie.encode(t))})}var at="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",le=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<at.length;s++)le[at.charCodeAt(s)]=s;var ct=s=>{let e=s.length*.75,t=s.length,i,r=0,n,o,c,u;s[s.length-1]==="="&&(e--,s[s.length-2]==="="&&e--);let d=new ArrayBuffer(e),f=new Uint8Array(d);for(i=0;i<t;i+=4)n=le[s.charCodeAt(i)],o=le[s.charCodeAt(i+1)],c=le[s.charCodeAt(i+2)],u=le[s.charCodeAt(i+3)],f[r++]=n<<2|o>>4,f[r++]=(o&15)<<4|c>>2,f[r++]=(c&3)<<6|u&63;return d};var Vt=typeof ArrayBuffer=="function",he=(s,e)=>{if(typeof s!="string")return{type:"message",data:lt(s,e)};let t=s.charAt(0);return t==="b"?{type:"message",data:Wt(s.substring(1),e)}:oe[t]?s.length>1?{type:oe[t],data:s.substring(1)}:{type:oe[t]}:ae},Wt=(s,e)=>{if(Vt){let t=ct(s);return lt(t,e)}else return{base64:!0,data:s}},lt=(s,e)=>{switch(e){case"blob":return s instanceof Blob?s:new Blob([s]);case"arraybuffer":default:return s instanceof ArrayBuffer?s:s.buffer}};var ht="",ut=(s,e)=>{let t=s.length,i=new Array(t),r=0;s.forEach((n,o)=>{ce(n,!1,c=>{i[o]=c,++r===t&&e(i.join(ht))})})},dt=(s,e)=>{let t=s.split(ht),i=[];for(let r=0;r<t.length;r++){let n=he(t[r],e);if(i.push(n),n.type==="error")break}return i};function ft(){return new TransformStream({transform(s,e){ot(s,t=>{let i=t.length,r;if(i<126)r=new Uint8Array(1),new DataView(r.buffer).setUint8(0,i);else if(i<65536){r=new Uint8Array(3);let n=new DataView(r.buffer);n.setUint8(0,126),n.setUint16(1,i)}else{r=new Uint8Array(9);let n=new DataView(r.buffer);n.setUint8(0,127),n.setBigUint64(1,BigInt(i))}s.data&&typeof s.data!="string"&&(r[0]|=128),e.enqueue(r),e.enqueue(t)})}})}var Ue;function Se(s){return s.reduce((e,t)=>e+t.length,0)}function Oe(s,e){if(s[0].length===e)return s.shift();let t=new Uint8Array(e),i=0;for(let r=0;r<e;r++)t[r]=s[0][i++],i===s[0].length&&(s.shift(),i=0);return s.length&&i<s[0].length&&(s[0]=s[0].slice(i)),t}function pt(s,e){Ue||(Ue=new TextDecoder);let t=[],i=0,r=-1,n=!1;return new TransformStream({transform(o,c){for(t.push(o);;){if(i===0){if(Se(t)<1)break;let u=Oe(t,1);n=(u[0]&128)===128,r=u[0]&127,r<126?i=3:r===126?i=1:i=2}else if(i===1){if(Se(t)<2)break;let u=Oe(t,2);r=new DataView(u.buffer,u.byteOffset,u.length).getUint16(0),i=3}else if(i===2){if(Se(t)<8)break;let u=Oe(t,8),d=new DataView(u.buffer,u.byteOffset,u.length),f=d.getUint32(0);if(f>Math.pow(2,21)-1){c.enqueue(ae);break}r=f*Math.pow(2,32)+d.getUint32(4),i=3}else{if(Se(t)<r)break;let u=Oe(t,r);c.enqueue(he(n?u:Ue.decode(u),e)),i=0}if(r===0||r>s){c.enqueue(ae);break}}}})}var Me=4;function g(s){if(s)return zt(s)}function zt(s){for(var e in g.prototype)s[e]=g.prototype[e];return s}g.prototype.on=g.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this};g.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this};g.prototype.off=g.prototype.removeListener=g.prototype.removeAllListeners=g.prototype.removeEventListener=function(s,e){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var t=this._callbacks["$"+s];if(!t)return this;if(arguments.length==1)return delete this._callbacks["$"+s],this;for(var i,r=0;r<t.length;r++)if(i=t[r],i===e||i.fn===e){t.splice(r,1);break}return t.length===0&&delete this._callbacks["$"+s],this};g.prototype.emit=function(s){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),t=this._callbacks["$"+s],i=1;i<arguments.length;i++)e[i-1]=arguments[i];if(t){t=t.slice(0);for(var i=0,r=t.length;i<r;++i)t[i].apply(this,e)}return this};g.prototype.emitReserved=g.prototype.emit;g.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};g.prototype.hasListeners=function(s){return!!this.listeners(s).length};var $=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),E=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),mt="arraybuffer";function xe(s,...e){return e.reduce((t,i)=>(s.hasOwnProperty(i)&&(t[i]=s[i]),t),{})}var Gt=E.setTimeout,Jt=E.clearTimeout;function L(s,e){e.useNativeTimers?(s.setTimeoutFn=Gt.bind(E),s.clearTimeoutFn=Jt.bind(E)):(s.setTimeoutFn=E.setTimeout.bind(E),s.clearTimeoutFn=E.clearTimeout.bind(E))}var Yt=1.33;function bt(s){return typeof s=="string"?Kt(s):Math.ceil((s.byteLength||s.size)*Yt)}function Kt(s){let e=0,t=0;for(let i=0,r=s.length;i<r;i++)e=s.charCodeAt(i),e<128?t+=1:e<2048?t+=2:e<55296||e>=57344?t+=3:(i++,t+=4);return t}function Ne(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function yt(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function gt(s){let e={},t=s.split("&");for(let i=0,r=t.length;i<r;i++){let n=t[i].split("=");e[decodeURIComponent(n[0])]=decodeURIComponent(n[1])}return e}var Ae=class extends Error{constructor(e,t,i){super(e),this.description=t,this.context=i,this.type="TransportError"}},I=class extends g{constructor(e){super(),this.writable=!1,L(this,e),this.opts=e,this.query=e.query,this.socket=e.socket,this.supportsBinary=!e.forceBase64}onError(e,t,i){return super.emitReserved("error",new Ae(e,t,i)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(e){this.readyState==="open"&&this.write(e)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(e){let t=he(e,this.socket.binaryType);this.onPacket(t)}onPacket(e){super.emitReserved("packet",e)}onClose(e){this.readyState="closed",super.emitReserved("close",e)}pause(e){}createUri(e,t={}){return e+"://"+this._hostname()+this._port()+this.opts.path+this._query(t)}_hostname(){let e=this.opts.hostname;return e.indexOf(":")===-1?e:"["+e+"]"}_port(){return this.opts.port&&(this.opts.secure&&+(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(e){let t=yt(e);return t.length?"?"+t:""}};var ue=class extends I{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(e){this.readyState="pausing";let t=()=>{this.readyState="paused",e()};if(this._polling||!this.writable){let i=0;this._polling&&(i++,this.once("pollComplete",function(){--i||t()})),this.writable||(i++,this.once("drain",function(){--i||t()}))}else t()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(e){let t=i=>{if(this.readyState==="opening"&&i.type==="open"&&this.onOpen(),i.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(i)};dt(e,this.socket.binaryType).forEach(t),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let e=()=>{this.write([{type:"close"}])};this.readyState==="open"?e():this.once("open",e)}write(e){this.writable=!1,ut(e,t=>{this.doWrite(t,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let e=this.opts.secure?"https":"http",t=this.query||{};return this.opts.timestampRequests!==!1&&(t[this.opts.timestampParam]=Ne()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}};var wt=!1;try{wt=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var vt=wt;function Xt(){}var De=class extends ue{constructor(e){if(super(e),typeof location<"u"){let t=location.protocol==="https:",i=location.port;i||(i=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||i!==e.port}}doWrite(e,t){let i=this.request({method:"POST",data:e});i.on("success",t),i.on("error",(r,n)=>{this.onError("xhr post error",r,n)})}doPoll(){let e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,i)=>{this.onError("xhr poll error",t,i)}),this.pollXhr=e}},U=class s extends g{constructor(e,t,i){super(),this.createRequest=e,L(this,i),this._opts=i,this._method=i.method||"GET",this._uri=t,this._data=i.data!==void 0?i.data:null,this._create()}_create(){var e;let t=xe(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;let i=this._xhr=this.createRequest(t);try{i.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){i.setDisableHeaderCheck&&i.setDisableHeaderCheck(!0);for(let r in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(r)&&i.setRequestHeader(r,this._opts.extraHeaders[r])}}catch{}if(this._method==="POST")try{i.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{i.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(i),"withCredentials"in i&&(i.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(i.timeout=this._opts.requestTimeout),i.onreadystatechange=()=>{var r;i.readyState===3&&((r=this._opts.cookieJar)===null||r===void 0||r.parseCookies(i.getResponseHeader("set-cookie"))),i.readyState===4&&(i.status===200||i.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof i.status=="number"?i.status:0)},0))},i.send(this._data)}catch(r){this.setTimeoutFn(()=>{this._onError(r)},0);return}typeof document<"u"&&(this._index=s.requestsCount++,s.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=Xt,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete s.requests[this._index],this._xhr=null}}_onLoad(){let e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};U.requestsCount=0;U.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",_t);else if(typeof addEventListener=="function"){let s="onpagehide"in E?"pagehide":"unload";addEventListener(s,_t,!1)}}function _t(){for(let s in U.requests)U.requests.hasOwnProperty(s)&&U.requests[s].abort()}var Qt=function(){let s=kt({xdomain:!1});return s&&s.responseType!==null}(),M=class extends De{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=Qt&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new U(kt,this.uri(),e)}};function kt(s){let e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||vt))return new XMLHttpRequest}catch{}if(!e)try{return new E[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var Et=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Pe=class extends I{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,i=Et?{}:xe(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(i.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(e,t,i)}catch(r){return this.emitReserved("error",r)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=e=>this.onClose({description:"websocket connection closed",context:e}),this.ws.onmessage=e=>this.onData(e.data),this.ws.onerror=e=>this.onError("websocket error",e)}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let i=e[t],r=t===e.length-1;ce(i,this.supportsBinary,n=>{try{this.doWrite(i,n)}catch{}r&&$(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let e=this.opts.secure?"wss":"ws",t=this.query||{};return this.opts.timestampRequests&&(t[this.opts.timestampParam]=Ne()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},Be=E.WebSocket||E.MozWebSocket,D=class extends Pe{createSocket(e,t,i){return Et?new Be(e,t,i):t?new Be(e,t):new Be(e)}doWrite(e,t){this.ws.send(t)}};var Y=class extends I{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(e){return this.emitReserved("error",e)}this._transport.closed.then(()=>{this.onClose()}).catch(e=>{this.onError("webtransport error",e)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(e=>{let t=pt(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=e.readable.pipeThrough(t).getReader(),r=ft();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let n=()=>{i.read().then(({done:c,value:u})=>{c||(this.onPacket(u),n())}).catch(c=>{})};n();let o={type:"open"};this.query.sid&&(o.data='{"sid":"'.concat(this.query.sid,'"}')),this._writer.write(o).then(()=>this.onOpen())})})}write(e){this.writable=!1;for(let t=0;t<e.length;t++){let i=e[t],r=t===e.length-1;this._writer.write(i).then(()=>{r&&$(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}};var He={websocket:D,webtransport:Y,polling:M};var Zt=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ei=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function K(s){if(s.length>8e3)throw"URI too long";let e=s,t=s.indexOf("["),i=s.indexOf("]");t!=-1&&i!=-1&&(s=s.substring(0,t)+s.substring(t,i).replace(/:/g,";")+s.substring(i,s.length));let r=Zt.exec(s||""),n={},o=14;for(;o--;)n[ei[o]]=r[o]||"";return t!=-1&&i!=-1&&(n.source=e,n.host=n.host.substring(1,n.host.length-1).replace(/;/g,":"),n.authority=n.authority.replace("[","").replace("]","").replace(/;/g,":"),n.ipv6uri=!0),n.pathNames=ti(n,n.path),n.queryKey=ii(n,n.query),n}function ti(s,e){let t=/\/{2,9}/g,i=e.replace(t,"/").split("/");return(e.slice(0,1)=="/"||e.length===0)&&i.splice(0,1),e.slice(-1)=="/"&&i.splice(i.length-1,1),i}function ii(s,e){let t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(i,r,n){r&&(t[r]=n)}),t}var qe=typeof addEventListener=="function"&&typeof removeEventListener=="function",Te=[];qe&&addEventListener("offline",()=>{Te.forEach(s=>s())},!1);var q=class s extends g{constructor(e,t){if(super(),this.binaryType=mt,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){let i=K(e);t.hostname=i.host,t.secure=i.protocol==="https"||i.protocol==="wss",t.port=i.port,i.query&&(t.query=i.query)}else t.host&&(t.hostname=K(t.host).host);L(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach(i=>{let r=i.prototype.name;this.transports.push(r),this._transportsByName[r]=i}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=gt(this.opts.query)),qe&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},Te.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=Me,t.transport=e,this.id&&(t.sid=this.id);let i=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return new this._transportsByName[e](i)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let e=this.opts.rememberUpgrade&&s.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){this.transport&&this.transport.removeAllListeners(),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){this.readyState="open",s.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let e=this._getWritablePackets();this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let i=0;i<this.writeBuffer.length;i++){let r=this.writeBuffer[i].data;if(r&&(t+=bt(r)),i>0&&t>this._maxPayload)return this.writeBuffer.slice(0,i);t+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let e=Date.now()>this._pingTimeoutTime;return e&&(this._pingTimeoutTime=0,$(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,i){return this._sendPacket("message",e,t,i),this}send(e,t,i){return this._sendPacket("message",e,t,i),this}_sendPacket(e,t,i,r){if(typeof t=="function"&&(r=t,t=void 0),typeof i=="function"&&(r=i,i=null),this.readyState==="closing"||this.readyState==="closed")return;i=i||{},i.compress=i.compress!==!1;let n={type:e,data:t,options:i};this.emitReserved("packetCreate",n),this.writeBuffer.push(n),r&&this.once("flush",r),this.flush()}close(){let e=()=>{this._onClose("forced close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},i=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?i():e()}):this.upgrading?i():e()),this}_onError(e){if(s.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),qe&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let i=Te.indexOf(this._offlineEventListener);i!==-1&&Te.splice(i,1)}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}};q.protocol=Me;var Re=class extends q{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let e=0;e<thi