@revenuecat/purchases-ui-js 0.0.18 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/footer/Footer.svelte +9 -3
- package/dist/components/image/Image.stories.svelte +124 -13
- package/dist/components/image/Image.svelte +104 -9
- package/dist/components/image/image-utils.d.ts +10 -2
- package/dist/components/image/image-utils.js +8 -16
- package/dist/components/paywall/Node.svelte +3 -0
- package/dist/components/paywall/Node.svelte.d.ts +2 -1
- package/dist/components/paywall/Paywall.stories.svelte +66 -5
- package/dist/components/paywall/Paywall.svelte +1 -1
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +6 -0
- package/dist/components/stack/Stack.svelte +2 -0
- package/dist/components/stack/stack-utils.d.ts +1 -1
- package/dist/components/stack/stack-utils.js +3 -3
- package/dist/components/text/text-utils.js +3 -3
- package/dist/data/entities.d.ts +9 -10
- package/dist/stories/fixtures.d.ts +1 -1
- package/dist/stories/fixtures.js +5961 -5434
- package/dist/utils/style-utils.d.ts +30 -28
- package/dist/utils/style-utils.js +57 -59
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentState, ImageMaskShapeType, PaywallData, TextNodeProps } from "../data/entities.js";
|
|
1
|
+
import type { ComponentState, ImageMaskShapeType, ImageProps, PaywallData, TextNodeProps } from "../data/entities.js";
|
|
2
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
3
|
type MarginVariables = {
|
|
4
4
|
"--margin-block-start": string;
|
|
@@ -60,11 +60,11 @@ type ComponentStyleVariables = {
|
|
|
60
60
|
* @param params - Component style configuration object
|
|
61
61
|
* @returns CSS style object with component styles
|
|
62
62
|
*/
|
|
63
|
-
export declare function getComponentStyles({
|
|
63
|
+
export declare function getComponentStyles({ background_color, border, margin, padding, color, colorMode, shape, shadow, }: {
|
|
64
64
|
padding?: Spacing;
|
|
65
65
|
margin?: Spacing;
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
background_color?: ColorType;
|
|
67
|
+
color?: ColorType;
|
|
68
68
|
border?: BorderType;
|
|
69
69
|
colorMode?: ColorMode;
|
|
70
70
|
shape?: ShapeType;
|
|
@@ -81,29 +81,6 @@ type SizeStyleVariables = {
|
|
|
81
81
|
* @returns CSS style object with size properties
|
|
82
82
|
*/
|
|
83
83
|
export declare function getSizeStyle(size: SizeType): SizeStyleVariables;
|
|
84
|
-
type GradientStyleVariables = {
|
|
85
|
-
"--background": string;
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Generates gradient background styles
|
|
89
|
-
* @param colorMode - Color mode (light/dark)
|
|
90
|
-
* @param gradientColors - Array of colors for gradient
|
|
91
|
-
* @returns CSS style object with gradient background
|
|
92
|
-
*/
|
|
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;
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* Generates mask styles for images
|
|
103
|
-
* @param maskShape - Shape configuration for image mask
|
|
104
|
-
* @returns CSS style object with mask properties
|
|
105
|
-
*/
|
|
106
|
-
export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => MaskStyleVariables;
|
|
107
84
|
type InsetStyleVariables = {
|
|
108
85
|
"--inset": string;
|
|
109
86
|
"--transform": string;
|
|
@@ -151,6 +128,31 @@ export declare function stringifyStyles(styles: Record<string, string | number>)
|
|
|
151
128
|
* @returns the id of the first package marked as `is_selected_by_default` or undefined
|
|
152
129
|
*/
|
|
153
130
|
export declare function findSelectedPackageId(paywallData: PaywallData): string | undefined;
|
|
154
|
-
export declare const getActiveStateProps: <T>(overrides?:
|
|
131
|
+
export declare const getActiveStateProps: <T>(overrides?: {
|
|
132
|
+
states?: Record<string, T>;
|
|
133
|
+
}, componentState?: ComponentState) => T;
|
|
155
134
|
export declare function prefixObject(object?: Record<string, string | number>, prefix?: string): Record<string, string | number>;
|
|
135
|
+
export declare function getMaskPath(props: ImageProps & {
|
|
136
|
+
imageAspectRatio: number;
|
|
137
|
+
}): string;
|
|
138
|
+
type MaskStyleVariables = {
|
|
139
|
+
"--border-start-start-radius": string;
|
|
140
|
+
"--border-start-end-radius": string;
|
|
141
|
+
"--border-end-start-radius": string;
|
|
142
|
+
"--border-end-end-radius": string;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Generates mask styles for images
|
|
146
|
+
* @param maskShape - Shape configuration for image mask
|
|
147
|
+
* @returns CSS style object with mask properties
|
|
148
|
+
*/
|
|
149
|
+
export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => MaskStyleVariables;
|
|
150
|
+
export declare function getLinearGradientAngle(props: ImageProps & {
|
|
151
|
+
imageAspectRatio: number;
|
|
152
|
+
}): {
|
|
153
|
+
x1: string;
|
|
154
|
+
y1: string;
|
|
155
|
+
x2: string;
|
|
156
|
+
y2: string;
|
|
157
|
+
};
|
|
156
158
|
export {};
|
|
@@ -88,7 +88,7 @@ export function getCornerRadiusStyle(corners) {
|
|
|
88
88
|
* @param params - Component style configuration object
|
|
89
89
|
* @returns CSS style object with component styles
|
|
90
90
|
*/
|
|
91
|
-
export function getComponentStyles({
|
|
91
|
+
export function getComponentStyles({ background_color, border, margin, padding, color, colorMode = "light", shape, shadow, }) {
|
|
92
92
|
const stylesObject = {
|
|
93
93
|
"--margin-block-start": "0px",
|
|
94
94
|
"--margin-inline-end": "0px",
|
|
@@ -113,16 +113,16 @@ export function getComponentStyles({ backgroundColor, border, margin, padding, t
|
|
|
113
113
|
if (margin) {
|
|
114
114
|
Object.assign(stylesObject, getSpacingStyle(margin, "margin"));
|
|
115
115
|
}
|
|
116
|
-
if (
|
|
116
|
+
if (background_color) {
|
|
117
117
|
stylesObject["--background"] = getColor({
|
|
118
|
-
colorMap:
|
|
118
|
+
colorMap: background_color,
|
|
119
119
|
colorMode,
|
|
120
120
|
fallback: "transparent",
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
if (
|
|
123
|
+
if (color) {
|
|
124
124
|
stylesObject["--text-color"] = getColor({
|
|
125
|
-
colorMap:
|
|
125
|
+
colorMap: color,
|
|
126
126
|
colorMode,
|
|
127
127
|
fallback: "#000000",
|
|
128
128
|
});
|
|
@@ -182,59 +182,6 @@ export function getSizeStyle(size) {
|
|
|
182
182
|
});
|
|
183
183
|
return styles;
|
|
184
184
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Generates gradient background styles
|
|
187
|
-
* @param colorMode - Color mode (light/dark)
|
|
188
|
-
* @param gradientColors - Array of colors for gradient
|
|
189
|
-
* @returns CSS style object with gradient background
|
|
190
|
-
*/
|
|
191
|
-
export function getGradientStyle(colorMode, gradientColors) {
|
|
192
|
-
if (!gradientColors)
|
|
193
|
-
return { "--background": "none" };
|
|
194
|
-
return {
|
|
195
|
-
"--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value || color["light"].value).join(", ")})`,
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Generates mask styles for images
|
|
200
|
-
* @param maskShape - Shape configuration for image mask
|
|
201
|
-
* @returns CSS style object with mask properties
|
|
202
|
-
*/
|
|
203
|
-
export const getMaskStyle = (maskShape) => {
|
|
204
|
-
const maskStyles = {
|
|
205
|
-
"--border-end-start-radius": "0px",
|
|
206
|
-
"--border-end-end-radius": "0px",
|
|
207
|
-
"--border-start-start-radius": "0px",
|
|
208
|
-
"--border-start-end-radius": "0px",
|
|
209
|
-
"--clip-path": "none",
|
|
210
|
-
};
|
|
211
|
-
if (maskShape?.type === "circle") {
|
|
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
|
-
});
|
|
218
|
-
}
|
|
219
|
-
if (maskShape?.type === "rectangle" && maskShape.corners) {
|
|
220
|
-
Object.assign(maskStyles, getCornerRadiusStyle(maskShape.corners));
|
|
221
|
-
}
|
|
222
|
-
// TODO: rework this implementation
|
|
223
|
-
if (maskShape?.type === "convex") {
|
|
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
|
-
});
|
|
230
|
-
}
|
|
231
|
-
if (maskShape?.type === "concave") {
|
|
232
|
-
Object.assign(maskStyles, {
|
|
233
|
-
"--clip-path": "polygon(0 0, 100% 0, 100% 100%, 50% 110%, 0 100%);",
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
return maskStyles;
|
|
237
|
-
};
|
|
238
185
|
export function getInsetStyles(dimension) {
|
|
239
186
|
const defaultStyles = {
|
|
240
187
|
"--inset": "initial",
|
|
@@ -385,7 +332,7 @@ export const getActiveStateProps = (overrides, componentState) => {
|
|
|
385
332
|
const activeStateKeys = getComponentActiveStateKeys(componentState);
|
|
386
333
|
const activeStateProps = activeStateKeys.reduce((props, key) => {
|
|
387
334
|
if (overrides) {
|
|
388
|
-
const styles = overrides[key] || {};
|
|
335
|
+
const styles = overrides?.states?.[key] || {};
|
|
389
336
|
return { ...props, ...styles };
|
|
390
337
|
}
|
|
391
338
|
return props;
|
|
@@ -413,3 +360,54 @@ export function prefixObject(object, prefix) {
|
|
|
413
360
|
return acc;
|
|
414
361
|
}, {});
|
|
415
362
|
}
|
|
363
|
+
export function getMaskPath(props) {
|
|
364
|
+
const { mask_shape: maskShape, imageAspectRatio } = props;
|
|
365
|
+
let maskPath = "";
|
|
366
|
+
if (maskShape?.type === "concave") {
|
|
367
|
+
maskPath = `M 0 0
|
|
368
|
+
H 100
|
|
369
|
+
V ${imageAspectRatio * 100}
|
|
370
|
+
Q 50 ${imageAspectRatio * 80} 0 ${imageAspectRatio * 100}
|
|
371
|
+
Z`;
|
|
372
|
+
}
|
|
373
|
+
else if (maskShape?.type === "convex") {
|
|
374
|
+
maskPath = `M 0 0
|
|
375
|
+
H 100
|
|
376
|
+
V ${imageAspectRatio * 80}
|
|
377
|
+
Q 50 ${imageAspectRatio * 120} 0 ${imageAspectRatio * 80}
|
|
378
|
+
Z`;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
maskPath = `M 0 0 H 100 V ${imageAspectRatio * 100} H 0 Z`;
|
|
382
|
+
}
|
|
383
|
+
return maskPath;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Generates mask styles for images
|
|
387
|
+
* @param maskShape - Shape configuration for image mask
|
|
388
|
+
* @returns CSS style object with mask properties
|
|
389
|
+
*/
|
|
390
|
+
export const getMaskStyle = (maskShape) => {
|
|
391
|
+
const maskStyles = {
|
|
392
|
+
"--border-end-start-radius": "0px",
|
|
393
|
+
"--border-end-end-radius": "0px",
|
|
394
|
+
"--border-start-start-radius": "0px",
|
|
395
|
+
"--border-start-end-radius": "0px",
|
|
396
|
+
};
|
|
397
|
+
if (maskShape?.corners) {
|
|
398
|
+
Object.assign(maskStyles, getCornerRadiusStyle(maskShape.corners));
|
|
399
|
+
}
|
|
400
|
+
return maskStyles;
|
|
401
|
+
};
|
|
402
|
+
export function getLinearGradientAngle(props) {
|
|
403
|
+
if (props.color_overlay?.[props.purchaseState.colorMode]?.type !== "linear") {
|
|
404
|
+
return { x1: "0%", y1: "0%", x2: "0%", y2: "0%" };
|
|
405
|
+
}
|
|
406
|
+
const { color_overlay: colorOverlay } = props;
|
|
407
|
+
const angle = colorOverlay?.["light"]?.degrees || 0;
|
|
408
|
+
const x1 = "50%";
|
|
409
|
+
const y1 = "0%";
|
|
410
|
+
const x2 = `${Math.round(50 + Math.sin(((angle + 90) * Math.PI) / 90) * 50)}%`;
|
|
411
|
+
const y2 = `${Math.round(50 - Math.cos(((angle + 90) * Math.PI) / 90) * 50)}%`;
|
|
412
|
+
return { x1, y1, x2, y2 };
|
|
413
|
+
}
|