@repobit/dex-store-elements 1.7.2 → 2.0.0

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 (227) hide show
  1. package/CHANGELOG.md +5 -905
  2. package/README.md +9 -7
  3. package/dist/src/actions/action.adapter.d.ts +36 -0
  4. package/dist/src/actions/action.adapter.js +183 -0
  5. package/dist/src/actions/action.adapter.js.map +1 -0
  6. package/dist/src/actions/action.attributes.d.ts +15 -0
  7. package/dist/src/actions/action.attributes.js +137 -0
  8. package/dist/src/actions/action.attributes.js.map +1 -0
  9. package/dist/src/actions/action.registry.d.ts +4 -0
  10. package/dist/src/actions/action.registry.js +119 -0
  11. package/dist/src/actions/action.registry.js.map +1 -0
  12. package/dist/src/actions/index.d.ts +3 -2
  13. package/dist/src/actions/index.js +3 -80
  14. package/dist/src/actions/index.js.map +1 -1
  15. package/dist/src/compute/compute.expand.d.ts +70 -0
  16. package/dist/src/compute/compute.expand.js +319 -0
  17. package/dist/src/compute/compute.expand.js.map +1 -0
  18. package/dist/src/compute/compute.scan.d.ts +54 -0
  19. package/dist/src/compute/compute.scan.js +160 -0
  20. package/dist/src/compute/compute.scan.js.map +1 -0
  21. package/dist/src/compute/option-resolver.d.ts +31 -0
  22. package/dist/src/compute/option-resolver.js +147 -0
  23. package/dist/src/compute/option-resolver.js.map +1 -0
  24. package/dist/src/contexts/context.compute.d.ts +12 -0
  25. package/dist/src/contexts/context.compute.js +4 -0
  26. package/dist/src/contexts/context.compute.js.map +1 -0
  27. package/dist/src/contexts/context.scope.d.ts +139 -0
  28. package/dist/src/contexts/context.scope.js +48 -0
  29. package/dist/src/contexts/context.scope.js.map +1 -0
  30. package/dist/src/controllers/controller.action-resolve.d.ts +110 -0
  31. package/dist/src/controllers/controller.action-resolve.js +203 -0
  32. package/dist/src/controllers/controller.action-resolve.js.map +1 -0
  33. package/dist/src/controllers/controller.action-topology.d.ts +59 -0
  34. package/dist/src/controllers/controller.action-topology.js +130 -0
  35. package/dist/src/controllers/controller.action-topology.js.map +1 -0
  36. package/dist/src/controllers/controller.compute.d.ts +72 -0
  37. package/dist/src/controllers/controller.compute.js +110 -0
  38. package/dist/src/controllers/controller.compute.js.map +1 -0
  39. package/dist/src/controllers/controller.resolve.d.ts +78 -0
  40. package/dist/src/controllers/controller.resolve.js +205 -0
  41. package/dist/src/controllers/controller.resolve.js.map +1 -0
  42. package/dist/src/core/action-topology.d.ts +62 -0
  43. package/dist/src/core/action-topology.js +67 -0
  44. package/dist/src/core/action-topology.js.map +1 -0
  45. package/dist/src/core/actions.d.ts +64 -0
  46. package/dist/src/core/actions.js +47 -0
  47. package/dist/src/core/actions.js.map +1 -0
  48. package/dist/src/core/node.element.d.ts +179 -0
  49. package/dist/src/core/node.element.js +573 -0
  50. package/dist/src/core/node.element.js.map +1 -0
  51. package/dist/src/core/node.scope.d.ts +374 -0
  52. package/dist/src/core/node.scope.js +558 -0
  53. package/dist/src/core/node.scope.js.map +1 -0
  54. package/dist/src/core/option-update.d.ts +11 -0
  55. package/dist/src/core/option-update.js +59 -0
  56. package/dist/src/core/option-update.js.map +1 -0
  57. package/dist/src/dsl/compilers/array/compiler.js +13 -14
  58. package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
  59. package/dist/src/dsl/compilers/boolean/compiler.d.ts +1 -1
  60. package/dist/src/dsl/compilers/boolean/compiler.js +14 -27
  61. package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
  62. package/dist/src/dsl/compilers/enum/compiler.js +7 -10
  63. package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
  64. package/dist/src/dsl/compilers/index.d.ts +1 -1
  65. package/dist/src/dsl/compilers/index.js +5 -5
  66. package/dist/src/dsl/compilers/index.js.map +1 -1
  67. package/dist/src/dsl/utilty.d.ts +0 -4
  68. package/dist/src/dsl/utilty.js +3 -30
  69. package/dist/src/dsl/utilty.js.map +1 -1
  70. package/dist/src/eta/batch.d.ts +123 -0
  71. package/dist/src/eta/batch.js +162 -0
  72. package/dist/src/eta/batch.js.map +1 -0
  73. package/dist/src/eta/batcher.d.ts +184 -0
  74. package/dist/src/eta/batcher.js +335 -0
  75. package/dist/src/eta/batcher.js.map +1 -0
  76. package/dist/src/eta/cache.d.ts +36 -0
  77. package/dist/src/eta/cache.js +56 -0
  78. package/dist/src/eta/cache.js.map +1 -0
  79. package/dist/src/eta/controller.d.ts +608 -0
  80. package/dist/src/eta/controller.js +1036 -0
  81. package/dist/src/eta/controller.js.map +1 -0
  82. package/dist/src/eta/factory.d.ts +74 -0
  83. package/dist/src/eta/factory.js +121 -0
  84. package/dist/src/eta/factory.js.map +1 -0
  85. package/dist/src/eta/idle.d.ts +39 -0
  86. package/dist/src/eta/idle.js +52 -0
  87. package/dist/src/eta/idle.js.map +1 -0
  88. package/dist/src/eta/index.d.ts +52 -0
  89. package/dist/src/eta/index.js +13 -0
  90. package/dist/src/eta/index.js.map +1 -0
  91. package/dist/src/eta/observer.d.ts +263 -0
  92. package/dist/src/eta/observer.js +263 -0
  93. package/dist/src/eta/observer.js.map +1 -0
  94. package/dist/src/eta/operations.d.ts +41 -0
  95. package/dist/src/eta/operations.js +59 -0
  96. package/dist/src/eta/operations.js.map +1 -0
  97. package/dist/src/eta/source-registry.d.ts +198 -0
  98. package/dist/src/eta/source-registry.js +267 -0
  99. package/dist/src/eta/source-registry.js.map +1 -0
  100. package/dist/src/eta/template-index.d.ts +285 -0
  101. package/dist/src/eta/template-index.js +642 -0
  102. package/dist/src/eta/template-index.js.map +1 -0
  103. package/dist/src/eta/types.d.ts +529 -0
  104. package/dist/src/eta/types.js +2 -0
  105. package/dist/src/eta/types.js.map +1 -0
  106. package/dist/src/index.d.ts +21 -9
  107. package/dist/src/index.js +22 -11
  108. package/dist/src/index.js.map +1 -1
  109. package/dist/src/nodes/node.context.d.ts +5 -3
  110. package/dist/src/nodes/node.context.js +48 -3
  111. package/dist/src/nodes/node.context.js.map +1 -1
  112. package/dist/src/nodes/node.option.d.ts +11 -31
  113. package/dist/src/nodes/node.option.js +158 -222
  114. package/dist/src/nodes/node.option.js.map +1 -1
  115. package/dist/src/nodes/node.product.d.ts +7 -11
  116. package/dist/src/nodes/node.product.js +85 -64
  117. package/dist/src/nodes/node.product.js.map +1 -1
  118. package/dist/src/renders/attributes/buyLink.d.ts +2 -2
  119. package/dist/src/renders/attributes/buyLink.js +14 -11
  120. package/dist/src/renders/attributes/buyLink.js.map +1 -1
  121. package/dist/src/renders/attributes/devices.d.ts +2 -2
  122. package/dist/src/renders/attributes/devices.js +9 -19
  123. package/dist/src/renders/attributes/devices.js.map +1 -1
  124. package/dist/src/renders/attributes/discount.d.ts +2 -2
  125. package/dist/src/renders/attributes/discount.js +56 -44
  126. package/dist/src/renders/attributes/discount.js.map +1 -1
  127. package/dist/src/renders/attributes/hide.d.ts +2 -2
  128. package/dist/src/renders/attributes/hide.js +49 -14
  129. package/dist/src/renders/attributes/hide.js.map +1 -1
  130. package/dist/src/renders/attributes/index.d.ts +3 -3
  131. package/dist/src/renders/attributes/index.js +2 -4
  132. package/dist/src/renders/attributes/index.js.map +1 -1
  133. package/dist/src/renders/attributes/price.d.ts +2 -2
  134. package/dist/src/renders/attributes/price.js +30 -44
  135. package/dist/src/renders/attributes/price.js.map +1 -1
  136. package/dist/src/renders/attributes/subscription.d.ts +2 -2
  137. package/dist/src/renders/attributes/subscription.js +14 -20
  138. package/dist/src/renders/attributes/subscription.js.map +1 -1
  139. package/dist/src/renders/attributes/utilty.d.ts +2 -0
  140. package/dist/src/renders/attributes/utilty.js +17 -4
  141. package/dist/src/renders/attributes/utilty.js.map +1 -1
  142. package/dist/src/renders/context.d.ts +122 -10
  143. package/dist/src/renders/context.js +140 -80
  144. package/dist/src/renders/context.js.map +1 -1
  145. package/dist/src/renders/format.js +2 -2
  146. package/dist/src/renders/format.js.map +1 -1
  147. package/dist/src/renders/index.d.ts +6 -2
  148. package/dist/src/renders/index.js +67 -29
  149. package/dist/src/renders/index.js.map +1 -1
  150. package/dist/src/renders/observe.d.ts +1 -4
  151. package/dist/src/renders/observe.js +10 -24
  152. package/dist/src/renders/observe.js.map +1 -1
  153. package/dist/src/renders/render.wrapper.d.ts +37 -0
  154. package/dist/src/renders/render.wrapper.js +147 -0
  155. package/dist/src/renders/render.wrapper.js.map +1 -0
  156. package/dist/src/templating/eta.js +1 -4
  157. package/dist/src/templating/eta.js.map +1 -1
  158. package/package.json +4 -5
  159. package/dist/src/actions/action.button.d.ts +0 -2
  160. package/dist/src/actions/action.button.js +0 -8
  161. package/dist/src/actions/action.button.js.map +0 -1
  162. package/dist/src/actions/action.input.d.ts +0 -2
  163. package/dist/src/actions/action.input.js +0 -43
  164. package/dist/src/actions/action.input.js.map +0 -1
  165. package/dist/src/actions/action.select.d.ts +0 -2
  166. package/dist/src/actions/action.select.js +0 -14
  167. package/dist/src/actions/action.select.js.map +0 -1
  168. package/dist/src/actions/utilty.d.ts +0 -16
  169. package/dist/src/actions/utilty.js +0 -149
  170. package/dist/src/actions/utilty.js.map +0 -1
  171. package/dist/src/contexts/context.datalayer.d.ts +0 -9
  172. package/dist/src/contexts/context.datalayer.js +0 -3
  173. package/dist/src/contexts/context.datalayer.js.map +0 -1
  174. package/dist/src/contexts/context.derived.d.ts +0 -12
  175. package/dist/src/contexts/context.derived.js +0 -3
  176. package/dist/src/contexts/context.derived.js.map +0 -1
  177. package/dist/src/contexts/context.option.d.ts +0 -5
  178. package/dist/src/contexts/context.option.js +0 -3
  179. package/dist/src/contexts/context.option.js.map +0 -1
  180. package/dist/src/contexts/context.product.d.ts +0 -5
  181. package/dist/src/contexts/context.product.js +0 -3
  182. package/dist/src/contexts/context.product.js.map +0 -1
  183. package/dist/src/contexts/context.state.d.ts +0 -28
  184. package/dist/src/contexts/context.state.js +0 -3
  185. package/dist/src/contexts/context.state.js.map +0 -1
  186. package/dist/src/contexts/context.store.d.ts +0 -5
  187. package/dist/src/contexts/context.store.js +0 -3
  188. package/dist/src/contexts/context.store.js.map +0 -1
  189. package/dist/src/controllers/collect-controller.d.ts +0 -39
  190. package/dist/src/controllers/collect-controller.js +0 -161
  191. package/dist/src/controllers/collect-controller.js.map +0 -1
  192. package/dist/src/controllers/compute-controller.d.ts +0 -55
  193. package/dist/src/controllers/compute-controller.js +0 -350
  194. package/dist/src/controllers/compute-controller.js.map +0 -1
  195. package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +0 -25
  196. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +0 -192
  197. package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +0 -1
  198. package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +0 -28
  199. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +0 -206
  200. package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +0 -1
  201. package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +0 -21
  202. package/dist/src/controllers/eta-renderer/eta-renderer.js +0 -77
  203. package/dist/src/controllers/eta-renderer/eta-renderer.js.map +0 -1
  204. package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +0 -24
  205. package/dist/src/controllers/eta-renderer/eta-template-cache.js +0 -61
  206. package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +0 -1
  207. package/dist/src/controllers/eta-renderer/eta-types.d.ts +0 -11
  208. package/dist/src/controllers/eta-renderer/eta-types.js +0 -1
  209. package/dist/src/controllers/eta-renderer/eta-types.js.map +0 -1
  210. package/dist/src/controllers/eta-renderer/index.d.ts +0 -2
  211. package/dist/src/controllers/eta-renderer/index.js +0 -2
  212. package/dist/src/controllers/eta-renderer/index.js.map +0 -1
  213. package/dist/src/controllers/event-pipeline-controller.d.ts +0 -28
  214. package/dist/src/controllers/event-pipeline-controller.js +0 -72
  215. package/dist/src/controllers/event-pipeline-controller.js.map +0 -1
  216. package/dist/src/events/events.d.ts +0 -75
  217. package/dist/src/events/events.js +0 -78
  218. package/dist/src/events/events.js.map +0 -1
  219. package/dist/src/nodes/node.root.d.ts +0 -16
  220. package/dist/src/nodes/node.root.js +0 -49
  221. package/dist/src/nodes/node.root.js.map +0 -1
  222. package/dist/src/nodes/node.state.d.ts +0 -88
  223. package/dist/src/nodes/node.state.js +0 -330
  224. package/dist/src/nodes/node.state.js.map +0 -1
  225. package/dist/src/renders/utility.d.ts +0 -32
  226. package/dist/src/renders/utility.js +0 -191
  227. package/dist/src/renders/utility.js.map +0 -1
@@ -1,28 +1,63 @@
1
1
  import { Compiler } from '../../dsl/compilers/index.js';
2
2
  import { toDSLContext } from '../context.js';
3
- const normalizeHideMode = (mode) => {
4
- if (mode === 'opacity' || mode === 'visibility')
3
+ const HIDE_MODES = new WeakMap();
4
+ function normalizeHideMode(mode) {
5
+ if (mode === 'opacity' ||
6
+ mode === 'visibility') {
5
7
  return mode;
8
+ }
6
9
  return 'display';
7
- };
8
- const applyHideMode = (el, mode, hide) => {
10
+ }
11
+ function applyHideMode(el, mode, hide) {
12
+ const previousMode = HIDE_MODES.get(el);
13
+ if (previousMode &&
14
+ previousMode !== mode) {
15
+ resetHideMode(el, previousMode);
16
+ }
17
+ if (!hide) {
18
+ resetHideMode(el, mode);
19
+ HIDE_MODES.delete(el);
20
+ return;
21
+ }
22
+ HIDE_MODES.set(el, mode);
9
23
  if (mode === 'opacity') {
10
- el.style.opacity = hide ? '0' : '';
24
+ el.style.opacity = '0';
11
25
  return;
12
26
  }
13
27
  if (mode === 'visibility') {
14
- el.style.visibility = hide ? 'hidden' : '';
28
+ el.style.visibility = 'hidden';
15
29
  return;
16
30
  }
17
- el.style.display = hide ? 'none' : '';
18
- };
19
- export const handleHide = async (el, ctx) => {
31
+ el.style.display = 'none';
32
+ }
33
+ function resetHideMode(el, mode) {
34
+ if (mode === 'opacity') {
35
+ el.style.opacity = '';
36
+ return;
37
+ }
38
+ if (mode === 'visibility') {
39
+ el.style.visibility = '';
40
+ return;
41
+ }
42
+ el.style.display = '';
43
+ }
44
+ function resetAppliedHideMode(el) {
45
+ const previousMode = HIDE_MODES.get(el);
46
+ if (!previousMode) {
47
+ return;
48
+ }
49
+ resetHideMode(el, previousMode);
50
+ HIDE_MODES.delete(el);
51
+ }
52
+ export const handleHide = (el, ctx) => {
20
53
  const { storeHide, storeHideType } = el.dataset;
21
- if (!storeHide)
54
+ if (!storeHide) {
55
+ resetAppliedHideMode(el);
22
56
  return;
23
- const dslCtx = await toDSLContext(ctx);
24
- const hide = Compiler.boolean({ expr: storeHide, ctx: dslCtx });
25
- const mode = normalizeHideMode(storeHideType);
26
- applyHideMode(el, mode, hide);
57
+ }
58
+ applyHideMode(el, normalizeHideMode(storeHideType), Compiler.boolean({
59
+ expr: storeHide,
60
+ ctx: toDSLContext(ctx)
61
+ }));
27
62
  };
28
63
  //# sourceMappingURL=hide.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hide.js","sourceRoot":"","sources":["../../../../src/renders/attributes/hide.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAI1C,MAAM,iBAAiB,GAAG,CAAC,IAAa,EAAY,EAAE;IACpD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,YAAY;QAAE,OAAO,IAAI,CAAC;IAC7D,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,CAAC,EAAe,EAAE,IAAc,EAAE,IAAa,EAAE,EAAE;IACvE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,OAAO;IACT,CAAC;IAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAC1B,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3C,OAAO;IACT,CAAC;IAED,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAE,EAAe,EAAE,GAAmB,EAAE,EAAE;IACvE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IAChD,IAAI,CAAC,SAAS;QAAE,OAAO;IAEvB,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,GAAG,CAAC,CAAC;IACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IAChE,MAAM,IAAI,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAE9C,aAAa,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport type { UnifiedContext } from '../context';\nimport { toDSLContext } from '../context';\n\ntype HideMode = 'display' | 'opacity' | 'visibility';\n\nconst normalizeHideMode = (mode?: string): HideMode => {\n if (mode === 'opacity' || mode === 'visibility') return mode;\n return 'display';\n};\n\nconst applyHideMode = (el: HTMLElement, mode: HideMode, hide: boolean) => {\n if (mode === 'opacity') {\n el.style.opacity = hide ? '0' : '';\n return;\n }\n\n if (mode === 'visibility') {\n el.style.visibility = hide ? 'hidden' : '';\n return;\n }\n\n el.style.display = hide ? 'none' : '';\n};\n\nexport const handleHide = async (el: HTMLElement, ctx: UnifiedContext) => {\n const { storeHide, storeHideType } = el.dataset;\n if (!storeHide) return;\n\n const dslCtx = await toDSLContext(ctx);\n const hide = Compiler.boolean({ expr: storeHide, ctx: dslCtx });\n const mode = normalizeHideMode(storeHideType);\n\n applyHideMode(el, mode, hide);\n};\n"]}
1
+ {"version":3,"file":"hide.js","sourceRoot":"","sources":["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,OAAO;IACT,CAAC;IAED,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;QAC1B,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,EAAE,CAAC;QACzB,OAAO;IACT,CAAC;IAED,EAAE,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;AACxB,CAAC;AAED,SAAS,oBAAoB,CAC3B,EAAe;IAEf,MAAM,YAAY,GAAG,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAExC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO;IACT,CAAC;IAED,aAAa,CACX,EAAE,EACF,YAAY,CACb,CAAC;IACF,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,SAAS,EACT,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IAEf,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,oBAAoB,CAAC,EAAE,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,aAAa,CACX,EAAE,EACF,iBAAiB,CAAC,aAAa,CAAC,EAChC,QAAQ,CAAC,OAAO,CAAC;QACf,IAAI,EAAE,SAAS;QACf,GAAG,EAAG,YAAY,CAAC,GAAG,CAAC;KACxB,CAAC,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport type { RenderContext } from '../context.js';\nimport { toDSLContext } from '../context.js';\n\ntype HideMode = 'display' | 'opacity' | 'visibility';\n\nconst HIDE_MODES = new WeakMap<HTMLElement, HideMode>();\n\nfunction normalizeHideMode(\n mode?: string\n): HideMode {\n if (\n mode === 'opacity' ||\n mode === 'visibility'\n ) {\n return mode;\n }\n\n return 'display';\n}\n\nfunction applyHideMode(\n el: HTMLElement,\n mode: HideMode,\n hide: boolean\n): void {\n const previousMode = HIDE_MODES.get(el);\n\n if (\n previousMode &&\n previousMode !== mode\n ) {\n resetHideMode(\n el,\n previousMode\n );\n }\n\n if (!hide) {\n resetHideMode(\n el,\n mode\n );\n HIDE_MODES.delete(el);\n return;\n }\n\n HIDE_MODES.set(\n el,\n mode\n );\n\n if (mode === 'opacity') {\n el.style.opacity = '0';\n return;\n }\n\n if (mode === 'visibility') {\n el.style.visibility = 'hidden';\n return;\n }\n\n el.style.display = 'none';\n}\n\nfunction resetHideMode(\n el: HTMLElement,\n mode: HideMode\n): void {\n if (mode === 'opacity') {\n el.style.opacity = '';\n return;\n }\n\n if (mode === 'visibility') {\n el.style.visibility = '';\n return;\n }\n\n el.style.display = '';\n}\n\nfunction resetAppliedHideMode(\n el: HTMLElement\n): void {\n const previousMode = HIDE_MODES.get(el);\n\n if (!previousMode) {\n return;\n }\n\n resetHideMode(\n el,\n previousMode\n );\n HIDE_MODES.delete(el);\n}\n\nexport const handleHide = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeHide,\n storeHideType\n } = el.dataset;\n\n if (!storeHide) {\n resetAppliedHideMode(el);\n return;\n }\n\n applyHideMode(\n el,\n normalizeHideMode(storeHideType),\n Compiler.boolean({\n expr: storeHide,\n ctx : toDSLContext(ctx)\n })\n );\n};\n"]}
@@ -1,3 +1,3 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export type AttributeHandler = (el: HTMLElement, ctx: UnifiedContext) => void | Promise<void>;
3
- export declare const renderAttributes: (el: HTMLElement, ctx: UnifiedContext) => Promise<void>;
1
+ import type { RenderContext } from '../context.js';
2
+ export type AttributeHandler = (el: HTMLElement, ctx: RenderContext) => void | Promise<void>;
3
+ export declare const renderAttributes: (el: HTMLElement, ctx: RenderContext) => Promise<void>;
@@ -4,7 +4,6 @@ import { handleDiscount } from './discount.js';
4
4
  import { handleHide } from './hide.js';
5
5
  import { handlePrice } from './price.js';
6
6
  import { handleSubscription } from './subscription.js';
7
- // Dispatch known attribute handlers. Order matters for conflicts; keep hide last.
8
7
  const handlers = [
9
8
  handleDevices,
10
9
  handleSubscription,
@@ -12,11 +11,10 @@ const handlers = [
12
11
  handlePrice,
13
12
  handleDiscount,
14
13
  handleHide
15
- // further handlers (devices, subscription, links) will be pushed here
16
14
  ];
17
15
  export const renderAttributes = async (el, ctx) => {
18
- for (const h of handlers) {
19
- await h(el, ctx);
16
+ for (const handler of handlers) {
17
+ await handler(el, ctx);
20
18
  }
21
19
  };
22
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renders/attributes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAIpD,kFAAkF;AAClF,MAAM,QAAQ,GAAuB;IACnC,aAAa;IACb,kBAAkB;IAClB,aAAa;IACb,WAAW;IACX,cAAc;IACd,UAAU;IACV,sEAAsE;CACvE,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EAAE,EAAe,EAAE,GAAmB,EAAE,EAAE;IAC7E,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,MAAM,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;IACnB,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { UnifiedContext } from '../context';\nimport { handleBuyLink } from './buyLink';\nimport { handleDevices } from './devices';\nimport { handleDiscount } from './discount';\nimport { handleHide } from './hide';\nimport { handlePrice } from './price';\nimport { handleSubscription } from './subscription';\n\nexport type AttributeHandler = (el: HTMLElement, ctx: UnifiedContext) => void | Promise<void>;\n\n// Dispatch known attribute handlers. Order matters for conflicts; keep hide last.\nconst handlers: AttributeHandler[] = [\n handleDevices,\n handleSubscription,\n handleBuyLink,\n handlePrice,\n handleDiscount,\n handleHide\n // further handlers (devices, subscription, links) will be pushed here\n];\n\nexport const renderAttributes = async (el: HTMLElement, ctx: UnifiedContext) => {\n for (const h of handlers) {\n await h(el, ctx);\n }\n};\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/renders/attributes/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAOvD,MAAM,QAAQ,GAAuB;IACnC,aAAa;IACb,kBAAkB;IAClB,aAAa;IACb,WAAW;IACX,cAAc;IACd,UAAU;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,EACnC,EAAe,EACf,GAAkB,EACH,EAAE;IACjB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,OAAO,CACX,EAAE,EACF,GAAG,CACJ,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { RenderContext } from '../context.js';\nimport { handleBuyLink } from './buyLink.js';\nimport { handleDevices } from './devices.js';\nimport { handleDiscount } from './discount.js';\nimport { handleHide } from './hide.js';\nimport { handlePrice } from './price.js';\nimport { handleSubscription } from './subscription.js';\n\nexport type AttributeHandler = (\n el: HTMLElement,\n ctx: RenderContext\n) => void | Promise<void>;\n\nconst handlers: AttributeHandler[] = [\n handleDevices,\n handleSubscription,\n handleBuyLink,\n handlePrice,\n handleDiscount,\n handleHide\n];\n\nexport const renderAttributes = async (\n el: HTMLElement,\n ctx: RenderContext\n): Promise<void> => {\n for (const handler of handlers) {\n await handler(\n el,\n ctx\n );\n }\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handlePrice: (el: HTMLElement, ctx: UnifiedContext) => void;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handlePrice: (el: HTMLElement, ctx: RenderContext) => void;
@@ -1,7 +1,13 @@
1
1
  import { Compiler } from '../../dsl/compilers/index.js';
2
+ import { getDiscountedPrice } from '../context.js';
2
3
  import { isPresent } from './utilty.js';
3
- const OPTION_PRICE_TOKENS = ['full', 'discounted', 'full-monthly', 'discounted-monthly'];
4
- const STATE_PRICE_TOKENS = [
4
+ const OPTION_PRICE_TOKENS = [
5
+ 'full',
6
+ 'discounted',
7
+ 'full-monthly',
8
+ 'discounted-monthly'
9
+ ];
10
+ const COMPUTE_PRICE_TOKENS = [
5
11
  'min-full',
6
12
  'max-full',
7
13
  'min-discounted',
@@ -11,64 +17,44 @@ const STATE_PRICE_TOKENS = [
11
17
  'min-discounted-monthly',
12
18
  'max-discounted-monthly'
13
19
  ];
14
- const OPTION_PRICE_AVAILABLE = {
15
- 'full': (option) => isPresent(option.getPrice({ currency: false })),
16
- 'discounted': (option) => isPresent(option.getDiscountedPrice({ currency: false })),
17
- 'full-monthly': (option) => isPresent(option.getPrice({ currency: false, monthly: true })),
18
- 'discounted-monthly': (option) => isPresent(option.getDiscountedPrice({ currency: false, monthly: true }))
19
- };
20
- const OPTION_PRICE_RENDER = {
21
- 'full': (option) => option.getPrice(),
22
- 'discounted': (option) => option.getDiscountedPrice(),
23
- 'full-monthly': (option) => option.getPrice({ monthly: true }),
24
- 'discounted-monthly': (option) => option.getDiscountedPrice({ monthly: true })
25
- };
26
- const STATE_PRICE_AVAILABLE = {
27
- 'min-full': (state) => Boolean(state.price.min.fmt),
28
- 'max-full': (state) => Boolean(state.price.max.fmt),
29
- 'min-full-monthly': (state) => Boolean(state.price.monthly.min.fmt),
30
- 'max-full-monthly': (state) => Boolean(state.price.monthly.max.fmt),
31
- 'min-discounted': (state) => Boolean(state.discountedPrice.min.fmt),
32
- 'max-discounted': (state) => Boolean(state.discountedPrice.max.fmt),
33
- 'min-discounted-monthly': (state) => Boolean(state.discountedPrice.monthly.min.fmt),
34
- 'max-discounted-monthly': (state) => Boolean(state.discountedPrice.monthly.max.fmt)
35
- };
36
- const STATE_PRICE_RENDER = {
37
- 'min-full': (state) => state.price.min.fmt,
38
- 'max-full': (state) => state.price.max.fmt,
39
- 'min-full-monthly': (state) => state.price.monthly.min.fmt,
40
- 'max-full-monthly': (state) => state.price.monthly.max.fmt,
41
- 'min-discounted': (state) => state.discountedPrice.min.fmt,
42
- 'max-discounted': (state) => state.discountedPrice.max.fmt,
43
- 'min-discounted-monthly': (state) => state.discountedPrice.monthly.min.fmt,
44
- 'max-discounted-monthly': (state) => state.discountedPrice.monthly.max.fmt
45
- };
46
- // Handles both data-store-price (option-level) and data-store-context-price (state-level)
47
20
  export const handlePrice = (el, ctx) => {
48
21
  const { storePrice, storeContextPrice } = el.dataset;
49
22
  const option = ctx.option;
50
- // Option-level price
51
23
  if (storePrice && option) {
24
+ const renderers = {
25
+ 'full': () => option.getPrice(),
26
+ 'discounted': () => getDiscountedPrice(option),
27
+ 'full-monthly': () => option.getPrice({ monthly: true }),
28
+ 'discounted-monthly': () => getDiscountedPrice(option, { monthly: true })
29
+ };
52
30
  const chosen = Compiler.enum({
53
31
  expr: storePrice,
54
32
  allowed: OPTION_PRICE_TOKENS,
55
- isAvailable: (token) => OPTION_PRICE_AVAILABLE[token](option)
33
+ isAvailable: (token) => isPresent(renderers[token]())
56
34
  });
57
35
  if (chosen) {
58
- el.textContent = OPTION_PRICE_RENDER[chosen](option);
36
+ el.textContent = renderers[chosen]() ?? '';
59
37
  return;
60
38
  }
61
39
  }
62
- const state = ctx.state;
63
- // State-level price
64
- if (storeContextPrice && state) {
40
+ if (storeContextPrice && ctx.compute) {
41
+ const renderers = {
42
+ 'min-full': () => ctx.compute?.price.min.fmt,
43
+ 'max-full': () => ctx.compute?.price.max.fmt,
44
+ 'min-discounted': () => ctx.compute?.discountedPrice.min.fmt,
45
+ 'max-discounted': () => ctx.compute?.discountedPrice.max.fmt,
46
+ 'min-full-monthly': () => ctx.compute?.price.monthly.min.fmt,
47
+ 'max-full-monthly': () => ctx.compute?.price.monthly.max.fmt,
48
+ 'min-discounted-monthly': () => ctx.compute?.discountedPrice.monthly.min.fmt,
49
+ 'max-discounted-monthly': () => ctx.compute?.discountedPrice.monthly.max.fmt
50
+ };
65
51
  const chosen = Compiler.enum({
66
52
  expr: storeContextPrice,
67
- allowed: STATE_PRICE_TOKENS,
68
- isAvailable: (token) => STATE_PRICE_AVAILABLE[token](state)
53
+ allowed: COMPUTE_PRICE_TOKENS,
54
+ isAvailable: (token) => isPresent(renderers[token]())
69
55
  });
70
56
  if (chosen) {
71
- el.textContent = STATE_PRICE_RENDER[chosen](state);
57
+ el.textContent = renderers[chosen]() ?? '';
72
58
  }
73
59
  }
74
60
  };
@@ -1 +1 @@
1
- {"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAoB,CAAU,CAAC;AAIlG,MAAM,kBAAkB,GAAG;IACzB,UAAU;IACV,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAIX,MAAM,sBAAsB,GAAG;IAC7B,MAAM,EAAgB,CAAC,MAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAA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;QAEH,IAAI,MAAM,EAAE,CAAC;YACX,EAAE,CAAC,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport type { UnifiedContext } from '../context';\nimport { isPresent } from './utilty';\n\nconst OPTION_PRICE_TOKENS = ['full', 'discounted', 'full-monthly', 'discounted-monthly'] as const;\ntype OptionPriceToken = typeof OPTION_PRICE_TOKENS[number];\ntype OptionCtx = NonNullable<UnifiedContext['option']>;\n\nconst STATE_PRICE_TOKENS = [\n 'min-full',\n 'max-full',\n 'min-discounted',\n 'max-discounted',\n 'min-full-monthly',\n 'max-full-monthly',\n 'min-discounted-monthly',\n 'max-discounted-monthly'\n] as const;\ntype StatePriceToken = typeof STATE_PRICE_TOKENS[number];\ntype StateCtx = NonNullable<UnifiedContext['state']>;\n\nconst OPTION_PRICE_AVAILABLE = {\n 'full' : (option: OptionCtx) => isPresent(option.getPrice({ currency: false })),\n 'discounted' : (option: OptionCtx) => isPresent(option.getDiscountedPrice({ currency: false })),\n 'full-monthly' : (option: OptionCtx) => isPresent(option.getPrice({ currency: false, monthly: true })),\n 'discounted-monthly': (option: OptionCtx) => isPresent(option.getDiscountedPrice({ currency: false, monthly: true }))\n} satisfies Record<OptionPriceToken, (option: OptionCtx) => boolean>;\n\nconst OPTION_PRICE_RENDER = {\n 'full' : (option: OptionCtx) => option.getPrice(),\n 'discounted' : (option: OptionCtx) => option.getDiscountedPrice(),\n 'full-monthly' : (option: OptionCtx) => option.getPrice({ monthly: true }),\n 'discounted-monthly': (option: OptionCtx) => option.getDiscountedPrice({ monthly: true })\n} satisfies Record<OptionPriceToken, (option: OptionCtx) => string>;\n\nconst STATE_PRICE_AVAILABLE = {\n 'min-full' : (state: StateCtx) => Boolean(state.price.min.fmt),\n 'max-full' : (state: StateCtx) => Boolean(state.price.max.fmt),\n 'min-full-monthly' : (state: StateCtx) => Boolean(state.price.monthly.min.fmt),\n 'max-full-monthly' : (state: StateCtx) => Boolean(state.price.monthly.max.fmt),\n 'min-discounted' : (state: StateCtx) => Boolean(state.discountedPrice.min.fmt),\n 'max-discounted' : (state: StateCtx) => Boolean(state.discountedPrice.max.fmt),\n 'min-discounted-monthly': (state: StateCtx) => Boolean(state.discountedPrice.monthly.min.fmt),\n 'max-discounted-monthly': (state: StateCtx) => Boolean(state.discountedPrice.monthly.max.fmt)\n} satisfies Record<StatePriceToken, (state: StateCtx) => boolean>;\n\nconst STATE_PRICE_RENDER = {\n 'min-full' : (state: StateCtx) => state.price.min.fmt,\n 'max-full' : (state: StateCtx) => state.price.max.fmt,\n 'min-full-monthly' : (state: StateCtx) => state.price.monthly.min.fmt,\n 'max-full-monthly' : (state: StateCtx) => state.price.monthly.max.fmt,\n 'min-discounted' : (state: StateCtx) => state.discountedPrice.min.fmt,\n 'max-discounted' : (state: StateCtx) => state.discountedPrice.max.fmt,\n 'min-discounted-monthly': (state: StateCtx) => state.discountedPrice.monthly.min.fmt,\n 'max-discounted-monthly': (state: StateCtx) => state.discountedPrice.monthly.max.fmt\n} satisfies Record<StatePriceToken, (state: StateCtx) => string>;\n\n// Handles both data-store-price (option-level) and data-store-context-price (state-level)\nexport const handlePrice = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storePrice, storeContextPrice } = el.dataset;\n const option = ctx.option;\n\n // Option-level price\n if (storePrice && option) {\n const chosen = Compiler.enum<OptionPriceToken>({\n expr : storePrice,\n allowed : OPTION_PRICE_TOKENS,\n isAvailable: (token) => OPTION_PRICE_AVAILABLE[token](option)\n });\n\n if (chosen) {\n el.textContent = OPTION_PRICE_RENDER[chosen](option);\n return;\n }\n }\n\n const state = ctx.state;\n\n // State-level price\n if (storeContextPrice && state) {\n const chosen = Compiler.enum<StatePriceToken>({\n expr : storeContextPrice,\n allowed : STATE_PRICE_TOKENS,\n isAvailable: (token) => STATE_PRICE_AVAILABLE[token](state)\n });\n\n if (chosen) {\n el.textContent = STATE_PRICE_RENDER[chosen](state);\n }\n }\n};\n"]}
1
+ {"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,mBAAmB,GAAG;IAC1B,MAAM;IACN,YAAY;IACZ,cAAc;IACd,oBAAoB;CACZ,CAAC;AAIX,MAAM,oBAAoB,GAAG;IAC3B,UAAU;IACV,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAIX,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,UAAU,EACV,iBAAiB,EAClB,GAAG,EAAE,CAAC,OAAO,CAAC;IACf,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAE1B,IAAI,UAAU,IAAI,MAAM,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG;YAChB,MAAM,EAAgB,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE;YAC7C,YAAY,EAAU,GAAG,EAAE,CAAC,kBAAkB,CAAC,MAAM,CAAC;YACtD,cAAc,EAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;YAC9D,oBAAoB,EAAE,GAAG,EAAE,CACzB,kBAAkB,CAChB,MAAM,EACN,EAAE,OAAO,EAAE,IAAI,EAAE,CAClB;SACyD,CAAC;QAE/D,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CAAmB;YAC7C,IAAI,EAAS,UAAU;YACvB,OAAO,EAAM,mBAAmB;YAChC,WAAW,EA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B;YACjC,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;SACtD,CAAC,CAAC;QAEH,IAAI,MAAM,EAAE,CAAC;YACX,EAAE,CAAC,WAAW,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;QAC7C,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport type { RenderContext } from '../context.js';\nimport { getDiscountedPrice } from '../context.js';\nimport { isPresent } from './utilty.js';\n\nconst OPTION_PRICE_TOKENS = [\n 'full',\n 'discounted',\n 'full-monthly',\n 'discounted-monthly'\n] as const;\n\ntype OptionPriceToken = typeof OPTION_PRICE_TOKENS[number];\n\nconst COMPUTE_PRICE_TOKENS = [\n 'min-full',\n 'max-full',\n 'min-discounted',\n 'max-discounted',\n 'min-full-monthly',\n 'max-full-monthly',\n 'min-discounted-monthly',\n 'max-discounted-monthly'\n] as const;\n\ntype ComputePriceToken = typeof COMPUTE_PRICE_TOKENS[number];\n\nexport const handlePrice = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storePrice,\n storeContextPrice\n } = el.dataset;\n const option = ctx.option;\n\n if (storePrice && option) {\n const renderers = {\n 'full' : () => option.getPrice(),\n 'discounted' : () => getDiscountedPrice(option),\n 'full-monthly' : () => option.getPrice({ monthly: true }),\n 'discounted-monthly': () =>\n getDiscountedPrice(\n option,\n { monthly: true }\n )\n } satisfies Record<OptionPriceToken, () => string | undefined>;\n\n const chosen = Compiler.enum<OptionPriceToken>({\n expr : storePrice,\n allowed : OPTION_PRICE_TOKENS,\n isAvailable: (token) => isPresent(renderers[token]())\n });\n\n if (chosen) {\n el.textContent = renderers[chosen]() ?? '';\n return;\n }\n }\n\n if (storeContextPrice && ctx.compute) {\n const renderers = {\n 'min-full' : () => ctx.compute?.price.min.fmt,\n 'max-full' : () => ctx.compute?.price.max.fmt,\n 'min-discounted' : () => ctx.compute?.discountedPrice.min.fmt,\n 'max-discounted' : () => ctx.compute?.discountedPrice.max.fmt,\n 'min-full-monthly' : () => ctx.compute?.price.monthly.min.fmt,\n 'max-full-monthly' : () => ctx.compute?.price.monthly.max.fmt,\n 'min-discounted-monthly': () =>\n ctx.compute?.discountedPrice.monthly.min.fmt,\n 'max-discounted-monthly': () =>\n ctx.compute?.discountedPrice.monthly.max.fmt\n } satisfies Record<ComputePriceToken, () => string | undefined>;\n\n const chosen = Compiler.enum<ComputePriceToken>({\n expr : storeContextPrice,\n allowed : COMPUTE_PRICE_TOKENS,\n isAvailable: (token) => isPresent(renderers[token]())\n });\n\n if (chosen) {\n el.textContent = renderers[chosen]() ?? '';\n }\n }\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { UnifiedContext } from '../context.js';
2
- export declare const handleSubscription: (el: HTMLElement, ctx: UnifiedContext) => void;
1
+ import type { RenderContext } from '../context.js';
2
+ export declare const handleSubscription: (el: HTMLElement, ctx: RenderContext) => void;
@@ -1,34 +1,28 @@
1
1
  import { Compiler } from '../../dsl/compilers/index.js';
2
2
  import { formatSubscription } from '../../renders/format.js';
3
+ import { buildSelectOptions } from './utilty.js';
3
4
  export const handleSubscription = (el, ctx) => {
4
5
  const { storeSubscription, storeSubscriptionType, storeTextSingle, storeTextMany } = el.dataset;
5
- if (storeSubscription === undefined)
6
+ if (storeSubscription === undefined || !ctx.option) {
6
7
  return;
7
- const option = ctx.option;
8
- if (!option)
9
- return;
10
- const type = storeSubscriptionType === 'months' ? 'months' : 'years';
11
- // input
8
+ }
9
+ const type = storeSubscriptionType === 'months'
10
+ ? 'months'
11
+ : 'years';
12
12
  if (el instanceof HTMLInputElement) {
13
- const value = type === 'months' ? option.getSubscription() : Math.floor(option.getSubscription() / 12);
13
+ const value = type === 'months'
14
+ ? ctx.option.getSubscription()
15
+ : Math.floor(ctx.option.getSubscription() / 12);
14
16
  el.value = String(value);
15
17
  return;
16
18
  }
17
- // select
18
19
  if (el instanceof HTMLSelectElement) {
19
- const selectedSubscription = option.getSubscription();
20
- const available = Compiler.array(storeSubscription) ?? option.getProduct().getSubscriptions().values;
21
- el.options.length = 0;
22
- for (const sub of available) {
23
- const isSelected = sub === selectedSubscription;
24
- const text = formatSubscription(sub, type, storeTextSingle, storeTextMany);
25
- const htmlOption = new Option(text, String(sub), isSelected, isSelected);
26
- htmlOption.setAttribute('data-store-set-subscription', String(sub));
27
- el.add(htmlOption);
28
- }
20
+ const selectedSubscription = ctx.option.getSubscription();
21
+ const available = Compiler.array(storeSubscription) ??
22
+ ctx.option.getProduct().getSubscriptions().values;
23
+ buildSelectOptions(el, available, selectedSubscription, (subscription) => formatSubscription(subscription, type, storeTextSingle, storeTextMany), 'data-store-set-subscription');
29
24
  return;
30
25
  }
31
- // generic content
32
- el.textContent = formatSubscription(option.getSubscription(), type, storeTextSingle, storeTextMany);
26
+ el.textContent = formatSubscription(ctx.option.getSubscription(), type, storeTextSingle, storeTextMany);
33
27
  };
34
28
  //# sourceMappingURL=subscription.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACzE,MAAM,EACJ,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IACf,IAAI,iBAAiB,KAAK,SAAS;QAAE,OAAO;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,IAAI,GAAG,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC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tG,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport { formatSubscription } from '@/renders/format';\nimport type { UnifiedContext } from '../context';\n\nexport const handleSubscription = (el: HTMLElement, ctx: UnifiedContext) => {\n const {\n storeSubscription,\n storeSubscriptionType,\n storeTextSingle,\n storeTextMany\n } = el.dataset;\n if (storeSubscription === undefined) return;\n const option = ctx.option;\n if (!option) return;\n\n const type = storeSubscriptionType === 'months' ? 'months' : 'years';\n\n // input\n if (el instanceof HTMLInputElement) {\n const value = type === 'months' ? option.getSubscription() : Math.floor(option.getSubscription() / 12);\n el.value = String(value);\n return;\n }\n\n // select\n if (el instanceof HTMLSelectElement) {\n const selectedSubscription = option.getSubscription();\n const available = Compiler.array(storeSubscription) ?? option.getProduct().getSubscriptions().values;\n\n el.options.length = 0;\n for (const sub of available) {\n const isSelected = sub === selectedSubscription;\n const text = formatSubscription(\n sub,\n type,\n storeTextSingle,\n storeTextMany\n );\n const htmlOption = new Option(\n text,\n String(sub),\n isSelected,\n isSelected\n );\n htmlOption.setAttribute('data-store-set-subscription', String(sub));\n el.add(htmlOption);\n }\n return;\n }\n\n // generic content\n el.textContent = formatSubscription(option.getSubscription(), type, storeTextSingle, storeTextMany);\n};\n"]}
1
+ {"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,EAAe,EACf,GAAkB,EACZ,EAAE;IACR,MAAM,EACJ,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IAEf,IAAI,iBAAiB,KAAK,SAAS,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACnD,OAAO;IACT,CAAC;IAED,MAAM,IAAI,GACR,qBAAqB,KAAK,QAAQ;QAChC,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,OAAO,CAAC;IAEd,IAAI,EAAE,YAAY,gBAAgB,EAAE,CAAC;QACnC,MAAM,KAAK,GACT,IAAI,KAAK,QAAQ;YACf,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE;YAC9B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;QAEpD,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,IAAI,EAAE,YAAY,iBAAiB,EAAE,CAAC;QACpC,MAAM,oBAAoB,GAAG,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;QAC1D,MAAM,SAAS,GACb,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC;YACjC,GAAG,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC;QAEpD,kBAAkB,CAChB,EAAE,EACF,SAAS,EACT,oBAAoB,EACpB,CAAC,YAAY,EAAE,EAAE,CAAC,kBAAkB,CAClC,YAAY,EACZ,IAAI,EACJ,eAAe,EACf,aAAa,CACd,EACD,6BAA6B,CAC9B,CAAC;QAEF,OAAO;IACT,CAAC;IAED,EAAE,CAAC,WAAW,GAAG,kBAAkB,CACjC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,EAC5B,IAAI,EACJ,eAAe,EACf,aAAa,CACd,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers/index.js';\nimport { formatSubscription } from '@/renders/format.js';\nimport type { RenderContext } from '../context.js';\nimport { buildSelectOptions } from './utilty.js';\n\nexport const handleSubscription = (\n el: HTMLElement,\n ctx: RenderContext\n): void => {\n const {\n storeSubscription,\n storeSubscriptionType,\n storeTextSingle,\n storeTextMany\n } = el.dataset;\n\n if (storeSubscription === undefined || !ctx.option) {\n return;\n }\n\n const type =\n storeSubscriptionType === 'months'\n ? 'months'\n : 'years';\n\n if (el instanceof HTMLInputElement) {\n const value =\n type === 'months'\n ? ctx.option.getSubscription()\n : Math.floor(ctx.option.getSubscription() / 12);\n\n el.value = String(value);\n return;\n }\n\n if (el instanceof HTMLSelectElement) {\n const selectedSubscription = ctx.option.getSubscription();\n const available =\n Compiler.array(storeSubscription) ??\n ctx.option.getProduct().getSubscriptions().values;\n\n buildSelectOptions(\n el,\n available,\n selectedSubscription,\n (subscription) => formatSubscription(\n subscription,\n type,\n storeTextSingle,\n storeTextMany\n ),\n 'data-store-set-subscription'\n );\n\n return;\n }\n\n el.textContent = formatSubscription(\n ctx.option.getSubscription(),\n type,\n storeTextSingle,\n storeTextMany\n );\n};\n"]}
@@ -1,2 +1,4 @@
1
1
  export declare const isPresent: (value: unknown) => boolean;
2
2
  export declare const resolveAnchor: (el: HTMLElement) => HTMLAnchorElement | null;
3
+ export type SelectOptionFormatter<T> = (value: T, index: number, values: readonly T[]) => string;
4
+ export declare const buildSelectOptions: <T>(select: HTMLSelectElement, values: readonly T[], selectedValue: T, formatLabel: SelectOptionFormatter<T>, setAttributeName: string) => void;
@@ -1,5 +1,18 @@
1
- export const isPresent = (value) => value !== null
2
- && value !== undefined
3
- && (typeof value !== 'number' || Number.isFinite(value));
4
- export const resolveAnchor = (el) => el instanceof HTMLAnchorElement ? el : el.querySelector('a');
1
+ export const isPresent = (value) => value !== null &&
2
+ value !== undefined &&
3
+ (typeof value !== 'number' || Number.isFinite(value));
4
+ export const resolveAnchor = (el) => el instanceof HTMLAnchorElement
5
+ ? el
6
+ : el.querySelector('a');
7
+ export const buildSelectOptions = (select, values, selectedValue, formatLabel, setAttributeName) => {
8
+ select.options.length = 0;
9
+ for (let index = 0; index < values.length; index += 1) {
10
+ const value = values[index];
11
+ const selected = value === selectedValue;
12
+ const label = formatLabel(value, index, values);
13
+ const option = new Option(label, String(value), selected, selected);
14
+ option.setAttribute(setAttributeName, String(value));
15
+ select.add(option);
16
+ }
17
+ };
5
18
  //# sourceMappingURL=utilty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../../src/renders/attributes/utilty.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE,CACnD,KAAK,KAAK,IAAI;OACX,KAAK,KAAK,SAAS;OACnB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAE3D,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAe,EAA4B,EAAE,CACzE,EAAE,YAAY,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAoB,GAAG,CAAC,CAAC","sourcesContent":["export const isPresent = (value: unknown): boolean =>\n value !== null\n && value !== undefined\n && (typeof value !== 'number' || Number.isFinite(value));\n\nexport const resolveAnchor = (el: HTMLElement): HTMLAnchorElement | null =>\n el instanceof HTMLAnchorElement ? el : el.querySelector<HTMLAnchorElement>('a');\n"]}
1
+ {"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../../src/renders/attributes/utilty.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAc,EACL,EAAE,CACX,KAAK,KAAK,IAAI;IACd,KAAK,KAAK,SAAS;IACnB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,EAAe,EACW,EAAE,CAC5B,EAAE,YAAY,iBAAiB;IAC7B,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC,EAAE,CAAC,aAAa,CAAoB,GAAG,CAAC,CAAC;AAQ/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAAyB,EACzB,MAAoB,EACpB,aAAgB,EAChB,WAAqC,EACrC,gBAAwB,EAClB,EAAE;IACR,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IAE1B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC5B,MAAM,QAAQ,GAAG,KAAK,KAAK,aAAa,CAAC;QACzC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAChD,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB,KAAK,EACL,MAAM,CAAC,KAAK,CAAC,EACb,QAAQ,EACR,QAAQ,CACT,CAAC;QAEF,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrD,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACrB,CAAC;AACH,CAAC,CAAC","sourcesContent":["export const isPresent = (\n value: unknown\n): boolean =>\n value !== null &&\n value !== undefined &&\n (typeof value !== 'number' || Number.isFinite(value));\n\nexport const resolveAnchor = (\n el: HTMLElement\n): HTMLAnchorElement | null =>\n el instanceof HTMLAnchorElement\n ? el\n : el.querySelector<HTMLAnchorElement>('a');\n\nexport type SelectOptionFormatter<T> = (\n value: T,\n index: number,\n values: readonly T[]\n) => string;\n\nexport const buildSelectOptions = <T>(\n select: HTMLSelectElement,\n values: readonly T[],\n selectedValue: T,\n formatLabel: SelectOptionFormatter<T>,\n setAttributeName: string\n): void => {\n select.options.length = 0;\n\n for (let index = 0; index < values.length; index += 1) {\n const value = values[index];\n const selected = value === selectedValue;\n const label = formatLabel(value, index, values);\n const option = new Option(\n label,\n String(value),\n selected,\n selected\n );\n\n option.setAttribute(setAttributeName, String(value));\n select.add(option);\n }\n};\n"]}
@@ -1,11 +1,123 @@
1
- import type { derivedContextType } from '../contexts/context.derived.js';
2
- import type { stateContextType } from '../contexts/context.state.js';
3
- import type { Product, ProductOption } from '@repobit/dex-store';
4
- export type UnifiedContext = {
5
- option?: ProductOption | null;
6
- product?: Product | null;
7
- state?: stateContextType;
8
- derived?: derivedContextType | null;
9
- };
1
+ import type { BdComputeResult } from '../compute/compute.expand.js';
2
+ import type { BdScope } from '../contexts/context.scope.js';
3
+ import type { Product, ProductOption, Store } from '@repobit/dex-store';
4
+ export type RenderContext = Readonly<{
5
+ scope?: BdScope;
6
+ store?: BdScope['store'];
7
+ product?: Product;
8
+ option?: ProductOption;
9
+ compute?: BdComputeResult;
10
+ }>;
10
11
  export type DSLContext = Record<string, unknown>;
11
- export declare const toDSLContext: ({ option, product, state, derived }: UnifiedContext) => Promise<DSLContext>;
12
+ /**
13
+ * Flattened option context exposed to Eta templates and the hide DSL.
14
+ *
15
+ * Mirrors the v1 `it.option.*` shape: every value is a pre-formatted string
16
+ * (currency-aware), so templates and hide expressions never need to call
17
+ * `option.getPrice()` directly. `links.trial` is the only callable — it
18
+ * resolves a trial URL for a given duration (e.g. `'30 days'`).
19
+ */
20
+ export type TemplateOptionContext = Readonly<{
21
+ price: {
22
+ full: string;
23
+ discounted: string | undefined;
24
+ fullMonthly: string;
25
+ discountedMonthly: string | undefined;
26
+ };
27
+ discount: {
28
+ percentage: string;
29
+ percentageMonthly: string;
30
+ value: string;
31
+ valueMonthly: string;
32
+ };
33
+ links: {
34
+ buy: string | undefined;
35
+ trial: (trialDuration: string) => string | undefined;
36
+ };
37
+ devices: number;
38
+ subscription: number;
39
+ }>;
40
+ export type TemplateProductContext = Readonly<{
41
+ id: string;
42
+ campaign: string | undefined;
43
+ name: string | undefined;
44
+ }>;
45
+ export type TemplateStateContext = Readonly<{
46
+ price: {
47
+ full: {
48
+ min: string;
49
+ max: string;
50
+ monthly: {
51
+ min: string;
52
+ max: string;
53
+ };
54
+ };
55
+ discounted: {
56
+ min: string;
57
+ max: string;
58
+ monthly: {
59
+ min: string;
60
+ max: string;
61
+ };
62
+ };
63
+ };
64
+ discount: {
65
+ percentage: {
66
+ min: string;
67
+ max: string;
68
+ monthly: {
69
+ min: string;
70
+ max: string;
71
+ };
72
+ };
73
+ value: {
74
+ min: string;
75
+ max: string;
76
+ monthly: {
77
+ min: string;
78
+ max: string;
79
+ };
80
+ };
81
+ };
82
+ scenarios: number;
83
+ }>;
84
+ /**
85
+ * Shape consumed by Eta templates and the hide DSL.
86
+ *
87
+ * Mirrors the v1 `it.*` layout: `option` / `product` / `state` are flattened
88
+ * DTOs, and `ctx` is an alias of `state`. `derived` is intentionally kept
89
+ * nested (see {@link BdScopedTemplateContext}) — v1 merged derived into the
90
+ * root via `deepmerge`; v2 exposes it explicitly so consumers can tell
91
+ * user-provided values apart from store-provided ones.
92
+ */
93
+ export type TemplateDslContext = Readonly<{
94
+ store: Store | undefined;
95
+ product: TemplateProductContext | undefined;
96
+ option: TemplateOptionContext | undefined;
97
+ state: TemplateStateContext | undefined;
98
+ ctx: TemplateStateContext | undefined;
99
+ }>;
100
+ export declare function createRenderContext(scope: BdScope | undefined, compute: BdComputeResult | undefined): RenderContext;
101
+ export declare function toDSLContext(ctx: RenderContext): DSLContext;
102
+ /**
103
+ * Build the flattened, v1-shaped DSL context.
104
+ *
105
+ * Used by both the hide DSL compiler (`renders/attributes/hide.ts`) and the
106
+ * Eta template controller (`core/node.scope.ts`) so the two surfaces agree
107
+ * on `it.option.*` / `it.product.*` / `it.state.*` / `it.ctx.*`.
108
+ */
109
+ export declare function buildTemplateDslContext(input: {
110
+ store: Store | undefined;
111
+ product: Product | undefined;
112
+ option: ProductOption | undefined;
113
+ state: BdComputeResult | undefined;
114
+ }): TemplateDslContext;
115
+ export declare function getDiscountedPrice(option: ProductOption, params?: {
116
+ monthly?: boolean;
117
+ }): string | undefined;
118
+ export declare function getDiscount(option: ProductOption, params?: {
119
+ monthly?: boolean;
120
+ percentage?: boolean;
121
+ symbol?: boolean;
122
+ }): string | undefined;
123
+ export declare function getProductName(product: Product): string | undefined;