@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.
- package/CHANGELOG.md +5 -905
- package/README.md +9 -7
- package/dist/src/actions/action.adapter.d.ts +36 -0
- package/dist/src/actions/action.adapter.js +183 -0
- package/dist/src/actions/action.adapter.js.map +1 -0
- package/dist/src/actions/action.attributes.d.ts +15 -0
- package/dist/src/actions/action.attributes.js +137 -0
- package/dist/src/actions/action.attributes.js.map +1 -0
- package/dist/src/actions/action.registry.d.ts +4 -0
- package/dist/src/actions/action.registry.js +119 -0
- package/dist/src/actions/action.registry.js.map +1 -0
- package/dist/src/actions/index.d.ts +3 -2
- package/dist/src/actions/index.js +3 -80
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/compute/compute.expand.d.ts +70 -0
- package/dist/src/compute/compute.expand.js +319 -0
- package/dist/src/compute/compute.expand.js.map +1 -0
- package/dist/src/compute/compute.scan.d.ts +54 -0
- package/dist/src/compute/compute.scan.js +160 -0
- package/dist/src/compute/compute.scan.js.map +1 -0
- package/dist/src/compute/option-resolver.d.ts +31 -0
- package/dist/src/compute/option-resolver.js +147 -0
- package/dist/src/compute/option-resolver.js.map +1 -0
- package/dist/src/contexts/context.compute.d.ts +12 -0
- package/dist/src/contexts/context.compute.js +4 -0
- package/dist/src/contexts/context.compute.js.map +1 -0
- package/dist/src/contexts/context.scope.d.ts +139 -0
- package/dist/src/contexts/context.scope.js +48 -0
- package/dist/src/contexts/context.scope.js.map +1 -0
- package/dist/src/controllers/controller.action-resolve.d.ts +110 -0
- package/dist/src/controllers/controller.action-resolve.js +203 -0
- package/dist/src/controllers/controller.action-resolve.js.map +1 -0
- package/dist/src/controllers/controller.action-topology.d.ts +59 -0
- package/dist/src/controllers/controller.action-topology.js +130 -0
- package/dist/src/controllers/controller.action-topology.js.map +1 -0
- package/dist/src/controllers/controller.compute.d.ts +72 -0
- package/dist/src/controllers/controller.compute.js +110 -0
- package/dist/src/controllers/controller.compute.js.map +1 -0
- package/dist/src/controllers/controller.resolve.d.ts +78 -0
- package/dist/src/controllers/controller.resolve.js +205 -0
- package/dist/src/controllers/controller.resolve.js.map +1 -0
- package/dist/src/core/action-topology.d.ts +62 -0
- package/dist/src/core/action-topology.js +67 -0
- package/dist/src/core/action-topology.js.map +1 -0
- package/dist/src/core/actions.d.ts +64 -0
- package/dist/src/core/actions.js +47 -0
- package/dist/src/core/actions.js.map +1 -0
- package/dist/src/core/node.element.d.ts +179 -0
- package/dist/src/core/node.element.js +573 -0
- package/dist/src/core/node.element.js.map +1 -0
- package/dist/src/core/node.scope.d.ts +374 -0
- package/dist/src/core/node.scope.js +558 -0
- package/dist/src/core/node.scope.js.map +1 -0
- package/dist/src/core/option-update.d.ts +11 -0
- package/dist/src/core/option-update.js +59 -0
- package/dist/src/core/option-update.js.map +1 -0
- package/dist/src/dsl/compilers/array/compiler.js +13 -14
- package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/boolean/compiler.d.ts +1 -1
- package/dist/src/dsl/compilers/boolean/compiler.js +14 -27
- package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/enum/compiler.js +7 -10
- package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/index.d.ts +1 -1
- package/dist/src/dsl/compilers/index.js +5 -5
- package/dist/src/dsl/compilers/index.js.map +1 -1
- package/dist/src/dsl/utilty.d.ts +0 -4
- package/dist/src/dsl/utilty.js +3 -30
- package/dist/src/dsl/utilty.js.map +1 -1
- package/dist/src/eta/batch.d.ts +123 -0
- package/dist/src/eta/batch.js +162 -0
- package/dist/src/eta/batch.js.map +1 -0
- package/dist/src/eta/batcher.d.ts +184 -0
- package/dist/src/eta/batcher.js +335 -0
- package/dist/src/eta/batcher.js.map +1 -0
- package/dist/src/eta/cache.d.ts +36 -0
- package/dist/src/eta/cache.js +56 -0
- package/dist/src/eta/cache.js.map +1 -0
- package/dist/src/eta/controller.d.ts +608 -0
- package/dist/src/eta/controller.js +1036 -0
- package/dist/src/eta/controller.js.map +1 -0
- package/dist/src/eta/factory.d.ts +74 -0
- package/dist/src/eta/factory.js +121 -0
- package/dist/src/eta/factory.js.map +1 -0
- package/dist/src/eta/idle.d.ts +39 -0
- package/dist/src/eta/idle.js +52 -0
- package/dist/src/eta/idle.js.map +1 -0
- package/dist/src/eta/index.d.ts +52 -0
- package/dist/src/eta/index.js +13 -0
- package/dist/src/eta/index.js.map +1 -0
- package/dist/src/eta/observer.d.ts +263 -0
- package/dist/src/eta/observer.js +263 -0
- package/dist/src/eta/observer.js.map +1 -0
- package/dist/src/eta/operations.d.ts +41 -0
- package/dist/src/eta/operations.js +59 -0
- package/dist/src/eta/operations.js.map +1 -0
- package/dist/src/eta/source-registry.d.ts +198 -0
- package/dist/src/eta/source-registry.js +267 -0
- package/dist/src/eta/source-registry.js.map +1 -0
- package/dist/src/eta/template-index.d.ts +285 -0
- package/dist/src/eta/template-index.js +642 -0
- package/dist/src/eta/template-index.js.map +1 -0
- package/dist/src/eta/types.d.ts +529 -0
- package/dist/src/eta/types.js +2 -0
- package/dist/src/eta/types.js.map +1 -0
- package/dist/src/index.d.ts +21 -9
- package/dist/src/index.js +22 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/nodes/node.context.d.ts +5 -3
- package/dist/src/nodes/node.context.js +48 -3
- package/dist/src/nodes/node.context.js.map +1 -1
- package/dist/src/nodes/node.option.d.ts +11 -31
- package/dist/src/nodes/node.option.js +158 -222
- package/dist/src/nodes/node.option.js.map +1 -1
- package/dist/src/nodes/node.product.d.ts +7 -11
- package/dist/src/nodes/node.product.js +85 -64
- package/dist/src/nodes/node.product.js.map +1 -1
- package/dist/src/renders/attributes/buyLink.d.ts +2 -2
- package/dist/src/renders/attributes/buyLink.js +14 -11
- package/dist/src/renders/attributes/buyLink.js.map +1 -1
- package/dist/src/renders/attributes/devices.d.ts +2 -2
- package/dist/src/renders/attributes/devices.js +9 -19
- package/dist/src/renders/attributes/devices.js.map +1 -1
- package/dist/src/renders/attributes/discount.d.ts +2 -2
- package/dist/src/renders/attributes/discount.js +56 -44
- package/dist/src/renders/attributes/discount.js.map +1 -1
- package/dist/src/renders/attributes/hide.d.ts +2 -2
- package/dist/src/renders/attributes/hide.js +49 -14
- package/dist/src/renders/attributes/hide.js.map +1 -1
- package/dist/src/renders/attributes/index.d.ts +3 -3
- package/dist/src/renders/attributes/index.js +2 -4
- package/dist/src/renders/attributes/index.js.map +1 -1
- package/dist/src/renders/attributes/price.d.ts +2 -2
- package/dist/src/renders/attributes/price.js +30 -44
- package/dist/src/renders/attributes/price.js.map +1 -1
- package/dist/src/renders/attributes/subscription.d.ts +2 -2
- package/dist/src/renders/attributes/subscription.js +14 -20
- package/dist/src/renders/attributes/subscription.js.map +1 -1
- package/dist/src/renders/attributes/utilty.d.ts +2 -0
- package/dist/src/renders/attributes/utilty.js +17 -4
- package/dist/src/renders/attributes/utilty.js.map +1 -1
- package/dist/src/renders/context.d.ts +122 -10
- package/dist/src/renders/context.js +140 -80
- package/dist/src/renders/context.js.map +1 -1
- package/dist/src/renders/format.js +2 -2
- package/dist/src/renders/format.js.map +1 -1
- package/dist/src/renders/index.d.ts +6 -2
- package/dist/src/renders/index.js +67 -29
- package/dist/src/renders/index.js.map +1 -1
- package/dist/src/renders/observe.d.ts +1 -4
- package/dist/src/renders/observe.js +10 -24
- package/dist/src/renders/observe.js.map +1 -1
- package/dist/src/renders/render.wrapper.d.ts +37 -0
- package/dist/src/renders/render.wrapper.js +147 -0
- package/dist/src/renders/render.wrapper.js.map +1 -0
- package/dist/src/templating/eta.js +1 -4
- package/dist/src/templating/eta.js.map +1 -1
- package/package.json +4 -5
- package/dist/src/actions/action.button.d.ts +0 -2
- package/dist/src/actions/action.button.js +0 -8
- package/dist/src/actions/action.button.js.map +0 -1
- package/dist/src/actions/action.input.d.ts +0 -2
- package/dist/src/actions/action.input.js +0 -43
- package/dist/src/actions/action.input.js.map +0 -1
- package/dist/src/actions/action.select.d.ts +0 -2
- package/dist/src/actions/action.select.js +0 -14
- package/dist/src/actions/action.select.js.map +0 -1
- package/dist/src/actions/utilty.d.ts +0 -16
- package/dist/src/actions/utilty.js +0 -149
- package/dist/src/actions/utilty.js.map +0 -1
- package/dist/src/contexts/context.datalayer.d.ts +0 -9
- package/dist/src/contexts/context.datalayer.js +0 -3
- package/dist/src/contexts/context.datalayer.js.map +0 -1
- package/dist/src/contexts/context.derived.d.ts +0 -12
- package/dist/src/contexts/context.derived.js +0 -3
- package/dist/src/contexts/context.derived.js.map +0 -1
- package/dist/src/contexts/context.option.d.ts +0 -5
- package/dist/src/contexts/context.option.js +0 -3
- package/dist/src/contexts/context.option.js.map +0 -1
- package/dist/src/contexts/context.product.d.ts +0 -5
- package/dist/src/contexts/context.product.js +0 -3
- package/dist/src/contexts/context.product.js.map +0 -1
- package/dist/src/contexts/context.state.d.ts +0 -28
- package/dist/src/contexts/context.state.js +0 -3
- package/dist/src/contexts/context.state.js.map +0 -1
- package/dist/src/contexts/context.store.d.ts +0 -5
- package/dist/src/contexts/context.store.js +0 -3
- package/dist/src/contexts/context.store.js.map +0 -1
- package/dist/src/controllers/collect-controller.d.ts +0 -39
- package/dist/src/controllers/collect-controller.js +0 -161
- package/dist/src/controllers/collect-controller.js.map +0 -1
- package/dist/src/controllers/compute-controller.d.ts +0 -55
- package/dist/src/controllers/compute-controller.js +0 -350
- package/dist/src/controllers/compute-controller.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +0 -25
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +0 -192
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +0 -28
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +0 -206
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +0 -21
- package/dist/src/controllers/eta-renderer/eta-renderer.js +0 -77
- package/dist/src/controllers/eta-renderer/eta-renderer.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +0 -24
- package/dist/src/controllers/eta-renderer/eta-template-cache.js +0 -61
- package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +0 -1
- package/dist/src/controllers/eta-renderer/eta-types.d.ts +0 -11
- package/dist/src/controllers/eta-renderer/eta-types.js +0 -1
- package/dist/src/controllers/eta-renderer/eta-types.js.map +0 -1
- package/dist/src/controllers/eta-renderer/index.d.ts +0 -2
- package/dist/src/controllers/eta-renderer/index.js +0 -2
- package/dist/src/controllers/eta-renderer/index.js.map +0 -1
- package/dist/src/controllers/event-pipeline-controller.d.ts +0 -28
- package/dist/src/controllers/event-pipeline-controller.js +0 -72
- package/dist/src/controllers/event-pipeline-controller.js.map +0 -1
- package/dist/src/events/events.d.ts +0 -75
- package/dist/src/events/events.js +0 -78
- package/dist/src/events/events.js.map +0 -1
- package/dist/src/nodes/node.root.d.ts +0 -16
- package/dist/src/nodes/node.root.js +0 -49
- package/dist/src/nodes/node.root.js.map +0 -1
- package/dist/src/nodes/node.state.d.ts +0 -88
- package/dist/src/nodes/node.state.js +0 -330
- package/dist/src/nodes/node.state.js.map +0 -1
- package/dist/src/renders/utility.d.ts +0 -32
- package/dist/src/renders/utility.js +0 -191
- package/dist/src/renders/utility.js.map +0 -1
|
@@ -1,88 +1,148 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
:
|
|
79
|
-
const base = {
|
|
80
|
-
option: optionCtx,
|
|
81
|
-
product: productCtx,
|
|
82
|
-
state: stateCtx,
|
|
83
|
-
ctx: stateCtx
|
|
111
|
+
},
|
|
112
|
+
scenarios: state.scenarios
|
|
84
113
|
};
|
|
85
|
-
|
|
86
|
-
|
|
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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AAG;oBAC1C,OAAO,EAAE;wBACP,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;wBAC9C,GAAG,EAAE,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;qBAC/C;iBACF;gBACD,KAAK,EAAE;oBACL,GAAG,EAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG;oBAC/B,GAAG,EAAM,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG;oBAC/B,OAAO,EAAE;wBACP,GAAG,EAAE,KAAK,CAAC,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 || {}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AAC;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 =
|
|
1
|
+
export const formatSubscription = (subscription, format = 'years', textSingular, textPlural) => {
|
|
2
2
|
const years = subscription / 12;
|
|
3
3
|
const months = subscription % 12;
|
|
4
|
-
if (format ===
|
|
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,
|
|
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
|
-
|
|
2
|
-
export
|
|
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 {
|
|
2
|
-
const
|
|
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
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
15
|
-
if (root instanceof HTMLElement &&
|
|
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) =>
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
54
|
-
for (const
|
|
55
|
-
for (const added of
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
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
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
for (const removed of mutation.removedNodes) {
|
|
94
|
+
if (removed instanceof HTMLElement) {
|
|
95
|
+
handleRemoved(removed);
|
|
96
|
+
}
|
|
64
97
|
}
|
|
65
98
|
}
|
|
66
99
|
});
|
|
67
|
-
|
|
100
|
+
observer.observe(node, {
|
|
68
101
|
childList: true,
|
|
69
102
|
subtree: true
|
|
70
103
|
});
|
|
71
|
-
observers.set(node,
|
|
72
|
-
activeObservers.add(
|
|
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
|
-
|
|
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,
|
|
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,CAAC;AAED,SAAS,iBAAiB,CACxB,IAA8B,EAC9B,EAAkC;IAElC,IACE,IAAI,YAAY,WAAW;QAC3B,YAAY,CAAC,IAAI,CAAC,EAClB,CAAC;QACD,EAAE,CAAC,IAAI,CAAC,CAAC;IACX,CAAC;IAED,IAAI;SACD,gBAAgB,CAAiB,WAAW,CAAC;SAC7C,OAAO,CAAC,EAAE,CAAC,CAAC;AACjB,CAAC;AAED,SAAS,iBAAiB,CACxB,IAA8B,EAC9B,EAAoC;IAEpC,IACE,IAAI,YAAY,WAAW;QAC3B,iBAAiB,CAAC,IAAI,CAAC,EACvB,CAAC;QACD,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtB,CAAC;IAED,IAAI;SACD,gBAAgB,CAAc,oBAAoB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EAAE,CAAC;oBAC5C,IAAI,OAAO,YAAY,WAAW,EAAE,CAAC;wBACnC,aAAa,CAAC,OAAO,CAAC,CAAC;oBACzB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,QAAQ,CAAC,OAAO,CACd,IAAI,EACJ;YACE,SAAS,EAAE,IAAI;YACf,OAAO,EAAI,IAAI;SAChB,CACF,CAAC;QAEF,SAAS,CAAC,GAAG,CACX,IAAI,EACJ,QAAQ,CACT,CAAC;QACF,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC,CAAC;IAEF,KAAK,CAAC,IAAI,CAAC,CAAC;IAEZ,OAAO,GAAG,EAAE;QACV,KAAK,MAAM,QAAQ,IAAI,eAAe,EAAE,CAAC;YACvC,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC;QAED,eAAe,CAAC,KAAK,EAAE,CAAC;QACxB,iBAAiB,CACf,IAAI,EACJ,iBAAiB,CAClB,CAAC;QACF,iBAAiB,CACf,IAAI,EACJ,iBAAiB,CAClB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CACxB,OAAoB;IAEpB,OAAO,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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
'data-store-
|
|
5
|
-
'data-store-
|
|
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-
|
|
15
|
-
'data-store-
|
|
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,
|
|
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
|
+
}
|