@revenuecat/purchases-ui-js 2.0.2 → 2.0.4
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 +66 -102
- package/dist/components/button/ButtonNode.svelte +18 -26
- package/dist/components/carousel/Carousel.stories.svelte +1039 -0
- package/dist/components/carousel/Carousel.stories.svelte.d.ts +19 -0
- package/dist/components/carousel/Carousel.svelte +298 -0
- package/dist/components/carousel/Carousel.svelte.d.ts +4 -0
- package/dist/components/carousel/CarouselPage.svelte +39 -0
- package/dist/components/carousel/CarouselPage.svelte.d.ts +11 -0
- package/dist/components/carousel/PageControl.svelte +93 -0
- package/dist/components/carousel/PageControl.svelte.d.ts +4 -0
- package/dist/components/carousel/carousel-utils.d.ts +4 -0
- package/dist/components/carousel/carousel-utils.js +21 -0
- package/dist/components/footer/Footer.stories.svelte +112 -102
- package/dist/components/footer/Footer.svelte +8 -4
- package/dist/components/icon/Icon.stories.svelte +100 -0
- package/dist/components/icon/Icon.stories.svelte.d.ts +19 -0
- package/dist/components/icon/Icon.svelte +73 -0
- package/dist/components/icon/Icon.svelte.d.ts +4 -0
- package/dist/components/image/ClipPath.svelte +49 -0
- package/dist/components/image/ClipPath.svelte.d.ts +9 -0
- package/dist/components/image/Image.stories.svelte +83 -188
- package/dist/components/image/Image.svelte +152 -136
- package/dist/components/image/Image.svelte.d.ts +1 -1
- package/dist/components/image/Overlay.svelte +36 -0
- package/dist/components/image/Overlay.svelte.d.ts +8 -0
- package/dist/components/package/Package.stories.svelte +10 -21
- package/dist/components/package/Package.svelte +8 -35
- package/dist/components/paywall/Node.svelte +25 -32
- package/dist/components/paywall/Node.svelte.d.ts +4 -6
- package/dist/components/paywall/Paywall.stories.svelte +36 -140
- package/dist/components/paywall/Paywall.svelte +23 -7
- package/dist/components/paywall/Paywall.svelte.d.ts +4 -2
- package/dist/components/paywall/fixtures/override-paywall.d.ts +2 -0
- package/dist/components/paywall/fixtures/override-paywall.js +1310 -0
- package/dist/components/paywall/fixtures/stack-paywall.d.ts +2 -0
- package/dist/components/paywall/fixtures/stack-paywall.js +5223 -0
- package/dist/components/paywall/fixtures/variables.d.ts +261 -0
- package/dist/components/paywall/fixtures/variables.js +262 -0
- package/dist/components/paywall/paywall-utils.d.ts +1 -1
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +10 -21
- package/dist/components/purchase-button/PurchaseButton.svelte +2 -27
- package/dist/components/stack/Stack.stories.svelte +2354 -978
- package/dist/components/stack/Stack.svelte +116 -134
- package/dist/components/stack/Stack.svelte.d.ts +8 -2
- package/dist/components/stack/stack-utils.d.ts +10 -30
- package/dist/components/stack/stack-utils.js +77 -255
- package/dist/components/text/Text.svelte +3 -37
- package/dist/components/text/Text.svelte.d.ts +1 -2
- package/dist/components/text/TextNode.stories.svelte +10 -36
- package/dist/components/text/TextNode.svelte +25 -28
- package/dist/components/text/TextNode.svelte.d.ts +1 -1
- package/dist/components/text/text-utils.d.ts +4 -9
- package/dist/components/text/text-utils.js +32 -117
- package/dist/components/timeline/Timeline.stories.svelte +640 -251
- package/dist/components/timeline/Timeline.svelte +42 -28
- package/dist/components/timeline/Timeline.svelte.d.ts +1 -1
- package/dist/components/timeline/TimelineItem.svelte +80 -112
- package/dist/components/timeline/TimelineItem.svelte.d.ts +6 -2
- package/dist/components/timeline/timeline-utils.d.ts +24 -6
- package/dist/components/timeline/timeline-utils.js +21 -113
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/stores/color-mode.d.ts +1 -1
- package/dist/stores/paywall.d.ts +5 -2
- package/dist/stores/selected.d.ts +5 -0
- package/dist/stores/selected.js +12 -0
- package/dist/stores/variables.d.ts +1 -1
- package/dist/stores/variables.js +0 -1
- package/dist/stories/component-decorator.d.ts +2 -0
- package/dist/stories/component-decorator.js +12 -0
- package/dist/stories/fixtures.d.ts +6 -3
- package/dist/stories/fixtures.js +5214 -4422
- package/dist/stories/paywall-decorator.js +6 -0
- package/dist/stories/variables-decorator.d.ts +1 -1
- package/dist/stories/viewport-decorator.d.ts +2 -0
- package/dist/stories/viewport-decorator.js +8 -0
- package/dist/stories/viewport-wrapper.svelte +55 -0
- package/dist/stories/viewport-wrapper.svelte.d.ts +10 -0
- package/dist/stories/with-layout.d.ts +2 -10
- package/dist/stories/with-layout.js +3 -5
- package/dist/types/alignment.d.ts +5 -3
- package/dist/types/background.d.ts +6 -5
- package/dist/types/base.d.ts +7 -0
- package/dist/types/colors.d.ts +4 -4
- package/dist/types/component.d.ts +7 -2
- package/dist/types/components/button.d.ts +6 -1
- package/dist/types/components/carousel.d.ts +51 -0
- package/dist/types/components/carousel.js +1 -0
- package/dist/types/components/footer.d.ts +2 -1
- package/dist/types/components/icon.d.ts +28 -0
- package/dist/types/components/icon.js +1 -0
- package/dist/types/components/image.d.ts +20 -0
- package/dist/types/components/image.js +1 -0
- package/dist/types/components/package.d.ts +2 -1
- package/dist/types/components/purchase-button.d.ts +2 -1
- package/dist/types/components/stack.d.ts +32 -0
- package/dist/types/components/stack.js +1 -0
- package/dist/types/components/text.d.ts +20 -0
- package/dist/types/components/text.js +1 -0
- package/dist/types/components/timeline.d.ts +35 -0
- package/dist/types/components/timeline.js +1 -0
- package/dist/types/localization.d.ts +2 -1
- package/dist/types/media.d.ts +4 -3
- package/dist/types/overrides.d.ts +48 -0
- package/dist/types/overrides.js +1 -0
- package/dist/types/paywall.d.ts +27 -0
- package/dist/types/paywall.js +1 -0
- package/dist/types/ui-config.d.ts +20 -0
- package/dist/types/ui-config.js +1 -0
- package/dist/types/variables.d.ts +13 -0
- package/dist/types/variables.js +10 -0
- package/dist/types.d.ts +17 -9
- package/dist/ui/atoms/typography.stories.svelte +1 -27
- package/dist/ui/molecules/button.stories.svelte +3 -8
- package/dist/ui/theme/colors.d.ts +0 -6
- package/dist/ui/theme/colors.js +1 -1
- package/dist/ui/theme/text.d.ts +3 -4
- package/dist/ui/theme/utils.d.ts +0 -10
- package/dist/ui/theme/utils.js +5 -5
- package/dist/utils/background-utils.d.ts +4 -0
- package/dist/utils/background-utils.js +39 -0
- package/dist/utils/base-utils.d.ts +18 -0
- package/dist/utils/base-utils.js +124 -0
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +6 -1
- package/dist/utils/font-utils.d.ts +4 -0
- package/dist/utils/font-utils.js +47 -0
- package/dist/utils/style-utils.d.ts +7 -120
- package/dist/utils/style-utils.js +29 -304
- package/dist/utils/variable-utils.d.ts +1 -22
- package/dist/utils/variable-utils.js +28 -24
- package/dist/web-components/index.css +1 -1
- package/dist/web-components/index.js +1435 -980
- package/package.json +36 -26
- package/dist/components/button/button-utils.d.ts +0 -2
- package/dist/components/button/button-utils.js +0 -19
- package/dist/components/image/image-utils.d.ts +0 -19
- package/dist/components/image/image-utils.js +0 -33
- package/dist/components/purchase-button/purchase-button-utils.d.ts +0 -2
- package/dist/components/purchase-button/purchase-button-utils.js +0 -20
- package/dist/data/entities.d.ts +0 -162
- package/dist/stories/meta-templates.d.ts +0 -12
- package/dist/stories/meta-templates.js +0 -155
- /package/dist/{data/entities.js → types/base.js} +0 -0
|
@@ -1,261 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"--margin-block-end": "0px",
|
|
21
|
-
"--margin-inline-start": "0px",
|
|
22
|
-
"--padding-block-start": "0px",
|
|
23
|
-
"--padding-inline-end": "0px",
|
|
24
|
-
"--padding-block-end": "0px",
|
|
25
|
-
"--padding-inline-start": "0px",
|
|
26
|
-
"--background": "unset",
|
|
27
|
-
"--text-color": "inherit",
|
|
28
|
-
"--border": "none",
|
|
29
|
-
"--border-end-start-radius": "0px",
|
|
30
|
-
"--border-end-end-radius": "0px",
|
|
31
|
-
"--border-start-start-radius": "0px",
|
|
32
|
-
"--border-start-end-radius": "0px",
|
|
33
|
-
"--shadow": "none",
|
|
34
|
-
"--position": "relative",
|
|
35
|
-
"--transform": "initial",
|
|
36
|
-
"--inset": "initial",
|
|
37
|
-
};
|
|
38
|
-
const activeStateProps = getActiveStateProps(overrides, componentState);
|
|
39
|
-
Object.assign(stackStyles, getComponentStyles({
|
|
40
|
-
background_color,
|
|
41
|
-
margin,
|
|
42
|
-
padding,
|
|
43
|
-
border,
|
|
44
|
-
colorMode,
|
|
45
|
-
shape,
|
|
46
|
-
shadow,
|
|
47
|
-
...activeStateProps,
|
|
48
|
-
}), getDimensionStyle({
|
|
49
|
-
...dimension,
|
|
50
|
-
...activeStateProps,
|
|
51
|
-
}), getSizeStyle({ ...size, ...activeStateProps }));
|
|
52
|
-
Object.assign(stackStyles, zStackChildStyles);
|
|
53
|
-
const prefixedStyles = prefixObject(stackStyles, "stack");
|
|
54
|
-
return stringifyStyles(prefixedStyles);
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Generates styles for badge component within a stack
|
|
58
|
-
* @param props - Stack component properties containing badge configuration
|
|
59
|
-
* @returns CSS style object with badge-specific styles including positioning, dimensions and appearance
|
|
60
|
-
*/
|
|
61
|
-
export function getBadgeStyles(colorMode, props) {
|
|
62
|
-
const { badge } = props;
|
|
63
|
-
if (!badge)
|
|
64
|
-
return "";
|
|
65
|
-
const styles = {
|
|
66
|
-
"--inset": "unset",
|
|
67
|
-
"--transform": "unset",
|
|
68
|
-
"--margin-block-start": "0px",
|
|
69
|
-
"--margin-inline-end": "0px",
|
|
70
|
-
"--margin-block-end": "0px",
|
|
71
|
-
"--margin-inline-start": "0px",
|
|
72
|
-
"--padding-block-start": "0px",
|
|
73
|
-
"--padding-inline-end": "0px",
|
|
74
|
-
"--padding-block-end": "0px",
|
|
75
|
-
"--padding-inline-start": "0px",
|
|
76
|
-
"--background": "unset",
|
|
77
|
-
"--text-color": "inherit",
|
|
78
|
-
"--border": "none",
|
|
79
|
-
"--border-end-start-radius": "0px",
|
|
80
|
-
"--border-end-end-radius": "0px",
|
|
81
|
-
"--border-start-start-radius": "0px",
|
|
82
|
-
"--border-start-end-radius": "0px",
|
|
83
|
-
"--shadow": "none",
|
|
84
|
-
"--badge-width": "unset",
|
|
85
|
-
"--z-index": "unset",
|
|
86
|
-
};
|
|
87
|
-
// Calculating this as a zIndex alignment since it behaves in the same way
|
|
88
|
-
// except there's no center alignment
|
|
89
|
-
Object.assign(styles, getInsetStyles({
|
|
90
|
-
type: "zlayer",
|
|
91
|
-
alignment: badge.alignment,
|
|
92
|
-
}), getComponentStyles({
|
|
93
|
-
...badge,
|
|
94
|
-
background_color: badge.background_color,
|
|
95
|
-
color: badge.color,
|
|
96
|
-
colorMode,
|
|
97
|
-
}));
|
|
98
|
-
if (badge.style === "overlay") {
|
|
99
|
-
// Disable vertical margin for nested & center aligned badges
|
|
100
|
-
styles["--margin-block-start"] = "0px";
|
|
101
|
-
styles["--margin-block-end"] = "0px";
|
|
102
|
-
// Vertically center the badge to the edge of the stack
|
|
103
|
-
styles["--transform"] = getBadgeTransformStyles(badge, 0, -(props.border?.width || 0));
|
|
1
|
+
import { px } from "../../utils/base-utils";
|
|
2
|
+
const ALIGNMENT_MAP = Object.freeze({
|
|
3
|
+
leading: "flex-start",
|
|
4
|
+
top: "flex-start",
|
|
5
|
+
center: "center",
|
|
6
|
+
trailing: "flex-end",
|
|
7
|
+
bottom: "flex-end",
|
|
8
|
+
});
|
|
9
|
+
const DISTRIBUTION_MAP = Object.freeze({
|
|
10
|
+
space_between: "space-between",
|
|
11
|
+
space_around: "space-around",
|
|
12
|
+
space_evenly: "space-evenly",
|
|
13
|
+
start: "flex-start",
|
|
14
|
+
center: "center",
|
|
15
|
+
end: "flex-end",
|
|
16
|
+
});
|
|
17
|
+
export function mapDimension(dimension) {
|
|
18
|
+
if (dimension.type === "zlayer") {
|
|
19
|
+
return {};
|
|
104
20
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
styles["--badge-width"] =
|
|
113
|
-
`calc(100% + ${(props.border?.width || 0) * 2}px)`;
|
|
114
|
-
styles["--z-index"] = "-1";
|
|
115
|
-
const highestRadius = Math.max(props.shape?.corners?.top_leading || 0, props.shape?.corners?.top_trailing || 0);
|
|
116
|
-
// one offs for top and bottom
|
|
117
|
-
if (badge.alignment === "top") {
|
|
118
|
-
styles["--padding-block-end"] =
|
|
119
|
-
`${highestRadius + badge.padding.bottom}px`;
|
|
120
|
-
styles["--transform"] = getBadgeTransformStyles(badge, highestRadius);
|
|
121
|
-
}
|
|
122
|
-
if (badge.alignment === "bottom") {
|
|
123
|
-
styles["--padding-block-start"] =
|
|
124
|
-
`${highestRadius + badge.padding.top}px`;
|
|
125
|
-
styles["--transform"] = getBadgeTransformStyles(badge, -highestRadius);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
styles["--transform"] = getBadgeTransformStyles(badge);
|
|
130
|
-
Object.assign(styles, getBadgeBorderRadiusStyles(props));
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const prefixedStyles = prefixObject(styles, "stack-badge");
|
|
134
|
-
return stringifyStyles(prefixedStyles);
|
|
135
|
-
}
|
|
136
|
-
const oppositeCornerDictionary = {
|
|
137
|
-
top_leading: "bottom_trailing",
|
|
138
|
-
top_trailing: "bottom_leading",
|
|
139
|
-
bottom_leading: "top_trailing",
|
|
140
|
-
bottom_trailing: "top_leading",
|
|
141
|
-
};
|
|
142
|
-
const propToCssPropDictionary = {
|
|
143
|
-
top_leading: "--border-start-start-radius",
|
|
144
|
-
top_trailing: "--border-start-end-radius",
|
|
145
|
-
bottom_leading: "--border-end-start-radius",
|
|
146
|
-
bottom_trailing: "--border-end-end-radius",
|
|
147
|
-
};
|
|
148
|
-
function getBadgeBorderRadiusStyles(props) {
|
|
149
|
-
const styles = {
|
|
150
|
-
"--border-end-start-radius": "0px",
|
|
151
|
-
"--border-end-end-radius": "0px",
|
|
152
|
-
"--border-start-start-radius": "0px",
|
|
153
|
-
"--border-start-end-radius": "0px",
|
|
21
|
+
const direction = dimension.type === "vertical" ? "column" : "row";
|
|
22
|
+
const justify = DISTRIBUTION_MAP[dimension.distribution] || "center";
|
|
23
|
+
const align = ALIGNMENT_MAP[dimension.alignment] || "center";
|
|
24
|
+
return {
|
|
25
|
+
"flex-direction": direction,
|
|
26
|
+
"justify-content": justify,
|
|
27
|
+
"align-items": align,
|
|
154
28
|
};
|
|
155
|
-
const { badge } = props;
|
|
156
|
-
if (!badge)
|
|
157
|
-
return styles;
|
|
158
|
-
const borderWidth = props.border?.width || 0;
|
|
159
|
-
const badgeAlignment = badge.alignment;
|
|
160
|
-
// badge inner radius
|
|
161
|
-
styles[propToCssPropDictionary[oppositeCornerDictionary[badgeAlignment]]] =
|
|
162
|
-
`${badge.shape?.corners[oppositeCornerDictionary[badgeAlignment]]}px`;
|
|
163
|
-
// badge outer radius
|
|
164
|
-
styles[propToCssPropDictionary[badgeAlignment]] =
|
|
165
|
-
`${props.shape?.corners[badgeAlignment] - borderWidth}px`;
|
|
166
|
-
return styles;
|
|
167
29
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return `translate(${horizontalOffset}px, calc(50% + ${verticalOffset}px))`;
|
|
186
|
-
}
|
|
187
|
-
if (badge.alignment === "bottom_trailing") {
|
|
188
|
-
return `translate(calc(0% - ${horizontalOffset}px), calc(50% + ${verticalOffset}px))`;
|
|
189
|
-
}
|
|
190
|
-
if (badge.alignment === "top") {
|
|
191
|
-
return `translate(calc(-50% + ${horizontalOffset}px), calc(-50% + ${verticalOffset}px))`;
|
|
192
|
-
}
|
|
193
|
-
if (badge.alignment === "bottom") {
|
|
194
|
-
return `translate(calc(50% + ${horizontalOffset}px), calc(50% + ${verticalOffset}px))`;
|
|
195
|
-
}
|
|
30
|
+
const Z_ALIGNMENT_MAP = Object.freeze({
|
|
31
|
+
top_leading: { justifyContent: "flex-start", alignItems: "flex-start" },
|
|
32
|
+
top: { justifyContent: "center", alignItems: "flex-start" },
|
|
33
|
+
top_trailing: { justifyContent: "flex-end", alignItems: "flex-start" },
|
|
34
|
+
leading: { justifyContent: "flex-start", alignItems: "center" },
|
|
35
|
+
center: { justifyContent: "center", alignItems: "center" },
|
|
36
|
+
trailing: { justifyContent: "flex-end", alignItems: "center" },
|
|
37
|
+
bottom_leading: { justifyContent: "flex-start", alignItems: "flex-end" },
|
|
38
|
+
bottom: { justifyContent: "center", alignItems: "flex-end" },
|
|
39
|
+
bottom_trailing: { justifyContent: "flex-end", alignItems: "flex-end" },
|
|
40
|
+
});
|
|
41
|
+
export function mapLayerAlignment(alignment) {
|
|
42
|
+
return Z_ALIGNMENT_MAP[alignment];
|
|
43
|
+
}
|
|
44
|
+
export function mapBadge(badge, parentBorderWidth) {
|
|
45
|
+
if (badge == null) {
|
|
46
|
+
return {};
|
|
196
47
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
48
|
+
const { style, alignment } = badge;
|
|
49
|
+
const isTop = alignment.startsWith("top");
|
|
50
|
+
const isLeading = alignment.endsWith("leading");
|
|
51
|
+
const isTrailing = alignment.endsWith("trailing");
|
|
52
|
+
const isCenter = !isLeading && !isTrailing;
|
|
53
|
+
const offset = parentBorderWidth ?? 0;
|
|
54
|
+
if (style === "overlay") {
|
|
55
|
+
const translateX = isCenter ? "translateX(-50%)" : "";
|
|
56
|
+
const translateY = isTop ? "translateY(-50%)" : "translateY(50%)";
|
|
57
|
+
return {
|
|
58
|
+
"z-index": 10,
|
|
59
|
+
position: "absolute",
|
|
60
|
+
width: "max-content",
|
|
61
|
+
top: isTop ? px(-offset / 2) : "initial",
|
|
62
|
+
bottom: !isTop ? px(-offset / 2) : "initial",
|
|
63
|
+
left: isLeading ? px(-offset) : isCenter ? "50%" : "initial",
|
|
64
|
+
right: isTrailing ? px(-offset) : "initial",
|
|
65
|
+
transform: `${translateX} ${translateY}`,
|
|
66
|
+
};
|
|
204
67
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
...badge,
|
|
221
|
-
type: "text",
|
|
222
|
-
size: {
|
|
223
|
-
width: { type: "fit" },
|
|
224
|
-
height: { type: "fit" },
|
|
225
|
-
},
|
|
226
|
-
color: badge?.color,
|
|
227
|
-
name: props.name,
|
|
228
|
-
});
|
|
229
|
-
const resetSpacing = {
|
|
230
|
-
"--text-margin-block-start": "0px",
|
|
231
|
-
"--text-margin-inline-end": "0px",
|
|
232
|
-
"--text-margin-block-end": "0px",
|
|
233
|
-
"--text-margin-inline-start": "0px",
|
|
234
|
-
"--text-padding-block-start": "0px",
|
|
235
|
-
"--text-padding-inline-end": "0px",
|
|
236
|
-
"--text-padding-block-end": "0px",
|
|
237
|
-
"--text-padding-inline-start": "0px",
|
|
238
|
-
};
|
|
239
|
-
const stylesObject = {
|
|
240
|
-
...textStyles,
|
|
241
|
-
...resetSpacing,
|
|
242
|
-
};
|
|
243
|
-
const stringifiedStyles = stringifyStyles(stylesObject);
|
|
244
|
-
return {
|
|
245
|
-
tagToRender,
|
|
246
|
-
textStyles: stringifiedStyles,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
export function getZStackChildStyles(props) {
|
|
250
|
-
const { dimension } = props;
|
|
251
|
-
const baseStyles = {
|
|
252
|
-
"--inset": "initial",
|
|
253
|
-
"--transform": "initial",
|
|
254
|
-
"--position": "relative",
|
|
255
|
-
};
|
|
256
|
-
if (dimension.type !== "zlayer")
|
|
257
|
-
return;
|
|
258
|
-
const insetStyles = getInsetStyles({ ...dimension, type: "zlayer" });
|
|
259
|
-
Object.assign(baseStyles, { ...insetStyles, "--position": "absolute" });
|
|
260
|
-
return baseStyles;
|
|
68
|
+
if (style === "nested") {
|
|
69
|
+
return {
|
|
70
|
+
"z-index": 10,
|
|
71
|
+
position: "absolute",
|
|
72
|
+
inset: 0,
|
|
73
|
+
display: "flex",
|
|
74
|
+
top: isTop ? px(offset) : "initial",
|
|
75
|
+
bottom: !isTop ? px(offset) : "initial",
|
|
76
|
+
left: isLeading ? px(offset) : isCenter ? "50%" : "initial",
|
|
77
|
+
right: isTrailing ? px(offset) : "initial",
|
|
78
|
+
transform: isCenter ? "translateX(-50%)" : "initial",
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
// Not supported yet.
|
|
82
|
+
return {};
|
|
261
83
|
}
|
|
@@ -3,47 +3,13 @@
|
|
|
3
3
|
|
|
4
4
|
interface TextProps {
|
|
5
5
|
component?: string;
|
|
6
|
-
|
|
7
|
-
id?: string;
|
|
6
|
+
style?: string;
|
|
8
7
|
children?: Snippet;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
const {
|
|
12
|
-
children,
|
|
13
|
-
styleVariables = "",
|
|
14
|
-
component = "p",
|
|
15
|
-
id,
|
|
16
|
-
}: TextProps = $props();
|
|
10
|
+
const { children, style = "", component = "p" }: TextProps = $props();
|
|
17
11
|
</script>
|
|
18
12
|
|
|
19
|
-
<svelte:element
|
|
20
|
-
this={component}
|
|
21
|
-
{id}
|
|
22
|
-
style={styleVariables}
|
|
23
|
-
class="rc-pw-text-block"
|
|
24
|
-
>
|
|
13
|
+
<svelte:element this={component} {style}>
|
|
25
14
|
{@render children?.()}
|
|
26
15
|
</svelte:element>
|
|
27
|
-
|
|
28
|
-
<style>
|
|
29
|
-
.rc-pw-text-block {
|
|
30
|
-
display: block;
|
|
31
|
-
padding-block-start: var(--text-padding-block-start, initial);
|
|
32
|
-
padding-inline-end: var(--text-padding-inline-end, initial);
|
|
33
|
-
padding-block-end: var(--text-padding-block-end, initial);
|
|
34
|
-
padding-inline-start: var(--text-padding-inline-start, initial);
|
|
35
|
-
margin-block-start: var(--text-margin-block-start, initial);
|
|
36
|
-
margin-inline-end: var(--text-margin-inline-end, initial);
|
|
37
|
-
margin-block-end: var(--text-margin-block-end, initial);
|
|
38
|
-
margin-inline-start: var(--text-margin-inline-start, initial);
|
|
39
|
-
color: var(--text-text-color, #ffffff);
|
|
40
|
-
background: var(--text-background, none);
|
|
41
|
-
font-size: var(--text-font-size, 1rem);
|
|
42
|
-
font-weight: var(--text-font-weight, normal);
|
|
43
|
-
text-align: var(--text-text-align, center);
|
|
44
|
-
font-family: var(--text-font-family, sans-serif);
|
|
45
|
-
-webkit-background-clip: var(--text-background-clip, initial);
|
|
46
|
-
background-clip: var(--text-background-clip, initial);
|
|
47
|
-
-webkit-text-fill-color: var(--text-text-fill-color, initial);
|
|
48
|
-
}
|
|
49
|
-
</style>
|
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
<script module lang="ts">
|
|
2
2
|
import TextNode from "./TextNode.svelte";
|
|
3
3
|
import { localizationDecorator } from "../../stories/localization-decorator";
|
|
4
|
-
import {
|
|
5
|
-
fontSizeStoryMeta,
|
|
6
|
-
fontWeightStoryMeta,
|
|
7
|
-
getColorStoryMeta,
|
|
8
|
-
getSpacingStoryMeta,
|
|
9
|
-
getTextControlStoryMeta,
|
|
10
|
-
horizontalAlignmentStoryMeta,
|
|
11
|
-
} from "../../stories/meta-templates";
|
|
12
4
|
import { variablesDecorator } from "../../stories/variables-decorator";
|
|
13
5
|
import type { Localizations } from "../../types/localization";
|
|
14
|
-
import type { VariableDictionary } from "../../
|
|
6
|
+
import type { VariableDictionary } from "../../types/variables";
|
|
15
7
|
import { defineMeta } from "@storybook/addon-svelte-csf";
|
|
8
|
+
import { VARIABLES } from "../paywall/fixtures/variables";
|
|
16
9
|
|
|
17
10
|
/*
|
|
18
11
|
* Documentation for this component can be found in https://www.notion.so/revenuecat/Text-e257cb046e104351861f8364ede617be?pvs=4
|
|
@@ -24,7 +17,6 @@
|
|
|
24
17
|
const { Story } = defineMeta({
|
|
25
18
|
title: "Components/Text",
|
|
26
19
|
component: TextNode,
|
|
27
|
-
tags: ["autodocs"],
|
|
28
20
|
decorators: [
|
|
29
21
|
(Story, context) => {
|
|
30
22
|
const localizations = context.parameters.localizations as Localizations;
|
|
@@ -41,19 +33,6 @@
|
|
|
41
33
|
height: { type: "fill" },
|
|
42
34
|
},
|
|
43
35
|
},
|
|
44
|
-
argTypes: {
|
|
45
|
-
name: getTextControlStoryMeta("Content of the text to render"),
|
|
46
|
-
font_name: getTextControlStoryMeta(
|
|
47
|
-
"Font family to be used, uses GoogleFonts API",
|
|
48
|
-
),
|
|
49
|
-
font_weight: fontWeightStoryMeta,
|
|
50
|
-
font_size: fontSizeStoryMeta,
|
|
51
|
-
color: getColorStoryMeta("Text color object"),
|
|
52
|
-
background_color: getColorStoryMeta("Background color object"),
|
|
53
|
-
horizontal_alignment: horizontalAlignmentStoryMeta,
|
|
54
|
-
padding: getSpacingStoryMeta("Padding values in pixels"),
|
|
55
|
-
margin: getSpacingStoryMeta("Margin values in pixels"),
|
|
56
|
-
},
|
|
57
36
|
parameters: {
|
|
58
37
|
localizations: {
|
|
59
38
|
[defaultLocale]: {
|
|
@@ -65,16 +44,15 @@
|
|
|
65
44
|
});
|
|
66
45
|
|
|
67
46
|
const mockVariableDictionary = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
47
|
+
...VARIABLES.$rc_weekly,
|
|
48
|
+
"product.store_product_name": "CatGPT",
|
|
49
|
+
"product.price": "$39.99",
|
|
50
|
+
"product.price_per_period": "$39.99/yr",
|
|
51
|
+
} satisfies VariableDictionary;
|
|
72
52
|
</script>
|
|
73
53
|
|
|
74
|
-
<!-- Default story -->
|
|
75
54
|
<Story name="Default" args={{ name: "hello world!" }} />
|
|
76
55
|
|
|
77
|
-
<!-- Font Weight text story -->
|
|
78
56
|
<Story
|
|
79
57
|
name="Font Weight"
|
|
80
58
|
args={{
|
|
@@ -84,7 +62,6 @@
|
|
|
84
62
|
}}
|
|
85
63
|
/>
|
|
86
64
|
|
|
87
|
-
<!-- Text Alignment text story -->
|
|
88
65
|
<Story
|
|
89
66
|
name="Text Alignment"
|
|
90
67
|
args={{
|
|
@@ -94,7 +71,6 @@
|
|
|
94
71
|
}}
|
|
95
72
|
/>
|
|
96
73
|
|
|
97
|
-
<!-- Color text story -->
|
|
98
74
|
<Story
|
|
99
75
|
name="Color"
|
|
100
76
|
args={{
|
|
@@ -112,7 +88,6 @@
|
|
|
112
88
|
}}
|
|
113
89
|
/>
|
|
114
90
|
|
|
115
|
-
<!-- Text with spacing story -->
|
|
116
91
|
<Story
|
|
117
92
|
name="With Spacing"
|
|
118
93
|
args={{
|
|
@@ -124,7 +99,6 @@
|
|
|
124
99
|
}}
|
|
125
100
|
/>
|
|
126
101
|
|
|
127
|
-
<!-- Text with variable dictionary story -->
|
|
128
102
|
<Story
|
|
129
103
|
name="With variable dictionary"
|
|
130
104
|
args={{
|
|
@@ -140,12 +114,12 @@
|
|
|
140
114
|
localizations: {
|
|
141
115
|
[defaultLocale]: {
|
|
142
116
|
[text_lid]:
|
|
143
|
-
"This is a text that contains variables: {{ product_name }} for {{ price }} per {{ price_per_period }}",
|
|
117
|
+
"This is a text that contains variables: {{ product.product_name }} for {{ product.price }} per {{ product.price_per_period }}",
|
|
144
118
|
},
|
|
145
119
|
} satisfies Localizations,
|
|
146
120
|
}}
|
|
147
121
|
/>
|
|
148
|
-
|
|
122
|
+
|
|
149
123
|
<Story
|
|
150
124
|
name="With missing variable in dictionary"
|
|
151
125
|
args={{
|
|
@@ -161,7 +135,7 @@
|
|
|
161
135
|
localizations: {
|
|
162
136
|
[defaultLocale]: {
|
|
163
137
|
[text_lid]:
|
|
164
|
-
"This is a text with variables: {{
|
|
138
|
+
"This is a text with variables: {{ product.store_product_name }} for {{ product.price }} per {{ product.price_per_period }} and a missing variable: {{ sub_period_abbreviated }}",
|
|
165
139
|
},
|
|
166
140
|
} satisfies Localizations,
|
|
167
141
|
}}
|
|
@@ -1,58 +1,55 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import {
|
|
3
3
|
getHtmlFromMarkdown,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
getTextComponentStyles,
|
|
5
|
+
getTextWrapperInlineStyles,
|
|
6
6
|
} from "./text-utils";
|
|
7
7
|
import Text from "./Text.svelte";
|
|
8
|
-
import type { TextNodeProps } from "../../data/entities";
|
|
9
8
|
import { getColorModeContext } from "../../stores/color-mode";
|
|
10
9
|
import { getLocalizationContext } from "../../stores/localization";
|
|
10
|
+
import { getSelectedStateContext } from "../../stores/selected";
|
|
11
11
|
import { getVariablesContext } from "../../stores/variables";
|
|
12
|
+
import type { TextNodeProps } from "../../types/components/text";
|
|
13
|
+
import { getActiveStateProps } from "../../utils/style-utils";
|
|
12
14
|
import { replaceVariables } from "../../utils/variable-utils";
|
|
13
15
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
+
const props: TextNodeProps = $props();
|
|
17
|
+
|
|
18
|
+
const selectedState = getSelectedStateContext();
|
|
19
|
+
const actualProps = $derived.by(() => {
|
|
20
|
+
return {
|
|
21
|
+
...props,
|
|
22
|
+
...getActiveStateProps($selectedState, props.overrides),
|
|
23
|
+
};
|
|
24
|
+
});
|
|
16
25
|
|
|
17
26
|
const getColorMode = getColorModeContext();
|
|
18
27
|
const colorMode = $derived(getColorMode());
|
|
19
28
|
|
|
20
29
|
const { tagToRender, textStyles } = $derived(
|
|
21
|
-
|
|
22
|
-
id,
|
|
23
|
-
text_lid,
|
|
24
|
-
background_color,
|
|
25
|
-
size,
|
|
26
|
-
...restProps,
|
|
27
|
-
}),
|
|
30
|
+
getTextComponentStyles(colorMode, actualProps),
|
|
28
31
|
);
|
|
29
32
|
|
|
30
33
|
const wrapperStyles = $derived(
|
|
31
|
-
|
|
34
|
+
getTextWrapperInlineStyles(
|
|
35
|
+
colorMode,
|
|
36
|
+
actualProps,
|
|
37
|
+
actualProps.size,
|
|
38
|
+
actualProps.background_color,
|
|
39
|
+
),
|
|
32
40
|
);
|
|
33
41
|
|
|
34
42
|
const variables = getVariablesContext();
|
|
35
43
|
const { getLocalizedString } = getLocalizationContext();
|
|
36
44
|
const label = $derived(
|
|
37
|
-
replaceVariables(getLocalizedString(text_lid), $variables),
|
|
45
|
+
replaceVariables(getLocalizedString(actualProps.text_lid), $variables),
|
|
38
46
|
);
|
|
47
|
+
|
|
39
48
|
const markdownParsed = $derived(getHtmlFromMarkdown(label));
|
|
40
49
|
</script>
|
|
41
50
|
|
|
42
|
-
<span style={wrapperStyles}
|
|
43
|
-
<Text
|
|
51
|
+
<span style={wrapperStyles}>
|
|
52
|
+
<Text style={textStyles} component={tagToRender}>
|
|
44
53
|
{@html markdownParsed}
|
|
45
54
|
</Text>
|
|
46
55
|
</span>
|
|
47
|
-
|
|
48
|
-
<style>
|
|
49
|
-
.rc-pw-text-wrapper {
|
|
50
|
-
display: block;
|
|
51
|
-
height: var(--text-height, initial);
|
|
52
|
-
width: var(--text-width, initial);
|
|
53
|
-
background: var(--text-background, none);
|
|
54
|
-
position: var(--text-position, relative);
|
|
55
|
-
inset: var(--text-inset, 0);
|
|
56
|
-
transform: var(--text-transform, initial);
|
|
57
|
-
}
|
|
58
|
-
</style>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TextNodeProps } from "../../
|
|
1
|
+
import type { TextNodeProps } from "../../types/components/text";
|
|
2
2
|
declare const TextNode: import("svelte").Component<TextNodeProps, {}, "">;
|
|
3
3
|
type TextNode = ReturnType<typeof TextNode>;
|
|
4
4
|
export default TextNode;
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import type { TextNodeProps } from "../../data/entities";
|
|
2
1
|
import type { ColorMode, SizeType } from "../../types";
|
|
3
2
|
import type { ColorGradientScheme, ColorScheme } from "../../types/colors";
|
|
3
|
+
import type { TextNodeProps } from "../../types/components/text";
|
|
4
4
|
export declare const defaultColor: ColorScheme;
|
|
5
|
-
export declare const defaultBackgroundColor: ColorGradientScheme;
|
|
6
5
|
/**
|
|
7
6
|
* Generates comprehensive styles for text components by combining text, component and size styles
|
|
8
7
|
* @param props - Text component properties including font, color, background, spacing etc.
|
|
9
|
-
* @returns Object containing text
|
|
8
|
+
* @returns Object containing text inline styles and the appropriate HTML tag to render
|
|
10
9
|
*/
|
|
11
10
|
export declare const getTextComponentStyles: (colorMode: ColorMode, props: TextNodeProps) => {
|
|
12
|
-
textStyles: Record<string, string | number>;
|
|
13
|
-
tagToRender: import("../../utils/style-utils").TextComponentTags;
|
|
14
|
-
};
|
|
15
|
-
export declare function getTextWrapperStyles(restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorGradientScheme | null): string;
|
|
16
|
-
export declare function getTextNodeStyles(colorMode: ColorMode, props: TextNodeProps): {
|
|
17
|
-
tagToRender: import("../../utils/style-utils").TextComponentTags;
|
|
18
11
|
textStyles: string;
|
|
12
|
+
tagToRender: string;
|
|
19
13
|
};
|
|
14
|
+
export declare function getTextWrapperInlineStyles(colorMode: ColorMode, _restProps: Partial<TextNodeProps>, size: SizeType, background_color?: ColorGradientScheme | null): string;
|
|
20
15
|
export declare function getHtmlFromMarkdown(text?: string): string;
|