@revenuecat/purchases-ui-js 2.0.2 → 2.0.3

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 (127) hide show
  1. package/dist/components/button/ButtonNode.stories.svelte +66 -102
  2. package/dist/components/button/ButtonNode.svelte +2 -27
  3. package/dist/components/footer/Footer.stories.svelte +112 -102
  4. package/dist/components/footer/Footer.svelte +8 -4
  5. package/dist/components/icon/Icon.stories.svelte +100 -0
  6. package/dist/components/icon/Icon.stories.svelte.d.ts +19 -0
  7. package/dist/components/icon/Icon.svelte +73 -0
  8. package/dist/components/icon/Icon.svelte.d.ts +4 -0
  9. package/dist/components/image/ClipPath.svelte +49 -0
  10. package/dist/components/image/ClipPath.svelte.d.ts +9 -0
  11. package/dist/components/image/Image.stories.svelte +83 -188
  12. package/dist/components/image/Image.svelte +152 -136
  13. package/dist/components/image/Image.svelte.d.ts +1 -1
  14. package/dist/components/image/Overlay.svelte +36 -0
  15. package/dist/components/image/Overlay.svelte.d.ts +8 -0
  16. package/dist/components/package/Package.stories.svelte +10 -21
  17. package/dist/components/package/Package.svelte +8 -35
  18. package/dist/components/paywall/Node.svelte +27 -28
  19. package/dist/components/paywall/Node.svelte.d.ts +3 -6
  20. package/dist/components/paywall/Paywall.stories.svelte +36 -140
  21. package/dist/components/paywall/Paywall.svelte +22 -6
  22. package/dist/components/paywall/Paywall.svelte.d.ts +3 -2
  23. package/dist/components/paywall/fixtures/override-paywall.d.ts +2 -0
  24. package/dist/components/paywall/fixtures/override-paywall.js +1310 -0
  25. package/dist/components/paywall/fixtures/stack-paywall.d.ts +2 -0
  26. package/dist/components/paywall/fixtures/stack-paywall.js +5223 -0
  27. package/dist/components/paywall/fixtures/variables.d.ts +261 -0
  28. package/dist/components/paywall/fixtures/variables.js +262 -0
  29. package/dist/components/purchase-button/PurchaseButton.stories.svelte +10 -21
  30. package/dist/components/purchase-button/PurchaseButton.svelte +2 -27
  31. package/dist/components/stack/Stack.stories.svelte +2354 -978
  32. package/dist/components/stack/Stack.svelte +111 -134
  33. package/dist/components/stack/Stack.svelte.d.ts +6 -2
  34. package/dist/components/stack/stack-utils.d.ts +10 -30
  35. package/dist/components/stack/stack-utils.js +77 -255
  36. package/dist/components/text/Text.svelte +3 -37
  37. package/dist/components/text/Text.svelte.d.ts +1 -2
  38. package/dist/components/text/TextNode.stories.svelte +10 -36
  39. package/dist/components/text/TextNode.svelte +25 -28
  40. package/dist/components/text/TextNode.svelte.d.ts +1 -1
  41. package/dist/components/text/text-utils.d.ts +4 -9
  42. package/dist/components/text/text-utils.js +32 -117
  43. package/dist/components/timeline/Timeline.stories.svelte +640 -251
  44. package/dist/components/timeline/Timeline.svelte +42 -28
  45. package/dist/components/timeline/Timeline.svelte.d.ts +1 -1
  46. package/dist/components/timeline/TimelineItem.svelte +80 -112
  47. package/dist/components/timeline/TimelineItem.svelte.d.ts +6 -2
  48. package/dist/components/timeline/timeline-utils.d.ts +24 -6
  49. package/dist/components/timeline/timeline-utils.js +21 -113
  50. package/dist/data/entities.d.ts +19 -135
  51. package/dist/index.d.ts +2 -1
  52. package/dist/index.js +2 -1
  53. package/dist/stores/color-mode.d.ts +1 -1
  54. package/dist/stores/paywall.d.ts +5 -2
  55. package/dist/stores/selected.d.ts +5 -0
  56. package/dist/stores/selected.js +12 -0
  57. package/dist/stores/variables.d.ts +1 -1
  58. package/dist/stores/variables.js +0 -1
  59. package/dist/stories/component-decorator.d.ts +2 -0
  60. package/dist/stories/component-decorator.js +12 -0
  61. package/dist/stories/fixtures.d.ts +5 -3
  62. package/dist/stories/fixtures.js +5214 -4422
  63. package/dist/stories/paywall-decorator.js +6 -0
  64. package/dist/stories/variables-decorator.d.ts +1 -1
  65. package/dist/stories/viewport-decorator.d.ts +2 -0
  66. package/dist/stories/viewport-decorator.js +8 -0
  67. package/dist/stories/viewport-wrapper.svelte +53 -0
  68. package/dist/stories/viewport-wrapper.svelte.d.ts +10 -0
  69. package/dist/stories/with-layout.d.ts +2 -10
  70. package/dist/stories/with-layout.js +3 -5
  71. package/dist/types/alignment.d.ts +5 -3
  72. package/dist/types/background.d.ts +6 -5
  73. package/dist/types/base.d.ts +7 -0
  74. package/dist/types/base.js +1 -0
  75. package/dist/types/colors.d.ts +4 -4
  76. package/dist/types/component.d.ts +6 -2
  77. package/dist/types/components/button.d.ts +4 -1
  78. package/dist/types/components/footer.d.ts +2 -1
  79. package/dist/types/components/icon.d.ts +28 -0
  80. package/dist/types/components/icon.js +1 -0
  81. package/dist/types/components/image.d.ts +20 -0
  82. package/dist/types/components/image.js +1 -0
  83. package/dist/types/components/package.d.ts +2 -1
  84. package/dist/types/components/purchase-button.d.ts +2 -1
  85. package/dist/types/components/stack.d.ts +32 -0
  86. package/dist/types/components/stack.js +1 -0
  87. package/dist/types/components/text.d.ts +20 -0
  88. package/dist/types/components/text.js +1 -0
  89. package/dist/types/components/timeline.d.ts +35 -0
  90. package/dist/types/components/timeline.js +1 -0
  91. package/dist/types/localization.d.ts +2 -1
  92. package/dist/types/media.d.ts +4 -3
  93. package/dist/types/overrides.d.ts +48 -0
  94. package/dist/types/overrides.js +1 -0
  95. package/dist/types/variables.d.ts +13 -0
  96. package/dist/types/variables.js +10 -0
  97. package/dist/types.d.ts +17 -9
  98. package/dist/ui/atoms/typography.stories.svelte +1 -27
  99. package/dist/ui/molecules/button.stories.svelte +3 -8
  100. package/dist/ui/theme/colors.d.ts +0 -6
  101. package/dist/ui/theme/colors.js +1 -1
  102. package/dist/ui/theme/text.d.ts +3 -4
  103. package/dist/ui/theme/utils.d.ts +0 -10
  104. package/dist/ui/theme/utils.js +5 -5
  105. package/dist/utils/background-utils.d.ts +4 -0
  106. package/dist/utils/background-utils.js +39 -0
  107. package/dist/utils/base-utils.d.ts +18 -0
  108. package/dist/utils/base-utils.js +124 -0
  109. package/dist/utils/constants.d.ts +2 -2
  110. package/dist/utils/constants.js +6 -1
  111. package/dist/utils/font-utils.d.ts +4 -0
  112. package/dist/utils/font-utils.js +47 -0
  113. package/dist/utils/style-utils.d.ts +7 -120
  114. package/dist/utils/style-utils.js +22 -302
  115. package/dist/utils/variable-utils.d.ts +1 -22
  116. package/dist/utils/variable-utils.js +28 -24
  117. package/dist/web-components/index.css +1 -1
  118. package/dist/web-components/index.js +1323 -895
  119. package/package.json +34 -24
  120. package/dist/components/button/button-utils.d.ts +0 -2
  121. package/dist/components/button/button-utils.js +0 -19
  122. package/dist/components/image/image-utils.d.ts +0 -19
  123. package/dist/components/image/image-utils.js +0 -33
  124. package/dist/components/purchase-button/purchase-button-utils.d.ts +0 -2
  125. package/dist/components/purchase-button/purchase-button-utils.js +0 -20
  126. package/dist/stories/meta-templates.d.ts +0 -12
  127. package/dist/stories/meta-templates.js +0 -155
@@ -8,14 +8,7 @@
8
8
  const { Story } = defineMeta({
9
9
  component: Button,
10
10
  title: "Molecules/Button",
11
- // @ts-expect-error ignore typing of decorator
12
- decorators: [withLayout],
13
- argTypes: {
14
- intent: {
15
- control: "radio",
16
- options: ["primary", undefined],
17
- },
18
- },
11
+ decorators: [withLayout()],
19
12
  render: template,
20
13
  });
21
14
 
@@ -38,5 +31,7 @@
38
31
  {/snippet}
39
32
 
40
33
  <Story name="Default" {args} />
34
+
41
35
  <Story name="Disabled" args={{ ...args, disabled: true }} />
36
+
42
37
  <Story name="Loading" args={{ ...args, loading: true }} />
@@ -1,4 +1,3 @@
1
- import type { BrandingAppearance } from "../utils/branding";
2
1
  /**
3
2
  * All those colors get translated in --rc-color-<property_name> css variables.
4
3
  * i.e. --rc-color-error or --rc-color-input-background
@@ -22,11 +21,6 @@ export interface Colors {
22
21
  }
23
22
  export declare const DEFAULT_FORM_COLORS: Colors;
24
23
  export declare const DEFAULT_INFO_COLORS: Colors;
25
- /**
26
- * Mappings from the colors defined above and the colors downloaded from the BrandingAppearance.
27
- * Bear in mind that font colors are calculated dynamically given the resulting background color.
28
- */
29
- export declare const ColorsToBrandingAppearanceMapping: Record<string, keyof BrandingAppearance>;
30
24
  export declare const FormColorsToBrandingAppearanceMapping: {
31
25
  "input-background": string;
32
26
  background: string;
@@ -36,7 +36,7 @@ export const DEFAULT_INFO_COLORS = {
36
36
  * Mappings from the colors defined above and the colors downloaded from the BrandingAppearance.
37
37
  * Bear in mind that font colors are calculated dynamically given the resulting background color.
38
38
  */
39
- export const ColorsToBrandingAppearanceMapping = {
39
+ const ColorsToBrandingAppearanceMapping = {
40
40
  error: "color_error",
41
41
  focus: "color_accent",
42
42
  accent: "color_accent",
@@ -2,18 +2,17 @@
2
2
  * All text styles get translated into --rc-text-<property_name> CSS variables.
3
3
  * i.e., --rc-text-title1-font-size or --rc-text-title1-line-height
4
4
  */
5
- export interface TextStyle {
5
+ interface TextStyle {
6
6
  fontSize: string;
7
7
  lineHeight: string;
8
8
  fontWeight: string;
9
9
  letterSpacing?: string;
10
10
  }
11
- export type ScreenType = "mobile" | "desktop";
12
- export type ScreenTextStyle = Record<TextStyleKey, TextStyle>;
13
- export type TextStyleKey = "heading2xl" | "headingXl" | "headingLg" | "headingMd" | "bodyBase" | "bodySmall" | "labelButton" | "labelDefault" | "captionDefault" | "captionLink";
11
+ type TextStyleKey = "heading2xl" | "headingXl" | "headingLg" | "headingMd" | "bodyBase" | "bodySmall" | "labelButton" | "labelDefault" | "captionDefault" | "captionLink";
14
12
  export type TextStyles = Record<TextStyleKey, {
15
13
  mobile: TextStyle;
16
14
  desktop: TextStyle;
17
15
  }>;
18
16
  export declare const DEFAULT_FONT_FAMILY = "-apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif";
19
17
  export declare const DEFAULT_TEXT_STYLES: TextStyles;
18
+ export {};
@@ -3,18 +3,8 @@ import { type Colors } from "./colors";
3
3
  import { type Shape } from "./shapes";
4
4
  import type { Spacing } from "./spacing";
5
5
  import { type TextStyles } from "./text";
6
- export declare const DEFAULT_LUMINANCE_THRESHOLD = 0.37;
7
- /**
8
- * Applies an alpha value to a color.
9
- * If the base color is light, the overlay color is black.
10
- * If the base color is dark, the overlay color is white.
11
- */
12
- export declare function applyAlpha(baseColor: string, alpha: number): string;
13
- export declare const toColors: (colorsMapping: Record<string, string>, defaultColors: Colors, brandingAppearance?: BrandingAppearance | null | undefined) => Colors;
14
- export declare const toProductInfoColors: (brandingAppearance?: BrandingAppearance | null | undefined) => Colors;
15
6
  export declare const toFormColors: (brandingAppearance?: BrandingAppearance | null | undefined) => Colors;
16
7
  export declare const toShape: (brandingAppearance?: BrandingAppearance | null | undefined) => Shape;
17
- export declare const toStyleVar: (prefix: string | undefined, entries: [string, string][]) => string;
18
8
  /**
19
9
  * Assigns values to the css variables given the branding appearance customization.
20
10
  * @param appearance BrandingAppearance
@@ -31,7 +31,7 @@ const isLightColor = ({ r, g, b, luminanceThreshold, }) => {
31
31
  // Return whether the background is light
32
32
  return luminance > luminanceThreshold;
33
33
  };
34
- export const DEFAULT_LUMINANCE_THRESHOLD = 0.37;
34
+ const DEFAULT_LUMINANCE_THRESHOLD = 0.37;
35
35
  const rgbToTextColors = (rgb, luminanceThreshold = DEFAULT_LUMINANCE_THRESHOLD) => {
36
36
  const baseColor = isLightColor({ ...rgb, luminanceThreshold })
37
37
  ? "0,0,0"
@@ -56,7 +56,7 @@ function overlayColor(baseColor, overlay, alpha) {
56
56
  * If the base color is light, the overlay color is black.
57
57
  * If the base color is dark, the overlay color is white.
58
58
  */
59
- export function applyAlpha(baseColor, alpha) {
59
+ function applyAlpha(baseColor, alpha) {
60
60
  const defaultRgb = { r: 255, g: 255, b: 255 };
61
61
  const normalizedAlpha = Math.max(0, Math.min(1, alpha));
62
62
  let appliedBaseColor = baseColor;
@@ -119,7 +119,7 @@ const mapColors = (colorsMapping, defaultColors, brandingAppearance) => {
119
119
  ]);
120
120
  return Object.fromEntries(mappedColors);
121
121
  };
122
- export const toColors = (colorsMapping, defaultColors, brandingAppearance) => {
122
+ const toColors = (colorsMapping, defaultColors, brandingAppearance) => {
123
123
  const mappedColors = mapColors(colorsMapping, defaultColors, brandingAppearance);
124
124
  return brandingAppearance
125
125
  ? {
@@ -130,7 +130,7 @@ export const toColors = (colorsMapping, defaultColors, brandingAppearance) => {
130
130
  }
131
131
  : { ...defaultColors }; //copy, do not reference.
132
132
  };
133
- export const toProductInfoColors = (brandingAppearance) => {
133
+ const toProductInfoColors = (brandingAppearance) => {
134
134
  return toColors(InfoColorsToBrandingAppearanceMapping, DEFAULT_INFO_COLORS, brandingAppearance);
135
135
  };
136
136
  export const toFormColors = (brandingAppearance) => {
@@ -151,7 +151,7 @@ export const toShape = (brandingAppearance) => {
151
151
  return DefaultShape;
152
152
  }
153
153
  };
154
- export const toStyleVar = (prefix = "", entries) => entries.map(([key, value]) => `--rc-${prefix}-${key}: ${value}`).join("; ");
154
+ const toStyleVar = (prefix = "", entries) => entries.map(([key, value]) => `--rc-${prefix}-${key}: ${value}`).join("; ");
155
155
  /**
156
156
  * Assigns values to the css variables given the branding appearance customization.
157
157
  * @param appearance BrandingAppearance
@@ -0,0 +1,4 @@
1
+ import type { ColorMode } from "../types";
2
+ import type { Background } from "../types/background";
3
+ import type { ColorGradientScheme } from "../types/colors";
4
+ export declare function mapBackground(colorMode: ColorMode, background_color: ColorGradientScheme | null | undefined, background: Background | null | undefined): Record<string, string>;
@@ -0,0 +1,39 @@
1
+ import { mapColor, mapColorMode, mapFitMode, mapOverlay } from "./base-utils";
2
+ function mapBackgroundImage(colorMode, info) {
3
+ const files = mapColorMode(colorMode, info);
4
+ return `url(${files.webp})`;
5
+ }
6
+ function mapBackgroundVideo(colorMode, info) {
7
+ // TODO: [MON-662] Implement video background.
8
+ console.error("Not supported yet");
9
+ return `url(${mapColorMode(colorMode, info)})`;
10
+ }
11
+ function mapBackgroundValue(colorMode, background_color, background) {
12
+ if (background == null) {
13
+ if (background_color == null) {
14
+ return "none";
15
+ }
16
+ return mapColor(colorMode, background_color);
17
+ }
18
+ if (background.type === "color") {
19
+ return mapColor(colorMode, background_color ?? background.value);
20
+ }
21
+ if (background.type === "image") {
22
+ return mapBackgroundImage(colorMode, background.value);
23
+ }
24
+ return mapBackgroundVideo(colorMode, background.value);
25
+ }
26
+ export function mapBackground(colorMode, background_color, background) {
27
+ const value = mapBackgroundValue(colorMode, background_color, background);
28
+ if (background?.type !== "image") {
29
+ return { background: value };
30
+ }
31
+ const { fit_mode, color_overlay } = background;
32
+ return {
33
+ background: value,
34
+ "background-size": mapFitMode(fit_mode),
35
+ "background-position": fit_mode === "fill" ? "center" : "top center",
36
+ "background-repeat": "no-repeat",
37
+ "--overlay": mapOverlay(colorMode, color_overlay),
38
+ };
39
+ }
@@ -0,0 +1,18 @@
1
+ import type { BorderType, CircleShape, ColorMode, ConcaveShape, ConvexShape, PillShape, RectangleShape, ShadowType, Size, Spacing } from "../types";
2
+ import type { ColorGradientScheme, ColorScheme } from "../types/colors";
3
+ import type { FitMode } from "../types/media";
4
+ export type CSS = Record<string, string | number>;
5
+ export declare function css(props: CSS): string;
6
+ export declare function px(value: string | number): string;
7
+ export declare function mapColorMode<T>(colorMode: ColorMode, value: {
8
+ light: T;
9
+ dark?: T | null;
10
+ }): T;
11
+ export declare function mapSize(size: Size, deviceFrameElement?: HTMLElement | null): string;
12
+ export declare function mapSpacing(spacing?: Spacing | null): string;
13
+ export declare function mapColor(colorMode: ColorMode, scheme: ColorScheme | ColorGradientScheme | null | undefined): string;
14
+ export declare function mapOverlay(colorMode: ColorMode, colorOverlay: ColorGradientScheme | null | undefined): string;
15
+ export declare function mapBorder(colorMode: ColorMode, border: BorderType | null | undefined): string;
16
+ export declare function mapBorderRadius(shape: RectangleShape | CircleShape | PillShape | ConcaveShape | ConvexShape | null | undefined): string;
17
+ export declare function mapShadow(colorMode: ColorMode, shadow: ShadowType | null | undefined): string;
18
+ export declare function mapFitMode(fit_mode: FitMode): string;
@@ -0,0 +1,124 @@
1
+ import { DEFAULT_SPACING } from "./constants";
2
+ export function css(props) {
3
+ return Object.entries(props)
4
+ .map(([key, value]) => `${key}:${value}`)
5
+ .join(";");
6
+ }
7
+ export function px(value) {
8
+ return `${value}px`;
9
+ }
10
+ function mapTuple(...tuple) {
11
+ return tuple.map(px).join(" ");
12
+ }
13
+ export function mapColorMode(colorMode, value) {
14
+ const result = value[colorMode];
15
+ return result ?? value.light;
16
+ }
17
+ export function mapSize(size, deviceFrameElement) {
18
+ switch (size.type) {
19
+ case "fill":
20
+ // Support both webkit and mozilla browsers
21
+ if (navigator.userAgent.includes("Firefox")) {
22
+ return "-moz-available";
23
+ }
24
+ else {
25
+ return "-webkit-fill-available";
26
+ }
27
+ case "fit":
28
+ return "fit-content";
29
+ case "fixed":
30
+ return px(size.value);
31
+ case "relative": {
32
+ // TODO(marek): Good enough for now.
33
+ if (!deviceFrameElement) {
34
+ console.error("[mapSizeConstraint] Device frame element is not available");
35
+ return `${(size.value ?? 0) * 100}%`;
36
+ }
37
+ // getBoundingClientRect returns device pixel values that may be affected by CSS transforms
38
+ // due to phone preview scaling.
39
+ // We need to account for any scaling that may be applied to the element
40
+ const rect = deviceFrameElement.getBoundingClientRect();
41
+ const computedStyle = window.getComputedStyle(
42
+ // Need to go up two levels to get the transformed viewport element.
43
+ deviceFrameElement.parentNode?.parentNode);
44
+ const { transform } = computedStyle;
45
+ const scale = transform === "none" ? 1 : parseFloat(transform.split("(")[1]);
46
+ const height = rect.height / (scale || 1);
47
+ return px((size.value ?? 0) * height);
48
+ }
49
+ }
50
+ }
51
+ export function mapSpacing(spacing) {
52
+ const { top, bottom, leading, trailing } = spacing ?? DEFAULT_SPACING;
53
+ return mapTuple(top, trailing, bottom, leading);
54
+ }
55
+ function mapColorInfo(info) {
56
+ if (info.type === "alias" || info.type === "hex") {
57
+ return info.value;
58
+ }
59
+ const points = info.points
60
+ .map((point) => `${point.color} ${point.percent}%`)
61
+ .join(", ");
62
+ switch (info.type) {
63
+ case "linear":
64
+ return `linear-gradient(${info.degrees}deg, ${points})`;
65
+ case "radial":
66
+ return `radial-gradient(circle, ${points})`;
67
+ }
68
+ }
69
+ export function mapColor(colorMode, scheme) {
70
+ if (scheme == null) {
71
+ return "transparent";
72
+ }
73
+ const info = mapColorMode(colorMode, scheme);
74
+ return mapColorInfo(info);
75
+ }
76
+ export function mapOverlay(colorMode, colorOverlay) {
77
+ if (colorOverlay == null) {
78
+ return "transparent";
79
+ }
80
+ return mapColor(colorMode, colorOverlay);
81
+ }
82
+ export function mapBorder(colorMode, border) {
83
+ if (border == null) {
84
+ return "none";
85
+ }
86
+ const color = mapColor(colorMode, border.color);
87
+ return `${border.width}px solid ${color}`;
88
+ }
89
+ function mapCornerRadius(corners) {
90
+ if (corners == null) {
91
+ return "0";
92
+ }
93
+ const { top_leading, top_trailing, bottom_trailing, bottom_leading } = corners;
94
+ return mapTuple(top_leading, top_trailing, bottom_trailing, bottom_leading);
95
+ }
96
+ export function mapBorderRadius(shape) {
97
+ switch (shape?.type) {
98
+ case undefined:
99
+ case "concave":
100
+ case "convex":
101
+ return "0";
102
+ case "rectangle":
103
+ return `${mapCornerRadius(shape.corners)}`;
104
+ case "circle":
105
+ case "pill":
106
+ return "9999px";
107
+ }
108
+ }
109
+ export function mapShadow(colorMode, shadow) {
110
+ if (shadow == null) {
111
+ return "none";
112
+ }
113
+ const { x, y, radius } = shadow;
114
+ const color = mapColor(colorMode, shadow.color);
115
+ return `${x}px ${y}px ${radius}px ${color}`;
116
+ }
117
+ export function mapFitMode(fit_mode) {
118
+ switch (fit_mode) {
119
+ case "fill":
120
+ return "cover";
121
+ case "fit":
122
+ return "contain";
123
+ }
124
+ }
@@ -1,4 +1,4 @@
1
- import type { ColorMode } from "../types";
1
+ import type { ColorMode, Spacing } from "../types";
2
2
  export declare const DEFAULT_COLOR_MODE: ColorMode;
3
3
  export declare const DEFAULT_TEXT_COLOR = "#000000";
4
- export declare const DEFAULT_BACKGROUND_COLOR = "#FFFFFF";
4
+ export declare const DEFAULT_SPACING: Spacing;
@@ -1,3 +1,8 @@
1
1
  export const DEFAULT_COLOR_MODE = "light";
2
2
  export const DEFAULT_TEXT_COLOR = "#000000";
3
- export const DEFAULT_BACKGROUND_COLOR = "#FFFFFF";
3
+ export const DEFAULT_SPACING = {
4
+ top: 0,
5
+ bottom: 0,
6
+ leading: 0,
7
+ trailing: 0,
8
+ };
@@ -0,0 +1,4 @@
1
+ import type { UIConfig } from "../data/entities";
2
+ export declare function isFontRCFMManaged(fontName: string): boolean;
3
+ export declare function getScopedFontFamily(fontFamily: string): string;
4
+ export declare function registerFonts(uiConfig: UIConfig): Promise<void>;
@@ -0,0 +1,47 @@
1
+ export function isFontRCFMManaged(fontName) {
2
+ return fontName.startsWith("RCFM:");
3
+ }
4
+ export function getScopedFontFamily(fontFamily) {
5
+ return `RevCatPaywall-${fontFamily}`;
6
+ }
7
+ export async function registerFonts(uiConfig) {
8
+ if (!uiConfig.app.fonts || typeof document === "undefined") {
9
+ return;
10
+ }
11
+ const fontPromises = [];
12
+ for (const [fontId, fontConfig] of Object.entries(uiConfig.app.fonts)) {
13
+ const webConfig = fontConfig.web;
14
+ if (!webConfig || !webConfig.url || !webConfig.family) {
15
+ console.warn(`[Font Registration] Skipping font ${fontId}: missing web config or required fields`);
16
+ continue;
17
+ }
18
+ try {
19
+ const registration = `${getScopedFontFamily(webConfig.family)}-${webConfig.style}-${webConfig.weight}`;
20
+ const fontFace = new FontFace(registration, `url(${webConfig.url})`, {
21
+ weight: webConfig.weight?.toString() || "400",
22
+ style: webConfig.style || "normal",
23
+ });
24
+ fontFace.family = getScopedFontFamily(webConfig.family);
25
+ const loadPromise = fontFace
26
+ .load()
27
+ .then(() => {
28
+ document.fonts.add(fontFace);
29
+ console.debug(`[Font Registration] Successfully registered font: ${registration} (${webConfig.family}, ${webConfig.weight}, ${webConfig.style})`);
30
+ })
31
+ .catch((error) => {
32
+ console.warn(`[Font Registration] Failed to load font ${webConfig.family}:`, error);
33
+ });
34
+ fontPromises.push(loadPromise);
35
+ }
36
+ catch (error) {
37
+ console.warn(`[Font Registration] Failed to create FontFace for ${fontId}:`, error);
38
+ }
39
+ }
40
+ try {
41
+ await Promise.allSettled(fontPromises);
42
+ console.debug(`[Font Registration] Font registration complete. Processed ${fontPromises.length} fonts.`);
43
+ }
44
+ catch (error) {
45
+ console.warn("[Font Registration] Unexpected error during font registration:", error);
46
+ }
47
+ }
@@ -1,27 +1,9 @@
1
- import type { ComponentState, ImageMaskShapeType, ImageProps, PaywallData, TextNodeProps } from "../data/entities.js";
2
- import type { Dimension } from "../types/alignment.js";
3
- import type { ColorGradientScheme, ColorScheme } from "../types/colors.js";
4
- import { type BorderType, type ColorMode, type CornerRadiusType, FontSizeTags, type ShadowType, type ShapeType, type SizeType, type Spacing } from "../types.js";
5
- type MarginVariables = {
6
- "--margin-block-start": string;
7
- "--margin-inline-end": string;
8
- "--margin-block-end": string;
9
- "--margin-inline-start": string;
10
- };
11
- type PaddingVariables = {
12
- "--padding-block-start": string;
13
- "--padding-inline-end": string;
14
- "--padding-block-end": string;
15
- "--padding-inline-start": string;
16
- };
17
- type SpacingStyleVariables = MarginVariables | PaddingVariables;
18
- export type TextComponentTags = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
19
- /**
20
- * Maps font size to appropriate HTML heading tag
21
- * @param fontSize - Key from FontSizeTags enum
22
- * @returns Corresponding HTML heading tag
23
- */
24
- export declare function getTextComponentTag(fontSize: keyof typeof FontSizeTags): TextComponentTags;
1
+ import type { PaywallData } from "../data/entities.js";
2
+ import type { ColorGradientScheme } from "../types/colors.js";
3
+ import type { Component } from "../types/component.js";
4
+ import type { TextNodeProps } from "../types/components/text";
5
+ import type { Overrides } from "../types/overrides.js";
6
+ import { type ColorMode } from "../types.js";
25
7
  /**
26
8
  * Gets color value based on color mode with fallback
27
9
  * @param params - Object containing color map, mode and fallback color
@@ -32,76 +14,6 @@ export declare function getColor({ colorMap, colorMode, fallback, }: {
32
14
  colorMode?: ColorMode;
33
15
  fallback?: string;
34
16
  }): string;
35
- /**
36
- * Generates CSS border style string
37
- * @param border - Border configuration object
38
- * @param colorMode - Color mode (light/dark)
39
- * @returns CSS border style string
40
- */
41
- export declare function getBorderStyle(border?: BorderType, colorMode?: ColorMode): string;
42
- type CornerRadiusStyleVariables = {
43
- "--border-start-start-radius": string;
44
- "--border-start-end-radius": string;
45
- "--border-end-start-radius": string;
46
- "--border-end-end-radius": string;
47
- };
48
- /**
49
- * Generates CSS border radius style for corners
50
- * @param corners - Corner radius configuration
51
- * @returns CSS border radius string
52
- */
53
- export declare function getCornerRadiusStyle(corners: CornerRadiusType): CornerRadiusStyleVariables;
54
- type ComponentStyleVariables = {
55
- "--background": string;
56
- "--text-color": string;
57
- "--border": string;
58
- "--shadow": string;
59
- } & CornerRadiusStyleVariables & SpacingStyleVariables;
60
- /**
61
- * Generates comprehensive component styles including spacing, colors, borders and shadows
62
- * @param params - Component style configuration object
63
- * @returns CSS style object with component styles
64
- */
65
- export declare function getComponentStyles({ background_color, border, margin, padding, color, colorMode, shape, shadow, }: {
66
- padding?: Spacing;
67
- margin?: Spacing;
68
- background_color?: ColorGradientScheme | null;
69
- color?: ColorScheme;
70
- border?: BorderType | null;
71
- colorMode?: ColorMode;
72
- shape?: ShapeType | null;
73
- shadow?: ShadowType | null;
74
- }): ComponentStyleVariables;
75
- type SizeStyleVariables = {
76
- "--width": string;
77
- "--height": string;
78
- "--flex": string;
79
- };
80
- /**
81
- * Generates size-related CSS styles for components
82
- * @param size - Size configuration object
83
- * @returns CSS style object with size properties
84
- */
85
- export declare function getSizeStyle(size: SizeType): SizeStyleVariables;
86
- type InsetStyleVariables = {
87
- "--inset": string;
88
- "--transform": string;
89
- };
90
- export declare function getInsetStyles(dimension: Dimension): InsetStyleVariables;
91
- type DimensionVariableType = {
92
- "--direction": string;
93
- "--alignment": string;
94
- "--distribution": string;
95
- "--position": string;
96
- "--inset": string;
97
- "--transform": string;
98
- };
99
- /**
100
- * Generates dimension-related styles for stack components
101
- * @param dimension - Dimension configuration object
102
- * @returns CSS style object with flex layout properties
103
- */
104
- export declare function getDimensionStyle(dimension: Dimension): DimensionVariableType;
105
17
  type TextStyleVariables = {
106
18
  "--text-align": string;
107
19
  "--font-weight": number | string;
@@ -130,31 +42,6 @@ export declare function stringifyStyles(styles: Record<string, string | number>)
130
42
  * @returns the id of the first package marked as `is_selected_by_default` or undefined
131
43
  */
132
44
  export declare function findSelectedPackageId(paywallData: PaywallData): string | undefined;
133
- export declare const getActiveStateProps: <T>(overrides?: {
134
- states?: Record<string, T>;
135
- }, componentState?: ComponentState) => T;
45
+ export declare const getActiveStateProps: <T extends Component>(selectedState: boolean, overrides?: Overrides<T>) => Partial<T>;
136
46
  export declare function prefixObject(object?: Record<string, string | number>, prefix?: string): Record<string, string | number>;
137
- export declare function getMaskPath(props: ImageProps & {
138
- imageAspectRatio: number;
139
- }): string;
140
- type MaskStyleVariables = {
141
- "--border-start-start-radius": string;
142
- "--border-start-end-radius": string;
143
- "--border-end-start-radius": string;
144
- "--border-end-end-radius": string;
145
- };
146
- /**
147
- * Generates mask styles for images
148
- * @param maskShape - Shape configuration for image mask
149
- * @returns CSS style object with mask properties
150
- */
151
- export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => MaskStyleVariables;
152
- export declare function getLinearGradientAngle(colorMode: ColorMode, props: ImageProps & {
153
- imageAspectRatio: number;
154
- }): {
155
- x1: string;
156
- y1: string;
157
- x2: string;
158
- y2: string;
159
- };
160
47
  export {};