@revenuecat/purchases-ui-js 2.0.0 → 2.0.2

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 (105) hide show
  1. package/dist/components/button/Button.svelte +1 -5
  2. package/dist/components/button/ButtonNode.stories.svelte +57 -71
  3. package/dist/components/button/ButtonNode.stories.svelte.d.ts +0 -8
  4. package/dist/components/button/ButtonNode.svelte +10 -21
  5. package/dist/components/button/ButtonNode.svelte.d.ts +2 -2
  6. package/dist/components/button/button-utils.d.ts +2 -2
  7. package/dist/components/footer/Footer.stories.svelte +26 -22
  8. package/dist/components/footer/Footer.stories.svelte.d.ts +0 -5
  9. package/dist/components/footer/Footer.svelte +3 -10
  10. package/dist/components/footer/Footer.svelte.d.ts +1 -1
  11. package/dist/components/image/Image.stories.svelte +27 -19
  12. package/dist/components/image/Image.svelte +18 -17
  13. package/dist/components/image/image-utils.d.ts +2 -1
  14. package/dist/components/image/image-utils.js +2 -2
  15. package/dist/components/package/Package.stories.svelte +31 -31
  16. package/dist/components/package/Package.stories.svelte.d.ts +0 -6
  17. package/dist/components/package/Package.svelte +19 -30
  18. package/dist/components/package/Package.svelte.d.ts +1 -1
  19. package/dist/components/paywall/Node.svelte +26 -50
  20. package/dist/components/paywall/Node.svelte.d.ts +11 -14
  21. package/dist/components/paywall/Paywall.stories.svelte +21 -78
  22. package/dist/components/paywall/Paywall.svelte +75 -100
  23. package/dist/components/paywall/Paywall.svelte.d.ts +4 -4
  24. package/dist/components/paywall/paywall-utils.d.ts +3 -2
  25. package/dist/components/paywall/paywall-utils.js +5 -5
  26. package/dist/components/purchase-button/PurchaseButton.stories.svelte +29 -31
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +0 -5
  28. package/dist/components/purchase-button/PurchaseButton.svelte +9 -20
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -1
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +1 -1
  31. package/dist/components/stack/Stack.stories.svelte +17 -94
  32. package/dist/components/stack/Stack.svelte +18 -48
  33. package/dist/components/stack/stack-utils.d.ts +4 -3
  34. package/dist/components/stack/stack-utils.js +7 -10
  35. package/dist/components/text/TextNode.stories.svelte +45 -152
  36. package/dist/components/text/TextNode.svelte +15 -23
  37. package/dist/components/text/text-utils.d.ts +7 -6
  38. package/dist/components/text/text-utils.js +7 -7
  39. package/dist/components/timeline/Timeline.stories.svelte +37 -48
  40. package/dist/components/timeline/Timeline.svelte +0 -2
  41. package/dist/components/timeline/TimelineItem.svelte +28 -11
  42. package/dist/components/timeline/timeline-utils.d.ts +3 -3
  43. package/dist/components/timeline/timeline-utils.js +7 -17
  44. package/dist/data/entities.d.ts +54 -145
  45. package/dist/index.d.ts +10 -10
  46. package/dist/index.js +10 -10
  47. package/dist/stores/color-mode.d.ts +6 -0
  48. package/dist/stores/color-mode.js +15 -0
  49. package/dist/stores/localization.d.ts +13 -0
  50. package/dist/stores/localization.js +26 -0
  51. package/dist/stores/paywall.d.ts +11 -0
  52. package/dist/stores/paywall.js +13 -0
  53. package/dist/stores/variables.d.ts +5 -0
  54. package/dist/stores/variables.js +14 -0
  55. package/dist/stories/fixtures.d.ts +1 -1
  56. package/dist/stories/fixtures.js +30 -135
  57. package/dist/stories/localization-decorator.d.ts +3 -0
  58. package/dist/stories/localization-decorator.js +7 -0
  59. package/dist/stories/paywall-decorator.d.ts +2 -0
  60. package/dist/stories/paywall-decorator.js +19 -0
  61. package/dist/stories/variables-decorator.d.ts +3 -0
  62. package/dist/stories/variables-decorator.js +9 -0
  63. package/dist/stories/with-layout.svelte +4 -4
  64. package/dist/types/alignment.d.ts +19 -0
  65. package/dist/types/background.d.ts +18 -0
  66. package/dist/types/background.js +1 -0
  67. package/dist/types/colors.d.ts +34 -0
  68. package/dist/types/colors.js +1 -0
  69. package/dist/types/component.d.ts +6 -0
  70. package/dist/types/component.js +1 -0
  71. package/dist/types/components/button.d.ts +36 -0
  72. package/dist/types/components/button.js +1 -0
  73. package/dist/types/components/footer.d.ts +5 -0
  74. package/dist/types/components/footer.js +1 -0
  75. package/dist/types/components/package.d.ts +8 -0
  76. package/dist/types/components/package.js +1 -0
  77. package/dist/types/components/purchase-button.d.ts +5 -0
  78. package/dist/types/components/purchase-button.js +1 -0
  79. package/dist/types/localization.d.ts +4 -0
  80. package/dist/types/localization.js +1 -0
  81. package/dist/types/media.d.ts +18 -0
  82. package/dist/types/media.js +1 -0
  83. package/dist/types.d.ts +5 -35
  84. package/dist/ui/atoms/typography.stories.svelte +7 -13
  85. package/dist/ui/atoms/typography.stories.svelte.d.ts +1 -1
  86. package/dist/ui/atoms/typography.svelte +1 -1
  87. package/dist/ui/layout/main-block.svelte +2 -2
  88. package/dist/ui/molecules/button.stories.svelte +8 -15
  89. package/dist/ui/molecules/button.svelte +3 -2
  90. package/dist/ui/molecules/button.svelte.d.ts +2 -26
  91. package/dist/ui/molecules/types.d.ts +2 -1
  92. package/dist/ui/theme/theme.d.ts +2 -2
  93. package/dist/ui/theme/theme.js +2 -2
  94. package/dist/ui/theme/utils.d.ts +2 -2
  95. package/dist/utils/style-utils.d.ts +13 -11
  96. package/dist/utils/style-utils.js +21 -27
  97. package/dist/utils/variable-utils.d.ts +1 -38
  98. package/dist/utils/variable-utils.js +6 -48
  99. package/dist/web-components/index.css +1 -1
  100. package/dist/web-components/index.js +610 -657
  101. package/package.json +33 -36
  102. package/dist/data/state.d.ts +0 -9
  103. package/dist/stores/theme.d.ts +0 -1
  104. package/dist/stores/theme.js +0 -17
  105. /package/dist/{data/state.js → types/alignment.js} +0 -0
@@ -5,20 +5,19 @@
5
5
  import {
6
6
  alignmentPaywallData,
7
7
  calmPaywallData,
8
+ colorModeOverrideTemplate,
9
+ e2eTestTemplate,
10
+ errorPaywallData,
11
+ fallbackPaywallData,
8
12
  fontsPaywallData,
13
+ gradientPaywallData,
9
14
  pastaPaywallData,
10
15
  paywallData,
11
- gradientPaywallData,
12
- variablesPastaPaywallData,
16
+ paywallWithFooter,
13
17
  posterMakerTemplate,
14
- e2eTestTemplate,
18
+ variablesPastaPaywallData,
15
19
  zStackTemplate,
16
- colorModeOverrideTemplate,
17
- errorPaywallData,
18
- paywallWithFooter,
19
- fallbackPaywallData,
20
20
  } from "../../stories/fixtures";
21
- import { fn } from "@storybook/test";
22
21
  import type { VariableDictionary } from "../../utils/variable-utils";
23
22
 
24
23
  const { Story } = defineMeta({
@@ -26,7 +25,14 @@
26
25
  component: Paywall,
27
26
  tags: ["autodocs"],
28
27
  argTypes: {},
29
- args: {},
28
+ args: {
29
+ onPurchaseClicked: (selectedPackageId: string) =>
30
+ alert(`Purchase package ${selectedPackageId}`),
31
+ onBackClicked: () => alert("Go back"),
32
+ onVisitCustomerCenterClicked: () => alert("Visit customer center"),
33
+ onRestorePurchasesClicked: () => alert("Restore purchases"),
34
+ onNavigateToUrlClicked: (url: string) => alert(`Navigate to ${url}`),
35
+ },
30
36
  });
31
37
  </script>
32
38
 
@@ -35,10 +41,6 @@
35
41
  name="Primary"
36
42
  args={{
37
43
  paywallData: paywallData,
38
- onPurchaseClicked: fn(),
39
- onBackClicked: fn(),
40
- onNavigateToUrlClicked: fn(),
41
- onRestorePurchasesClicked: fn(),
42
44
  }}
43
45
  />
44
46
 
@@ -47,10 +49,6 @@
47
49
  args={{
48
50
  paywallData: paywallData,
49
51
  selectedLocale: "it_IT",
50
- onPurchaseClicked: fn(),
51
- onBackClicked: fn(),
52
- onNavigateToUrlClicked: fn(),
53
- onRestorePurchasesClicked: fn(),
54
52
  }}
55
53
  />
56
54
 
@@ -59,10 +57,6 @@
59
57
  args={{
60
58
  paywallData: alignmentPaywallData,
61
59
  selectedLocale: "en_US",
62
- onPurchaseClicked: fn(),
63
- onBackClicked: fn(),
64
- onNavigateToUrlClicked: fn(),
65
- onRestorePurchasesClicked: fn(),
66
60
  }}
67
61
  />
68
62
 
@@ -71,10 +65,6 @@
71
65
  args={{
72
66
  paywallData: fontsPaywallData,
73
67
  selectedLocale: "en_US",
74
- onPurchaseClicked: fn(),
75
- onBackClicked: fn(),
76
- onNavigateToUrlClicked: fn(),
77
- onRestorePurchasesClicked: fn(),
78
68
  }}
79
69
  />
80
70
 
@@ -83,10 +73,6 @@
83
73
  args={{
84
74
  paywallData: pastaPaywallData,
85
75
  selectedLocale: "en_US",
86
- onPurchaseClicked: fn(),
87
- onBackClicked: fn(),
88
- onNavigateToUrlClicked: fn(),
89
- onRestorePurchasesClicked: fn(),
90
76
  }}
91
77
  />
92
78
  <Story
@@ -94,10 +80,6 @@
94
80
  args={{
95
81
  paywallData: variablesPastaPaywallData,
96
82
  selectedLocale: "en_US",
97
- onPurchaseClicked: fn(),
98
- onBackClicked: fn(),
99
- onNavigateToUrlClicked: fn(),
100
- onRestorePurchasesClicked: fn(),
101
83
  variablesPerPackage: {
102
84
  trial: {
103
85
  product_name: "This was a variable: Product A",
@@ -123,10 +105,6 @@
123
105
  args={{
124
106
  paywallData: calmPaywallData,
125
107
  selectedLocale: "en_US",
126
- onPurchaseClicked: fn(),
127
- onBackClicked: fn(),
128
- onNavigateToUrlClicked: fn(),
129
- onRestorePurchasesClicked: fn(),
130
108
  }}
131
109
  />
132
110
 
@@ -134,10 +112,6 @@
134
112
  name="Healthy Cat (Gradient)"
135
113
  args={{
136
114
  paywallData: gradientPaywallData,
137
- onPurchaseClicked: fn(),
138
- onBackClicked: fn(),
139
- onNavigateToUrlClicked: fn(),
140
- onRestorePurchasesClicked: fn(),
141
115
  }}
142
116
  />
143
117
 
@@ -145,10 +119,6 @@
145
119
  name="Dynamic state style overrides"
146
120
  args={{
147
121
  paywallData: e2eTestTemplate,
148
- onPurchaseClicked: fn(),
149
- onBackClicked: fn(),
150
- onNavigateToUrlClicked: fn(),
151
- onRestorePurchasesClicked: fn(),
152
122
  }}
153
123
  />
154
124
 
@@ -163,25 +133,26 @@
163
133
  ...e2eTestTemplate.components_config.base,
164
134
  background: {
165
135
  type: "image",
136
+ fit_mode: "fit",
137
+ color_overlay: null,
166
138
  value: {
167
139
  light: {
140
+ width: 1792,
141
+ height: 1024,
142
+ original: "https://assets.pawwalls.com/1005820_1732028636.jpeg",
168
143
  heic: "https://assets.pawwalls.com/1005820_1732028636.heic",
169
144
  heic_low_res:
170
145
  "https://assets.pawwalls.com/1005820_low_res_1732028636.heic",
171
- original: "https://assets.pawwalls.com/1005820_1732028636.jpeg",
172
146
  webp: "https://assets.pawwalls.com/1005820_1732028636.webp",
173
147
  webp_low_res:
174
148
  "https://assets.pawwalls.com/1005820_low_res_1732028636.webp",
175
149
  },
150
+ dark: null,
176
151
  },
177
152
  },
178
153
  },
179
154
  },
180
155
  },
181
- onPurchaseClicked: fn(),
182
- onBackClicked: fn(),
183
- onNavigateToUrlClicked: fn(),
184
- onRestorePurchasesClicked: fn(),
185
156
  }}
186
157
  />
187
158
 
@@ -189,10 +160,6 @@
189
160
  name="Poster Maker"
190
161
  args={{
191
162
  paywallData: posterMakerTemplate,
192
- onPurchaseClicked: fn(),
193
- onBackClicked: fn(),
194
- onNavigateToUrlClicked: fn(),
195
- onRestorePurchasesClicked: fn(),
196
163
  }}
197
164
  />
198
165
 
@@ -200,10 +167,6 @@
200
167
  name="E2E Test with variables"
201
168
  args={{
202
169
  paywallData: e2eTestTemplate,
203
- onPurchaseClicked: fn(),
204
- onBackClicked: fn(),
205
- onNavigateToUrlClicked: fn(),
206
- onRestorePurchasesClicked: fn(),
207
170
  variablesPerPackage: {
208
171
  $rc_annual: {
209
172
  product_name: "Yearly sub",
@@ -273,10 +236,6 @@
273
236
  name="Z Stack"
274
237
  args={{
275
238
  paywallData: zStackTemplate,
276
- onPurchaseClicked: fn(),
277
- onBackClicked: fn(),
278
- onNavigateToUrlClicked: fn(),
279
- onRestorePurchasesClicked: fn(),
280
239
  }}
281
240
  />
282
241
 
@@ -284,10 +243,6 @@
284
243
  name="Color Mode Override"
285
244
  args={{
286
245
  paywallData: colorModeOverrideTemplate,
287
- onPurchaseClicked: fn(),
288
- onBackClicked: fn(),
289
- onNavigateToUrlClicked: fn(),
290
- onRestorePurchasesClicked: fn(),
291
246
  preferredColorMode: "dark",
292
247
  }}
293
248
  />
@@ -296,10 +251,6 @@
296
251
  name="Invalid component type"
297
252
  args={{
298
253
  paywallData: errorPaywallData,
299
- onPurchaseClicked: fn(),
300
- onBackClicked: fn(),
301
- onNavigateToUrlClicked: fn(),
302
- onRestorePurchasesClicked: fn(),
303
254
  preferredColorMode: "dark",
304
255
  onError: (error: unknown) => alert(`Error - ${error}`),
305
256
  }}
@@ -309,10 +260,6 @@
309
260
  name="Fallback Paywall"
310
261
  args={{
311
262
  paywallData: fallbackPaywallData,
312
- onPurchaseClicked: fn(),
313
- onBackClicked: fn(),
314
- onNavigateToUrlClicked: fn(),
315
- onRestorePurchasesClicked: fn(),
316
263
  preferredColorMode: "dark",
317
264
  onError: (error: unknown) => console.error(`Error - ${error}`),
318
265
  }}
@@ -322,9 +269,5 @@
322
269
  name="Sticky Footer"
323
270
  args={{
324
271
  paywallData: paywallWithFooter,
325
- onPurchaseClicked: fn(),
326
- onBackClicked: fn(),
327
- onNavigateToUrlClicked: fn(),
328
- onRestorePurchasesClicked: fn(),
329
272
  }}
330
273
  />
@@ -1,160 +1,135 @@
1
1
  <script lang="ts">
2
- import type {
3
- Extra,
4
- NavigateToAction,
5
- PaywallData,
6
- StackProps,
7
- SupportedActions,
8
- } from "../../data/entities";
2
+ import type { PaywallData, StackProps } from "../../data/entities";
9
3
 
4
+ import Footer from "../footer/Footer.svelte";
10
5
  import Node from "./Node.svelte";
11
- import type { PurchaseState } from "../../data/state";
12
- import { findSelectedPackageId } from "../../utils/style-utils";
13
- import {
14
- getLabelById,
15
- type VariableDictionary,
16
- } from "../../utils/variable-utils";
17
6
  import {
18
7
  getBackgroundImageSource,
19
8
  getBackgroundStyles,
20
9
  } from "./paywall-utils";
21
- import { prefersDarkMode } from "../../stores/theme";
10
+ import { setColorModeContext } from "../../stores/color-mode";
11
+ import { setLocalizationContext } from "../../stores/localization";
12
+ import { setPaywallContext } from "../../stores/paywall";
13
+ import {
14
+ setVariablesContext,
15
+ type VariablesStore,
16
+ } from "../../stores/variables";
22
17
  import type { ColorMode } from "../../types";
23
- import Footer from "../footer/Footer.svelte";
24
- import { DEFAULT_COLOR_MODE } from "../../utils/constants";
18
+ import type { Action } from "../../types/components/button";
19
+ import { findSelectedPackageId } from "../../utils/style-utils";
20
+ import { type VariableDictionary } from "../../utils/variable-utils";
21
+ import { derived, readable, writable } from "svelte/store";
25
22
 
26
23
  interface Props {
27
24
  paywallData: PaywallData;
25
+ selectedLocale?: string;
26
+ variablesPerPackage?: Record<string, VariableDictionary>;
27
+ preferredColorMode?: ColorMode;
28
28
  onPurchaseClicked?: (selectedPackageId: string) => void;
29
29
  onBackClicked?: () => void;
30
30
  onVisitCustomerCenterClicked?: () => void;
31
31
  onRestorePurchasesClicked?: () => void;
32
32
  onNavigateToUrlClicked?: (url: string) => void;
33
- selectedLocale?: string;
34
- variablesPerPackage?: Record<string, VariableDictionary>;
35
- preferredColorMode?: ColorMode;
36
33
  onError?: (error: unknown) => void;
37
34
  }
38
35
 
39
36
  const {
40
37
  paywallData,
41
- onPurchaseClicked,
42
- onRestorePurchasesClicked,
43
- onNavigateToUrlClicked,
44
- onBackClicked,
45
- onVisitCustomerCenterClicked,
46
38
  selectedLocale,
47
39
  variablesPerPackage = {},
48
40
  preferredColorMode,
41
+ onPurchaseClicked,
42
+ onBackClicked,
43
+ onVisitCustomerCenterClicked,
44
+ onRestorePurchasesClicked,
45
+ onNavigateToUrlClicked,
49
46
  onError,
50
47
  }: Props = $props();
51
48
 
52
- let purchaseState: PurchaseState = $state({
53
- selectedPackageId: findSelectedPackageId(paywallData),
54
- locale: selectedLocale || paywallData.default_locale,
49
+ const getColorMode = setColorModeContext(() => preferredColorMode);
50
+ const colorMode = $derived(getColorMode());
51
+
52
+ const { getLocalizedString } = setLocalizationContext(() => ({
55
53
  defaultLocale: paywallData.default_locale,
56
- variablesPerPackage,
57
- colorMode:
58
- preferredColorMode || ($prefersDarkMode ? "dark" : DEFAULT_COLOR_MODE),
59
- });
54
+ selectedLocale,
55
+ localizations: paywallData.components_localizations!,
56
+ }));
60
57
 
61
- let variableDictionary = $state(
62
- variablesPerPackage[purchaseState.selectedPackageId || ""],
58
+ const selectedPackageId = writable<string | undefined>(
59
+ findSelectedPackageId(paywallData),
63
60
  );
64
61
 
65
- const onRestorePurchasesAction = (_: SupportedActions, _2?: Extra) => {
66
- onRestorePurchasesClicked?.();
67
- };
68
-
69
- const onNavigateBackAction = (_: SupportedActions, _2?: Extra) => {
70
- onBackClicked?.();
71
- };
72
-
73
- const onNavigateToUrl = (action: NavigateToAction, _?: Extra) => {
74
- if (action.destination === "customer_center") {
75
- onVisitCustomerCenterClicked?.();
62
+ const onPurchase = () => {
63
+ const packageId = $selectedPackageId;
64
+ if (packageId !== undefined) {
65
+ onPurchaseClicked?.(packageId);
76
66
  }
77
-
78
- if (!action.url) {
79
- return;
80
- }
81
-
82
- const localizedURL = getLabelById(
83
- action.url.url_lid,
84
- purchaseState.locale,
85
- purchaseState.defaultLocale,
86
- paywallData.components_localizations,
87
- );
88
- if (!localizedURL) {
89
- return;
90
- }
91
-
92
- onNavigateToUrlClicked?.(localizedURL);
93
67
  };
94
68
 
95
- const onSelectPackageAction = (_: SupportedActions, data?: Extra) => {
96
- purchaseState.selectedPackageId = data?.packageId as string | undefined;
97
- if (data?.packageId) {
98
- variableDictionary = variablesPerPackage[data.packageId as string];
99
- }
100
- };
101
-
102
- const onPurchaseAction = (_: SupportedActions, _2?: Extra) => {
103
- if (purchaseState.selectedPackageId === undefined) {
104
- return;
105
- }
106
- onPurchaseClicked?.(purchaseState.selectedPackageId);
107
- };
108
- const onAction = (action: SupportedActions, data?: Extra) => {
69
+ const onButtonAction = (action: Action) => {
109
70
  switch (action.type) {
110
- case "select_package":
111
- onSelectPackageAction(action, data);
112
- break;
113
- case "navigate_to":
114
- onNavigateToUrl(action, data);
115
- break;
116
71
  case "navigate_back":
117
- onNavigateBackAction(action, data);
118
- break;
72
+ onBackClicked?.();
73
+ return;
119
74
  case "restore_purchases":
120
- onRestorePurchasesAction(action, data);
121
- break;
122
- case "purchase":
123
- onPurchaseAction(action, data);
124
- break;
75
+ onRestorePurchasesClicked?.();
76
+ return;
77
+ }
78
+
79
+ switch (action.destination) {
80
+ case "customer_center":
81
+ onVisitCustomerCenterClicked?.();
82
+ return;
83
+ case "privacy_policy":
84
+ case "terms":
85
+ case "url":
86
+ const url = getLocalizedString(action.url.url_lid);
87
+ if (url) {
88
+ onNavigateToUrlClicked?.(url);
89
+ }
90
+ return;
91
+ case "offer_code":
92
+ case "sheet":
93
+ case "web_paywall_link":
94
+ // TODO: Implement later.
95
+ return;
125
96
  }
126
97
  };
127
98
 
99
+ setPaywallContext({
100
+ selectedPackageId,
101
+ variablesPerPackage: readable(variablesPerPackage),
102
+ onPurchase,
103
+ onButtonAction,
104
+ });
105
+
106
+ const variables: VariablesStore = derived(
107
+ selectedPackageId,
108
+ (packageId) => variablesPerPackage[packageId || ""],
109
+ );
110
+
111
+ setVariablesContext(variables);
112
+
128
113
  const backgroundStyles = $derived(
129
114
  getBackgroundStyles({
130
115
  background: paywallData.components_config.base?.background,
131
- colorMode: purchaseState.colorMode,
116
+ colorMode,
132
117
  }),
133
118
  );
134
119
  const backgroundImgSource = $derived(
135
- getBackgroundImageSource(paywallData, purchaseState.colorMode),
120
+ getBackgroundImageSource(paywallData, colorMode),
136
121
  );
137
122
  </script>
138
123
 
139
124
  <svelte:boundary onerror={onError}>
140
125
  <div class="rc-pw-paywall">
141
- <Node
142
- {onAction}
143
- nodeData={paywallData.components_config.base.stack}
144
- labels={paywallData.components_localizations}
145
- {purchaseState}
146
- {variableDictionary}
147
- />
126
+ <Node nodeData={paywallData.components_config.base.stack} />
148
127
 
149
128
  {#if paywallData.components_config.base.sticky_footer}
150
129
  <Footer
151
130
  {...paywallData.components_config.base.sticky_footer}
152
131
  stack={paywallData.components_config.base.sticky_footer
153
132
  .stack as StackProps}
154
- labels={paywallData.components_localizations}
155
- {purchaseState}
156
- {variableDictionary}
157
- {onAction}
158
133
  />
159
134
  {/if}
160
135
  {#if paywallData.components_config.base.background?.type === "color"}
@@ -1,16 +1,16 @@
1
1
  import type { PaywallData } from "../../data/entities";
2
- import { type VariableDictionary } from "../../utils/variable-utils";
3
2
  import type { ColorMode } from "../../types";
3
+ import { type VariableDictionary } from "../../utils/variable-utils";
4
4
  interface Props {
5
5
  paywallData: PaywallData;
6
+ selectedLocale?: string;
7
+ variablesPerPackage?: Record<string, VariableDictionary>;
8
+ preferredColorMode?: ColorMode;
6
9
  onPurchaseClicked?: (selectedPackageId: string) => void;
7
10
  onBackClicked?: () => void;
8
11
  onVisitCustomerCenterClicked?: () => void;
9
12
  onRestorePurchasesClicked?: () => void;
10
13
  onNavigateToUrlClicked?: (url: string) => void;
11
- selectedLocale?: string;
12
- variablesPerPackage?: Record<string, VariableDictionary>;
13
- preferredColorMode?: ColorMode;
14
14
  onError?: (error: unknown) => void;
15
15
  }
16
16
  declare const Paywall: import("svelte").Component<Props, {}, "">;
@@ -1,7 +1,8 @@
1
- import type { BaseNodeBackgroundType, PaywallData } from "../../data/entities";
1
+ import type { PaywallData } from "../../data/entities";
2
2
  import type { ColorMode } from "../../types";
3
+ import type { Background } from "../../types/background";
3
4
  export declare function getBackgroundStyles({ background, colorMode, }: {
4
- background?: BaseNodeBackgroundType;
5
+ background?: Background;
5
6
  colorMode: ColorMode;
6
7
  }): string;
7
8
  export declare function getBackgroundImageSource(paywallData: PaywallData, colorMode: ColorMode): string | undefined;
@@ -15,10 +15,10 @@ export function getBackgroundStyles({ background, colorMode, }) {
15
15
  return stringifyStyles(prefixedStyles);
16
16
  }
17
17
  export function getBackgroundImageSource(paywallData, colorMode) {
18
- if (paywallData.components_config.base?.background?.type !== "image")
18
+ const { background } = paywallData.components_config.base;
19
+ if (background?.type !== "image") {
19
20
  return "";
20
- const backgroundObject = paywallData.components_config.base
21
- .background;
22
- return (backgroundObject.value[colorMode]?.original ||
23
- backgroundObject.value[DEFAULT_COLOR_MODE]?.original);
21
+ }
22
+ const { value } = background;
23
+ return value[colorMode]?.original ?? value[DEFAULT_COLOR_MODE]?.original;
24
24
  }
@@ -1,19 +1,25 @@
1
1
  <script module lang="ts">
2
- import { defineMeta } from "@storybook/addon-svelte-csf";
3
2
  import PurchaseButton from "./PurchaseButton.svelte";
4
- import type { PurchaseState } from "../../data/state";
5
- import type { DimensionType } from "../../types";
6
- import type { SupportedActions } from "../../data/entities";
7
- import { DEFAULT_COLOR_MODE } from "../../utils/constants";
3
+ import { localizationDecorator } from "../../stories/localization-decorator";
4
+ import { defineMeta } from "@storybook/addon-svelte-csf";
8
5
 
9
- const onAction = (action: SupportedActions) => {
10
- alert(action.type);
11
- };
6
+ const defaultLocale = "en_US";
7
+ const text_lid = "6gpcQ4q6T8";
12
8
 
13
9
  const { Story } = defineMeta({
14
10
  title: "Components/PurchaseButton",
15
11
  component: PurchaseButton,
16
12
  tags: ["autodocs"],
13
+ decorators: [
14
+ localizationDecorator({
15
+ defaultLocale,
16
+ localizations: {
17
+ [defaultLocale]: {
18
+ [text_lid]: "Continue",
19
+ },
20
+ },
21
+ }),
22
+ ],
17
23
  argTypes: {
18
24
  stack: {
19
25
  control: { type: "object" },
@@ -27,17 +33,6 @@
27
33
  },
28
34
  },
29
35
  });
30
-
31
- export const labelsData = {
32
- en_US: {
33
- "6gpcQ4q6T8": "Continue",
34
- },
35
- };
36
- const purchaseState: PurchaseState = {
37
- colorMode: DEFAULT_COLOR_MODE,
38
- locale: "en_US",
39
- defaultLocale: "en_US",
40
- };
41
36
  </script>
42
37
 
43
38
  <!-- Default button -->
@@ -46,18 +41,24 @@
46
41
  args={{
47
42
  id: "mjaE9fOv5z",
48
43
  name: "Purchase_button",
49
- purchaseState,
50
44
  stack: {
51
- purchaseState,
52
45
  background_color: {
53
46
  light: {
54
47
  type: "hex",
55
48
  value: "#a229f3",
56
49
  },
57
50
  },
51
+ background: {
52
+ type: "color",
53
+ value: {
54
+ light: {
55
+ type: "hex",
56
+ value: "#a229f3",
57
+ },
58
+ },
59
+ },
58
60
  components: [
59
61
  {
60
- purchaseState,
61
62
  background_color: null,
62
63
  color: {
63
64
  light: {
@@ -65,8 +66,6 @@
65
66
  value: "#ffffff",
66
67
  },
67
68
  },
68
- labels: labelsData,
69
- components: [],
70
69
  font_name: null,
71
70
  font_size: "heading_m",
72
71
  font_weight: "extra_bold",
@@ -95,15 +94,15 @@
95
94
  value: null,
96
95
  },
97
96
  },
98
- text_lid: "6gpcQ4q6T8",
97
+ text_lid,
99
98
  type: "text",
100
99
  },
101
100
  ],
102
101
  dimension: {
103
- alignment: "top",
104
- distribution: "space_between",
105
102
  type: "vertical",
106
- } as DimensionType,
103
+ alignment: "center",
104
+ distribution: "center",
105
+ },
107
106
  id: "pbvAUBvilP",
108
107
  margin: {
109
108
  bottom: 16,
@@ -118,6 +117,8 @@
118
117
  top: 16,
119
118
  trailing: 16,
120
119
  },
120
+ border: null,
121
+ shadow: null,
121
122
  shape: {
122
123
  corners: {
123
124
  bottom_leading: 8,
@@ -137,10 +138,7 @@
137
138
  },
138
139
  spacing: 8,
139
140
  type: "stack",
140
- labels: labelsData,
141
141
  },
142
- labels: labelsData,
143
142
  type: "purchase_button",
144
- onAction,
145
143
  }}
146
144
  />
@@ -1,9 +1,4 @@
1
1
  import PurchaseButton from "./PurchaseButton.svelte";
2
- export declare const labelsData: {
3
- en_US: {
4
- "6gpcQ4q6T8": string;
5
- };
6
- };
7
2
  interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
8
3
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
9
4
  $$bindings?: Bindings;