@revenuecat/purchases-ui-js 2.0.0 → 2.0.2
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/button/Button.svelte +1 -5
- package/dist/components/button/ButtonNode.stories.svelte +57 -71
- package/dist/components/button/ButtonNode.stories.svelte.d.ts +0 -8
- package/dist/components/button/ButtonNode.svelte +10 -21
- package/dist/components/button/ButtonNode.svelte.d.ts +2 -2
- package/dist/components/button/button-utils.d.ts +2 -2
- package/dist/components/footer/Footer.stories.svelte +26 -22
- package/dist/components/footer/Footer.stories.svelte.d.ts +0 -5
- package/dist/components/footer/Footer.svelte +3 -10
- package/dist/components/footer/Footer.svelte.d.ts +1 -1
- package/dist/components/image/Image.stories.svelte +27 -19
- package/dist/components/image/Image.svelte +18 -17
- package/dist/components/image/image-utils.d.ts +2 -1
- package/dist/components/image/image-utils.js +2 -2
- package/dist/components/package/Package.stories.svelte +31 -31
- package/dist/components/package/Package.stories.svelte.d.ts +0 -6
- package/dist/components/package/Package.svelte +19 -30
- package/dist/components/package/Package.svelte.d.ts +1 -1
- package/dist/components/paywall/Node.svelte +26 -50
- package/dist/components/paywall/Node.svelte.d.ts +11 -14
- package/dist/components/paywall/Paywall.stories.svelte +21 -78
- package/dist/components/paywall/Paywall.svelte +75 -100
- package/dist/components/paywall/Paywall.svelte.d.ts +4 -4
- package/dist/components/paywall/paywall-utils.d.ts +3 -2
- package/dist/components/paywall/paywall-utils.js +5 -5
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +29 -31
- package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +0 -5
- package/dist/components/purchase-button/PurchaseButton.svelte +9 -20
- package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +1 -1
- package/dist/components/purchase-button/purchase-button-utils.d.ts +1 -1
- package/dist/components/stack/Stack.stories.svelte +17 -94
- package/dist/components/stack/Stack.svelte +18 -48
- package/dist/components/stack/stack-utils.d.ts +4 -3
- package/dist/components/stack/stack-utils.js +7 -10
- package/dist/components/text/TextNode.stories.svelte +45 -152
- package/dist/components/text/TextNode.svelte +15 -23
- package/dist/components/text/text-utils.d.ts +7 -6
- package/dist/components/text/text-utils.js +7 -7
- package/dist/components/timeline/Timeline.stories.svelte +37 -48
- package/dist/components/timeline/Timeline.svelte +0 -2
- package/dist/components/timeline/TimelineItem.svelte +28 -11
- package/dist/components/timeline/timeline-utils.d.ts +3 -3
- package/dist/components/timeline/timeline-utils.js +7 -17
- package/dist/data/entities.d.ts +54 -145
- package/dist/index.d.ts +10 -10
- package/dist/index.js +10 -10
- package/dist/stores/color-mode.d.ts +6 -0
- package/dist/stores/color-mode.js +15 -0
- package/dist/stores/localization.d.ts +13 -0
- package/dist/stores/localization.js +26 -0
- package/dist/stores/paywall.d.ts +11 -0
- package/dist/stores/paywall.js +13 -0
- package/dist/stores/variables.d.ts +5 -0
- package/dist/stores/variables.js +14 -0
- package/dist/stories/fixtures.d.ts +1 -1
- package/dist/stories/fixtures.js +30 -135
- package/dist/stories/localization-decorator.d.ts +3 -0
- package/dist/stories/localization-decorator.js +7 -0
- package/dist/stories/paywall-decorator.d.ts +2 -0
- package/dist/stories/paywall-decorator.js +19 -0
- package/dist/stories/variables-decorator.d.ts +3 -0
- package/dist/stories/variables-decorator.js +9 -0
- package/dist/stories/with-layout.svelte +4 -4
- package/dist/types/alignment.d.ts +19 -0
- package/dist/types/background.d.ts +18 -0
- package/dist/types/background.js +1 -0
- package/dist/types/colors.d.ts +34 -0
- package/dist/types/colors.js +1 -0
- package/dist/types/component.d.ts +6 -0
- package/dist/types/component.js +1 -0
- package/dist/types/components/button.d.ts +36 -0
- package/dist/types/components/button.js +1 -0
- package/dist/types/components/footer.d.ts +5 -0
- package/dist/types/components/footer.js +1 -0
- package/dist/types/components/package.d.ts +8 -0
- package/dist/types/components/package.js +1 -0
- package/dist/types/components/purchase-button.d.ts +5 -0
- package/dist/types/components/purchase-button.js +1 -0
- package/dist/types/localization.d.ts +4 -0
- package/dist/types/localization.js +1 -0
- package/dist/types/media.d.ts +18 -0
- package/dist/types/media.js +1 -0
- package/dist/types.d.ts +5 -35
- package/dist/ui/atoms/typography.stories.svelte +7 -13
- package/dist/ui/atoms/typography.stories.svelte.d.ts +1 -1
- package/dist/ui/atoms/typography.svelte +1 -1
- package/dist/ui/layout/main-block.svelte +2 -2
- package/dist/ui/molecules/button.stories.svelte +8 -15
- package/dist/ui/molecules/button.svelte +3 -2
- package/dist/ui/molecules/button.svelte.d.ts +2 -26
- package/dist/ui/molecules/types.d.ts +2 -1
- package/dist/ui/theme/theme.d.ts +2 -2
- package/dist/ui/theme/theme.js +2 -2
- package/dist/ui/theme/utils.d.ts +2 -2
- package/dist/utils/style-utils.d.ts +13 -11
- package/dist/utils/style-utils.js +21 -27
- package/dist/utils/variable-utils.d.ts +1 -38
- package/dist/utils/variable-utils.js +6 -48
- package/dist/web-components/index.css +1 -1
- package/dist/web-components/index.js +610 -657
- package/package.json +33 -36
- package/dist/data/state.d.ts +0 -9
- package/dist/stores/theme.d.ts +0 -1
- package/dist/stores/theme.js +0 -17
- /package/dist/{data/state.js → types/alignment.js} +0 -0
|
@@ -41,7 +41,7 @@ export function getColor({ colorMap, colorMode = DEFAULT_COLOR_MODE, fallback =
|
|
|
41
41
|
return fallback;
|
|
42
42
|
const color = colorMap[colorMode] || colorMap[DEFAULT_COLOR_MODE];
|
|
43
43
|
let colorPoints = "";
|
|
44
|
-
switch (color
|
|
44
|
+
switch (color?.type) {
|
|
45
45
|
case "hex":
|
|
46
46
|
case "alias":
|
|
47
47
|
return color.value ?? fallback;
|
|
@@ -257,8 +257,8 @@ export function getDimensionStyle(dimension) {
|
|
|
257
257
|
* @param colorMode - The currently selected ColorMode (dark/light)
|
|
258
258
|
* @returns CSS style object with text formatting properties
|
|
259
259
|
*/
|
|
260
|
-
export function getTextStyles(props
|
|
261
|
-
const { font_size, horizontal_alignment, font_weight, font_name
|
|
260
|
+
export function getTextStyles(props) {
|
|
261
|
+
const { font_size, horizontal_alignment, font_weight, font_name } = props;
|
|
262
262
|
const styles = {
|
|
263
263
|
"--text-align": "initial",
|
|
264
264
|
"--font-weight": "initial",
|
|
@@ -274,14 +274,6 @@ export function getTextStyles(props, colorMode = DEFAULT_COLOR_MODE) {
|
|
|
274
274
|
"--font-size": FontSizes[font_size] || FontSizes.body_m,
|
|
275
275
|
"--font-family": font_name || "sans-serif",
|
|
276
276
|
});
|
|
277
|
-
if (color &&
|
|
278
|
-
(color[colorMode]?.type === "linear" || color[colorMode]?.type === "radial")) {
|
|
279
|
-
Object.assign(styles, {
|
|
280
|
-
"--background-clip": "text",
|
|
281
|
-
"--text-fill-color": "transparent",
|
|
282
|
-
"--background": getColor({ colorMap: color, colorMode }),
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
277
|
return styles;
|
|
286
278
|
}
|
|
287
279
|
/**
|
|
@@ -301,31 +293,32 @@ export function stringifyStyles(styles) {
|
|
|
301
293
|
*/
|
|
302
294
|
export function findSelectedPackageId(paywallData) {
|
|
303
295
|
const traverseNode = (node) => {
|
|
304
|
-
if (node.type === "package" &&
|
|
305
|
-
node.is_selected_by_default) {
|
|
296
|
+
if (node.type === "package" && node.is_selected_by_default) {
|
|
306
297
|
return node;
|
|
307
298
|
}
|
|
308
|
-
if (
|
|
309
|
-
for (const
|
|
310
|
-
const pkg = traverseNode(
|
|
311
|
-
if (pkg) {
|
|
299
|
+
if ("components" in node && Array.isArray(node.components)) {
|
|
300
|
+
for (const component of node.components) {
|
|
301
|
+
const pkg = traverseNode(component);
|
|
302
|
+
if (pkg !== undefined) {
|
|
312
303
|
return pkg;
|
|
313
304
|
}
|
|
314
305
|
}
|
|
315
306
|
}
|
|
316
|
-
if (
|
|
307
|
+
if ("stack" in node) {
|
|
317
308
|
const pkg = traverseNode(node.stack);
|
|
318
|
-
if (pkg) {
|
|
309
|
+
if (pkg !== undefined) {
|
|
319
310
|
return pkg;
|
|
320
311
|
}
|
|
321
312
|
}
|
|
322
313
|
return undefined;
|
|
323
314
|
};
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
315
|
+
for (const component of paywallData.components_config.base.stack.components) {
|
|
316
|
+
const pkg = traverseNode(component);
|
|
317
|
+
if (pkg !== undefined) {
|
|
318
|
+
return pkg?.package_id;
|
|
319
|
+
}
|
|
327
320
|
}
|
|
328
|
-
return
|
|
321
|
+
return undefined;
|
|
329
322
|
}
|
|
330
323
|
export const getActiveStateProps = (overrides, componentState) => {
|
|
331
324
|
if (!componentState)
|
|
@@ -400,12 +393,13 @@ export const getMaskStyle = (maskShape) => {
|
|
|
400
393
|
}
|
|
401
394
|
return maskStyles;
|
|
402
395
|
};
|
|
403
|
-
export function getLinearGradientAngle(props) {
|
|
404
|
-
|
|
396
|
+
export function getLinearGradientAngle(colorMode, props) {
|
|
397
|
+
const { color_overlay: colorOverlay } = props;
|
|
398
|
+
if (colorOverlay?.[colorMode]?.type !== "linear") {
|
|
405
399
|
return { x1: "0%", y1: "0%", x2: "0%", y2: "0%" };
|
|
406
400
|
}
|
|
407
|
-
const
|
|
408
|
-
const angle =
|
|
401
|
+
const defaultColor = colorOverlay?.[DEFAULT_COLOR_MODE];
|
|
402
|
+
const angle = defaultColor?.type === "linear" ? defaultColor.degrees : 0;
|
|
409
403
|
const x1 = "50%";
|
|
410
404
|
const y1 = "0%";
|
|
411
405
|
const x2 = `${Math.round(50 + Math.sin(((angle + 90) * Math.PI) / 90) * 50)}%`;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { ComponentLocalizations } from "../data/entities";
|
|
2
1
|
export declare const VARIABLE_NAMES: string[];
|
|
3
2
|
export type VariableDictionary = {
|
|
4
3
|
product_name: string | number | undefined;
|
|
@@ -21,40 +20,4 @@ export type VariableDictionary = {
|
|
|
21
20
|
sub_relative_discount: string | number | undefined;
|
|
22
21
|
[key: string]: string | number | undefined;
|
|
23
22
|
};
|
|
24
|
-
export
|
|
25
|
-
value?: string;
|
|
26
|
-
variableDictionary?: VariableDictionary;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Returns a string with the variables replaced by values from the dictionary
|
|
30
|
-
* @param value A string like "Try {{ product_name }} for only {{ total_price_and_per_month }}"
|
|
31
|
-
* @param dictionary Dictionary containing the values for the variables
|
|
32
|
-
* @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
|
|
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;
|
|
23
|
+
export declare function replaceVariables(input?: string, variables?: VariableDictionary): string | undefined;
|
|
@@ -18,54 +18,12 @@ export const VARIABLE_NAMES = [
|
|
|
18
18
|
"sub_offer_price_2",
|
|
19
19
|
"sub_relative_discount",
|
|
20
20
|
];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
* @returns The string with values: "Try CatGPT Annual for only $59.99/yr ($4.99/mo)"
|
|
26
|
-
*/
|
|
27
|
-
export const replaceVariables = ({ value = "", variableDictionary: dictionary, }) => {
|
|
28
|
-
if (!dictionary)
|
|
29
|
-
return value;
|
|
21
|
+
export function replaceVariables(input = "", variables) {
|
|
22
|
+
if (variables === undefined) {
|
|
23
|
+
return input;
|
|
24
|
+
}
|
|
30
25
|
return VARIABLE_NAMES.reduce((result, variableName) => {
|
|
31
|
-
const currentVariableReplaced = result.replaceAll(`{{ ${variableName} }}`,
|
|
26
|
+
const currentVariableReplaced = result.replaceAll(`{{ ${variableName} }}`, variables[variableName]?.toString() || "N/A");
|
|
32
27
|
return currentVariableReplaced;
|
|
33
|
-
},
|
|
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;
|
|
28
|
+
}, input);
|
|
71
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.rcb-
|
|
1
|
+
.rcb-typography-heading-2xl.svelte-byrjto{font:var(--rc-text-heading2xl-mobile)}.rcb-typography-heading-xl.svelte-byrjto{font:var(--rc-text-headingXl-mobile)}.rcb-typography-heading-lg.svelte-byrjto{font:var(--rc-text-headingLg-mobile)}.rcb-typography-heading-md.svelte-byrjto{font:var(--rc-text-headingMd-mobile)}.rcb-typography-body-base.svelte-byrjto{font:var(--rc-text-bodyBase-mobile)}.rcb-typography-body-small.svelte-byrjto{font:var(--rc-text-bodySmall-mobile)}.rcb-typography-label-button.svelte-byrjto{font:var(--rc-text-labelButton-mobile)}.rcb-typography-label-default.svelte-byrjto{font:var(--rc-text-labelDefault-mobile)}.rcb-typography-caption-default.svelte-byrjto{font:var(--rc-text-captionDefault-mobile)}.rcb-typography-caption-link.svelte-byrjto{font:var(--rc-text-captionLink-mobile)}@container layout-query-container (width >= 768px){.rcb-typography-heading-2xl.svelte-byrjto{font:var(--rc-text-heading2xl-desktop)}.rcb-typography-heading-xl.svelte-byrjto{font:var(--rc-text-headingXl-desktop)}.rcb-typography-heading-lg.svelte-byrjto{font:var(--rc-text-headingLg-desktop)}.rcb-typography-heading-md.svelte-byrjto{font:var(--rc-text-headingMd-desktop)}.rcb-typography-body-base.svelte-byrjto{font:var(--rc-text-bodyBase-desktop)}.rcb-typography-body-small.svelte-byrjto{font:var(--rc-text-bodySmall-desktop)}.rcb-typography-label-button.svelte-byrjto{font:var(--rc-text-labelButton-desktop)}.rcb-typography-label-default.svelte-byrjto{font:var(--rc-text-labelDefault-desktop)}.rcb-typography-caption-default.svelte-byrjto{font:var(--rc-text-captionDefault-desktop)}.rcb-typography-caption-link.svelte-byrjto{font:var(--rc-text-captionLink-desktop)}}.rcb-processing.svelte-2j2b59{width:var(--width, 12px);aspect-ratio:1;border-radius:50%;animation:svelte-2j2b59-l5 1.5s infinite linear}@keyframes svelte-2j2b59-l5{0%{box-shadow:var(--shadow-offset) 0 #fff2,calc(-1 * var(--shadow-offset)) 0 #fff2;background:#fff2}25%{box-shadow:var(--shadow-offset) 0 #fff2,calc(-1 * var(--shadow-offset)) 0 #fff;background:#fff2}50%{box-shadow:var(--shadow-offset) 0 #fff2,calc(-1 * var(--shadow-offset)) 0 #fff2;background:#fff}75%{box-shadow:var(--shadow-offset) 0 #fff,calc(-1 * var(--shadow-offset)) 0 #fff2;background:#fff2}to{box-shadow:var(--shadow-offset) 0 #fff2,calc(-1 * var(--shadow-offset)) 0 #fff2;background:#fff2}}button.svelte-td7xvm{border:none;border-radius:var(--rc-shape-input-button-border-radius);cursor:pointer;height:var(--rc-spacing-inputHeight-mobile);color:var(--rc-color-grey-text-dark);background-color:var(--rc-color-grey-ui-dark);display:flex;align-items:center;justify-content:center;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-tap-highlight-color:transparent;transition:background-color .15s ease-in-out;-webkit-user-select:none;user-select:none}@container layout-query-container (width >= 768px){button.svelte-td7xvm{height:var(--rc-spacing-inputHeight-desktop)}}button.svelte-td7xvm:focus-visible{outline:2px solid var(--rc-color-focus)}button.intent-primary.svelte-td7xvm{background-color:var(--rc-color-primary);color:var(--rc-color-primary-text)}button.svelte-td7xvm:disabled{color:var(--rc-color-grey-text-light);background-color:var(--rc-color-grey-ui-dark);outline:none}button.intent-primary.svelte-td7xvm:not(:disabled):hover{background-color:var(--rc-color-primary-hover)}button.intent-primary.svelte-td7xvm:not(:disabled):active,button.svelte-td7xvm:active{background-color:var(--rc-color-primary-pressed);outline:none}button.intent-primary.svelte-td7xvm:disabled{color:var(--rc-color-grey-text-light);background-color:var(--rc-color-grey-ui-dark)}
|