@tbela99/css-parser 0.1.0 → 0.3.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.
Files changed (40) hide show
  1. package/README.md +267 -2
  2. package/dist/config.json.js +611 -4
  3. package/dist/index-umd-web.js +2898 -1223
  4. package/dist/index.cjs +2898 -1223
  5. package/dist/lib/ast/expand.js +11 -11
  6. package/dist/lib/ast/features/calc.js +33 -224
  7. package/dist/lib/ast/features/index.js +3 -3
  8. package/dist/lib/ast/features/inlinecssvariables.js +46 -31
  9. package/dist/lib/ast/features/shorthand.js +7 -7
  10. package/dist/lib/ast/features/utils/math.js +95 -0
  11. package/dist/lib/ast/math/expression.js +185 -0
  12. package/dist/lib/ast/math/math.js +95 -0
  13. package/dist/lib/ast/minify.js +34 -29
  14. package/dist/lib/ast/types.js +108 -78
  15. package/dist/lib/ast/walk.js +42 -9
  16. package/dist/lib/fs/resolve.js +4 -3
  17. package/dist/lib/iterable/set.js +48 -0
  18. package/dist/lib/iterable/weakmap.js +53 -0
  19. package/dist/lib/iterable/weakset.js +48 -0
  20. package/dist/lib/parser/declaration/list.js +7 -3
  21. package/dist/lib/parser/declaration/map.js +86 -7
  22. package/dist/lib/parser/declaration/set.js +43 -23
  23. package/dist/lib/parser/parse.js +561 -387
  24. package/dist/lib/parser/tokenize.js +42 -13
  25. package/dist/lib/parser/utils/declaration.js +67 -0
  26. package/dist/lib/parser/utils/syntax.js +32 -2
  27. package/dist/lib/parser/utils/type.js +7 -2
  28. package/dist/lib/renderer/render.js +163 -47
  29. package/dist/lib/renderer/utils/calccolor.js +238 -0
  30. package/dist/lib/renderer/utils/color.js +36 -164
  31. package/dist/lib/renderer/utils/hex.js +124 -0
  32. package/dist/lib/renderer/utils/hsl.js +49 -0
  33. package/dist/lib/renderer/utils/hsv.js +15 -0
  34. package/dist/lib/renderer/utils/hwb.js +50 -0
  35. package/dist/lib/renderer/utils/rgb.js +66 -0
  36. package/dist/node/index.js +8 -12
  37. package/dist/web/index.js +8 -12
  38. package/package.json +9 -7
  39. package/dist/index.d.ts +0 -1056
  40. /package/dist/lib/ast/{utiles → utils}/minifyfeature.js +0 -0
@@ -0,0 +1,66 @@
1
+ function hwb2rgb(hue, white, black, alpha = null) {
2
+ const rgb = hsl2rgb(hue, 1, .5);
3
+ for (let i = 0; i < 3; i++) {
4
+ rgb[i] *= (1 - white - black);
5
+ rgb[i] = Math.round(rgb[i] + white);
6
+ }
7
+ if (alpha != null && alpha != 1) {
8
+ rgb.push(alpha);
9
+ }
10
+ return rgb;
11
+ }
12
+ function hsl2rgb(h, s, l, a = null) {
13
+ let v = l <= .5 ? l * (1.0 + s) : l + s - l * s;
14
+ let r = l;
15
+ let g = l;
16
+ let b = l;
17
+ if (v > 0) {
18
+ let m = l + l - v;
19
+ let sv = (v - m) / v;
20
+ h *= 6.0;
21
+ let sextant = Math.floor(h);
22
+ let fract = h - sextant;
23
+ let vsf = v * sv * fract;
24
+ let mid1 = m + vsf;
25
+ let mid2 = v - vsf;
26
+ switch (sextant) {
27
+ case 0:
28
+ r = v;
29
+ g = mid1;
30
+ b = m;
31
+ break;
32
+ case 1:
33
+ r = mid2;
34
+ g = v;
35
+ b = m;
36
+ break;
37
+ case 2:
38
+ r = m;
39
+ g = v;
40
+ b = mid1;
41
+ break;
42
+ case 3:
43
+ r = m;
44
+ g = mid2;
45
+ b = v;
46
+ break;
47
+ case 4:
48
+ r = mid1;
49
+ g = m;
50
+ b = v;
51
+ break;
52
+ case 5:
53
+ r = v;
54
+ g = m;
55
+ b = mid2;
56
+ break;
57
+ }
58
+ }
59
+ const values = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
60
+ if (a != null && a != 1) {
61
+ values.push(Math.round(a * 255));
62
+ }
63
+ return values;
64
+ }
65
+
66
+ export { hsl2rgb, hwb2rgb };
@@ -1,18 +1,14 @@
1
- export { EnumToken, NodeType } from '../lib/ast/types.js';
2
- export { combinators, hasDeclaration, minify, reduceSelector, splitRule } from '../lib/ast/minify.js';
1
+ export { EnumToken } from '../lib/ast/types.js';
2
+ export { minify } from '../lib/ast/minify.js';
3
3
  export { walk, walkValues } from '../lib/ast/walk.js';
4
- export { expand, replaceCompound } from '../lib/ast/expand.js';
4
+ export { expand } from '../lib/ast/expand.js';
5
5
  import { doRender } from '../lib/renderer/render.js';
6
- export { colorsFunc, reduceNumber, renderToken } from '../lib/renderer/render.js';
6
+ export { renderToken } from '../lib/renderer/render.js';
7
7
  import { doParse } from '../lib/parser/parse.js';
8
- export { parseString, parseTokens, urlTokenMatcher } from '../lib/parser/parse.js';
9
- export { tokenize } from '../lib/parser/tokenize.js';
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';
11
- export { getConfig } from '../lib/parser/utils/config.js';
12
- export { funcList, matchType } from '../lib/parser/utils/type.js';
13
- import { load } from './load.js';
8
+ export { parseString, parseTokens } from '../lib/parser/parse.js';
9
+ import '../lib/renderer/utils/color.js';
14
10
  import { resolve, dirname } from '../lib/fs/resolve.js';
15
- export { matchUrl } from '../lib/fs/resolve.js';
11
+ import { load } from './load.js';
16
12
 
17
13
  function render(data, options = {}) {
18
14
  return doRender(data, Object.assign(options, { load, resolve, dirname, cwd: options.cwd ?? process.cwd() }));
@@ -39,4 +35,4 @@ async function transform(css, options = {}) {
39
35
  });
40
36
  }
41
37
 
42
- export { dirname, doParse, doRender, load, parse, render, resolve, transform };
38
+ export { dirname, load, parse, render, resolve, transform };
package/dist/web/index.js CHANGED
@@ -1,18 +1,14 @@
1
- export { EnumToken, NodeType } from '../lib/ast/types.js';
2
- export { combinators, hasDeclaration, minify, reduceSelector, splitRule } from '../lib/ast/minify.js';
1
+ export { EnumToken } from '../lib/ast/types.js';
2
+ export { minify } from '../lib/ast/minify.js';
3
3
  export { walk, walkValues } from '../lib/ast/walk.js';
4
- export { expand, replaceCompound } from '../lib/ast/expand.js';
4
+ export { expand } from '../lib/ast/expand.js';
5
5
  import { doRender } from '../lib/renderer/render.js';
6
- export { colorsFunc, reduceNumber, renderToken } from '../lib/renderer/render.js';
6
+ export { renderToken } from '../lib/renderer/render.js';
7
7
  import { doParse } from '../lib/parser/parse.js';
8
- export { parseString, parseTokens, urlTokenMatcher } from '../lib/parser/parse.js';
9
- export { tokenize } from '../lib/parser/tokenize.js';
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';
11
- export { getConfig } from '../lib/parser/utils/config.js';
12
- export { funcList, matchType } from '../lib/parser/utils/type.js';
13
- import { load } from './load.js';
8
+ export { parseString, parseTokens } from '../lib/parser/parse.js';
9
+ import '../lib/renderer/utils/color.js';
14
10
  import { resolve, dirname } from '../lib/fs/resolve.js';
15
- export { matchUrl } from '../lib/fs/resolve.js';
11
+ import { load } from './load.js';
16
12
 
17
13
  function render(data, options = {}) {
18
14
  return doRender(data, Object.assign(options, {
@@ -49,4 +45,4 @@ async function transform(css, options = {}) {
49
45
  });
50
46
  }
51
47
 
52
- export { dirname, doParse, doRender, load, parse, render, resolve, transform };
48
+ export { dirname, 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.1.0",
4
+ "version": "0.3.0",
5
5
  "exports": {
6
6
  ".": "./dist/node/index.js",
7
7
  "./umd": "./dist/index-umd-web.js",
@@ -11,12 +11,12 @@
11
11
  "type": "module",
12
12
  "typings": "dist/index.d.ts",
13
13
  "scripts": {
14
- "build": "rollup -c",
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",
14
+ "build": "rollup -c;./build.sh dist/index.d.ts 'declare interface' 'declare type'",
15
+ "test": "web-test-runner \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --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 --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
18
18
  "profile": "node --inspect-brk test/inspect.mjs",
19
- "debug": "web-test-runner \"test/**/*.web.spec.js\" --manual --open --node-resolve --root-dir=."
19
+ "debug": "web-test-runner \"test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -34,7 +34,8 @@
34
34
  "browser",
35
35
  "css-nesting",
36
36
  "css-compiler",
37
- "nested-css"
37
+ "nested-css",
38
+ "walker"
38
39
  ],
39
40
  "author": "Thierry Bela",
40
41
  "license": "MIT OR LGPL-3.0",
@@ -52,6 +53,7 @@
52
53
  "@types/mocha": "^10.0.1",
53
54
  "@types/node": "^20.4.10",
54
55
  "@web/test-runner": "^0.17.0",
56
+ "@web/test-runner-playwright": "^0.11.0",
55
57
  "c8": "^8.0.1",
56
58
  "mocha": "^10.2.0",
57
59
  "rollup": "^3.28.0",