@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
@@ -1,6 +1,6 @@
1
1
  import { EnumToken, ColorType } from '../ast/types.js';
2
- import { definedPropertySettings, wildCardFuncs, whenElseFunc, transformFunctions, mathFuncs, colorsFunc, timingFunc, supportFunc, generalEnclosedFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc } from '../syntax/constants.js';
3
- import { isDigit, isPseudo, isIdent, isWhiteSpace, isNumber, isNewLine, isHexColor, isHash, isPercentage, parseDimension } from '../syntax/syntax.js';
2
+ import { LOC, wildCardFuncs, whenElseFunc, transformFunctions, mathFuncs, colorsFunc, timingFunc, supportFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc, pseudoElements } from '../syntax/constants.js';
3
+ import { isDigit, isPseudo, isIdent, isWhiteSpace, isNumber, isHexColor, isHash, isPercentage, parseDimension, isNewLine } from '../syntax/syntax.js';
4
4
  import { equalsIgnoreCase } from './utils/text.js';
5
5
 
6
6
  const SymbolsMapTokens = {
@@ -34,6 +34,10 @@ const SymbolsMapTokens = {
34
34
  "\r": EnumToken.Whitespace,
35
35
  "\n": EnumToken.Whitespace,
36
36
  "\f": EnumToken.Whitespace,
37
+ ...pseudoElements.reduce((acc, curr) => {
38
+ acc[curr] = EnumToken.PseudoElementTokenType;
39
+ return acc;
40
+ }, Object.create(null)),
37
41
  ...containerFunc.reduce((acc, curr) => {
38
42
  acc[curr + "("] = EnumToken.ContainerFunctionTokenDefType;
39
43
  return acc;
@@ -54,10 +58,10 @@ const SymbolsMapTokens = {
54
58
  acc[curr + "("] = EnumToken.TimelineFunctionTokenDefType;
55
59
  return acc;
56
60
  }, Object.create(null)),
57
- ...generalEnclosedFunc.reduce((acc, curr) => {
58
- acc[curr + "("] = EnumToken.GeneralEnclosedFunctionTokenDefType;
59
- return acc;
60
- }, Object.create(null)),
61
+ // ...generalEnclosedFunc.reduce((acc, curr: string) => {
62
+ // acc[curr + "("] = EnumToken.GeneralEnclosedFunctionTokenDefType;
63
+ // return acc;
64
+ // }, Object.create(null)),
61
65
  ...supportFunc.reduce((acc, curr) => {
62
66
  acc[curr + "("] = EnumToken.SupportsFunctionTokenDefType;
63
67
  return acc;
@@ -206,7 +210,7 @@ function consumeString(quoteStr, buffer, parseInfo) {
206
210
  result.push(yieldResult(buffer + quote, parseInfo, EnumToken.StringTokenType));
207
211
  return result;
208
212
  }
209
- function getTokenType(val, hint) {
213
+ function yieldResult(val, parseInfo, hint) {
210
214
  let token = null;
211
215
  let dimension;
212
216
  if (hint != null) {
@@ -233,9 +237,9 @@ function getTokenType(val, hint) {
233
237
  case EnumToken.TimelineFunctionTokenDefType:
234
238
  searchArray = timelineFunc;
235
239
  break;
236
- case EnumToken.GeneralEnclosedFunctionTokenDefType:
237
- searchArray = generalEnclosedFunc;
238
- break;
240
+ // case EnumToken.GeneralEnclosedFunctionTokenDefType:
241
+ // searchArray = generalEnclosedFunc;
242
+ // break;
239
243
  case EnumToken.SupportsFunctionTokenDefType:
240
244
  searchArray = supportFunc;
241
245
  break;
@@ -259,19 +263,20 @@ function getTokenType(val, hint) {
259
263
  }
260
264
  else {
261
265
  let slice = val.slice(1);
262
- if (val.charAt(0) == "@" && isIdent(slice)) {
266
+ const chr = val.charAt(0);
267
+ if (chr == "@" && isIdent(slice)) {
263
268
  token = {
264
269
  typ: EnumToken.AtRuleTokenType,
265
270
  nam: slice,
266
271
  };
267
272
  }
268
- else if (val.charAt(0) == "." && isIdent(slice)) {
273
+ else if (chr == "." && isIdent(slice)) {
269
274
  token = {
270
275
  typ: EnumToken.ClassSelectorTokenType,
271
276
  val,
272
277
  };
273
278
  }
274
- else if (val.charAt(0) == "#") {
279
+ else if (chr == "#") {
275
280
  if (isHexColor(val)) {
276
281
  token = {
277
282
  typ: EnumToken.ColorTokenType,
@@ -286,7 +291,7 @@ function getTokenType(val, hint) {
286
291
  };
287
292
  }
288
293
  }
289
- else if ("\"'".includes(val.charAt(0))) {
294
+ else if ("\"'".includes(chr)) {
290
295
  token = {
291
296
  typ: EnumToken.UnclosedStringTokenType,
292
297
  val: val,
@@ -327,19 +332,12 @@ function getTokenType(val, hint) {
327
332
  val,
328
333
  };
329
334
  }
330
- return token;
331
- }
332
- function yieldResult(val, parseInfo, hint) {
333
- const token = getTokenType(val, hint);
334
- Object.defineProperty(token, "loc", {
335
- ...definedPropertySettings,
336
- enumerable: false,
337
- value: {
338
- src: parseInfo.src,
339
- sta: { ...parseInfo.position },
340
- end: { ...parseInfo.currentPosition },
341
- },
342
- });
335
+ // return token;
336
+ token[LOC] = {
337
+ src: parseInfo.src,
338
+ sta: { ...parseInfo.position },
339
+ end: { ...parseInfo.currentPosition },
340
+ };
343
341
  parseInfo.position.ind = parseInfo.currentPosition.ind;
344
342
  parseInfo.position.lin = parseInfo.currentPosition.lin;
345
343
  parseInfo.position.col = parseInfo.currentPosition.col;
@@ -407,6 +405,8 @@ function tokenize(parseInfo, yieldEOFToken = true) {
407
405
  let nextCharCode;
408
406
  const startTime = performance.now();
409
407
  const result = [];
408
+ // allow 10 characters buffer for the streaming parser to avoid incomplete tokens
409
+ const endPosition = parseInfo.stream.length - 10;
410
410
  parseInfo.buffer = "";
411
411
  while ((value = next(parseInfo))) {
412
412
  nextValue = parseInfo.stream.charAt(parseInfo.currentPosition.ind - parseInfo.offset + 1);
@@ -682,7 +682,9 @@ function tokenize(parseInfo, yieldEOFToken = true) {
682
682
  if (match(parseInfo, "important")) {
683
683
  result.push(yieldResult(value + next(parseInfo, 9), parseInfo, EnumToken.ImportantTokenType));
684
684
  buffer = "";
685
+ break;
685
686
  }
687
+ buffer += value;
686
688
  break;
687
689
  case 47 /* TokenMap.SLASH */:
688
690
  if (buffer.length > 0) {
@@ -793,6 +795,10 @@ function tokenize(parseInfo, yieldEOFToken = true) {
793
795
  buffer += value;
794
796
  break;
795
797
  }
798
+ if (!yieldEOFToken &&
799
+ endPosition <= parseInfo.stream.length - parseInfo.currentPosition.ind + parseInfo.offset) {
800
+ break;
801
+ }
796
802
  }
797
803
  if (yieldEOFToken) {
798
804
  if (buffer.length > 0) {
@@ -826,14 +832,14 @@ async function* tokenizeStream(input, parseInfo) {
826
832
  const { done, value } = await reader.read();
827
833
  const stream = ArrayBuffer.isView(value) ? decoder.decode(value, { stream: true }) : value;
828
834
  if (!done) {
829
- if (parseInfo.stream.length > 2) {
830
- parseInfo.stream = parseInfo.stream.slice(-2) + stream;
831
- parseInfo.offset = parseInfo.currentPosition.ind - 1;
835
+ if (typeof parseInfo.stream != "string") {
836
+ parseInfo.stream = stream;
832
837
  }
833
838
  else {
834
- parseInfo.stream = stream;
835
- parseInfo.offset = Math.max(0, parseInfo.currentPosition.ind);
839
+ parseInfo.stream = (parseInfo.stream.slice(parseInfo.currentPosition.ind - parseInfo.offset + 1) +
840
+ stream);
836
841
  }
842
+ parseInfo.offset = parseInfo.currentPosition.ind + 1;
837
843
  }
838
844
  yield* tokenize(parseInfo, done);
839
845
  if (done) {
@@ -859,4 +865,4 @@ function move(position, str) {
859
865
  }
860
866
  }
861
867
 
862
- export { SymbolsMapTokens, TokenMap, consumeString, getTokenType, hintsEnum, match, move, next, peek, tokenize, tokenizeStream, yieldResult };
868
+ export { SymbolsMapTokens, TokenMap, consumeString, hintsEnum, match, move, next, peek, tokenize, tokenizeStream, yieldResult };