@repobit/dex-store-elements 1.4.2 → 1.4.3
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 +10 -0
- package/README.md +15 -4
- package/dist/src/actions/action.button.js +4 -11
- package/dist/src/actions/action.button.js.map +1 -1
- package/dist/src/actions/action.input.js +28 -22
- package/dist/src/actions/action.input.js.map +1 -1
- package/dist/src/actions/action.select.js +10 -8
- package/dist/src/actions/action.select.js.map +1 -1
- package/dist/src/actions/index.d.ts +1 -1
- package/dist/src/actions/index.js +45 -49
- package/dist/src/actions/index.js.map +1 -1
- package/dist/src/actions/utilty.d.ts +1 -0
- package/dist/src/actions/utilty.js +59 -29
- package/dist/src/actions/utilty.js.map +1 -1
- package/dist/src/contexts/context.datalayer.js.map +1 -1
- package/dist/src/contexts/context.derived.js.map +1 -1
- package/dist/src/contexts/context.option.js.map +1 -1
- package/dist/src/contexts/context.product.js.map +1 -1
- package/dist/src/contexts/context.state.js.map +1 -1
- package/dist/src/contexts/context.store.js.map +1 -1
- package/dist/src/controllers/collect-controller.d.ts +39 -0
- package/dist/src/controllers/collect-controller.js +161 -0
- package/dist/src/controllers/collect-controller.js.map +1 -0
- package/dist/src/controllers/compute-controller.d.ts +55 -0
- package/dist/src/controllers/compute-controller.js +350 -0
- package/dist/src/controllers/compute-controller.js.map +1 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.d.ts +21 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js +152 -0
- package/dist/src/controllers/eta-renderer/eta-dom-renderer.js.map +1 -0
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.d.ts +28 -0
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js +206 -0
- package/dist/src/controllers/eta-renderer/eta-mutation-observer.js.map +1 -0
- package/dist/src/controllers/eta-renderer/eta-renderer.d.ts +21 -0
- package/dist/src/controllers/eta-renderer/eta-renderer.js +77 -0
- package/dist/src/controllers/eta-renderer/eta-renderer.js.map +1 -0
- package/dist/src/controllers/eta-renderer/eta-template-cache.d.ts +21 -0
- package/dist/src/controllers/eta-renderer/eta-template-cache.js +52 -0
- package/dist/src/controllers/eta-renderer/eta-template-cache.js.map +1 -0
- package/dist/src/controllers/eta-renderer/eta-types.d.ts +11 -0
- package/dist/src/controllers/eta-renderer/eta-types.js +1 -0
- package/dist/src/controllers/eta-renderer/eta-types.js.map +1 -0
- package/dist/src/controllers/eta-renderer/index.d.ts +2 -0
- package/dist/src/controllers/eta-renderer/index.js +2 -0
- package/dist/src/controllers/eta-renderer/index.js.map +1 -0
- package/dist/src/controllers/event-pipeline-controller.d.ts +28 -0
- package/dist/src/controllers/event-pipeline-controller.js +72 -0
- package/dist/src/controllers/event-pipeline-controller.js.map +1 -0
- package/dist/src/dsl/compilers/array/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/boolean/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/enum/compiler.js.map +1 -1
- package/dist/src/dsl/compilers/index.js.map +1 -1
- package/dist/src/dsl/utilty.js.map +1 -1
- package/dist/src/events/events.js.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/nodes/node.context.js.map +1 -1
- package/dist/src/nodes/node.option.d.ts +4 -2
- package/dist/src/nodes/node.option.js +56 -56
- package/dist/src/nodes/node.option.js.map +1 -1
- package/dist/src/nodes/node.product.d.ts +4 -3
- package/dist/src/nodes/node.product.js +16 -28
- package/dist/src/nodes/node.product.js.map +1 -1
- package/dist/src/nodes/node.root.js.map +1 -1
- package/dist/src/nodes/node.state.d.ts +18 -70
- package/dist/src/nodes/node.state.js +42 -862
- package/dist/src/nodes/node.state.js.map +1 -1
- package/dist/src/renders/attributes/buyLink.js +12 -8
- package/dist/src/renders/attributes/buyLink.js.map +1 -1
- package/dist/src/renders/attributes/devices.js +10 -10
- package/dist/src/renders/attributes/devices.js.map +1 -1
- package/dist/src/renders/attributes/discount.js +60 -81
- package/dist/src/renders/attributes/discount.js.map +1 -1
- package/dist/src/renders/attributes/hide.js +21 -26
- package/dist/src/renders/attributes/hide.js.map +1 -1
- package/dist/src/renders/attributes/index.js.map +1 -1
- package/dist/src/renders/attributes/price.js +60 -81
- package/dist/src/renders/attributes/price.js.map +1 -1
- package/dist/src/renders/attributes/subscription.js +11 -11
- package/dist/src/renders/attributes/subscription.js.map +1 -1
- package/dist/src/renders/attributes/trialLink.js +5 -4
- package/dist/src/renders/attributes/trialLink.js.map +1 -1
- package/dist/src/renders/attributes/utilty.d.ts +2 -0
- package/dist/src/renders/attributes/utilty.js +3 -0
- package/dist/src/renders/attributes/utilty.js.map +1 -0
- package/dist/src/renders/context.js.map +1 -1
- package/dist/src/renders/format.js.map +1 -1
- package/dist/src/renders/index.d.ts +1 -1
- package/dist/src/renders/index.js +46 -50
- package/dist/src/renders/index.js.map +1 -1
- package/dist/src/renders/observe.js.map +1 -1
- package/dist/src/renders/utility.js +46 -38
- package/dist/src/renders/utility.js.map +1 -1
- package/dist/src/templating/eta.js.map +1 -1
- package/package.json +2 -2
- package/dist/src/contexts/context.event.d.ts +0 -5
- package/dist/src/contexts/context.event.js +0 -3
- package/dist/src/contexts/context.event.js.map +0 -1
|
@@ -1,95 +1,74 @@
|
|
|
1
1
|
import { Compiler } from '../../dsl/compilers/index.js';
|
|
2
|
+
import { isPresent } from './utilty.js';
|
|
3
|
+
const OPTION_PRICE_TOKENS = ['full', 'discounted', 'full-monthly', 'discounted-monthly'];
|
|
4
|
+
const STATE_PRICE_TOKENS = [
|
|
5
|
+
'min-full',
|
|
6
|
+
'max-full',
|
|
7
|
+
'min-discounted',
|
|
8
|
+
'max-discounted',
|
|
9
|
+
'min-full-monthly',
|
|
10
|
+
'max-full-monthly',
|
|
11
|
+
'min-discounted-monthly',
|
|
12
|
+
'max-discounted-monthly'
|
|
13
|
+
];
|
|
14
|
+
const OPTION_PRICE_AVAILABLE = {
|
|
15
|
+
'full': (option) => isPresent(option.getPrice({ currency: false })),
|
|
16
|
+
'discounted': (option) => isPresent(option.getDiscountedPrice({ currency: false })),
|
|
17
|
+
'full-monthly': (option) => isPresent(option.getPrice({ currency: false, monthly: true })),
|
|
18
|
+
'discounted-monthly': (option) => isPresent(option.getDiscountedPrice({ currency: false, monthly: true }))
|
|
19
|
+
};
|
|
20
|
+
const OPTION_PRICE_RENDER = {
|
|
21
|
+
'full': (option) => option.getPrice(),
|
|
22
|
+
'discounted': (option) => option.getDiscountedPrice(),
|
|
23
|
+
'full-monthly': (option) => option.getPrice({ monthly: true }),
|
|
24
|
+
'discounted-monthly': (option) => option.getDiscountedPrice({ monthly: true })
|
|
25
|
+
};
|
|
26
|
+
const STATE_PRICE_AVAILABLE = {
|
|
27
|
+
'min-full': (state) => isPresent(state.price.min.value),
|
|
28
|
+
'max-full': (state) => isPresent(state.price.max.value),
|
|
29
|
+
'min-full-monthly': (state) => isPresent(state.price.monthly.min.value),
|
|
30
|
+
'max-full-monthly': (state) => isPresent(state.price.monthly.max.value),
|
|
31
|
+
'min-discounted': (state) => isPresent(state.discountedPrice.min.value),
|
|
32
|
+
'max-discounted': (state) => isPresent(state.discountedPrice.max.value),
|
|
33
|
+
'min-discounted-monthly': (state) => isPresent(state.discountedPrice.monthly.min.value),
|
|
34
|
+
'max-discounted-monthly': (state) => isPresent(state.discountedPrice.monthly.max.value)
|
|
35
|
+
};
|
|
36
|
+
const STATE_PRICE_RENDER = {
|
|
37
|
+
'min-full': (state) => state.price.min.fmt,
|
|
38
|
+
'max-full': (state) => state.price.max.fmt,
|
|
39
|
+
'min-full-monthly': (state) => state.price.monthly.min.fmt,
|
|
40
|
+
'max-full-monthly': (state) => state.price.monthly.max.fmt,
|
|
41
|
+
'min-discounted': (state) => state.discountedPrice.min.fmt,
|
|
42
|
+
'max-discounted': (state) => state.discountedPrice.max.fmt,
|
|
43
|
+
'min-discounted-monthly': (state) => state.discountedPrice.monthly.min.fmt,
|
|
44
|
+
'max-discounted-monthly': (state) => state.discountedPrice.monthly.max.fmt
|
|
45
|
+
};
|
|
2
46
|
// Handles both data-store-price (option-level) and data-store-context-price (state-level)
|
|
3
47
|
export const handlePrice = (el, ctx) => {
|
|
4
|
-
const
|
|
48
|
+
const { storePrice, storeContextPrice } = el.dataset;
|
|
49
|
+
const option = ctx.option;
|
|
5
50
|
// Option-level price
|
|
6
|
-
if (
|
|
7
|
-
const allowed = ['full', 'discounted', 'full-monthly', 'discounted-monthly'];
|
|
51
|
+
if (storePrice && option) {
|
|
8
52
|
const chosen = Compiler.enum({
|
|
9
|
-
expr:
|
|
10
|
-
allowed,
|
|
11
|
-
isAvailable: (
|
|
12
|
-
switch (v) {
|
|
13
|
-
case 'full':
|
|
14
|
-
return !!ctx.option.getPrice({ currency: false });
|
|
15
|
-
case 'discounted':
|
|
16
|
-
return !!ctx.option.getDiscountedPrice({ currency: false });
|
|
17
|
-
case 'full-monthly':
|
|
18
|
-
return !!ctx.option.getPrice({ currency: false, monthly: true });
|
|
19
|
-
case 'discounted-monthly':
|
|
20
|
-
return !!ctx.option.getDiscountedPrice({ currency: false, monthly: true });
|
|
21
|
-
}
|
|
22
|
-
}
|
|
53
|
+
expr: storePrice,
|
|
54
|
+
allowed: OPTION_PRICE_TOKENS,
|
|
55
|
+
isAvailable: (token) => OPTION_PRICE_AVAILABLE[token](option)
|
|
23
56
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
case 'discounted':
|
|
29
|
-
el.innerHTML = ctx.option.getDiscountedPrice();
|
|
30
|
-
return;
|
|
31
|
-
case 'full-monthly':
|
|
32
|
-
el.innerHTML = ctx.option.getPrice({ monthly: true });
|
|
33
|
-
return;
|
|
34
|
-
case 'discounted-monthly':
|
|
35
|
-
el.innerHTML = ctx.option.getDiscountedPrice({ monthly: true });
|
|
36
|
-
return;
|
|
57
|
+
if (chosen) {
|
|
58
|
+
el.textContent = OPTION_PRICE_RENDER[chosen](option);
|
|
59
|
+
return;
|
|
37
60
|
}
|
|
38
61
|
}
|
|
62
|
+
const state = ctx.state;
|
|
39
63
|
// State-level price
|
|
40
|
-
if (
|
|
41
|
-
const allowed = [
|
|
42
|
-
'min-full',
|
|
43
|
-
'max-full',
|
|
44
|
-
'min-discounted',
|
|
45
|
-
'max-discounted',
|
|
46
|
-
'min-full-monthly',
|
|
47
|
-
'max-full-monthly',
|
|
48
|
-
'min-discounted-monthly',
|
|
49
|
-
'max-discounted-monthly'
|
|
50
|
-
];
|
|
51
|
-
const s = ctx.state;
|
|
64
|
+
if (storeContextPrice && state) {
|
|
52
65
|
const chosen = Compiler.enum({
|
|
53
|
-
expr:
|
|
54
|
-
allowed,
|
|
55
|
-
isAvailable: (
|
|
56
|
-
switch (v) {
|
|
57
|
-
case 'min-full': return !!s.price.min.value;
|
|
58
|
-
case 'max-full': return !!s.price.max.value;
|
|
59
|
-
case 'min-full-monthly': return !!s.price.monthly.min.value;
|
|
60
|
-
case 'max-full-monthly': return !!s.price.monthly.max.value;
|
|
61
|
-
case 'min-discounted': return !!s.discountedPrice.min.value;
|
|
62
|
-
case 'max-discounted': return !!s.discountedPrice.max.value;
|
|
63
|
-
case 'min-discounted-monthly': return !!s.discountedPrice.monthly.min.value;
|
|
64
|
-
case 'max-discounted-monthly': return !!s.discountedPrice.monthly.max.value;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
66
|
+
expr: storeContextPrice,
|
|
67
|
+
allowed: STATE_PRICE_TOKENS,
|
|
68
|
+
isAvailable: (token) => STATE_PRICE_AVAILABLE[token](state)
|
|
67
69
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
el.innerHTML = s.price.min.fmt;
|
|
71
|
-
return;
|
|
72
|
-
case 'max-full':
|
|
73
|
-
el.innerHTML = s.price.max.fmt;
|
|
74
|
-
return;
|
|
75
|
-
case 'min-full-monthly':
|
|
76
|
-
el.innerHTML = s.price.monthly.min.fmt;
|
|
77
|
-
return;
|
|
78
|
-
case 'max-full-monthly':
|
|
79
|
-
el.innerHTML = s.price.monthly.max.fmt;
|
|
80
|
-
return;
|
|
81
|
-
case 'min-discounted':
|
|
82
|
-
el.innerHTML = s.discountedPrice.min.fmt;
|
|
83
|
-
return;
|
|
84
|
-
case 'max-discounted':
|
|
85
|
-
el.innerHTML = s.discountedPrice.max.fmt;
|
|
86
|
-
return;
|
|
87
|
-
case 'min-discounted-monthly':
|
|
88
|
-
el.innerHTML = s.discountedPrice.monthly.min.fmt;
|
|
89
|
-
return;
|
|
90
|
-
case 'max-discounted-monthly':
|
|
91
|
-
el.innerHTML = s.discountedPrice.monthly.max.fmt;
|
|
92
|
-
return;
|
|
70
|
+
if (chosen) {
|
|
71
|
+
el.textContent = STATE_PRICE_RENDER[chosen](state);
|
|
93
72
|
}
|
|
94
73
|
}
|
|
95
74
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"price.js","sourceRoot":"","sources":["../../../../src/renders/attributes/price.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,oBAAoB,CAAU,CAAC;AAIlG,MAAM,kBAAkB,GAAG;IACzB,UAAU;IACV,UAAU;IACV,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AAIX,MAAM,sBAAsB,GAAG;IAC7B,MAAM,EAAgB,CAAC,MAAiB,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5F,YAAY,EAAU,CAAC,MAAiB,EAAE,E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AK,CAAC,CAAC;QACrD,CAAC;IACH,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport type { UnifiedContext } from '../context';\nimport { isPresent } from './utilty';\n\nconst OPTION_PRICE_TOKENS = ['full', 'discounted', 'full-monthly', 'discounted-monthly'] as const;\ntype OptionPriceToken = typeof OPTION_PRICE_TOKENS[number];\ntype OptionCtx = NonNullable<UnifiedContext['option']>;\n\nconst STATE_PRICE_TOKENS = [\n 'min-full',\n 'max-full',\n 'min-discounted',\n 'max-discounted',\n 'min-full-monthly',\n 'max-full-monthly',\n 'min-discounted-monthly',\n 'max-discounted-monthly'\n] as const;\ntype StatePriceToken = typeof STATE_PRICE_TOKENS[number];\ntype StateCtx = NonNullable<UnifiedContext['state']>;\n\nconst OPTION_PRICE_AVAILABLE = {\n 'full' : (option: OptionCtx) => isPresent(option.getPrice({ currency: false })),\n 'discounted' : (option: OptionCtx) => isPresent(option.getDiscountedPrice({ currency: false })),\n 'full-monthly' : (option: OptionCtx) => isPresent(option.getPrice({ currency: false, monthly: true })),\n 'discounted-monthly': (option: OptionCtx) => isPresent(option.getDiscountedPrice({ currency: false, monthly: true }))\n} satisfies Record<OptionPriceToken, (option: OptionCtx) => boolean>;\n\nconst OPTION_PRICE_RENDER = {\n 'full' : (option: OptionCtx) => option.getPrice(),\n 'discounted' : (option: OptionCtx) => option.getDiscountedPrice(),\n 'full-monthly' : (option: OptionCtx) => option.getPrice({ monthly: true }),\n 'discounted-monthly': (option: OptionCtx) => option.getDiscountedPrice({ monthly: true })\n} satisfies Record<OptionPriceToken, (option: OptionCtx) => string>;\n\nconst STATE_PRICE_AVAILABLE = {\n 'min-full' : (state: StateCtx) => isPresent(state.price.min.value),\n 'max-full' : (state: StateCtx) => isPresent(state.price.max.value),\n 'min-full-monthly' : (state: StateCtx) => isPresent(state.price.monthly.min.value),\n 'max-full-monthly' : (state: StateCtx) => isPresent(state.price.monthly.max.value),\n 'min-discounted' : (state: StateCtx) => isPresent(state.discountedPrice.min.value),\n 'max-discounted' : (state: StateCtx) => isPresent(state.discountedPrice.max.value),\n 'min-discounted-monthly': (state: StateCtx) => isPresent(state.discountedPrice.monthly.min.value),\n 'max-discounted-monthly': (state: StateCtx) => isPresent(state.discountedPrice.monthly.max.value)\n} satisfies Record<StatePriceToken, (state: StateCtx) => boolean>;\n\nconst STATE_PRICE_RENDER = {\n 'min-full' : (state: StateCtx) => state.price.min.fmt,\n 'max-full' : (state: StateCtx) => state.price.max.fmt,\n 'min-full-monthly' : (state: StateCtx) => state.price.monthly.min.fmt,\n 'max-full-monthly' : (state: StateCtx) => state.price.monthly.max.fmt,\n 'min-discounted' : (state: StateCtx) => state.discountedPrice.min.fmt,\n 'max-discounted' : (state: StateCtx) => state.discountedPrice.max.fmt,\n 'min-discounted-monthly': (state: StateCtx) => state.discountedPrice.monthly.min.fmt,\n 'max-discounted-monthly': (state: StateCtx) => state.discountedPrice.monthly.max.fmt\n} satisfies Record<StatePriceToken, (state: StateCtx) => string>;\n\n// Handles both data-store-price (option-level) and data-store-context-price (state-level)\nexport const handlePrice = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storePrice, storeContextPrice } = el.dataset;\n const option = ctx.option;\n\n // Option-level price\n if (storePrice && option) {\n const chosen = Compiler.enum<OptionPriceToken>({\n expr : storePrice,\n allowed : OPTION_PRICE_TOKENS,\n isAvailable: (token) => OPTION_PRICE_AVAILABLE[token](option)\n });\n\n if (chosen) {\n el.textContent = OPTION_PRICE_RENDER[chosen](option);\n return;\n }\n }\n\n const state = ctx.state;\n\n // State-level price\n if (storeContextPrice && state) {\n const chosen = Compiler.enum<StatePriceToken>({\n expr : storeContextPrice,\n allowed : STATE_PRICE_TOKENS,\n isAvailable: (token) => STATE_PRICE_AVAILABLE[token](state)\n });\n\n if (chosen) {\n el.textContent = STATE_PRICE_RENDER[chosen](state);\n }\n }\n};\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Compiler } from '../../dsl/compilers/index.js';
|
|
2
2
|
import { formatSubscription } from '../../renders/format.js';
|
|
3
3
|
export const handleSubscription = (el, ctx) => {
|
|
4
|
-
|
|
4
|
+
const { storeSubscription, storeSubscriptionType, storeTextSingle, storeTextMany } = el.dataset;
|
|
5
|
+
if (storeSubscription === undefined)
|
|
5
6
|
return;
|
|
6
7
|
const option = ctx.option;
|
|
7
8
|
if (!option)
|
|
8
9
|
return;
|
|
9
|
-
const
|
|
10
|
-
const type = ds.storeSubscriptionType === 'months' ? 'months' : 'years';
|
|
10
|
+
const type = storeSubscriptionType === 'months' ? 'months' : 'years';
|
|
11
11
|
// input
|
|
12
12
|
if (el instanceof HTMLInputElement) {
|
|
13
13
|
const value = type === 'months' ? option.getSubscription() : Math.floor(option.getSubscription() / 12);
|
|
@@ -16,19 +16,19 @@ export const handleSubscription = (el, ctx) => {
|
|
|
16
16
|
}
|
|
17
17
|
// select
|
|
18
18
|
if (el instanceof HTMLSelectElement) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const available = (provided !== undefined ? Compiler.array(provided) : undefined) ?? product.getSubscriptions().values;
|
|
19
|
+
const selectedSubscription = option.getSubscription();
|
|
20
|
+
const available = Compiler.array(storeSubscription) ?? option.getProduct().getSubscriptions().values;
|
|
22
21
|
el.options.length = 0;
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
22
|
+
for (const sub of available) {
|
|
23
|
+
const isSelected = sub === selectedSubscription;
|
|
24
|
+
const text = formatSubscription(sub, type, storeTextSingle, storeTextMany);
|
|
25
|
+
const htmlOption = new Option(text, String(sub), isSelected, isSelected);
|
|
26
26
|
htmlOption.setAttribute('data-store-set-subscription', String(sub));
|
|
27
27
|
el.add(htmlOption);
|
|
28
|
-
}
|
|
28
|
+
}
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
// generic content
|
|
32
|
-
el.
|
|
32
|
+
el.textContent = formatSubscription(option.getSubscription(), type, storeTextSingle, storeTextMany);
|
|
33
33
|
};
|
|
34
34
|
//# sourceMappingURL=subscription.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACzE,
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../../../src/renders/attributes/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACzE,MAAM,EACJ,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,aAAa,EACd,GAAG,EAAE,CAAC,OAAO,CAAC;IACf,IAAI,iBAAiB,KAAK,SAAS;QAAE,OAAO;IAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,IAAI,GAAG,qBAAqB,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAErE,QAAQ;IACR,IAAI,EAAE,YAAY,gBAAgB,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;QACvG,EAAE,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO;IACT,CAAC;IAED,SAAS;IACT,IAAI,EAAE,YAAY,iBAAiB,EAAE,CAAC;QACpC,MAAM,oBAAoB,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC;QACtD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC,gBAAgB,EAAE,CAAC,MAAM,CAAC;QAErG,EAAE,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;QACtB,KAAK,MAAM,GAAG,IAAI,SAAS,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,GAAG,KAAK,oBAAoB,CAAC;YAChD,MAAM,IAAI,GAAG,kBAAkB,CAC7B,GAAG,EACH,IAAI,EACJ,eAAe,EACf,aAAa,CACd,CAAC;YACF,MAAM,UAAU,GAAG,IAAI,MAAM,CAC3B,IAAI,EACJ,MAAM,CAAC,GAAG,CAAC,EACX,UAAU,EACV,UAAU,CACX,CAAC;YACF,UAAU,CAAC,YAAY,CAAC,6BAA6B,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YACpE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACrB,CAAC;QACD,OAAO;IACT,CAAC;IAED,kBAAkB;IAClB,EAAE,CAAC,WAAW,GAAG,kBAAkB,CAAC,MAAM,CAAC,eAAe,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,aAAa,CAAC,CAAC;AACtG,CAAC,CAAC","sourcesContent":["import { Compiler } from '@/dsl/compilers';\nimport { formatSubscription } from '@/renders/format';\nimport type { UnifiedContext } from '../context';\n\nexport const handleSubscription = (el: HTMLElement, ctx: UnifiedContext) => {\n const {\n storeSubscription,\n storeSubscriptionType,\n storeTextSingle,\n storeTextMany\n } = el.dataset;\n if (storeSubscription === undefined) return;\n const option = ctx.option;\n if (!option) return;\n\n const type = storeSubscriptionType === 'months' ? 'months' : 'years';\n\n // input\n if (el instanceof HTMLInputElement) {\n const value = type === 'months' ? option.getSubscription() : Math.floor(option.getSubscription() / 12);\n el.value = String(value);\n return;\n }\n\n // select\n if (el instanceof HTMLSelectElement) {\n const selectedSubscription = option.getSubscription();\n const available = Compiler.array(storeSubscription) ?? option.getProduct().getSubscriptions().values;\n\n el.options.length = 0;\n for (const sub of available) {\n const isSelected = sub === selectedSubscription;\n const text = formatSubscription(\n sub,\n type,\n storeTextSingle,\n storeTextMany\n );\n const htmlOption = new Option(\n text,\n String(sub),\n isSelected,\n isSelected\n );\n htmlOption.setAttribute('data-store-set-subscription', String(sub));\n el.add(htmlOption);\n }\n return;\n }\n\n // generic content\n el.textContent = formatSubscription(option.getSubscription(), type, storeTextSingle, storeTextMany);\n};\n"]}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { resolveAnchor } from './utilty.js';
|
|
1
2
|
export const handleTrialLink = (el, ctx) => {
|
|
2
|
-
const
|
|
3
|
-
if (
|
|
3
|
+
const { storeTrialLink } = el.dataset;
|
|
4
|
+
if (storeTrialLink === undefined)
|
|
4
5
|
return;
|
|
5
6
|
const option = ctx.option;
|
|
6
7
|
if (!option)
|
|
7
8
|
return;
|
|
8
|
-
const link = el
|
|
9
|
+
const link = resolveAnchor(el);
|
|
9
10
|
if (!link)
|
|
10
11
|
return;
|
|
11
|
-
link.href = option.getTrialLink() ||
|
|
12
|
+
link.href = option.getTrialLink() || '';
|
|
12
13
|
};
|
|
13
14
|
//# sourceMappingURL=trialLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trialLink.js","sourceRoot":"","sources":["../../../../src/renders/attributes/trialLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trialLink.js","sourceRoot":"","sources":["../../../../src/renders/attributes/trialLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAe,EAAE,GAAmB,EAAE,EAAE;IACtE,MAAM,EAAE,cAAc,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC;IACtC,IAAI,cAAc,KAAK,SAAS;QAAE,OAAO;IACzC,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,IAAI,CAAC,MAAM;QAAE,OAAO;IAEpB,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO;IAElB,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,YAAY,EAAE,IAAI,EAAE,CAAC;AAC1C,CAAC,CAAC","sourcesContent":["import type { UnifiedContext } from '../context';\nimport { resolveAnchor } from './utilty';\n\nexport const handleTrialLink = (el: HTMLElement, ctx: UnifiedContext) => {\n const { storeTrialLink } = el.dataset;\n if (storeTrialLink === undefined) return;\n const option = ctx.option;\n if (!option) return;\n\n const link = resolveAnchor(el);\n if (!link) return;\n\n link.href = option.getTrialLink() || '';\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utilty.js","sourceRoot":"","sources":["../../../../src/renders/attributes/utilty.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAE5F,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAe,EAA4B,EAAE,CACzE,EAAE,YAAY,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAoB,GAAG,CAAC,CAAC","sourcesContent":["export const isPresent = (value: unknown): boolean => value !== null && value !== undefined;\n\nexport const resolveAnchor = (el: HTMLElement): HTMLAnchorElement | null =>\n el instanceof HTMLAnchorElement ? el : el.querySelector<HTMLAnchorElement>('a');\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/renders/context.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exts/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: option.getTrialLink()\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 +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;IACt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E,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,2 +1,2 @@
|
|
|
1
|
-
declare const registerRenderNodes: (root: HTMLElement | ShadowRoot) => void;
|
|
1
|
+
declare const registerRenderNodes: (root: HTMLElement | ShadowRoot) => () => void;
|
|
2
2
|
export { registerRenderNodes };
|
|
@@ -1,69 +1,57 @@
|
|
|
1
1
|
import { cleanupRenderNode, DATA_HIDE_NODE, DATA_RENDER_NODE, handleRenderNode } from "./utility.js";
|
|
2
2
|
const selectors = [DATA_HIDE_NODE, DATA_RENDER_NODE];
|
|
3
|
+
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)) {
|
|
8
|
+
fn(root);
|
|
9
|
+
}
|
|
10
|
+
root
|
|
11
|
+
.querySelectorAll(selectorStr)
|
|
12
|
+
.forEach(fn);
|
|
13
|
+
};
|
|
14
|
+
const forEachShadowRoot = (root, fn) => {
|
|
15
|
+
if (root instanceof HTMLElement && root.hasAttribute('shadow') && root.shadowRoot) {
|
|
16
|
+
fn(root.shadowRoot);
|
|
17
|
+
}
|
|
18
|
+
root
|
|
19
|
+
.querySelectorAll(SHADOW_HOST_SELECTOR)
|
|
20
|
+
.forEach((host) => host.shadowRoot && fn(host.shadowRoot));
|
|
21
|
+
};
|
|
3
22
|
const registerRenderNodes = (root) => {
|
|
4
23
|
const observed = new WeakSet();
|
|
5
|
-
const
|
|
24
|
+
const observers = new WeakMap();
|
|
25
|
+
const activeObservers = new Set();
|
|
26
|
+
const disconnect = (node) => {
|
|
27
|
+
const observer = observers.get(node);
|
|
28
|
+
if (!observer)
|
|
29
|
+
return;
|
|
30
|
+
observer.disconnect();
|
|
31
|
+
observers.delete(node);
|
|
32
|
+
activeObservers.delete(observer);
|
|
33
|
+
};
|
|
6
34
|
const cleanupShadowTree = (shadowRoot) => {
|
|
7
|
-
shadowRoot
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
shadowRoot
|
|
11
|
-
.querySelectorAll('[shadow]')
|
|
12
|
-
.forEach(host => host.shadowRoot && cleanupShadowTree(host.shadowRoot));
|
|
35
|
+
forEachRenderNode(shadowRoot, cleanupRenderNode);
|
|
36
|
+
forEachShadowRoot(shadowRoot, cleanupShadowTree);
|
|
37
|
+
disconnect(shadowRoot);
|
|
13
38
|
};
|
|
14
39
|
const handleAdded = (node) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
node
|
|
19
|
-
.querySelectorAll(selectorStr)
|
|
20
|
-
.forEach(handleRenderNode);
|
|
21
|
-
if (node.hasAttribute('shadow') && node.shadowRoot) {
|
|
22
|
-
watch(node.shadowRoot);
|
|
23
|
-
}
|
|
24
|
-
node
|
|
25
|
-
.querySelectorAll('[shadow]')
|
|
26
|
-
.forEach(host => host.shadowRoot && watch(host.shadowRoot));
|
|
40
|
+
forEachRenderNode(node, handleRenderNode);
|
|
41
|
+
forEachShadowRoot(node, watch);
|
|
27
42
|
};
|
|
28
43
|
const handleRemoved = (node) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
node
|
|
33
|
-
.querySelectorAll(selectorStr)
|
|
34
|
-
.forEach(n => cleanupRenderNode(n));
|
|
35
|
-
if (node.hasAttribute('shadow') && node.shadowRoot) {
|
|
36
|
-
cleanupShadowTree(node.shadowRoot);
|
|
37
|
-
}
|
|
38
|
-
node
|
|
39
|
-
.querySelectorAll('[shadow]')
|
|
40
|
-
.forEach(host => host.shadowRoot && cleanupShadowTree(host.shadowRoot));
|
|
44
|
+
forEachRenderNode(node, cleanupRenderNode);
|
|
45
|
+
forEachShadowRoot(node, cleanupShadowTree);
|
|
41
46
|
};
|
|
42
47
|
const watch = (node) => {
|
|
43
48
|
if (observed.has(node))
|
|
44
49
|
return;
|
|
45
50
|
observed.add(node);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
node
|
|
50
|
-
.querySelectorAll(selectorStr)
|
|
51
|
-
.forEach(handleRenderNode);
|
|
52
|
-
if (node instanceof HTMLElement && node.hasAttribute('shadow') && node.shadowRoot) {
|
|
53
|
-
watch(node.shadowRoot);
|
|
54
|
-
}
|
|
55
|
-
if ('querySelectorAll' in node) {
|
|
56
|
-
node
|
|
57
|
-
.querySelectorAll('[shadow]')
|
|
58
|
-
.forEach(host => host.shadowRoot && watch(host.shadowRoot));
|
|
59
|
-
}
|
|
51
|
+
forEachRenderNode(node, handleRenderNode);
|
|
52
|
+
forEachShadowRoot(node, watch);
|
|
60
53
|
const mo = new MutationObserver(muts => {
|
|
61
54
|
for (const m of muts) {
|
|
62
|
-
if (m.type === 'attributes') {
|
|
63
|
-
const attr = m.attributeName?.toLowerCase();
|
|
64
|
-
if (attr === 'class' || attr === 'style')
|
|
65
|
-
continue; // Ignore cosmetic-only mutations
|
|
66
|
-
}
|
|
67
55
|
for (const added of Array.from(m.addedNodes)) {
|
|
68
56
|
if (!(added instanceof HTMLElement))
|
|
69
57
|
continue;
|
|
@@ -80,8 +68,16 @@ const registerRenderNodes = (root) => {
|
|
|
80
68
|
childList: true,
|
|
81
69
|
subtree: true
|
|
82
70
|
});
|
|
71
|
+
observers.set(node, mo);
|
|
72
|
+
activeObservers.add(mo);
|
|
83
73
|
};
|
|
84
74
|
watch(root);
|
|
75
|
+
return () => {
|
|
76
|
+
for (const observer of activeObservers) {
|
|
77
|
+
observer.disconnect();
|
|
78
|
+
}
|
|
79
|
+
activeObservers.clear();
|
|
80
|
+
};
|
|
85
81
|
};
|
|
86
82
|
export { registerRenderNodes };
|
|
87
83
|
//# 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;
|
|
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;SAC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,OAAO,EAAI,IAAI;SAChB,CAAC,CAAC;QACH,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxB,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC,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 +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;IACrB,uBAAuB;CACf,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"}
|
|
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;IACrB,uBAAuB;CACf,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 'data-store-trial-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"]}
|