eleva 1.2.6-alpha → 1.2.8-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/README.md +2 -2
- package/dist/eleva.cjs.js +730 -0
- package/dist/eleva.cjs.js.map +1 -0
- package/dist/eleva.d.ts +305 -78
- package/dist/eleva.esm.js +280 -142
- package/dist/eleva.esm.js.map +1 -1
- package/dist/eleva.min.js +2 -1
- package/dist/eleva.min.js.map +1 -1
- package/dist/eleva.umd.js +280 -142
- package/dist/eleva.umd.js.map +1 -1
- package/package.json +10 -13
- package/src/core/Eleva.js +149 -83
- package/src/modules/Emitter.js +48 -18
- package/src/modules/Renderer.js +23 -6
- package/src/modules/Signal.js +25 -9
- package/src/modules/TemplateEngine.js +42 -27
- package/types/core/Eleva.d.ts +143 -78
- package/types/core/Eleva.d.ts.map +1 -1
- package/types/modules/Emitter.d.ts +35 -19
- package/types/modules/Emitter.d.ts.map +1 -1
- package/types/modules/Renderer.d.ts +26 -9
- package/types/modules/Renderer.d.ts.map +1 -1
- package/types/modules/Signal.d.ts +28 -12
- package/types/modules/Signal.d.ts.map +1 -1
- package/types/modules/TemplateEngine.d.ts +35 -17
- package/types/modules/TemplateEngine.d.ts.map +1 -1
|
@@ -1,34 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @class
|
|
3
|
-
* @classdesc
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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
|
-
/** @
|
|
9
|
-
|
|
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
|
-
* @
|
|
16
|
-
* @param {
|
|
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: (
|
|
28
|
+
public on(event: string, handler: (arg0: any) => void): () => boolean;
|
|
19
29
|
/**
|
|
20
|
-
* Removes
|
|
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(
|
|
35
|
+
* @param {function(any): void} [handler] - The specific handler function to remove.
|
|
36
|
+
* @returns {void}
|
|
24
37
|
*/
|
|
25
|
-
off(event: string, handler
|
|
38
|
+
public off(event: string, handler?: (arg0: any) => void): void;
|
|
26
39
|
/**
|
|
27
|
-
* Emits an 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
|
-
* @
|
|
30
|
-
* @param {
|
|
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
|
|
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"}
|
|
@@ -1,33 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @class 🎨 Renderer
|
|
3
|
-
* @classdesc
|
|
4
|
-
* Provides methods for
|
|
5
|
-
*
|
|
3
|
+
* @classdesc A DOM renderer that handles efficient DOM updates through patching and diffing.
|
|
4
|
+
* Provides methods for updating the DOM by comparing new and old structures and applying
|
|
5
|
+
* only the necessary changes, minimizing layout thrashing and improving performance.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const renderer = new Renderer();
|
|
9
|
+
* const container = document.getElementById("app");
|
|
10
|
+
* const newHtml = "<div>Updated content</div>";
|
|
11
|
+
* renderer.patchDOM(container, newHtml);
|
|
6
12
|
*/
|
|
7
13
|
export class Renderer {
|
|
8
14
|
/**
|
|
9
15
|
* Patches the DOM of a container element with new HTML content.
|
|
16
|
+
* This method efficiently updates the DOM by comparing the new content with the existing
|
|
17
|
+
* content and applying only the necessary changes.
|
|
10
18
|
*
|
|
19
|
+
* @public
|
|
11
20
|
* @param {HTMLElement} container - The container element to patch.
|
|
12
21
|
* @param {string} newHtml - The new HTML content to apply.
|
|
13
|
-
* @
|
|
22
|
+
* @returns {void}
|
|
23
|
+
* @throws {Error} If container is not an HTMLElement or newHtml is not a string.
|
|
14
24
|
*/
|
|
15
|
-
patchDOM(container: HTMLElement, newHtml: string): void;
|
|
25
|
+
public patchDOM(container: HTMLElement, newHtml: string): void;
|
|
16
26
|
/**
|
|
17
27
|
* Diffs two DOM trees (old and new) and applies updates to the old DOM.
|
|
28
|
+
* This method recursively compares nodes and their attributes, applying only
|
|
29
|
+
* the necessary changes to minimize DOM operations.
|
|
18
30
|
*
|
|
31
|
+
* @private
|
|
19
32
|
* @param {HTMLElement} oldParent - The original DOM element.
|
|
20
33
|
* @param {HTMLElement} newParent - The new DOM element.
|
|
21
|
-
* @
|
|
34
|
+
* @returns {void}
|
|
35
|
+
* @throws {Error} If either parent is not an HTMLElement.
|
|
22
36
|
*/
|
|
23
|
-
diff
|
|
37
|
+
private diff;
|
|
24
38
|
/**
|
|
25
39
|
* Updates the attributes of an element to match those of a new element.
|
|
40
|
+
* Handles special cases for ARIA attributes, data attributes, and boolean properties.
|
|
26
41
|
*
|
|
42
|
+
* @private
|
|
27
43
|
* @param {HTMLElement} oldEl - The element to update.
|
|
28
44
|
* @param {HTMLElement} newEl - The element providing the updated attributes.
|
|
29
|
-
* @
|
|
45
|
+
* @returns {void}
|
|
46
|
+
* @throws {Error} If either element is not an HTMLElement.
|
|
30
47
|
*/
|
|
31
|
-
updateAttributes
|
|
48
|
+
private updateAttributes;
|
|
32
49
|
}
|
|
33
50
|
//# sourceMappingURL=Renderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../../src/modules/Renderer.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"Renderer.d.ts","sourceRoot":"","sources":["../../src/modules/Renderer.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH;IACE;;;;;;;;;;OAUG;IACH,2BALW,WAAW,WACX,MAAM,GACJ,IAAI,CAehB;IAED;;;;;;;;;;OAUG;IACH,aA+DC;IAED;;;;;;;;;OASG;IACH,yBA4DC;CACF"}
|
|
@@ -1,41 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @class ⚡ Signal
|
|
3
|
-
* @classdesc
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* @classdesc A reactive data holder that enables fine-grained reactivity in the Eleva framework.
|
|
4
|
+
* Signals notify registered watchers when their value changes, enabling efficient DOM updates
|
|
5
|
+
* through targeted patching rather than full re-renders.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const count = new Signal(0);
|
|
9
|
+
* count.watch((value) => console.log(`Count changed to: ${value}`));
|
|
10
|
+
* count.value = 1; // Logs: "Count changed to: 1"
|
|
6
11
|
*/
|
|
7
12
|
export class Signal {
|
|
8
13
|
/**
|
|
9
|
-
* Creates a new Signal instance.
|
|
14
|
+
* Creates a new Signal instance with the specified initial value.
|
|
10
15
|
*
|
|
16
|
+
* @public
|
|
11
17
|
* @param {*} value - The initial value of the signal.
|
|
12
18
|
*/
|
|
13
19
|
constructor(value: any);
|
|
14
|
-
/** @private {
|
|
20
|
+
/** @private {T} Internal storage for the signal's current value, where T is the type of the initial value */
|
|
15
21
|
private _value;
|
|
16
|
-
/** @private {Set<function>} Collection of callback functions to be notified when value changes */
|
|
22
|
+
/** @private {Set<function(T): void>} Collection of callback functions to be notified when value changes, where T is the value type */
|
|
17
23
|
private _watchers;
|
|
18
24
|
/** @private {boolean} Flag to prevent multiple synchronous watcher notifications and batch updates into microtasks */
|
|
19
25
|
private _pending;
|
|
20
26
|
/**
|
|
21
27
|
* Sets a new value for the signal and notifies all registered watchers if the value has changed.
|
|
28
|
+
* The notification is batched using microtasks to prevent multiple synchronous updates.
|
|
22
29
|
*
|
|
23
|
-
* @
|
|
30
|
+
* @public
|
|
31
|
+
* @param {T} newVal - The new value to set, where T is the type of the initial value.
|
|
32
|
+
* @returns {void}
|
|
24
33
|
*/
|
|
25
|
-
set value(newVal:
|
|
34
|
+
public set value(newVal: T);
|
|
26
35
|
/**
|
|
27
36
|
* Gets the current value of the signal.
|
|
28
37
|
*
|
|
29
|
-
* @
|
|
38
|
+
* @public
|
|
39
|
+
* @returns {T} The current value, where T is the type of the initial value.
|
|
30
40
|
*/
|
|
31
|
-
get value():
|
|
41
|
+
public get value(): T;
|
|
32
42
|
/**
|
|
33
43
|
* Registers a watcher function that will be called whenever the signal's value changes.
|
|
44
|
+
* The watcher will receive the new value as its argument.
|
|
34
45
|
*
|
|
35
|
-
* @
|
|
46
|
+
* @public
|
|
47
|
+
* @param {function(T): void} fn - The callback function to invoke on value change, where T is the value type.
|
|
36
48
|
* @returns {function(): boolean} A function to unsubscribe the watcher.
|
|
49
|
+
* @example
|
|
50
|
+
* const unsubscribe = signal.watch((value) => console.log(value));
|
|
51
|
+
* // Later...
|
|
52
|
+
* unsubscribe(); // Stops watching for changes
|
|
37
53
|
*/
|
|
38
|
-
watch(fn: (arg0:
|
|
54
|
+
public watch(fn: (arg0: T) => void): () => boolean;
|
|
39
55
|
/**
|
|
40
56
|
* Notifies all registered watchers of a value change using microtask scheduling.
|
|
41
57
|
* Uses a pending flag to batch multiple synchronous updates into a single notification.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../src/modules/Signal.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"Signal.d.ts","sourceRoot":"","sources":["../../src/modules/Signal.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH;IACE;;;;;OAKG;IACH,mBAFW,GAAC,EASX;IANC,6GAA6G;IAC7G,eAAmB;IACnB,sIAAsI;IACtI,kBAA0B;IAC1B,sHAAsH;IACtH,iBAAqB;IAavB;;;;;;;OAOG;IACH,yBAHW,CAAC,EAQX;IAvBD;;;;;OAKG;IACH,oBAFa,CAAC,CAIb;IAiBD;;;;;;;;;;;OAWG;IACH,iBAPW,CAAS,IAAC,EAAD,CAAC,KAAG,IAAI,GACf,MAAY,OAAO,CAS/B;IAED;;;;;;;OAOG;IACH,wBAQC;CACF"}
|
|
@@ -1,29 +1,47 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @class 🔒 TemplateEngine
|
|
3
|
-
* @classdesc
|
|
4
|
-
* Provides
|
|
5
|
-
*
|
|
3
|
+
* @classdesc A secure template engine that handles interpolation and dynamic attribute parsing.
|
|
4
|
+
* Provides a safe way to evaluate expressions in templates while preventing XSS attacks.
|
|
5
|
+
* All methods are static and can be called directly on the class.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const template = "Hello, {{name}}!";
|
|
9
|
+
* const data = { name: "World" };
|
|
10
|
+
* const result = TemplateEngine.parse(template, data); // Returns: "Hello, World!"
|
|
6
11
|
*/
|
|
7
12
|
export class TemplateEngine {
|
|
8
13
|
/**
|
|
9
|
-
*
|
|
14
|
+
* @private {RegExp} Regular expression for matching template expressions in the format {{ expression }}
|
|
15
|
+
*/
|
|
16
|
+
private static expressionPattern;
|
|
17
|
+
/**
|
|
18
|
+
* Parses a template string, replacing expressions with their evaluated values.
|
|
19
|
+
* Expressions are evaluated in the provided data context.
|
|
10
20
|
*
|
|
11
|
-
* @
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
21
|
+
* @public
|
|
22
|
+
* @static
|
|
23
|
+
* @param {string} template - The template string to parse.
|
|
24
|
+
* @param {Object} data - The data context for evaluating expressions.
|
|
25
|
+
* @returns {string} The parsed template with expressions replaced by their values.
|
|
26
|
+
* @example
|
|
27
|
+
* const result = TemplateEngine.parse("{{user.name}} is {{user.age}} years old", {
|
|
28
|
+
* user: { name: "John", age: 30 }
|
|
29
|
+
* }); // Returns: "John is 30 years old"
|
|
14
30
|
*/
|
|
15
|
-
static parse(template: string, data:
|
|
16
|
-
[x: string]: any;
|
|
17
|
-
}): string;
|
|
31
|
+
public static parse(template: string, data: Object): string;
|
|
18
32
|
/**
|
|
19
|
-
* Evaluates
|
|
33
|
+
* Evaluates an expression in the context of the provided data object.
|
|
34
|
+
* Note: This does not provide a true sandbox and evaluated expressions may access global scope.
|
|
20
35
|
*
|
|
21
|
-
* @
|
|
22
|
-
* @
|
|
23
|
-
* @
|
|
36
|
+
* @public
|
|
37
|
+
* @static
|
|
38
|
+
* @param {string} expression - The expression to evaluate.
|
|
39
|
+
* @param {Object} data - The data context for evaluation.
|
|
40
|
+
* @returns {*} The result of the evaluation, or an empty string if evaluation fails.
|
|
41
|
+
* @example
|
|
42
|
+
* const result = TemplateEngine.evaluate("user.name", { user: { name: "John" } }); // Returns: "John"
|
|
43
|
+
* const age = TemplateEngine.evaluate("user.age", { user: { age: 30 } }); // Returns: 30
|
|
24
44
|
*/
|
|
25
|
-
static evaluate(
|
|
26
|
-
[x: string]: any;
|
|
27
|
-
}): any;
|
|
45
|
+
public static evaluate(expression: string, data: Object): any;
|
|
28
46
|
}
|
|
29
47
|
//# sourceMappingURL=TemplateEngine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../../src/modules/TemplateEngine.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH;IACE;;OAEG;IACH,iCAAkD;IAElD;;;;;;;;;;;;;OAaG;IACH,8BARW,MAAM,QACN,MAAM,GACJ,MAAM,CAWlB;IAED;;;;;;;;;;;;OAYG;IACH,mCAPW,MAAM,QACN,MAAM,GACJ,GAAC,CAYb;CACF"}
|