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