@webstudio-is/sdk-components-react-radix 0.91.0 → 0.92.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 (199) hide show
  1. package/lib/__generated__/accordion.props.js +6 -12
  2. package/lib/__generated__/checkbox.props.js +3 -6
  3. package/lib/__generated__/collapsible.props.js +4 -8
  4. package/lib/__generated__/dialog.props.js +8 -16
  5. package/lib/__generated__/label.props.js +2 -4
  6. package/lib/__generated__/navigation-menu.props.js +8 -16
  7. package/lib/__generated__/popover.props.js +4 -8
  8. package/lib/__generated__/radio-group.props.js +4 -8
  9. package/lib/__generated__/select.props.js +15 -19
  10. package/lib/__generated__/sheet.props.js +8 -16
  11. package/lib/__generated__/switch.props.js +3 -6
  12. package/lib/__generated__/tabs.props.js +5 -10
  13. package/lib/__generated__/tooltip.props.js +4 -8
  14. package/lib/accordion.js +7 -14
  15. package/{src/accordion.stories.tsx → lib/accordion.stories.js} +9 -12
  16. package/lib/accordion.ws.js +11 -22
  17. package/lib/checkbox.js +3 -6
  18. package/lib/checkbox.stories.js +19 -0
  19. package/lib/checkbox.ws.js +5 -10
  20. package/lib/collapsible.js +5 -10
  21. package/{src/collapsible.stories.tsx → lib/collapsible.stories.js} +9 -12
  22. package/lib/collapsible.ws.js +7 -14
  23. package/lib/components.js +13 -62
  24. package/lib/dialog.js +9 -18
  25. package/{src/dialog.stories.tsx → lib/dialog.stories.js} +9 -12
  26. package/lib/dialog.ws.js +15 -30
  27. package/lib/hooks.js +2 -4
  28. package/lib/label.js +2 -4
  29. package/lib/label.stories.js +19 -0
  30. package/lib/label.ws.js +3 -6
  31. package/lib/metas.js +55 -105
  32. package/lib/navigation-menu.js +9 -18
  33. package/{src/navigation-menu.stories.tsx → lib/navigation-menu.stories.js} +9 -12
  34. package/lib/navigation-menu.ws.js +16 -31
  35. package/lib/popover.js +5 -10
  36. package/{src/popover.stories.tsx → lib/popover.stories.js} +9 -12
  37. package/lib/popover.ws.js +7 -14
  38. package/lib/props-descriptions.js +2 -4
  39. package/lib/props.js +54 -103
  40. package/lib/radio-group.js +4 -8
  41. package/lib/radio-group.stories.js +19 -0
  42. package/lib/radio-group.ws.js +7 -14
  43. package/lib/select.js +10 -20
  44. package/{src/select.stories.tsx → lib/select.stories.js} +9 -12
  45. package/lib/select.ws.js +17 -34
  46. package/lib/sheet.js +9 -18
  47. package/{src/sheet.stories.tsx → lib/sheet.stories.js} +9 -12
  48. package/lib/sheet.ws.js +2 -4
  49. package/lib/switch.js +3 -6
  50. package/lib/switch.stories.js +19 -0
  51. package/lib/switch.ws.js +5 -10
  52. package/lib/tabs.js +6 -12
  53. package/{src/tabs.stories.tsx → lib/tabs.stories.js} +9 -12
  54. package/lib/tabs.ws.js +9 -18
  55. package/lib/theme/__generated__/tailwind-theme.js +517 -0
  56. package/lib/theme/styles.js +3 -6
  57. package/lib/theme/tailwind-classes.js +149 -301
  58. package/lib/theme/tailwind-colors.js +2 -4
  59. package/lib/tooltip.js +5 -10
  60. package/{src/tooltip.stories.tsx → lib/tooltip.stories.js} +9 -12
  61. package/lib/tooltip.ws.js +7 -14
  62. package/lib/types/__generated__/accordion.props.d.ts +1 -1
  63. package/lib/types/__generated__/checkbox.props.d.ts +1 -1
  64. package/lib/types/__generated__/collapsible.props.d.ts +1 -1
  65. package/lib/types/__generated__/dialog.props.d.ts +1 -1
  66. package/lib/types/__generated__/label.props.d.ts +1 -1
  67. package/lib/types/__generated__/navigation-menu.props.d.ts +1 -1
  68. package/lib/types/__generated__/popover.props.d.ts +1 -1
  69. package/lib/types/__generated__/radio-group.props.d.ts +1 -1
  70. package/lib/types/__generated__/select.props.d.ts +1 -1
  71. package/lib/types/__generated__/sheet.props.d.ts +1 -1
  72. package/lib/types/__generated__/switch.props.d.ts +1 -1
  73. package/lib/types/__generated__/tabs.props.d.ts +1 -1
  74. package/lib/types/__generated__/tooltip.props.d.ts +1 -1
  75. package/lib/types/accordion.d.ts +1 -1
  76. package/lib/types/sheet.d.ts +1 -1
  77. package/lib/types/theme/__generated__/tailwind-theme.d.ts +26 -0
  78. package/lib/types/theme/styles.d.ts +60 -60
  79. package/lib/types/theme/tailwind-classes.d.ts +33 -33
  80. package/package.json +20 -23
  81. package/lib/__generated__/button.props.js +0 -565
  82. package/lib/__generated__/input.props.js +0 -668
  83. package/lib/__generated__/textarea.props.js +0 -577
  84. package/lib/cjs/__generated__/accordion.props.js +0 -2645
  85. package/lib/cjs/__generated__/button.props.js +0 -585
  86. package/lib/cjs/__generated__/checkbox.props.js +0 -1103
  87. package/lib/cjs/__generated__/collapsible.props.js +0 -1050
  88. package/lib/cjs/__generated__/dialog.props.js +0 -2623
  89. package/lib/cjs/__generated__/input.props.js +0 -688
  90. package/lib/cjs/__generated__/label.props.js +0 -541
  91. package/lib/cjs/__generated__/navigation-menu.props.js +0 -2585
  92. package/lib/cjs/__generated__/popover.props.js +0 -582
  93. package/lib/cjs/__generated__/radio-group.props.js +0 -1647
  94. package/lib/cjs/__generated__/select.props.js +0 -3698
  95. package/lib/cjs/__generated__/sheet.props.js +0 -2642
  96. package/lib/cjs/__generated__/switch.props.js +0 -1103
  97. package/lib/cjs/__generated__/tabs.props.js +0 -2144
  98. package/lib/cjs/__generated__/textarea.props.js +0 -597
  99. package/lib/cjs/__generated__/tooltip.props.js +0 -593
  100. package/lib/cjs/accordion.js +0 -67
  101. package/lib/cjs/accordion.ws.js +0 -285
  102. package/lib/cjs/checkbox.js +0 -31
  103. package/lib/cjs/checkbox.ws.js +0 -174
  104. package/lib/cjs/collapsible.js +0 -53
  105. package/lib/cjs/collapsible.ws.js +0 -122
  106. package/lib/cjs/components.js +0 -82
  107. package/lib/cjs/dialog.js +0 -89
  108. package/lib/cjs/dialog.ws.js +0 -315
  109. package/lib/cjs/hooks.js +0 -43
  110. package/lib/cjs/label.js +0 -37
  111. package/lib/cjs/label.ws.js +0 -75
  112. package/lib/cjs/metas.js +0 -84
  113. package/lib/cjs/navigation-menu.js +0 -107
  114. package/lib/cjs/navigation-menu.ws.js +0 -514
  115. package/lib/cjs/package.json +0 -1
  116. package/lib/cjs/popover.js +0 -90
  117. package/lib/cjs/popover.ws.js +0 -142
  118. package/lib/cjs/props-descriptions.js +0 -56
  119. package/lib/cjs/props.js +0 -82
  120. package/lib/cjs/radio-group.js +0 -30
  121. package/lib/cjs/radio-group.ws.js +0 -191
  122. package/lib/cjs/select.js +0 -83
  123. package/lib/cjs/select.ws.js +0 -350
  124. package/lib/cjs/sheet.js +0 -96
  125. package/lib/cjs/sheet.ws.js +0 -257
  126. package/lib/cjs/switch.js +0 -27
  127. package/lib/cjs/switch.ws.js +0 -173
  128. package/lib/cjs/tabs.js +0 -59
  129. package/lib/cjs/tabs.ws.js +0 -196
  130. package/lib/cjs/theme/radix-common-types.js +0 -16
  131. package/lib/cjs/theme/styles.js +0 -96
  132. package/lib/cjs/theme/tailwind-classes.js +0 -819
  133. package/lib/cjs/theme/tailwind-colors.js +0 -45
  134. package/lib/cjs/theme/tailwind-theme.js +0 -46
  135. package/lib/cjs/tooltip.js +0 -87
  136. package/lib/cjs/tooltip.ws.js +0 -143
  137. package/lib/theme/radix-common-types.js +0 -0
  138. package/lib/theme/tailwind-theme.js +0 -16
  139. package/lib/types/__generated__/button.props.d.ts +0 -2
  140. package/lib/types/__generated__/input.props.d.ts +0 -2
  141. package/lib/types/__generated__/textarea.props.d.ts +0 -2
  142. package/lib/types/theme/radix-common-types.d.ts +0 -85
  143. package/lib/types/theme/tailwind-theme.d.ts +0 -72
  144. package/src/__generated__/accordion.props.ts +0 -2949
  145. package/src/__generated__/button.props.ts +0 -635
  146. package/src/__generated__/checkbox.props.ts +0 -1217
  147. package/src/__generated__/collapsible.props.ts +0 -1156
  148. package/src/__generated__/dialog.props.ts +0 -2923
  149. package/src/__generated__/input.props.ts +0 -748
  150. package/src/__generated__/label.props.ts +0 -585
  151. package/src/__generated__/navigation-menu.props.ts +0 -2882
  152. package/src/__generated__/popover.props.ts +0 -626
  153. package/src/__generated__/radio-group.props.ts +0 -1828
  154. package/src/__generated__/select.props.ts +0 -4130
  155. package/src/__generated__/sheet.props.ts +0 -2942
  156. package/src/__generated__/switch.props.ts +0 -1217
  157. package/src/__generated__/tabs.props.ts +0 -2386
  158. package/src/__generated__/textarea.props.ts +0 -645
  159. package/src/__generated__/tooltip.props.ts +0 -639
  160. package/src/accordion.tsx +0 -88
  161. package/src/accordion.ws.ts +0 -296
  162. package/src/checkbox.stories.ts +0 -22
  163. package/src/checkbox.tsx +0 -22
  164. package/src/checkbox.ws.ts +0 -154
  165. package/src/collapsible.tsx +0 -62
  166. package/src/collapsible.ws.ts +0 -115
  167. package/src/components.ts +0 -50
  168. package/src/dialog.tsx +0 -92
  169. package/src/dialog.ws.tsx +0 -320
  170. package/src/hooks.ts +0 -22
  171. package/src/label.stories.ts +0 -22
  172. package/src/label.tsx +0 -15
  173. package/src/label.ws.ts +0 -50
  174. package/src/metas.ts +0 -74
  175. package/src/navigation-menu.tsx +0 -130
  176. package/src/navigation-menu.ws.ts +0 -524
  177. package/src/popover.tsx +0 -96
  178. package/src/popover.ws.tsx +0 -128
  179. package/src/props-descriptions.ts +0 -43
  180. package/src/props.ts +0 -73
  181. package/src/radio-group.stories.ts +0 -22
  182. package/src/radio-group.tsx +0 -17
  183. package/src/radio-group.ws.ts +0 -178
  184. package/src/select.tsx +0 -112
  185. package/src/select.ws.ts +0 -349
  186. package/src/sheet.tsx +0 -79
  187. package/src/sheet.ws.tsx +0 -236
  188. package/src/switch.stories.ts +0 -22
  189. package/src/switch.tsx +0 -10
  190. package/src/switch.ws.ts +0 -146
  191. package/src/tabs.tsx +0 -64
  192. package/src/tabs.ws.ts +0 -198
  193. package/src/theme/radix-common-types.ts +0 -496
  194. package/src/theme/styles.ts +0 -76
  195. package/src/theme/tailwind-classes.ts +0 -1026
  196. package/src/theme/tailwind-colors.ts +0 -39
  197. package/src/theme/tailwind-theme.ts +0 -24
  198. package/src/tooltip.tsx +0 -95
  199. package/src/tooltip.ws.tsx +0 -130
@@ -1,1026 +0,0 @@
1
- /**
2
- * Quik and dirty implementation of tailwind classes conversion to webstudio styles.
3
- */
4
- import type { EmbedTemplateStyleDecl } from "@webstudio-is/react-sdk";
5
- import { theme } from "./tailwind-theme";
6
- import {
7
- parseCssValue,
8
- parseBoxShadow,
9
- StyleValue,
10
- type StyleProperty,
11
- } from "@webstudio-is/css-data";
12
- import type { EvaluatedDefaultTheme } from "./radix-common-types";
13
-
14
- export const property = (
15
- property: StyleProperty,
16
- value: string
17
- ): EmbedTemplateStyleDecl => {
18
- if (value.startsWith("--")) {
19
- return {
20
- property,
21
- value: { type: "var", value: value.slice(2), fallbacks: [] },
22
- };
23
- }
24
- return {
25
- property,
26
- value: { type: "unparsed", value },
27
- };
28
- };
29
-
30
- // https://github.com/tailwindlabs/tailwindcss/blob/master/src/css/preflight.css
31
- const preflight = (): EmbedTemplateStyleDecl[] => {
32
- const borderColorValue = parseCssValue("color", theme("colors")["border"]);
33
-
34
- return [
35
- {
36
- property: "borderTopStyle",
37
- value: { type: "keyword", value: "solid" },
38
- },
39
- {
40
- property: "borderRightStyle",
41
- value: { type: "keyword", value: "solid" },
42
- },
43
- {
44
- property: "borderBottomStyle",
45
- value: { type: "keyword", value: "solid" },
46
- },
47
- {
48
- property: "borderLeftStyle",
49
- value: { type: "keyword", value: "solid" },
50
- },
51
-
52
- {
53
- property: "borderTopColor",
54
- value: borderColorValue,
55
- },
56
- {
57
- property: "borderRightColor",
58
- value: borderColorValue,
59
- },
60
- {
61
- property: "borderBottomColor",
62
- value: borderColorValue,
63
- },
64
- {
65
- property: "borderLeftColor",
66
- value: borderColorValue,
67
- },
68
- ];
69
- };
70
-
71
- export const z = (
72
- zIndex?: StringEnumToNumeric<keyof EvaluatedDefaultTheme["zIndex"]>
73
- ): EmbedTemplateStyleDecl[] => {
74
- const valueString = theme("zIndex")[zIndex ?? "auto"];
75
- const value = parseCssValue("zIndex", valueString);
76
-
77
- return [
78
- {
79
- property: "zIndex",
80
- value,
81
- },
82
- ];
83
- };
84
-
85
- export const overflow = (
86
- value: "hidden" | "visible" | "scroll" | "auto"
87
- ): EmbedTemplateStyleDecl[] => [
88
- {
89
- property: "overflow",
90
- value: { type: "keyword", value },
91
- },
92
- ];
93
-
94
- export const rounded = (
95
- radius?: keyof EvaluatedDefaultTheme["borderRadius"]
96
- ): EmbedTemplateStyleDecl[] => {
97
- const valueString = theme("borderRadius")[radius ?? "DEFAULT"];
98
- const value = parseCssValue("borderTopWidth", valueString);
99
-
100
- return [
101
- {
102
- property: "borderTopLeftRadius",
103
- value,
104
- },
105
- {
106
- property: "borderTopRightRadius",
107
- value,
108
- },
109
- {
110
- property: "borderBottomRightRadius",
111
- value,
112
- },
113
- {
114
- property: "borderBottomLeftRadius",
115
- value,
116
- },
117
- ];
118
- };
119
-
120
- type StringEnumToNumeric<T extends string> = T extends `${infer Z extends
121
- number}`
122
- ? Z
123
- : never;
124
-
125
- type NonNumeric<T extends string> = T extends `${infer Z extends number}`
126
- ? never
127
- : T;
128
-
129
- export const border = (
130
- borderWidthOrColor?:
131
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["borderWidth"]>
132
- | keyof EvaluatedDefaultTheme["colors"]
133
- ): EmbedTemplateStyleDecl[] => {
134
- if (
135
- typeof borderWidthOrColor === "number" ||
136
- borderWidthOrColor === undefined
137
- ) {
138
- const key = `${borderWidthOrColor ?? "DEFAULT"}` as const;
139
-
140
- const valueString = theme("borderWidth")?.[key] ?? "1px";
141
-
142
- const value = parseCssValue("borderTopWidth", valueString);
143
- return [
144
- ...preflight(),
145
- { property: "borderTopWidth", value },
146
- { property: "borderRightWidth", value },
147
- { property: "borderBottomWidth", value },
148
- { property: "borderLeftWidth", value },
149
- ];
150
- }
151
-
152
- const value = parseCssValue("color", theme("colors")[borderWidthOrColor]);
153
-
154
- return [
155
- {
156
- property: "borderTopColor",
157
- value,
158
- },
159
- {
160
- property: "borderRightColor",
161
- value,
162
- },
163
- {
164
- property: "borderBottomColor",
165
- value,
166
- },
167
- {
168
- property: "borderLeftColor",
169
- value,
170
- },
171
- ];
172
- };
173
-
174
- export const borderB = (
175
- borderWidthOrColor?:
176
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["borderWidth"]>
177
- | keyof EvaluatedDefaultTheme["colors"]
178
- ): EmbedTemplateStyleDecl[] => {
179
- let widthValue: StyleValue = { type: "unit", value: 1, unit: "number" };
180
- let colorValue: StyleValue = parseCssValue(
181
- "color",
182
- theme("colors")["border"]
183
- );
184
- if (
185
- typeof borderWidthOrColor === "number" ||
186
- borderWidthOrColor === undefined
187
- ) {
188
- const key = `${borderWidthOrColor ?? "DEFAULT"}` as const;
189
- const valueString = theme("borderWidth")[key] ?? "1px";
190
- widthValue = parseCssValue("borderTopWidth", valueString);
191
- } else {
192
- colorValue = parseCssValue("color", theme("colors")[borderWidthOrColor]);
193
- }
194
-
195
- return [
196
- {
197
- property: "borderBottomWidth",
198
- value: widthValue,
199
- },
200
- {
201
- property: "borderBottomStyle",
202
- value: { type: "keyword", value: "solid" },
203
- },
204
- {
205
- property: "borderBottomColor",
206
- value: colorValue,
207
- },
208
- ];
209
- };
210
-
211
- const paddingProperty =
212
- (property: "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft") =>
213
- (
214
- padding:
215
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["padding"]>
216
- | NonNumeric<keyof EvaluatedDefaultTheme["padding"]>
217
- ): EmbedTemplateStyleDecl[] => {
218
- const key = `${padding}` as const;
219
- const valueString = theme("padding")?.[key] ?? "0";
220
- const value = parseCssValue(property, valueString);
221
-
222
- return [{ property, value }];
223
- };
224
-
225
- export const pt: ReturnType<typeof paddingProperty> = (padding) => {
226
- return paddingProperty("paddingTop")(padding);
227
- };
228
-
229
- export const pb: ReturnType<typeof paddingProperty> = (padding) => {
230
- return paddingProperty("paddingBottom")(padding);
231
- };
232
-
233
- export const pl: ReturnType<typeof paddingProperty> = (padding) => {
234
- return paddingProperty("paddingLeft")(padding);
235
- };
236
-
237
- export const pr: ReturnType<typeof paddingProperty> = (padding) => {
238
- return paddingProperty("paddingRight")(padding);
239
- };
240
-
241
- export const px: ReturnType<typeof paddingProperty> = (padding) => {
242
- return [pl(padding), pr(padding)].flat();
243
- };
244
-
245
- export const py: ReturnType<typeof paddingProperty> = (padding) => {
246
- return [pt(padding), pb(padding)].flat();
247
- };
248
-
249
- export const p: ReturnType<typeof paddingProperty> = (padding) => {
250
- return [px(padding), py(padding)].flat();
251
- };
252
-
253
- const marginProperty =
254
- (property: "marginTop" | "marginRight" | "marginBottom" | "marginLeft") =>
255
- (
256
- margin:
257
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["margin"]>
258
- | NonNumeric<keyof EvaluatedDefaultTheme["margin"]>
259
- ): EmbedTemplateStyleDecl[] => {
260
- const key = `${margin}` as const;
261
- const valueString = theme("margin")?.[key] ?? "0";
262
- const value = parseCssValue(property, valueString);
263
-
264
- return [{ property, value }];
265
- };
266
-
267
- export const ml: ReturnType<typeof marginProperty> = (margin) => {
268
- return marginProperty("marginLeft")(margin);
269
- };
270
-
271
- export const mr: ReturnType<typeof marginProperty> = (margin) => {
272
- return marginProperty("marginRight")(margin);
273
- };
274
-
275
- export const mt: ReturnType<typeof marginProperty> = (margin) => {
276
- return marginProperty("marginTop")(margin);
277
- };
278
-
279
- export const mb: ReturnType<typeof marginProperty> = (margin) => {
280
- return marginProperty("marginBottom")(margin);
281
- };
282
-
283
- export const mx: ReturnType<typeof marginProperty> = (margin) => {
284
- return [ml(margin), mr(margin)].flat();
285
- };
286
-
287
- export const my: ReturnType<typeof marginProperty> = (margin) => {
288
- return [mt(margin), mb(margin)].flat();
289
- };
290
-
291
- export const m: ReturnType<typeof marginProperty> = (margin) => {
292
- return [mx(margin), my(margin)].flat();
293
- };
294
-
295
- export const w = (
296
- spacing:
297
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["width"]>
298
- | NonNumeric<keyof EvaluatedDefaultTheme["width"]>
299
- ): EmbedTemplateStyleDecl[] => {
300
- const key = `${spacing}` as const;
301
- const valueString = theme("width")?.[key] ?? "0";
302
- const value = parseCssValue("width", valueString);
303
-
304
- return [{ property: "width", value }];
305
- };
306
-
307
- export const h = (
308
- spacing:
309
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["height"]>
310
- | NonNumeric<keyof EvaluatedDefaultTheme["height"]>
311
- ): EmbedTemplateStyleDecl[] => {
312
- const key = `${spacing}` as const;
313
- const valueString = theme("height")?.[key] ?? "0";
314
- const value = parseCssValue("height", valueString);
315
-
316
- return [{ property: "height", value }];
317
- };
318
-
319
- export const minH = (
320
- spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["height"]>
321
- ): EmbedTemplateStyleDecl[] => {
322
- const key = `${spacing}` as const;
323
- const valueString = theme("height")?.[key] ?? "0";
324
- const value = parseCssValue("minHeight", valueString);
325
-
326
- return [{ property: "minHeight", value }];
327
- };
328
-
329
- export const opacity = (
330
- opacity: StringEnumToNumeric<keyof EvaluatedDefaultTheme["opacity"]>
331
- ): EmbedTemplateStyleDecl[] => {
332
- const key = `${opacity}` as const;
333
- const valueString = theme("opacity")?.[key] ?? "0";
334
- const value = parseCssValue("opacity", valueString);
335
-
336
- return [
337
- {
338
- property: "opacity",
339
- value,
340
- },
341
- ];
342
- };
343
-
344
- export const cursor = (
345
- cursor: keyof EvaluatedDefaultTheme["cursor"]
346
- ): EmbedTemplateStyleDecl[] => {
347
- const valueString = theme("cursor")?.[cursor] ?? "auto";
348
- const value = parseCssValue("cursor", valueString);
349
-
350
- return [
351
- {
352
- property: "cursor",
353
- value,
354
- },
355
- ];
356
- };
357
-
358
- export const maxW = (
359
- spacing:
360
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["maxWidth"]>
361
- | NonNumeric<keyof EvaluatedDefaultTheme["maxWidth"]>
362
- ): EmbedTemplateStyleDecl[] => {
363
- const key = `${spacing}` as const;
364
- const valueString = theme("maxWidth")?.[key] ?? "0";
365
- const value = parseCssValue("width", valueString);
366
-
367
- return [{ property: "maxWidth", value }];
368
- };
369
-
370
- const positionStyle = (
371
- property: "left" | "right" | "top" | "bottom",
372
- spacing:
373
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
374
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
375
- ): EmbedTemplateStyleDecl => {
376
- const key = `${spacing}` as const;
377
- const valueString = theme("inset")?.[key] ?? "0";
378
- const value = parseCssValue(property, valueString);
379
-
380
- return { property, value };
381
- };
382
-
383
- export const top = (
384
- spacing:
385
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
386
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
387
- ): EmbedTemplateStyleDecl[] => [positionStyle("top", spacing)];
388
-
389
- export const right = (
390
- spacing:
391
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
392
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
393
- ): EmbedTemplateStyleDecl[] => [positionStyle("right", spacing)];
394
-
395
- export const bottom = (
396
- spacing:
397
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
398
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
399
- ): EmbedTemplateStyleDecl[] => [positionStyle("bottom", spacing)];
400
-
401
- export const left = (
402
- spacing:
403
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
404
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
405
- ): EmbedTemplateStyleDecl[] => [positionStyle("left", spacing)];
406
-
407
- export const inset = (
408
- spacing:
409
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["inset"]>
410
- | NonNumeric<keyof EvaluatedDefaultTheme["inset"]>
411
- ): EmbedTemplateStyleDecl[] => [
412
- positionStyle("left", spacing),
413
- positionStyle("right", spacing),
414
- positionStyle("top", spacing),
415
- positionStyle("bottom", spacing),
416
- ];
417
-
418
- export const aspect = (
419
- value: "auto" | "square" | "video"
420
- ): EmbedTemplateStyleDecl[] => {
421
- let unparsed: string = value;
422
- if (value === "square") {
423
- unparsed = "1 / 1";
424
- }
425
- if (value === "video") {
426
- unparsed = "16 / 9";
427
- }
428
- return [
429
- {
430
- property: "aspectRatio",
431
- value: { type: "unparsed", value: unparsed },
432
- },
433
- ];
434
- };
435
-
436
- export const backdropBlur = (
437
- blur: keyof EvaluatedDefaultTheme["blur"]
438
- ): EmbedTemplateStyleDecl[] => {
439
- const valueString = theme("blur")[blur];
440
- const value = {
441
- type: "unparsed" as const,
442
- value: `blur(${valueString})`,
443
- };
444
-
445
- return [{ property: "backdropFilter", value }];
446
- };
447
-
448
- export const list = (
449
- listStyle: keyof EvaluatedDefaultTheme["listStyleType"]
450
- ): EmbedTemplateStyleDecl[] => {
451
- const valueString = theme("listStyleType")[listStyle];
452
- const value = parseCssValue("listStyleType", valueString);
453
-
454
- return [{ property: "listStyleType", value }];
455
- };
456
-
457
- export const select = (selectValue: "none"): EmbedTemplateStyleDecl[] => {
458
- return [
459
- {
460
- property: "userSelect",
461
- value: {
462
- type: "keyword",
463
- value: "none",
464
- },
465
- },
466
- ];
467
- };
468
-
469
- export const bg = (
470
- color: keyof EvaluatedDefaultTheme["colors"],
471
- alpha?: number
472
- ): EmbedTemplateStyleDecl[] => {
473
- const value = parseCssValue("backgroundColor", theme("colors")[color]);
474
-
475
- if (alpha !== undefined && value.type === "rgb") {
476
- value.alpha = alpha / 100;
477
- }
478
-
479
- return [
480
- {
481
- property: "backgroundColor",
482
- value,
483
- },
484
- ];
485
- };
486
-
487
- export const fixed = (): EmbedTemplateStyleDecl[] => {
488
- return [{ property: "position", value: { type: "keyword", value: "fixed" } }];
489
- };
490
-
491
- export const relative = (): EmbedTemplateStyleDecl[] => {
492
- return [
493
- { property: "position", value: { type: "keyword", value: "relative" } },
494
- ];
495
- };
496
-
497
- export const absolute = (): EmbedTemplateStyleDecl[] => {
498
- return [
499
- { property: "position", value: { type: "keyword", value: "absolute" } },
500
- ];
501
- };
502
-
503
- export const grid = (): EmbedTemplateStyleDecl[] => {
504
- return [{ property: "display", value: { type: "keyword", value: "grid" } }];
505
- };
506
-
507
- const alignItems = {
508
- start: "flex-start",
509
- end: "flex-end",
510
- center: "center",
511
- baseline: "baseline",
512
- stretch: "stretch",
513
- } as const;
514
- type AlignItems = keyof typeof alignItems;
515
-
516
- export const items = (
517
- alignItemsParam: AlignItems
518
- ): EmbedTemplateStyleDecl[] => {
519
- return [
520
- {
521
- property: "alignItems",
522
- value: {
523
- type: "keyword",
524
- value: alignItems[alignItemsParam],
525
- },
526
- },
527
- ];
528
- };
529
-
530
- const justifyContent = {
531
- start: "flex-start",
532
- end: "flex-end",
533
- center: "center",
534
- between: "space-between",
535
- around: "space-around",
536
- evenly: "space-evenly",
537
- stretch: "stretch",
538
- } as const;
539
- type JustifyContent = keyof typeof justifyContent;
540
-
541
- export const justify = (
542
- justifyContentParam: JustifyContent
543
- ): EmbedTemplateStyleDecl[] => {
544
- return [
545
- {
546
- property: "justifyContent",
547
- value: {
548
- type: "keyword",
549
- value: justifyContent[justifyContentParam],
550
- },
551
- },
552
- ];
553
- };
554
-
555
- export const inlineFlex = (): EmbedTemplateStyleDecl[] => {
556
- return [
557
- { property: "display", value: { type: "keyword", value: "inline-flex" } },
558
- ];
559
- };
560
-
561
- export const block = (): EmbedTemplateStyleDecl[] => {
562
- return [{ property: "display", value: { type: "keyword", value: "block" } }];
563
- };
564
-
565
- const flexDirection = { row: "row", col: "column" } as const;
566
- type FlexDirection = keyof typeof flexDirection;
567
-
568
- type FlexSizing = 1 | "auto" | "initial" | "none";
569
-
570
- export const flex = (
571
- flexParam?: FlexDirection | FlexSizing
572
- ): EmbedTemplateStyleDecl[] => {
573
- if (flexParam === undefined) {
574
- return [{ property: "display", value: { type: "keyword", value: "flex" } }];
575
- }
576
-
577
- if (flexParam === 1) {
578
- return [
579
- {
580
- property: "flexGrow",
581
- value: { type: "unit", value: 1, unit: "number" },
582
- },
583
- {
584
- property: "flexShrink",
585
- value: { type: "unit", value: 1, unit: "number" },
586
- },
587
- {
588
- property: "flexBasis",
589
- value: { type: "unit", value: 0, unit: "%" },
590
- },
591
- ];
592
- }
593
-
594
- if (flexParam === "auto") {
595
- return [
596
- {
597
- property: "flexGrow",
598
- value: { type: "unit", value: 1, unit: "number" },
599
- },
600
- {
601
- property: "flexShrink",
602
- value: { type: "unit", value: 1, unit: "number" },
603
- },
604
- {
605
- property: "flexBasis",
606
- value: { type: "keyword", value: "auto" },
607
- },
608
- ];
609
- }
610
-
611
- if (flexParam === "initial") {
612
- return [
613
- {
614
- property: "flexGrow",
615
- value: { type: "unit", value: 0, unit: "number" },
616
- },
617
- {
618
- property: "flexShrink",
619
- value: { type: "unit", value: 1, unit: "number" },
620
- },
621
- {
622
- property: "flexBasis",
623
- value: { type: "keyword", value: "auto" },
624
- },
625
- ];
626
- }
627
-
628
- if (flexParam === "none") {
629
- return [
630
- {
631
- property: "flexGrow",
632
- value: { type: "unit", value: 0, unit: "number" },
633
- },
634
- {
635
- property: "flexShrink",
636
- value: { type: "unit", value: 0, unit: "number" },
637
- },
638
- {
639
- property: "flexBasis",
640
- value: { type: "keyword", value: "auto" },
641
- },
642
- ];
643
- }
644
-
645
- return [
646
- {
647
- property: "flexDirection",
648
- value: {
649
- type: "keyword",
650
- value: flexDirection[flexParam],
651
- },
652
- },
653
- ];
654
- };
655
-
656
- export const grow = (): EmbedTemplateStyleDecl[] => {
657
- return [
658
- {
659
- property: "flexGrow",
660
- value: { type: "unit", value: 1, unit: "number" },
661
- },
662
- ];
663
- };
664
-
665
- export const shrink = (value: number): EmbedTemplateStyleDecl[] => {
666
- return [
667
- {
668
- property: "flexGrow",
669
- value: { type: "unit", value, unit: "number" },
670
- },
671
- ];
672
- };
673
-
674
- export const gap = (
675
- gapValue: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
676
- ): EmbedTemplateStyleDecl[] => {
677
- const key = `${gapValue}` as const;
678
- const valueString = theme("spacing")?.[key] ?? "0";
679
- const value = parseCssValue("rowGap", valueString);
680
-
681
- return [
682
- { property: "rowGap", value },
683
- { property: "columnGap", value },
684
- ];
685
- };
686
-
687
- export const lineClamp = (
688
- lineClampValue: StringEnumToNumeric<keyof EvaluatedDefaultTheme["lineClamp"]>
689
- ): EmbedTemplateStyleDecl[] => {
690
- const key = `${lineClampValue}` as const;
691
- const valueString = theme("lineClamp")?.[key];
692
-
693
- return [
694
- {
695
- property: "overflow",
696
- value: {
697
- type: "keyword",
698
- value: "hidden",
699
- },
700
- },
701
- {
702
- property: "display",
703
-
704
- value: {
705
- type: "keyword",
706
- value: "-webkit-box",
707
- },
708
- },
709
- {
710
- property: "-webkit-box-orient" as "display",
711
- value: {
712
- type: "keyword",
713
- value: "vertical",
714
- },
715
- },
716
- {
717
- property: "-webkit-line-clamp" as "display",
718
- value: {
719
- type: "keyword",
720
- value: valueString,
721
- },
722
- },
723
- ];
724
- };
725
-
726
- export const leading = (
727
- lineHeight:
728
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["lineHeight"]>
729
- | NonNumeric<keyof EvaluatedDefaultTheme["lineHeight"]>
730
- ): EmbedTemplateStyleDecl[] => {
731
- const key = `${lineHeight}` as const;
732
- const valueString = theme("lineHeight")[key];
733
- const value = parseCssValue("lineHeight", valueString);
734
-
735
- return [{ property: "lineHeight", value }];
736
- };
737
-
738
- export const tracking = (
739
- letterSpacing:
740
- | StringEnumToNumeric<keyof EvaluatedDefaultTheme["letterSpacing"]>
741
- | NonNumeric<keyof EvaluatedDefaultTheme["letterSpacing"]>
742
- ): EmbedTemplateStyleDecl[] => {
743
- const key = `${letterSpacing}` as const;
744
- const valueString = theme("letterSpacing")[key];
745
- const value = parseCssValue("letterSpacing", valueString);
746
-
747
- return [{ property: "letterSpacing", value }];
748
- };
749
-
750
- export const outline = (value: "none"): EmbedTemplateStyleDecl[] => {
751
- return [
752
- {
753
- property: "outlineWidth",
754
- value: { type: "unit", value: 2, unit: "px" },
755
- },
756
- {
757
- property: "outlineStyle",
758
- value: { type: "keyword", value: "solid" },
759
- },
760
- {
761
- property: "outlineColor",
762
- value: { type: "keyword", value: "transparent" },
763
- },
764
- {
765
- property: "outlineOffset",
766
- value: { type: "unit", value: 2, unit: "px" },
767
- },
768
- ];
769
- };
770
-
771
- const textSizes = [
772
- "sm",
773
- "base",
774
- "lg",
775
- "xs",
776
- "xl",
777
- "2xl",
778
- "3xl",
779
- "4xl",
780
- "5xl",
781
- "6xl",
782
- "7xl",
783
- "8xl",
784
- "9xl",
785
- ] as const satisfies readonly (keyof EvaluatedDefaultTheme["fontSize"])[];
786
- type TextSize = keyof EvaluatedDefaultTheme["fontSize"];
787
-
788
- const isTextSize = (value: string): value is TextSize =>
789
- textSizes.includes(value as TextSize);
790
-
791
- export const text = (
792
- sizeOrColor: TextSize | keyof EvaluatedDefaultTheme["colors"]
793
- ): EmbedTemplateStyleDecl[] => {
794
- if (isTextSize(sizeOrColor)) {
795
- const valueArr = theme("fontSize")[sizeOrColor];
796
- const [fontSizeString, { lineHeight: lineHeightString }] = valueArr;
797
-
798
- const fontSize = parseCssValue("fontSize", fontSizeString);
799
- const lineHeight = parseCssValue("lineHeight", lineHeightString);
800
- return [
801
- { property: "fontSize", value: fontSize },
802
- { property: "lineHeight", value: lineHeight },
803
- ];
804
- }
805
-
806
- const value = parseCssValue("color", theme("colors")[sizeOrColor]);
807
-
808
- return [
809
- {
810
- property: "color",
811
- value,
812
- },
813
- ];
814
- };
815
-
816
- export const noUnderline = (): EmbedTemplateStyleDecl[] => {
817
- return [
818
- {
819
- property: "textDecorationLine",
820
- value: { type: "keyword", value: "none" },
821
- },
822
- ];
823
- };
824
-
825
- export const underline = (): EmbedTemplateStyleDecl[] => {
826
- return [
827
- {
828
- property: "textDecorationLine",
829
- value: { type: "keyword", value: "underline" },
830
- },
831
- ];
832
- };
833
-
834
- export const underlineOffset = (
835
- offset: StringEnumToNumeric<
836
- keyof EvaluatedDefaultTheme["textUnderlineOffset"]
837
- >
838
- ): EmbedTemplateStyleDecl[] => {
839
- const key = `${offset}` as const;
840
- const valueString = theme("textUnderlineOffset")[key];
841
- const value = parseCssValue("textUnderlineOffset", valueString);
842
-
843
- return [
844
- {
845
- property: "textUnderlineOffset",
846
- value,
847
- },
848
- ];
849
- };
850
-
851
- const weights = {
852
- thin: "100",
853
- extralight: "200",
854
- light: "300",
855
- normal: "400",
856
- medium: "500",
857
- semibold: "600",
858
- bold: "700",
859
- extrabold: "800",
860
- black: "900",
861
- } as const;
862
-
863
- export const font = (
864
- weight:
865
- | "thin"
866
- | "extralight"
867
- | "light"
868
- | "normal"
869
- | "medium"
870
- | "semibold"
871
- | "bold"
872
- | "extrabold"
873
- | "black"
874
- ): EmbedTemplateStyleDecl[] => {
875
- return [
876
- {
877
- property: "fontWeight",
878
- value: { type: "keyword", value: weights[weight] },
879
- },
880
- ];
881
- };
882
-
883
- export const whitespace = (
884
- value: "normal" | "nowrap" | "pre" | "pre-line" | "pre-wrap" | "break-spaces"
885
- ): EmbedTemplateStyleDecl[] => {
886
- return [
887
- {
888
- property: "whiteSpace",
889
- value: { type: "keyword", value },
890
- },
891
- ];
892
- };
893
-
894
- export const shadow = (
895
- shadowSize: keyof EvaluatedDefaultTheme["boxShadow"]
896
- ): EmbedTemplateStyleDecl[] => {
897
- const valueString = theme("boxShadow")[shadowSize];
898
- const value = parseBoxShadow(valueString);
899
-
900
- return [
901
- {
902
- property: "boxShadow",
903
- value,
904
- },
905
- ];
906
- };
907
-
908
- export const ring = (
909
- ringColor: keyof EvaluatedDefaultTheme["colors"],
910
- ringWidth: StringEnumToNumeric<keyof EvaluatedDefaultTheme["ringWidth"]>,
911
- ringOffsetColor: keyof EvaluatedDefaultTheme["colors"] = "background",
912
- ringOffsetWidth: StringEnumToNumeric<
913
- keyof EvaluatedDefaultTheme["ringOffsetWidth"]
914
- > = 0,
915
- inset: "inset" | "" = ""
916
- ): EmbedTemplateStyleDecl[] => {
917
- const ringWidthUnits = theme("ringWidth")[ringWidth];
918
- const ringOffsetWidthUnits = theme("ringOffsetWidth")[ringOffsetWidth];
919
- const ringColorRgb = theme("colors")[ringColor];
920
- const ringOffsetColorRgb = theme("colors")[ringOffsetColor];
921
- const ringOffsetShadow = `${inset} 0 0 0 ${ringOffsetWidthUnits} ${ringOffsetColorRgb}`;
922
-
923
- const ringWidthParsed = parseFloat(ringWidthUnits);
924
- const ringOffsetWidthParsed = parseFloat(ringOffsetWidthUnits);
925
-
926
- const ringShadow = `${inset} 0 0 0 ${
927
- ringWidthParsed + ringOffsetWidthParsed
928
- }px ${ringColorRgb}`;
929
-
930
- const value = parseBoxShadow(`${ringOffsetShadow}, ${ringShadow}`);
931
-
932
- return [
933
- {
934
- property: "boxShadow",
935
- value,
936
- },
937
- ];
938
- };
939
-
940
- export const pointerEvents = (
941
- value: "none" | "auto"
942
- ): EmbedTemplateStyleDecl[] => {
943
- return [{ property: "pointerEvents", value: { type: "keyword", value } }];
944
- };
945
-
946
- export const transition = (
947
- value: "none" | "all" | "transform"
948
- ): EmbedTemplateStyleDecl[] => {
949
- if (value === "none") {
950
- return [
951
- {
952
- property: "transitionProperty",
953
- value: { type: "keyword", value: "all" },
954
- },
955
- ];
956
- }
957
- return [
958
- {
959
- property: "transitionProperty",
960
- value: { type: "keyword", value },
961
- },
962
- {
963
- property: "transitionTimingFunction",
964
- value: { type: "unparsed", value: "cubic-bezier(0.4, 0, 0.2, 1)" },
965
- },
966
- {
967
- property: "transitionDuration",
968
- value: { type: "unparsed", value: "150ms" },
969
- },
970
- ];
971
- };
972
-
973
- export const duration = (ms: number): EmbedTemplateStyleDecl[] => {
974
- return [
975
- {
976
- property: "transitionDuration",
977
- value: { type: "unit", value: ms, unit: "ms" },
978
- },
979
- ];
980
- };
981
-
982
- export const hover = (
983
- value: EmbedTemplateStyleDecl[]
984
- ): EmbedTemplateStyleDecl[] => {
985
- return value.map((decl) => ({
986
- ...decl,
987
- state: ":hover",
988
- }));
989
- };
990
-
991
- export const focus = (
992
- value: EmbedTemplateStyleDecl[]
993
- ): EmbedTemplateStyleDecl[] => {
994
- return value.map((decl) => ({
995
- ...decl,
996
- state: ":focus",
997
- }));
998
- };
999
-
1000
- export const focusVisible = (
1001
- value: EmbedTemplateStyleDecl[]
1002
- ): EmbedTemplateStyleDecl[] => {
1003
- return value.map((decl) => ({
1004
- ...decl,
1005
- state: ":focus-visible",
1006
- }));
1007
- };
1008
-
1009
- export const disabled = (
1010
- value: EmbedTemplateStyleDecl[]
1011
- ): EmbedTemplateStyleDecl[] => {
1012
- return value.map((decl) => ({
1013
- ...decl,
1014
- state: ":disabled",
1015
- }));
1016
- };
1017
-
1018
- export const state = (
1019
- value: EmbedTemplateStyleDecl[],
1020
- state: string
1021
- ): EmbedTemplateStyleDecl[] => {
1022
- return value.map((decl) => ({
1023
- ...decl,
1024
- state,
1025
- }));
1026
- };