eleva 1.2.7-alpha → 1.2.9-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.
@@ -2,20 +2,26 @@
2
2
 
3
3
  /**
4
4
  * @class ⚡ Signal
5
- * @classdesc Fine-grained reactivity.
6
- * A reactive data holder that notifies registered watchers when its value changes,
7
- * enabling fine-grained DOM patching rather than full re-renders.
5
+ * @classdesc A reactive data holder that enables fine-grained reactivity in the Eleva framework.
6
+ * Signals notify registered watchers when their value changes, enabling efficient DOM updates
7
+ * through targeted patching rather than full re-renders.
8
+ *
9
+ * @example
10
+ * const count = new Signal(0);
11
+ * count.watch((value) => console.log(`Count changed to: ${value}`));
12
+ * count.value = 1; // Logs: "Count changed to: 1"
8
13
  */
9
14
  export class Signal {
10
15
  /**
11
- * Creates a new Signal instance.
16
+ * Creates a new Signal instance with the specified initial value.
12
17
  *
18
+ * @public
13
19
  * @param {*} value - The initial value of the signal.
14
20
  */
15
21
  constructor(value) {
16
- /** @private {*} Internal storage for the signal's current value */
22
+ /** @private {T} Internal storage for the signal's current value, where T is the type of the initial value */
17
23
  this._value = value;
18
- /** @private {Set<function>} Collection of callback functions to be notified when value changes */
24
+ /** @private {Set<function(T): void>} Collection of callback functions to be notified when value changes, where T is the value type */
19
25
  this._watchers = new Set();
20
26
  /** @private {boolean} Flag to prevent multiple synchronous watcher notifications and batch updates into microtasks */
21
27
  this._pending = false;
@@ -24,7 +30,8 @@ export class Signal {
24
30
  /**
25
31
  * Gets the current value of the signal.
26
32
  *
27
- * @returns {*} The current value.
33
+ * @public
34
+ * @returns {T} The current value, where T is the type of the initial value.
28
35
  */
29
36
  get value() {
30
37
  return this._value;
@@ -32,21 +39,30 @@ export class Signal {
32
39
 
33
40
  /**
34
41
  * Sets a new value for the signal and notifies all registered watchers if the value has changed.
42
+ * The notification is batched using microtasks to prevent multiple synchronous updates.
35
43
  *
36
- * @param {*} newVal - The new value to set.
44
+ * @public
45
+ * @param {T} newVal - The new value to set, where T is the type of the initial value.
46
+ * @returns {void}
37
47
  */
38
48
  set value(newVal) {
39
- if (newVal !== this._value) {
40
- this._value = newVal;
41
- this._notifyWatchers();
42
- }
49
+ if (this._value === newVal) return;
50
+
51
+ this._value = newVal;
52
+ this._notify();
43
53
  }
44
54
 
45
55
  /**
46
56
  * Registers a watcher function that will be called whenever the signal's value changes.
57
+ * The watcher will receive the new value as its argument.
47
58
  *
48
- * @param {function(any): void} fn - The callback function to invoke on value change.
59
+ * @public
60
+ * @param {function(T): void} fn - The callback function to invoke on value change, where T is the value type.
49
61
  * @returns {function(): boolean} A function to unsubscribe the watcher.
62
+ * @example
63
+ * const unsubscribe = signal.watch((value) => console.log(value));
64
+ * // Later...
65
+ * unsubscribe(); // Stops watching for changes
50
66
  */
51
67
  watch(fn) {
52
68
  this._watchers.add(fn);
@@ -61,13 +77,13 @@ export class Signal {
61
77
  * @private
62
78
  * @returns {void}
63
79
  */
64
- _notifyWatchers() {
65
- if (!this._pending) {
66
- this._pending = true;
67
- queueMicrotask(() => {
68
- this._pending = false;
69
- this._watchers.forEach((fn) => fn(this._value));
70
- });
71
- }
80
+ _notify() {
81
+ if (this._pending) return;
82
+
83
+ this._pending = true;
84
+ queueMicrotask(() => {
85
+ this._watchers.forEach((fn) => fn(this._value));
86
+ this._pending = false;
87
+ });
72
88
  }
73
89
  }
@@ -2,45 +2,60 @@
2
2
 
3
3
  /**
4
4
  * @class 🔒 TemplateEngine
5
- * @classdesc Secure interpolation & dynamic attribute parsing.
6
- * Provides methods to parse template strings by replacing interpolation expressions
7
- * with dynamic data values and to evaluate expressions within a given data context.
5
+ * @classdesc A secure template engine that handles interpolation and dynamic attribute parsing.
6
+ * Provides a safe way to evaluate expressions in templates while preventing XSS attacks.
7
+ * All methods are static and can be called directly on the class.
8
+ *
9
+ * @example
10
+ * const template = "Hello, {{name}}!";
11
+ * const data = { name: "World" };
12
+ * const result = TemplateEngine.parse(template, data); // Returns: "Hello, World!"
8
13
  */
9
14
  export class TemplateEngine {
10
15
  /**
11
- * Parses a template string and replaces interpolation expressions with corresponding values.
16
+ * @private {RegExp} Regular expression for matching template expressions in the format {{ expression }}
17
+ */
18
+ static expressionPattern = /\{\{\s*(.*?)\s*\}\}/g;
19
+
20
+ /**
21
+ * Parses a template string, replacing expressions with their evaluated values.
22
+ * Expressions are evaluated in the provided data context.
12
23
  *
13
- * @param {string} template - The template string containing expressions in the format `{{ expression }}`.
14
- * @param {Object<string, any>} data - The data object to use for evaluating expressions.
15
- * @returns {string} The resulting string with evaluated values.
24
+ * @public
25
+ * @static
26
+ * @param {string} template - The template string to parse.
27
+ * @param {Object} data - The data context for evaluating expressions.
28
+ * @returns {string} The parsed template with expressions replaced by their values.
29
+ * @example
30
+ * const result = TemplateEngine.parse("{{user.name}} is {{user.age}} years old", {
31
+ * user: { name: "John", age: 30 }
32
+ * }); // Returns: "John is 30 years old"
16
33
  */
17
34
  static parse(template, data) {
18
- if (!template || typeof template !== "string") return template;
19
-
20
- return template.replace(/\{\{\s*(.*?)\s*\}\}/g, (_, expr) => {
21
- return this.evaluate(expr, data);
22
- });
35
+ if (typeof template !== "string") return template;
36
+ return template.replace(this.expressionPattern, (_, expression) =>
37
+ this.evaluate(expression, data)
38
+ );
23
39
  }
24
40
 
25
41
  /**
26
- * Evaluates a JavaScript expression using the provided data context.
42
+ * Evaluates an expression in the context of the provided data object.
43
+ * Note: This does not provide a true sandbox and evaluated expressions may access global scope.
27
44
  *
28
- * @param {string} expr - The JavaScript expression to evaluate.
29
- * @param {Object<string, any>} data - The data context for evaluating the expression.
30
- * @returns {any} The result of the evaluated expression, or an empty string if undefined or on error.
45
+ * @public
46
+ * @static
47
+ * @param {string} expression - The expression to evaluate.
48
+ * @param {Object} data - The data context for evaluation.
49
+ * @returns {*} The result of the evaluation, or an empty string if evaluation fails.
50
+ * @example
51
+ * const result = TemplateEngine.evaluate("user.name", { user: { name: "John" } }); // Returns: "John"
52
+ * const age = TemplateEngine.evaluate("user.age", { user: { age: 30 } }); // Returns: 30
31
53
  */
32
- static evaluate(expr, data) {
33
- if (!expr || typeof expr !== "string") return expr;
34
-
54
+ static evaluate(expression, data) {
55
+ if (typeof expression !== "string") return expression;
35
56
  try {
36
- const compiledFn = new Function("data", `with(data) { return ${expr} }`);
37
- return compiledFn(data);
38
- } catch (error) {
39
- console.error(`Template evaluation error:`, {
40
- expression: expr,
41
- data,
42
- error: error.message,
43
- });
57
+ return new Function("data", `with(data) { return ${expression}; }`)(data);
58
+ } catch {
44
59
  return "";
45
60
  }
46
61
  }
@@ -1,138 +1,233 @@
1
1
  /**
2
- * Defines the structure and behavior of a component.
3
2
  * @typedef {Object} ComponentDefinition
4
3
  * @property {function(Object<string, any>): (Object<string, any>|Promise<Object<string, any>>)} [setup]
5
- * Optional setup function that initializes the component's reactive state and lifecycle.
6
- * Receives props and context as an argument and should return an object containing the component's state.
7
- * Can return either a synchronous object or a Promise that resolves to an object for async initialization.
8
- *
4
+ * Optional setup function that initializes the component's state and returns reactive data
9
5
  * @property {function(Object<string, any>): string} template
10
- * Required function that defines the component's HTML structure.
11
- * Receives the merged context (props + setup data) and must return an HTML template string.
12
- * Supports dynamic expressions using {{ }} syntax for reactive data binding.
13
- *
6
+ * Required function that defines the component's HTML structure
14
7
  * @property {function(Object<string, any>): string} [style]
15
- * Optional function that defines component-scoped CSS styles.
16
- * Receives the merged context and returns a CSS string that will be automatically scoped to the component.
17
- * Styles are injected into the component's container and only affect elements within it.
18
- *
8
+ * Optional function that provides component-scoped CSS styles
19
9
  * @property {Object<string, ComponentDefinition>} [children]
20
- * Optional object that defines nested child components.
21
- * Keys are CSS selectors that match elements in the template where child components should be mounted.
22
- * Values are ComponentDefinition objects that define the structure and behavior of each child component.
10
+ * Optional object defining nested child components
11
+ */
12
+ /**
13
+ * @typedef {Object} ElevaPlugin
14
+ * @property {function(Eleva, Object<string, any>): void} install
15
+ * Function that installs the plugin into the Eleva instance
16
+ * @property {string} name
17
+ * Unique identifier name for the plugin
18
+ */
19
+ /**
20
+ * @typedef {Object} MountResult
21
+ * @property {HTMLElement} container
22
+ * The DOM element where the component is mounted
23
+ * @property {Object<string, any>} data
24
+ * The component's reactive state and context data
25
+ * @property {function(): void} unmount
26
+ * Function to clean up and unmount the component
23
27
  */
24
28
  /**
25
29
  * @class 🧩 Eleva
26
- * @classdesc Signal-based component runtime framework with lifecycle hooks, scoped styles, and plugin support.
27
- * Manages component registration, plugin integration, event handling, and DOM rendering.
30
+ * @classdesc A modern, signal-based component runtime framework that provides lifecycle hooks,
31
+ * scoped styles, and plugin support. Eleva manages component registration, plugin integration,
32
+ * event handling, and DOM rendering with a focus on performance and developer experience.
33
+ *
34
+ * @example
35
+ * const app = new Eleva("myApp");
36
+ * app.component("myComponent", {
37
+ * template: (ctx) => `<div>Hello ${ctx.props.name}</div>`,
38
+ * setup: (ctx) => ({ count: new Signal(0) })
39
+ * });
40
+ * app.mount(document.getElementById("app"), "myComponent", { name: "World" });
28
41
  */
29
42
  export class Eleva {
30
43
  /**
31
- * Creates a new Eleva instance.
44
+ * Creates a new Eleva instance with the specified name and configuration.
32
45
  *
33
- * @param {string} name - The name of the Eleva instance.
34
- * @param {Object<string, any>} [config={}] - Optional configuration for the instance.
46
+ * @public
47
+ * @param {string} name - The unique identifier name for this Eleva instance.
48
+ * @param {Object<string, any>} [config={}] - Optional configuration object for the instance.
49
+ * May include framework-wide settings and default behaviors.
35
50
  */
36
51
  constructor(name: string, config?: {
37
52
  [x: string]: any;
38
53
  });
39
- /** @type {string} The unique identifier name for this Eleva instance */
40
- name: string;
41
- /** @type {Object<string, any>} Optional configuration object for the Eleva instance */
42
- config: {
54
+ /** @public {string} The unique identifier name for this Eleva instance */
55
+ public name: string;
56
+ /** @public {Object<string, any>} Optional configuration object for the Eleva instance */
57
+ public config: {
43
58
  [x: string]: any;
44
59
  };
45
- /** @type {Object<string, ComponentDefinition>} Object storing registered component definitions by name */
46
- _components: {
47
- [x: string]: ComponentDefinition;
48
- };
49
- /** @private {Array<Object>} Collection of installed plugin instances */
60
+ /** @public {Emitter} Instance of the event emitter for handling component events */
61
+ public emitter: Emitter;
62
+ /** @public {typeof Signal} Static reference to the Signal class for creating reactive state */
63
+ public signal: typeof Signal;
64
+ /** @public {Renderer} Instance of the renderer for handling DOM updates and patching */
65
+ public renderer: Renderer;
66
+ /** @private {Map<string, ComponentDefinition>} Registry of all component definitions by name */
67
+ private _components;
68
+ /** @private {Map<string, ElevaPlugin>} Collection of installed plugin instances by name */
50
69
  private _plugins;
51
- /** @private {string[]} Array of lifecycle hook names supported by the component */
70
+ /** @private {string[]} Array of lifecycle hook names supported by components */
52
71
  private _lifecycleHooks;
53
- /** @private {boolean} Flag indicating if component is currently mounted */
72
+ /** @private {boolean} Flag indicating if the root component is currently mounted */
54
73
  private _isMounted;
55
- /** @private {Emitter} Instance of the event emitter for handling component events */
56
- private emitter;
57
- /** @private {Signal} Instance of the signal for handling plugin and component signals */
58
- private signal;
59
- /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */
60
- private renderer;
61
74
  /**
62
75
  * Integrates a plugin with the Eleva framework.
76
+ * The plugin's install function will be called with the Eleva instance and provided options.
77
+ * After installation, the plugin will be available for use by components.
63
78
  *
64
- * @param {Object} plugin - The plugin object which should have an `install` function.
65
- * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.
66
- * @returns {Eleva} The Eleva instance (for chaining).
79
+ * @public
80
+ * @param {ElevaPlugin} plugin - The plugin object which must have an `install` function.
81
+ * @param {Object<string, any>} [options={}] - Optional configuration options for the plugin.
82
+ * @returns {Eleva} The Eleva instance (for method chaining).
83
+ * @example
84
+ * app.use(myPlugin, { option1: "value1" });
67
85
  */
68
- use(plugin: Object, options?: {
86
+ public use(plugin: ElevaPlugin, options?: {
69
87
  [x: string]: any;
70
88
  }): Eleva;
71
89
  /**
72
- * Registers a component with the Eleva instance.
90
+ * Registers a new component with the Eleva instance.
91
+ * The component will be available for mounting using its registered name.
73
92
  *
74
- * @param {string} name - The name of the component.
93
+ * @public
94
+ * @param {string} name - The unique name of the component to register.
75
95
  * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
76
- * @returns {Eleva} The Eleva instance (for chaining).
96
+ * @returns {Eleva} The Eleva instance (for method chaining).
97
+ * @throws {Error} If the component name is already registered.
98
+ * @example
99
+ * app.component("myButton", {
100
+ * template: (ctx) => `<button>${ctx.props.text}</button>`,
101
+ * style: () => "button { color: blue; }"
102
+ * });
77
103
  */
78
- component(name: string, definition: ComponentDefinition): Eleva;
104
+ public component(name: string, definition: ComponentDefinition): Eleva;
79
105
  /**
80
106
  * Mounts a registered component to a DOM element.
107
+ * This will initialize the component, set up its reactive state, and render it to the DOM.
81
108
  *
82
- * @param {HTMLElement} container - A DOM element where the component will be mounted.
83
- * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.
109
+ * @public
110
+ * @param {HTMLElement} container - The DOM element where the component will be mounted.
111
+ * @param {string|ComponentDefinition} compName - The name of the registered component or a direct component definition.
84
112
  * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.
85
- * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.
86
- * @throws {Error} If the container is not found or if the component is not registered.
113
+ * @returns {Promise<MountResult>}
114
+ * A Promise that resolves to an object containing:
115
+ * - container: The mounted component's container element
116
+ * - data: The component's reactive state and context
117
+ * - unmount: Function to clean up and unmount the component
118
+ * @throws {Error} If the container is not found, or component is not registered.
119
+ * @example
120
+ * const instance = await app.mount(document.getElementById("app"), "myComponent", { text: "Click me" });
121
+ * // Later...
122
+ * instance.unmount();
87
123
  */
88
- mount(container: HTMLElement, compName: string | ComponentDefinition, props?: {
124
+ public mount(container: HTMLElement, compName: string | ComponentDefinition, props?: {
89
125
  [x: string]: any;
90
- }): object | Promise<object>;
126
+ }): Promise<MountResult>;
91
127
  /**
92
- * Prepares default no-operation lifecycle hook functions.
128
+ * Prepares default no-operation lifecycle hook functions for a component.
129
+ * These hooks will be called at various stages of the component's lifecycle.
93
130
  *
94
- * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.
95
131
  * @private
132
+ * @returns {Object<string, function(): void>} An object mapping lifecycle hook names to empty functions.
133
+ * The returned object will be merged with the component's context.
96
134
  */
97
135
  private _prepareLifecycleHooks;
98
136
  /**
99
137
  * Processes DOM elements for event binding based on attributes starting with "@".
100
- * Tracks listeners for cleanup during unmount.
138
+ * This method handles the event delegation system and ensures proper cleanup of event listeners.
101
139
  *
102
- * @param {HTMLElement} container - The container element in which to search for events.
103
- * @param {Object<string, any>} context - The current context containing event handler definitions.
104
- * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.
105
140
  * @private
141
+ * @param {HTMLElement} container - The container element in which to search for event attributes.
142
+ * @param {Object<string, any>} context - The current component context containing event handler definitions.
143
+ * @param {Array<Function>} cleanupListeners - Array to collect cleanup functions for each event listener.
144
+ * @returns {void}
106
145
  */
107
146
  private _processEvents;
108
147
  /**
109
148
  * Injects scoped styles into the component's container.
149
+ * The styles are automatically prefixed to prevent style leakage to other components.
110
150
  *
111
- * @param {HTMLElement} container - The container element.
112
- * @param {string} compName - The component name used to identify the style element.
113
- * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.
114
- * @param {Object<string, any>} context - The current context for style interpolation.
115
151
  * @private
152
+ * @param {HTMLElement} container - The container element where styles should be injected.
153
+ * @param {string} compName - The component name used to identify the style element.
154
+ * @param {function(Object<string, any>): string} [styleFn] - Optional function that returns CSS styles as a string.
155
+ * @param {Object<string, any>} context - The current component context for style interpolation.
156
+ * @returns {void}
116
157
  */
117
158
  private _injectStyles;
118
159
  /**
119
- * Mounts child components within the parent component's container.
160
+ * Extracts props from an element's attributes that start with 'eleva-prop-'.
161
+ * This method is used to collect component properties from DOM elements.
162
+ *
163
+ * @private
164
+ * @param {HTMLElement} element - The DOM element to extract props from
165
+ * @returns {Object<string, any>} An object containing the extracted props
166
+ * @example
167
+ * // For an element with attributes:
168
+ * // <div eleva-prop-name="John" eleva-prop-age="25">
169
+ * // Returns: { name: "John", age: "25" }
170
+ */
171
+ private _extractProps;
172
+ /**
173
+ * Mounts a single component instance to a container element.
174
+ * This method handles the actual mounting of a component with its props.
175
+ *
176
+ * @private
177
+ * @param {HTMLElement} container - The container element to mount the component to
178
+ * @param {string|ComponentDefinition} component - The component to mount, either as a name or definition
179
+ * @param {Object<string, any>} props - The props to pass to the component
180
+ * @returns {Promise<MountResult>} A promise that resolves to the mounted component instance
181
+ * @throws {Error} If the container is not a valid HTMLElement
182
+ */
183
+ private _mountComponentInstance;
184
+ /**
185
+ * Mounts components found by a selector in the container.
186
+ * This method handles mounting multiple instances of the same component type.
187
+ *
188
+ * @private
189
+ * @param {HTMLElement} container - The container to search for components
190
+ * @param {string} selector - The CSS selector to find components
191
+ * @param {string|ComponentDefinition} component - The component to mount
192
+ * @param {Array<MountResult>} instances - Array to store the mounted component instances
193
+ * @returns {Promise<void>}
194
+ */
195
+ private _mountComponentsBySelector;
196
+ /**
197
+ * Mounts all components within the parent component's container.
198
+ * This method implements a dual mounting system that handles both:
199
+ * 1. Explicitly defined children components (passed through the children parameter)
200
+ * 2. Template-referenced components (found in the template using component names)
201
+ *
202
+ * The mounting process follows these steps:
203
+ * 1. Cleans up any existing component instances
204
+ * 2. Mounts explicitly defined children components
205
+ * 3. Mounts template-referenced components
120
206
  *
121
- * @param {HTMLElement} container - The parent container element.
122
- * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.
123
- * @param {Array<object>} childInstances - An array to store the mounted child component instances.
124
207
  * @private
208
+ * @param {HTMLElement} container - The container element to mount components in
209
+ * @param {Object<string, ComponentDefinition>} children - Map of selectors to component definitions for explicit children
210
+ * @param {Array<MountResult>} childInstances - Array to store all mounted component instances
211
+ * @returns {Promise<void>}
212
+ *
213
+ * @example
214
+ * // Explicit children mounting:
215
+ * const children = {
216
+ * '.user-profile': UserProfileComponent,
217
+ * '.settings-panel': SettingsComponent
218
+ * };
219
+ *
220
+ * // Template-referenced components:
221
+ * // <div>
222
+ * // <user-profile eleva-prop-name="John"></user-profile>
223
+ * // <settings-panel eleva-prop-theme="dark"></settings-panel>
224
+ * // </div>
125
225
  */
126
- private _mountChildren;
226
+ private _mountComponents;
127
227
  }
128
- /**
129
- * Defines the structure and behavior of a component.
130
- */
131
228
  export type ComponentDefinition = {
132
229
  /**
133
- * Optional setup function that initializes the component's reactive state and lifecycle.
134
- * Receives props and context as an argument and should return an object containing the component's state.
135
- * Can return either a synchronous object or a Promise that resolves to an object for async initialization.
230
+ * Optional setup function that initializes the component's state and returns reactive data
136
231
  */
137
232
  setup?: ((arg0: {
138
233
  [x: string]: any;
@@ -142,28 +237,53 @@ export type ComponentDefinition = {
142
237
  [x: string]: any;
143
238
  }>)) | undefined;
144
239
  /**
145
- * Required function that defines the component's HTML structure.
146
- * Receives the merged context (props + setup data) and must return an HTML template string.
147
- * Supports dynamic expressions using {{ }} syntax for reactive data binding.
240
+ * Required function that defines the component's HTML structure
148
241
  */
149
242
  template: (arg0: {
150
243
  [x: string]: any;
151
244
  }) => string;
152
245
  /**
153
- * Optional function that defines component-scoped CSS styles.
154
- * Receives the merged context and returns a CSS string that will be automatically scoped to the component.
155
- * Styles are injected into the component's container and only affect elements within it.
246
+ * Optional function that provides component-scoped CSS styles
156
247
  */
157
248
  style?: ((arg0: {
158
249
  [x: string]: any;
159
250
  }) => string) | undefined;
160
251
  /**
161
- * Optional object that defines nested child components.
162
- * Keys are CSS selectors that match elements in the template where child components should be mounted.
163
- * Values are ComponentDefinition objects that define the structure and behavior of each child component.
252
+ * Optional object defining nested child components
164
253
  */
165
254
  children?: {
166
255
  [x: string]: ComponentDefinition;
167
256
  } | undefined;
168
257
  };
258
+ export type ElevaPlugin = {
259
+ /**
260
+ * Function that installs the plugin into the Eleva instance
261
+ */
262
+ install: (arg0: Eleva, arg1: {
263
+ [x: string]: any;
264
+ }) => void;
265
+ /**
266
+ * Unique identifier name for the plugin
267
+ */
268
+ name: string;
269
+ };
270
+ export type MountResult = {
271
+ /**
272
+ * The DOM element where the component is mounted
273
+ */
274
+ container: HTMLElement;
275
+ /**
276
+ * The component's reactive state and context data
277
+ */
278
+ data: {
279
+ [x: string]: any;
280
+ };
281
+ /**
282
+ * Function to clean up and unmount the component
283
+ */
284
+ unmount: () => void;
285
+ };
286
+ import { Emitter } from "../modules/Emitter.js";
287
+ import { Signal } from "../modules/Signal.js";
288
+ import { Renderer } from "../modules/Renderer.js";
169
289
  //# sourceMappingURL=Eleva.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Eleva.d.ts","sourceRoot":"","sources":["../../src/core/Eleva.js"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;GAIG;AACH;IACE;;;;;OAKG;IACH,kBAHW,MAAM;;OA4BhB;IAxBC,wEAAwE;IACxE,MADW,MAAM,CACD;IAChB,uFAAuF;IACvF;;MAAoB;IACpB,0GAA0G;IAC1G;;MAAqB;IACrB,wEAAwE;IACxE,iBAAkB;IAClB,mFAAmF;IACnF,wBAMC;IACD,2EAA2E;IAC3E,mBAAuB;IACvB,qFAAqF;IACrF,gBAA4B;IAC5B,yFAAyF;IACzF,eAAoB;IACpB,yFAAyF;IACzF,iBAA8B;IAGhC;;;;;;OAMG;IACH,YAJW,MAAM;;QAEJ,KAAK,CAQjB;IAED;;;;;;OAMG;IACH,gBAJW,MAAM,cACN,mBAAmB,GACjB,KAAK,CAKjB;IAED;;;;;;;;OAQG;IACH,iBANW,WAAW,YACX,MAAM,GAAC,mBAAmB;;QAExB,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC,CAgHlC;IAED;;;;;OAKG;IACH,+BAKC;IAED;;;;;;;;OAQG;IACH,uBAiBC;IAED;;;;;;;;OAQG;IACH,sBAYC;IAED;;;;;;;OAOG;IACH,uBAgBC;CACF;;;;;;;;;;;;UAxS4C,CAAC;YAAO,MAAM,GAAE,GAAG;KAAC,GAAC,OAAO,CAAC;YAAO,MAAM,GAAE,GAAG;KAAC,CAAC,CAAC;;;;;;cAKjF,CAAS,IAAmB,EAAnB;YAAO,MAAM,GAAE,GAAG;KAAC,KAAG,MAAM;;;;;;;;UAKN,MAAM"}
1
+ {"version":3,"file":"Eleva.d.ts","sourceRoot":"","sources":["../../src/core/Eleva.js"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AAEH;;;;;;GAMG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;GAaG;AACH;IACE;;;;;;;OAOG;IACH,kBAJW,MAAM;;OA8BhB;IAzBC,0EAA0E;IAC1E,oBAAgB;IAChB,yFAAyF;IACzF;;MAAoB;IACpB,oFAAoF;IACpF,wBAA4B;IAC5B,+FAA+F;IAC/F,6BAAoB;IACpB,wFAAwF;IACxF,0BAA8B;IAE9B,gGAAgG;IAChG,oBAA4B;IAC5B,2FAA2F;IAC3F,iBAAyB;IACzB,gFAAgF;IAChF,wBAMC;IACD,oFAAoF;IACpF,mBAAuB;IAGzB;;;;;;;;;;;OAWG;IACH,mBANW,WAAW;;QAET,KAAK,CASjB;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAVW,MAAM,cACN,mBAAmB,GACjB,KAAK,CAYjB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,wBAdW,WAAW,YACX,MAAM,GAAC,mBAAmB;;QAExB,OAAO,CAAC,WAAW,CAAC,CAqIhC;IAED;;;;;;;OAOG;IACH,+BAOC;IAED;;;;;;;;;OASG;IACH,uBAiBC;IAED;;;;;;;;;;OAUG;IACH,sBAYC;IAED;;;;;;;;;;;OAWG;IACH,sBAQC;IAED;;;;;;;;;;OAUG;IACH,gCAGC;IAED;;;;;;;;;;OAUG;IACH,mCAMC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,yBA2BC;CACF;;;;;;;UAhc4C,CAAC;YAAO,MAAM,GAAE,GAAG;KAAC,GAAC,OAAO,CAAC;YAAO,MAAM,GAAE,GAAG;KAAC,CAAC,CAAC;;;;cAEjF,CAAS,IAAmB,EAAnB;YAAO,MAAM,GAAE,GAAG;KAAC,KAAG,MAAM;;;;;;UAEN,MAAM;;;;;;;;;;;;aAQrC,CAAS,IAAK,EAAL,KAAK,EAAE,IAAmB,EAAnB;YAAO,MAAM,GAAE,GAAG;KAAC,KAAG,IAAI;;;;UAE1C,MAAM;;;;;;eAMN,WAAW;;;;;;;;;;aAIX,MAAY,IAAI;;wBA7BN,uBAAuB;uBADxB,sBAAsB;yBAEpB,wBAAwB"}
@@ -1,34 +1,50 @@
1
1
  /**
2
- * @class 🎙️ Emitter
3
- * @classdesc Robust inter-component communication with event bubbling.
4
- * Implements a basic publish-subscribe pattern for event handling, allowing components
5
- * to communicate through custom events.
2
+ * @class 📡 Emitter
3
+ * @classdesc A robust event emitter that enables inter-component communication through a publish-subscribe pattern.
4
+ * Components can emit events and listen for events from other components, facilitating loose coupling
5
+ * and reactive updates across the application.
6
+ *
7
+ * @example
8
+ * const emitter = new Emitter();
9
+ * emitter.on('user:login', (user) => console.log(`User logged in: ${user.name}`));
10
+ * emitter.emit('user:login', { name: 'John' }); // Logs: "User logged in: John"
6
11
  */
7
12
  export class Emitter {
8
- /** @type {Object.<string, Function[]>} Storage for event handlers mapped by event name */
9
- events: {
10
- [x: string]: Function[];
11
- };
13
+ /** @private {Map<string, Set<function(any): void>>} Map of event names to their registered handler functions */
14
+ private _events;
12
15
  /**
13
- * Registers an event handler for the specified event.
16
+ * Registers an event handler for the specified event name.
17
+ * The handler will be called with the event data when the event is emitted.
14
18
  *
15
- * @param {string} event - The name of the event.
16
- * @param {function(...any): void} handler - The function to call when the event is emitted.
19
+ * @public
20
+ * @param {string} event - The name of the event to listen for.
21
+ * @param {function(any): void} handler - The callback function to invoke when the event occurs.
22
+ * @returns {function(): boolean} A function to unsubscribe the event handler.
23
+ * @example
24
+ * const unsubscribe = emitter.on('user:login', (user) => console.log(user));
25
+ * // Later...
26
+ * unsubscribe(); // Stops listening for the event
17
27
  */
18
- on(event: string, handler: (...args: any[]) => void): void;
28
+ public on(event: string, handler: (arg0: any) => void): () => boolean;
19
29
  /**
20
- * Removes a previously registered event handler.
30
+ * Removes an event handler for the specified event name.
31
+ * If no handler is provided, all handlers for the event are removed.
21
32
  *
33
+ * @public
22
34
  * @param {string} event - The name of the event.
23
- * @param {function(...any): void} handler - The handler function to remove.
35
+ * @param {function(any): void} [handler] - The specific handler function to remove.
36
+ * @returns {void}
24
37
  */
25
- off(event: string, handler: (...args: any[]) => void): void;
38
+ public off(event: string, handler?: (arg0: any) => void): void;
26
39
  /**
27
- * Emits an event, invoking all handlers registered for that event.
40
+ * Emits an event with the specified data to all registered handlers.
41
+ * Handlers are called synchronously in the order they were registered.
28
42
  *
29
- * @param {string} event - The event name.
30
- * @param {...any} args - Additional arguments to pass to the event handlers.
43
+ * @public
44
+ * @param {string} event - The name of the event to emit.
45
+ * @param {...any} args - Optional arguments to pass to the event handlers.
46
+ * @returns {void}
31
47
  */
32
- emit(event: string, ...args: any[]): void;
48
+ public emit(event: string, ...args: any[]): void;
33
49
  }
34
50
  //# sourceMappingURL=Emitter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Emitter.d.ts","sourceRoot":"","sources":["../../src/modules/Emitter.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IAKI,0FAA0F;IAC1F;;MAAgB;IAGlB;;;;;OAKG;IACH,UAHW,MAAM,WACN,IAAS,IAAM,EAAH,GAAG,EAAA,KAAG,IAAI,QAIhC;IAED;;;;;OAKG;IACH,WAHW,MAAM,WACN,IAAS,IAAM,EAAH,GAAG,EAAA,KAAG,IAAI,QAMhC;IAED;;;;;OAKG;IACH,YAHW,MAAM,WACH,GAAG,EAAA,QAIhB;CACF"}
1
+ {"version":3,"file":"Emitter.d.ts","sourceRoot":"","sources":["../../src/modules/Emitter.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH;IAOI,gHAAgH;IAChH,gBAAwB;IAG1B;;;;;;;;;;;;OAYG;IACH,iBARW,MAAM,WACN,CAAS,IAAG,EAAH,GAAG,KAAG,IAAI,GACjB,MAAY,OAAO,CAW/B;IAED;;;;;;;;OAQG;IACH,kBAJW,MAAM,YACN,CAAS,IAAG,EAAH,GAAG,KAAG,IAAI,GACjB,IAAI,CAYhB;IAED;;;;;;;;OAQG;IACH,mBAJW,MAAM,WACH,GAAG,EAAA,GACJ,IAAI,CAKhB;CACF"}