@tbela99/css-parser 1.4.2 → 1.4.4

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 (122) hide show
  1. package/CHANGELOG.md +354 -4
  2. package/README.md +69 -1077
  3. package/dist/config.json.js +76 -3
  4. package/dist/index-umd-web.js +26838 -18743
  5. package/dist/index.cjs +26819 -18731
  6. package/dist/index.d.ts +2471 -1884
  7. package/dist/lib/ast/clone.js +46 -0
  8. package/dist/lib/ast/expand.js +90 -65
  9. package/dist/lib/ast/features/calc.js +86 -43
  10. package/dist/lib/ast/features/if.js +221 -0
  11. package/dist/lib/ast/features/index.js +1 -0
  12. package/dist/lib/ast/features/inlinecssvariables.js +33 -28
  13. package/dist/lib/ast/features/prefix.js +406 -44
  14. package/dist/lib/ast/features/shorthand.js +6 -9
  15. package/dist/lib/ast/features/transform.js +14 -15
  16. package/dist/lib/ast/find.js +175 -0
  17. package/dist/lib/ast/math/expression.js +145 -99
  18. package/dist/lib/ast/math/math.js +30 -41
  19. package/dist/lib/ast/minify.js +551 -232
  20. package/dist/lib/ast/transform/compute.js +82 -69
  21. package/dist/lib/ast/transform/matrix.js +12 -26
  22. package/dist/lib/ast/transform/minify.js +154 -150
  23. package/dist/lib/ast/transform/perspective.js +1 -1
  24. package/dist/lib/ast/transform/rotate.js +1 -1
  25. package/dist/lib/ast/transform/scale.js +1 -1
  26. package/dist/lib/ast/transform/skew.js +1 -1
  27. package/dist/lib/ast/transform/translate.js +1 -1
  28. package/dist/lib/ast/transform/utils.js +3 -2
  29. package/dist/lib/ast/types.js +345 -30
  30. package/dist/lib/ast/walk.js +119 -64
  31. package/dist/lib/fs/resolve.js +94 -88
  32. package/dist/lib/parser/declaration/list.js +117 -26
  33. package/dist/lib/parser/declaration/map.js +141 -96
  34. package/dist/lib/parser/declaration/set.js +30 -25
  35. package/dist/lib/parser/parse.js +1810 -1739
  36. package/dist/lib/parser/tokenize.js +662 -403
  37. package/dist/lib/parser/utils/angle.js +29 -0
  38. package/dist/lib/parser/utils/at-rule-container.js +486 -0
  39. package/dist/lib/parser/utils/at-rule-font-feature-values.js +13 -0
  40. package/dist/lib/parser/utils/at-rule-generic.js +118 -0
  41. package/dist/lib/parser/utils/at-rule-import.js +393 -0
  42. package/dist/lib/parser/utils/at-rule-media.js +603 -0
  43. package/dist/lib/parser/utils/at-rule-support.js +431 -0
  44. package/dist/lib/parser/utils/at-rule-when-else.js +363 -0
  45. package/dist/lib/parser/utils/at-rule.js +31 -0
  46. package/dist/lib/parser/utils/cache.js +19 -0
  47. package/dist/lib/parser/utils/config.js +1 -0
  48. package/dist/lib/parser/utils/declaration.js +672 -91
  49. package/dist/lib/parser/utils/hash.js +1 -1
  50. package/dist/lib/parser/utils/selector.js +518 -0
  51. package/dist/lib/parser/utils/text.js +17 -1
  52. package/dist/lib/parser/utils/token.js +104 -0
  53. package/dist/lib/parser/utils/type.js +29 -18
  54. package/dist/lib/renderer/render.js +870 -269
  55. package/dist/lib/renderer/sourcemap/sourcemap.js +17 -7
  56. package/dist/lib/syntax/color/a98rgb.js +8 -12
  57. package/dist/lib/syntax/color/alpha.js +64 -0
  58. package/dist/lib/syntax/color/cmyk.js +23 -21
  59. package/dist/lib/syntax/color/color-mix.js +311 -237
  60. package/dist/lib/syntax/color/color.js +98 -92
  61. package/dist/lib/syntax/color/hex.js +29 -33
  62. package/dist/lib/syntax/color/hsl.js +7 -14
  63. package/dist/lib/syntax/color/hwb.js +14 -27
  64. package/dist/lib/syntax/color/lab.js +23 -24
  65. package/dist/lib/syntax/color/lch.js +16 -18
  66. package/dist/lib/syntax/color/oklab.js +21 -40
  67. package/dist/lib/syntax/color/oklch.js +16 -18
  68. package/dist/lib/syntax/color/p3.js +0 -8
  69. package/dist/lib/syntax/color/rec2020.js +9 -13
  70. package/dist/lib/syntax/color/relativecolor.js +160 -48
  71. package/dist/lib/syntax/color/rgb.js +14 -18
  72. package/dist/lib/syntax/color/srgb.js +30 -29
  73. package/dist/lib/syntax/color/utils/color-type.js +18 -0
  74. package/dist/lib/syntax/color/utils/colorspace.js +46 -0
  75. package/dist/lib/syntax/color/utils/components.js +36 -16
  76. package/dist/lib/syntax/color/utils/distance.js +21 -11
  77. package/dist/lib/syntax/color/utils/make-color.js +56 -0
  78. package/dist/lib/syntax/color/xyz.js +10 -22
  79. package/dist/lib/syntax/color/xyzd50.js +6 -20
  80. package/dist/lib/syntax/constants.js +464 -0
  81. package/dist/lib/syntax/syntax.js +825 -592
  82. package/dist/lib/validation/config.js +72 -33
  83. package/dist/lib/validation/config.json.js +1185 -85
  84. package/dist/lib/validation/match.js +3120 -0
  85. package/dist/lib/validation/parser/parse.js +683 -935
  86. package/dist/lib/validation/parser/typedef.js +106 -0
  87. package/dist/lib/validation/utils/list.js +4 -11
  88. package/dist/lib/validation/utils/whitespace.js +2 -8
  89. package/dist/node.js +102 -57
  90. package/dist/web.js +100 -48
  91. package/package.json +31 -17
  92. package/dist/lib/syntax/color/utils/constants.js +0 -214
  93. package/dist/lib/syntax/utils.js +0 -70
  94. package/dist/lib/validation/at-rules/container.js +0 -342
  95. package/dist/lib/validation/at-rules/counter-style.js +0 -90
  96. package/dist/lib/validation/at-rules/custom-media.js +0 -50
  97. package/dist/lib/validation/at-rules/document.js +0 -89
  98. package/dist/lib/validation/at-rules/else.js +0 -5
  99. package/dist/lib/validation/at-rules/font-feature-values.js +0 -63
  100. package/dist/lib/validation/at-rules/import.js +0 -150
  101. package/dist/lib/validation/at-rules/keyframes.js +0 -67
  102. package/dist/lib/validation/at-rules/layer.js +0 -41
  103. package/dist/lib/validation/at-rules/media.js +0 -255
  104. package/dist/lib/validation/at-rules/namespace.js +0 -81
  105. package/dist/lib/validation/at-rules/page-margin-box.js +0 -64
  106. package/dist/lib/validation/at-rules/page.js +0 -100
  107. package/dist/lib/validation/at-rules/supports.js +0 -295
  108. package/dist/lib/validation/at-rules/when.js +0 -185
  109. package/dist/lib/validation/atrule.js +0 -184
  110. package/dist/lib/validation/selector.js +0 -36
  111. package/dist/lib/validation/syntax.js +0 -1073
  112. package/dist/lib/validation/syntaxes/complex-selector-list.js +0 -27
  113. package/dist/lib/validation/syntaxes/complex-selector.js +0 -52
  114. package/dist/lib/validation/syntaxes/compound-selector.js +0 -196
  115. package/dist/lib/validation/syntaxes/family-name.js +0 -57
  116. package/dist/lib/validation/syntaxes/keyframe-selector.js +0 -36
  117. package/dist/lib/validation/syntaxes/layer-name.js +0 -57
  118. package/dist/lib/validation/syntaxes/relative-selector-list.js +0 -31
  119. package/dist/lib/validation/syntaxes/relative-selector.js +0 -38
  120. package/dist/lib/validation/syntaxes/selector-list.js +0 -5
  121. package/dist/lib/validation/syntaxes/selector.js +0 -5
  122. package/dist/lib/validation/syntaxes/url.js +0 -40
package/dist/web.js CHANGED
@@ -1,28 +1,25 @@
1
+ import { doParse } from './lib/parser/parse.js';
2
+ export { parseDeclarations, parseString } from './lib/parser/parse.js';
3
+ import { doRender } from './lib/renderer/render.js';
4
+ export { renderValue as renderToken } from './lib/renderer/render.js';
1
5
  import { ModuleScopeEnumOptions } from './lib/ast/types.js';
2
- export { ColorType, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
6
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, ValidationLevel } from './lib/ast/types.js';
7
+ import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
8
+ import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
9
+ import { ResponseType } from './types.js';
3
10
  export { minify } from './lib/ast/minify.js';
4
- export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
5
11
  export { expand } from './lib/ast/expand.js';
6
- import { doRender } from './lib/renderer/render.js';
7
- export { renderToken } from './lib/renderer/render.js';
8
- export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
9
- import { doParse } from './lib/parser/parse.js';
10
- export { parseDeclarations, parseString, parseTokens } from './lib/parser/parse.js';
11
- import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
12
- import './lib/parser/utils/config.js';
12
+ export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
13
13
  export { convertColor } from './lib/syntax/color/color.js';
14
- import './lib/syntax/color/utils/constants.js';
15
14
  export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
16
- import './lib/validation/config.js';
17
- import './lib/validation/parser/parse.js';
18
- import './lib/validation/syntaxes/complex-selector.js';
19
- import './lib/validation/syntax.js';
20
- import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
21
- import { ResponseType } from './types.js';
15
+ export { find, findAll, findByValue, findLast } from './lib/ast/find.js';
16
+ export { cloneNode } from './lib/ast/clone.js';
17
+ export { replaceNodeOrValue } from './lib/parser/utils/token.js';
18
+ export { SourceMap } from './lib/renderer/sourcemap/sourcemap.js';
22
19
  export { FeatureWalkMode } from './lib/ast/features/type.js';
23
20
 
24
21
  /**
25
- * load file or url
22
+ * Load file or url
26
23
  * @param url
27
24
  * @param currentDirectory
28
25
  * @param responseType
@@ -33,12 +30,15 @@ export { FeatureWalkMode } from './lib/ast/features/type.js';
33
30
  * const result = await load(file, '.', ResponseType.ArrayBuffer) as ArrayBuffer;
34
31
  * ```
35
32
  */
36
- async function load(url, currentDirectory = '.', responseType = false) {
37
- if (typeof responseType == 'boolean') {
33
+ async function load(url, currentDirectory = ".", responseType = false) {
34
+ if (typeof responseType == "boolean") {
38
35
  responseType = responseType ? ResponseType.ReadableStream : ResponseType.Text;
39
36
  }
40
37
  let t;
41
- if (matchUrl.test(url)) {
38
+ if (typeof url == "object") {
39
+ t = new URL(url.absolute, self.origin);
40
+ }
41
+ else if (matchUrl.test(url)) {
42
42
  t = new URL(url);
43
43
  }
44
44
  else if (currentDirectory != null && matchUrl.test(currentDirectory)) {
@@ -48,7 +48,7 @@ async function load(url, currentDirectory = '.', responseType = false) {
48
48
  const path = resolve(url, currentDirectory).absolute;
49
49
  t = new URL(path, self.origin);
50
50
  }
51
- return fetch(t, t.origin != self.origin ? { mode: 'cors' } : {}).then(async (response) => {
51
+ return fetch(t, t.origin != self.origin ? { mode: "cors" } : {}).then(async (response) => {
52
52
  if (!response.ok) {
53
53
  throw new Error(`${response.status} ${response.statusText} ${response.url}`);
54
54
  }
@@ -59,7 +59,7 @@ async function load(url, currentDirectory = '.', responseType = false) {
59
59
  });
60
60
  }
61
61
  /**
62
- * render the ast tree
62
+ * Render the ast tree
63
63
  * @param data
64
64
  * @param options
65
65
  * @param mapping
@@ -91,15 +91,18 @@ function render(data, options = {}, mapping) {
91
91
  return doRender(data, Object.assign(options, {
92
92
  resolve,
93
93
  dirname,
94
- cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
94
+ cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
95
+ ? self.location.pathname
96
+ : dirname(self.location.pathname),
95
97
  }), mapping);
96
98
  }
97
99
  /**
98
- * parse css file
100
+ * Parse css file
99
101
  * @param file url or path
100
102
  * @param options
101
103
  * @param asStream load file as stream
102
104
  *
105
+ * @deprecated
103
106
  * @throws Error file not found
104
107
  *
105
108
  * Example:
@@ -118,10 +121,11 @@ function render(data, options = {}, mapping) {
118
121
  * ```
119
122
  */
120
123
  async function parseFile(file, options = {}, asStream = false) {
121
- return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => parse(stream, { src: file, ...options }));
124
+ console.warn("DeprecationWarning: parseFile is deprecated, use parse instead as parse({file, asStream, ...options})");
125
+ return parse({ file, asStream, ...options });
122
126
  }
123
127
  /**
124
- * parse css
128
+ * Parse css
125
129
  * @param stream
126
130
  * @param options
127
131
  *
@@ -148,49 +152,78 @@ async function parseFile(file, options = {}, asStream = false) {
148
152
  * console.log(result.ast);
149
153
  * ```
150
154
  */
151
- async function parse(stream, options = {}) {
152
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize({
155
+ async function parse(...args) {
156
+ let options;
157
+ let stream;
158
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
159
+ stream = args[0];
160
+ options = args[1];
161
+ }
162
+ else {
163
+ // @ts-expect-error
164
+ const { file, input, ...opt } = args[0];
165
+ options = opt;
166
+ if (file != null) {
167
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => parse(stream, { src: options.file, ...options }));
168
+ }
169
+ else {
170
+ stream = input;
171
+ }
172
+ }
173
+ options ??= {};
174
+ options.parseInfo = {
153
175
  stream,
154
- buffer: '',
176
+ buffer: "",
155
177
  offset: 0,
156
- position: { ind: 0, lin: 1, col: 1 },
157
- currentPosition: { ind: -1, lin: 1, col: 0 }
158
- }), Object.assign(options, {
178
+ time: 0,
179
+ src: options.src ?? "",
180
+ position: { ind: 0, lin: 1, col: 0 },
181
+ currentPosition: { ind: -1, lin: 1, col: 0 },
182
+ };
183
+ return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize(options.parseInfo), Object.assign(options, {
159
184
  load,
160
185
  resolve,
161
186
  dirname,
162
- cwd: options.cwd ?? self.location.pathname.endsWith('/') ? self.location.pathname : dirname(self.location.pathname)
163
- })).then(result => {
187
+ cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
188
+ ? self.location.pathname
189
+ : dirname(self.location.pathname),
190
+ })).then((result) => {
164
191
  const { revMapping, ...res } = result;
165
192
  return res;
166
193
  });
167
194
  }
168
195
  /**
169
- * transform css file
196
+ * Transform css file
170
197
  * @param file url or path
171
198
  * @param options
172
199
  * @param asStream load file as stream
173
200
  *
201
+ * @deprecated
174
202
  * Example:
175
203
  *
176
204
  * ```ts
177
205
  *
178
- * import {transformFile} from '@tbela99/css-parser/web';
206
+ * import {transform} from '@tbela99/css-parser/web';
179
207
  *
180
- * // remote file
181
- * let result = await transformFile('https://docs.deno.com/styles.css');
208
+ * // remote file
209
+ * let result = await transform({file: 'https://docs.deno.com/styles.css'});
182
210
  * console.log(result.code);
183
211
  *
184
212
  * // local file
185
- * result = await transformFile('./css/styles.css');
213
+ * result = await transform({file: './css/styles.css'});
186
214
  * console.log(result.code);
187
215
  * ```
188
216
  */
189
217
  async function transformFile(file, options = {}, asStream = false) {
190
- return Promise.resolve((options.load ?? load)(file, '.', asStream)).then(stream => transform(stream, { src: file, ...options }));
218
+ console.error("DeprecationWarning: transformFile is deprecated, use transform instead as transform({file, asStream, ...options})");
219
+ return transform({
220
+ file,
221
+ asStream,
222
+ ...options,
223
+ });
191
224
  }
192
225
  /**
193
- * transform css
226
+ * Transform css
194
227
  * @param css
195
228
  * @param options
196
229
  *
@@ -211,24 +244,43 @@ async function transformFile(file, options = {}, asStream = false) {
211
244
  * console.log(result.code);
212
245
  * ```
213
246
  */
214
- async function transform(css, options = {}) {
247
+ async function transform(...args) {
248
+ let options;
249
+ let stream;
250
+ if (typeof args[0] === "string" || args[0] instanceof ReadableStream) {
251
+ stream = args[0];
252
+ options = args[1];
253
+ }
254
+ else {
255
+ // @ts-expect-error
256
+ const { file, input, ...opt } = args[0];
257
+ options = opt;
258
+ if (file != null) {
259
+ return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => transform(stream, { src: options.file, ...options }));
260
+ }
261
+ else {
262
+ stream = input;
263
+ }
264
+ }
215
265
  options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
216
266
  const startTime = performance.now();
217
- return parse(css, options).then((parseResult) => {
267
+ return parse(stream, options).then((parseResult) => {
218
268
  let mapping = null;
219
269
  let importMapping = null;
220
- if (typeof options.module == 'number' && (options.module & ModuleScopeEnumOptions.ICSS)) {
270
+ if (typeof options.module == "number" && options.module & ModuleScopeEnumOptions.ICSS) {
221
271
  mapping = parseResult.mapping;
222
272
  importMapping = parseResult.importMapping;
223
273
  }
224
- else if (typeof options.module == 'object' && typeof options.module.scoped == 'number' && (options.module.scoped & ModuleScopeEnumOptions.ICSS)) {
274
+ else if (typeof options.module == "object" &&
275
+ typeof options.module.scoped == "number" &&
276
+ options.module.scoped & ModuleScopeEnumOptions.ICSS) {
225
277
  mapping = parseResult.mapping;
226
278
  importMapping = parseResult.importMapping;
227
279
  }
228
280
  // ast already expanded by parse
229
281
  const rendered = render(parseResult.ast, {
230
282
  ...options,
231
- expandNestingRules: false
283
+ expandNestingRules: false,
232
284
  }, mapping != null ? { mapping, importMapping } : null);
233
285
  return {
234
286
  ...parseResult,
@@ -238,8 +290,8 @@ async function transform(css, options = {}) {
238
290
  bytesOut: rendered.code.length,
239
291
  ...parseResult.stats,
240
292
  render: rendered.stats.total,
241
- total: `${(performance.now() - startTime).toFixed(2)}ms`
242
- }
293
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
294
+ },
243
295
  };
244
296
  });
245
297
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "v1.4.2",
4
+ "version": "1.4.4",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -16,14 +16,18 @@
16
16
  "scripts": {
17
17
  "doc": "typedoc --tsconfig typedoc-tsconfig.jsonc",
18
18
  "build": "rollup -c;./build.sh ./dist/index.d.ts 'declare interface' 'declare type'",
19
+ "watch": "rollup -c -w",
20
+ "test:watch": "web-test-runner \"./test/**/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --watch",
19
21
  "test": "web-test-runner \"./test/**/web.spec.js\" --timeout=10000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
20
22
  "test:web": "web-test-runner \"./test/**/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.",
21
23
  "test:node": "mocha -p --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
22
- "test:cov": "c8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
24
+ "test:cov": "superc8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 'test/**/node.spec.js'",
23
25
  "test:web-cov": "web-test-runner -x 'test/specs/**/*.js' \"test/**/web.spec.js\" --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage",
24
- "profile": "node --enable-source-maps --inspect-brk test/inspect.js",
25
- "syntax-update": "esno tools/validation.ts",
26
- "debug": "web-test-runner \"./test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
26
+ "profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
27
+ "config-update": "esno scripts/shorthand.ts",
28
+ "syntax-update": "esno scripts/validation.ts",
29
+ "debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/**/node.spec.js\"",
30
+ "debug:web": "web-test-runner \"./test/**/web.spec.js\" --manual --open --node-resolve --root-dir=."
27
31
  },
28
32
  "repository": {
29
33
  "type": "git",
@@ -57,24 +61,34 @@
57
61
  "homepage": "https://github.com/tbela99/css-parser#readme",
58
62
  "devDependencies": {
59
63
  "@esm-bundle/chai": "^4.3.4-fix.0",
60
- "@rollup/plugin-commonjs": "^28.0.8",
64
+ "@rollup/plugin-commonjs": "^29.0.3",
61
65
  "@rollup/plugin-json": "^6.1.0",
62
66
  "@rollup/plugin-node-resolve": "^16.0.3",
63
67
  "@rollup/plugin-typescript": "^12.3.0",
64
68
  "@types/chai": "^5.2.3",
65
69
  "@types/mocha": "^10.0.10",
66
- "@types/node": "^24.9.1",
67
- "@types/web": "^0.0.274",
68
- "@web/test-runner": "^0.20.2",
69
- "@web/test-runner-playwright": "^0.11.1",
70
- "c8": "^10.1.3",
70
+ "@types/node": "^26.1.1",
71
+ "@types/web": "^0.0.352",
72
+ "@web/test-runner": "^1.0.0",
73
+ "@web/test-runner-playwright": "^1.0.0",
71
74
  "esno": "^4.8.0",
72
- "mocha": "^11.7.4",
73
- "playwright": "^1.56.1",
74
- "rollup": "^4.52.5",
75
- "rollup-plugin-dts": "^6.2.3",
75
+ "markdown-it-task-lists": "^2.1.1",
76
+ "mocha": "^11.7.6",
77
+ "playwright": "^1.61.1",
78
+ "rollup": "^4.62.2",
79
+ "rollup-plugin-dts": "^6.4.1",
80
+ "superc8": "^12.7.0",
76
81
  "tslib": "^2.8.1",
77
- "typedoc": "^0.28.14",
78
- "typedoc-material-theme": "^1.4.0"
82
+ "typedoc": "^0.28.20",
83
+ "typedoc-plugin-coverage": "^4.0.3",
84
+ "typedoc-plugin-redirect": "^1.3.0",
85
+ "typedoc-unhoax-theme": "^0.5.3"
86
+ },
87
+ "sideEffects": false,
88
+ "allowScripts": {
89
+ "esbuild@0.28.0": true,
90
+ "esbuild@0.28.1": true,
91
+ "fsevents@2.3.2": true,
92
+ "fsevents@2.3.3": true
79
93
  }
80
94
  }
@@ -1,214 +0,0 @@
1
- import { EnumToken } from '../../../ast/types.js';
2
- import '../../../ast/minify.js';
3
- import '../../../ast/walk.js';
4
- import '../../../parser/parse.js';
5
- import '../../../parser/tokenize.js';
6
- import '../../../parser/utils/config.js';
7
- import '../../../renderer/sourcemap/lib/encode.js';
8
-
9
- const colorPrecision = 6;
10
- const anglePrecision = .001;
11
- const colorRange = {
12
- lab: {
13
- l: [0, 100],
14
- a: [-125, 125],
15
- b: [-125, 125]
16
- },
17
- lch: {
18
- l: [0, 100],
19
- c: [0, 150],
20
- h: [0, 360]
21
- },
22
- oklab: {
23
- l: [0, 1],
24
- a: [-0.4, .4],
25
- b: [-0.4, 0.4]
26
- },
27
- oklch: {
28
- l: [0, 1],
29
- a: [0, .4],
30
- b: [0, 0.4]
31
- }
32
- };
33
- const timelineFunc = ['view', 'scroll'];
34
- const generalEnclosedFunc = ['selector', 'font-tech', 'font-format', 'media', 'supports'];
35
- const timingFunc = ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end', 'steps', 'cubic-bezier'];
36
- const funcLike = [
37
- EnumToken.ParensTokenType,
38
- EnumToken.FunctionTokenType,
39
- EnumToken.UrlFunctionTokenType,
40
- EnumToken.StartParensTokenType,
41
- EnumToken.ImageFunctionTokenType,
42
- EnumToken.TimingFunctionTokenType,
43
- EnumToken.TimingFunctionTokenType,
44
- EnumToken.PseudoClassFuncTokenType,
45
- EnumToken.GridTemplateFuncTokenType
46
- ];
47
- const colorsFunc = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk', 'color-mix', 'color', 'oklab', 'lab', 'oklch', 'lch', 'light-dark'];
48
- const colorFuncColorSpace = ['srgb', 'srgb-linear', 'display-p3', 'prophoto-rgb', 'a98-rgb', 'rec2020', 'xyz', 'xyz-d65', 'xyz-d50'];
49
- const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
50
- const k = Math.pow(29, 3) / Math.pow(3, 3);
51
- const e = Math.pow(6, 3) / Math.pow(29, 3);
52
- // color module v4
53
- const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText', '-webkit-focus-ring-color'].map(m => m.toLowerCase()));
54
- // deprecated
55
- const deprecatedSystemColors = new Set(['ActiveBorder', 'ActiveCaption', 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', 'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText'].map(t => t.toLowerCase()));
56
- // name to color
57
- const COLORS_NAMES = Object.seal({
58
- 'aliceblue': '#f0f8ff',
59
- 'antiquewhite': '#faebd7',
60
- 'aqua': '#00ffff',
61
- 'aquamarine': '#7fffd4',
62
- 'azure': '#f0ffff',
63
- 'beige': '#f5f5dc',
64
- 'bisque': '#ffe4c4',
65
- 'black': '#000000',
66
- 'blanchedalmond': '#ffebcd',
67
- 'blue': '#0000ff',
68
- 'blueviolet': '#8a2be2',
69
- 'brown': '#a52a2a',
70
- 'burlywood': '#deb887',
71
- 'cadetblue': '#5f9ea0',
72
- 'chartreuse': '#7fff00',
73
- 'chocolate': '#d2691e',
74
- 'coral': '#ff7f50',
75
- 'cornflowerblue': '#6495ed',
76
- 'cornsilk': '#fff8dc',
77
- 'crimson': '#dc143c',
78
- 'cyan': '#00ffff',
79
- 'darkblue': '#00008b',
80
- 'darkcyan': '#008b8b',
81
- 'darkgoldenrod': '#b8860b',
82
- 'darkgray': '#a9a9a9',
83
- 'darkgrey': '#a9a9a9',
84
- 'darkgreen': '#006400',
85
- 'darkkhaki': '#bdb76b',
86
- 'darkmagenta': '#8b008b',
87
- 'darkolivegreen': '#556b2f',
88
- 'darkorange': '#ff8c00',
89
- 'darkorchid': '#9932cc',
90
- 'darkred': '#8b0000',
91
- 'darksalmon': '#e9967a',
92
- 'darkseagreen': '#8fbc8f',
93
- 'darkslateblue': '#483d8b',
94
- 'darkslategray': '#2f4f4f',
95
- 'darkslategrey': '#2f4f4f',
96
- 'darkturquoise': '#00ced1',
97
- 'darkviolet': '#9400d3',
98
- 'deeppink': '#ff1493',
99
- 'deepskyblue': '#00bfff',
100
- 'dimgray': '#696969',
101
- 'dimgrey': '#696969',
102
- 'dodgerblue': '#1e90ff',
103
- 'firebrick': '#b22222',
104
- 'floralwhite': '#fffaf0',
105
- 'forestgreen': '#228b22',
106
- 'fuchsia': '#ff00ff',
107
- 'gainsboro': '#dcdcdc',
108
- 'ghostwhite': '#f8f8ff',
109
- 'gold': '#ffd700',
110
- 'goldenrod': '#daa520',
111
- 'gray': '#808080',
112
- 'grey': '#808080',
113
- 'green': '#008000',
114
- 'greenyellow': '#adff2f',
115
- 'honeydew': '#f0fff0',
116
- 'hotpink': '#ff69b4',
117
- 'indianred': '#cd5c5c',
118
- 'indigo': '#4b0082',
119
- 'ivory': '#fffff0',
120
- 'khaki': '#f0e68c',
121
- 'lavender': '#e6e6fa',
122
- 'lavenderblush': '#fff0f5',
123
- 'lawngreen': '#7cfc00',
124
- 'lemonchiffon': '#fffacd',
125
- 'lightblue': '#add8e6',
126
- 'lightcoral': '#f08080',
127
- 'lightcyan': '#e0ffff',
128
- 'lightgoldenrodyellow': '#fafad2',
129
- 'lightgray': '#d3d3d3',
130
- 'lightgrey': '#d3d3d3',
131
- 'lightgreen': '#90ee90',
132
- 'lightpink': '#ffb6c1',
133
- 'lightsalmon': '#ffa07a',
134
- 'lightseagreen': '#20b2aa',
135
- 'lightskyblue': '#87cefa',
136
- 'lightslategray': '#778899',
137
- 'lightslategrey': '#778899',
138
- 'lightsteelblue': '#b0c4de',
139
- 'lightyellow': '#ffffe0',
140
- 'lime': '#00ff00',
141
- 'limegreen': '#32cd32',
142
- 'linen': '#faf0e6',
143
- 'magenta': '#ff00ff',
144
- 'maroon': '#800000',
145
- 'mediumaquamarine': '#66cdaa',
146
- 'mediumblue': '#0000cd',
147
- 'mediumorchid': '#ba55d3',
148
- 'mediumpurple': '#9370d8',
149
- 'mediumseagreen': '#3cb371',
150
- 'mediumslateblue': '#7b68ee',
151
- 'mediumspringgreen': '#00fa9a',
152
- 'mediumturquoise': '#48d1cc',
153
- 'mediumvioletred': '#c71585',
154
- 'midnightblue': '#191970',
155
- 'mintcream': '#f5fffa',
156
- 'mistyrose': '#ffe4e1',
157
- 'moccasin': '#ffe4b5',
158
- 'navajowhite': '#ffdead',
159
- 'navy': '#000080',
160
- 'oldlace': '#fdf5e6',
161
- 'olive': '#808000',
162
- 'olivedrab': '#6b8e23',
163
- 'orange': '#ffa500',
164
- 'orangered': '#ff4500',
165
- 'orchid': '#da70d6',
166
- 'palegoldenrod': '#eee8aa',
167
- 'palegreen': '#98fb98',
168
- 'paleturquoise': '#afeeee',
169
- 'palevioletred': '#d87093',
170
- 'papayawhip': '#ffefd5',
171
- 'peachpuff': '#ffdab9',
172
- 'peru': '#cd853f',
173
- 'pink': '#ffc0cb',
174
- 'plum': '#dda0dd',
175
- 'powderblue': '#b0e0e6',
176
- 'purple': '#800080',
177
- 'red': '#ff0000',
178
- 'rosybrown': '#bc8f8f',
179
- 'royalblue': '#4169e1',
180
- 'saddlebrown': '#8b4513',
181
- 'salmon': '#fa8072',
182
- 'sandybrown': '#f4a460',
183
- 'seagreen': '#2e8b57',
184
- 'seashell': '#fff5ee',
185
- 'sienna': '#a0522d',
186
- 'silver': '#c0c0c0',
187
- 'skyblue': '#87ceeb',
188
- 'slateblue': '#6a5acd',
189
- 'slategray': '#708090',
190
- 'slategrey': '#708090',
191
- 'snow': '#fffafa',
192
- 'springgreen': '#00ff7f',
193
- 'steelblue': '#4682b4',
194
- 'tan': '#d2b48c',
195
- 'teal': '#008080',
196
- 'thistle': '#d8bfd8',
197
- 'tomato': '#ff6347',
198
- 'turquoise': '#40e0d0',
199
- 'violet': '#ee82ee',
200
- 'wheat': '#f5deb3',
201
- 'white': '#ffffff',
202
- 'whitesmoke': '#f5f5f5',
203
- 'yellow': '#ffff00',
204
- 'yellowgreen': '#9acd32',
205
- 'rebeccapurple': '#663399',
206
- 'transparent': '#00000000'
207
- });
208
- // color to name
209
- const NAMES_COLORS = Object.seal(Object.entries(COLORS_NAMES).reduce((acc, [key, value]) => {
210
- acc[value] = key;
211
- return acc;
212
- }, Object.create(null)));
213
-
214
- export { COLORS_NAMES, D50, NAMES_COLORS, anglePrecision, colorFuncColorSpace, colorPrecision, colorRange, colorsFunc, deprecatedSystemColors, e, funcLike, generalEnclosedFunc, k, systemColors, timelineFunc, timingFunc };
@@ -1,70 +0,0 @@
1
- import { EnumToken } from '../ast/types.js';
2
- import '../ast/minify.js';
3
- import '../ast/walk.js';
4
- import '../parser/parse.js';
5
- import '../parser/tokenize.js';
6
- import '../parser/utils/config.js';
7
- import './color/utils/constants.js';
8
- import '../renderer/sourcemap/lib/encode.js';
9
-
10
- function length2Px(value) {
11
- let result = null;
12
- if (value.typ == EnumToken.NumberTokenType) {
13
- result = +value.val;
14
- }
15
- else {
16
- switch (value.unit) {
17
- case 'cm':
18
- // @ts-ignore
19
- result = value.val * 37.8;
20
- break;
21
- case 'mm':
22
- // @ts-ignore
23
- result = value.val * 3.78;
24
- break;
25
- case 'Q':
26
- // @ts-ignore
27
- result = value.val * 37.8 / 40;
28
- break;
29
- case 'in':
30
- // @ts-ignore
31
- result = value.val / 96;
32
- break;
33
- case 'pc':
34
- // @ts-ignore
35
- result = value.val / 16;
36
- break;
37
- case 'pt':
38
- // @ts-ignore
39
- result = value.val * 4 / 3;
40
- break;
41
- case 'px':
42
- result = +value.val;
43
- break;
44
- }
45
- }
46
- return isNaN(result) ? null : result;
47
- }
48
- /**
49
- * minify number
50
- * @param val
51
- */
52
- function minifyNumber(val) {
53
- val = String(val);
54
- if (val === '0') {
55
- return '0';
56
- }
57
- const chr = val.charAt(0);
58
- if (chr == '-') {
59
- const slice = val.slice(0, 2);
60
- if (slice == '-0') {
61
- return val.length == 2 ? '0' : '-' + val.slice(2);
62
- }
63
- }
64
- if (chr == '0') {
65
- return val.slice(1);
66
- }
67
- return val;
68
- }
69
-
70
- export { length2Px, minifyNumber };