@jasonshimmy/custom-elements-runtime 0.0.7 → 0.0.8-beta.0
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/dist/custom-elements-runtime.cjs.js +5 -5
- package/dist/custom-elements-runtime.cjs.js.map +1 -1
- package/dist/custom-elements-runtime.es.js +1 -0
- package/dist/custom-elements-runtime.es.js.map +1 -1
- package/dist/custom-elements-runtime.umd.js +5 -5
- package/dist/custom-elements-runtime.umd.js.map +1 -1
- package/dist/runtime.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(p,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p.CustomElementsRuntime={}))})(this,(function(p){"use strict";var g=typeof document<"u"?document.currentScript:null;function L(t){let e=new Proxy(t,{set:(i,a,c)=>(i[a]=c,s(),!0)});const n=[];function r(i){n.push(i),i(e)}function o(){return e}function s(){n.forEach(i=>i(e))}return{subscribe:r,getState:o}}class E extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return E.instance||(E.instance=new E),E.instance}emit(e,n){const r=Date.now(),o=this.eventCounters.get(e);if(!o||r-o.window>1e3)this.eventCounters.set(e,{count:1,window:r});else if(o.count++,o.count>50&&(console.error(`Event storm detected for "${e}": ${o.count} events in 1 second. Throttling...`),o.count>100)){console.warn(`Blocking further "${e}" events to prevent infinite loop`);return}this.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!1,cancelable:!0}));const s=this.handlers[e];s&&s.forEach(i=>{try{i(n)}catch(a){console.error(`Error in global event handler for "${e}":`,a)}})}on(e,n){return this.handlers[e]||(this.handlers[e]=new Set),this.handlers[e].add(n),()=>this.off(e,n)}off(e,n){const r=this.handlers[e];r&&r.delete(n)}offAll(e){delete this.handlers[e]}listen(e,n,r){return this.addEventListener(e,n,r),()=>this.removeEventListener(e,n)}once(e,n){return new Promise(r=>{const o=this.on(e,s=>{o(),n(s),r(s)})})}getActiveEvents(){return Object.keys(this.handlers).filter(e=>this.handlers[e]&&this.handlers[e].size>0)}clear(){this.handlers={}}getHandlerCount(e){return this.handlers[e]?.size||0}getEventStats(){const e={};for(const[n,r]of this.eventCounters.entries())e[n]={count:r.count,handlersCount:this.getHandlerCount(n)};return e}resetEventCounters(){this.eventCounters.clear()}}const C=E.getInstance(),
|
|
1
|
+
(function(p,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(p=typeof globalThis<"u"?globalThis:p||self,g(p.CustomElementsRuntime={}))})(this,(function(p){"use strict";var g=typeof document<"u"?document.currentScript:null;function L(t){let e=new Proxy(t,{set:(i,a,c)=>(i[a]=c,s(),!0)});const n=[];function r(i){n.push(i),i(e)}function o(){return e}function s(){n.forEach(i=>i(e))}return{subscribe:r,getState:o}}class E extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return E.instance||(E.instance=new E),E.instance}emit(e,n){const r=Date.now(),o=this.eventCounters.get(e);if(!o||r-o.window>1e3)this.eventCounters.set(e,{count:1,window:r});else if(o.count++,o.count>50&&(console.error(`Event storm detected for "${e}": ${o.count} events in 1 second. Throttling...`),o.count>100)){console.warn(`Blocking further "${e}" events to prevent infinite loop`);return}this.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!1,cancelable:!0}));const s=this.handlers[e];s&&s.forEach(i=>{try{i(n)}catch(a){console.error(`Error in global event handler for "${e}":`,a)}})}on(e,n){return this.handlers[e]||(this.handlers[e]=new Set),this.handlers[e].add(n),()=>this.off(e,n)}off(e,n){const r=this.handlers[e];r&&r.delete(n)}offAll(e){delete this.handlers[e]}listen(e,n,r){return this.addEventListener(e,n,r),()=>this.removeEventListener(e,n)}once(e,n){return new Promise(r=>{const o=this.on(e,s=>{o(),n(s),r(s)})})}getActiveEvents(){return Object.keys(this.handlers).filter(e=>this.handlers[e]&&this.handlers[e].size>0)}clear(){this.handlers={}}getHandlerCount(e){return this.handlers[e]?.size||0}getEventStats(){const e={};for(const[n,r]of this.eventCounters.entries())e[n]={count:r.count,handlersCount:this.getHandlerCount(n)};return e}resetEventCounters(){this.eventCounters.clear()}}const C=E.getInstance(),J=typeof window>"u"||typeof document>"u";function Q(t){return{state:t,emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}}function q(t,e={}){J||console.warn("[SSR] renderToString should only be used on the server");try{const n=t.state,r=Q(n),o=t.template(n,r);let s="";e.includeStyles&&t.style&&(s=`<style>${typeof t.style=="function"?t.style(n):t.style}</style>`);const i=e.sanitizeAttributes?e.sanitizeAttributes(t.attrs||{}):t.attrs||{},a=Object.entries(i).map(([d,u])=>`${z(d)}="${z(u)}"`).join(" "),l=`${a?`<${t.tag} ${a}>`:`<${t.tag}>`}${s}${o}</${t.tag}>`;return e.prettyPrint?rt(l):l}catch(n){return console.error(`[SSR] Error rendering ${t.tag}:`,n),`<${t.tag}><div style="color: red;">SSR Error: ${nt(String(n))}</div></${t.tag}>`}}function tt(t,e={}){const n={components:new Map,styles:new Set},r=[];t.forEach(i=>{if(n.components.set(i.tag,i),i.style){const c=typeof i.style=="function"?i.style(i.state):i.style;n.styles.add(c)}const a=q(i,{...e,includeStyles:!1});r.push(a)});const o=Array.from(n.styles).join(`
|
|
2
2
|
`);return{html:r.join(`
|
|
3
|
-
`),styles:o,context:n}}function
|
|
3
|
+
`),styles:o,context:n}}function et(t){const e=Array.from(t.components.entries()).map(([n,r])=>({tag:n,state:r.state}));return`
|
|
4
4
|
<script type="module">
|
|
5
5
|
// Hydration data from SSR
|
|
6
6
|
window.__SSR_CONTEXT__ = ${JSON.stringify({components:e})};
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
// Clean up
|
|
34
34
|
delete window.__SSR_CONTEXT__;
|
|
35
35
|
}
|
|
36
|
-
<\/script>`.trim()}const
|
|
36
|
+
<\/script>`.trim()}const nt=t=>t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),z=t=>t.replace(/&/g,"&").replace(/"/g,""").replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">"),rt=t=>t.replace(/></g,`>
|
|
37
37
|
<`).split(`
|
|
38
38
|
`).map(e=>{const n=(e.match(/^<[^\/]/g)||[]).length-(e.match(/<\//g)||[]).length;return" ".repeat(Math.max(0,n))+e.trim()}).join(`
|
|
39
|
-
`);function W(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function k(t,e){if(typeof t!="string"||!e)return String(t);for(const n in e){if(typeof e[n]=="string"&&t===e[n])return W(t);if(Array.isArray(e[n])){for(const r of e[n])if(r&&typeof r=="object"){for(const o in r)if(typeof r[o]=="string"&&t===r[o])return W(t)}}}return String(t)}function rt(t,...e){function n(r,o,s){if(Array.isArray(r)){const i=r.map(a=>n(a,o,s));return i.some(a=>a instanceof Promise)?Promise.all(i).then(a=>a.join("")):i.join("")}if(typeof r=="function"){const i=n(r(o,s),o,s);return i instanceof Promise,i}return r==null?"":r instanceof Promise?r:String(r)}return(r,o)=>{let s="",i=!1;const a=[];for(let c=0;c<t.length;c++)if(s+=t[c],c<e.length){let l=e[c];const d=t[c],u=/data-on-[a-z]+="?$/.test(d);l=n(l,r,o),l instanceof Promise?(i=!0,a.push(l)):/=\s*"?$/.test(d)&&typeof l=="string"&&!u?(l=l.replace(/"/g,""").replace(/'/g,"'"),s+=l):!u&&!/=\s*"?$/.test(d)?s+=k(l,r):s+=l}return i?Promise.all(a).then(c=>{let l="",d=0;for(let u=0;u<t.length;u++)if(l+=t[u],u<e.length){let f=e[u];const h=t[u],y=/data-on-[a-z]+="?$/.test(h);f=n(f,r,o),f instanceof Promise?l+=c[d++]:/=\s*"?$/.test(h)&&typeof f=="string"&&!y?(f=f.replace(/"/g,""").replace(/'/g,"'"),l+=f):!y&&!/=\s*"?$/.test(h)?l+=k(f,r):l+=f}return l}):s}}function st(t,...e){const n="compiled-"+Math.random().toString(36).slice(2);function r(s,i,a){return Array.isArray(s)?s.map(c=>r(c,i,a)).join(""):typeof s=="function"?r(s(i,a),i,a):s==null?"":String(s)}const o=(s,i)=>{let a="";for(let c=0;c<t.length;c++)if(a+=t[c],c<e.length){let l=e[c];const d=t[c],u=/data-on-[a-z]+="?$/.test(d);l=r(l,s,i),/=\s*"?$/.test(d)&&typeof l=="string"&&!u?(l=l.replace(/"/g,""").replace(/'/g,"'"),a+=l):!u&&!/=\s*"?$/.test(d)?a+=k(l,s):a+=l??""}return a};return o.id=n,o}function it(t,...e){let n="";for(let r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=e[r]??"");return n}function ot(t){return Object.keys(t).filter(e=>t[e]).join(" ")}function at(t){return Object.entries(t).map(([e,n])=>`${e}: ${n}`).join("; ")}function F(t,e,n){const[r,...o]=n.split("|").map(a=>a.trim());if(!r||r==="__proto__"||r==="constructor"||r==="prototype")return;function s(a,c,l){const d=c.split(".");let u=a;for(let f=0;f<d.length-1;f++)d[f]in u||(u[d[f]]={}),u=u[d[f]];u[d[d.length-1]]=l}const i=a=>{let c;if(t instanceof HTMLInputElement&&t.type==="checkbox"){c=t.value;const l=t.getAttribute("data-true-value"),d=t.getAttribute("data-false-value");let u=Array.isArray(e[r])?e[r]:void 0;if(u){if(t.checked)u.includes(c)||u.push(c);else{const f=u.indexOf(c);f!==-1&&u.splice(f,1)}s(e,r,[...u])}else l!==null||d!==null?t.checked?s(e,r,l):s(e,r,d!==null?d:!1):s(e,r,t.checked)}else t instanceof HTMLInputElement&&t.type==="radio"?(c=t.value,s(e,r,c),((t.form||t.closest("form")||t.getRootNode())instanceof Element?(t.form||t.closest("form")||t.getRootNode()).querySelectorAll(`input[type="radio"][name="${t.name}"][data-model="${n}"]`):[]).forEach(d=>{d.checked=d.value===String(c)})):(c=t.value,t instanceof HTMLInputElement&&t.type==="number"&&(c=Number(c)),o.includes("trim")&&typeof c=="string"&&(c=c.trim()),o.includes("number")&&(c=Number(c)),s(e,r,c));if("_vnode"in t&&typeof t._vnode=="object"&&t._vnode?.props&&(t._vnode.props.value=c),a.type==="input"&&(t._isDirty=!0),a.type==="keydown"&&a.key==="Enter"&&(t._isDirty=!1,t instanceof HTMLElement&&t.isConnected)){let l=t.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"&&(t._isDirty=!1)};t.addEventListener("input",i),t.addEventListener("change",i),t.addEventListener("keydown",i),t.addEventListener("blur",i)}const M=(()=>{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 ct(t,e={}){const{development:n=M,cache:r=!0,optimize:o=!0}=e,s=G(t);if(r&&j.has(s)){if(n){const i=T.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheHits++,T.set(s,i)}return j.get(s)}if(n){const i=T.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheMisses++,T.set(s,i)}try{const i=dt(t,{development:n,optimize:o});return r&&j.set(s,i),i}catch(i){return n&&(console.error("[Template Compiler] Error compiling template:",i),console.error("[Template Compiler] Template:",t)),{statics:[t],dynamics:[],fragment:null,id:s,hasDynamics:!1,render:()=>t}}}function lt(t,e){if(typeof document>"u")return[0];try{let n=function(a,c=[]){if(a.nodeType===Node.TEXT_NODE){if(a.textContent?.includes(e))return c}else if(a.nodeType===Node.ELEMENT_NODE){let l=0;for(let d=0;d<a.childNodes.length;d++){const u=a.childNodes[d],f=n(u,[...c,l]);if(f)return f;l++}}return null};const s=new DOMParser().parseFromString(`<div>${t}</div>`,"text/html").body.firstElementChild;return n(s)||[0]}catch(n){return M&&console.warn("[Template Compiler] Error finding DOM path for placeholder:",e,n),[0]}}function dt(t,e){return new ut(t,e).compile()}class ut{template;options;dynamics=[];statics=[];constructor(e,n){this.template=e,this.options=n}compile(){this.parseTemplate();const e=this.createStaticFragment(),n=G(this.template),r=(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 d=l.getValue(o,s);return d instanceof Promise?d:Promise.resolve(d)})).then(l=>{let d="";for(let u=0;u<this.statics.length;u++)d+=this.statics[u],u<l.length&&(d+=l[u]);return d});i+=c}return i};return{statics:this.statics,dynamics:this.dynamics,fragment:e,id:n,hasDynamics:this.dynamics.length>0,render:r}}parseTemplate(){const e=/\{\{([^}]+)\}\}/g;let n=0,r;for(;(r=e.exec(this.template))!==null;){const s=this.template.slice(n,r.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 d=s.match(/style\s*=\s*"?([^:;]+):\s*$/);d&&(c=d[1].trim())}const l=r[1].trim();this.analyzeDynamicExpression(l,this.dynamics.length,a,c),n=r.index+r[0].length}const o=this.template.slice(n);this.statics.push(o)}analyzeDynamicExpression(e,n,r,o){let s="text",i;r?r==="class"?(s="class",i="class"):r==="style"?(s="style",i=o||"style"):r==="value"?(s="property",i="value"):(s="attribute",i=r):e.includes("class.")?(s="class",i=e.split(".")[1]):e.includes("style.")?(s="style",i=e.split(".")[1]):e.includes("@")?(s="event",i=e.split("@")[1]):e==="class"?(s="class",i="class"):e==="style"?(s="style",i="style"):e==="value"?(s="property",i="value"):e==="title"&&(s="attribute",i="title");const a=`__DYNAMIC_${n}__`,c=this.statics.join(a);let l=lt(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(e)})}createValueGetter(e){return(n,r)=>{try{let o;if(e&&typeof e=="function")o=e(n);else if(typeof e=="string"&&e.startsWith("state.")){const s=e.slice(6);o=n[s]}else typeof e=="string"&&/^[a-zA-Z0-9_$]+$/.test(e)?o=n[e]:(typeof e=="string"&&e.includes("("),o="");return o}catch(o){return this.options.development&&console.warn(`[Template Compiler] Error evaluating expression: ${e}`,o),""}}}createStaticFragment(){if(typeof document>"u")return null;try{const e=this.statics.join("");if(!e.trim())return null;const r=new DOMParser().parseFromString(e,"text/html"),o=document.createDocumentFragment();for(;r.body.firstChild;)o.appendChild(r.body.firstChild);return o}catch(e){return this.options.development&&console.warn("[Template Compiler] Could not create static fragment:",e),null}}}function $(t,e){try{if(e.length===1&&e[0]===0&&t instanceof Element)return t;let n=t;for(let r=0;r<e.length;r++){const o=e[r];if(!n.childNodes||n.childNodes.length<=o)return null;n=n.childNodes[o]}return n}catch{return null}}function H(t,e,n){let r;return t.fragment&&!t.hasDynamics?r=t.fragment.cloneNode(!0):r=ft(t,e,n),r}function U(t,e,n,r,o){if(t.hasDynamics)for(const s of t.dynamics)try{const i=s.getValue(n,r);if(o!==void 0&&s.getValue(o,r)===i)continue;K(e,s,i)}catch(i){console.warn("[Template Compiler] Error applying update:",i)}}function ft(t,e,n){let r="";for(let a=0;a<t.statics.length;a++)if(r+=t.statics[a],a<t.dynamics.length){const c=t.dynamics[a];if(c.type==="text"||c.type==="attribute"){const l=c.getValue(e,n);r+=String(l??"")}else(c.type==="property"||c.type==="class"||c.type==="style")&&(r+="")}if(typeof document>"u")return new DocumentFragment;const s=new DOMParser().parseFromString(r,"text/html"),i=document.createDocumentFragment();for(;s.body.firstChild;)i.appendChild(s.body.firstChild);for(const a of t.dynamics){const c=a.getValue(e,n),l=$(i,a.path);K(l,a,c)}return i}function K(t,e,n){try{if(e.type==="text"){const o=document.createTreeWalker(t,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: ${n}`);i.textContent=l,s=!0}}if(s)return;const a=$(t,e.path);a&&a.nodeType===Node.TEXT_NODE&&(a.textContent=n==null?"":String(n));return}const r=$(t,e.path);if(!r)return;switch(e.type){case"attribute":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;n==null||n===""?o.removeAttribute(e.target):o.setAttribute(e.target,String(n))}break;case"property":r.nodeType===Node.ELEMENT_NODE&&e.target&&(r[e.target]=n??"",r.setAttribute(e.target,n==null?"":String(n)));break;case"class":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;o.className=n==null?"":String(n),o.setAttribute("class",n==null?"":String(n))}break;case"style":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;o.style[e.target]=n==null?"":String(n),o.setAttribute("style",n==null?`${e.target}:`:`${e.target}:${n}`)}break;default:throw new Error(`Unknown update type: ${e.type}`)}}catch(r){(typeof globalThis<"u"?globalThis.isDevelopment:M)&&console.warn("[Template Compiler] Error applying update:",e,r)}}const j=new Map,T=new Map;function G(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function N(t,e,n,r,o){return r&&o?`${e}.${t}[${n}]:${r}:${o}`:r?`${e}.${t}[${n}]:${r}`:`${e}.${t}[${n}]`}function I(t,e,n){if(!(!t||!(t instanceof Element))&&t.contains(n)&&n.parentNode===t)try{t.replaceChild(e,n)}catch(r){console.error("[VDOM] safeReplaceChild: error replacing child",r,{parent:t,newChild:e,oldChild:n,parentHTML:t.outerHTML,newChildHTML:e.outerHTML,oldChildHTML:n.outerHTML})}}function b(t){if(t.type==="#whitespace")return null;if(t.type==="#text"){const n=document.createTextNode(t.props.nodeValue??"");return t.dom=n,n}const e=document.createElement(t.type);for(const[n,r]of Object.entries(t.props))n==="value"&&e instanceof HTMLInputElement?e.type==="radio"?e.setAttribute("value",r):(e.type,e.value=r,e.setAttribute("value",r)):e.setAttribute(n,r);t.dom=e;for(const n of t.children){const r=b(n);r&&e.appendChild(r)}return e}function B(t){const e=document.createElement("template");e.innerHTML=t.trim();const n=Array.from(e.content.childNodes);return n.length===1?w(n[0]):{type:"#fragment",key:void 0,props:{},children:n.map((o,s)=>w(o,"#fragment",s)),dom:void 0}}function w(t,e="",n=0){if(!t)return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0};if(t.nodeType===Node.TEXT_NODE)return!t.nodeValue||/^\s*$/.test(t.nodeValue)?{type:"#whitespace",key:void 0,props:{},children:[],dom:void 0}:{type:"#text",key:N("#text",e,n),props:{nodeValue:t.nodeValue},children:[],dom:t};if(t.nodeType===Node.ELEMENT_NODE){const r=t,o={};Array.from(r.attributes).forEach(l=>{o[l.name]=l.value});const s=r.tagName.toLowerCase();let i;if((s==="input"||s==="select"||s==="textarea")&&r.hasAttribute("data-model")){const l=r.getAttribute("data-model"),d=r.getAttribute("type")??"";i=`${s}:${l}:${d}`,o["data-uid"]=i,r.setAttribute("data-uid",i);let u=r.getAttribute("value"),f=r.getAttribute("checked");u&&(o.value=u),f&&(o.checked=f)}else s==="input"||s==="textarea"||s==="select"||r.hasAttribute("contenteditable")?(i=`${s}:${e}:${n}`,o["data-uid"]=i,r.setAttribute("data-uid",i)):(i=N(s,e,n),s==="li"&&(o["data-uid"]=i,r.setAttribute("data-uid",i)));const a=Array.from(r.childNodes).map((l,d)=>w(l,i,d));return{type:s,key:i,props:o,children:a,dom:r}}return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0}}function S(t,e,n){if(!e||!n)return;function r(c){return!!c&&c.type!=="#whitespace"&&!(c.type==="#text"&&(!c.props?.nodeValue||/^\s*$/.test(c.props.nodeValue)))}const o=Array.isArray(e.children)?e.children.filter(r):[],s=Array.isArray(n.children)?n.children.filter(r):[],i=n.type==="input"||n.type==="select"||n.type==="textarea";if(e.type!==n.type||e.key!==n.key){const c=b(n);if(c instanceof Node&&e.dom instanceof Node&&t.contains(e.dom)){if(I(t,c,e.dom),i&&n.props&&t.firstChild instanceof HTMLInputElement){const l=t.firstChild;l.type==="radio"||l.type,l.value=n.props.value,l.setAttribute("value",n.props.value),"checked"in n.props&&(l.checked=n.props.checked===!0||n.props.checked==="true")}}else if(c instanceof Node)if(c){if(t.appendChild(c),n.dom=c,i&&n.props&&t.firstChild instanceof HTMLInputElement){const l=t.firstChild;l.type==="radio"?l.setAttribute("value",n.props.value):(l.type,l.value=n.props.value,l.setAttribute("value",n.props.value)),"checked"in n.props&&(l.checked=n.props.checked===!0||n.props.checked==="true")}}else n.dom=void 0;else n.dom=void 0;return}if(i&&e.dom instanceof HTMLElement&&n.props){for(const[c,l]of Object.entries(n.props))if(c==="value"&&t.firstChild instanceof HTMLInputElement)t.firstChild.value=l;else if(c==="checked"&&t.firstChild instanceof HTMLInputElement)t.firstChild.checked=l===!0||l==="true";else if(c in e.dom)try{e.dom[c]=l}catch{}else e.dom.setAttribute(c,l);for(let c=n.children.length;c<o.length;c++)o[c]&&o[c].dom&&e.dom&&e.dom.contains(o[c].dom)&&e.dom.removeChild(o[c].dom);return}const a=e.dom;if(a&&a instanceof Element&&n.props){const c=a.tagName.toLowerCase()==="input"?a.getAttribute("type"):void 0,l=a.tagName.includes("-");for(const[d,u]of Object.entries(n.props))if(!(c==="radio"&&d==="value")){if(c==="checkbox"&&d==="value"){a.setAttribute("value",u);continue}a.setAttribute(d,u)}if(l)for(const[d,u]of Object.entries(n.props))a.setAttribute(d,u);for(const d of Array.from(a.attributes).map(u=>u.name))if(!(d in n.props)){if(c==="radio"&&d==="value"||c==="checkbox"&&d==="value")continue;a.removeAttribute(d)}}if(n.type==="#text"){if(a&&a.nodeType===Node.TEXT_NODE)a.nodeValue!==n.props.nodeValue&&(a.nodeValue=n.props.nodeValue),n.dom=a;else{const c=document.createTextNode(n.props.nodeValue??"");a&&t.contains(a)&&a.parentNode===t?I(t,c,a):t.appendChild(c),n.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 d=[];for(let f=0;f<s.length;f++){const h=s[f],y=h.key?c.get(h.key):o[f];let m;const x=h.type==="input"||h.type==="select"||h.type==="textarea";if(y&&y.dom&&(!x||y.type===h.type&&y.key===h.key))S(a,y,h),m=y.dom;else{const O=b(h);if(m=O instanceof Node?O:void 0,m){if((m instanceof Element||m instanceof Node)&&m.contains(a))throw console.error("[VDOM] Attempted to insert a parent into its own child:",{parentTag:a.tagName,childTag:m.tagName,parentUid:a.getAttribute?.("data-uid"),childUid:m.getAttribute?.("data-uid"),parent:a,child:m}),new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(m,a.childNodes[f]||null)}}h.dom=m,m&&d.push(m)}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<d.length;f++)if(a.childNodes[f]!==d[f]){if((d[f]instanceof Element||d[f]instanceof Node)&&d[f].contains(a))throw new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(d[f],a.childNodes[f]||null)}n.dom=a;const u=new Set(s.map(f=>f.key));Array.from(a.childNodes).forEach((f,h)=>{const y=f.getAttribute?.("data-uid");(y&&!u.has(y)||h>=s.length)&&a.removeChild(f)})}}const ht=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},v=(t,e)=>{for(const n of t){const r=[],o=n.path.replace(/:[^/]+/g,a=>(r.push(a.slice(1)),"([^/]+)")),s=new RegExp(`^${o}$`),i=e.match(s);if(i){const a={};return r.forEach((c,l)=>{a[c]=i[l+1]}),{route:n,params:a}}}return{route:null,params:{}}},D={};async function pt(t){if(t.component)return t.component;if(t.load){if(D[t.path])return D[t.path];try{const e=await t.load();return D[t.path]=e.default,e.default}catch{throw new Error(`Failed to load component for route: ${t.path}`)}}throw new Error(`No component or loader defined for route: ${t.path}`)}function Z(t){const{routes:e,base:n=""}=t;let r,o,s,i,a,c,l;if(typeof window<"u"&&typeof document<"u"){r=()=>{const u=new URL(window.location.href),f=u.pathname.replace(n,"")||"/",h=ht(u.search);return{path:f,query:h}},o=r();const d=v(e,o.path);s=L({path:o.path,params:d.params,query:o.query}),i=()=>{const u=r(),f=v(e,u.path),h=s.getState();h.path=u.path,h.params=f.params,h.query=u.query},window.addEventListener("popstate",i),a=u=>{window.history.pushState({},"",n+u),i()},c=u=>{window.history.replaceState({},"",n+u),i()},l=()=>window.history.back()}else{r=()=>({path:"/",query:{}}),o=r();const d=v(e,o.path);s=L({path:o.path,params:d.params,query:o.query}),i=()=>{},a=()=>{},c=()=>{},l=()=>{}}return{store:s,push:a,replace:c,back:l,subscribe:s.subscribe,matchRoute:d=>v(e,d),getCurrent:()=>s.getState(),resolveRouteComponent:pt}}function mt(t){const e=Z(t);return typeof window<"u"&&(window.__routerInstance=e),e}function yt(t,e){return v(t,e)}function P(t,e){const n=[],r=e?Object.keys(e):[],o={...t};let s=null;function i(d){return n.push(d),()=>{const u=n.indexOf(d);u!==-1&&n.splice(u,1)}}function a(d){Object.assign(s,d),n.forEach(u=>u(s))}const c=new WeakMap;function l(d){if(c.has(d))return c.get(d);const u=new Proxy(d,{get(f,h,y){if(h==="subscribe")return i;if(h==="set")return a;if(e&&r.includes(h))return e[h](s);const m=Reflect.get(f,h,y);return typeof m=="object"&&m!==null?l(m):m},set(f,h,y,m){if(e&&r.includes(h))return!1;const x=f[h],O=Reflect.set(f,h,y,m);return x!==y&&n.forEach(bt=>bt(s)),O},deleteProperty(f,h){if(e&&r.includes(h))return!1;const y=Reflect.deleteProperty(f,h);return n.forEach(m=>m(s)),y}});return c.set(d,u),u}return s=l(o),s}const _=[];function gt(t){_.push(t)}function A(t,e=new WeakSet){if(t===null||typeof t!="object"||e.has(t))return t;if(e.add(t),Array.isArray(t))return t.map(o=>A(o,e));Object.getPrototypeOf(t)!==Object.prototype&&Object.getPrototypeOf(t)!==null&&Object.setPrototypeOf(t,null);const n=["__proto__","constructor","prototype"],r=Object.create(null);for(const o of Object.keys(t))n.includes(o)||(r[o]=A(t[o],e));return r}function R(t){return!!t&&typeof t.then=="function"}let V;typeof HTMLElement<"u"&&(V=class extends HTMLElement{syncStateToAttributes(){if(!this.stateObj||!this.config?.reflect||!Array.isArray(this.config.reflect))return;const t=["__proto__","constructor","prototype"];this.config.reflect.forEach(e=>{if(t.includes(e)){this.removeAttribute(e);return}const n=this.stateObj[e];["string","number","boolean"].includes(typeof n)?n==null?this.removeAttribute(e):this.setAttribute(e,String(n)):this.removeAttribute(e)})}setTemplate(t){const e=this.config;typeof t=="function"?e.template=t:e.template=()=>t,this.render()}_hasError=!1;_mountedCalled=!1;_unmountedCalled=!1;_autoWiredHandlers={};removeEventListener(t,e,n){super.removeEventListener(t,e,n),this._autoWiredHandlers[t]&&(this._autoWiredHandlers[t]=this._autoWiredHandlers[t].filter(r=>r===e?(super.removeEventListener(t,r,n),!1):!0),this._autoWiredHandlers[t].length===0&&delete this._autoWiredHandlers[t])}static get observedAttributes(){const t=this.stateObj||{};return Object.keys(t).filter(e=>["string","number","boolean"].includes(typeof t[e]))}attributeChangedCallback(t,e,n){if(!(t==="__proto__"||t==="constructor"||t==="prototype")&&this.stateObj&&t in this.stateObj){const r=typeof this.config?.state?.[t];let o=n;if(n===null)o=void 0;else if(r==="number")if(o===void 0||o==="")o=this.config?.state?.[t];else{const s=Number(o);o=isNaN(s)?this.config?.state?.[t]:s}else r==="boolean"&&(o=o==="true");o=A(o),this.stateObj[t]!==o&&(this.config?.debug&&console.log("[runtime] state update:",{name:t,value:o}),this.stateObj[t]=o,this.render())}}forceSyncControlledInputs(){this.shadowRoot&&(this.shadowRoot.querySelectorAll("input[data-model]").forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]),o=document.activeElement===n;n._hasDirtyListener||(n.addEventListener("input",()=>{n._isDirty=!0}),n.addEventListener("blur",()=>{n._isDirty=!1}),n._hasDirtyListener=!0);const s=!!n._isDirty;o||s||n.type!=="radio"&&n.type!=="checkbox"&&n.value!==r&&(n.value=r)}),this.rebindEventListeners())}syncControlledInputsAndEvents(){this.shadowRoot&&(this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]);n.checked=n.value===r}),this.shadowRoot.querySelectorAll("input[data-model]").forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]);if(n.type==="checkbox"){const o=this.stateObj[e];if(Array.isArray(o))n.checked=o.includes(n.value);else{const s=n.getAttribute("data-true-value"),i=n.getAttribute("data-false-value");s!==null||i!==null?String(o)===s?n.checked=!0:String(o)===i?n.checked=!1:o===!0?n.checked=!0:n.checked=!1:n.checked=o===!0||o==="true"||o===1}}else n.type==="radio"||(n.value=r)}),this.shadowRoot.querySelectorAll("textarea[data-model]").forEach(t=>{const e=t.getAttribute("data-model");!e||!this.stateObj||typeof this.stateObj[e]>"u"||(t.value=String(this.stateObj[e]))}),this.shadowRoot.querySelectorAll("select[data-model]").forEach(t=>{const e=t.getAttribute("data-model");!e||!this.stateObj||typeof this.stateObj[e]>"u"||(t.value=String(this.stateObj[e]))}))}attachListItemModelListeners(){this.shadowRoot&&this.shadowRoot.querySelectorAll("input[data-bind]").forEach(t=>{const e=t.getAttribute("data-bind");if(!e)return;t._listItemModelListener&&(t.removeEventListener("input",t._listItemModelListener),t.removeEventListener("change",t._listItemModelListener),delete t._listItemModelListener);const n=e.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);if(n){const[,o,s,i]=n,a=parseInt(s,10),c=this.stateObj[o];t instanceof HTMLInputElement&&t.type==="checkbox"&&(t.checked=!!(Array.isArray(c)&&c[a]&&c[a][i]));const l=d=>{!Array.isArray(c)||!c[a]||(t instanceof HTMLInputElement&&t.type==="checkbox"?c[a][i]=t.checked:c[a][i]=t.value)};t.addEventListener("input",l),t.addEventListener("change",l),t._listItemModelListener=l;return}const r=e.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);if(r){const[,o,s,i]=r,a=this.stateObj[o],c=i?i.split("|").map(d=>d.trim()).filter(Boolean):[];t instanceof HTMLInputElement&&t.type==="checkbox"?t.checked=!!(a&&a[s]):t instanceof HTMLInputElement&&(t.value=a?String(a[s]??""):"");const l=d=>{if(!a)return;let u;t instanceof HTMLInputElement&&t.type==="checkbox"?u=t.checked:(u=t.value,c.includes("number")&&(u=Number(u)),c.includes("trim")&&typeof u=="string"&&(u=u.trim())),a[s]=u};t.addEventListener("input",l),t.addEventListener("change",l),t._listItemModelListener=l}})}attachControlledInputListeners(){const t=this.shadowRoot;t&&(t.querySelectorAll("[data-model]").forEach(e=>{const n=e.getAttribute("data-model");n&&(e._dataModelBound||(F(e,this.stateObj,n),e._dataModelBound=!0))}),t.querySelectorAll("[data-model]").forEach(e=>{const[n]=e.getAttribute("data-model")?.split("|").map(r=>r.trim())??[];if(!(!n||!(n in this.stateObj)))if(e instanceof HTMLInputElement)if(e.type==="checkbox"){const r=this.stateObj[n],o=e.getAttribute("data-true-value"),s=e.getAttribute("data-false-value");Array.isArray(r)?e.checked=r.includes(e.value):o!==null||s!==null?String(r)===o?e.checked=!0:String(r)===s?e.checked=!1:r===!0?e.checked=!0:e.checked=!1:e.checked=r===!0||r==="true"||r===1}else e.type==="radio"?e.checked=e.value===String(this.stateObj[n]):e.value=String(this.stateObj[n]??"");else(e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=String(this.stateObj[n]??""))}))}config;stateObj;api;_globalUnsubscribes=[];unsubscribes=[];lastCompiledTemplate=null;lastState=null;rafId=null;constructor(){super()}initializeConfig(){if(this.config)return;const t=this.tagName.toLowerCase(),n=(window.__componentRegistry||{})[t];if(!n||typeof n!="object")throw new Error("Invalid component config: must be an object");if(!n.state||typeof n.state!="object")throw new Error("Invalid component config: state must be an object");this.config=n;const r=n.computed?P(n.state,n.computed):P(n.state);if(this.stateObj=r,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)},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"}),n.style){const s=document.createElement("style");s.textContent=typeof n.style=="function"?n.style(this.stateObj):n.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);R(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 t of this.getAttributeNames())if(t in this.stateObj){const e=typeof this.config?.state?.[t];let n=this.getAttribute(t);e==="number"?n=Number(n):e==="boolean"&&(n=n==="true"),this.stateObj[t]=n===null?void 0:n}}if(!this._mountedCalled&&typeof this.config.onMounted=="function")try{const t=this.config.onMounted(this.api.state,this.api);R(t)?t.catch(e=>{typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(t){typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t),this._mountedCalled=!0}typeof this.render=="function"&&this.render()}disconnectedCallback(){if(Object.entries(this._autoWiredHandlers).forEach(([t,e])=>{e.forEach(n=>{super.removeEventListener(t,n)})}),this._autoWiredHandlers={},this.unsubscribes.forEach(t=>t()),this.unsubscribes=[],this._globalUnsubscribes.forEach(t=>t()),this._globalUnsubscribes=[],!this._unmountedCalled&&typeof this.config.onUnmounted=="function")try{const t=this.config.onUnmounted(this.api.state,this.api);R(t)?t.catch(e=>{typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e)}).finally(()=>{this._unmountedCalled=!0}):this._unmountedCalled=!0}catch(t){typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t),this._unmountedCalled=!0}this._mountedCalled=!1,this._unmountedCalled=!1}render(){this._hasError=!1,this.syncControlledInputsAndEvents(),setTimeout(()=>this.attachControlledInputListeners(),0);try{_.forEach(e=>{try{e.onRender?.(this.stateObj,this.api)}catch(n){this._handleRenderError(n)}}),this.config.computed&&Object.values(this.config.computed).forEach(e=>{try{e(this.stateObj)}catch(n){this._handleRenderError(n)}});const t=this.config.template(this.stateObj,this.api);t instanceof Promise?t.then(e=>{this._hasError||(this._renderTemplateResult(e),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}).catch(e=>{this._handleRenderError(e)}):this._hasError||(this._renderTemplateResult(t),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}catch(t){this._handleRenderError(t),this.renderError(t instanceof Error?t:new Error(String(t)))}}_prevVNode=null;rebindEventListeners(){if(!this.shadowRoot)return;["data-on-input","data-on-change","data-on-blur","data-on-click"].forEach(e=>{this.shadowRoot.querySelectorAll(`[${e}]`).forEach(n=>{const r=e.replace("data-on-",""),o=n.getAttribute(e);if(!o||typeof this.config[o]!="function")return;n._boundHandlers&&n._boundHandlers[r]&&n.removeEventListener(r,n._boundHandlers[r]);const s=this.config[o],i=a=>s.call(this,a);n.addEventListener(r,i),n._boundHandlers||(n._boundHandlers={}),n._boundHandlers[r]=i})}),Array.from(this.shadowRoot.children).forEach(e=>{e instanceof HTMLElement&&typeof e.rebindEventListeners=="function"&&e.rebindEventListeners()})}_renderTemplateResult(t){if(!this._hasError)try{let e=function(n){const r=new WeakSet;function o(s){if(s===null||typeof s!="object"||r.has(s))return s;if(r.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(n)};if(typeof t=="string"){let n=function(c){return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g,(l,d,u)=>{const f=u.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi,"");return`<${d}${f}>`})},r=function(c){c.children.forEach(r)};const o=n(t),s=B(o);r(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(u=>{u.nodeType===1&&u.nodeName==="STYLE"||c.removeChild(u)});const l={type:"#fragment",dom:c,children:s.children,props:{},key:void 0},d=this._prevVNode&&this._prevVNode.type==="#fragment"?{...this._prevVNode,dom:c}:l;S(c,d,l)}else s.children.forEach(l=>{const d=b(l);d&&i.appendChild(d),l.dom=d??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=b(s);l&&(this.shadowRoot.contains(c)&&this.shadowRoot.replaceChild(l,c),c=l)}else S(c,this._prevVNode,s);else c=b(s),c&&this.shadowRoot.appendChild(c);s.dom=c}this._prevVNode=s,this.forceSyncControlledInputs(),this.lastCompiledTemplate=null}else{const n=!this.shadowRoot.firstElementChild,r=this.lastCompiledTemplate?.id===t.id;if(n){const o=H(t,this.stateObj,this.api);this.shadowRoot.appendChild(o)}else if(r&&this.shadowRoot.firstElementChild){const o=this.lastState;U(t,this.shadowRoot.firstElementChild,this.stateObj,this.api,o||void 0)}else{const o=H(t,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=t}this.lastState=e(this.stateObj),this.updateStyle(),this.processRefs(),this.bindEvents(),this.syncControlledInputsAndEvents()}catch(e){this._handleRenderError(e)}}_handleRenderError(t){if(this._hasError=!0,this.config.debug&&console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`,t),_.forEach(e=>e.onError?.(t instanceof Error?t:new Error(String(t)),this.stateObj,this.api)),"onError"in this.config&&typeof this.config.onError=="function")try{this.config.onError(t instanceof Error?t:new Error(String(t)),this.api.state,this.api)}catch(e){this.config.debug&&console.error("[runtime] Error in onError handler:",e)}this.renderError(t instanceof Error?t:new Error(String(t)))}scheduleRender(){this.rafId!==void 0&&this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.render(),this.rafId=null})}updateStyle(){const t=this.shadowRoot.querySelector("style");if(!t||!this.config.style)return;const e=typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style;t.textContent=e}processRefs(){if(!this.config.refs)return;const t=new WeakMap;Object.entries(this.config.refs).forEach(([e,n])=>{const r=this.shadowRoot.querySelector(`[data-ref="${e}"]`);if(r){t.has(r)||t.set(r,new Set);const o=t.get(r),s=r.addEventListener;r.addEventListener=function(i,a,c){const l=`${i}`;o.has(l)||(o.add(l),s.call(r,i,a,c))},r.setAttribute("data-refs-processed","true");try{n(r,this.api.state,this.api)}catch(i){this._handleRenderError(i)}}})}bindEvents(){if(!this.shadowRoot)return;const t=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_ELEMENT);let e=t.nextNode();for(;e;){const n=e;Array.from(n.attributes).forEach(r=>{if(r.name.startsWith("data-on-")){const o=r.name.slice(8),s=r.value,i=this.config[s];if(typeof i=="function"){n._boundHandlers&&n._boundHandlers[o]&&n.removeEventListener(o,n._boundHandlers[o]);const a=c=>{i.call(this.config,c,this.api.state,this.api),this.syncControlledInputsAndEvents()};n.addEventListener(o,a),n._boundHandlers||(n._boundHandlers={}),n._boundHandlers[o]=a}else this.config.debug&&console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`,n)}}),e=t.nextNode()}}renderError(t){const e=this.config.style?typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style:"";this.shadowRoot.innerHTML=`
|
|
39
|
+
`);function W(t){return String(t).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function k(t,e){if(typeof t!="string"||!e)return String(t);for(const n in e){if(typeof e[n]=="string"&&t===e[n])return W(t);if(Array.isArray(e[n])){for(const r of e[n])if(r&&typeof r=="object"){for(const o in r)if(typeof r[o]=="string"&&t===r[o])return W(t)}}}return String(t)}function st(t,...e){function n(r,o,s){if(Array.isArray(r)){const i=r.map(a=>n(a,o,s));return i.some(a=>a instanceof Promise)?Promise.all(i).then(a=>a.join("")):i.join("")}if(typeof r=="function"){const i=n(r(o,s),o,s);return i instanceof Promise,i}return r==null?"":r instanceof Promise?r:String(r)}return(r,o)=>{let s="",i=!1;const a=[];for(let c=0;c<t.length;c++)if(s+=t[c],c<e.length){let l=e[c];const d=t[c],u=/data-on-[a-z]+="?$/.test(d);l=n(l,r,o),l instanceof Promise?(i=!0,a.push(l)):/=\s*"?$/.test(d)&&typeof l=="string"&&!u?(l=l.replace(/"/g,""").replace(/'/g,"'"),s+=l):!u&&!/=\s*"?$/.test(d)?s+=k(l,r):s+=l}return i?Promise.all(a).then(c=>{let l="",d=0;for(let u=0;u<t.length;u++)if(l+=t[u],u<e.length){let f=e[u];const h=t[u],y=/data-on-[a-z]+="?$/.test(h);f=n(f,r,o),f instanceof Promise?l+=c[d++]:/=\s*"?$/.test(h)&&typeof f=="string"&&!y?(f=f.replace(/"/g,""").replace(/'/g,"'"),l+=f):!y&&!/=\s*"?$/.test(h)?l+=k(f,r):l+=f}return l}):s}}function it(t,...e){const n="compiled-"+Math.random().toString(36).slice(2);function r(s,i,a){return Array.isArray(s)?s.map(c=>r(c,i,a)).join(""):typeof s=="function"?r(s(i,a),i,a):s==null?"":String(s)}const o=(s,i)=>{let a="";for(let c=0;c<t.length;c++)if(a+=t[c],c<e.length){let l=e[c];const d=t[c],u=/data-on-[a-z]+="?$/.test(d);l=r(l,s,i),/=\s*"?$/.test(d)&&typeof l=="string"&&!u?(l=l.replace(/"/g,""").replace(/'/g,"'"),a+=l):!u&&!/=\s*"?$/.test(d)?a+=k(l,s):a+=l??""}return a};return o.id=n,o}function ot(t,...e){let n="";for(let r=0;r<t.length;r++)n+=t[r],r<e.length&&(n+=e[r]??"");return n}function at(t){return Object.keys(t).filter(e=>t[e]).join(" ")}function ct(t){return Object.entries(t).map(([e,n])=>`${e}: ${n}`).join("; ")}function F(t,e,n){const[r,...o]=n.split("|").map(a=>a.trim());if(!r||r==="__proto__"||r==="constructor"||r==="prototype")return;function s(a,c,l){const d=c.split(".");let u=a;for(let f=0;f<d.length-1;f++)d[f]in u||(u[d[f]]={}),u=u[d[f]];u[d[d.length-1]]=l}const i=a=>{let c;if(t instanceof HTMLInputElement&&t.type==="checkbox"){c=t.value;const l=t.getAttribute("data-true-value"),d=t.getAttribute("data-false-value");let u=Array.isArray(e[r])?e[r]:void 0;if(u){if(t.checked)u.includes(c)||u.push(c);else{const f=u.indexOf(c);f!==-1&&u.splice(f,1)}s(e,r,[...u])}else l!==null||d!==null?t.checked?s(e,r,l):s(e,r,d!==null?d:!1):s(e,r,t.checked)}else t instanceof HTMLInputElement&&t.type==="radio"?(c=t.value,s(e,r,c),((t.form||t.closest("form")||t.getRootNode())instanceof Element?(t.form||t.closest("form")||t.getRootNode()).querySelectorAll(`input[type="radio"][name="${t.name}"][data-model="${n}"]`):[]).forEach(d=>{d.checked=d.value===String(c)})):(c=t.value,t instanceof HTMLInputElement&&t.type==="number"&&(c=Number(c)),o.includes("trim")&&typeof c=="string"&&(c=c.trim()),o.includes("number")&&(c=Number(c)),s(e,r,c));if("_vnode"in t&&typeof t._vnode=="object"&&t._vnode?.props&&(t._vnode.props.value=c),a.type==="input"&&(t._isDirty=!0),a.type==="keydown"&&a.key==="Enter"&&(t._isDirty=!1,t instanceof HTMLElement&&t.isConnected)){let l=t.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"&&(t._isDirty=!1)};t.addEventListener("input",i),t.addEventListener("change",i),t.addEventListener("keydown",i),t.addEventListener("blur",i)}const M=(()=>{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(t,e={}){const{development:n=M,cache:r=!0,optimize:o=!0}=e,s=G(t);if(r&&j.has(s)){if(n){const i=T.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheHits++,T.set(s,i)}return j.get(s)}if(n){const i=T.get(s)||{compilationTime:0,renderTime:0,updateTime:0,cacheHits:0,cacheMisses:0};i.cacheMisses++,T.set(s,i)}try{const i=ut(t,{development:n,optimize:o});return r&&j.set(s,i),i}catch(i){return n&&(console.error("[Template Compiler] Error compiling template:",i),console.error("[Template Compiler] Template:",t)),{statics:[t],dynamics:[],fragment:null,id:s,hasDynamics:!1,render:()=>t}}}function dt(t,e){if(typeof document>"u")return[0];try{let n=function(a,c=[]){if(a.nodeType===Node.TEXT_NODE){if(a.textContent?.includes(e))return c}else if(a.nodeType===Node.ELEMENT_NODE){let l=0;for(let d=0;d<a.childNodes.length;d++){const u=a.childNodes[d],f=n(u,[...c,l]);if(f)return f;l++}}return null};const s=new DOMParser().parseFromString(`<div>${t}</div>`,"text/html").body.firstElementChild;return n(s)||[0]}catch(n){return M&&console.warn("[Template Compiler] Error finding DOM path for placeholder:",e,n),[0]}}function ut(t,e){return new ft(t,e).compile()}class ft{template;options;dynamics=[];statics=[];constructor(e,n){this.template=e,this.options=n}compile(){this.parseTemplate();const e=this.createStaticFragment(),n=G(this.template),r=(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 d=l.getValue(o,s);return d instanceof Promise?d:Promise.resolve(d)})).then(l=>{let d="";for(let u=0;u<this.statics.length;u++)d+=this.statics[u],u<l.length&&(d+=l[u]);return d});i+=c}return i};return{statics:this.statics,dynamics:this.dynamics,fragment:e,id:n,hasDynamics:this.dynamics.length>0,render:r}}parseTemplate(){const e=/\{\{([^}]+)\}\}/g;let n=0,r;for(;(r=e.exec(this.template))!==null;){const s=this.template.slice(n,r.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 d=s.match(/style\s*=\s*"?([^:;]+):\s*$/);d&&(c=d[1].trim())}const l=r[1].trim();this.analyzeDynamicExpression(l,this.dynamics.length,a,c),n=r.index+r[0].length}const o=this.template.slice(n);this.statics.push(o)}analyzeDynamicExpression(e,n,r,o){let s="text",i;r?r==="class"?(s="class",i="class"):r==="style"?(s="style",i=o||"style"):r==="value"?(s="property",i="value"):(s="attribute",i=r):e.includes("class.")?(s="class",i=e.split(".")[1]):e.includes("style.")?(s="style",i=e.split(".")[1]):e.includes("@")?(s="event",i=e.split("@")[1]):e==="class"?(s="class",i="class"):e==="style"?(s="style",i="style"):e==="value"?(s="property",i="value"):e==="title"&&(s="attribute",i="title");const a=`__DYNAMIC_${n}__`,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(e)})}createValueGetter(e){return(n,r)=>{try{let o;if(e&&typeof e=="function")o=e(n);else if(typeof e=="string"&&e.startsWith("state.")){const s=e.slice(6);o=n[s]}else typeof e=="string"&&/^[a-zA-Z0-9_$]+$/.test(e)?o=n[e]:(typeof e=="string"&&e.includes("("),o="");return o}catch(o){return this.options.development&&console.warn(`[Template Compiler] Error evaluating expression: ${e}`,o),""}}}createStaticFragment(){if(typeof document>"u")return null;try{const e=this.statics.join("");if(!e.trim())return null;const r=new DOMParser().parseFromString(e,"text/html"),o=document.createDocumentFragment();for(;r.body.firstChild;)o.appendChild(r.body.firstChild);return o}catch(e){return this.options.development&&console.warn("[Template Compiler] Could not create static fragment:",e),null}}}function $(t,e){try{if(e.length===1&&e[0]===0&&t instanceof Element)return t;let n=t;for(let r=0;r<e.length;r++){const o=e[r];if(!n.childNodes||n.childNodes.length<=o)return null;n=n.childNodes[o]}return n}catch{return null}}function H(t,e,n){let r;return t.fragment&&!t.hasDynamics?r=t.fragment.cloneNode(!0):r=ht(t,e,n),r}function U(t,e,n,r,o){if(t.hasDynamics)for(const s of t.dynamics)try{const i=s.getValue(n,r);if(o!==void 0&&s.getValue(o,r)===i)continue;K(e,s,i)}catch(i){console.warn("[Template Compiler] Error applying update:",i)}}function ht(t,e,n){let r="";for(let a=0;a<t.statics.length;a++)if(r+=t.statics[a],a<t.dynamics.length){const c=t.dynamics[a];if(c.type==="text"||c.type==="attribute"){const l=c.getValue(e,n);r+=String(l??"")}else(c.type==="property"||c.type==="class"||c.type==="style")&&(r+="")}if(typeof document>"u")return new DocumentFragment;const s=new DOMParser().parseFromString(r,"text/html"),i=document.createDocumentFragment();for(;s.body.firstChild;)i.appendChild(s.body.firstChild);for(const a of t.dynamics){const c=a.getValue(e,n),l=$(i,a.path);K(l,a,c)}return i}function K(t,e,n){try{if(e.type==="text"){const o=document.createTreeWalker(t,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: ${n}`);i.textContent=l,s=!0}}if(s)return;const a=$(t,e.path);a&&a.nodeType===Node.TEXT_NODE&&(a.textContent=n==null?"":String(n));return}const r=$(t,e.path);if(!r)return;switch(e.type){case"attribute":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;n==null||n===""?o.removeAttribute(e.target):o.setAttribute(e.target,String(n))}break;case"property":r.nodeType===Node.ELEMENT_NODE&&e.target&&(r[e.target]=n??"",r.setAttribute(e.target,n==null?"":String(n)));break;case"class":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;o.className=n==null?"":String(n),o.setAttribute("class",n==null?"":String(n))}break;case"style":if(r.nodeType===Node.ELEMENT_NODE&&e.target){const o=r;o.style[e.target]=n==null?"":String(n),o.setAttribute("style",n==null?`${e.target}:`:`${e.target}:${n}`)}break;default:throw new Error(`Unknown update type: ${e.type}`)}}catch(r){(typeof globalThis<"u"?globalThis.isDevelopment:M)&&console.warn("[Template Compiler] Error applying update:",e,r)}}const j=new Map,T=new Map;function G(t){let e=0;for(let n=0;n<t.length;n++){const r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return`tpl_${Math.abs(e).toString(36)}`}function N(t,e,n,r,o){return r&&o?`${e}.${t}[${n}]:${r}:${o}`:r?`${e}.${t}[${n}]:${r}`:`${e}.${t}[${n}]`}function I(t,e,n){if(!(!t||!(t instanceof Element))&&t.contains(n)&&n.parentNode===t)try{t.replaceChild(e,n)}catch(r){console.error("[VDOM] safeReplaceChild: error replacing child",r,{parent:t,newChild:e,oldChild:n,parentHTML:t.outerHTML,newChildHTML:e.outerHTML,oldChildHTML:n.outerHTML})}}function b(t){if(t.type==="#whitespace")return null;if(t.type==="#text"){const n=document.createTextNode(t.props.nodeValue??"");return t.dom=n,n}const e=document.createElement(t.type);for(const[n,r]of Object.entries(t.props))n==="value"&&e instanceof HTMLInputElement?e.type==="radio"?e.setAttribute("value",r):(e.type,e.value=r,e.setAttribute("value",r)):e.setAttribute(n,r);t.dom=e;for(const n of t.children){const r=b(n);r&&e.appendChild(r)}return e}function B(t){const e=document.createElement("template");e.innerHTML=t.trim();const n=Array.from(e.content.childNodes);return n.length===1?w(n[0]):{type:"#fragment",key:void 0,props:{},children:n.map((o,s)=>w(o,"#fragment",s)),dom:void 0}}function w(t,e="",n=0){if(!t)return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0};if(t.nodeType===Node.TEXT_NODE)return!t.nodeValue||/^\s*$/.test(t.nodeValue)?{type:"#whitespace",key:void 0,props:{},children:[],dom:void 0}:{type:"#text",key:N("#text",e,n),props:{nodeValue:t.nodeValue},children:[],dom:t};if(t.nodeType===Node.ELEMENT_NODE){const r=t,o={};Array.from(r.attributes).forEach(l=>{o[l.name]=l.value});const s=r.tagName.toLowerCase();let i;if((s==="input"||s==="select"||s==="textarea")&&r.hasAttribute("data-model")){const l=r.getAttribute("data-model"),d=r.getAttribute("type")??"";i=`${s}:${l}:${d}`,o["data-uid"]=i,r.setAttribute("data-uid",i);let u=r.getAttribute("value"),f=r.getAttribute("checked");u&&(o.value=u),f&&(o.checked=f)}else s==="input"||s==="textarea"||s==="select"||r.hasAttribute("contenteditable")?(i=`${s}:${e}:${n}`,o["data-uid"]=i,r.setAttribute("data-uid",i)):(i=N(s,e,n),s==="li"&&(o["data-uid"]=i,r.setAttribute("data-uid",i)));const a=Array.from(r.childNodes).map((l,d)=>w(l,i,d));return{type:s,key:i,props:o,children:a,dom:r}}return{type:"#unknown",key:void 0,props:{},children:[],dom:void 0}}function S(t,e,n){if(!e||!n)return;function r(c){return!!c&&c.type!=="#whitespace"&&!(c.type==="#text"&&(!c.props?.nodeValue||/^\s*$/.test(c.props.nodeValue)))}const o=Array.isArray(e.children)?e.children.filter(r):[],s=Array.isArray(n.children)?n.children.filter(r):[],i=n.type==="input"||n.type==="select"||n.type==="textarea";if(e.type!==n.type||e.key!==n.key){const c=b(n);if(c instanceof Node&&e.dom instanceof Node&&t.contains(e.dom)){if(I(t,c,e.dom),i&&n.props&&t.firstChild instanceof HTMLInputElement){const l=t.firstChild;l.type==="radio"||l.type,l.value=n.props.value,l.setAttribute("value",n.props.value),"checked"in n.props&&(l.checked=n.props.checked===!0||n.props.checked==="true")}}else if(c instanceof Node)if(c){if(t.appendChild(c),n.dom=c,i&&n.props&&t.firstChild instanceof HTMLInputElement){const l=t.firstChild;l.type==="radio"?l.setAttribute("value",n.props.value):(l.type,l.value=n.props.value,l.setAttribute("value",n.props.value)),"checked"in n.props&&(l.checked=n.props.checked===!0||n.props.checked==="true")}}else n.dom=void 0;else n.dom=void 0;return}if(i&&e.dom instanceof HTMLElement&&n.props){for(const[c,l]of Object.entries(n.props))if(c==="value"&&t.firstChild instanceof HTMLInputElement)t.firstChild.value=l;else if(c==="checked"&&t.firstChild instanceof HTMLInputElement)t.firstChild.checked=l===!0||l==="true";else if(c in e.dom)try{e.dom[c]=l}catch{}else e.dom.setAttribute(c,l);for(let c=n.children.length;c<o.length;c++)o[c]&&o[c].dom&&e.dom&&e.dom.contains(o[c].dom)&&e.dom.removeChild(o[c].dom);return}const a=e.dom;if(a&&a instanceof Element&&n.props){const c=a.tagName.toLowerCase()==="input"?a.getAttribute("type"):void 0,l=a.tagName.includes("-");for(const[d,u]of Object.entries(n.props))if(!(c==="radio"&&d==="value")){if(c==="checkbox"&&d==="value"){a.setAttribute("value",u);continue}a.setAttribute(d,u)}if(l)for(const[d,u]of Object.entries(n.props))a.setAttribute(d,u);for(const d of Array.from(a.attributes).map(u=>u.name))if(!(d in n.props)){if(c==="radio"&&d==="value"||c==="checkbox"&&d==="value")continue;a.removeAttribute(d)}}if(n.type==="#text"){if(a&&a.nodeType===Node.TEXT_NODE)a.nodeValue!==n.props.nodeValue&&(a.nodeValue=n.props.nodeValue),n.dom=a;else{const c=document.createTextNode(n.props.nodeValue??"");a&&t.contains(a)&&a.parentNode===t?I(t,c,a):t.appendChild(c),n.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 d=[];for(let f=0;f<s.length;f++){const h=s[f],y=h.key?c.get(h.key):o[f];let m;const x=h.type==="input"||h.type==="select"||h.type==="textarea";if(y&&y.dom&&(!x||y.type===h.type&&y.key===h.key))S(a,y,h),m=y.dom;else{const O=b(h);if(m=O instanceof Node?O:void 0,m){if((m instanceof Element||m instanceof Node)&&m.contains(a))throw console.error("[VDOM] Attempted to insert a parent into its own child:",{parentTag:a.tagName,childTag:m.tagName,parentUid:a.getAttribute?.("data-uid"),childUid:m.getAttribute?.("data-uid"),parent:a,child:m}),new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(m,a.childNodes[f]||null)}}h.dom=m,m&&d.push(m)}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<d.length;f++)if(a.childNodes[f]!==d[f]){if((d[f]instanceof Element||d[f]instanceof Node)&&d[f].contains(a))throw new Error("VDOM patch error: Attempted to insert a parent into its own child");a.insertBefore(d[f],a.childNodes[f]||null)}n.dom=a;const u=new Set(s.map(f=>f.key));Array.from(a.childNodes).forEach((f,h)=>{const y=f.getAttribute?.("data-uid");(y&&!u.has(y)||h>=s.length)&&a.removeChild(f)})}}const pt=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},v=(t,e)=>{for(const n of t){const r=[],o=n.path.replace(/:[^/]+/g,a=>(r.push(a.slice(1)),"([^/]+)")),s=new RegExp(`^${o}$`),i=e.match(s);if(i){const a={};return r.forEach((c,l)=>{a[c]=i[l+1]}),{route:n,params:a}}}return{route:null,params:{}}},D={};async function Z(t){if(t.component)return t.component;if(t.load){if(D[t.path])return D[t.path];try{const e=await t.load();return D[t.path]=e.default,e.default}catch{throw new Error(`Failed to load component for route: ${t.path}`)}}throw new Error(`No component or loader defined for route: ${t.path}`)}function V(t){const{routes:e,base:n=""}=t;let r,o,s,i,a,c,l;if(typeof window<"u"&&typeof document<"u"){r=()=>{const u=new URL(window.location.href),f=u.pathname.replace(n,"")||"/",h=pt(u.search);return{path:f,query:h}},o=r();const d=v(e,o.path);s=L({path:o.path,params:d.params,query:o.query}),i=()=>{const u=r(),f=v(e,u.path),h=s.getState();h.path=u.path,h.params=f.params,h.query=u.query},window.addEventListener("popstate",i),a=u=>{window.history.pushState({},"",n+u),i()},c=u=>{window.history.replaceState({},"",n+u),i()},l=()=>window.history.back()}else{r=()=>({path:"/",query:{}}),o=r();const d=v(e,o.path);s=L({path:o.path,params:d.params,query:o.query}),i=()=>{},a=()=>{},c=()=>{},l=()=>{}}return{store:s,push:a,replace:c,back:l,subscribe:s.subscribe,matchRoute:d=>v(e,d),getCurrent:()=>s.getState(),resolveRouteComponent:Z}}function mt(t){const e=V(t);return typeof window<"u"&&(window.__routerInstance=e),e}function yt(t,e){return v(t,e)}function P(t,e){const n=[],r=e?Object.keys(e):[],o={...t};let s=null;function i(d){return n.push(d),()=>{const u=n.indexOf(d);u!==-1&&n.splice(u,1)}}function a(d){Object.assign(s,d),n.forEach(u=>u(s))}const c=new WeakMap;function l(d){if(c.has(d))return c.get(d);const u=new Proxy(d,{get(f,h,y){if(h==="subscribe")return i;if(h==="set")return a;if(e&&r.includes(h))return e[h](s);const m=Reflect.get(f,h,y);return typeof m=="object"&&m!==null?l(m):m},set(f,h,y,m){if(e&&r.includes(h))return!1;const x=f[h],O=Reflect.set(f,h,y,m);return x!==y&&n.forEach(bt=>bt(s)),O},deleteProperty(f,h){if(e&&r.includes(h))return!1;const y=Reflect.deleteProperty(f,h);return n.forEach(m=>m(s)),y}});return c.set(d,u),u}return s=l(o),s}const _=[];function gt(t){_.push(t)}function A(t,e=new WeakSet){if(t===null||typeof t!="object"||e.has(t))return t;if(e.add(t),Array.isArray(t))return t.map(o=>A(o,e));Object.getPrototypeOf(t)!==Object.prototype&&Object.getPrototypeOf(t)!==null&&Object.setPrototypeOf(t,null);const n=["__proto__","constructor","prototype"],r=Object.create(null);for(const o of Object.keys(t))n.includes(o)||(r[o]=A(t[o],e));return r}function R(t){return!!t&&typeof t.then=="function"}let X;typeof HTMLElement<"u"&&(X=class extends HTMLElement{syncStateToAttributes(){if(!this.stateObj||!this.config?.reflect||!Array.isArray(this.config.reflect))return;const t=["__proto__","constructor","prototype"];this.config.reflect.forEach(e=>{if(t.includes(e)){this.removeAttribute(e);return}const n=this.stateObj[e];["string","number","boolean"].includes(typeof n)?n==null?this.removeAttribute(e):this.setAttribute(e,String(n)):this.removeAttribute(e)})}setTemplate(t){const e=this.config;typeof t=="function"?e.template=t:e.template=()=>t,this.render()}_hasError=!1;_mountedCalled=!1;_unmountedCalled=!1;_autoWiredHandlers={};removeEventListener(t,e,n){super.removeEventListener(t,e,n),this._autoWiredHandlers[t]&&(this._autoWiredHandlers[t]=this._autoWiredHandlers[t].filter(r=>r===e?(super.removeEventListener(t,r,n),!1):!0),this._autoWiredHandlers[t].length===0&&delete this._autoWiredHandlers[t])}static get observedAttributes(){const t=this.stateObj||{};return Object.keys(t).filter(e=>["string","number","boolean"].includes(typeof t[e]))}attributeChangedCallback(t,e,n){if(!(t==="__proto__"||t==="constructor"||t==="prototype")&&this.stateObj&&t in this.stateObj){const r=typeof this.config?.state?.[t];let o=n;if(n===null)o=void 0;else if(r==="number")if(o===void 0||o==="")o=this.config?.state?.[t];else{const s=Number(o);o=isNaN(s)?this.config?.state?.[t]:s}else r==="boolean"&&(o=o==="true");o=A(o),this.stateObj[t]!==o&&(this.config?.debug&&console.log("[runtime] state update:",{name:t,value:o}),this.stateObj[t]=o,this.render())}}forceSyncControlledInputs(){this.shadowRoot&&(this.shadowRoot.querySelectorAll("input[data-model]").forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]),o=document.activeElement===n;n._hasDirtyListener||(n.addEventListener("input",()=>{n._isDirty=!0}),n.addEventListener("blur",()=>{n._isDirty=!1}),n._hasDirtyListener=!0);const s=!!n._isDirty;o||s||n.type!=="radio"&&n.type!=="checkbox"&&n.value!==r&&(n.value=r)}),this.rebindEventListeners())}syncControlledInputsAndEvents(){this.shadowRoot&&(this.shadowRoot.querySelectorAll('input[type="radio"][data-model]').forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]);n.checked=n.value===r}),this.shadowRoot.querySelectorAll("input[data-model]").forEach(t=>{const e=t.getAttribute("data-model");if(!e||!this.stateObj||typeof this.stateObj[e]>"u")return;const n=t,r=String(this.stateObj[e]);if(n.type==="checkbox"){const o=this.stateObj[e];if(Array.isArray(o))n.checked=o.includes(n.value);else{const s=n.getAttribute("data-true-value"),i=n.getAttribute("data-false-value");s!==null||i!==null?String(o)===s?n.checked=!0:String(o)===i?n.checked=!1:o===!0?n.checked=!0:n.checked=!1:n.checked=o===!0||o==="true"||o===1}}else n.type==="radio"||(n.value=r)}),this.shadowRoot.querySelectorAll("textarea[data-model]").forEach(t=>{const e=t.getAttribute("data-model");!e||!this.stateObj||typeof this.stateObj[e]>"u"||(t.value=String(this.stateObj[e]))}),this.shadowRoot.querySelectorAll("select[data-model]").forEach(t=>{const e=t.getAttribute("data-model");!e||!this.stateObj||typeof this.stateObj[e]>"u"||(t.value=String(this.stateObj[e]))}))}attachListItemModelListeners(){this.shadowRoot&&this.shadowRoot.querySelectorAll("input[data-bind]").forEach(t=>{const e=t.getAttribute("data-bind");if(!e)return;t._listItemModelListener&&(t.removeEventListener("input",t._listItemModelListener),t.removeEventListener("change",t._listItemModelListener),delete t._listItemModelListener);const n=e.match(/^([a-zA-Z0-9_]+)\[(\d+)\]\.([a-zA-Z0-9_]+)$/);if(n){const[,o,s,i]=n,a=parseInt(s,10),c=this.stateObj[o];t instanceof HTMLInputElement&&t.type==="checkbox"&&(t.checked=!!(Array.isArray(c)&&c[a]&&c[a][i]));const l=d=>{!Array.isArray(c)||!c[a]||(t instanceof HTMLInputElement&&t.type==="checkbox"?c[a][i]=t.checked:c[a][i]=t.value)};t.addEventListener("input",l),t.addEventListener("change",l),t._listItemModelListener=l;return}const r=e.match(/^([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)((?:\|[a-zA-Z0-9_]+)*)$/);if(r){const[,o,s,i]=r,a=this.stateObj[o],c=i?i.split("|").map(d=>d.trim()).filter(Boolean):[];t instanceof HTMLInputElement&&t.type==="checkbox"?t.checked=!!(a&&a[s]):t instanceof HTMLInputElement&&(t.value=a?String(a[s]??""):"");const l=d=>{if(!a)return;let u;t instanceof HTMLInputElement&&t.type==="checkbox"?u=t.checked:(u=t.value,c.includes("number")&&(u=Number(u)),c.includes("trim")&&typeof u=="string"&&(u=u.trim())),a[s]=u};t.addEventListener("input",l),t.addEventListener("change",l),t._listItemModelListener=l}})}attachControlledInputListeners(){const t=this.shadowRoot;t&&(t.querySelectorAll("[data-model]").forEach(e=>{const n=e.getAttribute("data-model");n&&(e._dataModelBound||(F(e,this.stateObj,n),e._dataModelBound=!0))}),t.querySelectorAll("[data-model]").forEach(e=>{const[n]=e.getAttribute("data-model")?.split("|").map(r=>r.trim())??[];if(!(!n||!(n in this.stateObj)))if(e instanceof HTMLInputElement)if(e.type==="checkbox"){const r=this.stateObj[n],o=e.getAttribute("data-true-value"),s=e.getAttribute("data-false-value");Array.isArray(r)?e.checked=r.includes(e.value):o!==null||s!==null?String(r)===o?e.checked=!0:String(r)===s?e.checked=!1:r===!0?e.checked=!0:e.checked=!1:e.checked=r===!0||r==="true"||r===1}else e.type==="radio"?e.checked=e.value===String(this.stateObj[n]):e.value=String(this.stateObj[n]??"");else(e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(e.value=String(this.stateObj[n]??""))}))}config;stateObj;api;_globalUnsubscribes=[];unsubscribes=[];lastCompiledTemplate=null;lastState=null;rafId=null;constructor(){super()}initializeConfig(){if(this.config)return;const t=this.tagName.toLowerCase(),n=(window.__componentRegistry||{})[t];if(!n||typeof n!="object")throw new Error("Invalid component config: must be an object");if(!n.state||typeof n.state!="object")throw new Error("Invalid component config: state must be an object");this.config=n;const r=n.computed?P(n.state,n.computed):P(n.state);if(this.stateObj=r,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)},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"}),n.style){const s=document.createElement("style");s.textContent=typeof n.style=="function"?n.style(this.stateObj):n.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);R(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 t of this.getAttributeNames())if(t in this.stateObj){const e=typeof this.config?.state?.[t];let n=this.getAttribute(t);e==="number"?n=Number(n):e==="boolean"&&(n=n==="true"),this.stateObj[t]=n===null?void 0:n}}if(!this._mountedCalled&&typeof this.config.onMounted=="function")try{const t=this.config.onMounted(this.api.state,this.api);R(t)?t.catch(e=>{typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e)}).finally(()=>{this._mountedCalled=!0}):this._mountedCalled=!0}catch(t){typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t),this._mountedCalled=!0}typeof this.render=="function"&&this.render()}disconnectedCallback(){if(Object.entries(this._autoWiredHandlers).forEach(([t,e])=>{e.forEach(n=>{super.removeEventListener(t,n)})}),this._autoWiredHandlers={},this.unsubscribes.forEach(t=>t()),this.unsubscribes=[],this._globalUnsubscribes.forEach(t=>t()),this._globalUnsubscribes=[],!this._unmountedCalled&&typeof this.config.onUnmounted=="function")try{const t=this.config.onUnmounted(this.api.state,this.api);R(t)?t.catch(e=>{typeof this.config.onError=="function"&&this.config.onError(e,this.api.state,this.api),this._handleRenderError(e)}).finally(()=>{this._unmountedCalled=!0}):this._unmountedCalled=!0}catch(t){typeof this.config.onError=="function"&&this.config.onError(t,this.api.state,this.api),this._handleRenderError(t),this._unmountedCalled=!0}this._mountedCalled=!1,this._unmountedCalled=!1}render(){this._hasError=!1,this.syncControlledInputsAndEvents(),setTimeout(()=>this.attachControlledInputListeners(),0);try{_.forEach(e=>{try{e.onRender?.(this.stateObj,this.api)}catch(n){this._handleRenderError(n)}}),this.config.computed&&Object.values(this.config.computed).forEach(e=>{try{e(this.stateObj)}catch(n){this._handleRenderError(n)}});const t=this.config.template(this.stateObj,this.api);t instanceof Promise?t.then(e=>{this._hasError||(this._renderTemplateResult(e),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}).catch(e=>{this._handleRenderError(e)}):this._hasError||(this._renderTemplateResult(t),this.syncStateToAttributes(),setTimeout(()=>this.attachListItemModelListeners(),0))}catch(t){this._handleRenderError(t),this.renderError(t instanceof Error?t:new Error(String(t)))}}_prevVNode=null;rebindEventListeners(){if(!this.shadowRoot)return;["data-on-input","data-on-change","data-on-blur","data-on-click"].forEach(e=>{this.shadowRoot.querySelectorAll(`[${e}]`).forEach(n=>{const r=e.replace("data-on-",""),o=n.getAttribute(e);if(!o||typeof this.config[o]!="function")return;n._boundHandlers&&n._boundHandlers[r]&&n.removeEventListener(r,n._boundHandlers[r]);const s=this.config[o],i=a=>s.call(this,a);n.addEventListener(r,i),n._boundHandlers||(n._boundHandlers={}),n._boundHandlers[r]=i})}),Array.from(this.shadowRoot.children).forEach(e=>{e instanceof HTMLElement&&typeof e.rebindEventListeners=="function"&&e.rebindEventListeners()})}_renderTemplateResult(t){if(!this._hasError)try{let e=function(n){const r=new WeakSet;function o(s){if(s===null||typeof s!="object"||r.has(s))return s;if(r.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(n)};if(typeof t=="string"){let n=function(c){return c.replace(/<([a-zA-Z0-9]+)([^>]*)>/g,(l,d,u)=>{const f=u.replace(/\s+on[a-zA-Z]+\s*=\s*(['"][^'"]*['"]|[^\s>]*)/gi,"");return`<${d}${f}>`})},r=function(c){c.children.forEach(r)};const o=n(t),s=B(o);r(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(u=>{u.nodeType===1&&u.nodeName==="STYLE"||c.removeChild(u)});const l={type:"#fragment",dom:c,children:s.children,props:{},key:void 0},d=this._prevVNode&&this._prevVNode.type==="#fragment"?{...this._prevVNode,dom:c}:l;S(c,d,l)}else s.children.forEach(l=>{const d=b(l);d&&i.appendChild(d),l.dom=d??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=b(s);l&&(this.shadowRoot.contains(c)&&this.shadowRoot.replaceChild(l,c),c=l)}else S(c,this._prevVNode,s);else c=b(s),c&&this.shadowRoot.appendChild(c);s.dom=c}this._prevVNode=s,this.forceSyncControlledInputs(),this.lastCompiledTemplate=null}else{const n=!this.shadowRoot.firstElementChild,r=this.lastCompiledTemplate?.id===t.id;if(n){const o=H(t,this.stateObj,this.api);this.shadowRoot.appendChild(o)}else if(r&&this.shadowRoot.firstElementChild){const o=this.lastState;U(t,this.shadowRoot.firstElementChild,this.stateObj,this.api,o||void 0)}else{const o=H(t,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=t}this.lastState=e(this.stateObj),this.updateStyle(),this.processRefs(),this.bindEvents(),this.syncControlledInputsAndEvents()}catch(e){this._handleRenderError(e)}}_handleRenderError(t){if(this._hasError=!0,this.config.debug&&console.error(`[runtime] Render error in <${this.tagName.toLowerCase()}>:`,t),_.forEach(e=>e.onError?.(t instanceof Error?t:new Error(String(t)),this.stateObj,this.api)),"onError"in this.config&&typeof this.config.onError=="function")try{this.config.onError(t instanceof Error?t:new Error(String(t)),this.api.state,this.api)}catch(e){this.config.debug&&console.error("[runtime] Error in onError handler:",e)}this.renderError(t instanceof Error?t:new Error(String(t)))}scheduleRender(){this.rafId!==void 0&&this.rafId!==null&&cancelAnimationFrame(this.rafId),this.rafId=requestAnimationFrame(()=>{this.render(),this.rafId=null})}updateStyle(){const t=this.shadowRoot.querySelector("style");if(!t||!this.config.style)return;const e=typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style;t.textContent=e}processRefs(){if(!this.config.refs)return;const t=new WeakMap;Object.entries(this.config.refs).forEach(([e,n])=>{const r=this.shadowRoot.querySelector(`[data-ref="${e}"]`);if(r){t.has(r)||t.set(r,new Set);const o=t.get(r),s=r.addEventListener;r.addEventListener=function(i,a,c){const l=`${i}`;o.has(l)||(o.add(l),s.call(r,i,a,c))},r.setAttribute("data-refs-processed","true");try{n(r,this.api.state,this.api)}catch(i){this._handleRenderError(i)}}})}bindEvents(){if(!this.shadowRoot)return;const t=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_ELEMENT);let e=t.nextNode();for(;e;){const n=e;Array.from(n.attributes).forEach(r=>{if(r.name.startsWith("data-on-")){const o=r.name.slice(8),s=r.value,i=this.config[s];if(typeof i=="function"){n._boundHandlers&&n._boundHandlers[o]&&n.removeEventListener(o,n._boundHandlers[o]);const a=c=>{i.call(this.config,c,this.api.state,this.api),this.syncControlledInputsAndEvents()};n.addEventListener(o,a),n._boundHandlers||(n._boundHandlers={}),n._boundHandlers[o]=a}else this.config.debug&&console.warn(`[runtime] Handler '${s}' not found on config for event '${o}'`,n)}}),e=t.nextNode()}}renderError(t){const e=this.config.style?typeof this.config.style=="function"?this.config.style(this.api.state):this.config.style:"";this.shadowRoot.innerHTML=`
|
|
40
40
|
<style>${e}</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: ${t.message}</div>
|
|
44
44
|
</div>
|
|
45
|
-
`}});function
|
|
45
|
+
`}});function Y(t,e){if(e=A(e),e.debug&&console.log(`[runtime] Debugging component: ${t}`,e),!t||!e.template){e&&typeof e.onError=="function"&&e.onError(new Error("Component requires tag and template"),e.state??{},{state:e.state??{},emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),e&&e.debug&&console.error("[runtime] Malformed config:",{tag:t,config:e});return}_.forEach(d=>{try{d.onInit?.(e)}catch(u){e&&typeof e.onError=="function"&&e.onError(u instanceof Error?u:new Error(String(u)),e.state,{state:e.state,emit:()=>{},onGlobal:()=>()=>{},offGlobal:()=>{},emitGlobal:()=>{}}),e&&e.debug&&console.error("[runtime] Plugin onInit error:",u)}});const r=typeof window<"u"&&window.VITE_DEV_HMR,o=typeof{url:typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:g&&g.tagName.toUpperCase()==="SCRIPT"&&g.src||new URL("custom-elements-runtime.umd.js",document.baseURI).href}<"u"&&void 0;if((r||o)&&customElements.get(t))try{document.querySelectorAll(t).forEach(d=>d.remove()),window.customElements._definitions&&delete window.customElements._definitions[t]}catch{}if(customElements.get(t)){e.debug&&console.warn(`[runtime] Component "${t}" already registered`);return}const s=P(e.state??{},e.computed);e.state=s,e._subscribe=s.subscribe;const i=e.state??{},a=Object.keys(i).filter(d=>["string","number","boolean"].includes(typeof i[d]));class c extends X{static get observedAttributes(){return a}constructor(){super()}}const l=c;typeof customElements<"u"&&!customElements.get(t)&&(window.__componentRegistry=window.__componentRegistry||{},window.__componentRegistry[t]=e,customElements.define(t,l))}Y("router-view",{template:(t,e)=>{const n=window.__routerInstance;if(!n)return"<div>Router not initialized.</div>";const{path:r}=n.getCurrent(),o=n.matchRoute(r);return o.route?`<${o.route.component}></${o.route.component}>`:"<div>Not found</div>"}}),p.Store=L,p.classes=at,p.compile=it,p.compileTemplate=lt,p.component=Y,p.createVNodeFromElement=w,p.css=ot,p.deepSanitizeObject=A,p.eventBus=C,p.generateHydrationScript=et,p.getVNodeKey=N,p.html=st,p.initRouter=mt,p.isPromise=R,p.matchRouteSSR=yt,p.mountVNode=b,p.parseVNodeFromHTML=B,p.patchVNode=S,p.renderCompiledTemplate=H,p.renderComponentsToString=tt,p.renderToString=q,p.resolveRouteComponent=Z,p.runtimePlugins=_,p.safeReplaceChild=I,p.styles=ct,p.updateCompiledTemplate=U,p.useDataModel=F,p.useRouter=V,p.useRuntimePlugin=gt,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
|
46
46
|
//# sourceMappingURL=custom-elements-runtime.umd.js.map
|