@unbndl/store 1.0.0

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/store.js ADDED
@@ -0,0 +1,1590 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.defineProperty, t = (t, n) => {
3
+ let r = {};
4
+ for (var i in t) e(r, i, {
5
+ get: t[i],
6
+ enumerable: !0
7
+ });
8
+ return n || e(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ }, n = class extends Error {};
10
+ n.prototype.name = "InvalidTokenError";
11
+ function r(e) {
12
+ return decodeURIComponent(atob(e).replace(/(.)/g, (e, t) => {
13
+ let n = t.charCodeAt(0).toString(16).toUpperCase();
14
+ return n.length < 2 && (n = "0" + n), "%" + n;
15
+ }));
16
+ }
17
+ function i(e) {
18
+ let t = e.replace(/-/g, "+").replace(/_/g, "/");
19
+ switch (t.length % 4) {
20
+ case 0: break;
21
+ case 2:
22
+ t += "==";
23
+ break;
24
+ case 3:
25
+ t += "=";
26
+ break;
27
+ default: throw Error("base64 string is not of the correct length");
28
+ }
29
+ try {
30
+ return r(t);
31
+ } catch {
32
+ return atob(t);
33
+ }
34
+ }
35
+ function a(e, t) {
36
+ if (typeof e != "string") throw new n("Invalid token specified: must be a string");
37
+ t ||= {};
38
+ let r = t.header === !0 ? 0 : 1, a = e.split(".")[r];
39
+ if (typeof a != "string") throw new n(`Invalid token specified: missing part #${r + 1}`);
40
+ let o;
41
+ try {
42
+ o = i(a);
43
+ } catch (e) {
44
+ throw new n(`Invalid token specified: invalid base64 for part #${r + 1} (${e.message})`);
45
+ }
46
+ try {
47
+ return JSON.parse(o);
48
+ } catch (e) {
49
+ throw new n(`Invalid token specified: invalid json for part #${r + 1} (${e.message})`);
50
+ }
51
+ }
52
+ var o = Object.defineProperty, s = /* @__PURE__ */ ((e, t) => {
53
+ let n = {};
54
+ for (var r in e) o(n, r, {
55
+ get: e[r],
56
+ enumerable: !0
57
+ });
58
+ return t || o(n, Symbol.toStringTag, { value: "Module" }), n;
59
+ })({
60
+ Dispatch: () => l,
61
+ None: () => c,
62
+ dispatch: () => ee,
63
+ dispatcher: () => u
64
+ }), c = [], l = class extends CustomEvent {
65
+ constructor(e, t = "un:message") {
66
+ super(t, {
67
+ bubbles: !0,
68
+ composed: !0,
69
+ detail: e
70
+ });
71
+ }
72
+ };
73
+ function u(e = "un:message") {
74
+ return (t, ...n) => t.dispatchEvent(new l(n, e));
75
+ }
76
+ var ee = u(), te = class extends CustomEvent {
77
+ constructor(e, t) {
78
+ super(e, {
79
+ bubbles: !0,
80
+ cancelable: !0,
81
+ composed: !0,
82
+ detail: t
83
+ });
84
+ }
85
+ };
86
+ function d(e, ...t) {
87
+ let n = { execute() {
88
+ e(...t.map((e) => e instanceof p ? e.open(n) : e)), t.forEach((e) => e instanceof p && e.close());
89
+ } };
90
+ n.execute();
91
+ }
92
+ var f = class e {
93
+ constructor() {
94
+ this.signals = /* @__PURE__ */ new WeakMap(), this.scheduled = /* @__PURE__ */ new WeakSet();
95
+ }
96
+ static {
97
+ this.scheduler = new e();
98
+ }
99
+ subscribe(e, t, n) {
100
+ let r = this.signals.get(e);
101
+ r || (r = /* @__PURE__ */ new Map(), this.signals.set(e, r));
102
+ let i = r.get(t);
103
+ i || (i = /* @__PURE__ */ new Set(), r.set(t, i)), i.add(n);
104
+ }
105
+ scheduleEffects(e, t) {
106
+ let n = this.signals.get(e);
107
+ if (!n) return;
108
+ let r = n.get(t);
109
+ if (r) for (let e of r) this.scheduled.has(e) || (this.scheduled.add(e), setTimeout(() => {
110
+ this.scheduled.delete(e), e.execute();
111
+ }));
112
+ }
113
+ }, ne = class {
114
+ constructor() {
115
+ this.running = [], this.eventType = "un-effect:change";
116
+ }
117
+ isRunning() {
118
+ return this.running.length > 0;
119
+ }
120
+ push(e) {
121
+ this.running.push(e);
122
+ }
123
+ pop() {
124
+ this.running.pop();
125
+ }
126
+ current() {
127
+ let e = this.running.length;
128
+ return e ? this.running[e - 1] : void 0;
129
+ }
130
+ subscribe(e, t) {
131
+ let n = this.current();
132
+ n && f.scheduler.subscribe(t, e, n);
133
+ }
134
+ runEffects(e, t) {
135
+ if (f.scheduler.scheduleEffects(t, e), this.host) {
136
+ let n = new te(this.eventType, {
137
+ property: e,
138
+ value: t[e]
139
+ });
140
+ this.host.dispatchEvent(n);
141
+ }
142
+ }
143
+ setHost(e, t) {
144
+ this.host = e, t && (this.eventType = t);
145
+ }
146
+ }, p = class {
147
+ static {
148
+ this.CHANGE_EVENT_TYPE = "un-context:change";
149
+ }
150
+ constructor(e, t) {
151
+ t ? (this.manager = t.manager, this.object = t.object, this.proxy = t.proxy, this.update(e)) : (this.manager = new ne(), this.object = e, this.proxy = re(this.object, this.manager));
152
+ }
153
+ get(e) {
154
+ return this.proxy[e];
155
+ }
156
+ set(e, t) {
157
+ this.proxy[e] = t;
158
+ }
159
+ toObject() {
160
+ return this.object;
161
+ }
162
+ update(e) {
163
+ Object.assign(this.proxy, e);
164
+ }
165
+ apply(e) {
166
+ this.update(e(this.proxy));
167
+ }
168
+ createEffect(e) {
169
+ d(e, this);
170
+ }
171
+ setHost(e, t) {
172
+ this.manager.setHost(e, t);
173
+ }
174
+ open(e) {
175
+ return this.manager.push(e), this.proxy;
176
+ }
177
+ close() {
178
+ this.manager.pop();
179
+ }
180
+ };
181
+ function re(e, t) {
182
+ return new Proxy(e, {
183
+ get: (e, n, r) => {
184
+ let i = Reflect.get(e, n, r);
185
+ return t.isRunning() && m(i) && t.subscribe(n, e), i;
186
+ },
187
+ set: (e, n, r, i) => {
188
+ let a = Reflect.set(e, n, r, i);
189
+ return a && m(r) && t.runEffects(n, e), a;
190
+ }
191
+ });
192
+ }
193
+ function m(e) {
194
+ switch (typeof e) {
195
+ case "object":
196
+ case "number":
197
+ case "string":
198
+ case "symbol":
199
+ case "boolean":
200
+ case "undefined": return !0;
201
+ default: return !1;
202
+ }
203
+ }
204
+ var ie = class {
205
+ constructor(e, ...t) {
206
+ this.effectFn = () => e(...t);
207
+ }
208
+ execute() {
209
+ this.effectFn();
210
+ }
211
+ };
212
+ function ae(e, t) {
213
+ return Object.assign(e, { render: t }), e;
214
+ }
215
+ function oe(e, t, ...n) {
216
+ let r = e.cloneNode(!0);
217
+ return Array.from(t.entries()).forEach(([e, t]) => {
218
+ let i = r.querySelector(`[data-${e}]`);
219
+ i && t.forEach((e) => e(i, r, ...n));
220
+ }), r;
221
+ }
222
+ var se = class e {
223
+ static {
224
+ this.parser = new DOMParser();
225
+ }
226
+ constructor(e) {
227
+ this.docType = "text/html", this.plugins = [], e && (this.docType = e);
228
+ }
229
+ use(e) {
230
+ this.plugins = this.plugins.concat(e);
231
+ }
232
+ parse(t, n) {
233
+ let r = {}, i = t.map((e, i) => {
234
+ if (i >= n.length) return [e];
235
+ let a = n[i], o = this.classifyPlace(i, t), s = this.tryReplacements(o, a);
236
+ if (s) {
237
+ let t = r[o.nodeLabel];
238
+ switch (t ? t.push(s) : r[o.nodeLabel] = [s], o.kind) {
239
+ case "attr value": return [e, `"" data-${o.nodeLabel}`];
240
+ case "tag content": return [e, `data-${o.nodeLabel}`];
241
+ case "element content": return [e, `<ins data-${o.nodeLabel}></ins>`];
242
+ }
243
+ } else throw console.error("No match for template parameter", o, a), `Failed to render template parameter ${i} around ${e}`;
244
+ return [e];
245
+ }).flat().join(""), a = e.parser.parseFromString(i, this.docType), o = a.head.childElementCount ? a.head.children : a.body.children, s = new DocumentFragment();
246
+ s.replaceChildren(...o);
247
+ let c = /* @__PURE__ */ new Map();
248
+ for (let e in r) {
249
+ let t = s.querySelector(`[data-${e}]`);
250
+ t && r[e].forEach((n) => {
251
+ let r = n.apply(t, s);
252
+ if (r) {
253
+ let t = c.get(e);
254
+ t ? t.push(r) : c.set(e, [r]);
255
+ }
256
+ });
257
+ }
258
+ return ae(s, (...e) => oe(s, c, ...e));
259
+ }
260
+ static {
261
+ this.OPEN_RE = /<([a-zA-z][$a-zA-Z0-9.-]*)\s+[^>]*$/;
262
+ }
263
+ static {
264
+ this.IN_TAG_RE = /^(\s+|[^<>]*|"[^"]*")*$/;
265
+ }
266
+ static {
267
+ this.ATTR_RE = /([$.]?[a-zA-Z][$a-zA-Z0-9.-]*)=\s*$/;
268
+ }
269
+ static {
270
+ this.CLOSE_RE = /[/]?>[^<]*$/;
271
+ }
272
+ classifyPlace(t, n) {
273
+ let r = null;
274
+ for (let i = t; i >= 0 && !(n[i].match(e.CLOSE_RE) || (r = n[i].match(e.OPEN_RE), r) || !n[i].match(e.IN_TAG_RE)); i--);
275
+ if (r) {
276
+ let i = n[t].match(e.ATTR_RE);
277
+ return i ? {
278
+ kind: "attr value",
279
+ nodeLabel: `node${t}`,
280
+ tagName: r[1],
281
+ attrName: i[1]
282
+ } : {
283
+ kind: "tag content",
284
+ nodeLabel: `node${t}`,
285
+ tagName: r[1]
286
+ };
287
+ }
288
+ return {
289
+ kind: "element content",
290
+ nodeLabel: `node${t}`
291
+ };
292
+ }
293
+ tryReplacements(e, t) {
294
+ let n = this.plugins;
295
+ for (let r = 0; r < n.length; r++) {
296
+ let i = n[r];
297
+ if (e.kind === i.place && ce(t, i)) return i.mutator(e, t);
298
+ }
299
+ }
300
+ };
301
+ function ce(e, t) {
302
+ return typeof t.types == "function" ? t.types(e, t) : t.types.includes(typeof e);
303
+ }
304
+ var h = class {
305
+ constructor(e) {
306
+ this.place = e;
307
+ }
308
+ apply(e, t) {
309
+ throw "abstract method 'apply' called";
310
+ }
311
+ }, g = class extends h {
312
+ constructor(e, t) {
313
+ super(e), this.content = t;
314
+ }
315
+ apply(e, t) {
316
+ (e.parentNode || t).replaceChild(this.content, e);
317
+ }
318
+ }, le = class extends h {
319
+ constructor(e, t) {
320
+ super(e), this.text = t, this.name = e.attrName;
321
+ }
322
+ apply(e) {
323
+ e.setAttribute(this.name, this.text);
324
+ }
325
+ }, _ = class extends h {
326
+ constructor(e, t) {
327
+ super(e), this.fn = t;
328
+ }
329
+ apply(e, t) {
330
+ let n = this.place.nodeLabel;
331
+ return (e, t, ...r) => {
332
+ let i = new Comment(` <<< ${n} `), a = new Comment(` >>> ${n} `), o = new DocumentFragment();
333
+ o.replaceChildren(i, a), (e.parentNode || t).replaceChild(o, e), d((...e) => {
334
+ v(this.fn(...e), i, a);
335
+ }, ...r);
336
+ };
337
+ }
338
+ };
339
+ function v(e, t, n) {
340
+ let r = t.parentNode;
341
+ if (!r) throw Error("No parent for placeholder");
342
+ let i = (e) => {
343
+ if (Array.isArray(e)) {
344
+ let t = new DocumentFragment(), n = e.map(i);
345
+ return t.replaceChildren(...n), t;
346
+ } else if (e instanceof Node) return e;
347
+ else return new Text(e?.toString() || "");
348
+ }, a = i(e);
349
+ console.log("📸 Rendered for view:", e, a);
350
+ let o = t.nextSibling;
351
+ for (; o && o !== n;) {
352
+ let e = o;
353
+ o = o.nextSibling, r.removeChild(e);
354
+ }
355
+ a && r.insertBefore(a, n);
356
+ }
357
+ var y = class extends h {
358
+ constructor(e, t) {
359
+ super(e), this.fn = t, this.name = e.attrName;
360
+ }
361
+ apply(e, t) {
362
+ return (e, t, ...n) => d((...t) => {
363
+ b(this.fn(...t), e, this.name);
364
+ }, ...n);
365
+ }
366
+ };
367
+ function b(e, t, n) {
368
+ let r = n.match(/^([.$])(.+)$/);
369
+ if (r) {
370
+ let [n, i, a] = r;
371
+ switch (i) {
372
+ case ".":
373
+ t[a] = e;
374
+ break;
375
+ case "$":
376
+ "viewModel" in t && t.viewModel instanceof p && t.viewModel.set(a, e);
377
+ break;
378
+ }
379
+ } else switch (typeof e) {
380
+ case "string":
381
+ t.setAttribute(n, e);
382
+ break;
383
+ case "undefined":
384
+ case "object":
385
+ case "boolean":
386
+ e ? t.setAttribute(n, n) : t.removeAttribute(n);
387
+ break;
388
+ default: t.setAttribute(n, e?.toString());
389
+ }
390
+ }
391
+ var x = class extends h {
392
+ constructor(e, t) {
393
+ super(e), this.fn = t;
394
+ }
395
+ apply(e, t) {
396
+ return (e, t, ...n) => d((...t) => {
397
+ let n = this.fn(...t);
398
+ typeof n == "function" && n(e);
399
+ }, ...n);
400
+ }
401
+ };
402
+ new se().use([
403
+ {
404
+ place: "element content",
405
+ types: [
406
+ "string",
407
+ "number",
408
+ "bigint",
409
+ "symbol",
410
+ "boolean"
411
+ ],
412
+ mutator: (e, t) => new g(e, new Text(t?.toString() || ""))
413
+ },
414
+ {
415
+ place: "attr value",
416
+ types: [
417
+ "string",
418
+ "number",
419
+ "bigint",
420
+ "symbol"
421
+ ],
422
+ mutator: (e, t) => new le(e, t?.toString() || "")
423
+ },
424
+ {
425
+ place: "element content",
426
+ types: (e) => e instanceof Node,
427
+ mutator: (e, t) => new g(e, t)
428
+ },
429
+ {
430
+ place: "element content",
431
+ types: ["function"],
432
+ mutator: (e, t) => new _(e, t)
433
+ },
434
+ {
435
+ place: "attr value",
436
+ types: ["function"],
437
+ mutator: (e, t) => new y(e, t)
438
+ },
439
+ {
440
+ place: "tag content",
441
+ types: ["function"],
442
+ mutator: (e, t) => new x(e, t)
443
+ }
444
+ ]);
445
+ var ue = class e extends HTMLElement {
446
+ static {
447
+ this.DISCOVERY_EVENT = "un-provider:discover";
448
+ }
449
+ static {
450
+ this.REGISTRY_EVENT = "un-provider:register";
451
+ }
452
+ static {
453
+ this.CHANGE_EVENT = "un-provider:change";
454
+ }
455
+ static {
456
+ document.addEventListener(e.DISCOVERY_EVENT, (e) => {
457
+ let [t, n] = e.detail, r = pe(t);
458
+ r && n(r);
459
+ }), document.addEventListener(e.REGISTRY_EVENT, (e) => {
460
+ let [t, n] = e.detail;
461
+ fe(t, n);
462
+ });
463
+ }
464
+ constructor(t, n) {
465
+ super(), this.contextLabel = n, this.context = new p(t), this.context.setHost(this, e.CHANGE_EVENT), this.addEventListener(e.DISCOVERY_EVENT, (e) => {
466
+ let [t, n] = e.detail;
467
+ t === this.contextLabel && (e.stopPropagation(), n(this));
468
+ });
469
+ let r = new CustomEvent(e.REGISTRY_EVENT, {
470
+ bubbles: !0,
471
+ composed: !0,
472
+ detail: [this.contextLabel, this]
473
+ });
474
+ this.dispatchEvent(r);
475
+ }
476
+ attach(t) {
477
+ return this.addEventListener(e.CHANGE_EVENT, t), this.context.toObject();
478
+ }
479
+ detach(t) {
480
+ this.removeEventListener(e.CHANGE_EVENT, t);
481
+ }
482
+ };
483
+ function de(e, t) {
484
+ return new Promise((n, r) => {
485
+ let i = new CustomEvent(ue.DISCOVERY_EVENT, {
486
+ bubbles: !0,
487
+ composed: !0,
488
+ detail: [t, (e) => e ? n(e) : r()]
489
+ });
490
+ e.isConnected ? e.dispatchEvent(i) : document.dispatchEvent(i);
491
+ });
492
+ }
493
+ var S = {};
494
+ function fe(e, t) {
495
+ S[e] = t;
496
+ }
497
+ function pe(e) {
498
+ return S[e];
499
+ }
500
+ var me = class {
501
+ constructor(e) {
502
+ this.contextLabel = e;
503
+ }
504
+ observe(e, t) {
505
+ return new Promise((n, r) => {
506
+ this.provider ? n(this.attachObserver(t)) : de(e, this.contextLabel).then((e) => {
507
+ this.provider = e, n(this.attachObserver(t));
508
+ }).catch((e) => r(e));
509
+ });
510
+ }
511
+ attachObserver(e) {
512
+ let t = this.provider.attach((t) => {
513
+ let { property: n, value: r } = t.detail, i = new ie(e, {
514
+ property: n,
515
+ value: r
516
+ });
517
+ this.observed && (this.observed[n] = r, i.execute());
518
+ });
519
+ return this.observed = t, t;
520
+ }
521
+ }, he = class {
522
+ constructor(e, t, n = "service:message", r = !0) {
523
+ this._pending = [], this._context = t, this._update = e, this._eventType = n, this._running = r;
524
+ }
525
+ attach(e) {
526
+ e.addEventListener(this._eventType, (e) => {
527
+ e.stopPropagation();
528
+ let t = e.detail;
529
+ this.consume(t);
530
+ });
531
+ }
532
+ start() {
533
+ this._running || (this._running = !0, this._pending.forEach((e) => this.process(e)));
534
+ }
535
+ consume(e) {
536
+ if (e.length === 0) {
537
+ let t = e;
538
+ this._running ? this.process(t) : this._pending.push(t);
539
+ }
540
+ }
541
+ process(e) {
542
+ let t = this._update(e, this._context.toObject());
543
+ if (!Array.isArray(t)) return t;
544
+ let [n, ...r] = t;
545
+ return r.forEach((e) => e.then((e) => this.consume(e))), n;
546
+ }
547
+ };
548
+ function ge(e, t) {
549
+ return new _e(e, t);
550
+ }
551
+ var _e = class {
552
+ constructor(e, t) {
553
+ this.client = e, this.observer = new me(t);
554
+ }
555
+ start(e) {
556
+ return this.observer.observe(this.client, (t) => {
557
+ e(t.property, t.value);
558
+ });
559
+ }
560
+ }, ve = "context:auth", C = class e {
561
+ static {
562
+ this.TOKEN_KEY = "un-auth:token";
563
+ }
564
+ constructor(e) {
565
+ this.authenticated = !1, this.username = e || "anonymous";
566
+ }
567
+ static deauthenticate(t) {
568
+ return t.authenticated = !1, t.username = "anonymous", localStorage.removeItem(e.TOKEN_KEY), t;
569
+ }
570
+ }, ye = class e extends C {
571
+ constructor(e) {
572
+ super();
573
+ let t = a(e);
574
+ console.log("Token payload", t), this.token = e, this.authenticated = !0, this.username = t.username;
575
+ }
576
+ static authenticate(t) {
577
+ let n = new e(t);
578
+ return localStorage.setItem(C.TOKEN_KEY, t), n;
579
+ }
580
+ static authenticateFromLocalStorage() {
581
+ let t = localStorage.getItem(C.TOKEN_KEY);
582
+ return t ? e.authenticate(t) : new C();
583
+ }
584
+ }, w = class e extends he {
585
+ static {
586
+ this.EVENT_TYPE = "auth:message";
587
+ }
588
+ constructor(t, n) {
589
+ super((e, t) => this.update(e, t), t, e.EVENT_TYPE), this._redirectForLogin = n;
590
+ }
591
+ update(e, t) {
592
+ switch (e[0]) {
593
+ case "auth/signin":
594
+ let { token: n, redirect: r } = e[1];
595
+ return [D(n), T(r)];
596
+ case "auth/signout": return [O(t), T(this._redirectForLogin)];
597
+ case "auth/redirect":
598
+ E(this._redirectForLogin, { next: window.location.href });
599
+ break;
600
+ default:
601
+ let i = e[0];
602
+ throw Error(`Unhandled Auth message "${i}"`);
603
+ }
604
+ return t;
605
+ }
606
+ };
607
+ s.dispatcher(w.EVENT_TYPE);
608
+ function T(e, t = {}) {
609
+ return new Promise((n) => {
610
+ E(e, t), n(s.None);
611
+ });
612
+ }
613
+ function E(e, t = {}) {
614
+ if (e) {
615
+ let n = window.location.href, r = new URL(e, n);
616
+ Object.entries(t).forEach(([e, t]) => r.searchParams.set(e, t)), console.log("Redirecting to ", e), window.location.assign(r);
617
+ }
618
+ }
619
+ function D(e) {
620
+ let { authenticated: t, username: n } = ye.authenticate(e);
621
+ return {
622
+ authenticated: t,
623
+ username: n,
624
+ token: e
625
+ };
626
+ }
627
+ function O(e) {
628
+ let { authenticated: t, username: n } = C.deauthenticate(new C(e.username));
629
+ return {
630
+ username: n,
631
+ authenticated: t,
632
+ token: void 0
633
+ };
634
+ }
635
+ function k(e, t = ve) {
636
+ return ge(e, t);
637
+ }
638
+ //#endregion
639
+ //#region ../service/dist/service.js
640
+ var A = Object.defineProperty, j = /* @__PURE__ */ ((e, t) => {
641
+ let n = {};
642
+ for (var r in e) A(n, r, {
643
+ get: e[r],
644
+ enumerable: !0
645
+ });
646
+ return t || A(n, Symbol.toStringTag, { value: "Module" }), n;
647
+ })({
648
+ Dispatch: () => N,
649
+ None: () => M,
650
+ dispatch: () => be,
651
+ dispatcher: () => P
652
+ }), M = [], N = class extends CustomEvent {
653
+ constructor(e, t = "un:message") {
654
+ super(t, {
655
+ bubbles: !0,
656
+ composed: !0,
657
+ detail: e
658
+ });
659
+ }
660
+ };
661
+ function P(e = "un:message") {
662
+ return (t, ...n) => t.dispatchEvent(new N(n, e));
663
+ }
664
+ var be = P(), xe = class extends CustomEvent {
665
+ constructor(e, t) {
666
+ super(e, {
667
+ bubbles: !0,
668
+ cancelable: !0,
669
+ composed: !0,
670
+ detail: t
671
+ });
672
+ }
673
+ };
674
+ function F(e, ...t) {
675
+ let n = { execute() {
676
+ e(...t.map((e) => e instanceof L ? e.open(n) : e)), t.forEach((e) => e instanceof L && e.close());
677
+ } };
678
+ n.execute();
679
+ }
680
+ var I = class e {
681
+ constructor() {
682
+ this.signals = /* @__PURE__ */ new WeakMap(), this.scheduled = /* @__PURE__ */ new WeakSet();
683
+ }
684
+ static {
685
+ this.scheduler = new e();
686
+ }
687
+ subscribe(e, t, n) {
688
+ let r = this.signals.get(e);
689
+ r || (r = /* @__PURE__ */ new Map(), this.signals.set(e, r));
690
+ let i = r.get(t);
691
+ i || (i = /* @__PURE__ */ new Set(), r.set(t, i)), i.add(n);
692
+ }
693
+ scheduleEffects(e, t) {
694
+ let n = this.signals.get(e);
695
+ if (!n) return;
696
+ let r = n.get(t);
697
+ if (r) for (let e of r) this.scheduled.has(e) || (this.scheduled.add(e), setTimeout(() => {
698
+ this.scheduled.delete(e), e.execute();
699
+ }));
700
+ }
701
+ }, Se = class {
702
+ constructor() {
703
+ this.running = [], this.eventType = "un-effect:change";
704
+ }
705
+ isRunning() {
706
+ return this.running.length > 0;
707
+ }
708
+ push(e) {
709
+ this.running.push(e);
710
+ }
711
+ pop() {
712
+ this.running.pop();
713
+ }
714
+ current() {
715
+ let e = this.running.length;
716
+ return e ? this.running[e - 1] : void 0;
717
+ }
718
+ subscribe(e, t) {
719
+ let n = this.current();
720
+ n && I.scheduler.subscribe(t, e, n);
721
+ }
722
+ runEffects(e, t) {
723
+ if (I.scheduler.scheduleEffects(t, e), this.host) {
724
+ let n = new xe(this.eventType, {
725
+ property: e,
726
+ value: t[e]
727
+ });
728
+ this.host.dispatchEvent(n);
729
+ }
730
+ }
731
+ setHost(e, t) {
732
+ this.host = e, t && (this.eventType = t);
733
+ }
734
+ }, L = class {
735
+ static {
736
+ this.CHANGE_EVENT_TYPE = "un-context:change";
737
+ }
738
+ constructor(e, t) {
739
+ t ? (this.manager = t.manager, this.object = t.object, this.proxy = t.proxy, this.update(e)) : (this.manager = new Se(), this.object = e, this.proxy = Ce(this.object, this.manager));
740
+ }
741
+ get(e) {
742
+ return this.proxy[e];
743
+ }
744
+ set(e, t) {
745
+ this.proxy[e] = t;
746
+ }
747
+ toObject() {
748
+ return this.object;
749
+ }
750
+ update(e) {
751
+ Object.assign(this.proxy, e);
752
+ }
753
+ apply(e) {
754
+ this.update(e(this.proxy));
755
+ }
756
+ createEffect(e) {
757
+ F(e, this);
758
+ }
759
+ setHost(e, t) {
760
+ this.manager.setHost(e, t);
761
+ }
762
+ open(e) {
763
+ return this.manager.push(e), this.proxy;
764
+ }
765
+ close() {
766
+ this.manager.pop();
767
+ }
768
+ };
769
+ function Ce(e, t) {
770
+ return new Proxy(e, {
771
+ get: (e, n, r) => {
772
+ let i = Reflect.get(e, n, r);
773
+ return t.isRunning() && R(i) && t.subscribe(n, e), i;
774
+ },
775
+ set: (e, n, r, i) => {
776
+ let a = Reflect.set(e, n, r, i);
777
+ return a && R(r) && t.runEffects(n, e), a;
778
+ }
779
+ });
780
+ }
781
+ function R(e) {
782
+ switch (typeof e) {
783
+ case "object":
784
+ case "number":
785
+ case "string":
786
+ case "symbol":
787
+ case "boolean":
788
+ case "undefined": return !0;
789
+ default: return !1;
790
+ }
791
+ }
792
+ var we = class {
793
+ constructor(e, ...t) {
794
+ this.effectFn = () => e(...t);
795
+ }
796
+ execute() {
797
+ this.effectFn();
798
+ }
799
+ };
800
+ function Te(e, t) {
801
+ return Object.assign(e, { render: t }), e;
802
+ }
803
+ function Ee(e, t, ...n) {
804
+ let r = e.cloneNode(!0);
805
+ return Array.from(t.entries()).forEach(([e, t]) => {
806
+ let i = r.querySelector(`[data-${e}]`);
807
+ i && t.forEach((e) => e(i, r, ...n));
808
+ }), r;
809
+ }
810
+ var De = class e {
811
+ static {
812
+ this.parser = new DOMParser();
813
+ }
814
+ constructor(e) {
815
+ this.docType = "text/html", this.plugins = [], e && (this.docType = e);
816
+ }
817
+ use(e) {
818
+ this.plugins = this.plugins.concat(e);
819
+ }
820
+ parse(t, n) {
821
+ let r = {}, i = t.map((e, i) => {
822
+ if (i >= n.length) return [e];
823
+ let a = n[i], o = this.classifyPlace(i, t), s = this.tryReplacements(o, a);
824
+ if (s) {
825
+ let t = r[o.nodeLabel];
826
+ switch (t ? t.push(s) : r[o.nodeLabel] = [s], o.kind) {
827
+ case "attr value": return [e, `"" data-${o.nodeLabel}`];
828
+ case "tag content": return [e, `data-${o.nodeLabel}`];
829
+ case "element content": return [e, `<ins data-${o.nodeLabel}></ins>`];
830
+ }
831
+ } else throw console.error("No match for template parameter", o, a), `Failed to render template parameter ${i} around ${e}`;
832
+ return [e];
833
+ }).flat().join(""), a = e.parser.parseFromString(i, this.docType), o = a.head.childElementCount ? a.head.children : a.body.children, s = new DocumentFragment();
834
+ s.replaceChildren(...o);
835
+ let c = /* @__PURE__ */ new Map();
836
+ for (let e in r) {
837
+ let t = s.querySelector(`[data-${e}]`);
838
+ t && r[e].forEach((n) => {
839
+ let r = n.apply(t, s);
840
+ if (r) {
841
+ let t = c.get(e);
842
+ t ? t.push(r) : c.set(e, [r]);
843
+ }
844
+ });
845
+ }
846
+ return Te(s, (...e) => Ee(s, c, ...e));
847
+ }
848
+ static {
849
+ this.OPEN_RE = /<([a-zA-z][$a-zA-Z0-9.-]*)\s+[^>]*$/;
850
+ }
851
+ static {
852
+ this.IN_TAG_RE = /^(\s+|[^<>]*|"[^"]*")*$/;
853
+ }
854
+ static {
855
+ this.ATTR_RE = /([$.]?[a-zA-Z][$a-zA-Z0-9.-]*)=\s*$/;
856
+ }
857
+ static {
858
+ this.CLOSE_RE = /[/]?>[^<]*$/;
859
+ }
860
+ classifyPlace(t, n) {
861
+ let r = null;
862
+ for (let i = t; i >= 0 && !(n[i].match(e.CLOSE_RE) || (r = n[i].match(e.OPEN_RE), r) || !n[i].match(e.IN_TAG_RE)); i--);
863
+ if (r) {
864
+ let i = n[t].match(e.ATTR_RE);
865
+ return i ? {
866
+ kind: "attr value",
867
+ nodeLabel: `node${t}`,
868
+ tagName: r[1],
869
+ attrName: i[1]
870
+ } : {
871
+ kind: "tag content",
872
+ nodeLabel: `node${t}`,
873
+ tagName: r[1]
874
+ };
875
+ }
876
+ return {
877
+ kind: "element content",
878
+ nodeLabel: `node${t}`
879
+ };
880
+ }
881
+ tryReplacements(e, t) {
882
+ let n = this.plugins;
883
+ for (let r = 0; r < n.length; r++) {
884
+ let i = n[r];
885
+ if (e.kind === i.place && Oe(t, i)) return i.mutator(e, t);
886
+ }
887
+ }
888
+ };
889
+ function Oe(e, t) {
890
+ return typeof t.types == "function" ? t.types(e, t) : t.types.includes(typeof e);
891
+ }
892
+ var z = class {
893
+ constructor(e) {
894
+ this.place = e;
895
+ }
896
+ apply(e, t) {
897
+ throw "abstract method 'apply' called";
898
+ }
899
+ }, B = class extends z {
900
+ constructor(e, t) {
901
+ super(e), this.content = t;
902
+ }
903
+ apply(e, t) {
904
+ (e.parentNode || t).replaceChild(this.content, e);
905
+ }
906
+ }, ke = class extends z {
907
+ constructor(e, t) {
908
+ super(e), this.text = t, this.name = e.attrName;
909
+ }
910
+ apply(e) {
911
+ e.setAttribute(this.name, this.text);
912
+ }
913
+ }, V = class extends z {
914
+ constructor(e, t) {
915
+ super(e), this.fn = t;
916
+ }
917
+ apply(e, t) {
918
+ let n = this.place.nodeLabel;
919
+ return (e, t, ...r) => {
920
+ let i = new Comment(` <<< ${n} `), a = new Comment(` >>> ${n} `), o = new DocumentFragment();
921
+ o.replaceChildren(i, a), (e.parentNode || t).replaceChild(o, e), F((...e) => {
922
+ Ae(this.fn(...e), i, a);
923
+ }, ...r);
924
+ };
925
+ }
926
+ };
927
+ function Ae(e, t, n) {
928
+ let r = t.parentNode;
929
+ if (!r) throw Error("No parent for placeholder");
930
+ let i = (e) => {
931
+ if (Array.isArray(e)) {
932
+ let t = new DocumentFragment(), n = e.map(i);
933
+ return t.replaceChildren(...n), t;
934
+ } else if (e instanceof Node) return e;
935
+ else return new Text(e?.toString() || "");
936
+ }, a = i(e);
937
+ console.log("📸 Rendered for view:", e, a);
938
+ let o = t.nextSibling;
939
+ for (; o && o !== n;) {
940
+ let e = o;
941
+ o = o.nextSibling, r.removeChild(e);
942
+ }
943
+ a && r.insertBefore(a, n);
944
+ }
945
+ var je = class extends z {
946
+ constructor(e, t) {
947
+ super(e), this.fn = t, this.name = e.attrName;
948
+ }
949
+ apply(e, t) {
950
+ return (e, t, ...n) => F((...t) => {
951
+ Me(this.fn(...t), e, this.name);
952
+ }, ...n);
953
+ }
954
+ };
955
+ function Me(e, t, n) {
956
+ let r = n.match(/^([.$])(.+)$/);
957
+ if (r) {
958
+ let [n, i, a] = r;
959
+ switch (i) {
960
+ case ".":
961
+ t[a] = e;
962
+ break;
963
+ case "$":
964
+ "viewModel" in t && t.viewModel instanceof L && t.viewModel.set(a, e);
965
+ break;
966
+ }
967
+ } else switch (typeof e) {
968
+ case "string":
969
+ t.setAttribute(n, e);
970
+ break;
971
+ case "undefined":
972
+ case "object":
973
+ case "boolean":
974
+ e ? t.setAttribute(n, n) : t.removeAttribute(n);
975
+ break;
976
+ default: t.setAttribute(n, e?.toString());
977
+ }
978
+ }
979
+ var Ne = class extends z {
980
+ constructor(e, t) {
981
+ super(e), this.fn = t;
982
+ }
983
+ apply(e, t) {
984
+ return (e, t, ...n) => F((...t) => {
985
+ let n = this.fn(...t);
986
+ typeof n == "function" && n(e);
987
+ }, ...n);
988
+ }
989
+ };
990
+ new De().use([
991
+ {
992
+ place: "element content",
993
+ types: [
994
+ "string",
995
+ "number",
996
+ "bigint",
997
+ "symbol",
998
+ "boolean"
999
+ ],
1000
+ mutator: (e, t) => new B(e, new Text(t?.toString() || ""))
1001
+ },
1002
+ {
1003
+ place: "attr value",
1004
+ types: [
1005
+ "string",
1006
+ "number",
1007
+ "bigint",
1008
+ "symbol"
1009
+ ],
1010
+ mutator: (e, t) => new ke(e, t?.toString() || "")
1011
+ },
1012
+ {
1013
+ place: "element content",
1014
+ types: (e) => e instanceof Node,
1015
+ mutator: (e, t) => new B(e, t)
1016
+ },
1017
+ {
1018
+ place: "element content",
1019
+ types: ["function"],
1020
+ mutator: (e, t) => new V(e, t)
1021
+ },
1022
+ {
1023
+ place: "attr value",
1024
+ types: ["function"],
1025
+ mutator: (e, t) => new je(e, t)
1026
+ },
1027
+ {
1028
+ place: "tag content",
1029
+ types: ["function"],
1030
+ mutator: (e, t) => new Ne(e, t)
1031
+ }
1032
+ ]);
1033
+ var H = class e extends HTMLElement {
1034
+ static {
1035
+ this.DISCOVERY_EVENT = "un-provider:discover";
1036
+ }
1037
+ static {
1038
+ this.REGISTRY_EVENT = "un-provider:register";
1039
+ }
1040
+ static {
1041
+ this.CHANGE_EVENT = "un-provider:change";
1042
+ }
1043
+ static {
1044
+ document.addEventListener(e.DISCOVERY_EVENT, (e) => {
1045
+ let [t, n] = e.detail, r = Ie(t);
1046
+ r && n(r);
1047
+ }), document.addEventListener(e.REGISTRY_EVENT, (e) => {
1048
+ let [t, n] = e.detail;
1049
+ Fe(t, n);
1050
+ });
1051
+ }
1052
+ constructor(t, n) {
1053
+ super(), this.contextLabel = n, this.context = new L(t), this.context.setHost(this, e.CHANGE_EVENT), this.addEventListener(e.DISCOVERY_EVENT, (e) => {
1054
+ let [t, n] = e.detail;
1055
+ t === this.contextLabel && (e.stopPropagation(), n(this));
1056
+ });
1057
+ let r = new CustomEvent(e.REGISTRY_EVENT, {
1058
+ bubbles: !0,
1059
+ composed: !0,
1060
+ detail: [this.contextLabel, this]
1061
+ });
1062
+ this.dispatchEvent(r);
1063
+ }
1064
+ attach(t) {
1065
+ return this.addEventListener(e.CHANGE_EVENT, t), this.context.toObject();
1066
+ }
1067
+ detach(t) {
1068
+ this.removeEventListener(e.CHANGE_EVENT, t);
1069
+ }
1070
+ };
1071
+ function Pe(e, t) {
1072
+ return new Promise((n, r) => {
1073
+ let i = new CustomEvent(H.DISCOVERY_EVENT, {
1074
+ bubbles: !0,
1075
+ composed: !0,
1076
+ detail: [t, (e) => e ? n(e) : r()]
1077
+ });
1078
+ e.isConnected ? e.dispatchEvent(i) : document.dispatchEvent(i);
1079
+ });
1080
+ }
1081
+ var U = {};
1082
+ function Fe(e, t) {
1083
+ U[e] = t;
1084
+ }
1085
+ function Ie(e) {
1086
+ return U[e];
1087
+ }
1088
+ var Le = class {
1089
+ constructor(e) {
1090
+ this.contextLabel = e;
1091
+ }
1092
+ observe(e, t) {
1093
+ return new Promise((n, r) => {
1094
+ this.provider ? n(this.attachObserver(t)) : Pe(e, this.contextLabel).then((e) => {
1095
+ this.provider = e, n(this.attachObserver(t));
1096
+ }).catch((e) => r(e));
1097
+ });
1098
+ }
1099
+ attachObserver(e) {
1100
+ let t = this.provider.attach((t) => {
1101
+ let { property: n, value: r } = t.detail, i = new we(e, {
1102
+ property: n,
1103
+ value: r
1104
+ });
1105
+ this.observed && (this.observed[n] = r, i.execute());
1106
+ });
1107
+ return this.observed = t, t;
1108
+ }
1109
+ }, Re = class {
1110
+ constructor(e, t, n = "service:message", r = !0) {
1111
+ this._pending = [], this._context = t, this._update = e, this._eventType = n, this._running = r;
1112
+ }
1113
+ attach(e) {
1114
+ e.addEventListener(this._eventType, (e) => {
1115
+ e.stopPropagation();
1116
+ let t = e.detail;
1117
+ this.consume(t);
1118
+ });
1119
+ }
1120
+ start() {
1121
+ this._running || (this._running = !0, this._pending.forEach((e) => this.process(e)));
1122
+ }
1123
+ consume(e) {
1124
+ if (e.length === 0) {
1125
+ let t = e;
1126
+ this._running ? this.process(t) : this._pending.push(t);
1127
+ }
1128
+ }
1129
+ process(e) {
1130
+ let t = this._update(e, this._context.toObject());
1131
+ if (!Array.isArray(t)) return t;
1132
+ let [n, ...r] = t;
1133
+ return r.forEach((e) => e.then((e) => this.consume(e))), n;
1134
+ }
1135
+ }, ze = class {
1136
+ constructor(e, t) {
1137
+ this.client = e, this.observer = new Le(t);
1138
+ }
1139
+ start(e) {
1140
+ return this.observer.observe(this.client, (t) => {
1141
+ e(t.property, t.value);
1142
+ });
1143
+ }
1144
+ }, W = class {
1145
+ constructor(e, t) {
1146
+ this.origin = e;
1147
+ let n = Be(t).map(([e, t]) => [t, e]);
1148
+ this.inverse = Object.fromEntries(n);
1149
+ }
1150
+ mapObservation(e) {
1151
+ let t = Object.entries(e);
1152
+ return Object.fromEntries(t.map(([e, t]) => [this.inverse[e], t]).filter((e) => e.length > 0));
1153
+ }
1154
+ start(e) {
1155
+ return this.origin.start((t, n) => {
1156
+ let r = this.inverse[t];
1157
+ e(r, n);
1158
+ }).then((e) => this.mapObservation(e));
1159
+ }
1160
+ };
1161
+ function Be(e) {
1162
+ return Object.entries(e).map(([e, t]) => [e, t]);
1163
+ }
1164
+ var Ve = class extends CustomEvent {
1165
+ constructor(e, t) {
1166
+ super(e, {
1167
+ bubbles: !0,
1168
+ cancelable: !0,
1169
+ composed: !0,
1170
+ detail: t
1171
+ });
1172
+ }
1173
+ };
1174
+ function G(e, ...t) {
1175
+ let n = { execute() {
1176
+ e(...t.map((e) => e instanceof q ? e.open(n) : e)), t.forEach((e) => e instanceof q && e.close());
1177
+ } };
1178
+ n.execute();
1179
+ }
1180
+ var K = class e {
1181
+ constructor() {
1182
+ this.signals = /* @__PURE__ */ new WeakMap(), this.scheduled = /* @__PURE__ */ new WeakSet();
1183
+ }
1184
+ static {
1185
+ this.scheduler = new e();
1186
+ }
1187
+ subscribe(e, t, n) {
1188
+ let r = this.signals.get(e);
1189
+ r || (r = /* @__PURE__ */ new Map(), this.signals.set(e, r));
1190
+ let i = r.get(t);
1191
+ i || (i = /* @__PURE__ */ new Set(), r.set(t, i)), i.add(n);
1192
+ }
1193
+ scheduleEffects(e, t) {
1194
+ let n = this.signals.get(e);
1195
+ if (!n) return;
1196
+ let r = n.get(t);
1197
+ if (r) for (let e of r) this.scheduled.has(e) || (this.scheduled.add(e), setTimeout(() => {
1198
+ this.scheduled.delete(e), e.execute();
1199
+ }));
1200
+ }
1201
+ }, He = class {
1202
+ constructor() {
1203
+ this.running = [], this.eventType = "un-effect:change";
1204
+ }
1205
+ isRunning() {
1206
+ return this.running.length > 0;
1207
+ }
1208
+ push(e) {
1209
+ this.running.push(e);
1210
+ }
1211
+ pop() {
1212
+ this.running.pop();
1213
+ }
1214
+ current() {
1215
+ let e = this.running.length;
1216
+ return e ? this.running[e - 1] : void 0;
1217
+ }
1218
+ subscribe(e, t) {
1219
+ let n = this.current();
1220
+ n && K.scheduler.subscribe(t, e, n);
1221
+ }
1222
+ runEffects(e, t) {
1223
+ if (K.scheduler.scheduleEffects(t, e), this.host) {
1224
+ let n = new Ve(this.eventType, {
1225
+ property: e,
1226
+ value: t[e]
1227
+ });
1228
+ this.host.dispatchEvent(n);
1229
+ }
1230
+ }
1231
+ setHost(e, t) {
1232
+ this.host = e, t && (this.eventType = t);
1233
+ }
1234
+ }, q = class {
1235
+ static {
1236
+ this.CHANGE_EVENT_TYPE = "un-context:change";
1237
+ }
1238
+ constructor(e, t) {
1239
+ t ? (this.manager = t.manager, this.object = t.object, this.proxy = t.proxy, this.update(e)) : (this.manager = new He(), this.object = e, this.proxy = Ue(this.object, this.manager));
1240
+ }
1241
+ get(e) {
1242
+ return this.proxy[e];
1243
+ }
1244
+ set(e, t) {
1245
+ this.proxy[e] = t;
1246
+ }
1247
+ toObject() {
1248
+ return this.object;
1249
+ }
1250
+ update(e) {
1251
+ Object.assign(this.proxy, e);
1252
+ }
1253
+ apply(e) {
1254
+ this.update(e(this.proxy));
1255
+ }
1256
+ createEffect(e) {
1257
+ G(e, this);
1258
+ }
1259
+ setHost(e, t) {
1260
+ this.manager.setHost(e, t);
1261
+ }
1262
+ open(e) {
1263
+ return this.manager.push(e), this.proxy;
1264
+ }
1265
+ close() {
1266
+ this.manager.pop();
1267
+ }
1268
+ };
1269
+ function Ue(e, t) {
1270
+ return new Proxy(e, {
1271
+ get: (e, n, r) => {
1272
+ let i = Reflect.get(e, n, r);
1273
+ return t.isRunning() && J(i) && t.subscribe(n, e), i;
1274
+ },
1275
+ set: (e, n, r, i) => {
1276
+ let a = Reflect.set(e, n, r, i);
1277
+ return a && J(r) && t.runEffects(n, e), a;
1278
+ }
1279
+ });
1280
+ }
1281
+ function J(e) {
1282
+ switch (typeof e) {
1283
+ case "object":
1284
+ case "number":
1285
+ case "string":
1286
+ case "symbol":
1287
+ case "boolean":
1288
+ case "undefined": return !0;
1289
+ default: return !1;
1290
+ }
1291
+ }
1292
+ function We(e, t) {
1293
+ return Object.assign(e, { render: t }), e;
1294
+ }
1295
+ function Ge(e, t, ...n) {
1296
+ let r = e.cloneNode(!0);
1297
+ return Array.from(t.entries()).forEach(([e, t]) => {
1298
+ let i = r.querySelector(`[data-${e}]`);
1299
+ i && t.forEach((e) => e(i, r, ...n));
1300
+ }), r;
1301
+ }
1302
+ var Ke = class e {
1303
+ static {
1304
+ this.parser = new DOMParser();
1305
+ }
1306
+ constructor(e) {
1307
+ this.docType = "text/html", this.plugins = [], e && (this.docType = e);
1308
+ }
1309
+ use(e) {
1310
+ this.plugins = this.plugins.concat(e);
1311
+ }
1312
+ parse(t, n) {
1313
+ let r = {}, i = t.map((e, i) => {
1314
+ if (i >= n.length) return [e];
1315
+ let a = n[i], o = this.classifyPlace(i, t), s = this.tryReplacements(o, a);
1316
+ if (s) {
1317
+ let t = r[o.nodeLabel];
1318
+ switch (t ? t.push(s) : r[o.nodeLabel] = [s], o.kind) {
1319
+ case "attr value": return [e, `"" data-${o.nodeLabel}`];
1320
+ case "tag content": return [e, `data-${o.nodeLabel}`];
1321
+ case "element content": return [e, `<ins data-${o.nodeLabel}></ins>`];
1322
+ }
1323
+ } else throw console.error("No match for template parameter", o, a), `Failed to render template parameter ${i} around ${e}`;
1324
+ return [e];
1325
+ }).flat().join(""), a = e.parser.parseFromString(i, this.docType), o = a.head.childElementCount ? a.head.children : a.body.children, s = new DocumentFragment();
1326
+ s.replaceChildren(...o);
1327
+ let c = /* @__PURE__ */ new Map();
1328
+ for (let e in r) {
1329
+ let t = s.querySelector(`[data-${e}]`);
1330
+ t && r[e].forEach((n) => {
1331
+ let r = n.apply(t, s);
1332
+ if (r) {
1333
+ let t = c.get(e);
1334
+ t ? t.push(r) : c.set(e, [r]);
1335
+ }
1336
+ });
1337
+ }
1338
+ return We(s, (...e) => Ge(s, c, ...e));
1339
+ }
1340
+ static {
1341
+ this.OPEN_RE = /<([a-zA-z][$a-zA-Z0-9.-]*)\s+[^>]*$/;
1342
+ }
1343
+ static {
1344
+ this.IN_TAG_RE = /^(\s+|[^<>]*|"[^"]*")*$/;
1345
+ }
1346
+ static {
1347
+ this.ATTR_RE = /([$.]?[a-zA-Z][$a-zA-Z0-9.-]*)=\s*$/;
1348
+ }
1349
+ static {
1350
+ this.CLOSE_RE = /[/]?>[^<]*$/;
1351
+ }
1352
+ classifyPlace(t, n) {
1353
+ let r = null;
1354
+ for (let i = t; i >= 0 && !(n[i].match(e.CLOSE_RE) || (r = n[i].match(e.OPEN_RE), r) || !n[i].match(e.IN_TAG_RE)); i--);
1355
+ if (r) {
1356
+ let i = n[t].match(e.ATTR_RE);
1357
+ return i ? {
1358
+ kind: "attr value",
1359
+ nodeLabel: `node${t}`,
1360
+ tagName: r[1],
1361
+ attrName: i[1]
1362
+ } : {
1363
+ kind: "tag content",
1364
+ nodeLabel: `node${t}`,
1365
+ tagName: r[1]
1366
+ };
1367
+ }
1368
+ return {
1369
+ kind: "element content",
1370
+ nodeLabel: `node${t}`
1371
+ };
1372
+ }
1373
+ tryReplacements(e, t) {
1374
+ let n = this.plugins;
1375
+ for (let r = 0; r < n.length; r++) {
1376
+ let i = n[r];
1377
+ if (e.kind === i.place && qe(t, i)) return i.mutator(e, t);
1378
+ }
1379
+ }
1380
+ };
1381
+ function qe(e, t) {
1382
+ return typeof t.types == "function" ? t.types(e, t) : t.types.includes(typeof e);
1383
+ }
1384
+ var Y = class {
1385
+ constructor(e) {
1386
+ this.place = e;
1387
+ }
1388
+ apply(e, t) {
1389
+ throw "abstract method 'apply' called";
1390
+ }
1391
+ }, X = class extends Y {
1392
+ constructor(e, t) {
1393
+ super(e), this.content = t;
1394
+ }
1395
+ apply(e, t) {
1396
+ (e.parentNode || t).replaceChild(this.content, e);
1397
+ }
1398
+ }, Je = class extends Y {
1399
+ constructor(e, t) {
1400
+ super(e), this.text = t, this.name = e.attrName;
1401
+ }
1402
+ apply(e) {
1403
+ e.setAttribute(this.name, this.text);
1404
+ }
1405
+ }, Ye = class extends Y {
1406
+ constructor(e, t) {
1407
+ super(e), this.fn = t;
1408
+ }
1409
+ apply(e, t) {
1410
+ let n = this.place.nodeLabel;
1411
+ return (e, t, ...r) => {
1412
+ let i = new Comment(` <<< ${n} `), a = new Comment(` >>> ${n} `), o = new DocumentFragment();
1413
+ o.replaceChildren(i, a), (e.parentNode || t).replaceChild(o, e), G((...e) => {
1414
+ Xe(this.fn(...e), i, a);
1415
+ }, ...r);
1416
+ };
1417
+ }
1418
+ };
1419
+ function Xe(e, t, n) {
1420
+ let r = t.parentNode;
1421
+ if (!r) throw Error("No parent for placeholder");
1422
+ let i = (e) => {
1423
+ if (Array.isArray(e)) {
1424
+ let t = new DocumentFragment(), n = e.map(i);
1425
+ return t.replaceChildren(...n), t;
1426
+ } else if (e instanceof Node) return e;
1427
+ else return new Text(e?.toString() || "");
1428
+ }, a = i(e);
1429
+ console.log("📸 Rendered for view:", e, a);
1430
+ let o = t.nextSibling;
1431
+ for (; o && o !== n;) {
1432
+ let e = o;
1433
+ o = o.nextSibling, r.removeChild(e);
1434
+ }
1435
+ a && r.insertBefore(a, n);
1436
+ }
1437
+ var Ze = class extends Y {
1438
+ constructor(e, t) {
1439
+ super(e), this.fn = t, this.name = e.attrName;
1440
+ }
1441
+ apply(e, t) {
1442
+ return (e, t, ...n) => G((...t) => {
1443
+ Qe(this.fn(...t), e, this.name);
1444
+ }, ...n);
1445
+ }
1446
+ };
1447
+ function Qe(e, t, n) {
1448
+ let r = n.match(/^([.$])(.+)$/);
1449
+ if (r) {
1450
+ let [n, i, a] = r;
1451
+ switch (i) {
1452
+ case ".":
1453
+ t[a] = e;
1454
+ break;
1455
+ case "$":
1456
+ "viewModel" in t && t.viewModel instanceof q && t.viewModel.set(a, e);
1457
+ break;
1458
+ }
1459
+ } else switch (typeof e) {
1460
+ case "string":
1461
+ t.setAttribute(n, e);
1462
+ break;
1463
+ case "undefined":
1464
+ case "object":
1465
+ case "boolean":
1466
+ e ? t.setAttribute(n, n) : t.removeAttribute(n);
1467
+ break;
1468
+ default: t.setAttribute(n, e?.toString());
1469
+ }
1470
+ }
1471
+ var $e = class extends Y {
1472
+ constructor(e, t) {
1473
+ super(e), this.fn = t;
1474
+ }
1475
+ apply(e, t) {
1476
+ return (e, t, ...n) => G((...t) => {
1477
+ let n = this.fn(...t);
1478
+ typeof n == "function" && n(e);
1479
+ }, ...n);
1480
+ }
1481
+ };
1482
+ new Ke().use([
1483
+ {
1484
+ place: "element content",
1485
+ types: [
1486
+ "string",
1487
+ "number",
1488
+ "bigint",
1489
+ "symbol",
1490
+ "boolean"
1491
+ ],
1492
+ mutator: (e, t) => new X(e, new Text(t?.toString() || ""))
1493
+ },
1494
+ {
1495
+ place: "attr value",
1496
+ types: [
1497
+ "string",
1498
+ "number",
1499
+ "bigint",
1500
+ "symbol"
1501
+ ],
1502
+ mutator: (e, t) => new Je(e, t?.toString() || "")
1503
+ },
1504
+ {
1505
+ place: "element content",
1506
+ types: (e) => e instanceof Node,
1507
+ mutator: (e, t) => new X(e, t)
1508
+ },
1509
+ {
1510
+ place: "element content",
1511
+ types: ["function"],
1512
+ mutator: (e, t) => new Ye(e, t)
1513
+ },
1514
+ {
1515
+ place: "attr value",
1516
+ types: ["function"],
1517
+ mutator: (e, t) => new Ze(e, t)
1518
+ },
1519
+ {
1520
+ place: "tag content",
1521
+ types: ["function"],
1522
+ mutator: (e, t) => new $e(e, t)
1523
+ }
1524
+ ]);
1525
+ var Z = class extends q {
1526
+ constructor(e, t) {
1527
+ super(e, t);
1528
+ }
1529
+ get $() {
1530
+ return this.toObject();
1531
+ }
1532
+ with(e, ...t) {
1533
+ let n = Object.fromEntries(t.map((e) => [e, e]));
1534
+ return this.merge(new W(e, n));
1535
+ }
1536
+ withCalculated(e, t) {
1537
+ return this.merge(new W(e, t));
1538
+ }
1539
+ withRenamed(e, t) {
1540
+ return this.merge(new W(e, t));
1541
+ }
1542
+ merge(e) {
1543
+ if (e) {
1544
+ let t = e.start((e, n) => {
1545
+ console.log("🪄 Merging effect", e, n, t), this.set(e, n);
1546
+ }).then((e) => {
1547
+ console.log("👀 ViewModel source observed:", e, t), Object.keys(e).forEach((t) => this.set(t, e[t]));
1548
+ });
1549
+ }
1550
+ return this;
1551
+ }
1552
+ render(e) {
1553
+ return e.render(this);
1554
+ }
1555
+ };
1556
+ function et(e) {
1557
+ return e === void 0 ? new Z({}) : new Z(e);
1558
+ }
1559
+ //#endregion
1560
+ //#region src/store.ts
1561
+ var tt = /* @__PURE__ */ t({
1562
+ CONTEXT_DEFAULT: () => Q,
1563
+ Provider: () => nt,
1564
+ Service: () => $,
1565
+ dispatch: () => rt
1566
+ }), Q = "context:store", $ = class e extends Re {
1567
+ static {
1568
+ this.EVENT_TYPE = "store:message";
1569
+ }
1570
+ constructor(t, n) {
1571
+ super((e, t) => n(t, e), t, e.EVENT_TYPE);
1572
+ }
1573
+ }, nt = class extends H {
1574
+ constructor(e, t) {
1575
+ super(t, Q), this.viewModel = et({ authenticated: !1 }).with(k(this), "authenticated", "username", "token"), this._updateFn = e;
1576
+ }
1577
+ connectedCallback() {
1578
+ new $(this.context, (e, t) => this._updateFn(e, t, this.viewModel.toObject())).attach(this);
1579
+ }
1580
+ };
1581
+ function rt(e, t) {
1582
+ console.log("📨 Dispatching message:", t, e), e.dispatchEvent(new j.Dispatch(t, $.EVENT_TYPE));
1583
+ }
1584
+ //#endregion
1585
+ //#region src/fromStore.ts
1586
+ function it(e, t = Q) {
1587
+ return new ze(e, t);
1588
+ }
1589
+ //#endregion
1590
+ export { tt as Store, it as fromStore };