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