@revenuecat/purchases-ui-js 2.0.5 → 2.1.0

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 (39) hide show
  1. package/dist/components/button/ButtonNode.stories.svelte +20 -0
  2. package/dist/components/button/ButtonNode.svelte +12 -4
  3. package/dist/components/paywall/Node.svelte +4 -0
  4. package/dist/components/paywall/Paywall.svelte +11 -5
  5. package/dist/components/paywall/Paywall.svelte.d.ts +1 -0
  6. package/dist/components/stack/Stack.svelte +6 -3
  7. package/dist/components/stack/Stack.svelte.d.ts +2 -0
  8. package/dist/components/tabs/TabControlToggle.svelte +103 -0
  9. package/dist/components/tabs/TabControlToggle.svelte.d.ts +4 -0
  10. package/dist/components/tabs/Tabs.stories.svelte +439 -0
  11. package/dist/components/tabs/Tabs.svelte +12 -5
  12. package/dist/components/tabs/tabs-context.d.ts +1 -0
  13. package/dist/components/text/TextNode.stories.svelte +106 -0
  14. package/dist/components/text/TextNode.svelte +5 -3
  15. package/dist/components/text/text-utils.d.ts +5 -5
  16. package/dist/components/text/text-utils.js +34 -19
  17. package/dist/components/timeline/TimelineItem.svelte +4 -8
  18. package/dist/components/video/Video.stories.svelte +267 -0
  19. package/dist/components/video/Video.stories.svelte.d.ts +19 -0
  20. package/dist/components/video/Video.svelte +248 -0
  21. package/dist/components/video/Video.svelte.d.ts +4 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/stores/paywall.d.ts +1 -1
  25. package/dist/stories/paywall-decorator.js +1 -1
  26. package/dist/types/base.d.ts +1 -0
  27. package/dist/types/component.d.ts +3 -2
  28. package/dist/types/components/button.d.ts +7 -1
  29. package/dist/types/components/tabs.d.ts +10 -0
  30. package/dist/types/components/text.d.ts +2 -2
  31. package/dist/types/components/video.d.ts +35 -0
  32. package/dist/types/components/video.js +1 -0
  33. package/dist/types/media.d.ts +17 -4
  34. package/dist/types/ui-config.d.ts +1 -1
  35. package/dist/utils/base-utils.d.ts +2 -1
  36. package/dist/utils/base-utils.js +1 -1
  37. package/dist/utils/style-utils.d.ts +0 -30
  38. package/dist/utils/style-utils.js +0 -66
  39. package/package.json +1 -1
@@ -6,7 +6,8 @@ import type { ImageProps } from "./components/image";
6
6
  import type { PackageProps } from "./components/package";
7
7
  import type { PurchaseButtonProps } from "./components/purchase-button";
8
8
  import type { StackProps } from "./components/stack";
9
- import type { TabControlButtonProps, TabControlProps, TabsProps } from "./components/tabs";
9
+ import type { TabControlButtonProps, TabControlProps, TabControlToggleProps, TabsProps } from "./components/tabs";
10
10
  import type { TextNodeProps } from "./components/text";
11
11
  import type { TimelineProps } from "./components/timeline";
12
- export type Component = ButtonProps | CarouselProps | FooterProps | IconProps | ImageProps | PackageProps | PurchaseButtonProps | StackProps | TabControlButtonProps | TabControlProps | TabsProps | TextNodeProps | TimelineProps;
12
+ import type { VideoProps } from "./components/video";
13
+ export type Component = ButtonProps | CarouselProps | FooterProps | IconProps | ImageProps | PackageProps | PurchaseButtonProps | StackProps | TabControlButtonProps | TabControlToggleProps | TabControlProps | TabsProps | TextNodeProps | TimelineProps | VideoProps;
@@ -2,6 +2,9 @@ import type { BaseComponent } from "../base";
2
2
  import type { Overrides } from "../overrides";
3
3
  import type { SheetProps } from "./sheet";
4
4
  import type { StackProps } from "./stack";
5
+ interface WorkflowAction {
6
+ type: "workflow";
7
+ }
5
8
  interface RestorePurchasesAction {
6
9
  type: "restore_purchases";
7
10
  }
@@ -31,12 +34,15 @@ interface NavigateToUrlAction {
31
34
  method: "deep_link" | "external_browser" | "in_app_browser";
32
35
  };
33
36
  }
34
- export type Action = RestorePurchasesAction | NavigateBackAction | NavigateToAction | NavigateToSheetAction | NavigateToWebPurchase | NavigateToUrlAction;
37
+ export type Action = WorkflowAction | RestorePurchasesAction | NavigateBackAction | NavigateToAction | NavigateToSheetAction | NavigateToWebPurchase | NavigateToUrlAction;
35
38
  export interface ButtonProps extends BaseComponent {
36
39
  type: "button";
37
40
  action: Action;
38
41
  stack: StackProps;
39
42
  transition?: null;
43
+ triggers?: {
44
+ on_press?: string;
45
+ };
40
46
  overrides?: Overrides<ButtonProps>;
41
47
  }
42
48
  export {};
@@ -1,6 +1,7 @@
1
1
  import type { BorderType, ShadowType, ShapeType, SizeType, Spacing } from "..";
2
2
  import type { Background } from "../background";
3
3
  import type { BaseComponent } from "../base";
4
+ import type { ColorGradientScheme } from "../colors";
4
5
  import type { Overrides } from "../overrides";
5
6
  import type { StackProps } from "./stack";
6
7
  type TabControlType = "buttons" | "toggle";
@@ -43,4 +44,13 @@ export interface TabControlButtonProps extends BaseComponent {
43
44
  */
44
45
  tab_index: number;
45
46
  }
47
+ export interface TabControlToggleProps extends BaseComponent {
48
+ type: "tab_control_toggle";
49
+ default_value: boolean;
50
+ thumb_color_on: ColorGradientScheme;
51
+ thumb_color_off: ColorGradientScheme;
52
+ track_color_on: ColorGradientScheme;
53
+ track_color_off: ColorGradientScheme;
54
+ overrides?: Overrides<TabControlToggleProps>;
55
+ }
46
56
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { FontSizes, FontWeights, SizeType, Spacing, TextAlignments } from "..";
2
2
  import type { BaseComponent } from "../base";
3
- import type { ColorGradientScheme, ColorScheme } from "../colors";
3
+ import type { ColorGradientScheme } from "../colors";
4
4
  import type { Overrides } from "../overrides";
5
5
  export interface TextNodeProps extends BaseComponent {
6
6
  text_lid: string;
@@ -9,7 +9,7 @@ export interface TextNodeProps extends BaseComponent {
9
9
  font_weight: keyof typeof FontWeights;
10
10
  font_weight_int?: number;
11
11
  horizontal_alignment: keyof typeof TextAlignments;
12
- color: ColorScheme;
12
+ color: ColorGradientScheme;
13
13
  background_color?: ColorGradientScheme | null;
14
14
  type: "text";
15
15
  visible?: boolean | null;
@@ -0,0 +1,35 @@
1
+ import type { BorderType, CircleShape, ConcaveShape, ConvexShape, RectangleShape, ShadowType, SizeType, Spacing } from "..";
2
+ import type { BaseComponent } from "../base";
3
+ import type { ColorGradientScheme } from "../colors";
4
+ import type { FitMode, ImageInfo, VideoInfo } from "../media";
5
+ import type { Overrides } from "../overrides";
6
+ export type VideoObjectFit = "fit" | "fill";
7
+ export type VideoMaskShape = {
8
+ type: "rectangle" | "circle" | "concave" | "convex";
9
+ corners?: {
10
+ top_leading?: number;
11
+ top_trailing?: number;
12
+ bottom_leading?: number;
13
+ bottom_trailing?: number;
14
+ } | null;
15
+ };
16
+ export interface VideoProps extends BaseComponent {
17
+ type: "video";
18
+ visible?: boolean | null;
19
+ source: VideoInfo | null;
20
+ fallback_source?: ImageInfo | null;
21
+ override_source_lid?: string | null;
22
+ size: SizeType;
23
+ mask_shape?: RectangleShape | CircleShape | ConcaveShape | ConvexShape | null;
24
+ fit_mode: FitMode;
25
+ padding?: Spacing | null;
26
+ margin?: Spacing | null;
27
+ color_overlay?: ColorGradientScheme | null;
28
+ border?: BorderType | null;
29
+ shadow?: ShadowType | null;
30
+ overrides?: Overrides<VideoProps>;
31
+ auto_play: boolean;
32
+ loop: boolean;
33
+ mute_audio: boolean;
34
+ show_controls: boolean;
35
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- type ImageFiles = {
1
+ export type ImageFiles = {
2
2
  width: number;
3
3
  height: number;
4
4
  original: string;
@@ -11,9 +11,22 @@ export type ImageInfo = {
11
11
  light: ImageFiles;
12
12
  dark?: ImageFiles | null;
13
13
  };
14
+ export type VideoFiles = {
15
+ width: number;
16
+ height: number;
17
+ url: string;
18
+ url_low_res: string;
19
+ checksum?: {
20
+ algo: string;
21
+ value: string;
22
+ } | null;
23
+ checksum_low_res?: {
24
+ algo: string;
25
+ value: string;
26
+ } | null;
27
+ };
14
28
  export type VideoInfo = {
15
- light: string;
16
- dark: string | null;
29
+ light: VideoFiles;
30
+ dark?: VideoFiles | null;
17
31
  };
18
32
  export type FitMode = "fit" | "fill";
19
- export {};
@@ -7,7 +7,7 @@ type AppFontFamilyConfig = {
7
7
  url: string;
8
8
  weight: number;
9
9
  };
10
- type AppFontsConfig = Record<string, {
10
+ export type AppFontsConfig = Record<string, {
11
11
  ios?: AppFontFamilyConfig;
12
12
  android?: AppFontFamilyConfig;
13
13
  web?: AppFontFamilyConfig;
@@ -1,5 +1,5 @@
1
1
  import type { BorderType, CircleShape, ColorMode, ConcaveShape, ConvexShape, PillShape, RectangleShape, ShadowType, Size, Spacing } from "../types";
2
- import type { ColorGradientScheme, ColorScheme } from "../types/colors";
2
+ import type { ColorGradientInfo, ColorGradientScheme, ColorScheme } from "../types/colors";
3
3
  import type { FitMode } from "../types/media";
4
4
  export type CSS = Record<string, string | number>;
5
5
  export declare function css(props: CSS): string;
@@ -10,6 +10,7 @@ export declare function mapColorMode<T>(colorMode: ColorMode, value: {
10
10
  }): T;
11
11
  export declare function mapSize(size: Size): string;
12
12
  export declare function mapSpacing(spacing?: Spacing | null): string;
13
+ export declare function mapColorInfo(info: ColorGradientInfo): string;
13
14
  export declare function mapColor(colorMode: ColorMode, scheme: ColorScheme | ColorGradientScheme | null | undefined): string;
14
15
  export declare function mapOverlay(colorMode: ColorMode, colorOverlay: ColorGradientScheme | null | undefined): string;
15
16
  export declare function mapBorder(colorMode: ColorMode, border: BorderType | null | undefined): string;
@@ -37,7 +37,7 @@ export function mapSpacing(spacing) {
37
37
  const { top, bottom, leading, trailing } = spacing ?? DEFAULT_SPACING;
38
38
  return mapTuple(top, trailing, bottom, leading);
39
39
  }
40
- function mapColorInfo(info) {
40
+ export function mapColorInfo(info) {
41
41
  if (info.type === "alias" || info.type === "hex") {
42
42
  return info.value;
43
43
  }
@@ -1,35 +1,6 @@
1
- import type { ColorGradientScheme } from "../types/colors.js";
2
1
  import type { Component } from "../types/component.js";
3
- import type { TextNodeProps } from "../types/components/text";
4
2
  import type { Overrides } from "../types/overrides.js";
5
3
  import type { RootPaywall } from "../types/paywall.js";
6
- import { type ColorMode } from "../types.js";
7
- /**
8
- * Gets color value based on color mode with fallback
9
- * @param params - Object containing color map, mode and fallback color
10
- * @returns Color value as string
11
- */
12
- export declare function getColor({ colorMap, colorMode, fallback, }: {
13
- colorMap?: ColorGradientScheme | null;
14
- colorMode?: ColorMode;
15
- fallback?: string;
16
- }): string;
17
- type TextStyleVariables = {
18
- "--text-align": string;
19
- "--font-weight": number | string;
20
- "--font-size": string;
21
- "--font-family": string;
22
- "--background-clip": string;
23
- "--text-fill-color": string;
24
- "--background": string;
25
- };
26
- /**
27
- * Generates text-related styles
28
- * @param props - Text component properties
29
- * @param colorMode - The currently selected ColorMode (dark/light)
30
- * @returns CSS style object with text formatting properties
31
- */
32
- export declare function getTextStyles(props: TextNodeProps): TextStyleVariables;
33
4
  /**
34
5
  * Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
35
6
  * @param paywallData
@@ -37,4 +8,3 @@ export declare function getTextStyles(props: TextNodeProps): TextStyleVariables;
37
8
  */
38
9
  export declare function findSelectedPackageId({ stack, sticky_footer, }: RootPaywall): string | undefined;
39
10
  export declare const getActiveStateProps: <T extends Component>(selectedState: boolean, overrides?: Overrides<T>) => Partial<T>;
40
- export {};
@@ -1,69 +1,3 @@
1
- import { getPaywallContext } from "../stores/paywall.js";
2
- import { DEFAULT_COLOR_MODE } from "./constants.js";
3
- import { FontSizes, FontWeights, TextAlignments, } from "../types.js";
4
- import { getScopedFontFamily, isFontRCFMManaged } from "./font-utils.js";
5
- /**
6
- * Gets color value based on color mode with fallback
7
- * @param params - Object containing color map, mode and fallback color
8
- * @returns Color value as string
9
- */
10
- export function getColor({ colorMap, colorMode = DEFAULT_COLOR_MODE, fallback = "FFFFFF", }) {
11
- if (!colorMap)
12
- return fallback;
13
- const color = colorMap[colorMode] || colorMap[DEFAULT_COLOR_MODE];
14
- let colorPoints = "";
15
- switch (color?.type) {
16
- case "hex":
17
- case "alias":
18
- return color.value ?? fallback;
19
- case "linear":
20
- colorPoints = (color.points || [])
21
- .map((point) => `${point.color} ${point.percent}%`)
22
- .join(", ");
23
- return `linear-gradient(${color.degrees}deg, ${colorPoints})`;
24
- case "radial":
25
- colorPoints = (color.points || [])
26
- .map((point) => `${point.color} ${point.percent}%`)
27
- .join(", ");
28
- return `radial-gradient(${colorPoints})`;
29
- default:
30
- return fallback;
31
- }
32
- }
33
- /**
34
- * Generates text-related styles
35
- * @param props - Text component properties
36
- * @param colorMode - The currently selected ColorMode (dark/light)
37
- * @returns CSS style object with text formatting properties
38
- */
39
- export function getTextStyles(props) {
40
- const { font_size, horizontal_alignment, font_weight, font_name, font_weight_int, } = props;
41
- const paywall = getPaywallContext();
42
- const uiConfig = paywall.uiConfig;
43
- const { fonts } = uiConfig.app;
44
- const font = fonts[font_name ?? ""];
45
- const fontFamily = font?.web?.family;
46
- const styles = {
47
- "--text-align": "initial",
48
- "--font-weight": "initial",
49
- "--font-size": "initial",
50
- "--font-family": "sans-serif",
51
- "--background-clip": "none",
52
- "--text-fill-color": "none",
53
- "--background": "unset",
54
- };
55
- Object.assign(styles, {
56
- "--text-align": TextAlignments[horizontal_alignment] || TextAlignments.leading,
57
- "--font-weight": font_weight_int ?? FontWeights[font_weight] ?? FontWeights.regular,
58
- "--font-size": Number.isInteger(Number(font_size))
59
- ? `${font_size}px`
60
- : FontSizes[font_size] || FontSizes.body_m,
61
- "--font-family": isFontRCFMManaged(font_name ?? "")
62
- ? getScopedFontFamily(fontFamily ?? "")
63
- : "sans-serif",
64
- });
65
- return styles;
66
- }
67
1
  /**
68
2
  * Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
69
3
  * @param paywallData
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": "2.0.5",
5
+ "version": "2.1.0",
6
6
  "author": {
7
7
  "name": "RevenueCat, Inc."
8
8
  },