@tbela99/css-parser 1.5.0 → 1.6.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 +59 -0
- package/README.md +10 -10
- package/dist/index-umd-web.js +5998 -4972
- package/dist/index.cjs +6001 -4977
- package/dist/index.d.ts +52 -38
- package/dist/lib/ast/expand.js +21 -7
- package/dist/lib/ast/features/calc.js +17 -55
- package/dist/lib/ast/features/if.js +7 -3
- package/dist/lib/ast/features/inlinecssvariables.js +6 -5
- package/dist/lib/ast/features/prefix.js +41 -44
- package/dist/lib/ast/features/shorthand.js +10 -5
- package/dist/lib/ast/features/transform.js +2 -2
- package/dist/lib/ast/math/expression.js +207 -34
- package/dist/lib/ast/minify.js +121 -24
- package/dist/lib/ast/node.js +5 -3
- package/dist/lib/ast/transform/compute.js +37 -5
- package/dist/lib/ast/transform/minify.js +7 -7
- package/dist/lib/ast/transform/perspective.js +1 -1
- package/dist/lib/ast/transform/rotate.js +1 -1
- package/dist/lib/ast/transform/scale.js +1 -1
- package/dist/lib/ast/transform/skew.js +1 -1
- package/dist/lib/ast/transform/translate.js +1 -1
- package/dist/lib/ast/transform/utils.js +46 -18
- package/dist/lib/ast/walk.js +28 -4
- package/dist/{config.json.js → lib/data/properties.json.js} +106 -0
- package/dist/lib/{validation/config.json.js → data/validation.json.js} +14 -8
- package/dist/lib/fs/resolve.js +11 -2
- package/dist/lib/parser/declaration/list.js +22 -7
- package/dist/lib/parser/declaration/map.js +26 -8
- package/dist/lib/parser/declaration/set.js +3 -1
- package/dist/lib/parser/linesmap.js +2 -4
- package/dist/lib/parser/parse.js +393 -231
- package/dist/lib/parser/tokenize.js +1478 -819
- package/dist/lib/parser/utils/at-rule-container.js +28 -196
- package/dist/lib/parser/utils/at-rule-generic.js +6 -7
- package/dist/lib/parser/utils/at-rule-import.js +17 -13
- package/dist/lib/parser/utils/at-rule-media.js +36 -19
- package/dist/lib/parser/utils/at-rule-support.js +19 -9
- package/dist/lib/parser/utils/at-rule-when-else.js +11 -38
- package/dist/lib/parser/utils/at-rule.js +0 -18
- package/dist/lib/parser/utils/config.js +1 -1
- package/dist/lib/parser/utils/declaration.js +40 -97
- package/dist/lib/parser/utils/hash.js +4 -4
- package/dist/lib/parser/utils/selector.js +179 -224
- package/dist/lib/parser/utils/text.js +4 -2
- package/dist/lib/renderer/render.js +104 -74
- package/dist/lib/renderer/sourcemap/lib/codec.js +3 -3
- package/dist/lib/renderer/sourcemap/sourcemap.js +2 -5
- package/dist/lib/syntax/color/a98rgb.js +14 -4
- package/dist/lib/syntax/color/cmyk.js +14 -21
- package/dist/lib/syntax/color/color-mix.js +21 -34
- package/dist/lib/syntax/color/color.js +32 -49
- package/dist/lib/syntax/color/hsl.js +15 -15
- package/dist/lib/syntax/color/hwb.js +18 -17
- package/dist/lib/syntax/color/lab.js +17 -17
- package/dist/lib/syntax/color/lch.js +13 -13
- package/dist/lib/syntax/color/oklab.js +10 -11
- package/dist/lib/syntax/color/oklch.js +15 -18
- package/dist/lib/syntax/color/p3.js +18 -12
- package/dist/lib/syntax/color/prophotorgb.js +26 -28
- package/dist/lib/syntax/color/rec2020.js +8 -4
- package/dist/lib/syntax/color/relative-color.js +26 -10
- package/dist/lib/syntax/color/srgb.js +9 -7
- package/dist/lib/syntax/color/utils/distance.js +1 -1
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/color/xyzd50.js +2 -2
- package/dist/lib/syntax/constants.js +13 -3
- package/dist/lib/syntax/syntax.js +32 -108
- package/dist/lib/validation/config.js +1 -1
- package/dist/lib/validation/match.js +29 -26
- package/dist/lib/validation/parser/parse.js +7 -3
- package/dist/node.js +16 -9
- package/dist/types.d.ts +5 -1
- package/dist/types.js +4 -0
- package/dist/utils/sync.js +22 -1
- package/dist/web.js +13 -4
- package/package.json +4 -4
- package/llms.txt +0 -80
package/dist/index.d.ts
CHANGED
|
@@ -966,6 +966,15 @@ declare enum ModuleScopeEnumOptions {
|
|
|
966
966
|
Shortest = 512
|
|
967
967
|
}
|
|
968
968
|
|
|
969
|
+
/**
|
|
970
|
+
* Location source id
|
|
971
|
+
*/
|
|
972
|
+
declare const LOCSRCID: unique symbol;
|
|
973
|
+
declare const LOCSTA: unique symbol;
|
|
974
|
+
declare const LOCEND: unique symbol;
|
|
975
|
+
/**
|
|
976
|
+
* Used by the validation parser
|
|
977
|
+
*/
|
|
969
978
|
declare const LOC: unique symbol;
|
|
970
979
|
declare const RAW: unique symbol;
|
|
971
980
|
declare const STATE: unique symbol;
|
|
@@ -2668,11 +2677,22 @@ export declare interface BaseToken {
|
|
|
2668
2677
|
* token type
|
|
2669
2678
|
*/
|
|
2670
2679
|
typ: EnumToken;
|
|
2680
|
+
|
|
2671
2681
|
/**
|
|
2672
|
-
*
|
|
2673
|
-
* @private
|
|
2682
|
+
* source src
|
|
2674
2683
|
*/
|
|
2675
|
-
[
|
|
2684
|
+
[LOCSRCID]?: number;
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* source start offset
|
|
2688
|
+
*/
|
|
2689
|
+
[LOCSTA]?: number;
|
|
2690
|
+
|
|
2691
|
+
/**
|
|
2692
|
+
* source end offset
|
|
2693
|
+
*/
|
|
2694
|
+
[LOCEND]?: number;
|
|
2695
|
+
|
|
2676
2696
|
/**
|
|
2677
2697
|
* parent node
|
|
2678
2698
|
* @private
|
|
@@ -3981,21 +4001,12 @@ declare class SourceMap {
|
|
|
3981
4001
|
* @returns
|
|
3982
4002
|
*/
|
|
3983
4003
|
addSourceContent(id: number, fileName: string | null, content: string | null): void;
|
|
3984
|
-
/**
|
|
3985
|
-
* Add sourcemap
|
|
3986
|
-
* @param newLine
|
|
3987
|
-
* @param newColumn
|
|
3988
|
-
* @param srcId
|
|
3989
|
-
* @param ln
|
|
3990
|
-
* @param col
|
|
3991
|
-
*/
|
|
3992
|
-
add(newLine: number, newColumn: number, srcId: number, ln: number, col: number): void;
|
|
3993
4004
|
/**
|
|
3994
4005
|
* Add multiple sourcemaps
|
|
3995
4006
|
* @param maps
|
|
3996
4007
|
* @throws
|
|
3997
4008
|
*/
|
|
3998
|
-
add(
|
|
4009
|
+
add(maps: Array<[newLine: number, newColumn: number, srcId: number, ln: number, col: number]>): void;
|
|
3999
4010
|
/**
|
|
4000
4011
|
* compute original positions
|
|
4001
4012
|
*/
|
|
@@ -4072,7 +4083,7 @@ declare class SourceFile {
|
|
|
4072
4083
|
/**
|
|
4073
4084
|
* Source file content
|
|
4074
4085
|
*/
|
|
4075
|
-
|
|
4086
|
+
content: string;
|
|
4076
4087
|
/**
|
|
4077
4088
|
* Constructor
|
|
4078
4089
|
* @param content
|
|
@@ -4392,6 +4403,28 @@ interface ValidationDimensionToken extends ValidationToken$1 {
|
|
|
4392
4403
|
unit: keyof EnumToken;
|
|
4393
4404
|
}
|
|
4394
4405
|
|
|
4406
|
+
/**
|
|
4407
|
+
* response type
|
|
4408
|
+
*/
|
|
4409
|
+
declare enum ResponseType {
|
|
4410
|
+
/**
|
|
4411
|
+
* return text
|
|
4412
|
+
*/
|
|
4413
|
+
Text = 0,
|
|
4414
|
+
/**
|
|
4415
|
+
* return a readable stream
|
|
4416
|
+
*/
|
|
4417
|
+
ReadableStream = 1,
|
|
4418
|
+
/**
|
|
4419
|
+
* return an arraybuffer
|
|
4420
|
+
*/
|
|
4421
|
+
ArrayBuffer = 2,
|
|
4422
|
+
/**
|
|
4423
|
+
* return a json object
|
|
4424
|
+
*/
|
|
4425
|
+
JSON = 3
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4395
4428
|
interface PropertyType {
|
|
4396
4429
|
shorthand: string;
|
|
4397
4430
|
}
|
|
@@ -4908,7 +4941,6 @@ interface BorderRadius {
|
|
|
4908
4941
|
* node walker options
|
|
4909
4942
|
*/
|
|
4910
4943
|
export declare interface WalkerOptions {
|
|
4911
|
-
|
|
4912
4944
|
/**
|
|
4913
4945
|
* walk in reverse
|
|
4914
4946
|
*/
|
|
@@ -4953,7 +4985,7 @@ export declare type WalkerValueFilter = (
|
|
|
4953
4985
|
parent?: AstNode$1 | Token$1 | AstNode$1[] | Token$1[] | null,
|
|
4954
4986
|
event?: WalkerEvent,
|
|
4955
4987
|
parents?: Generator<Token$1>,
|
|
4956
|
-
) => WalkerOption | null;
|
|
4988
|
+
) => WalkerOption | AstNode$1 | Token$1 | AstNode$1[] | Token$1[] | null;
|
|
4957
4989
|
|
|
4958
4990
|
/**
|
|
4959
4991
|
* walker result
|
|
@@ -5192,7 +5224,7 @@ export declare type LoadResult =
|
|
|
5192
5224
|
| Promise<ReadableStream<Uint8Array>>
|
|
5193
5225
|
| ReadableStream<Uint8Array>
|
|
5194
5226
|
| string
|
|
5195
|
-
| Promise<string
|
|
5227
|
+
| Promise<string> | object;
|
|
5196
5228
|
|
|
5197
5229
|
/**
|
|
5198
5230
|
* CSS module parser options
|
|
@@ -6080,24 +6112,6 @@ declare const resolve: (url: string, currentDirectory?: string, cwd?: string) =>
|
|
|
6080
6112
|
relative: string;
|
|
6081
6113
|
};
|
|
6082
6114
|
|
|
6083
|
-
/**
|
|
6084
|
-
* response type
|
|
6085
|
-
*/
|
|
6086
|
-
declare enum ResponseType$1 {
|
|
6087
|
-
/**
|
|
6088
|
-
* return text
|
|
6089
|
-
*/
|
|
6090
|
-
Text = 0,
|
|
6091
|
-
/**
|
|
6092
|
-
* return a readable stream
|
|
6093
|
-
*/
|
|
6094
|
-
ReadableStream = 1,
|
|
6095
|
-
/**
|
|
6096
|
-
* return an arraybuffer
|
|
6097
|
-
*/
|
|
6098
|
-
ArrayBuffer = 2
|
|
6099
|
-
}
|
|
6100
|
-
|
|
6101
6115
|
/**
|
|
6102
6116
|
* Validation syntax
|
|
6103
6117
|
* @internal
|
|
@@ -6233,7 +6247,7 @@ declare function expand(ast: AstStyleSheet | AstAtRule | AstRule): AstNode$1;
|
|
|
6233
6247
|
* console.log(declarations);
|
|
6234
6248
|
* ```
|
|
6235
6249
|
*/
|
|
6236
|
-
declare function parseDeclarations(declaration: string):
|
|
6250
|
+
declare function parseDeclarations(declaration: string): Array<AstDeclaration | AstComment>;
|
|
6237
6251
|
/**
|
|
6238
6252
|
* Parse css string and return an array of tokens
|
|
6239
6253
|
* @param src
|
|
@@ -6551,7 +6565,7 @@ declare function setNodeProperty(node: AstNode$1, key: 'tokens', value: Token$1[
|
|
|
6551
6565
|
declare function load(url: string | {
|
|
6552
6566
|
absolute: string;
|
|
6553
6567
|
relative: string;
|
|
6554
|
-
}, currentDirectory?: string, responseType?: boolean | ResponseType
|
|
6568
|
+
}, currentDirectory?: string, responseType?: boolean | ResponseType): Promise<string | ArrayBuffer | ReadableStream<Uint8Array<ArrayBufferLike>>>;
|
|
6555
6569
|
/**
|
|
6556
6570
|
* Render the ast tree
|
|
6557
6571
|
* @param data
|
|
@@ -6923,5 +6937,5 @@ declare function transform(options: ParseInputStreamOptions & TransformOptions):
|
|
|
6923
6937
|
*/
|
|
6924
6938
|
declare function transform(options: ParseInputFileOptions & TransformOptions): Promise<TransformResult>;
|
|
6925
6939
|
|
|
6926
|
-
export { ColorType$1 as ColorType, EnumAstNodeStatus$1 as EnumAstNodeStatus, EnumToken, FeatureWalkMode, ModuleCaseTransformEnum, ModuleScopeEnumOptions, ResponseType
|
|
6940
|
+
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 };
|
|
6927
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 };
|
package/dist/lib/ast/expand.js
CHANGED
|
@@ -28,9 +28,8 @@ function expand(ast) {
|
|
|
28
28
|
children = expandRule(node);
|
|
29
29
|
for (const child of children) {
|
|
30
30
|
child[PARENT] = result;
|
|
31
|
+
result.chi.push(child);
|
|
31
32
|
}
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
result.chi.push(...children);
|
|
34
33
|
}
|
|
35
34
|
else if (node.typ == EnumToken.AtRuleNodeType && "chi" in node) {
|
|
36
35
|
let hasRule = false;
|
|
@@ -150,6 +149,13 @@ function expandRule(node) {
|
|
|
150
149
|
}
|
|
151
150
|
if (withCompound.length > 0) {
|
|
152
151
|
if (withCompound.every((t) => t[0] == "&" && t.indexOf("&", 1) == -1)) {
|
|
152
|
+
// for (const w of withCompound) {
|
|
153
|
+
// for (let m = 0; m < w.length; m++) {
|
|
154
|
+
// // for (let n = 0; n < w[m].length; n++) {
|
|
155
|
+
// withoutCompound.push(w[m].slice(1));
|
|
156
|
+
// // }
|
|
157
|
+
// }
|
|
158
|
+
// }
|
|
153
159
|
withoutCompound.push(...withCompound.map((t) => t.slice(1)));
|
|
154
160
|
withCompound.length = 0;
|
|
155
161
|
}
|
|
@@ -189,7 +195,9 @@ function expandRule(node) {
|
|
|
189
195
|
rule.sel = selectors.reduce((acc, curr) => (curr.length == 0 ? acc : acc + (acc.length > 0 ? "," : "") + curr), "");
|
|
190
196
|
}
|
|
191
197
|
ast.chi.splice(i--, 1);
|
|
192
|
-
|
|
198
|
+
for (const s of expandRule(rule)) {
|
|
199
|
+
result.push(s);
|
|
200
|
+
}
|
|
193
201
|
}
|
|
194
202
|
else if (ast.chi[i].typ == EnumToken.AtRuleNodeType) {
|
|
195
203
|
let astAtRule = ast.chi[i];
|
|
@@ -224,13 +232,19 @@ function expandRule(node) {
|
|
|
224
232
|
values.push(r);
|
|
225
233
|
}
|
|
226
234
|
else if (r.typ == EnumToken.RuleNodeType) {
|
|
227
|
-
|
|
228
|
-
|
|
235
|
+
for (const rule of expandRule(r)) {
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
astAtRule.chi.push(rule);
|
|
238
|
+
}
|
|
229
239
|
}
|
|
230
240
|
}
|
|
231
241
|
}
|
|
232
|
-
|
|
233
|
-
|
|
242
|
+
if (astAtRule.chi.length > 0) {
|
|
243
|
+
result.push(astAtRule);
|
|
244
|
+
}
|
|
245
|
+
for (const r of values) {
|
|
246
|
+
result.push(r);
|
|
247
|
+
}
|
|
234
248
|
ast.chi.splice(i--, 1);
|
|
235
249
|
}
|
|
236
250
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
|
-
import { walkValues
|
|
2
|
+
import { walkValues } from '../walk.js';
|
|
3
3
|
import { evaluate } from '../math/expression.js';
|
|
4
|
-
import { renderValue } from '../../renderer/render.js';
|
|
5
4
|
import { FeatureWalkMode } from './type.js';
|
|
6
|
-
import { mathFuncs,
|
|
5
|
+
import { tokensfuncSet, mathFuncs, LOCEND, LOCSTA, LOCSRCID } from '../../syntax/constants.js';
|
|
6
|
+
import { replaceNodeOrValue } from '../../parser/utils/token.js';
|
|
7
7
|
|
|
8
8
|
class ComputeCalcExpressionFeature {
|
|
9
9
|
accept = new Set([EnumToken.RuleNodeType, EnumToken.AtRuleNodeType]);
|
|
@@ -28,57 +28,15 @@ class ComputeCalcExpressionFeature {
|
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
30
|
const set = new Set();
|
|
31
|
-
for (const { value, parent } of walkValues(node.val, node
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
parent.typ == EnumToken.DeclarationNodeType &&
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
parent.val.length == 1 &&
|
|
40
|
-
(node.typ === EnumToken.MathFunctionTokenType || node.typ === EnumToken.FunctionTokenType) &&
|
|
41
|
-
mathFuncs.includes(node.val) &&
|
|
42
|
-
node.chi.length == 1 &&
|
|
43
|
-
node.chi[0].typ == EnumToken.IdenTokenType) {
|
|
44
|
-
return WalkerOptionEnum.Ignore;
|
|
45
|
-
}
|
|
46
|
-
if ((node.typ === EnumToken.WildCardFunctionTokenType && node.val == "var") ||
|
|
47
|
-
(!mathFuncs.includes(parent.val) &&
|
|
48
|
-
[
|
|
49
|
-
EnumToken.MathFunctionTokenType,
|
|
50
|
-
EnumToken.ColorTokenType,
|
|
51
|
-
EnumToken.DeclarationNodeType,
|
|
52
|
-
EnumToken.ImageFunc,
|
|
53
|
-
EnumToken.RuleNodeType,
|
|
54
|
-
EnumToken.AtRuleNodeType,
|
|
55
|
-
EnumToken.StyleSheetNodeType,
|
|
56
|
-
].includes(parent?.typ))) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
31
|
+
for (const { value, parent } of walkValues(node.val, node)) {
|
|
32
|
+
if (parent?.typ == EnumToken.BinaryExpressionTokenType) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (value.typ == EnumToken.BinaryExpressionTokenType) {
|
|
59
36
|
// @ts-ignore
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
? node.val
|
|
64
|
-
: node.chi)?.slice();
|
|
65
|
-
if (slice != null &&
|
|
66
|
-
(node.typ === EnumToken.MathFunctionTokenType ||
|
|
67
|
-
(node.typ == EnumToken.FunctionTokenType &&
|
|
68
|
-
mathFuncs.includes(node.val)))) {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
const key = "chi" in node ? "chi" : "val";
|
|
71
|
-
const str1 = renderValue({ ...node, [key]: slice });
|
|
72
|
-
const str2 = renderValue(node); // values.reduce((acc: string, curr: Token): string => acc + renderValue(curr), '');
|
|
73
|
-
if (str1.length < str2.length) {
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
node[key] = slice;
|
|
76
|
-
}
|
|
77
|
-
return WalkerOptionEnum.Ignore;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
80
|
-
},
|
|
81
|
-
})) {
|
|
37
|
+
replaceNodeOrValue(parent, value, evaluate([value]));
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
82
40
|
if (value != null && tokensfuncSet.has(value.typ)) {
|
|
83
41
|
if (!set.has(value)) {
|
|
84
42
|
set.add(value);
|
|
@@ -125,7 +83,9 @@ class ComputeCalcExpressionFeature {
|
|
|
125
83
|
typ: EnumToken.MathFunctionTokenType,
|
|
126
84
|
val: "calc",
|
|
127
85
|
chi: values,
|
|
128
|
-
[
|
|
86
|
+
[LOCSRCID]: value[LOCSRCID],
|
|
87
|
+
[LOCSTA]: value[LOCSTA],
|
|
88
|
+
[LOCEND]: value[LOCEND],
|
|
129
89
|
}
|
|
130
90
|
: values[0]);
|
|
131
91
|
break;
|
|
@@ -139,7 +99,9 @@ class ComputeCalcExpressionFeature {
|
|
|
139
99
|
typ: EnumToken.MathFunctionTokenType,
|
|
140
100
|
val: "calc",
|
|
141
101
|
chi: values,
|
|
142
|
-
[
|
|
102
|
+
[LOCSRCID]: value[LOCSRCID],
|
|
103
|
+
[LOCSTA]: value[LOCSTA],
|
|
104
|
+
[LOCEND]: value[LOCEND],
|
|
143
105
|
});
|
|
144
106
|
break;
|
|
145
107
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EnumToken } from '../types.js';
|
|
2
2
|
import { renderValue } from '../../renderer/render.js';
|
|
3
3
|
import { FeatureWalkMode } from './type.js';
|
|
4
|
-
import { PARENT,
|
|
4
|
+
import { PARENT, LOCSRCID, LOCSTA, LOCEND, TOKENS } from '../../syntax/constants.js';
|
|
5
5
|
import { equalsIgnoreCase } from '../../parser/utils/text.js';
|
|
6
6
|
import { replaceNodeOrValue } from '../../parser/utils/token.js';
|
|
7
7
|
import { cloneNode } from '../clone.js';
|
|
@@ -87,7 +87,9 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
87
87
|
chi: [],
|
|
88
88
|
});
|
|
89
89
|
if (declaration[PARENT] != null) {
|
|
90
|
-
atRule[
|
|
90
|
+
atRule[LOCSRCID] = declaration[PARENT][LOCSRCID];
|
|
91
|
+
atRule[LOCSTA] = declaration[PARENT][LOCSTA];
|
|
92
|
+
atRule[LOCEND] = declaration[PARENT][LOCEND];
|
|
91
93
|
}
|
|
92
94
|
atRule[TOKENS] = [{ typ: EnumToken.ParensTokenType, chi: left.chi.slice() }];
|
|
93
95
|
const minify = atRule.nam !== "supports";
|
|
@@ -112,7 +114,9 @@ function substituteIfElseNode(declaration, node, wrapper, parentWrapper, cache)
|
|
|
112
114
|
atRule[TOKENS] = [left];
|
|
113
115
|
atRule.val = atRule[TOKENS].reduce((acc, curr) => acc + renderValue(curr), "");
|
|
114
116
|
if (declaration[PARENT] != null) {
|
|
115
|
-
atRule[
|
|
117
|
+
atRule[LOCSRCID] = declaration[PARENT][LOCSRCID];
|
|
118
|
+
atRule[LOCSTA] = declaration[PARENT][LOCSTA];
|
|
119
|
+
atRule[LOCEND] = declaration[PARENT][LOCEND];
|
|
116
120
|
}
|
|
117
121
|
clonedDeclaration = cloneNode(declaration, true, nodeMap);
|
|
118
122
|
replaceNodeOrValue(nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetParentWrapper : targetWrapper), nodeMap.get(targetWrapper.typ === EnumToken.WildCardFunctionTokenType ? targetWrapper : node), node.r.at(-1)?.typ === EnumToken.SemiColonTokenType
|
|
@@ -8,13 +8,14 @@ import { RAW, mathFuncs } from '../../syntax/constants.js';
|
|
|
8
8
|
function inlineExpression(token) {
|
|
9
9
|
const result = [];
|
|
10
10
|
if (token.typ == EnumToken.BinaryExpressionTokenType) {
|
|
11
|
+
const chi = inlineExpression(token.l);
|
|
12
|
+
chi.push({ typ: token.op });
|
|
13
|
+
for (const child of inlineExpression(token.r)) {
|
|
14
|
+
chi.push(child);
|
|
15
|
+
}
|
|
11
16
|
result.push({
|
|
12
17
|
typ: EnumToken.ParensTokenType,
|
|
13
|
-
chi
|
|
14
|
-
...inlineExpression(token.l),
|
|
15
|
-
{ typ: token.op },
|
|
16
|
-
...inlineExpression(token.r),
|
|
17
|
-
],
|
|
18
|
+
chi,
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
else {
|
|
@@ -67,8 +67,8 @@ function replaceAstNodes(tokens, root) {
|
|
|
67
67
|
// typ: EnumToken.ResolutionTokenType,
|
|
68
68
|
// unit: "x",
|
|
69
69
|
// });
|
|
70
|
-
// }
|
|
71
|
-
// else
|
|
70
|
+
// }
|
|
71
|
+
// else
|
|
72
72
|
if (isPseudClass && value.typ == EnumToken.PseudoElementTokenType) {
|
|
73
73
|
// @ts-ignore
|
|
74
74
|
value.typ = EnumToken.PseudoClassTokenType;
|
|
@@ -81,7 +81,7 @@ function replaceAstNodes(tokens, root) {
|
|
|
81
81
|
const set = new Set();
|
|
82
82
|
const split = splitTokenList(tokens, [EnumToken.CommaTokenType]);
|
|
83
83
|
tokens.length = 0;
|
|
84
|
-
|
|
84
|
+
for (const token of split.reduce((acc, curr) => {
|
|
85
85
|
const str = curr.reduce((acc, curr) => acc + renderValue(curr), "");
|
|
86
86
|
if (set.has(str)) {
|
|
87
87
|
return acc;
|
|
@@ -93,7 +93,9 @@ function replaceAstNodes(tokens, root) {
|
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
return acc.concat(curr);
|
|
96
|
-
}, []))
|
|
96
|
+
}, [])) {
|
|
97
|
+
tokens.push(token);
|
|
98
|
+
}
|
|
97
99
|
}
|
|
98
100
|
return result;
|
|
99
101
|
}
|
|
@@ -311,52 +313,28 @@ class ComputePrefixFeature {
|
|
|
311
313
|
// right bottom → left top to top left
|
|
312
314
|
const replacements = [];
|
|
313
315
|
if (key === "left top left bottom") {
|
|
314
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
315
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
316
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "bottom" });
|
|
316
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "bottom" });
|
|
317
317
|
}
|
|
318
318
|
else if (key === "left bottom left top") {
|
|
319
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
320
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
321
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "top" });
|
|
319
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "top" });
|
|
322
320
|
}
|
|
323
321
|
else if (key === "left top right top") {
|
|
324
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
325
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
326
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "right" });
|
|
322
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "right" });
|
|
327
323
|
}
|
|
328
324
|
else if (key === "right top left top") {
|
|
329
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
330
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
331
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "left" });
|
|
325
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "left" });
|
|
332
326
|
}
|
|
333
327
|
else if (key === "left top right bottom") {
|
|
334
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
335
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
336
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "bottom" });
|
|
337
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
338
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "right" });
|
|
328
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "bottom" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "right" });
|
|
339
329
|
}
|
|
340
330
|
else if (key === "right top left bottom") {
|
|
341
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
342
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
343
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "bottom" });
|
|
344
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
345
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "left" });
|
|
331
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "bottom" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "left" });
|
|
346
332
|
}
|
|
347
333
|
else if (key === "left bottom right top") {
|
|
348
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
349
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
350
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "top" });
|
|
351
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
352
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "right" });
|
|
334
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "top" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "right" });
|
|
353
335
|
}
|
|
354
336
|
else if (key === "right bottom left top") {
|
|
355
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" });
|
|
356
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
357
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "top" });
|
|
358
|
-
replacements.push({ typ: EnumToken.WhitespaceTokenType });
|
|
359
|
-
replacements.push({ typ: EnumToken.IdenTokenType, val: "left" });
|
|
337
|
+
replacements.push({ typ: EnumToken.IdenTokenType, val: "to" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "top" }, { typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "left" });
|
|
360
338
|
}
|
|
361
339
|
tokens.splice(0, i, ...replacements);
|
|
362
340
|
let checkStop = true;
|
|
@@ -369,7 +347,10 @@ class ComputePrefixFeature {
|
|
|
369
347
|
}
|
|
370
348
|
if (tokens[i].typ === EnumToken.FunctionTokenType) {
|
|
371
349
|
if (equalsIgnoreCase(tokens[i].val, "to")) {
|
|
372
|
-
colorStop.push(tokens[checkStopIndex]
|
|
350
|
+
colorStop.push(tokens[checkStopIndex]);
|
|
351
|
+
for (const token of tokens[i].chi) {
|
|
352
|
+
colorStop.push(token);
|
|
353
|
+
}
|
|
373
354
|
tokens.splice(checkStopIndex, i - checkStopIndex + 1);
|
|
374
355
|
i = checkStopIndex;
|
|
375
356
|
checkStop = false;
|
|
@@ -397,12 +378,16 @@ class ComputePrefixFeature {
|
|
|
397
378
|
}
|
|
398
379
|
}
|
|
399
380
|
if (colorStop.length > 0) {
|
|
400
|
-
|
|
381
|
+
for (const t of colorStop) {
|
|
382
|
+
tokens.push(t);
|
|
383
|
+
}
|
|
401
384
|
}
|
|
402
385
|
if (type !== "") {
|
|
403
386
|
token.val = type;
|
|
404
387
|
token.chi.length = 0;
|
|
405
|
-
|
|
388
|
+
for (const t of tokens) {
|
|
389
|
+
token.chi.push(t);
|
|
390
|
+
}
|
|
406
391
|
}
|
|
407
392
|
}
|
|
408
393
|
/**
|
|
@@ -473,7 +458,9 @@ class ComputePrefixFeature {
|
|
|
473
458
|
i++;
|
|
474
459
|
}
|
|
475
460
|
}
|
|
476
|
-
|
|
461
|
+
for (let m = i; m < tokens.length; m++) {
|
|
462
|
+
colorStops.push(tokens[m]);
|
|
463
|
+
}
|
|
477
464
|
tokens.length = 0;
|
|
478
465
|
if (form.length > 0 || size.length > 0) {
|
|
479
466
|
if (form.length === 0) {
|
|
@@ -481,17 +468,27 @@ class ComputePrefixFeature {
|
|
|
481
468
|
}
|
|
482
469
|
if (size.length > 0) {
|
|
483
470
|
form.push({ typ: EnumToken.WhitespaceTokenType });
|
|
484
|
-
|
|
471
|
+
for (const token of size) {
|
|
472
|
+
form.push(token);
|
|
473
|
+
}
|
|
485
474
|
}
|
|
486
475
|
if (positions.length > 0) {
|
|
487
|
-
form.push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "at" }, { typ: EnumToken.WhitespaceTokenType }
|
|
476
|
+
form.push({ typ: EnumToken.WhitespaceTokenType }, { typ: EnumToken.IdenTokenType, val: "at" }, { typ: EnumToken.WhitespaceTokenType });
|
|
477
|
+
for (const position of positions) {
|
|
478
|
+
form.push(position);
|
|
479
|
+
}
|
|
488
480
|
}
|
|
489
|
-
|
|
481
|
+
for (const token of form) {
|
|
482
|
+
tokens.push(token);
|
|
483
|
+
}
|
|
484
|
+
tokens.push({ typ: EnumToken.CommaTokenType });
|
|
490
485
|
}
|
|
491
486
|
token.val = equalsIgnoreCase(token.val, "-webkit-repeating-radial-gradient")
|
|
492
487
|
? "repeating-radial-gradient"
|
|
493
488
|
: "radial-gradient";
|
|
494
|
-
|
|
489
|
+
for (const colorStop of colorStops) {
|
|
490
|
+
tokens.push(colorStop);
|
|
491
|
+
}
|
|
495
492
|
return tokens;
|
|
496
493
|
}
|
|
497
494
|
}
|
|
@@ -20,7 +20,7 @@ class ComputeShorthandFeature {
|
|
|
20
20
|
options.features.push(new ComputeShorthandFeature(options));
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
run(ast, options
|
|
23
|
+
run(ast, options) {
|
|
24
24
|
if (!("chi" in ast)) {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
@@ -46,15 +46,20 @@ class ComputeShorthandFeature {
|
|
|
46
46
|
// @ts-ignore
|
|
47
47
|
const node = ast.chi[l];
|
|
48
48
|
if (node.typ == EnumToken.DeclarationNodeType) {
|
|
49
|
-
|
|
49
|
+
for (let m = k; m <= l; m++) {
|
|
50
|
+
properties.add(ast.chi[m]);
|
|
51
|
+
}
|
|
50
52
|
}
|
|
51
53
|
else {
|
|
52
|
-
|
|
54
|
+
for (let m = k; m <= l; m++) {
|
|
55
|
+
rules.push(ast.chi[m]);
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
k = l;
|
|
55
59
|
}
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
ast.chi.length = 0;
|
|
61
|
+
// @ts-expect-error
|
|
62
|
+
ast.chi.push(...properties, ...rules);
|
|
58
63
|
return ast;
|
|
59
64
|
}
|
|
60
65
|
}
|
|
@@ -25,7 +25,7 @@ class TransformCssFeature {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
run(ast) {
|
|
28
|
-
if (
|
|
28
|
+
if (ast.chi == null) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
31
|
let i = 0;
|
|
@@ -53,7 +53,7 @@ class TransformCssFeature {
|
|
|
53
53
|
minified: null,
|
|
54
54
|
};
|
|
55
55
|
if (matrix == null || cumulative == null || minified == null) {
|
|
56
|
-
node.val = children;
|
|
56
|
+
node.val = children.map((t) => t.typ == EnumToken.TransformFunctionTokenType ? minifyTransformFunctions(t) : t);
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
59
|
let r = [filterValues(children)];
|