@tbela99/css-parser 1.2.0 → 1.3.1

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.
Files changed (70) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +29 -11
  3. package/dist/index-umd-web.js +2041 -1967
  4. package/dist/index.cjs +2129 -1964
  5. package/dist/index.d.ts +1936 -77
  6. package/dist/lib/ast/expand.js +4 -65
  7. package/dist/lib/ast/features/calc.js +3 -27
  8. package/dist/lib/ast/features/inlinecssvariables.js +2 -21
  9. package/dist/lib/ast/features/prefix.js +2 -1
  10. package/dist/lib/ast/features/transform.js +4 -3
  11. package/dist/lib/ast/features/type.js +9 -0
  12. package/dist/lib/ast/math/expression.js +26 -149
  13. package/dist/lib/ast/math/math.js +9 -9
  14. package/dist/lib/ast/minify.js +82 -171
  15. package/dist/lib/ast/transform/compute.js +4 -37
  16. package/dist/lib/ast/transform/matrix.js +33 -34
  17. package/dist/lib/ast/transform/minify.js +32 -51
  18. package/dist/lib/ast/transform/perspective.js +1 -1
  19. package/dist/lib/ast/transform/rotate.js +13 -13
  20. package/dist/lib/ast/transform/scale.js +8 -8
  21. package/dist/lib/ast/transform/skew.js +4 -4
  22. package/dist/lib/ast/transform/translate.js +8 -8
  23. package/dist/lib/ast/transform/utils.js +31 -39
  24. package/dist/lib/ast/types.js +459 -5
  25. package/dist/lib/ast/walk.js +18 -0
  26. package/dist/lib/fs/resolve.js +11 -3
  27. package/dist/lib/parser/declaration/map.js +1 -0
  28. package/dist/lib/parser/declaration/set.js +2 -2
  29. package/dist/lib/parser/parse.js +139 -32
  30. package/dist/lib/parser/tokenize.js +41 -93
  31. package/dist/lib/parser/utils/type.js +1 -1
  32. package/dist/lib/renderer/render.js +61 -30
  33. package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
  34. package/dist/lib/syntax/color/cmyk.js +2 -2
  35. package/dist/lib/syntax/color/color-mix.js +11 -12
  36. package/dist/lib/syntax/color/color.js +14 -7
  37. package/dist/lib/syntax/color/hsl.js +4 -4
  38. package/dist/lib/syntax/color/hwb.js +27 -8
  39. package/dist/lib/syntax/color/lab.js +4 -4
  40. package/dist/lib/syntax/color/lch.js +4 -4
  41. package/dist/lib/syntax/color/oklab.js +4 -4
  42. package/dist/lib/syntax/color/oklch.js +4 -4
  43. package/dist/lib/syntax/color/relativecolor.js +1 -1
  44. package/dist/lib/syntax/color/rgb.js +4 -4
  45. package/dist/lib/syntax/color/utils/components.js +15 -3
  46. package/dist/lib/syntax/color/utils/distance.js +15 -1
  47. package/dist/lib/syntax/syntax.js +18 -17
  48. package/dist/lib/syntax/utils.js +1 -1
  49. package/dist/lib/validation/at-rules/document.js +1 -1
  50. package/dist/lib/validation/at-rules/import.js +4 -4
  51. package/dist/lib/validation/at-rules/keyframes.js +0 -11
  52. package/dist/lib/validation/at-rules/supports.js +6 -6
  53. package/dist/lib/validation/config.js +0 -4
  54. package/dist/lib/validation/config.json.js +33 -30
  55. package/dist/lib/validation/parser/parse.js +0 -8
  56. package/dist/lib/validation/selector.js +0 -9
  57. package/dist/lib/validation/syntax.js +17 -135
  58. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -11
  59. package/dist/lib/validation/syntaxes/family-name.js +0 -32
  60. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -11
  61. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -26
  62. package/dist/lib/validation/syntaxes/url.js +0 -33
  63. package/dist/lib/validation/utils/list.js +0 -8
  64. package/dist/node.js +229 -0
  65. package/dist/web.js +158 -0
  66. package/package.json +14 -11
  67. package/dist/node/index.js +0 -57
  68. package/dist/node/load.js +0 -20
  69. package/dist/web/index.js +0 -66
  70. package/dist/web/load.js +0 -31
package/dist/index.d.ts CHANGED
@@ -1,5 +1,16 @@
1
1
  /**
2
- * validation level enum
2
+ * syntax validation enum
3
+ */
4
+ declare enum SyntaxValidationResult {
5
+ /** valid syntax */
6
+ Valid = 0,
7
+ /** drop invalid syntax */
8
+ Drop = 1,
9
+ /** preserve unknown at-rules, declarations and pseudo-classes */
10
+ Lenient = 2
11
+ }
12
+ /**
13
+ * enum of validation levels
3
14
  */
4
15
  declare enum ValidationLevel {
5
16
  /**
@@ -16,183 +27,650 @@ declare enum ValidationLevel {
16
27
  All = 2
17
28
  }
18
29
  /**
19
- * token types enum
30
+ * enum of all token types
20
31
  */
21
32
  declare enum EnumToken {
33
+ /**
34
+ * comment token
35
+ */
22
36
  CommentTokenType = 0,
37
+ /**
38
+ * cdata section token
39
+ */
23
40
  CDOCOMMTokenType = 1,
41
+ /**
42
+ * style sheet node type
43
+ */
24
44
  StyleSheetNodeType = 2,
45
+ /**
46
+ * at-rule node type
47
+ */
25
48
  AtRuleNodeType = 3,
49
+ /**
50
+ * rule node type
51
+ */
26
52
  RuleNodeType = 4,
53
+ /**
54
+ * declaration node type
55
+ */
27
56
  DeclarationNodeType = 5,
57
+ /**
58
+ * literal token type
59
+ */
28
60
  LiteralTokenType = 6,
61
+ /**
62
+ * identifier token type
63
+ */
29
64
  IdenTokenType = 7,
65
+ /**
66
+ * dashed identifier token type
67
+ */
30
68
  DashedIdenTokenType = 8,
69
+ /**
70
+ * comma token type
71
+ */
31
72
  CommaTokenType = 9,
73
+ /**
74
+ * colon token type
75
+ */
32
76
  ColonTokenType = 10,
77
+ /**
78
+ * semicolon token type
79
+ */
33
80
  SemiColonTokenType = 11,
81
+ /**
82
+ * number token type
83
+ */
34
84
  NumberTokenType = 12,
85
+ /**
86
+ * at-rule token type
87
+ */
35
88
  AtRuleTokenType = 13,
89
+ /**
90
+ * percentage token type
91
+ */
36
92
  PercentageTokenType = 14,
93
+ /**
94
+ * function token type
95
+ */
37
96
  FunctionTokenType = 15,
97
+ /**
98
+ * timeline function token type
99
+ */
38
100
  TimelineFunctionTokenType = 16,
101
+ /**
102
+ * timing function token type
103
+ */
39
104
  TimingFunctionTokenType = 17,
105
+ /**
106
+ * url function token type
107
+ */
40
108
  UrlFunctionTokenType = 18,
109
+ /**
110
+ * image function token type
111
+ */
41
112
  ImageFunctionTokenType = 19,
113
+ /**
114
+ * string token type
115
+ */
42
116
  StringTokenType = 20,
117
+ /**
118
+ * unclosed string token type
119
+ */
43
120
  UnclosedStringTokenType = 21,
121
+ /**
122
+ * dimension token type
123
+ */
44
124
  DimensionTokenType = 22,
125
+ /**
126
+ * length token type
127
+ */
45
128
  LengthTokenType = 23,
129
+ /**
130
+ * angle token type
131
+ */
46
132
  AngleTokenType = 24,
133
+ /**
134
+ * time token type
135
+ */
47
136
  TimeTokenType = 25,
137
+ /**
138
+ * frequency token type
139
+ */
48
140
  FrequencyTokenType = 26,
141
+ /**
142
+ * resolution token type
143
+ */
49
144
  ResolutionTokenType = 27,
145
+ /**
146
+ * hash token type
147
+ */
50
148
  HashTokenType = 28,
149
+ /**
150
+ * block start token type
151
+ */
51
152
  BlockStartTokenType = 29,
153
+ /**
154
+ * block end token type
155
+ */
52
156
  BlockEndTokenType = 30,
157
+ /**
158
+ * attribute start token type
159
+ */
53
160
  AttrStartTokenType = 31,
161
+ /**
162
+ * attribute end token type
163
+ */
54
164
  AttrEndTokenType = 32,
165
+ /**
166
+ * start parentheses token type
167
+ */
55
168
  StartParensTokenType = 33,
169
+ /**
170
+ * end parentheses token type
171
+ */
56
172
  EndParensTokenType = 34,
173
+ /**
174
+ * parentheses token type
175
+ */
57
176
  ParensTokenType = 35,
177
+ /**
178
+ * whitespace token type
179
+ */
58
180
  WhitespaceTokenType = 36,
181
+ /**
182
+ * include match token type
183
+ */
59
184
  IncludeMatchTokenType = 37,
185
+ /**
186
+ * dash match token type
187
+ */
60
188
  DashMatchTokenType = 38,
189
+ /**
190
+ * equal match token type
191
+ */
61
192
  EqualMatchTokenType = 39,
193
+ /**
194
+ * less than token type
195
+ */
62
196
  LtTokenType = 40,
197
+ /**
198
+ * less than or equal to token type
199
+ */
63
200
  LteTokenType = 41,
201
+ /**
202
+ * greater than token type
203
+ */
64
204
  GtTokenType = 42,
205
+ /**
206
+ * greater than or equal to token type
207
+ */
65
208
  GteTokenType = 43,
209
+ /**
210
+ * pseudo-class token type
211
+ */
66
212
  PseudoClassTokenType = 44,
213
+ /**
214
+ * pseudo-class function token type
215
+ */
67
216
  PseudoClassFuncTokenType = 45,
217
+ /**
218
+ * delimiter token type
219
+ */
68
220
  DelimTokenType = 46,
221
+ /**
222
+ * URL token type
223
+ */
69
224
  UrlTokenTokenType = 47,
225
+ /**
226
+ * end of file token type
227
+ */
70
228
  EOFTokenType = 48,
229
+ /**
230
+ * important token type
231
+ */
71
232
  ImportantTokenType = 49,
233
+ /**
234
+ * color token type
235
+ */
72
236
  ColorTokenType = 50,
237
+ /**
238
+ * attribute token type
239
+ */
73
240
  AttrTokenType = 51,
241
+ /**
242
+ * bad comment token type
243
+ */
74
244
  BadCommentTokenType = 52,
245
+ /**
246
+ * bad cdo token type
247
+ */
75
248
  BadCdoTokenType = 53,
249
+ /**
250
+ * bad URL token type
251
+ */
76
252
  BadUrlTokenType = 54,
253
+ /**
254
+ * bad string token type
255
+ */
77
256
  BadStringTokenType = 55,
257
+ /**
258
+ * binary expression token type
259
+ */
78
260
  BinaryExpressionTokenType = 56,
261
+ /**
262
+ * unary expression token type
263
+ */
79
264
  UnaryExpressionTokenType = 57,
265
+ /**
266
+ * flex token type
267
+ */
80
268
  FlexTokenType = 58,
269
+ /**
270
+ * token list token type
271
+ */
81
272
  ListToken = 59,
273
+ /**
274
+ * addition token type
275
+ */
82
276
  Add = 60,
277
+ /**
278
+ * multiplication token type
279
+ */
83
280
  Mul = 61,
281
+ /**
282
+ * division token type
283
+ */
84
284
  Div = 62,
285
+ /**
286
+ * subtraction token type
287
+ */
85
288
  Sub = 63,
289
+ /**
290
+ * column combinator token type
291
+ */
86
292
  ColumnCombinatorTokenType = 64,
293
+ /**
294
+ * contain match token type
295
+ */
87
296
  ContainMatchTokenType = 65,
297
+ /**
298
+ * start match token type
299
+ */
88
300
  StartMatchTokenType = 66,
301
+ /**
302
+ * end match token type
303
+ */
89
304
  EndMatchTokenType = 67,
305
+ /**
306
+ * match expression token type
307
+ */
90
308
  MatchExpressionTokenType = 68,
309
+ /**
310
+ * namespace attribute token type
311
+ */
91
312
  NameSpaceAttributeTokenType = 69,
313
+ /**
314
+ * fraction token type
315
+ */
92
316
  FractionTokenType = 70,
317
+ /**
318
+ * identifier list token type
319
+ */
93
320
  IdenListTokenType = 71,
321
+ /**
322
+ * grid template function token type
323
+ */
94
324
  GridTemplateFuncTokenType = 72,
325
+ /**
326
+ * keyframe rule node type
327
+ */
95
328
  KeyFrameRuleNodeType = 73,
329
+ /**
330
+ * class selector token type
331
+ */
96
332
  ClassSelectorTokenType = 74,
333
+ /**
334
+ * universal selector token type
335
+ */
97
336
  UniversalSelectorTokenType = 75,
337
+ /**
338
+ * child combinator token type
339
+ */
98
340
  ChildCombinatorTokenType = 76,// >
341
+ /**
342
+ * descendant combinator token type
343
+ */
99
344
  DescendantCombinatorTokenType = 77,// whitespace
345
+ /**
346
+ * next sibling combinator token type
347
+ */
100
348
  NextSiblingCombinatorTokenType = 78,// +
349
+ /**
350
+ * subsequent sibling combinator token type
351
+ */
101
352
  SubsequentSiblingCombinatorTokenType = 79,// ~
353
+ /**
354
+ * nesting selector token type
355
+ */
102
356
  NestingSelectorTokenType = 80,// &
357
+ /**
358
+ * invalid rule token type
359
+ */
103
360
  InvalidRuleTokenType = 81,
361
+ /**
362
+ * invalid class selector token type
363
+ */
104
364
  InvalidClassSelectorTokenType = 82,
365
+ /**
366
+ * invalid attribute token type
367
+ */
105
368
  InvalidAttrTokenType = 83,
369
+ /**
370
+ * invalid at rule token type
371
+ */
106
372
  InvalidAtRuleTokenType = 84,
373
+ /**
374
+ * media query condition token type
375
+ */
107
376
  MediaQueryConditionTokenType = 85,
377
+ /**
378
+ * media feature token type
379
+ */
108
380
  MediaFeatureTokenType = 86,
381
+ /**
382
+ * media feature only token type
383
+ */
109
384
  MediaFeatureOnlyTokenType = 87,
385
+ /**
386
+ * media feature not token type
387
+ */
110
388
  MediaFeatureNotTokenType = 88,
389
+ /**
390
+ * media feature and token type
391
+ */
111
392
  MediaFeatureAndTokenType = 89,
393
+ /**
394
+ * media feature or token type
395
+ */
112
396
  MediaFeatureOrTokenType = 90,
397
+ /**
398
+ * pseudo page token type
399
+ */
113
400
  PseudoPageTokenType = 91,
401
+ /**
402
+ * pseudo element token type
403
+ */
114
404
  PseudoElementTokenType = 92,
405
+ /**
406
+ * keyframe at rule node type
407
+ */
115
408
  KeyframeAtRuleNodeType = 93,
409
+ /**
410
+ * invalid declaration node type
411
+ */
116
412
  InvalidDeclarationNodeType = 94,
413
+ /**
414
+ * alias for time token type
415
+ */
117
416
  Time = 25,
417
+ /**
418
+ * alias for identifier token type
419
+ */
118
420
  Iden = 7,
421
+ /**
422
+ * alias for end of file token type
423
+ */
119
424
  EOF = 48,
425
+ /**
426
+ * alias for hash token type
427
+ */
120
428
  Hash = 28,
429
+ /**
430
+ * alias for flex token type
431
+ */
121
432
  Flex = 58,
433
+ /**
434
+ * alias for angle token type
435
+ */
122
436
  Angle = 24,
437
+ /**
438
+ * alias for color token type
439
+ */
123
440
  Color = 50,
441
+ /**
442
+ * alias for comma token type
443
+ */
124
444
  Comma = 9,
445
+ /**
446
+ * alias for string token type
447
+ */
125
448
  String = 20,
449
+ /**
450
+ * alias for length token type
451
+ */
126
452
  Length = 23,
453
+ /**
454
+ * alias for number token type
455
+ */
127
456
  Number = 12,
457
+ /**
458
+ * alias for percentage token type
459
+ */
128
460
  Perc = 14,
461
+ /**
462
+ * alias for literal token type
463
+ */
129
464
  Literal = 6,
465
+ /**
466
+ * alias for comment token type
467
+ */
130
468
  Comment = 0,
469
+ /**
470
+ * alias for url function token type
471
+ */
131
472
  UrlFunc = 18,
473
+ /**
474
+ * alias for dimension token type
475
+ */
132
476
  Dimension = 22,
477
+ /**
478
+ * alias for frequency token type
479
+ */
133
480
  Frequency = 26,
481
+ /**
482
+ * alias for resolution token type
483
+ */
134
484
  Resolution = 27,
485
+ /**
486
+ * alias for whitespace token type
487
+ */
135
488
  Whitespace = 36,
489
+ /**
490
+ * alias for identifier list token type
491
+ */
136
492
  IdenList = 71,
493
+ /**
494
+ * alias for dashed identifier token type
495
+ */
137
496
  DashedIden = 8,
497
+ /**
498
+ * alias for grid template function token type
499
+ */
138
500
  GridTemplateFunc = 72,
501
+ /**
502
+ * alias for image function token type
503
+ */
139
504
  ImageFunc = 19,
505
+ /**
506
+ * alias for comment node type
507
+ */
140
508
  CommentNodeType = 0,
509
+ /**
510
+ * alias for cdata section node type
511
+ */
141
512
  CDOCOMMNodeType = 1,
513
+ /**
514
+ * alias for timing function token type
515
+ */
142
516
  TimingFunction = 17,
517
+ /**
518
+ * alias for timeline function token type
519
+ */
143
520
  TimelineFunction = 16
144
521
  }
522
+ /**
523
+ * supported color types enum
524
+ */
145
525
  declare enum ColorType {
526
+ /**
527
+ * system colors
528
+ */
146
529
  SYS = 0,
530
+ /**
531
+ * deprecated system colors
532
+ */
147
533
  DPSYS = 1,
534
+ /**
535
+ * colors as literals
536
+ */
148
537
  LIT = 2,
538
+ /**
539
+ * colors as hex values
540
+ */
149
541
  HEX = 3,
542
+ /**
543
+ * colors as rgb values
544
+ */
150
545
  RGBA = 4,
546
+ /**
547
+ * colors as hsl values
548
+ */
151
549
  HSLA = 5,
550
+ /**
551
+ * colors as hwb values
552
+ */
152
553
  HWB = 6,
554
+ /**
555
+ * colors as cmyk values
556
+ */
153
557
  CMYK = 7,
558
+ /**
559
+ * colors as oklab values
560
+ * */
154
561
  OKLAB = 8,
562
+ /**
563
+ * colors as oklch values
564
+ * */
155
565
  OKLCH = 9,
566
+ /**
567
+ * colors as lab values
568
+ */
156
569
  LAB = 10,
570
+ /**
571
+ * colors as lch values
572
+ */
157
573
  LCH = 11,
574
+ /**
575
+ * colors using color() function
576
+ */
158
577
  COLOR = 12,
578
+ /**
579
+ * color using srgb values
580
+ */
159
581
  SRGB = 13,
582
+ /**
583
+ * color using prophoto-rgb values
584
+ */
160
585
  PROPHOTO_RGB = 14,
586
+ /**
587
+ * color using a98-rgb values
588
+ */
161
589
  A98_RGB = 15,
590
+ /**
591
+ * color using rec2020 values
592
+ */
162
593
  REC2020 = 16,
594
+ /**
595
+ * color using display-p3 values
596
+ */
163
597
  DISPLAY_P3 = 17,
598
+ /**
599
+ * color using srgb-linear values
600
+ */
164
601
  SRGB_LINEAR = 18,
602
+ /**
603
+ * color using xyz-d50 values
604
+ */
165
605
  XYZ_D50 = 19,
606
+ /**
607
+ * color using xyz-d65 values
608
+ */
166
609
  XYZ_D65 = 20,
610
+ /**
611
+ * light-dark() color function
612
+ */
167
613
  LIGHT_DARK = 21,
614
+ /**
615
+ * color-mix() color function
616
+ */
168
617
  COLOR_MIX = 22,
618
+ /**
619
+ * alias for rgba
620
+ */
169
621
  RGB = 4,
622
+ /**
623
+ * alias for hsl
624
+ */
170
625
  HSL = 5,
626
+ /**
627
+ * alias for xyz-d65
628
+ */
171
629
  XYZ = 20,
630
+ /**
631
+ * alias for cmyk
632
+ */
172
633
  DEVICE_CMYK = 7
173
634
  }
174
635
 
175
636
  /**
176
- * minify ast
637
+ * apply minification rules to the ast tree
177
638
  * @param ast
178
639
  * @param options
179
640
  * @param recursive
180
641
  * @param errors
181
642
  * @param nestingContent
182
- * @param context
643
+ *
644
+ * @private
183
645
  */
184
- declare function minify(ast: AstNode, options?: ParserOptions, recursive?: boolean, errors?: ErrorDescription[], nestingContent?: boolean, context?: {
185
- [key: string]: any;
186
- }): AstNode;
646
+ declare function minify(ast: AstNode, options: ParserOptions | MinifyFeatureOptions, recursive: boolean, errors?: ErrorDescription[], nestingContent?: boolean): AstNode;
187
647
 
188
648
  declare enum WalkerOptionEnum {
649
+ /**
650
+ * ignore the current node and its children
651
+ */
189
652
  Ignore = 0,
653
+ /**
654
+ * stop walking the tree
655
+ */
190
656
  Stop = 1,
657
+ /**
658
+ * ignore node and process children
659
+ */
191
660
  Children = 2,
661
+ /**
662
+ * ignore children
663
+ */
192
664
  IgnoreChildren = 3
193
665
  }
194
666
  declare enum WalkerValueEvent {
667
+ /**
668
+ * enter node
669
+ */
195
670
  Enter = 0,
671
+ /**
672
+ * leave node
673
+ */
196
674
  Leave = 1
197
675
  }
198
676
  /**
@@ -215,38 +693,104 @@ declare function walkValues(values: Token[], root?: AstNode | Token | null, filt
215
693
  }, reverse?: boolean): Generator<WalkAttributesResult>;
216
694
 
217
695
  /**
218
- * expand nested css ast
696
+ * expand css nesting ast nodes
219
697
  * @param ast
698
+ *
699
+ * @private
220
700
  */
221
701
  declare function expand(ast: AstNode): AstNode;
222
702
 
223
703
  /**
224
- * render ast token
704
+ *
225
705
  * @param token
226
706
  * @param options
227
- * @param cache
228
- * @param reducer
229
- * @param errors
707
+ *
708
+ * @private
230
709
  */
231
710
  declare function renderToken(token: Token, options?: RenderOptions, cache?: {
232
711
  [key: string]: any;
233
712
  }, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
234
713
 
235
- declare function okLabDistance(okLab1: [number, number, number], okLab2: [number, number, number]): number;
236
- declare function isOkLabClose(color1: ColorToken, color2: ColorToken, threshold?: number): boolean;
714
+ /**
715
+ * Source map class
716
+ * @internal
717
+ */
718
+ declare class SourceMap {
719
+ #private;
720
+ /**
721
+ * Last location
722
+ */
723
+ lastLocation: Location | null;
724
+ /**
725
+ * Add a location
726
+ * @param source
727
+ * @param original
728
+ */
729
+ add(source: Location, original: Location): void;
730
+ /**
731
+ * Convert to URL encoded string
732
+ */
733
+ toUrl(): string;
734
+ /**
735
+ * Convert to JSON object
736
+ */
737
+ toJSON(): SourceMapObject;
738
+ }
237
739
 
238
740
  /**
239
- * parse css string
741
+ * parse a string as an array of declaration nodes
742
+ * @param declaration
743
+ *
744
+ * Example:
745
+ * ````ts
746
+ *
747
+ * const declarations = await parseDeclarations('color: red; background: blue');
748
+ * console.log(declarations);
749
+ * ```
750
+ */
751
+ declare function parseDeclarations(declaration: string): Promise<AstDeclaration[]>;
752
+ /**
753
+ * parse css string and return an array of tokens
240
754
  * @param src
241
755
  * @param options
756
+ *
757
+ * @private
758
+ *
759
+ * Example:
760
+ *
761
+ * ```ts
762
+ *
763
+ * import {parseString} from '@tbela99/css-parser';
764
+ *
765
+ * let tokens = parseString('body { color: red; }');
766
+ * console.log(tokens);
767
+ *
768
+ * tokens = parseString('#c322c980');
769
+ * console.log(tokens);
770
+ * ```
242
771
  */
243
772
  declare function parseString(src: string, options?: {
244
773
  location: boolean;
245
774
  }): Token[];
246
775
  /**
247
- * parse token array into a tree structure
776
+ * parse function tokens in a token array
248
777
  * @param tokens
249
778
  * @param options
779
+ *
780
+ * Example:
781
+ *
782
+ * ```ts
783
+ *
784
+ * import {parseString, parseTokens} from '@tbela99/css-parser';
785
+ *
786
+ * let tokens = parseString('body { color: red; }');
787
+ * console.log(parseTokens(tokens));
788
+ *
789
+ * tokens = parseString('#c322c980');
790
+ * console.log(parseTokens(tokens));
791
+ * ```
792
+ *
793
+ * @private
250
794
  */
251
795
  declare function parseTokens(tokens: Token[], options?: ParseTokenOptions): Token[];
252
796
 
@@ -315,7 +859,7 @@ export declare interface NestingSelectorToken extends BaseToken {
315
859
  export declare interface NumberToken extends BaseToken {
316
860
 
317
861
  typ: EnumToken.NumberTokenType,
318
- val: string | FractionToken;
862
+ val: number | FractionToken;
319
863
  }
320
864
 
321
865
  export declare interface AtRuleToken extends BaseToken {
@@ -328,13 +872,13 @@ export declare interface AtRuleToken extends BaseToken {
328
872
  export declare interface PercentageToken extends BaseToken {
329
873
 
330
874
  typ: EnumToken.PercentageTokenType,
331
- val: string | FractionToken;
875
+ val: number | FractionToken;
332
876
  }
333
877
 
334
878
  export declare interface FlexToken extends BaseToken {
335
879
 
336
880
  typ: EnumToken.FlexTokenType,
337
- val: string | FractionToken;
881
+ val: number | FractionToken;
338
882
  }
339
883
 
340
884
  export declare interface FunctionToken extends BaseToken {
@@ -400,42 +944,42 @@ export declare interface UnclosedStringToken extends BaseToken {
400
944
  export declare interface DimensionToken extends BaseToken {
401
945
 
402
946
  typ: EnumToken.DimensionTokenType;
403
- val: string | FractionToken;
947
+ val: number | FractionToken;
404
948
  unit: string;
405
949
  }
406
950
 
407
951
  export declare interface LengthToken extends BaseToken {
408
952
 
409
953
  typ: EnumToken.LengthTokenType;
410
- val: string | FractionToken;
954
+ val: number | FractionToken;
411
955
  unit: string;
412
956
  }
413
957
 
414
958
  export declare interface AngleToken extends BaseToken {
415
959
 
416
960
  typ: EnumToken.AngleTokenType;
417
- val: string | FractionToken;
961
+ val: number | FractionToken;
418
962
  unit: string;
419
963
  }
420
964
 
421
965
  export declare interface TimeToken extends BaseToken {
422
966
 
423
967
  typ: EnumToken.TimeTokenType;
424
- val: string | FractionToken;
968
+ val: number | FractionToken;
425
969
  unit: 'ms' | 's';
426
970
  }
427
971
 
428
972
  export declare interface FrequencyToken extends BaseToken {
429
973
 
430
974
  typ: EnumToken.FrequencyTokenType;
431
- val: string | FractionToken;
975
+ val: number | FractionToken;
432
976
  unit: 'Hz' | 'Khz';
433
977
  }
434
978
 
435
979
  export declare interface ResolutionToken extends BaseToken {
436
980
 
437
981
  typ: EnumToken.ResolutionTokenType;
438
- val: string | FractionToken;
982
+ val: number | FractionToken;
439
983
  unit: 'dpi' | 'dpcm' | 'dppx' | 'x';
440
984
  }
441
985
 
@@ -921,6 +1465,13 @@ declare enum ValidationTokenEnum {
921
1465
  Character = 39,
922
1466
  InfinityToken = 40
923
1467
  }
1468
+ declare const enum ValidationSyntaxGroupEnum {
1469
+ Declarations = "declarations",
1470
+ Functions = "functions",
1471
+ Syntaxes = "syntaxes",
1472
+ Selectors = "selectors",
1473
+ AtRules = "atRules"
1474
+ }
924
1475
  interface Position$1 {
925
1476
  ind: number;
926
1477
  lin: number;
@@ -941,24 +1492,141 @@ interface ValidationToken {
941
1492
  };
942
1493
  }
943
1494
 
1495
+ export declare interface ValidationSyntaxNode {
1496
+
1497
+ syntax: string;
1498
+ ast?: ValidationToken[];
1499
+ }
1500
+
1501
+ interface ValidationSelectorOptions extends ValidationOptions {
1502
+
1503
+ nestedSelector?: boolean;
1504
+ }
1505
+
1506
+ export declare interface ValidationConfiguration {
1507
+
1508
+ [ValidationSyntaxGroupEnum.Declarations]: ValidationSyntaxNode;
1509
+ [ValidationSyntaxGroupEnum.Functions]: ValidationSyntaxNode;
1510
+ [ValidationSyntaxGroupEnum.Syntaxes]: ValidationSyntaxNode;
1511
+ [ValidationSyntaxGroupEnum.Selectors]: ValidationSyntaxNode;
1512
+ [ValidationSyntaxGroupEnum.AtRules]: ValidationSyntaxNode;
1513
+ }
1514
+
1515
+ //= Record<keyof ValidationSyntaxGroupEnum, ValidationSyntaxNode>;
1516
+
1517
+ interface ValidationResult {
1518
+
1519
+ valid: SyntaxValidationResult;
1520
+ node: AstNode | Token | null;
1521
+ syntax: ValidationToken | string | null;
1522
+ error: string;
1523
+ cycle?: boolean;
1524
+ }
1525
+
1526
+ interface ValidationSyntaxResult extends ValidationResult {
1527
+
1528
+ syntax: ValidationToken | string | null;
1529
+ context: Context<Token> | Token[];
1530
+ }
1531
+
1532
+ interface Context<Type> {
1533
+
1534
+ index: number;
1535
+
1536
+ /**
1537
+ * The length of the context tokens to be consumed
1538
+ */
1539
+
1540
+ readonly length: number;
1541
+
1542
+ current<Type>(): Type | null;
1543
+
1544
+ update<Type>(context: Context<Type>): void;
1545
+
1546
+ consume<Type>(token: Type, howMany?: number): boolean;
1547
+
1548
+ peek<Type>(): Type | null;
1549
+
1550
+ // tokens<Type>(): Type[];
1551
+
1552
+ next<Type>(): Type | null;
1553
+
1554
+ consume<Type>(token: Type, howMany?: number): boolean;
1555
+
1556
+ slice<Type>(): Type[];
1557
+
1558
+ clone<Type>(): Context<Type>;
1559
+
1560
+ done(): boolean;
1561
+ }
1562
+
944
1563
  /**
945
- * Converts a color token to another color space
1564
+ * Converts a color to another color space
946
1565
  * @param token
947
1566
  * @param to
1567
+ *
1568
+ * <code>
1569
+ *
1570
+ * const token = {typ: EnumToken.ColorTokenType, kin: ColorType.HEX, val: '#F00'}
1571
+ * const result = convertColor(token, ColorType.LCH);
1572
+ *
1573
+ * </code>
948
1574
  */
949
1575
  declare function convertColor(token: ColorToken, to: ColorType): ColorToken | null;
950
1576
 
1577
+ /**
1578
+ * Calculate the distance between two okLab colors.
1579
+ * @param okLab1
1580
+ * @param okLab2
1581
+ *
1582
+ * @private
1583
+ */
1584
+ declare function okLabDistance(okLab1: [number, number, number], okLab2: [number, number, number]): number;
1585
+ /**
1586
+ * Check if two colors are close in okLab space.
1587
+ * @param color1
1588
+ * @param color2
1589
+ * @param threshold
1590
+ *
1591
+ * @private
1592
+ */
1593
+ declare function isOkLabClose(color1: ColorToken, color2: ColorToken, threshold?: number): boolean;
1594
+
1595
+ /**
1596
+ * Position
1597
+ */
951
1598
  export declare interface Position {
952
1599
 
1600
+ /**
1601
+ * index in the source
1602
+ */
953
1603
  ind: number;
1604
+ /**
1605
+ * line number
1606
+ */
954
1607
  lin: number;
1608
+ /**
1609
+ * column number
1610
+ */
955
1611
  col: number;
956
1612
  }
957
1613
 
1614
+ /**
1615
+ * token or node location
1616
+ */
958
1617
  export declare interface Location {
959
1618
 
1619
+ /**
1620
+ * start position
1621
+ */
960
1622
  sta: Position;
1623
+ /**
1624
+ * end position
1625
+ */
961
1626
  end: Position;
1627
+ /**
1628
+ * source file
1629
+ */
962
1630
  src: string;
963
1631
  }
964
1632
 
@@ -1006,6 +1674,13 @@ export declare interface AstInvalidDeclaration extends BaseToken {
1006
1674
  val: Array<AstNode>;
1007
1675
  }
1008
1676
 
1677
+ export declare interface AstInvalidAtRule extends BaseToken {
1678
+
1679
+ typ: EnumToken.InvalidAtRuleTokenType;
1680
+ val: string;
1681
+ chi?: Array<AstNode>;
1682
+ }
1683
+
1009
1684
  export declare interface AstKeyFrameRule extends BaseToken {
1010
1685
 
1011
1686
  typ: EnumToken.KeyFrameRuleNodeType;
@@ -1025,6 +1700,13 @@ export declare interface OptimizedSelector {
1025
1700
  reducible: boolean;
1026
1701
  }
1027
1702
 
1703
+ export declare interface OptimizedSelectorToken {
1704
+ match: boolean;
1705
+ optimized: Token[];
1706
+ selector: Token[][],
1707
+ reducible: boolean;
1708
+ }
1709
+
1028
1710
  export declare interface AstAtRule extends BaseToken {
1029
1711
 
1030
1712
  typ: EnumToken.AtRuleNodeType,
@@ -1076,48 +1758,647 @@ export declare type AstNode =
1076
1758
  /**
1077
1759
  * Declaration visitor handler
1078
1760
  */
1079
- export declare type DeclarationVisitorHandler = (node: AstDeclaration) => AstDeclaration | AstDeclaration[] | null | Promise<AstDeclaration | AstDeclaration[] | null>;
1761
+ export declare type DeclarationVisitorHandler = (node: AstDeclaration) => (AstDeclaration | AstDeclaration[] | null | Promise<AstDeclaration> | Promise<AstDeclaration[]> | Promise<null>);
1080
1762
  /**
1081
1763
  * Rule visitor handler
1082
1764
  */
1083
- export declare type RuleVisitorHandler = (node: AstRule) => AstRule | AstRule[] | null | Promise<AstRule | AstRule[] | null>;
1765
+ export declare type RuleVisitorHandler = (node: AstRule) => (AstRule | AstRule[] | null | Promise<AstRule> | Promise<AstRule[]> | Promise<null>);
1084
1766
 
1085
1767
  /**
1086
1768
  * AtRule visitor handler
1087
1769
  */
1088
- export declare type AtRuleVisitorHandler = (node: AstAtRule) => AstAtRule | AstAtRule[] | null | Promise<AstAtRule | AstAtRule[] | null>;
1770
+ export declare type AtRuleVisitorHandler = (node: AstAtRule) => (AstAtRule | AstAtRule[] | null | Promise<AstAtRule> | Promise<AstAtRule[]> | Promise<null>);
1089
1771
 
1090
1772
  /**
1091
- * Value visitor handler
1773
+ * node visitor callback map
1774
+ *
1092
1775
  */
1093
- export declare type ValueVisitorHandler = (node: Token) => Token | Token[] | null | Promise<Token | Token[] | null>;
1094
-
1095
-
1096
1776
  export declare interface VisitorNodeMap {
1097
1777
 
1778
+ /**
1779
+ * at rule visitor
1780
+ *
1781
+ * Example: change media at-rule prelude
1782
+ *
1783
+ * ```ts
1784
+ *
1785
+ * import {transform, AstAtRule, ParserOptions} from "@tbela99/css-parser";
1786
+ *
1787
+ * const options: ParserOptions = {
1788
+ *
1789
+ * visitor: {
1790
+ *
1791
+ * AtRule: {
1792
+ *
1793
+ * media: (node: AstAtRule): AstAtRule => {
1794
+ *
1795
+ * node.val = 'tv,screen';
1796
+ * return node
1797
+ * }
1798
+ * }
1799
+ * }
1800
+ * };
1801
+ *
1802
+ * const css = `
1803
+ *
1804
+ * @media screen {
1805
+ *
1806
+ * .foo {
1807
+ *
1808
+ * height: calc(100px * 2/ 15);
1809
+ * }
1810
+ * }
1811
+ * `;
1812
+ *
1813
+ * const result = await transform(css, options);
1814
+ *
1815
+ * console.debug(result.code);
1816
+ *
1817
+ * // @media tv,screen{.foo{height:calc(40px/3)}}
1818
+ * ```
1819
+ */
1098
1820
  AtRule?: Record<string, AtRuleVisitorHandler> | AtRuleVisitorHandler;
1821
+ /**
1822
+ * declaration visitor
1823
+ *
1824
+ * Example: add 'width: 3px' everytime a declaration with the name 'height' is found
1825
+ *
1826
+ * ```ts
1827
+ *
1828
+ * import {transform, parseDeclarations} from "@tbela99/css-parser";
1829
+ *
1830
+ * const options: ParserOptions = {
1831
+ *
1832
+ * removeEmpty: false,
1833
+ * visitor: {
1834
+ *
1835
+ * Declaration: {
1836
+ *
1837
+ * // called only for height declaration
1838
+ * height: (node: AstDeclaration): AstDeclaration[] => {
1839
+ *
1840
+ *
1841
+ * return [
1842
+ * node,
1843
+ * {
1844
+ *
1845
+ * typ: EnumToken.DeclarationNodeType,
1846
+ * nam: 'width',
1847
+ * val: [
1848
+ * <LengthToken>{
1849
+ * typ: EnumToken.LengthTokenType,
1850
+ * val: 3,
1851
+ * unit: 'px'
1852
+ * }
1853
+ * ]
1854
+ * }
1855
+ * ];
1856
+ * }
1857
+ * }
1858
+ * }
1859
+ * };
1860
+ *
1861
+ * const css = `
1862
+ *
1863
+ * .foo {
1864
+ * height: calc(100px * 2/ 15);
1865
+ * }
1866
+ * .selector {
1867
+ * color: lch(from peru calc(l * 0.8) calc(c * 0.7) calc(h + 180))
1868
+ * }
1869
+ * `;
1870
+ *
1871
+ * console.debug(await transform(css, options));
1872
+ *
1873
+ * // .foo{height:calc(40px/3);width:3px}.selector{color:#0880b0}
1874
+ * ```
1875
+ *
1876
+ * Example: rename 'margin' to 'padding' and 'height' to 'width'
1877
+ *
1878
+ * ```ts
1879
+ * import {AstDeclaration, ParserOptions, transform} from "../src/node.ts";
1880
+ *
1881
+ * const options: ParserOptions = {
1882
+ *
1883
+ * visitor: {
1884
+ *
1885
+ * // called for every declaration
1886
+ * Declaration: (node: AstDeclaration): null => {
1887
+ *
1888
+ *
1889
+ * if (node.nam == 'height') {
1890
+ *
1891
+ * node.nam = 'width';
1892
+ * }
1893
+ *
1894
+ * else if (node.nam == 'margin') {
1895
+ *
1896
+ * node.nam = 'padding'
1897
+ * }
1898
+ *
1899
+ * return null;
1900
+ * }
1901
+ * }
1902
+ * };
1903
+ *
1904
+ * const css = `
1905
+ *
1906
+ * .foo {
1907
+ * height: calc(100px * 2/ 15);
1908
+ * margin: 10px;
1909
+ * }
1910
+ * .selector {
1911
+ *
1912
+ * margin: 20px;}
1913
+ * `;
1914
+ *
1915
+ * const result = await transform(css, options);
1916
+ *
1917
+ * console.debug(result.code);
1918
+ *
1919
+ * // .foo{width:calc(40px/3);padding:10px}.selector{padding:20px}
1920
+ * ```
1921
+ */
1099
1922
  Declaration?: Record<string, DeclarationVisitorHandler> | DeclarationVisitorHandler;
1923
+
1924
+ /**
1925
+ * rule visitor
1926
+ *
1927
+ * Example: add 'width: 3px' to every rule with the selector '.foo'
1928
+ *
1929
+ * ```ts
1930
+ *
1931
+ * import {transform, parseDeclarations} from "@tbela99/css-parser";
1932
+ *
1933
+ * const options: ParserOptions = {
1934
+ *
1935
+ * removeEmpty: false,
1936
+ * visitor: {
1937
+ *
1938
+ * Rule: async (node: AstRule): Promise<AstRule | null> => {
1939
+ *
1940
+ * if (node.sel == '.foo') {
1941
+ *
1942
+ * node.chi.push(...await parseDeclarations('width: 3px'));
1943
+ * return node;
1944
+ * }
1945
+ *
1946
+ * return null;
1947
+ * }
1948
+ * }
1949
+ * };
1950
+ *
1951
+ * const css = `
1952
+ *
1953
+ * .foo {
1954
+ * .foo {
1955
+ * }
1956
+ * }
1957
+ * `;
1958
+ *
1959
+ * console.debug(await transform(css, options));
1960
+ *
1961
+ * // .foo{width:3px;.foo{width:3px}}
1962
+ * ```
1963
+ */
1100
1964
  Rule?: RuleVisitorHandler;
1101
- Value?: Record<EnumToken, ValueVisitorHandler> | ValueVisitorHandler;
1102
1965
  }
1103
1966
 
1104
- declare class SourceMap {
1105
- #private;
1106
- lastLocation: Location | null;
1107
- add(source: Location, original: Location): void;
1108
- toUrl(): string;
1109
- toJSON(): SourceMapObject;
1967
+ export declare interface PropertyListOptions {
1968
+
1969
+ removeDuplicateDeclarations?: boolean;
1970
+ computeShorthand?: boolean;
1971
+ }
1972
+
1973
+ export declare interface ParseInfo {
1974
+
1975
+ buffer: string;
1976
+ stream: string;
1977
+ position: Position;
1978
+ currentPosition: Position;
1979
+ }
1980
+
1981
+ /**
1982
+ * feature walk mode
1983
+ */
1984
+ declare enum FeatureWalkMode {
1985
+ /**
1986
+ * pre process
1987
+ */
1988
+ Pre = 0,
1989
+ /**
1990
+ * post process
1991
+ */
1992
+ Post = 1
1993
+ }
1994
+
1995
+ /**
1996
+ * supported transform functions
1997
+ *
1998
+ * @internal
1999
+ */
2000
+ declare const transformFunctions: string[];
2001
+ /**
2002
+ * supported math functions
2003
+ *
2004
+ * @internal
2005
+ */
2006
+ declare const mathFuncs: string[];
2007
+
2008
+ interface PropertyType {
2009
+
2010
+ shorthand: string;
2011
+ }
2012
+
2013
+ interface ShorthandPropertyType {
2014
+
2015
+ shorthand: string;
2016
+ map?: string;
2017
+ properties: string[];
2018
+ types: string[];
2019
+ multiple: boolean;
2020
+ separator: {
2021
+ typ: keyof EnumToken;
2022
+ val: string
2023
+ };
2024
+ keywords: string[];
2025
+ }
2026
+
2027
+ interface PropertySetType {
2028
+
2029
+ [key: string]: PropertyType | ShorthandPropertyType;
2030
+ }
2031
+
2032
+ interface PropertyMapType {
2033
+
2034
+ default: string[];
2035
+ types: string[];
2036
+ keywords: string[];
2037
+ required?: boolean;
2038
+ multiple?: boolean;
2039
+ prefix?: {
2040
+ typ: keyof EnumToken;
2041
+ val: string
2042
+ };
2043
+ previous?: string;
2044
+ separator?: {
2045
+
2046
+ typ: keyof EnumToken;
2047
+ };
2048
+ constraints?: {
2049
+ [key: string]: {
2050
+ [key: string]: any;
2051
+ }
2052
+ };
2053
+ mapping?: Record<string, string>
2054
+ }
2055
+
2056
+ interface ShorthandMapType {
2057
+
2058
+ shorthand: string;
2059
+ pattern: string;
2060
+ keywords: string[];
2061
+ default: string[];
2062
+ mapping?: Record<string, string>;
2063
+ multiple?: boolean;
2064
+ separator?: { typ: keyof EnumToken; val?: string };
2065
+ set?: Record<string, string[]>
2066
+ properties: {
2067
+ [property: string]: PropertyMapType;
2068
+ }
2069
+ }
2070
+
2071
+ interface ShorthandProperties {
2072
+ types: EnumToken[];
2073
+ default: string[];
2074
+ keywords: string[];
2075
+ required?: boolean;
2076
+ multiple?: boolean;
2077
+ constraints?: Array<any>;
2078
+ mapping?: {
2079
+ [key: string]: any;
2080
+ };
2081
+ validation?: {
2082
+ [key: string]: any;
2083
+ };
2084
+ prefix?: string;
2085
+ }
2086
+
2087
+ interface ShorthandDef {
2088
+ shorthand: string;
2089
+ pattern: string;
2090
+ keywords: string;
2091
+ defaults: string[];
2092
+ multiple?: boolean;
2093
+ separator?: string;
2094
+ }
2095
+
2096
+ interface ShorthandType {
2097
+ shorthand: string;
2098
+ properties: ShorthandProperties;
2099
+ }
2100
+
2101
+ // generated from config.json at https://app.quicktype.io/?l=ts
2102
+
2103
+ export declare interface PropertiesConfig {
2104
+ properties: PropertiesConfigProperties;
2105
+ map: Map$1;
2106
+ }
2107
+
2108
+ interface Map$1 {
2109
+ border: Border;
2110
+ "border-color": BackgroundPositionClass;
2111
+ "border-style": BackgroundPositionClass;
2112
+ "border-width": BackgroundPositionClass;
2113
+ outline: Outline;
2114
+ "outline-color": BackgroundPositionClass;
2115
+ "outline-style": BackgroundPositionClass;
2116
+ "outline-width": BackgroundPositionClass;
2117
+ font: Font;
2118
+ "font-weight": BackgroundPositionClass;
2119
+ "font-style": BackgroundPositionClass;
2120
+ "font-size": BackgroundPositionClass;
2121
+ "line-height": BackgroundPositionClass;
2122
+ "font-stretch": BackgroundPositionClass;
2123
+ "font-variant": BackgroundPositionClass;
2124
+ "font-family": BackgroundPositionClass;
2125
+ background: Background;
2126
+ "background-repeat": BackgroundPositionClass;
2127
+ "background-color": BackgroundPositionClass;
2128
+ "background-image": BackgroundPositionClass;
2129
+ "background-attachment": BackgroundPositionClass;
2130
+ "background-clip": BackgroundPositionClass;
2131
+ "background-origin": BackgroundPositionClass;
2132
+ "background-position": BackgroundPositionClass;
2133
+ "background-size": BackgroundPositionClass;
2134
+ }
2135
+
2136
+ interface Background {
2137
+ shorthand: string;
2138
+ pattern: string;
2139
+ keywords: string[];
2140
+ default: any[];
2141
+ multiple: boolean;
2142
+ separator: Separator;
2143
+ properties: BackgroundProperties;
2144
+ }
2145
+
2146
+ interface BackgroundProperties {
2147
+ "background-repeat": BackgroundRepeat;
2148
+ "background-color": PurpleBackgroundAttachment;
2149
+ "background-image": PurpleBackgroundAttachment;
2150
+ "background-attachment": PurpleBackgroundAttachment;
2151
+ "background-clip": PurpleBackgroundAttachment;
2152
+ "background-origin": PurpleBackgroundAttachment;
2153
+ "background-position": BackgroundPosition;
2154
+ "background-size": BackgroundSize;
2155
+ }
2156
+
2157
+ interface PurpleBackgroundAttachment {
2158
+ types: string[];
2159
+ default: string[];
2160
+ keywords: string[];
2161
+ required?: boolean;
2162
+ mapping?: BackgroundAttachmentMapping;
2163
+ }
2164
+
2165
+ interface BackgroundAttachmentMapping {
2166
+ "ultra-condensed": string;
2167
+ "extra-condensed": string;
2168
+ condensed: string;
2169
+ "semi-condensed": string;
2170
+ normal: string;
2171
+ "semi-expanded": string;
2172
+ expanded: string;
2173
+ "extra-expanded": string;
2174
+ "ultra-expanded": string;
2175
+ }
2176
+
2177
+ interface BackgroundPosition {
2178
+ multiple: boolean;
2179
+ types: string[];
2180
+ default: string[];
2181
+ keywords: string[];
2182
+ mapping: BackgroundPositionMapping;
2183
+ constraints: BackgroundPositionConstraints;
2184
+ }
2185
+
2186
+ interface BackgroundPositionConstraints {
2187
+ mapping: ConstraintsMapping;
2188
+ }
2189
+
2190
+ interface ConstraintsMapping {
2191
+ max: number;
2192
+ }
2193
+
2194
+ interface BackgroundPositionMapping {
2195
+ left: string;
2196
+ top: string;
2197
+ center: string;
2198
+ bottom: string;
2199
+ right: string;
2200
+ }
2201
+
2202
+ interface BackgroundRepeat {
2203
+ types: any[];
2204
+ default: string[];
2205
+ multiple: boolean;
2206
+ keywords: string[];
2207
+ mapping: BackgroundRepeatMapping;
2208
+ }
2209
+
2210
+ interface BackgroundRepeatMapping {
2211
+ "repeat no-repeat": string;
2212
+ "no-repeat repeat": string;
2213
+ "repeat repeat": string;
2214
+ "space space": string;
2215
+ "round round": string;
2216
+ "no-repeat no-repeat": string;
2217
+ }
2218
+
2219
+ interface BackgroundSize {
2220
+ multiple: boolean;
2221
+ previous: string;
2222
+ prefix: Prefix;
2223
+ types: string[];
2224
+ default: string[];
2225
+ keywords: string[];
2226
+ mapping: BackgroundSizeMapping;
2227
+ }
2228
+
2229
+ interface BackgroundSizeMapping {
2230
+ "auto auto": string;
2231
+ }
2232
+
2233
+ interface Prefix {
2234
+ typ: string;
2235
+ val: string;
2236
+ }
2237
+
2238
+ interface Separator {
2239
+ typ: string;
2240
+ }
2241
+
2242
+ interface BackgroundPositionClass {
2243
+ shorthand: string;
2244
+ }
2245
+
2246
+ interface Border {
2247
+ shorthand: string;
2248
+ pattern: string;
2249
+ keywords: string[];
2250
+ default: string[];
2251
+ properties: BorderProperties;
1110
2252
  }
1111
2253
 
1112
- export declare interface PropertyListOptions {
2254
+ interface BorderProperties {
2255
+ "border-color": BorderColorClass;
2256
+ "border-style": BorderColorClass;
2257
+ "border-width": BorderColorClass;
2258
+ }
1113
2259
 
1114
- removeDuplicateDeclarations?: boolean;
1115
- computeShorthand?: boolean;
2260
+ interface BorderColorClass {
1116
2261
  }
1117
2262
 
1118
- declare enum FeatureWalkMode {
1119
- Pre = 0,
1120
- Post = 1
2263
+ interface Font {
2264
+ shorthand: string;
2265
+ pattern: string;
2266
+ keywords: string[];
2267
+ default: any[];
2268
+ properties: FontProperties;
2269
+ }
2270
+
2271
+ interface FontProperties {
2272
+ "font-weight": FontWeight;
2273
+ "font-style": PurpleBackgroundAttachment;
2274
+ "font-size": PurpleBackgroundAttachment;
2275
+ "line-height": LineHeight;
2276
+ "font-stretch": PurpleBackgroundAttachment;
2277
+ "font-variant": PurpleBackgroundAttachment;
2278
+ "font-family": FontFamily;
2279
+ }
2280
+
2281
+ interface FontFamily {
2282
+ types: string[];
2283
+ default: any[];
2284
+ keywords: string[];
2285
+ required: boolean;
2286
+ multiple: boolean;
2287
+ separator: Separator;
2288
+ }
2289
+
2290
+ interface FontWeight {
2291
+ types: string[];
2292
+ default: string[];
2293
+ keywords: string[];
2294
+ constraints: FontWeightConstraints;
2295
+ mapping: FontWeightMapping;
2296
+ }
2297
+
2298
+ interface FontWeightConstraints {
2299
+ value: Value;
2300
+ }
2301
+
2302
+ interface Value {
2303
+ min: string;
2304
+ max: string;
2305
+ }
2306
+
2307
+ interface FontWeightMapping {
2308
+ thin: string;
2309
+ hairline: string;
2310
+ "extra light": string;
2311
+ "ultra light": string;
2312
+ light: string;
2313
+ normal: string;
2314
+ regular: string;
2315
+ medium: string;
2316
+ "semi bold": string;
2317
+ "demi bold": string;
2318
+ bold: string;
2319
+ "extra bold": string;
2320
+ "ultra bold": string;
2321
+ black: string;
2322
+ heavy: string;
2323
+ "extra black": string;
2324
+ "ultra black": string;
2325
+ }
2326
+
2327
+ interface LineHeight {
2328
+ types: string[];
2329
+ default: string[];
2330
+ keywords: string[];
2331
+ previous: string;
2332
+ prefix: Prefix;
2333
+ }
2334
+
2335
+ interface Outline {
2336
+ shorthand: string;
2337
+ pattern: string;
2338
+ keywords: string[];
2339
+ default: string[];
2340
+ properties: OutlineProperties;
2341
+ }
2342
+
2343
+ interface OutlineProperties {
2344
+ "outline-color": PurpleBackgroundAttachment;
2345
+ "outline-style": PurpleBackgroundAttachment;
2346
+ "outline-width": PurpleBackgroundAttachment;
2347
+ }
2348
+
2349
+ interface PropertiesConfigProperties {
2350
+ inset: BorderRadius;
2351
+ top: BackgroundPositionClass;
2352
+ right: BackgroundPositionClass;
2353
+ bottom: BackgroundPositionClass;
2354
+ left: BackgroundPositionClass;
2355
+ margin: BorderRadius;
2356
+ "margin-top": BackgroundPositionClass;
2357
+ "margin-right": BackgroundPositionClass;
2358
+ "margin-bottom": BackgroundPositionClass;
2359
+ "margin-left": BackgroundPositionClass;
2360
+ padding: BorderColor;
2361
+ "padding-top": BackgroundPositionClass;
2362
+ "padding-right": BackgroundPositionClass;
2363
+ "padding-bottom": BackgroundPositionClass;
2364
+ "padding-left": BackgroundPositionClass;
2365
+ "border-radius": BorderRadius;
2366
+ "border-top-left-radius": BackgroundPositionClass;
2367
+ "border-top-right-radius": BackgroundPositionClass;
2368
+ "border-bottom-right-radius": BackgroundPositionClass;
2369
+ "border-bottom-left-radius": BackgroundPositionClass;
2370
+ "border-width": BorderColor;
2371
+ "border-top-width": BackgroundPositionClass;
2372
+ "border-right-width": BackgroundPositionClass;
2373
+ "border-bottom-width": BackgroundPositionClass;
2374
+ "border-left-width": BackgroundPositionClass;
2375
+ "border-style": BorderColor;
2376
+ "border-top-style": BackgroundPositionClass;
2377
+ "border-right-style": BackgroundPositionClass;
2378
+ "border-bottom-style": BackgroundPositionClass;
2379
+ "border-left-style": BackgroundPositionClass;
2380
+ "border-color": BorderColor;
2381
+ "border-top-color": BackgroundPositionClass;
2382
+ "border-right-color": BackgroundPositionClass;
2383
+ "border-bottom-color": BackgroundPositionClass;
2384
+ "border-left-color": BackgroundPositionClass;
2385
+ }
2386
+
2387
+ interface BorderColor {
2388
+ shorthand: string;
2389
+ map?: string;
2390
+ properties: string[];
2391
+ types: string[];
2392
+ keywords: string[];
2393
+ }
2394
+
2395
+ interface BorderRadius {
2396
+ shorthand: string;
2397
+ properties: string[];
2398
+ types: string[];
2399
+ multiple: boolean;
2400
+ separator: null | string;
2401
+ keywords: string[];
1121
2402
  }
1122
2403
 
1123
2404
  export declare type WalkerOption = WalkerOptionEnum | Token | null;
@@ -1154,172 +2435,601 @@ export declare interface WalkAttributesResult {
1154
2435
  list: Token[] | null;
1155
2436
  }
1156
2437
 
2438
+ /**
2439
+ * error description
2440
+ */
1157
2441
  export declare interface ErrorDescription {
1158
2442
 
1159
- // drop rule or declaration | fix rule or declaration
2443
+ /**
2444
+ * drop rule or declaration
2445
+ */
2446
+
1160
2447
  action: 'drop' | 'ignore';
2448
+ /**
2449
+ * error message
2450
+ */
1161
2451
  message: string;
1162
- syntax?: string;
2452
+ /**
2453
+ * syntax error description
2454
+ */
2455
+ syntax?: string | null;
2456
+ /**
2457
+ * error node
2458
+ */
2459
+ node?: Token | AstNode | null;
2460
+ /**
2461
+ * error location
2462
+ */
1163
2463
  location?: Location;
2464
+ /**
2465
+ * error object
2466
+ */
1164
2467
  error?: Error;
2468
+ /**
2469
+ * raw tokens
2470
+ */
1165
2471
  rawTokens?: TokenizeResult[];
1166
2472
  }
1167
2473
 
2474
+ /**
2475
+ * css validation options
2476
+ */
1168
2477
  interface ValidationOptions {
1169
2478
 
2479
+ /**
2480
+ * enable css validation
2481
+ *
2482
+ * see {@link ValidationLevel}
2483
+ */
1170
2484
  validation?: boolean | ValidationLevel;
2485
+ /**
2486
+ * lenient validation. retain nodes that failed validation
2487
+ */
1171
2488
  lenient?: boolean;
2489
+ /**
2490
+ * visited tokens
2491
+ *
2492
+ * @private
2493
+ */
1172
2494
  visited?: WeakMap<Token, Map<string, Set<ValidationToken>>>;
1173
- isOptional?:boolean | null;
1174
- isRepeatable?:boolean | null;
1175
- isList?:boolean | null;
1176
- occurence?:boolean | null;
2495
+ /**
2496
+ * is optional
2497
+ *
2498
+ * @private
2499
+ */
2500
+ isOptional?: boolean | null;
2501
+ /**
2502
+ * is repeatable
2503
+ *
2504
+ * @private
2505
+ */
2506
+ isRepeatable?: boolean | null;
2507
+ /**
2508
+ * is list
2509
+ *
2510
+ * @private
2511
+ */
2512
+ isList?: boolean | null;
2513
+ /**
2514
+ * occurence
2515
+ *
2516
+ * @private
2517
+ */
2518
+ occurence?: boolean | null;
2519
+ /**
2520
+ * at least once
2521
+ *
2522
+ * @private
2523
+ */
1177
2524
  atLeastOnce?: boolean | null;
1178
2525
  }
1179
2526
 
2527
+ /**
2528
+ * minify options
2529
+ */
1180
2530
  interface MinifyOptions {
1181
2531
 
2532
+ /**
2533
+ * enable minification
2534
+ */
1182
2535
  minify?: boolean;
2536
+ /**
2537
+ * parse color tokens
2538
+ */
1183
2539
  parseColor?: boolean;
2540
+ /**
2541
+ * generate nested rules
2542
+ */
1184
2543
  nestingRules?: boolean;
2544
+ /**
2545
+ * expand nested rules
2546
+ */
1185
2547
  expandNestingRules?: boolean;
2548
+ /**
2549
+ * remove duplicate declarations from the same rule
2550
+ */
1186
2551
  removeDuplicateDeclarations?: boolean;
2552
+ /**
2553
+ * compute shorthand properties
2554
+ */
1187
2555
  computeShorthand?: boolean;
2556
+ /**
2557
+ * compute transform functions
2558
+ * see supported functions {@link transformFunctions}
2559
+ */
1188
2560
  computeTransform?: boolean;
2561
+ /**
2562
+ * compute math functions
2563
+ * see supported functions {@link mathFuncs}
2564
+ */
1189
2565
  computeCalcExpression?: boolean;
2566
+ /**
2567
+ * inline css variables
2568
+ */
1190
2569
  inlineCssVariables?: boolean;
2570
+ /**
2571
+ * remove empty ast nodes
2572
+ */
1191
2573
  removeEmpty?: boolean;
2574
+ /**
2575
+ * define minification passes.
2576
+ */
1192
2577
  pass?: number;
1193
2578
  }
1194
2579
 
2580
+ /**
2581
+ * parser options
2582
+ */
1195
2583
  export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptions, ValidationOptions, PropertyListOptions {
1196
2584
 
2585
+ /**
2586
+ * source file to be used for sourcemap
2587
+ */
1197
2588
  src?: string;
2589
+ /**
2590
+ * include sourcemap in the ast. sourcemap info is always generated
2591
+ */
1198
2592
  sourcemap?: boolean | 'inline';
2593
+ /**
2594
+ * remove @charset at-rule
2595
+ */
1199
2596
  removeCharset?: boolean;
2597
+ /**
2598
+ * resolve urls
2599
+ */
1200
2600
  resolveUrls?: boolean;
2601
+ /**
2602
+ * resolve import
2603
+ */
1201
2604
  resolveImport?: boolean;
2605
+ /**
2606
+ * current working directory
2607
+ * @ignore
2608
+ */
1202
2609
  cwd?: string;
2610
+ /**
2611
+ * remove css prefix
2612
+ */
1203
2613
  removePrefix?: boolean;
1204
- load?: (url: string, currentUrl: string) => Promise<string>;
2614
+ /**
2615
+ * get file or url as stream
2616
+ * @param url
2617
+ * @param currentUrl
2618
+ *
2619
+ * @private
2620
+ */
2621
+ getStream?: (url: string, currentUrl: string) => Promise<ReadableStream<string>>;
2622
+ /**
2623
+ * get directory name
2624
+ * @param path
2625
+ *
2626
+ * @private
2627
+ */
1205
2628
  dirname?: (path: string) => string;
2629
+ /**
2630
+ * resolve path
2631
+ * @param url
2632
+ * @param currentUrl
2633
+ * @param currentWorkingDirectory
2634
+ *
2635
+ * @private
2636
+ */
1206
2637
  resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => {
1207
2638
  absolute: string;
1208
2639
  relative: string;
1209
2640
  };
2641
+ /**
2642
+ * node visitor
2643
+ * {@link VisitorNodeMap}
2644
+ */
1210
2645
  visitor?: VisitorNodeMap;
2646
+ /**
2647
+ * abort signal
2648
+ *
2649
+ * Example: abort after 10 seconds
2650
+ * ```ts
2651
+ *
2652
+ * const result = await parse(cssString, {
2653
+ * signal: AbortSignal.timeout(10000)
2654
+ * });
2655
+ *
2656
+ * ```
2657
+ */
1211
2658
  signal?: AbortSignal;
2659
+ /**
2660
+ * set parent node
2661
+ */
1212
2662
  setParent?: boolean;
2663
+ /**
2664
+ * cache
2665
+ *
2666
+ * @private
2667
+ */
1213
2668
  cache?: WeakMap<AstNode, string>;
1214
2669
  }
1215
2670
 
1216
- export declare interface MinifyFeatureOptions {
2671
+ /**
2672
+ * minify feature options
2673
+ *
2674
+ * @internal
2675
+ */
2676
+ export declare interface MinifyFeatureOptions {
1217
2677
 
2678
+ /**
2679
+ * minify features
2680
+ *
2681
+ * @internal
2682
+ */
1218
2683
  features?: MinifyFeature[];
1219
2684
  }
1220
2685
 
2686
+ /**
2687
+ * minify feature
2688
+ *
2689
+ * @internal
2690
+ */
1221
2691
  export declare interface MinifyFeature {
1222
2692
 
2693
+ /**
2694
+ * ordering
2695
+ */
1223
2696
  ordering: number;
1224
-
1225
- register(options: MinifyFeatureOptions | ParserOptions): void;
1226
-
1227
- // run(ast: AstRule | AstAtRule, options: ParserOptions = {}, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: { [key: string]: any }): void;
1228
-
1229
- // cleanup?(ast: AstRuleStyleSheet, options: ParserOptions = {}, context: { [key: string]: any }): void;
1230
- }
1231
-
1232
- export declare interface MinifyFeature {
1233
-
1234
- ordering: number;
2697
+ /**
2698
+ * use in pre process
2699
+ */
1235
2700
  preProcess: boolean;
2701
+ /**
2702
+ * use in post process
2703
+ */
1236
2704
  postProcess: boolean;
2705
+ /**
2706
+ * register feature
2707
+ * @param options
2708
+ */
1237
2709
  register: (options: MinifyFeatureOptions | ParserOptions) => void;
2710
+ /**
2711
+ * run feature
2712
+ * @param ast
2713
+ * @param options
2714
+ * @param parent
2715
+ * @param context
2716
+ * @param mode
2717
+ */
1238
2718
  run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: {
1239
2719
  [key: string]: any
1240
2720
  }, mode: FeatureWalkMode) => void;
1241
2721
  }
1242
2722
 
2723
+ /**
2724
+ * resolved path
2725
+ * @internal
2726
+ */
1243
2727
  export declare interface ResolvedPath {
2728
+ /**
2729
+ * absolute path
2730
+ */
1244
2731
  absolute: string;
2732
+ /**
2733
+ * relative path
2734
+ */
1245
2735
  relative: string;
1246
2736
  }
1247
2737
 
2738
+ /**
2739
+ * ast node render options
2740
+ */
1248
2741
  export declare interface RenderOptions {
1249
2742
 
2743
+ /**
2744
+ * minify ast node.
2745
+ */
1250
2746
  minify?: boolean;
2747
+ /**
2748
+ * pretty print css
2749
+ */
1251
2750
  beautify?: boolean;
2751
+ /**
2752
+ * remove empty rule lists from the ast
2753
+ */
1252
2754
  removeEmpty?: boolean;
2755
+ /**
2756
+ * expand nesting rules
2757
+ */
1253
2758
  expandNestingRules?: boolean;
2759
+ /**
2760
+ * preserve license comments. license comments are comments that start with /*!
2761
+ */
1254
2762
  preserveLicense?: boolean;
2763
+ /**
2764
+ * generate sourcemap object. 'inline' will embed it in the css
2765
+ */
1255
2766
  sourcemap?: boolean | 'inline';
2767
+ /**
2768
+ * indent string
2769
+ */
1256
2770
  indent?: string;
2771
+ /**
2772
+ * new line string
2773
+ */
1257
2774
  newLine?: string;
2775
+ /**
2776
+ * remove comments
2777
+ */
1258
2778
  removeComments?: boolean;
2779
+ /**
2780
+ * convert color to the specified color space. 'true' will convert to HEX
2781
+ */
1259
2782
  convertColor?: boolean | ColorType;
2783
+ /**
2784
+ * ernder the node along with its parents
2785
+ */
1260
2786
  withParents?: boolean;
2787
+ /**
2788
+ * output file. used for url resolution
2789
+ * @internal
2790
+ */
1261
2791
  output?: string;
2792
+ /**
2793
+ * current working directory
2794
+ * @internal
2795
+ */
1262
2796
  cwd?: string;
1263
- load?: (url: string, currentUrl: string) => Promise<string>;
2797
+ /**
2798
+ * resolve path
2799
+ * @internal
2800
+ */
1264
2801
  resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => ResolvedPath;
1265
2802
  }
1266
2803
 
2804
+ /**
2805
+ * transform options
2806
+ */
1267
2807
  export declare interface TransformOptions extends ParserOptions, RenderOptions {
1268
2808
 
1269
2809
  }
1270
2810
 
2811
+ /**
2812
+ * parse result stats object
2813
+ */
1271
2814
  export declare interface ParseResultStats {
2815
+ /**
2816
+ * source file
2817
+ */
1272
2818
  src: string;
2819
+ /**
2820
+ * bytes read
2821
+ */
1273
2822
  bytesIn: number;
2823
+ /**
2824
+ * bytes read from imported files
2825
+ */
1274
2826
  importedBytesIn: number;
2827
+ /**
2828
+ * parse time
2829
+ */
1275
2830
  parse: string;
2831
+ /**
2832
+ * minify time
2833
+ */
1276
2834
  minify: string;
2835
+ /**
2836
+ * total time
2837
+ */
1277
2838
  total: string;
2839
+ /**
2840
+ * imported files stats
2841
+ */
1278
2842
  imports: ParseResultStats[]
1279
2843
  }
1280
2844
 
2845
+ /**
2846
+ * parse result object
2847
+ */
1281
2848
  export declare interface ParseResult {
2849
+ /**
2850
+ * parsed ast tree
2851
+ */
1282
2852
  ast: AstRuleStyleSheet;
2853
+ /**
2854
+ * parse errors
2855
+ */
1283
2856
  errors: ErrorDescription[];
2857
+ /**
2858
+ * parse stats
2859
+ */
1284
2860
  stats: ParseResultStats
1285
2861
  }
1286
2862
 
2863
+ /**
2864
+ * render result object
2865
+ */
1287
2866
  export declare interface RenderResult {
2867
+ /**
2868
+ * rendered css
2869
+ */
1288
2870
  code: string;
2871
+ /**
2872
+ * render errors
2873
+ */
1289
2874
  errors: ErrorDescription[];
2875
+ /**
2876
+ * render stats
2877
+ */
1290
2878
  stats: {
2879
+ /**
2880
+ * render time
2881
+ */
1291
2882
  total: string;
1292
2883
  },
2884
+ /**
2885
+ * source map
2886
+ */
1293
2887
  map?: SourceMap
1294
2888
  }
1295
2889
 
2890
+ /**
2891
+ * transform result object
2892
+ */
1296
2893
  export declare interface TransformResult extends ParseResult, RenderResult {
1297
2894
 
2895
+ /**
2896
+ * transform stats
2897
+ */
1298
2898
  stats: {
2899
+ /**
2900
+ * source file
2901
+ */
1299
2902
  src: string;
2903
+ /**
2904
+ * bytes read
2905
+ */
1300
2906
  bytesIn: number;
2907
+ /**
2908
+ * generated css size
2909
+ */
1301
2910
  bytesOut: number;
2911
+ /**
2912
+ * bytes read from imported files
2913
+ */
1302
2914
  importedBytesIn: number;
2915
+ /**
2916
+ * parse time
2917
+ */
1303
2918
  parse: string;
2919
+ /**
2920
+ * minify time
2921
+ */
1304
2922
  minify: string;
2923
+ /**
2924
+ * render time
2925
+ */
1305
2926
  render: string;
2927
+ /**
2928
+ * total time
2929
+ */
1306
2930
  total: string;
2931
+ /**
2932
+ * imported files stats
2933
+ */
1307
2934
  imports: ParseResultStats[];
1308
2935
  }
1309
2936
  }
1310
2937
 
2938
+ /**
2939
+ * parse token options
2940
+ */
1311
2941
  export declare interface ParseTokenOptions extends ParserOptions {
1312
2942
  }
1313
2943
 
2944
+ /**
2945
+ * tokenize result object
2946
+ * @internal
2947
+ */
1314
2948
  export declare interface TokenizeResult {
2949
+ /**
2950
+ * token
2951
+ */
1315
2952
  token: string;
2953
+ /**
2954
+ * token length
2955
+ */
1316
2956
  len: number;
2957
+ /**
2958
+ * token type hint
2959
+ */
1317
2960
  hint?: EnumToken;
2961
+ /**
2962
+ * token start position
2963
+ */
1318
2964
  sta: Position;
2965
+ /**
2966
+ * token end position
2967
+ */
1319
2968
  end: Position;
2969
+ /**
2970
+ * bytes in
2971
+ */
1320
2972
  bytesIn: number;
1321
2973
  }
1322
2974
 
2975
+ /**
2976
+ * matched selector object
2977
+ * @internal
2978
+ */
2979
+ export declare interface MatchedSelector {
2980
+ /**
2981
+ * matched selector
2982
+ */
2983
+ match: string[][];
2984
+ /**
2985
+ * selector 1
2986
+ */
2987
+ selector1: string[][];
2988
+ /**
2989
+ * selector 2
2990
+ */
2991
+ selector2: string[][];
2992
+ /**
2993
+ * selectors partially match
2994
+ */
2995
+ eq: boolean
2996
+ }
2997
+
2998
+ /**
2999
+ * variable scope info object
3000
+ * @internal
3001
+ */
3002
+ export declare interface VariableScopeInfo {
3003
+ /**
3004
+ * global scope
3005
+ */
3006
+ globalScope: boolean;
3007
+ /**
3008
+ * parent nodes
3009
+ */
3010
+ parent: Set<AstRule | AstAtRule>;
3011
+ /**
3012
+ * declaration count
3013
+ */
3014
+ declarationCount: number;
3015
+ /**
3016
+ * replaceable
3017
+ */
3018
+ replaceable: boolean;
3019
+ /**
3020
+ * declaration node
3021
+ */
3022
+ node: AstDeclaration;
3023
+ /**
3024
+ * declaration values
3025
+ */
3026
+ values: Token[];
3027
+ }
3028
+
3029
+ /**
3030
+ * source map object
3031
+ * @internal
3032
+ */
1323
3033
  export declare interface SourceMapObject {
1324
3034
  version: number;
1325
3035
  file?: string;
@@ -1333,13 +3043,16 @@ export declare interface SourceMapObject {
1333
3043
  /**
1334
3044
  * return the directory name of a path
1335
3045
  * @param path
3046
+ * @internal
1336
3047
  */
1337
3048
  declare function dirname(path: string): string;
1338
3049
  /**
1339
3050
  * resolve path
1340
- * @param url
1341
- * @param currentDirectory
1342
- * @param cwd
3051
+ * @param url url or path to resolve
3052
+ * @param currentDirectory directory used to resolve the path
3053
+ * @param cwd current working directory
3054
+ *
3055
+ * @private
1343
3056
  */
1344
3057
  declare function resolve(url: string, currentDirectory: string, cwd?: string): {
1345
3058
  absolute: string;
@@ -1347,23 +3060,169 @@ declare function resolve(url: string, currentDirectory: string, cwd?: string): {
1347
3060
  };
1348
3061
 
1349
3062
  /**
1350
- * load file
3063
+ * node module entry point
3064
+ * @module node
3065
+ */
3066
+
3067
+ /**
3068
+ * load file or url as stream
1351
3069
  * @param url
1352
3070
  * @param currentFile
3071
+ *
3072
+ * @private
1353
3073
  */
1354
- declare function load(url: string, currentFile?: string): Promise<string>;
1355
-
3074
+ declare function getStream(url: string, currentFile?: string): Promise<ReadableStream<string>>;
1356
3075
  /**
1357
- * render ast node
3076
+ * render ast tree
3077
+ * @param data
3078
+ * @param options
3079
+ *
3080
+ * Example:
3081
+ *
3082
+ * ```ts
3083
+ *
3084
+ * import {render, ColorType} from '@tbela99/css-parser';
3085
+ *
3086
+ * // remote file
3087
+ * let result = render(ast);
3088
+ * console.log(result.code);
3089
+ *
3090
+ * // local file
3091
+ * result = await parseFile(ast, {beatify: true, convertColor: ColorType.SRGB});
3092
+ * console.log(result.code);
3093
+ * ```
1358
3094
  */
1359
3095
  declare function render(data: AstNode, options?: RenderOptions): RenderResult;
3096
+ /**
3097
+ * parse css file
3098
+ * @param file url or path
3099
+ * @param options
3100
+ *
3101
+ * Example:
3102
+ *
3103
+ * ```ts
3104
+ *
3105
+ * import {parseFile} from '@tbela99/css-parser';
3106
+ *
3107
+ * // remote file
3108
+ * let result = await parseFile('https://docs.deno.com/styles.css');
3109
+ * console.log(result.ast);
3110
+ *
3111
+ * // local file
3112
+ * result = await parseFile('./css/styles.css');
3113
+ * console.log(result.ast);
3114
+ * ```
3115
+ */
3116
+ declare function parseFile(file: string, options?: ParserOptions): Promise<ParseResult>;
1360
3117
  /**
1361
3118
  * parse css
3119
+ * @param stream
3120
+ * @param opt
3121
+ *
3122
+ * Example:
3123
+ *
3124
+ * ```ts
3125
+ *
3126
+ * import {transform} from '@tbela99/css-parser';
3127
+ *
3128
+ * // css string
3129
+ * let result = await transform(css);
3130
+ * console.log(result.code);
3131
+ * ```
3132
+ *
3133
+ * Example using stream
3134
+ *
3135
+ * ```ts
3136
+ *
3137
+ * import {parse} from '@tbela99/css-parser';
3138
+ * import {Readable} from "node:stream";
3139
+ *
3140
+ * // usage: node index.ts < styles.css or cat styles.css | node index.ts
3141
+ *
3142
+ * const readableStream = Readable.toWeb(process.stdin);
3143
+ * const result = await parse(readableStream, {beautify: true});
3144
+ *
3145
+ * console.log(result.ast);
3146
+ * ```
3147
+ *
3148
+ * Example using fetch
3149
+ *
3150
+ * ```ts
3151
+ *
3152
+ * import {parse} from '@tbela99/css-parser';
3153
+ *
3154
+ * const response = await fetch('https://docs.deno.com/styles.css');
3155
+ * result = await parse(response.body, {beautify: true});
3156
+ *
3157
+ * console.log(result.ast);
3158
+ * ```
1362
3159
  */
1363
- declare function parse(iterator: string, opt?: ParserOptions): Promise<ParseResult>;
3160
+ declare function parse(stream: string | ReadableStream<string>, opt?: ParserOptions): Promise<ParseResult>;
1364
3161
  /**
1365
- * parse and render css
3162
+ * transform css file
3163
+ * @param file url or path
3164
+ * @param options
3165
+ *
3166
+ * Example:
3167
+ *
3168
+ * ```ts
3169
+ *
3170
+ * import {transformFile} from '@tbela99/css-parser';
3171
+ *
3172
+ * // remote file
3173
+ * let result = await transformFile('https://docs.deno.com/styles.css');
3174
+ * console.log(result.code);
3175
+ *
3176
+ * // local file
3177
+ * result = await transformFile('./css/styles.css');
3178
+ * console.log(result.code);
3179
+ * ```
3180
+ */
3181
+ declare function transformFile(file: string, options?: TransformOptions): Promise<TransformResult>;
3182
+ /**
3183
+ * transform css
3184
+ * @param css
3185
+ * @param options
3186
+ *
3187
+ * Example:
3188
+ *
3189
+ * ```ts
3190
+ *
3191
+ * import {transform} from '@tbela99/css-parser';
3192
+ *
3193
+ * // css string
3194
+ * let result = await transform(css);
3195
+ * console.log(result.code);
3196
+ * ```
3197
+ *
3198
+ * Example using stream
3199
+ *
3200
+ * ```ts
3201
+ *
3202
+ * import {transform} from '@tbela99/css-parser';
3203
+ * import {Readable} from "node:stream";
3204
+ *
3205
+ * // usage: node index.ts < styles.css or cat styles.css | node index.ts
3206
+ *
3207
+ * const readableStream = Readable.toWeb(process.stdin);
3208
+ * const result = await transform(readableStream, {beautify: true});
3209
+ *
3210
+ * console.log(result.code);
3211
+ * ```
3212
+ *
3213
+ * Example using fetch
3214
+ *
3215
+ * ```ts
3216
+ *
3217
+ * import {transform} from '@tbela99/css-parser';
3218
+ *
3219
+ * const response = await fetch('https://docs.deno.com/styles.css');
3220
+ * result = await transform(response.body, {beautify: true});
3221
+ *
3222
+ * console.log(result.code);
3223
+ * ```
1366
3224
  */
1367
- declare function transform(css: string, options?: TransformOptions): Promise<TransformResult>;
3225
+ declare function transform(css: string | ReadableStream<string>, options?: TransformOptions): Promise<TransformResult>;
1368
3226
 
1369
- export { ColorType, EnumToken, ValidationLevel, convertColor, dirname, expand, isOkLabClose, load, minify, okLabDistance, parse, parseString, parseTokens, render, renderToken, resolve, transform, walk, walkValues };
3227
+ export { ColorType, EnumToken, FeatureWalkMode, SourceMap, ValidationLevel, WalkerOptionEnum, WalkerValueEvent, convertColor, dirname, expand, getStream, isOkLabClose, mathFuncs, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseTokens, render, renderToken, resolve, transform, transformFile, transformFunctions, walk, walkValues };
3228
+ export type { AddToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstKeyframAtRule, AstKeyframeRule, AstNode, AstRule, AstRuleList, AstRuleStyleSheet, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ConstraintsMapping, ContainMatchToken, Context, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionImageToken, FunctionToken, FunctionURLToken, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, Location, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureAndToken, MediaFeatureNotToken, MediaFeatureOnlyToken, MediaFeatureOrToken, MediaFeatureToken, MediaQueryConditionToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo, ParseResult, ParseResultStats, ParseTokenOptions, ParserOptions, PercentageToken, Position, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token, TokenizeResult, TransformOptions, TransformResult, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, Value, VariableScopeInfo, VisitorNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerValueFilter, WhitespaceToken };