@draftbit/theme 50.5.3-22879.2 → 50.5.3-9ae597.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/lib/commonjs/DefaultTheme.js +1 -1
- package/lib/commonjs/Provider.js +1 -1
- package/lib/commonjs/createThemeValuesProxy.js +1 -1
- package/lib/commonjs/types.js +0 -1
- package/lib/commonjs/validators.js +1 -1
- package/lib/typescript/src/DefaultTheme.js +38 -38
- package/lib/typescript/src/DefaultTheme.js.map +1 -1
- package/lib/typescript/src/Provider.js +10 -38
- package/lib/typescript/src/Provider.js.map +1 -1
- package/lib/typescript/src/createThemeValuesProxy.js +19 -23
- package/lib/typescript/src/createThemeValuesProxy.js.map +1 -1
- package/lib/typescript/src/types.d.ts +2 -30
- package/lib/typescript/src/validators.d.ts +1 -2
- package/lib/typescript/src/validators.js +42 -62
- package/lib/typescript/src/validators.js.map +1 -1
- package/lib/typescript/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/DefaultTheme.js +38 -38
- package/src/DefaultTheme.js.map +1 -1
- package/src/DefaultTheme.ts +38 -38
- package/src/Provider.js +10 -38
- package/src/Provider.js.map +1 -1
- package/src/Provider.tsx +36 -60
- package/src/createThemeValuesProxy.js +19 -23
- package/src/createThemeValuesProxy.js.map +1 -1
- package/src/createThemeValuesProxy.ts +23 -32
- package/src/types.ts +2 -33
- package/src/validators.js +42 -62
- package/src/validators.js.map +1 -1
- package/src/validators.ts +46 -82
package/src/validators.js
CHANGED
|
@@ -1,72 +1,52 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
const PaletteSchema = z.record(z.string(), z.record(z.string(), z.string()));
|
|
3
|
-
const BreakpointSchema = z.record(z.string(), z.number());
|
|
4
|
-
const TextStyleSchema = z.union([
|
|
5
|
-
z.object({
|
|
6
|
-
fontSize: z.number(),
|
|
7
|
-
}),
|
|
8
|
-
z.object({
|
|
9
|
-
fontFamily: z.string(),
|
|
10
|
-
}),
|
|
11
|
-
z.object({
|
|
12
|
-
letterSpacing: z.number(),
|
|
13
|
-
}),
|
|
14
|
-
z.object({
|
|
15
|
-
lineHeight: z.number(),
|
|
16
|
-
}),
|
|
17
|
-
]);
|
|
18
|
-
const ThemeValuesSchema = z.record(z.string(), z.lazy(() => z.union([z.string(), z.number(), TextStyleSchema, ThemeValuesSchema])));
|
|
19
|
-
const TextStyleOrThemeValuesSchema = z.union([TextStyleSchema, ThemeValuesSchema]);
|
|
20
|
-
const ThemeSchema = z.object({
|
|
21
|
-
name: z.string(),
|
|
22
|
-
colors: z.object({
|
|
23
|
-
branding: ThemeValuesSchema.optional(),
|
|
24
|
-
text: ThemeValuesSchema.optional(),
|
|
25
|
-
background: ThemeValuesSchema.optional(),
|
|
26
|
-
foreground: ThemeValuesSchema.optional(),
|
|
27
|
-
border: ThemeValuesSchema.optional(),
|
|
28
|
-
}),
|
|
29
|
-
typography: z.object({
|
|
30
|
-
body1: TextStyleOrThemeValuesSchema.optional(),
|
|
31
|
-
body2: TextStyleOrThemeValuesSchema.optional(),
|
|
32
|
-
button: TextStyleOrThemeValuesSchema.optional(),
|
|
33
|
-
caption: TextStyleOrThemeValuesSchema.optional(),
|
|
34
|
-
headline1: TextStyleOrThemeValuesSchema.optional(),
|
|
35
|
-
headline2: TextStyleOrThemeValuesSchema.optional(),
|
|
36
|
-
headline3: TextStyleOrThemeValuesSchema.optional(),
|
|
37
|
-
headline4: TextStyleOrThemeValuesSchema.optional(),
|
|
38
|
-
headline5: TextStyleOrThemeValuesSchema.optional(),
|
|
39
|
-
headline6: TextStyleOrThemeValuesSchema.optional(),
|
|
40
|
-
overline: TextStyleOrThemeValuesSchema.optional(),
|
|
41
|
-
subtitle1: TextStyleOrThemeValuesSchema.optional(),
|
|
42
|
-
subtitle2: TextStyleOrThemeValuesSchema.optional(),
|
|
43
|
-
}),
|
|
44
|
-
});
|
|
45
1
|
export function validatePalettes(palettes) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
for (const key of Object.keys(palettes)) {
|
|
3
|
+
if (typeof key !== "string") {
|
|
4
|
+
throw new Error(`Invalid palettes object, ${key} is not a string`);
|
|
5
|
+
}
|
|
6
|
+
for (const [innerKey, value] of Object.entries(palettes[key])) {
|
|
7
|
+
if (typeof innerKey !== "string") {
|
|
8
|
+
throw new Error(`Invalid palette color key, ${innerKey} is not a string`);
|
|
9
|
+
}
|
|
10
|
+
if (typeof value !== "string") {
|
|
11
|
+
throw new Error(`Invalid palette color value, ${value} is not a string`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
49
14
|
}
|
|
50
15
|
}
|
|
51
16
|
export function validateBreakpoints(breakpoints) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
17
|
+
for (const [key, value] of Object.entries(breakpoints)) {
|
|
18
|
+
if (typeof key !== "string") {
|
|
19
|
+
throw new Error(`Invalid breakpoint key, ${key} is not a string`);
|
|
20
|
+
}
|
|
21
|
+
if (typeof value !== "number") {
|
|
22
|
+
throw new Error(`Invalid breakpoint value, ${value} is not a number`);
|
|
23
|
+
}
|
|
55
24
|
}
|
|
56
25
|
}
|
|
57
26
|
export function validateTheme(theme) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
27
|
+
function validateThemeValues(themeValue) {
|
|
28
|
+
if (themeValue === undefined || themeValue === null) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
for (const [key, value] of Object.entries(themeValue)) {
|
|
32
|
+
if (typeof key !== "string") {
|
|
33
|
+
throw new Error(`Invalid theme key, ${key} is not a string`);
|
|
34
|
+
}
|
|
35
|
+
if (value === undefined || value === null) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
else if (typeof value === "object") {
|
|
39
|
+
validateThemeValues(value);
|
|
40
|
+
}
|
|
41
|
+
else if (typeof value !== "string" && typeof value !== "number") {
|
|
42
|
+
throw new Error(`Invalid theme value, ${value} is not a string, number, or object`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
61
45
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (isTextStyle) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
return (_a = ThemeValuesSchema.safeParse(value).data) !== null && _a !== void 0 ? _a : null;
|
|
46
|
+
validateThemeValues(theme.colors.branding);
|
|
47
|
+
validateThemeValues(theme.colors.text);
|
|
48
|
+
validateThemeValues(theme.colors.foreground);
|
|
49
|
+
validateThemeValues(theme.colors.background);
|
|
50
|
+
validateThemeValues(theme.colors.border);
|
|
71
51
|
}
|
|
72
52
|
//# sourceMappingURL=validators.js.map
|
package/src/validators.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["validators.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["validators.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,gBAAgB,CAAC,QAAuB;IACtD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;QACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,kBAAkB,CAAC,CAAC;SACpE;QACD,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;YAC7D,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;gBAChC,MAAM,IAAI,KAAK,CACb,8BAA8B,QAAQ,kBAAkB,CACzD,CAAC;aACH;YACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,MAAM,IAAI,KAAK,CACb,gCAAgC,KAAK,kBAAkB,CACxD,CAAC;aACH;SACF;KACF;AACH,CAAC;AAED,MAAM,UAAU,mBAA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AAC;IAC7C,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7C,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
package/src/validators.ts
CHANGED
|
@@ -1,95 +1,59 @@
|
|
|
1
1
|
import { ColorPalettes, Breakpoints, Theme, ThemeValues } from "./types";
|
|
2
|
-
import { TextStyle } from "react-native";
|
|
3
|
-
import { z } from "zod";
|
|
4
|
-
|
|
5
|
-
const PaletteSchema: z.ZodType<ColorPalettes> = z.record(
|
|
6
|
-
z.string(),
|
|
7
|
-
z.record(z.string(), z.string())
|
|
8
|
-
);
|
|
9
|
-
|
|
10
|
-
const BreakpointSchema: z.ZodType<Breakpoints> = z.record(
|
|
11
|
-
z.string(),
|
|
12
|
-
z.number()
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
const TextStyleSchema: z.ZodType<TextStyle> = z.union([
|
|
16
|
-
z.object({
|
|
17
|
-
fontSize: z.number(),
|
|
18
|
-
}),
|
|
19
|
-
z.object({
|
|
20
|
-
fontFamily: z.string(),
|
|
21
|
-
}),
|
|
22
|
-
z.object({
|
|
23
|
-
letterSpacing: z.number(),
|
|
24
|
-
}),
|
|
25
|
-
z.object({
|
|
26
|
-
lineHeight: z.number(),
|
|
27
|
-
}),
|
|
28
|
-
]);
|
|
29
|
-
|
|
30
|
-
const ThemeValuesSchema: z.ZodType<ThemeValues> = z.record(
|
|
31
|
-
z.string(),
|
|
32
|
-
z.lazy(() =>
|
|
33
|
-
z.union([z.string(), z.number(), TextStyleSchema, ThemeValuesSchema])
|
|
34
|
-
)
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const TextStyleOrThemeValuesSchema: z.ZodType<ThemeValues | TextStyle> =
|
|
38
|
-
z.union([TextStyleSchema, ThemeValuesSchema]);
|
|
39
|
-
|
|
40
|
-
const ThemeSchema: z.ZodType<Theme> = z.object({
|
|
41
|
-
name: z.string(),
|
|
42
|
-
colors: z.object({
|
|
43
|
-
branding: ThemeValuesSchema.optional(),
|
|
44
|
-
text: ThemeValuesSchema.optional(),
|
|
45
|
-
background: ThemeValuesSchema.optional(),
|
|
46
|
-
foreground: ThemeValuesSchema.optional(),
|
|
47
|
-
border: ThemeValuesSchema.optional(),
|
|
48
|
-
}),
|
|
49
|
-
typography: z.object({
|
|
50
|
-
body1: TextStyleOrThemeValuesSchema.optional(),
|
|
51
|
-
body2: TextStyleOrThemeValuesSchema.optional(),
|
|
52
|
-
button: TextStyleOrThemeValuesSchema.optional(),
|
|
53
|
-
caption: TextStyleOrThemeValuesSchema.optional(),
|
|
54
|
-
headline1: TextStyleOrThemeValuesSchema.optional(),
|
|
55
|
-
headline2: TextStyleOrThemeValuesSchema.optional(),
|
|
56
|
-
headline3: TextStyleOrThemeValuesSchema.optional(),
|
|
57
|
-
headline4: TextStyleOrThemeValuesSchema.optional(),
|
|
58
|
-
headline5: TextStyleOrThemeValuesSchema.optional(),
|
|
59
|
-
headline6: TextStyleOrThemeValuesSchema.optional(),
|
|
60
|
-
overline: TextStyleOrThemeValuesSchema.optional(),
|
|
61
|
-
subtitle1: TextStyleOrThemeValuesSchema.optional(),
|
|
62
|
-
subtitle2: TextStyleOrThemeValuesSchema.optional(),
|
|
63
|
-
}),
|
|
64
|
-
});
|
|
65
2
|
|
|
66
3
|
export function validatePalettes(palettes: ColorPalettes) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
4
|
+
for (const key of Object.keys(palettes)) {
|
|
5
|
+
if (typeof key !== "string") {
|
|
6
|
+
throw new Error(`Invalid palettes object, ${key} is not a string`);
|
|
7
|
+
}
|
|
8
|
+
for (const [innerKey, value] of Object.entries(palettes[key])) {
|
|
9
|
+
if (typeof innerKey !== "string") {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Invalid palette color key, ${innerKey} is not a string`
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
if (typeof value !== "string") {
|
|
15
|
+
throw new Error(
|
|
16
|
+
`Invalid palette color value, ${value} is not a string`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
70
20
|
}
|
|
71
21
|
}
|
|
72
22
|
|
|
73
23
|
export function validateBreakpoints(breakpoints: Breakpoints) {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
24
|
+
for (const [key, value] of Object.entries(breakpoints)) {
|
|
25
|
+
if (typeof key !== "string") {
|
|
26
|
+
throw new Error(`Invalid breakpoint key, ${key} is not a string`);
|
|
27
|
+
}
|
|
28
|
+
if (typeof value !== "number") {
|
|
29
|
+
throw new Error(`Invalid breakpoint value, ${value} is not a number`);
|
|
30
|
+
}
|
|
77
31
|
}
|
|
78
32
|
}
|
|
79
33
|
|
|
80
34
|
export function validateTheme(theme: Theme) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
35
|
+
function validateThemeValues(themeValue?: ThemeValues) {
|
|
36
|
+
if (themeValue === undefined || themeValue === null) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const [key, value] of Object.entries(themeValue)) {
|
|
40
|
+
if (typeof key !== "string") {
|
|
41
|
+
throw new Error(`Invalid theme key, ${key} is not a string`);
|
|
42
|
+
}
|
|
43
|
+
if (value === undefined || value === null) {
|
|
44
|
+
continue;
|
|
45
|
+
} else if (typeof value === "object") {
|
|
46
|
+
validateThemeValues(value);
|
|
47
|
+
} else if (typeof value !== "string" && typeof value !== "number") {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Invalid theme value, ${value} is not a string, number, or object`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
84
53
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (isTextStyle) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return ThemeValuesSchema.safeParse(value).data ?? null;
|
|
54
|
+
validateThemeValues(theme.colors.branding);
|
|
55
|
+
validateThemeValues(theme.colors.text);
|
|
56
|
+
validateThemeValues(theme.colors.foreground);
|
|
57
|
+
validateThemeValues(theme.colors.background);
|
|
58
|
+
validateThemeValues(theme.colors.border);
|
|
95
59
|
}
|