ladrillosjs 2.0.0-beta.3 → 2.0.0-beta.3.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/README.md +152 -4
- package/dist/core/main.d.ts +2 -0
- package/dist/{index-DymB3-NG.mjs → index-JWdjGiUA.mjs} +216 -190
- package/dist/index-JWdjGiUA.mjs.map +1 -0
- package/dist/index-qEisp6n5.js +19 -0
- package/dist/index-qEisp6n5.js.map +1 -0
- package/dist/ladrillosjs.cjs.js +1 -1
- package/dist/ladrillosjs.es.js +1 -1
- package/dist/ladrillosjs.umd.js +17 -17
- package/dist/ladrillosjs.umd.js.map +1 -1
- package/dist/{webcomponent-BQLjYvOH.js → webcomponent-B-2Pj2ku.js} +2 -2
- package/dist/{webcomponent-BQLjYvOH.js.map → webcomponent-B-2Pj2ku.js.map} +1 -1
- package/dist/{webcomponent-DrCSyWrI.mjs → webcomponent-DT_kduma.mjs} +2 -2
- package/dist/{webcomponent-DrCSyWrI.mjs.map → webcomponent-DT_kduma.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/index-DZgn4gH2.js +0 -19
- package/dist/index-DZgn4gH2.js.map +0 -1
- package/dist/index-DymB3-NG.mjs.map +0 -1
package/dist/ladrillosjs.umd.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(g,$){typeof exports=="object"&&typeof module!="undefined"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(g=typeof globalThis!="undefined"?globalThis:g||self,$(g.ladrillosjs={}))})(this,(function(g){"use strict";var yt=Object.defineProperty,wt=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var Me=Object.getOwnPropertySymbols;var Et=Object.prototype.hasOwnProperty,vt=Object.prototype.propertyIsEnumerable;var Re=g=>{throw TypeError(g)};var Fe=(g,$,d)=>$ in g?yt(g,$,{enumerable:!0,configurable:!0,writable:!0,value:d}):g[$]=d,L=(g,$)=>{for(var d in $||($={}))Et.call($,d)&&Fe(g,d,$[d]);if(Me)for(var d of Me($))vt.call($,d)&&Fe(g,d,$[d]);return g},j=(g,$)=>wt(g,$t($));var de=(g,$,d)=>$.has(g)||Re("Cannot "+d);var x=(g,$,d)=>(de(g,$,"read from private field"),d?d.call(g):$.get(g)),N=(g,$,d)=>$.has(g)?Re("Cannot add the same private member more than once"):$ instanceof WeakSet?$.add(g):$.set(g,d),J=(g,$,d,k)=>(de(g,$,"write to private field"),k?k.call(g,d):$.set(g,d),d),D=(g,$,d)=>(de(g,$,"access private method"),d);var T=(g,$,d)=>new Promise((k,U)=>{var se=M=>{try{K(d.next(M))}catch(Z){U(Z)}},oe=M=>{try{K(d.throw(M))}catch(Z){U(Z)}},K=M=>M.done?k(M.value):Promise.resolve(M.value).then(se,oe);K((d=d.apply(g,$)).next())});var X,He,ze;const $=()=>{try{return!1}catch(n){return process.env.NODE_ENV==="development"}},d={log(n,...e){$()&&console.log(n,...e)},error(n,...e){console.error(n,...e)},warn(n,...e){$()&&console.warn(n,...e)}},k=(n,e)=>{const t=[n];return e&&(e.componentName&&t.push(`
|
|
2
2
|
Component: <${e.componentName}>`),e.componentPath&&t.push(`
|
|
3
3
|
File: ${e.componentPath}`),e.expression&&t.push(`
|
|
4
4
|
Expression: ${e.expression}`),e.attributeName&&t.push(`
|
|
5
5
|
Attribute: ${e.attributeName}`),e.eventType&&t.push(`
|
|
6
6
|
Event: ${e.eventType}`),e.elementTag&&t.push(`
|
|
7
7
|
Element: <${e.elementTag}>`),e.lineHint&&t.push(`
|
|
8
|
-
Location: ${e.lineHint}`)),t.join("")},U=(n,e,t)=>{const s=k("⚠️ Binding Error: Failed to evaluate expression",j(
|
|
8
|
+
Location: ${e.lineHint}`)),t.join("")},U=(n,e,t)=>{const s=k("⚠️ Binding Error: Failed to evaluate expression",j(L({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"Template binding expression"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},se=(n,e,t,s)=>{const o=k("⚠️ Event Handler Error: Failed to execute handler",j(L({},s),{eventType:n,expression:e,lineHint:(s==null?void 0:s.lineHint)||`on${n} handler`}));d.error(o),d.error(` Error details: ${t.message}`),t.stack&&console.debug(" Stack trace:",t.stack)},oe=(n,e,t)=>{const s=k("⚠️ Conditional Error: Failed to evaluate condition",j(L({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$if/$else-if condition"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},K=(n,e,t)=>{const s=k("⚠️ Loop Error: Failed to process loop",j(L({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$for loop expression"}));d.error(s),d.error(` Error details: ${e.message}`),e.stack&&console.debug(" Stack trace:",e.stack)},M=(n,e,t)=>{const s=k("⚠️ Registration Error: Failed to register component",{componentName:n,componentPath:e});d.error(s),d.error(` Error details: ${t.message}`),t.stack&&console.debug(" Stack trace:",t.stack)},Z=(n,e,t)=>{const s=k("⚠️ Fetch Error: Failed to load resource",j(L({},t),{componentPath:n}));d.error(s),d.error(` Error details: ${e.message}`)},re=(n,e)=>{const t=k(`⚠️ Parse Error: ${n}`,e);d.error(t)},Oe=(n,e)=>{const t=k("⚠️ Script Error: Failed to execute component script",e);d.error(t),d.error(` Error details: ${n.message}`),n.stack&&console.debug(" Stack trace:",n.stack)},We=(n,e,t)=>{const s=k("⚠️ Two-Way Binding Error: Failed to setup binding",j(L({},t),{expression:n,lineHint:(t==null?void 0:t.lineHint)||"$model binding"}));d.error(s),d.error(` Error details: ${e.message}`)},F=(n,e)=>{var t;return L({componentName:(n==null?void 0:n.tagName)||((t=n==null?void 0:n.constructor)==null?void 0:t.name),componentPath:(n==null?void 0:n.sourcePath)||(n==null?void 0:n._sourcePath)},e)},R=new Map,je=25,Ie=n=>{const e=R.get(n);return e&&(R.delete(n),R.set(n,e)),e},qe=(n,e)=>{if(R.has(n))R.delete(n);else if(R.size>=je){const t=R.keys().next().value;t&&R.delete(t)}R.set(n,e)},pe=n=>T(null,null,function*(){if(!n)throw new Error("Path cannot be null or empty");const e=Ie(n);if(e)return e;try{const t=yield fetch(n);if(!t.ok)throw new Error(`Failed to fetch component from ${n}: ${t.statusText}`);const s=yield t.text();return qe(n,s),s}catch(t){Z(n,t,{componentPath:n})}}),De=n=>T(null,null,function*(){try{const e=yield fetch(n);if(!e.ok)throw new Error(`HTTP ${e.status}`);return yield e.text()}catch(e){return Z(n,e),""}}),G={bindings:/{([^}]+)}/g,comments:{js:/\/\*[\s\S]*?\*\/|\/\/.*$/gm,css:/\/\*[\s\S]*?\*\//g,html:/<!--[\s\S]*?-->/g}},Ue=new DOMParser,he=(n,e)=>T(null,null,function*(){const t=Ze(n),{scripts:s,externalScripts:o}=Je(t),r=yield Ge(t),i=t.body.innerHTML.trim();return{tagName:e,template:i,scripts:s,externalScripts:o,styles:r}}),Ze=n=>Ue.parseFromString(n.replace(G.comments.html,""),"text/html"),Xe=n=>["/@vite/","/__vite","/webpack-dev-server","/hot-update","/__webpack_hmr","/browser-sync/","/livereload.js"].some(t=>n.includes(t)),Je=n=>{var s,o;const e=[],t=[];for(const r of n.querySelectorAll("script")){if(r.src){if(Xe(r.src)){r.remove();continue}const i=r.hasAttribute("external");t.push({src:r.getAttribute("src")||r.src,type:(s=r.type)!=null?s:null,external:i})}else if(r.textContent){let i=r.textContent.trim();i=i.replace(G.comments.js,"").trim(),e.push({content:i,type:(o=r.type)!=null?o:null})}r.remove()}return{scripts:e,externalScripts:t}},Ke=n=>{const e=n.match(/const __vite__css = "((?:[^"\\]|\\.)*)"/);if(e&&e[1])return e[1].replace(/\\r\\n/g,`
|
|
9
9
|
`).replace(/\\n/g,`
|
|
10
10
|
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\");const t=n.match(/export\s+default\s+"((?:[^"\\]|\\.)*)"/);return t&&t[1]?t[1].replace(/\\r\\n/g,`
|
|
11
11
|
`).replace(/\\n/g,`
|
|
12
|
-
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):n.includes("import")||n.includes("export")?(d.warn("CSS file returned JavaScript module format. CSS may not load correctly."),""):n},Ge=n=>
|
|
12
|
+
`).replace(/\\t/g," ").replace(/\\"/g,'"').replace(/\\\\/g,"\\"):n.includes("import")||n.includes("export")?(d.warn("CSS file returned JavaScript module format. CSS may not load correctly."),""):n},Ge=n=>T(null,null,function*(){let e="";const t=n.querySelectorAll("style, link[rel='stylesheet']");for(const s of t){if(s.tagName==="LINK"){const r=yield De(s.href),i=Ke(r);i&&(e+=`
|
|
13
13
|
`+i)}else if(s.tagName==="STYLE"){const o=s;if(o.textContent){let r=o.textContent.trim();r=r.replace(G.comments.css,"").trim(),e+=`
|
|
14
|
-
`+r}}s.remove()}return e.trim()});class Ye{constructor(){
|
|
14
|
+
`+r}}s.remove()}return e.trim()});class Ye{constructor(){N(this,X);this.components={},this.lazyComponents=new Set,this.intersectionObserver=null,this.lazyLoadingInProgress=new Map,this.lazyComponentsLoaded=new Set}registerComponent(e,t,s=!0,o=!1){return T(this,null,function*(){if(this.components[e]){d.warn(`Component with name "${e}" is already registered.`);return}if(o){this.lazyComponents.add(e),D(this,X,He).call(this,e,t,s),d.log(`Component ${e} registered as lazy-loaded`);return}try{const r=yield pe(t),i=yield he(r,e);this.components[e]={tagName:e,template:i.template,scripts:i.scripts,externalScripts:i.externalScripts,styles:i.styles,sourcePath:t,lazy:!1},d.log(`Component ${e} registered successfully`),yield D(this,X,ze).call(this,e,s)}catch(r){M(e,t,r);return}})}}X=new WeakSet,He=function(e,t,s){const o=this;class r extends HTMLElement{constructor(){super(),this.loaded=!1,this.observer=null,s&&(this.attachShadow({mode:"open"}),this.shadowRoot&&(this.shadowRoot.innerHTML=`
|
|
15
15
|
<style>
|
|
16
16
|
:host { display: block; min-height: 1px; }
|
|
17
17
|
</style>
|
|
18
|
-
`))}connectedCallback(){if(!this.loaded){if(this.hasAttribute("eager")){this.loaded=!0,this.loadComponent();return}this.observer=new IntersectionObserver(c=>{c.forEach(
|
|
18
|
+
`))}connectedCallback(){if(!this.loaded){if(this.hasAttribute("eager")){this.loaded=!0,this.loadComponent();return}this.observer=new IntersectionObserver(c=>{c.forEach(f=>{f.isIntersecting&&!this.loaded&&(this.loaded=!0,this.loadComponent())})},{rootMargin:"100px"}),this.observer.observe(this)}}disconnectedCallback(){this.observer&&(this.observer.disconnect(),this.observer=null)}loadComponent(){return T(this,null,function*(){try{if(o.lazyComponentsLoaded.has(e)){d.log(`Component ${e} already loaded, upgrading placeholder...`),this.upgradePlaceholder();return}if(o.lazyLoadingInProgress.has(e)){d.log(`Component ${e} is already loading, waiting...`),yield o.lazyLoadingInProgress.get(e),this.upgradePlaceholder();return}const c=this.performLoad();o.lazyLoadingInProgress.set(e,c),yield c,o.lazyLoadingInProgress.delete(e),o.lazyComponentsLoaded.add(e),o.lazyComponents.delete(e),d.log(`Component ${e} lazy-loaded successfully`)}catch(c){o.lazyLoadingInProgress.delete(e),M(e,t,c)}})}performLoad(){return T(this,null,function*(){d.log(`Lazy loading component: ${e}`);const c=this.parentNode;if(this.nextSibling,!c){re(`Placeholder for ${e} has no parent node`,{componentName:e,componentPath:t});return}const f=yield pe(t),a=yield he(f,e);d.log(`Component ${e} parsed successfully`),o.components[e]={tagName:e,template:a.template,scripts:a.scripts,externalScripts:a.externalScripts,styles:a.styles,sourcePath:t,lazy:!0};const l=`${e}-real`;d.log(`Defining real component with temp name: ${l}`);const u=o.components[e].tagName;o.components[e].tagName=l;const{defineWebComponent:p}=yield Promise.resolve().then(()=>Ne);p(o.components[e],s),d.log(`Real component ${l} defined`),o.components[e].tagName=u,this.upgradePlaceholder()})}upgradePlaceholder(){const c=this,f=this.parentNode,a=this.nextSibling;if(!f){re(`Placeholder for ${e} has no parent node`,{componentName:e,componentPath:t});return}const l=`${e}-real`,u=document.createElement(l);for(d.log(`Created real component instance: ${l}`),Array.from(c.attributes).forEach(p=>{p.name!=="eager"&&u.setAttribute(p.name,p.value)});c.firstChild;)u.appendChild(c.firstChild);a?(f.insertBefore(u,a),d.log("Inserted real component before next sibling")):(f.appendChild(u),d.log("Appended real component to parent")),f.removeChild(c),d.log("Removed placeholder element")}}customElements.get(e)||customElements.define(e,r)},ze=function(e,t){return T(this,null,function*(){const{defineWebComponent:s}=yield Promise.resolve().then(()=>Ne);this.components[e]&&s(this.components[e],t)})};const me=new Ye;class Qe{constructor(){this.listeners=new Map}emit(e,t){const s=new CustomEvent(e,{detail:t,bubbles:!0,composed:!0});document.dispatchEvent(s);const o=this.listeners.get(e);if(!o||o.size===0)return Promise.resolve();const r=[];return o.forEach(i=>{try{const c=i(t);c instanceof Promise&&r.push(c)}catch(c){d.error(`⚠️ Event Bus Error: Failed to execute listener for "${e}"`),d.error(` Error details: ${c.message}`),r.push(Promise.reject(c))}}),r.length>0?Promise.all(r).then(()=>{}):Promise.resolve()}listen(e,t){return this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(t),()=>{this.off(e,t)}}off(e,t){const s=this.listeners.get(e);s&&(s.delete(t),s.size===0&&this.listeners.delete(e))}clear(e){e?this.listeners.delete(e):this.listeners.clear()}listenerCount(e){var t,s;return(s=(t=this.listeners.get(e))==null?void 0:t.size)!=null?s:0}}const ie=new Qe,ge=(n,e,t,s)=>me.registerComponent(n,e,t,s),be=n=>T(null,null,function*(){yield Promise.all(n.map(({name:e,path:t,useShadowDOM:s,lazy:o})=>me.registerComponent(e,t,s,o)))}),ye=(n,e)=>ie.listen(n,e),we=(n,e)=>{ie.emit(n,e)},et=(n,e)=>{if(e){const t=e.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(t,{shadowRoot:n,element:e})}},Y=()=>{const n=window.__ladrilloContexts;if(n&&n.size>0){const e=Array.from(n.values());return e[e.length-1]}return null},$e=()=>{const n=Y();return n&&n.element?n.element.state||{}:{}},Q=n=>{const e=Y();e&&e.setState&&e.setState(n)},Ee=(n,e)=>(Q({[n]:e}),t=>{Q({[n]:t})}),ve=(n,e)=>{if(e)return e.querySelector(n);const t=Y();if(t){const s=t.shadowRoot||t.element;if(s){const o=s.querySelector(n);if(o)return o}}return document.querySelector(n)},Se=(n,e)=>{if(e)return e.querySelectorAll(n);const t=Y();if(t){const s=t.shadowRoot||t.element;if(s){const o=s.querySelectorAll(n);if(o.length>0)return o}}return document.querySelectorAll(n)};typeof window!="undefined"&&(window.ladrillosjs={registerComponent:ge,registerComponents:be},window.$listen=ye,window.$emit=we,window.$querySelector=ve,window.$querySelectorAll=Se,window.$reactive=Ee,window.$setState=Q,window.$getState=$e);const tt=(n,e,t)=>{if(!e)return;const s=document.createElement("style");s.textContent=e,t?n.appendChild(s):document.head.appendChild(s)},nt=(n,e)=>{n.innerHTML=e;const t=st(n),s=ot(n),o=rt(n),r=ct(n);return{bindings:t,twoWayBindings:s,conditionals:o,loops:r}},Ce=n=>{const e=[],t=n.match(/\((.*)\)/);if(!t)return e;const s=t[1].trim();return s&&s.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},st=n=>{const e=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null),t=[];let s;const o=i=>{let c=i.parentElement;for(;c;){if(c.hasAttribute&&c.hasAttribute("$for"))return!0;c=c.parentElement}return!1};for(;s=e.nextNode();){if(o(s))continue;const i=[...s.textContent.matchAll(G.bindings)];if(i.length>0){const c=s.textContent,f=i.map(a=>{const l=a[1].trim(),u=l.includes("(")&&l.includes(")"),p=/[+*/%<>=!&|]/.test(l)||/\s-\s/.test(l),m=/^(!|typeof\s|void\s|delete\s)/.test(l),E=p||m||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(l)||/\bnew\s+/.test(l)||/\b(typeof|instanceof|void|delete)\b/.test(l),b=u?[l.split("(")[0].trim()]:l.split(".").map(H=>H.trim()),y=u?Ce(l):[];return{raw:l,path:b,isFunction:u,isExpression:E,functionArgs:y}});t.push({node:s,bindings:f,original:c})}}return n.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 f=[...c.value.matchAll(G.bindings)];if(f.length>0){const a=c.value,l=f.map(u=>{const p=u[1].trim(),m=p.includes("(")&&p.includes(")"),E=/[+*/%<>=!&|]/.test(p)||/\s-\s/.test(p),b=/^(!|typeof\s|void\s|delete\s)/.test(p),y=E||b||/\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(p)||/\bnew\s+/.test(p)||/\b(typeof|instanceof|void|delete)\b/.test(p),H=m?[p.split("(")[0].trim()]:p.split(".").map(le=>le.trim()),O=m?Ce(p):[];return{raw:p,path:H,isFunction:m,isExpression:y,functionArgs:O}});t.push({node:i,bindings:l,original:a,isAttribute:!0,attributeName:c.name})}}}),t},ot=n=>{const e=[];return n.querySelectorAll("[\\$bind]").forEach(s=>{var c;const o=s.getAttribute("$bind");if(!o)return;const r=o.trim(),i=r.split(".").map(f=>f.trim());s instanceof HTMLInputElement||s instanceof HTMLTextAreaElement||s instanceof HTMLSelectElement?(e.push({element:s,path:i,raw:r,isContentEditable:!1,initialValue:s.value||""}),s.removeAttribute("$bind")):s instanceof HTMLElement&&s.hasAttribute("contenteditable")&&(e.push({element:s,path:i,raw:r,isContentEditable:!0,initialValue:((c=s.textContent)==null?void 0:c.trim())||""}),s.removeAttribute("$bind"))}),e},rt=n=>{const e=[],t=new Set;return n.querySelectorAll("[\\$if]").forEach(o=>{if(t.has(o))return;const r=[];let i=o;for(;i;){const c=i.hasAttribute("$if"),f=i.hasAttribute("$else-if"),a=i.hasAttribute("$else");if(!c&&!f&&!a)break;t.add(i);let l,u="";c?(l="if",u=i.getAttribute("$if")||"",i.removeAttribute("$if")):f?(l="else-if",u=i.getAttribute("$else-if")||"",i.removeAttribute("$else-if")):(l="else",i.removeAttribute("$else"));const p=document.createComment(`conditional:${l}:${u}`),m=i.parentElement||n,E=i.nextSibling;m.insertBefore(p,i);const b={element:i,condition:u.trim(),type:l,placeholder:p,group:[],originalParent:m,nextSibling:E};r.push(b);const y=i.nextElementSibling;if(i.remove(),i=y,y&&!y.hasAttribute("$else-if")&&!y.hasAttribute("$else"))break}r.forEach(c=>{c.group=r}),e.push(r)}),e},it=n=>{const e=new Set;return n.forEach(t=>{t.forEach(s=>{let o=s.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 a=c[1].split(".")[0];i.has(a)||e.add(a)}})}),e},ct=n=>{const e=[];return n.querySelectorAll("[\\$for]").forEach(s=>{var m;const o=s.getAttribute("$for");if(!o)return;const r=s.getAttribute("$key")||void 0,i=o.match(/^\s*(?:\(([^,]+),\s*([^)]+)\)|([^\s]+))\s+(?:in|of)\s+(.+)\s*$/);if(!i){re(`Invalid $for expression: "${o}"`,{expression:o,lineHint:"$for attribute parsing"});return}const c=(i[1]||i[3]).trim(),f=(m=i[2])==null?void 0:m.trim(),a=i[4].trim(),l=document.createComment(`loop:${o}`),u=s.parentElement||n;u.insertBefore(l,s),s.removeAttribute("$for"),r&&s.removeAttribute("$key"),s.remove();const p={template:s,expression:o,itemName:c,indexName:f,arrayName:a,keyAttribute:r,placeholder:l,renderedElements:[],originalParent:u};e.push(p)}),e},at=n=>{const e=new Set;return n.forEach(t=>{const s=t.arrayName.split(".")[0];e.add(s)}),e},I=new Map,lt=100,ce=n=>{const e=I.get(n);if(e)return I.delete(n),I.set(n,e),e;const t=new Function("component",`
|
|
19
19
|
const { Date, Array, Math, String, Number, Boolean, Object, JSON, RegExp } = globalThis;
|
|
20
20
|
with(component) {
|
|
21
21
|
return ${n};
|
|
22
22
|
}
|
|
23
|
-
`);if(
|
|
23
|
+
`);if(I.size>=lt){const s=I.keys().next().value;s&&I.delete(s)}return I.set(n,t),t},ee=(n,e)=>e.reduce((t,s)=>{if(!(t==null||typeof t!="object"))return t[s]},n),ae=(n,e,t)=>{if(e.length===0)return;const s=e[e.length-1],o=e.slice(0,-1);let r=n;for(const i of o)(r[i]===void 0||r[i]===null)&&(r[i]={}),r=r[i];r[s]=t},Ae=(n,e,t)=>{for(const s of n){let o=s.original,r,i=!1;for(const{raw:c,path:f,isFunction:a,isExpression:l}of s.bindings){let u,p=!1;if(l||a)try{u=ce(c)(t||e)}catch(E){U(c,E,F(t)),u=void 0,p=!0}else u=ee(e,f),u===void 0&&(p=!0);if(p){i=!0;continue}const m=String(u!=null?u:"");r=u,o=o.replace(`{${c}}`,m)}if(i&&s.original,s.node.nodeType===Node.TEXT_NODE){const c=s.node,f=c.parentElement,a=o.trim().startsWith("<")&&o.includes(">");f&&a?f.innerHTML=o:c.textContent=o}else{const c=s.node;s.isAttribute&&s.attributeName&&(["disabled","checked","readonly","required","selected","hidden","open","autofocus","autoplay","controls","loop","muted"].includes(s.attributeName.toLowerCase())?(typeof r=="boolean"?r:r==="true"||r==="True")?c.setAttribute(s.attributeName,""):c.removeAttribute(s.attributeName):c.setAttribute(s.attributeName,o))}}},ut=(n,e,t)=>{if(!n)return!0;let s=n.trim();s=s.replace(/\{([^}]+)\}/g,"$1");try{return new Function("context","component",`
|
|
24
24
|
with (context) {
|
|
25
25
|
try {
|
|
26
26
|
return Boolean(${s});
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
`)(e,t)}catch(o){return oe(n,o,
|
|
31
|
+
`)(e,t)}catch(o){return oe(n,o,F(t)),!1}},xe=(n,e)=>{const t=["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"];[n,...n.querySelectorAll("*")].forEach(o=>{t.forEach(r=>{const i=`on${r}`,c=o.getAttribute(i);if(c){const f=`__processed_${i}`;if(o[f])return;o.removeAttribute(i),o.addEventListener(r,function(a){try{new Function("event","component",`
|
|
32
32
|
with(component) {
|
|
33
33
|
${c}
|
|
34
34
|
}
|
|
35
|
-
`).call(this,
|
|
35
|
+
`).call(this,a,e)}catch(l){se(r,c,l,F(e,{elementTag:o.tagName.toLowerCase()}))}}),o[f]=!0}})})},_e=(n,e,t)=>{var s;for(const o of n){let r=!1;for(const i of o){const{element:c,condition:f,type:a,placeholder:l,originalParent:u}=i;let p=!1;a==="else"?p=!r:r||(p=ut(f,e,t),p&&(r=!0));const m=c.parentNode!==null;p&&!m?((s=l.parentNode)==null||s.insertBefore(c,l.nextSibling),t&&xe(c,t)):!p&&m&&c.remove()}}},ke=(n,e,t)=>{for(const s of n){const{template:o,itemName:r,indexName:i,arrayName:c,placeholder:f,renderedElements:a}=s,l=ee(e,c.split("."));if(l!==void 0&&!Array.isArray(l)){K(`${r} in ${c}`,new Error(`"${c}" is not an array, got: ${typeof l}`),F(t,{lineHint:"$for loop in template"})),a.forEach(u=>u.remove()),a.length=0;return}if(!l)return;a.forEach(u=>u.remove()),a.length=0,l.forEach((u,p)=>{var y;const m=o.cloneNode(!0),E=j(L({},e),{[r]:u});i&&(E[i]=p),dt(m,E,t);const b=a.length>0?a[a.length-1]:f;(y=b.parentNode)==null||y.insertBefore(m,b.nextSibling),a.push(m),t&&xe(m,t)})}},dt=(n,e,t)=>{const s=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null);let o;for(;o=s.nextNode();)if(o.textContent&&o.textContent.includes("{")){let i=o.textContent;[...o.textContent.matchAll(/\{([^}]+)\}/g)].forEach(f=>{const a=f[1].trim(),l=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);let m;if(p||l)try{const E=ce(a),b=typeof e=="object"&&e!==null?L(L({},e),t||{}):t||{};m=E(b)}catch(E){U(a,E,F(t,{lineHint:"$for loop template binding"})),m=void 0}else{const E=a.split(".").map(b=>b.trim());m=ee(e,E)}m!==void 0&&(i=i.replace(`{${a}}`,String(m!=null?m:"")))}),o.textContent=i}[n,...n.querySelectorAll("*")].forEach(i=>{Array.from(i.attributes).forEach(c=>{if(c.value.includes("{")){let f=c.value;[...c.value.matchAll(/\{([^}]+)\}/g)].forEach(l=>{const u=l[1].trim(),p=u.includes("(")&&u.includes(")"),E=/[+*/%<>=!&|]/.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(E||p)try{const y=ce(u),H=typeof e=="object"&&e!==null?L(L({},e),t||{}):t||{};b=y(H)}catch(y){U(u,y,F(t,{attributeName:c.name,lineHint:"$for loop attribute binding"})),b=void 0}else{const y=u.split(".").map(H=>H.trim());b=ee(e,y)}b!==void 0&&(f=f.replace(`{${u}}`,String(b!=null?b:"")))}),i.setAttribute(c.name,f)}})})},Le=n=>n instanceof ShadowRoot?n.host:n,ft=(n,e)=>{const t=new Set;e.forEach(({path:o})=>{const r=o[0];t.add(r)});const s=[];return t.forEach(o=>{s.push(`
|
|
36
36
|
if (!Object.getOwnPropertyDescriptor(component, '${o}')) {
|
|
37
37
|
Object.defineProperty(component, '${o}', {
|
|
38
38
|
get() { return this.state.${o}; },
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
`)}),{injectedCode:"",componentInjections:s.join(`
|
|
45
|
-
`),bindVarNames:t}},pt=(n,e,t=new Set)=>{const s=[],o=new Map,r=new Set;e.forEach(
|
|
46
|
-
`),{stateBindings:
|
|
47
|
-
`),
|
|
45
|
+
`),bindVarNames:t}},pt=(n,e,t=new Set)=>{const s=[],o=new Map,r=new Set;e.forEach(f=>{f.bindings.forEach(a=>{const l=a.path[0];r.add(l),a.isFunction&&a.functionArgs&&a.functionArgs.forEach(u=>{r.add(u)})})}),t.forEach(f=>{r.add(f)});const i=/(?:const|let|var)\s+(\w+)\s*=\s*([^;]+);?/g;let c;for(;(c=i.exec(n))!==null;){const f=c[1],a=c[2].trim();r.has(f)&&(s.push(`component.state.${f} = ${f};`),o.set(f,a))}return{stateBindings:s,boundVarNames:r,defaultValues:o}},ht=(n,e)=>{if(e.size===0)return n;let t=n;return e.forEach(s=>{const o=new RegExp(`\\b${s}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(o,`component.state.${s}$1 $2`);const r=new RegExp(`(?<!component\\.state\\.)\\b${s}((?:\\[[^\\]]+\\])(?:\\.[\\w]+|\\[[^\\]]+\\])*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(r,`component.state.${s}$1`);const i=new RegExp(`\\b${s}\\.(\\w+(?:\\.\\w+)*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(i,`component.state.${s}.$1 $2`);const c=new RegExp(`(?<!component\\.state\\.)(?<!const\\s${s}\\s*=\\s*{[^}]*)\\b${s}\\.(\\w+(?:\\.\\w+)*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,"g");t=t.replace(c,`component.state.${s}.$1`);const f=new RegExp(`(?<!\\.)\\b(\\+\\+|\\-\\-)${s}\\b|\\b${s}(\\+\\+|\\-\\-)`,"g");t=t.replace(f,u=>{if(u.startsWith("++")||u.startsWith("--"))return`${u.substring(0,2)}component.state.${s}`;{const p=u.substring(u.length-2);return`component.state.${s}${p}`}});const a=new RegExp(`(?<!\\.)\\b${s}\\s*(\\+=|\\-=|\\*=|\\/=|%=|\\*\\*=|<<=|>>=|>>>=|&=|\\|=|\\^=)`,"g");t=t.replace(a,`component.state.${s}$1`);const l=new RegExp(`(?<!const\\s)(?<!let\\s)(?<!var\\s)(?<!\\.)\\b${s}\\s*=\\s*([^=])`,"g");t=t.replace(l,`component.state.${s} = $1`)}),t},Te=(n,e,t,s,o,r=new Set)=>{try{const{injectedCode:i,componentInjections:c,bindVarNames:f}=ft(n,t),a=/function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[\w\s]*)\s*=>/g,l=[];let u;for(;(u=a.exec(n))!==null;){const P=u[1]||u[2];P&&l.push(P)}const p=l.map(P=>`component.${P} = typeof ${P} !== 'undefined' ? ${P}.bind(component) : undefined;`).join(`
|
|
46
|
+
`),{stateBindings:m,boundVarNames:E,defaultValues:b}=pt(n,e,r),y=new Set([...E,...f]),H=m.join(`
|
|
47
|
+
`),O=ht(n,y),le=`
|
|
48
48
|
(function() {
|
|
49
49
|
// Create component scope with direct access to state
|
|
50
50
|
const component = this;
|
|
@@ -79,18 +79,18 @@
|
|
|
79
79
|
|
|
80
80
|
// Execute script content within component scope so $bind variables are accessible
|
|
81
81
|
with(component) {
|
|
82
|
-
${
|
|
82
|
+
${O}
|
|
83
83
|
|
|
84
84
|
// Auto-bind variables to component state (e.g., const name = "value" → this.state.name = "value")
|
|
85
|
-
${
|
|
85
|
+
${H}
|
|
86
86
|
|
|
87
87
|
// Auto-attach all detected functions to component for onclick access
|
|
88
|
-
${
|
|
88
|
+
${p}
|
|
89
89
|
}
|
|
90
90
|
}).call(arguments[0], arguments[0], arguments[1], arguments[2])
|
|
91
|
-
`;return new Function(
|
|
91
|
+
`;return new Function(le)(o,s,ie),b}catch(i){return Oe(i,F(o)),new Map}},Pe=(n,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(s=>{const o=`on${s}`;(n instanceof ShadowRoot?n.querySelectorAll(`[${o}]`):e.querySelectorAll(`[${o}]`)).forEach(i=>{const c=`${o}`;if(i[`__processed_${c}`])return;const f=i.getAttribute(o);f&&(i.removeAttribute(o),i.addEventListener(s,function(a){new Function("event","component",`
|
|
92
92
|
with(component) {
|
|
93
|
-
${
|
|
93
|
+
${f}
|
|
94
94
|
}
|
|
95
|
-
`).call(this,
|
|
95
|
+
`).call(this,a,e)}),i[`__processed_${c}`]=!0)})})},mt=(r,i,c,...f)=>T(null,[r,i,c,...f],function*(n,e,t,s=[],o=new Set){const a=new Map;if(!(e!=null&&e.length))return a;const l=Le(n);for(const u of e)u.content&&Te(u.content,t,s,n,l,o).forEach((m,E)=>{a.has(E)||a.set(E,m)});return Pe(n,l),a}),gt=(n,e)=>new Promise((t,s)=>{const o=document.querySelector(`script[src="${n}"]`);if(o){if(o.dataset.loaded==="true"){t();return}o.addEventListener("load",()=>t(),{once:!0}),o.addEventListener("error",()=>s(new Error(`Failed to load external script: ${n}`)),{once:!0});return}const r=document.createElement("script");r.src=n,e&&(r.type=e),r.onload=()=>{r.dataset.loaded="true",t()},r.onerror=()=>s(new Error(`Failed to load external script: ${n}`)),document.head.appendChild(r)}),bt=(i,c,f,...a)=>T(null,[i,c,f,...a],function*(n,e,t,s=[],o=new Set,r){var u;const l=Le(n);for(const p of e){let m;r?r.startsWith("http://")||r.startsWith("https://")?m=r:m=new URL(r,window.location.href).href:m=window.location.href;const E=new URL(p.src,m).href;if(p.external)yield gt(E,p.type);else if(p.type==="module"){const b=l.tagName.toLowerCase();window.__ladrilloContexts||(window.__ladrilloContexts=new Map),window.__ladrilloContexts.set(b,{host:n,shadowRoot:n instanceof ShadowRoot?n:null,element:l,state:l.state,setState:(u=l.setState)==null?void 0:u.bind(l)});const y=document.createElement("script");y.type="module",y.src=E,y.setAttribute("data-component",b),document.head.appendChild(y)}else yield fetch(E).then(b=>{if(!b.ok)throw new Error(`HTTP ${b.status}: ${b.statusText}`);const y=b.headers.get("content-type");if(y&&!y.includes("javascript")&&!y.includes("text/plain"))throw new Error(`Expected JavaScript but got ${y}`);return b.text()}).then(b=>{Te(b,t,s,n,l,o)}).catch(b=>{console.error(`Failed to load external script: ${p.src}`,b)})}Pe(n,l)}),Ne=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(n,e)=>{var a,l,u,p,m,E,b,y,fe,O,Be,Ve;const{tagName:t,template:s,scripts:o,externalScripts:r,styles:i,sourcePath:c}=n,P=class P extends HTMLElement{constructor(){super();N(this,y);N(this,a,[]);N(this,l,[]);N(this,u,[]);N(this,p,[]);N(this,m,[]);N(this,E,c);N(this,b,new WeakMap);e&&this.attachShadow({mode:"open"});const h={},v=()=>{Ae(x(this,a),this.state,this),_e(x(this,u),this.state,this),ke(x(this,p),this.state,this),D(this,y,Ve).call(this)};this.state=new Proxy(h,{get:(C,w)=>C[w],set:(C,w,S)=>{const _=C[w];return w in C&&Object.is(_,S)||(S!==null&&typeof S=="object"?C[w]=D(this,y,fe).call(this,S,v):C[w]=S,Object.getOwnPropertyDescriptor(this,w)||Object.defineProperty(this,w,{get(){return this.state[w]},set(q){this.state[w]=q},enumerable:!0,configurable:!0}),v()),!0}})}setState(h){Object.assign(this.state,h)}connectedCallback(){return T(this,null,function*(){const h=e?this.shadowRoot:this,{bindings:v,twoWayBindings:C,conditionals:w,loops:S}=nt(h,s);J(this,a,v),J(this,l,C),J(this,u,w),J(this,p,S);const _=it(w),z=at(S);tt(h,i,e),yield bt(h,r,x(this,a),x(this,l),new Set([..._,...z]),x(this,E)),(yield mt(h,o,x(this,a),x(this,l),new Set([..._,...z]))).forEach((A,W)=>{if(this.state[W]===void 0)try{const B=new Function(`return ${A}`);this.state[W]=B()}catch(B){this.state[W]=A}}),this._initializeStateFromAttributes(),this._setupTwoWayBindings(),Ae(x(this,a),this.state,this),_e(x(this,u),this.state,this),ke(x(this,p),this.state,this),this._setupAttributeObserver()})}disconnectedCallback(){this.__attributeObserver&&(this.__attributeObserver.disconnect(),this.__attributeObserver=null),x(this,m).forEach(v=>{try{v()}catch(C){We("cleanup",C,F(this,{lineHint:"disconnectedCallback cleanup"}))}}),J(this,m,[]);const h=this.__eventUnsubscribers;h&&Array.isArray(h)&&(h.forEach(v=>{try{v()}catch(C){d.error("⚠️ Event Bus Error: Failed to unsubscribe from event",F(this)),d.error(` Error details: ${C.message}`)}}),this.__eventUnsubscribers=[])}_setupAttributeObserver(){const h=new MutationObserver(v=>{v.forEach(C=>{if(C.type==="attributes"&&C.attributeName){const w=this.getAttribute(C.attributeName);this._handleAttributeChange(C.attributeName,w)}})});h.observe(this,{attributes:!0,attributeOldValue:!0}),this.__attributeObserver=h}_initializeStateFromAttributes(){this.getAttributeNames().forEach(h=>{const v=this.getAttribute(h);this._handleAttributeChange(h,v)})}_handleAttributeChange(h,v){var w;if(h){const S="this.state.";h.startsWith(S)&&(h=h.slice(S.length))}const C=D(w=P,O,Be).call(w,v);this.state[h]=C}_setupTwoWayBindings(){x(this,l).forEach(({element:h,path:v,raw:C,isContentEditable:w,initialValue:S})=>{var z,q;if(this._getNestedValue(v)===void 0){const A=S||"";ae(this.state,v,A)}if(w){const A=h;A.textContent=(z=this._getNestedValue(v))!=null?z:"";const W=ue=>{const V=ue.target.textContent||"";ae(this.state,v,V)};A.addEventListener("input",W);const B=()=>{A.removeEventListener("input",W)};x(this,m).push(B)}else{const A=h,W=A instanceof HTMLInputElement&&A.type==="checkbox";A instanceof HTMLInputElement&&A.type,W?A.checked=!!this._getNestedValue(v):A.value=(q=this._getNestedValue(v))!=null?q:"";const B=te=>{const V=te.target;let ne;V instanceof HTMLInputElement&&V.type==="checkbox"?ne=V.checked:(V instanceof HTMLInputElement&&V.type,ne=V.value),ae(this.state,v,ne)};A.addEventListener("input",B);const ue=()=>{A.removeEventListener("input",B)};if(x(this,m).push(ue),A instanceof HTMLSelectElement||A instanceof HTMLInputElement&&["checkbox","radio","file"].includes(A.type)){A.addEventListener("change",B);const te=()=>{A.removeEventListener("change",B)};x(this,m).push(te)}}})}_getNestedValue(h){return h.reduce((v,C)=>v==null?void 0:v[C],this.state)}};a=new WeakMap,l=new WeakMap,u=new WeakMap,p=new WeakMap,m=new WeakMap,E=new WeakMap,b=new WeakMap,y=new WeakSet,fe=function(h,v){if(h===null||typeof h!="object"||h instanceof HTMLElement||h instanceof Node)return h;if(x(this,b).has(h))return x(this,b).get(h);const C=new Proxy(h,{get:(w,S)=>{const _=w[S];return Array.isArray(w)&&typeof _=="function"&&["push","pop","shift","unshift","splice","sort","reverse"].includes(S)?(...q)=>{const A=_.apply(w,q);return v(),A}:_!==null&&typeof _=="object"?D(this,y,fe).call(this,_,v):_},set:(w,S,_)=>{const z=w[S];return Object.is(z,_)||(w[S]=_,v()),!0}});return x(this,b).set(h,C),C},O=new WeakSet,Be=function(h){if(h===null||h==="")return null;if(h!=="undefined")try{return JSON.parse(h)}catch(v){return h}},Ve=function(){x(this,l).forEach(({element:h,path:v,isContentEditable:C})=>{const w=this._getNestedValue(v);if(C){const S=h;S.textContent!==w&&(S.textContent=w!=null?w:"")}else{const S=h;if(S instanceof HTMLInputElement&&S.type==="checkbox"){const _=!!w;S.checked!==_&&(S.checked=_)}else S.value!==w&&(S.value=w!=null?w:"")}})},N(P,O);let f=P;customElements.get(t)||(customElements.define(t,f),d.log(`Web component defined: <${t}></${t}>`))}},Symbol.toStringTag,{value:"Module"}));g.$emit=we,g.$getState=$e,g.$listen=ye,g.$querySelector=ve,g.$querySelectorAll=Se,g.$reactive=Ee,g.$setState=Q,g.__setComponentContext=et,g.registerComponent=ge,g.registerComponents=be,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
96
96
|
//# sourceMappingURL=ladrillosjs.umd.js.map
|