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