@tbela99/css-parser 1.4.6 → 1.4.8

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 (55) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +6578 -6969
  4. package/dist/index.cjs +7808 -8197
  5. package/dist/index.d.ts +923 -51
  6. package/dist/lib/ast/clone.js +16 -23
  7. package/dist/lib/ast/expand.js +2 -2
  8. package/dist/lib/ast/features/if.js +88 -87
  9. package/dist/lib/ast/features/inlinecssvariables.js +2 -2
  10. package/dist/lib/ast/features/prefix.js +26 -22
  11. package/dist/lib/ast/features/transform.js +3 -3
  12. package/dist/lib/ast/find.js +17 -14
  13. package/dist/lib/ast/minify.js +97 -94
  14. package/dist/lib/ast/types.js +10 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +47 -45
  17. package/dist/lib/parser/arena.js +206 -0
  18. package/dist/lib/parser/declaration/list.js +9 -10
  19. package/dist/lib/parser/declaration/map.js +13 -18
  20. package/dist/lib/parser/linemap.js +62 -0
  21. package/dist/lib/parser/parse.js +331 -504
  22. package/dist/lib/parser/source.js +72 -0
  23. package/dist/lib/parser/tokenize.js +39 -33
  24. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  25. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  26. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  27. package/dist/lib/parser/utils/at-rule-media.js +284 -283
  28. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  29. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  30. package/dist/lib/parser/utils/at-rule.js +19 -16
  31. package/dist/lib/parser/utils/cache.js +33 -5
  32. package/dist/lib/parser/utils/declaration.js +260 -298
  33. package/dist/lib/parser/utils/hash.js +15 -15
  34. package/dist/lib/parser/utils/selector.js +182 -222
  35. package/dist/lib/parser/utils/token.js +4 -7
  36. package/dist/lib/renderer/render.js +152 -121
  37. package/dist/lib/syntax/color/alpha.js +1 -4
  38. package/dist/lib/syntax/color/color-mix.js +8 -1
  39. package/dist/lib/syntax/color/color.js +17 -9
  40. package/dist/lib/syntax/color/hex.js +1 -1
  41. package/dist/lib/syntax/color/p3.js +9 -1
  42. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  43. package/dist/lib/syntax/color/utils/components.js +21 -22
  44. package/dist/lib/syntax/color/utils/distance.js +6 -1
  45. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  46. package/dist/lib/syntax/constants.js +25 -3
  47. package/dist/lib/syntax/syntax.js +240 -311
  48. package/dist/lib/validation/config.js +16 -17
  49. package/dist/lib/validation/match.js +1118 -1131
  50. package/dist/lib/validation/parser/parse.js +130 -286
  51. package/dist/node.js +18 -14
  52. package/dist/web.js +12 -10
  53. package/package.json +4 -4
  54. package/dist/lib/validation/utils/whitespace.js +0 -17
  55. /package/dist/lib/syntax/color/{relativecolor.js → relative-color.js} +0 -0
package/dist/node.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import process from 'node:process';
2
+ import { deprecate } from 'node:util';
2
3
  import { Readable } from 'node:stream';
3
4
  import { createReadStream } from 'node:fs';
4
5
  import { lstat, readFile } from 'node:fs/promises';
@@ -11,7 +12,6 @@ export { ColorType, EnumAstNodeStatus, EnumToken, ModuleCaseTransformEnum, Valid
11
12
  import { tokenizeStream, tokenize } from './lib/parser/tokenize.js';
12
13
  import { dirname, resolve, matchUrl } from './lib/fs/resolve.js';
13
14
  import { ResponseType } from './types.js';
14
- import { deprecate } from 'util';
15
15
  export { minify } from './lib/ast/minify.js';
16
16
  export { expand } from './lib/ast/expand.js';
17
17
  export { WalkerEvent, WalkerOptionEnum, walk, walkValues } from './lib/ast/walk.js';
@@ -112,6 +112,7 @@ function render(data, options = {}, mapping) {
112
112
  * @param asStream load file as stream
113
113
  *
114
114
  * @deprecated
115
+ * @see {@link parse}
115
116
  * @throws Error file not found
116
117
  *
117
118
  * Example:
@@ -137,7 +138,7 @@ const parseFile = deprecate(async (file, options = {}, asStream = false) => pars
137
138
  *
138
139
  * @throws Error file not found
139
140
  *
140
- * Example:
141
+ * Parsing a string
141
142
  *
142
143
  * ```ts
143
144
  *
@@ -148,7 +149,7 @@ const parseFile = deprecate(async (file, options = {}, asStream = false) => pars
148
149
  * console.log(result.ast);
149
150
  * ```
150
151
  *
151
- * Example using stream
152
+ * Parsing a Readable stream
152
153
  *
153
154
  * ```ts
154
155
  *
@@ -163,7 +164,7 @@ const parseFile = deprecate(async (file, options = {}, asStream = false) => pars
163
164
  * console.log(result.ast);
164
165
  * ```
165
166
  *
166
- * Example using fetch and readable stream
167
+ * Parsing a file as a ReadableStream
167
168
  *
168
169
  * ```ts
169
170
  *
@@ -187,13 +188,21 @@ async function parse(...args) {
187
188
  const { file, input, ...opt } = args[0];
188
189
  options = opt;
189
190
  if (file != null) {
190
- return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => parse(stream, { src: file, ...options }));
191
+ return Promise.resolve((options.load ?? load)(file, "", options.asStream ?? false)).then((stream) => parse(stream, { src: file, ...options }));
191
192
  }
192
193
  else {
193
194
  stream = input;
194
195
  }
195
196
  }
196
197
  options ??= {};
198
+ options.src ??= "";
199
+ Object.assign(options, {
200
+ load,
201
+ resolve,
202
+ dirname,
203
+ cwd: options.cwd ?? process.cwd(),
204
+ });
205
+ options.src = resolve(options.src, options.cwd).relative;
197
206
  options.parseInfo = {
198
207
  stream,
199
208
  buffer: "",
@@ -203,12 +212,7 @@ async function parse(...args) {
203
212
  position: { ind: 0, lin: 1, col: 0 },
204
213
  currentPosition: { ind: -1, lin: 1, col: 0 },
205
214
  };
206
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), Object.assign(options, {
207
- load,
208
- resolve,
209
- dirname,
210
- cwd: options.cwd ?? process.cwd(),
211
- })).then((result) => {
215
+ return doParse(stream instanceof ReadableStream ? tokenizeStream(stream, options.parseInfo) : tokenize(options.parseInfo), options).then((result) => {
212
216
  const { revMapping, ...res } = result;
213
217
  return res;
214
218
  });
@@ -247,7 +251,7 @@ const transformFile = deprecate(async (file, options = {}, asStream = false) =>
247
251
  * @param css
248
252
  * @param options
249
253
  *
250
- * Example:
254
+ * Paarsing a string
251
255
  *
252
256
  * ```ts
253
257
  *
@@ -258,7 +262,7 @@ const transformFile = deprecate(async (file, options = {}, asStream = false) =>
258
262
  * console.log(result.code);
259
263
  * ```
260
264
  *
261
- * Example using stream
265
+ * Parsing a Readable stream
262
266
  *
263
267
  * ```ts
264
268
  *
@@ -297,7 +301,7 @@ async function transform(...args) {
297
301
  const { file, input, ...opt } = args[0];
298
302
  options = opt;
299
303
  if (file != null) {
300
- return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => transform(stream, { src: file, ...options }));
304
+ return Promise.resolve((options.load ?? load)(file, "", options.asStream ?? false)).then((stream) => transform(stream, { src: file, ...options }));
301
305
  }
302
306
  else {
303
307
  stream = input;
package/dist/web.js CHANGED
@@ -164,13 +164,22 @@ async function parse(...args) {
164
164
  const { file, input, ...opt } = args[0];
165
165
  options = opt;
166
166
  if (file != null) {
167
- return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => parse(stream, { src: options.file, ...options }));
167
+ return Promise.resolve((options.load ?? load)(file, "", options.asStream ?? false)).then((stream) => parse(stream, { src: options.file, ...options }));
168
168
  }
169
169
  else {
170
170
  stream = input;
171
171
  }
172
172
  }
173
173
  options ??= {};
174
+ options.src ??= "";
175
+ Object.assign(options, {
176
+ load,
177
+ resolve,
178
+ dirname,
179
+ cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
180
+ ? self.location.pathname
181
+ : dirname(self.location.pathname),
182
+ });
174
183
  options.parseInfo = {
175
184
  stream,
176
185
  buffer: "",
@@ -180,14 +189,7 @@ async function parse(...args) {
180
189
  position: { ind: 0, lin: 1, col: 0 },
181
190
  currentPosition: { ind: -1, lin: 1, col: 0 },
182
191
  };
183
- return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize(options.parseInfo), Object.assign(options, {
184
- load,
185
- resolve,
186
- dirname,
187
- cwd: (options.cwd ?? self.location.pathname.endsWith("/"))
188
- ? self.location.pathname
189
- : dirname(self.location.pathname),
190
- })).then((result) => {
192
+ return doParse(stream instanceof ReadableStream ? tokenizeStream(stream) : tokenize(options.parseInfo), options).then((result) => {
191
193
  const { revMapping, ...res } = result;
192
194
  return res;
193
195
  });
@@ -256,7 +258,7 @@ async function transform(...args) {
256
258
  const { file, input, ...opt } = args[0];
257
259
  options = opt;
258
260
  if (file != null) {
259
- return Promise.resolve((options.load ?? load)(file, ".", options.asStream ?? false)).then((stream) => transform(stream, { src: options.file, ...options }));
261
+ return Promise.resolve((options.load ?? load)(file, "", options.asStream ?? false)).then((stream) => transform(stream, { src: options.file, ...options }));
260
262
  }
261
263
  else {
262
264
  stream = input;
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": "1.4.6",
4
+ "version": "1.4.8",
5
5
  "exports": {
6
6
  ".": "./dist/node.js",
7
7
  "./node": "./dist/node.js",
@@ -21,13 +21,13 @@
21
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\"",
22
22
  "test:web": "web-test-runner \"./test/**/web.spec.js\" --timeout 30000 --node-resolve --playwright --browsers chromium firefox webkit --root-dir=.",
23
23
  "test:node": "mocha -p --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'",
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
+ "test:cov": "superc8 -x 'test/specs/**/*.js' --reporter=html --reporter=text --reporter=json-summary mocha --reporter-options='maxDiffSize=1801920' -p --timeout=10000 'test/allFiles.js' 'test/**/node.spec.js'",
25
+ "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\"",
26
26
  "profile": "deno run --allow-read --cpu-prof --cpu-prof-flamegraph test/inspect.js",
27
27
  "config-update": "esno scripts/shorthand.ts",
28
28
  "syntax-update": "esno scripts/validation.ts",
29
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=."
30
+ "debug:web": "web-test-runner \"./test/specs/web.spec.js\" --manual --open --node-resolve --root-dir=."
31
31
  },
32
32
  "repository": {
33
33
  "type": "git",
@@ -1,17 +0,0 @@
1
- import { EnumToken } from '../../ast/types.js';
2
-
3
- function consumeWhitespace(tokens) {
4
- if (tokens.length == 0) {
5
- return true;
6
- }
7
- if (tokens[0].typ != EnumToken.WhitespaceTokenType && tokens[0].typ != EnumToken.DescendantCombinatorTokenType) {
8
- return false;
9
- }
10
- while (tokens.length > 0 &&
11
- (tokens[0].typ == EnumToken.WhitespaceTokenType || tokens[0].typ == EnumToken.DescendantCombinatorTokenType)) {
12
- tokens.shift();
13
- }
14
- return true;
15
- }
16
-
17
- export { consumeWhitespace };