@tbela99/css-parser 1.4.5 → 1.4.7

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 (47) hide show
  1. package/CHANGELOG.md +23 -2
  2. package/README.md +2 -0
  3. package/dist/index-umd-web.js +6546 -6987
  4. package/dist/index.cjs +7784 -8223
  5. package/dist/index.d.ts +919 -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 +6 -2
  15. package/dist/lib/ast/walk.js +1 -1
  16. package/dist/lib/fs/resolve.js +46 -44
  17. package/dist/lib/parser/declaration/list.js +9 -10
  18. package/dist/lib/parser/declaration/map.js +13 -18
  19. package/dist/lib/parser/parse.js +331 -506
  20. package/dist/lib/parser/tokenize.js +39 -33
  21. package/dist/lib/parser/utils/at-rule-container.js +244 -247
  22. package/dist/lib/parser/utils/at-rule-generic.js +25 -25
  23. package/dist/lib/parser/utils/at-rule-import.js +194 -234
  24. package/dist/lib/parser/utils/at-rule-media.js +286 -286
  25. package/dist/lib/parser/utils/at-rule-support.js +279 -251
  26. package/dist/lib/parser/utils/at-rule-when-else.js +256 -259
  27. package/dist/lib/parser/utils/at-rule.js +19 -16
  28. package/dist/lib/parser/utils/cache.js +33 -5
  29. package/dist/lib/parser/utils/declaration.js +260 -322
  30. package/dist/lib/parser/utils/hash.js +15 -15
  31. package/dist/lib/parser/utils/selector.js +182 -222
  32. package/dist/lib/parser/utils/token.js +4 -7
  33. package/dist/lib/renderer/render.js +150 -120
  34. package/dist/lib/syntax/color/alpha.js +1 -4
  35. package/dist/lib/syntax/color/color.js +5 -5
  36. package/dist/lib/syntax/color/utils/colorspace.js +3 -3
  37. package/dist/lib/syntax/color/utils/components.js +21 -22
  38. package/dist/lib/syntax/color/utils/matrix.js +12 -11
  39. package/dist/lib/syntax/constants.js +22 -3
  40. package/dist/lib/syntax/syntax.js +252 -311
  41. package/dist/lib/validation/config.js +16 -17
  42. package/dist/lib/validation/match.js +1118 -1131
  43. package/dist/lib/validation/parser/parse.js +130 -286
  44. package/dist/node.js +16 -12
  45. package/dist/web.js +10 -8
  46. package/package.json +4 -4
  47. package/dist/lib/validation/utils/whitespace.js +0 -17
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
  *
@@ -194,6 +195,14 @@ async function parse(...args) {
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
  *
package/dist/web.js CHANGED
@@ -171,6 +171,15 @@ async function parse(...args) {
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
  });
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.5",
4
+ "version": "1.4.7",
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/**/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 };