@projectwallace/css-layer-tree 2.0.0-alpha.0 → 2.0.2
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 +44 -39
- package/package.json +1 -1
package/dist/css-layer-tree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
class
|
|
1
|
+
import * as p from "css-tree";
|
|
2
|
+
class d {
|
|
3
3
|
/** @param {string} name */
|
|
4
4
|
constructor(e) {
|
|
5
5
|
this.name = e, this.is_anonymous = !1, this.children = /* @__PURE__ */ new Map(), this.locations = [];
|
|
@@ -9,15 +9,15 @@ class f {
|
|
|
9
9
|
* @param {string} name
|
|
10
10
|
* @param {T} location
|
|
11
11
|
*/
|
|
12
|
-
add_child(e,
|
|
12
|
+
add_child(e, a, u) {
|
|
13
13
|
let s = this;
|
|
14
14
|
if (e.forEach((t) => {
|
|
15
15
|
s = s.children.get(t);
|
|
16
|
-
}), s.children.has(
|
|
17
|
-
s.children.get(
|
|
16
|
+
}), s.children.has(a))
|
|
17
|
+
u !== void 0 && s.children.get(a).locations.push(u);
|
|
18
18
|
else {
|
|
19
|
-
const t = new
|
|
20
|
-
t.locations.push(
|
|
19
|
+
const t = new d(a);
|
|
20
|
+
u !== void 0 && t.locations.push(u), t.is_anonymous = a.startsWith("__anonymous"), s.children.set(a, t);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -40,8 +40,8 @@ class f {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
function _(
|
|
44
|
-
let e =
|
|
43
|
+
function _(i) {
|
|
44
|
+
let e = i.loc;
|
|
45
45
|
if (e)
|
|
46
46
|
return {
|
|
47
47
|
line: e.start.line,
|
|
@@ -50,67 +50,72 @@ function _(a) {
|
|
|
50
50
|
end: e.end.offset
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
53
|
+
function h(i) {
|
|
54
|
+
return i.name.toLowerCase() === "layer";
|
|
55
55
|
}
|
|
56
|
-
function c(
|
|
57
|
-
return
|
|
56
|
+
function c(i) {
|
|
57
|
+
return p.generate(i).split(".").map((e) => e.trim());
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
let e = [],
|
|
59
|
+
function g(i) {
|
|
60
|
+
let e = [], a = new d("root"), u = 0;
|
|
61
61
|
function s() {
|
|
62
|
-
return
|
|
62
|
+
return u++, `__anonymous-${u}__`;
|
|
63
63
|
}
|
|
64
|
-
return
|
|
64
|
+
return p.walk(i, {
|
|
65
65
|
visit: "Atrule",
|
|
66
66
|
enter(t) {
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
67
|
+
if (h(t)) {
|
|
68
|
+
let n = _(t);
|
|
69
69
|
if (t.prelude === null) {
|
|
70
70
|
let r = s();
|
|
71
|
-
|
|
71
|
+
a.add_child(e, r, n), e.push(r);
|
|
72
72
|
} else if (t.prelude.type === "AtrulePrelude")
|
|
73
73
|
if (t.block === null) {
|
|
74
|
-
let r =
|
|
75
|
-
for (let
|
|
76
|
-
|
|
74
|
+
let r = p.findAll(t.prelude, (o) => o.type === "Layer").map((o) => o.name);
|
|
75
|
+
for (let o of r) {
|
|
76
|
+
let f = o.split(".").map((l) => l.trim());
|
|
77
|
+
for (let l = 0; l < f.length; l++) {
|
|
78
|
+
let y = f.slice(0, l), m = f[l], w = l === f.length - 1 ? { ...n } : void 0;
|
|
79
|
+
a.add_child(y, m, w);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
77
82
|
} else
|
|
78
83
|
for (let r of c(t.prelude))
|
|
79
|
-
|
|
84
|
+
a.add_child(e, r, n), e.push(r);
|
|
80
85
|
} else if (t.name.toLowerCase() === "import" && t.prelude !== null && t.prelude.type === "AtrulePrelude") {
|
|
81
|
-
let
|
|
82
|
-
if (
|
|
83
|
-
for (let
|
|
84
|
-
|
|
86
|
+
let n = _(t), r = t.prelude, o = p.find(r, (l) => l.type === "Layer");
|
|
87
|
+
if (o) {
|
|
88
|
+
for (let l of c(o))
|
|
89
|
+
a.add_child(e, l, n), e.push(l);
|
|
85
90
|
return this.skip;
|
|
86
91
|
}
|
|
87
|
-
if (
|
|
88
|
-
return
|
|
92
|
+
if (p.find(r, (l) => l.type === "Identifier" && l.name.toLowerCase() === "layer"))
|
|
93
|
+
return a.add_child([], s(), n), this.skip;
|
|
89
94
|
}
|
|
90
95
|
},
|
|
91
96
|
leave(t) {
|
|
92
|
-
if (
|
|
97
|
+
if (h(t))
|
|
93
98
|
if (t.prelude !== null && t.prelude.type === "AtrulePrelude") {
|
|
94
|
-
let
|
|
95
|
-
for (let r = 0; r <
|
|
99
|
+
let n = c(t.prelude);
|
|
100
|
+
for (let r = 0; r < n.length; r++)
|
|
96
101
|
e.pop();
|
|
97
102
|
} else
|
|
98
103
|
e.pop();
|
|
99
104
|
else t.name.toLowerCase() === "import" && (e.length = 0);
|
|
100
105
|
}
|
|
101
|
-
}),
|
|
106
|
+
}), a.to_plain_object().children;
|
|
102
107
|
}
|
|
103
|
-
function
|
|
104
|
-
let e =
|
|
108
|
+
function k(i) {
|
|
109
|
+
let e = p.parse(i, {
|
|
105
110
|
positions: !0,
|
|
106
111
|
parseAtrulePrelude: !0,
|
|
107
112
|
parseValue: !1,
|
|
108
113
|
parseRulePrelude: !1,
|
|
109
114
|
parseCustomProperty: !1
|
|
110
115
|
});
|
|
111
|
-
return
|
|
116
|
+
return g(e);
|
|
112
117
|
}
|
|
113
118
|
export {
|
|
114
|
-
|
|
115
|
-
|
|
119
|
+
k as layer_tree,
|
|
120
|
+
g as layer_tree_from_ast
|
|
116
121
|
};
|