@repobit/dex-store-elements 1.7.3 → 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 -913
  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,88 +1,148 @@
1
- import deepmerge from 'deepmerge';
2
- export const toDSLContext = async ({ option, product, state, derived }) => {
3
- const optionCtx = option
4
- ? {
5
- price: {
6
- full: option.getPrice({ currency: true }),
7
- discounted: option.getDiscountedPrice({ currency: true }),
8
- fullMonthly: option.getPrice({ monthly: true, currency: true }),
9
- discountedMonthly: option.getDiscountedPrice({ monthly: true, currency: true })
10
- },
11
- discount: {
12
- percentage: option.getDiscount({ percentage: true, symbol: true }),
13
- percentageMonthly: option.getDiscount({ percentage: true, monthly: true, symbol: true }),
14
- value: option.getDiscount({ percentage: false, symbol: true }),
15
- valueMonthly: option.getDiscount({ percentage: false, monthly: true, symbol: true })
16
- },
17
- links: {
18
- buy: option.getBuyLink(),
19
- trial: (trialDuration) => option.getTrialLink(trialDuration)
20
- },
21
- devices: option.getDevices(),
22
- subscription: option.getSubscription()
23
- }
1
+ export function createRenderContext(scope, compute) {
2
+ return {
3
+ scope,
4
+ store: scope?.store,
5
+ product: scope?.product ?? scope?.option?.getProduct(),
6
+ option: scope?.option,
7
+ compute
8
+ };
9
+ }
10
+ export function toDSLContext(ctx) {
11
+ return buildTemplateDslContext({
12
+ store: ctx.store,
13
+ product: ctx.product,
14
+ option: ctx.option,
15
+ state: ctx.compute
16
+ });
17
+ }
18
+ /**
19
+ * Build the flattened, v1-shaped DSL context.
20
+ *
21
+ * Used by both the hide DSL compiler (`renders/attributes/hide.ts`) and the
22
+ * Eta template controller (`core/node.scope.ts`) so the two surfaces agree
23
+ * on `it.option.*` / `it.product.*` / `it.state.*` / `it.ctx.*`.
24
+ */
25
+ export function buildTemplateDslContext(input) {
26
+ const product = input.product ?? input.option?.getProduct();
27
+ const stateCtx = input.state
28
+ ? buildStateContext(input.state)
24
29
  : undefined;
25
- // derive product details from option when available
26
- const productCtx = product
27
- ? {
28
- id: product.getId(),
29
- campaign: product.getCampaign(),
30
- name: product.getName()
31
- }
32
- : option
33
- ? {
34
- id: option.getProduct().getId(),
35
- campaign: option.getProduct().getCampaign(),
36
- name: option.getProduct().getName()
30
+ return {
31
+ store: input.store,
32
+ product: product
33
+ ? buildProductContext(product)
34
+ : undefined,
35
+ option: input.option
36
+ ? buildOptionContext(input.option)
37
+ : undefined,
38
+ state: stateCtx,
39
+ ctx: stateCtx
40
+ };
41
+ }
42
+ function buildOptionContext(option) {
43
+ return {
44
+ price: {
45
+ full: option.getPrice({ currency: true }),
46
+ discounted: getDiscountedPrice(option),
47
+ fullMonthly: option.getPrice({
48
+ monthly: true,
49
+ currency: true
50
+ }),
51
+ discountedMonthly: getDiscountedPrice(option, { monthly: true })
52
+ },
53
+ discount: {
54
+ percentage: getDiscountString(option, { percentage: true, monthly: false }),
55
+ percentageMonthly: getDiscountString(option, { percentage: true, monthly: true }),
56
+ value: getDiscountString(option, { percentage: false, monthly: false }),
57
+ valueMonthly: getDiscountString(option, { percentage: false, monthly: true })
58
+ },
59
+ links: {
60
+ buy: getBuyLink(option),
61
+ trial: (trialDuration) => option.getTrialLink(trialDuration)
62
+ },
63
+ devices: option.getDevices(),
64
+ subscription: option.getSubscription()
65
+ };
66
+ }
67
+ function buildProductContext(product) {
68
+ return {
69
+ id: product.getId(),
70
+ campaign: product.getCampaign(),
71
+ name: getProductName(product)
72
+ };
73
+ }
74
+ function buildStateContext(state) {
75
+ return {
76
+ price: {
77
+ full: {
78
+ min: state.price.min.fmt,
79
+ max: state.price.max.fmt,
80
+ monthly: {
81
+ min: state.price.monthly.min.fmt,
82
+ max: state.price.monthly.max.fmt
83
+ }
84
+ },
85
+ discounted: {
86
+ min: state.discountedPrice.min.fmt,
87
+ max: state.discountedPrice.max.fmt,
88
+ monthly: {
89
+ min: state.discountedPrice.monthly.min.fmt,
90
+ max: state.discountedPrice.monthly.max.fmt
91
+ }
37
92
  }
38
- : undefined;
39
- const stateCtx = state
40
- ? {
41
- price: {
42
- full: {
43
- min: state.price.min.fmt,
44
- max: state.price.max.fmt,
45
- monthly: {
46
- min: state.price.monthly.min.fmt,
47
- max: state.price.monthly.max.fmt
48
- }
49
- },
50
- discounted: {
51
- min: state.discountedPrice.min.fmt,
52
- max: state.discountedPrice.max.fmt,
53
- monthly: {
54
- min: state.discountedPrice.monthly.min.fmt,
55
- max: state.discountedPrice.monthly.max.fmt
56
- }
93
+ },
94
+ discount: {
95
+ percentage: {
96
+ min: state.discount.percentage.min.fmt,
97
+ max: state.discount.percentage.max.fmt,
98
+ monthly: {
99
+ min: state.discount.percentage.monthly.min.fmt,
100
+ max: state.discount.percentage.monthly.max.fmt
57
101
  }
58
102
  },
59
- discount: {
60
- percentage: {
61
- min: state.discount.percentage.min.fmt,
62
- max: state.discount.percentage.max.fmt,
63
- monthly: {
64
- min: state.discount.percentage.monthly.min.fmt,
65
- max: state.discount.percentage.monthly.max.fmt
66
- }
67
- },
68
- value: {
69
- min: state.discount.min.fmt,
70
- max: state.discount.max.fmt,
71
- monthly: {
72
- min: state.discount.monthly.min.fmt,
73
- max: state.discount.monthly.max.fmt
74
- }
103
+ value: {
104
+ min: state.discount.min.fmt,
105
+ max: state.discount.max.fmt,
106
+ monthly: {
107
+ min: state.discount.monthly.min.fmt,
108
+ max: state.discount.monthly.max.fmt
75
109
  }
76
110
  }
77
- }
78
- : undefined;
79
- const base = {
80
- option: optionCtx,
81
- product: productCtx,
82
- state: stateCtx,
83
- ctx: stateCtx
111
+ },
112
+ scenarios: state.scenarios
84
113
  };
85
- const extra = derived ? await derived({ option, product, state }) : {};
86
- return deepmerge(base, extra || {});
87
- };
114
+ }
115
+ export function getDiscountedPrice(option, params) {
116
+ const maybe = option;
117
+ const value = maybe.getDiscountedPrice?.({
118
+ ...params,
119
+ currency: true
120
+ });
121
+ return stringifyPresentValue(value);
122
+ }
123
+ export function getDiscount(option, params) {
124
+ const maybe = option;
125
+ const value = maybe.getDiscount?.(params);
126
+ return stringifyPresentValue(value);
127
+ }
128
+ function getDiscountString(option, params) {
129
+ return getDiscount(option, { ...params, symbol: true }) ?? '';
130
+ }
131
+ function getBuyLink(option) {
132
+ const maybe = option;
133
+ return maybe.getBuyLink?.();
134
+ }
135
+ function stringifyPresentValue(value) {
136
+ if (value === null ||
137
+ value === undefined ||
138
+ (typeof value === 'number' &&
139
+ !Number.isFinite(value))) {
140
+ return undefined;
141
+ }
142
+ return String(value);
143
+ }
144
+ export function getProductName(product) {
145
+ const maybe = product;
146
+ return maybe.getName?.();
147
+ }
88
148
  //# sourceMappingURL=context.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/renders/context.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,MAAM,WAAW,CAAC;AAYlC,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAkB,EAAuB,EAAE;IAC7G,MAAM,SAAS,GAAG,MAAM;QACtB,CAAC,CAAC;YACA,KAAK,EAAE;gBACL,IAAI,EAAe,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBACtD,UAAU,EAAS,MAAM,CAAC,kBAAkB,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBAChE,WAAW,EAAQ,MAAM,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBACrE,iBAAiB,EAAE,MAAM,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;aAChF;YACD,QAAQ,EAAE;gBACR,UAAU,EAAS,MAAM,CAAC,WAA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AAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;wBACnC,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;qBACpC;iBACF;aACF;SACF;QACD,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,IAAI,GAA4B;QACpC,MAAM,EAAG,SAAS;QAClB,OAAO,EAAE,UAAU;QACnB,KAAK,EAAI,QAAQ;QACjB,GAAG,EAAM,QAAQ;KAClB,CAAC;IAEF,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAEvE,OAAO,SAAS,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAe,CAAC;AACpD,CAAC,CAAC","sourcesContent":["import type { derivedContextType } from '@/contexts/context.derived';\nimport type { stateContextType } from '@/contexts/context.state';\nimport type { Product, ProductOption } from '@repobit/dex-store';\nimport deepmerge from 'deepmerge';\n\nexport type UnifiedContext = {\n option? : ProductOption | null;\n product?: Product | null;\n state? : stateContextType;\n derived?: derivedContextType | null;\n};\n\n// Context shape used by the DSL compilers\nexport type DSLContext = Record<string, unknown>;\n\nexport const toDSLContext = async ({ option, product, state, derived }: UnifiedContext): Promise<DSLContext> => {\n const optionCtx = option\n ? {\n price: {\n full : option.getPrice({ currency: true }),\n discounted : option.getDiscountedPrice({ currency: true }),\n fullMonthly : option.getPrice({ monthly: true, currency: true }),\n discountedMonthly: option.getDiscountedPrice({ monthly: true, currency: true })\n },\n discount: {\n percentage : option.getDiscount({ percentage: true, symbol: true }),\n percentageMonthly: option.getDiscount({ percentage: true, monthly: true, symbol: true }),\n value : option.getDiscount({ percentage: false, symbol: true }),\n valueMonthly : option.getDiscount({ percentage: false, monthly: true, symbol: true })\n },\n links: {\n buy : option.getBuyLink(),\n trial: (trialDuration: string) => option.getTrialLink(trialDuration)\n },\n devices : option.getDevices(),\n subscription: option.getSubscription()\n }\n : undefined;\n\n // derive product details from option when available\n const productCtx = product\n ? {\n id : product.getId(),\n campaign: product.getCampaign(),\n name : product.getName()\n }\n : option\n ? {\n id : option.getProduct().getId(),\n campaign: option.getProduct().getCampaign(),\n name : option.getProduct().getName()\n }\n : undefined;\n\n const stateCtx = state\n ? {\n price: {\n full: {\n min : state.price.min.fmt,\n max : state.price.max.fmt,\n monthly: {\n min: state.price.monthly.min.fmt,\n max: state.price.monthly.max.fmt\n }\n },\n discounted: {\n min : state.discountedPrice.min.fmt,\n max : state.discountedPrice.max.fmt,\n monthly: {\n min: state.discountedPrice.monthly.min.fmt,\n max: state.discountedPrice.monthly.max.fmt\n }\n }\n },\n discount: {\n percentage: {\n min : state.discount.percentage.min.fmt,\n max : state.discount.percentage.max.fmt,\n monthly: {\n min: state.discount.percentage.monthly.min.fmt,\n max: state.discount.percentage.monthly.max.fmt\n }\n },\n value: {\n min : state.discount.min.fmt,\n max : state.discount.max.fmt,\n monthly: {\n min: state.discount.monthly.min.fmt,\n max: state.discount.monthly.max.fmt\n }\n }\n }\n }\n : undefined;\n\n const base: Record<string, unknown> = {\n option : optionCtx,\n product: productCtx,\n state : stateCtx,\n ctx : stateCtx\n };\n\n const extra = derived ? await derived({ option, product, state }) : {};\n\n return deepmerge(base, extra || {}) as DSLContext;\n};\n"]}
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/renders/context.ts"],"names":[],"mappings":"AA8FA,MAAM,UAAU,mBAAmB,CACjC,KAA0B,EAC1B,OAAoC;IAEpC,OAAO;QACL,KAAK;QACL,KAAK,EAAI,KAAK,EAAE,KAAK;QACrB,OAAO,EAAE,KAAK,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE;QACtD,MAAM,EAAG,KAAK,EAAE,MAAM;QACtB,OAAO;KACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,GAAkB;IAElB,OAAO,u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,MAAM;QACT,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAEL,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,MAAqB,EACrB,MAIC;IAED,MAAM,KAAK,GACT,MAQC,CAAC;IAEJ,MAAM,KAAK,GACT,KAAK,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC;IAE9B,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,iBAAiB,CACxB,MAAqB,EACrB,MAGC;IAED,OAAO,WAAW,CAChB,MAAM,EACN,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAC5B,IAAI,EAAE,CAAC;AACV,CAAC;AAED,SAAS,UAAU,CACjB,MAAqB;IAErB,MAAM,KAAK,GACT,MAEC,CAAC;IAEJ,OAAO,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC;AAC9B,CAAC;AAED,SAAS,qBAAqB,CAC5B,KAAc;IAEd,IACE,KAAK,KAAK,IAAI;QACd,KAAK,KAAK,SAAS;QACnB,CACE,OAAO,KAAK,KAAK,QAAQ;YACzB,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CACxB,EACD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,OAAgB;IAEhB,MAAM,KAAK,GACT,OAEC,CAAC;IAEJ,OAAO,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;AAC3B,CAAC","sourcesContent":["import type { BdComputeResult } from '@/compute/compute.expand.js';\nimport type { BdScope } from '@/contexts/context.scope.js';\nimport type { Product, ProductOption, Store } from '@repobit/dex-store';\n\nexport type RenderContext = Readonly<{\n scope? : BdScope;\n store? : BdScope['store'];\n product?: Product;\n option? : ProductOption;\n compute?: BdComputeResult;\n}>;\n\nexport type DSLContext = Record<string, unknown>;\n\n/**\n * Flattened option context exposed to Eta templates and the hide DSL.\n *\n * Mirrors the v1 `it.option.*` shape: every value is a pre-formatted string\n * (currency-aware), so templates and hide expressions never need to call\n * `option.getPrice()` directly. `links.trial` is the only callable — it\n * resolves a trial URL for a given duration (e.g. `'30 days'`).\n */\nexport type TemplateOptionContext = Readonly<{\n price: {\n full : string;\n discounted : string | undefined;\n fullMonthly : string;\n discountedMonthly: string | undefined;\n };\n discount: {\n percentage : string;\n percentageMonthly: string;\n value : string;\n valueMonthly : string;\n };\n links: {\n buy : string | undefined;\n trial: (trialDuration: string) => string | undefined;\n };\n devices : number;\n subscription: number;\n}>;\n\nexport type TemplateProductContext = Readonly<{\n id : string;\n campaign: string | undefined;\n name : string | undefined;\n}>;\n\nexport type TemplateStateContext = Readonly<{\n price: {\n full: {\n min : string;\n max : string;\n monthly: { min: string; max: string };\n };\n discounted: {\n min : string;\n max : string;\n monthly: { min: string; max: string };\n };\n };\n discount: {\n percentage: {\n min : string;\n max : string;\n monthly: { min: string; max: string };\n };\n value: {\n min : string;\n max : string;\n monthly: { min: string; max: string };\n };\n };\n scenarios: number;\n}>;\n\n/**\n * Shape consumed by Eta templates and the hide DSL.\n *\n * Mirrors the v1 `it.*` layout: `option` / `product` / `state` are flattened\n * DTOs, and `ctx` is an alias of `state`. `derived` is intentionally kept\n * nested (see {@link BdScopedTemplateContext}) — v1 merged derived into the\n * root via `deepmerge`; v2 exposes it explicitly so consumers can tell\n * user-provided values apart from store-provided ones.\n */\nexport type TemplateDslContext = Readonly<{\n store : Store | undefined;\n product: TemplateProductContext | undefined;\n option : TemplateOptionContext | undefined;\n state : TemplateStateContext | undefined;\n ctx : TemplateStateContext | undefined;\n}>;\n\nexport function createRenderContext(\n scope: BdScope | undefined,\n compute: BdComputeResult | undefined\n): RenderContext {\n return {\n scope,\n store : scope?.store,\n product: scope?.product ?? scope?.option?.getProduct(),\n option : scope?.option,\n compute\n };\n}\n\nexport function toDSLContext(\n ctx: RenderContext\n): DSLContext {\n return buildTemplateDslContext({\n store : ctx.store,\n product: ctx.product,\n option : ctx.option,\n state : ctx.compute\n });\n}\n\n/**\n * Build the flattened, v1-shaped DSL context.\n *\n * Used by both the hide DSL compiler (`renders/attributes/hide.ts`) and the\n * Eta template controller (`core/node.scope.ts`) so the two surfaces agree\n * on `it.option.*` / `it.product.*` / `it.state.*` / `it.ctx.*`.\n */\nexport function buildTemplateDslContext(input: {\n store : Store | undefined;\n product: Product | undefined;\n option : ProductOption | undefined;\n state : BdComputeResult | undefined;\n}): TemplateDslContext {\n const product = input.product ?? input.option?.getProduct();\n const stateCtx = input.state\n ? buildStateContext(input.state)\n : undefined;\n\n return {\n store : input.store,\n product: product\n ? buildProductContext(product)\n : undefined,\n option: input.option\n ? buildOptionContext(input.option)\n : undefined,\n state: stateCtx,\n ctx : stateCtx\n };\n}\n\nfunction buildOptionContext(\n option: ProductOption\n): TemplateOptionContext {\n return {\n price: {\n full : option.getPrice({ currency: true }),\n discounted : getDiscountedPrice(option),\n fullMonthly: option.getPrice({\n monthly : true,\n currency: true\n }),\n discountedMonthly: getDiscountedPrice(\n option,\n { monthly: true }\n )\n },\n discount: {\n percentage: getDiscountString(\n option,\n { percentage: true, monthly: false }\n ),\n percentageMonthly: getDiscountString(\n option,\n { percentage: true, monthly: true }\n ),\n value: getDiscountString(\n option,\n { percentage: false, monthly: false }\n ),\n valueMonthly: getDiscountString(\n option,\n { percentage: false, monthly: true }\n )\n },\n links: {\n buy : getBuyLink(option),\n trial: (trialDuration: string) =>\n option.getTrialLink(trialDuration)\n },\n devices : option.getDevices(),\n subscription: option.getSubscription()\n };\n}\n\nfunction buildProductContext(\n product: Product\n): TemplateProductContext {\n return {\n id : product.getId(),\n campaign: product.getCampaign(),\n name : getProductName(product)\n };\n}\n\nfunction buildStateContext(\n state: BdComputeResult\n): TemplateStateContext {\n return {\n price: {\n full: {\n min : state.price.min.fmt,\n max : state.price.max.fmt,\n monthly: {\n min: state.price.monthly.min.fmt,\n max: state.price.monthly.max.fmt\n }\n },\n discounted: {\n min : state.discountedPrice.min.fmt,\n max : state.discountedPrice.max.fmt,\n monthly: {\n min: state.discountedPrice.monthly.min.fmt,\n max: state.discountedPrice.monthly.max.fmt\n }\n }\n },\n discount: {\n percentage: {\n min : state.discount.percentage.min.fmt,\n max : state.discount.percentage.max.fmt,\n monthly: {\n min: state.discount.percentage.monthly.min.fmt,\n max: state.discount.percentage.monthly.max.fmt\n }\n },\n value: {\n min : state.discount.min.fmt,\n max : state.discount.max.fmt,\n monthly: {\n min: state.discount.monthly.min.fmt,\n max: state.discount.monthly.max.fmt\n }\n }\n },\n scenarios: state.scenarios\n };\n}\n\nexport function getDiscountedPrice(\n option: ProductOption,\n params?: {\n monthly?: boolean;\n }\n): string | undefined {\n const maybe =\n option as ProductOption & {\n getDiscountedPrice?: (\n params?: {\n monthly? : boolean;\n currency?: boolean;\n }\n ) => string | number | undefined;\n };\n\n const value: unknown =\n maybe.getDiscountedPrice?.({\n ...params,\n currency: true\n });\n\n return stringifyPresentValue(value);\n}\n\nexport function getDiscount(\n option: ProductOption,\n params?: {\n monthly? : boolean;\n percentage?: boolean;\n symbol? : boolean;\n }\n): string | undefined {\n const maybe =\n option as ProductOption & {\n getDiscount?: (\n params?: {\n monthly? : boolean;\n percentage?: boolean;\n symbol? : boolean;\n }\n ) => string | number | undefined;\n };\n\n const value: unknown =\n maybe.getDiscount?.(params);\n\n return stringifyPresentValue(value);\n}\n\nfunction getDiscountString(\n option: ProductOption,\n params: {\n percentage: boolean;\n monthly : boolean;\n }\n): string {\n return getDiscount(\n option,\n { ...params, symbol: true }\n ) ?? '';\n}\n\nfunction getBuyLink(\n option: ProductOption\n): string | undefined {\n const maybe =\n option as ProductOption & {\n getBuyLink?: () => string | undefined;\n };\n\n return maybe.getBuyLink?.();\n}\n\nfunction stringifyPresentValue(\n value: unknown\n): string | undefined {\n if (\n value === null ||\n value === undefined ||\n (\n typeof value === 'number' &&\n !Number.isFinite(value)\n )\n ) {\n return undefined;\n }\n\n return String(value);\n}\n\nexport function getProductName(\n product: Product\n): string | undefined {\n const maybe =\n product as Product & {\n getName?: () => string | undefined;\n };\n\n return maybe.getName?.();\n}\n"]}
@@ -1,7 +1,7 @@
1
- export const formatSubscription = (subscription, format = "years", textSingular, textPlural) => {
1
+ export const formatSubscription = (subscription, format = 'years', textSingular, textPlural) => {
2
2
  const years = subscription / 12;
3
3
  const months = subscription % 12;
4
- if (format === "years" && months === 0) {
4
+ if (format === 'years' && months === 0) {
5
5
  if (!textPlural || !textSingular) {
6
6
  return `${years}`;
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/renders/format.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,YAAoB,EACpB,SAA6B,OAAO,EACpC,YAAqB,EACrB,UAAmB,EACnB,EAAE;IACF,MAAM,KAAK,GAAG,YAAY,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,YAAY,GAAG,EAAE,CAAC;IAEjC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;YACjC,OAAO,GAAG,KAAK,EAAE,CAAC;QACpB,CAAC;QACD,OAAO,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;IAED,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,GAAG,YAAY,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,GAAG,YAAY,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,YAAqB,EACrB,UAAmB,EACnB,EAAE;IACF,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,GAAG,OAAO,EAAE,CAAC;IACtB,CAAC;IACD,OAAO,GAAG,OAAO,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AACnE,CAAC,CAAC","sourcesContent":["export const formatSubscription = (\n subscription: number,\n format: \"years\" | \"months\" = \"years\",\n textSingular?: string,\n textPlural?: string\n) => {\n const years = subscription / 12;\n const months = subscription % 12;\n\n if (format === \"years\" && months === 0) {\n if (!textPlural || !textSingular) {\n return `${years}`;\n }\n return `${years} ${years === 1 ? textSingular : textPlural}`;\n }\n\n if (!textPlural || !textSingular) {\n return `${subscription}`;\n }\n\n return `${subscription} ${subscription === 1 ? textSingular : textPlural}`;\n};\n\nexport const formatDevices = (\n devices: number,\n textSingular?: string,\n textPlural?: string\n) => {\n if (!textPlural || !textSingular) {\n return `${devices}`;\n }\n return `${devices} ${devices === 1 ? textSingular : textPlural}`;\n};\n\n"]}
1
+ {"version":3,"file":"format.js","sourceRoot":"","sources":["../../../src/renders/format.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,YAAoB,EACpB,SAA6B,OAAO,EACpC,YAAqB,EACrB,UAAmB,EACX,EAAE;IACV,MAAM,KAAK,GAAG,YAAY,GAAG,EAAE,CAAC;IAChC,MAAM,MAAM,GAAG,YAAY,GAAG,EAAE,CAAC;IAEjC,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;YACjC,OAAO,GAAG,KAAK,EAAE,CAAC;QACpB,CAAC;QAED,OAAO,GAAG,KAAK,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAC/D,CAAC;IAED,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,GAAG,YAAY,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,GAAG,YAAY,IAAI,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AAC7E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,OAAe,EACf,YAAqB,EACrB,UAAmB,EACX,EAAE;IACV,IAAI,CAAC,UAAU,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,OAAO,GAAG,OAAO,EAAE,CAAC;IACtB,CAAC;IAED,OAAO,GAAG,OAAO,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;AACnE,CAAC,CAAC","sourcesContent":["export const formatSubscription = (\n subscription: number,\n format: 'years' | 'months' = 'years',\n textSingular?: string,\n textPlural?: string\n): string => {\n const years = subscription / 12;\n const months = subscription % 12;\n\n if (format === 'years' && months === 0) {\n if (!textPlural || !textSingular) {\n return `${years}`;\n }\n\n return `${years} ${years === 1 ? textSingular : textPlural}`;\n }\n\n if (!textPlural || !textSingular) {\n return `${subscription}`;\n }\n\n return `${subscription} ${subscription === 1 ? textSingular : textPlural}`;\n};\n\nexport const formatDevices = (\n devices: number,\n textSingular?: string,\n textPlural?: string\n): string => {\n if (!textPlural || !textSingular) {\n return `${devices}`;\n }\n\n return `${devices} ${devices === 1 ? textSingular : textPlural}`;\n};\n"]}
@@ -1,2 +1,6 @@
1
- declare const registerRenderNodes: (root: HTMLElement | ShadowRoot) => () => void;
2
- export { registerRenderNodes };
1
+ import { type BdRenderTarget } from './render.wrapper.js';
2
+ export declare const DATA_RENDER_NODE = "[data-store-render]";
3
+ export declare const DATA_HIDE_NODE = "[data-store-hide]";
4
+ export declare function handleRenderNode(target: BdRenderTarget): void;
5
+ export declare function cleanupRenderNode(target: BdRenderTarget): void;
6
+ export declare function registerRenderNodes(root: HTMLElement | ShadowRoot): () => void;
@@ -1,32 +1,64 @@
1
- import { cleanupRenderNode, DATA_HIDE_NODE, DATA_RENDER_NODE, handleRenderNode } from "./utility.js";
2
- const selectors = [DATA_HIDE_NODE, DATA_RENDER_NODE];
1
+ import { BdRenderWrapper } from './render.wrapper.js';
2
+ export const DATA_RENDER_NODE = '[data-store-render]';
3
+ export const DATA_HIDE_NODE = '[data-store-hide]';
4
+ const selectors = [
5
+ DATA_RENDER_NODE,
6
+ DATA_HIDE_NODE
7
+ ];
3
8
  const selectorStr = selectors.join(',');
4
- const SHADOW_HOST_SELECTOR = '[shadow]';
5
- const isRenderNode = (node) => selectors.some((s) => node.matches(s));
6
- const forEachRenderNode = (root, fn) => {
7
- if (root instanceof HTMLElement && isRenderNode(root)) {
9
+ const SHADOW_HOST_SELECTOR = '[shadow], [data-bd-watch-shadow]';
10
+ const WRAPPERS = new WeakMap();
11
+ function isRenderNode(node) {
12
+ return selectors.some((selector) => node.matches(selector));
13
+ }
14
+ function forEachRenderNode(root, fn) {
15
+ if (root instanceof HTMLElement &&
16
+ isRenderNode(root)) {
8
17
  fn(root);
9
18
  }
10
19
  root
11
20
  .querySelectorAll(selectorStr)
12
21
  .forEach(fn);
13
- };
14
- const forEachShadowRoot = (root, fn) => {
15
- if (root instanceof HTMLElement && root.hasAttribute('shadow') && root.shadowRoot) {
22
+ }
23
+ function forEachShadowRoot(root, fn) {
24
+ if (root instanceof HTMLElement &&
25
+ matchesShadowHost(root)) {
16
26
  fn(root.shadowRoot);
17
27
  }
18
28
  root
19
29
  .querySelectorAll(SHADOW_HOST_SELECTOR)
20
- .forEach((host) => host.shadowRoot && fn(host.shadowRoot));
21
- };
22
- const registerRenderNodes = (root) => {
30
+ .forEach((host) => {
31
+ if (matchesShadowHost(host)) {
32
+ fn(host.shadowRoot);
33
+ }
34
+ });
35
+ }
36
+ export function handleRenderNode(target) {
37
+ if (WRAPPERS.has(target)) {
38
+ return;
39
+ }
40
+ const wrapper = new BdRenderWrapper(target);
41
+ WRAPPERS.set(target, wrapper);
42
+ wrapper.connect();
43
+ }
44
+ export function cleanupRenderNode(target) {
45
+ const wrapper = WRAPPERS.get(target);
46
+ if (!wrapper) {
47
+ return;
48
+ }
49
+ WRAPPERS.delete(target);
50
+ wrapper.disconnect();
51
+ }
52
+ export function registerRenderNodes(root) {
23
53
  const observed = new WeakSet();
24
54
  const observers = new WeakMap();
25
55
  const activeObservers = new Set();
26
56
  const disconnect = (node) => {
57
+ observed.delete(node);
27
58
  const observer = observers.get(node);
28
- if (!observer)
59
+ if (!observer) {
29
60
  return;
61
+ }
30
62
  observer.disconnect();
31
63
  observers.delete(node);
32
64
  activeObservers.delete(observer);
@@ -45,31 +77,32 @@ const registerRenderNodes = (root) => {
45
77
  forEachShadowRoot(node, cleanupShadowTree);
46
78
  };
47
79
  const watch = (node) => {
48
- if (observed.has(node))
80
+ if (observed.has(node)) {
49
81
  return;
82
+ }
50
83
  observed.add(node);
51
84
  forEachRenderNode(node, handleRenderNode);
52
85
  forEachShadowRoot(node, watch);
53
- const mo = new MutationObserver(muts => {
54
- for (const m of muts) {
55
- for (const added of Array.from(m.addedNodes)) {
56
- if (!(added instanceof HTMLElement))
57
- continue;
58
- handleAdded(added);
86
+ const observer = new MutationObserver((mutations) => {
87
+ for (const mutation of mutations) {
88
+ for (const added of mutation.addedNodes) {
89
+ if (added instanceof HTMLElement) {
90
+ handleAdded(added);
91
+ }
59
92
  }
60
- for (const removed of Array.from(m.removedNodes)) {
61
- if (!(removed instanceof HTMLElement))
62
- continue;
63
- handleRemoved(removed);
93
+ for (const removed of mutation.removedNodes) {
94
+ if (removed instanceof HTMLElement) {
95
+ handleRemoved(removed);
96
+ }
64
97
  }
65
98
  }
66
99
  });
67
- mo.observe(node, {
100
+ observer.observe(node, {
68
101
  childList: true,
69
102
  subtree: true
70
103
  });
71
- observers.set(node, mo);
72
- activeObservers.add(mo);
104
+ observers.set(node, observer);
105
+ activeObservers.add(observer);
73
106
  };
74
107
  watch(root);
75
108
  return () => {
@@ -77,7 +110,12 @@ const registerRenderNodes = (root) => {
77
110
  observer.disconnect();
78
111
  }
79
112
  activeObservers.clear();
113
+ forEachRenderNode(root, cleanupRenderNode);
114
+ forEachShadowRoot(root, cleanupShadowTree);
80
115
  };
81
- };
82
- export { registerRenderNodes };
116
+ }
117
+ function matchesShadowHost(element) {
118
+ return Boolean(element.shadowRoot &&
119
+ element.matches(SHADOW_HOST_SELECTOR));
120
+ }
83
121
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/renders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,gBAAgB,EAAc,MAAM,WAAW,CAAC;AAE9G,MAAM,SAAS,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;AACrD,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,MAAM,oBAAoB,GAAG,UAAU,CAAC;AAExC,MAAM,YAAY,GAAG,CAAC,IAAiB,EAAsB,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvG,MAAM,iBAAiB,GAAG,CAAC,IAA8B,EAAE,EAA8B,EAAE,EAAE;IAC3F,IAAI,IAAI,YAAY,WAAW,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,EAAE,CAAC,IAAI,CAAC,CAAC;IACX,CAAC;IAED,IAAI;SACD,gBAAgB,CAAa,WAAW,CAAC;SACzC,OAAO,CAAC,EAAE,CAAC,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAC,IAA8B,EAAE,EAAoC,EAAE,EAAE;IACjG,IAA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CAAC;IAEF,KAAK,CAAC,IAAI,CAAC,CAAC;IACZ,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC;QACD,eAAe,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,CAAC;AACJ,CAAC,CAAA;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["import { cleanupRenderNode, DATA_HIDE_NODE, DATA_RENDER_NODE, handleRenderNode, RenderNode } from \"./utility\";\n\nconst selectors = [DATA_HIDE_NODE, DATA_RENDER_NODE];\nconst selectorStr = selectors.join(',');\nconst SHADOW_HOST_SELECTOR = '[shadow]';\n\nconst isRenderNode = (node: HTMLElement): node is RenderNode => selectors.some((s) => node.matches(s));\n\nconst forEachRenderNode = (root: HTMLElement | ShadowRoot, fn: (node: RenderNode) => void) => {\n if (root instanceof HTMLElement && isRenderNode(root)) {\n fn(root);\n }\n\n root\n .querySelectorAll<RenderNode>(selectorStr)\n .forEach(fn);\n};\n\nconst forEachShadowRoot = (root: HTMLElement | ShadowRoot, fn: (shadowRoot: ShadowRoot) => void) => {\n if (root instanceof HTMLElement && root.hasAttribute('shadow') && root.shadowRoot) {\n fn(root.shadowRoot);\n }\n\n root\n .querySelectorAll<HTMLElement>(SHADOW_HOST_SELECTOR)\n .forEach((host) => host.shadowRoot && fn(host.shadowRoot));\n};\n\nconst registerRenderNodes = (root: HTMLElement | ShadowRoot) => {\n const observed = new WeakSet<Node>();\n const observers = new WeakMap<Node, MutationObserver>();\n const activeObservers = new Set<MutationObserver>();\n\n const disconnect = (node: Node) => {\n const observer = observers.get(node);\n if (!observer) return;\n observer.disconnect();\n observers.delete(node);\n activeObservers.delete(observer);\n };\n\n const cleanupShadowTree = (shadowRoot: ShadowRoot) => {\n forEachRenderNode(shadowRoot, cleanupRenderNode);\n forEachShadowRoot(shadowRoot, cleanupShadowTree);\n disconnect(shadowRoot);\n };\n\n const handleAdded = (node: HTMLElement) => {\n forEachRenderNode(node, handleRenderNode);\n forEachShadowRoot(node, watch);\n };\n\n const handleRemoved = (node: HTMLElement) => {\n forEachRenderNode(node, cleanupRenderNode);\n forEachShadowRoot(node, cleanupShadowTree);\n };\n\n const watch = (node: HTMLElement | ShadowRoot) => {\n if (observed.has(node)) return;\n observed.add(node);\n\n forEachRenderNode(node, handleRenderNode);\n forEachShadowRoot(node, watch);\n\n const mo = new MutationObserver(muts => {\n for (const m of muts) {\n for (const added of Array.from(m.addedNodes)) {\n if (!(added instanceof HTMLElement)) continue;\n handleAdded(added);\n }\n for (const removed of Array.from(m.removedNodes)) {\n if (!(removed instanceof HTMLElement)) continue;\n handleRemoved(removed);\n }\n }\n });\n\n mo.observe(node, {\n childList: true,\n subtree : true\n });\n observers.set(node, mo);\n activeObservers.add(mo);\n };\n\n watch(root);\n return () => {\n for (const observer of activeObservers) {\n observer.disconnect();\n }\n activeObservers.clear();\n };\n}\n\nexport { registerRenderNodes };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/renders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AACtD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD,MAAM,SAAS,GAAG;IAChB,gBAAgB;IAChB,cAAc;CACf,CAAC;AACF,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACxC,MAAM,oBAAoB,GAAG,kCAAkC,CAAC;AAEhE,MAAM,QAAQ,GAAG,IAAI,OAAO,EAAmC,CAAC;AAEhE,SAAS,YAAY,CACnB,IAAiB;IAEjB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CACjC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CACvB,CAAC;AACJ,C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AO,OAAO,CACZ,OAAO,CAAC,UAAU;QAClB,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CACtC,CAAC;AACJ,CAAC","sourcesContent":["import {\n BdRenderWrapper,\n type BdRenderTarget\n} from './render.wrapper.js';\n\nexport const DATA_RENDER_NODE = '[data-store-render]';\nexport const DATA_HIDE_NODE = '[data-store-hide]';\n\nconst selectors = [\n DATA_RENDER_NODE,\n DATA_HIDE_NODE\n];\nconst selectorStr = selectors.join(',');\nconst SHADOW_HOST_SELECTOR = '[shadow], [data-bd-watch-shadow]';\n\nconst WRAPPERS = new WeakMap<BdRenderTarget, BdRenderWrapper>();\n\nfunction isRenderNode(\n node: HTMLElement\n): node is BdRenderTarget {\n return selectors.some((selector) =>\n node.matches(selector)\n );\n}\n\nfunction forEachRenderNode(\n root: HTMLElement | ShadowRoot,\n fn: (node: BdRenderTarget) => void\n): void {\n if (\n root instanceof HTMLElement &&\n isRenderNode(root)\n ) {\n fn(root);\n }\n\n root\n .querySelectorAll<BdRenderTarget>(selectorStr)\n .forEach(fn);\n}\n\nfunction forEachShadowRoot(\n root: HTMLElement | ShadowRoot,\n fn: (shadowRoot: ShadowRoot) => void\n): void {\n if (\n root instanceof HTMLElement &&\n matchesShadowHost(root)\n ) {\n fn(root.shadowRoot);\n }\n\n root\n .querySelectorAll<HTMLElement>(SHADOW_HOST_SELECTOR)\n .forEach((host) => {\n if (matchesShadowHost(host)) {\n fn(host.shadowRoot);\n }\n });\n}\n\nexport function handleRenderNode(\n target: BdRenderTarget\n): void {\n if (WRAPPERS.has(target)) {\n return;\n }\n\n const wrapper = new BdRenderWrapper(target);\n\n WRAPPERS.set(\n target,\n wrapper\n );\n wrapper.connect();\n}\n\nexport function cleanupRenderNode(\n target: BdRenderTarget\n): void {\n const wrapper = WRAPPERS.get(target);\n\n if (!wrapper) {\n return;\n }\n\n WRAPPERS.delete(target);\n wrapper.disconnect();\n}\n\nexport function registerRenderNodes(\n root: HTMLElement | ShadowRoot\n): () => void {\n const observed = new WeakSet<Node>();\n const observers = new WeakMap<Node, MutationObserver>();\n const activeObservers = new Set<MutationObserver>();\n\n const disconnect = (\n node: Node\n ): void => {\n observed.delete(node);\n\n const observer = observers.get(node);\n\n if (!observer) {\n return;\n }\n\n observer.disconnect();\n observers.delete(node);\n activeObservers.delete(observer);\n };\n\n const cleanupShadowTree = (\n shadowRoot: ShadowRoot\n ): void => {\n forEachRenderNode(\n shadowRoot,\n cleanupRenderNode\n );\n forEachShadowRoot(\n shadowRoot,\n cleanupShadowTree\n );\n disconnect(shadowRoot);\n };\n\n const handleAdded = (\n node: HTMLElement\n ): void => {\n forEachRenderNode(\n node,\n handleRenderNode\n );\n forEachShadowRoot(\n node,\n watch\n );\n };\n\n const handleRemoved = (\n node: HTMLElement\n ): void => {\n forEachRenderNode(\n node,\n cleanupRenderNode\n );\n forEachShadowRoot(\n node,\n cleanupShadowTree\n );\n };\n\n const watch = (\n node: HTMLElement | ShadowRoot\n ): void => {\n if (observed.has(node)) {\n return;\n }\n\n observed.add(node);\n\n forEachRenderNode(\n node,\n handleRenderNode\n );\n forEachShadowRoot(\n node,\n watch\n );\n\n const observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n for (const added of mutation.addedNodes) {\n if (added instanceof HTMLElement) {\n handleAdded(added);\n }\n }\n\n for (const removed of mutation.removedNodes) {\n if (removed instanceof HTMLElement) {\n handleRemoved(removed);\n }\n }\n }\n });\n\n observer.observe(\n node,\n {\n childList: true,\n subtree : true\n }\n );\n\n observers.set(\n node,\n observer\n );\n activeObservers.add(observer);\n };\n\n watch(root);\n\n return () => {\n for (const observer of activeObservers) {\n observer.disconnect();\n }\n\n activeObservers.clear();\n forEachRenderNode(\n root,\n cleanupRenderNode\n );\n forEachShadowRoot(\n root,\n cleanupShadowTree\n );\n };\n}\n\nfunction matchesShadowHost(\n element: HTMLElement\n): element is HTMLElement & { shadowRoot: ShadowRoot } {\n return Boolean(\n element.shadowRoot &&\n element.matches(SHADOW_HOST_SELECTOR)\n );\n}\n"]}
@@ -1,4 +1 @@
1
- export declare const OBS_ATTRS_COMMON: readonly ["data-store-hide", "data-store-hide-type"];
2
- export declare const OBS_ATTRS_OPTION: readonly ["data-store-devices", "data-store-subscription", "data-store-text-single", "data-store-text-many", "data-store-subscription-type", "data-store-price", "data-store-discount", "data-store-buy-link"];
3
- export declare const OBS_ATTRS_STATE: readonly ["data-store-context-price", "data-store-context-discount"];
4
- export declare const OBS_ATTRS_OPTION_PLUS_STATE: readonly ["data-store-devices", "data-store-subscription", "data-store-text-single", "data-store-text-many", "data-store-subscription-type", "data-store-price", "data-store-discount", "data-store-buy-link", "data-store-context-price", "data-store-context-discount", "data-store-hide", "data-store-hide-type"];
1
+ export declare const OBS_ATTRS_RENDER: readonly ["data-store-buy-link", "data-store-context-discount", "data-store-context-price", "data-store-discount", "data-store-devices", "data-store-hide", "data-store-hide-type", "data-store-price", "data-store-subscription", "data-store-subscription-type", "data-store-text-many", "data-store-text-single"];
@@ -1,29 +1,15 @@
1
- // Attributes that, when changed, should trigger a re-render of nodes.
2
- // Shared across both contexts
3
- export const OBS_ATTRS_COMMON = [
4
- 'data-store-hide',
5
- 'data-store-hide-type'
6
- ];
7
- // Attributes affecting option-level rendering
8
- export const OBS_ATTRS_OPTION = [
1
+ export const OBS_ATTRS_RENDER = [
2
+ 'data-store-buy-link',
3
+ 'data-store-context-discount',
4
+ 'data-store-context-price',
5
+ 'data-store-discount',
9
6
  'data-store-devices',
7
+ 'data-store-hide',
8
+ 'data-store-hide-type',
9
+ 'data-store-price',
10
10
  'data-store-subscription',
11
- 'data-store-text-single',
12
- 'data-store-text-many',
13
11
  'data-store-subscription-type',
14
- 'data-store-price',
15
- 'data-store-discount',
16
- 'data-store-buy-link'
17
- ];
18
- // Attributes affecting state-level rendering
19
- export const OBS_ATTRS_STATE = [
20
- 'data-store-context-price',
21
- 'data-store-context-discount'
22
- ];
23
- // Combined set used when option-side also cares about state-driven attributes in markup
24
- export const OBS_ATTRS_OPTION_PLUS_STATE = [
25
- ...OBS_ATTRS_OPTION,
26
- ...OBS_ATTRS_STATE,
27
- ...OBS_ATTRS_COMMON
12
+ 'data-store-text-many',
13
+ 'data-store-text-single'
28
14
  ];
29
15
  //# sourceMappingURL=observe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../../src/renders/observe.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAEtE,8BAA8B;AAC9B,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,iBAAiB;IACjB,sBAAsB;CACd,CAAC;AAEX,8CAA8C;AAC9C,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,oBAAoB;IACpB,yBAAyB;IACzB,wBAAwB;IACxB,sBAAsB;IACtB,8BAA8B;IAC9B,kBAAkB;IAClB,qBAAqB;IACrB,qBAAqB;CACb,CAAC;AAEX,6CAA6C;AAC7C,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,0BAA0B;IAC1B,6BAA6B;CACrB,CAAC;AAEX,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,GAAG,gBAAgB;IACnB,GAAG,eAAe;IAClB,GAAG,gBAAgB;CACX,CAAC","sourcesContent":["// Attributes that, when changed, should trigger a re-render of nodes.\n\n// Shared across both contexts\nexport const OBS_ATTRS_COMMON = [\n 'data-store-hide',\n 'data-store-hide-type'\n] as const;\n\n// Attributes affecting option-level rendering\nexport const OBS_ATTRS_OPTION = [\n 'data-store-devices',\n 'data-store-subscription',\n 'data-store-text-single',\n 'data-store-text-many',\n 'data-store-subscription-type',\n 'data-store-price',\n 'data-store-discount',\n 'data-store-buy-link'\n] as const;\n\n// Attributes affecting state-level rendering\nexport const OBS_ATTRS_STATE = [\n 'data-store-context-price',\n 'data-store-context-discount'\n] as const;\n\n// Combined set used when option-side also cares about state-driven attributes in markup\nexport const OBS_ATTRS_OPTION_PLUS_STATE = [\n ...OBS_ATTRS_OPTION,\n ...OBS_ATTRS_STATE,\n ...OBS_ATTRS_COMMON\n] as const;\n"]}
1
+ {"version":3,"file":"observe.js","sourceRoot":"","sources":["../../../src/renders/observe.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,qBAAqB;IACrB,6BAA6B;IAC7B,0BAA0B;IAC1B,qBAAqB;IACrB,oBAAoB;IACpB,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;IAClB,yBAAyB;IACzB,8BAA8B;IAC9B,sBAAsB;IACtB,wBAAwB;CAChB,CAAC","sourcesContent":["export const OBS_ATTRS_RENDER = [\n 'data-store-buy-link',\n 'data-store-context-discount',\n 'data-store-context-price',\n 'data-store-discount',\n 'data-store-devices',\n 'data-store-hide',\n 'data-store-hide-type',\n 'data-store-price',\n 'data-store-subscription',\n 'data-store-subscription-type',\n 'data-store-text-many',\n 'data-store-text-single'\n] as const;\n"]}
@@ -0,0 +1,37 @@
1
+ import type { ReactiveController, ReactiveControllerHost } from 'lit';
2
+ import { type BdScope } from '../contexts/context.scope.js';
3
+ export type BdRenderTarget = HTMLElement & {
4
+ updateComplete?: Promise<boolean>;
5
+ };
6
+ /**
7
+ * Invisible render wrapper for a regular HTML render target.
8
+ *
9
+ * It implements the minimal ReactiveControllerHost surface needed by
10
+ * ContextConsumer, but delegates dispatchEvent to the target element. That
11
+ * makes the target the context request entrypoint without adding a wrapper
12
+ * element to the DOM.
13
+ */
14
+ export declare class BdRenderWrapper implements ReactiveControllerHost {
15
+ readonly target: BdRenderTarget;
16
+ scope?: BdScope;
17
+ private readonly _controllers;
18
+ private readonly _originalUpdateComplete?;
19
+ private readonly _renderTask;
20
+ private _observer?;
21
+ private _connected;
22
+ private _updateComplete;
23
+ private _computeResult?;
24
+ constructor(target: BdRenderTarget);
25
+ get updateComplete(): Promise<boolean>;
26
+ addController(controller: ReactiveController): void;
27
+ removeController(controller: ReactiveController): void;
28
+ requestUpdate(): void;
29
+ dispatchEvent(event: Event): boolean;
30
+ connect(): void;
31
+ disconnect(): void;
32
+ renderTarget(): Promise<boolean>;
33
+ private _queueRender;
34
+ private _observeTarget;
35
+ private _disconnectObserver;
36
+ private _restoreUpdateComplete;
37
+ }