ladrillosjs 1.0.0 → 1.0.1

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-lvbLxIns.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-Dntygkjn.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-dECyHgvF.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-46umVYfZ.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(g,m){typeof exports=="object"&&typeof module!="undefined"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(g=typeof globalThis!="undefined"?globalThis:g||self,m(g.ladrillosjs={}))})(this,function(g){"use strict";var dt=Object.defineProperty;var nt=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var rt=g=>{throw TypeError(g)};var st=(g,m,c)=>m in g?dt(g,m,{enumerable:!0,configurable:!0,writable:!0,value:c}):g[m]=c,G=(g,m)=>{for(var c in m||(m={}))pt.call(m,c)&&st(g,c,m[c]);if(nt)for(var c of nt(m))gt.call(m,c)&&st(g,c,m[c]);return g};var it=(g,m,c)=>m.has(g)||rt("Cannot "+c);var X=(g,m,c)=>(it(g,m,"read from private field"),c?c.call(g):m.get(g)),H=(g,m,c)=>m.has(g)?rt("Cannot add the same private member more than once"):m instanceof WeakSet?m.add(g):m.set(g,c);var Y=(g,m,c)=>(it(g,m,"access private method"),c);var L=(g,m,c)=>new Promise((N,q)=>{var K=W=>{try{j(c.next(W))}catch(Z){q(Z)}},I=W=>{try{j(c.throw(W))}catch(Z){q(Z)}},j=W=>W.done?N(W.value):Promise.resolve(W.value).then(K,I);j((c=c.apply(g,m)).next())});var z,U,J,ot;var m=typeof document!="undefined"?document.currentScript:null;const c={log(C,...f){},error(C,...f){console.error(C,...f)},warn(C,...f){}},D=class D{constructor(){H(this,z,new Map);H(this,U,new DOMParser);this.components={}}registerComponent(f,_,w=!0){return L(this,null,function*(){var $,T,A;if(this.components[f]){c.log(`Component ${f} already registered.`);return}this.components[f]={__registering:!0};try{const v=yield L(this,null,function*(){const t=X(this,z).get(_);if(t)return t;const n=yield(yield fetch(_)).text();return X(this,z).set(_,n),n}),F=X(this,U).parseFromString(v.replace(/<!--[\s\S]*?-->/g,""),"text/html"),tt=[],P=[];for(const t of F.querySelectorAll("script")){if(t.src)P.push({src:t.src,type:($=t.type)!=null?$:null,bind:t.hasAttribute("bind")});else if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),tt.push({content:e,type:(T=t.type)!=null?T:null})}t.remove()}let V="";for(const t of F.querySelectorAll("link[rel='stylesheet']"))V+=`
2
+ `+(yield Y(A=D,J,ot).call(A,`${t.href}?raw`)),t.remove();for(const t of F.querySelectorAll("style")){if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\//g,"").trim(),V+=`
3
+ `+e}t.remove()}V=V.trim(),this.components[f]={tagName:f,template:F.body.innerHTML.trim(),scripts:tt,externalScripts:P,style:V},yield this._defineWebComponent(f,w),c.log(`Component ${f} registered successfully`)}catch(v){c.error(`Failed to register component ${f}:`,v),delete this.components[f]}})}registerComponents(f,_=5){return L(this,null,function*(){const w=f.map(({name:T,path:A,useShadowDOM:v})=>()=>this.registerComponent(T,A,v)),$=yield this._runWithConcurrency(w,_);return $.forEach((T,A)=>{if(T.status==="rejected"){const{name:v}=f[A];c.error(`registration failed for ${v}:`,T.reason)}}),$})}_runWithConcurrency(f,_){return L(this,null,function*(){const w=[],$=[];for(const T of f){let A;const v=T();w.push(v),A=v.then(()=>{$.splice($.indexOf(A),1)}),$.push(A),$.length>=_&&(yield Promise.race($))}return Promise.allSettled(w)})}_defineWebComponent(f,_){return L(this,null,function*(){const{defineWebComponent:w}=yield Promise.resolve().then(()=>at);w(this.components[f],_)})}};z=new WeakMap,U=new WeakMap,J=new WeakSet,ot=function(f){return L(this,null,function*(){try{const _=yield fetch(f);if(!_.ok)throw new Error(`HTTP ${_.status}`);return yield _.text()}catch(_){return c.error(`Failed to fetch resource at ${f}:`,_),""}})},H(D,J);let N=D;const q=new N;function K(C={}){let f=C;const _=new Set;return{getState(){return f},setState(w){f=G(G({},f),w),_.forEach($=>$(f))},subscribe(w){return _.add(w),w(f),()=>_.delete(w)},reset(){f=C,_.forEach(w=>w(f))}}}const I=(...C)=>q.registerComponent(...C),j=(...C)=>q.registerComponents(...C);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:I,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 at=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(C,f)=>{var F,ct;const{tagName:_,template:w,scripts:$,externalScripts:T,style:A}=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=Y(s=P,F,ct).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 a=new Function("event",`return (${i});`).call(this);r=h=>a(h)}catch(u){c.error(`Error parsing inline arrow function handler: ${i}`,u),r=()=>{}}else i.includes("(")&&i.includes(")")?r=u=>{try{const a=i.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(a){const[,h,R]=a,Q=this[h]||this.state[h];if(typeof Q=="function"){let B=[];if(R.trim())try{B=new Function("event",`return [${R}]`).call(this,u)}catch(M){c.error(`Error parsing arguments for ${h}:`,M),B=[]}return Q.apply(this,B)}else c.warn(`Function "${h}" not found in component context. Available functions:`,Object.keys(this).filter(B=>typeof this[B]=="function").concat(Object.keys(this.state).filter(B=>typeof this.state[B]=="function")))}else new Function("event",i).call(this,u)}catch(a){c.error(`Error executing inline event handler: ${i}`,a)}}:r=u=>{const a=this[i];if(typeof a=="function")try{return a.call(this,u)}catch(h){c.error(`Error executing event handler method: ${i}`,h)}else c.warn(`Event handler method "${i}" not found on component. Available methods on 'this':`,Object.keys(this).filter(h=>typeof this[h]=="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(!A)return;const t=document.createElement("style");t.textContent=A,f?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return L(this,null,function*(){var t;for(const e of T){const n=new URL(e.src,typeof document=="undefined"&&typeof location=="undefined"?require("url").pathToFileURL(__filename).href:typeof document=="undefined"?location.href:m&&m.tagName.toUpperCase()==="SCRIPT"&&m.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):c.error(`Module ${e.src} does not export a default function or init function.`)}catch(s){c.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 $)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 R=n?t.innerText:s?t.value:t.textContent;this._setNestedState(e,R)};t.addEventListener(r,i),this._eventBindings.push({element:t,event:r,listener:i});const u=s?"value":void 0,a=s?t.getAttribute("value")||`{${e}}`:n?t.innerHTML:t.textContent;this._bindings.push({element:t,key:e,attrName:u,template:a});const h=s?t.value:n?t.innerText:t.textContent;this._setNestedState(e,h)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),e={},n=(s,r,i)=>{const u=r.split(".");let a=s;for(let h=0;h<u.length-1;h++){const R=u[h];(typeof a[R]!="object"||a[R]===null)&&(a[R]={}),a=a[R]}a[u[u.length-1]]=i};t.forEach(s=>{const r=s.getAttribute("data-bind"),i=s.isContentEditable,u="value"in s,a=i?s.innerText.trim():u?s.value:s.textContent.trim();n(e,r,a)}),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:a})=>{var h;r[a]=(h=this.state[a])!=null?h:""});const i=this._renderTemplate(s,r);if(/<[a-z][\s\S]*>/i.test(i)){const a=document.createRange().createContextualFragment(i);n.nodeType===Node.TEXT_NODE?n.replaceWith(a):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((a,h)=>a==null?void 0:a[h],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(a){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,k)=>{let p=!1,l=!1,d=!1,E=!1;for(let b=0;b<k;b++){const y=o[b];if(E){E=!1;continue}if(y==="\\"){E=!0;continue}y==="'"&&!l&&!d?p=!p:y==='"'&&!p&&!d?l=!l:y==="`"&&!p&&!l&&(d=!d)}return p||l||d},a=(o,k,p)=>{let l=o;const d=[];let E;for(k.lastIndex=0;(E=k.exec(l))!==null;)d.push({index:E.index,length:E[0].length,originalContent:E[0],groups:E.slice(1)});for(let b=d.length-1;b>=0;b--){const y=d[b];if(!u(l,y.index)){const S=p(y.originalContent,...y.groups,y.index,l);l=l.substring(0,y.index)+S+l.substring(y.index+y.length)}}return l};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let h=t;h=a(h,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,k,p)=>{if(!p||!p.trim())return o;const l=p.split(",").map(b=>b.trim()).filter(b=>b);let d=!1;const E=l.map(b=>{const y=b.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){d=!0;const S=i(y);return r.set(y,S),b.replace(y,S)}return b});return d?o.replace(p,E.join(", ")):o}),h=a(h,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,k,p)=>{if(!p||!p.trim())return o;const l=p.split(",").map(b=>b.trim()).filter(b=>b);let d=!1;const E=l.map(b=>{const y=b.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){d=!0;const S=i(y);return r.set(y,S),b.replace(y,S)}return b});return d?o.replace(p,E.join(", ")):o});const B=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let M;for(;(M=B.exec(t))!==null;)e.add(M[1]);const lt=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(M=lt.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=>{h=a(h,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(p,l,d)=>`${l}${d}this.state.${o}`),h=a(h,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(p,l)=>`this.state.${o}${l}`),h=a(h,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(p,l,d,E,b)=>{const y=E+l.length;let S=b.substring(Math.max(0,y-10),y);return/\b(const|let|var)\s+$/.test(S)?p:`${l}this.state.${o} ${d||""}=`});const k=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");h=a(h,k,(p,l,d)=>{if(d.substring(Math.max(0,l-11),l).endsWith("this.state.")||r.has(o)&&d.substring(Math.max(0,l-50),l).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 y=d.lastIndexOf(`
4
+ `,l)+1,S=d.substring(y,l);if(/\b(?:const|let|var)\s+$/.test(S)||l>0&&d[l-1]===".")return p;let x=l+p.length;for(;x<d.length&&/\s/.test(d[x]);)x++;return x<d.length&&d[x]==="("?p:`this.state.${o}`})}),r.forEach((o,k)=>{const p=new RegExp(`\\b${k}\\b`,"g");h=a(h,p,(l,d,E)=>{const b=E.substring(0,d);if(b.includes(o)){let y=0,S=-1;for(let x=b.length-1;x>=0;x--)if(b[x]==="}")y++;else if(b[x]==="{"&&(y--,y<0)){S=x;break}if(S!==-1){const x=b.substring(0,S);if(x.substring(Math.max(0,x.lastIndexOf("(",S))).includes(o)){if(E.substring(Math.max(0,d-11),d).endsWith("this.state."))return l;const ht=E.substring(d+l.length,Math.min(E.length,d+l.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(ht)?l:o}}}return l})});let O="";e.size>0&&(O=`
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=>{O+=`if (this._isBound('${o}')) {
8
+ `,O+=` if (typeof ${o} === 'function') {
9
+ `,O+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
10
+ `,O+=` } else if (typeof ${o} !== 'undefined' && ${n.has(o)}) {
11
+ `,O+=` 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
+ `,O+=` }
13
+ `,O+=`}
14
+ `}));const et=h+O;try{new Function(et).call(this)}catch(o){c.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
15
15
  ---
16
- `+J+`
16
+ `+et+`
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(a){return c.error(a),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)}};F=new WeakSet,ct=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(e){return t}},H(P,F);let v=P;customElements.define(_,v),c.log(`Web component defined: <${_}></${_}>`)}},Symbol.toStringTag,{value:"Module"}));g.createStore=K,g.registerComponent=I,g.registerComponents=j,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,16 @@
1
+ "use strict";var q=y=>{throw TypeError(y)};var J=(y,b,_)=>b.has(y)||q("Cannot "+_);var z=(y,b,_)=>b.has(y)?q("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(y):b.set(y,_);var P=(y,b,_)=>(J(y,b,"access private method"),_);var V=(y,b,_)=>new Promise((A,k)=>{var F=w=>{try{T(_.next(w))}catch(W){k(W)}},B=w=>{try{T(_.throw(w))}catch(W){k(W)}},T=w=>w.done?A(w.value):Promise.resolve(w.value).then(F,B);T((_=_.apply(y,b)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const S=require("./index-dECyHgvF.js");var N=typeof document!="undefined"?document.currentScript:null;function D(y,b){return JSON.stringify(y,(_,A)=>typeof A=="string"?A.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):A,b).replace(/"/g,"&quot;")}const X=(y,b)=>{var w,j;const{tagName:_,template:A,scripts:k,externalScripts:F,style:B}=y,L=class L 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=P(s=L,w,j).call(s,n);this.state[t]=e,this._render()}_loadTemplate(){b?this.shadowRoot.innerHTML=A:this.innerHTML=A,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 a=new Function("event",`return (${r});`).call(this);i=u=>a(u)}catch(l){S.logger.error(`Error parsing inline arrow function handler: ${r}`,l),i=()=>{}}else r.includes("(")&&r.includes(")")?i=l=>{try{const a=r.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(a){const[,u,v]=a,O=this[u]||this.state[u];if(typeof O=="function"){let x=[];if(v.trim())try{x=new Function("event",`return [${v}]`).call(this,l)}catch(R){S.logger.error(`Error parsing arguments for ${u}:`,R),x=[]}return O.apply(this,x)}else S.logger.warn(`Function "${u}" not found in component context. Available functions:`,Object.keys(this).filter(x=>typeof this[x]=="function").concat(Object.keys(this.state).filter(x=>typeof this.state[x]=="function")))}else new Function("event",r).call(this,l)}catch(a){S.logger.error(`Error executing inline event handler: ${r}`,a)}}:i=l=>{const a=this[r];if(typeof a=="function")try{return a.call(this,l)}catch(u){S.logger.error(`Error executing event handler method: ${r}`,u)}else S.logger.warn(`Event handler method "${r}" not found on component. Available methods on 'this':`,Object.keys(this).filter(u=>typeof this[u]=="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(!B)return;const t=document.createElement("style");t.textContent=B,b?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return V(this,null,function*(){var t;for(const n of F){const e=new URL(n.src,typeof document=="undefined"?require("url").pathToFileURL(__filename).href:N&&N.tagName.toUpperCase()==="SCRIPT"&&N.src||new URL("webcomponent-Dntygkjn.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):S.logger.error(`Module ${n.src} does not export a default function or init function.`)}catch(s){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 k)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 v=e?t.innerText:s?t.value:t.textContent;this._setNestedState(n,v)};t.addEventListener(i,r),this._eventBindings.push({element:t,event:i,listener:r});const l=s?"value":void 0,a=s?t.getAttribute("value")||`{${n}}`:e?t.innerHTML:t.textContent;this._bindings.push({element:t,key:n,attrName:l,template:a});const u=s?t.value:e?t.innerText:t.textContent;this._setNestedState(n,u)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),n={},e=(s,i,r)=>{const l=i.split(".");let a=s;for(let u=0;u<l.length-1;u++){const v=l[u];(typeof a[v]!="object"||a[v]===null)&&(a[v]={}),a=a[v]}a[l[l.length-1]]=r};t.forEach(s=>{const i=s.getAttribute("data-bind"),r=s.isContentEditable,l="value"in s,a=r?s.innerText.trim():l?s.value:s.textContent.trim();e(n,i,a)}),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:a})=>{var u;i[a]=(u=this.state[a])!=null?u:""});const r=this._renderTemplate(s,i);if(/<[a-z][\s\S]*>/i.test(r)){const a=document.createRange().createContextualFragment(r);e.nodeType===Node.TEXT_NODE?e.replaceWith(a):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((a,u)=>a==null?void 0:a[u],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(a){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,$)=>{let f=!1,c=!1,h=!1,p=!1;for(let d=0;d<$;d++){const g=o[d];if(p){p=!1;continue}if(g==="\\"){p=!0;continue}g==="'"&&!c&&!h?f=!f:g==='"'&&!f&&!h?c=!c:g==="`"&&!f&&!c&&(h=!h)}return f||c||h},a=(o,$,f)=>{let c=o;const h=[];let p;for($.lastIndex=0;(p=$.exec(c))!==null;)h.push({index:p.index,length:p[0].length,originalContent:p[0],groups:p.slice(1)});for(let d=h.length-1;d>=0;d--){const g=h[d];if(!l(c,g.index)){const m=f(g.originalContent,...g.groups,g.index,c);c=c.substring(0,g.index)+m+c.substring(g.index+g.length)}}return c};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let u=t;u=a(u,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,$,f)=>{if(!f||!f.trim())return o;const c=f.split(",").map(d=>d.trim()).filter(d=>d);let h=!1;const p=c.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){h=!0;const m=r(g);return i.set(g,m),d.replace(g,m)}return d});return h?o.replace(f,p.join(", ")):o}),u=a(u,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,$,f)=>{if(!f||!f.trim())return o;const c=f.split(",").map(d=>d.trim()).filter(d=>d);let h=!1;const p=c.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){h=!0;const m=r(g);return i.set(g,m),d.replace(g,m)}return d});return h?o.replace(f,p.join(", ")):o});const x=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let R;for(;(R=x.exec(t))!==null;)n.add(R[1]);const I=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(R=I.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=>{u=a(u,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(f,c,h)=>`${c}${h}this.state.${o}`),u=a(u,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(f,c)=>`this.state.${o}${c}`),u=a(u,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(f,c,h,p,d)=>{const g=p+c.length;let m=d.substring(Math.max(0,g-10),g);return/\b(const|let|var)\s+$/.test(m)?f:`${c}this.state.${o} ${h||""}=`});const $=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");u=a(u,$,(f,c,h)=>{if(h.substring(Math.max(0,c-11),c).endsWith("this.state.")||i.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(f))return f;const g=h.lastIndexOf(`
2
+ `,c)+1,m=h.substring(g,c);if(/\b(?:const|let|var)\s+$/.test(m)||c>0&&h[c-1]===".")return f;let E=c+f.length;for(;E<h.length&&/\s/.test(h[E]);)E++;return E<h.length&&h[E]==="("?f:`this.state.${o}`})}),i.forEach((o,$)=>{const f=new RegExp(`\\b${$}\\b`,"g");u=a(u,f,(c,h,p)=>{const d=p.substring(0,h);if(d.includes(o)){let g=0,m=-1;for(let E=d.length-1;E>=0;E--)if(d[E]==="}")g++;else if(d[E]==="{"&&(g--,g<0)){m=E;break}if(m!==-1){const E=d.substring(0,m);if(E.substring(Math.max(0,E.lastIndexOf("(",m))).includes(o)){if(p.substring(Math.max(0,h-11),h).endsWith("this.state."))return c;const U=p.substring(h+c.length,Math.min(p.length,h+c.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(U)?c:o}}}return c})});let C="";n.size>0&&(C=`
3
+
4
+ // --- Auto-processed by LadrillosJS Framework ---
5
+ `,n.forEach(o=>{C+=`if (this._isBound('${o}')) {
6
+ `,C+=` if (typeof ${o} === 'function') {
7
+ `,C+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
8
+ `,C+=` } else if (typeof ${o} !== 'undefined' && ${e.has(o)}) {
9
+ `,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); } }
10
+ `,C+=` }
11
+ `,C+=`}
12
+ `}));const M=u+C;try{new Function(M).call(this)}catch(o){S.logger.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
13
+ ---
14
+ `+M+`
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(a){return S.logger.error(a),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)}};w=new WeakSet,j=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(n){return t}},z(L,w);let T=L;customElements.define(_,T),S.logger.log(`Web component defined: <${_}></${_}>`)};exports.defineWebComponent=X;
@@ -1,38 +1,38 @@
1
- var z = (m) => {
2
- throw TypeError(m);
1
+ var z = (y) => {
2
+ throw TypeError(y);
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 = (y, b, _) => b.has(y) || z("Cannot " + _);
5
+ var M = (y, b, _) => b.has(y) ? z("Cannot add the same private member more than once") : b instanceof WeakSet ? b.add(y) : b.set(y, _);
6
+ var V = (y, b, _) => (J(y, b, "access private method"), _);
7
+ var q = (y, b, _) => new Promise((C, R) => {
8
+ var F = (w) => {
9
9
  try {
10
- S(y.next(_));
10
+ T(_.next(w));
11
11
  } catch (W) {
12
- C(W);
12
+ R(W);
13
13
  }
14
- }, T = (_) => {
14
+ }, B = (w) => {
15
15
  try {
16
- S(y.throw(_));
16
+ T(_.throw(w));
17
17
  } catch (W) {
18
- C(W);
18
+ R(W);
19
19
  }
20
- }, S = (_) => _.done ? v(_.value) : Promise.resolve(_.value).then(L, T);
21
- S((y = y.apply(m, p)).next());
20
+ }, T = (w) => w.done ? C(w.value) : Promise.resolve(w.value).then(F, B);
21
+ T((_ = _.apply(y, b)).next());
22
22
  });
23
- import { l as w } from "./index-CYYvcgtW.mjs";
24
- function M(m, p) {
23
+ import { l as S } from "./index-46umVYfZ.mjs";
24
+ function D(y, b) {
25
25
  return JSON.stringify(
26
- m,
27
- (y, v) => typeof v == "string" ? v.replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r") : v,
28
- p
26
+ y,
27
+ (_, C) => typeof C == "string" ? C.replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r") : C,
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 Q = (y, b) => {
32
+ var w, P;
33
+ const { tagName: _, template: C, scripts: R, externalScripts: F, style: B } = y, L = class L 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 = V(s = L, w, P).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 = C : this.innerHTML = C, 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
@@ -145,69 +145,69 @@ const K = (m, p) => {
145
145
  const r = s.trim();
146
146
  if (/^\([^)]*\)\s*=>/.test(r))
147
147
  try {
148
- const c = new Function("event", `return (${r});`).call(this);
149
- i = (f) => c(f);
150
- } catch (o) {
151
- w.error(
148
+ const a = new Function("event", `return (${r});`).call(this);
149
+ i = (u) => a(u);
150
+ } catch (l) {
151
+ S.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
- const c = r.match(
159
+ const a = r.match(
160
160
  /^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/
161
161
  );
162
- if (c) {
163
- const [, f, d] = c, O = this[f] || this.state[f];
162
+ if (a) {
163
+ const [, u, v] = a, O = this[u] || this.state[u];
164
164
  if (typeof O == "function") {
165
- let g = [];
166
- if (d.trim())
165
+ let x = [];
166
+ if (v.trim())
167
167
  try {
168
- g = new Function(
168
+ x = new Function(
169
169
  "event",
170
- `return [${d}]`
171
- ).call(this, o);
172
- } catch (B) {
173
- w.error(
174
- `Error parsing arguments for ${f}:`,
175
- B
176
- ), g = [];
170
+ `return [${v}]`
171
+ ).call(this, l);
172
+ } catch (k) {
173
+ S.error(
174
+ `Error parsing arguments for ${u}:`,
175
+ k
176
+ ), x = [];
177
177
  }
178
- return O.apply(this, g);
178
+ return O.apply(this, x);
179
179
  } else
180
- w.warn(
181
- `Function "${f}" not found in component context. Available functions:`,
182
- Object.keys(this).filter((g) => typeof this[g] == "function").concat(
180
+ S.warn(
181
+ `Function "${u}" not found in component context. Available functions:`,
182
+ Object.keys(this).filter((x) => typeof this[x] == "function").concat(
183
183
  Object.keys(this.state).filter(
184
- (g) => typeof this.state[g] == "function"
184
+ (x) => typeof this.state[x] == "function"
185
185
  )
186
186
  )
187
187
  );
188
188
  } else
189
- new Function("event", r).call(this, o);
190
- } catch (c) {
191
- w.error(
189
+ new Function("event", r).call(this, l);
190
+ } catch (a) {
191
+ S.error(
192
192
  `Error executing inline event handler: ${r}`,
193
- c
193
+ a
194
194
  );
195
195
  }
196
- } : i = (o) => {
197
- const c = this[r];
198
- if (typeof c == "function")
196
+ } : i = (l) => {
197
+ const a = this[r];
198
+ if (typeof a == "function")
199
199
  try {
200
- return c.call(this, o);
201
- } catch (f) {
202
- w.error(
200
+ return a.call(this, l);
201
+ } catch (u) {
202
+ S.error(
203
203
  `Error executing event handler method: ${r}`,
204
- f
204
+ u
205
205
  );
206
206
  }
207
207
  else
208
- w.warn(
208
+ S.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,31 +230,31 @@ 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 (!B) 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 = B, 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 q(this, null, function* () {
247
247
  var t;
248
- for (const n of L) {
248
+ for (const n of F) {
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 {
252
252
  const s = yield import(e);
253
- typeof s.default == "function" ? s.default.call(this) : typeof s.init == "function" ? s.init.call(this) : w.error(
253
+ typeof s.default == "function" ? s.default.call(this) : typeof s.init == "function" ? s.init.call(this) : S.error(
254
254
  `Module ${n.src} does not export a default function or init function.`
255
255
  );
256
256
  } catch (s) {
257
- w.error(`Failed to load component module ${n.src}`, s);
257
+ S.error(`Failed to load component module ${n.src}`, s);
258
258
  }
259
259
  else n != null && n.bind ? yield fetch(e).then((s) => s.text()).then(
260
260
  (s) => this._processScriptText(
@@ -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 R)
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,30 +302,30 @@ 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 v = e ? t.innerText : s ? t.value : t.textContent;
306
+ this._setNestedState(n, v);
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, a = s ? t.getAttribute("value") || `{${n}}` : e ? t.innerHTML : t.textContent;
310
+ this._bindings.push({ element: t, key: n, attrName: l, template: a });
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(".");
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];
318
+ const l = i.split(".");
319
+ let a = s;
320
+ for (let u = 0; u < l.length - 1; u++) {
321
+ const v = l[u];
322
+ (typeof a[v] != "object" || a[v] === null) && (a[v] = {}), a = a[v];
323
323
  }
324
- c[o[o.length - 1]] = r;
324
+ a[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();
328
- e(n, i, c);
327
+ const i = s.getAttribute("data-bind"), r = s.isContentEditable, l = "value" in s, a = r ? s.innerText.trim() : l ? s.value : s.textContent.trim();
328
+ e(n, i, a);
329
329
  }), this.setState(n), t.forEach((s) => {
330
330
  this._bindTwoWayForElement(s);
331
331
  });
@@ -337,19 +337,19 @@ const K = (m, p) => {
337
337
  const n = Array.isArray(t) ? t : [t], { node: e, template: s } = n[0];
338
338
  if (!e) return;
339
339
  const i = {};
340
- n.forEach(({ key: c }) => {
341
- var f;
342
- i[c] = (f = this.state[c]) != null ? f : "";
340
+ n.forEach(({ key: a }) => {
341
+ var u;
342
+ i[a] = (u = this.state[a]) != null ? u : "";
343
343
  });
344
344
  const r = this._renderTemplate(s, i);
345
345
  if (/<[a-z][\s\S]*>/i.test(r)) {
346
- const c = document.createRange().createContextualFragment(r);
347
- e.nodeType === Node.TEXT_NODE ? e.replaceWith(c) : e.innerHTML = r;
346
+ const a = document.createRange().createContextualFragment(r);
347
+ e.nodeType === Node.TEXT_NODE ? e.replaceWith(a) : e.innerHTML = r;
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((a, u) => a == null ? void 0 : a[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
- } catch (c) {
375
- o = !1;
374
+ } catch (a) {
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,152 @@ 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, c = !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 === "'" && !c && !h ? f = !f : p === '"' && !f && !h ? c = !c : p === "`" && !f && !c && (h = !h);
418
420
  }
419
- return u || a || h;
420
- }, r = (l, A, u) => {
421
- let a = l;
421
+ return f || c || h;
422
+ }, a = (o, $, f) => {
423
+ let c = 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(c)) !== 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,
439
- a
433
+ for (let d = h.length - 1; d >= 0; d--) {
434
+ const p = h[d];
435
+ if (!l(c, p.index)) {
436
+ const m = f(
437
+ p.originalContent,
438
+ ...p.groups,
439
+ p.index,
440
+ c
440
441
  );
441
- a = a.substring(0, b.index) + R + a.substring(b.index + b.length);
442
+ c = c.substring(0, p.index) + m + c.substring(p.index + p.length);
442
443
  }
443
444
  }
444
- return a;
445
+ return c;
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 = a(
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 c = f.split(",").map((d) => d.trim()).filter((d) => d);
457
+ let h = !1;
458
+ const g = c.map((d) => {
459
+ const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
460
+ if (this._isBound(p)) {
461
+ h = !0;
462
+ const m = r(p);
463
+ return i.set(p, m), d.replace(p, m);
464
+ }
465
+ return d;
466
+ });
467
+ return h ? o.replace(f, g.join(", ")) : o;
468
+ }
469
+ ), u = a(
470
+ u,
471
+ /\bfunction\s+(\w+)\s*\(([^)]*)\)/g,
472
+ (o, $, f) => {
473
+ if (!f || !f.trim()) return o;
474
+ const c = f.split(",").map((d) => d.trim()).filter((d) => d);
475
+ let h = !1;
476
+ const g = c.map((d) => {
477
+ const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
478
+ if (this._isBound(p)) {
479
+ h = !0;
480
+ const m = r(p);
481
+ return i.set(p, m), d.replace(p, m);
482
+ }
483
+ return d;
484
+ });
485
+ return h ? o.replace(f, g.join(", ")) : o;
486
+ }
487
+ );
488
+ const x = /\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;
489
+ let k;
490
+ for (; (k = x.exec(t)) !== null; )
491
+ n.add(k[1]);
492
+ const j = /\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;
493
+ for (; (k = j.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 = a(
505
+ u,
506
+ new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`, "g"),
507
+ (f, c, h) => `${c}${h}this.state.${o}`
508
+ ), u = a(
509
+ u,
510
+ new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`, "g"),
511
+ (f, c) => `this.state.${o}${c}`
512
+ ), u = a(
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, c, h, g, d) => {
519
+ const p = g + c.length;
520
+ let m = 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(m) ? f : `${c}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 = a(
532
+ u,
533
+ $,
534
+ (f, c, h) => {
501
535
  if (h.substring(
502
- Math.max(0, a - 11),
503
- a
504
- ).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(
513
- Math.max(0, a - 20),
514
- a
515
- );
516
- if (/\bextends\s+$/.test(b) || [
536
+ Math.max(0, c - 11),
537
+ c
538
+ ).endsWith("this.state.") || i.has(o) && h.substring(
539
+ Math.max(0, c - 50),
540
+ c
541
+ ).match(
542
+ /([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/
543
+ ) || [
517
544
  "break",
518
545
  "case",
519
546
  "catch",
@@ -548,64 +575,82 @@ const K = (m, p) => {
548
575
  "while",
549
576
  "with",
550
577
  "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}`;
578
+ ].includes(f))
579
+ return f;
580
+ const p = h.lastIndexOf(`
581
+ `, c) + 1, m = h.substring(p, c);
582
+ if (/\b(?:const|let|var)\s+$/.test(m) || c > 0 && h[c - 1] === ".")
583
+ return f;
584
+ let E = c + f.length;
585
+ for (; E < h.length && /\s/.test(h[E]); )
586
+ E++;
587
+ return E < h.length && h[E] === "(" ? f : `this.state.${o}`;
588
+ }
589
+ );
590
+ }), i.forEach((o, $) => {
591
+ const f = new RegExp(`\\b${$}\\b`, "g");
592
+ u = a(
593
+ u,
594
+ f,
595
+ (c, h, g) => {
596
+ const d = g.substring(0, h);
597
+ if (d.includes(o)) {
598
+ let p = 0, m = -1;
599
+ for (let E = d.length - 1; E >= 0; E--)
600
+ if (d[E] === "}") p++;
601
+ else if (d[E] === "{" && (p--, p < 0)) {
602
+ m = E;
603
+ break;
604
+ }
605
+ if (m !== -1) {
606
+ const E = d.substring(0, m);
607
+ if (E.substring(
608
+ Math.max(0, E.lastIndexOf("(", m))
609
+ ).includes(o)) {
610
+ if (g.substring(
611
+ Math.max(0, h - 11),
612
+ h
613
+ ).endsWith("this.state."))
614
+ return c;
615
+ const I = g.substring(
616
+ h + c.length,
617
+ Math.min(g.length, h + c.length + 20)
618
+ );
619
+ return /^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(I) ? c : o;
620
+ }
621
+ }
622
+ }
623
+ return c;
579
624
  }
580
625
  );
581
626
  });
582
- let g = "";
583
- n.size > 0 && (g = `
627
+ let A = "";
628
+ n.size > 0 && (A = `
584
629
 
585
630
  // --- 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
631
+ `, n.forEach((o) => {
632
+ A += `if (this._isBound('${o}')) {
633
+ `, A += ` if (typeof ${o} === 'function') {
634
+ `, A += ` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
635
+ `, A += ` } else if (typeof ${o} !== 'undefined' && ${e.has(
636
+ o
592
637
  )}) {
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 += `}
638
+ `, 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); } }
639
+ `, A += ` }
640
+ `, A += `}
596
641
  `;
597
642
  }));
598
- const B = d + g;
643
+ const N = u + A;
599
644
  try {
600
- new Function(B).call(this);
601
- } catch (l) {
602
- w.error("Error executing component script:", l), console.error(
645
+ new Function(N).call(this);
646
+ } catch (o) {
647
+ S.error("Error executing component script:", o), console.error(
603
648
  `LadrillosJS: Error executing component script. Processed script was:
604
649
  ---
605
- ` + B + `
650
+ ` + N + `
606
651
  ---
607
652
  Error details:`,
608
- l
653
+ o
609
654
  );
610
655
  }
611
656
  }
@@ -615,13 +660,13 @@ Error details:`,
615
660
  try {
616
661
  return new Function(`return (${t});`).call(this);
617
662
  } catch (i) {
618
- let r, o;
663
+ let r, l;
619
664
  for (; r = e.exec(n); )
620
- if (this._functions.set(s, r[0]), o = r[1].trim(), o)
665
+ if (this._functions.set(s, r[0]), l = r[1].trim(), l)
621
666
  try {
622
- return new Function(`${o}`).bind(this);
623
- } catch (c) {
624
- return w.error(c), o;
667
+ return new Function(`${l}`).bind(this);
668
+ } catch (a) {
669
+ return S.error(a), l;
625
670
  }
626
671
  return t;
627
672
  }
@@ -641,7 +686,11 @@ Error details:`,
641
686
  );
642
687
  return r && r[1] === t;
643
688
  }), 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)
689
+ (i) => i.some(({ expr: r }) => {
690
+ if (!r) return !1;
691
+ const l = t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
692
+ return new RegExp(`\\b${l}\\b`).test(r);
693
+ })
645
694
  );
646
695
  return n || e || s;
647
696
  }
@@ -691,7 +740,7 @@ Error details:`,
691
740
  return this.root.querySelectorAll(t);
692
741
  }
693
742
  };
694
- _ = new WeakSet(), H = function(t) {
743
+ w = new WeakSet(), P = function(t) {
695
744
  if (t === "") return null;
696
745
  if (t !== "undefined")
697
746
  try {
@@ -699,10 +748,10 @@ Error details:`,
699
748
  } catch (n) {
700
749
  return t;
701
750
  }
702
- }, q(k, _);
703
- let S = k;
704
- customElements.define(y, S), w.log(`Web component defined: <${y}></${y}>`);
751
+ }, M(L, w);
752
+ let T = L;
753
+ customElements.define(_, T), S.log(`Web component defined: <${_}></${_}>`);
705
754
  };
706
755
  export {
707
- K as defineWebComponent
756
+ Q as defineWebComponent
708
757
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ladrillosjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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;