@revenuecat/purchases-ui-js 0.0.17 → 0.0.19

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