@tbela99/css-parser 2.1.0 → 2.2.0
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/CHANGELOG.md +42 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +5 -2
- package/dist/index-umd-web.js +10738 -4359
- package/dist/index.d.ts +734 -100
- package/dist/{src/lib → lib}/ast/arena-node.js +10 -10
- package/dist/{src/lib → lib}/ast/arena.js +304 -139
- package/dist/{src/lib → lib}/ast/cache.js +2 -2
- package/dist/{src/lib → lib}/ast/features/calc.js +11 -9
- package/dist/{src/lib → lib}/ast/features/if.js +6 -6
- package/dist/{src/lib → lib}/ast/features/index.js +3 -2
- package/dist/{src/lib → lib}/ast/features/inlinecssvariables.js +12 -10
- package/dist/lib/ast/features/mixin.js +953 -0
- package/dist/{src/lib → lib}/ast/features/prefix.js +39 -39
- package/dist/lib/ast/features/shorthand.js +129 -0
- package/dist/lib/ast/features/transform.js +188 -0
- package/dist/{src/lib → lib}/ast/features/type.js +2 -2
- package/dist/{src/lib → lib}/ast/math/expression.js +24 -24
- package/dist/{src/lib → lib}/ast/math/math.js +2 -2
- package/dist/{src/lib → lib}/ast/minify.js +745 -201
- package/dist/lib/ast/mixins/custom-function.js +393 -0
- package/dist/lib/ast/mixins/utils.js +53 -0
- package/dist/lib/ast/mixins/variables.js +678 -0
- package/dist/lib/ast/strings.js +906 -0
- package/dist/lib/ast/transform/compute.js +560 -0
- package/dist/lib/ast/transform/matrix.js +67 -0
- package/dist/lib/ast/transform/minify.js +325 -0
- package/dist/lib/ast/transform/perspective.js +24 -0
- package/dist/{src/lib → lib}/ast/transform/rotate.js +16 -7
- package/dist/lib/ast/transform/scale.js +43 -0
- package/dist/lib/ast/transform/skew.js +38 -0
- package/dist/lib/ast/transform/translate.js +56 -0
- package/dist/lib/ast/transform/utils.js +390 -0
- package/dist/{src/lib → lib}/ast/types.js +2 -2
- package/dist/{src/lib → lib}/ast/walk.js +2 -2
- package/dist/{src/lib → lib}/fs/resolve.js +2 -2
- package/dist/{src/lib → lib}/parser/declaration/list.js +25 -8
- package/dist/{src/lib → lib}/parser/declaration/map.js +15 -15
- package/dist/{src/lib → lib}/parser/declaration/set.js +5 -5
- package/dist/{src/lib → lib}/parser/input.js +18 -3
- package/dist/{src/lib → lib}/parser/linesmap.js +2 -2
- package/dist/{src/lib → lib}/parser/parse.js +425 -258
- package/dist/{src/lib → lib}/parser/source.js +2 -2
- package/dist/{src/lib → lib}/parser/tokenize.js +480 -312
- package/dist/{src/lib → lib}/parser/utils/angle.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-container.js +12 -12
- package/dist/{src/lib → lib}/parser/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib → lib}/parser/utils/at-rule-import.js +10 -10
- package/dist/{src/lib → lib}/parser/utils/at-rule-media.js +14 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-support.js +9 -14
- package/dist/{src/lib → lib}/parser/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib → lib}/parser/utils/at-rule.js +3 -3
- package/dist/{src/lib → lib}/parser/utils/base64.js +2 -2
- package/dist/lib/parser/utils/cache.js +53 -0
- package/dist/lib/parser/utils/canonical.js +78 -0
- package/dist/lib/parser/utils/codes.js +93 -0
- package/dist/{src/lib → lib}/parser/utils/config.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/declaration.js +31 -26
- package/dist/{src/lib → lib}/parser/utils/eq.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/hash.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/selector.js +305 -63
- package/dist/{src/lib → lib}/parser/utils/text.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/token.js +2 -2
- package/dist/{src/lib → lib}/parser/utils/type.js +9 -7
- package/dist/{src/lib → lib}/printer/render.js +420 -152
- package/dist/lib/printer/result.js +148 -0
- package/dist/{src/lib → lib}/printer/sourcemap/lib/codec.js +2 -2
- package/dist/{src/lib → lib}/printer/sourcemap/sourcemap.js +2 -2
- package/dist/lib/printer/writer.js +252 -0
- package/dist/{src/lib → lib}/syntax/color/a98rgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/alpha.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/cmyk.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/color-mix.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/color.js +18 -18
- package/dist/{src/lib → lib}/syntax/color/hex.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/hsl.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/hwb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/lch.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklab.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/oklch.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/p3.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/prophotorgb.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/rec2020.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/relative-color.js +14 -14
- package/dist/{src/lib → lib}/syntax/color/rgb.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/srgb.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/color-type.js +4 -4
- package/dist/{src/lib → lib}/syntax/color/utils/colorspace.js +10 -10
- package/dist/{src/lib → lib}/syntax/color/utils/components.js +5 -5
- package/dist/{src/lib → lib}/syntax/color/utils/distance.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/utils/make-color.js +3 -3
- package/dist/{src/lib → lib}/syntax/color/utils/matrix.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyz.js +2 -2
- package/dist/{src/lib → lib}/syntax/color/xyzd50.js +2 -2
- package/dist/{src/lib → lib}/syntax/constants.js +26 -3
- package/dist/{src/lib → lib}/syntax/syntax.js +37 -29
- package/dist/{src/lib → lib}/validation/config.js +23 -10
- package/dist/lib/validation/first.js +571 -0
- package/dist/{src/lib → lib}/validation/match.js +292 -150
- package/dist/{src/lib → lib}/validation/parser/parse.js +2 -2
- package/dist/{src/lib → lib}/validation/parser/typedef.js +2 -2
- package/dist/{src/lib → lib}/validation/utils/list.js +3 -19
- package/dist/{src/node.js → node.js} +52 -34
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +10 -5
- package/dist/version.d.ts +4 -0
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +47 -34
- package/package.json +12 -12
- package/dist/package.json.js +0 -10
- package/dist/src/lib/ast/features/shorthand.js +0 -95
- package/dist/src/lib/ast/features/transform.js +0 -90
- package/dist/src/lib/ast/transform/compute.js +0 -362
- package/dist/src/lib/ast/transform/matrix.js +0 -88
- package/dist/src/lib/ast/transform/minify.js +0 -267
- package/dist/src/lib/ast/transform/perspective.js +0 -16
- package/dist/src/lib/ast/transform/scale.js +0 -39
- package/dist/src/lib/ast/transform/skew.js +0 -30
- package/dist/src/lib/ast/transform/translate.js +0 -39
- package/dist/src/lib/ast/transform/utils.js +0 -287
- package/dist/src/lib/parser/utils/cache.js +0 -54
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
function toDegrees(arena, angle) {
|
|
15
|
-
switch (arena.
|
|
15
|
+
switch (arena.resolveString(arena.unit[angle])) {
|
|
16
16
|
// case "deg":
|
|
17
17
|
// return angle;
|
|
18
18
|
case "rad":
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../../ast/arena.js';
|
|
9
9
|
import { EnumToken } from '../../ast/types.js';
|
|
10
|
-
import {
|
|
10
|
+
import { isFunctionDefType, mFGT, mFLT, tokensfuncDefMap } from '../../syntax/constants.js';
|
|
11
11
|
import { matchAllSyntaxes, createValidationContext, trimArray } from '../../validation/match.js';
|
|
12
12
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
13
13
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
@@ -16,7 +16,7 @@ import { equalsIgnoreCase } from './text.js';
|
|
|
16
16
|
function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
17
17
|
let matchCount = 0;
|
|
18
18
|
const errors = [];
|
|
19
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.
|
|
19
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[context]));
|
|
20
20
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
21
21
|
const parts = [[]];
|
|
22
22
|
for (const token of stream) {
|
|
@@ -26,7 +26,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
26
26
|
continue;
|
|
27
27
|
}
|
|
28
28
|
parts[parts.length - 1].push(token);
|
|
29
|
-
if (type === EnumToken.StartParensTokenType ||
|
|
29
|
+
if (type === EnumToken.StartParensTokenType || isFunctionDefType(type)) {
|
|
30
30
|
matchCount++;
|
|
31
31
|
}
|
|
32
32
|
else if (type === EnumToken.EndParensTokenType && matchCount > 0) {
|
|
@@ -93,7 +93,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
93
93
|
if (expectAndOr) {
|
|
94
94
|
let valid = true;
|
|
95
95
|
// if (arena.dataTypes[stream[i]] === EnumToken.IdenTokenType) {
|
|
96
|
-
// const val: string = arena.
|
|
96
|
+
// const val: string = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
97
97
|
// valid = val === "and" || val === "or";
|
|
98
98
|
// } else {
|
|
99
99
|
valid = arena.dataTypes[stream[i]] !== EnumToken.CommaTokenType;
|
|
@@ -114,7 +114,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
117
|
-
|
|
117
|
+
isFunctionDefType(arena.dataTypes[stream[i]])) {
|
|
118
118
|
scopes.push((currentScope = new Set()));
|
|
119
119
|
stack.push(stream[i]);
|
|
120
120
|
continue;
|
|
@@ -130,7 +130,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
130
130
|
break;
|
|
131
131
|
case EnumToken.IdenTokenType:
|
|
132
132
|
{
|
|
133
|
-
const val = arena.
|
|
133
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
134
134
|
if (val === "not") {
|
|
135
135
|
arena.dataTypes[stream[i]] = EnumToken.NotTokenType;
|
|
136
136
|
stack.push(stream[i]);
|
|
@@ -182,7 +182,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
182
182
|
if (arena.dataTypes[op] === EnumToken.ColonTokenType) {
|
|
183
183
|
const name = names.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
184
184
|
if (name != null) {
|
|
185
|
-
const val = arena.
|
|
185
|
+
const val = arena.resolveString(arena.stringValue[name]);
|
|
186
186
|
if (val.startsWith("min-")) {
|
|
187
187
|
// inlined: arena.setStr(name, val.substring(4))
|
|
188
188
|
arena.stringValue[name] = arena.internString(val.substring(4));
|
|
@@ -197,7 +197,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
197
197
|
}
|
|
198
198
|
// check <style()> or <scroll-state()>
|
|
199
199
|
}
|
|
200
|
-
if (stack.length > 0 &&
|
|
200
|
+
if (stack.length > 0 && isFunctionDefType(arena.dataTypes[stack[stack.length - 1]])) {
|
|
201
201
|
const index = tokens.indexOf(stack[stack.length - 1]);
|
|
202
202
|
arena.dataTypes[tokens[index]] = tokensfuncDefMap.get(arena.dataTypes[tokens[index]]);
|
|
203
203
|
arena.setTokenList(tokens[index], trimArray(arena, tokens.slice(index + 1, tokens.length - 1)));
|
|
@@ -215,7 +215,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
215
215
|
options.source.file,
|
|
216
216
|
...options.source.lineStarts.getOffsets(arena.getSpanStart(stream[i])),
|
|
217
217
|
],
|
|
218
|
-
message: `expecting '<${arena.
|
|
218
|
+
message: `expecting '<${arena.resolveString(arena.stringValue[tokens[index]])}-query>'`,
|
|
219
219
|
});
|
|
220
220
|
break;
|
|
221
221
|
}
|
|
@@ -330,7 +330,7 @@ function parseAtRuleContainerQueryList(arena, stream, context, options = {}) {
|
|
|
330
330
|
.find((t) => arena.dataTypes[t] === EnumToken.IdenTokenType);
|
|
331
331
|
if (name != null &&
|
|
332
332
|
name2 != null &&
|
|
333
|
-
equalsIgnoreCase(arena.
|
|
333
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[name]), arena.resolveString(arena.stringValue[name2]))) {
|
|
334
334
|
switch (arena.dataTypes[leftOp]) {
|
|
335
335
|
case EnumToken.LtTokenType:
|
|
336
336
|
arena.dataTypes[leftOp] = EnumToken.GtTokenType;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
@@ -10,7 +10,7 @@ import { trimArray, matchAllSyntaxes, createValidationContext } from '../../vali
|
|
|
10
10
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
11
11
|
|
|
12
12
|
function parseAtRuleFontFeatureValues(arena, stream, context, options = {}) {
|
|
13
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.
|
|
13
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[context]));
|
|
14
14
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
15
15
|
trimArray(arena, stream);
|
|
16
16
|
const { success, errors /* , ...all */ } = matchAllSyntaxes(arena, syntax, createValidationContext(arena, stream), options);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
|
-
import {
|
|
9
|
+
import { isFunctionDefType } from '../../syntax/constants.js';
|
|
10
10
|
import { equalsIgnoreCase } from './text.js';
|
|
11
11
|
|
|
12
12
|
function matchGenericSyntax(arena, stream, options) {
|
|
@@ -23,7 +23,7 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
23
23
|
arena.dataTypes[token] === EnumToken.CommentTokenType) {
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
26
|
-
if (arena.dataTypes[token] === EnumToken.StartParensTokenType ||
|
|
26
|
+
if (arena.dataTypes[token] === EnumToken.StartParensTokenType || isFunctionDefType(arena.dataTypes[token])) {
|
|
27
27
|
stack.push(token);
|
|
28
28
|
scopes.push(new Set());
|
|
29
29
|
expectAndOr = false;
|
|
@@ -32,7 +32,7 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
32
32
|
if (arena.dataTypes[token] === EnumToken.EndParensTokenType) {
|
|
33
33
|
if (stack.length === 0 ||
|
|
34
34
|
(arena.dataTypes[stack[stack.length - 1]] !== EnumToken.StartParensTokenType &&
|
|
35
|
-
!
|
|
35
|
+
!isFunctionDefType(arena.dataTypes[stack[stack.length - 1]]))) {
|
|
36
36
|
errors.push({
|
|
37
37
|
action: "drop",
|
|
38
38
|
message: `unexpected token ${EnumToken[arena.dataTypes[token]]}`,
|
|
@@ -51,7 +51,7 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
53
|
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
54
|
-
equalsIgnoreCase("and", arena.
|
|
54
|
+
equalsIgnoreCase("and", arena.resolveString(arena.stringValue[token]))) {
|
|
55
55
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.OrTokenType)) {
|
|
56
56
|
errors.push({
|
|
57
57
|
action: "drop",
|
|
@@ -72,7 +72,7 @@ function matchGenericSyntax(arena, stream, options) {
|
|
|
72
72
|
continue;
|
|
73
73
|
}
|
|
74
74
|
if (arena.dataTypes[token] === EnumToken.IdenTokenType &&
|
|
75
|
-
equalsIgnoreCase("or", arena.
|
|
75
|
+
equalsIgnoreCase("or", arena.resolveString(arena.stringValue[token]))) {
|
|
76
76
|
if (!expectAndOr || scopes.at(-1)?.has(EnumToken.AndTokenType)) {
|
|
77
77
|
errors.push({
|
|
78
78
|
action: "drop",
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
9
|
import { getSyntaxRule } from '../../validation/config.js';
|
|
10
10
|
import { trimArray } from '../../validation/match.js';
|
|
11
11
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
12
|
-
import { tokensfuncDefMap } from '../../syntax/constants.js';
|
|
12
|
+
import { tokensfuncDefMap, isFunctionDefType } from '../../syntax/constants.js';
|
|
13
13
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
14
14
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
15
15
|
|
|
@@ -38,7 +38,7 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
38
38
|
matchCount--;
|
|
39
39
|
}
|
|
40
40
|
else if (arena.dataTypes[stream[k]] === EnumToken.StartParensTokenType ||
|
|
41
|
-
|
|
41
|
+
isFunctionDefType(arena.dataTypes[stream[k]])) {
|
|
42
42
|
matchCount++;
|
|
43
43
|
}
|
|
44
44
|
if (matchCount === 0) {
|
|
@@ -77,11 +77,11 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
77
77
|
}
|
|
78
78
|
// layer | layer(<layer-name>)
|
|
79
79
|
if (arena.dataTypes[stream[index]] === EnumToken.IdenTokenType &&
|
|
80
|
-
"layer".localeCompare(arena.
|
|
80
|
+
"layer".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
81
81
|
tokens.push(stream[index++]);
|
|
82
82
|
}
|
|
83
|
-
else if (
|
|
84
|
-
"layer".localeCompare(arena.
|
|
83
|
+
else if (isFunctionDefType(arena.dataTypes[stream[index]]) &&
|
|
84
|
+
"layer".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
85
85
|
stack.push(stream[index]);
|
|
86
86
|
tokens.push(stream[index++]);
|
|
87
87
|
// <layer-name">
|
|
@@ -140,8 +140,8 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
140
140
|
}
|
|
141
141
|
// supports([ <supports-condition> | <declaration> ])
|
|
142
142
|
if (index < stream.length &&
|
|
143
|
-
|
|
144
|
-
"supports".localeCompare(arena.
|
|
143
|
+
isFunctionDefType(arena.dataTypes[stream[index]]) &&
|
|
144
|
+
"supports".localeCompare(arena.resolveString(arena.stringValue[stream[index]])) === 0) {
|
|
145
145
|
stack.push(stream[index]);
|
|
146
146
|
tokens.push(stream[index++]);
|
|
147
147
|
matchCount = 1;
|
|
@@ -150,7 +150,7 @@ function matchAtRuleImportSyntax(arena, atRule, stream, options) {
|
|
|
150
150
|
// match the next ')'
|
|
151
151
|
while (index < stream.length && matchCount > 0) {
|
|
152
152
|
if (arena.dataTypes[stream[index]] === EnumToken.StartParensTokenType ||
|
|
153
|
-
|
|
153
|
+
isFunctionDefType(arena.dataTypes[stream[index]])) {
|
|
154
154
|
matchCount++;
|
|
155
155
|
}
|
|
156
156
|
else if (arena.dataTypes[stream[index]] === EnumToken.EndParensTokenType) {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../../ast/arena.js';
|
|
9
9
|
import { EnumToken } from '../../ast/types.js';
|
|
10
10
|
import { evaluate } from '../../ast/math/expression.js';
|
|
11
11
|
import { gcd } from '../../ast/math/math.js';
|
|
12
|
-
import {
|
|
12
|
+
import { isFunctionDefType, mediaTypes, tokensfuncDefMap, mFLT, mFGT } from '../../syntax/constants.js';
|
|
13
13
|
import { trimArray, matchAllSyntaxes, createValidationContext, getMFInfo, isMFValue } from '../../validation/match.js';
|
|
14
14
|
import { ValidationSyntaxGroupEnum, MediaFeatureType } from '../../validation/parser/typedef.js';
|
|
15
15
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
@@ -32,7 +32,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
parts[parts.length - 1].push(token);
|
|
35
|
-
if (type === EnumToken.StartParensTokenType ||
|
|
35
|
+
if (type === EnumToken.StartParensTokenType || isFunctionDefType(type)) {
|
|
36
36
|
matchCount++;
|
|
37
37
|
}
|
|
38
38
|
else if (type === EnumToken.EndParensTokenType && matchCount > 0) {
|
|
@@ -57,7 +57,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
57
57
|
// [not | only] <media-type> [ and <media-condition-without-or> ]?
|
|
58
58
|
if (i < stream.length) {
|
|
59
59
|
if (arena.dataTypes[stream[i]] === EnumToken.IdenTokenType) {
|
|
60
|
-
const val = arena.
|
|
60
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
61
61
|
if (mediaTypes.includes(val)) {
|
|
62
62
|
tokens.push(stream[i]);
|
|
63
63
|
i++;
|
|
@@ -97,7 +97,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
97
97
|
continue;
|
|
98
98
|
}
|
|
99
99
|
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
100
|
-
|
|
100
|
+
isFunctionDefType(arena.dataTypes[stream[i]])) {
|
|
101
101
|
scopes.push((currentScope = new Set()));
|
|
102
102
|
stack.push(stream[i]);
|
|
103
103
|
continue;
|
|
@@ -113,7 +113,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
113
113
|
break;
|
|
114
114
|
case EnumToken.IdenTokenType:
|
|
115
115
|
{
|
|
116
|
-
const val = arena.
|
|
116
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
117
117
|
if (val === "and" || val === "or") {
|
|
118
118
|
arena.dataTypes[stream[i]] =
|
|
119
119
|
val === "and" ? EnumToken.AndTokenType : EnumToken.OrTokenType;
|
|
@@ -153,13 +153,13 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
153
153
|
}
|
|
154
154
|
break;
|
|
155
155
|
case EnumToken.EndParensTokenType:
|
|
156
|
-
if (stack.length > 0 &&
|
|
156
|
+
if (stack.length > 0 && isFunctionDefType(arena.dataTypes[stack[stack.length - 1]])) {
|
|
157
157
|
const index = tokens.indexOf(stack[stack.length - 1]);
|
|
158
158
|
arena.spanLocation(tokens[index], tokens[index], stream[i]);
|
|
159
159
|
arena.dataTypes[tokens[index]] = tokensfuncDefMap.get(arena.dataTypes[tokens[index]]);
|
|
160
160
|
arena.setTokenList(tokens[index], trimArray(arena, tokens.slice(index + 1, tokens.length - 1)));
|
|
161
161
|
tokens.length = index + 1;
|
|
162
|
-
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.
|
|
162
|
+
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, arena.resolveString(arena.stringValue[tokens[index]]) + "()")?.[0]?.chi, createValidationContext(arena, arena.tokens(tokens[index])), options);
|
|
163
163
|
stack.pop();
|
|
164
164
|
scopes.pop();
|
|
165
165
|
currentScope = scopes.at(-1);
|
|
@@ -189,7 +189,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
189
189
|
const names = trimArray(arena, tokens.slice(index2 + 1, index));
|
|
190
190
|
const filteredNames = names.filter((n) => arena.dataTypes[n] !== EnumToken.WhitespaceTokenType &&
|
|
191
191
|
arena.dataTypes[n] !== EnumToken.CommentTokenType);
|
|
192
|
-
const name = arena.
|
|
192
|
+
const name = arena.resolveString(arena.stringValue[filteredNames[0]]);
|
|
193
193
|
const mfInfo = getMFInfo(name);
|
|
194
194
|
for (const val of [left, right]) {
|
|
195
195
|
if (options.computeCalcExpression) {
|
|
@@ -198,7 +198,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
198
198
|
mfInfo.type !== MediaFeatureType.StringType)) {
|
|
199
199
|
for (let l = 0; l < val.length; l++) {
|
|
200
200
|
if (arena.dataTypes[val[l]] === EnumToken.MathFunctionTokenType &&
|
|
201
|
-
arena.
|
|
201
|
+
arena.resolveString(arena.stringValue[val[l]]) === "calc") {
|
|
202
202
|
const value = evaluate(arena, [val[l]]);
|
|
203
203
|
if (value.length === 1) {
|
|
204
204
|
arena.copyLocation(value[0], val[l]);
|
|
@@ -259,7 +259,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
259
259
|
let values = trimArray(arena, tokens.slice(index2 + 1, tokens.length - 1));
|
|
260
260
|
const filteredNames = (names).filter((n) => arena.dataTypes[n] !== EnumToken.WhitespaceTokenType &&
|
|
261
261
|
arena.dataTypes[n] !== EnumToken.CommentTokenType);
|
|
262
|
-
const name = arena.
|
|
262
|
+
const name = arena.resolveString(arena.stringValue[filteredNames[0]]);
|
|
263
263
|
const mfInfo = getMFInfo(name);
|
|
264
264
|
if (options.computeCalcExpression) {
|
|
265
265
|
if (mfInfo == null ||
|
|
@@ -268,7 +268,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
268
268
|
const val = values;
|
|
269
269
|
for (let l = 0; l < val.length; l++) {
|
|
270
270
|
if (arena.dataTypes[val[l]] === EnumToken.MathFunctionTokenType &&
|
|
271
|
-
arena.
|
|
271
|
+
arena.resolveString(arena.stringValue[val[l]]) === "calc") {
|
|
272
272
|
const value = evaluate(arena, [val[l]]);
|
|
273
273
|
if (value.length === 1) {
|
|
274
274
|
arena.copyLocation(value[0], val[l]);
|
|
@@ -416,7 +416,7 @@ function parseMediaqueryList(arena, stream, options) {
|
|
|
416
416
|
arena.dataTypes[rightNames[0]] === EnumToken.IdenTokenType &&
|
|
417
417
|
(arena.dataTypes[rightOp] === EnumToken.LtTokenType ||
|
|
418
418
|
arena.dataTypes[rightOp] === EnumToken.LteTokenType) &&
|
|
419
|
-
equalsIgnoreCase(arena.
|
|
419
|
+
equalsIgnoreCase(arena.resolveString(arena.stringValue[leftNames[0]]), arena.resolveString(arena.stringValue[rightNames[0]]))) {
|
|
420
420
|
const rangeQuery = arena.createToken(EnumToken.MediaRangeQueryTokenType);
|
|
421
421
|
arena.dataTypes[leftOp] =
|
|
422
422
|
arena.dataTypes[leftOp] === EnumToken.GteTokenType
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../../ast/types.js';
|
|
9
|
-
import { pseudoElements, tokensfuncDefMap } from '../../syntax/constants.js';
|
|
9
|
+
import { pseudoElements, isFunctionDefType, tokensfuncDefMap } from '../../syntax/constants.js';
|
|
10
10
|
import { getSyntaxConfig, getParsedSyntax } from '../../validation/config.js';
|
|
11
11
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
12
12
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
@@ -35,7 +35,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
35
35
|
tokens.push(stream[i]);
|
|
36
36
|
if (arena.dataTypes[stream[i]] === EnumToken.ColonTokenType) {
|
|
37
37
|
if (arena.dataTypes[stream[i + 1]] === EnumToken.IdenTokenType) {
|
|
38
|
-
const val = arena.
|
|
38
|
+
const val = arena.resolveString(arena.stringValue[stream[i + 1]]);
|
|
39
39
|
arena.dataTypes[stream[i]] = pseudoElements.includes(val)
|
|
40
40
|
? EnumToken.PseudoElementTokenType
|
|
41
41
|
: EnumToken.PseudoClassTokenType;
|
|
@@ -47,7 +47,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
49
|
if (arena.dataTypes[stream[i + 1]] === EnumToken.FunctionTokenDefType) {
|
|
50
|
-
val = ":" + arena.
|
|
50
|
+
val = ":" + arena.resolveString(arena.stringValue[stream[i + 1]]);
|
|
51
51
|
arena.dataTypes[stream[i]] =
|
|
52
52
|
val + "()" in getSyntaxConfig().selectors
|
|
53
53
|
? EnumToken.PseudoClassFunctionTokenDefType
|
|
@@ -82,7 +82,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
82
82
|
expectAndOr = false;
|
|
83
83
|
}
|
|
84
84
|
if (arena.dataTypes[stream[i]] === EnumToken.StartParensTokenType ||
|
|
85
|
-
|
|
85
|
+
isFunctionDefType(arena.dataTypes[stream[i]])) {
|
|
86
86
|
scopes.push((scope = new Set()));
|
|
87
87
|
stack.push(stream[i]);
|
|
88
88
|
continue;
|
|
@@ -114,7 +114,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
114
114
|
scope = scopes[scopes.length - 1];
|
|
115
115
|
expectAndOr = true;
|
|
116
116
|
}
|
|
117
|
-
else if (stack.length > 0 &&
|
|
117
|
+
else if (stack.length > 0 && isFunctionDefType(arena.dataTypes[stack[stack.length - 1]])) {
|
|
118
118
|
const func = stack[stack.length - 1];
|
|
119
119
|
const index = tokens.indexOf(func);
|
|
120
120
|
arena.dataTypes[func] = tokensfuncDefMap.get(arena.dataTypes[func]);
|
|
@@ -122,7 +122,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
122
122
|
arena.spanLocation(func, func, stream[i]);
|
|
123
123
|
if (arena.dataTypes[tokens[index]] === EnumToken.PseudoClassFuncTokenType) {
|
|
124
124
|
// not a declaration
|
|
125
|
-
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.
|
|
125
|
+
const result = matchAllSyntaxes(arena, getParsedSyntax(ValidationSyntaxGroupEnum.Selectors, arena.resolveString(arena.stringValue[tokens[index]]) + "()")?.[0]?.chi, createValidationContext(arena, arena.tokens(tokens[index])), options);
|
|
126
126
|
if (!result.success) {
|
|
127
127
|
return {
|
|
128
128
|
success: false,
|
|
@@ -133,11 +133,6 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
133
133
|
tokens.pop();
|
|
134
134
|
break;
|
|
135
135
|
}
|
|
136
|
-
//
|
|
137
|
-
let k = stack.length - 1;
|
|
138
|
-
while (tokensfuncDefMap.has(arena.dataTypes[stack[k]])) {
|
|
139
|
-
k--;
|
|
140
|
-
}
|
|
141
136
|
stack.pop();
|
|
142
137
|
tokens.pop();
|
|
143
138
|
scopes.pop();
|
|
@@ -182,7 +177,7 @@ function parseAtRuleSupportSyntax(arena, stream, context, options = {}) {
|
|
|
182
177
|
break;
|
|
183
178
|
case EnumToken.IdenTokenType:
|
|
184
179
|
{
|
|
185
|
-
const val = arena.
|
|
180
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
186
181
|
if ("not" === val) {
|
|
187
182
|
stack.push(stream[i]);
|
|
188
183
|
arena.dataTypes[stream[i]] = EnumToken.NotTokenType;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../../ast/arena.js';
|
|
9
9
|
import { EnumToken } from '../../ast/types.js';
|
|
10
10
|
import { trimArray } from '../../validation/match.js';
|
|
11
|
-
import { tokensfuncDefMap } from '../../syntax/constants.js';
|
|
11
|
+
import { tokensfuncDefMap, isFunctionDefType } from '../../syntax/constants.js';
|
|
12
12
|
import { parseMediaqueryList } from './at-rule-media.js';
|
|
13
13
|
import { parseAtRuleSupportSyntax } from './at-rule-support.js';
|
|
14
14
|
|
|
@@ -36,7 +36,7 @@ function matchAtRuleWhenElseSyntax(arena, stream, context, options = {}) {
|
|
|
36
36
|
switch (arena.dataTypes[stream[i]]) {
|
|
37
37
|
case EnumToken.IdenTokenType:
|
|
38
38
|
{
|
|
39
|
-
const val = arena.
|
|
39
|
+
const val = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
40
40
|
if ("and" === val || "or" === val) {
|
|
41
41
|
arena.dataTypes[stream[i]] = "or" === val ? EnumToken.OrTokenType : EnumToken.AndTokenType;
|
|
42
42
|
// scope.add(arena.dataTypes[stream[i]]);
|
|
@@ -58,12 +58,12 @@ function matchAtRuleWhenElseSyntax(arena, stream, context, options = {}) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
else if (arena.dataTypes[stream[j]] === EnumToken.StartParensTokenType ||
|
|
61
|
-
|
|
61
|
+
isFunctionDefType(arena.dataTypes[stream[j]])) {
|
|
62
62
|
matchCount++;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
const slice = stream.slice(i, j + 1);
|
|
66
|
-
const funcName = arena.
|
|
66
|
+
const funcName = arena.resolveString(arena.stringValue[stream[i]]).toLowerCase();
|
|
67
67
|
// the function token may be converted by the sub parsers
|
|
68
68
|
const isSupportsFunction = arena.dataTypes[stream[i]] === EnumToken.SupportsFunctionTokenDefType;
|
|
69
69
|
const funcType = tokensfuncDefMap.get(arena.dataTypes[stream[i]]);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
CSS parser, minifier and validator for node and the browser
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version: 2.
|
|
5
|
+
Version: 2.2.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
@@ -10,7 +10,7 @@ import { getSyntaxRule } from '../../validation/config.js';
|
|
|
10
10
|
import { trimArray, matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
|
|
11
11
|
|
|
12
12
|
function matchAtRuleSyntax(arena, atRule, stream, options) {
|
|
13
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.
|
|
13
|
+
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + arena.resolveString(arena.name[atRule]));
|
|
14
14
|
const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
|
|
15
15
|
trimArray(arena, stream);
|
|
16
16
|
if (syntax.length === 0) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
CSS parser, minifier and validator for node, deno, bun and the browser
|
|
3
|
+
|
|
4
|
+
Author(s): Thierry Bela
|
|
5
|
+
Version: 2.2.0
|
|
6
|
+
License: MIT
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* memoize a function by its arguments (compared with `Map` semantics). the `null` and `undefined` results are cached
|
|
10
|
+
* too: an unknown name is looked up once
|
|
11
|
+
* @param fn
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
function memoize(fn) {
|
|
15
|
+
const buckets = new Map();
|
|
16
|
+
return function (...args) {
|
|
17
|
+
const n = args.length;
|
|
18
|
+
let bucket = buckets.get(n);
|
|
19
|
+
if (bucket == null) {
|
|
20
|
+
bucket = new Map();
|
|
21
|
+
buckets.set(n, bucket);
|
|
22
|
+
}
|
|
23
|
+
if (n === 1) {
|
|
24
|
+
const key = args[0];
|
|
25
|
+
let value = bucket.get(key);
|
|
26
|
+
if (value === undefined && !bucket.has(key)) {
|
|
27
|
+
value = fn(key);
|
|
28
|
+
bucket.set(key, value);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
// the maps of the first arguments, then the results by last argument
|
|
33
|
+
let node = bucket;
|
|
34
|
+
for (let i = 0; i < n - 1; i++) {
|
|
35
|
+
const key = args[i];
|
|
36
|
+
let next = node.get(key);
|
|
37
|
+
if (next == null) {
|
|
38
|
+
next = new Map();
|
|
39
|
+
node.set(key, next);
|
|
40
|
+
}
|
|
41
|
+
node = next;
|
|
42
|
+
}
|
|
43
|
+
const last = n === 0 ? undefined : args[n - 1];
|
|
44
|
+
let value = node.get(last);
|
|
45
|
+
if (value === undefined && !node.has(last)) {
|
|
46
|
+
value = fn(...args);
|
|
47
|
+
node.set(last, value);
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { memoize };
|