@sanity/ui 2.11.0 → 2.11.2-canary.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 (39) hide show
  1. package/dist/index.d.mts +18 -19
  2. package/dist/index.d.ts +18 -19
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +34 -48
  6. package/src/core/components/autocomplete/__workshop__/constrainedHeight.tsx +1 -1
  7. package/src/core/components/autocomplete/autocomplete.tsx +3 -4
  8. package/src/core/components/autocomplete/autocompleteOption.tsx +1 -1
  9. package/src/core/components/dialog/dialogProvider.tsx +1 -1
  10. package/src/core/components/menu/__workshop__/asComponent.tsx +1 -1
  11. package/src/core/components/menu/menuButton.tsx +2 -2
  12. package/src/core/components/menu/menuGroup.tsx +1 -1
  13. package/src/core/components/tab/tabList.tsx +2 -2
  14. package/src/core/components/toast/toast.tsx +1 -1
  15. package/src/core/components/toast/toastProvider.tsx +1 -1
  16. package/src/core/components/tree/tree.tsx +1 -1
  17. package/src/core/components/tree/treeGroup.tsx +1 -1
  18. package/src/core/components/tree/treeItem.tsx +1 -1
  19. package/src/core/primitives/avatar/avatarStack.tsx +1 -1
  20. package/src/core/primitives/card/__workshop__/asComponent.tsx +1 -1
  21. package/src/core/primitives/popover/__workshop__/TestStory.tsx +2 -2
  22. package/src/core/primitives/popover/popover.tsx +3 -3
  23. package/src/core/primitives/tooltip/tooltip.tsx +1 -1
  24. package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupProvider.tsx +1 -1
  25. package/src/core/theme/__workshop__/build/story.tsx +1 -2
  26. package/src/core/theme/themeColorProvider.tsx +1 -1
  27. package/src/core/theme/themeProvider.tsx +1 -1
  28. package/src/core/utils/arrow/arrow.tsx +2 -2
  29. package/src/core/utils/boundaryElement/boundaryElementProvider.tsx +1 -3
  30. package/src/core/utils/layer/layerProvider.tsx +1 -1
  31. package/src/core/utils/portal/portalProvider.tsx +1 -1
  32. package/src/core/utils/virtualList/virtualList.tsx +1 -1
  33. package/dist/_legacy/getTheme_v2.esm.js +0 -399
  34. package/dist/_legacy/getTheme_v2.esm.js.map +0 -1
  35. package/dist/index.esm.js +0 -7263
  36. package/dist/index.esm.js.map +0 -1
  37. package/dist/theme.esm.js +0 -3691
  38. package/dist/theme.esm.js.map +0 -1
  39. package/theme.js +0 -2
package/dist/theme.esm.js DELETED
@@ -1,3691 +0,0 @@
1
- import { defaultThemeConfig, themeColor_v0_v2 } from "./_legacy/getTheme_v2.esm.js";
2
- import { getTheme_v2 } from "./_legacy/getTheme_v2.esm.js";
3
- import { COLOR_HUES, COLOR_TINTS, color } from "@sanity/color";
4
- function createSelectableTones(opts, base, dark, solid, muted) {
5
- return {
6
- default: _createSelectableStates(opts, base, dark, solid, muted, "default"),
7
- primary: _createSelectableStates(opts, base, dark, solid, muted, "primary"),
8
- positive: _createSelectableStates(opts, base, dark, solid, muted, "positive"),
9
- caution: _createSelectableStates(opts, base, dark, solid, muted, "caution"),
10
- critical: _createSelectableStates(opts, base, dark, solid, muted, "critical")
11
- };
12
- }
13
- function _createSelectableStates(opts, base, dark, solid, muted, tone) {
14
- return {
15
- enabled: opts.selectable({
16
- base,
17
- dark,
18
- solid,
19
- muted,
20
- state: "enabled",
21
- tone
22
- }),
23
- hovered: opts.selectable({
24
- base,
25
- dark,
26
- solid,
27
- muted,
28
- state: "hovered",
29
- tone
30
- }),
31
- pressed: opts.selectable({
32
- base,
33
- dark,
34
- solid,
35
- muted,
36
- state: "pressed",
37
- tone
38
- }),
39
- selected: opts.selectable({
40
- base,
41
- dark,
42
- solid,
43
- muted,
44
- state: "selected",
45
- tone
46
- }),
47
- disabled: opts.selectable({
48
- base,
49
- dark,
50
- solid,
51
- muted,
52
- state: "disabled",
53
- tone
54
- })
55
- };
56
- }
57
- function createSolidTones(opts, base, dark, name) {
58
- return {
59
- default: {
60
- enabled: opts.solid({
61
- base,
62
- dark,
63
- tone: "default",
64
- name,
65
- state: "enabled"
66
- }),
67
- disabled: opts.solid({
68
- base,
69
- dark,
70
- tone: "default",
71
- name,
72
- state: "disabled"
73
- }),
74
- hovered: opts.solid({
75
- base,
76
- dark,
77
- tone: "default",
78
- name,
79
- state: "hovered"
80
- }),
81
- pressed: opts.solid({
82
- base,
83
- dark,
84
- tone: "default",
85
- name,
86
- state: "pressed"
87
- }),
88
- selected: opts.solid({
89
- base,
90
- dark,
91
- tone: "default",
92
- name,
93
- state: "selected"
94
- })
95
- },
96
- transparent: {
97
- enabled: opts.solid({
98
- base,
99
- dark,
100
- tone: "transparent",
101
- name,
102
- state: "enabled"
103
- }),
104
- disabled: opts.solid({
105
- base,
106
- dark,
107
- tone: "transparent",
108
- name,
109
- state: "disabled"
110
- }),
111
- hovered: opts.solid({
112
- base,
113
- dark,
114
- tone: "transparent",
115
- name,
116
- state: "hovered"
117
- }),
118
- pressed: opts.solid({
119
- base,
120
- dark,
121
- tone: "transparent",
122
- name,
123
- state: "pressed"
124
- }),
125
- selected: opts.solid({
126
- base,
127
- dark,
128
- tone: "transparent",
129
- name,
130
- state: "selected"
131
- })
132
- },
133
- primary: {
134
- enabled: opts.solid({
135
- base,
136
- dark,
137
- tone: "primary",
138
- name,
139
- state: "enabled"
140
- }),
141
- disabled: opts.solid({
142
- base,
143
- dark,
144
- tone: "primary",
145
- name,
146
- state: "disabled"
147
- }),
148
- hovered: opts.solid({
149
- base,
150
- dark,
151
- tone: "primary",
152
- name,
153
- state: "hovered"
154
- }),
155
- pressed: opts.solid({
156
- base,
157
- dark,
158
- tone: "primary",
159
- name,
160
- state: "pressed"
161
- }),
162
- selected: opts.solid({
163
- base,
164
- dark,
165
- tone: "primary",
166
- name,
167
- state: "selected"
168
- })
169
- },
170
- positive: {
171
- enabled: opts.solid({
172
- base,
173
- dark,
174
- tone: "positive",
175
- name,
176
- state: "enabled"
177
- }),
178
- disabled: opts.solid({
179
- base,
180
- dark,
181
- tone: "positive",
182
- name,
183
- state: "disabled"
184
- }),
185
- hovered: opts.solid({
186
- base,
187
- dark,
188
- tone: "positive",
189
- name,
190
- state: "hovered"
191
- }),
192
- pressed: opts.solid({
193
- base,
194
- dark,
195
- tone: "positive",
196
- name,
197
- state: "pressed"
198
- }),
199
- selected: opts.solid({
200
- base,
201
- dark,
202
- tone: "positive",
203
- name,
204
- state: "selected"
205
- })
206
- },
207
- caution: {
208
- enabled: opts.solid({
209
- base,
210
- dark,
211
- tone: "caution",
212
- name,
213
- state: "enabled"
214
- }),
215
- disabled: opts.solid({
216
- base,
217
- dark,
218
- tone: "caution",
219
- name,
220
- state: "disabled"
221
- }),
222
- hovered: opts.solid({
223
- base,
224
- dark,
225
- tone: "caution",
226
- name,
227
- state: "hovered"
228
- }),
229
- pressed: opts.solid({
230
- base,
231
- dark,
232
- tone: "caution",
233
- name,
234
- state: "pressed"
235
- }),
236
- selected: opts.solid({
237
- base,
238
- dark,
239
- tone: "caution",
240
- name,
241
- state: "selected"
242
- })
243
- },
244
- critical: {
245
- enabled: opts.solid({
246
- base,
247
- dark,
248
- tone: "critical",
249
- name,
250
- state: "enabled"
251
- }),
252
- disabled: opts.solid({
253
- base,
254
- dark,
255
- tone: "critical",
256
- name,
257
- state: "disabled"
258
- }),
259
- hovered: opts.solid({
260
- base,
261
- dark,
262
- tone: "critical",
263
- name,
264
- state: "hovered"
265
- }),
266
- pressed: opts.solid({
267
- base,
268
- dark,
269
- tone: "critical",
270
- name,
271
- state: "pressed"
272
- }),
273
- selected: opts.solid({
274
- base,
275
- dark,
276
- tone: "critical",
277
- name,
278
- state: "selected"
279
- })
280
- }
281
- };
282
- }
283
- function createButtonTones(opts, base, dark, solid, muted, mode) {
284
- return {
285
- default: opts.button({
286
- base,
287
- dark,
288
- solid: solid.default,
289
- muted: muted.default,
290
- mode
291
- }),
292
- primary: opts.button({
293
- base,
294
- dark,
295
- solid: solid.primary,
296
- muted: muted.primary,
297
- mode
298
- }),
299
- positive: opts.button({
300
- base,
301
- dark,
302
- solid: solid.positive,
303
- muted: muted.positive,
304
- mode
305
- }),
306
- caution: opts.button({
307
- base,
308
- dark,
309
- solid: solid.caution,
310
- muted: muted.caution,
311
- mode
312
- }),
313
- critical: opts.button({
314
- base,
315
- dark,
316
- solid: solid.critical,
317
- muted: muted.critical,
318
- mode
319
- })
320
- };
321
- }
322
- function createButtonModes(opts, base, dark, solid, muted) {
323
- return {
324
- default: createButtonTones(opts, base, dark, solid, muted, "default"),
325
- ghost: createButtonTones(opts, base, dark, solid, muted, "ghost"),
326
- bleed: createButtonTones(opts, base, dark, solid, muted, "bleed")
327
- };
328
- }
329
- function createCardStates(opts, base, dark, name, solid, muted) {
330
- return {
331
- enabled: opts.card({
332
- base,
333
- dark,
334
- name,
335
- state: "enabled",
336
- solid,
337
- muted
338
- }),
339
- disabled: opts.card({
340
- base,
341
- dark,
342
- name,
343
- state: "disabled",
344
- solid,
345
- muted
346
- }),
347
- hovered: opts.card({
348
- base,
349
- dark,
350
- name,
351
- state: "hovered",
352
- solid,
353
- muted
354
- }),
355
- pressed: opts.card({
356
- base,
357
- dark,
358
- name,
359
- state: "pressed",
360
- solid,
361
- muted
362
- }),
363
- selected: opts.card({
364
- base,
365
- dark,
366
- name,
367
- state: "selected",
368
- solid,
369
- muted
370
- })
371
- };
372
- }
373
- const black = "hsl(0, 0%, 0%)", white = "hsl(0, 0%, 100%)", colors = {
374
- default: {
375
- lightest: "hsl(0, 0%, 95%)",
376
- lighter: "hsl(0, 0%, 70%)",
377
- light: "hsl(0, 0%, 65%)",
378
- base: "hsl(0, 0%, 50%)",
379
- dark: "hsl(0, 0%, 35%)",
380
- darker: "hsl(0, 0%, 20%)",
381
- darkest: "hsl(0, 0%, 5%)"
382
- },
383
- transparent: {
384
- lightest: "hsl(240, 100%, 95%)",
385
- lighter: "hsl(240, 100%, 70%)",
386
- light: "hsl(240, 100%, 65%)",
387
- base: "hsl(240, 100%, 50%)",
388
- dark: "hsl(240, 100%, 35%)",
389
- darker: "hsl(240, 100%, 20%)",
390
- darkest: "hsl(240, 100%, 5%)"
391
- },
392
- primary: {
393
- lightest: "hsl(240, 100%, 95%)",
394
- lighter: "hsl(240, 100%, 70%)",
395
- light: "hsl(240, 100%, 65%)",
396
- base: "hsl(240, 100%, 50%)",
397
- dark: "hsl(240, 100%, 35%)",
398
- darker: "hsl(240, 100%, 20%)",
399
- darkest: "hsl(240, 100%, 5%)"
400
- },
401
- positive: {
402
- lightest: "hsl(120, 100%, 95%)",
403
- lighter: "hsl(120, 100%, 70%)",
404
- light: "hsl(120, 100%, 65%)",
405
- base: "hsl(120, 100%, 50%)",
406
- dark: "hsl(120, 100%, 35%)",
407
- darker: "hsl(120, 100%, 20%)",
408
- darkest: "hsl(120, 100%, 5%)"
409
- },
410
- caution: {
411
- lightest: "hsl(60, 100%, 95%)",
412
- lighter: "hsl(60, 100%, 70%)",
413
- light: "hsl(60, 100%, 65%)",
414
- base: "hsl(60, 100%, 50%)",
415
- dark: "hsl(60, 100%, 35%)",
416
- darker: "hsl(60, 100%, 20%)",
417
- darkest: "hsl(60, 100%, 5%)"
418
- },
419
- critical: {
420
- lightest: "hsl(0, 100%, 95%)",
421
- lighter: "hsl(0, 100%, 70%)",
422
- light: "hsl(0, 100%, 65%)",
423
- base: "hsl(0, 100%, 50%)",
424
- dark: "hsl(0, 100%, 35%)",
425
- darker: "hsl(0, 100%, 20%)",
426
- darkest: "hsl(0, 100%, 5%)"
427
- }
428
- }, spots = {
429
- gray: "hsl(0, 0%, 50%)",
430
- red: "hsl(0, 100%, 50%)",
431
- orange: "hsl(30, 100%, 50%)",
432
- yellow: "hsl(60, 100%, 50%)",
433
- green: "hsl(120, 100%, 50%)",
434
- cyan: "hsl(180, 100%, 50%)",
435
- blue: "hsl(240, 100%, 50%)",
436
- purple: "hsl(270, 100%, 50%)",
437
- magenta: "hsl(300, 100%, 50%)"
438
- }, tones = {
439
- transparent: {
440
- bg: [colors.transparent.darkest, colors.transparent.lightest],
441
- fg: [colors.transparent.lightest, colors.transparent.darkest],
442
- border: [colors.transparent.darker, colors.transparent.lighter],
443
- focusRing: [colors.transparent.base, colors.transparent.base]
444
- },
445
- primary: {
446
- bg: [colors.primary.darkest, colors.primary.lightest],
447
- fg: [colors.primary.lightest, colors.primary.darkest],
448
- border: [colors.primary.darker, colors.primary.lighter],
449
- focusRing: [colors.primary.base, colors.primary.base]
450
- },
451
- positive: {
452
- bg: [colors.positive.darkest, colors.positive.lightest],
453
- fg: [colors.positive.lightest, colors.positive.darkest],
454
- border: [colors.positive.darker, colors.positive.lighter],
455
- focusRing: [colors.positive.base, colors.positive.base]
456
- },
457
- caution: {
458
- bg: [colors.caution.darkest, colors.caution.lightest],
459
- fg: [colors.caution.lightest, colors.caution.darkest],
460
- border: [colors.caution.darker, colors.caution.lighter],
461
- focusRing: [colors.caution.base, colors.caution.base]
462
- },
463
- critical: {
464
- bg: [colors.critical.darkest, colors.critical.lightest],
465
- fg: [colors.critical.lightest, colors.critical.darkest],
466
- border: [colors.critical.darker, colors.critical.lighter],
467
- focusRing: [colors.critical.base, colors.critical.base]
468
- }
469
- }, defaultOpts = {
470
- base: ({
471
- dark,
472
- name
473
- }) => name === "default" ? {
474
- bg: dark ? black : white,
475
- fg: dark ? white : black,
476
- border: dark ? colors.default.darkest : colors.default.lightest,
477
- focusRing: colors.primary.base,
478
- shadow: {
479
- outline: black,
480
- umbra: black,
481
- penumbra: black,
482
- ambient: black
483
- },
484
- skeleton: {
485
- from: dark ? white : black,
486
- to: dark ? white : black
487
- }
488
- } : {
489
- bg: tones[name].bg[dark ? 0 : 1],
490
- fg: tones[name].fg[dark ? 0 : 1],
491
- border: tones[name].border[dark ? 0 : 1],
492
- focusRing: tones[name].focusRing[dark ? 0 : 1],
493
- shadow: {
494
- outline: black,
495
- umbra: black,
496
- penumbra: black,
497
- ambient: black
498
- },
499
- skeleton: {
500
- from: dark ? white : black,
501
- to: dark ? white : black
502
- }
503
- },
504
- solid: ({
505
- base,
506
- dark,
507
- state,
508
- tone
509
- }) => {
510
- const color2 = colors[tone];
511
- return state === "hovered" ? {
512
- bg: dark ? color2.light : color2.dark,
513
- bg2: dark ? color2.light : color2.dark,
514
- border: dark ? color2.lighter : color2.darker,
515
- fg: dark ? color2.darkest : color2.lightest,
516
- icon: dark ? color2.darkest : color2.lightest,
517
- muted: {
518
- fg: black
519
- },
520
- accent: {
521
- fg: black
522
- },
523
- link: {
524
- fg: black
525
- },
526
- code: {
527
- bg: black,
528
- fg: black
529
- },
530
- skeleton: base.skeleton
531
- } : {
532
- bg: color2.base,
533
- bg2: color2.base,
534
- border: dark ? color2.light : color2.dark,
535
- fg: dark ? color2.darkest : color2.lightest,
536
- icon: dark ? color2.darkest : color2.lightest,
537
- muted: {
538
- fg: black
539
- },
540
- accent: {
541
- fg: black
542
- },
543
- link: {
544
- fg: black
545
- },
546
- code: {
547
- bg: black,
548
- fg: black
549
- },
550
- skeleton: base.skeleton
551
- };
552
- },
553
- muted: ({
554
- base,
555
- dark,
556
- state,
557
- tone
558
- }) => {
559
- const color2 = colors[tone];
560
- return state === "hovered" ? {
561
- bg: dark ? color2.darker : color2.lighter,
562
- bg2: dark ? color2.darker : color2.lighter,
563
- border: dark ? color2.lighter : color2.darker,
564
- fg: dark ? color2.lightest : color2.darkest,
565
- icon: dark ? color2.lightest : color2.darkest,
566
- muted: {
567
- fg: black
568
- },
569
- accent: {
570
- fg: black
571
- },
572
- link: {
573
- fg: black
574
- },
575
- code: {
576
- bg: black,
577
- fg: black
578
- },
579
- skeleton: base.skeleton
580
- } : {
581
- bg: dark ? color2.darkest : color2.lightest,
582
- bg2: dark ? color2.darkest : color2.lightest,
583
- border: dark ? color2.darker : color2.lighter,
584
- fg: dark ? color2.lighter : color2.darker,
585
- icon: dark ? color2.lighter : color2.darker,
586
- muted: {
587
- fg: black
588
- },
589
- accent: {
590
- fg: black
591
- },
592
- link: {
593
- fg: black
594
- },
595
- code: {
596
- bg: black,
597
- fg: black
598
- },
599
- skeleton: base.skeleton
600
- };
601
- },
602
- button: ({
603
- base,
604
- mode,
605
- muted,
606
- solid
607
- }) => mode === "bleed" ? {
608
- ...muted,
609
- enabled: {
610
- bg: "transparent",
611
- bg2: "transparent",
612
- fg: muted.enabled.fg,
613
- icon: muted.enabled.fg,
614
- border: "transparent",
615
- muted: {
616
- fg: black
617
- },
618
- accent: {
619
- fg: black
620
- },
621
- link: {
622
- fg: black
623
- },
624
- code: {
625
- bg: black,
626
- fg: black
627
- },
628
- skeleton: base.skeleton
629
- },
630
- hovered: {
631
- bg: muted.enabled.bg,
632
- bg2: muted.enabled.bg,
633
- fg: muted.hovered.fg,
634
- icon: muted.hovered.fg,
635
- border: "transparent",
636
- muted: {
637
- fg: black
638
- },
639
- accent: {
640
- fg: black
641
- },
642
- link: {
643
- fg: black
644
- },
645
- code: {
646
- bg: black,
647
- fg: black
648
- },
649
- skeleton: base.skeleton
650
- }
651
- } : mode === "ghost" ? {
652
- ...solid,
653
- enabled: muted.enabled
654
- } : solid,
655
- card: ({
656
- base
657
- }) => ({
658
- bg: black,
659
- bg2: black,
660
- fg: black,
661
- icon: black,
662
- border: black,
663
- muted: {
664
- fg: black
665
- },
666
- accent: {
667
- fg: black
668
- },
669
- link: {
670
- fg: black
671
- },
672
- code: {
673
- bg: black,
674
- fg: black
675
- },
676
- skeleton: base.skeleton
677
- }),
678
- input: () => ({
679
- bg: black,
680
- bg2: black,
681
- fg: black,
682
- border: black,
683
- placeholder: black
684
- }),
685
- selectable: ({
686
- muted,
687
- state,
688
- tone
689
- }) => muted[tone][state],
690
- spot: ({
691
- key
692
- }) => spots[key],
693
- syntax: () => ({
694
- atrule: black,
695
- attrName: black,
696
- attrValue: black,
697
- attribute: black,
698
- boolean: black,
699
- builtin: black,
700
- cdata: black,
701
- char: black,
702
- class: black,
703
- className: black,
704
- comment: black,
705
- constant: black,
706
- deleted: black,
707
- doctype: black,
708
- entity: black,
709
- function: black,
710
- hexcode: black,
711
- id: black,
712
- important: black,
713
- inserted: black,
714
- keyword: black,
715
- number: black,
716
- operator: black,
717
- prolog: black,
718
- property: black,
719
- pseudoClass: black,
720
- pseudoElement: black,
721
- punctuation: black,
722
- regex: black,
723
- selector: black,
724
- string: black,
725
- symbol: black,
726
- tag: black,
727
- unit: black,
728
- url: black,
729
- variable: black
730
- })
731
- };
732
- function createInputModes(opts, base, dark, solid, muted) {
733
- return {
734
- default: {
735
- enabled: opts.input({
736
- base,
737
- dark,
738
- mode: "default",
739
- state: "enabled",
740
- solid: solid.default,
741
- muted: muted.default
742
- }),
743
- disabled: opts.input({
744
- base,
745
- dark,
746
- mode: "default",
747
- state: "disabled",
748
- solid: solid.default,
749
- muted: muted.default
750
- }),
751
- hovered: opts.input({
752
- base,
753
- dark,
754
- mode: "default",
755
- state: "hovered",
756
- solid: solid.default,
757
- muted: muted.default
758
- }),
759
- readOnly: opts.input({
760
- base,
761
- dark,
762
- mode: "default",
763
- state: "readOnly",
764
- solid: solid.default,
765
- muted: muted.default
766
- })
767
- },
768
- invalid: {
769
- enabled: opts.input({
770
- base,
771
- dark,
772
- mode: "invalid",
773
- state: "enabled",
774
- solid: solid.default,
775
- muted: muted.default
776
- }),
777
- disabled: opts.input({
778
- base,
779
- dark,
780
- mode: "invalid",
781
- state: "disabled",
782
- solid: solid.default,
783
- muted: muted.default
784
- }),
785
- hovered: opts.input({
786
- base,
787
- dark,
788
- mode: "invalid",
789
- state: "hovered",
790
- solid: solid.default,
791
- muted: muted.default
792
- }),
793
- readOnly: opts.input({
794
- base,
795
- dark,
796
- mode: "invalid",
797
- state: "readOnly",
798
- solid: solid.default,
799
- muted: muted.default
800
- })
801
- }
802
- };
803
- }
804
- function createMutedTones(opts, base, dark, name) {
805
- return {
806
- default: {
807
- enabled: opts.muted({
808
- base,
809
- dark,
810
- tone: "default",
811
- name,
812
- state: "enabled"
813
- }),
814
- disabled: opts.muted({
815
- base,
816
- dark,
817
- tone: "default",
818
- name,
819
- state: "disabled"
820
- }),
821
- hovered: opts.muted({
822
- base,
823
- dark,
824
- tone: "default",
825
- name,
826
- state: "hovered"
827
- }),
828
- pressed: opts.muted({
829
- base,
830
- dark,
831
- tone: "default",
832
- name,
833
- state: "pressed"
834
- }),
835
- selected: opts.muted({
836
- base,
837
- dark,
838
- tone: "default",
839
- name,
840
- state: "selected"
841
- })
842
- },
843
- transparent: {
844
- enabled: opts.muted({
845
- base,
846
- dark,
847
- tone: "transparent",
848
- name,
849
- state: "enabled"
850
- }),
851
- disabled: opts.muted({
852
- base,
853
- dark,
854
- tone: "transparent",
855
- name,
856
- state: "disabled"
857
- }),
858
- hovered: opts.muted({
859
- base,
860
- dark,
861
- tone: "transparent",
862
- name,
863
- state: "hovered"
864
- }),
865
- pressed: opts.muted({
866
- base,
867
- dark,
868
- tone: "transparent",
869
- name,
870
- state: "pressed"
871
- }),
872
- selected: opts.muted({
873
- base,
874
- dark,
875
- tone: "transparent",
876
- name,
877
- state: "selected"
878
- })
879
- },
880
- primary: {
881
- enabled: opts.muted({
882
- base,
883
- dark,
884
- tone: "primary",
885
- name,
886
- state: "enabled"
887
- }),
888
- disabled: opts.muted({
889
- base,
890
- dark,
891
- tone: "primary",
892
- name,
893
- state: "disabled"
894
- }),
895
- hovered: opts.muted({
896
- base,
897
- dark,
898
- tone: "primary",
899
- name,
900
- state: "hovered"
901
- }),
902
- pressed: opts.muted({
903
- base,
904
- dark,
905
- tone: "primary",
906
- name,
907
- state: "pressed"
908
- }),
909
- selected: opts.muted({
910
- base,
911
- dark,
912
- tone: "primary",
913
- name,
914
- state: "selected"
915
- })
916
- },
917
- positive: {
918
- enabled: opts.muted({
919
- base,
920
- dark,
921
- tone: "positive",
922
- name,
923
- state: "enabled"
924
- }),
925
- disabled: opts.muted({
926
- base,
927
- dark,
928
- tone: "positive",
929
- name,
930
- state: "disabled"
931
- }),
932
- hovered: opts.muted({
933
- base,
934
- dark,
935
- tone: "positive",
936
- name,
937
- state: "hovered"
938
- }),
939
- pressed: opts.muted({
940
- base,
941
- dark,
942
- tone: "positive",
943
- name,
944
- state: "pressed"
945
- }),
946
- selected: opts.muted({
947
- base,
948
- dark,
949
- tone: "positive",
950
- name,
951
- state: "selected"
952
- })
953
- },
954
- caution: {
955
- enabled: opts.muted({
956
- base,
957
- dark,
958
- tone: "caution",
959
- name,
960
- state: "enabled"
961
- }),
962
- disabled: opts.muted({
963
- base,
964
- dark,
965
- tone: "caution",
966
- name,
967
- state: "disabled"
968
- }),
969
- hovered: opts.muted({
970
- base,
971
- dark,
972
- tone: "caution",
973
- name,
974
- state: "hovered"
975
- }),
976
- pressed: opts.muted({
977
- base,
978
- dark,
979
- tone: "caution",
980
- name,
981
- state: "pressed"
982
- }),
983
- selected: opts.muted({
984
- base,
985
- dark,
986
- tone: "caution",
987
- name,
988
- state: "selected"
989
- })
990
- },
991
- critical: {
992
- enabled: opts.muted({
993
- base,
994
- dark,
995
- tone: "critical",
996
- name,
997
- state: "enabled"
998
- }),
999
- disabled: opts.muted({
1000
- base,
1001
- dark,
1002
- tone: "critical",
1003
- name,
1004
- state: "disabled"
1005
- }),
1006
- hovered: opts.muted({
1007
- base,
1008
- dark,
1009
- tone: "critical",
1010
- name,
1011
- state: "hovered"
1012
- }),
1013
- pressed: opts.muted({
1014
- base,
1015
- dark,
1016
- tone: "critical",
1017
- name,
1018
- state: "pressed"
1019
- }),
1020
- selected: opts.muted({
1021
- base,
1022
- dark,
1023
- tone: "critical",
1024
- name,
1025
- state: "selected"
1026
- })
1027
- }
1028
- };
1029
- }
1030
- function createSpot(opts, base, dark) {
1031
- return {
1032
- gray: opts.spot({
1033
- base,
1034
- dark,
1035
- key: "gray"
1036
- }),
1037
- blue: opts.spot({
1038
- base,
1039
- dark,
1040
- key: "blue"
1041
- }),
1042
- purple: opts.spot({
1043
- base,
1044
- dark,
1045
- key: "purple"
1046
- }),
1047
- magenta: opts.spot({
1048
- base,
1049
- dark,
1050
- key: "magenta"
1051
- }),
1052
- red: opts.spot({
1053
- base,
1054
- dark,
1055
- key: "red"
1056
- }),
1057
- orange: opts.spot({
1058
- base,
1059
- dark,
1060
- key: "orange"
1061
- }),
1062
- yellow: opts.spot({
1063
- base,
1064
- dark,
1065
- key: "yellow"
1066
- }),
1067
- green: opts.spot({
1068
- base,
1069
- dark,
1070
- key: "green"
1071
- }),
1072
- cyan: opts.spot({
1073
- base,
1074
- dark,
1075
- key: "cyan"
1076
- })
1077
- };
1078
- }
1079
- function createColorTheme(partialOpts = {}) {
1080
- const builders = {
1081
- ...defaultOpts,
1082
- ...partialOpts
1083
- };
1084
- return {
1085
- light: _createColorScheme(builders, !1),
1086
- dark: _createColorScheme(builders, !0)
1087
- };
1088
- }
1089
- function _createColorScheme(opts, dark) {
1090
- return {
1091
- default: _createColor(opts, dark, "default"),
1092
- transparent: _createColor(opts, dark, "transparent"),
1093
- primary: _createColor(opts, dark, "primary"),
1094
- positive: _createColor(opts, dark, "positive"),
1095
- caution: _createColor(opts, dark, "caution"),
1096
- critical: _createColor(opts, dark, "critical")
1097
- };
1098
- }
1099
- function _createColor(opts, dark, name) {
1100
- const base = opts.base({
1101
- dark,
1102
- name
1103
- }), solid = createSolidTones(opts, base, dark, name), muted = createMutedTones(opts, base, dark, name);
1104
- return {
1105
- base,
1106
- button: createButtonModes(opts, base, dark, solid, muted),
1107
- card: createCardStates(opts, base, dark, name, solid, muted),
1108
- dark,
1109
- input: createInputModes(opts, base, dark, solid, muted),
1110
- selectable: createSelectableTones(opts, base, dark, solid, muted),
1111
- spot: createSpot(opts, base, dark),
1112
- syntax: opts.syntax({
1113
- base,
1114
- dark
1115
- }),
1116
- solid,
1117
- muted
1118
- };
1119
- }
1120
- const defaultThemeFonts = {
1121
- code: {
1122
- family: "ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace",
1123
- weights: {
1124
- regular: 400,
1125
- medium: 500,
1126
- semibold: 600,
1127
- bold: 700
1128
- },
1129
- sizes: [{
1130
- ascenderHeight: 4,
1131
- descenderHeight: 4,
1132
- fontSize: 10,
1133
- iconSize: 17,
1134
- lineHeight: 15,
1135
- letterSpacing: 0
1136
- }, {
1137
- ascenderHeight: 5,
1138
- descenderHeight: 5,
1139
- fontSize: 13,
1140
- iconSize: 21,
1141
- lineHeight: 19,
1142
- letterSpacing: 0
1143
- }, {
1144
- ascenderHeight: 6,
1145
- descenderHeight: 6,
1146
- fontSize: 16,
1147
- iconSize: 25,
1148
- lineHeight: 23,
1149
- letterSpacing: 0
1150
- }, {
1151
- ascenderHeight: 7,
1152
- descenderHeight: 7,
1153
- fontSize: 19,
1154
- iconSize: 29,
1155
- lineHeight: 27,
1156
- letterSpacing: 0
1157
- }, {
1158
- ascenderHeight: 8,
1159
- descenderHeight: 8,
1160
- fontSize: 22,
1161
- iconSize: 33,
1162
- lineHeight: 31,
1163
- letterSpacing: 0
1164
- }]
1165
- },
1166
- heading: {
1167
- family: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Liberation Sans", Helvetica, Arial, system-ui, sans-serif',
1168
- weights: {
1169
- regular: 700,
1170
- medium: 800,
1171
- semibold: 900,
1172
- bold: 900
1173
- },
1174
- sizes: [{
1175
- ascenderHeight: 5,
1176
- descenderHeight: 5,
1177
- fontSize: 13,
1178
- iconSize: 17,
1179
- lineHeight: 19,
1180
- letterSpacing: 0
1181
- }, {
1182
- ascenderHeight: 6,
1183
- descenderHeight: 6,
1184
- fontSize: 16,
1185
- iconSize: 25,
1186
- lineHeight: 23,
1187
- letterSpacing: 0
1188
- }, {
1189
- ascenderHeight: 7,
1190
- descenderHeight: 7,
1191
- fontSize: 21,
1192
- iconSize: 33,
1193
- lineHeight: 29,
1194
- letterSpacing: 0
1195
- }, {
1196
- ascenderHeight: 8,
1197
- descenderHeight: 8,
1198
- fontSize: 27,
1199
- iconSize: 41,
1200
- lineHeight: 35,
1201
- letterSpacing: 0
1202
- }, {
1203
- ascenderHeight: 9.5,
1204
- descenderHeight: 8.5,
1205
- fontSize: 33,
1206
- iconSize: 49,
1207
- lineHeight: 41,
1208
- letterSpacing: 0
1209
- }, {
1210
- ascenderHeight: 10.5,
1211
- descenderHeight: 9.5,
1212
- fontSize: 38,
1213
- iconSize: 53,
1214
- lineHeight: 47,
1215
- letterSpacing: 0
1216
- }]
1217
- },
1218
- label: {
1219
- family: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Liberation Sans", system-ui, sans-serif',
1220
- weights: {
1221
- regular: 600,
1222
- medium: 700,
1223
- semibold: 800,
1224
- bold: 900
1225
- },
1226
- sizes: [{
1227
- ascenderHeight: 2,
1228
- descenderHeight: 2,
1229
- fontSize: 8.1,
1230
- iconSize: 13,
1231
- lineHeight: 10,
1232
- letterSpacing: 0.5
1233
- }, {
1234
- ascenderHeight: 2,
1235
- descenderHeight: 2,
1236
- fontSize: 9.5,
1237
- iconSize: 15,
1238
- lineHeight: 11,
1239
- letterSpacing: 0.5
1240
- }, {
1241
- ascenderHeight: 2,
1242
- descenderHeight: 2,
1243
- fontSize: 10.8,
1244
- iconSize: 17,
1245
- lineHeight: 12,
1246
- letterSpacing: 0.5
1247
- }, {
1248
- ascenderHeight: 2,
1249
- descenderHeight: 2,
1250
- fontSize: 12.25,
1251
- iconSize: 19,
1252
- lineHeight: 13,
1253
- letterSpacing: 0.5
1254
- }, {
1255
- ascenderHeight: 2,
1256
- descenderHeight: 2,
1257
- fontSize: 13.6,
1258
- iconSize: 21,
1259
- lineHeight: 14,
1260
- letterSpacing: 0.5
1261
- }, {
1262
- ascenderHeight: 2,
1263
- descenderHeight: 2,
1264
- fontSize: 15,
1265
- iconSize: 23,
1266
- lineHeight: 15,
1267
- letterSpacing: 0.5
1268
- }]
1269
- },
1270
- text: {
1271
- family: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Liberation Sans", Helvetica, Arial, system-ui, sans-serif',
1272
- weights: {
1273
- regular: 400,
1274
- medium: 500,
1275
- semibold: 600,
1276
- bold: 700
1277
- },
1278
- sizes: [{
1279
- ascenderHeight: 4,
1280
- descenderHeight: 4,
1281
- fontSize: 10,
1282
- iconSize: 17,
1283
- lineHeight: 15,
1284
- letterSpacing: 0
1285
- }, {
1286
- ascenderHeight: 5,
1287
- descenderHeight: 5,
1288
- fontSize: 13,
1289
- iconSize: 21,
1290
- lineHeight: 19,
1291
- letterSpacing: 0
1292
- }, {
1293
- ascenderHeight: 6,
1294
- descenderHeight: 6,
1295
- fontSize: 15,
1296
- iconSize: 25,
1297
- lineHeight: 23,
1298
- letterSpacing: 0
1299
- }, {
1300
- ascenderHeight: 7,
1301
- descenderHeight: 7,
1302
- fontSize: 18,
1303
- iconSize: 29,
1304
- lineHeight: 27,
1305
- letterSpacing: 0
1306
- }, {
1307
- ascenderHeight: 8,
1308
- descenderHeight: 8,
1309
- fontSize: 21,
1310
- iconSize: 33,
1311
- lineHeight: 31,
1312
- letterSpacing: 0
1313
- }]
1314
- }
1315
- };
1316
- function is_v0(themeProp) {
1317
- return themeProp._version === 0;
1318
- }
1319
- function is_v2(themeProp) {
1320
- return themeProp._version === 2;
1321
- }
1322
- const cache$2 = /* @__PURE__ */ new WeakMap();
1323
- function v0_v2(v0) {
1324
- if (v0.v2) return v0.v2;
1325
- const cached_v2 = cache$2.get(v0);
1326
- if (cached_v2) return cached_v2;
1327
- const {
1328
- avatar,
1329
- button,
1330
- color: color2,
1331
- container,
1332
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1333
- focusRing: _unused_focusRing,
1334
- fonts: font,
1335
- input,
1336
- layer,
1337
- media,
1338
- radius,
1339
- shadows: shadow,
1340
- space,
1341
- styles: style
1342
- } = v0, v2 = {
1343
- _version: 2,
1344
- avatar: {
1345
- ...defaultThemeConfig.avatar,
1346
- ...avatar
1347
- },
1348
- button: {
1349
- ...defaultThemeConfig.button,
1350
- ...button
1351
- },
1352
- card: defaultThemeConfig.card,
1353
- color: {
1354
- light: {
1355
- transparent: themeColor_v0_v2(color2.light.transparent),
1356
- default: themeColor_v0_v2(color2.light.default),
1357
- neutral: themeColor_v0_v2(color2.light.transparent),
1358
- primary: themeColor_v0_v2(color2.light.primary),
1359
- suggest: themeColor_v0_v2(color2.light.primary),
1360
- positive: themeColor_v0_v2(color2.light.positive),
1361
- caution: themeColor_v0_v2(color2.light.caution),
1362
- critical: themeColor_v0_v2(color2.light.critical)
1363
- },
1364
- dark: {
1365
- transparent: themeColor_v0_v2(color2.dark.transparent),
1366
- default: themeColor_v0_v2(color2.dark.default),
1367
- neutral: themeColor_v0_v2(color2.dark.transparent),
1368
- primary: themeColor_v0_v2(color2.dark.primary),
1369
- suggest: themeColor_v0_v2(color2.dark.primary),
1370
- positive: themeColor_v0_v2(color2.dark.positive),
1371
- caution: themeColor_v0_v2(color2.dark.caution),
1372
- critical: themeColor_v0_v2(color2.dark.critical)
1373
- }
1374
- },
1375
- container,
1376
- font,
1377
- input: {
1378
- ...defaultThemeConfig.input,
1379
- ...input,
1380
- checkbox: {
1381
- ...defaultThemeConfig.input.checkbox,
1382
- ...input.checkbox
1383
- },
1384
- radio: {
1385
- ...defaultThemeConfig.input.radio,
1386
- ...input.radio
1387
- },
1388
- switch: {
1389
- ...defaultThemeConfig.input.switch,
1390
- ...input.switch
1391
- }
1392
- },
1393
- layer: layer ?? defaultThemeConfig.layer,
1394
- media,
1395
- radius,
1396
- shadow,
1397
- space,
1398
- style
1399
- };
1400
- return cache$2.set(v0, v2), v2;
1401
- }
1402
- const cache$1 = /* @__PURE__ */ new WeakMap();
1403
- function v2_v0(v2) {
1404
- const cachedTheme = cache$1.get(v2);
1405
- if (cachedTheme) return cachedTheme;
1406
- const {
1407
- avatar,
1408
- button,
1409
- color: color2,
1410
- container,
1411
- font: fonts,
1412
- input,
1413
- media,
1414
- radius,
1415
- shadow: shadows,
1416
- space,
1417
- style: styles
1418
- } = v2;
1419
- return {
1420
- _version: 0,
1421
- avatar,
1422
- button,
1423
- container,
1424
- color: {
1425
- light: {
1426
- transparent: themeColor_v2_v0(color2.light.transparent),
1427
- default: themeColor_v2_v0(color2.light.default),
1428
- primary: themeColor_v2_v0(color2.light.primary),
1429
- positive: themeColor_v2_v0(color2.light.positive),
1430
- caution: themeColor_v2_v0(color2.light.caution),
1431
- critical: themeColor_v2_v0(color2.light.critical)
1432
- },
1433
- dark: {
1434
- transparent: themeColor_v2_v0(color2.dark.transparent),
1435
- default: themeColor_v2_v0(color2.dark.default),
1436
- primary: themeColor_v2_v0(color2.dark.primary),
1437
- positive: themeColor_v2_v0(color2.dark.positive),
1438
- caution: themeColor_v2_v0(color2.dark.caution),
1439
- critical: themeColor_v2_v0(color2.dark.critical)
1440
- }
1441
- },
1442
- focusRing: input.text.focusRing,
1443
- fonts,
1444
- input,
1445
- media,
1446
- radius,
1447
- shadows,
1448
- space,
1449
- styles,
1450
- v2
1451
- };
1452
- }
1453
- function themeColor_v2_v0(color_v2) {
1454
- return {
1455
- base: {
1456
- bg: color_v2.bg,
1457
- fg: color_v2.fg,
1458
- border: color_v2.border,
1459
- focusRing: color_v2.focusRing,
1460
- shadow: color_v2.shadow
1461
- },
1462
- button: color_v2.button,
1463
- card: color_v2.selectable.default,
1464
- dark: color_v2._dark,
1465
- input: {
1466
- default: inputStatesThemeColor_v2_v0(color_v2.input.default),
1467
- invalid: inputStatesThemeColor_v2_v0(color_v2.input.invalid)
1468
- },
1469
- muted: {
1470
- ...color_v2.button.ghost,
1471
- transparent: color_v2.button.ghost.default
1472
- },
1473
- solid: {
1474
- ...color_v2.button.default,
1475
- transparent: color_v2.button.default.default
1476
- },
1477
- selectable: color_v2.selectable,
1478
- spot: {
1479
- gray: color_v2.avatar.gray.bg,
1480
- blue: color_v2.avatar.blue.bg,
1481
- purple: color_v2.avatar.purple.bg,
1482
- magenta: color_v2.avatar.magenta.bg,
1483
- red: color_v2.avatar.red.bg,
1484
- orange: color_v2.avatar.orange.bg,
1485
- yellow: color_v2.avatar.yellow.bg,
1486
- green: color_v2.avatar.green.bg,
1487
- cyan: color_v2.avatar.cyan.bg
1488
- },
1489
- syntax: color_v2.syntax
1490
- };
1491
- }
1492
- function inputStatesThemeColor_v2_v0(t) {
1493
- return {
1494
- enabled: inputStateThemeColor_v2_v0(t.enabled),
1495
- disabled: inputStateThemeColor_v2_v0(t.disabled),
1496
- readOnly: inputStateThemeColor_v2_v0(t.readOnly),
1497
- hovered: inputStateThemeColor_v2_v0(t.hovered)
1498
- };
1499
- }
1500
- function inputStateThemeColor_v2_v0(t) {
1501
- return {
1502
- bg: t.bg,
1503
- bg2: t.muted.bg,
1504
- border: t.border,
1505
- fg: t.fg,
1506
- placeholder: t.placeholder
1507
- };
1508
- }
1509
- const THEME_COLOR_SCHEMES = ["light", "dark"], THEME_COLOR_BLEND_MODES = ["multiply", "screen"], THEME_COLOR_CARD_TONES = [
1510
- "transparent",
1511
- "default",
1512
- "neutral",
1513
- "primary",
1514
- // deprecated
1515
- "suggest",
1516
- "positive",
1517
- "caution",
1518
- "critical"
1519
- ], THEME_COLOR_STATE_TONES = [
1520
- "default",
1521
- "neutral",
1522
- "primary",
1523
- // deprecated
1524
- "suggest",
1525
- "positive",
1526
- "caution",
1527
- "critical"
1528
- ], THEME_COLOR_STATES = ["enabled", "hovered", "pressed", "selected", "disabled"], THEME_COLOR_BUTTON_MODES = ["default", "ghost", "bleed"], THEME_COLOR_INPUT_MODES = ["default", "invalid"], THEME_COLOR_INPUT_STATES = ["enabled", "hovered", "readOnly", "disabled"], THEME_COLOR_AVATAR_COLORS = COLOR_HUES;
1529
- function isColorBlendModeValue(str) {
1530
- return THEME_COLOR_BLEND_MODES.includes(str);
1531
- }
1532
- function isColorHueKey(str) {
1533
- return COLOR_HUES.includes(str);
1534
- }
1535
- function isColorTintKey(str) {
1536
- return COLOR_TINTS.includes(str);
1537
- }
1538
- function isColorButtonMode(str) {
1539
- return THEME_COLOR_BUTTON_MODES.includes(str);
1540
- }
1541
- const COLOR_CONFIG_STATE_KEYS = ["_hue", "bg", "fg", "border", "focusRing", "muted/fg", "accent/fg", "link/fg", "code/bg", "code/fg", "skeleton/from", "skeleton/to", "status/dot", "status/icon"], COLOR_CONFIG_CARD_KEYS = [...COLOR_CONFIG_STATE_KEYS, "_hue", "bg", "fg", "border", "focusRing", "shadow/outline", "shadow/umbra", "shadow/penumbra", "shadow/ambient"], COLOR_CONFIG_BLEND_KEYS = ["_blend"], COLOR_CONFIG_AVATAR_COLORS = ["*", ...THEME_COLOR_AVATAR_COLORS], COLOR_CONFIG_CARD_TONES = ["*", ...THEME_COLOR_CARD_TONES], COLOR_CONFIG_STATE_TONES = ["*", ...THEME_COLOR_STATE_TONES], COLOR_CONFIG_STATES = ["*", ...THEME_COLOR_STATES], COLOR_CONFIG_INPUT_MODES = ["*", ...THEME_COLOR_INPUT_MODES], COLOR_CONFIG_INPUT_STATES = ["*", ...THEME_COLOR_INPUT_STATES];
1542
- function parseTokenKey(str) {
1543
- const segments = str.split("/"), segment0 = segments.shift() || "";
1544
- if (isColorConfigBaseTone(segment0)) {
1545
- const key = segments.join("/");
1546
- if (isColorConfigBaseKey(key))
1547
- return {
1548
- type: "base",
1549
- tone: segment0,
1550
- key
1551
- };
1552
- if (isColorConfigBlendKey(key))
1553
- return {
1554
- type: "base",
1555
- tone: segment0,
1556
- key
1557
- };
1558
- }
1559
- if (segment0 === "button") {
1560
- const segment1 = segments.shift() || "";
1561
- if (isColorConfigStateTone(segment1)) {
1562
- const segment2 = segments.shift() || "";
1563
- if (isColorButtonMode(segment2)) {
1564
- const key = segments.join("/");
1565
- if (isColorConfigStateKey(key))
1566
- return {
1567
- type: "button",
1568
- tone: segment1,
1569
- mode: segment2,
1570
- key
1571
- };
1572
- if (isColorConfigBlendKey(key))
1573
- return {
1574
- type: "button",
1575
- tone: segment1,
1576
- mode: segment2,
1577
- key
1578
- };
1579
- }
1580
- }
1581
- }
1582
- }
1583
- function isColorMixPercentValue(str) {
1584
- return /^\d+%$/.test(str);
1585
- }
1586
- function parseTokenValue(str) {
1587
- const segments = str.split("/");
1588
- let nextSegment = segments.shift() || "";
1589
- const [segment0, segment0mix] = nextSegment.split(" ");
1590
- if (isColorTintKey(segment0)) {
1591
- const tint = segment0, segment1 = segments.shift() || "";
1592
- if (isColorMixPercentValue(segment0mix)) {
1593
- const mix2 = Number(segment0mix.slice(0, -1)) / 100;
1594
- return {
1595
- type: "color",
1596
- tint,
1597
- mix: mix2
1598
- };
1599
- }
1600
- if (isColorOpacityValue(segment1)) {
1601
- const opacity = Number(segment1);
1602
- return {
1603
- type: "color",
1604
- tint,
1605
- opacity
1606
- };
1607
- }
1608
- return {
1609
- type: "color",
1610
- tint
1611
- };
1612
- }
1613
- if (isColorValue(segment0)) {
1614
- const key = segment0, segment1 = segments.shift() || "";
1615
- if (isColorMixPercentValue(segment0mix)) {
1616
- const mix2 = Number(segment0mix.slice(0, -1)) / 100;
1617
- return {
1618
- type: "color",
1619
- key,
1620
- mix: mix2
1621
- };
1622
- }
1623
- if (isColorOpacityValue(segment1)) {
1624
- const opacity = Number(segment1);
1625
- return {
1626
- type: "color",
1627
- key,
1628
- opacity
1629
- };
1630
- }
1631
- return {
1632
- type: "color",
1633
- key
1634
- };
1635
- }
1636
- if (isColorHueKey(segment0)) {
1637
- const hue = segment0;
1638
- nextSegment = segments.shift() || "";
1639
- const [segment1, segment1mix] = nextSegment.split(" ");
1640
- if (isColorTintKey(segment1)) {
1641
- const tint = segment1, segment2 = segments.shift() || "";
1642
- if (isColorMixPercentValue(segment1mix)) {
1643
- const mix2 = Number(segment1mix.slice(0, -1)) / 100;
1644
- return {
1645
- type: "color",
1646
- hue,
1647
- tint,
1648
- mix: mix2
1649
- };
1650
- }
1651
- if (isColorOpacityValue(segment2)) {
1652
- const opacity = Number(segment2);
1653
- return {
1654
- type: "color",
1655
- hue,
1656
- tint,
1657
- opacity
1658
- };
1659
- }
1660
- return {
1661
- type: "color",
1662
- hue,
1663
- tint
1664
- };
1665
- }
1666
- return {
1667
- type: "hue",
1668
- value: hue
1669
- };
1670
- }
1671
- if (isColorBlendModeValue(segment0))
1672
- return {
1673
- type: "blendMode",
1674
- value: segment0
1675
- };
1676
- }
1677
- function isColorConfigBaseTone(str) {
1678
- return COLOR_CONFIG_CARD_TONES.includes(str);
1679
- }
1680
- function isColorConfigBaseKey(str) {
1681
- return COLOR_CONFIG_CARD_KEYS.includes(str);
1682
- }
1683
- function isColorConfigStateKey(str) {
1684
- return COLOR_CONFIG_STATE_KEYS.includes(str);
1685
- }
1686
- function isColorConfigStateTone(str) {
1687
- return COLOR_CONFIG_STATE_TONES.includes(str);
1688
- }
1689
- function isColorConfigBlendKey(str) {
1690
- return COLOR_CONFIG_BLEND_KEYS.includes(str);
1691
- }
1692
- function isColorTokenValue(str) {
1693
- return parseTokenValue(str)?.type === "color" || parseTokenValue(str)?.type === "hue";
1694
- }
1695
- function isColorValue(str) {
1696
- return str === "black" || str === "white";
1697
- }
1698
- function isColorOpacityValue(str) {
1699
- return str === "0" || /^0\.[0-9]+$/.test(str) || str === "1";
1700
- }
1701
- function compileColorTokenValue(node) {
1702
- let key = "";
1703
- return node.key === "black" || node.key === "white" ? key = node.key : key = `${node.hue}/${node.tint}`, node.mix !== void 0 ? `${key} ${node.mix * 100}%` : (node.opacity !== void 0 && (key += `/${node.opacity}`), key);
1704
- }
1705
- const DEFAULT_COLOR_TOKEN_VALUE = ["500", "500"];
1706
- function resolveColorTokenValue(context, value = DEFAULT_COLOR_TOKEN_VALUE) {
1707
- const {
1708
- hue,
1709
- scheme
1710
- } = context, node = parseTokenValue(value[scheme === "light" ? 0 : 1]);
1711
- if (!node || node.type !== "color")
1712
- throw new Error(`Invalid color token: ${value[0]}`);
1713
- return compileColorTokenValue({
1714
- ...node,
1715
- hue: node.hue || hue
1716
- });
1717
- }
1718
- const defaultColorTokens = {
1719
- base: {
1720
- "*": {
1721
- _blend: ["multiply", "screen"],
1722
- accent: {
1723
- fg: ["purple/600", "purple/400"]
1724
- },
1725
- avatar: {
1726
- "*": {
1727
- _blend: ["screen", "multiply"],
1728
- bg: ["500", "400"],
1729
- fg: ["white", "black"]
1730
- }
1731
- },
1732
- backdrop: ["gray/200/0.5", "black/0.5"],
1733
- badge: {
1734
- "*": {
1735
- bg: ["100", "900"],
1736
- fg: ["600", "400"],
1737
- icon: ["500", "500"],
1738
- dot: ["500", "500"]
1739
- },
1740
- positive: {
1741
- bg: ["200 50%", "900"],
1742
- fg: ["600", "500"]
1743
- },
1744
- caution: {
1745
- bg: ["200 50%", "900"],
1746
- fg: ["600", "500"]
1747
- }
1748
- },
1749
- bg: ["50", "950"],
1750
- border: ["200", "800"],
1751
- code: {
1752
- bg: ["50", "950"],
1753
- fg: ["600", "400"]
1754
- },
1755
- fg: ["800", "200"],
1756
- focusRing: ["blue/500", "blue/500"],
1757
- icon: ["600", "400"],
1758
- kbd: {
1759
- bg: ["white", "black"],
1760
- fg: ["600", "400"],
1761
- border: ["200", "800"]
1762
- },
1763
- link: {
1764
- fg: ["blue/600", "blue/300"]
1765
- },
1766
- muted: {
1767
- bg: ["50", "950"],
1768
- fg: ["700 75%", "300 75%"]
1769
- },
1770
- shadow: {
1771
- outline: ["500/0.3", "500/0.4"],
1772
- umbra: ["gray/500/0.1", "black/0.2"],
1773
- penumbra: ["gray/500/0.07", "black/0.14"],
1774
- ambient: ["gray/500/0.06", "black/0.12"]
1775
- },
1776
- skeleton: {
1777
- from: ["100", "900"],
1778
- to: ["100 50%", "900 50%"]
1779
- }
1780
- },
1781
- transparent: {
1782
- bg: ["50", "black"]
1783
- },
1784
- default: {
1785
- bg: ["white", "950"],
1786
- fg: ["800", "200"],
1787
- muted: {
1788
- fg: ["600", "400"]
1789
- }
1790
- },
1791
- primary: {
1792
- _hue: "blue"
1793
- },
1794
- suggest: {
1795
- _hue: "purple"
1796
- },
1797
- positive: {
1798
- _hue: "green",
1799
- shadow: {
1800
- outline: ["500/0.4", "500/0.4"]
1801
- }
1802
- },
1803
- caution: {
1804
- _hue: "yellow",
1805
- shadow: {
1806
- outline: ["600/0.3", "500/0.4"]
1807
- }
1808
- },
1809
- critical: {
1810
- _hue: "red"
1811
- }
1812
- },
1813
- button: {
1814
- default: {
1815
- "*": {
1816
- "*": {
1817
- _blend: ["screen", "multiply"],
1818
- accent: {
1819
- fg: ["purple/300", "purple/700"]
1820
- },
1821
- avatar: {
1822
- "*": {
1823
- _blend: ["screen", "multiply"],
1824
- bg: ["500", "400"],
1825
- fg: ["white", "black"]
1826
- }
1827
- },
1828
- badge: {
1829
- "*": {
1830
- bg: ["900", "100"],
1831
- fg: ["400", "600"],
1832
- dot: ["500", "500"],
1833
- icon: ["500", "500"]
1834
- }
1835
- },
1836
- bg: ["500", "400"],
1837
- border: ["500/0", "400/0"],
1838
- code: {
1839
- bg: ["500 20%", "400 20%"],
1840
- fg: ["200", "600"]
1841
- },
1842
- fg: ["white", "black"],
1843
- icon: ["100 70%", "900 70%"],
1844
- kbd: {
1845
- bg: ["black", "white"],
1846
- fg: ["200", "600"],
1847
- border: ["800", "200"]
1848
- },
1849
- link: {
1850
- fg: ["blue/200", "blue/600"]
1851
- },
1852
- muted: {
1853
- bg: ["950", "50"],
1854
- fg: ["100 70%", "900 70%"]
1855
- },
1856
- skeleton: {
1857
- from: ["900", "100"],
1858
- to: ["900 50%", "100 50%"]
1859
- }
1860
- },
1861
- hovered: {
1862
- bg: ["600", "300"],
1863
- border: ["700/0", "300/0"]
1864
- },
1865
- pressed: {
1866
- bg: ["700", "300"]
1867
- },
1868
- selected: {
1869
- bg: ["700", "300"]
1870
- },
1871
- disabled: {
1872
- _hue: "gray",
1873
- accent: {
1874
- fg: ["100 70%", "900 70%"]
1875
- },
1876
- avatar: {
1877
- "*": {
1878
- _blend: ["screen", "multiply"],
1879
- bg: ["gray/500", "gray/400"],
1880
- fg: ["white", "black"]
1881
- }
1882
- },
1883
- badge: {
1884
- "*": {
1885
- bg: ["gray/700", "gray/300"],
1886
- fg: ["white", "black"],
1887
- dot: ["white", "black"],
1888
- icon: ["white", "black"]
1889
- }
1890
- },
1891
- bg: ["300", "600"],
1892
- code: {
1893
- bg: ["950", "50"],
1894
- fg: ["300", "600"]
1895
- },
1896
- fg: ["300", "600"],
1897
- muted: {
1898
- bg: ["950", "50"],
1899
- fg: ["300", "600"]
1900
- },
1901
- kbd: {
1902
- bg: ["black", "white"],
1903
- fg: ["white", "black"],
1904
- border: ["700", "300"]
1905
- },
1906
- link: {
1907
- fg: ["100 70%", "900 70%"]
1908
- }
1909
- }
1910
- },
1911
- default: {
1912
- "*": {
1913
- avatar: {
1914
- "*": {
1915
- _blend: ["screen", "multiply"],
1916
- bg: ["500", "400"],
1917
- fg: ["white", "black"]
1918
- }
1919
- },
1920
- bg: ["800", "200"],
1921
- muted: {
1922
- bg: ["950", "50"],
1923
- fg: ["400", "600"]
1924
- }
1925
- },
1926
- hovered: {
1927
- bg: ["900", "100"]
1928
- },
1929
- pressed: {
1930
- bg: ["black", "white"]
1931
- },
1932
- selected: {
1933
- bg: ["black", "white"]
1934
- }
1935
- }
1936
- },
1937
- ghost: {
1938
- "*": {
1939
- "*": {
1940
- _blend: ["multiply", "screen"],
1941
- accent: {
1942
- fg: ["purple/700 60%", "purple/300 70%"]
1943
- },
1944
- avatar: {
1945
- "*": {
1946
- _blend: ["screen", "multiply"],
1947
- bg: ["500", "400"],
1948
- fg: ["white", "black"]
1949
- }
1950
- },
1951
- badge: {
1952
- "*": {
1953
- bg: ["100", "900"],
1954
- fg: ["600", "400"],
1955
- dot: ["500", "500"],
1956
- icon: ["500", "500"]
1957
- }
1958
- },
1959
- bg: ["50", "950"],
1960
- border: ["100", "900"],
1961
- code: {
1962
- bg: ["500 10%", "400 10%"],
1963
- fg: ["700 60%", "400 60%"]
1964
- },
1965
- fg: ["600", "400"],
1966
- icon: ["700 60%", "300 60%"],
1967
- kbd: {
1968
- bg: ["white", "black"],
1969
- fg: ["600", "400"],
1970
- border: ["200", "800"]
1971
- },
1972
- link: {
1973
- fg: ["blue/700 60%", "blue/300 60%"]
1974
- },
1975
- muted: {
1976
- bg: ["100", "950"],
1977
- fg: ["700 60%", "300 60%"]
1978
- },
1979
- skeleton: {
1980
- from: ["100", "900"],
1981
- to: ["100 50%", "900 50%"]
1982
- }
1983
- },
1984
- hovered: {
1985
- bg: ["100", "900"],
1986
- fg: ["700", "300"]
1987
- },
1988
- pressed: {
1989
- bg: ["200", "800"],
1990
- fg: ["800", "200"]
1991
- },
1992
- selected: {
1993
- bg: ["200", "800"],
1994
- fg: ["800", "200"]
1995
- },
1996
- disabled: {
1997
- _hue: "gray",
1998
- accent: {
1999
- fg: ["200", "800"]
2000
- },
2001
- avatar: {
2002
- "*": {
2003
- _blend: ["screen", "multiply"],
2004
- bg: ["gray/100", "gray/900"],
2005
- fg: ["white", "black"]
2006
- }
2007
- },
2008
- badge: {
2009
- "*": {
2010
- _hue: "gray",
2011
- bg: ["50", "950"],
2012
- fg: ["gray/200", "gray/800"],
2013
- dot: ["gray/200", "gray/800"],
2014
- icon: ["gray/200", "gray/800"]
2015
- }
2016
- },
2017
- border: ["100", "900"],
2018
- code: {
2019
- bg: ["50", "950"],
2020
- fg: ["200", "800"]
2021
- },
2022
- fg: ["400", "600"],
2023
- icon: ["300", "700"],
2024
- muted: {
2025
- fg: ["300", "700"]
2026
- },
2027
- kbd: {
2028
- bg: ["white", "black"],
2029
- fg: ["200", "800"],
2030
- border: ["100", "900"]
2031
- },
2032
- link: {
2033
- fg: ["200", "800"]
2034
- }
2035
- }
2036
- },
2037
- positive: {
2038
- "*": {
2039
- border: ["600 20%", "800"]
2040
- }
2041
- },
2042
- caution: {
2043
- "*": {
2044
- border: ["600 20%", "800"]
2045
- }
2046
- }
2047
- },
2048
- bleed: {
2049
- "*": {
2050
- "*": {
2051
- _blend: ["multiply", "screen"],
2052
- accent: {
2053
- fg: ["purple/700 70%", "purple/300 70%"]
2054
- },
2055
- avatar: {
2056
- "*": {
2057
- _blend: ["screen", "multiply"],
2058
- bg: ["500", "400"],
2059
- fg: ["white", "black"]
2060
- }
2061
- },
2062
- badge: {
2063
- "*": {
2064
- bg: ["100", "900"],
2065
- fg: ["600", "400"],
2066
- dot: ["500", "500"],
2067
- icon: ["500", "500"]
2068
- }
2069
- },
2070
- bg: ["white", "black"],
2071
- border: ["white/0", "black/0"],
2072
- code: {
2073
- bg: ["50", "950"],
2074
- fg: ["700 75%", "300 75%"]
2075
- },
2076
- fg: ["700", "300"],
2077
- icon: ["700 75%", "300 75%"],
2078
- kbd: {
2079
- bg: ["white", "black"],
2080
- fg: ["700", "300"],
2081
- border: ["200", "800"]
2082
- },
2083
- link: {
2084
- fg: ["blue/700 70%", "blue/300 70%"]
2085
- },
2086
- muted: {
2087
- bg: ["100", "950"],
2088
- fg: ["700 75%", "300 75%"]
2089
- },
2090
- skeleton: {
2091
- from: ["100", "900"],
2092
- to: ["100 50%", "900 50%"]
2093
- }
2094
- },
2095
- hovered: {
2096
- bg: ["50", "950"],
2097
- fg: ["800", "200"],
2098
- icon: ["800 70%", "300 70%"]
2099
- },
2100
- pressed: {
2101
- bg: ["100", "900"],
2102
- fg: ["800", "200"],
2103
- icon: ["800 70%", "200 70%"]
2104
- },
2105
- selected: {
2106
- bg: ["100", "900"],
2107
- fg: ["800", "200"],
2108
- icon: ["800 60%", "200 60%"]
2109
- },
2110
- disabled: {
2111
- _hue: "gray",
2112
- accent: {
2113
- fg: ["200", "800"]
2114
- },
2115
- avatar: {
2116
- "*": {
2117
- _blend: ["screen", "multiply"],
2118
- bg: ["gray/100", "gray/900"],
2119
- fg: ["white", "black"]
2120
- }
2121
- },
2122
- badge: {
2123
- "*": {
2124
- _hue: "gray",
2125
- bg: ["50", "950"],
2126
- fg: ["gray/200", "gray/800"],
2127
- dot: ["gray/200", "gray/800"],
2128
- icon: ["gray/200", "gray/800"]
2129
- }
2130
- },
2131
- code: {
2132
- bg: ["50", "950"],
2133
- fg: ["200", "800"]
2134
- },
2135
- fg: ["400", "600"],
2136
- icon: ["300", "700"],
2137
- muted: {
2138
- fg: ["400", "600"]
2139
- },
2140
- kbd: {
2141
- bg: ["white", "black"],
2142
- fg: ["200", "800"],
2143
- border: ["100", "900"]
2144
- },
2145
- link: {
2146
- fg: ["200", "800"]
2147
- }
2148
- }
2149
- }
2150
- }
2151
- },
2152
- input: {
2153
- "*": {
2154
- "*": {
2155
- _blend: ["multiply", "screen"],
2156
- bg: ["white", "black"],
2157
- border: ["200", "700"],
2158
- fg: ["black", "200"],
2159
- muted: {
2160
- bg: ["50", "950"]
2161
- },
2162
- placeholder: ["400", "600"]
2163
- },
2164
- hovered: {
2165
- border: ["300", "700"]
2166
- },
2167
- readOnly: {
2168
- bg: ["50", "950"],
2169
- border: ["200", "800"],
2170
- fg: ["800", "200"]
2171
- },
2172
- disabled: {
2173
- bg: ["50", "950"],
2174
- fg: ["400", "600"],
2175
- border: ["100", "900"],
2176
- placeholder: ["200", "800 50%"]
2177
- }
2178
- },
2179
- invalid: {
2180
- "*": {
2181
- _hue: "red",
2182
- bg: ["100", "950"]
2183
- }
2184
- }
2185
- },
2186
- selectable: {
2187
- "*": {
2188
- "*": {
2189
- _blend: ["multiply", "screen"],
2190
- accent: {
2191
- fg: ["purple/700 70%", "purple/300 70%"]
2192
- },
2193
- avatar: {
2194
- "*": {
2195
- _blend: ["screen", "multiply"],
2196
- bg: ["500", "400"],
2197
- fg: ["white", "black"]
2198
- }
2199
- },
2200
- badge: {
2201
- "*": {
2202
- bg: ["100", "900"],
2203
- fg: ["600", "400"],
2204
- dot: ["500", "500"],
2205
- icon: ["500", "500"]
2206
- }
2207
- },
2208
- bg: ["white", "black"],
2209
- border: ["200", "800"],
2210
- code: {
2211
- bg: ["50", "950"],
2212
- fg: ["600", "400"]
2213
- },
2214
- fg: ["700", "300"],
2215
- icon: ["700 75%", "300 75%"],
2216
- kbd: {
2217
- bg: ["white", "black"],
2218
- fg: ["600", "400"],
2219
- border: ["200", "800"]
2220
- },
2221
- link: {
2222
- fg: ["blue/700 70%", "blue/300 70%"]
2223
- },
2224
- muted: {
2225
- bg: ["50", "950"],
2226
- fg: ["700 75%", "300 75%"]
2227
- },
2228
- skeleton: {
2229
- from: ["100", "900"],
2230
- to: ["100 50%", "900 50%"]
2231
- }
2232
- },
2233
- hovered: {
2234
- bg: ["50", "950"]
2235
- },
2236
- pressed: {
2237
- bg: ["100", "900"]
2238
- },
2239
- selected: {
2240
- _blend: ["screen", "multiply"],
2241
- accent: {
2242
- fg: ["purple/300", "purple/700"]
2243
- },
2244
- avatar: {
2245
- "*": {
2246
- _blend: ["multiply", "screen"],
2247
- bg: ["white", "black"],
2248
- fg: ["black", "white"]
2249
- }
2250
- },
2251
- badge: {
2252
- "*": {
2253
- bg: ["900", "100"],
2254
- fg: ["400", "600"],
2255
- dot: ["500", "500"],
2256
- icon: ["500", "500"]
2257
- }
2258
- },
2259
- bg: ["500", "400"],
2260
- border: ["500 20%", "400 20%"],
2261
- code: {
2262
- bg: ["500 20%", "400 20%"],
2263
- fg: ["200", "600"]
2264
- },
2265
- fg: ["white", "black"],
2266
- icon: ["100 70%", "900 70%"],
2267
- kbd: {
2268
- bg: ["black", "white"],
2269
- fg: ["200", "600"],
2270
- border: ["800", "200"]
2271
- },
2272
- link: {
2273
- fg: ["blue/200", "blue/600"]
2274
- },
2275
- muted: {
2276
- bg: ["500 10%", "400 10%"],
2277
- fg: ["100 70%", "900 70%"]
2278
- },
2279
- skeleton: {
2280
- from: ["900", "100"],
2281
- to: ["900 50%", "100 50%"]
2282
- }
2283
- },
2284
- disabled: {
2285
- _hue: "gray",
2286
- accent: {
2287
- fg: ["200", "800"]
2288
- },
2289
- avatar: {
2290
- "*": {
2291
- _blend: ["screen", "multiply"],
2292
- bg: ["gray/100", "gray/900"],
2293
- fg: ["white", "black"]
2294
- }
2295
- },
2296
- badge: {
2297
- "*": {
2298
- _hue: "gray",
2299
- bg: ["50", "950"],
2300
- fg: ["gray/200", "gray/800"],
2301
- dot: ["gray/200", "gray/800"],
2302
- icon: ["gray/200", "gray/800"]
2303
- }
2304
- },
2305
- border: ["100", "900"],
2306
- code: {
2307
- bg: ["50", "950"],
2308
- fg: ["200", "800"]
2309
- },
2310
- fg: ["200", "800"],
2311
- icon: ["200", "800"],
2312
- kbd: {
2313
- bg: ["white", "black"],
2314
- fg: ["200", "800"],
2315
- border: ["100", "900"]
2316
- },
2317
- link: {
2318
- fg: ["200", "800"]
2319
- },
2320
- muted: {
2321
- bg: ["50 50%", "950 50%"],
2322
- fg: ["200", "800"]
2323
- }
2324
- }
2325
- },
2326
- default: {
2327
- selected: {
2328
- _hue: "blue"
2329
- }
2330
- },
2331
- critical: {
2332
- disabled: {
2333
- bg: ["50 50%", "950 50%"]
2334
- }
2335
- }
2336
- },
2337
- syntax: {
2338
- atrule: ["purple/600", "purple/400"],
2339
- attrName: ["green/600", "green/400"],
2340
- attrValue: ["yellow/600", "yellow/400"],
2341
- attribute: ["yellow/600", "yellow/400"],
2342
- boolean: ["purple/600", "purple/400"],
2343
- builtin: ["purple/600", "purple/400"],
2344
- cdata: ["yellow/600", "yellow/400"],
2345
- char: ["yellow/600", "yellow/400"],
2346
- class: ["orange/600", "orange/400"],
2347
- className: ["cyan/600", "cyan/400"],
2348
- comment: ["gray/400", "gray/600"],
2349
- constant: ["purple/600", "purple/400"],
2350
- deleted: ["red/600", "red/400"],
2351
- entity: ["red/600", "red/400"],
2352
- function: ["green/600", "green/400"],
2353
- hexcode: ["blue/600", "blue/400"],
2354
- id: ["purple/600", "purple/400"],
2355
- important: ["purple/600", "purple/400"],
2356
- inserted: ["yellow/600", "yellow/400"],
2357
- keyword: ["magenta/600", "magenta/400"],
2358
- number: ["purple/600", "purple/400"],
2359
- operator: ["magenta/600", "magenta/400"],
2360
- property: ["blue/600", "blue/400"],
2361
- pseudoClass: ["yellow/600", "yellow/400"],
2362
- pseudoElement: ["yellow/600", "yellow/400"],
2363
- punctuation: ["gray/600", "gray/400"],
2364
- regex: ["blue/600", "blue/400"],
2365
- selector: ["red/600", "red/400"],
2366
- string: ["yellow/600", "yellow/400"],
2367
- symbol: ["purple/600", "purple/400"],
2368
- tag: ["red/600", "red/400"],
2369
- unit: ["orange/600", "orange/400"],
2370
- url: ["red/600", "red/400"],
2371
- variable: ["red/600", "red/400"]
2372
- }
2373
- };
2374
- function isRecord(value) {
2375
- return !!(value && typeof value == "object" && !Array.isArray(value));
2376
- }
2377
- function merge(...records) {
2378
- const _records = records.filter(Boolean);
2379
- return _records.length === 0 ? {} : _records.reduce(_merge, {});
2380
- }
2381
- function _merge(acc, source) {
2382
- for (const key of Object.keys(source)) {
2383
- const prevValue = acc[key], nextValue = source[key];
2384
- isRecord(prevValue) && isRecord(nextValue) ? acc[key] = merge(prevValue, nextValue) : acc[key] = nextValue;
2385
- }
2386
- return acc;
2387
- }
2388
- function resolveColorTokens(inputTokens) {
2389
- const tokens = merge(defaultColorTokens, inputTokens);
2390
- return {
2391
- base: resolveBaseColorTokens(tokens),
2392
- button: resolveButtonColorTokens(tokens),
2393
- input: resolveInputColorTokens(tokens),
2394
- selectable: resolveSelectableColorTokens(tokens),
2395
- syntax: tokens.syntax
2396
- };
2397
- }
2398
- function resolveBaseColorTokens(sparseTokens) {
2399
- const tokens = {};
2400
- for (const tone of THEME_COLOR_CARD_TONES)
2401
- tokens[tone] = resolveBaseColorTones(sparseTokens, tone);
2402
- return tokens;
2403
- }
2404
- function resolveBaseColorTones(inputTokens, tone) {
2405
- const spec = merge(inputTokens?.base?.["*"], inputTokens?.base?.[tone]), hue = spec._hue || inputTokens?.base?.[tone]?._hue || "gray";
2406
- return {
2407
- ...spec,
2408
- _hue: hue,
2409
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2410
- ...acc,
2411
- [hue2]: merge({
2412
- _hue: hue2
2413
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2414
- }), {}),
2415
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2416
- ...acc,
2417
- [tone2]: {
2418
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2419
- ...spec.badge?.["*"],
2420
- ...spec.badge?.[tone2]
2421
- }
2422
- }), {})
2423
- };
2424
- }
2425
- function resolveButtonColorTokens(inputTokens) {
2426
- const tokens = {};
2427
- for (const mode of THEME_COLOR_BUTTON_MODES)
2428
- tokens[mode] = resolveButtonToneColorTokens(inputTokens, mode);
2429
- return tokens;
2430
- }
2431
- function resolveButtonToneColorTokens(inputTokens, mode) {
2432
- const tokens = {};
2433
- for (const tone of THEME_COLOR_STATE_TONES)
2434
- tokens[tone] = resolveButtonModeColorTokens(inputTokens, mode, tone);
2435
- return tokens;
2436
- }
2437
- function resolveButtonModeColorTokens(inputTokens, mode, tone) {
2438
- const tokens = {};
2439
- for (const state of THEME_COLOR_STATES)
2440
- tokens[state] = resolveButtonStateColorTokens(inputTokens, tone, mode, state);
2441
- return tokens;
2442
- }
2443
- function resolveButtonStateColorTokens(inputTokens, tone, mode, state) {
2444
- const spec = merge(inputTokens?.button?.[mode]?.["*"]?.["*"], inputTokens?.button?.[mode]?.[tone]?.["*"], inputTokens?.button?.[mode]?.["*"]?.[state], inputTokens?.button?.[mode]?.[tone]?.[state]), hue = spec._hue || inputTokens?.base?.[tone]?._hue;
2445
- return {
2446
- ...spec,
2447
- _hue: hue,
2448
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2449
- ...acc,
2450
- [hue2]: merge({
2451
- _hue: hue2
2452
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2453
- }), {}),
2454
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2455
- ...acc,
2456
- [tone2]: {
2457
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2458
- ...spec.badge?.["*"],
2459
- ...spec.badge?.[tone2]
2460
- }
2461
- }), {})
2462
- };
2463
- }
2464
- function resolveInputColorTokens(inputTokens) {
2465
- const tokens = {};
2466
- for (const mode of THEME_COLOR_INPUT_MODES)
2467
- tokens[mode] = resolveInputModeColorTokens(inputTokens, mode);
2468
- return tokens;
2469
- }
2470
- function resolveInputModeColorTokens(inputTokens, mode) {
2471
- const states = {};
2472
- for (const state of THEME_COLOR_INPUT_STATES)
2473
- states[state] = resolveInputStateColorTokens(inputTokens, mode, state);
2474
- return states;
2475
- }
2476
- function resolveInputStateColorTokens(inputTokens, mode, state) {
2477
- const spec = merge(inputTokens?.input?.["*"]?.["*"], inputTokens?.input?.[mode]?.["*"], inputTokens?.input?.["*"]?.[state], inputTokens?.input?.[mode]?.[state]), hue = spec._hue || inputTokens?.input?.[mode]?._hue;
2478
- return {
2479
- ...spec,
2480
- _hue: hue
2481
- };
2482
- }
2483
- function resolveSelectableColorTokens(inputTokens) {
2484
- const tokens = {};
2485
- for (const tone of THEME_COLOR_STATE_TONES)
2486
- tokens[tone] = resolveSelectableToneColorTokens(inputTokens, tone);
2487
- return tokens;
2488
- }
2489
- function resolveSelectableToneColorTokens(inputTokens, tone) {
2490
- const states = {
2491
- _hue: inputTokens?.selectable?.[tone]?._hue || inputTokens?.base?.[tone]?._hue
2492
- };
2493
- for (const state of THEME_COLOR_STATES)
2494
- states[state] = resolveSelectableStateColorTokens(inputTokens, tone, state);
2495
- return states;
2496
- }
2497
- function resolveSelectableStateColorTokens(inputTokens, tone, state) {
2498
- const spec = merge(inputTokens?.selectable?.["*"]?.["*"], inputTokens?.selectable?.[tone]?.["*"], inputTokens?.selectable?.["*"]?.[state], inputTokens?.selectable?.[tone]?.[state]), hue = spec._hue || inputTokens?.base?.[tone]?._hue;
2499
- return {
2500
- ...spec,
2501
- _hue: hue,
2502
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2503
- ...acc,
2504
- [hue2]: merge({
2505
- _hue: hue2
2506
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2507
- }), {}),
2508
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2509
- ...acc,
2510
- [tone2]: {
2511
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2512
- ...spec.badge?.["*"],
2513
- ...spec.badge?.[tone2]
2514
- }
2515
- }), {})
2516
- };
2517
- }
2518
- function buildColorTheme(config) {
2519
- const resolvedConfig = {
2520
- ...config,
2521
- color: resolveColorTokens(config?.color)
2522
- };
2523
- return {
2524
- light: buildColorScheme({
2525
- scheme: "light"
2526
- }, resolvedConfig),
2527
- dark: buildColorScheme({
2528
- scheme: "dark"
2529
- }, resolvedConfig)
2530
- };
2531
- }
2532
- function buildColorScheme(options, config) {
2533
- const {
2534
- scheme
2535
- } = options, colorScheme = {};
2536
- for (const tone of THEME_COLOR_CARD_TONES)
2537
- colorScheme[tone] = buildCardColorTheme({
2538
- scheme,
2539
- tone
2540
- }, config);
2541
- return colorScheme;
2542
- }
2543
- function buildCardColorTheme(options, config) {
2544
- const {
2545
- scheme,
2546
- tone
2547
- } = options, tokens = config?.color?.base?.[tone], context = {
2548
- hue: tokens?._hue || "gray",
2549
- scheme
2550
- };
2551
- return {
2552
- _blend: (tokens?._blend || ["multiply", "screen"])[scheme === "light" ? 0 : 1],
2553
- _dark: scheme === "dark",
2554
- accent: {
2555
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2556
- },
2557
- avatar: buildAvatarColorTheme({
2558
- scheme
2559
- }, tokens),
2560
- backdrop: resolveColorTokenValue(context, tokens?.backdrop),
2561
- badge: buildBadgeColorTheme(tokens?.badge, {
2562
- scheme
2563
- }, config),
2564
- bg: resolveColorTokenValue(context, tokens?.bg),
2565
- border: resolveColorTokenValue(context, tokens?.border),
2566
- button: buildButtonColorTheme({
2567
- scheme,
2568
- tone
2569
- }, config),
2570
- code: {
2571
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2572
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2573
- },
2574
- fg: resolveColorTokenValue(context, tokens?.fg),
2575
- focusRing: resolveColorTokenValue(context, tokens?.focusRing),
2576
- icon: resolveColorTokenValue(context, tokens?.icon),
2577
- input: buildInputColorTheme({
2578
- scheme,
2579
- tone
2580
- }, config),
2581
- kbd: {
2582
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2583
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2584
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2585
- },
2586
- link: {
2587
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2588
- },
2589
- muted: {
2590
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2591
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2592
- },
2593
- selectable: buildSelectableColorTheme({
2594
- scheme,
2595
- tone
2596
- }, config),
2597
- shadow: buildShadowColorTheme({
2598
- scheme,
2599
- tone
2600
- }, config),
2601
- skeleton: {
2602
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2603
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2604
- },
2605
- syntax: buildSyntaxColorTheme({
2606
- scheme
2607
- }, config)
2608
- };
2609
- }
2610
- function buildShadowColorTheme(options, config) {
2611
- const {
2612
- scheme,
2613
- tone
2614
- } = options, tokens = config?.color?.base?.[tone], context = {
2615
- hue: tokens?._hue || "gray",
2616
- scheme
2617
- };
2618
- return {
2619
- outline: resolveColorTokenValue(context, tokens?.shadow?.outline),
2620
- umbra: resolveColorTokenValue(context, tokens?.shadow?.umbra),
2621
- penumbra: resolveColorTokenValue(context, tokens?.shadow?.penumbra),
2622
- ambient: resolveColorTokenValue(context, tokens?.shadow?.ambient)
2623
- };
2624
- }
2625
- function buildAvatarColorTheme(options, stateTokens) {
2626
- const {
2627
- scheme
2628
- } = options;
2629
- return {
2630
- gray: _buildAvatarColorTheme({
2631
- color: "gray",
2632
- scheme
2633
- }, stateTokens),
2634
- blue: _buildAvatarColorTheme({
2635
- color: "blue",
2636
- scheme
2637
- }, stateTokens),
2638
- purple: _buildAvatarColorTheme({
2639
- color: "purple",
2640
- scheme
2641
- }, stateTokens),
2642
- magenta: _buildAvatarColorTheme({
2643
- color: "magenta",
2644
- scheme
2645
- }, stateTokens),
2646
- red: _buildAvatarColorTheme({
2647
- color: "red",
2648
- scheme
2649
- }, stateTokens),
2650
- orange: _buildAvatarColorTheme({
2651
- color: "orange",
2652
- scheme
2653
- }, stateTokens),
2654
- yellow: _buildAvatarColorTheme({
2655
- color: "yellow",
2656
- scheme
2657
- }, stateTokens),
2658
- green: _buildAvatarColorTheme({
2659
- color: "green",
2660
- scheme
2661
- }, stateTokens),
2662
- cyan: _buildAvatarColorTheme({
2663
- color: "cyan",
2664
- scheme
2665
- }, stateTokens)
2666
- };
2667
- }
2668
- function _buildAvatarColorTheme(options, stateTokens) {
2669
- const {
2670
- color: color2,
2671
- scheme
2672
- } = options, tokens = stateTokens?.avatar?.[color2], context = {
2673
- hue: tokens?._hue || "gray",
2674
- scheme
2675
- };
2676
- return {
2677
- _blend: (tokens?._blend || ["screen", "multiply"])[scheme === "light" ? 0 : 1],
2678
- bg: resolveColorTokenValue(context, tokens?.bg),
2679
- fg: resolveColorTokenValue(context, tokens?.fg)
2680
- };
2681
- }
2682
- function buildBadgeColorTheme(tokens, options, config) {
2683
- const {
2684
- scheme
2685
- } = options, colorBadge = {};
2686
- for (const tone of THEME_COLOR_STATE_TONES)
2687
- colorBadge[tone] = _buildBadgeColorTheme(tokens, {
2688
- scheme,
2689
- tone
2690
- }, config);
2691
- return colorBadge;
2692
- }
2693
- function _buildBadgeColorTheme(parentTokens, options, config) {
2694
- const {
2695
- scheme,
2696
- tone
2697
- } = options, tokens = parentTokens?.[tone], context = {
2698
- hue: tokens?._hue || config?.color?.base?.[tone]?._hue || "gray",
2699
- scheme
2700
- };
2701
- return {
2702
- bg: resolveColorTokenValue(context, tokens?.bg),
2703
- fg: resolveColorTokenValue(context, tokens?.fg),
2704
- dot: resolveColorTokenValue(context, tokens?.dot),
2705
- icon: resolveColorTokenValue(context, tokens?.icon)
2706
- };
2707
- }
2708
- function buildButtonColorTheme(options, config) {
2709
- const {
2710
- scheme,
2711
- tone: cardTone
2712
- } = options, modes = {};
2713
- for (const mode of THEME_COLOR_BUTTON_MODES)
2714
- modes[mode] = buildButtonTonesColorTheme({
2715
- cardTone,
2716
- scheme,
2717
- mode
2718
- }, config);
2719
- return modes;
2720
- }
2721
- function buildButtonTonesColorTheme(options, config) {
2722
- const {
2723
- cardTone,
2724
- mode,
2725
- scheme
2726
- } = options, tones2 = {};
2727
- for (const tone of THEME_COLOR_STATE_TONES)
2728
- tones2[tone] = buildButtonStatesColorTheme({
2729
- cardTone,
2730
- mode,
2731
- scheme,
2732
- tone
2733
- }, config);
2734
- return tones2;
2735
- }
2736
- function buildButtonStatesColorTheme(options, config) {
2737
- const {
2738
- cardTone,
2739
- mode,
2740
- scheme,
2741
- tone
2742
- } = options, states = {};
2743
- for (const state of THEME_COLOR_STATES)
2744
- states[state] = buildButtonStateColorTheme({
2745
- cardTone,
2746
- mode,
2747
- tone,
2748
- scheme,
2749
- state
2750
- }, config);
2751
- return states;
2752
- }
2753
- function buildButtonStateColorTheme(options, config) {
2754
- const {
2755
- cardTone,
2756
- mode,
2757
- tone,
2758
- scheme,
2759
- state
2760
- } = options, cardTokens = config?.color?.base?.[cardTone], tokens = config?.color?.button?.[mode]?.[tone]?.[state], hue = tokens?._hue || cardTokens?._hue || "gray", blendMode = tokens?._blend || ["screen", "multiply"], context = {
2761
- hue,
2762
- scheme
2763
- };
2764
- return {
2765
- _blend: blendMode[scheme === "light" ? 0 : 1],
2766
- accent: {
2767
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2768
- },
2769
- avatar: buildAvatarColorTheme({
2770
- scheme
2771
- }, tokens),
2772
- badge: buildBadgeColorTheme(tokens?.badge, {
2773
- scheme
2774
- }, config),
2775
- bg: resolveColorTokenValue(context, tokens?.bg),
2776
- border: resolveColorTokenValue(context, tokens?.border),
2777
- code: {
2778
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2779
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2780
- },
2781
- fg: resolveColorTokenValue(context, tokens?.fg),
2782
- icon: resolveColorTokenValue(context, tokens?.icon),
2783
- muted: {
2784
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2785
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2786
- },
2787
- kbd: {
2788
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2789
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2790
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2791
- },
2792
- link: {
2793
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2794
- },
2795
- skeleton: {
2796
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2797
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2798
- }
2799
- };
2800
- }
2801
- function buildInputColorTheme(options, config) {
2802
- const {
2803
- scheme,
2804
- tone
2805
- } = options;
2806
- return {
2807
- default: buildInputStatesColorTheme({
2808
- mode: "default",
2809
- scheme,
2810
- tone
2811
- }, config),
2812
- invalid: buildInputStatesColorTheme({
2813
- mode: "invalid",
2814
- scheme,
2815
- tone
2816
- }, config)
2817
- };
2818
- }
2819
- function buildInputStatesColorTheme(options, config) {
2820
- const {
2821
- mode,
2822
- scheme,
2823
- tone
2824
- } = options;
2825
- return {
2826
- enabled: buildInputStateColorTheme({
2827
- mode,
2828
- scheme,
2829
- state: "enabled",
2830
- cardTone: tone
2831
- }, config),
2832
- hovered: buildInputStateColorTheme({
2833
- mode,
2834
- scheme,
2835
- state: "hovered",
2836
- cardTone: tone
2837
- }, config),
2838
- readOnly: buildInputStateColorTheme({
2839
- mode,
2840
- scheme,
2841
- state: "readOnly",
2842
- cardTone: tone
2843
- }, config),
2844
- disabled: buildInputStateColorTheme({
2845
- mode,
2846
- scheme,
2847
- state: "disabled",
2848
- cardTone: tone
2849
- }, config)
2850
- };
2851
- }
2852
- function buildInputStateColorTheme(options, config) {
2853
- const {
2854
- cardTone,
2855
- mode,
2856
- scheme,
2857
- state
2858
- } = options, cardTokens = config?.color?.base?.[cardTone], tokens = config?.color?.input?.[mode]?.[state], hue = tokens?._hue || cardTokens?._hue || "gray", blendMode = tokens?._blend || ["screen", "multiply"], context = {
2859
- hue,
2860
- scheme
2861
- };
2862
- return {
2863
- _blend: blendMode[scheme === "light" ? 0 : 1],
2864
- bg: resolveColorTokenValue(context, tokens?.bg),
2865
- border: resolveColorTokenValue(context, tokens?.border),
2866
- fg: resolveColorTokenValue(context, tokens?.fg),
2867
- muted: {
2868
- bg: resolveColorTokenValue(context, tokens?.muted?.bg)
2869
- },
2870
- placeholder: resolveColorTokenValue(context, tokens?.placeholder)
2871
- };
2872
- }
2873
- function buildSelectableColorTheme(options, config) {
2874
- const {
2875
- scheme,
2876
- tone: cardTone
2877
- } = options, tones2 = {};
2878
- for (const tone of THEME_COLOR_STATE_TONES)
2879
- tones2[tone] = buildSelectableStatesColorTheme({
2880
- cardTone,
2881
- scheme,
2882
- tone
2883
- }, config);
2884
- return tones2;
2885
- }
2886
- function buildSelectableStatesColorTheme(options, config) {
2887
- const {
2888
- cardTone,
2889
- scheme,
2890
- tone
2891
- } = options, states = {};
2892
- for (const state of THEME_COLOR_STATES)
2893
- states[state] = buildSelectableStateColorTheme({
2894
- cardTone,
2895
- tone,
2896
- scheme,
2897
- state
2898
- }, config);
2899
- return states;
2900
- }
2901
- function buildSelectableStateColorTheme(options, config) {
2902
- const {
2903
- cardTone,
2904
- scheme,
2905
- state,
2906
- tone
2907
- } = options, cardTokens = config?.color?.base?.[cardTone], tokens = config?.color?.selectable?.[tone]?.[state], hue = tokens?._hue || cardTokens?._hue || "gray", blendMode = tokens?._blend || ["screen", "multiply"], context = {
2908
- hue,
2909
- scheme
2910
- };
2911
- return {
2912
- _blend: blendMode[scheme === "light" ? 0 : 1],
2913
- accent: {
2914
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2915
- },
2916
- avatar: buildAvatarColorTheme({
2917
- scheme
2918
- }, tokens),
2919
- badge: buildBadgeColorTheme(tokens?.badge, {
2920
- scheme
2921
- }, config),
2922
- bg: resolveColorTokenValue(context, tokens?.bg),
2923
- border: resolveColorTokenValue(context, tokens?.border),
2924
- code: {
2925
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2926
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2927
- },
2928
- fg: resolveColorTokenValue(context, tokens?.fg),
2929
- icon: resolveColorTokenValue(context, tokens?.icon),
2930
- muted: {
2931
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2932
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2933
- },
2934
- kbd: {
2935
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2936
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2937
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2938
- },
2939
- link: {
2940
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2941
- },
2942
- skeleton: {
2943
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2944
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2945
- }
2946
- };
2947
- }
2948
- function buildSyntaxColorTheme(options, config) {
2949
- const {
2950
- scheme
2951
- } = options, tokens = config?.color?.syntax, context = {
2952
- hue: "gray",
2953
- scheme
2954
- };
2955
- return {
2956
- atrule: resolveColorTokenValue(context, tokens?.atrule),
2957
- attrName: resolveColorTokenValue(context, tokens?.attrName),
2958
- attrValue: resolveColorTokenValue(context, tokens?.attrValue),
2959
- attribute: resolveColorTokenValue(context, tokens?.attribute),
2960
- boolean: resolveColorTokenValue(context, tokens?.boolean),
2961
- builtin: resolveColorTokenValue(context, tokens?.builtin),
2962
- cdata: resolveColorTokenValue(context, tokens?.cdata),
2963
- char: resolveColorTokenValue(context, tokens?.char),
2964
- class: resolveColorTokenValue(context, tokens?.class),
2965
- className: resolveColorTokenValue(context, tokens?.className),
2966
- comment: resolveColorTokenValue(context, tokens?.comment),
2967
- constant: resolveColorTokenValue(context, tokens?.constant),
2968
- deleted: resolveColorTokenValue(context, tokens?.deleted),
2969
- doctype: resolveColorTokenValue(context, tokens?.doctype),
2970
- entity: resolveColorTokenValue(context, tokens?.entity),
2971
- function: resolveColorTokenValue(context, tokens?.function),
2972
- hexcode: resolveColorTokenValue(context, tokens?.hexcode),
2973
- id: resolveColorTokenValue(context, tokens?.id),
2974
- important: resolveColorTokenValue(context, tokens?.important),
2975
- inserted: resolveColorTokenValue(context, tokens?.inserted),
2976
- keyword: resolveColorTokenValue(context, tokens?.keyword),
2977
- number: resolveColorTokenValue(context, tokens?.number),
2978
- operator: resolveColorTokenValue(context, tokens?.operator),
2979
- prolog: resolveColorTokenValue(context, tokens?.prolog),
2980
- property: resolveColorTokenValue(context, tokens?.property),
2981
- pseudoClass: resolveColorTokenValue(context, tokens?.pseudoClass),
2982
- pseudoElement: resolveColorTokenValue(context, tokens?.pseudoElement),
2983
- punctuation: resolveColorTokenValue(context, tokens?.punctuation),
2984
- regex: resolveColorTokenValue(context, tokens?.regex),
2985
- selector: resolveColorTokenValue(context, tokens?.selector),
2986
- string: resolveColorTokenValue(context, tokens?.string),
2987
- symbol: resolveColorTokenValue(context, tokens?.symbol),
2988
- tag: resolveColorTokenValue(context, tokens?.tag),
2989
- unit: resolveColorTokenValue(context, tokens?.unit),
2990
- url: resolveColorTokenValue(context, tokens?.url),
2991
- variable: resolveColorTokenValue(context, tokens?.variable)
2992
- };
2993
- }
2994
- const defaultColorPalette = color;
2995
- function mixChannel(b, s, weight) {
2996
- const delta = (s - b) * weight;
2997
- return b + delta;
2998
- }
2999
- function mix(b, s, weight) {
3000
- return {
3001
- r: mixChannel(b.r, s.r, weight),
3002
- g: mixChannel(b.g, s.g, weight),
3003
- b: mixChannel(b.b, s.b, weight)
3004
- };
3005
- }
3006
- function multiplyChannel(b, s) {
3007
- return b * s;
3008
- }
3009
- function multiply(b, s) {
3010
- return {
3011
- r: multiplyChannel(b.r / 255, s.r / 255) * 255,
3012
- g: multiplyChannel(b.g / 255, s.g / 255) * 255,
3013
- b: multiplyChannel(b.b / 255, s.b / 255) * 255
3014
- };
3015
- }
3016
- function screenChannel(b, s) {
3017
- return b + s - b * s;
3018
- }
3019
- function screen(b, s) {
3020
- return {
3021
- r: screenChannel(b.r / 255, s.r / 255) * 255,
3022
- g: screenChannel(b.g / 255, s.g / 255) * 255,
3023
- b: screenChannel(b.b / 255, s.b / 255) * 255
3024
- };
3025
- }
3026
- function lerp(x, y, a) {
3027
- return x * (1 - a) + y * a;
3028
- }
3029
- function invlerp(x, y, a) {
3030
- return clamp((a - x) / (y - x));
3031
- }
3032
- function clamp(a, min = 0, max = 1) {
3033
- return Math.min(max, Math.max(min, a));
3034
- }
3035
- function range(x1, y1, x2, y2, a) {
3036
- return lerp(x2, y2, invlerp(x1, y1, a));
3037
- }
3038
- function round(value) {
3039
- return Math.round(value);
3040
- }
3041
- function hexToRgb(hex) {
3042
- if (hex.length === 4) {
3043
- const hexR = hex.slice(1, 2), hexG = hex.slice(2, 3), hexB = hex.slice(3, 4);
3044
- return {
3045
- r: parseInt(hexR + hexR, 16),
3046
- g: parseInt(hexG + hexG, 16),
3047
- b: parseInt(hexB + hexB, 16)
3048
- };
3049
- }
3050
- return {
3051
- r: parseInt(hex.slice(1, 3), 16),
3052
- g: parseInt(hex.slice(3, 5), 16),
3053
- b: parseInt(hex.slice(5, 7), 16)
3054
- };
3055
- }
3056
- function rgbaToRGBA(rgba2) {
3057
- const values = rgba2.replace(/rgba\(|\)/g, "").split(",");
3058
- return {
3059
- r: parseInt(values[0]),
3060
- g: parseInt(values[1]),
3061
- b: parseInt(values[2]),
3062
- a: parseFloat(values[3])
3063
- };
3064
- }
3065
- function rgbToHex(color2) {
3066
- const r = round(clamp(Math.round(color2.r), 0, 255)), g = round(clamp(Math.round(color2.g), 0, 255)), b = round(clamp(Math.round(color2.b), 0, 255));
3067
- return "a" in color2 ? `rgba(${r},${g},${b},${color2.a})` : "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
3068
- }
3069
- function rgbToHsl({
3070
- r,
3071
- g,
3072
- b
3073
- }) {
3074
- r /= 255, g /= 255, b /= 255;
3075
- const cmin = Math.min(r, g, b), cmax = Math.max(r, g, b), delta = cmax - cmin;
3076
- let h = 0, s = 0, l = 0;
3077
- return delta == 0 ? h = 0 : cmax == r ? h = (g - b) / delta % 6 : cmax == g ? h = (b - r) / delta + 2 : h = (r - g) / delta + 4, h = Math.round(h * 60), h < 0 && (h += 360), l = (cmax + cmin) / 2, s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1)), s = +(s * 100).toFixed(1), l = +(l * 100).toFixed(1), {
3078
- h,
3079
- s,
3080
- l
3081
- };
3082
- }
3083
- function hslToRgb(hsl) {
3084
- const s = hsl.s / 100, l = hsl.l / 100, c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(hsl.h / 60 % 2 - 1)), m = l - c / 2;
3085
- let r = 0, g = 0, b = 0;
3086
- return 0 <= hsl.h && hsl.h < 60 ? (r = c, g = x, b = 0) : 60 <= hsl.h && hsl.h < 120 ? (r = x, g = c, b = 0) : 120 <= hsl.h && hsl.h < 180 ? (r = 0, g = c, b = x) : 180 <= hsl.h && hsl.h < 240 ? (r = 0, g = x, b = c) : 240 <= hsl.h && hsl.h < 300 ? (r = x, g = 0, b = c) : 300 <= hsl.h && hsl.h < 360 && (r = c, g = 0, b = x), {
3087
- r: Math.round((r + m) * 255),
3088
- g: Math.round((g + m) * 255),
3089
- b: Math.round((b + m) * 255)
3090
- };
3091
- }
3092
- const HEX_CHARS = "0123456789ABCDEFabcdef", HSL_RE = /hsl\(\s*(\d+)\s*,\s*((\d+(?:\.\d+)?)%)\s*,\s*((\d+(?:\.\d+)?)%)\s*\)/i;
3093
- function isHexChars(str) {
3094
- for (const c of str)
3095
- if (HEX_CHARS.indexOf(c) === -1)
3096
- return !1;
3097
- return !0;
3098
- }
3099
- function isHex(str) {
3100
- return str[0] !== "#" || !(str.length === 4 || str.length === 7) ? !1 : isHexChars(str.slice(1));
3101
- }
3102
- function parseHsl(str) {
3103
- const res = HSL_RE.exec(str);
3104
- if (!res)
3105
- throw new Error(`parseHsl: string is not a HSL color: "${str}"`);
3106
- return {
3107
- h: parseInt(res[1]),
3108
- s: parseFloat(res[3]),
3109
- l: parseFloat(res[5])
3110
- };
3111
- }
3112
- function parseColor(color2) {
3113
- if (!color2) return {
3114
- r: 0,
3115
- g: 0,
3116
- b: 0
3117
- };
3118
- if (typeof color2 != "string")
3119
- throw new Error("parseColor: expected a string");
3120
- if (isHex(color2))
3121
- return hexToRgb(color2);
3122
- if (color2.startsWith("hsl("))
3123
- return hslToRgb(parseHsl(color2));
3124
- if (color2.startsWith("rgba("))
3125
- return rgbaToRGBA(color2);
3126
- throw new Error(`parseColor: unexpected color format: "${color2}"`);
3127
- }
3128
- function getContrastRatio(bg, fg) {
3129
- const rgb1 = parseColor(bg), rgb2 = parseColor(fg), c1 = rgb_lrgb(rgb1), c2 = rgb_lrgb(rgb2), l1 = lrgb_luminance(c1), l2 = lrgb_luminance(c2);
3130
- return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
3131
- }
3132
- function rgb_lrgb({
3133
- r,
3134
- g,
3135
- b
3136
- }) {
3137
- return [rgb_lrgb1(r / 255), rgb_lrgb1(g / 255), rgb_lrgb1(b / 255)];
3138
- }
3139
- function rgb_lrgb1(v) {
3140
- return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
3141
- }
3142
- function lrgb_luminance([r, g, b]) {
3143
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
3144
- }
3145
- function rgba(color2, a) {
3146
- const rgb = parseColor(color2);
3147
- return `rgba(${rgb.r},${rgb.g},${rgb.b},${a})`;
3148
- }
3149
- const RGB_RANGE = [0, 255];
3150
- function mixThemeColor(value, options) {
3151
- const {
3152
- blendMode
3153
- } = options, color2 = parseColor(value), black2 = parseColor(options.black), white2 = parseColor(options.white), bg = options.bg ? parseColor(options.bg) : blendMode === "multiply" ? white2 : black2, paletteRange = {
3154
- r: [black2.r, white2.r],
3155
- g: [black2.g, white2.g],
3156
- b: [black2.b, white2.b]
3157
- }, convertedBgColor = {
3158
- r: clamp(range(...paletteRange.r, ...RGB_RANGE, bg.r), ...RGB_RANGE),
3159
- g: clamp(range(...paletteRange.g, ...RGB_RANGE, bg.g), ...RGB_RANGE),
3160
- b: clamp(range(...paletteRange.b, ...RGB_RANGE, bg.b), ...RGB_RANGE)
3161
- }, convertedColor = {
3162
- r: clamp(range(...paletteRange.r, ...RGB_RANGE, color2.r), ...RGB_RANGE),
3163
- g: clamp(range(...paletteRange.g, ...RGB_RANGE, color2.g), ...RGB_RANGE),
3164
- b: clamp(range(...paletteRange.b, ...RGB_RANGE, color2.b), ...RGB_RANGE)
3165
- }, resultColor = blendMode === "multiply" ? multiply(convertedBgColor, convertedColor) : screen(convertedBgColor, convertedColor), v = {
3166
- r: clamp(range(...RGB_RANGE, ...paletteRange.r, resultColor.r), ...paletteRange.r),
3167
- g: clamp(range(...RGB_RANGE, ...paletteRange.g, resultColor.g), ...paletteRange.g),
3168
- b: clamp(range(...RGB_RANGE, ...paletteRange.b, resultColor.b), ...paletteRange.b)
3169
- };
3170
- return rgbToHex(v);
3171
- }
3172
- function renderColorValue(str, options) {
3173
- const {
3174
- bg,
3175
- blendMode,
3176
- colorPalette
3177
- } = options;
3178
- if (bg === "white")
3179
- throw new Error("Cannot blend with white background");
3180
- const node = parseTokenValue(str);
3181
- if (!node || node.type !== "color")
3182
- throw new Error(`Invalid color token value: ${str}`);
3183
- let hex = "";
3184
- if (node.key === "black" && (hex = renderColorHex(colorPalette.black)), node.key === "white" && (hex = renderColorHex(colorPalette.white)), node.hue && node.tint && (hex = renderColorHex(colorPalette[node.hue][node.tint])), !hex)
3185
- throw new Error(`Invalid color token value: ${str}`);
3186
- const hexBeforeMix = hex, mixOptions = {
3187
- blendMode,
3188
- bg,
3189
- black: renderColorHex(colorPalette.black),
3190
- // opacity: node.opacity,
3191
- white: renderColorHex(colorPalette.white)
3192
- };
3193
- try {
3194
- if (hex = mixThemeColor(hex, mixOptions), bg && node.mix !== void 0) {
3195
- const from = hexToRgb(bg), to = hexToRgb(hex);
3196
- hex = rgbToHex(mix(from, to, node.mix));
3197
- }
3198
- } catch (err) {
3199
- throw console.warn("could not blend", hex, mixOptions), err;
3200
- }
3201
- return hex === "#aN" && (console.warn(`invalid color token value: ${str}`), hex = hexBeforeMix), node.opacity !== void 0 && (hex = rgba(hex, node.opacity)), hex;
3202
- }
3203
- function renderColorHex(color2) {
3204
- return typeof color2 == "string" ? color2 : color2.hex;
3205
- }
3206
- function renderThemeColorSchemes(value, config) {
3207
- const colorPalette = config?.palette ?? defaultColorPalette;
3208
- return {
3209
- light: renderThemeColorScheme(colorPalette, value.light),
3210
- dark: renderThemeColorScheme(colorPalette, value.dark)
3211
- };
3212
- }
3213
- function renderThemeColorScheme(colorPalette, value) {
3214
- const toneEntries = Object.entries(value), [, transparentTone] = toneEntries.find(([k]) => k === "transparent"), [, defaultTone] = toneEntries.find(([k]) => k === "default"), renderedTransparentTone = renderThemeColor(transparentTone, {
3215
- colorPalette
3216
- }), renderedDefaultTone = renderThemeColor(defaultTone, {
3217
- colorPalette
3218
- }), bg = renderedDefaultTone.bg;
3219
- if (bg === "white")
3220
- throw new Error("Cannot blend with white background");
3221
- return Object.fromEntries([["transparent", renderedTransparentTone], ["default", renderedDefaultTone], ...toneEntries.filter(([k]) => k !== "default" && k !== "transparent").map(([k, v]) => [k, renderThemeColor(v, {
3222
- bg,
3223
- colorPalette
3224
- })])]);
3225
- }
3226
- function renderThemeColor(value, options) {
3227
- const {
3228
- colorPalette,
3229
- bg
3230
- } = options, blendMode = value._blend || "multiply", baseBg = renderColorValue(value.bg, {
3231
- colorPalette,
3232
- bg,
3233
- blendMode
3234
- }), colorOptions = {
3235
- colorPalette,
3236
- bg: baseBg,
3237
- blendMode
3238
- }, button = renderThemeColorButton(value.button, {
3239
- baseBg,
3240
- blendMode,
3241
- colorPalette
3242
- }), selectable = renderThemeColorSelectable(value.selectable, {
3243
- colorPalette,
3244
- baseBg,
3245
- blendMode
3246
- }), shadow = {
3247
- outline: renderColorValue(value.shadow.outline, colorOptions),
3248
- umbra: renderColorValue(value.shadow.umbra, {
3249
- ...colorOptions,
3250
- bg: void 0,
3251
- colorPalette: {
3252
- ...colorPalette,
3253
- black: "#000000"
3254
- }
3255
- }),
3256
- penumbra: renderColorValue(value.shadow.penumbra, {
3257
- ...colorOptions,
3258
- bg: void 0,
3259
- colorPalette: {
3260
- ...colorPalette,
3261
- black: "#000000"
3262
- }
3263
- }),
3264
- ambient: renderColorValue(value.shadow.ambient, {
3265
- ...colorOptions,
3266
- bg: void 0,
3267
- colorPalette: {
3268
- ...colorPalette,
3269
- black: "#000000"
3270
- }
3271
- })
3272
- };
3273
- return {
3274
- _blend: blendMode,
3275
- _dark: value._dark,
3276
- accent: {
3277
- fg: renderColorValue(value.accent.fg, colorOptions)
3278
- },
3279
- avatar: renderThemeColorAvatar(value.avatar, {
3280
- baseBg,
3281
- colorPalette,
3282
- blendMode
3283
- }),
3284
- backdrop: renderColorValue(value.backdrop, colorOptions),
3285
- badge: renderThemeColorBadge(value.badge, {
3286
- baseBg,
3287
- colorPalette,
3288
- blendMode
3289
- }),
3290
- bg: baseBg,
3291
- border: renderColorValue(value.border, colorOptions),
3292
- button,
3293
- code: {
3294
- bg: renderColorValue(value.code.bg, colorOptions),
3295
- fg: renderColorValue(value.code.fg, colorOptions)
3296
- },
3297
- fg: renderColorValue(value.fg, colorOptions),
3298
- focusRing: renderColorValue(value.focusRing, colorOptions),
3299
- icon: renderColorValue(value.icon, colorOptions),
3300
- input: renderThemeColorInput(value.input, {
3301
- baseBg,
3302
- colorPalette,
3303
- blendMode
3304
- }),
3305
- kbd: renderThemeColorKBD(value.kbd, {
3306
- baseBg,
3307
- colorPalette,
3308
- blendMode
3309
- }),
3310
- link: {
3311
- fg: renderColorValue(value.link.fg, colorOptions)
3312
- },
3313
- muted: {
3314
- bg: renderColorValue(value.muted.bg, colorOptions),
3315
- fg: renderColorValue(value.muted.fg, colorOptions)
3316
- },
3317
- shadow,
3318
- skeleton: {
3319
- from: renderColorValue(value.skeleton.from, colorOptions),
3320
- to: renderColorValue(value.skeleton.to, colorOptions)
3321
- },
3322
- syntax: renderSyntaxColorTheme(value.syntax, {
3323
- baseBg,
3324
- colorPalette,
3325
- blendMode
3326
- }),
3327
- selectable
3328
- };
3329
- }
3330
- function renderThemeColorKBD(value, options) {
3331
- const {
3332
- baseBg,
3333
- blendMode,
3334
- colorPalette
3335
- } = options, rootOptions = {
3336
- bg: baseBg,
3337
- blendMode,
3338
- colorPalette
3339
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3340
- bg,
3341
- blendMode,
3342
- colorPalette
3343
- };
3344
- return {
3345
- bg,
3346
- fg: renderColorValue(value.fg, colorOptions),
3347
- border: renderColorValue(value.border, colorOptions)
3348
- };
3349
- }
3350
- function renderThemeColorAvatar(value, options) {
3351
- const colorAvatar = {};
3352
- for (const hue of COLOR_HUES)
3353
- colorAvatar[hue] = renderThemeColorAvatarColor(value[hue], options);
3354
- return colorAvatar;
3355
- }
3356
- function renderThemeColorAvatarColor(value, options) {
3357
- const {
3358
- baseBg,
3359
- blendMode: rootBlendMode,
3360
- colorPalette
3361
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3362
- bg: baseBg,
3363
- blendMode: rootBlendMode,
3364
- colorPalette
3365
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3366
- bg,
3367
- blendMode,
3368
- colorPalette
3369
- };
3370
- return {
3371
- _blend: blendMode,
3372
- bg,
3373
- fg: renderColorValue(value.fg, colorOptions)
3374
- };
3375
- }
3376
- function renderThemeColorBadge(value, options) {
3377
- const colorBadge = {};
3378
- for (const tone of THEME_COLOR_STATE_TONES)
3379
- colorBadge[tone] = renderThemeColorBadgeColor(value[tone], options);
3380
- return colorBadge;
3381
- }
3382
- function renderThemeColorBadgeColor(value, options) {
3383
- const {
3384
- baseBg,
3385
- blendMode: rootBlendMode,
3386
- colorPalette
3387
- } = options, blendMode = rootBlendMode, rootOptions = {
3388
- bg: baseBg,
3389
- blendMode: rootBlendMode,
3390
- colorPalette
3391
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3392
- bg,
3393
- blendMode,
3394
- colorPalette
3395
- };
3396
- return {
3397
- bg,
3398
- dot: renderColorValue(value.dot, colorOptions),
3399
- fg: renderColorValue(value.fg, colorOptions),
3400
- icon: renderColorValue(value.icon, colorOptions)
3401
- };
3402
- }
3403
- function renderThemeColorButton(value, options) {
3404
- return {
3405
- default: renderThemeColorButtonTones(value.default, options),
3406
- ghost: renderThemeColorButtonTones(value.ghost, options),
3407
- bleed: renderThemeColorButtonTones(value.bleed, options)
3408
- };
3409
- }
3410
- function renderThemeColorButtonTones(value, options) {
3411
- const colorButtonMode = {};
3412
- for (const tone of THEME_COLOR_STATE_TONES)
3413
- colorButtonMode[tone] = renderThemeColorButtonStates(value[tone], options);
3414
- return colorButtonMode;
3415
- }
3416
- function renderThemeColorButtonStates(value, options) {
3417
- return {
3418
- enabled: renderThemeColorState(value.enabled, options),
3419
- hovered: renderThemeColorState(value.hovered, options),
3420
- pressed: renderThemeColorState(value.pressed, options),
3421
- selected: renderThemeColorState(value.selected, options),
3422
- disabled: renderThemeColorState(value.disabled, options)
3423
- };
3424
- }
3425
- function renderThemeColorState(value, options) {
3426
- const {
3427
- baseBg,
3428
- blendMode: rootBlendMode,
3429
- colorPalette
3430
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3431
- bg: baseBg,
3432
- blendMode: rootBlendMode,
3433
- colorPalette
3434
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3435
- bg,
3436
- blendMode,
3437
- colorPalette
3438
- };
3439
- return {
3440
- _blend: blendMode,
3441
- accent: {
3442
- fg: renderColorValue(value.accent.fg, colorOptions)
3443
- },
3444
- avatar: renderThemeColorAvatar(value.avatar, {
3445
- baseBg: bg,
3446
- colorPalette,
3447
- blendMode
3448
- }),
3449
- badge: renderThemeColorBadge(value.badge, {
3450
- baseBg: bg,
3451
- colorPalette,
3452
- blendMode
3453
- }),
3454
- bg,
3455
- border: renderColorValue(value.border, colorOptions),
3456
- code: {
3457
- bg: renderColorValue(value.code.bg, colorOptions),
3458
- fg: renderColorValue(value.code.fg, colorOptions)
3459
- },
3460
- fg: renderColorValue(value.fg, colorOptions),
3461
- icon: renderColorValue(value.icon, colorOptions),
3462
- link: {
3463
- fg: renderColorValue(value.link.fg, colorOptions)
3464
- },
3465
- muted: {
3466
- bg: renderColorValue(value.muted.bg, colorOptions),
3467
- fg: renderColorValue(value.muted.fg, colorOptions)
3468
- },
3469
- kbd: {
3470
- bg: renderColorValue(value.kbd.bg, colorOptions),
3471
- fg: renderColorValue(value.kbd.fg, colorOptions),
3472
- border: renderColorValue(value.kbd.border, colorOptions)
3473
- },
3474
- skeleton: {
3475
- from: renderColorValue(value.skeleton?.from, colorOptions),
3476
- to: renderColorValue(value.skeleton?.to, colorOptions)
3477
- }
3478
- };
3479
- }
3480
- function renderThemeColorInput(value, options) {
3481
- return {
3482
- default: renderInputStatesColorTheme(value.default, options),
3483
- invalid: renderInputStatesColorTheme(value.invalid, options)
3484
- };
3485
- }
3486
- function renderInputStatesColorTheme(value, options) {
3487
- return {
3488
- enabled: renderInputStateColorTheme(value.enabled, options),
3489
- hovered: renderInputStateColorTheme(value.hovered, options),
3490
- readOnly: renderInputStateColorTheme(value.readOnly, options),
3491
- disabled: renderInputStateColorTheme(value.disabled, options)
3492
- };
3493
- }
3494
- function renderInputStateColorTheme(value, options) {
3495
- const {
3496
- baseBg,
3497
- blendMode: rootBlendMode,
3498
- colorPalette
3499
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3500
- colorPalette,
3501
- bg: baseBg,
3502
- blendMode: rootBlendMode
3503
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3504
- colorPalette,
3505
- bg,
3506
- blendMode
3507
- };
3508
- return {
3509
- _blend: blendMode,
3510
- bg,
3511
- border: renderColorValue(value.border, colorOptions),
3512
- fg: renderColorValue(value.fg, colorOptions),
3513
- muted: {
3514
- bg: renderColorValue(value.muted.bg, colorOptions)
3515
- },
3516
- placeholder: renderColorValue(value.placeholder, colorOptions)
3517
- };
3518
- }
3519
- function renderThemeColorSelectable(value, options) {
3520
- const colorSelectable = {};
3521
- for (const tone of THEME_COLOR_STATE_TONES)
3522
- colorSelectable[tone] = renderThemeColorSelectableStates(value[tone], options);
3523
- return colorSelectable;
3524
- }
3525
- function renderThemeColorSelectableStates(value, options) {
3526
- return {
3527
- enabled: renderThemeColorState(value.enabled, options),
3528
- hovered: renderThemeColorState(value.hovered, options),
3529
- pressed: renderThemeColorState(value.pressed, options),
3530
- selected: renderThemeColorState(value.selected, options),
3531
- disabled: renderThemeColorState(value.disabled, options)
3532
- };
3533
- }
3534
- function renderSyntaxColorTheme(value, options) {
3535
- const {
3536
- colorPalette,
3537
- baseBg,
3538
- blendMode
3539
- } = options, colorOptions = {
3540
- colorPalette,
3541
- bg: baseBg,
3542
- blendMode
3543
- };
3544
- return {
3545
- atrule: renderColorValue(value.atrule, colorOptions),
3546
- attrName: renderColorValue(value.attrName, colorOptions),
3547
- attrValue: renderColorValue(value.attrValue, colorOptions),
3548
- attribute: renderColorValue(value.attribute, colorOptions),
3549
- boolean: renderColorValue(value.boolean, colorOptions),
3550
- builtin: renderColorValue(value.builtin, colorOptions),
3551
- cdata: renderColorValue(value.cdata, colorOptions),
3552
- char: renderColorValue(value.char, colorOptions),
3553
- class: renderColorValue(value.class, colorOptions),
3554
- className: renderColorValue(value.className, colorOptions),
3555
- comment: renderColorValue(value.comment, colorOptions),
3556
- constant: renderColorValue(value.constant, colorOptions),
3557
- deleted: renderColorValue(value.deleted, colorOptions),
3558
- doctype: renderColorValue(value.doctype, colorOptions),
3559
- entity: renderColorValue(value.entity, colorOptions),
3560
- function: renderColorValue(value.function, colorOptions),
3561
- hexcode: renderColorValue(value.hexcode, colorOptions),
3562
- id: renderColorValue(value.id, colorOptions),
3563
- important: renderColorValue(value.important, colorOptions),
3564
- inserted: renderColorValue(value.inserted, colorOptions),
3565
- keyword: renderColorValue(value.keyword, colorOptions),
3566
- number: renderColorValue(value.number, colorOptions),
3567
- operator: renderColorValue(value.operator, colorOptions),
3568
- prolog: renderColorValue(value.prolog, colorOptions),
3569
- property: renderColorValue(value.property, colorOptions),
3570
- pseudoClass: renderColorValue(value.pseudoClass, colorOptions),
3571
- pseudoElement: renderColorValue(value.pseudoElement, colorOptions),
3572
- punctuation: renderColorValue(value.punctuation, colorOptions),
3573
- regex: renderColorValue(value.regex, colorOptions),
3574
- selector: renderColorValue(value.selector, colorOptions),
3575
- string: renderColorValue(value.string, colorOptions),
3576
- symbol: renderColorValue(value.symbol, colorOptions),
3577
- tag: renderColorValue(value.tag, colorOptions),
3578
- unit: renderColorValue(value.unit, colorOptions),
3579
- url: renderColorValue(value.url, colorOptions),
3580
- variable: renderColorValue(value.variable, colorOptions)
3581
- };
3582
- }
3583
- function buildTheme(config) {
3584
- const colorTheme = buildColorTheme(config), v2 = {
3585
- _version: 2,
3586
- avatar: config?.avatar ?? defaultThemeConfig.avatar,
3587
- button: config?.button ?? defaultThemeConfig.button,
3588
- card: config?.card ?? defaultThemeConfig.card,
3589
- // How colors are generated:
3590
- // 1. Merge custom tokens with default tokens
3591
- // 2. Generate tree of color keys (gray/500, black, white, etc.)
3592
- // 3. Apply mixing and render to hex values
3593
- // render(build(mergeWithDefaults()))
3594
- color: renderThemeColorSchemes(colorTheme, config),
3595
- container: config?.container ?? defaultThemeConfig.container,
3596
- font: config?.font ?? defaultThemeFonts,
3597
- input: config?.input ?? defaultThemeConfig.input,
3598
- layer: config?.layer ?? defaultThemeConfig.layer,
3599
- media: config?.media ?? defaultThemeConfig.media,
3600
- radius: config?.radius ?? defaultThemeConfig.radius,
3601
- shadow: config?.shadow ?? defaultThemeConfig.shadow,
3602
- space: config?.space ?? defaultThemeConfig.space,
3603
- style: config?.style ?? defaultThemeConfig.style
3604
- };
3605
- return v2_v0(v2);
3606
- }
3607
- const cache = /* @__PURE__ */ new Map();
3608
- function getScopedTheme(themeProp, scheme, tone) {
3609
- const cachedTheme = _getCachedTheme(themeProp, scheme, tone);
3610
- if (cachedTheme) return cachedTheme;
3611
- const v0 = is_v2(themeProp) ? v2_v0(themeProp) : themeProp, v2 = is_v2(themeProp) ? themeProp : v0_v2(themeProp), colorScheme_v0 = v0.color[scheme] || v0.color.light, color_v0 = colorScheme_v0[tone] || colorScheme_v0.default, layer_v0 = v0.layer || defaultThemeConfig.layer, colorScheme_v2 = v2.color[scheme] || v2.color.light, color_v2 = colorScheme_v2[tone] || colorScheme_v2.default, layer_v2 = v2.layer || defaultThemeConfig.layer, theme = {
3612
- sanity: {
3613
- ...v0,
3614
- color: color_v0,
3615
- layer: layer_v0,
3616
- v2: {
3617
- ...v2,
3618
- _resolved: !0,
3619
- color: color_v2,
3620
- layer: layer_v2
3621
- }
3622
- }
3623
- };
3624
- return _setCachedTheme(themeProp, scheme, tone, theme), theme;
3625
- }
3626
- function _getCachedTheme(rootTheme, scheme, tone) {
3627
- const schemeCache = cache.get(scheme);
3628
- if (!schemeCache) return;
3629
- const toneCache = schemeCache.get(tone);
3630
- if (toneCache)
3631
- return toneCache.get(rootTheme);
3632
- }
3633
- function _setCachedTheme(rootTheme, scheme, tone, theme) {
3634
- cache.has(scheme) || cache.set(scheme, /* @__PURE__ */ new Map());
3635
- const schemeCache = cache.get(scheme);
3636
- schemeCache.has(tone) || schemeCache.set(tone, /* @__PURE__ */ new WeakMap()), schemeCache.get(tone).set(rootTheme, theme);
3637
- }
3638
- export {
3639
- COLOR_CONFIG_AVATAR_COLORS,
3640
- COLOR_CONFIG_BLEND_KEYS,
3641
- COLOR_CONFIG_CARD_KEYS,
3642
- COLOR_CONFIG_CARD_TONES,
3643
- COLOR_CONFIG_INPUT_MODES,
3644
- COLOR_CONFIG_INPUT_STATES,
3645
- COLOR_CONFIG_STATES,
3646
- COLOR_CONFIG_STATE_KEYS,
3647
- COLOR_CONFIG_STATE_TONES,
3648
- THEME_COLOR_AVATAR_COLORS,
3649
- THEME_COLOR_BLEND_MODES,
3650
- THEME_COLOR_BUTTON_MODES,
3651
- THEME_COLOR_CARD_TONES,
3652
- THEME_COLOR_INPUT_MODES,
3653
- THEME_COLOR_INPUT_STATES,
3654
- THEME_COLOR_SCHEMES,
3655
- THEME_COLOR_STATES,
3656
- THEME_COLOR_STATE_TONES,
3657
- buildTheme,
3658
- createColorTheme,
3659
- getContrastRatio,
3660
- getScopedTheme,
3661
- getTheme_v2,
3662
- hexToRgb,
3663
- hslToRgb,
3664
- isColorBlendModeValue,
3665
- isColorButtonMode,
3666
- isColorConfigBaseKey,
3667
- isColorConfigBaseTone,
3668
- isColorConfigBlendKey,
3669
- isColorConfigStateKey,
3670
- isColorConfigStateTone,
3671
- isColorHueKey,
3672
- isColorOpacityValue,
3673
- isColorTintKey,
3674
- isColorTokenValue,
3675
- isColorValue,
3676
- is_v0,
3677
- is_v2,
3678
- mix,
3679
- multiply,
3680
- parseColor,
3681
- parseTokenKey,
3682
- parseTokenValue,
3683
- rgbToHex,
3684
- rgbToHsl,
3685
- rgba,
3686
- rgbaToRGBA,
3687
- screen,
3688
- v0_v2,
3689
- v2_v0
3690
- };
3691
- //# sourceMappingURL=theme.esm.js.map