@revenuecat/purchases-ui-js 0.0.16 → 0.0.18

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 (67) hide show
  1. package/dist/components/button/Button.svelte +0 -13
  2. package/dist/components/button/Button.svelte.d.ts +4 -2
  3. package/dist/components/button/ButtonNode.stories.svelte +16 -11
  4. package/dist/components/button/ButtonNode.svelte +26 -1
  5. package/dist/components/button/ButtonNode.svelte.d.ts +1 -0
  6. package/dist/components/button/button-utils.d.ts +2 -0
  7. package/dist/components/button/button-utils.js +19 -0
  8. package/dist/components/footer/Footer.stories.svelte +47 -155
  9. package/dist/components/footer/Footer.stories.svelte.d.ts +1 -2
  10. package/dist/components/footer/Footer.svelte +10 -1
  11. package/dist/components/footer/Footer.svelte.d.ts +1 -0
  12. package/dist/components/image/Image.stories.svelte +13 -7
  13. package/dist/components/image/Image.svelte +37 -19
  14. package/dist/components/image/Image.svelte.d.ts +1 -0
  15. package/dist/components/image/image-utils.d.ts +2 -12
  16. package/dist/components/image/image-utils.js +28 -11
  17. package/dist/components/package/Package.stories.svelte +5 -5
  18. package/dist/components/package/Package.svelte +15 -6
  19. package/dist/components/package/Package.svelte.d.ts +1 -0
  20. package/dist/components/paywall/Node.svelte +77 -17
  21. package/dist/components/paywall/Node.svelte.d.ts +21 -2
  22. package/dist/components/paywall/Paywall.stories.svelte +93 -15
  23. package/dist/components/paywall/Paywall.svelte +110 -88
  24. package/dist/components/paywall/Paywall.svelte.d.ts +4 -0
  25. package/dist/components/paywall/paywall-utils.d.ts +1 -1
  26. package/dist/components/paywall/paywall-utils.js +11 -9
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte +7 -8
  28. package/dist/components/purchase-button/PurchaseButton.svelte +24 -10
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -0
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +2 -0
  31. package/dist/components/purchase-button/purchase-button-utils.js +20 -0
  32. package/dist/components/stack/Stack.stories.svelte +1138 -6
  33. package/dist/components/stack/Stack.svelte +160 -42
  34. package/dist/components/stack/Stack.svelte.d.ts +1 -0
  35. package/dist/components/stack/stack-utils.d.ts +24 -24
  36. package/dist/components/stack/stack-utils.js +245 -12
  37. package/dist/components/text/Text.svelte +24 -19
  38. package/dist/components/text/Text.svelte.d.ts +4 -2
  39. package/dist/components/text/TextNode.stories.svelte +13 -13
  40. package/dist/components/text/TextNode.svelte +24 -34
  41. package/dist/components/text/TextNode.svelte.d.ts +1 -0
  42. package/dist/components/text/text-utils.d.ts +11 -14
  43. package/dist/components/text/text-utils.js +130 -15
  44. package/dist/components/timeline/Timeline.stories.svelte +640 -0
  45. package/dist/components/timeline/Timeline.stories.svelte.d.ts +19 -0
  46. package/dist/components/timeline/Timeline.svelte +40 -0
  47. package/dist/components/timeline/Timeline.svelte.d.ts +4 -0
  48. package/dist/components/timeline/TimelineItem.svelte +112 -0
  49. package/dist/components/timeline/TimelineItem.svelte.d.ts +4 -0
  50. package/dist/components/timeline/timeline-utils.d.ts +8 -0
  51. package/dist/components/timeline/timeline-utils.js +128 -0
  52. package/dist/data/entities.d.ts +89 -9
  53. package/dist/data/state.d.ts +2 -0
  54. package/dist/index.d.ts +3 -2
  55. package/dist/index.js +3 -2
  56. package/dist/stories/fixtures.d.ts +7 -1
  57. package/dist/stories/fixtures.js +6898 -7
  58. package/dist/stories/meta-templates.d.ts +0 -1
  59. package/dist/stories/meta-templates.js +0 -5
  60. package/dist/types.d.ts +16 -7
  61. package/dist/types.js +7 -0
  62. package/dist/utils/style-utils.d.ts +80 -41
  63. package/dist/utils/style-utils.js +157 -70
  64. package/dist/utils/variable-utils.d.ts +27 -0
  65. package/dist/utils/variable-utils.js +37 -0
  66. package/package.json +27 -25
  67. package/dist/components/paywall/global-styles.css +0 -9
@@ -1,21 +1,26 @@
1
1
  <script lang="ts">
2
2
  import type {
3
- BaseNodeBackgroundImage,
4
3
  Extra,
5
4
  NavigateToAction,
6
5
  PaywallData,
6
+ StackProps,
7
7
  SupportedActions,
8
8
  } from "../../data/entities";
9
9
 
10
10
  import Node from "./Node.svelte";
11
11
  import type { PurchaseState } from "../../data/state";
12
- import { findSelectedPackageId, getLabelById } from "../../utils/style-utils";
13
- import { type VariableDictionary } from "../../utils/variable-utils";
12
+ import { findSelectedPackageId } from "../../utils/style-utils";
13
+ import {
14
+ getLabelById,
15
+ type VariableDictionary,
16
+ } from "../../utils/variable-utils";
14
17
  import {
15
18
  getBackgroundImageSource,
16
19
  getBackgroundStyles,
17
20
  } from "./paywall-utils";
18
21
  import { prefersDarkMode } from "../../stores/theme";
22
+ import type { ColorMode } from "../../types";
23
+ import Footer from "../footer/Footer.svelte";
19
24
 
20
25
  interface Props {
21
26
  paywallData: PaywallData;
@@ -26,6 +31,8 @@
26
31
  onNavigateToUrlClicked?: (url: string) => void;
27
32
  selectedLocale?: string;
28
33
  variablesPerPackage?: Record<string, VariableDictionary>;
34
+ preferredColorMode?: ColorMode;
35
+ onError?: (error: unknown) => void;
29
36
  }
30
37
 
31
38
  const {
@@ -37,6 +44,8 @@
37
44
  onVisitCustomerCenterClicked,
38
45
  selectedLocale,
39
46
  variablesPerPackage = {},
47
+ preferredColorMode,
48
+ onError,
40
49
  }: Props = $props();
41
50
 
42
51
  let purchaseState: PurchaseState = $state({
@@ -44,6 +53,7 @@
44
53
  locale: selectedLocale || paywallData.default_locale,
45
54
  defaultLocale: paywallData.default_locale,
46
55
  variablesPerPackage,
56
+ colorMode: preferredColorMode || ($prefersDarkMode ? "dark" : "light"),
47
57
  });
48
58
 
49
59
  let variableDictionary = $state(
@@ -81,9 +91,9 @@
81
91
  };
82
92
 
83
93
  const onSelectPackageAction = (_: SupportedActions, data?: Extra) => {
84
- purchaseState.selectedPackageId = data?.packageId;
94
+ purchaseState.selectedPackageId = data?.packageId as string | undefined;
85
95
  if (data?.packageId) {
86
- variableDictionary = variablesPerPackage[data.packageId];
96
+ variableDictionary = variablesPerPackage[data.packageId as string];
87
97
  }
88
98
  };
89
99
 
@@ -113,125 +123,137 @@
113
123
  break;
114
124
  }
115
125
  };
116
- const colorMode = $derived($prefersDarkMode ? "dark" : "light");
117
126
 
118
127
  const backgroundStyles = $derived(
119
128
  getBackgroundStyles({
120
129
  background: paywallData.components_config.base?.background,
121
- colorMode,
130
+ colorMode: purchaseState.colorMode,
122
131
  }),
123
132
  );
124
133
  const backgroundImgSource = $derived(
125
- getBackgroundImageSource(paywallData, $prefersDarkMode ? "dark" : "light"),
134
+ getBackgroundImageSource(paywallData, purchaseState.colorMode),
126
135
  );
127
136
  </script>
128
137
 
129
- <div class="paywall">
130
- <Node
131
- {onAction}
132
- nodeData={paywallData.components_config.base.stack}
133
- labels={paywallData.components_localizations}
134
- {purchaseState}
135
- {variableDictionary}
136
- />
137
- {#if paywallData.components_config.base.background?.type === "color"}
138
- <div class="paywall-background" style={backgroundStyles}></div>
139
- {:else if paywallData.components_config.base.background?.type === "image"}
140
- <div class="paywall-background image-container">
141
- <img class="image" src={backgroundImgSource} alt="" />
142
- </div>
143
- {/if}
144
- </div>
138
+ <svelte:boundary onerror={onError}>
139
+ <div class="rc-pw-paywall">
140
+ <Node
141
+ {onAction}
142
+ nodeData={paywallData.components_config.base.stack}
143
+ labels={paywallData.components_localizations}
144
+ {purchaseState}
145
+ {variableDictionary}
146
+ />
145
147
 
146
- <style>
147
- /* 1. Use a more-intuitive box-sizing model */
148
- *,
149
- *::before,
150
- *::after {
151
- box-sizing: border-box;
152
- margin: 0;
153
- }
148
+ {#if paywallData.components_config.base.sticky_footer}
149
+ <Footer
150
+ {...paywallData.components_config.base.sticky_footer}
151
+ stack={paywallData.components_config.base.sticky_footer
152
+ .stack as StackProps}
153
+ labels={paywallData.components_localizations}
154
+ {purchaseState}
155
+ {variableDictionary}
156
+ />
157
+ {/if}
158
+ {#if paywallData.components_config.base.background?.type === "color"}
159
+ <div class="rc-pw-paywall-background" style={backgroundStyles}></div>
160
+ {:else if paywallData.components_config.base.background?.type === "image"}
161
+ <div class="rc-pw-paywall-background rc-pw-image-container">
162
+ <img class="rc-pw-image" src={backgroundImgSource} alt="" />
163
+ </div>
164
+ {/if}
165
+ </div>
166
+ </svelte:boundary>
154
167
 
155
- .paywall {
168
+ <style>
169
+ .rc-pw-paywall {
156
170
  position: relative;
171
+ display: block;
172
+ max-height: 100%;
157
173
  }
158
174
 
159
- .paywall-background {
175
+ .rc-pw-paywall-background {
160
176
  position: absolute;
161
177
  top: 0;
162
178
  left: 0;
163
179
  width: 100%;
164
180
  height: 100%;
165
- background: var(--background, none);
181
+ background: var(--paywall-background, none);
166
182
  z-index: -1;
167
183
  }
168
- .image-container {
184
+ .rc-pw-image-container {
169
185
  overflow: hidden;
170
186
  background: none;
171
187
  }
172
188
 
173
- .image {
189
+ .rc-pw-image {
174
190
  width: 100%;
175
191
  height: 100%;
176
192
  object-fit: cover;
177
193
  display: block;
178
194
  }
179
195
 
180
- body {
181
- /* 3. Add accessible line-height */
182
- line-height: 1.5;
183
- /* 4. Improve text rendering */
184
- -webkit-font-smoothing: antialiased;
185
- }
186
-
187
- /* 5. Improve media defaults */
188
- img,
189
- picture,
190
- video,
191
- canvas,
192
- svg {
193
- display: block;
194
- max-width: 100%;
195
- }
196
+ :global {
197
+ *,
198
+ *::before,
199
+ *::after {
200
+ box-sizing: border-box;
201
+ margin: 0;
202
+ padding: 0;
203
+ font-family: sans-serif;
204
+ }
205
+ body {
206
+ line-height: 1.5;
207
+ -webkit-font-smoothing: antialiased;
208
+ }
209
+ img,
210
+ picture,
211
+ video,
212
+ canvas,
213
+ svg {
214
+ display: block;
215
+ max-width: 100%;
216
+ }
196
217
 
197
- /* 6. Inherit fonts for form controls */
198
- input,
199
- button,
200
- textarea,
201
- select {
202
- font: inherit;
203
- }
218
+ input,
219
+ button,
220
+ textarea,
221
+ select {
222
+ font: inherit;
223
+ }
224
+ button {
225
+ border: none;
226
+ cursor: pointer;
227
+ background: transparent;
228
+ width: fit-content;
229
+ }
204
230
 
205
- /* 7. Avoid text overflows */
206
- p,
207
- h1,
208
- h2,
209
- h3,
210
- h4,
211
- h5,
212
- h6 {
213
- overflow-wrap: break-word;
214
- }
231
+ p,
232
+ h1,
233
+ h2,
234
+ h3,
235
+ h4,
236
+ h5,
237
+ h6 {
238
+ overflow-wrap: break-word;
239
+ }
215
240
 
216
- /* 8. Improve line wrapping */
217
- p {
218
- text-wrap: pretty;
219
- }
241
+ p {
242
+ text-wrap: pretty;
243
+ }
220
244
 
221
- h1,
222
- h2,
223
- h3,
224
- h4,
225
- h5,
226
- h6 {
227
- text-wrap: balance;
228
- }
245
+ h1,
246
+ h2,
247
+ h3,
248
+ h4,
249
+ h5,
250
+ h6 {
251
+ text-wrap: balance;
252
+ }
229
253
 
230
- /*
231
- 9. Create a root stacking context
232
- */
233
- #root,
234
- #__next {
235
- isolation: isolate;
254
+ #root,
255
+ #__next {
256
+ isolation: isolate;
257
+ }
236
258
  }
237
259
  </style>
@@ -1,5 +1,6 @@
1
1
  import type { PaywallData } from "../../data/entities";
2
2
  import { type VariableDictionary } from "../../utils/variable-utils";
3
+ import type { ColorMode } from "../../types";
3
4
  declare const Paywall: import("svelte").Component<{
4
5
  paywallData: PaywallData;
5
6
  onPurchaseClicked?: (selectedPackageId: string) => void;
@@ -9,5 +10,8 @@ declare const Paywall: import("svelte").Component<{
9
10
  onNavigateToUrlClicked?: (url: string) => void;
10
11
  selectedLocale?: string;
11
12
  variablesPerPackage?: Record<string, VariableDictionary>;
13
+ preferredColorMode?: ColorMode;
14
+ onError?: (error: unknown) => void;
12
15
  }, {}, "">;
16
+ type Paywall = ReturnType<typeof Paywall>;
13
17
  export default Paywall;
@@ -3,5 +3,5 @@ import type { ColorMode } from "../../types";
3
3
  export declare function getBackgroundStyles({ background, colorMode, }: {
4
4
  background?: BaseNodeBackgroundType;
5
5
  colorMode: ColorMode;
6
- }): string | undefined;
6
+ }): string;
7
7
  export declare function getBackgroundImageSource(paywallData: PaywallData, colorMode: ColorMode): string;
@@ -1,15 +1,17 @@
1
- import { getColor } from "../../utils/style-utils";
1
+ import { getColor, prefixObject, stringifyStyles, } from "../../utils/style-utils";
2
2
  export function getBackgroundStyles({ background, colorMode, }) {
3
- if (!background)
4
- return "";
5
- if (background.type === "color") {
6
- const style = getColor({
7
- colorMap: background.value,
8
- colorMode,
9
- fallback: "transparent",
3
+ const styles = { "--background": "initial" };
4
+ if (background?.type === "color") {
5
+ Object.assign(styles, {
6
+ "--background": getColor({
7
+ colorMap: background.value,
8
+ colorMode,
9
+ fallback: "transparent",
10
+ }),
10
11
  });
11
- return `--background: ${style};`;
12
12
  }
13
+ const prefixedStyles = prefixObject(styles, "paywall");
14
+ return stringifyStyles(prefixedStyles);
13
15
  }
14
16
  export function getBackgroundImageSource(paywallData, colorMode) {
15
17
  if (paywallData.components_config.base?.background?.type !== "image")
@@ -1,14 +1,14 @@
1
1
  <script module lang="ts">
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
3
  import PurchaseButton from "./PurchaseButton.svelte";
4
- import { colorModeStoryMeta } from "../../stories/meta-templates";
4
+ import type { PurchaseState } from "../../data/state";
5
+ import type { ColorMode, DimensionType } from "../../types";
5
6
 
6
7
  const { Story } = defineMeta({
7
8
  title: "Components/PurchaseButton",
8
9
  component: PurchaseButton,
9
10
  tags: ["autodocs"],
10
11
  argTypes: {
11
- colorMode: colorModeStoryMeta,
12
12
  stack: {
13
13
  control: { type: "object" },
14
14
  description: "Stack configuration for button content",
@@ -27,7 +27,8 @@
27
27
  "6gpcQ4q6T8": "Continue",
28
28
  },
29
29
  };
30
- const purchaseState = {
30
+ const purchaseState: PurchaseState = {
31
+ colorMode: "light" as ColorMode,
31
32
  locale: "en_US",
32
33
  defaultLocale: "en_US",
33
34
  };
@@ -48,7 +49,6 @@
48
49
  value: "#a229f3",
49
50
  },
50
51
  },
51
- border: null,
52
52
  components: [
53
53
  {
54
54
  purchaseState,
@@ -94,10 +94,10 @@
94
94
  },
95
95
  ],
96
96
  dimension: {
97
- alignment: "leading",
97
+ alignment: "top",
98
98
  distribution: "space_between",
99
99
  type: "vertical",
100
- },
100
+ } as DimensionType,
101
101
  id: "pbvAUBvilP",
102
102
  margin: {
103
103
  bottom: 16,
@@ -124,15 +124,14 @@
124
124
  size: {
125
125
  height: {
126
126
  type: "fit",
127
- value: null,
128
127
  },
129
128
  width: {
130
129
  type: "fill",
131
- value: null,
132
130
  },
133
131
  },
134
132
  spacing: 8,
135
133
  type: "stack",
134
+ labels: labelsData,
136
135
  },
137
136
  labels: labelsData,
138
137
  type: "purchase_button",
@@ -2,6 +2,7 @@
2
2
  import type { PurchaseButtonProps } from "../../data/entities";
3
3
  import Stack from "../stack/Stack.svelte";
4
4
  import { Button } from "../../index";
5
+ import { getPurchaseButtonStyles } from "./purchase-button-utils";
5
6
 
6
7
  const {
7
8
  stack,
@@ -9,25 +10,38 @@
9
10
  onAction,
10
11
  purchaseState,
11
12
  variableDictionary,
13
+ zStackChildStyles,
14
+ ...restProps
12
15
  }: PurchaseButtonProps = $props();
13
16
  const handleClick = () => {
14
17
  onAction && onAction({ type: "purchase" });
15
18
  };
19
+
20
+ const buttonStyles = $derived(
21
+ getPurchaseButtonStyles({
22
+ stack,
23
+ labels,
24
+ onAction,
25
+ purchaseState,
26
+ variableDictionary,
27
+ zStackChildStyles,
28
+ ...restProps,
29
+ }),
30
+ );
16
31
  </script>
17
32
 
18
- <Button onclick={handleClick} class="purchase-button">
33
+ <Button
34
+ onclick={handleClick}
35
+ class="rc-pw-purchase-button"
36
+ style={buttonStyles}
37
+ >
19
38
  <Stack {...stack} {labels} {purchaseState} {variableDictionary} />
20
39
  </Button>
21
40
 
22
41
  <style>
23
- .purchase-button {
24
- border: none;
25
- cursor: pointer;
26
- background: transparent;
27
- padding: 0;
28
- width: 100%;
29
- display: flex;
30
- align-items: center;
31
- justify-content: center;
42
+ .rc-pw-purchase-button {
43
+ position: var(--purchase-button-position, relative);
44
+ inset: var(--purchase-button-inset, 0);
45
+ transform: var(--purchase-button-transform, initial);
32
46
  }
33
47
  </style>
@@ -1,3 +1,4 @@
1
1
  import type { PurchaseButtonProps } from "../../data/entities";
2
2
  declare const PurchaseButton: import("svelte").Component<PurchaseButtonProps, {}, "">;
3
+ type PurchaseButton = ReturnType<typeof PurchaseButton>;
3
4
  export default PurchaseButton;
@@ -0,0 +1,2 @@
1
+ import type { PurchaseButtonProps } from "../../data/entities";
2
+ export declare function getPurchaseButtonStyles({ stack, zStackChildStyles, }: PurchaseButtonProps): string;
@@ -0,0 +1,20 @@
1
+ import { prefixObject, stringifyStyles } from "../../utils/style-utils";
2
+ export function getPurchaseButtonStyles({ stack, zStackChildStyles, }) {
3
+ // Get the width of the inner stack to adjust to the outer button wrapper
4
+ const width = stack.size.width.type === "fill" ? "100%" : "fit-content";
5
+ // Prefix zStack child styles with purchase-button to prevent class overlap conflicts
6
+ const prefixedObject = prefixObject(zStackChildStyles || {}, "purchase-button");
7
+ // Define set of variables to be assigned to the purchase button
8
+ // Define width as an inline style
9
+ const assignedVariables = {
10
+ position: "var(--purchase-button-position, relative)",
11
+ inset: "var(--purchase-button-inset, 0)",
12
+ transform: "var(--purchase-button-transform, initial)",
13
+ width,
14
+ };
15
+ const purchaseButtonInlineStyles = stringifyStyles({
16
+ ...prefixedObject,
17
+ ...assignedVariables,
18
+ });
19
+ return purchaseButtonInlineStyles;
20
+ }