@webstudio-is/css-data 0.19.0 → 0.20.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.
@@ -1,32 +1,63 @@
1
- // This file was generated by yarn mdn-data
2
- export const units = [
3
- "ch",
4
- "cm",
5
- "deg",
6
- "dpcm",
7
- "dpi",
8
- "dppx",
9
- "em",
10
- "ex",
11
- "fr",
12
- "grad",
13
- "Hz",
14
- "in",
15
- "kHz",
16
- "mm",
17
- "ms",
18
- "pc",
19
- "pt",
20
- "px",
21
- "Q",
22
- "rad",
23
- "rem",
24
- "s",
25
- "turn",
26
- "vh",
27
- "vmax",
28
- "vmin",
29
- "vw",
30
- "x",
31
- "%",
32
- ] as const;
1
+ // This file was generated by pnpm mdn-data
2
+ export const units = {
3
+ number: [],
4
+ percentage: ["%"],
5
+ angle: ["deg", "grad", "rad", "turn"],
6
+ decibel: ["db"],
7
+ flex: ["fr"],
8
+ frequency: ["hz", "khz"],
9
+ length: [
10
+ "cm",
11
+ "mm",
12
+ "q",
13
+ "in",
14
+ "pt",
15
+ "pc",
16
+ "px",
17
+ "em",
18
+ "rem",
19
+ "ex",
20
+ "rex",
21
+ "cap",
22
+ "rcap",
23
+ "ch",
24
+ "rch",
25
+ "ic",
26
+ "ric",
27
+ "lh",
28
+ "rlh",
29
+ "vw",
30
+ "svw",
31
+ "lvw",
32
+ "dvw",
33
+ "vh",
34
+ "svh",
35
+ "lvh",
36
+ "dvh",
37
+ "vi",
38
+ "svi",
39
+ "lvi",
40
+ "dvi",
41
+ "vb",
42
+ "svb",
43
+ "lvb",
44
+ "dvb",
45
+ "vmin",
46
+ "svmin",
47
+ "lvmin",
48
+ "dvmin",
49
+ "vmax",
50
+ "svmax",
51
+ "lvmax",
52
+ "dvmax",
53
+ "cqw",
54
+ "cqh",
55
+ "cqi",
56
+ "cqb",
57
+ "cqmin",
58
+ "cqmax",
59
+ ],
60
+ resolution: ["dpi", "dpcm", "dppx", "x"],
61
+ semitones: ["st"],
62
+ time: ["s", "ms"],
63
+ } as const;
package/src/schema.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { units } from "./__generated__/units";
2
2
  import { properties } from "./__generated__/properties";
3
3
  import { z } from "zod";
4
+ import { ImageAsset } from "@webstudio-is/asset-uploader";
4
5
 
5
6
  type Properties = typeof properties & {
6
7
  [custom: CustomProperty]: {
@@ -16,7 +17,16 @@ type CustomProperty = `--${string}`;
16
17
 
17
18
  export type AppliesTo = Properties[StyleProperty]["appliesTo"];
18
19
 
19
- const Unit = z.union([z.enum(units), z.literal("number")]);
20
+ export type UnitGroup = keyof typeof units;
21
+
22
+ type UnitEnum = typeof units[UnitGroup][number];
23
+
24
+ const Unit = z.union([
25
+ // expected tuple with at least single element
26
+ // so cast to tuple with single union element to get correct inference
27
+ z.enum(Object.values(units).flat() as [UnitEnum]),
28
+ z.literal("number"),
29
+ ]);
20
30
 
21
31
  export type Unit = z.infer<typeof Unit>;
22
32
 
@@ -50,6 +60,13 @@ const RgbValue = z.object({
50
60
  });
51
61
  export type RgbValue = z.infer<typeof RgbValue>;
52
62
 
63
+ export const ImageValue = z.object({
64
+ type: z.literal("image"),
65
+ value: z.array(z.object({ type: z.literal("asset"), value: ImageAsset })),
66
+ });
67
+
68
+ export type ImageValue = z.infer<typeof ImageValue>;
69
+
53
70
  // We want to be able to render the invalid value
54
71
  // and show it is invalid visually, without saving it to the db
55
72
  const InvalidValue = z.object({
@@ -69,14 +86,22 @@ export const validStaticValueTypes = [
69
86
  "keyword",
70
87
  "fontFamily",
71
88
  "rgb",
89
+ "image",
72
90
  ] as const;
73
91
 
74
- const ValidStaticStyleValue = z.union([
92
+ /**
93
+ * Shared zod types with DB types.
94
+ * ImageValue in DB has a different type
95
+ */
96
+ const SharedStaticStyleValue = z.union([
75
97
  UnitValue,
76
98
  KeywordValue,
77
99
  FontFamilyValue,
78
100
  RgbValue,
79
101
  ]);
102
+
103
+ const ValidStaticStyleValue = z.union([ImageValue, SharedStaticStyleValue]);
104
+
80
105
  export type ValidStaticStyleValue = z.infer<typeof ValidStaticStyleValue>;
81
106
 
82
107
  const VarValue = z.object({
@@ -91,8 +116,18 @@ const StyleValue = z.union([
91
116
  InvalidValue,
92
117
  UnsetValue,
93
118
  VarValue,
94
- RgbValue,
95
119
  ]);
120
+
121
+ /**
122
+ * Shared types with DB types
123
+ */
124
+ export const SharedStyleValue = z.union([
125
+ SharedStaticStyleValue,
126
+ InvalidValue,
127
+ UnsetValue,
128
+ VarValue,
129
+ ]);
130
+
96
131
  export type StyleValue = z.infer<typeof StyleValue>;
97
132
 
98
133
  const Style = z.record(z.string(), StyleValue);