@jasonshimmy/custom-elements-runtime 2.8.2 → 3.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.
Files changed (91) hide show
  1. package/README.md +159 -46
  2. package/dist/css-utils-Cg4o1MqY.js +643 -0
  3. package/dist/css-utils-Cg4o1MqY.js.map +1 -0
  4. package/dist/css-utils-RqkyBWft.cjs +576 -0
  5. package/dist/css-utils-RqkyBWft.cjs.map +1 -0
  6. package/dist/custom-elements-runtime.cjs.js +3 -3
  7. package/dist/custom-elements-runtime.cjs.js.map +1 -1
  8. package/dist/custom-elements-runtime.dom-jit-css.cjs.js +7 -0
  9. package/dist/custom-elements-runtime.dom-jit-css.cjs.js.map +1 -0
  10. package/dist/custom-elements-runtime.dom-jit-css.es.js +136 -0
  11. package/dist/custom-elements-runtime.dom-jit-css.es.js.map +1 -0
  12. package/dist/custom-elements-runtime.es.js +70 -67
  13. package/dist/custom-elements-runtime.es.js.map +1 -1
  14. package/dist/custom-elements-runtime.event-bus.cjs.js +1 -1
  15. package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
  16. package/dist/custom-elements-runtime.event-bus.es.js +62 -46
  17. package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
  18. package/dist/custom-elements-runtime.jit-css.cjs.js +2 -0
  19. package/dist/custom-elements-runtime.jit-css.cjs.js.map +1 -0
  20. package/dist/custom-elements-runtime.jit-css.es.js +38 -0
  21. package/dist/custom-elements-runtime.jit-css.es.js.map +1 -0
  22. package/dist/custom-elements-runtime.router.cjs.js +20 -20
  23. package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
  24. package/dist/custom-elements-runtime.router.es.js +448 -434
  25. package/dist/custom-elements-runtime.router.es.js.map +1 -1
  26. package/dist/custom-elements-runtime.ssr.cjs.js +1 -1
  27. package/dist/custom-elements-runtime.ssr.cjs.js.map +1 -1
  28. package/dist/custom-elements-runtime.ssr.es.js +33 -18
  29. package/dist/custom-elements-runtime.ssr.es.js.map +1 -1
  30. package/dist/custom-elements-runtime.store.cjs.js +1 -1
  31. package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
  32. package/dist/custom-elements-runtime.store.es.js +21 -16
  33. package/dist/custom-elements-runtime.store.es.js.map +1 -1
  34. package/dist/custom-elements-runtime.transitions.cjs.js +1 -1
  35. package/dist/custom-elements-runtime.transitions.cjs.js.map +1 -1
  36. package/dist/custom-elements-runtime.transitions.es.js +279 -7
  37. package/dist/custom-elements-runtime.transitions.es.js.map +1 -1
  38. package/dist/custom-elements-runtime.vite-plugin.cjs.js +2 -0
  39. package/dist/custom-elements-runtime.vite-plugin.cjs.js.map +1 -0
  40. package/dist/custom-elements-runtime.vite-plugin.es.js +73 -0
  41. package/dist/custom-elements-runtime.vite-plugin.es.js.map +1 -0
  42. package/dist/dom-jit-css.d.ts +66 -0
  43. package/dist/event-bus.d.ts +3 -1
  44. package/dist/{namespace-helpers-DhLBqt-7.js → helpers-CweFZFWU.js} +265 -287
  45. package/dist/helpers-CweFZFWU.js.map +1 -0
  46. package/dist/helpers-DeWjSmOl.cjs +5 -0
  47. package/dist/helpers-DeWjSmOl.cjs.map +1 -0
  48. package/dist/hooks-BrrLKSub.cjs +3 -0
  49. package/dist/hooks-BrrLKSub.cjs.map +1 -0
  50. package/dist/hooks-DyShDHKo.js +403 -0
  51. package/dist/hooks-DyShDHKo.js.map +1 -0
  52. package/dist/index.d.ts +3 -3
  53. package/dist/jit-css.d.ts +30 -0
  54. package/dist/namespace-helpers-CnpZ5__p.js +45 -0
  55. package/dist/namespace-helpers-CnpZ5__p.js.map +1 -0
  56. package/dist/namespace-helpers-CyIDtI97.cjs +2 -0
  57. package/dist/namespace-helpers-CyIDtI97.cjs.map +1 -0
  58. package/dist/router/types.d.ts +4 -2
  59. package/dist/runtime/css-utils.d.ts +33 -0
  60. package/dist/runtime/discovery-state.d.ts +3 -0
  61. package/dist/runtime/hooks.d.ts +78 -0
  62. package/dist/runtime/jit-hooks.d.ts +28 -0
  63. package/dist/runtime/render-bridge.d.ts +37 -0
  64. package/dist/runtime/scheduler.d.ts +3 -4
  65. package/dist/runtime/secure-expression-evaluator.d.ts +0 -1
  66. package/dist/runtime/style.d.ts +84 -26
  67. package/dist/runtime/template-compiler/lru-cache.d.ts +0 -3
  68. package/dist/runtime/vdom-helpers.d.ts +0 -1
  69. package/dist/ssr.d.ts +42 -0
  70. package/dist/{transitions-DMJXs_tY.js → style-BmyOIMcU.js} +904 -1344
  71. package/dist/style-BmyOIMcU.js.map +1 -0
  72. package/dist/style-D40DsIqJ.cjs +55 -0
  73. package/dist/style-D40DsIqJ.cjs.map +1 -0
  74. package/dist/style.css +1 -1
  75. package/dist/template-compiler-B5uN1EQw.js +3731 -0
  76. package/dist/template-compiler-B5uN1EQw.js.map +1 -0
  77. package/dist/template-compiler-Cx623BSB.cjs +23 -0
  78. package/dist/template-compiler-Cx623BSB.cjs.map +1 -0
  79. package/dist/variables.css +1 -1
  80. package/dist/vite-plugin.d.ts +52 -0
  81. package/package.json +55 -6
  82. package/dist/namespace-helpers-Ctd_h7j2.cjs +0 -5
  83. package/dist/namespace-helpers-Ctd_h7j2.cjs.map +0 -1
  84. package/dist/namespace-helpers-DhLBqt-7.js.map +0 -1
  85. package/dist/template-compiler-Bvx02nAT.js +0 -4020
  86. package/dist/template-compiler-Bvx02nAT.js.map +0 -1
  87. package/dist/template-compiler-bj-MFC_Y.cjs +0 -23
  88. package/dist/template-compiler-bj-MFC_Y.cjs.map +0 -1
  89. package/dist/transitions-DMJXs_tY.js.map +0 -1
  90. package/dist/transitions-f4KfN29T.cjs +0 -330
  91. package/dist/transitions-f4KfN29T.cjs.map +0 -1
@@ -1,28 +1,36 @@
1
- import { d as l } from "./logger-BvkEbVM4.js";
2
- class o extends EventTarget {
1
+ import { d as h } from "./logger-BvkEbVM4.js";
2
+ class i extends EventTarget {
3
3
  handlers = {};
4
4
  static instance;
5
5
  eventCounters = /* @__PURE__ */ new Map();
6
+ nativeUnsubscribers = /* @__PURE__ */ new Map();
7
+ MAX_EVENT_COUNTERS = 1e3;
6
8
  /**
7
9
  * Returns the singleton instance of GlobalEventBus
8
10
  */
9
11
  static getInstance() {
10
- return o.instance || (o.instance = new o()), o.instance;
12
+ return i.instance || (i.instance = new i()), i.instance;
11
13
  }
12
14
  /**
13
15
  * Emit a global event with optional data. Includes event storm protection.
14
16
  * @param eventName - Name of the event
15
17
  * @param data - Optional event payload
16
18
  */
17
- emit(t, n) {
18
- const e = Date.now(), r = this.eventCounters.get(t);
19
- if (!r || e - r.window > 1e3)
20
- this.eventCounters.set(t, { count: 1, window: e });
21
- else if (r.count++, r.count > 50 && r.count > 100)
19
+ emit(t, e) {
20
+ const n = Date.now(), s = this.eventCounters.get(t);
21
+ if (!s || n - s.window > 1e3) {
22
+ if (!s && this.eventCounters.size >= this.MAX_EVENT_COUNTERS) {
23
+ const u = this.eventCounters.keys().next().value;
24
+ u !== void 0 && this.eventCounters.delete(u);
25
+ }
26
+ this.eventCounters.set(t, { count: 1, window: n });
27
+ } else if (s.count++, s.count === 51 && h(
28
+ `[EventBus] Event "${t}" is firing too frequently (>${s.count - 1}/s). Emissions above 50/s are throttled and above 100/s are dropped to prevent event storms. Consider debouncing the emitter.`
29
+ ), s.count > 100)
22
30
  return;
23
31
  this.dispatchEvent(
24
32
  new CustomEvent(t, {
25
- detail: n,
33
+ detail: e,
26
34
  bubbles: !1,
27
35
  // Global events don't need to bubble
28
36
  cancelable: !0
@@ -31,9 +39,9 @@ class o extends EventTarget {
31
39
  const c = this.handlers[t];
32
40
  c && c.forEach((u) => {
33
41
  try {
34
- u(n);
35
- } catch (h) {
36
- l(`Error in global event handler for "${t}":`, h);
42
+ u(e);
43
+ } catch (a) {
44
+ h(`Error in global event handler for "${t}":`, a);
37
45
  }
38
46
  });
39
47
  }
@@ -42,17 +50,17 @@ class o extends EventTarget {
42
50
  * @param eventName - Name of the event
43
51
  * @param handler - Handler function
44
52
  */
45
- on(t, n) {
46
- return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(n), () => this.off(t, n);
53
+ on(t, e) {
54
+ return this.handlers[t] || (this.handlers[t] = /* @__PURE__ */ new Set()), this.handlers[t].add(e), () => this.off(t, e);
47
55
  }
48
56
  /**
49
57
  * Remove a specific handler for a global event.
50
58
  * @param eventName - Name of the event
51
59
  * @param handler - Handler function to remove
52
60
  */
53
- off(t, n) {
54
- const e = this.handlers[t];
55
- e && e.delete(n);
61
+ off(t, e) {
62
+ const n = this.handlers[t];
63
+ n && (n.delete(e), n.size === 0 && delete this.handlers[t]);
56
64
  }
57
65
  /**
58
66
  * Remove all handlers for a specific event.
@@ -67,18 +75,22 @@ class o extends EventTarget {
67
75
  * @param handler - CustomEvent handler
68
76
  * @param options - AddEventListener options
69
77
  */
70
- listen(t, n, e) {
71
- return this.addEventListener(t, n, e), () => this.removeEventListener(t, n);
78
+ listen(t, e, n) {
79
+ this.addEventListener(t, e, n);
80
+ const s = () => {
81
+ this.removeEventListener(t, e), this.nativeUnsubscribers.delete(s);
82
+ };
83
+ return this.nativeUnsubscribers.set(s, !0), s;
72
84
  }
73
- once(t, n) {
74
- if (n !== void 0) {
75
- const e = this.on(t, (r) => {
76
- e(), n(r);
85
+ once(t, e) {
86
+ if (e !== void 0) {
87
+ const n = this.on(t, (s) => {
88
+ n(), e(s);
77
89
  });
78
90
  } else
79
- return new Promise((e) => {
80
- const r = this.on(t, (c) => {
81
- r(), e(c);
91
+ return new Promise((n) => {
92
+ const s = this.on(t, (c) => {
93
+ s(), n(c);
82
94
  });
83
95
  });
84
96
  }
@@ -91,10 +103,14 @@ class o extends EventTarget {
91
103
  );
92
104
  }
93
105
  /**
94
- * Clear all event handlers (useful for testing or cleanup).
106
+ * Clear all event handlers and native EventTarget listeners (useful for testing or cleanup).
95
107
  */
96
108
  clear() {
97
109
  this.handlers = {};
110
+ const t = Array.from(this.nativeUnsubscribers.keys());
111
+ this.nativeUnsubscribers.clear();
112
+ for (const e of t)
113
+ e();
98
114
  }
99
115
  /**
100
116
  * Get the number of handlers registered for a specific event.
@@ -108,10 +124,10 @@ class o extends EventTarget {
108
124
  */
109
125
  getEventStats() {
110
126
  const t = {};
111
- for (const [n, e] of this.eventCounters.entries())
112
- t[n] = {
113
- count: e.count,
114
- handlersCount: this.getHandlerCount(n)
127
+ for (const [e, n] of this.eventCounters.entries())
128
+ t[e] = {
129
+ count: n.count,
130
+ handlersCount: this.getHandlerCount(e)
115
131
  };
116
132
  return t;
117
133
  }
@@ -122,29 +138,29 @@ class o extends EventTarget {
122
138
  this.eventCounters.clear();
123
139
  }
124
140
  }
125
- const i = new Proxy(
141
+ const o = new Proxy(
126
142
  {},
127
143
  {
128
- get(s, t) {
129
- const n = o.getInstance(), e = n[t];
130
- return typeof e == "function" ? e.bind(n) : e;
144
+ get(r, t) {
145
+ const e = i.getInstance(), n = e[t];
146
+ return typeof n == "function" ? n.bind(e) : n;
131
147
  },
132
148
  apply() {
133
149
  throw new TypeError("eventBus is not a callable function");
134
150
  }
135
151
  }
136
- ), f = (s, t) => i.emit(s, t), d = (s, t) => i.on(s, t), w = (s, t) => i.off(s, t);
137
- function g(s, t) {
138
- return t !== void 0 ? i.once(s, t) : i.once(s);
152
+ ), d = (r, t) => o.emit(r, t), f = (r, t) => o.on(r, t), b = (r, t) => o.off(r, t);
153
+ function v(r, t) {
154
+ return t !== void 0 ? o.once(r, t) : o.once(r);
139
155
  }
140
- const v = (s, t, n) => i.listen(s, t, n);
156
+ const E = (r, t, e) => o.listen(r, t, e);
141
157
  export {
142
- o as GlobalEventBus,
143
- f as emit,
144
- i as eventBus,
145
- v as listen,
146
- w as off,
147
- d as on,
148
- g as once
158
+ i as GlobalEventBus,
159
+ d as emit,
160
+ o as eventBus,
161
+ E as listen,
162
+ b as off,
163
+ f as on,
164
+ v as once
149
165
  };
150
166
  //# sourceMappingURL=custom-elements-runtime.event-bus.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-elements-runtime.event-bus.es.js","sources":["../src/lib/event-bus.ts"],"sourcesContent":["/**\n * Event handler type for global event bus\n */\nexport type EventHandler<T> = (data: T) => void;\n\nimport { devError } from './runtime/logger';\n\n/**\n * Event map type using Set for efficient handler management\n */\ntype EventMap<Events extends Record<string, unknown>> = {\n [K in keyof Events]: Set<EventHandler<Events[K]>>;\n};\n\n/**\n * GlobalEventBus provides a singleton event bus for cross-component communication.\n * Uses Set for handler storage to optimize add/remove operations and prevent duplicates.\n */\nexport class GlobalEventBus extends EventTarget {\n private handlers: EventMap<Record<string, unknown>> = {};\n private static instance: GlobalEventBus;\n private eventCounters: Map<string, { count: number; window: number }> =\n new Map();\n\n /**\n * Returns the singleton instance of GlobalEventBus\n */\n static getInstance(): GlobalEventBus {\n if (!GlobalEventBus.instance) {\n GlobalEventBus.instance = new GlobalEventBus();\n }\n return GlobalEventBus.instance;\n }\n\n /**\n * Emit a global event with optional data. Includes event storm protection.\n * @param eventName - Name of the event\n * @param data - Optional event payload\n */\n emit<T = unknown>(eventName: string, data?: T): void {\n // Event storm protection\n const now = Date.now();\n const counter = this.eventCounters.get(eventName);\n\n if (!counter || now - counter.window > 1000) {\n // Reset counter every second\n this.eventCounters.set(eventName, { count: 1, window: now });\n } else {\n counter.count++;\n\n if (counter.count > 50) {\n // Throttle excessive events to avoid event storms (silent in runtime)\n if (counter.count > 100) {\n return;\n }\n }\n }\n\n // Use native CustomEvent for better browser integration\n this.dispatchEvent(\n new CustomEvent(eventName, {\n detail: data,\n bubbles: false, // Global events don't need to bubble\n cancelable: true,\n }),\n );\n\n // Also trigger registered handlers\n const eventHandlers = this.handlers[eventName];\n if (eventHandlers) {\n eventHandlers.forEach((handler) => {\n try {\n handler(data);\n } catch (error) {\n devError(`Error in global event handler for \"${eventName}\":`, error);\n }\n });\n }\n }\n\n /**\n * Register a handler for a global event. Returns an unsubscribe function.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n on<T = unknown>(eventName: string, handler: EventHandler<T>): () => void {\n if (!this.handlers[eventName]) {\n this.handlers[eventName] = new Set<EventHandler<unknown>>();\n }\n this.handlers[eventName].add(handler as EventHandler<unknown>);\n return () => this.off(eventName, handler);\n }\n\n /**\n * Remove a specific handler for a global event.\n * @param eventName - Name of the event\n * @param handler - Handler function to remove\n */\n off<T = unknown>(eventName: string, handler: EventHandler<T>): void {\n const eventHandlers = this.handlers[eventName];\n if (eventHandlers) {\n eventHandlers.delete(handler as EventHandler<unknown>);\n }\n }\n\n /**\n * Remove all handlers for a specific event.\n * @param eventName - Name of the event\n */\n offAll(eventName: string): void {\n delete this.handlers[eventName];\n }\n\n /**\n * Listen for a native CustomEvent. Returns an unsubscribe function.\n * @param eventName - Name of the event\n * @param handler - CustomEvent handler\n * @param options - AddEventListener options\n */\n listen<T = unknown>(\n eventName: string,\n handler: (event: CustomEvent<T>) => void,\n options?: AddEventListenerOptions,\n ): () => void {\n this.addEventListener(eventName, handler as EventListener, options);\n return () => this.removeEventListener(eventName, handler as EventListener);\n }\n\n /**\n * Register a one-time event handler (callback form).\n * The handler is invoked exactly once, then automatically unsubscribed.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n once<T = unknown>(eventName: string, handler: EventHandler<T>): void;\n /**\n * Returns a Promise that resolves with the first emission of the event\n * (Promise form — no handler argument).\n * @param eventName - Name of the event\n */\n once<T = unknown>(eventName: string): Promise<T>;\n once<T = unknown>(\n eventName: string,\n handler?: EventHandler<T>,\n ): void | Promise<T> {\n if (handler !== undefined) {\n // Callback form: fire-and-forget, returns void\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n handler(data);\n });\n } else {\n // Promise form: resolves on first emission\n return new Promise<T>((resolve) => {\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n resolve(data);\n });\n });\n }\n }\n\n /**\n * Get a list of all active event names with registered handlers.\n */\n getActiveEvents(): string[] {\n return Object.keys(this.handlers).filter(\n (eventName) =>\n this.handlers[eventName] && this.handlers[eventName].size > 0,\n );\n }\n\n /**\n * Clear all event handlers (useful for testing or cleanup).\n */\n clear(): void {\n this.handlers = {};\n // Note: This doesn't clear native event listeners, use removeAllListeners if needed\n }\n\n /**\n * Get the number of handlers registered for a specific event.\n * @param eventName - Name of the event\n */\n getHandlerCount(eventName: string): number {\n return this.handlers[eventName]?.size || 0;\n }\n\n /**\n * Get event statistics for debugging.\n */\n getEventStats(): Record<string, { count: number; handlersCount: number }> {\n const stats: Record<string, { count: number; handlersCount: number }> = {};\n for (const [eventName, counter] of this.eventCounters.entries()) {\n stats[eventName] = {\n count: counter.count,\n handlersCount: this.getHandlerCount(eventName),\n };\n }\n return stats;\n }\n\n /**\n * Reset event counters (useful for testing or after resolving issues).\n */\n resetEventCounters(): void {\n this.eventCounters.clear();\n }\n}\n\n/**\n * Singleton instance of the global event bus\n */\n/**\n * Lazily-instantiated event bus.\n *\n * We preserve the `eventBus` export for backward compatibility but avoid\n * creating the underlying GlobalEventBus instance at module import time.\n * A small proxy defers the call to `GlobalEventBus.getInstance()` until a\n * property is accessed. This reduces import-time side-effects and helps\n * bundlers tree-shake unused entrypoints.\n */\nexport const eventBus = new Proxy(\n {},\n {\n get(_target, prop: PropertyKey) {\n const inst = GlobalEventBus.getInstance();\n const val = (inst as unknown as Record<PropertyKey, unknown>)[prop];\n // If the property is a function (method), bind it to the instance\n // so callers using `eventBus.method(...)` get the correct `this`.\n if (typeof val === 'function')\n return (val as (...args: unknown[]) => unknown).bind(inst);\n return val;\n },\n apply() {\n throw new TypeError('eventBus is not a callable function');\n },\n },\n) as unknown as GlobalEventBus;\n\n/**\n * Emit a global event\n */\nexport const emit = <T = unknown>(eventName: string, data?: T) =>\n eventBus.emit(eventName, data);\n\n/**\n * Register a handler for a global event\n */\nexport const on = <T = unknown>(eventName: string, handler: EventHandler<T>) =>\n eventBus.on(eventName, handler);\n\n/**\n * Remove a handler for a global event\n */\nexport const off = <T = unknown>(eventName: string, handler: EventHandler<T>) =>\n eventBus.off(eventName, handler);\n\n/**\n * Register a one-time handler for a global event (callback form).\n * The handler fires once then auto-unsubscribes.\n */\nexport function once<T = unknown>(\n eventName: string,\n handler: EventHandler<T>,\n): void;\n/**\n * Returns a Promise that resolves with the next emission of the event\n * (Promise form — no handler argument needed).\n */\nexport function once<T = unknown>(eventName: string): Promise<T>;\nexport function once<T = unknown>(\n eventName: string,\n handler?: EventHandler<T>,\n): void | Promise<T> {\n if (handler !== undefined) {\n return eventBus.once(eventName, handler);\n }\n return eventBus.once<T>(eventName);\n}\n\n/**\n * Listen for a native CustomEvent\n */\nexport const listen = <T = unknown>(\n eventName: string,\n handler: (event: CustomEvent<T>) => void,\n options?: AddEventListenerOptions,\n) => eventBus.listen(eventName, handler, options);\n"],"names":["GlobalEventBus","eventName","data","now","counter","eventHandlers","handler","error","devError","options","unsubscribe","resolve","stats","eventBus","_target","prop","inst","val","emit","on","off","once","listen"],"mappings":";AAkBO,MAAMA,UAAuB,YAAY;AAAA,EACtC,WAA8C,CAAA;AAAA,EACtD,OAAe;AAAA,EACP,oCACF,IAAA;AAAA;AAAA;AAAA;AAAA,EAKN,OAAO,cAA8B;AACnC,WAAKA,EAAe,aAClBA,EAAe,WAAW,IAAIA,EAAA,IAEzBA,EAAe;AAAA,EACxB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,KAAkBC,GAAmBC,GAAgB;AAEnD,UAAMC,IAAM,KAAK,IAAA,GACXC,IAAU,KAAK,cAAc,IAAIH,CAAS;AAEhD,QAAI,CAACG,KAAWD,IAAMC,EAAQ,SAAS;AAErC,WAAK,cAAc,IAAIH,GAAW,EAAE,OAAO,GAAG,QAAQE,GAAK;AAAA,aAE3DC,EAAQ,SAEJA,EAAQ,QAAQ,MAEdA,EAAQ,QAAQ;AAClB;AAMN,SAAK;AAAA,MACH,IAAI,YAAYH,GAAW;AAAA,QACzB,QAAQC;AAAA,QACR,SAAS;AAAA;AAAA,QACT,YAAY;AAAA,MAAA,CACb;AAAA,IAAA;AAIH,UAAMG,IAAgB,KAAK,SAASJ,CAAS;AAC7C,IAAII,KACFA,EAAc,QAAQ,CAACC,MAAY;AACjC,UAAI;AACF,QAAAA,EAAQJ,CAAI;AAAA,MACd,SAASK,GAAO;AACd,QAAAC,EAAS,sCAAsCP,CAAS,MAAMM,CAAK;AAAA,MACrE;AAAA,IACF,CAAC;AAAA,EAEL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,GAAgBN,GAAmBK,GAAsC;AACvE,WAAK,KAAK,SAASL,CAAS,MAC1B,KAAK,SAASA,CAAS,IAAI,oBAAI,IAAA,IAEjC,KAAK,SAASA,CAAS,EAAE,IAAIK,CAAgC,GACtD,MAAM,KAAK,IAAIL,GAAWK,CAAO;AAAA,EAC1C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,IAAiBL,GAAmBK,GAAgC;AAClE,UAAMD,IAAgB,KAAK,SAASJ,CAAS;AAC7C,IAAII,KACFA,EAAc,OAAOC,CAAgC;AAAA,EAEzD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAOL,GAAyB;AAC9B,WAAO,KAAK,SAASA,CAAS;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OACEA,GACAK,GACAG,GACY;AACZ,gBAAK,iBAAiBR,GAAWK,GAA0BG,CAAO,GAC3D,MAAM,KAAK,oBAAoBR,GAAWK,CAAwB;AAAA,EAC3E;AAAA,EAeA,KACEL,GACAK,GACmB;AACnB,QAAIA,MAAY,QAAW;AAEzB,YAAMI,IAAc,KAAK,GAAGT,GAAW,CAACC,MAAY;AAClD,QAAAQ,EAAA,GACAJ,EAAQJ,CAAI;AAAA,MACd,CAAC;AAAA,IACH;AAEE,aAAO,IAAI,QAAW,CAACS,MAAY;AACjC,cAAMD,IAAc,KAAK,GAAGT,GAAW,CAACC,MAAY;AAClD,UAAAQ,EAAA,GACAC,EAAQT,CAAI;AAAA,QACd,CAAC;AAAA,MACH,CAAC;AAAA,EAEL;AAAA;AAAA;AAAA;AAAA,EAKA,kBAA4B;AAC1B,WAAO,OAAO,KAAK,KAAK,QAAQ,EAAE;AAAA,MAChC,CAACD,MACC,KAAK,SAASA,CAAS,KAAK,KAAK,SAASA,CAAS,EAAE,OAAO;AAAA,IAAA;AAAA,EAElE;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,WAAW,CAAA;AAAA,EAElB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgBA,GAA2B;AACzC,WAAO,KAAK,SAASA,CAAS,GAAG,QAAQ;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA,EAKA,gBAA0E;AACxE,UAAMW,IAAkE,CAAA;AACxE,eAAW,CAACX,GAAWG,CAAO,KAAK,KAAK,cAAc;AACpD,MAAAQ,EAAMX,CAAS,IAAI;AAAA,QACjB,OAAOG,EAAQ;AAAA,QACf,eAAe,KAAK,gBAAgBH,CAAS;AAAA,MAAA;AAGjD,WAAOW;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKA,qBAA2B;AACzB,SAAK,cAAc,MAAA;AAAA,EACrB;AACF;AAcO,MAAMC,IAAW,IAAI;AAAA,EAC1B,CAAA;AAAA,EACA;AAAA,IACE,IAAIC,GAASC,GAAmB;AAC9B,YAAMC,IAAOhB,EAAe,YAAA,GACtBiB,IAAOD,EAAiDD,CAAI;AAGlE,aAAI,OAAOE,KAAQ,aACTA,EAAwC,KAAKD,CAAI,IACpDC;AAAA,IACT;AAAA,IACA,QAAQ;AACN,YAAM,IAAI,UAAU,qCAAqC;AAAA,IAC3D;AAAA,EAAA;AAEJ,GAKaC,IAAO,CAAcjB,GAAmBC,MACnDW,EAAS,KAAKZ,GAAWC,CAAI,GAKlBiB,IAAK,CAAclB,GAAmBK,MACjDO,EAAS,GAAGZ,GAAWK,CAAO,GAKnBc,IAAM,CAAcnB,GAAmBK,MAClDO,EAAS,IAAIZ,GAAWK,CAAO;AAe1B,SAASe,EACdpB,GACAK,GACmB;AACnB,SAAIA,MAAY,SACPO,EAAS,KAAKZ,GAAWK,CAAO,IAElCO,EAAS,KAAQZ,CAAS;AACnC;AAKO,MAAMqB,IAAS,CACpBrB,GACAK,GACAG,MACGI,EAAS,OAAOZ,GAAWK,GAASG,CAAO;"}
1
+ {"version":3,"file":"custom-elements-runtime.event-bus.es.js","sources":["../src/lib/event-bus.ts"],"sourcesContent":["/**\n * Event handler type for global event bus\n */\nexport type EventHandler<T> = (data: T) => void;\n\nimport { devError } from './runtime/logger';\n\n/**\n * Event map type using Set for efficient handler management\n */\ntype EventMap<Events extends Record<string, unknown>> = {\n [K in keyof Events]: Set<EventHandler<Events[K]>>;\n};\n\n/**\n * GlobalEventBus provides a singleton event bus for cross-component communication.\n * Uses Set for handler storage to optimize add/remove operations and prevent duplicates.\n */\nexport class GlobalEventBus extends EventTarget {\n private handlers: EventMap<Record<string, unknown>> = {};\n private static instance: GlobalEventBus;\n private eventCounters: Map<string, { count: number; window: number }> =\n new Map();\n private nativeUnsubscribers: Map<() => void, true> = new Map();\n private readonly MAX_EVENT_COUNTERS = 1000;\n\n /**\n * Returns the singleton instance of GlobalEventBus\n */\n static getInstance(): GlobalEventBus {\n if (!GlobalEventBus.instance) {\n GlobalEventBus.instance = new GlobalEventBus();\n }\n return GlobalEventBus.instance;\n }\n\n /**\n * Emit a global event with optional data. Includes event storm protection.\n * @param eventName - Name of the event\n * @param data - Optional event payload\n */\n emit<T = unknown>(eventName: string, data?: T): void {\n // Event storm protection\n const now = Date.now();\n const counter = this.eventCounters.get(eventName);\n\n if (!counter || now - counter.window > 1000) {\n // Evict oldest entry if the map is at capacity to prevent unbounded growth.\n if (!counter && this.eventCounters.size >= this.MAX_EVENT_COUNTERS) {\n const firstKey = this.eventCounters.keys().next().value;\n if (firstKey !== undefined) this.eventCounters.delete(firstKey);\n }\n // Reset counter every second\n this.eventCounters.set(eventName, { count: 1, window: now });\n } else {\n counter.count++;\n\n if (counter.count === 51) {\n // Warn once at the throttle threshold so developers know emissions are being dropped.\n devError(\n `[EventBus] Event \"${eventName}\" is firing too frequently (>${counter.count - 1}/s). ` +\n 'Emissions above 50/s are throttled and above 100/s are dropped to prevent event storms. ' +\n 'Consider debouncing the emitter.',\n );\n }\n if (counter.count > 100) {\n // Drop the event to protect against runaway event storms.\n return;\n }\n }\n\n // Use native CustomEvent for better browser integration\n this.dispatchEvent(\n new CustomEvent(eventName, {\n detail: data,\n bubbles: false, // Global events don't need to bubble\n cancelable: true,\n }),\n );\n\n // Also trigger registered handlers\n const eventHandlers = this.handlers[eventName];\n if (eventHandlers) {\n eventHandlers.forEach((handler) => {\n try {\n handler(data);\n } catch (error) {\n devError(`Error in global event handler for \"${eventName}\":`, error);\n }\n });\n }\n }\n\n /**\n * Register a handler for a global event. Returns an unsubscribe function.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n on<T = unknown>(eventName: string, handler: EventHandler<T>): () => void {\n if (!this.handlers[eventName]) {\n this.handlers[eventName] = new Set<EventHandler<unknown>>();\n }\n this.handlers[eventName].add(handler as EventHandler<unknown>);\n return () => this.off(eventName, handler);\n }\n\n /**\n * Remove a specific handler for a global event.\n * @param eventName - Name of the event\n * @param handler - Handler function to remove\n */\n off<T = unknown>(eventName: string, handler: EventHandler<T>): void {\n const eventHandlers = this.handlers[eventName];\n if (eventHandlers) {\n eventHandlers.delete(handler as EventHandler<unknown>);\n // Remove the entry entirely once it is empty so stale keys don't\n // accumulate indefinitely in long-lived apps.\n if (eventHandlers.size === 0) {\n delete this.handlers[eventName];\n }\n }\n }\n\n /**\n * Remove all handlers for a specific event.\n * @param eventName - Name of the event\n */\n offAll(eventName: string): void {\n delete this.handlers[eventName];\n }\n\n /**\n * Listen for a native CustomEvent. Returns an unsubscribe function.\n * @param eventName - Name of the event\n * @param handler - CustomEvent handler\n * @param options - AddEventListener options\n */\n listen<T = unknown>(\n eventName: string,\n handler: (event: CustomEvent<T>) => void,\n options?: AddEventListenerOptions,\n ): () => void {\n this.addEventListener(eventName, handler as EventListener, options);\n // Use a wrapper so calling unsubscribe also removes it from nativeUnsubscribers,\n // preventing indefinite accumulation in long-lived apps.\n const unsubscribe: () => void = () => {\n this.removeEventListener(eventName, handler as EventListener);\n this.nativeUnsubscribers.delete(unsubscribe);\n };\n this.nativeUnsubscribers.set(unsubscribe, true);\n return unsubscribe;\n }\n\n /**\n * Register a one-time event handler (callback form).\n * The handler is invoked exactly once, then automatically unsubscribed.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n once<T = unknown>(eventName: string, handler: EventHandler<T>): void;\n /**\n * Returns a Promise that resolves with the first emission of the event\n * (Promise form — no handler argument).\n * @param eventName - Name of the event\n */\n once<T = unknown>(eventName: string): Promise<T>;\n once<T = unknown>(\n eventName: string,\n handler?: EventHandler<T>,\n ): void | Promise<T> {\n if (handler !== undefined) {\n // Callback form: fire-and-forget, returns void\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n handler(data);\n });\n } else {\n // Promise form: resolves on first emission\n return new Promise<T>((resolve) => {\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n resolve(data);\n });\n });\n }\n }\n\n /**\n * Get a list of all active event names with registered handlers.\n */\n getActiveEvents(): string[] {\n return Object.keys(this.handlers).filter(\n (eventName) =>\n this.handlers[eventName] && this.handlers[eventName].size > 0,\n );\n }\n\n /**\n * Clear all event handlers and native EventTarget listeners (useful for testing or cleanup).\n */\n clear(): void {\n this.handlers = {};\n const toCleanup = Array.from(this.nativeUnsubscribers.keys());\n this.nativeUnsubscribers.clear();\n for (const unsubscribe of toCleanup) {\n unsubscribe();\n }\n }\n\n /**\n * Get the number of handlers registered for a specific event.\n * @param eventName - Name of the event\n */\n getHandlerCount(eventName: string): number {\n return this.handlers[eventName]?.size || 0;\n }\n\n /**\n * Get event statistics for debugging.\n */\n getEventStats(): Record<string, { count: number; handlersCount: number }> {\n const stats: Record<string, { count: number; handlersCount: number }> = {};\n for (const [eventName, counter] of this.eventCounters.entries()) {\n stats[eventName] = {\n count: counter.count,\n handlersCount: this.getHandlerCount(eventName),\n };\n }\n return stats;\n }\n\n /**\n * Reset event counters (useful for testing or after resolving issues).\n */\n resetEventCounters(): void {\n this.eventCounters.clear();\n }\n}\n\n/**\n * Singleton instance of the global event bus\n */\n/**\n * Lazily-instantiated event bus.\n *\n * We preserve the `eventBus` export for backward compatibility but avoid\n * creating the underlying GlobalEventBus instance at module import time.\n * A small proxy defers the call to `GlobalEventBus.getInstance()` until a\n * property is accessed. This reduces import-time side-effects and helps\n * bundlers tree-shake unused entrypoints.\n */\nexport const eventBus = new Proxy(\n {},\n {\n get(_target, prop: PropertyKey) {\n const inst = GlobalEventBus.getInstance();\n const val = (inst as unknown as Record<PropertyKey, unknown>)[prop];\n // If the property is a function (method), bind it to the instance\n // so callers using `eventBus.method(...)` get the correct `this`.\n if (typeof val === 'function')\n return (val as (...args: unknown[]) => unknown).bind(inst);\n return val;\n },\n apply() {\n throw new TypeError('eventBus is not a callable function');\n },\n },\n) as unknown as GlobalEventBus;\n\n/**\n * Emit a global event\n */\nexport const emit = <T = unknown>(eventName: string, data?: T) =>\n eventBus.emit(eventName, data);\n\n/**\n * Register a handler for a global event\n */\nexport const on = <T = unknown>(eventName: string, handler: EventHandler<T>) =>\n eventBus.on(eventName, handler);\n\n/**\n * Remove a handler for a global event\n */\nexport const off = <T = unknown>(eventName: string, handler: EventHandler<T>) =>\n eventBus.off(eventName, handler);\n\n/**\n * Register a one-time handler for a global event (callback form).\n * The handler fires once then auto-unsubscribes.\n */\nexport function once<T = unknown>(\n eventName: string,\n handler: EventHandler<T>,\n): void;\n/**\n * Returns a Promise that resolves with the next emission of the event\n * (Promise form — no handler argument needed).\n */\nexport function once<T = unknown>(eventName: string): Promise<T>;\nexport function once<T = unknown>(\n eventName: string,\n handler?: EventHandler<T>,\n): void | Promise<T> {\n if (handler !== undefined) {\n return eventBus.once(eventName, handler);\n }\n return eventBus.once<T>(eventName);\n}\n\n/**\n * Listen for a native CustomEvent\n */\nexport const listen = <T = unknown>(\n eventName: string,\n handler: (event: CustomEvent<T>) => void,\n options?: AddEventListenerOptions,\n) => eventBus.listen(eventName, handler, options);\n"],"names":["GlobalEventBus","eventName","data","now","counter","firstKey","devError","eventHandlers","handler","error","options","unsubscribe","resolve","toCleanup","stats","eventBus","_target","prop","inst","val","emit","on","off","once","listen"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./helpers-DeWjSmOl.cjs"),r=require("./hooks-BrrLKSub.cjs"),e=require("./style-D40DsIqJ.cjs");function a(s){if(o.isDiscoveryRender())return;const t=r.getCurrentComponentContext()?._host?.shadowRoot??null;t?e.registerJITCSSComponent(t,s):e.enableJITCSS(s)}function n(s){return s}exports.useDesignTokens=r.useDesignTokens;exports.useGlobalStyle=r.useGlobalStyle;exports.colors=e.colors;exports.containerVariants=e.containerVariants;exports.disableJITCSS=e.disableJITCSS;exports.enableJITCSS=e.enableJITCSS;exports.extractClassesFromHTML=e.extractClassesFromHTML;exports.getJITCSSOptions=e.getJITCSSOptions;exports.isJITCSSEnabled=e.isJITCSSEnabled;exports.isJITCSSEnabledFor=e.isJITCSSEnabledFor;exports.jitCSS=e.jitCSS;exports.mediaVariants=e.mediaVariants;exports.parseArbitrary=e.parseArbitrary;exports.parseColorClass=e.parseColorClass;exports.parseColorWithOpacity=e.parseColorWithOpacity;exports.parseGradientColorStop=e.parseGradientColorStop;exports.parseSpacing=e.parseSpacing;exports.registerJITCSSComponent=e.registerJITCSSComponent;exports.selectorVariants=e.selectorVariants;exports.utilityMap=e.utilityMap;exports.cls=n;exports.useJITCSS=a;
2
+ //# sourceMappingURL=custom-elements-runtime.jit-css.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-elements-runtime.jit-css.cjs.js","sources":["../src/lib/runtime/jit-hooks.ts","../src/lib/jit-css.ts"],"sourcesContent":["/**\n * JIT CSS hooks — lives in a separate module so that hooks.ts does not\n * statically import style.ts. Consumers who never call `useJITCSS` will\n * have the entire JIT engine tree-shaken out of their bundle.\n */\n\nimport { isDiscoveryRender as _isDiscoveryRenderFn } from './discovery-state';\nimport { getCurrentComponentContext } from './hooks';\nimport {\n enableJITCSS,\n registerJITCSSComponent,\n type JITCSSOptions,\n} from './style';\n\n/**\n * Configure the JIT CSS engine for the current session.\n * This is a convenience wrapper around `enableJITCSS()` that can be called\n * inside a component render function or at module initialisation time.\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * // Enable extended Tailwind colors so bg-blue-500, text-violet-700, etc. generate CSS\n * useJITCSS({ extendedColors: true });\n * return html`<div class=\"bg-blue-500 text-white\">Hello</div>`;\n * });\n * ```\n *\n * @example\n * ```ts\n * // At app entry – enable once for all components\n * useJITCSS({ extendedColors: true, customColors: { brand: { '500': '#e63946' } } });\n * ```\n */\nexport function useJITCSS(options?: JITCSSOptions): void {\n // During discovery renders (component registration phase) there is no real\n // shadow root. Without this guard, useJITCSS() falls through to\n // enableJITCSS() and globally enables JIT CSS for every component — exactly\n // the opt-in behaviour we are trying to prevent.\n if (_isDiscoveryRenderFn()) return;\n\n // When called inside a component render function, register this component's\n // shadow root for per-component JIT CSS opt-in. Context is always set during\n // a real render; it may be absent (null) or missing _host when called at app\n // startup level (outside any component context).\n const host = (getCurrentComponentContext() as { _host?: Element } | null)\n ?._host;\n const shadowRoot = host?.shadowRoot ?? null;\n\n if (shadowRoot) {\n // Per-component opt-in: register this shadow root only.\n registerJITCSSComponent(shadowRoot, options);\n } else {\n // App-level call (outside component context) — enable for all components\n // globally, preserving v2 behaviour when called at the entry point.\n enableJITCSS(options);\n }\n}\n\nexport type { JITCSSOptions };\n","/**\n * JIT CSS entry point — opt-in import for the full JIT CSS engine.\n *\n * @example\n * ```ts\n * import {\n * useJITCSS,\n * enableJITCSS,\n * } from '@jasonshimmy/custom-elements-runtime/jit-css';\n * ```\n */\n\n// Hooks\nexport { useJITCSS } from './runtime/jit-hooks';\nexport { useDesignTokens, useGlobalStyle } from './runtime/hooks';\nexport type { JITCSSOptions, DesignTokens } from './runtime/hooks';\n\n// Global configuration\nexport {\n enableJITCSS,\n disableJITCSS,\n isJITCSSEnabled,\n isJITCSSEnabledFor,\n registerJITCSSComponent,\n getJITCSSOptions,\n jitCSS,\n extractClassesFromHTML,\n parseColorClass,\n parseColorWithOpacity,\n parseGradientColorStop,\n parseSpacing,\n parseArbitrary,\n utilityMap,\n selectorVariants,\n mediaVariants,\n containerVariants,\n colors,\n} from './runtime/style';\n\n/**\n * A no-op identity function that signals to development tools (IDE\n * autocomplete, linters, PurgeCSS-style scanners) that the string contains\n * JIT CSS utility class names.\n *\n * At runtime this is simply `return className` — zero overhead.\n *\n * @example\n * ```ts\n * import { cls } from '@jasonshimmy/custom-elements-runtime/jit-css';\n *\n * const containerClasses = cls('flex items-center gap-4 bg-primary-500 text-white');\n * ```\n */\nexport function cls(className: string): string {\n return className;\n}\n"],"names":["useJITCSS","options","_isDiscoveryRenderFn","shadowRoot","getCurrentComponentContext","registerJITCSSComponent","enableJITCSS","cls","className"],"mappings":"8LAkCO,SAASA,EAAUC,EAA+B,CAKvD,GAAIC,EAAAA,oBAAwB,OAQ5B,MAAMC,EAFQC,EAAAA,8BACV,OACqB,YAAc,KAEnCD,EAEFE,EAAAA,wBAAwBF,EAAYF,CAAO,EAI3CK,EAAAA,aAAaL,CAAO,CAExB,CCJO,SAASM,EAAIC,EAA2B,CAC7C,OAAOA,CACT"}
@@ -0,0 +1,38 @@
1
+ import { A as o } from "./helpers-CweFZFWU.js";
2
+ import { g as r } from "./hooks-DyShDHKo.js";
3
+ import { f, j as u } from "./hooks-DyShDHKo.js";
4
+ import { r as e, e as t } from "./style-BmyOIMcU.js";
5
+ import { c as T, a as b, d as g, b as h, g as I, i as J, f as x, j as y, m as j, p as R, h as V, k, l as w, n as A, s as D, u as E } from "./style-BmyOIMcU.js";
6
+ function p(s) {
7
+ if (o()) return;
8
+ const a = r()?._host?.shadowRoot ?? null;
9
+ a ? e(a, s) : t(s);
10
+ }
11
+ function C(s) {
12
+ return s;
13
+ }
14
+ export {
15
+ C as cls,
16
+ T as colors,
17
+ b as containerVariants,
18
+ g as disableJITCSS,
19
+ t as enableJITCSS,
20
+ h as extractClassesFromHTML,
21
+ I as getJITCSSOptions,
22
+ J as isJITCSSEnabled,
23
+ x as isJITCSSEnabledFor,
24
+ y as jitCSS,
25
+ j as mediaVariants,
26
+ R as parseArbitrary,
27
+ V as parseColorClass,
28
+ k as parseColorWithOpacity,
29
+ w as parseGradientColorStop,
30
+ A as parseSpacing,
31
+ e as registerJITCSSComponent,
32
+ D as selectorVariants,
33
+ f as useDesignTokens,
34
+ u as useGlobalStyle,
35
+ p as useJITCSS,
36
+ E as utilityMap
37
+ };
38
+ //# sourceMappingURL=custom-elements-runtime.jit-css.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-elements-runtime.jit-css.es.js","sources":["../src/lib/runtime/jit-hooks.ts","../src/lib/jit-css.ts"],"sourcesContent":["/**\n * JIT CSS hooks — lives in a separate module so that hooks.ts does not\n * statically import style.ts. Consumers who never call `useJITCSS` will\n * have the entire JIT engine tree-shaken out of their bundle.\n */\n\nimport { isDiscoveryRender as _isDiscoveryRenderFn } from './discovery-state';\nimport { getCurrentComponentContext } from './hooks';\nimport {\n enableJITCSS,\n registerJITCSSComponent,\n type JITCSSOptions,\n} from './style';\n\n/**\n * Configure the JIT CSS engine for the current session.\n * This is a convenience wrapper around `enableJITCSS()` that can be called\n * inside a component render function or at module initialisation time.\n *\n * @example\n * ```ts\n * component('my-component', () => {\n * // Enable extended Tailwind colors so bg-blue-500, text-violet-700, etc. generate CSS\n * useJITCSS({ extendedColors: true });\n * return html`<div class=\"bg-blue-500 text-white\">Hello</div>`;\n * });\n * ```\n *\n * @example\n * ```ts\n * // At app entry – enable once for all components\n * useJITCSS({ extendedColors: true, customColors: { brand: { '500': '#e63946' } } });\n * ```\n */\nexport function useJITCSS(options?: JITCSSOptions): void {\n // During discovery renders (component registration phase) there is no real\n // shadow root. Without this guard, useJITCSS() falls through to\n // enableJITCSS() and globally enables JIT CSS for every component — exactly\n // the opt-in behaviour we are trying to prevent.\n if (_isDiscoveryRenderFn()) return;\n\n // When called inside a component render function, register this component's\n // shadow root for per-component JIT CSS opt-in. Context is always set during\n // a real render; it may be absent (null) or missing _host when called at app\n // startup level (outside any component context).\n const host = (getCurrentComponentContext() as { _host?: Element } | null)\n ?._host;\n const shadowRoot = host?.shadowRoot ?? null;\n\n if (shadowRoot) {\n // Per-component opt-in: register this shadow root only.\n registerJITCSSComponent(shadowRoot, options);\n } else {\n // App-level call (outside component context) — enable for all components\n // globally, preserving v2 behaviour when called at the entry point.\n enableJITCSS(options);\n }\n}\n\nexport type { JITCSSOptions };\n","/**\n * JIT CSS entry point — opt-in import for the full JIT CSS engine.\n *\n * @example\n * ```ts\n * import {\n * useJITCSS,\n * enableJITCSS,\n * } from '@jasonshimmy/custom-elements-runtime/jit-css';\n * ```\n */\n\n// Hooks\nexport { useJITCSS } from './runtime/jit-hooks';\nexport { useDesignTokens, useGlobalStyle } from './runtime/hooks';\nexport type { JITCSSOptions, DesignTokens } from './runtime/hooks';\n\n// Global configuration\nexport {\n enableJITCSS,\n disableJITCSS,\n isJITCSSEnabled,\n isJITCSSEnabledFor,\n registerJITCSSComponent,\n getJITCSSOptions,\n jitCSS,\n extractClassesFromHTML,\n parseColorClass,\n parseColorWithOpacity,\n parseGradientColorStop,\n parseSpacing,\n parseArbitrary,\n utilityMap,\n selectorVariants,\n mediaVariants,\n containerVariants,\n colors,\n} from './runtime/style';\n\n/**\n * A no-op identity function that signals to development tools (IDE\n * autocomplete, linters, PurgeCSS-style scanners) that the string contains\n * JIT CSS utility class names.\n *\n * At runtime this is simply `return className` — zero overhead.\n *\n * @example\n * ```ts\n * import { cls } from '@jasonshimmy/custom-elements-runtime/jit-css';\n *\n * const containerClasses = cls('flex items-center gap-4 bg-primary-500 text-white');\n * ```\n */\nexport function cls(className: string): string {\n return className;\n}\n"],"names":["useJITCSS","options","_isDiscoveryRenderFn","shadowRoot","getCurrentComponentContext","registerJITCSSComponent","enableJITCSS","cls","className"],"mappings":";;;;;AAkCO,SAASA,EAAUC,GAA+B;AAKvD,MAAIC,IAAwB;AAQ5B,QAAMC,IAFQC,KACV,OACqB,cAAc;AAEvC,EAAID,IAEFE,EAAwBF,GAAYF,CAAO,IAI3CK,EAAaL,CAAO;AAExB;ACJO,SAASM,EAAIC,GAA2B;AAC7C,SAAOA;AACT;"}
@@ -1,31 +1,31 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./logger-CSALKaYm.cjs"),$=require("./namespace-helpers-Ctd_h7j2.cjs"),x=require("./template-compiler-bj-MFC_Y.cjs"),ot=require("./custom-elements-runtime.store.cjs.js"),bt=require("./custom-elements-runtime.directives.cjs.js"),rt={enabled:!0,offset:0,timeoutMs:2e3},tt=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},ft=t=>{if(!t||Object.keys(t).length===0)return"";try{return"?"+new URLSearchParams(t).toString()}catch{return""}},nt=t=>t?/^\s*javascript\s*:/i.test(t):!1,U=t=>/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t)||t.startsWith("//"),dt=t=>{try{return decodeURIComponent(t)}catch{return t}};function A(t){if(!t)return"/";let r=t.replace(/\/+/g,"/");return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r}const ht=t=>{if(!t)return"";const r=A(t);return r==="/"?"":r},st=new WeakMap;function wt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function St(t){const r=t.path||"/",v=A(r),a=v==="/"?[]:v.split("/").filter(Boolean),l=[],o=[];for(let u=0;u<a.length;u++){const f=a[u];if(f==="*"){if(u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const W=`splat${l.length}`;l.push(W),o.push("__SPLAT__");continue}const y=f.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(y){const W=y[1],k=!!y[2];if(k&&u!==a.length-1)return c.devWarn(`Route '${t.path}' contains a splat param ':${W}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};l.push(W),o.push(k?"__SPLAT__":"([^/]+)");continue}o.push(wt(f))}let b;if(o.length===0)b="^/$";else if(o[o.length-1]==="__SPLAT__"){const f=o.slice(0,-1).join("/");f?b=`^/${f}(?:/(.*))?(?:/)?$`:b="^(?:/(.*))?(?:/)?$"}else b=`^/${o.join("/")}(?:/)?$`;try{return{regex:new RegExp(b),paramNames:l}}catch(u){return c.devWarn(`Failed to compile route regex for '${t.path}': ${String(u)}`),{invalid:!0}}}const F=(t,r)=>{const v=A(r);for(const a of t){let l=st.get(a);if(l||(l=St(a),st.set(a,l)),l.invalid)continue;const{regex:o,paramNames:b}=l,u=o.exec(v);if(u){const f={};for(let y=0;y<b.length;y++){const W=u[y+1]||"";f[b[y]]=W?dt(W):""}return{route:a,params:f}}}return{route:null,params:{}}};function Z(t,r){for(const v of t)if(F([v],r).route!==null)return v;return null}function Rt(t,r){return F(t,r)}const ct=50;let G={},L={};function pt(){G={},L={}}function Et(){const t=Object.entries(G);if(t.length<=ct)return;const v=t.sort(([,a],[,l])=>a.lastAccessed-l.lastAccessed).slice(0,t.length-ct);for(const[a]of v)delete G[a]}async function yt(t){if(t.component)return t.component;if(t.load){const r=G[t.path];if(r)return r.lastAccessed=Date.now(),r.component;if(L[t.path]!==void 0)return L[t.path];const v=typeof window>"u";try{const a=t.load().then(l=>{Et();const o=l.default;return G[t.path]={component:o,lastAccessed:Date.now()},delete L[t.path],o}).catch(l=>{delete L[t.path];const o=l instanceof Error?l.message:String(l);throw v&&c.devError(`SSR component load failed for route: ${t.path}. ${o}`),new Error(`Failed to load component for route: ${t.path}. ${o}`)});return L[t.path]=a,await a}catch(a){const l=a instanceof Error?a.message:String(a);throw new Error(`Failed to load component for route: ${t.path}. ${l}`,{cause:a})}}throw new Error(`No component or loader defined for route: ${t.path}`)}let g=null;function $t(t){g=t}function it(){return g}const j=new Set;let N=null;function mt(){if(N){try{N()}catch{}N=null}if(g)try{let t=!1;N=g.subscribe(r=>{t=!0;for(const v of j)try{v(r)}catch{}});try{C.base=g.base}catch{}if(t){const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}else{const r=g.getCurrent();for(const v of j)try{v(r)}catch{}}try{typeof window<"u"&&$.flushDOMUpdates()}catch{}}catch{N=null}}function Ct(){mt()}const C={store:{subscribe(t){if(g)return g.store.subscribe(t);try{t({path:"/",params:{},query:{}})}catch{}return()=>{}},getState(){return g?g.getCurrent():{path:"/",params:{},query:{}}},setState(t){if(g)try{g.store.setState(t)}catch{}}},subscribe(t){if(typeof t!="function")return c.devWarn("activeRouterProxy.subscribe: listener must be a function"),()=>{};if(j.add(t),g)if(!N)mt();else try{const r=g.getCurrent();r&&t(r)}catch(r){c.devWarn("activeRouterProxy subscription failed",r)}else try{t({path:"/",params:{},query:{}})}catch(r){c.devWarn("activeRouterProxy fallback state delivery failed",r)}return()=>{try{if(j.delete(t),j.size===0&&N){try{N()}catch(r){c.devWarn("activeRouterProxy inner unsubscribe failed",r)}N=null}}catch(r){c.devWarn("activeRouterProxy unsubscribe failed",r)}}},getCurrent(){return g?g.getCurrent():{path:"/",params:{},query:{}}},async push(t){return g?g.push(t):Promise.resolve()},async replace(t){return g?g.replace(t):Promise.resolve()},back(){if(g)return g.back()},matchRoute(t){return g?g.matchRoute(t):{route:null,params:{}}},resolveRouteComponent(t){return g?g.resolveRouteComponent(t):Promise.reject(new Error("No active router"))},base:"",scrollToFragment(t){return g?g.scrollToFragment(t):Promise.resolve(!1)}};function vt(t){const{routes:r,base:v="",initialUrl:a,scrollToFragment:l=!0}=t,o=ht(v),b=typeof l=="boolean"?{...rt,enabled:l}:{...rt,...l};let u,f,y,W,k,z,B;const _=new Set,K=10;let q=0;const J=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.beforeEnter)return!0;try{const n=await e.beforeEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("beforeEnter error",n);try{y.setState(i)}catch{}throw n}},X=async(s,i)=>{const e=Z(r,s.path);if(!e||!e.onEnter)return!0;try{const n=await e.onEnter(s,i);if(typeof n=="string"){const p=`${s.path}->${n}`;return _.has(p)||q>=K?(c.devError(`Redirect loop detected: ${p}`),!1):n}return n!==!1}catch(n){c.devError("onEnter error",n);try{y.setState(i)}catch{}throw n}},et=(s,i)=>{const e=Z(r,s.path);if(!(!e||!e.afterEnter))try{e.afterEnter(s,i)}catch(n){c.devError("afterEnter error",n)}},I=new Map,M=100,T=s=>{if(I.has(s))return I.get(s);const i=F(r,s);if(I.size>=M){const e=Math.floor(M*.25),n=Array.from(I.keys());for(let p=0;p<e&&p<n.length;p++)I.delete(n[p])}return I.set(s,i),i},Y=()=>{};async function V(s,i=0){try{const e=document.getElementById(s);if(!e)return!1;if(i>0)try{const n=e.getBoundingClientRect(),p=Math.max(0,window.scrollY+n.top-i);typeof window.scrollTo=="function"&&window.scrollTo({top:p,behavior:"auto"})}catch{try{e.scrollIntoView()}catch{return!1}}else if(typeof e.scrollIntoView=="function")try{e.scrollIntoView({behavior:"auto",block:"start",inline:"nearest"})}catch{try{e.scrollIntoView()}catch{return!1}}return!0}catch{return!1}}function h(s,i=0,e=2e3){return new Promise(n=>{let p=!1,m=null;const w=Date.now(),S=P=>{p||(p=!0,m&&clearTimeout(m),n(P))},E=async()=>{if(!p)try{if(await V(s,i))return S(!0);const P=async()=>{if(p)return;if(Date.now()-w>=e)return S(!1);try{if(await V(s,i))return S(!0);requestAnimationFrame(P)}catch(gt){c.devWarn("Scroll retry attempt failed:",gt),requestAnimationFrame(P)}};requestAnimationFrame(P)}catch(P){c.devWarn("Initial scroll attempt failed:",P),S(!1)}};m=setTimeout(()=>{S(!1)},e),E().catch(P=>{c.devWarn("Scroll attempt failed:",P),S(!1)})})}let R=!1;const d=async(s,i=!1)=>{if(R){c.devWarn(`Navigation to ${s} blocked - navigation already in progress`);return}R=!0,q=0,_.clear();try{await D(s,i)}finally{R=!1,q=0,_.clear()}},O=s=>{const i=s.indexOf("#"),e=i>=0?s.slice(i+1):"",n=i>=0?s.slice(0,i):s,p=n.indexOf("?"),m=p>=0?n.slice(0,p):n,w=p>=0?tt(n.slice(p)):{},S=m.startsWith(o)?m.slice(o.length):m;return{path:A(S||"/"),query:w,fragment:e}},D=async(s,i=!1)=>{try{const e=O(s),n=T(e.path);if(!n.route)throw new Error(`No route found for ${e.path}`);const p=y.getState(),m={path:e.path,params:n.params,query:e.query,fragment:e.fragment},w=await J(m,p);if(w===!1)return;if(typeof w=="string"){q++;const E=`${m.path}->${w}`;_.add(E),await D(w,!0);return}const S=await X(m,p);if(S===!1)return;if(typeof S=="string"){q++;const E=`${m.path}->${S}`;_.add(E),await D(S,!0);return}if(typeof window<"u"&&typeof document<"u"){const E=ft(e.query),P=o+e.path+(E||"")+(e.fragment?"#"+e.fragment:"");i?window.history.replaceState({},"",P):window.history.pushState({},"",P)}if(y.setState(m),et(m,p),typeof window<"u"&&typeof document<"u")try{const E=m.fragment;b.enabled&&E&&h(String(E),b.offset,b.timeoutMs).catch(()=>{})}catch{}}catch(e){if(c.devError("Navigation error:",e),e instanceof Error&&(e.stack?.includes("runBeforeEnter")||e.stack?.includes("runOnEnter")))throw e;try{const n=y.getState();if(!F(r,n.path).route){let m=r.find(w=>w.path==="/");if(m||(m=r.find(w=>!w.path.includes(":")&&!w.path.includes("*"))),!m&&r.length>0&&(m=r[0]),m){const w=F(r,m.path);y.setState({path:m.path,params:w.params,query:{}})}else c.devError("No fallback route available for error recovery")}}catch(n){c.devWarn("State recovery failed during navigation error:",n)}}};if((s=>{if(!s||s.length===0)return c.devError("Router configuration error: No routes provided"),!1;const i=new Set;for(const e of s){if(!e.path)return c.devError("Router configuration error: Route missing path",e),!1;i.has(e.path)&&c.devWarn(`Duplicate route path detected: ${e.path}`),i.add(e.path),!e.component&&!e.load&&c.devWarn(`Route '${e.path}' has no component or load function`)}return!0})(r),typeof window>"u"||typeof a<"u"){for(const s of r)T(s.path);c.devWarn(`Pre-compiled ${r.length} routes for SSR`)}if(typeof window<"u"&&typeof document<"u"&&typeof a>"u"){u=()=>{try{const e=new URL(window.location.href),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async(e=!1)=>{const n=u();await d(n.path,e)};const i=()=>W(!0);window.addEventListener("popstate",i),k=e=>d(e,!1),z=e=>d(e,!0),B=()=>window.history.back()}else{u=()=>{try{const e=new URL(a||"/","http://localhost"),n=e.pathname,p=n.startsWith(o)?n.slice(o.length):n,m=A(p||"/"),w=tt(e.search),S=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:m,query:w,fragment:S}}catch(e){return c.devWarn("Invalid SSR URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},f=u();const s=T(f.path);y=ot.createStore({path:f.path,params:s.params,query:f.query,fragment:f.fragment}),W=async()=>{const e=u();await i(e.path)};const i=async e=>{if(q++,q>K){c.devError(`SSR redirect depth exceeded for path: ${e}`);return}try{const n=O(e),p=T(n.path);if(!p.route)throw new Error(`No route found for ${n.path}`);const m=y.getState(),w={path:n.path,params:p.params,query:n.query,fragment:n.fragment},S=Z(r,w.path);if(S?.beforeEnter){const E=await S.beforeEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}if(S?.onEnter){const E=await S.onEnter(w,m);if(typeof E=="string"){const P=`${w.path}->${E}`;_.add(P),await i(E);return}if(E===!1)return}y.setState(w),S?.afterEnter&&S.afterEnter(w,m)}catch(n){throw c.devError("SSR navigation error:",n),n}};k=async e=>(q=0,_.clear(),i(e)),z=async e=>(q=0,_.clear(),i(e)),B=()=>{}}return{_cleanupScrollState:Y,store:y,push:k,replace:z,back:B,subscribe:y.subscribe,matchRoute:s=>T(s),getCurrent:()=>y.getState(),resolveRouteComponent:yt,base:o,scrollToFragment:s=>{const i=s||y.getState().fragment;return!i||typeof window>"u"||typeof document>"u"?Promise.resolve(!1):h(i,b.offset,b.timeoutMs)}}}function At(t){pt();const r=vt(t),v=it();if(v)try{v._cleanupScrollState?.()}catch{}$t(r);try{Ct();try{typeof window<"u"&&$.flushDOMUpdates()}catch{}try{typeof window<"u"&&queueMicrotask(()=>{try{$.flushDOMUpdates()}catch{}})}catch{}}catch{}return x.component("router-view",async()=>{if(!it())return x.html`<div>Router not initialized.</div>`;const a=$.ref(C.getCurrent()),l=typeof window>"u";let o;l||(x.useOnConnected(()=>{try{typeof C.subscribe=="function"&&(o=C.subscribe(u=>{try{u&&typeof u=="object"&&typeof u.path=="string"?a.value=u:(c.devWarn("router-view received invalid state",u),a.value={path:"/",params:{},query:{}})}catch(f){c.devWarn("router-view subscription update failed",f);try{a.value={path:"/",params:{},query:{}}}catch{}}}))}catch(u){c.devWarn("router-view subscribe failed",u)}}),x.useOnDisconnected(()=>{if(typeof o=="function"){try{o()}catch(u){c.devWarn("router-view unsubscribe failed",u)}o=void 0}}));const b=C.matchRoute(a.value.path);if(!b||!b.route)return x.html`<div>Not found</div>`;try{const f=await C.resolveRouteComponent(b.route);if(typeof f=="string")return{tag:f,props:{},children:[]};if(typeof f=="function"){const y=f();return(y instanceof Promise?y:Promise.resolve(y)).then(k=>typeof k=="string"?{tag:k,props:{},children:[]}:k)}return x.html`<div>Invalid route component</div>`}catch{return x.html`<div>Invalid route component</div>`}}),x.component("router-link",()=>{const a=x.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),l=typeof window>"u",o=$.ref(C.getCurrent()),b=o.value?.path||"/",u=String(a.to||""),f=l?{isExactActive:lt(b,u,C.base),isActive:ut(b,u,C.base),isExternal:U(u)||!!a.external}:null;let y;x.useStyle(()=>"a,button{display:inline-block;}");const W=$.ref(a.class||""),k=$.ref(a.style||"");if(!l){let h=null;x.useOnConnected(R=>{try{if(typeof C.subscribe=="function"){y=C.subscribe(d=>{try{d&&typeof d=="object"&&typeof d.path=="string"?o.value=d:(c.devWarn("router-link received invalid state",d),o.value={path:"/",params:{},query:{}})}catch(O){c.devWarn("router-link subscription update failed",O);try{o.value={path:"/",params:{},query:{}}}catch{}}});try{const d=C.getCurrent();d&&typeof d.path=="string"&&(o.value=d)}catch(d){c.devWarn("router-link initial state sync failed",d)}h=setInterval(()=>{try{const d=C.getCurrent();d&&typeof d.path=="string"&&JSON.stringify(o.value)!==JSON.stringify(d)&&(o.value=d)}catch{}},100)}}catch(d){c.devWarn("router-link subscribe failed",d)}try{const d=R?._host;if(d instanceof HTMLElement){const O=d.getAttribute("class"),D=d.getAttribute("style");O&&(W.value=O),D&&(k.value=D),O!==null&&d.removeAttribute("class"),D!==null&&d.removeAttribute("style");try{R?._requestRender?.();try{$.flushDOMUpdates()}catch{}}catch{}}}catch(d){c.devWarn("router-link host migration failed",d)}}),x.useOnDisconnected(()=>{if(typeof y=="function")try{y()}catch(R){c.devWarn("router-link unsubscribe failed",R)}finally{y=void 0}if(h)try{clearInterval(h)}catch(R){c.devWarn("router-link sync interval cleanup failed",R)}finally{h=null}})}const z=$.computed(()=>{if(l&&f)return f.isExactActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:lt(o.value.path,R,h)}catch(h){return c.devWarn("isExactActive computation error",h),!1}}),B=$.computed(()=>{if(l&&f)return f.isActive;try{const h=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:a.exact?z.value:ut(o.value.path,R,h)}catch(h){return c.devWarn("isActive computation error",h),!1}}),_=$.computed(()=>{const h=String(a.to||"");if(nt(h))return null;if(U(h))return h;const[R,d]=h.split("#"),[O,D]=(R||"").split("?"),H=C.base??"";let Q=O||"/";if(H&&H!=="/"){const s=A(H),i=A(Q);i.startsWith(s)?Q=i.slice(s.length)||"/":Q=i}const at=A(Q||"/");return H+at+(D?"?"+D:"")+(d?"#"+d:"")}),K=$.computed(()=>{const R=(W&&W.value||a.class||"").split(/\s+/).filter(Boolean),d={};for(const O of R)d[O]=!0;return d}),q=$.computed(()=>({...K.value,[a.activeClass||"active"]:B.value,[a.exactActiveClass||"exact-active"]:z.value})),J=$.computed(()=>Object.keys(q.value).filter(h=>q.value[h]).join(" ")),X=$.computed(()=>a.tag||"a"),et=$.computed(()=>X.value==="button"),I=$.computed(()=>z.value?a.ariaCurrentValue:null),M=$.computed(()=>!!a.disabled),T=$.computed(()=>{const h=String(a.to||"");return(U(h)||!!a.external)&&X.value==="a"}),Y=$.computed(()=>k&&k.value||a.style||""),V=h=>{if(h.defaultPrevented||h.button!==0||h.metaKey||h.altKey||h.ctrlKey||h.shiftKey)return;if(M.value){h.preventDefault();return}const R=String(a.to||"");if(nt(R)){try{h.preventDefault()}catch{}c.devWarn("Blocked unsafe javascript: URI in router-link.to");return}T.value||(h.preventDefault(),a.replace?C.replace(a.to):C.push(a.to))};return x.html`
2
- ${bt.match().when(et.value,x.html`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./logger-CSALKaYm.cjs"),E=require("./helpers-DeWjSmOl.cjs"),D=require("./template-compiler-Cx623BSB.cjs"),j=require("./hooks-BrrLKSub.cjs"),it=require("./custom-elements-runtime.store.cjs.js"),Rt=require("./custom-elements-runtime.directives.cjs.js"),ot={enabled:!0,offset:0,timeoutMs:2e3},rt=t=>t?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(t)):{},pt=t=>{if(!t||Object.keys(t).length===0)return"";try{return"?"+new URLSearchParams(t).toString()}catch{return""}},st=t=>t?/^\s*javascript\s*:/i.test(t):!1,K=t=>/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(t)||t.startsWith("//"),yt=t=>{try{return decodeURIComponent(t)}catch{return t}};function A(t){if(!t)return"/";let r=t.replace(/\/+/g,"/");return r.startsWith("/")||(r="/"+r),r.length>1&&r.endsWith("/")&&(r=r.slice(0,-1)),r}const mt=t=>{if(!t)return"";const r=A(t);return r==="/"?"":r},lt=new WeakMap;function Et(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $t(t){const r=t.path||"/",v=A(r),a=v==="/"?[]:v.split("/").filter(Boolean),i=[],o=[];for(let l=0;l<a.length;l++){const u=a[l];if(u==="*"){if(l!==a.length-1)return c.devWarn(`Route '${t.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const P=`splat${i.length}`;i.push(P),o.push("__SPLAT__");continue}const y=u.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(y){const P=y[1],W=!!y[2];if(W&&l!==a.length-1)return c.devWarn(`Route '${t.path}' contains a splat param ':${P}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};i.push(P),o.push(W?"__SPLAT__":"([^/]+)");continue}o.push(Et(u))}let w;if(o.length===0)w="^/$";else if(o[o.length-1]==="__SPLAT__"){const u=o.slice(0,-1).join("/");u?w=`^/${u}(?:/(.*))?(?:/)?$`:w="^(?:/(.*))?(?:/)?$"}else w=`^/${o.join("/")}(?:/)?$`;try{return{regex:new RegExp(w),paramNames:i}}catch(l){return c.devWarn(`Failed to compile route regex for '${t.path}': ${String(l)}`),{invalid:!0}}}const V=(t,r)=>{const v=A(r);for(const a of t){let i=lt.get(a);if(i||(i=$t(a),lt.set(a,i)),i.invalid)continue;const{regex:o,paramNames:w}=i,l=o.exec(v);if(l){const u={};for(let y=0;y<w.length;y++){const P=l[y+1]||"";u[w[y]]=P?yt(P):""}return{route:a,params:u}}}return{route:null,params:{}}};function G(t,r){for(const v of t)if(V([v],r).route!==null)return v;return null}function Ct(t,r){return V(t,r)}const ut=50;let J={},B={};function vt(){J={},B={}}function At(){const t=Object.entries(J);if(t.length<=ut)return;const v=t.sort(([,a],[,i])=>a.lastAccessed-i.lastAccessed).slice(0,t.length-ut);for(const[a]of v)delete J[a]}async function gt(t){if(t.component)return t.component;if(t.load){const r=J[t.path];if(r)return r.lastAccessed=Date.now(),r.component;if(B[t.path]!==void 0)return B[t.path];const v=typeof window>"u";try{const a=t.load().then(i=>{At();const o=i.default;return J[t.path]={component:o,lastAccessed:Date.now()},delete B[t.path],o}).catch(i=>{delete B[t.path];const o=i instanceof Error?i.message:String(i);throw v&&c.devError(`SSR component load failed for route: ${t.path}. ${o}`),new Error(`Failed to load component for route: ${t.path}. ${o}`)});return B[t.path]=a,await a}catch(a){const i=a instanceof Error?a.message:String(a);throw new Error(`Failed to load component for route: ${t.path}. ${i}`,{cause:a})}}throw new Error(`No component or loader defined for route: ${t.path}`)}let m=null;function Pt(t){m=t}function ft(){return m}const H=new Set;let I=null;function bt(){if(I){try{I()}catch{}I=null}if(m)try{let t=!1;I=m.subscribe(r=>{t=!0;for(const v of H)try{v(r)}catch{}});try{C.base=m.base}catch{}if(t){const r=m.getCurrent();for(const v of H)try{v(r)}catch{}}else{const r=m.getCurrent();for(const v of H)try{v(r)}catch{}}try{typeof window<"u"&&E.flushDOMUpdates()}catch{}}catch{I=null}}function Wt(){bt()}const C={store:{subscribe(t){if(m)return m.store.subscribe(t);try{t({path:"/",params:{},query:{}})}catch{}return()=>{}},getState(){return m?m.getCurrent():{path:"/",params:{},query:{}}},setState(t){if(m)try{m.store.setState(t)}catch{}}},subscribe(t){if(typeof t!="function")return c.devWarn("activeRouterProxy.subscribe: listener must be a function"),()=>{};if(H.add(t),m)if(!I)bt();else try{const r=m.getCurrent();r&&t(r)}catch(r){c.devWarn("activeRouterProxy subscription failed",r)}else try{t({path:"/",params:{},query:{}})}catch(r){c.devWarn("activeRouterProxy fallback state delivery failed",r)}return()=>{try{if(H.delete(t),H.size===0&&I){try{I()}catch(r){c.devWarn("activeRouterProxy inner unsubscribe failed",r)}I=null}}catch(r){c.devWarn("activeRouterProxy unsubscribe failed",r)}}},getCurrent(){return m?m.getCurrent():{path:"/",params:{},query:{}}},async push(t){return m?m.push(t):Promise.resolve()},async replace(t){return m?m.replace(t):Promise.resolve()},back(){if(m)return m.back()},matchRoute(t){return m?m.matchRoute(t):{route:null,params:{}}},resolveRouteComponent(t){return m?m.resolveRouteComponent(t):Promise.reject(new Error("No active router"))},base:"",scrollToFragment(t){return m?m.scrollToFragment(t):Promise.resolve(!1)},destroy(){m&&m.destroy()}};function wt(t){const{routes:r,base:v="",initialUrl:a,scrollToFragment:i=!0}=t,o=mt(v),w=typeof i=="boolean"?{...ot,enabled:i}:{...ot,...i};let l,u,y,P,W,L,Q,X=()=>{};const _=new Set,F=10;let k=0;const Y=async(s,f)=>{const e=G(r,s.path);if(!e||!e.beforeEnter)return!0;try{const n=await e.beforeEnter(s,f);if(typeof n=="string"){const h=`${s.path}->${n}`;return _.has(h)||k>=F?(c.devError(`Redirect loop detected: ${h}`),!1):n}return n!==!1}catch(n){c.devError("beforeEnter error",n);try{y.setState(f)}catch{}throw n}},nt=async(s,f)=>{const e=G(r,s.path);if(!e||!e.onEnter)return!0;try{const n=await e.onEnter(s,f);if(typeof n=="string"){const h=`${s.path}->${n}`;return _.has(h)||k>=F?(c.devError(`Redirect loop detected: ${h}`),!1):n}return n!==!1}catch(n){c.devError("onEnter error",n);try{y.setState(f)}catch{}throw n}},tt=(s,f)=>{const e=G(r,s.path);if(!(!e||!e.afterEnter))try{const n=e.afterEnter(s,f);n instanceof Promise&&n.catch(h=>{c.devError("afterEnter async error",h)})}catch(n){c.devError("afterEnter error",n)}},x=new Map,U=100,O=s=>{if(x.has(s))return x.get(s);const f=V(r,s);if(x.size>=U){const e=Math.floor(U*.25),n=Array.from(x.keys());for(let h=0;h<e&&h<n.length;h++)x.delete(n[h])}return x.set(s,f),f},et=()=>{};async function p(s,f=0){try{const e=document.getElementById(s);if(!e)return!1;if(f>0)try{const n=e.getBoundingClientRect(),h=Math.max(0,window.scrollY+n.top-f);typeof window.scrollTo=="function"&&window.scrollTo({top:h,behavior:"auto"})}catch{try{e.scrollIntoView()}catch{return!1}}else if(typeof e.scrollIntoView=="function")try{e.scrollIntoView({behavior:"auto",block:"start",inline:"nearest"})}catch{try{e.scrollIntoView()}catch{return!1}}return!0}catch{return!1}}function R(s,f=0,e=2e3){return new Promise(n=>{let h=!1,g=null,b=null;const $=Date.now(),S=T=>{h||(h=!0,g&&clearTimeout(g),b!==null&&cancelAnimationFrame(b),n(T))},z=async()=>{if(!h)try{if(await p(s,f))return S(!0);const T=async()=>{if(h)return;if(Date.now()-$>=e)return S(!1);try{if(await p(s,f))return S(!0);b=requestAnimationFrame(T)}catch(St){c.devWarn("Scroll retry attempt failed:",St),b=requestAnimationFrame(T)}};b=requestAnimationFrame(T)}catch(T){c.devWarn("Initial scroll attempt failed:",T),S(!1)}};g=setTimeout(()=>{S(!1)},e),z().catch(T=>{c.devWarn("Scroll attempt failed:",T),S(!1)})})}let d=!1;const q=async(s,f=!1)=>{if(d){c.devWarn(`Navigation to ${s} blocked - navigation already in progress`);return}d=!0,k=0,_.clear();try{await N(s,f)}finally{d=!1,k=0,_.clear()}},M=s=>{const f=s.indexOf("#"),e=f>=0?s.slice(f+1):"",n=f>=0?s.slice(0,f):s,h=n.indexOf("?"),g=h>=0?n.slice(0,h):n,b=h>=0?rt(n.slice(h)):{},$=g.startsWith(o)?g.slice(o.length):g;return{path:A($||"/"),query:b,fragment:e}},N=async(s,f=!1)=>{try{const e=M(s),n=O(e.path);if(!n.route)throw new Error(`No route found for ${e.path}`);const h=y.getState(),g={path:e.path,params:n.params,query:e.query,fragment:e.fragment},b=await Y(g,h);if(b===!1)return;if(typeof b=="string"){k++;const S=`${g.path}->${b}`;_.add(S),await N(b,!0);return}const $=await nt(g,h);if($===!1)return;if(typeof $=="string"){k++;const S=`${g.path}->${$}`;_.add(S),await N($,!0);return}if(typeof window<"u"&&typeof document<"u"){const S=pt(e.query),z=o+e.path+(S||"")+(e.fragment?"#"+e.fragment:"");f?window.history.replaceState({},"",z):window.history.pushState({},"",z)}if(y.setState(g),tt(g,h),typeof window<"u"&&typeof document<"u")try{const S=g.fragment;w.enabled&&S&&R(String(S),w.offset,w.timeoutMs).catch(()=>{})}catch{}}catch(e){if(c.devError("Navigation error:",e),e instanceof Error&&(e.stack?.includes("runBeforeEnter")||e.stack?.includes("runOnEnter")))throw e;try{const n=y.getState();if(!V(r,n.path).route){let g=r.find(b=>b.path==="/");if(g||(g=r.find(b=>!b.path.includes(":")&&!b.path.includes("*"))),!g&&r.length>0&&(g=r[0]),g){const b=V(r,g.path);y.setState({path:g.path,params:b.params,query:{}})}else c.devError("No fallback route available for error recovery")}}catch(n){c.devWarn("State recovery failed during navigation error:",n)}}};if((s=>{if(!s||s.length===0)return c.devError("Router configuration error: No routes provided"),!1;const f=new Set;for(const e of s){if(!e.path)return c.devError("Router configuration error: Route missing path",e),!1;f.has(e.path)&&c.devWarn(`Duplicate route path detected: ${e.path}`),f.add(e.path),!e.component&&!e.load&&c.devWarn(`Route '${e.path}' has no component or load function`)}return!0})(r),typeof window>"u"||typeof a<"u"){for(const s of r)O(s.path);c.devWarn(`Pre-compiled ${r.length} routes for SSR`)}if(typeof window<"u"&&typeof document<"u"&&typeof a>"u"){l=()=>{try{const e=new URL(window.location.href),n=e.pathname,h=n.startsWith(o)?n.slice(o.length):n,g=A(h||"/"),b=rt(e.search),$=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:g,query:b,fragment:$}}catch(e){return c.devWarn("Invalid URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},u=l();const s=O(u.path);y=it.createStore({path:u.path,params:s.params,query:u.query,fragment:u.fragment}),P=async(e=!1)=>{const n=l();await q(n.path,e)};const f=()=>P(!0);window.addEventListener("popstate",f),X=()=>window.removeEventListener("popstate",f),W=e=>q(e,!1),L=e=>q(e,!0),Q=()=>window.history.back()}else{l=()=>{try{const e=new URL(a||"/","http://localhost"),n=e.pathname,h=n.startsWith(o)?n.slice(o.length):n,g=A(h||"/"),b=rt(e.search),$=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:g,query:b,fragment:$}}catch(e){return c.devWarn("Invalid SSR URL detected, falling back to safe defaults",e),{path:"/",query:{},fragment:""}}},u=l();const s=O(u.path);y=it.createStore({path:u.path,params:s.params,query:u.query,fragment:u.fragment}),P=async()=>{const e=l();await f(e.path)};const f=async e=>{if(k++,k>F){c.devError(`SSR redirect depth exceeded for path: ${e}`);return}try{const n=M(e),h=O(n.path);if(!h.route)throw new Error(`No route found for ${n.path}`);const g=y.getState(),b={path:n.path,params:h.params,query:n.query,fragment:n.fragment},$=G(r,b.path);if($?.beforeEnter){const S=await $.beforeEnter(b,g);if(typeof S=="string"){const z=`${b.path}->${S}`;_.add(z),await f(S);return}if(S===!1)return}if($?.onEnter){const S=await $.onEnter(b,g);if(typeof S=="string"){const z=`${b.path}->${S}`;_.add(z),await f(S);return}if(S===!1)return}y.setState(b),$?.afterEnter&&$.afterEnter(b,g)}catch(n){throw c.devError("SSR navigation error:",n),n}};W=async e=>(k=0,_.clear(),f(e)),L=async e=>(k=0,_.clear(),f(e)),Q=()=>{}}return{_cleanupScrollState:et,destroy:X,store:y,push:W,replace:L,back:Q,subscribe:y.subscribe,matchRoute:s=>O(s),getCurrent:()=>y.getState(),resolveRouteComponent:gt,base:o,scrollToFragment:s=>{const f=s||y.getState().fragment;return!f||typeof window>"u"||typeof document>"u"?Promise.resolve(!1):R(f,w.offset,w.timeoutMs)}}}function xt(t){vt();const r=wt(t),v=ft();if(v){try{v.destroy()}catch{}try{v._cleanupScrollState?.()}catch{}}Pt(r);try{Wt();try{typeof window<"u"&&E.flushDOMUpdates()}catch{}try{typeof window<"u"&&queueMicrotask(()=>{try{E.flushDOMUpdates()}catch{}})}catch{}}catch{}return D.component("router-view",async()=>{if(!ft())return D.html`<div>Router not initialized.</div>`;const a=E.ref(C.getCurrent()),i=typeof window>"u";let o;i||(j.useOnConnected(()=>{try{typeof C.subscribe=="function"&&(o=C.subscribe(l=>{try{l&&typeof l=="object"&&typeof l.path=="string"?a.value=l:(c.devWarn("router-view received invalid state",l),a.value={path:"/",params:{},query:{}})}catch(u){c.devWarn("router-view subscription update failed",u);try{a.value={path:"/",params:{},query:{}}}catch{}}}))}catch(l){c.devWarn("router-view subscribe failed",l)}}),j.useOnDisconnected(()=>{if(typeof o=="function"){try{o()}catch(l){c.devWarn("router-view unsubscribe failed",l)}o=void 0}}));const w=C.matchRoute(a.value.path);if(!w||!w.route)return D.html`<div>Not found</div>`;try{const u=await C.resolveRouteComponent(w.route);if(typeof u=="string")return{tag:u,props:{},children:[]};if(typeof u=="function"){const y=u();return(y instanceof Promise?y:Promise.resolve(y)).then(W=>typeof W=="string"?{tag:W,props:{},children:[]}:W)}return D.html`<div>Invalid route component</div>`}catch{return D.html`<div>Invalid route component</div>`}}),D.component("router-link",()=>{const a=j.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),i=typeof window>"u",o=E.ref(C.getCurrent()),w=o.value?.path||"/",l=String(a.to||""),u=i?{isExactActive:dt(w,l,C.base),isActive:ht(w,l,C.base),isExternal:K(l)||!!a.external}:null;let y;j.useStyle(()=>"a,button{display:inline-block;}");const P=E.ref(a.class||""),W=E.ref(a.style||"");if(!i){let p=null;j.useOnConnected(R=>{try{if(typeof C.subscribe=="function"){y=C.subscribe(d=>{try{d&&typeof d=="object"&&typeof d.path=="string"?o.value=d:(c.devWarn("router-link received invalid state",d),o.value={path:"/",params:{},query:{}})}catch(q){c.devWarn("router-link subscription update failed",q);try{o.value={path:"/",params:{},query:{}}}catch{}}});try{const d=C.getCurrent();d&&typeof d.path=="string"&&(o.value=d)}catch(d){c.devWarn("router-link initial state sync failed",d)}p=setInterval(()=>{try{const d=C.getCurrent();d&&typeof d.path=="string"&&JSON.stringify(o.value)!==JSON.stringify(d)&&(o.value=d)}catch{}},100)}}catch(d){c.devWarn("router-link subscribe failed",d)}try{const d=R?._host;if(d instanceof HTMLElement){const q=d.getAttribute("class"),M=d.getAttribute("style");q&&(P.value=q),M&&(W.value=M),q!==null&&d.removeAttribute("class"),M!==null&&d.removeAttribute("style");try{R?._requestRender?.();try{E.flushDOMUpdates()}catch{}}catch{}}}catch(d){c.devWarn("router-link host migration failed",d)}}),j.useOnDisconnected(()=>{if(typeof y=="function")try{y()}catch(R){c.devWarn("router-link unsubscribe failed",R)}finally{y=void 0}if(p)try{clearInterval(p)}catch(R){c.devWarn("router-link sync interval cleanup failed",R)}finally{p=null}})}const L=E.computed(()=>{if(i&&u)return u.isExactActive;try{const p=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:dt(o.value.path,R,p)}catch(p){return c.devWarn("isExactActive computation error",p),!1}}),Q=E.computed(()=>{if(i&&u)return u.isActive;try{const p=C.base??"",R=a.to||"";return!o.value||typeof o.value.path!="string"?!1:a.exact?L.value:ht(o.value.path,R,p)}catch(p){return c.devWarn("isActive computation error",p),!1}}),X=E.computed(()=>{const p=String(a.to||"");if(st(p))return null;if(K(p))return p;const[R,d]=p.split("#"),[q,M]=(R||"").split("?"),N=C.base??"";let Z=q||"/";if(N&&N!=="/"){const at=A(N),s=A(Z);s.startsWith(at)?Z=s.slice(at.length)||"/":Z=s}const ct=A(Z||"/");return N+ct+(M?"?"+M:"")+(d?"#"+d:"")}),_=E.computed(()=>{const R=(P&&P.value||a.class||"").split(/\s+/).filter(Boolean),d={};for(const q of R)d[q]=!0;return d}),F=E.computed(()=>({..._.value,[a.activeClass||"active"]:Q.value,[a.exactActiveClass||"exact-active"]:L.value})),k=E.computed(()=>Object.keys(F.value).filter(p=>F.value[p]).join(" ")),Y=E.computed(()=>a.tag||"a"),nt=E.computed(()=>Y.value==="button"),tt=E.computed(()=>L.value?a.ariaCurrentValue:null),x=E.computed(()=>!!a.disabled),U=E.computed(()=>{const p=String(a.to||"");return(K(p)||!!a.external)&&Y.value==="a"}),O=E.computed(()=>W&&W.value||a.style||""),et=p=>{if(p.defaultPrevented||p.button!==0||p.metaKey||p.altKey||p.ctrlKey||p.shiftKey)return;if(x.value){p.preventDefault();return}const R=String(a.to||"");if(st(R)){try{p.preventDefault()}catch{}c.devWarn("Blocked unsafe javascript: URI in router-link.to");return}U.value||(p.preventDefault(),a.replace?C.replace(a.to):C.push(a.to))};return D.html`
2
+ ${Rt.match().when(nt.value,D.html`
3
3
  <button
4
4
  part="button"
5
- class="${J.value}"
6
- style="${Y.value||null}"
7
- aria-current="${I.value}"
8
- disabled="${M.value?"":null}"
9
- aria-disabled="${M.value?"true":null}"
10
- tabindex="${M.value?"-1":null}"
11
- @click="${V}"
5
+ class="${k.value}"
6
+ style="${O.value||null}"
7
+ aria-current="${tt.value}"
8
+ disabled="${x.value?"":null}"
9
+ aria-disabled="${x.value?"true":null}"
10
+ tabindex="${x.value?"-1":null}"
11
+ @click="${et}"
12
12
  >
13
13
  <slot></slot>
14
14
  </button>
15
- `).otherwise(x.html`
15
+ `).otherwise(D.html`
16
16
  <a
17
17
  part="link"
18
- href="${M.value?null:_.value}"
19
- class="${J.value}"
20
- style="${Y.value||null}"
21
- aria-current="${I.value}"
22
- aria-disabled="${M.value?"true":null}"
23
- tabindex="${M.value?"-1":null}"
24
- target="${T.value?"_blank":null}"
25
- rel="${T.value?"noopener noreferrer":null}"
26
- @click="${V}"
18
+ href="${x.value?null:X.value}"
19
+ class="${k.value}"
20
+ style="${O.value||null}"
21
+ aria-current="${tt.value}"
22
+ aria-disabled="${x.value?"true":null}"
23
+ tabindex="${x.value?"-1":null}"
24
+ target="${U.value?"_blank":null}"
25
+ rel="${U.value?"noopener noreferrer":null}"
26
+ @click="${et}"
27
27
  ><slot></slot
28
28
  ></a>
29
29
  `).done()}
30
- `}),r}function lt(t,r,v){if(U(r))return!1;let l=(r.split("#")[0]||"/").split("?")[0];if(v&&v!=="/"){const u=A(v),f=A(l);f.startsWith(u)?l=f.slice(u.length)||"/":l=f}const o=A(t),b=A(l);return o===b}function ut(t,r,v){if(U(r))return!1;let l=(r.split("#")[0]||"/").split("?")[0];if(v&&v!=="/"){const u=A(v),f=A(l);f.startsWith(u)?l=f.slice(u.length)||"/":l=f}const o=A(t),b=A(l);return b==="/"?o==="/":o===b?!0:o.startsWith(b.endsWith("/")?b:b+"/")}exports.DEFAULT_SCROLL_CONFIG=rt;exports.activeRouterProxy=C;exports.canonicalizeBase=ht;exports.clearComponentCache=pt;exports.findMatchedRoute=Z;exports.initRouter=At;exports.isAbsoluteUrl=U;exports.isDangerousScheme=nt;exports.matchRoute=F;exports.matchRouteSSR=Rt;exports.normalizePathForRoute=A;exports.parseQuery=tt;exports.resolveRouteComponent=yt;exports.safeDecode=dt;exports.serializeQuery=ft;exports.useRouter=vt;
30
+ `}),r}function dt(t,r,v){if(K(r))return!1;let i=(r.split("#")[0]||"/").split("?")[0];if(v&&v!=="/"){const l=A(v),u=A(i);u.startsWith(l)?i=u.slice(l.length)||"/":i=u}const o=A(t),w=A(i);return o===w}function ht(t,r,v){if(K(r))return!1;let i=(r.split("#")[0]||"/").split("?")[0];if(v&&v!=="/"){const l=A(v),u=A(i);u.startsWith(l)?i=u.slice(l.length)||"/":i=u}const o=A(t),w=A(i);return w==="/"?o==="/":o===w?!0:o.startsWith(w.endsWith("/")?w:w+"/")}exports.DEFAULT_SCROLL_CONFIG=ot;exports.activeRouterProxy=C;exports.canonicalizeBase=mt;exports.clearComponentCache=vt;exports.findMatchedRoute=G;exports.initRouter=xt;exports.isAbsoluteUrl=K;exports.isDangerousScheme=st;exports.matchRoute=V;exports.matchRouteSSR=Ct;exports.normalizePathForRoute=A;exports.parseQuery=rt;exports.resolveRouteComponent=gt;exports.safeDecode=yt;exports.serializeQuery=pt;exports.useRouter=wt;
31
31
  //# sourceMappingURL=custom-elements-runtime.router.cjs.js.map