@draftbit/theme 50.6.2-fba047.2 → 50.6.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.
Files changed (36) hide show
  1. package/lib/commonjs/Provider.js +1 -1
  2. package/lib/commonjs/createTheme.js +1 -1
  3. package/lib/commonjs/createThemeValuesProxy.js +1 -1
  4. package/lib/commonjs/utils.js +1 -0
  5. package/lib/commonjs/validators.js +1 -1
  6. package/lib/typescript/src/Provider.js +29 -12
  7. package/lib/typescript/src/Provider.js.map +1 -1
  8. package/lib/typescript/src/createTheme.d.ts +1 -13
  9. package/lib/typescript/src/createTheme.js +19 -7
  10. package/lib/typescript/src/createTheme.js.map +1 -1
  11. package/lib/typescript/src/createThemeValuesProxy.d.ts +9 -1
  12. package/lib/typescript/src/createThemeValuesProxy.js +26 -24
  13. package/lib/typescript/src/createThemeValuesProxy.js.map +1 -1
  14. package/lib/typescript/src/utils.d.ts +3 -0
  15. package/lib/typescript/src/utils.js +18 -0
  16. package/lib/typescript/src/utils.js.map +1 -0
  17. package/lib/typescript/src/validators.d.ts +1 -3
  18. package/lib/typescript/src/validators.js +74 -10
  19. package/lib/typescript/src/validators.js.map +1 -1
  20. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +5 -3
  22. package/src/Provider.js +29 -12
  23. package/src/Provider.js.map +1 -1
  24. package/src/Provider.tsx +28 -42
  25. package/src/createTheme.js +19 -7
  26. package/src/createTheme.js.map +1 -1
  27. package/src/createTheme.ts +28 -7
  28. package/src/createThemeValuesProxy.js +26 -24
  29. package/src/createThemeValuesProxy.js.map +1 -1
  30. package/src/createThemeValuesProxy.ts +44 -90
  31. package/src/utils.js +18 -0
  32. package/src/utils.js.map +1 -0
  33. package/src/utils.ts +22 -0
  34. package/src/validators.js +74 -10
  35. package/src/validators.js.map +1 -1
  36. package/src/validators.ts +93 -12
package/src/validators.ts CHANGED
@@ -1,22 +1,103 @@
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
+ fontWeight: z.enum([
24
+ "normal",
25
+ "bold",
26
+ "100",
27
+ "200",
28
+ "300",
29
+ "400",
30
+ "500",
31
+ "600",
32
+ "700",
33
+ "800",
34
+ "900",
35
+ ]),
36
+ }),
37
+ z.object({
38
+ fontStyle: z.enum(["normal", "italic"]),
39
+ }),
40
+ z.object({
41
+ letterSpacing: z.number(),
42
+ }),
43
+ z.object({
44
+ lineHeight: z.number(),
45
+ }),
46
+ ]);
47
+
48
+ const ThemeValuesSchema: z.ZodType<ThemeValues> = z.record(
49
+ z.string(),
50
+ z.lazy(() =>
51
+ z.union([z.string(), z.number(), TextStyleSchema, ThemeValuesSchema])
52
+ )
53
+ );
54
+
55
+ const TextStyleOrThemeValuesSchema: z.ZodType<ThemeValues | TextStyle> =
56
+ z.union([TextStyleSchema, ThemeValuesSchema]);
57
+
58
+ const ThemeSchema: z.ZodType<Theme> = z.object({
59
+ name: z.string(),
60
+ colors: z.object({
61
+ branding: ThemeValuesSchema.optional(),
62
+ text: ThemeValuesSchema.optional(),
63
+ background: ThemeValuesSchema.optional(),
64
+ foreground: ThemeValuesSchema.optional(),
65
+ border: ThemeValuesSchema.optional(),
66
+ }),
67
+ typography: z.object({
68
+ body1: TextStyleOrThemeValuesSchema.optional(),
69
+ body2: TextStyleOrThemeValuesSchema.optional(),
70
+ button: TextStyleOrThemeValuesSchema.optional(),
71
+ caption: TextStyleOrThemeValuesSchema.optional(),
72
+ headline1: TextStyleOrThemeValuesSchema.optional(),
73
+ headline2: TextStyleOrThemeValuesSchema.optional(),
74
+ headline3: TextStyleOrThemeValuesSchema.optional(),
75
+ headline4: TextStyleOrThemeValuesSchema.optional(),
76
+ headline5: TextStyleOrThemeValuesSchema.optional(),
77
+ headline6: TextStyleOrThemeValuesSchema.optional(),
78
+ overline: TextStyleOrThemeValuesSchema.optional(),
79
+ subtitle1: TextStyleOrThemeValuesSchema.optional(),
80
+ subtitle2: TextStyleOrThemeValuesSchema.optional(),
81
+ }),
82
+ });
2
83
 
3
84
  export function validatePalettes(palettes: ColorPalettes) {
4
- palettes;
85
+ const result = PaletteSchema.safeParse(palettes);
86
+ if (!result.success) {
87
+ throw new Error("Invalid palettes object: " + result.error.message);
88
+ }
5
89
  }
6
90
 
7
91
  export function validateBreakpoints(breakpoints: Breakpoints) {
8
- breakpoints;
92
+ const result = BreakpointSchema.safeParse(breakpoints);
93
+ if (!result.success) {
94
+ throw new Error("Invalid breakpoints object: " + result.error.message);
95
+ }
9
96
  }
10
97
 
11
98
  export function validateTheme(theme: Theme) {
12
- theme;
13
- }
14
-
15
- export function isTextStyleObject(value: any): boolean {
16
- value;
17
- return true;
18
- }
19
-
20
- export function asThemeValuesObject(value: any): ThemeValues | null {
21
- return value;
99
+ const result = ThemeSchema.safeParse(theme);
100
+ if (!result.success) {
101
+ throw new Error("Invalid theme object: " + result.error.message);
102
+ }
22
103
  }