ladrillosjs 0.1.8 → 1.0.0-rc.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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-BaJULV0N.js");exports.ladrillos=e.ladrillos;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-DnJwfSBj.js");exports.ladrillos=e.ladrillos;
@@ -1,4 +1,4 @@
1
- import { a as o } from "./main-CE6RxSxw.mjs";
1
+ import { a as o } from "./main-DuU83ybE.mjs";
2
2
  export {
3
3
  o as ladrillos
4
4
  };
@@ -1,5 +1,3 @@
1
- (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n.ladrillosjs={}))})(this,function(n){"use strict";var F=Object.defineProperty;var W=n=>{throw TypeError(n)};var O=(n,e,o)=>e in n?F(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o;var C=(n,e,o)=>O(n,typeof e!="symbol"?e+"":e,o),j=(n,e,o)=>e.has(n)||W("Cannot "+o);var L=(n,e,o)=>(j(n,e,"read from private field"),o?o.call(n):e.get(n)),P=(n,e,o)=>e.has(n)?W("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(n):e.set(n,o);var A=(n,e,o)=>new Promise((_,S)=>{var $=p=>{try{x(o.next(p))}catch(a){S(a)}},M=p=>{try{x(o.throw(p))}catch(a){S(a)}},x=p=>p.done?_(p.value):Promise.resolve(p.value).then($,M);x((o=o.apply(n,e)).next())});var p;const e={log(a,...c){},error(a,...c){console.error(a,...c)},warn(a,...c){}},o=["___vscode_livepreview_injected_script"];class _{constructor(){P(this,p,new Map);this.components={}}registerComponent(c,d,u=!0){return A(this,null,function*(){if(this.components[c]){e.log(`Component ${c} already registered, skipping.`);return}try{const f=[];let g=L(this,p).get(d);g||(g=yield(yield fetch(d)).text(),L(this,p).set(d,g));const N=g.replace(/<!--[\s\S]*?-->/g,""),w=new DOMParser().parseFromString(N,"text/html");Array.from(w.querySelectorAll("script[external]")).forEach(i=>{const t=i.getAttribute("src");t&&f.push(t),i.remove()});let E="";const B=Array.from(w.querySelectorAll("script:not([type='module']):not([external])"));function b(i){return A(this,null,function*(){try{const t=yield fetch(i);if(!t.ok)throw new Error(`HTTP ${t.status}`);return yield t.text()}catch(t){return e.error(`Failed to fetch resource at ${i}:`,t),""}})}for(const i of B){const t=i.getAttribute("src");if(t&&o.some(r=>t.includes(r))){e.log(`Skipping ignored script "${t}"`),i.remove();continue}t?E+=`
2
- `+(yield b(t)):E+=`
3
- `+i.textContent,i.remove()}E=E.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1").trim();let y="";const q=Array.from(w.querySelectorAll("link[rel='stylesheet']"));for(const i of q){const t=i.getAttribute("href");t&&(y+=`
4
- `+(yield b(t+"?raw"))),i.remove()}const T=Array.from(w.querySelectorAll("style"));for(const i of T)y+=`
5
- `+i.textContent,i.remove();y=y.trim();const v=document.createElement("template");v.innerHTML=w.body.innerHTML,this.components[c]={tagName:c,template:v,script:E,style:y,externalScripts:f},this._defineWebComponent(c,u),e.log(`Component ${c} registered successfully`)}catch(f){e.error(`Failed to register component ${c}:`,f)}})}_defineWebComponent(c,d){return A(this,null,function*(){const{defineWebComponent:u}=yield Promise.resolve().then(()=>x);u(this.components[c],d)})}}p=new WeakMap,C(_,"_SCRIPT_ALL",/<script>([\s\S]*?)<\/script>/g),C(_,"_STYLE_ALL",/<style>([\s\S]*?)<\/style>/g),C(_,"_SCRIPT_ONE",/<script>([\s\S]*?)<\/script>/),C(_,"_STYLE_ONE",/<style>([\s\S]*?)<\/style>/);const S=new _;function $(a,c={}){return new Proxy(c,{set(d,u,f){const g=d[u];return d[u]=f,g!==f&&!a._initializing&&(typeof a._updateBinding=="function"?a._updateBinding(u,f):a._update()),!0},get(d,u){return d[u]}})}const x=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(a,c)=>{if(!a){e.error("Component is not defined or invalid.");return}if(customElements.get(a.tagName)){e.warn(`Component ${a.tagName} is already defined.`);return}const{tagName:d,template:u,script:f,style:g,externalScripts:N}=a,R=/{(.*?)}/g,w=/{\s*([\w$]+)\(\)\s*}/,B=(i=>{const t=new Set;return i.innerHTML.replace(R,(r,s)=>t.add(s.trim().toLowerCase())),Array.from(t)})(u),b=f.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g,"state.$1 =").replace(/function\s+([\w$]+)\s*\(/g,"state.$1 = function (").replace(/\bclass\s+([\w$]+)\s*(extends\s+[\w$]+\s*)?{/g,"state.$1 = class $1 $2{"),y=f?new Function("state",`with(state){${b}}`):()=>{},T=(i=>{const t=[];return i.content.querySelectorAll("*").forEach(r=>{Array.from(r.attributes).forEach(s=>{if(!s.name.startsWith("on"))return;const l=s.name.slice(2),m=s.value.match(w);m&&(r.dataset._evtIndex=t.length,t.push({evt:l,fnName:m[1]}),r.removeAttribute(s.name))})}),t})(u);class v extends HTMLElement{constructor(){super(),c&&this.attachShadow({mode:"open"}),this.state={},this.styleElement=document.createElement("style"),this.scriptElement=document.createElement("script"),this.styleElement.textContent=g||"",this._textBindings={},this._origText=new Map,this._hasConnected=!1,this._isUpdating=!1,this._isBinding=!1}connectedCallback(){if(this._hasConnected)return;this._hasConnected=!0,this._textBindings={},this._origText=new Map;const t=u.content.cloneNode(!0);this.shadowRoot?this.shadowRoot.innerHTML="":this.innerHTML="",N.forEach(s=>{const l=document.createElement("script");l.src=s,l.onload=()=>{e.log(`Loaded external script: ${s}`)},document.head.appendChild(l)}),this.shadowRoot?(this.shadowRoot.appendChild(this.scriptElement),this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.appendChild(this.styleElement),this.appendChild(t)),this.state=$(this,{}),this._initializing=!0;try{y.call(this,this.state)}catch(s){console.error("Error initializing component script:",s)}finally{this._initializing=!1}const r=this.shadowRoot||this;this._processTemplate(r)}_processTemplate(t){this._getAllTextNodes(t).forEach(s=>{const l=s.textContent;l.includes("{")&&l.includes("}")&&(this._origText.set(s,l),s.textContent=l.replace(/{([^}]+)}/g,(m,h)=>(h=h.trim(),this._textBindings[h]=this._textBindings[h]||[],this._textBindings[h].push(s),this.hasAttribute(h)?this.getAttribute(h):this.state[h]!==void 0?this.state[h]:m)))}),T.forEach((s,l)=>{const m=t.querySelector(`[data-_evt-index="${l}"]`);m.removeAttribute("data-_evt-index"),m.addEventListener(s.evt,h=>{const H=this.state[s.fnName];typeof H=="function"&&H.call(m,h)})})}_getAllTextNodes(t){const r=[],s=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let l;for(;l=s.nextNode();)r.push(l);return r}_update(){if(!this._isUpdating){this._isUpdating=!0;try{const t=u.content.cloneNode(!0);this._processTemplate(t),this.shadowRoot?(this.shadowRoot.innerHTML="",this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.innerHTML="",this.appendChild(this.styleElement),this.appendChild(t))}finally{this._isUpdating=!1}}}_updateBinding(t){if(!this._isBinding){this._isBinding=!0;try{(this._textBindings[t]||[]).forEach(s=>{const l=this._origText.get(s)||"";s.textContent=l.replace(R,(m,h)=>(h=h.trim(),this.hasAttribute(h)?this.getAttribute(h):this.state[h]))})}finally{this._isBinding=!1,this.emit(t,this.state[t])}}}disconnectedCallback(){this._hasConnected=!1,T.forEach((t,r)=>{const s=(this.shadowRoot||this).querySelector(`[data-_evt-index="${r}"]`);s&&s.removeEventListener(t.evt,this.state[t.fnName])}),e.log("disconnectedCallback",this)}static get observedAttributes(){return B}attributeChangedCallback(t,r,s){r!==s&&(this.state[t]=s)}emit(t,r){const s=r!=null?r:this.state;this.dispatchEvent(new CustomEvent(t,{detail:s,bubbles:!0}))}querySelector(t){return this.shadowRoot?this.shadowRoot.querySelector(t):super.querySelector(t)}querySelectorAll(t){return this.shadowRoot?this.shadowRoot.querySelectorAll(t):super.querySelectorAll(t)}}customElements.define(d,v),e.log(`Web component defined: <${d}></${d}>`)}},Symbol.toStringTag,{value:"Module"}));n.ladrillos=S,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(l,c){typeof exports=="object"&&typeof module!="undefined"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis!="undefined"?globalThis:l||self,c(l.ladrillosjs={}))})(this,function(l){"use strict";var R=l=>{throw TypeError(l)};var W=(l,c,h)=>c.has(l)||R("Cannot "+h);var T=(l,c,h)=>(W(l,c,"read from private field"),h?h.call(l):c.get(l)),$=(l,c,h)=>c.has(l)?R("Cannot add the same private member more than once"):c instanceof WeakSet?c.add(l):c.set(l,h);var j=(l,c,h)=>(W(l,c,"access private method"),h);var w=(l,c,h)=>new Promise((B,k)=>{var q=u=>{try{p(h.next(u))}catch(F){k(F)}},m=u=>{try{p(h.throw(u))}catch(F){k(F)}},p=u=>u.done?B(u.value):Promise.resolve(u.value).then(q,m);p((h=h.apply(l,c)).next())});var m,p,u,H;const c={log(b,...i){},error(b,...i){console.error(b,...i)},warn(b,...i){}},S=class S{constructor(){$(this,m,new Map);$(this,p,new DOMParser);this.components={}}registerComponent(i,d,g=!0){return w(this,null,function*(){var x,E,A;if(this.components[i]){c.log(`Component ${i} already registered.`);return}this.components[i]={__registering:!0};try{const v=yield w(this,null,function*(){const t=T(this,m).get(d);if(t)return t;const r=yield(yield fetch(d)).text();return T(this,m).set(d,r),r}),C=T(this,p).parseFromString(v.replace(/<!--[\s\S]*?-->/g,""),"text/html"),e=[],n=[];for(const t of C.querySelectorAll("script"))t.src?n.push({src:t.src,type:(x=t.type)!=null?x:null}):t.textContent&&e.push({content:t.textContent.trim(),type:(E=t.type)!=null?E:null}),t.remove();let o="";for(const t of C.querySelectorAll("link[rel='stylesheet']"))o+=`
2
+ `+(yield j(A=S,u,H).call(A,`${t.href}?raw`)),t.remove();for(const t of C.querySelectorAll("style"))t.textContent&&(o+=`
3
+ `+t.textContent.trim()),t.remove();o=o.trim(),this.components[i]={tagName:i,template:C.body.innerHTML.trim(),scripts:e,externalScripts:n,style:o},yield this._defineWebComponent(i,g),c.log(`Component ${i} registered successfully`)}catch(v){c.error(`Failed to register component ${i}:`,v),delete this.components[i]}})}_defineWebComponent(i,d){return w(this,null,function*(){const{defineWebComponent:g}=yield Promise.resolve().then(()=>q);g(this.components[i],d)})}};m=new WeakMap,p=new WeakMap,u=new WeakSet,H=function(i){return w(this,null,function*(){try{const d=yield fetch(i);if(!d.ok)throw new Error(`HTTP ${d.status}`);return yield d.text()}catch(d){return c.error(`Failed to fetch resource at ${i}:`,d),""}})},$(S,u);let h=S;const B=new h,q=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(b,i)=>{const{tagName:d,template:g,scripts:x,externalScripts:E,style:A}=b;class v extends HTMLElement{constructor(){super(),i&&this.attachShadow({mode:"open"}),this.state={},this._bindings=[],this._eventBindings=[],this.observer=new MutationObserver(e=>{e.forEach(n=>{if(n.type==="attributes"){const o=n.attributeName,t=this.getAttribute(o);this.handleAttributeChange(o,t)}})}),this.observer.observe(this,{attributes:!0,attributeOldValue:!0}),this._render()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._loadScript(),this._render()}handleAttributeChange(e,n){this._render()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:e,event:n,listener:o})=>{e.removeEventListener(n,o)}),this._eventBindings=[]}_loadTemplate(){i?this.shadowRoot.innerHTML=g:this.innerHTML=g,this._scanBindings()}_scanBindings(){const e=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_TEXT,null,!1);let n;for(;n=e.nextNode();){const o=[...n.textContent.matchAll(/{([^}]+)}/g)];if(o.length){const t=o.map(([,s])=>({node:n,template:n.textContent,key:s.trim()}));this._bindings.push(t)}}this._getEventBindings()}_getEventBindings(){var n;((n=this.shadowRoot)!=null?n:this).querySelectorAll("*").forEach(o=>{Array.from(o.attributes).forEach(t=>{if(!t.name.startsWith("on"))return;const s=t.name.slice(2),r=t.value;o.removeAttribute(t.name);const a=f=>{r.includes("(")?new Function(`return ${r}`).call(this):typeof this[r]=="function"?this[r](f):typeof this.state[r]=="function"&&this.state[r](f)};o.addEventListener(s,a),this._eventBindings.push({key:r,element:o,event:s,listener:a})})})}_render(){this.getAttributeNames().forEach(e=>{this.state[e]=this.getAttribute(e)}),this._bindings.forEach(e=>{var n;if(Array.isArray(e)){const{node:o,template:t}=e[0],s={};e.forEach(({key:r})=>{var a;s[r]=(a=this.state[r])!=null?a:""}),o.textContent=this._renderTemplate(t,s)}else{const{node:o,template:t,key:s}=e,r={[s]:(n=this.state[s])!=null?n:""};o.textContent=this._renderTemplate(t,r)}})}_renderTemplate(e,n){return e.replace(/\{\s*([\w.]+)\s*}/g,(o,t)=>{let s=n[t];if(typeof s=="function")try{s=s.call(this)}catch(r){s=""}return s!=null?s:""})}_loadStyles(){const e=document.createElement("style");e.textContent=A,i?this.shadowRoot.appendChild(e):this.appendChild(e)}_loadScript(){return w(this,null,function*(){var e;for(const n of E)if(n.type==="component"){const t=yield(yield fetch(n.src)).text();this._processScriptText(t)}else yield this._injectScriptTag(n.src,n.type);for(const n of x)if(n.type==="module"){const o=document.createElement("script");o.type="module",o.textContent=n.content,((e=this.shadowRoot)!=null?e:this).appendChild(o)}else this._processScriptText(n.content);this._render()})}_processScriptText(e){const n=/(?:const|let|var)\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*=\s*([\s\S]+?);/g,o=/=>\s*{([\s\S]*?)};/g,t={};let s=0;for(;(s=e.indexOf("function ",s))!==-1;){const a=/^function\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*\([^)]*\)\s*{/.exec(e.slice(s));if(!a){s+=8;continue}const f=a[1];let y=0,_=s+a[0].length-1;do e[_]==="{"?y++:e[_]==="}"&&y--,_++;while(_<e.length&&y>0);t[f]=e.slice(s,_),s=_}for(const a in t)if(this._isBound(a))try{const f=new Function(`return (${t[a]});`).call(this).bind(this);this[a]=f}catch(f){console.error("failed to eval function",a,f)}let r;for(;r=n.exec(e);){const[,a,f]=r;if(!this._isBound(a))continue;const y=this._evalExpression(f.trim(),e,o);typeof y=="function"?this[a]=y.bind(this):this.state[a]=y}new Function(e).call(this)}_evalExpression(e,n,o){try{return new Function(`return (${e});`).call(this)}catch(t){let s,r;for(;s=o.exec(n);)r=s[1].trim();if(r)try{return new Function(r).bind(this)}catch(a){return console.error(a),r}return e}}_isBound(e){const n=this._eventBindings.some(t=>t.key===e),o=this._bindings.some(t=>Array.isArray(t)?t.some(s=>s.key===e):t.key===e);return n||o}_injectScriptTag(e,n){return new Promise((o,t)=>{const s=document.createElement("script");s.src=e,n&&(s.type=n),s.onload=o,s.onerror=t,document.head.appendChild(s)})}setState(e){Object.assign(this.state,e),this._render()}querySelector(e){return i?this.shadowRoot.querySelector(e):this.querySelector(e)}querySelectorAll(e){return i?this.shadowRoot.querySelectorAll(e):this.querySelectorAll(e)}}customElements.define(d,v),c.log(`Web component defined: <${d}></${d}>`)}},Symbol.toStringTag,{value:"Module"}));l.ladrillos=B,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1,3 @@
1
+ "use strict";var b=r=>{throw TypeError(r)};var q=(r,e,t)=>e.has(r)||b("Cannot "+t);var y=(r,e,t)=>(q(r,e,"read from private field"),t?t.call(r):e.get(r)),m=(r,e,t)=>e.has(r)?b("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 p=(r,e,t)=>new Promise((i,l)=>{var g=o=>{try{n(t.next(o))}catch(c){l(c)}},u=o=>{try{n(t.throw(o))}catch(c){l(c)}},n=o=>o.done?i(o.value):Promise.resolve(o.value).then(g,u);n((t=t.apply(r,e)).next())});const h={log(r,...e){},error(r,...e){console.error(r,...e)},warn(r,...e){}};var f,w,d,F;const C=class C{constructor(){m(this,f,new Map);m(this,w,new DOMParser);this.components={}}registerComponent(e,t,i=!0){return p(this,null,function*(){var l,g,u;if(this.components[e]){h.log(`Component ${e} already registered.`);return}this.components[e]={__registering:!0};try{const n=yield p(this,null,function*(){const s=y(this,f).get(t);if(s)return s;const $=yield(yield fetch(t)).text();return y(this,f).set(t,$),$}),o=y(this,w).parseFromString(n.replace(/<!--[\s\S]*?-->/g,""),"text/html"),c=[],S=[];for(const s of o.querySelectorAll("script"))s.src?S.push({src:s.src,type:(l=s.type)!=null?l:null}):s.textContent&&c.push({content:s.textContent.trim(),type:(g=s.type)!=null?g:null}),s.remove();let a="";for(const s of o.querySelectorAll("link[rel='stylesheet']"))a+=`
2
+ `+(yield v(u=C,d,F).call(u,`${s.href}?raw`)),s.remove();for(const s of o.querySelectorAll("style"))s.textContent&&(a+=`
3
+ `+s.textContent.trim()),s.remove();a=a.trim(),this.components[e]={tagName:e,template:o.body.innerHTML.trim(),scripts:c,externalScripts:S,style:a},yield this._defineWebComponent(e,i),h.log(`Component ${e} registered successfully`)}catch(n){h.error(`Failed to register component ${e}:`,n),delete this.components[e]}})}_defineWebComponent(e,t){return p(this,null,function*(){const{defineWebComponent:i}=yield Promise.resolve().then(()=>require("./webcomponent-BoakYBr7.js"));i(this.components[e],t)})}};f=new WeakMap,w=new WeakMap,d=new WeakSet,F=function(e){return p(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),""}})},m(C,d);let x=C;const k=new x;exports.ladrillos=k;exports.logger=h;
@@ -0,0 +1,126 @@
1
+ var b = (r) => {
2
+ throw TypeError(r);
3
+ };
4
+ var F = (r, t, e) => t.has(r) || b("Cannot " + e);
5
+ var g = (r, t, e) => (F(r, t, "read from private field"), e ? e.call(r) : t.get(r)), m = (r, t, e) => t.has(r) ? b("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e);
6
+ var k = (r, t, e) => (F(r, t, "access private method"), e);
7
+ var p = (r, t, e) => new Promise((i, a) => {
8
+ var f = (o) => {
9
+ try {
10
+ n(e.next(o));
11
+ } catch (c) {
12
+ a(c);
13
+ }
14
+ }, y = (o) => {
15
+ try {
16
+ n(e.throw(o));
17
+ } catch (c) {
18
+ a(c);
19
+ }
20
+ }, n = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(f, y);
21
+ n((e = e.apply(r, t)).next());
22
+ });
23
+ const u = {
24
+ /**
25
+ * Log a message only in development mode
26
+ * @param {string} message - The message to log
27
+ * @param {any[]} args - Additional arguments to log
28
+ */
29
+ log(r, ...t) {
30
+ },
31
+ /**
32
+ * Log an error (always logs in both dev and production)
33
+ * @param {string} message - The error message
34
+ * @param {any[]} args - Additional arguments to log
35
+ */
36
+ error(r, ...t) {
37
+ console.error(r, ...t);
38
+ },
39
+ /**
40
+ * Log a warning only in development mode
41
+ * @param {string} message - The warning message
42
+ * @param {any[]} args - Additional arguments to log
43
+ */
44
+ warn(r, ...t) {
45
+ }
46
+ };
47
+ var h, w, d, q;
48
+ const x = class x {
49
+ constructor() {
50
+ m(this, h, /* @__PURE__ */ new Map());
51
+ m(this, w, new DOMParser());
52
+ this.components = {};
53
+ }
54
+ /**
55
+ * Registers a web‐component by fetching its HTML, scripts, and styles.
56
+ * @param {string} name
57
+ * @param {string} path
58
+ * @param {boolean} [useShadowDOM=true]
59
+ */
60
+ registerComponent(t, e, i = !0) {
61
+ return p(this, null, function* () {
62
+ var a, f, y;
63
+ if (this.components[t]) {
64
+ u.log(`Component ${t} already registered.`);
65
+ return;
66
+ }
67
+ this.components[t] = { __registering: !0 };
68
+ try {
69
+ const n = yield p(this, null, function* () {
70
+ const s = g(this, h).get(e);
71
+ if (s) return s;
72
+ const $ = yield (yield fetch(e)).text();
73
+ return g(this, h).set(e, $), $;
74
+ }), o = g(this, w).parseFromString(
75
+ n.replace(/<!--[\s\S]*?-->/g, ""),
76
+ "text/html"
77
+ ), c = [], S = [];
78
+ for (const s of o.querySelectorAll("script"))
79
+ s.src ? S.push({ src: s.src, type: (a = s.type) != null ? a : null }) : s.textContent && c.push({
80
+ content: s.textContent.trim(),
81
+ type: (f = s.type) != null ? f : null
82
+ }), s.remove();
83
+ let l = "";
84
+ for (const s of o.querySelectorAll("link[rel='stylesheet']"))
85
+ l += `
86
+ ` + (yield k(y = x, d, q).call(y, `${s.href}?raw`)), s.remove();
87
+ for (const s of o.querySelectorAll("style"))
88
+ s.textContent && (l += `
89
+ ` + s.textContent.trim()), s.remove();
90
+ l = l.trim(), this.components[t] = {
91
+ tagName: t,
92
+ template: o.body.innerHTML.trim(),
93
+ scripts: c,
94
+ externalScripts: S,
95
+ style: l
96
+ }, yield this._defineWebComponent(t, i), u.log(`Component ${t} registered successfully`);
97
+ } catch (n) {
98
+ u.error(`Failed to register component ${t}:`, n), delete this.components[t];
99
+ }
100
+ });
101
+ }
102
+ /** @private */
103
+ _defineWebComponent(t, e) {
104
+ return p(this, null, function* () {
105
+ const { defineWebComponent: i } = yield import("./webcomponent-DhJB3i4W.mjs");
106
+ i(this.components[t], e);
107
+ });
108
+ }
109
+ };
110
+ h = new WeakMap(), w = new WeakMap(), d = new WeakSet(), q = function(t) {
111
+ return p(this, null, function* () {
112
+ try {
113
+ const e = yield fetch(t);
114
+ if (!e.ok) throw new Error(`HTTP ${e.status}`);
115
+ return yield e.text();
116
+ } catch (e) {
117
+ return u.error(`Failed to fetch resource at ${t}:`, e), "";
118
+ }
119
+ });
120
+ }, m(x, d);
121
+ let C = x;
122
+ const M = new C();
123
+ export {
124
+ M as a,
125
+ u as l
126
+ };
@@ -0,0 +1 @@
1
+ "use strict";var b=(_,h,a)=>new Promise((p,m)=>{var y=l=>{try{f(a.next(l))}catch(e){m(e)}},g=l=>{try{f(a.throw(l))}catch(e){m(e)}},f=l=>l.done?p(l.value):Promise.resolve(l.value).then(y,g);f((a=a.apply(_,h)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./main-DnJwfSBj.js"),w=(_,h)=>{const{tagName:a,template:p,scripts:m,externalScripts:y,style:g}=_;class f extends HTMLElement{constructor(){super(),h&&this.attachShadow({mode:"open"}),this.state={},this._bindings=[],this._eventBindings=[],this.observer=new MutationObserver(e=>{e.forEach(t=>{if(t.type==="attributes"){const s=t.attributeName,i=this.getAttribute(s);this.handleAttributeChange(s,i)}})}),this.observer.observe(this,{attributes:!0,attributeOldValue:!0}),this._render()}connectedCallback(){this._loadTemplate(),this._loadStyles(),this._loadScript(),this._render()}handleAttributeChange(e,t){this._render()}disconnectedCallback(){this.observer.disconnect(),this._eventBindings.forEach(({element:e,event:t,listener:s})=>{e.removeEventListener(t,s)}),this._eventBindings=[]}_loadTemplate(){h?this.shadowRoot.innerHTML=p:this.innerHTML=p,this._scanBindings()}_scanBindings(){const e=document.createTreeWalker(this.shadowRoot,NodeFilter.SHOW_TEXT,null,!1);let t;for(;t=e.nextNode();){const s=[...t.textContent.matchAll(/{([^}]+)}/g)];if(s.length){const i=s.map(([,n])=>({node:t,template:t.textContent,key:n.trim()}));this._bindings.push(i)}}this._getEventBindings()}_getEventBindings(){var t;((t=this.shadowRoot)!=null?t:this).querySelectorAll("*").forEach(s=>{Array.from(s.attributes).forEach(i=>{if(!i.name.startsWith("on"))return;const n=i.name.slice(2),o=i.value;s.removeAttribute(i.name);const r=c=>{o.includes("(")?new Function(`return ${o}`).call(this):typeof this[o]=="function"?this[o](c):typeof this.state[o]=="function"&&this.state[o](c)};s.addEventListener(n,r),this._eventBindings.push({key:o,element:s,event:n,listener:r})})})}_render(){this.getAttributeNames().forEach(e=>{this.state[e]=this.getAttribute(e)}),this._bindings.forEach(e=>{var t;if(Array.isArray(e)){const{node:s,template:i}=e[0],n={};e.forEach(({key:o})=>{var r;n[o]=(r=this.state[o])!=null?r:""}),s.textContent=this._renderTemplate(i,n)}else{const{node:s,template:i,key:n}=e,o={[n]:(t=this.state[n])!=null?t:""};s.textContent=this._renderTemplate(i,o)}})}_renderTemplate(e,t){return e.replace(/\{\s*([\w.]+)\s*}/g,(s,i)=>{let n=t[i];if(typeof n=="function")try{n=n.call(this)}catch(o){n=""}return n!=null?n:""})}_loadStyles(){const e=document.createElement("style");e.textContent=g,h?this.shadowRoot.appendChild(e):this.appendChild(e)}_loadScript(){return b(this,null,function*(){var e;for(const t of y)if(t.type==="component"){const i=yield(yield fetch(t.src)).text();this._processScriptText(i)}else yield this._injectScriptTag(t.src,t.type);for(const t of m)if(t.type==="module"){const s=document.createElement("script");s.type="module",s.textContent=t.content,((e=this.shadowRoot)!=null?e:this).appendChild(s)}else this._processScriptText(t.content);this._render()})}_processScriptText(e){const t=/(?:const|let|var)\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*=\s*([\s\S]+?);/g,s=/=>\s*{([\s\S]*?)};/g,i={};let n=0;for(;(n=e.indexOf("function ",n))!==-1;){const r=/^function\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*\([^)]*\)\s*{/.exec(e.slice(n));if(!r){n+=8;continue}const c=r[1];let d=0,u=n+r[0].length-1;do e[u]==="{"?d++:e[u]==="}"&&d--,u++;while(u<e.length&&d>0);i[c]=e.slice(n,u),n=u}for(const r in i)if(this._isBound(r))try{const c=new Function(`return (${i[r]});`).call(this).bind(this);this[r]=c}catch(c){console.error("failed to eval function",r,c)}let o;for(;o=t.exec(e);){const[,r,c]=o;if(!this._isBound(r))continue;const d=this._evalExpression(c.trim(),e,s);typeof d=="function"?this[r]=d.bind(this):this.state[r]=d}new Function(e).call(this)}_evalExpression(e,t,s){try{return new Function(`return (${e});`).call(this)}catch(i){let n,o;for(;n=s.exec(t);)o=n[1].trim();if(o)try{return new Function(o).bind(this)}catch(r){return console.error(r),o}return e}}_isBound(e){const t=this._eventBindings.some(i=>i.key===e),s=this._bindings.some(i=>Array.isArray(i)?i.some(n=>n.key===e):i.key===e);return t||s}_injectScriptTag(e,t){return new Promise((s,i)=>{const n=document.createElement("script");n.src=e,t&&(n.type=t),n.onload=s,n.onerror=i,document.head.appendChild(n)})}setState(e){Object.assign(this.state,e),this._render()}querySelector(e){return h?this.shadowRoot.querySelector(e):this.querySelector(e)}querySelectorAll(e){return h?this.shadowRoot.querySelectorAll(e):this.querySelectorAll(e)}}customElements.define(a,f),v.logger.log(`Web component defined: <${a}></${a}>`)};exports.defineWebComponent=w;
@@ -0,0 +1,227 @@
1
+ var v = (_, h, a) => new Promise((f, m) => {
2
+ var y = (l) => {
3
+ try {
4
+ p(a.next(l));
5
+ } catch (t) {
6
+ m(t);
7
+ }
8
+ }, g = (l) => {
9
+ try {
10
+ p(a.throw(l));
11
+ } catch (t) {
12
+ m(t);
13
+ }
14
+ }, p = (l) => l.done ? f(l.value) : Promise.resolve(l.value).then(y, g);
15
+ p((a = a.apply(_, h)).next());
16
+ });
17
+ import { l as b } from "./main-DuU83ybE.mjs";
18
+ const A = (_, h) => {
19
+ const { tagName: a, template: f, scripts: m, externalScripts: y, style: g } = _;
20
+ class p extends HTMLElement {
21
+ constructor() {
22
+ super(), h && this.attachShadow({ mode: "open" }), this.state = {}, this._bindings = [], this._eventBindings = [], this.observer = new MutationObserver((t) => {
23
+ t.forEach((e) => {
24
+ if (e.type === "attributes") {
25
+ const s = e.attributeName, i = this.getAttribute(s);
26
+ this.handleAttributeChange(s, i);
27
+ }
28
+ });
29
+ }), this.observer.observe(this, {
30
+ attributes: !0,
31
+ // Watch for attribute changes
32
+ attributeOldValue: !0
33
+ // Track old values too
34
+ }), this._render();
35
+ }
36
+ connectedCallback() {
37
+ this._loadTemplate(), this._loadStyles(), this._loadScript(), this._render();
38
+ }
39
+ handleAttributeChange(t, e) {
40
+ this._render();
41
+ }
42
+ disconnectedCallback() {
43
+ this.observer.disconnect(), this._eventBindings.forEach(({ element: t, event: e, listener: s }) => {
44
+ t.removeEventListener(e, s);
45
+ }), this._eventBindings = [];
46
+ }
47
+ _loadTemplate() {
48
+ h ? this.shadowRoot.innerHTML = f : this.innerHTML = f, this._scanBindings();
49
+ }
50
+ _scanBindings() {
51
+ const t = document.createTreeWalker(
52
+ this.shadowRoot,
53
+ NodeFilter.SHOW_TEXT,
54
+ null,
55
+ !1
56
+ );
57
+ let e;
58
+ for (; e = t.nextNode(); ) {
59
+ const s = [...e.textContent.matchAll(/{([^}]+)}/g)];
60
+ if (s.length) {
61
+ const i = s.map(([, n]) => ({
62
+ node: e,
63
+ template: e.textContent,
64
+ key: n.trim()
65
+ }));
66
+ this._bindings.push(i);
67
+ }
68
+ }
69
+ this._getEventBindings();
70
+ }
71
+ _getEventBindings() {
72
+ var e;
73
+ ((e = this.shadowRoot) != null ? e : this).querySelectorAll("*").forEach((s) => {
74
+ Array.from(s.attributes).forEach((i) => {
75
+ if (!i.name.startsWith("on")) return;
76
+ const n = i.name.slice(2), o = i.value;
77
+ s.removeAttribute(i.name);
78
+ const r = (c) => {
79
+ o.includes("(") ? new Function(`return ${o}`).call(this) : typeof this[o] == "function" ? this[o](c) : typeof this.state[o] == "function" && this.state[o](c);
80
+ };
81
+ s.addEventListener(n, r), this._eventBindings.push({
82
+ key: o,
83
+ element: s,
84
+ event: n,
85
+ listener: r
86
+ });
87
+ });
88
+ });
89
+ }
90
+ _render() {
91
+ this.getAttributeNames().forEach((t) => {
92
+ this.state[t] = this.getAttribute(t);
93
+ }), this._bindings.forEach((t) => {
94
+ var e;
95
+ if (Array.isArray(t)) {
96
+ const { node: s, template: i } = t[0], n = {};
97
+ t.forEach(({ key: o }) => {
98
+ var r;
99
+ n[o] = (r = this.state[o]) != null ? r : "";
100
+ }), s.textContent = this._renderTemplate(i, n);
101
+ } else {
102
+ const { node: s, template: i, key: n } = t, o = { [n]: (e = this.state[n]) != null ? e : "" };
103
+ s.textContent = this._renderTemplate(i, o);
104
+ }
105
+ });
106
+ }
107
+ _renderTemplate(t, e) {
108
+ return t.replace(/\{\s*([\w.]+)\s*}/g, (s, i) => {
109
+ let n = e[i];
110
+ if (typeof n == "function")
111
+ try {
112
+ n = n.call(this);
113
+ } catch (o) {
114
+ n = "";
115
+ }
116
+ return n != null ? n : "";
117
+ });
118
+ }
119
+ _loadStyles() {
120
+ const t = document.createElement("style");
121
+ t.textContent = g, h ? this.shadowRoot.appendChild(t) : this.appendChild(t);
122
+ }
123
+ _loadScript() {
124
+ return v(this, null, function* () {
125
+ var t;
126
+ for (const e of y)
127
+ if (e.type === "component") {
128
+ const i = yield (yield fetch(e.src)).text();
129
+ this._processScriptText(i);
130
+ } else
131
+ yield this._injectScriptTag(e.src, e.type);
132
+ for (const e of m)
133
+ if (e.type === "module") {
134
+ const s = document.createElement("script");
135
+ s.type = "module", s.textContent = e.content, ((t = this.shadowRoot) != null ? t : this).appendChild(s);
136
+ } else
137
+ this._processScriptText(e.content);
138
+ this._render();
139
+ });
140
+ }
141
+ /**
142
+ * Finds all top‑level vars in `srcText`, evaluates them into this.state
143
+ * if they're bound, then execs the script in component context.
144
+ */
145
+ _processScriptText(t) {
146
+ const e = /(?:const|let|var)\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*=\s*([\s\S]+?);/g, s = /=>\s*{([\s\S]*?)};/g, i = {};
147
+ let n = 0;
148
+ for (; (n = t.indexOf("function ", n)) !== -1; ) {
149
+ const r = /^function\s+([$_A-Za-z][$_A-Za-z0-9]*)\s*\([^)]*\)\s*{/.exec(
150
+ t.slice(n)
151
+ );
152
+ if (!r) {
153
+ n += 8;
154
+ continue;
155
+ }
156
+ const c = r[1];
157
+ let d = 0, u = n + r[0].length - 1;
158
+ do
159
+ t[u] === "{" ? d++ : t[u] === "}" && d--, u++;
160
+ while (u < t.length && d > 0);
161
+ i[c] = t.slice(n, u), n = u;
162
+ }
163
+ for (const r in i)
164
+ if (this._isBound(r))
165
+ try {
166
+ const c = new Function(`return (${i[r]});`).call(this).bind(this);
167
+ this[r] = c;
168
+ } catch (c) {
169
+ console.error("failed to eval function", r, c);
170
+ }
171
+ let o;
172
+ for (; o = e.exec(t); ) {
173
+ const [, r, c] = o;
174
+ if (!this._isBound(r)) continue;
175
+ const d = this._evalExpression(
176
+ c.trim(),
177
+ t,
178
+ s
179
+ );
180
+ typeof d == "function" ? this[r] = d.bind(this) : this.state[r] = d;
181
+ }
182
+ new Function(t).call(this);
183
+ }
184
+ _evalExpression(t, e, s) {
185
+ try {
186
+ return new Function(`return (${t});`).call(this);
187
+ } catch (i) {
188
+ let n, o;
189
+ for (; n = s.exec(e); )
190
+ o = n[1].trim();
191
+ if (o)
192
+ try {
193
+ return new Function(o).bind(this);
194
+ } catch (r) {
195
+ return console.error(r), o;
196
+ }
197
+ return t;
198
+ }
199
+ }
200
+ _isBound(t) {
201
+ const e = this._eventBindings.some((i) => i.key === t), s = this._bindings.some(
202
+ (i) => Array.isArray(i) ? i.some((n) => n.key === t) : i.key === t
203
+ );
204
+ return e || s;
205
+ }
206
+ _injectScriptTag(t, e) {
207
+ return new Promise((s, i) => {
208
+ const n = document.createElement("script");
209
+ n.src = t, e && (n.type = e), n.onload = s, n.onerror = i, document.head.appendChild(n);
210
+ });
211
+ }
212
+ // --- public APIs
213
+ setState(t) {
214
+ Object.assign(this.state, t), this._render();
215
+ }
216
+ querySelector(t) {
217
+ return h ? this.shadowRoot.querySelector(t) : this.querySelector(t);
218
+ }
219
+ querySelectorAll(t) {
220
+ return h ? this.shadowRoot.querySelectorAll(t) : this.querySelectorAll(t);
221
+ }
222
+ }
223
+ customElements.define(a, p), b.log(`Web component defined: <${a}></${a}>`);
224
+ };
225
+ export {
226
+ A as defineWebComponent
227
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ladrillosjs",
3
- "version": "0.1.8",
3
+ "version": "1.0.0-rc.2",
4
4
  "description": "A lightweight, zero-dependency web component framework for building modular web applications.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +0,0 @@
1
- "use strict";var b=Object.defineProperty;var A=t=>{throw TypeError(t)};var x=(t,e,r)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var g=(t,e,r)=>x(t,typeof e!="symbol"?e+"":e,r),k=(t,e,r)=>e.has(t)||A("Cannot "+r);var _=(t,e,r)=>(k(t,e,"read from private field"),r?r.call(t):e.get(t)),C=(t,e,r)=>e.has(t)?A("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r);var h=(t,e,r)=>new Promise((p,i)=>{var l=n=>{try{u(r.next(n))}catch(c){i(c)}},S=n=>{try{u(r.throw(n))}catch(c){i(c)}},u=n=>n.done?p(n.value):Promise.resolve(n.value).then(l,S);u((r=r.apply(t,e)).next())});const a={log(t,...e){},error(t,...e){console.error(t,...e)},warn(t,...e){}},q=["___vscode_livepreview_injected_script"];var y;class f{constructor(){C(this,y,new Map);this.components={}}registerComponent(e,r,p=!0){return h(this,null,function*(){if(this.components[e]){a.log(`Component ${e} already registered, skipping.`);return}try{const i=[];let l=_(this,y).get(r);l||(l=yield(yield fetch(r)).text(),_(this,y).set(r,l));const S=l.replace(/<!--[\s\S]*?-->/g,""),n=new DOMParser().parseFromString(S,"text/html");Array.from(n.querySelectorAll("script[external]")).forEach(s=>{const o=s.getAttribute("src");o&&i.push(o),s.remove()});let c="";const v=Array.from(n.querySelectorAll("script:not([type='module']):not([external])"));function d(s){return h(this,null,function*(){try{const o=yield fetch(s);if(!o.ok)throw new Error(`HTTP ${o.status}`);return yield o.text()}catch(o){return a.error(`Failed to fetch resource at ${s}:`,o),""}})}for(const s of v){const o=s.getAttribute("src");if(o&&q.some($=>o.includes($))){a.log(`Skipping ignored script "${o}"`),s.remove();continue}o?c+=`
2
- `+(yield d(o)):c+=`
3
- `+s.textContent,s.remove()}c=c.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(^|[^:])\/\/.*$/gm,"$1").trim();let m="";const E=Array.from(n.querySelectorAll("link[rel='stylesheet']"));for(const s of E){const o=s.getAttribute("href");o&&(m+=`
4
- `+(yield d(o+"?raw"))),s.remove()}const T=Array.from(n.querySelectorAll("style"));for(const s of T)m+=`
5
- `+s.textContent,s.remove();m=m.trim();const w=document.createElement("template");w.innerHTML=n.body.innerHTML,this.components[e]={tagName:e,template:w,script:c,style:m,externalScripts:i},this._defineWebComponent(e,p),a.log(`Component ${e} registered successfully`)}catch(i){a.error(`Failed to register component ${e}:`,i)}})}_defineWebComponent(e,r){return h(this,null,function*(){const{defineWebComponent:p}=yield Promise.resolve().then(()=>require("./webcomponent-UVarlU1-.js"));p(this.components[e],r)})}}y=new WeakMap,g(f,"_SCRIPT_ALL",/<script>([\s\S]*?)<\/script>/g),g(f,"_STYLE_ALL",/<style>([\s\S]*?)<\/style>/g),g(f,"_SCRIPT_ONE",/<script>([\s\S]*?)<\/script>/),g(f,"_STYLE_ONE",/<style>([\s\S]*?)<\/style>/);const L=new f;exports.ladrillos=L;exports.logger=a;
@@ -1,145 +0,0 @@
1
- var $ = Object.defineProperty;
2
- var A = (t) => {
3
- throw TypeError(t);
4
- };
5
- var b = (t, e, r) => e in t ? $(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
6
- var m = (t, e, r) => b(t, typeof e != "symbol" ? e + "" : e, r), k = (t, e, r) => e.has(t) || A("Cannot " + r);
7
- var _ = (t, e, r) => (k(t, e, "read from private field"), r ? r.call(t) : e.get(t)), C = (t, e, r) => e.has(t) ? A("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r);
8
- var h = (t, e, r) => new Promise((a, i) => {
9
- var l = (n) => {
10
- try {
11
- u(r.next(n));
12
- } catch (c) {
13
- i(c);
14
- }
15
- }, S = (n) => {
16
- try {
17
- u(r.throw(n));
18
- } catch (c) {
19
- i(c);
20
- }
21
- }, u = (n) => n.done ? a(n.value) : Promise.resolve(n.value).then(l, S);
22
- u((r = r.apply(t, e)).next());
23
- });
24
- const f = {
25
- /**
26
- * Log a message only in development mode
27
- * @param {string} message - The message to log
28
- * @param {any[]} args - Additional arguments to log
29
- */
30
- log(t, ...e) {
31
- },
32
- /**
33
- * Log an error (always logs in both dev and production)
34
- * @param {string} message - The error message
35
- * @param {any[]} args - Additional arguments to log
36
- */
37
- error(t, ...e) {
38
- console.error(t, ...e);
39
- },
40
- /**
41
- * Log a warning only in development mode
42
- * @param {string} message - The warning message
43
- * @param {any[]} args - Additional arguments to log
44
- */
45
- warn(t, ...e) {
46
- }
47
- }, L = ["___vscode_livepreview_injected_script"];
48
- var y;
49
- class g {
50
- constructor() {
51
- C(this, y, /* @__PURE__ */ new Map());
52
- this.components = {};
53
- }
54
- /**
55
- * @param {string} name
56
- * @param {string} path
57
- * @param {boolean} [useShadowDOM=true]
58
- * @returns {Promise<void>}
59
- */
60
- registerComponent(e, r, a = !0) {
61
- return h(this, null, function* () {
62
- if (this.components[e]) {
63
- f.log(`Component ${e} already registered, skipping.`);
64
- return;
65
- }
66
- try {
67
- const i = [];
68
- let l = _(this, y).get(r);
69
- l || (l = yield (yield fetch(r)).text(), _(this, y).set(r, l));
70
- const S = l.replace(/<!--[\s\S]*?-->/g, ""), n = new DOMParser().parseFromString(S, "text/html");
71
- Array.from(n.querySelectorAll("script[external]")).forEach((s) => {
72
- const o = s.getAttribute("src");
73
- o && i.push(o), s.remove();
74
- });
75
- let c = "";
76
- const E = Array.from(
77
- n.querySelectorAll("script:not([type='module']):not([external])")
78
- );
79
- function w(s) {
80
- return h(this, null, function* () {
81
- try {
82
- const o = yield fetch(s);
83
- if (!o.ok) throw new Error(`HTTP ${o.status}`);
84
- return yield o.text();
85
- } catch (o) {
86
- return f.error(`Failed to fetch resource at ${s}:`, o), "";
87
- }
88
- });
89
- }
90
- for (const s of E) {
91
- const o = s.getAttribute("src");
92
- if (o && L.some((x) => o.includes(x))) {
93
- f.log(`Skipping ignored script "${o}"`), s.remove();
94
- continue;
95
- }
96
- o ? c += `
97
- ` + (yield w(o)) : c += `
98
- ` + s.textContent, s.remove();
99
- }
100
- c = c.replace(/\/\*[\s\S]*?\*\//g, "").replace(/(^|[^:])\/\/.*$/gm, "$1").trim();
101
- let p = "";
102
- const T = Array.from(
103
- n.querySelectorAll("link[rel='stylesheet']")
104
- );
105
- for (const s of T) {
106
- const o = s.getAttribute("href");
107
- o && (p += `
108
- ` + (yield w(o + "?raw"))), s.remove();
109
- }
110
- const v = Array.from(n.querySelectorAll("style"));
111
- for (const s of v)
112
- p += `
113
- ` + s.textContent, s.remove();
114
- p = p.trim();
115
- const d = document.createElement("template");
116
- d.innerHTML = n.body.innerHTML, this.components[e] = {
117
- tagName: e,
118
- template: d,
119
- script: c,
120
- style: p,
121
- externalScripts: i
122
- }, this._defineWebComponent(e, a), f.log(`Component ${e} registered successfully`);
123
- } catch (i) {
124
- f.error(`Failed to register component ${e}:`, i);
125
- }
126
- });
127
- }
128
- /**
129
- * @private
130
- * @param {string} name
131
- * @param {boolean} useShadowDOM
132
- */
133
- _defineWebComponent(e, r) {
134
- return h(this, null, function* () {
135
- const { defineWebComponent: a } = yield import("./webcomponent-u6r_KhfX.mjs");
136
- a(this.components[e], r);
137
- });
138
- }
139
- }
140
- y = new WeakMap(), m(g, "_SCRIPT_ALL", /<script>([\s\S]*?)<\/script>/g), m(g, "_STYLE_ALL", /<style>([\s\S]*?)<\/style>/g), m(g, "_SCRIPT_ONE", /<script>([\s\S]*?)<\/script>/), m(g, "_STYLE_ONE", /<style>([\s\S]*?)<\/style>/);
141
- const F = new g();
142
- export {
143
- F as a,
144
- f as l
145
- };
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./main-BaJULV0N.js");function v(r,u={}){return new Proxy(u,{set(h,o,l){const g=h[o];return h[o]=l,g!==l&&!r._initializing&&(typeof r._updateBinding=="function"?r._updateBinding(o,l):r._update()),!0},get(h,o){return h[o]}})}const B=(r,u)=>{if(!r){d.logger.error("Component is not defined or invalid.");return}if(customElements.get(r.tagName)){d.logger.warn(`Component ${r.tagName} is already defined.`);return}const{tagName:h,template:o,script:l,style:g,externalScripts:_}=r,p=/{(.*?)}/g,E=/{\s*([\w$]+)\(\)\s*}/,x=(c=>{const t=new Set;return c.innerHTML.replace(p,(s,e)=>t.add(e.trim().toLowerCase())),Array.from(t)})(o),w=l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g,"state.$1 =").replace(/function\s+([\w$]+)\s*\(/g,"state.$1 = function (").replace(/\bclass\s+([\w$]+)\s*(extends\s+[\w$]+\s*)?{/g,"state.$1 = class $1 $2{"),C=l?new Function("state",`with(state){${w}}`):()=>{},f=(c=>{const t=[];return c.content.querySelectorAll("*").forEach(s=>{Array.from(s.attributes).forEach(e=>{if(!e.name.startsWith("on"))return;const i=e.name.slice(2),a=e.value.match(E);a&&(s.dataset._evtIndex=t.length,t.push({evt:i,fnName:a[1]}),s.removeAttribute(e.name))})}),t})(o);class b extends HTMLElement{constructor(){super(),u&&this.attachShadow({mode:"open"}),this.state={},this.styleElement=document.createElement("style"),this.scriptElement=document.createElement("script"),this.styleElement.textContent=g||"",this._textBindings={},this._origText=new Map,this._hasConnected=!1,this._isUpdating=!1,this._isBinding=!1}connectedCallback(){if(this._hasConnected)return;this._hasConnected=!0,this._textBindings={},this._origText=new Map;const t=o.content.cloneNode(!0);this.shadowRoot?this.shadowRoot.innerHTML="":this.innerHTML="",_.forEach(e=>{const i=document.createElement("script");i.src=e,i.onload=()=>{d.logger.log(`Loaded external script: ${e}`)},document.head.appendChild(i)}),this.shadowRoot?(this.shadowRoot.appendChild(this.scriptElement),this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.appendChild(this.styleElement),this.appendChild(t)),this.state=v(this,{}),this._initializing=!0;try{C.call(this,this.state)}catch(e){console.error("Error initializing component script:",e)}finally{this._initializing=!1}const s=this.shadowRoot||this;this._processTemplate(s)}_processTemplate(t){this._getAllTextNodes(t).forEach(e=>{const i=e.textContent;i.includes("{")&&i.includes("}")&&(this._origText.set(e,i),e.textContent=i.replace(/{([^}]+)}/g,(a,n)=>(n=n.trim(),this._textBindings[n]=this._textBindings[n]||[],this._textBindings[n].push(e),this.hasAttribute(n)?this.getAttribute(n):this.state[n]!==void 0?this.state[n]:a)))}),f.forEach((e,i)=>{const a=t.querySelector(`[data-_evt-index="${i}"]`);a.removeAttribute("data-_evt-index"),a.addEventListener(e.evt,n=>{const m=this.state[e.fnName];typeof m=="function"&&m.call(a,n)})})}_getAllTextNodes(t){const s=[],e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let i;for(;i=e.nextNode();)s.push(i);return s}_update(){if(!this._isUpdating){this._isUpdating=!0;try{const t=o.content.cloneNode(!0);this._processTemplate(t),this.shadowRoot?(this.shadowRoot.innerHTML="",this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.innerHTML="",this.appendChild(this.styleElement),this.appendChild(t))}finally{this._isUpdating=!1}}}_updateBinding(t){if(!this._isBinding){this._isBinding=!0;try{(this._textBindings[t]||[]).forEach(e=>{const i=this._origText.get(e)||"";e.textContent=i.replace(p,(a,n)=>(n=n.trim(),this.hasAttribute(n)?this.getAttribute(n):this.state[n]))})}finally{this._isBinding=!1,this.emit(t,this.state[t])}}}disconnectedCallback(){this._hasConnected=!1,f.forEach((t,s)=>{const e=(this.shadowRoot||this).querySelector(`[data-_evt-index="${s}"]`);e&&e.removeEventListener(t.evt,this.state[t.fnName])}),d.logger.log("disconnectedCallback",this)}static get observedAttributes(){return x}attributeChangedCallback(t,s,e){s!==e&&(this.state[t]=e)}emit(t,s){const e=s!=null?s:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0}))}querySelector(t){return this.shadowRoot?this.shadowRoot.querySelector(t):super.querySelector(t)}querySelectorAll(t){return this.shadowRoot?this.shadowRoot.querySelectorAll(t):super.querySelectorAll(t)}}customElements.define(h,b),d.logger.log(`Web component defined: <${h}></${h}>`)};exports.defineWebComponent=B;
@@ -1,184 +0,0 @@
1
- import { l as d } from "./main-CE6RxSxw.mjs";
2
- function v(r, u = {}) {
3
- return new Proxy(u, {
4
- set(h, o, l) {
5
- const p = h[o];
6
- return h[o] = l, p !== l && !r._initializing && (typeof r._updateBinding == "function" ? r._updateBinding(o, l) : r._update()), !0;
7
- },
8
- get(h, o) {
9
- return h[o];
10
- }
11
- });
12
- }
13
- const T = (r, u) => {
14
- if (!r) {
15
- d.error("Component is not defined or invalid.");
16
- return;
17
- }
18
- if (customElements.get(r.tagName)) {
19
- d.warn(`Component ${r.tagName} is already defined.`);
20
- return;
21
- }
22
- const { tagName: h, template: o, script: l, style: p, externalScripts: _ } = r, f = /{(.*?)}/g, E = /{\s*([\w$]+)\(\)\s*}/, x = ((c) => {
23
- const t = /* @__PURE__ */ new Set();
24
- return c.innerHTML.replace(
25
- f,
26
- (s, e) => t.add(e.trim().toLowerCase())
27
- ), Array.from(t);
28
- })(o), w = l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g, "state.$1 =").replace(/function\s+([\w$]+)\s*\(/g, "state.$1 = function (").replace(
29
- /\bclass\s+([\w$]+)\s*(extends\s+[\w$]+\s*)?{/g,
30
- "state.$1 = class $1 $2{"
31
- ), C = l ? new Function("state", `with(state){${w}}`) : () => {
32
- }, g = ((c) => {
33
- const t = [];
34
- return c.content.querySelectorAll("*").forEach((s) => {
35
- Array.from(s.attributes).forEach((e) => {
36
- if (!e.name.startsWith("on")) return;
37
- const i = e.name.slice(2), a = e.value.match(E);
38
- a && (s.dataset._evtIndex = t.length, t.push({ evt: i, fnName: a[1] }), s.removeAttribute(e.name));
39
- });
40
- }), t;
41
- })(o);
42
- class b extends HTMLElement {
43
- constructor() {
44
- super(), u && this.attachShadow({ mode: "open" }), this.state = {}, this.styleElement = document.createElement("style"), this.scriptElement = document.createElement("script"), this.styleElement.textContent = p || "", this._textBindings = {}, this._origText = /* @__PURE__ */ new Map(), this._hasConnected = !1, this._isUpdating = !1, this._isBinding = !1;
45
- }
46
- /**
47
- * Called when element is inserted into the DOM.
48
- * - Initializes reactive state
49
- * - Runs user script to populate state
50
- * - Processes template bindings
51
- * - Appends style + content to (shadow) root
52
- */
53
- connectedCallback() {
54
- if (this._hasConnected) return;
55
- this._hasConnected = !0, this._textBindings = {}, this._origText = /* @__PURE__ */ new Map();
56
- const t = o.content.cloneNode(!0);
57
- this.shadowRoot ? this.shadowRoot.innerHTML = "" : this.innerHTML = "", _.forEach((e) => {
58
- const i = document.createElement("script");
59
- i.src = e, i.onload = () => {
60
- d.log(`Loaded external script: ${e}`);
61
- }, document.head.appendChild(i);
62
- }), this.shadowRoot ? (this.shadowRoot.appendChild(this.scriptElement), this.shadowRoot.appendChild(this.styleElement), this.shadowRoot.appendChild(t)) : (this.appendChild(this.styleElement), this.appendChild(t)), this.state = v(this, {}), this._initializing = !0;
63
- try {
64
- C.call(this, this.state);
65
- } catch (e) {
66
- console.error("Error initializing component script:", e);
67
- } finally {
68
- this._initializing = !1;
69
- }
70
- const s = this.shadowRoot || this;
71
- this._processTemplate(s);
72
- }
73
- _processTemplate(t) {
74
- this._getAllTextNodes(t).forEach((e) => {
75
- const i = e.textContent;
76
- i.includes("{") && i.includes("}") && (this._origText.set(e, i), e.textContent = i.replace(/{([^}]+)}/g, (a, n) => (n = n.trim(), this._textBindings[n] = this._textBindings[n] || [], this._textBindings[n].push(e), this.hasAttribute(n) ? this.getAttribute(n) : this.state[n] !== void 0 ? this.state[n] : a)));
77
- }), g.forEach((e, i) => {
78
- const a = t.querySelector(`[data-_evt-index="${i}"]`);
79
- a.removeAttribute("data-_evt-index"), a.addEventListener(e.evt, (n) => {
80
- const m = this.state[e.fnName];
81
- typeof m == "function" && m.call(a, n);
82
- });
83
- });
84
- }
85
- /**
86
- * Retrieve all text nodes under a given root node.
87
- *
88
- * @param {Node} node
89
- * @returns {Text[]}
90
- */
91
- _getAllTextNodes(t) {
92
- const s = [], e = document.createTreeWalker(
93
- t,
94
- NodeFilter.SHOW_TEXT,
95
- null,
96
- !1
97
- );
98
- let i;
99
- for (; i = e.nextNode(); )
100
- s.push(i);
101
- return s;
102
- }
103
- /**
104
- * clears previous DOM, re-processes template and styles.
105
- * Usually called by reactive state on mutation.
106
- */
107
- _update() {
108
- if (!this._isUpdating) {
109
- this._isUpdating = !0;
110
- try {
111
- const t = o.content.cloneNode(!0);
112
- this._processTemplate(t), this.shadowRoot ? (this.shadowRoot.innerHTML = "", this.shadowRoot.appendChild(this.styleElement), this.shadowRoot.appendChild(t)) : (this.innerHTML = "", this.appendChild(this.styleElement), this.appendChild(t));
113
- } finally {
114
- this._isUpdating = !1;
115
- }
116
- }
117
- }
118
- // only update the nodes bound to a single key
119
- _updateBinding(t) {
120
- if (!this._isBinding) {
121
- this._isBinding = !0;
122
- try {
123
- (this._textBindings[t] || []).forEach((e) => {
124
- const i = this._origText.get(e) || "";
125
- e.textContent = i.replace(f, (a, n) => (n = n.trim(), this.hasAttribute(n) ? this.getAttribute(n) : this.state[n]));
126
- });
127
- } finally {
128
- this._isBinding = !1, this.emit(t, this.state[t]);
129
- }
130
- }
131
- }
132
- /**
133
- * Called when the element is removed from the DOM
134
- */
135
- disconnectedCallback() {
136
- this._hasConnected = !1, g.forEach((t, s) => {
137
- const e = (this.shadowRoot || this).querySelector(
138
- `[data-_evt-index="${s}"]`
139
- );
140
- e && e.removeEventListener(t.evt, this.state[t.fnName]);
141
- }), d.log("disconnectedCallback", this);
142
- }
143
- // property
144
- static get observedAttributes() {
145
- return x;
146
- }
147
- /**
148
- * Called when one of the observed attributes changes.
149
- * Updates state and triggers a re-render via the reactive proxy.
150
- *
151
- * @param {string} name
152
- * @param {string} oldVal
153
- * @param {string} newVal
154
- */
155
- attributeChangedCallback(t, s, e) {
156
- s !== e && (this.state[t] = e);
157
- }
158
- /**
159
- * Dispatch a custom event from the component.
160
- *
161
- * @param {string} name Event name
162
- * @param {*} [detail] Payload; defaults to full component state
163
- */
164
- emit(t, s) {
165
- const e = s != null ? s : this.state;
166
- this.dispatchEvent(
167
- new CustomEvent(t, {
168
- detail: e,
169
- bubbles: !0
170
- })
171
- );
172
- }
173
- querySelector(t) {
174
- return this.shadowRoot ? this.shadowRoot.querySelector(t) : super.querySelector(t);
175
- }
176
- querySelectorAll(t) {
177
- return this.shadowRoot ? this.shadowRoot.querySelectorAll(t) : super.querySelectorAll(t);
178
- }
179
- }
180
- customElements.define(h, b), d.log(`Web component defined: <${h}></${h}>`);
181
- };
182
- export {
183
- T as defineWebComponent
184
- };