@jasonshimmy/custom-elements-runtime 2.5.1 → 2.5.5

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 (90) hide show
  1. package/README.md +115 -40
  2. package/dist/css/colors.d.ts +14 -0
  3. package/dist/custom-elements-runtime.cjs.js +6 -18
  4. package/dist/custom-elements-runtime.cjs.js.map +1 -1
  5. package/dist/custom-elements-runtime.colors.cjs.js +2 -0
  6. package/dist/custom-elements-runtime.colors.cjs.js.map +1 -0
  7. package/dist/custom-elements-runtime.colors.es.js +279 -0
  8. package/dist/custom-elements-runtime.colors.es.js.map +1 -0
  9. package/dist/custom-elements-runtime.directive-enhancements.es.js +1 -1
  10. package/dist/custom-elements-runtime.es.js +246 -3648
  11. package/dist/custom-elements-runtime.es.js.map +1 -1
  12. package/dist/custom-elements-runtime.event-bus.cjs.js +1 -1
  13. package/dist/custom-elements-runtime.event-bus.cjs.js.map +1 -1
  14. package/dist/custom-elements-runtime.event-bus.es.js +28 -25
  15. package/dist/custom-elements-runtime.event-bus.es.js.map +1 -1
  16. package/dist/custom-elements-runtime.router.cjs.js +20 -20
  17. package/dist/custom-elements-runtime.router.cjs.js.map +1 -1
  18. package/dist/custom-elements-runtime.router.es.js +790 -464
  19. package/dist/custom-elements-runtime.router.es.js.map +1 -1
  20. package/dist/custom-elements-runtime.ssr.cjs.js +1 -1
  21. package/dist/custom-elements-runtime.ssr.es.js +12 -8
  22. package/dist/custom-elements-runtime.ssr.es.js.map +1 -1
  23. package/dist/custom-elements-runtime.store.cjs.js +1 -1
  24. package/dist/custom-elements-runtime.store.cjs.js.map +1 -1
  25. package/dist/custom-elements-runtime.store.es.js +5 -5
  26. package/dist/custom-elements-runtime.store.es.js.map +1 -1
  27. package/dist/custom-elements-runtime.transitions.cjs.js +1 -1
  28. package/dist/custom-elements-runtime.transitions.es.js +1 -1
  29. package/dist/event-bus.d.ts +17 -4
  30. package/dist/index.d.ts +13 -3
  31. package/dist/keep-alive.d.ts +50 -0
  32. package/dist/{logger-BuUYv7C_.js → logger-BvkEbVM4.js} +15 -11
  33. package/dist/logger-BvkEbVM4.js.map +1 -0
  34. package/dist/logger-CSALKaYm.cjs +2 -0
  35. package/dist/logger-CSALKaYm.cjs.map +1 -0
  36. package/dist/namespace-helpers-4qeKVqQw.cjs +5 -0
  37. package/dist/namespace-helpers-4qeKVqQw.cjs.map +1 -0
  38. package/dist/namespace-helpers-DcD_6_K1.js +989 -0
  39. package/dist/namespace-helpers-DcD_6_K1.js.map +1 -0
  40. package/dist/router/active-proxy.d.ts +5 -0
  41. package/dist/router/component-loader.d.ts +11 -0
  42. package/dist/router/instance.d.ts +11 -0
  43. package/dist/router/matcher.d.ts +14 -0
  44. package/dist/router/path-utils.d.ts +48 -0
  45. package/dist/router/types.d.ts +134 -0
  46. package/dist/router.d.ts +6 -147
  47. package/dist/runtime/builtin-components.d.ts +78 -0
  48. package/dist/runtime/component/element-class.d.ts +4 -0
  49. package/dist/runtime/component/factory.d.ts +39 -0
  50. package/dist/runtime/component/registry.d.ts +16 -0
  51. package/dist/runtime/component.d.ts +3 -50
  52. package/dist/runtime/discovery-state.d.ts +30 -0
  53. package/dist/runtime/hooks.d.ts +115 -0
  54. package/dist/runtime/logger.d.ts +19 -1
  55. package/dist/runtime/monitoring/health-monitor.d.ts +56 -0
  56. package/dist/runtime/reactive.d.ts +39 -7
  57. package/dist/runtime/render.d.ts +20 -4
  58. package/dist/runtime/scheduler.d.ts +115 -2
  59. package/dist/runtime/template-compiler/impl.d.ts +14 -0
  60. package/dist/runtime/template-compiler/lru-cache.d.ts +20 -0
  61. package/dist/runtime/template-compiler/props-parser.d.ts +15 -0
  62. package/dist/runtime/template-compiler/vnode-utils.d.ts +5 -0
  63. package/dist/runtime/template-compiler.d.ts +5 -28
  64. package/dist/runtime/types.d.ts +10 -0
  65. package/dist/runtime/vdom-directives.d.ts +71 -0
  66. package/dist/runtime/vdom-helpers.d.ts +126 -0
  67. package/dist/runtime/vdom-patch.d.ts +67 -0
  68. package/dist/runtime/vdom.d.ts +16 -140
  69. package/dist/ssr.d.ts +2 -1
  70. package/dist/teleport.d.ts +68 -0
  71. package/dist/template-compiler-CA4YRaBu.cjs +23 -0
  72. package/dist/template-compiler-CA4YRaBu.cjs.map +1 -0
  73. package/dist/template-compiler-CJFwjLCP.js +3981 -0
  74. package/dist/template-compiler-CJFwjLCP.js.map +1 -0
  75. package/dist/transitions-DPZiuXb9.cjs +330 -0
  76. package/dist/transitions-DPZiuXb9.cjs.map +1 -0
  77. package/dist/{transitions-CZ21fzhh.js → transitions-Di5wW9yc.js} +1059 -618
  78. package/dist/transitions-Di5wW9yc.js.map +1 -0
  79. package/dist/transitions.d.ts +1 -1
  80. package/package.json +20 -12
  81. package/dist/logger-BuUYv7C_.js.map +0 -1
  82. package/dist/logger-DiXdWaF-.cjs +0 -2
  83. package/dist/logger-DiXdWaF-.cjs.map +0 -1
  84. package/dist/namespace-helpers-BsKQl3aH.cjs +0 -5
  85. package/dist/namespace-helpers-BsKQl3aH.cjs.map +0 -1
  86. package/dist/namespace-helpers-Dw1mgQab.js +0 -692
  87. package/dist/namespace-helpers-Dw1mgQab.js.map +0 -1
  88. package/dist/transitions-CZ21fzhh.js.map +0 -1
  89. package/dist/transitions-RXe2brRm.cjs +0 -302
  90. package/dist/transitions-RXe2brRm.cjs.map +0 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./logger-DiXdWaF-.cjs");class r extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return r.instance||(r.instance=new r),r.instance}emit(t,e){const n=Date.now(),o=this.eventCounters.get(t);if(!o||n-o.window>1e3)this.eventCounters.set(t,{count:1,window:n});else if(o.count++,o.count>50&&o.count>100)return;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!1,cancelable:!0}));const c=this.handlers[t];c&&c.forEach(l=>{try{l(e)}catch(u){a.devError(`Error in global event handler for "${t}":`,u)}})}on(t,e){return this.handlers[t]||(this.handlers[t]=new Set),this.handlers[t].add(e),()=>this.off(t,e)}off(t,e){const n=this.handlers[t];n&&n.delete(e)}offAll(t){delete this.handlers[t]}listen(t,e,n){return this.addEventListener(t,e,n),()=>this.removeEventListener(t,e)}once(t,e){return new Promise(n=>{const o=this.on(t,c=>{o(),e(c),n(c)})})}getActiveEvents(){return Object.keys(this.handlers).filter(t=>this.handlers[t]&&this.handlers[t].size>0)}clear(){this.handlers={}}getHandlerCount(t){return this.handlers[t]?.size||0}getEventStats(){const t={};for(const[e,n]of this.eventCounters.entries())t[e]={count:n.count,handlersCount:this.getHandlerCount(e)};return t}resetEventCounters(){this.eventCounters.clear()}}const i=new Proxy({},{get(s,t){const e=r.getInstance(),n=e[t];return typeof n=="function"?n.bind(e):n},apply(s,t,e){return r.getInstance().apply(t,e)}}),h=(s,t)=>i.emit(s,t),d=(s,t)=>i.on(s,t),f=(s,t)=>i.off(s,t),g=(s,t)=>i.once(s,t),v=(s,t,e)=>i.listen(s,t,e);exports.GlobalEventBus=r;exports.emit=h;exports.eventBus=i;exports.listen=v;exports.off=f;exports.on=d;exports.once=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./logger-CSALKaYm.cjs");class o extends EventTarget{handlers={};static instance;eventCounters=new Map;static getInstance(){return o.instance||(o.instance=new o),o.instance}emit(t,e){const n=Date.now(),r=this.eventCounters.get(t);if(!r||n-r.window>1e3)this.eventCounters.set(t,{count:1,window:n});else if(r.count++,r.count>50&&r.count>100)return;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!1,cancelable:!0}));const c=this.handlers[t];c&&c.forEach(u=>{try{u(e)}catch(l){h.devError(`Error in global event handler for "${t}":`,l)}})}on(t,e){return this.handlers[t]||(this.handlers[t]=new Set),this.handlers[t].add(e),()=>this.off(t,e)}off(t,e){const n=this.handlers[t];n&&n.delete(e)}offAll(t){delete this.handlers[t]}listen(t,e,n){return this.addEventListener(t,e,n),()=>this.removeEventListener(t,e)}once(t,e){if(e!==void 0){const n=this.on(t,r=>{n(),e(r)})}else return new Promise(n=>{const r=this.on(t,c=>{r(),n(c)})})}getActiveEvents(){return Object.keys(this.handlers).filter(t=>this.handlers[t]&&this.handlers[t].size>0)}clear(){this.handlers={}}getHandlerCount(t){return this.handlers[t]?.size||0}getEventStats(){const t={};for(const[e,n]of this.eventCounters.entries())t[e]={count:n.count,handlersCount:this.getHandlerCount(e)};return t}resetEventCounters(){this.eventCounters.clear()}}const i=new Proxy({},{get(s,t){const e=o.getInstance(),n=e[t];return typeof n=="function"?n.bind(e):n},apply(){throw new TypeError("eventBus is not a callable function")}}),a=(s,t)=>i.emit(s,t),f=(s,t)=>i.on(s,t),d=(s,t)=>i.off(s,t);function g(s,t){return t!==void 0?i.once(s,t):i.once(s)}const v=(s,t,e)=>i.listen(s,t,e);exports.GlobalEventBus=o;exports.emit=a;exports.eventBus=i;exports.listen=v;exports.off=d;exports.on=f;exports.once=g;
2
2
  //# sourceMappingURL=custom-elements-runtime.event-bus.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom-elements-runtime.event-bus.cjs.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. Returns a promise that resolves with the event data.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n once<T = unknown>(eventName: string, handler: EventHandler<T>): Promise<T> {\n return new Promise((resolve) => {\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n handler(data);\n resolve(data);\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const val = (inst as any)[prop as any];\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') return val.bind(inst);\n return val;\n },\n // Support direct function calls (unlikely) and other traps defensively\n apply(_target, thisArg, args) {\n const inst = GlobalEventBus.getInstance();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (inst as any).apply(thisArg, args);\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\n */\nexport const once = <T = unknown>(\n eventName: string,\n handler: EventHandler<T>,\n) => eventBus.once(eventName, handler);\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","resolve","unsubscribe","stats","eventBus","_target","prop","inst","val","thisArg","args","emit","on","off","once","listen"],"mappings":"yHAkBO,MAAMA,UAAuB,WAAY,CACtC,SAA8C,CAAA,EACtD,OAAe,SACP,kBACF,IAKN,OAAO,aAA8B,CACnC,OAAKA,EAAe,WAClBA,EAAe,SAAW,IAAIA,GAEzBA,EAAe,QACxB,CAOA,KAAkBC,EAAmBC,EAAgB,CAEnD,MAAMC,EAAM,KAAK,IAAA,EACXC,EAAU,KAAK,cAAc,IAAIH,CAAS,EAEhD,GAAI,CAACG,GAAWD,EAAMC,EAAQ,OAAS,IAErC,KAAK,cAAc,IAAIH,EAAW,CAAE,MAAO,EAAG,OAAQE,EAAK,UAE3DC,EAAQ,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AG,MAAQ,CAC3C,CAKA,eAA0E,CACxE,MAAMW,EAAkE,CAAA,EACxE,SAAW,CAACX,EAAWG,CAAO,IAAK,KAAK,cAAc,UACpDQ,EAAMX,CAAS,EAAI,CACjB,MAAOG,EAAQ,MACf,cAAe,KAAK,gBAAgBH,CAAS,CAAA,EAGjD,OAAOW,CACT,CAKA,oBAA2B,CACzB,KAAK,cAAc,MAAA,CACrB,CACF,CAcO,MAAMC,EAAW,IAAI,MAC1B,CAAA,EACA,CACE,IAAIC,EAASC,EAAmB,CAC9B,MAAMC,EAAOhB,EAAe,YAAA,EAEtBiB,EAAOD,EAAaD,CAAW,EAGrC,OAAI,OAAOE,GAAQ,WAAmBA,EAAI,KAAKD,CAAI,EAC5CC,CACT,EAEA,MAAMH,EAASI,EAASC,EAAM,CAG5B,OAFanB,EAAe,YAAA,EAEP,MAAMkB,EAASC,CAAI,CAC1C,CAAA,CAEJ,EAKaC,EAAO,CAAcnB,EAAmBC,IACnDW,EAAS,KAAKZ,EAAWC,CAAI,EAKlBmB,EAAK,CAAcpB,EAAmBK,IACjDO,EAAS,GAAGZ,EAAWK,CAAO,EAKnBgB,EAAM,CAAcrB,EAAmBK,IAClDO,EAAS,IAAIZ,EAAWK,CAAO,EAKpBiB,EAAO,CAClBtB,EACAK,IACGO,EAAS,KAAKZ,EAAWK,CAAO,EAKxBkB,EAAS,CACpBvB,EACAK,EACAG,IACGI,EAAS,OAAOZ,EAAWK,EAASG,CAAO"}
1
+ {"version":3,"file":"custom-elements-runtime.event-bus.cjs.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":"yHAkBO,MAAMA,UAAuB,WAAY,CACtC,SAA8C,CAAA,EACtD,OAAe,SACP,kBACF,IAKN,OAAO,aAA8B,CACnC,OAAKA,EAAe,WAClBA,EAAe,SAAW,IAAIA,GAEzBA,EAAe,QACxB,CAOA,KAAkBC,EAAmBC,EAAgB,CAEnD,MAAMC,EAAM,KAAK,IAAA,EACXC,EAAU,KAAK,cAAc,IAAIH,CAAS,EAEhD,GAAI,CAACG,GAAWD,EAAMC,EAAQ,OAAS,IAErC,KAAK,cAAc,IAAIH,EAAW,CAAE,MAAO,EAAG,OAAQE,EAAK,UAE3DC,EAAQ,QAEJA,EAAQ,MAAQ,IAEdA,EAAQ,MAAQ,IAClB,OAMN,KAAK,cACH,IAAI,YAAYH,EAAW,CACzB,OAAQC,EACR,QAAS,GACT,WAAY,EAAA,CACb,CAAA,EAIH,MAAMG,EAAgB,KAAK,SAASJ,CAAS,EACzCI,GACFA,EAAc,QAASC,GAAY,CACjC,GAAI,CACFA,EAAQJ,CAAI,CACd,OAASK,EAAO,CACdC,EAAAA,SAAS,sCAAsCP,CAAS,KAAMM,CAAK,CACrE,CACF,CAAC,CAEL,CAOA,GAAgBN,EAAmBK,EAAsC,CACvE,OAAK,KAAK,SAASL,CAAS,IAC1B,KAAK,SAASA,CAAS,EAAI,IAAI,KAEjC,KAAK,SAASA,CAAS,EAAE,IAAIK,CAAgC,EACtD,IAAM,KAAK,IAAIL,EAAWK,CAAO,CAC1C,CAOA,IAAiBL,EAAmBK,EAAgC,CAClE,MAAMD,EAAgB,KAAK,SAASJ,CAAS,EACzCI,GACFA,E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C,CAC3D,CAAA,CAEJ,EAKaC,EAAO,CAAcjB,EAAmBC,IACnDW,EAAS,KAAKZ,EAAWC,CAAI,EAKlBiB,EAAK,CAAclB,EAAmBK,IACjDO,EAAS,GAAGZ,EAAWK,CAAO,EAKnBc,EAAM,CAAcnB,EAAmBK,IAClDO,EAAS,IAAIZ,EAAWK,CAAO,EAe1B,SAASe,EACdpB,EACAK,EACmB,CACnB,OAAIA,IAAY,OACPO,EAAS,KAAKZ,EAAWK,CAAO,EAElCO,EAAS,KAAQZ,CAAS,CACnC,CAKO,MAAMqB,EAAS,CACpBrB,EACAK,EACAG,IACGI,EAAS,OAAOZ,EAAWK,EAASG,CAAO"}
@@ -1,4 +1,4 @@
1
- import { d as l } from "./logger-BuUYv7C_.js";
1
+ import { d as l } from "./logger-BvkEbVM4.js";
2
2
  class o extends EventTarget {
3
3
  handlers = {};
4
4
  static instance;
@@ -28,12 +28,12 @@ class o extends EventTarget {
28
28
  cancelable: !0
29
29
  })
30
30
  );
31
- const i = this.handlers[t];
32
- i && i.forEach((h) => {
31
+ const c = this.handlers[t];
32
+ c && c.forEach((u) => {
33
33
  try {
34
- h(n);
35
- } catch (a) {
36
- l(`Error in global event handler for "${t}":`, a);
34
+ u(n);
35
+ } catch (h) {
36
+ l(`Error in global event handler for "${t}":`, h);
37
37
  }
38
38
  });
39
39
  }
@@ -70,17 +70,17 @@ class o extends EventTarget {
70
70
  listen(t, n, e) {
71
71
  return this.addEventListener(t, n, e), () => this.removeEventListener(t, n);
72
72
  }
73
- /**
74
- * Register a one-time event handler. Returns a promise that resolves with the event data.
75
- * @param eventName - Name of the event
76
- * @param handler - Handler function
77
- */
78
73
  once(t, n) {
79
- return new Promise((e) => {
80
- const r = this.on(t, (i) => {
81
- r(), n(i), e(i);
74
+ if (n !== void 0) {
75
+ const e = this.on(t, (r) => {
76
+ e(), n(r);
77
+ });
78
+ } else
79
+ return new Promise((e) => {
80
+ const r = this.on(t, (c) => {
81
+ r(), e(c);
82
+ });
82
83
  });
83
- });
84
84
  }
85
85
  /**
86
86
  * Get a list of all active event names with registered handlers.
@@ -122,26 +122,29 @@ class o extends EventTarget {
122
122
  this.eventCounters.clear();
123
123
  }
124
124
  }
125
- const c = new Proxy(
125
+ const i = new Proxy(
126
126
  {},
127
127
  {
128
128
  get(s, t) {
129
129
  const n = o.getInstance(), e = n[t];
130
130
  return typeof e == "function" ? e.bind(n) : e;
131
131
  },
132
- // Support direct function calls (unlikely) and other traps defensively
133
- apply(s, t, n) {
134
- return o.getInstance().apply(t, n);
132
+ apply() {
133
+ throw new TypeError("eventBus is not a callable function");
135
134
  }
136
135
  }
137
- ), d = (s, t) => c.emit(s, t), f = (s, t) => c.on(s, t), g = (s, t) => c.off(s, t), w = (s, t) => c.once(s, t), v = (s, t, n) => c.listen(s, t, n);
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);
139
+ }
140
+ const v = (s, t, n) => i.listen(s, t, n);
138
141
  export {
139
142
  o as GlobalEventBus,
140
- d as emit,
141
- c as eventBus,
143
+ f as emit,
144
+ i as eventBus,
142
145
  v as listen,
143
- g as off,
144
- f as on,
145
- w as once
146
+ w as off,
147
+ d as on,
148
+ g as once
146
149
  };
147
150
  //# 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. Returns a promise that resolves with the event data.\n * @param eventName - Name of the event\n * @param handler - Handler function\n */\n once<T = unknown>(eventName: string, handler: EventHandler<T>): Promise<T> {\n return new Promise((resolve) => {\n const unsubscribe = this.on(eventName, (data: T) => {\n unsubscribe();\n handler(data);\n resolve(data);\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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const val = (inst as any)[prop as any];\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') return val.bind(inst);\n return val;\n },\n // Support direct function calls (unlikely) and other traps defensively\n apply(_target, thisArg, args) {\n const inst = GlobalEventBus.getInstance();\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (inst as any).apply(thisArg, args);\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\n */\nexport const once = <T = unknown>(\n eventName: string,\n handler: EventHandler<T>,\n) => eventBus.once(eventName, handler);\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","resolve","unsubscribe","stats","eventBus","_target","prop","inst","val","thisArg","args","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,I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AaD,CAAW;AAGrC,aAAI,OAAOE,KAAQ,aAAmBA,EAAI,KAAKD,CAAI,IAC5CC;AAAA,IACT;AAAA;AAAA,IAEA,MAAMH,GAASI,GAASC,GAAM;AAG5B,aAFanB,EAAe,YAAA,EAEP,MAAMkB,GAASC,CAAI;AAAA,IAC1C;AAAA,EAAA;AAEJ,GAKaC,IAAO,CAAcnB,GAAmBC,MACnDW,EAAS,KAAKZ,GAAWC,CAAI,GAKlBmB,IAAK,CAAcpB,GAAmBK,MACjDO,EAAS,GAAGZ,GAAWK,CAAO,GAKnBgB,IAAM,CAAcrB,GAAmBK,MAClDO,EAAS,IAAIZ,GAAWK,CAAO,GAKpBiB,IAAO,CAClBtB,GACAK,MACGO,EAAS,KAAKZ,GAAWK,CAAO,GAKxBkB,IAAS,CACpBvB,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\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;A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K,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,31 +1,31 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("./custom-elements-runtime.cjs.js"),E=require("./namespace-helpers-BsKQl3aH.cjs"),G=require("./custom-elements-runtime.store.cjs.js"),S=require("./logger-DiXdWaF-.cjs"),at=require("./custom-elements-runtime.directives.cjs.js"),F=o=>o?typeof URLSearchParams>"u"?{}:Object.fromEntries(new URLSearchParams(o)):{},et=o=>{if(!o||Object.keys(o).length===0)return"";try{return"?"+new URLSearchParams(o).toString()}catch{return""}},J=o=>o?/^\s*javascript\s*:/i.test(o):!1,tt=new WeakMap;function ot(o){return o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function q(o){if(!o)return"/";let c=o.replace(/\/+/g,"/");return c.startsWith("/")||(c="/"+c),c.length>1&&c.endsWith("/")&&(c=c.slice(0,-1)),c}function st(o){const c=o.path||"/",s=q(c),m=s==="/"?[]:s.split("/").filter(Boolean),h=[],l=[];for(let i=0;i<m.length;i++){const d=m[i];if(d==="*"){if(i!==m.length-1)return S.devWarn(`Route '${o.path}' contains a '*' splat in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};const g=`splat${h.length}`;h.push(g),l.push("__SPLAT__");continue}const b=d.match(/^:([A-Za-z0-9_-]+)(\*)?$/);if(b){const g=b[1],C=!!b[2];if(C&&i!==m.length-1)return S.devWarn(`Route '${o.path}' contains a splat param ':${g}*' in a non-terminal position; splats must be the last segment. This route will be ignored.`),{invalid:!0};h.push(g),l.push(C?"__SPLAT__":"([^/]+)");continue}l.push(ot(d))}let p;if(l.length===0)p="^/$";else if(l[l.length-1]==="__SPLAT__"){const d=l.slice(0,-1).join("/");d?p=`^/${d}(?:/(.*))?(?:/)?$`:p="^(?:/(.*))?(?:/)?$"}else p=`^/${l.join("/")}(?:/)?$`;try{return{regex:new RegExp(p),paramNames:h}}catch(i){return S.devWarn(`Failed to compile route regex for '${o.path}': ${String(i)}`),{invalid:!0}}}const I=(o,c)=>{const s=q(c);for(const m of o){let h=tt.get(m);if(h||(h=st(m),tt.set(m,h)),h.invalid)continue;const{regex:l,paramNames:p}=h,i=l.exec(s);if(i){const d={},b=g=>{try{return decodeURIComponent(g)}catch{return g}};for(let g=0;g<p.length;g++){const C=i[g+1]||"";d[p[g]]=C?b(C):""}return{route:m,params:d}}}return{route:null,params:{}}};function V(o,c){for(const s of o)if(I([s],c).route!==null)return s;return null}const H={};async function rt(o){if(o.component)return o.component;if(o.load){if(H[o.path])return H[o.path];try{const c=await o.load();return H[o.path]=c.default,c.default}catch{throw new Error(`Failed to load component for route: ${o.path}`)}}throw new Error(`No component or loader defined for route: ${o.path}`)}function nt(o){const{routes:c,base:s="",initialUrl:m,scrollToFragment:h=!0}=o,l=(()=>{if(!s)return"";const n=q(s);return n==="/"?"":n})(),p=typeof h=="boolean"?{enabled:!!h,offset:0,timeoutMs:2e3}:{enabled:h.enabled??!0,offset:h.offset??0,timeoutMs:h.timeoutMs??2e3};let i,d,b,g,C,B,D;const Y=async(n,e)=>{const t=V(c,n.path);if(!t||!t.beforeEnter)return!0;try{const r=await t.beforeEnter(n,e);return typeof r=="string"?(await v(r,!0),!1):r!==!1}catch(r){return S.devError("beforeEnter error",r),!1}},Q=async(n,e)=>{const t=V(c,n.path);if(!t||!t.onEnter)return!0;try{const r=await t.onEnter(n,e);return typeof r=="string"?(await v(r,!0),!1):r!==!1}catch(r){return S.devError("onEnter error",r),!1}},Z=(n,e)=>{const t=V(c,n.path);if(!(!t||!t.afterEnter))try{t.afterEnter(n,e)}catch(r){S.devError("afterEnter error",r)}};let w=0,O=null,P=null,L=null;async function a(n,e=0){try{const t=document.getElementById(n);if(!t)return!1;if(e&&e>0)try{const r=t.getBoundingClientRect(),$=Math.max(0,window.scrollY+r.top-e);typeof window.scrollTo=="function"&&window.scrollTo({top:$,behavior:"auto"})}catch{try{t.scrollIntoView()}catch{}}else if(typeof t.scrollIntoView=="function")try{t.scrollIntoView({behavior:"auto",block:"start",inline:"nearest"})}catch{try{t.scrollIntoView()}catch{}}return!0}catch{return!1}}function u(){if(O){try{O.disconnect()}catch{}O=null}if(P){try{clearTimeout(P)}catch{}P=null}}function y(n,e,t){w+=1;const r=w;if(L){try{L(!1)}catch{}L=null}return u(),new Promise($=>{L=$;const f=W=>{if(r===w){u();try{$(W)}finally{L=null}}};queueMicrotask(async()=>{if(r!==w)return f(!1);if(await a(n,e))return f(!0);if(typeof window.requestAnimationFrame=="function")window.requestAnimationFrame(async()=>{if(r!==w)return f(!1);if(await a(n,e))return f(!0);if(r!==w)return f(!1);const W=document.querySelector("router-view")||document.body;try{const _=new MutationObserver(async()=>{r===w&&await a(n,e)&&f(!0)});O=_,_.observe(W,{childList:!0,subtree:!0,attributes:!1}),P=window.setTimeout(()=>{if(r===w){try{_.disconnect()}catch{}O=null,P=null,f(!1)}},t??2e3)}catch{let R=0;const x=async()=>{if(r!==w)return f(!1);if(await a(n,e))return f(!0);R+=1,R<40?window.setTimeout(x,50):f(!1)};x()}});else{const W=document.querySelector("router-view")||document.body;try{const _=new MutationObserver(async()=>{r===w&&await a(n,e)&&f(!0)});O=_,_.observe(W,{childList:!0,subtree:!0,attributes:!1}),P=window.setTimeout(()=>{if(r===w){try{_.disconnect()}catch{}O=null,P=null,f(!1)}},t??2e3)}catch{let R=0;const x=async()=>{if(r!==w)return f(!1);if(await a(n,e))return f(!0);R+=1,R<40?window.setTimeout(x,50):f(!1)};x()}}})})}const v=async(n,e=!1)=>{try{const t=n.indexOf("#"),r=t>=0?n.slice(t+1):"",$=t>=0?n.slice(0,t):n,f=$.indexOf("?"),T=f>=0?$.slice(0,f):$,W=f>=0?F($.slice(f)):{},_=T.startsWith(l)?T.slice(l.length):T,R={path:q(_||"/"),query:W,fragment:r},x=I(c,R.path);if(!x.route)throw new Error(`No route found for ${R.path}`);const N=b.getState(),z={path:R.path,params:x.params,query:R.query,fragment:R.fragment};if(!await Y(z,N)||!await Q(z,N))return;if(typeof window<"u"&&typeof document<"u"){const k=et(R.query),X=l+R.path+(k||"")+(R.fragment?"#"+R.fragment:"");e?window.history.replaceState({},"",X):window.history.pushState({},"",X)}b.setState(z),Z(z,N);try{const k=z.fragment;p.enabled&&k&&typeof window<"u"&&typeof document<"u"&&y(String(k),p.offset,p.timeoutMs).catch(()=>{})}catch{}}catch(t){S.devError("Navigation error:",t)}};if(typeof window<"u"&&typeof document<"u"&&typeof m>"u"){i=()=>{const e=new URL(window.location.href),t=e.pathname,r=t.startsWith(l)?t.slice(l.length):t,$=q(r||"/"),f=F(e.search),T=e.hash&&e.hash.length?e.hash.slice(1):"";return{path:$,query:f,fragment:T}},d=i();const n=I(c,d.path);b=G.createStore({path:d.path,params:n.params,query:d.query,fragment:d.fragment}),g=async(e=!1)=>{const t=i();await v(t.path,e)},window.addEventListener("popstate",()=>g(!0)),C=e=>v(e,!1),B=e=>v(e,!0),D=()=>window.history.back()}else{i=()=>{const t=new URL(m||"/","http://localhost"),r=t.pathname,$=r.startsWith(l)?r.slice(l.length):r,f=q($||"/"),T=F(t.search),W=t.hash&&t.hash.length?t.hash.slice(1):"";return{path:f,query:T,fragment:W}},d=i();const n=I(c,d.path);b=G.createStore({path:d.path,params:n.params,query:d.query,fragment:d.fragment}),g=async()=>{const t=i();await e(t.path)};const e=async t=>{try{const r=t.indexOf("#"),$=r>=0?t.slice(r+1):"",f=r>=0?t.slice(0,r):t,T=f.indexOf("?"),W=T>=0?f.slice(0,T):f,_=T>=0?F(f.slice(T)):{},U=W.startsWith(l)?W.slice(l.length):W,x={path:q(U||"/"),query:_,fragment:$},N=I(c,x.path);if(!N.route)throw new Error(`No route found for ${x.path}`);const z=b.getState(),j={path:x.path,params:N.params,query:x.query,fragment:x.fragment},M=V(c,j.path);if(M?.beforeEnter){const k=await M.beforeEnter(j,z);if(typeof k=="string"){await e(k);return}if(k===!1)return}if(M?.onEnter){const k=await M.onEnter(j,z);if(typeof k=="string"){await e(k);return}if(k===!1)return}b.setState(j),M?.afterEnter&&M.afterEnter(j,z)}catch(r){throw S.devError("SSR navigation error:",r),r}};C=async t=>e(t),B=async t=>e(t),D=()=>{}}return{store:b,push:C,replace:B,back:D,subscribe:b.subscribe,matchRoute:n=>I(c,n),getCurrent:()=>b.getState(),resolveRouteComponent:rt,base:l,scrollToFragment:n=>{const e=n||b.getState().fragment;return!e||typeof window>"u"||typeof document>"u"?Promise.resolve(!1):y(String(e),p.offset,p.timeoutMs)}}}function ct(o,c){return I(o,c)}let K=null;function it(o){const c=nt(o);return K=c,A.component("router-view",async()=>{const s=()=>K||c;if(!s())return A.html`<div>Router not initialized.</div>`;const m=E.ref(s().getCurrent());let h;A.useOnConnected(()=>{try{s()&&typeof s().subscribe=="function"&&(h=s().subscribe(p=>{try{m.value=p}catch(i){S.devWarn("router-view subscription update failed",i)}}))}catch(p){S.devWarn("router-view subscribe failed",p)}}),A.useOnDisconnected(()=>{if(typeof h=="function")try{h()}catch(p){S.devWarn("router-view unsubscribe failed",p)}});const l=s().matchRoute(m.value.path);if(!l||!l.route)return A.html`<div>Not found</div>`;try{const i=await s().resolveRouteComponent(l.route);if(typeof i=="string")return{tag:i,props:{},children:[]};if(typeof i=="function"){const d=i();return(d instanceof Promise?d:Promise.resolve(d)).then(g=>typeof g=="string"?{tag:g,props:{},children:[]}:g)}return A.html`<div>Invalid route component</div>`}catch{return A.html`<div>Invalid route component</div>`}}),A.component("router-link",()=>{const s=A.useProps({to:"",tag:"a",replace:!1,exact:!1,activeClass:"active",exactActiveClass:"exact-active",ariaCurrentValue:"page",disabled:!1,external:!1,class:"",style:""}),m=()=>K||c,h=E.ref(m().getCurrent());let l;A.useStyle(()=>"a,button{display:inline-block;}");const p=E.ref(s.class||""),i=E.ref(s.style||"");A.useOnConnected(a=>{try{m()&&typeof m().subscribe=="function"&&(l=m().subscribe(u=>{try{h.value=u}catch(y){S.devWarn("router-link subscription update failed",y)}}))}catch(u){S.devWarn("router-link subscribe failed",u)}try{const u=a?._host;if(u instanceof HTMLElement){const y=u.getAttribute("class"),v=u.getAttribute("style");y&&(p.value=y),v&&(i.value=v),y!==null&&u.removeAttribute("class"),v!==null&&u.removeAttribute("style")}}catch(u){S.devWarn("router-link host migration failed",u)}}),A.useOnDisconnected(()=>{if(typeof l=="function")try{l()}catch(a){S.devWarn("router-link unsubscribe failed",a)}});const d=E.computed(()=>{const a=m().base??"",u=s.to||"";if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u)||u.startsWith("//"))return!1;const y=(u.split("#")[0]||"/").split("?")[0];try{let v=y;a&&v.startsWith(a)&&(v=v.slice(a.length)||"/");const n=q(h.value.path),e=q(v);return n===e}catch{return h.value.path===y}}),b=E.computed(()=>{const a=m().base??"",u=s.to||"";if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(u)||u.startsWith("//"))return!1;const y=(u.split("#")[0]||"/").split("?")[0];if(s.exact)return d.value;try{let v=y;a&&v.startsWith(a)&&(v=v.slice(a.length)||"/");const n=q(h.value.path),e=q(v);return e==="/"?n==="/":n===e?!0:n.startsWith(e.endsWith("/")?e:e+"/")}catch{return h.value&&typeof h.value.path=="string"&&h.value.path.startsWith(y)}}),g=E.computed(()=>{const a=String(s.to||"");if(J(a))return null;if(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a)||a.startsWith("//"))return a;const[u,y]=a.split("#"),[v,n]=(u||"").split("?"),e=m().base??"";let t=v||"/";e&&t.startsWith(e)&&(t=t.slice(e.length)||"/");const r=q(t||"/");return e+r+(n?"?"+n:"")+(y?"#"+y:"")}),C=E.computed(()=>{const u=(p&&p.value||s.class||"").split(/\s+/).filter(Boolean),y={};for(const v of u)y[v]=!0;return y}),B=E.computed(()=>({...C.value,[s.activeClass||"active"]:b.value,[s.exactActiveClass||"exact-active"]:d.value})),D=E.computed(()=>Object.keys(B.value).filter(a=>B.value[a]).join(" ")),Y=E.computed(()=>s.tag||"a"),Q=E.computed(()=>Y.value==="button"),Z=E.computed(()=>d.value?s.ariaCurrentValue:null),w=E.computed(()=>!!s.disabled),O=E.computed(()=>{const a=String(s.to||"");return(/^[a-zA-Z][a-zA-Z0-9+.-]*:/.test(a)||a.startsWith("//")||!!s.external)&&Y.value==="a"}),P=E.computed(()=>i&&i.value||s.style||""),L=a=>{if(a.defaultPrevented||a.button!==0||a.metaKey||a.altKey||a.ctrlKey||a.shiftKey)return;if(w.value){a.preventDefault();return}const u=String(s.to||"");if(J(u)){try{a.preventDefault()}catch{}S.devWarn("Blocked unsafe javascript: URI in router-link.to");return}if(O.value)return;a.preventDefault();const y=m();s.replace?y.replace(s.to):y.push(s.to)};return A.html`
2
- ${at.match().when(Q.value,A.html`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("./logger-CSALKaYm.cjs"),$=require("./namespace-helpers-4qeKVqQw.cjs"),x=require("./template-compiler-CA4YRaBu.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`
3
3
  <button
4
4
  part="button"
5
- class="${D.value}"
6
- style="${P.value||null}"
7
- aria-current="${Z.value}"
8
- disabled="${w.value?"":null}"
9
- aria-disabled="${w.value?"true":null}"
10
- tabindex="${w.value?"-1":null}"
11
- @click="${L}"
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}"
12
12
  >
13
13
  <slot></slot>
14
14
  </button>
15
- `).otherwise(A.html`
15
+ `).otherwise(x.html`
16
16
  <a
17
17
  part="link"
18
- href="${w.value?null:g.value}"
19
- class="${D.value}"
20
- style="${P.value||null}"
21
- aria-current="${Z.value}"
22
- aria-disabled="${w.value?"true":null}"
23
- tabindex="${w.value?"-1":null}"
24
- target="${O.value?"_blank":null}"
25
- rel="${O.value?"noopener noreferrer":null}"
26
- @click="${L}"
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}"
27
27
  ><slot></slot
28
28
  ></a>
29
29
  `).done()}
30
- `}),c}exports.initRouter=it;exports.matchRoute=I;exports.matchRouteSSR=ct;exports.normalizePathForRoute=q;exports.parseQuery=F;exports.resolveRouteComponent=rt;exports.serializeQuery=et;exports.useRouter=nt;
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;
31
31
  //# sourceMappingURL=custom-elements-runtime.router.cjs.js.map