@tbela99/css-parser 2.1.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 +66 -1
- package/README.md +14 -7
- package/architecture.png +0 -0
- package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
- package/dist/{src/lib/ast → ast}/arena.js +304 -139
- package/dist/{src/lib/ast → ast}/cache.js +40 -24
- package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
- package/dist/{src/lib/ast → ast}/features/if.js +6 -6
- package/dist/ast/features/index.d.ts +7 -0
- package/dist/{src/lib/ast → ast}/features/index.js +3 -2
- package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
- package/dist/ast/features/mixin.js +953 -0
- package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
- package/dist/ast/features/shorthand.js +129 -0
- package/dist/ast/features/transform.js +188 -0
- package/dist/{src/lib/ast → ast}/features/type.js +2 -2
- package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
- package/dist/{src/lib/ast → ast}/math/math.js +2 -2
- package/dist/{src/lib/ast → ast}/minify.js +745 -201
- package/dist/ast/mixins/custom-function.js +393 -0
- package/dist/ast/mixins/utils.js +53 -0
- package/dist/ast/mixins/variables.js +678 -0
- package/dist/ast/strings.js +910 -0
- package/dist/ast/transform/compute.js +560 -0
- package/dist/ast/transform/matrix.js +67 -0
- package/dist/ast/transform/minify.js +325 -0
- package/dist/ast/transform/perspective.js +24 -0
- package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
- package/dist/ast/transform/scale.js +43 -0
- package/dist/ast/transform/skew.js +38 -0
- package/dist/ast/transform/translate.js +56 -0
- package/dist/ast/transform/utils.js +390 -0
- package/dist/{src/lib/ast → ast}/types.js +2 -2
- package/dist/{src/lib/ast → ast}/walk.js +2 -2
- package/dist/{src/data → data}/properties.json.js +86 -2
- package/dist/{src/data → data}/validation.json.js +30 -21
- package/dist/{src/lib/fs → fs}/resolve.js +2 -2
- package/dist/index-umd-web.js +19727 -10719
- package/dist/index.d.ts +738 -100
- package/dist/{src/node.js → node.js} +70 -52
- package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
- package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
- package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
- package/dist/{src/lib/parser → parser}/input.js +18 -3
- package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
- package/dist/{src/lib/parser → parser}/parse.js +444 -278
- package/dist/{src/lib/parser → parser}/source.js +3 -3
- package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
- package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
- package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
- package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
- package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
- package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
- package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
- package/dist/parser/utils/cache.js +53 -0
- package/dist/parser/utils/canonical.js +78 -0
- package/dist/parser/utils/codes.js +93 -0
- package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
- package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
- package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
- package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
- package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
- package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
- package/dist/{src/lib/printer → printer}/render.js +582 -153
- package/dist/printer/result.js +148 -0
- package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
- package/dist/printer/writer.js +252 -0
- package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
- package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
- package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
- package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
- package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
- package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
- package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
- package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
- package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
- package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
- package/dist/{src/types.js → types.js} +2 -2
- package/dist/{src/utils → utils}/sync.js +12 -7
- 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/{src/lib/validation → validation}/config.js +63 -16
- package/dist/validation/first.js +574 -0
- package/dist/{src/lib/validation → validation}/match.js +376 -161
- package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
- package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
- package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
- package/dist/version.js +13 -0
- package/dist/{src/web.js → web.js} +68 -55
- package/package.json +15 -13
- 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
- package/dist/types.d.ts +0 -21
- package/dist/utils/sync.d.ts +0 -16
|
@@ -1,37 +1,42 @@
|
|
|
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.3.0
|
|
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 {
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
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
|
+
import { Buffer } from 'node:buffer';
|
|
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';
|
|
20
23
|
import { ResponseType } from './types.js';
|
|
21
24
|
import { resolve as resolve$1 } from 'node:path';
|
|
22
|
-
import { SourceFile } from './
|
|
25
|
+
import { SourceFile } from './parser/source.js';
|
|
23
26
|
import { cwd } from 'node:process';
|
|
24
|
-
import {
|
|
25
|
-
export { minify } from './
|
|
26
|
-
export { convertColor } from './
|
|
27
|
-
export { isOkLabClose, okLabDistance } from './
|
|
28
|
-
export { Arena, AstArena, TokenField, arenaColumns } from './
|
|
29
|
-
export { ARENA, ARENAID, AstArenaNode } from './
|
|
30
|
-
export { SourceMap } from './
|
|
31
|
-
export { FeatureWalkMode } from './
|
|
32
|
-
export { parseSyntax } from './
|
|
33
|
-
export { version } from '
|
|
27
|
+
import { validateSyncArguments, parseResult } from './utils/sync.js';
|
|
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
|
+
export { version } from './version.js';
|
|
34
37
|
|
|
38
|
+
// the rendered css is encoded with the node.js Buffer: faster than TextEncoder.encodeInto()
|
|
39
|
+
useNativeBuffer(Buffer);
|
|
35
40
|
/**
|
|
36
41
|
* Load file or url
|
|
37
42
|
* @param url
|
|
@@ -117,7 +122,9 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
117
122
|
* ```
|
|
118
123
|
*/
|
|
119
124
|
function render(arena, data, options = {}, mapping) {
|
|
120
|
-
return doRender(arena, data,
|
|
125
|
+
return doRender(arena, data,
|
|
126
|
+
// the options of the caller are not modified
|
|
127
|
+
{ ...options, resolve, dirname, cwd: options.cwd ?? resolve$1() }, mapping);
|
|
121
128
|
}
|
|
122
129
|
/**
|
|
123
130
|
* Parse CSS
|
|
@@ -150,7 +157,15 @@ function parseSync(...args) {
|
|
|
150
157
|
if (options != null) {
|
|
151
158
|
validateSyncArguments(options);
|
|
152
159
|
}
|
|
153
|
-
options
|
|
160
|
+
// the options of the caller are not modified: they may be reused
|
|
161
|
+
return parseSyncInput(stream, { ...options });
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* parse a css input. the options belong to the call: they are modified (source, parse info, ...)
|
|
165
|
+
* @param stream
|
|
166
|
+
* @param options
|
|
167
|
+
*/
|
|
168
|
+
function parseSyncInput(stream, options) {
|
|
154
169
|
options.src ??= "";
|
|
155
170
|
options.sourcesMap ??= new Map();
|
|
156
171
|
Object.assign(options, {
|
|
@@ -197,7 +212,11 @@ function transformSync(...args) {
|
|
|
197
212
|
options = opt;
|
|
198
213
|
stream = input;
|
|
199
214
|
}
|
|
200
|
-
options
|
|
215
|
+
if (options != null) {
|
|
216
|
+
validateSyncArguments(options);
|
|
217
|
+
}
|
|
218
|
+
// the options of the caller are not modified: they may be reused
|
|
219
|
+
options = { ...options };
|
|
201
220
|
if (options.minify == null) {
|
|
202
221
|
options.minify = true;
|
|
203
222
|
}
|
|
@@ -208,7 +227,7 @@ function transformSync(...args) {
|
|
|
208
227
|
options.removeCharset = true;
|
|
209
228
|
}
|
|
210
229
|
const startTime = performance.now();
|
|
211
|
-
const parseResult =
|
|
230
|
+
const parseResult = parseSyncInput(stream, options);
|
|
212
231
|
let mapping = null;
|
|
213
232
|
let importMapping = null;
|
|
214
233
|
if ((typeof options.module === "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
|
|
@@ -223,17 +242,12 @@ function transformSync(...args) {
|
|
|
223
242
|
...options,
|
|
224
243
|
expandNestingRules: false,
|
|
225
244
|
}, mapping != null ? { mapping, importMapping } : null);
|
|
226
|
-
return {
|
|
227
|
-
|
|
228
|
-
...
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
...parseResult.stats,
|
|
233
|
-
render: rendered.stats.total,
|
|
234
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`,
|
|
235
|
-
},
|
|
236
|
-
};
|
|
245
|
+
return new TransformResult(parseResult, rendered, {
|
|
246
|
+
bytesOut: RenderResult.codeLength(rendered),
|
|
247
|
+
...parseResult.stats,
|
|
248
|
+
render: rendered.stats.total,
|
|
249
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`,
|
|
250
|
+
});
|
|
237
251
|
}
|
|
238
252
|
/**
|
|
239
253
|
* Parse CSS
|
|
@@ -300,7 +314,15 @@ async function parse(...args) {
|
|
|
300
314
|
stream = input;
|
|
301
315
|
}
|
|
302
316
|
}
|
|
303
|
-
options
|
|
317
|
+
// the options of the caller are not modified: they may be reused
|
|
318
|
+
return parseInput(stream, { ...options });
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* parse a css input. the options belong to the call: they are modified (source, parse info, ...)
|
|
322
|
+
* @param stream
|
|
323
|
+
* @param options
|
|
324
|
+
*/
|
|
325
|
+
async function parseInput(stream, options) {
|
|
304
326
|
options.src ??= "";
|
|
305
327
|
options.sourcesMap ??= new Map();
|
|
306
328
|
Object.assign(options, {
|
|
@@ -386,7 +408,8 @@ async function transform(...args) {
|
|
|
386
408
|
stream = input;
|
|
387
409
|
}
|
|
388
410
|
}
|
|
389
|
-
options
|
|
411
|
+
// the options of the caller are not modified: they may be reused
|
|
412
|
+
options = { ...options };
|
|
390
413
|
if (options.minify == null) {
|
|
391
414
|
options.minify = true;
|
|
392
415
|
}
|
|
@@ -397,7 +420,7 @@ async function transform(...args) {
|
|
|
397
420
|
options.removeCharset = true;
|
|
398
421
|
}
|
|
399
422
|
const startTime = performance.now();
|
|
400
|
-
return
|
|
423
|
+
return parseInput(stream, options).then((parseResult) => {
|
|
401
424
|
let mapping = null;
|
|
402
425
|
let importMapping = null;
|
|
403
426
|
if ((typeof options.module === "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
|
|
@@ -412,18 +435,13 @@ async function transform(...args) {
|
|
|
412
435
|
...options,
|
|
413
436
|
expandNestingRules: false,
|
|
414
437
|
}, mapping != null ? { mapping, importMapping } : null);
|
|
415
|
-
return {
|
|
416
|
-
|
|
417
|
-
...
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
...parseResult.stats,
|
|
422
|
-
render: rendered.stats.total,
|
|
423
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`,
|
|
424
|
-
},
|
|
425
|
-
};
|
|
438
|
+
return new TransformResult(parseResult, rendered, {
|
|
439
|
+
bytesOut: RenderResult.codeLength(rendered),
|
|
440
|
+
...parseResult.stats,
|
|
441
|
+
render: rendered.stats.total,
|
|
442
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`,
|
|
443
|
+
});
|
|
426
444
|
});
|
|
427
445
|
}
|
|
428
446
|
|
|
429
|
-
export { ModuleScopeEnumOptions, ResponseType, dirname, load, parse, parseSync, render, resolve, transform, transformSync };
|
|
447
|
+
export { ModuleScopeEnumOptions, RenderResult, ResponseType, TransformResult, dirname, load, parse, parseSync, render, resolve, transform, transformSync };
|
|
@@ -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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { PropertySet } from './set.js';
|
|
9
9
|
import { getConfig } from '../utils/config.js';
|
|
10
10
|
import { PropertyMap } from './map.js';
|
|
11
|
-
import {
|
|
11
|
+
import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
|
|
12
12
|
import { getParsedSyntax } from '../../validation/config.js';
|
|
13
13
|
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
14
14
|
import { isValidDeclarationValue } from '../../validation/match.js';
|
|
@@ -108,17 +108,24 @@ class PropertyList {
|
|
|
108
108
|
* keys shared by the lists that use the same arena
|
|
109
109
|
*/
|
|
110
110
|
memo;
|
|
111
|
+
/**
|
|
112
|
+
* syntaxes of the descriptors of the at-rule that contains the declarations: `result` in `@function`. the
|
|
113
|
+
* declarations that are not validated are validated with them
|
|
114
|
+
*/
|
|
115
|
+
descriptors;
|
|
111
116
|
/**
|
|
112
117
|
*
|
|
113
118
|
* @param arena
|
|
114
119
|
* @param options
|
|
115
120
|
* @param memo keys shared by the lists that use the same arena
|
|
121
|
+
* @param descriptors syntaxes of the descriptors of the at-rule that contains the declarations
|
|
116
122
|
*/
|
|
117
|
-
constructor(arena, options = {}, memo = null) {
|
|
123
|
+
constructor(arena, options = {}, memo = null, descriptors = null) {
|
|
118
124
|
this.arena = arena;
|
|
119
125
|
this.options = options;
|
|
120
126
|
this.declarations = new Map();
|
|
121
127
|
this.memo = memo ?? new DeclarationMemo();
|
|
128
|
+
this.descriptors = descriptors;
|
|
122
129
|
}
|
|
123
130
|
/**
|
|
124
131
|
* add a declaration
|
|
@@ -131,7 +138,7 @@ class PropertyList {
|
|
|
131
138
|
name =
|
|
132
139
|
arena.dataTypes[declaration] !== EnumToken.DeclarationNodeType
|
|
133
140
|
? null
|
|
134
|
-
: arena.
|
|
141
|
+
: arena.resolveString(arena.name[declaration]);
|
|
135
142
|
// do not compute shorthand for invalid declarations
|
|
136
143
|
if (name == null) {
|
|
137
144
|
this.declarations.set(this.memo.key(arena, declaration), declaration);
|
|
@@ -162,7 +169,9 @@ class PropertyList {
|
|
|
162
169
|
return this;
|
|
163
170
|
}
|
|
164
171
|
if (arena.flags[declaration] & EnumAstNodeStatus.Unvalidated) {
|
|
165
|
-
syntaxRules =
|
|
172
|
+
syntaxRules =
|
|
173
|
+
this.descriptors?.[lowercase(name)] ??
|
|
174
|
+
getParsedSyntax(ValidationSyntaxGroupEnum.Declarations, lowercase(name));
|
|
166
175
|
if (syntaxRules != null) {
|
|
167
176
|
arena.flags[declaration] |=
|
|
168
177
|
(isValidDeclarationValue(arena, syntaxRules, declaration, this.options)
|
|
@@ -272,6 +281,14 @@ class PropertyList {
|
|
|
272
281
|
if (shorthand != null) {
|
|
273
282
|
this.mapValues(declaration, shorthand);
|
|
274
283
|
}
|
|
284
|
+
const existing = this.declarations.get(propertyName);
|
|
285
|
+
// a previous declaration with the same name takes precedence when it is !important and the new one is not
|
|
286
|
+
if (existing != null &&
|
|
287
|
+
typeof existing === "number" &&
|
|
288
|
+
arena.flags[existing] & EnumAstNodeStatus.ImportantDeclaration &&
|
|
289
|
+
(arena.flags[declaration] & EnumAstNodeStatus.ImportantDeclaration) == 0) {
|
|
290
|
+
return this;
|
|
291
|
+
}
|
|
275
292
|
this.declarations.set(propertyName, declaration);
|
|
276
293
|
}
|
|
277
294
|
return this;
|
|
@@ -305,7 +322,7 @@ class PropertyList {
|
|
|
305
322
|
default: {
|
|
306
323
|
for (const v of set) {
|
|
307
324
|
if (arena.dataTypes[v] === EnumToken.IdenTokenType) {
|
|
308
|
-
const value = arena.
|
|
325
|
+
const value = arena.resolveString(arena.stringValue[v]).toLowerCase();
|
|
309
326
|
if (value === pattern || new RegExp(`(^|\|)${pattern}(\||$)`).test(value)) {
|
|
310
327
|
val.push(v);
|
|
311
328
|
set.delete(v);
|
|
@@ -329,7 +346,7 @@ class PropertyList {
|
|
|
329
346
|
}
|
|
330
347
|
for (const val of declarationValues) {
|
|
331
348
|
if (arena.dataTypes[val] === EnumToken.IdenTokenType) {
|
|
332
|
-
name = arena.
|
|
349
|
+
name = arena.resolveString(arena.stringValue[val]).toLowerCase();
|
|
333
350
|
if (mapping.mapping[name] != null) {
|
|
334
351
|
const typ = EnumToken[mapping.mapping[name].typ];
|
|
335
352
|
arena.resetToken(val, typ, mapping.mapping[name].val);
|
|
@@ -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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { eqToken } from '../utils/eq.js';
|
|
@@ -41,7 +41,7 @@ function configToken(arena, config) {
|
|
|
41
41
|
function matchConfigToken(arena, token, config) {
|
|
42
42
|
return (config != null &&
|
|
43
43
|
arena.dataTypes[token] === configType(config) &&
|
|
44
|
-
(config.val == null || arena.
|
|
44
|
+
(config.val == null || arena.resolveString(arena.stringValue[token]) === config.val));
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* map of declarations that can be merged into a single shorthand declaration.
|
|
@@ -83,7 +83,7 @@ class PropertyMap {
|
|
|
83
83
|
*/
|
|
84
84
|
add(declaration) {
|
|
85
85
|
const arena = this.arena;
|
|
86
|
-
const nam = arena.
|
|
86
|
+
const nam = arena.resolveString(arena.name[declaration]);
|
|
87
87
|
if (nam === this.config.shorthand) {
|
|
88
88
|
this.declarations.clear();
|
|
89
89
|
this.declarations.set(nam, declaration);
|
|
@@ -270,7 +270,7 @@ class PropertyMap {
|
|
|
270
270
|
else {
|
|
271
271
|
// a property set has no name
|
|
272
272
|
key =
|
|
273
|
-
value instanceof PropertySet ? "undefined" : arena.
|
|
273
|
+
value instanceof PropertySet ? "undefined" : arena.resolveString(arena.name[value]);
|
|
274
274
|
mapped[key] = value;
|
|
275
275
|
}
|
|
276
276
|
}
|
|
@@ -413,7 +413,7 @@ class PropertyMap {
|
|
|
413
413
|
if (declaration instanceof PropertySet || declaration instanceof PropertyMap) {
|
|
414
414
|
continue;
|
|
415
415
|
}
|
|
416
|
-
const nam = arena.
|
|
416
|
+
const nam = arena.resolveString(arena.name[declaration]);
|
|
417
417
|
const config = nam === this.config.shorthand ? this.config : (propertiesMapping[nam] ?? this.config);
|
|
418
418
|
if (!("mapping" in config)) {
|
|
419
419
|
continue;
|
|
@@ -474,7 +474,7 @@ class PropertyMap {
|
|
|
474
474
|
props.separator != null &&
|
|
475
475
|
configType(props.separator) === valType &&
|
|
476
476
|
(valType === EnumToken.CommaTokenType ||
|
|
477
|
-
props.separator.val === arena.
|
|
477
|
+
props.separator.val === arena.resolveString(arena.stringValue[val]))) {
|
|
478
478
|
continue;
|
|
479
479
|
}
|
|
480
480
|
match = matchType(arena, val, curr[1]);
|
|
@@ -621,7 +621,7 @@ class PropertyMap {
|
|
|
621
621
|
EnumToken.IdenTokenType,
|
|
622
622
|
].includes(arena.dataTypes[v]) ||
|
|
623
623
|
(arena.dataTypes[v] === EnumToken.IdenTokenType &&
|
|
624
|
-
!propertiesMapping[curr[0]].default.includes(arena.
|
|
624
|
+
!propertiesMapping[curr[0]].default.includes(arena.resolveString(arena.stringValue[v])))) {
|
|
625
625
|
doFilterDefault = false;
|
|
626
626
|
break;
|
|
627
627
|
}
|
|
@@ -635,7 +635,7 @@ class PropertyMap {
|
|
|
635
635
|
}
|
|
636
636
|
return (!doFilterDefault ||
|
|
637
637
|
!(arena.dataTypes[val] === EnumToken.IdenTokenType &&
|
|
638
|
-
props.default.includes(arena.
|
|
638
|
+
props.default.includes(arena.resolveString(arena.stringValue[val]))));
|
|
639
639
|
});
|
|
640
640
|
if (filtered.length > 0 ||
|
|
641
641
|
!(this.requiredCount == requiredCount && propertiesMapping[curr[0]].required)) {
|
|
@@ -651,15 +651,15 @@ class PropertyMap {
|
|
|
651
651
|
while (i--) {
|
|
652
652
|
if (arena.dataTypes[values[i]] === EnumToken.IdenTokenType &&
|
|
653
653
|
// @ts-expect-error
|
|
654
|
-
arena.
|
|
655
|
-
// inlined: this.parse(props.mapping[arena.
|
|
654
|
+
arena.resolveString(arena.stringValue[values[i]]) in props.mapping) {
|
|
655
|
+
// inlined: this.parse(props.mapping[arena.resolveString(arena.stringValue[values[i]])])
|
|
656
656
|
values.splice(i, 1, ...(this.memo == null
|
|
657
657
|
? parseString(this.arena,
|
|
658
658
|
// @ts-ignore
|
|
659
|
-
props.mapping[arena.
|
|
659
|
+
props.mapping[arena.resolveString(arena.stringValue[values[i]])])
|
|
660
660
|
: this.memo.parse(this.arena,
|
|
661
661
|
// @ts-ignore
|
|
662
|
-
props.mapping[arena.
|
|
662
|
+
props.mapping[arena.resolveString(arena.stringValue[values[i]])])));
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
}
|
|
@@ -722,8 +722,8 @@ class PropertyMap {
|
|
|
722
722
|
}
|
|
723
723
|
if (values.length === 1 &&
|
|
724
724
|
arena.stringValue[values[0]] !== 0 &&
|
|
725
|
-
this.config.default.includes(arena.
|
|
726
|
-
this.config.default[0] !== arena.
|
|
725
|
+
this.config.default.includes(arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) &&
|
|
726
|
+
this.config.default[0] !== arena.resolveString(arena.stringValue[values[0]]).toLowerCase()) {
|
|
727
727
|
// inlined: this.parse(this.config.default[0])
|
|
728
728
|
values =
|
|
729
729
|
this.memo == null
|
|
@@ -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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { numericTokenTypes } from '../../ast/arena.js';
|
|
@@ -57,7 +57,7 @@ class PropertySet {
|
|
|
57
57
|
}
|
|
58
58
|
add(declaration) {
|
|
59
59
|
const arena = this.arena;
|
|
60
|
-
const nam = arena.
|
|
60
|
+
const nam = arena.resolveString(arena.name[declaration]);
|
|
61
61
|
if (nam === this.config.shorthand) {
|
|
62
62
|
this.declarations = new Map();
|
|
63
63
|
}
|
|
@@ -86,7 +86,7 @@ class PropertySet {
|
|
|
86
86
|
}
|
|
87
87
|
if (typ !== EnumToken.WhitespaceTokenType && typ !== EnumToken.CommentTokenType) {
|
|
88
88
|
if (typ === EnumToken.IdenTokenType &&
|
|
89
|
-
this.config.keywords.includes(arena.
|
|
89
|
+
this.config.keywords.includes(arena.resolveString(arena.stringValue[token]))) {
|
|
90
90
|
if (tokens.length === 0) {
|
|
91
91
|
tokens.push([]);
|
|
92
92
|
current++;
|
|
@@ -94,7 +94,7 @@ class PropertySet {
|
|
|
94
94
|
tokens[current].push(token);
|
|
95
95
|
}
|
|
96
96
|
if (typ === EnumToken.LiteralTokenType &&
|
|
97
|
-
arena.
|
|
97
|
+
arena.resolveString(arena.stringValue[token]) === this.config.separator?.val) {
|
|
98
98
|
tokens.push([]);
|
|
99
99
|
current++;
|
|
100
100
|
continue;
|
|
@@ -1,11 +1,17 @@
|
|
|
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.3.0
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
|
+
import { nativeBufferClass } from '../printer/writer.js';
|
|
9
|
+
|
|
8
10
|
const encoder = new TextEncoder();
|
|
11
|
+
/**
|
|
12
|
+
* the code units of a Uint16Array are stored in the platform byte order
|
|
13
|
+
*/
|
|
14
|
+
const littleEndian = new Uint8Array(new Uint16Array([1]).buffer)[0] === 1;
|
|
9
15
|
const decoder = new TextDecoder();
|
|
10
16
|
const nonAscii = /[^\x00-\x7f]/;
|
|
11
17
|
const empty = new Uint8Array(0);
|
|
@@ -39,6 +45,13 @@ function bytesOf(input) {
|
|
|
39
45
|
* @param text
|
|
40
46
|
*/
|
|
41
47
|
function codeUnitsOf(text) {
|
|
48
|
+
const native = nativeBufferClass();
|
|
49
|
+
// node.js: the code units are written by the native encoder (little endian platforms)
|
|
50
|
+
if (native !== null && littleEndian) {
|
|
51
|
+
const buffer = native.allocUnsafeSlow(text.length * 2);
|
|
52
|
+
buffer.write(text, 0, text.length * 2, "utf16le");
|
|
53
|
+
return new Uint16Array(buffer.buffer, buffer.byteOffset, text.length);
|
|
54
|
+
}
|
|
42
55
|
const codes = new Uint16Array(text.length);
|
|
43
56
|
for (let i = 0; i < text.length; i++) {
|
|
44
57
|
codes[i] = text.charCodeAt(i);
|
|
@@ -56,7 +69,9 @@ function toCodeUnits(input) {
|
|
|
56
69
|
return { codes: empty, text: "" };
|
|
57
70
|
}
|
|
58
71
|
if (typeof input === "string") {
|
|
59
|
-
|
|
72
|
+
// an ascii string has a byte for each code unit: the encoded string is the code units
|
|
73
|
+
const bytes = encoder.encode(input);
|
|
74
|
+
return { codes: bytes.length === input.length ? bytes : codeUnitsOf(input), text: input };
|
|
60
75
|
}
|
|
61
76
|
const bytes = bytesOf(input);
|
|
62
77
|
const text = decoder.decode(bytes);
|