@revenuecat/purchases-ui-js 2.0.6 → 2.1.0
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/ButtonNode.stories.svelte +20 -0
- package/dist/components/button/ButtonNode.svelte +7 -1
- package/dist/components/paywall/Paywall.svelte +8 -1
- package/dist/components/paywall/Paywall.svelte.d.ts +1 -0
- package/dist/components/text/TextNode.stories.svelte +106 -0
- package/dist/components/text/TextNode.svelte +5 -3
- package/dist/components/text/text-utils.d.ts +5 -5
- package/dist/components/text/text-utils.js +34 -19
- package/dist/components/timeline/TimelineItem.svelte +4 -8
- package/dist/stores/paywall.d.ts +1 -1
- package/dist/stories/paywall-decorator.js +1 -1
- package/dist/types/base.d.ts +1 -0
- package/dist/types/components/button.d.ts +7 -1
- package/dist/types/components/text.d.ts +2 -2
- package/dist/types/ui-config.d.ts +1 -1
- package/dist/utils/base-utils.d.ts +2 -1
- package/dist/utils/base-utils.js +1 -1
- package/dist/utils/style-utils.d.ts +0 -30
- package/dist/utils/style-utils.js +0 -66
- package/package.json +1 -1
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
id2: "Navigate back",
|
|
76
76
|
id3: "Navigate to",
|
|
77
77
|
id4: "URL navigation",
|
|
78
|
+
id5: "Workflow Action",
|
|
78
79
|
},
|
|
79
80
|
},
|
|
80
81
|
}),
|
|
@@ -166,3 +167,22 @@
|
|
|
166
167
|
},
|
|
167
168
|
}}
|
|
168
169
|
/>
|
|
170
|
+
|
|
171
|
+
<Story
|
|
172
|
+
name="Workflow Action"
|
|
173
|
+
args={{
|
|
174
|
+
action: {
|
|
175
|
+
type: "workflow",
|
|
176
|
+
},
|
|
177
|
+
triggers: {
|
|
178
|
+
on_press: "workflow-action-id",
|
|
179
|
+
},
|
|
180
|
+
stack: {
|
|
181
|
+
...stackProps(5),
|
|
182
|
+
background_color: {
|
|
183
|
+
dark: { type: "hex", value: "#9C27B0" },
|
|
184
|
+
light: { type: "hex", value: "#9C27B0" },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
}}
|
|
188
|
+
/>
|
|
@@ -17,10 +17,16 @@
|
|
|
17
17
|
|
|
18
18
|
const { onButtonAction } = getPaywallContext();
|
|
19
19
|
|
|
20
|
-
const onclick = () =>
|
|
20
|
+
const onclick = () => {
|
|
21
|
+
const actionId = props.triggers?.on_press;
|
|
22
|
+
onButtonAction(props.action, actionId);
|
|
23
|
+
};
|
|
21
24
|
|
|
22
25
|
const visible = $derived.by(() => {
|
|
23
26
|
switch (action.type) {
|
|
27
|
+
case "workflow":
|
|
28
|
+
return true;
|
|
29
|
+
case "restore_purchases":
|
|
24
30
|
case "navigate_back":
|
|
25
31
|
return false;
|
|
26
32
|
case "navigate_to":
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
onVisitCustomerCenterClicked?: () => void;
|
|
34
34
|
onRestorePurchasesClicked?: () => void;
|
|
35
35
|
onNavigateToUrlClicked?: (url: string) => void;
|
|
36
|
+
onActionTriggered?: (actionId: string) => void;
|
|
36
37
|
onError?: (error: unknown) => void;
|
|
37
38
|
}
|
|
38
39
|
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
onVisitCustomerCenterClicked,
|
|
47
48
|
onRestorePurchasesClicked,
|
|
48
49
|
onNavigateToUrlClicked,
|
|
50
|
+
onActionTriggered,
|
|
49
51
|
onError,
|
|
50
52
|
uiConfig,
|
|
51
53
|
}: Props = $props();
|
|
@@ -76,8 +78,13 @@
|
|
|
76
78
|
|
|
77
79
|
let sheet = $state<SheetProps>();
|
|
78
80
|
|
|
79
|
-
const onButtonAction = (action: Action) => {
|
|
81
|
+
const onButtonAction = (action: Action, actionId?: string) => {
|
|
80
82
|
switch (action.type) {
|
|
83
|
+
case "workflow":
|
|
84
|
+
if (actionId) {
|
|
85
|
+
onActionTriggered?.(actionId);
|
|
86
|
+
}
|
|
87
|
+
return;
|
|
81
88
|
case "navigate_back":
|
|
82
89
|
onBackClicked?.();
|
|
83
90
|
return;
|
|
@@ -13,6 +13,7 @@ interface Props {
|
|
|
13
13
|
onVisitCustomerCenterClicked?: () => void;
|
|
14
14
|
onRestorePurchasesClicked?: () => void;
|
|
15
15
|
onNavigateToUrlClicked?: (url: string) => void;
|
|
16
|
+
onActionTriggered?: (actionId: string) => void;
|
|
16
17
|
onError?: (error: unknown) => void;
|
|
17
18
|
}
|
|
18
19
|
declare const Paywall: import("svelte").Component<Props, {}, "">;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import type { VariableDictionary } from "../../types/variables";
|
|
7
7
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
8
8
|
import { VARIABLES } from "../paywall/fixtures/variables";
|
|
9
|
+
import { DEFAULT_SPACING } from "../../utils/constants";
|
|
9
10
|
|
|
10
11
|
/*
|
|
11
12
|
* Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
|
|
@@ -32,6 +33,8 @@
|
|
|
32
33
|
width: { type: "fill" },
|
|
33
34
|
height: { type: "fill" },
|
|
34
35
|
},
|
|
36
|
+
padding: DEFAULT_SPACING,
|
|
37
|
+
margin: DEFAULT_SPACING,
|
|
35
38
|
},
|
|
36
39
|
parameters: {
|
|
37
40
|
localizations: {
|
|
@@ -88,6 +91,109 @@
|
|
|
88
91
|
}}
|
|
89
92
|
/>
|
|
90
93
|
|
|
94
|
+
<Story
|
|
95
|
+
name="Linear gradeint"
|
|
96
|
+
decorators={[
|
|
97
|
+
localizationDecorator({
|
|
98
|
+
defaultLocale,
|
|
99
|
+
localizations: { [defaultLocale]: { [text_lid]: "Linear gradient" } },
|
|
100
|
+
}),
|
|
101
|
+
]}
|
|
102
|
+
args={{
|
|
103
|
+
color: {
|
|
104
|
+
light: {
|
|
105
|
+
degrees: 90,
|
|
106
|
+
points: [
|
|
107
|
+
{
|
|
108
|
+
color: "#e81c0fFF",
|
|
109
|
+
percent: 0,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
color: "#0029ffff",
|
|
113
|
+
percent: 100,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
type: "linear",
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
background_color: {
|
|
120
|
+
light: {
|
|
121
|
+
degrees: 90,
|
|
122
|
+
points: [
|
|
123
|
+
{
|
|
124
|
+
color: "#ffffffff",
|
|
125
|
+
percent: 0,
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
color: "#000000ff",
|
|
129
|
+
percent: 100,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
type: "linear",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
font_size: 48,
|
|
136
|
+
font_weight: "regular",
|
|
137
|
+
font_weight_int: 400,
|
|
138
|
+
horizontal_alignment: "leading",
|
|
139
|
+
size: {
|
|
140
|
+
width: { type: "fit" },
|
|
141
|
+
height: { type: "fit" },
|
|
142
|
+
},
|
|
143
|
+
}}
|
|
144
|
+
/>
|
|
145
|
+
|
|
146
|
+
<Story
|
|
147
|
+
name="Radial gradient"
|
|
148
|
+
decorators={[
|
|
149
|
+
localizationDecorator({
|
|
150
|
+
defaultLocale,
|
|
151
|
+
localizations: { [defaultLocale]: { [text_lid]: "Radial gradient" } },
|
|
152
|
+
}),
|
|
153
|
+
]}
|
|
154
|
+
args={{
|
|
155
|
+
color: {
|
|
156
|
+
light: {
|
|
157
|
+
points: [
|
|
158
|
+
{
|
|
159
|
+
color: "#3bf60cff",
|
|
160
|
+
percent: 23,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
color: "#e40fe8ff",
|
|
164
|
+
percent: 100,
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
type: "radial",
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
background_color: {
|
|
171
|
+
light: {
|
|
172
|
+
degrees: 90,
|
|
173
|
+
points: [
|
|
174
|
+
{
|
|
175
|
+
color: "#ffffffff",
|
|
176
|
+
percent: 0,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
color: "#000000ff",
|
|
180
|
+
percent: 100,
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
type: "linear",
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
font_size: 48,
|
|
187
|
+
font_weight: "regular",
|
|
188
|
+
font_weight_int: 400,
|
|
189
|
+
horizontal_alignment: "leading",
|
|
190
|
+
size: {
|
|
191
|
+
width: { type: "fit" },
|
|
192
|
+
height: { type: "fit" },
|
|
193
|
+
},
|
|
194
|
+
}}
|
|
195
|
+
/>
|
|
196
|
+
|
|
91
197
|
<Story
|
|
92
198
|
name="With Spacing"
|
|
93
199
|
args={{
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import Text from "./Text.svelte";
|
|
8
8
|
import { getColorModeContext } from "../../stores/color-mode";
|
|
9
9
|
import { getLocalizationContext } from "../../stores/localization";
|
|
10
|
+
import { getPaywallContext } from "../../stores/paywall";
|
|
10
11
|
import { getSelectedStateContext } from "../../stores/selected";
|
|
11
12
|
import { getVariablesContext } from "../../stores/variables";
|
|
12
13
|
import type { TextNodeProps } from "../../types/components/text";
|
|
@@ -26,8 +27,9 @@
|
|
|
26
27
|
const getColorMode = getColorModeContext();
|
|
27
28
|
const colorMode = $derived(getColorMode());
|
|
28
29
|
|
|
29
|
-
const {
|
|
30
|
-
|
|
30
|
+
const { uiConfig } = getPaywallContext();
|
|
31
|
+
let textStyles = $derived(
|
|
32
|
+
getTextComponentStyles(colorMode, actualProps, uiConfig.app.fonts),
|
|
31
33
|
);
|
|
32
34
|
|
|
33
35
|
const wrapperStyles = $derived(
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
</script>
|
|
50
52
|
|
|
51
53
|
<span style={wrapperStyles}>
|
|
52
|
-
<Text style={textStyles} component=
|
|
54
|
+
<Text style={textStyles} component="span">
|
|
53
55
|
{@html markdownParsed}
|
|
54
56
|
</Text>
|
|
55
57
|
</span>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ColorMode, type SizeType } from "../../types";
|
|
2
2
|
import type { ColorGradientScheme, ColorScheme } from "../../types/colors";
|
|
3
3
|
import type { TextNodeProps } from "../../types/components/text";
|
|
4
|
+
import type { AppFontsConfig } from "../../types/ui-config";
|
|
5
|
+
import { type CSS } from "../../utils/base-utils";
|
|
4
6
|
export declare const defaultColor: ColorScheme;
|
|
7
|
+
export declare function mapTextColor(colorMode: ColorMode, scheme: ColorGradientScheme): CSS;
|
|
5
8
|
/**
|
|
6
9
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
7
10
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
8
11
|
* @returns Object containing text inline styles and the appropriate HTML tag to render
|
|
9
12
|
*/
|
|
10
|
-
export declare const getTextComponentStyles: (colorMode: ColorMode, props: TextNodeProps) =>
|
|
11
|
-
textStyles: string;
|
|
12
|
-
tagToRender: string;
|
|
13
|
-
};
|
|
13
|
+
export declare const getTextComponentStyles: (colorMode: ColorMode, props: TextNodeProps, fonts: AppFontsConfig) => string;
|
|
14
14
|
export declare function getTextWrapperInlineStyles(colorMode: ColorMode, _restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorGradientScheme | null): string;
|
|
15
15
|
export declare function getHtmlFromMarkdown(text?: string): string;
|
|
@@ -1,38 +1,53 @@
|
|
|
1
|
+
import { FontSizes, FontWeights, TextAlignments, } from "../../types";
|
|
1
2
|
import { mapBackground } from "../../utils/background-utils";
|
|
2
|
-
import { css,
|
|
3
|
+
import { css, mapColorInfo, mapColorMode, mapSize, mapSpacing, } from "../../utils/base-utils";
|
|
3
4
|
import { DEFAULT_TEXT_COLOR } from "../../utils/constants";
|
|
4
|
-
import {
|
|
5
|
+
import { getScopedFontFamily, isFontRCFMManaged } from "../../utils/font-utils";
|
|
5
6
|
export const defaultColor = {
|
|
6
7
|
light: { type: "hex", value: DEFAULT_TEXT_COLOR },
|
|
7
8
|
};
|
|
9
|
+
export function mapTextColor(colorMode, scheme) {
|
|
10
|
+
const info = mapColorMode(colorMode, scheme);
|
|
11
|
+
const color = mapColorInfo(info);
|
|
12
|
+
switch (info.type) {
|
|
13
|
+
case "alias":
|
|
14
|
+
case "hex":
|
|
15
|
+
return { color };
|
|
16
|
+
case "linear":
|
|
17
|
+
case "radial":
|
|
18
|
+
return {
|
|
19
|
+
color: "transparent",
|
|
20
|
+
background: color,
|
|
21
|
+
"-webkit-background-clip": "text",
|
|
22
|
+
"background-clip": "text",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
8
26
|
/**
|
|
9
27
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
10
28
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
11
29
|
* @returns Object containing text inline styles and the appropriate HTML tag to render
|
|
12
30
|
*/
|
|
13
|
-
export const getTextComponentStyles = (colorMode, props) => {
|
|
14
|
-
const { color = defaultColor,
|
|
15
|
-
const
|
|
16
|
-
const
|
|
31
|
+
export const getTextComponentStyles = (colorMode, props, fonts) => {
|
|
32
|
+
const { font_name, font_size, font_weight, font_weight_int, horizontal_alignment, color = defaultColor, padding, margin, size, } = props;
|
|
33
|
+
const font = fonts[font_name ?? ""];
|
|
34
|
+
const fontFamily = font?.web?.family;
|
|
35
|
+
return css({
|
|
17
36
|
display: "block",
|
|
18
37
|
width: mapSize(size.width),
|
|
19
38
|
height: mapSize(size.height),
|
|
20
39
|
margin: mapSpacing(margin),
|
|
21
40
|
padding: mapSpacing(padding),
|
|
22
|
-
...
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"font-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
...mapTextColor(colorMode, color),
|
|
42
|
+
"text-align": TextAlignments[horizontal_alignment] || TextAlignments.leading,
|
|
43
|
+
"font-weight": font_weight_int ?? FontWeights[font_weight] ?? FontWeights.regular,
|
|
44
|
+
"font-size": Number.isInteger(Number(font_size))
|
|
45
|
+
? `${font_size}px`
|
|
46
|
+
: FontSizes[font_size] || FontSizes.body_m,
|
|
47
|
+
"font-family": isFontRCFMManaged(font_name ?? "")
|
|
48
|
+
? getScopedFontFamily(fontFamily ?? "")
|
|
49
|
+
: "sans-serif",
|
|
31
50
|
});
|
|
32
|
-
return {
|
|
33
|
-
textStyles: style,
|
|
34
|
-
tagToRender: "span",
|
|
35
|
-
};
|
|
36
51
|
};
|
|
37
52
|
export function getTextWrapperInlineStyles(colorMode, _restProps, size, background_color) {
|
|
38
53
|
return css({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { getTimelineItemContentInlineStyles } from "./timeline-utils";
|
|
3
|
-
import type { TimelineItemProps } from "../../types/components/timeline";
|
|
4
3
|
import { getColorModeContext } from "../../stores/color-mode";
|
|
5
|
-
import { getColor, getActiveStateProps } from "../../utils/style-utils";
|
|
6
4
|
import { getSelectedStateContext } from "../../stores/selected";
|
|
5
|
+
import type { TimelineItemProps } from "../../types/components/timeline";
|
|
6
|
+
import { css, mapColor } from "../../utils/base-utils";
|
|
7
|
+
import { getActiveStateProps } from "../../utils/style-utils";
|
|
7
8
|
import Icon from "../icon/Icon.svelte";
|
|
8
|
-
import { css } from "../../utils/base-utils";
|
|
9
9
|
import TextNode from "../text/TextNode.svelte";
|
|
10
10
|
|
|
11
11
|
interface Props extends TimelineItemProps {
|
|
@@ -64,11 +64,7 @@
|
|
|
64
64
|
const connectorBarStyles = $derived.by(() => {
|
|
65
65
|
if (!connector) return "";
|
|
66
66
|
|
|
67
|
-
const background =
|
|
68
|
-
colorMap: connector.color,
|
|
69
|
-
colorMode,
|
|
70
|
-
fallback: "#000000",
|
|
71
|
-
});
|
|
67
|
+
const background = mapColor(colorMode, connector.color);
|
|
72
68
|
|
|
73
69
|
return css({
|
|
74
70
|
width: "100%",
|
package/dist/stores/paywall.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ type PaywallContext = Readonly<{
|
|
|
6
6
|
selectedPackageId: Writable<string | undefined>;
|
|
7
7
|
variablesPerPackage: Readable<Record<string, VariableDictionary> | undefined>;
|
|
8
8
|
onPurchase: () => void;
|
|
9
|
-
onButtonAction: (action: Action) => void;
|
|
9
|
+
onButtonAction: (action: Action, actionId?: string) => void;
|
|
10
10
|
uiConfig: UIConfig;
|
|
11
11
|
}>;
|
|
12
12
|
export declare function setPaywallContext(context: PaywallContext): void;
|
|
@@ -17,7 +17,7 @@ export function paywallDecorator() {
|
|
|
17
17
|
selectedPackageId,
|
|
18
18
|
variablesPerPackage: readable(undefined),
|
|
19
19
|
onPurchase: () => window.alert("Purchase clicked"),
|
|
20
|
-
onButtonAction: (action) => window.alert(`Button clicked: ${JSON.stringify(action, undefined, 2)}`),
|
|
20
|
+
onButtonAction: (action, actionId) => window.alert(`Button clicked: ${JSON.stringify({ action, actionId }, undefined, 2)}`),
|
|
21
21
|
uiConfig: emptyUiConfig,
|
|
22
22
|
});
|
|
23
23
|
return Story();
|
package/dist/types/base.d.ts
CHANGED
|
@@ -2,6 +2,9 @@ import type { BaseComponent } from "../base";
|
|
|
2
2
|
import type { Overrides } from "../overrides";
|
|
3
3
|
import type { SheetProps } from "./sheet";
|
|
4
4
|
import type { StackProps } from "./stack";
|
|
5
|
+
interface WorkflowAction {
|
|
6
|
+
type: "workflow";
|
|
7
|
+
}
|
|
5
8
|
interface RestorePurchasesAction {
|
|
6
9
|
type: "restore_purchases";
|
|
7
10
|
}
|
|
@@ -31,12 +34,15 @@ interface NavigateToUrlAction {
|
|
|
31
34
|
method: "deep_link" | "external_browser" | "in_app_browser";
|
|
32
35
|
};
|
|
33
36
|
}
|
|
34
|
-
export type Action = RestorePurchasesAction | NavigateBackAction | NavigateToAction | NavigateToSheetAction | NavigateToWebPurchase | NavigateToUrlAction;
|
|
37
|
+
export type Action = WorkflowAction | RestorePurchasesAction | NavigateBackAction | NavigateToAction | NavigateToSheetAction | NavigateToWebPurchase | NavigateToUrlAction;
|
|
35
38
|
export interface ButtonProps extends BaseComponent {
|
|
36
39
|
type: "button";
|
|
37
40
|
action: Action;
|
|
38
41
|
stack: StackProps;
|
|
39
42
|
transition?: null;
|
|
43
|
+
triggers?: {
|
|
44
|
+
on_press?: string;
|
|
45
|
+
};
|
|
40
46
|
overrides?: Overrides<ButtonProps>;
|
|
41
47
|
}
|
|
42
48
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FontSizes, FontWeights, SizeType, Spacing, TextAlignments } from "..";
|
|
2
2
|
import type { BaseComponent } from "../base";
|
|
3
|
-
import type { ColorGradientScheme
|
|
3
|
+
import type { ColorGradientScheme } from "../colors";
|
|
4
4
|
import type { Overrides } from "../overrides";
|
|
5
5
|
export interface TextNodeProps extends BaseComponent {
|
|
6
6
|
text_lid: string;
|
|
@@ -9,7 +9,7 @@ export interface TextNodeProps extends BaseComponent {
|
|
|
9
9
|
font_weight: keyof typeof FontWeights;
|
|
10
10
|
font_weight_int?: number;
|
|
11
11
|
horizontal_alignment: keyof typeof TextAlignments;
|
|
12
|
-
color:
|
|
12
|
+
color: ColorGradientScheme;
|
|
13
13
|
background_color?: ColorGradientScheme | null;
|
|
14
14
|
type: "text";
|
|
15
15
|
visible?: boolean | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BorderType, CircleShape, ColorMode, ConcaveShape, ConvexShape, PillShape, RectangleShape, ShadowType, Size, Spacing } from "../types";
|
|
2
|
-
import type { ColorGradientScheme, ColorScheme } from "../types/colors";
|
|
2
|
+
import type { ColorGradientInfo, ColorGradientScheme, ColorScheme } from "../types/colors";
|
|
3
3
|
import type { FitMode } from "../types/media";
|
|
4
4
|
export type CSS = Record<string, string | number>;
|
|
5
5
|
export declare function css(props: CSS): string;
|
|
@@ -10,6 +10,7 @@ export declare function mapColorMode<T>(colorMode: ColorMode, value: {
|
|
|
10
10
|
}): T;
|
|
11
11
|
export declare function mapSize(size: Size): string;
|
|
12
12
|
export declare function mapSpacing(spacing?: Spacing | null): string;
|
|
13
|
+
export declare function mapColorInfo(info: ColorGradientInfo): string;
|
|
13
14
|
export declare function mapColor(colorMode: ColorMode, scheme: ColorScheme | ColorGradientScheme | null | undefined): string;
|
|
14
15
|
export declare function mapOverlay(colorMode: ColorMode, colorOverlay: ColorGradientScheme | null | undefined): string;
|
|
15
16
|
export declare function mapBorder(colorMode: ColorMode, border: BorderType | null | undefined): string;
|
package/dist/utils/base-utils.js
CHANGED
|
@@ -37,7 +37,7 @@ export function mapSpacing(spacing) {
|
|
|
37
37
|
const { top, bottom, leading, trailing } = spacing ?? DEFAULT_SPACING;
|
|
38
38
|
return mapTuple(top, trailing, bottom, leading);
|
|
39
39
|
}
|
|
40
|
-
function mapColorInfo(info) {
|
|
40
|
+
export function mapColorInfo(info) {
|
|
41
41
|
if (info.type === "alias" || info.type === "hex") {
|
|
42
42
|
return info.value;
|
|
43
43
|
}
|
|
@@ -1,35 +1,6 @@
|
|
|
1
|
-
import type { ColorGradientScheme } from "../types/colors.js";
|
|
2
1
|
import type { Component } from "../types/component.js";
|
|
3
|
-
import type { TextNodeProps } from "../types/components/text";
|
|
4
2
|
import type { Overrides } from "../types/overrides.js";
|
|
5
3
|
import type { RootPaywall } from "../types/paywall.js";
|
|
6
|
-
import { type ColorMode } from "../types.js";
|
|
7
|
-
/**
|
|
8
|
-
* Gets color value based on color mode with fallback
|
|
9
|
-
* @param params - Object containing color map, mode and fallback color
|
|
10
|
-
* @returns Color value as string
|
|
11
|
-
*/
|
|
12
|
-
export declare function getColor({ colorMap, colorMode, fallback, }: {
|
|
13
|
-
colorMap?: ColorGradientScheme | null;
|
|
14
|
-
colorMode?: ColorMode;
|
|
15
|
-
fallback?: string;
|
|
16
|
-
}): string;
|
|
17
|
-
type TextStyleVariables = {
|
|
18
|
-
"--text-align": string;
|
|
19
|
-
"--font-weight": number | string;
|
|
20
|
-
"--font-size": string;
|
|
21
|
-
"--font-family": string;
|
|
22
|
-
"--background-clip": string;
|
|
23
|
-
"--text-fill-color": string;
|
|
24
|
-
"--background": string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Generates text-related styles
|
|
28
|
-
* @param props - Text component properties
|
|
29
|
-
* @param colorMode - The currently selected ColorMode (dark/light)
|
|
30
|
-
* @returns CSS style object with text formatting properties
|
|
31
|
-
*/
|
|
32
|
-
export declare function getTextStyles(props: TextNodeProps): TextStyleVariables;
|
|
33
4
|
/**
|
|
34
5
|
* Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
|
|
35
6
|
* @param paywallData
|
|
@@ -37,4 +8,3 @@ export declare function getTextStyles(props: TextNodeProps): TextStyleVariables;
|
|
|
37
8
|
*/
|
|
38
9
|
export declare function findSelectedPackageId({ stack, sticky_footer, }: RootPaywall): string | undefined;
|
|
39
10
|
export declare const getActiveStateProps: <T extends Component>(selectedState: boolean, overrides?: Overrides<T>) => Partial<T>;
|
|
40
|
-
export {};
|
|
@@ -1,69 +1,3 @@
|
|
|
1
|
-
import { getPaywallContext } from "../stores/paywall.js";
|
|
2
|
-
import { DEFAULT_COLOR_MODE } from "./constants.js";
|
|
3
|
-
import { FontSizes, FontWeights, TextAlignments, } from "../types.js";
|
|
4
|
-
import { getScopedFontFamily, isFontRCFMManaged } from "./font-utils.js";
|
|
5
|
-
/**
|
|
6
|
-
* Gets color value based on color mode with fallback
|
|
7
|
-
* @param params - Object containing color map, mode and fallback color
|
|
8
|
-
* @returns Color value as string
|
|
9
|
-
*/
|
|
10
|
-
export function getColor({ colorMap, colorMode = DEFAULT_COLOR_MODE, fallback = "FFFFFF", }) {
|
|
11
|
-
if (!colorMap)
|
|
12
|
-
return fallback;
|
|
13
|
-
const color = colorMap[colorMode] || colorMap[DEFAULT_COLOR_MODE];
|
|
14
|
-
let colorPoints = "";
|
|
15
|
-
switch (color?.type) {
|
|
16
|
-
case "hex":
|
|
17
|
-
case "alias":
|
|
18
|
-
return color.value ?? fallback;
|
|
19
|
-
case "linear":
|
|
20
|
-
colorPoints = (color.points || [])
|
|
21
|
-
.map((point) => `${point.color} ${point.percent}%`)
|
|
22
|
-
.join(", ");
|
|
23
|
-
return `linear-gradient(${color.degrees}deg, ${colorPoints})`;
|
|
24
|
-
case "radial":
|
|
25
|
-
colorPoints = (color.points || [])
|
|
26
|
-
.map((point) => `${point.color} ${point.percent}%`)
|
|
27
|
-
.join(", ");
|
|
28
|
-
return `radial-gradient(${colorPoints})`;
|
|
29
|
-
default:
|
|
30
|
-
return fallback;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Generates text-related styles
|
|
35
|
-
* @param props - Text component properties
|
|
36
|
-
* @param colorMode - The currently selected ColorMode (dark/light)
|
|
37
|
-
* @returns CSS style object with text formatting properties
|
|
38
|
-
*/
|
|
39
|
-
export function getTextStyles(props) {
|
|
40
|
-
const { font_size, horizontal_alignment, font_weight, font_name, font_weight_int, } = props;
|
|
41
|
-
const paywall = getPaywallContext();
|
|
42
|
-
const uiConfig = paywall.uiConfig;
|
|
43
|
-
const { fonts } = uiConfig.app;
|
|
44
|
-
const font = fonts[font_name ?? ""];
|
|
45
|
-
const fontFamily = font?.web?.family;
|
|
46
|
-
const styles = {
|
|
47
|
-
"--text-align": "initial",
|
|
48
|
-
"--font-weight": "initial",
|
|
49
|
-
"--font-size": "initial",
|
|
50
|
-
"--font-family": "sans-serif",
|
|
51
|
-
"--background-clip": "none",
|
|
52
|
-
"--text-fill-color": "none",
|
|
53
|
-
"--background": "unset",
|
|
54
|
-
};
|
|
55
|
-
Object.assign(styles, {
|
|
56
|
-
"--text-align": TextAlignments[horizontal_alignment] || TextAlignments.leading,
|
|
57
|
-
"--font-weight": font_weight_int ?? FontWeights[font_weight] ?? FontWeights.regular,
|
|
58
|
-
"--font-size": Number.isInteger(Number(font_size))
|
|
59
|
-
? `${font_size}px`
|
|
60
|
-
: FontSizes[font_size] || FontSizes.body_m,
|
|
61
|
-
"--font-family": isFontRCFMManaged(font_name ?? "")
|
|
62
|
-
? getScopedFontFamily(fontFamily ?? "")
|
|
63
|
-
: "sans-serif",
|
|
64
|
-
});
|
|
65
|
-
return styles;
|
|
66
|
-
}
|
|
67
1
|
/**
|
|
68
2
|
* Given an instance of PaywallData, returns the id of the first package marked as `is_selected_by_default` if any.
|
|
69
3
|
* @param paywallData
|