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