@jasonshimmy/custom-elements-runtime 0.0.9-beta.5 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/custom-elements-runtime.cjs.js +9 -9
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +77 -71
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +6 -6
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,7 +51,8 @@ No config needed — TypeScript support is built-in.
|
|
|
51
51
|
|
|
52
52
|
## ⚠️ Things to Know
|
|
53
53
|
|
|
54
|
-
- Templates need a single root node (fragments allowed with keys)
|
|
54
|
+
- Templates need a single root node (fragments allowed with keys)
|
|
55
|
+
- Always use helpers (e.g.; `html`, `compile`, `css`) to sanitize templates and styles
|
|
55
56
|
- One handler per event type per element
|
|
56
57
|
- User input takes priority over programmatic changes
|
|
57
58
|
- SSR hydration is opt-in (`data-hydrate`)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var O=typeof document<"u"?document.currentScript:null;function $(e){let t=new Proxy(e,{set:(i,a,c)=>(i[a]=c,s(),!0)});const r=[];function n(i){r.push(i),i(t)}function o(){return t}function s(){r.forEach(i=>i(t))}return{subscribe:n,getState:o}}class g extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return g.instance||(g.instance=new g),g.instance}emit(t,r){const n=Date.now(),o=this.eventCounters.get(t);if(!o||n-o.window>1e3)this.eventCounters.set(t,{count:1,window:n});else if(o.count++,o.count>50&&(console.error(`Event storm detected for "${t}": ${o.count} events in 1 second. Throttling...`),o.count>100)){console.warn(`Blocking further "${t}" events to prevent infinite loop`);return}this.dispatchEvent(new CustomEvent(t,{detail:r,bubbles:!1,cancelable:!0}));const s=this.handlers[t];s&&s.forEach(i=>{try{i(r)}catch(a){console.error(`Error in global event handler for "${t}":`,a)}})}on(t,r){return this.handlers[t]||(this.handlers[t]=new Set),this.handlers[t].add(r),()=>this.off(t,r)}off(t,r){const n=this.handlers[t];n&&n.delete(r)}offAll(t){delete this.handlers[t]}listen(t,r,n){return this.addEventListener(t,r,n),()=>this.removeEventListener(t,r)}once(t,r){return new Promise(n=>{const o=this.on(t,s=>{o(),r(s),n(s)})})}getActiveEvents(){return Object.keys(this.handlers).filter(t=>this.handlers[t]&&this.handlers[t].size>0)}clear(){this.handlers={}}getHandlerCount(t){return this.handlers[t]?.size||0}getEventStats(){const t={};for(const[r,n]of this.eventCounters.entries())t[r]={count:n.count,handlersCount:this.getHandlerCount(r)};return t}resetEventCounters(){this.eventCounters.clear()}}const C=g.getInstance(),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var O=typeof document<"u"?document.currentScript:null;function $(e){let t=new Proxy(e,{set:(i,a,c)=>(i[a]=c,s(),!0)});const r=[];function n(i){r.push(i),i(t)}function o(){return t}function s(){r.forEach(i=>i(t))}return{subscribe:n,getState:o}}class g extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return g.instance||(g.instance=new g),g.instance}emit(t,r){const n=Date.now(),o=this.eventCounters.get(t);if(!o||n-o.window>1e3)this.eventCounters.set(t,{count:1,window:n});else if(o.count++,o.count>50&&(console.error(`Event storm detected for "${t}": ${o.count} events in 1 second. Throttling...`),o.count>100)){console.warn(`Blocking further "${t}" events to prevent infinite loop`);return}this.dispatchEvent(new CustomEvent(t,{detail:r,bubbles:!1,cancelable:!0}));const s=this.handlers[t];s&&s.forEach(i=>{try{i(r)}catch(a){console.error(`Error in global event handler for "${t}":`,a)}})}on(t,r){return this.handlers[t]||(this.handlers[t]=new Set),this.handlers[t].add(r),()=>this.off(t,r)}off(t,r){const n=this.handlers[t];n&&n.delete(r)}offAll(t){delete this.handlers[t]}listen(t,r,n){return this.addEventListener(t,r,n),()=>this.removeEventListener(t,r)}once(t,r){return new Promise(n=>{const o=this.on(t,s=>{o(),r(s),n(s)})})}getActiveEvents(){return Object.keys(this.handlers).filter(t=>this.handlers[t]&&this.handlers[t].size>0)}clear(){this.handlers={}}getHandlerCount(t){return this.handlers[t]?.size||0}getEventStats(){const t={};for(const[r,n]of this.eventCounters.entries())t[r]={count:n.count,handlersCount:this.getHandlerCount(r)};return t}resetEventCounters(){this.eventCounters.clear()}}const C=g.getInstance(),et=typeof window>"u"||typeof document>"u";function rt(e){return{state:e,emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{},render:()=>{}}}function U(e,t={}){et||console.warn("[SSR] renderToString should only be used on the server");try{const r=e.state,n=rt(r),o=e.template(r,n);let s="";t.includeStyles&&e.style&&(s=`<style>${typeof e.style=="function"?e.style(r):e.style}</style>`);const i=t.sanitizeAttributes?t.sanitizeAttributes(e.attrs||{}):e.attrs||{},a=Object.entries(i).map(([u,d])=>`${W(u)}="${W(d)}"`).join(" "),l=`${a?`<${e.tag} ${a}>`:`<${e.tag}>`}${s}${o}</${e.tag}>`;return t.prettyPrint?ot(l):l}catch(r){return console.error(`[SSR] Error rendering ${e.tag}:`,r),`<${e.tag}><div style="color: red;">SSR Error: ${it(String(r))}</div></${e.tag}>`}}function nt(e,t={}){const r={components:new Map,styles:new Set},n=[];e.forEach(i=>{if(r.components.set(i.tag,i),i.style){const c=typeof i.style=="function"?i.style(i.state):i.style;r.styles.add(c)}const a=U(i,{...t,includeStyles:!1});n.push(a)});const o=Array.from(r.styles).join(`
|
|
2
2
|
`);return{html:n.join(`
|
|
3
|
-
`),styles:o,context:r}}function
|
|
3
|
+
`),styles:o,context:r}}function st(e){const t=Array.from(e.components.entries()).map(([r,n])=>({tag:r,state:n.state}));return`
|
|
4
4
|
<script type="module">
|
|
5
5
|
// Hydration data from SSR
|
|
6
6
|
window.__SSR_CONTEXT__ = ${JSON.stringify({components:t})};
|
|
@@ -33,22 +33,22 @@
|
|
|
33
33
|
// Clean up
|
|
34
34
|
delete window.__SSR_CONTEXT__;
|
|
35
35
|
}
|
|
36
|
-
<\/script>`.trim()}const
|
|
36
|
+
<\/script>`.trim()}const it=e=>e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),W=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),ot=e=>e.replace(/></g,`>
|
|
37
37
|
<`).split(`
|
|
38
38
|
`).map(t=>{const r=(t.match(/^<[^\/]/g)||[]).length-(t.match(/<\//g)||[]).length;return" ".repeat(Math.max(0,r))+t.trim()}).join(`
|
|
39
|
-
`);function F(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function j(e,t){if(typeof e!="string"||!t)return String(e);for(const r in t){if(typeof t[r]=="string"&&e===t[r])return F(e);if(Array.isArray(t[r])){for(const n of t[r])if(n&&typeof n=="object"){for(const o in n)if(typeof n[o]=="string"&&e===n[o])return F(e)}}}return String(e)}function T(e,...t){function r(n,o,s){if(Array.isArray(n)){const i=n.map(a=>r(a,o,s));return i.some(a=>a instanceof Promise)?Promise.all(i).then(a=>a.join("")):i.join("")}if(typeof n=="function"){const i=r(n(o,s),o,s);return i instanceof Promise,i}return n==null?"":n instanceof Promise?n:String(n)}return(n,o)=>{let s="",i=!1;const a=[];for(let c=0;c<e.length;c++)if(s+=e[c],c<t.length){let l=t[c];const u=e[c],d=/data-on-[a-z]+="?$/.test(u);l=r(l,n,o),l instanceof Promise?(i=!0,a.push(l)):/=\s*"?$/.test(u)&&typeof l=="string"&&!d?(l=l.replace(/"/g,""").replace(/'/g,"'"),s+=l):!d&&!/=\s*"?$/.test(u)?s+=j(l,n):s+=l}return i?Promise.all(a).then(c=>{let l="",u=0;for(let d=0;d<e.length;d++)if(l+=e[d],d<t.length){let f=t[d];const h=e[d],m=/data-on-[a-z]+="?$/.test(h);f=r(f,n,o),f instanceof Promise?l+=c[u++]:/=\s*"?$/.test(h)&&typeof f=="string"&&!m?(f=f.replace(/"/g,""").replace(/'/g,"'"),l+=f):!m&&!/=\s*"?$/.test(h)?l+=j(f,n):l+=f}return l}):s}}function ot(e,...t){const r="compiled-"+Math.random().toString(36).slice(2);function n(s,i,a){return Array.isArray(s)?s.map(c=>n(c,i,a)).join(""):typeof s=="function"?n(s(i,a),i,a):s==null?"":String(s)}const o=(s,i)=>{let a="";for(let c=0;c<e.length;c++)if(a+=e[c],c<t.length){let l=t[c];const u=e[c],d=/data-on-[a-z]+="?$/.test(u);l=n(l,s,i),/=\s*"?$/.test(u)&&typeof l=="string"&&!d?(l=l.replace(/"/g,""").replace(/'/g,"'"),a+=l):!d&&!/=\s*"?$/.test(u)?a+=j(l,s):a+=l??""}return a};return o.id=r,o}function K(e,...t){let r="";for(let n=0;n<e.length;n++)r+=e[n],n<t.length&&(r+=t[n]??"");return r}function at(e){return Object.keys(e).filter(t=>e[t]).join(" ")}function ct(e){return Object.entries(e).map(([t,r])=>`${t}: ${r}`).join("; ")}function B(e,t,r){const[n,...o]=r.split("|").map(a=>a.trim());if(!n||n==="__proto__"||n==="constructor"||n==="prototype")return;function s(a,c,l){const u=c.split(".");let d=a;for(let f=0;f<u.length-1;f++)u[f]in d||(d[u[f]]={}),d=d[u[f]];d[u[u.length-1]]=l}const i=a=>{let c;if(e instanceof HTMLInputElement&&e.type==="checkbox"){c=e.value;const l=e.getAttribute("data-true-value"),u=e.getAttribute("data-false-value");let d=Array.isArray(t[n])?t[n]:void 0;if(d){if(e.checked)d.includes(c)||d.push(c);else{const f=d.indexOf(c);f!==-1&&d.splice(f,1)}s(t,n,[...d])}else l!==null||u!==null?e.checked?s(t,n,l):s(t,n,u!==null?u:!1):s(t,n,e.checked)}else e instanceof HTMLInputElement&&e.type==="radio"?(c=e.value,s(t,n,c),((e.form||e.closest("form")||e.getRootNode())instanceof Element?(e.form||e.closest("form")||e.getRootNode()).querySelectorAll(`input[type="radio"][name="${e.name}"][data-model="${r}"]`):[]).forEach(u=>{u.checked=u.value===String(c)})):(c=e.value,e instanceof HTMLInputElement&&e.type==="number"&&(c=Number(c)),o.includes("trim")&&typeof c=="string"&&(c=c.trim()),o.includes("number")&&(c=Number(c)),s(t,n,c));if("_vnode"in e&&typeof e._vnode=="object"&&e._vnode?.props&&(e._vnode.props.value=c),a.type==="input"&&(e._isDirty=!0),a.type==="keydown"&&a.key==="Enter"&&(e._isDirty=!1,e instanceof HTMLElement&&e.isConnected)){let l=e.parentElement;for(;l&&!(l instanceof HTMLElement&&l.shadowRoot);)l=l.parentElement;l&&typeof l=="object"&&l!==null&&"render"in l&&typeof l.render=="function"&&l.render()}a.type==="blur"&&(e._isDirty=!1)};e.addEventListener("input",i),e.addEventListener("change",i),e.addEventListener("keydown",i),e.addEventListener("blur",i)}const z=(()=>{try{if(typeof process<"u"&&process.env)return process.env.NODE_ENV==="development"}catch{}return typeof window<"u"?window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1":!1})();function lt(e,t={}){const{development:r=z,cache:n=!0,optimize:o=!0}=t,s=Z(e);if(n&&L.has(s)){if(r){const i=A.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheHits++,A.set(s,i)}return L.get(s)}if(r){const i=A.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheMisses++,A.set(s,i)}try{const i=dt(e,{development:r,optimize:o});return n&&L.set(s,i),i}catch(i){return r&&(console.error("[Template Compiler] Error compiling template:",i),console.error("[Template Compiler] Template:",e)),{statics:[e],dynamics:[],fragment:null,id:s,hasDynamics:!1,render:()=>e}}}function ut(e,t){if(typeof document>"u")return[0];try{let r=function(a,c=[]){if(a.nodeType===Node.TEXT_NODE){if(a.textContent?.includes(t))return c}else if(a.nodeType===Node.ELEMENT_NODE){let l=0;for(let u=0;u<a.childNodes.length;u++){const d=a.childNodes[u],f=r(d,[...c,l]);if(f)return f;l++}}return null};const s=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html").body.firstElementChild;return r(s)||[0]}catch(r){return z&&console.warn("[Template Compiler] Error finding DOM path for placeholder:",t,r),[0]}}function dt(e,t){return new ft(e,t).compile()}class ft{template;options;dynamics=[];statics=[];constructor(t,r){this.template=t,this.options=r}compile(){this.parseTemplate();const t=this.createStaticFragment(),r=Z(this.template),n=(o,s)=>{let i="";for(let a=0;a<this.statics.length;a++)if(i+=this.statics[a],a<this.dynamics.length){let c=this.dynamics[a].getValue(o,s);if(c instanceof Promise)return Promise.all(this.dynamics.map(l=>{const u=l.getValue(o,s);return u instanceof Promise?u:Promise.resolve(u)})).then(l=>{let u="";for(let d=0;d<this.statics.length;d++)u+=this.statics[d],d<l.length&&(u+=l[d]);return u});i+=c}return i};return{statics:this.statics,dynamics:this.dynamics,fragment:t,id:r,hasDynamics:this.dynamics.length>0,render:n}}parseTemplate(){const t=/\{\{([^}]+)\}\}/g;let r=0,n;for(;(n=t.exec(this.template))!==null;){const s=this.template.slice(r,n.index);this.statics.push(s);let i=s.match(/([a-zA-Z0-9_-]+)\s*=\s*"?$/),a=i?i[1]:void 0,c;if(s.endsWith('style="color:'))a="style",c="color";else if(a==="style"){const u=s.match(/style\s*=\s*"?([^:;]+):\s*$/);u&&(c=u[1].trim())}const l=n[1].trim();this.analyzeDynamicExpression(l,this.dynamics.length,a,c),r=n.index+n[0].length}const o=this.template.slice(r);this.statics.push(o)}analyzeDynamicExpression(t,r,n,o){let s="text",i;n?n==="class"?(s="class",i="class"):n==="style"?(s="style",i=o||"style"):n==="value"?(s="property",i="value"):(s="attribute",i=n):t.includes("class.")?(s="class",i=t.split(".")[1]):t.includes("style.")?(s="style",i=t.split(".")[1]):t.includes("@")?(s="event",i=t.split("@")[1]):t==="class"?(s="class",i="class"):t==="style"?(s="style",i="style"):t==="value"?(s="property",i="value"):t==="title"&&(s="attribute",i="title");const a=`__DYNAMIC_${r}__`,c=this.statics.join(a);let l=ut(c,a);this.statics.length===2&&s!=="text"?l=[0]:this.statics.length===2&&l.length===0&&(l=[0]),this.dynamics.push({path:l,type:s,target:i,getValue:this.createValueGetter(t)})}createValueGetter(t){return(r,n)=>{try{let o;if(t&&typeof t=="function")o=t(r);else if(typeof t=="string"&&t.startsWith("state.")){const s=t.slice(6);o=r[s]}else typeof t=="string"&&/^[a-zA-Z0-9_$]+$/.test(t)?o=r[t]:(typeof t=="string"&&t.includes("("),o="");return o}catch(o){return this.options.development&&console.warn(`[Template Compiler] Error evaluating expression: ${t}`,o),""}}}createStaticFragment(){if(typeof document>"u")return null;try{const t=this.statics.join("");if(!t.trim())return null;const n=new DOMParser().parseFromString(t,"text/html"),o=document.createDocumentFragment();for(;n.body.firstChild;)o.appendChild(n.body.firstChild);return o}catch(t){return this.options.development&&console.warn("[Template Compiler] Could not create static fragment:",t),null}}}function H(e,t){try{if(t.length===1&&t[0]===0&&e instanceof Element)return e;let r=e;for(let n=0;n<t.length;n++){const o=t[n];if(!r.childNodes||r.childNodes.length<=o)return null;r=r.childNodes[o]}return r}catch{return null}}function x(e,t,r){let n;return e.fragment&&!e.hasDynamics?n=e.fragment.cloneNode(!0):n=ht(e,t,r),n}function G(e,t,r,n,o){if(e.hasDynamics)for(const s of e.dynamics)try{const i=s.getValue(r,n);if(o!==void 0&&s.getValue(o,n)===i)continue;V(t,s,i)}catch(i){console.warn("[Template Compiler] Error applying update:",i)}}function ht(e,t,r){let n="";for(let a=0;a<e.statics.length;a++)if(n+=e.statics[a],a<e.dynamics.length){const c=e.dynamics[a];if(c.type==="text"||c.type==="attribute"){const l=c.getValue(t,r);n+=String(l??"")}else(c.type==="property"||c.type==="class"||c.type==="style")&&(n+="")}if(typeof document>"u")return new DocumentFragment;const s=new DOMParser().parseFromString(n,"text/html"),i=document.createDocumentFragment();for(;s.body.firstChild;)i.appendChild(s.body.firstChild);for(const a of e.dynamics){const c=a.getValue(t,r),l=H(i,a.path);V(l,a,c)}return i}function V(e,t,r){try{if(t.type==="text"){const o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let s=!1,i;for(;i=o.nextNode();){const c=i.textContent||"";if(c.includes("Count: ")){const l=c.replace(/Count: \d+/,`Count: ${r}`);i.textContent=l,s=!0}}if(s)return;const a=H(e,t.path);a&&a.nodeType===Node.TEXT_NODE&&(a.textContent=r==null?"":String(r));return}const n=H(e,t.path);if(!n)return;switch(t.type){case"attribute":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;r==null||r===""?o.removeAttribute(t.target):o.setAttribute(t.target,String(r))}break;case"property":n.nodeType===Node.ELEMENT_NODE&&t.target&&(n[t.target]=r??"",n.setAttribute(t.target,r==null?"":String(r)));break;case"class":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;o.className=r==null?"":String(r),o.setAttribute("class",r==null?"":String(r))}break;case"style":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;o.style[t.target]=r==null?"":String(r),o.setAttribute("style",r==null?`${t.target}:`:`${t.target}:${r}`)}break;default:throw new Error(`Unknown update type: ${t.type}`)}}catch(n){(typeof globalThis<"u"?globalThis.isDevelopment:z)&&console.warn("[Template Compiler] Error applying update:",t,n)}}const L=new Map,A=new Map;function Z(e){let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);t=(t<<5)-t+n,t=t&t}return`tpl_${Math.abs(t).toString(36)}`}function N(e,t,r,n,o){return n&&o?`${t}.${e}[${r}]:${n}:${o}`:n?`${t}.${e}[${r}]:${n}`:`${t}.${e}[${r}]`}function D(e,t,r){if(!(!e||!(e instanceof Element))&&e.contains(r)&&r.parentNode===e)try{e.replaceChild(t,r)}catch(n){console.error("[VDOM] safeReplaceChild: error replacing child",n,{parent:e,newChild:t,oldChild:r,parentHTML:e.outerHTML,newChildHTML:t.outerHTML,oldChildHTML:r.outerHTML})}}function y(e){if(e.type==="#whitespace")return null;if(e.type==="#text"){const r=document.createTextNode(e.props.nodeValue??"");return e.dom=r,r}const t=document.createElement(e.type);for(const[r,n]of Object.entries(e.props))r==="value"&&t instanceof HTMLInputElement?t.type==="radio"?t.setAttribute("value",n):(t.type,t.value=n,t.setAttribute("value",n)):t.setAttribute(r,n);e.dom=t;for(const r of e.children){const n=y(r);n&&t.appendChild(n)}return t}function X(e){const t=document.createElement("template");t.innerHTML=e.trim();const r=Array.from(t.content.childNodes);return r.length===1?w(r[0]):{type:"#fragment",key:void 0,props:{},children:r.map((o,s)=>w(o,"#fragment",s)),dom:void 0}}function w(e,t="",r=0){if(!e)return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0};if(e.nodeType===Node.TEXT_NODE)return!e.nodeValue||/^\s*$/.test(e.nodeValue)?{type:"#whitespace",key:void 0,props:{},children:[],dom:void 0}:{type:"#text",key:N("#text",t,r),props:{nodeValue:e.nodeValue},children:[],dom:e};if(e.nodeType===Node.ELEMENT_NODE){const n=e,o={};Array.from(n.attributes).forEach(l=>{o[l.name]=l.value});const s=n.tagName.toLowerCase();let i;if((s==="input"||s==="select"||s==="textarea")&&n.hasAttribute("data-model")){const l=n.getAttribute("data-model"),u=n.getAttribute("type")??"";i=`${s}:${l}:${u}`,o["data-uid"]=i,n.setAttribute("data-uid",i);let d=n.getAttribute("value"),f=n.getAttribute("checked");d&&(o.value=d),f&&(o.checked=f)}else s==="input"||s==="textarea"||s==="select"||n.hasAttribute("contenteditable")?(i=`${s}:${t}:${r}`,o["data-uid"]=i,n.setAttribute("data-uid",i)):(i=N(s,t,r),s==="li"&&(o["data-uid"]=i,n.setAttribute("data-uid",i)));const a=Array.from(n.childNodes).map((l,u)=>w(l,i,u));return{type:s,key:i,props:o,children:a,dom:n}}return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0}}function R(e,t,r){if(!t||!r)return;function n(c){return!!c&&c.type!=="#whitespace"&&!(c.type==="#text"&&(!c.props?.nodeValue||/^\s*$/.test(c.props.nodeValue)))}const o=Array.isArray(t.children)?t.children.filter(n):[],s=Array.isArray(r.children)?r.children.filter(n):[],i=r.type==="input"||r.type==="select"||r.type==="textarea";if(t.type!==r.type||t.key!==r.key){const c=y(r);if(c instanceof Node&&t.dom instanceof Node&&e.contains(t.dom)){if(D(e,c,t.dom),i&&r.props&&e.firstChild instanceof HTMLInputElement){const l=e.firstChild;l.type==="radio"||l.type,l.value=r.props.value,l.setAttribute("value",r.props.value),"checked"in r.props&&(l.checked=r.props.checked===!0||r.props.checked==="true")}}else if(c instanceof Node)if(c){if(e.appendChild(c),r.dom=c,i&&r.props&&e.firstChild instanceof HTMLInputElement){const l=e.firstChild;l.type==="radio"?l.setAttribute("value",r.props.value):(l.type,l.value=r.props.value,l.setAttribute("value",r.props.value)),"checked"in r.props&&(l.checked=r.props.checked===!0||r.props.checked==="true")}}else r.dom=void 0;else r.dom=void 0;return}if(i&&t.dom instanceof HTMLElement&&r.props){for(const[c,l]of Object.entries(r.props))if(c==="value"&&e.firstChild instanceof HTMLInputElement)e.firstChild.value=l;else if(c==="checked"&&e.firstChild instanceof HTMLInputElement)e.firstChild.checked=l===!0||l==="true";else if(c in t.dom)try{t.dom[c]=l}catch{}else t.dom.setAttribute(c,l);for(let c=r.children.length;c<o.length;c++)o[c]&&o[c].dom&&t.dom&&t.dom.contains(o[c].dom)&&t.dom.removeChild(o[c].dom);return}const a=t.dom;if(a&&a instanceof Element&&r.props){const c=a.tagName.toLowerCase()==="input"?a.getAttribute("type"):void 0,l=a.tagName.includes("-");for(const[u,d]of Object.entries(r.props))if(!(c==="radio"&&u==="value")){if(c==="checkbox"&&u==="value"){a.setAttribute("value",d);continue}a.setAttribute(u,d)}if(l)for(const[u,d]of Object.entries(r.props))a.setAttribute(u,d);for(const u of Array.from(a.attributes).map(d=>d.name))if(!(u in r.props)){if(c==="radio"&&u==="value"||c==="checkbox"&&u==="value")continue;a.removeAttribute(u)}}if(r.type==="#text"){if(a&&a.nodeType===Node.TEXT_NODE)a.nodeValue!==r.props.nodeValue&&(a.nodeValue=r.props.nodeValue),r.dom=a;else{const c=document.createTextNode(r.props.nodeValue??"");a&&e.contains(a)&&a.parentNode===e?D(e,c,a):e.appendChild(c),r.dom=c}return}if(a instanceof Element){const c=new Map;o.forEach(f=>f.key&&c.set(f.key,f));const l=new Set(s.map(f=>f.key));let u=[];for(let f=0;f<s.length;f++){const h=s[f],m=h.key?c.get(h.key):o[f];let p;const k=h.type==="input"||h.type==="select"||h.type==="textarea";if(m&&m.dom&&(!k||m.type===h.type&&m.key===h.key))R(a,m,h),p=m.dom;else{const _=y(h);if(p=_ instanceof Node?_:void 0,p){if((p instanceof Element||p instanceof Node)&&p.contains(a))throw console.error("[VDOM] Attempted to insert a parent into its own child:",{parentTag:a.tagName,childTag:p.tagName,parentUid:a.getAttribute?.("data-uid"),childUid:p.getAttribute?.("data-uid"),parent:a,child:p}),new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(p,a.childNodes[f]||null)}}h.dom=p,p&&u.push(p)}for(o.forEach(f=>{!l.has(f.key)&&f.dom&&a.contains(f.dom)&&a.removeChild(f.dom)});a.childNodes.length>s.length;)a.removeChild(a.lastChild);for(let f=0;f<u.length;f++)if(a.childNodes[f]!==u[f]){if((u[f]instanceof Element||u[f]instanceof Node)&&u[f].contains(a))throw new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(u[f],a.childNodes[f]||null)}r.dom=a;const d=new Set(s.map(f=>f.key));Array.from(a.childNodes).forEach((f,h)=>{const m=f.getAttribute?.("data-uid");(m&&!d.has(m)||h>=s.length)&&a.removeChild(f)})}}const pt=e=>e?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(e)):{},b=(e,t)=>{for(const r of e){const n=[],o=r.path.replace(/:[^/]+/g,a=>(n.push(a.slice(1)),"([^/]+)")),s=new RegExp(`^${o}$`),i=t.match(s);if(i){const a={};return n.forEach((c,l)=>{a[c]=i[l+1]}),{route:r,params:a}}}return{route:null,params:{}}},M={};async function Y(e){if(e.component)return e.component;if(e.load){if(M[e.path])return M[e.path];try{const t=await e.load();return M[e.path]=t.default,t.default}catch{throw new Error(`Failed to load component for route: ${e.path}`)}}throw new Error(`No component or loader defined for route: ${e.path}`)}function J(e){const{routes:t,base:r=""}=e;let n,o,s,i,a,c,l;if(typeof window<"u"&&typeof document<"u"){n=()=>{const d=new URL(window.location.href),f=d.pathname.replace(r,"")||"/",h=pt(d.search);return{path:f,query:h}},o=n();const u=b(t,o.path);s=$({path:o.path,params:u.params,query:o.query}),i=()=>{const d=n(),f=b(t,d.path),h=s.getState();h.path=d.path,h.params=f.params,h.query=d.query},window.addEventListener("popstate",i),a=d=>{window.history.pushState({},"",r+d),i()},c=d=>{window.history.replaceState({},"",r+d),i()},l=()=>window.history.back()}else{n=()=>({path:"/",query:{}}),o=n();const u=b(t,o.path);s=$({path:o.path,params:u.params,query:o.query}),i=()=>{},a=()=>{},c=()=>{},l=()=>{}}return{store:s,push:a,replace:c,back:l,subscribe:s.subscribe,matchRoute:u=>b(t,u),getCurrent:()=>s.getState(),resolveRouteComponent:Y}}function mt(e,t){return b(e,t)}function I(e,t){const r=[],n=t?Object.keys(t):[],o={...e};let s=null;function i(u){return r.push(u),()=>{const d=r.indexOf(u);d!==-1&&r.splice(d,1)}}function a(u){Object.assign(s,u),r.forEach(d=>d(s))}const c=new WeakMap;function l(u){if(c.has(u))return c.get(u);const d=new Proxy(u,{get(f,h,m){if(h==="subscribe")return i;if(h==="set")return a;if(t&&n.includes(h))return t[h](s);const p=Reflect.get(f,h,m);return typeof p=="object"&&p!==null?l(p):p},set(f,h,m,p){if(t&&n.includes(h))return!1;const k=f[h],_=Reflect.set(f,h,m,p);return k!==m&&r.forEach(Q=>Q(s)),_},deleteProperty(f,h){if(t&&n.includes(h))return!1;const m=Reflect.deleteProperty(f,h);return r.forEach(p=>p(s)),m}});return c.set(u,d),d}return s=l(o),s}const E=[];function yt(e){E.push(e)}function v(e,t=new WeakSet){if(e===null||typeof e!="object"||t.has(e))return e;if(t.add(e),Array.isArray(e))return e.map(o=>v(o,t));Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null&&Object.setPrototypeOf(e,null);const r=["__proto__","constructor","prototype"],n=Object.create(null);for(const o of Object.keys(e))r.includes(o)||(n[o]=v(e[o],t));return n}function S(e){return!!e&&typeof e.then=="function"}let P;typeof HTMLElement<"u"?P=class extends HTMLElement{syncStateToAttributes(){if(!this.stateObj||!this.config?.reflect||!Array.isArray(this.config.reflect))return;const e=["__proto__","constructor","prototype"];this.config.reflect.forEach(t=>{if(e.includes(t)){this.removeAttribute(t);return}const r=this.stateObj[t];["string","number","boolean"].includes(typeof r)?r==null?this.removeAttribute(t):this.setAttribute(t,String(r)):this.removeAttribute(t)})}setTemplate(e){const t=this.config;typeof e=="function"?t.template=e:t.template=()=>e,this.render()}_hasError=!1;_mountedCalled=!1;_unmountedCalled=!1;_autoWiredHandlers={};removeEventListener(e,t,r){super.removeEventListener(e,t,r),this._autoWiredHandlers[e]&&(this._autoWiredHandlers[e]=this._autoWiredHandlers[e].filter(n=>n===t?(super.removeEventListener(e,n,r),!1):!0),this._autoWiredHandlers[e].length===0&&delete this._autoWiredHandlers[e])}static get observedAttributes(){const e=this.stateObj||{};return Object.keys(e).filter(t=>["string","number","boolean"].includes(typeof e[t]))}attributeChangedCallback(e,t,r){if(e==="__proto__"||e==="constructor"||e==="prototype"||!this.stateObj)return;const n=e.replace(/-([a-z])/g,(s,i)=>i.toUpperCase()),o=e in this.stateObj?e:n in this.stateObj?n:null;if(o){const s=typeof this.config?.state?.[o];let i=r;if(r===null)i=void 0;else if(s==="number")if(i===void 0||i==="")i=this.config?.state?.[o];else{const a=Number(i);i=isNaN(a)?this.config?.state?.[o]:a}else s==="boolean"&&(i=i==="true");i=v(i),this.stateObj[o]!==i&&(this.config?.debug&&console.log("[runtime] state update:",{stateKey:o,value:i}),this.stateObj[o]=i,this.render())}}forceSyncControlledInputs(){this.shadowRoot&&(this.shadowRoot.querySelectorAll("input[data-model]").forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]),o=document.activeElement===r;r._hasDirtyListener||(r.addEventListener("input",()=>{r._isDirty=!0}),r.addEventListener("blur",()=>{r._isDirty=!1}),r._hasDirtyListener=!0);const s=!!r._isDirty;o||s||r.type!=="radio"&&r.type!=="checkbox"&&r.value!==n&&(r.value=n)}),this.rebindEventListeners())}syncControlledInputsAndEvents(){this.shadowRoot&&(this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]);r.checked=r.value===n}),this.shadowRoot.querySelectorAll("input[data-model]").forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]);if(r.type==="checkbox"){const o=this.stateObj[t];if(Array.isArray(o))r.checked=o.includes(r.value);else{const s=r.getAttribute("data-true-value"),i=r.getAttribute("data-false-value");s!==null||i!==null?String(o)===s?r.checked=!0:String(o)===i?r.checked=!1:o===!0?r.checked=!0:r.checked=!1:r.checked=o===!0||o==="true"||o===1}}else r.type==="radio"||(r.value=n)}),this.shadowRoot.querySelectorAll("textarea[data-model]").forEach(e=>{const t=e.getAttribute("data-model");!t||!this.stateObj||typeof this.stateObj[t]>"u"||(e.value=String(this.stateObj[t]))}),this.shadowRoot.querySelectorAll("select[data-model]").forEach(e=>{const t=e.getAttribute("data-model");!t||!this.stateObj||typeof this.stateObj[t]>"u"||(e.value=String(this.stateObj[t]))}))}attachListItemModelListeners(){this.shadowRoot&&this.shadowRoot.querySelectorAll("input[data-bind]").forEach(e=>{const t=e.getAttribute("data-bind");if(!t)return;e._listItemModelListener&&(e.removeEventListener("input",e._listItemModelListener),e.removeEventListener("change",e._listItemModelListener),delete e._listItemModelListener);const r=t.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);if(r){const[,o,s,i]=r,a=parseInt(s,10),c=this.stateObj[o];e instanceof HTMLInputElement&&e.type==="checkbox"&&(e.checked=!!(Array.isArray(c)&&c[a]&&c[a][i]));const l=u=>{!Array.isArray(c)||!c[a]||(e instanceof HTMLInputElement&&e.type==="checkbox"?c[a][i]=e.checked:c[a][i]=e.value)};e.addEventListener("input",l),e.addEventListener("change",l),e._listItemModelListener=l;return}const n=t.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);if(n){const[,o,s,i]=n,a=this.stateObj[o],c=i?i.split("|").map(u=>u.trim()).filter(Boolean):[];e instanceof HTMLInputElement&&e.type==="checkbox"?e.checked=!!(a&&a[s]):e instanceof HTMLInputElement&&(e.value=a?String(a[s]??""):"");const l=u=>{if(!a)return;let d;e instanceof HTMLInputElement&&e.type==="checkbox"?d=e.checked:(d=e.value,c.includes("number")&&(d=Number(d)),c.includes("trim")&&typeof d=="string"&&(d=d.trim())),a[s]=d};e.addEventListener("input",l),e.addEventListener("change",l),e._listItemModelListener=l}})}attachControlledInputListeners(){const e=this.shadowRoot;e&&(e.querySelectorAll("[data-model]").forEach(t=>{const r=t.getAttribute("data-model");r&&(t._dataModelBound||(B(t,this.stateObj,r),t._dataModelBound=!0))}),e.querySelectorAll("[data-model]").forEach(t=>{const[r]=t.getAttribute("data-model")?.split("|").map(n=>n.trim())??[];if(!(!r||!(r in this.stateObj)))if(t instanceof HTMLInputElement)if(t.type==="checkbox"){const n=this.stateObj[r],o=t.getAttribute("data-true-value"),s=t.getAttribute("data-false-value");Array.isArray(n)?t.checked=n.includes(t.value):o!==null||s!==null?String(n)===o?t.checked=!0:String(n)===s?t.checked=!1:n===!0?t.checked=!0:t.checked=!1:t.checked=n===!0||n==="true"||n===1}else t.type==="radio"?t.checked=t.value===String(this.stateObj[r]):t.value=String(this.stateObj[r]??"");else(t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t.value=String(this.stateObj[r]??""))}))}config;stateObj;api;_globalUnsubscribes=[];unsubscribes=[];lastCompiledTemplate=null;lastState=null;rafId=null;constructor(){super()}initializeConfig(){if(this.config)return;const e=this.tagName.toLowerCase(),r=(window.__componentRegistry||{})[e];if(!r||typeof r!="object")throw new Error("Invalid component config: must be an object");if(!r.state||typeof r.state!="object")throw new Error("Invalid component config: state must be an object");this.config=r;const n=r.computed?I(r.state,r.computed):I(r.state);if(this.stateObj=n,typeof this.stateObj.subscribe=="function"&&this.unsubscribes.push(this.stateObj.subscribe(()=>{this.scheduleRender()})),this.api={state:this.stateObj,emit:(s,i)=>this.dispatchEvent(new CustomEvent(s,{detail:i,bubbles:!0})),onGlobal:(s,i)=>{const a=C.on(s,i);return this._globalUnsubscribes.push(a),a},offGlobal:(s,i)=>C.off(s,i),emitGlobal:(s,i)=>C.emit(s,i),render:()=>this.render()},Object.keys(this.config).forEach(s=>{if(s.startsWith("on")&&s.length>2&&typeof this.config[s]=="function"){const i=s.charAt(2).toLowerCase()+s.slice(3),a=c=>{const l=c.detail??c;this.config[s](l,this.api.state,this.api)};this.addEventListener(i,a),this._autoWiredHandlers[i]||(this._autoWiredHandlers[i]=[]),this._autoWiredHandlers[i].push(a)}}),this.attachShadow({mode:"open"}),r.style){const s=document.createElement("style");s.textContent=typeof r.style=="function"?r.style(this.stateObj):r.style,this.shadowRoot.appendChild(s)}if(typeof this.config.hydrate=="function"){const s=this.shadowRoot?.querySelectorAll("[data-hydrate]");try{s&&s.length>0?s.forEach(i=>{try{this.config.hydrate(i,this.stateObj,this.api)}catch(a){typeof this.config.onError=="function"&&this.config.onError(a instanceof Error?a:new Error(String(a)),this.api.state,this.api),this._handleRenderError(a)}}):this.config.hydrate(this.shadowRoot,this.stateObj,this.api)}catch(i){typeof this.config.onError=="function"&&this.config.onError(i instanceof Error?i:new Error(String(i)),this.api.state,this.api),this._handleRenderError(i)}}if(this.hasAttribute("data-hydrated")?this.processRefs():this.render(),!this._mountedCalled&&typeof this.config.onMounted=="function")try{const s=this.config.onMounted(this.api.state,this.api);S(s)?s.catch(i=>{typeof this.config.onError=="function"&&this.config.onError(i,this.api.state,this.api),this._handleRenderError(i)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(s){typeof this.config.onError=="function"&&this.config.onError(s,this.api.state,this.api),this._handleRenderError(s),this._mountedCalled=!0}}connectedCallback(){if(this.initializeConfig(),this.stateObj)for(const e of this.getAttributeNames()){const r=e.replace(/-([a-z])/g,(n,o)=>o.toUpperCase());if(r in this.stateObj){const n=typeof this.config?.state?.[r];let o=this.getAttribute(e);n==="number"?o=Number(o):n==="boolean"&&(o=o==="true"),this.stateObj[r]=o===null?void 0:o}}if(!this._mountedCalled&&typeof this.config.onMounted=="function")try{const e=this.config.onMounted(this.api.state,this.api);S(e)?e.catch(t=>{typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(e){typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e),this._mountedCalled=!0}typeof this.render=="function"&&this.render()}disconnectedCallback(){if(Object.entries(this._autoWiredHandlers).forEach(([e,t])=>{t.forEach(r=>{super.removeEventListener(e,r)})}),this._autoWiredHandlers={},this.unsubscribes.forEach(e=>e()),this.unsubscribes=[],this._globalUnsubscribes.forEach(e=>e()),this._globalUnsubscribes=[],!this._unmountedCalled&&typeof this.config.onUnmounted=="function")try{const e=this.config.onUnmounted(this.api.state,this.api);S(e)?e.catch(t=>{typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t)}).finally(()=>{this._unmountedCalled=!0}):this._unmountedCalled=!0}catch(e){typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e),this._unmountedCalled=!0}this._mountedCalled=!1,this._unmountedCalled=!1}render(){this._hasError=!1,this.syncControlledInputsAndEvents(),setTimeout(()=>this.attachControlledInputListeners(),0);try{E.forEach(t=>{try{t.onRender?.(this.stateObj,this.api)}catch(r){this._handleRenderError(r)}}),this.config.computed&&Object.values(this.config.computed).forEach(t=>{try{t(this.stateObj)}catch(r){this._handleRenderError(r)}});const e=this.config.template(this.stateObj,this.api);e instanceof Promise?e.then(t=>{this._hasError||(this._renderTemplateResult(t),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}).catch(t=>{this._handleRenderError(t)}):this._hasError||(this._renderTemplateResult(e),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}catch(e){this._handleRenderError(e),this.renderError(e instanceof Error?e:new Error(String(e)))}}_prevVNode=null;rebindEventListeners(){if(!this.shadowRoot)return;["data-on-input","data-on-change","data-on-blur","data-on-click"].forEach(t=>{this.shadowRoot.querySelectorAll(`[${t}]`).forEach(r=>{const n=t.replace("data-on-",""),o=r.getAttribute(t);if(!o||typeof this.config[o]!="function")return;r._boundHandlers&&r._boundHandlers[n]&&r.removeEventListener(n,r._boundHandlers[n]);const s=this.config[o],i=a=>s.call(this,a,this.stateObj,this.api);r.addEventListener(n,i),r._boundHandlers||(r._boundHandlers={}),r._boundHandlers[n]=i})}),Array.from(this.shadowRoot.children).forEach(t=>{t instanceof HTMLElement&&typeof t.rebindEventListeners=="function"&&t.rebindEventListeners()})}_renderTemplateResult(e){if(!this._hasError)try{let t=function(r){const n=new WeakSet;function o(s){if(s===null||typeof s!="object"||n.has(s))return s;if(n.add(s),Array.isArray(s))return s.map(o);const i={};for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&(i[a]=o(s[a]));return i}return o(r)};if(typeof e=="string"){let r=function(c){return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g,(l,u,d)=>{const f=d.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi,"");return`<${u}${f}>`})},n=function(c){c.children.forEach(n)};const o=r(e),s=X(o);n(s);const i=this.shadowRoot;if(!i)return;let a=i.querySelector("style");if(a||(a=document.createElement("style"),i.appendChild(a)),this.config.style?a.textContent=typeof this.config.style=="function"?this.config.style(this.stateObj):this.config.style:a.textContent="",s.type==="#fragment"){const c=Array.from(i.childNodes).find(l=>l.nodeType===1&&l!==a);if(c){Array.from(c.childNodes).forEach(d=>{d.nodeType===1&&d.nodeName==="STYLE"||c.removeChild(d)});const l={type:"#fragment",dom:c,children:s.children,props:{},key:void 0},u=this._prevVNode&&this._prevVNode.type==="#fragment"?{...this._prevVNode,dom:c}:l;R(c,u,l)}else s.children.forEach(l=>{const u=y(l);u&&i.appendChild(u),l.dom=u??void 0})}else{let c=Array.from(this.shadowRoot.childNodes).find(l=>l!==a&&l.nodeType===1);if(c)if(this._prevVNode&&(this._prevVNode.type!==s.type||this._prevVNode.key!==s.key)){const l=y(s);l&&(this.shadowRoot.contains(c)&&this.shadowRoot.replaceChild(l,c),c=l)}else R(c,this._prevVNode,s);else c=y(s),c&&this.shadowRoot.appendChild(c);s.dom=c}this._prevVNode=s,this.forceSyncControlledInputs(),this.lastCompiledTemplate=null}else{const r=!this.shadowRoot.firstElementChild,n=this.lastCompiledTemplate?.id===e.id;if(r){const o=x(e,this.stateObj,this.api);this.shadowRoot.appendChild(o)}else if(n&&this.shadowRoot.firstElementChild){const o=this.lastState;G(e,this.shadowRoot.firstElementChild,this.stateObj,this.api,o||void 0)}else{const o=x(e,this.stateObj,this.api);let s=this.shadowRoot.querySelector("style");s||(s=document.createElement("style"),this.shadowRoot.insertBefore(s,this.shadowRoot.firstChild)),this.config.style?s.textContent=typeof this.config.style=="function"?this.config.style(this.stateObj):this.config.style:s.textContent="";let i=this.shadowRoot.querySelector("[data-root]");for(i||(i=document.createElement("div"),i.setAttribute("data-root",""),this.shadowRoot.appendChild(i));i.firstChild;)i.removeChild(i.firstChild);i.appendChild(o)}this.lastCompiledTemplate=e}this.lastState=t(this.stateObj),this.updateStyle(),this.processRefs(),this.bindEvents(),this.syncControlledInputsAndEvents()}catch(t){this._handleRenderError(t)}}_handleRenderError(e){if(this._hasError=!0,this.config.debug&&console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`,e),E.forEach(t=>t.onError?.(e instanceof Error?e:new Error(String(e)),this.stateObj,this.api)),"onError"in this.config&&typeof this.config.onError=="function")try{this.config.onError(e instanceof Error?e:new Error(String(e)),this.api.state,this.api)}catch(t){this.config.debug&&console.error("[runtime] Error in onError handler:",t)}this.renderError(e instanceof Error?e:new Error(String(e)))}scheduleRender(){this.rafId!==void 0&&this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.render(),this.rafId=null})}updateStyle(){const e=this.shadowRoot.querySelector("style");if(!e||!this.config.style)return;const t=typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style;e.textContent=t}processRefs(){if(!this.config.refs)return;const e=new WeakMap;Object.entries(this.config.refs).forEach(([t,r])=>{const n=this.shadowRoot.querySelector(`[data-ref="${t}"]`);if(n){e.has(n)||e.set(n,new Set);const o=e.get(n),s=n.addEventListener;n.addEventListener=function(i,a,c){const l=`${i}`;o.has(l)||(o.add(l),s.call(n,i,a,c))},n.setAttribute("data-refs-processed","true");try{r(n,this.api.state,this.api)}catch(i){this._handleRenderError(i)}}})}bindEvents(){if(!this.shadowRoot)return;const e=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_ELEMENT);let t=e.nextNode();for(;t;){const r=t;Array.from(r.attributes).forEach(n=>{if(n.name.startsWith("data-on-")){const o=n.name.slice(8),s=n.value,i=this.config[s];if(typeof i=="function"){r._boundHandlers&&r._boundHandlers[o]&&r.removeEventListener(o,r._boundHandlers[o]);const a=c=>{i.call(this.config,c,this.api.state,this.api),this.syncControlledInputsAndEvents()};r.addEventListener(o,a),r._boundHandlers||(r._boundHandlers={}),r._boundHandlers[o]=a}else this.config.debug&&console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`,r)}}),t=e.nextNode()}}renderError(e){const t=this.config.style?typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style:"";this.shadowRoot.innerHTML=`
|
|
39
|
+
`);function K(e){return typeof e!="string"?String(e):/expression\s*\(|url\s*\(\s*['"]?javascript:/i.test(e)?"":e.replace(/[\u0000-\u001F\u007F-\u009F]/g,"").replace(/<|>|"|'|`|;/g,"")}function F(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function j(e,t){if(typeof e!="string"||!t)return String(e);for(const r in t){if(typeof t[r]=="string"&&e===t[r])return F(e);if(Array.isArray(t[r])){for(const n of t[r])if(n&&typeof n=="object"){for(const o in n)if(typeof n[o]=="string"&&e===n[o])return F(e)}}}return String(e)}function S(e,...t){function r(n,o,s){if(Array.isArray(n)){const i=n.map(a=>r(a,o,s));return i.some(a=>a instanceof Promise)?Promise.all(i).then(a=>a.join("")):i.join("")}if(typeof n=="function"){const i=r(n(o,s),o,s);return i instanceof Promise,i}return n==null?"":n instanceof Promise?n:String(n)}return(n,o)=>{let s="",i=!1;const a=[];for(let c=0;c<e.length;c++)if(s+=e[c],c<t.length){let l=t[c];const u=e[c],d=/data-on-[a-z]+="?$/.test(u);l=r(l,n,o),l instanceof Promise?(i=!0,a.push(l)):/=\s*"?$/.test(u)&&typeof l=="string"&&!d?(l=l.replace(/"/g,""").replace(/'/g,"'"),s+=l):!d&&!/=\s*"?$/.test(u)?s+=j(l,n):s+=l}return i?Promise.all(a).then(c=>{let l="",u=0;for(let d=0;d<e.length;d++)if(l+=e[d],d<t.length){let f=t[d];const h=e[d],m=/data-on-[a-z]+="?$/.test(h);f=r(f,n,o),f instanceof Promise?l+=c[u++]:/=\s*"?$/.test(h)&&typeof f=="string"&&!m?(f=f.replace(/"/g,""").replace(/'/g,"'"),l+=f):!m&&!/=\s*"?$/.test(h)?l+=j(f,n):l+=f}return l}):s}}function at(e,...t){const r="compiled-"+Math.random().toString(36).slice(2);function n(s,i,a){return Array.isArray(s)?s.map(c=>n(c,i,a)).join(""):typeof s=="function"?n(s(i,a),i,a):s==null?"":String(s)}const o=(s,i)=>{let a="";for(let c=0;c<e.length;c++)if(a+=e[c],c<t.length){let l=t[c];const u=e[c],d=/data-on-[a-z]+="?$/.test(u);l=n(l,s,i),/=\s*"?$/.test(u)&&typeof l=="string"&&!d?(l=l.replace(/"/g,""").replace(/'/g,"'"),a+=l):!d&&!/=\s*"?$/.test(u)?a+=j(l,s):a+=l??""}return a};return o.id=r,o}function V(e,...t){let r="";for(let n=0;n<e.length;n++)r+=e[n],n<t.length&&(r+=K(t[n]));return r}function ct(e){return Object.keys(e).filter(t=>e[t]).join(" ")}function lt(e){return Object.entries(e).map(([t,r])=>{const n=t.replace(/[^a-zA-Z0-9\-]/g,""),o=typeof r=="string"?K(r):r;return`${n}: ${o}`}).join("; ")}function B(e,t,r){const[n,...o]=r.split("|").map(a=>a.trim());if(!n||n==="__proto__"||n==="constructor"||n==="prototype")return;function s(a,c,l){const u=c.split(".");let d=a;for(let f=0;f<u.length-1;f++)u[f]in d||(d[u[f]]={}),d=d[u[f]];d[u[u.length-1]]=l}const i=a=>{let c;if(e instanceof HTMLInputElement&&e.type==="checkbox"){c=e.value;const l=e.getAttribute("data-true-value"),u=e.getAttribute("data-false-value");let d=Array.isArray(t[n])?t[n]:void 0;if(d){if(e.checked)d.includes(c)||d.push(c);else{const f=d.indexOf(c);f!==-1&&d.splice(f,1)}s(t,n,[...d])}else l!==null||u!==null?e.checked?s(t,n,l):s(t,n,u!==null?u:!1):s(t,n,e.checked)}else e instanceof HTMLInputElement&&e.type==="radio"?(c=e.value,s(t,n,c),((e.form||e.closest("form")||e.getRootNode())instanceof Element?(e.form||e.closest("form")||e.getRootNode()).querySelectorAll(`input[type="radio"][name="${e.name}"][data-model="${r}"]`):[]).forEach(u=>{u.checked=u.value===String(c)})):(c=e.value,e instanceof HTMLInputElement&&e.type==="number"&&(c=Number(c)),o.includes("trim")&&typeof c=="string"&&(c=c.trim()),o.includes("number")&&(c=Number(c)),s(t,n,c));if("_vnode"in e&&typeof e._vnode=="object"&&e._vnode?.props&&(e._vnode.props.value=c),a.type==="input"&&(e._isDirty=!0),a.type==="keydown"&&a.key==="Enter"&&(e._isDirty=!1,e instanceof HTMLElement&&e.isConnected)){let l=e.parentElement;for(;l&&!(l instanceof HTMLElement&&l.shadowRoot);)l=l.parentElement;l&&typeof l=="object"&&l!==null&&"render"in l&&typeof l.render=="function"&&l.render()}a.type==="blur"&&(e._isDirty=!1)};e.addEventListener("input",i),e.addEventListener("change",i),e.addEventListener("keydown",i),e.addEventListener("blur",i)}const z=(()=>{try{if(typeof process<"u"&&process.env)return process.env.NODE_ENV==="development"}catch{}return typeof window<"u"?window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1":!1})();function ut(e,t={}){const{development:r=z,cache:n=!0,optimize:o=!0}=t,s=X(e);if(n&&L.has(s)){if(r){const i=_.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheHits++,_.set(s,i)}return L.get(s)}if(r){const i=_.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheMisses++,_.set(s,i)}try{const i=ft(e,{development:r,optimize:o});return n&&L.set(s,i),i}catch(i){return r&&(console.error("[Template Compiler] Error compiling template:",i),console.error("[Template Compiler] Template:",e)),{statics:[e],dynamics:[],fragment:null,id:s,hasDynamics:!1,render:()=>e}}}function dt(e,t){if(typeof document>"u")return[0];try{let r=function(a,c=[]){if(a.nodeType===Node.TEXT_NODE){if(a.textContent?.includes(t))return c}else if(a.nodeType===Node.ELEMENT_NODE){let l=0;for(let u=0;u<a.childNodes.length;u++){const d=a.childNodes[u],f=r(d,[...c,l]);if(f)return f;l++}}return null};const s=new DOMParser().parseFromString(`<div>${e}</div>`,"text/html").body.firstElementChild;return r(s)||[0]}catch(r){return z&&console.warn("[Template Compiler] Error finding DOM path for placeholder:",t,r),[0]}}function ft(e,t){return new ht(e,t).compile()}class ht{template;options;dynamics=[];statics=[];constructor(t,r){this.template=t,this.options=r}compile(){this.parseTemplate();const t=this.createStaticFragment(),r=X(this.template),n=(o,s)=>{let i="";for(let a=0;a<this.statics.length;a++)if(i+=this.statics[a],a<this.dynamics.length){let c=this.dynamics[a].getValue(o,s);if(c instanceof Promise)return Promise.all(this.dynamics.map(l=>{const u=l.getValue(o,s);return u instanceof Promise?u:Promise.resolve(u)})).then(l=>{let u="";for(let d=0;d<this.statics.length;d++)u+=this.statics[d],d<l.length&&(u+=l[d]);return u});i+=c}return i};return{statics:this.statics,dynamics:this.dynamics,fragment:t,id:r,hasDynamics:this.dynamics.length>0,render:n}}parseTemplate(){const t=/\{\{([^}]+)\}\}/g;let r=0,n;for(;(n=t.exec(this.template))!==null;){const s=this.template.slice(r,n.index);this.statics.push(s);let i=s.match(/([a-zA-Z0-9_-]+)\s*=\s*"?$/),a=i?i[1]:void 0,c;if(s.endsWith('style="color:'))a="style",c="color";else if(a==="style"){const u=s.match(/style\s*=\s*"?([^:;]+):\s*$/);u&&(c=u[1].trim())}const l=n[1].trim();this.analyzeDynamicExpression(l,this.dynamics.length,a,c),r=n.index+n[0].length}const o=this.template.slice(r);this.statics.push(o)}analyzeDynamicExpression(t,r,n,o){let s="text",i;n?n==="class"?(s="class",i="class"):n==="style"?(s="style",i=o||"style"):n==="value"?(s="property",i="value"):(s="attribute",i=n):t.includes("class.")?(s="class",i=t.split(".")[1]):t.includes("style.")?(s="style",i=t.split(".")[1]):t.includes("@")?(s="event",i=t.split("@")[1]):t==="class"?(s="class",i="class"):t==="style"?(s="style",i="style"):t==="value"?(s="property",i="value"):t==="title"&&(s="attribute",i="title");const a=`__DYNAMIC_${r}__`,c=this.statics.join(a);let l=dt(c,a);this.statics.length===2&&s!=="text"?l=[0]:this.statics.length===2&&l.length===0&&(l=[0]),this.dynamics.push({path:l,type:s,target:i,getValue:this.createValueGetter(t)})}createValueGetter(t){return(r,n)=>{try{let o;if(t&&typeof t=="function")o=t(r);else if(typeof t=="string"&&t.startsWith("state.")){const s=t.slice(6);o=r[s]}else typeof t=="string"&&/^[a-zA-Z0-9_$]+$/.test(t)?o=r[t]:(typeof t=="string"&&t.includes("("),o="");return o}catch(o){return this.options.development&&console.warn(`[Template Compiler] Error evaluating expression: ${t}`,o),""}}}createStaticFragment(){if(typeof document>"u")return null;try{const t=this.statics.join("");if(!t.trim())return null;const n=new DOMParser().parseFromString(t,"text/html"),o=document.createDocumentFragment();for(;n.body.firstChild;)o.appendChild(n.body.firstChild);return o}catch(t){return this.options.development&&console.warn("[Template Compiler] Could not create static fragment:",t),null}}}function H(e,t){try{if(t.length===1&&t[0]===0&&e instanceof Element)return e;let r=e;for(let n=0;n<t.length;n++){const o=t[n];if(!r.childNodes||r.childNodes.length<=o)return null;r=r.childNodes[o]}return r}catch{return null}}function x(e,t,r){let n;return e.fragment&&!e.hasDynamics?n=e.fragment.cloneNode(!0):n=pt(e,t,r),n}function G(e,t,r,n,o){if(e.hasDynamics)for(const s of e.dynamics)try{const i=s.getValue(r,n);if(o!==void 0&&s.getValue(o,n)===i)continue;Z(t,s,i)}catch(i){console.warn("[Template Compiler] Error applying update:",i)}}function pt(e,t,r){let n="";for(let a=0;a<e.statics.length;a++)if(n+=e.statics[a],a<e.dynamics.length){const c=e.dynamics[a];if(c.type==="text"||c.type==="attribute"){const l=c.getValue(t,r);n+=String(l??"")}else(c.type==="property"||c.type==="class"||c.type==="style")&&(n+="")}if(typeof document>"u")return new DocumentFragment;const s=new DOMParser().parseFromString(n,"text/html"),i=document.createDocumentFragment();for(;s.body.firstChild;)i.appendChild(s.body.firstChild);for(const a of e.dynamics){const c=a.getValue(t,r),l=H(i,a.path);Z(l,a,c)}return i}function Z(e,t,r){try{if(t.type==="text"){const o=document.createTreeWalker(e,NodeFilter.SHOW_TEXT);let s=!1,i;for(;i=o.nextNode();){const c=i.textContent||"";if(c.includes("Count: ")){const l=c.replace(/Count: \d+/,`Count: ${r}`);i.textContent=l,s=!0}}if(s)return;const a=H(e,t.path);a&&a.nodeType===Node.TEXT_NODE&&(a.textContent=r==null?"":String(r));return}const n=H(e,t.path);if(!n)return;switch(t.type){case"attribute":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;r==null||r===""?o.removeAttribute(t.target):o.setAttribute(t.target,String(r))}break;case"property":n.nodeType===Node.ELEMENT_NODE&&t.target&&(n[t.target]=r??"",n.setAttribute(t.target,r==null?"":String(r)));break;case"class":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;o.className=r==null?"":String(r),o.setAttribute("class",r==null?"":String(r))}break;case"style":if(n.nodeType===Node.ELEMENT_NODE&&t.target){const o=n;o.style[t.target]=r==null?"":String(r),o.setAttribute("style",r==null?`${t.target}:`:`${t.target}:${r}`)}break;default:throw new Error(`Unknown update type: ${t.type}`)}}catch(n){(typeof globalThis<"u"?globalThis.isDevelopment:z)&&console.warn("[Template Compiler] Error applying update:",t,n)}}const L=new Map,_=new Map;function X(e){let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);t=(t<<5)-t+n,t=t&t}return`tpl_${Math.abs(t).toString(36)}`}function N(e,t,r,n,o){return n&&o?`${t}.${e}[${r}]:${n}:${o}`:n?`${t}.${e}[${r}]:${n}`:`${t}.${e}[${r}]`}function D(e,t,r){if(!(!e||!(e instanceof Element))&&e.contains(r)&&r.parentNode===e)try{e.replaceChild(t,r)}catch(n){console.error("[VDOM] safeReplaceChild: error replacing child",n,{parent:e,newChild:t,oldChild:r,parentHTML:e.outerHTML,newChildHTML:t.outerHTML,oldChildHTML:r.outerHTML})}}function y(e){if(e.type==="#whitespace")return null;if(e.type==="#text"){const r=document.createTextNode(e.props.nodeValue??"");return e.dom=r,r}const t=document.createElement(e.type);for(const[r,n]of Object.entries(e.props))r==="value"&&t instanceof HTMLInputElement?t.type==="radio"?t.setAttribute("value",n):(t.type,t.value=n,t.setAttribute("value",n)):t.setAttribute(r,n);e.dom=t;for(const r of e.children){const n=y(r);n&&t.appendChild(n)}return t}function Y(e){const t=document.createElement("template");t.innerHTML=e.trim();const r=Array.from(t.content.childNodes);return r.length===1?w(r[0]):{type:"#fragment",key:void 0,props:{},children:r.map((o,s)=>w(o,"#fragment",s)),dom:void 0}}function w(e,t="",r=0){if(!e)return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0};if(e.nodeType===Node.TEXT_NODE)return!e.nodeValue||/^\s*$/.test(e.nodeValue)?{type:"#whitespace",key:void 0,props:{},children:[],dom:void 0}:{type:"#text",key:N("#text",t,r),props:{nodeValue:e.nodeValue},children:[],dom:e};if(e.nodeType===Node.ELEMENT_NODE){const n=e,o={};Array.from(n.attributes).forEach(l=>{o[l.name]=l.value});const s=n.tagName.toLowerCase();let i;if((s==="input"||s==="select"||s==="textarea")&&n.hasAttribute("data-model")){const l=n.getAttribute("data-model"),u=n.getAttribute("type")??"";i=`${s}:${l}:${u}`,o["data-uid"]=i,n.setAttribute("data-uid",i);let d=n.getAttribute("value"),f=n.getAttribute("checked");d&&(o.value=d),f&&(o.checked=f)}else s==="input"||s==="textarea"||s==="select"||n.hasAttribute("contenteditable")?(i=`${s}:${t}:${r}`,o["data-uid"]=i,n.setAttribute("data-uid",i)):(i=N(s,t,r),s==="li"&&(o["data-uid"]=i,n.setAttribute("data-uid",i)));const a=Array.from(n.childNodes).map((l,u)=>w(l,i,u));return{type:s,key:i,props:o,children:a,dom:n}}return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0}}function R(e,t,r){if(!t||!r)return;function n(c){return!!c&&c.type!=="#whitespace"&&!(c.type==="#text"&&(!c.props?.nodeValue||/^\s*$/.test(c.props.nodeValue)))}const o=Array.isArray(t.children)?t.children.filter(n):[],s=Array.isArray(r.children)?r.children.filter(n):[],i=r.type==="input"||r.type==="select"||r.type==="textarea";if(t.type!==r.type||t.key!==r.key){const c=y(r);if(c instanceof Node&&t.dom instanceof Node&&e.contains(t.dom)){if(D(e,c,t.dom),i&&r.props&&e.firstChild instanceof HTMLInputElement){const l=e.firstChild;l.type==="radio"||l.type,l.value=r.props.value,l.setAttribute("value",r.props.value),"checked"in r.props&&(l.checked=r.props.checked===!0||r.props.checked==="true")}}else if(c instanceof Node)if(c){if(e.appendChild(c),r.dom=c,i&&r.props&&e.firstChild instanceof HTMLInputElement){const l=e.firstChild;l.type==="radio"?l.setAttribute("value",r.props.value):(l.type,l.value=r.props.value,l.setAttribute("value",r.props.value)),"checked"in r.props&&(l.checked=r.props.checked===!0||r.props.checked==="true")}}else r.dom=void 0;else r.dom=void 0;return}if(i&&t.dom instanceof HTMLElement&&r.props){for(const[c,l]of Object.entries(r.props))if(c==="value"&&e.firstChild instanceof HTMLInputElement)e.firstChild.value=l;else if(c==="checked"&&e.firstChild instanceof HTMLInputElement)e.firstChild.checked=l===!0||l==="true";else if(c in t.dom)try{t.dom[c]=l}catch{}else t.dom.setAttribute(c,l);for(let c=r.children.length;c<o.length;c++)o[c]&&o[c].dom&&t.dom&&t.dom.contains(o[c].dom)&&t.dom.removeChild(o[c].dom);return}const a=t.dom;if(a&&a instanceof Element&&r.props){const c=a.tagName.toLowerCase()==="input"?a.getAttribute("type"):void 0,l=a.tagName.includes("-");for(const[u,d]of Object.entries(r.props))if(!(c==="radio"&&u==="value")){if(c==="checkbox"&&u==="value"){a.setAttribute("value",d);continue}a.setAttribute(u,d)}if(l)for(const[u,d]of Object.entries(r.props))a.setAttribute(u,d);for(const u of Array.from(a.attributes).map(d=>d.name))if(!(u in r.props)){if(c==="radio"&&u==="value"||c==="checkbox"&&u==="value")continue;a.removeAttribute(u)}}if(r.type==="#text"){if(a&&a.nodeType===Node.TEXT_NODE)a.nodeValue!==r.props.nodeValue&&(a.nodeValue=r.props.nodeValue),r.dom=a;else{const c=document.createTextNode(r.props.nodeValue??"");a&&e.contains(a)&&a.parentNode===e?D(e,c,a):e.appendChild(c),r.dom=c}return}if(a instanceof Element){const c=new Map;o.forEach(f=>f.key&&c.set(f.key,f));const l=new Set(s.map(f=>f.key));let u=[];for(let f=0;f<s.length;f++){const h=s[f],m=h.key?c.get(h.key):o[f];let p;const k=h.type==="input"||h.type==="select"||h.type==="textarea";if(m&&m.dom&&(!k||m.type===h.type&&m.key===h.key))R(a,m,h),p=m.dom;else{const A=y(h);if(p=A instanceof Node?A:void 0,p){if((p instanceof Element||p instanceof Node)&&p.contains(a))throw console.error("[VDOM] Attempted to insert a parent into its own child:",{parentTag:a.tagName,childTag:p.tagName,parentUid:a.getAttribute?.("data-uid"),childUid:p.getAttribute?.("data-uid"),parent:a,child:p}),new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(p,a.childNodes[f]||null)}}h.dom=p,p&&u.push(p)}for(o.forEach(f=>{!l.has(f.key)&&f.dom&&a.contains(f.dom)&&a.removeChild(f.dom)});a.childNodes.length>s.length;)a.removeChild(a.lastChild);for(let f=0;f<u.length;f++)if(a.childNodes[f]!==u[f]){if((u[f]instanceof Element||u[f]instanceof Node)&&u[f].contains(a))throw new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(u[f],a.childNodes[f]||null)}r.dom=a;const d=new Set(s.map(f=>f.key));Array.from(a.childNodes).forEach((f,h)=>{const m=f.getAttribute?.("data-uid");(m&&!d.has(m)||h>=s.length)&&a.removeChild(f)})}}const mt=e=>e?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(e)):{},b=(e,t)=>{for(const r of e){const n=[],o=r.path.replace(/:[^/]+/g,a=>(n.push(a.slice(1)),"([^/]+)")),s=new RegExp(`^${o}$`),i=t.match(s);if(i){const a={};return n.forEach((c,l)=>{a[c]=i[l+1]}),{route:r,params:a}}}return{route:null,params:{}}},M={};async function J(e){if(e.component)return e.component;if(e.load){if(M[e.path])return M[e.path];try{const t=await e.load();return M[e.path]=t.default,t.default}catch{throw new Error(`Failed to load component for route: ${e.path}`)}}throw new Error(`No component or loader defined for route: ${e.path}`)}function Q(e){const{routes:t,base:r=""}=e;let n,o,s,i,a,c,l;if(typeof window<"u"&&typeof document<"u"){n=()=>{const d=new URL(window.location.href),f=d.pathname.replace(r,"")||"/",h=mt(d.search);return{path:f,query:h}},o=n();const u=b(t,o.path);s=$({path:o.path,params:u.params,query:o.query}),i=()=>{const d=n(),f=b(t,d.path),h=s.getState();h.path=d.path,h.params=f.params,h.query=d.query},window.addEventListener("popstate",i),a=d=>{window.history.pushState({},"",r+d),i()},c=d=>{window.history.replaceState({},"",r+d),i()},l=()=>window.history.back()}else{n=()=>({path:"/",query:{}}),o=n();const u=b(t,o.path);s=$({path:o.path,params:u.params,query:o.query}),i=()=>{},a=()=>{},c=()=>{},l=()=>{}}return{store:s,push:a,replace:c,back:l,subscribe:s.subscribe,matchRoute:u=>b(t,u),getCurrent:()=>s.getState(),resolveRouteComponent:J}}function yt(e,t){return b(e,t)}function I(e,t){const r=[],n=t?Object.keys(t):[],o={...e};let s=null;function i(u){return r.push(u),()=>{const d=r.indexOf(u);d!==-1&&r.splice(d,1)}}function a(u){Object.assign(s,u),r.forEach(d=>d(s))}const c=new WeakMap;function l(u){if(c.has(u))return c.get(u);const d=new Proxy(u,{get(f,h,m){if(h==="subscribe")return i;if(h==="set")return a;if(t&&n.includes(h))return t[h](s);const p=Reflect.get(f,h,m);return typeof p=="object"&&p!==null?l(p):p},set(f,h,m,p){if(t&&n.includes(h))return!1;const k=f[h],A=Reflect.set(f,h,m,p);return k!==m&&r.forEach(tt=>tt(s)),A},deleteProperty(f,h){if(t&&n.includes(h))return!1;const m=Reflect.deleteProperty(f,h);return r.forEach(p=>p(s)),m}});return c.set(u,d),d}return s=l(o),s}const E=[];function gt(e){E.push(e)}function v(e,t=new WeakSet){if(e===null||typeof e!="object"||t.has(e))return e;if(t.add(e),Array.isArray(e))return e.map(o=>v(o,t));Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null&&Object.setPrototypeOf(e,null);const r=["__proto__","constructor","prototype"],n=Object.create(null);for(const o of Object.keys(e))r.includes(o)||(n[o]=v(e[o],t));return n}function T(e){return!!e&&typeof e.then=="function"}let P;typeof HTMLElement<"u"?P=class extends HTMLElement{syncStateToAttributes(){if(!this.stateObj||!this.config?.reflect||!Array.isArray(this.config.reflect))return;const e=["__proto__","constructor","prototype"];this.config.reflect.forEach(t=>{if(e.includes(t)){this.removeAttribute(t);return}const r=this.stateObj[t];["string","number","boolean"].includes(typeof r)?r==null?this.removeAttribute(t):this.setAttribute(t,String(r)):this.removeAttribute(t)})}setTemplate(e){const t=this.config;typeof e=="function"?t.template=e:t.template=()=>e,this.render()}_hasError=!1;_mountedCalled=!1;_unmountedCalled=!1;_autoWiredHandlers={};removeEventListener(e,t,r){super.removeEventListener(e,t,r),this._autoWiredHandlers[e]&&(this._autoWiredHandlers[e]=this._autoWiredHandlers[e].filter(n=>n===t?(super.removeEventListener(e,n,r),!1):!0),this._autoWiredHandlers[e].length===0&&delete this._autoWiredHandlers[e])}static get observedAttributes(){const e=this.stateObj||{};return Object.keys(e).filter(t=>["string","number","boolean"].includes(typeof e[t]))}attributeChangedCallback(e,t,r){if(e==="__proto__"||e==="constructor"||e==="prototype"||!this.stateObj)return;const n=e.replace(/-([a-z])/g,(s,i)=>i.toUpperCase()),o=e in this.stateObj?e:n in this.stateObj?n:null;if(o){const s=typeof this.config?.state?.[o];let i=r;if(r===null)i=void 0;else if(s==="number")if(i===void 0||i==="")i=this.config?.state?.[o];else{const a=Number(i);i=isNaN(a)?this.config?.state?.[o]:a}else s==="boolean"&&(i=i==="true");i=v(i),this.stateObj[o]!==i&&(this.config?.debug&&console.log("[runtime] state update:",{stateKey:o,value:i}),this.stateObj[o]=i,this.render())}}forceSyncControlledInputs(){this.shadowRoot&&(this.shadowRoot.querySelectorAll("input[data-model]").forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]),o=document.activeElement===r;r._hasDirtyListener||(r.addEventListener("input",()=>{r._isDirty=!0}),r.addEventListener("blur",()=>{r._isDirty=!1}),r._hasDirtyListener=!0);const s=!!r._isDirty;o||s||r.type!=="radio"&&r.type!=="checkbox"&&r.value!==n&&(r.value=n)}),this.rebindEventListeners())}syncControlledInputsAndEvents(){this.shadowRoot&&(this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]);r.checked=r.value===n}),this.shadowRoot.querySelectorAll("input[data-model]").forEach(e=>{const t=e.getAttribute("data-model");if(!t||!this.stateObj||typeof this.stateObj[t]>"u")return;const r=e,n=String(this.stateObj[t]);if(r.type==="checkbox"){const o=this.stateObj[t];if(Array.isArray(o))r.checked=o.includes(r.value);else{const s=r.getAttribute("data-true-value"),i=r.getAttribute("data-false-value");s!==null||i!==null?String(o)===s?r.checked=!0:String(o)===i?r.checked=!1:o===!0?r.checked=!0:r.checked=!1:r.checked=o===!0||o==="true"||o===1}}else r.type==="radio"||(r.value=n)}),this.shadowRoot.querySelectorAll("textarea[data-model]").forEach(e=>{const t=e.getAttribute("data-model");!t||!this.stateObj||typeof this.stateObj[t]>"u"||(e.value=String(this.stateObj[t]))}),this.shadowRoot.querySelectorAll("select[data-model]").forEach(e=>{const t=e.getAttribute("data-model");!t||!this.stateObj||typeof this.stateObj[t]>"u"||(e.value=String(this.stateObj[t]))}))}attachListItemModelListeners(){this.shadowRoot&&this.shadowRoot.querySelectorAll("input[data-bind]").forEach(e=>{const t=e.getAttribute("data-bind");if(!t)return;e._listItemModelListener&&(e.removeEventListener("input",e._listItemModelListener),e.removeEventListener("change",e._listItemModelListener),delete e._listItemModelListener);const r=t.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);if(r){const[,o,s,i]=r,a=parseInt(s,10),c=this.stateObj[o];e instanceof HTMLInputElement&&e.type==="checkbox"&&(e.checked=!!(Array.isArray(c)&&c[a]&&c[a][i]));const l=u=>{!Array.isArray(c)||!c[a]||(e instanceof HTMLInputElement&&e.type==="checkbox"?c[a][i]=e.checked:c[a][i]=e.value)};e.addEventListener("input",l),e.addEventListener("change",l),e._listItemModelListener=l;return}const n=t.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);if(n){const[,o,s,i]=n,a=this.stateObj[o],c=i?i.split("|").map(u=>u.trim()).filter(Boolean):[];e instanceof HTMLInputElement&&e.type==="checkbox"?e.checked=!!(a&&a[s]):e instanceof HTMLInputElement&&(e.value=a?String(a[s]??""):"");const l=u=>{if(!a)return;let d;e instanceof HTMLInputElement&&e.type==="checkbox"?d=e.checked:(d=e.value,c.includes("number")&&(d=Number(d)),c.includes("trim")&&typeof d=="string"&&(d=d.trim())),a[s]=d};e.addEventListener("input",l),e.addEventListener("change",l),e._listItemModelListener=l}})}attachControlledInputListeners(){const e=this.shadowRoot;e&&(e.querySelectorAll("[data-model]").forEach(t=>{const r=t.getAttribute("data-model");r&&(t._dataModelBound||(B(t,this.stateObj,r),t._dataModelBound=!0))}),e.querySelectorAll("[data-model]").forEach(t=>{const[r]=t.getAttribute("data-model")?.split("|").map(n=>n.trim())??[];if(!(!r||!(r in this.stateObj)))if(t instanceof HTMLInputElement)if(t.type==="checkbox"){const n=this.stateObj[r],o=t.getAttribute("data-true-value"),s=t.getAttribute("data-false-value");Array.isArray(n)?t.checked=n.includes(t.value):o!==null||s!==null?String(n)===o?t.checked=!0:String(n)===s?t.checked=!1:n===!0?t.checked=!0:t.checked=!1:t.checked=n===!0||n==="true"||n===1}else t.type==="radio"?t.checked=t.value===String(this.stateObj[r]):t.value=String(this.stateObj[r]??"");else(t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement)&&(t.value=String(this.stateObj[r]??""))}))}config;stateObj;api;_globalUnsubscribes=[];unsubscribes=[];lastCompiledTemplate=null;lastState=null;rafId=null;constructor(){super()}initializeConfig(){if(this.config)return;const e=this.tagName.toLowerCase(),r=(window.__componentRegistry||{})[e];if(!r||typeof r!="object")throw new Error("Invalid component config: must be an object");if(!r.state||typeof r.state!="object")throw new Error("Invalid component config: state must be an object");this.config=r;const n=r.computed?I(r.state,r.computed):I(r.state);if(this.stateObj=n,typeof this.stateObj.subscribe=="function"&&this.unsubscribes.push(this.stateObj.subscribe(()=>{this.scheduleRender()})),this.api={state:this.stateObj,emit:(s,i)=>this.dispatchEvent(new CustomEvent(s,{detail:i,bubbles:!0})),onGlobal:(s,i)=>{const a=C.on(s,i);return this._globalUnsubscribes.push(a),a},offGlobal:(s,i)=>C.off(s,i),emitGlobal:(s,i)=>C.emit(s,i),render:()=>this.render()},Object.keys(this.config).forEach(s=>{if(s.startsWith("on")&&s.length>2&&typeof this.config[s]=="function"){const i=s.charAt(2).toLowerCase()+s.slice(3),a=c=>{const l=c.detail??c;this.config[s](l,this.api.state,this.api)};this.addEventListener(i,a),this._autoWiredHandlers[i]||(this._autoWiredHandlers[i]=[]),this._autoWiredHandlers[i].push(a)}}),this.attachShadow({mode:"open"}),r.style){const s=document.createElement("style");s.textContent=typeof r.style=="function"?r.style(this.stateObj):r.style,this.shadowRoot.appendChild(s)}if(typeof this.config.hydrate=="function"){const s=this.shadowRoot?.querySelectorAll("[data-hydrate]");try{s&&s.length>0?s.forEach(i=>{try{this.config.hydrate(i,this.stateObj,this.api)}catch(a){typeof this.config.onError=="function"&&this.config.onError(a instanceof Error?a:new Error(String(a)),this.api.state,this.api),this._handleRenderError(a)}}):this.config.hydrate(this.shadowRoot,this.stateObj,this.api)}catch(i){typeof this.config.onError=="function"&&this.config.onError(i instanceof Error?i:new Error(String(i)),this.api.state,this.api),this._handleRenderError(i)}}if(this.hasAttribute("data-hydrated")?this.processRefs():this.render(),!this._mountedCalled&&typeof this.config.onMounted=="function")try{const s=this.config.onMounted(this.api.state,this.api);T(s)?s.catch(i=>{typeof this.config.onError=="function"&&this.config.onError(i,this.api.state,this.api),this._handleRenderError(i)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(s){typeof this.config.onError=="function"&&this.config.onError(s,this.api.state,this.api),this._handleRenderError(s),this._mountedCalled=!0}}connectedCallback(){if(this.initializeConfig(),this.stateObj)for(const e of this.getAttributeNames()){const r=e.replace(/-([a-z])/g,(n,o)=>o.toUpperCase());if(r in this.stateObj){const n=typeof this.config?.state?.[r];let o=this.getAttribute(e);n==="number"?o=Number(o):n==="boolean"&&(o=o==="true"),this.stateObj[r]=o===null?void 0:o}}if(!this._mountedCalled&&typeof this.config.onMounted=="function")try{const e=this.config.onMounted(this.api.state,this.api);T(e)?e.catch(t=>{typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(e){typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e),this._mountedCalled=!0}typeof this.render=="function"&&this.render()}disconnectedCallback(){if(Object.entries(this._autoWiredHandlers).forEach(([e,t])=>{t.forEach(r=>{super.removeEventListener(e,r)})}),this._autoWiredHandlers={},this.unsubscribes.forEach(e=>e()),this.unsubscribes=[],this._globalUnsubscribes.forEach(e=>e()),this._globalUnsubscribes=[],!this._unmountedCalled&&typeof this.config.onUnmounted=="function")try{const e=this.config.onUnmounted(this.api.state,this.api);T(e)?e.catch(t=>{typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t)}).finally(()=>{this._unmountedCalled=!0}):this._unmountedCalled=!0}catch(e){typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e),this._unmountedCalled=!0}this._mountedCalled=!1,this._unmountedCalled=!1}render(){this._hasError=!1,this.syncControlledInputsAndEvents(),setTimeout(()=>this.attachControlledInputListeners(),0);try{E.forEach(t=>{try{t.onRender?.(this.stateObj,this.api)}catch(r){this._handleRenderError(r)}}),this.config.computed&&Object.values(this.config.computed).forEach(t=>{try{t(this.stateObj)}catch(r){this._handleRenderError(r)}});const e=this.config.template(this.stateObj,this.api);e instanceof Promise?e.then(t=>{this._hasError||(this._renderTemplateResult(t),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}).catch(t=>{this._handleRenderError(t)}):this._hasError||(this._renderTemplateResult(e),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}catch(e){this._handleRenderError(e),this.renderError(e instanceof Error?e:new Error(String(e)))}}_prevVNode=null;rebindEventListeners(){if(!this.shadowRoot)return;["data-on-input","data-on-change","data-on-blur","data-on-click"].forEach(t=>{this.shadowRoot.querySelectorAll(`[${t}]`).forEach(r=>{const n=t.replace("data-on-",""),o=r.getAttribute(t);if(!o||typeof this.config[o]!="function")return;r._boundHandlers&&r._boundHandlers[n]&&r.removeEventListener(n,r._boundHandlers[n]);const s=this.config[o],i=a=>s.call(this,a,this.stateObj,this.api);r.addEventListener(n,i),r._boundHandlers||(r._boundHandlers={}),r._boundHandlers[n]=i})}),Array.from(this.shadowRoot.children).forEach(t=>{t instanceof HTMLElement&&typeof t.rebindEventListeners=="function"&&t.rebindEventListeners()})}_renderTemplateResult(e){if(!this._hasError)try{let t=function(r){const n=new WeakSet;function o(s){if(s===null||typeof s!="object"||n.has(s))return s;if(n.add(s),Array.isArray(s))return s.map(o);const i={};for(const a in s)Object.prototype.hasOwnProperty.call(s,a)&&(i[a]=o(s[a]));return i}return o(r)};if(typeof e=="string"){let r=function(c){return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g,(l,u,d)=>{const f=d.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi,"");return`<${u}${f}>`})},n=function(c){c.children.forEach(n)};const o=r(e),s=Y(o);n(s);const i=this.shadowRoot;if(!i)return;let a=i.querySelector("style");if(a||(a=document.createElement("style"),i.appendChild(a)),this.config.style?a.textContent=typeof this.config.style=="function"?this.config.style(this.stateObj):this.config.style:a.textContent="",s.type==="#fragment"){const c=Array.from(i.childNodes).find(l=>l.nodeType===1&&l!==a);if(c){Array.from(c.childNodes).forEach(d=>{d.nodeType===1&&d.nodeName==="STYLE"||c.removeChild(d)});const l={type:"#fragment",dom:c,children:s.children,props:{},key:void 0},u=this._prevVNode&&this._prevVNode.type==="#fragment"?{...this._prevVNode,dom:c}:l;R(c,u,l)}else s.children.forEach(l=>{const u=y(l);u&&i.appendChild(u),l.dom=u??void 0})}else{let c=Array.from(this.shadowRoot.childNodes).find(l=>l!==a&&l.nodeType===1);if(c)if(this._prevVNode&&(this._prevVNode.type!==s.type||this._prevVNode.key!==s.key)){const l=y(s);l&&(this.shadowRoot.contains(c)&&this.shadowRoot.replaceChild(l,c),c=l)}else R(c,this._prevVNode,s);else c=y(s),c&&this.shadowRoot.appendChild(c);s.dom=c}this._prevVNode=s,this.forceSyncControlledInputs(),this.lastCompiledTemplate=null}else{const r=!this.shadowRoot.firstElementChild,n=this.lastCompiledTemplate?.id===e.id;if(r){const o=x(e,this.stateObj,this.api);this.shadowRoot.appendChild(o)}else if(n&&this.shadowRoot.firstElementChild){const o=this.lastState;G(e,this.shadowRoot.firstElementChild,this.stateObj,this.api,o||void 0)}else{const o=x(e,this.stateObj,this.api);let s=this.shadowRoot.querySelector("style");s||(s=document.createElement("style"),this.shadowRoot.insertBefore(s,this.shadowRoot.firstChild)),this.config.style?s.textContent=typeof this.config.style=="function"?this.config.style(this.stateObj):this.config.style:s.textContent="";let i=this.shadowRoot.querySelector("[data-root]");for(i||(i=document.createElement("div"),i.setAttribute("data-root",""),this.shadowRoot.appendChild(i));i.firstChild;)i.removeChild(i.firstChild);i.appendChild(o)}this.lastCompiledTemplate=e}this.lastState=t(this.stateObj),this.updateStyle(),this.processRefs(),this.bindEvents(),this.syncControlledInputsAndEvents()}catch(t){this._handleRenderError(t)}}_handleRenderError(e){if(this._hasError=!0,this.config.debug&&console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`,e),E.forEach(t=>t.onError?.(e instanceof Error?e:new Error(String(e)),this.stateObj,this.api)),"onError"in this.config&&typeof this.config.onError=="function")try{this.config.onError(e instanceof Error?e:new Error(String(e)),this.api.state,this.api)}catch(t){this.config.debug&&console.error("[runtime] Error in onError handler:",t)}this.renderError(e instanceof Error?e:new Error(String(e)))}scheduleRender(){this.rafId!==void 0&&this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.render(),this.rafId=null})}updateStyle(){const e=this.shadowRoot.querySelector("style");if(!e||!this.config.style)return;const t=typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style;e.textContent=t}processRefs(){if(!this.config.refs)return;const e=new WeakMap;Object.entries(this.config.refs).forEach(([t,r])=>{const n=this.shadowRoot.querySelector(`[data-ref="${t}"]`);if(n){e.has(n)||e.set(n,new Set);const o=e.get(n),s=n.addEventListener;n.addEventListener=function(i,a,c){const l=`${i}`;o.has(l)||(o.add(l),s.call(n,i,a,c))},n.setAttribute("data-refs-processed","true");try{r(n,this.api.state,this.api)}catch(i){this._handleRenderError(i)}}})}bindEvents(){if(!this.shadowRoot)return;const e=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_ELEMENT);let t=e.nextNode();for(;t;){const r=t;Array.from(r.attributes).forEach(n=>{if(n.name.startsWith("data-on-")){const o=n.name.slice(8),s=n.value,i=this.config[s];if(typeof i=="function"){r._boundHandlers&&r._boundHandlers[o]&&r.removeEventListener(o,r._boundHandlers[o]);const a=c=>{i.call(this.config,c,this.api.state,this.api),this.syncControlledInputsAndEvents()};r.addEventListener(o,a),r._boundHandlers||(r._boundHandlers={}),r._boundHandlers[o]=a}else this.config.debug&&console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`,r)}}),t=e.nextNode()}}renderError(e){const t=this.config.style?typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style:"";this.shadowRoot.innerHTML=`
|
|
40
40
|
<style>${t}</style>
|
|
41
41
|
<div style="color: red; border: 1px solid red; padding: 1rem; border-radius: 4px;">
|
|
42
42
|
<h3>Error Boundary</h3>
|
|
43
43
|
<div>Error: ${e.message}</div>
|
|
44
44
|
</div>
|
|
45
|
-
`}}:P=class{constructor(){}};function q(e,t){if(t=v(t),t.debug&&console.log(`[runtime] Debugging component: ${e}`,t),!e||!t.template){t&&typeof t.onError=="function"&&t.onError(new Error("Component requires tag and template"),t.state??{},{state:t.state??{},emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),t&&t.debug&&console.error("[runtime] Malformed config:",{tag:e,config:t});return}E.forEach(u=>{try{u.onInit?.(t)}catch(d){t&&typeof t.onError=="function"&&t.onError(d instanceof Error?d:new Error(String(d)),t.state,{state:t.state,emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),t&&t.debug&&console.error("[runtime] Plugin onInit error:",d)}});const n=typeof window<"u"&&window.VITE_DEV_HMR,o=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:O&&O.tagName.toUpperCase()==="SCRIPT"&&O.src||new URL("custom-elements-runtime.cjs.js",document.baseURI).href}<"u"&&void 0;if((n||o)&&typeof customElements<"u"&&customElements.get(e))try{document.querySelectorAll(e).forEach(u=>u.remove()),window.customElements._definitions&&delete window.customElements._definitions[e]}catch{}if(typeof customElements<"u"&&customElements.get(e)){t.debug&&console.warn(`[runtime] Component "${e}" already registered`);return}const s=I(t.state??{},t.computed);t.state=s,t._subscribe=s.subscribe;const i=t.state??{},a=Object.keys(i).filter(u=>["string","number","boolean"].includes(typeof i[u]));class c extends P{static get observedAttributes(){return a}constructor(){super()}}const l=c;typeof customElements<"u"&&!customElements.get(e)&&(window.__componentRegistry=window.__componentRegistry||{},window.__componentRegistry[e]=t,customElements.define(e,l))}function
|
|
45
|
+
`}}:P=class{constructor(){}};function q(e,t){if(t=v(t),t.debug&&console.log(`[runtime] Debugging component: ${e}`,t),!e||!t.template){t&&typeof t.onError=="function"&&t.onError(new Error("Component requires tag and template"),t.state??{},{state:t.state??{},emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),t&&t.debug&&console.error("[runtime] Malformed config:",{tag:e,config:t});return}E.forEach(u=>{try{u.onInit?.(t)}catch(d){t&&typeof t.onError=="function"&&t.onError(d instanceof Error?d:new Error(String(d)),t.state,{state:t.state,emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),t&&t.debug&&console.error("[runtime] Plugin onInit error:",d)}});const n=typeof window<"u"&&window.VITE_DEV_HMR,o=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:O&&O.tagName.toUpperCase()==="SCRIPT"&&O.src||new URL("custom-elements-runtime.cjs.js",document.baseURI).href}<"u"&&void 0;if((n||o)&&typeof customElements<"u"&&customElements.get(e))try{document.querySelectorAll(e).forEach(u=>u.remove()),window.customElements._definitions&&delete window.customElements._definitions[e]}catch{}if(typeof customElements<"u"&&customElements.get(e)){t.debug&&console.warn(`[runtime] Component "${e}" already registered`);return}const s=I(t.state??{},t.computed);t.state=s,t._subscribe=s.subscribe;const i=t.state??{},a=Object.keys(i).filter(u=>["string","number","boolean"].includes(typeof i[u]));class c extends P{static get observedAttributes(){return a}constructor(){super()}}const l=c;typeof customElements<"u"&&!customElements.get(e)&&(window.__componentRegistry=window.__componentRegistry||{},window.__componentRegistry[e]=t,customElements.define(e,l))}function bt(e){const t=Q(e);return q("router-view",{template:async()=>{if(!t)return"<div>Router not initialized.</div>";const r=t.getCurrent(),{path:n}=r,o=t.matchRoute(n);return o.route?(o.route.load&&await o.route.load(),`<${o.route.component}></${o.route.component}>`):"<div>Not found</div>"},onMounted(r,n){t&&typeof t.subscribe=="function"&&t.subscribe(()=>{n.render()})}}),q("router-link",{state:{to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,style:V`
|
|
46
46
|
[aria-disabled="true"] {
|
|
47
47
|
pointer-events: none;
|
|
48
48
|
opacity: 0.5;
|
|
49
49
|
}
|
|
50
|
-
`},computed:{current(){return t.getCurrent()},isExactActive(r){return r.current.path===r.to},isActive(r){const n=r.current;return r.exact?r.isExactActive:n&&typeof n.path=="string"?n.path.startsWith(r.to):!1},className(r){return r.isExactActive?r.exactActiveClass:r.isActive?r.activeClass:""},ariaCurrent(r){return r.isExactActive?`aria-current="${r.ariaCurrentValue}"`:""},isButton(r){return r.tag==="button"},disabledAttr(r){return r.disabled?r.isButton?'disabled aria-disabled="true" tabindex="-1"':'aria-disabled="true" tabindex="-1"':""},externalAttr(r){return r.external&&(r.tag==="a"||!r.tag)?'target="_blank" rel="noopener noreferrer"':""}},reflect:["to","tag","replace","exact","activeClass","exactActiveClass","ariaCurrentValue","disabled","external","style"],style:r=>r.style,template:r=>
|
|
51
|
-
${r.isButton?
|
|
50
|
+
`},computed:{current(){return t.getCurrent()},isExactActive(r){return r.current.path===r.to},isActive(r){const n=r.current;return r.exact?r.isExactActive:n&&typeof n.path=="string"?n.path.startsWith(r.to):!1},className(r){return r.isExactActive?r.exactActiveClass:r.isActive?r.activeClass:""},ariaCurrent(r){return r.isExactActive?`aria-current="${r.ariaCurrentValue}"`:""},isButton(r){return r.tag==="button"},disabledAttr(r){return r.disabled?r.isButton?'disabled aria-disabled="true" tabindex="-1"':'aria-disabled="true" tabindex="-1"':""},externalAttr(r){return r.external&&(r.tag==="a"||!r.tag)?'target="_blank" rel="noopener noreferrer"':""}},reflect:["to","tag","replace","exact","activeClass","exactActiveClass","ariaCurrentValue","disabled","external","style"],style:r=>r.style,template:r=>S`
|
|
51
|
+
${r.isButton?S`
|
|
52
52
|
<button
|
|
53
53
|
part="button"
|
|
54
54
|
class="${r.className}"
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
${r.externalAttr}
|
|
58
58
|
data-on-click="navigate"
|
|
59
59
|
><slot></slot></button>
|
|
60
|
-
`(r):
|
|
60
|
+
`(r):S`
|
|
61
61
|
<a
|
|
62
62
|
part="link"
|
|
63
63
|
href="${r.to}"
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
data-on-click="navigate"
|
|
69
69
|
><slot></slot></a>
|
|
70
70
|
`(r)}
|
|
71
|
-
`(r),navigate:(r,n)=>{if(n.disabled){r.preventDefault();return}n.external&&(n.tag==="a"||!n.tag)||(r.preventDefault(),n.replace?t.replace(n.to):t.push(n.to))}}),t}exports.Store=$;exports.classes=
|
|
71
|
+
`(r),navigate:(r,n)=>{if(n.disabled){r.preventDefault();return}n.external&&(n.tag==="a"||!n.tag)||(r.preventDefault(),n.replace?t.replace(n.to):t.push(n.to))}}),t}exports.Store=$;exports.classes=ct;exports.compile=at;exports.compileTemplate=ut;exports.component=q;exports.createVNodeFromElement=w;exports.css=V;exports.deepSanitizeObject=v;exports.eventBus=C;exports.generateHydrationScript=st;exports.getVNodeKey=N;exports.html=S;exports.initRouter=bt;exports.isPromise=T;exports.matchRouteSSR=yt;exports.mountVNode=y;exports.parseVNodeFromHTML=Y;exports.patchVNode=R;exports.renderCompiledTemplate=x;exports.renderComponentsToString=nt;exports.renderToString=U;exports.resolveRouteComponent=J;exports.runtimePlugins=E;exports.safeReplaceChild=D;exports.styles=lt;exports.updateCompiledTemplate=G;exports.useDataModel=B;exports.useRouter=Q;exports.useRuntimePlugin=gt;
|
|
72
72
|
//# sourceMappingURL=custom-elements-runtime.cjs.js.map
|