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