@tbela99/css-parser 0.7.0 → 0.8.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/README.md +142 -81
- package/dist/index-umd-web.js +7027 -51519
- package/dist/index.cjs +7022 -51515
- package/dist/index.d.ts +189 -60
- package/dist/lib/ast/expand.js +87 -2
- package/dist/lib/ast/features/calc.js +76 -12
- package/dist/lib/ast/features/inlinecssvariables.js +6 -1
- package/dist/lib/ast/features/prefix.js +17 -9
- package/dist/lib/ast/features/shorthand.js +1 -0
- package/dist/lib/ast/math/expression.js +299 -11
- package/dist/lib/ast/math/math.js +7 -1
- package/dist/lib/ast/minify.js +1 -1
- package/dist/lib/ast/types.js +58 -49
- package/dist/lib/ast/walk.js +80 -18
- package/dist/lib/parser/declaration/list.js +1 -0
- package/dist/lib/parser/declaration/map.js +1 -0
- package/dist/lib/parser/declaration/set.js +1 -0
- package/dist/lib/parser/parse.js +285 -72
- package/dist/lib/parser/tokenize.js +23 -3
- package/dist/lib/parser/utils/declaration.js +2 -2
- package/dist/lib/parser/utils/type.js +6 -6
- package/dist/lib/renderer/color/a98rgb.js +1 -0
- package/dist/lib/renderer/color/color.js +1 -0
- package/dist/lib/renderer/color/colormix.js +1 -0
- package/dist/lib/renderer/color/hex.js +1 -0
- package/dist/lib/renderer/color/hsl.js +1 -0
- package/dist/lib/renderer/color/hwb.js +1 -0
- package/dist/lib/renderer/color/lab.js +1 -0
- package/dist/lib/renderer/color/lch.js +1 -0
- package/dist/lib/renderer/color/oklab.js +1 -0
- package/dist/lib/renderer/color/oklch.js +1 -0
- package/dist/lib/renderer/color/p3.js +1 -0
- package/dist/lib/renderer/color/prophotoRgb.js +56 -0
- package/dist/lib/renderer/color/rec2020.js +1 -0
- package/dist/lib/renderer/color/relativecolor.js +52 -28
- package/dist/lib/renderer/color/rgb.js +1 -0
- package/dist/lib/renderer/color/srgb.js +1 -0
- package/dist/lib/renderer/color/utils/components.js +1 -0
- package/dist/lib/renderer/color/utils/constants.js +1 -0
- package/dist/lib/renderer/color/xyz.js +1 -0
- package/dist/lib/renderer/color/xyzd50.js +1 -0
- package/dist/lib/renderer/render.js +28 -6
- package/dist/lib/syntax/syntax.js +27 -4
- package/dist/lib/validation/at-rules/counter-style.js +78 -0
- package/dist/lib/validation/at-rules/document.js +114 -0
- package/dist/lib/validation/at-rules/font-feature-values.js +49 -0
- package/dist/lib/validation/at-rules/import.js +196 -0
- package/dist/lib/validation/at-rules/keyframes.js +70 -0
- package/dist/lib/validation/at-rules/layer.js +27 -0
- package/dist/lib/validation/at-rules/media.js +166 -0
- package/dist/lib/validation/at-rules/namespace.js +85 -0
- package/dist/lib/validation/at-rules/page-margin-box.js +56 -0
- package/dist/lib/validation/at-rules/page.js +88 -0
- package/dist/lib/validation/at-rules/supports.js +262 -0
- package/dist/lib/validation/atrule.js +172 -0
- package/dist/lib/validation/config.js +30 -2
- package/dist/lib/validation/config.json.js +1560 -50902
- package/dist/lib/validation/declaration.js +72 -0
- package/dist/lib/validation/parser/parse.js +1059 -7
- package/dist/lib/validation/parser/types.js +27 -12
- package/dist/lib/validation/selector.js +23 -444
- package/dist/lib/validation/syntax.js +1429 -0
- package/dist/lib/validation/syntaxes/complex-selector-list.js +41 -0
- package/dist/lib/validation/syntaxes/complex-selector.js +283 -0
- package/dist/lib/validation/syntaxes/family-name.js +91 -0
- package/dist/lib/validation/syntaxes/keyframe-block-list.js +27 -0
- package/dist/lib/validation/syntaxes/keyframe-selector.js +137 -0
- package/dist/lib/validation/syntaxes/layer-name.js +67 -0
- package/dist/lib/validation/syntaxes/relative-selector-list.js +27 -0
- package/dist/lib/validation/syntaxes/relative-selector.js +36 -0
- package/dist/lib/validation/syntaxes/selector-list.js +5 -0
- package/dist/lib/validation/syntaxes/selector.js +5 -0
- package/dist/lib/validation/syntaxes/url.js +75 -0
- package/dist/lib/validation/utils/list.js +24 -0
- package/dist/lib/validation/utils/whitespace.js +22 -0
- package/dist/node/index.js +13 -0
- package/dist/web/index.js +13 -0
- package/dist/web/load.js +1 -0
- package/package.json +17 -15
- package/dist/lib/ast/utils/minifyfeature.js +0 -9
- package/dist/lib/iterable/weakset.js +0 -58
- package/dist/lib/parser/utils/syntax.js +0 -450
package/dist/lib/ast/walk.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { EnumToken } from './types.js';
|
|
2
2
|
|
|
3
|
+
var WalkerValueEvent;
|
|
4
|
+
(function (WalkerValueEvent) {
|
|
5
|
+
WalkerValueEvent[WalkerValueEvent["Enter"] = 0] = "Enter";
|
|
6
|
+
WalkerValueEvent[WalkerValueEvent["Leave"] = 1] = "Leave";
|
|
7
|
+
})(WalkerValueEvent || (WalkerValueEvent = {}));
|
|
3
8
|
function* walk(node, filter) {
|
|
4
9
|
const parents = [node];
|
|
5
10
|
const root = node;
|
|
@@ -28,40 +33,97 @@ function* walk(node, filter) {
|
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
|
-
function* walkValues(values, root = null, filter) {
|
|
36
|
+
function* walkValues(values, root = null, filter, reverse) {
|
|
37
|
+
// const set = new Set<Token>();
|
|
32
38
|
const stack = values.slice();
|
|
33
39
|
const map = new Map;
|
|
34
|
-
let value;
|
|
35
40
|
let previous = null;
|
|
36
|
-
|
|
41
|
+
// let parent: FunctionToken | ParensToken | BinaryExpressionToken | null = null;
|
|
42
|
+
if (filter != null && typeof filter == 'function') {
|
|
43
|
+
filter = {
|
|
44
|
+
event: WalkerValueEvent.Enter,
|
|
45
|
+
fn: filter
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else if (filter == null) {
|
|
49
|
+
filter = {
|
|
50
|
+
event: WalkerValueEvent.Enter
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
while (stack.length > 0) {
|
|
54
|
+
let value = reverse ? stack.pop() : stack.shift();
|
|
37
55
|
let option = null;
|
|
38
|
-
if (filter != null) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
if (filter.fn != null && filter.event == WalkerValueEvent.Enter) {
|
|
57
|
+
const isValid = filter.type == null || value.typ == filter.type ||
|
|
58
|
+
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
59
|
+
(typeof filter.type == 'function' && filter.type(value));
|
|
60
|
+
if (isValid) {
|
|
61
|
+
option = filter.fn(value, map.get(value) ?? root, WalkerValueEvent.Enter);
|
|
62
|
+
if (option === 'ignore') {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (option === 'stop') {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
if (option != null && typeof option == 'object' && 'typ' in option) {
|
|
70
|
+
map.set(option, map.get(value) ?? root);
|
|
71
|
+
}
|
|
45
72
|
}
|
|
46
73
|
}
|
|
47
74
|
// @ts-ignore
|
|
48
|
-
if (option !== 'children') {
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
if (filter.event == WalkerValueEvent.Enter && option !== 'children') {
|
|
76
|
+
yield {
|
|
77
|
+
value,
|
|
78
|
+
parent: map.get(value) ?? root,
|
|
79
|
+
previousValue: previous,
|
|
80
|
+
nextValue: stack[0] ?? null,
|
|
81
|
+
// @ts-ignore
|
|
82
|
+
root: root ?? null
|
|
83
|
+
};
|
|
51
84
|
}
|
|
52
85
|
if (option !== 'ignore-children' && 'chi' in value) {
|
|
53
|
-
|
|
86
|
+
const sliced = value.chi.slice();
|
|
87
|
+
for (const child of sliced) {
|
|
54
88
|
map.set(child, value);
|
|
55
89
|
}
|
|
56
|
-
|
|
90
|
+
if (reverse) {
|
|
91
|
+
stack.push(...sliced);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
stack.unshift(...sliced);
|
|
95
|
+
}
|
|
57
96
|
}
|
|
58
97
|
else if (value.typ == EnumToken.BinaryExpressionTokenType) {
|
|
59
|
-
map.set(value.l, value);
|
|
60
|
-
map.set(value.r, value);
|
|
98
|
+
map.set(value.l, map.get(value) ?? root);
|
|
99
|
+
map.set(value.r, map.get(value) ?? root);
|
|
61
100
|
stack.unshift(value.l, value.r);
|
|
62
101
|
}
|
|
102
|
+
if (filter.event == WalkerValueEvent.Leave && filter.fn != null) {
|
|
103
|
+
const isValid = filter.type == null || value.typ == filter.type ||
|
|
104
|
+
(Array.isArray(filter.type) && filter.type.includes(value.typ)) ||
|
|
105
|
+
(typeof filter.type == 'function' && filter.type(value));
|
|
106
|
+
if (isValid) {
|
|
107
|
+
option = filter.fn(value, map.get(value), WalkerValueEvent.Leave);
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
if (option != null && 'typ' in option) {
|
|
110
|
+
map.set(option, map.get(value) ?? root);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
if (filter.event == WalkerValueEvent.Leave && option !== 'children') {
|
|
116
|
+
yield {
|
|
117
|
+
value,
|
|
118
|
+
parent: map.get(value) ?? root,
|
|
119
|
+
previousValue: previous,
|
|
120
|
+
nextValue: stack[0] ?? null,
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
root: root ?? null
|
|
123
|
+
};
|
|
124
|
+
}
|
|
63
125
|
previous = value;
|
|
64
126
|
}
|
|
65
127
|
}
|
|
66
128
|
|
|
67
|
-
export { walk, walkValues };
|
|
129
|
+
export { WalkerValueEvent, walk, walkValues };
|
|
@@ -2,6 +2,7 @@ import { PropertySet } from './set.js';
|
|
|
2
2
|
import { getConfig } from '../utils/config.js';
|
|
3
3
|
import { EnumToken } from '../../ast/types.js';
|
|
4
4
|
import '../../ast/minify.js';
|
|
5
|
+
import '../../ast/walk.js';
|
|
5
6
|
import { parseString } from '../parse.js';
|
|
6
7
|
import '../../renderer/color/utils/constants.js';
|
|
7
8
|
import '../../renderer/sourcemap/lib/encode.js';
|
|
@@ -3,6 +3,7 @@ import { getConfig } from '../utils/config.js';
|
|
|
3
3
|
import { matchType } from '../utils/type.js';
|
|
4
4
|
import { EnumToken } from '../../ast/types.js';
|
|
5
5
|
import '../../ast/minify.js';
|
|
6
|
+
import '../../ast/walk.js';
|
|
6
7
|
import { parseString } from '../parse.js';
|
|
7
8
|
import { renderToken } from '../../renderer/render.js';
|
|
8
9
|
import '../../renderer/color/utils/constants.js';
|