@adaas/are-html 0.0.2 → 0.0.4

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 (200) hide show
  1. package/README.md +4 -4
  2. package/dist/browser/index.d.mts +88 -5
  3. package/dist/browser/index.mjs +542 -176
  4. package/dist/browser/index.mjs.map +1 -1
  5. package/dist/node/attributes/AreBinding.attribute.js +17 -4
  6. package/dist/node/attributes/AreBinding.attribute.js.map +1 -1
  7. package/dist/node/attributes/AreBinding.attribute.mjs +10 -3
  8. package/dist/node/attributes/AreBinding.attribute.mjs.map +1 -1
  9. package/dist/node/attributes/AreDirective.attribute.js +17 -4
  10. package/dist/node/attributes/AreDirective.attribute.js.map +1 -1
  11. package/dist/node/attributes/AreDirective.attribute.mjs +10 -3
  12. package/dist/node/attributes/AreDirective.attribute.mjs.map +1 -1
  13. package/dist/node/attributes/AreEvent.attribute.js +17 -4
  14. package/dist/node/attributes/AreEvent.attribute.js.map +1 -1
  15. package/dist/node/attributes/AreEvent.attribute.mjs +10 -3
  16. package/dist/node/attributes/AreEvent.attribute.mjs.map +1 -1
  17. package/dist/node/attributes/AreStatic.attribute.js +17 -4
  18. package/dist/node/attributes/AreStatic.attribute.js.map +1 -1
  19. package/dist/node/attributes/AreStatic.attribute.mjs +10 -3
  20. package/dist/node/attributes/AreStatic.attribute.mjs.map +1 -1
  21. package/dist/node/directives/AreDirectiveFor.directive.d.mts +8 -0
  22. package/dist/node/directives/AreDirectiveFor.directive.d.ts +8 -0
  23. package/dist/node/directives/AreDirectiveFor.directive.js +78 -33
  24. package/dist/node/directives/AreDirectiveFor.directive.js.map +1 -1
  25. package/dist/node/directives/AreDirectiveFor.directive.mjs +78 -33
  26. package/dist/node/directives/AreDirectiveFor.directive.mjs.map +1 -1
  27. package/dist/node/directives/AreDirectiveIf.directive.d.mts +18 -0
  28. package/dist/node/directives/AreDirectiveIf.directive.d.ts +18 -0
  29. package/dist/node/directives/AreDirectiveIf.directive.js +10 -3
  30. package/dist/node/directives/AreDirectiveIf.directive.js.map +1 -1
  31. package/dist/node/directives/AreDirectiveIf.directive.mjs +10 -3
  32. package/dist/node/directives/AreDirectiveIf.directive.mjs.map +1 -1
  33. package/dist/node/engine/AreHTML.compiler.d.mts +2 -2
  34. package/dist/node/engine/AreHTML.compiler.d.ts +2 -2
  35. package/dist/node/engine/AreHTML.compiler.js +57 -29
  36. package/dist/node/engine/AreHTML.compiler.js.map +1 -1
  37. package/dist/node/engine/AreHTML.compiler.mjs +58 -30
  38. package/dist/node/engine/AreHTML.compiler.mjs.map +1 -1
  39. package/dist/node/engine/AreHTML.constants.d.mts +53 -1
  40. package/dist/node/engine/AreHTML.constants.d.ts +53 -1
  41. package/dist/node/engine/AreHTML.constants.js +100 -0
  42. package/dist/node/engine/AreHTML.constants.js.map +1 -1
  43. package/dist/node/engine/AreHTML.constants.mjs +93 -0
  44. package/dist/node/engine/AreHTML.constants.mjs.map +1 -1
  45. package/dist/node/engine/AreHTML.context.d.mts +6 -2
  46. package/dist/node/engine/AreHTML.context.d.ts +6 -2
  47. package/dist/node/engine/AreHTML.context.js +42 -7
  48. package/dist/node/engine/AreHTML.context.js.map +1 -1
  49. package/dist/node/engine/AreHTML.context.mjs +35 -6
  50. package/dist/node/engine/AreHTML.context.mjs.map +1 -1
  51. package/dist/node/engine/AreHTML.engine.js +10 -7
  52. package/dist/node/engine/AreHTML.engine.js.map +1 -1
  53. package/dist/node/engine/AreHTML.engine.mjs +10 -7
  54. package/dist/node/engine/AreHTML.engine.mjs.map +1 -1
  55. package/dist/node/engine/AreHTML.interpreter.js +155 -43
  56. package/dist/node/engine/AreHTML.interpreter.js.map +1 -1
  57. package/dist/node/engine/AreHTML.interpreter.mjs +155 -43
  58. package/dist/node/engine/AreHTML.interpreter.mjs.map +1 -1
  59. package/dist/node/engine/AreHTML.lifecycle.js +17 -12
  60. package/dist/node/engine/AreHTML.lifecycle.js.map +1 -1
  61. package/dist/node/engine/AreHTML.lifecycle.mjs +9 -2
  62. package/dist/node/engine/AreHTML.lifecycle.mjs.map +1 -1
  63. package/dist/node/engine/AreHTML.tokenizer.js +14 -9
  64. package/dist/node/engine/AreHTML.tokenizer.js.map +1 -1
  65. package/dist/node/engine/AreHTML.tokenizer.mjs +10 -3
  66. package/dist/node/engine/AreHTML.tokenizer.mjs.map +1 -1
  67. package/dist/node/engine/AreHTML.transformer.js +13 -8
  68. package/dist/node/engine/AreHTML.transformer.js.map +1 -1
  69. package/dist/node/engine/AreHTML.transformer.mjs +9 -2
  70. package/dist/node/engine/AreHTML.transformer.mjs.map +1 -1
  71. package/dist/node/index.d.mts +2 -1
  72. package/dist/node/index.d.ts +2 -1
  73. package/dist/node/index.js +3 -3
  74. package/dist/node/index.mjs +1 -1
  75. package/dist/node/instructions/AddAttribute.instruction.js +3 -4
  76. package/dist/node/instructions/AddAttribute.instruction.js.map +1 -1
  77. package/dist/node/instructions/AddAttribute.instruction.mjs +3 -4
  78. package/dist/node/instructions/AddAttribute.instruction.mjs.map +1 -1
  79. package/dist/node/instructions/AddComment.instruction.js +3 -4
  80. package/dist/node/instructions/AddComment.instruction.js.map +1 -1
  81. package/dist/node/instructions/AddComment.instruction.mjs +3 -4
  82. package/dist/node/instructions/AddComment.instruction.mjs.map +1 -1
  83. package/dist/node/instructions/AddElement.instruction.js +3 -4
  84. package/dist/node/instructions/AddElement.instruction.js.map +1 -1
  85. package/dist/node/instructions/AddElement.instruction.mjs +3 -4
  86. package/dist/node/instructions/AddElement.instruction.mjs.map +1 -1
  87. package/dist/node/instructions/AddInterpolation.instruction.js +3 -4
  88. package/dist/node/instructions/AddInterpolation.instruction.js.map +1 -1
  89. package/dist/node/instructions/AddInterpolation.instruction.mjs +3 -4
  90. package/dist/node/instructions/AddInterpolation.instruction.mjs.map +1 -1
  91. package/dist/node/instructions/AddListener.instruction.js +3 -4
  92. package/dist/node/instructions/AddListener.instruction.js.map +1 -1
  93. package/dist/node/instructions/AddListener.instruction.mjs +3 -4
  94. package/dist/node/instructions/AddListener.instruction.mjs.map +1 -1
  95. package/dist/node/instructions/AddStyle.instruction.js +3 -4
  96. package/dist/node/instructions/AddStyle.instruction.js.map +1 -1
  97. package/dist/node/instructions/AddStyle.instruction.mjs +3 -4
  98. package/dist/node/instructions/AddStyle.instruction.mjs.map +1 -1
  99. package/dist/node/instructions/AddText.instruction.js +3 -4
  100. package/dist/node/instructions/AddText.instruction.js.map +1 -1
  101. package/dist/node/instructions/AddText.instruction.mjs +3 -4
  102. package/dist/node/instructions/AddText.instruction.mjs.map +1 -1
  103. package/dist/node/lib/AreDirective/AreDirective.component.js +5 -0
  104. package/dist/node/lib/AreDirective/AreDirective.component.js.map +1 -1
  105. package/dist/node/lib/AreDirective/AreDirective.component.mjs +5 -0
  106. package/dist/node/lib/AreDirective/AreDirective.component.mjs.map +1 -1
  107. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.js +17 -4
  108. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.js.map +1 -1
  109. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.mjs +10 -3
  110. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.mjs.map +1 -1
  111. package/dist/node/lib/AreHTMLNode/AreHTMLNode.js +3 -4
  112. package/dist/node/lib/AreHTMLNode/AreHTMLNode.js.map +1 -1
  113. package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs +3 -4
  114. package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs.map +1 -1
  115. package/dist/node/lib/AreRoot/AreRoot.component.js +3 -4
  116. package/dist/node/lib/AreRoot/AreRoot.component.js.map +1 -1
  117. package/dist/node/lib/AreRoot/AreRoot.component.mjs +3 -4
  118. package/dist/node/lib/AreRoot/AreRoot.component.mjs.map +1 -1
  119. package/dist/node/lib/{AreWatcher/AreWatcher.component.d.mts → AreRouteWatcher/AreRouteWatcher.component.d.mts} +2 -2
  120. package/dist/node/lib/{AreWatcher/AreWatcher.component.d.ts → AreRouteWatcher/AreRouteWatcher.component.d.ts} +2 -2
  121. package/dist/node/lib/{AreWatcher/AreWatcher.component.js → AreRouteWatcher/AreRouteWatcher.component.js} +9 -10
  122. package/dist/node/lib/AreRouteWatcher/AreRouteWatcher.component.js.map +1 -0
  123. package/dist/node/lib/{AreWatcher/AreWatcher.component.mjs → AreRouteWatcher/AreRouteWatcher.component.mjs} +10 -11
  124. package/dist/node/lib/AreRouteWatcher/AreRouteWatcher.component.mjs.map +1 -0
  125. package/dist/node/lib/AreStyle/AreStyle.context.js +17 -4
  126. package/dist/node/lib/AreStyle/AreStyle.context.js.map +1 -1
  127. package/dist/node/lib/AreStyle/AreStyle.context.mjs +10 -3
  128. package/dist/node/lib/AreStyle/AreStyle.context.mjs.map +1 -1
  129. package/dist/node/nodes/AreComment.js +17 -4
  130. package/dist/node/nodes/AreComment.js.map +1 -1
  131. package/dist/node/nodes/AreComment.mjs +10 -3
  132. package/dist/node/nodes/AreComment.mjs.map +1 -1
  133. package/dist/node/nodes/AreComponent.js +3 -4
  134. package/dist/node/nodes/AreComponent.js.map +1 -1
  135. package/dist/node/nodes/AreComponent.mjs +3 -4
  136. package/dist/node/nodes/AreComponent.mjs.map +1 -1
  137. package/dist/node/nodes/AreInterpolation.js +17 -4
  138. package/dist/node/nodes/AreInterpolation.js.map +1 -1
  139. package/dist/node/nodes/AreInterpolation.mjs +10 -3
  140. package/dist/node/nodes/AreInterpolation.mjs.map +1 -1
  141. package/dist/node/nodes/AreRoot.js +3 -4
  142. package/dist/node/nodes/AreRoot.js.map +1 -1
  143. package/dist/node/nodes/AreRoot.mjs +3 -4
  144. package/dist/node/nodes/AreRoot.mjs.map +1 -1
  145. package/dist/node/nodes/AreText.js +17 -4
  146. package/dist/node/nodes/AreText.js.map +1 -1
  147. package/dist/node/nodes/AreText.mjs +10 -3
  148. package/dist/node/nodes/AreText.mjs.map +1 -1
  149. package/dist/node/signals/AreRoute.signal.js +18 -5
  150. package/dist/node/signals/AreRoute.signal.js.map +1 -1
  151. package/dist/node/signals/AreRoute.signal.mjs +10 -3
  152. package/dist/node/signals/AreRoute.signal.mjs.map +1 -1
  153. package/docs/SYNTAX.md +714 -0
  154. package/docs/arehtml.monaco.json +235 -0
  155. package/docs/arehtml.monaco.ts +119 -0
  156. package/examples/dashboard/dist/index.html +1 -1
  157. package/examples/dashboard/dist/mpioi5ab-8c3oa9.js +13674 -0
  158. package/examples/jumpstart/dist/index.html +1 -1
  159. package/examples/{dashboard/dist/mnzfypsd-6zjt7w.js → jumpstart/dist/mor90p6y-0plg7g.js} +1869 -1926
  160. package/examples/jumpstart/dist/{mnpl1g4i-nobz9g.js → mor90p7p-1898bz.js} +2797 -2282
  161. package/examples/jumpstart/src/components/List.component.ts +14 -13
  162. package/examples/jumpstart/src/concept.ts +5 -4
  163. package/jest.config.ts +1 -1
  164. package/package.json +10 -6
  165. package/src/attributes/AreBinding.attribute.ts +5 -0
  166. package/src/attributes/AreDirective.attribute.ts +5 -0
  167. package/src/attributes/AreEvent.attribute.ts +5 -0
  168. package/src/attributes/AreStatic.attribute.ts +5 -0
  169. package/src/directives/AreDirectiveFor.directive.ts +97 -60
  170. package/src/directives/AreDirectiveIf.directive.ts +37 -15
  171. package/src/engine/AreHTML.compiler.ts +64 -36
  172. package/src/engine/AreHTML.constants.ts +144 -0
  173. package/src/engine/AreHTML.context.ts +33 -4
  174. package/src/engine/AreHTML.engine.ts +12 -7
  175. package/src/engine/AreHTML.interpreter.ts +195 -68
  176. package/src/engine/AreHTML.lifecycle.ts +5 -0
  177. package/src/engine/AreHTML.tokenizer.ts +6 -1
  178. package/src/engine/AreHTML.transformer.ts +5 -0
  179. package/src/index.ts +2 -2
  180. package/src/instructions/AddAttribute.instruction.ts +3 -4
  181. package/src/instructions/AddComment.instruction.ts +3 -4
  182. package/src/instructions/AddElement.instruction.ts +3 -4
  183. package/src/instructions/AddInterpolation.instruction.ts +3 -4
  184. package/src/instructions/AddListener.instruction.ts +3 -4
  185. package/src/instructions/AddStyle.instruction.ts +3 -4
  186. package/src/instructions/AddText.instruction.ts +3 -4
  187. package/src/lib/AreDirective/AreDirective.component.ts +5 -0
  188. package/src/lib/AreHTMLAttribute/AreHTML.attribute.ts +5 -0
  189. package/src/lib/AreHTMLNode/AreHTMLNode.ts +3 -4
  190. package/src/lib/AreRoot/AreRoot.component.ts +3 -4
  191. package/src/lib/{AreWatcher/AreWatcher.component.ts → AreRouteWatcher/AreRouteWatcher.component.ts} +5 -6
  192. package/src/lib/AreStyle/AreStyle.context.ts +5 -0
  193. package/src/nodes/AreComment.ts +5 -0
  194. package/src/nodes/AreComponent.ts +3 -4
  195. package/src/nodes/AreInterpolation.ts +5 -0
  196. package/src/nodes/AreRoot.ts +3 -4
  197. package/src/nodes/AreText.ts +5 -0
  198. package/src/signals/AreRoute.signal.ts +5 -0
  199. package/dist/node/lib/AreWatcher/AreWatcher.component.js.map +0 -1
  200. package/dist/node/lib/AreWatcher/AreWatcher.component.mjs.map +0 -1
@@ -1,3 +1,96 @@
1
+ import '../chunk-EQQGB2QZ.mjs';
1
2
 
3
+ const BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
4
+ "allowfullscreen",
5
+ "async",
6
+ "autofocus",
7
+ "autoplay",
8
+ "checked",
9
+ "controls",
10
+ "default",
11
+ "defer",
12
+ "disabled",
13
+ "formnovalidate",
14
+ "hidden",
15
+ "inert",
16
+ "ismap",
17
+ "itemscope",
18
+ "loop",
19
+ "multiple",
20
+ "muted",
21
+ "nomodule",
22
+ "novalidate",
23
+ "open",
24
+ "playsinline",
25
+ "readonly",
26
+ "required",
27
+ "reversed",
28
+ "selected"
29
+ ]);
30
+ function isBooleanAttribute(name) {
31
+ return BOOLEAN_ATTRIBUTES.has(name.toLowerCase());
32
+ }
33
+ const IDL_FORM_PROPERTIES = {
34
+ INPUT: /* @__PURE__ */ new Set(["value", "checked", "indeterminate"]),
35
+ TEXTAREA: /* @__PURE__ */ new Set(["value"]),
36
+ SELECT: /* @__PURE__ */ new Set(["value"]),
37
+ OPTION: /* @__PURE__ */ new Set(["selected"])
38
+ };
39
+ function isIDLFormProperty(tagName, attrName) {
40
+ const set = IDL_FORM_PROPERTIES[tagName.toUpperCase()];
41
+ return !!set && set.has(attrName);
42
+ }
43
+ function normalizeClassValue(value) {
44
+ if (value === null || value === void 0 || value === false) return "";
45
+ if (typeof value === "string") return value;
46
+ if (typeof value === "number") return String(value);
47
+ if (Array.isArray(value)) {
48
+ return value.map(normalizeClassValue).filter(Boolean).join(" ");
49
+ }
50
+ if (typeof value === "object") {
51
+ const parts = [];
52
+ for (const key of Object.keys(value)) {
53
+ if (value[key]) parts.push(key);
54
+ }
55
+ return parts.join(" ");
56
+ }
57
+ return "";
58
+ }
59
+ function normalizeStyleValue(value) {
60
+ if (value === null || value === void 0 || value === false) return "";
61
+ if (typeof value === "string") return value;
62
+ if (typeof value === "number") return String(value);
63
+ if (Array.isArray(value)) {
64
+ return value.map(normalizeStyleValue).filter(Boolean).join("; ");
65
+ }
66
+ if (typeof value === "object") {
67
+ const parts = [];
68
+ for (const key of Object.keys(value)) {
69
+ const v = value[key];
70
+ if (v === null || v === void 0 || v === false) continue;
71
+ const kebab = key.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
72
+ parts.push(`${kebab}: ${v}`);
73
+ }
74
+ return parts.join("; ");
75
+ }
76
+ return "";
77
+ }
78
+ function parseEventName(raw) {
79
+ const [event, ...modifiers] = raw.split(".");
80
+ return { event, modifiers: new Set(modifiers) };
81
+ }
82
+ const LISTENER_OPTION_MODIFIERS = /* @__PURE__ */ new Set(["capture", "once", "passive"]);
83
+ function toDOMString(value) {
84
+ if (value === null || value === void 0) return "";
85
+ if (typeof value === "string") return value;
86
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
87
+ try {
88
+ return JSON.stringify(value);
89
+ } catch {
90
+ return "";
91
+ }
92
+ }
93
+
94
+ export { BOOLEAN_ATTRIBUTES, IDL_FORM_PROPERTIES, LISTENER_OPTION_MODIFIERS, isBooleanAttribute, isIDLFormProperty, normalizeClassValue, normalizeStyleValue, parseEventName, toDOMString };
2
95
  //# sourceMappingURL=AreHTML.constants.mjs.map
3
96
  //# sourceMappingURL=AreHTML.constants.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"AreHTML.constants.mjs"}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.constants.ts"],"names":[],"mappings":";;AAOO,MAAM,kBAAA,uBAAyB,GAAA,CAAY;AAAA,EAC9C,iBAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,SAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,gBAAA;AAAA,EACA,QAAA;AAAA,EACA,OAAA;AAAA,EACA,OAAA;AAAA,EACA,WAAA;AAAA,EACA,MAAA;AAAA,EACA,UAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,YAAA;AAAA,EACA,MAAA;AAAA,EACA,aAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA,UAAA;AAAA,EACA;AACJ,CAAC;AAEM,SAAS,mBAAmB,IAAA,EAAuB;AACtD,EAAA,OAAO,kBAAA,CAAmB,GAAA,CAAI,IAAA,CAAK,WAAA,EAAa,CAAA;AACpD;AASO,MAAM,mBAAA,GAAmD;AAAA,EAC5D,uBAAO,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,SAAA,EAAW,eAAe,CAAC,CAAA;AAAA,EACpD,QAAA,kBAAU,IAAI,GAAA,CAAI,CAAC,OAAO,CAAC,CAAA;AAAA,EAC3B,MAAA,kBAAQ,IAAI,GAAA,CAAI,CAAC,OAAO,CAAC,CAAA;AAAA,EACzB,MAAA,kBAAQ,IAAI,GAAA,CAAI,CAAC,UAAU,CAAC;AAChC;AAEO,SAAS,iBAAA,CAAkB,SAAiB,QAAA,EAA2B;AAC1E,EAAA,MAAM,GAAA,GAAM,mBAAA,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AI;AACA,IAAA,OAAO,IAAA,CAAK,UAAU,KAAK,CAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,EAAA;AAAA,EACX;AACJ","file":"AreHTML.constants.mjs","sourcesContent":["/**\n * Boolean HTML attributes whose presence (regardless of value) implies \"true\",\n * and whose absence implies \"false\". Setting these via `setAttribute(name, value)`\n * always renders the attribute, which is wrong for reactive bindings.\n *\n * Reference: https://html.spec.whatwg.org/multipage/indices.html#attributes-3\n */\nexport const BOOLEAN_ATTRIBUTES = new Set<string>([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n]);\n\nexport function isBooleanAttribute(name: string): boolean {\n return BOOLEAN_ATTRIBUTES.has(name.toLowerCase());\n}\n\n/**\n * Form-control IDL properties that must be set as a JS property\n * (not just an attribute) so live user input is reflected.\n *\n * `<input value=\"foo\">` only sets the *default* value;\n * `input.value = \"foo\"` updates the live state.\n */\nexport const IDL_FORM_PROPERTIES: Record<string, Set<string>> = {\n INPUT: new Set(['value', 'checked', 'indeterminate']),\n TEXTAREA: new Set(['value']),\n SELECT: new Set(['value']),\n OPTION: new Set(['selected']),\n};\n\nexport function isIDLFormProperty(tagName: string, attrName: string): boolean {\n const set = IDL_FORM_PROPERTIES[tagName.toUpperCase()];\n return !!set && set.has(attrName);\n}\n\n/**\n * Normalize a `:class` binding value into a single space-separated string.\n * Supports the common shapes:\n * - string → \"a b\"\n * - array<string | object | falsy> → [\"a\", { b: true, c: cond }, null]\n * - object<string, boolean> → { a: true, b: false }\n */\nexport function normalizeClassValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeClassValue).filter(Boolean).join(' ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n if (value[key]) parts.push(key);\n }\n return parts.join(' ');\n }\n return '';\n}\n\n/**\n * Normalize a `:style` binding value into an inline-style string.\n * Supports:\n * - string → \"color: red; font-size: 12px\"\n * - object<string, string|number> → { color: 'red', fontSize: '12px' }\n * - array<string | object> → ['color: red', { fontSize: '12px' }]\n */\nexport function normalizeStyleValue(value: any): string {\n if (value === null || value === undefined || value === false) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number') return String(value);\n\n if (Array.isArray(value)) {\n return value.map(normalizeStyleValue).filter(Boolean).join('; ');\n }\n if (typeof value === 'object') {\n const parts: string[] = [];\n for (const key of Object.keys(value)) {\n const v = value[key];\n if (v === null || v === undefined || v === false) continue;\n const kebab = key.replace(/[A-Z]/g, m => '-' + m.toLowerCase());\n parts.push(`${kebab}: ${v}`);\n }\n return parts.join('; ');\n }\n return '';\n}\n\n/**\n * Parse a DOM event name with modifiers, e.g. \"click.stop.prevent\" or \"keydown.enter\".\n * Returns the bare event name plus the modifier set.\n */\nexport interface ParsedEventName {\n event: string;\n modifiers: Set<string>;\n}\n\nexport function parseEventName(raw: string): ParsedEventName {\n const [event, ...modifiers] = raw.split('.');\n return { event, modifiers: new Set(modifiers) };\n}\n\n/**\n * Known event-listener modifiers that map directly to addEventListener options.\n */\nexport const LISTENER_OPTION_MODIFIERS = new Set(['capture', 'once', 'passive']);\n\n/**\n * Coerce a value into a string for DOM consumption.\n * Avoids \"undefined\"/\"null\"/\"[object Object]\" leaks into the DOM.\n */\nexport function toDOMString(value: any): string {\n if (value === null || value === undefined) return '';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return '';\n }\n}\n\n\n"]}
@@ -38,7 +38,7 @@ declare class AreHTMLEngineContext extends AreContext {
38
38
  /**
39
39
  * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).
40
40
  */
41
- elementListeners: WeakMap<Node, Map<string, EventListenerOrEventListenerObject>>;
41
+ elementListeners: WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>;
42
42
  };
43
43
  /**
44
44
  * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.
@@ -96,13 +96,17 @@ declare class AreHTMLEngineContext extends AreContext {
96
96
  * @returns
97
97
  */
98
98
  getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined;
99
+ /**
100
+ * Returns all listeners registered for a given element + event name.
101
+ */
102
+ getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined;
99
103
  /**
100
104
  * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.
101
105
  *
102
106
  * @param element
103
107
  * @param eventName
104
108
  */
105
- removeListener(element: Node, eventName: string): void;
109
+ removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void;
106
110
  }
107
111
 
108
112
  export { AreHTMLEngineContext };
@@ -38,7 +38,7 @@ declare class AreHTMLEngineContext extends AreContext {
38
38
  /**
39
39
  * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).
40
40
  */
41
- elementListeners: WeakMap<Node, Map<string, EventListenerOrEventListenerObject>>;
41
+ elementListeners: WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>;
42
42
  };
43
43
  /**
44
44
  * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.
@@ -96,13 +96,17 @@ declare class AreHTMLEngineContext extends AreContext {
96
96
  * @returns
97
97
  */
98
98
  getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined;
99
+ /**
100
+ * Returns all listeners registered for a given element + event name.
101
+ */
102
+ getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined;
99
103
  /**
100
104
  * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.
101
105
  *
102
106
  * @param element
103
107
  * @param eventName
104
108
  */
105
- removeListener(element: Node, eventName: string): void;
109
+ removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void;
106
110
  }
107
111
 
108
112
  export { AreHTMLEngineContext };
@@ -1,8 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  var are = require('@adaas/are');
4
+ var core = require('@adaas/a-frame/core');
4
5
 
5
- class AreHTMLEngineContext extends are.AreContext {
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __decorateClass = (decorators, target, key, kind) => {
8
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
9
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
10
+ if (decorator = decorators[i])
11
+ result = (decorator(result)) || result;
12
+ return result;
13
+ };
14
+ exports.AreHTMLEngineContext = class AreHTMLEngineContext extends are.AreContext {
6
15
  constructor(props) {
7
16
  super(props.container?.body.innerHTML || props.source || "");
8
17
  /**
@@ -127,7 +136,11 @@ class AreHTMLEngineContext extends are.AreContext {
127
136
  if (!this.index.elementListeners.has(element)) {
128
137
  this.index.elementListeners.set(element, /* @__PURE__ */ new Map());
129
138
  }
130
- this.index.elementListeners.get(element).set(eventName, listener);
139
+ const byEvent = this.index.elementListeners.get(element);
140
+ if (!byEvent.has(eventName)) {
141
+ byEvent.set(eventName, /* @__PURE__ */ new Set());
142
+ }
143
+ byEvent.get(eventName).add(listener);
131
144
  }
132
145
  /**
133
146
  * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.
@@ -137,6 +150,14 @@ class AreHTMLEngineContext extends are.AreContext {
137
150
  * @returns
138
151
  */
139
152
  getListener(element, eventName) {
153
+ const set = this.index.elementListeners.get(element)?.get(eventName);
154
+ if (!set || set.size === 0) return void 0;
155
+ return set.values().next().value;
156
+ }
157
+ /**
158
+ * Returns all listeners registered for a given element + event name.
159
+ */
160
+ getListeners(element, eventName) {
140
161
  return this.index.elementListeners.get(element)?.get(eventName);
141
162
  }
142
163
  /**
@@ -145,11 +166,25 @@ class AreHTMLEngineContext extends are.AreContext {
145
166
  * @param element
146
167
  * @param eventName
147
168
  */
148
- removeListener(element, eventName) {
149
- this.index.elementListeners.get(element)?.delete(eventName);
169
+ removeListener(element, eventName, listener) {
170
+ const byEvent = this.index.elementListeners.get(element);
171
+ if (!byEvent) return;
172
+ if (listener) {
173
+ const set = byEvent.get(eventName);
174
+ if (set) {
175
+ set.delete(listener);
176
+ if (set.size === 0) byEvent.delete(eventName);
177
+ }
178
+ } else {
179
+ byEvent.delete(eventName);
180
+ }
150
181
  }
151
- }
152
-
153
- exports.AreHTMLEngineContext = AreHTMLEngineContext;
182
+ };
183
+ exports.AreHTMLEngineContext = __decorateClass([
184
+ core.A_Frame.Define({
185
+ namespace: "a-are-html",
186
+ description: "Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives."
187
+ })
188
+ ], exports.AreHTMLEngineContext);
154
189
  //# sourceMappingURL=AreHTML.context.js.map
155
190
  //# sourceMappingURL=AreHTML.context.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":["AreContext"],"mappings":";;;;AAIO,MAAM,6BAA6BA,cAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMd,kBAAA,sBAAwB,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM1C,eAAA,sBAAqB,GAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5C,oBAAA,sBAA0B,OAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMhD,oBAAA,sBAA0B,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA,MAI5C,gBAAA,sBAAsB,OAAA;AAA+D,KACzF;AAUI,IAAA,IAAA,CAAK,aAAa,KAAA,CAAM,SAAA;AAAA,EAC5B;AAAA,EAEA,IAAI,SAAA,GAAsB;AACtB,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EAChB;AAAA,EAUA,eAAe,IAAA,EAA0C;AACrD,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC1B,MAAA,OAAO,IAAA,CAAK,KAAA,CAAM,kBAAA,CAAmB,GAAA,CAAI,IAAI,CAAA;AAAA,IACjD,CAAA,MAAO;AACH,MAAA,OAAO,KAAK,KAAA,CAAM,kBAAA,CAAmB,IAAI,IAAA,CAAK,KAAA,CAAM,UAAU,C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A;AAAA;AAAA;AAAA;AAAA,EASA,WAAA,CAAY,OAAA,EAAe,SAAA,EAAmB,QAAA,EAAoD;AAC9F,IAAA,IAAI,CAAC,IAAA,CAAK,KAAA,CAAM,gBAAA,CAAiB,GAAA,CAAI,OAAO,CAAA,EAAG;AAC3C,MAAA,IAAA,CAAK,MAAM,gBAAA,CAAiB,GAAA,CAAI,OAAA,kBAAS,IAAI,KAAK,CAAA;AAAA,IACtD;AACA,IAAA,IAAA,CAAK,MAAM,gBAAA,CAAiB,GAAA,CAAI,OAAO,CAAA,CAAG,GAAA,CAAI,WAAW,QAAQ,CAAA;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,WAAA,CAAY,SAAe,SAAA,EAAmE;AAC1F,IAAA,OAAO,KAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAA,CAAe,SAAe,SAAA,EAAyB;AACnD,IAAA,IAAA,CAAK,MAAM,gBAAA,CAAiB,GAAA,CAAI,OAAO,CAAA,EAAG,OAAO,SAAS,CAAA;AAAA,EAC9D;AACJ","file":"AreHTML.context.js","sourcesContent":["import { AreContext, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\n\n\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, EventListenerOrEventListenerObject>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n if (node) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n this.index.elementListeners.get(element)!.set(eventName, listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string): void {\n this.index.elementListeners.get(element)?.delete(eventName);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":["AreHTMLEngineContext","AreContext","A_Frame"],"mappings":";;;;;;;;;;;;;AASaA,4BAAA,GAAN,mCAAmCC,cAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMd,kBAAA,sBAAwB,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM1C,eAAA,sBAAqB,GAAA,EAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5C,oBAAA,sBAA0B,OAAA,EAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMhD,oBAAA,sBAA0B,GAAA,EAAkB;AAAA;AAAA;AAAA;AAAA,MAI5C,gBAAA,sBAAsB,OAAA;AAAoE,KAC9F;AAUI,IAAA,IAAA,CAAK,aAAa,KAAA,CAAM,SAAA;AAAA,EAC5B;AAAA,EAEA,IAAI,SAAA,GAAsB;AACtB,IAAA,OAAO,IAAA,CAAK,UAAA;AAAA,EAChB;AAAA,EAUA,eAAe,IAAA,EAA0C;AACrD,IAAA,IAAI,OAAO,SAAS,QAAA,EAAU;AAC1B,MAAA,OAAO,IAAA,CAAK,KAAA,CAAM,kBAAA,CAAmB,GAAA,CAAI,IAAI,CAAA;AAAA,IACjD,CAAA,MAAO;AACH,MAAA,OAAO,KAAK,KAAA,CAAM,kBAAA,CAAmB,IAAI,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA;AAAA,IAClE;AAAA,EACJ;AAAA;AAAA;AAA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CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA;AACvD,IAAA,IAAI,CAAC,OAAA,EAAS;AACd,IAAA,IAAI,QAAA,EAAU;AACV,MAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAA;AACjC,MAAA,IAAI,GAAA,EAAK;AACL,QAAA,GAAA,CAAI,OAAO,QAAQ,CAAA;AACnB,QAAA,IAAI,GAAA,CAAI,IAAA,KAAS,CAAA,EAAG,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,MAChD;AAAA,IACJ,CAAA,MAAO;AACH,MAAA,OAAA,CAAQ,OAAO,SAAS,CAAA;AAAA,IAC5B;AAAA,EACJ;AACJ;AAvNaD,4BAAA,GAAN,eAAA,CAAA;AAAA,EAJNE,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYF,4BAAA,CAAA","file":"AreHTML.context.js","sourcesContent":["import { AreContext, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n if (node) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
- import '../chunk-EQQGB2QZ.mjs';
1
+ import { __decorateClass } from '../chunk-EQQGB2QZ.mjs';
2
2
  import { AreContext } from '@adaas/are';
3
+ import { A_Frame } from '@adaas/a-frame/core';
3
4
 
4
- class AreHTMLEngineContext extends AreContext {
5
+ let AreHTMLEngineContext = class extends AreContext {
5
6
  constructor(props) {
6
7
  super(props.container?.body.innerHTML || props.source || "");
7
8
  /**
@@ -126,7 +127,11 @@ class AreHTMLEngineContext extends AreContext {
126
127
  if (!this.index.elementListeners.has(element)) {
127
128
  this.index.elementListeners.set(element, /* @__PURE__ */ new Map());
128
129
  }
129
- this.index.elementListeners.get(element).set(eventName, listener);
130
+ const byEvent = this.index.elementListeners.get(element);
131
+ if (!byEvent.has(eventName)) {
132
+ byEvent.set(eventName, /* @__PURE__ */ new Set());
133
+ }
134
+ byEvent.get(eventName).add(listener);
130
135
  }
131
136
  /**
132
137
  * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.
@@ -136,6 +141,14 @@ class AreHTMLEngineContext extends AreContext {
136
141
  * @returns
137
142
  */
138
143
  getListener(element, eventName) {
144
+ const set = this.index.elementListeners.get(element)?.get(eventName);
145
+ if (!set || set.size === 0) return void 0;
146
+ return set.values().next().value;
147
+ }
148
+ /**
149
+ * Returns all listeners registered for a given element + event name.
150
+ */
151
+ getListeners(element, eventName) {
139
152
  return this.index.elementListeners.get(element)?.get(eventName);
140
153
  }
141
154
  /**
@@ -144,10 +157,26 @@ class AreHTMLEngineContext extends AreContext {
144
157
  * @param element
145
158
  * @param eventName
146
159
  */
147
- removeListener(element, eventName) {
148
- this.index.elementListeners.get(element)?.delete(eventName);
160
+ removeListener(element, eventName, listener) {
161
+ const byEvent = this.index.elementListeners.get(element);
162
+ if (!byEvent) return;
163
+ if (listener) {
164
+ const set = byEvent.get(eventName);
165
+ if (set) {
166
+ set.delete(listener);
167
+ if (set.size === 0) byEvent.delete(eventName);
168
+ }
169
+ } else {
170
+ byEvent.delete(eventName);
171
+ }
149
172
  }
150
- }
173
+ };
174
+ AreHTMLEngineContext = __decorateClass([
175
+ A_Frame.Define({
176
+ namespace: "a-are-html",
177
+ description: "Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives."
178
+ })
179
+ ], AreHTMLEngineContext);
151
180
 
152
181
  export { AreHTMLEngineContext };
153
182
  //# sourceMappingURL=AreHTML.context.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":[],"mappings":";;;AAIO,MAAM,6BAA6B,UAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,EAQA,WAAA,CAAY,SAAe,SAAA,EAAmE;AAC1F,IAAA,OAAO,KAAK,KAAA,CAAM,gBAAA,CAAiB,IAAI,OAAO,CAAA,EAAG,IAAI,SAAS,CAAA;AAAA,EAClE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,cAAA,CAAe,SAAe,SAAA,EAAyB;AACnD,IAAA,IAAA,CAAK,MAAM,gBAAA,CAAiB,GAAA,CAAI,OAAO,CAAA,EAAG,OAAO,SAAS,CAAA;AAAA,EAC9D;AACJ","file":"AreHTML.context.mjs","sourcesContent":["import { AreContext, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\n\n\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, EventListenerOrEventListenerObject>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n if (node) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n this.index.elementListeners.get(element)!.set(eventName, listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string): void {\n this.index.elementListeners.get(element)?.delete(eventName);\n }\n}\n"]}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.context.ts"],"names":[],"mappings":";;;;AASO,IAAM,oBAAA,GAAN,cAAmC,UAAA,CAAW;AAAA,EAgDjD,YAAY,KAAA,EAA2C;AACnD,IAAA,KAAA,CAAM,MAAM,SAAA,EAAW,IAAA,CAAK,SAAA,IAAa,KAAA,CAAM,UAAU,EAAE,CAAA;AAtC/D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAA,IAAA,CAAU,KAAA,GAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMd,kBAA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,EAJN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACY,oBAAA,CAAA","file":"AreHTML.context.mjs","sourcesContent":["import { AreContext, AreInstruction, AreNode } from \"@adaas/are\";\nimport { AreHTMLContextConstructor } from \"./AreHTML.types\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Runtime index for the HTML rendering engine. Maps each AreNode and instruction ASEID to its corresponding DOM element so that apply and revert handlers on interpreter instructions can look up their DOM node in O(1). Tracks root-element mounts and maintains the group-level index used by structural directives.'\n})\nexport class AreHTMLEngineContext extends AreContext {\n\n /**\n * Index structure mapping:\n * \n * Node -> Group ID -> Element\n * -----------------------------------------------------------------------------------\n * | - Attribute | group: string | Node\n * | - Directive (e.g. for) | | Node\n */\n\n protected index = {\n /**\n * 1 AreNode = 1 Dom Node\n * \n * uses ASEID\n */\n nodeToHostElements: new Map<string, Node>(),\n /**\n * 1 Group Instruction = MANY Dom Nodes (e.g. for loop)\n * \n * uses ASEID\n */\n groupToElements: new Map<string, Set<Node>>(),\n /**\n * 1 Dom Node = 1 Instruction \n * \n * uses ASEID\n */\n elementToInstruction: new WeakMap<Node, string>(),\n /**\n * 1 Instruction = 1 Dom Node (for CreateElement instructions, for example)\n * \n * uses ASEID\n */\n instructionToElement: new Map<string, Node>(),\n /**\n * Event listeners attached to elements, used for proper cleanup when reverting instructions. Maps a DOM element to a map of event names and their corresponding listeners, allowing the engine to track which listeners are attached to which elements and remove them when necessary (e.g., when an instruction is reverted).\n */\n elementListeners: new WeakMap<Node, Map<string, Set<EventListenerOrEventListenerObject>>>()\n }\n\n /**\n * The root container for the HTML engine, which can be either a Document or a ShadowRoot. This is where the engine will mount the generated DOM elements. The context uses this container to manage the relationship between AreNodes, instructions, and their corresponding DOM elements, allowing for efficient updates and cleanups as the application state changes.\n */\n protected _container: Document;\n\n\n constructor(props: Partial<AreHTMLContextConstructor>) {\n super(props.container?.body.innerHTML || props.source || '');\n this._container = props.container!;\n }\n\n get container(): Document {\n return this._container;\n }\n\n\n /**\n * Retrieves the DOM element associated with a given AreNode. This method looks up the node's ASEID in the nodeToHostElements map to find the corresponding DOM element. If the node is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific nodes in the AreNode tree, enabling dynamic updates and interactions based on the application state.\n * \n * @param nodeASEID \n */\n getNodeElement(nodeASEID: string): Node | undefined\n getNodeElement(node: AreNode): Node | undefined\n getNodeElement(node: AreNode | string): Node | undefined {\n if (typeof node === 'string') {\n return this.index.nodeToHostElements.get(node);\n } else {\n return this.index.nodeToHostElements.get(node.aseid.toString());\n }\n }\n\n /**\n * Associates a DOM element with a given instruction and its owner node. This method updates the context's index to map the instruction's ASEID to the provided DOM element, and also maps the element back to the instruction's ASEID for reverse lookup. If the instruction has an owner node, it also maps the node's ASEID to the element. Additionally, if the instruction belongs to a group, it adds the element to the set of elements associated with that group. This indexing allows the engine to efficiently manage and update DOM elements based on instructions and their corresponding nodes, enabling dynamic rendering and interaction in response to application state changes.\n * \n * @param instruction \n * @param element \n */\n setInstructionElement(instruction: AreInstruction, element: Node): void {\n const node = instruction.owner;\n\n this.index.instructionToElement.set(instruction.aseid.toString(), element);\n this.index.elementToInstruction.set(element, instruction.aseid.toString());\n\n if (node) {\n this.index.nodeToHostElements.set(node.aseid.toString(), element);\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n if (!this.index.groupToElements.has(groupId)) {\n this.index.groupToElements.set(groupId, new Set());\n }\n this.index.groupToElements.get(groupId)!.add(element);\n }\n }\n\n\n /**\n * Retrieves the DOM element associated with a given instruction. This method looks up the instruction's ASEID in the instructionToElement map to find the corresponding DOM element. If the instruction is not found, it returns undefined. This allows the engine to efficiently access and manipulate the DOM elements that correspond to specific instructions, enabling dynamic updates and interactions based on the application state.\n * \n * @param instructionASEID \n */\n getElementByInstruction(instructionASEID: string): Node | undefined\n getElementByInstruction(instruction: AreInstruction): Node | undefined\n getElementByInstruction(instruction: AreInstruction | string): Node | undefined {\n if (typeof instruction === 'string') {\n return this.index.instructionToElement.get(instruction);\n } else {\n return this.index.instructionToElement.get(instruction.aseid.toString());\n }\n }\n\n\n /**\n * Removes the association between a given instruction and its corresponding DOM element. This method looks up the instruction's ASEID to find the associated DOM element, and if found, it deletes the mapping from both instructionToElement and elementToInstruction. If the instruction has an owner node, it also removes the mapping from nodeToHostElements. Additionally, if the instruction belongs to a group, it removes the element from the set of elements associated with that group, and if the group has no more elements, it deletes the group from the index. This cleanup is essential for maintaining an accurate and efficient mapping of instructions to DOM elements, especially when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param instruction \n */\n removeInstructionElement(instruction: AreInstruction): void {\n const element = this.index.instructionToElement.get(instruction.aseid.toString());\n if (element) {\n this.index.instructionToElement.delete(instruction.aseid.toString());\n this.index.elementToInstruction.delete(element);\n\n const node = instruction.owner;\n if (node) {\n this.index.nodeToHostElements.delete(node.aseid.toString());\n }\n\n if (instruction.group) {\n const groupId = instruction.group;\n const groupElements = this.index.groupToElements.get(groupId);\n if (groupElements) {\n groupElements.delete(element);\n if (groupElements.size === 0) {\n this.index.groupToElements.delete(groupId);\n }\n }\n }\n }\n }\n\n /**\n * Retrieves the set of DOM elements associated with a given group. This method looks up the group name or instruction's ASEID in the groupToElements map to find the corresponding set of DOM elements. If the group is not found, it returns undefined. This allows the engine to efficiently access and manipulate all DOM elements that belong to a specific group (e.g., all elements generated by a particular loop instruction), enabling dynamic updates and interactions based on the application state.\n * \n * @param groupName \n */\n getElementsByGroup(groupName: string): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction): Set<Node> | undefined\n getElementsByGroup(instruction: AreInstruction | string): Set<Node> | undefined {\n if (typeof instruction === 'string') {\n return this.index.groupToElements.get(instruction);\n } else {\n return this.index.groupToElements.get(instruction.aseid.toString());\n }\n }\n\n /**\n * Adds an event listener to a specific DOM element and keeps track of it in the context's index for proper cleanup later. This method takes a DOM element, an event name, and a listener function or object, and stores this information in the elementListeners map. This allows the engine to efficiently manage event listeners attached to dynamically created elements, ensuring that they can be removed when the associated instructions are reverted or when nodes are removed from the DOM, preventing memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n * @param listener \n */\n addListener(element: Node, eventName: string, listener: EventListenerOrEventListenerObject): void {\n if (!this.index.elementListeners.has(element)) {\n this.index.elementListeners.set(element, new Map());\n }\n const byEvent = this.index.elementListeners.get(element)!;\n if (!byEvent.has(eventName)) {\n byEvent.set(eventName, new Set());\n }\n byEvent.get(eventName)!.add(listener);\n }\n /**\n * Retrieves the event listener associated with a specific DOM element and event name from the context's index. This method looks up the element in the elementListeners map and then retrieves the listener for the specified event name. If no listener is found for the given element and event, it returns undefined. This allows the engine to efficiently access and manage event listeners that have been attached to dynamically created elements, enabling proper cleanup when instructions are reverted or when nodes are removed from the DOM.\n * \n * @param element \n * @param eventName \n * @returns \n */\n getListener(element: Node, eventName: string): EventListenerOrEventListenerObject | undefined {\n const set = this.index.elementListeners.get(element)?.get(eventName);\n if (!set || set.size === 0) return undefined;\n // Return the first listener for backwards compatibility.\n return set.values().next().value;\n }\n\n /**\n * Returns all listeners registered for a given element + event name.\n */\n getListeners(element: Node, eventName: string): Set<EventListenerOrEventListenerObject> | undefined {\n return this.index.elementListeners.get(element)?.get(eventName);\n }\n /**\n * Removes an event listener from a specific DOM element and updates the context's index accordingly. This method looks up the element in the elementListeners map and deletes the listener for the specified event name. This is typically called when an instruction is reverted or when a node is removed from the DOM, ensuring that any attached event listeners are properly cleaned up to prevent memory leaks and unintended behavior.\n * \n * @param element \n * @param eventName \n */\n removeListener(element: Node, eventName: string, listener?: EventListenerOrEventListenerObject): void {\n const byEvent = this.index.elementListeners.get(element);\n if (!byEvent) return;\n if (listener) {\n const set = byEvent.get(eventName);\n if (set) {\n set.delete(listener);\n if (set.size === 0) byEvent.delete(eventName);\n }\n } else {\n byEvent.delete(eventName);\n }\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var aConcept = require('@adaas/a-concept');
4
- var aFrame = require('@adaas/a-frame');
4
+ var core = require('@adaas/a-frame/core');
5
5
  var aService = require('@adaas/a-utils/a-service');
6
6
  var are = require('@adaas/are');
7
7
  var interpreter = require('@adaas/are-html/interpreter');
@@ -136,8 +136,12 @@ exports.AreHTMLEngine = class AreHTMLEngine extends are.AreEngine {
136
136
  if (nextOpen !== -1 && nextOpen < nextClose) {
137
137
  const charAfter = source[nextOpen + tagName.length + 1];
138
138
  if (charAfter === " " || charAfter === ">" || charAfter === "/") {
139
- level++;
140
- searchIndex = nextOpen + tagName.length + 1;
139
+ const innerEnd = exports.AreHTMLEngine.findTagClose(source, nextOpen);
140
+ const isSelfClose = innerEnd !== -1 && source[innerEnd - 1] === "/";
141
+ if (!isSelfClose) {
142
+ level++;
143
+ }
144
+ searchIndex = innerEnd === -1 ? nextOpen + tagName.length + 1 : innerEnd + 1;
141
145
  continue;
142
146
  }
143
147
  }
@@ -181,10 +185,9 @@ __decorateClass([
181
185
  __decorateParam(0, aConcept.A_Inject(aConcept.A_Scope))
182
186
  ], exports.AreHTMLEngine.prototype, "init", 1);
183
187
  exports.AreHTMLEngine = __decorateClass([
184
- aFrame.A_Frame.Component({
185
- namespace: "A-ARE",
186
- name: "AreHTMLEngine",
187
- description: "HTML Rendering Engine for A-Concept Rendering Engine (ARE), responsible for processing and rendering HTML templates within the ARE framework."
188
+ core.A_Frame.Define({
189
+ namespace: "a-are-html",
190
+ description: "Concrete HTML rendering engine that assembles the full ARE pipeline for web environments. Bootstraps and wires AreHTMLTokenizer, AreHTMLTransformer, AreHTMLCompiler, AreHTMLInterpreter, and AreHTMLLifecycle; mounts root nodes from inline or fetched templates; and drives reactive re-renders via the AreSignals bus."
188
191
  })
189
192
  ], exports.AreHTMLEngine);
190
193
  //# sourceMappingURL=AreHTML.engine.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/engine/AreHTML.engine.ts"],"names":["AreHTMLEngine","AreEngine","AreSyntax","AreComment","AreInterpolation","AreRootNode","AreComponentNode","AreText","AreHTMLEngineContext","AreHTMLCompiler","AreHTMLInterpreter","AreHTMLTokenizer","AreHTMLLifecycle","AreHTMLTransformer","content","match","A_Feature","A_ServiceFeatures","A_Scope","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBaA,qBAAA,GAAN,4BAA4BC,aAAA,CAAU;AAAA,EAIzC,IAAI,aAAA,GAAgB;AAChB,IAAA,OAAO,IAAIC,aAAA,CAAU;AAAA,MACjB,cAAA,EAAgB,IAAA;AAAA,MAChB,UAAA,EAAY,IAAA;AAAA,MACZ,KAAA,EAAO;AAAA;AAAA,QAEH;AAAA,UACI,OAAA,EAAS,MAAA;AAAA,UACT,OAAA,EAAS,KAAA;AAAA,UACT,SAAA,EAAWC,qBAAA;AAAA,UACX,QAAA,EAAU,EAAA;AAAA,UACV,MAAA,EAAQ,KAAA;AAAA,UACR,OAAA,EAAS,CAAC,GAAA,MAAS,EAAE,OAAA,EAAS,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,CAAE,IAAA,EAAK,EAAE;AAAA,SAC1D;AAAA;AAAA,QAEA;AAAA,UACI,OAAA,EAAS,IAAA;AAAA,UACT,OAAA,EAAS,IAAA;AAAA,UACT,SAAA,EAAWC,iCAAA;AAAA,UACX,QAAA,EAAU,CAAA;AAAA,UACV,MAAA,EAAQ,KAAA;AAAA,UACR,SAAS,CAAC,CAAA,EAAG,WAAW,EAAE,GAAA,EAAK,MAAM,OAAA,EAAQ;AAAA,SACjD;AAAA;AAAA,QAEA;AAAA,UACI,OAAA,EAAS,IAAA,CAAK,kBAAA,CAAmB,IAAA,CAAK,IAAI,CAAA;AAAA,UAC1C,SAAA,EAAWC,mBAAA;AAAA,UACX,QAAA,EAAU;AAAA,SACd;AAAA;AAAA,QAEA;AAAA,UACI,OAAA,EAAS,IAAA,CAAK,kBAA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Y,CAAC,UAAU,OAAO,CAAA;AAAA,IAC1D;AAEA,IAAA,OAAO,EAAA;AAAA,EACX;AAEJ;AAhIU,eAAA,CAAA;AAAA,EAJLC,mBAAU,MAAA,CAAO;AAAA,IACd,MAAMC,0BAAA,CAAkB,YAAA;AAAA,IACxB,MAAA,EAAQ;AAAA,GACX,CAAA;AAAA,EAEI,qCAASC,gBAAO,CAAA;AAAA,CAAA,EA3DZlB,qBAAA,CA0DH,SAAA,EAAA,MAAA,EAAA,CAAA,CAAA;AA1DGA,qBAAA,GAAN,eAAA,CAAA;AAAA,EALNmB,eAAQ,SAAA,CAAU;AAAA,IACf,SAAA,EAAW,OAAA;AAAA,IACX,IAAA,EAAM,eAAA;AAAA,IACN,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYnB,qBAAA,CAAA","file":"AreHTML.engine.js","sourcesContent":["import { A_Feature, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Frame } from \"@adaas/a-frame\";\nimport { A_ServiceFeatures } from \"@adaas/a-utils/a-service\";\nimport { AreEngine, AreSyntaxTokenMatch, AreSyntax } from \"@adaas/are\";\nimport { AreHTMLInterpreter } from \"@adaas/are-html/interpreter\";\nimport { AreHTMLEngineContext } from \"./AreHTML.context\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AreComment } from \"@adaas/are-html/nodes/AreComment\";\nimport { AreComponentNode } from \"@adaas/are-html/nodes/AreComponent\";\nimport { AreHTMLTokenizer } from \"@adaas/are-html/tokenizer\";\nimport { AreRootNode } from \"@adaas/are-html/nodes/AreRoot\";\nimport { AreHTMLLifecycle } from \"@adaas/are-html/lifecycle\";\nimport { AreHTMLTransformer } from \"@adaas/are-html/transformer\";\nimport { AreHTMLCompiler } from \"./AreHTML.compiler\";\n\n\n\n@A_Frame.Component({\n namespace: 'A-ARE',\n name: 'AreHTMLEngine',\n description: 'HTML Rendering Engine for A-Concept Rendering Engine (ARE), responsible for processing and rendering HTML templates within the ARE framework.'\n})\nexport class AreHTMLEngine extends AreEngine {\n\n\n\n get DefaultSyntax() {\n return new AreSyntax({\n trimWhitespace: true,\n strictMode: true,\n rules: [\n // HTML comments\n {\n opening: '<!--',\n closing: '-->',\n component: AreComment,\n priority: 10,\n nested: false,\n extract: (raw) => ({ content: raw.slice(4, -3).trim() }),\n },\n // interpolations\n {\n opening: '{{',\n closing: '}}',\n component: AreInterpolation,\n priority: 9,\n nested: false,\n extract: (_, match) => ({ key: match.content }),\n },\n // are-root — matched before generic elements, produces AreRootNode\n {\n matcher: this.rootElementMatcher.bind(this),\n component: AreRootNode,\n priority: 5,\n },\n // generic HTML elements\n {\n matcher: this.htmlElementMatcher.bind(this),\n component: AreComponentNode,\n priority: 4,\n },\n // plain text fallback\n {\n component: AreText,\n priority: 0,\n },\n ],\n })\n }\n\n\n /**\n * Inject AreHTMLSyntax into the container scope before loading\n * \n * @param container \n */\n @A_Feature.Extend({\n name: A_ServiceFeatures.onBeforeLoad,\n before: /.*/\n })\n async init(\n @A_Inject(A_Scope) scope: A_Scope,\n ) {\n this.package(scope, {\n context: new AreHTMLEngineContext({}),\n syntax: this.DefaultSyntax,\n compiler: AreHTMLCompiler,\n interpreter: AreHTMLInterpreter,\n tokenizer: AreHTMLTokenizer,\n lifecycle: AreHTMLLifecycle,\n transformer: AreHTMLTransformer,\n });\n }\n\n\n protected rootElementMatcher(\n source: string,\n from: number,\n to: number,\n build: (raw: string, content: string, position: number, closing: string) => AreSyntaxTokenMatch\n ): AreSyntaxTokenMatch | null {\n\n // const rootTag = this.config.rootTag\n const rootTag = 'are-root';\n\n const tagStart = source.indexOf('<', from)\n if (tagStart === -1 || tagStart >= to) return null\n\n // only match if the tag name is exactly the configured root tag\n const tagNameMatch = source.slice(tagStart).match(/^<([a-zA-Z][a-zA-Z0-9-]*)/)\n if (!tagNameMatch || tagNameMatch[1].toLowerCase() !== rootTag) return null\n\n // delegate the actual matching to the shared HTML element logic\n return this.htmlElementMatcher(source, from, to, build)\n }\n\n protected htmlElementMatcher(\n source: string,\n from: number,\n to: number,\n build: (raw: string, content: string, position: number, closing: string) => AreSyntaxTokenMatch\n ): AreSyntaxTokenMatch | null {\n let index = from\n\n while (index < to) {\n const tagStart = source.indexOf('<', index)\n if (tagStart === -1 || tagStart >= to) return null\n\n // skip comments, closing tags, doctype, processing instructions\n if (source.startsWith('<!--', tagStart)) { index = tagStart + 1; continue }\n if (source[tagStart + 1] === '/') { index = tagStart + 1; continue }\n if (source[tagStart + 1] === '!' || source[tagStart + 1] === '?') { index = tagStart + 1; continue }\n\n const tagNameMatch = source.slice(tagStart).match(/^<([a-zA-Z][a-zA-Z0-9-]*)/)\n if (!tagNameMatch) { index = tagStart + 1; continue }\n\n const tagName = tagNameMatch[1]\n const openingTagEnd = AreHTMLEngine.findTagClose(source, tagStart)\n if (openingTagEnd === -1) return null\n\n // extract id attribute if present in the opening tag\n const openingTagStr = source.slice(tagStart, openingTagEnd + 1)\n const idMatch = openingTagStr.match(/\\bid=[\"']([^\"']*)[\"']/)\n const id = idMatch ? idMatch[1] : undefined\n\n // self-closing: <br/> or <input/>\n if (source[openingTagEnd - 1] === '/') {\n const raw = source.slice(tagStart, openingTagEnd + 1)\n const content = source.slice(tagStart + tagNameMatch[0].length, openingTagEnd - 1)\n const match = build(raw, content, tagStart, '/>')\n match.payload = { entity: tagName, selfClose: true, id }\n return match\n }\n\n // find matching closing tag respecting nesting\n const closingTag = `</${tagName}>`\n let level = 0\n let searchIndex = openingTagEnd + 1\n let closingStart = -1\n\n while (searchIndex < to) {\n const nextOpen = source.indexOf(`<${tagName}`, searchIndex)\n const nextClose = source.indexOf(closingTag, searchIndex)\n if (nextClose === -1) break\n\n if (nextOpen !== -1 && nextOpen < nextClose) {\n const charAfter = source[nextOpen + tagName.length + 1]\n if (charAfter === ' ' || charAfter === '>' || charAfter === '/') {\n level++\n searchIndex = nextOpen + tagName.length + 1\n continue\n }\n }\n\n if (level === 0) { closingStart = nextClose; break }\n level--\n searchIndex = nextClose + closingTag.length\n }\n\n if (closingStart === -1) return null\n\n const fullTag = source.slice(tagStart, closingStart + closingTag.length)\n const content = source.slice(openingTagEnd + 1, closingStart)\n const match = build(fullTag, content, tagStart, closingTag)\n match.payload = { entity: tagName, selfClose: false, id }\n return match\n }\n return null\n }\n\n /**\n * Find the index of the closing `>` of an opening tag, skipping over\n * `>` characters that appear inside quoted attribute values.\n */\n private static findTagClose(source: string, from: number): number {\n let inSingle = false\n let inDouble = false\n\n for (let i = from; i < source.length; i++) {\n const ch = source[i]\n if (ch === '\"' && !inSingle) inDouble = !inDouble\n else if (ch === \"'\" && !inDouble) inSingle = !inSingle\n else if (ch === '>' && !inSingle && !inDouble) return i\n }\n\n return -1\n }\n\n}"]}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.engine.ts"],"names":["AreHTMLEngine","AreEngine","AreSyntax","AreComment","AreInterpolation","AreRootNode","AreComponentNode","AreText","AreHTMLEngineContext","AreHTMLCompiler","AreHTMLInterpreter","AreHTMLTokenizer","AreHTMLLifecycle","AreHTMLTransformer","content","match","A_Feature","A_ServiceFeatures","A_Scope","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBaA,qBAAA,GAAN,4BAA4BC,aAAA,CAAU;AAAA,EAIzC,IAAI,aAAA,GAAgB;AAChB,IAAA,OAAO,IAAIC,aAAA,CAAU;AAAA,MACjB,cAAA,EAAgB,IAAA;AAAA,MAChB,UAAA,EAAY,IAAA;AAAA,MACZ,KAAA,EAAO;AAAA;AAAA,QAEH;AAAA,UACI,OAAA,EAAS,MAAA;AAAA,UACT,OAAA,EAAS,KAAA;AAAA,UACT,SAAA,EAAWC,qBAAA;AAAA,UACX,QAAA,EAAU,EAAA;AAAA,UACV,MAAA,EAAQ,KAAA;AAAA,UACR,OAAA,EAAS,CAAC,GAAA,MAAS,EAAE,OAAA,EAAS,GAAA,CAAI,KAAA,CAAM,CAAA,EAAG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a;AAAA,GAChB;AAAA,CAAA,EACYnB,qBAAA,CAAA","file":"AreHTML.engine.js","sourcesContent":["import { A_Feature, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Frame } from \"@adaas/a-frame/core\"\nimport { A_ServiceFeatures } from \"@adaas/a-utils/a-service\";\nimport { AreEngine, AreSyntaxTokenMatch, AreSyntax } from \"@adaas/are\";\nimport { AreHTMLInterpreter } from \"@adaas/are-html/interpreter\";\nimport { AreHTMLEngineContext } from \"./AreHTML.context\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AreComment } from \"@adaas/are-html/nodes/AreComment\";\nimport { AreComponentNode } from \"@adaas/are-html/nodes/AreComponent\";\nimport { AreHTMLTokenizer } from \"@adaas/are-html/tokenizer\";\nimport { AreRootNode } from \"@adaas/are-html/nodes/AreRoot\";\nimport { AreHTMLLifecycle } from \"@adaas/are-html/lifecycle\";\nimport { AreHTMLTransformer } from \"@adaas/are-html/transformer\";\nimport { AreHTMLCompiler } from \"./AreHTML.compiler\";\n\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Concrete HTML rendering engine that assembles the full ARE pipeline for web environments. Bootstraps and wires AreHTMLTokenizer, AreHTMLTransformer, AreHTMLCompiler, AreHTMLInterpreter, and AreHTMLLifecycle; mounts root nodes from inline or fetched templates; and drives reactive re-renders via the AreSignals bus.'\n})\nexport class AreHTMLEngine extends AreEngine {\n\n\n\n get DefaultSyntax() {\n return new AreSyntax({\n trimWhitespace: true,\n strictMode: true,\n rules: [\n // HTML comments\n {\n opening: '<!--',\n closing: '-->',\n component: AreComment,\n priority: 10,\n nested: false,\n extract: (raw) => ({ content: raw.slice(4, -3).trim() }),\n },\n // interpolations\n {\n opening: '{{',\n closing: '}}',\n component: AreInterpolation,\n priority: 9,\n nested: false,\n extract: (_, match) => ({ key: match.content }),\n },\n // are-root — matched before generic elements, produces AreRootNode\n {\n matcher: this.rootElementMatcher.bind(this),\n component: AreRootNode,\n priority: 5,\n },\n // generic HTML elements\n {\n matcher: this.htmlElementMatcher.bind(this),\n component: AreComponentNode,\n priority: 4,\n },\n // plain text fallback\n {\n component: AreText,\n priority: 0,\n },\n ],\n })\n }\n\n\n /**\n * Inject AreHTMLSyntax into the container scope before loading\n * \n * @param container \n */\n @A_Feature.Extend({\n name: A_ServiceFeatures.onBeforeLoad,\n before: /.*/\n })\n async init(\n @A_Inject(A_Scope) scope: A_Scope,\n ) {\n this.package(scope, {\n context: new AreHTMLEngineContext({}),\n syntax: this.DefaultSyntax,\n compiler: AreHTMLCompiler,\n interpreter: AreHTMLInterpreter,\n tokenizer: AreHTMLTokenizer,\n lifecycle: AreHTMLLifecycle,\n transformer: AreHTMLTransformer,\n });\n }\n\n\n protected rootElementMatcher(\n source: string,\n from: number,\n to: number,\n build: (raw: string, content: string, position: number, closing: string) => AreSyntaxTokenMatch\n ): AreSyntaxTokenMatch | null {\n\n // const rootTag = this.config.rootTag\n const rootTag = 'are-root';\n\n const tagStart = source.indexOf('<', from)\n if (tagStart === -1 || tagStart >= to) return null\n\n // only match if the tag name is exactly the configured root tag\n const tagNameMatch = source.slice(tagStart).match(/^<([a-zA-Z][a-zA-Z0-9-]*)/)\n if (!tagNameMatch || tagNameMatch[1].toLowerCase() !== rootTag) return null\n\n // delegate the actual matching to the shared HTML element logic\n return this.htmlElementMatcher(source, from, to, build)\n }\n\n protected htmlElementMatcher(\n source: string,\n from: number,\n to: number,\n build: (raw: string, content: string, position: number, closing: string) => AreSyntaxTokenMatch\n ): AreSyntaxTokenMatch | null {\n let index = from\n\n while (index < to) {\n const tagStart = source.indexOf('<', index)\n if (tagStart === -1 || tagStart >= to) return null\n\n // skip comments, closing tags, doctype, processing instructions\n if (source.startsWith('<!--', tagStart)) { index = tagStart + 1; continue }\n if (source[tagStart + 1] === '/') { index = tagStart + 1; continue }\n if (source[tagStart + 1] === '!' || source[tagStart + 1] === '?') { index = tagStart + 1; continue }\n\n const tagNameMatch = source.slice(tagStart).match(/^<([a-zA-Z][a-zA-Z0-9-]*)/)\n if (!tagNameMatch) { index = tagStart + 1; continue }\n\n const tagName = tagNameMatch[1]\n const openingTagEnd = AreHTMLEngine.findTagClose(source, tagStart)\n if (openingTagEnd === -1) return null\n\n // extract id attribute if present in the opening tag\n const openingTagStr = source.slice(tagStart, openingTagEnd + 1)\n const idMatch = openingTagStr.match(/\\bid=[\"']([^\"']*)[\"']/)\n const id = idMatch ? idMatch[1] : undefined\n\n // self-closing: <br/> or <input/>\n if (source[openingTagEnd - 1] === '/') {\n const raw = source.slice(tagStart, openingTagEnd + 1)\n const content = source.slice(tagStart + tagNameMatch[0].length, openingTagEnd - 1)\n const match = build(raw, content, tagStart, '/>')\n match.payload = { entity: tagName, selfClose: true, id }\n return match\n }\n\n // find matching closing tag respecting nesting\n const closingTag = `</${tagName}>`\n let level = 0\n let searchIndex = openingTagEnd + 1\n let closingStart = -1\n\n while (searchIndex < to) {\n const nextOpen = source.indexOf(`<${tagName}`, searchIndex)\n const nextClose = source.indexOf(closingTag, searchIndex)\n if (nextClose === -1) break\n\n if (nextOpen !== -1 && nextOpen < nextClose) {\n const charAfter = source[nextOpen + tagName.length + 1]\n if (charAfter === ' ' || charAfter === '>' || charAfter === '/') {\n // Skip self-closing nested occurrences, e.g. <div/> inside <div>...</div>.\n const innerEnd = AreHTMLEngine.findTagClose(source, nextOpen)\n const isSelfClose = innerEnd !== -1 && source[innerEnd - 1] === '/'\n\n if (!isSelfClose) {\n level++\n }\n searchIndex = (innerEnd === -1 ? nextOpen + tagName.length + 1 : innerEnd + 1)\n continue\n }\n }\n\n if (level === 0) { closingStart = nextClose; break }\n level--\n searchIndex = nextClose + closingTag.length\n }\n\n if (closingStart === -1) return null\n\n const fullTag = source.slice(tagStart, closingStart + closingTag.length)\n const content = source.slice(openingTagEnd + 1, closingStart)\n const match = build(fullTag, content, tagStart, closingTag)\n match.payload = { entity: tagName, selfClose: false, id }\n return match\n }\n return null\n }\n\n /**\n * Find the index of the closing `>` of an opening tag, skipping over\n * `>` characters that appear inside quoted attribute values.\n */\n private static findTagClose(source: string, from: number): number {\n let inSingle = false\n let inDouble = false\n\n for (let i = from; i < source.length; i++) {\n const ch = source[i]\n if (ch === '\"' && !inSingle) inDouble = !inDouble\n else if (ch === \"'\" && !inDouble) inSingle = !inSingle\n else if (ch === '>' && !inSingle && !inDouble) return i\n }\n\n return -1\n }\n\n}"]}