@revenuecat/purchases-ui-js 0.0.8
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/LICENSE +21 -0
- package/README.md +11 -0
- package/dist/components/button/Button.svelte +33 -0
- package/dist/components/button/Button.svelte.d.ts +8 -0
- package/dist/components/button/ButtonNode.stories.svelte +204 -0
- package/dist/components/button/ButtonNode.stories.svelte.d.ts +27 -0
- package/dist/components/button/ButtonNode.svelte +15 -0
- package/dist/components/button/ButtonNode.svelte.d.ts +3 -0
- package/dist/components/footer/Footer.stories.svelte +237 -0
- package/dist/components/footer/Footer.stories.svelte.d.ts +25 -0
- package/dist/components/footer/Footer.svelte +11 -0
- package/dist/components/footer/Footer.svelte.d.ts +3 -0
- package/dist/components/image/Image.stories.svelte +165 -0
- package/dist/components/image/Image.stories.svelte.d.ts +19 -0
- package/dist/components/image/Image.svelte +45 -0
- package/dist/components/image/Image.svelte.d.ts +3 -0
- package/dist/components/image/image-utils.d.ts +20 -0
- package/dist/components/image/image-utils.js +19 -0
- package/dist/components/package/Package.stories.svelte +243 -0
- package/dist/components/package/Package.stories.svelte.d.ts +25 -0
- package/dist/components/package/Package.svelte +39 -0
- package/dist/components/package/Package.svelte.d.ts +3 -0
- package/dist/components/paywall/Node.svelte +55 -0
- package/dist/components/paywall/Node.svelte.d.ts +9 -0
- package/dist/components/paywall/Paywall.stories.svelte +24 -0
- package/dist/components/paywall/Paywall.stories.svelte.d.ts +19 -0
- package/dist/components/paywall/Paywall.svelte +122 -0
- package/dist/components/paywall/Paywall.svelte.d.ts +6 -0
- package/dist/components/paywall/global-styles.css +9 -0
- package/dist/components/purchase-button/PurchaseButton.stories.svelte +133 -0
- package/dist/components/purchase-button/PurchaseButton.stories.svelte.d.ts +24 -0
- package/dist/components/purchase-button/PurchaseButton.svelte +28 -0
- package/dist/components/purchase-button/PurchaseButton.svelte.d.ts +3 -0
- package/dist/components/stack/Stack.stories.svelte +306 -0
- package/dist/components/stack/Stack.stories.svelte.d.ts +19 -0
- package/dist/components/stack/Stack.svelte +61 -0
- package/dist/components/stack/Stack.svelte.d.ts +3 -0
- package/dist/components/stack/stack-utils.d.ts +29 -0
- package/dist/components/stack/stack-utils.js +26 -0
- package/dist/components/text/Text.stories.svelte +101 -0
- package/dist/components/text/Text.stories.svelte.d.ts +19 -0
- package/dist/components/text/Text.svelte +40 -0
- package/dist/components/text/Text.svelte.d.ts +3 -0
- package/dist/components/text/text-utils.d.ts +20 -0
- package/dist/components/text/text-utils.js +34 -0
- package/dist/data/entities.d.ts +139 -0
- package/dist/data/entities.js +1 -0
- package/dist/data/state.d.ts +3 -0
- package/dist/data/state.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +11 -0
- package/dist/stores/theme.d.ts +1 -0
- package/dist/stores/theme.js +17 -0
- package/dist/stories/fixtures.d.ts +12 -0
- package/dist/stories/fixtures.js +6855 -0
- package/dist/stories/meta-templates.d.ts +13 -0
- package/dist/stories/meta-templates.js +156 -0
- package/dist/types.d.ts +125 -0
- package/dist/types.js +61 -0
- package/dist/utils.d.ts +93 -0
- package/dist/utils.js +227 -0
- package/package.json +91 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { InputType } from "storybook/internal/types";
|
|
2
|
+
export declare const getSpacingStoryMeta: (description: string) => InputType;
|
|
3
|
+
export declare const getColorStoryMeta: (description: string) => InputType;
|
|
4
|
+
export declare const stackDimensionStoryMeta: InputType;
|
|
5
|
+
export declare const getTextControlStoryMeta: (description: string) => InputType;
|
|
6
|
+
export declare const fontWeightStoryMeta: InputType;
|
|
7
|
+
export declare const fontSizeStoryMeta: InputType;
|
|
8
|
+
export declare const textStyleStoryMeta: InputType;
|
|
9
|
+
export declare const horizontalAlignmentStoryMeta: InputType;
|
|
10
|
+
export declare const colorModeStoryMeta: InputType;
|
|
11
|
+
export declare const shadowStoryMeta: InputType;
|
|
12
|
+
export declare const borderStoryMeta: InputType;
|
|
13
|
+
export declare const sizeStoryMeta: InputType;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export const getSpacingStoryMeta = (description) => ({
|
|
2
|
+
description,
|
|
3
|
+
control: { type: "object" },
|
|
4
|
+
defaultValue: { top: 0, trailing: 0, bottom: 0, leading: 0 },
|
|
5
|
+
table: {
|
|
6
|
+
type: {
|
|
7
|
+
summary: "object",
|
|
8
|
+
detail: "{ top: number, trailing: number, bottom: number, leading: number }",
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
export const getColorStoryMeta = (description) => ({
|
|
13
|
+
description,
|
|
14
|
+
control: {
|
|
15
|
+
type: "object",
|
|
16
|
+
fields: {
|
|
17
|
+
light: { type: "color" },
|
|
18
|
+
dark: { type: "color" },
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultValue: { dark: "#FFFFFF", light: "#FFFFFF" },
|
|
22
|
+
table: {
|
|
23
|
+
type: {
|
|
24
|
+
summary: "object",
|
|
25
|
+
detail: "{ dark: string, light: string }",
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
export const stackDimensionStoryMeta = {
|
|
30
|
+
control: { type: "object" },
|
|
31
|
+
description: "Stack dimension configuration",
|
|
32
|
+
table: {
|
|
33
|
+
type: {
|
|
34
|
+
summary: "object",
|
|
35
|
+
detail: `{
|
|
36
|
+
type: "vertical" | "horizontal" | "zlayer",
|
|
37
|
+
alignment: "start" | "center" | "end" | "top" | "bottom",
|
|
38
|
+
distribution: "start" | "center" | "end" | "space_between" | "space_around" | "space_evenly"
|
|
39
|
+
}`,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
export const getTextControlStoryMeta = (description) => ({
|
|
44
|
+
control: { type: "text" },
|
|
45
|
+
description,
|
|
46
|
+
});
|
|
47
|
+
export const fontWeightStoryMeta = {
|
|
48
|
+
control: { type: "select" },
|
|
49
|
+
options: [
|
|
50
|
+
"black",
|
|
51
|
+
"extra-bold",
|
|
52
|
+
"bold",
|
|
53
|
+
"semi-bold",
|
|
54
|
+
"medium",
|
|
55
|
+
"regular",
|
|
56
|
+
"light",
|
|
57
|
+
"extra-light",
|
|
58
|
+
"thin",
|
|
59
|
+
],
|
|
60
|
+
description: "Font weight to be used",
|
|
61
|
+
};
|
|
62
|
+
export const fontSizeStoryMeta = {
|
|
63
|
+
control: { type: "select" },
|
|
64
|
+
options: [
|
|
65
|
+
"body_s",
|
|
66
|
+
"body_m",
|
|
67
|
+
"body_l",
|
|
68
|
+
"body_xl",
|
|
69
|
+
"heading_xs",
|
|
70
|
+
"heading_s",
|
|
71
|
+
"heading_m",
|
|
72
|
+
"heading_l",
|
|
73
|
+
"heading_xl",
|
|
74
|
+
"heading_xxl",
|
|
75
|
+
],
|
|
76
|
+
description: "Font size to be used",
|
|
77
|
+
};
|
|
78
|
+
export const textStyleStoryMeta = {
|
|
79
|
+
control: { type: "select" },
|
|
80
|
+
options: ["normal", "bold", "italic", "strikethrough", "link", "monospace"],
|
|
81
|
+
description: "Text style to be used",
|
|
82
|
+
};
|
|
83
|
+
export const horizontalAlignmentStoryMeta = {
|
|
84
|
+
control: { type: "select" },
|
|
85
|
+
options: ["center", "start", "end"],
|
|
86
|
+
description: "Text horizontal alignment",
|
|
87
|
+
};
|
|
88
|
+
export const colorModeStoryMeta = {
|
|
89
|
+
control: { type: "select" },
|
|
90
|
+
options: ["light", "dark"],
|
|
91
|
+
description: "Color mode",
|
|
92
|
+
};
|
|
93
|
+
export const shadowStoryMeta = {
|
|
94
|
+
control: {
|
|
95
|
+
type: "object",
|
|
96
|
+
fields: {
|
|
97
|
+
x: { type: "number" },
|
|
98
|
+
y: { type: "number" },
|
|
99
|
+
radius: { type: "number" },
|
|
100
|
+
color: { type: "color" },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
defaultValue: {
|
|
104
|
+
x: 0,
|
|
105
|
+
y: 0,
|
|
106
|
+
radius: 0,
|
|
107
|
+
color: { dark: "#000000", light: "#000000" },
|
|
108
|
+
},
|
|
109
|
+
table: {
|
|
110
|
+
type: {
|
|
111
|
+
summary: "object",
|
|
112
|
+
detail: "{ x: number, y: number, radius: number, color: { dark: string, light: string } }",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
description: "Shadow properties including x, y, radius, and color",
|
|
116
|
+
};
|
|
117
|
+
export const borderStoryMeta = {
|
|
118
|
+
control: {
|
|
119
|
+
type: "object",
|
|
120
|
+
fields: {
|
|
121
|
+
width: { type: "number" },
|
|
122
|
+
color: { type: "color" },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
defaultValue: {
|
|
126
|
+
width: 0,
|
|
127
|
+
color: { dark: "#000000", light: "#000000" },
|
|
128
|
+
},
|
|
129
|
+
description: "Border properties including width, color, style, and radius",
|
|
130
|
+
};
|
|
131
|
+
export const sizeStoryMeta = {
|
|
132
|
+
control: {
|
|
133
|
+
type: "object",
|
|
134
|
+
fields: {
|
|
135
|
+
width: {
|
|
136
|
+
type: "object",
|
|
137
|
+
fields: {
|
|
138
|
+
type: { type: "select", options: ["fit", "fill", "fixed"] },
|
|
139
|
+
value: { type: "number" },
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
height: {
|
|
143
|
+
type: "object",
|
|
144
|
+
fields: {
|
|
145
|
+
type: { type: "select", options: ["fit", "fill", "fixed"] },
|
|
146
|
+
value: { type: "number" },
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
defaultValue: {
|
|
152
|
+
width: { type: "fill" },
|
|
153
|
+
height: { type: "fill" },
|
|
154
|
+
},
|
|
155
|
+
description: "Size properties including width and height",
|
|
156
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
export type ColorMode = "light" | "dark";
|
|
2
|
+
type Color = {
|
|
3
|
+
type: "hex" | "alias";
|
|
4
|
+
value: string;
|
|
5
|
+
};
|
|
6
|
+
export type ColorType = {
|
|
7
|
+
dark?: Color;
|
|
8
|
+
light: Color;
|
|
9
|
+
};
|
|
10
|
+
export declare enum FontSizeTags {
|
|
11
|
+
body_s = "p",
|
|
12
|
+
body_m = "p",
|
|
13
|
+
body_l = "p",
|
|
14
|
+
body_xl = "p",
|
|
15
|
+
heading_xs = "h6",
|
|
16
|
+
heading_s = "h5",
|
|
17
|
+
heading_m = "h4",
|
|
18
|
+
heading_l = "h3",
|
|
19
|
+
heading_xl = "h2",
|
|
20
|
+
heading_xxl = "h1"
|
|
21
|
+
}
|
|
22
|
+
export declare enum FontWeights {
|
|
23
|
+
extra_light = 100,
|
|
24
|
+
thin = 200,
|
|
25
|
+
light = 300,
|
|
26
|
+
regular = 400,
|
|
27
|
+
medium = 500,
|
|
28
|
+
semi_bold = 600,
|
|
29
|
+
bold = 700,
|
|
30
|
+
extra_bold = 800,
|
|
31
|
+
black = 900
|
|
32
|
+
}
|
|
33
|
+
export declare enum FontSizes {
|
|
34
|
+
body_s = "13px",
|
|
35
|
+
body_m = "14px",
|
|
36
|
+
body_l = "15px",
|
|
37
|
+
body_xl = "16px",
|
|
38
|
+
heading_xs = "14px",
|
|
39
|
+
heading_s = "16px",
|
|
40
|
+
heading_m = "18px",
|
|
41
|
+
heading_l = "20px",
|
|
42
|
+
heading_xl = "26px",
|
|
43
|
+
heading_xxl = "32px"
|
|
44
|
+
}
|
|
45
|
+
export type TextAlignment = "center" | "start" | "end";
|
|
46
|
+
export type SizeType = {
|
|
47
|
+
width: Size;
|
|
48
|
+
height: Size;
|
|
49
|
+
};
|
|
50
|
+
export type Size = FixedSize | RelativeSize;
|
|
51
|
+
export type FitTypes = "fit" | "fill";
|
|
52
|
+
type FixedSize = {
|
|
53
|
+
type: "fixed";
|
|
54
|
+
value: number;
|
|
55
|
+
};
|
|
56
|
+
type RelativeSize = {
|
|
57
|
+
type: FitTypes;
|
|
58
|
+
};
|
|
59
|
+
export type ShapeType = RectangleShape | PillShape;
|
|
60
|
+
type RectangleShape = {
|
|
61
|
+
type: "rectangle";
|
|
62
|
+
corners: CornerRadiusType;
|
|
63
|
+
};
|
|
64
|
+
type PillShape = {
|
|
65
|
+
type: "pill";
|
|
66
|
+
};
|
|
67
|
+
export type BorderType = {
|
|
68
|
+
color: ColorType;
|
|
69
|
+
width: number;
|
|
70
|
+
};
|
|
71
|
+
export type Spacing = {
|
|
72
|
+
top: number;
|
|
73
|
+
bottom: number;
|
|
74
|
+
leading: number;
|
|
75
|
+
trailing: number;
|
|
76
|
+
};
|
|
77
|
+
export type CornerRadiusType = {
|
|
78
|
+
bottom_leading: number;
|
|
79
|
+
bottom_trailing: number;
|
|
80
|
+
top_leading: number;
|
|
81
|
+
top_trailing: number;
|
|
82
|
+
};
|
|
83
|
+
export type DimensionType = VerticalAlignment | HorizontalAlignment | ZAlignment;
|
|
84
|
+
type VerticalAlignment = {
|
|
85
|
+
type: "vertical";
|
|
86
|
+
alignment: "top" | "center" | "bottom";
|
|
87
|
+
distribution?: Distribution;
|
|
88
|
+
};
|
|
89
|
+
type HorizontalAlignment = {
|
|
90
|
+
type: "horizontal";
|
|
91
|
+
alignment: "leading" | "center" | "trailing";
|
|
92
|
+
distribution?: Distribution;
|
|
93
|
+
};
|
|
94
|
+
type ZAlignment = {
|
|
95
|
+
type: "zlayer";
|
|
96
|
+
alignment: "top_leading" | "top" | "top_trailing" | "leading" | "center" | "trailing" | "bottom_leading" | "bottom" | "bottom_trailing";
|
|
97
|
+
distribution: never;
|
|
98
|
+
};
|
|
99
|
+
type Distribution = "space_between" | "space_around" | "space_evenly" | "start" | "center" | "end";
|
|
100
|
+
export type ShadowType = {
|
|
101
|
+
x: number;
|
|
102
|
+
y: number;
|
|
103
|
+
radius: number;
|
|
104
|
+
color: ColorType;
|
|
105
|
+
};
|
|
106
|
+
export declare enum StackDirection {
|
|
107
|
+
vertical = "column",
|
|
108
|
+
horizontal = "row"
|
|
109
|
+
}
|
|
110
|
+
export declare enum StackAlignment {
|
|
111
|
+
top = "flex-start",
|
|
112
|
+
leading = "flex-start",
|
|
113
|
+
center = "center",
|
|
114
|
+
bottom = "flex-end",
|
|
115
|
+
trailing = "flex-end"
|
|
116
|
+
}
|
|
117
|
+
export declare enum StackDistribution {
|
|
118
|
+
space_between = "space-between",
|
|
119
|
+
space_around = "space-around",
|
|
120
|
+
space_evenly = "space-evenly",
|
|
121
|
+
start = "flex-start",
|
|
122
|
+
center = "center",
|
|
123
|
+
end = "flex-end"
|
|
124
|
+
}
|
|
125
|
+
export {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Text types
|
|
2
|
+
export var FontSizeTags;
|
|
3
|
+
(function (FontSizeTags) {
|
|
4
|
+
FontSizeTags["body_s"] = "p";
|
|
5
|
+
FontSizeTags["body_m"] = "p";
|
|
6
|
+
FontSizeTags["body_l"] = "p";
|
|
7
|
+
FontSizeTags["body_xl"] = "p";
|
|
8
|
+
FontSizeTags["heading_xs"] = "h6";
|
|
9
|
+
FontSizeTags["heading_s"] = "h5";
|
|
10
|
+
FontSizeTags["heading_m"] = "h4";
|
|
11
|
+
FontSizeTags["heading_l"] = "h3";
|
|
12
|
+
FontSizeTags["heading_xl"] = "h2";
|
|
13
|
+
FontSizeTags["heading_xxl"] = "h1";
|
|
14
|
+
})(FontSizeTags || (FontSizeTags = {}));
|
|
15
|
+
export var FontWeights;
|
|
16
|
+
(function (FontWeights) {
|
|
17
|
+
FontWeights[FontWeights["extra_light"] = 100] = "extra_light";
|
|
18
|
+
FontWeights[FontWeights["thin"] = 200] = "thin";
|
|
19
|
+
FontWeights[FontWeights["light"] = 300] = "light";
|
|
20
|
+
FontWeights[FontWeights["regular"] = 400] = "regular";
|
|
21
|
+
FontWeights[FontWeights["medium"] = 500] = "medium";
|
|
22
|
+
FontWeights[FontWeights["semi_bold"] = 600] = "semi_bold";
|
|
23
|
+
FontWeights[FontWeights["bold"] = 700] = "bold";
|
|
24
|
+
FontWeights[FontWeights["extra_bold"] = 800] = "extra_bold";
|
|
25
|
+
FontWeights[FontWeights["black"] = 900] = "black";
|
|
26
|
+
})(FontWeights || (FontWeights = {}));
|
|
27
|
+
export var FontSizes;
|
|
28
|
+
(function (FontSizes) {
|
|
29
|
+
FontSizes["body_s"] = "13px";
|
|
30
|
+
FontSizes["body_m"] = "14px";
|
|
31
|
+
FontSizes["body_l"] = "15px";
|
|
32
|
+
FontSizes["body_xl"] = "16px";
|
|
33
|
+
FontSizes["heading_xs"] = "14px";
|
|
34
|
+
FontSizes["heading_s"] = "16px";
|
|
35
|
+
FontSizes["heading_m"] = "18px";
|
|
36
|
+
FontSizes["heading_l"] = "20px";
|
|
37
|
+
FontSizes["heading_xl"] = "26px";
|
|
38
|
+
FontSizes["heading_xxl"] = "32px";
|
|
39
|
+
})(FontSizes || (FontSizes = {}));
|
|
40
|
+
export var StackDirection;
|
|
41
|
+
(function (StackDirection) {
|
|
42
|
+
StackDirection["vertical"] = "column";
|
|
43
|
+
StackDirection["horizontal"] = "row";
|
|
44
|
+
})(StackDirection || (StackDirection = {}));
|
|
45
|
+
export var StackAlignment;
|
|
46
|
+
(function (StackAlignment) {
|
|
47
|
+
StackAlignment["top"] = "flex-start";
|
|
48
|
+
StackAlignment["leading"] = "flex-start";
|
|
49
|
+
StackAlignment["center"] = "center";
|
|
50
|
+
StackAlignment["bottom"] = "flex-end";
|
|
51
|
+
StackAlignment["trailing"] = "flex-end";
|
|
52
|
+
})(StackAlignment || (StackAlignment = {}));
|
|
53
|
+
export var StackDistribution;
|
|
54
|
+
(function (StackDistribution) {
|
|
55
|
+
StackDistribution["space_between"] = "space-between";
|
|
56
|
+
StackDistribution["space_around"] = "space-around";
|
|
57
|
+
StackDistribution["space_evenly"] = "space-evenly";
|
|
58
|
+
StackDistribution["start"] = "flex-start";
|
|
59
|
+
StackDistribution["center"] = "center";
|
|
60
|
+
StackDistribution["end"] = "flex-end";
|
|
61
|
+
})(StackDistribution || (StackDistribution = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { ImageMaskShapeType, TextProps } from "./data/entities.js";
|
|
2
|
+
import { FontSizeTags, type BorderType, type ColorMode, type ColorType, type DimensionType, type ShadowType, type ShapeType, type SizeType, type Spacing } from "./types.js";
|
|
3
|
+
export type TextComponentTags = "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
|
|
4
|
+
/**
|
|
5
|
+
* Maps font size to appropriate HTML heading tag
|
|
6
|
+
* @param fontSize - Key from FontSizeTags enum
|
|
7
|
+
* @returns Corresponding HTML heading tag
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTextComponentTag(fontSize: keyof typeof FontSizeTags): TextComponentTags;
|
|
10
|
+
/**
|
|
11
|
+
* Generates comprehensive component styles including spacing, colors, borders and shadows
|
|
12
|
+
* @param params - Component style configuration object
|
|
13
|
+
* @returns CSS style object with component styles
|
|
14
|
+
*/
|
|
15
|
+
export declare function getComponentStyles({ backgroundColor, border, margin, padding, textColor, colorMode, shape, shadow, }: {
|
|
16
|
+
padding?: Spacing;
|
|
17
|
+
margin?: Spacing;
|
|
18
|
+
backgroundColor?: ColorType;
|
|
19
|
+
textColor?: ColorType;
|
|
20
|
+
border?: BorderType;
|
|
21
|
+
colorMode?: ColorMode;
|
|
22
|
+
shape?: ShapeType;
|
|
23
|
+
shadow?: ShadowType;
|
|
24
|
+
}): {
|
|
25
|
+
"--margin-block-start": string;
|
|
26
|
+
"--margin-inline-end": string;
|
|
27
|
+
"--margin-block-end": string;
|
|
28
|
+
"--margin-inline-start": string;
|
|
29
|
+
"--padding-block-start": string;
|
|
30
|
+
"--padding-inline-end": string;
|
|
31
|
+
"--padding-block-end": string;
|
|
32
|
+
"--padding-inline-start": string;
|
|
33
|
+
"--background-color": string;
|
|
34
|
+
"--text-color": string;
|
|
35
|
+
"--border": string;
|
|
36
|
+
"--border-radius": string;
|
|
37
|
+
"--shadow": string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Generates size-related CSS styles for components
|
|
41
|
+
* @param size - Size configuration object
|
|
42
|
+
* @returns CSS style object with size properties
|
|
43
|
+
*/
|
|
44
|
+
export declare function getSizeStyle(size: SizeType): {
|
|
45
|
+
"--width": string;
|
|
46
|
+
"--height": string;
|
|
47
|
+
"--flex": string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Generates gradient background styles
|
|
51
|
+
* @param colorMode - Color mode (light/dark)
|
|
52
|
+
* @param gradientColors - Array of colors for gradient
|
|
53
|
+
* @returns CSS style object with gradient background
|
|
54
|
+
*/
|
|
55
|
+
export declare function getGradientStyle(colorMode: ColorMode, gradientColors?: ColorType[]): {
|
|
56
|
+
"--background": string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Generates mask styles for images
|
|
60
|
+
* @param maskShape - Shape configuration for image mask
|
|
61
|
+
* @returns CSS style object with mask properties
|
|
62
|
+
*/
|
|
63
|
+
export declare const getMaskStyle: (maskShape?: ImageMaskShapeType) => {
|
|
64
|
+
"--corner-radius": string;
|
|
65
|
+
"--clip-path": string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Generates dimension-related styles for stack components
|
|
69
|
+
* @param dimension - Dimension configuration object
|
|
70
|
+
* @returns CSS style object with flex layout properties
|
|
71
|
+
*/
|
|
72
|
+
export declare function getDimensionStyle(dimension: DimensionType): {
|
|
73
|
+
"--direction": string;
|
|
74
|
+
"--alignment": string;
|
|
75
|
+
"--distribution": string;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Generates text-related styles
|
|
79
|
+
* @param props - Text component properties
|
|
80
|
+
* @returns CSS style object with text formatting properties
|
|
81
|
+
*/
|
|
82
|
+
export declare function getTextStyles(props: TextProps): {
|
|
83
|
+
"--text-align": string;
|
|
84
|
+
"--font-weight": number;
|
|
85
|
+
"--font-size": string;
|
|
86
|
+
"--font-family": string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Converts a style object to a CSS string
|
|
90
|
+
* @param styles - Object containing CSS properties and values
|
|
91
|
+
* @returns CSS string
|
|
92
|
+
*/
|
|
93
|
+
export declare function stringifyStyles(styles: Record<string, string | number>): string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { FontSizes, FontWeights, StackAlignment, StackDirection, StackDistribution, FontSizeTags, } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generates CSS spacing styles for margin or padding
|
|
4
|
+
* @param spacing - The spacing object containing top, trailing, bottom, and leading values
|
|
5
|
+
* @param spacingKey - The type of spacing ('margin' or 'padding')
|
|
6
|
+
* @returns CSS style object with logical properties for spacing
|
|
7
|
+
*/
|
|
8
|
+
function getSpacingStyle(spacing, spacingKey) {
|
|
9
|
+
if (!spacing || !spacingKey)
|
|
10
|
+
return "";
|
|
11
|
+
return {
|
|
12
|
+
[`--${spacingKey}-block-start`]: `${spacing.top ?? 0}px`,
|
|
13
|
+
[`--${spacingKey}-inline-end`]: `${spacing.trailing ?? 0}px`,
|
|
14
|
+
[`--${spacingKey}-block-end`]: `${spacing.bottom ?? 0}px`,
|
|
15
|
+
[`--${spacingKey}-inline-start`]: `${spacing.leading ?? 0}px`,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Maps font size to appropriate HTML heading tag
|
|
20
|
+
* @param fontSize - Key from FontSizeTags enum
|
|
21
|
+
* @returns Corresponding HTML heading tag
|
|
22
|
+
*/
|
|
23
|
+
export function getTextComponentTag(fontSize) {
|
|
24
|
+
return FontSizeTags[fontSize];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Gets color value based on color mode with fallback
|
|
28
|
+
* @param params - Object containing color map, mode and fallback color
|
|
29
|
+
* @returns Color value as string
|
|
30
|
+
*/
|
|
31
|
+
function getColor({ colorMap, colorMode = "light", fallback = "FFFFFF", }) {
|
|
32
|
+
return colorMap?.[colorMode]?.value || fallback;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generates CSS border style string
|
|
36
|
+
* @param border - Border configuration object
|
|
37
|
+
* @param colorMode - Color mode (light/dark)
|
|
38
|
+
* @returns CSS border style string
|
|
39
|
+
*/
|
|
40
|
+
function getBorderStyle(border, colorMode = "light") {
|
|
41
|
+
const color = getColor({ colorMap: border.color, colorMode });
|
|
42
|
+
return `${border.width}px solid ${color}`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Generates CSS border radius style for corners
|
|
46
|
+
* @param corners - Corner radius configuration
|
|
47
|
+
* @returns CSS border radius string
|
|
48
|
+
*/
|
|
49
|
+
function getCornerRadiusStyle(corners) {
|
|
50
|
+
return `${corners.top_leading}px ${corners.top_trailing}px ${corners.bottom_trailing}px ${corners.bottom_leading}px`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generates comprehensive component styles including spacing, colors, borders and shadows
|
|
54
|
+
* @param params - Component style configuration object
|
|
55
|
+
* @returns CSS style object with component styles
|
|
56
|
+
*/
|
|
57
|
+
export function getComponentStyles({ backgroundColor, border, margin, padding, textColor, colorMode = "light", shape, shadow, }) {
|
|
58
|
+
const stylesObject = {
|
|
59
|
+
"--margin-block-start": "0px",
|
|
60
|
+
"--margin-inline-end": "0px",
|
|
61
|
+
"--margin-block-end": "0px",
|
|
62
|
+
"--margin-inline-start": "0px",
|
|
63
|
+
"--padding-block-start": "0px",
|
|
64
|
+
"--padding-inline-end": "0px",
|
|
65
|
+
"--padding-block-end": "0px",
|
|
66
|
+
"--padding-inline-start": "0px",
|
|
67
|
+
"--background-color": "transparent",
|
|
68
|
+
"--text-color": "#000000",
|
|
69
|
+
"--border": "none",
|
|
70
|
+
"--border-radius": "0px",
|
|
71
|
+
"--shadow": "none",
|
|
72
|
+
};
|
|
73
|
+
if (padding) {
|
|
74
|
+
Object.assign(stylesObject, getSpacingStyle(padding, "padding"));
|
|
75
|
+
}
|
|
76
|
+
if (margin) {
|
|
77
|
+
Object.assign(stylesObject, getSpacingStyle(margin, "margin"));
|
|
78
|
+
}
|
|
79
|
+
if (backgroundColor) {
|
|
80
|
+
stylesObject["--background-color"] = getColor({
|
|
81
|
+
colorMap: backgroundColor,
|
|
82
|
+
colorMode,
|
|
83
|
+
fallback: "transparent",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (textColor) {
|
|
87
|
+
stylesObject["--text-color"] = getColor({
|
|
88
|
+
colorMap: textColor,
|
|
89
|
+
colorMode,
|
|
90
|
+
fallback: "#000000",
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
if (border) {
|
|
94
|
+
stylesObject["--border"] = getBorderStyle(border, colorMode);
|
|
95
|
+
}
|
|
96
|
+
if (shape?.type === "rectangle" && shape.corners) {
|
|
97
|
+
stylesObject["--border-radius"] = getCornerRadiusStyle(shape.corners);
|
|
98
|
+
}
|
|
99
|
+
if (shape?.type === "pill") {
|
|
100
|
+
stylesObject["--border-radius"] = "9999px;";
|
|
101
|
+
}
|
|
102
|
+
if (shadow) {
|
|
103
|
+
stylesObject["--shadow"] = `${shadow.x}px ${shadow.y}px ${shadow.radius}px
|
|
104
|
+
${getColor({ colorMap: shadow.color, colorMode, fallback: "#000000" })};`;
|
|
105
|
+
}
|
|
106
|
+
return stylesObject;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Generates size-related CSS styles for components
|
|
110
|
+
* @param size - Size configuration object
|
|
111
|
+
* @returns CSS style object with size properties
|
|
112
|
+
*/
|
|
113
|
+
export function getSizeStyle(size) {
|
|
114
|
+
function getSizeValue(size) {
|
|
115
|
+
if (size.type === "fixed") {
|
|
116
|
+
return `${size.value}px`;
|
|
117
|
+
}
|
|
118
|
+
if (size.type === "fit") {
|
|
119
|
+
return "fit-content";
|
|
120
|
+
}
|
|
121
|
+
if (size.type === "fill") {
|
|
122
|
+
const userAgent = navigator.userAgent;
|
|
123
|
+
const isFirefox = userAgent.match(/firefox|fxios/i);
|
|
124
|
+
return isFirefox ? "-moz-available" : "-webkit-fill-available";
|
|
125
|
+
}
|
|
126
|
+
return "unset";
|
|
127
|
+
}
|
|
128
|
+
const width = getSizeValue(size.width);
|
|
129
|
+
const height = getSizeValue(size.height);
|
|
130
|
+
const isGrow = size.width.type === "fill" || size.height.type === "fill";
|
|
131
|
+
return {
|
|
132
|
+
"--width": width,
|
|
133
|
+
"--height": height,
|
|
134
|
+
"--flex": isGrow ? "unset" : "0 1 auto",
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Generates gradient background styles
|
|
139
|
+
* @param colorMode - Color mode (light/dark)
|
|
140
|
+
* @param gradientColors - Array of colors for gradient
|
|
141
|
+
* @returns CSS style object with gradient background
|
|
142
|
+
*/
|
|
143
|
+
export function getGradientStyle(colorMode, gradientColors) {
|
|
144
|
+
if (!gradientColors)
|
|
145
|
+
return { "--background": "unset" };
|
|
146
|
+
return {
|
|
147
|
+
"--background": `linear-gradient(${gradientColors.map((color) => color[colorMode]?.value).join(", ")})`,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generates mask styles for images
|
|
152
|
+
* @param maskShape - Shape configuration for image mask
|
|
153
|
+
* @returns CSS style object with mask properties
|
|
154
|
+
*/
|
|
155
|
+
export const getMaskStyle = (maskShape) => {
|
|
156
|
+
let maskStyles = {
|
|
157
|
+
"--corner-radius": "0px",
|
|
158
|
+
"--clip-path": "none",
|
|
159
|
+
};
|
|
160
|
+
if (maskShape?.type === "circle") {
|
|
161
|
+
maskStyles["--corner-radius"] = "50%";
|
|
162
|
+
}
|
|
163
|
+
if (maskShape?.type === "rectangle" && maskShape.corners) {
|
|
164
|
+
maskStyles["--corner-radius"] = getCornerRadiusStyle(maskShape.corners);
|
|
165
|
+
}
|
|
166
|
+
// TODO: rework this implementation
|
|
167
|
+
if (maskShape?.type === "convex") {
|
|
168
|
+
maskStyles["--corner-radius"] = "0 0 50% 50%;";
|
|
169
|
+
}
|
|
170
|
+
if (maskShape?.type === "concave") {
|
|
171
|
+
maskStyles["--clip-path"] =
|
|
172
|
+
"polygon(0 0, 100% 0, 100% 100%, 50% 110%, 0 100%);";
|
|
173
|
+
}
|
|
174
|
+
return maskStyles;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Generates dimension-related styles for stack components
|
|
178
|
+
* @param dimension - Dimension configuration object
|
|
179
|
+
* @returns CSS style object with flex layout properties
|
|
180
|
+
*/
|
|
181
|
+
export function getDimensionStyle(dimension) {
|
|
182
|
+
const styles = {
|
|
183
|
+
"--direction": "row",
|
|
184
|
+
"--alignment": "unset",
|
|
185
|
+
"--distribution": "unset",
|
|
186
|
+
};
|
|
187
|
+
if (dimension.type === "zlayer") {
|
|
188
|
+
// TODO: Review with Monetization team
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
styles["--direction"] = StackDirection[dimension.type];
|
|
192
|
+
styles["--alignment"] = StackAlignment[dimension.alignment];
|
|
193
|
+
if (dimension.distribution) {
|
|
194
|
+
styles["--distribution"] = StackDistribution[dimension.distribution];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return styles;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Generates text-related styles
|
|
201
|
+
* @param props - Text component properties
|
|
202
|
+
* @returns CSS style object with text formatting properties
|
|
203
|
+
*/
|
|
204
|
+
export function getTextStyles(props) {
|
|
205
|
+
const { font_size, horizontal_alignment, font_weight, font_name } = props;
|
|
206
|
+
const styles = {
|
|
207
|
+
"--text-align": "initial",
|
|
208
|
+
"--font-weight": 400,
|
|
209
|
+
"--font-size": "initial",
|
|
210
|
+
"--font-family": "sans-serif",
|
|
211
|
+
};
|
|
212
|
+
styles["--text-align"] = horizontal_alignment;
|
|
213
|
+
styles["--font-weight"] = FontWeights[font_weight];
|
|
214
|
+
styles["--font-size"] = FontSizes[font_size];
|
|
215
|
+
styles["--font-family"] = font_name || "sans-serif";
|
|
216
|
+
return styles;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Converts a style object to a CSS string
|
|
220
|
+
* @param styles - Object containing CSS properties and values
|
|
221
|
+
* @returns CSS string
|
|
222
|
+
*/
|
|
223
|
+
export function stringifyStyles(styles) {
|
|
224
|
+
return Object.entries(styles)
|
|
225
|
+
.map(([key, value]) => `${key}: ${value};`)
|
|
226
|
+
.join("; ");
|
|
227
|
+
}
|