@jasonshimmy/custom-elements-runtime 2.2.9 → 2.3.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.
@@ -0,0 +1,692 @@
1
+ import { d as x, a as _ } from "./logger-BuUYv7C_.js";
2
+ class v {
3
+ pendingUpdates = /* @__PURE__ */ new Map();
4
+ isFlushScheduled = !1;
5
+ /**
6
+ * Schedule an update to be executed in the next microtask
7
+ * Uses component identity to deduplicate multiple render requests for the same component
8
+ */
9
+ schedule(t, r) {
10
+ const n = r || t;
11
+ if (this.pendingUpdates.set(n, t), !this.isFlushScheduled) {
12
+ this.isFlushScheduled = !0;
13
+ const s = globalThis.process;
14
+ typeof s < "u" && s.env?.NODE_ENV === "test" || typeof window < "u" && (window.__vitest__ || window.Cypress) ? this.flush() : queueMicrotask(() => this.flush());
15
+ }
16
+ }
17
+ /**
18
+ * Execute all pending updates
19
+ */
20
+ flush() {
21
+ const t = this.pendingUpdates;
22
+ this.pendingUpdates = /* @__PURE__ */ new Map(), this.isFlushScheduled = !1;
23
+ for (const r of t.values())
24
+ try {
25
+ r();
26
+ } catch (n) {
27
+ x("Error in batched update:", n);
28
+ }
29
+ }
30
+ /**
31
+ * Get the number of pending updates
32
+ */
33
+ get pendingCount() {
34
+ return this.pendingUpdates.size;
35
+ }
36
+ }
37
+ const H = new v();
38
+ function L(e, t) {
39
+ H.schedule(e, t);
40
+ }
41
+ const C = /* @__PURE__ */ new WeakSet();
42
+ class D {
43
+ static cache = /* @__PURE__ */ new WeakMap();
44
+ static arrayHandlerCache = /* @__PURE__ */ new WeakMap();
45
+ static objectHandlerCache = /* @__PURE__ */ new WeakMap();
46
+ /**
47
+ * Get or create a reactive proxy for an object
48
+ */
49
+ static getOrCreateProxy(t, r, n = !1) {
50
+ const s = this.cache.get(t);
51
+ if (s)
52
+ return s;
53
+ const a = n ? this.getOrCreateArrayHandler(r) : this.getOrCreateObjectHandler(r), i = new Proxy(t, a);
54
+ try {
55
+ E.markAsProxy(i);
56
+ } catch {
57
+ }
58
+ return this.cache.set(t, i), i;
59
+ }
60
+ /**
61
+ * Get or create a cached array handler
62
+ */
63
+ static getOrCreateArrayHandler(t) {
64
+ if (!this.arrayHandlerCache.has(t)) {
65
+ const r = {
66
+ get: (n, s, a) => {
67
+ const i = Reflect.get(n, s, a);
68
+ return typeof i == "function" && typeof s == "string" && [
69
+ "push",
70
+ "pop",
71
+ "shift",
72
+ "unshift",
73
+ "splice",
74
+ "sort",
75
+ "reverse",
76
+ "fill",
77
+ "copyWithin"
78
+ ].includes(s) ? function(...u) {
79
+ const d = i.apply(n, u);
80
+ return t.triggerUpdate(), d;
81
+ } : i;
82
+ },
83
+ set: (n, s, a) => (n[s] = t.makeReactiveValue(a), t.triggerUpdate(), !0),
84
+ deleteProperty: (n, s) => (delete n[s], t.triggerUpdate(), !0)
85
+ };
86
+ this.arrayHandlerCache.set(t, r);
87
+ }
88
+ return this.arrayHandlerCache.get(t);
89
+ }
90
+ /**
91
+ * Get or create a cached object handler
92
+ */
93
+ static getOrCreateObjectHandler(t) {
94
+ if (!this.objectHandlerCache.has(t)) {
95
+ const r = {
96
+ get: (n, s, a) => Reflect.get(n, s, a),
97
+ set: (n, s, a) => (n[s] = t.makeReactiveValue(a), t.triggerUpdate(), !0),
98
+ deleteProperty: (n, s) => (delete n[s], t.triggerUpdate(), !0)
99
+ };
100
+ this.objectHandlerCache.set(t, r);
101
+ }
102
+ return this.objectHandlerCache.get(t);
103
+ }
104
+ /**
105
+ * Check if an object already has a cached proxy
106
+ */
107
+ static hasProxy(t) {
108
+ return this.cache.has(t);
109
+ }
110
+ /**
111
+ * Clear all cached proxies (useful for testing)
112
+ */
113
+ static clear() {
114
+ this.cache = /* @__PURE__ */ new WeakMap(), this.arrayHandlerCache = /* @__PURE__ */ new WeakMap(), this.objectHandlerCache = /* @__PURE__ */ new WeakMap();
115
+ }
116
+ /**
117
+ * Get cache statistics (for debugging)
118
+ * Note: WeakMap doesn't provide size, so this is limited
119
+ */
120
+ static getStats() {
121
+ return {
122
+ hasCachedProxies: this.cache instanceof WeakMap
123
+ };
124
+ }
125
+ }
126
+ class E {
127
+ // Cache a stable reactiveContext object keyed by onUpdate -> makeReactive
128
+ // This allows handler caches in ReactiveProxyCache to reuse handlers
129
+ // for identical reactive contexts instead of creating a new context object
130
+ // on each createReactiveProxy call.
131
+ static contextCache = /* @__PURE__ */ new WeakMap();
132
+ /**
133
+ * Create an optimized reactive proxy with minimal overhead
134
+ */
135
+ static createReactiveProxy(t, r, n) {
136
+ try {
137
+ if (C.has(t)) return t;
138
+ } catch {
139
+ }
140
+ const s = Array.isArray(t);
141
+ let a = this.contextCache.get(r);
142
+ a || (a = /* @__PURE__ */ new WeakMap(), this.contextCache.set(r, a));
143
+ let i = a.get(n);
144
+ return i || (i = {
145
+ triggerUpdate: r,
146
+ makeReactiveValue: n
147
+ }, a.set(n, i)), D.getOrCreateProxy(t, i, s);
148
+ }
149
+ /**
150
+ * Mark an object as a proxy (for optimization)
151
+ */
152
+ static markAsProxy(t) {
153
+ if (t)
154
+ try {
155
+ C.add(t);
156
+ } catch {
157
+ }
158
+ }
159
+ }
160
+ class N {
161
+ // Use a stack to support nested callers (component render -> watcher)
162
+ // so that watchers can temporarily become the "current component" while
163
+ // establishing dependencies without clobbering the outer component id.
164
+ currentComponentStack = [];
165
+ // Consolidated component data: stores dependencies, render function, state index, and last warning time
166
+ componentData = /* @__PURE__ */ new Map();
167
+ // Flat storage: compound key `${componentId}:${stateIndex}` -> ReactiveState
168
+ stateStorage = /* @__PURE__ */ new Map();
169
+ trackingDisabled = !1;
170
+ /**
171
+ * Set the current component being rendered for dependency tracking
172
+ */
173
+ setCurrentComponent(t, r) {
174
+ if (this.currentComponentStack.push(t), !this.componentData.has(t))
175
+ this.componentData.set(t, {
176
+ dependencies: /* @__PURE__ */ new Set(),
177
+ renderFn: r,
178
+ stateIndex: 0,
179
+ lastWarnTime: 0,
180
+ watchers: /* @__PURE__ */ new Map()
181
+ });
182
+ else {
183
+ const n = this.componentData.get(t);
184
+ if (n.watchers && n.watchers.size) {
185
+ for (const s of n.watchers.values())
186
+ try {
187
+ this.cleanup(s);
188
+ } catch {
189
+ }
190
+ n.watchers.clear();
191
+ }
192
+ n.renderFn = r, n.stateIndex = 0;
193
+ }
194
+ }
195
+ /**
196
+ * Clear the current component after rendering
197
+ */
198
+ clearCurrentComponent() {
199
+ this.currentComponentStack.pop();
200
+ }
201
+ /**
202
+ * Get the current component id (top of stack) or null
203
+ */
204
+ getCurrentComponentId() {
205
+ return this.currentComponentStack.length ? this.currentComponentStack[this.currentComponentStack.length - 1] : null;
206
+ }
207
+ /**
208
+ * Register a watcher id under a component so it can be cleaned up on re-render
209
+ */
210
+ registerWatcher(t, r) {
211
+ const n = this.componentData.get(t);
212
+ n && n.watchers.set(r, r);
213
+ }
214
+ /**
215
+ * Temporarily disable dependency tracking
216
+ */
217
+ disableTracking() {
218
+ this.trackingDisabled = !0;
219
+ }
220
+ /**
221
+ * Re-enable dependency tracking
222
+ */
223
+ enableTracking() {
224
+ this.trackingDisabled = !1;
225
+ }
226
+ /**
227
+ * Check if a component is currently rendering
228
+ */
229
+ isRenderingComponent() {
230
+ return this.currentComponentStack.length > 0;
231
+ }
232
+ /**
233
+ * Return whether we should emit a render-time warning for the current component.
234
+ * This throttles warnings to avoid spamming the console for legitimate rapid updates.
235
+ */
236
+ shouldEmitRenderWarning() {
237
+ const t = this.currentComponentStack.length ? this.currentComponentStack[this.currentComponentStack.length - 1] : null;
238
+ if (!t) return !0;
239
+ const r = this.componentData.get(t);
240
+ if (!r) return !0;
241
+ const n = Date.now();
242
+ return n - r.lastWarnTime < 1e3 ? !1 : (r.lastWarnTime = n, !0);
243
+ }
244
+ /**
245
+ * Execute a function with tracking disabled
246
+ */
247
+ withoutTracking(t) {
248
+ const r = this.trackingDisabled;
249
+ this.trackingDisabled = !0;
250
+ try {
251
+ return t();
252
+ } finally {
253
+ this.trackingDisabled = r;
254
+ }
255
+ }
256
+ /**
257
+ * Get or create a state instance for the current component
258
+ */
259
+ getOrCreateState(t) {
260
+ const r = this.currentComponentStack.length ? this.currentComponentStack[this.currentComponentStack.length - 1] : null;
261
+ if (!r)
262
+ return new g(t);
263
+ const n = this.componentData.get(r);
264
+ if (!n)
265
+ return new g(t);
266
+ const s = `${r}:${n.stateIndex++}`;
267
+ let a = this.stateStorage.get(s);
268
+ return a || (a = new g(t), this.stateStorage.set(s, a)), a;
269
+ }
270
+ /**
271
+ * Track a dependency for the current component
272
+ */
273
+ trackDependency(t) {
274
+ if (this.trackingDisabled) return;
275
+ const r = this.currentComponentStack.length ? this.currentComponentStack[this.currentComponentStack.length - 1] : null;
276
+ if (!r) return;
277
+ const n = this.componentData.get(r);
278
+ n && (n.dependencies.add(t), t.addDependent(r));
279
+ }
280
+ /**
281
+ * Trigger updates for all components that depend on a state
282
+ */
283
+ triggerUpdate(t) {
284
+ const r = t.getDependents();
285
+ for (const n of r) {
286
+ const s = this.componentData.get(n);
287
+ s && L(s.renderFn, n);
288
+ }
289
+ }
290
+ /**
291
+ * Clean up component dependencies when component is destroyed
292
+ */
293
+ cleanup(t) {
294
+ const r = this.componentData.get(t);
295
+ if (r) {
296
+ for (const s of r.dependencies)
297
+ s.removeDependent(t);
298
+ this.componentData.delete(t);
299
+ }
300
+ const n = t + ":";
301
+ for (const s of this.stateStorage.keys())
302
+ s.startsWith(n) && this.stateStorage.delete(s);
303
+ }
304
+ }
305
+ const o = new N();
306
+ class g {
307
+ _value;
308
+ dependents = /* @__PURE__ */ new Set();
309
+ constructor(t) {
310
+ this._value = this.makeReactive(t);
311
+ try {
312
+ const r = Symbol.for("@cer/ReactiveState");
313
+ Object.defineProperty(this, r, {
314
+ value: !0,
315
+ enumerable: !1,
316
+ configurable: !1
317
+ });
318
+ } catch {
319
+ }
320
+ }
321
+ get value() {
322
+ return o.trackDependency(this), this._value;
323
+ }
324
+ set value(t) {
325
+ o.isRenderingComponent() && o.shouldEmitRenderWarning() && _(
326
+ `🚨 State modification detected during render! This can cause infinite loops.
327
+ • Move state updates to event handlers
328
+ • Use useEffect/watch for side effects
329
+ • Ensure computed properties don't modify state`
330
+ ), this._value = this.makeReactive(t), o.triggerUpdate(this);
331
+ }
332
+ addDependent(t) {
333
+ this.dependents.add(t);
334
+ }
335
+ removeDependent(t) {
336
+ this.dependents.delete(t);
337
+ }
338
+ getDependents() {
339
+ return this.dependents;
340
+ }
341
+ makeReactive(t) {
342
+ return t === null || typeof t != "object" || t instanceof Node || t instanceof Element || t instanceof HTMLElement ? t : E.createReactiveProxy(
343
+ t,
344
+ () => o.triggerUpdate(this),
345
+ (r) => this.makeReactive(r)
346
+ );
347
+ }
348
+ }
349
+ function j(e) {
350
+ return o.getOrCreateState(
351
+ e === void 0 ? null : e
352
+ );
353
+ }
354
+ function m(e) {
355
+ if (!e || typeof e != "object") return !1;
356
+ try {
357
+ const t = Symbol.for("@cer/ReactiveState");
358
+ return Object.prototype.hasOwnProperty.call(e, t);
359
+ } catch {
360
+ return !1;
361
+ }
362
+ }
363
+ function F(e) {
364
+ const t = new g(e());
365
+ return {
366
+ get value() {
367
+ return o.trackDependency(t), e();
368
+ }
369
+ };
370
+ }
371
+ function z(e, t, r) {
372
+ let n;
373
+ const s = (() => {
374
+ try {
375
+ if (m(e))
376
+ return () => e.value;
377
+ } catch {
378
+ }
379
+ return e;
380
+ })(), a = `watch-${Math.random().toString(36).substr(2, 9)}`;
381
+ try {
382
+ const c = o.getCurrentComponentId();
383
+ c && o.registerWatcher(c, a);
384
+ } catch {
385
+ }
386
+ const i = () => {
387
+ o.setCurrentComponent(a, i);
388
+ const c = s();
389
+ o.clearCurrentComponent(), c !== n && (t(c, n), n = c);
390
+ };
391
+ return o.setCurrentComponent(a, i), n = s(), o.clearCurrentComponent(), r && r.immediate && t(n, void 0), () => {
392
+ o.cleanup(a);
393
+ };
394
+ }
395
+ const I = (e) => {
396
+ try {
397
+ e();
398
+ } catch {
399
+ }
400
+ }, h = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), y = 500;
401
+ let w, k, S = !1, b = !1, M;
402
+ const R = !!globalThis.process?.versions?.node;
403
+ function q(e) {
404
+ if (h.has(e))
405
+ return h.get(e);
406
+ const t = e.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
407
+ return h.size < y && h.set(e, t), t;
408
+ }
409
+ function $(e) {
410
+ if (p.has(e))
411
+ return p.get(e);
412
+ const t = e.replace(/-([a-z])/g, (r, n) => n.toUpperCase());
413
+ return p.size < y && p.set(e, t), t;
414
+ }
415
+ function V(e) {
416
+ if (typeof e == "string") {
417
+ if (f.has(e))
418
+ return f.get(e);
419
+ const t = e.replace(
420
+ /[&<>"']/g,
421
+ (r) => ({
422
+ "&": "&amp;",
423
+ "<": "&lt;",
424
+ ">": "&gt;",
425
+ '"': "&quot;",
426
+ "'": "&#39;"
427
+ })[r]
428
+ );
429
+ return t !== e && f.size < y && f.set(e, t), t;
430
+ }
431
+ return e;
432
+ }
433
+ function l(e) {
434
+ if (!e) return "";
435
+ const t = String(e);
436
+ if (typeof document < "u" && typeof document.createElement == "function") {
437
+ const c = t.replace(/</g, "").replace(/>/g, ""), u = M || (M = document.createElement("div"));
438
+ try {
439
+ l._el = u;
440
+ } catch {
441
+ }
442
+ return u.innerHTML = c, (u.textContent || "").replace(new RegExp("", "g"), "<").replace(new RegExp("", "g"), ">");
443
+ }
444
+ const r = {
445
+ lt: "<",
446
+ gt: ">",
447
+ amp: "&",
448
+ quot: '"',
449
+ apos: "'",
450
+ nbsp: " "
451
+ }, n = w ?? l._namedMap;
452
+ let s = n;
453
+ if (!s && R)
454
+ try {
455
+ const a = globalThis.require;
456
+ if (typeof a == "function") {
457
+ const i = [
458
+ "@jasonshimmy/custom-elements-runtime/entities.json",
459
+ // installed package export
460
+ "../../entities.json",
461
+ // dist/runtime -> ../../entities.json
462
+ "../../../entities.json",
463
+ // src/lib/runtime -> ../../../entities.json
464
+ "../entities.json",
465
+ "./entities.json"
466
+ ];
467
+ for (const c of i)
468
+ try {
469
+ const u = a(c);
470
+ if (u && typeof u == "object") {
471
+ s = u;
472
+ break;
473
+ }
474
+ } catch {
475
+ }
476
+ }
477
+ } catch {
478
+ }
479
+ if (!s) {
480
+ s = r, S = !0;
481
+ try {
482
+ l._usedFallback = !0;
483
+ } catch {
484
+ }
485
+ const a = l._namedMapLoader ?? k;
486
+ a && a().then((i) => {
487
+ w = i;
488
+ try {
489
+ l._namedMap = i;
490
+ } catch {
491
+ }
492
+ }).catch(() => {
493
+ });
494
+ }
495
+ if ((S || l._usedFallback) && !(b || l._warnedFallback)) {
496
+ b = !0;
497
+ try {
498
+ l._warnedFallback = !0;
499
+ } catch {
500
+ }
501
+ try {
502
+ _(
503
+ "decodeEntities: using small SSR fallback entity map. Register the full entities.json via registerEntityMap(entities) on the server to enable full HTML5 named-entity decoding."
504
+ );
505
+ } catch {
506
+ }
507
+ }
508
+ return t.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (a, i) => {
509
+ if (i.charCodeAt(0) === 35) {
510
+ const d = (i.charAt(1) || "").toLowerCase() === "x" ? parseInt(i.slice(2), 16) : parseInt(i.slice(1), 10);
511
+ return Number.isNaN(d) ? `&${i};` : String.fromCodePoint(d);
512
+ }
513
+ const c = s[i] ?? (n && n[i]);
514
+ return c !== void 0 ? c : `&${i};`;
515
+ });
516
+ }
517
+ async function A() {
518
+ const e = [
519
+ "@jasonshimmy",
520
+ "custom-elements-runtime",
521
+ "entities.json"
522
+ ].join("/");
523
+ try {
524
+ const t = await import(
525
+ /* @vite-ignore */
526
+ e
527
+ );
528
+ return t && (t.default || t);
529
+ } catch {
530
+ try {
531
+ const t = [
532
+ e,
533
+ // try package export via dynamic import too (best for installed packages)
534
+ "./entities.json",
535
+ "../../entities.json",
536
+ "../../../entities.json"
537
+ ];
538
+ for (const r of t)
539
+ try {
540
+ const n = await import(
541
+ /* @vite-ignore */
542
+ r
543
+ );
544
+ if (n)
545
+ return n && (n.default || n);
546
+ } catch {
547
+ }
548
+ return {
549
+ lt: "<",
550
+ gt: ">",
551
+ amp: "&",
552
+ quot: '"',
553
+ apos: "'",
554
+ nbsp: " "
555
+ };
556
+ } catch {
557
+ return {
558
+ lt: "<",
559
+ gt: ">",
560
+ amp: "&",
561
+ quot: '"',
562
+ apos: "'",
563
+ nbsp: " "
564
+ };
565
+ }
566
+ }
567
+ }
568
+ k = A;
569
+ l._namedMapLoader = A;
570
+ function G(e) {
571
+ const t = String(e);
572
+ return { __unsafeHTML: t, __rawHTML: t };
573
+ }
574
+ function K(e) {
575
+ return !!e && (typeof e.__unsafeHTML == "string" || typeof e.__rawHTML == "string");
576
+ }
577
+ function Z(e, t) {
578
+ if (typeof t == "string") {
579
+ if (t === "") return;
580
+ const r = t.split(".");
581
+ let n = e;
582
+ for (const s of r) {
583
+ if (n == null || typeof n != "object") {
584
+ n = void 0;
585
+ break;
586
+ }
587
+ n = n[s];
588
+ }
589
+ return m(n) ? n.value : n;
590
+ }
591
+ return t;
592
+ }
593
+ function B(e, t, r) {
594
+ const n = String(t).split("."), s = n.pop();
595
+ if (!s) return;
596
+ const a = n.reduce(
597
+ (i, c) => (i[c] == null && (i[c] = {}), i[c]),
598
+ e
599
+ );
600
+ m(a[s]) ? a[s].value = r : a[s] = r;
601
+ }
602
+ function P(e) {
603
+ try {
604
+ if (e && typeof e == "object") {
605
+ if (m(e)) return e.value;
606
+ if ("value" in e) {
607
+ const t = e.value;
608
+ return t == null || typeof t == "string" || typeof t == "number" || typeof t == "boolean" ? t : e;
609
+ }
610
+ }
611
+ } catch {
612
+ }
613
+ return e;
614
+ }
615
+ function X(e) {
616
+ const t = P(e);
617
+ if (t == null) return null;
618
+ const r = typeof t;
619
+ return r === "string" || r === "number" || r === "boolean" ? String(t) : null;
620
+ }
621
+ function J(e) {
622
+ if (!e || typeof e != "string") return !1;
623
+ if (e === "class" || e.endsWith("Class")) return !0;
624
+ if (e.includes("-"))
625
+ try {
626
+ if (e.split("-").some((r) => r === "class")) return !0;
627
+ } catch {
628
+ }
629
+ return !1;
630
+ }
631
+ const T = {
632
+ xlink: "http://www.w3.org/1999/xlink",
633
+ xml: "http://www.w3.org/XML/1998/namespace"
634
+ };
635
+ function Q(e, t, r) {
636
+ try {
637
+ if (!t || !t.includes(":")) {
638
+ e.setAttribute(t, r);
639
+ return;
640
+ }
641
+ const n = t.indexOf(":"), s = t.substring(0, n), a = t.substring(n + 1), i = T[s];
642
+ i ? e.setAttributeNS(i, a, r) : e.setAttribute(t, r);
643
+ } catch {
644
+ try {
645
+ e.setAttribute(t, r);
646
+ } catch {
647
+ }
648
+ }
649
+ }
650
+ function Y(e, t) {
651
+ try {
652
+ if (!t || !t.includes(":")) {
653
+ e.removeAttribute(t);
654
+ return;
655
+ }
656
+ const r = t.indexOf(":"), n = t.substring(0, r), s = t.substring(r + 1), a = T[n];
657
+ a ? e.removeAttributeNS(a, s) : e.removeAttribute(t);
658
+ } catch {
659
+ try {
660
+ e.removeAttribute(t);
661
+ } catch {
662
+ }
663
+ }
664
+ }
665
+ const W = "http://www.w3.org/2000/svg", O = "http://www.w3.org/1998/Math/MathML", tt = {
666
+ svg: W,
667
+ math: O
668
+ };
669
+ export {
670
+ W as S,
671
+ tt as T,
672
+ I as a,
673
+ X as b,
674
+ F as c,
675
+ Q as d,
676
+ V as e,
677
+ Y as f,
678
+ Z as g,
679
+ $ as h,
680
+ m as i,
681
+ J as j,
682
+ o as k,
683
+ L as l,
684
+ K as m,
685
+ l as n,
686
+ j as r,
687
+ B as s,
688
+ q as t,
689
+ G as u,
690
+ z as w
691
+ };
692
+ //# sourceMappingURL=namespace-helpers-Dw1mgQab.js.map