@revenuecat/purchases-ui-js 0.0.13 → 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.
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;
@@ -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;
@@ -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",
@@ -143,7 +163,7 @@ export function getSizeStyle(size) {
143
163
  */
144
164
  export function getGradientStyle(colorMode, gradientColors) {
145
165
  if (!gradientColors)
146
- return { "--background": "unset" };
166
+ return { "--background": "none" };
147
167
  return {
148
168
  "--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value).join(", ")})`,
149
169
  };
@@ -1,8 +1,28 @@
1
1
  export declare const VARIABLE_NAMES: string[];
2
- export type VariableDictionary = Record<string, string | number | undefined>;
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
+ };
3
23
  export type ReplaceVariablesProps = {
4
24
  value?: string;
5
- dictionary?: VariableDictionary;
25
+ variableDictionary?: VariableDictionary;
6
26
  };
7
27
  /**
8
28
  * Returns a string with the variables replaced by values from the dictionary
@@ -10,4 +30,4 @@ export type ReplaceVariablesProps = {
10
30
  * @param dictionary Dictionary containing the values for the variables
11
31
  * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
12
32
  */
13
- export declare const replaceVariables: ({ value, dictionary, }: ReplaceVariablesProps) => string | undefined;
33
+ export declare const replaceVariables: ({ value, variableDictionary: dictionary, }: ReplaceVariablesProps) => string | undefined;
@@ -24,7 +24,7 @@ export const VARIABLE_NAMES = [
24
24
  * @param dictionary Dictionary containing the values for the variables
25
25
  * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
26
26
  */
27
- export const replaceVariables = ({ value = "", dictionary, }) => {
27
+ export const replaceVariables = ({ value = "", variableDictionary: dictionary, }) => {
28
28
  if (!dictionary)
29
29
  return value;
30
30
  return VARIABLE_NAMES.reduce((result, variableName) => {
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.13",
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",