ladrillosjs 0.1.6 → 0.1.8
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/ladrillosjs.cjs.js +1 -1
- package/dist/ladrillosjs.es.js +1 -1
- package/dist/ladrillosjs.umd.js +5 -5
- package/dist/main-BaJULV0N.js +5 -0
- package/dist/main-CE6RxSxw.mjs +145 -0
- package/dist/webcomponent-UVarlU1-.js +1 -0
- package/dist/webcomponent-u6r_KhfX.mjs +184 -0
- package/package.json +2 -3
- package/dist/main-BNWsTWhL.mjs +0 -167
- package/dist/main-DtdmxWqG.js +0 -5
- package/dist/webcomponent-B4FfYJcG.mjs +0 -171
- package/dist/webcomponent-Cpdm2yXq.js +0 -1
package/dist/ladrillosjs.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-BaJULV0N.js");exports.ladrillos=e.ladrillos;
|
package/dist/ladrillosjs.es.js
CHANGED
package/dist/ladrillosjs.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`+(yield
|
|
3
|
-
`+
|
|
4
|
-
`+(yield
|
|
5
|
-
`+
|
|
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"})});
|
|
@@ -0,0 +1,5 @@
|
|
|
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;
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
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;
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ladrillosjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A lightweight, zero-dependency web component framework for building modular web applications.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,8 +15,7 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
17
|
"import": "./dist/ladrillosjs.es.js",
|
|
18
|
-
"require": "./dist/ladrillosjs.cjs.js"
|
|
19
|
-
"browser": "./dist/ladrillosjs.umd.js"
|
|
18
|
+
"require": "./dist/ladrillosjs.cjs.js"
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
21
|
"scripts": {
|
package/dist/main-BNWsTWhL.mjs
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
var k = Object.defineProperty;
|
|
2
|
-
var $ = (e) => {
|
|
3
|
-
throw TypeError(e);
|
|
4
|
-
};
|
|
5
|
-
var b = (e, t, r) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
6
|
-
var y = (e, t, r) => b(e, typeof t != "symbol" ? t + "" : t, r), v = (e, t, r) => t.has(e) || $("Cannot " + r);
|
|
7
|
-
var w = (e, t, r) => (v(e, t, "read from private field"), r ? r.call(e) : t.get(e)), A = (e, t, r) => t.has(e) ? $("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
8
|
-
var d = (e, t, r) => new Promise((a, c) => {
|
|
9
|
-
var u = (o) => {
|
|
10
|
-
try {
|
|
11
|
-
l(r.next(o));
|
|
12
|
-
} catch (p) {
|
|
13
|
-
c(p);
|
|
14
|
-
}
|
|
15
|
-
}, S = (o) => {
|
|
16
|
-
try {
|
|
17
|
-
l(r.throw(o));
|
|
18
|
-
} catch (p) {
|
|
19
|
-
c(p);
|
|
20
|
-
}
|
|
21
|
-
}, l = (o) => o.done ? a(o.value) : Promise.resolve(o.value).then(u, S);
|
|
22
|
-
l((r = r.apply(e, t)).next());
|
|
23
|
-
});
|
|
24
|
-
const E = {
|
|
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(e, ...t) {
|
|
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(e, ...t) {
|
|
38
|
-
console.error(e, ...t);
|
|
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(e, ...t) {
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var h;
|
|
49
|
-
class f {
|
|
50
|
-
constructor() {
|
|
51
|
-
A(this, h, /* @__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(t, r, a = !0) {
|
|
61
|
-
return d(this, null, function* () {
|
|
62
|
-
if (this.components[t]) {
|
|
63
|
-
E.log(`Component ${t} already registered, skipping.`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
try {
|
|
67
|
-
let c = w(this, h).get(r);
|
|
68
|
-
c || (c = yield (yield fetch(r)).text(), w(this, h).set(r, c));
|
|
69
|
-
const u = c.replace(/<!--[\s\S]*?-->/g, ""), l = new DOMParser().parseFromString(u, "text/html");
|
|
70
|
-
let o = "";
|
|
71
|
-
const p = Array.from(
|
|
72
|
-
l.querySelectorAll("script:not([type='module'])")
|
|
73
|
-
);
|
|
74
|
-
for (const n of p) {
|
|
75
|
-
if (n.src) {
|
|
76
|
-
const g = n.getAttribute("src");
|
|
77
|
-
let i;
|
|
78
|
-
try {
|
|
79
|
-
i = g;
|
|
80
|
-
} catch (s) {
|
|
81
|
-
console.error(
|
|
82
|
-
`Invalid script URL "${g}" (base "${r}") - skipping:`,
|
|
83
|
-
s
|
|
84
|
-
), n.remove();
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
try {
|
|
88
|
-
const s = yield fetch(i);
|
|
89
|
-
if (!s.ok) throw new Error(`HTTP ${s.status}`);
|
|
90
|
-
o += `
|
|
91
|
-
` + (yield s.text());
|
|
92
|
-
} catch (s) {
|
|
93
|
-
console.error(
|
|
94
|
-
`Could not load script at ${i} - skipping:`,
|
|
95
|
-
s
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
} else
|
|
99
|
-
o += `
|
|
100
|
-
` + n.textContent;
|
|
101
|
-
n.remove();
|
|
102
|
-
}
|
|
103
|
-
o = o.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/.*$/gm, "").trim();
|
|
104
|
-
let m = "";
|
|
105
|
-
const T = Array.from(
|
|
106
|
-
l.querySelectorAll("link[rel='stylesheet']")
|
|
107
|
-
);
|
|
108
|
-
for (const n of T) {
|
|
109
|
-
const g = n.getAttribute("href");
|
|
110
|
-
let i;
|
|
111
|
-
try {
|
|
112
|
-
i = g + "?raw";
|
|
113
|
-
} catch (s) {
|
|
114
|
-
console.error(
|
|
115
|
-
`Invalid stylesheet URL "${g}" (base "${r}") - skipping:`,
|
|
116
|
-
s
|
|
117
|
-
), n.remove();
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
const s = yield fetch(i);
|
|
122
|
-
if (!s.ok) throw new Error(`HTTP ${s.status}`);
|
|
123
|
-
m += `
|
|
124
|
-
` + (yield s.text());
|
|
125
|
-
} catch (s) {
|
|
126
|
-
console.error(
|
|
127
|
-
`Could not load stylesheet at ${i} - skipping:`,
|
|
128
|
-
s
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
n.remove();
|
|
132
|
-
}
|
|
133
|
-
const _ = Array.from(l.querySelectorAll("style"));
|
|
134
|
-
for (const n of _)
|
|
135
|
-
m += `
|
|
136
|
-
` + n.textContent, n.remove();
|
|
137
|
-
m = m.trim();
|
|
138
|
-
const C = document.createElement("template");
|
|
139
|
-
C.innerHTML = l.body.innerHTML, this.components[t] = {
|
|
140
|
-
tagName: t,
|
|
141
|
-
template: C,
|
|
142
|
-
script: o,
|
|
143
|
-
style: m
|
|
144
|
-
}, this._defineWebComponent(t, a), E.log(`Component ${t} registered successfully`);
|
|
145
|
-
} catch (c) {
|
|
146
|
-
E.error(`Failed to register component ${t}:`, c);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* @private
|
|
152
|
-
* @param {string} name
|
|
153
|
-
* @param {boolean} useShadowDOM
|
|
154
|
-
*/
|
|
155
|
-
_defineWebComponent(t, r) {
|
|
156
|
-
return d(this, null, function* () {
|
|
157
|
-
const { defineWebComponent: a } = yield import("./webcomponent-B4FfYJcG.mjs");
|
|
158
|
-
a(this.components[t], r);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
h = new WeakMap(), y(f, "_SCRIPT_ALL", /<script>([\s\S]*?)<\/script>/g), y(f, "_STYLE_ALL", /<style>([\s\S]*?)<\/style>/g), y(f, "_SCRIPT_ONE", /<script>([\s\S]*?)<\/script>/), y(f, "_STYLE_ONE", /<style>([\s\S]*?)<\/style>/);
|
|
163
|
-
const L = new f();
|
|
164
|
-
export {
|
|
165
|
-
L as a,
|
|
166
|
-
E as l
|
|
167
|
-
};
|
package/dist/main-DtdmxWqG.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";var k=Object.defineProperty;var $=t=>{throw TypeError(t)};var b=(t,e,r)=>e in t?k(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var y=(t,e,r)=>b(t,typeof e!="symbol"?e+"":e,r),v=(t,e,r)=>e.has(t)||$("Cannot "+r);var w=(t,e,r)=>(v(t,e,"read from private field"),r?r.call(t):e.get(t)),A=(t,e,r)=>e.has(t)?$("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r);var E=(t,e,r)=>new Promise((a,c)=>{var d=o=>{try{l(r.next(o))}catch(p){c(p)}},S=o=>{try{l(r.throw(o))}catch(p){c(p)}},l=o=>o.done?a(o.value):Promise.resolve(o.value).then(d,S);l((r=r.apply(t,e)).next())});const u={log(t,...e){},error(t,...e){console.error(t,...e)},warn(t,...e){}};var h;class f{constructor(){A(this,h,new Map);this.components={}}registerComponent(e,r,a=!0){return E(this,null,function*(){if(this.components[e]){u.log(`Component ${e} already registered, skipping.`);return}try{let c=w(this,h).get(r);c||(c=yield(yield fetch(r)).text(),w(this,h).set(r,c));const d=c.replace(/<!--[\s\S]*?-->/g,""),l=new DOMParser().parseFromString(d,"text/html");let o="";const p=Array.from(l.querySelectorAll("script:not([type='module'])"));for(const n of p){if(n.src){const m=n.getAttribute("src");let i;try{i=m}catch(s){console.error(`Invalid script URL "${m}" (base "${r}") - skipping:`,s),n.remove();continue}try{const s=yield fetch(i);if(!s.ok)throw new Error(`HTTP ${s.status}`);o+=`
|
|
2
|
-
`+(yield s.text())}catch(s){console.error(`Could not load script at ${i} - skipping:`,s)}}else o+=`
|
|
3
|
-
`+n.textContent;n.remove()}o=o.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/.*$/gm,"").trim();let g="";const T=Array.from(l.querySelectorAll("link[rel='stylesheet']"));for(const n of T){const m=n.getAttribute("href");let i;try{i=m+"?raw"}catch(s){console.error(`Invalid stylesheet URL "${m}" (base "${r}") - skipping:`,s),n.remove();continue}try{const s=yield fetch(i);if(!s.ok)throw new Error(`HTTP ${s.status}`);g+=`
|
|
4
|
-
`+(yield s.text())}catch(s){console.error(`Could not load stylesheet at ${i} - skipping:`,s)}n.remove()}const _=Array.from(l.querySelectorAll("style"));for(const n of _)g+=`
|
|
5
|
-
`+n.textContent,n.remove();g=g.trim();const C=document.createElement("template");C.innerHTML=l.body.innerHTML,this.components[e]={tagName:e,template:C,script:o,style:g},this._defineWebComponent(e,a),u.log(`Component ${e} registered successfully`)}catch(c){u.error(`Failed to register component ${e}:`,c)}})}_defineWebComponent(e,r){return E(this,null,function*(){const{defineWebComponent:a}=yield Promise.resolve().then(()=>require("./webcomponent-Cpdm2yXq.js"));a(this.components[e],r)})}}h=new WeakMap,y(f,"_SCRIPT_ALL",/<script>([\s\S]*?)<\/script>/g),y(f,"_STYLE_ALL",/<style>([\s\S]*?)<\/style>/g),y(f,"_SCRIPT_ONE",/<script>([\s\S]*?)<\/script>/),y(f,"_STYLE_ONE",/<style>([\s\S]*?)<\/style>/);const L=new f;exports.ladrillos=L;exports.logger=u;
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { l as c } from "./main-BNWsTWhL.mjs";
|
|
2
|
-
function C(a, u = {}) {
|
|
3
|
-
return new Proxy(u, {
|
|
4
|
-
set(h, r, l) {
|
|
5
|
-
const f = h[r];
|
|
6
|
-
return h[r] = l, f !== l && !a._initializing && (typeof a._updateBinding == "function" ? a._updateBinding(r, l) : a._update()), !0;
|
|
7
|
-
},
|
|
8
|
-
get(h, r) {
|
|
9
|
-
return h[r];
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
const y = (a, u) => {
|
|
14
|
-
if (!a) {
|
|
15
|
-
c.error("Component is not defined or invalid.");
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
if (customElements.get(a.tagName)) {
|
|
19
|
-
c.warn(`Component ${a.tagName} is already defined.`);
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const { tagName: h, template: r, script: l, style: f } = a, m = ((d) => {
|
|
23
|
-
const t = /{(.*?)}/g, i = /* @__PURE__ */ new Set();
|
|
24
|
-
let e;
|
|
25
|
-
for (; (e = t.exec(d.innerHTML)) !== null; )
|
|
26
|
-
i.add(e[1].trim().toLowerCase());
|
|
27
|
-
return Array.from(i);
|
|
28
|
-
})(r), _ = l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g, "state.$1 =").replace(/function\s+([\w$]+)\s*\(/g, "state.$1 = function ("), x = l ? new Function("state", `with(state){${_}}`) : () => {
|
|
29
|
-
}, g = [];
|
|
30
|
-
r.content.querySelectorAll("*").forEach((d) => {
|
|
31
|
-
Array.from(d.attributes).forEach((t) => {
|
|
32
|
-
if (!t.name.startsWith("on")) return;
|
|
33
|
-
const i = t.name.slice(2), e = t.value.match(/{\s*([\w$]+)\(\)\s*}/);
|
|
34
|
-
if (!e) return;
|
|
35
|
-
const s = e[1];
|
|
36
|
-
d.dataset._evtIndex = g.length, g.push({ evt: i, fnName: s }), d.removeAttribute(t.name);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
class w extends HTMLElement {
|
|
40
|
-
constructor() {
|
|
41
|
-
super(), u && this.attachShadow({ mode: "open" }), this.state = {}, this.styleElement = document.createElement("style"), this.styleElement.textContent = f || "", this._textBindings = {}, this._origText = /* @__PURE__ */ new Map(), this._hasConnected = !1, this._isUpdating = !1, this._isBinding = !1;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Called when element is inserted into the DOM.
|
|
45
|
-
* - Initializes reactive state
|
|
46
|
-
* - Runs user script to populate state
|
|
47
|
-
* - Processes template bindings
|
|
48
|
-
* - Appends style + content to (shadow) root
|
|
49
|
-
*/
|
|
50
|
-
connectedCallback() {
|
|
51
|
-
if (this._hasConnected) return;
|
|
52
|
-
this._hasConnected = !0, this._textBindings = {}, this._origText = /* @__PURE__ */ new Map();
|
|
53
|
-
const t = r.content.cloneNode(!0);
|
|
54
|
-
this.shadowRoot ? this.shadowRoot.innerHTML = "" : this.innerHTML = "", this.shadowRoot ? (this.shadowRoot.appendChild(this.styleElement), this.shadowRoot.appendChild(t)) : (this.appendChild(this.styleElement), this.appendChild(t)), this.state = C(this, {}), this._initializing = !0;
|
|
55
|
-
try {
|
|
56
|
-
x.call(this, this.state);
|
|
57
|
-
} catch (e) {
|
|
58
|
-
console.error("Error initializing component script:", e);
|
|
59
|
-
} finally {
|
|
60
|
-
this._initializing = !1;
|
|
61
|
-
}
|
|
62
|
-
const i = this.shadowRoot || this;
|
|
63
|
-
this._processTemplate(i);
|
|
64
|
-
}
|
|
65
|
-
_processTemplate(t) {
|
|
66
|
-
this._getAllTextNodes(t).forEach((e) => {
|
|
67
|
-
const s = e.textContent;
|
|
68
|
-
s.includes("{") && s.includes("}") && (this._origText.set(e, s), e.textContent = s.replace(/{([^}]+)}/g, (n, o) => (o = o.trim(), this._textBindings[o] = this._textBindings[o] || [], this._textBindings[o].push(e), this.hasAttribute(o) ? this.getAttribute(o) : this.state[o] !== void 0 ? this.state[o] : n)));
|
|
69
|
-
}), g.forEach((e, s) => {
|
|
70
|
-
const n = t.querySelector(`[data-_evt-index="${s}"]`);
|
|
71
|
-
n.removeAttribute("data-_evt-index"), n.addEventListener(e.evt, (o) => {
|
|
72
|
-
const p = this.state[e.fnName];
|
|
73
|
-
typeof p == "function" && p.call(n, o);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Retrieve all text nodes under a given root node.
|
|
79
|
-
*
|
|
80
|
-
* @param {Node} node
|
|
81
|
-
* @returns {Text[]}
|
|
82
|
-
*/
|
|
83
|
-
_getAllTextNodes(t) {
|
|
84
|
-
const i = [], e = document.createTreeWalker(
|
|
85
|
-
t,
|
|
86
|
-
NodeFilter.SHOW_TEXT,
|
|
87
|
-
null,
|
|
88
|
-
!1
|
|
89
|
-
);
|
|
90
|
-
let s;
|
|
91
|
-
for (; s = e.nextNode(); )
|
|
92
|
-
i.push(s);
|
|
93
|
-
return i;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* clears previous DOM, re-processes template and styles.
|
|
97
|
-
* Usually called by reactive state on mutation.
|
|
98
|
-
*/
|
|
99
|
-
_update() {
|
|
100
|
-
if (!this._isUpdating) {
|
|
101
|
-
this._isUpdating = !0;
|
|
102
|
-
try {
|
|
103
|
-
const t = r.content.cloneNode(!0);
|
|
104
|
-
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));
|
|
105
|
-
} finally {
|
|
106
|
-
this._isUpdating = !1;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// only update the nodes bound to a single key
|
|
111
|
-
_updateBinding(t) {
|
|
112
|
-
if (!this._isBinding) {
|
|
113
|
-
this._isBinding = !0;
|
|
114
|
-
try {
|
|
115
|
-
(this._textBindings[t] || []).forEach((i) => {
|
|
116
|
-
const e = this._origText.get(i) || "";
|
|
117
|
-
i.textContent = e.replace(/{([^}]+)}/g, (s, n) => (n = n.trim(), this.hasAttribute(n) ? this.getAttribute(n) : this.state[n]));
|
|
118
|
-
});
|
|
119
|
-
} finally {
|
|
120
|
-
this._isBinding = !1;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Called when the element is removed from the DOM
|
|
126
|
-
*/
|
|
127
|
-
disconnectedCallback() {
|
|
128
|
-
this._hasConnected = !1, c.log("disconnectedCallback", this);
|
|
129
|
-
}
|
|
130
|
-
// property
|
|
131
|
-
static get observedAttributes() {
|
|
132
|
-
return m;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Called when one of the observed attributes changes.
|
|
136
|
-
* Updates state and triggers a re-render via the reactive proxy.
|
|
137
|
-
*
|
|
138
|
-
* @param {string} name
|
|
139
|
-
* @param {string} oldVal
|
|
140
|
-
* @param {string} newVal
|
|
141
|
-
*/
|
|
142
|
-
attributeChangedCallback(t, i, e) {
|
|
143
|
-
i !== e && (this.state[t] = e);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Dispatch a custom event from the component.
|
|
147
|
-
*
|
|
148
|
-
* @param {string} name Event name
|
|
149
|
-
* @param {*} [detail] Payload; defaults to full component state
|
|
150
|
-
*/
|
|
151
|
-
emit(t, i) {
|
|
152
|
-
const e = i != null ? i : this.state;
|
|
153
|
-
this.dispatchEvent(
|
|
154
|
-
new CustomEvent(t, {
|
|
155
|
-
detail: e,
|
|
156
|
-
bubbles: !0
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
querySelector(t) {
|
|
161
|
-
return this.shadowRoot ? this.shadowRoot.querySelector(t) : super.querySelector(t);
|
|
162
|
-
}
|
|
163
|
-
querySelectorAll(t) {
|
|
164
|
-
return this.shadowRoot ? this.shadowRoot.querySelectorAll(t) : super.querySelectorAll(t);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
customElements.define(h, w), c.log(`Web component defined: <${h}></${h}>`);
|
|
168
|
-
};
|
|
169
|
-
export {
|
|
170
|
-
y as defineWebComponent
|
|
171
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./main-DtdmxWqG.js");function C(a,u={}){return new Proxy(u,{set(h,r,l){const g=h[r];return h[r]=l,g!==l&&!a._initializing&&(typeof a._updateBinding=="function"?a._updateBinding(r,l):a._update()),!0},get(h,r){return h[r]}})}const b=(a,u)=>{if(!a){c.logger.error("Component is not defined or invalid.");return}if(customElements.get(a.tagName)){c.logger.warn(`Component ${a.tagName} is already defined.`);return}const{tagName:h,template:r,script:l,style:g}=a,m=(d=>{const t=/{(.*?)}/g,i=new Set;let e;for(;(e=t.exec(d.innerHTML))!==null;)i.add(e[1].trim().toLowerCase());return Array.from(i)})(r),_=l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g,"state.$1 =").replace(/function\s+([\w$]+)\s*\(/g,"state.$1 = function ("),x=l?new Function("state",`with(state){${_}}`):()=>{},f=[];r.content.querySelectorAll("*").forEach(d=>{Array.from(d.attributes).forEach(t=>{if(!t.name.startsWith("on"))return;const i=t.name.slice(2),e=t.value.match(/{\s*([\w$]+)\(\)\s*}/);if(!e)return;const s=e[1];d.dataset._evtIndex=f.length,f.push({evt:i,fnName:s}),d.removeAttribute(t.name)})});class w extends HTMLElement{constructor(){super(),u&&this.attachShadow({mode:"open"}),this.state={},this.styleElement=document.createElement("style"),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=r.content.cloneNode(!0);this.shadowRoot?this.shadowRoot.innerHTML="":this.innerHTML="",this.shadowRoot?(this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.appendChild(this.styleElement),this.appendChild(t)),this.state=C(this,{}),this._initializing=!0;try{x.call(this,this.state)}catch(e){console.error("Error initializing component script:",e)}finally{this._initializing=!1}const i=this.shadowRoot||this;this._processTemplate(i)}_processTemplate(t){this._getAllTextNodes(t).forEach(e=>{const s=e.textContent;s.includes("{")&&s.includes("}")&&(this._origText.set(e,s),e.textContent=s.replace(/{([^}]+)}/g,(n,o)=>(o=o.trim(),this._textBindings[o]=this._textBindings[o]||[],this._textBindings[o].push(e),this.hasAttribute(o)?this.getAttribute(o):this.state[o]!==void 0?this.state[o]:n)))}),f.forEach((e,s)=>{const n=t.querySelector(`[data-_evt-index="${s}"]`);n.removeAttribute("data-_evt-index"),n.addEventListener(e.evt,o=>{const p=this.state[e.fnName];typeof p=="function"&&p.call(n,o)})})}_getAllTextNodes(t){const i=[],e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let s;for(;s=e.nextNode();)i.push(s);return i}_update(){if(!this._isUpdating){this._isUpdating=!0;try{const t=r.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(i=>{const e=this._origText.get(i)||"";i.textContent=e.replace(/{([^}]+)}/g,(s,n)=>(n=n.trim(),this.hasAttribute(n)?this.getAttribute(n):this.state[n]))})}finally{this._isBinding=!1}}}disconnectedCallback(){this._hasConnected=!1,c.logger.log("disconnectedCallback",this)}static get observedAttributes(){return m}attributeChangedCallback(t,i,e){i!==e&&(this.state[t]=e)}emit(t,i){const e=i!=null?i: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,w),c.logger.log(`Web component defined: <${h}></${h}>`)};exports.defineWebComponent=b;
|