From 51d1839572973a512a76a87fd0b58145a9b67f64 Mon Sep 17 00:00:00 2001 From: Natxo <1172351+natxocc@users.noreply.github.com> Date: Mon, 16 Mar 2026 01:12:44 +0100 Subject: [PATCH] Update sigpro.js --- sigpro.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sigpro.js b/sigpro.js index 31da5bb..1f465ac 100644 --- a/sigpro.js +++ b/sigpro.js @@ -1 +1 @@ -var e=null,t=new Set,n=!1,r=0,i=()=>{if(n=!1,r++,r>100)throw t.clear(),r=0,Error(`SigPro: Infinite reactive loop detected.`);try{let e=Array.from(t);t.clear();for(let t of e)t.run()}catch(e){console.error(`SigPro Flush Error:`,e)}finally{setTimeout(()=>{r=0},0)}},a=r=>{let a=new Set;if(typeof r==`function`){let n=!0,i,o={dependencies:new Set,cleanupHandlers:new Set,markDirty:()=>{n||(n=!0,a.forEach(e=>{e.markDirty&&e.markDirty(),t.add(e)}))},run:()=>{o.dependencies.forEach(e=>e.delete(o)),o.dependencies.clear();let t=e;e=o;try{i=r()}finally{e=t,n=!1}}};return()=>(e&&(a.add(e),e.dependencies.add(a)),n&&o.run(),i)}return(...o)=>{if(o.length){let e=typeof o[0]==`function`?o[0](r):o[0];Object.is(r,e)||(r=e,a.forEach(e=>{e.markDirty&&e.markDirty(),t.add(e)}),!n&&t.size&&(n=!0,queueMicrotask(i)))}return e&&(a.add(e),e.dependencies.add(a)),r}},o=t=>{let n={dependencies:new Set,cleanupHandlers:new Set,run(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers.clear(),this.dependencies.forEach(e=>e.delete(this)),this.dependencies.clear();let n=e;e=this;try{let e=t();typeof e==`function`&&(this.cleanupFunction=e)}finally{e=n}},stop(){this.cleanupHandlers.forEach(e=>e()),this.dependencies.forEach(e=>e.delete(this)),this.cleanupFunction?.()}};return e&&e.cleanupHandlers.add(()=>n.stop()),n.run(),()=>n.stop()},s=(e,t,n=localStorage)=>{let r;try{let i=n.getItem(e);r=i===null?t:JSON.parse(i)}catch(i){console.warn(`Error reading ${e} from storage:`,i),r=t,n.removeItem(e)}let i=a(r);return o(()=>{try{let t=i();t==null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch(t){console.warn(`Error saving ${e} to storage:`,t)}}),i},c=(e,...t)=>{let n=c._templateCache??=new WeakMap,r=(e,t)=>t.reduce((e,t)=>e?.childNodes?.[t],e),i=(e,t)=>{let n=e.textContent.split(`{{part}}`),r=e.parentNode,i=0;n.forEach((a,s)=>{if(a&&r.insertBefore(document.createTextNode(a),e),s{let e=typeof n==`function`?n():n;if(e===c)return;if(c=e,typeof e!=`object`&&!Array.isArray(e)){let t=a.nextSibling,n=String(e??``);if(t!==s&&t?.nodeType===3)t.textContent=n;else{for(;a.nextSibling!==s;)r.removeChild(a.nextSibling);r.insertBefore(document.createTextNode(n),s)}return}for(;a.nextSibling!==s;)r.removeChild(a.nextSibling);let t=Array.isArray(e)?e:[e],i=document.createDocumentFragment();t.forEach(e=>{if(e==null||e===!1)return;let t=e instanceof Node?e:document.createTextNode(e);i.appendChild(t)}),r.insertBefore(i,s)})}}),e.remove()},a=n.get(e);if(!a){let t=document.createElement(`template`);t.innerHTML=e.join(`{{part}}`);let r=[],i=document.createTreeWalker(t.content,133),o=e=>{let n=[];for(;e&&e!==t.content;){let t=0;for(let n=e.previousSibling;n;n=n.previousSibling)t++;n.push(t),e=e.parentNode}return n.reverse()},s;for(;s=i.nextNode();){let e=!1,t={type:s.nodeType,path:o(s),parts:[]};if(s.nodeType===1)for(let n=0;n({node:r(s,e.path),info:e})).forEach(({node:e,info:n})=>{if(e){if(n.type===1)n.parts.forEach(n=>{let r=t[l++],i=n.name,a=i[0];if(a===`@`){let[t,...n]=i.slice(1).split(`.`),a=i=>{if(n.includes(`prevent`)&&i.preventDefault(),n.includes(`stop`)&&i.stopPropagation(),!(n.includes(`self`)&&i.target!==e)){if(n.some(e=>e.startsWith(`debounce`))){let t=n.find(e=>e.startsWith(`debounce`))?.split(`:`)[1]||300;clearTimeout(e._debounceTimer),e._debounceTimer=setTimeout(()=>r(i),t);return}n.includes(`once`)&&e.removeEventListener(t,a),r(i)}};e.addEventListener(t,a,{passive:n.includes(`passive`),capture:n.includes(`capture`)}),o.onCleanup&&o.onCleanup(()=>e.removeEventListener(t,a))}else if(a===`:`){let t=i.slice(1),n=e.type===`checkbox`||e.type===`radio`?`change`:`input`;o(()=>{let n=typeof r==`function`?r():r;e[t]!==n&&(e[t]=n)}),e.addEventListener(n,()=>{let t=n===`change`?e.checked:e.value;typeof r==`function`&&r(t)})}else if(a===`?`){let t=i.slice(1);o(()=>{let n=typeof r==`function`?r():r;e.toggleAttribute(t,!!n)})}else if(a===`.`){let t=i.slice(1);o(()=>{let n=typeof r==`function`?r():r;e[t]=n,n!=null&&typeof n!=`object`&&typeof n!=`boolean`&&e.setAttribute(t,n)})}else typeof r==`function`?o(()=>e.setAttribute(i,r())):e.setAttribute(i,r)});else if(n.type===3){let n=e.textContent.split(`{{part}}`).length-1;i(e,t.slice(l,l+n)),l+=n}}}),s},l=(e,t,n=[])=>{customElements.get(e)||customElements.define(e,class extends HTMLElement{static get observedAttributes(){return n}constructor(){super(),this._propertySignals={},this.cleanupFunctions=[],n.forEach(e=>this._propertySignals[e]=a(void 0))}connectedCallback(){let e=[...this.childNodes];this.innerHTML=``,n.forEach(e=>{let t=this.hasOwnProperty(e)?this[e]:this.getAttribute(e);Object.defineProperty(this,e,{get:()=>this._propertySignals[e](),set:t=>{let n=t===`false`?!1:t===``&&e!==`value`?!0:t;this._propertySignals[e](n)},configurable:!0}),t!=null&&(this[e]=t)});let r={select:e=>this.querySelector(e),slot:t=>e.filter(e=>{let n=e.nodeType===1?e.getAttribute(`slot`):null;return t?n===t:!n}),emit:(e,t)=>this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),host:this,onUnmount:e=>this.cleanupFunctions.push(e)},i=t(this._propertySignals,r);i instanceof Node&&this.appendChild(i)}attributeChangedCallback(e,t,n){this[e]!==n&&(this[e]=n)}disconnectedCallback(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[]}})},u=async(e,t,n)=>{n&&n(!0);try{let n=await(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).text();try{return JSON.parse(n)}catch{return console.warn(`Invalid JSON response`),null}}catch{return null}finally{n&&n(!1)}},d=e=>String(e).replace(/[<>"']/g,``),f=t=>{let n=()=>window.location.hash.replace(/^#/,``)||`/`,r=a(n()),i=document.createElement(`div`);return i.style.display=`contents`,window.addEventListener(`hashchange`,()=>{let e=d(n());r()!==e&&r(e)}),o(()=>{let n=r(),a=null,o={};for(let e of t)if(e.path instanceof RegExp){let t=n.match(e.path);if(t){a=e,o=t.groups||{id:t[1]};break}}else if(e.path===n){a=e;break}let s=e;e=null;try{let e=a?a.component(o):Object.assign(document.createElement(`h1`),{textContent:`404`});i.replaceChildren(e instanceof Node?e:document.createTextNode(e??``))}finally{e=s}}),i};f.go=e=>{let t=e.startsWith(`/`)?e:`/${e}`;window.location.hash!==`#${t}`&&(window.location.hash=t)},a.effect=o,a.component=l,a.fetch=u,a.router=f,a.ws=(e,t={})=>{let{reconnect:n=!0,maxReconnect:r=5,reconnectInterval:i=1e3}=t,s=a(`disconnected`),c=a([]),l=a(null),u=null,d=0,f=null,p=()=>{s(`connecting`),u=new WebSocket(e),u.onopen=()=>{s(`connected`),d=0,l(null)},u.onmessage=e=>{let t=e.data;c([...c(),t])},u.onerror=e=>{l(e),s(`error`)},u.onclose=()=>{s(`disconnected`),n&&d{d++,p()},i*2**d))}},m=e=>{u?.readyState===WebSocket.OPEN&&u.send(typeof e==`string`?e:JSON.stringify(e))},h=()=>{f&&clearTimeout(f),u&&=(u.close(),null)};return p(),o?.onCleanup&&o.onCleanup(h),{status:s,messages:c,error:l,send:m,close:h}},a.storage=s;var e=null,t=new Set,n=!1,r=0,i=()=>{if(n=!1,r++,r>100)throw t.clear(),r=0,Error(`SigPro: Infinite reactive loop detected.`);try{let e=Array.from(t);t.clear();for(let t of e)t.run()}catch(e){console.error(`SigPro Flush Error:`,e)}finally{setTimeout(()=>{r=0},0)}},a=r=>{let a=new Set;if(typeof r==`function`){let n=!0,i,o={dependencies:new Set,cleanupHandlers:new Set,markDirty:()=>{n||(n=!0,a.forEach(e=>{e.markDirty&&e.markDirty(),t.add(e)}))},run:()=>{o.dependencies.forEach(e=>e.delete(o)),o.dependencies.clear();let t=e;e=o;try{i=r()}finally{e=t,n=!1}}};return()=>(e&&(a.add(e),e.dependencies.add(a)),n&&o.run(),i)}return(...o)=>{if(o.length){let e=typeof o[0]==`function`?o[0](r):o[0];Object.is(r,e)||(r=e,a.forEach(e=>{e.markDirty&&e.markDirty(),t.add(e)}),!n&&t.size&&(n=!0,queueMicrotask(i)))}return e&&(a.add(e),e.dependencies.add(a)),r}},o=t=>{let n={dependencies:new Set,cleanupHandlers:new Set,run(){this.cleanupHandlers.forEach(e=>e()),this.cleanupHandlers.clear(),this.dependencies.forEach(e=>e.delete(this)),this.dependencies.clear();let n=e;e=this;try{let e=t();typeof e==`function`&&(this.cleanupFunction=e)}finally{e=n}},stop(){this.cleanupHandlers.forEach(e=>e()),this.dependencies.forEach(e=>e.delete(this)),this.cleanupFunction?.()}};return e&&e.cleanupHandlers.add(()=>n.stop()),n.run(),()=>n.stop()},s=(e,t,n=localStorage)=>{let r;try{let i=n.getItem(e);r=i===null?t:JSON.parse(i)}catch(i){console.warn(`Error reading ${e} from storage:`,i),r=t,n.removeItem(e)}let i=a(r);return o(()=>{try{let t=i();t==null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch(t){console.warn(`Error saving ${e} to storage:`,t)}}),i},c=(e,...t)=>{let n=c._templateCache??=new WeakMap,r=(e,t)=>t.reduce((e,t)=>e?.childNodes?.[t],e),i=(e,t)=>{let n=e.textContent.split(`{{part}}`),r=e.parentNode,i=0;n.forEach((a,s)=>{if(a&&r.insertBefore(document.createTextNode(a),e),s{let e=typeof n==`function`?n():n;if(e===c)return;if(c=e,typeof e!=`object`&&!Array.isArray(e)){let t=a.nextSibling,n=String(e??``);if(t!==s&&t?.nodeType===3)t.textContent=n;else{for(;a.nextSibling!==s;)r.removeChild(a.nextSibling);r.insertBefore(document.createTextNode(n),s)}return}for(;a.nextSibling!==s;)r.removeChild(a.nextSibling);let t=Array.isArray(e)?e:[e],i=document.createDocumentFragment();t.forEach(e=>{if(e==null||e===!1)return;let t=e instanceof Node?e:document.createTextNode(e);i.appendChild(t)}),r.insertBefore(i,s)})}}),e.remove()},a=n.get(e);if(!a){let t=document.createElement(`template`);t.innerHTML=e.join(`{{part}}`);let r=[],i=document.createTreeWalker(t.content,133),o=e=>{let n=[];for(;e&&e!==t.content;){let t=0;for(let n=e.previousSibling;n;n=n.previousSibling)t++;n.push(t),e=e.parentNode}return n.reverse()},s;for(;s=i.nextNode();){let e=!1,t={type:s.nodeType,path:o(s),parts:[]};if(s.nodeType===1)for(let n=0;n({node:r(s,e.path),info:e})).forEach(({node:e,info:n})=>{if(e){if(n.type===1)n.parts.forEach(n=>{let r=t[l++],i=n.name,a=i[0];if(a===`@`){let[t,...n]=i.slice(1).split(`.`),a=i=>{if(n.includes(`prevent`)&&i.preventDefault(),n.includes(`stop`)&&i.stopPropagation(),!(n.includes(`self`)&&i.target!==e)){if(n.some(e=>e.startsWith(`debounce`))){let t=n.find(e=>e.startsWith(`debounce`))?.split(`:`)[1]||300;clearTimeout(e._debounceTimer),e._debounceTimer=setTimeout(()=>r(i),t);return}n.includes(`once`)&&e.removeEventListener(t,a),r(i)}};e.addEventListener(t,a,{passive:n.includes(`passive`),capture:n.includes(`capture`)}),o.onCleanup&&o.onCleanup(()=>e.removeEventListener(t,a))}else if(a===`:`){let t=i.slice(1),n=e.type===`checkbox`||e.type===`radio`?`change`:`input`;o(()=>{let n=typeof r==`function`?r():r;e[t]!==n&&(e[t]=n)}),e.addEventListener(n,()=>{let t=n===`change`?e.checked:e.value;typeof r==`function`&&r(t)})}else if(a===`?`){let t=i.slice(1);o(()=>{let n=typeof r==`function`?r():r;e.toggleAttribute(t,!!n)})}else if(a===`.`){let t=i.slice(1);o(()=>{let n=typeof r==`function`?r():r;e[t]=n,n!=null&&typeof n!=`object`&&typeof n!=`boolean`&&e.setAttribute(t,n)})}else typeof r==`function`?o(()=>e.setAttribute(i,r())):e.setAttribute(i,r)});else if(n.type===3){let n=e.textContent.split(`{{part}}`).length-1;i(e,t.slice(l,l+n)),l+=n}}}),s},l=(e,t,n=[])=>{customElements.get(e)||customElements.define(e,class extends HTMLElement{static get observedAttributes(){return n}constructor(){super(),this._propertySignals={},this.cleanupFunctions=[],n.forEach(e=>this._propertySignals[e]=a(void 0))}connectedCallback(){let e=[...this.childNodes];this.innerHTML=``,n.forEach(e=>{let t=this.hasOwnProperty(e)?this[e]:this.getAttribute(e);Object.defineProperty(this,e,{get:()=>this._propertySignals[e](),set:t=>{let n=t===`false`?!1:t===``&&e!==`value`?!0:t;this._propertySignals[e](n)},configurable:!0}),t!=null&&(this[e]=t)});let r={select:e=>this.querySelector(e),slot:t=>e.filter(e=>{let n=e.nodeType===1?e.getAttribute(`slot`):null;return t?n===t:!n}),emit:(e,t)=>this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),host:this,onUnmount:e=>this.cleanupFunctions.push(e)},i=t(this._propertySignals,r);i instanceof Node&&this.appendChild(i)}attributeChangedCallback(e,t,n){this[e]!==n&&(this[e]=n)}disconnectedCallback(){this.cleanupFunctions.forEach(e=>e()),this.cleanupFunctions=[]}})},u=async(e,t,n)=>{n&&n(!0);try{let n=await(await fetch(e,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})).text();try{return JSON.parse(n)}catch{return console.warn(`Invalid JSON response`),null}}catch{return null}finally{n&&n(!1)}},d=e=>String(e).replace(/[<>"']/g,``),f=t=>{let n=()=>window.location.hash.replace(/^#/,``)||`/`,r=a(n()),i=document.createElement(`div`);return i.style.display=`contents`,window.addEventListener(`hashchange`,()=>{let e=d(n());r()!==e&&r(e)}),o(()=>{let n=r(),a=null,o={};for(let e of t)if(e.path instanceof RegExp){let t=n.match(e.path);if(t){a=e,o=t.groups||{id:t[1]};break}}else if(e.path===n){a=e;break}let s=e;e=null;try{let e=a?a.component(o):Object.assign(document.createElement(`h1`),{textContent:`404`});i.replaceChildren(e instanceof Node?e:document.createTextNode(e??``))}finally{e=s}}),i};f.go=e=>{let t=e.startsWith(`/`)?e:`/${e}`;window.location.hash!==`#${t}`&&(window.location.hash=t)},a.effect=o,a.component=l,a.fetch=u,a.router=f,a.ws=(e,t={})=>{let{reconnect:n=!0,maxReconnect:r=5,reconnectInterval:i=1e3}=t,s=a(`disconnected`),c=a([]),l=a(null),u=null,d=0,f=null,p=()=>{s(`connecting`),u=new WebSocket(e),u.onopen=()=>{s(`connected`),d=0,l(null)},u.onmessage=e=>{let t=e.data;c([...c(),t])},u.onerror=e=>{l(e),s(`error`)},u.onclose=()=>{s(`disconnected`),n&&d{d++,p()},i*2**d))}},m=e=>{u?.readyState===WebSocket.OPEN&&u.send(typeof e==`string`?e:JSON.stringify(e))},h=()=>{f&&clearTimeout(f),u&&=(u.close(),null)};return p(),o?.onCleanup&&o.onCleanup(h),{status:s,messages:c,error:l,send:m,close:h}},a.storage=s;export { a as $, c as html }; +let activeEffect=null;const effectQueue=new Set;let isFlushScheduled=!1,flushCount=0;const flushEffectQueue=()=>{if(isFlushScheduled=!1,flushCount++,flushCount>100)throw effectQueue.clear(),flushCount=0,new Error("SigPro: Infinite reactive loop detected.");try{const e=Array.from(effectQueue);effectQueue.clear();for(const t of e)t.run()}catch(e){console.error("SigPro Flush Error:",e)}finally{setTimeout((()=>{flushCount=0}),0)}};export const $=e=>{const t=new Set;if("function"==typeof e){let n,o=!0;const c={dependencies:new Set,cleanupHandlers:new Set,markDirty:()=>{o||(o=!0,t.forEach((e=>{e.markDirty&&e.markDirty(),effectQueue.add(e)})))},run:()=>{c.dependencies.forEach((e=>e.delete(c))),c.dependencies.clear();const t=activeEffect;activeEffect=c;try{n=e()}finally{activeEffect=t,o=!1}}};return()=>(activeEffect&&(t.add(activeEffect),activeEffect.dependencies.add(t)),o&&c.run(),n)}return(...n)=>{if(n.length){const o="function"==typeof n[0]?n[0](e):n[0];Object.is(e,o)||(e=o,t.forEach((e=>{e.markDirty&&e.markDirty(),effectQueue.add(e)})),!isFlushScheduled&&effectQueue.size&&(isFlushScheduled=!0,queueMicrotask(flushEffectQueue)))}return activeEffect&&(t.add(activeEffect),activeEffect.dependencies.add(t)),e}};const $e=e=>{const t={dependencies:new Set,cleanupHandlers:new Set,run(){this.cleanupHandlers.forEach((e=>e())),this.cleanupHandlers.clear(),this.dependencies.forEach((e=>e.delete(this))),this.dependencies.clear();const t=activeEffect;activeEffect=this;try{const t=e();"function"==typeof t&&(this.cleanupFunction=t)}finally{activeEffect=t}},stop(){this.cleanupHandlers.forEach((e=>e())),this.dependencies.forEach((e=>e.delete(this))),this.cleanupFunction?.()}};return activeEffect&&activeEffect.cleanupHandlers.add((()=>t.stop())),t.run(),()=>t.stop()},$s=(e,t,n=localStorage)=>{let o;try{const c=n.getItem(e);o=null!==c?JSON.parse(c):t}catch(c){console.warn(`Error reading ${e} from storage:`,c),o=t,n.removeItem(e)}const c=$(o);return $e((()=>{try{const t=c();null==t?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch(t){console.warn(`Error saving ${e} to storage:`,t)}})),c};export const html=(e,...t)=>{const n=html._templateCache??(html._templateCache=new WeakMap);let o=n.get(e);if(!o){const t=document.createElement("template");t.innerHTML=e.join("{{part}}");const c=[],s=document.createTreeWalker(t.content,133),r=e=>{const n=[];for(;e&&e!==t.content;){let t=0;for(let n=e.previousSibling;n;n=n.previousSibling)t++;n.push(t),e=e.parentNode}return n.reverse()};let i;for(;i=s.nextNode();){let e=!1;const t={type:i.nodeType,path:r(i),parts:[]};if(1===i.nodeType)for(let n=0;n{return{node:(t=c,n=e.path,n.reduce(((e,t)=>e?.childNodes?.[t]),t)),info:e};var t,n})).forEach((({node:e,info:n})=>{if(e)if(1===n.type)n.parts.forEach((n=>{const o=t[s++],c=n.name,r=c[0];if("@"===r){const[t,...n]=c.slice(1).split("."),s=c=>{if(n.includes("prevent")&&c.preventDefault(),n.includes("stop")&&c.stopPropagation(),!n.includes("self")||c.target===e){if(n.some((e=>e.startsWith("debounce")))){const t=n.find((e=>e.startsWith("debounce")))?.split(":")[1]||300;return clearTimeout(e._debounceTimer),void(e._debounceTimer=setTimeout((()=>o(c)),t))}n.includes("once")&&e.removeEventListener(t,s),o(c)}};e.addEventListener(t,s,{passive:n.includes("passive"),capture:n.includes("capture")}),$e.onCleanup&&$e.onCleanup((()=>e.removeEventListener(t,s)))}else if(":"===r){const t=c.slice(1),n="checkbox"===e.type||"radio"===e.type?"change":"input";$e((()=>{const n="function"==typeof o?o():o;e[t]!==n&&(e[t]=n)})),e.addEventListener(n,(()=>{const t="change"===n?e.checked:e.value;"function"==typeof o&&o(t)}))}else if("?"===r){const t=c.slice(1);$e((()=>{const n="function"==typeof o?o():o;e.toggleAttribute(t,!!n)}))}else if("."===r){const t=c.slice(1);$e((()=>{let n="function"==typeof o?o():o;e[t]=n,null!=n&&"object"!=typeof n&&"boolean"!=typeof n&&e.setAttribute(t,n)}))}else"function"==typeof o?$e((()=>e.setAttribute(c,o()))):e.setAttribute(c,o)}));else if(3===n.type){const n=e.textContent.split("{{part}}").length-1;((e,t)=>{const n=e.textContent.split("{{part}}"),o=e.parentNode;let c=0;n.forEach(((s,r)=>{if(s&&o.insertBefore(document.createTextNode(s),e),r{let e="function"==typeof n?n():n;if(e===i)return;if(i=e,"object"!=typeof e&&!Array.isArray(e)){const t=s.nextSibling,n=String(e??"");if(t!==r&&3===t?.nodeType)t.textContent=n;else{for(;s.nextSibling!==r;)o.removeChild(s.nextSibling);o.insertBefore(document.createTextNode(n),r)}return}for(;s.nextSibling!==r;)o.removeChild(s.nextSibling);const t=Array.isArray(e)?e:[e],c=document.createDocumentFragment();t.forEach((e=>{if(null==e||!1===e)return;const t=e instanceof Node?e:document.createTextNode(e);c.appendChild(t)})),o.insertBefore(c,r)}))}})),e.remove()})(e,t.slice(s,s+n)),s+=n}})),c};const $c=(e,t,n=[])=>{customElements.get(e)||customElements.define(e,class extends HTMLElement{static get observedAttributes(){return n}constructor(){super(),this._propertySignals={},this.cleanupFunctions=[],n.forEach((e=>this._propertySignals[e]=$(void 0)))}connectedCallback(){const e=[...this.childNodes];this.innerHTML="",n.forEach((e=>{const t=this.hasOwnProperty(e)?this[e]:this.getAttribute(e);Object.defineProperty(this,e,{get:()=>this._propertySignals[e](),set:t=>{const n="false"!==t&&(""===t&&"value"!==e||t);this._propertySignals[e](n)},configurable:!0}),null!=t&&(this[e]=t)}));const o={select:e=>this.querySelector(e),slot:t=>e.filter((e=>{const n=1===e.nodeType?e.getAttribute("slot"):null;return t?n===t:!n})),emit:(e,t)=>this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0})),host:this,onUnmount:e=>this.cleanupFunctions.push(e)},c=t(this._propertySignals,o);c instanceof Node&&this.appendChild(c)}attributeChangedCallback(e,t,n){this[e]!==n&&(this[e]=n)}disconnectedCallback(){this.cleanupFunctions.forEach((e=>e())),this.cleanupFunctions=[]}})},$f=async(e,t,n)=>{n&&n(!0);try{const n=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),o=await n.text();try{return JSON.parse(o)}catch(e){return console.warn("Invalid JSON response"),null}}catch(e){return null}finally{n&&n(!1)}},sanitizePath=e=>String(e).replace(/[<>"']/g,""),$r=e=>{const t=()=>window.location.hash.replace(/^#/,"")||"/",n=$(t()),o=document.createElement("div");return o.style.display="contents",window.addEventListener("hashchange",(()=>{const e=(o=t(),String(o).replace(/[<>"']/g,""));var o;n()!==e&&n(e)})),$e((()=>{const t=n();let c=null,s={};for(const n of e)if(n.path instanceof RegExp){const e=t.match(n.path);if(e){c=n,s=e.groups||{id:e[1]};break}}else if(n.path===t){c=n;break}const r=activeEffect;activeEffect=null;try{const e=c?c.component(s):Object.assign(document.createElement("h1"),{textContent:"404"});o.replaceChildren(e instanceof Node?e:document.createTextNode(e??""))}finally{activeEffect=r}})),o};$r.go=e=>{const t=e.startsWith("/")?e:`/${e}`;window.location.hash!==`#${t}`&&(window.location.hash=t)};const $ws=(e,t={})=>{const{reconnect:n=!0,maxReconnect:o=5,reconnectInterval:c=1e3}=t,s=$("disconnected"),r=$([]),i=$(null);let a=null,l=0,u=null;const f=()=>{s("connecting"),a=new WebSocket(e),a.onopen=()=>{s("connected"),l=0,i(null)},a.onmessage=e=>{const t=e.data;r([...r(),t])},a.onerror=e=>{i(e),s("error")},a.onclose=()=>{s("disconnected"),n&&l{l++,f()}),c*Math.pow(2,l)))}},d=()=>{u&&clearTimeout(u),a&&(a.close(),a=null)};return f(),$e?.onCleanup&&$e.onCleanup(d),{status:s,messages:r,error:i,send:e=>{a?.readyState===WebSocket.OPEN&&a.send("string"==typeof e?e:JSON.stringify(e))},close:d}};$.effect=$e,$.component=$c,$.fetch=$f,$.router=$r,$.ws=$ws,$.storage=$s;