@tbela99/css-parser 1.1.1-alpha4 → 1.1.1

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.
package/CHANGELOG.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  ## v1.1.1
4
4
 
5
- - [x] fix validation issues
5
+ - [x] fix bug when css nesting is disabled #89
6
+ - [x] validation rules update #87
6
7
 
7
8
  ## v1.1.0
8
9
 
package/README.md CHANGED
@@ -96,7 +96,7 @@ Javascript module from cdn
96
96
 
97
97
  <script type="module">
98
98
 
99
- import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.0/web';
99
+ import {transform} from 'https://esm.sh/@tbela99/css-parser@1.1.1/web';
100
100
 
101
101
 
102
102
  const css = `
@@ -266,7 +266,7 @@
266
266
  const k = Math.pow(29, 3) / Math.pow(3, 3);
267
267
  const e = Math.pow(6, 3) / Math.pow(29, 3);
268
268
  // color module v4
269
- const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText'].map(m => m.toLowerCase()));
269
+ const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText', '-webkit-focus-ring-color'].map(m => m.toLowerCase()));
270
270
  // deprecated
271
271
  const deprecatedSystemColors = new Set(['ActiveBorder', 'ActiveCaption', 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', 'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText'].map(t => t.toLowerCase()));
272
272
  // name to color
@@ -13429,7 +13429,6 @@
13429
13429
  break;
13430
13430
  }
13431
13431
  ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
13432
- // console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
13433
13432
  if (ast != null) {
13434
13433
  let token = null;
13435
13434
  const values = node.val.slice();
@@ -13449,7 +13448,6 @@
13449
13448
  }
13450
13449
  }
13451
13450
  result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
13452
- // console.error(JSON.stringify({ast, values, result}, null, 1));
13453
13451
  if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
13454
13452
  let token = null;
13455
13453
  while ((token = result.context.next()) != null) {
@@ -13508,7 +13506,6 @@
13508
13506
  let i = 0;
13509
13507
  let result;
13510
13508
  let token = null;
13511
- // console.error(`>> doEvaluateSyntax: ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${JSON.stringify({syntaxes}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
13512
13509
  for (; i < syntaxes.length; i++) {
13513
13510
  syntax = syntaxes[i];
13514
13511
  if (context.done()) {
@@ -13538,7 +13535,6 @@
13538
13535
  }
13539
13536
  else {
13540
13537
  if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
13541
- // console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
13542
13538
  return {
13543
13539
  valid: SyntaxValidationResult.Drop,
13544
13540
  node: token,
@@ -13686,7 +13682,6 @@
13686
13682
  };
13687
13683
  }
13688
13684
  function match(syntax, context, options) {
13689
- // console.error(`>> match(): ${renderSyntax(syntax)}\n>> ${JSON.stringify({syntax}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
13690
13685
  let success = false;
13691
13686
  let result;
13692
13687
  let token = context.peek();
@@ -13768,17 +13763,12 @@
13768
13763
  context
13769
13764
  };
13770
13765
  }
13771
- // {
13772
- // console.error(JSON.stringify({funcDef: (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken).chi}, null, 1))
13773
- //
13774
- // const child = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken;
13775
13766
  result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
13776
13767
  if (result.valid == SyntaxValidationResult.Valid) {
13777
13768
  context.next();
13778
13769
  result.context = context;
13779
13770
  return result;
13780
13771
  }
13781
- // }
13782
13772
  break;
13783
13773
  case ValidationTokenEnum.DeclarationType:
13784
13774
  return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -13938,7 +13928,7 @@
13938
13928
  valid: SyntaxValidationResult.Drop,
13939
13929
  node: token,
13940
13930
  syntax,
13941
- error: `expected <length>`,
13931
+ error: `expected <length-percentage>`,
13942
13932
  context
13943
13933
  };
13944
13934
  }
@@ -14121,7 +14111,6 @@
14121
14111
  ['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
14122
14112
  if (!success) {
14123
14113
  success = mathFuncs.includes(token.val.toLowerCase()) &&
14124
- // (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
14125
14114
  doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
14126
14115
  ...options,
14127
14116
  isRepeatable: null,
@@ -21050,8 +21039,7 @@
21050
21039
  }
21051
21040
  let rule = selector.map(s => {
21052
21041
  if (s[0] == '&') {
21053
- // @ts-ignore
21054
- s[0] = node.optimized.optimized[0];
21042
+ s.splice(0, 1, ...node.optimized.optimized);
21055
21043
  }
21056
21044
  return s.join('');
21057
21045
  }).join(',');
package/dist/index.cjs CHANGED
@@ -265,7 +265,7 @@ const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
265
265
  const k = Math.pow(29, 3) / Math.pow(3, 3);
266
266
  const e = Math.pow(6, 3) / Math.pow(29, 3);
267
267
  // color module v4
268
- const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText'].map(m => m.toLowerCase()));
268
+ const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText', '-webkit-focus-ring-color'].map(m => m.toLowerCase()));
269
269
  // deprecated
270
270
  const deprecatedSystemColors = new Set(['ActiveBorder', 'ActiveCaption', 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', 'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText'].map(t => t.toLowerCase()));
271
271
  // name to color
@@ -13538,7 +13538,6 @@ function evaluateSyntax(node, options) {
13538
13538
  break;
13539
13539
  }
13540
13540
  ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
13541
- // console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
13542
13541
  if (ast != null) {
13543
13542
  let token = null;
13544
13543
  const values = node.val.slice();
@@ -13558,7 +13557,6 @@ function evaluateSyntax(node, options) {
13558
13557
  }
13559
13558
  }
13560
13559
  result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
13561
- // console.error(JSON.stringify({ast, values, result}, null, 1));
13562
13560
  if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
13563
13561
  let token = null;
13564
13562
  while ((token = result.context.next()) != null) {
@@ -13617,7 +13615,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
13617
13615
  let i = 0;
13618
13616
  let result;
13619
13617
  let token = null;
13620
- // console.error(`>> doEvaluateSyntax: ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${JSON.stringify({syntaxes}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
13621
13618
  for (; i < syntaxes.length; i++) {
13622
13619
  syntax = syntaxes[i];
13623
13620
  if (context.done()) {
@@ -13647,7 +13644,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
13647
13644
  }
13648
13645
  else {
13649
13646
  if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
13650
- // console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
13651
13647
  return {
13652
13648
  valid: SyntaxValidationResult.Drop,
13653
13649
  node: token,
@@ -13795,7 +13791,6 @@ function matchOccurence(syntax, context, options) {
13795
13791
  };
13796
13792
  }
13797
13793
  function match(syntax, context, options) {
13798
- // console.error(`>> match(): ${renderSyntax(syntax)}\n>> ${JSON.stringify({syntax}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
13799
13794
  let success = false;
13800
13795
  let result;
13801
13796
  let token = context.peek();
@@ -13877,17 +13872,12 @@ function match(syntax, context, options) {
13877
13872
  context
13878
13873
  };
13879
13874
  }
13880
- // {
13881
- // console.error(JSON.stringify({funcDef: (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken).chi}, null, 1))
13882
- //
13883
- // const child = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken;
13884
13875
  result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
13885
13876
  if (result.valid == SyntaxValidationResult.Valid) {
13886
13877
  context.next();
13887
13878
  result.context = context;
13888
13879
  return result;
13889
13880
  }
13890
- // }
13891
13881
  break;
13892
13882
  case ValidationTokenEnum.DeclarationType:
13893
13883
  return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -14047,7 +14037,7 @@ function matchPropertyType(syntax, context, options) {
14047
14037
  valid: SyntaxValidationResult.Drop,
14048
14038
  node: token,
14049
14039
  syntax,
14050
- error: `expected <length>`,
14040
+ error: `expected <length-percentage>`,
14051
14041
  context
14052
14042
  };
14053
14043
  }
@@ -14230,7 +14220,6 @@ function matchPropertyType(syntax, context, options) {
14230
14220
  ['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
14231
14221
  if (!success) {
14232
14222
  success = mathFuncs.includes(token.val.toLowerCase()) &&
14233
- // (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
14234
14223
  doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
14235
14224
  ...options,
14236
14225
  isRepeatable: null,
@@ -21159,8 +21148,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
21159
21148
  }
21160
21149
  let rule = selector.map(s => {
21161
21150
  if (s[0] == '&') {
21162
- // @ts-ignore
21163
- s[0] = node.optimized.optimized[0];
21151
+ s.splice(0, 1, ...node.optimized.optimized);
21164
21152
  }
21165
21153
  return s.join('');
21166
21154
  }).join(',');
@@ -347,8 +347,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
347
347
  }
348
348
  let rule = selector.map(s => {
349
349
  if (s[0] == '&') {
350
- // @ts-ignore
351
- s[0] = node.optimized.optimized[0];
350
+ s.splice(0, 1, ...node.optimized.optimized);
352
351
  }
353
352
  return s.join('');
354
353
  }).join(',');
@@ -77,7 +77,7 @@ const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
77
77
  const k = Math.pow(29, 3) / Math.pow(3, 3);
78
78
  const e = Math.pow(6, 3) / Math.pow(29, 3);
79
79
  // color module v4
80
- const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText'].map(m => m.toLowerCase()));
80
+ const systemColors = new Set(['ActiveText', 'ButtonBorder', 'ButtonFace', 'ButtonText', 'Canvas', 'CanvasText', 'Field', 'FieldText', 'GrayText', 'Highlight', 'HighlightText', 'LinkText', 'Mark', 'MarkText', 'VisitedText', '-webkit-focus-ring-color'].map(m => m.toLowerCase()));
81
81
  // deprecated
82
82
  const deprecatedSystemColors = new Set(['ActiveBorder', 'ActiveCaption', 'AppWorkspace', 'Background', 'ButtonFace', 'ButtonHighlight', 'ButtonShadow', 'ButtonText', 'CaptionText', 'GrayText', 'Highlight', 'HighlightText', 'InactiveBorder', 'InactiveCaption', 'InactiveCaptionText', 'InfoBackground', 'InfoText', 'Menu', 'MenuText', 'Scrollbar', 'ThreeDDarkShadow', 'ThreeDFace', 'ThreeDHighlight', 'ThreeDLightShadow', 'ThreeDShadow', 'Window', 'WindowFrame', 'WindowText'].map(t => t.toLowerCase()));
83
83
  // name to color
@@ -102,7 +102,6 @@ function evaluateSyntax(node, options) {
102
102
  break;
103
103
  }
104
104
  ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
105
- // console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
106
105
  if (ast != null) {
107
106
  let token = null;
108
107
  const values = node.val.slice();
@@ -122,7 +121,6 @@ function evaluateSyntax(node, options) {
122
121
  }
123
122
  }
124
123
  result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
125
- // console.error(JSON.stringify({ast, values, result}, null, 1));
126
124
  if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
127
125
  let token = null;
128
126
  while ((token = result.context.next()) != null) {
@@ -181,7 +179,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
181
179
  let i = 0;
182
180
  let result;
183
181
  let token = null;
184
- // console.error(`>> doEvaluateSyntax: ${syntaxes.reduce((acc, curr) => acc + renderSyntax(curr), '')}\n>> ${JSON.stringify({syntaxes}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
185
182
  for (; i < syntaxes.length; i++) {
186
183
  syntax = syntaxes[i];
187
184
  if (context.done()) {
@@ -211,7 +208,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
211
208
  }
212
209
  else {
213
210
  if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
214
- // console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
215
211
  return {
216
212
  valid: SyntaxValidationResult.Drop,
217
213
  node: token,
@@ -359,7 +355,6 @@ function matchOccurence(syntax, context, options) {
359
355
  };
360
356
  }
361
357
  function match(syntax, context, options) {
362
- // console.error(`>> match(): ${renderSyntax(syntax)}\n>> ${JSON.stringify({syntax}, null, 1)}>> context: ${context.slice<Token>().reduce((acc, curr) => acc + renderToken(curr), '')}`);
363
358
  let success = false;
364
359
  let result;
365
360
  let token = context.peek();
@@ -441,17 +436,12 @@ function match(syntax, context, options) {
441
436
  context
442
437
  };
443
438
  }
444
- // {
445
- // console.error(JSON.stringify({funcDef: (getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken).chi}, null, 1))
446
- //
447
- // const child = getParsedSyntax(ValidationSyntaxGroupEnum.Syntaxes, (syntax as ValidationFunctionDefinitionToken).val + '()')?.[0] as ValidationFunctionToken;
448
439
  result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
449
440
  if (result.valid == SyntaxValidationResult.Valid) {
450
441
  context.next();
451
442
  result.context = context;
452
443
  return result;
453
444
  }
454
- // }
455
445
  break;
456
446
  case ValidationTokenEnum.DeclarationType:
457
447
  return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -611,7 +601,7 @@ function matchPropertyType(syntax, context, options) {
611
601
  valid: SyntaxValidationResult.Drop,
612
602
  node: token,
613
603
  syntax,
614
- error: `expected <length>`,
604
+ error: `expected <length-percentage>`,
615
605
  context
616
606
  };
617
607
  }
@@ -794,7 +784,6 @@ function matchPropertyType(syntax, context, options) {
794
784
  ['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
795
785
  if (!success) {
796
786
  success = mathFuncs.includes(token.val.toLowerCase()) &&
797
- // (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
798
787
  doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
799
788
  ...options,
800
789
  isRepeatable: null,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbela99/css-parser",
3
3
  "description": "CSS parser for node and the browser",
4
- "version": "v1.1.1-alpha4",
4
+ "version": "v1.1.1",
5
5
  "exports": {
6
6
  ".": "./dist/node/index.js",
7
7
  "./node": "./dist/node/index.js",