Skip to content

Commit 21ff83b

Browse files
authored
Merge pull request #91 from tbela99/v.next
css syntax update
2 parents f6700b6 + 00cff13 commit 21ff83b

File tree

14 files changed

+42
-113
lines changed

14 files changed

+42
-113
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## v1.1.1
44

5-
- [x] fix validation issues
5+
- [x] fix bug when css nesting is disabled #89
6+
- [x] validation rules update #87
67

78
## v1.1.0
89

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Javascript module from cdn
9696

9797
<script type="module">
9898
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';
100100
101101
102102
const css = `

dist/index-umd-web.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@
266266
const k = Math.pow(29, 3) / Math.pow(3, 3);
267267
const e = Math.pow(6, 3) / Math.pow(29, 3);
268268
// 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()));
270270
// deprecated
271271
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()));
272272
// name to color
@@ -13429,7 +13429,6 @@
1342913429
break;
1343013430
}
1343113431
ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
13432-
// console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
1343313432
if (ast != null) {
1343413433
let token = null;
1343513434
const values = node.val.slice();
@@ -13449,7 +13448,6 @@
1344913448
}
1345013449
}
1345113450
result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
13452-
// console.error(JSON.stringify({ast, values, result}, null, 1));
1345313451
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
1345413452
let token = null;
1345513453
while ((token = result.context.next()) != null) {
@@ -13508,7 +13506,6 @@
1350813506
let i = 0;
1350913507
let result;
1351013508
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), '')}`);
1351213509
for (; i < syntaxes.length; i++) {
1351313510
syntax = syntaxes[i];
1351413511
if (context.done()) {
@@ -13538,7 +13535,6 @@
1353813535
}
1353913536
else {
1354013537
if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
13541-
// console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
1354213538
return {
1354313539
valid: SyntaxValidationResult.Drop,
1354413540
node: token,
@@ -13686,7 +13682,6 @@
1368613682
};
1368713683
}
1368813684
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), '')}`);
1369013685
let success = false;
1369113686
let result;
1369213687
let token = context.peek();
@@ -13768,17 +13763,12 @@
1376813763
context
1376913764
};
1377013765
}
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;
1377513766
result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
1377613767
if (result.valid == SyntaxValidationResult.Valid) {
1377713768
context.next();
1377813769
result.context = context;
1377913770
return result;
1378013771
}
13781-
// }
1378213772
break;
1378313773
case ValidationTokenEnum.DeclarationType:
1378413774
return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -13938,7 +13928,7 @@
1393813928
valid: SyntaxValidationResult.Drop,
1393913929
node: token,
1394013930
syntax,
13941-
error: `expected <length>`,
13931+
error: `expected <length-percentage>`,
1394213932
context
1394313933
};
1394413934
}
@@ -14121,7 +14111,6 @@
1412114111
['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
1412214112
if (!success) {
1412314113
success = mathFuncs.includes(token.val.toLowerCase()) &&
14124-
// (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
1412514114
doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
1412614115
...options,
1412714116
isRepeatable: null,
@@ -21050,8 +21039,7 @@
2105021039
}
2105121040
let rule = selector.map(s => {
2105221041
if (s[0] == '&') {
21053-
// @ts-ignore
21054-
s[0] = node.optimized.optimized[0];
21042+
s.splice(0, 1, ...node.optimized.optimized);
2105521043
}
2105621044
return s.join('');
2105721045
}).join(',');

dist/index.cjs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
265265
const k = Math.pow(29, 3) / Math.pow(3, 3);
266266
const e = Math.pow(6, 3) / Math.pow(29, 3);
267267
// 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()));
269269
// deprecated
270270
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()));
271271
// name to color
@@ -13538,7 +13538,6 @@ function evaluateSyntax(node, options) {
1353813538
break;
1353913539
}
1354013540
ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
13541-
// console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
1354213541
if (ast != null) {
1354313542
let token = null;
1354413543
const values = node.val.slice();
@@ -13558,7 +13557,6 @@ function evaluateSyntax(node, options) {
1355813557
}
1355913558
}
1356013559
result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
13561-
// console.error(JSON.stringify({ast, values, result}, null, 1));
1356213560
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
1356313561
let token = null;
1356413562
while ((token = result.context.next()) != null) {
@@ -13617,7 +13615,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
1361713615
let i = 0;
1361813616
let result;
1361913617
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), '')}`);
1362113618
for (; i < syntaxes.length; i++) {
1362213619
syntax = syntaxes[i];
1362313620
if (context.done()) {
@@ -13647,7 +13644,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
1364713644
}
1364813645
else {
1364913646
if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
13650-
// console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
1365113647
return {
1365213648
valid: SyntaxValidationResult.Drop,
1365313649
node: token,
@@ -13795,7 +13791,6 @@ function matchOccurence(syntax, context, options) {
1379513791
};
1379613792
}
1379713793
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), '')}`);
1379913794
let success = false;
1380013795
let result;
1380113796
let token = context.peek();
@@ -13877,17 +13872,12 @@ function match(syntax, context, options) {
1387713872
context
1387813873
};
1387913874
}
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;
1388413875
result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
1388513876
if (result.valid == SyntaxValidationResult.Valid) {
1388613877
context.next();
1388713878
result.context = context;
1388813879
return result;
1388913880
}
13890-
// }
1389113881
break;
1389213882
case ValidationTokenEnum.DeclarationType:
1389313883
return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -14047,7 +14037,7 @@ function matchPropertyType(syntax, context, options) {
1404714037
valid: SyntaxValidationResult.Drop,
1404814038
node: token,
1404914039
syntax,
14050-
error: `expected <length>`,
14040+
error: `expected <length-percentage>`,
1405114041
context
1405214042
};
1405314043
}
@@ -14230,7 +14220,6 @@ function matchPropertyType(syntax, context, options) {
1423014220
['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
1423114221
if (!success) {
1423214222
success = mathFuncs.includes(token.val.toLowerCase()) &&
14233-
// (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
1423414223
doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
1423514224
...options,
1423614225
isRepeatable: null,
@@ -21159,8 +21148,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
2115921148
}
2116021149
let rule = selector.map(s => {
2116121150
if (s[0] == '&') {
21162-
// @ts-ignore
21163-
s[0] = node.optimized.optimized[0];
21151+
s.splice(0, 1, ...node.optimized.optimized);
2116421152
}
2116521153
return s.join('');
2116621154
}).join(',');

dist/lib/ast/minify.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
347347
}
348348
let rule = selector.map(s => {
349349
if (s[0] == '&') {
350-
// @ts-ignore
351-
s[0] = node.optimized.optimized[0];
350+
s.splice(0, 1, ...node.optimized.optimized);
352351
}
353352
return s.join('');
354353
}).join(',');

dist/lib/renderer/color/utils/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ const D50 = [0.3457 / 0.3585, 1.00000, (1.0 - 0.3457 - 0.3585) / 0.3585];
7777
const k = Math.pow(29, 3) / Math.pow(3, 3);
7878
const e = Math.pow(6, 3) / Math.pow(29, 3);
7979
// 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()));
8181
// deprecated
8282
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()));
8383
// name to color

dist/lib/validation/syntax.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ function evaluateSyntax(node, options) {
102102
break;
103103
}
104104
ast = getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, node.nam);
105-
// console.error({ast: ast.reduce((acc, curr) => acc + renderSyntax(curr), '')});
106105
if (ast != null) {
107106
let token = null;
108107
const values = node.val.slice();
@@ -122,7 +121,6 @@ function evaluateSyntax(node, options) {
122121
}
123122
}
124123
result = doEvaluateSyntax(ast, createContext(values), { ...options, visited: new WeakMap() });
125-
// console.error(JSON.stringify({ast, values, result}, null, 1));
126124
if (result.valid == SyntaxValidationResult.Valid && !result.context.done()) {
127125
let token = null;
128126
while ((token = result.context.next()) != null) {
@@ -181,7 +179,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
181179
let i = 0;
182180
let result;
183181
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), '')}`);
185182
for (; i < syntaxes.length; i++) {
186183
syntax = syntaxes[i];
187184
if (context.done()) {
@@ -211,7 +208,6 @@ function doEvaluateSyntax(syntaxes, context, options) {
211208
}
212209
else {
213210
if (isVisited(token, syntax, 'doEvaluateSyntax', options)) {
214-
// console.error(`cyclic dependency: ${renderSyntax(syntax)}`);
215211
return {
216212
valid: SyntaxValidationResult.Drop,
217213
node: token,
@@ -359,7 +355,6 @@ function matchOccurence(syntax, context, options) {
359355
};
360356
}
361357
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), '')}`);
363358
let success = false;
364359
let result;
365360
let token = context.peek();
@@ -441,17 +436,12 @@ function match(syntax, context, options) {
441436
context
442437
};
443438
}
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;
448439
result = match(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, syntax.val + '()')?.[0], context, options);
449440
if (result.valid == SyntaxValidationResult.Valid) {
450441
context.next();
451442
result.context = context;
452443
return result;
453444
}
454-
// }
455445
break;
456446
case ValidationTokenEnum.DeclarationType:
457447
return doEvaluateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, syntax.val), context, {
@@ -611,7 +601,7 @@ function matchPropertyType(syntax, context, options) {
611601
valid: SyntaxValidationResult.Drop,
612602
node: token,
613603
syntax,
614-
error: `expected <length>`,
604+
error: `expected <length-percentage>`,
615605
context
616606
};
617607
}
@@ -794,7 +784,6 @@ function matchPropertyType(syntax, context, options) {
794784
['length-percentage', 'length', 'number', 'number-token', 'angle', 'percentage', 'dimension'].includes(syntax.val)) {
795785
if (!success) {
796786
success = mathFuncs.includes(token.val.toLowerCase()) &&
797-
// (token as FunctionToken).val + '()' in config[ValidationSyntaxGroupEnum.Syntaxes] &&
798787
doEvaluateSyntax(getParsedSyntax("syntaxes" /* ValidationSyntaxGroupEnum.Syntaxes */, token.val + '()')?.[0]?.chi ?? [], createContext(token.chi), {
799788
...options,
800789
isRepeatable: null,

jsr.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tbela99/css-parser",
3-
"version": "1.1.1-alpha4",
3+
"version": "1.1.1",
44
"publish": {
55
"include": [
66
"src",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@tbela99/css-parser",
33
"description": "CSS parser for node and the browser",
4-
"version": "v1.1.1-alpha4",
4+
"version": "v1.1.1",
55
"exports": {
66
".": "./dist/node/index.js",
77
"./node": "./dist/node/index.js",

src/lib/ast/minify.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ function doMinify(ast: AstNode, options: ParserOptions = {}, recursive: boolean
487487
return acc;
488488

489489
}, []);
490-
490+
``
491491
if (!wrap) {
492492

493493
wrap = selector.some((s: string[]) => s[0] != '&');
@@ -497,8 +497,7 @@ function doMinify(ast: AstNode, options: ParserOptions = {}, recursive: boolean
497497

498498
if (s[0] == '&') {
499499

500-
// @ts-ignore
501-
s[0] = node.optimized.optimized[0];
500+
s.splice(0, 1, ...(node as AstRule)!.optimized!.optimized);
502501
}
503502

504503
return s.join('');

0 commit comments

Comments
 (0)