eleva 1.0.1 → 1.1.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 (97) hide show
  1. package/README.md +21 -10
  2. package/dist/{eleva-plugins.cjs.js → eleva-plugins.cjs} +1002 -292
  3. package/dist/eleva-plugins.cjs.map +1 -0
  4. package/dist/eleva-plugins.d.cts +1352 -0
  5. package/dist/eleva-plugins.d.cts.map +1 -0
  6. package/dist/eleva-plugins.d.ts +1352 -0
  7. package/dist/eleva-plugins.d.ts.map +1 -0
  8. package/dist/{eleva-plugins.esm.js → eleva-plugins.js} +1002 -292
  9. package/dist/eleva-plugins.js.map +1 -0
  10. package/dist/eleva-plugins.umd.js +1001 -291
  11. package/dist/eleva-plugins.umd.js.map +1 -1
  12. package/dist/eleva-plugins.umd.min.js +1 -1
  13. package/dist/eleva-plugins.umd.min.js.map +1 -1
  14. package/dist/{eleva.cjs.js → eleva.cjs} +421 -191
  15. package/dist/eleva.cjs.map +1 -0
  16. package/dist/eleva.d.cts +1329 -0
  17. package/dist/eleva.d.cts.map +1 -0
  18. package/dist/eleva.d.ts +473 -226
  19. package/dist/eleva.d.ts.map +1 -0
  20. package/dist/{eleva.esm.js → eleva.js} +422 -192
  21. package/dist/eleva.js.map +1 -0
  22. package/dist/eleva.umd.js +420 -190
  23. package/dist/eleva.umd.js.map +1 -1
  24. package/dist/eleva.umd.min.js +1 -1
  25. package/dist/eleva.umd.min.js.map +1 -1
  26. package/dist/plugins/attr.cjs +279 -0
  27. package/dist/plugins/attr.cjs.map +1 -0
  28. package/dist/plugins/attr.d.cts +101 -0
  29. package/dist/plugins/attr.d.cts.map +1 -0
  30. package/dist/plugins/attr.d.ts +101 -0
  31. package/dist/plugins/attr.d.ts.map +1 -0
  32. package/dist/plugins/attr.js +276 -0
  33. package/dist/plugins/attr.js.map +1 -0
  34. package/dist/plugins/attr.umd.js +111 -22
  35. package/dist/plugins/attr.umd.js.map +1 -1
  36. package/dist/plugins/attr.umd.min.js +1 -1
  37. package/dist/plugins/attr.umd.min.js.map +1 -1
  38. package/dist/plugins/router.cjs +1873 -0
  39. package/dist/plugins/router.cjs.map +1 -0
  40. package/dist/plugins/router.d.cts +1296 -0
  41. package/dist/plugins/router.d.cts.map +1 -0
  42. package/dist/plugins/router.d.ts +1296 -0
  43. package/dist/plugins/router.d.ts.map +1 -0
  44. package/dist/plugins/router.js +1870 -0
  45. package/dist/plugins/router.js.map +1 -0
  46. package/dist/plugins/router.umd.js +482 -186
  47. package/dist/plugins/router.umd.js.map +1 -1
  48. package/dist/plugins/router.umd.min.js +1 -1
  49. package/dist/plugins/router.umd.min.js.map +1 -1
  50. package/dist/plugins/store.cjs +920 -0
  51. package/dist/plugins/store.cjs.map +1 -0
  52. package/dist/plugins/store.d.cts +266 -0
  53. package/dist/plugins/store.d.cts.map +1 -0
  54. package/dist/plugins/store.d.ts +266 -0
  55. package/dist/plugins/store.d.ts.map +1 -0
  56. package/dist/plugins/store.js +917 -0
  57. package/dist/plugins/store.js.map +1 -0
  58. package/dist/plugins/store.umd.js +410 -85
  59. package/dist/plugins/store.umd.js.map +1 -1
  60. package/dist/plugins/store.umd.min.js +1 -1
  61. package/dist/plugins/store.umd.min.js.map +1 -1
  62. package/package.json +112 -68
  63. package/src/core/Eleva.js +195 -115
  64. package/src/index.cjs +10 -0
  65. package/src/index.js +11 -0
  66. package/src/modules/Emitter.js +68 -20
  67. package/src/modules/Renderer.js +82 -20
  68. package/src/modules/Signal.js +43 -15
  69. package/src/modules/TemplateEngine.js +50 -9
  70. package/src/plugins/Attr.js +121 -19
  71. package/src/plugins/Router.js +526 -181
  72. package/src/plugins/Store.js +448 -69
  73. package/src/plugins/index.js +1 -0
  74. package/types/core/Eleva.d.ts +263 -169
  75. package/types/core/Eleva.d.ts.map +1 -1
  76. package/types/index.d.cts +3 -0
  77. package/types/index.d.cts.map +1 -0
  78. package/types/index.d.ts +5 -0
  79. package/types/index.d.ts.map +1 -1
  80. package/types/modules/Emitter.d.ts +73 -30
  81. package/types/modules/Emitter.d.ts.map +1 -1
  82. package/types/modules/Renderer.d.ts +48 -18
  83. package/types/modules/Renderer.d.ts.map +1 -1
  84. package/types/modules/Signal.d.ts +44 -16
  85. package/types/modules/Signal.d.ts.map +1 -1
  86. package/types/modules/TemplateEngine.d.ts +46 -11
  87. package/types/modules/TemplateEngine.d.ts.map +1 -1
  88. package/types/plugins/Attr.d.ts +83 -16
  89. package/types/plugins/Attr.d.ts.map +1 -1
  90. package/types/plugins/Router.d.ts +498 -207
  91. package/types/plugins/Router.d.ts.map +1 -1
  92. package/types/plugins/Store.d.ts +211 -37
  93. package/types/plugins/Store.d.ts.map +1 -1
  94. package/dist/eleva-plugins.cjs.js.map +0 -1
  95. package/dist/eleva-plugins.esm.js.map +0 -1
  96. package/dist/eleva.cjs.js.map +0 -1
  97. package/dist/eleva.esm.js.map +0 -1
@@ -1,167 +1,194 @@
1
1
  /**
2
- * @typedef {Object} ElevaConfig
3
- * @property {boolean} [debug=false]
4
- * Enable debug mode for verbose logging
5
- * @property {string} [prefix='e']
6
- * Prefix for component style scoping
7
- * @property {boolean} [async=true]
8
- * Enable async component setup
2
+ * Configuration options for the Eleva instance (reserved for future use).
3
+ * @typedef {Record<string, unknown>} ElevaConfig
9
4
  */
10
5
  /**
6
+ * Component definition object.
11
7
  * @typedef {Object} ComponentDefinition
12
8
  * @property {SetupFunction} [setup]
13
- * Optional setup function that initializes the component's state and returns reactive data
14
- * @property {TemplateFunction|string} template
15
- * Required function or string that defines the component's HTML structure
16
- * @property {StyleFunction|string} [style]
17
- * Optional function or string that provides component-scoped CSS styles
9
+ * Optional setup function that initializes the component's state and returns reactive data.
10
+ * @property {TemplateFunction | string} template
11
+ * Required function or string that defines the component's HTML structure.
12
+ * @property {StyleFunction | string} [style]
13
+ * Optional function or string that provides CSS styles for the component.
14
+ * Styles are preserved across DOM diffs via data-e-style markers.
18
15
  * @property {ChildrenMap} [children]
19
- * Optional object defining nested child components
16
+ * Optional object defining nested child components.
20
17
  */
21
18
  /**
19
+ * Setup function that initializes component state.
22
20
  * @callback SetupFunction
23
- * @param {ComponentContext} ctx - The component context with props, emitter, and signal factory
24
- * @returns {SetupResult|Promise<SetupResult>} Reactive data and lifecycle hooks
21
+ * @param {ComponentContext} ctx
22
+ * The component context with props, emitter, and signal factory.
23
+ * @returns {SetupResult | Promise<SetupResult>}
24
+ * Reactive data and lifecycle hooks.
25
25
  */
26
26
  /**
27
+ * Data returned from setup function, may include lifecycle hooks.
27
28
  * @typedef {Record<string, unknown> & LifecycleHooks} SetupResult
28
- * Data returned from setup function, may include lifecycle hooks
29
29
  */
30
30
  /**
31
+ * Template function that returns HTML markup.
31
32
  * @callback TemplateFunction
32
- * @param {ComponentContext} ctx - The component context
33
- * @returns {string|Promise<string>} HTML template string
33
+ * @param {ComponentContext & SetupResult} ctx
34
+ * The merged component context and setup data.
35
+ * @returns {string | Promise<string>}
36
+ * HTML template string.
34
37
  */
35
38
  /**
39
+ * Style function that returns CSS styles.
36
40
  * @callback StyleFunction
37
- * @param {ComponentContext} ctx - The component context
38
- * @returns {string} CSS styles string
41
+ * @param {ComponentContext & SetupResult} ctx
42
+ * The merged component context and setup data.
43
+ * @returns {string}
44
+ * CSS styles string.
39
45
  */
40
46
  /**
41
- * @typedef {Record<string, ComponentDefinition|string>} ChildrenMap
42
- * Map of CSS selectors to component definitions or registered component names
47
+ * Map of CSS selectors to component definitions or registered component names.
48
+ * @typedef {Record<string, ComponentDefinition | string>} ChildrenMap
43
49
  */
44
50
  /**
51
+ * Context passed to component setup function.
45
52
  * @typedef {Object} ComponentContext
46
53
  * @property {ComponentProps} props
47
- * Component properties passed during mounting
54
+ * Component properties passed during mounting.
48
55
  * @property {Emitter} emitter
49
- * Event emitter instance for component event handling
56
+ * Event emitter instance for component event handling.
50
57
  * @property {SignalFactory} signal
51
- * Factory function to create reactive Signal instances
58
+ * Factory function to create reactive Signal instances.
59
+ * @description
60
+ * Plugins may extend this context with additional properties (e.g., `ctx.router`, `ctx.store`).
61
+ * @see RouterContext - Router plugin injected context.
62
+ * @see StoreApi - Store plugin injected context.
52
63
  */
53
64
  /**
65
+ * Properties passed to a component during mounting.
54
66
  * @typedef {Record<string, unknown>} ComponentProps
55
- * Properties passed to a component during mounting
56
67
  */
57
68
  /**
58
- * @callback SignalFactory
59
- * @template T
60
- * @param {T} initialValue - The initial value for the signal
61
- * @returns {Signal<T>} A new Signal instance
69
+ * Factory function to create reactive Signal instances.
70
+ * @typedef {<T>(initialValue: T) => Signal<T>} SignalFactory
62
71
  */
63
72
  /**
73
+ * Lifecycle hooks that can be returned from setup function.
64
74
  * @typedef {Object} LifecycleHooks
65
75
  * @property {LifecycleHook} [onBeforeMount]
66
- * Hook called before component mounting
76
+ * Called before component mounting.
67
77
  * @property {LifecycleHook} [onMount]
68
- * Hook called after component mounting
78
+ * Called after component mounting.
69
79
  * @property {LifecycleHook} [onBeforeUpdate]
70
- * Hook called before component update
80
+ * Called before component update.
71
81
  * @property {LifecycleHook} [onUpdate]
72
- * Hook called after component update
82
+ * Called after component update.
73
83
  * @property {UnmountHook} [onUnmount]
74
- * Hook called during component unmounting
84
+ * Called during component unmounting.
75
85
  */
76
86
  /**
87
+ * Lifecycle hook function.
77
88
  * @callback LifecycleHook
78
- * @param {LifecycleHookContext} ctx - Context with container and component data
79
- * @returns {void|Promise<void>}
89
+ * @param {LifecycleHookContext} ctx
90
+ * Context with container and component data.
91
+ * @returns {void | Promise<void>}
80
92
  */
81
93
  /**
94
+ * Unmount hook function with cleanup resources.
82
95
  * @callback UnmountHook
83
- * @param {UnmountHookContext} ctx - Context with cleanup resources
84
- * @returns {void|Promise<void>}
96
+ * @param {UnmountHookContext} ctx
97
+ * Context with cleanup resources.
98
+ * @returns {void | Promise<void>}
85
99
  */
86
100
  /**
101
+ * Context passed to lifecycle hooks.
87
102
  * @typedef {Object} LifecycleHookContext
88
103
  * @property {HTMLElement} container
89
- * The DOM element where the component is mounted
104
+ * The DOM element where the component is mounted.
90
105
  * @property {ComponentContext & SetupResult} context
91
- * The component's reactive state and context data
106
+ * The component's reactive state and context data.
92
107
  */
93
108
  /**
109
+ * Context passed to unmount hook with cleanup resources.
94
110
  * @typedef {Object} UnmountHookContext
95
111
  * @property {HTMLElement} container
96
- * The DOM element where the component is mounted
112
+ * The DOM element where the component is mounted.
97
113
  * @property {ComponentContext & SetupResult} context
98
- * The component's reactive state and context data
114
+ * The component's reactive state and context data.
99
115
  * @property {CleanupResources} cleanup
100
- * Object containing cleanup functions and instances
116
+ * Object containing cleanup functions and instances.
101
117
  */
102
118
  /**
119
+ * Resources available for cleanup during unmount.
103
120
  * @typedef {Object} CleanupResources
104
- * @property {Array<UnsubscribeFunction>} watchers
105
- * Signal watcher cleanup functions
106
- * @property {Array<UnsubscribeFunction>} listeners
107
- * Event listener cleanup functions
108
- * @property {Array<MountResult>} children
109
- * Child component instances
121
+ * @property {UnsubscribeFunction[]} watchers
122
+ * Signal watcher cleanup functions.
123
+ * @property {UnsubscribeFunction[]} listeners
124
+ * Event listener cleanup functions.
125
+ * @property {MountResult[]} children
126
+ * Child component instances.
110
127
  */
111
128
  /**
129
+ * Result of mounting a component.
112
130
  * @typedef {Object} MountResult
113
131
  * @property {HTMLElement} container
114
- * The DOM element where the component is mounted
132
+ * The DOM element where the component is mounted.
115
133
  * @property {ComponentContext & SetupResult} data
116
- * The component's reactive state and context data
134
+ * The component's reactive state and context data.
117
135
  * @property {UnmountFunction} unmount
118
- * Function to clean up and unmount the component
136
+ * Function to clean up and unmount the component.
119
137
  */
120
138
  /**
139
+ * Function to unmount a component and clean up resources.
121
140
  * @callback UnmountFunction
122
141
  * @returns {Promise<void>}
123
142
  */
124
143
  /**
144
+ * Function to unsubscribe from events or watchers.
125
145
  * @callback UnsubscribeFunction
126
- * @returns {void|boolean}
146
+ * @returns {void | boolean}
127
147
  */
128
148
  /**
149
+ * Plugin interface for extending Eleva.
129
150
  * @typedef {Object} ElevaPlugin
130
- * @property {PluginInstallFunction} install
131
- * Function that installs the plugin into the Eleva instance
132
151
  * @property {string} name
133
- * Unique identifier name for the plugin
152
+ * Unique identifier name for the plugin.
153
+ * @property {string} [version]
154
+ * Optional version string for the plugin.
155
+ * @property {PluginInstallFunction} install
156
+ * Function that installs the plugin.
134
157
  * @property {PluginUninstallFunction} [uninstall]
135
- * Optional function to uninstall the plugin
158
+ * Optional function to uninstall the plugin.
136
159
  */
137
160
  /**
161
+ * Plugin install function.
138
162
  * @callback PluginInstallFunction
139
- * @param {Eleva} eleva - The Eleva instance
140
- * @param {PluginOptions} options - Plugin configuration options
141
- * @returns {void|Eleva|unknown} Optionally returns the Eleva instance or plugin result
163
+ * @param {Eleva} eleva
164
+ * The Eleva instance.
165
+ * @param {PluginOptions} [options]
166
+ * Plugin configuration options.
167
+ * @returns {void | Eleva | unknown}
142
168
  */
143
169
  /**
170
+ * Plugin uninstall function.
144
171
  * @callback PluginUninstallFunction
145
- * @param {Eleva} eleva - The Eleva instance
146
- * @returns {void}
172
+ * @param {Eleva} eleva
173
+ * The Eleva instance.
174
+ * @returns {void | Promise<void>}
147
175
  */
148
176
  /**
177
+ * Configuration options passed to a plugin during installation.
149
178
  * @typedef {Record<string, unknown>} PluginOptions
150
- * Configuration options passed to a plugin during installation
151
179
  */
152
180
  /**
153
- * @callback EventHandler
154
- * @param {Event} event - The DOM event object
155
- * @returns {void}
181
+ * Handler function for DOM events (e.g., click, input, submit).
182
+ * @typedef {(event: Event) => void} DOMEventHandler
156
183
  */
157
184
  /**
185
+ * Common DOM event names (prefixed with @ in templates).
158
186
  * @typedef {'click'|'submit'|'input'|'change'|'focus'|'blur'|'keydown'|'keyup'|'keypress'|'mouseenter'|'mouseleave'|'mouseover'|'mouseout'|'mousedown'|'mouseup'|'touchstart'|'touchend'|'touchmove'|'scroll'|'resize'|'load'|'error'|string} DOMEventName
159
- * Common DOM event names (prefixed with @ in templates)
160
187
  */
161
188
  /**
162
189
  * @class 🧩 Eleva
163
190
  * @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
164
- * scoped styles, and plugin support. Eleva manages component registration, plugin integration,
191
+ * component styles, and plugin support. Eleva manages component registration, plugin integration,
165
192
  * event handling, and DOM rendering with a focus on performance and developer experience.
166
193
  *
167
194
  * @example
@@ -191,11 +218,10 @@ export class Eleva {
191
218
  * Creates a new Eleva instance with the specified name and configuration.
192
219
  *
193
220
  * @public
221
+ * @constructor
194
222
  * @param {string} name - The unique identifier name for this Eleva instance.
195
- * @param {Record<string, unknown>} [config={}] - Optional configuration object for the instance.
196
- * May include framework-wide settings and default behaviors.
223
+ * @param {ElevaConfig} [config={}] - Optional configuration object for the instance.
197
224
  * @throws {Error} If the name is not provided or is not a string.
198
- * @returns {Eleva} A new Eleva instance.
199
225
  *
200
226
  * @example
201
227
  * const app = new Eleva("myApp");
@@ -206,19 +232,19 @@ export class Eleva {
206
232
  * app.mount(document.getElementById("app"), "myComponent", { name: "World" });
207
233
  *
208
234
  */
209
- constructor(name: string, config?: Record<string, unknown>);
210
- /** @public {string} The unique identifier name for this Eleva instance */
211
- public name: string;
212
- /** @public {Object<string, unknown>} Optional configuration object for the Eleva instance */
213
- public config: Record<string, unknown>;
214
- /** @public {Emitter} Instance of the event emitter for handling component events */
215
- public emitter: Emitter;
216
- /** @public {typeof Signal} Static reference to the Signal class for creating reactive state */
217
- public signal: typeof Signal;
218
- /** @public {typeof TemplateEngine} Static reference to the TemplateEngine class for template parsing */
219
- public templateEngine: typeof TemplateEngine;
220
- /** @public {Renderer} Instance of the renderer for handling DOM updates and patching */
221
- public renderer: Renderer;
235
+ constructor(name: string, config?: ElevaConfig);
236
+ /** @public @readonly {string} The unique identifier name for this Eleva instance */
237
+ public readonly name: string;
238
+ /** @public @readonly {Record<string, unknown>} Configuration object for the Eleva instance */
239
+ public readonly config: ElevaConfig;
240
+ /** @public @readonly {Emitter} Event emitter for handling component events */
241
+ public readonly emitter: Emitter;
242
+ /** @public @readonly {typeof Signal} Signal class for creating reactive state */
243
+ public readonly signal: typeof Signal;
244
+ /** @public @readonly {typeof TemplateEngine} TemplateEngine class for template parsing */
245
+ public readonly templateEngine: typeof TemplateEngine;
246
+ /** @public @readonly {Renderer} Renderer for handling DOM updates and patching */
247
+ public readonly renderer: Renderer;
222
248
  /** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */
223
249
  private _components;
224
250
  /** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
@@ -230,14 +256,16 @@ export class Eleva {
230
256
  * The plugin's install function will be called with the Eleva instance and provided options.
231
257
  * After installation, the plugin will be available for use by components.
232
258
  *
233
- * Note: Plugins that wrap core methods (e.g., mount) must be uninstalled in reverse order
259
+ * @note Plugins that wrap core methods (e.g., mount) must be uninstalled in reverse order
234
260
  * of installation (LIFO - Last In, First Out) to avoid conflicts.
235
261
  *
236
262
  * @public
237
263
  * @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
238
- * @param {Object<string, unknown>} [options={}] - Optional configuration options for the plugin.
239
- * @returns {Eleva} The Eleva instance (for method chaining).
264
+ * @param {PluginOptions} [options={}] - Optional configuration options for the plugin.
265
+ * @returns {Eleva | unknown} The Eleva instance (for method chaining) or the result returned by the plugin.
240
266
  * @throws {Error} If plugin does not have an install function.
267
+ * @see component - Register components after installing plugins.
268
+ * @see mount - Mount components to the DOM.
241
269
  * @example
242
270
  * app.use(myPlugin, { option1: "value1" });
243
271
  *
@@ -249,9 +277,7 @@ export class Eleva {
249
277
  * PluginB.uninstall(app);
250
278
  * PluginA.uninstall(app);
251
279
  */
252
- public use(plugin: ElevaPlugin, options?: {
253
- [x: string]: unknown;
254
- }): Eleva;
280
+ public use(plugin: ElevaPlugin, options?: PluginOptions): Eleva | unknown;
255
281
  /**
256
282
  * Registers a new component with the Eleva instance.
257
283
  * The component will be available for mounting using its registered name.
@@ -261,6 +287,7 @@ export class Eleva {
261
287
  * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
262
288
  * @returns {Eleva} The Eleva instance (for method chaining).
263
289
  * @throws {Error} If name is not a non-empty string or definition has no template.
290
+ * @see mount - Mount this component to the DOM.
264
291
  * @example
265
292
  * app.component("myButton", {
266
293
  * template: (ctx) => `<button>${ctx.props.text}</button>`,
@@ -271,45 +298,57 @@ export class Eleva {
271
298
  /**
272
299
  * Mounts a registered component to a DOM element.
273
300
  * This will initialize the component, set up its reactive state, and render it to the DOM.
301
+ * If the container already has a mounted Eleva instance, it is returned as-is.
302
+ * Unmount clears the container contents and removes the internal instance marker.
274
303
  *
275
304
  * @public
305
+ * @async
276
306
  * @param {HTMLElement} container - The DOM element where the component will be mounted.
277
- * @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.
278
- * @param {Object<string, unknown>} [props={}] - Optional properties to pass to the component.
307
+ * @param {string | ComponentDefinition} compName - The name of the registered component or a direct component definition.
308
+ * @param {ComponentProps} [props={}] - Optional properties to pass to the component.
279
309
  * @returns {Promise<MountResult>}
280
310
  * A Promise that resolves to an object containing:
281
311
  * - container: The mounted component's container element
282
312
  * - data: The component's reactive state and context
283
313
  * - unmount: Function to clean up and unmount the component
284
314
  * @throws {Error} If container is not a DOM element or component is not registered.
315
+ * @throws {Error} If setup function, template function, or style function throws.
285
316
  * @example
286
317
  * const instance = await app.mount(document.getElementById("app"), "myComponent", { text: "Click me" });
287
318
  * // Later...
288
- * instance.unmount();
319
+ * await instance.unmount();
289
320
  */
290
- public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: {
291
- [x: string]: unknown;
292
- }): Promise<MountResult>;
321
+ public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: ComponentProps): Promise<MountResult>;
293
322
  /**
294
323
  * Processes DOM elements for event binding based on attributes starting with "@".
295
- * This method handles the event delegation system and ensures proper cleanup of event listeners.
324
+ * This method attaches event listeners directly to elements and ensures proper cleanup.
325
+ * Bound `@event` attributes are removed after listeners are attached.
326
+ *
327
+ * Handler resolution order:
328
+ * 1. Direct context property lookup (e.g., context["handleClick"])
329
+ * 2. Template expression evaluation via TemplateEngine (e.g., "increment()")
296
330
  *
297
331
  * @private
298
332
  * @param {HTMLElement} container - The container element in which to search for event attributes.
299
- * @param {ComponentContext} context - The current component context containing event handler definitions.
300
- * @param {Array<() => void>} listeners - Array to collect cleanup functions for each event listener.
333
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
334
+ * @param {UnsubscribeFunction[]} listeners - Array to collect cleanup functions for each event listener.
301
335
  * @returns {void}
336
+ * @see TemplateEngine.evaluate - Expression evaluation. fallback.
302
337
  */
303
338
  private _processEvents;
304
339
  /**
305
- * Injects scoped styles into the component's container.
306
- * The styles are automatically prefixed to prevent style leakage to other components.
340
+ * Injects styles into the component's container.
341
+ * Styles are placed in a `<style>` element with a `data-e-style` attribute for identification.
342
+ *
343
+ * @note Styles are not automatically scoped - use unique class names or CSS nesting for isolation.
344
+ *
345
+ * Optimization: Skips DOM update if style content hasn't changed.
307
346
  *
308
347
  * @private
309
348
  * @param {HTMLElement} container - The container element where styles should be injected.
310
349
  * @param {string} compId - The component ID used to identify the style element.
311
- * @param {(function(ComponentContext): string)|string} styleDef - The component's style definition (function or string).
312
- * @param {ComponentContext} context - The current component context for style interpolation.
350
+ * @param {StyleFunction | string} styleDef - The component's style definition (function or string).
351
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
313
352
  * @returns {void}
314
353
  */
315
354
  private _injectStyles;
@@ -317,11 +356,13 @@ export class Eleva {
317
356
  * Extracts and evaluates props from an element's attributes that start with `:`.
318
357
  * Prop values are evaluated as expressions against the component context,
319
358
  * allowing direct passing of objects, arrays, and other complex types.
359
+ * Processed attributes are removed from the element after extraction.
320
360
  *
321
361
  * @private
322
- * @param {HTMLElement} element - The DOM element to extract props from
323
- * @param {ComponentContext} context - The component context for evaluating prop expressions
324
- * @returns {Record<string, string>} An object containing the evaluated props
362
+ * @param {HTMLElement} element - The DOM element to extract props from.
363
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
364
+ * @returns {ComponentProps} An object containing the evaluated props.
365
+ * @see TemplateEngine.evaluate - Expression evaluation.
325
366
  * @example
326
367
  * // For an element with attributes:
327
368
  * // <div :name="user.name" :data="items">
@@ -334,188 +375,241 @@ export class Eleva {
334
375
  * This method handles mounting of explicitly defined children components.
335
376
  *
336
377
  * The mounting process follows these steps:
337
- * 1. Cleans up any existing component instances
378
+ * 1. Finds matching DOM nodes within the container
338
379
  * 2. Mounts explicitly defined children components
339
380
  *
340
381
  * @private
341
- * @param {HTMLElement} container - The container element to mount components in
342
- * @param {Object<string, ComponentDefinition>} children - Map of selectors to component definitions for explicit children
343
- * @param {Array<MountResult>} childInstances - Array to store all mounted component instances
344
- * @param {ComponentContext} context - The parent component context for evaluating prop expressions
382
+ * @async
383
+ * @param {HTMLElement} container - The container element to mount components in.
384
+ * @param {ChildrenMap} children - Map of selectors to component definitions for explicit children.
385
+ * @param {MountResult[]} childInstances - Array to store all mounted component instances.
386
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
345
387
  * @returns {Promise<void>}
346
388
  *
347
389
  * @example
348
390
  * // Explicit children mounting:
349
391
  * const children = {
350
- * 'UserProfile': UserProfileComponent,
392
+ * 'user-profile': UserProfileComponent,
351
393
  * '#settings-panel': "settings-panel"
352
394
  * };
353
395
  */
354
396
  private _mountComponents;
355
397
  }
356
- export type ElevaConfig = {
357
- /**
358
- * Enable debug mode for verbose logging
359
- */
360
- debug?: boolean | undefined;
361
- /**
362
- * Prefix for component style scoping
363
- */
364
- prefix?: string | undefined;
365
- /**
366
- * Enable async component setup
367
- */
368
- async?: boolean | undefined;
369
- };
398
+ /**
399
+ * Configuration options for the Eleva instance (reserved for future use).
400
+ */
401
+ export type ElevaConfig = Record<string, unknown>;
402
+ /**
403
+ * Component definition object.
404
+ */
370
405
  export type ComponentDefinition = {
371
406
  /**
372
- * Optional setup function that initializes the component's state and returns reactive data
407
+ * Optional setup function that initializes the component's state and returns reactive data.
373
408
  */
374
409
  setup?: SetupFunction | undefined;
375
410
  /**
376
- * Required function or string that defines the component's HTML structure
411
+ * Required function or string that defines the component's HTML structure.
377
412
  */
378
413
  template: TemplateFunction | string;
379
414
  /**
380
- * Optional function or string that provides component-scoped CSS styles
415
+ * Optional function or string that provides CSS styles for the component.
416
+ * Styles are preserved across DOM diffs via data-e-style markers.
381
417
  */
382
418
  style?: string | StyleFunction | undefined;
383
419
  /**
384
- * Optional object defining nested child components
420
+ * Optional object defining nested child components.
385
421
  */
386
422
  children?: ChildrenMap | undefined;
387
423
  };
424
+ /**
425
+ * Setup function that initializes component state.
426
+ */
388
427
  export type SetupFunction = (ctx: ComponentContext) => SetupResult | Promise<SetupResult>;
389
428
  /**
390
- * Data returned from setup function, may include lifecycle hooks
429
+ * Data returned from setup function, may include lifecycle hooks.
391
430
  */
392
431
  export type SetupResult = Record<string, unknown> & LifecycleHooks;
393
- export type TemplateFunction = (ctx: ComponentContext) => string | Promise<string>;
394
- export type StyleFunction = (ctx: ComponentContext) => string;
395
432
  /**
396
- * Map of CSS selectors to component definitions or registered component names
433
+ * Template function that returns HTML markup.
434
+ */
435
+ export type TemplateFunction = (ctx: ComponentContext & SetupResult) => string | Promise<string>;
436
+ /**
437
+ * Style function that returns CSS styles.
438
+ */
439
+ export type StyleFunction = (ctx: ComponentContext & SetupResult) => string;
440
+ /**
441
+ * Map of CSS selectors to component definitions or registered component names.
397
442
  */
398
443
  export type ChildrenMap = Record<string, ComponentDefinition | string>;
444
+ /**
445
+ * Context passed to component setup function.
446
+ */
399
447
  export type ComponentContext = {
400
448
  /**
401
- * Component properties passed during mounting
449
+ * Component properties passed during mounting.
402
450
  */
403
451
  props: ComponentProps;
404
452
  /**
405
- * Event emitter instance for component event handling
453
+ * Event emitter instance for component event handling.
406
454
  */
407
455
  emitter: Emitter;
408
456
  /**
409
- * Factory function to create reactive Signal instances
457
+ * Factory function to create reactive Signal instances.
410
458
  */
411
459
  signal: SignalFactory;
412
460
  };
413
461
  /**
414
- * Properties passed to a component during mounting
462
+ * Properties passed to a component during mounting.
415
463
  */
416
464
  export type ComponentProps = Record<string, unknown>;
417
- export type SignalFactory = () => any;
465
+ /**
466
+ * Factory function to create reactive Signal instances.
467
+ */
468
+ export type SignalFactory = <T>(initialValue: T) => Signal<T>;
469
+ /**
470
+ * Lifecycle hooks that can be returned from setup function.
471
+ */
418
472
  export type LifecycleHooks = {
419
473
  /**
420
- * Hook called before component mounting
474
+ * Called before component mounting.
421
475
  */
422
476
  onBeforeMount?: LifecycleHook | undefined;
423
477
  /**
424
- * Hook called after component mounting
478
+ * Called after component mounting.
425
479
  */
426
480
  onMount?: LifecycleHook | undefined;
427
481
  /**
428
- * Hook called before component update
482
+ * Called before component update.
429
483
  */
430
484
  onBeforeUpdate?: LifecycleHook | undefined;
431
485
  /**
432
- * Hook called after component update
486
+ * Called after component update.
433
487
  */
434
488
  onUpdate?: LifecycleHook | undefined;
435
489
  /**
436
- * Hook called during component unmounting
490
+ * Called during component unmounting.
437
491
  */
438
492
  onUnmount?: UnmountHook | undefined;
439
493
  };
494
+ /**
495
+ * Lifecycle hook function.
496
+ */
440
497
  export type LifecycleHook = (ctx: LifecycleHookContext) => void | Promise<void>;
498
+ /**
499
+ * Unmount hook function with cleanup resources.
500
+ */
441
501
  export type UnmountHook = (ctx: UnmountHookContext) => void | Promise<void>;
502
+ /**
503
+ * Context passed to lifecycle hooks.
504
+ */
442
505
  export type LifecycleHookContext = {
443
506
  /**
444
- * The DOM element where the component is mounted
507
+ * The DOM element where the component is mounted.
445
508
  */
446
509
  container: HTMLElement;
447
510
  /**
448
- * The component's reactive state and context data
511
+ * The component's reactive state and context data.
449
512
  */
450
513
  context: ComponentContext & SetupResult;
451
514
  };
515
+ /**
516
+ * Context passed to unmount hook with cleanup resources.
517
+ */
452
518
  export type UnmountHookContext = {
453
519
  /**
454
- * The DOM element where the component is mounted
520
+ * The DOM element where the component is mounted.
455
521
  */
456
522
  container: HTMLElement;
457
523
  /**
458
- * The component's reactive state and context data
524
+ * The component's reactive state and context data.
459
525
  */
460
526
  context: ComponentContext & SetupResult;
461
527
  /**
462
- * Object containing cleanup functions and instances
528
+ * Object containing cleanup functions and instances.
463
529
  */
464
530
  cleanup: CleanupResources;
465
531
  };
532
+ /**
533
+ * Resources available for cleanup during unmount.
534
+ */
466
535
  export type CleanupResources = {
467
536
  /**
468
- * Signal watcher cleanup functions
537
+ * Signal watcher cleanup functions.
469
538
  */
470
- watchers: Array<UnsubscribeFunction>;
539
+ watchers: UnsubscribeFunction[];
471
540
  /**
472
- * Event listener cleanup functions
541
+ * Event listener cleanup functions.
473
542
  */
474
- listeners: Array<UnsubscribeFunction>;
543
+ listeners: UnsubscribeFunction[];
475
544
  /**
476
- * Child component instances
545
+ * Child component instances.
477
546
  */
478
- children: Array<MountResult>;
547
+ children: MountResult[];
479
548
  };
549
+ /**
550
+ * Result of mounting a component.
551
+ */
480
552
  export type MountResult = {
481
553
  /**
482
- * The DOM element where the component is mounted
554
+ * The DOM element where the component is mounted.
483
555
  */
484
556
  container: HTMLElement;
485
557
  /**
486
- * The component's reactive state and context data
558
+ * The component's reactive state and context data.
487
559
  */
488
560
  data: ComponentContext & SetupResult;
489
561
  /**
490
- * Function to clean up and unmount the component
562
+ * Function to clean up and unmount the component.
491
563
  */
492
564
  unmount: UnmountFunction;
493
565
  };
566
+ /**
567
+ * Function to unmount a component and clean up resources.
568
+ */
494
569
  export type UnmountFunction = () => Promise<void>;
570
+ /**
571
+ * Function to unsubscribe from events or watchers.
572
+ */
495
573
  export type UnsubscribeFunction = () => void | boolean;
574
+ /**
575
+ * Plugin interface for extending Eleva.
576
+ */
496
577
  export type ElevaPlugin = {
497
578
  /**
498
- * Function that installs the plugin into the Eleva instance
579
+ * Unique identifier name for the plugin.
499
580
  */
500
- install: PluginInstallFunction;
581
+ name: string;
501
582
  /**
502
- * Unique identifier name for the plugin
583
+ * Optional version string for the plugin.
503
584
  */
504
- name: string;
585
+ version?: string | undefined;
586
+ /**
587
+ * Function that installs the plugin.
588
+ */
589
+ install: PluginInstallFunction;
505
590
  /**
506
- * Optional function to uninstall the plugin
591
+ * Optional function to uninstall the plugin.
507
592
  */
508
593
  uninstall?: PluginUninstallFunction | undefined;
509
594
  };
510
- export type PluginInstallFunction = (eleva: Eleva, options: PluginOptions) => void | Eleva | unknown;
511
- export type PluginUninstallFunction = (eleva: Eleva) => void;
512
595
  /**
513
- * Configuration options passed to a plugin during installation
596
+ * Plugin install function.
597
+ */
598
+ export type PluginInstallFunction = (eleva: Eleva, options?: PluginOptions | undefined) => void | Eleva | unknown;
599
+ /**
600
+ * Plugin uninstall function.
601
+ */
602
+ export type PluginUninstallFunction = (eleva: Eleva) => void | Promise<void>;
603
+ /**
604
+ * Configuration options passed to a plugin during installation.
514
605
  */
515
606
  export type PluginOptions = Record<string, unknown>;
516
- export type EventHandler = (event: Event) => void;
517
607
  /**
518
- * Common DOM event names (prefixed with @ in templates)
608
+ * Handler function for DOM events (e.g., click, input, submit).
609
+ */
610
+ export type DOMEventHandler = (event: Event) => void;
611
+ /**
612
+ * Common DOM event names (prefixed with @ in templates).
519
613
  */
520
614
  export type DOMEventName = "click" | "submit" | "input" | "change" | "focus" | "blur" | "keydown" | "keyup" | "keypress" | "mouseenter" | "mouseleave" | "mouseover" | "mouseout" | "mousedown" | "mouseup" | "touchstart" | "touchend" | "touchmove" | "scroll" | "resize" | "load" | "error" | string;
521
615
  import { Emitter } from "../modules/Emitter.js";