@tbela99/css-parser 0.9.0 → 0.9.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/README.md +8 -5
- package/dist/index-umd-web.js +469 -1946
- package/dist/index.cjs +459 -1936
- package/dist/index.d.ts +25 -12
- package/dist/lib/ast/expand.js +15 -2
- package/dist/lib/ast/minify.js +1 -1
- package/dist/lib/ast/types.js +1 -0
- package/dist/lib/parser/parse.js +66 -40
- package/dist/lib/renderer/color/color.js +2 -2
- package/dist/lib/renderer/color/lab.js +2 -1
- package/dist/lib/renderer/color/prophotoRgb.js +2 -2
- package/dist/lib/renderer/color/prophotorgb.js +2 -2
- package/dist/lib/renderer/color/xyz.js +2 -18
- package/dist/lib/renderer/color/xyzd50.js +20 -2
- package/dist/lib/renderer/render.js +3 -2
- package/dist/lib/renderer/sourcemap/sourcemap.js +1 -1
- package/dist/lib/syntax/syntax.js +2 -1
- package/dist/lib/validation/at-rules/document.js +40 -60
- package/dist/lib/validation/at-rules/import.js +61 -59
- package/dist/lib/validation/at-rules/media.js +2 -1
- package/dist/lib/validation/at-rules/supports.js +40 -9
- package/dist/lib/validation/config.json.js +83 -35
- package/dist/lib/validation/declaration.js +2 -10
- package/dist/lib/validation/parser/parse.js +1 -95
- package/dist/lib/validation/parser/types.js +1 -2
- package/dist/lib/validation/syntax.js +39 -5
- package/dist/lib/validation/syntaxes/compound-selector.js +2 -2
- package/dist/lib/validation/syntaxes/layer-name.js +5 -16
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -91,6 +91,7 @@ declare enum EnumToken {
|
|
|
91
91
|
MediaFeatureAndTokenType = 89,
|
|
92
92
|
MediaFeatureOrTokenType = 90,
|
|
93
93
|
PseudoPageTokenType = 91,
|
|
94
|
+
PseudoElementTokenType = 92,
|
|
94
95
|
Time = 25,
|
|
95
96
|
Iden = 7,
|
|
96
97
|
EOF = 48,
|
|
@@ -129,7 +130,7 @@ declare enum EnumToken {
|
|
|
129
130
|
* @param nestingContent
|
|
130
131
|
* @param context
|
|
131
132
|
*/
|
|
132
|
-
declare function minify(ast: AstNode, options?: ParserOptions |
|
|
133
|
+
declare function minify(ast: AstNode, options?: ParserOptions | MinifyFeatureOptions, recursive?: boolean, errors?: ErrorDescription[], nestingContent?: boolean, context?: {
|
|
133
134
|
[key: string]: any;
|
|
134
135
|
}): AstNode;
|
|
135
136
|
|
|
@@ -517,6 +518,12 @@ export declare interface PseudoClassToken extends BaseToken {
|
|
|
517
518
|
val: string;
|
|
518
519
|
}
|
|
519
520
|
|
|
521
|
+
export declare interface PseudoElementToken extends BaseToken {
|
|
522
|
+
|
|
523
|
+
typ: EnumToken.PseudoElementTokenType;
|
|
524
|
+
val: string;
|
|
525
|
+
}
|
|
526
|
+
|
|
520
527
|
export declare interface PseudoPageToken extends BaseToken {
|
|
521
528
|
|
|
522
529
|
typ: EnumToken.PseudoPageTokenType;
|
|
@@ -812,6 +819,7 @@ export declare type Token =
|
|
|
812
819
|
ListToken
|
|
813
820
|
| PseudoClassToken
|
|
814
821
|
| PseudoPageToken
|
|
822
|
+
| PseudoElementToken
|
|
815
823
|
| PseudoClassFunctionToken
|
|
816
824
|
| DelimToken
|
|
817
825
|
| BinaryExpressionToken
|
|
@@ -1035,24 +1043,29 @@ interface ValidationOptions {
|
|
|
1035
1043
|
lenient?: boolean;
|
|
1036
1044
|
}
|
|
1037
1045
|
|
|
1038
|
-
|
|
1046
|
+
interface MinifyOptions {
|
|
1039
1047
|
|
|
1040
1048
|
minify?: boolean;
|
|
1041
|
-
src?: string;
|
|
1042
|
-
sourcemap?: boolean;
|
|
1043
1049
|
nestingRules?: boolean;
|
|
1044
1050
|
expandNestingRules?: boolean;
|
|
1045
|
-
|
|
1051
|
+
removeDuplicateDeclarations?: boolean;
|
|
1052
|
+
computeShorthand?: boolean;
|
|
1053
|
+
computeCalcExpression?: boolean;
|
|
1054
|
+
inlineCssVariables?: boolean;
|
|
1046
1055
|
removeEmpty?: boolean;
|
|
1056
|
+
pass?: number;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
export declare interface ParserOptions extends MinifyOptions, ValidationOptions, PropertyListOptions {
|
|
1060
|
+
|
|
1061
|
+
src?: string;
|
|
1062
|
+
sourcemap?: boolean;
|
|
1063
|
+
removeCharset?: boolean;
|
|
1047
1064
|
resolveUrls?: boolean;
|
|
1048
1065
|
resolveImport?: boolean;
|
|
1049
1066
|
cwd?: string;
|
|
1050
1067
|
parseColor?: boolean;
|
|
1051
|
-
removeDuplicateDeclarations?: boolean;
|
|
1052
|
-
computeShorthand?: boolean;
|
|
1053
1068
|
removePrefix?: boolean;
|
|
1054
|
-
inlineCssVariables?: boolean;
|
|
1055
|
-
computeCalcExpression?: boolean;
|
|
1056
1069
|
load?: (url: string, currentUrl: string) => Promise<string>;
|
|
1057
1070
|
dirname?: (path: string) => string;
|
|
1058
1071
|
resolve?: (url: string, currentUrl: string, currentWorkingDirectory?: string) => {
|
|
@@ -1064,7 +1077,7 @@ export declare interface ParserOptions extends ValidationOptions, PropertyListOp
|
|
|
1064
1077
|
setParent?: boolean;
|
|
1065
1078
|
}
|
|
1066
1079
|
|
|
1067
|
-
export declare interface
|
|
1080
|
+
export declare interface MinifyFeatureOptions extends ParserOptions {
|
|
1068
1081
|
|
|
1069
1082
|
features: MinifyFeature[];
|
|
1070
1083
|
}
|
|
@@ -1073,7 +1086,7 @@ export declare interface MinifyFeature {
|
|
|
1073
1086
|
|
|
1074
1087
|
ordering: number;
|
|
1075
1088
|
|
|
1076
|
-
register(options:
|
|
1089
|
+
register(options: MinifyFeatureOptions | ParserOptions): void;
|
|
1077
1090
|
|
|
1078
1091
|
// run(ast: AstRule | AstAtRule, options: ParserOptions = {}, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: { [key: string]: any }): void;
|
|
1079
1092
|
|
|
@@ -1083,7 +1096,7 @@ export declare interface MinifyFeature {
|
|
|
1083
1096
|
export declare interface MinifyFeature {
|
|
1084
1097
|
|
|
1085
1098
|
ordering: number;
|
|
1086
|
-
register: (options:
|
|
1099
|
+
register: (options: MinifyFeatureOptions | ParserOptions) => void;
|
|
1087
1100
|
run: (ast: AstRule | AstAtRule, options: ParserOptions, parent: AstRule | AstAtRule | AstRuleStyleSheet, context: {
|
|
1088
1101
|
[key: string]: any
|
|
1089
1102
|
}) => void;
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -69,7 +69,14 @@ function expandRule(node) {
|
|
|
69
69
|
rule.sel = splitRule(ast.sel).reduce((a, b) => a.concat([b.join('') + r]), []).join(',');
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
selRule.
|
|
72
|
+
// selRule = splitRule(selRule.reduce((acc, curr) => acc + (acc.length > 0 ? ',' : '') + curr.join(''), ''));
|
|
73
|
+
const arSelf = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::'))).reduce((acc, curr) => acc.concat([curr.join('')]), []).join(',');
|
|
74
|
+
if (arSelf.length == 0) {
|
|
75
|
+
ast.chi.splice(i--, 1);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
//
|
|
79
|
+
selRule.forEach(arr => combinators.includes(arr[0].charAt(0)) ? arr.unshift(arSelf) : arr.unshift(arSelf, ' '));
|
|
73
80
|
rule.sel = selRule.reduce((acc, curr) => {
|
|
74
81
|
acc.push(curr.join(''));
|
|
75
82
|
return acc;
|
|
@@ -80,8 +87,14 @@ function expandRule(node) {
|
|
|
80
87
|
let childSelectorCompound = [];
|
|
81
88
|
let withCompound = [];
|
|
82
89
|
let withoutCompound = [];
|
|
83
|
-
|
|
90
|
+
// pseudo elements cannot be used with '&'
|
|
91
|
+
// https://www.w3.org/TR/css-nesting-1/#example-7145ff1e
|
|
92
|
+
const rules = splitRule(ast.sel).filter((r) => r.every((t) => t != ':before' && t != ':after' && !t.startsWith('::')));
|
|
84
93
|
const parentSelector = !node.sel.includes('&');
|
|
94
|
+
if (rules.length == 0) {
|
|
95
|
+
ast.chi.splice(i--, 1);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
85
98
|
for (const sel of (rule.raw ?? splitRule(rule.sel))) {
|
|
86
99
|
const s = sel.join('');
|
|
87
100
|
if (s.includes('&') || parentSelector) {
|
package/dist/lib/ast/minify.js
CHANGED
|
@@ -227,7 +227,7 @@ function minify(ast, options = {}, recursive = false, errors, nestingContent, co
|
|
|
227
227
|
return s.join('');
|
|
228
228
|
}).join(',');
|
|
229
229
|
// @ts-ignore
|
|
230
|
-
let sel = wrap ? node.optimized.optimized
|
|
230
|
+
let sel = wrap ? node.optimized.optimized.join('') + `:is(${rule})` : rule;
|
|
231
231
|
if (rule.includes('&')) {
|
|
232
232
|
// @ts-ignore
|
|
233
233
|
rule = replaceCompound(rule, node.optimized.optimized[0]);
|
package/dist/lib/ast/types.js
CHANGED
|
@@ -101,6 +101,7 @@ var EnumToken;
|
|
|
101
101
|
EnumToken[EnumToken["MediaFeatureAndTokenType"] = 89] = "MediaFeatureAndTokenType";
|
|
102
102
|
EnumToken[EnumToken["MediaFeatureOrTokenType"] = 90] = "MediaFeatureOrTokenType";
|
|
103
103
|
EnumToken[EnumToken["PseudoPageTokenType"] = 91] = "PseudoPageTokenType";
|
|
104
|
+
EnumToken[EnumToken["PseudoElementTokenType"] = 92] = "PseudoElementTokenType";
|
|
104
105
|
/* aliases */
|
|
105
106
|
EnumToken[EnumToken["Time"] = 25] = "Time";
|
|
106
107
|
EnumToken[EnumToken["Iden"] = 7] = "Iden";
|
package/dist/lib/parser/parse.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { webkitPseudoAliasMap, isIdentStart, isIdent, mathFuncs, isColor, isHexColor, isPseudo, isAtKeyword, isFunction, isNumber, isPercentage, isFlex, isDimension, parseDimension, isHash, mediaTypes } from '../syntax/syntax.js';
|
|
1
|
+
import { webkitPseudoAliasMap, isIdentStart, isIdent, mathFuncs, isColor, isHexColor, isPseudo, pseudoElements, isAtKeyword, isFunction, isNumber, isPercentage, isFlex, isDimension, parseDimension, isHash, mediaTypes } from '../syntax/syntax.js';
|
|
2
2
|
import './utils/config.js';
|
|
3
3
|
import { EnumToken, funcLike, ValidationLevel } from '../ast/types.js';
|
|
4
4
|
import { minify, definedPropertySettings, combinators } from '../ast/minify.js';
|
|
@@ -46,6 +46,7 @@ async function doParse(iterator, options = {}) {
|
|
|
46
46
|
src: '',
|
|
47
47
|
sourcemap: false,
|
|
48
48
|
minify: true,
|
|
49
|
+
pass: 1,
|
|
49
50
|
parseColor: true,
|
|
50
51
|
nestingRules: false,
|
|
51
52
|
resolveImport: false,
|
|
@@ -165,7 +166,7 @@ async function doParse(iterator, options = {}) {
|
|
|
165
166
|
await parseNode(tokens, context, stats, options, errors, src, map, rawTokens);
|
|
166
167
|
rawTokens.length = 0;
|
|
167
168
|
if (context != null && context.typ == EnumToken.InvalidRuleTokenType) {
|
|
168
|
-
const index = context.chi.findIndex(node => node == context);
|
|
169
|
+
const index = context.chi.findIndex((node) => node == context);
|
|
169
170
|
if (index > -1) {
|
|
170
171
|
context.chi.splice(index, 1);
|
|
171
172
|
}
|
|
@@ -225,7 +226,10 @@ async function doParse(iterator, options = {}) {
|
|
|
225
226
|
}
|
|
226
227
|
if (options.minify) {
|
|
227
228
|
if (ast.chi.length > 0) {
|
|
228
|
-
|
|
229
|
+
let passes = options.pass ?? 1;
|
|
230
|
+
while (passes--) {
|
|
231
|
+
minify(ast, options, true, errors, false);
|
|
232
|
+
}
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
const endTime = performance.now();
|
|
@@ -326,8 +330,13 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
326
330
|
continue;
|
|
327
331
|
}
|
|
328
332
|
if (type != EnumToken.AtRuleNodeType) {
|
|
329
|
-
|
|
330
|
-
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
if (!(type == EnumToken.InvalidAtRuleTokenType &&
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
['charset', 'layer', 'import'].includes(context.chi[i].nam))) {
|
|
337
|
+
errors.push({ action: 'drop', message: 'invalid @import', location: { src, ...position } });
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
331
340
|
}
|
|
332
341
|
// @ts-ignore
|
|
333
342
|
const name = context.chi[i].nam;
|
|
@@ -362,12 +371,20 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
362
371
|
if (tokens[0].typ == EnumToken.UrlFunctionTokenType) {
|
|
363
372
|
if (tokens[1].typ == EnumToken.UrlTokenTokenType || tokens[1].typ == EnumToken.StringTokenType) {
|
|
364
373
|
tokens.shift();
|
|
365
|
-
if (tokens[
|
|
374
|
+
if (tokens[0]?.typ == EnumToken.UrlTokenTokenType) {
|
|
366
375
|
// @ts-ignore
|
|
367
376
|
tokens[0].typ = EnumToken.StringTokenType;
|
|
368
377
|
// @ts-ignore
|
|
369
378
|
tokens[0].val = `"${tokens[0].val}"`;
|
|
370
379
|
}
|
|
380
|
+
// @ts-ignore
|
|
381
|
+
while (tokens[1]?.typ == EnumToken.WhitespaceTokenType || tokens[1]?.typ == EnumToken.CommentTokenType) {
|
|
382
|
+
tokens.splice(1, 1);
|
|
383
|
+
}
|
|
384
|
+
// @ts-ignore
|
|
385
|
+
if (tokens[1]?.typ == EnumToken.EndParensTokenType) {
|
|
386
|
+
tokens.splice(1, 1);
|
|
387
|
+
}
|
|
371
388
|
}
|
|
372
389
|
}
|
|
373
390
|
// @ts-ignore
|
|
@@ -451,11 +468,11 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
451
468
|
const node = {
|
|
452
469
|
typ: EnumToken.AtRuleNodeType,
|
|
453
470
|
nam: renderToken(atRule, { removeComments: true }),
|
|
454
|
-
tokens: t,
|
|
471
|
+
// tokens: t,
|
|
455
472
|
val: raw.join('')
|
|
456
473
|
};
|
|
457
474
|
Object.defineProperties(node, {
|
|
458
|
-
tokens: { ...definedPropertySettings, enumerable:
|
|
475
|
+
tokens: { ...definedPropertySettings, enumerable: false, value: tokens.slice() },
|
|
459
476
|
raw: { ...definedPropertySettings, value: raw }
|
|
460
477
|
});
|
|
461
478
|
if (delim.typ == EnumToken.BlockStartTokenType) {
|
|
@@ -580,7 +597,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
580
597
|
};
|
|
581
598
|
Object.defineProperty(node, 'tokens', {
|
|
582
599
|
...definedPropertySettings,
|
|
583
|
-
enumerable:
|
|
600
|
+
enumerable: false,
|
|
584
601
|
value: tokens.slice()
|
|
585
602
|
});
|
|
586
603
|
let raw = [...uniq.values()];
|
|
@@ -681,7 +698,7 @@ async function parseNode(results, context, stats, options, errors, src, map, raw
|
|
|
681
698
|
//
|
|
682
699
|
// const valid: ValidationResult = validateDeclaration(result, options, context);
|
|
683
700
|
//
|
|
684
|
-
// console.error({valid});
|
|
701
|
+
// // console.error({valid});
|
|
685
702
|
//
|
|
686
703
|
// if (valid.valid == ValidationLevel.Drop) {
|
|
687
704
|
//
|
|
@@ -1053,10 +1070,16 @@ function getTokenType(val, hint) {
|
|
|
1053
1070
|
val: val.slice(0, -1),
|
|
1054
1071
|
chi: []
|
|
1055
1072
|
}
|
|
1056
|
-
:
|
|
1057
|
-
|
|
1073
|
+
: (
|
|
1074
|
+
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
1075
|
+
val.startsWith('::') || pseudoElements.includes(val) ? {
|
|
1076
|
+
typ: EnumToken.PseudoElementTokenType,
|
|
1058
1077
|
val
|
|
1059
|
-
}
|
|
1078
|
+
} :
|
|
1079
|
+
{
|
|
1080
|
+
typ: EnumToken.PseudoClassTokenType,
|
|
1081
|
+
val
|
|
1082
|
+
});
|
|
1060
1083
|
}
|
|
1061
1084
|
if (isAtKeyword(val)) {
|
|
1062
1085
|
return {
|
|
@@ -1233,25 +1256,25 @@ function parseTokens(tokens, options = {}) {
|
|
|
1233
1256
|
break;
|
|
1234
1257
|
}
|
|
1235
1258
|
}
|
|
1236
|
-
Object.assign(t, {
|
|
1259
|
+
const attr = Object.assign(t, {
|
|
1237
1260
|
typ: inAttr == 0 ? EnumToken.AttrTokenType : EnumToken.InvalidAttrTokenType,
|
|
1238
1261
|
chi: tokens.splice(i + 1, k - i)
|
|
1239
1262
|
});
|
|
1240
1263
|
// @ts-ignore
|
|
1241
|
-
if (
|
|
1264
|
+
if (attr.chi.at(-1).typ == EnumToken.AttrEndTokenType) {
|
|
1242
1265
|
// @ts-ignore
|
|
1243
|
-
|
|
1266
|
+
attr.chi.pop();
|
|
1244
1267
|
}
|
|
1245
1268
|
// @ts-ignore
|
|
1246
|
-
if (
|
|
1269
|
+
if (attr.chi.length > 1) {
|
|
1247
1270
|
/*(<AttrToken>t).chi =*/
|
|
1248
1271
|
// @ts-ignore
|
|
1249
|
-
parseTokens(
|
|
1272
|
+
parseTokens(attr.chi, t.typ);
|
|
1250
1273
|
}
|
|
1251
|
-
let m =
|
|
1274
|
+
let m = attr.chi.length;
|
|
1252
1275
|
let val;
|
|
1253
|
-
for (m = 0; m <
|
|
1254
|
-
val =
|
|
1276
|
+
for (m = 0; m < attr.chi.length; m++) {
|
|
1277
|
+
val = attr.chi[m];
|
|
1255
1278
|
if (val.typ == EnumToken.StringTokenType) {
|
|
1256
1279
|
const slice = val.val.slice(1, -1);
|
|
1257
1280
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
@@ -1261,55 +1284,55 @@ function parseTokens(tokens, options = {}) {
|
|
|
1261
1284
|
else if (val.typ == EnumToken.LiteralTokenType && val.val == '|') {
|
|
1262
1285
|
let upper = m;
|
|
1263
1286
|
let lower = m;
|
|
1264
|
-
while (++upper <
|
|
1265
|
-
if (
|
|
1287
|
+
while (++upper < attr.chi.length) {
|
|
1288
|
+
if (attr.chi[upper].typ == EnumToken.CommentTokenType) {
|
|
1266
1289
|
continue;
|
|
1267
1290
|
}
|
|
1268
1291
|
break;
|
|
1269
1292
|
}
|
|
1270
1293
|
while (lower-- > 0) {
|
|
1271
|
-
if (
|
|
1294
|
+
if (attr.chi[lower].typ == EnumToken.CommentTokenType) {
|
|
1272
1295
|
continue;
|
|
1273
1296
|
}
|
|
1274
1297
|
break;
|
|
1275
1298
|
}
|
|
1276
1299
|
// @ts-ignore
|
|
1277
|
-
|
|
1300
|
+
attr.chi[m] = {
|
|
1278
1301
|
typ: EnumToken.NameSpaceAttributeTokenType,
|
|
1279
|
-
l:
|
|
1280
|
-
r:
|
|
1302
|
+
l: attr.chi[lower],
|
|
1303
|
+
r: attr.chi[upper]
|
|
1281
1304
|
};
|
|
1282
|
-
|
|
1305
|
+
attr.chi.splice(upper, 1);
|
|
1283
1306
|
if (lower >= 0) {
|
|
1284
|
-
|
|
1307
|
+
attr.chi.splice(lower, 1);
|
|
1285
1308
|
m--;
|
|
1286
1309
|
}
|
|
1287
1310
|
}
|
|
1288
1311
|
else if ([
|
|
1289
1312
|
EnumToken.DashMatchTokenType, EnumToken.StartMatchTokenType, EnumToken.ContainMatchTokenType, EnumToken.EndMatchTokenType, EnumToken.IncludeMatchTokenType, EnumToken.DelimTokenType
|
|
1290
|
-
].includes(
|
|
1313
|
+
].includes(attr.chi[m].typ)) {
|
|
1291
1314
|
let upper = m;
|
|
1292
1315
|
let lower = m;
|
|
1293
|
-
while (++upper <
|
|
1294
|
-
if (
|
|
1316
|
+
while (++upper < attr.chi.length) {
|
|
1317
|
+
if (attr.chi[upper].typ == EnumToken.CommentTokenType) {
|
|
1295
1318
|
continue;
|
|
1296
1319
|
}
|
|
1297
1320
|
break;
|
|
1298
1321
|
}
|
|
1299
1322
|
while (lower-- > 0) {
|
|
1300
|
-
if (
|
|
1323
|
+
if (attr.chi[lower].typ == EnumToken.CommentTokenType) {
|
|
1301
1324
|
continue;
|
|
1302
1325
|
}
|
|
1303
1326
|
break;
|
|
1304
1327
|
}
|
|
1305
|
-
val =
|
|
1328
|
+
val = attr.chi[lower];
|
|
1306
1329
|
if (val.typ == EnumToken.StringTokenType) {
|
|
1307
1330
|
const slice = val.val.slice(1, -1);
|
|
1308
1331
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
1309
1332
|
Object.assign(val, { typ: EnumToken.IdenTokenType, val: slice });
|
|
1310
1333
|
}
|
|
1311
1334
|
}
|
|
1312
|
-
val =
|
|
1335
|
+
val = attr.chi[upper];
|
|
1313
1336
|
if (val.typ == EnumToken.StringTokenType) {
|
|
1314
1337
|
const slice = val.val.slice(1, -1);
|
|
1315
1338
|
if ((slice.charAt(0) != '-' || (slice.charAt(0) == '-' && isIdentStart(slice.charCodeAt(1)))) && isIdent(slice)) {
|
|
@@ -1429,7 +1452,9 @@ function parseTokens(tokens, options = {}) {
|
|
|
1429
1452
|
t.typ = EnumToken.ColorTokenType;
|
|
1430
1453
|
// @ts-ignore
|
|
1431
1454
|
t.kin = t.val;
|
|
1455
|
+
// @ts-ignore
|
|
1432
1456
|
if (t.chi[0].typ == EnumToken.IdenTokenType) {
|
|
1457
|
+
// @ts-ignore
|
|
1433
1458
|
if (t.chi[0].val == 'from') {
|
|
1434
1459
|
// @ts-ignore
|
|
1435
1460
|
t.cal = 'rel';
|
|
@@ -1439,10 +1464,11 @@ function parseTokens(tokens, options = {}) {
|
|
|
1439
1464
|
// @ts-ignore
|
|
1440
1465
|
t.cal = 'mix';
|
|
1441
1466
|
}
|
|
1442
|
-
else
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1467
|
+
else { // @ts-ignore
|
|
1468
|
+
if (t.val == 'color') {
|
|
1469
|
+
// @ts-ignore
|
|
1470
|
+
t.cal = 'col';
|
|
1471
|
+
}
|
|
1446
1472
|
}
|
|
1447
1473
|
}
|
|
1448
1474
|
const filter = [EnumToken.WhitespaceTokenType, EnumToken.CommentTokenType];
|
|
@@ -1476,7 +1502,7 @@ function parseTokens(tokens, options = {}) {
|
|
|
1476
1502
|
if (t.chi.length > 0) {
|
|
1477
1503
|
if (t.typ == EnumToken.PseudoClassFuncTokenType && t.val == ':is' && options.minify) {
|
|
1478
1504
|
//
|
|
1479
|
-
const count = t.chi.filter(t => t.typ != EnumToken.CommentTokenType).length;
|
|
1505
|
+
const count = t.chi.filter((t) => t.typ != EnumToken.CommentTokenType).length;
|
|
1480
1506
|
if (count == 1 ||
|
|
1481
1507
|
(i == 0 &&
|
|
1482
1508
|
(tokens[i + 1]?.typ == EnumToken.CommaTokenType || tokens.length == i + 1)) ||
|
|
@@ -15,9 +15,9 @@ import { xyz2srgb, lsrgb2srgbvalues, srgb2lsrgbvalues, lch2srgb, oklab2srgb, lab
|
|
|
15
15
|
import { prophotorgb2srgbvalues, srgb2prophotorgbvalues } from './prophotorgb.js';
|
|
16
16
|
import { a98rgb2srgbvalues, srgb2a98values } from './a98rgb.js';
|
|
17
17
|
import { rec20202srgb, srgb2rec2020values } from './rec2020.js';
|
|
18
|
-
import {
|
|
18
|
+
import { srgb2xyz } from './xyz.js';
|
|
19
19
|
import { p32srgbvalues, srgb2p3values } from './p3.js';
|
|
20
|
-
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
20
|
+
import { xyzd502srgb, XYZ_D65_to_D50 } from './xyzd50.js';
|
|
21
21
|
import '../sourcemap/lib/encode.js';
|
|
22
22
|
import '../../parser/utils/config.js';
|
|
23
23
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { e, k, D50 } from './utils/constants.js';
|
|
2
2
|
import { getComponents } from './utils/components.js';
|
|
3
|
-
import { srgb2xyz
|
|
3
|
+
import { srgb2xyz } from './xyz.js';
|
|
4
4
|
import { oklch2srgb, hwb2srgb, hsl2srgb, rgb2srgb, hex2srgb } from './srgb.js';
|
|
5
5
|
import { getLCHComponents } from './lch.js';
|
|
6
6
|
import { OKLab_to_XYZ, getOKLABComponents } from './oklab.js';
|
|
@@ -9,6 +9,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
9
9
|
import '../../ast/minify.js';
|
|
10
10
|
import '../../ast/walk.js';
|
|
11
11
|
import '../../parser/parse.js';
|
|
12
|
+
import { xyzd502srgb } from './xyzd50.js';
|
|
12
13
|
import '../sourcemap/lib/encode.js';
|
|
13
14
|
import '../../parser/utils/config.js';
|
|
14
15
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { srgb2xyz
|
|
2
|
-
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
1
|
+
import { srgb2xyz } from './xyz.js';
|
|
2
|
+
import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
|
|
3
3
|
|
|
4
4
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
5
5
|
// @ts-ignore
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { srgb2xyz
|
|
2
|
-
import { XYZ_D65_to_D50 } from './xyzd50.js';
|
|
1
|
+
import { srgb2xyz } from './xyz.js';
|
|
2
|
+
import { XYZ_D65_to_D50, xyzd502srgb } from './xyzd50.js';
|
|
3
3
|
|
|
4
4
|
function prophotorgb2srgbvalues(r, g, b, a = null) {
|
|
5
5
|
// @ts-ignore
|
|
@@ -4,26 +4,10 @@ import '../../ast/types.js';
|
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
5
|
import '../../ast/walk.js';
|
|
6
6
|
import '../../parser/parse.js';
|
|
7
|
-
import { srgb2lsrgbvalues
|
|
7
|
+
import { srgb2lsrgbvalues } from './srgb.js';
|
|
8
8
|
import '../sourcemap/lib/encode.js';
|
|
9
9
|
import '../../parser/utils/config.js';
|
|
10
10
|
|
|
11
|
-
function xyzd502srgb(x, y, z) {
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
return lsrgb2srgbvalues(
|
|
14
|
-
/* r: */
|
|
15
|
-
x * 3.1341359569958707 -
|
|
16
|
-
y * 1.6173863321612538 -
|
|
17
|
-
0.4906619460083532 * z,
|
|
18
|
-
/* g: */
|
|
19
|
-
x * -0.978795502912089 +
|
|
20
|
-
y * 1.916254567259524 +
|
|
21
|
-
0.03344273116131949 * z,
|
|
22
|
-
/* b: */
|
|
23
|
-
x * 0.07195537988411677 -
|
|
24
|
-
y * 0.2289768264158322 +
|
|
25
|
-
1.405386058324125 * z);
|
|
26
|
-
}
|
|
27
11
|
function XYZ_to_lin_sRGB(x, y, z) {
|
|
28
12
|
// convert XYZ to linear-light sRGB
|
|
29
13
|
const M = [
|
|
@@ -63,4 +47,4 @@ function srgb2xyz(r, g, b, alpha) {
|
|
|
63
47
|
return rgb;
|
|
64
48
|
}
|
|
65
49
|
|
|
66
|
-
export { XYZ_D50_to_D65, XYZ_to_lin_sRGB, srgb2xyz
|
|
50
|
+
export { XYZ_D50_to_D65, XYZ_to_lin_sRGB, srgb2xyz };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { lsrgb2srgbvalues } from './srgb.js';
|
|
1
2
|
import { multiplyMatrices } from './utils/matrix.js';
|
|
2
3
|
import './utils/constants.js';
|
|
3
4
|
import '../../ast/types.js';
|
|
@@ -10,11 +11,12 @@ import { XYZ_D50_to_D65 } from './xyz.js';
|
|
|
10
11
|
import '../sourcemap/lib/encode.js';
|
|
11
12
|
import '../../parser/utils/config.js';
|
|
12
13
|
|
|
14
|
+
/*
|
|
15
|
+
*/
|
|
13
16
|
function xyzd502lch(x, y, z, alpha) {
|
|
14
17
|
// @ts-ignore
|
|
15
18
|
const [l, a, b] = xyz2lab(...XYZ_D50_to_D65(x, y, z));
|
|
16
19
|
// L in range [0,100]. For use in CSS, add a percent
|
|
17
|
-
// @ts-ignore
|
|
18
20
|
return lab2lchvalues(l, a, b, alpha);
|
|
19
21
|
}
|
|
20
22
|
function XYZ_D65_to_D50(x, y, z) {
|
|
@@ -31,5 +33,21 @@ function XYZ_D65_to_D50(x, y, z) {
|
|
|
31
33
|
];
|
|
32
34
|
return multiplyMatrices(M, [x, y, z]);
|
|
33
35
|
}
|
|
36
|
+
function xyzd502srgb(x, y, z) {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
return lsrgb2srgbvalues(
|
|
39
|
+
/* r: */
|
|
40
|
+
x * 3.1341359569958707 -
|
|
41
|
+
y * 1.6173863321612538 -
|
|
42
|
+
0.4906619460083532 * z,
|
|
43
|
+
/* g: */
|
|
44
|
+
x * -0.978795502912089 +
|
|
45
|
+
y * 1.916254567259524 +
|
|
46
|
+
0.03344273116131949 * z,
|
|
47
|
+
/* b: */
|
|
48
|
+
x * 0.07195537988411677 -
|
|
49
|
+
y * 0.2289768264158322 +
|
|
50
|
+
1.405386058324125 * z);
|
|
51
|
+
}
|
|
34
52
|
|
|
35
|
-
export { XYZ_D65_to_D50, xyzd502lch };
|
|
53
|
+
export { XYZ_D65_to_D50, xyzd502lch, xyzd502srgb };
|
|
@@ -9,7 +9,7 @@ import { expand } from '../ast/expand.js';
|
|
|
9
9
|
import { colorMix } from './color/colormix.js';
|
|
10
10
|
import { parseRelativeColor } from './color/relativecolor.js';
|
|
11
11
|
import { SourceMap } from './sourcemap/sourcemap.js';
|
|
12
|
-
import { isColor, mathFuncs, isNewLine } from '../syntax/syntax.js';
|
|
12
|
+
import { isColor, pseudoElements, mathFuncs, isNewLine } from '../syntax/syntax.js';
|
|
13
13
|
|
|
14
14
|
const colorsFunc = ['rgb', 'rgba', 'hsl', 'hsla', 'hwb', 'device-cmyk', 'color-mix', 'color', 'oklab', 'lab', 'oklch', 'lch', 'light-dark'];
|
|
15
15
|
function reduceNumber(val) {
|
|
@@ -589,8 +589,9 @@ function renderToken(token, options = {}, cache = Object.create(null), reducer,
|
|
|
589
589
|
return '';
|
|
590
590
|
}
|
|
591
591
|
case EnumToken.PseudoClassTokenType:
|
|
592
|
+
case EnumToken.PseudoElementTokenType:
|
|
592
593
|
// https://www.w3.org/TR/selectors-4/#single-colon-pseudos
|
|
593
|
-
if (token.typ == EnumToken.
|
|
594
|
+
if (token.typ == EnumToken.PseudoElementTokenType && pseudoElements.includes(token.val.slice(1))) {
|
|
594
595
|
return token.val.slice(1);
|
|
595
596
|
}
|
|
596
597
|
case EnumToken.UrlTokenTokenType:
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { encode } from './lib/encode.js';
|
|
2
2
|
|
|
3
3
|
class SourceMap {
|
|
4
|
+
lastLocation = null;
|
|
4
5
|
#version = 3;
|
|
5
6
|
#sources = [];
|
|
6
7
|
#map = new Map;
|
|
7
8
|
#line = -1;
|
|
8
|
-
lastLocation = null;
|
|
9
9
|
add(source, original) {
|
|
10
10
|
if (original.src !== '') {
|
|
11
11
|
if (!this.#sources.includes(original.src)) {
|
|
@@ -25,6 +25,7 @@ const mediaTypes = ['all', 'print', 'screen',
|
|
|
25
25
|
'aural', 'braille', 'embossed', 'handheld', 'projection', 'tty', 'tv', 'speech'];
|
|
26
26
|
// https://www.w3.org/TR/css-values-4/#math-function
|
|
27
27
|
const mathFuncs = ['calc', 'clamp', 'min', 'max', 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'hypot', 'log', 'exp', 'abs', 'sign'];
|
|
28
|
+
const pseudoElements = [':before', ':after', ':first-line', ':first-letter'];
|
|
28
29
|
const webkitPseudoAliasMap = {
|
|
29
30
|
'-webkit-autofill': 'autofill',
|
|
30
31
|
'-webkit-any': 'is',
|
|
@@ -811,4 +812,4 @@ function isWhiteSpace(codepoint) {
|
|
|
811
812
|
codepoint == 0xa || codepoint == 0xc || codepoint == 0xd;
|
|
812
813
|
}
|
|
813
814
|
|
|
814
|
-
export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseDimension, webkitExtensions, webkitPseudoAliasMap };
|
|
815
|
+
export { colorFontTech, fontFeaturesTech, fontFormat, isAngle, isAtKeyword, isColor, isColorspace, isDigit, isDimension, isFlex, isFrequency, isFunction, isHash, isHexColor, isHueInterpolationMethod, isIdent, isIdentCodepoint, isIdentStart, isLength, isNewLine, isNonPrintable, isNumber, isPercentage, isPolarColorspace, isPseudo, isRectangularOrthogonalColorspace, isResolution, isTime, isWhiteSpace, mathFuncs, mediaTypes, mozExtensions, parseDimension, pseudoElements, webkitExtensions, webkitPseudoAliasMap };
|