@tbela99/css-parser 2.2.0 → 2.3.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 +24 -0
- package/dist/{lib/ast → ast}/arena-node.js +1 -1
- package/dist/{lib/ast → ast}/arena.js +1 -1
- package/dist/{lib/ast → ast}/cache.js +39 -23
- package/dist/{lib/ast → ast}/features/calc.js +1 -1
- package/dist/{lib/ast → ast}/features/if.js +1 -1
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{lib/ast → ast}/features/index.js +1 -1
- package/dist/{lib/ast → ast}/features/inlinecssvariables.js +1 -1
- package/dist/{lib/ast → ast}/features/mixin.js +1 -1
- package/dist/{lib/ast → ast}/features/prefix.js +1 -1
- package/dist/{lib/ast → ast}/features/shorthand.js +1 -1
- package/dist/{lib/ast → ast}/features/transform.js +1 -1
- package/dist/{lib/ast → ast}/features/type.js +1 -1
- package/dist/{lib/ast → ast}/math/expression.js +1 -1
- package/dist/{lib/ast → ast}/math/math.js +1 -1
- package/dist/{lib/ast → ast}/minify.js +1 -1
- package/dist/{lib/ast → ast}/mixins/custom-function.js +1 -1
- package/dist/{lib/ast → ast}/mixins/utils.js +1 -1
- package/dist/{lib/ast → ast}/mixins/variables.js +1 -1
- package/dist/{lib/ast → ast}/strings.js +5 -1
- package/dist/{lib/ast → ast}/transform/compute.js +1 -1
- package/dist/{lib/ast → ast}/transform/matrix.js +1 -1
- package/dist/{lib/ast → ast}/transform/minify.js +1 -1
- package/dist/{lib/ast → ast}/transform/perspective.js +1 -1
- package/dist/{lib/ast → ast}/transform/rotate.js +1 -1
- package/dist/{lib/ast → ast}/transform/scale.js +1 -1
- package/dist/{lib/ast → ast}/transform/skew.js +1 -1
- package/dist/{lib/ast → ast}/transform/translate.js +1 -1
- package/dist/{lib/ast → ast}/transform/utils.js +1 -1
- package/dist/{lib/ast → ast}/types.js +1 -1
- package/dist/{lib/ast → ast}/walk.js +1 -1
- package/dist/data/properties.json.js +1 -1
- package/dist/data/validation.json.js +26 -20
- package/dist/{lib/fs → fs}/resolve.js +1 -1
- package/dist/index-umd-web.js +2755 -126
- package/dist/index.d.ts +6 -2
- package/dist/node.js +21 -21
- package/dist/{lib/parser → parser}/declaration/list.js +1 -1
- package/dist/{lib/parser → parser}/declaration/map.js +1 -1
- package/dist/{lib/parser → parser}/declaration/set.js +1 -1
- package/dist/{lib/parser → parser}/input.js +1 -1
- package/dist/{lib/parser → parser}/linesmap.js +1 -1
- package/dist/{lib/parser → parser}/parse.js +20 -21
- package/dist/{lib/parser → parser}/source.js +2 -2
- package/dist/{lib/parser → parser}/tokenize.js +1 -1
- package/dist/{lib/parser → parser}/utils/angle.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-container.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-font-feature-values.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-generic.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-import.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-media.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-support.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule-when-else.js +1 -1
- package/dist/{lib/parser → parser}/utils/at-rule.js +1 -1
- package/dist/{lib/parser → parser}/utils/base64.js +1 -1
- package/dist/{lib/parser → parser}/utils/cache.js +1 -1
- package/dist/{lib/parser → parser}/utils/canonical.js +1 -1
- package/dist/{lib/parser → parser}/utils/codes.js +1 -1
- package/dist/{lib/parser → parser}/utils/config.js +2 -2
- package/dist/{lib/parser → parser}/utils/declaration.js +1 -1
- package/dist/{lib/parser → parser}/utils/eq.js +1 -1
- package/dist/{lib/parser → parser}/utils/hash.js +1 -1
- package/dist/{lib/parser → parser}/utils/selector.js +38 -28
- package/dist/{lib/parser → parser}/utils/text.js +1 -1
- package/dist/{lib/parser → parser}/utils/token.js +1 -1
- package/dist/{lib/parser → parser}/utils/type.js +1 -1
- package/dist/{lib/printer/sourcemap → printer}/lib/codec.js +1 -1
- package/dist/{lib/printer → printer}/render.js +184 -23
- package/dist/{lib/printer → printer}/result.js +1 -1
- package/dist/{lib/printer/sourcemap → printer}/sourcemap.js +3 -2
- package/dist/{lib/printer → printer}/writer.js +1 -1
- package/dist/{lib/syntax → syntax}/color/a98rgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/alpha.js +1 -1
- package/dist/{lib/syntax → syntax}/color/cmyk.js +1 -1
- package/dist/{lib/syntax → syntax}/color/color-mix.js +1 -1
- package/dist/{lib/syntax → syntax}/color/color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hex.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hsl.js +1 -1
- package/dist/{lib/syntax → syntax}/color/hwb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/lab.js +1 -1
- package/dist/{lib/syntax → syntax}/color/lch.js +1 -1
- package/dist/{lib/syntax → syntax}/color/oklab.js +1 -1
- package/dist/{lib/syntax → syntax}/color/oklch.js +1 -1
- package/dist/{lib/syntax → syntax}/color/p3.js +1 -1
- package/dist/{lib/syntax → syntax}/color/prophotorgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/rec2020.js +1 -1
- package/dist/{lib/syntax → syntax}/color/relative-color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/rgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/srgb.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/color-type.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/colorspace.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/components.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/distance.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/make-color.js +1 -1
- package/dist/{lib/syntax → syntax}/color/utils/matrix.js +1 -1
- package/dist/{lib/syntax → syntax}/color/xyz.js +1 -1
- package/dist/{lib/syntax → syntax}/color/xyzd50.js +1 -1
- package/dist/{lib/syntax → syntax}/constants.js +2 -2
- package/dist/{lib/syntax → syntax}/syntax.js +1 -1
- package/dist/types.js +1 -1
- package/dist/utils/sync.js +3 -3
- package/dist/validation/compiled/builtins.js +32 -0
- package/dist/validation/compiled/runtime.js +705 -0
- package/dist/validation/compiled/syntaxes.js +1620 -0
- package/dist/{lib/validation → validation}/config.js +41 -7
- package/dist/{lib/validation → validation}/first.js +6 -3
- package/dist/{lib/validation → validation}/match.js +87 -14
- package/dist/{lib/validation → validation}/parser/parse.js +1 -1
- package/dist/{lib/validation → validation}/parser/typedef.js +1 -1
- package/dist/{lib/validation → validation}/utils/list.js +1 -1
- package/dist/version.js +2 -2
- package/dist/web.js +23 -23
- package/package.json +4 -2
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
- package/dist/version.d.ts +0 -4
|
@@ -2,10 +2,10 @@
|
|
|
2
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
import config from '
|
|
8
|
+
import config from '../data/validation.json.js';
|
|
9
9
|
import { trimSyntaxArray, parseSyntax } from './parser/parse.js';
|
|
10
10
|
import { ValidationTokenEnum, ValidationSyntaxGroupEnum } from './parser/typedef.js';
|
|
11
11
|
import { memoize } from '../parser/utils/cache.js';
|
|
@@ -17,7 +17,7 @@ import { memoize } from '../parser/utils/cache.js';
|
|
|
17
17
|
const parsedSyntaxes = new WeakMap();
|
|
18
18
|
Object.freeze(config);
|
|
19
19
|
function getSyntaxConfig() {
|
|
20
|
-
// @ts-
|
|
20
|
+
// @ts-ignore
|
|
21
21
|
return config;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -90,7 +90,7 @@ function findNode(group, key) {
|
|
|
90
90
|
return obj;
|
|
91
91
|
}
|
|
92
92
|
const getParsedSyntax = memoize((group, key) => {
|
|
93
|
-
// @ts-
|
|
93
|
+
// @ts-ignore
|
|
94
94
|
const obj = findNode(group, key);
|
|
95
95
|
if (obj == null) {
|
|
96
96
|
return null;
|
|
@@ -99,9 +99,43 @@ const getParsedSyntax = memoize((group, key) => {
|
|
|
99
99
|
if (syntax === undefined) {
|
|
100
100
|
syntax = Object.freeze(trimSyntaxArray(parseSyntax(obj.syntax)));
|
|
101
101
|
parsedSyntaxes.set(obj, syntax);
|
|
102
|
+
syntaxNodes.set(syntax, obj);
|
|
102
103
|
}
|
|
103
104
|
return syntax;
|
|
104
105
|
});
|
|
106
|
+
/**
|
|
107
|
+
* the definition node of a parsed syntax, see {@link syntaxKey}
|
|
108
|
+
*/
|
|
109
|
+
const syntaxNodes = new WeakMap();
|
|
110
|
+
/**
|
|
111
|
+
* the key of the definitions that are compiled (`group/name`, see scripts/compile-syntax.ts), by definition node
|
|
112
|
+
*/
|
|
113
|
+
let nodeKeys = null;
|
|
114
|
+
/**
|
|
115
|
+
* the key of the definition of a parsed syntax (`declarations/width`, `types/color`), see scripts/compile-syntax.ts.
|
|
116
|
+
* null if the syntax is not the syntax of a declaration, a type or a function (a descriptor, ...)
|
|
117
|
+
* @param syntaxes a syntax returned by {@link getParsedSyntax}
|
|
118
|
+
*/
|
|
119
|
+
function syntaxKey(syntaxes) {
|
|
120
|
+
const node = syntaxNodes.get(syntaxes);
|
|
121
|
+
if (node === undefined) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (nodeKeys === null) {
|
|
125
|
+
nodeKeys = new Map();
|
|
126
|
+
const groups = config;
|
|
127
|
+
for (const group of [
|
|
128
|
+
ValidationSyntaxGroupEnum.Declarations,
|
|
129
|
+
ValidationSyntaxGroupEnum.Syntaxes,
|
|
130
|
+
ValidationSyntaxGroupEnum.Types,
|
|
131
|
+
]) {
|
|
132
|
+
for (const [key, value] of Object.entries(groups[group] ?? {})) {
|
|
133
|
+
nodeKeys.set(value, group + "/" + key);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return nodeKeys.get(node) ?? null;
|
|
138
|
+
}
|
|
105
139
|
const getSyntaxRule = memoize((group, key) => {
|
|
106
140
|
const node = findNode(group, key);
|
|
107
141
|
if (node == null) {
|
|
@@ -133,10 +167,10 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
133
167
|
let block = blockStart === -1 ? null : trimSyntaxArray(syntaxRules.slice(blockStart + 1, blockEnd));
|
|
134
168
|
let prelude = trimSyntaxArray(blockStart === -1 ? syntaxRules.slice() : syntaxRules.slice(0, blockStart));
|
|
135
169
|
let propertyDescriptors = null;
|
|
136
|
-
// @ts-
|
|
170
|
+
// @ts-ignore
|
|
137
171
|
if (node.descriptors != null) {
|
|
138
172
|
propertyDescriptors = {};
|
|
139
|
-
// @ts-
|
|
173
|
+
// @ts-ignore
|
|
140
174
|
for (const [key, value] of Object.entries(node.descriptors)) {
|
|
141
175
|
// @ts-expect-error
|
|
142
176
|
propertyDescriptors[key] = parseSyntax(typeof value === "string" ? value : value.syntax);
|
|
@@ -170,4 +204,4 @@ const getSyntaxRule = memoize((group, key) => {
|
|
|
170
204
|
};
|
|
171
205
|
});
|
|
172
206
|
|
|
173
|
-
export { getParsedSyntax, getSyntax, getSyntaxConfig, getSyntaxRule, hasSyntax };
|
|
207
|
+
export { getParsedSyntax, getSyntax, getSyntaxConfig, getSyntaxRule, hasSyntax, syntaxKey };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../ast/types.js';
|
|
@@ -396,8 +396,8 @@ function firstOf(syntax) {
|
|
|
396
396
|
*/
|
|
397
397
|
const cssWideKeywords = getSyntaxConfig().declarations.all.syntax.split(/[\s|]+/g);
|
|
398
398
|
/**
|
|
399
|
-
* the token may match a syntax that does not accept its type (`var()`, `env()`, `attr()`, the
|
|
400
|
-
* wide keywords, ...): the first token sets do not apply
|
|
399
|
+
* the token may match a syntax that does not accept its type (`var()`, `env()`, `attr()`, the custom function calls,
|
|
400
|
+
* the math functions, the css wide keywords, ...): the first token sets do not apply
|
|
401
401
|
* @param arena
|
|
402
402
|
* @param token
|
|
403
403
|
* @param typ
|
|
@@ -408,6 +408,9 @@ function matchesAnySyntax(arena, token, typ) {
|
|
|
408
408
|
case EnumToken.WildCardFunctionTokenDefType:
|
|
409
409
|
case EnumToken.MathFunctionTokenType:
|
|
410
410
|
case EnumToken.MathFunctionTokenDefType:
|
|
411
|
+
// a custom function call is substituted by its result, like var()
|
|
412
|
+
case EnumToken.CustomFunctionTokenType:
|
|
413
|
+
case EnumToken.CustomFunctionTokenDefType:
|
|
411
414
|
return true;
|
|
412
415
|
case EnumToken.IdenTokenType: {
|
|
413
416
|
const value = arena.resolveString(arena.stringValue[token]);
|
|
@@ -2,18 +2,19 @@
|
|
|
2
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { TokenField } from '../ast/arena.js';
|
|
9
|
-
import { getParsedSyntax, hasSyntax, getSyntax, getSyntaxConfig } from './config.js';
|
|
9
|
+
import { syntaxKey, getParsedSyntax, hasSyntax, getSyntax, getSyntaxConfig } from './config.js';
|
|
10
10
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
11
|
-
import {
|
|
11
|
+
import { ValidationTokenEnum, ValidationSyntaxGroupEnum, MediaFeatureType } from './parser/typedef.js';
|
|
12
12
|
import { isFunctionDefType, isFunctionType, funcLike, tokensfuncDefMap, mFLT, mFGT } from '../syntax/constants.js';
|
|
13
13
|
import { isColor } from '../syntax/syntax.js';
|
|
14
14
|
import { equalsIgnoreCase, lowercase } from '../parser/utils/text.js';
|
|
15
15
|
import { parseTokens } from '../parser/parse.js';
|
|
16
16
|
import { matchingAlternatives, isNullable, mayStartWith } from './first.js';
|
|
17
|
+
import { compiledMatcher, matchCompiled } from './compiled/runtime.js';
|
|
17
18
|
|
|
18
19
|
const config = getSyntaxConfig();
|
|
19
20
|
// @ts-expect-error
|
|
@@ -381,9 +382,9 @@ class ValidationTokenContext {
|
|
|
381
382
|
* @param tokens
|
|
382
383
|
* @returns
|
|
383
384
|
*/
|
|
384
|
-
function createValidationContext(arena, tokens) {
|
|
385
|
+
function createValidationContext(arena, tokens, start = 0, end = tokens.length) {
|
|
385
386
|
const filtered = [];
|
|
386
|
-
for (let i = 0; i <
|
|
387
|
+
for (let i = Math.max(0, start); i < end; i++) {
|
|
387
388
|
if (arena.dataTypes[tokens[i]] !== EnumToken.CommentTokenType) {
|
|
388
389
|
filtered.push(tokens[i]);
|
|
389
390
|
}
|
|
@@ -682,7 +683,9 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
|
|
|
682
683
|
arena.dataTypes[stack.at(-1)] === EnumToken.PseudoElementTokenType) {
|
|
683
684
|
const token = stack.at(-1);
|
|
684
685
|
const index = tokens.indexOf(token);
|
|
685
|
-
|
|
686
|
+
// the syntax is looked up once per function name, the tokens are read in place
|
|
687
|
+
const result = matchAllSyntaxes(arena, selectorFunctionSyntax(arena, token)?.[0]
|
|
688
|
+
?.chi ?? [], createValidationContext(arena, tokens, index + 1, tokens.length - 1), options);
|
|
686
689
|
if (!result.success) {
|
|
687
690
|
success = false;
|
|
688
691
|
if (result.errors.length > 0) {
|
|
@@ -766,10 +769,12 @@ function matchSelectorSyntax(arena, stream, errors, options, nested = true) {
|
|
|
766
769
|
],
|
|
767
770
|
};
|
|
768
771
|
}
|
|
769
|
-
stream.length = 0
|
|
772
|
+
// the tokens are written in place: the stream has at least as many tokens. `stream.length = 0` would release its
|
|
773
|
+
// backing store, the pushes would allocate it again
|
|
770
774
|
for (let i = 0; i < tokens.length; i++) {
|
|
771
|
-
stream
|
|
775
|
+
stream[i] = tokens[i];
|
|
772
776
|
}
|
|
777
|
+
stream.length = tokens.length;
|
|
773
778
|
return { success, errors };
|
|
774
779
|
}
|
|
775
780
|
/**
|
|
@@ -838,6 +843,10 @@ const cachedValidMatch = Object.freeze({
|
|
|
838
843
|
let encoding = new Float64Array(512);
|
|
839
844
|
let encodingLength = 0;
|
|
840
845
|
let encodingHash = 0;
|
|
846
|
+
/**
|
|
847
|
+
* true if the encoded value contains a token the compiled matchers do not handle (var(), a custom function call, ...): the interpreter validates the value, see {@link compiledVerdict}
|
|
848
|
+
*/
|
|
849
|
+
let encodingBail = false;
|
|
841
850
|
/**
|
|
842
851
|
* append a value to the encoding and update its hash
|
|
843
852
|
* @param value
|
|
@@ -860,6 +869,15 @@ function encode(value) {
|
|
|
860
869
|
*/
|
|
861
870
|
function encodeToken(arena, token) {
|
|
862
871
|
const typ = arena.dataTypes[token];
|
|
872
|
+
if (typ === EnumToken.WildCardFunctionTokenType ||
|
|
873
|
+
typ === EnumToken.WildCardFunctionTokenDefType ||
|
|
874
|
+
typ === EnumToken.CustomFunctionTokenType ||
|
|
875
|
+
typ === EnumToken.CustomFunctionTokenDefType ||
|
|
876
|
+
typ === EnumToken.BadCdoTokenType ||
|
|
877
|
+
typ === EnumToken.BadCommentTokenType ||
|
|
878
|
+
typ === EnumToken.BadStringTokenType) {
|
|
879
|
+
encodingBail = true;
|
|
880
|
+
}
|
|
863
881
|
encode(typ);
|
|
864
882
|
encode(arena.name[token]);
|
|
865
883
|
// the validation does not read the content of the strings (only their type): `content: "\f101"` and
|
|
@@ -1060,6 +1078,36 @@ function valueTokens(arena, tokens) {
|
|
|
1060
1078
|
}
|
|
1061
1079
|
return result;
|
|
1062
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* the compiled matchers of the syntaxes, null when the syntaxes are not compiled
|
|
1083
|
+
*/
|
|
1084
|
+
const compiledMatchers = new WeakMap();
|
|
1085
|
+
/**
|
|
1086
|
+
* true if the value is valid according to the compiled matcher of the syntax. false: the interpreter must validate it
|
|
1087
|
+
* (the value may be valid). the value must be encoded (see {@link encodeToken})
|
|
1088
|
+
* @param arena
|
|
1089
|
+
* @param syntaxes
|
|
1090
|
+
* @param tokens
|
|
1091
|
+
* @param options
|
|
1092
|
+
*/
|
|
1093
|
+
function compiledVerdict(arena, syntaxes, tokens, options) {
|
|
1094
|
+
if (encodingBail) {
|
|
1095
|
+
return false;
|
|
1096
|
+
}
|
|
1097
|
+
let matcher = compiledMatchers.get(syntaxes);
|
|
1098
|
+
if (matcher === undefined) {
|
|
1099
|
+
const key = syntaxKey(syntaxes);
|
|
1100
|
+
matcher = key === null ? null : compiledMatcher(key);
|
|
1101
|
+
compiledMatchers.set(syntaxes, matcher);
|
|
1102
|
+
}
|
|
1103
|
+
if (matcher === null) {
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
if (!matchCompiled(arena, matcher, tokens, options)) {
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1063
1111
|
/**
|
|
1064
1112
|
* validate the value of a declaration. a value that has already been validated for the same syntax in the same arena
|
|
1065
1113
|
* (same encoding, see {@link encodeToken}) is not validated again: `width: 10px` is validated once, whatever the number
|
|
@@ -1072,10 +1120,15 @@ function valueTokens(arena, tokens) {
|
|
|
1072
1120
|
function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
|
|
1073
1121
|
encodingLength = 0;
|
|
1074
1122
|
encodingHash = 0x811c9dc5;
|
|
1123
|
+
encodingBail = false;
|
|
1075
1124
|
for (let i = 0; i < tokens.length; i++) {
|
|
1076
1125
|
encodeToken(arena, tokens[i]);
|
|
1077
1126
|
}
|
|
1078
1127
|
const cached = findValidation(arena, syntaxes);
|
|
1128
|
+
if (cached == null && compiledVerdict(arena, syntaxes, tokens, options)) {
|
|
1129
|
+
cacheValidation(arena, syntaxes, storeEncoding(arena), encodingLength, encodingHash, true, null);
|
|
1130
|
+
return cachedValidMatch;
|
|
1131
|
+
}
|
|
1079
1132
|
if (cached != null) {
|
|
1080
1133
|
if (cached.valid) {
|
|
1081
1134
|
return cachedValidMatch;
|
|
@@ -1123,6 +1176,7 @@ function matchDeclarationSyntax(arena, syntaxes, tokens, options) {
|
|
|
1123
1176
|
function isValidDeclarationValue(arena, syntaxes, declaration, options) {
|
|
1124
1177
|
encodingLength = 0;
|
|
1125
1178
|
encodingHash = 0x811c9dc5;
|
|
1179
|
+
encodingBail = false;
|
|
1126
1180
|
for (let token = arena.firstToken[declaration]; token !== 0; token = arena.nextSibling[token]) {
|
|
1127
1181
|
encodeToken(arena, token);
|
|
1128
1182
|
}
|
|
@@ -1130,6 +1184,10 @@ function isValidDeclarationValue(arena, syntaxes, declaration, options) {
|
|
|
1130
1184
|
if (cached != null) {
|
|
1131
1185
|
return cached.valid;
|
|
1132
1186
|
}
|
|
1187
|
+
if (compiledVerdict(arena, syntaxes, arena.tokens(declaration), options)) {
|
|
1188
|
+
cacheValidation(arena, syntaxes, storeEncoding(arena), encodingLength, encodingHash, true, null);
|
|
1189
|
+
return true;
|
|
1190
|
+
}
|
|
1133
1191
|
// the encoding is stored before the validation, which may encode other values
|
|
1134
1192
|
const length = encodingLength;
|
|
1135
1193
|
const offset = storeEncoding(arena);
|
|
@@ -1495,7 +1553,7 @@ function selectorFunctionSyntax(arena, token) {
|
|
|
1495
1553
|
*/
|
|
1496
1554
|
const wildCardProbes = new Map();
|
|
1497
1555
|
/**
|
|
1498
|
-
* var(), env()
|
|
1556
|
+
* var(), env(), if() and the custom function calls may be substituted by any number of values. the function is matched:
|
|
1499
1557
|
* - as a part of the syntax at index: `var(--color) 65%` is matched by `<linear-color-stop>` (`<color>` is the function)
|
|
1500
1558
|
* - as the syntax at index, or as all the remaining syntaxes when it is the last token
|
|
1501
1559
|
*
|
|
@@ -1655,12 +1713,27 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
|
|
|
1655
1713
|
return wildCardResult;
|
|
1656
1714
|
}
|
|
1657
1715
|
}
|
|
1716
|
+
// a custom function call (`--fn()`) is substituted by the result of the function: like var(), it may be
|
|
1717
|
+
// substituted by any number of values
|
|
1718
|
+
if ((arena.dataTypes[token] === EnumToken.CustomFunctionTokenType ||
|
|
1719
|
+
arena.dataTypes[token] === EnumToken.CustomFunctionTokenDefType) &&
|
|
1720
|
+
wildCardProbes.get(token) !== syntaxes[i]) {
|
|
1721
|
+
const wildCardResult = matchWildCardFunction(arena, syntaxes, i, context, token,
|
|
1722
|
+
// the arguments of the call are not validated: they are the arguments of the custom function
|
|
1723
|
+
arena.dataTypes[token] === EnumToken.CustomFunctionTokenDefType
|
|
1724
|
+
? trimArray(arena, context.peekRange()).at(-1)
|
|
1725
|
+
: token, options, out);
|
|
1726
|
+
if (wildCardResult == null) {
|
|
1727
|
+
continue;
|
|
1728
|
+
}
|
|
1729
|
+
return wildCardResult;
|
|
1730
|
+
}
|
|
1658
1731
|
if (
|
|
1659
1732
|
// @ts-ignore
|
|
1660
1733
|
arena.dataTypes[token] === EnumToken.WildCardFunctionTokenDefType &&
|
|
1661
1734
|
wildCardProbes.get(token) !== syntaxes[i]) {
|
|
1662
1735
|
const range = trimArray(arena, context.peekRange());
|
|
1663
|
-
result = matchSyntax(arena, functionSyntax(arena, token)?.[0]?.chi, createValidationContext(arena, range
|
|
1736
|
+
result = matchSyntax(arena, functionSyntax(arena, token)?.[0]?.chi, createValidationContext(arena, range, 1, range.length - 1), options, out);
|
|
1664
1737
|
if (result.success) {
|
|
1665
1738
|
const wildCardResult = matchWildCardFunction(arena, syntaxes, i, context, token, range.at(-1), options, out);
|
|
1666
1739
|
if (wildCardResult == null) {
|
|
@@ -1962,7 +2035,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
|
|
|
1962
2035
|
}
|
|
1963
2036
|
if (isFunctionDefType(arena.dataTypes[token])) {
|
|
1964
2037
|
const range = context.peekRange();
|
|
1965
|
-
result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, range
|
|
2038
|
+
result = matchSyntax(arena, syntaxes[i].chi, createValidationContext(arena, range, 1, range.length - 1), options, out);
|
|
1966
2039
|
if (result.success && result.context.done()) {
|
|
1967
2040
|
context.update(range.at(-1));
|
|
1968
2041
|
visitedSyntaxes[visit] = null;
|
|
@@ -2006,7 +2079,7 @@ function matchSyntax(arena, syntaxes, context, options, out = createMatch()) {
|
|
|
2006
2079
|
equalsIgnoreCase(arena.resolveString(arena.stringValue[token]), syntaxes[i].val)) {
|
|
2007
2080
|
if (isFunctionDefType(arena.dataTypes[token])) {
|
|
2008
2081
|
const children = trimArray(arena, context.peekRange());
|
|
2009
|
-
result = matchSyntax(arena, (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(arena, children
|
|
2082
|
+
result = matchSyntax(arena, (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, syntaxes[i].val + "()")?.[0]).chi ?? [], createValidationContext(arena, children, 1, children.length - 1), options, out);
|
|
2010
2083
|
if (result.success && result.context.done()) {
|
|
2011
2084
|
success = true;
|
|
2012
2085
|
visitedSyntaxes[visit] = null;
|
|
@@ -2285,7 +2358,7 @@ function matchProperty(arena, property, context, options) {
|
|
|
2285
2358
|
}
|
|
2286
2359
|
else {
|
|
2287
2360
|
const range = context.peekRange();
|
|
2288
|
-
result = matchSyntax(arena, syntax, createValidationContext(arena, range
|
|
2361
|
+
result = matchSyntax(arena, syntax, createValidationContext(arena, range, 1, range.length - 1), options);
|
|
2289
2362
|
if (result.success) {
|
|
2290
2363
|
context.update(range.at(-1));
|
|
2291
2364
|
return {
|
|
@@ -3103,4 +3176,4 @@ function matchRepeatableSyntax(arena, syntax, context, options) {
|
|
|
3103
3176
|
};
|
|
3104
3177
|
}
|
|
3105
3178
|
|
|
3106
|
-
export { createValidationContext, funcTypes, getMFInfo, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchSelectorSyntax, trimArray };
|
|
3179
|
+
export { ValidationTokenContext, createValidationContext, funcTypes, getMFInfo, isCssWideKeyword, isMFValue, isValidDeclarationValue, matchAllSyntaxes, matchDeclarationSyntax, matchOccurenceSyntax, matchProperty, matchSelectorSyntax, selectorFunctionSyntax, trimArray };
|
package/dist/version.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
9
|
* Version number
|
|
10
10
|
*/
|
|
11
|
-
const version = "2.
|
|
11
|
+
const version = "2.3.0";
|
|
12
12
|
|
|
13
13
|
export { version };
|
package/dist/web.js
CHANGED
|
@@ -2,31 +2,31 @@
|
|
|
2
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
import { doParse, doParseSync } from './
|
|
9
|
-
export { parseDeclarations, parseString } from './
|
|
10
|
-
import { doRender } from './
|
|
11
|
-
export { renderValue } from './
|
|
12
|
-
import { TransformResult, RenderResult } from './
|
|
13
|
-
import { ModuleScopeEnumOptions } from './
|
|
14
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './
|
|
15
|
-
import { createParseInfo, Tokenizer } from './
|
|
16
|
-
import { isCssInput } from './
|
|
17
|
-
import { matchUrl, resolve, dirname } from './
|
|
8
|
+
import { doParse, doParseSync } from './parser/parse.js';
|
|
9
|
+
export { parseDeclarations, parseString } from './parser/parse.js';
|
|
10
|
+
import { doRender } from './printer/render.js';
|
|
11
|
+
export { renderValue } from './printer/render.js';
|
|
12
|
+
import { TransformResult, RenderResult } from './printer/result.js';
|
|
13
|
+
import { ModuleScopeEnumOptions } from './ast/types.js';
|
|
14
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
15
|
+
import { createParseInfo, Tokenizer } from './parser/tokenize.js';
|
|
16
|
+
import { isCssInput } from './parser/input.js';
|
|
17
|
+
import { matchUrl, resolve, dirname } from './fs/resolve.js';
|
|
18
18
|
import { ResponseType } from './types.js';
|
|
19
|
-
import { SourceFile } from './
|
|
19
|
+
import { SourceFile } from './parser/source.js';
|
|
20
20
|
import { validateSyncArguments, parseResult } from './utils/sync.js';
|
|
21
|
-
export { minify } from './
|
|
22
|
-
export { convertColor } from './
|
|
23
|
-
export { isOkLabClose, okLabDistance } from './
|
|
24
|
-
export { Arena, AstArena, TokenField, arenaColumns } from './
|
|
25
|
-
export { ARENA, ARENAID, AstArenaNode } from './
|
|
26
|
-
export { PropertyList } from './
|
|
27
|
-
export { SourceMap } from './
|
|
28
|
-
export { FeatureWalkMode } from './
|
|
29
|
-
export { parseSyntax } from './
|
|
21
|
+
export { minify } from './ast/minify.js';
|
|
22
|
+
export { convertColor } from './syntax/color/color.js';
|
|
23
|
+
export { isOkLabClose, okLabDistance } from './syntax/color/utils/distance.js';
|
|
24
|
+
export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
|
|
25
|
+
export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
|
|
26
|
+
export { PropertyList } from './parser/declaration/list.js';
|
|
27
|
+
export { SourceMap } from './printer/sourcemap.js';
|
|
28
|
+
export { FeatureWalkMode } from './ast/features/type.js';
|
|
29
|
+
export { parseSyntax } from './validation/parser/parse.js';
|
|
30
30
|
export { version } from './version.js';
|
|
31
31
|
|
|
32
32
|
/**
|
|
@@ -272,7 +272,7 @@ async function parse(...args) {
|
|
|
272
272
|
return Promise.resolve((options.load != null
|
|
273
273
|
? options.load(file, "", options.asStream ?? false)
|
|
274
274
|
: // the default loader loads the file as an ArrayBuffer: the preferred input of the tokenizer
|
|
275
|
-
load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => parse(stream, { src:
|
|
275
|
+
load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => parse(stream, { src: file, ...options }));
|
|
276
276
|
}
|
|
277
277
|
else {
|
|
278
278
|
stream = input;
|
|
@@ -347,7 +347,7 @@ async function transform(...args) {
|
|
|
347
347
|
return Promise.resolve((options.load != null
|
|
348
348
|
? options.load(file, "", options.asStream ?? false)
|
|
349
349
|
: // the default loader loads the file as an ArrayBuffer: the preferred input of the tokenizer
|
|
350
|
-
load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => transform(stream, { src:
|
|
350
|
+
load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => transform(stream, { src: file, ...options }));
|
|
351
351
|
}
|
|
352
352
|
else {
|
|
353
353
|
stream = input;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser, minifier and validator for node, deno, bun and the browser",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/node.js",
|
|
7
7
|
"./node": "./dist/node.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"test:web-cov": "web-test-runner -x 'test/specs/code/*.js' --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage \"test/specs/web.spec.js\"",
|
|
25
25
|
"profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
|
|
26
26
|
"config-update": "esno scripts/shorthand.ts",
|
|
27
|
-
"syntax-update": "esno scripts/webref.ts",
|
|
27
|
+
"syntax-update": "esno scripts/webref.ts && npm run syntax-compile",
|
|
28
|
+
"syntax-compile": "esno scripts/compile-syntax.ts",
|
|
29
|
+
"syntax-verify": "esno scripts/verify-syntax.ts",
|
|
28
30
|
"debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
|
|
29
31
|
"debug:web": "web-test-runner \"./test/specs/web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
30
32
|
},
|
package/dist/types.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* response type
|
|
3
|
-
*/
|
|
4
|
-
export declare enum ResponseType {
|
|
5
|
-
/**
|
|
6
|
-
* return text
|
|
7
|
-
*/
|
|
8
|
-
Text = 0,
|
|
9
|
-
/**
|
|
10
|
-
* return a readable stream
|
|
11
|
-
*/
|
|
12
|
-
ReadableStream = 1,
|
|
13
|
-
/**
|
|
14
|
-
* return an arraybuffer
|
|
15
|
-
*/
|
|
16
|
-
ArrayBuffer = 2,
|
|
17
|
-
/**
|
|
18
|
-
* return a json object
|
|
19
|
-
*/
|
|
20
|
-
JSON = 3
|
|
21
|
-
}
|
package/dist/utils/sync.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ParseResult, ParserOptions, ParserSyncOptions } from "../@types/index.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* parse result. process input sourcemap
|
|
4
|
-
* @param result
|
|
5
|
-
* @param options
|
|
6
|
-
* @returns
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export declare function parseResult(result: ParseResult, options: ParserOptions): ParseResult;
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param options
|
|
13
|
-
* @param prefix
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
export declare function validateSyncArguments(options: ParserSyncOptions, prefix?: string): void;
|
package/dist/version.d.ts
DELETED