@tbela99/css-parser 1.4.3 → 1.4.5
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 +196 -2
- package/README.md +68 -1120
- package/dist/config.json.js +43 -2
- package/dist/index-umd-web.js +18118 -15886
- package/dist/index.cjs +16838 -14611
- package/dist/index.d.ts +1804 -1684
- package/dist/lib/ast/clone.js +4 -3
- package/dist/lib/ast/expand.js +2 -2
- package/dist/lib/ast/features/calc.js +59 -54
- package/dist/lib/ast/features/if.js +64 -17
- package/dist/lib/ast/features/inlinecssvariables.js +2 -2
- package/dist/lib/ast/features/prefix.js +343 -6
- package/dist/lib/ast/features/transform.js +7 -4
- package/dist/lib/ast/find.js +5 -5
- package/dist/lib/ast/math/expression.js +12 -8
- package/dist/lib/ast/minify.js +28 -33
- package/dist/lib/ast/transform/minify.js +135 -131
- package/dist/lib/ast/transform/utils.js +3 -2
- package/dist/lib/ast/types.js +69 -8
- package/dist/lib/ast/walk.js +4 -5
- package/dist/lib/fs/resolve.js +71 -57
- package/dist/lib/parser/declaration/list.js +92 -3
- package/dist/lib/parser/declaration/map.js +5 -5
- package/dist/lib/parser/parse.js +530 -466
- package/dist/lib/parser/tokenize.js +110 -4
- package/dist/lib/parser/utils/angle.js +29 -0
- package/dist/lib/parser/utils/at-rule-container.js +2 -2
- package/dist/lib/parser/utils/at-rule-font-feature-values.js +2 -2
- package/dist/lib/parser/utils/at-rule-generic.js +1 -1
- package/dist/lib/parser/utils/at-rule-media.js +2 -2
- package/dist/lib/parser/utils/at-rule-support.js +73 -8
- package/dist/lib/parser/utils/at-rule-when-else.js +2 -2
- package/dist/lib/parser/utils/at-rule.js +2 -8
- package/dist/lib/parser/utils/declaration.js +179 -76
- package/dist/lib/parser/utils/selector.js +53 -11
- package/dist/lib/parser/utils/token.js +13 -11
- package/dist/lib/renderer/render.js +501 -59
- package/dist/lib/syntax/color/alpha.js +64 -0
- package/dist/lib/syntax/color/cmyk.js +2 -2
- package/dist/lib/syntax/color/color-mix.js +283 -220
- package/dist/lib/syntax/color/color.js +37 -28
- package/dist/lib/syntax/color/hex.js +2 -2
- package/dist/lib/syntax/color/hsl.js +3 -3
- package/dist/lib/syntax/color/hwb.js +7 -7
- package/dist/lib/syntax/color/lab.js +5 -5
- package/dist/lib/syntax/color/lch.js +4 -4
- package/dist/lib/syntax/color/oklab.js +3 -3
- package/dist/lib/syntax/color/oklch.js +3 -3
- package/dist/lib/syntax/color/relativecolor.js +97 -12
- package/dist/lib/syntax/color/srgb.js +5 -5
- package/dist/lib/syntax/color/utils/color-type.js +18 -0
- package/dist/lib/syntax/color/utils/colorspace.js +46 -0
- package/dist/lib/syntax/color/utils/components.js +7 -3
- package/dist/lib/syntax/color/utils/distance.js +21 -4
- package/dist/lib/syntax/color/utils/make-color.js +56 -0
- package/dist/lib/syntax/color/xyz.js +2 -2
- package/dist/lib/syntax/constants.js +29 -1
- package/dist/lib/syntax/syntax.js +307 -39
- package/dist/lib/validation/config.js +2 -2
- package/dist/lib/validation/config.json.js +32 -17
- package/dist/lib/validation/match.js +239 -104
- package/dist/lib/validation/parser/parse.js +0 -1
- package/dist/lib/validation/parser/typedef.js +6 -0
- package/dist/node.js +64 -22
- package/dist/web.js +65 -18
- package/package.json +26 -15
- package/.nyc_output/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.nyc_output/processinfo/4874b20e-6f53-4d7a-be5a-cf68316925f2.json +0 -1
- package/.nyc_output/processinfo/6193bc4c-6f5f-4898-8950-c628825e6342.json +0 -1
- package/.repl_history +0 -4
- package/badges/coverage.svg +0 -20
- package/deno.lock +0 -2861
- package/dist/lib/ast/clone.d.ts +0 -10
- package/dist/lib/ast/expand.d.ts +0 -14
- package/dist/lib/ast/features/calc.d.ts +0 -10
- package/dist/lib/ast/features/if.d.ts +0 -10
- package/dist/lib/ast/features/index.d.ts +0 -6
- package/dist/lib/ast/features/inlinecssvariables.d.ts +0 -15
- package/dist/lib/ast/features/prefix.d.ts +0 -8
- package/dist/lib/ast/features/shorthand.d.ts +0 -12
- package/dist/lib/ast/features/transform.d.ts +0 -10
- package/dist/lib/ast/features/type.d.ts +0 -15
- package/dist/lib/ast/find.d.ts +0 -165
- package/dist/lib/ast/math/expression.d.ts +0 -18
- package/dist/lib/ast/math/math.d.ts +0 -6
- package/dist/lib/ast/minify.d.ts +0 -19
- package/dist/lib/ast/transform/compute.d.ts +0 -8
- package/dist/lib/ast/transform/matrix.d.ts +0 -22
- package/dist/lib/ast/transform/minify.d.ts +0 -5
- package/dist/lib/ast/transform/perspective.d.ts +0 -3
- package/dist/lib/ast/transform/rotate.d.ts +0 -12
- package/dist/lib/ast/transform/scale.d.ts +0 -6
- package/dist/lib/ast/transform/skew.d.ts +0 -4
- package/dist/lib/ast/transform/translate.d.ts +0 -6
- package/dist/lib/ast/transform/utils.d.ts +0 -9
- package/dist/lib/ast/types.d.ts +0 -903
- package/dist/lib/ast/walk.d.ts +0 -162
- package/dist/lib/fs/resolve.d.ts +0 -20
- package/dist/lib/parser/declaration/list.d.ts +0 -16
- package/dist/lib/parser/declaration/map.d.ts +0 -15
- package/dist/lib/parser/declaration/set.d.ts +0 -9
- package/dist/lib/parser/node.d.ts +0 -7
- package/dist/lib/parser/parse.d.ts +0 -107
- package/dist/lib/parser/tokenize.d.ts +0 -57
- package/dist/lib/parser/utils/at-rule-container.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-font-feature-values.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-generic.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-import.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-media.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-page.js +0 -28
- package/dist/lib/parser/utils/at-rule-support.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule-token.d.ts +0 -1
- package/dist/lib/parser/utils/at-rule-when-else.d.ts +0 -5
- package/dist/lib/parser/utils/at-rule.d.ts +0 -13
- package/dist/lib/parser/utils/cache.d.ts +0 -6
- package/dist/lib/parser/utils/config.d.ts +0 -2
- package/dist/lib/parser/utils/declaration-list.d.ts +0 -5
- package/dist/lib/parser/utils/declaration.d.ts +0 -18
- package/dist/lib/parser/utils/eq.d.ts +0 -1
- package/dist/lib/parser/utils/hash.d.ts +0 -21
- package/dist/lib/parser/utils/selector.d.ts +0 -5
- package/dist/lib/parser/utils/text.d.ts +0 -3
- package/dist/lib/parser/utils/token.d.ts +0 -14
- package/dist/lib/parser/utils/type.d.ts +0 -2
- package/dist/lib/renderer/render.d.ts +0 -28
- package/dist/lib/renderer/sourcemap/lib/encode.d.ts +0 -1
- package/dist/lib/renderer/sourcemap/sourcemap.d.ts +0 -26
- package/dist/lib/syntax/color/a98rgb.d.ts +0 -2
- package/dist/lib/syntax/color/cmyk.d.ts +0 -10
- package/dist/lib/syntax/color/color-mix.d.ts +0 -2
- package/dist/lib/syntax/color/color.d.ts +0 -42
- package/dist/lib/syntax/color/hex.d.ts +0 -16
- package/dist/lib/syntax/color/hsl.d.ts +0 -20
- package/dist/lib/syntax/color/hsv.d.ts +0 -2
- package/dist/lib/syntax/color/hwb.d.ts +0 -21
- package/dist/lib/syntax/color/lab.d.ts +0 -25
- package/dist/lib/syntax/color/lch.d.ts +0 -23
- package/dist/lib/syntax/color/oklab.d.ts +0 -22
- package/dist/lib/syntax/color/oklch.d.ts +0 -20
- package/dist/lib/syntax/color/p3.d.ts +0 -6
- package/dist/lib/syntax/color/prophotorgb.d.ts +0 -2
- package/dist/lib/syntax/color/rec2020.d.ts +0 -2
- package/dist/lib/syntax/color/relativecolor.d.ts +0 -13
- package/dist/lib/syntax/color/rgb.d.ts +0 -20
- package/dist/lib/syntax/color/srgb.d.ts +0 -23
- package/dist/lib/syntax/color/utils/components.d.ts +0 -2
- package/dist/lib/syntax/color/utils/distance.d.ts +0 -18
- package/dist/lib/syntax/color/utils/matrix.d.ts +0 -6
- package/dist/lib/syntax/color/xyz.d.ts +0 -5
- package/dist/lib/syntax/color/xyzd50.d.ts +0 -4
- package/dist/lib/syntax/constants.d.ts +0 -67
- package/dist/lib/syntax/syntax.d.ts +0 -38
- package/dist/lib/validation/config.d.ts +0 -14
- package/dist/lib/validation/json.d.ts +0 -2
- package/dist/lib/validation/match.d.ts +0 -38
- package/dist/lib/validation/parser/parse.d.ts +0 -8
- package/dist/lib/validation/parser/typedef.d.ts +0 -95
- package/dist/lib/validation/utils/list.d.ts +0 -4
- package/dist/lib/validation/utils/whitespace.d.ts +0 -2
- package/dist/node.d.ts +0 -207
- package/dist/web.d.ts +0 -169
- package/playground/index.html +0 -1328
- package/playground/sw.js +0 -55
- package/playground/tree.js +0 -176
package/dist/lib/ast/walk.d.ts
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import type { AstNode, Token, WalkAttributesResult, WalkerFilter, WalkerValueFilter, WalkResult } from "../../@types/index.d.ts";
|
|
2
|
-
import { EnumToken } from "./types.ts";
|
|
3
|
-
/**
|
|
4
|
-
* options for the walk function
|
|
5
|
-
*/
|
|
6
|
-
export declare enum WalkerOptionEnum {
|
|
7
|
-
/**
|
|
8
|
-
* ignore the current node and its children
|
|
9
|
-
*/
|
|
10
|
-
Ignore = 1,
|
|
11
|
-
/**
|
|
12
|
-
* stop walking the tree
|
|
13
|
-
*/
|
|
14
|
-
Stop = 2,
|
|
15
|
-
/**
|
|
16
|
-
* ignore the current node and process its children
|
|
17
|
-
*/
|
|
18
|
-
Children = 4,
|
|
19
|
-
/**
|
|
20
|
-
* ignore the current node children
|
|
21
|
-
*/
|
|
22
|
-
IgnoreChildren = 8
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* event types for the walkValues function
|
|
26
|
-
*/
|
|
27
|
-
export declare enum WalkerEvent {
|
|
28
|
-
/**
|
|
29
|
-
* enter node
|
|
30
|
-
*/
|
|
31
|
-
Enter = 1,
|
|
32
|
-
/**
|
|
33
|
-
* leave node
|
|
34
|
-
*/
|
|
35
|
-
Leave = 2
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* walk ast nodes
|
|
39
|
-
* @param node initial node
|
|
40
|
-
* @param filter control the walk process
|
|
41
|
-
* @param reverse walk in reverse order
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
*
|
|
45
|
-
* import {walk} from '@tbela99/css-parser';
|
|
46
|
-
*
|
|
47
|
-
* const css = `
|
|
48
|
-
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
49
|
-
*
|
|
50
|
-
* html,
|
|
51
|
-
* body {
|
|
52
|
-
* line-height: 1.474;
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* .ruler {
|
|
56
|
-
*
|
|
57
|
-
* height: 10px;
|
|
58
|
-
* }
|
|
59
|
-
* `;
|
|
60
|
-
*
|
|
61
|
-
* for (const {node, parent, root} of walk(ast)) {
|
|
62
|
-
*
|
|
63
|
-
* // do something with node
|
|
64
|
-
* }
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* Using a {@link filter} function to control the ast traversal. the filter function returns a value of type {@link WalkerOption}.
|
|
68
|
-
*
|
|
69
|
-
* ```ts
|
|
70
|
-
* import {EnumToken, transform, walk, WalkerOptionEnum} from '@tbela99/css-parser';
|
|
71
|
-
*
|
|
72
|
-
* const css = `
|
|
73
|
-
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
74
|
-
*
|
|
75
|
-
* html,
|
|
76
|
-
* body {
|
|
77
|
-
* line-height: 1.474;
|
|
78
|
-
* }
|
|
79
|
-
*
|
|
80
|
-
* .ruler {
|
|
81
|
-
*
|
|
82
|
-
* height: 10px;
|
|
83
|
-
* }
|
|
84
|
-
* `;
|
|
85
|
-
*
|
|
86
|
-
* function filter(node) {
|
|
87
|
-
*
|
|
88
|
-
* if (node.typ == EnumToken.AstRule && node.sel.includes('html')) {
|
|
89
|
-
*
|
|
90
|
-
* // skip the children of the current node
|
|
91
|
-
* return WalkerOptionEnum.IgnoreChildren;
|
|
92
|
-
* }
|
|
93
|
-
* }
|
|
94
|
-
*
|
|
95
|
-
* const result = await transform(css);
|
|
96
|
-
* for (const {node} of walk(result.ast, filter)) {
|
|
97
|
-
*
|
|
98
|
-
* console.error([EnumToken[node.typ]]);
|
|
99
|
-
* }
|
|
100
|
-
*
|
|
101
|
-
* // [ "StyleSheetNodeType" ]
|
|
102
|
-
* // [ "RuleNodeType" ]
|
|
103
|
-
* // [ "DeclarationNodeType" ]
|
|
104
|
-
* // [ "RuleNodeType" ]
|
|
105
|
-
* // [ "DeclarationNodeType" ]
|
|
106
|
-
* // [ "RuleNodeType" ]
|
|
107
|
-
* // [ "DeclarationNodeType" ]
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
export declare function walk(node: AstNode, filter?: WalkerFilter | null, reverse?: boolean): Generator<WalkResult>;
|
|
111
|
-
/**
|
|
112
|
-
* walk ast node value tokens
|
|
113
|
-
* @param values
|
|
114
|
-
* @param root
|
|
115
|
-
* @param filter
|
|
116
|
-
* @param reverse
|
|
117
|
-
*
|
|
118
|
-
* Example:
|
|
119
|
-
*
|
|
120
|
-
* ```ts
|
|
121
|
-
*
|
|
122
|
-
* import {AstDeclaration, EnumToken, transform, walkValues} from '@tbela99/css-parser';
|
|
123
|
-
*
|
|
124
|
-
* const css = `
|
|
125
|
-
* body { color: color(from var(--base-color) display-p3 r calc(g + 0.24) calc(b + 0.15)); }
|
|
126
|
-
* `;
|
|
127
|
-
*
|
|
128
|
-
* const result = await transform(css);
|
|
129
|
-
* const declaration = result.ast.chi[0].chi[0] as AstDeclaration;
|
|
130
|
-
*
|
|
131
|
-
* // walk the node attribute's tokens in reverse order
|
|
132
|
-
* for (const {value} of walkValues(declaration.val, null, null,true)) {
|
|
133
|
-
*
|
|
134
|
-
* console.error([EnumToken[value.typ], value.val]);
|
|
135
|
-
* }
|
|
136
|
-
*
|
|
137
|
-
* // [ "Color", "color" ]
|
|
138
|
-
* // [ "FunctionTokenType", "calc" ]
|
|
139
|
-
* // [ "Number", 0.15 ]
|
|
140
|
-
* // [ "Add", undefined ]
|
|
141
|
-
* // [ "Iden", "b" ]
|
|
142
|
-
* // [ "Whitespace", undefined ]
|
|
143
|
-
* // [ "FunctionTokenType", "calc" ]
|
|
144
|
-
* // [ "Number", 0.24 ]
|
|
145
|
-
* // [ "Add", undefined ]
|
|
146
|
-
* // [ "Iden", "g" ]
|
|
147
|
-
* // [ "Whitespace", undefined ]
|
|
148
|
-
* // [ "Iden", "r" ]
|
|
149
|
-
* // [ "Whitespace", undefined ]
|
|
150
|
-
* // [ "Iden", "display-p3" ]
|
|
151
|
-
* // [ "Whitespace", undefined ]
|
|
152
|
-
* // [ "FunctionTokenType", "var" ]
|
|
153
|
-
* // [ "DashedIden", "--base-color" ]
|
|
154
|
-
* // [ "Whitespace", undefined ]
|
|
155
|
-
* // [ "Iden", "from" ]
|
|
156
|
-
* ```
|
|
157
|
-
*/
|
|
158
|
-
export declare function walkValues(values: Token[], root?: AstNode | Token | null, filter?: WalkerValueFilter | null | {
|
|
159
|
-
event?: WalkerEvent;
|
|
160
|
-
fn?: WalkerValueFilter;
|
|
161
|
-
type?: EnumToken | EnumToken[] | ((token: Token) => boolean);
|
|
162
|
-
}, reverse?: boolean): Generator<WalkAttributesResult>;
|
package/dist/lib/fs/resolve.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const matchUrl: RegExp;
|
|
2
|
-
/**
|
|
3
|
-
* return the directory name of a path
|
|
4
|
-
* @param path
|
|
5
|
-
*
|
|
6
|
-
* @private
|
|
7
|
-
*/
|
|
8
|
-
export declare function dirname(path: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* resolve path
|
|
11
|
-
* @param url url or path to resolve
|
|
12
|
-
* @param currentDirectory directory used to resolve the path
|
|
13
|
-
* @param cwd current working directory
|
|
14
|
-
*
|
|
15
|
-
* @private
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolve(url: string, currentDirectory: string, cwd?: string): {
|
|
18
|
-
absolute: string;
|
|
19
|
-
relative: string;
|
|
20
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { AstNode, PropertyListOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
import { PropertySet } from "./set.ts";
|
|
3
|
-
import { PropertyMap } from "./map.ts";
|
|
4
|
-
export declare class PropertyList {
|
|
5
|
-
protected options: PropertyListOptions;
|
|
6
|
-
protected declarations: Map<string, AstNode | PropertySet | PropertyMap>;
|
|
7
|
-
constructor(options?: PropertyListOptions);
|
|
8
|
-
set(nam: string, value: string | Token[]): this;
|
|
9
|
-
add(...declarations: AstNode[]): this;
|
|
10
|
-
[Symbol.iterator](): {
|
|
11
|
-
next(): {
|
|
12
|
-
value: AstNode;
|
|
13
|
-
done: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { AstDeclaration, ShorthandMapType } from "../../../@types/index.d.ts";
|
|
2
|
-
import { PropertySet } from "./set.ts";
|
|
3
|
-
export declare class PropertyMap {
|
|
4
|
-
protected config: ShorthandMapType;
|
|
5
|
-
protected declarations: Map<string, AstDeclaration | PropertySet>;
|
|
6
|
-
protected requiredCount: any;
|
|
7
|
-
protected pattern: string[];
|
|
8
|
-
constructor(config: ShorthandMapType);
|
|
9
|
-
add(declaration: AstDeclaration): this;
|
|
10
|
-
[Symbol.iterator](): ArrayIterator<AstDeclaration> | {
|
|
11
|
-
next(): IteratorResult<AstDeclaration>;
|
|
12
|
-
};
|
|
13
|
-
private matchTypes;
|
|
14
|
-
private removeDefaults;
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { AstDeclaration, ShorthandPropertyType } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare class PropertySet {
|
|
3
|
-
protected config: ShorthandPropertyType;
|
|
4
|
-
protected declarations: Map<string, AstDeclaration>;
|
|
5
|
-
constructor(config: ShorthandPropertyType);
|
|
6
|
-
add(declaration: AstDeclaration): this;
|
|
7
|
-
isShortHand(): boolean;
|
|
8
|
-
[Symbol.iterator](): IterableIterator<AstDeclaration>;
|
|
9
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { EnumToken } from "../ast/types.ts";
|
|
2
|
-
import type { AstAtRule, AstComment, AstDeclaration, AstInvalidAtRule, AstRule, AstStyleSheet, CssVariableImportTokenType, CssVariableToken, ErrorDescription, ParseResult, ParserOptions, ParseTokenOptions, Token, TokenizeResult } from "../../@types/index.d.ts";
|
|
3
|
-
export declare const trimWhiteSpace: EnumToken[];
|
|
4
|
-
export declare const atRulesMap: Map<string, EnumToken>;
|
|
5
|
-
/**
|
|
6
|
-
* short-scoped name generator.
|
|
7
|
-
*
|
|
8
|
-
* @param localName
|
|
9
|
-
* @param filePath
|
|
10
|
-
* @param pattern
|
|
11
|
-
* @param hashLength
|
|
12
|
-
*
|
|
13
|
-
* @returns string
|
|
14
|
-
*/
|
|
15
|
-
export declare const getShortNameGenerator: (...args: any[]) => any;
|
|
16
|
-
/**
|
|
17
|
-
* transform case of key name
|
|
18
|
-
* @param key
|
|
19
|
-
* @param how
|
|
20
|
-
*
|
|
21
|
-
* @throws Error
|
|
22
|
-
* @private
|
|
23
|
-
*/
|
|
24
|
-
export declare const getKeyName: (...args: any[]) => any;
|
|
25
|
-
/**
|
|
26
|
-
* generate scoped name
|
|
27
|
-
* @param localName
|
|
28
|
-
* @param filePath
|
|
29
|
-
* @param pattern
|
|
30
|
-
* @param hashLength
|
|
31
|
-
*
|
|
32
|
-
* @throws Error
|
|
33
|
-
* @private
|
|
34
|
-
*/
|
|
35
|
-
export declare const generateScopedName: (...args: any[]) => any;
|
|
36
|
-
/**
|
|
37
|
-
* parse css string
|
|
38
|
-
* @param iter
|
|
39
|
-
* @param options
|
|
40
|
-
*
|
|
41
|
-
* @throws Error
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
export declare function doParse(iter: Array<TokenizeResult> | Iterable<TokenizeResult> | AsyncGenerator<TokenizeResult>, options?: ParserOptions): Promise<ParseResult>;
|
|
45
|
-
/**mjgvgyikjkml,kmbm b8790u89y70
|
|
46
|
-
vbbnkit;;;jmjhyg77 * @param options
|
|
47
|
-
* @param errors
|
|
48
|
-
* @param parseAsBlock
|
|
49
|
-
*/
|
|
50
|
-
export declare function parseAtRule(stream: Token[], context: AstRule | AstAtRule | AstStyleSheet, options: ParserOptions, errors: ErrorDescription[], parseAsBlock?: boolean | null): AstAtRule | AstInvalidAtRule | CssVariableImportTokenType | CssVariableToken | null;
|
|
51
|
-
/**
|
|
52
|
-
* parse a string as an array of declaration nodes
|
|
53
|
-
* @param declaration
|
|
54
|
-
*
|
|
55
|
-
* Example:
|
|
56
|
-
* ````ts
|
|
57
|
-
*
|
|
58
|
-
* const declarations = await parseDeclarations('color: red; background: blue');
|
|
59
|
-
* console.log(declarations);
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare function parseDeclarations(declaration: string): Promise<Array<AstDeclaration | AstComment>>;
|
|
63
|
-
/**
|
|
64
|
-
* parse css string and return an array of tokens
|
|
65
|
-
* @param src
|
|
66
|
-
* @param options
|
|
67
|
-
*
|
|
68
|
-
* @private
|
|
69
|
-
*
|
|
70
|
-
* Example:
|
|
71
|
-
*
|
|
72
|
-
* ```ts
|
|
73
|
-
*
|
|
74
|
-
* import {parseString} from '@tbela99/css-parser';
|
|
75
|
-
*
|
|
76
|
-
* let tokens = parseString('body { color: red; }');
|
|
77
|
-
* console.log(tokens);
|
|
78
|
-
*
|
|
79
|
-
* tokens = parseString('#c322c980');
|
|
80
|
-
* console.log(tokens);
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare function parseString(src: string, options?: {
|
|
84
|
-
location: boolean;
|
|
85
|
-
src?: string;
|
|
86
|
-
}): Token[];
|
|
87
|
-
/**
|
|
88
|
-
* parse function tokens in a token array
|
|
89
|
-
* @param tokens
|
|
90
|
-
* @param options
|
|
91
|
-
*
|
|
92
|
-
* Example:
|
|
93
|
-
*
|
|
94
|
-
* ```ts
|
|
95
|
-
*
|
|
96
|
-
* import {parseString, parseTokens} from '@tbela99/css-parser';
|
|
97
|
-
*
|
|
98
|
-
* let tokens = parseString('body { color: red; }');
|
|
99
|
-
* console.log(parseTokens(tokens));
|
|
100
|
-
*
|
|
101
|
-
* tokens = parseString('#c322c980');
|
|
102
|
-
* console.log(parseTokens(tokens));
|
|
103
|
-
* ```
|
|
104
|
-
*
|
|
105
|
-
* @private
|
|
106
|
-
*/
|
|
107
|
-
export declare function parseTokens(tokens: Token[], options?: ParseTokenOptions): Token[];
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import type { ParseInfo, Position, Token, TokenizeResult } from "../../@types/index.d.ts";
|
|
2
|
-
import { EnumToken } from "../ast/types.ts";
|
|
3
|
-
export declare const SymbolsMapTokens: Record<string, EnumToken>;
|
|
4
|
-
export declare const hintsEnum: Set<EnumToken>;
|
|
5
|
-
export declare const enum TokenMap {
|
|
6
|
-
EXCLAMATION = 33,// '!', EXCLAMATION
|
|
7
|
-
SLASH = 47,// '/'
|
|
8
|
-
LOWERTHAN = 60,// '<', LESS THAN
|
|
9
|
-
HASH = 35,// '#', HASH
|
|
10
|
-
REVERSE_SOLIDUS = 92,// '\', REVERSE SOLIDUS
|
|
11
|
-
DOUBLE_QUOTE = 34,// '"', DOUBLEQ
|
|
12
|
-
SINGLE_QUOTE = 39,// "'", SINGLEQ
|
|
13
|
-
DOT = 46,// '.', DOT
|
|
14
|
-
AT = 64,// '@', AT
|
|
15
|
-
PIPE = 124,// '|', PIPE
|
|
16
|
-
EQUALS = 61,// '=', EQUALS
|
|
17
|
-
AMPERSAND = 38,// '&', AMPERSAND
|
|
18
|
-
STAR = 42,// '*', STAR
|
|
19
|
-
TILDA = 126,// '~', TILDA
|
|
20
|
-
CARET = 94,// '^', CARET
|
|
21
|
-
DOLLAR = 36,// '$', DOLLAR
|
|
22
|
-
COMMA = 44,// ',', COMMA
|
|
23
|
-
COLON = 58,// ':', COLON
|
|
24
|
-
SEMICOLON = 59,// ';', SEMICOLON
|
|
25
|
-
LEFT_PARENTHESIS = 40,// '(', LEFT PARENTHESIS
|
|
26
|
-
RIGHT_PARENTHESIS = 41,
|
|
27
|
-
LEFT_BRACKETS = 91,// '[', LEFT_BRACKETS
|
|
28
|
-
RIGHT_BRACKETS = 93,// ']', RIGHT_BRACKETS
|
|
29
|
-
LEFT_BRACE = 123,// '{', LEFT_BRACE
|
|
30
|
-
RIGHT_BRACE = 125,
|
|
31
|
-
PLUS = 43,// '+', PLUS
|
|
32
|
-
MINUS = 45,
|
|
33
|
-
GREATERTHAN = 62
|
|
34
|
-
}
|
|
35
|
-
export declare function consumeString(quoteStr: '"' | "'", buffer: string, parseInfo: ParseInfo): Array<TokenizeResult>;
|
|
36
|
-
export declare function getTokenType(val: string, hint?: EnumToken): Token;
|
|
37
|
-
export declare function yieldResult(val: string, parseInfo: ParseInfo, hint?: EnumToken): TokenizeResult;
|
|
38
|
-
export declare function match(parseInfo: ParseInfo, input: string): boolean;
|
|
39
|
-
export declare function peek(parseInfo: ParseInfo, count?: number): string;
|
|
40
|
-
export declare function next(parseInfo: ParseInfo, count?: number): string;
|
|
41
|
-
/**
|
|
42
|
-
* tokenize css string
|
|
43
|
-
* @param parseInfo
|
|
44
|
-
* @param yieldEOFToken
|
|
45
|
-
*/
|
|
46
|
-
export declare function tokenize(parseInfo: ParseInfo | string, yieldEOFToken?: boolean): Array<TokenizeResult>;
|
|
47
|
-
/**
|
|
48
|
-
* tokenize readable stream
|
|
49
|
-
* @param input
|
|
50
|
-
*/
|
|
51
|
-
export declare function tokenizeStream(input: ReadableStream<Uint8Array>, parseInfo?: ParseInfo): AsyncGenerator<TokenizeResult>;
|
|
52
|
-
/**
|
|
53
|
-
* Update position
|
|
54
|
-
* @param position
|
|
55
|
-
* @param str
|
|
56
|
-
*/
|
|
57
|
-
export declare function move(position: Position, str: string): void;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AstAtRule, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function parseAtRuleContainerQueryList(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ParserOptions, Token, AstAtRule, AtRuleToken } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function parseAtRuleFontFeatureValues(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: import("../../../@types/index.d.ts").ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AtRuleToken, ErrorDescription, ParserOptions, Token, ValidationOptions } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function matchGenericSyntax(atRule: AtRuleToken, stream: Token[], options: ParserOptions | ValidationOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AstAtRule, AstRule, AstStyleSheet, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function matchAtRuleImportSyntax(atRule: AtRuleToken, stream: Token[], context: AstRule | AstAtRule | AstStyleSheet, options: ParserOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AstAtRule, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function parseAtRulePage(context: AstAtRule | AtRuleToken, stream: Token[], options: ParserOptions, errors: ErrorDescription[]): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { EnumToken } from '../../ast/types.js';
|
|
2
|
-
import { getSyntaxRule } from '../../validation/config.js';
|
|
3
|
-
import { matchAllSyntax, createValidationContext } from '../../validation/match.js';
|
|
4
|
-
import { trimSyntaxArray } from '../../validation/parser/parse.js';
|
|
5
|
-
import { ValidationSyntaxGroupEnum } from '../../validation/parser/typedef.js';
|
|
6
|
-
|
|
7
|
-
function parseAtRulePage(context, stream, options, errors) {
|
|
8
|
-
const syntaxRules = getSyntaxRule(ValidationSyntaxGroupEnum.AtRules, "@page");
|
|
9
|
-
const syntax = syntaxRules?.getPreludeRules?.()?.slice?.(1);
|
|
10
|
-
let validate = false;
|
|
11
|
-
for (const token of stream) {
|
|
12
|
-
if (token.typ !== EnumToken.WhitespaceTokenType && token.typ !== EnumToken.CommentTokenType) {
|
|
13
|
-
validate = true;
|
|
14
|
-
break;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (!validate) {
|
|
18
|
-
return {
|
|
19
|
-
success: true,
|
|
20
|
-
errors,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
const result = matchAllSyntax(trimSyntaxArray(syntax), createValidationContext(stream), options);
|
|
24
|
-
errors.push(...result.errors);
|
|
25
|
-
return { success: result.success, errors };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { parseAtRulePage };
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Token, AstAtRule, ParserOptions, ErrorDescription, AtRuleToken } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function parseAtRuleSupportSyntax(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function parseAtRuleToken(): void;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { AstAtRule, AtRuleToken, ErrorDescription, ParserOptions, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function matchAtRuleWhenElseSyntax(stream: Token[], context: AstAtRule | AtRuleToken, options?: ParserOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { AtRuleToken, Token, ParserOptions, ValidationOptions } from "../../../@types/index.d.ts";
|
|
2
|
-
export declare function matchAtRuleSyntax(atRule: AtRuleToken, stream: Token[], options: ParserOptions | ValidationOptions): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: {
|
|
5
|
-
action: string;
|
|
6
|
-
message: string;
|
|
7
|
-
node: Token;
|
|
8
|
-
location: import("../../../@types/ast").Location;
|
|
9
|
-
}[];
|
|
10
|
-
} | {
|
|
11
|
-
success: boolean;
|
|
12
|
-
errors: import("../../../@types/index.d.ts").ErrorDescription[];
|
|
13
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { AstAtRule, AtRuleToken, Token, ParserOptions, ErrorDescription } from "../../../@types";
|
|
2
|
-
export declare function parseDeclarationList(context: AstAtRule | AtRuleToken, stream: Token[], options: ParserOptions, errors: ErrorDescription[]): {
|
|
3
|
-
success: boolean;
|
|
4
|
-
errors: ErrorDescription[];
|
|
5
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { AstAtRule, AstDeclaration, AstInvalidAtRule, AstInvalidDeclaration, AstInvalidRule, AstKeyFrameRule, AstRule, AstStyleSheet, AtRuleToken, ErrorDescription, ParserOptions, RawNodeToken, Token } from "../../../@types/index.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param tokens
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function isDeclarationValue(tokens: Token[]): {
|
|
8
|
-
success: boolean;
|
|
9
|
-
errors: ErrorDescription[];
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* parse declaration
|
|
13
|
-
* @param tokens
|
|
14
|
-
* @param parent
|
|
15
|
-
* @param options
|
|
16
|
-
* @param errors
|
|
17
|
-
*/
|
|
18
|
-
export declare function parseDeclaration(tokens: Token[], parent: AstRule | AstAtRule | AstKeyFrameRule | AstStyleSheet | AtRuleToken | AstInvalidAtRule | AstInvalidRule | null, options: ParserOptions, errors: ErrorDescription[]): AstDeclaration | AstInvalidDeclaration | RawNodeToken;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function eq(a: any, b: any): boolean;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare const LOWER = "abcdefghijklmnopqrstuvwxyz";
|
|
2
|
-
export declare const DIGITS = "0123456789";
|
|
3
|
-
export declare const FULL_ALPHABET: string[];
|
|
4
|
-
export declare const FIRST_ALPHABET: string[];
|
|
5
|
-
/**
|
|
6
|
-
* supported hash algorithms
|
|
7
|
-
*/
|
|
8
|
-
export declare const hashAlgorithms: string[];
|
|
9
|
-
/**
|
|
10
|
-
* generate a hash id
|
|
11
|
-
* @param input
|
|
12
|
-
* @param length
|
|
13
|
-
*/
|
|
14
|
-
export declare function hashId(input: string, length?: number): string;
|
|
15
|
-
/**
|
|
16
|
-
* generate a hash
|
|
17
|
-
* @param input
|
|
18
|
-
* @param length
|
|
19
|
-
* @param algo
|
|
20
|
-
*/
|
|
21
|
-
export declare function hash(input: string, length?: number, algo?: string): Promise<string>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Token, AstRule, AstAtRule, AstKeyFrameRule, AstKeyframesAtRule, AstStyleSheet, ParserOptions, ErrorDescription, AstInvalidRule, AtRuleToken } from "../../../@types/index.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* parse selector
|
|
4
|
-
*/
|
|
5
|
-
export declare function parseSelector(tokens: Token[], context: AtRuleToken | AstRule | AstAtRule | AstKeyFrameRule | AstKeyframesAtRule | AstStyleSheet | null, options: ParserOptions, errors: ErrorDescription[]): AstRule | AstInvalidRule | AstKeyFrameRule;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AstNode } from "../../../@types/ast.d.ts";
|
|
2
|
-
import type { BinaryExpressionToken, Token } from "../../../@types/token.d.ts";
|
|
3
|
-
/**
|
|
4
|
-
* replace token in its parent node
|
|
5
|
-
* @param parent
|
|
6
|
-
* @param value
|
|
7
|
-
* @param replacement
|
|
8
|
-
*/
|
|
9
|
-
export declare function replaceToken(parent: BinaryExpressionToken | (AstNode & ({
|
|
10
|
-
chi: Token[];
|
|
11
|
-
} | {
|
|
12
|
-
val: Token[];
|
|
13
|
-
})), value: Token, replacement: Token | Token[]): boolean;
|
|
14
|
-
export declare function trimWhiteSpaceTokens(tokens: Token[]): Token[];
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { AstNode, ErrorDescription, RenderOptions, RenderResult, Token } from "../../@types/index.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* render ast
|
|
4
|
-
* @param data
|
|
5
|
-
* @param options
|
|
6
|
-
* @param mapping
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export declare function doRender(data: AstNode, options?: RenderOptions, mapping?: {
|
|
10
|
-
mapping: Record<string, string>;
|
|
11
|
-
importMapping: Record<string, Record<string, string>> | null;
|
|
12
|
-
} | null): RenderResult;
|
|
13
|
-
/**
|
|
14
|
-
* render ast token
|
|
15
|
-
* @param token
|
|
16
|
-
* @param options
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
export declare function renderToken(token: Token, options?: RenderOptions, cache?: {
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}, reducer?: (acc: string, curr: Token) => string, errors?: ErrorDescription[]): string;
|
|
22
|
-
/**
|
|
23
|
-
* Remove whitespace tokens that are not needed
|
|
24
|
-
* @param values
|
|
25
|
-
*
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export declare function filterValues(values: Token[]): Token[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function encode(value: number | number[]): string;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { Location, SourceMapObject } from "../../../@types/index.d.ts";
|
|
2
|
-
/**
|
|
3
|
-
* Source map class
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
6
|
-
export declare class SourceMap {
|
|
7
|
-
#private;
|
|
8
|
-
/**
|
|
9
|
-
* Last location
|
|
10
|
-
*/
|
|
11
|
-
lastLocation: Location | null;
|
|
12
|
-
/**
|
|
13
|
-
* Add a location
|
|
14
|
-
* @param source
|
|
15
|
-
* @param original
|
|
16
|
-
*/
|
|
17
|
-
add(source: Location, original: Location): void;
|
|
18
|
-
/**
|
|
19
|
-
* Convert to URL encoded string
|
|
20
|
-
*/
|
|
21
|
-
toUrl(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Convert to JSON object
|
|
24
|
-
*/
|
|
25
|
-
toJSON(): SourceMapObject;
|
|
26
|
-
}
|