@tbela99/css-parser 0.0.1-rc4 → 0.0.1-rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -2,1079 +2,6 @@
2
2
 
3
3
  var promises = require('fs/promises');
4
4
 
5
- // https://www.w3.org/TR/CSS21/syndata.html#syntax
6
- // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
7
- // '\\'
8
- const REVERSE_SOLIDUS = 0x5c;
9
- const dimensionUnits = [
10
- 'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
11
- 'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
12
- 'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
13
- 'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
14
- ];
15
- function isLength(dimension) {
16
- return 'unit' in dimension && dimensionUnits.includes(dimension.unit.toLowerCase());
17
- }
18
- function isResolution(dimension) {
19
- return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
20
- }
21
- function isAngle(dimension) {
22
- return 'unit' in dimension && ['rad', 'turn', 'deg', 'grad'].includes(dimension.unit.toLowerCase());
23
- }
24
- function isTime(dimension) {
25
- return 'unit' in dimension && ['ms', 's'].includes(dimension.unit.toLowerCase());
26
- }
27
- function isFrequency(dimension) {
28
- return 'unit' in dimension && ['hz', 'khz'].includes(dimension.unit.toLowerCase());
29
- }
30
- function isLetter(codepoint) {
31
- // lowercase
32
- return (codepoint >= 0x61 && codepoint <= 0x7a) ||
33
- // uppercase
34
- (codepoint >= 0x41 && codepoint <= 0x5a);
35
- }
36
- function isNonAscii(codepoint) {
37
- return codepoint >= 0x80;
38
- }
39
- function isIdentStart(codepoint) {
40
- // _
41
- return codepoint == 0x5f || isLetter(codepoint) || isNonAscii(codepoint);
42
- }
43
- function isDigit(codepoint) {
44
- return codepoint >= 0x30 && codepoint <= 0x39;
45
- }
46
- function isIdentCodepoint(codepoint) {
47
- // -
48
- return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
49
- }
50
- function isIdent(name) {
51
- const j = name.length - 1;
52
- let i = 0;
53
- let codepoint = name.charCodeAt(0);
54
- // -
55
- if (codepoint == 0x2d) {
56
- const nextCodepoint = name.charCodeAt(1);
57
- if (Number.isNaN(nextCodepoint)) {
58
- return false;
59
- }
60
- // -
61
- if (nextCodepoint == 0x2d) {
62
- return true;
63
- }
64
- if (nextCodepoint == REVERSE_SOLIDUS) {
65
- return name.length > 2 && !isNewLine(name.charCodeAt(2));
66
- }
67
- return true;
68
- }
69
- if (!isIdentStart(codepoint)) {
70
- return false;
71
- }
72
- while (i < j) {
73
- i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
74
- codepoint = name.charCodeAt(i);
75
- if (!isIdentCodepoint(codepoint)) {
76
- return false;
77
- }
78
- }
79
- return true;
80
- }
81
- function isPseudo(name) {
82
- if (name.charAt(0) != ':') {
83
- return false;
84
- }
85
- if (name.endsWith('(')) {
86
- return isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1));
87
- }
88
- return isIdent(name.charAt(1) == ':' ? name.slice(2) : name.slice(1));
89
- }
90
- function isHash(name) {
91
- if (name.charAt(0) != '#') {
92
- return false;
93
- }
94
- return isIdent(name.charAt(1));
95
- }
96
- function isNumber(name) {
97
- if (name.length == 0) {
98
- return false;
99
- }
100
- let codepoint = name.charCodeAt(0);
101
- let i = 0;
102
- const j = name.length;
103
- if (j == 1 && !isDigit(codepoint)) {
104
- return false;
105
- }
106
- // '+' '-'
107
- if ([0x2b, 0x2d].includes(codepoint)) {
108
- i++;
109
- }
110
- // consume digits
111
- while (i < j) {
112
- codepoint = name.charCodeAt(i);
113
- if (isDigit(codepoint)) {
114
- i++;
115
- continue;
116
- }
117
- // '.' 'E' 'e'
118
- if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
119
- break;
120
- }
121
- return false;
122
- }
123
- // '.'
124
- if (codepoint == 0x2e) {
125
- if (!isDigit(name.charCodeAt(++i))) {
126
- return false;
127
- }
128
- }
129
- while (i < j) {
130
- codepoint = name.charCodeAt(i);
131
- if (isDigit(codepoint)) {
132
- i++;
133
- continue;
134
- }
135
- // 'E' 'e'
136
- if (codepoint == 0x45 || codepoint == 0x65) {
137
- i++;
138
- break;
139
- }
140
- return false;
141
- }
142
- // 'E' 'e'
143
- if (codepoint == 0x45 || codepoint == 0x65) {
144
- if (i == j) {
145
- return false;
146
- }
147
- codepoint = name.charCodeAt(i + 1);
148
- // '+' '-'
149
- if ([0x2b, 0x2d].includes(codepoint)) {
150
- i++;
151
- }
152
- codepoint = name.charCodeAt(i + 1);
153
- if (!isDigit(codepoint)) {
154
- return false;
155
- }
156
- }
157
- while (++i < j) {
158
- codepoint = name.charCodeAt(i);
159
- if (!isDigit(codepoint)) {
160
- return false;
161
- }
162
- }
163
- return true;
164
- }
165
- function isDimension(name) {
166
- let index = name.length;
167
- while (index--) {
168
- if (isLetter(name.charCodeAt(index))) {
169
- continue;
170
- }
171
- index++;
172
- break;
173
- }
174
- const number = name.slice(0, index);
175
- return number.length > 0 && isIdentStart(name.charCodeAt(index)) && isNumber(number);
176
- }
177
- function isPercentage(name) {
178
- return name.endsWith('%') && isNumber(name.slice(0, -1));
179
- }
180
- function parseDimension(name) {
181
- let index = name.length;
182
- while (index--) {
183
- if (isLetter(name.charCodeAt(index))) {
184
- continue;
185
- }
186
- index++;
187
- break;
188
- }
189
- const dimension = { typ: 'Dimension', val: name.slice(0, index), unit: name.slice(index) };
190
- if (isAngle(dimension)) {
191
- // @ts-ignore
192
- dimension.typ = 'Angle';
193
- }
194
- else if (isLength(dimension)) {
195
- // @ts-ignore
196
- dimension.typ = 'Length';
197
- }
198
- else if (isTime(dimension)) {
199
- // @ts-ignore
200
- dimension.typ = 'Time';
201
- }
202
- else if (isResolution(dimension)) {
203
- // @ts-ignore
204
- dimension.typ = 'Resolution';
205
- if (dimension.unit == 'dppx') {
206
- dimension.unit = 'x';
207
- }
208
- }
209
- else if (isFrequency(dimension)) {
210
- // @ts-ignore
211
- dimension.typ = 'Frequency';
212
- }
213
- return dimension;
214
- }
215
- function isHexColor(name) {
216
- if (name.charAt(0) != '#' || ![4, 5, 7, 9].includes(name.length)) {
217
- return false;
218
- }
219
- for (let chr of name.slice(1)) {
220
- let codepoint = chr.charCodeAt(0);
221
- if (!isDigit(codepoint) &&
222
- // A-F
223
- !(codepoint >= 0x41 && codepoint <= 0x46) &&
224
- // a-f
225
- !(codepoint >= 0x61 && codepoint <= 0x66)) {
226
- return false;
227
- }
228
- }
229
- return true;
230
- }
231
- function isHexDigit(name) {
232
- if (name.length || name.length > 6) {
233
- return false;
234
- }
235
- for (let chr of name) {
236
- let codepoint = chr.charCodeAt(0);
237
- if (!isDigit(codepoint) &&
238
- // A F
239
- !(codepoint >= 0x41 && codepoint <= 0x46) &&
240
- // a f
241
- !(codepoint >= 0x61 && codepoint <= 0x66)) {
242
- return false;
243
- }
244
- }
245
- return true;
246
- }
247
- function isFunction(name) {
248
- return name.endsWith('(') && isIdent(name.slice(0, -1));
249
- }
250
- function isAtKeyword(name) {
251
- return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
252
- }
253
- function isNewLine(codepoint) {
254
- // \n \r \f
255
- return codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
256
- }
257
- function isWhiteSpace(codepoint) {
258
- return codepoint == 0x9 || codepoint == 0x20 ||
259
- // isNewLine
260
- codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
261
- }
262
-
263
- var properties = {
264
- inset: {
265
- shorthand: "inset",
266
- properties: [
267
- "top",
268
- "right",
269
- "bottom",
270
- "left"
271
- ],
272
- types: [
273
- "Length",
274
- "Perc"
275
- ],
276
- multiple: false,
277
- separator: null,
278
- keywords: [
279
- "auto"
280
- ]
281
- },
282
- top: {
283
- shorthand: "inset"
284
- },
285
- right: {
286
- shorthand: "inset"
287
- },
288
- bottom: {
289
- shorthand: "inset"
290
- },
291
- left: {
292
- shorthand: "inset"
293
- },
294
- margin: {
295
- shorthand: "margin",
296
- properties: [
297
- "margin-top",
298
- "margin-right",
299
- "margin-bottom",
300
- "margin-left"
301
- ],
302
- types: [
303
- "Length",
304
- "Perc"
305
- ],
306
- multiple: false,
307
- separator: null,
308
- keywords: [
309
- "auto"
310
- ]
311
- },
312
- "margin-top": {
313
- shorthand: "margin"
314
- },
315
- "margin-right": {
316
- shorthand: "margin"
317
- },
318
- "margin-bottom": {
319
- shorthand: "margin"
320
- },
321
- "margin-left": {
322
- shorthand: "margin"
323
- },
324
- padding: {
325
- shorthand: "padding",
326
- properties: [
327
- "padding-top",
328
- "padding-right",
329
- "padding-bottom",
330
- "padding-left"
331
- ],
332
- types: [
333
- "Length",
334
- "Perc"
335
- ],
336
- keywords: [
337
- ]
338
- },
339
- "padding-top": {
340
- shorthand: "padding"
341
- },
342
- "padding-right": {
343
- shorthand: "padding"
344
- },
345
- "padding-bottom": {
346
- shorthand: "padding"
347
- },
348
- "padding-left": {
349
- shorthand: "padding"
350
- },
351
- "border-radius": {
352
- shorthand: "border-radius",
353
- properties: [
354
- "border-top-left-radius",
355
- "border-top-right-radius",
356
- "border-bottom-right-radius",
357
- "border-bottom-left-radius"
358
- ],
359
- types: [
360
- "Length",
361
- "Perc"
362
- ],
363
- multiple: true,
364
- separator: "/",
365
- keywords: [
366
- ]
367
- },
368
- "border-top-left-radius": {
369
- shorthand: "border-radius"
370
- },
371
- "border-top-right-radius": {
372
- shorthand: "border-radius"
373
- },
374
- "border-bottom-right-radius": {
375
- shorthand: "border-radius"
376
- },
377
- "border-bottom-left-radius": {
378
- shorthand: "border-radius"
379
- },
380
- "border-width": {
381
- shorthand: "border-width",
382
- map: "border",
383
- properties: [
384
- "border-top-width",
385
- "border-right-width",
386
- "border-bottom-width",
387
- "border-left-width"
388
- ],
389
- types: [
390
- "Length",
391
- "Perc"
392
- ],
393
- "default": [
394
- "medium"
395
- ],
396
- keywords: [
397
- "thin",
398
- "medium",
399
- "thick"
400
- ]
401
- },
402
- "border-top-width": {
403
- map: "border",
404
- shorthand: "border-width"
405
- },
406
- "border-right-width": {
407
- map: "border",
408
- shorthand: "border-width"
409
- },
410
- "border-bottom-width": {
411
- map: "border",
412
- shorthand: "border-width"
413
- },
414
- "border-left-width": {
415
- map: "border",
416
- shorthand: "border-width"
417
- },
418
- "border-style": {
419
- shorthand: "border-style",
420
- map: "border",
421
- properties: [
422
- "border-top-style",
423
- "border-right-style",
424
- "border-bottom-style",
425
- "border-left-style"
426
- ],
427
- types: [
428
- ],
429
- "default": [
430
- "none"
431
- ],
432
- keywords: [
433
- "none",
434
- "hidden",
435
- "dotted",
436
- "dashed",
437
- "solid",
438
- "double",
439
- "groove",
440
- "ridge",
441
- "inset",
442
- "outset"
443
- ]
444
- },
445
- "border-top-style": {
446
- map: "border",
447
- shorthand: "border-style"
448
- },
449
- "border-right-style": {
450
- map: "border",
451
- shorthand: "border-style"
452
- },
453
- "border-bottom-style": {
454
- map: "border",
455
- shorthand: "border-style"
456
- },
457
- "border-left-style": {
458
- map: "border",
459
- shorthand: "border-style"
460
- },
461
- "border-color": {
462
- shorthand: "border-color",
463
- map: "border",
464
- properties: [
465
- "border-top-color",
466
- "border-right-color",
467
- "border-bottom-color",
468
- "border-left-color"
469
- ],
470
- types: [
471
- "Color"
472
- ],
473
- "default": [
474
- "currentcolor"
475
- ],
476
- keywords: [
477
- ]
478
- },
479
- "border-top-color": {
480
- map: "border",
481
- shorthand: "border-color"
482
- },
483
- "border-right-color": {
484
- map: "border",
485
- shorthand: "border-color"
486
- },
487
- "border-bottom-color": {
488
- map: "border",
489
- shorthand: "border-color"
490
- },
491
- "border-left-color": {
492
- map: "border",
493
- shorthand: "border-color"
494
- }
495
- };
496
- var map = {
497
- border: {
498
- shorthand: "border",
499
- pattern: "border-color border-style border-width",
500
- keywords: [
501
- "none"
502
- ],
503
- "default": [
504
- "0",
505
- "none"
506
- ],
507
- properties: {
508
- "border-color": {
509
- types: [
510
- "Color"
511
- ],
512
- "default": [
513
- "currentcolor"
514
- ],
515
- keywords: [
516
- ]
517
- },
518
- "border-style": {
519
- types: [
520
- ],
521
- "default": [
522
- "none"
523
- ],
524
- keywords: [
525
- "none",
526
- "hidden",
527
- "dotted",
528
- "dashed",
529
- "solid",
530
- "double",
531
- "groove",
532
- "ridge",
533
- "inset",
534
- "outset"
535
- ]
536
- },
537
- "border-width": {
538
- types: [
539
- "Length",
540
- "Perc"
541
- ],
542
- "default": [
543
- "medium"
544
- ],
545
- keywords: [
546
- "thin",
547
- "medium",
548
- "thick"
549
- ]
550
- }
551
- }
552
- },
553
- "border-color": {
554
- shorthand: "border"
555
- },
556
- "border-style": {
557
- shorthand: "border"
558
- },
559
- "border-width": {
560
- shorthand: "border"
561
- },
562
- outline: {
563
- shorthand: "outline",
564
- pattern: "outline-color outline-style outline-width",
565
- keywords: [
566
- "none"
567
- ],
568
- "default": [
569
- "0",
570
- "none"
571
- ],
572
- properties: {
573
- "outline-color": {
574
- types: [
575
- "Color"
576
- ],
577
- "default": [
578
- "currentColor"
579
- ],
580
- keywords: [
581
- "currentColor"
582
- ]
583
- },
584
- "outline-style": {
585
- types: [
586
- ],
587
- "default": [
588
- "none"
589
- ],
590
- keywords: [
591
- "auto",
592
- "none",
593
- "dotted",
594
- "dashed",
595
- "solid",
596
- "double",
597
- "groove",
598
- "ridge",
599
- "inset",
600
- "outset"
601
- ]
602
- },
603
- "outline-width": {
604
- types: [
605
- "Length",
606
- "Perc"
607
- ],
608
- "default": [
609
- "medium"
610
- ],
611
- keywords: [
612
- "thin",
613
- "medium",
614
- "thick"
615
- ]
616
- }
617
- }
618
- },
619
- "outline-color": {
620
- shorthand: "outline"
621
- },
622
- "outline-style": {
623
- shorthand: "outline"
624
- },
625
- "outline-width": {
626
- shorthand: "outline"
627
- },
628
- font: {
629
- shorthand: "font",
630
- pattern: "font-weight font-style font-size line-height font-stretch font-variant font-family",
631
- keywords: [
632
- "caption",
633
- "icon",
634
- "menu",
635
- "message-box",
636
- "small-caption",
637
- "status-bar",
638
- "-moz-window, ",
639
- "-moz-document, ",
640
- "-moz-desktop, ",
641
- "-moz-info, ",
642
- "-moz-dialog",
643
- "-moz-button",
644
- "-moz-pull-down-menu",
645
- "-moz-list",
646
- "-moz-field"
647
- ],
648
- "default": [
649
- ],
650
- properties: {
651
- "font-weight": {
652
- types: [
653
- "Number"
654
- ],
655
- "default": [
656
- "normal",
657
- "400"
658
- ],
659
- keywords: [
660
- "normal",
661
- "bold",
662
- "lighter",
663
- "bolder"
664
- ],
665
- constraints: {
666
- value: {
667
- min: "1",
668
- max: "1000"
669
- }
670
- },
671
- mapping: {
672
- thin: "100",
673
- hairline: "100",
674
- "extra light": "200",
675
- "ultra light": "200",
676
- light: "300",
677
- normal: "400",
678
- regular: "400",
679
- medium: "500",
680
- "semi bold": "600",
681
- "demi bold": "600",
682
- bold: "700",
683
- "extra bold": "800",
684
- "ultra bold": "800",
685
- black: "900",
686
- heavy: "900",
687
- "extra black": "950",
688
- "ultra black": "950"
689
- }
690
- },
691
- "font-style": {
692
- types: [
693
- "Angle"
694
- ],
695
- "default": [
696
- "normal"
697
- ],
698
- keywords: [
699
- "normal",
700
- "italic",
701
- "oblique"
702
- ]
703
- },
704
- "font-size": {
705
- types: [
706
- "Length",
707
- "Perc"
708
- ],
709
- "default": [
710
- ],
711
- keywords: [
712
- "xx-small",
713
- "x-small",
714
- "small",
715
- "medium",
716
- "large",
717
- "x-large",
718
- "xx-large",
719
- "xxx-large",
720
- "larger",
721
- "smaller"
722
- ],
723
- required: true
724
- },
725
- "line-height": {
726
- types: [
727
- "Length",
728
- "Perc",
729
- "Number"
730
- ],
731
- "default": [
732
- "normal"
733
- ],
734
- keywords: [
735
- "normal"
736
- ],
737
- previous: "font-size",
738
- prefix: {
739
- typ: "Literal",
740
- val: "/"
741
- }
742
- },
743
- "font-stretch": {
744
- types: [
745
- "Perc"
746
- ],
747
- "default": [
748
- "normal"
749
- ],
750
- keywords: [
751
- "ultra-condensed",
752
- "extra-condensed",
753
- "condensed",
754
- "semi-condensed",
755
- "normal",
756
- "semi-expanded",
757
- "expanded",
758
- "extra-expanded",
759
- "ultra-expanded"
760
- ],
761
- mapping: {
762
- "ultra-condensed": "50%",
763
- "extra-condensed": "62.5%",
764
- condensed: "75%",
765
- "semi-condensed": "87.5%",
766
- normal: "100%",
767
- "semi-expanded": "112.5%",
768
- expanded: "125%",
769
- "extra-expanded": "150%",
770
- "ultra-expanded": "200%"
771
- }
772
- },
773
- "font-variant": {
774
- types: [
775
- ],
776
- "default": [
777
- "normal"
778
- ],
779
- keywords: [
780
- "normal",
781
- "none",
782
- "common-ligatures",
783
- "no-common-ligatures",
784
- "discretionary-ligatures",
785
- "no-discretionary-ligatures",
786
- "historical-ligatures",
787
- "no-historical-ligatures",
788
- "contextual",
789
- "no-contextual",
790
- "historical-forms",
791
- "small-caps",
792
- "all-small-caps",
793
- "petite-caps",
794
- "all-petite-caps",
795
- "unicase",
796
- "titling-caps",
797
- "ordinal",
798
- "slashed-zero",
799
- "lining-nums",
800
- "oldstyle-nums",
801
- "proportional-nums",
802
- "tabular-nums",
803
- "diagonal-fractions",
804
- "stacked-fractions",
805
- "ordinal",
806
- "slashed-zero",
807
- "ruby",
808
- "jis78",
809
- "jis83",
810
- "jis90",
811
- "jis04",
812
- "simplified",
813
- "traditional",
814
- "full-width",
815
- "proportional-width",
816
- "ruby",
817
- "sub",
818
- "super",
819
- "text",
820
- "emoji",
821
- "unicode"
822
- ]
823
- },
824
- "font-family": {
825
- types: [
826
- "String",
827
- "Iden"
828
- ],
829
- "default": [
830
- ],
831
- keywords: [
832
- "serif",
833
- "sans-serif",
834
- "monospace",
835
- "cursive",
836
- "fantasy",
837
- "system-ui",
838
- "ui-serif",
839
- "ui-sans-serif",
840
- "ui-monospace",
841
- "ui-rounded",
842
- "math",
843
- "emoji",
844
- "fangsong"
845
- ],
846
- required: true,
847
- multiple: true,
848
- separator: {
849
- typ: "Comma"
850
- }
851
- }
852
- }
853
- },
854
- "font-weight": {
855
- shorthand: "font"
856
- },
857
- "font-style": {
858
- shorthand: "font"
859
- },
860
- "font-size": {
861
- shorthand: "font"
862
- },
863
- "line-height": {
864
- shorthand: "font"
865
- },
866
- "font-stretch": {
867
- shorthand: "font"
868
- },
869
- "font-variant": {
870
- shorthand: "font"
871
- },
872
- "font-family": {
873
- shorthand: "font"
874
- },
875
- background: {
876
- shorthand: "background",
877
- pattern: "background-repeat background-color background-image background-attachment background-clip background-origin background-position background-size",
878
- keywords: [
879
- "none"
880
- ],
881
- "default": [
882
- ],
883
- multiple: true,
884
- separator: {
885
- typ: "Comma"
886
- },
887
- properties: {
888
- "background-repeat": {
889
- types: [
890
- ],
891
- "default": [
892
- "repeat"
893
- ],
894
- multiple: true,
895
- keywords: [
896
- "repeat-x",
897
- "repeat-y",
898
- "repeat",
899
- "space",
900
- "round",
901
- "no-repeat"
902
- ],
903
- mapping: {
904
- "repeat no-repeat": "repeat-x",
905
- "no-repeat repeat": "repeat-y",
906
- "repeat repeat": "repeat",
907
- "space space": "space",
908
- "round round": "round",
909
- "no-repeat no-repeat": "no-repeat"
910
- }
911
- },
912
- "background-color": {
913
- types: [
914
- "Color"
915
- ],
916
- "default": [
917
- "transparent"
918
- ],
919
- multiple: true,
920
- keywords: [
921
- ]
922
- },
923
- "background-image": {
924
- types: [
925
- "UrlFunc"
926
- ],
927
- "default": [
928
- "none"
929
- ],
930
- keywords: [
931
- "none"
932
- ]
933
- },
934
- "background-attachment": {
935
- types: [
936
- ],
937
- "default": [
938
- "scroll"
939
- ],
940
- multiple: true,
941
- keywords: [
942
- "scroll",
943
- "fixed",
944
- "local"
945
- ]
946
- },
947
- "background-clip": {
948
- types: [
949
- ],
950
- "default": [
951
- "border-box"
952
- ],
953
- multiple: true,
954
- keywords: [
955
- "border-box",
956
- "padding-box",
957
- "content-box",
958
- "text"
959
- ]
960
- },
961
- "background-origin": {
962
- types: [
963
- ],
964
- "default": [
965
- "padding-box"
966
- ],
967
- multiple: true,
968
- keywords: [
969
- "border-box",
970
- "padding-box",
971
- "content-box"
972
- ]
973
- },
974
- "background-position": {
975
- multiple: true,
976
- types: [
977
- "Perc",
978
- "Length"
979
- ],
980
- "default": [
981
- "0 0",
982
- "top left",
983
- "left top"
984
- ],
985
- keywords: [
986
- "top",
987
- "left",
988
- "center",
989
- "bottom",
990
- "right"
991
- ],
992
- mapping: {
993
- left: "0",
994
- top: "0",
995
- center: "50%",
996
- bottom: "100%",
997
- right: "100%"
998
- },
999
- constraints: {
1000
- mapping: {
1001
- max: 2
1002
- }
1003
- }
1004
- },
1005
- "background-size": {
1006
- multiple: true,
1007
- previous: "background-position",
1008
- prefix: {
1009
- typ: "Literal",
1010
- val: "/"
1011
- },
1012
- types: [
1013
- "Perc",
1014
- "Length"
1015
- ],
1016
- "default": [
1017
- "auto",
1018
- "auto auto"
1019
- ],
1020
- keywords: [
1021
- "auto",
1022
- "cover",
1023
- "contain"
1024
- ],
1025
- mapping: {
1026
- "auto auto": "auto"
1027
- }
1028
- }
1029
- }
1030
- },
1031
- "background-repeat": {
1032
- shorthand: "background"
1033
- },
1034
- "background-color": {
1035
- shorthand: "background"
1036
- },
1037
- "background-image": {
1038
- shorthand: "background"
1039
- },
1040
- "background-attachment": {
1041
- shorthand: "background"
1042
- },
1043
- "background-clip": {
1044
- shorthand: "background"
1045
- },
1046
- "background-origin": {
1047
- shorthand: "background"
1048
- },
1049
- "background-position": {
1050
- shorthand: "background"
1051
- },
1052
- "background-size": {
1053
- shorthand: "background"
1054
- }
1055
- };
1056
- var config$1 = {
1057
- properties: properties,
1058
- map: map
1059
- };
1060
-
1061
- const getConfig = () => config$1;
1062
-
1063
- const funcList = ['clamp', 'calc'];
1064
- function matchType(val, properties) {
1065
- if (val.typ == 'Iden' && properties.keywords.includes(val.val) ||
1066
- (properties.types.includes(val.typ))) {
1067
- return true;
1068
- }
1069
- if (val.typ == 'Number' && val.val == '0') {
1070
- return properties.types.some(type => type == 'Length' || type == 'Angle');
1071
- }
1072
- if (val.typ == 'Func' && funcList.includes(val.val)) {
1073
- return val.chi.every((t => ['Literal', 'Comma', 'Whitespace', 'Start-parens', 'End-parens'].includes(t.typ) || matchType(t, properties)));
1074
- }
1075
- return false;
1076
- }
1077
-
1078
5
  // name to color
1079
6
  const COLORS_NAMES = Object.seal({
1080
7
  'aliceblue': '#f0f8ff',
@@ -1389,487 +316,1573 @@ function rgb2Hex(token) {
1389
316
  // @ts-ignore
1390
317
  value += Math.round(t.typ == 'Perc' ? 255 * t.val / 100 : t.val).toString(16).padStart(2, '0');
1391
318
  }
1392
- // @ts-ignore
1393
- if (token.chi.length == 7) {
1394
- // @ts-ignore
1395
- t = token.chi[6];
319
+ // @ts-ignore
320
+ if (token.chi.length == 7) {
321
+ // @ts-ignore
322
+ t = token.chi[6];
323
+ // @ts-ignore
324
+ if ((t.typ == 'Number' && t.val < 1) ||
325
+ // @ts-ignore
326
+ (t.typ == 'Perc' && t.val < 100)) {
327
+ // @ts-ignore
328
+ value += Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)).toString(16).padStart(2, '0');
329
+ }
330
+ }
331
+ return value;
332
+ }
333
+ function hsl2Hex(token) {
334
+ let t;
335
+ // @ts-ignore
336
+ let h = getAngle(token.chi[0]);
337
+ // @ts-ignore
338
+ t = token.chi[2];
339
+ // @ts-ignore
340
+ let s = t.typ == 'Perc' ? t.val / 100 : t.val;
341
+ // @ts-ignore
342
+ t = token.chi[4];
343
+ // @ts-ignore
344
+ let l = t.typ == 'Perc' ? t.val / 100 : t.val;
345
+ let a = null;
346
+ if (token.chi?.length == 7) {
347
+ // @ts-ignore
348
+ t = token.chi[6];
349
+ // @ts-ignore
350
+ if ((t.typ == 'Perc' && t.val < 100) ||
351
+ // @ts-ignore
352
+ (t.typ == 'Number' && t.val < 1)) {
353
+ // @ts-ignore
354
+ a = (t.typ == 'Perc' ? t.val / 100 : t.val);
355
+ }
356
+ }
357
+ return `#${hsl2rgb(h, s, l, a).reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
358
+ }
359
+ function hwb2hex(token) {
360
+ let t;
361
+ // @ts-ignore
362
+ let h = getAngle(token.chi[0]);
363
+ // @ts-ignore
364
+ t = token.chi[2];
365
+ // @ts-ignore
366
+ let white = t.typ == 'Perc' ? t.val / 100 : t.val;
367
+ // @ts-ignore
368
+ t = token.chi[4];
369
+ // @ts-ignore
370
+ let black = t.typ == 'Perc' ? t.val / 100 : t.val;
371
+ let a = null;
372
+ if (token.chi?.length == 7) {
373
+ // @ts-ignore
374
+ t = token.chi[6];
375
+ // @ts-ignore
376
+ if ((t.typ == 'Perc' && t.val < 100) ||
377
+ // @ts-ignore
378
+ (t.typ == 'Number' && t.val < 1)) {
379
+ // @ts-ignore
380
+ a = (t.typ == 'Perc' ? t.val / 100 : t.val);
381
+ }
382
+ }
383
+ const rgb = hsl2rgb(h, 1, .5, a);
384
+ let value;
385
+ for (let i = 0; i < 3; i++) {
386
+ value = rgb[i] / 255;
387
+ value *= (1 - white - black);
388
+ value += white;
389
+ rgb[i] = Math.round(value * 255);
390
+ }
391
+ return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
392
+ }
393
+ function cmyk2hex(token) {
394
+ // @ts-ignore
395
+ let t = token.chi[0];
396
+ // @ts-ignore
397
+ const c = t.typ == 'Perc' ? t.val / 100 : t.val;
398
+ // @ts-ignore
399
+ t = token.chi[2];
400
+ // @ts-ignore
401
+ const m = t.typ == 'Perc' ? t.val / 100 : t.val;
402
+ // @ts-ignore
403
+ t = token.chi[4];
404
+ // @ts-ignore
405
+ const y = t.typ == 'Perc' ? t.val / 100 : t.val;
406
+ // @ts-ignore
407
+ t = token.chi[6];
408
+ // @ts-ignore
409
+ const k = t.typ == 'Perc' ? t.val / 100 : t.val;
410
+ const rgb = [
411
+ Math.round(255 * (1 - Math.min(1, c * (1 - k) + k))),
412
+ Math.round(255 * (1 - Math.min(1, m * (1 - k) + k))),
413
+ Math.round(255 * (1 - Math.min(1, y * (1 - k) + k)))
414
+ ];
415
+ // @ts-ignore
416
+ if (token.chi.length >= 9) {
417
+ // @ts-ignore
418
+ t = token.chi[8];
419
+ // @ts-ignore
420
+ rgb.push(Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)));
421
+ }
422
+ return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
423
+ }
424
+ function getAngle(token) {
425
+ if (token.typ == 'Angle') {
426
+ switch (token.unit) {
427
+ case 'deg':
428
+ // @ts-ignore
429
+ return token.val / 360;
430
+ case 'rad':
431
+ // @ts-ignore
432
+ return token.val / (2 * Math.PI);
433
+ case 'grad':
434
+ // @ts-ignore
435
+ return token.val / 400;
436
+ case 'turn':
437
+ // @ts-ignore
438
+ return +token.val;
439
+ }
440
+ }
441
+ // @ts-ignore
442
+ return token.val / 360;
443
+ }
444
+ function hsl2rgb(h, s, l, a = null) {
445
+ let v = l <= .5 ? l * (1.0 + s) : l + s - l * s;
446
+ let r = l;
447
+ let g = l;
448
+ let b = l;
449
+ if (v > 0) {
450
+ let m = l + l - v;
451
+ let sv = (v - m) / v;
452
+ h *= 6.0;
453
+ let sextant = Math.floor(h);
454
+ let fract = h - sextant;
455
+ let vsf = v * sv * fract;
456
+ let mid1 = m + vsf;
457
+ let mid2 = v - vsf;
458
+ switch (sextant) {
459
+ case 0:
460
+ r = v;
461
+ g = mid1;
462
+ b = m;
463
+ break;
464
+ case 1:
465
+ r = mid2;
466
+ g = v;
467
+ b = m;
468
+ break;
469
+ case 2:
470
+ r = m;
471
+ g = v;
472
+ b = mid1;
473
+ break;
474
+ case 3:
475
+ r = m;
476
+ g = mid2;
477
+ b = v;
478
+ break;
479
+ case 4:
480
+ r = mid1;
481
+ g = m;
482
+ b = v;
483
+ break;
484
+ case 5:
485
+ r = v;
486
+ g = m;
487
+ b = mid2;
488
+ break;
489
+ }
490
+ }
491
+ const values = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
492
+ if (a != null && a != 1) {
493
+ values.push(Math.round(a * 255));
494
+ }
495
+ return values;
496
+ }
497
+
498
+ const colorsFunc = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk'];
499
+ function reduceNumber(val) {
500
+ val = (+val).toString();
501
+ if (val === '0') {
502
+ return '0';
503
+ }
504
+ const chr = val.charAt(0);
505
+ if (chr == '-') {
506
+ const slice = val.slice(0, 2);
507
+ if (slice == '-0') {
508
+ return val.length == 2 ? '0' : '-' + val.slice(2);
509
+ }
510
+ }
511
+ if (chr == '0') {
512
+ return val.slice(1);
513
+ }
514
+ return val;
515
+ }
516
+ function render(data, opt = {}) {
517
+ const startTime = performance.now();
518
+ const options = Object.assign(opt.minify ?? true ? {
519
+ indent: '',
520
+ newLine: '',
521
+ removeComments: true
522
+ } : {
523
+ indent: ' ',
524
+ newLine: '\n',
525
+ compress: false,
526
+ removeComments: false,
527
+ }, { colorConvert: true, preserveLicense: false }, opt);
528
+ return {
529
+ code: doRender(data, options, function reducer(acc, curr) {
530
+ if (curr.typ == 'Comment' && options.removeComments) {
531
+ if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
532
+ return acc;
533
+ }
534
+ return acc + curr.val;
535
+ }
536
+ return acc + renderToken(curr, options, reducer);
537
+ }, 0), stats: {
538
+ total: `${(performance.now() - startTime).toFixed(2)}ms`
539
+ }
540
+ };
541
+ }
542
+ // @ts-ignore
543
+ function doRender(data, options, reducer, level = 0, indents = []) {
544
+ if (indents.length < level + 1) {
545
+ indents.push(options.indent.repeat(level));
546
+ }
547
+ if (indents.length < level + 2) {
548
+ indents.push(options.indent.repeat(level + 1));
549
+ }
550
+ const indent = indents[level];
551
+ const indentSub = indents[level + 1];
552
+ switch (data.typ) {
553
+ case 'Declaration':
554
+ return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
555
+ case 'Comment':
556
+ return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
557
+ case 'StyleSheet':
558
+ return data.chi.reduce((css, node) => {
559
+ const str = doRender(node, options, reducer, level, indents);
560
+ if (str === '') {
561
+ return css;
562
+ }
563
+ if (css === '') {
564
+ return str;
565
+ }
566
+ return `${css}${options.newLine}${str}`;
567
+ }, '');
568
+ case 'AtRule':
569
+ case 'Rule':
570
+ if (data.typ == 'AtRule' && !('chi' in data)) {
571
+ return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
572
+ }
573
+ // @ts-ignore
574
+ let children = data.chi.reduce((css, node) => {
575
+ let str;
576
+ if (node.typ == 'Comment') {
577
+ str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
578
+ }
579
+ else if (node.typ == 'Declaration') {
580
+ if (node.val.length == 0) {
581
+ console.error(`invalid declaration`, node);
582
+ return '';
583
+ }
584
+ str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
585
+ }
586
+ else if (node.typ == 'AtRule' && !('chi' in node)) {
587
+ str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
588
+ }
589
+ else {
590
+ str = doRender(node, options, reducer, level + 1, indents);
591
+ }
592
+ if (css === '') {
593
+ return str;
594
+ }
595
+ if (str === '') {
596
+ return css;
597
+ }
598
+ return `${css}${options.newLine}${indentSub}${str}`;
599
+ }, '');
600
+ if (children.endsWith(';')) {
601
+ children = children.slice(0, -1);
602
+ }
603
+ if (data.typ == 'AtRule') {
604
+ return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
605
+ }
606
+ return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
607
+ }
608
+ return '';
609
+ }
610
+ function renderToken(token, options = {}, reducer) {
611
+ if (reducer == null) {
612
+ reducer = function (acc, curr) {
613
+ if (curr.typ == 'Comment' && options.removeComments) {
614
+ if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
615
+ return acc;
616
+ }
617
+ return acc + curr.val;
618
+ }
619
+ return acc + renderToken(curr, options, reducer);
620
+ };
621
+ }
622
+ switch (token.typ) {
623
+ case 'Color':
624
+ if (options.minify || options.colorConvert) {
625
+ if (token.kin == 'lit' && token.val.toLowerCase() == 'currentcolor') {
626
+ return 'currentcolor';
627
+ }
628
+ let value = token.kin == 'hex' ? token.val.toLowerCase() : (token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : '');
629
+ if (token.val == 'rgb' || token.val == 'rgba') {
630
+ value = rgb2Hex(token);
631
+ }
632
+ else if (token.val == 'hsl' || token.val == 'hsla') {
633
+ value = hsl2Hex(token);
634
+ }
635
+ else if (token.val == 'hwb') {
636
+ value = hwb2hex(token);
637
+ }
638
+ else if (token.val == 'device-cmyk') {
639
+ value = cmyk2hex(token);
640
+ }
641
+ const named_color = NAMES_COLORS[value];
642
+ if (value !== '') {
643
+ if (value.length == 7) {
644
+ if (value[1] == value[2] &&
645
+ value[3] == value[4] &&
646
+ value[5] == value[6]) {
647
+ value = `#${value[1]}${value[3]}${value[5]}`;
648
+ }
649
+ }
650
+ else if (value.length == 9) {
651
+ if (value[1] == value[2] &&
652
+ value[3] == value[4] &&
653
+ value[5] == value[6] &&
654
+ value[7] == value[8]) {
655
+ value = `#${value[1]}${value[3]}${value[5]}${value[7]}`;
656
+ }
657
+ }
658
+ return named_color != null && named_color.length <= value.length ? named_color : value;
659
+ }
660
+ }
661
+ if (token.kin == 'hex' || token.kin == 'lit') {
662
+ return token.val;
663
+ }
664
+ case 'Start-parens':
665
+ if (!('chi' in token)) {
666
+ return '(';
667
+ }
668
+ case 'Func':
669
+ case 'UrlFunc':
670
+ case 'Pseudo-class-func':
671
+ // @ts-ignore
672
+ return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
673
+ case 'Includes':
674
+ return '~=';
675
+ case 'Dash-match':
676
+ return '|=';
677
+ case 'Lt':
678
+ return '<';
679
+ case 'Lte':
680
+ return '<=';
681
+ case 'Gt':
682
+ return '>';
683
+ case 'Gte':
684
+ return '>=';
685
+ case 'End-parens':
686
+ return ')';
687
+ case 'Attr-start':
688
+ return '[';
689
+ case 'Attr-end':
690
+ return ']';
691
+ case 'Whitespace':
692
+ return ' ';
693
+ case 'Colon':
694
+ return ':';
695
+ case 'Semi-colon':
696
+ return ';';
697
+ case 'Comma':
698
+ return ',';
699
+ case 'Important':
700
+ return '!important';
701
+ case 'Attr':
702
+ return '[' + token.chi.reduce(reducer, '') + ']';
703
+ case 'Time':
704
+ case 'Angle':
705
+ case 'Length':
706
+ case 'Dimension':
707
+ case 'Frequency':
708
+ case 'Resolution':
709
+ let val = reduceNumber(token.val);
710
+ let unit = token.unit;
711
+ if (token.typ == 'Angle') {
712
+ const angle = getAngle(token);
713
+ let v;
714
+ let value = val + unit;
715
+ for (const u of ['turn', 'deg', 'rad', 'grad']) {
716
+ if (token.unit == u) {
717
+ continue;
718
+ }
719
+ switch (u) {
720
+ case 'turn':
721
+ v = reduceNumber(angle);
722
+ if (v.length + 4 < value.length) {
723
+ val = v;
724
+ unit = u;
725
+ value = v + u;
726
+ }
727
+ break;
728
+ case 'deg':
729
+ v = reduceNumber(angle * 360);
730
+ if (v.length + 3 < value.length) {
731
+ val = v;
732
+ unit = u;
733
+ value = v + u;
734
+ }
735
+ break;
736
+ case 'rad':
737
+ v = reduceNumber(angle * (2 * Math.PI));
738
+ if (v.length + 3 < value.length) {
739
+ val = v;
740
+ unit = u;
741
+ value = v + u;
742
+ }
743
+ break;
744
+ case 'grad':
745
+ v = reduceNumber(angle * 400);
746
+ if (v.length + 4 < value.length) {
747
+ val = v;
748
+ unit = u;
749
+ value = v + u;
750
+ }
751
+ break;
752
+ }
753
+ }
754
+ }
755
+ if (val === '0') {
756
+ if (token.typ == 'Time') {
757
+ return '0s';
758
+ }
759
+ if (token.typ == 'Frequency') {
760
+ return '0Hz';
761
+ }
762
+ // @ts-ignore
763
+ if (token.typ == 'Resolution') {
764
+ return '0x';
765
+ }
766
+ return '0';
767
+ }
768
+ return val + unit;
769
+ case 'Perc':
770
+ return token.val + '%';
771
+ case 'Number':
772
+ const num = (+token.val).toString();
773
+ if (token.val.length < num.length) {
774
+ return token.val;
775
+ }
776
+ if (num.charAt(0) === '0' && num.length > 1) {
777
+ return num.slice(1);
778
+ }
779
+ const slice = num.slice(0, 2);
780
+ if (slice == '-0') {
781
+ return '-' + num.slice(2);
782
+ }
783
+ return num;
784
+ case 'Comment':
785
+ if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
786
+ return '';
787
+ }
788
+ case 'Url-token':
789
+ case 'At-rule':
790
+ case 'Hash':
791
+ case 'Pseudo-class':
792
+ case 'Literal':
793
+ case 'String':
794
+ case 'Iden':
795
+ case 'Delim':
796
+ return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
797
+ }
798
+ console.error(`unexpected token ${JSON.stringify(token, null, 1)}`);
799
+ // throw new Error(`unexpected token ${JSON.stringify(token, null, 1)}`);
800
+ return '';
801
+ }
802
+
803
+ // https://www.w3.org/TR/CSS21/syndata.html#syntax
804
+ // https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#typedef-ident-token
805
+ // '\\'
806
+ const REVERSE_SOLIDUS = 0x5c;
807
+ const dimensionUnits = [
808
+ 'q', 'cap', 'ch', 'cm', 'cqb', 'cqh', 'cqi', 'cqmax', 'cqmin', 'cqw', 'dvb',
809
+ 'dvh', 'dvi', 'dvmax', 'dvmin', 'dvw', 'em', 'ex', 'ic', 'in', 'lh', 'lvb',
810
+ 'lvh', 'lvi', 'lvmax', 'lvw', 'mm', 'pc', 'pt', 'px', 'rem', 'rlh', 'svb',
811
+ 'svh', 'svi', 'svmin', 'svw', 'vb', 'vh', 'vi', 'vmax', 'vmin', 'vw'
812
+ ];
813
+ function isLength(dimension) {
814
+ return 'unit' in dimension && dimensionUnits.includes(dimension.unit.toLowerCase());
815
+ }
816
+ function isResolution(dimension) {
817
+ return 'unit' in dimension && ['dpi', 'dpcm', 'dppx', 'x'].includes(dimension.unit.toLowerCase());
818
+ }
819
+ function isAngle(dimension) {
820
+ return 'unit' in dimension && ['rad', 'turn', 'deg', 'grad'].includes(dimension.unit.toLowerCase());
821
+ }
822
+ function isTime(dimension) {
823
+ return 'unit' in dimension && ['ms', 's'].includes(dimension.unit.toLowerCase());
824
+ }
825
+ function isFrequency(dimension) {
826
+ return 'unit' in dimension && ['hz', 'khz'].includes(dimension.unit.toLowerCase());
827
+ }
828
+ function isColor(token) {
829
+ if (token.typ == 'Color') {
830
+ return true;
831
+ }
832
+ if (token.typ == 'Iden') {
833
+ // named color
834
+ return token.val.toLowerCase() in COLORS_NAMES;
835
+ }
836
+ if (token.typ == 'Func' && token.chi.length > 0 && colorsFunc.includes(token.val)) {
1396
837
  // @ts-ignore
1397
- if ((t.typ == 'Number' && t.val < 1) ||
1398
- // @ts-ignore
1399
- (t.typ == 'Perc' && t.val < 100)) {
1400
- // @ts-ignore
1401
- value += Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)).toString(16).padStart(2, '0');
838
+ for (const v of token.chi) {
839
+ if (!['Number', 'Perc', 'Comma', 'Whitespace'].includes(v.typ)) {
840
+ return false;
841
+ }
1402
842
  }
843
+ return true;
1403
844
  }
1404
- return value;
845
+ return false;
1405
846
  }
1406
- function hsl2Hex(token) {
1407
- let t;
1408
- // @ts-ignore
1409
- let h = getAngle(token.chi[0]);
1410
- // @ts-ignore
1411
- t = token.chi[2];
1412
- // @ts-ignore
1413
- let s = t.typ == 'Perc' ? t.val / 100 : t.val;
1414
- // @ts-ignore
1415
- t = token.chi[4];
1416
- // @ts-ignore
1417
- let l = t.typ == 'Perc' ? t.val / 100 : t.val;
1418
- let a = null;
1419
- if (token.chi?.length == 7) {
1420
- // @ts-ignore
1421
- t = token.chi[6];
1422
- // @ts-ignore
1423
- if ((t.typ == 'Perc' && t.val < 100) ||
1424
- // @ts-ignore
1425
- (t.typ == 'Number' && t.val < 1)) {
1426
- // @ts-ignore
1427
- a = (t.typ == 'Perc' ? t.val / 100 : t.val);
847
+ function isLetter(codepoint) {
848
+ // lowercase
849
+ return (codepoint >= 0x61 && codepoint <= 0x7a) ||
850
+ // uppercase
851
+ (codepoint >= 0x41 && codepoint <= 0x5a);
852
+ }
853
+ function isNonAscii(codepoint) {
854
+ return codepoint >= 0x80;
855
+ }
856
+ function isIdentStart(codepoint) {
857
+ // _
858
+ return codepoint == 0x5f || isLetter(codepoint) || isNonAscii(codepoint);
859
+ }
860
+ function isDigit(codepoint) {
861
+ return codepoint >= 0x30 && codepoint <= 0x39;
862
+ }
863
+ function isIdentCodepoint(codepoint) {
864
+ // -
865
+ return codepoint == 0x2d || isDigit(codepoint) || isIdentStart(codepoint);
866
+ }
867
+ function isIdent(name) {
868
+ const j = name.length - 1;
869
+ let i = 0;
870
+ let codepoint = name.charCodeAt(0);
871
+ // -
872
+ if (codepoint == 0x2d) {
873
+ const nextCodepoint = name.charCodeAt(1);
874
+ if (Number.isNaN(nextCodepoint)) {
875
+ return false;
876
+ }
877
+ // -
878
+ if (nextCodepoint == 0x2d) {
879
+ return true;
880
+ }
881
+ if (nextCodepoint == REVERSE_SOLIDUS) {
882
+ return name.length > 2 && !isNewLine(name.charCodeAt(2));
1428
883
  }
884
+ return true;
1429
885
  }
1430
- return `#${hsl2rgb(h, s, l, a).reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
886
+ if (!isIdentStart(codepoint)) {
887
+ return false;
888
+ }
889
+ while (i < j) {
890
+ i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
891
+ codepoint = name.charCodeAt(i);
892
+ if (!isIdentCodepoint(codepoint)) {
893
+ return false;
894
+ }
895
+ }
896
+ return true;
1431
897
  }
1432
- function hwb2hex(token) {
1433
- let t;
1434
- // @ts-ignore
1435
- let h = getAngle(token.chi[0]);
1436
- // @ts-ignore
1437
- t = token.chi[2];
1438
- // @ts-ignore
1439
- let white = t.typ == 'Perc' ? t.val / 100 : t.val;
1440
- // @ts-ignore
1441
- t = token.chi[4];
1442
- // @ts-ignore
1443
- let black = t.typ == 'Perc' ? t.val / 100 : t.val;
1444
- let a = null;
1445
- if (token.chi?.length == 7) {
1446
- // @ts-ignore
1447
- t = token.chi[6];
1448
- // @ts-ignore
1449
- if ((t.typ == 'Perc' && t.val < 100) ||
1450
- // @ts-ignore
1451
- (t.typ == 'Number' && t.val < 1)) {
1452
- // @ts-ignore
1453
- a = (t.typ == 'Perc' ? t.val / 100 : t.val);
898
+ function isPseudo(name) {
899
+ return name.charAt(0) == ':' &&
900
+ ((name.endsWith('(') && isIdent(name.charAt(1) == ':' ? name.slice(2, -1) : name.slice(1, -1))) ||
901
+ isIdent(name.charAt(1) == ':' ? name.slice(2) : name.slice(1)));
902
+ }
903
+ function isHash(name) {
904
+ return name.charAt(0) == '#' && isIdent(name.charAt(1));
905
+ }
906
+ function isNumber(name) {
907
+ if (name.length == 0) {
908
+ return false;
909
+ }
910
+ let codepoint = name.charCodeAt(0);
911
+ let i = 0;
912
+ const j = name.length;
913
+ if (j == 1 && !isDigit(codepoint)) {
914
+ return false;
915
+ }
916
+ // '+' '-'
917
+ if ([0x2b, 0x2d].includes(codepoint)) {
918
+ i++;
919
+ }
920
+ // consume digits
921
+ while (i < j) {
922
+ codepoint = name.charCodeAt(i);
923
+ if (isDigit(codepoint)) {
924
+ i++;
925
+ continue;
926
+ }
927
+ // '.' 'E' 'e'
928
+ if (codepoint == 0x2e || codepoint == 0x45 || codepoint == 0x65) {
929
+ break;
1454
930
  }
931
+ return false;
1455
932
  }
1456
- const rgb = hsl2rgb(h, 1, .5, a);
1457
- let value;
1458
- for (let i = 0; i < 3; i++) {
1459
- value = rgb[i] / 255;
1460
- value *= (1 - white - black);
1461
- value += white;
1462
- rgb[i] = Math.round(value * 255);
933
+ // '.'
934
+ if (codepoint == 0x2e) {
935
+ if (!isDigit(name.charCodeAt(++i))) {
936
+ return false;
937
+ }
1463
938
  }
1464
- return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
1465
- }
1466
- function cmyk2hex(token) {
1467
- // @ts-ignore
1468
- let t = token.chi[0];
1469
- // @ts-ignore
1470
- const c = t.typ == 'Perc' ? t.val / 100 : t.val;
1471
- // @ts-ignore
1472
- t = token.chi[2];
1473
- // @ts-ignore
1474
- const m = t.typ == 'Perc' ? t.val / 100 : t.val;
1475
- // @ts-ignore
1476
- t = token.chi[4];
1477
- // @ts-ignore
1478
- const y = t.typ == 'Perc' ? t.val / 100 : t.val;
1479
- // @ts-ignore
1480
- t = token.chi[6];
1481
- // @ts-ignore
1482
- const k = t.typ == 'Perc' ? t.val / 100 : t.val;
1483
- const rgb = [
1484
- Math.round(255 * (1 - Math.min(1, c * (1 - k) + k))),
1485
- Math.round(255 * (1 - Math.min(1, m * (1 - k) + k))),
1486
- Math.round(255 * (1 - Math.min(1, y * (1 - k) + k)))
1487
- ];
1488
- // @ts-ignore
1489
- if (token.chi.length >= 9) {
1490
- // @ts-ignore
1491
- t = token.chi[8];
1492
- // @ts-ignore
1493
- rgb.push(Math.round(255 * (t.typ == 'Perc' ? t.val / 100 : t.val)));
939
+ while (i < j) {
940
+ codepoint = name.charCodeAt(i);
941
+ if (isDigit(codepoint)) {
942
+ i++;
943
+ continue;
944
+ }
945
+ // 'E' 'e'
946
+ if (codepoint == 0x45 || codepoint == 0x65) {
947
+ i++;
948
+ break;
949
+ }
950
+ return false;
1494
951
  }
1495
- return `#${rgb.reduce((acc, curr) => acc + curr.toString(16).padStart(2, '0'), '')}`;
952
+ // 'E' 'e'
953
+ if (codepoint == 0x45 || codepoint == 0x65) {
954
+ if (i == j) {
955
+ return false;
956
+ }
957
+ codepoint = name.charCodeAt(i + 1);
958
+ // '+' '-'
959
+ if ([0x2b, 0x2d].includes(codepoint)) {
960
+ i++;
961
+ }
962
+ codepoint = name.charCodeAt(i + 1);
963
+ if (!isDigit(codepoint)) {
964
+ return false;
965
+ }
966
+ }
967
+ while (++i < j) {
968
+ codepoint = name.charCodeAt(i);
969
+ if (!isDigit(codepoint)) {
970
+ return false;
971
+ }
972
+ }
973
+ return true;
1496
974
  }
1497
- function getAngle(token) {
1498
- if (token.typ == 'Angle') {
1499
- switch (token.unit) {
1500
- case 'deg':
1501
- // @ts-ignore
1502
- return token.val / 360;
1503
- case 'rad':
1504
- // @ts-ignore
1505
- return token.val / (2 * Math.PI);
1506
- case 'grad':
1507
- // @ts-ignore
1508
- return token.val / 400;
1509
- case 'turn':
1510
- // @ts-ignore
1511
- return +token.val;
975
+ function isDimension(name) {
976
+ let index = name.length;
977
+ while (index--) {
978
+ if (isLetter(name.charCodeAt(index))) {
979
+ continue;
1512
980
  }
981
+ index++;
982
+ break;
1513
983
  }
1514
- // @ts-ignore
1515
- return token.val / 360;
984
+ const number = name.slice(0, index);
985
+ return number.length > 0 && isIdentStart(name.charCodeAt(index)) && isNumber(number);
1516
986
  }
1517
- function hsl2rgb(h, s, l, a = null) {
1518
- let v = l <= .5 ? l * (1.0 + s) : l + s - l * s;
1519
- let r = l;
1520
- let g = l;
1521
- let b = l;
1522
- if (v > 0) {
1523
- let m = l + l - v;
1524
- let sv = (v - m) / v;
1525
- h *= 6.0;
1526
- let sextant = Math.floor(h);
1527
- let fract = h - sextant;
1528
- let vsf = v * sv * fract;
1529
- let mid1 = m + vsf;
1530
- let mid2 = v - vsf;
1531
- switch (sextant) {
1532
- case 0:
1533
- r = v;
1534
- g = mid1;
1535
- b = m;
1536
- break;
1537
- case 1:
1538
- r = mid2;
1539
- g = v;
1540
- b = m;
1541
- break;
1542
- case 2:
1543
- r = m;
1544
- g = v;
1545
- b = mid1;
1546
- break;
1547
- case 3:
1548
- r = m;
1549
- g = mid2;
1550
- b = v;
1551
- break;
1552
- case 4:
1553
- r = mid1;
1554
- g = m;
1555
- b = v;
1556
- break;
1557
- case 5:
1558
- r = v;
1559
- g = m;
1560
- b = mid2;
1561
- break;
987
+ function isPercentage(name) {
988
+ return name.endsWith('%') && isNumber(name.slice(0, -1));
989
+ }
990
+ function parseDimension(name) {
991
+ let index = name.length;
992
+ while (index--) {
993
+ if (isLetter(name.charCodeAt(index))) {
994
+ continue;
1562
995
  }
996
+ index++;
997
+ break;
1563
998
  }
1564
- const values = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
1565
- if (a != null && a != 1) {
1566
- values.push(Math.round(a * 255));
999
+ const dimension = { typ: 'Dimension', val: name.slice(0, index), unit: name.slice(index) };
1000
+ if (isAngle(dimension)) {
1001
+ // @ts-ignore
1002
+ dimension.typ = 'Angle';
1567
1003
  }
1568
- return values;
1569
- }
1570
-
1571
- function reduceNumber(val) {
1572
- val = (+val).toString();
1573
- if (val === '0') {
1574
- return '0';
1004
+ else if (isLength(dimension)) {
1005
+ // @ts-ignore
1006
+ dimension.typ = 'Length';
1575
1007
  }
1576
- const chr = val.charAt(0);
1577
- if (chr == '-') {
1578
- const slice = val.slice(0, 2);
1579
- if (slice == '-0') {
1580
- return val.length == 2 ? '0' : '-' + val.slice(2);
1008
+ else if (isTime(dimension)) {
1009
+ // @ts-ignore
1010
+ dimension.typ = 'Time';
1011
+ }
1012
+ else if (isResolution(dimension)) {
1013
+ // @ts-ignore
1014
+ dimension.typ = 'Resolution';
1015
+ if (dimension.unit == 'dppx') {
1016
+ dimension.unit = 'x';
1581
1017
  }
1582
1018
  }
1583
- if (chr == '0') {
1584
- return val.slice(1);
1019
+ else if (isFrequency(dimension)) {
1020
+ // @ts-ignore
1021
+ dimension.typ = 'Frequency';
1585
1022
  }
1586
- return val;
1023
+ return dimension;
1587
1024
  }
1588
- function render(data, opt = {}) {
1589
- const startTime = performance.now();
1590
- const options = Object.assign(opt.minify ?? true ? {
1591
- indent: '',
1592
- newLine: '',
1593
- removeComments: true
1594
- } : {
1595
- indent: ' ',
1596
- newLine: '\n',
1597
- compress: false,
1598
- removeComments: false,
1599
- }, { colorConvert: true, preserveLicense: false }, opt);
1600
- return {
1601
- code: doRender(data, options, function reducer(acc, curr) {
1602
- if (curr.typ == 'Comment' && options.removeComments) {
1603
- if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
1604
- return acc;
1605
- }
1606
- return acc + curr.val;
1607
- }
1608
- return acc + renderToken(curr, options, reducer);
1609
- }, 0), stats: {
1610
- total: `${(performance.now() - startTime).toFixed(2)}ms`
1025
+ function isHexColor(name) {
1026
+ if (name.charAt(0) != '#' || ![4, 5, 7, 9].includes(name.length)) {
1027
+ return false;
1028
+ }
1029
+ for (let chr of name.slice(1)) {
1030
+ let codepoint = chr.charCodeAt(0);
1031
+ if (!isDigit(codepoint) &&
1032
+ // A-F
1033
+ !(codepoint >= 0x41 && codepoint <= 0x46) &&
1034
+ // a-f
1035
+ !(codepoint >= 0x61 && codepoint <= 0x66)) {
1036
+ return false;
1611
1037
  }
1612
- };
1038
+ }
1039
+ return true;
1613
1040
  }
1614
- // @ts-ignore
1615
- function doRender(data, options, reducer, level = 0, indents = []) {
1616
- if (indents.length < level + 1) {
1617
- indents.push(options.indent.repeat(level));
1041
+ function isHexDigit(name) {
1042
+ if (name.length || name.length > 6) {
1043
+ return false;
1618
1044
  }
1619
- if (indents.length < level + 2) {
1620
- indents.push(options.indent.repeat(level + 1));
1045
+ for (let chr of name) {
1046
+ let codepoint = chr.charCodeAt(0);
1047
+ if (!isDigit(codepoint) &&
1048
+ // A F
1049
+ !(codepoint >= 0x41 && codepoint <= 0x46) &&
1050
+ // a f
1051
+ !(codepoint >= 0x61 && codepoint <= 0x66)) {
1052
+ return false;
1053
+ }
1621
1054
  }
1622
- const indent = indents[level];
1623
- const indentSub = indents[level + 1];
1624
- switch (data.typ) {
1625
- case 'Declaration':
1626
- return `${data.nam}:${options.indent}${data.val.reduce(reducer, '')}`;
1627
- case 'Comment':
1628
- return !options.removeComments || (options.preserveLicense && data.val.startsWith('/*!')) ? data.val : '';
1629
- case 'StyleSheet':
1630
- return data.chi.reduce((css, node) => {
1631
- const str = doRender(node, options, reducer, level, indents);
1632
- if (str === '') {
1633
- return css;
1634
- }
1635
- if (css === '') {
1636
- return str;
1637
- }
1638
- return `${css}${options.newLine}${str}`;
1639
- }, '');
1640
- case 'AtRule':
1641
- case 'Rule':
1642
- if (data.typ == 'AtRule' && !('chi' in data)) {
1643
- return `${indent}@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val};`;
1644
- }
1645
- // @ts-ignore
1646
- let children = data.chi.reduce((css, node) => {
1647
- let str;
1648
- if (node.typ == 'Comment') {
1649
- str = options.removeComments && (!options.preserveLicense || !node.val.startsWith('/*!')) ? '' : node.val;
1650
- }
1651
- else if (node.typ == 'Declaration') {
1652
- if (node.val.length == 0) {
1653
- console.error(`invalid declaration`, node);
1654
- return '';
1655
- }
1656
- str = `${node.nam}:${options.indent}${node.val.reduce(reducer, '').trimEnd()};`;
1657
- }
1658
- else if (node.typ == 'AtRule' && !('chi' in node)) {
1659
- str = `${data.val === '' ? '' : options.indent || ' '}${data.val};`;
1660
- }
1661
- else {
1662
- str = doRender(node, options, reducer, level + 1, indents);
1663
- }
1664
- if (css === '') {
1665
- return str;
1666
- }
1667
- if (str === '') {
1668
- return css;
1669
- }
1670
- return `${css}${options.newLine}${indentSub}${str}`;
1671
- }, '');
1672
- if (children.endsWith(';')) {
1673
- children = children.slice(0, -1);
1674
- }
1675
- if (data.typ == 'AtRule') {
1676
- return `@${data.nam}${data.val === '' ? '' : options.indent || ' '}${data.val}${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
1677
- }
1678
- return data.sel + `${options.indent}{${options.newLine}` + (children === '' ? '' : indentSub + children + options.newLine) + indent + `}`;
1055
+ return true;
1056
+ }
1057
+ function isFunction(name) {
1058
+ return name.endsWith('(') && isIdent(name.slice(0, -1));
1059
+ }
1060
+ function isAtKeyword(name) {
1061
+ return name.charCodeAt(0) == 0x40 && isIdent(name.slice(1));
1062
+ }
1063
+ function isNewLine(codepoint) {
1064
+ // \n \r \f
1065
+ return codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
1066
+ }
1067
+ function isWhiteSpace(codepoint) {
1068
+ return codepoint == 0x9 || codepoint == 0x20 ||
1069
+ // isNewLine
1070
+ codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
1071
+ }
1072
+
1073
+ var properties = {
1074
+ inset: {
1075
+ shorthand: "inset",
1076
+ properties: [
1077
+ "top",
1078
+ "right",
1079
+ "bottom",
1080
+ "left"
1081
+ ],
1082
+ types: [
1083
+ "Length",
1084
+ "Perc"
1085
+ ],
1086
+ multiple: false,
1087
+ separator: null,
1088
+ keywords: [
1089
+ "auto"
1090
+ ]
1091
+ },
1092
+ top: {
1093
+ shorthand: "inset"
1094
+ },
1095
+ right: {
1096
+ shorthand: "inset"
1097
+ },
1098
+ bottom: {
1099
+ shorthand: "inset"
1100
+ },
1101
+ left: {
1102
+ shorthand: "inset"
1103
+ },
1104
+ margin: {
1105
+ shorthand: "margin",
1106
+ properties: [
1107
+ "margin-top",
1108
+ "margin-right",
1109
+ "margin-bottom",
1110
+ "margin-left"
1111
+ ],
1112
+ types: [
1113
+ "Length",
1114
+ "Perc"
1115
+ ],
1116
+ multiple: false,
1117
+ separator: null,
1118
+ keywords: [
1119
+ "auto"
1120
+ ]
1121
+ },
1122
+ "margin-top": {
1123
+ shorthand: "margin"
1124
+ },
1125
+ "margin-right": {
1126
+ shorthand: "margin"
1127
+ },
1128
+ "margin-bottom": {
1129
+ shorthand: "margin"
1130
+ },
1131
+ "margin-left": {
1132
+ shorthand: "margin"
1133
+ },
1134
+ padding: {
1135
+ shorthand: "padding",
1136
+ properties: [
1137
+ "padding-top",
1138
+ "padding-right",
1139
+ "padding-bottom",
1140
+ "padding-left"
1141
+ ],
1142
+ types: [
1143
+ "Length",
1144
+ "Perc"
1145
+ ],
1146
+ keywords: [
1147
+ ]
1148
+ },
1149
+ "padding-top": {
1150
+ shorthand: "padding"
1151
+ },
1152
+ "padding-right": {
1153
+ shorthand: "padding"
1154
+ },
1155
+ "padding-bottom": {
1156
+ shorthand: "padding"
1157
+ },
1158
+ "padding-left": {
1159
+ shorthand: "padding"
1160
+ },
1161
+ "border-radius": {
1162
+ shorthand: "border-radius",
1163
+ properties: [
1164
+ "border-top-left-radius",
1165
+ "border-top-right-radius",
1166
+ "border-bottom-right-radius",
1167
+ "border-bottom-left-radius"
1168
+ ],
1169
+ types: [
1170
+ "Length",
1171
+ "Perc"
1172
+ ],
1173
+ multiple: true,
1174
+ separator: "/",
1175
+ keywords: [
1176
+ ]
1177
+ },
1178
+ "border-top-left-radius": {
1179
+ shorthand: "border-radius"
1180
+ },
1181
+ "border-top-right-radius": {
1182
+ shorthand: "border-radius"
1183
+ },
1184
+ "border-bottom-right-radius": {
1185
+ shorthand: "border-radius"
1186
+ },
1187
+ "border-bottom-left-radius": {
1188
+ shorthand: "border-radius"
1189
+ },
1190
+ "border-width": {
1191
+ shorthand: "border-width",
1192
+ map: "border",
1193
+ properties: [
1194
+ "border-top-width",
1195
+ "border-right-width",
1196
+ "border-bottom-width",
1197
+ "border-left-width"
1198
+ ],
1199
+ types: [
1200
+ "Length",
1201
+ "Perc"
1202
+ ],
1203
+ "default": [
1204
+ "medium"
1205
+ ],
1206
+ keywords: [
1207
+ "thin",
1208
+ "medium",
1209
+ "thick"
1210
+ ]
1211
+ },
1212
+ "border-top-width": {
1213
+ map: "border",
1214
+ shorthand: "border-width"
1215
+ },
1216
+ "border-right-width": {
1217
+ map: "border",
1218
+ shorthand: "border-width"
1219
+ },
1220
+ "border-bottom-width": {
1221
+ map: "border",
1222
+ shorthand: "border-width"
1223
+ },
1224
+ "border-left-width": {
1225
+ map: "border",
1226
+ shorthand: "border-width"
1227
+ },
1228
+ "border-style": {
1229
+ shorthand: "border-style",
1230
+ map: "border",
1231
+ properties: [
1232
+ "border-top-style",
1233
+ "border-right-style",
1234
+ "border-bottom-style",
1235
+ "border-left-style"
1236
+ ],
1237
+ types: [
1238
+ ],
1239
+ "default": [
1240
+ "none"
1241
+ ],
1242
+ keywords: [
1243
+ "none",
1244
+ "hidden",
1245
+ "dotted",
1246
+ "dashed",
1247
+ "solid",
1248
+ "double",
1249
+ "groove",
1250
+ "ridge",
1251
+ "inset",
1252
+ "outset"
1253
+ ]
1254
+ },
1255
+ "border-top-style": {
1256
+ map: "border",
1257
+ shorthand: "border-style"
1258
+ },
1259
+ "border-right-style": {
1260
+ map: "border",
1261
+ shorthand: "border-style"
1262
+ },
1263
+ "border-bottom-style": {
1264
+ map: "border",
1265
+ shorthand: "border-style"
1266
+ },
1267
+ "border-left-style": {
1268
+ map: "border",
1269
+ shorthand: "border-style"
1270
+ },
1271
+ "border-color": {
1272
+ shorthand: "border-color",
1273
+ map: "border",
1274
+ properties: [
1275
+ "border-top-color",
1276
+ "border-right-color",
1277
+ "border-bottom-color",
1278
+ "border-left-color"
1279
+ ],
1280
+ types: [
1281
+ "Color"
1282
+ ],
1283
+ "default": [
1284
+ "currentcolor"
1285
+ ],
1286
+ keywords: [
1287
+ ]
1288
+ },
1289
+ "border-top-color": {
1290
+ map: "border",
1291
+ shorthand: "border-color"
1292
+ },
1293
+ "border-right-color": {
1294
+ map: "border",
1295
+ shorthand: "border-color"
1296
+ },
1297
+ "border-bottom-color": {
1298
+ map: "border",
1299
+ shorthand: "border-color"
1300
+ },
1301
+ "border-left-color": {
1302
+ map: "border",
1303
+ shorthand: "border-color"
1304
+ }
1305
+ };
1306
+ var map = {
1307
+ border: {
1308
+ shorthand: "border",
1309
+ pattern: "border-color border-style border-width",
1310
+ keywords: [
1311
+ "none"
1312
+ ],
1313
+ "default": [
1314
+ "0",
1315
+ "none"
1316
+ ],
1317
+ properties: {
1318
+ "border-color": {
1319
+ types: [
1320
+ "Color"
1321
+ ],
1322
+ "default": [
1323
+ "currentcolor"
1324
+ ],
1325
+ keywords: [
1326
+ ]
1327
+ },
1328
+ "border-style": {
1329
+ types: [
1330
+ ],
1331
+ "default": [
1332
+ "none"
1333
+ ],
1334
+ keywords: [
1335
+ "none",
1336
+ "hidden",
1337
+ "dotted",
1338
+ "dashed",
1339
+ "solid",
1340
+ "double",
1341
+ "groove",
1342
+ "ridge",
1343
+ "inset",
1344
+ "outset"
1345
+ ]
1346
+ },
1347
+ "border-width": {
1348
+ types: [
1349
+ "Length",
1350
+ "Perc"
1351
+ ],
1352
+ "default": [
1353
+ "medium"
1354
+ ],
1355
+ keywords: [
1356
+ "thin",
1357
+ "medium",
1358
+ "thick"
1359
+ ]
1360
+ }
1361
+ }
1362
+ },
1363
+ "border-color": {
1364
+ shorthand: "border"
1365
+ },
1366
+ "border-style": {
1367
+ shorthand: "border"
1368
+ },
1369
+ "border-width": {
1370
+ shorthand: "border"
1371
+ },
1372
+ outline: {
1373
+ shorthand: "outline",
1374
+ pattern: "outline-color outline-style outline-width",
1375
+ keywords: [
1376
+ "none"
1377
+ ],
1378
+ "default": [
1379
+ "0",
1380
+ "none"
1381
+ ],
1382
+ properties: {
1383
+ "outline-color": {
1384
+ types: [
1385
+ "Color"
1386
+ ],
1387
+ "default": [
1388
+ "currentColor"
1389
+ ],
1390
+ keywords: [
1391
+ "currentColor"
1392
+ ]
1393
+ },
1394
+ "outline-style": {
1395
+ types: [
1396
+ ],
1397
+ "default": [
1398
+ "none"
1399
+ ],
1400
+ keywords: [
1401
+ "auto",
1402
+ "none",
1403
+ "dotted",
1404
+ "dashed",
1405
+ "solid",
1406
+ "double",
1407
+ "groove",
1408
+ "ridge",
1409
+ "inset",
1410
+ "outset"
1411
+ ]
1412
+ },
1413
+ "outline-width": {
1414
+ types: [
1415
+ "Length",
1416
+ "Perc"
1417
+ ],
1418
+ "default": [
1419
+ "medium"
1420
+ ],
1421
+ keywords: [
1422
+ "thin",
1423
+ "medium",
1424
+ "thick"
1425
+ ]
1426
+ }
1427
+ }
1428
+ },
1429
+ "outline-color": {
1430
+ shorthand: "outline"
1431
+ },
1432
+ "outline-style": {
1433
+ shorthand: "outline"
1434
+ },
1435
+ "outline-width": {
1436
+ shorthand: "outline"
1437
+ },
1438
+ font: {
1439
+ shorthand: "font",
1440
+ pattern: "font-weight font-style font-size line-height font-stretch font-variant font-family",
1441
+ keywords: [
1442
+ "caption",
1443
+ "icon",
1444
+ "menu",
1445
+ "message-box",
1446
+ "small-caption",
1447
+ "status-bar",
1448
+ "-moz-window, ",
1449
+ "-moz-document, ",
1450
+ "-moz-desktop, ",
1451
+ "-moz-info, ",
1452
+ "-moz-dialog",
1453
+ "-moz-button",
1454
+ "-moz-pull-down-menu",
1455
+ "-moz-list",
1456
+ "-moz-field"
1457
+ ],
1458
+ "default": [
1459
+ ],
1460
+ properties: {
1461
+ "font-weight": {
1462
+ types: [
1463
+ "Number"
1464
+ ],
1465
+ "default": [
1466
+ "normal",
1467
+ "400"
1468
+ ],
1469
+ keywords: [
1470
+ "normal",
1471
+ "bold",
1472
+ "lighter",
1473
+ "bolder"
1474
+ ],
1475
+ constraints: {
1476
+ value: {
1477
+ min: "1",
1478
+ max: "1000"
1479
+ }
1480
+ },
1481
+ mapping: {
1482
+ thin: "100",
1483
+ hairline: "100",
1484
+ "extra light": "200",
1485
+ "ultra light": "200",
1486
+ light: "300",
1487
+ normal: "400",
1488
+ regular: "400",
1489
+ medium: "500",
1490
+ "semi bold": "600",
1491
+ "demi bold": "600",
1492
+ bold: "700",
1493
+ "extra bold": "800",
1494
+ "ultra bold": "800",
1495
+ black: "900",
1496
+ heavy: "900",
1497
+ "extra black": "950",
1498
+ "ultra black": "950"
1499
+ }
1500
+ },
1501
+ "font-style": {
1502
+ types: [
1503
+ "Angle"
1504
+ ],
1505
+ "default": [
1506
+ "normal"
1507
+ ],
1508
+ keywords: [
1509
+ "normal",
1510
+ "italic",
1511
+ "oblique"
1512
+ ]
1513
+ },
1514
+ "font-size": {
1515
+ types: [
1516
+ "Length",
1517
+ "Perc"
1518
+ ],
1519
+ "default": [
1520
+ ],
1521
+ keywords: [
1522
+ "xx-small",
1523
+ "x-small",
1524
+ "small",
1525
+ "medium",
1526
+ "large",
1527
+ "x-large",
1528
+ "xx-large",
1529
+ "xxx-large",
1530
+ "larger",
1531
+ "smaller"
1532
+ ],
1533
+ required: true
1534
+ },
1535
+ "line-height": {
1536
+ types: [
1537
+ "Length",
1538
+ "Perc",
1539
+ "Number"
1540
+ ],
1541
+ "default": [
1542
+ "normal"
1543
+ ],
1544
+ keywords: [
1545
+ "normal"
1546
+ ],
1547
+ previous: "font-size",
1548
+ prefix: {
1549
+ typ: "Literal",
1550
+ val: "/"
1551
+ }
1552
+ },
1553
+ "font-stretch": {
1554
+ types: [
1555
+ "Perc"
1556
+ ],
1557
+ "default": [
1558
+ "normal"
1559
+ ],
1560
+ keywords: [
1561
+ "ultra-condensed",
1562
+ "extra-condensed",
1563
+ "condensed",
1564
+ "semi-condensed",
1565
+ "normal",
1566
+ "semi-expanded",
1567
+ "expanded",
1568
+ "extra-expanded",
1569
+ "ultra-expanded"
1570
+ ],
1571
+ mapping: {
1572
+ "ultra-condensed": "50%",
1573
+ "extra-condensed": "62.5%",
1574
+ condensed: "75%",
1575
+ "semi-condensed": "87.5%",
1576
+ normal: "100%",
1577
+ "semi-expanded": "112.5%",
1578
+ expanded: "125%",
1579
+ "extra-expanded": "150%",
1580
+ "ultra-expanded": "200%"
1581
+ }
1582
+ },
1583
+ "font-variant": {
1584
+ types: [
1585
+ ],
1586
+ "default": [
1587
+ "normal"
1588
+ ],
1589
+ keywords: [
1590
+ "normal",
1591
+ "none",
1592
+ "common-ligatures",
1593
+ "no-common-ligatures",
1594
+ "discretionary-ligatures",
1595
+ "no-discretionary-ligatures",
1596
+ "historical-ligatures",
1597
+ "no-historical-ligatures",
1598
+ "contextual",
1599
+ "no-contextual",
1600
+ "historical-forms",
1601
+ "small-caps",
1602
+ "all-small-caps",
1603
+ "petite-caps",
1604
+ "all-petite-caps",
1605
+ "unicase",
1606
+ "titling-caps",
1607
+ "ordinal",
1608
+ "slashed-zero",
1609
+ "lining-nums",
1610
+ "oldstyle-nums",
1611
+ "proportional-nums",
1612
+ "tabular-nums",
1613
+ "diagonal-fractions",
1614
+ "stacked-fractions",
1615
+ "ordinal",
1616
+ "slashed-zero",
1617
+ "ruby",
1618
+ "jis78",
1619
+ "jis83",
1620
+ "jis90",
1621
+ "jis04",
1622
+ "simplified",
1623
+ "traditional",
1624
+ "full-width",
1625
+ "proportional-width",
1626
+ "ruby",
1627
+ "sub",
1628
+ "super",
1629
+ "text",
1630
+ "emoji",
1631
+ "unicode"
1632
+ ]
1633
+ },
1634
+ "font-family": {
1635
+ types: [
1636
+ "String",
1637
+ "Iden"
1638
+ ],
1639
+ "default": [
1640
+ ],
1641
+ keywords: [
1642
+ "serif",
1643
+ "sans-serif",
1644
+ "monospace",
1645
+ "cursive",
1646
+ "fantasy",
1647
+ "system-ui",
1648
+ "ui-serif",
1649
+ "ui-sans-serif",
1650
+ "ui-monospace",
1651
+ "ui-rounded",
1652
+ "math",
1653
+ "emoji",
1654
+ "fangsong"
1655
+ ],
1656
+ required: true,
1657
+ multiple: true,
1658
+ separator: {
1659
+ typ: "Comma"
1660
+ }
1661
+ }
1662
+ }
1663
+ },
1664
+ "font-weight": {
1665
+ shorthand: "font"
1666
+ },
1667
+ "font-style": {
1668
+ shorthand: "font"
1669
+ },
1670
+ "font-size": {
1671
+ shorthand: "font"
1672
+ },
1673
+ "line-height": {
1674
+ shorthand: "font"
1675
+ },
1676
+ "font-stretch": {
1677
+ shorthand: "font"
1678
+ },
1679
+ "font-variant": {
1680
+ shorthand: "font"
1681
+ },
1682
+ "font-family": {
1683
+ shorthand: "font"
1684
+ },
1685
+ background: {
1686
+ shorthand: "background",
1687
+ pattern: "background-repeat background-color background-image background-attachment background-clip background-origin background-position background-size",
1688
+ keywords: [
1689
+ "none"
1690
+ ],
1691
+ "default": [
1692
+ ],
1693
+ multiple: true,
1694
+ separator: {
1695
+ typ: "Comma"
1696
+ },
1697
+ properties: {
1698
+ "background-repeat": {
1699
+ types: [
1700
+ ],
1701
+ "default": [
1702
+ "repeat"
1703
+ ],
1704
+ multiple: true,
1705
+ keywords: [
1706
+ "repeat-x",
1707
+ "repeat-y",
1708
+ "repeat",
1709
+ "space",
1710
+ "round",
1711
+ "no-repeat"
1712
+ ],
1713
+ mapping: {
1714
+ "repeat no-repeat": "repeat-x",
1715
+ "no-repeat repeat": "repeat-y",
1716
+ "repeat repeat": "repeat",
1717
+ "space space": "space",
1718
+ "round round": "round",
1719
+ "no-repeat no-repeat": "no-repeat"
1720
+ }
1721
+ },
1722
+ "background-color": {
1723
+ types: [
1724
+ "Color"
1725
+ ],
1726
+ "default": [
1727
+ "transparent"
1728
+ ],
1729
+ multiple: true,
1730
+ keywords: [
1731
+ ]
1732
+ },
1733
+ "background-image": {
1734
+ types: [
1735
+ "UrlFunc"
1736
+ ],
1737
+ "default": [
1738
+ "none"
1739
+ ],
1740
+ keywords: [
1741
+ "none"
1742
+ ]
1743
+ },
1744
+ "background-attachment": {
1745
+ types: [
1746
+ ],
1747
+ "default": [
1748
+ "scroll"
1749
+ ],
1750
+ multiple: true,
1751
+ keywords: [
1752
+ "scroll",
1753
+ "fixed",
1754
+ "local"
1755
+ ]
1756
+ },
1757
+ "background-clip": {
1758
+ types: [
1759
+ ],
1760
+ "default": [
1761
+ "border-box"
1762
+ ],
1763
+ multiple: true,
1764
+ keywords: [
1765
+ "border-box",
1766
+ "padding-box",
1767
+ "content-box",
1768
+ "text"
1769
+ ]
1770
+ },
1771
+ "background-origin": {
1772
+ types: [
1773
+ ],
1774
+ "default": [
1775
+ "padding-box"
1776
+ ],
1777
+ multiple: true,
1778
+ keywords: [
1779
+ "border-box",
1780
+ "padding-box",
1781
+ "content-box"
1782
+ ]
1783
+ },
1784
+ "background-position": {
1785
+ multiple: true,
1786
+ types: [
1787
+ "Perc",
1788
+ "Length"
1789
+ ],
1790
+ "default": [
1791
+ "0 0",
1792
+ "top left",
1793
+ "left top"
1794
+ ],
1795
+ keywords: [
1796
+ "top",
1797
+ "left",
1798
+ "center",
1799
+ "bottom",
1800
+ "right"
1801
+ ],
1802
+ mapping: {
1803
+ left: "0",
1804
+ top: "0",
1805
+ center: "50%",
1806
+ bottom: "100%",
1807
+ right: "100%"
1808
+ },
1809
+ constraints: {
1810
+ mapping: {
1811
+ max: 2
1812
+ }
1813
+ }
1814
+ },
1815
+ "background-size": {
1816
+ multiple: true,
1817
+ previous: "background-position",
1818
+ prefix: {
1819
+ typ: "Literal",
1820
+ val: "/"
1821
+ },
1822
+ types: [
1823
+ "Perc",
1824
+ "Length"
1825
+ ],
1826
+ "default": [
1827
+ "auto",
1828
+ "auto auto"
1829
+ ],
1830
+ keywords: [
1831
+ "auto",
1832
+ "cover",
1833
+ "contain"
1834
+ ],
1835
+ mapping: {
1836
+ "auto auto": "auto"
1837
+ }
1838
+ }
1839
+ }
1840
+ },
1841
+ "background-repeat": {
1842
+ shorthand: "background"
1843
+ },
1844
+ "background-color": {
1845
+ shorthand: "background"
1846
+ },
1847
+ "background-image": {
1848
+ shorthand: "background"
1849
+ },
1850
+ "background-attachment": {
1851
+ shorthand: "background"
1852
+ },
1853
+ "background-clip": {
1854
+ shorthand: "background"
1855
+ },
1856
+ "background-origin": {
1857
+ shorthand: "background"
1858
+ },
1859
+ "background-position": {
1860
+ shorthand: "background"
1861
+ },
1862
+ "background-size": {
1863
+ shorthand: "background"
1864
+ }
1865
+ };
1866
+ var config$1 = {
1867
+ properties: properties,
1868
+ map: map
1869
+ };
1870
+
1871
+ const getConfig = () => config$1;
1872
+
1873
+ const funcList = ['clamp', 'calc'];
1874
+ function matchType(val, properties) {
1875
+ if (val.typ == 'Iden' && properties.keywords.includes(val.val) ||
1876
+ (properties.types.includes(val.typ))) {
1877
+ return true;
1679
1878
  }
1680
- return '';
1681
- }
1682
- function renderToken(token, options = {}, reducer) {
1683
- if (reducer == null) {
1684
- reducer = function (acc, curr) {
1685
- if (curr.typ == 'Comment' && options.removeComments) {
1686
- if (!options.preserveLicense || !curr.val.startsWith('/*!')) {
1687
- return acc;
1688
- }
1689
- return acc + curr.val;
1690
- }
1691
- return acc + renderToken(curr, options, reducer);
1692
- };
1879
+ if (val.typ == 'Number' && val.val == '0') {
1880
+ return properties.types.some(type => type == 'Length' || type == 'Angle');
1693
1881
  }
1694
- switch (token.typ) {
1695
- case 'Color':
1696
- if (options.minify || options.colorConvert) {
1697
- if (token.kin == 'lit' && token.val.toLowerCase() == 'currentcolor') {
1698
- return 'currentcolor';
1699
- }
1700
- let value = token.kin == 'hex' ? token.val.toLowerCase() : (token.kin == 'lit' ? COLORS_NAMES[token.val.toLowerCase()] : '');
1701
- if (token.val == 'rgb' || token.val == 'rgba') {
1702
- value = rgb2Hex(token);
1703
- }
1704
- else if (token.val == 'hsl' || token.val == 'hsla') {
1705
- value = hsl2Hex(token);
1706
- }
1707
- else if (token.val == 'hwb') {
1708
- value = hwb2hex(token);
1709
- }
1710
- else if (token.val == 'device-cmyk') {
1711
- value = cmyk2hex(token);
1712
- }
1713
- const named_color = NAMES_COLORS[value];
1714
- if (value !== '') {
1715
- if (value.length == 7) {
1716
- if (value[1] == value[2] &&
1717
- value[3] == value[4] &&
1718
- value[5] == value[6]) {
1719
- value = `#${value[1]}${value[3]}${value[5]}`;
1720
- }
1721
- }
1722
- else if (value.length == 9) {
1723
- if (value[1] == value[2] &&
1724
- value[3] == value[4] &&
1725
- value[5] == value[6] &&
1726
- value[7] == value[8]) {
1727
- value = `#${value[1]}${value[3]}${value[5]}${value[7]}`;
1728
- }
1729
- }
1730
- return named_color != null && named_color.length <= value.length ? named_color : value;
1731
- }
1732
- }
1733
- if (token.kin == 'hex' || token.kin == 'lit') {
1734
- return token.val;
1735
- }
1736
- case 'Start-parens':
1737
- if (!('chi' in token)) {
1738
- return '(';
1739
- }
1740
- case 'Func':
1741
- case 'UrlFunc':
1742
- case 'Pseudo-class-func':
1743
- // @ts-ignore
1744
- return ( /* options.minify && 'Pseudo-class-func' == token.typ && token.val.slice(0, 2) == '::' ? token.val.slice(1) :*/token.val ?? '') + '(' + token.chi.reduce(reducer, '') + ')';
1745
- case 'Includes':
1746
- return '~=';
1747
- case 'Dash-match':
1748
- return '|=';
1749
- case 'Lt':
1750
- return '<';
1751
- case 'Lte':
1752
- return '<=';
1753
- case 'Gt':
1754
- return '>';
1755
- case 'Gte':
1756
- return '>=';
1757
- case 'End-parens':
1758
- return ')';
1759
- case 'Attr-start':
1760
- return '[';
1761
- case 'Attr-end':
1762
- return ']';
1763
- case 'Whitespace':
1764
- return ' ';
1765
- case 'Colon':
1766
- return ':';
1767
- case 'Semi-colon':
1768
- return ';';
1769
- case 'Comma':
1770
- return ',';
1771
- case 'Important':
1772
- return '!important';
1773
- case 'Attr':
1774
- return '[' + token.chi.reduce(reducer, '') + ']';
1775
- case 'Time':
1776
- case 'Angle':
1777
- case 'Length':
1778
- case 'Dimension':
1779
- case 'Frequency':
1780
- case 'Resolution':
1781
- let val = reduceNumber(token.val);
1782
- let unit = token.unit;
1783
- if (token.typ == 'Angle') {
1784
- const angle = getAngle(token);
1785
- let v;
1786
- let value = val + unit;
1787
- for (const u of ['turn', 'deg', 'rad', 'grad']) {
1788
- if (token.unit == u) {
1789
- continue;
1790
- }
1791
- switch (u) {
1792
- case 'turn':
1793
- v = reduceNumber(angle);
1794
- if (v.length + 4 < value.length) {
1795
- val = v;
1796
- unit = u;
1797
- value = v + u;
1798
- }
1799
- break;
1800
- case 'deg':
1801
- v = reduceNumber(angle * 360);
1802
- if (v.length + 3 < value.length) {
1803
- val = v;
1804
- unit = u;
1805
- value = v + u;
1806
- }
1807
- break;
1808
- case 'rad':
1809
- v = reduceNumber(angle * (2 * Math.PI));
1810
- if (v.length + 3 < value.length) {
1811
- val = v;
1812
- unit = u;
1813
- value = v + u;
1814
- }
1815
- break;
1816
- case 'grad':
1817
- v = reduceNumber(angle * 400);
1818
- if (v.length + 4 < value.length) {
1819
- val = v;
1820
- unit = u;
1821
- value = v + u;
1822
- }
1823
- break;
1824
- }
1825
- }
1826
- }
1827
- if (val === '0') {
1828
- if (unit == 'Time') {
1829
- return '0s';
1830
- }
1831
- if (unit == 'Frequency') {
1832
- return '0Hz';
1833
- }
1834
- // @ts-ignore
1835
- if (unit == 'Resolution') {
1836
- return '0x';
1837
- }
1838
- return '0';
1839
- }
1840
- return val + unit;
1841
- case 'Perc':
1842
- return token.val + '%';
1843
- case 'Number':
1844
- const num = (+token.val).toString();
1845
- if (token.val.length < num.length) {
1846
- return token.val;
1847
- }
1848
- if (num.charAt(0) === '0' && num.length > 1) {
1849
- return num.slice(1);
1850
- }
1851
- const slice = num.slice(0, 2);
1852
- if (slice == '-0') {
1853
- return '-' + num.slice(2);
1854
- }
1855
- return num;
1856
- case 'Comment':
1857
- if (options.removeComments && (!options.preserveLicense || !token.val.startsWith('/*!'))) {
1858
- return '';
1859
- }
1860
- case 'Url-token':
1861
- case 'At-rule':
1862
- case 'Hash':
1863
- case 'Pseudo-class':
1864
- case 'Literal':
1865
- case 'String':
1866
- case 'Iden':
1867
- case 'Delim':
1868
- return /* options.minify && 'Pseudo-class' == token.typ && '::' == token.val.slice(0, 2) ? token.val.slice(1) : */ token.val;
1882
+ if (val.typ == 'Func' && funcList.includes(val.val)) {
1883
+ return val.chi.every((t => ['Literal', 'Comma', 'Whitespace', 'Start-parens', 'End-parens'].includes(t.typ) || matchType(t, properties)));
1869
1884
  }
1870
- console.error(`unexpected token ${JSON.stringify(token, null, 1)}`);
1871
- // throw new Error(`unexpected token ${JSON.stringify(token, null, 1)}`);
1872
- return '';
1885
+ return false;
1873
1886
  }
1874
1887
 
1875
1888
  function eq(a, b) {
@@ -3517,31 +3530,18 @@ function* tokenize(iterator) {
3517
3530
  return char;
3518
3531
  }
3519
3532
  while (value = next()) {
3520
- if (ind >= iterator.length) {
3521
- if (buffer.length > 0) {
3522
- yield pushToken(buffer);
3523
- buffer = '';
3524
- }
3525
- break;
3526
- }
3527
3533
  if (isWhiteSpace(value.charCodeAt(0))) {
3528
3534
  if (buffer.length > 0) {
3529
3535
  yield pushToken(buffer);
3530
3536
  buffer = '';
3531
3537
  }
3532
3538
  while (value = next()) {
3533
- if (ind >= iterator.length) {
3534
- break;
3535
- }
3536
3539
  if (!isWhiteSpace(value.charCodeAt(0))) {
3537
3540
  break;
3538
3541
  }
3539
3542
  }
3540
3543
  yield pushToken('', 'Whitespace');
3541
3544
  buffer = '';
3542
- if (ind >= iterator.length) {
3543
- break;
3544
- }
3545
3545
  }
3546
3546
  switch (value) {
3547
3547
  case '/':
@@ -3555,34 +3555,12 @@ function* tokenize(iterator) {
3555
3555
  }
3556
3556
  buffer += value;
3557
3557
  if (peek() == '*') {
3558
- buffer += '*';
3559
- // i++;
3560
- next();
3558
+ buffer += next();
3561
3559
  while (value = next()) {
3562
- if (ind >= iterator.length) {
3563
- yield pushToken(buffer, 'Bad-comment');
3564
- break;
3565
- }
3566
- if (value == '\\') {
3567
- buffer += value;
3568
- value = next();
3569
- if (ind >= iterator.length) {
3570
- yield pushToken(buffer, 'Bad-comment');
3571
- break;
3572
- }
3573
- buffer += value;
3574
- continue;
3575
- }
3576
3560
  if (value == '*') {
3577
3561
  buffer += value;
3578
- value = next();
3579
- if (ind >= iterator.length) {
3580
- yield pushToken(buffer, 'Bad-comment');
3581
- break;
3582
- }
3583
- buffer += value;
3584
- if (value == '/') {
3585
- yield pushToken(buffer, 'Comment');
3562
+ if (peek() == '/') {
3563
+ yield pushToken(buffer + next(), 'Comment');
3586
3564
  buffer = '';
3587
3565
  break;
3588
3566
  }
@@ -3591,6 +3569,8 @@ function* tokenize(iterator) {
3591
3569
  buffer += value;
3592
3570
  }
3593
3571
  }
3572
+ yield pushToken(buffer, 'Bad-comment');
3573
+ buffer = '';
3594
3574
  }
3595
3575
  break;
3596
3576
  case '<':
@@ -3604,15 +3584,9 @@ function* tokenize(iterator) {
3604
3584
  break;
3605
3585
  }
3606
3586
  buffer += value;
3607
- value = next();
3608
- if (ind >= iterator.length) {
3609
- break;
3610
- }
3611
3587
  if (peek(3) == '!--') {
3588
+ buffer += next(3);
3612
3589
  while (value = next()) {
3613
- if (ind >= iterator.length) {
3614
- break;
3615
- }
3616
3590
  buffer += value;
3617
3591
  if (value == '>' && prev(2) == '--') {
3618
3592
  yield pushToken(buffer, 'CDOCOMM');
@@ -3621,15 +3595,14 @@ function* tokenize(iterator) {
3621
3595
  }
3622
3596
  }
3623
3597
  }
3624
- if (ind >= iterator.length) {
3625
- yield pushToken(buffer, 'BADCDO');
3626
- buffer = '';
3627
- }
3598
+ // if (!peek()) {
3599
+ yield pushToken(buffer, 'Bad-cdo');
3600
+ buffer = '';
3601
+ // }
3628
3602
  break;
3629
3603
  case '\\':
3630
- value = next();
3631
3604
  // EOF
3632
- if (ind + 1 >= iterator.length) {
3605
+ if (!(value = next())) {
3633
3606
  // end of stream ignore \\
3634
3607
  yield pushToken(buffer);
3635
3608
  buffer = '';
@@ -3648,8 +3621,7 @@ function* tokenize(iterator) {
3648
3621
  buffer = '';
3649
3622
  }
3650
3623
  buffer += value;
3651
- value = next();
3652
- if (ind >= iterator.length) {
3624
+ if (!(value = next())) {
3653
3625
  yield pushToken(buffer);
3654
3626
  buffer = '';
3655
3627
  break;
@@ -3816,8 +3788,7 @@ function* tokenize(iterator) {
3816
3788
  yield pushToken(buffer);
3817
3789
  buffer = '';
3818
3790
  }
3819
- const important = peek(9);
3820
- if (important == 'important') {
3791
+ if (peek(9) == 'important') {
3821
3792
  yield pushToken('', 'Important');
3822
3793
  next(9);
3823
3794
  buffer = '';
@@ -3884,10 +3855,6 @@ async function parse$1(iterator, opt = {}) {
3884
3855
  let tokens = results.map(mapToken);
3885
3856
  let i;
3886
3857
  let loc;
3887
- // if ((<Token>tokens.at(-1))?.typ == 'EOF') {
3888
- //
3889
- // tokens.pop();
3890
- // }
3891
3858
  for (i = 0; i < tokens.length; i++) {
3892
3859
  if (tokens[i].typ == 'Comment') {
3893
3860
  // @ts-ignore
@@ -4164,6 +4131,11 @@ async function parse$1(iterator, opt = {}) {
4164
4131
  if (item == null) {
4165
4132
  break;
4166
4133
  }
4134
+ // console.debug({item});
4135
+ if (item.hint != null && item.hint.startsWith('Bad-')) {
4136
+ // bad token
4137
+ continue;
4138
+ }
4167
4139
  tokens.push(item);
4168
4140
  bytesIn = item.bytesIn;
4169
4141
  if (item.token == ';' || item.token == '{') {
@@ -4473,41 +4445,33 @@ function parseTokens(tokens, options = {}) {
4473
4445
  // @ts-ignore
4474
4446
  t.chi.pop();
4475
4447
  }
4476
- let isColor = true;
4477
4448
  // @ts-ignore
4478
- if (options.parseColor && ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk'].includes(t.val)) {
4449
+ if (options.parseColor && t.typ == 'Func' && isColor(t)) {
4450
+ // if (isColor) {
4479
4451
  // @ts-ignore
4480
- for (const v of t.chi) {
4481
- if (v.typ == 'Func' && v.val == 'var') {
4482
- isColor = false;
4483
- break;
4484
- }
4485
- }
4486
- if (isColor) {
4487
- // @ts-ignore
4488
- t.typ = 'Color';
4489
- // @ts-ignore
4490
- t.kin = t.val;
4452
+ t.typ = 'Color';
4453
+ // @ts-ignore
4454
+ t.kin = t.val;
4455
+ // @ts-ignore
4456
+ let m = t.chi.length;
4457
+ while (m-- > 0) {
4491
4458
  // @ts-ignore
4492
- let m = t.chi.length;
4493
- while (m-- > 0) {
4459
+ if (['Literal'].concat(trimWhiteSpace).includes(t.chi[m].typ)) {
4494
4460
  // @ts-ignore
4495
- if (['Literal'].concat(trimWhiteSpace).includes(t.chi[m].typ)) {
4461
+ if (t.chi[m + 1]?.typ == 'Whitespace') {
4496
4462
  // @ts-ignore
4497
- if (t.chi[m + 1]?.typ == 'Whitespace') {
4498
- // @ts-ignore
4499
- t.chi.splice(m + 1, 1);
4500
- }
4463
+ t.chi.splice(m + 1, 1);
4464
+ }
4465
+ // @ts-ignore
4466
+ if (t.chi[m - 1]?.typ == 'Whitespace') {
4501
4467
  // @ts-ignore
4502
- if (t.chi[m - 1]?.typ == 'Whitespace') {
4503
- // @ts-ignore
4504
- t.chi.splice(m - 1, 1);
4505
- m--;
4506
- }
4468
+ t.chi.splice(m - 1, 1);
4469
+ m--;
4507
4470
  }
4508
4471
  }
4509
- continue;
4510
4472
  }
4473
+ continue;
4474
+ // }
4511
4475
  }
4512
4476
  if (t.typ == 'UrlFunc') {
4513
4477
  // @ts-ignore
@@ -4532,7 +4496,7 @@ function parseTokens(tokens, options = {}) {
4532
4496
  // @ts-ignore
4533
4497
  if (t.chi.length > 0) {
4534
4498
  // @ts-ignore
4535
- parseTokens(t.chi, t.typ);
4499
+ parseTokens(t.chi, options);
4536
4500
  if (t.typ == 'Pseudo-class-func' && t.val == ':is' && options.minify) {
4537
4501
  //
4538
4502
  const count = t.chi.filter(t => t.typ != 'Comment').length;
@@ -4551,7 +4515,7 @@ function parseTokens(tokens, options = {}) {
4551
4515
  if (t.typ == 'Iden') {
4552
4516
  // named color
4553
4517
  const value = t.val.toLowerCase();
4554
- if (COLORS_NAMES[value] != null) {
4518
+ if (value in COLORS_NAMES) {
4555
4519
  Object.assign(t, {
4556
4520
  typ: 'Color',
4557
4521
  val: COLORS_NAMES[value].length < value.length ? COLORS_NAMES[value] : value,
@@ -4698,19 +4662,22 @@ async function load(url, currentFile) {
4698
4662
  return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : promises.readFile(resolved.absolute, { encoding: 'utf-8' });
4699
4663
  }
4700
4664
 
4701
- function parse(iterator, opt = {}) {
4665
+ async function parse(iterator, opt = {}) {
4702
4666
  return parse$1(iterator, Object.assign(opt, { load, resolve, cwd: opt.cwd ?? process.cwd() }));
4703
4667
  }
4704
- function transform(css, options = {}) {
4668
+ async function transform(css, options = {}) {
4705
4669
  return transform$1(css, Object.assign(options, { load, resolve, cwd: options.cwd ?? process.cwd() }));
4706
4670
  }
4707
4671
 
4672
+ exports.colorsFunc = colorsFunc;
4708
4673
  exports.combinators = combinators;
4709
4674
  exports.dirname = dirname;
4675
+ exports.funcList = funcList;
4710
4676
  exports.getConfig = getConfig;
4711
4677
  exports.hasDeclaration = hasDeclaration;
4712
4678
  exports.isAngle = isAngle;
4713
4679
  exports.isAtKeyword = isAtKeyword;
4680
+ exports.isColor = isColor;
4714
4681
  exports.isDigit = isDigit;
4715
4682
  exports.isDimension = isDimension;
4716
4683
  exports.isFrequency = isFrequency;