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.
@@ -1,55 +1,95 @@
1
1
  /**
2
- * 🧩 Eleva Core: Signal-based component runtime framework with lifecycle, scoped styles, and plugins.
2
+ * Defines the structure and behavior of a component.
3
+ * @typedef {Object} ComponentDefinition
4
+ * @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.
3
8
  *
4
- * The Eleva class is the core of the framework. It manages component registration,
5
- * plugin integration, lifecycle hooks, event handling, and DOM rendering.
9
+ * @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
+ *
14
+ * @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
+ *
19
+ * @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.
23
+ */
24
+ /**
25
+ * @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.
6
28
  */
7
29
  export class Eleva {
8
30
  /**
9
31
  * Creates a new Eleva instance.
10
32
  *
11
33
  * @param {string} name - The name of the Eleva instance.
12
- * @param {object} [config={}] - Optional configuration for the instance.
34
+ * @param {Object<string, any>} [config={}] - Optional configuration for the instance.
13
35
  */
14
- constructor(name: string, config?: object);
36
+ constructor(name: string, config?: {
37
+ [x: string]: any;
38
+ });
39
+ /** @type {string} The unique identifier name for this Eleva instance */
15
40
  name: string;
16
- config: object;
17
- _components: {};
18
- _plugins: any[];
19
- _lifecycleHooks: string[];
20
- _isMounted: boolean;
21
- emitter: Emitter;
22
- renderer: Renderer;
41
+ /** @type {Object<string, any>} Optional configuration object for the Eleva instance */
42
+ config: {
43
+ [x: string]: any;
44
+ };
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 */
50
+ private _plugins;
51
+ /** @private {string[]} Array of lifecycle hook names supported by the component */
52
+ private _lifecycleHooks;
53
+ /** @private {boolean} Flag indicating if component is currently mounted */
54
+ private _isMounted;
55
+ /** @private {Emitter} Instance of the event emitter for handling component events */
56
+ private emitter;
57
+ /** @private {Renderer} Instance of the renderer for handling DOM updates and patching */
58
+ private renderer;
23
59
  /**
24
60
  * Integrates a plugin with the Eleva framework.
25
61
  *
26
- * @param {object} [plugin] - The plugin object which should have an install function.
27
- * @param {object} [options={}] - Optional options to pass to the plugin.
62
+ * @param {Object} plugin - The plugin object which should have an `install` function.
63
+ * @param {Object<string, any>} [options={}] - Optional options to pass to the plugin.
28
64
  * @returns {Eleva} The Eleva instance (for chaining).
29
65
  */
30
- use(plugin?: object, options?: object): Eleva;
66
+ use(plugin: Object, options?: {
67
+ [x: string]: any;
68
+ }): Eleva;
31
69
  /**
32
70
  * Registers a component with the Eleva instance.
33
71
  *
34
72
  * @param {string} name - The name of the component.
35
- * @param {object} definition - The component definition including setup, template, style, and children.
73
+ * @param {ComponentDefinition} definition - The component definition including setup, template, style, and children.
36
74
  * @returns {Eleva} The Eleva instance (for chaining).
37
75
  */
38
- component(name: string, definition: object): Eleva;
76
+ component(name: string, definition: ComponentDefinition): Eleva;
39
77
  /**
40
78
  * Mounts a registered component to a DOM element.
41
79
  *
42
- * @param {string|HTMLElement} selectorOrElement - A CSS selector string or DOM element where the component will be mounted.
43
- * @param {string} compName - The name of the component to mount.
44
- * @param {object} [props={}] - Optional properties to pass to the component.
80
+ * @param {HTMLElement} container - A DOM element where the component will be mounted.
81
+ * @param {string|ComponentDefinition} compName - The name of the component to mount or a component definition.
82
+ * @param {Object<string, any>} [props={}] - Optional properties to pass to the component.
45
83
  * @returns {object|Promise<object>} An object representing the mounted component instance, or a Promise that resolves to it for asynchronous setups.
46
- * @throws Will throw an error if the container or component is not found.
84
+ * @throws {Error} If the container is not found or if the component is not registered.
47
85
  */
48
- mount(selectorOrElement: string | HTMLElement, compName: string, props?: object): object | Promise<object>;
86
+ mount(container: HTMLElement, compName: string | ComponentDefinition, props?: {
87
+ [x: string]: any;
88
+ }): object | Promise<object>;
49
89
  /**
50
90
  * Prepares default no-operation lifecycle hook functions.
51
91
  *
52
- * @returns {object} An object with keys for lifecycle hooks mapped to empty functions.
92
+ * @returns {Object<string, function(): void>} An object with keys for lifecycle hooks mapped to empty functions.
53
93
  * @private
54
94
  */
55
95
  private _prepareLifecycleHooks;
@@ -57,7 +97,7 @@ export class Eleva {
57
97
  * Processes DOM elements for event binding based on attributes starting with "@".
58
98
  *
59
99
  * @param {HTMLElement} container - The container element in which to search for events.
60
- * @param {object} context - The current context containing event handler definitions.
100
+ * @param {Object<string, any>} context - The current context containing event handler definitions.
61
101
  * @private
62
102
  */
63
103
  private _processEvents;
@@ -66,8 +106,8 @@ export class Eleva {
66
106
  *
67
107
  * @param {HTMLElement} container - The container element.
68
108
  * @param {string} compName - The component name used to identify the style element.
69
- * @param {Function} styleFn - A function that returns CSS styles as a string.
70
- * @param {object} context - The current context for style interpolation.
109
+ * @param {function(Object<string, any>): string} [styleFn] - A function that returns CSS styles as a string.
110
+ * @param {Object<string, any>} context - The current context for style interpolation.
71
111
  * @private
72
112
  */
73
113
  private _injectStyles;
@@ -75,12 +115,51 @@ export class Eleva {
75
115
  * Mounts child components within the parent component's container.
76
116
  *
77
117
  * @param {HTMLElement} container - The parent container element.
78
- * @param {object} children - An object mapping child component selectors to their definitions.
79
- * @param {Array} childInstances - An array to store the mounted child component instances.
118
+ * @param {Object<string, ComponentDefinition>} [children] - An object mapping child component selectors to their definitions.
119
+ * @param {Array<object>} childInstances - An array to store the mounted child component instances.
80
120
  * @private
81
121
  */
82
122
  private _mountChildren;
83
123
  }
84
- import { Emitter } from "../modules/Emitter.js";
85
- import { Renderer } from "../modules/Renderer.js";
124
+ /**
125
+ * Defines the structure and behavior of a component.
126
+ */
127
+ export type ComponentDefinition = {
128
+ /**
129
+ * Optional setup function that initializes the component's reactive state and lifecycle.
130
+ * Receives props and context as an argument and should return an object containing the component's state.
131
+ * Can return either a synchronous object or a Promise that resolves to an object for async initialization.
132
+ */
133
+ setup?: ((arg0: {
134
+ [x: string]: any;
135
+ }) => ({
136
+ [x: string]: any;
137
+ } | Promise<{
138
+ [x: string]: any;
139
+ }>)) | undefined;
140
+ /**
141
+ * Required function that defines the component's HTML structure.
142
+ * Receives the merged context (props + setup data) and must return an HTML template string.
143
+ * Supports dynamic expressions using {{ }} syntax for reactive data binding.
144
+ */
145
+ template: (arg0: {
146
+ [x: string]: any;
147
+ }) => string;
148
+ /**
149
+ * Optional function that defines component-scoped CSS styles.
150
+ * Receives the merged context and returns a CSS string that will be automatically scoped to the component.
151
+ * Styles are injected into the component's container and only affect elements within it.
152
+ */
153
+ style?: ((arg0: {
154
+ [x: string]: any;
155
+ }) => string) | undefined;
156
+ /**
157
+ * Optional object that defines nested child components.
158
+ * Keys are CSS selectors that match elements in the template where child components should be mounted.
159
+ * Values are ComponentDefinition objects that define the structure and behavior of each child component.
160
+ */
161
+ children?: {
162
+ [x: string]: ComponentDefinition;
163
+ } | undefined;
164
+ };
86
165
  //# sourceMappingURL=Eleva.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Eleva.d.ts","sourceRoot":"","sources":["../../src/core/Eleva.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH;IACE;;;;;OAKG;IACH,kBAHW,MAAM,WACN,MAAM,EAiBhB;IAdC,aAAgB;IAChB,eAAoB;IACpB,gBAAqB;IACrB,gBAAkB;IAClB,0BAMC;IACD,oBAAuB;IACvB,iBAA4B;IAC5B,mBAA8B;IAGhC;;;;;;OAMG;IACH,aAJW,MAAM,YACN,MAAM,GACJ,KAAK,CAQjB;IAED;;;;;;OAMG;IACH,gBAJW,MAAM,cACN,MAAM,GACJ,KAAK,CAKjB;IAED;;;;;;;;OAQG;IACH,yBANW,MAAM,GAAC,WAAW,YAClB,MAAM,UACN,MAAM,GACJ,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC,CA0FlC;IAED;;;;;OAKG;IACH,+BAKC;IAED;;;;;;OAMG;IACH,uBAaC;IAED;;;;;;;;OAQG;IACH,sBAYC;IAED;;;;;;;OAOG;IACH,uBAgBC;CACF;wBAjPuB,uBAAuB;yBACtB,wBAAwB"}
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;;OA0BhB;IAtBC,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,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;;;;;;OAMG;IACH,uBAaC;IAED;;;;;;;;OAQG;IACH,sBAYC;IAED;;;;;;;OAOG;IACH,uBAgBC;CACF;;;;;;;;;;;;UAhS4C,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,11 +1,11 @@
1
1
  /**
2
- * 🎙️ Emitter: Robust inter-component communication with event bubbling.
3
- *
4
- * Implements a basic publish-subscribe pattern for event handling,
5
- * allowing components to communicate through custom events.
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.
6
6
  */
7
7
  export class Emitter {
8
- /** @type {Object.<string, Function[]>} */
8
+ /** @type {Object.<string, Function[]>} Storage for event handlers mapped by event name */
9
9
  events: {
10
10
  [x: string]: Function[];
11
11
  };
@@ -13,21 +13,21 @@ export class Emitter {
13
13
  * Registers an event handler for the specified event.
14
14
  *
15
15
  * @param {string} event - The name of the event.
16
- * @param {Function} handler - The function to call when the event is emitted.
16
+ * @param {function(...any): void} handler - The function to call when the event is emitted.
17
17
  */
18
- on(event: string, handler: Function): void;
18
+ on(event: string, handler: (...args: any[]) => void): void;
19
19
  /**
20
20
  * Removes a previously registered event handler.
21
21
  *
22
22
  * @param {string} event - The name of the event.
23
- * @param {Function} handler - The handler function to remove.
23
+ * @param {function(...any): void} handler - The handler function to remove.
24
24
  */
25
- off(event: string, handler: Function): void;
25
+ off(event: string, handler: (...args: any[]) => void): void;
26
26
  /**
27
27
  * Emits an event, invoking all handlers registered for that event.
28
28
  *
29
29
  * @param {string} event - The event name.
30
- * @param {...*} args - Additional arguments to pass to the event handlers.
30
+ * @param {...any} args - Additional arguments to pass to the event handlers.
31
31
  */
32
32
  emit(event: string, ...args: any[]): void;
33
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Emitter.d.ts","sourceRoot":"","sources":["../../src/modules/Emitter.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IAKI,0CAA0C;IAC1C;;MAAgB;IAGlB;;;;;OAKG;IACH,UAHW,MAAM,2BAKhB;IAED;;;;;OAKG;IACH,WAHW,MAAM,2BAOhB;IAED;;;;;OAKG;IACH,YAHW,MAAM,WACH,GAAC,EAAA,QAId;CACF"}
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,6 +1,6 @@
1
1
  /**
2
- * 🎨 Renderer: Handles DOM patching, diffing, and attribute updates.
3
- *
2
+ * @class 🎨 Renderer
3
+ * @classdesc Handles DOM patching, diffing, and attribute updates.
4
4
  * Provides methods for efficient DOM updates by diffing the new and old DOM structures
5
5
  * and applying only the necessary changes.
6
6
  */
@@ -1,8 +1,8 @@
1
1
  /**
2
- * ⚡ Signal: Fine-grained reactivity.
3
- *
2
+ * @class ⚡ Signal
3
+ * @classdesc Fine-grained reactivity.
4
4
  * A reactive data holder that notifies registered watchers when its value changes,
5
- * allowing for fine-grained DOM patching rather than full re-renders.
5
+ * enabling fine-grained DOM patching rather than full re-renders.
6
6
  */
7
7
  export class Signal {
8
8
  /**
@@ -11,8 +11,10 @@ export class Signal {
11
11
  * @param {*} value - The initial value of the signal.
12
12
  */
13
13
  constructor(value: any);
14
- _value: any;
15
- _watchers: Set<any>;
14
+ /** @private {*} Internal storage for the signal's current value */
15
+ private _value;
16
+ /** @private {Set<function>} Collection of callback functions to be notified when value changes */
17
+ private _watchers;
16
18
  /**
17
19
  * Sets a new value for the signal and notifies all registered watchers if the value has changed.
18
20
  *
@@ -28,9 +30,9 @@ export class Signal {
28
30
  /**
29
31
  * Registers a watcher function that will be called whenever the signal's value changes.
30
32
  *
31
- * @param {Function} fn - The callback function to invoke on value change.
32
- * @returns {Function} A function to unsubscribe the watcher.
33
+ * @param {function(any): void} fn - The callback function to invoke on value change.
34
+ * @returns {function(): boolean} A function to unsubscribe the watcher.
33
35
  */
34
- watch(fn: Function): Function;
36
+ watch(fn: (arg0: any) => void): () => boolean;
35
37
  }
36
38
  //# sourceMappingURL=Signal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../src/modules/Signal.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,mBAFW,GAAC,EAKX;IAFC,YAAmB;IACnB,oBAA0B;IAY5B;;;;OAIG;IACH,kBAFW,GAAC,EAOX;IAnBD;;;;OAIG;IACH,aAFa,GAAC,CAIb;IAcD;;;;;OAKG;IACH,8BAGC;CACF"}
1
+ {"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../src/modules/Signal.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,mBAFW,GAAC,EAOX;IAJC,mEAAmE;IACnE,eAAmB;IACnB,kGAAkG;IAClG,kBAA0B;IAY5B;;;;OAIG;IACH,kBAFW,GAAC,EAOX;IAnBD;;;;OAIG;IACH,aAFa,GAAC,CAIb;IAcD;;;;;OAKG;IACH,UAHW,CAAS,IAAG,EAAH,GAAG,KAAG,IAAI,GACjB,MAAY,OAAO,CAK/B;CACF"}
@@ -1,26 +1,29 @@
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
  export 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
- static parse(template: string, data: object): string;
15
+ static parse(template: string, data: {
16
+ [x: string]: any;
17
+ }): string;
17
18
  /**
18
- * Evaluates an expression using the provided data context.
19
+ * Evaluates a JavaScript expression using the provided data context.
19
20
  *
20
21
  * @param {string} expr - The JavaScript expression to evaluate.
21
- * @param {object} data - The data context for evaluating the expression.
22
- * @returns {*} The result of the evaluated expression, or an empty string if undefined or on error.
22
+ * @param {Object<string, any>} data - The data context for evaluating the expression.
23
+ * @returns {any} The result of the evaluated expression, or an empty string if undefined or on error.
23
24
  */
24
- static evaluate(expr: string, data: object): any;
25
+ static evaluate(expr: string, data: {
26
+ [x: string]: any;
27
+ }): any;
25
28
  }
26
29
  //# sourceMappingURL=TemplateEngine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH;IACE;;;;;;OAMG;IACH,uBAJW,MAAM,QACN,MAAM,GACJ,MAAM,CAOlB;IAED;;;;;;OAMG;IACH,sBAJW,MAAM,QACN,MAAM,GACJ,GAAC,CAgBb;CACF"}
1
+ {"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH;IACE;;;;;;OAMG;IACH,uBAJW,MAAM;;QAEJ,MAAM,CAOlB;IAED;;;;;;OAMG;IACH,sBAJW,MAAM;;QAEJ,GAAG,CAgBf;CACF"}