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
@@ -0,0 +1,1329 @@
1
+ /**
2
+ * @module eleva/emitter
3
+ * @fileoverview Event emitter for publish-subscribe communication between components.
4
+ */
5
+ /**
6
+ * Callback function invoked when an event is emitted.
7
+ * @callback EventHandler
8
+ * @param {...any} args
9
+ * Event arguments passed to the handler.
10
+ * @returns {void | Promise<void>}
11
+ */
12
+ /**
13
+ * Function to unsubscribe an event handler.
14
+ * @callback EventUnsubscribe
15
+ * @returns {void}
16
+ */
17
+ /**
18
+ * Event name string identifier.
19
+ * @typedef {string} EventName
20
+ * @description
21
+ * Recommended convention: 'namespace:action' (e.g., 'user:login').
22
+ * This pattern prevents naming collisions and improves code readability.
23
+ *
24
+ * Common namespaces:
25
+ * - `user:` - User-related events (login, logout, update)
26
+ * - `component:` - Component lifecycle events (mount, unmount)
27
+ * - `router:` - Navigation events (beforeEach, afterEach)
28
+ * - `store:` - State management events (change, error)
29
+ * @example
30
+ * 'user:login' // User logged in
31
+ * 'cart:update' // Shopping cart updated
32
+ * 'component:mount' // Component was mounted
33
+ */
34
+ /**
35
+ * Interface describing the public API of an Emitter.
36
+ * @typedef {Object} EmitterLike
37
+ * @property {(event: string, handler: EventHandler) => EventUnsubscribe} on
38
+ * Subscribe to an event.
39
+ * @property {(event: string, handler?: EventHandler) => void} off
40
+ * Unsubscribe from an event.
41
+ * @property {(event: string, ...args: unknown[]) => void} emit
42
+ * Emit an event with arguments.
43
+ */
44
+ /**
45
+ * @class 📡 Emitter
46
+ * @classdesc A robust event emitter that enables inter-component communication through a publish-subscribe pattern.
47
+ * Components can emit events and listen for events from other components, facilitating loose coupling
48
+ * and reactive updates across the application.
49
+ * Events are handled synchronously in the order they were registered, with proper cleanup
50
+ * of unsubscribed handlers.
51
+ *
52
+ * Event names should follow the format 'namespace:action' for consistency and organization.
53
+ *
54
+ * @example
55
+ * // Basic usage
56
+ * const emitter = new Emitter();
57
+ * emitter.on('user:login', (user) => console.log(`User logged in: ${user.name}`));
58
+ * emitter.emit('user:login', { name: 'John' }); // Logs: "User logged in: John"
59
+ *
60
+ * @example
61
+ * // With unsubscribe
62
+ * const unsub = emitter.on('cart:update', (items) => {
63
+ * console.log(`Cart has ${items.length} items`);
64
+ * });
65
+ * emitter.emit('cart:update', [{ id: 1, name: 'Book' }]); // Logs: "Cart has 1 items"
66
+ * unsub(); // Stop listening
67
+ * emitter.emit('cart:update', []); // No log output
68
+ *
69
+ * @example
70
+ * // Multiple arguments
71
+ * emitter.on('order:placed', (orderId, amount, currency) => {
72
+ * console.log(`Order ${orderId}: ${amount} ${currency}`);
73
+ * });
74
+ * emitter.emit('order:placed', 'ORD-123', 99.99, 'USD');
75
+ *
76
+ * @example
77
+ * // Common event patterns
78
+ * // Lifecycle events
79
+ * emitter.on('component:mount', (component) => {});
80
+ * emitter.on('component:unmount', (component) => {});
81
+ * // Note: These lifecycle names are conventions; Eleva core does not emit them by default.
82
+ * // State events
83
+ * emitter.on('state:change', (newState, oldState) => {});
84
+ * // Navigation events
85
+ * emitter.on('router:navigate', (to, from) => {});
86
+ *
87
+ * @implements {EmitterLike}
88
+ */
89
+ declare class Emitter implements EmitterLike {
90
+ /**
91
+ * Map of event names to their registered handler functions
92
+ * @private
93
+ * @type {Map<string, Set<EventHandler>>}
94
+ */
95
+ private _events;
96
+ /**
97
+ * Registers an event handler for the specified event name.
98
+ * The handler will be called with the event data when the event is emitted.
99
+ * Event names should follow the format 'namespace:action' for consistency.
100
+ *
101
+ * @public
102
+ * @param {string} event - The name of the event to listen for (e.g., 'user:login').
103
+ * @param {EventHandler} handler - The callback function to invoke when the event occurs.
104
+ * Note: Handlers returning Promises are NOT awaited. For async operations,
105
+ * handle promise resolution within your handler.
106
+ * @returns {EventUnsubscribe} A function to unsubscribe the event handler.
107
+ *
108
+ * @example
109
+ * // Basic subscription
110
+ * const unsubscribe = emitter.on('user:login', (user) => console.log(user));
111
+ *
112
+ * @example
113
+ * // Handler with typed parameter
114
+ * emitter.on('user:update', (user) => {
115
+ * console.log(`User ${user.id}: ${user.name}`);
116
+ * });
117
+ *
118
+ * @example
119
+ * // Cleanup
120
+ * unsubscribe(); // Stops listening for the event
121
+ */
122
+ public on(event: string, handler: EventHandler): EventUnsubscribe;
123
+ /**
124
+ * Removes an event handler for the specified event name.
125
+ * Automatically cleans up empty event sets to prevent memory leaks.
126
+ *
127
+ * Behavior varies based on whether handler is provided:
128
+ * - With handler: Removes only that specific handler function (O(1) Set deletion)
129
+ * - Without handler: Removes ALL handlers for the event (O(1) Map deletion)
130
+ *
131
+ * @public
132
+ * @param {string} event - The name of the event to remove handlers from.
133
+ * @param {EventHandler} [handler] - The specific handler to remove. If omitted, all handlers are removed.
134
+ * @returns {void}
135
+ *
136
+ * @example
137
+ * // Remove a specific handler
138
+ * const loginHandler = (user) => console.log(user);
139
+ * emitter.on('user:login', loginHandler);
140
+ * emitter.off('user:login', loginHandler);
141
+ *
142
+ * @example
143
+ * // Remove all handlers for an event
144
+ * emitter.off('user:login');
145
+ */
146
+ public off(event: string, handler?: EventHandler): void;
147
+ /**
148
+ * Emits an event with the specified data to all registered handlers.
149
+ * Handlers are called synchronously in the order they were registered.
150
+ * If no handlers are registered for the event, the emission is silently ignored.
151
+ * Handlers that return promises are not awaited.
152
+ *
153
+ * Error propagation behavior:
154
+ * - If a handler throws synchronously, the error propagates immediately
155
+ * - Remaining handlers in the iteration are NOT called after an error
156
+ * - For error-resilient emission, wrap your emit call in try/catch
157
+ * - Async handler rejections are not caught (fire-and-forget)
158
+ *
159
+ * @public
160
+ * @param {string} event - The name of the event to emit.
161
+ * @param {...any} args - Optional arguments to pass to the event handlers.
162
+ * @returns {void}
163
+ * @throws {Error} If a handler throws synchronously, the error propagates to the caller.
164
+ *
165
+ * @example
166
+ * // Emit an event with data
167
+ * emitter.emit('user:login', { name: 'John', role: 'admin' });
168
+ *
169
+ * @example
170
+ * // Emit an event with multiple arguments
171
+ * emitter.emit('order:placed', 'ORD-123', 99.99, 'USD');
172
+ *
173
+ * @example
174
+ * // Emit without data
175
+ * emitter.emit('app:ready');
176
+ */
177
+ public emit(event: string, ...args: any[]): void;
178
+ }
179
+ /**
180
+ * Callback function invoked when an event is emitted.
181
+ */
182
+ type EventHandler = (...args: any[]) => void | Promise<void>;
183
+ /**
184
+ * Function to unsubscribe an event handler.
185
+ */
186
+ type EventUnsubscribe = () => void;
187
+ /**
188
+ * Interface describing the public API of an Emitter.
189
+ */
190
+ type EmitterLike = {
191
+ /**
192
+ * Subscribe to an event.
193
+ */
194
+ on: (event: string, handler: EventHandler) => EventUnsubscribe;
195
+ /**
196
+ * Unsubscribe from an event.
197
+ */
198
+ off: (event: string, handler?: EventHandler) => void;
199
+ /**
200
+ * Emit an event with arguments.
201
+ */
202
+ emit: (event: string, ...args: unknown[]) => void;
203
+ };
204
+
205
+ /**
206
+ * @module eleva/signal
207
+ * @fileoverview Reactive Signal primitive for fine-grained state management and change notification.
208
+ */
209
+ /**
210
+ * Callback function invoked when a signal's value changes.
211
+ * @template T The type of value held by the signal.
212
+ * @callback SignalWatcher
213
+ * @param {T} value
214
+ * The new value of the signal.
215
+ * @returns {void}
216
+ */
217
+ /**
218
+ * Function to unsubscribe a watcher from a signal.
219
+ * @callback SignalUnsubscribe
220
+ * @returns {boolean}
221
+ * True if the watcher was successfully removed, false if already removed.
222
+ * Safe to call multiple times (idempotent).
223
+ */
224
+ /**
225
+ * Interface describing the public API of a Signal.
226
+ * @template T The type of value held by the signal.
227
+ * @typedef {Object} SignalLike
228
+ * @property {T} value
229
+ * The current value of the signal.
230
+ * @property {function(SignalWatcher<T>): SignalUnsubscribe} watch
231
+ * Subscribe to value changes.
232
+ */
233
+ /**
234
+ * @class ⚡ Signal
235
+ * @classdesc A reactive data holder that enables fine-grained reactivity in the Eleva framework.
236
+ * Signals notify registered watchers synchronously when their value changes, enabling efficient
237
+ * DOM updates through targeted patching rather than full re-renders.
238
+ * Synchronous notification preserves stack traces and allows immediate value inspection.
239
+ * Render batching is handled at the component level, not the signal level.
240
+ * The class is generic, allowing type-safe handling of any value type T.
241
+ *
242
+ * @template T The type of value held by the signal.
243
+ *
244
+ * @example
245
+ * // Basic usage
246
+ * const count = new Signal(0);
247
+ * count.watch((value) => console.log(`Count changed to: ${value}`));
248
+ * count.value = 1; // Logs: "Count changed to: 1"
249
+ *
250
+ * @example
251
+ * // With unsubscribe
252
+ * const name = new Signal("John");
253
+ * const unsubscribe = name.watch((value) => console.log(value));
254
+ * name.value = "Jane"; // Logs: "Jane"
255
+ * unsubscribe(); // Stop watching
256
+ * name.value = "Bob"; // No log output
257
+ *
258
+ * @example
259
+ * // With objects
260
+ * const position = new Signal({ x: 0, y: 0 });
261
+ * position.value = { x: 10, y: 20 }; // Triggers watchers
262
+ *
263
+ * @implements {SignalLike<T>}
264
+ */
265
+ declare class Signal<T> implements SignalLike<T> {
266
+ /**
267
+ * Creates a new Signal instance with the specified initial value.
268
+ *
269
+ * @public
270
+ * @constructor
271
+ * @param {T} value - The initial value of the signal.
272
+ *
273
+ * @example
274
+ * // Primitive types
275
+ * const count = new Signal(0); // Signal<number>
276
+ * const name = new Signal("John"); // Signal<string>
277
+ * const active = new Signal(true); // Signal<boolean>
278
+ *
279
+ * @example
280
+ * // Complex types
281
+ * const items = new Signal([]); // Signal holding an array
282
+ * const user = new Signal(null); // Signal holding nullable object
283
+ */
284
+ constructor(value: T);
285
+ /**
286
+ * Internal storage for the signal's current value.
287
+ * @private
288
+ * @type {T}
289
+ */
290
+ private _value;
291
+ /**
292
+ * Collection of callback functions to be notified when value changes.
293
+ * @private
294
+ * @type {Set<SignalWatcher<T>>}
295
+ */
296
+ private _watchers;
297
+ /**
298
+ * Sets a new value for the signal and synchronously notifies all registered watchers if the value has changed.
299
+ * Synchronous notification preserves stack traces and ensures immediate value consistency.
300
+ *
301
+ * Uses strict equality (===) for comparison. For objects/arrays, watchers are only notified
302
+ * if the reference changes, not if properties are mutated. To trigger updates with objects,
303
+ * assign a new reference: `signal.value = { ...signal.value, updated: true }`.
304
+ *
305
+ * @public
306
+ * @param {T} newVal - The new value to set.
307
+ * @returns {void}
308
+ */
309
+ public set value(newVal: T);
310
+ /**
311
+ * Gets the current value of the signal.
312
+ *
313
+ * @public
314
+ * @returns {T} The current value.
315
+ */
316
+ public get value(): T;
317
+ /**
318
+ * Registers a watcher function that will be called whenever the signal's value changes.
319
+ * The watcher will receive the new value as its argument.
320
+ *
321
+ * @public
322
+ * @param {SignalWatcher<T>} fn - The callback function to invoke on value change.
323
+ * @returns {SignalUnsubscribe} A function to unsubscribe the watcher.
324
+ * Returns true if watcher was removed, false if it wasn't registered.
325
+ * Safe to call multiple times (idempotent after first call).
326
+ *
327
+ * @example
328
+ * // Basic watching
329
+ * const unsubscribe = signal.watch((value) => console.log(value));
330
+ *
331
+ * @example
332
+ * // Stop watching
333
+ * unsubscribe(); // Returns true if watcher was removed
334
+ * unsubscribe(); // Returns false (already removed, safe to call again)
335
+ *
336
+ * @example
337
+ * // Multiple watchers
338
+ * const unsub1 = signal.watch((v) => console.log("Watcher 1:", v));
339
+ * const unsub2 = signal.watch((v) => console.log("Watcher 2:", v));
340
+ * signal.value = "test"; // Both watchers are called
341
+ */
342
+ public watch(fn: SignalWatcher<T>): SignalUnsubscribe;
343
+ /**
344
+ * Synchronously notifies all registered watchers of the value change.
345
+ * This preserves stack traces for debugging and ensures immediate
346
+ * value consistency. Render batching is handled at the component level.
347
+ *
348
+ * @note If a watcher throws, subsequent watchers are NOT called.
349
+ * The error propagates to the caller (the setter).
350
+ *
351
+ * @private
352
+ * @returns {void}
353
+ */
354
+ private _notify;
355
+ }
356
+ /**
357
+ * Callback function invoked when a signal's value changes.
358
+ */
359
+ type SignalWatcher<T> = (value: T) => void;
360
+ /**
361
+ * Function to unsubscribe a watcher from a signal.
362
+ */
363
+ type SignalUnsubscribe = () => boolean;
364
+ /**
365
+ * Interface describing the public API of a Signal.
366
+ */
367
+ type SignalLike<T> = {
368
+ /**
369
+ * The current value of the signal.
370
+ */
371
+ value: T;
372
+ /**
373
+ * Subscribe to value changes.
374
+ */
375
+ watch: (arg0: SignalWatcher<T>) => SignalUnsubscribe;
376
+ };
377
+
378
+ /**
379
+ * @module eleva/template-engine
380
+ * @fileoverview Expression evaluator for directive attributes and property bindings.
381
+ */
382
+ /**
383
+ * Data context object for expression evaluation.
384
+ * @typedef {Record<string, unknown>} ContextData
385
+ * @description Contains variables and functions available during template evaluation.
386
+ */
387
+ /**
388
+ * JavaScript expression string to be evaluated.
389
+ * @typedef {string} Expression
390
+ * @description A JavaScript expression evaluated against a ContextData object.
391
+ */
392
+ /**
393
+ * Result of evaluating an expression.
394
+ * @typedef {unknown} EvaluationResult
395
+ * @description Can be string, number, boolean, object, function, or any JavaScript value.
396
+ */
397
+ /**
398
+ * Compiled expression function cached for performance.
399
+ * @typedef {(data: ContextData) => EvaluationResult} CompiledExpressionFunction
400
+ * @description Pre-compiled function that evaluates an expression against context data.
401
+ */
402
+ /**
403
+ * @class 🔒 TemplateEngine
404
+ * @classdesc A minimal expression evaluator for Eleva's directive attributes.
405
+ * Evaluates JavaScript expressions against a component's context data.
406
+ * Used internally for `@event` handlers and `:prop` bindings.
407
+ *
408
+ * All methods are static and can be called directly on the class.
409
+ *
410
+ * @example
411
+ * // Property access
412
+ * TemplateEngine.evaluate("user.name", { user: { name: "John" } });
413
+ * // Result: "John"
414
+ *
415
+ * @example
416
+ * // Function reference (for @event handlers)
417
+ * TemplateEngine.evaluate("handleClick", { handleClick: () => console.log("clicked") });
418
+ * // Result: [Function]
419
+ *
420
+ * @example
421
+ * // Signal values (for :prop bindings)
422
+ * TemplateEngine.evaluate("count.value", { count: { value: 42 } });
423
+ * // Result: 42
424
+ *
425
+ * @example
426
+ * // Complex expressions
427
+ * TemplateEngine.evaluate("items.filter(i => i.active)", { items: [{active: true}, {active: false}] });
428
+ * // Result: [{active: true}]
429
+ */
430
+ declare class TemplateEngine {
431
+ /**
432
+ * Cache for compiled expression functions.
433
+ * Stores compiled Function objects keyed by expression string for O(1) lookup.
434
+ * The cache persists for the application lifetime and is never cleared.
435
+ * This improves performance for repeated evaluations of the same expression.
436
+ *
437
+ * Memory consideration: For applications with highly dynamic expressions
438
+ * (e.g., user-generated), memory usage grows unbounded. This is typically
439
+ * not an issue for static templates where expressions are finite.
440
+ *
441
+ * @static
442
+ * @private
443
+ * @type {Map<string, CompiledExpressionFunction>}
444
+ */
445
+ private static _functionCache;
446
+ /**
447
+ * Evaluates an expression in the context of the provided data object.
448
+ * Used for resolving `@event` handlers and `:prop` bindings.
449
+ * Non-string expressions are returned as-is.
450
+ *
451
+ * @security CRITICAL SECURITY WARNING
452
+ * This method is NOT sandboxed. It uses `new Function()` and `with` statement,
453
+ * allowing full access to the global scope. Potential attack vectors include:
454
+ * - Code injection via malicious expressions
455
+ * - XSS attacks if user input is used as expressions
456
+ * - Access to sensitive globals (window, document, fetch, etc.)
457
+ *
458
+ * ONLY use with developer-defined template strings.
459
+ * NEVER use with user-provided input or untrusted data.
460
+ *
461
+ * Mitigation strategies:
462
+ * - Always sanitize any user-generated content before rendering in templates
463
+ * - Use Content Security Policy (CSP) headers to restrict script execution
464
+ * - Keep expressions simple (property access, method calls) - avoid complex logic
465
+ *
466
+ * @public
467
+ * @static
468
+ * @param {Expression | unknown} expression - The expression to evaluate.
469
+ * @param {ContextData} data - The data context for evaluation.
470
+ * @returns {EvaluationResult} The result of the evaluation, or empty string if evaluation fails.
471
+ * @note Evaluation failures return an empty string without throwing.
472
+ *
473
+ * @example
474
+ * // Property access
475
+ * TemplateEngine.evaluate("user.name", { user: { name: "John" } });
476
+ * // Result: "John"
477
+ *
478
+ * @example
479
+ * // Function reference
480
+ * TemplateEngine.evaluate("increment", { increment: () => count++ });
481
+ * // Result: [Function]
482
+ *
483
+ * @example
484
+ * // Nested property with Signal
485
+ * TemplateEngine.evaluate("count.value", { count: { value: 42 } });
486
+ * // Result: 42
487
+ *
488
+ * @example
489
+ * // Object reference (no JSON.stringify needed)
490
+ * TemplateEngine.evaluate("user", { user: { name: "John", age: 30 } });
491
+ * // Result: { name: "John", age: 30 }
492
+ *
493
+ * @example
494
+ * // Expressions
495
+ * TemplateEngine.evaluate("items.length > 0", { items: [1, 2, 3] });
496
+ * // Result: true
497
+ *
498
+ * @example
499
+ * // Failed evaluation returns empty string
500
+ * TemplateEngine.evaluate("nonexistent.property", {});
501
+ * // Result: ""
502
+ */
503
+ public static evaluate(expression: Expression | unknown, data: ContextData): EvaluationResult;
504
+ }
505
+ /**
506
+ * Data context object for expression evaluation.
507
+ */
508
+ type ContextData = Record<string, unknown>;
509
+ /**
510
+ * JavaScript expression string to be evaluated.
511
+ */
512
+ type Expression = string;
513
+ /**
514
+ * Result of evaluating an expression.
515
+ */
516
+ type EvaluationResult = unknown;
517
+
518
+ /**
519
+ * @class 🎨 Renderer
520
+ * @classdesc A high-performance DOM renderer that implements an optimized two-pointer diffing
521
+ * algorithm with key-based node reconciliation. The renderer efficiently updates the DOM by
522
+ * computing the minimal set of operations needed to transform the current state to the desired state.
523
+ *
524
+ * Key features:
525
+ * - Two-pointer diffing algorithm for efficient DOM updates
526
+ * - Key-based node reconciliation for optimal list performance (O(1) lookup)
527
+ * - Preserves DOM node identity during reordering (maintains event listeners, focus, animations)
528
+ * - Intelligent attribute synchronization (skips Eleva event attributes)
529
+ * - Preservation of Eleva-managed component instances and style elements
530
+ *
531
+ * @example
532
+ * // Basic usage
533
+ * const renderer = new Renderer();
534
+ * renderer.patchDOM(container, '<div>Updated content</div>');
535
+ *
536
+ * @example
537
+ * // With keyed elements for optimal list updates
538
+ * const html = items.map(item => `<li key="${item.id}">${item.name}</li>`).join('');
539
+ * renderer.patchDOM(listContainer, `<ul>${html}</ul>`);
540
+ *
541
+ * @example
542
+ * // Keyed elements preserve DOM identity during reordering
543
+ * // Before: [A, B, C] -> After: [C, A, B]
544
+ * // The actual DOM nodes are moved, not recreated
545
+ * renderer.patchDOM(container, '<div key="C">C</div><div key="A">A</div><div key="B">B</div>');
546
+ *
547
+ * @implements {RendererLike}
548
+ */
549
+ declare class Renderer implements RendererLike {
550
+ /**
551
+ * Temporary container for parsing new HTML content.
552
+ * Reused across patch operations to minimize memory allocation.
553
+ * @private
554
+ * @type {HTMLDivElement}
555
+ */
556
+ private _tempContainer;
557
+ /**
558
+ * Patches the DOM of the given container with the provided HTML string.
559
+ * Uses an optimized two-pointer diffing algorithm to minimize DOM operations.
560
+ * The algorithm computes the minimal set of insertions, deletions, and updates
561
+ * needed to transform the current DOM state to match the new HTML.
562
+ *
563
+ * @public
564
+ * @param {HTMLElement} container - The container element to patch.
565
+ * @param {string} newHtml - The new HTML string to render.
566
+ * @returns {void}
567
+ *
568
+ * @example
569
+ * // Simple content update
570
+ * renderer.patchDOM(container, '<div class="updated">New content</div>');
571
+ *
572
+ * @example
573
+ * // List with keyed items (optimal for reordering)
574
+ * renderer.patchDOM(container, '<ul><li key="1">First</li><li key="2">Second</li></ul>');
575
+ *
576
+ * @example
577
+ * // Empty the container
578
+ * renderer.patchDOM(container, '');
579
+ *
580
+ * @see _diff - Low-level diffing algorithm.
581
+ * @see _patchNode - Individual node patching.
582
+ */
583
+ public patchDOM(container: HTMLElement, newHtml: string): void;
584
+ /**
585
+ * Performs a diff between two DOM nodes and patches the old node to match the new node.
586
+ * Uses a two-pointer algorithm with key-based reconciliation for optimal performance.
587
+ * This method modifies oldParent in-place - it is not a pure function.
588
+ *
589
+ * Algorithm details:
590
+ * 1. Early exit if both nodes have no children (O(1) leaf node optimization)
591
+ * 2. Convert NodeLists to arrays for indexed access
592
+ * 3. Initialize two-pointer indices (oldStart/oldEnd, newStart/newEnd)
593
+ * 4. While pointers haven't crossed:
594
+ * a. Skip null entries (from previous moves)
595
+ * b. If nodes match (same key+tag or same type+name): patch and advance
596
+ * c. On mismatch: lazily build key→node map for O(1) lookup
597
+ * d. If keyed match found: move existing node (preserves DOM identity)
598
+ * e. Otherwise: clone and insert new node
599
+ * 5. After loop: append remaining new nodes or remove remaining old nodes
600
+ *
601
+ * Complexity: O(n) for most cases, O(n²) worst case with no keys.
602
+ * Non-keyed elements are matched by position and tag name.
603
+ *
604
+ * @private
605
+ * @param {Element} oldParent - The original DOM element to update (modified in-place).
606
+ * @param {Element} newParent - The new DOM element with desired state.
607
+ * @returns {void}
608
+ */
609
+ private _diff;
610
+ /**
611
+ * Patches a single node, updating its content and attributes to match the new node.
612
+ * Handles text nodes (nodeType 3 / Node.TEXT_NODE) by updating nodeValue,
613
+ * and element nodes (nodeType 1 / Node.ELEMENT_NODE) by updating attributes
614
+ * and recursively diffing children.
615
+ *
616
+ * Skips nodes that are managed by Eleva component instances to prevent interference
617
+ * with nested component state.
618
+ *
619
+ * @private
620
+ * @param {Node} oldNode - The original DOM node to update.
621
+ * @param {Node} newNode - The new DOM node with desired state.
622
+ * @returns {void}
623
+ */
624
+ private _patchNode;
625
+ /**
626
+ * Removes a node from its parent, with special handling for Eleva-managed elements.
627
+ * Style elements with the `data-e-style` attribute are preserved to maintain
628
+ * component styles across re-renders. Without this protection, component styles
629
+ * would be removed during DOM diffing and lost until the next full re-render.
630
+ *
631
+ * @note Style tags persist for the component's entire lifecycle. If the template
632
+ * conditionally removes elements that the CSS rules target (e.g., `.foo` elements),
633
+ * the style rules remain but simply have no matching elements. This is expected
634
+ * behavior - styles are cleaned up when the component unmounts, not when individual
635
+ * elements are removed.
636
+ *
637
+ * @private
638
+ * @param {HTMLElement} parent - The parent element containing the node.
639
+ * @param {Node} node - The node to remove.
640
+ * @returns {void}
641
+ * @see _injectStyles - Where data-e-style elements are created.
642
+ */
643
+ private _removeNode;
644
+ /**
645
+ * Updates the attributes of an element to match a new element's attributes.
646
+ * Adds new attributes, updates changed values, and removes attributes no longer present.
647
+ * Also syncs DOM properties that can diverge from attributes after user interaction.
648
+ *
649
+ * Processing order:
650
+ * 1. Iterate new attributes, skip @ prefixed (event) attributes
651
+ * 2. Update attribute if value changed
652
+ * 3. Sync corresponding DOM property if writable (handles boolean conversion)
653
+ * 4. Iterate old attributes in reverse, remove if not in new element
654
+ * 5. Sync SYNC_PROPS (value, checked, selected) from new to old element
655
+ *
656
+ * @private
657
+ * @param {Element} oldEl - The original element to update.
658
+ * @param {Element} newEl - The new element with target attributes.
659
+ * @returns {void}
660
+ */
661
+ private _updateAttributes;
662
+ /**
663
+ * Determines if two nodes are the same for reconciliation purposes.
664
+ * Two nodes are considered the same if:
665
+ * - Both have keys: keys match AND tag names match
666
+ * - Neither has keys: node types match AND node names match
667
+ * - One has key, other doesn't: not the same
668
+ *
669
+ * This ensures keyed elements are only reused when both key and tag match,
670
+ * preventing bugs like `<div key="a">` incorrectly matching `<span key="a">`.
671
+ *
672
+ * @private
673
+ * @param {Node} oldNode - The first node to compare.
674
+ * @param {Node} newNode - The second node to compare.
675
+ * @returns {boolean} True if the nodes are considered the same for reconciliation.
676
+ */
677
+ private _isSameNode;
678
+ /**
679
+ * Extracts the key attribute from a node if it exists.
680
+ * Only element nodes (nodeType === 1) can have key attributes.
681
+ * Uses optional chaining for null-safe access.
682
+ *
683
+ * @private
684
+ * @param {Node | null | undefined} node - The node to extract the key from.
685
+ * @returns {string | null} The key attribute value, or null if not an element or no key.
686
+ */
687
+ private _getNodeKey;
688
+ /**
689
+ * Creates a key map for efficient O(1) lookup of keyed elements during diffing.
690
+ * The map is built lazily only when needed (when a mismatch occurs during diffing).
691
+ *
692
+ * @private
693
+ * @param {ChildNode[]} children - The array of child nodes to map.
694
+ * @param {number} start - The start index (inclusive) for mapping.
695
+ * @param {number} end - The end index (inclusive) for mapping.
696
+ * @returns {KeyMap} A Map of key strings to their corresponding DOM nodes.
697
+ */
698
+ private _createKeyMap;
699
+ }
700
+ /**
701
+ * Interface describing the public API of a Renderer.
702
+ */
703
+ type RendererLike = {
704
+ /**
705
+ * Patches the DOM with new HTML content.
706
+ */
707
+ patchDOM: (arg0: HTMLElement, arg1: string) => void;
708
+ };
709
+
710
+ /**
711
+ * Configuration options for the Eleva instance (reserved for future use).
712
+ * @typedef {Record<string, unknown>} ElevaConfig
713
+ */
714
+ /**
715
+ * Component definition object.
716
+ * @typedef {Object} ComponentDefinition
717
+ * @property {SetupFunction} [setup]
718
+ * Optional setup function that initializes the component's state and returns reactive data.
719
+ * @property {TemplateFunction | string} template
720
+ * Required function or string that defines the component's HTML structure.
721
+ * @property {StyleFunction | string} [style]
722
+ * Optional function or string that provides CSS styles for the component.
723
+ * Styles are preserved across DOM diffs via data-e-style markers.
724
+ * @property {ChildrenMap} [children]
725
+ * Optional object defining nested child components.
726
+ */
727
+ /**
728
+ * Setup function that initializes component state.
729
+ * @callback SetupFunction
730
+ * @param {ComponentContext} ctx
731
+ * The component context with props, emitter, and signal factory.
732
+ * @returns {SetupResult | Promise<SetupResult>}
733
+ * Reactive data and lifecycle hooks.
734
+ */
735
+ /**
736
+ * Data returned from setup function, may include lifecycle hooks.
737
+ * @typedef {Record<string, unknown> & LifecycleHooks} SetupResult
738
+ */
739
+ /**
740
+ * Template function that returns HTML markup.
741
+ * @callback TemplateFunction
742
+ * @param {ComponentContext & SetupResult} ctx
743
+ * The merged component context and setup data.
744
+ * @returns {string | Promise<string>}
745
+ * HTML template string.
746
+ */
747
+ /**
748
+ * Style function that returns CSS styles.
749
+ * @callback StyleFunction
750
+ * @param {ComponentContext & SetupResult} ctx
751
+ * The merged component context and setup data.
752
+ * @returns {string}
753
+ * CSS styles string.
754
+ */
755
+ /**
756
+ * Map of CSS selectors to component definitions or registered component names.
757
+ * @typedef {Record<string, ComponentDefinition | string>} ChildrenMap
758
+ */
759
+ /**
760
+ * Context passed to component setup function.
761
+ * @typedef {Object} ComponentContext
762
+ * @property {ComponentProps} props
763
+ * Component properties passed during mounting.
764
+ * @property {Emitter} emitter
765
+ * Event emitter instance for component event handling.
766
+ * @property {SignalFactory} signal
767
+ * Factory function to create reactive Signal instances.
768
+ * @description
769
+ * Plugins may extend this context with additional properties (e.g., `ctx.router`, `ctx.store`).
770
+ * @see RouterContext - Router plugin injected context.
771
+ * @see StoreApi - Store plugin injected context.
772
+ */
773
+ /**
774
+ * Properties passed to a component during mounting.
775
+ * @typedef {Record<string, unknown>} ComponentProps
776
+ */
777
+ /**
778
+ * Factory function to create reactive Signal instances.
779
+ * @typedef {<T>(initialValue: T) => Signal<T>} SignalFactory
780
+ */
781
+ /**
782
+ * Lifecycle hooks that can be returned from setup function.
783
+ * @typedef {Object} LifecycleHooks
784
+ * @property {LifecycleHook} [onBeforeMount]
785
+ * Called before component mounting.
786
+ * @property {LifecycleHook} [onMount]
787
+ * Called after component mounting.
788
+ * @property {LifecycleHook} [onBeforeUpdate]
789
+ * Called before component update.
790
+ * @property {LifecycleHook} [onUpdate]
791
+ * Called after component update.
792
+ * @property {UnmountHook} [onUnmount]
793
+ * Called during component unmounting.
794
+ */
795
+ /**
796
+ * Lifecycle hook function.
797
+ * @callback LifecycleHook
798
+ * @param {LifecycleHookContext} ctx
799
+ * Context with container and component data.
800
+ * @returns {void | Promise<void>}
801
+ */
802
+ /**
803
+ * Unmount hook function with cleanup resources.
804
+ * @callback UnmountHook
805
+ * @param {UnmountHookContext} ctx
806
+ * Context with cleanup resources.
807
+ * @returns {void | Promise<void>}
808
+ */
809
+ /**
810
+ * Context passed to lifecycle hooks.
811
+ * @typedef {Object} LifecycleHookContext
812
+ * @property {HTMLElement} container
813
+ * The DOM element where the component is mounted.
814
+ * @property {ComponentContext & SetupResult} context
815
+ * The component's reactive state and context data.
816
+ */
817
+ /**
818
+ * Context passed to unmount hook with cleanup resources.
819
+ * @typedef {Object} UnmountHookContext
820
+ * @property {HTMLElement} container
821
+ * The DOM element where the component is mounted.
822
+ * @property {ComponentContext & SetupResult} context
823
+ * The component's reactive state and context data.
824
+ * @property {CleanupResources} cleanup
825
+ * Object containing cleanup functions and instances.
826
+ */
827
+ /**
828
+ * Resources available for cleanup during unmount.
829
+ * @typedef {Object} CleanupResources
830
+ * @property {UnsubscribeFunction[]} watchers
831
+ * Signal watcher cleanup functions.
832
+ * @property {UnsubscribeFunction[]} listeners
833
+ * Event listener cleanup functions.
834
+ * @property {MountResult[]} children
835
+ * Child component instances.
836
+ */
837
+ /**
838
+ * Result of mounting a component.
839
+ * @typedef {Object} MountResult
840
+ * @property {HTMLElement} container
841
+ * The DOM element where the component is mounted.
842
+ * @property {ComponentContext & SetupResult} data
843
+ * The component's reactive state and context data.
844
+ * @property {UnmountFunction} unmount
845
+ * Function to clean up and unmount the component.
846
+ */
847
+ /**
848
+ * Function to unmount a component and clean up resources.
849
+ * @callback UnmountFunction
850
+ * @returns {Promise<void>}
851
+ */
852
+ /**
853
+ * Function to unsubscribe from events or watchers.
854
+ * @callback UnsubscribeFunction
855
+ * @returns {void | boolean}
856
+ */
857
+ /**
858
+ * Plugin interface for extending Eleva.
859
+ * @typedef {Object} ElevaPlugin
860
+ * @property {string} name
861
+ * Unique identifier name for the plugin.
862
+ * @property {string} [version]
863
+ * Optional version string for the plugin.
864
+ * @property {PluginInstallFunction} install
865
+ * Function that installs the plugin.
866
+ * @property {PluginUninstallFunction} [uninstall]
867
+ * Optional function to uninstall the plugin.
868
+ */
869
+ /**
870
+ * Plugin install function.
871
+ * @callback PluginInstallFunction
872
+ * @param {Eleva} eleva
873
+ * The Eleva instance.
874
+ * @param {PluginOptions} [options]
875
+ * Plugin configuration options.
876
+ * @returns {void | Eleva | unknown}
877
+ */
878
+ /**
879
+ * Plugin uninstall function.
880
+ * @callback PluginUninstallFunction
881
+ * @param {Eleva} eleva
882
+ * The Eleva instance.
883
+ * @returns {void | Promise<void>}
884
+ */
885
+ /**
886
+ * Configuration options passed to a plugin during installation.
887
+ * @typedef {Record<string, unknown>} PluginOptions
888
+ */
889
+ /**
890
+ * Handler function for DOM events (e.g., click, input, submit).
891
+ * @typedef {(event: Event) => void} DOMEventHandler
892
+ */
893
+ /**
894
+ * Common DOM event names (prefixed with @ in templates).
895
+ * @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
896
+ */
897
+ /**
898
+ * @class 🧩 Eleva
899
+ * @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
900
+ * component styles, and plugin support. Eleva manages component registration, plugin integration,
901
+ * event handling, and DOM rendering with a focus on performance and developer experience.
902
+ *
903
+ * @example
904
+ * // Basic component creation and mounting
905
+ * const app = new Eleva("myApp");
906
+ * app.component("myComponent", {
907
+ * setup: (ctx) => ({ count: ctx.signal(0) }),
908
+ * template: (ctx) => `<div>Hello ${ctx.props.name}</div>`
909
+ * });
910
+ * app.mount(document.getElementById("app"), "myComponent", { name: "World" });
911
+ *
912
+ * @example
913
+ * // Using lifecycle hooks
914
+ * app.component("lifecycleDemo", {
915
+ * setup: () => {
916
+ * return {
917
+ * onMount: ({ container, context }) => {
918
+ * console.log('Component mounted!');
919
+ * }
920
+ * };
921
+ * },
922
+ * template: `<div>Lifecycle Demo</div>`
923
+ * });
924
+ */
925
+ declare class Eleva {
926
+ /**
927
+ * Creates a new Eleva instance with the specified name and configuration.
928
+ *
929
+ * @public
930
+ * @constructor
931
+ * @param {string} name - The unique identifier name for this Eleva instance.
932
+ * @param {ElevaConfig} [config={}] - Optional configuration object for the instance.
933
+ * @throws {Error} If the name is not provided or is not a string.
934
+ *
935
+ * @example
936
+ * const app = new Eleva("myApp");
937
+ * app.component("myComponent", {
938
+ * setup: (ctx) => ({ count: ctx.signal(0) }),
939
+ * template: (ctx) => `<div>Hello ${ctx.props.name}!</div>`
940
+ * });
941
+ * app.mount(document.getElementById("app"), "myComponent", { name: "World" });
942
+ *
943
+ */
944
+ constructor(name: string, config?: ElevaConfig);
945
+ /** @public @readonly {string} The unique identifier name for this Eleva instance */
946
+ public readonly name: string;
947
+ /** @public @readonly {Record<string, unknown>} Configuration object for the Eleva instance */
948
+ public readonly config: ElevaConfig;
949
+ /** @public @readonly {Emitter} Event emitter for handling component events */
950
+ public readonly emitter: Emitter;
951
+ /** @public @readonly {typeof Signal} Signal class for creating reactive state */
952
+ public readonly signal: typeof Signal;
953
+ /** @public @readonly {typeof TemplateEngine} TemplateEngine class for template parsing */
954
+ public readonly templateEngine: typeof TemplateEngine;
955
+ /** @public @readonly {Renderer} Renderer for handling DOM updates and patching */
956
+ public readonly renderer: Renderer;
957
+ /** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */
958
+ private _components;
959
+ /** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
960
+ private _plugins;
961
+ /** @private {number} Counter for generating unique component IDs */
962
+ private _componentCounter;
963
+ /**
964
+ * Integrates a plugin with the Eleva framework.
965
+ * The plugin's install function will be called with the Eleva instance and provided options.
966
+ * After installation, the plugin will be available for use by components.
967
+ *
968
+ * @note Plugins that wrap core methods (e.g., mount) must be uninstalled in reverse order
969
+ * of installation (LIFO - Last In, First Out) to avoid conflicts.
970
+ *
971
+ * @public
972
+ * @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
973
+ * @param {PluginOptions} [options={}] - Optional configuration options for the plugin.
974
+ * @returns {Eleva | unknown} The Eleva instance (for method chaining) or the result returned by the plugin.
975
+ * @throws {Error} If plugin does not have an install function.
976
+ * @see component - Register components after installing plugins.
977
+ * @see mount - Mount components to the DOM.
978
+ * @example
979
+ * app.use(myPlugin, { option1: "value1" });
980
+ *
981
+ * @example
982
+ * // Correct uninstall order (LIFO)
983
+ * app.use(PluginA);
984
+ * app.use(PluginB);
985
+ * // Uninstall in reverse order:
986
+ * PluginB.uninstall(app);
987
+ * PluginA.uninstall(app);
988
+ */
989
+ public use(plugin: ElevaPlugin, options?: PluginOptions): Eleva | unknown;
990
+ /**
991
+ * Registers a new component with the Eleva instance.
992
+ * The component will be available for mounting using its registered name.
993
+ *
994
+ * @public
995
+ * @param {string} name - The unique name of the component to register.
996
+ * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
997
+ * @returns {Eleva} The Eleva instance (for method chaining).
998
+ * @throws {Error} If name is not a non-empty string or definition has no template.
999
+ * @see mount - Mount this component to the DOM.
1000
+ * @example
1001
+ * app.component("myButton", {
1002
+ * template: (ctx) => `<button>${ctx.props.text}</button>`,
1003
+ * style: `button { color: blue; }`
1004
+ * });
1005
+ */
1006
+ public component(name: string, definition: ComponentDefinition): Eleva;
1007
+ /**
1008
+ * Mounts a registered component to a DOM element.
1009
+ * This will initialize the component, set up its reactive state, and render it to the DOM.
1010
+ * If the container already has a mounted Eleva instance, it is returned as-is.
1011
+ * Unmount clears the container contents and removes the internal instance marker.
1012
+ *
1013
+ * @public
1014
+ * @async
1015
+ * @param {HTMLElement} container - The DOM element where the component will be mounted.
1016
+ * @param {string | ComponentDefinition} compName - The name of the registered component or a direct component definition.
1017
+ * @param {ComponentProps} [props={}] - Optional properties to pass to the component.
1018
+ * @returns {Promise<MountResult>}
1019
+ * A Promise that resolves to an object containing:
1020
+ * - container: The mounted component's container element
1021
+ * - data: The component's reactive state and context
1022
+ * - unmount: Function to clean up and unmount the component
1023
+ * @throws {Error} If container is not a DOM element or component is not registered.
1024
+ * @throws {Error} If setup function, template function, or style function throws.
1025
+ * @example
1026
+ * const instance = await app.mount(document.getElementById("app"), "myComponent", { text: "Click me" });
1027
+ * // Later...
1028
+ * await instance.unmount();
1029
+ */
1030
+ public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: ComponentProps): Promise<MountResult>;
1031
+ /**
1032
+ * Processes DOM elements for event binding based on attributes starting with "@".
1033
+ * This method attaches event listeners directly to elements and ensures proper cleanup.
1034
+ * Bound `@event` attributes are removed after listeners are attached.
1035
+ *
1036
+ * Handler resolution order:
1037
+ * 1. Direct context property lookup (e.g., context["handleClick"])
1038
+ * 2. Template expression evaluation via TemplateEngine (e.g., "increment()")
1039
+ *
1040
+ * @private
1041
+ * @param {HTMLElement} container - The container element in which to search for event attributes.
1042
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
1043
+ * @param {UnsubscribeFunction[]} listeners - Array to collect cleanup functions for each event listener.
1044
+ * @returns {void}
1045
+ * @see TemplateEngine.evaluate - Expression evaluation. fallback.
1046
+ */
1047
+ private _processEvents;
1048
+ /**
1049
+ * Injects styles into the component's container.
1050
+ * Styles are placed in a `<style>` element with a `data-e-style` attribute for identification.
1051
+ *
1052
+ * @note Styles are not automatically scoped - use unique class names or CSS nesting for isolation.
1053
+ *
1054
+ * Optimization: Skips DOM update if style content hasn't changed.
1055
+ *
1056
+ * @private
1057
+ * @param {HTMLElement} container - The container element where styles should be injected.
1058
+ * @param {string} compId - The component ID used to identify the style element.
1059
+ * @param {StyleFunction | string} styleDef - The component's style definition (function or string).
1060
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
1061
+ * @returns {void}
1062
+ */
1063
+ private _injectStyles;
1064
+ /**
1065
+ * Extracts and evaluates props from an element's attributes that start with `:`.
1066
+ * Prop values are evaluated as expressions against the component context,
1067
+ * allowing direct passing of objects, arrays, and other complex types.
1068
+ * Processed attributes are removed from the element after extraction.
1069
+ *
1070
+ * @private
1071
+ * @param {HTMLElement} element - The DOM element to extract props from.
1072
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
1073
+ * @returns {ComponentProps} An object containing the evaluated props.
1074
+ * @see TemplateEngine.evaluate - Expression evaluation.
1075
+ * @example
1076
+ * // For an element with attributes:
1077
+ * // <div :name="user.name" :data="items">
1078
+ * // With context: { user: { name: "John" }, items: [1, 2, 3] }
1079
+ * // Returns: { name: "John", data: [1, 2, 3] }
1080
+ */
1081
+ private _extractProps;
1082
+ /**
1083
+ * Mounts all components within the parent component's container.
1084
+ * This method handles mounting of explicitly defined children components.
1085
+ *
1086
+ * The mounting process follows these steps:
1087
+ * 1. Finds matching DOM nodes within the container
1088
+ * 2. Mounts explicitly defined children components
1089
+ *
1090
+ * @private
1091
+ * @async
1092
+ * @param {HTMLElement} container - The container element to mount components in.
1093
+ * @param {ChildrenMap} children - Map of selectors to component definitions for explicit children.
1094
+ * @param {MountResult[]} childInstances - Array to store all mounted component instances.
1095
+ * @param {ComponentContext & SetupResult} context - The merged component context and setup data.
1096
+ * @returns {Promise<void>}
1097
+ *
1098
+ * @example
1099
+ * // Explicit children mounting:
1100
+ * const children = {
1101
+ * 'user-profile': UserProfileComponent,
1102
+ * '#settings-panel': "settings-panel"
1103
+ * };
1104
+ */
1105
+ private _mountComponents;
1106
+ }
1107
+ /**
1108
+ * Configuration options for the Eleva instance (reserved for future use).
1109
+ */
1110
+ type ElevaConfig = Record<string, unknown>;
1111
+ /**
1112
+ * Component definition object.
1113
+ */
1114
+ type ComponentDefinition = {
1115
+ /**
1116
+ * Optional setup function that initializes the component's state and returns reactive data.
1117
+ */
1118
+ setup?: SetupFunction | undefined;
1119
+ /**
1120
+ * Required function or string that defines the component's HTML structure.
1121
+ */
1122
+ template: TemplateFunction | string;
1123
+ /**
1124
+ * Optional function or string that provides CSS styles for the component.
1125
+ * Styles are preserved across DOM diffs via data-e-style markers.
1126
+ */
1127
+ style?: string | StyleFunction | undefined;
1128
+ /**
1129
+ * Optional object defining nested child components.
1130
+ */
1131
+ children?: ChildrenMap | undefined;
1132
+ };
1133
+ /**
1134
+ * Setup function that initializes component state.
1135
+ */
1136
+ type SetupFunction = (ctx: ComponentContext) => SetupResult | Promise<SetupResult>;
1137
+ /**
1138
+ * Data returned from setup function, may include lifecycle hooks.
1139
+ */
1140
+ type SetupResult = Record<string, unknown> & LifecycleHooks;
1141
+ /**
1142
+ * Template function that returns HTML markup.
1143
+ */
1144
+ type TemplateFunction = (ctx: ComponentContext & SetupResult) => string | Promise<string>;
1145
+ /**
1146
+ * Style function that returns CSS styles.
1147
+ */
1148
+ type StyleFunction = (ctx: ComponentContext & SetupResult) => string;
1149
+ /**
1150
+ * Map of CSS selectors to component definitions or registered component names.
1151
+ */
1152
+ type ChildrenMap = Record<string, ComponentDefinition | string>;
1153
+ /**
1154
+ * Context passed to component setup function.
1155
+ */
1156
+ type ComponentContext = {
1157
+ /**
1158
+ * Component properties passed during mounting.
1159
+ */
1160
+ props: ComponentProps;
1161
+ /**
1162
+ * Event emitter instance for component event handling.
1163
+ */
1164
+ emitter: Emitter;
1165
+ /**
1166
+ * Factory function to create reactive Signal instances.
1167
+ */
1168
+ signal: SignalFactory;
1169
+ };
1170
+ /**
1171
+ * Properties passed to a component during mounting.
1172
+ */
1173
+ type ComponentProps = Record<string, unknown>;
1174
+ /**
1175
+ * Factory function to create reactive Signal instances.
1176
+ */
1177
+ type SignalFactory = <T>(initialValue: T) => Signal<T>;
1178
+ /**
1179
+ * Lifecycle hooks that can be returned from setup function.
1180
+ */
1181
+ type LifecycleHooks = {
1182
+ /**
1183
+ * Called before component mounting.
1184
+ */
1185
+ onBeforeMount?: LifecycleHook | undefined;
1186
+ /**
1187
+ * Called after component mounting.
1188
+ */
1189
+ onMount?: LifecycleHook | undefined;
1190
+ /**
1191
+ * Called before component update.
1192
+ */
1193
+ onBeforeUpdate?: LifecycleHook | undefined;
1194
+ /**
1195
+ * Called after component update.
1196
+ */
1197
+ onUpdate?: LifecycleHook | undefined;
1198
+ /**
1199
+ * Called during component unmounting.
1200
+ */
1201
+ onUnmount?: UnmountHook | undefined;
1202
+ };
1203
+ /**
1204
+ * Lifecycle hook function.
1205
+ */
1206
+ type LifecycleHook = (ctx: LifecycleHookContext) => void | Promise<void>;
1207
+ /**
1208
+ * Unmount hook function with cleanup resources.
1209
+ */
1210
+ type UnmountHook = (ctx: UnmountHookContext) => void | Promise<void>;
1211
+ /**
1212
+ * Context passed to lifecycle hooks.
1213
+ */
1214
+ type LifecycleHookContext = {
1215
+ /**
1216
+ * The DOM element where the component is mounted.
1217
+ */
1218
+ container: HTMLElement;
1219
+ /**
1220
+ * The component's reactive state and context data.
1221
+ */
1222
+ context: ComponentContext & SetupResult;
1223
+ };
1224
+ /**
1225
+ * Context passed to unmount hook with cleanup resources.
1226
+ */
1227
+ type UnmountHookContext = {
1228
+ /**
1229
+ * The DOM element where the component is mounted.
1230
+ */
1231
+ container: HTMLElement;
1232
+ /**
1233
+ * The component's reactive state and context data.
1234
+ */
1235
+ context: ComponentContext & SetupResult;
1236
+ /**
1237
+ * Object containing cleanup functions and instances.
1238
+ */
1239
+ cleanup: CleanupResources;
1240
+ };
1241
+ /**
1242
+ * Resources available for cleanup during unmount.
1243
+ */
1244
+ type CleanupResources = {
1245
+ /**
1246
+ * Signal watcher cleanup functions.
1247
+ */
1248
+ watchers: UnsubscribeFunction[];
1249
+ /**
1250
+ * Event listener cleanup functions.
1251
+ */
1252
+ listeners: UnsubscribeFunction[];
1253
+ /**
1254
+ * Child component instances.
1255
+ */
1256
+ children: MountResult[];
1257
+ };
1258
+ /**
1259
+ * Result of mounting a component.
1260
+ */
1261
+ type MountResult = {
1262
+ /**
1263
+ * The DOM element where the component is mounted.
1264
+ */
1265
+ container: HTMLElement;
1266
+ /**
1267
+ * The component's reactive state and context data.
1268
+ */
1269
+ data: ComponentContext & SetupResult;
1270
+ /**
1271
+ * Function to clean up and unmount the component.
1272
+ */
1273
+ unmount: UnmountFunction;
1274
+ };
1275
+ /**
1276
+ * Function to unmount a component and clean up resources.
1277
+ */
1278
+ type UnmountFunction = () => Promise<void>;
1279
+ /**
1280
+ * Function to unsubscribe from events or watchers.
1281
+ */
1282
+ type UnsubscribeFunction = () => void | boolean;
1283
+ /**
1284
+ * Plugin interface for extending Eleva.
1285
+ */
1286
+ type ElevaPlugin = {
1287
+ /**
1288
+ * Unique identifier name for the plugin.
1289
+ */
1290
+ name: string;
1291
+ /**
1292
+ * Optional version string for the plugin.
1293
+ */
1294
+ version?: string | undefined;
1295
+ /**
1296
+ * Function that installs the plugin.
1297
+ */
1298
+ install: PluginInstallFunction;
1299
+ /**
1300
+ * Optional function to uninstall the plugin.
1301
+ */
1302
+ uninstall?: PluginUninstallFunction | undefined;
1303
+ };
1304
+ /**
1305
+ * Plugin install function.
1306
+ */
1307
+ type PluginInstallFunction = (eleva: Eleva, options?: PluginOptions | undefined) => void | Eleva | unknown;
1308
+ /**
1309
+ * Plugin uninstall function.
1310
+ */
1311
+ type PluginUninstallFunction = (eleva: Eleva) => void | Promise<void>;
1312
+ /**
1313
+ * Configuration options passed to a plugin during installation.
1314
+ */
1315
+ type PluginOptions = Record<string, unknown>;
1316
+ /**
1317
+ * Handler function for DOM events (e.g., click, input, submit).
1318
+ */
1319
+ type DOMEventHandler = (event: Event) => void;
1320
+ /**
1321
+ * Common DOM event names (prefixed with @ in templates).
1322
+ */
1323
+ 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;
1324
+
1325
+ //# sourceMappingURL=index.d.ts.map
1326
+
1327
+ export { Eleva, Emitter, Renderer, Signal, TemplateEngine, Eleva as default };
1328
+ export type { ChildrenMap, CleanupResources, ComponentContext, ComponentDefinition, ComponentProps, DOMEventHandler, DOMEventName, ElevaConfig, ElevaPlugin, LifecycleHook, LifecycleHookContext, LifecycleHooks, MountResult, PluginInstallFunction, PluginOptions, PluginUninstallFunction, SetupFunction, SetupResult, SignalFactory, StyleFunction, TemplateFunction, UnmountFunction, UnmountHook, UnmountHookContext, UnsubscribeFunction };
1329
+ //# sourceMappingURL=eleva.d.cts.map