@sanity/ui 2.15.2 → 2.15.4

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.
package/dist/theme.esm.js DELETED
@@ -1,3723 +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
- fonts: font,
1333
- input,
1334
- layer,
1335
- media,
1336
- radius,
1337
- shadows: shadow,
1338
- space,
1339
- styles: style
1340
- } = v0, v2 = {
1341
- _version: 2,
1342
- avatar: {
1343
- ...defaultThemeConfig.avatar,
1344
- ...avatar
1345
- },
1346
- button: {
1347
- ...defaultThemeConfig.button,
1348
- ...button
1349
- },
1350
- card: defaultThemeConfig.card,
1351
- color: {
1352
- light: {
1353
- transparent: themeColor_v0_v2(color2.light.transparent),
1354
- default: themeColor_v0_v2(color2.light.default),
1355
- neutral: themeColor_v0_v2(color2.light.transparent),
1356
- primary: themeColor_v0_v2(color2.light.primary),
1357
- suggest: themeColor_v0_v2(color2.light.primary),
1358
- positive: themeColor_v0_v2(color2.light.positive),
1359
- caution: themeColor_v0_v2(color2.light.caution),
1360
- critical: themeColor_v0_v2(color2.light.critical)
1361
- },
1362
- dark: {
1363
- transparent: themeColor_v0_v2(color2.dark.transparent),
1364
- default: themeColor_v0_v2(color2.dark.default),
1365
- neutral: themeColor_v0_v2(color2.dark.transparent),
1366
- primary: themeColor_v0_v2(color2.dark.primary),
1367
- suggest: themeColor_v0_v2(color2.dark.primary),
1368
- positive: themeColor_v0_v2(color2.dark.positive),
1369
- caution: themeColor_v0_v2(color2.dark.caution),
1370
- critical: themeColor_v0_v2(color2.dark.critical)
1371
- }
1372
- },
1373
- container,
1374
- font,
1375
- input: {
1376
- ...defaultThemeConfig.input,
1377
- ...input,
1378
- checkbox: {
1379
- ...defaultThemeConfig.input.checkbox,
1380
- ...input.checkbox
1381
- },
1382
- radio: {
1383
- ...defaultThemeConfig.input.radio,
1384
- ...input.radio
1385
- },
1386
- switch: {
1387
- ...defaultThemeConfig.input.switch,
1388
- ...input.switch
1389
- }
1390
- },
1391
- layer: layer ?? defaultThemeConfig.layer,
1392
- media,
1393
- radius,
1394
- shadow,
1395
- space,
1396
- style
1397
- };
1398
- return cache$2.set(v0, v2), v2;
1399
- }
1400
- const cache$1 = /* @__PURE__ */ new WeakMap();
1401
- function v2_v0(v2) {
1402
- const cachedTheme = cache$1.get(v2);
1403
- if (cachedTheme) return cachedTheme;
1404
- const {
1405
- avatar,
1406
- button,
1407
- color: color2,
1408
- container,
1409
- font: fonts,
1410
- input,
1411
- media,
1412
- radius,
1413
- shadow: shadows,
1414
- space,
1415
- style: styles
1416
- } = v2;
1417
- return {
1418
- _version: 0,
1419
- avatar,
1420
- button,
1421
- container,
1422
- color: {
1423
- light: {
1424
- transparent: themeColor_v2_v0(color2.light.transparent),
1425
- default: themeColor_v2_v0(color2.light.default),
1426
- primary: themeColor_v2_v0(color2.light.primary),
1427
- positive: themeColor_v2_v0(color2.light.positive),
1428
- caution: themeColor_v2_v0(color2.light.caution),
1429
- critical: themeColor_v2_v0(color2.light.critical)
1430
- },
1431
- dark: {
1432
- transparent: themeColor_v2_v0(color2.dark.transparent),
1433
- default: themeColor_v2_v0(color2.dark.default),
1434
- primary: themeColor_v2_v0(color2.dark.primary),
1435
- positive: themeColor_v2_v0(color2.dark.positive),
1436
- caution: themeColor_v2_v0(color2.dark.caution),
1437
- critical: themeColor_v2_v0(color2.dark.critical)
1438
- }
1439
- },
1440
- focusRing: input.text.focusRing,
1441
- fonts,
1442
- input,
1443
- media,
1444
- radius,
1445
- shadows,
1446
- space,
1447
- styles,
1448
- v2
1449
- };
1450
- }
1451
- function themeColor_v2_v0(color_v2) {
1452
- return {
1453
- base: {
1454
- bg: color_v2.bg,
1455
- fg: color_v2.fg,
1456
- border: color_v2.border,
1457
- focusRing: color_v2.focusRing,
1458
- shadow: color_v2.shadow
1459
- },
1460
- button: color_v2.button,
1461
- card: color_v2.selectable.default,
1462
- dark: color_v2._dark,
1463
- input: {
1464
- default: inputStatesThemeColor_v2_v0(color_v2.input.default),
1465
- invalid: inputStatesThemeColor_v2_v0(color_v2.input.invalid)
1466
- },
1467
- muted: {
1468
- ...color_v2.button.ghost,
1469
- transparent: color_v2.button.ghost.default
1470
- },
1471
- solid: {
1472
- ...color_v2.button.default,
1473
- transparent: color_v2.button.default.default
1474
- },
1475
- selectable: color_v2.selectable,
1476
- spot: {
1477
- gray: color_v2.avatar.gray.bg,
1478
- blue: color_v2.avatar.blue.bg,
1479
- purple: color_v2.avatar.purple.bg,
1480
- magenta: color_v2.avatar.magenta.bg,
1481
- red: color_v2.avatar.red.bg,
1482
- orange: color_v2.avatar.orange.bg,
1483
- yellow: color_v2.avatar.yellow.bg,
1484
- green: color_v2.avatar.green.bg,
1485
- cyan: color_v2.avatar.cyan.bg
1486
- },
1487
- syntax: color_v2.syntax
1488
- };
1489
- }
1490
- function inputStatesThemeColor_v2_v0(t) {
1491
- return {
1492
- enabled: inputStateThemeColor_v2_v0(t.enabled),
1493
- disabled: inputStateThemeColor_v2_v0(t.disabled),
1494
- readOnly: inputStateThemeColor_v2_v0(t.readOnly),
1495
- hovered: inputStateThemeColor_v2_v0(t.hovered)
1496
- };
1497
- }
1498
- function inputStateThemeColor_v2_v0(t) {
1499
- return {
1500
- bg: t.bg,
1501
- bg2: t.muted.bg,
1502
- border: t.border,
1503
- fg: t.fg,
1504
- placeholder: t.placeholder
1505
- };
1506
- }
1507
- const THEME_COLOR_SCHEMES = ["light", "dark"], THEME_COLOR_BLEND_MODES = ["multiply", "screen"], THEME_COLOR_CARD_TONES = [
1508
- "transparent",
1509
- "default",
1510
- "neutral",
1511
- "primary",
1512
- // deprecated
1513
- "suggest",
1514
- "positive",
1515
- "caution",
1516
- "critical"
1517
- ], THEME_COLOR_STATE_TONES = [
1518
- "default",
1519
- "neutral",
1520
- "primary",
1521
- // deprecated
1522
- "suggest",
1523
- "positive",
1524
- "caution",
1525
- "critical"
1526
- ], 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;
1527
- function isColorBlendModeValue(str) {
1528
- return THEME_COLOR_BLEND_MODES.includes(str);
1529
- }
1530
- function isColorHueKey(str) {
1531
- return COLOR_HUES.includes(str);
1532
- }
1533
- function isColorTintKey(str) {
1534
- return COLOR_TINTS.includes(str);
1535
- }
1536
- function isColorButtonMode(str) {
1537
- return THEME_COLOR_BUTTON_MODES.includes(str);
1538
- }
1539
- 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];
1540
- function parseTokenKey(str) {
1541
- const segments = str.split("/"), segment0 = segments.shift() || "";
1542
- if (isColorConfigBaseTone(segment0)) {
1543
- const key = segments.join("/");
1544
- if (isColorConfigBaseKey(key))
1545
- return {
1546
- type: "base",
1547
- tone: segment0,
1548
- key
1549
- };
1550
- if (isColorConfigBlendKey(key))
1551
- return {
1552
- type: "base",
1553
- tone: segment0,
1554
- key
1555
- };
1556
- }
1557
- if (segment0 === "button") {
1558
- const segment1 = segments.shift() || "";
1559
- if (isColorConfigStateTone(segment1)) {
1560
- const segment2 = segments.shift() || "";
1561
- if (isColorButtonMode(segment2)) {
1562
- const key = segments.join("/");
1563
- if (isColorConfigStateKey(key))
1564
- return {
1565
- type: "button",
1566
- tone: segment1,
1567
- mode: segment2,
1568
- key
1569
- };
1570
- if (isColorConfigBlendKey(key))
1571
- return {
1572
- type: "button",
1573
- tone: segment1,
1574
- mode: segment2,
1575
- key
1576
- };
1577
- }
1578
- }
1579
- }
1580
- }
1581
- function isColorMixPercentValue(str) {
1582
- return /^\d+%$/.test(str);
1583
- }
1584
- function parseTokenValue(str) {
1585
- const segments = str.split("/");
1586
- let nextSegment = segments.shift() || "";
1587
- const [segment0, segment0mix] = nextSegment.split(" ");
1588
- if (isColorTintKey(segment0)) {
1589
- const tint = segment0, segment1 = segments.shift() || "";
1590
- if (isColorMixPercentValue(segment0mix)) {
1591
- const mix2 = Number(segment0mix.slice(0, -1)) / 100;
1592
- return {
1593
- type: "color",
1594
- tint,
1595
- mix: mix2
1596
- };
1597
- }
1598
- if (isColorOpacityValue(segment1)) {
1599
- const opacity = Number(segment1);
1600
- return {
1601
- type: "color",
1602
- tint,
1603
- opacity
1604
- };
1605
- }
1606
- return {
1607
- type: "color",
1608
- tint
1609
- };
1610
- }
1611
- if (isColorValue(segment0)) {
1612
- const key = segment0, segment1 = segments.shift() || "";
1613
- if (isColorMixPercentValue(segment0mix)) {
1614
- const mix2 = Number(segment0mix.slice(0, -1)) / 100;
1615
- return {
1616
- type: "color",
1617
- key,
1618
- mix: mix2
1619
- };
1620
- }
1621
- if (isColorOpacityValue(segment1)) {
1622
- const opacity = Number(segment1);
1623
- return {
1624
- type: "color",
1625
- key,
1626
- opacity
1627
- };
1628
- }
1629
- return {
1630
- type: "color",
1631
- key
1632
- };
1633
- }
1634
- if (isColorHueKey(segment0)) {
1635
- const hue = segment0;
1636
- nextSegment = segments.shift() || "";
1637
- const [segment1, segment1mix] = nextSegment.split(" ");
1638
- if (isColorTintKey(segment1)) {
1639
- const tint = segment1, segment2 = segments.shift() || "";
1640
- if (isColorMixPercentValue(segment1mix)) {
1641
- const mix2 = Number(segment1mix.slice(0, -1)) / 100;
1642
- return {
1643
- type: "color",
1644
- hue,
1645
- tint,
1646
- mix: mix2
1647
- };
1648
- }
1649
- if (isColorOpacityValue(segment2)) {
1650
- const opacity = Number(segment2);
1651
- return {
1652
- type: "color",
1653
- hue,
1654
- tint,
1655
- opacity
1656
- };
1657
- }
1658
- return {
1659
- type: "color",
1660
- hue,
1661
- tint
1662
- };
1663
- }
1664
- return {
1665
- type: "hue",
1666
- value: hue
1667
- };
1668
- }
1669
- if (isColorBlendModeValue(segment0))
1670
- return {
1671
- type: "blendMode",
1672
- value: segment0
1673
- };
1674
- }
1675
- function isColorConfigBaseTone(str) {
1676
- return COLOR_CONFIG_CARD_TONES.includes(str);
1677
- }
1678
- function isColorConfigBaseKey(str) {
1679
- return COLOR_CONFIG_CARD_KEYS.includes(str);
1680
- }
1681
- function isColorConfigStateKey(str) {
1682
- return COLOR_CONFIG_STATE_KEYS.includes(str);
1683
- }
1684
- function isColorConfigStateTone(str) {
1685
- return COLOR_CONFIG_STATE_TONES.includes(str);
1686
- }
1687
- function isColorConfigBlendKey(str) {
1688
- return COLOR_CONFIG_BLEND_KEYS.includes(str);
1689
- }
1690
- function isColorTokenValue(str) {
1691
- return parseTokenValue(str)?.type === "color" || parseTokenValue(str)?.type === "hue";
1692
- }
1693
- function isColorValue(str) {
1694
- return str === "black" || str === "white";
1695
- }
1696
- function isColorOpacityValue(str) {
1697
- return str === "0" || /^0\.[0-9]+$/.test(str) || str === "1";
1698
- }
1699
- function compileColorTokenValue(node) {
1700
- let key = "";
1701
- 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);
1702
- }
1703
- const DEFAULT_COLOR_TOKEN_VALUE = ["500", "500"];
1704
- function resolveColorTokenValue(context, value = DEFAULT_COLOR_TOKEN_VALUE) {
1705
- const {
1706
- hue,
1707
- scheme
1708
- } = context, node = parseTokenValue(value[scheme === "light" ? 0 : 1]);
1709
- if (!node || node.type !== "color")
1710
- throw new Error(`Invalid color token: ${value[0]}`);
1711
- return compileColorTokenValue({
1712
- ...node,
1713
- hue: node.hue || hue
1714
- });
1715
- }
1716
- const defaultColorTokens = {
1717
- base: {
1718
- "*": {
1719
- _blend: ["multiply", "screen"],
1720
- accent: {
1721
- fg: ["purple/600", "purple/400"]
1722
- },
1723
- avatar: {
1724
- "*": {
1725
- _blend: ["screen", "multiply"],
1726
- bg: ["500", "400"],
1727
- fg: ["white", "black"]
1728
- }
1729
- },
1730
- backdrop: ["gray/200/0.5", "black/0.5"],
1731
- badge: {
1732
- "*": {
1733
- bg: ["100", "900"],
1734
- fg: ["600", "400"],
1735
- icon: ["500", "500"],
1736
- dot: ["500", "500"]
1737
- },
1738
- positive: {
1739
- bg: ["200 50%", "900"],
1740
- fg: ["600", "500"]
1741
- },
1742
- caution: {
1743
- bg: ["200 50%", "900"],
1744
- fg: ["600", "500"]
1745
- }
1746
- },
1747
- bg: ["50", "950"],
1748
- border: ["200", "800"],
1749
- code: {
1750
- bg: ["50", "950"],
1751
- fg: ["600", "400"]
1752
- },
1753
- fg: ["800", "200"],
1754
- focusRing: ["blue/500", "blue/500"],
1755
- icon: ["600", "400"],
1756
- kbd: {
1757
- bg: ["white", "black"],
1758
- fg: ["600", "400"],
1759
- border: ["200", "800"]
1760
- },
1761
- link: {
1762
- fg: ["blue/600", "blue/300"]
1763
- },
1764
- muted: {
1765
- bg: ["50", "950"],
1766
- fg: ["700 75%", "300 75%"]
1767
- },
1768
- shadow: {
1769
- outline: ["500/0.3", "500/0.4"],
1770
- umbra: ["gray/500/0.1", "black/0.2"],
1771
- penumbra: ["gray/500/0.07", "black/0.14"],
1772
- ambient: ["gray/500/0.06", "black/0.12"]
1773
- },
1774
- skeleton: {
1775
- from: ["100", "900"],
1776
- to: ["100 50%", "900 50%"]
1777
- }
1778
- },
1779
- transparent: {
1780
- bg: ["50", "black"]
1781
- },
1782
- default: {
1783
- bg: ["white", "950"],
1784
- fg: ["800", "200"],
1785
- muted: {
1786
- fg: ["600", "400"]
1787
- }
1788
- },
1789
- primary: {
1790
- _hue: "blue"
1791
- },
1792
- suggest: {
1793
- _hue: "purple"
1794
- },
1795
- positive: {
1796
- _hue: "green",
1797
- shadow: {
1798
- outline: ["500/0.4", "500/0.4"]
1799
- }
1800
- },
1801
- caution: {
1802
- _hue: "yellow",
1803
- shadow: {
1804
- outline: ["600/0.3", "500/0.4"]
1805
- }
1806
- },
1807
- critical: {
1808
- _hue: "red"
1809
- }
1810
- },
1811
- button: {
1812
- default: {
1813
- "*": {
1814
- "*": {
1815
- _blend: ["screen", "multiply"],
1816
- accent: {
1817
- fg: ["purple/300", "purple/700"]
1818
- },
1819
- avatar: {
1820
- "*": {
1821
- _blend: ["screen", "multiply"],
1822
- bg: ["500", "400"],
1823
- fg: ["white", "black"]
1824
- }
1825
- },
1826
- badge: {
1827
- "*": {
1828
- bg: ["900", "100"],
1829
- fg: ["400", "600"],
1830
- dot: ["500", "500"],
1831
- icon: ["500", "500"]
1832
- }
1833
- },
1834
- bg: ["500", "400"],
1835
- border: ["500/0", "400/0"],
1836
- code: {
1837
- bg: ["500 20%", "400 20%"],
1838
- fg: ["200", "600"]
1839
- },
1840
- fg: ["white", "black"],
1841
- icon: ["100 70%", "900 70%"],
1842
- kbd: {
1843
- bg: ["black", "white"],
1844
- fg: ["200", "600"],
1845
- border: ["800", "200"]
1846
- },
1847
- link: {
1848
- fg: ["blue/200", "blue/600"]
1849
- },
1850
- muted: {
1851
- bg: ["950", "50"],
1852
- fg: ["100 70%", "900 70%"]
1853
- },
1854
- skeleton: {
1855
- from: ["900", "100"],
1856
- to: ["900 50%", "100 50%"]
1857
- }
1858
- },
1859
- hovered: {
1860
- bg: ["600", "300"],
1861
- border: ["700/0", "300/0"]
1862
- },
1863
- pressed: {
1864
- bg: ["700", "300"]
1865
- },
1866
- selected: {
1867
- bg: ["700", "300"]
1868
- },
1869
- disabled: {
1870
- _hue: "gray",
1871
- accent: {
1872
- fg: ["100 70%", "900 70%"]
1873
- },
1874
- avatar: {
1875
- "*": {
1876
- _blend: ["screen", "multiply"],
1877
- bg: ["gray/500", "gray/400"],
1878
- fg: ["white", "black"]
1879
- }
1880
- },
1881
- badge: {
1882
- "*": {
1883
- bg: ["gray/700", "gray/300"],
1884
- fg: ["white", "black"],
1885
- dot: ["white", "black"],
1886
- icon: ["white", "black"]
1887
- }
1888
- },
1889
- bg: ["300", "600"],
1890
- code: {
1891
- bg: ["950", "50"],
1892
- fg: ["300", "600"]
1893
- },
1894
- fg: ["300", "600"],
1895
- muted: {
1896
- bg: ["950", "50"],
1897
- fg: ["300", "600"]
1898
- },
1899
- kbd: {
1900
- bg: ["black", "white"],
1901
- fg: ["white", "black"],
1902
- border: ["700", "300"]
1903
- },
1904
- link: {
1905
- fg: ["100 70%", "900 70%"]
1906
- }
1907
- }
1908
- },
1909
- default: {
1910
- "*": {
1911
- avatar: {
1912
- "*": {
1913
- _blend: ["screen", "multiply"],
1914
- bg: ["500", "400"],
1915
- fg: ["white", "black"]
1916
- }
1917
- },
1918
- bg: ["800", "200"],
1919
- muted: {
1920
- bg: ["950", "50"],
1921
- fg: ["400", "600"]
1922
- }
1923
- },
1924
- hovered: {
1925
- bg: ["900", "100"]
1926
- },
1927
- pressed: {
1928
- bg: ["black", "white"]
1929
- },
1930
- selected: {
1931
- bg: ["black", "white"]
1932
- }
1933
- }
1934
- },
1935
- ghost: {
1936
- "*": {
1937
- "*": {
1938
- _blend: ["multiply", "screen"],
1939
- accent: {
1940
- fg: ["purple/700 60%", "purple/300 70%"]
1941
- },
1942
- avatar: {
1943
- "*": {
1944
- _blend: ["screen", "multiply"],
1945
- bg: ["500", "400"],
1946
- fg: ["white", "black"]
1947
- }
1948
- },
1949
- badge: {
1950
- "*": {
1951
- bg: ["100", "900"],
1952
- fg: ["600", "400"],
1953
- dot: ["500", "500"],
1954
- icon: ["500", "500"]
1955
- }
1956
- },
1957
- bg: ["50", "950"],
1958
- border: ["100", "900"],
1959
- code: {
1960
- bg: ["500 10%", "400 10%"],
1961
- fg: ["700 60%", "400 60%"]
1962
- },
1963
- fg: ["600", "400"],
1964
- icon: ["700 60%", "300 60%"],
1965
- kbd: {
1966
- bg: ["white", "black"],
1967
- fg: ["600", "400"],
1968
- border: ["200", "800"]
1969
- },
1970
- link: {
1971
- fg: ["blue/700 60%", "blue/300 60%"]
1972
- },
1973
- muted: {
1974
- bg: ["100", "950"],
1975
- fg: ["700 60%", "300 60%"]
1976
- },
1977
- skeleton: {
1978
- from: ["100", "900"],
1979
- to: ["100 50%", "900 50%"]
1980
- }
1981
- },
1982
- hovered: {
1983
- bg: ["100", "900"],
1984
- fg: ["700", "300"]
1985
- },
1986
- pressed: {
1987
- bg: ["200", "800"],
1988
- fg: ["800", "200"]
1989
- },
1990
- selected: {
1991
- bg: ["200", "800"],
1992
- fg: ["800", "200"]
1993
- },
1994
- disabled: {
1995
- _hue: "gray",
1996
- accent: {
1997
- fg: ["200", "800"]
1998
- },
1999
- avatar: {
2000
- "*": {
2001
- _blend: ["screen", "multiply"],
2002
- bg: ["gray/100", "gray/900"],
2003
- fg: ["white", "black"]
2004
- }
2005
- },
2006
- badge: {
2007
- "*": {
2008
- _hue: "gray",
2009
- bg: ["50", "950"],
2010
- fg: ["gray/200", "gray/800"],
2011
- dot: ["gray/200", "gray/800"],
2012
- icon: ["gray/200", "gray/800"]
2013
- }
2014
- },
2015
- border: ["100", "900"],
2016
- code: {
2017
- bg: ["50", "950"],
2018
- fg: ["200", "800"]
2019
- },
2020
- fg: ["400", "600"],
2021
- icon: ["300", "700"],
2022
- muted: {
2023
- fg: ["300", "700"]
2024
- },
2025
- kbd: {
2026
- bg: ["white", "black"],
2027
- fg: ["200", "800"],
2028
- border: ["100", "900"]
2029
- },
2030
- link: {
2031
- fg: ["200", "800"]
2032
- }
2033
- }
2034
- },
2035
- positive: {
2036
- "*": {
2037
- border: ["600 20%", "800"]
2038
- }
2039
- },
2040
- caution: {
2041
- "*": {
2042
- border: ["600 20%", "800"]
2043
- }
2044
- }
2045
- },
2046
- bleed: {
2047
- "*": {
2048
- "*": {
2049
- _blend: ["multiply", "screen"],
2050
- accent: {
2051
- fg: ["purple/700 70%", "purple/300 70%"]
2052
- },
2053
- avatar: {
2054
- "*": {
2055
- _blend: ["screen", "multiply"],
2056
- bg: ["500", "400"],
2057
- fg: ["white", "black"]
2058
- }
2059
- },
2060
- badge: {
2061
- "*": {
2062
- bg: ["100", "900"],
2063
- fg: ["600", "400"],
2064
- dot: ["500", "500"],
2065
- icon: ["500", "500"]
2066
- }
2067
- },
2068
- bg: ["white", "black"],
2069
- border: ["white/0", "black/0"],
2070
- code: {
2071
- bg: ["50", "950"],
2072
- fg: ["700 75%", "300 75%"]
2073
- },
2074
- fg: ["700", "300"],
2075
- icon: ["700 75%", "300 75%"],
2076
- kbd: {
2077
- bg: ["white", "black"],
2078
- fg: ["700", "300"],
2079
- border: ["200", "800"]
2080
- },
2081
- link: {
2082
- fg: ["blue/700 70%", "blue/300 70%"]
2083
- },
2084
- muted: {
2085
- bg: ["100", "950"],
2086
- fg: ["700 75%", "300 75%"]
2087
- },
2088
- skeleton: {
2089
- from: ["100", "900"],
2090
- to: ["100 50%", "900 50%"]
2091
- }
2092
- },
2093
- hovered: {
2094
- bg: ["50", "950"],
2095
- fg: ["800", "200"],
2096
- icon: ["800 70%", "300 70%"]
2097
- },
2098
- pressed: {
2099
- bg: ["100", "900"],
2100
- fg: ["800", "200"],
2101
- icon: ["800 70%", "200 70%"]
2102
- },
2103
- selected: {
2104
- bg: ["100", "900"],
2105
- fg: ["800", "200"],
2106
- icon: ["800 60%", "200 60%"]
2107
- },
2108
- disabled: {
2109
- _hue: "gray",
2110
- accent: {
2111
- fg: ["200", "800"]
2112
- },
2113
- avatar: {
2114
- "*": {
2115
- _blend: ["screen", "multiply"],
2116
- bg: ["gray/100", "gray/900"],
2117
- fg: ["white", "black"]
2118
- }
2119
- },
2120
- badge: {
2121
- "*": {
2122
- _hue: "gray",
2123
- bg: ["50", "950"],
2124
- fg: ["gray/200", "gray/800"],
2125
- dot: ["gray/200", "gray/800"],
2126
- icon: ["gray/200", "gray/800"]
2127
- }
2128
- },
2129
- code: {
2130
- bg: ["50", "950"],
2131
- fg: ["200", "800"]
2132
- },
2133
- fg: ["400", "600"],
2134
- icon: ["300", "700"],
2135
- muted: {
2136
- fg: ["400", "600"]
2137
- },
2138
- kbd: {
2139
- bg: ["white", "black"],
2140
- fg: ["200", "800"],
2141
- border: ["100", "900"]
2142
- },
2143
- link: {
2144
- fg: ["200", "800"]
2145
- }
2146
- }
2147
- }
2148
- }
2149
- },
2150
- input: {
2151
- "*": {
2152
- "*": {
2153
- _blend: ["multiply", "screen"],
2154
- bg: ["white", "black"],
2155
- border: ["200", "700"],
2156
- fg: ["black", "200"],
2157
- muted: {
2158
- bg: ["50", "950"]
2159
- },
2160
- placeholder: ["400", "600"]
2161
- },
2162
- hovered: {
2163
- border: ["300", "700"]
2164
- },
2165
- readOnly: {
2166
- bg: ["50", "950"],
2167
- border: ["200", "800"],
2168
- fg: ["800", "200"]
2169
- },
2170
- disabled: {
2171
- bg: ["50", "950"],
2172
- fg: ["400", "600"],
2173
- border: ["100", "900"],
2174
- placeholder: ["200", "800 50%"]
2175
- }
2176
- },
2177
- invalid: {
2178
- "*": {
2179
- _hue: "red",
2180
- bg: ["100", "950"]
2181
- }
2182
- }
2183
- },
2184
- selectable: {
2185
- "*": {
2186
- "*": {
2187
- _blend: ["multiply", "screen"],
2188
- accent: {
2189
- fg: ["purple/700 70%", "purple/300 70%"]
2190
- },
2191
- avatar: {
2192
- "*": {
2193
- _blend: ["screen", "multiply"],
2194
- bg: ["500", "400"],
2195
- fg: ["white", "black"]
2196
- }
2197
- },
2198
- badge: {
2199
- "*": {
2200
- bg: ["100", "900"],
2201
- fg: ["600", "400"],
2202
- dot: ["500", "500"],
2203
- icon: ["500", "500"]
2204
- }
2205
- },
2206
- bg: ["white", "black"],
2207
- border: ["200", "800"],
2208
- code: {
2209
- bg: ["50", "950"],
2210
- fg: ["600", "400"]
2211
- },
2212
- fg: ["700", "300"],
2213
- icon: ["700 75%", "300 75%"],
2214
- kbd: {
2215
- bg: ["white", "black"],
2216
- fg: ["600", "400"],
2217
- border: ["200", "800"]
2218
- },
2219
- link: {
2220
- fg: ["blue/700 70%", "blue/300 70%"]
2221
- },
2222
- muted: {
2223
- bg: ["50", "950"],
2224
- fg: ["700 75%", "300 75%"]
2225
- },
2226
- skeleton: {
2227
- from: ["100", "900"],
2228
- to: ["100 50%", "900 50%"]
2229
- }
2230
- },
2231
- hovered: {
2232
- bg: ["50", "950"]
2233
- },
2234
- pressed: {
2235
- bg: ["100", "900"]
2236
- },
2237
- selected: {
2238
- _blend: ["screen", "multiply"],
2239
- accent: {
2240
- fg: ["purple/300", "purple/700"]
2241
- },
2242
- avatar: {
2243
- "*": {
2244
- _blend: ["multiply", "screen"],
2245
- bg: ["white", "black"],
2246
- fg: ["black", "white"]
2247
- }
2248
- },
2249
- badge: {
2250
- "*": {
2251
- bg: ["900", "100"],
2252
- fg: ["400", "600"],
2253
- dot: ["500", "500"],
2254
- icon: ["500", "500"]
2255
- }
2256
- },
2257
- bg: ["500", "400"],
2258
- border: ["500 20%", "400 20%"],
2259
- code: {
2260
- bg: ["500 20%", "400 20%"],
2261
- fg: ["200", "600"]
2262
- },
2263
- fg: ["white", "black"],
2264
- icon: ["100 70%", "900 70%"],
2265
- kbd: {
2266
- bg: ["black", "white"],
2267
- fg: ["200", "600"],
2268
- border: ["800", "200"]
2269
- },
2270
- link: {
2271
- fg: ["blue/200", "blue/600"]
2272
- },
2273
- muted: {
2274
- bg: ["500 10%", "400 10%"],
2275
- fg: ["100 70%", "900 70%"]
2276
- },
2277
- skeleton: {
2278
- from: ["900", "100"],
2279
- to: ["900 50%", "100 50%"]
2280
- }
2281
- },
2282
- disabled: {
2283
- _hue: "gray",
2284
- accent: {
2285
- fg: ["200", "800"]
2286
- },
2287
- avatar: {
2288
- "*": {
2289
- _blend: ["screen", "multiply"],
2290
- bg: ["gray/100", "gray/900"],
2291
- fg: ["white", "black"]
2292
- }
2293
- },
2294
- badge: {
2295
- "*": {
2296
- _hue: "gray",
2297
- bg: ["50", "950"],
2298
- fg: ["gray/200", "gray/800"],
2299
- dot: ["gray/200", "gray/800"],
2300
- icon: ["gray/200", "gray/800"]
2301
- }
2302
- },
2303
- border: ["100", "900"],
2304
- code: {
2305
- bg: ["50", "950"],
2306
- fg: ["200", "800"]
2307
- },
2308
- fg: ["200", "800"],
2309
- icon: ["200", "800"],
2310
- kbd: {
2311
- bg: ["white", "black"],
2312
- fg: ["200", "800"],
2313
- border: ["100", "900"]
2314
- },
2315
- link: {
2316
- fg: ["200", "800"]
2317
- },
2318
- muted: {
2319
- bg: ["50 50%", "950 50%"],
2320
- fg: ["200", "800"]
2321
- }
2322
- }
2323
- },
2324
- default: {
2325
- selected: {
2326
- _hue: "blue"
2327
- }
2328
- },
2329
- critical: {
2330
- disabled: {
2331
- bg: ["50 50%", "950 50%"]
2332
- }
2333
- }
2334
- },
2335
- syntax: {
2336
- atrule: ["purple/600", "purple/400"],
2337
- attrName: ["green/600", "green/400"],
2338
- attrValue: ["yellow/600", "yellow/400"],
2339
- attribute: ["yellow/600", "yellow/400"],
2340
- boolean: ["purple/600", "purple/400"],
2341
- builtin: ["purple/600", "purple/400"],
2342
- cdata: ["yellow/600", "yellow/400"],
2343
- char: ["yellow/600", "yellow/400"],
2344
- class: ["orange/600", "orange/400"],
2345
- className: ["cyan/600", "cyan/400"],
2346
- comment: ["gray/400", "gray/600"],
2347
- constant: ["purple/600", "purple/400"],
2348
- deleted: ["red/600", "red/400"],
2349
- entity: ["red/600", "red/400"],
2350
- function: ["green/600", "green/400"],
2351
- hexcode: ["blue/600", "blue/400"],
2352
- id: ["purple/600", "purple/400"],
2353
- important: ["purple/600", "purple/400"],
2354
- inserted: ["yellow/600", "yellow/400"],
2355
- keyword: ["magenta/600", "magenta/400"],
2356
- number: ["purple/600", "purple/400"],
2357
- operator: ["magenta/600", "magenta/400"],
2358
- property: ["blue/600", "blue/400"],
2359
- pseudoClass: ["yellow/600", "yellow/400"],
2360
- pseudoElement: ["yellow/600", "yellow/400"],
2361
- punctuation: ["gray/600", "gray/400"],
2362
- regex: ["blue/600", "blue/400"],
2363
- selector: ["red/600", "red/400"],
2364
- string: ["yellow/600", "yellow/400"],
2365
- symbol: ["purple/600", "purple/400"],
2366
- tag: ["red/600", "red/400"],
2367
- unit: ["orange/600", "orange/400"],
2368
- url: ["red/600", "red/400"],
2369
- variable: ["red/600", "red/400"]
2370
- }
2371
- };
2372
- function isRecord(value) {
2373
- return !!(value && typeof value == "object" && !Array.isArray(value));
2374
- }
2375
- function merge(...records) {
2376
- const _records = records.filter(Boolean);
2377
- return _records.length === 0 ? {} : _records.reduce(_merge, {});
2378
- }
2379
- function _merge(acc, source) {
2380
- for (const key of Object.keys(source)) {
2381
- const prevValue = acc[key], nextValue = source[key];
2382
- isRecord(prevValue) && isRecord(nextValue) ? acc[key] = merge(prevValue, nextValue) : acc[key] = nextValue;
2383
- }
2384
- return acc;
2385
- }
2386
- function resolveColorTokens(inputTokens) {
2387
- const tokens = merge(defaultColorTokens, inputTokens);
2388
- return {
2389
- base: resolveBaseColorTokens(tokens),
2390
- button: resolveButtonColorTokens(tokens),
2391
- input: resolveInputColorTokens(tokens),
2392
- selectable: resolveSelectableColorTokens(tokens),
2393
- syntax: tokens.syntax
2394
- };
2395
- }
2396
- function resolveBaseColorTokens(sparseTokens) {
2397
- const tokens = {};
2398
- for (const tone of THEME_COLOR_CARD_TONES)
2399
- tokens[tone] = resolveBaseColorTones(sparseTokens, tone);
2400
- return tokens;
2401
- }
2402
- function resolveBaseColorTones(inputTokens, tone) {
2403
- const spec = merge(inputTokens?.base?.["*"], inputTokens?.base?.[tone]), hue = spec._hue || inputTokens?.base?.[tone]?._hue || "gray";
2404
- return {
2405
- ...spec,
2406
- _hue: hue,
2407
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2408
- ...acc,
2409
- [hue2]: merge({
2410
- _hue: hue2
2411
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2412
- }), {}),
2413
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2414
- ...acc,
2415
- [tone2]: {
2416
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2417
- ...spec.badge?.["*"],
2418
- ...spec.badge?.[tone2]
2419
- }
2420
- }), {})
2421
- };
2422
- }
2423
- function resolveButtonColorTokens(inputTokens) {
2424
- const tokens = {};
2425
- for (const mode of THEME_COLOR_BUTTON_MODES)
2426
- tokens[mode] = resolveButtonToneColorTokens(inputTokens, mode);
2427
- return tokens;
2428
- }
2429
- function resolveButtonToneColorTokens(inputTokens, mode) {
2430
- const tokens = {};
2431
- for (const tone of THEME_COLOR_STATE_TONES)
2432
- tokens[tone] = resolveButtonModeColorTokens(inputTokens, mode, tone);
2433
- return tokens;
2434
- }
2435
- function resolveButtonModeColorTokens(inputTokens, mode, tone) {
2436
- const tokens = {};
2437
- for (const state of THEME_COLOR_STATES)
2438
- tokens[state] = resolveButtonStateColorTokens(inputTokens, tone, mode, state);
2439
- return tokens;
2440
- }
2441
- function resolveButtonStateColorTokens(inputTokens, tone, mode, state) {
2442
- 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;
2443
- return {
2444
- ...spec,
2445
- _hue: hue,
2446
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2447
- ...acc,
2448
- [hue2]: merge({
2449
- _hue: hue2
2450
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2451
- }), {}),
2452
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2453
- ...acc,
2454
- [tone2]: {
2455
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2456
- ...spec.badge?.["*"],
2457
- ...spec.badge?.[tone2]
2458
- }
2459
- }), {})
2460
- };
2461
- }
2462
- function resolveInputColorTokens(inputTokens) {
2463
- const tokens = {};
2464
- for (const mode of THEME_COLOR_INPUT_MODES)
2465
- tokens[mode] = resolveInputModeColorTokens(inputTokens, mode);
2466
- return tokens;
2467
- }
2468
- function resolveInputModeColorTokens(inputTokens, mode) {
2469
- const states = {};
2470
- for (const state of THEME_COLOR_INPUT_STATES)
2471
- states[state] = resolveInputStateColorTokens(inputTokens, mode, state);
2472
- return states;
2473
- }
2474
- function resolveInputStateColorTokens(inputTokens, mode, state) {
2475
- const spec = merge(inputTokens?.input?.["*"]?.["*"], inputTokens?.input?.[mode]?.["*"], inputTokens?.input?.["*"]?.[state], inputTokens?.input?.[mode]?.[state]), hue = spec._hue || inputTokens?.input?.[mode]?._hue;
2476
- return {
2477
- ...spec,
2478
- _hue: hue
2479
- };
2480
- }
2481
- function resolveSelectableColorTokens(inputTokens) {
2482
- const tokens = {};
2483
- for (const tone of THEME_COLOR_STATE_TONES)
2484
- tokens[tone] = resolveSelectableToneColorTokens(inputTokens, tone);
2485
- return tokens;
2486
- }
2487
- function resolveSelectableToneColorTokens(inputTokens, tone) {
2488
- const states = {
2489
- _hue: inputTokens?.selectable?.[tone]?._hue || inputTokens?.base?.[tone]?._hue
2490
- };
2491
- for (const state of THEME_COLOR_STATES)
2492
- states[state] = resolveSelectableStateColorTokens(inputTokens, tone, state);
2493
- return states;
2494
- }
2495
- function resolveSelectableStateColorTokens(inputTokens, tone, state) {
2496
- const spec = merge(inputTokens?.selectable?.["*"]?.["*"], inputTokens?.selectable?.[tone]?.["*"], inputTokens?.selectable?.["*"]?.[state], inputTokens?.selectable?.[tone]?.[state]), hue = spec._hue || inputTokens?.base?.[tone]?._hue;
2497
- return {
2498
- ...spec,
2499
- _hue: hue,
2500
- avatar: COLOR_HUES.reduce((acc, hue2) => ({
2501
- ...acc,
2502
- [hue2]: merge({
2503
- _hue: hue2
2504
- }, spec.avatar?.["*"], spec.avatar?.[hue2])
2505
- }), {}),
2506
- badge: THEME_COLOR_STATE_TONES.reduce((acc, tone2) => ({
2507
- ...acc,
2508
- [tone2]: {
2509
- _hue: inputTokens?.base?.[tone2]?._hue || hue,
2510
- ...spec.badge?.["*"],
2511
- ...spec.badge?.[tone2]
2512
- }
2513
- }), {})
2514
- };
2515
- }
2516
- function buildColorTheme(config) {
2517
- const resolvedConfig = {
2518
- color: resolveColorTokens(config?.color)
2519
- };
2520
- return {
2521
- light: buildColorScheme({
2522
- scheme: "light"
2523
- }, resolvedConfig),
2524
- dark: buildColorScheme({
2525
- scheme: "dark"
2526
- }, resolvedConfig)
2527
- };
2528
- }
2529
- function buildColorScheme(options, config) {
2530
- const {
2531
- scheme
2532
- } = options, colorScheme = {};
2533
- for (const tone of THEME_COLOR_CARD_TONES)
2534
- colorScheme[tone] = buildCardColorTheme({
2535
- scheme,
2536
- tone
2537
- }, config);
2538
- return colorScheme;
2539
- }
2540
- function buildCardColorTheme(options, config) {
2541
- const {
2542
- scheme,
2543
- tone
2544
- } = options, tokens = config?.color?.base?.[tone], context = {
2545
- hue: tokens?._hue || "gray",
2546
- scheme
2547
- };
2548
- return {
2549
- _blend: (tokens?._blend || ["multiply", "screen"])[scheme === "light" ? 0 : 1],
2550
- _dark: scheme === "dark",
2551
- accent: {
2552
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2553
- },
2554
- avatar: buildAvatarColorTheme({
2555
- scheme
2556
- }, tokens),
2557
- backdrop: resolveColorTokenValue(context, tokens?.backdrop),
2558
- badge: buildBadgeColorTheme(tokens?.badge, {
2559
- scheme
2560
- }, config),
2561
- bg: resolveColorTokenValue(context, tokens?.bg),
2562
- border: resolveColorTokenValue(context, tokens?.border),
2563
- button: buildButtonColorTheme({
2564
- scheme,
2565
- tone
2566
- }, config),
2567
- code: {
2568
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2569
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2570
- },
2571
- fg: resolveColorTokenValue(context, tokens?.fg),
2572
- focusRing: resolveColorTokenValue(context, tokens?.focusRing),
2573
- icon: resolveColorTokenValue(context, tokens?.icon),
2574
- input: buildInputColorTheme({
2575
- scheme,
2576
- tone
2577
- }, config),
2578
- kbd: {
2579
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2580
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2581
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2582
- },
2583
- link: {
2584
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2585
- },
2586
- muted: {
2587
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2588
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2589
- },
2590
- selectable: buildSelectableColorTheme({
2591
- scheme,
2592
- tone
2593
- }, config),
2594
- shadow: buildShadowColorTheme({
2595
- scheme,
2596
- tone
2597
- }, config),
2598
- skeleton: {
2599
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2600
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2601
- },
2602
- syntax: buildSyntaxColorTheme({
2603
- scheme
2604
- }, config)
2605
- };
2606
- }
2607
- function buildShadowColorTheme(options, config) {
2608
- const {
2609
- scheme,
2610
- tone
2611
- } = options, tokens = config?.color?.base?.[tone], context = {
2612
- hue: tokens?._hue || "gray",
2613
- scheme
2614
- };
2615
- return {
2616
- outline: resolveColorTokenValue(context, tokens?.shadow?.outline),
2617
- umbra: resolveColorTokenValue(context, tokens?.shadow?.umbra),
2618
- penumbra: resolveColorTokenValue(context, tokens?.shadow?.penumbra),
2619
- ambient: resolveColorTokenValue(context, tokens?.shadow?.ambient)
2620
- };
2621
- }
2622
- function buildAvatarColorTheme(options, stateTokens) {
2623
- const {
2624
- scheme
2625
- } = options;
2626
- return {
2627
- gray: _buildAvatarColorTheme({
2628
- color: "gray",
2629
- scheme
2630
- }, stateTokens),
2631
- blue: _buildAvatarColorTheme({
2632
- color: "blue",
2633
- scheme
2634
- }, stateTokens),
2635
- purple: _buildAvatarColorTheme({
2636
- color: "purple",
2637
- scheme
2638
- }, stateTokens),
2639
- magenta: _buildAvatarColorTheme({
2640
- color: "magenta",
2641
- scheme
2642
- }, stateTokens),
2643
- red: _buildAvatarColorTheme({
2644
- color: "red",
2645
- scheme
2646
- }, stateTokens),
2647
- orange: _buildAvatarColorTheme({
2648
- color: "orange",
2649
- scheme
2650
- }, stateTokens),
2651
- yellow: _buildAvatarColorTheme({
2652
- color: "yellow",
2653
- scheme
2654
- }, stateTokens),
2655
- green: _buildAvatarColorTheme({
2656
- color: "green",
2657
- scheme
2658
- }, stateTokens),
2659
- cyan: _buildAvatarColorTheme({
2660
- color: "cyan",
2661
- scheme
2662
- }, stateTokens)
2663
- };
2664
- }
2665
- function _buildAvatarColorTheme(options, stateTokens) {
2666
- const {
2667
- color: color2,
2668
- scheme
2669
- } = options, tokens = stateTokens?.avatar?.[color2], context = {
2670
- hue: tokens?._hue || "gray",
2671
- scheme
2672
- };
2673
- return {
2674
- _blend: (tokens?._blend || ["screen", "multiply"])[scheme === "light" ? 0 : 1],
2675
- bg: resolveColorTokenValue(context, tokens?.bg),
2676
- fg: resolveColorTokenValue(context, tokens?.fg)
2677
- };
2678
- }
2679
- function buildBadgeColorTheme(tokens, options, config) {
2680
- const {
2681
- scheme
2682
- } = options, colorBadge = {};
2683
- for (const tone of THEME_COLOR_STATE_TONES)
2684
- colorBadge[tone] = _buildBadgeColorTheme(tokens, {
2685
- scheme,
2686
- tone
2687
- }, config);
2688
- return colorBadge;
2689
- }
2690
- function _buildBadgeColorTheme(parentTokens, options, config) {
2691
- const {
2692
- scheme,
2693
- tone
2694
- } = options, tokens = parentTokens?.[tone], context = {
2695
- hue: tokens?._hue || config?.color?.base?.[tone]?._hue || "gray",
2696
- scheme
2697
- };
2698
- return {
2699
- bg: resolveColorTokenValue(context, tokens?.bg),
2700
- fg: resolveColorTokenValue(context, tokens?.fg),
2701
- dot: resolveColorTokenValue(context, tokens?.dot),
2702
- icon: resolveColorTokenValue(context, tokens?.icon)
2703
- };
2704
- }
2705
- function buildButtonColorTheme(options, config) {
2706
- const {
2707
- scheme,
2708
- tone: cardTone
2709
- } = options, modes = {};
2710
- for (const mode of THEME_COLOR_BUTTON_MODES)
2711
- modes[mode] = buildButtonTonesColorTheme({
2712
- cardTone,
2713
- scheme,
2714
- mode
2715
- }, config);
2716
- return modes;
2717
- }
2718
- function buildButtonTonesColorTheme(options, config) {
2719
- const {
2720
- cardTone,
2721
- mode,
2722
- scheme
2723
- } = options, tones2 = {};
2724
- for (const tone of THEME_COLOR_STATE_TONES)
2725
- tones2[tone] = buildButtonStatesColorTheme({
2726
- cardTone,
2727
- mode,
2728
- scheme,
2729
- tone
2730
- }, config);
2731
- return tones2;
2732
- }
2733
- function buildButtonStatesColorTheme(options, config) {
2734
- const {
2735
- cardTone,
2736
- mode,
2737
- scheme,
2738
- tone
2739
- } = options, states = {};
2740
- for (const state of THEME_COLOR_STATES)
2741
- states[state] = buildButtonStateColorTheme({
2742
- cardTone,
2743
- mode,
2744
- tone,
2745
- scheme,
2746
- state
2747
- }, config);
2748
- return states;
2749
- }
2750
- function buildButtonStateColorTheme(options, config) {
2751
- const {
2752
- cardTone,
2753
- mode,
2754
- tone,
2755
- scheme,
2756
- state
2757
- } = 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 = {
2758
- hue,
2759
- scheme
2760
- };
2761
- return {
2762
- _blend: blendMode[scheme === "light" ? 0 : 1],
2763
- accent: {
2764
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2765
- },
2766
- avatar: buildAvatarColorTheme({
2767
- scheme
2768
- }, tokens),
2769
- badge: buildBadgeColorTheme(tokens?.badge, {
2770
- scheme
2771
- }, config),
2772
- bg: resolveColorTokenValue(context, tokens?.bg),
2773
- border: resolveColorTokenValue(context, tokens?.border),
2774
- code: {
2775
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2776
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2777
- },
2778
- fg: resolveColorTokenValue(context, tokens?.fg),
2779
- icon: resolveColorTokenValue(context, tokens?.icon),
2780
- muted: {
2781
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2782
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2783
- },
2784
- kbd: {
2785
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2786
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2787
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2788
- },
2789
- link: {
2790
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2791
- },
2792
- skeleton: {
2793
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2794
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2795
- }
2796
- };
2797
- }
2798
- function buildInputColorTheme(options, config) {
2799
- const {
2800
- scheme,
2801
- tone
2802
- } = options;
2803
- return {
2804
- default: buildInputStatesColorTheme({
2805
- mode: "default",
2806
- scheme,
2807
- tone
2808
- }, config),
2809
- invalid: buildInputStatesColorTheme({
2810
- mode: "invalid",
2811
- scheme,
2812
- tone
2813
- }, config)
2814
- };
2815
- }
2816
- function buildInputStatesColorTheme(options, config) {
2817
- const {
2818
- mode,
2819
- scheme,
2820
- tone
2821
- } = options;
2822
- return {
2823
- enabled: buildInputStateColorTheme({
2824
- mode,
2825
- scheme,
2826
- state: "enabled",
2827
- cardTone: tone
2828
- }, config),
2829
- hovered: buildInputStateColorTheme({
2830
- mode,
2831
- scheme,
2832
- state: "hovered",
2833
- cardTone: tone
2834
- }, config),
2835
- readOnly: buildInputStateColorTheme({
2836
- mode,
2837
- scheme,
2838
- state: "readOnly",
2839
- cardTone: tone
2840
- }, config),
2841
- disabled: buildInputStateColorTheme({
2842
- mode,
2843
- scheme,
2844
- state: "disabled",
2845
- cardTone: tone
2846
- }, config)
2847
- };
2848
- }
2849
- function buildInputStateColorTheme(options, config) {
2850
- const {
2851
- cardTone,
2852
- mode,
2853
- scheme,
2854
- state
2855
- } = options, cardTokens = config?.color?.base?.[cardTone], tokens = config?.color?.input?.[mode]?.[state], hue = tokens?._hue || cardTokens?._hue || "gray", blendMode = tokens?._blend || ["screen", "multiply"], context = {
2856
- hue,
2857
- scheme
2858
- };
2859
- return {
2860
- _blend: blendMode[scheme === "light" ? 0 : 1],
2861
- bg: resolveColorTokenValue(context, tokens?.bg),
2862
- border: resolveColorTokenValue(context, tokens?.border),
2863
- fg: resolveColorTokenValue(context, tokens?.fg),
2864
- muted: {
2865
- bg: resolveColorTokenValue(context, tokens?.muted?.bg)
2866
- },
2867
- placeholder: resolveColorTokenValue(context, tokens?.placeholder)
2868
- };
2869
- }
2870
- function buildSelectableColorTheme(options, config) {
2871
- const {
2872
- scheme,
2873
- tone: cardTone
2874
- } = options, tones2 = {};
2875
- for (const tone of THEME_COLOR_STATE_TONES)
2876
- tones2[tone] = buildSelectableStatesColorTheme({
2877
- cardTone,
2878
- scheme,
2879
- tone
2880
- }, config);
2881
- return tones2;
2882
- }
2883
- function buildSelectableStatesColorTheme(options, config) {
2884
- const {
2885
- cardTone,
2886
- scheme,
2887
- tone
2888
- } = options, states = {};
2889
- for (const state of THEME_COLOR_STATES)
2890
- states[state] = buildSelectableStateColorTheme({
2891
- cardTone,
2892
- tone,
2893
- scheme,
2894
- state
2895
- }, config);
2896
- return states;
2897
- }
2898
- function buildSelectableStateColorTheme(options, config) {
2899
- const {
2900
- cardTone,
2901
- scheme,
2902
- state,
2903
- tone
2904
- } = options, cardTokens = config?.color?.base?.[cardTone], tokens = config?.color?.selectable?.[tone]?.[state], hue = tokens?._hue || cardTokens?._hue || "gray", blendMode = tokens?._blend || ["screen", "multiply"], context = {
2905
- hue,
2906
- scheme
2907
- };
2908
- return {
2909
- _blend: blendMode[scheme === "light" ? 0 : 1],
2910
- accent: {
2911
- fg: resolveColorTokenValue(context, tokens?.accent?.fg)
2912
- },
2913
- avatar: buildAvatarColorTheme({
2914
- scheme
2915
- }, tokens),
2916
- badge: buildBadgeColorTheme(tokens?.badge, {
2917
- scheme
2918
- }, config),
2919
- bg: resolveColorTokenValue(context, tokens?.bg),
2920
- border: resolveColorTokenValue(context, tokens?.border),
2921
- code: {
2922
- bg: resolveColorTokenValue(context, tokens?.code?.bg),
2923
- fg: resolveColorTokenValue(context, tokens?.code?.fg)
2924
- },
2925
- fg: resolveColorTokenValue(context, tokens?.fg),
2926
- icon: resolveColorTokenValue(context, tokens?.icon),
2927
- muted: {
2928
- bg: resolveColorTokenValue(context, tokens?.muted?.bg),
2929
- fg: resolveColorTokenValue(context, tokens?.muted?.fg)
2930
- },
2931
- kbd: {
2932
- bg: resolveColorTokenValue(context, tokens?.kbd?.bg),
2933
- fg: resolveColorTokenValue(context, tokens?.kbd?.fg),
2934
- border: resolveColorTokenValue(context, tokens?.kbd?.border)
2935
- },
2936
- link: {
2937
- fg: resolveColorTokenValue(context, tokens?.link?.fg)
2938
- },
2939
- skeleton: {
2940
- from: resolveColorTokenValue(context, tokens?.skeleton?.from),
2941
- to: resolveColorTokenValue(context, tokens?.skeleton?.to)
2942
- }
2943
- };
2944
- }
2945
- function buildSyntaxColorTheme(options, config) {
2946
- const {
2947
- scheme
2948
- } = options, tokens = config?.color?.syntax, context = {
2949
- hue: "gray",
2950
- scheme
2951
- };
2952
- return {
2953
- atrule: resolveColorTokenValue(context, tokens?.atrule),
2954
- attrName: resolveColorTokenValue(context, tokens?.attrName),
2955
- attrValue: resolveColorTokenValue(context, tokens?.attrValue),
2956
- attribute: resolveColorTokenValue(context, tokens?.attribute),
2957
- boolean: resolveColorTokenValue(context, tokens?.boolean),
2958
- builtin: resolveColorTokenValue(context, tokens?.builtin),
2959
- cdata: resolveColorTokenValue(context, tokens?.cdata),
2960
- char: resolveColorTokenValue(context, tokens?.char),
2961
- class: resolveColorTokenValue(context, tokens?.class),
2962
- className: resolveColorTokenValue(context, tokens?.className),
2963
- comment: resolveColorTokenValue(context, tokens?.comment),
2964
- constant: resolveColorTokenValue(context, tokens?.constant),
2965
- deleted: resolveColorTokenValue(context, tokens?.deleted),
2966
- doctype: resolveColorTokenValue(context, tokens?.doctype),
2967
- entity: resolveColorTokenValue(context, tokens?.entity),
2968
- function: resolveColorTokenValue(context, tokens?.function),
2969
- hexcode: resolveColorTokenValue(context, tokens?.hexcode),
2970
- id: resolveColorTokenValue(context, tokens?.id),
2971
- important: resolveColorTokenValue(context, tokens?.important),
2972
- inserted: resolveColorTokenValue(context, tokens?.inserted),
2973
- keyword: resolveColorTokenValue(context, tokens?.keyword),
2974
- number: resolveColorTokenValue(context, tokens?.number),
2975
- operator: resolveColorTokenValue(context, tokens?.operator),
2976
- prolog: resolveColorTokenValue(context, tokens?.prolog),
2977
- property: resolveColorTokenValue(context, tokens?.property),
2978
- pseudoClass: resolveColorTokenValue(context, tokens?.pseudoClass),
2979
- pseudoElement: resolveColorTokenValue(context, tokens?.pseudoElement),
2980
- punctuation: resolveColorTokenValue(context, tokens?.punctuation),
2981
- regex: resolveColorTokenValue(context, tokens?.regex),
2982
- selector: resolveColorTokenValue(context, tokens?.selector),
2983
- string: resolveColorTokenValue(context, tokens?.string),
2984
- symbol: resolveColorTokenValue(context, tokens?.symbol),
2985
- tag: resolveColorTokenValue(context, tokens?.tag),
2986
- unit: resolveColorTokenValue(context, tokens?.unit),
2987
- url: resolveColorTokenValue(context, tokens?.url),
2988
- variable: resolveColorTokenValue(context, tokens?.variable)
2989
- };
2990
- }
2991
- const defaultColorPalette = color;
2992
- function mixChannel(b, s, weight) {
2993
- const delta = (s - b) * weight;
2994
- return b + delta;
2995
- }
2996
- function mix(b, s, weight) {
2997
- return {
2998
- r: mixChannel(b.r, s.r, weight),
2999
- g: mixChannel(b.g, s.g, weight),
3000
- b: mixChannel(b.b, s.b, weight)
3001
- };
3002
- }
3003
- function multiplyChannel(b, s) {
3004
- return b * s;
3005
- }
3006
- function multiply(b, s) {
3007
- return {
3008
- r: multiplyChannel(b.r / 255, s.r / 255) * 255,
3009
- g: multiplyChannel(b.g / 255, s.g / 255) * 255,
3010
- b: multiplyChannel(b.b / 255, s.b / 255) * 255
3011
- };
3012
- }
3013
- function screenChannel(b, s) {
3014
- return b + s - b * s;
3015
- }
3016
- function screen(b, s) {
3017
- return {
3018
- r: screenChannel(b.r / 255, s.r / 255) * 255,
3019
- g: screenChannel(b.g / 255, s.g / 255) * 255,
3020
- b: screenChannel(b.b / 255, s.b / 255) * 255
3021
- };
3022
- }
3023
- function lerp(x, y, a) {
3024
- return x * (1 - a) + y * a;
3025
- }
3026
- function invlerp(x, y, a) {
3027
- return clamp((a - x) / (y - x));
3028
- }
3029
- function clamp(a, min = 0, max = 1) {
3030
- return Math.min(max, Math.max(min, a));
3031
- }
3032
- function range(x1, y1, x2, y2, a) {
3033
- return lerp(x2, y2, invlerp(x1, y1, a));
3034
- }
3035
- function round(value) {
3036
- return Math.round(value);
3037
- }
3038
- function hexToRgb(hex) {
3039
- if (hex.length === 4) {
3040
- const hexR = hex.slice(1, 2), hexG = hex.slice(2, 3), hexB = hex.slice(3, 4);
3041
- return {
3042
- r: parseInt(hexR + hexR, 16),
3043
- g: parseInt(hexG + hexG, 16),
3044
- b: parseInt(hexB + hexB, 16)
3045
- };
3046
- }
3047
- return {
3048
- r: parseInt(hex.slice(1, 3), 16),
3049
- g: parseInt(hex.slice(3, 5), 16),
3050
- b: parseInt(hex.slice(5, 7), 16)
3051
- };
3052
- }
3053
- function rgbaToRGBA(rgba2) {
3054
- const values = rgba2.replace(/rgba\(|\)/g, "").split(",");
3055
- return {
3056
- r: parseInt(values[0]),
3057
- g: parseInt(values[1]),
3058
- b: parseInt(values[2]),
3059
- a: parseFloat(values[3])
3060
- };
3061
- }
3062
- function rgbToHex(color2) {
3063
- 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));
3064
- return "a" in color2 ? `rgba(${r},${g},${b},${color2.a})` : "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
3065
- }
3066
- function rgbToHsl({
3067
- r,
3068
- g,
3069
- b
3070
- }) {
3071
- r /= 255, g /= 255, b /= 255;
3072
- const cmin = Math.min(r, g, b), cmax = Math.max(r, g, b), delta = cmax - cmin;
3073
- let h = 0, s = 0, l = 0;
3074
- 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), {
3075
- h,
3076
- s,
3077
- l
3078
- };
3079
- }
3080
- function hslToRgb(hsl) {
3081
- 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;
3082
- let r = 0, g = 0, b = 0;
3083
- 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), {
3084
- r: Math.round((r + m) * 255),
3085
- g: Math.round((g + m) * 255),
3086
- b: Math.round((b + m) * 255)
3087
- };
3088
- }
3089
- const HEX_CHARS = "0123456789ABCDEFabcdef", HSL_RE = /hsl\(\s*(\d+)\s*,\s*((\d+(?:\.\d+)?)%)\s*,\s*((\d+(?:\.\d+)?)%)\s*\)/i;
3090
- function isHexChars(str) {
3091
- for (const c of str)
3092
- if (HEX_CHARS.indexOf(c) === -1)
3093
- return !1;
3094
- return !0;
3095
- }
3096
- function isHex(str) {
3097
- return str[0] !== "#" || !(str.length === 4 || str.length === 7) ? !1 : isHexChars(str.slice(1));
3098
- }
3099
- function parseHsl(str) {
3100
- const res = HSL_RE.exec(str);
3101
- if (!res)
3102
- throw new Error(`parseHsl: string is not a HSL color: "${str}"`);
3103
- return {
3104
- h: parseInt(res[1]),
3105
- s: parseFloat(res[3]),
3106
- l: parseFloat(res[5])
3107
- };
3108
- }
3109
- function parseColor(color2) {
3110
- if (!color2) return {
3111
- r: 0,
3112
- g: 0,
3113
- b: 0
3114
- };
3115
- if (typeof color2 != "string")
3116
- throw new Error("parseColor: expected a string");
3117
- if (isHex(color2))
3118
- return hexToRgb(color2);
3119
- if (color2.startsWith("hsl("))
3120
- return hslToRgb(parseHsl(color2));
3121
- if (color2.startsWith("rgba("))
3122
- return rgbaToRGBA(color2);
3123
- throw new Error(`parseColor: unexpected color format: "${color2}"`);
3124
- }
3125
- function getContrastRatio(bg, fg) {
3126
- const rgb1 = parseColor(bg), rgb2 = parseColor(fg), c1 = rgb_lrgb(rgb1), c2 = rgb_lrgb(rgb2), l1 = lrgb_luminance(c1), l2 = lrgb_luminance(c2);
3127
- return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
3128
- }
3129
- function rgb_lrgb({
3130
- r,
3131
- g,
3132
- b
3133
- }) {
3134
- return [rgb_lrgb1(r / 255), rgb_lrgb1(g / 255), rgb_lrgb1(b / 255)];
3135
- }
3136
- function rgb_lrgb1(v) {
3137
- return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
3138
- }
3139
- function lrgb_luminance([r, g, b]) {
3140
- return 0.2126 * r + 0.7152 * g + 0.0722 * b;
3141
- }
3142
- function rgba(color2, a) {
3143
- const rgb = parseColor(color2);
3144
- return `rgba(${rgb.r},${rgb.g},${rgb.b},${a})`;
3145
- }
3146
- const RGB_RANGE = [0, 255];
3147
- function mixThemeColor(value, options) {
3148
- const {
3149
- blendMode
3150
- } = options, color2 = parseColor(value), black2 = parseColor(options.black), white2 = parseColor(options.white), bg = options.bg ? parseColor(options.bg) : blendMode === "multiply" ? white2 : black2, paletteRange = {
3151
- r: [black2.r, white2.r],
3152
- g: [black2.g, white2.g],
3153
- b: [black2.b, white2.b]
3154
- }, convertedBgColor = {
3155
- r: clamp(range(...paletteRange.r, ...RGB_RANGE, bg.r), ...RGB_RANGE),
3156
- g: clamp(range(...paletteRange.g, ...RGB_RANGE, bg.g), ...RGB_RANGE),
3157
- b: clamp(range(...paletteRange.b, ...RGB_RANGE, bg.b), ...RGB_RANGE)
3158
- }, convertedColor = {
3159
- r: clamp(range(...paletteRange.r, ...RGB_RANGE, color2.r), ...RGB_RANGE),
3160
- g: clamp(range(...paletteRange.g, ...RGB_RANGE, color2.g), ...RGB_RANGE),
3161
- b: clamp(range(...paletteRange.b, ...RGB_RANGE, color2.b), ...RGB_RANGE)
3162
- }, resultColor = blendMode === "multiply" ? multiply(convertedBgColor, convertedColor) : screen(convertedBgColor, convertedColor), v = {
3163
- r: clamp(range(...RGB_RANGE, ...paletteRange.r, resultColor.r), ...paletteRange.r),
3164
- g: clamp(range(...RGB_RANGE, ...paletteRange.g, resultColor.g), ...paletteRange.g),
3165
- b: clamp(range(...RGB_RANGE, ...paletteRange.b, resultColor.b), ...paletteRange.b)
3166
- };
3167
- return rgbToHex(v);
3168
- }
3169
- function renderColorValue(str, options) {
3170
- const {
3171
- bg,
3172
- blendMode,
3173
- colorPalette
3174
- } = options;
3175
- if (bg === "white")
3176
- throw new Error("Cannot blend with white background");
3177
- const node = parseTokenValue(str);
3178
- if (!node || node.type !== "color")
3179
- throw new Error(`Invalid color token value: ${str}`);
3180
- let hex = "";
3181
- 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)
3182
- throw new Error(`Invalid color token value: ${str}`);
3183
- const hexBeforeMix = hex, mixOptions = {
3184
- blendMode,
3185
- bg,
3186
- black: renderColorHex(colorPalette.black),
3187
- // opacity: node.opacity,
3188
- white: renderColorHex(colorPalette.white)
3189
- };
3190
- try {
3191
- if (hex = mixThemeColor(hex, mixOptions), bg && node.mix !== void 0) {
3192
- const from = hexToRgb(bg), to = hexToRgb(hex);
3193
- hex = rgbToHex(mix(from, to, node.mix));
3194
- }
3195
- } catch (err) {
3196
- throw console.warn("could not blend", hex, mixOptions), err;
3197
- }
3198
- return hex === "#aN" && (console.warn(`invalid color token value: ${str}`), hex = hexBeforeMix), node.opacity !== void 0 && (hex = rgba(hex, node.opacity)), hex;
3199
- }
3200
- function renderColorHex(color2) {
3201
- return typeof color2 == "string" ? color2 : color2.hex;
3202
- }
3203
- function renderThemeColorSchemes(value, config) {
3204
- const colorPalette = config?.palette ?? defaultColorPalette;
3205
- return {
3206
- light: renderThemeColorScheme(colorPalette, value.light),
3207
- dark: renderThemeColorScheme(colorPalette, value.dark)
3208
- };
3209
- }
3210
- function renderThemeColorScheme(colorPalette, value) {
3211
- const toneEntries = Object.entries(value), [, transparentTone] = toneEntries.find(([k]) => k === "transparent"), [, defaultTone] = toneEntries.find(([k]) => k === "default"), renderedTransparentTone = renderThemeColor(transparentTone, {
3212
- colorPalette
3213
- }), renderedDefaultTone = renderThemeColor(defaultTone, {
3214
- colorPalette
3215
- }), bg = renderedDefaultTone.bg;
3216
- if (bg === "white")
3217
- throw new Error("Cannot blend with white background");
3218
- return Object.fromEntries([["transparent", renderedTransparentTone], ["default", renderedDefaultTone], ...toneEntries.filter(([k]) => k !== "default" && k !== "transparent").map(([k, v]) => [k, renderThemeColor(v, {
3219
- bg,
3220
- colorPalette
3221
- })])]);
3222
- }
3223
- function renderThemeColor(value, options) {
3224
- const {
3225
- colorPalette,
3226
- bg
3227
- } = options, blendMode = value._blend || "multiply", baseBg = renderColorValue(value.bg, {
3228
- colorPalette,
3229
- bg,
3230
- blendMode
3231
- }), colorOptions = {
3232
- colorPalette,
3233
- bg: baseBg,
3234
- blendMode
3235
- }, button = renderThemeColorButton(value.button, {
3236
- baseBg,
3237
- blendMode,
3238
- colorPalette
3239
- }), selectable = renderThemeColorSelectable(value.selectable, {
3240
- colorPalette,
3241
- baseBg,
3242
- blendMode
3243
- }), shadow = {
3244
- outline: renderColorValue(value.shadow.outline, colorOptions),
3245
- umbra: renderColorValue(value.shadow.umbra, {
3246
- ...colorOptions,
3247
- bg: void 0,
3248
- colorPalette: {
3249
- ...colorPalette,
3250
- black: "#000000"
3251
- }
3252
- }),
3253
- penumbra: renderColorValue(value.shadow.penumbra, {
3254
- ...colorOptions,
3255
- bg: void 0,
3256
- colorPalette: {
3257
- ...colorPalette,
3258
- black: "#000000"
3259
- }
3260
- }),
3261
- ambient: renderColorValue(value.shadow.ambient, {
3262
- ...colorOptions,
3263
- bg: void 0,
3264
- colorPalette: {
3265
- ...colorPalette,
3266
- black: "#000000"
3267
- }
3268
- })
3269
- };
3270
- return {
3271
- _blend: blendMode,
3272
- _dark: value._dark,
3273
- accent: {
3274
- fg: renderColorValue(value.accent.fg, colorOptions)
3275
- },
3276
- avatar: renderThemeColorAvatar(value.avatar, {
3277
- baseBg,
3278
- colorPalette,
3279
- blendMode
3280
- }),
3281
- backdrop: renderColorValue(value.backdrop, colorOptions),
3282
- badge: renderThemeColorBadge(value.badge, {
3283
- baseBg,
3284
- colorPalette,
3285
- blendMode
3286
- }),
3287
- bg: baseBg,
3288
- border: renderColorValue(value.border, colorOptions),
3289
- button,
3290
- code: {
3291
- bg: renderColorValue(value.code.bg, colorOptions),
3292
- fg: renderColorValue(value.code.fg, colorOptions)
3293
- },
3294
- fg: renderColorValue(value.fg, colorOptions),
3295
- focusRing: renderColorValue(value.focusRing, colorOptions),
3296
- icon: renderColorValue(value.icon, colorOptions),
3297
- input: renderThemeColorInput(value.input, {
3298
- baseBg,
3299
- colorPalette,
3300
- blendMode
3301
- }),
3302
- kbd: renderThemeColorKBD(value.kbd, {
3303
- baseBg,
3304
- colorPalette,
3305
- blendMode
3306
- }),
3307
- link: {
3308
- fg: renderColorValue(value.link.fg, colorOptions)
3309
- },
3310
- muted: {
3311
- bg: renderColorValue(value.muted.bg, colorOptions),
3312
- fg: renderColorValue(value.muted.fg, colorOptions)
3313
- },
3314
- shadow,
3315
- skeleton: {
3316
- from: renderColorValue(value.skeleton.from, colorOptions),
3317
- to: renderColorValue(value.skeleton.to, colorOptions)
3318
- },
3319
- syntax: renderSyntaxColorTheme(value.syntax, {
3320
- baseBg,
3321
- colorPalette,
3322
- blendMode
3323
- }),
3324
- selectable
3325
- };
3326
- }
3327
- function renderThemeColorKBD(value, options) {
3328
- const {
3329
- baseBg,
3330
- blendMode,
3331
- colorPalette
3332
- } = options, rootOptions = {
3333
- bg: baseBg,
3334
- blendMode,
3335
- colorPalette
3336
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3337
- bg,
3338
- blendMode,
3339
- colorPalette
3340
- };
3341
- return {
3342
- bg,
3343
- fg: renderColorValue(value.fg, colorOptions),
3344
- border: renderColorValue(value.border, colorOptions)
3345
- };
3346
- }
3347
- function renderThemeColorAvatar(value, options) {
3348
- const colorAvatar = {};
3349
- for (const hue of COLOR_HUES)
3350
- colorAvatar[hue] = renderThemeColorAvatarColor(value[hue], options);
3351
- return colorAvatar;
3352
- }
3353
- function renderThemeColorAvatarColor(value, options) {
3354
- const {
3355
- baseBg,
3356
- blendMode: rootBlendMode,
3357
- colorPalette
3358
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3359
- bg: baseBg,
3360
- blendMode: rootBlendMode,
3361
- colorPalette
3362
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3363
- bg,
3364
- blendMode,
3365
- colorPalette
3366
- };
3367
- return {
3368
- _blend: blendMode,
3369
- bg,
3370
- fg: renderColorValue(value.fg, colorOptions)
3371
- };
3372
- }
3373
- function renderThemeColorBadge(value, options) {
3374
- const colorBadge = {};
3375
- for (const tone of THEME_COLOR_STATE_TONES)
3376
- colorBadge[tone] = renderThemeColorBadgeColor(value[tone], options);
3377
- return colorBadge;
3378
- }
3379
- function renderThemeColorBadgeColor(value, options) {
3380
- const {
3381
- baseBg,
3382
- blendMode: rootBlendMode,
3383
- colorPalette
3384
- } = options, blendMode = rootBlendMode, rootOptions = {
3385
- bg: baseBg,
3386
- blendMode: rootBlendMode,
3387
- colorPalette
3388
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3389
- bg,
3390
- blendMode,
3391
- colorPalette
3392
- };
3393
- return {
3394
- bg,
3395
- dot: renderColorValue(value.dot, colorOptions),
3396
- fg: renderColorValue(value.fg, colorOptions),
3397
- icon: renderColorValue(value.icon, colorOptions)
3398
- };
3399
- }
3400
- function renderThemeColorButton(value, options) {
3401
- return {
3402
- default: renderThemeColorButtonTones(value.default, options),
3403
- ghost: renderThemeColorButtonTones(value.ghost, options),
3404
- bleed: renderThemeColorButtonTones(value.bleed, options)
3405
- };
3406
- }
3407
- function renderThemeColorButtonTones(value, options) {
3408
- const colorButtonMode = {};
3409
- for (const tone of THEME_COLOR_STATE_TONES)
3410
- colorButtonMode[tone] = renderThemeColorButtonStates(value[tone], options);
3411
- return colorButtonMode;
3412
- }
3413
- function renderThemeColorButtonStates(value, options) {
3414
- return {
3415
- enabled: renderThemeColorState(value.enabled, options),
3416
- hovered: renderThemeColorState(value.hovered, options),
3417
- pressed: renderThemeColorState(value.pressed, options),
3418
- selected: renderThemeColorState(value.selected, options),
3419
- disabled: renderThemeColorState(value.disabled, options)
3420
- };
3421
- }
3422
- function renderThemeColorState(value, options) {
3423
- const {
3424
- baseBg,
3425
- blendMode: rootBlendMode,
3426
- colorPalette
3427
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3428
- bg: baseBg,
3429
- blendMode: rootBlendMode,
3430
- colorPalette
3431
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3432
- bg,
3433
- blendMode,
3434
- colorPalette
3435
- };
3436
- return {
3437
- _blend: blendMode,
3438
- accent: {
3439
- fg: renderColorValue(value.accent.fg, colorOptions)
3440
- },
3441
- avatar: renderThemeColorAvatar(value.avatar, {
3442
- baseBg: bg,
3443
- colorPalette,
3444
- blendMode
3445
- }),
3446
- badge: renderThemeColorBadge(value.badge, {
3447
- baseBg: bg,
3448
- colorPalette,
3449
- blendMode
3450
- }),
3451
- bg,
3452
- border: renderColorValue(value.border, colorOptions),
3453
- code: {
3454
- bg: renderColorValue(value.code.bg, colorOptions),
3455
- fg: renderColorValue(value.code.fg, colorOptions)
3456
- },
3457
- fg: renderColorValue(value.fg, colorOptions),
3458
- icon: renderColorValue(value.icon, colorOptions),
3459
- link: {
3460
- fg: renderColorValue(value.link.fg, colorOptions)
3461
- },
3462
- muted: {
3463
- bg: renderColorValue(value.muted.bg, colorOptions),
3464
- fg: renderColorValue(value.muted.fg, colorOptions)
3465
- },
3466
- kbd: {
3467
- bg: renderColorValue(value.kbd.bg, colorOptions),
3468
- fg: renderColorValue(value.kbd.fg, colorOptions),
3469
- border: renderColorValue(value.kbd.border, colorOptions)
3470
- },
3471
- skeleton: {
3472
- from: renderColorValue(value.skeleton?.from, colorOptions),
3473
- to: renderColorValue(value.skeleton?.to, colorOptions)
3474
- }
3475
- };
3476
- }
3477
- function renderThemeColorInput(value, options) {
3478
- return {
3479
- default: renderInputStatesColorTheme(value.default, options),
3480
- invalid: renderInputStatesColorTheme(value.invalid, options)
3481
- };
3482
- }
3483
- function renderInputStatesColorTheme(value, options) {
3484
- return {
3485
- enabled: renderInputStateColorTheme(value.enabled, options),
3486
- hovered: renderInputStateColorTheme(value.hovered, options),
3487
- readOnly: renderInputStateColorTheme(value.readOnly, options),
3488
- disabled: renderInputStateColorTheme(value.disabled, options)
3489
- };
3490
- }
3491
- function renderInputStateColorTheme(value, options) {
3492
- const {
3493
- baseBg,
3494
- blendMode: rootBlendMode,
3495
- colorPalette
3496
- } = options, blendMode = value._blend || "multiply", rootOptions = {
3497
- colorPalette,
3498
- bg: baseBg,
3499
- blendMode: rootBlendMode
3500
- }, bg = renderColorValue(value.bg, rootOptions), colorOptions = {
3501
- colorPalette,
3502
- bg,
3503
- blendMode
3504
- };
3505
- return {
3506
- _blend: blendMode,
3507
- bg,
3508
- border: renderColorValue(value.border, colorOptions),
3509
- fg: renderColorValue(value.fg, colorOptions),
3510
- muted: {
3511
- bg: renderColorValue(value.muted.bg, colorOptions)
3512
- },
3513
- placeholder: renderColorValue(value.placeholder, colorOptions)
3514
- };
3515
- }
3516
- function renderThemeColorSelectable(value, options) {
3517
- const colorSelectable = {};
3518
- for (const tone of THEME_COLOR_STATE_TONES)
3519
- colorSelectable[tone] = renderThemeColorSelectableStates(value[tone], options);
3520
- return colorSelectable;
3521
- }
3522
- function renderThemeColorSelectableStates(value, options) {
3523
- return {
3524
- enabled: renderThemeColorState(value.enabled, options),
3525
- hovered: renderThemeColorState(value.hovered, options),
3526
- pressed: renderThemeColorState(value.pressed, options),
3527
- selected: renderThemeColorState(value.selected, options),
3528
- disabled: renderThemeColorState(value.disabled, options)
3529
- };
3530
- }
3531
- function renderSyntaxColorTheme(value, options) {
3532
- const {
3533
- colorPalette,
3534
- baseBg,
3535
- blendMode
3536
- } = options, colorOptions = {
3537
- colorPalette,
3538
- bg: baseBg,
3539
- blendMode
3540
- };
3541
- return {
3542
- atrule: renderColorValue(value.atrule, colorOptions),
3543
- attrName: renderColorValue(value.attrName, colorOptions),
3544
- attrValue: renderColorValue(value.attrValue, colorOptions),
3545
- attribute: renderColorValue(value.attribute, colorOptions),
3546
- boolean: renderColorValue(value.boolean, colorOptions),
3547
- builtin: renderColorValue(value.builtin, colorOptions),
3548
- cdata: renderColorValue(value.cdata, colorOptions),
3549
- char: renderColorValue(value.char, colorOptions),
3550
- class: renderColorValue(value.class, colorOptions),
3551
- className: renderColorValue(value.className, colorOptions),
3552
- comment: renderColorValue(value.comment, colorOptions),
3553
- constant: renderColorValue(value.constant, colorOptions),
3554
- deleted: renderColorValue(value.deleted, colorOptions),
3555
- doctype: renderColorValue(value.doctype, colorOptions),
3556
- entity: renderColorValue(value.entity, colorOptions),
3557
- function: renderColorValue(value.function, colorOptions),
3558
- hexcode: renderColorValue(value.hexcode, colorOptions),
3559
- id: renderColorValue(value.id, colorOptions),
3560
- important: renderColorValue(value.important, colorOptions),
3561
- inserted: renderColorValue(value.inserted, colorOptions),
3562
- keyword: renderColorValue(value.keyword, colorOptions),
3563
- number: renderColorValue(value.number, colorOptions),
3564
- operator: renderColorValue(value.operator, colorOptions),
3565
- prolog: renderColorValue(value.prolog, colorOptions),
3566
- property: renderColorValue(value.property, colorOptions),
3567
- pseudoClass: renderColorValue(value.pseudoClass, colorOptions),
3568
- pseudoElement: renderColorValue(value.pseudoElement, colorOptions),
3569
- punctuation: renderColorValue(value.punctuation, colorOptions),
3570
- regex: renderColorValue(value.regex, colorOptions),
3571
- selector: renderColorValue(value.selector, colorOptions),
3572
- string: renderColorValue(value.string, colorOptions),
3573
- symbol: renderColorValue(value.symbol, colorOptions),
3574
- tag: renderColorValue(value.tag, colorOptions),
3575
- unit: renderColorValue(value.unit, colorOptions),
3576
- url: renderColorValue(value.url, colorOptions),
3577
- variable: renderColorValue(value.variable, colorOptions)
3578
- };
3579
- }
3580
- function buildTheme(config) {
3581
- const colorTheme = buildColorTheme(config), v2 = {
3582
- _version: 2,
3583
- avatar: config?.avatar ?? defaultThemeConfig.avatar,
3584
- button: config?.button ?? defaultThemeConfig.button,
3585
- card: config?.card ?? defaultThemeConfig.card,
3586
- // How colors are generated:
3587
- // 1. Merge custom tokens with default tokens
3588
- // 2. Generate tree of color keys (gray/500, black, white, etc.)
3589
- // 3. Apply mixing and render to hex values
3590
- // render(build(mergeWithDefaults()))
3591
- color: renderThemeColorSchemes(colorTheme, config),
3592
- container: config?.container ?? defaultThemeConfig.container,
3593
- font: config?.font ?? defaultThemeFonts,
3594
- input: config?.input ?? defaultThemeConfig.input,
3595
- layer: config?.layer ?? defaultThemeConfig.layer,
3596
- media: config?.media ?? defaultThemeConfig.media,
3597
- radius: config?.radius ?? defaultThemeConfig.radius,
3598
- shadow: config?.shadow ?? defaultThemeConfig.shadow,
3599
- space: config?.space ?? defaultThemeConfig.space,
3600
- style: config?.style ?? defaultThemeConfig.style
3601
- };
3602
- return v2_v0(v2);
3603
- }
3604
- function themeColor_v0_v2_9(color2) {
3605
- if ("neutral" in color2.badge)
3606
- return color2;
3607
- const colors2 = color2;
3608
- return {
3609
- ...colors2,
3610
- badge: {
3611
- ...colors2.badge,
3612
- neutral: colors2.badge.default,
3613
- suggest: colors2.badge.primary
3614
- },
3615
- button: {
3616
- bleed: {
3617
- ...colors2.button.bleed,
3618
- neutral: colors2.button.bleed.default,
3619
- suggest: colors2.button.bleed.primary
3620
- },
3621
- default: {
3622
- ...colors2.button.default,
3623
- neutral: colors2.button.default.default,
3624
- suggest: colors2.button.default.primary
3625
- },
3626
- ghost: {
3627
- ...colors2.button.ghost,
3628
- neutral: colors2.button.ghost.default,
3629
- suggest: colors2.button.ghost.primary
3630
- }
3631
- },
3632
- selectable: {
3633
- ...colors2.selectable,
3634
- neutral: colors2.selectable.default,
3635
- suggest: colors2.selectable.primary
3636
- }
3637
- };
3638
- }
3639
- const cache = /* @__PURE__ */ new Map();
3640
- function getScopedTheme(themeProp, scheme, tone) {
3641
- const cachedTheme = _getCachedTheme(themeProp, scheme, tone);
3642
- if (cachedTheme) return cachedTheme;
3643
- 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, color_v2_9 = themeColor_v0_v2_9(color_v2), layer_v2 = v2.layer || defaultThemeConfig.layer, theme = {
3644
- sanity: {
3645
- ...v0,
3646
- color: color_v0,
3647
- layer: layer_v0,
3648
- v2: {
3649
- ...v2,
3650
- _resolved: !0,
3651
- color: color_v2_9,
3652
- layer: layer_v2
3653
- }
3654
- }
3655
- };
3656
- return _setCachedTheme(themeProp, scheme, tone, theme), theme;
3657
- }
3658
- function _getCachedTheme(rootTheme, scheme, tone) {
3659
- const schemeCache = cache.get(scheme);
3660
- if (!schemeCache) return;
3661
- const toneCache = schemeCache.get(tone);
3662
- if (toneCache)
3663
- return toneCache.get(rootTheme);
3664
- }
3665
- function _setCachedTheme(rootTheme, scheme, tone, theme) {
3666
- cache.has(scheme) || cache.set(scheme, /* @__PURE__ */ new Map());
3667
- const schemeCache = cache.get(scheme);
3668
- schemeCache.has(tone) || schemeCache.set(tone, /* @__PURE__ */ new WeakMap()), schemeCache.get(tone).set(rootTheme, theme);
3669
- }
3670
- export {
3671
- COLOR_CONFIG_AVATAR_COLORS,
3672
- COLOR_CONFIG_BLEND_KEYS,
3673
- COLOR_CONFIG_CARD_KEYS,
3674
- COLOR_CONFIG_CARD_TONES,
3675
- COLOR_CONFIG_INPUT_MODES,
3676
- COLOR_CONFIG_INPUT_STATES,
3677
- COLOR_CONFIG_STATES,
3678
- COLOR_CONFIG_STATE_KEYS,
3679
- COLOR_CONFIG_STATE_TONES,
3680
- THEME_COLOR_AVATAR_COLORS,
3681
- THEME_COLOR_BLEND_MODES,
3682
- THEME_COLOR_BUTTON_MODES,
3683
- THEME_COLOR_CARD_TONES,
3684
- THEME_COLOR_INPUT_MODES,
3685
- THEME_COLOR_INPUT_STATES,
3686
- THEME_COLOR_SCHEMES,
3687
- THEME_COLOR_STATES,
3688
- THEME_COLOR_STATE_TONES,
3689
- buildTheme,
3690
- createColorTheme,
3691
- getContrastRatio,
3692
- getScopedTheme,
3693
- getTheme_v2,
3694
- hexToRgb,
3695
- hslToRgb,
3696
- isColorBlendModeValue,
3697
- isColorButtonMode,
3698
- isColorConfigBaseKey,
3699
- isColorConfigBaseTone,
3700
- isColorConfigBlendKey,
3701
- isColorConfigStateKey,
3702
- isColorConfigStateTone,
3703
- isColorHueKey,
3704
- isColorOpacityValue,
3705
- isColorTintKey,
3706
- isColorTokenValue,
3707
- isColorValue,
3708
- is_v0,
3709
- is_v2,
3710
- mix,
3711
- multiply,
3712
- parseColor,
3713
- parseTokenKey,
3714
- parseTokenValue,
3715
- rgbToHex,
3716
- rgbToHsl,
3717
- rgba,
3718
- rgbaToRGBA,
3719
- screen,
3720
- v0_v2,
3721
- v2_v0
3722
- };
3723
- //# sourceMappingURL=theme.esm.js.map