ladrillosjs 1.0.2 → 2.0.0-beta.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.
Files changed (37) hide show
  1. package/README.md +533 -105
  2. package/dist/cache/functionCache.d.ts +15 -0
  3. package/dist/cache/index.d.ts +16 -0
  4. package/dist/core/componentParser.d.ts +29 -0
  5. package/dist/core/componentSource.d.ts +12 -0
  6. package/dist/core/css/cssParser.d.ts +3 -0
  7. package/dist/core/eventBus.d.ts +41 -0
  8. package/dist/core/html/htmlRenderer.d.ts +18 -0
  9. package/dist/core/html/htmlparser.d.ts +16 -0
  10. package/dist/core/js/scriptParser.d.ts +3 -0
  11. package/dist/core/main.d.ts +4 -26
  12. package/dist/core/webcomponent.d.ts +2 -2
  13. package/dist/index-CXHidyhO.js +8 -0
  14. package/dist/index-CXHidyhO.js.map +1 -0
  15. package/dist/index-VkDZJVOR.mjs +361 -0
  16. package/dist/index-VkDZJVOR.mjs.map +1 -0
  17. package/dist/index.d.ts +56 -6
  18. package/dist/ladrillosjs.cjs.js +2 -1
  19. package/dist/ladrillosjs.cjs.js.map +1 -0
  20. package/dist/ladrillosjs.es.js +12 -4
  21. package/dist/ladrillosjs.es.js.map +1 -0
  22. package/dist/ladrillosjs.umd.js +76 -18
  23. package/dist/ladrillosjs.umd.js.map +1 -0
  24. package/dist/types/LadrilloTypes.d.ts +47 -14
  25. package/dist/utils/logger.d.ts +14 -11
  26. package/dist/utils/regex.d.ts +2 -0
  27. package/dist/webcomponent-CJ3lZBZb.mjs +703 -0
  28. package/dist/webcomponent-CJ3lZBZb.mjs.map +1 -0
  29. package/dist/webcomponent-i9W7LUiv.js +70 -0
  30. package/dist/webcomponent-i9W7LUiv.js.map +1 -0
  31. package/package.json +8 -4
  32. package/dist/core/store.d.ts +0 -6
  33. package/dist/index-D_dHFObN.mjs +0 -215
  34. package/dist/index-X9YN_DbT.js +0 -3
  35. package/dist/utils/stringify.d.ts +0 -7
  36. package/dist/webcomponent-Cga3h8cx.js +0 -16
  37. package/dist/webcomponent-UTcwAakf.mjs +0 -769
@@ -1,215 +0,0 @@
1
- var v = Object.defineProperty;
2
- var E = Object.getOwnPropertySymbols;
3
- var M = Object.prototype.hasOwnProperty, T = Object.prototype.propertyIsEnumerable;
4
- var A = (r) => {
5
- throw TypeError(r);
6
- };
7
- var W = (r, e, t) => e in r ? v(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, S = (r, e) => {
8
- for (var t in e || (e = {}))
9
- M.call(e, t) && W(r, t, e[t]);
10
- if (E)
11
- for (var t of E(e))
12
- T.call(e, t) && W(r, t, e[t]);
13
- return r;
14
- };
15
- var F = (r, e, t) => e.has(r) || A("Cannot " + t);
16
- var d = (r, e, t) => (F(r, e, "read from private field"), t ? t.call(r) : e.get(r)), y = (r, e, t) => e.has(r) ? A("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
17
- var P = (r, e, t) => (F(r, e, "access private method"), t);
18
- var u = (r, e, t) => new Promise((s, o) => {
19
- var l = (a) => {
20
- try {
21
- c(t.next(a));
22
- } catch (f) {
23
- o(f);
24
- }
25
- }, i = (a) => {
26
- try {
27
- c(t.throw(a));
28
- } catch (f) {
29
- o(f);
30
- }
31
- }, c = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(l, i);
32
- c((t = t.apply(r, e)).next());
33
- });
34
- const g = {
35
- /**
36
- * Log a message only in development mode
37
- * @param {string} message - The message to log
38
- * @param {any[]} args - Additional arguments to log
39
- */
40
- log(r, ...e) {
41
- },
42
- /**
43
- * Log an error (always logs in both dev and production)
44
- * @param {string} message - The error message
45
- * @param {any[]} args - Additional arguments to log
46
- */
47
- error(r, ...e) {
48
- console.error(r, ...e);
49
- },
50
- /**
51
- * Log a warning only in development mode
52
- * @param {string} message - The warning message
53
- * @param {any[]} args - Additional arguments to log
54
- */
55
- warn(r, ...e) {
56
- }
57
- };
58
- var m, w, C, _;
59
- const x = class x {
60
- constructor() {
61
- y(this, m, /* @__PURE__ */ new Map());
62
- y(this, w, new DOMParser());
63
- this.components = {};
64
- }
65
- /**
66
- * Registers a web‐component by fetching its HTML, scripts, and styles.
67
- * @param {string} name
68
- * @param {string} path
69
- * @param {boolean} [useShadowDOM=true]
70
- */
71
- registerComponent(e, t, s = !0) {
72
- return u(this, null, function* () {
73
- var o, l, i;
74
- if (this.components[e]) {
75
- g.log(`Component ${e} already registered.`);
76
- return;
77
- }
78
- this.components[e] = { __registering: !0 };
79
- try {
80
- const c = yield u(this, null, function* () {
81
- const n = d(this, m).get(t);
82
- if (n) return n;
83
- const k = yield (yield fetch(t)).text();
84
- return d(this, m).set(t, k), k;
85
- }), a = d(this, w).parseFromString(
86
- c.replace(/<!--[\s\S]*?-->/g, ""),
87
- "text/html"
88
- ), f = [], $ = [];
89
- for (const n of a.querySelectorAll("script")) {
90
- if (n.src)
91
- $.push({
92
- src: n.src,
93
- type: (o = n.type) != null ? o : null,
94
- bind: n.hasAttribute("bind")
95
- });
96
- else if (n.textContent) {
97
- let p = n.textContent.trim();
98
- p = p.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, "").trim(), f.push({
99
- content: p,
100
- type: (l = n.type) != null ? l : null
101
- });
102
- }
103
- n.remove();
104
- }
105
- let h = "";
106
- for (const n of a.querySelectorAll("link[rel='stylesheet']"))
107
- h += `
108
- ` + (yield P(i = x, C, _).call(i, `${n.href}?raw`)), n.remove();
109
- for (const n of a.querySelectorAll("style")) {
110
- if (n.textContent) {
111
- let p = n.textContent.trim();
112
- p = p.replace(/\/\*[\s\S]*?\*\//g, "").trim(), h += `
113
- ` + p;
114
- }
115
- n.remove();
116
- }
117
- h = h.trim(), this.components[e] = {
118
- tagName: e,
119
- template: a.body.innerHTML.trim(),
120
- scripts: f,
121
- externalScripts: $,
122
- style: h
123
- }, yield this._defineWebComponent(e, s), g.log(`Component ${e} registered successfully`);
124
- } catch (c) {
125
- g.error(`Failed to register component ${e}:`, c), delete this.components[e];
126
- }
127
- });
128
- }
129
- /**
130
- * Registers multiple components with optional concurrency throttling.
131
- * @param {{name: string, path: string,useShadowDOM:boolean}[]} components
132
- * @param {number} [concurrency=5] max simultaneous registrations
133
- */
134
- registerComponents(e, t = 5) {
135
- return u(this, null, function* () {
136
- const s = e.map(
137
- ({ name: l, path: i, useShadowDOM: c }) => () => this.registerComponent(l, i, c)
138
- ), o = yield this._runWithConcurrency(s, t);
139
- return o.forEach((l, i) => {
140
- if (l.status === "rejected") {
141
- const { name: c } = e[i];
142
- g.error(`registration failed for ${c}:`, l.reason);
143
- }
144
- }), o;
145
- });
146
- }
147
- /** @private */
148
- _runWithConcurrency(e, t) {
149
- return u(this, null, function* () {
150
- const s = [], o = [];
151
- for (const l of e) {
152
- let i;
153
- const c = l();
154
- s.push(c), i = c.then(() => {
155
- o.splice(o.indexOf(i), 1);
156
- }), o.push(i), o.length >= t && (yield Promise.race(o));
157
- }
158
- return Promise.allSettled(s);
159
- });
160
- }
161
- /** @private */
162
- _defineWebComponent(e, t) {
163
- return u(this, null, function* () {
164
- const { defineWebComponent: s } = yield import("./webcomponent-UTcwAakf.mjs");
165
- s(this.components[e], t);
166
- });
167
- }
168
- };
169
- m = new WeakMap(), w = new WeakMap(), C = new WeakSet(), _ = function(e) {
170
- return u(this, null, function* () {
171
- try {
172
- const t = yield fetch(e);
173
- if (!t.ok) throw new Error(`HTTP ${t.status}`);
174
- return yield t.text();
175
- } catch (t) {
176
- return g.error(`Failed to fetch resource at ${e}:`, t), "";
177
- }
178
- });
179
- }, y(x, C);
180
- let b = x;
181
- const q = new b();
182
- function D(r = {}) {
183
- let e = r;
184
- const t = /* @__PURE__ */ new Set();
185
- return {
186
- // read-only access
187
- getState() {
188
- return e;
189
- },
190
- // update state by merging partial, then notify
191
- setState(s) {
192
- e = S(S({}, e), s), t.forEach((o) => o(e));
193
- },
194
- // subscribe: fn will be called immediately and on every change
195
- subscribe(s) {
196
- return t.add(s), s(e), () => t.delete(s);
197
- },
198
- // clear store
199
- reset() {
200
- e = r, t.forEach((s) => s(e));
201
- }
202
- };
203
- }
204
- const j = (...r) => q.registerComponent(...r), H = (...r) => q.registerComponents(...r);
205
- typeof window != "undefined" && (window.ladrillosjs = {
206
- registerComponent: j,
207
- registerComponents: H
208
- // changed code
209
- });
210
- export {
211
- H as a,
212
- D as c,
213
- g as l,
214
- j as r
215
- };
@@ -1,3 +0,0 @@
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
- `+(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-Cga3h8cx.js"));s(this.components[e],t)})}};m=new WeakMap,w=new WeakMap,C=new WeakSet,A=function(e){return u(this,null,function*(){try{const t=yield fetch(e);if(!t.ok)throw new Error(`HTTP ${t.status}`);return yield t.text()}catch(t){return h.error(`Failed to fetch resource at ${e}:`,t),""}})},y(S,C);let b=S;const F=new b;function O(r={}){let e=r;const t=new Set;return{getState(){return e},setState(s){e=x(x({},e),s),t.forEach(o=>o(e))},subscribe(s){return t.add(s),s(e),()=>t.delete(s)},reset(){e=r,t.forEach(s=>s(e))}}}const _=(...r)=>F.registerComponent(...r),M=(...r)=>F.registerComponents(...r);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:_,registerComponents:M});exports.createStore=O;exports.logger=h;exports.registerComponent=_;exports.registerComponents=M;
@@ -1,7 +0,0 @@
1
- /**
2
- * Safely stringifies an object, escaping double quotes and special characters for HTML attributes.
3
- * @param {any} obj - The object to stringify.
4
- * @param {number|string} [space] - Indentation for pretty-printing.
5
- * @returns {string} - The safely stringified JSON string, escaped for HTML attributes.
6
- */
7
- export function stringify(obj: any, space?: number | string): string;
@@ -1,16 +0,0 @@
1
- "use strict";var V=m=>{throw TypeError(m)};var J=(m,b,y)=>b.has(m)||V("Cannot "+y);var j=(m,b,y)=>b.has(m)?V("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(m):b.set(m,y);var I=(m,b,y)=>(J(m,b,"access private method"),y);var H=(m,b,y)=>new Promise((x,B)=>{var O=E=>{try{T(y.next(E))}catch(F){B(F)}},L=E=>{try{T(y.throw(E))}catch(F){B(F)}},T=E=>E.done?x(E.value):Promise.resolve(E.value).then(O,L);T((y=y.apply(m,b)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("./index-X9YN_DbT.js");var q=typeof document!="undefined"?document.currentScript:null;function D(m,b){return JSON.stringify(m,(y,x)=>typeof x=="string"?x.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):x,b).replace(/"/g,"&quot;")}const X=(m,b)=>{var E,Z;const{tagName:y,template:x,scripts:B,externalScripts:O,style:L}=m,W=class W extends HTMLElement{constructor(){super(),b&&this.attachShadow({mode:"open"}),this.root=b?this.shadowRoot:document,this.stringify=D;const t={};this.state=new Proxy(t,{set:(n,e,s)=>(n[e]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:n,listener:e})=>{t.removeEventListener(n,e)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(n=>{if(n.type==="attributes"){const e=n.attributeName,s=this.getAttribute(e);this._handleAttributeChange(e,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const n of t)if(n.attributeName==="contenteditable"){const e=n.target;e.isContentEditable&&e.hasAttribute("data-bind")&&this._bindTwoWayForElement(e)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,n,e){const s=new MutationObserver(t.bind(this));return s.observe(n,e),s}_handleAttributeChange(t,n){var s;if(t){const i="this.state.";t.startsWith(i)&&(t=t.slice(i.length))}const e=I(s=W,E,Z).call(s,n);this.state[t]=e,this._render()}_loadTemplate(){b?this.shadowRoot.innerHTML=x:this.innerHTML=x,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=t.nextNode();){const e=[...n.textContent.matchAll(/{([^}]+)}/g)];if(e.length){const s=e.map(([,i])=>({node:n,template:n.textContent,key:i.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(e=>{Array.from(e.attributes).forEach(s=>{const i=[...s.value.matchAll(/{([^}]+)}/g)];i.length&&i.forEach(([,r])=>{this._bindings.push({element:e,attrName:s.name,template:s.value,key:r.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(n=>{if(!n.name.startsWith("on"))return;const e=n.name.slice(2),s=n.value.trim();t.removeAttribute(n.name);let i;const r=s.trim();if(/^\([^)]*\)\s*=>/.test(r))try{const c=new Function("event",`return (${r});`).call(this);i=h=>c(h)}catch(l){$.logger.error(`Error parsing inline arrow function handler: ${r}`,l),i=()=>{}}else r.includes("(")&&r.includes(")")?i=l=>{try{const c=r.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(c){const[,h,S]=c,N=this[h]||this.state[h];if(typeof N=="function"){let C=[];if(S.trim())try{C=new Function("event",`return [${S}]`).call(this,l)}catch(R){$.logger.error(`Error parsing arguments for ${h}:`,R),C=[]}return N.apply(this,C)}else $.logger.warn(`Function "${h}" not found in component context. Available functions:`,Object.keys(this).filter(C=>typeof this[C]=="function").concat(Object.keys(this.state).filter(C=>typeof this.state[C]=="function")))}else new Function("event",r).call(this,l)}catch(c){$.logger.error(`Error executing inline event handler: ${r}`,c)}}:i=l=>{const c=this[r];if(typeof c=="function")try{return c.call(this,l)}catch(h){$.logger.error(`Error executing event handler method: ${r}`,h)}else $.logger.warn(`Event handler method "${r}" not found on component. Available methods on 'this':`,Object.keys(this).filter(h=>typeof this[h]=="function"))};t.addEventListener(e,i),this._eventBindings.push({key:s,element:t,event:e,listener:i})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let n=[];t.forEach(e=>{const s=e.hasAttribute("data-if");s&&n.length&&(this._conditionals.push(n),n=[]);const i=s?"if":e.hasAttribute("data-else-if")?"else-if":"else",r=i==="else"?null:e.getAttribute(i==="if"?"data-if":"data-else-if"),l=document.createComment(`ladrillos-${i}`);e.parentNode.insertBefore(l,e),e.remove(),n.push({el:e,type:i,expr:r,placeholder:l})}),n.length&&this._conditionals.push(n)}_loadStyles(){if(!L)return;const t=document.createElement("style");t.textContent=L,b?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return H(this,null,function*(){var t;for(const n of O){const e=new URL(n.src,typeof document=="undefined"?require("url").pathToFileURL(__filename).href:q&&q.tagName.toUpperCase()==="SCRIPT"&&q.src||new URL("webcomponent-Cga3h8cx.js",document.baseURI).href).href;if(n.type==="module"&&(n!=null&&n.bind))try{const s=yield import(e);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):$.logger.error(`Module ${n.src} does not export a default function or init function.`)}catch(s){$.logger.error(`Failed to load component module ${n.src}`,s)}else n!=null&&n.bind?yield fetch(e).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(n.src,n.type)}for(const n of B)if(n.type==="module"){const e=document.createElement("script");e.type="module",e.textContent=n.content,((t=this.shadowRoot)!=null?t:this).appendChild(e)}else this._processScriptText(n.content);this._render()})}_injectScriptTag(t,n){return new Promise((e,s)=>{const i=document.createElement("script");i.src=t,n&&(i.type=n),i.onload=e,i.onerror=s,document.head.appendChild(i)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const n=this.getAttribute(t);this._handleAttributeChange(t,n)})}_setNestedState(t,n){const e=t.split(".");let s=this.state;for(let i=0;i<e.length-1;i++){const r=e[i];(typeof s[r]!="object"||s[r]===null)&&(s[r]={}),s=s[r]}s[e[e.length-1]]=n,this._render()}_bindTwoWayForElement(t){const n=t.getAttribute("data-bind"),e=t.isContentEditable,s="value"in t,i=e||s?"input":"change",r=()=>{const S=e?t.innerText:s?t.value:t.textContent;this._setNestedState(n,S)};t.addEventListener(i,r),this._eventBindings.push({element:t,event:i,listener:r});const l=s?"value":void 0,c=s?t.getAttribute("value")||`{${n}}`:e?t.innerHTML:t.textContent;this._bindings.push({element:t,key:n,attrName:l,template:c});const h=s?t.value:e?t.innerText:t.textContent;this._setNestedState(n,h)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),n={},e=(s,i,r)=>{const l=i.split(".");let c=s;for(let h=0;h<l.length-1;h++){const S=l[h];(typeof c[S]!="object"||c[S]===null)&&(c[S]={}),c=c[S]}c[l[l.length-1]]=r};t.forEach(s=>{const i=s.getAttribute("data-bind"),r=s.isContentEditable,l="value"in s,c=r?s.innerText.trim():l?s.value:s.textContent.trim();e(n,i,c)}),this.setState(n),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const n=Array.isArray(t)?t:[t],{node:e,template:s}=n[0];if(!e)return;const i={};n.forEach(({key:c})=>{var h;i[c]=(h=this.state[c])!=null?h:""});const r=this._renderTemplate(s,i);if(/<[a-z][\s\S]*>/i.test(r)){const c=document.createRange().createContextualFragment(r);e.nodeType===Node.TEXT_NODE?e.replaceWith(c):e.innerHTML=r}else e==null||e.nodeType,Node.TEXT_NODE,e.textContent=r}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:n,template:e,key:s})=>{var l;const i=(l=s.split(".").reduce((c,h)=>c==null?void 0:c[h],this.state))!=null?l:"",r=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(n,e.replace(r,i))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const e=(s=t.getAttribute("data-bind").split(".").reduce((i,r)=>i==null?void 0:i[r],this.state))!=null?s:"";t.isContentEditable?t.innerText!==e&&(t.innerText=e):"value"in t?t.value!==e&&(t.value=e):t.textContent!==e&&(t.textContent=e)})}_applyConditionals(){this._conditionals.forEach(t=>{let n=!1;t.forEach(({el:e,type:s,expr:i,placeholder:r})=>{let l=!1;if(s==="else")l=!n;else try{l=Function("state",`with(state){return(${i})}`)(this.state)}catch(c){l=!1}l&&!n?(!e.isConnected&&r.parentNode&&r.parentNode.insertBefore(e,r.nextSibling),r.remove(),n=!0):e.isConnected&&e.parentNode&&(e.parentNode.insertBefore(r,e),e.remove())})})}_renderTemplate(t,n){return t.replace(/\{\s*([-\w.]+)\s*}/g,(e,s)=>{let i=s.split(".").reduce((r,l)=>r==null?void 0:r[l],this.state);if(typeof i=="function")try{i=i.call(this)}catch(r){i=""}return i!=null?i:""})}_processScriptText(t){const n=new Set,e=new Set,s=new Set,i=new Map,r=o=>`__param_${o}_${Math.random().toString(36).substr(2,9)}`,l=(o,w)=>{let f=!1,a=!1,u=!1,p=!1;for(let d=0;d<w;d++){const g=o[d];if(p){p=!1;continue}if(g==="\\"){p=!0;continue}g==="'"&&!a&&!u?f=!f:g==='"'&&!f&&!u?a=!a:g==="`"&&!f&&!a&&(u=!u)}return f||a||u},c=(o,w,f)=>{let a=o;const u=[];let p;for(w.lastIndex=0;(p=w.exec(a))!==null;)u.push({index:p.index,length:p[0].length,originalContent:p[0],groups:p.slice(1)});for(let d=u.length-1;d>=0;d--){const g=u[d];if(!l(a,g.index)){const _=f(g.originalContent,...g.groups,g.index,a);a=a.substring(0,g.index)+_+a.substring(g.index+g.length)}}return a};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let h=t;h=c(h,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,w,f)=>{if(!f||!f.trim())return o;const a=f.split(",").map(d=>d.trim()).filter(d=>d);let u=!1;const p=a.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){u=!0;const _=r(g);return i.set(g,_),d.replace(g,_)}return d});return u?o.replace(f,p.join(", ")):o}),h=c(h,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,w,f)=>{if(!f||!f.trim())return o;const a=f.split(",").map(d=>d.trim()).filter(d=>d);let u=!1;const p=a.map(d=>{const g=d.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(g)){u=!0;const _=r(g);return i.set(g,_),d.replace(g,_)}return d});return u?o.replace(f,p.join(", ")):o});const C=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let R;for(;(R=C.exec(t))!==null;)n.add(R[1]);const U=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(R=U.exec(t))!==null;)n.add(R[2]);n.forEach(o=>{this._isBound(o)&&(new RegExp(`\\b${o}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${o}\\s*\\(`).test(t)||e.add(o))}),new Set([...e,...s]).forEach(o=>{h=c(h,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(f,a,u)=>`${a}${u}this.state.${o}`),h=c(h,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(f,a)=>`this.state.${o}${a}`),h=c(h,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(f,a,u,p,d)=>{const g=p+a.length;let _=d.substring(Math.max(0,g-10),g);return/\b(const|let|var)\s+$/.test(_)?f:`${a}this.state.${o} ${u||""}=`});const w=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");h=c(h,w,(f,a,u)=>{if(u.substring(Math.max(0,a-11),a).endsWith("this.state."))return f;const d=u.substring(Math.max(0,a-20),a),g=u.substring(a+f.length,Math.min(u.length,a+f.length+10));if(/[{,]\s*$/.test(d)&&/^\s*:/.test(g)||i.has(o)&&u.substring(Math.max(0,a-50),a).match(/([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(f))return f;const v=u.lastIndexOf(`
2
- `,a)+1,M=u.substring(v,a);if(/\b(?:const|let|var)\s+$/.test(M)||a>0&&u[a-1]===".")return f;let k=a+f.length;for(;k<u.length&&/\s/.test(u[k]);)k++;return k<u.length&&u[k]==="("?f:`this.state.${o}`})}),i.forEach((o,w)=>{const f=new RegExp(`\\b${w}\\b`,"g");h=c(h,f,(a,u,p)=>{const d=p.substring(0,u);if(d.includes(o)){let g=0,_=-1;for(let v=d.length-1;v>=0;v--)if(d[v]==="}")g++;else if(d[v]==="{"&&(g--,g<0)){_=v;break}if(_!==-1){const v=d.substring(0,_);if(v.substring(Math.max(0,v.lastIndexOf("(",_))).includes(o)){if(p.substring(Math.max(0,u-11),u).endsWith("this.state."))return a;const P=p.substring(u+a.length,Math.min(p.length,u+a.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(P)?a:o}}}return a})});let A="";n.size>0&&(A=`
3
-
4
- // --- Auto-processed by LadrillosJS Framework ---
5
- `,n.forEach(o=>{A+=`if (this._isBound('${o}')) {
6
- `,A+=` if (typeof ${o} === 'function') {
7
- `,A+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
8
- `,A+=` } else if (typeof ${o} !== 'undefined' && ${e.has(o)}) {
9
- `,A+=` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
10
- `,A+=` }
11
- `,A+=`}
12
- `}));const z=h+A;try{new Function(z).call(this)}catch(o){$.logger.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
13
- ---
14
- `+z+`
15
- ---
16
- Error details:`,o)}}_evalExpression(t,n,e,s){try{return new Function(`return (${t});`).call(this)}catch(i){let r,l;for(;r=e.exec(n);)if(this._functions.set(s,r[0]),l=r[1].trim(),l)try{return new Function(`${l}`).bind(this)}catch(c){return $.logger.error(c),l}return t}}_isBound(t){if(t in this.state)return!0;const n=this._eventBindings.some(i=>{if(!i.key)return!1;if(i.key===t)return!0;const r=i.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return r&&r[1]===t}),e=this._bindings.some(i=>Array.isArray(i)?i.some(r=>r.key===t||r.key.startsWith(t+".")):i.key===t||i.key.startsWith(t+".")),s=this._conditionals.some(i=>i.some(({expr:r})=>{if(!r)return!1;const l=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${l}\\b`).test(r)}));return n||e||s}emit(t,n){const e=n!=null?n:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}listen(t,n){const e=s=>n(s.detail);document.addEventListener(t,e),this._eventBindings.push({element:document,event:t,listener:e})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};E=new WeakSet,Z=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(n){return t}},j(W,E);let T=W;customElements.define(y,T),$.logger.log(`Web component defined: <${y}></${y}>`)};exports.defineWebComponent=X;