@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.
@@ -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 };