ladrillosjs 1.0.0 → 1.0.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.
@@ -161,7 +161,7 @@ const x = class x {
161
161
  /** @private */
162
162
  _defineWebComponent(e, t) {
163
163
  return u(this, null, function* () {
164
- const { defineWebComponent: s } = yield import("./webcomponent-8TKKZviJ.mjs");
164
+ const { defineWebComponent: s } = yield import("./webcomponent-UTcwAakf.mjs");
165
165
  s(this.components[e], t);
166
166
  });
167
167
  }
@@ -1,3 +1,3 @@
1
1
  "use strict";var T=Object.defineProperty;var E=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var W=r=>{throw TypeError(r)};var P=(r,e,t)=>e in r?T(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))j.call(e,t)&&P(r,t,e[t]);if(E)for(var t of E(e))H.call(e,t)&&P(r,t,e[t]);return r};var q=(r,e,t)=>e.has(r)||W("Cannot "+t);var d=(r,e,t)=>(q(r,e,"read from private field"),t?t.call(r):e.get(r)),y=(r,e,t)=>e.has(r)?W("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t);var v=(r,e,t)=>(q(r,e,"access private method"),t);var u=(r,e,t)=>new Promise((s,o)=>{var l=a=>{try{c(t.next(a))}catch(g){o(g)}},i=a=>{try{c(t.throw(a))}catch(g){o(g)}},c=a=>a.done?s(a.value):Promise.resolve(a.value).then(l,i);c((t=t.apply(r,e)).next())});const h={log(r,...e){},error(r,...e){console.error(r,...e)},warn(r,...e){}};var m,w,C,A;const S=class S{constructor(){y(this,m,new Map);y(this,w,new DOMParser);this.components={}}registerComponent(e,t,s=!0){return u(this,null,function*(){var o,l,i;if(this.components[e]){h.log(`Component ${e} already registered.`);return}this.components[e]={__registering:!0};try{const c=yield u(this,null,function*(){const n=d(this,m).get(t);if(n)return n;const k=yield(yield fetch(t)).text();return d(this,m).set(t,k),k}),a=d(this,w).parseFromString(c.replace(/<!--[\s\S]*?-->/g,""),"text/html"),g=[],$=[];for(const n of a.querySelectorAll("script")){if(n.src)$.push({src:n.src,type:(o=n.type)!=null?o:null,bind:n.hasAttribute("bind")});else if(n.textContent){let p=n.textContent.trim();p=p.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),g.push({content:p,type:(l=n.type)!=null?l:null})}n.remove()}let f="";for(const n of a.querySelectorAll("link[rel='stylesheet']"))f+=`
2
2
  `+(yield v(i=S,C,A).call(i,`${n.href}?raw`)),n.remove();for(const n of a.querySelectorAll("style")){if(n.textContent){let p=n.textContent.trim();p=p.replace(/\/\*[\s\S]*?\*\//g,"").trim(),f+=`
3
- `+p}n.remove()}f=f.trim(),this.components[e]={tagName:e,template:a.body.innerHTML.trim(),scripts:g,externalScripts:$,style:f},yield this._defineWebComponent(e,s),h.log(`Component ${e} registered successfully`)}catch(c){h.error(`Failed to register component ${e}:`,c),delete this.components[e]}})}registerComponents(e,t=5){return u(this,null,function*(){const s=e.map(({name:l,path:i,useShadowDOM:c})=>()=>this.registerComponent(l,i,c)),o=yield this._runWithConcurrency(s,t);return o.forEach((l,i)=>{if(l.status==="rejected"){const{name:c}=e[i];h.error(`registration failed for ${c}:`,l.reason)}}),o})}_runWithConcurrency(e,t){return u(this,null,function*(){const s=[],o=[];for(const l of e){let i;const c=l();s.push(c),i=c.then(()=>{o.splice(o.indexOf(i),1)}),o.push(i),o.length>=t&&(yield Promise.race(o))}return Promise.allSettled(s)})}_defineWebComponent(e,t){return u(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>require("./webcomponent-BOcL3Sbk.js"));s(this.components[e],t)})}};m=new WeakMap,w=new WeakMap,C=new WeakSet,A=function(e){return u(this,null,function*(){try{const t=yield fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return yield t.text()}catch(t){return h.error(`Failed to fetch resource at ${e}:`,t),""}})},y(S,C);let b=S;const F=new b;function O(r={}){let e=r;const t=new Set;return{getState(){return e},setState(s){e=x(x({},e),s),t.forEach(o=>o(e))},subscribe(s){return t.add(s),s(e),()=>t.delete(s)},reset(){e=r,t.forEach(s=>s(e))}}}const _=(...r)=>F.registerComponent(...r),M=(...r)=>F.registerComponents(...r);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:_,registerComponents:M});exports.createStore=O;exports.logger=h;exports.registerComponent=_;exports.registerComponents=M;
3
+ `+p}n.remove()}f=f.trim(),this.components[e]={tagName:e,template:a.body.innerHTML.trim(),scripts:g,externalScripts:$,style:f},yield this._defineWebComponent(e,s),h.log(`Component ${e} registered successfully`)}catch(c){h.error(`Failed to register component ${e}:`,c),delete this.components[e]}})}registerComponents(e,t=5){return u(this,null,function*(){const s=e.map(({name:l,path:i,useShadowDOM:c})=>()=>this.registerComponent(l,i,c)),o=yield this._runWithConcurrency(s,t);return o.forEach((l,i)=>{if(l.status==="rejected"){const{name:c}=e[i];h.error(`registration failed for ${c}:`,l.reason)}}),o})}_runWithConcurrency(e,t){return u(this,null,function*(){const s=[],o=[];for(const l of e){let i;const c=l();s.push(c),i=c.then(()=>{o.splice(o.indexOf(i),1)}),o.push(i),o.length>=t&&(yield Promise.race(o))}return Promise.allSettled(s)})}_defineWebComponent(e,t){return u(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>require("./webcomponent-Cga3h8cx.js"));s(this.components[e],t)})}};m=new WeakMap,w=new WeakMap,C=new WeakSet,A=function(e){return u(this,null,function*(){try{const t=yield fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return yield t.text()}catch(t){return h.error(`Failed to fetch resource at ${e}:`,t),""}})},y(S,C);let b=S;const F=new b;function O(r={}){let e=r;const t=new Set;return{getState(){return e},setState(s){e=x(x({},e),s),t.forEach(o=>o(e))},subscribe(s){return t.add(s),s(e),()=>t.delete(s)},reset(){e=r,t.forEach(s=>s(e))}}}const _=(...r)=>F.registerComponent(...r),M=(...r)=>F.registerComponents(...r);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:_,registerComponents:M});exports.createStore=O;exports.logger=h;exports.registerComponent=_;exports.registerComponents=M;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-D8qqeJcR.js");exports.createStore=e.createStore;exports.registerComponent=e.registerComponent;exports.registerComponents=e.registerComponents;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-X9YN_DbT.js");exports.createStore=e.createStore;exports.registerComponent=e.registerComponent;exports.registerComponents=e.registerComponents;
@@ -1,4 +1,4 @@
1
- import { c as o, r as t, a as s } from "./index-CYYvcgtW.mjs";
1
+ import { c as o, r as t, a as s } from "./index-D_dHFObN.mjs";
2
2
  export {
3
3
  o as createStore,
4
4
  t as registerComponent,
@@ -1,18 +1,18 @@
1
- (function(f,d){typeof exports=="object"&&typeof module!="undefined"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(f=typeof globalThis!="undefined"?globalThis:f||self,d(f.ladrillosjs={}))})(this,function(f){"use strict";var ft=Object.defineProperty;var et=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,pt=Object.prototype.propertyIsEnumerable;var st=f=>{throw TypeError(f)};var nt=(f,d,o)=>d in f?ft(f,d,{enumerable:!0,configurable:!0,writable:!0,value:o}):f[d]=o,Q=(f,d)=>{for(var o in d||(d={}))dt.call(d,o)&&nt(f,o,d[o]);if(et)for(var o of et(d))pt.call(d,o)&&nt(f,o,d[o]);return f};var it=(f,d,o)=>d.has(f)||st("Cannot "+o);var D=(f,d,o)=>(it(f,d,"read from private field"),o?o.call(f):d.get(f)),N=(f,d,o)=>d.has(f)?st("Cannot add the same private member more than once"):d instanceof WeakSet?d.add(f):d.set(f,o);var G=(f,d,o)=>(it(f,d,"access private method"),o);var W=(f,d,o)=>new Promise((L,j)=>{var X=k=>{try{F(o.next(k))}catch(M){j(M)}},H=k=>{try{F(o.throw(k))}catch(M){j(M)}},F=k=>k.done?L(k.value):Promise.resolve(k.value).then(X,H);F((o=o.apply(f,d)).next())});var q,V,I,rt;var d=typeof document!="undefined"?document.currentScript:null;const o={log($,...c){},error($,...c){console.error($,...c)},warn($,...c){}},Z=class Z{constructor(){N(this,q,new Map);N(this,V,new DOMParser);this.components={}}registerComponent(c,m,y=!0){return W(this,null,function*(){var S,A,v;if(this.components[c]){o.log(`Component ${c} already registered.`);return}this.components[c]={__registering:!0};try{const C=yield W(this,null,function*(){const t=D(this,q).get(m);if(t)return t;const n=yield(yield fetch(m)).text();return D(this,q).set(m,n),n}),B=D(this,V).parseFromString(C.replace(/<!--[\s\S]*?-->/g,""),"text/html"),Y=[],R=[];for(const t of B.querySelectorAll("script")){if(t.src)R.push({src:t.src,type:(S=t.type)!=null?S:null,bind:t.hasAttribute("bind")});else if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),Y.push({content:e,type:(A=t.type)!=null?A:null})}t.remove()}let z="";for(const t of B.querySelectorAll("link[rel='stylesheet']"))z+=`
2
- `+(yield G(v=Z,I,rt).call(v,`${t.href}?raw`)),t.remove();for(const t of B.querySelectorAll("style")){if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\//g,"").trim(),z+=`
3
- `+e}t.remove()}z=z.trim(),this.components[c]={tagName:c,template:B.body.innerHTML.trim(),scripts:Y,externalScripts:R,style:z},yield this._defineWebComponent(c,y),o.log(`Component ${c} registered successfully`)}catch(C){o.error(`Failed to register component ${c}:`,C),delete this.components[c]}})}registerComponents(c,m=5){return W(this,null,function*(){const y=c.map(({name:A,path:v,useShadowDOM:C})=>()=>this.registerComponent(A,v,C)),S=yield this._runWithConcurrency(y,m);return S.forEach((A,v)=>{if(A.status==="rejected"){const{name:C}=c[v];o.error(`registration failed for ${C}:`,A.reason)}}),S})}_runWithConcurrency(c,m){return W(this,null,function*(){const y=[],S=[];for(const A of c){let v;const C=A();y.push(C),v=C.then(()=>{S.splice(S.indexOf(v),1)}),S.push(v),S.length>=m&&(yield Promise.race(S))}return Promise.allSettled(y)})}_defineWebComponent(c,m){return W(this,null,function*(){const{defineWebComponent:y}=yield Promise.resolve().then(()=>ct);y(this.components[c],m)})}};q=new WeakMap,V=new WeakMap,I=new WeakSet,rt=function(c){return W(this,null,function*(){try{const m=yield fetch(c);if(!m.ok)throw new Error(`HTTP ${m.status}`);return yield m.text()}catch(m){return o.error(`Failed to fetch resource at ${c}:`,m),""}})},N(Z,I);let L=Z;const j=new L;function X($={}){let c=$;const m=new Set;return{getState(){return c},setState(y){c=Q(Q({},c),y),m.forEach(S=>S(c))},subscribe(y){return m.add(y),y(c),()=>m.delete(y)},reset(){c=$,m.forEach(y=>y(c))}}}const H=(...$)=>j.registerComponent(...$),F=(...$)=>j.registerComponents(...$);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:H,registerComponents:F});function k($,c){return JSON.stringify($,(m,y)=>typeof y=="string"?y.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):y,c).replace(/"/g,"&quot;")}const ct=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:($,c)=>{var B,ot;const{tagName:m,template:y,scripts:S,externalScripts:A,style:v}=$,R=class R extends HTMLElement{constructor(){super(),c&&this.attachShadow({mode:"open"}),this.root=c?this.shadowRoot:document,this.stringify=k;const t={};this.state=new Proxy(t,{set:(e,n,s)=>(e[n]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:e,listener:n})=>{t.removeEventListener(e,n)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(e=>{if(e.type==="attributes"){const n=e.attributeName,s=this.getAttribute(n);this._handleAttributeChange(n,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const e of t)if(e.attributeName==="contenteditable"){const n=e.target;n.isContentEditable&&n.hasAttribute("data-bind")&&this._bindTwoWayForElement(n)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,e,n){const s=new MutationObserver(t.bind(this));return s.observe(e,n),s}_handleAttributeChange(t,e){var s;if(t){const i="this.state.";t.startsWith(i)&&(t=t.slice(i.length))}const n=G(s=R,B,ot).call(s,e);this.state[t]=n,this._render()}_loadTemplate(){c?this.shadowRoot.innerHTML=y:this.innerHTML=y,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let e;for(;e=t.nextNode();){const n=[...e.textContent.matchAll(/{([^}]+)}/g)];if(n.length){const s=n.map(([,i])=>({node:e,template:e.textContent,key:i.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(n=>{Array.from(n.attributes).forEach(s=>{const i=[...s.value.matchAll(/{([^}]+)}/g)];i.length&&i.forEach(([,r])=>{this._bindings.push({element:n,attrName:s.name,template:s.value,key:r.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(e=>{if(!e.name.startsWith("on"))return;const n=e.name.slice(2),s=e.value.trim();t.removeAttribute(e.name);let i;const r=s.trim();if(/^\([^)]*\)\s*=>/.test(r))try{const u=new Function("event",`return (${r});`).call(this);i=b=>u(b)}catch(a){o.error(`Error parsing inline arrow function handler: ${r}`,a),i=()=>{}}else r.includes("(")&&r.includes(")")?i=a=>{try{const u=r.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(u){const[,b,_]=u,K=this[b]||this.state[b];if(typeof K=="function"){let w=[];if(_.trim())try{w=new Function("event",`return [${_}]`).call(this,a)}catch(J){o.error(`Error parsing arguments for ${b}:`,J),w=[]}return K.apply(this,w)}else o.warn(`Function "${b}" not found in component context. Available functions:`,Object.keys(this).filter(w=>typeof this[w]=="function").concat(Object.keys(this.state).filter(w=>typeof this.state[w]=="function")))}else new Function("event",r).call(this,a)}catch(u){o.error(`Error executing inline event handler: ${r}`,u)}}:i=a=>{const u=this[r];if(typeof u=="function")try{return u.call(this,a)}catch(b){o.error(`Error executing event handler method: ${r}`,b)}else o.warn(`Event handler method "${r}" not found on component. Available methods on 'this':`,Object.keys(this).filter(b=>typeof this[b]=="function"))};t.addEventListener(n,i),this._eventBindings.push({key:s,element:t,event:n,listener:i})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let e=[];t.forEach(n=>{const s=n.hasAttribute("data-if");s&&e.length&&(this._conditionals.push(e),e=[]);const i=s?"if":n.hasAttribute("data-else-if")?"else-if":"else",r=i==="else"?null:n.getAttribute(i==="if"?"data-if":"data-else-if"),a=document.createComment(`ladrillos-${i}`);n.parentNode.insertBefore(a,n),n.remove(),e.push({el:n,type:i,expr:r,placeholder:a})}),e.length&&this._conditionals.push(e)}_loadStyles(){if(!v)return;const t=document.createElement("style");t.textContent=v,c?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return W(this,null,function*(){var t;for(const e of A){const n=new URL(e.src,typeof document=="undefined"&&typeof location=="undefined"?require("url").pathToFileURL(__filename).href:typeof document=="undefined"?location.href:d&&d.tagName.toUpperCase()==="SCRIPT"&&d.src||new URL("ladrillosjs.umd.js",document.baseURI).href).href;if(e.type==="module"&&(e!=null&&e.bind))try{const s=yield import(n);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):o.error(`Module ${e.src} does not export a default function or init function.`)}catch(s){o.error(`Failed to load component module ${e.src}`,s)}else e!=null&&e.bind?yield fetch(n).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(e.src,e.type)}for(const e of S)if(e.type==="module"){const n=document.createElement("script");n.type="module",n.textContent=e.content,((t=this.shadowRoot)!=null?t:this).appendChild(n)}else this._processScriptText(e.content);this._render()})}_injectScriptTag(t,e){return new Promise((n,s)=>{const i=document.createElement("script");i.src=t,e&&(i.type=e),i.onload=n,i.onerror=s,document.head.appendChild(i)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const e=this.getAttribute(t);this._handleAttributeChange(t,e)})}_setNestedState(t,e){const n=t.split(".");let s=this.state;for(let i=0;i<n.length-1;i++){const r=n[i];(typeof s[r]!="object"||s[r]===null)&&(s[r]={}),s=s[r]}s[n[n.length-1]]=e,this._render()}_bindTwoWayForElement(t){const e=t.getAttribute("data-bind"),n=t.isContentEditable,s="value"in t,i=n||s?"input":"change",r=()=>{const _=n?t.innerText:s?t.value:t.textContent;this._setNestedState(e,_)};t.addEventListener(i,r),this._eventBindings.push({element:t,event:i,listener:r});const a=s?"value":void 0,u=s?t.getAttribute("value")||`{${e}}`:n?t.innerHTML:t.textContent;this._bindings.push({element:t,key:e,attrName:a,template:u});const b=s?t.value:n?t.innerText:t.textContent;this._setNestedState(e,b)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),e={},n=(s,i,r)=>{const a=i.split(".");let u=s;for(let b=0;b<a.length-1;b++){const _=a[b];(typeof u[_]!="object"||u[_]===null)&&(u[_]={}),u=u[_]}u[a[a.length-1]]=r};t.forEach(s=>{const i=s.getAttribute("data-bind"),r=s.isContentEditable,a="value"in s,u=r?s.innerText.trim():a?s.value:s.textContent.trim();n(e,i,u)}),this.setState(e),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const e=Array.isArray(t)?t:[t],{node:n,template:s}=e[0];if(!n)return;const i={};e.forEach(({key:u})=>{var b;i[u]=(b=this.state[u])!=null?b:""});const r=this._renderTemplate(s,i);if(/<[a-z][\s\S]*>/i.test(r)){const u=document.createRange().createContextualFragment(r);n.nodeType===Node.TEXT_NODE?n.replaceWith(u):n.innerHTML=r}else n==null||n.nodeType,Node.TEXT_NODE,n.textContent=r}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:e,template:n,key:s})=>{var a;const i=(a=s.split(".").reduce((u,b)=>u==null?void 0:u[b],this.state))!=null?a:"",r=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(e,n.replace(r,i))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const n=(s=t.getAttribute("data-bind").split(".").reduce((i,r)=>i==null?void 0:i[r],this.state))!=null?s:"";t.isContentEditable?t.innerText!==n&&(t.innerText=n):"value"in t?t.value!==n&&(t.value=n):t.textContent!==n&&(t.textContent=n)})}_applyConditionals(){this._conditionals.forEach(t=>{let e=!1;t.forEach(({el:n,type:s,expr:i,placeholder:r})=>{let a=!1;if(s==="else")a=!e;else try{a=Function("state",`with(state){return(${i})}`)(this.state)}catch(u){a=!1}a&&!e?(!n.isConnected&&r.parentNode&&r.parentNode.insertBefore(n,r.nextSibling),r.remove(),e=!0):n.isConnected&&n.parentNode&&(n.parentNode.insertBefore(r,n),n.remove())})})}_renderTemplate(t,e){return t.replace(/\{\s*([-\w.]+)\s*}/g,(n,s)=>{let i=s.split(".").reduce((r,a)=>r==null?void 0:r[a],this.state);if(typeof i=="function")try{i=i.call(this)}catch(r){i=""}return i!=null?i:""})}_processScriptText(t){const e=new Set,n=new Set,s=new Set,i=(h,O)=>{let g=!1,l=!1,p=!1,x=!1;for(let T=0;T<O;T++){const E=h[T];if(x){x=!1;continue}if(E==="\\"){x=!0;continue}E==="'"&&!l&&!p?g=!g:E==='"'&&!g&&!p?l=!l:E==="`"&&!g&&!l&&(p=!p)}return g||l||p},r=(h,O,g)=>{let l=h;const p=[];let x;for(O.lastIndex=0;(x=O.exec(l))!==null;)p.push({index:x.index,length:x[0].length,originalContent:x[0],groups:x.slice(1)});for(let T=p.length-1;T>=0;T--){const E=p[T];if(!i(l,E.index)){const U=g(E.originalContent,...E.groups,E.index,l);l=l.substring(0,E.index)+U+l.substring(E.index+E.length)}}return l};Object.keys(this.state).forEach(h=>{this._isBound(h)&&s.add(h)});const a=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let u;for(;(u=a.exec(t))!==null;)e.add(u[1]);const b=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(u=b.exec(t))!==null;)e.add(u[2]);e.forEach(h=>{this._isBound(h)&&(new RegExp(`\\b${h}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${h}\\s*\\(`).test(t)||n.add(h))});let _=t;new Set([...n,...s]).forEach(h=>{_=r(_,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${h}\\b`,"g"),(g,l,p)=>`${l}${p}this.state.${h}`),_=r(_,new RegExp(`\\b${h}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(g,l)=>`this.state.${h}${l}`),_=r(_,new RegExp(`(^|\\W)${h}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(g,l,p,x,T)=>{const E=x+l.length;let U=T.substring(Math.max(0,E-10),E);return/\b(const|let|var)\s+$/.test(U)?g:`${l}this.state.${h} ${p||""}=`});const O=new RegExp(`\\b${h}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");_=r(_,O,(g,l,p)=>{if(p.substring(Math.max(0,l-11),l).endsWith("this.state."))return g;const T=p.substring(Math.max(0,l-10),l);if(/\bclass\s+$/.test(T))return g;const E=p.substring(Math.max(0,l-20),l);if(/\bextends\s+$/.test(E)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(g))return g;const tt=p.substring(Math.max(0,l-20),l),at=p.substring(l+g.length,Math.min(p.length,l+g.length+10));if(/\.state\[['"]\s*$/.test(tt)||/state\[['"]\s*$/.test(tt)||/^\s*-/.test(at))return g;const lt=p.substring(Math.max(0,l-50),l);if(/\]\s*\.\s*$/.test(lt))return g;const ut=p.lastIndexOf(`
4
- `,l)+1,ht=p.substring(ut,l);if(/\b(?:const|let|var)\s+$/.test(ht)||l>0&&p[l-1]===".")return g;let P=l+g.length;for(;P<p.length&&/\s/.test(p[P]);)P++;return P<p.length&&p[P]==="("?g:`this.state.${h}`})});let w="";e.size>0&&(w=`
1
+ (function(m,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis!="undefined"?globalThis:m||self,b(m.ladrillosjs={}))})(this,function(m){"use strict";var dt=Object.defineProperty;var it=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var ct=m=>{throw TypeError(m)};var ot=(m,b,a)=>b in m?dt(m,b,{enumerable:!0,configurable:!0,writable:!0,value:a}):m[b]=a,Y=(m,b)=>{for(var a in b||(b={}))pt.call(b,a)&&ot(m,a,b[a]);if(it)for(var a of it(b))gt.call(b,a)&&ot(m,a,b[a]);return m};var at=(m,b,a)=>b.has(m)||ct("Cannot "+a);var K=(m,b,a)=>(at(m,b,"read from private field"),a?a.call(m):b.get(m)),I=(m,b,a)=>b.has(m)?ct("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(m):b.set(m,a);var tt=(m,b,a)=>(at(m,b,"access private method"),a);var L=(m,b,a)=>new Promise((q,z)=>{var Q=W=>{try{j(a.next(W))}catch(U){z(U)}},Z=W=>{try{j(a.throw(W))}catch(U){z(U)}},j=W=>W.done?q(W.value):Promise.resolve(W.value).then(Q,Z);j((a=a.apply(m,b)).next())});var V,J,D,lt;var b=typeof document!="undefined"?document.currentScript:null;const a={log(C,...f){},error(C,...f){console.error(C,...f)},warn(C,...f){}},X=class X{constructor(){I(this,V,new Map);I(this,J,new DOMParser);this.components={}}registerComponent(f,_,w=!0){return L(this,null,function*(){var S,A,x;if(this.components[f]){a.log(`Component ${f} already registered.`);return}this.components[f]={__registering:!0};try{const v=yield L(this,null,function*(){const t=K(this,V).get(_);if(t)return t;const n=yield(yield fetch(_)).text();return K(this,V).set(_,n),n}),B=K(this,J).parseFromString(v.replace(/<!--[\s\S]*?-->/g,""),"text/html"),et=[],P=[];for(const t of B.querySelectorAll("script")){if(t.src)P.push({src:t.src,type:(S=t.type)!=null?S:null,bind:t.hasAttribute("bind")});else if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),et.push({content:e,type:(A=t.type)!=null?A:null})}t.remove()}let H="";for(const t of B.querySelectorAll("link[rel='stylesheet']"))H+=`
2
+ `+(yield tt(x=X,D,lt).call(x,`${t.href}?raw`)),t.remove();for(const t of B.querySelectorAll("style")){if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\//g,"").trim(),H+=`
3
+ `+e}t.remove()}H=H.trim(),this.components[f]={tagName:f,template:B.body.innerHTML.trim(),scripts:et,externalScripts:P,style:H},yield this._defineWebComponent(f,w),a.log(`Component ${f} registered successfully`)}catch(v){a.error(`Failed to register component ${f}:`,v),delete this.components[f]}})}registerComponents(f,_=5){return L(this,null,function*(){const w=f.map(({name:A,path:x,useShadowDOM:v})=>()=>this.registerComponent(A,x,v)),S=yield this._runWithConcurrency(w,_);return S.forEach((A,x)=>{if(A.status==="rejected"){const{name:v}=f[x];a.error(`registration failed for ${v}:`,A.reason)}}),S})}_runWithConcurrency(f,_){return L(this,null,function*(){const w=[],S=[];for(const A of f){let x;const v=A();w.push(v),x=v.then(()=>{S.splice(S.indexOf(x),1)}),S.push(x),S.length>=_&&(yield Promise.race(S))}return Promise.allSettled(w)})}_defineWebComponent(f,_){return L(this,null,function*(){const{defineWebComponent:w}=yield Promise.resolve().then(()=>ft);w(this.components[f],_)})}};V=new WeakMap,J=new WeakMap,D=new WeakSet,lt=function(f){return L(this,null,function*(){try{const _=yield fetch(f);if(!_.ok)throw new Error(`HTTP ${_.status}`);return yield _.text()}catch(_){return a.error(`Failed to fetch resource at ${f}:`,_),""}})},I(X,D);let q=X;const z=new q;function Q(C={}){let f=C;const _=new Set;return{getState(){return f},setState(w){f=Y(Y({},f),w),_.forEach(S=>S(f))},subscribe(w){return _.add(w),w(f),()=>_.delete(w)},reset(){f=C,_.forEach(w=>w(f))}}}const Z=(...C)=>z.registerComponent(...C),j=(...C)=>z.registerComponents(...C);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:Z,registerComponents:j});function W(C,f){return JSON.stringify(C,(_,w)=>typeof w=="string"?w.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):w,f).replace(/"/g,"&quot;")}const ft=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(C,f)=>{var B,ut;const{tagName:_,template:w,scripts:S,externalScripts:A,style:x}=C,P=class P extends HTMLElement{constructor(){super(),f&&this.attachShadow({mode:"open"}),this.root=f?this.shadowRoot:document,this.stringify=W;const t={};this.state=new Proxy(t,{set:(e,n,s)=>(e[n]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:e,listener:n})=>{t.removeEventListener(e,n)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(e=>{if(e.type==="attributes"){const n=e.attributeName,s=this.getAttribute(n);this._handleAttributeChange(n,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const e of t)if(e.attributeName==="contenteditable"){const n=e.target;n.isContentEditable&&n.hasAttribute("data-bind")&&this._bindTwoWayForElement(n)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,e,n){const s=new MutationObserver(t.bind(this));return s.observe(e,n),s}_handleAttributeChange(t,e){var s;if(t){const r="this.state.";t.startsWith(r)&&(t=t.slice(r.length))}const n=tt(s=P,B,ut).call(s,e);this.state[t]=n,this._render()}_loadTemplate(){f?this.shadowRoot.innerHTML=w:this.innerHTML=w,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let e;for(;e=t.nextNode();){const n=[...e.textContent.matchAll(/{([^}]+)}/g)];if(n.length){const s=n.map(([,r])=>({node:e,template:e.textContent,key:r.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(n=>{Array.from(n.attributes).forEach(s=>{const r=[...s.value.matchAll(/{([^}]+)}/g)];r.length&&r.forEach(([,i])=>{this._bindings.push({element:n,attrName:s.name,template:s.value,key:i.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(e=>{if(!e.name.startsWith("on"))return;const n=e.name.slice(2),s=e.value.trim();t.removeAttribute(e.name);let r;const i=s.trim();if(/^\([^)]*\)\s*=>/.test(i))try{const l=new Function("event",`return (${i});`).call(this);r=d=>l(d)}catch(u){a.error(`Error parsing inline arrow function handler: ${i}`,u),r=()=>{}}else i.includes("(")&&i.includes(")")?r=u=>{try{const l=i.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(l){const[,d,k]=l,G=this[d]||this.state[d];if(typeof G=="function"){let O=[];if(k.trim())try{O=new Function("event",`return [${k}]`).call(this,u)}catch(M){a.error(`Error parsing arguments for ${d}:`,M),O=[]}return G.apply(this,O)}else a.warn(`Function "${d}" not found in component context. Available functions:`,Object.keys(this).filter(O=>typeof this[O]=="function").concat(Object.keys(this.state).filter(O=>typeof this.state[O]=="function")))}else new Function("event",i).call(this,u)}catch(l){a.error(`Error executing inline event handler: ${i}`,l)}}:r=u=>{const l=this[i];if(typeof l=="function")try{return l.call(this,u)}catch(d){a.error(`Error executing event handler method: ${i}`,d)}else a.warn(`Event handler method "${i}" not found on component. Available methods on 'this':`,Object.keys(this).filter(d=>typeof this[d]=="function"))};t.addEventListener(n,r),this._eventBindings.push({key:s,element:t,event:n,listener:r})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let e=[];t.forEach(n=>{const s=n.hasAttribute("data-if");s&&e.length&&(this._conditionals.push(e),e=[]);const r=s?"if":n.hasAttribute("data-else-if")?"else-if":"else",i=r==="else"?null:n.getAttribute(r==="if"?"data-if":"data-else-if"),u=document.createComment(`ladrillos-${r}`);n.parentNode.insertBefore(u,n),n.remove(),e.push({el:n,type:r,expr:i,placeholder:u})}),e.length&&this._conditionals.push(e)}_loadStyles(){if(!x)return;const t=document.createElement("style");t.textContent=x,f?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return L(this,null,function*(){var t;for(const e of A){const n=new URL(e.src,typeof document=="undefined"&&typeof location=="undefined"?require("url").pathToFileURL(__filename).href:typeof document=="undefined"?location.href:b&&b.tagName.toUpperCase()==="SCRIPT"&&b.src||new URL("ladrillosjs.umd.js",document.baseURI).href).href;if(e.type==="module"&&(e!=null&&e.bind))try{const s=yield import(n);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):a.error(`Module ${e.src} does not export a default function or init function.`)}catch(s){a.error(`Failed to load component module ${e.src}`,s)}else e!=null&&e.bind?yield fetch(n).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(e.src,e.type)}for(const e of S)if(e.type==="module"){const n=document.createElement("script");n.type="module",n.textContent=e.content,((t=this.shadowRoot)!=null?t:this).appendChild(n)}else this._processScriptText(e.content);this._render()})}_injectScriptTag(t,e){return new Promise((n,s)=>{const r=document.createElement("script");r.src=t,e&&(r.type=e),r.onload=n,r.onerror=s,document.head.appendChild(r)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const e=this.getAttribute(t);this._handleAttributeChange(t,e)})}_setNestedState(t,e){const n=t.split(".");let s=this.state;for(let r=0;r<n.length-1;r++){const i=n[r];(typeof s[i]!="object"||s[i]===null)&&(s[i]={}),s=s[i]}s[n[n.length-1]]=e,this._render()}_bindTwoWayForElement(t){const e=t.getAttribute("data-bind"),n=t.isContentEditable,s="value"in t,r=n||s?"input":"change",i=()=>{const k=n?t.innerText:s?t.value:t.textContent;this._setNestedState(e,k)};t.addEventListener(r,i),this._eventBindings.push({element:t,event:r,listener:i});const u=s?"value":void 0,l=s?t.getAttribute("value")||`{${e}}`:n?t.innerHTML:t.textContent;this._bindings.push({element:t,key:e,attrName:u,template:l});const d=s?t.value:n?t.innerText:t.textContent;this._setNestedState(e,d)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),e={},n=(s,r,i)=>{const u=r.split(".");let l=s;for(let d=0;d<u.length-1;d++){const k=u[d];(typeof l[k]!="object"||l[k]===null)&&(l[k]={}),l=l[k]}l[u[u.length-1]]=i};t.forEach(s=>{const r=s.getAttribute("data-bind"),i=s.isContentEditable,u="value"in s,l=i?s.innerText.trim():u?s.value:s.textContent.trim();n(e,r,l)}),this.setState(e),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const e=Array.isArray(t)?t:[t],{node:n,template:s}=e[0];if(!n)return;const r={};e.forEach(({key:l})=>{var d;r[l]=(d=this.state[l])!=null?d:""});const i=this._renderTemplate(s,r);if(/<[a-z][\s\S]*>/i.test(i)){const l=document.createRange().createContextualFragment(i);n.nodeType===Node.TEXT_NODE?n.replaceWith(l):n.innerHTML=i}else n==null||n.nodeType,Node.TEXT_NODE,n.textContent=i}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:e,template:n,key:s})=>{var u;const r=(u=s.split(".").reduce((l,d)=>l==null?void 0:l[d],this.state))!=null?u:"",i=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(e,n.replace(i,r))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const n=(s=t.getAttribute("data-bind").split(".").reduce((r,i)=>r==null?void 0:r[i],this.state))!=null?s:"";t.isContentEditable?t.innerText!==n&&(t.innerText=n):"value"in t?t.value!==n&&(t.value=n):t.textContent!==n&&(t.textContent=n)})}_applyConditionals(){this._conditionals.forEach(t=>{let e=!1;t.forEach(({el:n,type:s,expr:r,placeholder:i})=>{let u=!1;if(s==="else")u=!e;else try{u=Function("state",`with(state){return(${r})}`)(this.state)}catch(l){u=!1}u&&!e?(!n.isConnected&&i.parentNode&&i.parentNode.insertBefore(n,i.nextSibling),i.remove(),e=!0):n.isConnected&&n.parentNode&&(n.parentNode.insertBefore(i,n),n.remove())})})}_renderTemplate(t,e){return t.replace(/\{\s*([-\w.]+)\s*}/g,(n,s)=>{let r=s.split(".").reduce((i,u)=>i==null?void 0:i[u],this.state);if(typeof r=="function")try{r=r.call(this)}catch(i){r=""}return r!=null?r:""})}_processScriptText(t){const e=new Set,n=new Set,s=new Set,r=new Map,i=o=>`__param_${o}_${Math.random().toString(36).substr(2,9)}`,u=(o,T)=>{let p=!1,c=!1,h=!1,E=!1;for(let g=0;g<T;g++){const y=o[g];if(E){E=!1;continue}if(y==="\\"){E=!0;continue}y==="'"&&!c&&!h?p=!p:y==='"'&&!p&&!h?c=!c:y==="`"&&!p&&!c&&(h=!h)}return p||c||h},l=(o,T,p)=>{let c=o;const h=[];let E;for(T.lastIndex=0;(E=T.exec(c))!==null;)h.push({index:E.index,length:E[0].length,originalContent:E[0],groups:E.slice(1)});for(let g=h.length-1;g>=0;g--){const y=h[g];if(!u(c,y.index)){const $=p(y.originalContent,...y.groups,y.index,c);c=c.substring(0,y.index)+$+c.substring(y.index+y.length)}}return c};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let d=t;d=l(d,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,T,p)=>{if(!p||!p.trim())return o;const c=p.split(",").map(g=>g.trim()).filter(g=>g);let h=!1;const E=c.map(g=>{const y=g.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){h=!0;const $=i(y);return r.set(y,$),g.replace(y,$)}return g});return h?o.replace(p,E.join(", ")):o}),d=l(d,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,T,p)=>{if(!p||!p.trim())return o;const c=p.split(",").map(g=>g.trim()).filter(g=>g);let h=!1;const E=c.map(g=>{const y=g.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){h=!0;const $=i(y);return r.set(y,$),g.replace(y,$)}return g});return h?o.replace(p,E.join(", ")):o});const O=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let M;for(;(M=O.exec(t))!==null;)e.add(M[1]);const ht=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(M=ht.exec(t))!==null;)e.add(M[2]);e.forEach(o=>{this._isBound(o)&&(new RegExp(`\\b${o}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${o}\\s*\\(`).test(t)||n.add(o))}),new Set([...n,...s]).forEach(o=>{d=l(d,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(p,c,h)=>`${c}${h}this.state.${o}`),d=l(d,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(p,c)=>`this.state.${o}${c}`),d=l(d,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(p,c,h,E,g)=>{const y=E+c.length;let $=g.substring(Math.max(0,y-10),y);return/\b(const|let|var)\s+$/.test($)?p:`${c}this.state.${o} ${h||""}=`});const T=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");d=l(d,T,(p,c,h)=>{if(h.substring(Math.max(0,c-11),c).endsWith("this.state."))return p;const g=h.substring(Math.max(0,c-20),c),y=h.substring(c+p.length,Math.min(h.length,c+p.length+10));if(/[{,]\s*$/.test(g)&&/^\s*:/.test(y)||r.has(o)&&h.substring(Math.max(0,c-50),c).match(/([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(p))return p;const R=h.lastIndexOf(`
4
+ `,c)+1,st=h.substring(R,c);if(/\b(?:const|let|var)\s+$/.test(st)||c>0&&h[c-1]===".")return p;let N=c+p.length;for(;N<h.length&&/\s/.test(h[N]);)N++;return N<h.length&&h[N]==="("?p:`this.state.${o}`})}),r.forEach((o,T)=>{const p=new RegExp(`\\b${T}\\b`,"g");d=l(d,p,(c,h,E)=>{const g=E.substring(0,h);if(g.includes(o)){let y=0,$=-1;for(let R=g.length-1;R>=0;R--)if(g[R]==="}")y++;else if(g[R]==="{"&&(y--,y<0)){$=R;break}if($!==-1){const R=g.substring(0,$);if(R.substring(Math.max(0,R.lastIndexOf("(",$))).includes(o)){if(E.substring(Math.max(0,h-11),h).endsWith("this.state."))return c;const rt=E.substring(h+c.length,Math.min(E.length,h+c.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(rt)?c:o}}}return c})});let F="";e.size>0&&(F=`
5
5
 
6
6
  // --- Auto-processed by LadrillosJS Framework ---
7
- `,e.forEach(h=>{w+=`if (this._isBound('${h}')) {
8
- `,w+=` if (typeof ${h} === 'function') {
9
- `,w+=` try { this.${h} = ${h}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${h} to component context.', e); }
10
- `,w+=` } else if (typeof ${h} !== 'undefined' && ${n.has(h)}) {
11
- `,w+=` if(typeof this.state.${h} === 'undefined') { try { this.state.${h} = ${h}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${h} from script.', e); } }
12
- `,w+=` }
13
- `,w+=`}
14
- `}));const J=_+w;try{new Function(J).call(this)}catch(h){o.error("Error executing component script:",h),console.error(`LadrillosJS: Error executing component script. Processed script was:
7
+ `,e.forEach(o=>{F+=`if (this._isBound('${o}')) {
8
+ `,F+=` if (typeof ${o} === 'function') {
9
+ `,F+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
10
+ `,F+=` } else if (typeof ${o} !== 'undefined' && ${n.has(o)}) {
11
+ `,F+=` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
12
+ `,F+=` }
13
+ `,F+=`}
14
+ `}));const nt=d+F;try{new Function(nt).call(this)}catch(o){a.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
15
15
  ---
16
- `+J+`
16
+ `+nt+`
17
17
  ---
18
- Error details:`,h)}}_evalExpression(t,e,n,s){try{return new Function(`return (${t});`).call(this)}catch(i){let r,a;for(;r=n.exec(e);)if(this._functions.set(s,r[0]),a=r[1].trim(),a)try{return new Function(`${a}`).bind(this)}catch(u){return o.error(u),a}return t}}_isBound(t){if(t in this.state)return!0;const e=this._eventBindings.some(i=>{if(!i.key)return!1;if(i.key===t)return!0;const r=i.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return r&&r[1]===t}),n=this._bindings.some(i=>Array.isArray(i)?i.some(r=>r.key===t||r.key.startsWith(t+".")):i.key===t||i.key.startsWith(t+".")),s=this._conditionals.some(i=>i.some(({expr:r})=>r?new RegExp(`\\b${t}\\b`).test(r):!1));return e||n||s}emit(t,e){const n=e!=null?e:this.state;this.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0}))}listen(t,e){const n=s=>e(s.detail);document.addEventListener(t,n),this._eventBindings.push({element:document,event:t,listener:n})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};B=new WeakSet,ot=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(e){return t}},N(R,B);let C=R;customElements.define(m,C),o.log(`Web component defined: <${m}></${m}>`)}},Symbol.toStringTag,{value:"Module"}));f.createStore=X,f.registerComponent=H,f.registerComponents=F,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
18
+ Error details:`,o)}}_evalExpression(t,e,n,s){try{return new Function(`return (${t});`).call(this)}catch(r){let i,u;for(;i=n.exec(e);)if(this._functions.set(s,i[0]),u=i[1].trim(),u)try{return new Function(`${u}`).bind(this)}catch(l){return a.error(l),u}return t}}_isBound(t){if(t in this.state)return!0;const e=this._eventBindings.some(r=>{if(!r.key)return!1;if(r.key===t)return!0;const i=r.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return i&&i[1]===t}),n=this._bindings.some(r=>Array.isArray(r)?r.some(i=>i.key===t||i.key.startsWith(t+".")):r.key===t||r.key.startsWith(t+".")),s=this._conditionals.some(r=>r.some(({expr:i})=>{if(!i)return!1;const u=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${u}\\b`).test(i)}));return e||n||s}emit(t,e){const n=e!=null?e:this.state;this.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0}))}listen(t,e){const n=s=>e(s.detail);document.addEventListener(t,n),this._eventBindings.push({element:document,event:t,listener:n})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};B=new WeakSet,ut=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(e){return t}},I(P,B);let v=P;customElements.define(_,v),a.log(`Web component defined: <${_}></${_}>`)}},Symbol.toStringTag,{value:"Module"}));m.createStore=Q,m.registerComponent=Z,m.registerComponents=j,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,16 @@
1
+ "use strict";var V=m=>{throw TypeError(m)};var J=(m,b,y)=>b.has(m)||V("Cannot "+y);var j=(m,b,y)=>b.has(m)?V("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(m):b.set(m,y);var I=(m,b,y)=>(J(m,b,"access private method"),y);var H=(m,b,y)=>new Promise((x,B)=>{var O=E=>{try{T(y.next(E))}catch(F){B(F)}},L=E=>{try{T(y.throw(E))}catch(F){B(F)}},T=E=>E.done?x(E.value):Promise.resolve(E.value).then(O,L);T((y=y.apply(m,b)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("./index-X9YN_DbT.js");var q=typeof document!="undefined"?document.currentScript:null;function D(m,b){return JSON.stringify(m,(y,x)=>typeof x=="string"?x.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):x,b).replace(/"/g,"&quot;")}const X=(m,b)=>{var E,Z;const{tagName:y,template:x,scripts:B,externalScripts:O,style:L}=m,W=class W extends HTMLElement{constructor(){super(),b&&this.attachShadow({mode:"open"}),this.root=b?this.shadowRoot:document,this.stringify=D;const t={};this.state=new Proxy(t,{set:(n,e,s)=>(n[e]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:n,listener:e})=>{t.removeEventListener(n,e)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(n=>{if(n.type==="attributes"){const e=n.attributeName,s=this.getAttribute(e);this._handleAttributeChange(e,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const n of t)if(n.attributeName==="contenteditable"){const e=n.target;e.isContentEditable&&e.hasAttribute("data-bind")&&this._bindTwoWayForElement(e)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,n,e){const s=new MutationObserver(t.bind(this));return s.observe(n,e),s}_handleAttributeChange(t,n){var s;if(t){const i="this.state.";t.startsWith(i)&&(t=t.slice(i.length))}const e=I(s=W,E,Z).call(s,n);this.state[t]=e,this._render()}_loadTemplate(){b?this.shadowRoot.innerHTML=x:this.innerHTML=x,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=t.nextNode();){const e=[...n.textContent.matchAll(/{([^}]+)}/g)];if(e.length){const s=e.map(([,i])=>({node:n,template:n.textContent,key:i.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(e=>{Array.from(e.attributes).forEach(s=>{const i=[...s.value.matchAll(/{([^}]+)}/g)];i.length&&i.forEach(([,r])=>{this._bindings.push({element:e,attrName:s.name,template:s.value,key:r.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(n=>{if(!n.name.startsWith("on"))return;const e=n.name.slice(2),s=n.value.trim();t.removeAttribute(n.name);let i;const r=s.trim();if(/^\([^)]*\)\s*=>/.test(r))try{const c=new Function("event",`return (${r});`).call(this);i=h=>c(h)}catch(l){$.logger.error(`Error parsing inline arrow function handler: ${r}`,l),i=()=>{}}else r.includes("(")&&r.includes(")")?i=l=>{try{const c=r.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(c){const[,h,S]=c,N=this[h]||this.state[h];if(typeof N=="function"){let C=[];if(S.trim())try{C=new Function("event",`return [${S}]`).call(this,l)}catch(R){$.logger.error(`Error parsing arguments for ${h}:`,R),C=[]}return N.apply(this,C)}else $.logger.warn(`Function "${h}" not found in component context. Available functions:`,Object.keys(this).filter(C=>typeof this[C]=="function").concat(Object.keys(this.state).filter(C=>typeof this.state[C]=="function")))}else new Function("event",r).call(this,l)}catch(c){$.logger.error(`Error executing inline event handler: ${r}`,c)}}:i=l=>{const c=this[r];if(typeof c=="function")try{return c.call(this,l)}catch(h){$.logger.error(`Error executing event handler method: ${r}`,h)}else $.logger.warn(`Event handler method "${r}" not found on component. Available methods on 'this':`,Object.keys(this).filter(h=>typeof this[h]=="function"))};t.addEventListener(e,i),this._eventBindings.push({key:s,element:t,event:e,listener:i})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let n=[];t.forEach(e=>{const s=e.hasAttribute("data-if");s&&n.length&&(this._conditionals.push(n),n=[]);const i=s?"if":e.hasAttribute("data-else-if")?"else-if":"else",r=i==="else"?null:e.getAttribute(i==="if"?"data-if":"data-else-if"),l=document.createComment(`ladrillos-${i}`);e.parentNode.insertBefore(l,e),e.remove(),n.push({el:e,type:i,expr:r,placeholder:l})}),n.length&&this._conditionals.push(n)}_loadStyles(){if(!L)return;const t=document.createElement("style");t.textContent=L,b?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return H(this,null,function*(){var t;for(const n of O){const e=new URL(n.src,typeof document=="undefined"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("webcomponent-Cga3h8cx.js",document.baseURI).href).href;if(n.type==="module"&&(n!=null&&n.bind))try{const s=yield import(e);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):$.logger.error(`Module ${n.src} does not export a default function or init function.`)}catch(s){$.logger.error(`Failed to load component module ${n.src}`,s)}else n!=null&&n.bind?yield fetch(e).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(n.src,n.type)}for(const n of B)if(n.type==="module"){const e=document.createElement("script");e.type="module",e.textContent=n.content,((t=this.shadowRoot)!=null?t:this).appendChild(e)}else this._processScriptText(n.content);this._render()})}_injectScriptTag(t,n){return new Promise((e,s)=>{const i=document.createElement("script");i.src=t,n&&(i.type=n),i.onload=e,i.onerror=s,document.head.appendChild(i)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const n=this.getAttribute(t);this._handleAttributeChange(t,n)})}_setNestedState(t,n){const e=t.split(".");let s=this.state;for(let i=0;i<e.length-1;i++){const r=e[i];(typeof s[r]!="object"||s[r]===null)&&(s[r]={}),s=s[r]}s[e[e.length-1]]=n,this._render()}_bindTwoWayForElement(t){const n=t.getAttribute("data-bind"),e=t.isContentEditable,s="value"in t,i=e||s?"input":"change",r=()=>{const S=e?t.innerText:s?t.value:t.textContent;this._setNestedState(n,S)};t.addEventListener(i,r),this._eventBindings.push({element:t,event:i,listener:r});const l=s?"value":void 0,c=s?t.getAttribute("value")||`{${n}}`:e?t.innerHTML:t.textContent;this._bindings.push({element:t,key:n,attrName:l,template:c});const h=s?t.value:e?t.innerText:t.textContent;this._setNestedState(n,h)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),n={},e=(s,i,r)=>{const l=i.split(".");let c=s;for(let h=0;h<l.length-1;h++){const S=l[h];(typeof c[S]!="object"||c[S]===null)&&(c[S]={}),c=c[S]}c[l[l.length-1]]=r};t.forEach(s=>{const i=s.getAttribute("data-bind"),r=s.isContentEditable,l="value"in s,c=r?s.innerText.trim():l?s.value:s.textContent.trim();e(n,i,c)}),this.setState(n),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const n=Array.isArray(t)?t:[t],{node:e,template:s}=n[0];if(!e)return;const i={};n.forEach(({key:c})=>{var h;i[c]=(h=this.state[c])!=null?h:""});const r=this._renderTemplate(s,i);if(/<[a-z][\s\S]*>/i.test(r)){const c=document.createRange().createContextualFragment(r);e.nodeType===Node.TEXT_NODE?e.replaceWith(c):e.innerHTML=r}else e==null||e.nodeType,Node.TEXT_NODE,e.textContent=r}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:n,template:e,key:s})=>{var l;const i=(l=s.split(".").reduce((c,h)=>c==null?void 0:c[h],this.state))!=null?l:"",r=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(n,e.replace(r,i))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const e=(s=t.getAttribute("data-bind").split(".").reduce((i,r)=>i==null?void 0:i[r],this.state))!=null?s:"";t.isContentEditable?t.innerText!==e&&(t.innerText=e):"value"in t?t.value!==e&&(t.value=e):t.textContent!==e&&(t.textContent=e)})}_applyConditionals(){this._conditionals.forEach(t=>{let n=!1;t.forEach(({el:e,type:s,expr:i,placeholder:r})=>{let l=!1;if(s==="else")l=!n;else try{l=Function("state",`with(state){return(${i})}`)(this.state)}catch(c){l=!1}l&&!n?(!e.isConnected&&r.parentNode&&r.parentNode.insertBefore(e,r.nextSibling),r.remove(),n=!0):e.isConnected&&e.parentNode&&(e.parentNode.insertBefore(r,e),e.remove())})})}_renderTemplate(t,n){return t.replace(/\{\s*([-\w.]+)\s*}/g,(e,s)=>{let i=s.split(".").reduce((r,l)=>r==null?void 0:r[l],this.state);if(typeof i=="function")try{i=i.call(this)}catch(r){i=""}return i!=null?i:""})}_processScriptText(t){const n=new Set,e=new Set,s=new Set,i=new Map,r=o=>`__param_${o}_${Math.random().toString(36).substr(2,9)}`,l=(o,w)=>{let f=!1,a=!1,u=!1,p=!1;for(let d=0;d<w;d++){const g=o[d];if(p){p=!1;continue}if(g==="\\"){p=!0;continue}g==="'"&&!a&&!u?f=!f:g==='"'&&!f&&!u?a=!a:g==="`"&&!f&&!a&&(u=!u)}return f||a||u},c=(o,w,f)=>{let a=o;const u=[];let p;for(w.lastIndex=0;(p=w.exec(a))!==null;)u.push({index:p.index,length:p[0].length,originalContent:p[0],groups:p.slice(1)});for(let d=u.length-1;d>=0;d--){const g=u[d];if(!l(a,g.index)){const _=f(g.originalContent,...g.groups,g.index,a);a=a.substring(0,g.index)+_+a.substring(g.index+g.length)}}return a};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let h=t;h=c(h,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,w,f)=>{if(!f||!f.trim())return o;const a=f.split(",").map(d=>d.trim()).filter(d=>d);let u=!1;const p=a.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){u=!0;const _=r(g);return i.set(g,_),d.replace(g,_)}return d});return u?o.replace(f,p.join(", ")):o}),h=c(h,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,w,f)=>{if(!f||!f.trim())return o;const a=f.split(",").map(d=>d.trim()).filter(d=>d);let u=!1;const p=a.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){u=!0;const _=r(g);return i.set(g,_),d.replace(g,_)}return d});return u?o.replace(f,p.join(", ")):o});const C=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let R;for(;(R=C.exec(t))!==null;)n.add(R[1]);const U=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(R=U.exec(t))!==null;)n.add(R[2]);n.forEach(o=>{this._isBound(o)&&(new RegExp(`\\b${o}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${o}\\s*\\(`).test(t)||e.add(o))}),new Set([...e,...s]).forEach(o=>{h=c(h,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(f,a,u)=>`${a}${u}this.state.${o}`),h=c(h,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(f,a)=>`this.state.${o}${a}`),h=c(h,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(f,a,u,p,d)=>{const g=p+a.length;let _=d.substring(Math.max(0,g-10),g);return/\b(const|let|var)\s+$/.test(_)?f:`${a}this.state.${o} ${u||""}=`});const w=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");h=c(h,w,(f,a,u)=>{if(u.substring(Math.max(0,a-11),a).endsWith("this.state."))return f;const d=u.substring(Math.max(0,a-20),a),g=u.substring(a+f.length,Math.min(u.length,a+f.length+10));if(/[{,]\s*$/.test(d)&&/^\s*:/.test(g)||i.has(o)&&u.substring(Math.max(0,a-50),a).match(/([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(f))return f;const v=u.lastIndexOf(`
2
+ `,a)+1,M=u.substring(v,a);if(/\b(?:const|let|var)\s+$/.test(M)||a>0&&u[a-1]===".")return f;let k=a+f.length;for(;k<u.length&&/\s/.test(u[k]);)k++;return k<u.length&&u[k]==="("?f:`this.state.${o}`})}),i.forEach((o,w)=>{const f=new RegExp(`\\b${w}\\b`,"g");h=c(h,f,(a,u,p)=>{const d=p.substring(0,u);if(d.includes(o)){let g=0,_=-1;for(let v=d.length-1;v>=0;v--)if(d[v]==="}")g++;else if(d[v]==="{"&&(g--,g<0)){_=v;break}if(_!==-1){const v=d.substring(0,_);if(v.substring(Math.max(0,v.lastIndexOf("(",_))).includes(o)){if(p.substring(Math.max(0,u-11),u).endsWith("this.state."))return a;const P=p.substring(u+a.length,Math.min(p.length,u+a.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(P)?a:o}}}return a})});let A="";n.size>0&&(A=`
3
+
4
+ // --- Auto-processed by LadrillosJS Framework ---
5
+ `,n.forEach(o=>{A+=`if (this._isBound('${o}')) {
6
+ `,A+=` if (typeof ${o} === 'function') {
7
+ `,A+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
8
+ `,A+=` } else if (typeof ${o} !== 'undefined' && ${e.has(o)}) {
9
+ `,A+=` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
10
+ `,A+=` }
11
+ `,A+=`}
12
+ `}));const z=h+A;try{new Function(z).call(this)}catch(o){$.logger.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
13
+ ---
14
+ `+z+`
15
+ ---
16
+ Error details:`,o)}}_evalExpression(t,n,e,s){try{return new Function(`return (${t});`).call(this)}catch(i){let r,l;for(;r=e.exec(n);)if(this._functions.set(s,r[0]),l=r[1].trim(),l)try{return new Function(`${l}`).bind(this)}catch(c){return $.logger.error(c),l}return t}}_isBound(t){if(t in this.state)return!0;const n=this._eventBindings.some(i=>{if(!i.key)return!1;if(i.key===t)return!0;const r=i.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return r&&r[1]===t}),e=this._bindings.some(i=>Array.isArray(i)?i.some(r=>r.key===t||r.key.startsWith(t+".")):i.key===t||i.key.startsWith(t+".")),s=this._conditionals.some(i=>i.some(({expr:r})=>{if(!r)return!1;const l=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${l}\\b`).test(r)}));return n||e||s}emit(t,n){const e=n!=null?n:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}listen(t,n){const e=s=>n(s.detail);document.addEventListener(t,e),this._eventBindings.push({element:document,event:t,listener:e})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};E=new WeakSet,Z=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(n){return t}},j(W,E);let T=W;customElements.define(y,T),$.logger.log(`Web component defined: <${y}></${y}>`)};exports.defineWebComponent=X;
@@ -1,38 +1,38 @@
1
- var z = (m) => {
1
+ var q = (m) => {
2
2
  throw TypeError(m);
3
3
  };
4
- var P = (m, p, y) => p.has(m) || z("Cannot " + y);
5
- var q = (m, p, y) => p.has(m) ? z("Cannot add the same private member more than once") : p instanceof WeakSet ? p.add(m) : p.set(m, y);
6
- var N = (m, p, y) => (P(m, p, "access private method"), y);
7
- var V = (m, p, y) => new Promise((v, C) => {
8
- var L = (_) => {
4
+ var J = (m, b, y) => b.has(m) || q("Cannot " + y);
5
+ var P = (m, b, y) => b.has(m) ? q("Cannot add the same private member more than once") : b instanceof WeakSet ? b.add(m) : b.set(m, y);
6
+ var j = (m, b, y) => (J(m, b, "access private method"), y);
7
+ var H = (m, b, y) => new Promise((x, B) => {
8
+ var O = (E) => {
9
9
  try {
10
- S(y.next(_));
11
- } catch (W) {
12
- C(W);
10
+ T(y.next(E));
11
+ } catch (F) {
12
+ B(F);
13
13
  }
14
- }, T = (_) => {
14
+ }, L = (E) => {
15
15
  try {
16
- S(y.throw(_));
17
- } catch (W) {
18
- C(W);
16
+ T(y.throw(E));
17
+ } catch (F) {
18
+ B(F);
19
19
  }
20
- }, S = (_) => _.done ? v(_.value) : Promise.resolve(_.value).then(L, T);
21
- S((y = y.apply(m, p)).next());
20
+ }, T = (E) => E.done ? x(E.value) : Promise.resolve(E.value).then(O, L);
21
+ T((y = y.apply(m, b)).next());
22
22
  });
23
- import { l as w } from "./index-CYYvcgtW.mjs";
24
- function M(m, p) {
23
+ import { l as w } from "./index-D_dHFObN.mjs";
24
+ function D(m, b) {
25
25
  return JSON.stringify(
26
26
  m,
27
- (y, v) => typeof v == "string" ? v.replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r") : v,
28
- p
27
+ (y, x) => typeof x == "string" ? x.replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r") : x,
28
+ b
29
29
  ).replace(/"/g, "&quot;");
30
30
  }
31
- const K = (m, p) => {
32
- var _, H;
33
- const { tagName: y, template: v, scripts: C, externalScripts: L, style: T } = m, k = class k extends HTMLElement {
31
+ const G = (m, b) => {
32
+ var E, Z;
33
+ const { tagName: y, template: x, scripts: B, externalScripts: O, style: L } = m, W = class W extends HTMLElement {
34
34
  constructor() {
35
- super(), p && this.attachShadow({ mode: "open" }), this.root = p ? this.shadowRoot : document, this.stringify = M;
35
+ super(), b && this.attachShadow({ mode: "open" }), this.root = b ? this.shadowRoot : document, this.stringify = D;
36
36
  const t = {};
37
37
  this.state = new Proxy(t, {
38
38
  set: (n, e, s) => (n[e] = s, this._render(), !0)
@@ -91,12 +91,12 @@ const K = (m, p) => {
91
91
  const i = "this.state.";
92
92
  t.startsWith(i) && (t = t.slice(i.length));
93
93
  }
94
- const e = N(s = k, _, H).call(s, n);
94
+ const e = j(s = W, E, Z).call(s, n);
95
95
  this.state[t] = e, this._render();
96
96
  }
97
97
  // sets template to innerHTML or shadowRoot.innerHTML
98
98
  _loadTemplate() {
99
- p ? this.shadowRoot.innerHTML = v : this.innerHTML = v, this._scanBindings();
99
+ b ? this.shadowRoot.innerHTML = x : this.innerHTML = x, this._scanBindings();
100
100
  }
101
101
  // scans the template for bindings and event handlers
102
102
  // and stores them in this._bindings and this._eventBindings
@@ -146,68 +146,68 @@ const K = (m, p) => {
146
146
  if (/^\([^)]*\)\s*=>/.test(r))
147
147
  try {
148
148
  const c = new Function("event", `return (${r});`).call(this);
149
- i = (f) => c(f);
150
- } catch (o) {
149
+ i = (u) => c(u);
150
+ } catch (l) {
151
151
  w.error(
152
152
  `Error parsing inline arrow function handler: ${r}`,
153
- o
153
+ l
154
154
  ), i = () => {
155
155
  };
156
156
  }
157
- else r.includes("(") && r.includes(")") ? i = (o) => {
157
+ else r.includes("(") && r.includes(")") ? i = (l) => {
158
158
  try {
159
159
  const c = r.match(
160
160
  /^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/
161
161
  );
162
162
  if (c) {
163
- const [, f, d] = c, O = this[f] || this.state[f];
164
- if (typeof O == "function") {
165
- let g = [];
166
- if (d.trim())
163
+ const [, u, S] = c, N = this[u] || this.state[u];
164
+ if (typeof N == "function") {
165
+ let A = [];
166
+ if (S.trim())
167
167
  try {
168
- g = new Function(
168
+ A = new Function(
169
169
  "event",
170
- `return [${d}]`
171
- ).call(this, o);
172
- } catch (B) {
170
+ `return [${S}]`
171
+ ).call(this, l);
172
+ } catch (k) {
173
173
  w.error(
174
- `Error parsing arguments for ${f}:`,
175
- B
176
- ), g = [];
174
+ `Error parsing arguments for ${u}:`,
175
+ k
176
+ ), A = [];
177
177
  }
178
- return O.apply(this, g);
178
+ return N.apply(this, A);
179
179
  } else
180
180
  w.warn(
181
- `Function "${f}" not found in component context. Available functions:`,
182
- Object.keys(this).filter((g) => typeof this[g] == "function").concat(
181
+ `Function "${u}" not found in component context. Available functions:`,
182
+ Object.keys(this).filter((A) => typeof this[A] == "function").concat(
183
183
  Object.keys(this.state).filter(
184
- (g) => typeof this.state[g] == "function"
184
+ (A) => typeof this.state[A] == "function"
185
185
  )
186
186
  )
187
187
  );
188
188
  } else
189
- new Function("event", r).call(this, o);
189
+ new Function("event", r).call(this, l);
190
190
  } catch (c) {
191
191
  w.error(
192
192
  `Error executing inline event handler: ${r}`,
193
193
  c
194
194
  );
195
195
  }
196
- } : i = (o) => {
196
+ } : i = (l) => {
197
197
  const c = this[r];
198
198
  if (typeof c == "function")
199
199
  try {
200
- return c.call(this, o);
201
- } catch (f) {
200
+ return c.call(this, l);
201
+ } catch (u) {
202
202
  w.error(
203
203
  `Error executing event handler method: ${r}`,
204
- f
204
+ u
205
205
  );
206
206
  }
207
207
  else
208
208
  w.warn(
209
209
  `Event handler method "${r}" not found on component. Available methods on 'this':`,
210
- Object.keys(this).filter((f) => typeof this[f] == "function")
210
+ Object.keys(this).filter((u) => typeof this[u] == "function")
211
211
  );
212
212
  };
213
213
  t.addEventListener(e, i), this._eventBindings.push({
@@ -230,22 +230,22 @@ const K = (m, p) => {
230
230
  t.forEach((e) => {
231
231
  const s = e.hasAttribute("data-if");
232
232
  s && n.length && (this._conditionals.push(n), n = []);
233
- const i = s ? "if" : e.hasAttribute("data-else-if") ? "else-if" : "else", r = i === "else" ? null : e.getAttribute(i === "if" ? "data-if" : "data-else-if"), o = document.createComment(`ladrillos-${i}`);
234
- e.parentNode.insertBefore(o, e), e.remove(), n.push({ el: e, type: i, expr: r, placeholder: o });
233
+ const i = s ? "if" : e.hasAttribute("data-else-if") ? "else-if" : "else", r = i === "else" ? null : e.getAttribute(i === "if" ? "data-if" : "data-else-if"), l = document.createComment(`ladrillos-${i}`);
234
+ e.parentNode.insertBefore(l, e), e.remove(), n.push({ el: e, type: i, expr: r, placeholder: l });
235
235
  }), n.length && this._conditionals.push(n);
236
236
  }
237
237
  // loads the styles into the shadowRoot or document head
238
238
  _loadStyles() {
239
- if (!T) return;
239
+ if (!L) return;
240
240
  const t = document.createElement("style");
241
- t.textContent = T, p ? this.root.appendChild(t) : this.root.head.appendChild(t);
241
+ t.textContent = L, b ? this.root.appendChild(t) : this.root.head.appendChild(t);
242
242
  }
243
243
  // loads the external scripts and inline scripts
244
244
  // and binds them to the component context
245
245
  _loadScript() {
246
- return V(this, null, function* () {
246
+ return H(this, null, function* () {
247
247
  var t;
248
- for (const n of L) {
248
+ for (const n of O) {
249
249
  const e = new URL(n.src, import.meta.url).href;
250
250
  if (n.type === "module" && (n != null && n.bind))
251
251
  try {
@@ -262,7 +262,7 @@ const K = (m, p) => {
262
262
  )
263
263
  ) : yield this._injectScriptTag(n.src, n.type);
264
264
  }
265
- for (const n of C)
265
+ for (const n of B)
266
266
  if (n.type === "module") {
267
267
  const e = document.createElement("script");
268
268
  e.type = "module", e.textContent = n.content, ((t = this.shadowRoot) != null ? t : this).appendChild(e);
@@ -302,29 +302,29 @@ const K = (m, p) => {
302
302
  }
303
303
  _bindTwoWayForElement(t) {
304
304
  const n = t.getAttribute("data-bind"), e = t.isContentEditable, s = "value" in t, i = e || s ? "input" : "change", r = () => {
305
- const d = e ? t.innerText : s ? t.value : t.textContent;
306
- this._setNestedState(n, d);
305
+ const S = e ? t.innerText : s ? t.value : t.textContent;
306
+ this._setNestedState(n, S);
307
307
  };
308
308
  t.addEventListener(i, r), this._eventBindings.push({ element: t, event: i, listener: r });
309
- const o = s ? "value" : void 0, c = s ? t.getAttribute("value") || `{${n}}` : e ? t.innerHTML : t.textContent;
310
- this._bindings.push({ element: t, key: n, attrName: o, template: c });
311
- const f = s ? t.value : e ? t.innerText : t.textContent;
312
- this._setNestedState(n, f);
309
+ const l = s ? "value" : void 0, c = s ? t.getAttribute("value") || `{${n}}` : e ? t.innerHTML : t.textContent;
310
+ this._bindings.push({ element: t, key: n, attrName: l, template: c });
311
+ const u = s ? t.value : e ? t.innerText : t.textContent;
312
+ this._setNestedState(n, u);
313
313
  }
314
314
  // sets up two-way bindings for editable elements
315
315
  // e.g. <input data-bind="name" value="{name}">
316
316
  _setupTwoWayBindings() {
317
317
  const t = this.root.querySelectorAll("[data-bind]"), n = {}, e = (s, i, r) => {
318
- const o = i.split(".");
318
+ const l = i.split(".");
319
319
  let c = s;
320
- for (let f = 0; f < o.length - 1; f++) {
321
- const d = o[f];
322
- (typeof c[d] != "object" || c[d] === null) && (c[d] = {}), c = c[d];
320
+ for (let u = 0; u < l.length - 1; u++) {
321
+ const S = l[u];
322
+ (typeof c[S] != "object" || c[S] === null) && (c[S] = {}), c = c[S];
323
323
  }
324
- c[o[o.length - 1]] = r;
324
+ c[l[l.length - 1]] = r;
325
325
  };
326
326
  t.forEach((s) => {
327
- const i = s.getAttribute("data-bind"), r = s.isContentEditable, o = "value" in s, c = r ? s.innerText.trim() : o ? s.value : s.textContent.trim();
327
+ const i = s.getAttribute("data-bind"), r = s.isContentEditable, l = "value" in s, c = r ? s.innerText.trim() : l ? s.value : s.textContent.trim();
328
328
  e(n, i, c);
329
329
  }), this.setState(n), t.forEach((s) => {
330
330
  this._bindTwoWayForElement(s);
@@ -338,8 +338,8 @@ const K = (m, p) => {
338
338
  if (!e) return;
339
339
  const i = {};
340
340
  n.forEach(({ key: c }) => {
341
- var f;
342
- i[c] = (f = this.state[c]) != null ? f : "";
341
+ var u;
342
+ i[c] = (u = this.state[c]) != null ? u : "";
343
343
  });
344
344
  const r = this._renderTemplate(s, i);
345
345
  if (/<[a-z][\s\S]*>/i.test(r)) {
@@ -348,8 +348,8 @@ const K = (m, p) => {
348
348
  } else
349
349
  e == null || e.nodeType, Node.TEXT_NODE, e.textContent = r;
350
350
  }), this._bindings.filter((t) => t.element).forEach(({ element: t, attrName: n, template: e, key: s }) => {
351
- var o;
352
- const i = (o = s.split(".").reduce((c, f) => c == null ? void 0 : c[f], this.state)) != null ? o : "", r = new RegExp(`\\{\\s*${s}\\s*\\}`, "g");
351
+ var l;
352
+ const i = (l = s.split(".").reduce((c, u) => c == null ? void 0 : c[u], this.state)) != null ? l : "", r = new RegExp(`\\{\\s*${s}\\s*\\}`, "g");
353
353
  t.setAttribute(n, e.replace(r, i));
354
354
  }), this.root.querySelectorAll("[data-bind]").forEach((t) => {
355
355
  var s;
@@ -362,19 +362,19 @@ const K = (m, p) => {
362
362
  this._conditionals.forEach((t) => {
363
363
  let n = !1;
364
364
  t.forEach(({ el: e, type: s, expr: i, placeholder: r }) => {
365
- let o = !1;
365
+ let l = !1;
366
366
  if (s === "else")
367
- o = !n;
367
+ l = !n;
368
368
  else
369
369
  try {
370
- o = Function(
370
+ l = Function(
371
371
  "state",
372
372
  `with(state){return(${i})}`
373
373
  )(this.state);
374
374
  } catch (c) {
375
- o = !1;
375
+ l = !1;
376
376
  }
377
- o && !n ? (!e.isConnected && r.parentNode && r.parentNode.insertBefore(e, r.nextSibling), r.remove(), n = !0) : e.isConnected && e.parentNode && (e.parentNode.insertBefore(r, e), e.remove());
377
+ l && !n ? (!e.isConnected && r.parentNode && r.parentNode.insertBefore(e, r.nextSibling), r.remove(), n = !0) : e.isConnected && e.parentNode && (e.parentNode.insertBefore(r, e), e.remove());
378
378
  });
379
379
  });
380
380
  }
@@ -382,7 +382,7 @@ const K = (m, p) => {
382
382
  // e.g. {name} => "John Doe"
383
383
  _renderTemplate(t, n) {
384
384
  return t.replace(/\{\s*([-\w.]+)\s*}/g, (e, s) => {
385
- let i = s.split(".").reduce((r, o) => r == null ? void 0 : r[o], this.state);
385
+ let i = s.split(".").reduce((r, l) => r == null ? void 0 : r[l], this.state);
386
386
  if (typeof i == "function")
387
387
  try {
388
388
  i = i.call(this);
@@ -395,125 +395,164 @@ const K = (m, p) => {
395
395
  /**
396
396
  * 1. Identifies top-level function declarations (e.g., `function foo(){}` or `const foo = ()=>{}`).
397
397
  * 2. Identifies top-level variable declarations (e.g., `const bar = 123;`).
398
- * 3. Transforms increment/decrement operations on bound variables to use this.state
399
- * 4. Transforms references to attribute-based state variables
400
- * 5. Appends assignments to `this` for bound functions (e.g., `this.foo = foo;`).
401
- * 6. Appends initialization for `this.state` for bound variables if not already set in state (e.g., `if(typeof this.state.bar === 'undefined') this.state.bar = bar;`).
402
- * 7. Executes the combined script in the component's context (`this`).
398
+ * 3. Renames function parameters that conflict with bound variables to avoid shadowing.
399
+ * 4. Transforms increment/decrement operations on bound variables to use this.state
400
+ * 5. Transforms references to attribute-based state variables
401
+ * 6. Replaces renamed parameter references with unique names
402
+ * 7. Appends assignments to `this` for bound functions (e.g., `this.foo = foo;`).
403
+ * 8. Appends initialization for `this.state` for bound variables if not already set in state (e.g., `if(typeof this.state.bar === 'undefined') this.state.bar = bar;`).
404
+ * 9. Executes the combined script in the component's context (`this`).
403
405
  */
404
406
  _processScriptText(t) {
405
- const n = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = (l, A) => {
406
- let u = !1, a = !1, h = !1, E = !1;
407
- for (let $ = 0; $ < A; $++) {
408
- const b = l[$];
409
- if (E) {
410
- E = !1;
407
+ const n = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), r = (o) => `__param_${o}_${Math.random().toString(36).substr(2, 9)}`, l = (o, $) => {
408
+ let f = !1, a = !1, h = !1, g = !1;
409
+ for (let d = 0; d < $; d++) {
410
+ const p = o[d];
411
+ if (g) {
412
+ g = !1;
411
413
  continue;
412
414
  }
413
- if (b === "\\") {
414
- E = !0;
415
+ if (p === "\\") {
416
+ g = !0;
415
417
  continue;
416
418
  }
417
- b === "'" && !a && !h ? u = !u : b === '"' && !u && !h ? a = !a : b === "`" && !u && !a && (h = !h);
419
+ p === "'" && !a && !h ? f = !f : p === '"' && !f && !h ? a = !a : p === "`" && !f && !a && (h = !h);
418
420
  }
419
- return u || a || h;
420
- }, r = (l, A, u) => {
421
- let a = l;
421
+ return f || a || h;
422
+ }, c = (o, $, f) => {
423
+ let a = o;
422
424
  const h = [];
423
- let E;
424
- for (A.lastIndex = 0; (E = A.exec(a)) !== null; )
425
+ let g;
426
+ for ($.lastIndex = 0; (g = $.exec(a)) !== null; )
425
427
  h.push({
426
- index: E.index,
427
- length: E[0].length,
428
- originalContent: E[0],
429
- groups: E.slice(1)
430
- // Capture groups
428
+ index: g.index,
429
+ length: g[0].length,
430
+ originalContent: g[0],
431
+ groups: g.slice(1)
431
432
  });
432
- for (let $ = h.length - 1; $ >= 0; $--) {
433
- const b = h[$];
434
- if (!i(a, b.index)) {
435
- const R = u(
436
- b.originalContent,
437
- ...b.groups,
438
- b.index,
433
+ for (let d = h.length - 1; d >= 0; d--) {
434
+ const p = h[d];
435
+ if (!l(a, p.index)) {
436
+ const _ = f(
437
+ p.originalContent,
438
+ ...p.groups,
439
+ p.index,
439
440
  a
440
441
  );
441
- a = a.substring(0, b.index) + R + a.substring(b.index + b.length);
442
+ a = a.substring(0, p.index) + _ + a.substring(p.index + p.length);
442
443
  }
443
444
  }
444
445
  return a;
445
446
  };
446
- Object.keys(this.state).forEach((l) => {
447
- this._isBound(l) && s.add(l);
447
+ Object.keys(this.state).forEach((o) => {
448
+ this._isBound(o) && s.add(o);
448
449
  });
449
- const o = /\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;
450
- let c;
451
- for (; (c = o.exec(t)) !== null; )
452
- n.add(c[1]);
453
- const f = /\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;
454
- for (; (c = f.exec(t)) !== null; )
455
- n.add(c[2]);
456
- n.forEach((l) => {
457
- this._isBound(l) && (new RegExp(
458
- `\\b${l}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,
450
+ let u = t;
451
+ u = c(
452
+ u,
453
+ /\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,
454
+ (o, $, f) => {
455
+ if (!f || !f.trim()) return o;
456
+ const a = f.split(",").map((d) => d.trim()).filter((d) => d);
457
+ let h = !1;
458
+ const g = a.map((d) => {
459
+ const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
460
+ if (this._isBound(p)) {
461
+ h = !0;
462
+ const _ = r(p);
463
+ return i.set(p, _), d.replace(p, _);
464
+ }
465
+ return d;
466
+ });
467
+ return h ? o.replace(f, g.join(", ")) : o;
468
+ }
469
+ ), u = c(
470
+ u,
471
+ /\bfunction\s+(\w+)\s*\(([^)]*)\)/g,
472
+ (o, $, f) => {
473
+ if (!f || !f.trim()) return o;
474
+ const a = f.split(",").map((d) => d.trim()).filter((d) => d);
475
+ let h = !1;
476
+ const g = a.map((d) => {
477
+ const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
478
+ if (this._isBound(p)) {
479
+ h = !0;
480
+ const _ = r(p);
481
+ return i.set(p, _), d.replace(p, _);
482
+ }
483
+ return d;
484
+ });
485
+ return h ? o.replace(f, g.join(", ")) : o;
486
+ }
487
+ );
488
+ const A = /\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;
489
+ let k;
490
+ for (; (k = A.exec(t)) !== null; )
491
+ n.add(k[1]);
492
+ const I = /\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;
493
+ for (; (k = I.exec(t)) !== null; )
494
+ n.add(k[2]);
495
+ n.forEach((o) => {
496
+ this._isBound(o) && (new RegExp(
497
+ `\\b${o}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,
459
498
  "g"
460
- ).test(t) || new RegExp(`\\bfunction\\s+${l}\\s*\\(`).test(t) || e.add(l));
461
- });
462
- let d = t;
463
- (/* @__PURE__ */ new Set([
499
+ ).test(t) || new RegExp(`\\bfunction\\s+${o}\\s*\\(`).test(t) || e.add(o));
500
+ }), (/* @__PURE__ */ new Set([
464
501
  ...e,
465
502
  ...s
466
- ])).forEach((l) => {
467
- d = r(
468
- d,
469
- new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${l}\\b`, "g"),
470
- (u, a, h) => `${a}${h}this.state.${l}`
471
- ), d = r(
472
- d,
473
- new RegExp(`\\b${l}\\s*(\\+\\+|\\-\\-)(?!\\.)`, "g"),
474
- // (?!\\.) to avoid issues if varName itself could be part of obj.prop++
475
- (u, a) => `this.state.${l}${a}`
476
- ), d = r(
477
- d,
503
+ ])).forEach((o) => {
504
+ u = c(
505
+ u,
506
+ new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`, "g"),
507
+ (f, a, h) => `${a}${h}this.state.${o}`
508
+ ), u = c(
509
+ u,
510
+ new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`, "g"),
511
+ (f, a) => `this.state.${o}${a}`
512
+ ), u = c(
513
+ u,
478
514
  new RegExp(
479
- `(^|\\W)${l}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,
515
+ `(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,
480
516
  "g"
481
517
  ),
482
- (u, a, h, E, $) => {
483
- const b = E + a.length;
484
- let R = $.substring(
485
- Math.max(0, b - 10),
486
- b
518
+ (f, a, h, g, d) => {
519
+ const p = g + a.length;
520
+ let _ = d.substring(
521
+ Math.max(0, p - 10),
522
+ p
487
523
  );
488
- return /\b(const|let|var)\s+$/.test(R) ? u : `${a}this.state.${l} ${h || ""}=`;
524
+ return /\b(const|let|var)\s+$/.test(_) ? f : `${a}this.state.${o} ${h || ""}=`;
489
525
  }
490
526
  );
491
- const A = new RegExp(
492
- `\\b${l}\\b(?!\\s*[+\\-*/%&|^]?=)`,
493
- // Your original regex for this part
527
+ const $ = new RegExp(
528
+ `\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,
494
529
  "g"
495
530
  );
496
- d = r(
497
- d,
498
- A,
499
- // This is your existing callback logic for referenceRegex
500
- (u, a, h) => {
531
+ u = c(
532
+ u,
533
+ $,
534
+ (f, a, h) => {
501
535
  if (h.substring(
502
536
  Math.max(0, a - 11),
503
537
  a
504
538
  ).endsWith("this.state."))
505
- return u;
506
- const $ = h.substring(
507
- Math.max(0, a - 10),
508
- a
509
- );
510
- if (/\bclass\s+$/.test($))
511
- return u;
512
- const b = h.substring(
539
+ return f;
540
+ const d = h.substring(
513
541
  Math.max(0, a - 20),
514
542
  a
543
+ ), p = h.substring(
544
+ a + f.length,
545
+ Math.min(
546
+ h.length,
547
+ a + f.length + 10
548
+ )
515
549
  );
516
- if (/\bextends\s+$/.test(b) || [
550
+ if (/[{,]\s*$/.test(d) && /^\s*:/.test(p) || i.has(o) && h.substring(
551
+ Math.max(0, a - 50),
552
+ a
553
+ ).match(
554
+ /([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/
555
+ ) || [
517
556
  "break",
518
557
  "case",
519
558
  "catch",
@@ -548,64 +587,82 @@ const K = (m, p) => {
548
587
  "while",
549
588
  "with",
550
589
  "yield"
551
- ].includes(u))
552
- return u;
553
- const F = h.substring(
554
- Math.max(0, a - 20),
555
- a
556
- ), Z = h.substring(
557
- a + u.length,
558
- Math.min(
559
- h.length,
560
- a + u.length + 10
561
- )
562
- );
563
- if (/\.state\[['"]\s*$/.test(F) || /state\[['"]\s*$/.test(F) || /^\s*-/.test(Z))
564
- return u;
565
- const j = h.substring(
566
- Math.max(0, a - 50),
567
- a
568
- );
569
- if (/\]\s*\.\s*$/.test(j))
570
- return u;
571
- const I = h.lastIndexOf(`
572
- `, a) + 1, J = h.substring(I, a);
573
- if (/\b(?:const|let|var)\s+$/.test(J) || a > 0 && h[a - 1] === ".")
574
- return u;
575
- let x = a + u.length;
576
- for (; x < h.length && /\s/.test(h[x]); )
577
- x++;
578
- return x < h.length && h[x] === "(" ? u : `this.state.${l}`;
590
+ ].includes(f))
591
+ return f;
592
+ const v = h.lastIndexOf(`
593
+ `, a) + 1, M = h.substring(v, a);
594
+ if (/\b(?:const|let|var)\s+$/.test(M) || a > 0 && h[a - 1] === ".")
595
+ return f;
596
+ let R = a + f.length;
597
+ for (; R < h.length && /\s/.test(h[R]); )
598
+ R++;
599
+ return R < h.length && h[R] === "(" ? f : `this.state.${o}`;
600
+ }
601
+ );
602
+ }), i.forEach((o, $) => {
603
+ const f = new RegExp(`\\b${$}\\b`, "g");
604
+ u = c(
605
+ u,
606
+ f,
607
+ (a, h, g) => {
608
+ const d = g.substring(0, h);
609
+ if (d.includes(o)) {
610
+ let p = 0, _ = -1;
611
+ for (let v = d.length - 1; v >= 0; v--)
612
+ if (d[v] === "}") p++;
613
+ else if (d[v] === "{" && (p--, p < 0)) {
614
+ _ = v;
615
+ break;
616
+ }
617
+ if (_ !== -1) {
618
+ const v = d.substring(0, _);
619
+ if (v.substring(
620
+ Math.max(0, v.lastIndexOf("(", _))
621
+ ).includes(o)) {
622
+ if (g.substring(
623
+ Math.max(0, h - 11),
624
+ h
625
+ ).endsWith("this.state."))
626
+ return a;
627
+ const V = g.substring(
628
+ h + a.length,
629
+ Math.min(g.length, h + a.length + 20)
630
+ );
631
+ return /^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(V) ? a : o;
632
+ }
633
+ }
634
+ }
635
+ return a;
579
636
  }
580
637
  );
581
638
  });
582
- let g = "";
583
- n.size > 0 && (g = `
639
+ let C = "";
640
+ n.size > 0 && (C = `
584
641
 
585
642
  // --- Auto-processed by LadrillosJS Framework ---
586
- `, n.forEach((l) => {
587
- g += `if (this._isBound('${l}')) {
588
- `, g += ` if (typeof ${l} === 'function') {
589
- `, g += ` try { this.${l} = ${l}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${l} to component context.', e); }
590
- `, g += ` } else if (typeof ${l} !== 'undefined' && ${e.has(
591
- l
643
+ `, n.forEach((o) => {
644
+ C += `if (this._isBound('${o}')) {
645
+ `, C += ` if (typeof ${o} === 'function') {
646
+ `, C += ` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
647
+ `, C += ` } else if (typeof ${o} !== 'undefined' && ${e.has(
648
+ o
592
649
  )}) {
593
- `, g += ` if(typeof this.state.${l} === 'undefined') { try { this.state.${l} = ${l}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${l} from script.', e); } }
594
- `, g += ` }
595
- `, g += `}
650
+ `, C += ` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
651
+ `, C += ` }
652
+ `, C += `}
596
653
  `;
597
654
  }));
598
- const B = d + g;
655
+ const z = u + C;
599
656
  try {
600
- new Function(B).call(this);
601
- } catch (l) {
602
- w.error("Error executing component script:", l), console.error(
657
+ new Function(z).call(this);
658
+ } catch (o) {
659
+ w.error("Error executing component script:", o), console.error(
603
660
  `LadrillosJS: Error executing component script. Processed script was:
604
661
  ---
605
- ` + B + `
662
+ ` + z + `
606
663
  ---
607
664
  Error details:`,
608
- l
665
+ o
609
666
  );
610
667
  }
611
668
  }
@@ -615,13 +672,13 @@ Error details:`,
615
672
  try {
616
673
  return new Function(`return (${t});`).call(this);
617
674
  } catch (i) {
618
- let r, o;
675
+ let r, l;
619
676
  for (; r = e.exec(n); )
620
- if (this._functions.set(s, r[0]), o = r[1].trim(), o)
677
+ if (this._functions.set(s, r[0]), l = r[1].trim(), l)
621
678
  try {
622
- return new Function(`${o}`).bind(this);
679
+ return new Function(`${l}`).bind(this);
623
680
  } catch (c) {
624
- return w.error(c), o;
681
+ return w.error(c), l;
625
682
  }
626
683
  return t;
627
684
  }
@@ -641,7 +698,11 @@ Error details:`,
641
698
  );
642
699
  return r && r[1] === t;
643
700
  }), e = this._bindings.some((i) => Array.isArray(i) ? i.some((r) => r.key === t || r.key.startsWith(t + ".")) : i.key === t || i.key.startsWith(t + ".")), s = this._conditionals.some(
644
- (i) => i.some(({ expr: r }) => r ? new RegExp(`\\b${t}\\b`).test(r) : !1)
701
+ (i) => i.some(({ expr: r }) => {
702
+ if (!r) return !1;
703
+ const l = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
704
+ return new RegExp(`\\b${l}\\b`).test(r);
705
+ })
645
706
  );
646
707
  return n || e || s;
647
708
  }
@@ -691,7 +752,7 @@ Error details:`,
691
752
  return this.root.querySelectorAll(t);
692
753
  }
693
754
  };
694
- _ = new WeakSet(), H = function(t) {
755
+ E = new WeakSet(), Z = function(t) {
695
756
  if (t === "") return null;
696
757
  if (t !== "undefined")
697
758
  try {
@@ -699,10 +760,10 @@ Error details:`,
699
760
  } catch (n) {
700
761
  return t;
701
762
  }
702
- }, q(k, _);
703
- let S = k;
704
- customElements.define(y, S), w.log(`Web component defined: <${y}></${y}>`);
763
+ }, P(W, E);
764
+ let T = W;
765
+ customElements.define(y, T), w.log(`Web component defined: <${y}></${y}>`);
705
766
  };
706
767
  export {
707
- K as defineWebComponent
768
+ G as defineWebComponent
708
769
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ladrillosjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A lightweight, zero-dependency web component framework for building modular web applications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,16 +0,0 @@
1
- "use strict";var q=m=>{throw TypeError(m)};var U=(m,g,y)=>g.has(m)||q("Cannot "+y);var N=(m,g,y)=>g.has(m)?q("Cannot add the same private member more than once"):g instanceof WeakSet?g.add(m):g.set(m,y);var j=(m,g,y)=>(U(m,g,"access private method"),y);var V=(m,g,y)=>new Promise((v,x)=>{var L=_=>{try{S(y.next(_))}catch(W){x(W)}},T=_=>{try{S(y.throw(_))}catch(W){x(W)}},S=_=>_.done?v(_.value):Promise.resolve(_.value).then(L,T);S((y=y.apply(m,g)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("./index-D8qqeJcR.js");var F=typeof document!="undefined"?document.currentScript:null;function M(m,g){return JSON.stringify(m,(y,v)=>typeof v=="string"?v.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):v,g).replace(/"/g,"&quot;")}const X=(m,g)=>{var _,H;const{tagName:y,template:v,scripts:x,externalScripts:L,style:T}=m,k=class k extends HTMLElement{constructor(){super(),g&&this.attachShadow({mode:"open"}),this.root=g?this.shadowRoot:document,this.stringify=M;const t={};this.state=new Proxy(t,{set:(n,e,s)=>(n[e]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:n,listener:e})=>{t.removeEventListener(n,e)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(n=>{if(n.type==="attributes"){const e=n.attributeName,s=this.getAttribute(e);this._handleAttributeChange(e,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const n of t)if(n.attributeName==="contenteditable"){const e=n.target;e.isContentEditable&&e.hasAttribute("data-bind")&&this._bindTwoWayForElement(e)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,n,e){const s=new MutationObserver(t.bind(this));return s.observe(n,e),s}_handleAttributeChange(t,n){var s;if(t){const i="this.state.";t.startsWith(i)&&(t=t.slice(i.length))}const e=j(s=k,_,H).call(s,n);this.state[t]=e,this._render()}_loadTemplate(){g?this.shadowRoot.innerHTML=v:this.innerHTML=v,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=t.nextNode();){const e=[...n.textContent.matchAll(/{([^}]+)}/g)];if(e.length){const s=e.map(([,i])=>({node:n,template:n.textContent,key:i.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(e=>{Array.from(e.attributes).forEach(s=>{const i=[...s.value.matchAll(/{([^}]+)}/g)];i.length&&i.forEach(([,r])=>{this._bindings.push({element:e,attrName:s.name,template:s.value,key:r.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(n=>{if(!n.name.startsWith("on"))return;const e=n.name.slice(2),s=n.value.trim();t.removeAttribute(n.name);let i;const r=s.trim();if(/^\([^)]*\)\s*=>/.test(r))try{const c=new Function("event",`return (${r});`).call(this);i=d=>c(d)}catch(o){w.logger.error(`Error parsing inline arrow function handler: ${r}`,o),i=()=>{}}else r.includes("(")&&r.includes(")")?i=o=>{try{const c=r.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(c){const[,d,f]=c,O=this[d]||this.state[d];if(typeof O=="function"){let p=[];if(f.trim())try{p=new Function("event",`return [${f}]`).call(this,o)}catch(B){w.logger.error(`Error parsing arguments for ${d}:`,B),p=[]}return O.apply(this,p)}else w.logger.warn(`Function "${d}" not found in component context. Available functions:`,Object.keys(this).filter(p=>typeof this[p]=="function").concat(Object.keys(this.state).filter(p=>typeof this.state[p]=="function")))}else new Function("event",r).call(this,o)}catch(c){w.logger.error(`Error executing inline event handler: ${r}`,c)}}:i=o=>{const c=this[r];if(typeof c=="function")try{return c.call(this,o)}catch(d){w.logger.error(`Error executing event handler method: ${r}`,d)}else w.logger.warn(`Event handler method "${r}" not found on component. Available methods on 'this':`,Object.keys(this).filter(d=>typeof this[d]=="function"))};t.addEventListener(e,i),this._eventBindings.push({key:s,element:t,event:e,listener:i})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let n=[];t.forEach(e=>{const s=e.hasAttribute("data-if");s&&n.length&&(this._conditionals.push(n),n=[]);const i=s?"if":e.hasAttribute("data-else-if")?"else-if":"else",r=i==="else"?null:e.getAttribute(i==="if"?"data-if":"data-else-if"),o=document.createComment(`ladrillos-${i}`);e.parentNode.insertBefore(o,e),e.remove(),n.push({el:e,type:i,expr:r,placeholder:o})}),n.length&&this._conditionals.push(n)}_loadStyles(){if(!T)return;const t=document.createElement("style");t.textContent=T,g?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return V(this,null,function*(){var t;for(const n of L){const e=new URL(n.src,typeof document=="undefined"?require("url").pathToFileURL(__filename).href:F&&F.tagName.toUpperCase()==="SCRIPT"&&F.src||new URL("webcomponent-BOcL3Sbk.js",document.baseURI).href).href;if(n.type==="module"&&(n!=null&&n.bind))try{const s=yield import(e);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):w.logger.error(`Module ${n.src} does not export a default function or init function.`)}catch(s){w.logger.error(`Failed to load component module ${n.src}`,s)}else n!=null&&n.bind?yield fetch(e).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(n.src,n.type)}for(const n of x)if(n.type==="module"){const e=document.createElement("script");e.type="module",e.textContent=n.content,((t=this.shadowRoot)!=null?t:this).appendChild(e)}else this._processScriptText(n.content);this._render()})}_injectScriptTag(t,n){return new Promise((e,s)=>{const i=document.createElement("script");i.src=t,n&&(i.type=n),i.onload=e,i.onerror=s,document.head.appendChild(i)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const n=this.getAttribute(t);this._handleAttributeChange(t,n)})}_setNestedState(t,n){const e=t.split(".");let s=this.state;for(let i=0;i<e.length-1;i++){const r=e[i];(typeof s[r]!="object"||s[r]===null)&&(s[r]={}),s=s[r]}s[e[e.length-1]]=n,this._render()}_bindTwoWayForElement(t){const n=t.getAttribute("data-bind"),e=t.isContentEditable,s="value"in t,i=e||s?"input":"change",r=()=>{const f=e?t.innerText:s?t.value:t.textContent;this._setNestedState(n,f)};t.addEventListener(i,r),this._eventBindings.push({element:t,event:i,listener:r});const o=s?"value":void 0,c=s?t.getAttribute("value")||`{${n}}`:e?t.innerHTML:t.textContent;this._bindings.push({element:t,key:n,attrName:o,template:c});const d=s?t.value:e?t.innerText:t.textContent;this._setNestedState(n,d)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),n={},e=(s,i,r)=>{const o=i.split(".");let c=s;for(let d=0;d<o.length-1;d++){const f=o[d];(typeof c[f]!="object"||c[f]===null)&&(c[f]={}),c=c[f]}c[o[o.length-1]]=r};t.forEach(s=>{const i=s.getAttribute("data-bind"),r=s.isContentEditable,o="value"in s,c=r?s.innerText.trim():o?s.value:s.textContent.trim();e(n,i,c)}),this.setState(n),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const n=Array.isArray(t)?t:[t],{node:e,template:s}=n[0];if(!e)return;const i={};n.forEach(({key:c})=>{var d;i[c]=(d=this.state[c])!=null?d:""});const r=this._renderTemplate(s,i);if(/<[a-z][\s\S]*>/i.test(r)){const c=document.createRange().createContextualFragment(r);e.nodeType===Node.TEXT_NODE?e.replaceWith(c):e.innerHTML=r}else e==null||e.nodeType,Node.TEXT_NODE,e.textContent=r}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:n,template:e,key:s})=>{var o;const i=(o=s.split(".").reduce((c,d)=>c==null?void 0:c[d],this.state))!=null?o:"",r=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(n,e.replace(r,i))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const e=(s=t.getAttribute("data-bind").split(".").reduce((i,r)=>i==null?void 0:i[r],this.state))!=null?s:"";t.isContentEditable?t.innerText!==e&&(t.innerText=e):"value"in t?t.value!==e&&(t.value=e):t.textContent!==e&&(t.textContent=e)})}_applyConditionals(){this._conditionals.forEach(t=>{let n=!1;t.forEach(({el:e,type:s,expr:i,placeholder:r})=>{let o=!1;if(s==="else")o=!n;else try{o=Function("state",`with(state){return(${i})}`)(this.state)}catch(c){o=!1}o&&!n?(!e.isConnected&&r.parentNode&&r.parentNode.insertBefore(e,r.nextSibling),r.remove(),n=!0):e.isConnected&&e.parentNode&&(e.parentNode.insertBefore(r,e),e.remove())})})}_renderTemplate(t,n){return t.replace(/\{\s*([-\w.]+)\s*}/g,(e,s)=>{let i=s.split(".").reduce((r,o)=>r==null?void 0:r[o],this.state);if(typeof i=="function")try{i=i.call(this)}catch(r){i=""}return i!=null?i:""})}_processScriptText(t){const n=new Set,e=new Set,s=new Set,i=(l,A)=>{let u=!1,a=!1,h=!1,E=!1;for(let $=0;$<A;$++){const b=l[$];if(E){E=!1;continue}if(b==="\\"){E=!0;continue}b==="'"&&!a&&!h?u=!u:b==='"'&&!u&&!h?a=!a:b==="`"&&!u&&!a&&(h=!h)}return u||a||h},r=(l,A,u)=>{let a=l;const h=[];let E;for(A.lastIndex=0;(E=A.exec(a))!==null;)h.push({index:E.index,length:E[0].length,originalContent:E[0],groups:E.slice(1)});for(let $=h.length-1;$>=0;$--){const b=h[$];if(!i(a,b.index)){const R=u(b.originalContent,...b.groups,b.index,a);a=a.substring(0,b.index)+R+a.substring(b.index+b.length)}}return a};Object.keys(this.state).forEach(l=>{this._isBound(l)&&s.add(l)});const o=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let c;for(;(c=o.exec(t))!==null;)n.add(c[1]);const d=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(c=d.exec(t))!==null;)n.add(c[2]);n.forEach(l=>{this._isBound(l)&&(new RegExp(`\\b${l}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${l}\\s*\\(`).test(t)||e.add(l))});let f=t;new Set([...e,...s]).forEach(l=>{f=r(f,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${l}\\b`,"g"),(u,a,h)=>`${a}${h}this.state.${l}`),f=r(f,new RegExp(`\\b${l}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(u,a)=>`this.state.${l}${a}`),f=r(f,new RegExp(`(^|\\W)${l}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(u,a,h,E,$)=>{const b=E+a.length;let R=$.substring(Math.max(0,b-10),b);return/\b(const|let|var)\s+$/.test(R)?u:`${a}this.state.${l} ${h||""}=`});const A=new RegExp(`\\b${l}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");f=r(f,A,(u,a,h)=>{if(h.substring(Math.max(0,a-11),a).endsWith("this.state."))return u;const $=h.substring(Math.max(0,a-10),a);if(/\bclass\s+$/.test($))return u;const b=h.substring(Math.max(0,a-20),a);if(/\bextends\s+$/.test(b)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(u))return u;const z=h.substring(Math.max(0,a-20),a),I=h.substring(a+u.length,Math.min(h.length,a+u.length+10));if(/\.state\[['"]\s*$/.test(z)||/state\[['"]\s*$/.test(z)||/^\s*-/.test(I))return u;const P=h.substring(Math.max(0,a-50),a);if(/\]\s*\.\s*$/.test(P))return u;const Z=h.lastIndexOf(`
2
- `,a)+1,J=h.substring(Z,a);if(/\b(?:const|let|var)\s+$/.test(J)||a>0&&h[a-1]===".")return u;let C=a+u.length;for(;C<h.length&&/\s/.test(h[C]);)C++;return C<h.length&&h[C]==="("?u:`this.state.${l}`})});let p="";n.size>0&&(p=`
3
-
4
- // --- Auto-processed by LadrillosJS Framework ---
5
- `,n.forEach(l=>{p+=`if (this._isBound('${l}')) {
6
- `,p+=` if (typeof ${l} === 'function') {
7
- `,p+=` try { this.${l} = ${l}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${l} to component context.', e); }
8
- `,p+=` } else if (typeof ${l} !== 'undefined' && ${e.has(l)}) {
9
- `,p+=` if(typeof this.state.${l} === 'undefined') { try { this.state.${l} = ${l}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${l} from script.', e); } }
10
- `,p+=` }
11
- `,p+=`}
12
- `}));const B=f+p;try{new Function(B).call(this)}catch(l){w.logger.error("Error executing component script:",l),console.error(`LadrillosJS: Error executing component script. Processed script was:
13
- ---
14
- `+B+`
15
- ---
16
- Error details:`,l)}}_evalExpression(t,n,e,s){try{return new Function(`return (${t});`).call(this)}catch(i){let r,o;for(;r=e.exec(n);)if(this._functions.set(s,r[0]),o=r[1].trim(),o)try{return new Function(`${o}`).bind(this)}catch(c){return w.logger.error(c),o}return t}}_isBound(t){if(t in this.state)return!0;const n=this._eventBindings.some(i=>{if(!i.key)return!1;if(i.key===t)return!0;const r=i.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return r&&r[1]===t}),e=this._bindings.some(i=>Array.isArray(i)?i.some(r=>r.key===t||r.key.startsWith(t+".")):i.key===t||i.key.startsWith(t+".")),s=this._conditionals.some(i=>i.some(({expr:r})=>r?new RegExp(`\\b${t}\\b`).test(r):!1));return n||e||s}emit(t,n){const e=n!=null?n:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}listen(t,n){const e=s=>n(s.detail);document.addEventListener(t,e),this._eventBindings.push({element:document,event:t,listener:e})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};_=new WeakSet,H=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(n){return t}},N(k,_);let S=k;customElements.define(y,S),w.logger.log(`Web component defined: <${y}></${y}>`)};exports.defineWebComponent=X;