@tbela99/css-parser 1.3.0 → 1.3.2
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 +10 -0
- package/README.md +28 -10
- package/dist/index-umd-web.js +1610 -1170
- package/dist/index.cjs +1699 -1168
- package/dist/index.d.ts +1834 -71
- package/dist/lib/ast/expand.js +4 -65
- package/dist/lib/ast/features/calc.js +2 -2
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +2 -1
- package/dist/lib/ast/features/transform.js +2 -1
- package/dist/lib/ast/features/type.js +9 -0
- package/dist/lib/ast/math/math.js +1 -1
- package/dist/lib/ast/minify.js +82 -171
- package/dist/lib/ast/types.js +369 -4
- package/dist/lib/ast/walk.js +18 -0
- package/dist/lib/fs/resolve.js +11 -3
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/parse.js +106 -21
- package/dist/lib/parser/tokenize.js +40 -80
- package/dist/lib/renderer/render.js +25 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +34 -0
- package/dist/lib/syntax/color/color.js +7 -0
- package/dist/lib/syntax/color/utils/distance.js +5 -1
- package/dist/lib/syntax/syntax.js +10 -0
- package/dist/lib/validation/config.json.js +33 -30
- package/dist/lib/validation/syntax.js +3 -1
- package/dist/node.js +229 -0
- package/dist/web.js +158 -0
- package/package.json +14 -11
- package/dist/node/index.js +0 -57
- package/dist/node/load.js +0 -20
- package/dist/web/index.js +0 -66
- package/dist/web/load.js +0 -31
package/dist/node/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import process from 'node:process';
|
|
2
|
-
export { ColorType, EnumToken, ValidationLevel } from '../lib/ast/types.js';
|
|
3
|
-
export { minify } from '../lib/ast/minify.js';
|
|
4
|
-
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
5
|
-
export { expand } from '../lib/ast/expand.js';
|
|
6
|
-
import { doRender } from '../lib/renderer/render.js';
|
|
7
|
-
export { renderToken } from '../lib/renderer/render.js';
|
|
8
|
-
import '../lib/syntax/color/utils/constants.js';
|
|
9
|
-
export { convertColor } from '../lib/syntax/color/color.js';
|
|
10
|
-
export { isOkLabClose, okLabDistance } from '../lib/syntax/color/utils/distance.js';
|
|
11
|
-
import { doParse } from '../lib/parser/parse.js';
|
|
12
|
-
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
13
|
-
import '../lib/parser/tokenize.js';
|
|
14
|
-
import '../lib/parser/utils/config.js';
|
|
15
|
-
import '../lib/validation/config.js';
|
|
16
|
-
import '../lib/validation/parser/types.js';
|
|
17
|
-
import '../lib/validation/parser/parse.js';
|
|
18
|
-
import '../lib/validation/syntaxes/complex-selector.js';
|
|
19
|
-
import '../lib/validation/syntax.js';
|
|
20
|
-
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
21
|
-
import { load } from './load.js';
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* render ast node
|
|
25
|
-
*/
|
|
26
|
-
function render(data, options = {}) {
|
|
27
|
-
return doRender(data, Object.assign(options, { load, resolve, dirname, cwd: options.cwd ?? process.cwd() }));
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* parse css
|
|
31
|
-
*/
|
|
32
|
-
async function parse(iterator, opt = {}) {
|
|
33
|
-
return doParse(iterator, Object.assign(opt, { load, resolve, dirname, cwd: opt.cwd ?? process.cwd() }));
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* parse and render css
|
|
37
|
-
*/
|
|
38
|
-
async function transform(css, options = {}) {
|
|
39
|
-
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
40
|
-
const startTime = performance.now();
|
|
41
|
-
return parse(css, options).then((parseResult) => {
|
|
42
|
-
const rendered = render(parseResult.ast, options);
|
|
43
|
-
return {
|
|
44
|
-
...parseResult,
|
|
45
|
-
...rendered,
|
|
46
|
-
errors: parseResult.errors.concat(rendered.errors),
|
|
47
|
-
stats: {
|
|
48
|
-
bytesOut: rendered.code.length,
|
|
49
|
-
...parseResult.stats,
|
|
50
|
-
render: rendered.stats.total,
|
|
51
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { dirname, load, parse, render, resolve, transform };
|
package/dist/node/load.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises';
|
|
2
|
-
import { resolve, matchUrl } from '../lib/fs/resolve.js';
|
|
3
|
-
|
|
4
|
-
function parseResponse(response) {
|
|
5
|
-
if (!response.ok) {
|
|
6
|
-
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|
|
7
|
-
}
|
|
8
|
-
return response.text();
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* load file
|
|
12
|
-
* @param url
|
|
13
|
-
* @param currentFile
|
|
14
|
-
*/
|
|
15
|
-
async function load(url, currentFile = '.') {
|
|
16
|
-
const resolved = resolve(url, currentFile);
|
|
17
|
-
return matchUrl.test(resolved.absolute) ? fetch(resolved.absolute).then(parseResponse) : readFile(resolved.absolute, { encoding: 'utf-8' });
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { load };
|
package/dist/web/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
export { ColorType, EnumToken, ValidationLevel } from '../lib/ast/types.js';
|
|
2
|
-
export { minify } from '../lib/ast/minify.js';
|
|
3
|
-
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
4
|
-
export { expand } from '../lib/ast/expand.js';
|
|
5
|
-
import { doRender } from '../lib/renderer/render.js';
|
|
6
|
-
export { renderToken } from '../lib/renderer/render.js';
|
|
7
|
-
import '../lib/syntax/color/utils/constants.js';
|
|
8
|
-
export { convertColor } from '../lib/syntax/color/color.js';
|
|
9
|
-
export { isOkLabClose, okLabDistance } from '../lib/syntax/color/utils/distance.js';
|
|
10
|
-
import { doParse } from '../lib/parser/parse.js';
|
|
11
|
-
export { parseString, parseTokens } from '../lib/parser/parse.js';
|
|
12
|
-
import '../lib/parser/tokenize.js';
|
|
13
|
-
import '../lib/parser/utils/config.js';
|
|
14
|
-
import '../lib/validation/config.js';
|
|
15
|
-
import '../lib/validation/parser/types.js';
|
|
16
|
-
import '../lib/validation/parser/parse.js';
|
|
17
|
-
import '../lib/validation/syntaxes/complex-selector.js';
|
|
18
|
-
import '../lib/validation/syntax.js';
|
|
19
|
-
import { dirname, resolve } from '../lib/fs/resolve.js';
|
|
20
|
-
import { load } from './load.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* render ast node
|
|
24
|
-
*/
|
|
25
|
-
function render(data, options = {}) {
|
|
26
|
-
return doRender(data, Object.assign(options, {
|
|
27
|
-
load,
|
|
28
|
-
resolve,
|
|
29
|
-
dirname,
|
|
30
|
-
cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* parse css
|
|
35
|
-
*/
|
|
36
|
-
async function parse(iterator, opt = {}) {
|
|
37
|
-
return doParse(iterator, Object.assign(opt, {
|
|
38
|
-
load,
|
|
39
|
-
resolve,
|
|
40
|
-
dirname,
|
|
41
|
-
cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* parse and render css
|
|
46
|
-
*/
|
|
47
|
-
async function transform(css, options = {}) {
|
|
48
|
-
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
49
|
-
const startTime = performance.now();
|
|
50
|
-
return parse(css, options).then((parseResult) => {
|
|
51
|
-
const rendered = render(parseResult.ast, options);
|
|
52
|
-
return {
|
|
53
|
-
...parseResult,
|
|
54
|
-
...rendered,
|
|
55
|
-
errors: parseResult.errors.concat(rendered.errors),
|
|
56
|
-
stats: {
|
|
57
|
-
bytesOut: rendered.code.length,
|
|
58
|
-
...parseResult.stats,
|
|
59
|
-
render: rendered.stats.total,
|
|
60
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { dirname, load, parse, render, resolve, transform };
|
package/dist/web/load.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { matchUrl, resolve } from '../lib/fs/resolve.js';
|
|
2
|
-
|
|
3
|
-
function parseResponse(response) {
|
|
4
|
-
if (!response.ok) {
|
|
5
|
-
throw new Error(`${response.status} ${response.statusText} ${response.url}`);
|
|
6
|
-
}
|
|
7
|
-
return response.text();
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* load file
|
|
11
|
-
* @param url
|
|
12
|
-
* @param currentFile
|
|
13
|
-
*/
|
|
14
|
-
async function load(url, currentFile) {
|
|
15
|
-
let t;
|
|
16
|
-
if (matchUrl.test(url)) {
|
|
17
|
-
t = new URL(url);
|
|
18
|
-
}
|
|
19
|
-
else if (matchUrl.test(currentFile)) {
|
|
20
|
-
t = new URL(url, currentFile);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
const path = resolve(url, currentFile).absolute;
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
t = new URL(path, self.origin);
|
|
26
|
-
}
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
return fetch(t, t.origin != self.origin ? { mode: 'cors' } : {}).then(parseResponse);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { load };
|