@revenuecat/purchases-ui-js 0.0.12 → 0.0.13

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.
@@ -2,7 +2,7 @@
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
3
  import ButtonNode from "./ButtonNode.svelte";
4
4
  import { colorModeStoryMeta } from "../../stories/meta-templates";
5
- import type { SupportedActions, TextProps } from "../../data/entities";
5
+ import type { SupportedActions, TextNodeProps } from "../../data/entities";
6
6
 
7
7
  const onAction = (action: SupportedActions) => {
8
8
  alert(action.type);
@@ -1,6 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { getImageComponentStyles } from "./image-utils";
3
- import { stringifyStyles } from "../../utils";
3
+ import { stringifyStyles } from "../../utils/style-utils";
4
4
  import type { ImageProps } from "../../data/entities";
5
5
 
6
6
  const { id, colorMode, source, ...restProps }: ImageProps = $props();
@@ -30,12 +30,13 @@
30
30
  border-radius: var(--corner-radius, unset);
31
31
  clip-path: var(--clip-path, unset);
32
32
  display: flex;
33
- flex: 1 0 auto;
33
+ flex: var(--flex, 1 0 auto);
34
34
  }
35
35
  .image {
36
36
  width: 100%;
37
37
  height: 100%;
38
38
  object-fit: cover;
39
+ display: block;
39
40
  }
40
41
  .image-overlay {
41
42
  position: absolute;
@@ -1,4 +1,4 @@
1
- import { getGradientStyle, getMaskStyle, getSizeStyle } from "../../utils";
1
+ import { getGradientStyle, getMaskStyle, getSizeStyle, } from "../../utils/style-utils";
2
2
  /**
3
3
  * Generates comprehensive styles for image components by combining gradient and size styles
4
4
  * @param props - Image component properties including gradient, mask and size
@@ -1,13 +1,5 @@
1
1
  <script lang="ts">
2
- import {
3
- Stack,
4
- Text,
5
- Button,
6
- Image,
7
- PurchaseButton,
8
- Package,
9
- Footer,
10
- } from "../..";
2
+ import { Stack, Image, PurchaseButton, Package, Footer } from "../..";
11
3
  import Self from "./Node.svelte";
12
4
  import {
13
5
  type ActionsProps,
@@ -19,19 +11,18 @@
19
11
  } from "../../data/entities";
20
12
  import { prefersDarkMode } from "../../stores/theme";
21
13
  import ButtonNode from "../button/ButtonNode.svelte";
22
- import type { PurchaseState } from "../../data/state";
14
+ import TextNode from "../text/TextNode.svelte";
23
15
 
24
16
  interface Props extends ActionsProps, PurchaseStateProps {
25
17
  nodeData: PaywallComponent;
26
18
  labels: ComponentLocalizations;
27
19
  onAction?: (action: SupportedActions, data?: Extra) => void;
28
- purchaseState?: PurchaseState;
29
20
  }
30
21
 
31
22
  const { nodeData, labels, onAction, purchaseState }: Props = $props();
32
23
 
33
24
  const ComponentTypes = {
34
- text: Text,
25
+ text: TextNode,
35
26
  stack: Stack,
36
27
  image: Image,
37
28
  button: ButtonNode,
@@ -1,9 +1,7 @@
1
1
  import { type ActionsProps, type ComponentLocalizations, type Extra, type PaywallComponent, type PurchaseStateProps, type SupportedActions } from "../../data/entities";
2
- import type { PurchaseState } from "../../data/state";
3
2
  declare const Node: import("svelte").Component<ActionsProps & PurchaseStateProps & {
4
3
  nodeData: PaywallComponent;
5
4
  labels: ComponentLocalizations;
6
5
  onAction?: (action: SupportedActions, data?: Extra) => void;
7
- purchaseState?: PurchaseState;
8
6
  }, {}, "">;
9
7
  export default Node;
@@ -2,7 +2,13 @@
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
3
 
4
4
  import Paywall from "./Paywall.svelte";
5
- import { paywallData } from "../../stories/fixtures";
5
+ import {
6
+ alignmentPaywallData,
7
+ calmPaywallData,
8
+ fontsPaywallData,
9
+ pastaPaywallData,
10
+ paywallData,
11
+ } from "../../stories/fixtures";
6
12
  import { fn } from "@storybook/test";
7
13
 
8
14
  const { Story } = defineMeta({
@@ -25,7 +31,7 @@
25
31
  onRestorePurchasesClicked: fn(),
26
32
  }}
27
33
  />
28
-
34
+ <!-- Italian missing labels story -->
29
35
  <Story
30
36
  name="Italian Missing Labels"
31
37
  args={{
@@ -37,3 +43,51 @@
37
43
  onRestorePurchasesClicked: fn(),
38
44
  }}
39
45
  />
46
+
47
+ <Story
48
+ name="Alignment paywall example"
49
+ args={{
50
+ paywallData: alignmentPaywallData,
51
+ selectedLocale: "en_US",
52
+ onPurchaseClicked: fn(),
53
+ onBackClicked: fn(),
54
+ onNavigateToClicked: fn(),
55
+ onRestorePurchasesClicked: fn(),
56
+ }}
57
+ />
58
+
59
+ <Story
60
+ name="Fonts paywall example"
61
+ args={{
62
+ paywallData: fontsPaywallData,
63
+ selectedLocale: "en_US",
64
+ onPurchaseClicked: fn(),
65
+ onBackClicked: fn(),
66
+ onNavigateToClicked: fn(),
67
+ onRestorePurchasesClicked: fn(),
68
+ }}
69
+ />
70
+
71
+ <Story
72
+ name="Pasta paywall example"
73
+ args={{
74
+ paywallData: pastaPaywallData,
75
+ selectedLocale: "en_US",
76
+ onPurchaseClicked: fn(),
77
+ onBackClicked: fn(),
78
+ onNavigateToClicked: fn(),
79
+ onRestorePurchasesClicked: fn(),
80
+ }}
81
+ />
82
+
83
+ <Story
84
+ name="Calm paywall example"
85
+ args={{
86
+ paywallData: calmPaywallData,
87
+ selectedLocale: "en_US",
88
+ onPurchaseClicked: fn(),
89
+ onBackClicked: fn(),
90
+ onNavigateToClicked: fn(),
91
+ onRestorePurchasesClicked: fn(),
92
+ }}
93
+ />
@@ -8,7 +8,7 @@
8
8
 
9
9
  import Node from "./Node.svelte";
10
10
  import type { PurchaseState } from "../../data/state";
11
- import { findSelectedPackageId, getLabelById } from "../../utils";
11
+ import { findSelectedPackageId, getLabelById } from "../../utils/style-utils";
12
12
 
13
13
  interface Props {
14
14
  paywallData: PaywallData;
@@ -98,7 +98,7 @@
98
98
  };
99
99
  </script>
100
100
 
101
- <div>
101
+ <div class="paywall">
102
102
  <Node
103
103
  {onAction}
104
104
  nodeData={paywallData.components_config.base.stack}
@@ -2,7 +2,7 @@
2
2
  import type { StackProps } from "../../data/entities";
3
3
  import Node from "../paywall/Node.svelte";
4
4
  import { getStackComponentStyles } from "./stack-utils";
5
- import { stringifyStyles } from "../../utils";
5
+ import { stringifyStyles } from "../../utils/style-utils";
6
6
 
7
7
  const {
8
8
  id,
@@ -56,6 +56,5 @@
56
56
  margin-block-end: var(--margin-block-end, 0);
57
57
  margin-inline-start: var(--margin-inline-start, 0);
58
58
  flex: var(--flex, 0 1 auto);
59
- align-self: center;
60
59
  }
61
60
  </style>
@@ -1,5 +1,6 @@
1
1
  import type { StackProps } from "../../data/entities";
2
2
  type StackStyleVariables = {
3
+ "--flex": string;
3
4
  "--height": string;
4
5
  "--width": string;
5
6
  "--spacing": string;
@@ -1,4 +1,4 @@
1
- import { getComponentStyles, getDimensionStyle, getSizeStyle, } from "../../utils";
1
+ import { getComponentStyles, getDimensionStyle, getSizeStyle, } from "../../utils/style-utils";
2
2
  /**
3
3
  * Generates comprehensive styles for stack components by combining component, dimension and size styles
4
4
  * @param props - Stack component properties including background, spacing, size, border etc.
@@ -1,38 +1,28 @@
1
1
  <script lang="ts">
2
- import { getTextComponentStyles } from "./text-utils";
3
- import type { TextProps } from "../../data/entities";
4
- import { getLabelById, stringifyStyles } from "../../utils";
2
+ import type { Snippet } from "svelte";
5
3
 
6
- const { id, labels, text_lid, purchaseState, ...restProps }: TextProps =
7
- $props();
8
-
9
- const { tagToRender, textStyles } = $derived(
10
- getTextComponentStyles({
11
- id,
12
- labels,
13
- text_lid,
14
- purchaseState,
15
- ...restProps,
16
- }),
17
- );
18
- const stylesString = $derived(stringifyStyles(textStyles));
4
+ interface TextProps {
5
+ component?: string;
6
+ styleVariables?: string;
7
+ id?: string;
8
+ children?: Snippet;
9
+ }
19
10
 
20
- const label = $derived(
21
- getLabelById(
22
- text_lid,
23
- purchaseState.locale,
24
- purchaseState.defaultLocale,
25
- labels,
26
- ),
27
- );
11
+ const {
12
+ children,
13
+ styleVariables = "",
14
+ component = "p",
15
+ id,
16
+ }: TextProps = $props();
28
17
  </script>
29
18
 
30
- <svelte:element this={tagToRender} {id} style={stylesString} class="text-block">
31
- {label}
19
+ <svelte:element this={component} {id} style={styleVariables} class="text-block">
20
+ {@render children?.()}
32
21
  </svelte:element>
33
22
 
34
23
  <style>
35
24
  .text-block {
25
+ display: block;
36
26
  padding-block-start: var(--padding-block-start, unset);
37
27
  padding-inline-end: var(--padding-inline-end, unset);
38
28
  padding-block-end: var(--padding-block-end, unset);
@@ -1,3 +1,8 @@
1
- import type { TextProps } from "../../data/entities";
2
- declare const Text: import("svelte").Component<TextProps, {}, "">;
1
+ import type { Snippet } from "svelte";
2
+ declare const Text: import("svelte").Component<{
3
+ component?: string;
4
+ styleVariables?: string;
5
+ id?: string;
6
+ children?: Snippet;
7
+ }, {}, "">;
3
8
  export default Text;
@@ -1,6 +1,6 @@
1
1
  <script module lang="ts">
2
2
  import { defineMeta } from "@storybook/addon-svelte-csf";
3
- import Text from "./Text.svelte";
3
+ import TextNode from "./TextNode.svelte";
4
4
  import {
5
5
  colorModeStoryMeta,
6
6
  fontSizeStoryMeta,
@@ -12,12 +12,12 @@
12
12
  } from "../../stories/meta-templates";
13
13
 
14
14
  /*
15
- * Documentatino for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
15
+ * Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
16
16
  */
17
17
 
18
18
  const { Story } = defineMeta({
19
19
  title: "Components/Text",
20
- component: Text,
20
+ component: TextNode,
21
21
  tags: ["autodocs"],
22
22
  argTypes: {
23
23
  name: getTextControlStoryMeta("Content of the text to render"),
@@ -32,6 +32,11 @@
32
32
  horizontal_alignment: horizontalAlignmentStoryMeta,
33
33
  padding: getSpacingStoryMeta("Padding values in pixels"),
34
34
  margin: getSpacingStoryMeta("Margin values in pixels"),
35
+ variableDictionary: {
36
+ description: "Dictionary containing the values for the variables",
37
+ control: { type: "object" },
38
+ defaultValue: {},
39
+ },
35
40
  },
36
41
  args: {
37
42
  labels: { en_US: { lb123: "Test text" } },
@@ -46,6 +51,12 @@
46
51
  },
47
52
  },
48
53
  });
54
+
55
+ const mockVariableDictionary = {
56
+ product_name: "CatGPT",
57
+ price: "$39.99",
58
+ price_per_period: "$39.99/yr",
59
+ };
49
60
  </script>
50
61
 
51
62
  <!-- Default story -->
@@ -103,3 +114,44 @@
103
114
  name: "hello world!",
104
115
  }}
105
116
  />
117
+
118
+ <!-- Text with variable dictionary story -->
119
+ <Story
120
+ name="With variable dictionary"
121
+ args={{
122
+ font_weight: "regular",
123
+ text_style: "normal",
124
+ horizontal_alignment: "start",
125
+ padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
126
+ margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
127
+ name: "hello world!",
128
+ variableDictionary: mockVariableDictionary,
129
+ labels: {
130
+ en_US: {
131
+ lb123:
132
+ "This is a text that contains variables: {{ product_name }} for {{ price }} per {{ price_per_period }}",
133
+ },
134
+ },
135
+ text_lid: "lb123",
136
+ }}
137
+ />
138
+ <!-- Text with missing variable in dictionary story -->
139
+ <Story
140
+ name="With missing variable in dictionary"
141
+ args={{
142
+ font_weight: "regular",
143
+ text_style: "normal",
144
+ horizontal_alignment: "start",
145
+ padding: { top: 16, trailing: 24, bottom: 16, leading: 24 },
146
+ margin: { top: 8, trailing: 0, bottom: 8, leading: 0 },
147
+ name: "hello world!",
148
+ variableDictionary: mockVariableDictionary,
149
+ labels: {
150
+ en_US: {
151
+ lb123:
152
+ "This is a text with variables: {{ product_name }} for {{ price }} per {{ price_per_period }} and a missing variable: {{ sub_period_abbreviated }}",
153
+ },
154
+ },
155
+ text_lid: "lb123",
156
+ }}
157
+ />
@@ -1,4 +1,4 @@
1
- import Text from "./Text.svelte";
1
+ import TextNode from "./TextNode.svelte";
2
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> {
3
3
  new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
4
  $$bindings?: Bindings;
@@ -12,8 +12,8 @@ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> =
12
12
  };
13
13
  z_$$bindings?: Bindings;
14
14
  }
15
- declare const Text: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
15
+ declare const TextNode: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
16
16
  [evt: string]: CustomEvent<any>;
17
17
  }, {}, {}, string>;
18
- type Text = InstanceType<typeof Text>;
19
- export default Text;
18
+ type TextNode = InstanceType<typeof TextNode>;
19
+ export default TextNode;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { getTextComponentStyles } from "./text-utils";
3
+ import Text from "./Text.svelte";
4
+ import type { TextNodeProps } from "../../data/entities";
5
+ import { getLabelById, stringifyStyles } from "../../utils/style-utils";
6
+ import { replaceVariables } from "../../utils/variable-utils";
7
+
8
+ const {
9
+ id,
10
+ labels,
11
+ text_lid,
12
+ purchaseState,
13
+ variableDictionary,
14
+ ...restProps
15
+ }: TextNodeProps = $props();
16
+
17
+ const { tagToRender, textStyles } = $derived(
18
+ getTextComponentStyles({
19
+ id,
20
+ labels,
21
+ text_lid,
22
+ purchaseState,
23
+ ...restProps,
24
+ }),
25
+ );
26
+ const styles = $derived(stringifyStyles(textStyles));
27
+
28
+ const label = $derived(
29
+ getLabelById(
30
+ text_lid,
31
+ purchaseState.locale,
32
+ purchaseState.defaultLocale,
33
+ labels,
34
+ ),
35
+ );
36
+ const parsedLabel = $derived(
37
+ replaceVariables({
38
+ value: label,
39
+ dictionary: variableDictionary,
40
+ }),
41
+ );
42
+ </script>
43
+
44
+ <Text styleVariables={styles} component={tagToRender} {id}>
45
+ {parsedLabel}
46
+ </Text>
@@ -0,0 +1,3 @@
1
+ import type { TextNodeProps } from "../../data/entities";
2
+ declare const TextNode: import("svelte").Component<TextNodeProps, {}, "">;
3
+ export default TextNode;
@@ -1,5 +1,5 @@
1
- import { type TextComponentTags } from "../../utils";
2
- import type { TextProps } from "../../data/entities";
1
+ import { type TextComponentTags } from "../../utils/style-utils";
2
+ import type { TextNodeProps } from "../../data/entities";
3
3
  type TextStyleVariables = {
4
4
  "--width": string;
5
5
  "--height": string;
@@ -13,7 +13,7 @@ type TextStyleVariables = {
13
13
  * @param props - Text component properties including font, color, background, spacing etc.
14
14
  * @returns Object containing text style variables and the appropriate HTML tag to render
15
15
  */
16
- export declare const getTextComponentStyles: (props: TextProps) => {
16
+ export declare const getTextComponentStyles: (props: TextNodeProps) => {
17
17
  textStyles: TextStyleVariables;
18
18
  tagToRender: TextComponentTags;
19
19
  };
@@ -1,5 +1,5 @@
1
- import { getSizeStyle, getTextComponentTag, getTextStyles, } from "../../utils";
2
- import { getComponentStyles } from "../../utils";
1
+ import { getSizeStyle, getTextComponentTag, getTextStyles, } from "../../utils/style-utils";
2
+ import { getComponentStyles } from "../../utils/style-utils";
3
3
  /**
4
4
  * Generates comprehensive styles for text components by combining text, component and size styles
5
5
  * @param props - Text component properties including font, color, background, spacing etc.
@@ -1,5 +1,6 @@
1
1
  import type { BorderType, ColorMode, ColorType, CornerRadiusType, DimensionType, FitTypes, FontSizeTags, FontWeights, ShadowType, ShapeType, SizeType, Spacing, TextAlignment } from "../types";
2
2
  import type { PurchaseState } from "./state";
3
+ import type { VariableDictionary } from "../utils/variable-utils";
3
4
  export interface Extra {
4
5
  [key: string]: any;
5
6
  }
@@ -104,7 +105,7 @@ export interface StackProps extends SharedComponentProps {
104
105
  spacing?: number;
105
106
  type: "stack";
106
107
  }
107
- export interface TextProps extends SharedComponentProps {
108
+ export interface TextNodeProps extends SharedComponentProps {
108
109
  background_color?: ColorType;
109
110
  color: ColorType;
110
111
  components: PaywallComponent[];
@@ -117,6 +118,7 @@ export interface TextProps extends SharedComponentProps {
117
118
  text_lid: string;
118
119
  type: "text";
119
120
  size: SizeType;
121
+ variableDictionary?: VariableDictionary;
120
122
  }
121
123
  type ImageSourceDictionaryType = Record<"original" | "heic" | "heic_low_res" | "webp" | "webp_low_res", string>;
122
124
  type ImageSourceType = {
@@ -3,6 +3,7 @@ export declare const paywallData: PaywallData;
3
3
  export declare const alignmentPaywallData: PaywallData;
4
4
  export declare const fontsPaywallData: PaywallData;
5
5
  export declare const pastaPaywallData: PaywallData;
6
+ export declare const calmPaywallData: PaywallData;
6
7
  export declare const labelsData: {
7
8
  en_US: {
8
9
  id1: string;