ladrillosjs 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{index-46umVYfZ.mjs → index-D_dHFObN.mjs} +1 -1
- package/dist/{index-dECyHgvF.js → index-X9YN_DbT.js} +1 -1
- package/dist/ladrillosjs.cjs.js +1 -1
- package/dist/ladrillosjs.es.js +1 -1
- package/dist/ladrillosjs.umd.js +14 -14
- package/dist/{webcomponent-Dntygkjn.js → webcomponent-Cga3h8cx.js} +12 -12
- package/dist/{webcomponent-lvbLxIns.mjs → webcomponent-UTcwAakf.mjs} +170 -158
- package/package.json +1 -1
|
@@ -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-
|
|
164
|
+
const { defineWebComponent: s } = yield import("./webcomponent-UTcwAakf.mjs");
|
|
165
165
|
s(this.components[e], t);
|
|
166
166
|
});
|
|
167
167
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use strict";var T=Object.defineProperty;var E=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,H=Object.prototype.propertyIsEnumerable;var W=r=>{throw TypeError(r)};var P=(r,e,t)=>e in r?T(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,x=(r,e)=>{for(var t in e||(e={}))j.call(e,t)&&P(r,t,e[t]);if(E)for(var t of E(e))H.call(e,t)&&P(r,t,e[t]);return r};var q=(r,e,t)=>e.has(r)||W("Cannot "+t);var d=(r,e,t)=>(q(r,e,"read from private field"),t?t.call(r):e.get(r)),y=(r,e,t)=>e.has(r)?W("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t);var v=(r,e,t)=>(q(r,e,"access private method"),t);var u=(r,e,t)=>new Promise((s,o)=>{var l=a=>{try{c(t.next(a))}catch(g){o(g)}},i=a=>{try{c(t.throw(a))}catch(g){o(g)}},c=a=>a.done?s(a.value):Promise.resolve(a.value).then(l,i);c((t=t.apply(r,e)).next())});const h={log(r,...e){},error(r,...e){console.error(r,...e)},warn(r,...e){}};var m,w,C,A;const S=class S{constructor(){y(this,m,new Map);y(this,w,new DOMParser);this.components={}}registerComponent(e,t,s=!0){return u(this,null,function*(){var o,l,i;if(this.components[e]){h.log(`Component ${e} already registered.`);return}this.components[e]={__registering:!0};try{const c=yield u(this,null,function*(){const n=d(this,m).get(t);if(n)return n;const k=yield(yield fetch(t)).text();return d(this,m).set(t,k),k}),a=d(this,w).parseFromString(c.replace(/<!--[\s\S]*?-->/g,""),"text/html"),g=[],$=[];for(const n of a.querySelectorAll("script")){if(n.src)$.push({src:n.src,type:(o=n.type)!=null?o:null,bind:n.hasAttribute("bind")});else if(n.textContent){let p=n.textContent.trim();p=p.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),g.push({content:p,type:(l=n.type)!=null?l:null})}n.remove()}let f="";for(const n of a.querySelectorAll("link[rel='stylesheet']"))f+=`
|
|
2
2
|
`+(yield v(i=S,C,A).call(i,`${n.href}?raw`)),n.remove();for(const n of a.querySelectorAll("style")){if(n.textContent){let p=n.textContent.trim();p=p.replace(/\/\*[\s\S]*?\*\//g,"").trim(),f+=`
|
|
3
|
-
`+p}n.remove()}f=f.trim(),this.components[e]={tagName:e,template:a.body.innerHTML.trim(),scripts:g,externalScripts:$,style:f},yield this._defineWebComponent(e,s),h.log(`Component ${e} registered successfully`)}catch(c){h.error(`Failed to register component ${e}:`,c),delete this.components[e]}})}registerComponents(e,t=5){return u(this,null,function*(){const s=e.map(({name:l,path:i,useShadowDOM:c})=>()=>this.registerComponent(l,i,c)),o=yield this._runWithConcurrency(s,t);return o.forEach((l,i)=>{if(l.status==="rejected"){const{name:c}=e[i];h.error(`registration failed for ${c}:`,l.reason)}}),o})}_runWithConcurrency(e,t){return u(this,null,function*(){const s=[],o=[];for(const l of e){let i;const c=l();s.push(c),i=c.then(()=>{o.splice(o.indexOf(i),1)}),o.push(i),o.length>=t&&(yield Promise.race(o))}return Promise.allSettled(s)})}_defineWebComponent(e,t){return u(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>require("./webcomponent-
|
|
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;
|
package/dist/ladrillosjs.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-X9YN_DbT.js");exports.createStore=e.createStore;exports.registerComponent=e.registerComponent;exports.registerComponents=e.registerComponents;
|
package/dist/ladrillosjs.es.js
CHANGED
package/dist/ladrillosjs.umd.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`+(yield
|
|
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,""")}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
|
-
`,
|
|
1
|
+
(function(m,b){typeof exports=="object"&&typeof module!="undefined"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis!="undefined"?globalThis:m||self,b(m.ladrillosjs={}))})(this,function(m){"use strict";var dt=Object.defineProperty;var it=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,gt=Object.prototype.propertyIsEnumerable;var ct=m=>{throw TypeError(m)};var ot=(m,b,a)=>b in m?dt(m,b,{enumerable:!0,configurable:!0,writable:!0,value:a}):m[b]=a,Y=(m,b)=>{for(var a in b||(b={}))pt.call(b,a)&&ot(m,a,b[a]);if(it)for(var a of it(b))gt.call(b,a)&&ot(m,a,b[a]);return m};var at=(m,b,a)=>b.has(m)||ct("Cannot "+a);var K=(m,b,a)=>(at(m,b,"read from private field"),a?a.call(m):b.get(m)),I=(m,b,a)=>b.has(m)?ct("Cannot add the same private member more than once"):b instanceof WeakSet?b.add(m):b.set(m,a);var tt=(m,b,a)=>(at(m,b,"access private method"),a);var L=(m,b,a)=>new Promise((q,z)=>{var Q=W=>{try{j(a.next(W))}catch(U){z(U)}},Z=W=>{try{j(a.throw(W))}catch(U){z(U)}},j=W=>W.done?q(W.value):Promise.resolve(W.value).then(Q,Z);j((a=a.apply(m,b)).next())});var V,J,D,lt;var b=typeof document!="undefined"?document.currentScript:null;const a={log(C,...f){},error(C,...f){console.error(C,...f)},warn(C,...f){}},X=class X{constructor(){I(this,V,new Map);I(this,J,new DOMParser);this.components={}}registerComponent(f,_,w=!0){return L(this,null,function*(){var S,A,x;if(this.components[f]){a.log(`Component ${f} already registered.`);return}this.components[f]={__registering:!0};try{const v=yield L(this,null,function*(){const t=K(this,V).get(_);if(t)return t;const n=yield(yield fetch(_)).text();return K(this,V).set(_,n),n}),B=K(this,J).parseFromString(v.replace(/<!--[\s\S]*?-->/g,""),"text/html"),et=[],P=[];for(const t of B.querySelectorAll("script")){if(t.src)P.push({src:t.src,type:(S=t.type)!=null?S:null,bind:t.hasAttribute("bind")});else if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim(),et.push({content:e,type:(A=t.type)!=null?A:null})}t.remove()}let H="";for(const t of B.querySelectorAll("link[rel='stylesheet']"))H+=`
|
|
2
|
+
`+(yield tt(x=X,D,lt).call(x,`${t.href}?raw`)),t.remove();for(const t of B.querySelectorAll("style")){if(t.textContent){let e=t.textContent.trim();e=e.replace(/\/\*[\s\S]*?\*\//g,"").trim(),H+=`
|
|
3
|
+
`+e}t.remove()}H=H.trim(),this.components[f]={tagName:f,template:B.body.innerHTML.trim(),scripts:et,externalScripts:P,style:H},yield this._defineWebComponent(f,w),a.log(`Component ${f} registered successfully`)}catch(v){a.error(`Failed to register component ${f}:`,v),delete this.components[f]}})}registerComponents(f,_=5){return L(this,null,function*(){const w=f.map(({name:A,path:x,useShadowDOM:v})=>()=>this.registerComponent(A,x,v)),S=yield this._runWithConcurrency(w,_);return S.forEach((A,x)=>{if(A.status==="rejected"){const{name:v}=f[x];a.error(`registration failed for ${v}:`,A.reason)}}),S})}_runWithConcurrency(f,_){return L(this,null,function*(){const w=[],S=[];for(const A of f){let x;const v=A();w.push(v),x=v.then(()=>{S.splice(S.indexOf(x),1)}),S.push(x),S.length>=_&&(yield Promise.race(S))}return Promise.allSettled(w)})}_defineWebComponent(f,_){return L(this,null,function*(){const{defineWebComponent:w}=yield Promise.resolve().then(()=>ft);w(this.components[f],_)})}};V=new WeakMap,J=new WeakMap,D=new WeakSet,lt=function(f){return L(this,null,function*(){try{const _=yield fetch(f);if(!_.ok)throw new Error(`HTTP ${_.status}`);return yield _.text()}catch(_){return a.error(`Failed to fetch resource at ${f}:`,_),""}})},I(X,D);let q=X;const z=new q;function Q(C={}){let f=C;const _=new Set;return{getState(){return f},setState(w){f=Y(Y({},f),w),_.forEach(S=>S(f))},subscribe(w){return _.add(w),w(f),()=>_.delete(w)},reset(){f=C,_.forEach(w=>w(f))}}}const Z=(...C)=>z.registerComponent(...C),j=(...C)=>z.registerComponents(...C);typeof window!="undefined"&&(window.ladrillosjs={registerComponent:Z,registerComponents:j});function W(C,f){return JSON.stringify(C,(_,w)=>typeof w=="string"?w.replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r"):w,f).replace(/"/g,""")}const ft=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(C,f)=>{var B,ut;const{tagName:_,template:w,scripts:S,externalScripts:A,style:x}=C,P=class P extends HTMLElement{constructor(){super(),f&&this.attachShadow({mode:"open"}),this.root=f?this.shadowRoot:document,this.stringify=W;const t={};this.state=new Proxy(t,{set:(e,n,s)=>(e[n]=s,this._render(),!0)}),this._bindings=[],this._eventBindings=[],this._conditionals=[],this._initObservers()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._initializeStateFromAttributes(),this._loadScript(),this._setupTwoWayBindings()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:t,event:e,listener:n})=>{t.removeEventListener(e,n)}),this._eventBindings=[]}_initObservers(){this.observer=this._createObserver(t=>{t.forEach(e=>{if(e.type==="attributes"){const n=e.attributeName,s=this.getAttribute(n);this._handleAttributeChange(n,s)}})},this,{attributes:!0,attributeOldValue:!0}),this.elementObserver=this._createObserver(t=>{for(const e of t)if(e.attributeName==="contenteditable"){const n=e.target;n.isContentEditable&&n.hasAttribute("data-bind")&&this._bindTwoWayForElement(n)}},this.root,{attributes:!0,subtree:!0,attributeFilter:["contenteditable"]})}_createObserver(t,e,n){const s=new MutationObserver(t.bind(this));return s.observe(e,n),s}_handleAttributeChange(t,e){var s;if(t){const r="this.state.";t.startsWith(r)&&(t=t.slice(r.length))}const n=tt(s=P,B,ut).call(s,e);this.state[t]=n,this._render()}_loadTemplate(){f?this.shadowRoot.innerHTML=w:this.innerHTML=w,this._scanBindings()}_scanBindings(){const t=document.createTreeWalker(this.root,NodeFilter.SHOW_TEXT,null,!1);let e;for(;e=t.nextNode();){const n=[...e.textContent.matchAll(/{([^}]+)}/g)];if(n.length){const s=n.map(([,r])=>({node:e,template:e.textContent,key:r.trim()}));this._bindings.push(s)}}this.root.querySelectorAll("*").forEach(n=>{Array.from(n.attributes).forEach(s=>{const r=[...s.value.matchAll(/{([^}]+)}/g)];r.length&&r.forEach(([,i])=>{this._bindings.push({element:n,attrName:s.name,template:s.value,key:i.trim()})})})}),this._getEventBindings(),this._scanConditionals()}_getEventBindings(){this.root.querySelectorAll("*").forEach(t=>{Array.from(t.attributes).forEach(e=>{if(!e.name.startsWith("on"))return;const n=e.name.slice(2),s=e.value.trim();t.removeAttribute(e.name);let r;const i=s.trim();if(/^\([^)]*\)\s*=>/.test(i))try{const l=new Function("event",`return (${i});`).call(this);r=d=>l(d)}catch(u){a.error(`Error parsing inline arrow function handler: ${i}`,u),r=()=>{}}else i.includes("(")&&i.includes(")")?r=u=>{try{const l=i.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/);if(l){const[,d,k]=l,G=this[d]||this.state[d];if(typeof G=="function"){let O=[];if(k.trim())try{O=new Function("event",`return [${k}]`).call(this,u)}catch(M){a.error(`Error parsing arguments for ${d}:`,M),O=[]}return G.apply(this,O)}else a.warn(`Function "${d}" not found in component context. Available functions:`,Object.keys(this).filter(O=>typeof this[O]=="function").concat(Object.keys(this.state).filter(O=>typeof this.state[O]=="function")))}else new Function("event",i).call(this,u)}catch(l){a.error(`Error executing inline event handler: ${i}`,l)}}:r=u=>{const l=this[i];if(typeof l=="function")try{return l.call(this,u)}catch(d){a.error(`Error executing event handler method: ${i}`,d)}else a.warn(`Event handler method "${i}" not found on component. Available methods on 'this':`,Object.keys(this).filter(d=>typeof this[d]=="function"))};t.addEventListener(n,r),this._eventBindings.push({key:s,element:t,event:n,listener:r})})})}_scanConditionals(){this._conditionals=[];const t=Array.from(this.root.querySelectorAll("[data-if], [data-else-if], [data-else]"));let e=[];t.forEach(n=>{const s=n.hasAttribute("data-if");s&&e.length&&(this._conditionals.push(e),e=[]);const r=s?"if":n.hasAttribute("data-else-if")?"else-if":"else",i=r==="else"?null:n.getAttribute(r==="if"?"data-if":"data-else-if"),u=document.createComment(`ladrillos-${r}`);n.parentNode.insertBefore(u,n),n.remove(),e.push({el:n,type:r,expr:i,placeholder:u})}),e.length&&this._conditionals.push(e)}_loadStyles(){if(!x)return;const t=document.createElement("style");t.textContent=x,f?this.root.appendChild(t):this.root.head.appendChild(t)}_loadScript(){return L(this,null,function*(){var t;for(const e of A){const n=new URL(e.src,typeof document=="undefined"&&typeof location=="undefined"?require("url").pathToFileURL(__filename).href:typeof document=="undefined"?location.href:b&&b.tagName.toUpperCase()==="SCRIPT"&&b.src||new URL("ladrillosjs.umd.js",document.baseURI).href).href;if(e.type==="module"&&(e!=null&&e.bind))try{const s=yield import(n);typeof s.default=="function"?s.default.call(this):typeof s.init=="function"?s.init.call(this):a.error(`Module ${e.src} does not export a default function or init function.`)}catch(s){a.error(`Failed to load component module ${e.src}`,s)}else e!=null&&e.bind?yield fetch(n).then(s=>s.text()).then(s=>this._processScriptText(s.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,"").trim())):yield this._injectScriptTag(e.src,e.type)}for(const e of S)if(e.type==="module"){const n=document.createElement("script");n.type="module",n.textContent=e.content,((t=this.shadowRoot)!=null?t:this).appendChild(n)}else this._processScriptText(e.content);this._render()})}_injectScriptTag(t,e){return new Promise((n,s)=>{const r=document.createElement("script");r.src=t,e&&(r.type=e),r.onload=n,r.onerror=s,document.head.appendChild(r)})}_initializeStateFromAttributes(){this.getAttributeNames().forEach(t=>{const e=this.getAttribute(t);this._handleAttributeChange(t,e)})}_setNestedState(t,e){const n=t.split(".");let s=this.state;for(let r=0;r<n.length-1;r++){const i=n[r];(typeof s[i]!="object"||s[i]===null)&&(s[i]={}),s=s[i]}s[n[n.length-1]]=e,this._render()}_bindTwoWayForElement(t){const e=t.getAttribute("data-bind"),n=t.isContentEditable,s="value"in t,r=n||s?"input":"change",i=()=>{const k=n?t.innerText:s?t.value:t.textContent;this._setNestedState(e,k)};t.addEventListener(r,i),this._eventBindings.push({element:t,event:r,listener:i});const u=s?"value":void 0,l=s?t.getAttribute("value")||`{${e}}`:n?t.innerHTML:t.textContent;this._bindings.push({element:t,key:e,attrName:u,template:l});const d=s?t.value:n?t.innerText:t.textContent;this._setNestedState(e,d)}_setupTwoWayBindings(){const t=this.root.querySelectorAll("[data-bind]"),e={},n=(s,r,i)=>{const u=r.split(".");let l=s;for(let d=0;d<u.length-1;d++){const k=u[d];(typeof l[k]!="object"||l[k]===null)&&(l[k]={}),l=l[k]}l[u[u.length-1]]=i};t.forEach(s=>{const r=s.getAttribute("data-bind"),i=s.isContentEditable,u="value"in s,l=i?s.innerText.trim():u?s.value:s.textContent.trim();n(e,r,l)}),this.setState(e),t.forEach(s=>{this._bindTwoWayForElement(s)})}_render(){this._applyConditionals(),this._bindings.forEach(t=>{const e=Array.isArray(t)?t:[t],{node:n,template:s}=e[0];if(!n)return;const r={};e.forEach(({key:l})=>{var d;r[l]=(d=this.state[l])!=null?d:""});const i=this._renderTemplate(s,r);if(/<[a-z][\s\S]*>/i.test(i)){const l=document.createRange().createContextualFragment(i);n.nodeType===Node.TEXT_NODE?n.replaceWith(l):n.innerHTML=i}else n==null||n.nodeType,Node.TEXT_NODE,n.textContent=i}),this._bindings.filter(t=>t.element).forEach(({element:t,attrName:e,template:n,key:s})=>{var u;const r=(u=s.split(".").reduce((l,d)=>l==null?void 0:l[d],this.state))!=null?u:"",i=new RegExp(`\\{\\s*${s}\\s*\\}`,"g");t.setAttribute(e,n.replace(i,r))}),this.root.querySelectorAll("[data-bind]").forEach(t=>{var s;const n=(s=t.getAttribute("data-bind").split(".").reduce((r,i)=>r==null?void 0:r[i],this.state))!=null?s:"";t.isContentEditable?t.innerText!==n&&(t.innerText=n):"value"in t?t.value!==n&&(t.value=n):t.textContent!==n&&(t.textContent=n)})}_applyConditionals(){this._conditionals.forEach(t=>{let e=!1;t.forEach(({el:n,type:s,expr:r,placeholder:i})=>{let u=!1;if(s==="else")u=!e;else try{u=Function("state",`with(state){return(${r})}`)(this.state)}catch(l){u=!1}u&&!e?(!n.isConnected&&i.parentNode&&i.parentNode.insertBefore(n,i.nextSibling),i.remove(),e=!0):n.isConnected&&n.parentNode&&(n.parentNode.insertBefore(i,n),n.remove())})})}_renderTemplate(t,e){return t.replace(/\{\s*([-\w.]+)\s*}/g,(n,s)=>{let r=s.split(".").reduce((i,u)=>i==null?void 0:i[u],this.state);if(typeof r=="function")try{r=r.call(this)}catch(i){r=""}return r!=null?r:""})}_processScriptText(t){const e=new Set,n=new Set,s=new Set,r=new Map,i=o=>`__param_${o}_${Math.random().toString(36).substr(2,9)}`,u=(o,T)=>{let p=!1,c=!1,h=!1,E=!1;for(let g=0;g<T;g++){const y=o[g];if(E){E=!1;continue}if(y==="\\"){E=!0;continue}y==="'"&&!c&&!h?p=!p:y==='"'&&!p&&!h?c=!c:y==="`"&&!p&&!c&&(h=!h)}return p||c||h},l=(o,T,p)=>{let c=o;const h=[];let E;for(T.lastIndex=0;(E=T.exec(c))!==null;)h.push({index:E.index,length:E[0].length,originalContent:E[0],groups:E.slice(1)});for(let g=h.length-1;g>=0;g--){const y=h[g];if(!u(c,y.index)){const $=p(y.originalContent,...y.groups,y.index,c);c=c.substring(0,y.index)+$+c.substring(y.index+y.length)}}return c};Object.keys(this.state).forEach(o=>{this._isBound(o)&&s.add(o)});let d=t;d=l(d,/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,(o,T,p)=>{if(!p||!p.trim())return o;const c=p.split(",").map(g=>g.trim()).filter(g=>g);let h=!1;const E=c.map(g=>{const y=g.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){h=!0;const $=i(y);return r.set(y,$),g.replace(y,$)}return g});return h?o.replace(p,E.join(", ")):o}),d=l(d,/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,(o,T,p)=>{if(!p||!p.trim())return o;const c=p.split(",").map(g=>g.trim()).filter(g=>g);let h=!1;const E=c.map(g=>{const y=g.split("=")[0].trim().replace(/[{}[\]]/g,"");if(this._isBound(y)){h=!0;const $=i(y);return r.set(y,$),g.replace(y,$)}return g});return h?o.replace(p,E.join(", ")):o});const O=/\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;let M;for(;(M=O.exec(t))!==null;)e.add(M[1]);const ht=/\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;for(;(M=ht.exec(t))!==null;)e.add(M[2]);e.forEach(o=>{this._isBound(o)&&(new RegExp(`\\b${o}\\s*=\\s*(?:function|\\([^)]*\\)\\s*=>|[^=]+=>)`,"g").test(t)||new RegExp(`\\bfunction\\s+${o}\\s*\\(`).test(t)||n.add(o))}),new Set([...n,...s]).forEach(o=>{d=l(d,new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`,"g"),(p,c,h)=>`${c}${h}this.state.${o}`),d=l(d,new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`,"g"),(p,c)=>`this.state.${o}${c}`),d=l(d,new RegExp(`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,"g"),(p,c,h,E,g)=>{const y=E+c.length;let $=g.substring(Math.max(0,y-10),y);return/\b(const|let|var)\s+$/.test($)?p:`${c}this.state.${o} ${h||""}=`});const T=new RegExp(`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,"g");d=l(d,T,(p,c,h)=>{if(h.substring(Math.max(0,c-11),c).endsWith("this.state."))return p;const g=h.substring(Math.max(0,c-20),c),y=h.substring(c+p.length,Math.min(h.length,c+p.length+10));if(/[{,]\s*$/.test(g)&&/^\s*:/.test(y)||r.has(o)&&h.substring(Math.max(0,c-50),c).match(/([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/)||["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","let","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield"].includes(p))return p;const R=h.lastIndexOf(`
|
|
4
|
+
`,c)+1,st=h.substring(R,c);if(/\b(?:const|let|var)\s+$/.test(st)||c>0&&h[c-1]===".")return p;let N=c+p.length;for(;N<h.length&&/\s/.test(h[N]);)N++;return N<h.length&&h[N]==="("?p:`this.state.${o}`})}),r.forEach((o,T)=>{const p=new RegExp(`\\b${T}\\b`,"g");d=l(d,p,(c,h,E)=>{const g=E.substring(0,h);if(g.includes(o)){let y=0,$=-1;for(let R=g.length-1;R>=0;R--)if(g[R]==="}")y++;else if(g[R]==="{"&&(y--,y<0)){$=R;break}if($!==-1){const R=g.substring(0,$);if(R.substring(Math.max(0,R.lastIndexOf("(",$))).includes(o)){if(E.substring(Math.max(0,h-11),h).endsWith("this.state."))return c;const rt=E.substring(h+c.length,Math.min(E.length,h+c.length+20));return/^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(rt)?c:o}}}return c})});let F="";e.size>0&&(F=`
|
|
5
5
|
|
|
6
6
|
// --- Auto-processed by LadrillosJS Framework ---
|
|
7
|
-
`,e.forEach(o=>{
|
|
8
|
-
`,
|
|
9
|
-
`,
|
|
10
|
-
`,
|
|
11
|
-
`,
|
|
12
|
-
`,
|
|
13
|
-
`,
|
|
14
|
-
`}));const
|
|
7
|
+
`,e.forEach(o=>{F+=`if (this._isBound('${o}')) {
|
|
8
|
+
`,F+=` if (typeof ${o} === 'function') {
|
|
9
|
+
`,F+=` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
|
|
10
|
+
`,F+=` } else if (typeof ${o} !== 'undefined' && ${n.has(o)}) {
|
|
11
|
+
`,F+=` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
|
|
12
|
+
`,F+=` }
|
|
13
|
+
`,F+=`}
|
|
14
|
+
`}));const nt=d+F;try{new Function(nt).call(this)}catch(o){a.error("Error executing component script:",o),console.error(`LadrillosJS: Error executing component script. Processed script was:
|
|
15
15
|
---
|
|
16
|
-
`+
|
|
16
|
+
`+nt+`
|
|
17
17
|
---
|
|
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(
|
|
18
|
+
Error details:`,o)}}_evalExpression(t,e,n,s){try{return new Function(`return (${t});`).call(this)}catch(r){let i,u;for(;i=n.exec(e);)if(this._functions.set(s,i[0]),u=i[1].trim(),u)try{return new Function(`${u}`).bind(this)}catch(l){return a.error(l),u}return t}}_isBound(t){if(t in this.state)return!0;const e=this._eventBindings.some(r=>{if(!r.key)return!1;if(r.key===t)return!0;const i=r.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return i&&i[1]===t}),n=this._bindings.some(r=>Array.isArray(r)?r.some(i=>i.key===t||i.key.startsWith(t+".")):r.key===t||r.key.startsWith(t+".")),s=this._conditionals.some(r=>r.some(({expr:i})=>{if(!i)return!1;const u=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${u}\\b`).test(i)}));return e||n||s}emit(t,e){const n=e!=null?e:this.state;this.dispatchEvent(new CustomEvent(t,{detail:n,bubbles:!0,composed:!0}))}listen(t,e){const n=s=>e(s.detail);document.addEventListener(t,n),this._eventBindings.push({element:document,event:t,listener:n})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};B=new WeakSet,ut=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(e){return t}},I(P,B);let v=P;customElements.define(_,v),a.log(`Web component defined: <${_}></${_}>`)}},Symbol.toStringTag,{value:"Module"}));m.createStore=Q,m.registerComponent=Z,m.registerComponents=j,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -1,16 +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,""")}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
|
-
`,
|
|
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,""")}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
3
|
|
|
4
4
|
// --- Auto-processed by LadrillosJS Framework ---
|
|
5
|
-
`,n.forEach(o=>{
|
|
6
|
-
`,
|
|
7
|
-
`,
|
|
8
|
-
`,
|
|
9
|
-
`,
|
|
10
|
-
`,
|
|
11
|
-
`,
|
|
12
|
-
`}));const
|
|
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
13
|
---
|
|
14
|
-
`+
|
|
14
|
+
`+z+`
|
|
15
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(
|
|
16
|
+
Error details:`,o)}}_evalExpression(t,n,e,s){try{return new Function(`return (${t});`).call(this)}catch(i){let r,l;for(;r=e.exec(n);)if(this._functions.set(s,r[0]),l=r[1].trim(),l)try{return new Function(`${l}`).bind(this)}catch(c){return $.logger.error(c),l}return t}}_isBound(t){if(t in this.state)return!0;const n=this._eventBindings.some(i=>{if(!i.key)return!1;if(i.key===t)return!0;const r=i.key.match(/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/);return r&&r[1]===t}),e=this._bindings.some(i=>Array.isArray(i)?i.some(r=>r.key===t||r.key.startsWith(t+".")):i.key===t||i.key.startsWith(t+".")),s=this._conditionals.some(i=>i.some(({expr:r})=>{if(!r)return!1;const l=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return new RegExp(`\\b${l}\\b`).test(r)}));return n||e||s}emit(t,n){const e=n!=null?n:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0,composed:!0}))}listen(t,n){const e=s=>n(s.detail);document.addEventListener(t,e),this._eventBindings.push({element:document,event:t,listener:e})}setState(t){Object.assign(this.state,t),this._render()}querySelector(t){return this.root.querySelector(t)}querySelectorAll(t){return this.root.querySelectorAll(t)}};E=new WeakSet,Z=function(t){if(t==="")return null;if(t!=="undefined")try{return JSON.parse(t)}catch(n){return t}},j(W,E);let T=W;customElements.define(y,T),$.logger.log(`Web component defined: <${y}></${y}>`)};exports.defineWebComponent=X;
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
var
|
|
2
|
-
throw TypeError(
|
|
1
|
+
var q = (m) => {
|
|
2
|
+
throw TypeError(m);
|
|
3
3
|
};
|
|
4
|
-
var J = (
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
4
|
+
var J = (m, b, y) => b.has(m) || q("Cannot " + y);
|
|
5
|
+
var P = (m, b, y) => b.has(m) ? q("Cannot add the same private member more than once") : b instanceof WeakSet ? b.add(m) : b.set(m, y);
|
|
6
|
+
var j = (m, b, y) => (J(m, b, "access private method"), y);
|
|
7
|
+
var H = (m, b, y) => new Promise((x, B) => {
|
|
8
|
+
var O = (E) => {
|
|
9
9
|
try {
|
|
10
|
-
T(
|
|
11
|
-
} catch (
|
|
12
|
-
|
|
10
|
+
T(y.next(E));
|
|
11
|
+
} catch (F) {
|
|
12
|
+
B(F);
|
|
13
13
|
}
|
|
14
|
-
},
|
|
14
|
+
}, L = (E) => {
|
|
15
15
|
try {
|
|
16
|
-
T(
|
|
17
|
-
} catch (
|
|
18
|
-
|
|
16
|
+
T(y.throw(E));
|
|
17
|
+
} catch (F) {
|
|
18
|
+
B(F);
|
|
19
19
|
}
|
|
20
|
-
}, T = (
|
|
21
|
-
T((
|
|
20
|
+
}, T = (E) => E.done ? x(E.value) : Promise.resolve(E.value).then(O, L);
|
|
21
|
+
T((y = y.apply(m, b)).next());
|
|
22
22
|
});
|
|
23
|
-
import { l as
|
|
24
|
-
function D(
|
|
23
|
+
import { l as w } from "./index-D_dHFObN.mjs";
|
|
24
|
+
function D(m, b) {
|
|
25
25
|
return JSON.stringify(
|
|
26
|
-
|
|
27
|
-
(
|
|
26
|
+
m,
|
|
27
|
+
(y, x) => typeof x == "string" ? x.replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r") : x,
|
|
28
28
|
b
|
|
29
29
|
).replace(/"/g, """);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
32
|
-
var
|
|
33
|
-
const { tagName:
|
|
31
|
+
const G = (m, b) => {
|
|
32
|
+
var E, Z;
|
|
33
|
+
const { tagName: y, template: x, scripts: B, externalScripts: O, style: L } = m, W = class W extends HTMLElement {
|
|
34
34
|
constructor() {
|
|
35
35
|
super(), b && this.attachShadow({ mode: "open" }), this.root = b ? this.shadowRoot : document, this.stringify = D;
|
|
36
36
|
const t = {};
|
|
@@ -91,12 +91,12 @@ const Q = (y, b) => {
|
|
|
91
91
|
const i = "this.state.";
|
|
92
92
|
t.startsWith(i) && (t = t.slice(i.length));
|
|
93
93
|
}
|
|
94
|
-
const e =
|
|
94
|
+
const e = j(s = W, E, Z).call(s, n);
|
|
95
95
|
this.state[t] = e, this._render();
|
|
96
96
|
}
|
|
97
97
|
// sets template to innerHTML or shadowRoot.innerHTML
|
|
98
98
|
_loadTemplate() {
|
|
99
|
-
b ? this.shadowRoot.innerHTML =
|
|
99
|
+
b ? this.shadowRoot.innerHTML = x : this.innerHTML = x, this._scanBindings();
|
|
100
100
|
}
|
|
101
101
|
// scans the template for bindings and event handlers
|
|
102
102
|
// and stores them in this._bindings and this._eventBindings
|
|
@@ -145,10 +145,10 @@ const Q = (y, b) => {
|
|
|
145
145
|
const r = s.trim();
|
|
146
146
|
if (/^\([^)]*\)\s*=>/.test(r))
|
|
147
147
|
try {
|
|
148
|
-
const
|
|
149
|
-
i = (u) =>
|
|
148
|
+
const c = new Function("event", `return (${r});`).call(this);
|
|
149
|
+
i = (u) => c(u);
|
|
150
150
|
} catch (l) {
|
|
151
|
-
|
|
151
|
+
w.error(
|
|
152
152
|
`Error parsing inline arrow function handler: ${r}`,
|
|
153
153
|
l
|
|
154
154
|
), i = () => {
|
|
@@ -156,56 +156,56 @@ const Q = (y, b) => {
|
|
|
156
156
|
}
|
|
157
157
|
else r.includes("(") && r.includes(")") ? i = (l) => {
|
|
158
158
|
try {
|
|
159
|
-
const
|
|
159
|
+
const c = r.match(
|
|
160
160
|
/^([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\((.*)\)$/
|
|
161
161
|
);
|
|
162
|
-
if (
|
|
163
|
-
const [, u,
|
|
164
|
-
if (typeof
|
|
165
|
-
let
|
|
166
|
-
if (
|
|
162
|
+
if (c) {
|
|
163
|
+
const [, u, S] = c, N = this[u] || this.state[u];
|
|
164
|
+
if (typeof N == "function") {
|
|
165
|
+
let A = [];
|
|
166
|
+
if (S.trim())
|
|
167
167
|
try {
|
|
168
|
-
|
|
168
|
+
A = new Function(
|
|
169
169
|
"event",
|
|
170
|
-
`return [${
|
|
170
|
+
`return [${S}]`
|
|
171
171
|
).call(this, l);
|
|
172
172
|
} catch (k) {
|
|
173
|
-
|
|
173
|
+
w.error(
|
|
174
174
|
`Error parsing arguments for ${u}:`,
|
|
175
175
|
k
|
|
176
|
-
),
|
|
176
|
+
), A = [];
|
|
177
177
|
}
|
|
178
|
-
return
|
|
178
|
+
return N.apply(this, A);
|
|
179
179
|
} else
|
|
180
|
-
|
|
180
|
+
w.warn(
|
|
181
181
|
`Function "${u}" not found in component context. Available functions:`,
|
|
182
|
-
Object.keys(this).filter((
|
|
182
|
+
Object.keys(this).filter((A) => typeof this[A] == "function").concat(
|
|
183
183
|
Object.keys(this.state).filter(
|
|
184
|
-
(
|
|
184
|
+
(A) => typeof this.state[A] == "function"
|
|
185
185
|
)
|
|
186
186
|
)
|
|
187
187
|
);
|
|
188
188
|
} else
|
|
189
189
|
new Function("event", r).call(this, l);
|
|
190
|
-
} catch (
|
|
191
|
-
|
|
190
|
+
} catch (c) {
|
|
191
|
+
w.error(
|
|
192
192
|
`Error executing inline event handler: ${r}`,
|
|
193
|
-
|
|
193
|
+
c
|
|
194
194
|
);
|
|
195
195
|
}
|
|
196
196
|
} : i = (l) => {
|
|
197
|
-
const
|
|
198
|
-
if (typeof
|
|
197
|
+
const c = this[r];
|
|
198
|
+
if (typeof c == "function")
|
|
199
199
|
try {
|
|
200
|
-
return
|
|
200
|
+
return c.call(this, l);
|
|
201
201
|
} catch (u) {
|
|
202
|
-
|
|
202
|
+
w.error(
|
|
203
203
|
`Error executing event handler method: ${r}`,
|
|
204
204
|
u
|
|
205
205
|
);
|
|
206
206
|
}
|
|
207
207
|
else
|
|
208
|
-
|
|
208
|
+
w.warn(
|
|
209
209
|
`Event handler method "${r}" not found on component. Available methods on 'this':`,
|
|
210
210
|
Object.keys(this).filter((u) => typeof this[u] == "function")
|
|
211
211
|
);
|
|
@@ -236,25 +236,25 @@ const Q = (y, b) => {
|
|
|
236
236
|
}
|
|
237
237
|
// loads the styles into the shadowRoot or document head
|
|
238
238
|
_loadStyles() {
|
|
239
|
-
if (!
|
|
239
|
+
if (!L) return;
|
|
240
240
|
const t = document.createElement("style");
|
|
241
|
-
t.textContent =
|
|
241
|
+
t.textContent = L, b ? this.root.appendChild(t) : this.root.head.appendChild(t);
|
|
242
242
|
}
|
|
243
243
|
// loads the external scripts and inline scripts
|
|
244
244
|
// and binds them to the component context
|
|
245
245
|
_loadScript() {
|
|
246
|
-
return
|
|
246
|
+
return H(this, null, function* () {
|
|
247
247
|
var t;
|
|
248
|
-
for (const n of
|
|
248
|
+
for (const n of O) {
|
|
249
249
|
const e = new URL(n.src, import.meta.url).href;
|
|
250
250
|
if (n.type === "module" && (n != null && n.bind))
|
|
251
251
|
try {
|
|
252
252
|
const s = yield import(e);
|
|
253
|
-
typeof s.default == "function" ? s.default.call(this) : typeof s.init == "function" ? s.init.call(this) :
|
|
253
|
+
typeof s.default == "function" ? s.default.call(this) : typeof s.init == "function" ? s.init.call(this) : w.error(
|
|
254
254
|
`Module ${n.src} does not export a default function or init function.`
|
|
255
255
|
);
|
|
256
256
|
} catch (s) {
|
|
257
|
-
|
|
257
|
+
w.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 Q = (y, b) => {
|
|
|
262
262
|
)
|
|
263
263
|
) : yield this._injectScriptTag(n.src, n.type);
|
|
264
264
|
}
|
|
265
|
-
for (const n of
|
|
265
|
+
for (const n of B)
|
|
266
266
|
if (n.type === "module") {
|
|
267
267
|
const e = document.createElement("script");
|
|
268
268
|
e.type = "module", e.textContent = n.content, ((t = this.shadowRoot) != null ? t : this).appendChild(e);
|
|
@@ -302,12 +302,12 @@ const Q = (y, b) => {
|
|
|
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
|
|
306
|
-
this._setNestedState(n,
|
|
305
|
+
const S = e ? t.innerText : s ? t.value : t.textContent;
|
|
306
|
+
this._setNestedState(n, S);
|
|
307
307
|
};
|
|
308
308
|
t.addEventListener(i, r), this._eventBindings.push({ element: t, event: i, listener: r });
|
|
309
|
-
const l = s ? "value" : void 0,
|
|
310
|
-
this._bindings.push({ element: t, key: n, attrName: l, template:
|
|
309
|
+
const l = s ? "value" : void 0, c = s ? t.getAttribute("value") || `{${n}}` : e ? t.innerHTML : t.textContent;
|
|
310
|
+
this._bindings.push({ element: t, key: n, attrName: l, template: c });
|
|
311
311
|
const u = s ? t.value : e ? t.innerText : t.textContent;
|
|
312
312
|
this._setNestedState(n, u);
|
|
313
313
|
}
|
|
@@ -316,16 +316,16 @@ const Q = (y, b) => {
|
|
|
316
316
|
_setupTwoWayBindings() {
|
|
317
317
|
const t = this.root.querySelectorAll("[data-bind]"), n = {}, e = (s, i, r) => {
|
|
318
318
|
const l = i.split(".");
|
|
319
|
-
let
|
|
319
|
+
let c = s;
|
|
320
320
|
for (let u = 0; u < l.length - 1; u++) {
|
|
321
|
-
const
|
|
322
|
-
(typeof
|
|
321
|
+
const S = l[u];
|
|
322
|
+
(typeof c[S] != "object" || c[S] === null) && (c[S] = {}), c = c[S];
|
|
323
323
|
}
|
|
324
|
-
|
|
324
|
+
c[l[l.length - 1]] = r;
|
|
325
325
|
};
|
|
326
326
|
t.forEach((s) => {
|
|
327
|
-
const i = s.getAttribute("data-bind"), r = s.isContentEditable, l = "value" in s,
|
|
328
|
-
e(n, i,
|
|
327
|
+
const i = s.getAttribute("data-bind"), r = s.isContentEditable, l = "value" in s, c = r ? s.innerText.trim() : l ? s.value : s.textContent.trim();
|
|
328
|
+
e(n, i, c);
|
|
329
329
|
}), this.setState(n), t.forEach((s) => {
|
|
330
330
|
this._bindTwoWayForElement(s);
|
|
331
331
|
});
|
|
@@ -337,19 +337,19 @@ const Q = (y, b) => {
|
|
|
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:
|
|
340
|
+
n.forEach(({ key: c }) => {
|
|
341
341
|
var u;
|
|
342
|
-
i[
|
|
342
|
+
i[c] = (u = this.state[c]) != null ? u : "";
|
|
343
343
|
});
|
|
344
344
|
const r = this._renderTemplate(s, i);
|
|
345
345
|
if (/<[a-z][\s\S]*>/i.test(r)) {
|
|
346
|
-
const
|
|
347
|
-
e.nodeType === Node.TEXT_NODE ? e.replaceWith(
|
|
346
|
+
const c = document.createRange().createContextualFragment(r);
|
|
347
|
+
e.nodeType === Node.TEXT_NODE ? e.replaceWith(c) : 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
351
|
var l;
|
|
352
|
-
const i = (l = s.split(".").reduce((
|
|
352
|
+
const i = (l = s.split(".").reduce((c, u) => c == null ? void 0 : c[u], this.state)) != null ? l : "", r = new RegExp(`\\{\\s*${s}\\s*\\}`, "g");
|
|
353
353
|
t.setAttribute(n, e.replace(r, i));
|
|
354
354
|
}), this.root.querySelectorAll("[data-bind]").forEach((t) => {
|
|
355
355
|
var s;
|
|
@@ -371,7 +371,7 @@ const Q = (y, b) => {
|
|
|
371
371
|
"state",
|
|
372
372
|
`with(state){return(${i})}`
|
|
373
373
|
)(this.state);
|
|
374
|
-
} catch (
|
|
374
|
+
} catch (c) {
|
|
375
375
|
l = !1;
|
|
376
376
|
}
|
|
377
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());
|
|
@@ -405,7 +405,7 @@ const Q = (y, b) => {
|
|
|
405
405
|
*/
|
|
406
406
|
_processScriptText(t) {
|
|
407
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,
|
|
408
|
+
let f = !1, a = !1, h = !1, g = !1;
|
|
409
409
|
for (let d = 0; d < $; d++) {
|
|
410
410
|
const p = o[d];
|
|
411
411
|
if (g) {
|
|
@@ -416,14 +416,14 @@ const Q = (y, b) => {
|
|
|
416
416
|
g = !0;
|
|
417
417
|
continue;
|
|
418
418
|
}
|
|
419
|
-
p === "'" && !
|
|
419
|
+
p === "'" && !a && !h ? f = !f : p === '"' && !f && !h ? a = !a : p === "`" && !f && !a && (h = !h);
|
|
420
420
|
}
|
|
421
|
-
return f ||
|
|
422
|
-
},
|
|
423
|
-
let
|
|
421
|
+
return f || a || h;
|
|
422
|
+
}, c = (o, $, f) => {
|
|
423
|
+
let a = o;
|
|
424
424
|
const h = [];
|
|
425
425
|
let g;
|
|
426
|
-
for ($.lastIndex = 0; (g = $.exec(
|
|
426
|
+
for ($.lastIndex = 0; (g = $.exec(a)) !== null; )
|
|
427
427
|
h.push({
|
|
428
428
|
index: g.index,
|
|
429
429
|
length: g[0].length,
|
|
@@ -432,65 +432,65 @@ const Q = (y, b) => {
|
|
|
432
432
|
});
|
|
433
433
|
for (let d = h.length - 1; d >= 0; d--) {
|
|
434
434
|
const p = h[d];
|
|
435
|
-
if (!l(
|
|
436
|
-
const
|
|
435
|
+
if (!l(a, p.index)) {
|
|
436
|
+
const _ = f(
|
|
437
437
|
p.originalContent,
|
|
438
438
|
...p.groups,
|
|
439
439
|
p.index,
|
|
440
|
-
|
|
440
|
+
a
|
|
441
441
|
);
|
|
442
|
-
|
|
442
|
+
a = a.substring(0, p.index) + _ + a.substring(p.index + p.length);
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
return
|
|
445
|
+
return a;
|
|
446
446
|
};
|
|
447
447
|
Object.keys(this.state).forEach((o) => {
|
|
448
448
|
this._isBound(o) && s.add(o);
|
|
449
449
|
});
|
|
450
450
|
let u = t;
|
|
451
|
-
u =
|
|
451
|
+
u = c(
|
|
452
452
|
u,
|
|
453
453
|
/\b(function\s+\w+\s*|const\s+\w+\s*=\s*|let\s+\w+\s*=\s*|var\s+\w+\s*=\s*)*\(([^)]*)\)\s*=>/g,
|
|
454
454
|
(o, $, f) => {
|
|
455
455
|
if (!f || !f.trim()) return o;
|
|
456
|
-
const
|
|
456
|
+
const a = f.split(",").map((d) => d.trim()).filter((d) => d);
|
|
457
457
|
let h = !1;
|
|
458
|
-
const g =
|
|
458
|
+
const g = a.map((d) => {
|
|
459
459
|
const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
|
|
460
460
|
if (this._isBound(p)) {
|
|
461
461
|
h = !0;
|
|
462
|
-
const
|
|
463
|
-
return i.set(p,
|
|
462
|
+
const _ = r(p);
|
|
463
|
+
return i.set(p, _), d.replace(p, _);
|
|
464
464
|
}
|
|
465
465
|
return d;
|
|
466
466
|
});
|
|
467
467
|
return h ? o.replace(f, g.join(", ")) : o;
|
|
468
468
|
}
|
|
469
|
-
), u =
|
|
469
|
+
), u = c(
|
|
470
470
|
u,
|
|
471
471
|
/\bfunction\s+(\w+)\s*\(([^)]*)\)/g,
|
|
472
472
|
(o, $, f) => {
|
|
473
473
|
if (!f || !f.trim()) return o;
|
|
474
|
-
const
|
|
474
|
+
const a = f.split(",").map((d) => d.trim()).filter((d) => d);
|
|
475
475
|
let h = !1;
|
|
476
|
-
const g =
|
|
476
|
+
const g = a.map((d) => {
|
|
477
477
|
const p = d.split("=")[0].trim().replace(/[{}[\]]/g, "");
|
|
478
478
|
if (this._isBound(p)) {
|
|
479
479
|
h = !0;
|
|
480
|
-
const
|
|
481
|
-
return i.set(p,
|
|
480
|
+
const _ = r(p);
|
|
481
|
+
return i.set(p, _), d.replace(p, _);
|
|
482
482
|
}
|
|
483
483
|
return d;
|
|
484
484
|
});
|
|
485
485
|
return h ? o.replace(f, g.join(", ")) : o;
|
|
486
486
|
}
|
|
487
487
|
);
|
|
488
|
-
const
|
|
488
|
+
const A = /\bfunction\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*\(/g;
|
|
489
489
|
let k;
|
|
490
|
-
for (; (k =
|
|
490
|
+
for (; (k = A.exec(t)) !== null; )
|
|
491
491
|
n.add(k[1]);
|
|
492
|
-
const
|
|
493
|
-
for (; (k =
|
|
492
|
+
const I = /\b(const|let|var)\s+([a-zA-Z_$][0-9a-zA-Z_$]*)\s*=/g;
|
|
493
|
+
for (; (k = I.exec(t)) !== null; )
|
|
494
494
|
n.add(k[2]);
|
|
495
495
|
n.forEach((o) => {
|
|
496
496
|
this._isBound(o) && (new RegExp(
|
|
@@ -501,43 +501,55 @@ const Q = (y, b) => {
|
|
|
501
501
|
...e,
|
|
502
502
|
...s
|
|
503
503
|
])).forEach((o) => {
|
|
504
|
-
u =
|
|
504
|
+
u = c(
|
|
505
505
|
u,
|
|
506
506
|
new RegExp(`(^|\\W)(\\+\\+|\\-\\-)\\s*${o}\\b`, "g"),
|
|
507
|
-
(f,
|
|
508
|
-
), u =
|
|
507
|
+
(f, a, h) => `${a}${h}this.state.${o}`
|
|
508
|
+
), u = c(
|
|
509
509
|
u,
|
|
510
510
|
new RegExp(`\\b${o}\\s*(\\+\\+|\\-\\-)(?!\\.)`, "g"),
|
|
511
|
-
(f,
|
|
512
|
-
), u =
|
|
511
|
+
(f, a) => `this.state.${o}${a}`
|
|
512
|
+
), u = c(
|
|
513
513
|
u,
|
|
514
514
|
new RegExp(
|
|
515
515
|
`(^|\\W)${o}\\s*([+\\-*/%&|^]|<<|>>|>>>)?=(?!=)`,
|
|
516
516
|
"g"
|
|
517
517
|
),
|
|
518
|
-
(f,
|
|
519
|
-
const p = g +
|
|
520
|
-
let
|
|
518
|
+
(f, a, h, g, d) => {
|
|
519
|
+
const p = g + a.length;
|
|
520
|
+
let _ = d.substring(
|
|
521
521
|
Math.max(0, p - 10),
|
|
522
522
|
p
|
|
523
523
|
);
|
|
524
|
-
return /\b(const|let|var)\s+$/.test(
|
|
524
|
+
return /\b(const|let|var)\s+$/.test(_) ? f : `${a}this.state.${o} ${h || ""}=`;
|
|
525
525
|
}
|
|
526
526
|
);
|
|
527
527
|
const $ = new RegExp(
|
|
528
528
|
`\\b${o}\\b(?!\\s*[+\\-*/%&|^]?=)`,
|
|
529
529
|
"g"
|
|
530
530
|
);
|
|
531
|
-
u =
|
|
531
|
+
u = c(
|
|
532
532
|
u,
|
|
533
533
|
$,
|
|
534
|
-
(f,
|
|
534
|
+
(f, a, h) => {
|
|
535
535
|
if (h.substring(
|
|
536
|
-
Math.max(0,
|
|
537
|
-
|
|
538
|
-
).endsWith("this.state.")
|
|
539
|
-
|
|
540
|
-
|
|
536
|
+
Math.max(0, a - 11),
|
|
537
|
+
a
|
|
538
|
+
).endsWith("this.state."))
|
|
539
|
+
return f;
|
|
540
|
+
const d = h.substring(
|
|
541
|
+
Math.max(0, a - 20),
|
|
542
|
+
a
|
|
543
|
+
), p = h.substring(
|
|
544
|
+
a + f.length,
|
|
545
|
+
Math.min(
|
|
546
|
+
h.length,
|
|
547
|
+
a + f.length + 10
|
|
548
|
+
)
|
|
549
|
+
);
|
|
550
|
+
if (/[{,]\s*$/.test(d) && /^\s*:/.test(p) || i.has(o) && h.substring(
|
|
551
|
+
Math.max(0, a - 50),
|
|
552
|
+
a
|
|
541
553
|
).match(
|
|
542
554
|
/([+\-*/%&|^]|<<|>>|>>>)?=\s*[^=]*$/
|
|
543
555
|
) || [
|
|
@@ -577,77 +589,77 @@ const Q = (y, b) => {
|
|
|
577
589
|
"yield"
|
|
578
590
|
].includes(f))
|
|
579
591
|
return f;
|
|
580
|
-
const
|
|
581
|
-
`,
|
|
582
|
-
if (/\b(?:const|let|var)\s+$/.test(
|
|
592
|
+
const v = h.lastIndexOf(`
|
|
593
|
+
`, a) + 1, M = h.substring(v, a);
|
|
594
|
+
if (/\b(?:const|let|var)\s+$/.test(M) || a > 0 && h[a - 1] === ".")
|
|
583
595
|
return f;
|
|
584
|
-
let
|
|
585
|
-
for (;
|
|
586
|
-
|
|
587
|
-
return
|
|
596
|
+
let R = a + f.length;
|
|
597
|
+
for (; R < h.length && /\s/.test(h[R]); )
|
|
598
|
+
R++;
|
|
599
|
+
return R < h.length && h[R] === "(" ? f : `this.state.${o}`;
|
|
588
600
|
}
|
|
589
601
|
);
|
|
590
602
|
}), i.forEach((o, $) => {
|
|
591
603
|
const f = new RegExp(`\\b${$}\\b`, "g");
|
|
592
|
-
u =
|
|
604
|
+
u = c(
|
|
593
605
|
u,
|
|
594
606
|
f,
|
|
595
|
-
(
|
|
607
|
+
(a, h, g) => {
|
|
596
608
|
const d = g.substring(0, h);
|
|
597
609
|
if (d.includes(o)) {
|
|
598
|
-
let p = 0,
|
|
599
|
-
for (let
|
|
600
|
-
if (d[
|
|
601
|
-
else if (d[
|
|
602
|
-
|
|
610
|
+
let p = 0, _ = -1;
|
|
611
|
+
for (let v = d.length - 1; v >= 0; v--)
|
|
612
|
+
if (d[v] === "}") p++;
|
|
613
|
+
else if (d[v] === "{" && (p--, p < 0)) {
|
|
614
|
+
_ = v;
|
|
603
615
|
break;
|
|
604
616
|
}
|
|
605
|
-
if (
|
|
606
|
-
const
|
|
607
|
-
if (
|
|
608
|
-
Math.max(0,
|
|
617
|
+
if (_ !== -1) {
|
|
618
|
+
const v = d.substring(0, _);
|
|
619
|
+
if (v.substring(
|
|
620
|
+
Math.max(0, v.lastIndexOf("(", _))
|
|
609
621
|
).includes(o)) {
|
|
610
622
|
if (g.substring(
|
|
611
623
|
Math.max(0, h - 11),
|
|
612
624
|
h
|
|
613
625
|
).endsWith("this.state."))
|
|
614
|
-
return
|
|
615
|
-
const
|
|
616
|
-
h +
|
|
617
|
-
Math.min(g.length, h +
|
|
626
|
+
return a;
|
|
627
|
+
const V = g.substring(
|
|
628
|
+
h + a.length,
|
|
629
|
+
Math.min(g.length, h + a.length + 20)
|
|
618
630
|
);
|
|
619
|
-
return /^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(
|
|
631
|
+
return /^\s*([+\-*/%&|^]|<<|>>|>>>)?=(?!=)/.test(V) ? a : o;
|
|
620
632
|
}
|
|
621
633
|
}
|
|
622
634
|
}
|
|
623
|
-
return
|
|
635
|
+
return a;
|
|
624
636
|
}
|
|
625
637
|
);
|
|
626
638
|
});
|
|
627
|
-
let
|
|
628
|
-
n.size > 0 && (
|
|
639
|
+
let C = "";
|
|
640
|
+
n.size > 0 && (C = `
|
|
629
641
|
|
|
630
642
|
// --- Auto-processed by LadrillosJS Framework ---
|
|
631
643
|
`, n.forEach((o) => {
|
|
632
|
-
|
|
633
|
-
`,
|
|
634
|
-
`,
|
|
635
|
-
`,
|
|
644
|
+
C += `if (this._isBound('${o}')) {
|
|
645
|
+
`, C += ` if (typeof ${o} === 'function') {
|
|
646
|
+
`, C += ` try { this.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to assign function ${o} to component context.', e); }
|
|
647
|
+
`, C += ` } else if (typeof ${o} !== 'undefined' && ${e.has(
|
|
636
648
|
o
|
|
637
649
|
)}) {
|
|
638
|
-
`,
|
|
639
|
-
`,
|
|
640
|
-
`,
|
|
650
|
+
`, C += ` if(typeof this.state.${o} === 'undefined') { try { this.state.${o} = ${o}; } catch(e) { console.warn('LadrillosJS: Failed to initialize state for ${o} from script.', e); } }
|
|
651
|
+
`, C += ` }
|
|
652
|
+
`, C += `}
|
|
641
653
|
`;
|
|
642
654
|
}));
|
|
643
|
-
const
|
|
655
|
+
const z = u + C;
|
|
644
656
|
try {
|
|
645
|
-
new Function(
|
|
657
|
+
new Function(z).call(this);
|
|
646
658
|
} catch (o) {
|
|
647
|
-
|
|
659
|
+
w.error("Error executing component script:", o), console.error(
|
|
648
660
|
`LadrillosJS: Error executing component script. Processed script was:
|
|
649
661
|
---
|
|
650
|
-
` +
|
|
662
|
+
` + z + `
|
|
651
663
|
---
|
|
652
664
|
Error details:`,
|
|
653
665
|
o
|
|
@@ -665,8 +677,8 @@ Error details:`,
|
|
|
665
677
|
if (this._functions.set(s, r[0]), l = r[1].trim(), l)
|
|
666
678
|
try {
|
|
667
679
|
return new Function(`${l}`).bind(this);
|
|
668
|
-
} catch (
|
|
669
|
-
return
|
|
680
|
+
} catch (c) {
|
|
681
|
+
return w.error(c), l;
|
|
670
682
|
}
|
|
671
683
|
return t;
|
|
672
684
|
}
|
|
@@ -740,7 +752,7 @@ Error details:`,
|
|
|
740
752
|
return this.root.querySelectorAll(t);
|
|
741
753
|
}
|
|
742
754
|
};
|
|
743
|
-
|
|
755
|
+
E = new WeakSet(), Z = function(t) {
|
|
744
756
|
if (t === "") return null;
|
|
745
757
|
if (t !== "undefined")
|
|
746
758
|
try {
|
|
@@ -748,10 +760,10 @@ Error details:`,
|
|
|
748
760
|
} catch (n) {
|
|
749
761
|
return t;
|
|
750
762
|
}
|
|
751
|
-
},
|
|
752
|
-
let T =
|
|
753
|
-
customElements.define(
|
|
763
|
+
}, P(W, E);
|
|
764
|
+
let T = W;
|
|
765
|
+
customElements.define(y, T), w.log(`Web component defined: <${y}></${y}>`);
|
|
754
766
|
};
|
|
755
767
|
export {
|
|
756
|
-
|
|
768
|
+
G as defineWebComponent
|
|
757
769
|
};
|