@projectwallace/css-layer-tree 2.1.0 → 2.1.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/dist/css-layer-tree.js +66 -60
- package/package.json +1 -1
package/dist/css-layer-tree.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { traverse as g, AT_RULE as m, LAYER_NAME as
|
|
2
|
-
class
|
|
1
|
+
import { traverse as g, AT_RULE as m, LAYER_NAME as _, parse as b } from "@projectwallace/css-parser";
|
|
2
|
+
class p {
|
|
3
3
|
/** @param {string} name */
|
|
4
|
-
constructor(
|
|
5
|
-
this.name =
|
|
4
|
+
constructor(l) {
|
|
5
|
+
this.name = l, this.is_anonymous = !1, this.children = /* @__PURE__ */ new Map(), this.locations = [];
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* @param {string[]} path
|
|
9
9
|
* @param {string} name
|
|
10
10
|
* @param {T} location
|
|
11
11
|
*/
|
|
12
|
-
add_child(
|
|
13
|
-
let
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
}),
|
|
17
|
-
|
|
12
|
+
add_child(l, i, c) {
|
|
13
|
+
let s = this;
|
|
14
|
+
if (l.forEach((e) => {
|
|
15
|
+
s = s.children.get(e);
|
|
16
|
+
}), s.children.has(i))
|
|
17
|
+
c !== void 0 && s.children.get(i).locations.push(c);
|
|
18
18
|
else {
|
|
19
|
-
const e = new
|
|
20
|
-
|
|
19
|
+
const e = new p(i);
|
|
20
|
+
c !== void 0 && e.locations.push(c), e.is_anonymous = i.startsWith("__anonymous"), s.children.set(i, e);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -36,59 +36,67 @@ class _ {
|
|
|
36
36
|
name: this.name,
|
|
37
37
|
is_anonymous: this.is_anonymous,
|
|
38
38
|
locations: this.locations,
|
|
39
|
-
children: Array.from(this.children.values(), (
|
|
39
|
+
children: Array.from(this.children.values(), (l) => l.to_plain_object())
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function
|
|
44
|
-
return
|
|
43
|
+
function d(a) {
|
|
44
|
+
return a.split(".").map((l) => l.trim());
|
|
45
45
|
}
|
|
46
|
-
function u(
|
|
46
|
+
function u(a) {
|
|
47
47
|
return {
|
|
48
|
-
line:
|
|
49
|
-
column:
|
|
50
|
-
start:
|
|
51
|
-
end:
|
|
48
|
+
line: a.line,
|
|
49
|
+
column: a.column,
|
|
50
|
+
start: a.start,
|
|
51
|
+
end: a.end
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
function k(
|
|
55
|
-
let
|
|
56
|
-
function
|
|
57
|
-
return
|
|
54
|
+
function k(a) {
|
|
55
|
+
let l = [], i = new p("root"), c = 0;
|
|
56
|
+
function s() {
|
|
57
|
+
return c++, `__anonymous-${c}__`;
|
|
58
58
|
}
|
|
59
|
-
return g(
|
|
59
|
+
return g(a, {
|
|
60
60
|
enter(e) {
|
|
61
61
|
if (e.type === m) {
|
|
62
62
|
if (e.name === "layer")
|
|
63
63
|
if (e.prelude) {
|
|
64
|
-
let
|
|
65
|
-
if (e.has_block)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
for (let
|
|
70
|
-
let o =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
let n = e.prelude.text.split(",").map((t) => t.trim());
|
|
65
|
+
if (e.has_block) {
|
|
66
|
+
let t = [];
|
|
67
|
+
for (let r of e.prelude.children)
|
|
68
|
+
r.type === _ && t.push(r.text);
|
|
69
|
+
for (let r = 0; r < t.length; r++) {
|
|
70
|
+
let o = t[r];
|
|
71
|
+
if (!o) continue;
|
|
72
|
+
let h = t.slice(0, r), f = r === t.length - 1 ? u(e) : void 0;
|
|
73
|
+
i.add_child(l.concat(h), o, f);
|
|
74
|
+
}
|
|
75
|
+
l.push(...t);
|
|
76
|
+
} else
|
|
77
|
+
for (let t of n) {
|
|
78
|
+
let r = d(t);
|
|
79
|
+
for (let o = 0; o < r.length; o++) {
|
|
80
|
+
let h = r.slice(0, o), f = r[o];
|
|
81
|
+
if (f) {
|
|
82
|
+
let y = o === r.length - 1 ? u(e) : void 0;
|
|
83
|
+
i.add_child(h, f, y);
|
|
76
84
|
}
|
|
77
85
|
}
|
|
78
86
|
}
|
|
79
87
|
} else {
|
|
80
|
-
let
|
|
81
|
-
|
|
88
|
+
let n = s();
|
|
89
|
+
i.add_child(l, n, u(e)), l.push(n);
|
|
82
90
|
}
|
|
83
91
|
else if (e.name === "import" && e.prelude) {
|
|
84
|
-
for (let
|
|
85
|
-
if (
|
|
86
|
-
if (
|
|
87
|
-
for (let
|
|
88
|
-
|
|
92
|
+
for (let n of e.prelude.children)
|
|
93
|
+
if (n.type === _) {
|
|
94
|
+
if (n.name.trim())
|
|
95
|
+
for (let t of d(n.name))
|
|
96
|
+
i.add_child(l, t, u(e)), l.push(t);
|
|
89
97
|
else {
|
|
90
|
-
let
|
|
91
|
-
|
|
98
|
+
let t = s();
|
|
99
|
+
i.add_child([], t, u(e));
|
|
92
100
|
}
|
|
93
101
|
break;
|
|
94
102
|
}
|
|
@@ -99,27 +107,25 @@ function k(s) {
|
|
|
99
107
|
if (e.type === m)
|
|
100
108
|
if (e.name === "layer")
|
|
101
109
|
if (e.prelude && e.has_block) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
110
|
+
let n = 0;
|
|
111
|
+
for (let t of e.prelude.children)
|
|
112
|
+
t.type === _ && n++;
|
|
113
|
+
for (let t = 0; t < n; t++)
|
|
114
|
+
l.pop();
|
|
109
115
|
} else
|
|
110
|
-
|
|
111
|
-
else e.name === "import" && (
|
|
116
|
+
l.pop();
|
|
117
|
+
else e.name === "import" && (l.length = 0);
|
|
112
118
|
}
|
|
113
|
-
}),
|
|
119
|
+
}), i.to_plain_object().children;
|
|
114
120
|
}
|
|
115
|
-
function
|
|
116
|
-
let
|
|
121
|
+
function w(a) {
|
|
122
|
+
let l = b(a, {
|
|
117
123
|
parse_selectors: !1,
|
|
118
124
|
parse_values: !1
|
|
119
125
|
});
|
|
120
|
-
return k(
|
|
126
|
+
return k(l);
|
|
121
127
|
}
|
|
122
128
|
export {
|
|
123
|
-
|
|
129
|
+
w as layer_tree,
|
|
124
130
|
k as layer_tree_from_ast
|
|
125
131
|
};
|