ladrillosjs 2.0.0-beta.2.2 → 2.0.0-beta.3

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/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ComponentRegistration } from "./types/LadrilloTypes.js";
1
2
  declare global {
2
3
  interface Window {
3
4
  ladrillosjs: {
@@ -13,12 +14,8 @@ declare global {
13
14
  $getState: typeof $getState;
14
15
  }
15
16
  }
16
- export declare const registerComponent: (name: string, path: string, useShadowDOM?: boolean) => Promise<void>;
17
- export declare const registerComponents: (components: Array<{
18
- name: string;
19
- path: string;
20
- useShadowDOM?: boolean;
21
- }>) => Promise<void>;
17
+ export declare const registerComponent: (name: string, path: string, useShadowDOM?: boolean, lazy?: boolean) => Promise<void>;
18
+ export declare const registerComponents: (components: ComponentRegistration[]) => Promise<void>;
22
19
  export declare const $listen: (event: string, callback: (data?: any) => void) => () => void;
23
20
  export declare const $emit: (event: string, data?: any) => void;
24
21
  /**
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CMmTngHq.js");exports.$emit=e.$emit;exports.$getState=e.$getState;exports.$listen=e.$listen;exports.$querySelector=e.$querySelector;exports.$querySelectorAll=e.$querySelectorAll;exports.$reactive=e.$reactive;exports.$setState=e.$setState;exports.__setComponentContext=e.__setComponentContext;exports.registerComponent=e.registerComponent;exports.registerComponents=e.registerComponents;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DZgn4gH2.js");exports.$emit=e.$emit;exports.$getState=e.$getState;exports.$listen=e.$listen;exports.$querySelector=e.$querySelector;exports.$querySelectorAll=e.$querySelectorAll;exports.$reactive=e.$reactive;exports.$setState=e.$setState;exports.__setComponentContext=e.__setComponentContext;exports.registerComponent=e.registerComponent;exports.registerComponents=e.registerComponents;
2
2
  //# sourceMappingURL=ladrillosjs.cjs.js.map
@@ -1,14 +1,14 @@
1
- import { b as s, c as a, $ as r, g as o, h as n, f as $, d as i, _ as l, r as m, a as c } from "./index-CrzikOU3.mjs";
1
+ import { k as s, m as a, $ as o, p as r, q as n, o as $, n as m, _ as i, r as l, j as p } from "./index-DymB3-NG.mjs";
2
2
  export {
3
3
  s as $emit,
4
4
  a as $getState,
5
- r as $listen,
6
- o as $querySelector,
5
+ o as $listen,
6
+ r as $querySelector,
7
7
  n as $querySelectorAll,
8
8
  $ as $reactive,
9
- i as $setState,
10
- l as __setComponentContext,
11
- m as registerComponent,
12
- c as registerComponents
9
+ m as $setState,
10
+ i as __setComponentContext,
11
+ l as registerComponent,
12
+ p as registerComponents
13
13
  };
14
14
  //# sourceMappingURL=ladrillosjs.es.js.map
@@ -1,27 +1,38 @@
1
- (function(m,y){typeof exports=="object"&&typeof module!="undefined"?y(exports):typeof define=="function"&&define.amd?define(["exports"],y):(m=typeof globalThis!="undefined"?globalThis:m||self,y(m.ladrillosjs={}))})(this,(function(m){"use strict";var it=Object.defineProperty,ct=Object.defineProperties;var at=Object.getOwnPropertyDescriptors;var Ae=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var _e=m=>{throw TypeError(m)};var Ce=(m,y,$)=>y in m?it(m,y,{enumerable:!0,configurable:!0,writable:!0,value:$}):m[y]=$,H=(m,y)=>{for(var $ in y||(y={}))lt.call(y,$)&&Ce(m,$,y[$]);if(Ae)for(var $ of Ae(y))ut.call(y,$)&&Ce(m,$,y[$]);return m},Te=(m,y)=>ct(m,at(y));var ie=(m,y,$)=>y.has(m)||_e("Cannot "+$);var C=(m,y,$)=>(ie(m,y,"read from private field"),$?$.call(m):y.get(m)),L=(m,y,$)=>y.has(m)?_e("Cannot add the same private member more than once"):y instanceof WeakSet?y.add(m):y.set(m,$),z=(m,y,$,T)=>(ie(m,y,"write to private field"),T?T.call(m,$):y.set(m,$),$),I=(m,y,$)=>(ie(m,y,"access private method"),$);var R=(m,y,$)=>new Promise((T,U)=>{var Q=M=>{try{D($.next(M))}catch(V){U(V)}},ee=M=>{try{D($.throw(M))}catch(V){U(V)}},D=M=>M.done?T(M.value):Promise.resolve(M.value).then(Q,ee);D(($=$.apply(m,y)).next())});var K,ke;const y=()=>{try{return!1}catch(t){return process.env.NODE_ENV==="development"}},$={log(t,...e){y()&&console.log(t,...e)},error(t,...e){console.error(t,...e)},warn(t,...e){y()&&console.warn(t,...e)}},T=new Map,U=25,Q=t=>{const e=T.get(t);return e&&(T.delete(t),T.set(t,e)),e},ee=(t,e)=>{if(T.has(t))T.delete(t);else if(T.size>=U){const s=T.keys().next().value;s&&T.delete(s)}T.set(t,e)},D=t=>R(null,null,function*(){if(!t)throw new Error("Path cannot be null or empty");const e=Q(t);if(e)return e;try{const s=yield fetch(t);if(!s.ok)throw new Error(`Failed to fetch component from ${t}: ${s.statusText}`);const n=yield s.text();return ee(t,n),n}catch(s){$.error(`Error fetching component from ${t}: ${s.message}`)}}),M=t=>R(null,null,function*(){try{const e=yield fetch(t);if(!e.ok)throw new Error(`HTTP ${e.status}`);return yield e.text()}catch(e){return $.error(`Failed to fetch resource at ${t}:`,e),""}}),V={bindings:/{([^}]+)}/g,comments:{js:/\/\*[\s\S]*?\*\/|\/\/.*$/gm,css:/\/\*[\s\S]*?\*\//g,html:/<!--[\s\S]*?-->/g}},Me=new DOMParser,Ve=(t,e)=>R(null,null,function*(){const s=Fe(t),{scripts:n,externalScripts:o}=Oe(s),r=yield je(s),i=s.body.innerHTML.trim();return{tagName:e,template:i,scripts:n,externalScripts:o,styles:r}}),Fe=t=>Me.parseFromString(t.replace(V.comments.html,""),"text/html"),Ne=t=>["/@vite/","/__vite","/webpack-dev-server","/hot-update","/__webpack_hmr","/browser-sync/","/livereload.js"].some(s=>t.includes(s)),Oe=t=>{var n,o;const e=[],s=[];for(const r of t.querySelectorAll("script")){if(r.src){if(Ne(r.src)){r.remove();continue}const i=r.hasAttribute("external");s.push({src:r.getAttribute("src")||r.src,type:(n=r.type)!=null?n:null,external:i})}else if(r.textContent){let i=r.textContent.trim();i=i.replace(V.comments.js,"").trim(),e.push({content:i,type:(o=r.type)!=null?o:null})}r.remove()}return{scripts:e,externalScripts:s}},Be=t=>{const e=t.match(/const __vite__css = "((?:[^"\\]|\\.)*)"/);if(e&&e[1])return e[1].replace(/\\r\\n/g,`
1
+ (function(b,$){typeof exports=="object"&&typeof module!="undefined"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(b=typeof globalThis!="undefined"?globalThis:b||self,$(b.ladrillosjs={}))})(this,(function(b){"use strict";var wt=Object.defineProperty,yt=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var Fe=Object.getOwnPropertySymbols;var Et=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable;var He=b=>{throw TypeError(b)};var Re=(b,$,d)=>$ in b?wt(b,$,{enumerable:!0,configurable:!0,writable:!0,value:d}):b[$]=d,T=(b,$)=>{for(var d in $||($={}))Et.call($,d)&&Re(b,d,$[d]);if(Fe)for(var d of Fe($))vt.call($,d)&&Re(b,d,$[d]);return b},j=(b,$)=>yt(b,$t($));var ue=(b,$,d)=>$.has(b)||He("Cannot "+d);var x=(b,$,d)=>(ue(b,$,"read from private field"),d?d.call(b):$.get(b)),M=(b,$,d)=>$.has(b)?He("Cannot add the same private member more than once"):$ instanceof WeakSet?$.add(b):$.set(b,d),J=(b,$,d,k)=>(ue(b,$,"write to private field"),k?k.call(b,d):$.set(b,d),d),D=(b,$,d)=>(ue(b,$,"access private method"),d);var L=(b,$,d)=>new Promise((k,U)=>{var se=F=>{try{K(d.next(F))}catch(Z){U(Z)}},oe=F=>{try{K(d.throw(F))}catch(Z){U(Z)}},K=F=>F.done?k(F.value):Promise.resolve(F.value).then(se,oe);K((d=d.apply(b,$)).next())});var X,Pe,Be;const $=()=>{try{return!1}catch(n){return process.env.NODE_ENV==="development"}},d={log(n,...e){$()&&console.log(n,...e)},error(n,...e){console.error(n,...e)},warn(n,...e){$()&&console.warn(n,...e)}},k=(n,e)=>{const t=[n];return e&&(e.componentName&&t.push(`
2
+ Component: <${e.componentName}>`),e.componentPath&&t.push(`
3
+ File: ${e.componentPath}`),e.expression&&t.push(`
4
+ Expression: ${e.expression}`),e.attributeName&&t.push(`
5
+ Attribute: ${e.attributeName}`),e.eventType&&t.push(`
6
+ Event: ${e.eventType}`),e.elementTag&&t.push(`
7
+ Element: <${e.elementTag}>`),e.lineHint&&t.push(`
8
+ Location: ${e.lineHint}`)),t.join("")},U=(n,e,t)=>{const s=k("⚠️ Binding Error: Failed to evaluate expression",j(T({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"Template binding expression"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},se=(n,e,t,s)=>{const o=k("⚠️ Event Handler Error: Failed to execute handler",j(T({},s),{eventType:n,expression:e,lineHint:(s==null?void 0:s.lineHint)||`on${n} handler`}));d.error(o),d.error(` Error details: ${t.message}`),t.stack&&console.debug(" Stack trace:",t.stack)},oe=(n,e,t)=>{const s=k("⚠️ Conditional Error: Failed to evaluate condition",j(T({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$if/$else-if condition"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},K=(n,e,t)=>{const s=k("⚠️ Loop Error: Failed to process loop",j(T({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$for loop expression"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},F=(n,e,t)=>{const s=k("⚠️ Registration Error: Failed to register component",{componentName:n,componentPath:e});d.error(s),d.error(` Error details: ${t.message}`),t.stack&&console.debug(" Stack trace:",t.stack)},Z=(n,e,t)=>{const s=k("⚠️ Fetch Error: Failed to load resource",j(T({},t),{componentPath:n}));d.error(s),d.error(` Error details: ${e.message}`)},fe=(n,e)=>{const t=k(`⚠️ Parse Error: ${n}`,e);d.error(t)},ze=(n,e)=>{const t=k("⚠️ Script Error: Failed to execute component script",e);d.error(t),d.error(` Error details: ${n.message}`),n.stack&&console.debug(" Stack trace:",n.stack)},We=(n,e,t)=>{const s=k("⚠️ Two-Way Binding Error: Failed to setup binding",j(T({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$model binding"}));d.error(s),d.error(` Error details: ${e.message}`)},R=(n,e)=>{var t;return T({componentName:(n==null?void 0:n.tagName)||((t=n==null?void 0:n.constructor)==null?void 0:t.name),componentPath:(n==null?void 0:n.sourcePath)||(n==null?void 0:n._sourcePath)},e)},H=new Map,je=25,qe=n=>{const e=H.get(n);return e&&(H.delete(n),H.set(n,e)),e},Ie=(n,e)=>{if(H.has(n))H.delete(n);else if(H.size>=je){const t=H.keys().next().value;t&&H.delete(t)}H.set(n,e)},pe=n=>L(null,null,function*(){if(!n)throw new Error("Path cannot be null or empty");const e=qe(n);if(e)return e;try{const t=yield fetch(n);if(!t.ok)throw new Error(`Failed to fetch component from ${n}: ${t.statusText}`);const s=yield t.text();return Ie(n,s),s}catch(t){Z(n,t,{componentPath:n})}}),De=n=>L(null,null,function*(){try{const e=yield fetch(n);if(!e.ok)throw new Error(`HTTP ${e.status}`);return yield e.text()}catch(e){return Z(n,e),""}}),G={bindings:/{([^}]+)}/g,comments:{js:/\/\*[\s\S]*?\*\/|\/\/.*$/gm,css:/\/\*[\s\S]*?\*\//g,html:/<!--[\s\S]*?-->/g}},Ue=new DOMParser,he=(n,e)=>L(null,null,function*(){const t=Ze(n),{scripts:s,externalScripts:o}=Je(t),r=yield Ge(t),i=t.body.innerHTML.trim();return{tagName:e,template:i,scripts:s,externalScripts:o,styles:r}}),Ze=n=>Ue.parseFromString(n.replace(G.comments.html,""),"text/html"),Xe=n=>["/@vite/","/__vite","/webpack-dev-server","/hot-update","/__webpack_hmr","/browser-sync/","/livereload.js"].some(t=>n.includes(t)),Je=n=>{var s,o;const e=[],t=[];for(const r of n.querySelectorAll("script")){if(r.src){if(Xe(r.src)){r.remove();continue}const i=r.hasAttribute("external");t.push({src:r.getAttribute("src")||r.src,type:(s=r.type)!=null?s:null,external:i})}else if(r.textContent){let i=r.textContent.trim();i=i.replace(G.comments.js,"").trim(),e.push({content:i,type:(o=r.type)!=null?o:null})}r.remove()}return{scripts:e,externalScripts:t}},Ke=n=>{const e=n.match(/const __vite__css = "((?:[^"\\]|\\.)*)"/);if(e&&e[1])return e[1].replace(/\\r\\n/g,`
2
9
  `).replace(/\\n/g,`
3
- `).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\");const s=t.match(/export\s+default\s+"((?:[^"\\]|\\.)*)"/);return s&&s[1]?s[1].replace(/\\r\\n/g,`
10
+ `).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\");const t=n.match(/export\s+default\s+"((?:[^"\\]|\\.)*)"/);return t&&t[1]?t[1].replace(/\\r\\n/g,`
4
11
  `).replace(/\\n/g,`
5
- `).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):t.includes("import")||t.includes("export")?($.warn("CSS file returned JavaScript module format. CSS may not load correctly."),""):t},je=t=>R(null,null,function*(){let e="";const s=t.querySelectorAll("style, link[rel='stylesheet']");for(const n of s){if(n.tagName==="LINK"){const r=yield M(n.href),i=Be(r);i&&(e+=`
6
- `+i)}else if(n.tagName==="STYLE"){const o=n;if(o.textContent){let r=o.textContent.trim();r=r.replace(V.comments.css,"").trim(),e+=`
7
- `+r}}n.remove()}return e.trim()});class qe{constructor(){L(this,K);this.components={}}registerComponent(e,s,n=!0){return R(this,null,function*(){if(this.components[e]){$.warn(`Component with name "${e}" is already registered.`);return}try{const o=yield D(s),r=yield Ve(o,e);this.components[e]={tagName:e,template:r.template,scripts:r.scripts,externalScripts:r.externalScripts,styles:r.styles,sourcePath:s},$.log(`Component ${e} registered successfully`),yield I(this,K,ke).call(this,e,n)}catch(o){$.error(`Failed to register component "${e}": ${o.message}`);return}})}}K=new WeakSet,ke=function(e,s){return R(this,null,function*(){const{defineWebComponent:n}=yield Promise.resolve().then(()=>rt);this.components[e]&&n(this.components[e],s)})};const ae=new qe;class Pe{constructor(){this.listeners=new Map}emit(e,s){const n=new CustomEvent(e,{detail:s,bubbles:!0,composed:!0});document.dispatchEvent(n);const o=this.listeners.get(e);if(!o||o.size===0)return Promise.resolve();const r=[];return o.forEach(i=>{try{const c=i(s);c instanceof Promise&&r.push(c)}catch(c){console.error(`Error in event listener for "${e}":`,c),r.push(Promise.reject(c))}}),r.length>0?Promise.all(r).then(()=>{}):Promise.resolve()}listen(e,s){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(s),()=>{this.off(e,s)}}off(e,s){const n=this.listeners.get(e);n&&(n.delete(s),n.size===0&&this.listeners.delete(e))}clear(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){var s,n;return(n=(s=this.listeners.get(e))==null?void 0:s.size)!=null?n:0}}const te=new Pe,le=(t,e,s)=>ae.registerComponent(t,e,s),ue=t=>R(null,null,function*(){yield Promise.all(t.map(({name:e,path:s,useShadowDOM:n})=>ae.registerComponent(e,s,n)))}),de=(t,e)=>te.listen(t,e),fe=(t,e)=>{te.emit(t,e)},We=(t,e)=>{if(e){const s=e.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(s,{shadowRoot:t,element:e})}},Z=()=>{const t=window.__ladrilloContexts;if(t&&t.size>0){const e=Array.from(t.values());return e[e.length-1]}return null},pe=()=>{const t=Z();return t&&t.element?t.element.state||{}:{}},X=t=>{const e=Z();e&&e.setState&&e.setState(t)},he=(t,e)=>(X({[t]:e}),s=>{X({[t]:s})}),me=(t,e)=>{if(e)return e.querySelector(t);const s=Z();if(s){const n=s.shadowRoot||s.element;if(n){const o=n.querySelector(t);if(o)return o}}return document.querySelector(t)},be=(t,e)=>{if(e)return e.querySelectorAll(t);const s=Z();if(s){const n=s.shadowRoot||s.element;if(n){const o=n.querySelectorAll(t);if(o.length>0)return o}}return document.querySelectorAll(t)};typeof window!="undefined"&&(window.ladrillosjs={registerComponent:le,registerComponents:ue},window.$listen=de,window.$emit=fe,window.$querySelector=me,window.$querySelectorAll=be,window.$reactive=he,window.$setState=X,window.$getState=pe);const He=(t,e,s)=>{if(!e)return;const n=document.createElement("style");n.textContent=e,s?t.appendChild(n):document.head.appendChild(n)},ze=(t,e)=>{t.innerHTML=e;const s=Ie(t),n=De(t),o=Ue(t),r=Xe(t);return{bindings:s,twoWayBindings:n,conditionals:o,loops:r}},ge=t=>{const e=[],s=t.match(/\((.*)\)/);if(!s)return e;const n=s[1].trim();return n&&n.split(",").map(r=>r.trim()).forEach(r=>{if(/^['"]/.test(r)||/^\d+/.test(r))return;const i=r.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);i&&e.push(i[1])}),e},Ie=t=>{const e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null),s=[];let n;const o=i=>{let c=i.parentElement;for(;c;){if(c.hasAttribute&&c.hasAttribute("$for"))return!0;c=c.parentElement}return!1};for(;n=e.nextNode();){if(o(n))continue;const i=[...n.textContent.matchAll(V.bindings)];if(i.length>0){const c=n.textContent,f=i.map(l=>{const a=l[1].trim(),u=a.includes("(")&&a.includes(")"),d=/[+*/%<>=!&|]/.test(a)||/\s-\s/.test(a),h=/^(!|typeof\s|void\s|delete\s)/.test(a),E=d||h||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(a)||/\bnew\s+/.test(a)||/\b(typeof|instanceof|void|delete)\b/.test(a),b=u?[a.split("(")[0].trim()]:a.split(".").map(F=>F.trim()),g=u?ge(a):[];return{raw:a,path:b,isFunction:u,isExpression:E,functionArgs:g}});s.push({node:n,bindings:f,original:c})}}return t.querySelectorAll("*").forEach(i=>{if(!(i.hasAttribute("$for")||o(i)))for(const c of i.attributes){if(c.name==="$if"||c.name==="$else-if"||c.name==="$else"||c.name==="$bind")continue;const f=[...c.value.matchAll(V.bindings)];if(f.length>0){const l=c.value,a=f.map(u=>{const d=u[1].trim(),h=d.includes("(")&&d.includes(")"),E=/[+*/%<>=!&|]/.test(d)||/\s-\s/.test(d),b=/^(!|typeof\s|void\s|delete\s)/.test(d),g=E||b||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(d)||/\bnew\s+/.test(d)||/\b(typeof|instanceof|void|delete)\b/.test(d),F=h?[d.split("(")[0].trim()]:d.split(".").map(oe=>oe.trim()),j=h?ge(d):[];return{raw:d,path:F,isFunction:h,isExpression:g,functionArgs:j}});s.push({node:i,bindings:a,original:l,isAttribute:!0,attributeName:c.name})}}}),s},De=t=>{const e=[];return t.querySelectorAll("[\\$bind]").forEach(n=>{var c;const o=n.getAttribute("$bind");if(!o)return;const r=o.trim(),i=r.split(".").map(f=>f.trim());n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement||n instanceof HTMLSelectElement?(e.push({element:n,path:i,raw:r,isContentEditable:!1,initialValue:n.value||""}),n.removeAttribute("$bind")):n instanceof HTMLElement&&n.hasAttribute("contenteditable")&&(e.push({element:n,path:i,raw:r,isContentEditable:!0,initialValue:((c=n.textContent)==null?void 0:c.trim())||""}),n.removeAttribute("$bind"))}),e},Ue=t=>{const e=[],s=new Set;return t.querySelectorAll("[\\$if]").forEach(o=>{if(s.has(o))return;const r=[];let i=o;for(;i;){const c=i.hasAttribute("$if"),f=i.hasAttribute("$else-if"),l=i.hasAttribute("$else");if(!c&&!f&&!l)break;s.add(i);let a,u="";c?(a="if",u=i.getAttribute("$if")||"",i.removeAttribute("$if")):f?(a="else-if",u=i.getAttribute("$else-if")||"",i.removeAttribute("$else-if")):(a="else",i.removeAttribute("$else"));const d=document.createComment(`conditional:${a}:${u}`),h=i.parentElement||t,E=i.nextSibling;h.insertBefore(d,i);const b={element:i,condition:u.trim(),type:a,placeholder:d,group:[],originalParent:h,nextSibling:E};r.push(b);const g=i.nextElementSibling;if(i.remove(),i=g,g&&!g.hasAttribute("$else-if")&&!g.hasAttribute("$else"))break}r.forEach(c=>{c.group=r}),e.push(r)}),e},Ze=t=>{const e=new Set;return t.forEach(s=>{s.forEach(n=>{let o=n.condition;o=o.replace(/\{([^}]+)\}/g,"$1");const r=/\b([a-zA-Z_$][a-zA-Z0-9_$]*(?:\.[a-zA-Z_$][a-zA-Z0-9_$]*)*)\b/g,i=new Set(["true","false","null","undefined","typeof","instanceof","new","return","if","else","for","while","do","switch","case","break","continue"]);let c;for(;(c=r.exec(o))!==null;){const l=c[1].split(".")[0];i.has(l)||e.add(l)}})}),e},Xe=t=>{const e=[];return t.querySelectorAll("[\\$for]").forEach(n=>{var h;const o=n.getAttribute("$for");if(!o)return;const r=n.getAttribute("$key")||void 0,i=o.match(/^\s*(?:\(([^,]+),\s*([^)]+)\)|([^\s]+))\s+(?:in|of)\s+(.+)\s*$/);if(!i){console.error(`Invalid $for expression: "${o}"`);return}const c=(i[1]||i[3]).trim(),f=(h=i[2])==null?void 0:h.trim(),l=i[4].trim(),a=document.createComment(`loop:${o}`),u=n.parentElement||t;u.insertBefore(a,n),n.removeAttribute("$for"),r&&n.removeAttribute("$key"),n.remove();const d={template:n,expression:o,itemName:c,indexName:f,arrayName:l,keyAttribute:r,placeholder:a,renderedElements:[],originalParent:u};e.push(d)}),e},Je=t=>{const e=new Set;return t.forEach(s=>{const n=s.arrayName.split(".")[0];e.add(n)}),e},P=new Map,Ke=100,ne=t=>{const e=P.get(t);if(e)return P.delete(t),P.set(t,e),e;const s=new Function("component",`
12
+ `).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):n.includes("import")||n.includes("export")?(d.warn("CSS file returned JavaScript module format. CSS may not load correctly."),""):n},Ge=n=>L(null,null,function*(){let e="";const t=n.querySelectorAll("style, link[rel='stylesheet']");for(const s of t){if(s.tagName==="LINK"){const r=yield De(s.href),i=Ke(r);i&&(e+=`
13
+ `+i)}else if(s.tagName==="STYLE"){const o=s;if(o.textContent){let r=o.textContent.trim();r=r.replace(G.comments.css,"").trim(),e+=`
14
+ `+r}}s.remove()}return e.trim()});class Ye{constructor(){M(this,X);this.components={},this.lazyComponents=new Set,this.intersectionObserver=null}registerComponent(e,t,s=!0,o=!1){return L(this,null,function*(){if(this.components[e]){d.warn(`Component with name "${e}" is already registered.`);return}if(o){this.lazyComponents.add(e),D(this,X,Pe).call(this,e,t,s),d.log(`Component ${e} registered as lazy-loaded`);return}try{const r=yield pe(t),i=yield he(r,e);this.components[e]={tagName:e,template:i.template,scripts:i.scripts,externalScripts:i.externalScripts,styles:i.styles,sourcePath:t,lazy:!1},d.log(`Component ${e} registered successfully`),yield D(this,X,Be).call(this,e,s)}catch(r){F(e,t,r);return}})}}X=new WeakSet,Pe=function(e,t,s){const o=this;class r extends HTMLElement{constructor(){super(),this.loaded=!1,this.observer=null,s&&(this.attachShadow({mode:"open"}),this.shadowRoot&&(this.shadowRoot.innerHTML=`
15
+ <style>
16
+ :host { display: block; min-height: 1px; }
17
+ </style>
18
+ `))}connectedCallback(){if(!this.loaded){if(this.hasAttribute("eager")){this.loaded=!0,this.loadComponent();return}this.observer=new IntersectionObserver(c=>{c.forEach(p=>{p.isIntersecting&&!this.loaded&&(this.loaded=!0,this.loadComponent())})},{rootMargin:"50px"}),this.observer.observe(this)}}disconnectedCallback(){this.observer&&(this.observer.disconnect(),this.observer=null)}loadComponent(){return L(this,null,function*(){try{d.log(`Lazy loading component: ${e}`);const c=this,p=this.parentNode,l=this.nextSibling;if(!p){fe(`Placeholder for ${e} has no parent node`,{componentName:e,componentPath:t});return}const u=yield pe(t),a=yield he(u,e);d.log(`Component ${e} parsed successfully`),o.components[e]={tagName:e,template:a.template,scripts:a.scripts,externalScripts:a.externalScripts,styles:a.styles,sourcePath:t,lazy:!0};const f=`${e}-real`;d.log(`Defining real component with temp name: ${f}`);const h=o.components[e].tagName;o.components[e].tagName=f;const{defineWebComponent:E}=yield Promise.resolve().then(()=>Me);E(o.components[e],s),d.log(`Real component ${f} defined`),o.components[e].tagName=h;const g=document.createElement(f);for(d.log(`Created real component instance: ${f}`),Array.from(c.attributes).forEach(w=>{g.setAttribute(w.name,w.value)});c.firstChild;)g.appendChild(c.firstChild);l?(p.insertBefore(g,l),d.log("Inserted real component before next sibling")):(p.appendChild(g),d.log("Appended real component to parent")),p.removeChild(c),d.log("Removed placeholder element"),o.lazyComponents.delete(e),d.log(`Component ${e} lazy-loaded successfully`)}catch(c){F(e,t,c)}})}}customElements.get(e)||customElements.define(e,r)},Be=function(e,t){return L(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>Me);this.components[e]&&s(this.components[e],t)})};const me=new Ye;class Qe{constructor(){this.listeners=new Map}emit(e,t){const s=new CustomEvent(e,{detail:t,bubbles:!0,composed:!0});document.dispatchEvent(s);const o=this.listeners.get(e);if(!o||o.size===0)return Promise.resolve();const r=[];return o.forEach(i=>{try{const c=i(t);c instanceof Promise&&r.push(c)}catch(c){d.error(`⚠️ Event Bus Error: Failed to execute listener for "${e}"`),d.error(` Error details: ${c.message}`),r.push(Promise.reject(c))}}),r.length>0?Promise.all(r).then(()=>{}):Promise.resolve()}listen(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.off(e,t)}}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}clear(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){var t,s;return(s=(t=this.listeners.get(e))==null?void 0:t.size)!=null?s:0}}const re=new Qe,ge=(n,e,t,s)=>me.registerComponent(n,e,t,s),be=n=>L(null,null,function*(){yield Promise.all(n.map(({name:e,path:t,useShadowDOM:s,lazy:o})=>me.registerComponent(e,t,s,o)))}),we=(n,e)=>re.listen(n,e),ye=(n,e)=>{re.emit(n,e)},et=(n,e)=>{if(e){const t=e.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(t,{shadowRoot:n,element:e})}},Y=()=>{const n=window.__ladrilloContexts;if(n&&n.size>0){const e=Array.from(n.values());return e[e.length-1]}return null},$e=()=>{const n=Y();return n&&n.element?n.element.state||{}:{}},Q=n=>{const e=Y();e&&e.setState&&e.setState(n)},Ee=(n,e)=>(Q({[n]:e}),t=>{Q({[n]:t})}),ve=(n,e)=>{if(e)return e.querySelector(n);const t=Y();if(t){const s=t.shadowRoot||t.element;if(s){const o=s.querySelector(n);if(o)return o}}return document.querySelector(n)},Se=(n,e)=>{if(e)return e.querySelectorAll(n);const t=Y();if(t){const s=t.shadowRoot||t.element;if(s){const o=s.querySelectorAll(n);if(o.length>0)return o}}return document.querySelectorAll(n)};typeof window!="undefined"&&(window.ladrillosjs={registerComponent:ge,registerComponents:be},window.$listen=we,window.$emit=ye,window.$querySelector=ve,window.$querySelectorAll=Se,window.$reactive=Ee,window.$setState=Q,window.$getState=$e);const tt=(n,e,t)=>{if(!e)return;const s=document.createElement("style");s.textContent=e,t?n.appendChild(s):document.head.appendChild(s)},nt=(n,e)=>{n.innerHTML=e;const t=st(n),s=ot(n),o=rt(n),r=ct(n);return{bindings:t,twoWayBindings:s,conditionals:o,loops:r}},Ce=n=>{const e=[],t=n.match(/\((.*)\)/);if(!t)return e;const s=t[1].trim();return s&&s.split(",").map(r=>r.trim()).forEach(r=>{if(/^['"]/.test(r)||/^\d+/.test(r))return;const i=r.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);i&&e.push(i[1])}),e},st=n=>{const e=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null),t=[];let s;const o=i=>{let c=i.parentElement;for(;c;){if(c.hasAttribute&&c.hasAttribute("$for"))return!0;c=c.parentElement}return!1};for(;s=e.nextNode();){if(o(s))continue;const i=[...s.textContent.matchAll(G.bindings)];if(i.length>0){const c=s.textContent,p=i.map(l=>{const u=l[1].trim(),a=u.includes("(")&&u.includes(")"),f=/[+*/%<>=!&|]/.test(u)||/\s-\s/.test(u),h=/^(!|typeof\s|void\s|delete\s)/.test(u),E=f||h||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(u)||/\bnew\s+/.test(u)||/\b(typeof|instanceof|void|delete)\b/.test(u),g=a?[u.split("(")[0].trim()]:u.split(".").map(P=>P.trim()),w=a?Ce(u):[];return{raw:u,path:g,isFunction:a,isExpression:E,functionArgs:w}});t.push({node:s,bindings:p,original:c})}}return n.querySelectorAll("*").forEach(i=>{if(!(i.hasAttribute("$for")||o(i)))for(const c of i.attributes){if(c.name==="$if"||c.name==="$else-if"||c.name==="$else"||c.name==="$bind")continue;const p=[...c.value.matchAll(G.bindings)];if(p.length>0){const l=c.value,u=p.map(a=>{const f=a[1].trim(),h=f.includes("(")&&f.includes(")"),E=/[+*/%<>=!&|]/.test(f)||/\s-\s/.test(f),g=/^(!|typeof\s|void\s|delete\s)/.test(f),w=E||g||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(f)||/\bnew\s+/.test(f)||/\b(typeof|instanceof|void|delete)\b/.test(f),P=h?[f.split("(")[0].trim()]:f.split(".").map(ae=>ae.trim()),z=h?Ce(f):[];return{raw:f,path:P,isFunction:h,isExpression:w,functionArgs:z}});t.push({node:i,bindings:u,original:l,isAttribute:!0,attributeName:c.name})}}}),t},ot=n=>{const e=[];return n.querySelectorAll("[\\$bind]").forEach(s=>{var c;const o=s.getAttribute("$bind");if(!o)return;const r=o.trim(),i=r.split(".").map(p=>p.trim());s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement?(e.push({element:s,path:i,raw:r,isContentEditable:!1,initialValue:s.value||""}),s.removeAttribute("$bind")):s instanceof HTMLElement&&s.hasAttribute("contenteditable")&&(e.push({element:s,path:i,raw:r,isContentEditable:!0,initialValue:((c=s.textContent)==null?void 0:c.trim())||""}),s.removeAttribute("$bind"))}),e},rt=n=>{const e=[],t=new Set;return n.querySelectorAll("[\\$if]").forEach(o=>{if(t.has(o))return;const r=[];let i=o;for(;i;){const c=i.hasAttribute("$if"),p=i.hasAttribute("$else-if"),l=i.hasAttribute("$else");if(!c&&!p&&!l)break;t.add(i);let u,a="";c?(u="if",a=i.getAttribute("$if")||"",i.removeAttribute("$if")):p?(u="else-if",a=i.getAttribute("$else-if")||"",i.removeAttribute("$else-if")):(u="else",i.removeAttribute("$else"));const f=document.createComment(`conditional:${u}:${a}`),h=i.parentElement||n,E=i.nextSibling;h.insertBefore(f,i);const g={element:i,condition:a.trim(),type:u,placeholder:f,group:[],originalParent:h,nextSibling:E};r.push(g);const w=i.nextElementSibling;if(i.remove(),i=w,w&&!w.hasAttribute("$else-if")&&!w.hasAttribute("$else"))break}r.forEach(c=>{c.group=r}),e.push(r)}),e},it=n=>{const e=new Set;return n.forEach(t=>{t.forEach(s=>{let o=s.condition;o=o.replace(/\{([^}]+)\}/g,"$1");const r=/\b([a-zA-Z_$][a-zA-Z0-9_$]*(?:\.[a-zA-Z_$][a-zA-Z0-9_$]*)*)\b/g,i=new Set(["true","false","null","undefined","typeof","instanceof","new","return","if","else","for","while","do","switch","case","break","continue"]);let c;for(;(c=r.exec(o))!==null;){const l=c[1].split(".")[0];i.has(l)||e.add(l)}})}),e},ct=n=>{const e=[];return n.querySelectorAll("[\\$for]").forEach(s=>{var h;const o=s.getAttribute("$for");if(!o)return;const r=s.getAttribute("$key")||void 0,i=o.match(/^\s*(?:\(([^,]+),\s*([^)]+)\)|([^\s]+))\s+(?:in|of)\s+(.+)\s*$/);if(!i){fe(`Invalid $for expression: "${o}"`,{expression:o,lineHint:"$for attribute parsing"});return}const c=(i[1]||i[3]).trim(),p=(h=i[2])==null?void 0:h.trim(),l=i[4].trim(),u=document.createComment(`loop:${o}`),a=s.parentElement||n;a.insertBefore(u,s),s.removeAttribute("$for"),r&&s.removeAttribute("$key"),s.remove();const f={template:s,expression:o,itemName:c,indexName:p,arrayName:l,keyAttribute:r,placeholder:u,renderedElements:[],originalParent:a};e.push(f)}),e},at=n=>{const e=new Set;return n.forEach(t=>{const s=t.arrayName.split(".")[0];e.add(s)}),e},q=new Map,lt=100,ie=n=>{const e=q.get(n);if(e)return q.delete(n),q.set(n,e),e;const t=new Function("component",`
8
19
  const { Date, Array, Math, String, Number, Boolean, Object, JSON, RegExp } = globalThis;
9
20
  with(component) {
10
- return ${t};
21
+ return ${n};
11
22
  }
12
- `);if(P.size>=Ke){const n=P.keys().next().value;n&&P.delete(n)}return P.set(t,s),s},J=(t,e)=>e.reduce((s,n)=>{if(!(s==null||typeof s!="object"))return s[n]},t),se=(t,e,s)=>{if(e.length===0)return;const n=e[e.length-1],o=e.slice(0,-1);let r=t;for(const i of o)(r[i]===void 0||r[i]===null)&&(r[i]={}),r=r[i];r[n]=s},we=(t,e,s)=>{for(const n of t){let o=n.original,r,i=!1;for(const{raw:c,path:f,isFunction:l,isExpression:a}of n.bindings){let u,d=!1;if(a||l)try{u=ne(c)(s||e)}catch(E){console.error(`Error executing expression binding {${c}}:`,E),u=void 0,d=!0}else u=J(e,f),u===void 0&&(d=!0);if(d){i=!0;continue}const h=String(u!=null?u:"");r=u,o=o.replace(`{${c}}`,h)}if(i&&n.original,n.node.nodeType===Node.TEXT_NODE){const c=n.node,f=c.parentElement,l=o.trim().startsWith("<")&&o.includes(">");f&&l?f.innerHTML=o:c.textContent=o}else{const c=n.node;n.isAttribute&&n.attributeName&&(["disabled","checked","readonly","required","selected","hidden","open","autofocus","autoplay","controls","loop","muted"].includes(n.attributeName.toLowerCase())?(typeof r=="boolean"?r:r==="true"||r==="True")?c.setAttribute(n.attributeName,""):c.removeAttribute(n.attributeName):c.setAttribute(n.attributeName,o))}}},Ge=(t,e,s)=>{if(!t)return!0;let n=t.trim();n=n.replace(/\{([^}]+)\}/g,"$1");try{return new Function("context","component",`
23
+ `);if(q.size>=lt){const s=q.keys().next().value;s&&q.delete(s)}return q.set(n,t),t},ee=(n,e)=>e.reduce((t,s)=>{if(!(t==null||typeof t!="object"))return t[s]},n),ce=(n,e,t)=>{if(e.length===0)return;const s=e[e.length-1],o=e.slice(0,-1);let r=n;for(const i of o)(r[i]===void 0||r[i]===null)&&(r[i]={}),r=r[i];r[s]=t},Ae=(n,e,t)=>{for(const s of n){let o=s.original,r,i=!1;for(const{raw:c,path:p,isFunction:l,isExpression:u}of s.bindings){let a,f=!1;if(u||l)try{a=ie(c)(t||e)}catch(E){U(c,E,R(t)),a=void 0,f=!0}else a=ee(e,p),a===void 0&&(f=!0);if(f){i=!0;continue}const h=String(a!=null?a:"");r=a,o=o.replace(`{${c}}`,h)}if(i&&s.original,s.node.nodeType===Node.TEXT_NODE){const c=s.node,p=c.parentElement,l=o.trim().startsWith("<")&&o.includes(">");p&&l?p.innerHTML=o:c.textContent=o}else{const c=s.node;s.isAttribute&&s.attributeName&&(["disabled","checked","readonly","required","selected","hidden","open","autofocus","autoplay","controls","loop","muted"].includes(s.attributeName.toLowerCase())?(typeof r=="boolean"?r:r==="true"||r==="True")?c.setAttribute(s.attributeName,""):c.removeAttribute(s.attributeName):c.setAttribute(s.attributeName,o))}}},ut=(n,e,t)=>{if(!n)return!0;let s=n.trim();s=s.replace(/\{([^}]+)\}/g,"$1");try{return new Function("context","component",`
13
24
  with (context) {
14
25
  try {
15
- return Boolean(${n});
26
+ return Boolean(${s});
16
27
  } catch (e) {
17
28
  return false;
18
29
  }
19
30
  }
20
- `)(e,s)}catch(o){return console.error(`Error evaluating condition "${t}":`,o),!1}},ye=(t,e)=>{const s=["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","keydown","keyup","keypress","focus","blur","change","input","submit","reset","scroll","resize","load","unload","touchstart","touchend","touchmove","touchcancel","dragstart","drag","dragend","dragenter","dragover","dragleave","drop"];[t,...t.querySelectorAll("*")].forEach(o=>{s.forEach(r=>{const i=`on${r}`,c=o.getAttribute(i);if(c){const f=`__processed_${i}`;if(o[f])return;o.removeAttribute(i),o.addEventListener(r,function(l){try{new Function("event","component",`
31
+ `)(e,t)}catch(o){return oe(n,o,R(t)),!1}},xe=(n,e)=>{const t=["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","keydown","keyup","keypress","focus","blur","change","input","submit","reset","scroll","resize","load","unload","touchstart","touchend","touchmove","touchcancel","dragstart","drag","dragend","dragenter","dragover","dragleave","drop"];[n,...n.querySelectorAll("*")].forEach(o=>{t.forEach(r=>{const i=`on${r}`,c=o.getAttribute(i);if(c){const p=`__processed_${i}`;if(o[p])return;o.removeAttribute(i),o.addEventListener(r,function(l){try{new Function("event","component",`
21
32
  with(component) {
22
33
  ${c}
23
34
  }
24
- `).call(this,l,e)}catch(a){console.error(`Error executing ${r} handler:`,a,c)}}),o[f]=!0}})})},$e=(t,e,s)=>{var n;for(const o of t){let r=!1;for(const i of o){const{element:c,condition:f,type:l,placeholder:a,originalParent:u}=i;let d=!1;l==="else"?d=!r:r||(d=Ge(f,e,s),d&&(r=!0));const h=c.parentNode!==null;d&&!h?((n=a.parentNode)==null||n.insertBefore(c,a.nextSibling),s&&ye(c,s)):!d&&h&&c.remove()}}},Ee=(t,e,s)=>{for(const n of t){const{template:o,itemName:r,indexName:i,arrayName:c,placeholder:f,renderedElements:l}=n,a=J(e,c.split("."));if(a!==void 0&&!Array.isArray(a)){console.warn(`$for: "${c}" is not an array, got:`,a),l.forEach(u=>u.remove()),l.length=0;return}if(!a)return;l.forEach(u=>u.remove()),l.length=0,a.forEach((u,d)=>{var g;const h=o.cloneNode(!0),E=Te(H({},e),{[r]:u});i&&(E[i]=d),Ye(h,E,s);const b=l.length>0?l[l.length-1]:f;(g=b.parentNode)==null||g.insertBefore(h,b.nextSibling),l.push(h),s&&ye(h,s)})}},Ye=(t,e,s)=>{const n=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null);let o;for(;o=n.nextNode();)if(o.textContent&&o.textContent.includes("{")){let i=o.textContent;[...o.textContent.matchAll(/\{([^}]+)\}/g)].forEach(f=>{const l=f[1].trim(),a=l.includes("(")&&l.includes(")"),d=/[+*/%<>=!&|]/.test(l)||/\s-\s/.test(l)||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(l)||/\bnew\s+/.test(l)||/\b(typeof|instanceof|void|delete)\b/.test(l);let h;if(d||a)try{const E=ne(l),b=typeof e=="object"&&e!==null?H(H({},e),s||{}):s||{};h=E(b)}catch(E){console.error(`Error executing expression in loop {${l}}:`,E),h=void 0}else{const E=l.split(".").map(b=>b.trim());h=J(e,E)}h!==void 0&&(i=i.replace(`{${l}}`,String(h!=null?h:"")))}),o.textContent=i}[t,...t.querySelectorAll("*")].forEach(i=>{Array.from(i.attributes).forEach(c=>{if(c.value.includes("{")){let f=c.value;[...c.value.matchAll(/\{([^}]+)\}/g)].forEach(a=>{const u=a[1].trim(),d=u.includes("(")&&u.includes(")"),E=/[+*/%<>=!&|]/.test(u)||/\s-\s/.test(u)||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(u)||/\bnew\s+/.test(u)||/\b(typeof|instanceof|void|delete)\b/.test(u);let b;if(E||d)try{const g=ne(u),F=typeof e=="object"&&e!==null?H(H({},e),s||{}):s||{};b=g(F)}catch(g){console.error(`Error executing expression in loop attribute {${u}}:`,g),b=void 0}else{const g=u.split(".").map(F=>F.trim());b=J(e,g)}b!==void 0&&(f=f.replace(`{${u}}`,String(b!=null?b:"")))}),i.setAttribute(c.name,f)}})})},ve=t=>t instanceof ShadowRoot?t.host:t,Qe=(t,e)=>{const s=new Set;e.forEach(({path:o})=>{const r=o[0];s.add(r)});const n=[];return s.forEach(o=>{n.push(`
35
+ `).call(this,l,e)}catch(u){se(r,c,u,R(e,{elementTag:o.tagName.toLowerCase()}))}}),o[p]=!0}})})},_e=(n,e,t)=>{var s;for(const o of n){let r=!1;for(const i of o){const{element:c,condition:p,type:l,placeholder:u,originalParent:a}=i;let f=!1;l==="else"?f=!r:r||(f=ut(p,e,t),f&&(r=!0));const h=c.parentNode!==null;f&&!h?((s=u.parentNode)==null||s.insertBefore(c,u.nextSibling),t&&xe(c,t)):!f&&h&&c.remove()}}},ke=(n,e,t)=>{for(const s of n){const{template:o,itemName:r,indexName:i,arrayName:c,placeholder:p,renderedElements:l}=s,u=ee(e,c.split("."));if(u!==void 0&&!Array.isArray(u)){K(`${r} in ${c}`,new Error(`"${c}" is not an array, got: ${typeof u}`),R(t,{lineHint:"$for loop in template"})),l.forEach(a=>a.remove()),l.length=0;return}if(!u)return;l.forEach(a=>a.remove()),l.length=0,u.forEach((a,f)=>{var w;const h=o.cloneNode(!0),E=j(T({},e),{[r]:a});i&&(E[i]=f),dt(h,E,t);const g=l.length>0?l[l.length-1]:p;(w=g.parentNode)==null||w.insertBefore(h,g.nextSibling),l.push(h),t&&xe(h,t)})}},dt=(n,e,t)=>{const s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let o;for(;o=s.nextNode();)if(o.textContent&&o.textContent.includes("{")){let i=o.textContent;[...o.textContent.matchAll(/\{([^}]+)\}/g)].forEach(p=>{const l=p[1].trim(),u=l.includes("(")&&l.includes(")"),f=/[+*/%<>=!&|]/.test(l)||/\s-\s/.test(l)||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(l)||/\bnew\s+/.test(l)||/\b(typeof|instanceof|void|delete)\b/.test(l);let h;if(f||u)try{const E=ie(l),g=typeof e=="object"&&e!==null?T(T({},e),t||{}):t||{};h=E(g)}catch(E){U(l,E,R(t,{lineHint:"$for loop template binding"})),h=void 0}else{const E=l.split(".").map(g=>g.trim());h=ee(e,E)}h!==void 0&&(i=i.replace(`{${l}}`,String(h!=null?h:"")))}),o.textContent=i}[n,...n.querySelectorAll("*")].forEach(i=>{Array.from(i.attributes).forEach(c=>{if(c.value.includes("{")){let p=c.value;[...c.value.matchAll(/\{([^}]+)\}/g)].forEach(u=>{const a=u[1].trim(),f=a.includes("(")&&a.includes(")"),E=/[+*/%<>=!&|]/.test(a)||/\s-\s/.test(a)||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(a)||/\bnew\s+/.test(a)||/\b(typeof|instanceof|void|delete)\b/.test(a);let g;if(E||f)try{const w=ie(a),P=typeof e=="object"&&e!==null?T(T({},e),t||{}):t||{};g=w(P)}catch(w){U(a,w,R(t,{attributeName:c.name,lineHint:"$for loop attribute binding"})),g=void 0}else{const w=a.split(".").map(P=>P.trim());g=ee(e,w)}g!==void 0&&(p=p.replace(`{${a}}`,String(g!=null?g:"")))}),i.setAttribute(c.name,p)}})})},Te=n=>n instanceof ShadowRoot?n.host:n,ft=(n,e)=>{const t=new Set;e.forEach(({path:o})=>{const r=o[0];t.add(r)});const s=[];return t.forEach(o=>{s.push(`
25
36
  if (!Object.getOwnPropertyDescriptor(component, '${o}')) {
26
37
  Object.defineProperty(component, '${o}', {
27
38
  get() { return this.state.${o}; },
@@ -30,10 +41,10 @@
30
41
  configurable: true
31
42
  });
32
43
  }
33
- `)}),{injectedCode:"",componentInjections:n.join(`
34
- `),bindVarNames:s}},et=(t,e,s=new Set)=>{const n=[],o=new Map,r=new Set;e.forEach(f=>{f.bindings.forEach(l=>{const a=l.path[0];r.add(a),l.isFunction&&l.functionArgs&&l.functionArgs.forEach(u=>{r.add(u)})})}),s.forEach(f=>{r.add(f)});const i=/(?:const|let|var)\s+(\w+)\s*=\s*([^;]+);?/g;let c;for(;(c=i.exec(t))!==null;){const f=c[1],l=c[2].trim();r.has(f)&&(n.push(`component.state.${f} = ${f};`),o.set(f,l))}return{stateBindings:n,boundVarNames:r,defaultValues:o}},tt=(t,e)=>{if(e.size===0)return t;let s=t;return e.forEach(n=>{const o=new RegExp(`\\b${n}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");s=s.replace(o,`component.state.${n}$1 $2`);const r=new RegExp(`(?<!component\\.state\\.)\\b${n}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");s=s.replace(r,`component.state.${n}$1`);const i=new RegExp(`\\b${n}\\.(\\w+(?:\\.\\w+)*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");s=s.replace(i,`component.state.${n}.$1 $2`);const c=new RegExp(`(?<!component\\.state\\.)(?<!const\\s${n}\\s*=\\s*{[^}]*)\\b${n}\\.(\\w+(?:\\.\\w+)*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");s=s.replace(c,`component.state.${n}.$1`);const f=new RegExp(`(?<!\\.)\\b(\\+\\+|\\-\\-)${n}\\b|\\b${n}(\\+\\+|\\-\\-)`,"g");s=s.replace(f,u=>{if(u.startsWith("++")||u.startsWith("--"))return`${u.substring(0,2)}component.state.${n}`;{const d=u.substring(u.length-2);return`component.state.${n}${d}`}});const l=new RegExp(`(?<!\\.)\\b${n}\\s*(\\+=|\\-=|\\*=|\\/=|%=|\\*\\*=|<<=|>>=|>>>=|&=|\\|=|\\^=)`,"g");s=s.replace(l,`component.state.${n}$1`);const a=new RegExp(`(?<!const\\s)(?<!let\\s)(?<!var\\s)(?<!\\.)\\b${n}\\s*=\\s*([^=])`,"g");s=s.replace(a,`component.state.${n} = $1`)}),s},xe=(t,e,s,n,o,r=new Set)=>{try{const{injectedCode:i,componentInjections:c,bindVarNames:f}=Qe(t,s),l=/function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[\w\s]*)\s*=>/g,a=[];let u;for(;(u=l.exec(t))!==null;){const k=u[1]||u[2];k&&a.push(k)}const d=a.map(k=>`component.${k} = typeof ${k} !== 'undefined' ? ${k}.bind(component) : undefined;`).join(`
35
- `),{stateBindings:h,boundVarNames:E,defaultValues:b}=et(t,e,r),g=new Set([...E,...f]),F=h.join(`
36
- `),j=tt(t,g),oe=`
44
+ `)}),{injectedCode:"",componentInjections:s.join(`
45
+ `),bindVarNames:t}},pt=(n,e,t=new Set)=>{const s=[],o=new Map,r=new Set;e.forEach(p=>{p.bindings.forEach(l=>{const u=l.path[0];r.add(u),l.isFunction&&l.functionArgs&&l.functionArgs.forEach(a=>{r.add(a)})})}),t.forEach(p=>{r.add(p)});const i=/(?:const|let|var)\s+(\w+)\s*=\s*([^;]+);?/g;let c;for(;(c=i.exec(n))!==null;){const p=c[1],l=c[2].trim();r.has(p)&&(s.push(`component.state.${p} = ${p};`),o.set(p,l))}return{stateBindings:s,boundVarNames:r,defaultValues:o}},ht=(n,e)=>{if(e.size===0)return n;let t=n;return e.forEach(s=>{const o=new RegExp(`\\b${s}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(o,`component.state.${s}$1 $2`);const r=new RegExp(`(?<!component\\.state\\.)\\b${s}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(r,`component.state.${s}$1`);const i=new RegExp(`\\b${s}\\.(\\w+(?:\\.\\w+)*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(i,`component.state.${s}.$1 $2`);const c=new RegExp(`(?<!component\\.state\\.)(?<!const\\s${s}\\s*=\\s*{[^}]*)\\b${s}\\.(\\w+(?:\\.\\w+)*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(c,`component.state.${s}.$1`);const p=new RegExp(`(?<!\\.)\\b(\\+\\+|\\-\\-)${s}\\b|\\b${s}(\\+\\+|\\-\\-)`,"g");t=t.replace(p,a=>{if(a.startsWith("++")||a.startsWith("--"))return`${a.substring(0,2)}component.state.${s}`;{const f=a.substring(a.length-2);return`component.state.${s}${f}`}});const l=new RegExp(`(?<!\\.)\\b${s}\\s*(\\+=|\\-=|\\*=|\\/=|%=|\\*\\*=|<<=|>>=|>>>=|&=|\\|=|\\^=)`,"g");t=t.replace(l,`component.state.${s}$1`);const u=new RegExp(`(?<!const\\s)(?<!let\\s)(?<!var\\s)(?<!\\.)\\b${s}\\s*=\\s*([^=])`,"g");t=t.replace(u,`component.state.${s} = $1`)}),t},Le=(n,e,t,s,o,r=new Set)=>{try{const{injectedCode:i,componentInjections:c,bindVarNames:p}=ft(n,t),l=/function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[\w\s]*)\s*=>/g,u=[];let a;for(;(a=l.exec(n))!==null;){const N=a[1]||a[2];N&&u.push(N)}const f=u.map(N=>`component.${N} = typeof ${N} !== 'undefined' ? ${N}.bind(component) : undefined;`).join(`
46
+ `),{stateBindings:h,boundVarNames:E,defaultValues:g}=pt(n,e,r),w=new Set([...E,...p]),P=h.join(`
47
+ `),z=ht(n,w),ae=`
37
48
  (function() {
38
49
  // Create component scope with direct access to state
39
50
  const component = this;
@@ -68,18 +79,18 @@
68
79
 
69
80
  // Execute script content within component scope so $bind variables are accessible
70
81
  with(component) {
71
- ${j}
82
+ ${z}
72
83
 
73
84
  // Auto-bind variables to component state (e.g., const name = "value" → this.state.name = "value")
74
- ${F}
85
+ ${P}
75
86
 
76
87
  // Auto-attach all detected functions to component for onclick access
77
- ${d}
88
+ ${f}
78
89
  }
79
90
  }).call(arguments[0], arguments[0], arguments[1], arguments[2])
80
- `;return new Function(oe)(o,n,te),b}catch(i){return console.error("Script execution failed:",i),new Map}},Se=(t,e)=>{["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","keydown","keyup","keypress","focus","blur","change","input","submit","reset","scroll","resize","load","unload","touchstart","touchend","touchmove","touchcancel","dragstart","drag","dragend","dragenter","dragover","dragleave","drop"].forEach(n=>{const o=`on${n}`;(t instanceof ShadowRoot?t.querySelectorAll(`[${o}]`):e.querySelectorAll(`[${o}]`)).forEach(i=>{const c=`${o}`;if(i[`__processed_${c}`])return;const f=i.getAttribute(o);f&&(i.removeAttribute(o),i.addEventListener(n,function(l){new Function("event","component",`
91
+ `;return new Function(ae)(o,s,re),g}catch(i){return ze(i,R(o)),new Map}},Ne=(n,e)=>{["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","keydown","keyup","keypress","focus","blur","change","input","submit","reset","scroll","resize","load","unload","touchstart","touchend","touchmove","touchcancel","dragstart","drag","dragend","dragenter","dragover","dragleave","drop"].forEach(s=>{const o=`on${s}`;(n instanceof ShadowRoot?n.querySelectorAll(`[${o}]`):e.querySelectorAll(`[${o}]`)).forEach(i=>{const c=`${o}`;if(i[`__processed_${c}`])return;const p=i.getAttribute(o);p&&(i.removeAttribute(o),i.addEventListener(s,function(l){new Function("event","component",`
81
92
  with(component) {
82
- ${f}
93
+ ${p}
83
94
  }
84
- `).call(this,l,e)}),i[`__processed_${c}`]=!0)})})},nt=(r,i,c,...f)=>R(null,[r,i,c,...f],function*(t,e,s,n=[],o=new Set){const l=new Map;if(!(e!=null&&e.length))return l;const a=ve(t);for(const u of e)u.content&&xe(u.content,s,n,t,a,o).forEach((h,E)=>{l.has(E)||l.set(E,h)});return Se(t,a),l}),st=(t,e)=>new Promise((s,n)=>{const o=document.querySelector(`script[src="${t}"]`);if(o){if(o.dataset.loaded==="true"){s();return}o.addEventListener("load",()=>s(),{once:!0}),o.addEventListener("error",()=>n(new Error(`Failed to load external script: ${t}`)),{once:!0});return}const r=document.createElement("script");r.src=t,e&&(r.type=e),r.onload=()=>{r.dataset.loaded="true",s()},r.onerror=()=>n(new Error(`Failed to load external script: ${t}`)),document.head.appendChild(r)}),ot=(i,c,f,...l)=>R(null,[i,c,f,...l],function*(t,e,s,n=[],o=new Set,r){var u;const a=ve(t);for(const d of e){let h;r?r.startsWith("http://")||r.startsWith("https://")?h=r:h=new URL(r,window.location.href).href:h=window.location.href;const E=new URL(d.src,h).href;if(d.external)yield st(E,d.type);else if(d.type==="module"){const b=a.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(b,{host:t,shadowRoot:t instanceof ShadowRoot?t:null,element:a,state:a.state,setState:(u=a.setState)==null?void 0:u.bind(a)});const g=document.createElement("script");g.type="module",g.src=E,g.setAttribute("data-component",b),document.head.appendChild(g)}else yield fetch(E).then(b=>{if(!b.ok)throw new Error(`HTTP ${b.status}: ${b.statusText}`);const g=b.headers.get("content-type");if(g&&!g.includes("javascript")&&!g.includes("text/plain"))throw new Error(`Expected JavaScript but got ${g}`);return b.text()}).then(b=>{xe(b,s,n,t,a,o)}).catch(b=>{console.error(`Failed to load external script: ${d.src}`,b)})}Se(t,a)}),rt=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(t,e)=>{var l,a,u,d,h,E,b,g,ce,j,Le,Re;const{tagName:s,template:n,scripts:o,externalScripts:r,styles:i,sourcePath:c}=t,k=class k extends HTMLElement{constructor(){super();L(this,g);L(this,l,[]);L(this,a,[]);L(this,u,[]);L(this,d,[]);L(this,h,[]);L(this,E,c);L(this,b,new WeakMap);e&&this.attachShadow({mode:"open"});const p={},v=()=>{we(C(this,l),this.state,this),$e(C(this,u),this.state,this),Ee(C(this,d),this.state,this),I(this,g,Re).call(this)};this.state=new Proxy(p,{get:(S,w)=>S[w],set:(S,w,x)=>{const _=S[w];return w in S&&Object.is(_,x)||(x!==null&&typeof x=="object"?S[w]=I(this,g,ce).call(this,x,v):S[w]=x,Object.getOwnPropertyDescriptor(this,w)||Object.defineProperty(this,w,{get(){return this.state[w]},set(W){this.state[w]=W},enumerable:!0,configurable:!0}),v()),!0}})}setState(p){Object.assign(this.state,p)}connectedCallback(){return R(this,null,function*(){const p=e?this.shadowRoot:this,{bindings:v,twoWayBindings:S,conditionals:w,loops:x}=ze(p,n);z(this,l,v),z(this,a,S),z(this,u,w),z(this,d,x);const _=Ze(w),N=Je(x);He(p,i,e),yield ot(p,r,C(this,l),C(this,a),new Set([..._,...N]),C(this,E)),(yield nt(p,o,C(this,l),C(this,a),new Set([..._,...N]))).forEach((A,q)=>{if(this.state[q]===void 0)try{const O=new Function(`return ${A}`);this.state[q]=O()}catch(O){this.state[q]=A}}),this._initializeStateFromAttributes(),this._setupTwoWayBindings(),we(C(this,l),this.state,this),$e(C(this,u),this.state,this),Ee(C(this,d),this.state,this),this._setupAttributeObserver()})}disconnectedCallback(){this.__attributeObserver&&(this.__attributeObserver.disconnect(),this.__attributeObserver=null),C(this,h).forEach(v=>{try{v()}catch(S){console.error("Error cleaning up two-way binding:",S)}}),z(this,h,[]);const p=this.__eventUnsubscribers;p&&Array.isArray(p)&&(p.forEach(v=>{try{v()}catch(S){console.error("Error unsubscribing from event:",S)}}),this.__eventUnsubscribers=[])}_setupAttributeObserver(){const p=new MutationObserver(v=>{v.forEach(S=>{if(S.type==="attributes"&&S.attributeName){const w=this.getAttribute(S.attributeName);this._handleAttributeChange(S.attributeName,w)}})});p.observe(this,{attributes:!0,attributeOldValue:!0}),this.__attributeObserver=p}_initializeStateFromAttributes(){this.getAttributeNames().forEach(p=>{const v=this.getAttribute(p);this._handleAttributeChange(p,v)})}_handleAttributeChange(p,v){var w;if(p){const x="this.state.";p.startsWith(x)&&(p=p.slice(x.length))}const S=I(w=k,j,Le).call(w,v);this.state[p]=S}_setupTwoWayBindings(){C(this,a).forEach(({element:p,path:v,raw:S,isContentEditable:w,initialValue:x})=>{var N,W;if(this._getNestedValue(v)===void 0){const A=x||"";se(this.state,v,A)}if(w){const A=p;A.textContent=(N=this._getNestedValue(v))!=null?N:"";const q=re=>{const B=re.target.textContent||"";se(this.state,v,B)};A.addEventListener("input",q);const O=()=>{A.removeEventListener("input",q)};C(this,h).push(O)}else{const A=p,q=A instanceof HTMLInputElement&&A.type==="checkbox";A instanceof HTMLInputElement&&A.type,q?A.checked=!!this._getNestedValue(v):A.value=(W=this._getNestedValue(v))!=null?W:"";const O=G=>{const B=G.target;let Y;B instanceof HTMLInputElement&&B.type==="checkbox"?Y=B.checked:(B instanceof HTMLInputElement&&B.type,Y=B.value),se(this.state,v,Y)};A.addEventListener("input",O);const re=()=>{A.removeEventListener("input",O)};if(C(this,h).push(re),A instanceof HTMLSelectElement||A instanceof HTMLInputElement&&["checkbox","radio","file"].includes(A.type)){A.addEventListener("change",O);const G=()=>{A.removeEventListener("change",O)};C(this,h).push(G)}}})}_getNestedValue(p){return p.reduce((v,S)=>v==null?void 0:v[S],this.state)}};l=new WeakMap,a=new WeakMap,u=new WeakMap,d=new WeakMap,h=new WeakMap,E=new WeakMap,b=new WeakMap,g=new WeakSet,ce=function(p,v){if(p===null||typeof p!="object"||p instanceof HTMLElement||p instanceof Node)return p;if(C(this,b).has(p))return C(this,b).get(p);const S=new Proxy(p,{get:(w,x)=>{const _=w[x];return Array.isArray(w)&&typeof _=="function"&&["push","pop","shift","unshift","splice","sort","reverse"].includes(x)?(...W)=>{const A=_.apply(w,W);return v(),A}:_!==null&&typeof _=="object"?I(this,g,ce).call(this,_,v):_},set:(w,x,_)=>{const N=w[x];return Object.is(N,_)||(w[x]=_,v()),!0}});return C(this,b).set(p,S),S},j=new WeakSet,Le=function(p){if(p===null||p==="")return null;if(p!=="undefined")try{return JSON.parse(p)}catch(v){return p}},Re=function(){C(this,a).forEach(({element:p,path:v,isContentEditable:S})=>{const w=this._getNestedValue(v);if(S){const x=p;x.textContent!==w&&(x.textContent=w!=null?w:"")}else{const x=p;if(x instanceof HTMLInputElement&&x.type==="checkbox"){const _=!!w;x.checked!==_&&(x.checked=_)}else x.value!==w&&(x.value=w!=null?w:"")}})},L(k,j);let f=k;customElements.define(s,f),$.log(`Web component defined: <${s}></${s}>`)}},Symbol.toStringTag,{value:"Module"}));m.$emit=fe,m.$getState=pe,m.$listen=de,m.$querySelector=me,m.$querySelectorAll=be,m.$reactive=he,m.$setState=X,m.__setComponentContext=We,m.registerComponent=le,m.registerComponents=ue,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
95
+ `).call(this,l,e)}),i[`__processed_${c}`]=!0)})})},mt=(r,i,c,...p)=>L(null,[r,i,c,...p],function*(n,e,t,s=[],o=new Set){const l=new Map;if(!(e!=null&&e.length))return l;const u=Te(n);for(const a of e)a.content&&Le(a.content,t,s,n,u,o).forEach((h,E)=>{l.has(E)||l.set(E,h)});return Ne(n,u),l}),gt=(n,e)=>new Promise((t,s)=>{const o=document.querySelector(`script[src="${n}"]`);if(o){if(o.dataset.loaded==="true"){t();return}o.addEventListener("load",()=>t(),{once:!0}),o.addEventListener("error",()=>s(new Error(`Failed to load external script: ${n}`)),{once:!0});return}const r=document.createElement("script");r.src=n,e&&(r.type=e),r.onload=()=>{r.dataset.loaded="true",t()},r.onerror=()=>s(new Error(`Failed to load external script: ${n}`)),document.head.appendChild(r)}),bt=(i,c,p,...l)=>L(null,[i,c,p,...l],function*(n,e,t,s=[],o=new Set,r){var a;const u=Te(n);for(const f of e){let h;r?r.startsWith("http://")||r.startsWith("https://")?h=r:h=new URL(r,window.location.href).href:h=window.location.href;const E=new URL(f.src,h).href;if(f.external)yield gt(E,f.type);else if(f.type==="module"){const g=u.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(g,{host:n,shadowRoot:n instanceof ShadowRoot?n:null,element:u,state:u.state,setState:(a=u.setState)==null?void 0:a.bind(u)});const w=document.createElement("script");w.type="module",w.src=E,w.setAttribute("data-component",g),document.head.appendChild(w)}else yield fetch(E).then(g=>{if(!g.ok)throw new Error(`HTTP ${g.status}: ${g.statusText}`);const w=g.headers.get("content-type");if(w&&!w.includes("javascript")&&!w.includes("text/plain"))throw new Error(`Expected JavaScript but got ${w}`);return g.text()}).then(g=>{Le(g,t,s,n,u,o)}).catch(g=>{console.error(`Failed to load external script: ${f.src}`,g)})}Ne(n,u)}),Me=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(n,e)=>{var l,u,a,f,h,E,g,w,de,z,Ve,Oe;const{tagName:t,template:s,scripts:o,externalScripts:r,styles:i,sourcePath:c}=n,N=class N extends HTMLElement{constructor(){super();M(this,w);M(this,l,[]);M(this,u,[]);M(this,a,[]);M(this,f,[]);M(this,h,[]);M(this,E,c);M(this,g,new WeakMap);e&&this.attachShadow({mode:"open"});const m={},v=()=>{Ae(x(this,l),this.state,this),_e(x(this,a),this.state,this),ke(x(this,f),this.state,this),D(this,w,Oe).call(this)};this.state=new Proxy(m,{get:(C,y)=>C[y],set:(C,y,S)=>{const _=C[y];return y in C&&Object.is(_,S)||(S!==null&&typeof S=="object"?C[y]=D(this,w,de).call(this,S,v):C[y]=S,Object.getOwnPropertyDescriptor(this,y)||Object.defineProperty(this,y,{get(){return this.state[y]},set(I){this.state[y]=I},enumerable:!0,configurable:!0}),v()),!0}})}setState(m){Object.assign(this.state,m)}connectedCallback(){return L(this,null,function*(){const m=e?this.shadowRoot:this,{bindings:v,twoWayBindings:C,conditionals:y,loops:S}=nt(m,s);J(this,l,v),J(this,u,C),J(this,a,y),J(this,f,S);const _=it(y),B=at(S);tt(m,i,e),yield bt(m,r,x(this,l),x(this,u),new Set([..._,...B]),x(this,E)),(yield mt(m,o,x(this,l),x(this,u),new Set([..._,...B]))).forEach((A,W)=>{if(this.state[W]===void 0)try{const V=new Function(`return ${A}`);this.state[W]=V()}catch(V){this.state[W]=A}}),this._initializeStateFromAttributes(),this._setupTwoWayBindings(),Ae(x(this,l),this.state,this),_e(x(this,a),this.state,this),ke(x(this,f),this.state,this),this._setupAttributeObserver()})}disconnectedCallback(){this.__attributeObserver&&(this.__attributeObserver.disconnect(),this.__attributeObserver=null),x(this,h).forEach(v=>{try{v()}catch(C){We("cleanup",C,R(this,{lineHint:"disconnectedCallback cleanup"}))}}),J(this,h,[]);const m=this.__eventUnsubscribers;m&&Array.isArray(m)&&(m.forEach(v=>{try{v()}catch(C){d.error("⚠️ Event Bus Error: Failed to unsubscribe from event",R(this)),d.error(` Error details: ${C.message}`)}}),this.__eventUnsubscribers=[])}_setupAttributeObserver(){const m=new MutationObserver(v=>{v.forEach(C=>{if(C.type==="attributes"&&C.attributeName){const y=this.getAttribute(C.attributeName);this._handleAttributeChange(C.attributeName,y)}})});m.observe(this,{attributes:!0,attributeOldValue:!0}),this.__attributeObserver=m}_initializeStateFromAttributes(){this.getAttributeNames().forEach(m=>{const v=this.getAttribute(m);this._handleAttributeChange(m,v)})}_handleAttributeChange(m,v){var y;if(m){const S="this.state.";m.startsWith(S)&&(m=m.slice(S.length))}const C=D(y=N,z,Ve).call(y,v);this.state[m]=C}_setupTwoWayBindings(){x(this,u).forEach(({element:m,path:v,raw:C,isContentEditable:y,initialValue:S})=>{var B,I;if(this._getNestedValue(v)===void 0){const A=S||"";ce(this.state,v,A)}if(y){const A=m;A.textContent=(B=this._getNestedValue(v))!=null?B:"";const W=le=>{const O=le.target.textContent||"";ce(this.state,v,O)};A.addEventListener("input",W);const V=()=>{A.removeEventListener("input",W)};x(this,h).push(V)}else{const A=m,W=A instanceof HTMLInputElement&&A.type==="checkbox";A instanceof HTMLInputElement&&A.type,W?A.checked=!!this._getNestedValue(v):A.value=(I=this._getNestedValue(v))!=null?I:"";const V=te=>{const O=te.target;let ne;O instanceof HTMLInputElement&&O.type==="checkbox"?ne=O.checked:(O instanceof HTMLInputElement&&O.type,ne=O.value),ce(this.state,v,ne)};A.addEventListener("input",V);const le=()=>{A.removeEventListener("input",V)};if(x(this,h).push(le),A instanceof HTMLSelectElement||A instanceof HTMLInputElement&&["checkbox","radio","file"].includes(A.type)){A.addEventListener("change",V);const te=()=>{A.removeEventListener("change",V)};x(this,h).push(te)}}})}_getNestedValue(m){return m.reduce((v,C)=>v==null?void 0:v[C],this.state)}};l=new WeakMap,u=new WeakMap,a=new WeakMap,f=new WeakMap,h=new WeakMap,E=new WeakMap,g=new WeakMap,w=new WeakSet,de=function(m,v){if(m===null||typeof m!="object"||m instanceof HTMLElement||m instanceof Node)return m;if(x(this,g).has(m))return x(this,g).get(m);const C=new Proxy(m,{get:(y,S)=>{const _=y[S];return Array.isArray(y)&&typeof _=="function"&&["push","pop","shift","unshift","splice","sort","reverse"].includes(S)?(...I)=>{const A=_.apply(y,I);return v(),A}:_!==null&&typeof _=="object"?D(this,w,de).call(this,_,v):_},set:(y,S,_)=>{const B=y[S];return Object.is(B,_)||(y[S]=_,v()),!0}});return x(this,g).set(m,C),C},z=new WeakSet,Ve=function(m){if(m===null||m==="")return null;if(m!=="undefined")try{return JSON.parse(m)}catch(v){return m}},Oe=function(){x(this,u).forEach(({element:m,path:v,isContentEditable:C})=>{const y=this._getNestedValue(v);if(C){const S=m;S.textContent!==y&&(S.textContent=y!=null?y:"")}else{const S=m;if(S instanceof HTMLInputElement&&S.type==="checkbox"){const _=!!y;S.checked!==_&&(S.checked=_)}else S.value!==y&&(S.value=y!=null?y:"")}})},M(N,z);let p=N;customElements.get(t)||(customElements.define(t,p),d.log(`Web component defined: <${t}></${t}>`))}},Symbol.toStringTag,{value:"Module"}));b.$emit=ye,b.$getState=$e,b.$listen=we,b.$querySelector=ve,b.$querySelectorAll=Se,b.$reactive=Ee,b.$setState=Q,b.__setComponentContext=et,b.registerComponent=ge,b.registerComponents=be,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
85
96
  //# sourceMappingURL=ladrillosjs.umd.js.map