@revenuecat/purchases-ui-js 0.0.12 → 0.0.14

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 (36) hide show
  1. package/dist/components/button/Button.svelte +1 -1
  2. package/dist/components/button/ButtonNode.stories.svelte +1 -1
  3. package/dist/components/button/ButtonNode.svelte +9 -3
  4. package/dist/components/footer/Footer.svelte +3 -3
  5. package/dist/components/image/Image.svelte +6 -3
  6. package/dist/components/image/image-utils.js +1 -1
  7. package/dist/components/package/Package.svelte +23 -7
  8. package/dist/components/paywall/Node.svelte +20 -14
  9. package/dist/components/paywall/Node.svelte.d.ts +2 -2
  10. package/dist/components/paywall/Paywall.stories.svelte +96 -1
  11. package/dist/components/paywall/Paywall.svelte +14 -2
  12. package/dist/components/paywall/Paywall.svelte.d.ts +2 -0
  13. package/dist/components/purchase-button/PurchaseButton.svelte +9 -4
  14. package/dist/components/stack/Stack.svelte +10 -4
  15. package/dist/components/stack/stack-utils.d.ts +2 -1
  16. package/dist/components/stack/stack-utils.js +1 -1
  17. package/dist/components/text/Text.svelte +17 -27
  18. package/dist/components/text/Text.svelte.d.ts +7 -2
  19. package/dist/components/text/{Text.stories.svelte → TextNode.stories.svelte} +55 -3
  20. package/dist/components/text/{Text.stories.svelte.d.ts → TextNode.stories.svelte.d.ts} +4 -4
  21. package/dist/components/text/TextNode.svelte +46 -0
  22. package/dist/components/text/TextNode.svelte.d.ts +3 -0
  23. package/dist/components/text/text-utils.d.ts +3 -3
  24. package/dist/components/text/text-utils.js +2 -2
  25. package/dist/data/entities.d.ts +4 -1
  26. package/dist/data/state.d.ts +2 -0
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.js +1 -0
  29. package/dist/stories/fixtures.d.ts +3 -0
  30. package/dist/stories/fixtures.js +5331 -0
  31. package/dist/types.d.ts +8 -2
  32. package/dist/{utils.d.ts → utils/style-utils.d.ts} +14 -4
  33. package/dist/{utils.js → utils/style-utils.js} +33 -12
  34. package/dist/utils/variable-utils.d.ts +33 -0
  35. package/dist/utils/variable-utils.js +34 -0
  36. package/package.json +3 -2
package/dist/types.d.ts CHANGED
@@ -1,7 +1,13 @@
1
1
  export type ColorMode = "light" | "dark";
2
+ export type ColorStop = {
3
+ color: string;
4
+ percent: number;
5
+ };
2
6
  type Color = {
3
- type: "hex" | "alias";
4
- value: string;
7
+ type: "hex" | "alias" | "linear" | "radial";
8
+ value?: string;
9
+ degrees?: number;
10
+ points?: ColorStop[];
5
11
  };
6
12
  export type ColorType = {
7
13
  dark?: Color;
@@ -1,5 +1,5 @@
1
- import type { ComponentLocalizations, ImageMaskShapeType, PaywallData, TextProps } from "./data/entities.js";
2
- import { type BorderType, type ColorMode, type ColorType, type DimensionType, FontSizeTags, type ShadowType, type ShapeType, type SizeType, type Spacing } from "./types.js";
1
+ import type { ComponentLocalizations, ImageMaskShapeType, PaywallData, TextNodeProps } from "../data/entities.js";
2
+ import { type BorderType, type ColorMode, type ColorType, type DimensionType, FontSizeTags, type ShadowType, type ShapeType, type SizeType, type Spacing } from "../types.js";
3
3
  export type TextComponentTags = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
4
4
  /**
5
5
  * Maps font size to appropriate HTML heading tag
@@ -7,6 +7,16 @@ export type TextComponentTags = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
7
7
  * @returns Corresponding HTML heading tag
8
8
  */
9
9
  export declare function getTextComponentTag(fontSize: keyof typeof FontSizeTags): TextComponentTags;
10
+ /**
11
+ * Gets color value based on color mode with fallback
12
+ * @param params - Object containing color map, mode and fallback color
13
+ * @returns Color value as string
14
+ */
15
+ export declare function getColor({ colorMap, colorMode, fallback, }: {
16
+ colorMap?: ColorType;
17
+ colorMode?: ColorMode;
18
+ fallback?: string;
19
+ }): string;
10
20
  /**
11
21
  * Generates comprehensive component styles including spacing, colors, borders and shadows
12
22
  * @param params - Component style configuration object
@@ -30,7 +40,7 @@ export declare function getComponentStyles({ backgroundColor, border, margin, pa
30
40
  "--padding-inline-end": string;
31
41
  "--padding-block-end": string;
32
42
  "--padding-inline-start": string;
33
- "--background-color": string;
43
+ "--background": string;
34
44
  "--text-color": string;
35
45
  "--border": string;
36
46
  "--border-radius": string;
@@ -79,7 +89,7 @@ export declare function getDimensionStyle(dimension: DimensionType): {
79
89
  * @param props - Text component properties
80
90
  * @returns CSS style object with text formatting properties
81
91
  */
82
- export declare function getTextStyles(props: TextProps): {
92
+ export declare function getTextStyles(props: TextNodeProps): {
83
93
  "--text-align": string;
84
94
  "--font-weight": number;
85
95
  "--font-size": string;
@@ -1,4 +1,4 @@
1
- import { FontSizes, FontSizeTags, FontWeights, StackAlignment, StackDirection, StackDistribution, } from "./types.js";
1
+ import { FontSizes, FontSizeTags, FontWeights, StackAlignment, StackDirection, StackDistribution, } from "../types.js";
2
2
  /**
3
3
  * Generates CSS spacing styles for margin or padding
4
4
  * @param spacing - The spacing object containing top, trailing, bottom, and leading values
@@ -28,8 +28,28 @@ export function getTextComponentTag(fontSize) {
28
28
  * @param params - Object containing color map, mode and fallback color
29
29
  * @returns Color value as string
30
30
  */
31
- function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }) {
32
- return colorMap?.[colorMode]?.value || fallback;
31
+ export function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }) {
32
+ const color = colorMap?.[colorMode];
33
+ if (!color) {
34
+ return fallback;
35
+ }
36
+ let colorPoints = "";
37
+ switch (color.type) {
38
+ case "hex":
39
+ case "alias":
40
+ return color.value ?? fallback;
41
+ case "linear":
42
+ colorPoints = (color.points || [])
43
+ .map((point) => `${point.color} ${point.percent}%`)
44
+ .join(", ");
45
+ return `linear-gradient(${color.degrees}deg, ${colorPoints})`;
46
+ case "radial":
47
+ colorPoints = (color.points || [])
48
+ .map((point) => `${point.color} ${point.percent}%`)
49
+ .join(", ");
50
+ return `radial-gradient(${colorPoints})`;
51
+ }
52
+ return fallback;
33
53
  }
34
54
  /**
35
55
  * Generates CSS border style string
@@ -64,7 +84,7 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
64
84
  "--padding-inline-end": "0px",
65
85
  "--padding-block-end": "0px",
66
86
  "--padding-inline-start": "0px",
67
- "--background-color": "transparent",
87
+ "--background": "transparent",
68
88
  "--text-color": "#000000",
69
89
  "--border": "none",
70
90
  "--border-radius": "0px",
@@ -77,7 +97,7 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
77
97
  Object.assign(stylesObject, getSpacingStyle(margin, "margin"));
78
98
  }
79
99
  if (backgroundColor) {
80
- stylesObject["--background-color"] = getColor({
100
+ stylesObject["--background"] = getColor({
81
101
  colorMap: backgroundColor,
82
102
  colorMode,
83
103
  fallback: "transparent",
@@ -97,11 +117,11 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
97
117
  stylesObject["--border-radius"] = getCornerRadiusStyle(shape.corners);
98
118
  }
99
119
  if (shape?.type === "pill") {
100
- stylesObject["--border-radius"] = "9999px;";
120
+ stylesObject["--border-radius"] = "9999px";
101
121
  }
102
122
  if (shadow) {
103
123
  stylesObject["--shadow"] = `${shadow.x}px ${shadow.y}px ${shadow.radius}px
104
- ${getColor({ colorMap: shadow.color, colorMode, fallback: "#000000" })};`;
124
+ ${getColor({ colorMap: shadow.color, colorMode, fallback: "#000000" })}`;
105
125
  }
106
126
  return stylesObject;
107
127
  }
@@ -119,6 +139,7 @@ export function getSizeStyle(size) {
119
139
  return "fit-content";
120
140
  }
121
141
  if (size.type === "fill") {
142
+ // return "100%";
122
143
  const userAgent = navigator.userAgent;
123
144
  const isFirefox = userAgent.match(/firefox|fxios/i);
124
145
  return isFirefox ? "-moz-available" : "-webkit-fill-available";
@@ -142,7 +163,7 @@ export function getSizeStyle(size) {
142
163
  */
143
164
  export function getGradientStyle(colorMode, gradientColors) {
144
165
  if (!gradientColors)
145
- return { "--background": "unset" };
166
+ return { "--background": "none" };
146
167
  return {
147
168
  "--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value).join(", ")})`,
148
169
  };
@@ -180,9 +201,9 @@ export const getMaskStyle = (maskShape) => {
180
201
  */
181
202
  export function getDimensionStyle(dimension) {
182
203
  const styles = {
183
- "--direction": "row",
184
- "--alignment": "unset",
185
- "--distribution": "unset",
204
+ "--direction": "initial",
205
+ "--alignment": "initial",
206
+ "--distribution": "initial",
186
207
  };
187
208
  if (dimension.type === "zlayer") {
188
209
  // TODO: Review with Monetization team
@@ -222,7 +243,7 @@ export function getTextStyles(props) {
222
243
  */
223
244
  export function stringifyStyles(styles) {
224
245
  return Object.entries(styles)
225
- .map(([key, value]) => `${key}: ${value};`)
246
+ .map(([key, value]) => `${key}: ${value}`)
226
247
  .join("; ");
227
248
  }
228
249
  /**
@@ -0,0 +1,33 @@
1
+ export declare const VARIABLE_NAMES: string[];
2
+ export type VariableDictionary = {
3
+ product_name: string | number | undefined;
4
+ price: string | number | undefined;
5
+ price_per_period: string | number | undefined;
6
+ price_per_period_full: string | number | undefined;
7
+ total_price_and_per_month: string | number | undefined;
8
+ total_price_and_per_month_full: string | number | undefined;
9
+ sub_price_per_month: string | number | undefined;
10
+ sub_price_per_week: string | number | undefined;
11
+ sub_duration: string | number | undefined;
12
+ sub_duration_in_months: string | number | undefined;
13
+ sub_period: string | number | undefined;
14
+ sub_period_length: string | number | undefined;
15
+ sub_period_abbreviated: string | number | undefined;
16
+ sub_offer_duration: string | number | undefined;
17
+ sub_offer_duration_2: string | number | undefined;
18
+ sub_offer_price: string | number | undefined;
19
+ sub_offer_price_2: string | number | undefined;
20
+ sub_relative_discount: string | number | undefined;
21
+ [key: string]: string | number | undefined;
22
+ };
23
+ export type ReplaceVariablesProps = {
24
+ value?: string;
25
+ variableDictionary?: VariableDictionary;
26
+ };
27
+ /**
28
+ * Returns a string with the variables replaced by values from the dictionary
29
+ * @param value A string like "Try {{ product_name }} for only {{ total_price_and_per_month }}"
30
+ * @param dictionary Dictionary containing the values for the variables
31
+ * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
32
+ */
33
+ export declare const replaceVariables: ({ value, variableDictionary: dictionary, }: ReplaceVariablesProps) => string | undefined;
@@ -0,0 +1,34 @@
1
+ export const VARIABLE_NAMES = [
2
+ "product_name",
3
+ "price",
4
+ "price_per_period",
5
+ "price_per_period_full",
6
+ "total_price_and_per_month",
7
+ "total_price_and_per_month_full",
8
+ "sub_price_per_month",
9
+ "sub_price_per_week",
10
+ "sub_duration",
11
+ "sub_duration_in_months",
12
+ "sub_period",
13
+ "sub_period_length",
14
+ "sub_period_abbreviated",
15
+ "sub_offer_duration",
16
+ "sub_offer_duration_2",
17
+ "sub_offer_price",
18
+ "sub_offer_price_2",
19
+ "sub_relative_discount",
20
+ ];
21
+ /**
22
+ * Returns a string with the variables replaced by values from the dictionary
23
+ * @param value A string like "Try {{ product_name }} for only {{ total_price_and_per_month }}"
24
+ * @param dictionary Dictionary containing the values for the variables
25
+ * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
26
+ */
27
+ export const replaceVariables = ({ value = "", variableDictionary: dictionary, }) => {
28
+ if (!dictionary)
29
+ return value;
30
+ return VARIABLE_NAMES.reduce((result, variableName) => {
31
+ const currentVariableReplaced = result.replaceAll(`{{ ${variableName} }}`, dictionary[variableName]?.toString() || "N/A");
32
+ return currentVariableReplaced;
33
+ }, value);
34
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@revenuecat/purchases-ui-js",
3
3
  "description": "Web components for Paywalls. Powered by RevenueCat",
4
4
  "private": false,
5
- "version": "0.0.12",
5
+ "version": "0.0.14",
6
6
  "author": {
7
7
  "name": "RevenueCat, Inc."
8
8
  },
@@ -35,7 +35,8 @@
35
35
  "prepare": "husky",
36
36
  "chromatic": "chromatic",
37
37
  "format": "prettier --write .",
38
- "typecheck": "tsc --noEmit"
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "vitest"
39
40
  },
40
41
  "files": [
41
42
  "dist",