@tbela99/css-parser 2.2.0 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/README.md +24 -9
- 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 +2770 -128
- package/dist/index.d.ts +21 -4
- 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 +16 -3
- 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
package/dist/index.d.ts
CHANGED
|
@@ -1312,7 +1312,11 @@ declare const enum StringDerived {
|
|
|
1312
1312
|
/**
|
|
1313
1313
|
* the kind of a transform function name or of a transform property name (see `transformKind()`)
|
|
1314
1314
|
*/
|
|
1315
|
-
TransformKind = 2
|
|
1315
|
+
TransformKind = 2,
|
|
1316
|
+
/**
|
|
1317
|
+
* true if the rules are allowed in the block of an at-rule (by name, without `@`), see `parseSelector()`
|
|
1318
|
+
*/
|
|
1319
|
+
AtRuleAcceptsRules = 3
|
|
1316
1320
|
}
|
|
1317
1321
|
/**
|
|
1318
1322
|
* structured-cloneable copy of a string table, see {@link StringTable.export}
|
|
@@ -7014,7 +7018,16 @@ declare class RenderResult {
|
|
|
7014
7018
|
*/
|
|
7015
7019
|
static readonly shape: RenderResult;
|
|
7016
7020
|
/**
|
|
7017
|
-
* Rendered CSS, encoded as UTF-8
|
|
7021
|
+
* Rendered CSS, encoded as UTF-8: the output of the render, no conversion. Use it to write the css to a file or to
|
|
7022
|
+
* the network, or to send it to another thread without a copy:
|
|
7023
|
+
*
|
|
7024
|
+
* ```ts
|
|
7025
|
+
* self.postMessage(result.write, [result.write.buffer]);
|
|
7026
|
+
* ```
|
|
7027
|
+
*
|
|
7028
|
+
* It is a view of the first bytes of a larger buffer (`write.buffer`): without a transfer, `postMessage()` copies
|
|
7029
|
+
* the whole buffer, send `write.slice()` to copy only the css. See
|
|
7030
|
+
* [Zero copy between threads](../../files/usage.md#zero-copy-between-threads).
|
|
7018
7031
|
*/
|
|
7019
7032
|
write: Uint8Array;
|
|
7020
7033
|
/**
|
|
@@ -7045,7 +7058,11 @@ declare class RenderResult {
|
|
|
7045
7058
|
*/
|
|
7046
7059
|
static codeLength(result: RenderResult): number;
|
|
7047
7060
|
/**
|
|
7048
|
-
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read
|
|
7061
|
+
* Rendered CSS. The bytes of {@link RenderResult.write} are decoded the first time the property is read, the
|
|
7062
|
+
* string is kept for the next reads: no string is created when it is not read.
|
|
7063
|
+
*
|
|
7064
|
+
* It is a getter, not a property of the object: `postMessage()` and `structuredClone()` do not send it, and it is
|
|
7065
|
+
* an empty string when it is read for the first time after {@link RenderResult.write} was transferred.
|
|
7049
7066
|
*/
|
|
7050
7067
|
get code(): string;
|
|
7051
7068
|
/**
|
|
@@ -8403,7 +8420,7 @@ declare function parseSyntax(syntax: string): ValidationToken$1[];
|
|
|
8403
8420
|
/**
|
|
8404
8421
|
* Version number
|
|
8405
8422
|
*/
|
|
8406
|
-
declare const version = "2.
|
|
8423
|
+
declare const version = "2.3.1";
|
|
8407
8424
|
|
|
8408
8425
|
/**
|
|
8409
8426
|
* Load file or url
|
package/dist/node.js
CHANGED
|
@@ -2,37 +2,37 @@
|
|
|
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.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
9
9
|
import { createReadStream } from 'node:fs';
|
|
10
10
|
import { lstat, readFile } from 'node:fs/promises';
|
|
11
|
-
import { doParse, doParseSync } from './
|
|
12
|
-
export { parseDeclarations, parseString } from './
|
|
13
|
-
import { doRender } from './
|
|
14
|
-
export { renderValue } from './
|
|
15
|
-
import { TransformResult, RenderResult } from './
|
|
16
|
-
import { useNativeBuffer } from './
|
|
11
|
+
import { doParse, doParseSync } from './parser/parse.js';
|
|
12
|
+
export { parseDeclarations, parseString } from './parser/parse.js';
|
|
13
|
+
import { doRender } from './printer/render.js';
|
|
14
|
+
export { renderValue } from './printer/render.js';
|
|
15
|
+
import { TransformResult, RenderResult } from './printer/result.js';
|
|
16
|
+
import { useNativeBuffer } from './printer/writer.js';
|
|
17
17
|
import { Buffer } from 'node:buffer';
|
|
18
|
-
import { ModuleScopeEnumOptions } from './
|
|
19
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './
|
|
20
|
-
import { createParseInfo, Tokenizer } from './
|
|
21
|
-
import { isCssInput } from './
|
|
22
|
-
import { resolve, matchUrl, dirname } from './
|
|
18
|
+
import { ModuleScopeEnumOptions } from './ast/types.js';
|
|
19
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
|
|
20
|
+
import { createParseInfo, Tokenizer } from './parser/tokenize.js';
|
|
21
|
+
import { isCssInput } from './parser/input.js';
|
|
22
|
+
import { resolve, matchUrl, dirname } from './fs/resolve.js';
|
|
23
23
|
import { ResponseType } from './types.js';
|
|
24
24
|
import { resolve as resolve$1 } from 'node:path';
|
|
25
|
-
import { SourceFile } from './
|
|
25
|
+
import { SourceFile } from './parser/source.js';
|
|
26
26
|
import { cwd } from 'node:process';
|
|
27
27
|
import { validateSyncArguments, parseResult } from './utils/sync.js';
|
|
28
|
-
export { minify } from './
|
|
29
|
-
export { convertColor } from './
|
|
30
|
-
export { isOkLabClose, okLabDistance } from './
|
|
31
|
-
export { Arena, AstArena, TokenField, arenaColumns } from './
|
|
32
|
-
export { ARENA, ARENAID, AstArenaNode } from './
|
|
33
|
-
export { SourceMap } from './
|
|
34
|
-
export { FeatureWalkMode } from './
|
|
35
|
-
export { parseSyntax } from './
|
|
28
|
+
export { minify } from './ast/minify.js';
|
|
29
|
+
export { convertColor } from './syntax/color/color.js';
|
|
30
|
+
export { isOkLabClose, okLabDistance } from './syntax/color/utils/distance.js';
|
|
31
|
+
export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
|
|
32
|
+
export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
|
|
33
|
+
export { SourceMap } from './printer/sourcemap.js';
|
|
34
|
+
export { FeatureWalkMode } from './ast/features/type.js';
|
|
35
|
+
export { parseSyntax } from './validation/parser/parse.js';
|
|
36
36
|
export { version } from './version.js';
|
|
37
37
|
|
|
38
38
|
// the rendered css is encoded with the node.js Buffer: faster than TextEncoder.encodeInto()
|
|
@@ -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.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { isIdentColor, parseColor, isColor } from '../syntax/syntax.js';
|
|
@@ -11,7 +11,7 @@ import { renderValue } from '../printer/render.js';
|
|
|
11
11
|
import { EnumToken, EnumAstNodeStatus, ModuleCaseTransformEnum, ModuleScopeEnumOptions, WalkerEvent } from '../ast/types.js';
|
|
12
12
|
import { minify } from '../ast/minify.js';
|
|
13
13
|
import { Tokenizer, createParseInfo } from './tokenize.js';
|
|
14
|
-
import { ResponseType } from '
|
|
14
|
+
import { ResponseType } from '../types.js';
|
|
15
15
|
import { AstArena, TokenField } from '../ast/arena.js';
|
|
16
16
|
import { AstArenaNode, ARENAID } from '../ast/arena-node.js';
|
|
17
17
|
import { isFunctionDefType, tokensfuncDefMap, pageMarginBoxType } from '../syntax/constants.js';
|
|
@@ -242,13 +242,12 @@ function reject(reason) {
|
|
|
242
242
|
* @private
|
|
243
243
|
*/
|
|
244
244
|
const getKeyName = memoize((key, how) => {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return dasherize(key);
|
|
245
|
+
// the case transforms are flags
|
|
246
|
+
if (how & (ModuleCaseTransformEnum.CamelCase | ModuleCaseTransformEnum.CamelCaseOnly)) {
|
|
247
|
+
return camelize(key);
|
|
248
|
+
}
|
|
249
|
+
if (how & (ModuleCaseTransformEnum.DashCase | ModuleCaseTransformEnum.DashCaseOnly)) {
|
|
250
|
+
return dasherize(key);
|
|
252
251
|
}
|
|
253
252
|
return key;
|
|
254
253
|
});
|
|
@@ -496,8 +495,8 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
496
495
|
valuesHandlers.get(EnumToken[key]).push(value);
|
|
497
496
|
}
|
|
498
497
|
else if (typeof value === "object") {
|
|
499
|
-
if ("type" in value && "handler" in value && value.type
|
|
500
|
-
if (value.type
|
|
498
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
499
|
+
if (value.type & WalkerEvent.Enter) {
|
|
501
500
|
if (!preValuesHandlers.has(EnumToken[key])) {
|
|
502
501
|
preValuesHandlers.set(EnumToken[key], []);
|
|
503
502
|
}
|
|
@@ -505,7 +504,7 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
505
504
|
.get(EnumToken[key])
|
|
506
505
|
.push(value.handler);
|
|
507
506
|
}
|
|
508
|
-
|
|
507
|
+
if (value.type & WalkerEvent.Leave) {
|
|
509
508
|
if (!postValuesHandlers.has(EnumToken[key])) {
|
|
510
509
|
postValuesHandlers.set(EnumToken[key], []);
|
|
511
510
|
}
|
|
@@ -534,8 +533,8 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
534
533
|
.push(value);
|
|
535
534
|
}
|
|
536
535
|
else if (typeof value === "object") {
|
|
537
|
-
if ("type" in value && "handler" in value && value.type
|
|
538
|
-
if (value.type
|
|
536
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
537
|
+
if (value.type & WalkerEvent.Enter) {
|
|
539
538
|
if (!preVisitorsHandlersMap.has(key)) {
|
|
540
539
|
preVisitorsHandlersMap.set(key, []);
|
|
541
540
|
}
|
|
@@ -543,7 +542,7 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
543
542
|
.get(key)
|
|
544
543
|
.push(value.handler);
|
|
545
544
|
}
|
|
546
|
-
|
|
545
|
+
if (value.type & WalkerEvent.Leave) {
|
|
547
546
|
if (!postVisitorsHandlersMap.has(key)) {
|
|
548
547
|
postVisitorsHandlersMap.set(key, []);
|
|
549
548
|
}
|
|
@@ -570,11 +569,11 @@ function parseVisitors(visitorsDef, errors) {
|
|
|
570
569
|
allVisitorsHandlers.add(value);
|
|
571
570
|
}
|
|
572
571
|
else if (typeof value === "object") {
|
|
573
|
-
if ("type" in value && "handler" in value && value.type
|
|
574
|
-
if (value.type
|
|
572
|
+
if ("type" in value && "handler" in value && typeof value.type == "number" && (value.type & (WalkerEvent.Enter | WalkerEvent.Leave)) != 0) {
|
|
573
|
+
if (value.type & WalkerEvent.Enter) {
|
|
575
574
|
preAllVisitorsHandlers.add(value.handler);
|
|
576
575
|
}
|
|
577
|
-
|
|
576
|
+
if (value.type & WalkerEvent.Leave) {
|
|
578
577
|
postAllVisitorsHandlers.add(value.handler);
|
|
579
578
|
}
|
|
580
579
|
}
|
|
@@ -1529,7 +1528,7 @@ function doParseSync(tokenizer, options = {}) {
|
|
|
1529
1528
|
}
|
|
1530
1529
|
}
|
|
1531
1530
|
}
|
|
1532
|
-
if (moduleSettings.naming
|
|
1531
|
+
if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
|
|
1533
1532
|
revMapping = {};
|
|
1534
1533
|
mapping = {};
|
|
1535
1534
|
let keyName;
|
|
@@ -2615,7 +2614,7 @@ async function doParse(iter, options = {}) {
|
|
|
2615
2614
|
}
|
|
2616
2615
|
}
|
|
2617
2616
|
}
|
|
2618
|
-
if (moduleSettings.naming
|
|
2617
|
+
if ((moduleSettings.naming & ModuleCaseTransformEnum.IgnoreCase) == 0) {
|
|
2619
2618
|
revMapping = {};
|
|
2620
2619
|
mapping = Object.entries(mapping).reduce((acc, [key, value]) => {
|
|
2621
2620
|
const keyName = getKeyName(key, moduleSettings.naming);
|
|
@@ -3377,7 +3376,7 @@ function parseAtRule(arena, stream, context, options, errors, parseAsBlock = nul
|
|
|
3377
3376
|
success = false;
|
|
3378
3377
|
}
|
|
3379
3378
|
else {
|
|
3380
|
-
context = createValidationContext(arena, stream
|
|
3379
|
+
context = createValidationContext(arena, stream, index);
|
|
3381
3380
|
// @ts-ignore
|
|
3382
3381
|
range = context.peekRange((t) => arena.dataTypes[t] === EnumToken.EndParensTokenType);
|
|
3383
3382
|
// inlined: arena.typeOf(range.at(-1))
|
|
@@ -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.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
import { SourceMap } from '../printer/sourcemap
|
|
8
|
+
import { SourceMap } from '../printer/sourcemap.js';
|
|
9
9
|
import { LineMap } from './linesmap.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -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.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
-
import config from '
|
|
8
|
+
import config from '../../data/properties.json.js';
|
|
9
9
|
|
|
10
10
|
Object.freeze(config);
|
|
11
11
|
// @ts-expect-error
|
|
@@ -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.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
|
|
@@ -10,8 +10,8 @@ import { StringBuilder } from '../../ast/strings.js';
|
|
|
10
10
|
import { renderValue } from '../../printer/render.js';
|
|
11
11
|
import { isFunctionDefType, tokensfuncDefMap, pseudoElements, combinators } from '../../syntax/constants.js';
|
|
12
12
|
import { isHash, isIdent } from '../../syntax/syntax.js';
|
|
13
|
-
import { getParsedSyntax, getSyntaxRule
|
|
14
|
-
import { matchAllSyntaxes, createValidationContext, trimArray, matchSelectorSyntax } from '../../validation/match.js';
|
|
13
|
+
import { getParsedSyntax, getSyntaxRule } from '../../validation/config.js';
|
|
14
|
+
import { matchAllSyntaxes, createValidationContext, trimArray, selectorFunctionSyntax, matchSelectorSyntax } from '../../validation/match.js';
|
|
15
15
|
import { ValidationSyntaxGroupEnum, ValidationTokenEnum } from '../../validation/parser/typedef.js';
|
|
16
16
|
import { splitTokenList } from '../../validation/utils/list.js';
|
|
17
17
|
import { trimWhiteSpace } from '../parse.js';
|
|
@@ -239,26 +239,12 @@ function parseSelector(arena, tokens, context, options, errors) {
|
|
|
239
239
|
let index;
|
|
240
240
|
let parent = context;
|
|
241
241
|
let nested = false;
|
|
242
|
-
let val;
|
|
243
242
|
if (contextType !== EnumToken.StyleSheetNodeType && contextType !== EnumToken.RuleNodeType) {
|
|
244
243
|
allowed = false;
|
|
245
244
|
if (contextType === EnumToken.AtRuleNodeType) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const rules = syntaxRule?.getBlockRules?.();
|
|
250
|
-
if (rules != null) {
|
|
251
|
-
for (const rule of rules) {
|
|
252
|
-
if (ValidationTokenEnum.PropertyType === rule.typ) {
|
|
253
|
-
if ("block-contents" === rule.val ||
|
|
254
|
-
"rule-list" === rule.val) {
|
|
255
|
-
allowed = true;
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
245
|
+
// computed once per at-rule name: the name is not concatenated for each selector
|
|
246
|
+
atRuleArena = arena;
|
|
247
|
+
allowed = arena.stringDerived(arena.name[context], 3 /* StringDerived.AtRuleAcceptsRules */, atRuleAcceptsRules);
|
|
262
248
|
}
|
|
263
249
|
}
|
|
264
250
|
while (parent != null && parent > 0) {
|
|
@@ -293,13 +279,12 @@ function parseSelector(arena, tokens, context, options, errors) {
|
|
|
293
279
|
continue;
|
|
294
280
|
}
|
|
295
281
|
if (arena.dataTypes[next] === EnumToken.FunctionTokenDefType) {
|
|
296
|
-
|
|
282
|
+
// ":" + name, no string is created. `:name()` is a selector function: looked up once per name
|
|
283
|
+
arena.stringValue[token] = arena.internBuilder(arena.appendString(pseudoBuilder.reset().appendCode(0x3a), arena.stringValue[next]));
|
|
297
284
|
arena.dataTypes[token] =
|
|
298
|
-
|
|
285
|
+
selectorFunctionSyntax(arena, token) != null
|
|
299
286
|
? EnumToken.PseudoClassFunctionTokenDefType
|
|
300
287
|
: arena.dataTypes[next];
|
|
301
|
-
// inlined: arena.setStr(token, val)
|
|
302
|
-
arena.stringValue[token] = arena.internString(val);
|
|
303
288
|
arena.spanLocation(token, token, next);
|
|
304
289
|
all[write++] = token;
|
|
305
290
|
read++;
|
|
@@ -323,13 +308,12 @@ function parseSelector(arena, tokens, context, options, errors) {
|
|
|
323
308
|
continue;
|
|
324
309
|
}
|
|
325
310
|
if (arena.dataTypes[next] === EnumToken.FunctionTokenDefType) {
|
|
326
|
-
|
|
311
|
+
// "::" + name, no string is created
|
|
312
|
+
arena.stringValue[token] = arena.internBuilder(arena.appendString(pseudoBuilder.reset().appendCode(0x3a).appendCode(0x3a), arena.stringValue[next]));
|
|
327
313
|
arena.dataTypes[token] =
|
|
328
|
-
|
|
314
|
+
selectorFunctionSyntax(arena, token) != null
|
|
329
315
|
? EnumToken.PseudoClassFunctionTokenDefType
|
|
330
316
|
: EnumToken.FunctionTokenDefType;
|
|
331
|
-
// inlined: arena.setStr(token, val)
|
|
332
|
-
arena.stringValue[token] = arena.internString(val);
|
|
333
317
|
arena.spanLocation(token, token, next);
|
|
334
318
|
all[write++] = token;
|
|
335
319
|
read++;
|
|
@@ -431,6 +415,32 @@ const selectorRenderOptions = { minify: false };
|
|
|
431
415
|
* builder of the pseudo classes and pseudo elements
|
|
432
416
|
*/
|
|
433
417
|
const pseudoBuilder = new StringBuilder();
|
|
418
|
+
/**
|
|
419
|
+
* the arena of the at-rule names read by {@link atRuleAcceptsRules}: the function passed to the string table is not a
|
|
420
|
+
* closure
|
|
421
|
+
*/
|
|
422
|
+
let atRuleArena = null;
|
|
423
|
+
/**
|
|
424
|
+
* true if the rules are allowed in the block of an at-rule, by name (see {@link StringDerived.AtRuleAcceptsRules})
|
|
425
|
+
* @param id the at-rule name
|
|
426
|
+
*/
|
|
427
|
+
function atRuleAcceptsRules(id) {
|
|
428
|
+
const syntaxRule = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + atRuleArena.resolveString(id));
|
|
429
|
+
if (syntaxRule?.acceptAnyRule) {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
const rules = syntaxRule?.getBlockRules?.();
|
|
433
|
+
if (rules != null) {
|
|
434
|
+
for (const rule of rules) {
|
|
435
|
+
if (ValidationTokenEnum.PropertyType === rule.typ &&
|
|
436
|
+
("block-contents" === rule.val ||
|
|
437
|
+
"rule-list" === rule.val)) {
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
434
444
|
/**
|
|
435
445
|
* true if ":" + the string is a pseudo element with a single colon syntax (`:before`). the string is not created
|
|
436
446
|
* @param arena
|