@webstudio-is/css-data 0.3.0 → 0.4.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.
Files changed (42) hide show
  1. package/lib/__generated__/keyword-values.js +6617 -6615
  2. package/lib/__generated__/properties.js +3200 -3198
  3. package/lib/__generated__/units.js +33 -31
  4. package/lib/cjs/__generated__/keyword-values.cjs +6636 -6617
  5. package/lib/cjs/__generated__/properties.cjs +3219 -3200
  6. package/lib/cjs/__generated__/units.cjs +52 -33
  7. package/lib/cjs/index.cjs +19 -18
  8. package/lib/cjs/popularity-index.cjs +4631 -4612
  9. package/lib/cjs/schema.cjs +83 -53
  10. package/lib/popularity-index.js +4612 -4610
  11. package/lib/schema.js +62 -49
  12. package/package.json +11 -19
  13. package/src/__generated__/keyword-values.ts +6616 -0
  14. package/src/__generated__/properties.ts +3200 -0
  15. package/src/__generated__/units.ts +32 -0
  16. package/{lib/cjs/index.d.ts → src/index.ts} +0 -1
  17. package/src/popularity-index.ts +4611 -0
  18. package/src/schema.ts +103 -0
  19. package/lib/__generated__/keyword-values.d.ts +0 -302
  20. package/lib/__generated__/keyword-values.d.ts.map +0 -1
  21. package/lib/__generated__/properties.d.ts +0 -3199
  22. package/lib/__generated__/properties.d.ts.map +0 -1
  23. package/lib/__generated__/units.d.ts +0 -2
  24. package/lib/__generated__/units.d.ts.map +0 -1
  25. package/lib/cjs/__generated__/keyword-values.d.ts +0 -302
  26. package/lib/cjs/__generated__/keyword-values.d.ts.map +0 -1
  27. package/lib/cjs/__generated__/properties.d.ts +0 -3199
  28. package/lib/cjs/__generated__/properties.d.ts.map +0 -1
  29. package/lib/cjs/__generated__/units.d.ts +0 -2
  30. package/lib/cjs/__generated__/units.d.ts.map +0 -1
  31. package/lib/cjs/index.d.ts.map +0 -1
  32. package/lib/cjs/popularity-index.d.ts +0 -7
  33. package/lib/cjs/popularity-index.d.ts.map +0 -1
  34. package/lib/cjs/schema.d.ts +0 -607
  35. package/lib/cjs/schema.d.ts.map +0 -1
  36. package/lib/index.d.ts +0 -5
  37. package/lib/index.d.ts.map +0 -1
  38. package/lib/popularity-index.d.ts +0 -7
  39. package/lib/popularity-index.d.ts.map +0 -1
  40. package/lib/schema.d.ts +0 -607
  41. package/lib/schema.d.ts.map +0 -1
  42. package/lib/tsconfig.tsbuildinfo +0 -1
package/src/schema.ts ADDED
@@ -0,0 +1,103 @@
1
+ import { units } from "./__generated__/units";
2
+ import { properties } from "./__generated__/properties";
3
+ import { z } from "zod";
4
+
5
+ type Properties = typeof properties & {
6
+ [custom: CustomProperty]: {
7
+ appliesTo: "allElements";
8
+ initial: string;
9
+ inherited: boolean;
10
+ };
11
+ };
12
+
13
+ export type StyleProperty = keyof Properties;
14
+
15
+ type CustomProperty = `--${string}`;
16
+
17
+ export type AppliesTo = Properties[StyleProperty]["appliesTo"];
18
+
19
+ export const Unit = z.union([z.enum(units), z.literal("number")]);
20
+
21
+ export type Unit = z.infer<typeof Unit>;
22
+
23
+ export const UnitValue = z.object({
24
+ type: z.literal("unit"),
25
+ unit: Unit,
26
+ value: z.number(),
27
+ });
28
+
29
+ export type UnitValue = z.infer<typeof UnitValue>;
30
+
31
+ export const KeywordValue = z.object({
32
+ type: z.literal("keyword"),
33
+ // @todo use exact type
34
+ value: z.string(),
35
+ });
36
+ export type KeywordValue = z.infer<typeof KeywordValue>;
37
+
38
+ export const FontFamilyValue = z.object({
39
+ type: z.literal("fontFamily"),
40
+ value: z.array(z.string()),
41
+ });
42
+ export type FontFamilyValue = z.infer<typeof FontFamilyValue>;
43
+
44
+ // We want to be able to render the invalid value
45
+ // and show it is invalid visually, without saving it to the db
46
+ export const InvalidValue = z.object({
47
+ type: z.literal("invalid"),
48
+ value: z.string(),
49
+ });
50
+ export type InvalidValue = z.infer<typeof InvalidValue>;
51
+
52
+ export const UnsetValue = z.object({
53
+ type: z.literal("unset"),
54
+ value: z.literal(""),
55
+ });
56
+ export type UnsetValue = z.infer<typeof UnsetValue>;
57
+
58
+ export const validStaticValueTypes = ["unit", "keyword", "fontFamily"] as const;
59
+
60
+ export const ValidStaticStyleValue = z.union([
61
+ UnitValue,
62
+ KeywordValue,
63
+ FontFamilyValue,
64
+ ]);
65
+ export type ValidStaticStyleValue = z.infer<typeof ValidStaticStyleValue>;
66
+
67
+ export const VarValue = z.object({
68
+ type: z.literal("var"),
69
+ value: z.string(),
70
+ fallbacks: z.array(ValidStaticStyleValue),
71
+ });
72
+ export type VarValue = z.infer<typeof VarValue>;
73
+
74
+ export const StyleValue = z.union([
75
+ ValidStaticStyleValue,
76
+ InvalidValue,
77
+ UnsetValue,
78
+ VarValue,
79
+ ]);
80
+ export type StyleValue = z.infer<typeof StyleValue>;
81
+
82
+ export const Style = z.record(z.string(), StyleValue);
83
+
84
+ export type Style = {
85
+ [property in StyleProperty]?: StyleValue;
86
+ } & { [property: CustomProperty]: StyleValue };
87
+
88
+ export const CssRule = z.object({
89
+ style: Style,
90
+ breakpoint: z.optional(z.string()),
91
+ });
92
+
93
+ export type CssRule = z.infer<typeof CssRule>;
94
+
95
+ export const Breakpoint = z.object({
96
+ id: z.string(),
97
+ label: z.string(),
98
+ minWidth: z.number(),
99
+ });
100
+
101
+ export const Breakpoints = z.array(Breakpoint);
102
+
103
+ export type Breakpoint = z.infer<typeof Breakpoint>;