@tbela99/css-parser 0.0.1-alpha3

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/index.cjs ADDED
@@ -0,0 +1,3896 @@
1
+ 'use strict';
2
+
3
+ var promises = require('fs/promises');
4
+
5
+ // https://www.w3.org/TR/CSS21/syndata.html#syntax
6
+ // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
7
+ // '\\'
8
+ const REVERSE_SOLIDUS = 0x5c;
9
+ function isLength(dimension) {
10
+ return 'unit' in dimension && [
11
+ 'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
12
+ 'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
13
+ 'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
14
+ 'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
15
+ ].includes(dimension.unit.toLowerCase());
16
+ }
17
+ function isResolution(dimension) {
18
+ return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
19
+ }
20
+ function isAngle(dimension) {
21
+ return 'unit' in dimension && ['rad', 'turn', 'deg', 'grad'].includes(dimension.unit.toLowerCase());
22
+ }
23
+ function isTime(dimension) {
24
+ return 'unit' in dimension && ['ms', 's'].includes(dimension.unit.toLowerCase());
25
+ }
26
+ function isFrequency(dimension) {
27
+ return 'unit' in dimension && ['hz', 'khz'].includes(dimension.unit.toLowerCase());
28
+ }
29
+ function isLetter(codepoint) {
30
+ // lowercase
31
+ return (codepoint >= 0x61 && codepoint <= 0x7a) ||
32
+ // uppercase
33
+ (codepoint >= 0x41 && codepoint <= 0x5a);
34
+ }
35
+ function isNonAscii(codepoint) {
36
+ return codepoint >= 0x80;
37
+ }
38
+ function isIdentStart(codepoint) {
39
+ // _
40
+ return codepoint == 0x5f || isLetter(codepoint) || isNonAscii(codepoint);
41
+ }
42
+ function isDigit(codepoint) {
43
+ return codepoint >= 0x30 && codepoint <= 0x39;
44
+ }
45
+ function isIdentCodepoint(codepoint) {
46
+ // -
47
+ return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
48
+ }
49
+ function isIdent(name) {
50
+ const j = name.length - 1;
51
+ let i = 0;
52
+ let codepoint = name.charCodeAt(0);
53
+ // -
54
+ if (codepoint == 0x2d) {
55
+ const nextCodepoint = name.charCodeAt(1);
56
+ if (nextCodepoint == null) {
57
+ return false;
58
+ }
59
+ // -
60
+ if (nextCodepoint == 0x2d) {
61
+ return true;
62
+ }
63
+ if (nextCodepoint == REVERSE_SOLIDUS) {
64
+ return name.length > 2 && !isNewLine(name.charCodeAt(2));
65
+ }
66
+ return true;
67
+ }
68
+ if (!isIdentStart(codepoint)) {
69
+ return false;
70
+ }
71
+ while (i < j) {
72
+ i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
73
+ codepoint = name.charCodeAt(i);
74
+ if (!isIdentCodepoint(codepoint)) {
75
+ return false;
76
+ }
77
+ }
78
+ return true;
79
+ }
80
+ function isPseudo(name) {
81
+ if (name.charAt(0) != ':') {
82
+ return false;
83
+ }
84
+ if (name.endsWith('(')) {
85
+ return isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1));
86
+ }
87
+ return isIdent(name.charAt(1) == ':' ? name.slice(2) : name.slice(1));
88
+ }
89
+ function isHash(name) {
90
+ if (name.charAt(0) != '#') {
91
+ return false;
92
+ }
93
+ if (isIdent(name.charAt(1))) {
94
+ return true;
95
+ }
96
+ return true;
97
+ }
98
+ function isNumber(name) {
99
+ if (name.length == 0) {
100
+ return false;
101
+ }
102
+ let codepoint = name.charCodeAt(0);
103
+ let i = 0;
104
+ const j = name.length;
105
+ // '+' '-'
106
+ if ([0x2b, 0x2d].includes(codepoint)) {
107
+ i++;
108
+ }
109
+ // consume digits
110
+ while (i < j) {
111
+ codepoint = name.charCodeAt(i);
112
+ if (isDigit(codepoint)) {
113
+ i++;
114
+ continue;
115
+ }
116
+ // '.' 'E' 'e'
117
+ if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
118
+ break;
119
+ }
120
+ return false;
121
+ }
122
+ // '.'
123
+ if (codepoint == 0x2e) {
124
+ if (!isDigit(name.charCodeAt(++i))) {
125
+ return false;
126
+ }
127
+ }
128
+ while (i < j) {
129
+ codepoint = name.charCodeAt(i);
130
+ if (isDigit(codepoint)) {
131
+ i++;
132
+ continue;
133
+ }
134
+ // 'E' 'e'
135
+ if (codepoint == 0x45 || codepoint == 0x65) {
136
+ i++;
137
+ break;
138
+ }
139
+ return false;
140
+ }
141
+ // 'E' 'e'
142
+ if (codepoint == 0x45 || codepoint == 0x65) {
143
+ if (i == j) {
144
+ return false;
145
+ }
146
+ codepoint = name.charCodeAt(i + 1);
147
+ // '+' '-'
148
+ if ([0x2b, 0x2d].includes(codepoint)) {
149
+ i++;
150
+ }
151
+ codepoint = name.charCodeAt(i + 1);
152
+ if (!isDigit(codepoint)) {
153
+ return false;
154
+ }
155
+ }
156
+ while (++i < j) {
157
+ codepoint = name.charCodeAt(i);
158
+ if (!isDigit(codepoint)) {
159
+ return false;
160
+ }
161
+ }
162
+ return true;
163
+ }
164
+ function isDimension(name) {
165
+ let index = 0;
166
+ while (index++ < name.length) {
167
+ if (isDigit(name.charCodeAt(name.length - index))) {
168
+ index--;
169
+ break;
170
+ }
171
+ if (index == 3) {
172
+ break;
173
+ }
174
+ }
175
+ if (index == 0 || index > 3) {
176
+ return false;
177
+ }
178
+ const number = name.slice(0, -index);
179
+ return number.length > 0 && isIdentStart(name.charCodeAt(name.length - index)) && isNumber(number);
180
+ }
181
+ function isPercentage(name) {
182
+ return name.endsWith('%') && isNumber(name.slice(0, -1));
183
+ }
184
+ function parseDimension(name) {
185
+ let index = 0;
186
+ while (index++ < name.length) {
187
+ if (isDigit(name.charCodeAt(name.length - index))) {
188
+ index--;
189
+ break;
190
+ }
191
+ if (index == 3) {
192
+ break;
193
+ }
194
+ }
195
+ const dimension = { typ: 'Dimension', val: name.slice(0, -index), unit: name.slice(-index) };
196
+ if (isAngle(dimension)) {
197
+ // @ts-ignore
198
+ dimension.typ = 'Angle';
199
+ }
200
+ else if (isLength(dimension)) {
201
+ // @ts-ignore
202
+ dimension.typ = 'Length';
203
+ }
204
+ else if (isTime(dimension)) {
205
+ // @ts-ignore
206
+ dimension.typ = 'Time';
207
+ }
208
+ else if (isResolution(dimension)) {
209
+ // @ts-ignore
210
+ dimension.typ = 'Resolution';
211
+ if (dimension.unit == 'dppx') {
212
+ dimension.unit = 'x';
213
+ }
214
+ }
215
+ else if (isFrequency(dimension)) {
216
+ // @ts-ignore
217
+ dimension.typ = 'Frequency';
218
+ }
219
+ return dimension;
220
+ }
221
+ function isHexColor(name) {
222
+ if (name.charAt(0) != '#' || ![4, 5, 7, 9].includes(name.length)) {
223
+ return false;
224
+ }
225
+ for (let chr of name.slice(1)) {
226
+ let codepoint = chr.charCodeAt(0);
227
+ if (!isDigit(codepoint) &&
228
+ // A-F
229
+ !(codepoint >= 0x41 && codepoint <= 0x46) &&
230
+ // a-f
231
+ !(codepoint >= 0x61 && codepoint <= 0x66)) {
232
+ return false;
233
+ }
234
+ }
235
+ return true;
236
+ }
237
+ function isFunction(name) {
238
+ return name.endsWith('(') && isIdent(name.slice(0, -1));
239
+ }
240
+ function isAtKeyword(name) {
241
+ return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
242
+ }
243
+ function isNewLine(codepoint) {
244
+ // \n \r \f
245
+ return codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
246
+ }
247
+ function isWhiteSpace(codepoint) {
248
+ return codepoint == 0x9 || codepoint == 0x20 || isNewLine(codepoint);
249
+ }
250
+
251
+ var properties = {
252
+ inset: {
253
+ shorthand: "inset",
254
+ properties: [
255
+ "top",
256
+ "right",
257
+ "bottom",
258
+ "left"
259
+ ],
260
+ types: [
261
+ "Length",
262
+ "Perc"
263
+ ],
264
+ multiple: false,
265
+ separator: null,
266
+ keywords: [
267
+ "auto"
268
+ ]
269
+ },
270
+ top: {
271
+ shorthand: "inset"
272
+ },
273
+ right: {
274
+ shorthand: "inset"
275
+ },
276
+ bottom: {
277
+ shorthand: "inset"
278
+ },
279
+ left: {
280
+ shorthand: "inset"
281
+ },
282
+ margin: {
283
+ shorthand: "margin",
284
+ properties: [
285
+ "margin-top",
286
+ "margin-right",
287
+ "margin-bottom",
288
+ "margin-left"
289
+ ],
290
+ types: [
291
+ "Length",
292
+ "Perc"
293
+ ],
294
+ multiple: false,
295
+ separator: null,
296
+ keywords: [
297
+ "auto"
298
+ ]
299
+ },
300
+ "margin-top": {
301
+ shorthand: "margin"
302
+ },
303
+ "margin-right": {
304
+ shorthand: "margin"
305
+ },
306
+ "margin-bottom": {
307
+ shorthand: "margin"
308
+ },
309
+ "margin-left": {
310
+ shorthand: "margin"
311
+ },
312
+ padding: {
313
+ shorthand: "padding",
314
+ properties: [
315
+ "padding-top",
316
+ "padding-right",
317
+ "padding-bottom",
318
+ "padding-left"
319
+ ],
320
+ types: [
321
+ "Length",
322
+ "Perc"
323
+ ],
324
+ keywords: [
325
+ ]
326
+ },
327
+ "padding-top": {
328
+ shorthand: "padding"
329
+ },
330
+ "padding-right": {
331
+ shorthand: "padding"
332
+ },
333
+ "padding-bottom": {
334
+ shorthand: "padding"
335
+ },
336
+ "padding-left": {
337
+ shorthand: "padding"
338
+ },
339
+ "border-radius": {
340
+ shorthand: "border-radius",
341
+ properties: [
342
+ "border-top-left-radius",
343
+ "border-top-right-radius",
344
+ "border-bottom-right-radius",
345
+ "border-bottom-left-radius"
346
+ ],
347
+ types: [
348
+ "Length",
349
+ "Perc"
350
+ ],
351
+ multiple: true,
352
+ separator: "/",
353
+ keywords: [
354
+ ]
355
+ },
356
+ "border-top-left-radius": {
357
+ shorthand: "border-radius"
358
+ },
359
+ "border-top-right-radius": {
360
+ shorthand: "border-radius"
361
+ },
362
+ "border-bottom-right-radius": {
363
+ shorthand: "border-radius"
364
+ },
365
+ "border-bottom-left-radius": {
366
+ shorthand: "border-radius"
367
+ },
368
+ "border-width": {
369
+ shorthand: "border-width",
370
+ properties: [
371
+ "border-top-width",
372
+ "border-right-width",
373
+ "border-bottom-width",
374
+ "border-left-width"
375
+ ],
376
+ types: [
377
+ "Length",
378
+ "Perc"
379
+ ],
380
+ keywords: [
381
+ "thin",
382
+ "medium",
383
+ "thick"
384
+ ]
385
+ },
386
+ "border-top-width": {
387
+ shorthand: "border-width"
388
+ },
389
+ "border-right-width": {
390
+ shorthand: "border-width"
391
+ },
392
+ "border-bottom-width": {
393
+ shorthand: "border-width"
394
+ },
395
+ "border-left-width": {
396
+ shorthand: "border-width"
397
+ },
398
+ "border-style": {
399
+ shorthand: "border-style",
400
+ properties: [
401
+ "border-top-style",
402
+ "border-right-style",
403
+ "border-bottom-style",
404
+ "border-left-style"
405
+ ],
406
+ types: [
407
+ ],
408
+ keywords: [
409
+ "none",
410
+ "hidden",
411
+ "dotted",
412
+ "dashed",
413
+ "solid",
414
+ "double",
415
+ "groove",
416
+ "ridge",
417
+ "inset",
418
+ "outset"
419
+ ]
420
+ },
421
+ "border-top-style": {
422
+ shorthand: "border-style"
423
+ },
424
+ "border-right-style": {
425
+ shorthand: "border-style"
426
+ },
427
+ "border-bottom-style": {
428
+ shorthand: "border-style"
429
+ },
430
+ "border-left-style": {
431
+ shorthand: "border-style"
432
+ },
433
+ "border-color": {
434
+ shorthand: "border-color",
435
+ properties: [
436
+ "border-top-color",
437
+ "border-right-color",
438
+ "border-bottom-color",
439
+ "border-left-color"
440
+ ],
441
+ types: [
442
+ "Color"
443
+ ],
444
+ keywords: [
445
+ ]
446
+ },
447
+ "border-top-color": {
448
+ shorthand: "border-color"
449
+ },
450
+ "border-right-color": {
451
+ shorthand: "border-color"
452
+ },
453
+ "border-bottom-color": {
454
+ shorthand: "border-color"
455
+ },
456
+ "border-left-color": {
457
+ shorthand: "border-color"
458
+ }
459
+ };
460
+ var map = {
461
+ outline: {
462
+ shorthand: "outline",
463
+ pattern: "outline-color outline-style outline-width",
464
+ keywords: [
465
+ "none"
466
+ ],
467
+ "default": [
468
+ "0",
469
+ "none"
470
+ ],
471
+ properties: {
472
+ "outline-color": {
473
+ types: [
474
+ "Color"
475
+ ],
476
+ "default": [
477
+ "currentColor",
478
+ "invert"
479
+ ],
480
+ keywords: [
481
+ "currentColor",
482
+ "invert"
483
+ ]
484
+ },
485
+ "outline-style": {
486
+ types: [
487
+ ],
488
+ "default": [
489
+ "none"
490
+ ],
491
+ keywords: [
492
+ "auto",
493
+ "none",
494
+ "dotted",
495
+ "dashed",
496
+ "solid",
497
+ "double",
498
+ "groove",
499
+ "ridge",
500
+ "inset",
501
+ "outset"
502
+ ]
503
+ },
504
+ "outline-width": {
505
+ types: [
506
+ "Length",
507
+ "Perc"
508
+ ],
509
+ "default": [
510
+ "medium"
511
+ ],
512
+ keywords: [
513
+ "thin",
514
+ "medium",
515
+ "thick"
516
+ ]
517
+ }
518
+ }
519
+ },
520
+ "outline-color": {
521
+ shorthand: "outline"
522
+ },
523
+ "outline-style": {
524
+ shorthand: "outline"
525
+ },
526
+ "outline-width": {
527
+ shorthand: "outline"
528
+ },
529
+ font: {
530
+ shorthand: "font",
531
+ pattern: "font-weight font-style font-size line-height font-stretch font-variant font-family",
532
+ keywords: [
533
+ "caption",
534
+ "icon",
535
+ "menu",
536
+ "message-box",
537
+ "small-caption",
538
+ "status-bar",
539
+ "-moz-window, ",
540
+ "-moz-document, ",
541
+ "-moz-desktop, ",
542
+ "-moz-info, ",
543
+ "-moz-dialog",
544
+ "-moz-button",
545
+ "-moz-pull-down-menu",
546
+ "-moz-list",
547
+ "-moz-field"
548
+ ],
549
+ "default": [
550
+ ],
551
+ properties: {
552
+ "font-weight": {
553
+ types: [
554
+ "Number"
555
+ ],
556
+ "default": [
557
+ "normal",
558
+ "400"
559
+ ],
560
+ keywords: [
561
+ "normal",
562
+ "bold",
563
+ "lighter",
564
+ "bolder"
565
+ ],
566
+ constraints: {
567
+ value: {
568
+ min: "1",
569
+ max: "1000"
570
+ }
571
+ },
572
+ mapping: {
573
+ thin: "100",
574
+ hairline: "100",
575
+ "extra light": "200",
576
+ "ultra light": "200",
577
+ light: "300",
578
+ normal: "400",
579
+ regular: "400",
580
+ medium: "500",
581
+ "semi bold": "600",
582
+ "demi bold": "600",
583
+ bold: "700",
584
+ "extra bold": "800",
585
+ "ultra bold": "800",
586
+ black: "900",
587
+ heavy: "900",
588
+ "extra black": "950",
589
+ "ultra black": "950"
590
+ }
591
+ },
592
+ "font-style": {
593
+ types: [
594
+ "Angle"
595
+ ],
596
+ "default": [
597
+ "normal"
598
+ ],
599
+ keywords: [
600
+ "normal",
601
+ "italic",
602
+ "oblique"
603
+ ]
604
+ },
605
+ "font-size": {
606
+ types: [
607
+ "Length",
608
+ "Perc"
609
+ ],
610
+ "default": [
611
+ ],
612
+ keywords: [
613
+ "xx-small",
614
+ "x-small",
615
+ "small",
616
+ "medium",
617
+ "large",
618
+ "x-large",
619
+ "xx-large",
620
+ "xxx-large",
621
+ "larger",
622
+ "smaller"
623
+ ],
624
+ required: true
625
+ },
626
+ "line-height": {
627
+ types: [
628
+ "Length",
629
+ "Perc",
630
+ "Number"
631
+ ],
632
+ "default": [
633
+ "normal"
634
+ ],
635
+ keywords: [
636
+ "normal"
637
+ ],
638
+ previous: "font-size",
639
+ prefix: {
640
+ typ: "Literal",
641
+ val: "/"
642
+ }
643
+ },
644
+ "font-stretch": {
645
+ types: [
646
+ "Perc"
647
+ ],
648
+ "default": [
649
+ "normal"
650
+ ],
651
+ keywords: [
652
+ "ultra-condensed",
653
+ "extra-condensed",
654
+ "condensed",
655
+ "semi-condensed",
656
+ "normal",
657
+ "semi-expanded",
658
+ "expanded",
659
+ "extra-expanded",
660
+ "ultra-expanded"
661
+ ],
662
+ mapping: {
663
+ "ultra-condensed": "50%",
664
+ "extra-condensed": "62.5%",
665
+ condensed: "75%",
666
+ "semi-condensed": "87.5%",
667
+ normal: "100%",
668
+ "semi-expanded": "112.5%",
669
+ expanded: "125%",
670
+ "extra-expanded": "150%",
671
+ "ultra-expanded": "200%"
672
+ }
673
+ },
674
+ "font-variant": {
675
+ types: [
676
+ ],
677
+ "default": [
678
+ "normal"
679
+ ],
680
+ keywords: [
681
+ "normal",
682
+ "none",
683
+ "common-ligatures",
684
+ "no-common-ligatures",
685
+ "discretionary-ligatures",
686
+ "no-discretionary-ligatures",
687
+ "historical-ligatures",
688
+ "no-historical-ligatures",
689
+ "contextual",
690
+ "no-contextual",
691
+ "historical-forms",
692
+ "small-caps",
693
+ "all-small-caps",
694
+ "petite-caps",
695
+ "all-petite-caps",
696
+ "unicase",
697
+ "titling-caps",
698
+ "ordinal",
699
+ "slashed-zero",
700
+ "lining-nums",
701
+ "oldstyle-nums",
702
+ "proportional-nums",
703
+ "tabular-nums",
704
+ "diagonal-fractions",
705
+ "stacked-fractions",
706
+ "ordinal",
707
+ "slashed-zero",
708
+ "ruby",
709
+ "jis78",
710
+ "jis83",
711
+ "jis90",
712
+ "jis04",
713
+ "simplified",
714
+ "traditional",
715
+ "full-width",
716
+ "proportional-width",
717
+ "ruby",
718
+ "sub",
719
+ "super",
720
+ "text",
721
+ "emoji",
722
+ "unicode"
723
+ ]
724
+ },
725
+ "font-family": {
726
+ types: [
727
+ "String",
728
+ "Iden"
729
+ ],
730
+ "default": [
731
+ ],
732
+ keywords: [
733
+ "serif",
734
+ "sans-serif",
735
+ "monospace",
736
+ "cursive",
737
+ "fantasy",
738
+ "system-ui",
739
+ "ui-serif",
740
+ "ui-sans-serif",
741
+ "ui-monospace",
742
+ "ui-rounded",
743
+ "math",
744
+ "emoji",
745
+ "fangsong"
746
+ ],
747
+ required: true,
748
+ multiple: true,
749
+ separator: {
750
+ typ: "Comma"
751
+ }
752
+ }
753
+ }
754
+ },
755
+ "font-weight": {
756
+ shorthand: "font"
757
+ },
758
+ "font-style": {
759
+ shorthand: "font"
760
+ },
761
+ "font-size": {
762
+ shorthand: "font"
763
+ },
764
+ "line-height": {
765
+ shorthand: "font"
766
+ },
767
+ "font-stretch": {
768
+ shorthand: "font"
769
+ },
770
+ "font-variant": {
771
+ shorthand: "font"
772
+ },
773
+ "font-family": {
774
+ shorthand: "font"
775
+ },
776
+ background: {
777
+ shorthand: "background",
778
+ pattern: "background-repeat background-color background-image background-attachment background-clip background-origin background-position background-size",
779
+ keywords: [
780
+ "none"
781
+ ],
782
+ "default": [
783
+ ],
784
+ multiple: true,
785
+ separator: {
786
+ typ: "Comma"
787
+ },
788
+ properties: {
789
+ "background-repeat": {
790
+ types: [
791
+ ],
792
+ "default": [
793
+ "repeat"
794
+ ],
795
+ multiple: true,
796
+ keywords: [
797
+ "repeat-x",
798
+ "repeat-y",
799
+ "repeat",
800
+ "space",
801
+ "round",
802
+ "no-repeat"
803
+ ],
804
+ mapping: {
805
+ "repeat no-repeat": "repeat-x",
806
+ "no-repeat repeat": "repeat-y",
807
+ "repeat repeat": "repeat",
808
+ "space space": "space",
809
+ "round round": "round",
810
+ "no-repeat no-repeat": "no-repeat"
811
+ }
812
+ },
813
+ "background-color": {
814
+ types: [
815
+ "Color"
816
+ ],
817
+ "default": [
818
+ "transparent"
819
+ ],
820
+ keywords: [
821
+ ]
822
+ },
823
+ "background-image": {
824
+ types: [
825
+ "UrlFunc"
826
+ ],
827
+ "default": [
828
+ "none"
829
+ ],
830
+ keywords: [
831
+ "none"
832
+ ]
833
+ },
834
+ "background-attachment": {
835
+ types: [
836
+ ],
837
+ "default": [
838
+ "scroll"
839
+ ],
840
+ keywords: [
841
+ "scroll",
842
+ "fixed",
843
+ "local"
844
+ ]
845
+ },
846
+ "background-clip": {
847
+ types: [
848
+ ],
849
+ "default": [
850
+ "border-box"
851
+ ],
852
+ keywords: [
853
+ "border-box",
854
+ "padding-box",
855
+ "content-box",
856
+ "text"
857
+ ]
858
+ },
859
+ "background-origin": {
860
+ types: [
861
+ ],
862
+ "default": [
863
+ "padding-box"
864
+ ],
865
+ keywords: [
866
+ "border-box",
867
+ "padding-box",
868
+ "content-box"
869
+ ]
870
+ },
871
+ "background-position": {
872
+ multiple: true,
873
+ types: [
874
+ "Perc",
875
+ "Length"
876
+ ],
877
+ "default": [
878
+ "0 0",
879
+ "top left",
880
+ "left top"
881
+ ],
882
+ keywords: [
883
+ "top",
884
+ "left",
885
+ "center",
886
+ "bottom",
887
+ "right"
888
+ ],
889
+ mapping: {
890
+ left: "0",
891
+ top: "0",
892
+ center: "50%",
893
+ bottom: "100%",
894
+ right: "100%"
895
+ },
896
+ constraints: {
897
+ mapping: {
898
+ max: 2
899
+ }
900
+ }
901
+ },
902
+ "background-size": {
903
+ multiple: true,
904
+ previous: "background-position",
905
+ prefix: {
906
+ typ: "Literal",
907
+ val: "/"
908
+ },
909
+ types: [
910
+ "Perc",
911
+ "Length"
912
+ ],
913
+ "default": [
914
+ "auto",
915
+ "auto auto"
916
+ ],
917
+ keywords: [
918
+ "auto",
919
+ "cover",
920
+ "contain"
921
+ ],
922
+ mapping: {
923
+ "auto auto": "auto"
924
+ }
925
+ }
926
+ }
927
+ },
928
+ "background-repeat": {
929
+ shorthand: "background"
930
+ },
931
+ "background-color": {
932
+ shorthand: "background"
933
+ },
934
+ "background-image": {
935
+ shorthand: "background"
936
+ },
937
+ "background-attachment": {
938
+ shorthand: "background"
939
+ },
940
+ "background-clip": {
941
+ shorthand: "background"
942
+ },
943
+ "background-origin": {
944
+ shorthand: "background"
945
+ },
946
+ "background-position": {
947
+ shorthand: "background"
948
+ },
949
+ "background-size": {
950
+ shorthand: "background"
951
+ }
952
+ };
953
+ var config$1 = {
954
+ properties: properties,
955
+ map: map
956
+ };
957
+
958
+ const getConfig = () => config$1;
959
+
960
+ // name to color
961
+ const COLORS_NAMES = Object.seal({
962
+ 'aliceblue': '#f0f8ff',
963
+ 'antiquewhite': '#faebd7',
964
+ 'aqua': '#00ffff',
965
+ 'aquamarine': '#7fffd4',
966
+ 'azure': '#f0ffff',
967
+ 'beige': '#f5f5dc',
968
+ 'bisque': '#ffe4c4',
969
+ 'black': '#000000',
970
+ 'blanchedalmond': '#ffebcd',
971
+ 'blue': '#0000ff',
972
+ 'blueviolet': '#8a2be2',
973
+ 'brown': '#a52a2a',
974
+ 'burlywood': '#deb887',
975
+ 'cadetblue': '#5f9ea0',
976
+ 'chartreuse': '#7fff00',
977
+ 'chocolate': '#d2691e',
978
+ 'coral': '#ff7f50',
979
+ 'cornflowerblue': '#6495ed',
980
+ 'cornsilk': '#fff8dc',
981
+ 'crimson': '#dc143c',
982
+ 'cyan': '#00ffff',
983
+ 'darkblue': '#00008b',
984
+ 'darkcyan': '#008b8b',
985
+ 'darkgoldenrod': '#b8860b',
986
+ 'darkgray': '#a9a9a9',
987
+ 'darkgrey': '#a9a9a9',
988
+ 'darkgreen': '#006400',
989
+ 'darkkhaki': '#bdb76b',
990
+ 'darkmagenta': '#8b008b',
991
+ 'darkolivegreen': '#556b2f',
992
+ 'darkorange': '#ff8c00',
993
+ 'darkorchid': '#9932cc',
994
+ 'darkred': '#8b0000',
995
+ 'darksalmon': '#e9967a',
996
+ 'darkseagreen': '#8fbc8f',
997
+ 'darkslateblue': '#483d8b',
998
+ 'darkslategray': '#2f4f4f',
999
+ 'darkslategrey': '#2f4f4f',
1000
+ 'darkturquoise': '#00ced1',
1001
+ 'darkviolet': '#9400d3',
1002
+ 'deeppink': '#ff1493',
1003
+ 'deepskyblue': '#00bfff',
1004
+ 'dimgray': '#696969',
1005
+ 'dimgrey': '#696969',
1006
+ 'dodgerblue': '#1e90ff',
1007
+ 'firebrick': '#b22222',
1008
+ 'floralwhite': '#fffaf0',
1009
+ 'forestgreen': '#228b22',
1010
+ 'fuchsia': '#ff00ff',
1011
+ 'gainsboro': '#dcdcdc',
1012
+ 'ghostwhite': '#f8f8ff',
1013
+ 'gold': '#ffd700',
1014
+ 'goldenrod': '#daa520',
1015
+ 'gray': '#808080',
1016
+ 'grey': '#808080',
1017
+ 'green': '#008000',
1018
+ 'greenyellow': '#adff2f',
1019
+ 'honeydew': '#f0fff0',
1020
+ 'hotpink': '#ff69b4',
1021
+ 'indianred': '#cd5c5c',
1022
+ 'indigo': '#4b0082',
1023
+ 'ivory': '#fffff0',
1024
+ 'khaki': '#f0e68c',
1025
+ 'lavender': '#e6e6fa',
1026
+ 'lavenderblush': '#fff0f5',
1027
+ 'lawngreen': '#7cfc00',
1028
+ 'lemonchiffon': '#fffacd',
1029
+ 'lightblue': '#add8e6',
1030
+ 'lightcoral': '#f08080',
1031
+ 'lightcyan': '#e0ffff',
1032
+ 'lightgoldenrodyellow': '#fafad2',
1033
+ 'lightgray': '#d3d3d3',
1034
+ 'lightgrey': '#d3d3d3',
1035
+ 'lightgreen': '#90ee90',
1036
+ 'lightpink': '#ffb6c1',
1037
+ 'lightsalmon': '#ffa07a',
1038
+ 'lightseagreen': '#20b2aa',
1039
+ 'lightskyblue': '#87cefa',
1040
+ 'lightslategray': '#778899',
1041
+ 'lightslategrey': '#778899',
1042
+ 'lightsteelblue': '#b0c4de',
1043
+ 'lightyellow': '#ffffe0',
1044
+ 'lime': '#00ff00',
1045
+ 'limegreen': '#32cd32',
1046
+ 'linen': '#faf0e6',
1047
+ 'magenta': '#ff00ff',
1048
+ 'maroon': '#800000',
1049
+ 'mediumaquamarine': '#66cdaa',
1050
+ 'mediumblue': '#0000cd',
1051
+ 'mediumorchid': '#ba55d3',
1052
+ 'mediumpurple': '#9370d8',
1053
+ 'mediumseagreen': '#3cb371',
1054
+ 'mediumslateblue': '#7b68ee',
1055
+ 'mediumspringgreen': '#00fa9a',
1056
+ 'mediumturquoise': '#48d1cc',
1057
+ 'mediumvioletred': '#c71585',
1058
+ 'midnightblue': '#191970',
1059
+ 'mintcream': '#f5fffa',
1060
+ 'mistyrose': '#ffe4e1',
1061
+ 'moccasin': '#ffe4b5',
1062
+ 'navajowhite': '#ffdead',
1063
+ 'navy': '#000080',
1064
+ 'oldlace': '#fdf5e6',
1065
+ 'olive': '#808000',
1066
+ 'olivedrab': '#6b8e23',
1067
+ 'orange': '#ffa500',
1068
+ 'orangered': '#ff4500',
1069
+ 'orchid': '#da70d6',
1070
+ 'palegoldenrod': '#eee8aa',
1071
+ 'palegreen': '#98fb98',
1072
+ 'paleturquoise': '#afeeee',
1073
+ 'palevioletred': '#d87093',
1074
+ 'papayawhip': '#ffefd5',
1075
+ 'peachpuff': '#ffdab9',
1076
+ 'peru': '#cd853f',
1077
+ 'pink': '#ffc0cb',
1078
+ 'plum': '#dda0dd',
1079
+ 'powderblue': '#b0e0e6',
1080
+ 'purple': '#800080',
1081
+ 'red': '#ff0000',
1082
+ 'rosybrown': '#bc8f8f',
1083
+ 'royalblue': '#4169e1',
1084
+ 'saddlebrown': '#8b4513',
1085
+ 'salmon': '#fa8072',
1086
+ 'sandybrown': '#f4a460',
1087
+ 'seagreen': '#2e8b57',
1088
+ 'seashell': '#fff5ee',
1089
+ 'sienna': '#a0522d',
1090
+ 'silver': '#c0c0c0',
1091
+ 'skyblue': '#87ceeb',
1092
+ 'slateblue': '#6a5acd',
1093
+ 'slategray': '#708090',
1094
+ 'slategrey': '#708090',
1095
+ 'snow': '#fffafa',
1096
+ 'springgreen': '#00ff7f',
1097
+ 'steelblue': '#4682b4',
1098
+ 'tan': '#d2b48c',
1099
+ 'teal': '#008080',
1100
+ 'thistle': '#d8bfd8',
1101
+ 'tomato': '#ff6347',
1102
+ 'turquoise': '#40e0d0',
1103
+ 'violet': '#ee82ee',
1104
+ 'wheat': '#f5deb3',
1105
+ 'white': '#ffffff',
1106
+ 'whitesmoke': '#f5f5f5',
1107
+ 'yellow': '#ffff00',
1108
+ 'yellowgreen': '#9acd32',
1109
+ 'rebeccapurple': '#663399',
1110
+ 'transparent': '#00000000'
1111
+ });
1112
+ // color to name
1113
+ const NAMES_COLORS = Object.seal({
1114
+ '#f0f8ff': 'aliceblue',
1115
+ '#faebd7': 'antiquewhite',
1116
+ // '#00ffff': 'aqua',
1117
+ '#7fffd4': 'aquamarine',
1118
+ '#f0ffff': 'azure',
1119
+ '#f5f5dc': 'beige',
1120
+ '#ffe4c4': 'bisque',
1121
+ '#000000': 'black',
1122
+ '#ffebcd': 'blanchedalmond',
1123
+ '#0000ff': 'blue',
1124
+ '#8a2be2': 'blueviolet',
1125
+ '#a52a2a': 'brown',
1126
+ '#deb887': 'burlywood',
1127
+ '#5f9ea0': 'cadetblue',
1128
+ '#7fff00': 'chartreuse',
1129
+ '#d2691e': 'chocolate',
1130
+ '#ff7f50': 'coral',
1131
+ '#6495ed': 'cornflowerblue',
1132
+ '#fff8dc': 'cornsilk',
1133
+ '#dc143c': 'crimson',
1134
+ '#00ffff': 'cyan',
1135
+ '#00008b': 'darkblue',
1136
+ '#008b8b': 'darkcyan',
1137
+ '#b8860b': 'darkgoldenrod',
1138
+ // '#a9a9a9': 'darkgray',
1139
+ '#a9a9a9': 'darkgrey',
1140
+ '#006400': 'darkgreen',
1141
+ '#bdb76b': 'darkkhaki',
1142
+ '#8b008b': 'darkmagenta',
1143
+ '#556b2f': 'darkolivegreen',
1144
+ '#ff8c00': 'darkorange',
1145
+ '#9932cc': 'darkorchid',
1146
+ '#8b0000': 'darkred',
1147
+ '#e9967a': 'darksalmon',
1148
+ '#8fbc8f': 'darkseagreen',
1149
+ '#483d8b': 'darkslateblue',
1150
+ // '#2f4f4f': 'darkslategray',
1151
+ '#2f4f4f': 'darkslategrey',
1152
+ '#00ced1': 'darkturquoise',
1153
+ '#9400d3': 'darkviolet',
1154
+ '#ff1493': 'deeppink',
1155
+ '#00bfff': 'deepskyblue',
1156
+ // '#696969': 'dimgray',
1157
+ '#696969': 'dimgrey',
1158
+ '#1e90ff': 'dodgerblue',
1159
+ '#b22222': 'firebrick',
1160
+ '#fffaf0': 'floralwhite',
1161
+ '#228b22': 'forestgreen',
1162
+ // '#ff00ff': 'fuchsia',
1163
+ '#dcdcdc': 'gainsboro',
1164
+ '#f8f8ff': 'ghostwhite',
1165
+ '#ffd700': 'gold',
1166
+ '#daa520': 'goldenrod',
1167
+ // '#808080': 'gray',
1168
+ '#808080': 'grey',
1169
+ '#008000': 'green',
1170
+ '#adff2f': 'greenyellow',
1171
+ '#f0fff0': 'honeydew',
1172
+ '#ff69b4': 'hotpink',
1173
+ '#cd5c5c': 'indianred',
1174
+ '#4b0082': 'indigo',
1175
+ '#fffff0': 'ivory',
1176
+ '#f0e68c': 'khaki',
1177
+ '#e6e6fa': 'lavender',
1178
+ '#fff0f5': 'lavenderblush',
1179
+ '#7cfc00': 'lawngreen',
1180
+ '#fffacd': 'lemonchiffon',
1181
+ '#add8e6': 'lightblue',
1182
+ '#f08080': 'lightcoral',
1183
+ '#e0ffff': 'lightcyan',
1184
+ '#fafad2': 'lightgoldenrodyellow',
1185
+ // '#d3d3d3': 'lightgray',
1186
+ '#d3d3d3': 'lightgrey',
1187
+ '#90ee90': 'lightgreen',
1188
+ '#ffb6c1': 'lightpink',
1189
+ '#ffa07a': 'lightsalmon',
1190
+ '#20b2aa': 'lightseagreen',
1191
+ '#87cefa': 'lightskyblue',
1192
+ // '#778899': 'lightslategray',
1193
+ '#778899': 'lightslategrey',
1194
+ '#b0c4de': 'lightsteelblue',
1195
+ '#ffffe0': 'lightyellow',
1196
+ '#00ff00': 'lime',
1197
+ '#32cd32': 'limegreen',
1198
+ '#faf0e6': 'linen',
1199
+ '#ff00ff': 'magenta',
1200
+ '#800000': 'maroon',
1201
+ '#66cdaa': 'mediumaquamarine',
1202
+ '#0000cd': 'mediumblue',
1203
+ '#ba55d3': 'mediumorchid',
1204
+ '#9370d8': 'mediumpurple',
1205
+ '#3cb371': 'mediumseagreen',
1206
+ '#7b68ee': 'mediumslateblue',
1207
+ '#00fa9a': 'mediumspringgreen',
1208
+ '#48d1cc': 'mediumturquoise',
1209
+ '#c71585': 'mediumvioletred',
1210
+ '#191970': 'midnightblue',
1211
+ '#f5fffa': 'mintcream',
1212
+ '#ffe4e1': 'mistyrose',
1213
+ '#ffe4b5': 'moccasin',
1214
+ '#ffdead': 'navajowhite',
1215
+ '#000080': 'navy',
1216
+ '#fdf5e6': 'oldlace',
1217
+ '#808000': 'olive',
1218
+ '#6b8e23': 'olivedrab',
1219
+ '#ffa500': 'orange',
1220
+ '#ff4500': 'orangered',
1221
+ '#da70d6': 'orchid',
1222
+ '#eee8aa': 'palegoldenrod',
1223
+ '#98fb98': 'palegreen',
1224
+ '#afeeee': 'paleturquoise',
1225
+ '#d87093': 'palevioletred',
1226
+ '#ffefd5': 'papayawhip',
1227
+ '#ffdab9': 'peachpuff',
1228
+ '#cd853f': 'peru',
1229
+ '#ffc0cb': 'pink',
1230
+ '#dda0dd': 'plum',
1231
+ '#b0e0e6': 'powderblue',
1232
+ '#800080': 'purple',
1233
+ '#ff0000': 'red',
1234
+ '#bc8f8f': 'rosybrown',
1235
+ '#4169e1': 'royalblue',
1236
+ '#8b4513': 'saddlebrown',
1237
+ '#fa8072': 'salmon',
1238
+ '#f4a460': 'sandybrown',
1239
+ '#2e8b57': 'seagreen',
1240
+ '#fff5ee': 'seashell',
1241
+ '#a0522d': 'sienna',
1242
+ '#c0c0c0': 'silver',
1243
+ '#87ceeb': 'skyblue',
1244
+ '#6a5acd': 'slateblue',
1245
+ // '#708090': 'slategray',
1246
+ '#708090': 'slategrey',
1247
+ '#fffafa': 'snow',
1248
+ '#00ff7f': 'springgreen',
1249
+ '#4682b4': 'steelblue',
1250
+ '#d2b48c': 'tan',
1251
+ '#008080': 'teal',
1252
+ '#d8bfd8': 'thistle',
1253
+ '#ff6347': 'tomato',
1254
+ '#40e0d0': 'turquoise',
1255
+ '#ee82ee': 'violet',
1256
+ '#f5deb3': 'wheat',
1257
+ '#ffffff': 'white',
1258
+ '#f5f5f5': 'whitesmoke',
1259
+ '#ffff00': 'yellow',
1260
+ '#9acd32': 'yellowgreen',
1261
+ '#663399': 'rebeccapurple',
1262
+ '#00000000': 'transparent'
1263
+ });
1264
+ function rgb2Hex(token) {
1265
+ let value = '#';
1266
+ let t;
1267
+ // @ts-ignore
1268
+ for (let i = 0; i < 6; i += 2) {
1269
+ // @ts-ignore
1270
+ t = token.chi[i];
1271
+ // @ts-ignore
1272
+ value += Math.round(t.typ == 'Perc' ? 255 * t.val / 100 : t.val).toString(16).padStart(2, '0');
1273
+ }
1274
+ // @ts-ignore
1275
+ if (token.chi.length == 7) {
1276
+ // @ts-ignore
1277
+ t = token.chi[6];
1278
+ // @ts-ignore
1279
+ if ((t.typ == 'Number' && t.val < 1) ||
1280
+ // @ts-ignore
1281
+ (t.typ == 'Perc' && t.val < 100)) {
1282
+ // @ts-ignore
1283
+ value += Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)).toString(16).padStart(2, '0');
1284
+ }
1285
+ }
1286
+ return value;
1287
+ }
1288
+ function hsl2Hex(token) {
1289
+ let t;
1290
+ // @ts-ignore
1291
+ let h = getAngle(token.chi[0]);
1292
+ // @ts-ignore
1293
+ t = token.chi[2];
1294
+ // @ts-ignore
1295
+ let s = t.typ == 'Perc' ? t.val / 100 : t.val;
1296
+ // @ts-ignore
1297
+ t = token.chi[4];
1298
+ // @ts-ignore
1299
+ let l = t.typ == 'Perc' ? t.val / 100 : t.val;
1300
+ let a = null;
1301
+ if (token.chi?.length == 7) {
1302
+ // @ts-ignore
1303
+ t = token.chi[6];
1304
+ // @ts-ignore
1305
+ if ((t.typ == 'Perc' && t.val < 100) ||
1306
+ // @ts-ignore
1307
+ (t.typ == 'Number' && t.val < 1)) {
1308
+ // @ts-ignore
1309
+ a = (t.typ == 'Perc' ? t.val / 100 : t.val);
1310
+ }
1311
+ }
1312
+ return `#${hsl2rgb(h, s, l, a).reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
1313
+ }
1314
+ function hwb2hex(token) {
1315
+ let t;
1316
+ // @ts-ignore
1317
+ let h = getAngle(token.chi[0]);
1318
+ // @ts-ignore
1319
+ t = token.chi[2];
1320
+ // @ts-ignore
1321
+ let white = t.typ == 'Perc' ? t.val / 100 : t.val;
1322
+ // @ts-ignore
1323
+ t = token.chi[4];
1324
+ // @ts-ignore
1325
+ let black = t.typ == 'Perc' ? t.val / 100 : t.val;
1326
+ let a = null;
1327
+ if (token.chi?.length == 7) {
1328
+ // @ts-ignore
1329
+ t = token.chi[6];
1330
+ // @ts-ignore
1331
+ if ((t.typ == 'Perc' && t.val < 100) ||
1332
+ // @ts-ignore
1333
+ (t.typ == 'Number' && t.val < 1)) {
1334
+ // @ts-ignore
1335
+ a = (t.typ == 'Perc' ? t.val / 100 : t.val);
1336
+ }
1337
+ }
1338
+ const rgb = hsl2rgb(h, 1, .5, a);
1339
+ let value;
1340
+ for (let i = 0; i < 3; i++) {
1341
+ value = rgb[i] / 255;
1342
+ value *= (1 - white - black);
1343
+ value += white;
1344
+ rgb[i] = Math.round(value * 255);
1345
+ }
1346
+ return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
1347
+ }
1348
+ function cmyk2hex(token) {
1349
+ // @ts-ignore
1350
+ let t = token.chi[0];
1351
+ // @ts-ignore
1352
+ const c = t.typ == 'Perc' ? t.val / 100 : t.val;
1353
+ // @ts-ignore
1354
+ t = token.chi[2];
1355
+ // @ts-ignore
1356
+ const m = t.typ == 'Perc' ? t.val / 100 : t.val;
1357
+ // @ts-ignore
1358
+ t = token.chi[4];
1359
+ // @ts-ignore
1360
+ const y = t.typ == 'Perc' ? t.val / 100 : t.val;
1361
+ // @ts-ignore
1362
+ t = token.chi[6];
1363
+ // @ts-ignore
1364
+ const k = t.typ == 'Perc' ? t.val / 100 : t.val;
1365
+ const rgb = [
1366
+ Math.round(255 * (1 - Math.min(1, c * (1 - k) + k))),
1367
+ Math.round(255 * (1 - Math.min(1, m * (1 - k) + k))),
1368
+ Math.round(255 * (1 - Math.min(1, y * (1 - k) + k)))
1369
+ ];
1370
+ // @ts-ignore
1371
+ if (token.chi.length >= 9) {
1372
+ // @ts-ignore
1373
+ t = token.chi[8];
1374
+ // @ts-ignore
1375
+ rgb.push(Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)));
1376
+ }
1377
+ return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
1378
+ }
1379
+ function getAngle(token) {
1380
+ if (token.typ == 'Dimension') {
1381
+ switch (token.unit) {
1382
+ case 'deg':
1383
+ // @ts-ignore
1384
+ return token.val / 360;
1385
+ case 'rad':
1386
+ // @ts-ignore
1387
+ return token.val / (2 * Math.PI);
1388
+ case 'grad':
1389
+ // @ts-ignore
1390
+ return token.val / 400;
1391
+ case 'turn':
1392
+ // @ts-ignore
1393
+ return +token.val;
1394
+ }
1395
+ }
1396
+ // @ts-ignore
1397
+ return token.val / 360;
1398
+ }
1399
+ function hsl2rgb(h, s, l, a = null) {
1400
+ let v = l <= .5 ? l * (1.0 + s) : l + s - l * s;
1401
+ let r = l;
1402
+ let g = l;
1403
+ let b = l;
1404
+ if (v > 0) {
1405
+ let m = l + l - v;
1406
+ let sv = (v - m) / v;
1407
+ h *= 6.0;
1408
+ let sextant = Math.floor(h);
1409
+ let fract = h - sextant;
1410
+ let vsf = v * sv * fract;
1411
+ let mid1 = m + vsf;
1412
+ let mid2 = v - vsf;
1413
+ switch (sextant) {
1414
+ case 0:
1415
+ r = v;
1416
+ g = mid1;
1417
+ b = m;
1418
+ break;
1419
+ case 1:
1420
+ r = mid2;
1421
+ g = v;
1422
+ b = m;
1423
+ break;
1424
+ case 2:
1425
+ r = m;
1426
+ g = v;
1427
+ b = mid1;
1428
+ break;
1429
+ case 3:
1430
+ r = m;
1431
+ g = mid2;
1432
+ b = v;
1433
+ break;
1434
+ case 4:
1435
+ r = mid1;
1436
+ g = m;
1437
+ b = v;
1438
+ break;
1439
+ case 5:
1440
+ r = v;
1441
+ g = m;
1442
+ b = mid2;
1443
+ break;
1444
+ }
1445
+ }
1446
+ const values = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
1447
+ if (a != null && a != 1) {
1448
+ values.push(Math.round(a * 255));
1449
+ }
1450
+ return values;
1451
+ }
1452
+
1453
+ const indents = [];
1454
+ function render(data, opt = {}) {
1455
+ const options = Object.assign(opt.compress ? {
1456
+ indent: '',
1457
+ newLine: '',
1458
+ removeComments: true
1459
+ } : {
1460
+ indent: ' ',
1461
+ newLine: '\n',
1462
+ compress: false,
1463
+ removeComments: false,
1464
+ }, { colorConvert: true, preserveLicense: false }, opt);
1465
+ function reducer(acc, curr, index, original) {
1466
+ if (curr.typ == 'Comment' && options.removeComments) {
1467
+ if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
1468
+ return acc;
1469
+ }
1470
+ }
1471
+ if (options.compress && curr.typ == 'Whitespace') {
1472
+ if (original[index + 1]?.typ == 'Start-parens' ||
1473
+ (index > 0 && (original[index - 1].typ == 'Pseudo-class-func' ||
1474
+ original[index - 1].typ == 'End-parens' ||
1475
+ original[index - 1].typ == 'UrlFunc' ||
1476
+ original[index - 1].typ == 'Func' ||
1477
+ (original[index - 1].typ == 'Color' &&
1478
+ original[index - 1].kin != 'hex' &&
1479
+ original[index - 1].kin != 'lit')))) {
1480
+ return acc;
1481
+ }
1482
+ }
1483
+ return acc + renderToken(curr, options);
1484
+ }
1485
+ return { code: doRender(data, options, reducer) };
1486
+ }
1487
+ // @ts-ignore
1488
+ function doRender(data, options, reducer, level = 0) {
1489
+ if (indents.length < level + 1) {
1490
+ indents.push(options.indent.repeat(level));
1491
+ }
1492
+ if (indents.length < level + 2) {
1493
+ indents.push(options.indent.repeat(level + 1));
1494
+ }
1495
+ const indent = indents[level];
1496
+ const indentSub = indents[level + 1];
1497
+ switch (data.typ) {
1498
+ case 'Comment':
1499
+ return options.removeComments ? '' : data.val;
1500
+ case 'StyleSheet':
1501
+ return data.chi.reduce((css, node) => {
1502
+ const str = doRender(node, options, reducer, level);
1503
+ if (str === '') {
1504
+ return css;
1505
+ }
1506
+ if (css === '') {
1507
+ return str;
1508
+ }
1509
+ return `${css}${options.newLine}${str}`;
1510
+ }, '');
1511
+ case 'AtRule':
1512
+ case 'Rule':
1513
+ if (data.typ == 'AtRule' && !('chi' in data)) {
1514
+ return `${indent}@${data.nam} ${data.val};`;
1515
+ }
1516
+ // @ts-ignore
1517
+ let children = data.chi.reduce((css, node) => {
1518
+ let str;
1519
+ if (node.typ == 'Comment') {
1520
+ str = options.removeComments ? '' : node.val;
1521
+ }
1522
+ else if (node.typ == 'Declaration') {
1523
+ str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
1524
+ }
1525
+ else if (node.typ == 'AtRule' && !('chi' in node)) {
1526
+ str = `@${node.nam} ${node.val};`;
1527
+ }
1528
+ else {
1529
+ str = doRender(node, options, reducer, level + 1);
1530
+ }
1531
+ if (css === '') {
1532
+ return str;
1533
+ }
1534
+ if (str === '') {
1535
+ return css;
1536
+ }
1537
+ if (str !== '')
1538
+ return `${css}${options.newLine}${indentSub}${str}`;
1539
+ }, '');
1540
+ if (children.endsWith(';')) {
1541
+ children = children.slice(0, -1);
1542
+ }
1543
+ if (data.typ == 'AtRule') {
1544
+ return `@${data.nam}${data.val ? ' ' + data.val + options.indent : ''}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
1545
+ }
1546
+ return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
1547
+ }
1548
+ return '';
1549
+ }
1550
+ function renderToken(token, options = {}) {
1551
+ switch (token.typ) {
1552
+ case 'Color':
1553
+ if (options.compress || options.colorConvert) {
1554
+ let value = token.kin == 'hex' ? token.val.toLowerCase() : '';
1555
+ if (token.val == 'rgb' || token.val == 'rgba') {
1556
+ value = rgb2Hex(token);
1557
+ }
1558
+ else if (token.val == 'hsl' || token.val == 'hsla') {
1559
+ value = hsl2Hex(token);
1560
+ }
1561
+ else if (token.val == 'hwb') {
1562
+ value = hwb2hex(token);
1563
+ }
1564
+ else if (token.val == 'device-cmyk') {
1565
+ value = cmyk2hex(token);
1566
+ }
1567
+ const named_color = NAMES_COLORS[value];
1568
+ if (value !== '') {
1569
+ if (value.length == 7) {
1570
+ if (value[1] == value[2] &&
1571
+ value[3] == value[4] &&
1572
+ value[5] == value[6]) {
1573
+ value = `#${value[1]}${value[3]}${value[5]}`;
1574
+ }
1575
+ }
1576
+ else if (value.length == 9) {
1577
+ if (value[1] == value[2] &&
1578
+ value[3] == value[4] &&
1579
+ value[5] == value[6] &&
1580
+ value[7] == value[8]) {
1581
+ value = `#${value[1]}${value[3]}${value[5]}${value[7]}`;
1582
+ }
1583
+ }
1584
+ return named_color != null && named_color.length <= value.length ? named_color : value;
1585
+ }
1586
+ }
1587
+ if (token.kin == 'hex' || token.kin == 'lit') {
1588
+ return token.val;
1589
+ }
1590
+ case 'Func':
1591
+ case 'UrlFunc':
1592
+ case 'Pseudo-class-func':
1593
+ // @ts-ignore
1594
+ return (options.compress && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) : token.val) + '(' + token.chi.reduce((acc, curr) => {
1595
+ if (options.removeComments && curr.typ == 'Comment') {
1596
+ if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
1597
+ return acc;
1598
+ }
1599
+ }
1600
+ return acc + renderToken(curr, options);
1601
+ }, '') + ')';
1602
+ case 'Includes':
1603
+ return '~=';
1604
+ case 'Dash-match':
1605
+ return '|=';
1606
+ case 'Lt':
1607
+ return '<';
1608
+ case 'Gt':
1609
+ return '>';
1610
+ case 'Start-parens':
1611
+ return '(';
1612
+ case 'End-parens':
1613
+ return ')';
1614
+ case 'Attr-start':
1615
+ return '[';
1616
+ case 'Attr-end':
1617
+ return ']';
1618
+ case 'Whitespace':
1619
+ return ' ';
1620
+ case 'Colon':
1621
+ return ':';
1622
+ case 'Semi-colon':
1623
+ return ';';
1624
+ case 'Comma':
1625
+ return ',';
1626
+ case 'Important':
1627
+ return '!important';
1628
+ case 'Attr':
1629
+ return '[' + token.chi.reduce((acc, curr) => acc + renderToken(curr, options), '') + ']';
1630
+ case 'Time':
1631
+ case 'Frequency':
1632
+ case 'Angle':
1633
+ case 'Length':
1634
+ case 'Dimension':
1635
+ const val = (+token.val).toString();
1636
+ if (val === '0') {
1637
+ if (token.typ == 'Time') {
1638
+ return '0s';
1639
+ }
1640
+ if (token.typ == 'Frequency') {
1641
+ return '0Hz';
1642
+ }
1643
+ // @ts-ignore
1644
+ if (token.typ == 'Resolution') {
1645
+ return '0x';
1646
+ }
1647
+ return '0';
1648
+ }
1649
+ const chr = val.charAt(0);
1650
+ if (chr == '-') {
1651
+ const slice = val.slice(0, 2);
1652
+ if (slice == '-0') {
1653
+ return (val.length == 2 ? '0' : '-' + val.slice(2)) + token.unit;
1654
+ }
1655
+ }
1656
+ else if (chr == '0') {
1657
+ return val.slice(1) + token.unit;
1658
+ }
1659
+ return val + token.unit;
1660
+ case 'Perc':
1661
+ return token.val + '%';
1662
+ case 'Number':
1663
+ const num = (+token.val).toString();
1664
+ if (token.val.length < num.length) {
1665
+ return token.val;
1666
+ }
1667
+ if (num.charAt(0) === '0' && num.length > 1) {
1668
+ return num.slice(1);
1669
+ }
1670
+ const slice = num.slice(0, 2);
1671
+ if (slice == '-0') {
1672
+ return '-' + num.slice(2);
1673
+ }
1674
+ return num;
1675
+ case 'Comment':
1676
+ if (options.removeComments) {
1677
+ return '';
1678
+ }
1679
+ case 'Url-token':
1680
+ case 'At-rule':
1681
+ case 'Hash':
1682
+ case 'Pseudo-class':
1683
+ case 'Literal':
1684
+ case 'String':
1685
+ case 'Iden':
1686
+ case 'Delim':
1687
+ return options.compress && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : token.val;
1688
+ }
1689
+ throw new Error(`unexpected token ${JSON.stringify(token, null, 1)}`);
1690
+ }
1691
+
1692
+ function eq(a, b) {
1693
+ if ((typeof a != 'object') || typeof b != 'object') {
1694
+ return a === b;
1695
+ }
1696
+ const k1 = Object.keys(a);
1697
+ const k2 = Object.keys(b);
1698
+ return k1.length == k2.length &&
1699
+ k1.every((key) => {
1700
+ return eq(a[key], b[key]);
1701
+ });
1702
+ }
1703
+
1704
+ class PropertySet {
1705
+ config;
1706
+ declarations;
1707
+ constructor(config) {
1708
+ this.config = config;
1709
+ this.declarations = new Map;
1710
+ }
1711
+ add(declaration) {
1712
+ if (declaration.nam == this.config.shorthand) {
1713
+ this.declarations.clear();
1714
+ this.declarations.set(declaration.nam, declaration);
1715
+ }
1716
+ else {
1717
+ // expand shorthand
1718
+ if (declaration.nam != this.config.shorthand && this.declarations.has(this.config.shorthand)) {
1719
+ let isValid = true;
1720
+ let current = -1;
1721
+ const tokens = [];
1722
+ // @ts-ignore
1723
+ for (let token of this.declarations.get(this.config.shorthand).val) {
1724
+ if (this.config.types.includes(token.typ) || (token.typ == 'Number' && token.val == '0' &&
1725
+ (this.config.types.includes('Length') ||
1726
+ this.config.types.includes('Angle') ||
1727
+ this.config.types.includes('Dimension')))) {
1728
+ if (tokens.length == 0) {
1729
+ tokens.push([]);
1730
+ current++;
1731
+ }
1732
+ tokens[current].push(token);
1733
+ continue;
1734
+ }
1735
+ if (token.typ != 'Whitespace' && token.typ != 'Comment') {
1736
+ if (token.typ == 'Iden' && this.config.keywords.includes(token.val)) {
1737
+ tokens[current].push(token);
1738
+ }
1739
+ if (token.typ == 'Literal' && token.val == this.config.separator) {
1740
+ tokens.push([]);
1741
+ current++;
1742
+ continue;
1743
+ }
1744
+ isValid = false;
1745
+ break;
1746
+ }
1747
+ }
1748
+ if (isValid && tokens.length > 0) {
1749
+ this.declarations.delete(this.config.shorthand);
1750
+ for (const values of tokens) {
1751
+ this.config.properties.forEach((property, index) => {
1752
+ // if (property == declaration.nam) {
1753
+ //
1754
+ // return;
1755
+ // }
1756
+ if (!this.declarations.has(property)) {
1757
+ this.declarations.set(property, {
1758
+ typ: 'Declaration',
1759
+ nam: property,
1760
+ val: []
1761
+ });
1762
+ }
1763
+ while (index > 0 && index >= values.length) {
1764
+ if (index > 1) {
1765
+ index %= 2;
1766
+ }
1767
+ else {
1768
+ index = 0;
1769
+ break;
1770
+ }
1771
+ }
1772
+ // @ts-ignore
1773
+ const val = this.declarations.get(property).val;
1774
+ if (val.length > 0) {
1775
+ val.push({ typ: 'Whitespace' });
1776
+ }
1777
+ val.push({ ...values[index] });
1778
+ });
1779
+ }
1780
+ }
1781
+ this.declarations.set(declaration.nam, declaration);
1782
+ return this;
1783
+ }
1784
+ // declaration.chi = declaration.chi.reduce((acc: Token[], token: Token) => {
1785
+ //
1786
+ // if (this.config.types.includes(token.typ) || ('0' == (<DimensionToken>token).chi && (
1787
+ // this.config.types.includes('Length') ||
1788
+ // this.config.types.includes('Angle') ||
1789
+ // this.config.types.includes('Dimension'))) || (token.typ == 'Iden' && this.config.keywords.includes(token.chi))) {
1790
+ //
1791
+ // acc.push(token);
1792
+ // }
1793
+ //
1794
+ // return acc;
1795
+ // }, <Token[]>[]);
1796
+ this.declarations.set(declaration.nam, declaration);
1797
+ }
1798
+ return this;
1799
+ }
1800
+ [Symbol.iterator]() {
1801
+ let iterator;
1802
+ const declarations = this.declarations;
1803
+ if (declarations.size < this.config.properties.length || this.config.properties.some((property, index) => {
1804
+ return !declarations.has(property) || (index > 0 &&
1805
+ // @ts-ignore
1806
+ declarations.get(property).val.length != declarations.get(this.config.properties[Math.floor(index / 2)]).val.length);
1807
+ })) {
1808
+ iterator = declarations.values();
1809
+ }
1810
+ else {
1811
+ const values = [];
1812
+ this.config.properties.forEach((property) => {
1813
+ let index = 0;
1814
+ // @ts-ignore
1815
+ for (const token of this.declarations.get(property).val) {
1816
+ if (token.typ == 'Whitespace') {
1817
+ continue;
1818
+ }
1819
+ if (values.length == index) {
1820
+ values.push([]);
1821
+ }
1822
+ values[index].push(token);
1823
+ index++;
1824
+ }
1825
+ });
1826
+ for (const value of values) {
1827
+ let i = value.length;
1828
+ while (i-- > 1) {
1829
+ const t = value[i];
1830
+ const k = value[i == 1 ? 0 : i % 2];
1831
+ if (t.val == k.val && t.val == '0') {
1832
+ if ((t.typ == 'Number' && isLength(k)) ||
1833
+ (k.typ == 'Number' && isLength(t)) ||
1834
+ (isLength(k) || isLength(t))) {
1835
+ value.splice(i, 1);
1836
+ continue;
1837
+ }
1838
+ }
1839
+ if (eq(t, k)) {
1840
+ value.splice(i, 1);
1841
+ continue;
1842
+ }
1843
+ break;
1844
+ }
1845
+ }
1846
+ iterator = [{
1847
+ typ: 'Declaration',
1848
+ nam: this.config.shorthand,
1849
+ val: values.reduce((acc, curr) => {
1850
+ if (curr.length > 1) {
1851
+ const k = curr.length * 2 - 1;
1852
+ let i = 1;
1853
+ while (i < k) {
1854
+ curr.splice(i, 0, { typ: 'Whitespace' });
1855
+ i += 2;
1856
+ }
1857
+ }
1858
+ if (acc.length > 0) {
1859
+ acc.push({ typ: 'Literal', val: this.config.separator });
1860
+ }
1861
+ acc.push(...curr);
1862
+ return acc;
1863
+ }, [])
1864
+ }][Symbol.iterator]();
1865
+ return {
1866
+ next() {
1867
+ return iterator.next();
1868
+ }
1869
+ };
1870
+ }
1871
+ return {
1872
+ next() {
1873
+ return iterator.next();
1874
+ }
1875
+ };
1876
+ }
1877
+ }
1878
+
1879
+ function matchType(val, properties) {
1880
+ if (val.typ == 'Iden' && properties.keywords.includes(val.val) ||
1881
+ (properties.types.includes(val.typ))) {
1882
+ return true;
1883
+ }
1884
+ if (val.typ == 'Number' && val.val == '0') {
1885
+ return properties.types.some(type => type == 'Length' || type == 'Angle');
1886
+ }
1887
+ return false;
1888
+ }
1889
+
1890
+ function getTokenType(val) {
1891
+ if (val == 'transparent' || val == 'currentcolor') {
1892
+ return {
1893
+ typ: 'Color',
1894
+ val,
1895
+ kin: 'lit'
1896
+ };
1897
+ }
1898
+ if (val.endsWith('%')) {
1899
+ return {
1900
+ typ: 'Perc',
1901
+ val: val.slice(0, -1)
1902
+ };
1903
+ }
1904
+ return {
1905
+ typ: isNumber(val) ? 'Number' : 'Iden',
1906
+ val
1907
+ };
1908
+ }
1909
+ function parseString(val) {
1910
+ return val.split(/\s/).map(getTokenType).reduce((acc, curr) => {
1911
+ if (acc.length > 0) {
1912
+ acc.push({ typ: 'Whitespace' });
1913
+ }
1914
+ acc.push(curr);
1915
+ return acc;
1916
+ }, []);
1917
+ }
1918
+ class PropertyMap {
1919
+ config;
1920
+ declarations;
1921
+ requiredCount;
1922
+ pattern;
1923
+ constructor(config) {
1924
+ const values = Object.values(config.properties);
1925
+ this.requiredCount = values.reduce((acc, curr) => curr.required ? ++acc : acc, 0) || values.length;
1926
+ this.config = config;
1927
+ this.declarations = new Map;
1928
+ this.pattern = config.pattern.split(/\s/);
1929
+ }
1930
+ add(declaration) {
1931
+ if (declaration.nam == this.config.shorthand) {
1932
+ this.declarations.clear();
1933
+ this.declarations.set(declaration.nam, declaration);
1934
+ }
1935
+ else {
1936
+ const separator = this.config.separator;
1937
+ // expand shorthand
1938
+ if (declaration.nam != this.config.shorthand && this.declarations.has(this.config.shorthand)) {
1939
+ const tokens = {};
1940
+ const values = [];
1941
+ // @ts-ignore
1942
+ this.declarations.get(this.config.shorthand).val.slice().reduce((acc, curr) => {
1943
+ if (separator != null && separator.typ == curr.typ && eq(separator, curr)) {
1944
+ acc.push([]);
1945
+ return acc;
1946
+ }
1947
+ // else {
1948
+ // @ts-ignore
1949
+ acc.at(-1).push(curr);
1950
+ // }
1951
+ return acc;
1952
+ }, [[]]).
1953
+ // @ts-ignore
1954
+ reduce((acc, list, current) => {
1955
+ values.push(...this.pattern.reduce((acc, property) => {
1956
+ // let current: number = 0;
1957
+ const props = this.config.properties[property];
1958
+ for (let i = 0; i < acc.length; i++) {
1959
+ if (acc[i].typ == 'Comment' || acc[i].typ == 'Whitespace') {
1960
+ acc.splice(i, 1);
1961
+ i--;
1962
+ continue;
1963
+ }
1964
+ if (matchType(acc[i], props)) {
1965
+ if ('prefix' in props && props.previous != null && !(props.previous in tokens)) {
1966
+ return acc;
1967
+ }
1968
+ if (!(property in tokens)) {
1969
+ tokens[property] = [[acc[i]]];
1970
+ }
1971
+ else {
1972
+ if (current == tokens[property].length) {
1973
+ tokens[property].push([acc[i]]);
1974
+ // tokens[property][current].push();
1975
+ }
1976
+ else {
1977
+ tokens[property][current].push({ typ: 'Whitespace' }, acc[i]);
1978
+ }
1979
+ }
1980
+ acc.splice(i, 1);
1981
+ i--;
1982
+ // @ts-ignore
1983
+ if ('prefix' in props && acc[i]?.typ == props.prefix.typ) {
1984
+ // @ts-ignore
1985
+ if (eq(acc[i], this.config.properties[property].prefix)) {
1986
+ acc.splice(i, 1);
1987
+ i--;
1988
+ }
1989
+ }
1990
+ if (props.multiple) {
1991
+ continue;
1992
+ }
1993
+ return acc;
1994
+ }
1995
+ else {
1996
+ if (property in tokens && tokens[property].length > current) {
1997
+ return acc;
1998
+ }
1999
+ }
2000
+ }
2001
+ if (property in tokens && tokens[property].length > current) {
2002
+ return acc;
2003
+ }
2004
+ // default
2005
+ if (props.default.length > 0) {
2006
+ const defaults = parseString(props.default[0]);
2007
+ if (!(property in tokens)) {
2008
+ tokens[property] = [
2009
+ [...defaults
2010
+ ]
2011
+ ];
2012
+ }
2013
+ else {
2014
+ if (current == tokens[property].length) {
2015
+ tokens[property].push([]);
2016
+ tokens[property][current].push(...defaults);
2017
+ }
2018
+ else {
2019
+ tokens[property][current].push({ typ: 'Whitespace' }, ...defaults);
2020
+ }
2021
+ }
2022
+ }
2023
+ return acc;
2024
+ }, list));
2025
+ return values;
2026
+ }, []);
2027
+ if (values.length == 0) {
2028
+ this.declarations = Object.entries(tokens).reduce((acc, curr) => {
2029
+ acc.set(curr[0], {
2030
+ typ: 'Declaration',
2031
+ nam: curr[0],
2032
+ val: curr[1].reduce((acc, curr) => {
2033
+ if (acc.length > 0) {
2034
+ acc.push({ ...separator });
2035
+ }
2036
+ acc.push(...curr);
2037
+ return acc;
2038
+ }, [])
2039
+ });
2040
+ return acc;
2041
+ }, new Map);
2042
+ }
2043
+ }
2044
+ this.declarations.set(declaration.nam, declaration);
2045
+ }
2046
+ return this;
2047
+ }
2048
+ [Symbol.iterator]() {
2049
+ let requiredCount = Object.keys(this.config.properties).reduce((acc, curr) => this.declarations.has(curr) && this.config.properties[curr].required ? ++acc : acc, 0);
2050
+ if (requiredCount == 0) {
2051
+ requiredCount = this.declarations.size;
2052
+ }
2053
+ if (requiredCount < this.requiredCount) {
2054
+ // if (this.declarations.size == 1 && this.declarations.has(this.config.shorthand)) {
2055
+ //
2056
+ // this.declarations
2057
+ // }
2058
+ return this.declarations.values();
2059
+ }
2060
+ let count = 0;
2061
+ const separator = this.config.separator;
2062
+ const tokens = {};
2063
+ // @ts-ignore
2064
+ const valid = Object.entries(this.config.properties).reduce((acc, curr) => {
2065
+ if (!this.declarations.has(curr[0])) {
2066
+ if (curr[1].required) {
2067
+ acc.push(curr[0]);
2068
+ }
2069
+ return acc;
2070
+ }
2071
+ let current = 0;
2072
+ const props = this.config.properties[curr[0]];
2073
+ // @ts-ignore
2074
+ for (const val of this.declarations.get(curr[0]).val) {
2075
+ if (separator != null && separator.typ == val.typ && eq(separator, val)) {
2076
+ current++;
2077
+ if (tokens[curr[0]].length == current) {
2078
+ tokens[curr[0]].push([]);
2079
+ }
2080
+ continue;
2081
+ }
2082
+ if (val.typ == 'Whitespace' || val.typ == 'Comment') {
2083
+ continue;
2084
+ }
2085
+ if (props.multiple && props.separator != null && props.separator.typ == val.typ && eq(val, props.separator)) {
2086
+ continue;
2087
+ }
2088
+ if (matchType(val, curr[1])) {
2089
+ if (!(curr[0] in tokens)) {
2090
+ tokens[curr[0]] = [[]];
2091
+ }
2092
+ // is default value
2093
+ tokens[curr[0]][current].push(val);
2094
+ continue;
2095
+ }
2096
+ acc.push(curr[0]);
2097
+ break;
2098
+ }
2099
+ if (count == 0) {
2100
+ count = current;
2101
+ }
2102
+ return acc;
2103
+ }, []);
2104
+ if (valid.length > 0 || Object.values(tokens).every(v => v.every(v => v.length == count))) {
2105
+ return this.declarations.values();
2106
+ }
2107
+ const values = Object.entries(tokens).reduce((acc, curr) => {
2108
+ const props = this.config.properties[curr[0]];
2109
+ for (let i = 0; i < curr[1].length; i++) {
2110
+ if (acc.length == i) {
2111
+ acc.push([]);
2112
+ }
2113
+ let values = curr[1][i].reduce((acc, curr) => {
2114
+ if (acc.length > 0) {
2115
+ acc.push({ typ: 'Whitespace' });
2116
+ }
2117
+ acc.push(curr);
2118
+ return acc;
2119
+ }, []);
2120
+ if (props.default.includes(curr[1][i].reduce((acc, curr) => acc + renderToken(curr) + ' ', '').trimEnd())) {
2121
+ continue;
2122
+ }
2123
+ values = values.filter((val) => {
2124
+ if (val.typ == 'Whitespace' || val.typ == 'Comment') {
2125
+ return false;
2126
+ }
2127
+ return !(val.typ == 'Iden' && props.default.includes(val.val));
2128
+ });
2129
+ if (values.length > 0) {
2130
+ if ('mapping' in props) {
2131
+ // @ts-ignore
2132
+ if (!('constraints' in props) || !('max' in props.constraints) || values.length <= props.constraints.mapping.max) {
2133
+ let i = values.length;
2134
+ while (i--) {
2135
+ // @ts-ignore
2136
+ if (values[i].typ == 'Iden' && values[i].val in props.mapping) {
2137
+ // @ts-ignore
2138
+ values.splice(i, 1, ...parseString(props.mapping[values[i].val]));
2139
+ }
2140
+ }
2141
+ }
2142
+ }
2143
+ if ('prefix' in props) {
2144
+ // @ts-ignore
2145
+ acc[i].push({ ...props.prefix });
2146
+ }
2147
+ else if (acc[i].length > 0) {
2148
+ acc[i].push({ typ: 'Whitespace' });
2149
+ }
2150
+ acc[i].push(...values.reduce((acc, curr) => {
2151
+ if (acc.length > 0) {
2152
+ // @ts-ignore
2153
+ acc.push({ ...(props.separator ?? { typ: 'Whitespace' }) });
2154
+ }
2155
+ // @ts-ignore
2156
+ acc.push(curr);
2157
+ return acc;
2158
+ }, []));
2159
+ }
2160
+ }
2161
+ return acc;
2162
+ }, []).reduce((acc, curr) => {
2163
+ if (acc.length > 0) {
2164
+ acc.push({ ...separator });
2165
+ }
2166
+ if (curr.length == 0) {
2167
+ curr.push(...this.config.default[0].split(/\s/).map(getTokenType).reduce((acc, curr) => {
2168
+ if (acc.length > 0) {
2169
+ acc.push({ typ: 'Whitespace' });
2170
+ }
2171
+ acc.push(curr);
2172
+ return acc;
2173
+ }, []));
2174
+ }
2175
+ acc.push(...curr);
2176
+ return acc;
2177
+ }, []);
2178
+ return [{
2179
+ typ: 'Declaration',
2180
+ nam: this.config.shorthand,
2181
+ val: values
2182
+ }][Symbol.iterator]();
2183
+ }
2184
+ }
2185
+
2186
+ const config = getConfig();
2187
+ class PropertyList {
2188
+ declarations;
2189
+ constructor() {
2190
+ this.declarations = new Map;
2191
+ }
2192
+ add(declaration) {
2193
+ if (declaration.typ != 'Declaration') {
2194
+ this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
2195
+ return this;
2196
+ }
2197
+ const propertyName = declaration.nam;
2198
+ if (propertyName in config.properties) {
2199
+ // @ts-ignore
2200
+ const shorthand = config.properties[propertyName].shorthand;
2201
+ if (!this.declarations.has(shorthand)) {
2202
+ // @ts-ignore
2203
+ this.declarations.set(shorthand, new PropertySet(config.properties[shorthand]));
2204
+ }
2205
+ this.declarations.get(shorthand).add(declaration);
2206
+ return this;
2207
+ }
2208
+ if (propertyName in config.map) {
2209
+ // @ts-ignore
2210
+ const shorthand = config.map[propertyName].shorthand;
2211
+ if (!this.declarations.has(shorthand)) {
2212
+ // @ts-ignore
2213
+ this.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
2214
+ }
2215
+ this.declarations.get(shorthand).add(declaration);
2216
+ return this;
2217
+ }
2218
+ this.declarations.set(propertyName, declaration);
2219
+ return this;
2220
+ }
2221
+ [Symbol.iterator]() {
2222
+ let iterator = this.declarations.values();
2223
+ const iterators = [];
2224
+ return {
2225
+ next() {
2226
+ let value = iterator.next();
2227
+ while ((value.done && iterators.length > 0) ||
2228
+ value.value instanceof PropertySet ||
2229
+ value.value instanceof PropertyMap) {
2230
+ if (value.value instanceof PropertySet || value.value instanceof PropertyMap) {
2231
+ iterators.unshift(iterator);
2232
+ // @ts-ignore
2233
+ iterator = value.value[Symbol.iterator]();
2234
+ value = iterator.next();
2235
+ }
2236
+ if (value.done && iterators.length > 0) {
2237
+ iterator = iterators.shift();
2238
+ value = iterator.next();
2239
+ }
2240
+ }
2241
+ return value;
2242
+ }
2243
+ };
2244
+ }
2245
+ }
2246
+
2247
+ const configuration = getConfig();
2248
+ function deduplicate(ast, options = {}, recursive = false) {
2249
+ // @ts-ignore
2250
+ if (('chi' in ast) && ast.chi?.length > 0) {
2251
+ let i = 0;
2252
+ let previous;
2253
+ let node;
2254
+ let nodeIndex;
2255
+ // @ts-ignore
2256
+ for (; i < ast.chi.length; i++) {
2257
+ // @ts-ignore
2258
+ if (ast.chi[i].typ == 'Comment') {
2259
+ continue;
2260
+ }
2261
+ // @ts-ignore
2262
+ node = ast.chi[i];
2263
+ if (node.typ == 'AtRule' && node.nam == 'font-face') {
2264
+ continue;
2265
+ }
2266
+ if (node.typ == 'AtRule' && node.val == 'all') {
2267
+ // @ts-ignore
2268
+ ast.chi?.splice(i, 1, ...node.chi);
2269
+ i--;
2270
+ continue;
2271
+ }
2272
+ // @ts-ignore
2273
+ if (previous != null && 'chi' in previous && ('chi' in node)) {
2274
+ // @ts-ignore
2275
+ if (previous.typ == node.typ) {
2276
+ let shouldMerge = true;
2277
+ // @ts-ignore
2278
+ let k = previous.chi.length;
2279
+ while (k-- > 0) {
2280
+ // @ts-ignore
2281
+ if (previous.chi[k].typ == 'Comment') {
2282
+ continue;
2283
+ }
2284
+ // @ts-ignore
2285
+ shouldMerge = previous.chi[k].typ == 'Declaration';
2286
+ break;
2287
+ }
2288
+ if (shouldMerge) {
2289
+ // @ts-ignore
2290
+ if ((node.typ == 'Rule' && node.sel == previous.sel) ||
2291
+ // @ts-ignore
2292
+ (node.typ == 'AtRule') && node.val == previous.val) {
2293
+ // @ts-ignore
2294
+ node.chi.unshift(...previous.chi);
2295
+ // @ts-ignore
2296
+ ast.chi.splice(nodeIndex, 1);
2297
+ // @ts-ignore
2298
+ if (hasDeclaration(node)) {
2299
+ deduplicateRule(node);
2300
+ }
2301
+ else {
2302
+ deduplicate(node, options, recursive);
2303
+ }
2304
+ i--;
2305
+ previous = node;
2306
+ nodeIndex = i;
2307
+ continue;
2308
+ }
2309
+ else if (node.typ == 'Rule' && previous?.typ == 'Rule') {
2310
+ const intersect = diff(previous, node, options);
2311
+ if (intersect != null) {
2312
+ if (intersect.node1.chi.length == 0) {
2313
+ // @ts-ignore
2314
+ ast.chi.splice(i, 1);
2315
+ }
2316
+ else {
2317
+ // @ts-ignore
2318
+ ast.chi.splice(i, 1, intersect.node1);
2319
+ }
2320
+ if (intersect.node2.chi.length == 0) {
2321
+ // @ts-ignore
2322
+ ast.chi.splice(nodeIndex, 1, intersect.result);
2323
+ }
2324
+ else {
2325
+ // @ts-ignore
2326
+ ast.chi.splice(nodeIndex, 1, intersect.result, intersect.node2);
2327
+ }
2328
+ }
2329
+ }
2330
+ }
2331
+ }
2332
+ // @ts-ignore
2333
+ if (recursive && previous != node) {
2334
+ // @ts-ignore
2335
+ if (hasDeclaration(previous)) {
2336
+ deduplicateRule(previous);
2337
+ }
2338
+ else {
2339
+ deduplicate(previous, options, recursive);
2340
+ }
2341
+ }
2342
+ }
2343
+ previous = node;
2344
+ nodeIndex = i;
2345
+ }
2346
+ // @ts-ignore
2347
+ if (recursive && node != null && ('chi' in node)) {
2348
+ // @ts-ignore
2349
+ if (node.chi.some(n => n.typ == 'Declaration')) {
2350
+ deduplicateRule(node);
2351
+ }
2352
+ else {
2353
+ deduplicate(node, options, recursive);
2354
+ }
2355
+ }
2356
+ }
2357
+ return ast;
2358
+ }
2359
+ function hasDeclaration(node) {
2360
+ // @ts-ignore
2361
+ for (let i = 0; i < node.chi?.length; i++) {
2362
+ // @ts-ignore
2363
+ if (node.chi[i].typ == 'Comment') {
2364
+ continue;
2365
+ }
2366
+ // @ts-ignore
2367
+ return node.chi[i].typ == 'Declaration';
2368
+ }
2369
+ return true;
2370
+ }
2371
+ function deduplicateRule(ast, options = {}) {
2372
+ // @ts-ignore
2373
+ if (!('chi' in ast) || ast.chi?.length <= 1) {
2374
+ return ast;
2375
+ }
2376
+ // @ts-ignore
2377
+ const j = ast.chi.length;
2378
+ let k = 0;
2379
+ let map = new Map;
2380
+ // @ts-ignore
2381
+ for (; k < j; k++) {
2382
+ // @ts-ignore
2383
+ const node = ast.chi[k];
2384
+ if (node.typ == 'Comment') {
2385
+ // @ts-ignore
2386
+ map.set(node, node);
2387
+ continue;
2388
+ }
2389
+ else if (node.typ != 'Declaration') {
2390
+ break;
2391
+ }
2392
+ if (node.nam in configuration.map ||
2393
+ node.nam in configuration.properties) {
2394
+ // @ts-ignore
2395
+ const shorthand = node.nam in configuration.map ? configuration.map[node.nam].shorthand : configuration.properties[node.nam].shorthand;
2396
+ if (!map.has(shorthand)) {
2397
+ map.set(shorthand, new PropertyList());
2398
+ }
2399
+ map.get(shorthand).add(node);
2400
+ }
2401
+ else {
2402
+ map.set(node.nam, node);
2403
+ }
2404
+ }
2405
+ const children = [];
2406
+ for (let child of map.values()) {
2407
+ if (child instanceof PropertyList) {
2408
+ // @ts-ignore
2409
+ children.push(...child);
2410
+ }
2411
+ else {
2412
+ // @ts-ignore
2413
+ children.push(child);
2414
+ }
2415
+ }
2416
+ // @ts-ignore
2417
+ ast.chi = children.concat(ast.chi?.slice(k));
2418
+ /*
2419
+ // @ts-ignore
2420
+
2421
+ const properties: PropertyList = new PropertyList();
2422
+
2423
+ for (; k < j; k++) {
2424
+
2425
+ // @ts-ignore
2426
+ if ('Comment' == ast.chi[k].typ || 'Declaration' == ast.chi[k].typ) {
2427
+
2428
+ // @ts-ignore
2429
+ properties.add(ast.chi[k]);
2430
+ continue;
2431
+ }
2432
+
2433
+ break;
2434
+ }
2435
+
2436
+ // @ts-ignore
2437
+ ast.chi = [...properties].concat(ast.chi.slice(k));
2438
+ */
2439
+ //
2440
+ // @ts-ignore
2441
+ // ast.chi.splice(0, k - 1, ...properties);
2442
+ return ast;
2443
+ }
2444
+ function splitRule(buffer) {
2445
+ const result = [];
2446
+ let str = '';
2447
+ for (let i = 0; i < buffer.length; i++) {
2448
+ let chr = buffer.charAt(i);
2449
+ if (chr == ',') {
2450
+ if (str !== '') {
2451
+ result.push(str);
2452
+ str = '';
2453
+ }
2454
+ continue;
2455
+ }
2456
+ str += chr;
2457
+ if (chr == '\\') {
2458
+ str += buffer.charAt(++i);
2459
+ continue;
2460
+ }
2461
+ if (chr == '"' || chr == "'") {
2462
+ let k = i;
2463
+ while (++k < buffer.length) {
2464
+ chr = buffer.charAt(k);
2465
+ str += chr;
2466
+ if (chr == '//') {
2467
+ str += buffer.charAt(++k);
2468
+ continue;
2469
+ }
2470
+ if (chr == buffer.charAt(i)) {
2471
+ break;
2472
+ }
2473
+ }
2474
+ continue;
2475
+ }
2476
+ if (chr == '(' || chr == '[') {
2477
+ const open = chr;
2478
+ const close = chr == '(' ? ')' : ']';
2479
+ let inParens = 1;
2480
+ let k = i;
2481
+ while (++k < buffer.length) {
2482
+ chr = buffer.charAt(k);
2483
+ if (chr == '\\') {
2484
+ str += buffer.slice(k, k + 2);
2485
+ k++;
2486
+ continue;
2487
+ }
2488
+ str += chr;
2489
+ if (chr == open) {
2490
+ inParens++;
2491
+ }
2492
+ else if (chr == close) {
2493
+ inParens--;
2494
+ }
2495
+ if (inParens == 0) {
2496
+ break;
2497
+ }
2498
+ }
2499
+ i = k;
2500
+ continue;
2501
+ }
2502
+ }
2503
+ if (str !== '') {
2504
+ result.push(str);
2505
+ }
2506
+ return result;
2507
+ }
2508
+ function diff(n1, n2, options = {}) {
2509
+ let node1 = n1;
2510
+ let node2 = n2;
2511
+ let exchanged = false;
2512
+ if (node1.chi.length > node2.chi.length) {
2513
+ const t = node1;
2514
+ node1 = node2;
2515
+ node2 = t;
2516
+ exchanged = true;
2517
+ }
2518
+ let i = node1.chi.length;
2519
+ let j = node2.chi.length;
2520
+ if (i == 0 || j == 0) {
2521
+ // @ts-ignore
2522
+ return null;
2523
+ }
2524
+ node1 = { ...node1, chi: node1.chi.slice() };
2525
+ node2 = { ...node2, chi: node2.chi.slice() };
2526
+ const intersect = [];
2527
+ while (i--) {
2528
+ if (node1.chi[i].typ == 'Comment') {
2529
+ continue;
2530
+ }
2531
+ j = node2.chi.length;
2532
+ if (j == 0) {
2533
+ break;
2534
+ }
2535
+ while (j--) {
2536
+ if (node2.chi[j].typ == 'Comment') {
2537
+ continue;
2538
+ }
2539
+ if (node1.chi[i].nam == node2.chi[j].nam) {
2540
+ if (eq(node1.chi[i], node2.chi[j])) {
2541
+ intersect.push(node1.chi[i]);
2542
+ node1.chi.splice(i, 1);
2543
+ node2.chi.splice(j, 1);
2544
+ break;
2545
+ }
2546
+ }
2547
+ }
2548
+ }
2549
+ // @ts-ignore
2550
+ const result = (intersect.length == 0 ? null : {
2551
+ ...node1,
2552
+ // @ts-ignore
2553
+ sel: [...new Set([...(n1.raw || splitRule(n1.sel)).concat(n2.raw || splitRule(n2.sel))])].join(),
2554
+ chi: intersect.reverse()
2555
+ });
2556
+ if (result == null || [n1, n2].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0) <= [node1, node2, result].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0)) {
2557
+ // @ts-ignore
2558
+ return null;
2559
+ }
2560
+ return { result, node1: exchanged ? node2 : node1, node2: exchanged ? node2 : node2 };
2561
+ }
2562
+
2563
+ const urlTokenMatcher = /^(["']?)[a-zA-Z0-9_/.-][a-zA-Z0-9_/:.#?-]+(\1)$/;
2564
+ const funcLike = ['Start-parens', 'Func', 'UrlFunc', 'Pseudo-class-func'];
2565
+ async function parse$1(iterator, opt = {}) {
2566
+ const errors = [];
2567
+ const options = {
2568
+ src: '',
2569
+ sourcemap: false,
2570
+ compress: false,
2571
+ resolveImport: false,
2572
+ resolveUrls: false,
2573
+ removeEmpty: true,
2574
+ ...opt
2575
+ };
2576
+ if (options.resolveImport) {
2577
+ options.resolveUrls = true;
2578
+ }
2579
+ let ind = -1;
2580
+ let lin = 1;
2581
+ let col = 0;
2582
+ const tokens = [];
2583
+ const src = options.src;
2584
+ const stack = [];
2585
+ const ast = {
2586
+ typ: "StyleSheet",
2587
+ chi: []
2588
+ };
2589
+ const position = {
2590
+ ind: Math.max(ind, 0),
2591
+ lin: lin,
2592
+ col: Math.max(col, 1)
2593
+ };
2594
+ let value;
2595
+ let buffer = '';
2596
+ let total = iterator.length;
2597
+ let bytesIn = total;
2598
+ let map = new Map;
2599
+ let context = ast;
2600
+ if (options.sourcemap) {
2601
+ ast.loc = {
2602
+ sta: {
2603
+ ind: ind,
2604
+ lin: lin,
2605
+ col: col
2606
+ },
2607
+ src: ''
2608
+ };
2609
+ }
2610
+ function getType(val) {
2611
+ if (val === '') {
2612
+ throw new Error('empty string?');
2613
+ }
2614
+ if (val == ':') {
2615
+ return { typ: 'Colon' };
2616
+ }
2617
+ if (val == ')') {
2618
+ return { typ: 'End-parens' };
2619
+ }
2620
+ if (val == '(') {
2621
+ return { typ: 'Start-parens' };
2622
+ }
2623
+ if (val == '=') {
2624
+ return { typ: 'Delim', val };
2625
+ }
2626
+ if (val == ';') {
2627
+ return { typ: 'Semi-colon' };
2628
+ }
2629
+ if (val == ',') {
2630
+ return { typ: 'Comma' };
2631
+ }
2632
+ if (val == '<') {
2633
+ return { typ: 'Lt' };
2634
+ }
2635
+ if (val == '>') {
2636
+ return { typ: 'Gt' };
2637
+ }
2638
+ if (isPseudo(val)) {
2639
+ return val.endsWith('(') ? {
2640
+ typ: 'Pseudo-class-func',
2641
+ val: val.slice(0, -1),
2642
+ chi: []
2643
+ }
2644
+ : {
2645
+ typ: 'Pseudo-class',
2646
+ val
2647
+ };
2648
+ }
2649
+ if (isAtKeyword(val)) {
2650
+ return {
2651
+ typ: 'At-rule',
2652
+ val: val.slice(1)
2653
+ };
2654
+ }
2655
+ if (isFunction(val)) {
2656
+ val = val.slice(0, -1);
2657
+ return {
2658
+ typ: val == 'url' ? 'UrlFunc' : 'Func',
2659
+ val,
2660
+ chi: []
2661
+ };
2662
+ }
2663
+ if (isNumber(val)) {
2664
+ return {
2665
+ typ: 'Number',
2666
+ val
2667
+ };
2668
+ }
2669
+ if (isDimension(val)) {
2670
+ return parseDimension(val);
2671
+ }
2672
+ if (isPercentage(val)) {
2673
+ return {
2674
+ typ: 'Perc',
2675
+ val: val.slice(0, -1)
2676
+ };
2677
+ }
2678
+ if (val == 'currentColor') {
2679
+ return {
2680
+ typ: 'Color',
2681
+ val,
2682
+ kin: 'lit'
2683
+ };
2684
+ }
2685
+ if (isIdent(val)) {
2686
+ return {
2687
+ typ: 'Iden',
2688
+ val
2689
+ };
2690
+ }
2691
+ if (val.charAt(0) == '#' && isHash(val)) {
2692
+ return {
2693
+ typ: 'Hash',
2694
+ val
2695
+ };
2696
+ }
2697
+ if ('"\''.includes(val.charAt(0))) {
2698
+ return {
2699
+ typ: 'Unclosed-string',
2700
+ val
2701
+ };
2702
+ }
2703
+ return {
2704
+ typ: 'Literal',
2705
+ val
2706
+ };
2707
+ }
2708
+ // consume and throw away
2709
+ function consume(open, close) {
2710
+ let count = 1;
2711
+ let chr;
2712
+ while (true) {
2713
+ chr = next();
2714
+ if (chr == '\\') {
2715
+ if (peek() === '') {
2716
+ break;
2717
+ }
2718
+ continue;
2719
+ }
2720
+ else if (chr == '/' && peek() == '*') {
2721
+ next();
2722
+ while (true) {
2723
+ chr = next();
2724
+ if (chr === '') {
2725
+ break;
2726
+ }
2727
+ if (chr == '*' && peek() == '/') {
2728
+ next();
2729
+ break;
2730
+ }
2731
+ }
2732
+ }
2733
+ else if (chr == close) {
2734
+ count--;
2735
+ }
2736
+ else if (chr == open) {
2737
+ count++;
2738
+ }
2739
+ if (chr === '' || count == 0) {
2740
+ break;
2741
+ }
2742
+ }
2743
+ }
2744
+ async function parseNode(tokens) {
2745
+ let i;
2746
+ let loc;
2747
+ for (i = 0; i < tokens.length; i++) {
2748
+ if (tokens[i].typ == 'Comment') {
2749
+ // @ts-ignore
2750
+ context.chi.push(tokens[i]);
2751
+ const position = map.get(tokens[i]);
2752
+ loc = {
2753
+ sta: position,
2754
+ src
2755
+ };
2756
+ if (options.sourcemap) {
2757
+ tokens[i].loc = loc;
2758
+ }
2759
+ }
2760
+ else if (tokens[i].typ != 'Whitespace') {
2761
+ break;
2762
+ }
2763
+ }
2764
+ tokens = tokens.slice(i);
2765
+ if (tokens.length == 0) {
2766
+ return null;
2767
+ }
2768
+ let delim = tokens.at(-1);
2769
+ if (delim.typ == 'Semi-colon' || delim.typ == 'Block-start' || delim.typ == 'Block-end') {
2770
+ tokens.pop();
2771
+ }
2772
+ else {
2773
+ delim = { typ: 'Semi-colon' };
2774
+ }
2775
+ // @ts-ignore
2776
+ while (['Whitespace', 'Bad-string', 'Bad-comment'].includes(tokens.at(-1)?.typ)) {
2777
+ tokens.pop();
2778
+ }
2779
+ if (tokens.length == 0) {
2780
+ return null;
2781
+ }
2782
+ if (tokens[0]?.typ == 'At-rule') {
2783
+ const atRule = tokens.shift();
2784
+ const position = map.get(atRule);
2785
+ if (atRule.val == 'charset' && position.ind > 0) {
2786
+ errors.push({ action: 'drop', message: 'invalid @charset', location: { src, ...position } });
2787
+ return null;
2788
+ }
2789
+ // @ts-ignore
2790
+ while (['Whitespace'].includes(tokens[0]?.typ)) {
2791
+ tokens.shift();
2792
+ }
2793
+ if (atRule.val == 'import') {
2794
+ // only @charset and @layer are accepted before @import
2795
+ if (context.chi.length > 0) {
2796
+ let i = context.chi.length;
2797
+ while (i--) {
2798
+ const type = context.chi[i].typ;
2799
+ if (type == 'Comment') {
2800
+ continue;
2801
+ }
2802
+ if (type != 'AtRule') {
2803
+ errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
2804
+ return null;
2805
+ }
2806
+ const name = context.chi[i].nam;
2807
+ if (name != 'charset' && name != 'import' && name != 'layer') {
2808
+ errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
2809
+ return null;
2810
+ }
2811
+ break;
2812
+ }
2813
+ }
2814
+ // @ts-ignore
2815
+ if (tokens[0]?.typ != 'String' && tokens[0]?.typ != 'UrlFunc') {
2816
+ errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
2817
+ return null;
2818
+ }
2819
+ // @ts-ignore
2820
+ if (tokens[0].typ == 'UrlFunc' && tokens[1]?.typ != 'Url-token' && tokens[1]?.typ != 'String') {
2821
+ errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
2822
+ return null;
2823
+ }
2824
+ }
2825
+ if (atRule.val == 'import') {
2826
+ // @ts-ignore
2827
+ if (tokens[0].typ == 'UrlFunc' && tokens[1].typ == 'Url-token') {
2828
+ tokens.shift();
2829
+ // @ts-ignore
2830
+ tokens[0].typ = 'String';
2831
+ // @ts-ignore
2832
+ tokens[0].val = `"${tokens[0].val}"`;
2833
+ }
2834
+ // @ts-ignore
2835
+ if (tokens[0].typ == 'String') {
2836
+ if (options.resolveImport) {
2837
+ const url = tokens[0].val.slice(1, -1);
2838
+ try {
2839
+ // @ts-ignore
2840
+ const root = await options.load(url, options.src).then((src) => {
2841
+ bytesIn += src.length;
2842
+ // @ts-ignore
2843
+ return parse$1(src, Object.assign({}, options, { src: options.resolve(url, options.src).absolute }));
2844
+ });
2845
+ context.chi.push(...root.ast.chi);
2846
+ if (root.errors.length > 0) {
2847
+ errors.push(...root.errors);
2848
+ }
2849
+ return null;
2850
+ }
2851
+ catch (error) {
2852
+ console.error(error);
2853
+ }
2854
+ }
2855
+ }
2856
+ }
2857
+ // https://www.w3.org/TR/css-nesting-1/#conditionals
2858
+ // allowed nesting at-rules
2859
+ // there must be a top level rule in the stack
2860
+ const node = {
2861
+ typ: 'AtRule',
2862
+ nam: renderToken(atRule, { removeComments: true }),
2863
+ val: tokens.reduce((acc, curr, index, array) => {
2864
+ if (curr.typ == 'Whitespace') {
2865
+ if (array[index + 1]?.typ == 'Start-parens' ||
2866
+ array[index - 1]?.typ == 'End-parens' ||
2867
+ array[index - 1]?.typ == 'Func') {
2868
+ return acc;
2869
+ }
2870
+ }
2871
+ return acc + renderToken(curr, { removeComments: true });
2872
+ }, '')
2873
+ };
2874
+ if (delim.typ == 'Block-start') {
2875
+ node.chi = [];
2876
+ }
2877
+ loc = {
2878
+ sta: position,
2879
+ src
2880
+ };
2881
+ if (options.sourcemap) {
2882
+ node.loc = loc;
2883
+ }
2884
+ // @ts-ignore
2885
+ context.chi.push(node);
2886
+ return delim.typ == 'Block-start' ? node : null;
2887
+ }
2888
+ else {
2889
+ // rule
2890
+ if (delim.typ == 'Block-start') {
2891
+ const position = map.get(tokens[0]);
2892
+ if (context.typ == 'Rule') {
2893
+ if (tokens[0]?.typ == 'Iden') {
2894
+ errors.push({ action: 'drop', message: 'invalid nesting rule', location: { src, ...position } });
2895
+ return null;
2896
+ }
2897
+ }
2898
+ const sel = parseTokens(tokens, { compress: options.compress }).map(curr => renderToken(curr, { compress: true }));
2899
+ const raw = [...new Set(sel.reduce((acc, curr) => {
2900
+ if (curr == ',') {
2901
+ acc.push('');
2902
+ }
2903
+ else {
2904
+ acc[acc.length - 1] += curr;
2905
+ }
2906
+ return acc;
2907
+ }, ['']))];
2908
+ const node = {
2909
+ typ: 'Rule',
2910
+ // @ts-ignore
2911
+ sel: raw.join(','),
2912
+ chi: []
2913
+ };
2914
+ Object.defineProperty(node, 'raw', { enumerable: false, get: () => raw });
2915
+ loc = {
2916
+ sta: position,
2917
+ src
2918
+ };
2919
+ if (options.sourcemap) {
2920
+ node.loc = loc;
2921
+ }
2922
+ // @ts-ignore
2923
+ context.chi.push(node);
2924
+ return node;
2925
+ }
2926
+ else {
2927
+ // declaration
2928
+ // @ts-ignore
2929
+ let name = null;
2930
+ // @ts-ignore
2931
+ let value = null;
2932
+ for (let i = 0; i < tokens.length; i++) {
2933
+ if (tokens[i].typ == 'Comment') {
2934
+ continue;
2935
+ }
2936
+ if (tokens[i].typ == 'Colon') {
2937
+ name = tokens.slice(0, i);
2938
+ value = parseTokens(tokens.slice(i + 1), { parseColor: true, src: options.src, resolveUrls: options.resolveUrls, resolve: options.resolve, cwd: options.cwd });
2939
+ }
2940
+ }
2941
+ if (name == null) {
2942
+ name = tokens;
2943
+ }
2944
+ const position = map.get(name[0]);
2945
+ if (name.length > 0) {
2946
+ for (let i = 1; i < name.length; i++) {
2947
+ if (name[i].typ != 'Whitespace' && name[i].typ != 'Comment') {
2948
+ errors.push({
2949
+ action: 'drop',
2950
+ message: 'invalid declaration',
2951
+ location: { src, ...position }
2952
+ });
2953
+ return null;
2954
+ }
2955
+ }
2956
+ }
2957
+ // if (name.length == 0) {
2958
+ //
2959
+ // errors.push({action: 'drop', message: 'invalid declaration', location: {src, ...position}});
2960
+ // return null;
2961
+ // }
2962
+ if (value == null) {
2963
+ errors.push({ action: 'drop', message: 'invalid declaration', location: { src, ...position } });
2964
+ return null;
2965
+ }
2966
+ if (value.length == 0) {
2967
+ errors.push({ action: 'drop', message: 'invalid declaration', location: { src, ...position } });
2968
+ return null;
2969
+ }
2970
+ const node = {
2971
+ typ: 'Declaration',
2972
+ // @ts-ignore
2973
+ nam: renderToken(name.shift(), { removeComments: true }),
2974
+ // @ts-ignore
2975
+ val: value
2976
+ };
2977
+ while (node.val[0]?.typ == 'Whitespace') {
2978
+ node.val.shift();
2979
+ }
2980
+ if (node.val.length == 0) {
2981
+ errors.push({ action: 'drop', message: 'invalid declaration', location: { src, ...position } });
2982
+ return null;
2983
+ }
2984
+ // // location not needed for declaration
2985
+ // loc = <Location>{
2986
+ // sta: position,
2987
+ // src
2988
+ // };
2989
+ //
2990
+ // if (options.sourcemap) {
2991
+ //
2992
+ // node.loc = loc
2993
+ // }
2994
+ // @ts-ignore
2995
+ context.chi.push(node);
2996
+ return null;
2997
+ }
2998
+ }
2999
+ }
3000
+ function peek(count = 1) {
3001
+ if (count == 1) {
3002
+ return iterator.charAt(ind + 1);
3003
+ }
3004
+ return iterator.slice(ind + 1, ind + count + 1);
3005
+ }
3006
+ function prev(count = 1) {
3007
+ if (count == 1) {
3008
+ return ind == 0 ? '' : iterator.charAt(ind - 1);
3009
+ }
3010
+ return iterator.slice(ind - 1 - count, ind - 1);
3011
+ }
3012
+ function next(count = 1) {
3013
+ let char = '';
3014
+ while (count-- > 0 && ind < total) {
3015
+ const codepoint = iterator.charCodeAt(++ind);
3016
+ if (isNaN(codepoint)) {
3017
+ return char;
3018
+ }
3019
+ char += iterator.charAt(ind);
3020
+ if (isNewLine(codepoint)) {
3021
+ lin++;
3022
+ col = 0;
3023
+ }
3024
+ else {
3025
+ col++;
3026
+ }
3027
+ }
3028
+ return char;
3029
+ }
3030
+ function pushToken(token) {
3031
+ tokens.push(token);
3032
+ map.set(token, { ...position });
3033
+ position.ind = ind;
3034
+ position.lin = lin;
3035
+ position.col = col == 0 ? 1 : col;
3036
+ // }
3037
+ }
3038
+ function consumeWhiteSpace() {
3039
+ let count = 0;
3040
+ while (isWhiteSpace(iterator.charAt(count + ind + 1).charCodeAt(0))) {
3041
+ count++;
3042
+ }
3043
+ next(count);
3044
+ return count;
3045
+ }
3046
+ function consumeString(quoteStr) {
3047
+ const quote = quoteStr;
3048
+ let value;
3049
+ let hasNewLine = false;
3050
+ if (buffer.length > 0) {
3051
+ pushToken(getType(buffer));
3052
+ buffer = '';
3053
+ }
3054
+ buffer += quoteStr;
3055
+ while (ind < total) {
3056
+ value = peek();
3057
+ if (ind >= total) {
3058
+ pushToken({ typ: hasNewLine ? 'Bad-string' : 'Unclosed-string', val: buffer });
3059
+ break;
3060
+ }
3061
+ if (value == '\\') {
3062
+ const sequence = peek(6);
3063
+ let escapeSequence = '';
3064
+ let codepoint;
3065
+ let i;
3066
+ for (i = 1; i < sequence.length; i++) {
3067
+ codepoint = sequence.charCodeAt(i);
3068
+ if (codepoint == 0x20 ||
3069
+ (codepoint >= 0x61 && codepoint <= 0x66) ||
3070
+ (codepoint >= 0x41 && codepoint <= 0x46) ||
3071
+ (codepoint >= 0x30 && codepoint <= 0x39)) {
3072
+ escapeSequence += sequence[i];
3073
+ if (codepoint == 0x20) {
3074
+ break;
3075
+ }
3076
+ continue;
3077
+ }
3078
+ break;
3079
+ }
3080
+ // not hex or new line
3081
+ // @ts-ignore
3082
+ if (i == 1 && !isNewLine(codepoint)) {
3083
+ buffer += sequence[i];
3084
+ next(2);
3085
+ continue;
3086
+ }
3087
+ if (escapeSequence.trimEnd().length > 0) {
3088
+ const codepoint = Number(`0x${escapeSequence.trimEnd()}`);
3089
+ if (codepoint == 0 ||
3090
+ // leading surrogate
3091
+ (0xD800 <= codepoint && codepoint <= 0xDBFF) ||
3092
+ // trailing surrogate
3093
+ (0xDC00 <= codepoint && codepoint <= 0xDFFF)) {
3094
+ buffer += String.fromCodePoint(0xFFFD);
3095
+ }
3096
+ else {
3097
+ buffer += String.fromCodePoint(codepoint);
3098
+ }
3099
+ next(escapeSequence.length + 1);
3100
+ continue;
3101
+ }
3102
+ // buffer += value;
3103
+ if (ind >= total) {
3104
+ // drop '\\' at the end
3105
+ pushToken(getType(buffer));
3106
+ break;
3107
+ }
3108
+ buffer += next(2);
3109
+ continue;
3110
+ }
3111
+ if (value == quote) {
3112
+ buffer += value;
3113
+ pushToken({ typ: hasNewLine ? 'Bad-string' : 'String', val: buffer });
3114
+ next();
3115
+ // i += value.length;
3116
+ buffer = '';
3117
+ break;
3118
+ }
3119
+ if (isNewLine(value.charCodeAt(0))) {
3120
+ hasNewLine = true;
3121
+ }
3122
+ if (hasNewLine && value == ';') {
3123
+ pushToken({ typ: 'Bad-string', val: buffer });
3124
+ buffer = '';
3125
+ break;
3126
+ }
3127
+ buffer += value;
3128
+ // i += value.length;
3129
+ next();
3130
+ }
3131
+ }
3132
+ while (ind < total) {
3133
+ value = next();
3134
+ if (ind >= total) {
3135
+ if (buffer.length > 0) {
3136
+ pushToken(getType(buffer));
3137
+ buffer = '';
3138
+ }
3139
+ break;
3140
+ }
3141
+ if (isWhiteSpace(value.charCodeAt(0))) {
3142
+ if (buffer.length > 0) {
3143
+ pushToken(getType(buffer));
3144
+ buffer = '';
3145
+ }
3146
+ while (ind < total) {
3147
+ value = next();
3148
+ if (ind >= total) {
3149
+ break;
3150
+ }
3151
+ if (!isWhiteSpace(value.charCodeAt(0))) {
3152
+ break;
3153
+ }
3154
+ }
3155
+ pushToken({ typ: 'Whitespace' });
3156
+ buffer = '';
3157
+ if (ind >= total) {
3158
+ break;
3159
+ }
3160
+ }
3161
+ switch (value) {
3162
+ case '/':
3163
+ if (buffer.length > 0 && tokens.at(-1)?.typ == 'Whitespace') {
3164
+ pushToken(getType(buffer));
3165
+ buffer = '';
3166
+ if (peek() != '*') {
3167
+ pushToken(getType(value));
3168
+ break;
3169
+ }
3170
+ }
3171
+ buffer += value;
3172
+ if (peek() == '*') {
3173
+ buffer += '*';
3174
+ // i++;
3175
+ next();
3176
+ while (ind < total) {
3177
+ value = next();
3178
+ if (ind >= total) {
3179
+ pushToken({
3180
+ typ: 'Bad-comment', val: buffer
3181
+ });
3182
+ break;
3183
+ }
3184
+ if (value == '\\') {
3185
+ buffer += value;
3186
+ value = next();
3187
+ if (ind >= total) {
3188
+ pushToken({
3189
+ typ: 'Bad-comment',
3190
+ val: buffer
3191
+ });
3192
+ break;
3193
+ }
3194
+ buffer += value;
3195
+ continue;
3196
+ }
3197
+ if (value == '*') {
3198
+ buffer += value;
3199
+ value = next();
3200
+ if (ind >= total) {
3201
+ pushToken({
3202
+ typ: 'Bad-comment', val: buffer
3203
+ });
3204
+ break;
3205
+ }
3206
+ buffer += value;
3207
+ if (value == '/') {
3208
+ pushToken({ typ: 'Comment', val: buffer });
3209
+ buffer = '';
3210
+ break;
3211
+ }
3212
+ }
3213
+ else {
3214
+ buffer += value;
3215
+ }
3216
+ }
3217
+ }
3218
+ // else {
3219
+ //
3220
+ // pushToken(getType(buffer));
3221
+ // buffer = '';
3222
+ // }
3223
+ break;
3224
+ case '<':
3225
+ if (buffer.length > 0) {
3226
+ pushToken(getType(buffer));
3227
+ buffer = '';
3228
+ }
3229
+ buffer += value;
3230
+ value = next();
3231
+ if (ind >= total) {
3232
+ break;
3233
+ }
3234
+ if (peek(3) == '!--') {
3235
+ while (ind < total) {
3236
+ value = next();
3237
+ if (ind >= total) {
3238
+ break;
3239
+ }
3240
+ buffer += value;
3241
+ if (value == '>' && prev(2) == '--') {
3242
+ pushToken({
3243
+ typ: 'CDOCOMM',
3244
+ val: buffer
3245
+ });
3246
+ buffer = '';
3247
+ break;
3248
+ }
3249
+ }
3250
+ }
3251
+ if (ind >= total) {
3252
+ pushToken({ typ: 'BADCDO', val: buffer });
3253
+ buffer = '';
3254
+ }
3255
+ break;
3256
+ case '\\':
3257
+ value = next();
3258
+ // EOF
3259
+ if (ind + 1 >= total) {
3260
+ // end of stream ignore \\
3261
+ pushToken(getType(buffer));
3262
+ buffer = '';
3263
+ break;
3264
+ }
3265
+ buffer += value;
3266
+ break;
3267
+ case '"':
3268
+ case "'":
3269
+ consumeString(value);
3270
+ break;
3271
+ case '~':
3272
+ case '|':
3273
+ if (buffer.length > 0) {
3274
+ pushToken(getType(buffer));
3275
+ buffer = '';
3276
+ }
3277
+ buffer += value;
3278
+ value = next();
3279
+ if (ind >= total) {
3280
+ pushToken(getType(buffer));
3281
+ buffer = '';
3282
+ break;
3283
+ }
3284
+ if (value == '=') {
3285
+ buffer += value;
3286
+ pushToken({
3287
+ typ: buffer[0] == '~' ? 'Includes' : 'Dash-matches',
3288
+ val: buffer
3289
+ });
3290
+ buffer = '';
3291
+ break;
3292
+ }
3293
+ pushToken(getType(buffer));
3294
+ buffer = value;
3295
+ break;
3296
+ case '>':
3297
+ if (tokens[tokens.length - 1]?.typ == 'Whitespace') {
3298
+ tokens.pop();
3299
+ }
3300
+ pushToken({ typ: 'Gt' });
3301
+ consumeWhiteSpace();
3302
+ break;
3303
+ case ':':
3304
+ case ',':
3305
+ case '=':
3306
+ if (buffer.length > 0) {
3307
+ pushToken(getType(buffer));
3308
+ buffer = '';
3309
+ }
3310
+ if (value == ':' && ':' == peek()) {
3311
+ buffer += value + next();
3312
+ break;
3313
+ }
3314
+ // if (value == ',' && tokens[tokens.length - 1]?.typ == 'Whitespace') {
3315
+ //
3316
+ // tokens.pop();
3317
+ // }
3318
+ pushToken(getType(value));
3319
+ buffer = '';
3320
+ while (isWhiteSpace(peek().charCodeAt(0))) {
3321
+ next();
3322
+ }
3323
+ break;
3324
+ case ')':
3325
+ if (buffer.length > 0) {
3326
+ pushToken(getType(buffer));
3327
+ buffer = '';
3328
+ }
3329
+ pushToken({ typ: 'End-parens' });
3330
+ break;
3331
+ case '(':
3332
+ if (buffer.length == 0) {
3333
+ pushToken({ typ: 'Start-parens' });
3334
+ }
3335
+ else {
3336
+ buffer += value;
3337
+ pushToken(getType(buffer));
3338
+ buffer = '';
3339
+ const token = tokens[tokens.length - 1];
3340
+ if (token.typ == 'UrlFunc' /* && token.chi == 'url' */) {
3341
+ // consume either string or url token
3342
+ let whitespace = '';
3343
+ value = peek();
3344
+ while (isWhiteSpace(value.charCodeAt(0))) {
3345
+ whitespace += value;
3346
+ }
3347
+ if (whitespace.length > 0) {
3348
+ next(whitespace.length);
3349
+ }
3350
+ value = peek();
3351
+ if (value == '"' || value == "'") {
3352
+ consumeString(next());
3353
+ let token = tokens[tokens.length - 1];
3354
+ if (['String', 'Literal'].includes(token.typ) && urlTokenMatcher.test(token.val)) {
3355
+ if (token.val.slice(1, 6) != 'data:') {
3356
+ if (token.typ == 'String') {
3357
+ token.val = token.val.slice(1, -1);
3358
+ }
3359
+ // @ts-ignore
3360
+ token.typ = 'Url-token';
3361
+ }
3362
+ }
3363
+ break;
3364
+ }
3365
+ else {
3366
+ buffer = '';
3367
+ do {
3368
+ let cp = value.charCodeAt(0);
3369
+ // EOF -
3370
+ if (cp == null) {
3371
+ pushToken({ typ: 'Bad-url-token', val: buffer });
3372
+ break;
3373
+ }
3374
+ // ')'
3375
+ if (cp == 0x29 || cp == null) {
3376
+ if (buffer.length == 0) {
3377
+ pushToken({ typ: 'Bad-url-token', val: '' });
3378
+ }
3379
+ else {
3380
+ pushToken({ typ: 'Url-token', val: buffer });
3381
+ }
3382
+ if (cp != null) {
3383
+ pushToken(getType(next()));
3384
+ }
3385
+ break;
3386
+ }
3387
+ if (isWhiteSpace(cp)) {
3388
+ whitespace = next();
3389
+ while (true) {
3390
+ value = peek();
3391
+ cp = value.charCodeAt(0);
3392
+ if (isWhiteSpace(cp)) {
3393
+ whitespace += value;
3394
+ continue;
3395
+ }
3396
+ break;
3397
+ }
3398
+ if (cp == null || cp == 0x29) {
3399
+ continue;
3400
+ }
3401
+ // bad url token
3402
+ buffer += next(whitespace.length);
3403
+ do {
3404
+ value = peek();
3405
+ cp = value.charCodeAt(0);
3406
+ if (cp == null || cp == 0x29) {
3407
+ break;
3408
+ }
3409
+ buffer += next();
3410
+ } while (true);
3411
+ pushToken({ typ: 'Bad-url-token', val: buffer });
3412
+ continue;
3413
+ }
3414
+ buffer += next();
3415
+ value = peek();
3416
+ } while (true);
3417
+ buffer = '';
3418
+ }
3419
+ }
3420
+ }
3421
+ break;
3422
+ case '[':
3423
+ case ']':
3424
+ case '{':
3425
+ case '}':
3426
+ case ';':
3427
+ if (buffer.length > 0) {
3428
+ pushToken(getType(buffer));
3429
+ buffer = '';
3430
+ }
3431
+ pushToken(getBlockType(value));
3432
+ let node = null;
3433
+ if (value == '{' || value == ';') {
3434
+ node = await parseNode(tokens);
3435
+ if (node != null) {
3436
+ stack.push(node);
3437
+ // @ts-ignore
3438
+ context = node;
3439
+ }
3440
+ else if (value == '{') {
3441
+ // node == null
3442
+ // consume and throw away until the closing '}' or EOF
3443
+ consume('{', '}');
3444
+ }
3445
+ tokens.length = 0;
3446
+ map.clear();
3447
+ }
3448
+ else if (value == '}') {
3449
+ await parseNode(tokens);
3450
+ const previousNode = stack.pop();
3451
+ // @ts-ignore
3452
+ context = stack[stack.length - 1] || ast;
3453
+ // @ts-ignore
3454
+ if (options.removeEmpty && previousNode != null && previousNode.chi.length == 0 && context.chi[context.chi.length - 1] == previousNode) {
3455
+ context.chi.pop();
3456
+ }
3457
+ else if (previousNode != null && previousNode != ast && options.compress) {
3458
+ // @ts-ignore
3459
+ if (hasDeclaration(previousNode)) {
3460
+ deduplicateRule(previousNode);
3461
+ }
3462
+ else {
3463
+ deduplicate(previousNode, options);
3464
+ }
3465
+ }
3466
+ tokens.length = 0;
3467
+ map.clear();
3468
+ buffer = '';
3469
+ }
3470
+ break;
3471
+ case '!':
3472
+ if (buffer.length > 0) {
3473
+ pushToken(getType(buffer));
3474
+ buffer = '';
3475
+ }
3476
+ const important = peek(9);
3477
+ if (important == 'important') {
3478
+ if (tokens[tokens.length - 1]?.typ == 'Whitespace') {
3479
+ tokens.pop();
3480
+ }
3481
+ pushToken({ typ: 'Important' });
3482
+ next(9);
3483
+ buffer = '';
3484
+ break;
3485
+ }
3486
+ buffer = '!';
3487
+ break;
3488
+ default:
3489
+ buffer += value;
3490
+ break;
3491
+ }
3492
+ }
3493
+ if (buffer.length > 0) {
3494
+ pushToken(getType(buffer));
3495
+ }
3496
+ if (tokens.length > 0) {
3497
+ await parseNode(tokens);
3498
+ }
3499
+ if (options.compress) {
3500
+ while (stack.length > 0) {
3501
+ const node = stack.pop();
3502
+ if (hasDeclaration(node)) {
3503
+ deduplicateRule(node, options);
3504
+ }
3505
+ else {
3506
+ deduplicate(node, options);
3507
+ }
3508
+ }
3509
+ if (ast.chi.length > 0) {
3510
+ deduplicate(ast, options);
3511
+ }
3512
+ }
3513
+ return { ast, errors, bytesIn };
3514
+ }
3515
+ function parseTokens(tokens, options = {}) {
3516
+ for (let i = 0; i < tokens.length; i++) {
3517
+ const t = tokens[i];
3518
+ if (t.typ == 'Whitespace' && ((i == 0 ||
3519
+ i + 1 == tokens.length ||
3520
+ ['Comma', 'Start-parens'].includes(tokens[i + 1].typ) ||
3521
+ (i > 0 && funcLike.includes(tokens[i - 1].typ))))) {
3522
+ tokens.splice(i--, 1);
3523
+ continue;
3524
+ }
3525
+ if (t.typ == 'Colon') {
3526
+ const typ = tokens[i + 1]?.typ;
3527
+ if (typ != null) {
3528
+ if (typ == 'Func') {
3529
+ tokens[i + 1].val = ':' + tokens[i + 1].val;
3530
+ tokens[i + 1].typ = 'Pseudo-class-func';
3531
+ }
3532
+ else if (typ == 'Iden') {
3533
+ tokens[i + 1].val = ':' + tokens[i + 1].val;
3534
+ tokens[i + 1].typ = 'Pseudo-class';
3535
+ }
3536
+ if (typ == 'Func' || typ == 'Iden') {
3537
+ tokens.splice(i, 1);
3538
+ i--;
3539
+ continue;
3540
+ }
3541
+ }
3542
+ }
3543
+ if (t.typ == 'Attr-start') {
3544
+ let k = i;
3545
+ let inAttr = 1;
3546
+ while (++k < tokens.length) {
3547
+ if (tokens[k].typ == 'Attr-end') {
3548
+ inAttr--;
3549
+ }
3550
+ else if (tokens[k].typ == 'Attr-start') {
3551
+ inAttr++;
3552
+ }
3553
+ if (inAttr == 0) {
3554
+ break;
3555
+ }
3556
+ }
3557
+ Object.assign(t, { typ: 'Attr', chi: tokens.splice(i + 1, k - i) });
3558
+ // @ts-ignore
3559
+ if (t.chi.at(-1).typ == 'Attr-end') {
3560
+ // @ts-ignore
3561
+ t.chi.pop();
3562
+ // @ts-ignore
3563
+ if (t.chi.length > 1) {
3564
+ /*(<AttrToken>t).chi =*/
3565
+ // @ts-ignore
3566
+ parseTokens(t.chi, options);
3567
+ }
3568
+ // @ts-ignore
3569
+ t.chi.forEach(val => {
3570
+ if (val.typ == 'String') {
3571
+ const slice = val.val.slice(1, -1);
3572
+ if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
3573
+ Object.assign(val, { typ: 'Iden', val: slice });
3574
+ }
3575
+ }
3576
+ });
3577
+ }
3578
+ continue;
3579
+ }
3580
+ if (funcLike.includes(t.typ)) {
3581
+ let parens = 1;
3582
+ let k = i;
3583
+ while (++k < tokens.length) {
3584
+ if (tokens[k].typ == 'Colon') {
3585
+ const typ = tokens[k + 1]?.typ;
3586
+ if (typ != null) {
3587
+ if (typ == 'Iden') {
3588
+ tokens[k + 1].typ = 'Pseudo-class';
3589
+ tokens[k + 1].val = ':' + tokens[k + 1].val;
3590
+ }
3591
+ else if (typ == 'Func') {
3592
+ tokens[k + 1].typ = 'Pseudo-class-func';
3593
+ tokens[k + 1].val = ':' + tokens[k + 1].val;
3594
+ }
3595
+ if (typ == 'Func' || typ == 'Iden') {
3596
+ tokens.splice(k, 1);
3597
+ k--;
3598
+ continue;
3599
+ }
3600
+ }
3601
+ }
3602
+ if (funcLike.includes(tokens[k].typ)) {
3603
+ parens++;
3604
+ }
3605
+ else if (tokens[k].typ == 'End-parens') {
3606
+ parens--;
3607
+ }
3608
+ if (parens == 0) {
3609
+ break;
3610
+ }
3611
+ }
3612
+ // @ts-ignore
3613
+ t.chi = tokens.splice(i + 1, k - i);
3614
+ // @ts-ignore
3615
+ if (t.chi.at(-1)?.typ == 'End-parens') {
3616
+ // @ts-ignore
3617
+ t.chi.pop();
3618
+ }
3619
+ // @ts-ignore
3620
+ if (options.parseColor && ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk'].includes(t.val)) {
3621
+ let isColor = true;
3622
+ // @ts-ignore
3623
+ for (const v of t.chi) {
3624
+ if (v.typ == 'Func' && v.val == 'var') {
3625
+ isColor = false;
3626
+ break;
3627
+ }
3628
+ }
3629
+ if (!isColor) {
3630
+ continue;
3631
+ }
3632
+ // @ts-ignore
3633
+ t.typ = 'Color';
3634
+ // @ts-ignore
3635
+ t.kin = t.val;
3636
+ // @ts-ignore
3637
+ let m = t.chi.length;
3638
+ while (m-- > 0) {
3639
+ // @ts-ignore
3640
+ if (t.chi[m].typ == 'Literal') {
3641
+ // @ts-ignore
3642
+ if (t.chi[m + 1]?.typ == 'Whitespace') {
3643
+ // @ts-ignore
3644
+ t.chi.splice(m + 1, 1);
3645
+ }
3646
+ // @ts-ignore
3647
+ if (t.chi[m - 1]?.typ == 'Whitespace') {
3648
+ // @ts-ignore
3649
+ t.chi.splice(m - 1, 1);
3650
+ m--;
3651
+ }
3652
+ }
3653
+ }
3654
+ }
3655
+ else if (t.typ == 'UrlFunc') {
3656
+ // @ts-ignore
3657
+ if (t.chi[0]?.typ == 'String') {
3658
+ // @ts-ignore
3659
+ const value = t.chi[0].val.slice(1, -1);
3660
+ if (t.chi[0].val.slice(1, 5) != 'data:' && urlTokenMatcher.test(value)) {
3661
+ // @ts-ignore
3662
+ t.chi[0].typ = 'Url-token';
3663
+ // @ts-ignore
3664
+ t.chi[0].val = options.src !== '' && options.resolveUrls ? options.resolve(value, options.src).absolute : value;
3665
+ }
3666
+ }
3667
+ if (t.chi[0]?.typ == 'Url-token') {
3668
+ if (options.src !== '' && options.resolveUrls) {
3669
+ // @ts-ignore
3670
+ t.chi[0].val = options.resolve(t.chi[0].val, options.src, options.cwd).relative;
3671
+ }
3672
+ }
3673
+ }
3674
+ // @ts-ignore
3675
+ if (t.chi.length > 0) {
3676
+ // @ts-ignore
3677
+ parseTokens(t.chi, options);
3678
+ if (t.typ == 'Pseudo-class-func' && t.val == ':is' && options.compress) {
3679
+ //
3680
+ const count = t.chi.filter(t => t.typ != 'Comment').length;
3681
+ if (count == 1 ||
3682
+ (i == 0 &&
3683
+ (tokens[i + 1]?.typ == 'Comma' || tokens.length == i + 1)) ||
3684
+ (tokens[i - 1]?.typ == 'Comma' && (tokens[i + 1]?.typ == 'Comma' || tokens.length == i + 1))) {
3685
+ tokens.splice(i, 1, ...t.chi);
3686
+ i = Math.max(0, i - t.chi.length);
3687
+ }
3688
+ }
3689
+ }
3690
+ continue;
3691
+ }
3692
+ if (options.parseColor) {
3693
+ if (t.typ == 'Iden') {
3694
+ // named color
3695
+ const value = t.val.toLowerCase();
3696
+ if (COLORS_NAMES[value] != null) {
3697
+ Object.assign(t, {
3698
+ typ: 'Color',
3699
+ val: COLORS_NAMES[value].length < value.length ? COLORS_NAMES[value] : value,
3700
+ kin: 'hex'
3701
+ });
3702
+ }
3703
+ continue;
3704
+ }
3705
+ if (t.typ == 'Hash' && isHexColor(t.val)) {
3706
+ // hex color
3707
+ // @ts-ignore
3708
+ t.typ = 'Color';
3709
+ // @ts-ignore
3710
+ t.kin = 'hex';
3711
+ }
3712
+ }
3713
+ }
3714
+ return tokens;
3715
+ }
3716
+ function getBlockType(chr) {
3717
+ if (chr == ';') {
3718
+ return { typ: 'Semi-colon' };
3719
+ }
3720
+ if (chr == '{') {
3721
+ return { typ: 'Block-start' };
3722
+ }
3723
+ if (chr == '}') {
3724
+ return { typ: 'Block-end' };
3725
+ }
3726
+ if (chr == '[') {
3727
+ return { typ: 'Attr-start' };
3728
+ }
3729
+ if (chr == ']') {
3730
+ return { typ: 'Attr-end' };
3731
+ }
3732
+ throw new Error(`unhandled token: '${chr}'`);
3733
+ }
3734
+
3735
+ function* walk(node) {
3736
+ // @ts-ignore
3737
+ yield* doWalk(node, null, null);
3738
+ }
3739
+ function* doWalk(node, parent, root) {
3740
+ yield { node, parent, root };
3741
+ if ('chi' in node) {
3742
+ for (const child of node.chi) {
3743
+ yield* doWalk(child, node, (root == null ? node : root));
3744
+ }
3745
+ }
3746
+ }
3747
+
3748
+ async function transform$1(css, options = {}) {
3749
+ options = { compress: true, removeEmpty: true, ...options };
3750
+ const startTime = performance.now();
3751
+ const parseResult = await parse$1(css, options);
3752
+ const renderTime = performance.now();
3753
+ const rendered = render(parseResult.ast, options);
3754
+ const endTime = performance.now();
3755
+ return {
3756
+ ...parseResult, ...rendered, stats: {
3757
+ bytesIn: parseResult.bytesIn,
3758
+ bytesOut: rendered.code.length,
3759
+ parse: `${(renderTime - startTime).toFixed(2)}ms`,
3760
+ render: `${(endTime - renderTime).toFixed(2)}ms`,
3761
+ total: `${(endTime - startTime).toFixed(2)}ms`
3762
+ }
3763
+ };
3764
+ }
3765
+
3766
+ const matchUrl = /^(https?:)?\/\//;
3767
+ function dirname(path) {
3768
+ if (path == '/' || path === '') {
3769
+ return path;
3770
+ }
3771
+ let i = 0;
3772
+ let parts = [''];
3773
+ for (; i < path.length; i++) {
3774
+ const chr = path.charAt(i);
3775
+ if (chr == '/') {
3776
+ parts.push('');
3777
+ }
3778
+ else if (chr == '?' || chr == '#') {
3779
+ break;
3780
+ }
3781
+ else {
3782
+ parts[parts.length - 1] += chr;
3783
+ }
3784
+ }
3785
+ parts.pop();
3786
+ return parts.length == 0 ? '/' : parts.join('/');
3787
+ }
3788
+ function splitPath(result) {
3789
+ const parts = [''];
3790
+ let i = 0;
3791
+ for (; i < result.length; i++) {
3792
+ const chr = result.charAt(i);
3793
+ if (chr == '/') {
3794
+ parts.push('');
3795
+ }
3796
+ else if (chr == '?' || chr == '#') {
3797
+ break;
3798
+ }
3799
+ else {
3800
+ parts[parts.length - 1] += chr;
3801
+ }
3802
+ }
3803
+ let k = parts.length;
3804
+ while (k--) {
3805
+ if (parts[k] == '.') {
3806
+ parts.splice(k, 1);
3807
+ }
3808
+ else if (parts[k] == '..') {
3809
+ parts.splice(k - 1, 2);
3810
+ }
3811
+ }
3812
+ return { parts, i };
3813
+ }
3814
+ function resolve(url, currentDirectory, cwd) {
3815
+ if (matchUrl.test(url)) {
3816
+ return {
3817
+ absolute: url,
3818
+ relative: url
3819
+ };
3820
+ }
3821
+ if (matchUrl.test(currentDirectory)) {
3822
+ const path = new URL(url, currentDirectory).href;
3823
+ return {
3824
+ absolute: path,
3825
+ relative: path
3826
+ };
3827
+ }
3828
+ let result;
3829
+ if (url.charAt(0) == '/') {
3830
+ result = url;
3831
+ }
3832
+ else if (currentDirectory.charAt(0) == '/') {
3833
+ result = dirname(currentDirectory) + '/' + url;
3834
+ }
3835
+ else if (currentDirectory === '' || dirname(currentDirectory) === '') {
3836
+ result = url;
3837
+ }
3838
+ else {
3839
+ result = dirname(currentDirectory) + '/' + url;
3840
+ }
3841
+ let { parts, i } = splitPath(result);
3842
+ if (parts.length == 0) {
3843
+ const path = result.charAt(0) == '/' ? '/' : '';
3844
+ return {
3845
+ absolute: path,
3846
+ relative: path
3847
+ };
3848
+ }
3849
+ const absolute = parts.join('/');
3850
+ const { parts: dirs } = splitPath(cwd ?? currentDirectory);
3851
+ for (const p of dirs) {
3852
+ if (parts[0] == p) {
3853
+ parts.shift();
3854
+ }
3855
+ else {
3856
+ parts.unshift('..');
3857
+ }
3858
+ }
3859
+ return {
3860
+ absolute,
3861
+ relative: parts.join('/') + (i < result.length ? result.slice(i) : '')
3862
+ };
3863
+ }
3864
+
3865
+ function parseResponse(response) {
3866
+ if (!response.ok) {
3867
+ throw new Error(`${response.status} ${response.statusText} ${response.url}`);
3868
+ }
3869
+ return response.text();
3870
+ }
3871
+ async function load(url, currentFile) {
3872
+ const resolved = resolve(url, currentFile);
3873
+ return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : promises.readFile(resolved.absolute, { encoding: 'utf-8' });
3874
+ }
3875
+
3876
+ function parse(iterator, opt = {}) {
3877
+ Object.assign(opt, { load, resolve, cwd: opt.cwd ?? process.cwd() });
3878
+ return parse$1(iterator, opt);
3879
+ }
3880
+ function transform(css, options = {}) {
3881
+ Object.assign(options, { load, resolve, cwd: options.cwd ?? process.cwd() });
3882
+ return transform$1(css, options);
3883
+ }
3884
+
3885
+ exports.deduplicate = deduplicate;
3886
+ exports.deduplicateRule = deduplicateRule;
3887
+ exports.dirname = dirname;
3888
+ exports.hasDeclaration = hasDeclaration;
3889
+ exports.load = load;
3890
+ exports.matchUrl = matchUrl;
3891
+ exports.parse = parse;
3892
+ exports.render = render;
3893
+ exports.renderToken = renderToken;
3894
+ exports.resolve = resolve;
3895
+ exports.transform = transform;
3896
+ exports.walk = walk;