@tbela99/css-parser 0.9.1 → 1.1.0
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 +265 -0
- package/LICENSE.md +1 -1
- package/README.md +29 -17
- package/dist/index-umd-web.js +7461 -4360
- package/dist/index.cjs +8608 -5507
- package/dist/index.d.ts +203 -61
- package/dist/lib/ast/expand.js +2 -1
- package/dist/lib/ast/features/calc.js +19 -11
- package/dist/lib/ast/features/index.js +1 -0
- package/dist/lib/ast/features/inlinecssvariables.js +47 -29
- package/dist/lib/ast/features/prefix.js +117 -91
- package/dist/lib/ast/features/shorthand.js +34 -14
- package/dist/lib/ast/features/transform.js +67 -0
- package/dist/lib/ast/features/type.js +7 -0
- package/dist/lib/ast/math/expression.js +20 -10
- package/dist/lib/ast/math/math.js +20 -2
- package/dist/lib/ast/minify.js +209 -80
- package/dist/lib/ast/transform/compute.js +337 -0
- package/dist/lib/ast/transform/convert.js +33 -0
- package/dist/lib/ast/transform/matrix.js +112 -0
- package/dist/lib/ast/transform/minify.js +296 -0
- package/dist/lib/ast/transform/perspective.js +10 -0
- package/dist/lib/ast/transform/rotate.js +40 -0
- package/dist/lib/ast/transform/scale.js +32 -0
- package/dist/lib/ast/transform/skew.js +23 -0
- package/dist/lib/ast/transform/translate.js +32 -0
- package/dist/lib/ast/transform/utils.js +198 -0
- package/dist/lib/ast/types.js +18 -15
- package/dist/lib/ast/walk.js +54 -22
- package/dist/lib/fs/resolve.js +10 -0
- package/dist/lib/parser/declaration/list.js +48 -45
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +2 -1
- package/dist/lib/parser/parse.js +449 -340
- package/dist/lib/parser/tokenize.js +147 -72
- package/dist/lib/parser/utils/declaration.js +5 -4
- package/dist/lib/parser/utils/type.js +2 -1
- package/dist/lib/renderer/color/a98rgb.js +2 -1
- package/dist/lib/renderer/color/{colormix.js → color-mix.js} +16 -7
- package/dist/lib/renderer/color/color.js +264 -170
- package/dist/lib/renderer/color/hex.js +19 -8
- package/dist/lib/renderer/color/hsl.js +9 -3
- package/dist/lib/renderer/color/hwb.js +2 -1
- package/dist/lib/renderer/color/lab.js +10 -1
- package/dist/lib/renderer/color/lch.js +10 -1
- package/dist/lib/renderer/color/oklab.js +10 -1
- package/dist/lib/renderer/color/oklch.js +10 -1
- package/dist/lib/renderer/color/p3.js +2 -1
- package/dist/lib/renderer/color/rec2020.js +2 -1
- package/dist/lib/renderer/color/relativecolor.js +27 -32
- package/dist/lib/renderer/color/rgb.js +14 -10
- package/dist/lib/renderer/color/srgb.js +48 -23
- package/dist/lib/renderer/color/utils/components.js +18 -6
- package/dist/lib/renderer/color/utils/constants.js +47 -3
- package/dist/lib/renderer/color/xyz.js +2 -1
- package/dist/lib/renderer/color/xyzd50.js +2 -1
- package/dist/lib/renderer/render.js +108 -43
- package/dist/lib/syntax/syntax.js +267 -136
- package/dist/lib/validation/at-rules/container.js +81 -103
- package/dist/lib/validation/at-rules/counter-style.js +9 -8
- package/dist/lib/validation/at-rules/custom-media.js +13 -15
- package/dist/lib/validation/at-rules/document.js +22 -27
- package/dist/lib/validation/at-rules/font-feature-values.js +8 -8
- package/dist/lib/validation/at-rules/import.js +30 -81
- package/dist/lib/validation/at-rules/keyframes.js +19 -23
- package/dist/lib/validation/at-rules/layer.js +5 -5
- package/dist/lib/validation/at-rules/media.js +42 -53
- package/dist/lib/validation/at-rules/namespace.js +19 -23
- package/dist/lib/validation/at-rules/page-margin-box.js +15 -18
- package/dist/lib/validation/at-rules/page.js +8 -7
- package/dist/lib/validation/at-rules/supports.js +73 -82
- package/dist/lib/validation/at-rules/when.js +32 -36
- package/dist/lib/validation/atrule.js +15 -18
- package/dist/lib/validation/config.js +24 -1
- package/dist/lib/validation/config.json.js +563 -63
- package/dist/lib/validation/parser/parse.js +196 -185
- package/dist/lib/validation/parser/types.js +1 -1
- package/dist/lib/validation/selector.js +8 -5
- package/dist/lib/validation/syntax.js +724 -1405
- package/dist/lib/validation/syntaxes/complex-selector-list.js +10 -11
- package/dist/lib/validation/syntaxes/complex-selector.js +10 -11
- package/dist/lib/validation/syntaxes/compound-selector.js +40 -50
- package/dist/lib/validation/syntaxes/family-name.js +9 -8
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +6 -5
- package/dist/lib/validation/syntaxes/keyframe-selector.js +23 -105
- package/dist/lib/validation/syntaxes/layer-name.js +6 -5
- package/dist/lib/validation/syntaxes/relative-selector-list.js +7 -6
- package/dist/lib/validation/syntaxes/relative-selector.js +17 -15
- package/dist/lib/validation/syntaxes/url.js +18 -22
- package/dist/lib/validation/utils/list.js +20 -2
- package/dist/lib/validation/utils/whitespace.js +2 -1
- package/dist/node/index.js +4 -2
- package/dist/node/load.js +6 -1
- package/dist/web/index.js +4 -2
- package/dist/web/load.js +5 -0
- package/package.json +16 -15
- package/dist/lib/renderer/color/prophotoRgb.js +0 -56
- package/dist/lib/validation/declaration.js +0 -94
- package/dist/lib/validation/syntaxes/image.js +0 -29
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var WalkerOptionEnum;
|
|
2
|
+
(function (WalkerOptionEnum) {
|
|
3
|
+
WalkerOptionEnum[WalkerOptionEnum["Ignore"] = 0] = "Ignore";
|
|
4
|
+
WalkerOptionEnum[WalkerOptionEnum["Stop"] = 1] = "Stop";
|
|
5
|
+
WalkerOptionEnum[WalkerOptionEnum["Children"] = 2] = "Children";
|
|
6
|
+
WalkerOptionEnum[WalkerOptionEnum["IgnoreChildren"] = 3] = "IgnoreChildren";
|
|
7
|
+
})(WalkerOptionEnum || (WalkerOptionEnum = {}));
|
|
3
8
|
var WalkerValueEvent;
|
|
4
9
|
(function (WalkerValueEvent) {
|
|
5
10
|
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
@@ -18,10 +23,10 @@ function* walk(node, filter) {
|
|
|
18
23
|
let option = null;
|
|
19
24
|
if (filter != null) {
|
|
20
25
|
option = filter(node);
|
|
21
|
-
if (option ===
|
|
26
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
22
27
|
continue;
|
|
23
28
|
}
|
|
24
|
-
if (option ===
|
|
29
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
25
30
|
break;
|
|
26
31
|
}
|
|
27
32
|
}
|
|
@@ -30,7 +35,7 @@ function* walk(node, filter) {
|
|
|
30
35
|
// @ts-ignore
|
|
31
36
|
yield { node, parent: map.get(node), root };
|
|
32
37
|
}
|
|
33
|
-
if (option !==
|
|
38
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in node) {
|
|
34
39
|
parents.unshift(...node.chi);
|
|
35
40
|
for (const child of node.chi.slice()) {
|
|
36
41
|
map.set(child, node);
|
|
@@ -39,7 +44,7 @@ function* walk(node, filter) {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
/**
|
|
42
|
-
* walk ast
|
|
47
|
+
* walk ast node value tokens
|
|
43
48
|
* @param values
|
|
44
49
|
* @param root
|
|
45
50
|
* @param filter
|
|
@@ -62,19 +67,20 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
62
67
|
event: WalkerValueEvent.Enter
|
|
63
68
|
};
|
|
64
69
|
}
|
|
70
|
+
const eventType = filter.event ?? WalkerValueEvent.Enter;
|
|
65
71
|
while (stack.length > 0) {
|
|
66
72
|
let value = reverse ? stack.pop() : stack.shift();
|
|
67
73
|
let option = null;
|
|
68
|
-
if (filter.fn != null &&
|
|
74
|
+
if (filter.fn != null && eventType == WalkerValueEvent.Enter) {
|
|
69
75
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
70
76
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
71
77
|
(typeof filter.type == 'function' && filter.type(value));
|
|
72
78
|
if (isValid) {
|
|
73
|
-
option = filter.fn(value, map.get(value) ?? root
|
|
74
|
-
if (option ===
|
|
79
|
+
option = filter.fn(value, map.get(value) ?? root);
|
|
80
|
+
if (option === WalkerOptionEnum.Ignore) {
|
|
75
81
|
continue;
|
|
76
82
|
}
|
|
77
|
-
if (option ===
|
|
83
|
+
if (option === WalkerOptionEnum.Stop) {
|
|
78
84
|
break;
|
|
79
85
|
}
|
|
80
86
|
// @ts-ignore
|
|
@@ -83,8 +89,7 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
|
|
92
|
+
if (eventType == WalkerValueEvent.Enter && option !== WalkerOptionEnum.Children) {
|
|
88
93
|
yield {
|
|
89
94
|
value,
|
|
90
95
|
parent: map.get(value) ?? root,
|
|
@@ -94,7 +99,7 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
94
99
|
root: root ?? null
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
|
-
if (option !==
|
|
102
|
+
if (option !== WalkerOptionEnum.IgnoreChildren && 'chi' in value) {
|
|
98
103
|
const sliced = value.chi.slice();
|
|
99
104
|
for (const child of sliced) {
|
|
100
105
|
map.set(child, value);
|
|
@@ -106,25 +111,52 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
106
111
|
stack.unshift(...sliced);
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
else
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
else {
|
|
115
|
+
const values = [];
|
|
116
|
+
if ('l' in value && value.l != null) {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
values.push(value.l);
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
map.set(value.l, value);
|
|
121
|
+
}
|
|
122
|
+
if ('op' in value && typeof value.op == 'object') {
|
|
123
|
+
values.push(value.op);
|
|
124
|
+
// @ts-ignore
|
|
125
|
+
map.set(value.op, value);
|
|
126
|
+
}
|
|
127
|
+
if ('r' in value && value.r != null) {
|
|
128
|
+
if (Array.isArray(value.r)) {
|
|
129
|
+
for (const r of value.r) {
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
values.push(r);
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
map.set(r, value);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
values.push(value.r);
|
|
139
|
+
// @ts-ignore
|
|
140
|
+
map.set(value.r, value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (values.length > 0) {
|
|
144
|
+
stack.unshift(...values);
|
|
145
|
+
}
|
|
113
146
|
}
|
|
114
|
-
if (
|
|
147
|
+
if (eventType == WalkerValueEvent.Leave && filter.fn != null) {
|
|
115
148
|
const isValid = filter.type == null || value.typ == filter.type ||
|
|
116
149
|
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
117
150
|
(typeof filter.type == 'function' && filter.type(value));
|
|
118
151
|
if (isValid) {
|
|
119
|
-
option = filter.fn(value, map.get(value)
|
|
152
|
+
option = filter.fn(value, map.get(value));
|
|
120
153
|
// @ts-ignore
|
|
121
154
|
if (option != null && 'typ' in option) {
|
|
122
155
|
map.set(option, map.get(value) ?? root);
|
|
123
156
|
}
|
|
124
157
|
}
|
|
125
158
|
}
|
|
126
|
-
|
|
127
|
-
if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
|
|
159
|
+
if (eventType == WalkerValueEvent.Leave && option !== WalkerOptionEnum.Children) {
|
|
128
160
|
yield {
|
|
129
161
|
value,
|
|
130
162
|
parent: map.get(value) ?? root,
|
|
@@ -138,4 +170,4 @@ function* walkValues(values, root = null, filter, reverse) {
|
|
|
138
170
|
}
|
|
139
171
|
}
|
|
140
172
|
|
|
141
|
-
export { WalkerValueEvent, walk, walkValues };
|
|
173
|
+
export { WalkerOptionEnum, WalkerValueEvent, walk, walkValues };
|
package/dist/lib/fs/resolve.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
const matchUrl = /^(https?:)?\/\//;
|
|
2
|
+
/**
|
|
3
|
+
* return the directory name of a path
|
|
4
|
+
* @param path
|
|
5
|
+
*/
|
|
2
6
|
function dirname(path) {
|
|
3
7
|
if (path == '/' || path === '') {
|
|
4
8
|
return path;
|
|
@@ -47,6 +51,12 @@ function splitPath(result) {
|
|
|
47
51
|
}
|
|
48
52
|
return { parts, i };
|
|
49
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* resolve path
|
|
56
|
+
* @param url
|
|
57
|
+
* @param currentDirectory
|
|
58
|
+
* @param cwd
|
|
59
|
+
*/
|
|
50
60
|
function resolve(url, currentDirectory, cwd) {
|
|
51
61
|
if (matchUrl.test(url)) {
|
|
52
62
|
return {
|
|
@@ -4,6 +4,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
5
|
import '../../ast/walk.js';
|
|
6
6
|
import { parseString } from '../parse.js';
|
|
7
|
+
import '../tokenize.js';
|
|
7
8
|
import '../../renderer/color/utils/constants.js';
|
|
8
9
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
9
10
|
import { PropertyMap } from './map.js';
|
|
@@ -23,61 +24,63 @@ class PropertyList {
|
|
|
23
24
|
val: Array.isArray(value) ? value : parseString(String(value))
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
add(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if ('map' in config.properties[propertyName]) {
|
|
41
|
-
shortHandType = 'map';
|
|
27
|
+
add(...declarations) {
|
|
28
|
+
for (const declaration of declarations) {
|
|
29
|
+
if (declaration.typ != EnumToken.DeclarationNodeType || !this.options.removeDuplicateDeclarations) {
|
|
30
|
+
this.declarations.set(Number(Math.random().toString().slice(2)).toString(36), declaration);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (!this.options.computeShorthand) {
|
|
34
|
+
this.declarations.set(declaration.nam, declaration);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
let propertyName = declaration.nam;
|
|
38
|
+
let shortHandType;
|
|
39
|
+
let shorthand;
|
|
40
|
+
if (propertyName in config.properties) {
|
|
42
41
|
// @ts-ignore
|
|
43
|
-
|
|
42
|
+
if ('map' in config.properties[propertyName]) {
|
|
43
|
+
shortHandType = 'map';
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
shorthand = config.properties[propertyName].map;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
shortHandType = 'set';
|
|
49
|
+
// @ts-ignore
|
|
50
|
+
shorthand = config.properties[propertyName].shorthand;
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
|
-
else {
|
|
46
|
-
shortHandType = '
|
|
53
|
+
else if (propertyName in config.map) {
|
|
54
|
+
shortHandType = 'map';
|
|
47
55
|
// @ts-ignore
|
|
48
|
-
shorthand = config.
|
|
56
|
+
shorthand = config.map[propertyName].shorthand;
|
|
49
57
|
}
|
|
50
|
-
}
|
|
51
|
-
else if (propertyName in config.map) {
|
|
52
|
-
shortHandType = 'map';
|
|
53
58
|
// @ts-ignore
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
if (shortHandType == 'map') {
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
if (!this.declarations.has(shorthand)) {
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
this.declarations.set(shorthand, new PropertyMap(config.map[shorthand]));
|
|
64
|
+
}
|
|
60
65
|
// @ts-ignore
|
|
61
|
-
this.declarations.
|
|
66
|
+
this.declarations.get(shorthand).add(declaration);
|
|
67
|
+
// return this;
|
|
62
68
|
}
|
|
63
69
|
// @ts-ignore
|
|
64
|
-
|
|
65
|
-
// return this;
|
|
66
|
-
}
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
else if (shortHandType == 'set') {
|
|
69
|
-
// @ts-ignore
|
|
70
|
-
// const shorthand: string = <string>config.properties[propertyName].shorthand;
|
|
71
|
-
if (!this.declarations.has(shorthand)) {
|
|
70
|
+
else if (shortHandType == 'set') {
|
|
72
71
|
// @ts-ignore
|
|
73
|
-
|
|
72
|
+
// const shorthand: string = <string>config.properties[propertyName].shorthand;
|
|
73
|
+
if (!this.declarations.has(shorthand)) {
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
this.declarations.set(shorthand, new PropertySet(config.properties[shorthand]));
|
|
76
|
+
}
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
this.declarations.get(shorthand).add(declaration);
|
|
79
|
+
// return this;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
this.declarations.set(propertyName, declaration);
|
|
74
83
|
}
|
|
75
|
-
// @ts-ignore
|
|
76
|
-
this.declarations.get(shorthand).add(declaration);
|
|
77
|
-
// return this;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.declarations.set(propertyName, declaration);
|
|
81
84
|
}
|
|
82
85
|
return this;
|
|
83
86
|
}
|
|
@@ -5,6 +5,7 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
5
5
|
import '../../ast/minify.js';
|
|
6
6
|
import '../../ast/walk.js';
|
|
7
7
|
import { parseString } from '../parse.js';
|
|
8
|
+
import '../tokenize.js';
|
|
8
9
|
import { renderToken } from '../../renderer/render.js';
|
|
9
10
|
import '../../renderer/color/utils/constants.js';
|
|
10
11
|
import { PropertySet } from './set.js';
|
|
@@ -3,8 +3,9 @@ import { EnumToken } from '../../ast/types.js';
|
|
|
3
3
|
import '../../ast/minify.js';
|
|
4
4
|
import '../../ast/walk.js';
|
|
5
5
|
import '../parse.js';
|
|
6
|
-
import
|
|
6
|
+
import '../tokenize.js';
|
|
7
7
|
import '../utils/config.js';
|
|
8
|
+
import { isLength } from '../../syntax/syntax.js';
|
|
8
9
|
import '../../renderer/color/utils/constants.js';
|
|
9
10
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
10
11
|
|