@tbela99/css-parser 1.8.2 → 2.0.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 +66 -0
- package/README.md +129 -31
- package/dist/index-umd-web.js +27383 -24083
- package/dist/index.d.ts +2737 -2200
- package/dist/package.json.js +2 -2
- package/dist/src/data/properties.json.js +1 -1
- package/dist/src/data/validation.json.js +1 -1
- package/dist/src/lib/ast/arena-node.js +548 -0
- package/dist/src/lib/ast/arena.js +3198 -0
- package/dist/src/lib/ast/cache.js +333 -0
- package/dist/src/lib/ast/features/calc.js +85 -76
- package/dist/src/lib/ast/features/if.js +155 -115
- package/dist/src/lib/ast/features/index.js +1 -1
- package/dist/src/lib/ast/features/inlinecssvariables.js +77 -84
- package/dist/src/lib/ast/features/prefix.js +184 -183
- package/dist/src/lib/ast/features/shorthand.js +40 -46
- package/dist/src/lib/ast/features/transform.js +24 -24
- package/dist/src/lib/ast/features/type.js +1 -1
- package/dist/src/lib/ast/math/expression.js +458 -543
- package/dist/src/lib/ast/math/math.js +19 -41
- package/dist/src/lib/ast/minify.js +590 -647
- package/dist/src/lib/ast/transform/compute.js +82 -85
- package/dist/src/lib/ast/transform/matrix.js +21 -38
- package/dist/src/lib/ast/transform/minify.js +82 -193
- package/dist/src/lib/ast/transform/perspective.js +2 -3
- package/dist/src/lib/ast/transform/rotate.js +1 -1
- package/dist/src/lib/ast/transform/scale.js +1 -1
- package/dist/src/lib/ast/transform/skew.js +1 -1
- package/dist/src/lib/ast/transform/translate.js +1 -1
- package/dist/src/lib/ast/transform/utils.js +2 -2
- package/dist/src/lib/ast/types.js +263 -258
- package/dist/src/lib/ast/walk.js +246 -610
- package/dist/src/lib/fs/resolve.js +1 -1
- package/dist/src/lib/parser/declaration/list.js +223 -139
- package/dist/src/lib/parser/declaration/map.js +251 -238
- package/dist/src/lib/parser/declaration/set.js +74 -66
- package/dist/src/lib/parser/linesmap.js +1 -1
- package/dist/src/lib/parser/parse.js +1379 -1658
- package/dist/src/lib/parser/source.js +7 -4
- package/dist/src/lib/parser/tokenize.js +406 -199
- package/dist/src/lib/parser/utils/angle.js +11 -13
- package/dist/src/lib/parser/utils/at-rule-container.js +183 -168
- package/dist/src/lib/parser/utils/at-rule-font-feature-values.js +5 -5
- package/dist/src/lib/parser/utils/at-rule-generic.js +31 -24
- package/dist/src/lib/parser/utils/at-rule-import.js +44 -44
- package/dist/src/lib/parser/utils/at-rule-media.js +216 -205
- package/dist/src/lib/parser/utils/at-rule-support.js +83 -88
- package/dist/src/lib/parser/utils/at-rule-when-else.js +47 -47
- package/dist/src/lib/parser/utils/at-rule.js +5 -5
- package/dist/src/lib/parser/utils/base64.js +2 -2
- package/dist/src/lib/parser/utils/cache.js +1 -1
- package/dist/src/lib/parser/utils/config.js +1 -1
- package/dist/src/lib/parser/utils/declaration.js +233 -234
- package/dist/src/lib/parser/utils/eq.js +50 -3
- package/dist/src/lib/parser/utils/hash.js +2 -35
- package/dist/src/lib/parser/utils/selector.js +309 -387
- package/dist/src/lib/parser/utils/text.js +18 -4
- package/dist/src/lib/parser/utils/token.js +16 -69
- package/dist/src/lib/parser/utils/type.js +37 -24
- package/dist/src/lib/printer/render.js +965 -511
- package/dist/src/lib/printer/sourcemap/lib/codec.js +1 -1
- package/dist/src/lib/printer/sourcemap/sourcemap.js +1 -1
- package/dist/src/lib/syntax/color/a98rgb.js +1 -1
- package/dist/src/lib/syntax/color/alpha.js +36 -37
- package/dist/src/lib/syntax/color/cmyk.js +35 -52
- package/dist/src/lib/syntax/color/color-mix.js +96 -132
- package/dist/src/lib/syntax/color/color.js +222 -231
- package/dist/src/lib/syntax/color/hex.js +45 -55
- package/dist/src/lib/syntax/color/hsl.js +54 -62
- package/dist/src/lib/syntax/color/hwb.js +60 -68
- package/dist/src/lib/syntax/color/lab.js +59 -67
- package/dist/src/lib/syntax/color/lch.js +59 -67
- package/dist/src/lib/syntax/color/oklab.js +60 -68
- package/dist/src/lib/syntax/color/oklch.js +60 -67
- package/dist/src/lib/syntax/color/p3.js +1 -1
- package/dist/src/lib/syntax/color/prophotorgb.js +1 -1
- package/dist/src/lib/syntax/color/rec2020.js +1 -1
- package/dist/src/lib/syntax/color/relative-color.js +94 -144
- package/dist/src/lib/syntax/color/rgb.js +54 -57
- package/dist/src/lib/syntax/color/srgb.js +55 -53
- package/dist/src/lib/syntax/color/utils/color-type.js +13 -10
- package/dist/src/lib/syntax/color/utils/colorspace.js +11 -11
- package/dist/src/lib/syntax/color/utils/components.js +19 -20
- package/dist/src/lib/syntax/color/utils/distance.js +15 -13
- package/dist/src/lib/syntax/color/utils/make-color.js +15 -19
- package/dist/src/lib/syntax/color/utils/matrix.js +2 -2
- package/dist/src/lib/syntax/color/xyz.js +1 -1
- package/dist/src/lib/syntax/color/xyzd50.js +1 -1
- package/dist/src/lib/syntax/constants.js +2 -16
- package/dist/src/lib/syntax/syntax.js +301 -407
- package/dist/src/lib/validation/config.js +1 -1
- package/dist/src/lib/validation/match.js +959 -723
- package/dist/src/lib/validation/parser/parse.js +230 -112
- package/dist/src/lib/validation/parser/typedef.js +1 -1
- package/dist/src/lib/validation/utils/list.js +27 -12
- package/dist/src/node.js +12 -72
- package/dist/src/types.js +1 -1
- package/dist/src/utils/sync.js +9 -6
- package/dist/src/web.js +11 -73
- package/package.json +9 -10
- package/dist/index.cjs +0 -35870
- package/dist/src/lib/ast/clone.js +0 -51
- package/dist/src/lib/ast/expand.js +0 -311
- package/dist/src/lib/ast/find.js +0 -192
- package/dist/src/lib/ast/node.js +0 -59
package/dist/src/types.js
CHANGED
package/dist/src/utils/sync.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { EnumToken } from '../lib/ast/types.js';
|
|
9
|
+
import { AstArena } from '../lib/ast/arena.js';
|
|
9
10
|
import { dirname } from '../lib/fs/resolve.js';
|
|
10
11
|
import { ResponseType } from '../types.js';
|
|
11
12
|
|
|
@@ -23,10 +24,12 @@ function parseResult(result, options) {
|
|
|
23
24
|
}
|
|
24
25
|
else {
|
|
25
26
|
// extract inline source map from the input CSS
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
const arena = result.arena;
|
|
28
|
+
const token = arena.lastChild[result.ast];
|
|
29
|
+
if (token != 0 &&
|
|
30
|
+
arena.dataTypes[token] == EnumToken.CommentTokenType &&
|
|
31
|
+
arena.startsWith(token, "val", "/*# sourceMappingURL=")) {
|
|
32
|
+
let data = arena.strings[arena.stringValue[token]].slice(21, -2).trim();
|
|
30
33
|
if (data.endsWith(".map")) {
|
|
31
34
|
if (options.load == null) {
|
|
32
35
|
data = "";
|
|
@@ -71,7 +74,7 @@ function validateSyncArguments(options, prefix = "options.") {
|
|
|
71
74
|
throw new Error(`[${prefix + key}]: Async functions are not supported in sync mode. Use parse() or transform() instead.`);
|
|
72
75
|
}
|
|
73
76
|
}
|
|
74
|
-
else if (value != null && typeof value == "object") {
|
|
77
|
+
else if (value != null && typeof value == "object" && !(value instanceof AstArena)) {
|
|
75
78
|
validateSyncArguments(value, prefix + key + ".");
|
|
76
79
|
}
|
|
77
80
|
}
|
package/dist/src/web.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
CSS parser, minifier and validator for node and the browser
|
|
3
3
|
|
|
4
4
|
Author(s): Thierry Bela
|
|
5
|
-
Version:
|
|
5
|
+
Version: 2.0.1
|
|
6
6
|
License: MIT
|
|
7
7
|
*/
|
|
8
8
|
import { doParse, doParseSync } from './lib/parser/parse.js';
|
|
@@ -10,24 +10,20 @@ export { parseDeclarations, parseString } from './lib/parser/parse.js';
|
|
|
10
10
|
import { doRender } from './lib/printer/render.js';
|
|
11
11
|
export { renderValue as renderToken } from './lib/printer/render.js';
|
|
12
12
|
import { ModuleScopeEnumOptions } from './lib/ast/types.js';
|
|
13
|
-
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum,
|
|
13
|
+
export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './lib/ast/types.js';
|
|
14
14
|
import { Tokenizer } from './lib/parser/tokenize.js';
|
|
15
15
|
import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
|
|
16
16
|
import { ResponseType } from './types.js';
|
|
17
17
|
import { SourceFile } from './lib/parser/source.js';
|
|
18
18
|
import { parseResult, validateSyncArguments } from './utils/sync.js';
|
|
19
19
|
export { minify } from './lib/ast/minify.js';
|
|
20
|
-
export { expand } from './lib/ast/expand.js';
|
|
21
|
-
export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
|
|
22
20
|
export { convertColor } from './lib/syntax/color/color.js';
|
|
23
21
|
export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export { replaceNodeOrValue } from './lib/parser/utils/token.js';
|
|
22
|
+
export { Arena, AstArena, TokenField, arenaColumns } from './lib/ast/arena.js';
|
|
23
|
+
export { ARENA, ARENAID, AstArenaNode } from './lib/ast/arena-node.js';
|
|
27
24
|
export { PropertyList } from './lib/parser/declaration/list.js';
|
|
28
25
|
export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
|
|
29
26
|
export { FeatureWalkMode } from './lib/ast/features/type.js';
|
|
30
|
-
export { getNodeProperty, setNodeProperty } from './lib/ast/node.js';
|
|
31
27
|
export { parseSyntax } from './lib/validation/parser/parse.js';
|
|
32
28
|
export { version } from '../package.json.js';
|
|
33
29
|
|
|
@@ -89,13 +85,13 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
89
85
|
* const css = 'body { color: color(from hsl(0 100% 50%) xyz x y z); }';
|
|
90
86
|
* const parseResult = await parse(css);
|
|
91
87
|
*
|
|
92
|
-
* let renderResult = render(parseResult.ast);
|
|
88
|
+
* let renderResult = render(parseResult.arena, parseResult.ast);
|
|
93
89
|
* console.log(result.code);
|
|
94
90
|
*
|
|
95
91
|
* // body{color:red}
|
|
96
92
|
*
|
|
97
93
|
*
|
|
98
|
-
* renderResult = render(parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
|
|
94
|
+
* renderResult = render(parseResult.arena, parseResult.ast, {beautify: true, convertColor: ColorType.SRGB});
|
|
99
95
|
* console.log(renderResult.code);
|
|
100
96
|
*
|
|
101
97
|
* // body {
|
|
@@ -103,8 +99,8 @@ async function load(url, currentDirectory = ".", responseType = false) {
|
|
|
103
99
|
* // }
|
|
104
100
|
* ```
|
|
105
101
|
*/
|
|
106
|
-
function render(data, options = {}, mapping) {
|
|
107
|
-
return doRender(data, Object.assign(options, {
|
|
102
|
+
function render(arena, data, options = {}, mapping) {
|
|
103
|
+
return doRender(arena, data, Object.assign(options, {
|
|
108
104
|
resolve,
|
|
109
105
|
dirname,
|
|
110
106
|
cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
|
|
@@ -112,34 +108,6 @@ function render(data, options = {}, mapping) {
|
|
|
112
108
|
: dirname(self.location.pathname),
|
|
113
109
|
}), mapping);
|
|
114
110
|
}
|
|
115
|
-
/**
|
|
116
|
-
* Parse CSS file
|
|
117
|
-
* @param file url or path
|
|
118
|
-
* @param options
|
|
119
|
-
* @param asStream load file as stream
|
|
120
|
-
*
|
|
121
|
-
* @deprecated
|
|
122
|
-
* @throws Error file not found
|
|
123
|
-
*
|
|
124
|
-
* Example:
|
|
125
|
-
*
|
|
126
|
-
* ```ts
|
|
127
|
-
*
|
|
128
|
-
* import {parseFile} from '@tbela99/css-parser/web';
|
|
129
|
-
*
|
|
130
|
-
* // remote file
|
|
131
|
-
* let result = await parseFile('https://docs.deno.com/styles.css');
|
|
132
|
-
* console.log(result.ast);
|
|
133
|
-
*
|
|
134
|
-
* // local file
|
|
135
|
-
* result = await parseFile('./css/styles.css');
|
|
136
|
-
* console.log(result.ast);
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
async function parseFile(file, options = {}, asStream = false) {
|
|
140
|
-
console.warn("DeprecationWarning: parseFile is deprecated, use parse instead as parse({file, asStream, ...options})");
|
|
141
|
-
return parse({ file, asStream, ...options });
|
|
142
|
-
}
|
|
143
111
|
/**
|
|
144
112
|
* Parse CSS
|
|
145
113
|
* @param args
|
|
@@ -243,7 +211,7 @@ function transformSync(...args) {
|
|
|
243
211
|
importMapping = parseResult.importMapping;
|
|
244
212
|
}
|
|
245
213
|
// ast already expanded by parse
|
|
246
|
-
const rendered = render(parseResult.ast, {
|
|
214
|
+
const rendered = render(parseResult.arena, parseResult.ast, {
|
|
247
215
|
...options,
|
|
248
216
|
expandNestingRules: false,
|
|
249
217
|
}, mapping != null ? { mapping, importMapping } : null);
|
|
@@ -336,36 +304,6 @@ async function parse(...args) {
|
|
|
336
304
|
? result
|
|
337
305
|
: parseResult(result, options));
|
|
338
306
|
}
|
|
339
|
-
/**
|
|
340
|
-
* Transform CSS file
|
|
341
|
-
* @param file url or path
|
|
342
|
-
* @param options
|
|
343
|
-
* @param asStream load file as stream
|
|
344
|
-
*
|
|
345
|
-
* @deprecated
|
|
346
|
-
* Example:
|
|
347
|
-
*
|
|
348
|
-
* ```ts
|
|
349
|
-
*
|
|
350
|
-
* import {transform} from '@tbela99/css-parser/web';
|
|
351
|
-
*
|
|
352
|
-
* // remote file
|
|
353
|
-
* let result = await transform({file: 'https://docs.deno.com/styles.css'});
|
|
354
|
-
* console.log(result.code);
|
|
355
|
-
*
|
|
356
|
-
* // local file
|
|
357
|
-
* result = await transform({file: './css/styles.css'});
|
|
358
|
-
* console.log(result.code);
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
async function transformFile(file, options = {}, asStream = false) {
|
|
362
|
-
console.error("DeprecationWarning: transformFile is deprecated, use transform instead as transform({file, asStream, ...options})");
|
|
363
|
-
return transform({
|
|
364
|
-
file,
|
|
365
|
-
asStream,
|
|
366
|
-
...options,
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
307
|
/**
|
|
370
308
|
* Transform CSS
|
|
371
309
|
*
|
|
@@ -418,7 +356,7 @@ async function transform(...args) {
|
|
|
418
356
|
importMapping = parseResult.importMapping;
|
|
419
357
|
}
|
|
420
358
|
// ast already expanded by parse
|
|
421
|
-
const rendered = render(parseResult.ast, {
|
|
359
|
+
const rendered = render(parseResult.arena, parseResult.ast, {
|
|
422
360
|
...options,
|
|
423
361
|
expandNestingRules: false,
|
|
424
362
|
}, mapping != null ? { mapping, importMapping } : null);
|
|
@@ -436,4 +374,4 @@ async function transform(...args) {
|
|
|
436
374
|
});
|
|
437
375
|
}
|
|
438
376
|
|
|
439
|
-
export { ModuleScopeEnumOptions, ResponseType, dirname, load, parse,
|
|
377
|
+
export { ModuleScopeEnumOptions, ResponseType, dirname, load, parse, parseSync, render, resolve, transform, transformSync };
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser, minifier and validator for node and the browser",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/src/node.js",
|
|
7
7
|
"./node": "./dist/src/node.js",
|
|
8
|
-
"./web": "./dist/src/web.js"
|
|
9
|
-
"./cjs": "./dist/index.cjs"
|
|
8
|
+
"./web": "./dist/src/web.js"
|
|
10
9
|
},
|
|
11
10
|
"type": "module",
|
|
12
11
|
"typings": "dist/index.d.ts",
|
|
@@ -17,16 +16,16 @@
|
|
|
17
16
|
"doc": "typedoc --tsconfig typedoc-tsconfig.jsonc",
|
|
18
17
|
"build": "rollup -c;./build.sh ./dist/index.d.ts 'declare interface' 'declare type'",
|
|
19
18
|
"watch": "rollup -c -w",
|
|
20
|
-
"test:watch": "web-test-runner \"./test
|
|
21
|
-
"test": "web-test-runner \"./test
|
|
22
|
-
"test:web": "web-test-runner \"./test
|
|
23
|
-
"test:node": "mocha -p --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test
|
|
24
|
-
"test:cov": "superc8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' -p --timeout=10000 'test/allFiles.js' 'test
|
|
19
|
+
"test:watch": "web-test-runner \"./test/specs/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --watch",
|
|
20
|
+
"test": "web-test-runner \"./test/specs/web.spec.js\" --timeout=10000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
|
|
21
|
+
"test:web": "web-test-runner \"./test/specs/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.",
|
|
22
|
+
"test:node": "mocha -p --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
|
|
23
|
+
"test:cov": "superc8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' -p --timeout=10000 'test/allFiles.js' 'test/specs/node.spec.js'",
|
|
25
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\"",
|
|
26
25
|
"profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
|
|
27
26
|
"config-update": "esno scripts/shorthand.ts",
|
|
28
27
|
"syntax-update": "esno scripts/validation.ts",
|
|
29
|
-
"debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test
|
|
28
|
+
"debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
|
|
30
29
|
"debug:web": "web-test-runner \"./test/specs/web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
31
30
|
},
|
|
32
31
|
"repository": {
|
|
@@ -91,4 +90,4 @@
|
|
|
91
90
|
"typedoc-unhoax-theme": "^0.5.3"
|
|
92
91
|
},
|
|
93
92
|
"sideEffects": false
|
|
94
|
-
}
|
|
93
|
+
}
|