@adaas/are-html 0.0.11 → 0.0.13

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 (113) hide show
  1. package/dist/browser/index.d.mts +19 -4
  2. package/dist/browser/index.mjs +115 -8
  3. package/dist/browser/index.mjs.map +1 -1
  4. package/dist/node/{AreBinding.attribute-C6JasbJL.d.ts → AreBinding.attribute-Bm5LlOyE.d.ts} +7 -0
  5. package/dist/node/{AreBinding.attribute-C6qrxN8K.d.mts → AreBinding.attribute-doUvtOjc.d.mts} +7 -0
  6. package/dist/node/attributes/AreBinding.attribute.d.mts +1 -1
  7. package/dist/node/attributes/AreBinding.attribute.d.ts +1 -1
  8. package/dist/node/attributes/AreDirective.attribute.d.mts +1 -1
  9. package/dist/node/attributes/AreDirective.attribute.d.ts +1 -1
  10. package/dist/node/attributes/AreEvent.attribute.d.mts +1 -1
  11. package/dist/node/attributes/AreEvent.attribute.d.ts +1 -1
  12. package/dist/node/attributes/AreStatic.attribute.d.mts +1 -1
  13. package/dist/node/attributes/AreStatic.attribute.d.ts +1 -1
  14. package/dist/node/directives/AreDirectiveFor.directive.d.mts +1 -1
  15. package/dist/node/directives/AreDirectiveFor.directive.d.ts +1 -1
  16. package/dist/node/directives/AreDirectiveFor.directive.js +11 -1
  17. package/dist/node/directives/AreDirectiveFor.directive.js.map +1 -1
  18. package/dist/node/directives/AreDirectiveFor.directive.mjs +11 -1
  19. package/dist/node/directives/AreDirectiveFor.directive.mjs.map +1 -1
  20. package/dist/node/directives/AreDirectiveIf.directive.d.mts +1 -1
  21. package/dist/node/directives/AreDirectiveIf.directive.d.ts +1 -1
  22. package/dist/node/engine/AreHTML.compiler.d.mts +8 -1
  23. package/dist/node/engine/AreHTML.compiler.d.ts +8 -1
  24. package/dist/node/engine/AreHTML.compiler.js +17 -0
  25. package/dist/node/engine/AreHTML.compiler.js.map +1 -1
  26. package/dist/node/engine/AreHTML.compiler.mjs +17 -0
  27. package/dist/node/engine/AreHTML.compiler.mjs.map +1 -1
  28. package/dist/node/engine/AreHTML.context.js +2 -2
  29. package/dist/node/engine/AreHTML.context.js.map +1 -1
  30. package/dist/node/engine/AreHTML.context.mjs +3 -3
  31. package/dist/node/engine/AreHTML.context.mjs.map +1 -1
  32. package/dist/node/engine/AreHTML.interpreter.d.mts +3 -0
  33. package/dist/node/engine/AreHTML.interpreter.d.ts +3 -0
  34. package/dist/node/engine/AreHTML.interpreter.js +44 -0
  35. package/dist/node/engine/AreHTML.interpreter.js.map +1 -1
  36. package/dist/node/engine/AreHTML.interpreter.mjs +44 -0
  37. package/dist/node/engine/AreHTML.interpreter.mjs.map +1 -1
  38. package/dist/node/engine/AreHTML.lifecycle.d.mts +2 -1
  39. package/dist/node/engine/AreHTML.lifecycle.d.ts +2 -1
  40. package/dist/node/engine/AreHTML.lifecycle.js +13 -1
  41. package/dist/node/engine/AreHTML.lifecycle.js.map +1 -1
  42. package/dist/node/engine/AreHTML.lifecycle.mjs +13 -1
  43. package/dist/node/engine/AreHTML.lifecycle.mjs.map +1 -1
  44. package/dist/node/engine/AreHTML.tokenizer.d.mts +1 -1
  45. package/dist/node/engine/AreHTML.tokenizer.d.ts +1 -1
  46. package/dist/node/engine/AreHTML.transformer.d.mts +1 -1
  47. package/dist/node/engine/AreHTML.transformer.d.ts +1 -1
  48. package/dist/node/index.d.mts +1 -1
  49. package/dist/node/index.d.ts +1 -1
  50. package/dist/node/instructions/AreHTML.instructions.types.d.mts +2 -4
  51. package/dist/node/instructions/AreHTML.instructions.types.d.ts +2 -4
  52. package/dist/node/lib/AreDirective/AreDirective.component.d.mts +1 -1
  53. package/dist/node/lib/AreDirective/AreDirective.component.d.ts +1 -1
  54. package/dist/node/lib/AreDirective/AreDirective.types.d.mts +1 -1
  55. package/dist/node/lib/AreDirective/AreDirective.types.d.ts +1 -1
  56. package/dist/node/lib/AreHTML/AreHTML.tokenizer.d.mts +1 -1
  57. package/dist/node/lib/AreHTML/AreHTML.tokenizer.d.ts +1 -1
  58. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.d.mts +1 -1
  59. package/dist/node/lib/AreHTMLAttribute/AreHTML.attribute.d.ts +1 -1
  60. package/dist/node/lib/AreHTMLNode/AreHTMLNode.d.mts +1 -1
  61. package/dist/node/lib/AreHTMLNode/AreHTMLNode.d.ts +1 -1
  62. package/dist/node/lib/AreHTMLNode/AreHTMLNode.js +14 -0
  63. package/dist/node/lib/AreHTMLNode/AreHTMLNode.js.map +1 -1
  64. package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs +14 -0
  65. package/dist/node/lib/AreHTMLNode/AreHTMLNode.mjs.map +1 -1
  66. package/dist/node/lib/AreRoot/AreRoot.component.js +16 -3
  67. package/dist/node/lib/AreRoot/AreRoot.component.js.map +1 -1
  68. package/dist/node/lib/AreRoot/AreRoot.component.mjs +16 -3
  69. package/dist/node/lib/AreRoot/AreRoot.component.mjs.map +1 -1
  70. package/dist/node/nodes/AreComment.d.mts +1 -1
  71. package/dist/node/nodes/AreComment.d.ts +1 -1
  72. package/dist/node/nodes/AreComponent.d.mts +1 -1
  73. package/dist/node/nodes/AreComponent.d.ts +1 -1
  74. package/dist/node/nodes/AreInterpolation.d.mts +1 -1
  75. package/dist/node/nodes/AreInterpolation.d.ts +1 -1
  76. package/dist/node/nodes/AreRoot.d.mts +1 -1
  77. package/dist/node/nodes/AreRoot.d.ts +1 -1
  78. package/dist/node/nodes/AreText.d.mts +1 -1
  79. package/dist/node/nodes/AreText.d.ts +1 -1
  80. package/examples/component-styles/concept.ts +41 -0
  81. package/examples/component-styles/containers/UI.container.ts +122 -0
  82. package/examples/component-styles/dist/index.html +25 -0
  83. package/examples/{jumpstart/dist/mor90p6y-0plg7g.js → component-styles/dist/mpq29j47-owas2v.js} +8326 -5942
  84. package/examples/component-styles/public/index.html +25 -0
  85. package/examples/component-styles/src/components/AppPage.component.ts +74 -0
  86. package/examples/component-styles/src/components/TheAlert.component.ts +81 -0
  87. package/examples/component-styles/src/components/TheButton.component.ts +71 -0
  88. package/examples/component-styles/src/components/TheCard.component.ts +64 -0
  89. package/examples/component-styles/src/concept.ts +70 -0
  90. package/examples/dashboard/dist/index.html +1 -1
  91. package/examples/dashboard/dist/{mpmt0gys-1r9rcu.js → mppzjw80-9gwa4h.js} +1223 -863
  92. package/examples/jumpstart/dist/index.html +1 -1
  93. package/examples/jumpstart/dist/{mor90p7p-1898bz.js → mppwx932-xbmb0x.js} +4215 -1984
  94. package/examples/signal-routing/concept.ts +41 -0
  95. package/examples/signal-routing/containers/UI.container.ts +126 -0
  96. package/examples/signal-routing/dist/index.html +18 -0
  97. package/examples/signal-routing/dist/mpq6u1wz-2pkqe2.js +14002 -0
  98. package/examples/signal-routing/public/index.html +18 -0
  99. package/examples/signal-routing/src/components/AboutPage.component.ts +74 -0
  100. package/examples/signal-routing/src/components/AppShell.component.ts +42 -0
  101. package/examples/signal-routing/src/components/HomePage.component.ts +76 -0
  102. package/examples/signal-routing/src/components/NavBar.component.ts +104 -0
  103. package/examples/signal-routing/src/components/SettingsPage.component.ts +98 -0
  104. package/examples/signal-routing/src/concept.ts +114 -0
  105. package/package.json +7 -5
  106. package/src/directives/AreDirectiveFor.directive.ts +12 -1
  107. package/src/engine/AreHTML.compiler.ts +24 -7
  108. package/src/engine/AreHTML.context.ts +6 -4
  109. package/src/engine/AreHTML.interpreter.ts +54 -0
  110. package/src/engine/AreHTML.lifecycle.ts +16 -12
  111. package/src/instructions/AreHTML.instructions.types.ts +2 -4
  112. package/src/lib/AreHTMLNode/AreHTMLNode.ts +15 -0
  113. package/src/lib/AreRoot/AreRoot.component.ts +31 -7
@@ -98,6 +98,13 @@ declare class AreHTMLNode extends AreNode {
98
98
  * The styles defined for the node, which can include inline styles or styles defined in a separate stylesheet that are applied to the node. These styles can be used to control the visual appearance of the node and can be defined using standard CSS syntax.
99
99
  */
100
100
  get styles(): AreStyle;
101
+ /**
102
+ * Registers or updates the component-scoped CSS string for this node.
103
+ * Called by the @Are.Styles-decorated method on the associated component.
104
+ * A new AreStyle fragment is registered in scope on first call; subsequent
105
+ * calls update the existing fragment in-place.
106
+ */
107
+ setStyles(css: string): void;
101
108
  }
102
109
 
103
110
  declare class AreHTMLAttribute extends AreAttribute {
@@ -98,6 +98,13 @@ declare class AreHTMLNode extends AreNode {
98
98
  * The styles defined for the node, which can include inline styles or styles defined in a separate stylesheet that are applied to the node. These styles can be used to control the visual appearance of the node and can be defined using standard CSS syntax.
99
99
  */
100
100
  get styles(): AreStyle;
101
+ /**
102
+ * Registers or updates the component-scoped CSS string for this node.
103
+ * Called by the @Are.Styles-decorated method on the associated component.
104
+ * A new AreStyle fragment is registered in scope on first call; subsequent
105
+ * calls update the existing fragment in-place.
106
+ */
107
+ setStyles(css: string): void;
101
108
  }
102
109
 
103
110
  declare class AreHTMLAttribute extends AreAttribute {
@@ -1,4 +1,4 @@
1
- export { A as AreBindingAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
1
+ export { A as AreBindingAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.mjs';
@@ -1,4 +1,4 @@
1
- export { A as AreBindingAttribute } from '../AreBinding.attribute-C6JasbJL.js';
1
+ export { A as AreBindingAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.js';
@@ -1,4 +1,4 @@
1
- export { b as AreDirectiveAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
1
+ export { b as AreDirectiveAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.mjs';
@@ -1,4 +1,4 @@
1
- export { b as AreDirectiveAttribute } from '../AreBinding.attribute-C6JasbJL.js';
1
+ export { b as AreDirectiveAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.js';
@@ -1,4 +1,4 @@
1
- export { c as AreEventAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
1
+ export { c as AreEventAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.mjs';
@@ -1,4 +1,4 @@
1
- export { c as AreEventAttribute } from '../AreBinding.attribute-C6JasbJL.js';
1
+ export { c as AreEventAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.js';
@@ -1,4 +1,4 @@
1
- export { f as AreStaticAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
1
+ export { f as AreStaticAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.mjs';
@@ -1,4 +1,4 @@
1
- export { f as AreStaticAttribute } from '../AreBinding.attribute-C6JasbJL.js';
1
+ export { f as AreStaticAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
2
2
  import '@adaas/are';
3
3
  import '@adaas/a-concept';
4
4
  import '../lib/AreStyle/AreStyle.context.js';
@@ -1,6 +1,6 @@
1
1
  import { A_Scope } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
- import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
3
+ import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
4
4
  import { AreStore, AreScene } from '@adaas/are';
5
5
  import '../lib/AreStyle/AreStyle.context.mjs';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { A_Scope } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
- import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-C6JasbJL.js';
3
+ import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
4
4
  import { AreStore, AreScene } from '@adaas/are';
5
5
  import '../lib/AreStyle/AreStyle.context.js';
6
6
 
@@ -175,7 +175,17 @@ exports.AreDirectiveFor = class AreDirectiveFor extends AreDirective_component.A
175
175
  if (arg.startsWith("'") && arg.endsWith("'")) return arg.slice(1, -1);
176
176
  if (arg.startsWith('"') && arg.endsWith('"')) return arg.slice(1, -1);
177
177
  if (!isNaN(Number(arg))) return Number(arg);
178
- return store.get(arg);
178
+ const stripped = arg.replace(/\?$/, "");
179
+ if (stripped.includes(".")) {
180
+ const parts = stripped.split(".").map((p) => p.replace(/\?$/, ""));
181
+ let val = store.get(parts[0]);
182
+ for (let j = 1; j < parts.length; j++) {
183
+ if (val == null) return void 0;
184
+ val = val[parts[j]];
185
+ }
186
+ return val ?? void 0;
187
+ }
188
+ return store.get(stripped);
179
189
  });
180
190
  result = fn(...resolvedArgs);
181
191
  } else if (arrayExpr.includes(".")) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/AreDirectiveFor.directive.ts"],"names":["AreDirectiveFor","AreDirective","AddCommentInstruction","AreDirectiveContext","AreCompilerError","A_Caller","A_Scope","AreStore","AreScene","A_Logger","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyBaA,uBAAA,GAAN,8BAA8BC,mCAAA,CAAa;AAAA,EAI9C,UACwB,SAAA,EACD,KAAA,EACC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AAEE,IAAA,MAAA,CAAO,MAAM,CAAA,gCAAA,EAAmC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAEnF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAQvB,IAAA,MAAM,WAAA,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,CAAA,CAAA;AAAA,EACjB,qCAASC,YAAQ,CAAA;AAAA,CAAA,EAjGbR,uBAAA,CA8FT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AA9FSA,uBAAA,GAAN,eAAA,CAAA;AAAA,EALNU,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACAT,mCAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACXD,uBAAA,CAAA","file":"AreDirectiveFor.directive.js","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreCompilerError, AreScene, AreStore } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\ntype AreForExpression = {\n key: string;\n index: string | undefined;\n arrayExpr: string;\n /** Optional `track <expr>` clause, e.g. `track row.id` */\n trackExpr: string | undefined;\n};\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $for directive. Iterates over an array expression resolved from the store and renders a cloned template fragment per item, managing per-item subscopes and comment-node anchors. Supports keyed diffing via an optional track clause to minimise DOM mutations on collection updates.'\n})\n@AreDirective.Priority(1)\nexport class AreDirectiveFor extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n\n logger.debug(`[Transform] directive $FOR for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * Transfer the original node's scope (with all registered attributes and children)\n * to the template clone, and give the owner node a fresh empty scope.\n * This mirrors the $if directive's approach, making the owner a lightweight\n * group container whose sole visible presence is a comment placeholder.\n */\n const forTemplate = node.cloneWithScope();\n\n /**\n * Remove the $for attribute from the template so iterative clones do not\n * re-trigger this directive during their own transform phase.\n * Re-register it on the owner so the reactive compile/update pipeline keeps working.\n */\n const forAttr = forTemplate.attributes.find(d => d.name === attribute.name);\n\n if (forAttr) {\n forTemplate.scope.deregister(forAttr);\n node.scope.register(forAttr);\n }\n\n /**\n * Re-initialize the owner node with its fresh scope so it becomes a valid\n * group container that will own the generated item nodes as children.\n */\n node.init();\n\n /**\n * Store the template for use in compile and update.\n */\n attribute.template = forTemplate;\n\n\n /**\n * Parse the $for expression and evaluate the source array.\n */\n const { key, index, arrayExpr } = this.parseExpression(attribute.content);\n const array = this.resolveArray(store, arrayExpr, attribute.content);\n\n attribute.value = array;\n\n /**\n * For each item in the array, spawn a clone of the template with the\n * item's store values pre-set and its scene activated.\n *\n * The children are added to the owner node before the main compiler's\n * children iteration loop runs, so the main cycle will compile them —\n * no explicit child.compile() call is needed here.\n */\n for (let i = 0; i < array.length; i++) {\n this.spawnItemNode(attribute.template!, attribute.owner, key, index, array[i], i);\n }\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Replace the group node's default host declaration with a comment placeholder\n * so the owner element itself does not render as a DOM element — the item nodes\n * render as its children instead.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- for: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier });\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n }\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Re-evaluate the source array.\n */\n const { key, index, arrayExpr, trackExpr } = this.parseExpression(attribute.content);\n const newArray = this.resolveArray(store, arrayExpr, attribute.content);\n\n const owner = attribute.owner;\n const currentChildren = [...owner.children] as AreHTMLNode[];\n\n attribute.value = newArray;\n\n const computeKey = this.makeKeyFn(key, index, trackExpr);\n\n // ── 1. Index existing children by stable key ────────────────────────\n const childByKey = new Map<any, AreHTMLNode>();\n const remaining = new Set<AreHTMLNode>();\n\n for (let i = 0; i < currentChildren.length; i++) {\n const child = currentChildren[i];\n const ctx = child.scope.resolveFlat(AreDirectiveContext);\n const k = ctx ? computeKey(ctx.scope[key], ctx.scope[index || 'index']) : Symbol('orphan');\n childByKey.set(k, child);\n remaining.add(child);\n }\n\n // ── 2. Walk desired list; reuse existing or spawn new ───────────────\n const desired: AreHTMLNode[] = [];\n const newOnes: AreHTMLNode[] = [];\n\n for (let i = 0; i < newArray.length; i++) {\n const item = newArray[i];\n const k = computeKey(item, i);\n const existing = childByKey.get(k);\n\n if (existing) {\n remaining.delete(existing);\n\n let directiveContext = existing.scope.resolveFlat(AreDirectiveContext);\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(existing.aseid);\n existing.scope.register(directiveContext);\n }\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n };\n desired.push(existing);\n } else {\n const itemNode = this.spawnItemNode(attribute.template!, owner, key, index, item, i);\n desired.push(itemNode);\n newOnes.push(itemNode);\n }\n }\n\n // ── 3. Unmount + detach removed children ─────────────────────────────\n for (const child of remaining) {\n child.unmount();\n owner.removeChild(child);\n }\n\n // ── 4. Mount only the new ones (kept children stay where they are). ─\n for (const child of newOnes) {\n child.transform();\n child.compile();\n child.mount();\n }\n }\n\n\n // ─────────────────────────────────────────────────────────────────────────────\n // ── Helpers ──────────────────────────────────────────────────────────────────\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Build a key-function that derives a stable identity from each item.\n * If the user provided a `track <expr>` clause, evaluate it as a path on\n * the item; otherwise fall back to the item identity (reference equality).\n */\n private makeKeyFn(key: string, index: string | undefined, trackExpr: string | undefined): (item: any, i: number) => any {\n if (!trackExpr) {\n return (item, i) => item ?? i;\n }\n\n // Strip any leading `key.` so users can write `track row.id`.\n const path = trackExpr.startsWith(key + '.') ? trackExpr.slice(key.length + 1) : trackExpr;\n\n return (item, i) => {\n if (item == null) return i;\n if (path === key || path === '$index') return path === '$index' ? i : item;\n\n // dotted path lookup\n const parts = path.split('.');\n let v: any = item;\n for (const p of parts) {\n if (v == null) return i;\n v = v[p];\n }\n return v ?? i;\n };\n }\n\n /**\n * Parses the $for expression string into its constituent parts.\n *\n * Supported formats:\n * item in items\n * item, index in items\n * (item, index) in items\n * item in filter(items)\n * item, index in filter(items, 'active')\n * item in items track item.id\n * (item, i) in items track item.id\n */\n private parseExpression(content: string): AreForExpression {\n // Strip optional `track <expr>` suffix first.\n let trackExpr: string | undefined;\n const trackIdx = content.search(/\\s+track\\s+/);\n let body = content;\n if (trackIdx !== -1) {\n const m = content.slice(trackIdx).match(/\\s+track\\s+(.+)$/);\n if (m) {\n trackExpr = m[1].trim();\n body = content.slice(0, trackIdx).trim();\n }\n }\n\n const inIndex = body.lastIndexOf(' in ');\n const keyAndIndex = body.slice(0, inIndex).trim().replace(/^\\(|\\)$/g, '');\n const arrayExpr = body.slice(inIndex + 4).trim();\n const keyParts = keyAndIndex.split(',').map(p => p.trim());\n\n return {\n key: keyParts[0],\n index: keyParts[1] || undefined,\n arrayExpr,\n trackExpr,\n };\n }\n\n /**\n * Resolves the array expression against the store.\n * Supports both plain key lookups and function-call expressions:\n * items → store.get('items')\n * filter(items) → store.get('filter')(store.get('items'))\n */\n private resolveArray(store: AreStore, arrayExpr: string, fullContent: string): any[] {\n let result: any;\n const callMatch = arrayExpr.match(/^([^(]+)\\((.+)\\)$/);\n\n if (callMatch) {\n const fnName = callMatch[1].trim();\n const fn = store.get(fnName as any);\n\n if (typeof fn !== 'function')\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Function',\n description: `The expression \"${fnName}\" in the \"for\" directive does not resolve to a function in the store. Received: ${typeof fn}`,\n });\n\n const rawArgs = callMatch[2].split(',').map(a => a.trim());\n const resolvedArgs = rawArgs.map(arg => {\n if (arg.startsWith(\"'\") && arg.endsWith(\"'\")) return arg.slice(1, -1);\n if (arg.startsWith('\"') && arg.endsWith('\"')) return arg.slice(1, -1);\n if (!isNaN(Number(arg))) return Number(arg);\n return store.get(arg as any);\n });\n\n result = (fn as Function)(...resolvedArgs);\n } else if (arrayExpr.includes('.')) {\n // dotted-path lookup: e.g. \"list.items\" or \"record?.keywords\"\n // Strip optional-chaining `?` suffix from each segment so that\n // `record?.keywords` resolves the same as `record.keywords`.\n const parts = arrayExpr.split('.').map(p => p.replace(/\\?$/, ''));\n result = store.get(parts[0] as any);\n for (let i = 1; i < parts.length; i++) {\n if (result == null) break;\n result = result[parts[i]];\n }\n } else {\n result = store.get(arrayExpr.replace(/\\?$/, '') as any);\n }\n\n // null / undefined from optional-chaining expressions (e.g. `record?.keywords`)\n // means the source object is not yet loaded — treat as empty array so the\n // directive initialises gracefully and fills in when the store updates.\n if (result == null) return [];\n\n if (!Array.isArray(result))\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Value',\n description: `The \"for\" directive expects an array but got ${typeof result}. Expression: \"${fullContent}\". Received: ${JSON.stringify(result)}`,\n });\n\n return result;\n }\n\n /**\n * Creates a single item node from the template, registers it as a child of\n * the owner, initialises it, injects item-scoped store values, and activates\n * its scene so the mount/compile cycle will include it.\n *\n * NOTE: This method does NOT call compile() or mount() — the caller is\n * responsible for doing so when the main lifecycle cycle won't cover it\n * (i.e. during update, but not during the initial compile phase).\n */\n private spawnItemNode(\n template: AreHTMLNode,\n owner: AreHTMLNode,\n key: string,\n index: string | undefined,\n item: any,\n i: number,\n ): AreHTMLNode {\n const itemNode = template.clone() as AreHTMLNode;\n\n owner.addChild(itemNode);\n\n const queue = [itemNode];\n\n while (queue.length > 0) {\n const current = queue.shift()!\n\n current.init();\n\n queue.push(...current.children as AreHTMLNode[]);\n }\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n let directiveContext = itemNode.scope.resolveFlat(AreDirectiveContext);\n\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(itemNode.aseid);\n itemNode.scope.register(directiveContext);\n }\n\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n }\n\n itemNode.scene.activate();\n\n return itemNode;\n }\n}"]}
1
+ {"version":3,"sources":["../../../src/directives/AreDirectiveFor.directive.ts"],"names":["AreDirectiveFor","AreDirective","AddCommentInstruction","AreDirectiveContext","AreCompilerError","A_Caller","A_Scope","AreStore","AreScene","A_Logger","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyBaA,uBAAA,GAAN,8BAA8BC,mCAAA,CAAa;AAAA,EAI9C,UACwB,SAAA,EACD,KAAA,EACC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AAEE,IAAA,MAAA,CAAO,MAAM,CAAA,gCAAA,EAAmC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAEnF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAQvB,IAAA,MAAM,WAAA,GAAc,KAAK,cAAA,EAAe;AAOxC,IAAA,MAAM,OAAA,GAAU,YAAY,UAAA,CAAW,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,IAAI,CAAA;AAE1E,IAAA,IAAI,OAAA,EAAS;AACT,MAAA,WAAA,CAAY,KAA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AAQ,CAAA,CAAA;AAAA,EACjB,qCAASC,gBAAQ,CAAA;AAAA,CAAA,EATbT,uBAAA,CAIT,SAAA,EAAA,WAAA,EAAA,CAAA,CAAA;AAoEA,eAAA,CAAA;AAAA,EADCC,mCAAA,CAAa,OAAA;AAAA,EAET,qCAASI,iBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASC,YAAQ,CAAA;AAAA,CAAA,EA3EbR,uBAAA,CAwET,SAAA,EAAA,SAAA,EAAA,CAAA,CAAA;AAsBA,eAAA,CAAA;AAAA,EADCC,mCAAA,CAAa,MAAA;AAAA,EAET,qCAASI,iBAAQ,CAAA,CAAA;AAAA,EACjB,qCAASE,YAAQ,CAAA,CAAA;AAAA,EACjB,qCAASC,YAAQ,CAAA;AAAA,CAAA,EAjGbR,uBAAA,CA8FT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AA9FSA,uBAAA,GAAN,eAAA,CAAA;AAAA,EALNU,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACAT,mCAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACXD,uBAAA,CAAA","file":"AreDirectiveFor.directive.js","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreCompilerError, AreScene, AreStore } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\ntype AreForExpression = {\n key: string;\n index: string | undefined;\n arrayExpr: string;\n /** Optional `track <expr>` clause, e.g. `track row.id` */\n trackExpr: string | undefined;\n};\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $for directive. Iterates over an array expression resolved from the store and renders a cloned template fragment per item, managing per-item subscopes and comment-node anchors. Supports keyed diffing via an optional track clause to minimise DOM mutations on collection updates.'\n})\n@AreDirective.Priority(1)\nexport class AreDirectiveFor extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n\n logger.debug(`[Transform] directive $FOR for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * Transfer the original node's scope (with all registered attributes and children)\n * to the template clone, and give the owner node a fresh empty scope.\n * This mirrors the $if directive's approach, making the owner a lightweight\n * group container whose sole visible presence is a comment placeholder.\n */\n const forTemplate = node.cloneWithScope();\n\n /**\n * Remove the $for attribute from the template so iterative clones do not\n * re-trigger this directive during their own transform phase.\n * Re-register it on the owner so the reactive compile/update pipeline keeps working.\n */\n const forAttr = forTemplate.attributes.find(d => d.name === attribute.name);\n\n if (forAttr) {\n forTemplate.scope.deregister(forAttr);\n node.scope.register(forAttr);\n }\n\n /**\n * Re-initialize the owner node with its fresh scope so it becomes a valid\n * group container that will own the generated item nodes as children.\n */\n node.init();\n\n /**\n * Store the template for use in compile and update.\n */\n attribute.template = forTemplate;\n\n\n /**\n * Parse the $for expression and evaluate the source array.\n */\n const { key, index, arrayExpr } = this.parseExpression(attribute.content);\n const array = this.resolveArray(store, arrayExpr, attribute.content);\n\n attribute.value = array;\n\n /**\n * For each item in the array, spawn a clone of the template with the\n * item's store values pre-set and its scene activated.\n *\n * The children are added to the owner node before the main compiler's\n * children iteration loop runs, so the main cycle will compile them —\n * no explicit child.compile() call is needed here.\n */\n for (let i = 0; i < array.length; i++) {\n this.spawnItemNode(attribute.template!, attribute.owner, key, index, array[i], i);\n }\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Replace the group node's default host declaration with a comment placeholder\n * so the owner element itself does not render as a DOM element — the item nodes\n * render as its children instead.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- for: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier });\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n }\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Re-evaluate the source array.\n */\n const { key, index, arrayExpr, trackExpr } = this.parseExpression(attribute.content);\n const newArray = this.resolveArray(store, arrayExpr, attribute.content);\n\n const owner = attribute.owner;\n const currentChildren = [...owner.children] as AreHTMLNode[];\n\n attribute.value = newArray;\n\n const computeKey = this.makeKeyFn(key, index, trackExpr);\n\n // ── 1. Index existing children by stable key ────────────────────────\n const childByKey = new Map<any, AreHTMLNode>();\n const remaining = new Set<AreHTMLNode>();\n\n for (let i = 0; i < currentChildren.length; i++) {\n const child = currentChildren[i];\n const ctx = child.scope.resolveFlat(AreDirectiveContext);\n const k = ctx ? computeKey(ctx.scope[key], ctx.scope[index || 'index']) : Symbol('orphan');\n childByKey.set(k, child);\n remaining.add(child);\n }\n\n // ── 2. Walk desired list; reuse existing or spawn new ───────────────\n const desired: AreHTMLNode[] = [];\n const newOnes: AreHTMLNode[] = [];\n\n for (let i = 0; i < newArray.length; i++) {\n const item = newArray[i];\n const k = computeKey(item, i);\n const existing = childByKey.get(k);\n\n if (existing) {\n remaining.delete(existing);\n\n let directiveContext = existing.scope.resolveFlat(AreDirectiveContext);\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(existing.aseid);\n existing.scope.register(directiveContext);\n }\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n };\n desired.push(existing);\n } else {\n const itemNode = this.spawnItemNode(attribute.template!, owner, key, index, item, i);\n desired.push(itemNode);\n newOnes.push(itemNode);\n }\n }\n\n // ── 3. Unmount + detach removed children ─────────────────────────────\n for (const child of remaining) {\n child.unmount();\n owner.removeChild(child);\n }\n\n // ── 4. Mount only the new ones (kept children stay where they are). ─\n for (const child of newOnes) {\n child.transform();\n child.compile();\n child.mount();\n }\n }\n\n\n // ─────────────────────────────────────────────────────────────────────────────\n // ── Helpers ──────────────────────────────────────────────────────────────────\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Build a key-function that derives a stable identity from each item.\n * If the user provided a `track <expr>` clause, evaluate it as a path on\n * the item; otherwise fall back to the item identity (reference equality).\n */\n private makeKeyFn(key: string, index: string | undefined, trackExpr: string | undefined): (item: any, i: number) => any {\n if (!trackExpr) {\n return (item, i) => item ?? i;\n }\n\n // Strip any leading `key.` so users can write `track row.id`.\n const path = trackExpr.startsWith(key + '.') ? trackExpr.slice(key.length + 1) : trackExpr;\n\n return (item, i) => {\n if (item == null) return i;\n if (path === key || path === '$index') return path === '$index' ? i : item;\n\n // dotted path lookup\n const parts = path.split('.');\n let v: any = item;\n for (const p of parts) {\n if (v == null) return i;\n v = v[p];\n }\n return v ?? i;\n };\n }\n\n /**\n * Parses the $for expression string into its constituent parts.\n *\n * Supported formats:\n * item in items\n * item, index in items\n * (item, index) in items\n * item in filter(items)\n * item, index in filter(items, 'active')\n * item in items track item.id\n * (item, i) in items track item.id\n */\n private parseExpression(content: string): AreForExpression {\n // Strip optional `track <expr>` suffix first.\n let trackExpr: string | undefined;\n const trackIdx = content.search(/\\s+track\\s+/);\n let body = content;\n if (trackIdx !== -1) {\n const m = content.slice(trackIdx).match(/\\s+track\\s+(.+)$/);\n if (m) {\n trackExpr = m[1].trim();\n body = content.slice(0, trackIdx).trim();\n }\n }\n\n const inIndex = body.lastIndexOf(' in ');\n const keyAndIndex = body.slice(0, inIndex).trim().replace(/^\\(|\\)$/g, '');\n const arrayExpr = body.slice(inIndex + 4).trim();\n const keyParts = keyAndIndex.split(',').map(p => p.trim());\n\n return {\n key: keyParts[0],\n index: keyParts[1] || undefined,\n arrayExpr,\n trackExpr,\n };\n }\n\n /**\n * Resolves the array expression against the store.\n * Supports both plain key lookups and function-call expressions:\n * items → store.get('items')\n * filter(items) → store.get('filter')(store.get('items'))\n */\n private resolveArray(store: AreStore, arrayExpr: string, fullContent: string): any[] {\n let result: any;\n const callMatch = arrayExpr.match(/^([^(]+)\\((.+)\\)$/);\n\n if (callMatch) {\n const fnName = callMatch[1].trim();\n const fn = store.get(fnName as any);\n\n if (typeof fn !== 'function')\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Function',\n description: `The expression \"${fnName}\" in the \"for\" directive does not resolve to a function in the store. Received: ${typeof fn}`,\n });\n\n const rawArgs = callMatch[2].split(',').map(a => a.trim());\n const resolvedArgs = rawArgs.map(arg => {\n if (arg.startsWith(\"'\") && arg.endsWith(\"'\")) return arg.slice(1, -1);\n if (arg.startsWith('\"') && arg.endsWith('\"')) return arg.slice(1, -1);\n if (!isNaN(Number(arg))) return Number(arg);\n // Dotted-path / optional-chain: e.g. `record?.embedding` or `record.data`\n const stripped = arg.replace(/\\?$/, '');\n if (stripped.includes('.')) {\n const parts = stripped.split('.').map(p => p.replace(/\\?$/, ''));\n let val: any = store.get(parts[0] as any);\n for (let j = 1; j < parts.length; j++) {\n if (val == null) return undefined;\n val = val[parts[j]];\n }\n return val ?? undefined;\n }\n return store.get(stripped as any);\n });\n\n result = (fn as Function)(...resolvedArgs);\n } else if (arrayExpr.includes('.')) {\n // dotted-path lookup: e.g. \"list.items\" or \"record?.keywords\"\n // Strip optional-chaining `?` suffix from each segment so that\n // `record?.keywords` resolves the same as `record.keywords`.\n const parts = arrayExpr.split('.').map(p => p.replace(/\\?$/, ''));\n result = store.get(parts[0] as any);\n for (let i = 1; i < parts.length; i++) {\n if (result == null) break;\n result = result[parts[i]];\n }\n } else {\n result = store.get(arrayExpr.replace(/\\?$/, '') as any);\n }\n\n // null / undefined from optional-chaining expressions (e.g. `record?.keywords`)\n // means the source object is not yet loaded — treat as empty array so the\n // directive initialises gracefully and fills in when the store updates.\n if (result == null) return [];\n\n if (!Array.isArray(result))\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Value',\n description: `The \"for\" directive expects an array but got ${typeof result}. Expression: \"${fullContent}\". Received: ${JSON.stringify(result)}`,\n });\n\n return result;\n }\n\n /**\n * Creates a single item node from the template, registers it as a child of\n * the owner, initialises it, injects item-scoped store values, and activates\n * its scene so the mount/compile cycle will include it.\n *\n * NOTE: This method does NOT call compile() or mount() — the caller is\n * responsible for doing so when the main lifecycle cycle won't cover it\n * (i.e. during update, but not during the initial compile phase).\n */\n private spawnItemNode(\n template: AreHTMLNode,\n owner: AreHTMLNode,\n key: string,\n index: string | undefined,\n item: any,\n i: number,\n ): AreHTMLNode {\n const itemNode = template.clone() as AreHTMLNode;\n\n owner.addChild(itemNode);\n\n const queue = [itemNode];\n\n while (queue.length > 0) {\n const current = queue.shift()!\n\n current.init();\n\n queue.push(...current.children as AreHTMLNode[]);\n }\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n let directiveContext = itemNode.scope.resolveFlat(AreDirectiveContext);\n\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(itemNode.aseid);\n itemNode.scope.register(directiveContext);\n }\n\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n }\n\n itemNode.scene.activate();\n\n return itemNode;\n }\n}"]}
@@ -163,7 +163,17 @@ let AreDirectiveFor = class extends AreDirective {
163
163
  if (arg.startsWith("'") && arg.endsWith("'")) return arg.slice(1, -1);
164
164
  if (arg.startsWith('"') && arg.endsWith('"')) return arg.slice(1, -1);
165
165
  if (!isNaN(Number(arg))) return Number(arg);
166
- return store.get(arg);
166
+ const stripped = arg.replace(/\?$/, "");
167
+ if (stripped.includes(".")) {
168
+ const parts = stripped.split(".").map((p) => p.replace(/\?$/, ""));
169
+ let val = store.get(parts[0]);
170
+ for (let j = 1; j < parts.length; j++) {
171
+ if (val == null) return void 0;
172
+ val = val[parts[j]];
173
+ }
174
+ return val ?? void 0;
175
+ }
176
+ return store.get(stripped);
167
177
  });
168
178
  result = fn(...resolvedArgs);
169
179
  } else if (arrayExpr.includes(".")) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/directives/AreDirectiveFor.directive.ts"],"names":[],"mappings":";;;;;;;;;AAyBO,IAAM,eAAA,GAAN,cAA8B,YAAA,CAAa;AAAA,EAI9C,UACwB,SAAA,EACD,KAAA,EACC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AAEE,IAAA,MAAA,CAAO,MAAM,CAAA,gCAAA,EAAmC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAEnF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAQvB,IAAA,MAAM,WAAA,GAAc,KAAK,cAAA,EAAe;AAOxC,IAAA,MAAM,OAAA,GAAU,YAAY,UAAA,CAAW,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,IAAI,CAAA;AAE1E,IAAA,IAAI,OAAA,EAAS;AACT,MAAA,WAAA,CAAY,KAAA,CAAM,WAAW,OAAO,CAAA;AACpC,MAAA,IAAA,CAAK,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA,IAC/B;AAMA,IAAA,IAAA,CAAK,IAAA,EAAK;AAKV,IAAA,SAAA,CAAU,Q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@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreCompilerError, AreScene, AreStore } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\ntype AreForExpression = {\n key: string;\n index: string | undefined;\n arrayExpr: string;\n /** Optional `track <expr>` clause, e.g. `track row.id` */\n trackExpr: string | undefined;\n};\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $for directive. Iterates over an array expression resolved from the store and renders a cloned template fragment per item, managing per-item subscopes and comment-node anchors. Supports keyed diffing via an optional track clause to minimise DOM mutations on collection updates.'\n})\n@AreDirective.Priority(1)\nexport class AreDirectiveFor extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n\n logger.debug(`[Transform] directive $FOR for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * Transfer the original node's scope (with all registered attributes and children)\n * to the template clone, and give the owner node a fresh empty scope.\n * This mirrors the $if directive's approach, making the owner a lightweight\n * group container whose sole visible presence is a comment placeholder.\n */\n const forTemplate = node.cloneWithScope();\n\n /**\n * Remove the $for attribute from the template so iterative clones do not\n * re-trigger this directive during their own transform phase.\n * Re-register it on the owner so the reactive compile/update pipeline keeps working.\n */\n const forAttr = forTemplate.attributes.find(d => d.name === attribute.name);\n\n if (forAttr) {\n forTemplate.scope.deregister(forAttr);\n node.scope.register(forAttr);\n }\n\n /**\n * Re-initialize the owner node with its fresh scope so it becomes a valid\n * group container that will own the generated item nodes as children.\n */\n node.init();\n\n /**\n * Store the template for use in compile and update.\n */\n attribute.template = forTemplate;\n\n\n /**\n * Parse the $for expression and evaluate the source array.\n */\n const { key, index, arrayExpr } = this.parseExpression(attribute.content);\n const array = this.resolveArray(store, arrayExpr, attribute.content);\n\n attribute.value = array;\n\n /**\n * For each item in the array, spawn a clone of the template with the\n * item's store values pre-set and its scene activated.\n *\n * The children are added to the owner node before the main compiler's\n * children iteration loop runs, so the main cycle will compile them —\n * no explicit child.compile() call is needed here.\n */\n for (let i = 0; i < array.length; i++) {\n this.spawnItemNode(attribute.template!, attribute.owner, key, index, array[i], i);\n }\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Replace the group node's default host declaration with a comment placeholder\n * so the owner element itself does not render as a DOM element — the item nodes\n * render as its children instead.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- for: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier });\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n }\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Re-evaluate the source array.\n */\n const { key, index, arrayExpr, trackExpr } = this.parseExpression(attribute.content);\n const newArray = this.resolveArray(store, arrayExpr, attribute.content);\n\n const owner = attribute.owner;\n const currentChildren = [...owner.children] as AreHTMLNode[];\n\n attribute.value = newArray;\n\n const computeKey = this.makeKeyFn(key, index, trackExpr);\n\n // ── 1. Index existing children by stable key ────────────────────────\n const childByKey = new Map<any, AreHTMLNode>();\n const remaining = new Set<AreHTMLNode>();\n\n for (let i = 0; i < currentChildren.length; i++) {\n const child = currentChildren[i];\n const ctx = child.scope.resolveFlat(AreDirectiveContext);\n const k = ctx ? computeKey(ctx.scope[key], ctx.scope[index || 'index']) : Symbol('orphan');\n childByKey.set(k, child);\n remaining.add(child);\n }\n\n // ── 2. Walk desired list; reuse existing or spawn new ───────────────\n const desired: AreHTMLNode[] = [];\n const newOnes: AreHTMLNode[] = [];\n\n for (let i = 0; i < newArray.length; i++) {\n const item = newArray[i];\n const k = computeKey(item, i);\n const existing = childByKey.get(k);\n\n if (existing) {\n remaining.delete(existing);\n\n let directiveContext = existing.scope.resolveFlat(AreDirectiveContext);\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(existing.aseid);\n existing.scope.register(directiveContext);\n }\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n };\n desired.push(existing);\n } else {\n const itemNode = this.spawnItemNode(attribute.template!, owner, key, index, item, i);\n desired.push(itemNode);\n newOnes.push(itemNode);\n }\n }\n\n // ── 3. Unmount + detach removed children ─────────────────────────────\n for (const child of remaining) {\n child.unmount();\n owner.removeChild(child);\n }\n\n // ── 4. Mount only the new ones (kept children stay where they are). ─\n for (const child of newOnes) {\n child.transform();\n child.compile();\n child.mount();\n }\n }\n\n\n // ─────────────────────────────────────────────────────────────────────────────\n // ── Helpers ──────────────────────────────────────────────────────────────────\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Build a key-function that derives a stable identity from each item.\n * If the user provided a `track <expr>` clause, evaluate it as a path on\n * the item; otherwise fall back to the item identity (reference equality).\n */\n private makeKeyFn(key: string, index: string | undefined, trackExpr: string | undefined): (item: any, i: number) => any {\n if (!trackExpr) {\n return (item, i) => item ?? i;\n }\n\n // Strip any leading `key.` so users can write `track row.id`.\n const path = trackExpr.startsWith(key + '.') ? trackExpr.slice(key.length + 1) : trackExpr;\n\n return (item, i) => {\n if (item == null) return i;\n if (path === key || path === '$index') return path === '$index' ? i : item;\n\n // dotted path lookup\n const parts = path.split('.');\n let v: any = item;\n for (const p of parts) {\n if (v == null) return i;\n v = v[p];\n }\n return v ?? i;\n };\n }\n\n /**\n * Parses the $for expression string into its constituent parts.\n *\n * Supported formats:\n * item in items\n * item, index in items\n * (item, index) in items\n * item in filter(items)\n * item, index in filter(items, 'active')\n * item in items track item.id\n * (item, i) in items track item.id\n */\n private parseExpression(content: string): AreForExpression {\n // Strip optional `track <expr>` suffix first.\n let trackExpr: string | undefined;\n const trackIdx = content.search(/\\s+track\\s+/);\n let body = content;\n if (trackIdx !== -1) {\n const m = content.slice(trackIdx).match(/\\s+track\\s+(.+)$/);\n if (m) {\n trackExpr = m[1].trim();\n body = content.slice(0, trackIdx).trim();\n }\n }\n\n const inIndex = body.lastIndexOf(' in ');\n const keyAndIndex = body.slice(0, inIndex).trim().replace(/^\\(|\\)$/g, '');\n const arrayExpr = body.slice(inIndex + 4).trim();\n const keyParts = keyAndIndex.split(',').map(p => p.trim());\n\n return {\n key: keyParts[0],\n index: keyParts[1] || undefined,\n arrayExpr,\n trackExpr,\n };\n }\n\n /**\n * Resolves the array expression against the store.\n * Supports both plain key lookups and function-call expressions:\n * items → store.get('items')\n * filter(items) → store.get('filter')(store.get('items'))\n */\n private resolveArray(store: AreStore, arrayExpr: string, fullContent: string): any[] {\n let result: any;\n const callMatch = arrayExpr.match(/^([^(]+)\\((.+)\\)$/);\n\n if (callMatch) {\n const fnName = callMatch[1].trim();\n const fn = store.get(fnName as any);\n\n if (typeof fn !== 'function')\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Function',\n description: `The expression \"${fnName}\" in the \"for\" directive does not resolve to a function in the store. Received: ${typeof fn}`,\n });\n\n const rawArgs = callMatch[2].split(',').map(a => a.trim());\n const resolvedArgs = rawArgs.map(arg => {\n if (arg.startsWith(\"'\") && arg.endsWith(\"'\")) return arg.slice(1, -1);\n if (arg.startsWith('\"') && arg.endsWith('\"')) return arg.slice(1, -1);\n if (!isNaN(Number(arg))) return Number(arg);\n return store.get(arg as any);\n });\n\n result = (fn as Function)(...resolvedArgs);\n } else if (arrayExpr.includes('.')) {\n // dotted-path lookup: e.g. \"list.items\" or \"record?.keywords\"\n // Strip optional-chaining `?` suffix from each segment so that\n // `record?.keywords` resolves the same as `record.keywords`.\n const parts = arrayExpr.split('.').map(p => p.replace(/\\?$/, ''));\n result = store.get(parts[0] as any);\n for (let i = 1; i < parts.length; i++) {\n if (result == null) break;\n result = result[parts[i]];\n }\n } else {\n result = store.get(arrayExpr.replace(/\\?$/, '') as any);\n }\n\n // null / undefined from optional-chaining expressions (e.g. `record?.keywords`)\n // means the source object is not yet loaded — treat as empty array so the\n // directive initialises gracefully and fills in when the store updates.\n if (result == null) return [];\n\n if (!Array.isArray(result))\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Value',\n description: `The \"for\" directive expects an array but got ${typeof result}. Expression: \"${fullContent}\". Received: ${JSON.stringify(result)}`,\n });\n\n return result;\n }\n\n /**\n * Creates a single item node from the template, registers it as a child of\n * the owner, initialises it, injects item-scoped store values, and activates\n * its scene so the mount/compile cycle will include it.\n *\n * NOTE: This method does NOT call compile() or mount() — the caller is\n * responsible for doing so when the main lifecycle cycle won't cover it\n * (i.e. during update, but not during the initial compile phase).\n */\n private spawnItemNode(\n template: AreHTMLNode,\n owner: AreHTMLNode,\n key: string,\n index: string | undefined,\n item: any,\n i: number,\n ): AreHTMLNode {\n const itemNode = template.clone() as AreHTMLNode;\n\n owner.addChild(itemNode);\n\n const queue = [itemNode];\n\n while (queue.length > 0) {\n const current = queue.shift()!\n\n current.init();\n\n queue.push(...current.children as AreHTMLNode[]);\n }\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n let directiveContext = itemNode.scope.resolveFlat(AreDirectiveContext);\n\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(itemNode.aseid);\n itemNode.scope.register(directiveContext);\n }\n\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n }\n\n itemNode.scene.activate();\n\n return itemNode;\n }\n}"]}
1
+ {"version":3,"sources":["../../../src/directives/AreDirectiveFor.directive.ts"],"names":[],"mappings":";;;;;;;;;AAyBO,IAAM,eAAA,GAAN,cAA8B,YAAA,CAAa;AAAA,EAI9C,UACwB,SAAA,EACD,KAAA,EACC,KAAA,EACA,KAAA,EACA,WACjB,IAAA,EACL;AAEE,IAAA,MAAA,CAAO,MAAM,CAAA,gCAAA,EAAmC,SAAA,CAAU,MAAM,KAAA,CAAM,QAAA,EAAU,CAAA,CAAA,CAAG,CAAA;AAEnF,IAAA,MAAM,OAAO,SAAA,CAAU,KAAA;AAQvB,IAAA,MAAM,WAAA,GAAc,KAAK,cAAA,EAAe;AAOxC,IAAA,MAAM,OAAA,GAAU,YAAY,UAAA,CAAW,IAAA,CAAK,OAAK,CAAA,CAAE,IAAA,KAAS,UAAU,IAAI,CAAA;AAE1E,IAAA,IAAI,OAAA,EAAS;AACT,MAAA,WAAA,CAAY,KAAA,CAAM,WAAW,OAAO,CAAA;AACpC,MAAA,IAAA,CAAK,KAAA,CAAM,SAAS,OAAO,CAAA;AAAA,IAC/B;AAMA,IAAA,IAAA,CAAK,IAAA,EAAK;AAKV,IAAA,SAAA,CAAU,QAAA,GAAW,WAAA;AAMrB,IAAA,MAAM,EAAE,KAAK,KAAA,EAAO,SAAA,KAAc,IAAA,CAAK,eAAA,CAAgB,UAAU,OAAO,CAAA;AACxE,IAAA,MAAM,QAAQ,IAAA,CAAK,YAAA,CAAa,KAAA,EAAO,SAAA,EAAW,UAAU,OAAO,CAAA;AAEnE,IAAA,SAAA,CAAU,KAAA,GAAQ,KAAA;AAUlB,IAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,KAAA,CAAM,QAAQ,CA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AAA,EAjGb,eAAA,CA8FT,SAAA,EAAA,QAAA,EAAA,CAAA,CAAA;AA9FS,eAAA,GAAN,eAAA,CAAA;AAAA,EALN,QAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB,CAAA;AAAA,EACA,YAAA,CAAa,SAAS,CAAC;AAAA,CAAA,EACX,eAAA,CAAA","file":"AreDirectiveFor.directive.mjs","sourcesContent":["import { A_Caller, A_Inject, A_Scope } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreCompilerError, AreScene, AreStore } from \"@adaas/are\";\nimport { AreDirective } from \"@adaas/are-html/directive/AreDirective.component\";\nimport { AddCommentInstruction } from \"@adaas/are-html/instructions/AddComment.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\nimport { AreDirectiveContext } from \"@adaas/are-html/directive/AreDirective.context\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\n\n\ntype AreForExpression = {\n key: string;\n index: string | undefined;\n arrayExpr: string;\n /** Optional `track <expr>` clause, e.g. `track row.id` */\n trackExpr: string | undefined;\n};\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'Built-in $for directive. Iterates over an array expression resolved from the store and renders a cloned template fragment per item, managing per-item subscopes and comment-node anchors. Supports keyed diffing via an optional track clause to minimise DOM mutations on collection updates.'\n})\n@AreDirective.Priority(1)\nexport class AreDirectiveFor extends AreDirective {\n\n\n @AreDirective.Transform\n transform(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(A_Scope) scope: A_Scope,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger: A_Logger,\n ...args: any[]\n ) {\n\n logger.debug(`[Transform] directive $FOR for <${attribute.owner.aseid.toString()}>`)\n\n const node = attribute.owner;\n\n /**\n * Transfer the original node's scope (with all registered attributes and children)\n * to the template clone, and give the owner node a fresh empty scope.\n * This mirrors the $if directive's approach, making the owner a lightweight\n * group container whose sole visible presence is a comment placeholder.\n */\n const forTemplate = node.cloneWithScope();\n\n /**\n * Remove the $for attribute from the template so iterative clones do not\n * re-trigger this directive during their own transform phase.\n * Re-register it on the owner so the reactive compile/update pipeline keeps working.\n */\n const forAttr = forTemplate.attributes.find(d => d.name === attribute.name);\n\n if (forAttr) {\n forTemplate.scope.deregister(forAttr);\n node.scope.register(forAttr);\n }\n\n /**\n * Re-initialize the owner node with its fresh scope so it becomes a valid\n * group container that will own the generated item nodes as children.\n */\n node.init();\n\n /**\n * Store the template for use in compile and update.\n */\n attribute.template = forTemplate;\n\n\n /**\n * Parse the $for expression and evaluate the source array.\n */\n const { key, index, arrayExpr } = this.parseExpression(attribute.content);\n const array = this.resolveArray(store, arrayExpr, attribute.content);\n\n attribute.value = array;\n\n /**\n * For each item in the array, spawn a clone of the template with the\n * item's store values pre-set and its scene activated.\n *\n * The children are added to the owner node before the main compiler's\n * children iteration loop runs, so the main cycle will compile them —\n * no explicit child.compile() call is needed here.\n */\n for (let i = 0; i < array.length; i++) {\n this.spawnItemNode(attribute.template!, attribute.owner, key, index, array[i], i);\n }\n }\n\n\n @AreDirective.Compile\n compile(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Replace the group node's default host declaration with a comment placeholder\n * so the owner element itself does not render as a DOM element — the item nodes\n * render as its children instead.\n */\n const hostInstruction = scene.host!;\n const commentIdentifier = ` --- for: ${attribute.template!.id} --- `;\n const declaration = new AddCommentInstruction({ content: commentIdentifier });\n\n scene.setHost(declaration);\n scene.planBefore(declaration, hostInstruction);\n scene.unPlan(hostInstruction);\n }\n\n\n @AreDirective.Update\n update(\n @A_Inject(A_Caller) attribute: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ): void {\n /**\n * Re-evaluate the source array.\n */\n const { key, index, arrayExpr, trackExpr } = this.parseExpression(attribute.content);\n const newArray = this.resolveArray(store, arrayExpr, attribute.content);\n\n const owner = attribute.owner;\n const currentChildren = [...owner.children] as AreHTMLNode[];\n\n attribute.value = newArray;\n\n const computeKey = this.makeKeyFn(key, index, trackExpr);\n\n // ── 1. Index existing children by stable key ────────────────────────\n const childByKey = new Map<any, AreHTMLNode>();\n const remaining = new Set<AreHTMLNode>();\n\n for (let i = 0; i < currentChildren.length; i++) {\n const child = currentChildren[i];\n const ctx = child.scope.resolveFlat(AreDirectiveContext);\n const k = ctx ? computeKey(ctx.scope[key], ctx.scope[index || 'index']) : Symbol('orphan');\n childByKey.set(k, child);\n remaining.add(child);\n }\n\n // ── 2. Walk desired list; reuse existing or spawn new ───────────────\n const desired: AreHTMLNode[] = [];\n const newOnes: AreHTMLNode[] = [];\n\n for (let i = 0; i < newArray.length; i++) {\n const item = newArray[i];\n const k = computeKey(item, i);\n const existing = childByKey.get(k);\n\n if (existing) {\n remaining.delete(existing);\n\n let directiveContext = existing.scope.resolveFlat(AreDirectiveContext);\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(existing.aseid);\n existing.scope.register(directiveContext);\n }\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n };\n desired.push(existing);\n } else {\n const itemNode = this.spawnItemNode(attribute.template!, owner, key, index, item, i);\n desired.push(itemNode);\n newOnes.push(itemNode);\n }\n }\n\n // ── 3. Unmount + detach removed children ─────────────────────────────\n for (const child of remaining) {\n child.unmount();\n owner.removeChild(child);\n }\n\n // ── 4. Mount only the new ones (kept children stay where they are). ─\n for (const child of newOnes) {\n child.transform();\n child.compile();\n child.mount();\n }\n }\n\n\n // ─────────────────────────────────────────────────────────────────────────────\n // ── Helpers ──────────────────────────────────────────────────────────────────\n // ─────────────────────────────────────────────────────────────────────────────\n\n /**\n * Build a key-function that derives a stable identity from each item.\n * If the user provided a `track <expr>` clause, evaluate it as a path on\n * the item; otherwise fall back to the item identity (reference equality).\n */\n private makeKeyFn(key: string, index: string | undefined, trackExpr: string | undefined): (item: any, i: number) => any {\n if (!trackExpr) {\n return (item, i) => item ?? i;\n }\n\n // Strip any leading `key.` so users can write `track row.id`.\n const path = trackExpr.startsWith(key + '.') ? trackExpr.slice(key.length + 1) : trackExpr;\n\n return (item, i) => {\n if (item == null) return i;\n if (path === key || path === '$index') return path === '$index' ? i : item;\n\n // dotted path lookup\n const parts = path.split('.');\n let v: any = item;\n for (const p of parts) {\n if (v == null) return i;\n v = v[p];\n }\n return v ?? i;\n };\n }\n\n /**\n * Parses the $for expression string into its constituent parts.\n *\n * Supported formats:\n * item in items\n * item, index in items\n * (item, index) in items\n * item in filter(items)\n * item, index in filter(items, 'active')\n * item in items track item.id\n * (item, i) in items track item.id\n */\n private parseExpression(content: string): AreForExpression {\n // Strip optional `track <expr>` suffix first.\n let trackExpr: string | undefined;\n const trackIdx = content.search(/\\s+track\\s+/);\n let body = content;\n if (trackIdx !== -1) {\n const m = content.slice(trackIdx).match(/\\s+track\\s+(.+)$/);\n if (m) {\n trackExpr = m[1].trim();\n body = content.slice(0, trackIdx).trim();\n }\n }\n\n const inIndex = body.lastIndexOf(' in ');\n const keyAndIndex = body.slice(0, inIndex).trim().replace(/^\\(|\\)$/g, '');\n const arrayExpr = body.slice(inIndex + 4).trim();\n const keyParts = keyAndIndex.split(',').map(p => p.trim());\n\n return {\n key: keyParts[0],\n index: keyParts[1] || undefined,\n arrayExpr,\n trackExpr,\n };\n }\n\n /**\n * Resolves the array expression against the store.\n * Supports both plain key lookups and function-call expressions:\n * items → store.get('items')\n * filter(items) → store.get('filter')(store.get('items'))\n */\n private resolveArray(store: AreStore, arrayExpr: string, fullContent: string): any[] {\n let result: any;\n const callMatch = arrayExpr.match(/^([^(]+)\\((.+)\\)$/);\n\n if (callMatch) {\n const fnName = callMatch[1].trim();\n const fn = store.get(fnName as any);\n\n if (typeof fn !== 'function')\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Function',\n description: `The expression \"${fnName}\" in the \"for\" directive does not resolve to a function in the store. Received: ${typeof fn}`,\n });\n\n const rawArgs = callMatch[2].split(',').map(a => a.trim());\n const resolvedArgs = rawArgs.map(arg => {\n if (arg.startsWith(\"'\") && arg.endsWith(\"'\")) return arg.slice(1, -1);\n if (arg.startsWith('\"') && arg.endsWith('\"')) return arg.slice(1, -1);\n if (!isNaN(Number(arg))) return Number(arg);\n // Dotted-path / optional-chain: e.g. `record?.embedding` or `record.data`\n const stripped = arg.replace(/\\?$/, '');\n if (stripped.includes('.')) {\n const parts = stripped.split('.').map(p => p.replace(/\\?$/, ''));\n let val: any = store.get(parts[0] as any);\n for (let j = 1; j < parts.length; j++) {\n if (val == null) return undefined;\n val = val[parts[j]];\n }\n return val ?? undefined;\n }\n return store.get(stripped as any);\n });\n\n result = (fn as Function)(...resolvedArgs);\n } else if (arrayExpr.includes('.')) {\n // dotted-path lookup: e.g. \"list.items\" or \"record?.keywords\"\n // Strip optional-chaining `?` suffix from each segment so that\n // `record?.keywords` resolves the same as `record.keywords`.\n const parts = arrayExpr.split('.').map(p => p.replace(/\\?$/, ''));\n result = store.get(parts[0] as any);\n for (let i = 1; i < parts.length; i++) {\n if (result == null) break;\n result = result[parts[i]];\n }\n } else {\n result = store.get(arrayExpr.replace(/\\?$/, '') as any);\n }\n\n // null / undefined from optional-chaining expressions (e.g. `record?.keywords`)\n // means the source object is not yet loaded — treat as empty array so the\n // directive initialises gracefully and fills in when the store updates.\n if (result == null) return [];\n\n if (!Array.isArray(result))\n throw new AreCompilerError({\n title: 'Invalid \"for\" Directive Value',\n description: `The \"for\" directive expects an array but got ${typeof result}. Expression: \"${fullContent}\". Received: ${JSON.stringify(result)}`,\n });\n\n return result;\n }\n\n /**\n * Creates a single item node from the template, registers it as a child of\n * the owner, initialises it, injects item-scoped store values, and activates\n * its scene so the mount/compile cycle will include it.\n *\n * NOTE: This method does NOT call compile() or mount() — the caller is\n * responsible for doing so when the main lifecycle cycle won't cover it\n * (i.e. during update, but not during the initial compile phase).\n */\n private spawnItemNode(\n template: AreHTMLNode,\n owner: AreHTMLNode,\n key: string,\n index: string | undefined,\n item: any,\n i: number,\n ): AreHTMLNode {\n const itemNode = template.clone() as AreHTMLNode;\n\n owner.addChild(itemNode);\n\n const queue = [itemNode];\n\n while (queue.length > 0) {\n const current = queue.shift()!\n\n current.init();\n\n queue.push(...current.children as AreHTMLNode[]);\n }\n\n /**\n * Resolve or create a directive context for the item node. This is needed to hold the item-specific store values (e.g. the \"item\" and \"index\" in a \"for\" loop) that the template's bindings will reference during compile and update. The context is shared among all clones of the same template, but that's fine because each clone gets its own scope values assigned here.\n */\n let directiveContext = itemNode.scope.resolveFlat(AreDirectiveContext);\n\n if (!directiveContext) {\n directiveContext = new AreDirectiveContext(itemNode.aseid);\n itemNode.scope.register(directiveContext);\n }\n\n directiveContext.scope = {\n ...directiveContext.scope,\n [key]: item,\n [index || 'index']: i,\n }\n\n itemNode.scene.activate();\n\n return itemNode;\n }\n}"]}
@@ -1,6 +1,6 @@
1
1
  import { A_Scope } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
- import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
3
+ import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
4
4
  import { AreStore, AreScene, AreSyntax } from '@adaas/are';
5
5
  import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.mjs';
6
6
  import '../lib/AreStyle/AreStyle.context.mjs';
@@ -1,6 +1,6 @@
1
1
  import { A_Scope } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
- import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-C6JasbJL.js';
3
+ import { a as AreDirective, b as AreDirectiveAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
4
4
  import { AreStore, AreScene, AreSyntax } from '@adaas/are';
5
5
  import { AreDirectiveContext } from '../lib/AreDirective/AreDirective.context.js';
6
6
  import '../lib/AreStyle/AreStyle.context.js';
@@ -1,12 +1,19 @@
1
1
  import { A_Feature } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
3
  import { AreCompiler, AreScene, AreStore, AreSyntax } from '@adaas/are';
4
- import { f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-C6qrxN8K.mjs';
4
+ import { e as AreHTMLNode, f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-doUvtOjc.mjs';
5
5
  import { AreInterpolation } from '../nodes/AreInterpolation.mjs';
6
6
  import { AreText } from '../nodes/AreText.mjs';
7
7
  import '../lib/AreStyle/AreStyle.context.mjs';
8
8
 
9
9
  declare class AreHTMLCompiler extends AreCompiler {
10
+ /**
11
+ * Extends the base compile for all AreHTMLNode instances (elements, components, root nodes).
12
+ * After the standard element/attribute/children instructions are emitted, checks whether
13
+ * the node has a registered AreStyle and plans an AddStyleInstruction so the interpreter
14
+ * can inject the CSS into the document head during mount.
15
+ */
16
+ compileHTMLNode(node: AreHTMLNode, scene: AreScene, logger?: A_Logger, ...args: any[]): void;
10
17
  /**
11
18
  * Default compile method for interpolations, which can be overridden by specific implementations if needed.
12
19
  *
@@ -1,12 +1,19 @@
1
1
  import { A_Feature } from '@adaas/a-concept';
2
2
  import { A_Logger } from '@adaas/a-utils/a-logger';
3
3
  import { AreCompiler, AreScene, AreStore, AreSyntax } from '@adaas/are';
4
- import { f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-C6JasbJL.js';
4
+ import { e as AreHTMLNode, f as AreStaticAttribute, b as AreDirectiveAttribute, c as AreEventAttribute, A as AreBindingAttribute } from '../AreBinding.attribute-Bm5LlOyE.js';
5
5
  import { AreInterpolation } from '../nodes/AreInterpolation.js';
6
6
  import { AreText } from '../nodes/AreText.js';
7
7
  import '../lib/AreStyle/AreStyle.context.js';
8
8
 
9
9
  declare class AreHTMLCompiler extends AreCompiler {
10
+ /**
11
+ * Extends the base compile for all AreHTMLNode instances (elements, components, root nodes).
12
+ * After the standard element/attribute/children instructions are emitted, checks whether
13
+ * the node has a registered AreStyle and plans an AddStyleInstruction so the interpreter
14
+ * can inject the CSS into the document head during mount.
15
+ */
16
+ compileHTMLNode(node: AreHTMLNode, scene: AreScene, logger?: A_Logger, ...args: any[]): void;
10
17
  /**
11
18
  * Default compile method for interpolations, which can be overridden by specific implementations if needed.
12
19
  *
@@ -14,6 +14,8 @@ var AreText = require('@adaas/are-html/nodes/AreText');
14
14
  var AddAttribute_instruction = require('@adaas/are-html/instructions/AddAttribute.instruction');
15
15
  var AddText_instruction = require('@adaas/are-html/instructions/AddText.instruction');
16
16
  var AddListener_instruction = require('@adaas/are-html/instructions/AddListener.instruction');
17
+ var AddStyle_instruction = require('@adaas/are-html/instructions/AddStyle.instruction');
18
+ var node = require('@adaas/are-html/node');
17
19
 
18
20
  var __defProp = Object.defineProperty;
19
21
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -27,6 +29,15 @@ var __decorateClass = (decorators, target, key, kind) => {
27
29
  };
28
30
  var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
29
31
  exports.AreHTMLCompiler = class AreHTMLCompiler extends are.AreCompiler {
32
+ compileHTMLNode(node, scene, logger, ...args) {
33
+ super.compile(node, scene, logger, ...args);
34
+ if (node.styles?.styles) {
35
+ const host = scene.host;
36
+ if (host) {
37
+ scene.plan(new AddStyle_instruction.AddStyleInstruction(host, { styles: node.styles.styles }));
38
+ }
39
+ }
40
+ }
30
41
  compileInterpolation(interpolation, scene, store, logger, ...args) {
31
42
  scene.plan(new AddText_instruction.AddTextInstruction({ content: interpolation.content, evaluate: true }));
32
43
  }
@@ -139,6 +150,12 @@ exports.AreHTMLCompiler = class AreHTMLCompiler extends are.AreCompiler {
139
150
  scene.plan(instruction);
140
151
  }
141
152
  };
153
+ __decorateClass([
154
+ are.AreCompiler.Compile(node.AreHTMLNode),
155
+ __decorateParam(0, aConcept.A_Inject(aConcept.A_Caller)),
156
+ __decorateParam(1, aConcept.A_Inject(are.AreScene)),
157
+ __decorateParam(2, aConcept.A_Inject(aLogger.A_Logger))
158
+ ], exports.AreHTMLCompiler.prototype, "compileHTMLNode", 1);
142
159
  __decorateClass([
143
160
  are.AreCompiler.Compile(AreInterpolation.AreInterpolation),
144
161
  __decorateParam(0, aConcept.A_Inject(aConcept.A_Caller)),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/engine/AreHTML.compiler.ts"],"names":["AreHTMLCompiler","AreCompiler","AddTextInstruction","AreCompilerError","AddAttributeInstruction","AreDirectiveFeatures","A_FormatterHelper","AddListenerInstruction","AreInterpolation","A_Caller","AreScene","AreStore","A_Logger","AreText","AreStaticAttribute","AreDirectiveAttribute","A_Feature","AreEventAttribute","AreBindingAttribute","AreSyntax","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBaA,uBAAA,GAAN,8BAA8BC,eAAA,CAAY;AAAA,EAuB7C,oBAAA,CACwB,aAAA,EACA,KAAA,EAEA,KAAA,EACA,WACjB,IAAA,EACL;AAeE,IAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,sCAAA,CAAmB,EAAE,OAAA,EAAS,cAAc,OAAA,EAAS,QAAA,EAAU,IAAA,EAAM,CAAC,CAAA;AAAA,EACzF;AAAA,EAMA,WAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACL;AACE,IAAA,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAQ,CAAA,oCAAA,EAAuC,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA,iBAAA,EAA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iler.js","sourcesContent":["import { A_Caller, A_Dependency, A_Feature, A_FormatterHelper, A_Inject } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\nimport { AreCompiler, AreScene, AreCompilerError, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreStaticAttribute } from \"@adaas/are-html/attributes/AreStatic.attribute\";\nimport { AreDirectiveFeatures } from \"@adaas/are-html/directive/AreDirective.constants\";\nimport { AreEventAttribute } from \"@adaas/are-html/attributes/AreEvent.attribute\";\nimport { AreBindingAttribute } from \"@adaas/are-html/attributes/AreBinding.attribute\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AddAttributeInstruction} from \"@adaas/are-html/instructions/AddAttribute.instruction\";\nimport { AddTextInstruction} from \"@adaas/are-html/instructions/AddText.instruction\";\nimport { AddListenerInstruction} from \"@adaas/are-html/instructions/AddListener.instruction\";\n\n\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'HTML-specific compiler for A-Concept Rendering Engine (ARE) components, extending the base AreCompiler to handle HTML templates, styles, and rendering logic tailored for web environments.'\n})\nexport class AreHTMLCompiler extends AreCompiler {\n\n // compile(\n // @A_Inject(A_Caller) node: AreHTMLNode,\n // @A_Inject(AreScene) scene: AreScene,\n // ...args: any[]\n // ): void {\n // super.compile(node, scene, ...args);\n // }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Interpolation Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n /**\n * Default compile method for interpolations, which can be overridden by specific implementations if needed.\n * \n * @param interpolation \n * @param scope \n * @param scene \n * @param store \n * @param feature \n */\n @AreCompiler.Compile(AreInterpolation)\n compileInterpolation(\n @A_Inject(A_Caller) interpolation: AreInterpolation,\n @A_Inject(AreScene) scene: AreScene,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n // if (scene.host)\n // console.log('Scene Host: ', scene.host);\n\n // let content = '';\n\n // logger?.debug('green', `AreHTMLCompiler: compile interpolation <${interpolation.aseid.toString()}> with key: \"${interpolation.content}\"`, store.get(interpolation.content));\n\n // try {\n // content = AreCommonHelper.evaluate(interpolation.content, store);\n\n // } catch (error) {\n // content = ''\n // }\n\n scene.plan(new AddTextInstruction({ content: interpolation.content, evaluate: true }));\n }\n\n // -----------------------------------------------------------------------------------------\n // ------------------------------Are-Text Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n @AreCompiler.Compile(AreText)\n compileText(\n @A_Inject(A_Caller) text: AreText,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n logger?.debug('cyan', `AreHTMLCompiler: compile text node <${text.aseid.toString()}> with content: \"${text.content}\"`);\n if (scene.host)\n scene.unPlan(scene.host);\n\n scene.plan(new AddTextInstruction({ content: text.content }));\n\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Attribute Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n\n @AreCompiler.Compile(AreStaticAttribute)\n compileStaticAttribute(\n @A_Inject(A_Caller) attribute: AreStaticAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n const content = attribute.content;\n\n /**\n * If the attribute value contains {{ }} interpolations, transform them into\n * a JS string-concatenation expression so the interpreter can evaluate them.\n * e.g. \"color:{{expr}}\" → '\"color:\"+(expr)+\"\"'\n */\n if (content.includes('{{')) {\n const transformed = '\"' + content.replace(/\\{\\{([^}]+)\\}\\}/g, '\"+($1)+\"') + '\"';\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: transformed,\n evaluate: true,\n }));\n return;\n }\n\n /**\n * Default case: regular static attribute rendered as-is.\n */\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content\n }));\n }\n\n @AreCompiler.Compile(AreDirectiveAttribute)\n compileDirectiveAttribute(\n @A_Inject(A_Caller) directive: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Feature) feature: A_Feature,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n store.watch(directive);\n\n /**\n * 3. If the attribute is a directive, then we should find a component that is responsible for\n * the directive compiling logic, and call it. \n * In case component is not found we just want to log a warning, \n * since the directive may be handled by some parent component or simply is a mistake in the template.\n */\n if (directive.component) {\n feature.chain(directive.component, AreDirectiveFeatures.Compile, directive.owner.scope);\n } else {\n logger?.warning(`Directive handler component not found for directive: ${directive.name}. Make sure to create a component named \"AreDirective${A_FormatterHelper.toPascalCase(directive.name)}\" to handle this directive.`);\n }\n\n store.unwatch(directive);\n }\n\n\n @AreCompiler.Compile(AreEventAttribute)\n compileEventAttribute(\n @A_Inject(A_Caller) attribute: AreEventAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n /**\n * 2. In case the attribute is an event listener, then \n * we should simply add a callback handler that will be used to proxy an event \n * into the ComponentNode component. \n *[!] In this case AreAttribute is AreEventAttribute that has prepared callback function to be used \n * in the event listener. It is important to store callback function once \n * to prevent duplicated functions in case of multiple compilations during development.\n */\n scene.plan(new AddListenerInstruction(scene.host, {\n name: attribute.name,\n handler: attribute.content\n }));\n }\n\n\n @AreCompiler.Compile(AreBindingAttribute)\n compileBindingAttribute(\n @A_Inject(A_Caller) attribute: AreBindingAttribute,\n @A_Inject(AreScene) scene: AreScene,\n @A_Dependency.Parent()\n @A_Inject(AreStore) parentStore: AreStore,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n\n const node = attribute.owner;\n const props = node.component?.props;\n\n // Component prop names are typically declared in camelCase, while template\n // markup uses kebab-case. Try both forms when matching.\n let propName: string | undefined;\n if (props) {\n if (props[attribute.name]) {\n propName = attribute.name;\n } else {\n const camel = A_FormatterHelper.toCamelCase(attribute.name);\n if (props[camel]) propName = camel;\n }\n }\n\n /**\n * 1. Component prop binding — evaluate against the parent store and\n * keep the child store reactive to upstream changes.\n */\n if (propName && props) {\n const propDefinition = props[propName];\n\n const coerce = (raw: any): any => {\n let value = raw;\n if (propDefinition.type) {\n switch (propDefinition.type) {\n case 'string': value = value === undefined || value === null ? '' : String(value); break;\n case 'number': value = Number(value); break;\n case 'boolean': value = Boolean(value); break;\n }\n }\n return value;\n };\n\n // The watcher entity below is registered against parentStore so that\n // updates to the bound expression in the parent flow into the child store.\n const watcher = {\n update: () => {\n try {\n parentStore.watch(watcher);\n const next = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n store.set(propName!, next);\n } catch (e) {\n parentStore.unwatch(watcher);\n }\n }\n };\n\n // Initial read with watch active so dependencies are recorded.\n parentStore.watch(watcher);\n const initial = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n\n store.set(propName, initial);\n return;\n }\n\n /**\n * 2. Default attribute binding — evaluated reactively against the local store.\n */\n const instruction = new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content,\n evaluate: true\n })\n\n scene.plan(instruction);\n }\n\n\n}"]}
1
+ {"version":3,"sources":["../../../src/engine/AreHTML.compiler.ts"],"names":["AreHTMLCompiler","AreCompiler","AddStyleInstruction","AddTextInstruction","AreCompilerError","AddAttributeInstruction","AreDirectiveFeatures","A_FormatterHelper","AddListenerInstruction","AreHTMLNode","A_Caller","AreScene","A_Logger","AreInterpolation","AreStore","AreText","AreStaticAttribute","AreDirectiveAttribute","A_Feature","AreEventAttribute","AreBindingAttribute","AreSyntax","A_Frame"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwBaA,uBAAA,GAAN,8BAA8BC,eAAA,CAAY;AAAA,EAS7C,eAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACC;AACJ,IAAA,KAAA,CAAM,OAAA,CAAQ,IAAA,EAAM,KAAA,EAAO,MAAA,EAAQ,GAAG,IAAI,CAAA;AAE1C,IAAA,IAAI,IAAA,CAAK,QAAQ,MAAA,EAAQ;AACrB,MAAA,MAAM,OAAO,KAAA,CAAM,IAAA;AACnB,MAAA,IAAI,IAAA,EAAM;AACN,QAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,wCAAA,CAAoB,IAAA,EAAM,EAAE,QAAQ,IAAA,CAAK,MAAA,CAAO,MAAA,EAAQ,CAAC,CAAA;AAAA,MAC5E;AAAA,IACJ;AAAA,EACJ;AAAA,EAeA,oBAAA,CACwB,aAAA,EACA,KAAA,EAEA,KAAA,EACA,WACjB,IAAA,EACL;AAeE,IAAA,KAAA,CAAM,IAAA,CAAK,IAAIC,sCAAA,CAAmB,EAAE,OAAA,EAAS,cAAc,OAAA,EAAS,QAAA,EAAU,IAAA,EAAM,CAAC,CAAA;AAAA,EACzF;AAAA,EAMA,WAAA,CACwB,IAAA,EACA,KAAA,EACA,MAAA,EAAA,GACjB,IAAA,EACL;AACE,IAAA,MAAA,EAAQ,KAAA,CAAM,MAAA,EAAQ,CAAA,oCAAA,EAAuC,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA,iBAAA,EAAoB,IAAA,CAAK,OAAO,CAAA,CAAA,CAAG,CAAA;AACrH,IAAA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,CAAA,CAAA;AAjLSA,uBAAA,GAAN,eAAA,CAAA;AAAA,EAJNsB,aAAQ,MAAA,CAAO;AAAA,IACZ,SAAA,EAAW,YAAA;AAAA,IACX,WAAA,EAAa;AAAA,GAChB;AAAA,CAAA,EACYtB,uBAAA,CAAA","file":"AreHTML.compiler.js","sourcesContent":["import { A_Caller, A_Dependency, A_Feature, A_FormatterHelper, A_Inject } from \"@adaas/a-concept\";\nimport { A_Logger } from \"@adaas/a-utils/a-logger\";\nimport { A_Frame } from \"@adaas/a-frame/core\";\nimport { AreCompiler, AreScene, AreCompilerError, AreStore, AreSyntax } from \"@adaas/are\";\nimport { AreDirectiveAttribute } from \"@adaas/are-html/attributes/AreDirective.attribute\";\nimport { AreStaticAttribute } from \"@adaas/are-html/attributes/AreStatic.attribute\";\nimport { AreDirectiveFeatures } from \"@adaas/are-html/directive/AreDirective.constants\";\nimport { AreEventAttribute } from \"@adaas/are-html/attributes/AreEvent.attribute\";\nimport { AreBindingAttribute } from \"@adaas/are-html/attributes/AreBinding.attribute\";\nimport { AreInterpolation } from \"@adaas/are-html/nodes/AreInterpolation\";\nimport { AreText } from \"@adaas/are-html/nodes/AreText\";\nimport { AddAttributeInstruction} from \"@adaas/are-html/instructions/AddAttribute.instruction\";\nimport { AddTextInstruction} from \"@adaas/are-html/instructions/AddText.instruction\";\nimport { AddListenerInstruction} from \"@adaas/are-html/instructions/AddListener.instruction\";\nimport { AddStyleInstruction } from \"@adaas/are-html/instructions/AddStyle.instruction\";\nimport { AreHTMLNode } from \"@adaas/are-html/node\";\n\n\n\n\n@A_Frame.Define({\n namespace: 'a-are-html',\n description: 'HTML-specific compiler for A-Concept Rendering Engine (ARE) components, extending the base AreCompiler to handle HTML templates, styles, and rendering logic tailored for web environments.'\n})\nexport class AreHTMLCompiler extends AreCompiler {\n\n /**\n * Extends the base compile for all AreHTMLNode instances (elements, components, root nodes).\n * After the standard element/attribute/children instructions are emitted, checks whether\n * the node has a registered AreStyle and plans an AddStyleInstruction so the interpreter\n * can inject the CSS into the document head during mount.\n */\n @AreCompiler.Compile(AreHTMLNode)\n compileHTMLNode(\n @A_Inject(A_Caller) node: AreHTMLNode,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ): void {\n super.compile(node, scene, logger, ...args);\n\n if (node.styles?.styles) {\n const host = scene.host;\n if (host) {\n scene.plan(new AddStyleInstruction(host, { styles: node.styles.styles }));\n }\n }\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Interpolation Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n /**\n * Default compile method for interpolations, which can be overridden by specific implementations if needed.\n * \n * @param interpolation \n * @param scope \n * @param scene \n * @param store \n * @param feature \n */\n @AreCompiler.Compile(AreInterpolation)\n compileInterpolation(\n @A_Inject(A_Caller) interpolation: AreInterpolation,\n @A_Inject(AreScene) scene: AreScene,\n\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n // if (scene.host)\n // console.log('Scene Host: ', scene.host);\n\n // let content = '';\n\n // logger?.debug('green', `AreHTMLCompiler: compile interpolation <${interpolation.aseid.toString()}> with key: \"${interpolation.content}\"`, store.get(interpolation.content));\n\n // try {\n // content = AreCommonHelper.evaluate(interpolation.content, store);\n\n // } catch (error) {\n // content = ''\n // }\n\n scene.plan(new AddTextInstruction({ content: interpolation.content, evaluate: true }));\n }\n\n // -----------------------------------------------------------------------------------------\n // ------------------------------Are-Text Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n @AreCompiler.Compile(AreText)\n compileText(\n @A_Inject(A_Caller) text: AreText,\n @A_Inject(AreScene) scene: AreScene,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n logger?.debug('cyan', `AreHTMLCompiler: compile text node <${text.aseid.toString()}> with content: \"${text.content}\"`);\n if (scene.host)\n scene.unPlan(scene.host);\n\n scene.plan(new AddTextInstruction({ content: text.content }));\n\n }\n\n // -----------------------------------------------------------------------------------------\n // -------------------------Are-Attribute Compile Section-----------------------------------\n // -----------------------------------------------------------------------------------------\n\n @AreCompiler.Compile(AreStaticAttribute)\n compileStaticAttribute(\n @A_Inject(A_Caller) attribute: AreStaticAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n const content = attribute.content;\n\n /**\n * If the attribute value contains {{ }} interpolations, transform them into\n * a JS string-concatenation expression so the interpreter can evaluate them.\n * e.g. \"color:{{expr}}\" → '\"color:\"+(expr)+\"\"'\n */\n if (content.includes('{{')) {\n const transformed = '\"' + content.replace(/\\{\\{([^}]+)\\}\\}/g, '\"+($1)+\"') + '\"';\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: transformed,\n evaluate: true,\n }));\n return;\n }\n\n /**\n * Default case: regular static attribute rendered as-is.\n */\n scene.plan(new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content\n }));\n }\n\n @AreCompiler.Compile(AreDirectiveAttribute)\n compileDirectiveAttribute(\n @A_Inject(A_Caller) directive: AreDirectiveAttribute,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(A_Feature) feature: A_Feature,\n @A_Inject(A_Logger) logger?: A_Logger,\n ...args: any[]\n ) {\n store.watch(directive);\n\n /**\n * 3. If the attribute is a directive, then we should find a component that is responsible for\n * the directive compiling logic, and call it. \n * In case component is not found we just want to log a warning, \n * since the directive may be handled by some parent component or simply is a mistake in the template.\n */\n if (directive.component) {\n feature.chain(directive.component, AreDirectiveFeatures.Compile, directive.owner.scope);\n } else {\n logger?.warning(`Directive handler component not found for directive: ${directive.name}. Make sure to create a component named \"AreDirective${A_FormatterHelper.toPascalCase(directive.name)}\" to handle this directive.`);\n }\n\n store.unwatch(directive);\n }\n\n\n @AreCompiler.Compile(AreEventAttribute)\n compileEventAttribute(\n @A_Inject(A_Caller) attribute: AreEventAttribute,\n @A_Inject(AreScene) scene: AreScene,\n ...args: any[]\n ) {\n\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n /**\n * 2. In case the attribute is an event listener, then \n * we should simply add a callback handler that will be used to proxy an event \n * into the ComponentNode component. \n *[!] In this case AreAttribute is AreEventAttribute that has prepared callback function to be used \n * in the event listener. It is important to store callback function once \n * to prevent duplicated functions in case of multiple compilations during development.\n */\n scene.plan(new AddListenerInstruction(scene.host, {\n name: attribute.name,\n handler: attribute.content\n }));\n }\n\n\n @AreCompiler.Compile(AreBindingAttribute)\n compileBindingAttribute(\n @A_Inject(A_Caller) attribute: AreBindingAttribute,\n @A_Inject(AreScene) scene: AreScene,\n @A_Dependency.Parent()\n @A_Inject(AreStore) parentStore: AreStore,\n @A_Inject(AreStore) store: AreStore,\n @A_Inject(AreSyntax) syntax: AreSyntax,\n ...args: any[]\n ) {\n if (!scene.host)\n throw new AreCompilerError({\n title: 'Scene Host Not Found',\n description: `No host found for the scene with id: ${scene.id}. Please ensure that the scene is properly initialized and has a host before compiling binding attributes.`\n });\n\n\n const node = attribute.owner;\n const props = node.component?.props;\n\n // Component prop names are typically declared in camelCase, while template\n // markup uses kebab-case. Try both forms when matching.\n let propName: string | undefined;\n if (props) {\n if (props[attribute.name]) {\n propName = attribute.name;\n } else {\n const camel = A_FormatterHelper.toCamelCase(attribute.name);\n if (props[camel]) propName = camel;\n }\n }\n\n /**\n * 1. Component prop binding — evaluate against the parent store and\n * keep the child store reactive to upstream changes.\n */\n if (propName && props) {\n const propDefinition = props[propName];\n\n const coerce = (raw: any): any => {\n let value = raw;\n if (propDefinition.type) {\n switch (propDefinition.type) {\n case 'string': value = value === undefined || value === null ? '' : String(value); break;\n case 'number': value = Number(value); break;\n case 'boolean': value = Boolean(value); break;\n }\n }\n return value;\n };\n\n // The watcher entity below is registered against parentStore so that\n // updates to the bound expression in the parent flow into the child store.\n const watcher = {\n update: () => {\n try {\n parentStore.watch(watcher);\n const next = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n store.set(propName!, next);\n } catch (e) {\n parentStore.unwatch(watcher);\n }\n }\n };\n\n // Initial read with watch active so dependencies are recorded.\n parentStore.watch(watcher);\n const initial = coerce(syntax.evaluate(attribute.content, parentStore));\n parentStore.unwatch(watcher);\n\n store.set(propName, initial);\n return;\n }\n\n /**\n * 2. Default attribute binding — evaluated reactively against the local store.\n */\n const instruction = new AddAttributeInstruction(scene.host, {\n name: attribute.name,\n content: attribute.content,\n evaluate: true\n })\n\n scene.plan(instruction);\n }\n\n\n}"]}