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.
@@ -1,33 +1,50 @@
1
1
  /**
2
2
  * @class 🎨 Renderer
3
- * @classdesc Handles DOM patching, diffing, and attribute updates.
4
- * Provides methods for efficient DOM updates by diffing the new and old DOM structures
5
- * and applying only the necessary changes.
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
- * @throws {Error} If container is not an HTMLElement or newHtml is not a string
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
- * @throws {Error} If either parent is not an HTMLElement
34
+ * @returns {void}
35
+ * @throws {Error} If either parent is not an HTMLElement.
22
36
  */
23
- diff(oldParent: HTMLElement, newParent: HTMLElement): void;
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
- * @throws {Error} If either element is not an HTMLElement
45
+ * @returns {void}
46
+ * @throws {Error} If either element is not an HTMLElement.
30
47
  */
31
- updateAttributes(oldEl: HTMLElement, newEl: HTMLElement): void;
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;;;;;GAKG;AACH;IACE;;;;;;OAMG;IACH,oBAJW,WAAW,WACX,MAAM,QAehB;IAED;;;;;;OAMG;IACH,gBAJW,WAAW,aACX,WAAW,QAkErB;IAED;;;;;;OAMG;IACH,wBAJW,WAAW,SACX,WAAW,QA+DrB;CACF"}
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 Fine-grained reactivity.
4
- * A reactive data holder that notifies registered watchers when its value changes,
5
- * enabling fine-grained DOM patching rather than full re-renders.
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 {*} Internal storage for the signal's current value */
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
- * @param {*} newVal - The new value to set.
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: any);
34
+ public set value(newVal: T);
26
35
  /**
27
36
  * Gets the current value of the signal.
28
37
  *
29
- * @returns {*} The current value.
38
+ * @public
39
+ * @returns {T} The current value, where T is the type of the initial value.
30
40
  */
31
- get value(): any;
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
- * @param {function(any): void} fn - The callback function to invoke on value change.
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: any) => void): () => boolean;
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.
@@ -44,6 +60,6 @@ export class Signal {
44
60
  * @private
45
61
  * @returns {void}
46
62
  */
47
- private _notifyWatchers;
63
+ private _notify;
48
64
  }
49
65
  //# 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,EASX;IANC,mEAAmE;IACnE,eAAmB;IACnB,kGAAkG;IAClG,kBAA0B;IAC1B,sHAAsH;IACtH,iBAAqB;IAYvB;;;;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;IAED;;;;;;;OAOG;IACH,wBAQC;CACF"}
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,gBAQC;CACF"}
@@ -1,29 +1,47 @@
1
1
  /**
2
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.
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
- * Parses a template string and replaces interpolation expressions with corresponding values.
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
- * @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.
13
- * @returns {string} The resulting string with evaluated values.
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 a JavaScript expression using the provided data context.
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
- * @param {string} expr - The JavaScript expression to evaluate.
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.
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(expr: string, data: {
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;;;;;GAKG;AACH;IACE;;;;;;OAMG;IACH,uBAJW,MAAM;;QAEJ,MAAM,CAQlB;IAED;;;;;;OAMG;IACH,sBAJW,MAAM;;QAEJ,GAAG,CAgBf;CACF"}
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"}