@adaas/are-html 0.0.6 → 0.0.9

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.
Files changed (35) hide show
  1. package/dist/browser/index.d.mts +14 -1
  2. package/dist/browser/index.mjs +56 -7
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/node/directives/AreDirectiveFor.directive.js +7 -0
  5. package/dist/node/directives/AreDirectiveFor.directive.js.map +1 -1
  6. package/dist/node/directives/AreDirectiveFor.directive.mjs +7 -0
  7. package/dist/node/directives/AreDirectiveFor.directive.mjs.map +1 -1
  8. package/dist/node/engine/AreHTML.constants.d.mts +8 -1
  9. package/dist/node/engine/AreHTML.constants.d.ts +8 -1
  10. package/dist/node/engine/AreHTML.constants.js +8 -0
  11. package/dist/node/engine/AreHTML.constants.js.map +1 -1
  12. package/dist/node/engine/AreHTML.constants.mjs +7 -1
  13. package/dist/node/engine/AreHTML.constants.mjs.map +1 -1
  14. package/dist/node/engine/AreHTML.interpreter.d.mts +6 -0
  15. package/dist/node/engine/AreHTML.interpreter.d.ts +6 -0
  16. package/dist/node/engine/AreHTML.interpreter.js +40 -5
  17. package/dist/node/engine/AreHTML.interpreter.js.map +1 -1
  18. package/dist/node/engine/AreHTML.interpreter.mjs +41 -6
  19. package/dist/node/engine/AreHTML.interpreter.mjs.map +1 -1
  20. package/dist/node/engine/AreHTML.lifecycle.js +1 -0
  21. package/dist/node/engine/AreHTML.lifecycle.js.map +1 -1
  22. package/dist/node/engine/AreHTML.lifecycle.mjs +1 -0
  23. package/dist/node/engine/AreHTML.lifecycle.mjs.map +1 -1
  24. package/dist/node/engine/AreHTML.tokenizer.js +1 -1
  25. package/dist/node/engine/AreHTML.tokenizer.js.map +1 -1
  26. package/dist/node/engine/AreHTML.tokenizer.mjs +1 -1
  27. package/dist/node/engine/AreHTML.tokenizer.mjs.map +1 -1
  28. package/dist/node/index.d.mts +1 -1
  29. package/dist/node/index.d.ts +1 -1
  30. package/package.json +7 -7
  31. package/src/directives/AreDirectiveFor.directive.ts +8 -0
  32. package/src/engine/AreHTML.constants.ts +21 -0
  33. package/src/engine/AreHTML.interpreter.ts +52 -6
  34. package/src/engine/AreHTML.lifecycle.ts +6 -0
  35. package/src/engine/AreHTML.tokenizer.ts +1 -1
@@ -311,6 +311,13 @@ declare class AreRoute extends AreSignal<A_Route> {
311
311
  compare(other: A_Signal<A_Route>): boolean;
312
312
  }
313
313
 
314
+ /** XML namespace URI for SVG elements. */
315
+ declare const SVG_NAMESPACE = "http://www.w3.org/2000/svg";
316
+ /**
317
+ * Maps namespace prefixes used in SVG/XML attributes to their canonical URIs.
318
+ * Used by the interpreter when calling setAttributeNS / removeAttributeNS.
319
+ */
320
+ declare const SVG_ATTRIBUTE_NS: Record<string, string>;
314
321
  /**
315
322
  * Void HTML elements that cannot have children and must not have a closing tag.
316
323
  * Per the HTML5 spec these are treated as self-closing even when written as
@@ -537,6 +544,12 @@ declare class AreHTMLInterpreter extends AreInterpreter {
537
544
  removeText(declaration: AddTextInstruction, context: AreHTMLEngineContext): void;
538
545
  addComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext, store: AreStore, syntax: AreSyntax, directiveContext?: AreDirectiveContext, logger?: A_Logger): void;
539
546
  removeComment(declaration: AddCommentInstruction, context: AreHTMLEngineContext): void;
547
+ /**
548
+ * Returns true when any ancestor of the given node has the tag `svg`,
549
+ * meaning the node lives inside an SVG subtree and its DOM element must be
550
+ * created via createElementNS(SVG_NAMESPACE, tag).
551
+ */
552
+ private isInSVGContext;
540
553
  }
541
554
 
542
555
  declare class AreHTMLLifecycle extends AreLifecycle {
@@ -618,4 +631,4 @@ declare class AreRouteWatcher extends A_Component {
618
631
  private notify;
619
632
  }
620
633
 
621
- export { AddAttributeInstruction, AddElementInstruction, AddInterpolationInstruction, AddListenerInstruction, AddStyleInstruction, AddTextInstruction, AreBindingAttribute, AreComment, AreComponentNode, AreDirective, AreDirectiveAttribute, AreDirectiveContext, AreDirectiveFeatures, AreDirectiveFor, AreDirectiveIf, AreDirectiveMeta, type AreDirectiveOrderDecoratorParameters, AreEventAttribute, AreHTMLAttribute, AreHTMLCompiler, type AreHTMLContextConstructor, AreHTMLEngine, AreHTMLEngineContext, AreHTMLInstructions, AreHTMLInterpreter, AreHTMLLifecycle, AreHTMLNode, AreHTMLTokenizer, AreHTMLTransformer, type AreHtmlAddAttributeInstructionPayload, type AreHtmlAddCommentInstructionPayload, type AreHtmlAddElementInstructionPayload, type AreHtmlAddInterpolationInstructionPayload, type AreHtmlAddListenerInstructionPayload, type AreHtmlAddStyleInstructionPayload, type AreHtmlAddTextInstructionPayload, AreInterpolation, AreRoot, AreRootNode, AreRoute, AreRouteWatcher, AreStaticAttribute, AreStyle, AreText, BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, type ParsedEventName, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
634
+ export { AddAttributeInstruction, AddElementInstruction, AddInterpolationInstruction, AddListenerInstruction, AddStyleInstruction, AddTextInstruction, AreBindingAttribute, AreComment, AreComponentNode, AreDirective, AreDirectiveAttribute, AreDirectiveContext, AreDirectiveFeatures, AreDirectiveFor, AreDirectiveIf, AreDirectiveMeta, type AreDirectiveOrderDecoratorParameters, AreEventAttribute, AreHTMLAttribute, AreHTMLCompiler, type AreHTMLContextConstructor, AreHTMLEngine, AreHTMLEngineContext, AreHTMLInstructions, AreHTMLInterpreter, AreHTMLLifecycle, AreHTMLNode, AreHTMLTokenizer, AreHTMLTransformer, type AreHtmlAddAttributeInstructionPayload, type AreHtmlAddCommentInstructionPayload, type AreHtmlAddElementInstructionPayload, type AreHtmlAddInterpolationInstructionPayload, type AreHtmlAddListenerInstructionPayload, type AreHtmlAddStyleInstructionPayload, type AreHtmlAddTextInstructionPayload, AreInterpolation, AreRoot, AreRootNode, AreRoute, AreRouteWatcher, AreStaticAttribute, AreStyle, AreText, BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, type ParsedEventName, SVG_ATTRIBUTE_NS, SVG_NAMESPACE, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
@@ -394,6 +394,13 @@ var AreDirectiveFor = class extends AreDirective {
394
394
  return store.get(arg);
395
395
  });
396
396
  result = fn(...resolvedArgs);
397
+ } else if (arrayExpr.includes(".")) {
398
+ const parts = arrayExpr.split(".");
399
+ result = store.get(parts[0]);
400
+ for (let i = 1; i < parts.length; i++) {
401
+ if (result == null) break;
402
+ result = result[parts[i]];
403
+ }
397
404
  } else {
398
405
  result = store.get(arrayExpr);
399
406
  }
@@ -821,6 +828,12 @@ AreRoute = __decorateClass([
821
828
  ], AreRoute);
822
829
 
823
830
  // src/engine/AreHTML.constants.ts
831
+ var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
832
+ var SVG_ATTRIBUTE_NS = {
833
+ xlink: "http://www.w3.org/1999/xlink",
834
+ xml: "http://www.w3.org/XML/1998/namespace",
835
+ xmlns: "http://www.w3.org/2000/xmlns/"
836
+ };
824
837
  var VOID_ELEMENTS = /* @__PURE__ */ new Set([
825
838
  "area",
826
839
  "base",
@@ -1277,6 +1290,7 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1277
1290
  parent = parent.parent;
1278
1291
  }
1279
1292
  const tag = node.tag;
1293
+ const isSVG = tag === "svg" || this.isInSVGContext(node);
1280
1294
  if (parent) {
1281
1295
  const mountPoint = context.getNodeElement(parent);
1282
1296
  if (!mountPoint) {
@@ -1285,8 +1299,7 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1285
1299
  description: `Could not find a mount point for the node with id "${node.id}". Ensure that the parent node is rendered before its children, or that a valid root element with the corresponding id exists in the DOM.`
1286
1300
  });
1287
1301
  }
1288
- const element = context.container.createElement(tag);
1289
- element.setAttribute("data-aseid", node.aseid.toString());
1302
+ const element = isSVG ? context.container.createElementNS(SVG_NAMESPACE, tag) : context.container.createElement(tag);
1290
1303
  if (mountPoint.nodeType === Node.ELEMENT_NODE) {
1291
1304
  mountPoint.appendChild(element);
1292
1305
  } else {
@@ -1301,8 +1314,7 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1301
1314
  description: `Could not find a mount point for the node with id "${node.id}". Ensure that the parent node is rendered before its children, or that a valid root element with the corresponding id exists in the DOM.`
1302
1315
  });
1303
1316
  }
1304
- const element = context.container.createElement(tag);
1305
- element.setAttribute("data-aseid", node.aseid.toString());
1317
+ const element = isSVG ? context.container.createElementNS(SVG_NAMESPACE, tag) : context.container.createElement(tag);
1306
1318
  mountPoint.parentNode?.replaceChild(element, mountPoint);
1307
1319
  context.setInstructionElement(declaration, element);
1308
1320
  }
@@ -1333,6 +1345,15 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1333
1345
  }) : content;
1334
1346
  const el = element;
1335
1347
  const lowerName = name.toLowerCase();
1348
+ const colonIdx = name.indexOf(":");
1349
+ if (colonIdx > 0) {
1350
+ const ns = SVG_ATTRIBUTE_NS[name.slice(0, colonIdx)];
1351
+ if (ns) {
1352
+ el.setAttributeNS(ns, name, toDOMString(rawValue));
1353
+ mutation.cache = toDOMString(rawValue);
1354
+ return;
1355
+ }
1356
+ }
1336
1357
  if (isBooleanAttribute(lowerName)) {
1337
1358
  if (rawValue) {
1338
1359
  el.setAttribute(lowerName, "");
@@ -1409,7 +1430,17 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1409
1430
  if (!element) return;
1410
1431
  const { name } = mutation.payload;
1411
1432
  if (name && element.nodeType === Node.ELEMENT_NODE) {
1412
- element?.removeAttribute(name);
1433
+ const colonIdx = name.indexOf(":");
1434
+ if (colonIdx > 0) {
1435
+ const ns = SVG_ATTRIBUTE_NS[name.slice(0, colonIdx)];
1436
+ if (ns) {
1437
+ element.removeAttributeNS(ns, name.slice(colonIdx + 1));
1438
+ } else {
1439
+ element.removeAttribute(name);
1440
+ }
1441
+ } else {
1442
+ element.removeAttribute(name);
1443
+ }
1413
1444
  }
1414
1445
  } catch (error) {
1415
1446
  console.log("Error removing attribute:", error);
@@ -1583,6 +1614,23 @@ var AreHTMLInterpreter = class extends AreInterpreter {
1583
1614
  element.parentNode?.removeChild(element);
1584
1615
  context.removeInstructionElement(declaration);
1585
1616
  }
1617
+ // ─────────────────────────────────────────────────────────────────────────────
1618
+ // ── SVG helpers ───────────────────────────────────────────────────────────────
1619
+ // ─────────────────────────────────────────────────────────────────────────────
1620
+ /**
1621
+ * Returns true when any ancestor of the given node has the tag `svg`,
1622
+ * meaning the node lives inside an SVG subtree and its DOM element must be
1623
+ * created via createElementNS(SVG_NAMESPACE, tag).
1624
+ */
1625
+ isInSVGContext(node) {
1626
+ let current = node.parent;
1627
+ while (current) {
1628
+ if (current.tag === "svg") return true;
1629
+ if (current.tag === "foreignobject") return false;
1630
+ current = current.parent;
1631
+ }
1632
+ return false;
1633
+ }
1586
1634
  };
1587
1635
  __decorateClass([
1588
1636
  A_Frame.Define({
@@ -1695,7 +1743,7 @@ AreHTMLInterpreter = __decorateClass([
1695
1743
  var AreHTMLTokenizer = class extends AreTokenizer {
1696
1744
  constructor() {
1697
1745
  super(...arguments);
1698
- this.ATTR_PATTERN = /([$:@]?[\w.-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>/"'=]+)))?/g;
1746
+ this.ATTR_PATTERN = /([$:@]?[\w.-]+(?::[\w.-]+)?)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>/"'=]+)))?/g;
1699
1747
  }
1700
1748
  tokenize(node, context, logger) {
1701
1749
  super.tokenize(node, context, logger);
@@ -1769,6 +1817,7 @@ var AreHTMLLifecycle = class extends AreLifecycle {
1769
1817
  }
1770
1818
  mount(node, scene, logger, ...args) {
1771
1819
  logger?.debug(`[Mount] Component Trigger for <${node.aseid.entity}> with aseid :{${node.aseid.toString()}}`);
1820
+ if (scene.isInactive) return;
1772
1821
  node.interpret();
1773
1822
  for (let i = 0; i < node.children.length; i++) {
1774
1823
  const child = node.children[i];
@@ -2192,6 +2241,6 @@ AreRouteWatcher = __decorateClass([
2192
2241
  })
2193
2242
  ], AreRouteWatcher);
2194
2243
 
2195
- export { AddAttributeInstruction, AddElementInstruction, AddInterpolationInstruction, AddListenerInstruction, AddStyleInstruction, AddTextInstruction, AreBindingAttribute, AreComment, AreComponentNode, AreDirective, AreDirectiveAttribute, AreDirectiveContext, AreDirectiveFeatures, AreDirectiveFor, AreDirectiveIf, AreDirectiveMeta, AreEventAttribute, AreHTMLAttribute, AreHTMLCompiler, AreHTMLEngine, AreHTMLEngineContext, AreHTMLInstructions, AreHTMLInterpreter, AreHTMLLifecycle, AreHTMLNode, AreHTMLTokenizer, AreHTMLTransformer, AreInterpolation, AreRoot, AreRootNode, AreRoute, AreRouteWatcher, AreStaticAttribute, AreStyle, AreText, BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
2244
+ export { AddAttributeInstruction, AddElementInstruction, AddInterpolationInstruction, AddListenerInstruction, AddStyleInstruction, AddTextInstruction, AreBindingAttribute, AreComment, AreComponentNode, AreDirective, AreDirectiveAttribute, AreDirectiveContext, AreDirectiveFeatures, AreDirectiveFor, AreDirectiveIf, AreDirectiveMeta, AreEventAttribute, AreHTMLAttribute, AreHTMLCompiler, AreHTMLEngine, AreHTMLEngineContext, AreHTMLInstructions, AreHTMLInterpreter, AreHTMLLifecycle, AreHTMLNode, AreHTMLTokenizer, AreHTMLTransformer, AreInterpolation, AreRoot, AreRootNode, AreRoute, AreRouteWatcher, AreStaticAttribute, AreStyle, AreText, BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, SVG_ATTRIBUTE_NS, SVG_NAMESPACE, VOID_ELEMENTS, isBooleanAttribute, isIDLFormProperty, isVoidElement, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
2196
2245
  //# sourceMappingURL=index.mjs.map
2197
2246
  //# sourceMappingURL=index.mjs.map