@tbela99/css-parser 1.6.1 → 1.6.3

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 (39) hide show
  1. package/CHANGELOG.md +119 -2
  2. package/README.md +1 -0
  3. package/dist/index-umd-web.js +1214 -247
  4. package/dist/index.cjs +1214 -247
  5. package/dist/index.d.ts +71 -6
  6. package/dist/lib/ast/features/prefix.js +9 -1
  7. package/dist/lib/ast/features/shorthand.js +1 -1
  8. package/dist/lib/ast/math/expression.js +156 -1
  9. package/dist/lib/ast/transform/compute.js +4 -8
  10. package/dist/lib/ast/types.js +12 -0
  11. package/dist/lib/parser/declaration/list.js +8 -10
  12. package/dist/lib/parser/parse.js +2 -9
  13. package/dist/lib/parser/tokenize.js +50 -18
  14. package/dist/lib/parser/utils/at-rule-font-feature-values.js +1 -1
  15. package/dist/lib/parser/utils/at-rule-media.js +66 -0
  16. package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
  17. package/dist/lib/parser/utils/base64.js +14 -0
  18. package/dist/lib/parser/utils/declaration.js +7 -14
  19. package/dist/lib/parser/utils/eq.js +6 -0
  20. package/dist/lib/parser/utils/hash.js +1 -0
  21. package/dist/lib/parser/utils/selector.js +1 -1
  22. package/dist/lib/parser/utils/text.js +16 -0
  23. package/dist/lib/renderer/render.js +18 -4
  24. package/dist/lib/renderer/sourcemap/lib/codec.js +5 -0
  25. package/dist/lib/renderer/sourcemap/sourcemap.js +35 -5
  26. package/dist/lib/syntax/color/alpha.js +57 -22
  27. package/dist/lib/syntax/color/color-mix.js +18 -18
  28. package/dist/lib/syntax/color/srgb.js +10 -5
  29. package/dist/lib/syntax/color/utils/components.js +1 -1
  30. package/dist/lib/syntax/color/utils/distance.js +2 -2
  31. package/dist/lib/syntax/color/utils/matrix.js +1 -0
  32. package/dist/lib/syntax/color/xyz.js +5 -0
  33. package/dist/lib/syntax/color/xyzd50.js +17 -0
  34. package/dist/lib/syntax/syntax.js +549 -13
  35. package/dist/lib/validation/config.js +26 -0
  36. package/dist/lib/validation/match.js +16 -4
  37. package/dist/node.js +8 -14
  38. package/dist/web.js +8 -14
  39. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -653,6 +653,18 @@ declare enum EnumToken {
653
653
  * wrapped values token type like {Arial, sans-serif}
654
654
  */
655
655
  WrappedValuesTokenType = 140,
656
+ /**
657
+ * infinity token
658
+ */
659
+ NaNTokenType = 141,
660
+ /**
661
+ * infinity token
662
+ */
663
+ InfinityTokenType = 142,
664
+ /**
665
+ * negative infinity token
666
+ */
667
+ NegativeInfinityTokenType = 143,
656
668
  /**
657
669
  * alias for time token type
658
670
  */
@@ -1146,6 +1158,27 @@ export declare interface NumberToken extends BaseToken {
1146
1158
  val: number | FractionToken;
1147
1159
  }
1148
1160
 
1161
+ export declare interface NaNToken extends BaseToken {
1162
+ /**
1163
+ * @inheritdoc
1164
+ */
1165
+ typ: EnumToken.NaNTokenType;
1166
+ }
1167
+
1168
+ export declare interface InfinityToken extends BaseToken {
1169
+ /**
1170
+ * @inheritdoc
1171
+ */
1172
+ typ: EnumToken.InfinityTokenType;
1173
+ }
1174
+
1175
+ export declare interface NegativeInfinityToken extends BaseToken {
1176
+ /**
1177
+ * @inheritdoc
1178
+ */
1179
+ typ: EnumToken.NegativeInfinityTokenType;
1180
+ }
1181
+
1149
1182
  /**
1150
1183
  * At rule token
1151
1184
  */
@@ -2649,6 +2682,9 @@ export declare type Token$1 =
2649
2682
  | FunctionDefToken
2650
2683
  | RawNodeToken
2651
2684
  | InvalidMediaQueryToken
2685
+ | NaNToken
2686
+ | InfinityToken
2687
+ | NegativeInfinityToken
2652
2688
  | EOFToken;
2653
2689
 
2654
2690
  /**
@@ -3936,6 +3972,35 @@ export declare interface VisitorNodeMap {
3936
3972
 
3937
3973
  /**
3938
3974
  * Generate and parse source map
3975
+ *
3976
+ * ```ts
3977
+ * const sourcemap = new SourceMap();
3978
+ *
3979
+ * // you can also pass an input sourcemap
3980
+ * // const sourcemap = new SourceMap(sourcemapObjectOrJSONString);
3981
+ *
3982
+ * sourcemap.addSourceContent(0, '/css/styles.css', null);
3983
+ * sourcemap.addSourceContent(1, '/css/typography.css', null);
3984
+ *
3985
+ * const maps = [];
3986
+ *
3987
+ * maps.add([
3988
+ 1, 1, 0, 1, 1]);
3989
+ * maps.add([
3990
+ 2, 1, 1, 1, 1
3991
+ ]);
3992
+
3993
+ sourcemap.add(maps);
3994
+
3995
+ // convert to inline sourcemap
3996
+ sourcemap.toUrl();
3997
+
3998
+ // convert to JSON
3999
+ sourcemap.toJSON();
4000
+
4001
+ // find the original file, line and column
4002
+ sourcemap.find(2, 1);
4003
+ ```
3939
4004
  */
3940
4005
  declare class SourceMap {
3941
4006
  /**
@@ -3995,9 +4060,9 @@ declare class SourceMap {
3995
4060
  constructor(sourcemaps: string | SourceMapObject);
3996
4061
  /**
3997
4062
  * add source
3998
- * @param id
3999
- * @param fileName
4000
- * @param content
4063
+ * @param id source id
4064
+ * @param fileName source file
4065
+ * @param content source content
4001
4066
  * @returns
4002
4067
  */
4003
4068
  addSourceContent(id: number, fileName: string | null, content: string | null): void;
@@ -6304,11 +6369,11 @@ declare function convertColor(token: ColorToken, to: ColorType$1): ColorToken |
6304
6369
 
6305
6370
  /**
6306
6371
  * Calculate the distance between two okLab colors.
6307
- * @param okLab1
6308
- * @param okLab2
6309
6372
  *
6310
6373
  * @private
6311
6374
  * {@link https://drafts.csswg.org/css-color-4/#comparing-color-values}
6375
+ * @param color1
6376
+ * @param color2
6312
6377
  */
6313
6378
  declare function okLabDistance(color1: ColorToken, color2: ColorToken): number | null;
6314
6379
  /**
@@ -6938,4 +7003,4 @@ declare function transform(options: ParseInputStreamOptions & TransformOptions):
6938
7003
  declare function transform(options: ParseInputFileOptions & TransformOptions): Promise<TransformResult>;
6939
7004
 
6940
7005
  export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType, SourceMap, ValidationLevel, WalkerEvent, WalkerOptionEnum, cloneNode, convertColor, dirname, expand, find, findAll, findByValue, findLast, getNodeProperty, isOkLabClose, load, minify, okLabDistance, parse, parseDeclarations, parseFile, parseString, parseSync, render, renderValue as renderToken, replaceNodeOrValue, resolve, setNodeProperty, transform, transformFile, transformSync, walk, walkValues };
6941
- export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NameSpaceAttributeToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenSearchResult, TokenizeResult, TransformOptions, TransformResult, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerOptions, WalkerValueFilter, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken };
7006
+ export type { AddToken, AndToken, AngleToken, AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyframesAtRule, AstKeyframesRule, AstNode$1 as AstNode, AstNodeStatus, AstRule, AstRuleList, AstStyleSheet, AstValueMatcher, AtRuleToken, AtRuleVisitorHandler, AttrEndToken, AttrStartToken, AttrToken, Background, BackgroundAttachmentMapping, BackgroundPosition, BackgroundPositionClass, BackgroundPositionConstraints, BackgroundPositionMapping, BackgroundProperties, BackgroundRepeat, BackgroundRepeatMapping, BackgroundSize, BackgroundSizeMapping, BadCDOCommentToken, BadCommentToken, BadStringToken, BadUrlToken, BaseToken, BinaryExpressionNode, BinaryExpressionToken, BlockEndToken, BlockStartToken, Border, BorderColor, BorderColorClass, BorderProperties, BorderRadius, CDOCommentToken, ChildCombinatorToken, ClassSelectorToken, ColonToken, ColorToken, ColumnCombinatorToken, CommaToken, CommentToken, ComposesSelectorToken, ConstraintsMapping, ContainMatchToken, ContainerStyleRangeToken, CssVariableImportTokenType, CssVariableMapTokenType, CssVariableToken, DashMatchToken, DashedIdentToken, DeclarationVisitorHandler, DelimToken, DescendantCombinatorToken, DimensionToken, DivToken, DoubleColonToken, EOFToken, EndMatchToken, EqualMatchToken, ErrorDescription$1 as ErrorDescription, FlexToken, Font, FontFamily, FontProperties, FontWeight, FontWeightConstraints, FontWeightMapping, FractionToken, FrequencyToken, FunctionDefToken, FunctionImageToken, FunctionToken, FunctionURLToken, GenericVisitorAstNodeHandlerMap, GenericVisitorAstNodeSyncHandlerMap, GenericVisitorAsyncResult, GenericVisitorHandler, GenericVisitorResult, GenericVisitorSyncHandler, GenericVisitorSyncResult, GreaterThanOrEqualToken, GreaterThanToken, GridTemplateFuncToken, HashToken, IdentListToken, IdentToken, IfConditionToken, IfElseConditionToken, ImportantToken, IncludeMatchToken, InfinityToken, InvalidAttrToken, InvalidClassSelectorToken, InvalidMediaQueryToken, LengthToken, LessThanOrEqualToken, LessThanToken, LineHeight, ListToken, LiteralToken, LoadResult, Map$1 as Map, MatchExpressionToken, MatchedSelector, MediaFeatureOnlyToken, MediaFeatureToken, MediaQueryConditionToken, MediaQueryUnaryFeatureToken, MediaRangeQueryToken, MinifyFeature, MinifyFeatureOptions, MinifyOptions, ModuleAsyncOptions, ModuleSyncOptions, MulToken, NaNToken, NameSpaceAttributeToken, NegativeInfinityToken, NestingSelectorToken, NextSiblingCombinatorToken, NotToken, NumberToken, OptimizedSelector, OptimizedSelectorToken, OrToken, Outline, OutlineProperties, ParensEndToken, ParensStartToken, ParensToken, ParseInfo$1 as ParseInfo, ParseInputFileOptions, ParseInputOptions, ParseInputStreamOptions, ParseResult, ParseResultStats, ParseSourceOptions, ParseTokenOptions, ParserOptions, ParserSourceMapOptions, ParserSyncOptions, PercentageToken, Prefix, PropertiesConfig, PropertiesConfigProperties, PropertyListOptions, PropertyMapType, PropertySetType, PropertyType, PseudoClassFunctionToken, PseudoClassToken, PseudoElementToken, PseudoPageToken, PurpleBackgroundAttachment, RawNodeToken, RawSelectorTokens, RenderOptions, RenderResult, ResolutionToken, ResolvedPath, RuleVisitorHandler, SemiColonToken, Separator, ShorthandDef, ShorthandMapType, ShorthandProperties, ShorthandPropertyType, ShorthandType, SinglePropertyType, SinglePropertyTypeMapping, SourceLocation, SourceMapObject, StartMatchToken, StringToken, SubToken, SubsequentCombinatorToken, SupportsQueryConditionToken, SupportsQueryUnaryConditionToken, TimeToken, TimelineFunctionToken, TimingFunctionToken, Token$1 as Token, TokenSearchResult, TokenizeResult, TransformOptions, TransformResult, TransformSyncOptions, UnaryExpression, UnaryExpressionNode, UnclosedStringToken, UniversalSelectorToken, UrlToken, ValidationConfiguration, ValidationMediaFeature, ValidationOptions, ValidationResult, ValidationSelectorOptions, ValidationSyntaxNode, ValidationSyntaxResult, ValidationToken$1 as ValidationToken, Value, ValueVisitorHandler, ValueVisitorSyncHandler, VariableScopeInfo, VisitorNodeMap, VisitorSyncNodeMap, WalkAttributesResult, WalkResult, WalkerFilter, WalkerOption, WalkerOptions, WalkerValueFilter, WhenElseQueryConditionToken, WhenElseUnaryConditionToken, WhitespaceToken, WrappedValuesToken };
@@ -37,7 +37,6 @@ function replaceAstNodes(tokens, root) {
37
37
  token.val = pseudoAliasMap[token.val];
38
38
  if ((equalsIgnoreCase(token.val, "min-resolution") ||
39
39
  equalsIgnoreCase(token.val, "max-resolution")) &&
40
- // ["min-resolution", "max-resolution"].includes((token as IdentToken).val) &&
41
40
  value.r?.[0]?.typ == EnumToken.NumberTokenType) {
42
41
  Object.assign(value.r?.[0], {
43
42
  typ: EnumToken.ResolutionTokenType,
@@ -45,6 +44,14 @@ function replaceAstNodes(tokens, root) {
45
44
  });
46
45
  result = true;
47
46
  }
47
+ let isMin = token.val.startsWith("min-");
48
+ let isMax = token.val.startsWith("max-");
49
+ if (isMin || isMax) {
50
+ token.val = token.val.slice(4);
51
+ value.op.typ = isMax
52
+ ? EnumToken.LteTokenType
53
+ : EnumToken.GteTokenType;
54
+ }
48
55
  }
49
56
  }
50
57
  }
@@ -77,6 +84,7 @@ function replaceAstNodes(tokens, root) {
77
84
  }
78
85
  }
79
86
  }
87
+ // remove duplicate tokens
80
88
  if (tokens.find((t) => t.typ == EnumToken.CommaTokenType) != null) {
81
89
  const set = new Set();
82
90
  const split = splitTokenList(tokens, [EnumToken.CommaTokenType]);
@@ -21,7 +21,7 @@ class ComputeShorthandFeature {
21
21
  }
22
22
  }
23
23
  run(ast, options) {
24
- if (!("chi" in ast)) {
24
+ if (!("chi" in ast || ast.chi?.length == 0)) {
25
25
  return null;
26
26
  }
27
27
  // @ts-ignore
@@ -1,3 +1,4 @@
1
+ import { equalsIgnoreCase } from '../../parser/utils/text.js';
1
2
  import { mathFuncs, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
2
3
  import { EnumToken } from '../types.js';
3
4
  import { rem, compute } from './math.js';
@@ -155,6 +156,35 @@ function doEvaluate(l, r, op) {
155
156
  if (!isScalarToken(l) || !isScalarToken(r) || (l.typ == r.typ && "unit" in l && "unit" in r && l.unit != r.unit)) {
156
157
  return defaultReturn;
157
158
  }
159
+ if (l.typ == EnumToken.IdenTokenType) {
160
+ if (equalsIgnoreCase(l.val, "Infinity")) {
161
+ Object.assign(l, { typ: EnumToken.InfinityTokenType });
162
+ }
163
+ else if (equalsIgnoreCase(l.val, "-Infinity")) {
164
+ Object.assign(l, { typ: EnumToken.NegativeInfinityTokenType });
165
+ }
166
+ else if (equalsIgnoreCase(l.val, "NaN")) {
167
+ Object.assign(l, { typ: EnumToken.NaNTokenType });
168
+ }
169
+ }
170
+ if (r.typ == EnumToken.IdenTokenType) {
171
+ if (equalsIgnoreCase(r.val, "Infinity")) {
172
+ Object.assign(r, { typ: EnumToken.InfinityTokenType });
173
+ }
174
+ else if (equalsIgnoreCase(r.val, "-Infinity")) {
175
+ Object.assign(r, { typ: EnumToken.NegativeInfinityTokenType });
176
+ }
177
+ }
178
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/calc-keyword#notes
179
+ if (l.typ == EnumToken.NaNTokenType || r.typ == EnumToken.NaNTokenType) {
180
+ return computeNaN(l, r, defaultReturn);
181
+ }
182
+ if (l.typ == EnumToken.InfinityTokenType ||
183
+ l.typ == EnumToken.NegativeInfinityTokenType ||
184
+ r.typ == EnumToken.InfinityTokenType ||
185
+ r.typ == EnumToken.NegativeInfinityTokenType) {
186
+ return computeInfinity(l, r, op, defaultReturn);
187
+ }
158
188
  if (r.typ == EnumToken.FunctionTokenType || r.typ == EnumToken.MathFunctionTokenType) {
159
189
  const val = evaluateFunc(r);
160
190
  if (val == null) {
@@ -225,6 +255,18 @@ function doEvaluate(l, r, op) {
225
255
  }
226
256
  }
227
257
  }
258
+ if (op == EnumToken.Div && v2 == 0) {
259
+ if (v1 == 0) {
260
+ return Object.assign(l, { typ: EnumToken.IdenTokenType, val: "NaN" });
261
+ }
262
+ let sign = Math.sign(v1) * Math.sign(v2);
263
+ sign = Object.is(sign, -0) ? -1 : 1;
264
+ Object.assign(l, {
265
+ typ: l.typ == EnumToken.IdenTokenType ? EnumToken.NumberTokenType : l.typ,
266
+ val: Object.is(sign, -0) ? -1 : sign,
267
+ });
268
+ return defaultReturn;
269
+ }
228
270
  // @ts-ignore
229
271
  const val = compute(v1, v2, op);
230
272
  const token = {
@@ -241,6 +283,112 @@ function doEvaluate(l, r, op) {
241
283
  }
242
284
  return token;
243
285
  }
286
+ /**
287
+ *
288
+ * @param l
289
+ * @param r
290
+ * @param defaultReturn
291
+ * @returns
292
+ */
293
+ function computeNaN(l, r, defaultReturn) {
294
+ if (l.typ == EnumToken.NaNTokenType) {
295
+ if (r.typ == EnumToken.NumberTokenType ||
296
+ // @ts-expect-error
297
+ (r.typ == EnumToken.IdenTokenType && typeof Math[r.val.toUpperCase()] == "string")) {
298
+ return l;
299
+ }
300
+ // NaN Infinity e pi ...
301
+ if (r.typ == EnumToken.IdenTokenType ||
302
+ r.typ == EnumToken.InfinityTokenType ||
303
+ r.typ == EnumToken.NegativeInfinityTokenType) {
304
+ return l;
305
+ }
306
+ if (typeof r.val == "number") {
307
+ Object.assign(r, { val: 1 });
308
+ }
309
+ return r.typ == EnumToken.NaNTokenType ? l : defaultReturn;
310
+ }
311
+ if (r.typ == EnumToken.NaNTokenType) {
312
+ // if ((r as IdentToken).val == "NaN") {
313
+ if (l.typ == EnumToken.NumberTokenType ||
314
+ // @ts-expect-error
315
+ (l.typ == EnumToken.IdenTokenType && typeof Math[l.val.toUpperCase()] == "string")) {
316
+ return r;
317
+ }
318
+ if (typeof l.val == "number") {
319
+ Object.assign(l, { val: 1 });
320
+ }
321
+ // return defaultReturn;
322
+ }
323
+ // }
324
+ return defaultReturn;
325
+ }
326
+ /**
327
+ *
328
+ * @param l
329
+ * @param r
330
+ * @param op
331
+ * @param defaultReturn
332
+ * @returns
333
+ */
334
+ function computeInfinity(l, r, op, defaultReturn) {
335
+ if (l.typ == EnumToken.InfinityTokenType || l.typ == EnumToken.NegativeInfinityTokenType) {
336
+ if (r.typ == EnumToken.InfinityTokenType || r.typ == EnumToken.NegativeInfinityTokenType) {
337
+ // Infinity / Infinity Infinity - Infinity
338
+ if (op == EnumToken.Div ||
339
+ (op == EnumToken.Add && l.typ != r.typ) ||
340
+ (op == EnumToken.Sub && l.typ == r.typ)) {
341
+ return Object.assign(l, { typ: EnumToken.NaNTokenType });
342
+ }
343
+ if (l.typ != r.typ) {
344
+ l.typ = EnumToken.NegativeInfinityTokenType;
345
+ }
346
+ return l;
347
+ }
348
+ const value = getValue(r);
349
+ const sign = Math.sign(value);
350
+ const isNumber = r.typ == EnumToken.NumberTokenType || r.typ == EnumToken.IdenTokenType;
351
+ // Infinity * 0
352
+ if (value == 0 && op == EnumToken.Mul) {
353
+ l.typ = EnumToken.NaNTokenType;
354
+ return isNumber ? l : defaultReturn;
355
+ }
356
+ if (isNumber) {
357
+ // @ts-ignore
358
+ r.val /= r.val * sign;
359
+ }
360
+ if (op == EnumToken.Div) {
361
+ return isNumber
362
+ ? Object.assign(r, { typ: EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
363
+ : defaultReturn;
364
+ }
365
+ if (sign == -1) {
366
+ l.typ =
367
+ l.typ == EnumToken.InfinityTokenType
368
+ ? EnumToken.NegativeInfinityTokenType
369
+ : EnumToken.InfinityTokenType;
370
+ }
371
+ return isNumber ? l : defaultReturn;
372
+ }
373
+ if (r.typ == EnumToken.InfinityTokenType || r.typ == EnumToken.NegativeInfinityTokenType) {
374
+ const value = getValue(l);
375
+ let sign = Math.sign(value);
376
+ const isNumber = l.typ == EnumToken.NumberTokenType || l.typ == EnumToken.IdenTokenType;
377
+ if (isNumber) {
378
+ Object.assign(l, { typ: EnumToken.NumberTokenType, val: sign });
379
+ }
380
+ if (value == 0 && op == EnumToken.Mul) {
381
+ return Object.assign(l, { typ: EnumToken.NaNTokenType });
382
+ }
383
+ if (op == EnumToken.Div) {
384
+ return isNumber
385
+ ? Object.assign(l, { typ: EnumToken.NumberTokenType, val: sign < 0 ? -0 : 0 })
386
+ : defaultReturn;
387
+ }
388
+ return l.typ == isNumber || value == 0 ? r : defaultReturn;
389
+ }
390
+ return defaultReturn;
391
+ }
244
392
  function getValue(t) {
245
393
  if (t.typ == EnumToken.IdenTokenType) {
246
394
  // @ts-ignore
@@ -575,7 +723,14 @@ function isScalarToken(token) {
575
723
  (token.typ == EnumToken.FunctionTokenType && mathFuncs.includes(token.val)) ||
576
724
  // @ts-ignore
577
725
  (token.typ == EnumToken.IdenTokenType && typeof Math[token.val.toUpperCase()] == "number") ||
578
- [EnumToken.NumberTokenType, EnumToken.FractionTokenType, EnumToken.PercentageTokenType].includes(token.typ));
726
+ (token.typ == EnumToken.IdenTokenType && token.val == "NaN") ||
727
+ (token.typ == EnumToken.IdenTokenType &&
728
+ (equalsIgnoreCase(token.val, "Infinity") ||
729
+ equalsIgnoreCase(token.val, "-Infinity"))) ||
730
+ [EnumToken.NumberTokenType, EnumToken.FractionTokenType, EnumToken.PercentageTokenType].includes(token.typ) ||
731
+ token.typ == EnumToken.NaNTokenType ||
732
+ token.typ == EnumToken.InfinityTokenType ||
733
+ token.typ == EnumToken.NegativeInfinityTokenType);
579
734
  }
580
735
  /**
581
736
  *
@@ -2,7 +2,7 @@ import { identity, multiply, toZero } from './utils.js';
2
2
  import { EnumToken } from '../types.js';
3
3
  import { stripCommaToken } from '../../validation/utils/list.js';
4
4
  import { translateX, translateY, translateZ, translate, translate3d } from './translate.js';
5
- import { getNumber, getAngle } from '../../syntax/color/color.js';
5
+ import { getAngle, getNumber } from '../../syntax/color/color.js';
6
6
  import { rotate, rotate3D } from './rotate.js';
7
7
  import { scale3d, scale, scaleX, scaleY, scaleZ } from './scale.js';
8
8
  import { minify } from './minify.js';
@@ -18,7 +18,6 @@ function compute(transformLists) {
18
18
  let matrix = identity();
19
19
  let mat;
20
20
  let transforms;
21
- let shouldComputeMatrix = true;
22
21
  const cumulative = [];
23
22
  // all transform function arguments must be 0 or scale(1)
24
23
  for (const transform of transformLists) {
@@ -37,17 +36,14 @@ function compute(transformLists) {
37
36
  child.typ != EnumToken.PercentageTokenType) ||
38
37
  // angle >= 360deg, do not transform
39
38
  Math.abs(getAngle(child)) >= 1) {
40
- shouldComputeMatrix = false;
39
+ return null;
41
40
  }
42
41
  }
43
- break;
44
- }
45
- if (!shouldComputeMatrix) {
46
- break;
42
+ // break;
47
43
  }
48
44
  }
49
45
  for (const transformList of splitTransformList(transformLists)) {
50
- mat = shouldComputeMatrix ? computeMatrix(transformList, identity()) : null;
46
+ mat = computeMatrix(transformList, identity());
51
47
  if (mat == null) {
52
48
  return null;
53
49
  }
@@ -660,6 +660,18 @@ var EnumToken;
660
660
  * wrapped values token type like {Arial, sans-serif}
661
661
  */
662
662
  EnumToken[EnumToken["WrappedValuesTokenType"] = 140] = "WrappedValuesTokenType";
663
+ /**
664
+ * infinity token
665
+ */
666
+ EnumToken[EnumToken["NaNTokenType"] = 141] = "NaNTokenType";
667
+ /**
668
+ * infinity token
669
+ */
670
+ EnumToken[EnumToken["InfinityTokenType"] = 142] = "InfinityTokenType";
671
+ /**
672
+ * negative infinity token
673
+ */
674
+ EnumToken[EnumToken["NegativeInfinityTokenType"] = 143] = "NegativeInfinityTokenType";
663
675
  /* aliases */
664
676
  /**
665
677
  * alias for time token type
@@ -1,8 +1,7 @@
1
1
  import { PropertySet } from './set.js';
2
2
  import { getConfig } from '../utils/config.js';
3
3
  import { PropertyMap } from './map.js';
4
- import { parseString } from '../parse.js';
5
- import { EnumToken, EnumAstNodeStatus } from '../../ast/types.js';
4
+ import { EnumAstNodeStatus, EnumToken } from '../../ast/types.js';
6
5
  import { getParsedSyntax } from '../../validation/config.js';
7
6
  import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
8
7
  import { matchAllSyntaxes, createValidationContext } from '../../validation/match.js';
@@ -14,18 +13,17 @@ const config = getConfig();
14
13
  class PropertyList {
15
14
  options = { removeDuplicateDeclarations: true, computeShorthand: true };
16
15
  declarations;
17
- // ketsey = new Map;
18
16
  constructor(options = {}) {
19
17
  this.options = options;
20
18
  this.declarations = new Map();
21
19
  }
22
- set(nam, value) {
23
- return this.add({
24
- typ: EnumToken.DeclarationNodeType,
25
- nam,
26
- val: Array.isArray(value) ? value : parseString(String(value)),
27
- });
28
- }
20
+ // set(nam: string, value: string | Token[]) {
21
+ // return this.add({
22
+ // typ: EnumToken.DeclarationNodeType,
23
+ // nam,
24
+ // val: Array.isArray(value) ? value : parseString(String(value)),
25
+ // });
26
+ // }
29
27
  add(...declarations) {
30
28
  let name;
31
29
  let syntaxRules = null;
@@ -434,7 +434,7 @@ function parseVisitors(visitorsDef, errors) {
434
434
  }
435
435
  /**
436
436
  * Parse css string
437
- * @param iter
437
+ * @param tokenizer
438
438
  * @param options
439
439
  *
440
440
  * @throws Error
@@ -1431,6 +1431,7 @@ async function doParse(iter, options = {}) {
1431
1431
  const imports = [];
1432
1432
  let item;
1433
1433
  let node;
1434
+ // @ts-ignore ignore error
1434
1435
  let parensMatch = 0;
1435
1436
  let curlyBracketMatch = 0;
1436
1437
  let tokenizer = iter instanceof Promise ? await iter : iter;
@@ -3429,14 +3430,6 @@ function parseDeclarations(declaration) {
3429
3430
  * ```
3430
3431
  */
3431
3432
  function parseString(src, options = { parseColor: true }, errors) {
3432
- // const parseInfo: ParseInfo = {
3433
- // stream: src,
3434
- // offset: 0,
3435
- // time: 0,
3436
- // source: new SourceFile(src, [], ""),
3437
- // position: 0,
3438
- // currentPosition: 0,
3439
- // };
3440
3433
  const tokenizer = new Tokenizer({
3441
3434
  stream: src,
3442
3435
  buffer: "",
@@ -5,9 +5,19 @@ import { SourceFile } from './source.js';
5
5
 
6
6
  const SymbolsMapTokens = Object.create(null);
7
7
  // Regex for escape sequence decoding - compile once, reuse many times
8
- const ESCAPE_SEQUENCE_REGEX = /\\([0-9a-fA-F]{1,6})(?:\s)?/g;
8
+ const ESCAPE_SEQUENCE_REGEX = /\\((\n|\r|\f|\v|\u2028|\u2029|([0-9a-fA-F]{1,6})) ?)/gms;
9
9
  function decodeEscapeSequences(value) {
10
10
  return value.replace(ESCAPE_SEQUENCE_REGEX, (_, sequence) => {
11
+ // \n \r \f \v
12
+ switch (sequence.charCodeAt(0)) {
13
+ case 0xa:
14
+ case 0xb:
15
+ case 0xc:
16
+ case 0xd:
17
+ case 0x2028:
18
+ case 0x2029:
19
+ return "";
20
+ }
11
21
  const codepoint = parseInt(sequence, 16);
12
22
  if (codepoint == 0 ||
13
23
  // leading surrogate
@@ -245,18 +255,17 @@ class Tokenizer {
245
255
  constructor(parseInfo, input = null) {
246
256
  this.parseInfo = parseInfo;
247
257
  this.input = input;
248
- if (typeof this.parseInfo == "string") {
249
- if (typeof parseInfo == "string") {
250
- this.parseInfo = {
258
+ this.parseInfo =
259
+ typeof parseInfo == "string"
260
+ ? {
251
261
  stream: parseInfo,
252
262
  source: new SourceFile(parseInfo, [], ""),
253
263
  offset: 0,
254
264
  time: 0,
255
265
  position: 0,
256
266
  currentPosition: 0,
257
- };
258
- }
259
- }
267
+ }
268
+ : parseInfo;
260
269
  }
261
270
  /**
262
271
  *
@@ -273,6 +282,18 @@ class Tokenizer {
273
282
  this.advance(parseInfo, 2);
274
283
  continue;
275
284
  }
285
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
286
+ // \n \r \f \v
287
+ if (charCode == 0xa ||
288
+ charCode == 0xb ||
289
+ charCode == 0xc ||
290
+ charCode == 0xd ||
291
+ charCode == 0x2028 ||
292
+ charCode == 0x2029) {
293
+ this.advance(parseInfo, 2);
294
+ decodeSegments = true;
295
+ continue;
296
+ }
276
297
  const sequence = this.peek(parseInfo, 7);
277
298
  let escapeSequence = "";
278
299
  let codepoint;
@@ -316,7 +337,7 @@ class Tokenizer {
316
337
  this.advance(parseInfo);
317
338
  }
318
339
  // EOF - 'Unclosed-string' fixed
319
- return this.makeToken(parseInfo, EnumToken.StringTokenType);
340
+ return this.makeToken(parseInfo, EnumToken.StringTokenType, decodeSegments ? { decodeSegments } : null);
320
341
  // return result;
321
342
  }
322
343
  /**
@@ -378,7 +399,7 @@ class Tokenizer {
378
399
  return this.makeToken(parseInfo, EnumToken.BadUrlTokenType);
379
400
  }
380
401
  if (isWhiteSpace(charCode)) {
381
- this.advance(parseInfo, k);
402
+ // this.advance(parseInfo, k);
382
403
  k++;
383
404
  continue;
384
405
  }
@@ -782,14 +803,28 @@ class Tokenizer {
782
803
  } while (
783
804
  // !(value === "/" && this.match(parseInfo, "/*") &&
784
805
  charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */ &&
806
+ !isWhiteSpace(charCode) &&
785
807
  parseInfo.currentPosition < endPosition);
786
- // if (parseInfo.position < parseInfo.currentPosition) {
808
+ if (charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */) {
809
+ let k = 1;
810
+ while (k < endPosition) {
811
+ charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + k);
812
+ if (isWhiteSpace(charCode)) {
813
+ k++;
814
+ continue;
815
+ }
816
+ break;
817
+ }
818
+ if (charCode != charCode || (charCode != 41 /* TokenMap.RIGHT_PARENTHESIS */ && !isIdentStart(charCode))) {
819
+ this.advance(parseInfo, k);
820
+ return this.makeToken(parseInfo, EnumToken.BadUrlTokenType);
821
+ }
822
+ }
787
823
  return this.makeToken(parseInfo,
788
824
  // parseInfo.position < parseInfo.currentPosition
789
825
  (charCode = this.peekCharCode(parseInfo)) != charCode || !this.isURLToken(parseInfo)
790
826
  ? EnumToken.BadUrlTokenType
791
827
  : EnumToken.UrlTokenTokenType);
792
- // }
793
828
  }
794
829
  /**
795
830
  *
@@ -1034,8 +1069,6 @@ class Tokenizer {
1034
1069
  /**
1035
1070
  *
1036
1071
  * @param parseInfo
1037
- * @param start
1038
- * @param end
1039
1072
  * @returns
1040
1073
  */
1041
1074
  isIdentToken(parseInfo /* , start?: number, end?: number */) {
@@ -1166,8 +1199,6 @@ class Tokenizer {
1166
1199
  }
1167
1200
  /**
1168
1201
  * Tokenize CSS string
1169
- * @param parseInfo
1170
- * @param yieldEOFToken
1171
1202
  */
1172
1203
  next( /* parseInfo: ParseInfo | string, yieldEOFToken: boolean = true */) {
1173
1204
  const parseInfo = this.parseInfo;
@@ -1308,7 +1339,7 @@ class Tokenizer {
1308
1339
  // ) {
1309
1340
  // this.advance(parseInfo);
1310
1341
  // return this.makeToken(parseInfo, EnumToken.PseudoClassFunctionTokenDefType);
1311
- // } else
1342
+ // } else
1312
1343
  if (this.isIdentToken(parseInfo)) {
1313
1344
  const hint = this.startsWith(parseInfo, "--")
1314
1345
  ? EnumToken.CustomFunctionTokenDefType
@@ -1553,6 +1584,9 @@ class Tokenizer {
1553
1584
  case 46 /* TokenMap.DOT */:
1554
1585
  const codepoint = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1);
1555
1586
  if (isIdentStart(codepoint) || codepoint == 45 /* TokenMap.MINUS */) {
1587
+ if (parseInfo.position < parseInfo.currentPosition) {
1588
+ return this.makeToken(parseInfo);
1589
+ }
1556
1590
  this.advance(parseInfo);
1557
1591
  let tokensCount = this.consumeIdentToken(parseInfo);
1558
1592
  if (tokensCount > 0) {
@@ -1584,8 +1618,6 @@ class Tokenizer {
1584
1618
  }
1585
1619
  /**
1586
1620
  * tokenize readable stream
1587
- * @param input
1588
- * @param parseInfo
1589
1621
  */
1590
1622
  async tokenizeStream() {
1591
1623
  const decoder = new TextDecoder("utf-8");
@@ -6,7 +6,7 @@ function parseAtRuleFontFeatureValues(stream, context, options = {}) {
6
6
  const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@" + context.nam);
7
7
  const syntax = syntaxRules?.getPreludeRules()?.slice?.(1);
8
8
  trimArray(stream);
9
- const { success, errors} = matchAllSyntaxes(syntax, createValidationContext(stream), options);
9
+ const { success, errors /* , ...all */ } = matchAllSyntaxes(syntax, createValidationContext(stream), options);
10
10
  return { success, errors };
11
11
  }
12
12