@xaendar/core 0.7.13 → 0.7.15

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.
@@ -150,6 +150,7 @@ export declare class Context {
150
150
  */
151
151
  private _unwatchFns;
152
152
  /**
153
+ *
153
154
  */
154
155
  createElement: Function_2<[string], Element>;
155
156
  /**
@@ -250,6 +251,30 @@ export declare class Context {
250
251
  */
251
252
  export declare function createAnchor(label: string, parentNode: HTMLElement, context: Context, referenceNode?: Comment | null): Comment;
252
253
 
254
+ /**
255
+ * Creates an HTML element with the specified tag name.
256
+ *
257
+ * @param tagName - The HTML tag name of the element to create.
258
+ * @returns The newly created HTML element.
259
+ */
260
+ export declare function createElement(tagName: string): HTMLElement;
261
+
262
+ /**
263
+ * Creates a MathML element with the specified tag name using the MathML namespace.
264
+ *
265
+ * @param tagName - The MathML tag name of the element to create.
266
+ * @returns The newly created MathML element.
267
+ */
268
+ export declare function createMATHMLElement(tagName: string): MathMLElement;
269
+
270
+ /**
271
+ * Creates an SVG element with the specified tag name using the SVG namespace.
272
+ *
273
+ * @param tagName - The SVG tag name of the element to create.
274
+ * @returns The newly created SVG element.
275
+ */
276
+ export declare function createSVGElement(tagName: string): SVGElement;
277
+
253
278
  /**
254
279
  * Runs a side-effectful function and automatically re-runs it whenever any
255
280
  * Signal read during its execution changes.
@@ -454,8 +479,6 @@ declare type IterationVariablesHandle = {
454
479
  update: (newIndex: number, items: unknown[]) => void;
455
480
  };
456
481
 
457
- export declare const MATHML_NS = "http://w3.org";
458
-
459
482
  /**
460
483
  * Mounts a node into the DOM and binds it to the context lifecycle.
461
484
  *
@@ -666,8 +689,6 @@ declare type Signal_2<Value = any> = Signal.State<Value> & {
666
689
  };
667
690
  export { Signal_2 as Signal }
668
691
 
669
- export declare const SVG_NS = "http://www.w3.org/2000/svg";
670
-
671
692
  /**
672
693
  * Creates a reactive switch/case structure by converting it into an if/else-if chain
673
694
  * and delegating to {@link _if}.
@@ -1,17 +1,3 @@
1
- //#region ../packages/core/src/costants.ts
2
- /**
3
- * Metadata key used internally to store the list of observed attribute names
4
- * on a web component class.
5
- *
6
- * Populated by the `@Property` decorator and consumed by `@WebComponent` to
7
- * define `observedAttributes` on the custom element class.
8
- *
9
- * @internal
10
- */
11
- var INTERNAL_OBSERVED_ATTRIBUTES = `observedAttributes`;
12
- var SVG_NS = "http://www.w3.org/2000/svg";
13
- var MATHML_NS = "http://w3.org";
14
- //#endregion
15
1
  //#region ../packages/core/src/decorators/event.decorator.ts
16
2
  function isEventOptions(value) {
17
3
  return !!value && typeof value === "object" && ("bubbles" in value || "cancelable" in value || "composed" in value);
@@ -63,6 +49,20 @@ function Event(options) {
63
49
  };
64
50
  }
65
51
  //#endregion
52
+ //#region ../packages/core/src/costants.ts
53
+ /**
54
+ * Metadata key used internally to store the list of observed attribute names
55
+ * on a web component class.
56
+ *
57
+ * Populated by the `@Property` decorator and consumed by `@WebComponent` to
58
+ * define `observedAttributes` on the custom element class.
59
+ *
60
+ * @internal
61
+ */
62
+ var INTERNAL_OBSERVED_ATTRIBUTES = `observedAttributes`;
63
+ var SVG_NS = "http://www.w3.org/2000/svg";
64
+ var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
65
+ //#endregion
66
66
  //#region ../packages/core/src/signals/input/input-instance.symbol.ts
67
67
  /**
68
68
  * Unique symbol used to mark an object as a valid `InputSignal` instance.
@@ -496,6 +496,66 @@ function signal(value, options) {
496
496
  */
497
497
  var untracked = Signal.subtle.untrack;
498
498
  //#endregion
499
+ //#region ../packages/core/src/utils/render-element.util.ts
500
+ /**
501
+ * Creates a DOM element, applies attributes and event listeners, appends it
502
+ * to the parent, and registers cleanup functions in the current context.
503
+ *
504
+ * Static (literal) attribute values are set once via `setAttribute`. Dynamic
505
+ * attribute values are wrapped in a reactive `effect` so they update
506
+ * automatically whenever the underlying signal changes. Event listeners are
507
+ * attached with `addEventListener` and the corresponding `removeEventListener`
508
+ * is registered as a cleanup function.
509
+ *
510
+ * @param parentNode - The parent HTML element to append the new element to.
511
+ * @param context - The current template execution scope.
512
+ * @param tagName - The HTML tag name of the element to create.
513
+ * @param attributes - List of attribute descriptors to apply to the element.
514
+ * @param events - List of event listener descriptors to attach to the element.
515
+ * @returns The newly created HTML element.
516
+ */
517
+ function _renderElement(parentNode, context, anchor, tagName, attributes, events) {
518
+ const element = context.createElement(tagName);
519
+ mountNode(element, parentNode, context, anchor);
520
+ attributes.forEach(({ name, value, literal }) => {
521
+ literal ? element.setAttribute(name, String(value())) : context.listen(effect(() => element.setAttribute(name, String(value()))));
522
+ });
523
+ events.forEach((event) => {
524
+ const handler = ($event) => context.getEventHandler(event.handler)(...event.parameters.map((event) => event($event)));
525
+ const name = event.name;
526
+ element.addEventListener(name, handler);
527
+ context.listen(() => element.removeEventListener(name, handler));
528
+ });
529
+ return element;
530
+ }
531
+ /**
532
+ * Creates an HTML element with the specified tag name.
533
+ *
534
+ * @param tagName - The HTML tag name of the element to create.
535
+ * @returns The newly created HTML element.
536
+ */
537
+ function createElement(tagName) {
538
+ return document.createElement(tagName);
539
+ }
540
+ /**
541
+ * Creates an SVG element with the specified tag name using the SVG namespace.
542
+ *
543
+ * @param tagName - The SVG tag name of the element to create.
544
+ * @returns The newly created SVG element.
545
+ */
546
+ function createSVGElement(tagName) {
547
+ return document.createElementNS(SVG_NS, tagName);
548
+ }
549
+ /**
550
+ * Creates a MathML element with the specified tag name using the MathML namespace.
551
+ *
552
+ * @param tagName - The MathML tag name of the element to create.
553
+ * @returns The newly created MathML element.
554
+ */
555
+ function createMATHMLElement(tagName) {
556
+ return document.createElementNS(MATHML_NS, tagName);
557
+ }
558
+ //#endregion
499
559
  //#region ../packages/core/src/utils/context.util.ts
500
560
  /**
501
561
  * Tracks identifier scope during run time template function execution
@@ -529,6 +589,7 @@ var Context = class {
529
589
  */
530
590
  _unwatchFns = new Array();
531
591
  /**
592
+ *
532
593
  */
533
594
  createElement;
534
595
  /**
@@ -539,7 +600,7 @@ var Context = class {
539
600
  constructor(_root, _parent) {
540
601
  this._root = _root;
541
602
  this._parent = _parent;
542
- this.createElement = this._parent.createElement;
603
+ this.createElement = createElement;
543
604
  }
544
605
  /**
545
606
  * Registers a new identifier name in this scope.
@@ -922,39 +983,6 @@ function teardown(parentContext, state) {
922
983
  }
923
984
  }
924
985
  //#endregion
925
- //#region ../packages/core/src/utils/render-element.util.ts
926
- /**
927
- * Creates a DOM element, applies attributes and event listeners, appends it
928
- * to the parent, and registers cleanup functions in the current context.
929
- *
930
- * Static (literal) attribute values are set once via `setAttribute`. Dynamic
931
- * attribute values are wrapped in a reactive `effect` so they update
932
- * automatically whenever the underlying signal changes. Event listeners are
933
- * attached with `addEventListener` and the corresponding `removeEventListener`
934
- * is registered as a cleanup function.
935
- *
936
- * @param parentNode - The parent HTML element to append the new element to.
937
- * @param context - The current template execution scope.
938
- * @param tagName - The HTML tag name of the element to create.
939
- * @param attributes - List of attribute descriptors to apply to the element.
940
- * @param events - List of event listener descriptors to attach to the element.
941
- * @returns The newly created HTML element.
942
- */
943
- function _renderElement(parentNode, context, anchor, tagName, attributes, events) {
944
- const element = context.createElement(tagName);
945
- mountNode(element, parentNode, context, anchor);
946
- attributes.forEach(({ name, value, literal }) => {
947
- literal ? element.setAttribute(name, String(value())) : context.listen(effect(() => element.setAttribute(name, String(value()))));
948
- });
949
- events.forEach((event) => {
950
- const handler = ($event) => context.getEventHandler(event.handler)(...event.parameters.map((event) => event($event)));
951
- const name = event.name;
952
- element.addEventListener(name, handler);
953
- context.listen(() => element.removeEventListener(name, handler));
954
- });
955
- return element;
956
- }
957
- //#endregion
958
986
  //#region ../packages/core/src/utils/render-text.util.ts
959
987
  /**
960
988
  * Creates a reactive text node bound to a named identifier in the current scope.
@@ -1018,4 +1046,4 @@ function _switch(parentNode, parentContext, expression, blocks) {
1018
1046
  })));
1019
1047
  }
1020
1048
  //#endregion
1021
- export { BaseWebComponent, Context, Event, MATHML_NS, Property, SVG_NS, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, computed, createAnchor, effect, input, mountNode, signal, untracked };
1049
+ export { BaseWebComponent, Context, Event, Property, WebComponent, _for, _if, _iterationVariables, _renderElement, _renderLiteralText, _renderText, _switch, computed, createAnchor, createElement, createMATHMLElement, createSVGElement, effect, input, mountNode, signal, untracked };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/core",
3
- "version": "0.7.13",
3
+ "version": "0.7.15",
4
4
  "description": "A library containing core utils such as webcomponent base classes and theming support",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -16,7 +16,7 @@
16
16
  }
17
17
  },
18
18
  "dependencies": {
19
- "@xaendar/signals": "0.7.13",
20
- "@xaendar/types": "0.7.13"
19
+ "@xaendar/signals": "0.7.15",
20
+ "@xaendar/types": "0.7.15"
21
21
  }
22
22
  }