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 158 kB
var ri=Object.create;var Pe=Object.defineProperty;var si=Object.getOwnPropertyDescriptor;var ni=Object.getOwnPropertyNames;var oi=Object.getPrototypeOf,ai=Object.prototype.hasOwnProperty;var pt=s=>{throw TypeError(s)};var ci=(s,e,t)=>e in s?Pe(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var mt=(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 li=(s,e)=>{for(var t in e)Pe(s,t,{get:e[t],enumerable:!0})},ui=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of ni(e))!ai.call(s,r)&&r!==t&&Pe(s,r,{get:()=>e[r],enumerable:!(i=si(e,r))||i.enumerable});return s};var bt=(s,e,t)=>(t=s!=null?ri(oi(s)):{},ui(e||!s||!s.__esModule?Pe(t,"default",{value:s,enumerable:!0}):t,s));var p=(s,e,t)=>ci(s,typeof e!="symbol"?e+"":e,t),gt=(s,e,t)=>e.has(s)||pt("Cannot "+t);var h=(s,e,t)=>(gt(s,e,"read from private field"),t?t.call(s):e.get(s)),S=(s,e,t)=>e.has(s)?pt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(s):e.set(s,t),C=(s,e,t,i)=>(gt(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t);var qe=(s,e,t,i)=>({set _(r){C(s,e,r,t)},get _(){return h(s,e,i)}});function yt(s={}){let{content:e="",title:t="",icon:i="",type:r="info",showDismiss:n,autoClose:o=5,time:a=!0}=s,l="uib-info-overlay",d=document.getElementById(l);d||(d=document.createElement("div"),d.id=l,document.body.appendChild(d),console.log(">> SHOW OVERLAY >>",s,document.getElementById(l)));let f="overlay-entry-".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),m=document.createElement("div");m.id=f,m.style.marginBottom="0.5rem";let b={info:{iconDefault:"\u2139\uFE0F",titleDefault:"Information",color:"hsl(188.2deg 77.78% 40.59%)"},success:{iconDefault:"\u2705",titleDefault:"Success",color:"hsl(133.7deg 61.35% 40.59%)"},warning:{iconDefault:"\u26A0\uFE0F",titleDefault:"Warning",color:"hsl(35.19deg 84.38% 62.35%)"},error:{iconDefault:"\u274C",titleDefault:"Error",color:"hsl(2.74deg 92.59% 62.94%)"}},g=b[r]||b.info,y=n!==void 0?n:o===null,_=i||g.iconDefault,T=t||g.titleDefault,I="";if(a){let N=new Date,ge=N.getFullYear(),ye=String(N.getMonth()+1).padStart(2,"0"),ve=String(N.getDate()).padStart(2,"0"),we=String(N.getHours()).padStart(2,"0"),Ee=String(N.getMinutes()).padStart(2,"0"),Qe=String(N.getSeconds()).padStart(2,"0"),ii="".concat(ge,"-").concat(ye,"-").concat(ve," ").concat(we,":").concat(Ee,":").concat(Qe);I='<div class="uib-overlay-time" style="font-size: 0.8em; color: var(--text3, #999); margin-left: auto; margin-right: '.concat(y?"0.5rem":"0",';">').concat(ii,"</div>")}m.innerHTML='\n <div class="uib-overlay-entry" style="--callout-color:'.concat(g.color,';">\n <div class="uib-overlay-header">\n <div class="uib-overlay-icon">').concat(_,'</div>\n <div class="uib-overlay-title">').concat(T,"</div>\n ").concat(I,"\n ").concat(y?'<button class="uib-overlay-dismiss" data-entry-id="'.concat(f,'" title="Close">\xD7</button>'):"",'\n </div>\n <div class="uib-overlay-content">\n ').concat(e,"\n </div>\n </div>\n "),d.children.length>0?d.insertBefore(m,d.firstChild):d.appendChild(m);let v=()=>{let N=document.getElementById(f);N&&(N.style.animation="slideOut 0.3s ease-in",setTimeout(()=>{N.parentNode&&N.remove()},300))},O=m.querySelector(".uib-overlay-dismiss");O&&O.addEventListener("click",v);let D=null;return o!==null&&o>0&&(D=setTimeout(v,o*1e3)),{close:()=>{D&&clearTimeout(D),v()},id:f}}var c,hi=(c=class{constructor(e,t,i){p(this,"version","7.5.0-src");p(this,"sanitiseExtraTags",["uib-var"]);p(this,"sanitiseExtraAttribs",["variable","report","undefined"]);p(this,"ui_md_plugins");if(e)c.win=e;else throw new Error("Ui:constructor. Current environment does not include `window`, UI functions cannot be used.");c.doc=c.win.document,t?c.log=t:c.log=function(){return function(){}},i?this.syntaxHighlight=i:this.syntaxHighlight=function(){},c.win.markdownit&&(c.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(c.md.utils.escapeHtml(r).trim(),"</code></pre>")}},c.md=c.win.markdownit(c.mdOpts))}_markDownIt(){if(c.win.markdownit&&(!this.ui_md_plugins&&c.win.uibuilder&&c.win.uibuilder.ui_md_plugins&&(this.ui_md_plugins=c.win.uibuilder.ui_md_plugins),c.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(c.md.utils.escapeHtml(e).trim(),"</code></pre>")}},c.md=c.win.markdownit(c.mdOpts),this.ui_md_plugins)){if(!Array.isArray(this.ui_md_plugins)){c.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")c.md.use(c.win[e]);else{let t=Object.keys(e)[0];c.md.use(c.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){c.log("trace","Ui:_uiManager:add","Starting _uiAdd")(),e.components.forEach((i,r)=>{c.log("trace","Ui:_uiAdd:components-forEach:".concat(r),"Component to add: ",i)();let n;switch(i.type){case"html":{i.ns="html",n=c.doc.createElement("div");break}case"svg":{i.ns="svg",n=c.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{i.ns="dom",n=c.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=c.doc.querySelector(i.parent):e.parent&&(o=c.doc.querySelector(e.parent)),o||(c.log("info","Ui:_uiAdd","No parent found, adding to body")(),o=c.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(" "),c.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){c.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)=>{c.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=c.doc.createElementNS("http://www.w3.org/2000/svg",r.type),this._uiComposeComponent(o,r),e.appendChild(o)):(o=c.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(()=>bt(mt(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){c.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:{c.log("error","Ui:_uiManager","Invalid msg._ui[".concat(i,"].method (").concat(t.method,"). Ignoring"))();break}}}))}_uiReload(){c.log("trace","Ui:uiManager:reload","reloading")(),location.reload()}_uiRemove(e,t=!1){e.components.forEach(i=>{let r;t!==!0?r=[c.doc.querySelector(i)]:r=c.doc.querySelectorAll(i),r.forEach(n=>{try{n.remove()}catch(o){c.log("trace","Ui:_uiRemove","Could not remove. ".concat(o.message))()}})})}_uiReplace(e){c.log("trace","Ui:_uiReplace","Starting")(),e.components.forEach((t,i)=>{c.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Component to replace: ",t)();let r;if(t.id?r=c.doc.getElementById(t.id):t.selector||t.select?r=c.doc.querySelector(t.selector):t.name?r=c.doc.querySelector('[name="'.concat(t.name,'"]')):t.type&&(r=c.doc.querySelector(t.type)),c.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Element to replace: ",r)(),r==null){c.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=c.doc.createElement("div");break}case"svg":{t.ns="svg",n=c.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{t.ns="dom",n=c.doc.createElement(t.type);break}}this._uiComposeComponent(n,t),r.replaceWith(n),t.components&&this._uiExtendEl(n,t.components,t.ns)})}_uiUpdate(e){c.log("trace","UI:_uiUpdate:update","Starting _uiUpdate",e)(),e.components||(e.components=[Object.assign({},e)]),e.components.forEach((t,i)=>{c.log("trace","_uiUpdate:components-forEach","Start loop #".concat(i),t)();let r;if(t.parentEl?r=t.parentEl:t.id?r=c.doc.querySelectorAll("#".concat(t.id)):t.selector||t.select?r=c.doc.querySelectorAll(t.selector):t.name?r=c.doc.querySelectorAll('[name="'.concat(t.name,'"]')):t.type&&(r=c.doc.querySelectorAll(t.type)),r===void 0||r.length<1){c.log("warn","Ui:_uiManager:update","Cannot find the DOM element. Ignoring.",t)();return}c.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(c.log("trace","_uiUpdate:components-forEach","Updating element #".concat(o),n)(),this._uiComposeComponent(n,t),t.components){c.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component"),t,n)();let a={_ui:[]};t.components.forEach((l,d)=>{let f=l.method||t.method||e.method;l.method&&delete l.method,Array.isArray(l)||(l=[l]),c.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component #").concat(d),l)(),a._ui.push({method:f,parentEl:n,components:l})}),c.log("trace","_uiUpdate:nested-component","Element #".concat(o," - nested-component new manager"),a)(),this._uiManager(a)}})})}$(e,t,i){if(i||(i=c.doc),t||(t="el"),!i||!i.nodeType)return c.log(1,"Uib:$","Invalid context element. Must be a valid HTML element.",i)(),null;let r=i.querySelector(e);if(!r||!r.nodeType)return c.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 c.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,c.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=c.doc),!t||!t.nodeType?(c.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 l;i||(i={}),i.onceOnly||(i.onceOnly=!1),i.mode||(i.mode="insert");let r=c.doc.getElementById(e);if(!r||r.tagName!=="TEMPLATE"){c.log("error","Ui:applyTemplate","Source must be a <template>. id='".concat(e,"'"))();return}let n=c.doc.getElementById(t);if(!n){c.log("error","Ui:applyTemplate","Target not found: id='".concat(t,"'"))();return}let o=(l=n.innerHTML)!=null?l:"";o&&i.mode==="replace"&&c.log("warn","Ui:applyTemplate","Target element is not empty, content is replaced. id='".concat(t,"'"))();let a;if(i.onceOnly===!0?a=c.doc.adoptNode(r.content):a=c.doc.importNode(r.content,!0),a){if(i.attributes){let d=a.firstElementChild;Object.keys(i.attributes).forEach(f=>{d.setAttribute(f,i.attributes[f])})}if(i.mode==="insert")n.appendChild(a);else if(i.mode==="replace")n.innerHTML="",n.appendChild(a);else if(i.mode==="wrap"&&(n.innerHTML="",n.appendChild(a),o)){let d=n.getElementsByTagName("slot");d.length>0&&(d[0].innerHTML=o)}}else c.log("warn","Ui:applyTemplate","No valid content found in template")()}convertMarkdown(e){if(!e)return"";if(!c.win.markdownit)return e;c.md||this._markDownIt();try{return c.md.render(e.trim())}catch(t){return c.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 c.log(0,"Ui:include","Current environment does not include `fetch`, skipping.")(),"Current environment does not include `fetch`, skipping.";if(!e)return c.log(0,"Ui:include","url parameter must be provided, skipping.")(),"url parameter must be provided, skipping.";if(!t||!t.id)return c.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 c.log(0,"Ui:include","Fetch of file '".concat(e,"' failed. "),d.message)(),d.message}if(!i.ok)return c.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="",a="Include successful",l;switch(n){case"html":{l=await i.text(),o=l;break}case"json":{l=await i.json(),o='<pre class="syntax-highlight">',o+=this.syntaxHighlight(l),o+="</pre>";break}case"form":{l=await i.formData(),o='<pre class="syntax-highlight">',o+=this.syntaxHighlight(l),o+="</pre>";break}case"image":{l=await i.blob(),o='<img src="'.concat(URL.createObjectURL(l),'">'),c.win.DOMPurify&&(a="Include successful. BUT DOMPurify loaded which may block its use.",c.log("warn","Ui:include:image",a)());break}case"video":{l=await i.blob(),o='<video controls autoplay><source src="'.concat(URL.createObjectURL(l),'"></video>'),c.win.DOMPurify&&(a="Include successful. BUT DOMPurify loaded which may block its use.",c.log("warn","Ui:include:video",a)());break}case"pdf":case"text":default:{l=await i.blob(),o='<iframe style="resize:both;width:inherit;height:inherit;" src="'.concat(URL.createObjectURL(l),'">'),c.win.DOMPurify&&(a="Include successful. BUT DOMPurify loaded which may block its use.",c.log("warn","Ui:include:".concat(n),a)());break}}return t.type="div",t.slot=o,t.parent||(t.parent="body"),t.attributes||(t.attributes={class:"included"}),this._uiReplace({components:[t]}),c.log("trace","Ui:include:".concat(n),a)(),a}loadScriptSrc(e){let t=c.doc.createElement("script");t.src=e,t.async=!1,c.doc.head.appendChild(t)}loadScriptTxt(e){let t=c.doc.createElement("script");t.async=!1,t.textContent=e,c.doc.head.appendChild(t)}loadStyleSrc(e){let t=c.doc.createElement("link");t.href=e,t.rel="stylesheet",t.type="text/css",c.doc.head.appendChild(t)}loadStyleTxt(e){let t=c.doc.createElement("style");t.textContent=e,c.doc.head.appendChild(t)}loadui(e){if(!fetch){c.log(0,"Ui:loadui","Current environment does not include `fetch`, skipping.")();return}if(!e){c.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));c.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?(c.log("trace","Ui:loadui:then2","Parsed JSON successfully obtained")(),this._uiManager({_ui:t}),!0):!1).catch(t=>{c.log("warn","Ui:loadui:catch","Error. ",t)()})}moveElement(e){let{sourceSelector:t,targetSelector:i,moveType:r,position:n}=e;if(!document.querySelector(t)){c.log(0,"Ui:moveElement","Source element not found")();return}if(!document.querySelector(i)){c.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=c.doc.querySelectorAll("".concat(t," li"));r&&(i.list={entries:r.length})}if(e.nodeName==="DL"){let r=c.doc.querySelectorAll("".concat(t," dt"));r&&(i.list={entries:r.length})}if(e.nodeName==="TABLE"){let r=c.doc.querySelectorAll("".concat(t," > tbody > tr")),n=c.doc.querySelectorAll("".concat(t," > thead > tr")),o=c.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;if(t||(t=""),t=this.sanitiseHTML(t),e.nodeName==="TEMPLATE"){e.innerHTML=t;return}let i=c.doc.createRange().createContextualFragment(t),r=c.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 c.win.DOMPurify?c.win.DOMPurify.sanitize(e,{ADD_TAGS:this.sanitiseExtraTags,ADD_ATTR:this.sanitiseExtraAttribs}):e}showDialog(e,t,i){(!e||!["notify","alert"].includes(e))&&(e="notify"),t||(t={noAutohide:!0,modal:!0,appendToast:!1});let r="";if(i.payload&&typeof i.payload=="string"&&(r+="<div>".concat(i.payload,"</div>")),t.content&&(r+="<div>".concat(t.content,"</div>")),r==="")return c.log(1,"Ui:showDialog","Toast content is blank. Not shown.")(),null;let n="";t.title?n=t.title:i.topic&&(n=i.topic),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);let o="",a="";e==="alert"&&(a='<svg viewBox="0 0 192.146 192.146"><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>',t.modal=!0,t.autohide=!1),o='<div class="toast-head">'.concat(a).concat(n,'</div><div class="toast-body">').concat(r,"</div>");let l=()=>{g&&(c.doc.body.removeEventListener("keyup",f),g.removeEventListener("keyup",f),g.removeEventListener("touchend",f),g.removeEventListener("click",f),g.remove())},d=y=>{y.removeEventListener("keyup",f),y.removeEventListener("touchend",f),y.removeEventListener("click",f),y.remove(),g&&g.childElementCount===0&&l()},f=y=>{y.stopPropagation(),g&&(console.log("toasterEventHandler",y,g.contains(y.target),b.contains(y.target),b===y.target),l())},m=y=>{y.stopPropagation();let _;if(y.target.classList.contains("toast")?_=y.target:_=y.target.closest(".toast"),!_){c.log(1,"Ui:showDialog","Event target is not a (or in a) toast element, ignoring event")();return}let T=!!_.querySelector("input, textarea, button");if(console.log("toastEventHandler",T,y,_.contains(y.target),_===y.target),T){if(y.key!=="Escape")return;d(_)}d(_)},b=c.doc.createElement("div");if(b.title="Click or Esc to clear this notifcation",b.setAttribute("class","toast ".concat(e)),b.setAttribute("role",e==="alert"?"alertdialog":"dialog"),b.dataset.modal=t.modal,b.dataset.autohide=t.autohide,b.dataset.autoHideDelay=t.autoHideDelay,b.innerHTML=o,t.appendToast===!0){let y=Array.from(c.doc.body.querySelectorAll(".toast")).pop();y?y.insertAdjacentElement("afterend",b):c.doc.body.insertBefore(b,c.doc.body.firstChild)}else c.doc.body.insertBefore(b,c.doc.body.firstChild);b.addEventListener("keyup",m),b.addEventListener("click",m),b.addEventListener("touchend",m),t.autohide===!0&&setInterval(()=>{d(b)},t.autoHideDelay);let g;return t.modal===!0&&(g=c.doc.getElementById("toaster"),g===null&&(g=c.doc.createElement("div"),g.id="toaster",g.title="Click, touch, or ESC to clear notifcations",g.setAttribute("class","toaster"),g.setAttribute("arial-label","Toast message"),g.addEventListener("click",f),g.addEventListener("touchend",f),c.doc.body.addEventListener("keyup",f),c.doc.body.insertAdjacentElement("afterbegin",g))),b}showOverlay(e){return yt(e)}ui(e){let t={};e._ui?t=e:t._ui=e,this._uiManager(t)}uiGet(e,t=null){let i=c.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 a={},l=o.constructor.name.toLowerCase();if(l==="namednodemap")for(let d of o)a[d.name]=o[d.name].value;else if(!l.includes("map"))a[t]=o;else{let d={};for(let f in o)d[f]=o[f]}a.class&&(a.classes=Array.from(n.classList)),r.push(a)}}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=c.doc.createElement("p");return f.textContent="Input data is not an array or an object, cannot create a table.",f}i.length>1e3&&c.log(1,"Uib:buildHtmlTable","Warning, data is ".concat(i.length," rows. Anything over 1,000 can get very slow to complete."))();let n=c.doc.createElement("table"),o=c.doc.createElement("thead"),a=c.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]";a.dataset.colReference="",t.cols=[],Object.keys(e[0]).forEach((m,b)=>{t.cols.push({index:b,hasName:f,name:f?m:void 0,key:m!=null?m:b,title:m})})}n.cols=t.cols,t.cols.forEach(f=>{let m=c.doc.createElement("th");m.textContent=f.title,f.hasName===!0&&(m.dataset.colName=name),a.appendChild(m)}),o.appendChild(a),n.appendChild(o);let l=c.doc.createElement("tbody");n.appendChild(l);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=c.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=c.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 a=o.getElementsByTagName("tbody")[i.body];if(!a)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 l=i.cols,d=c.doc.createElement("tr");i.rowId&&(d.id=i.rowId);let f=[];for(let m of l){let b=c.doc.createElement("td");b.colMeta=m,m.hasName&&(b.dataset.colName=m.name),f.push(b)}if(Object.keys(t).forEach((m,b,g)=>{let y=f.find(T=>{var I;return((I=T==null?void 0:T.colMeta)==null?void 0:I.name)===m}),_;if(y)_=t[m];else{let T=Number(m);isNaN(T)&&(T=b),T<=f.length-1&&(y=f[T],_=Object.values(t)[T])}y&&(i.allowHTML?y.innerHTML=this.sanitiseHTML(_):y.textContent=_)}),d.append(...f),"afterRow"in i){let m=a.rows[i.afterRow];if(m)return m.after(d)}else if("beforeRow"in i){let m=a.rows[i.beforeRow];if(m)return m.before(d)}else if("replaceRow"in i){let m=a.rows[i.replaceRow];if(m)return m.replaceWith(d)}return a.appendChild(d)}tblAddListener(e,t={},i={}){let r=c.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(l=>delete i[l]);let o=n.target.closest("tr"),a=n.target.closest("td");if(o){i.clickType=t.eventScope,i.eventType=t.eventType;let l=i.rowIndex=o.rowIndex,d=i.cellIndex=a.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(a,t.pad);i[f]=t.returnType==="text"?a.textContent.trim():a.innerHTML}c.log(t.logLevel,"Ui:tblAddClickListener","".concat(t.eventScope," ").concat(t.eventType," on row=").concat(l,", col=").concat(d,", data: "),i)(),t.send===!0&&c.win.uibuilder&&c.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,a,l;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=(a=e.querySelector("thead>tr:first-of-type"))==null?void 0:a.children),i||(i=(l=e.querySelector("tr:first-of-type"))==null?void 0:l.children),!i)return c.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,b=d?f:"C".concat(String(n.cellIndex+1).padStart(t.pad,"0"));r.push({index:m,hasName:d,name:f,key:b,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=c.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)}},p(c,"win"),p(c,"doc"),p(c,"log"),p(c,"mdOpts"),p(c,"md"),c),vt=hi;var U=Object.create(null);U.open="0";U.close="1";U.ping="2";U.pong="3";U.message="4";U.upgrade="5";U.noop="6";var _e=Object.create(null);Object.keys(U).forEach(s=>{_e[U[s]]=s});var ke={type:"error",data:"parser error"};var _t=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",kt=typeof ArrayBuffer=="function",St=s=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer,Se=({type:s,data:e},t,i)=>_t&&e instanceof Blob?t?i(e):wt(e,i):kt&&(e instanceof ArrayBuffer||St(e))?t?i(e):wt(new Blob([e]),i):i(U[s]+(e||"")),wt=(s,e)=>{let t=new FileReader;return t.onload=function(){let i=t.result.split(",")[1];e("b"+(i||""))},t.readAsDataURL(s)};function Et(s){return s instanceof Uint8Array?s:s instanceof ArrayBuffer?new Uint8Array(s):new Uint8Array(s.buffer,s.byteOffset,s.byteLength)}var Ze;function Ct(s,e){if(_t&&s.data instanceof Blob)return s.data.arrayBuffer().then(Et).then(e);if(kt&&(s.data instanceof ArrayBuffer||St(s.data)))return e(Et(s.data));Se(s,!1,t=>{Ze||(Ze=new TextEncoder),e(Ze.encode(t))})}var xt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Ce=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let s=0;s<xt.length;s++)Ce[xt.charCodeAt(s)]=s;var Tt=s=>{let e=s.length*.75,t=s.length,i,r=0,n,o,a,l;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=Ce[s.charCodeAt(i)],o=Ce[s.charCodeAt(i+1)],a=Ce[s.charCodeAt(i+2)],l=Ce[s.charCodeAt(i+3)],f[r++]=n<<2|o>>4,f[r++]=(o&15)<<4|a>>2,f[r++]=(a&3)<<6|l&63;return d};var di=typeof ArrayBuffer=="function",xe=(s,e)=>{if(typeof s!="string")return{type:"message",data:Ot(s,e)};let t=s.charAt(0);return t==="b"?{type:"message",data:fi(s.substring(1),e)}:_e[t]?s.length>1?{type:_e[t],data:s.substring(1)}:{type:_e[t]}:ke},fi=(s,e)=>{if(di){let t=Tt(s);return Ot(t,e)}else return{base64:!0,data:s}},Ot=(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 Nt="",At=(s,e)=>{let t=s.length,i=new Array(t),r=0;s.forEach((n,o)=>{Se(n,!1,a=>{i[o]=a,++r===t&&e(i.join(Nt))})})},$t=(s,e)=>{let t=s.split(Nt),i=[];for(let r=0;r<t.length;r++){let n=xe(t[r],e);if(i.push(n),n.type==="error")break}return i};function Lt(){return new TransformStream({transform(s,e){Ct(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 et;function je(s){return s.reduce((e,t)=>e+t.length,0)}function Fe(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 Rt(s,e){et||(et=new TextDecoder);let t=[],i=0,r=-1,n=!1;return new TransformStream({transform(o,a){for(t.push(o);;){if(i===0){if(je(t)<1)break;let l=Fe(t,1);n=(l[0]&128)===128,r=l[0]&127,r<126?i=3:r===126?i=1:i=2}else if(i===1){if(je(t)<2)break;let l=Fe(t,2);r=new DataView(l.buffer,l.byteOffset,l.length).getUint16(0),i=3}else if(i===2){if(je(t)<8)break;let l=Fe(t,8),d=new DataView(l.buffer,l.byteOffset,l.length),f=d.getUint32(0);if(f>Math.pow(2,21)-1){a.enqueue(ke);break}r=f*Math.pow(2,32)+d.getUint32(4),i=3}else{if(je(t)<r)break;let l=Fe(t,r);a.enqueue(xe(n?l:et.decode(l),e)),i=0}if(r===0||r>s){a.enqueue(ke);break}}}})}var tt=4;function x(s){if(s)return pi(s)}function pi(s){for(var e in x.prototype)s[e]=x.prototype[e];return s}x.prototype.on=x.prototype.addEventListener=function(s,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+s]=this._callbacks["$"+s]||[]).push(e),this};x.prototype.once=function(s,e){function t(){this.off(s,t),e.apply(this,arguments)}return t.fn=e,this.on(s,t),this};x.prototype.off=x.prototype.removeListener=x.prototype.removeAllListeners=x.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};x.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};x.prototype.emitReserved=x.prototype.emit;x.prototype.listeners=function(s){return this._callbacks=this._callbacks||{},this._callbacks["$"+s]||[]};x.prototype.hasListeners=function(s){return!!this.listeners(s).length};var j=typeof Promise=="function"&&typeof Promise.resolve=="function"?e=>Promise.resolve().then(e):(e,t)=>t(e,0),$=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),It="arraybuffer";function Ve(s,...e){return e.reduce((t,i)=>(s.hasOwnProperty(i)&&(t[i]=s[i]),t),{})}var mi=$.setTimeout,bi=$.clearTimeout;function F(s,e){e.useNativeTimers?(s.setTimeoutFn=mi.bind($),s.clearTimeoutFn=bi.bind($)):(s.setTimeoutFn=$.setTimeout.bind($),s.clearTimeoutFn=$.clearTimeout.bind($))}var gi=1.33;function Mt(s){return typeof s=="string"?yi(s):Math.ceil((s.byteLength||s.size)*gi)}function yi(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 We(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function Dt(s){let e="";for(let t in s)s.hasOwnProperty(t)&&(e.length&&(e+="&"),e+=encodeURIComponent(t)+"="+encodeURIComponent(s[t]));return e}function Ut(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 ze=class extends Error{constructor(e,t,i){super(e),this.description=t,this.context=i,this.type="TransportError"}},V=class extends x{constructor(e){super(),this.writable=!1,F(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 ze(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=xe(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=Dt(e);return t.length?"?"+t:""}};var Te=class extends V{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)};$t(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,At(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]=We()),!this.supportsBinary&&!t.sid&&(t.b64=1),this.createUri(e,t)}};var Bt=!1;try{Bt=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var Ht=Bt;function vi(){}var it=class extends Te{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}},W=class s extends x{constructor(e,t,i){super(),this.createRequest=e,F(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=Ve(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=vi,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()}};W.requestsCount=0;W.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",Pt);else if(typeof addEventListener=="function"){let s="onpagehide"in $?"pagehide":"unload";addEventListener(s,Pt,!1)}}function Pt(){for(let s in W.requests)W.requests.hasOwnProperty(s)&&W.requests[s].abort()}var wi=(function(){let s=qt({xdomain:!1});return s&&s.responseType!==null})(),z=class extends it{constructor(e){super(e);let t=e&&e.forceBase64;this.supportsBinary=wi&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new W(qt,this.uri(),e)}};function qt(s){let e=s.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||Ht))return new XMLHttpRequest}catch{}if(!e)try{return new $[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var jt=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",st=class extends V{get name(){return"websocket"}doOpen(){let e=this.uri(),t=this.opts.protocols,i=jt?{}:Ve(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;Se(i,this.supportsBinary,n=>{try{this.doWrite(i,n)}catch{}r&&j(()=>{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]=We()),this.supportsBinary||(t.b64=1),this.createUri(e,t)}},rt=$.WebSocket||$.MozWebSocket,Y=class extends st{createSocket(e,t,i){return jt?new rt(e,t,i):t?new rt(e,t):new rt(e)}doWrite(e,t){this.ws.send(t)}};var ne=class extends V{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=Rt(Number.MAX_SAFE_INTEGER,this.socket.binaryType),i=e.readable.pipeThrough(t).getReader(),r=Lt();r.readable.pipeTo(e.writable),this._writer=r.writable.getWriter();let n=()=>{i.read().then(({done:a,value:l})=>{a||(this.onPacket(l),n())}).catch(a=>{})};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&&j(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var e;(e=this._transport)===null||e===void 0||e.close()}};var nt={websocket:Y,webtransport:ne,polling:z};var Ei=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,_i=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function oe(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=Ei.exec(s||""),n={},o=14;for(;o--;)n[_i[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=ki(n,n.path),n.queryKey=Si(n,n.query),n}function ki(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 Si(s,e){let t={};return e.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(i,r,n){r&&(t[r]=n)}),t}var ot=typeof addEventListener=="function"&&typeof removeEventListener=="function",Ye=[];ot&&addEventListener("offline",()=>{Ye.forEach(s=>s())},!1);var Z=class s extends x{constructor(e,t){if(super(),this.binaryType=It,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=oe(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=oe(t.host).host);F(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=Ut(this.opts.query)),ot&&(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"})},Ye.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(e){let t=Object.assign({},this.opts.query);t.EIO=tt,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"