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