@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.
@@ -1,23 +1,42 @@
1
- export { combinators, hasDeclaration, minify, minifyRule, reduceSelector, splitRule } from '../lib/ast/minify.js';
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
- export { colorsFunc, render, renderToken } from '../lib/renderer/render.js';
5
- import { parse as parse$1 } from '../lib/parser/parse.js';
6
- export { parseString, urlTokenMatcher } from '../lib/parser/parse.js';
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 { dirname, matchUrl } from '../lib/fs/resolve.js';
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 parse$1(iterator, Object.assign(opt, { load, resolve, cwd: opt.cwd ?? process.cwd() }));
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
- return transform$1(css, Object.assign(options, { load, resolve, cwd: options.cwd ?? process.cwd() }));
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 { combinators, hasDeclaration, minify, minifyRule, reduceSelector, splitRule } from '../lib/ast/minify.js';
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
- export { colorsFunc, render, renderToken } from '../lib/renderer/render.js';
5
- import { parse as parse$1 } from '../lib/parser/parse.js';
6
- export { parseString, urlTokenMatcher } from '../lib/parser/parse.js';
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
- async function parse(iterator, opt = {}) {
17
- return parse$1(iterator, Object.assign(opt, {
17
+ function render(data, options = {}) {
18
+ return doRender(data, Object.assign(options, {
18
19
  load,
19
20
  resolve,
20
- cwd: opt.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
21
+ dirname,
22
+ cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
21
23
  }));
22
24
  }
23
- async function transform(css, options = {}) {
24
- return transform$1(css, Object.assign(options, {
25
+ async function parse(iterator, opt = {}) {
26
+ return doParse(iterator, Object.assign(opt, {
25
27
  load,
26
28
  resolve,
27
- cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
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.1-rc7",
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-spec.js\" --node-resolve --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.spec.js\"",
16
- "test:cov": "web-test-runner \"test/**/*.web-spec.js\" --node-resolve --root-dir=. --coverage; c8 --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' \"test/**/*.spec.js\"",
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",
@@ -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 };