@tbela99/css-parser 2.1.0 → 2.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 (130) hide show
  1. package/CHANGELOG.md +66 -1
  2. package/README.md +14 -7
  3. package/architecture.png +0 -0
  4. package/dist/{src/lib/ast → ast}/arena-node.js +10 -10
  5. package/dist/{src/lib/ast → ast}/arena.js +304 -139
  6. package/dist/{src/lib/ast → ast}/cache.js +40 -24
  7. package/dist/{src/lib/ast → ast}/features/calc.js +11 -9
  8. package/dist/{src/lib/ast → ast}/features/if.js +6 -6
  9. package/dist/ast/features/index.d.ts +7 -0
  10. package/dist/{src/lib/ast → ast}/features/index.js +3 -2
  11. package/dist/{src/lib/ast → ast}/features/inlinecssvariables.js +12 -10
  12. package/dist/ast/features/mixin.js +953 -0
  13. package/dist/{src/lib/ast → ast}/features/prefix.js +39 -39
  14. package/dist/ast/features/shorthand.js +129 -0
  15. package/dist/ast/features/transform.js +188 -0
  16. package/dist/{src/lib/ast → ast}/features/type.js +2 -2
  17. package/dist/{src/lib/ast → ast}/math/expression.js +24 -24
  18. package/dist/{src/lib/ast → ast}/math/math.js +2 -2
  19. package/dist/{src/lib/ast → ast}/minify.js +745 -201
  20. package/dist/ast/mixins/custom-function.js +393 -0
  21. package/dist/ast/mixins/utils.js +53 -0
  22. package/dist/ast/mixins/variables.js +678 -0
  23. package/dist/ast/strings.js +910 -0
  24. package/dist/ast/transform/compute.js +560 -0
  25. package/dist/ast/transform/matrix.js +67 -0
  26. package/dist/ast/transform/minify.js +325 -0
  27. package/dist/ast/transform/perspective.js +24 -0
  28. package/dist/{src/lib/ast → ast}/transform/rotate.js +16 -7
  29. package/dist/ast/transform/scale.js +43 -0
  30. package/dist/ast/transform/skew.js +38 -0
  31. package/dist/ast/transform/translate.js +56 -0
  32. package/dist/ast/transform/utils.js +390 -0
  33. package/dist/{src/lib/ast → ast}/types.js +2 -2
  34. package/dist/{src/lib/ast → ast}/walk.js +2 -2
  35. package/dist/{src/data → data}/properties.json.js +86 -2
  36. package/dist/{src/data → data}/validation.json.js +30 -21
  37. package/dist/{src/lib/fs → fs}/resolve.js +2 -2
  38. package/dist/index-umd-web.js +19727 -10719
  39. package/dist/index.d.ts +738 -100
  40. package/dist/{src/node.js → node.js} +70 -52
  41. package/dist/{src/lib/parser → parser}/declaration/list.js +25 -8
  42. package/dist/{src/lib/parser → parser}/declaration/map.js +15 -15
  43. package/dist/{src/lib/parser → parser}/declaration/set.js +5 -5
  44. package/dist/{src/lib/parser → parser}/input.js +18 -3
  45. package/dist/{src/lib/parser → parser}/linesmap.js +2 -2
  46. package/dist/{src/lib/parser → parser}/parse.js +444 -278
  47. package/dist/{src/lib/parser → parser}/source.js +3 -3
  48. package/dist/{src/lib/parser → parser}/tokenize.js +480 -312
  49. package/dist/{src/lib/parser → parser}/utils/angle.js +3 -3
  50. package/dist/{src/lib/parser → parser}/utils/at-rule-container.js +12 -12
  51. package/dist/{src/lib/parser → parser}/utils/at-rule-font-feature-values.js +3 -3
  52. package/dist/{src/lib/parser → parser}/utils/at-rule-generic.js +7 -7
  53. package/dist/{src/lib/parser → parser}/utils/at-rule-import.js +10 -10
  54. package/dist/{src/lib/parser → parser}/utils/at-rule-media.js +14 -14
  55. package/dist/{src/lib/parser → parser}/utils/at-rule-support.js +9 -14
  56. package/dist/{src/lib/parser → parser}/utils/at-rule-when-else.js +6 -6
  57. package/dist/{src/lib/parser → parser}/utils/at-rule.js +3 -3
  58. package/dist/{src/lib/parser → parser}/utils/base64.js +2 -2
  59. package/dist/parser/utils/cache.js +53 -0
  60. package/dist/parser/utils/canonical.js +78 -0
  61. package/dist/parser/utils/codes.js +93 -0
  62. package/dist/{src/lib/parser → parser}/utils/config.js +3 -3
  63. package/dist/{src/lib/parser → parser}/utils/declaration.js +31 -26
  64. package/dist/{src/lib/parser → parser}/utils/eq.js +2 -2
  65. package/dist/{src/lib/parser → parser}/utils/hash.js +2 -2
  66. package/dist/{src/lib/parser → parser}/utils/selector.js +339 -87
  67. package/dist/{src/lib/parser → parser}/utils/text.js +2 -2
  68. package/dist/{src/lib/parser → parser}/utils/token.js +2 -2
  69. package/dist/{src/lib/parser → parser}/utils/type.js +9 -7
  70. package/dist/{src/lib/printer/sourcemap → printer}/lib/codec.js +2 -2
  71. package/dist/{src/lib/printer → printer}/render.js +582 -153
  72. package/dist/printer/result.js +148 -0
  73. package/dist/{src/lib/printer/sourcemap → printer}/sourcemap.js +4 -3
  74. package/dist/printer/writer.js +252 -0
  75. package/dist/{src/lib/syntax → syntax}/color/a98rgb.js +2 -2
  76. package/dist/{src/lib/syntax → syntax}/color/alpha.js +10 -10
  77. package/dist/{src/lib/syntax → syntax}/color/cmyk.js +2 -2
  78. package/dist/{src/lib/syntax → syntax}/color/color-mix.js +18 -18
  79. package/dist/{src/lib/syntax → syntax}/color/color.js +18 -18
  80. package/dist/{src/lib/syntax → syntax}/color/hex.js +3 -3
  81. package/dist/{src/lib/syntax → syntax}/color/hsl.js +2 -2
  82. package/dist/{src/lib/syntax → syntax}/color/hwb.js +2 -2
  83. package/dist/{src/lib/syntax → syntax}/color/lab.js +2 -2
  84. package/dist/{src/lib/syntax → syntax}/color/lch.js +2 -2
  85. package/dist/{src/lib/syntax → syntax}/color/oklab.js +2 -2
  86. package/dist/{src/lib/syntax → syntax}/color/oklch.js +3 -3
  87. package/dist/{src/lib/syntax → syntax}/color/p3.js +2 -2
  88. package/dist/{src/lib/syntax → syntax}/color/prophotorgb.js +2 -2
  89. package/dist/{src/lib/syntax → syntax}/color/rec2020.js +2 -2
  90. package/dist/{src/lib/syntax → syntax}/color/relative-color.js +14 -14
  91. package/dist/{src/lib/syntax → syntax}/color/rgb.js +4 -4
  92. package/dist/{src/lib/syntax → syntax}/color/srgb.js +5 -5
  93. package/dist/{src/lib/syntax → syntax}/color/utils/color-type.js +4 -4
  94. package/dist/{src/lib/syntax → syntax}/color/utils/colorspace.js +10 -10
  95. package/dist/{src/lib/syntax → syntax}/color/utils/components.js +5 -5
  96. package/dist/{src/lib/syntax → syntax}/color/utils/distance.js +2 -2
  97. package/dist/{src/lib/syntax → syntax}/color/utils/make-color.js +3 -3
  98. package/dist/{src/lib/syntax → syntax}/color/utils/matrix.js +2 -2
  99. package/dist/{src/lib/syntax → syntax}/color/xyz.js +2 -2
  100. package/dist/{src/lib/syntax → syntax}/color/xyzd50.js +2 -2
  101. package/dist/{src/lib/syntax → syntax}/constants.js +27 -4
  102. package/dist/{src/lib/syntax → syntax}/syntax.js +37 -29
  103. package/dist/{src/types.js → types.js} +2 -2
  104. package/dist/{src/utils → utils}/sync.js +12 -7
  105. package/dist/validation/compiled/builtins.js +32 -0
  106. package/dist/validation/compiled/runtime.js +705 -0
  107. package/dist/validation/compiled/syntaxes.js +1620 -0
  108. package/dist/{src/lib/validation → validation}/config.js +63 -16
  109. package/dist/validation/first.js +574 -0
  110. package/dist/{src/lib/validation → validation}/match.js +376 -161
  111. package/dist/{src/lib/validation → validation}/parser/parse.js +2 -2
  112. package/dist/{src/lib/validation → validation}/parser/typedef.js +2 -2
  113. package/dist/{src/lib/validation → validation}/utils/list.js +3 -19
  114. package/dist/version.js +13 -0
  115. package/dist/{src/web.js → web.js} +68 -55
  116. package/package.json +15 -13
  117. package/dist/package.json.js +0 -10
  118. package/dist/src/lib/ast/features/shorthand.js +0 -95
  119. package/dist/src/lib/ast/features/transform.js +0 -90
  120. package/dist/src/lib/ast/transform/compute.js +0 -362
  121. package/dist/src/lib/ast/transform/matrix.js +0 -88
  122. package/dist/src/lib/ast/transform/minify.js +0 -267
  123. package/dist/src/lib/ast/transform/perspective.js +0 -16
  124. package/dist/src/lib/ast/transform/scale.js +0 -39
  125. package/dist/src/lib/ast/transform/skew.js +0 -30
  126. package/dist/src/lib/ast/transform/translate.js +0 -39
  127. package/dist/src/lib/ast/transform/utils.js +0 -287
  128. package/dist/src/lib/parser/utils/cache.js +0 -54
  129. package/dist/types.d.ts +0 -21
  130. package/dist/utils/sync.d.ts +0 -16
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
@@ -1,8 +1,8 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  var ValidationTokenEnum;
@@ -1,28 +1,12 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
8
  import { EnumToken } from '../../ast/types.js';
9
9
 
10
- /**
11
- * remove comma and comment tokens
12
- * @param arena
13
- * @param tokenList
14
- */
15
- function stripCommaToken(arena, tokenList) {
16
- let result = [];
17
- for (let i = 0; i < tokenList.length; i++) {
18
- const typ = arena.dataTypes[tokenList[i]];
19
- if (typ === EnumToken.CommentTokenType || typ === EnumToken.CommaTokenType) {
20
- continue;
21
- }
22
- result.push(tokenList[i]);
23
- }
24
- return result;
25
- }
26
10
  /**
27
11
  * split a token list
28
12
  * @param arena
@@ -47,4 +31,4 @@ function splitTokenList(arena, tokenList, split = [EnumToken.CommaTokenType], in
47
31
  return result;
48
32
  }
49
33
 
50
- export { splitTokenList, stripCommaToken };
34
+ export { splitTokenList };
@@ -0,0 +1,13 @@
1
+ /*
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
+
4
+ Author(s): Thierry Bela
5
+ Version: 2.3.0
6
+ License: MIT
7
+ */
8
+ /**
9
+ * Version number
10
+ */
11
+ const version = "2.3.0";
12
+
13
+ export { version };
@@ -1,32 +1,33 @@
1
1
  /*
2
- CSS parser, minifier and validator for node and the browser
2
+ CSS parser, minifier and validator for node, deno, bun and the browser
3
3
 
4
4
  Author(s): Thierry Bela
5
- Version: 2.1.0
5
+ Version: 2.3.0
6
6
  License: MIT
7
7
  */
8
- import { doParse, doParseSync } from './lib/parser/parse.js';
9
- export { parseDeclarations, parseString } from './lib/parser/parse.js';
10
- import { doRender } from './lib/printer/render.js';
11
- export { renderValue } from './lib/printer/render.js';
12
- import { ModuleScopeEnumOptions } from './lib/ast/types.js';
13
- export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './lib/ast/types.js';
14
- import { createParseInfo, Tokenizer } from './lib/parser/tokenize.js';
15
- import { isCssInput } from './lib/parser/input.js';
16
- import { matchUrl, resolve, dirname } from './lib/fs/resolve.js';
8
+ import { doParse, doParseSync } from './parser/parse.js';
9
+ export { parseDeclarations, parseString } from './parser/parse.js';
10
+ import { doRender } from './printer/render.js';
11
+ export { renderValue } from './printer/render.js';
12
+ import { TransformResult, RenderResult } from './printer/result.js';
13
+ import { ModuleScopeEnumOptions } from './ast/types.js';
14
+ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, WalkerEvent, WalkerOptionEnum } from './ast/types.js';
15
+ import { createParseInfo, Tokenizer } from './parser/tokenize.js';
16
+ import { isCssInput } from './parser/input.js';
17
+ import { matchUrl, resolve, dirname } from './fs/resolve.js';
17
18
  import { ResponseType } from './types.js';
18
- import { SourceFile } from './lib/parser/source.js';
19
- import { parseResult, validateSyncArguments } from './utils/sync.js';
20
- export { minify } from './lib/ast/minify.js';
21
- export { convertColor } from './lib/syntax/color/color.js';
22
- export { isOkLabClose, okLabDistance } from './lib/syntax/color/utils/distance.js';
23
- export { Arena, AstArena, TokenField, arenaColumns } from './lib/ast/arena.js';
24
- export { ARENA, ARENAID, AstArenaNode } from './lib/ast/arena-node.js';
25
- export { PropertyList } from './lib/parser/declaration/list.js';
26
- export { SourceMap } from './lib/printer/sourcemap/sourcemap.js';
27
- export { FeatureWalkMode } from './lib/ast/features/type.js';
28
- export { parseSyntax } from './lib/validation/parser/parse.js';
29
- export { version } from '../package.json.js';
19
+ import { SourceFile } from './parser/source.js';
20
+ import { validateSyncArguments, parseResult } from './utils/sync.js';
21
+ export { minify } from './ast/minify.js';
22
+ export { convertColor } from './syntax/color/color.js';
23
+ export { isOkLabClose, okLabDistance } from './syntax/color/utils/distance.js';
24
+ export { Arena, AstArena, TokenField, arenaColumns } from './ast/arena.js';
25
+ export { ARENA, ARENAID, AstArenaNode } from './ast/arena-node.js';
26
+ export { PropertyList } from './parser/declaration/list.js';
27
+ export { SourceMap } from './printer/sourcemap.js';
28
+ export { FeatureWalkMode } from './ast/features/type.js';
29
+ export { parseSyntax } from './validation/parser/parse.js';
30
+ export { version } from './version.js';
30
31
 
31
32
  /**
32
33
  * Load file or url
@@ -102,13 +103,16 @@ async function load(url, currentDirectory = ".", responseType = false) {
102
103
  * ```
103
104
  */
104
105
  function render(arena, data, options = {}, mapping) {
105
- return doRender(arena, data, Object.assign(options, {
106
+ return doRender(arena, data,
107
+ // the options of the caller are not modified
108
+ {
109
+ ...options,
106
110
  resolve,
107
111
  dirname,
108
112
  cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
109
113
  ? self.location.pathname
110
114
  : dirname(self.location.pathname),
111
- }), mapping);
115
+ }, mapping);
112
116
  }
113
117
  /**
114
118
  * Parse CSS
@@ -141,7 +145,15 @@ function parseSync(...args) {
141
145
  if (options != null) {
142
146
  validateSyncArguments(options);
143
147
  }
144
- options ??= {};
148
+ // the options of the caller are not modified: they may be reused
149
+ return parseSyncInput(stream, { ...options });
150
+ }
151
+ /**
152
+ * parse a css input. the options belong to the call: they are modified (source, parse info, ...)
153
+ * @param stream
154
+ * @param options
155
+ */
156
+ function parseSyncInput(stream, options) {
145
157
  options.src ??= "";
146
158
  options.sourcesMap ??= new Map();
147
159
  Object.assign(options, {
@@ -190,10 +202,13 @@ function transformSync(...args) {
190
202
  options = opt;
191
203
  stream = input;
192
204
  }
193
- options ??= {};
205
+ if (options != null) {
206
+ validateSyncArguments(options);
207
+ }
208
+ // the options of the caller are not modified: they may be reused
194
209
  options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
195
210
  const startTime = performance.now();
196
- const parseResult = parseSync(stream, options);
211
+ const parseResult = parseSyncInput(stream, options);
197
212
  let mapping = null;
198
213
  let importMapping = null;
199
214
  if ((typeof options.module === "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
@@ -208,17 +223,12 @@ function transformSync(...args) {
208
223
  ...options,
209
224
  expandNestingRules: false,
210
225
  }, mapping != null ? { mapping, importMapping } : null);
211
- return {
212
- ...parseResult,
213
- ...rendered,
214
- errors: parseResult.errors.concat(rendered.errors),
215
- stats: {
216
- bytesOut: rendered.code.length,
217
- ...parseResult.stats,
218
- render: rendered.stats.total,
219
- total: `${(performance.now() - startTime).toFixed(2)}ms`,
220
- },
221
- };
226
+ return new TransformResult(parseResult, rendered, {
227
+ bytesOut: RenderResult.codeLength(rendered),
228
+ ...parseResult.stats,
229
+ render: rendered.stats.total,
230
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
231
+ });
222
232
  }
223
233
  /**
224
234
  * Parse CSS
@@ -262,13 +272,21 @@ async function parse(...args) {
262
272
  return Promise.resolve((options.load != null
263
273
  ? options.load(file, "", options.asStream ?? false)
264
274
  : // the default loader loads the file as an ArrayBuffer: the preferred input of the tokenizer
265
- load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => parse(stream, { src: options.file, ...options }));
275
+ load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => parse(stream, { src: file, ...options }));
266
276
  }
267
277
  else {
268
278
  stream = input;
269
279
  }
270
280
  }
271
- options ??= {};
281
+ // the options of the caller are not modified: they may be reused
282
+ return parseInput(stream, { ...options });
283
+ }
284
+ /**
285
+ * parse a css input. the options belong to the call: they are modified (source, parse info, ...)
286
+ * @param stream
287
+ * @param options
288
+ */
289
+ async function parseInput(stream, options) {
272
290
  options.src ??= "";
273
291
  options.sourcesMap ??= new Map();
274
292
  Object.assign(options, {
@@ -329,7 +347,7 @@ async function transform(...args) {
329
347
  return Promise.resolve((options.load != null
330
348
  ? options.load(file, "", options.asStream ?? false)
331
349
  : // the default loader loads the file as an ArrayBuffer: the preferred input of the tokenizer
332
- load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => transform(stream, { src: options.file, ...options }));
350
+ load(file, "", options.asStream ? ResponseType.ReadableStream : ResponseType.ArrayBuffer))).then((stream) => transform(stream, { src: file, ...options }));
333
351
  }
334
352
  else {
335
353
  stream = input;
@@ -337,7 +355,7 @@ async function transform(...args) {
337
355
  }
338
356
  options = { minify: true, removeEmpty: true, removeCharset: true, ...options };
339
357
  const startTime = performance.now();
340
- return parse(stream, options).then((parseResult) => {
358
+ return parseInput(stream, options).then((parseResult) => {
341
359
  let mapping = null;
342
360
  let importMapping = null;
343
361
  if ((typeof options.module === "number" && options.module & ModuleScopeEnumOptions.ICSS) ||
@@ -352,18 +370,13 @@ async function transform(...args) {
352
370
  ...options,
353
371
  expandNestingRules: false,
354
372
  }, mapping != null ? { mapping, importMapping } : null);
355
- return {
356
- ...parseResult,
357
- ...rendered,
358
- errors: parseResult.errors.concat(rendered.errors),
359
- stats: {
360
- bytesOut: rendered.code.length,
361
- ...parseResult.stats,
362
- render: rendered.stats.total,
363
- total: `${(performance.now() - startTime).toFixed(2)}ms`,
364
- },
365
- };
373
+ return new TransformResult(parseResult, rendered, {
374
+ bytesOut: RenderResult.codeLength(rendered),
375
+ ...parseResult.stats,
376
+ render: rendered.stats.total,
377
+ total: `${(performance.now() - startTime).toFixed(2)}ms`,
378
+ });
366
379
  });
367
380
  }
368
381
 
369
- export { ModuleScopeEnumOptions, ResponseType, dirname, load, parse, parseSync, render, resolve, transform, transformSync };
382
+ export { ModuleScopeEnumOptions, RenderResult, ResponseType, TransformResult, dirname, load, parse, parseSync, render, resolve, transform, transformSync };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
- "description": "CSS parser, minifier and validator for node and the browser",
4
- "version": "2.1.0",
3
+ "description": "CSS parser, minifier and validator for node, deno, bun and the browser",
4
+ "version": "2.3.0",
5
5
  "exports": {
6
- ".": "./dist/src/node.js",
7
- "./node": "./dist/src/node.js",
8
- "./web": "./dist/src/web.js"
6
+ ".": "./dist/node.js",
7
+ "./node": "./dist/node.js",
8
+ "./web": "./dist/web.js"
9
9
  },
10
10
  "type": "module",
11
11
  "typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "doc": "typedoc --tsconfig typedoc-tsconfig.jsonc",
17
- "build": "rollup -c;./build.sh ./dist/index.d.ts 'declare interface' 'declare type'",
17
+ "build": "rollup -c;sh build.sh ./dist/index.d.ts 'declare interface' 'declare type'",
18
18
  "watch": "rollup -c -w",
19
19
  "test:watch": "web-test-runner \"./test/specs/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --watch",
20
20
  "test": "web-test-runner \"./test/specs/web.spec.js\" --timeout=10000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.; mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
@@ -24,7 +24,9 @@
24
24
  "test:web-cov": "web-test-runner -x 'test/specs/code/*.js' --node-resolve --playwright --browsers chromium firefox webkit --root-dir=. --coverage \"test/specs/web.spec.js\"",
25
25
  "profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
26
26
  "config-update": "esno scripts/shorthand.ts",
27
- "syntax-update": "esno scripts/webref.ts",
27
+ "syntax-update": "esno scripts/webref.ts && npm run syntax-compile",
28
+ "syntax-compile": "esno scripts/compile-syntax.ts",
29
+ "syntax-verify": "esno scripts/verify-syntax.ts",
28
30
  "debug:node": "mocha --reporter-options='maxDiffSize=1801920' --timeout=10000 \"test/specs/node.spec.js\"",
29
31
  "debug:web": "web-test-runner \"./test/specs/web.spec.js\" --manual --open --node-resolve --root-dir=."
30
32
  },
@@ -68,17 +70,17 @@
68
70
  "@types/chai-as-promised": "^8.0.2",
69
71
  "@types/mocha": "^10.0.10",
70
72
  "@types/node": "^26.6.6",
71
- "@types/web": "^0.0.359",
73
+ "@types/web": "^0.0.367",
72
74
  "@typescript/typescript6": "^6.0.2",
73
- "@web/test-runner": "^1.0.0",
74
- "@web/test-runner-playwright": "^1.0.0",
75
+ "@web/test-runner": "^1.0.1",
76
+ "@web/test-runner-playwright": "^1.0.2",
75
77
  "chai": "^6.3.0",
76
78
  "chai-as-promised": "^8.0.2",
77
79
  "esno": "^4.8.0",
78
80
  "markdown-it-task-lists": "^2.1.1",
79
81
  "mocha": "^12.0.3",
80
- "playwright": "^1.64.1",
81
- "rollup": "^4.67.2",
82
+ "playwright": "^1.65.1",
83
+ "rollup": "^4.68.5",
82
84
  "rollup-plugin-dts": "^6.5.1",
83
85
  "rollup-plugin-version-injector": "^1.3.3",
84
86
  "superc8": "^12.7.0",
@@ -90,4 +92,4 @@
90
92
  "typedoc-unhoax-theme": "^0.5.3"
91
93
  },
92
94
  "sideEffects": false
93
- }
95
+ }
@@ -1,10 +0,0 @@
1
- /*
2
- CSS parser, minifier and validator for node and the browser
3
-
4
- Author(s): Thierry Bela
5
- Version: 2.1.0
6
- License: MIT
7
- */
8
- var version = "2.1.0";
9
-
10
- export { version };
@@ -1,95 +0,0 @@
1
- /*
2
- CSS parser, minifier and validator for node and the browser
3
-
4
- Author(s): Thierry Bela
5
- Version: 2.1.0
6
- License: MIT
7
- */
8
- import { DeclarationMemo, PropertyList } from '../../parser/declaration/list.js';
9
- import { EnumToken, EnumAstNodeStatus } from '../types.js';
10
- import { FeatureWalkMode } from './type.js';
11
-
12
- class ComputeShorthandFeature {
13
- accept = new Set([
14
- EnumToken.RuleNodeType,
15
- EnumToken.AtRuleNodeType,
16
- EnumToken.KeyframesRuleNodeType,
17
- ]);
18
- get ordering() {
19
- return 5;
20
- }
21
- get processMode() {
22
- return FeatureWalkMode.Post;
23
- }
24
- static register(options) {
25
- if (options.computeShorthand) {
26
- // @ts-ignore
27
- options.features.push(new ComputeShorthandFeature(options));
28
- }
29
- }
30
- /**
31
- *
32
- * @param arena
33
- * @param ast
34
- * @param options
35
- * @param _parent
36
- * @param context
37
- */
38
- run(arena, ast, options, _parent, context) {
39
- if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren) || arena.firstChild[ast] === 0) {
40
- return null;
41
- }
42
- // the keys of the declarations are shared by the rules of the minification
43
- const memo = context == null ? null : (context.declarations ??= new DeclarationMemo());
44
- const list = new PropertyList(arena, options, memo);
45
- let doNotSort = false;
46
- let hasDeclarations = false;
47
- if (arena.dataTypes[ast] === EnumToken.AtRuleNodeType) {
48
- switch (arena.strings[arena.name[ast]]) {
49
- case "function":
50
- case "mixin":
51
- doNotSort = true;
52
- break;
53
- }
54
- }
55
- // the declarations (with their leading comments) are moved into the property list,
56
- // the rules (with their leading comments) stay in place
57
- let child = arena.firstChild[ast];
58
- while (child !== 0) {
59
- let last = child;
60
- if (!doNotSort) {
61
- // capture comments with the next node
62
- while (arena.nextSibling[last] !== 0 && arena.dataTypes[last] === EnumToken.CommentNodeType) {
63
- last = arena.nextSibling[last];
64
- }
65
- }
66
- const next = arena.nextSibling[last];
67
- // https://drafts.csswg.org/css-mixins/#:~:text=The%20value%20of%20the%20result%20descriptor%20is%20always%2016px%20in%20the%20above%20example
68
- if (doNotSort || arena.dataTypes[last] === EnumToken.DeclarationNodeType) {
69
- hasDeclarations = true;
70
- for (let node = child; node !== next;) {
71
- const nextNode = arena.nextSibling[node];
72
- arena.detach(node);
73
- list.addDeclaration(node);
74
- node = nextNode;
75
- }
76
- }
77
- child = next;
78
- }
79
- if (hasDeclarations) {
80
- // the declarations are inserted before the rules
81
- const first = arena.firstChild[ast];
82
- for (const node of list) {
83
- if (first === 0) {
84
- arena.appendChild(ast, node);
85
- }
86
- else {
87
- arena.insertBefore(first, node);
88
- }
89
- }
90
- }
91
- return ast;
92
- }
93
- }
94
-
95
- export { ComputeShorthandFeature };
@@ -1,90 +0,0 @@
1
- /*
2
- CSS parser, minifier and validator for node and the browser
3
-
4
- Author(s): Thierry Bela
5
- Version: 2.1.0
6
- License: MIT
7
- */
8
- import { EnumToken, EnumAstNodeStatus } from '../types.js';
9
- import { compute } from '../transform/compute.js';
10
- import { filterValues, renderValue } from '../../printer/render.js';
11
- import { minifyTransformFunctions, eqMatrix } from '../transform/minify.js';
12
- import { FeatureWalkMode } from './type.js';
13
-
14
- /**
15
- * transform property and its prefixed versions
16
- */
17
- const transformProperty = /^(-[a-z]+-)?transform$/;
18
- class TransformCssFeature {
19
- accept = new Set([
20
- EnumToken.RuleNodeType,
21
- EnumToken.AtRuleNodeType,
22
- EnumToken.KeyframesRuleNodeType,
23
- ]);
24
- get ordering() {
25
- return 4;
26
- }
27
- get processMode() {
28
- return FeatureWalkMode.Post;
29
- }
30
- static register(options) {
31
- // @ts-ignore
32
- if (options.computeTransform) {
33
- // @ts-ignore
34
- options.features.push(new TransformCssFeature());
35
- }
36
- }
37
- /**
38
- *
39
- * @param arena
40
- * @param ast
41
- */
42
- run(arena, ast) {
43
- if (!(arena.flags[ast] & EnumAstNodeStatus.HasChildren)) {
44
- return null;
45
- }
46
- let node;
47
- for (node = arena.firstChild[ast]; node !== 0; node = arena.nextSibling[node]) {
48
- if (arena.flags[node] & (EnumAstNodeStatus.Invalid | EnumAstNodeStatus.ValidationFailed)) {
49
- continue;
50
- }
51
- if (arena.dataTypes[node] !== EnumToken.DeclarationNodeType ||
52
- !transformProperty.test(arena.strings[arena.name[node]])) {
53
- continue;
54
- }
55
- const children = [];
56
- for (const child of arena.tokens(node)) {
57
- children.push(arena.dataTypes[child] === EnumToken.TransformFunctionTokenType
58
- ? minifyTransformFunctions(arena, child)
59
- : child);
60
- }
61
- let { matrix, cumulative, minified } = compute(arena, children) ?? {
62
- matrix: null,
63
- cumulative: null,
64
- minified: null,
65
- };
66
- if (matrix == null || cumulative == null || minified == null) {
67
- arena.setTokenList(node, children);
68
- continue;
69
- }
70
- let r = [filterValues(arena, children)];
71
- if (eqMatrix(arena, matrix, cumulative)) {
72
- r.push(cumulative);
73
- }
74
- if (eqMatrix(arena, matrix, minified)) {
75
- r.push(minified);
76
- }
77
- const l = renderValue(arena, matrix).length;
78
- // inlined: arena.setTokens(node, ...r.reduce((acc: Token[], curr: Token[]): Token[] => { if (curr.reduce((acc: string, t: Token) => acc + renderValue(arena, t), "").length < l) { return curr; } return acc; }, [matrix]))
79
- arena.setTokenList(node, r.reduce((acc, curr) => {
80
- if (curr.reduce((acc, t) => acc + renderValue(arena, t), "").length < l) {
81
- return curr;
82
- }
83
- return acc;
84
- }, [matrix]));
85
- }
86
- return null;
87
- }
88
- }
89
-
90
- export { TransformCssFeature };