@tbela99/css-parser 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +1 -0
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +1 -0
- package/.repl_history +4 -0
- package/CHANGELOG.md +164 -4
- package/README.md +43 -0
- package/badges/coverage.svg +20 -0
- package/deno.lock +2861 -0
- package/dist/config.json.js +33 -1
- package/dist/index-umd-web.js +24382 -18476
- package/dist/index.cjs +24522 -18618
- package/dist/index.d.ts +1396 -929
- package/dist/lib/ast/clone.d.ts +10 -0
- package/dist/lib/ast/clone.js +45 -0
- package/dist/lib/ast/expand.d.ts +14 -0
- package/dist/lib/ast/expand.js +89 -64
- package/dist/lib/ast/features/calc.d.ts +10 -0
- package/dist/lib/ast/features/calc.js +62 -24
- package/dist/lib/ast/features/if.d.ts +10 -0
- package/dist/lib/ast/features/if.js +215 -0
- package/dist/lib/ast/features/index.d.ts +6 -0
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.d.ts +15 -0
- package/dist/lib/ast/features/inlinecssvariables.js +32 -27
- package/dist/lib/ast/features/prefix.d.ts +8 -0
- package/dist/lib/ast/features/prefix.js +68 -43
- package/dist/lib/ast/features/shorthand.d.ts +12 -0
- package/dist/lib/ast/features/shorthand.js +6 -9
- package/dist/lib/ast/features/transform.d.ts +10 -0
- package/dist/lib/ast/features/transform.js +9 -13
- package/dist/lib/ast/features/type.d.ts +15 -0
- package/dist/lib/ast/find.d.ts +165 -0
- package/dist/lib/ast/find.js +175 -0
- package/dist/lib/ast/math/expression.d.ts +18 -0
- package/dist/lib/ast/math/expression.js +140 -98
- package/dist/lib/ast/math/math.d.ts +6 -0
- package/dist/lib/ast/math/math.js +30 -41
- package/dist/lib/ast/minify.d.ts +19 -0
- package/dist/lib/ast/minify.js +541 -217
- package/dist/lib/ast/transform/compute.d.ts +8 -0
- package/dist/lib/ast/transform/compute.js +82 -69
- package/dist/lib/ast/transform/matrix.d.ts +22 -0
- package/dist/lib/ast/transform/matrix.js +12 -26
- package/dist/lib/ast/transform/minify.d.ts +5 -0
- package/dist/lib/ast/transform/minify.js +20 -20
- package/dist/lib/ast/transform/perspective.d.ts +3 -0
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.d.ts +12 -0
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.d.ts +6 -0
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.d.ts +4 -0
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.d.ts +6 -0
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.d.ts +9 -0
- package/dist/lib/ast/types.d.ts +903 -0
- package/dist/lib/ast/types.js +277 -23
- package/dist/lib/ast/walk.d.ts +162 -0
- package/dist/lib/ast/walk.js +116 -60
- package/dist/lib/fs/resolve.d.ts +20 -0
- package/dist/lib/fs/resolve.js +37 -45
- package/dist/lib/parser/declaration/list.d.ts +16 -0
- package/dist/lib/parser/declaration/list.js +26 -24
- package/dist/lib/parser/declaration/map.d.ts +15 -0
- package/dist/lib/parser/declaration/map.js +140 -95
- package/dist/lib/parser/declaration/set.d.ts +9 -0
- package/dist/lib/parser/declaration/set.js +30 -25
- package/dist/lib/parser/node.d.ts +7 -0
- package/dist/lib/parser/parse.d.ts +107 -0
- package/dist/lib/parser/parse.js +1454 -1445
- package/dist/lib/parser/tokenize.d.ts +57 -0
- package/dist/lib/parser/tokenize.js +557 -404
- package/dist/lib/parser/utils/at-rule-container.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-container.js +486 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
- package/dist/lib/parser/utils/at-rule-generic.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-generic.js +118 -0
- package/dist/lib/parser/utils/at-rule-import.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-import.js +393 -0
- package/dist/lib/parser/utils/at-rule-media.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-media.js +603 -0
- package/dist/lib/parser/utils/at-rule-page.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-page.js +28 -0
- package/dist/lib/parser/utils/at-rule-support.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-support.js +366 -0
- package/dist/lib/parser/utils/at-rule-token.d.ts +1 -0
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +5 -0
- package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
- package/dist/lib/parser/utils/at-rule.d.ts +13 -0
- package/dist/lib/parser/utils/at-rule.js +37 -0
- package/dist/lib/parser/utils/cache.d.ts +6 -0
- package/dist/lib/parser/utils/cache.js +19 -0
- package/dist/lib/parser/utils/config.d.ts +2 -0
- package/dist/lib/parser/utils/config.js +1 -0
- package/dist/lib/parser/utils/declaration-list.d.ts +5 -0
- package/dist/lib/parser/utils/declaration.d.ts +18 -0
- package/dist/lib/parser/utils/declaration.js +569 -91
- package/dist/lib/parser/utils/eq.d.ts +1 -0
- package/dist/lib/parser/utils/hash.d.ts +21 -0
- package/dist/lib/parser/utils/hash.js +1 -1
- package/dist/lib/parser/utils/selector.d.ts +5 -0
- package/dist/lib/parser/utils/selector.js +476 -0
- package/dist/lib/parser/utils/text.d.ts +3 -0
- package/dist/lib/parser/utils/text.js +17 -1
- package/dist/lib/parser/utils/token.d.ts +14 -0
- package/dist/lib/parser/utils/token.js +102 -0
- package/dist/lib/parser/utils/type.d.ts +2 -0
- package/dist/lib/parser/utils/type.js +29 -18
- package/dist/lib/renderer/render.d.ts +28 -0
- package/dist/lib/renderer/render.js +421 -262
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +1 -0
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +26 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
- package/dist/lib/syntax/color/a98rgb.d.ts +2 -0
- package/dist/lib/syntax/color/a98rgb.js +8 -12
- package/dist/lib/syntax/color/cmyk.d.ts +10 -0
- package/dist/lib/syntax/color/cmyk.js +23 -21
- package/dist/lib/syntax/color/color-mix.d.ts +2 -0
- package/dist/lib/syntax/color/color-mix.js +88 -77
- package/dist/lib/syntax/color/color.d.ts +42 -0
- package/dist/lib/syntax/color/color.js +65 -68
- package/dist/lib/syntax/color/hex.d.ts +16 -0
- package/dist/lib/syntax/color/hex.js +27 -31
- package/dist/lib/syntax/color/hsl.d.ts +20 -0
- package/dist/lib/syntax/color/hsl.js +5 -12
- package/dist/lib/syntax/color/hsv.d.ts +2 -0
- package/dist/lib/syntax/color/hwb.d.ts +21 -0
- package/dist/lib/syntax/color/hwb.js +8 -21
- package/dist/lib/syntax/color/lab.d.ts +25 -0
- package/dist/lib/syntax/color/lab.js +20 -21
- package/dist/lib/syntax/color/lch.d.ts +23 -0
- package/dist/lib/syntax/color/lch.js +13 -15
- package/dist/lib/syntax/color/oklab.d.ts +22 -0
- package/dist/lib/syntax/color/oklab.js +20 -39
- package/dist/lib/syntax/color/oklch.d.ts +20 -0
- package/dist/lib/syntax/color/oklch.js +14 -16
- package/dist/lib/syntax/color/p3.d.ts +6 -0
- package/dist/lib/syntax/color/p3.js +0 -8
- package/dist/lib/syntax/color/prophotorgb.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.d.ts +2 -0
- package/dist/lib/syntax/color/rec2020.js +9 -13
- package/dist/lib/syntax/color/relativecolor.d.ts +13 -0
- package/dist/lib/syntax/color/relativecolor.js +68 -41
- package/dist/lib/syntax/color/rgb.d.ts +20 -0
- package/dist/lib/syntax/color/rgb.js +14 -18
- package/dist/lib/syntax/color/srgb.d.ts +23 -0
- package/dist/lib/syntax/color/srgb.js +27 -26
- package/dist/lib/syntax/color/utils/components.d.ts +2 -0
- package/dist/lib/syntax/color/utils/components.js +30 -14
- package/dist/lib/syntax/color/utils/distance.d.ts +18 -0
- package/dist/lib/syntax/color/utils/distance.js +1 -8
- package/dist/lib/syntax/color/utils/matrix.d.ts +6 -0
- package/dist/lib/syntax/color/xyz.d.ts +5 -0
- package/dist/lib/syntax/color/xyz.js +8 -20
- package/dist/lib/syntax/color/xyzd50.d.ts +4 -0
- package/dist/lib/syntax/color/xyzd50.js +6 -20
- package/dist/lib/syntax/constants.d.ts +67 -0
- package/dist/lib/syntax/constants.js +436 -0
- package/dist/lib/syntax/syntax.d.ts +38 -0
- package/dist/lib/syntax/syntax.js +533 -568
- package/dist/lib/validation/config.d.ts +14 -0
- package/dist/lib/validation/config.js +72 -33
- package/dist/lib/validation/config.json.js +1159 -74
- package/dist/lib/validation/json.d.ts +2 -0
- package/dist/lib/validation/match.d.ts +38 -0
- package/dist/lib/validation/match.js +2985 -0
- package/dist/lib/validation/parser/parse.d.ts +8 -0
- package/dist/lib/validation/parser/parse.js +684 -935
- package/dist/lib/validation/parser/typedef.d.ts +95 -0
- package/dist/lib/validation/parser/typedef.js +100 -0
- package/dist/lib/validation/utils/list.d.ts +4 -0
- package/dist/lib/validation/utils/list.js +4 -11
- package/dist/lib/validation/utils/whitespace.d.ts +2 -0
- package/dist/lib/validation/utils/whitespace.js +2 -8
- package/dist/node.d.ts +207 -0
- package/dist/node.js +42 -39
- package/dist/web.d.ts +169 -0
- package/dist/web.js +38 -33
- package/package.json +15 -12
- package/playground/index.html +1328 -0
- package/playground/sw.js +55 -0
- package/playground/tree.js +176 -0
- package/dist/lib/syntax/color/utils/constants.js +0 -214
- package/dist/lib/syntax/utils.js +0 -70
- package/dist/lib/validation/at-rules/container.js +0 -342
- package/dist/lib/validation/at-rules/counter-style.js +0 -90
- package/dist/lib/validation/at-rules/custom-media.js +0 -50
- package/dist/lib/validation/at-rules/document.js +0 -89
- package/dist/lib/validation/at-rules/else.js +0 -5
- package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
- package/dist/lib/validation/at-rules/import.js +0 -150
- package/dist/lib/validation/at-rules/keyframes.js +0 -67
- package/dist/lib/validation/at-rules/layer.js +0 -41
- package/dist/lib/validation/at-rules/media.js +0 -255
- package/dist/lib/validation/at-rules/namespace.js +0 -81
- package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
- package/dist/lib/validation/at-rules/page.js +0 -100
- package/dist/lib/validation/at-rules/supports.js +0 -295
- package/dist/lib/validation/at-rules/when.js +0 -185
- package/dist/lib/validation/atrule.js +0 -184
- package/dist/lib/validation/selector.js +0 -36
- package/dist/lib/validation/syntax.js +0 -1073
- package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
- package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
- package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
- package/dist/lib/validation/syntaxes/family-name.js +0 -57
- package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
- package/dist/lib/validation/syntaxes/layer-name.js +0 -57
- package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
- package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
- package/dist/lib/validation/syntaxes/selector-list.js +0 -5
- package/dist/lib/validation/syntaxes/selector.js +0 -5
- package/dist/lib/validation/syntaxes/url.js +0 -40
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
export declare enum ValidationTokenEnum {
|
|
2
|
+
Root = 0,
|
|
3
|
+
Keyword = 1,
|
|
4
|
+
PropertyType = 2,
|
|
5
|
+
DeclarationType = 3,
|
|
6
|
+
AtRule = 4,
|
|
7
|
+
FunctionDefinition = 5,
|
|
8
|
+
OpenBracket = 6,
|
|
9
|
+
CloseBracket = 7,
|
|
10
|
+
OpenParenthesis = 8,
|
|
11
|
+
CloseParenthesis = 9,
|
|
12
|
+
Comma = 10,
|
|
13
|
+
Pipe = 11,
|
|
14
|
+
Column = 12,
|
|
15
|
+
Star = 13,
|
|
16
|
+
OpenCurlyBrace = 14,
|
|
17
|
+
CloseCurlyBrace = 15,
|
|
18
|
+
HashMark = 16,
|
|
19
|
+
QuestionMark = 17,
|
|
20
|
+
Function = 18,
|
|
21
|
+
Number = 19,
|
|
22
|
+
Whitespace = 20,
|
|
23
|
+
Parenthesis = 21,
|
|
24
|
+
Bracket = 22,
|
|
25
|
+
Block = 23,
|
|
26
|
+
Plus = 24,
|
|
27
|
+
Separator = 25,
|
|
28
|
+
Exclamation = 26,
|
|
29
|
+
Ampersand = 27,
|
|
30
|
+
PipeToken = 28,
|
|
31
|
+
ColumnToken = 29,
|
|
32
|
+
AmpersandToken = 30,
|
|
33
|
+
Parens = 31,
|
|
34
|
+
PseudoClassToken = 32,
|
|
35
|
+
PseudoClassFunctionToken = 33,
|
|
36
|
+
StringToken = 34,
|
|
37
|
+
AtRuleDefinition = 35,
|
|
38
|
+
DeclarationNameToken = 36,
|
|
39
|
+
DeclarationDefinitionToken = 37,
|
|
40
|
+
SemiColon = 38,
|
|
41
|
+
Character = 39,
|
|
42
|
+
InfinityToken = 40,
|
|
43
|
+
LessThan = 41,
|
|
44
|
+
GreaterThan = 42,
|
|
45
|
+
/**
|
|
46
|
+
* end of token stream
|
|
47
|
+
*/
|
|
48
|
+
EOF = 43,
|
|
49
|
+
/**
|
|
50
|
+
* optional group or tokens, used to group validation tokens
|
|
51
|
+
*
|
|
52
|
+
* ```ts
|
|
53
|
+
* // <bg-layer>#? , <final-bg-layer> -> [<bg-layer>#? ,]? <final-bg-layer>
|
|
54
|
+
* // , <angular-color-stop> ]#? -> [, <angular-color-stop> ]#?]?
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
OptionalGroupToken = 44,
|
|
58
|
+
/**
|
|
59
|
+
* dimension token
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* // <time [0s,∞]> -> {
|
|
63
|
+
* // typ: ValidationTokenEnum.PropertyType
|
|
64
|
+
* // val: 'time',
|
|
65
|
+
* // range: {
|
|
66
|
+
* // min: ValidationNumberToken,
|
|
67
|
+
* // max: null | ValidationNumberToken | ValidationInfinityToken
|
|
68
|
+
* // }
|
|
69
|
+
* // }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
Dimension = 45,
|
|
73
|
+
DisallowWhitespace = 46,
|
|
74
|
+
Colon = 47
|
|
75
|
+
}
|
|
76
|
+
export declare enum ValidationSyntaxGroupEnum {
|
|
77
|
+
Declarations = "declarations",
|
|
78
|
+
Functions = "functions",
|
|
79
|
+
Syntaxes = "syntaxes",
|
|
80
|
+
Selectors = "selectors",
|
|
81
|
+
AtRules = "atRules",
|
|
82
|
+
Units = "units",
|
|
83
|
+
Languages = "languages",
|
|
84
|
+
mediaFeatures = "mediaFeatures"
|
|
85
|
+
}
|
|
86
|
+
export declare enum MediaFeatureType {
|
|
87
|
+
BooleanType = "boolean",
|
|
88
|
+
IntergerType = "integer",
|
|
89
|
+
KeywordType = "keyword",
|
|
90
|
+
LengthType = "length",
|
|
91
|
+
NumberType = "number",
|
|
92
|
+
RatioType = "ratio",
|
|
93
|
+
ResolutionType = "resolution",
|
|
94
|
+
StringType = "string"
|
|
95
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var ValidationTokenEnum;
|
|
2
|
+
(function (ValidationTokenEnum) {
|
|
3
|
+
ValidationTokenEnum[ValidationTokenEnum["Root"] = 0] = "Root";
|
|
4
|
+
ValidationTokenEnum[ValidationTokenEnum["Keyword"] = 1] = "Keyword";
|
|
5
|
+
ValidationTokenEnum[ValidationTokenEnum["PropertyType"] = 2] = "PropertyType";
|
|
6
|
+
ValidationTokenEnum[ValidationTokenEnum["DeclarationType"] = 3] = "DeclarationType";
|
|
7
|
+
ValidationTokenEnum[ValidationTokenEnum["AtRule"] = 4] = "AtRule";
|
|
8
|
+
ValidationTokenEnum[ValidationTokenEnum["FunctionDefinition"] = 5] = "FunctionDefinition";
|
|
9
|
+
ValidationTokenEnum[ValidationTokenEnum["OpenBracket"] = 6] = "OpenBracket";
|
|
10
|
+
ValidationTokenEnum[ValidationTokenEnum["CloseBracket"] = 7] = "CloseBracket";
|
|
11
|
+
ValidationTokenEnum[ValidationTokenEnum["OpenParenthesis"] = 8] = "OpenParenthesis";
|
|
12
|
+
ValidationTokenEnum[ValidationTokenEnum["CloseParenthesis"] = 9] = "CloseParenthesis";
|
|
13
|
+
ValidationTokenEnum[ValidationTokenEnum["Comma"] = 10] = "Comma";
|
|
14
|
+
ValidationTokenEnum[ValidationTokenEnum["Pipe"] = 11] = "Pipe";
|
|
15
|
+
ValidationTokenEnum[ValidationTokenEnum["Column"] = 12] = "Column";
|
|
16
|
+
ValidationTokenEnum[ValidationTokenEnum["Star"] = 13] = "Star";
|
|
17
|
+
ValidationTokenEnum[ValidationTokenEnum["OpenCurlyBrace"] = 14] = "OpenCurlyBrace";
|
|
18
|
+
ValidationTokenEnum[ValidationTokenEnum["CloseCurlyBrace"] = 15] = "CloseCurlyBrace";
|
|
19
|
+
ValidationTokenEnum[ValidationTokenEnum["HashMark"] = 16] = "HashMark";
|
|
20
|
+
ValidationTokenEnum[ValidationTokenEnum["QuestionMark"] = 17] = "QuestionMark";
|
|
21
|
+
ValidationTokenEnum[ValidationTokenEnum["Function"] = 18] = "Function";
|
|
22
|
+
ValidationTokenEnum[ValidationTokenEnum["Number"] = 19] = "Number";
|
|
23
|
+
ValidationTokenEnum[ValidationTokenEnum["Whitespace"] = 20] = "Whitespace";
|
|
24
|
+
ValidationTokenEnum[ValidationTokenEnum["Parenthesis"] = 21] = "Parenthesis";
|
|
25
|
+
ValidationTokenEnum[ValidationTokenEnum["Bracket"] = 22] = "Bracket";
|
|
26
|
+
ValidationTokenEnum[ValidationTokenEnum["Block"] = 23] = "Block";
|
|
27
|
+
ValidationTokenEnum[ValidationTokenEnum["Plus"] = 24] = "Plus";
|
|
28
|
+
ValidationTokenEnum[ValidationTokenEnum["Separator"] = 25] = "Separator";
|
|
29
|
+
ValidationTokenEnum[ValidationTokenEnum["Exclamation"] = 26] = "Exclamation";
|
|
30
|
+
ValidationTokenEnum[ValidationTokenEnum["Ampersand"] = 27] = "Ampersand";
|
|
31
|
+
ValidationTokenEnum[ValidationTokenEnum["PipeToken"] = 28] = "PipeToken";
|
|
32
|
+
ValidationTokenEnum[ValidationTokenEnum["ColumnToken"] = 29] = "ColumnToken";
|
|
33
|
+
ValidationTokenEnum[ValidationTokenEnum["AmpersandToken"] = 30] = "AmpersandToken";
|
|
34
|
+
ValidationTokenEnum[ValidationTokenEnum["Parens"] = 31] = "Parens";
|
|
35
|
+
ValidationTokenEnum[ValidationTokenEnum["PseudoClassToken"] = 32] = "PseudoClassToken";
|
|
36
|
+
ValidationTokenEnum[ValidationTokenEnum["PseudoClassFunctionToken"] = 33] = "PseudoClassFunctionToken";
|
|
37
|
+
ValidationTokenEnum[ValidationTokenEnum["StringToken"] = 34] = "StringToken";
|
|
38
|
+
ValidationTokenEnum[ValidationTokenEnum["AtRuleDefinition"] = 35] = "AtRuleDefinition";
|
|
39
|
+
ValidationTokenEnum[ValidationTokenEnum["DeclarationNameToken"] = 36] = "DeclarationNameToken";
|
|
40
|
+
ValidationTokenEnum[ValidationTokenEnum["DeclarationDefinitionToken"] = 37] = "DeclarationDefinitionToken";
|
|
41
|
+
ValidationTokenEnum[ValidationTokenEnum["SemiColon"] = 38] = "SemiColon";
|
|
42
|
+
ValidationTokenEnum[ValidationTokenEnum["Character"] = 39] = "Character";
|
|
43
|
+
ValidationTokenEnum[ValidationTokenEnum["InfinityToken"] = 40] = "InfinityToken";
|
|
44
|
+
ValidationTokenEnum[ValidationTokenEnum["LessThan"] = 41] = "LessThan";
|
|
45
|
+
ValidationTokenEnum[ValidationTokenEnum["GreaterThan"] = 42] = "GreaterThan";
|
|
46
|
+
/**
|
|
47
|
+
* end of token stream
|
|
48
|
+
*/
|
|
49
|
+
ValidationTokenEnum[ValidationTokenEnum["EOF"] = 43] = "EOF";
|
|
50
|
+
/**
|
|
51
|
+
* optional group or tokens, used to group validation tokens
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* // <bg-layer>#? , <final-bg-layer> -> [<bg-layer>#? ,]? <final-bg-layer>
|
|
55
|
+
* // , <angular-color-stop> ]#? -> [, <angular-color-stop> ]#?]?
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
ValidationTokenEnum[ValidationTokenEnum["OptionalGroupToken"] = 44] = "OptionalGroupToken";
|
|
59
|
+
/**
|
|
60
|
+
* dimension token
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* // <time [0s,∞]> -> {
|
|
64
|
+
* // typ: ValidationTokenEnum.PropertyType
|
|
65
|
+
* // val: 'time',
|
|
66
|
+
* // range: {
|
|
67
|
+
* // min: ValidationNumberToken,
|
|
68
|
+
* // max: null | ValidationNumberToken | ValidationInfinityToken
|
|
69
|
+
* // }
|
|
70
|
+
* // }
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
ValidationTokenEnum[ValidationTokenEnum["Dimension"] = 45] = "Dimension";
|
|
74
|
+
ValidationTokenEnum[ValidationTokenEnum["DisallowWhitespace"] = 46] = "DisallowWhitespace";
|
|
75
|
+
ValidationTokenEnum[ValidationTokenEnum["Colon"] = 47] = "Colon";
|
|
76
|
+
})(ValidationTokenEnum || (ValidationTokenEnum = {}));
|
|
77
|
+
var ValidationSyntaxGroupEnum;
|
|
78
|
+
(function (ValidationSyntaxGroupEnum) {
|
|
79
|
+
ValidationSyntaxGroupEnum["Declarations"] = "declarations";
|
|
80
|
+
ValidationSyntaxGroupEnum["Functions"] = "functions";
|
|
81
|
+
ValidationSyntaxGroupEnum["Syntaxes"] = "syntaxes";
|
|
82
|
+
ValidationSyntaxGroupEnum["Selectors"] = "selectors";
|
|
83
|
+
ValidationSyntaxGroupEnum["AtRules"] = "atRules";
|
|
84
|
+
ValidationSyntaxGroupEnum["Units"] = "units";
|
|
85
|
+
ValidationSyntaxGroupEnum["Languages"] = "languages";
|
|
86
|
+
ValidationSyntaxGroupEnum["mediaFeatures"] = "mediaFeatures";
|
|
87
|
+
})(ValidationSyntaxGroupEnum || (ValidationSyntaxGroupEnum = {}));
|
|
88
|
+
var MediaFeatureType;
|
|
89
|
+
(function (MediaFeatureType) {
|
|
90
|
+
MediaFeatureType["BooleanType"] = "boolean";
|
|
91
|
+
MediaFeatureType["IntergerType"] = "integer";
|
|
92
|
+
MediaFeatureType["KeywordType"] = "keyword";
|
|
93
|
+
MediaFeatureType["LengthType"] = "length";
|
|
94
|
+
MediaFeatureType["NumberType"] = "number";
|
|
95
|
+
MediaFeatureType["RatioType"] = "ratio";
|
|
96
|
+
MediaFeatureType["ResolutionType"] = "resolution";
|
|
97
|
+
MediaFeatureType["StringType"] = "string";
|
|
98
|
+
})(MediaFeatureType || (MediaFeatureType = {}));
|
|
99
|
+
|
|
100
|
+
export { MediaFeatureType, ValidationSyntaxGroupEnum, ValidationTokenEnum };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EnumToken } from "../../ast/types.ts";
|
|
2
|
+
import type { Token } from "../../../@types/index.d.ts";
|
|
3
|
+
export declare function stripCommaToken(tokenList: Token[]): Token[] | null;
|
|
4
|
+
export declare function splitTokenList(tokenList: Token[], split?: EnumToken[], includeSplitToken?: boolean): Token[][];
|
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
2
|
|
|
10
3
|
function stripCommaToken(tokenList) {
|
|
11
4
|
let result = [];
|
|
12
5
|
for (let i = 0; i < tokenList.length; i++) {
|
|
13
|
-
if (tokenList[i].typ != EnumToken.WhitespaceTokenType) {
|
|
14
|
-
tokenList[i];
|
|
15
|
-
}
|
|
16
6
|
if (tokenList[i].typ == EnumToken.CommentTokenType || tokenList[i].typ == EnumToken.CommaTokenType) {
|
|
17
7
|
continue;
|
|
18
8
|
}
|
|
@@ -20,9 +10,12 @@ function stripCommaToken(tokenList) {
|
|
|
20
10
|
}
|
|
21
11
|
return result;
|
|
22
12
|
}
|
|
23
|
-
function splitTokenList(tokenList, split = [EnumToken.CommaTokenType]) {
|
|
13
|
+
function splitTokenList(tokenList, split = [EnumToken.CommaTokenType], includeSplitToken = false) {
|
|
24
14
|
return tokenList.reduce((acc, curr) => {
|
|
25
15
|
if (split.includes(curr.typ)) {
|
|
16
|
+
if (includeSplitToken && Array.isArray(acc[acc.length - 1])) {
|
|
17
|
+
acc[acc.length - 1].push(curr);
|
|
18
|
+
}
|
|
26
19
|
acc.push([]);
|
|
27
20
|
}
|
|
28
21
|
else {
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import '../../ast/minify.js';
|
|
3
|
-
import '../../ast/walk.js';
|
|
4
|
-
import '../../parser/parse.js';
|
|
5
|
-
import '../../parser/tokenize.js';
|
|
6
|
-
import '../../parser/utils/config.js';
|
|
7
|
-
import '../../syntax/color/utils/constants.js';
|
|
8
|
-
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
2
|
|
|
10
3
|
function consumeWhitespace(tokens) {
|
|
11
4
|
if (tokens.length == 0) {
|
|
@@ -14,7 +7,8 @@ function consumeWhitespace(tokens) {
|
|
|
14
7
|
if (tokens[0].typ != EnumToken.WhitespaceTokenType && tokens[0].typ != EnumToken.DescendantCombinatorTokenType) {
|
|
15
8
|
return false;
|
|
16
9
|
}
|
|
17
|
-
while (tokens.length > 0 &&
|
|
10
|
+
while (tokens.length > 0 &&
|
|
11
|
+
(tokens[0].typ == EnumToken.WhitespaceTokenType || tokens[0].typ == EnumToken.DescendantCombinatorTokenType)) {
|
|
18
12
|
tokens.shift();
|
|
19
13
|
}
|
|
20
14
|
return true;
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult } from "./@types/index.d.ts";
|
|
2
|
+
import { dirname, resolve } from "./lib/fs/resolve.ts";
|
|
3
|
+
import { ResponseType } from "./types.ts";
|
|
4
|
+
export type * from "./@types/index.d.ts";
|
|
5
|
+
export type * from "./@types/ast.d.ts";
|
|
6
|
+
export type * from "./@types/token.d.ts";
|
|
7
|
+
export type * from "./@types/parse.d.ts";
|
|
8
|
+
export type * from "./@types/validation.d.ts";
|
|
9
|
+
export type * from "./@types/walker.d.ts";
|
|
10
|
+
export type { AstNode, ParseResult, ParserOptions, RenderOptions, RenderResult, TransformOptions, TransformResult, } from "./@types/index.d.ts";
|
|
11
|
+
export { minify } from "./lib/ast/minify.ts";
|
|
12
|
+
export { expand } from "./lib/ast/expand.ts";
|
|
13
|
+
export { walk, walkValues, WalkerEvent, WalkerOptionEnum } from "./lib/ast/walk.ts";
|
|
14
|
+
export { parseString } from "./lib/parser/parse.ts";
|
|
15
|
+
export { renderToken } from "./lib/renderer/render.ts";
|
|
16
|
+
export { convertColor } from "./lib/syntax/color/color.ts";
|
|
17
|
+
export { isOkLabClose, okLabDistance } from "./lib/syntax/color/utils/distance.ts";
|
|
18
|
+
export { parseDeclarations } from "./lib/parser/parse.ts";
|
|
19
|
+
export { find, findLast, findByValue, findAll } from "./lib/ast/find.ts";
|
|
20
|
+
export { cloneNode } from "./lib/ast/clone.ts";
|
|
21
|
+
export { EnumToken, ColorType, ValidationLevel, ModuleScopeEnumOptions, ModuleCaseTransformEnum, } from "./lib/ast/types.ts";
|
|
22
|
+
export { SourceMap } from "./lib/renderer/sourcemap/sourcemap.ts";
|
|
23
|
+
export type { ValidationToken } from "./lib/validation/parser/types.d.ts";
|
|
24
|
+
export { FeatureWalkMode } from "./lib/ast/features/type.ts";
|
|
25
|
+
export { dirname, resolve, ResponseType };
|
|
26
|
+
/**
|
|
27
|
+
* load file or url
|
|
28
|
+
* @param url
|
|
29
|
+
* @param currentDirectory
|
|
30
|
+
* @param responseType
|
|
31
|
+
* @throws Error file not found
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* import {load, ResponseType} from '@tbela99/css-parser';
|
|
35
|
+
* const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function load(url: string, currentDirectory?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
39
|
+
/**
|
|
40
|
+
* render the ast tree
|
|
41
|
+
* @param data
|
|
42
|
+
* @param options
|
|
43
|
+
* @param mapping
|
|
44
|
+
*
|
|
45
|
+
* Example:
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
*
|
|
49
|
+
* import {render, ColorType} from '@tbela99/css-parser';
|
|
50
|
+
*
|
|
51
|
+
* const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
|
|
52
|
+
* const parseResult = await parse(css);
|
|
53
|
+
*
|
|
54
|
+
* let renderResult = render(parseResult.ast);
|
|
55
|
+
* console.log(result.code);
|
|
56
|
+
*
|
|
57
|
+
* // body{color:red}
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
|
|
61
|
+
* console.log(renderResult.code);
|
|
62
|
+
*
|
|
63
|
+
* // body {
|
|
64
|
+
* // color: color(srgb 1 0 0)
|
|
65
|
+
* // }
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function render(data: AstNode, options?: RenderOptions, mapping?: {
|
|
69
|
+
mapping: Record<string, string>;
|
|
70
|
+
importMapping: Record<string, Record<string, string>> | null;
|
|
71
|
+
} | null): RenderResult;
|
|
72
|
+
/**
|
|
73
|
+
* parse css file
|
|
74
|
+
* @param file url or path
|
|
75
|
+
* @param options
|
|
76
|
+
* @param asStream load file as stream
|
|
77
|
+
*
|
|
78
|
+
* @throws Error file not found
|
|
79
|
+
*
|
|
80
|
+
* Example:
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
*
|
|
84
|
+
* import {parseFile} from '@tbela99/css-parser';
|
|
85
|
+
*
|
|
86
|
+
* // remote file
|
|
87
|
+
* let result = await parseFile('https://docs.deno.com/styles.css');
|
|
88
|
+
* console.log(result.ast);
|
|
89
|
+
*
|
|
90
|
+
* // local file
|
|
91
|
+
* result = await parseFile('./css/styles.css');
|
|
92
|
+
* console.log(result.ast);
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function parseFile(file: string, options?: ParserOptions, asStream?: boolean): Promise<ParseResult>;
|
|
96
|
+
/**
|
|
97
|
+
* parse css
|
|
98
|
+
* @param stream
|
|
99
|
+
* @param options
|
|
100
|
+
*
|
|
101
|
+
* Example:
|
|
102
|
+
*
|
|
103
|
+
* ```ts
|
|
104
|
+
*
|
|
105
|
+
* import {parse} from '@tbela99/css-parser';
|
|
106
|
+
*
|
|
107
|
+
* // css string
|
|
108
|
+
* let result = await parse(css);
|
|
109
|
+
* console.log(result.ast);
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* Example using stream
|
|
113
|
+
*
|
|
114
|
+
* ```ts
|
|
115
|
+
*
|
|
116
|
+
* import {parse} from '@tbela99/css-parser';
|
|
117
|
+
* import {Readable} from "node:stream";
|
|
118
|
+
*
|
|
119
|
+
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
120
|
+
*
|
|
121
|
+
* const readableStream = Readable.toWeb(process.stdin);
|
|
122
|
+
* let result = await parse(readableStream, {beautify: true});
|
|
123
|
+
*
|
|
124
|
+
* console.log(result.ast);
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* Example using fetch and readable stream
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
*
|
|
131
|
+
* import {parse} from '@tbela99/css-parser';
|
|
132
|
+
*
|
|
133
|
+
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
134
|
+
* const result = await parse(response.body, {beautify: true});
|
|
135
|
+
*
|
|
136
|
+
* console.log(result.ast);
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function parse(stream: string | ReadableStream<Uint8Array>, options?: ParserOptions): Promise<ParseResult>;
|
|
140
|
+
/**
|
|
141
|
+
* transform css file
|
|
142
|
+
* @param file url or path
|
|
143
|
+
* @param options
|
|
144
|
+
* @param asStream load file as stream
|
|
145
|
+
*
|
|
146
|
+
* @throws Error file not found
|
|
147
|
+
*
|
|
148
|
+
* Example:
|
|
149
|
+
*
|
|
150
|
+
* ```ts
|
|
151
|
+
*
|
|
152
|
+
* import {transformFile} from '@tbela99/css-parser';
|
|
153
|
+
*
|
|
154
|
+
* // remote file
|
|
155
|
+
* let result = await transformFile('https://docs.deno.com/styles.css');
|
|
156
|
+
* console.log(result.code);
|
|
157
|
+
*
|
|
158
|
+
* // local file
|
|
159
|
+
* result = await transformFile('./css/styles.css');
|
|
160
|
+
* console.log(result.code);
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare function transformFile(file: string, options?: TransformOptions, asStream?: boolean): Promise<TransformResult>;
|
|
164
|
+
/**
|
|
165
|
+
* transform css
|
|
166
|
+
* @param css
|
|
167
|
+
* @param options
|
|
168
|
+
*
|
|
169
|
+
* Example:
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
*
|
|
173
|
+
* import {transform} from '@tbela99/css-parser';
|
|
174
|
+
*
|
|
175
|
+
* // css string
|
|
176
|
+
* const result = await transform(css);
|
|
177
|
+
* console.log(result.code);
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* Example using stream
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
*
|
|
184
|
+
* import {transform} from '@tbela99/css-parser';
|
|
185
|
+
* import {Readable} from "node:stream";
|
|
186
|
+
*
|
|
187
|
+
* // usage: node index.ts < styles.css or cat styles.css | node index.ts
|
|
188
|
+
*
|
|
189
|
+
* const readableStream = Readable.toWeb(process.stdin);
|
|
190
|
+
* const result = await transform(readableStream, {beautify: true});
|
|
191
|
+
*
|
|
192
|
+
* console.log(result.code);
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* Example using fetch
|
|
196
|
+
*
|
|
197
|
+
* ```ts
|
|
198
|
+
*
|
|
199
|
+
* import {transform} from '@tbela99/css-parser';
|
|
200
|
+
*
|
|
201
|
+
* const response = await fetch('https://docs.deno.com/styles.css');
|
|
202
|
+
* result = await transform(response.body, {beautify: true});
|
|
203
|
+
*
|
|
204
|
+
* console.log(result.code);
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
export declare function transform(css: string | ReadableStream<Uint8Array>, options?: TransformOptions): Promise<TransformResult>;
|
package/dist/node.js
CHANGED
|
@@ -1,28 +1,24 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { createReadStream } from 'node:fs';
|
|
4
|
+
import { lstat, readFile } from 'node:fs/promises';
|
|
5
|
+
import { doParse } from './lib/parser/parse.js';
|
|
6
|
+
export { parseDeclarations, parseString } from './lib/parser/parse.js';
|
|
7
|
+
import { doRender } from './lib/renderer/render.js';
|
|
8
|
+
export { renderToken } from './lib/renderer/render.js';
|
|
2
9
|
import { ModuleScopeEnumOptions } from './lib/ast/types.js';
|
|
3
10
|
export { ColorType, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
|
|
11
|
+
import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
|
|
12
|
+
import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
|
|
13
|
+
import { ResponseType } from './types.js';
|
|
4
14
|
export { minify } from './lib/ast/minify.js';
|
|
5
|
-
export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
|
|
6
15
|
export { expand } from './lib/ast/expand.js';
|
|
7
|
-
|
|
8
|
-
export { renderToken } from './lib/renderer/render.js';
|
|
9
|
-
export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
|
|
10
|
-
import { doParse } from './lib/parser/parse.js';
|
|
11
|
-
export { parseDeclarations, parseString, parseTokens } from './lib/parser/parse.js';
|
|
12
|
-
import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
|
|
13
|
-
import './lib/parser/utils/config.js';
|
|
16
|
+
export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
|
|
14
17
|
export { convertColor } from './lib/syntax/color/color.js';
|
|
15
|
-
import './lib/syntax/color/utils/constants.js';
|
|
16
18
|
export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import './lib/validation/syntax.js';
|
|
21
|
-
import { resolve, matchUrl, dirname } from './lib/fs/resolve.js';
|
|
22
|
-
import { Readable } from 'node:stream';
|
|
23
|
-
import { createReadStream } from 'node:fs';
|
|
24
|
-
import { lstat, readFile } from 'node:fs/promises';
|
|
25
|
-
import { ResponseType } from './types.js';
|
|
19
|
+
export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
|
|
20
|
+
export { cloneNode } from './lib/ast/clone.js';
|
|
21
|
+
export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
|
|
26
22
|
export { FeatureWalkMode } from './lib/ast/features/type.js';
|
|
27
23
|
|
|
28
24
|
/**
|
|
@@ -37,9 +33,9 @@ export { FeatureWalkMode } from './lib/ast/features/type.js';
|
|
|
37
33
|
* const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
|
|
38
34
|
* ```
|
|
39
35
|
*/
|
|
40
|
-
async function load(url, currentDirectory =
|
|
36
|
+
async function load(url, currentDirectory = ".", responseType = false) {
|
|
41
37
|
const resolved = resolve(url, currentDirectory);
|
|
42
|
-
if (typeof responseType ==
|
|
38
|
+
if (typeof responseType == "boolean") {
|
|
43
39
|
responseType = responseType ? ResponseType.ReadableStream : ResponseType.Text;
|
|
44
40
|
}
|
|
45
41
|
if (matchUrl.test(resolved.absolute)) {
|
|
@@ -50,21 +46,23 @@ async function load(url, currentDirectory = '.', responseType = false) {
|
|
|
50
46
|
if (responseType == ResponseType.ArrayBuffer) {
|
|
51
47
|
return response.arrayBuffer();
|
|
52
48
|
}
|
|
53
|
-
return responseType == ResponseType.ReadableStream
|
|
49
|
+
return responseType == ResponseType.ReadableStream
|
|
50
|
+
? response.body
|
|
51
|
+
: response.text();
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
try {
|
|
57
55
|
const stats = await lstat(resolved.absolute);
|
|
58
56
|
if (stats.isFile()) {
|
|
59
57
|
if (responseType == ResponseType.Text) {
|
|
60
|
-
return readFile(resolved.absolute,
|
|
58
|
+
return readFile(resolved.absolute, "utf-8");
|
|
61
59
|
}
|
|
62
60
|
if (responseType == ResponseType.ArrayBuffer) {
|
|
63
|
-
return readFile(resolved.absolute).then(buffer => buffer.buffer);
|
|
61
|
+
return readFile(resolved.absolute).then((buffer) => buffer.buffer);
|
|
64
62
|
}
|
|
65
63
|
return Readable.toWeb(createReadStream(resolved.absolute, {
|
|
66
|
-
encoding:
|
|
67
|
-
highWaterMark: 64 * 1024
|
|
64
|
+
encoding: "utf-8",
|
|
65
|
+
highWaterMark: 64 * 1024,
|
|
68
66
|
}));
|
|
69
67
|
}
|
|
70
68
|
}
|
|
@@ -129,7 +127,7 @@ function render(data, options = {}, mapping) {
|
|
|
129
127
|
* ```
|
|
130
128
|
*/
|
|
131
129
|
async function parseFile(file, options = {}, asStream = false) {
|
|
132
|
-
return Promise.resolve((options.load ?? load)(file,
|
|
130
|
+
return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => parse(stream, { src: file, ...options }));
|
|
133
131
|
}
|
|
134
132
|
/**
|
|
135
133
|
* parse css
|
|
@@ -175,18 +173,21 @@ async function parseFile(file, options = {}, asStream = false) {
|
|
|
175
173
|
* ```
|
|
176
174
|
*/
|
|
177
175
|
async function parse(stream, options = {}) {
|
|
178
|
-
|
|
176
|
+
options.parseInfo = {
|
|
179
177
|
stream,
|
|
180
|
-
buffer:
|
|
178
|
+
buffer: "",
|
|
179
|
+
src: options.src ?? "",
|
|
181
180
|
offset: 0,
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
181
|
+
time: 0,
|
|
182
|
+
position: { ind: 0, lin: 1, col: 0 },
|
|
183
|
+
currentPosition: { ind: -1, lin: 1, col: 0 },
|
|
184
|
+
};
|
|
185
|
+
return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), Object.assign(options, {
|
|
185
186
|
load,
|
|
186
187
|
resolve,
|
|
187
188
|
dirname,
|
|
188
|
-
cwd: options.cwd ?? process.cwd()
|
|
189
|
-
})).then(result => {
|
|
189
|
+
cwd: options.cwd ?? process.cwd(),
|
|
190
|
+
})).then((result) => {
|
|
190
191
|
const { revMapping, ...res } = result;
|
|
191
192
|
return res;
|
|
192
193
|
});
|
|
@@ -215,7 +216,7 @@ async function parse(stream, options = {}) {
|
|
|
215
216
|
* ```
|
|
216
217
|
*/
|
|
217
218
|
async function transformFile(file, options = {}, asStream = false) {
|
|
218
|
-
return Promise.resolve((options.load ?? load)(file,
|
|
219
|
+
return Promise.resolve((options.load ?? load)(file, ".", asStream)).then((stream) => transform(stream, { src: file, ...options }));
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
221
222
|
* transform css
|
|
@@ -266,18 +267,20 @@ async function transform(css, options = {}) {
|
|
|
266
267
|
return parse(css, options).then((parseResult) => {
|
|
267
268
|
let mapping = null;
|
|
268
269
|
let importMapping = null;
|
|
269
|
-
if (typeof options.module ==
|
|
270
|
+
if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
|
|
270
271
|
mapping = parseResult.mapping;
|
|
271
272
|
importMapping = parseResult.importMapping;
|
|
272
273
|
}
|
|
273
|
-
else if (typeof options.module ==
|
|
274
|
+
else if (typeof options.module == "object" &&
|
|
275
|
+
typeof options.module.scoped == "number" &&
|
|
276
|
+
options.module.scoped & ModuleScopeEnumOptions.ICSS) {
|
|
274
277
|
mapping = parseResult.mapping;
|
|
275
278
|
importMapping = parseResult.importMapping;
|
|
276
279
|
}
|
|
277
280
|
// ast already expanded by parse
|
|
278
281
|
const rendered = render(parseResult.ast, {
|
|
279
282
|
...options,
|
|
280
|
-
expandNestingRules: false
|
|
283
|
+
expandNestingRules: false,
|
|
281
284
|
}, mapping != null ? { mapping, importMapping } : null);
|
|
282
285
|
return {
|
|
283
286
|
...parseResult,
|
|
@@ -287,8 +290,8 @@ async function transform(css, options = {}) {
|
|
|
287
290
|
bytesOut: rendered.code.length,
|
|
288
291
|
...parseResult.stats,
|
|
289
292
|
render: rendered.stats.total,
|
|
290
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms
|
|
291
|
-
}
|
|
293
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`,
|
|
294
|
+
},
|
|
292
295
|
};
|
|
293
296
|
});
|
|
294
297
|
}
|