@tbela99/css-parser 0.0.1-rc7 → 0.1.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/README.md +157 -41
- package/dist/index-umd-web.js +2058 -1242
- package/dist/index.cjs +2052 -1238
- package/dist/index.d.ts +677 -332
- package/dist/lib/ast/expand.js +14 -20
- package/dist/lib/ast/features/calc.js +256 -0
- package/dist/lib/ast/features/index.js +3 -0
- package/dist/lib/ast/features/inlinecssvariables.js +115 -0
- package/dist/lib/ast/features/shorthand.js +45 -0
- package/dist/lib/ast/minify.js +395 -371
- package/dist/lib/ast/types.js +88 -0
- package/dist/lib/ast/utiles/minifyfeature.js +8 -0
- package/dist/lib/ast/walk.js +24 -9
- package/dist/lib/parser/declaration/list.js +18 -4
- package/dist/lib/parser/declaration/map.js +51 -30
- package/dist/lib/parser/declaration/set.js +18 -12
- package/dist/lib/parser/parse.js +176 -136
- package/dist/lib/parser/tokenize.js +42 -35
- package/dist/lib/parser/utils/eq.js +1 -1
- package/dist/lib/parser/utils/syntax.js +13 -10
- package/dist/lib/parser/utils/type.js +18 -6
- package/dist/lib/renderer/render.js +201 -79
- package/dist/lib/renderer/sourcemap/lib/encode.js +37 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +58 -0
- package/dist/lib/renderer/utils/color.js +25 -20
- package/dist/node/index.js +29 -10
- package/dist/web/index.js +33 -12
- package/package.json +5 -4
- package/dist/lib/transform.js +0 -24
package/dist/node/index.js
CHANGED
|
@@ -1,23 +1,42 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EnumToken, NodeType } from '../lib/ast/types.js';
|
|
2
|
+
export { combinators, hasDeclaration, minify, reduceSelector, splitRule } from '../lib/ast/minify.js';
|
|
2
3
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
3
4
|
export { expand, replaceCompound } from '../lib/ast/expand.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { doRender } from '../lib/renderer/render.js';
|
|
6
|
+
export { colorsFunc, reduceNumber, renderToken } from '../lib/renderer/render.js';
|
|
7
|
+
import { doParse } from '../lib/parser/parse.js';
|
|
8
|
+
export { parseString, parseTokens, urlTokenMatcher } from '../lib/parser/parse.js';
|
|
7
9
|
export { tokenize } from '../lib/parser/tokenize.js';
|
|
8
10
|
export { isAngle, isAtKeyword, isColor, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, parseDimension } from '../lib/parser/utils/syntax.js';
|
|
9
11
|
export { getConfig } from '../lib/parser/utils/config.js';
|
|
10
12
|
export { funcList, matchType } from '../lib/parser/utils/type.js';
|
|
11
|
-
import { transform as transform$1 } from '../lib/transform.js';
|
|
12
13
|
import { load } from './load.js';
|
|
13
|
-
import { resolve } from '../lib/fs/resolve.js';
|
|
14
|
-
export {
|
|
14
|
+
import { resolve, dirname } from '../lib/fs/resolve.js';
|
|
15
|
+
export { matchUrl } from '../lib/fs/resolve.js';
|
|
15
16
|
|
|
17
|
+
function render(data, options = {}) {
|
|
18
|
+
return doRender(data, Object.assign(options, { load, resolve, dirname, cwd: options.cwd ?? process.cwd() }));
|
|
19
|
+
}
|
|
16
20
|
async function parse(iterator, opt = {}) {
|
|
17
|
-
return
|
|
21
|
+
return doParse(iterator, Object.assign(opt, { load, resolve, dirname, cwd: opt.cwd ?? process.cwd() }));
|
|
18
22
|
}
|
|
19
23
|
async function transform(css, options = {}) {
|
|
20
|
-
|
|
24
|
+
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
25
|
+
const startTime = performance.now();
|
|
26
|
+
return parse(css, options).then((parseResult) => {
|
|
27
|
+
const rendered = render(parseResult.ast, options);
|
|
28
|
+
return {
|
|
29
|
+
...parseResult,
|
|
30
|
+
...rendered,
|
|
31
|
+
errors: parseResult.errors.concat(rendered.errors),
|
|
32
|
+
stats: {
|
|
33
|
+
bytesOut: rendered.code.length,
|
|
34
|
+
...parseResult.stats,
|
|
35
|
+
render: rendered.stats.total,
|
|
36
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
});
|
|
21
40
|
}
|
|
22
41
|
|
|
23
|
-
export { load, parse, resolve, transform };
|
|
42
|
+
export { dirname, doParse, doRender, load, parse, render, resolve, transform };
|
package/dist/web/index.js
CHANGED
|
@@ -1,31 +1,52 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { EnumToken, NodeType } from '../lib/ast/types.js';
|
|
2
|
+
export { combinators, hasDeclaration, minify, reduceSelector, splitRule } from '../lib/ast/minify.js';
|
|
2
3
|
export { walk, walkValues } from '../lib/ast/walk.js';
|
|
3
4
|
export { expand, replaceCompound } from '../lib/ast/expand.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { doRender } from '../lib/renderer/render.js';
|
|
6
|
+
export { colorsFunc, reduceNumber, renderToken } from '../lib/renderer/render.js';
|
|
7
|
+
import { doParse } from '../lib/parser/parse.js';
|
|
8
|
+
export { parseString, parseTokens, urlTokenMatcher } from '../lib/parser/parse.js';
|
|
7
9
|
export { tokenize } from '../lib/parser/tokenize.js';
|
|
8
10
|
export { isAngle, isAtKeyword, isColor, isDigit, isDimension, isFrequency, isFunction, isHash, isHexColor, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPseudo, isResolution, isTime, isWhiteSpace, parseDimension } from '../lib/parser/utils/syntax.js';
|
|
9
11
|
export { getConfig } from '../lib/parser/utils/config.js';
|
|
10
12
|
export { funcList, matchType } from '../lib/parser/utils/type.js';
|
|
11
|
-
import { transform as transform$1 } from '../lib/transform.js';
|
|
12
13
|
import { load } from './load.js';
|
|
13
14
|
import { resolve, dirname } from '../lib/fs/resolve.js';
|
|
14
15
|
export { matchUrl } from '../lib/fs/resolve.js';
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
return
|
|
17
|
+
function render(data, options = {}) {
|
|
18
|
+
return doRender(data, Object.assign(options, {
|
|
18
19
|
load,
|
|
19
20
|
resolve,
|
|
20
|
-
|
|
21
|
+
dirname,
|
|
22
|
+
cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
21
23
|
}));
|
|
22
24
|
}
|
|
23
|
-
async function
|
|
24
|
-
return
|
|
25
|
+
async function parse(iterator, opt = {}) {
|
|
26
|
+
return doParse(iterator, Object.assign(opt, {
|
|
25
27
|
load,
|
|
26
28
|
resolve,
|
|
27
|
-
|
|
29
|
+
dirname,
|
|
30
|
+
cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
|
|
28
31
|
}));
|
|
29
32
|
}
|
|
33
|
+
async function transform(css, options = {}) {
|
|
34
|
+
options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
|
|
35
|
+
const startTime = performance.now();
|
|
36
|
+
return parse(css, options).then((parseResult) => {
|
|
37
|
+
const rendered = render(parseResult.ast, options);
|
|
38
|
+
return {
|
|
39
|
+
...parseResult,
|
|
40
|
+
...rendered,
|
|
41
|
+
errors: parseResult.errors.concat(rendered.errors),
|
|
42
|
+
stats: {
|
|
43
|
+
bytesOut: rendered.code.length,
|
|
44
|
+
...parseResult.stats,
|
|
45
|
+
render: rendered.stats.total,
|
|
46
|
+
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
30
51
|
|
|
31
|
-
export { dirname, load, parse, resolve, transform };
|
|
52
|
+
export { dirname, doParse, doRender, load, parse, render, resolve, transform };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbela99/css-parser",
|
|
3
3
|
"description": "CSS parser for node and the browser",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/node/index.js",
|
|
7
7
|
"./umd": "./dist/index-umd-web.js",
|
|
@@ -12,10 +12,11 @@
|
|
|
12
12
|
"typings": "dist/index.d.ts",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "rollup -c",
|
|
15
|
-
"test": "web-test-runner \"test/**/*.web
|
|
16
|
-
"test:cov": "
|
|
15
|
+
"test": "web-test-runner \"test/**/*.web.spec.js\" --node-resolve --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.node.spec.js\"",
|
|
16
|
+
"test:cov": "c8 --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.node.spec.js\"",
|
|
17
|
+
"test:web-cov": "web-test-runner \"test/**/*.web.spec.js\" --node-resolve --root-dir=. --coverage",
|
|
17
18
|
"profile": "node --inspect-brk test/inspect.mjs",
|
|
18
|
-
"debug": "web-test-runner \"test/**/*.web.js\" --manual --open --node-resolve --root-dir=."
|
|
19
|
+
"debug": "web-test-runner \"test/**/*.web.spec.js\" --manual --open --node-resolve --root-dir=."
|
|
19
20
|
},
|
|
20
21
|
"repository": {
|
|
21
22
|
"type": "git",
|
package/dist/lib/transform.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { parse } from './parser/parse.js';
|
|
2
|
-
import { render } from './renderer/render.js';
|
|
3
|
-
import './renderer/utils/color.js';
|
|
4
|
-
|
|
5
|
-
async function transform(css, options = {}) {
|
|
6
|
-
options = { minify: true, removeEmpty: true, ...options };
|
|
7
|
-
const startTime = performance.now();
|
|
8
|
-
return parse(css, options).then((parseResult) => {
|
|
9
|
-
const rendered = render(parseResult.ast, options);
|
|
10
|
-
return {
|
|
11
|
-
...parseResult,
|
|
12
|
-
...rendered,
|
|
13
|
-
errors: parseResult.errors.concat(rendered.errors),
|
|
14
|
-
stats: {
|
|
15
|
-
bytesOut: rendered.code.length,
|
|
16
|
-
...parseResult.stats,
|
|
17
|
-
render: rendered.stats.total,
|
|
18
|
-
total: `${(performance.now() - startTime).toFixed(2)}ms`
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { transform };
|