ladrillosjs 2.0.0-beta.2 → 2.0.0-beta.2.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,970 +0,0 @@
1
- var at = Object.defineProperty, lt = Object.defineProperties;
2
- var ut = Object.getOwnPropertyDescriptors;
3
- var D = Object.getOwnPropertySymbols;
4
- var dt = Object.prototype.hasOwnProperty, ft = Object.prototype.propertyIsEnumerable;
5
- var J = (t) => {
6
- throw TypeError(t);
7
- };
8
- var X = (t, e, n) => e in t ? at(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, k = (t, e) => {
9
- for (var n in e || (e = {}))
10
- dt.call(e, n) && X(t, n, e[n]);
11
- if (D)
12
- for (var n of D(e))
13
- ft.call(e, n) && X(t, n, e[n]);
14
- return t;
15
- }, G = (t, e) => lt(t, ut(e));
16
- var z = (t, e, n) => e.has(t) || J("Cannot " + n);
17
- var A = (t, e, n) => (z(t, e, "read from private field"), n ? n.call(t) : e.get(t)), T = (t, e, n) => e.has(t) ? J("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, n), O = (t, e, n, s) => (z(t, e, "write to private field"), s ? s.call(t, n) : e.set(t, n), n), R = (t, e, n) => (z(t, e, "access private method"), n);
18
- var W = (t, e, n) => new Promise((s, o) => {
19
- var i = (u) => {
20
- try {
21
- a(n.next(u));
22
- } catch (c) {
23
- o(c);
24
- }
25
- }, r = (u) => {
26
- try {
27
- a(n.throw(u));
28
- } catch (c) {
29
- o(c);
30
- }
31
- }, a = (u) => u.done ? s(u.value) : Promise.resolve(u.value).then(i, r);
32
- a((n = n.apply(t, e)).next());
33
- });
34
- import { R as K, e as ht, l as pt } from "./index-CUJmLlUh.mjs";
35
- const mt = (t, e, n) => {
36
- if (!e) return;
37
- const s = document.createElement("style");
38
- s.textContent = e, n ? t.appendChild(s) : document.head.appendChild(s);
39
- }, bt = (t, e) => {
40
- t.innerHTML = e;
41
- const n = gt(t), s = Et(t), o = wt(t), i = yt(t);
42
- return { bindings: n, twoWayBindings: s, conditionals: o, loops: i };
43
- }, Q = (t) => {
44
- const e = [], n = t.match(/\((.*)\)/);
45
- if (!n) return e;
46
- const s = n[1].trim();
47
- return s && s.split(",").map((i) => i.trim()).forEach((i) => {
48
- if (/^['"]/.test(i) || /^\d+/.test(i)) return;
49
- const r = i.match(/^([a-zA-Z_$][a-zA-Z0-9_$]*)/);
50
- r && e.push(r[1]);
51
- }), e;
52
- }, gt = (t) => {
53
- const e = document.createTreeWalker(t, NodeFilter.SHOW_TEXT, null), n = [];
54
- let s;
55
- const o = (r) => {
56
- let a = r.parentElement;
57
- for (; a; ) {
58
- if (a.hasAttribute && a.hasAttribute("$for"))
59
- return !0;
60
- a = a.parentElement;
61
- }
62
- return !1;
63
- };
64
- for (; s = e.nextNode(); ) {
65
- if (o(s))
66
- continue;
67
- const r = [...s.textContent.matchAll(K.bindings)];
68
- if (r.length > 0) {
69
- const a = s.textContent, u = r.map((c) => {
70
- const l = c[1].trim(), d = l.includes("(") && l.includes(")"), p = /[+*/%<>=!&|]/.test(l) || // Math or logical operators (excluding hyphen)
71
- /\s-\s/.test(l) || /\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(l) || // Method calls like name.toLowerCase()
72
- /\bnew\s+/.test(l) || // Object instantiation like new Date()
73
- /\b(typeof|instanceof|void|delete)\b/.test(l), y = d ? [l.split("(")[0].trim()] : l.split(".").map((w) => w.trim()), m = d ? Q(l) : [];
74
- return { raw: l, path: y, isFunction: d, isExpression: p, functionArgs: m };
75
- });
76
- n.push({ node: s, bindings: u, original: a });
77
- }
78
- }
79
- return t.querySelectorAll("*").forEach((r) => {
80
- if (!(r.hasAttribute("$for") || o(r)))
81
- for (const a of r.attributes) {
82
- if (a.name === "$if" || a.name === "$else-if" || a.name === "$else" || a.name === "$bind")
83
- continue;
84
- const u = [...a.value.matchAll(K.bindings)];
85
- if (u.length > 0) {
86
- const c = a.value, l = u.map((d) => {
87
- const f = d[1].trim(), p = f.includes("(") && f.includes(")"), m = /[+*/%<>=!&|]/.test(f) || // Math or logical operators (excluding hyphen)
88
- /\s-\s/.test(f) || /\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(f) || // Method calls like name.toLowerCase()
89
- /\bnew\s+/.test(f) || // Object instantiation like new Date()
90
- /\b(typeof|instanceof|void|delete)\b/.test(f), w = p ? [f.split("(")[0].trim()] : f.split(".").map((M) => M.trim()), x = p ? Q(f) : [];
91
- return { raw: f, path: w, isFunction: p, isExpression: m, functionArgs: x };
92
- });
93
- n.push({
94
- node: r,
95
- bindings: l,
96
- original: c,
97
- isAttribute: !0,
98
- attributeName: a.name
99
- });
100
- }
101
- }
102
- }), n;
103
- }, Et = (t) => {
104
- const e = [];
105
- return t.querySelectorAll("[\\$bind]").forEach((s) => {
106
- var a;
107
- const o = s.getAttribute("$bind");
108
- if (!o) return;
109
- const i = o.trim(), r = i.split(".").map((u) => u.trim());
110
- s instanceof HTMLInputElement || s instanceof HTMLTextAreaElement || s instanceof HTMLSelectElement ? (e.push({
111
- element: s,
112
- path: r,
113
- raw: i,
114
- isContentEditable: !1,
115
- initialValue: s.value || ""
116
- }), s.removeAttribute("$bind")) : s instanceof HTMLElement && s.hasAttribute("contenteditable") && (e.push({
117
- element: s,
118
- path: r,
119
- raw: i,
120
- isContentEditable: !0,
121
- initialValue: ((a = s.textContent) == null ? void 0 : a.trim()) || ""
122
- }), s.removeAttribute("$bind"));
123
- }), e;
124
- }, wt = (t) => {
125
- const e = [], n = /* @__PURE__ */ new Set();
126
- return t.querySelectorAll("[\\$if]").forEach((o) => {
127
- if (n.has(o)) return;
128
- const i = [];
129
- let r = o;
130
- for (; r; ) {
131
- const a = r.hasAttribute("$if"), u = r.hasAttribute("$else-if"), c = r.hasAttribute("$else");
132
- if (!a && !u && !c) break;
133
- n.add(r);
134
- let l, d = "";
135
- a ? (l = "if", d = r.getAttribute("$if") || "", r.removeAttribute("$if")) : u ? (l = "else-if", d = r.getAttribute("$else-if") || "", r.removeAttribute("$else-if")) : (l = "else", r.removeAttribute("$else"));
136
- const f = document.createComment(
137
- `conditional:${l}:${d}`
138
- ), p = r.parentElement || t, y = r.nextSibling;
139
- p.insertBefore(f, r);
140
- const m = {
141
- element: r,
142
- condition: d.trim(),
143
- type: l,
144
- placeholder: f,
145
- group: [],
146
- // Will be set after the group is complete
147
- originalParent: p,
148
- nextSibling: y
149
- };
150
- i.push(m);
151
- const w = r.nextElementSibling;
152
- if (r.remove(), r = w, w && !w.hasAttribute("$else-if") && !w.hasAttribute("$else"))
153
- break;
154
- }
155
- i.forEach((a) => {
156
- a.group = i;
157
- }), e.push(i);
158
- }), e;
159
- }, $t = (t) => {
160
- const e = /* @__PURE__ */ new Set();
161
- return t.forEach((n) => {
162
- n.forEach((s) => {
163
- let o = s.condition;
164
- o = o.replace(/\{([^}]+)\}/g, "$1");
165
- const i = /\b([a-zA-Z_$][a-zA-Z0-9_$]*(?:\.[a-zA-Z_$][a-zA-Z0-9_$]*)*)\b/g, r = /* @__PURE__ */ new Set([
166
- "true",
167
- "false",
168
- "null",
169
- "undefined",
170
- "typeof",
171
- "instanceof",
172
- "new",
173
- "return",
174
- "if",
175
- "else",
176
- "for",
177
- "while",
178
- "do",
179
- "switch",
180
- "case",
181
- "break",
182
- "continue"
183
- ]);
184
- let a;
185
- for (; (a = i.exec(o)) !== null; ) {
186
- const c = a[1].split(".")[0];
187
- r.has(c) || e.add(c);
188
- }
189
- });
190
- }), e;
191
- }, yt = (t) => {
192
- const e = [];
193
- return t.querySelectorAll("[\\$for]").forEach((s) => {
194
- var p;
195
- const o = s.getAttribute("$for");
196
- if (!o) return;
197
- const i = s.getAttribute("$key") || void 0, r = o.match(
198
- /^\s*(?:\(([^,]+),\s*([^)]+)\)|([^\s]+))\s+(?:in|of)\s+(.+)\s*$/
199
- );
200
- if (!r) {
201
- console.error(`Invalid $for expression: "${o}"`);
202
- return;
203
- }
204
- const a = (r[1] || r[3]).trim(), u = (p = r[2]) == null ? void 0 : p.trim(), c = r[4].trim(), l = document.createComment(`loop:${o}`), d = s.parentElement || t;
205
- d.insertBefore(l, s), s.removeAttribute("$for"), i && s.removeAttribute("$key"), s.remove();
206
- const f = {
207
- template: s,
208
- expression: o,
209
- itemName: a,
210
- indexName: u,
211
- arrayName: c,
212
- keyAttribute: i,
213
- placeholder: l,
214
- renderedElements: [],
215
- originalParent: d
216
- };
217
- e.push(f);
218
- }), e;
219
- }, vt = (t) => {
220
- const e = /* @__PURE__ */ new Set();
221
- return t.forEach((n) => {
222
- const s = n.arrayName.split(".")[0];
223
- e.add(s);
224
- }), e;
225
- }, N = /* @__PURE__ */ new Map(), At = 100, P = (t) => {
226
- const e = N.get(t);
227
- if (e)
228
- return N.delete(t), N.set(t, e), e;
229
- const n = new Function(
230
- "component",
231
- `
232
- const { Date, Array, Math, String, Number, Boolean, Object, JSON, RegExp } = globalThis;
233
- with(component) {
234
- return ${t};
235
- }
236
- `
237
- );
238
- if (N.size >= At) {
239
- const s = N.keys().next().value;
240
- s && N.delete(s);
241
- }
242
- return N.set(t, n), n;
243
- }, H = (t, e) => e.reduce((n, s) => {
244
- if (!(n == null || typeof n != "object"))
245
- return n[s];
246
- }, t), q = (t, e, n) => {
247
- if (e.length === 0) return;
248
- const s = e[e.length - 1], o = e.slice(0, -1);
249
- let i = t;
250
- for (const r of o)
251
- (i[r] === void 0 || i[r] === null) && (i[r] = {}), i = i[r];
252
- i[s] = n;
253
- }, Y = (t, e, n) => {
254
- for (const s of t) {
255
- let o = s.original;
256
- for (const { raw: i, path: r, isFunction: a, isExpression: u } of s.bindings) {
257
- let c;
258
- if (u || a)
259
- try {
260
- const d = P(i), f = typeof e == "object" && e !== null ? k(k({}, e), n || {}) : n || {};
261
- c = d(f);
262
- } catch (d) {
263
- console.error(`Error executing expression binding {${i}}:`, d), c = void 0;
264
- }
265
- else
266
- c = H(e, r);
267
- if (c === void 0) continue;
268
- const l = String(c != null ? c : "");
269
- o = o.replace(`{${i}}`, l);
270
- }
271
- if (s.node.nodeType === Node.TEXT_NODE) {
272
- const i = s.node, r = i.parentElement, a = o.trim().startsWith("<") && o.includes(">");
273
- r && a ? r.innerHTML = o : i.textContent = o;
274
- } else {
275
- const i = s.node;
276
- s.isAttribute && s.attributeName && i.setAttribute(s.attributeName, o);
277
- }
278
- }
279
- }, xt = (t, e, n) => {
280
- if (!t) return !0;
281
- let s = t.trim();
282
- s = s.replace(/\{([^}]+)\}/g, "$1");
283
- try {
284
- return new Function(
285
- "context",
286
- "component",
287
- `
288
- with (context) {
289
- try {
290
- return Boolean(${s});
291
- } catch (e) {
292
- return false;
293
- }
294
- }
295
- `
296
- )(e, n);
297
- } catch (o) {
298
- return console.error(`Error evaluating condition "${t}":`, o), !1;
299
- }
300
- }, nt = (t, e) => {
301
- const n = [
302
- "click",
303
- "dblclick",
304
- "mousedown",
305
- "mouseup",
306
- "mouseover",
307
- "mouseout",
308
- "mousemove",
309
- "mouseenter",
310
- "mouseleave",
311
- "keydown",
312
- "keyup",
313
- "keypress",
314
- "focus",
315
- "blur",
316
- "change",
317
- "input",
318
- "submit",
319
- "reset",
320
- "scroll",
321
- "resize",
322
- "load",
323
- "unload",
324
- "touchstart",
325
- "touchend",
326
- "touchmove",
327
- "touchcancel",
328
- "dragstart",
329
- "drag",
330
- "dragend",
331
- "dragenter",
332
- "dragover",
333
- "dragleave",
334
- "drop"
335
- ];
336
- [t, ...t.querySelectorAll("*")].forEach((o) => {
337
- n.forEach((i) => {
338
- const r = `on${i}`, a = o.getAttribute(r);
339
- if (a) {
340
- const u = `__processed_${r}`;
341
- if (o[u]) return;
342
- o.removeAttribute(r), o.addEventListener(
343
- i,
344
- function(c) {
345
- try {
346
- new Function(
347
- "event",
348
- "component",
349
- `
350
- with(component) {
351
- ${a}
352
- }
353
- `
354
- ).call(this, c, e);
355
- } catch (l) {
356
- console.error(
357
- `Error executing ${i} handler:`,
358
- l,
359
- a
360
- );
361
- }
362
- }
363
- ), o[u] = !0;
364
- }
365
- });
366
- });
367
- }, tt = (t, e, n) => {
368
- var s;
369
- for (const o of t) {
370
- let i = !1;
371
- for (const r of o) {
372
- const { element: a, condition: u, type: c, placeholder: l, originalParent: d } = r;
373
- let f = !1;
374
- c === "else" ? f = !i : i || (f = xt(u, e, n), f && (i = !0));
375
- const p = a.parentNode !== null;
376
- f && !p ? ((s = l.parentNode) == null || s.insertBefore(a, l.nextSibling), n && nt(a, n)) : !f && p && a.remove();
377
- }
378
- }
379
- }, et = (t, e, n) => {
380
- for (const s of t) {
381
- const {
382
- template: o,
383
- itemName: i,
384
- indexName: r,
385
- arrayName: a,
386
- placeholder: u,
387
- renderedElements: c
388
- } = s, l = H(e, a.split("."));
389
- if (l !== void 0 && !Array.isArray(l)) {
390
- console.warn(`$for: "${a}" is not an array, got:`, l), c.forEach((d) => d.remove()), c.length = 0;
391
- return;
392
- }
393
- if (!l)
394
- return;
395
- c.forEach((d) => d.remove()), c.length = 0, l.forEach((d, f) => {
396
- var w;
397
- const p = o.cloneNode(!0), y = G(k({}, e), {
398
- [i]: d
399
- });
400
- r && (y[r] = f), St(p, y, n);
401
- const m = c.length > 0 ? c[c.length - 1] : u;
402
- (w = m.parentNode) == null || w.insertBefore(p, m.nextSibling), c.push(p), n && nt(p, n);
403
- });
404
- }
405
- }, St = (t, e, n) => {
406
- const s = document.createTreeWalker(t, NodeFilter.SHOW_TEXT, null);
407
- let o;
408
- for (; o = s.nextNode(); )
409
- if (o.textContent && o.textContent.includes("{")) {
410
- let r = o.textContent;
411
- [...o.textContent.matchAll(/\{([^}]+)\}/g)].forEach((u) => {
412
- const c = u[1].trim(), l = c.includes("(") && c.includes(")"), f = /[+*/%<>=!&|]/.test(c) || /\s-\s/.test(c) || /\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(c) || // Method calls
413
- /\bnew\s+/.test(c) || // Object instantiation like new Date()
414
- /\b(typeof|instanceof|void|delete)\b/.test(c);
415
- let p;
416
- if (f || l)
417
- try {
418
- const y = P(c), m = typeof e == "object" && e !== null ? k(k({}, e), n || {}) : n || {};
419
- p = y(m);
420
- } catch (y) {
421
- console.error(
422
- `Error executing expression in loop {${c}}:`,
423
- y
424
- ), p = void 0;
425
- }
426
- else {
427
- const y = c.split(".").map((m) => m.trim());
428
- p = H(e, y);
429
- }
430
- p !== void 0 && (r = r.replace(`{${c}}`, String(p != null ? p : "")));
431
- }), o.textContent = r;
432
- }
433
- [t, ...t.querySelectorAll("*")].forEach((r) => {
434
- Array.from(r.attributes).forEach((a) => {
435
- if (a.value.includes("{")) {
436
- let u = a.value;
437
- [...a.value.matchAll(/\{([^}]+)\}/g)].forEach((l) => {
438
- const d = l[1].trim(), f = d.includes("(") && d.includes(")"), y = /[+*/%<>=!&|]/.test(d) || /\s-\s/.test(d) || /\.(?![\s}])[a-zA-Z_$][\w]*\(/.test(d) || // Method calls
439
- /\bnew\s+/.test(d) || // Object instantiation like new Date()
440
- /\b(typeof|instanceof|void|delete)\b/.test(d);
441
- let m;
442
- if (y || f)
443
- try {
444
- const w = P(d), x = typeof e == "object" && e !== null ? k(k({}, e), n || {}) : n || {};
445
- m = w(x);
446
- } catch (w) {
447
- console.error(
448
- `Error executing expression in loop attribute {${d}}:`,
449
- w
450
- ), m = void 0;
451
- }
452
- else {
453
- const w = d.split(".").map((x) => x.trim());
454
- m = H(e, w);
455
- }
456
- m !== void 0 && (u = u.replace(`{${d}}`, String(m != null ? m : "")));
457
- }), r.setAttribute(a.name, u);
458
- }
459
- });
460
- });
461
- }, st = (t) => t instanceof ShadowRoot ? t.host : t, _t = (t, e) => {
462
- const n = /* @__PURE__ */ new Set();
463
- e.forEach(({ path: o }) => {
464
- const i = o[0];
465
- n.add(i);
466
- });
467
- const s = [];
468
- return n.forEach((o) => {
469
- s.push(`
470
- if (!Object.getOwnPropertyDescriptor(component, '${o}')) {
471
- Object.defineProperty(component, '${o}', {
472
- get() { return this.state.${o}; },
473
- set(val) { this.state.${o} = val; },
474
- enumerable: true,
475
- configurable: true
476
- });
477
- }
478
- `);
479
- }), {
480
- injectedCode: "",
481
- // No longer needed in script scope
482
- componentInjections: s.join(`
483
- `),
484
- bindVarNames: n
485
- };
486
- }, Ct = (t, e, n = /* @__PURE__ */ new Set()) => {
487
- const s = [], o = /* @__PURE__ */ new Set();
488
- e.forEach((a) => {
489
- a.bindings.forEach((u) => {
490
- const c = u.path[0];
491
- o.add(c), u.isFunction && u.functionArgs && u.functionArgs.forEach((l) => {
492
- o.add(l);
493
- });
494
- });
495
- }), n.forEach((a) => {
496
- o.add(a);
497
- });
498
- const i = /(?:const|let|var)\s+(\w+)\s*=\s*([^;]+);?/g;
499
- let r;
500
- for (; (r = i.exec(t)) !== null; ) {
501
- const a = r[1];
502
- o.has(a) && s.push(`component.state.${a} = ${a};`);
503
- }
504
- return { stateBindings: s, boundVarNames: o };
505
- }, Tt = (t, e) => {
506
- if (e.size === 0) return t;
507
- let n = t;
508
- return e.forEach((s) => {
509
- const o = new RegExp(
510
- `\\b${s}\\.(\\w+(?:\\.\\w+)*)\\s*([=+\\-*/%&|^]|\\+\\+|\\-\\-)`,
511
- "g"
512
- );
513
- n = n.replace(
514
- o,
515
- `component.state.${s}.$1 $2`
516
- );
517
- const i = new RegExp(
518
- `(?<!component\\.state\\.)(?<!const\\s${s}\\s*=\\s*{[^}]*)\\b${s}\\.(\\w+(?:\\.\\w+)*)(?![=+\\-*/%&|^]|\\+\\+|\\-\\-)`,
519
- "g"
520
- );
521
- n = n.replace(
522
- i,
523
- `component.state.${s}.$1`
524
- );
525
- const r = new RegExp(
526
- `(?<!\\.)\\b(\\+\\+|\\-\\-)${s}\\b|\\b${s}(\\+\\+|\\-\\-)`,
527
- "g"
528
- );
529
- n = n.replace(r, (c) => {
530
- if (c.startsWith("++") || c.startsWith("--"))
531
- return `${c.substring(0, 2)}component.state.${s}`;
532
- {
533
- const l = c.substring(c.length - 2);
534
- return `component.state.${s}${l}`;
535
- }
536
- });
537
- const a = new RegExp(
538
- `(?<!\\.)\\b${s}\\s*(\\+=|\\-=|\\*=|\\/=|%=|\\*\\*=|<<=|>>=|>>>=|&=|\\|=|\\^=)`,
539
- "g"
540
- );
541
- n = n.replace(
542
- a,
543
- `component.state.${s}$1`
544
- );
545
- const u = new RegExp(
546
- `(?<!const\\s)(?<!let\\s)(?<!var\\s)(?<!\\.)\\b${s}\\s*=\\s*([^=])`,
547
- "g"
548
- );
549
- n = n.replace(
550
- u,
551
- `component.state.${s} = $1`
552
- );
553
- }), n;
554
- }, ot = (t, e, n, s, o, i = /* @__PURE__ */ new Set()) => {
555
- try {
556
- const { injectedCode: r, componentInjections: a, bindVarNames: u } = _t(t, n), c = /function\s+(\w+)|const\s+(\w+)\s*=\s*(?:\([^)]*\)|[\w\s]*)\s*=>/g, l = [];
557
- let d;
558
- for (; (d = c.exec(t)) !== null; ) {
559
- const S = d[1] || d[2];
560
- S && l.push(S);
561
- }
562
- const f = l.map(
563
- (S) => `component.${S} = typeof ${S} !== 'undefined' ? ${S}.bind(component) : undefined;`
564
- ).join(`
565
- `), { stateBindings: p, boundVarNames: y } = Ct(
566
- t,
567
- e,
568
- i
569
- ), m = /* @__PURE__ */ new Set([...y, ...u]), w = p.join(`
570
- `), x = Tt(
571
- t,
572
- m
573
- ), M = `
574
- (function() {
575
- // Create component scope with direct access to state
576
- const component = this;
577
- const $state = component.state;
578
-
579
- // Define $bind variables on component object for event handler access
580
- ${a}
581
-
582
- // Provide framework utilities with $ prefix to avoid naming conflicts
583
- const $setState = (updates) => component.setState(updates);
584
-
585
- // Event bus methods for component communication
586
- const $emit = (eventName, data) => arguments[2].emit(eventName, data);
587
- const $listen = (eventName, callback) => {
588
- const unsubscribe = arguments[2].listen(eventName, callback);
589
- // Store unsubscribe function for cleanup on disconnect
590
- if (!component.__eventUnsubscribers) {
591
- component.__eventUnsubscribers = [];
592
- }
593
- component.__eventUnsubscribers.push(unsubscribe);
594
- return unsubscribe;
595
- };
596
-
597
- // Also attach to component for event handler access
598
- component.$emit = $emit;
599
- component.$listen = $listen;
600
-
601
- // Override querySelector/querySelectorAll to query within the component's host
602
- const host = arguments[1];
603
- const $querySelector = (selector) => host.querySelector(selector);
604
- const $querySelectorAll = (selector) => host.querySelectorAll(selector);
605
-
606
- // Execute script content within component scope so $bind variables are accessible
607
- with(component) {
608
- ${x}
609
-
610
- // Auto-bind variables to component state (e.g., const name = "value" → this.state.name = "value")
611
- ${w}
612
-
613
- // Auto-attach all detected functions to component for onclick access
614
- ${f}
615
- }
616
- }).call(arguments[0], arguments[0], arguments[1], arguments[2])
617
- `;
618
- new Function(M)(o, s, ht);
619
- } catch (r) {
620
- console.error("Script execution failed:", r);
621
- }
622
- }, rt = (t, e) => {
623
- [
624
- "click",
625
- "dblclick",
626
- "mousedown",
627
- "mouseup",
628
- "mouseover",
629
- "mouseout",
630
- "mousemove",
631
- "mouseenter",
632
- "mouseleave",
633
- "keydown",
634
- "keyup",
635
- "keypress",
636
- "focus",
637
- "blur",
638
- "change",
639
- "input",
640
- "submit",
641
- "reset",
642
- "scroll",
643
- "resize",
644
- "load",
645
- "unload",
646
- "touchstart",
647
- "touchend",
648
- "touchmove",
649
- "touchcancel",
650
- "dragstart",
651
- "drag",
652
- "dragend",
653
- "dragenter",
654
- "dragover",
655
- "dragleave",
656
- "drop"
657
- ].forEach((s) => {
658
- const o = `on${s}`;
659
- (t instanceof ShadowRoot ? t.querySelectorAll(`[${o}]`) : e.querySelectorAll(`[${o}]`)).forEach((r) => {
660
- const a = `${o}`;
661
- if (r[`__processed_${a}`]) return;
662
- const u = r.getAttribute(o);
663
- u && (r.removeAttribute(o), r.addEventListener(
664
- s,
665
- function(c) {
666
- new Function(
667
- "event",
668
- "component",
669
- `
670
- with(component) {
671
- ${u}
672
- }
673
- `
674
- ).call(this, c, e);
675
- }
676
- ), r[`__processed_${a}`] = !0);
677
- });
678
- });
679
- }, kt = (i, r, a, ...u) => W(null, [i, r, a, ...u], function* (t, e, n, s = [], o = /* @__PURE__ */ new Set()) {
680
- if (!(e != null && e.length)) return;
681
- const c = st(t);
682
- for (const l of e)
683
- l.content && ot(
684
- l.content,
685
- n,
686
- s,
687
- t,
688
- c,
689
- o
690
- );
691
- rt(t, c);
692
- }), Lt = (t, e) => new Promise((n, s) => {
693
- const o = document.querySelector(
694
- `script[src="${t}"]`
695
- );
696
- if (o) {
697
- if (o.dataset.loaded === "true") {
698
- n();
699
- return;
700
- }
701
- o.addEventListener("load", () => n(), { once: !0 }), o.addEventListener(
702
- "error",
703
- () => s(new Error(`Failed to load external script: ${t}`)),
704
- { once: !0 }
705
- );
706
- return;
707
- }
708
- const i = document.createElement("script");
709
- i.src = t, e && (i.type = e), i.onload = () => {
710
- i.dataset.loaded = "true", n();
711
- }, i.onerror = () => s(new Error(`Failed to load external script: ${t}`)), document.head.appendChild(i);
712
- }), Nt = (r, a, u, ...c) => W(null, [r, a, u, ...c], function* (t, e, n, s = [], o = /* @__PURE__ */ new Set(), i) {
713
- var d;
714
- const l = st(t);
715
- for (const f of e) {
716
- let p;
717
- i ? i.startsWith("http://") || i.startsWith("https://") ? p = i : p = new URL(
718
- i,
719
- window.location.href
720
- ).href : p = window.location.href;
721
- const y = new URL(f.src, p).href;
722
- if (f.external)
723
- yield Lt(y, f.type);
724
- else if (f.type === "module") {
725
- const m = l.tagName.toLowerCase();
726
- window.__ladrilloContexts || (window.__ladrilloContexts = /* @__PURE__ */ new Map()), window.__ladrilloContexts.set(m, {
727
- host: t,
728
- shadowRoot: t instanceof ShadowRoot ? t : null,
729
- element: l,
730
- state: l.state,
731
- setState: (d = l.setState) == null ? void 0 : d.bind(l)
732
- });
733
- const w = document.createElement("script");
734
- w.type = "module", w.src = y, w.setAttribute("data-component", m), document.head.appendChild(w);
735
- } else
736
- yield fetch(y).then((m) => {
737
- if (!m.ok)
738
- throw new Error(`HTTP ${m.status}: ${m.statusText}`);
739
- const w = m.headers.get("content-type");
740
- if (w && !w.includes("javascript") && !w.includes("text/plain"))
741
- throw new Error(`Expected JavaScript but got ${w}`);
742
- return m.text();
743
- }).then((m) => {
744
- ot(
745
- m,
746
- n,
747
- s,
748
- t,
749
- l,
750
- o
751
- );
752
- }).catch((m) => {
753
- console.error(`Failed to load external script: ${f.src}`, m);
754
- });
755
- }
756
- rt(t, l);
757
- }), Ft = (t, e) => {
758
- var c, l, d, f, p, y, m, U, x, it, ct;
759
- const { tagName: n, template: s, scripts: o, externalScripts: i, styles: r, sourcePath: a } = t, S = class S extends HTMLElement {
760
- constructor() {
761
- super();
762
- T(this, m);
763
- T(this, c, []);
764
- T(this, l, []);
765
- T(this, d, []);
766
- T(this, f, []);
767
- T(this, p, []);
768
- T(this, y, a);
769
- e && this.attachShadow({ mode: "open" });
770
- const h = {}, g = () => {
771
- Y(A(this, c), this.state, this), tt(A(this, d), this.state, this), et(A(this, f), this.state, this), R(this, m, ct).call(this);
772
- };
773
- this.state = new Proxy(h, {
774
- get: ($, b) => $[b],
775
- set: ($, b, E) => {
776
- const _ = $[b];
777
- return Object.is(_, E) || (E !== null && typeof E == "object" ? $[b] = R(this, m, U).call(this, E, g) : $[b] = E, Object.getOwnPropertyDescriptor(this, b) || Object.defineProperty(this, b, {
778
- get() {
779
- return this.state[b];
780
- },
781
- set(L) {
782
- this.state[b] = L;
783
- },
784
- enumerable: !0,
785
- configurable: !0
786
- }), g()), !0;
787
- }
788
- });
789
- }
790
- /**
791
- * Updates component state with one or more key-value pairs
792
- * @param updates - Object containing state updates
793
- * @example
794
- * component.setState({ count: 5, name: 'John' })
795
- */
796
- setState(h) {
797
- Object.assign(this.state, h);
798
- }
799
- // Invoked when element is added to the DOM
800
- connectedCallback() {
801
- return W(this, null, function* () {
802
- const h = e ? this.shadowRoot : this, { bindings: g, twoWayBindings: $, conditionals: b, loops: E } = bt(
803
- h,
804
- s
805
- );
806
- O(this, c, g), O(this, l, $), O(this, d, b), O(this, f, E);
807
- const _ = $t(b), L = vt(E);
808
- mt(h, r, e), this._initializeStateFromAttributes(), this._setupTwoWayBindings(), yield Nt(
809
- h,
810
- i,
811
- A(this, c),
812
- A(this, l),
813
- /* @__PURE__ */ new Set([..._, ...L]),
814
- A(this, y)
815
- ), yield kt(
816
- h,
817
- o,
818
- A(this, c),
819
- A(this, l),
820
- /* @__PURE__ */ new Set([..._, ...L])
821
- ), Y(A(this, c), this.state, this), tt(A(this, d), this.state, this), et(A(this, f), this.state, this), this._setupAttributeObserver();
822
- });
823
- }
824
- // Invoked when element is removed from the DOM
825
- disconnectedCallback() {
826
- this.__attributeObserver && (this.__attributeObserver.disconnect(), this.__attributeObserver = null), A(this, p).forEach((g) => {
827
- try {
828
- g();
829
- } catch ($) {
830
- console.error("Error cleaning up two-way binding:", $);
831
- }
832
- }), O(this, p, []);
833
- const h = this.__eventUnsubscribers;
834
- h && Array.isArray(h) && (h.forEach((g) => {
835
- try {
836
- g();
837
- } catch ($) {
838
- console.error("Error unsubscribing from event:", $);
839
- }
840
- }), this.__eventUnsubscribers = []);
841
- }
842
- // Set up observer to watch for attribute changes
843
- _setupAttributeObserver() {
844
- const h = new MutationObserver((g) => {
845
- g.forEach(($) => {
846
- if ($.type === "attributes" && $.attributeName) {
847
- const b = this.getAttribute($.attributeName);
848
- this._handleAttributeChange($.attributeName, b);
849
- }
850
- });
851
- });
852
- h.observe(this, {
853
- attributes: !0,
854
- attributeOldValue: !0
855
- }), this.__attributeObserver = h;
856
- }
857
- // initializes the state from the attributes
858
- _initializeStateFromAttributes() {
859
- this.getAttributeNames().forEach((h) => {
860
- const g = this.getAttribute(h);
861
- this._handleAttributeChange(h, g);
862
- });
863
- }
864
- // Invoked when attributes are changed.
865
- _handleAttributeChange(h, g) {
866
- var b;
867
- if (h) {
868
- const E = "this.state.";
869
- h.startsWith(E) && (h = h.slice(E.length));
870
- }
871
- const $ = R(b = S, x, it).call(b, g);
872
- this.state[h] = $;
873
- }
874
- // Setup two-way data bindings for input elements with $bind
875
- _setupTwoWayBindings() {
876
- A(this, l).forEach(
877
- ({ element: h, path: g, raw: $, isContentEditable: b, initialValue: E }) => {
878
- var L, Z;
879
- if (this._getNestedValue(g) === void 0) {
880
- const v = E || "";
881
- q(this.state, g, v);
882
- }
883
- if (b) {
884
- const v = h;
885
- v.textContent = (L = this._getNestedValue(g)) != null ? L : "";
886
- const V = (I) => {
887
- const C = I.target.textContent || "";
888
- q(this.state, g, C);
889
- };
890
- v.addEventListener("input", V);
891
- const B = () => {
892
- v.removeEventListener("input", V);
893
- };
894
- A(this, p).push(B);
895
- } else {
896
- const v = h, V = v instanceof HTMLInputElement && v.type === "checkbox";
897
- v instanceof HTMLInputElement && v.type, V ? v.checked = !!this._getNestedValue(g) : v.value = (Z = this._getNestedValue(g)) != null ? Z : "";
898
- const B = (F) => {
899
- const C = F.target;
900
- let j;
901
- C instanceof HTMLInputElement && C.type === "checkbox" ? j = C.checked : (C instanceof HTMLInputElement && C.type, j = C.value), q(this.state, g, j);
902
- };
903
- v.addEventListener("input", B);
904
- const I = () => {
905
- v.removeEventListener("input", B);
906
- };
907
- if (A(this, p).push(I), v instanceof HTMLSelectElement || v instanceof HTMLInputElement && ["checkbox", "radio", "file"].includes(v.type)) {
908
- v.addEventListener("change", B);
909
- const F = () => {
910
- v.removeEventListener("change", B);
911
- };
912
- A(this, p).push(F);
913
- }
914
- }
915
- }
916
- );
917
- }
918
- // Helper to get nested value from state
919
- _getNestedValue(h) {
920
- return h.reduce((g, $) => g == null ? void 0 : g[$], this.state);
921
- }
922
- };
923
- c = new WeakMap(), l = new WeakMap(), d = new WeakMap(), f = new WeakMap(), p = new WeakMap(), y = new WeakMap(), m = new WeakSet(), /**
924
- * Creates a deep reactive proxy that tracks nested object/array mutations
925
- * @param target - The object or array to make reactive
926
- * @param callback - Function to call when any nested property changes
927
- */
928
- U = function(h, g) {
929
- return h === null || typeof h != "object" || h instanceof HTMLElement || h instanceof Node ? h : new Proxy(h, {
930
- get: ($, b) => {
931
- const E = $[b];
932
- return E !== null && typeof E == "object" ? R(this, m, U).call(this, E, g) : E;
933
- },
934
- set: ($, b, E) => {
935
- const _ = $[b];
936
- return Object.is(_, E) || ($[b] = E, g()), !0;
937
- }
938
- });
939
- }, x = new WeakSet(), it = function(h) {
940
- if (h === null || h === "") return null;
941
- if (h !== "undefined")
942
- try {
943
- return JSON.parse(h);
944
- } catch (g) {
945
- return h;
946
- }
947
- }, // Update two-way bound elements when state changes
948
- ct = function() {
949
- A(this, l).forEach(({ element: h, path: g, isContentEditable: $ }) => {
950
- const b = this._getNestedValue(g);
951
- if ($) {
952
- const E = h;
953
- E.textContent !== b && (E.textContent = b != null ? b : "");
954
- } else {
955
- const E = h;
956
- if (E instanceof HTMLInputElement && E.type === "checkbox") {
957
- const _ = !!b;
958
- E.checked !== _ && (E.checked = _);
959
- } else
960
- E.value !== b && (E.value = b != null ? b : "");
961
- }
962
- });
963
- }, T(S, x);
964
- let u = S;
965
- customElements.define(n, u), pt.log(`Web component defined: <${n}></${n}>`);
966
- };
967
- export {
968
- Ft as defineWebComponent
969
- };
970
- //# sourceMappingURL=webcomponent-DzBRHkic.mjs.map