@revenuecat/purchases-ui-js 0.0.14 → 0.0.16

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
@@ -31,7 +31,7 @@ export declare enum FontWeights {
31
31
  light = 300,
32
32
  regular = 400,
33
33
  medium = 500,
34
- semi_bold = 600,
34
+ semibold = 600,
35
35
  bold = 700,
36
36
  extra_bold = 800,
37
37
  black = 900
package/dist/types.js CHANGED
@@ -19,7 +19,7 @@ export var FontWeights;
19
19
  FontWeights[FontWeights["light"] = 300] = "light";
20
20
  FontWeights[FontWeights["regular"] = 400] = "regular";
21
21
  FontWeights[FontWeights["medium"] = 500] = "medium";
22
- FontWeights[FontWeights["semi_bold"] = 600] = "semi_bold";
22
+ FontWeights[FontWeights["semibold"] = 600] = "semibold";
23
23
  FontWeights[FontWeights["bold"] = 700] = "bold";
24
24
  FontWeights[FontWeights["extra_bold"] = 800] = "extra_bold";
25
25
  FontWeights[FontWeights["black"] = 900] = "black";
@@ -1,4 +1,4 @@
1
- import type { ComponentLocalizations, ImageMaskShapeType, PaywallData, TextNodeProps } from "../data/entities.js";
1
+ import type { ComponentLocalizations, ComponentState, ImageMaskShapeType, PaywallData, TextNodeProps } from "../data/entities.js";
2
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
  /**
@@ -87,14 +87,10 @@ export declare function getDimensionStyle(dimension: DimensionType): {
87
87
  /**
88
88
  * Generates text-related styles
89
89
  * @param props - Text component properties
90
+ * @param colorMode - The currently selected ColorMode (dark/light)
90
91
  * @returns CSS style object with text formatting properties
91
92
  */
92
- export declare function getTextStyles(props: TextNodeProps): {
93
- "--text-align": string;
94
- "--font-weight": number;
95
- "--font-size": string;
96
- "--font-family": string;
97
- };
93
+ export declare function getTextStyles(props: TextNodeProps, colorMode?: ColorMode): Record<string, unknown>;
98
94
  /**
99
95
  * Converts a style object to a CSS string
100
96
  * @param styles - Object containing CSS properties and values
@@ -118,3 +114,4 @@ export declare function getLabelById(label_id: string, locale: string, fallbackL
118
114
  * @returns the id of the first package marked as `is_selected_by_default` or undefined
119
115
  */
120
116
  export declare function findSelectedPackageId(paywallData: PaywallData): string | undefined;
117
+ export declare const getActiveStateProps: <T>(overrides?: Record<string, T>, componentState?: ComponentState) => T;
@@ -29,10 +29,9 @@ export function getTextComponentTag(fontSize) {
29
29
  * @returns Color value as string
30
30
  */
31
31
  export function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }) {
32
- const color = colorMap?.[colorMode];
33
- if (!color) {
32
+ if (!colorMap)
34
33
  return fallback;
35
- }
34
+ const color = colorMap[colorMode] || colorMap["light"];
36
35
  let colorPoints = "";
37
36
  switch (color.type) {
38
37
  case "hex":
@@ -139,7 +138,6 @@ export function getSizeStyle(size) {
139
138
  return "fit-content";
140
139
  }
141
140
  if (size.type === "fill") {
142
- // return "100%";
143
141
  const userAgent = navigator.userAgent;
144
142
  const isFirefox = userAgent.match(/firefox|fxios/i);
145
143
  return isFirefox ? "-moz-available" : "-webkit-fill-available";
@@ -165,7 +163,7 @@ export function getGradientStyle(colorMode, gradientColors) {
165
163
  if (!gradientColors)
166
164
  return { "--background": "none" };
167
165
  return {
168
- "--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value).join(", ")})`,
166
+ "--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value || color["light"].value).join(", ")})`,
169
167
  };
170
168
  }
171
169
  /**
@@ -174,7 +172,7 @@ export function getGradientStyle(colorMode, gradientColors) {
174
172
  * @returns CSS style object with mask properties
175
173
  */
176
174
  export const getMaskStyle = (maskShape) => {
177
- let maskStyles = {
175
+ const maskStyles = {
178
176
  "--corner-radius": "0px",
179
177
  "--clip-path": "none",
180
178
  };
@@ -220,20 +218,29 @@ export function getDimensionStyle(dimension) {
220
218
  /**
221
219
  * Generates text-related styles
222
220
  * @param props - Text component properties
221
+ * @param colorMode - The currently selected ColorMode (dark/light)
223
222
  * @returns CSS style object with text formatting properties
224
223
  */
225
- export function getTextStyles(props) {
226
- const { font_size, horizontal_alignment, font_weight, font_name } = props;
224
+ export function getTextStyles(props, colorMode = "light") {
225
+ const { font_size, horizontal_alignment, font_weight, font_name, color } = props;
227
226
  const styles = {
228
227
  "--text-align": "initial",
229
228
  "--font-weight": 400,
230
229
  "--font-size": "initial",
231
230
  "--font-family": "sans-serif",
231
+ "--background-clip": "initial",
232
+ "--text-fill-color": "initial",
232
233
  };
233
234
  styles["--text-align"] = horizontal_alignment;
234
- styles["--font-weight"] = FontWeights[font_weight];
235
- styles["--font-size"] = FontSizes[font_size];
235
+ styles["--font-weight"] = FontWeights[font_weight] || FontWeights.regular;
236
+ styles["--font-size"] = FontSizes[font_size] || FontSizes.body_m;
236
237
  styles["--font-family"] = font_name || "sans-serif";
238
+ if (color &&
239
+ (color[colorMode]?.type === "linear" || color[colorMode]?.type === "radial")) {
240
+ styles["--background-clip"] = "text";
241
+ styles["--text-fill-color"] = "transparent";
242
+ styles["--background"] = getColor({ colorMap: color, colorMode });
243
+ }
237
244
  return styles;
238
245
  }
239
246
  /**
@@ -257,7 +264,7 @@ export function stringifyStyles(styles) {
257
264
  * @returns The label in the preferred or fallback locale, or undefined.
258
265
  */
259
266
  export function getLabelById(label_id, locale, fallbackLocale, labels) {
260
- const fallback = (labels[fallbackLocale] || {})[label_id];
267
+ const fallback = labels[fallbackLocale]?.[label_id];
261
268
  if (!(labels[locale] || {})[label_id]) {
262
269
  return fallback;
263
270
  }
@@ -274,8 +281,8 @@ export function findSelectedPackageId(paywallData) {
274
281
  node.is_selected_by_default) {
275
282
  return node;
276
283
  }
277
- if (node.components) {
278
- for (let c of node.components) {
284
+ if (node.components && Array.isArray(node.components)) {
285
+ for (const c of node.components) {
279
286
  const pkg = traverseNode(c);
280
287
  if (pkg) {
281
288
  return pkg;
@@ -296,3 +303,26 @@ export function findSelectedPackageId(paywallData) {
296
303
  }
297
304
  return p.package_id;
298
305
  }
306
+ export const getActiveStateProps = (overrides, componentState) => {
307
+ if (!componentState)
308
+ return {};
309
+ const activeStateKeys = getComponentActiveStateKeys(componentState);
310
+ const activeStateProps = activeStateKeys.reduce((props, key) => {
311
+ if (overrides) {
312
+ const styles = overrides[key] || {};
313
+ return { ...props, ...styles };
314
+ }
315
+ return props;
316
+ }, {});
317
+ return activeStateProps;
318
+ };
319
+ const getComponentActiveStateKeys = (componentState) => {
320
+ if (!componentState)
321
+ return [];
322
+ const stateKeys = Object.entries(componentState).reduce((activeStates, [stateKey, stateValue]) => {
323
+ if (stateValue)
324
+ activeStates.push(stateKey);
325
+ return activeStates;
326
+ }, []);
327
+ return stateKeys;
328
+ };
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.14",
5
+ "version": "0.0.16",
6
6
  "author": {
7
7
  "name": "RevenueCat, Inc."
8
8
  },
@@ -36,7 +36,8 @@
36
36
  "chromatic": "chromatic",
37
37
  "format": "prettier --write .",
38
38
  "typecheck": "tsc --noEmit",
39
- "test": "vitest"
39
+ "test": "vitest",
40
+ "lint": "eslint --config eslint.config.js src/**/*"
40
41
  },
41
42
  "files": [
42
43
  "dist",
@@ -61,6 +62,7 @@
61
62
  },
62
63
  "devDependencies": {
63
64
  "@chromatic-com/storybook": "^1.9.0",
65
+ "@eslint/js": "^9.16.0",
64
66
  "@storybook/addon-essentials": "^8.3.6",
65
67
  "@storybook/addon-interactions": "^8.3.6",
66
68
  "@storybook/addon-links": "^8.3.6",
@@ -73,7 +75,11 @@
73
75
  "@sveltejs/kit": "^2.0.0",
74
76
  "@sveltejs/package": "^2.0.0",
75
77
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
78
+ "@typescript-eslint/parser": "^8.17.0",
76
79
  "chromatic": "^11.16.1",
80
+ "eslint": "^9.16.0",
81
+ "eslint-plugin-svelte": "^2.46.1",
82
+ "globals": "^15.13.0",
77
83
  "husky": "^9.1.6",
78
84
  "lint-staged": "^15.2.10",
79
85
  "prettier": "^3.3.3",
@@ -83,10 +89,14 @@
83
89
  "svelte": "^5.0.0",
84
90
  "svelte-check": "^4.0.0",
85
91
  "typescript": "^5.0.0",
92
+ "typescript-eslint": "^8.17.0",
86
93
  "vite": "^5.0.11"
87
94
  },
88
95
  "lint-staged": {
89
- "**/*": "prettier --write --ignore-unknown"
96
+ "**/*": [
97
+ "prettier --write --ignore-unknown",
98
+ "eslint --fix"
99
+ ]
90
100
  },
91
101
  "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
92
102
  }