@webstudio-is/sdk-components-react-radix 0.83.0 → 0.85.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 (103) hide show
  1. package/lib/__generated__/dialog.props.js +2120 -0
  2. package/lib/__generated__/popover.props.js +468 -0
  3. package/lib/__generated__/sheet.props.js +2159 -0
  4. package/lib/__generated__/tabs.props.js +1286 -0
  5. package/lib/__generated__/tooltip.props.js +478 -0
  6. package/lib/cjs/__generated__/dialog.props.js +2140 -0
  7. package/lib/cjs/__generated__/popover.props.js +488 -0
  8. package/lib/cjs/__generated__/sheet.props.js +2179 -0
  9. package/lib/cjs/__generated__/tabs.props.js +1306 -0
  10. package/lib/cjs/__generated__/tooltip.props.js +498 -0
  11. package/lib/cjs/collapsible.js +34 -4
  12. package/lib/cjs/collapsible.ws.js +14 -9
  13. package/lib/cjs/components.js +30 -1
  14. package/lib/cjs/dialog.js +57 -0
  15. package/lib/cjs/dialog.ws.js +311 -0
  16. package/lib/cjs/hooks.js +25 -0
  17. package/lib/cjs/metas.js +30 -1
  18. package/lib/cjs/popover.js +58 -0
  19. package/lib/cjs/popover.ws.js +141 -0
  20. package/lib/cjs/props.js +30 -1
  21. package/lib/cjs/sheet.js +63 -0
  22. package/lib/cjs/sheet.ws.js +317 -0
  23. package/lib/cjs/tabs.js +41 -0
  24. package/lib/cjs/tabs.ws.js +213 -0
  25. package/lib/cjs/theme/radix-common-types.js +16 -0
  26. package/lib/cjs/theme/tailwind-classes.js +547 -0
  27. package/lib/cjs/theme/tailwind-colors.js +35 -0
  28. package/lib/cjs/theme/tailwind-theme.js +46 -0
  29. package/lib/cjs/tooltip.js +55 -0
  30. package/lib/cjs/tooltip.ws.js +142 -0
  31. package/lib/collapsible.js +35 -7
  32. package/lib/collapsible.ws.js +19 -10
  33. package/lib/components.js +46 -1
  34. package/lib/dialog.js +30 -0
  35. package/lib/dialog.ws.js +298 -0
  36. package/lib/hooks.js +5 -0
  37. package/lib/metas.js +59 -1
  38. package/lib/popover.js +31 -0
  39. package/lib/popover.ws.js +116 -0
  40. package/lib/props.js +59 -1
  41. package/lib/sheet.js +35 -0
  42. package/lib/sheet.ws.js +304 -0
  43. package/lib/tabs.js +24 -0
  44. package/lib/tabs.ws.js +193 -0
  45. package/lib/theme/radix-common-types.js +0 -0
  46. package/lib/theme/tailwind-classes.js +527 -0
  47. package/lib/theme/tailwind-colors.js +15 -0
  48. package/lib/theme/tailwind-theme.js +16 -0
  49. package/lib/tooltip.js +28 -0
  50. package/lib/tooltip.ws.js +117 -0
  51. package/lib/types/__generated__/dialog.props.d.ts +8 -0
  52. package/lib/types/__generated__/popover.props.d.ts +4 -0
  53. package/lib/types/__generated__/sheet.props.d.ts +8 -0
  54. package/lib/types/__generated__/tabs.props.d.ts +5 -0
  55. package/lib/types/__generated__/tooltip.props.d.ts +4 -0
  56. package/lib/types/collapsible.d.ts +4 -3
  57. package/lib/types/components.d.ts +5 -0
  58. package/lib/types/dialog.d.ts +25 -0
  59. package/lib/types/dialog.ws.d.ts +23 -0
  60. package/lib/types/hooks.d.ts +2 -0
  61. package/lib/types/metas.d.ts +5 -0
  62. package/lib/types/popover.d.ts +21 -0
  63. package/lib/types/popover.ws.d.ts +15 -0
  64. package/lib/types/props.d.ts +5 -0
  65. package/lib/types/sheet.d.ts +15 -0
  66. package/lib/types/sheet.ws.d.ts +23 -0
  67. package/lib/types/tabs.d.ts +15 -0
  68. package/lib/types/tabs.ws.d.ts +9 -0
  69. package/lib/types/theme/radix-common-types.d.ts +84 -0
  70. package/lib/types/theme/tailwind-classes.d.ts +83 -0
  71. package/lib/types/theme/tailwind-colors.d.ts +21 -0
  72. package/lib/types/theme/tailwind-theme.d.ts +72 -0
  73. package/lib/types/tooltip.d.ts +21 -0
  74. package/lib/types/tooltip.ws.d.ts +15 -0
  75. package/package.json +23 -6
  76. package/src/__generated__/dialog.props.ts +2363 -0
  77. package/src/__generated__/popover.props.ts +515 -0
  78. package/src/__generated__/sheet.props.ts +2402 -0
  79. package/src/__generated__/tabs.props.ts +1434 -0
  80. package/src/__generated__/tooltip.props.ts +526 -0
  81. package/src/collapsible.stories.tsx +21 -0
  82. package/src/collapsible.tsx +44 -21
  83. package/src/collapsible.ws.ts +21 -10
  84. package/src/components.ts +21 -0
  85. package/src/dialog.tsx +66 -0
  86. package/src/dialog.ws.tsx +315 -0
  87. package/src/hooks.ts +4 -0
  88. package/src/metas.ts +34 -0
  89. package/src/popover.tsx +70 -0
  90. package/src/popover.ws.tsx +127 -0
  91. package/src/props.ts +34 -0
  92. package/src/sheet.stories.tsx +21 -0
  93. package/src/sheet.tsx +40 -0
  94. package/src/sheet.ws.tsx +326 -0
  95. package/src/tabs.stories.tsx +21 -0
  96. package/src/tabs.tsx +46 -0
  97. package/src/tabs.ws.ts +211 -0
  98. package/src/theme/radix-common-types.ts +495 -0
  99. package/src/theme/tailwind-classes.ts +695 -0
  100. package/src/theme/tailwind-colors.ts +45 -0
  101. package/src/theme/tailwind-theme.ts +24 -0
  102. package/src/tooltip.tsx +69 -0
  103. package/src/tooltip.ws.tsx +128 -0
@@ -0,0 +1,695 @@
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 { parseCssValue, parseBoxShadow } from "@webstudio-is/css-data";
7
+ import type { EvaluatedDefaultTheme } from "./radix-common-types";
8
+
9
+ // https://github.com/tailwindlabs/tailwindcss/blob/master/src/css/preflight.css
10
+ const preflight = (): EmbedTemplateStyleDecl[] => {
11
+ const borderColorValue = parseCssValue("color", theme("colors")["border"]);
12
+
13
+ return [
14
+ {
15
+ property: "borderTopStyle",
16
+ value: { type: "keyword", value: "solid" },
17
+ },
18
+ {
19
+ property: "borderRightStyle",
20
+ value: { type: "keyword", value: "solid" },
21
+ },
22
+ {
23
+ property: "borderBottomStyle",
24
+ value: { type: "keyword", value: "solid" },
25
+ },
26
+ {
27
+ property: "borderLeftStyle",
28
+ value: { type: "keyword", value: "solid" },
29
+ },
30
+
31
+ {
32
+ property: "borderTopColor",
33
+ value: borderColorValue,
34
+ },
35
+ {
36
+ property: "borderRightColor",
37
+ value: borderColorValue,
38
+ },
39
+ {
40
+ property: "borderBottomColor",
41
+ value: borderColorValue,
42
+ },
43
+ {
44
+ property: "borderLeftColor",
45
+ value: borderColorValue,
46
+ },
47
+ ];
48
+ };
49
+
50
+ export const z = (
51
+ zIndex?: StringEnumToNumeric<keyof EvaluatedDefaultTheme["zIndex"]>
52
+ ): EmbedTemplateStyleDecl[] => {
53
+ const valueString = theme("zIndex")[zIndex ?? "auto"];
54
+ const value = parseCssValue("zIndex", valueString);
55
+
56
+ return [
57
+ {
58
+ property: "zIndex",
59
+ value,
60
+ },
61
+ ];
62
+ };
63
+
64
+ export const overflow = (
65
+ value: "hidden" | "visible" | "scroll" | "auto"
66
+ ): EmbedTemplateStyleDecl[] => [
67
+ {
68
+ property: "overflow",
69
+ value: { type: "keyword", value },
70
+ },
71
+ ];
72
+
73
+ export const rounded = (
74
+ radius?: keyof EvaluatedDefaultTheme["borderRadius"]
75
+ ): EmbedTemplateStyleDecl[] => {
76
+ const valueString = theme("borderRadius")[radius ?? "DEFAULT"];
77
+ const value = parseCssValue("borderTopWidth", valueString);
78
+
79
+ return [
80
+ {
81
+ property: "borderTopLeftRadius",
82
+ value,
83
+ },
84
+ {
85
+ property: "borderTopRightRadius",
86
+ value,
87
+ },
88
+ {
89
+ property: "borderBottomRightRadius",
90
+ value,
91
+ },
92
+ {
93
+ property: "borderBottomLeftRadius",
94
+ value,
95
+ },
96
+ ];
97
+ };
98
+
99
+ type StringEnumToNumeric<T extends string> = T extends `${infer Z extends
100
+ number}`
101
+ ? Z
102
+ : never;
103
+
104
+ type NonNumeric<T extends string> = T extends `${infer Z extends number}`
105
+ ? never
106
+ : T;
107
+
108
+ export const border = (
109
+ borderWidth?: StringEnumToNumeric<keyof EvaluatedDefaultTheme["borderWidth"]>
110
+ ): EmbedTemplateStyleDecl[] => {
111
+ const key = `${borderWidth ?? "DEFAULT"}` as const;
112
+
113
+ const valueString = theme("borderWidth")?.[key] ?? "1px";
114
+
115
+ const value = parseCssValue("borderTopWidth", valueString);
116
+ return [
117
+ ...preflight(),
118
+ { property: "borderTopWidth", value },
119
+ { property: "borderRightWidth", value },
120
+ { property: "borderBottomWidth", value },
121
+ { property: "borderLeftWidth", value },
122
+ ];
123
+ };
124
+
125
+ export const px = (
126
+ padding:
127
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["padding"]>
128
+ | NonNumeric<keyof EvaluatedDefaultTheme["padding"]>
129
+ ): EmbedTemplateStyleDecl[] => {
130
+ const key = `${padding}` as const;
131
+ const valueString = theme("padding")?.[key] ?? "0";
132
+ const value = parseCssValue("paddingLeft", valueString);
133
+
134
+ return [
135
+ { property: "paddingLeft", value },
136
+ { property: "paddingRight", value },
137
+ ];
138
+ };
139
+
140
+ export const py = (
141
+ padding:
142
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["padding"]>
143
+ | NonNumeric<keyof EvaluatedDefaultTheme["padding"]>
144
+ ): EmbedTemplateStyleDecl[] => {
145
+ const key = `${padding}` as const;
146
+ const valueString = theme("padding")[key];
147
+ const value = parseCssValue("paddingTop", valueString);
148
+
149
+ return [
150
+ { property: "paddingTop", value },
151
+ { property: "paddingBottom", value },
152
+ ];
153
+ };
154
+
155
+ export const p = (
156
+ padding:
157
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["padding"]>
158
+ | NonNumeric<keyof EvaluatedDefaultTheme["padding"]>
159
+ ): EmbedTemplateStyleDecl[] => {
160
+ return [...px(padding), ...py(padding)];
161
+ };
162
+
163
+ const marginProperty =
164
+ (property: "marginTop" | "marginRight" | "marginBottom" | "marginLeft") =>
165
+ (
166
+ margin:
167
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["margin"]>
168
+ | NonNumeric<keyof EvaluatedDefaultTheme["margin"]>
169
+ ): EmbedTemplateStyleDecl[] => {
170
+ const key = `${margin}` as const;
171
+ const valueString = theme("margin")?.[key] ?? "0";
172
+ const value = parseCssValue(property, valueString);
173
+
174
+ return [{ property, value }];
175
+ };
176
+
177
+ export const ml: ReturnType<typeof marginProperty> = (margin) => {
178
+ return marginProperty("marginLeft")(margin);
179
+ };
180
+
181
+ export const mr: ReturnType<typeof marginProperty> = (margin) => {
182
+ return marginProperty("marginRight")(margin);
183
+ };
184
+
185
+ export const mt: ReturnType<typeof marginProperty> = (margin) => {
186
+ return marginProperty("marginTop")(margin);
187
+ };
188
+
189
+ export const mb: ReturnType<typeof marginProperty> = (margin) => {
190
+ return marginProperty("marginBottom")(margin);
191
+ };
192
+
193
+ export const mx: ReturnType<typeof marginProperty> = (margin) => {
194
+ return [ml(margin), mr(margin)].flat();
195
+ };
196
+
197
+ export const my: ReturnType<typeof marginProperty> = (margin) => {
198
+ return [mt(margin), mb(margin)].flat();
199
+ };
200
+
201
+ export const m: ReturnType<typeof marginProperty> = (margin) => {
202
+ return [mx(margin), my(margin)].flat();
203
+ };
204
+
205
+ export const w = (
206
+ spacing:
207
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["width"]>
208
+ | NonNumeric<keyof EvaluatedDefaultTheme["width"]>
209
+ ): EmbedTemplateStyleDecl[] => {
210
+ const key = `${spacing}` as const;
211
+ const valueString = theme("width")?.[key] ?? "0";
212
+ const value = parseCssValue("width", valueString);
213
+
214
+ return [{ property: "width", value }];
215
+ };
216
+
217
+ export const h = (
218
+ spacing:
219
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["height"]>
220
+ | NonNumeric<keyof EvaluatedDefaultTheme["height"]>
221
+ ): EmbedTemplateStyleDecl[] => {
222
+ const key = `${spacing}` as const;
223
+ const valueString = theme("height")?.[key] ?? "0";
224
+ const value = parseCssValue("height", valueString);
225
+
226
+ return [{ property: "height", value }];
227
+ };
228
+
229
+ export const opacity = (
230
+ opacity: StringEnumToNumeric<keyof EvaluatedDefaultTheme["opacity"]>
231
+ ): EmbedTemplateStyleDecl[] => {
232
+ const key = `${opacity}` as const;
233
+ const valueString = theme("opacity")?.[key] ?? "0";
234
+ const value = parseCssValue("opacity", valueString);
235
+
236
+ return [
237
+ {
238
+ property: "opacity",
239
+ value,
240
+ },
241
+ ];
242
+ };
243
+
244
+ export const maxW = (
245
+ spacing:
246
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["maxWidth"]>
247
+ | NonNumeric<keyof EvaluatedDefaultTheme["maxWidth"]>
248
+ ): EmbedTemplateStyleDecl[] => {
249
+ const key = `${spacing}` as const;
250
+ const valueString = theme("maxWidth")?.[key] ?? "0";
251
+ const value = parseCssValue("width", valueString);
252
+
253
+ return [{ property: "maxWidth", value }];
254
+ };
255
+
256
+ const positionStyle = (
257
+ property: "left" | "right" | "top" | "bottom",
258
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
259
+ ): EmbedTemplateStyleDecl => {
260
+ const key = `${spacing}` as const;
261
+ const valueString = theme("spacing")?.[key] ?? "0";
262
+ const value = parseCssValue(property, valueString);
263
+
264
+ return { property, value };
265
+ };
266
+
267
+ export const top = (
268
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
269
+ ): EmbedTemplateStyleDecl[] => [positionStyle("top", spacing)];
270
+
271
+ export const right = (
272
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
273
+ ): EmbedTemplateStyleDecl[] => [positionStyle("right", spacing)];
274
+
275
+ export const bottom = (
276
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
277
+ ): EmbedTemplateStyleDecl[] => [positionStyle("bottom", spacing)];
278
+
279
+ export const left = (
280
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
281
+ ): EmbedTemplateStyleDecl[] => [positionStyle("left", spacing)];
282
+
283
+ export const inset = (
284
+ spacing: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
285
+ ): EmbedTemplateStyleDecl[] => [
286
+ positionStyle("left", spacing),
287
+ positionStyle("right", spacing),
288
+ positionStyle("top", spacing),
289
+ positionStyle("bottom", spacing),
290
+ ];
291
+
292
+ export const backdropBlur = (
293
+ blur: keyof EvaluatedDefaultTheme["blur"]
294
+ ): EmbedTemplateStyleDecl[] => {
295
+ const valueString = theme("blur")[blur];
296
+ const value = {
297
+ type: "unparsed" as const,
298
+ value: `blur(${valueString})`,
299
+ };
300
+
301
+ return [{ property: "backdropFilter", value }];
302
+ };
303
+
304
+ export const bg = (
305
+ color: keyof EvaluatedDefaultTheme["colors"],
306
+ alpha?: number
307
+ ): EmbedTemplateStyleDecl[] => {
308
+ const value = parseCssValue("backgroundColor", theme("colors")[color]);
309
+
310
+ if (alpha !== undefined && value.type === "rgb") {
311
+ value.alpha = alpha / 100;
312
+ }
313
+
314
+ return [
315
+ {
316
+ property: "backgroundColor",
317
+ value,
318
+ },
319
+ ];
320
+ };
321
+
322
+ export const fixed = (): EmbedTemplateStyleDecl[] => {
323
+ return [{ property: "position", value: { type: "keyword", value: "fixed" } }];
324
+ };
325
+
326
+ export const relative = (): EmbedTemplateStyleDecl[] => {
327
+ return [
328
+ { property: "position", value: { type: "keyword", value: "relative" } },
329
+ ];
330
+ };
331
+
332
+ export const absolute = (): EmbedTemplateStyleDecl[] => {
333
+ return [
334
+ { property: "position", value: { type: "keyword", value: "absolute" } },
335
+ ];
336
+ };
337
+
338
+ export const grid = (): EmbedTemplateStyleDecl[] => {
339
+ return [{ property: "display", value: { type: "keyword", value: "grid" } }];
340
+ };
341
+
342
+ const alignItems = {
343
+ start: "flex-start",
344
+ end: "flex-end",
345
+ center: "center",
346
+ baseline: "baseline",
347
+ stretch: "stretch",
348
+ } as const;
349
+ type AlignItems = keyof typeof alignItems;
350
+
351
+ export const items = (
352
+ alignItemsParam: AlignItems
353
+ ): EmbedTemplateStyleDecl[] => {
354
+ return [
355
+ {
356
+ property: "alignItems",
357
+ value: {
358
+ type: "keyword",
359
+ value: alignItems[alignItemsParam],
360
+ },
361
+ },
362
+ ];
363
+ };
364
+
365
+ const justifyContent = {
366
+ start: "flex-start",
367
+ end: "flex-end",
368
+ center: "center",
369
+ between: "space-between",
370
+ around: "space-around",
371
+ evenly: "space-evenly",
372
+ stretch: "stretch",
373
+ } as const;
374
+ type JustifyContent = keyof typeof justifyContent;
375
+
376
+ export const justify = (
377
+ justifyContentParam: JustifyContent
378
+ ): EmbedTemplateStyleDecl[] => {
379
+ return [
380
+ {
381
+ property: "justifyContent",
382
+ value: {
383
+ type: "keyword",
384
+ value: justifyContent[justifyContentParam],
385
+ },
386
+ },
387
+ ];
388
+ };
389
+
390
+ export const inlineFlex = (): EmbedTemplateStyleDecl[] => {
391
+ return [
392
+ { property: "display", value: { type: "keyword", value: "inline-flex" } },
393
+ ];
394
+ };
395
+
396
+ const flexDirection = { row: "row", col: "column" } as const;
397
+ type FlexDirection = keyof typeof flexDirection;
398
+
399
+ export const flex = (flexParam?: FlexDirection): EmbedTemplateStyleDecl[] => {
400
+ if (flexParam === undefined) {
401
+ return [{ property: "display", value: { type: "keyword", value: "flex" } }];
402
+ }
403
+
404
+ return [
405
+ {
406
+ property: "flexDirection",
407
+ value: {
408
+ type: "keyword",
409
+ value: flexDirection[flexParam],
410
+ },
411
+ },
412
+ ];
413
+ };
414
+
415
+ export const grow = (): EmbedTemplateStyleDecl[] => {
416
+ return [
417
+ {
418
+ property: "flexGrow",
419
+ value: {
420
+ type: "unit",
421
+ value: 1,
422
+ unit: "number",
423
+ },
424
+ },
425
+ ];
426
+ };
427
+
428
+ export const gap = (
429
+ gapValue: StringEnumToNumeric<keyof EvaluatedDefaultTheme["spacing"]>
430
+ ): EmbedTemplateStyleDecl[] => {
431
+ const key = `${gapValue}` as const;
432
+ const valueString = theme("spacing")?.[key] ?? "0";
433
+ const value = parseCssValue("rowGap", valueString);
434
+
435
+ return [
436
+ { property: "rowGap", value },
437
+ { property: "columnGap", value },
438
+ ];
439
+ };
440
+
441
+ export const leading = (
442
+ lineHeight:
443
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["lineHeight"]>
444
+ | NonNumeric<keyof EvaluatedDefaultTheme["lineHeight"]>
445
+ ): EmbedTemplateStyleDecl[] => {
446
+ const key = `${lineHeight}` as const;
447
+ const valueString = theme("lineHeight")[key];
448
+ const value = parseCssValue("lineHeight", valueString);
449
+
450
+ return [{ property: "lineHeight", value }];
451
+ };
452
+
453
+ export const tracking = (
454
+ letterSpacing:
455
+ | StringEnumToNumeric<keyof EvaluatedDefaultTheme["letterSpacing"]>
456
+ | NonNumeric<keyof EvaluatedDefaultTheme["letterSpacing"]>
457
+ ): EmbedTemplateStyleDecl[] => {
458
+ const key = `${letterSpacing}` as const;
459
+ const valueString = theme("letterSpacing")[key];
460
+ const value = parseCssValue("letterSpacing", valueString);
461
+
462
+ return [{ property: "letterSpacing", value }];
463
+ };
464
+
465
+ export const outline = (value: "none"): EmbedTemplateStyleDecl[] => {
466
+ return [
467
+ {
468
+ property: "outlineWidth",
469
+ value: { type: "unit", value: 2, unit: "px" },
470
+ },
471
+ {
472
+ property: "outlineStyle",
473
+ value: { type: "keyword", value: "solid" },
474
+ },
475
+ {
476
+ property: "outlineColor",
477
+ value: { type: "keyword", value: "transparent" },
478
+ },
479
+ {
480
+ property: "outlineOffset",
481
+ value: { type: "unit", value: 2, unit: "px" },
482
+ },
483
+ ];
484
+ };
485
+
486
+ const textSizes = [
487
+ "sm",
488
+ "base",
489
+ "lg",
490
+ "xs",
491
+ "xl",
492
+ "2xl",
493
+ "3xl",
494
+ "4xl",
495
+ "5xl",
496
+ "6xl",
497
+ "7xl",
498
+ "8xl",
499
+ "9xl",
500
+ ] as const satisfies readonly (keyof EvaluatedDefaultTheme["fontSize"])[];
501
+ type TextSize = keyof EvaluatedDefaultTheme["fontSize"];
502
+
503
+ const isTextSize = (value: string): value is TextSize =>
504
+ textSizes.includes(value as TextSize);
505
+
506
+ export const text = (
507
+ sizeOrColor: TextSize | keyof EvaluatedDefaultTheme["colors"]
508
+ ): EmbedTemplateStyleDecl[] => {
509
+ if (isTextSize(sizeOrColor)) {
510
+ const valueArr = theme("fontSize")[sizeOrColor];
511
+ const [fontSizeString, { lineHeight: lineHeightString }] = valueArr;
512
+
513
+ const fontSize = parseCssValue("fontSize", fontSizeString);
514
+ const lineHeight = parseCssValue("lineHeight", lineHeightString);
515
+ return [
516
+ { property: "fontSize", value: fontSize },
517
+ { property: "lineHeight", value: lineHeight },
518
+ ];
519
+ }
520
+
521
+ const value = parseCssValue("color", theme("colors")[sizeOrColor]);
522
+
523
+ return [
524
+ {
525
+ property: "color",
526
+ value,
527
+ },
528
+ ];
529
+ };
530
+
531
+ const weights = {
532
+ thin: "100",
533
+ extralight: "200",
534
+ light: "300",
535
+ normal: "400",
536
+ medium: "500",
537
+ semibold: "600",
538
+ bold: "700",
539
+ extrabold: "800",
540
+ black: "900",
541
+ } as const;
542
+
543
+ export const font = (
544
+ weight:
545
+ | "thin"
546
+ | "extralight"
547
+ | "light"
548
+ | "normal"
549
+ | "medium"
550
+ | "semibold"
551
+ | "bold"
552
+ | "extrabold"
553
+ | "black"
554
+ ): EmbedTemplateStyleDecl[] => {
555
+ return [
556
+ {
557
+ property: "fontWeight",
558
+ value: { type: "keyword", value: weights[weight] },
559
+ },
560
+ ];
561
+ };
562
+
563
+ export const whitespace = (
564
+ value: "normal" | "nowrap" | "pre" | "pre-line" | "pre-wrap" | "break-spaces"
565
+ ): EmbedTemplateStyleDecl[] => {
566
+ return [
567
+ {
568
+ property: "whiteSpace",
569
+ value: { type: "keyword", value },
570
+ },
571
+ ];
572
+ };
573
+
574
+ export const shadow = (
575
+ shadowSize: keyof EvaluatedDefaultTheme["boxShadow"]
576
+ ): EmbedTemplateStyleDecl[] => {
577
+ const valueString = theme("boxShadow")[shadowSize];
578
+ const value = parseBoxShadow(valueString);
579
+
580
+ return [
581
+ {
582
+ property: "boxShadow",
583
+ value,
584
+ },
585
+ ];
586
+ };
587
+
588
+ export const ring = (
589
+ ringColor: keyof EvaluatedDefaultTheme["colors"],
590
+ ringWidth: StringEnumToNumeric<keyof EvaluatedDefaultTheme["ringWidth"]>,
591
+ ringOffsetColor: keyof EvaluatedDefaultTheme["colors"] = "background",
592
+ ringOffsetWidth: StringEnumToNumeric<
593
+ keyof EvaluatedDefaultTheme["ringOffsetWidth"]
594
+ > = 0,
595
+ inset: "inset" | "" = ""
596
+ ): EmbedTemplateStyleDecl[] => {
597
+ const ringWidthUnits = theme("ringWidth")[ringWidth];
598
+ const ringOffsetWidthUnits = theme("ringOffsetWidth")[ringOffsetWidth];
599
+ const ringColorRgb = theme("colors")[ringColor];
600
+ const ringOffsetColorRgb = theme("colors")[ringOffsetColor];
601
+ const ringOffsetShadow = `${inset} 0 0 0 ${ringOffsetWidthUnits} ${ringOffsetColorRgb}`;
602
+
603
+ const ringWidthParsed = parseFloat(ringWidthUnits);
604
+ const ringOffsetWidthParsed = parseFloat(ringOffsetWidthUnits);
605
+
606
+ const ringShadow = `${inset} 0 0 0 ${
607
+ ringWidthParsed + ringOffsetWidthParsed
608
+ }px ${ringColorRgb}`;
609
+
610
+ const value = parseBoxShadow(`${ringOffsetShadow}, ${ringShadow}`);
611
+
612
+ return [
613
+ {
614
+ property: "boxShadow",
615
+ value,
616
+ },
617
+ ];
618
+ };
619
+
620
+ export const pointerEvents = (
621
+ value: "none" | "auto"
622
+ ): EmbedTemplateStyleDecl[] => {
623
+ return [{ property: "pointerEvents", value: { type: "keyword", value } }];
624
+ };
625
+
626
+ export const transition = (value: "none" | "all"): EmbedTemplateStyleDecl[] => {
627
+ if (value === "none") {
628
+ return [
629
+ {
630
+ property: "transitionProperty",
631
+ value: { type: "keyword", value: "all" },
632
+ },
633
+ ];
634
+ }
635
+ return [
636
+ {
637
+ property: "transitionProperty",
638
+ value: { type: "keyword", value: "all" },
639
+ },
640
+ {
641
+ property: "transitionTimingFunction",
642
+ value: { type: "unparsed", value: "cubic-bezier(0.4, 0, 0.2, 1)" },
643
+ },
644
+ {
645
+ property: "transitionDuration",
646
+ value: { type: "unparsed", value: "150ms" },
647
+ },
648
+ ];
649
+ };
650
+
651
+ export const hover = (
652
+ value: EmbedTemplateStyleDecl[]
653
+ ): EmbedTemplateStyleDecl[] => {
654
+ return value.map((decl) => ({
655
+ ...decl,
656
+ state: ":hover",
657
+ }));
658
+ };
659
+
660
+ export const focus = (
661
+ value: EmbedTemplateStyleDecl[]
662
+ ): EmbedTemplateStyleDecl[] => {
663
+ return value.map((decl) => ({
664
+ ...decl,
665
+ state: ":focus",
666
+ }));
667
+ };
668
+
669
+ export const focusVisible = (
670
+ value: EmbedTemplateStyleDecl[]
671
+ ): EmbedTemplateStyleDecl[] => {
672
+ return value.map((decl) => ({
673
+ ...decl,
674
+ state: ":focus-visible",
675
+ }));
676
+ };
677
+
678
+ export const disabled = (
679
+ value: EmbedTemplateStyleDecl[]
680
+ ): EmbedTemplateStyleDecl[] => {
681
+ return value.map((decl) => ({
682
+ ...decl,
683
+ state: ":disabled",
684
+ }));
685
+ };
686
+
687
+ export const state = (
688
+ value: EmbedTemplateStyleDecl[],
689
+ state: string
690
+ ): EmbedTemplateStyleDecl[] => {
691
+ return value.map((decl) => ({
692
+ ...decl,
693
+ state,
694
+ }));
695
+ };