ladrillosjs 2.0.0-beta.3 → 2.0.0-beta.3.2

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.
@@ -1,26 +1,26 @@
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(`
1
+ (function(g,$){typeof exports=="object"&&typeof module!="undefined"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(g=typeof globalThis!="undefined"?globalThis:g||self,$(g.ladrillosjs={}))})(this,(function(g){"use strict";var yt=Object.defineProperty,wt=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var Me=Object.getOwnPropertySymbols;var Et=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable;var Re=g=>{throw TypeError(g)};var Fe=(g,$,d)=>$ in g?yt(g,$,{enumerable:!0,configurable:!0,writable:!0,value:d}):g[$]=d,L=(g,$)=>{for(var d in $||($={}))Et.call($,d)&&Fe(g,d,$[d]);if(Me)for(var d of Me($))vt.call($,d)&&Fe(g,d,$[d]);return g},j=(g,$)=>wt(g,$t($));var de=(g,$,d)=>$.has(g)||Re("Cannot "+d);var x=(g,$,d)=>(de(g,$,"read from private field"),d?d.call(g):$.get(g)),N=(g,$,d)=>$.has(g)?Re("Cannot add the same private member more than once"):$ instanceof WeakSet?$.add(g):$.set(g,d),J=(g,$,d,k)=>(de(g,$,"write to private field"),k?k.call(g,d):$.set(g,d),d),D=(g,$,d)=>(de(g,$,"access private method"),d);var T=(g,$,d)=>new Promise((k,U)=>{var se=M=>{try{K(d.next(M))}catch(Z){U(Z)}},oe=M=>{try{K(d.throw(M))}catch(Z){U(Z)}},K=M=>M.done?k(M.value):Promise.resolve(M.value).then(se,oe);K((d=d.apply(g,$)).next())});var X,He,ze;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
2
  Component: <${e.componentName}>`),e.componentPath&&t.push(`
3
3
  File: ${e.componentPath}`),e.expression&&t.push(`
4
4
  Expression: ${e.expression}`),e.attributeName&&t.push(`
5
5
  Attribute: ${e.attributeName}`),e.eventType&&t.push(`
6
6
  Event: ${e.eventType}`),e.elementTag&&t.push(`
7
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,`
8
+ Location: ${e.lineHint}`)),t.join("")},U=(n,e,t)=>{const s=k("⚠️ Binding Error: Failed to evaluate expression",j(L({},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(L({},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(L({},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(L({},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)},M=(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(L({},t),{componentPath:n}));d.error(s),d.error(` Error details: ${e.message}`)},re=(n,e)=>{const t=k(`⚠️ Parse Error: ${n}`,e);d.error(t)},Oe=(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(L({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$model binding"}));d.error(s),d.error(` Error details: ${e.message}`)},F=(n,e)=>{var t;return L({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)},R=new Map,je=25,Ie=n=>{const e=R.get(n);return e&&(R.delete(n),R.set(n,e)),e},qe=(n,e)=>{if(R.has(n))R.delete(n);else if(R.size>=je){const t=R.keys().next().value;t&&R.delete(t)}R.set(n,e)},pe=n=>T(null,null,function*(){if(!n)throw new Error("Path cannot be null or empty");const e=Ie(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 qe(n,s),s}catch(t){Z(n,t,{componentPath:n})}}),De=n=>T(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)=>T(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,`
9
9
  `).replace(/\\n/g,`
10
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,`
11
11
  `).replace(/\\n/g,`
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+=`
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=>T(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
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=`
14
+ `+r}}s.remove()}return e.trim()});class Ye{constructor(){N(this,X);this.components={},this.lazyComponents=new Set,this.intersectionObserver=null,this.lazyLoadingInProgress=new Map,this.lazyComponentsLoaded=new Set}registerComponent(e,t,s=!0,o=!1){return T(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,He).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,ze).call(this,e,s)}catch(r){M(e,t,r);return}})}}X=new WeakSet,He=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
15
  <style>
16
16
  :host { display: block; min-height: 1px; }
17
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",`
18
+ `))}connectedCallback(){if(!this.loaded){if(this.hasAttribute("eager")){this.loaded=!0,this.loadComponent();return}this.observer=new IntersectionObserver(c=>{c.forEach(f=>{f.isIntersecting&&!this.loaded&&(this.loaded=!0,this.loadComponent())})},{rootMargin:"100px"}),this.observer.observe(this)}}disconnectedCallback(){this.observer&&(this.observer.disconnect(),this.observer=null)}loadComponent(){return T(this,null,function*(){try{if(o.lazyComponentsLoaded.has(e)){d.log(`Component ${e} already loaded, upgrading placeholder...`),this.upgradePlaceholder();return}if(o.lazyLoadingInProgress.has(e)){d.log(`Component ${e} is already loading, waiting...`),yield o.lazyLoadingInProgress.get(e),this.upgradePlaceholder();return}const c=this.performLoad();o.lazyLoadingInProgress.set(e,c),yield c,o.lazyLoadingInProgress.delete(e),o.lazyComponentsLoaded.add(e),o.lazyComponents.delete(e),d.log(`Component ${e} lazy-loaded successfully`)}catch(c){o.lazyLoadingInProgress.delete(e),M(e,t,c)}})}performLoad(){return T(this,null,function*(){d.log(`Lazy loading component: ${e}`);const c=this.parentNode;if(this.nextSibling,!c){re(`Placeholder for ${e} has no parent node`,{componentName:e,componentPath:t});return}const f=yield pe(t),a=yield he(f,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 l=`${e}-real`;d.log(`Defining real component with temp name: ${l}`);const u=o.components[e].tagName;o.components[e].tagName=l;const{defineWebComponent:p}=yield Promise.resolve().then(()=>Ne);p(o.components[e],s),d.log(`Real component ${l} defined`),o.components[e].tagName=u,this.upgradePlaceholder()})}upgradePlaceholder(){const c=this,f=this.parentNode,a=this.nextSibling;if(!f){re(`Placeholder for ${e} has no parent node`,{componentName:e,componentPath:t});return}const l=`${e}-real`,u=document.createElement(l);for(d.log(`Created real component instance: ${l}`),Array.from(c.attributes).forEach(p=>{p.name!=="eager"&&u.setAttribute(p.name,p.value)});c.firstChild;)u.appendChild(c.firstChild);a?(f.insertBefore(u,a),d.log("Inserted real component before next sibling")):(f.appendChild(u),d.log("Appended real component to parent")),f.removeChild(c),d.log("Removed placeholder element")}}customElements.get(e)||customElements.define(e,r)},ze=function(e,t){return T(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>Ne);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 ie=new Qe,ge=(n,e,t,s)=>me.registerComponent(n,e,t,s),be=n=>T(null,null,function*(){yield Promise.all(n.map(({name:e,path:t,useShadowDOM:s,lazy:o})=>me.registerComponent(e,t,s,o)))}),ye=(n,e)=>ie.listen(n,e),we=(n,e)=>{ie.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=ye,window.$emit=we,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,f=i.map(a=>{const l=a[1].trim(),u=l.includes("(")&&l.includes(")"),p=/[+*/%<>=!&|]/.test(l)||/\s-\s/.test(l),m=/^(!|typeof\s|void\s|delete\s)/.test(l),E=p||m||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(l)||/\bnew\s+/.test(l)||/\b(typeof|instanceof|void|delete)\b/.test(l),b=u?[l.split("(")[0].trim()]:l.split(".").map(H=>H.trim()),y=u?Ce(l):[];return{raw:l,path:b,isFunction:u,isExpression:E,functionArgs:y}});t.push({node:s,bindings:f,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 f=[...c.value.matchAll(G.bindings)];if(f.length>0){const a=c.value,l=f.map(u=>{const p=u[1].trim(),m=p.includes("(")&&p.includes(")"),E=/[+*/%<>=!&|]/.test(p)||/\s-\s/.test(p),b=/^(!|typeof\s|void\s|delete\s)/.test(p),y=E||b||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(p)||/\bnew\s+/.test(p)||/\b(typeof|instanceof|void|delete)\b/.test(p),H=m?[p.split("(")[0].trim()]:p.split(".").map(le=>le.trim()),O=m?Ce(p):[];return{raw:p,path:H,isFunction:m,isExpression:y,functionArgs:O}});t.push({node:i,bindings:l,original:a,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(f=>f.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"),f=i.hasAttribute("$else-if"),a=i.hasAttribute("$else");if(!c&&!f&&!a)break;t.add(i);let l,u="";c?(l="if",u=i.getAttribute("$if")||"",i.removeAttribute("$if")):f?(l="else-if",u=i.getAttribute("$else-if")||"",i.removeAttribute("$else-if")):(l="else",i.removeAttribute("$else"));const p=document.createComment(`conditional:${l}:${u}`),m=i.parentElement||n,E=i.nextSibling;m.insertBefore(p,i);const b={element:i,condition:u.trim(),type:l,placeholder:p,group:[],originalParent:m,nextSibling:E};r.push(b);const y=i.nextElementSibling;if(i.remove(),i=y,y&&!y.hasAttribute("$else-if")&&!y.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 a=c[1].split(".")[0];i.has(a)||e.add(a)}})}),e},ct=n=>{const e=[];return n.querySelectorAll("[\\$for]").forEach(s=>{var m;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){re(`Invalid $for expression: "${o}"`,{expression:o,lineHint:"$for attribute parsing"});return}const c=(i[1]||i[3]).trim(),f=(m=i[2])==null?void 0:m.trim(),a=i[4].trim(),l=document.createComment(`loop:${o}`),u=s.parentElement||n;u.insertBefore(l,s),s.removeAttribute("$for"),r&&s.removeAttribute("$key"),s.remove();const p={template:s,expression:o,itemName:c,indexName:f,arrayName:a,keyAttribute:r,placeholder:l,renderedElements:[],originalParent:u};e.push(p)}),e},at=n=>{const e=new Set;return n.forEach(t=>{const s=t.arrayName.split(".")[0];e.add(s)}),e},I=new Map,lt=100,ce=n=>{const e=I.get(n);if(e)return I.delete(n),I.set(n,e),e;const t=new Function("component",`
19
19
  const { Date, Array, Math, String, Number, Boolean, Object, JSON, RegExp } = globalThis;
20
20
  with(component) {
21
21
  return ${n};
22
22
  }
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",`
23
+ `);if(I.size>=lt){const s=I.keys().next().value;s&&I.delete(s)}return I.set(n,t),t},ee=(n,e)=>e.reduce((t,s)=>{if(!(t==null||typeof t!="object"))return t[s]},n),ae=(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:f,isFunction:a,isExpression:l}of s.bindings){let u,p=!1;if(l||a)try{u=ce(c)(t||e)}catch(E){U(c,E,F(t)),u=void 0,p=!0}else u=ee(e,f),u===void 0&&(p=!0);if(p){i=!0;continue}const m=String(u!=null?u:"");r=u,o=o.replace(`{${c}}`,m)}if(i&&s.original,s.node.nodeType===Node.TEXT_NODE){const c=s.node,f=c.parentElement,a=o.trim().startsWith("<")&&o.includes(">");f&&a?f.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",`
24
24
  with (context) {
25
25
  try {
26
26
  return Boolean(${s});
@@ -28,11 +28,11 @@
28
28
  return false;
29
29
  }
30
30
  }
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",`
31
+ `)(e,t)}catch(o){return oe(n,o,F(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 f=`__processed_${i}`;if(o[f])return;o.removeAttribute(i),o.addEventListener(r,function(a){try{new Function("event","component",`
32
32
  with(component) {
33
33
  ${c}
34
34
  }
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(`
35
+ `).call(this,a,e)}catch(l){se(r,c,l,F(e,{elementTag:o.tagName.toLowerCase()}))}}),o[f]=!0}})})},_e=(n,e,t)=>{var s;for(const o of n){let r=!1;for(const i of o){const{element:c,condition:f,type:a,placeholder:l,originalParent:u}=i;let p=!1;a==="else"?p=!r:r||(p=ut(f,e,t),p&&(r=!0));const m=c.parentNode!==null;p&&!m?((s=l.parentNode)==null||s.insertBefore(c,l.nextSibling),t&&xe(c,t)):!p&&m&&c.remove()}}},ke=(n,e,t)=>{for(const s of n){const{template:o,itemName:r,indexName:i,arrayName:c,placeholder:f,renderedElements:a}=s,l=ee(e,c.split("."));if(l!==void 0&&!Array.isArray(l)){K(`${r} in ${c}`,new Error(`"${c}" is not an array, got: ${typeof l}`),F(t,{lineHint:"$for loop in template"})),a.forEach(u=>u.remove()),a.length=0;return}if(!l)return;a.forEach(u=>u.remove()),a.length=0,l.forEach((u,p)=>{var y;const m=o.cloneNode(!0),E=j(L({},e),{[r]:u});i&&(E[i]=p),dt(m,E,t);const b=a.length>0?a[a.length-1]:f;(y=b.parentNode)==null||y.insertBefore(m,b.nextSibling),a.push(m),t&&xe(m,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(f=>{const a=f[1].trim(),l=a.includes("(")&&a.includes(")"),p=/[+*/%<>=!&|]/.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 m;if(p||l)try{const E=ce(a),b=typeof e=="object"&&e!==null?L(L({},e),t||{}):t||{};m=E(b)}catch(E){U(a,E,F(t,{lineHint:"$for loop template binding"})),m=void 0}else{const E=a.split(".").map(b=>b.trim());m=ee(e,E)}m!==void 0&&(i=i.replace(`{${a}}`,String(m!=null?m:"")))}),o.textContent=i}[n,...n.querySelectorAll("*")].forEach(i=>{Array.from(i.attributes).forEach(c=>{if(c.value.includes("{")){let f=c.value;[...c.value.matchAll(/\{([^}]+)\}/g)].forEach(l=>{const u=l[1].trim(),p=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||p)try{const y=ce(u),H=typeof e=="object"&&e!==null?L(L({},e),t||{}):t||{};b=y(H)}catch(y){U(u,y,F(t,{attributeName:c.name,lineHint:"$for loop attribute binding"})),b=void 0}else{const y=u.split(".").map(H=>H.trim());b=ee(e,y)}b!==void 0&&(f=f.replace(`{${u}}`,String(b!=null?b:"")))}),i.setAttribute(c.name,f)}})})},Le=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(`
36
36
  if (!Object.getOwnPropertyDescriptor(component, '${o}')) {
37
37
  Object.defineProperty(component, '${o}', {
38
38
  get() { return this.state.${o}; },
@@ -42,9 +42,9 @@
42
42
  });
43
43
  }
44
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=`
45
+ `),bindVarNames:t}},pt=(n,e,t=new Set)=>{const s=[],o=new Map,r=new Set;e.forEach(f=>{f.bindings.forEach(a=>{const l=a.path[0];r.add(l),a.isFunction&&a.functionArgs&&a.functionArgs.forEach(u=>{r.add(u)})})}),t.forEach(f=>{r.add(f)});const i=/(?:const|let|var)\s+(\w+)\s*=\s*([^;]+);?/g;let c;for(;(c=i.exec(n))!==null;){const f=c[1],a=c[2].trim();r.has(f)&&(s.push(`component.state.${f} = ${f};`),o.set(f,a))}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 f=new RegExp(`(?<!\\.)\\b(\\+\\+|\\-\\-)${s}\\b|\\b${s}(\\+\\+|\\-\\-)`,"g");t=t.replace(f,u=>{if(u.startsWith("++")||u.startsWith("--"))return`${u.substring(0,2)}component.state.${s}`;{const p=u.substring(u.length-2);return`component.state.${s}${p}`}});const a=new RegExp(`(?<!\\.)\\b${s}\\s*(\\+=|\\-=|\\*=|\\/=|%=|\\*\\*=|<<=|>>=|>>>=|&=|\\|=|\\^=)`,"g");t=t.replace(a,`component.state.${s}$1`);const l=new RegExp(`(?<!const\\s)(?<!let\\s)(?<!var\\s)(?<!\\.)\\b${s}\\s*=\\s*([^=])`,"g");t=t.replace(l,`component.state.${s} = $1`)}),t},Te=(n,e,t,s,o,r=new Set)=>{try{const{injectedCode:i,componentInjections:c,bindVarNames:f}=ft(n,t),a=/function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[\w\s]*)\s*=>/g,l=[];let u;for(;(u=a.exec(n))!==null;){const P=u[1]||u[2];P&&l.push(P)}const p=l.map(P=>`component.${P} = typeof ${P} !== 'undefined' ? ${P}.bind(component) : undefined;`).join(`
46
+ `),{stateBindings:m,boundVarNames:E,defaultValues:b}=pt(n,e,r),y=new Set([...E,...f]),H=m.join(`
47
+ `),O=ht(n,y),le=`
48
48
  (function() {
49
49
  // Create component scope with direct access to state
50
50
  const component = this;
@@ -79,18 +79,18 @@
79
79
 
80
80
  // Execute script content within component scope so $bind variables are accessible
81
81
  with(component) {
82
- ${z}
82
+ ${O}
83
83
 
84
84
  // Auto-bind variables to component state (e.g., const name = "value" → this.state.name = "value")
85
- ${P}
85
+ ${H}
86
86
 
87
87
  // Auto-attach all detected functions to component for onclick access
88
- ${f}
88
+ ${p}
89
89
  }
90
90
  }).call(arguments[0], arguments[0], arguments[1], arguments[2])
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",`
91
+ `;return new Function(le)(o,s,ie),b}catch(i){return Oe(i,F(o)),new Map}},Pe=(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 f=i.getAttribute(o);f&&(i.removeAttribute(o),i.addEventListener(s,function(a){new Function("event","component",`
92
92
  with(component) {
93
- ${p}
93
+ ${f}
94
94
  }
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"})}));
95
+ `).call(this,a,e)}),i[`__processed_${c}`]=!0)})})},mt=(r,i,c,...f)=>T(null,[r,i,c,...f],function*(n,e,t,s=[],o=new Set){const a=new Map;if(!(e!=null&&e.length))return a;const l=Le(n);for(const u of e)u.content&&Te(u.content,t,s,n,l,o).forEach((m,E)=>{a.has(E)||a.set(E,m)});return Pe(n,l),a}),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,f,...a)=>T(null,[i,c,f,...a],function*(n,e,t,s=[],o=new Set,r){var u;const l=Le(n);for(const p of e){let m;r?r.startsWith("http://")||r.startsWith("https://")?m=r:m=new URL(r,window.location.href).href:m=window.location.href;const E=new URL(p.src,m).href;if(p.external)yield gt(E,p.type);else if(p.type==="module"){const b=l.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(b,{host:n,shadowRoot:n instanceof ShadowRoot?n:null,element:l,state:l.state,setState:(u=l.setState)==null?void 0:u.bind(l)});const y=document.createElement("script");y.type="module",y.src=E,y.setAttribute("data-component",b),document.head.appendChild(y)}else yield fetch(E).then(b=>{if(!b.ok)throw new Error(`HTTP ${b.status}: ${b.statusText}`);const y=b.headers.get("content-type");if(y&&!y.includes("javascript")&&!y.includes("text/plain"))throw new Error(`Expected JavaScript but got ${y}`);return b.text()}).then(b=>{Te(b,t,s,n,l,o)}).catch(b=>{console.error(`Failed to load external script: ${p.src}`,b)})}Pe(n,l)}),Ne=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(n,e)=>{var a,l,u,p,m,E,b,y,fe,O,Be,Ve;const{tagName:t,template:s,scripts:o,externalScripts:r,styles:i,sourcePath:c}=n,P=class P extends HTMLElement{constructor(){super();N(this,y);N(this,a,[]);N(this,l,[]);N(this,u,[]);N(this,p,[]);N(this,m,[]);N(this,E,c);N(this,b,new WeakMap);e&&this.attachShadow({mode:"open"});const h={},v=()=>{Ae(x(this,a),this.state,this),_e(x(this,u),this.state,this),ke(x(this,p),this.state,this),D(this,y,Ve).call(this)};this.state=new Proxy(h,{get:(C,w)=>C[w],set:(C,w,S)=>{const _=C[w];return w in C&&Object.is(_,S)||(S!==null&&typeof S=="object"?C[w]=D(this,y,fe).call(this,S,v):C[w]=S,Object.getOwnPropertyDescriptor(this,w)||Object.defineProperty(this,w,{get(){return this.state[w]},set(q){this.state[w]=q},enumerable:!0,configurable:!0}),v()),!0}})}setState(h){Object.assign(this.state,h)}connectedCallback(){return T(this,null,function*(){const h=e?this.shadowRoot:this,{bindings:v,twoWayBindings:C,conditionals:w,loops:S}=nt(h,s);J(this,a,v),J(this,l,C),J(this,u,w),J(this,p,S);const _=it(w),z=at(S);tt(h,i,e),yield bt(h,r,x(this,a),x(this,l),new Set([..._,...z]),x(this,E)),(yield mt(h,o,x(this,a),x(this,l),new Set([..._,...z]))).forEach((A,W)=>{if(this.state[W]===void 0)try{const B=new Function(`return ${A}`);this.state[W]=B()}catch(B){this.state[W]=A}}),this._initializeStateFromAttributes(),this._setupTwoWayBindings(),Ae(x(this,a),this.state,this),_e(x(this,u),this.state,this),ke(x(this,p),this.state,this),this._setupAttributeObserver()})}disconnectedCallback(){this.__attributeObserver&&(this.__attributeObserver.disconnect(),this.__attributeObserver=null),x(this,m).forEach(v=>{try{v()}catch(C){We("cleanup",C,F(this,{lineHint:"disconnectedCallback cleanup"}))}}),J(this,m,[]);const h=this.__eventUnsubscribers;h&&Array.isArray(h)&&(h.forEach(v=>{try{v()}catch(C){d.error("⚠️ Event Bus Error: Failed to unsubscribe from event",F(this)),d.error(` Error details: ${C.message}`)}}),this.__eventUnsubscribers=[])}_setupAttributeObserver(){const h=new MutationObserver(v=>{v.forEach(C=>{if(C.type==="attributes"&&C.attributeName){const w=this.getAttribute(C.attributeName);this._handleAttributeChange(C.attributeName,w)}})});h.observe(this,{attributes:!0,attributeOldValue:!0}),this.__attributeObserver=h}_initializeStateFromAttributes(){this.getAttributeNames().forEach(h=>{const v=this.getAttribute(h);this._handleAttributeChange(h,v)})}_handleAttributeChange(h,v){var w;if(h){const S="this.state.";h.startsWith(S)&&(h=h.slice(S.length))}const C=D(w=P,O,Be).call(w,v);this.state[h]=C}_setupTwoWayBindings(){x(this,l).forEach(({element:h,path:v,raw:C,isContentEditable:w,initialValue:S})=>{var z,q;if(this._getNestedValue(v)===void 0){const A=S||"";ae(this.state,v,A)}if(w){const A=h;A.textContent=(z=this._getNestedValue(v))!=null?z:"";const W=ue=>{const V=ue.target.textContent||"";ae(this.state,v,V)};A.addEventListener("input",W);const B=()=>{A.removeEventListener("input",W)};x(this,m).push(B)}else{const A=h,W=A instanceof HTMLInputElement&&A.type==="checkbox";A instanceof HTMLInputElement&&A.type,W?A.checked=!!this._getNestedValue(v):A.value=(q=this._getNestedValue(v))!=null?q:"";const B=te=>{const V=te.target;let ne;V instanceof HTMLInputElement&&V.type==="checkbox"?ne=V.checked:(V instanceof HTMLInputElement&&V.type,ne=V.value),ae(this.state,v,ne)};A.addEventListener("input",B);const ue=()=>{A.removeEventListener("input",B)};if(x(this,m).push(ue),A instanceof HTMLSelectElement||A instanceof HTMLInputElement&&["checkbox","radio","file"].includes(A.type)){A.addEventListener("change",B);const te=()=>{A.removeEventListener("change",B)};x(this,m).push(te)}}})}_getNestedValue(h){return h.reduce((v,C)=>v==null?void 0:v[C],this.state)}};a=new WeakMap,l=new WeakMap,u=new WeakMap,p=new WeakMap,m=new WeakMap,E=new WeakMap,b=new WeakMap,y=new WeakSet,fe=function(h,v){if(h===null||typeof h!="object"||h instanceof HTMLElement||h instanceof Node)return h;if(x(this,b).has(h))return x(this,b).get(h);const C=new Proxy(h,{get:(w,S)=>{const _=w[S];return Array.isArray(w)&&typeof _=="function"&&["push","pop","shift","unshift","splice","sort","reverse"].includes(S)?(...q)=>{const A=_.apply(w,q);return v(),A}:_!==null&&typeof _=="object"?D(this,y,fe).call(this,_,v):_},set:(w,S,_)=>{const z=w[S];return Object.is(z,_)||(w[S]=_,v()),!0}});return x(this,b).set(h,C),C},O=new WeakSet,Be=function(h){if(h===null||h==="")return null;if(h!=="undefined")try{return JSON.parse(h)}catch(v){return h}},Ve=function(){x(this,l).forEach(({element:h,path:v,isContentEditable:C})=>{const w=this._getNestedValue(v);if(C){const S=h;S.textContent!==w&&(S.textContent=w!=null?w:"")}else{const S=h;if(S instanceof HTMLInputElement&&S.type==="checkbox"){const _=!!w;S.checked!==_&&(S.checked=_)}else S.value!==w&&(S.value=w!=null?w:"")}})},N(P,O);let f=P;customElements.get(t)||(customElements.define(t,f),d.log(`Web component defined: <${t}></${t}>`))}},Symbol.toStringTag,{value:"Module"}));g.$emit=we,g.$getState=$e,g.$listen=ye,g.$querySelector=ve,g.$querySelectorAll=Se,g.$reactive=Ee,g.$setState=Q,g.__setComponentContext=et,g.registerComponent=ge,g.registerComponents=be,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
96
96
  //# sourceMappingURL=ladrillosjs.umd.js.map