eleva 1.0.0-alpha → 1.2.0-alpha

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.
package/dist/eleva.esm.js CHANGED
@@ -1,16 +1,15 @@
1
1
  /**
2
- * 🔒 TemplateEngine: Secure interpolation & dynamic attribute parsing.
3
- *
4
- * This class provides methods to parse template strings by replacing
5
- * interpolation expressions with dynamic data values and to evaluate expressions
6
- * within a given data context.
2
+ * @class 🔒 TemplateEngine
3
+ * @classdesc Secure interpolation & dynamic attribute parsing.
4
+ * Provides methods to parse template strings by replacing interpolation expressions
5
+ * with dynamic data values and to evaluate expressions within a given data context.
7
6
  */
8
7
  class TemplateEngine {
9
8
  /**
10
9
  * Parses a template string and replaces interpolation expressions with corresponding values.
11
10
  *
12
- * @param {string} template - The template string containing expressions in the format {{ expression }}.
13
- * @param {object} data - The data object to use for evaluating expressions.
11
+ * @param {string} template - The template string containing expressions in the format `{{ expression }}`.
12
+ * @param {Object<string, any>} data - The data object to use for evaluating expressions.
14
13
  * @returns {string} The resulting string with evaluated values.
15
14
  */
16
15
  static parse(template, data) {
@@ -21,16 +20,16 @@ class TemplateEngine {
21
20
  }
22
21
 
23
22
  /**
24
- * Evaluates an expression using the provided data context.
23
+ * Evaluates a JavaScript expression using the provided data context.
25
24
  *
26
25
  * @param {string} expr - The JavaScript expression to evaluate.
27
- * @param {object} data - The data context for evaluating the expression.
28
- * @returns {*} The result of the evaluated expression, or an empty string if undefined or on error.
26
+ * @param {Object<string, any>} data - The data context for evaluating the expression.
27
+ * @returns {any} The result of the evaluated expression, or an empty string if undefined or on error.
29
28
  */
30
29
  static evaluate(expr, data) {
31
30
  try {
32
31
  const keys = Object.keys(data);
33
- const values = keys.map(k => data[k]);
32
+ const values = Object.values(data);
34
33
  const result = new Function(...keys, `return ${expr}`)(...values);
35
34
  return result === undefined ? "" : result;
36
35
  } catch (error) {
@@ -45,10 +44,10 @@ class TemplateEngine {
45
44
  }
46
45
 
47
46
  /**
48
- * ⚡ Signal: Fine-grained reactivity.
49
- *
47
+ * @class ⚡ Signal
48
+ * @classdesc Fine-grained reactivity.
50
49
  * A reactive data holder that notifies registered watchers when its value changes,
51
- * allowing for fine-grained DOM patching rather than full re-renders.
50
+ * enabling fine-grained DOM patching rather than full re-renders.
52
51
  */
53
52
  class Signal {
54
53
  /**
@@ -57,7 +56,9 @@ class Signal {
57
56
  * @param {*} value - The initial value of the signal.
58
57
  */
59
58
  constructor(value) {
59
+ /** @private {*} Internal storage for the signal's current value */
60
60
  this._value = value;
61
+ /** @private {Set<function>} Collection of callback functions to be notified when value changes */
61
62
  this._watchers = new Set();
62
63
  }
63
64
 
@@ -85,8 +86,8 @@ class Signal {
85
86
  /**
86
87
  * Registers a watcher function that will be called whenever the signal's value changes.
87
88
  *
88
- * @param {Function} fn - The callback function to invoke on value change.
89
- * @returns {Function} A function to unsubscribe the watcher.
89
+ * @param {function(any): void} fn - The callback function to invoke on value change.
90
+ * @returns {function(): boolean} A function to unsubscribe the watcher.
90
91
  */
91
92
  watch(fn) {
92
93
  this._watchers.add(fn);
@@ -95,17 +96,17 @@ class Signal {
95
96
  }
96
97
 
97
98
  /**
98
- * 🎙️ Emitter: Robust inter-component communication with event bubbling.
99
- *
100
- * Implements a basic publish-subscribe pattern for event handling,
101
- * allowing components to communicate through custom events.
99
+ * @class 🎙️ Emitter
100
+ * @classdesc Robust inter-component communication with event bubbling.
101
+ * Implements a basic publish-subscribe pattern for event handling, allowing components
102
+ * to communicate through custom events.
102
103
  */
103
104
  class Emitter {
104
105
  /**
105
106
  * Creates a new Emitter instance.
106
107
  */
107
108
  constructor() {
108
- /** @type {Object.<string, Function[]>} */
109
+ /** @type {Object.<string, Function[]>} Storage for event handlers mapped by event name */
109
110
  this.events = {};
110
111
  }
111
112
 
@@ -113,7 +114,7 @@ class Emitter {
113
114
  * Registers an event handler for the specified event.
114
115
  *
115
116
  * @param {string} event - The name of the event.
116
- * @param {Function} handler - The function to call when the event is emitted.
117
+ * @param {function(...any): void} handler - The function to call when the event is emitted.
117
118
  */
118
119
  on(event, handler) {
119
120
  (this.events[event] || (this.events[event] = [])).push(handler);
@@ -123,7 +124,7 @@ class Emitter {
123
124
  * Removes a previously registered event handler.
124
125
  *
125
126
  * @param {string} event - The name of the event.
126
- * @param {Function} handler - The handler function to remove.
127
+ * @param {function(...any): void} handler - The handler function to remove.
127
128
  */
128
129
  off(event, handler) {
129
130
  if (this.events[event]) {
@@ -135,7 +136,7 @@ class Emitter {
135
136
  * Emits an event, invoking all handlers registered for that event.
136
137
  *
137
138
  * @param {string} event - The event name.
138
- * @param {...*} args - Additional arguments to pass to the event handlers.
139
+ * @param {...any} args - Additional arguments to pass to the event handlers.
139
140
  */
140
141
  emit(event, ...args) {
141
142
  (this.events[event] || []).forEach(handler => handler(...args));
@@ -143,8 +144,8 @@ class Emitter {
143
144
  }
144
145
 
145
146
  /**
146
- * 🎨 Renderer: Handles DOM patching, diffing, and attribute updates.
147
- *
147
+ * @class 🎨 Renderer
148
+ * @classdesc Handles DOM patching, diffing, and attribute updates.
148
149
  * Provides methods for efficient DOM updates by diffing the new and old DOM structures
149
150
  * and applying only the necessary changes.
150
151
  */
@@ -175,18 +176,18 @@ class Renderer {
175
176
  const oldNode = oldNodes[i];
176
177
  const newNode = newNodes[i];
177
178
 
178
- // Append new nodes that don't exist in the old tree.
179
+ // Case 1: Append new nodes that don't exist in the old tree.
179
180
  if (!oldNode && newNode) {
180
181
  oldParent.appendChild(newNode.cloneNode(true));
181
182
  continue;
182
183
  }
183
- // Remove old nodes not present in the new tree.
184
+ // Case 2: Remove old nodes not present in the new tree.
184
185
  if (oldNode && !newNode) {
185
186
  oldParent.removeChild(oldNode);
186
187
  continue;
187
188
  }
188
189
 
189
- // For element nodes, compare keys if available.
190
+ // Case 3: For element nodes, compare keys if available.
190
191
  if (oldNode.nodeType === Node.ELEMENT_NODE && newNode.nodeType === Node.ELEMENT_NODE) {
191
192
  const oldKey = oldNode.getAttribute("key");
192
193
  const newKey = newNode.getAttribute("key");
@@ -198,19 +199,19 @@ class Renderer {
198
199
  }
199
200
  }
200
201
 
201
- // Replace nodes if types or tag names differ.
202
+ // Case 4: Replace nodes if types or tag names differ.
202
203
  if (oldNode.nodeType !== newNode.nodeType || oldNode.nodeName !== newNode.nodeName) {
203
204
  oldParent.replaceChild(newNode.cloneNode(true), oldNode);
204
205
  continue;
205
206
  }
206
- // For text nodes, update content if different.
207
+ // Case 5: For text nodes, update content if different.
207
208
  if (oldNode.nodeType === Node.TEXT_NODE) {
208
209
  if (oldNode.nodeValue !== newNode.nodeValue) {
209
210
  oldNode.nodeValue = newNode.nodeValue;
210
211
  }
211
212
  continue;
212
213
  }
213
- // For element nodes, update attributes and then diff children.
214
+ // Case 6: For element nodes, update attributes and then diff children.
214
215
  if (oldNode.nodeType === Node.ELEMENT_NODE) {
215
216
  this.updateAttributes(oldNode, newNode);
216
217
  this.diff(oldNode, newNode);
@@ -255,34 +256,65 @@ class Renderer {
255
256
  }
256
257
 
257
258
  /**
258
- * 🧩 Eleva Core: Signal-based component runtime framework with lifecycle, scoped styles, and plugins.
259
+ * Defines the structure and behavior of a component.
260
+ * @typedef {Object} ComponentDefinition
261
+ * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]
262
+ * Optional setup function that initializes the component's reactive state and lifecycle.
263
+ * Receives props and context as an argument and should return an object containing the component's state.
264
+ * Can return either a synchronous object or a Promise that resolves to an object for async initialization.
265
+ *
266
+ * @property {function(Object<string, any>): string} template
267
+ * Required function that defines the component's HTML structure.
268
+ * Receives the merged context (props + setup data) and must return an HTML template string.
269
+ * Supports dynamic expressions using {{ }} syntax for reactive data binding.
270
+ *
271
+ * @property {function(Object<string, any>): string} [style]
272
+ * Optional function that defines component-scoped CSS styles.
273
+ * Receives the merged context and returns a CSS string that will be automatically scoped to the component.
274
+ * Styles are injected into the component's container and only affect elements within it.
259
275
  *
260
- * The Eleva class is the core of the framework. It manages component registration,
261
- * plugin integration, lifecycle hooks, event handling, and DOM rendering.
276
+ * @property {Object<string, ComponentDefinition>} [children]
277
+ * Optional object that defines nested child components.
278
+ * Keys are CSS selectors that match elements in the template where child components should be mounted.
279
+ * Values are ComponentDefinition objects that define the structure and behavior of each child component.
280
+ */
281
+
282
+ /**
283
+ * @class 🧩 Eleva
284
+ * @classdesc Signal-based component runtime framework with lifecycle hooks, scoped styles, and plugin support.
285
+ * Manages component registration, plugin integration, event handling, and DOM rendering.
262
286
  */
263
287
  class Eleva {
264
288
  /**
265
289
  * Creates a new Eleva instance.
266
290
  *
267
291
  * @param {string} name - The name of the Eleva instance.
268
- * @param {object} [config={}] - Optional configuration for the instance.
292
+ * @param {Object<string, any>} [config={}] - Optional configuration for the instance.
269
293
  */
270
294
  constructor(name, config = {}) {
295
+ /** @type {string} The unique identifier name for this Eleva instance */
271
296
  this.name = name;
297
+ /** @type {Object<string, any>} Optional configuration object for the Eleva instance */
272
298
  this.config = config;
299
+ /** @type {Object<string, ComponentDefinition>} Object storing registered component definitions by name */
273
300
  this._components = {};
301
+ /** @private {Array<Object>} Collection of installed plugin instances */
274
302
  this._plugins = [];
303
+ /** @private {string[]} Array of lifecycle hook names supported by the component */
275
304
  this._lifecycleHooks = ["onBeforeMount", "onMount", "onBeforeUpdate", "onUpdate", "onUnmount"];
305
+ /** @private {boolean} Flag indicating if component is currently mounted */
276
306
  this._isMounted = false;
307
+ /** @private {Emitter} Instance of the event emitter for handling component events */
277
308
  this.emitter = new Emitter();
309
+ /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */
278
310
  this.renderer = new Renderer();
279
311
  }
280
312
 
281
313
  /**
282
314
  * Integrates a plugin with the Eleva framework.
283
315
  *
284
- * @param {object} [plugin] - The plugin object which should have an install function.
285
- * @param {object} [options={}] - Optional options to pass to the plugin.
316
+ * @param {Object} plugin - The plugin object which should have an `install` function.
317
+ * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.
286
318
  * @returns {Eleva} The Eleva instance (for chaining).
287
319
  */
288
320
  use(plugin, options = {}) {
@@ -297,7 +329,7 @@ class Eleva {
297
329
  * Registers a component with the Eleva instance.
298
330
  *
299
331
  * @param {string} name - The name of the component.
300
- * @param {object} definition - The component definition including setup, template, style, and children.
332
+ * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
301
333
  * @returns {Eleva} The Eleva instance (for chaining).
302
334
  */
303
335
  component(name, definition) {
@@ -308,27 +340,50 @@ class Eleva {
308
340
  /**
309
341
  * Mounts a registered component to a DOM element.
310
342
  *
311
- * @param {string|HTMLElement} selectorOrElement - A CSS selector string or DOM element where the component will be mounted.
312
- * @param {string} compName - The name of the component to mount.
313
- * @param {object} [props={}] - Optional properties to pass to the component.
343
+ * @param {HTMLElement} container - A DOM element where the component will be mounted.
344
+ * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.
345
+ * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.
314
346
  * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.
315
- * @throws Will throw an error if the container or component is not found.
347
+ * @throws {Error} If the container is not found or if the component is not registered.
316
348
  */
317
- mount(selectorOrElement, compName, props = {}) {
318
- const container = typeof selectorOrElement === "string" ? document.querySelector(selectorOrElement) : selectorOrElement;
319
- if (!container) throw new Error(`Container not found: ${selectorOrElement}`);
320
- const definition = this._components[compName];
321
- if (!definition) throw new Error(`Component "${compName}" not registered.`);
349
+ mount(container, compName, props = {}) {
350
+ if (!container) throw new Error(`Container not found: ${container}`);
351
+ let definition;
352
+ if (typeof compName === "string") {
353
+ definition = this._components[compName];
354
+ if (!definition) throw new Error(`Component "${compName}" not registered.`);
355
+ } else if (typeof compName === "object") {
356
+ definition = compName;
357
+ } else {
358
+ throw new Error("Invalid component parameter.");
359
+ }
360
+
361
+ /**
362
+ * Destructure the component definition to access core functionality.
363
+ * - setup: Optional function for component initialization and state management
364
+ * - template: Required function that returns the component's HTML structure
365
+ * - style: Optional function for component-scoped CSS styles
366
+ * - children: Optional object defining nested child components
367
+ */
322
368
  const {
323
369
  setup,
324
370
  template,
325
371
  style,
326
372
  children
327
373
  } = definition;
374
+
375
+ /**
376
+ * Creates the initial context object for the component instance.
377
+ * This context provides core functionality and will be merged with setup data.
378
+ * @type {Object<string, any>}
379
+ * @property {Object<string, any>} props - Component properties passed during mounting
380
+ * @property {Emitter} emitter - Event emitter instance for component event handling
381
+ * @property {function(any): Signal} signal - Factory function to create reactive Signal instances
382
+ * @property {Object<string, function(): void>} ...lifecycleHooks - Prepared lifecycle hook functions
383
+ */
328
384
  const context = {
329
385
  props,
330
- emit: this.emitter.emit.bind(this.emitter),
331
- on: this.emitter.on.bind(this.emitter),
386
+ emitter: this.emitter,
332
387
  signal: v => new Signal(v),
333
388
  ...this._prepareLifecycleHooks()
334
389
  };
@@ -336,7 +391,7 @@ class Eleva {
336
391
  /**
337
392
  * Processes the mounting of the component.
338
393
  *
339
- * @param {object} data - Data returned from the component's setup function.
394
+ * @param {Object<string, any>} data - Data returned from the component's setup function.
340
395
  * @returns {object} An object with the container, merged context data, and an unmount function.
341
396
  */
342
397
  const processMount = data => {
@@ -369,6 +424,12 @@ class Eleva {
369
424
  mergedContext.onUpdate && mergedContext.onUpdate();
370
425
  }
371
426
  };
427
+
428
+ /**
429
+ * Sets up reactive watchers for all Signal instances in the component's data.
430
+ * When a Signal's value changes, the component will re-render to reflect the updates.
431
+ * Stores unsubscribe functions to clean up watchers when component unmounts.
432
+ */
372
433
  Object.values(data).forEach(val => {
373
434
  if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));
374
435
  });
@@ -378,6 +439,8 @@ class Eleva {
378
439
  data: mergedContext,
379
440
  /**
380
441
  * Unmounts the component, cleaning up watchers, child components, and clearing the container.
442
+ *
443
+ * @returns {void}
381
444
  */
382
445
  unmount: () => {
383
446
  watcherUnsubscribers.forEach(fn => fn());
@@ -388,20 +451,14 @@ class Eleva {
388
451
  };
389
452
  };
390
453
 
391
- // Handle asynchronous setup if needed.
392
- const setupResult = setup(context);
393
- if (setupResult && typeof setupResult.then === "function") {
394
- return setupResult.then(data => processMount(data));
395
- } else {
396
- const data = setupResult || {};
397
- return processMount(data);
398
- }
454
+ // Handle asynchronous setup.
455
+ return Promise.resolve(typeof setup === "function" ? setup(context) : {}).then(data => processMount(data));
399
456
  }
400
457
 
401
458
  /**
402
459
  * Prepares default no-operation lifecycle hook functions.
403
460
  *
404
- * @returns {object} An object with keys for lifecycle hooks mapped to empty functions.
461
+ * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.
405
462
  * @private
406
463
  */
407
464
  _prepareLifecycleHooks() {
@@ -415,7 +472,7 @@ class Eleva {
415
472
  * Processes DOM elements for event binding based on attributes starting with "@".
416
473
  *
417
474
  * @param {HTMLElement} container - The container element in which to search for events.
418
- * @param {object} context - The current context containing event handler definitions.
475
+ * @param {Object<string, any>} context - The current context containing event handler definitions.
419
476
  * @private
420
477
  */
421
478
  _processEvents(container, context) {
@@ -441,8 +498,8 @@ class Eleva {
441
498
  *
442
499
  * @param {HTMLElement} container - The container element.
443
500
  * @param {string} compName - The component name used to identify the style element.
444
- * @param {Function} styleFn - A function that returns CSS styles as a string.
445
- * @param {object} context - The current context for style interpolation.
501
+ * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.
502
+ * @param {Object<string, any>} context - The current context for style interpolation.
446
503
  * @private
447
504
  */
448
505
  _injectStyles(container, compName, styleFn, context) {
@@ -461,15 +518,15 @@ class Eleva {
461
518
  * Mounts child components within the parent component's container.
462
519
  *
463
520
  * @param {HTMLElement} container - The parent container element.
464
- * @param {object} children - An object mapping child component selectors to their definitions.
465
- * @param {Array} childInstances - An array to store the mounted child component instances.
521
+ * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.
522
+ * @param {Array<object>} childInstances - An array to store the mounted child component instances.
466
523
  * @private
467
524
  */
468
525
  _mountChildren(container, children, childInstances) {
469
526
  childInstances.forEach(child => child.unmount());
470
527
  childInstances.length = 0;
471
- Object.keys(children || {}).forEach(childName => {
472
- container.querySelectorAll(childName).forEach(childEl => {
528
+ Object.keys(children || {}).forEach(childSelector => {
529
+ container.querySelectorAll(childSelector).forEach(childEl => {
473
530
  const props = {};
474
531
  [...childEl.attributes].forEach(({
475
532
  name,
@@ -479,7 +536,7 @@ class Eleva {
479
536
  props[name.slice("eleva-prop-".length)] = value;
480
537
  }
481
538
  });
482
- const instance = this.mount(childEl, childName, props);
539
+ const instance = this.mount(childEl, children[childSelector], props);
483
540
  childInstances.push(instance);
484
541
  });
485
542
  });
@@ -1 +1 @@
1
- {"version":3,"file":"eleva.esm.js","sources":["../src/modules/TemplateEngine.js","../src/modules/Signal.js","../src/modules/Emitter.js","../src/modules/Renderer.js","../src/core/Eleva.js"],"sourcesContent":["\"use strict\";\n\n/**\n * 🔒 TemplateEngine: Secure interpolation & dynamic attribute parsing.\n *\n * This class provides methods to parse template strings by replacing\n * interpolation expressions with dynamic data values and to evaluate expressions\n * within a given data context.\n */\nexport class TemplateEngine {\n /**\n * Parses a template string and replaces interpolation expressions with corresponding values.\n *\n * @param {string} template - The template string containing expressions in the format {{ expression }}.\n * @param {object} data - The data object to use for evaluating expressions.\n * @returns {string} The resulting string with evaluated values.\n */\n static parse(template, data) {\n return template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, expr) => {\n const value = this.evaluate(expr, data);\n return value === undefined ? \"\" : value;\n });\n }\n\n /**\n * Evaluates an expression using the provided data context.\n *\n * @param {string} expr - The JavaScript expression to evaluate.\n * @param {object} data - The data context for evaluating the expression.\n * @returns {*} The result of the evaluated expression, or an empty string if undefined or on error.\n */\n static evaluate(expr, data) {\n try {\n const keys = Object.keys(data);\n const values = keys.map((k) => data[k]);\n const result = new Function(...keys, `return ${expr}`)(...values);\n return result === undefined ? \"\" : result;\n } catch (error) {\n console.error(`Template evaluation error:`, {\n expression: expr,\n data,\n error: error.message,\n });\n return \"\";\n }\n }\n}\n","\"use strict\";\n\n/**\n * ⚡ Signal: Fine-grained reactivity.\n *\n * A reactive data holder that notifies registered watchers when its value changes,\n * allowing for fine-grained DOM patching rather than full re-renders.\n */\nexport class Signal {\n /**\n * Creates a new Signal instance.\n *\n * @param {*} value - The initial value of the signal.\n */\n constructor(value) {\n this._value = value;\n this._watchers = new Set();\n }\n\n /**\n * Gets the current value of the signal.\n *\n * @returns {*} The current value.\n */\n get value() {\n return this._value;\n }\n\n /**\n * Sets a new value for the signal and notifies all registered watchers if the value has changed.\n *\n * @param {*} newVal - The new value to set.\n */\n set value(newVal) {\n if (newVal !== this._value) {\n this._value = newVal;\n this._watchers.forEach((fn) => fn(newVal));\n }\n }\n\n /**\n * Registers a watcher function that will be called whenever the signal's value changes.\n *\n * @param {Function} fn - The callback function to invoke on value change.\n * @returns {Function} A function to unsubscribe the watcher.\n */\n watch(fn) {\n this._watchers.add(fn);\n return () => this._watchers.delete(fn);\n }\n}\n","\"use strict\";\n\n/**\n * 🎙️ Emitter: Robust inter-component communication with event bubbling.\n *\n * Implements a basic publish-subscribe pattern for event handling,\n * allowing components to communicate through custom events.\n */\nexport class Emitter {\n /**\n * Creates a new Emitter instance.\n */\n constructor() {\n /** @type {Object.<string, Function[]>} */\n this.events = {};\n }\n\n /**\n * Registers an event handler for the specified event.\n *\n * @param {string} event - The name of the event.\n * @param {Function} handler - The function to call when the event is emitted.\n */\n on(event, handler) {\n (this.events[event] || (this.events[event] = [])).push(handler);\n }\n\n /**\n * Removes a previously registered event handler.\n *\n * @param {string} event - The name of the event.\n * @param {Function} handler - The handler function to remove.\n */\n off(event, handler) {\n if (this.events[event]) {\n this.events[event] = this.events[event].filter((h) => h !== handler);\n }\n }\n\n /**\n * Emits an event, invoking all handlers registered for that event.\n *\n * @param {string} event - The event name.\n * @param {...*} args - Additional arguments to pass to the event handlers.\n */\n emit(event, ...args) {\n (this.events[event] || []).forEach((handler) => handler(...args));\n }\n}\n","\"use strict\";\n\n/**\n * 🎨 Renderer: Handles DOM patching, diffing, and attribute updates.\n *\n * Provides methods for efficient DOM updates by diffing the new and old DOM structures\n * and applying only the necessary changes.\n */\nexport class Renderer {\n /**\n * Patches the DOM of a container element with new HTML content.\n *\n * @param {HTMLElement} container - The container element to patch.\n * @param {string} newHtml - The new HTML content to apply.\n */\n patchDOM(container, newHtml) {\n const tempContainer = document.createElement(\"div\");\n tempContainer.innerHTML = newHtml;\n this.diff(container, tempContainer);\n }\n\n /**\n * Diffs two DOM trees (old and new) and applies updates to the old DOM.\n *\n * @param {HTMLElement} oldParent - The original DOM element.\n * @param {HTMLElement} newParent - The new DOM element.\n */\n diff(oldParent, newParent) {\n const oldNodes = Array.from(oldParent.childNodes);\n const newNodes = Array.from(newParent.childNodes);\n const max = Math.max(oldNodes.length, newNodes.length);\n for (let i = 0; i < max; i++) {\n const oldNode = oldNodes[i];\n const newNode = newNodes[i];\n\n // Append new nodes that don't exist in the old tree.\n if (!oldNode && newNode) {\n oldParent.appendChild(newNode.cloneNode(true));\n continue;\n }\n // Remove old nodes not present in the new tree.\n if (oldNode && !newNode) {\n oldParent.removeChild(oldNode);\n continue;\n }\n\n // For element nodes, compare keys if available.\n if (\n oldNode.nodeType === Node.ELEMENT_NODE &&\n newNode.nodeType === Node.ELEMENT_NODE\n ) {\n const oldKey = oldNode.getAttribute(\"key\");\n const newKey = newNode.getAttribute(\"key\");\n if (oldKey || newKey) {\n if (oldKey !== newKey) {\n oldParent.replaceChild(newNode.cloneNode(true), oldNode);\n continue;\n }\n }\n }\n\n // Replace nodes if types or tag names differ.\n if (\n oldNode.nodeType !== newNode.nodeType ||\n oldNode.nodeName !== newNode.nodeName\n ) {\n oldParent.replaceChild(newNode.cloneNode(true), oldNode);\n continue;\n }\n // For text nodes, update content if different.\n if (oldNode.nodeType === Node.TEXT_NODE) {\n if (oldNode.nodeValue !== newNode.nodeValue) {\n oldNode.nodeValue = newNode.nodeValue;\n }\n continue;\n }\n // For element nodes, update attributes and then diff children.\n if (oldNode.nodeType === Node.ELEMENT_NODE) {\n this.updateAttributes(oldNode, newNode);\n this.diff(oldNode, newNode);\n }\n }\n }\n\n /**\n * Updates the attributes of an element to match those of a new element.\n *\n * @param {HTMLElement} oldEl - The element to update.\n * @param {HTMLElement} newEl - The element providing the updated attributes.\n */\n updateAttributes(oldEl, newEl) {\n const attributeToPropertyMap = {\n value: \"value\",\n checked: \"checked\",\n selected: \"selected\",\n disabled: \"disabled\",\n };\n\n // Remove old attributes that no longer exist.\n Array.from(oldEl.attributes).forEach((attr) => {\n if (attr.name.startsWith(\"@\")) return;\n if (!newEl.hasAttribute(attr.name)) {\n oldEl.removeAttribute(attr.name);\n }\n });\n // Add or update attributes from newEl.\n Array.from(newEl.attributes).forEach((attr) => {\n if (attr.name.startsWith(\"@\")) return;\n if (oldEl.getAttribute(attr.name) !== attr.value) {\n oldEl.setAttribute(attr.name, attr.value);\n if (attributeToPropertyMap[attr.name]) {\n oldEl[attributeToPropertyMap[attr.name]] = attr.value;\n } else if (attr.name in oldEl) {\n oldEl[attr.name] = attr.value;\n }\n }\n });\n }\n}\n","\"use strict\";\n\nimport { TemplateEngine } from \"../modules/TemplateEngine.js\";\nimport { Signal } from \"../modules/Signal.js\";\nimport { Emitter } from \"../modules/Emitter.js\";\nimport { Renderer } from \"../modules/Renderer.js\";\n\n/**\n * 🧩 Eleva Core: Signal-based component runtime framework with lifecycle, scoped styles, and plugins.\n *\n * The Eleva class is the core of the framework. It manages component registration,\n * plugin integration, lifecycle hooks, event handling, and DOM rendering.\n */\nexport class Eleva {\n /**\n * Creates a new Eleva instance.\n *\n * @param {string} name - The name of the Eleva instance.\n * @param {object} [config={}] - Optional configuration for the instance.\n */\n constructor(name, config = {}) {\n this.name = name;\n this.config = config;\n this._components = {};\n this._plugins = [];\n this._lifecycleHooks = [\n \"onBeforeMount\",\n \"onMount\",\n \"onBeforeUpdate\",\n \"onUpdate\",\n \"onUnmount\",\n ];\n this._isMounted = false;\n this.emitter = new Emitter();\n this.renderer = new Renderer();\n }\n\n /**\n * Integrates a plugin with the Eleva framework.\n *\n * @param {object} [plugin] - The plugin object which should have an install function.\n * @param {object} [options={}] - Optional options to pass to the plugin.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n use(plugin, options = {}) {\n if (typeof plugin.install === \"function\") {\n plugin.install(this, options);\n }\n this._plugins.push(plugin);\n return this;\n }\n\n /**\n * Registers a component with the Eleva instance.\n *\n * @param {string} name - The name of the component.\n * @param {object} definition - The component definition including setup, template, style, and children.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n component(name, definition) {\n this._components[name] = definition;\n return this;\n }\n\n /**\n * Mounts a registered component to a DOM element.\n *\n * @param {string|HTMLElement} selectorOrElement - A CSS selector string or DOM element where the component will be mounted.\n * @param {string} compName - The name of the component to mount.\n * @param {object} [props={}] - Optional properties to pass to the component.\n * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.\n * @throws Will throw an error if the container or component is not found.\n */\n mount(selectorOrElement, compName, props = {}) {\n const container =\n typeof selectorOrElement === \"string\"\n ? document.querySelector(selectorOrElement)\n : selectorOrElement;\n if (!container)\n throw new Error(`Container not found: ${selectorOrElement}`);\n\n const definition = this._components[compName];\n if (!definition) throw new Error(`Component \"${compName}\" not registered.`);\n\n const { setup, template, style, children } = definition;\n const context = {\n props,\n emit: this.emitter.emit.bind(this.emitter),\n on: this.emitter.on.bind(this.emitter),\n signal: (v) => new Signal(v),\n ...this._prepareLifecycleHooks(),\n };\n\n /**\n * Processes the mounting of the component.\n *\n * @param {object} data - Data returned from the component's setup function.\n * @returns {object} An object with the container, merged context data, and an unmount function.\n */\n const processMount = (data) => {\n const mergedContext = { ...context, ...data };\n const watcherUnsubscribers = [];\n const childInstances = [];\n\n if (!this._isMounted) {\n mergedContext.onBeforeMount && mergedContext.onBeforeMount();\n } else {\n mergedContext.onBeforeUpdate && mergedContext.onBeforeUpdate();\n }\n\n /**\n * Renders the component by parsing the template, patching the DOM,\n * processing events, injecting styles, and mounting child components.\n */\n const render = () => {\n const newHtml = TemplateEngine.parse(\n template(mergedContext),\n mergedContext\n );\n this.renderer.patchDOM(container, newHtml);\n this._processEvents(container, mergedContext);\n this._injectStyles(container, compName, style, mergedContext);\n this._mountChildren(container, children, childInstances);\n if (!this._isMounted) {\n mergedContext.onMount && mergedContext.onMount();\n this._isMounted = true;\n } else {\n mergedContext.onUpdate && mergedContext.onUpdate();\n }\n };\n\n Object.values(data).forEach((val) => {\n if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));\n });\n\n render();\n\n return {\n container,\n data: mergedContext,\n /**\n * Unmounts the component, cleaning up watchers, child components, and clearing the container.\n */\n unmount: () => {\n watcherUnsubscribers.forEach((fn) => fn());\n childInstances.forEach((child) => child.unmount());\n mergedContext.onUnmount && mergedContext.onUnmount();\n container.innerHTML = \"\";\n },\n };\n };\n\n // Handle asynchronous setup if needed.\n const setupResult = setup(context);\n if (setupResult && typeof setupResult.then === \"function\") {\n return setupResult.then((data) => processMount(data));\n } else {\n const data = setupResult || {};\n return processMount(data);\n }\n }\n\n /**\n * Prepares default no-operation lifecycle hook functions.\n *\n * @returns {object} An object with keys for lifecycle hooks mapped to empty functions.\n * @private\n */\n _prepareLifecycleHooks() {\n return this._lifecycleHooks.reduce((acc, hook) => {\n acc[hook] = () => {};\n return acc;\n }, {});\n }\n\n /**\n * Processes DOM elements for event binding based on attributes starting with \"@\".\n *\n * @param {HTMLElement} container - The container element in which to search for events.\n * @param {object} context - The current context containing event handler definitions.\n * @private\n */\n _processEvents(container, context) {\n container.querySelectorAll(\"*\").forEach((el) => {\n [...el.attributes].forEach(({ name, value }) => {\n if (name.startsWith(\"@\")) {\n const event = name.slice(1);\n const handler = TemplateEngine.evaluate(value, context);\n if (typeof handler === \"function\") {\n el.addEventListener(event, handler);\n el.removeAttribute(name);\n }\n }\n });\n });\n }\n\n /**\n * Injects scoped styles into the component's container.\n *\n * @param {HTMLElement} container - The container element.\n * @param {string} compName - The component name used to identify the style element.\n * @param {Function} styleFn - A function that returns CSS styles as a string.\n * @param {object} context - The current context for style interpolation.\n * @private\n */\n _injectStyles(container, compName, styleFn, context) {\n if (styleFn) {\n let styleEl = container.querySelector(\n `style[data-eleva-style=\"${compName}\"]`\n );\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.setAttribute(\"data-eleva-style\", compName);\n container.appendChild(styleEl);\n }\n styleEl.textContent = TemplateEngine.parse(styleFn(context), context);\n }\n }\n\n /**\n * Mounts child components within the parent component's container.\n *\n * @param {HTMLElement} container - The parent container element.\n * @param {object} children - An object mapping child component selectors to their definitions.\n * @param {Array} childInstances - An array to store the mounted child component instances.\n * @private\n */\n _mountChildren(container, children, childInstances) {\n childInstances.forEach((child) => child.unmount());\n childInstances.length = 0;\n\n Object.keys(children || {}).forEach((childName) => {\n container.querySelectorAll(childName).forEach((childEl) => {\n const props = {};\n [...childEl.attributes].forEach(({ name, value }) => {\n if (name.startsWith(\"eleva-prop-\")) {\n props[name.slice(\"eleva-prop-\".length)] = value;\n }\n });\n const instance = this.mount(childEl, childName, props);\n childInstances.push(instance);\n });\n });\n }\n}\n"],"names":["TemplateEngine","parse","template","data","replace","_","expr","value","evaluate","undefined","keys","Object","values","map","k","result","Function","error","console","expression","message","Signal","constructor","_value","_watchers","Set","newVal","forEach","fn","watch","add","delete","Emitter","events","on","event","handler","push","off","filter","h","emit","args","Renderer","patchDOM","container","newHtml","tempContainer","document","createElement","innerHTML","diff","oldParent","newParent","oldNodes","Array","from","childNodes","newNodes","max","Math","length","i","oldNode","newNode","appendChild","cloneNode","removeChild","nodeType","Node","ELEMENT_NODE","oldKey","getAttribute","newKey","replaceChild","nodeName","TEXT_NODE","nodeValue","updateAttributes","oldEl","newEl","attributeToPropertyMap","checked","selected","disabled","attributes","attr","name","startsWith","hasAttribute","removeAttribute","setAttribute","Eleva","config","_components","_plugins","_lifecycleHooks","_isMounted","emitter","renderer","use","plugin","options","install","component","definition","mount","selectorOrElement","compName","props","querySelector","Error","setup","style","children","context","bind","signal","v","_prepareLifecycleHooks","processMount","mergedContext","watcherUnsubscribers","childInstances","onBeforeMount","onBeforeUpdate","render","_processEvents","_injectStyles","_mountChildren","onMount","onUpdate","val","unmount","child","onUnmount","setupResult","then","reduce","acc","hook","querySelectorAll","el","slice","addEventListener","styleFn","styleEl","textContent","childName","childEl","instance"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,CAAC;AAC1B;AACF;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,OAAOC,KAAKA,CAACC,QAAQ,EAAEC,IAAI,EAAE;IAC3B,OAAOD,QAAQ,CAACE,OAAO,CAAC,sBAAsB,EAAE,CAACC,CAAC,EAAEC,IAAI,KAAK;MAC3D,MAAMC,KAAK,GAAG,IAAI,CAACC,QAAQ,CAACF,IAAI,EAAEH,IAAI,CAAC;AACvC,MAAA,OAAOI,KAAK,KAAKE,SAAS,GAAG,EAAE,GAAGF,KAAK;AACzC,KAAC,CAAC;AACJ;;AAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,OAAOC,QAAQA,CAACF,IAAI,EAAEH,IAAI,EAAE;IAC1B,IAAI;AACF,MAAA,MAAMO,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACP,IAAI,CAAC;AAC9B,MAAA,MAAMS,MAAM,GAAGF,IAAI,CAACG,GAAG,CAAEC,CAAC,IAAKX,IAAI,CAACW,CAAC,CAAC,CAAC;AACvC,MAAA,MAAMC,MAAM,GAAG,IAAIC,QAAQ,CAAC,GAAGN,IAAI,EAAE,CAAA,OAAA,EAAUJ,IAAI,CAAE,CAAA,CAAC,CAAC,GAAGM,MAAM,CAAC;AACjE,MAAA,OAAOG,MAAM,KAAKN,SAAS,GAAG,EAAE,GAAGM,MAAM;KAC1C,CAAC,OAAOE,KAAK,EAAE;AACdC,MAAAA,OAAO,CAACD,KAAK,CAAC,CAAA,0BAAA,CAA4B,EAAE;AAC1CE,QAAAA,UAAU,EAAEb,IAAI;QAChBH,IAAI;QACJc,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AACA;AACEc,EAAAA,cAAcA,CAACpF,SAAS,EAAEqE,QAAQ,EAAES,cAAc,EAAE;IAClDA,cAAc,CAAChG,OAAO,CAAE2G,KAAK,IAAKA,KAAK,CAACD,OAAO,EAAE,CAAC;IAClDV,cAAc,CAAC9D,MAAM,GAAG,CAAC;AAEzBlD,IAAAA,MAAM,CAACD,IAAI,CAACwG,QAAQ,IAAI,EAAE,CAAC,CAACvF,OAAO,CAAEyH,SAAS,IAAK;MACjDvG,SAAS,CAACgG,gBAAgB,CAACO,SAAS,CAAC,CAACzH,OAAO,CAAE0H,OAAO,IAAK;QACzD,MAAMxC,KAAK,GAAG,EAAE;QAChB,CAAC,GAAGwC,OAAO,CAAChE,UAAU,CAAC,CAAC1D,OAAO,CAAC,CAAC;UAAE4D,IAAI;AAAEhF,UAAAA;AAAM,SAAC,KAAK;AACnD,UAAA,IAAIgF,IAAI,CAACC,UAAU,CAAC,aAAa,CAAC,EAAE;YAClCqB,KAAK,CAACtB,IAAI,CAACwD,KAAK,CAAC,aAAa,CAAClF,MAAM,CAAC,CAAC,GAAGtD,KAAK;AACjD;AACF,SAAC,CAAC;QACF,MAAM+I,QAAQ,GAAG,IAAI,CAAC5C,KAAK,CAAC2C,OAAO,EAAED,SAAS,EAAEvC,KAAK,CAAC;AACtDc,QAAAA,cAAc,CAACtF,IAAI,CAACiH,QAAQ,CAAC;AAC/B,OAAC,CAAC;AACJ,KAAC,CAAC;AACJ;AACF;;;;"}
1
+ {"version":3,"file":"eleva.esm.js","sources":["../src/modules/TemplateEngine.js","../src/modules/Signal.js","../src/modules/Emitter.js","../src/modules/Renderer.js","../src/core/Eleva.js"],"sourcesContent":["\"use strict\";\n\n/**\n * @class 🔒 TemplateEngine\n * @classdesc Secure interpolation & dynamic attribute parsing.\n * Provides methods to parse template strings by replacing interpolation expressions\n * with dynamic data values and to evaluate expressions within a given data context.\n */\nexport class TemplateEngine {\n /**\n * Parses a template string and replaces interpolation expressions with corresponding values.\n *\n * @param {string} template - The template string containing expressions in the format `{{ expression }}`.\n * @param {Object<string, any>} data - The data object to use for evaluating expressions.\n * @returns {string} The resulting string with evaluated values.\n */\n static parse(template, data) {\n return template.replace(/\\{\\{\\s*(.*?)\\s*\\}\\}/g, (_, expr) => {\n const value = this.evaluate(expr, data);\n return value === undefined ? \"\" : value;\n });\n }\n\n /**\n * Evaluates a JavaScript expression using the provided data context.\n *\n * @param {string} expr - The JavaScript expression to evaluate.\n * @param {Object<string, any>} data - The data context for evaluating the expression.\n * @returns {any} The result of the evaluated expression, or an empty string if undefined or on error.\n */\n static evaluate(expr, data) {\n try {\n const keys = Object.keys(data);\n const values = Object.values(data);\n const result = new Function(...keys, `return ${expr}`)(...values);\n return result === undefined ? \"\" : result;\n } catch (error) {\n console.error(`Template evaluation error:`, {\n expression: expr,\n data,\n error: error.message,\n });\n return \"\";\n }\n }\n}\n","\"use strict\";\n\n/**\n * @class ⚡ Signal\n * @classdesc Fine-grained reactivity.\n * A reactive data holder that notifies registered watchers when its value changes,\n * enabling fine-grained DOM patching rather than full re-renders.\n */\nexport class Signal {\n /**\n * Creates a new Signal instance.\n *\n * @param {*} value - The initial value of the signal.\n */\n constructor(value) {\n /** @private {*} Internal storage for the signal's current value */\n this._value = value;\n /** @private {Set<function>} Collection of callback functions to be notified when value changes */\n this._watchers = new Set();\n }\n\n /**\n * Gets the current value of the signal.\n *\n * @returns {*} The current value.\n */\n get value() {\n return this._value;\n }\n\n /**\n * Sets a new value for the signal and notifies all registered watchers if the value has changed.\n *\n * @param {*} newVal - The new value to set.\n */\n set value(newVal) {\n if (newVal !== this._value) {\n this._value = newVal;\n this._watchers.forEach((fn) => fn(newVal));\n }\n }\n\n /**\n * Registers a watcher function that will be called whenever the signal's value changes.\n *\n * @param {function(any): void} fn - The callback function to invoke on value change.\n * @returns {function(): boolean} A function to unsubscribe the watcher.\n */\n watch(fn) {\n this._watchers.add(fn);\n return () => this._watchers.delete(fn);\n }\n}\n","\"use strict\";\n\n/**\n * @class 🎙️ Emitter\n * @classdesc Robust inter-component communication with event bubbling.\n * Implements a basic publish-subscribe pattern for event handling, allowing components\n * to communicate through custom events.\n */\nexport class Emitter {\n /**\n * Creates a new Emitter instance.\n */\n constructor() {\n /** @type {Object.<string, Function[]>} Storage for event handlers mapped by event name */\n this.events = {};\n }\n\n /**\n * Registers an event handler for the specified event.\n *\n * @param {string} event - The name of the event.\n * @param {function(...any): void} handler - The function to call when the event is emitted.\n */\n on(event, handler) {\n (this.events[event] || (this.events[event] = [])).push(handler);\n }\n\n /**\n * Removes a previously registered event handler.\n *\n * @param {string} event - The name of the event.\n * @param {function(...any): void} handler - The handler function to remove.\n */\n off(event, handler) {\n if (this.events[event]) {\n this.events[event] = this.events[event].filter((h) => h !== handler);\n }\n }\n\n /**\n * Emits an event, invoking all handlers registered for that event.\n *\n * @param {string} event - The event name.\n * @param {...any} args - Additional arguments to pass to the event handlers.\n */\n emit(event, ...args) {\n (this.events[event] || []).forEach((handler) => handler(...args));\n }\n}\n","\"use strict\";\n\n/**\n * @class 🎨 Renderer\n * @classdesc Handles DOM patching, diffing, and attribute updates.\n * Provides methods for efficient DOM updates by diffing the new and old DOM structures\n * and applying only the necessary changes.\n */\nexport class Renderer {\n /**\n * Patches the DOM of a container element with new HTML content.\n *\n * @param {HTMLElement} container - The container element to patch.\n * @param {string} newHtml - The new HTML content to apply.\n */\n patchDOM(container, newHtml) {\n const tempContainer = document.createElement(\"div\");\n tempContainer.innerHTML = newHtml;\n this.diff(container, tempContainer);\n }\n\n /**\n * Diffs two DOM trees (old and new) and applies updates to the old DOM.\n *\n * @param {HTMLElement} oldParent - The original DOM element.\n * @param {HTMLElement} newParent - The new DOM element.\n */\n diff(oldParent, newParent) {\n const oldNodes = Array.from(oldParent.childNodes);\n const newNodes = Array.from(newParent.childNodes);\n const max = Math.max(oldNodes.length, newNodes.length);\n for (let i = 0; i < max; i++) {\n const oldNode = oldNodes[i];\n const newNode = newNodes[i];\n\n // Case 1: Append new nodes that don't exist in the old tree.\n if (!oldNode && newNode) {\n oldParent.appendChild(newNode.cloneNode(true));\n continue;\n }\n // Case 2: Remove old nodes not present in the new tree.\n if (oldNode && !newNode) {\n oldParent.removeChild(oldNode);\n continue;\n }\n\n // Case 3: For element nodes, compare keys if available.\n if (\n oldNode.nodeType === Node.ELEMENT_NODE &&\n newNode.nodeType === Node.ELEMENT_NODE\n ) {\n const oldKey = oldNode.getAttribute(\"key\");\n const newKey = newNode.getAttribute(\"key\");\n if (oldKey || newKey) {\n if (oldKey !== newKey) {\n oldParent.replaceChild(newNode.cloneNode(true), oldNode);\n continue;\n }\n }\n }\n\n // Case 4: Replace nodes if types or tag names differ.\n if (\n oldNode.nodeType !== newNode.nodeType ||\n oldNode.nodeName !== newNode.nodeName\n ) {\n oldParent.replaceChild(newNode.cloneNode(true), oldNode);\n continue;\n }\n // Case 5: For text nodes, update content if different.\n if (oldNode.nodeType === Node.TEXT_NODE) {\n if (oldNode.nodeValue !== newNode.nodeValue) {\n oldNode.nodeValue = newNode.nodeValue;\n }\n continue;\n }\n // Case 6: For element nodes, update attributes and then diff children.\n if (oldNode.nodeType === Node.ELEMENT_NODE) {\n this.updateAttributes(oldNode, newNode);\n this.diff(oldNode, newNode);\n }\n }\n }\n\n /**\n * Updates the attributes of an element to match those of a new element.\n *\n * @param {HTMLElement} oldEl - The element to update.\n * @param {HTMLElement} newEl - The element providing the updated attributes.\n */\n updateAttributes(oldEl, newEl) {\n const attributeToPropertyMap = {\n value: \"value\",\n checked: \"checked\",\n selected: \"selected\",\n disabled: \"disabled\",\n };\n\n // Remove old attributes that no longer exist.\n Array.from(oldEl.attributes).forEach((attr) => {\n if (attr.name.startsWith(\"@\")) return;\n if (!newEl.hasAttribute(attr.name)) {\n oldEl.removeAttribute(attr.name);\n }\n });\n // Add or update attributes from newEl.\n Array.from(newEl.attributes).forEach((attr) => {\n if (attr.name.startsWith(\"@\")) return;\n if (oldEl.getAttribute(attr.name) !== attr.value) {\n oldEl.setAttribute(attr.name, attr.value);\n if (attributeToPropertyMap[attr.name]) {\n oldEl[attributeToPropertyMap[attr.name]] = attr.value;\n } else if (attr.name in oldEl) {\n oldEl[attr.name] = attr.value;\n }\n }\n });\n }\n}\n","\"use strict\";\n\nimport { TemplateEngine } from \"../modules/TemplateEngine.js\";\nimport { Signal } from \"../modules/Signal.js\";\nimport { Emitter } from \"../modules/Emitter.js\";\nimport { Renderer } from \"../modules/Renderer.js\";\n\n/**\n * Defines the structure and behavior of a component.\n * @typedef {Object} ComponentDefinition\n * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]\n * Optional setup function that initializes the component's reactive state and lifecycle.\n * Receives props and context as an argument and should return an object containing the component's state.\n * Can return either a synchronous object or a Promise that resolves to an object for async initialization.\n *\n * @property {function(Object<string, any>): string} template\n * Required function that defines the component's HTML structure.\n * Receives the merged context (props + setup data) and must return an HTML template string.\n * Supports dynamic expressions using {{ }} syntax for reactive data binding.\n *\n * @property {function(Object<string, any>): string} [style]\n * Optional function that defines component-scoped CSS styles.\n * Receives the merged context and returns a CSS string that will be automatically scoped to the component.\n * Styles are injected into the component's container and only affect elements within it.\n *\n * @property {Object<string, ComponentDefinition>} [children]\n * Optional object that defines nested child components.\n * Keys are CSS selectors that match elements in the template where child components should be mounted.\n * Values are ComponentDefinition objects that define the structure and behavior of each child component.\n */\n\n/**\n * @class 🧩 Eleva\n * @classdesc Signal-based component runtime framework with lifecycle hooks, scoped styles, and plugin support.\n * Manages component registration, plugin integration, event handling, and DOM rendering.\n */\nexport class Eleva {\n /**\n * Creates a new Eleva instance.\n *\n * @param {string} name - The name of the Eleva instance.\n * @param {Object<string, any>} [config={}] - Optional configuration for the instance.\n */\n constructor(name, config = {}) {\n /** @type {string} The unique identifier name for this Eleva instance */\n this.name = name;\n /** @type {Object<string, any>} Optional configuration object for the Eleva instance */\n this.config = config;\n /** @type {Object<string, ComponentDefinition>} Object storing registered component definitions by name */\n this._components = {};\n /** @private {Array<Object>} Collection of installed plugin instances */\n this._plugins = [];\n /** @private {string[]} Array of lifecycle hook names supported by the component */\n this._lifecycleHooks = [\n \"onBeforeMount\",\n \"onMount\",\n \"onBeforeUpdate\",\n \"onUpdate\",\n \"onUnmount\",\n ];\n /** @private {boolean} Flag indicating if component is currently mounted */\n this._isMounted = false;\n /** @private {Emitter} Instance of the event emitter for handling component events */\n this.emitter = new Emitter();\n /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */\n this.renderer = new Renderer();\n }\n\n /**\n * Integrates a plugin with the Eleva framework.\n *\n * @param {Object} plugin - The plugin object which should have an `install` function.\n * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n use(plugin, options = {}) {\n if (typeof plugin.install === \"function\") {\n plugin.install(this, options);\n }\n this._plugins.push(plugin);\n return this;\n }\n\n /**\n * Registers a component with the Eleva instance.\n *\n * @param {string} name - The name of the component.\n * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.\n * @returns {Eleva} The Eleva instance (for chaining).\n */\n component(name, definition) {\n this._components[name] = definition;\n return this;\n }\n\n /**\n * Mounts a registered component to a DOM element.\n *\n * @param {HTMLElement} container - A DOM element where the component will be mounted.\n * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.\n * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.\n * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.\n * @throws {Error} If the container is not found or if the component is not registered.\n */\n mount(container, compName, props = {}) {\n if (!container) throw new Error(`Container not found: ${container}`);\n\n let definition;\n if (typeof compName === \"string\") {\n definition = this._components[compName];\n if (!definition)\n throw new Error(`Component \"${compName}\" not registered.`);\n } else if (typeof compName === \"object\") {\n definition = compName;\n } else {\n throw new Error(\"Invalid component parameter.\");\n }\n\n /**\n * Destructure the component definition to access core functionality.\n * - setup: Optional function for component initialization and state management\n * - template: Required function that returns the component's HTML structure\n * - style: Optional function for component-scoped CSS styles\n * - children: Optional object defining nested child components\n */\n const { setup, template, style, children } = definition;\n\n /**\n * Creates the initial context object for the component instance.\n * This context provides core functionality and will be merged with setup data.\n * @type {Object<string, any>}\n * @property {Object<string, any>} props - Component properties passed during mounting\n * @property {Emitter} emitter - Event emitter instance for component event handling\n * @property {function(any): Signal} signal - Factory function to create reactive Signal instances\n * @property {Object<string, function(): void>} ...lifecycleHooks - Prepared lifecycle hook functions\n */\n const context = {\n props,\n emitter: this.emitter,\n signal: (v) => new Signal(v),\n ...this._prepareLifecycleHooks(),\n };\n\n /**\n * Processes the mounting of the component.\n *\n * @param {Object<string, any>} data - Data returned from the component's setup function.\n * @returns {object} An object with the container, merged context data, and an unmount function.\n */\n const processMount = (data) => {\n const mergedContext = { ...context, ...data };\n const watcherUnsubscribers = [];\n const childInstances = [];\n\n if (!this._isMounted) {\n mergedContext.onBeforeMount && mergedContext.onBeforeMount();\n } else {\n mergedContext.onBeforeUpdate && mergedContext.onBeforeUpdate();\n }\n\n /**\n * Renders the component by parsing the template, patching the DOM,\n * processing events, injecting styles, and mounting child components.\n */\n const render = () => {\n const newHtml = TemplateEngine.parse(\n template(mergedContext),\n mergedContext\n );\n this.renderer.patchDOM(container, newHtml);\n this._processEvents(container, mergedContext);\n this._injectStyles(container, compName, style, mergedContext);\n this._mountChildren(container, children, childInstances);\n if (!this._isMounted) {\n mergedContext.onMount && mergedContext.onMount();\n this._isMounted = true;\n } else {\n mergedContext.onUpdate && mergedContext.onUpdate();\n }\n };\n\n /**\n * Sets up reactive watchers for all Signal instances in the component's data.\n * When a Signal's value changes, the component will re-render to reflect the updates.\n * Stores unsubscribe functions to clean up watchers when component unmounts.\n */\n Object.values(data).forEach((val) => {\n if (val instanceof Signal) watcherUnsubscribers.push(val.watch(render));\n });\n\n render();\n\n return {\n container,\n data: mergedContext,\n /**\n * Unmounts the component, cleaning up watchers, child components, and clearing the container.\n *\n * @returns {void}\n */\n unmount: () => {\n watcherUnsubscribers.forEach((fn) => fn());\n childInstances.forEach((child) => child.unmount());\n mergedContext.onUnmount && mergedContext.onUnmount();\n container.innerHTML = \"\";\n },\n };\n };\n\n // Handle asynchronous setup.\n return Promise.resolve(\n typeof setup === \"function\" ? setup(context) : {}\n ).then((data) => processMount(data));\n }\n\n /**\n * Prepares default no-operation lifecycle hook functions.\n *\n * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.\n * @private\n */\n _prepareLifecycleHooks() {\n return this._lifecycleHooks.reduce((acc, hook) => {\n acc[hook] = () => {};\n return acc;\n }, {});\n }\n\n /**\n * Processes DOM elements for event binding based on attributes starting with \"@\".\n *\n * @param {HTMLElement} container - The container element in which to search for events.\n * @param {Object<string, any>} context - The current context containing event handler definitions.\n * @private\n */\n _processEvents(container, context) {\n container.querySelectorAll(\"*\").forEach((el) => {\n [...el.attributes].forEach(({ name, value }) => {\n if (name.startsWith(\"@\")) {\n const event = name.slice(1);\n const handler = TemplateEngine.evaluate(value, context);\n if (typeof handler === \"function\") {\n el.addEventListener(event, handler);\n el.removeAttribute(name);\n }\n }\n });\n });\n }\n\n /**\n * Injects scoped styles into the component's container.\n *\n * @param {HTMLElement} container - The container element.\n * @param {string} compName - The component name used to identify the style element.\n * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.\n * @param {Object<string, any>} context - The current context for style interpolation.\n * @private\n */\n _injectStyles(container, compName, styleFn, context) {\n if (styleFn) {\n let styleEl = container.querySelector(\n `style[data-eleva-style=\"${compName}\"]`\n );\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.setAttribute(\"data-eleva-style\", compName);\n container.appendChild(styleEl);\n }\n styleEl.textContent = TemplateEngine.parse(styleFn(context), context);\n }\n }\n\n /**\n * Mounts child components within the parent component's container.\n *\n * @param {HTMLElement} container - The parent container element.\n * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.\n * @param {Array<object>} childInstances - An array to store the mounted child component instances.\n * @private\n */\n _mountChildren(container, children, childInstances) {\n childInstances.forEach((child) => child.unmount());\n childInstances.length = 0;\n\n Object.keys(children || {}).forEach((childSelector) => {\n container.querySelectorAll(childSelector).forEach((childEl) => {\n const props = {};\n [...childEl.attributes].forEach(({ name, value }) => {\n if (name.startsWith(\"eleva-prop-\")) {\n props[name.slice(\"eleva-prop-\".length)] = value;\n }\n });\n const instance = this.mount(childEl, children[childSelector], props);\n childInstances.push(instance);\n });\n });\n }\n}\n"],"names":["TemplateEngine","parse","template","data","replace","_","expr","value","evaluate","undefined","keys","Object","values","result","Function","error","console","expression","message","Signal","constructor","_value","_watchers","Set","newVal","forEach","fn","watch","add","delete","Emitter","events","on","event","handler","push","off","filter","h","emit","args","Renderer","patchDOM","container","newHtml","tempContainer","document","createElement","innerHTML","diff","oldParent","newParent","oldNodes","Array","from","childNodes","newNodes","max","Math","length","i","oldNode","newNode","appendChild","cloneNode","removeChild","nodeType","Node","ELEMENT_NODE","oldKey","getAttribute","newKey","replaceChild","nodeName","TEXT_NODE","nodeValue","updateAttributes","oldEl","newEl","attributeToPropertyMap","checked","selected","disabled","attributes","attr","name","startsWith","hasAttribute","removeAttribute","setAttribute","Eleva","config","_components","_plugins","_lifecycleHooks","_isMounted","emitter","renderer","use","plugin","options","install","component","definition","mount","compName","props","Error","setup","style","children","context","signal","v","_prepareLifecycleHooks","processMount","mergedContext","watcherUnsubscribers","childInstances","onBeforeMount","onBeforeUpdate","render","_processEvents","_injectStyles","_mountChildren","onMount","onUpdate","val","unmount","child","onUnmount","Promise","resolve","then","reduce","acc","hook","querySelectorAll","el","slice","addEventListener","styleFn","styleEl","querySelector","textContent","childSelector","childEl","instance"],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,cAAc,CAAC;AAC1B;AACF;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,OAAOC,KAAKA,CAACC,QAAQ,EAAEC,IAAI,EAAE;IAC3B,OAAOD,QAAQ,CAACE,OAAO,CAAC,sBAAsB,EAAE,CAACC,CAAC,EAAEC,IAAI,KAAK;MAC3D,MAA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AAC,GAAGwC,OAAO,CAAC/D,UAAU,CAAC,CAAC1D,OAAO,CAAC,CAAC;UAAE4D,IAAI;AAAE9E,UAAAA;AAAM,SAAC,KAAK;AACnD,UAAA,IAAI8E,IAAI,CAACC,UAAU,CAAC,aAAa,CAAC,EAAE;YAClCoB,KAAK,CAACrB,IAAI,CAACsD,KAAK,CAAC,aAAa,CAAChF,MAAM,CAAC,CAAC,GAAGpD,KAAK;AACjD;AACF,SAAC,CAAC;AACF,QAAA,MAAM4I,QAAQ,GAAG,IAAI,CAAC3C,KAAK,CAAC0C,OAAO,EAAEpC,QAAQ,CAACmC,aAAa,CAAC,EAAEvC,KAAK,CAAC;AACpEY,QAAAA,cAAc,CAACnF,IAAI,CAACgH,QAAQ,CAAC;AAC/B,OAAC,CAAC;AACJ,KAAC,CAAC;AACJ;AACF;;;;"}
package/dist/eleva.min.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Eleva=t()}(this,(function(){"use strict";class e{static parse(e,t){return e.replace(/\{\{\s*(.*?)\s*\}\}/g,((e,n)=>{const o=this.evaluate(n,t);return void 0===o?"":o}))}static evaluate(e,t){try{const n=Object.keys(t),o=n.map((e=>t[e])),s=new Function(...n,`return ${e}`)(...o);return void 0===s?"":s}catch(n){return console.error("Template evaluation error:",{expression:e,data:t,error:n.message}),""}}}class t{constructor(e){this._value=e,this._watchers=new Set}get value(){return this._value}set value(e){e!==this._value&&(this._value=e,this._watchers.forEach((t=>t(e))))}watch(e){return this._watchers.add(e),()=>this._watchers.delete(e)}}class n{constructor(){this.events={}}on(e,t){(this.events[e]||(this.events[e]=[])).push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){(this.events[e]||[]).forEach((e=>e(...t)))}}class o{patchDOM(e,t){const n=document.createElement("div");n.innerHTML=t,this.diff(e,n)}diff(e,t){const n=Array.from(e.childNodes),o=Array.from(t.childNodes),s=Math.max(n.length,o.length);for(let t=0;t<s;t++){const s=n[t],r=o[t];if(s||!r)if(!s||r){if(s.nodeType===Node.ELEMENT_NODE&&r.nodeType===Node.ELEMENT_NODE){const t=s.getAttribute("key"),n=r.getAttribute("key");if((t||n)&&t!==n){e.replaceChild(r.cloneNode(!0),s);continue}}s.nodeType===r.nodeType&&s.nodeName===r.nodeName?s.nodeType!==Node.TEXT_NODE?s.nodeType===Node.ELEMENT_NODE&&(this.updateAttributes(s,r),this.diff(s,r)):s.nodeValue!==r.nodeValue&&(s.nodeValue=r.nodeValue):e.replaceChild(r.cloneNode(!0),s)}else e.removeChild(s);else e.appendChild(r.cloneNode(!0))}}updateAttributes(e,t){const n={value:"value",checked:"checked",selected:"selected",disabled:"disabled"};Array.from(e.attributes).forEach((n=>{n.name.startsWith("@")||t.hasAttribute(n.name)||e.removeAttribute(n.name)})),Array.from(t.attributes).forEach((t=>{t.name.startsWith("@")||e.getAttribute(t.name)!==t.value&&(e.setAttribute(t.name,t.value),n[t.name]?e[n[t.name]]=t.value:t.name in e&&(e[t.name]=t.value))}))}}return class{constructor(e,t={}){this.name=e,this.config=t,this._components={},this._plugins=[],this._lifecycleHooks=["onBeforeMount","onMount","onBeforeUpdate","onUpdate","onUnmount"],this._isMounted=!1,this.emitter=new n,this.renderer=new o}use(e,t={}){return"function"==typeof e.install&&e.install(this,t),this._plugins.push(e),this}component(e,t){return this._components[e]=t,this}mount(n,o,s={}){const r="string"==typeof n?document.querySelector(n):n;if(!r)throw new Error(`Container not found: ${n}`);const i=this._components[o];if(!i)throw new Error(`Component "${o}" not registered.`);const{setup:a,template:c,style:u,children:l}=i,h={props:s,emit:this.emitter.emit.bind(this.emitter),on:this.emitter.on.bind(this.emitter),signal:e=>new t(e),...this._prepareLifecycleHooks()},d=n=>{const s={...h,...n},i=[],a=[];this._isMounted?s.onBeforeUpdate&&s.onBeforeUpdate():s.onBeforeMount&&s.onBeforeMount();const d=()=>{const t=e.parse(c(s),s);this.renderer.patchDOM(r,t),this._processEvents(r,s),this._injectStyles(r,o,u,s),this._mountChildren(r,l,a),this._isMounted?s.onUpdate&&s.onUpdate():(s.onMount&&s.onMount(),this._isMounted=!0)};return Object.values(n).forEach((e=>{e instanceof t&&i.push(e.watch(d))})),d(),{container:r,data:s,unmount:()=>{i.forEach((e=>e())),a.forEach((e=>e.unmount())),s.onUnmount&&s.onUnmount(),r.innerHTML=""}}},f=a(h);if(f&&"function"==typeof f.then)return f.then((e=>d(e)));return d(f||{})}_prepareLifecycleHooks(){return this._lifecycleHooks.reduce(((e,t)=>(e[t]=()=>{},e)),{})}_processEvents(t,n){t.querySelectorAll("*").forEach((t=>{[...t.attributes].forEach((({name:o,value:s})=>{if(o.startsWith("@")){const r=o.slice(1),i=e.evaluate(s,n);"function"==typeof i&&(t.addEventListener(r,i),t.removeAttribute(o))}}))}))}_injectStyles(t,n,o,s){if(o){let r=t.querySelector(`style[data-eleva-style="${n}"]`);r||(r=document.createElement("style"),r.setAttribute("data-eleva-style",n),t.appendChild(r)),r.textContent=e.parse(o(s),s)}}_mountChildren(e,t,n){n.forEach((e=>e.unmount())),n.length=0,Object.keys(t||{}).forEach((t=>{e.querySelectorAll(t).forEach((e=>{const o={};[...e.attributes].forEach((({name:e,value:t})=>{e.startsWith("eleva-prop-")&&(o[e.slice(11)]=t)}));const s=this.mount(e,t,o);n.push(s)}))}))}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Eleva=t()}(this,(function(){"use strict";class e{static parse(e,t){return e.replace(/\{\{\s*(.*?)\s*\}\}/g,((e,n)=>{const o=this.evaluate(n,t);return void 0===o?"":o}))}static evaluate(e,t){try{const n=Object.keys(t),o=Object.values(t),s=new Function(...n,`return ${e}`)(...o);return void 0===s?"":s}catch(n){return console.error("Template evaluation error:",{expression:e,data:t,error:n.message}),""}}}class t{constructor(e){this._value=e,this._watchers=new Set}get value(){return this._value}set value(e){e!==this._value&&(this._value=e,this._watchers.forEach((t=>t(e))))}watch(e){return this._watchers.add(e),()=>this._watchers.delete(e)}}class n{constructor(){this.events={}}on(e,t){(this.events[e]||(this.events[e]=[])).push(t)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)))}emit(e,...t){(this.events[e]||[]).forEach((e=>e(...t)))}}class o{patchDOM(e,t){const n=document.createElement("div");n.innerHTML=t,this.diff(e,n)}diff(e,t){const n=Array.from(e.childNodes),o=Array.from(t.childNodes),s=Math.max(n.length,o.length);for(let t=0;t<s;t++){const s=n[t],r=o[t];if(s||!r)if(!s||r){if(s.nodeType===Node.ELEMENT_NODE&&r.nodeType===Node.ELEMENT_NODE){const t=s.getAttribute("key"),n=r.getAttribute("key");if((t||n)&&t!==n){e.replaceChild(r.cloneNode(!0),s);continue}}s.nodeType===r.nodeType&&s.nodeName===r.nodeName?s.nodeType!==Node.TEXT_NODE?s.nodeType===Node.ELEMENT_NODE&&(this.updateAttributes(s,r),this.diff(s,r)):s.nodeValue!==r.nodeValue&&(s.nodeValue=r.nodeValue):e.replaceChild(r.cloneNode(!0),s)}else e.removeChild(s);else e.appendChild(r.cloneNode(!0))}}updateAttributes(e,t){const n={value:"value",checked:"checked",selected:"selected",disabled:"disabled"};Array.from(e.attributes).forEach((n=>{n.name.startsWith("@")||t.hasAttribute(n.name)||e.removeAttribute(n.name)})),Array.from(t.attributes).forEach((t=>{t.name.startsWith("@")||e.getAttribute(t.name)!==t.value&&(e.setAttribute(t.name,t.value),n[t.name]?e[n[t.name]]=t.value:t.name in e&&(e[t.name]=t.value))}))}}return class{constructor(e,t={}){this.name=e,this.config=t,this._components={},this._plugins=[],this._lifecycleHooks=["onBeforeMount","onMount","onBeforeUpdate","onUpdate","onUnmount"],this._isMounted=!1,this.emitter=new n,this.renderer=new o}use(e,t={}){return"function"==typeof e.install&&e.install(this,t),this._plugins.push(e),this}component(e,t){return this._components[e]=t,this}mount(n,o,s={}){if(!n)throw new Error(`Container not found: ${n}`);let r;if("string"==typeof o){if(r=this._components[o],!r)throw new Error(`Component "${o}" not registered.`)}else{if("object"!=typeof o)throw new Error("Invalid component parameter.");r=o}const{setup:i,template:a,style:c,children:l}=r,u={props:s,emitter:this.emitter,signal:e=>new t(e),...this._prepareLifecycleHooks()},h=s=>{const r={...u,...s},i=[],h=[];this._isMounted?r.onBeforeUpdate&&r.onBeforeUpdate():r.onBeforeMount&&r.onBeforeMount();const d=()=>{const t=e.parse(a(r),r);this.renderer.patchDOM(n,t),this._processEvents(n,r),this._injectStyles(n,o,c,r),this._mountChildren(n,l,h),this._isMounted?r.onUpdate&&r.onUpdate():(r.onMount&&r.onMount(),this._isMounted=!0)};return Object.values(s).forEach((e=>{e instanceof t&&i.push(e.watch(d))})),d(),{container:n,data:r,unmount:()=>{i.forEach((e=>e())),h.forEach((e=>e.unmount())),r.onUnmount&&r.onUnmount(),n.innerHTML=""}}};return Promise.resolve("function"==typeof i?i(u):{}).then((e=>h(e)))}_prepareLifecycleHooks(){return this._lifecycleHooks.reduce(((e,t)=>(e[t]=()=>{},e)),{})}_processEvents(t,n){t.querySelectorAll("*").forEach((t=>{[...t.attributes].forEach((({name:o,value:s})=>{if(o.startsWith("@")){const r=o.slice(1),i=e.evaluate(s,n);"function"==typeof i&&(t.addEventListener(r,i),t.removeAttribute(o))}}))}))}_injectStyles(t,n,o,s){if(o){let r=t.querySelector(`style[data-eleva-style="${n}"]`);r||(r=document.createElement("style"),r.setAttribute("data-eleva-style",n),t.appendChild(r)),r.textContent=e.parse(o(s),s)}}_mountChildren(e,t,n){n.forEach((e=>e.unmount())),n.length=0,Object.keys(t||{}).forEach((o=>{e.querySelectorAll(o).forEach((e=>{const s={};[...e.attributes].forEach((({name:e,value:t})=>{e.startsWith("eleva-prop-")&&(s[e.slice(11)]=t)}));const r=this.mount(e,t[o],s);n.push(r)}))}))}}}));
2
2
  //# sourceMappingURL=eleva.min.js.map