@revenuecat/purchases-ui-js 0.0.16 → 0.0.18

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 (67) hide show
  1. package/dist/components/button/Button.svelte +0 -13
  2. package/dist/components/button/Button.svelte.d.ts +4 -2
  3. package/dist/components/button/ButtonNode.stories.svelte +16 -11
  4. package/dist/components/button/ButtonNode.svelte +26 -1
  5. package/dist/components/button/ButtonNode.svelte.d.ts +1 -0
  6. package/dist/components/button/button-utils.d.ts +2 -0
  7. package/dist/components/button/button-utils.js +19 -0
  8. package/dist/components/footer/Footer.stories.svelte +47 -155
  9. package/dist/components/footer/Footer.stories.svelte.d.ts +1 -2
  10. package/dist/components/footer/Footer.svelte +10 -1
  11. package/dist/components/footer/Footer.svelte.d.ts +1 -0
  12. package/dist/components/image/Image.stories.svelte +13 -7
  13. package/dist/components/image/Image.svelte +37 -19
  14. package/dist/components/image/Image.svelte.d.ts +1 -0
  15. package/dist/components/image/image-utils.d.ts +2 -12
  16. package/dist/components/image/image-utils.js +28 -11
  17. package/dist/components/package/Package.stories.svelte +5 -5
  18. package/dist/components/package/Package.svelte +15 -6
  19. package/dist/components/package/Package.svelte.d.ts +1 -0
  20. package/dist/components/paywall/Node.svelte +77 -17
  21. package/dist/components/paywall/Node.svelte.d.ts +21 -2
  22. package/dist/components/paywall/Paywall.stories.svelte +93 -15
  23. package/dist/components/paywall/Paywall.svelte +110 -88
  24. package/dist/components/paywall/Paywall.svelte.d.ts +4 -0
  25. package/dist/components/paywall/paywall-utils.d.ts +1 -1
  26. package/dist/components/paywall/paywall-utils.js +11 -9
  27. package/dist/components/purchase-button/PurchaseButton.stories.svelte +7 -8
  28. package/dist/components/purchase-button/PurchaseButton.svelte +24 -10
  29. package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -0
  30. package/dist/components/purchase-button/purchase-button-utils.d.ts +2 -0
  31. package/dist/components/purchase-button/purchase-button-utils.js +20 -0
  32. package/dist/components/stack/Stack.stories.svelte +1138 -6
  33. package/dist/components/stack/Stack.svelte +160 -42
  34. package/dist/components/stack/Stack.svelte.d.ts +1 -0
  35. package/dist/components/stack/stack-utils.d.ts +24 -24
  36. package/dist/components/stack/stack-utils.js +245 -12
  37. package/dist/components/text/Text.svelte +24 -19
  38. package/dist/components/text/Text.svelte.d.ts +4 -2
  39. package/dist/components/text/TextNode.stories.svelte +13 -13
  40. package/dist/components/text/TextNode.svelte +24 -34
  41. package/dist/components/text/TextNode.svelte.d.ts +1 -0
  42. package/dist/components/text/text-utils.d.ts +11 -14
  43. package/dist/components/text/text-utils.js +130 -15
  44. package/dist/components/timeline/Timeline.stories.svelte +640 -0
  45. package/dist/components/timeline/Timeline.stories.svelte.d.ts +19 -0
  46. package/dist/components/timeline/Timeline.svelte +40 -0
  47. package/dist/components/timeline/Timeline.svelte.d.ts +4 -0
  48. package/dist/components/timeline/TimelineItem.svelte +112 -0
  49. package/dist/components/timeline/TimelineItem.svelte.d.ts +4 -0
  50. package/dist/components/timeline/timeline-utils.d.ts +8 -0
  51. package/dist/components/timeline/timeline-utils.js +128 -0
  52. package/dist/data/entities.d.ts +89 -9
  53. package/dist/data/state.d.ts +2 -0
  54. package/dist/index.d.ts +3 -2
  55. package/dist/index.js +3 -2
  56. package/dist/stories/fixtures.d.ts +7 -1
  57. package/dist/stories/fixtures.js +6898 -7
  58. package/dist/stories/meta-templates.d.ts +0 -1
  59. package/dist/stories/meta-templates.js +0 -5
  60. package/dist/types.d.ts +16 -7
  61. package/dist/types.js +7 -0
  62. package/dist/utils/style-utils.d.ts +80 -41
  63. package/dist/utils/style-utils.js +157 -70
  64. package/dist/utils/variable-utils.d.ts +27 -0
  65. package/dist/utils/variable-utils.js +37 -0
  66. package/package.json +27 -25
  67. package/dist/components/paywall/global-styles.css +0 -9
@@ -7,7 +7,6 @@ export declare const fontWeightStoryMeta: InputType;
7
7
  export declare const fontSizeStoryMeta: InputType;
8
8
  export declare const textStyleStoryMeta: InputType;
9
9
  export declare const horizontalAlignmentStoryMeta: InputType;
10
- export declare const colorModeStoryMeta: InputType;
11
10
  export declare const shadowStoryMeta: InputType;
12
11
  export declare const borderStoryMeta: InputType;
13
12
  export declare const sizeStoryMeta: InputType;
@@ -85,11 +85,6 @@ export const horizontalAlignmentStoryMeta = {
85
85
  options: ["center", "start", "end"],
86
86
  description: "Text horizontal alignment",
87
87
  };
88
- export const colorModeStoryMeta = {
89
- control: { type: "select" },
90
- options: ["light", "dark"],
91
- description: "Color mode",
92
- };
93
88
  export const shadowStoryMeta = {
94
89
  control: {
95
90
  type: "object",
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ export type ColorStop = {
3
3
  color: string;
4
4
  percent: number;
5
5
  };
6
- type Color = {
6
+ export type Color = {
7
7
  type: "hex" | "alias" | "linear" | "radial";
8
8
  value?: string;
9
9
  degrees?: number;
@@ -48,7 +48,11 @@ export declare enum FontSizes {
48
48
  heading_xl = "26px",
49
49
  heading_xxl = "32px"
50
50
  }
51
- export type TextAlignment = "center" | "start" | "end";
51
+ export declare enum TextAlignments {
52
+ leading = "start",
53
+ center = "center",
54
+ trailing = "end"
55
+ }
52
56
  export type SizeType = {
53
57
  width: Size;
54
58
  height: Size;
@@ -63,10 +67,13 @@ type RelativeSize = {
63
67
  type: FitTypes;
64
68
  };
65
69
  export type ShapeType = RectangleShape | PillShape;
66
- type RectangleShape = {
70
+ export type RectangleShape = {
67
71
  type: "rectangle";
68
72
  corners: CornerRadiusType;
69
73
  };
74
+ export type CircleShape = {
75
+ type: "circle";
76
+ };
70
77
  type PillShape = {
71
78
  type: "pill";
72
79
  };
@@ -97,10 +104,11 @@ type HorizontalAlignment = {
97
104
  alignment: "leading" | "center" | "trailing";
98
105
  distribution?: Distribution;
99
106
  };
100
- type ZAlignment = {
107
+ export type AlignmentType = "top_leading" | "top" | "top_trailing" | "leading" | "center" | "trailing" | "bottom_leading" | "bottom" | "bottom_trailing";
108
+ export type ZAlignment = {
101
109
  type: "zlayer";
102
- alignment: "top_leading" | "top" | "top_trailing" | "leading" | "center" | "trailing" | "bottom_leading" | "bottom" | "bottom_trailing";
103
- distribution: never;
110
+ alignment: AlignmentType;
111
+ distribution?: never;
104
112
  };
105
113
  type Distribution = "space_between" | "space_around" | "space_evenly" | "start" | "center" | "end";
106
114
  export type ShadowType = {
@@ -111,7 +119,8 @@ export type ShadowType = {
111
119
  };
112
120
  export declare enum StackDirection {
113
121
  vertical = "column",
114
- horizontal = "row"
122
+ horizontal = "row",
123
+ zlayer = "zstack"
115
124
  }
116
125
  export declare enum StackAlignment {
117
126
  top = "flex-start",
package/dist/types.js CHANGED
@@ -37,10 +37,17 @@ export var FontSizes;
37
37
  FontSizes["heading_xl"] = "26px";
38
38
  FontSizes["heading_xxl"] = "32px";
39
39
  })(FontSizes || (FontSizes = {}));
40
+ export var TextAlignments;
41
+ (function (TextAlignments) {
42
+ TextAlignments["leading"] = "start";
43
+ TextAlignments["center"] = "center";
44
+ TextAlignments["trailing"] = "end";
45
+ })(TextAlignments || (TextAlignments = {}));
40
46
  export var StackDirection;
41
47
  (function (StackDirection) {
42
48
  StackDirection["vertical"] = "column";
43
49
  StackDirection["horizontal"] = "row";
50
+ StackDirection["zlayer"] = "zstack";
44
51
  })(StackDirection || (StackDirection = {}));
45
52
  export var StackAlignment;
46
53
  (function (StackAlignment) {
@@ -1,5 +1,18 @@
1
- import type { ComponentLocalizations, ComponentState, 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";
1
+ import type { ComponentState, ImageMaskShapeType, PaywallData, TextNodeProps } from "../data/entities.js";
2
+ import { type BorderType, type ColorMode, type ColorType, type CornerRadiusType, type DimensionType, FontSizeTags, type ShadowType, type ShapeType, type SizeType, type Spacing } from "../types.js";
3
+ type MarginVariables = {
4
+ "--margin-block-start": string;
5
+ "--margin-inline-end": string;
6
+ "--margin-block-end": string;
7
+ "--margin-inline-start": string;
8
+ };
9
+ type PaddingVariables = {
10
+ "--padding-block-start": string;
11
+ "--padding-inline-end": string;
12
+ "--padding-block-end": string;
13
+ "--padding-inline-start": string;
14
+ };
15
+ type SpacingStyleVariables = MarginVariables | PaddingVariables;
3
16
  export type TextComponentTags = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
4
17
  /**
5
18
  * Maps font size to appropriate HTML heading tag
@@ -17,6 +30,31 @@ export declare function getColor({ colorMap, colorMode, fallback, }: {
17
30
  colorMode?: ColorMode;
18
31
  fallback?: string;
19
32
  }): string;
33
+ /**
34
+ * Generates CSS border style string
35
+ * @param border - Border configuration object
36
+ * @param colorMode - Color mode (light/dark)
37
+ * @returns CSS border style string
38
+ */
39
+ export declare function getBorderStyle(border?: BorderType, colorMode?: ColorMode): string;
40
+ type CornerRadiusStyleVariables = {
41
+ "--border-start-start-radius": string;
42
+ "--border-start-end-radius": string;
43
+ "--border-end-start-radius": string;
44
+ "--border-end-end-radius": string;
45
+ };
46
+ /**
47
+ * Generates CSS border radius style for corners
48
+ * @param corners - Corner radius configuration
49
+ * @returns CSS border radius string
50
+ */
51
+ export declare function getCornerRadiusStyle(corners: CornerRadiusType): CornerRadiusStyleVariables;
52
+ type ComponentStyleVariables = {
53
+ "--background": string;
54
+ "--text-color": string;
55
+ "--border": string;
56
+ "--shadow": string;
57
+ } & CornerRadiusStyleVariables & SpacingStyleVariables;
20
58
  /**
21
59
  * Generates comprehensive component styles including spacing, colors, borders and shadows
22
60
  * @param params - Component style configuration object
@@ -31,30 +69,20 @@ export declare function getComponentStyles({ backgroundColor, border, margin, pa
31
69
  colorMode?: ColorMode;
32
70
  shape?: ShapeType;
33
71
  shadow?: ShadowType;
34
- }): {
35
- "--margin-block-start": string;
36
- "--margin-inline-end": string;
37
- "--margin-block-end": string;
38
- "--margin-inline-start": string;
39
- "--padding-block-start": string;
40
- "--padding-inline-end": string;
41
- "--padding-block-end": string;
42
- "--padding-inline-start": string;
43
- "--background": string;
44
- "--text-color": string;
45
- "--border": string;
46
- "--border-radius": string;
47
- "--shadow": string;
72
+ }): ComponentStyleVariables;
73
+ type SizeStyleVariables = {
74
+ "--width": string;
75
+ "--height": string;
76
+ "--flex": string;
48
77
  };
49
78
  /**
50
79
  * Generates size-related CSS styles for components
51
80
  * @param size - Size configuration object
52
81
  * @returns CSS style object with size properties
53
82
  */
54
- export declare function getSizeStyle(size: SizeType): {
55
- "--width": string;
56
- "--height": string;
57
- "--flex": string;
83
+ export declare function getSizeStyle(size: SizeType): SizeStyleVariables;
84
+ type GradientStyleVariables = {
85
+ "--background": string;
58
86
  };
59
87
  /**
60
88
  * Generates gradient background styles
@@ -62,27 +90,47 @@ export declare function getSizeStyle(size: SizeType): {
62
90
  * @param gradientColors - Array of colors for gradient
63
91
  * @returns CSS style object with gradient background
64
92
  */
65
- export declare function getGradientStyle(colorMode: ColorMode, gradientColors?: ColorType[]): {
66
- "--background": string;
93
+ export declare function getGradientStyle(colorMode: ColorMode, gradientColors?: ColorType[]): GradientStyleVariables;
94
+ type MaskStyleVariables = {
95
+ "--border-start-start-radius": string;
96
+ "--border-start-end-radius": string;
97
+ "--border-end-start-radius": string;
98
+ "--border-end-end-radius": string;
99
+ "--clip-path": string;
67
100
  };
68
101
  /**
69
102
  * Generates mask styles for images
70
103
  * @param maskShape - Shape configuration for image mask
71
104
  * @returns CSS style object with mask properties
72
105
  */
73
- export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => {
74
- "--corner-radius": string;
75
- "--clip-path": string;
106
+ export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => MaskStyleVariables;
107
+ type InsetStyleVariables = {
108
+ "--inset": string;
109
+ "--transform": string;
110
+ };
111
+ export declare function getInsetStyles(dimension: DimensionType): InsetStyleVariables;
112
+ type DimensionVariableType = {
113
+ "--direction": string;
114
+ "--alignment": string;
115
+ "--distribution": string;
116
+ "--position": string;
117
+ "--inset": string;
118
+ "--transform": string;
76
119
  };
77
120
  /**
78
121
  * Generates dimension-related styles for stack components
79
122
  * @param dimension - Dimension configuration object
80
123
  * @returns CSS style object with flex layout properties
81
124
  */
82
- export declare function getDimensionStyle(dimension: DimensionType): {
83
- "--direction": string;
84
- "--alignment": string;
85
- "--distribution": string;
125
+ export declare function getDimensionStyle(dimension: DimensionType): DimensionVariableType;
126
+ type TextStyleVariables = {
127
+ "--text-align": string;
128
+ "--font-weight": number | string;
129
+ "--font-size": string;
130
+ "--font-family": string;
131
+ "--background-clip": string;
132
+ "--text-fill-color": string;
133
+ "--background": string;
86
134
  };
87
135
  /**
88
136
  * Generates text-related styles
@@ -90,24 +138,13 @@ export declare function getDimensionStyle(dimension: DimensionType): {
90
138
  * @param colorMode - The currently selected ColorMode (dark/light)
91
139
  * @returns CSS style object with text formatting properties
92
140
  */
93
- export declare function getTextStyles(props: TextNodeProps, colorMode?: ColorMode): Record<string, unknown>;
141
+ export declare function getTextStyles(props: TextNodeProps, colorMode?: ColorMode): TextStyleVariables;
94
142
  /**
95
143
  * Converts a style object to a CSS string
96
144
  * @param styles - Object containing CSS properties and values
97
145
  * @returns CSS string
98
146
  */
99
147
  export declare function stringifyStyles(styles: Record<string, string | number>): string;
100
- /**
101
- * Given a ComponentLocalizations object and a locale returns the label with label_id in the chosen locale, if any. Falls
102
- * back to the label with the same label_id in the fallbackLocale, if any. Finally returns undefined if no label can be
103
- * found for the requested label_id.
104
- * @param label_id - The id of the label to be returned
105
- * @param locale - The preferred locale to return the label
106
- * @param fallbackLocale - The locale to fall back to in case no label is found in the preferred one
107
- * @param labels - A ComponentLocalizations instance
108
- * @returns The label in the preferred or fallback locale, or undefined.
109
- */
110
- export declare function getLabelById(label_id: string, locale: string, fallbackLocale: string, labels: ComponentLocalizations): string | undefined;
111
148
  /**
112
149
  * Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
113
150
  * @param paywallData
@@ -115,3 +152,5 @@ export declare function getLabelById(label_id: string, locale: string, fallbackL
115
152
  */
116
153
  export declare function findSelectedPackageId(paywallData: PaywallData): string | undefined;
117
154
  export declare const getActiveStateProps: <T>(overrides?: Record<string, T>, componentState?: ComponentState) => T;
155
+ export declare function prefixObject(object?: Record<string, string | number>, prefix?: string): Record<string, string | number>;
156
+ export {};
@@ -1,4 +1,4 @@
1
- import { FontSizes, FontSizeTags, FontWeights, StackAlignment, StackDirection, StackDistribution, } from "../types.js";
1
+ import { FontSizes, FontSizeTags, FontWeights, StackAlignment, StackDirection, StackDistribution, TextAlignments, } 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
@@ -6,14 +6,21 @@ import { FontSizes, FontSizeTags, FontWeights, StackAlignment, StackDirection, S
6
6
  * @returns CSS style object with logical properties for spacing
7
7
  */
8
8
  function getSpacingStyle(spacing, spacingKey) {
9
+ const styles = {
10
+ [`--${spacingKey}-block-start`]: "0px",
11
+ [`--${spacingKey}-inline-end`]: "0px",
12
+ [`--${spacingKey}-block-end`]: "0px",
13
+ [`--${spacingKey}-inline-start`]: "0px",
14
+ };
9
15
  if (!spacing || !spacingKey)
10
- return "";
11
- return {
16
+ return styles;
17
+ Object.assign(styles, {
12
18
  [`--${spacingKey}-block-start`]: `${spacing.top ?? 0}px`,
13
19
  [`--${spacingKey}-inline-end`]: `${spacing.trailing ?? 0}px`,
14
20
  [`--${spacingKey}-block-end`]: `${spacing.bottom ?? 0}px`,
15
21
  [`--${spacingKey}-inline-start`]: `${spacing.leading ?? 0}px`,
16
- };
22
+ });
23
+ return styles;
17
24
  }
18
25
  /**
19
26
  * Maps font size to appropriate HTML heading tag
@@ -47,8 +54,9 @@ export function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }
47
54
  .map((point) => `${point.color} ${point.percent}%`)
48
55
  .join(", ");
49
56
  return `radial-gradient(${colorPoints})`;
57
+ default:
58
+ return fallback;
50
59
  }
51
- return fallback;
52
60
  }
53
61
  /**
54
62
  * Generates CSS border style string
@@ -56,7 +64,9 @@ export function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }
56
64
  * @param colorMode - Color mode (light/dark)
57
65
  * @returns CSS border style string
58
66
  */
59
- function getBorderStyle(border, colorMode = "light") {
67
+ export function getBorderStyle(border, colorMode = "light") {
68
+ if (!border)
69
+ return "";
60
70
  const color = getColor({ colorMap: border.color, colorMode });
61
71
  return `${border.width}px solid ${color}`;
62
72
  }
@@ -65,8 +75,13 @@ function getBorderStyle(border, colorMode = "light") {
65
75
  * @param corners - Corner radius configuration
66
76
  * @returns CSS border radius string
67
77
  */
68
- function getCornerRadiusStyle(corners) {
69
- return `${corners.top_leading}px ${corners.top_trailing}px ${corners.bottom_trailing}px ${corners.bottom_leading}px`;
78
+ export function getCornerRadiusStyle(corners) {
79
+ return {
80
+ "--border-start-start-radius": `${corners.top_leading}px`,
81
+ "--border-start-end-radius": `${corners.top_trailing}px`,
82
+ "--border-end-start-radius": `${corners.bottom_leading}px`,
83
+ "--border-end-end-radius": `${corners.bottom_trailing}px`,
84
+ };
70
85
  }
71
86
  /**
72
87
  * Generates comprehensive component styles including spacing, colors, borders and shadows
@@ -83,10 +98,13 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
83
98
  "--padding-inline-end": "0px",
84
99
  "--padding-block-end": "0px",
85
100
  "--padding-inline-start": "0px",
86
- "--background": "transparent",
87
- "--text-color": "#000000",
101
+ "--background": "initial",
102
+ "--text-color": "initial",
88
103
  "--border": "none",
89
- "--border-radius": "0px",
104
+ "--border-end-start-radius": "0px",
105
+ "--border-end-end-radius": "0px",
106
+ "--border-start-start-radius": "0px",
107
+ "--border-start-end-radius": "0px",
90
108
  "--shadow": "none",
91
109
  };
92
110
  if (padding) {
@@ -113,10 +131,15 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
113
131
  stylesObject["--border"] = getBorderStyle(border, colorMode);
114
132
  }
115
133
  if (shape?.type === "rectangle" && shape.corners) {
116
- stylesObject["--border-radius"] = getCornerRadiusStyle(shape.corners);
134
+ Object.assign(stylesObject, getCornerRadiusStyle(shape.corners));
117
135
  }
118
136
  if (shape?.type === "pill") {
119
- stylesObject["--border-radius"] = "9999px";
137
+ Object.assign(stylesObject, getCornerRadiusStyle({
138
+ bottom_leading: 9999,
139
+ bottom_trailing: 9999,
140
+ top_leading: 9999,
141
+ top_trailing: 9999,
142
+ }));
120
143
  }
121
144
  if (shadow) {
122
145
  stylesObject["--shadow"] = `${shadow.x}px ${shadow.y}px ${shadow.radius}px
@@ -124,34 +147,40 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
124
147
  }
125
148
  return stylesObject;
126
149
  }
150
+ function getSizeValue(size) {
151
+ if (size.type === "fixed") {
152
+ return `${size.value}px`;
153
+ }
154
+ if (size.type === "fit") {
155
+ return "fit-content";
156
+ }
157
+ if (size.type === "fill") {
158
+ const userAgent = navigator.userAgent;
159
+ const isFirefox = userAgent.match(/firefox|fxios/i);
160
+ return isFirefox ? "-moz-available" : "-webkit-fill-available";
161
+ }
162
+ return "initial";
163
+ }
127
164
  /**
128
165
  * Generates size-related CSS styles for components
129
166
  * @param size - Size configuration object
130
167
  * @returns CSS style object with size properties
131
168
  */
132
169
  export function getSizeStyle(size) {
133
- function getSizeValue(size) {
134
- if (size.type === "fixed") {
135
- return `${size.value}px`;
136
- }
137
- if (size.type === "fit") {
138
- return "fit-content";
139
- }
140
- if (size.type === "fill") {
141
- const userAgent = navigator.userAgent;
142
- const isFirefox = userAgent.match(/firefox|fxios/i);
143
- return isFirefox ? "-moz-available" : "-webkit-fill-available";
144
- }
145
- return "unset";
146
- }
170
+ const styles = {
171
+ "--width": "initial",
172
+ "--height": "initial",
173
+ "--flex": "initial",
174
+ };
147
175
  const width = getSizeValue(size.width);
148
176
  const height = getSizeValue(size.height);
149
177
  const isGrow = size.width.type === "fill" || size.height.type === "fill";
150
- return {
178
+ Object.assign(styles, {
151
179
  "--width": width,
152
180
  "--height": height,
153
- "--flex": isGrow ? "unset" : "0 1 auto",
154
- };
181
+ "--flex": isGrow ? "initial" : "0 1 auto",
182
+ });
183
+ return styles;
155
184
  }
156
185
  /**
157
186
  * Generates gradient background styles
@@ -173,25 +202,80 @@ export function getGradientStyle(colorMode, gradientColors) {
173
202
  */
174
203
  export const getMaskStyle = (maskShape) => {
175
204
  const maskStyles = {
176
- "--corner-radius": "0px",
205
+ "--border-end-start-radius": "0px",
206
+ "--border-end-end-radius": "0px",
207
+ "--border-start-start-radius": "0px",
208
+ "--border-start-end-radius": "0px",
177
209
  "--clip-path": "none",
178
210
  };
179
211
  if (maskShape?.type === "circle") {
180
- maskStyles["--corner-radius"] = "50%";
212
+ Object.assign(maskStyles, {
213
+ "--border-end-start-radius": "50%",
214
+ "--border-end-end-radius": "50%",
215
+ "--border-start-start-radius": "50%",
216
+ "--border-start-end-radius": "50%",
217
+ });
181
218
  }
182
219
  if (maskShape?.type === "rectangle" && maskShape.corners) {
183
- maskStyles["--corner-radius"] = getCornerRadiusStyle(maskShape.corners);
220
+ Object.assign(maskStyles, getCornerRadiusStyle(maskShape.corners));
184
221
  }
185
222
  // TODO: rework this implementation
186
223
  if (maskShape?.type === "convex") {
187
- maskStyles["--corner-radius"] = "0 0 50% 50%;";
224
+ Object.assign(maskStyles, {
225
+ "--border-start-start-radius": "0%",
226
+ "--border-start-end-radius": "0%",
227
+ "--border-end-start-radius": "50%",
228
+ "--border-end-end-radius": "50%",
229
+ });
188
230
  }
189
231
  if (maskShape?.type === "concave") {
190
- maskStyles["--clip-path"] =
191
- "polygon(0 0, 100% 0, 100% 100%, 50% 110%, 0 100%);";
232
+ Object.assign(maskStyles, {
233
+ "--clip-path": "polygon(0 0, 100% 0, 100% 100%, 50% 110%, 0 100%);",
234
+ });
192
235
  }
193
236
  return maskStyles;
194
237
  };
238
+ export function getInsetStyles(dimension) {
239
+ const defaultStyles = {
240
+ "--inset": "initial",
241
+ "--transform": "initial",
242
+ };
243
+ switch (dimension.alignment) {
244
+ case "top_leading":
245
+ defaultStyles["--inset"] = "0 auto auto 0";
246
+ break;
247
+ case "top":
248
+ defaultStyles["--inset"] = "auto auto auto 50%";
249
+ defaultStyles["--transform"] = "translate(-50%, 0)";
250
+ break;
251
+ case "top_trailing":
252
+ defaultStyles["--inset"] = "0 0 auto auto";
253
+ break;
254
+ case "leading":
255
+ defaultStyles["--inset"] = "50% 0 50% 0";
256
+ defaultStyles["--transform"] = "translate(0, -50%)";
257
+ break;
258
+ case "center":
259
+ defaultStyles["--inset"] = "50% auto auto 50%";
260
+ defaultStyles["--transform"] = "translate(-50%, -50%)";
261
+ break;
262
+ case "trailing":
263
+ defaultStyles["--inset"] = "50% 0 50% auto";
264
+ defaultStyles["--transform"] = "translate(0, -50%)";
265
+ break;
266
+ case "bottom_leading":
267
+ defaultStyles["--inset"] = "auto auto 0 0";
268
+ break;
269
+ case "bottom":
270
+ defaultStyles["--inset"] = "auto 50% 0 auto";
271
+ defaultStyles["--transform"] = "translate(50%, 0)";
272
+ break;
273
+ case "bottom_trailing":
274
+ defaultStyles["--inset"] = "auto 0 0 auto";
275
+ break;
276
+ }
277
+ return defaultStyles;
278
+ }
195
279
  /**
196
280
  * Generates dimension-related styles for stack components
197
281
  * @param dimension - Dimension configuration object
@@ -202,15 +286,19 @@ export function getDimensionStyle(dimension) {
202
286
  "--direction": "initial",
203
287
  "--alignment": "initial",
204
288
  "--distribution": "initial",
289
+ "--position": "relative",
290
+ "--inset": "initial",
291
+ "--transform": "initial",
205
292
  };
206
- if (dimension.type === "zlayer") {
207
- // TODO: Review with Monetization team
208
- }
209
- else {
210
- styles["--direction"] = StackDirection[dimension.type];
211
- styles["--alignment"] = StackAlignment[dimension.alignment];
293
+ if (dimension.type !== "zlayer") {
294
+ Object.assign(styles, {
295
+ "--direction": StackDirection[dimension.type],
296
+ "--alignment": StackAlignment[dimension.alignment],
297
+ });
212
298
  if (dimension.distribution) {
213
- styles["--distribution"] = StackDistribution[dimension.distribution];
299
+ Object.assign(styles, {
300
+ "--distribution": StackDistribution[dimension.distribution],
301
+ });
214
302
  }
215
303
  }
216
304
  return styles;
@@ -225,21 +313,26 @@ export function getTextStyles(props, colorMode = "light") {
225
313
  const { font_size, horizontal_alignment, font_weight, font_name, color } = props;
226
314
  const styles = {
227
315
  "--text-align": "initial",
228
- "--font-weight": 400,
316
+ "--font-weight": "initial",
229
317
  "--font-size": "initial",
230
318
  "--font-family": "sans-serif",
231
- "--background-clip": "initial",
232
- "--text-fill-color": "initial",
319
+ "--background-clip": "none",
320
+ "--text-fill-color": "none",
321
+ "--background": "unset",
233
322
  };
234
- styles["--text-align"] = horizontal_alignment;
235
- styles["--font-weight"] = FontWeights[font_weight] || FontWeights.regular;
236
- styles["--font-size"] = FontSizes[font_size] || FontSizes.body_m;
237
- styles["--font-family"] = font_name || "sans-serif";
323
+ Object.assign(styles, {
324
+ "--text-align": TextAlignments[horizontal_alignment] || TextAlignments.leading,
325
+ "--font-weight": FontWeights[font_weight] || FontWeights.regular,
326
+ "--font-size": FontSizes[font_size] || FontSizes.body_m,
327
+ "--font-family": font_name || "sans-serif",
328
+ });
238
329
  if (color &&
239
330
  (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 });
331
+ Object.assign(styles, {
332
+ "--background-clip": "text",
333
+ "--text-fill-color": "transparent",
334
+ "--background": getColor({ colorMap: color, colorMode }),
335
+ });
243
336
  }
244
337
  return styles;
245
338
  }
@@ -253,23 +346,6 @@ export function stringifyStyles(styles) {
253
346
  .map(([key, value]) => `${key}: ${value}`)
254
347
  .join("; ");
255
348
  }
256
- /**
257
- * Given a ComponentLocalizations object and a locale returns the label with label_id in the chosen locale, if any. Falls
258
- * back to the label with the same label_id in the fallbackLocale, if any. Finally returns undefined if no label can be
259
- * found for the requested label_id.
260
- * @param label_id - The id of the label to be returned
261
- * @param locale - The preferred locale to return the label
262
- * @param fallbackLocale - The locale to fall back to in case no label is found in the preferred one
263
- * @param labels - A ComponentLocalizations instance
264
- * @returns The label in the preferred or fallback locale, or undefined.
265
- */
266
- export function getLabelById(label_id, locale, fallbackLocale, labels) {
267
- const fallback = labels[fallbackLocale]?.[label_id];
268
- if (!(labels[locale] || {})[label_id]) {
269
- return fallback;
270
- }
271
- return labels[locale][label_id];
272
- }
273
349
  /**
274
350
  * Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
275
351
  * @param paywallData
@@ -326,3 +402,14 @@ const getComponentActiveStateKeys = (componentState) => {
326
402
  }, []);
327
403
  return stateKeys;
328
404
  };
405
+ export function prefixObject(object, prefix) {
406
+ if (!object)
407
+ return {};
408
+ if (!prefix)
409
+ return object;
410
+ return Object.entries(object).reduce((acc, [key, value]) => {
411
+ const replacedKey = key.replace(/^--/, `${prefix}-`);
412
+ acc[`--${replacedKey}`] = value;
413
+ return acc;
414
+ }, {});
415
+ }
@@ -1,3 +1,4 @@
1
+ import type { ComponentLocalizations } from "../data/entities";
1
2
  export declare const VARIABLE_NAMES: string[];
2
3
  export type VariableDictionary = {
3
4
  product_name: string | number | undefined;
@@ -31,3 +32,29 @@ export type ReplaceVariablesProps = {
31
32
  * @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
32
33
  */
33
34
  export declare const replaceVariables: ({ value, variableDictionary: dictionary, }: ReplaceVariablesProps) => string | undefined;
35
+ /**
36
+ * Given a ComponentLocalizations object and a locale returns the label with label_id in the chosen locale, if any. Falls
37
+ * back to the label with the same label_id in the fallbackLocale, if any. Finally returns undefined if no label can be
38
+ * found for the requested label_id.
39
+ * @param label_id - The id of the label to be returned
40
+ * @param locale - The preferred locale to return the label
41
+ * @param fallbackLocale - The locale to fall back to in case no label is found in the preferred one
42
+ * @param labels - A ComponentLocalizations instance
43
+ * @returns The label in the preferred or fallback locale, or undefined.
44
+ */
45
+ export declare function getLabelById(label_id: string | null | undefined, locale: string, fallbackLocale: string, labels: ComponentLocalizations): string | undefined;
46
+ /**
47
+ * Gets a label by ID and replaces any variables in it with values from the dictionary
48
+ * @param text_lid - The ID of the text label to retrieve
49
+ * @param purchaseState - Object containing locale and defaultLocale
50
+ * @param labels - ComponentLocalizations containing the labels
51
+ * @param variableDictionary - Dictionary of variables to replace in the label text
52
+ * @returns The label with variables replaced, or undefined if label not found
53
+ */
54
+ export declare function getLabelAndReplaceVariables({ text_lid, locale, defaultLocale, labels, variableDictionary, }: {
55
+ text_lid?: string;
56
+ locale: string;
57
+ defaultLocale: string;
58
+ labels: ComponentLocalizations;
59
+ variableDictionary?: VariableDictionary;
60
+ }): string | undefined;