@projectwallace/css-layer-tree 2.0.2 → 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 +86 -76
- package/package.json +6 -7
package/dist/css-layer-tree.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import
|
|
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(
|
|
12
|
+
add_child(l, i, c) {
|
|
13
13
|
let s = this;
|
|
14
|
-
if (
|
|
15
|
-
s = s.children.get(
|
|
16
|
-
}), s.children.has(
|
|
17
|
-
|
|
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
|
|
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,86 +36,96 @@ class d {
|
|
|
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
|
-
|
|
45
|
-
if (e)
|
|
46
|
-
return {
|
|
47
|
-
line: e.start.line,
|
|
48
|
-
column: e.start.column,
|
|
49
|
-
start: e.start.offset,
|
|
50
|
-
end: e.end.offset
|
|
51
|
-
};
|
|
43
|
+
function d(a) {
|
|
44
|
+
return a.split(".").map((l) => l.trim());
|
|
52
45
|
}
|
|
53
|
-
function
|
|
54
|
-
return
|
|
46
|
+
function u(a) {
|
|
47
|
+
return {
|
|
48
|
+
line: a.line,
|
|
49
|
+
column: a.column,
|
|
50
|
+
start: a.start,
|
|
51
|
+
end: a.end
|
|
52
|
+
};
|
|
55
53
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
function g(i) {
|
|
60
|
-
let e = [], a = new d("root"), u = 0;
|
|
54
|
+
function k(a) {
|
|
55
|
+
let l = [], i = new p("root"), c = 0;
|
|
61
56
|
function s() {
|
|
62
|
-
return
|
|
57
|
+
return c++, `__anonymous-${c}__`;
|
|
63
58
|
}
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
return g(a, {
|
|
60
|
+
enter(e) {
|
|
61
|
+
if (e.type === m) {
|
|
62
|
+
if (e.name === "layer")
|
|
63
|
+
if (e.prelude) {
|
|
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);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
80
86
|
}
|
|
87
|
+
} else {
|
|
88
|
+
let n = s();
|
|
89
|
+
i.add_child(l, n, u(e)), l.push(n);
|
|
90
|
+
}
|
|
91
|
+
else if (e.name === "import" && e.prelude) {
|
|
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);
|
|
97
|
+
else {
|
|
98
|
+
let t = s();
|
|
99
|
+
i.add_child([], t, u(e));
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
81
102
|
}
|
|
82
|
-
} else
|
|
83
|
-
for (let r of c(t.prelude))
|
|
84
|
-
a.add_child(e, r, n), e.push(r);
|
|
85
|
-
} else if (t.name.toLowerCase() === "import" && t.prelude !== null && t.prelude.type === "AtrulePrelude") {
|
|
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);
|
|
90
|
-
return this.skip;
|
|
91
103
|
}
|
|
92
|
-
if (p.find(r, (l) => l.type === "Identifier" && l.name.toLowerCase() === "layer"))
|
|
93
|
-
return a.add_child([], s(), n), this.skip;
|
|
94
104
|
}
|
|
95
105
|
},
|
|
96
|
-
leave(
|
|
97
|
-
if (
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
e.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
leave(e) {
|
|
107
|
+
if (e.type === m)
|
|
108
|
+
if (e.name === "layer")
|
|
109
|
+
if (e.prelude && e.has_block) {
|
|
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();
|
|
115
|
+
} else
|
|
116
|
+
l.pop();
|
|
117
|
+
else e.name === "import" && (l.length = 0);
|
|
105
118
|
}
|
|
106
|
-
}),
|
|
119
|
+
}), i.to_plain_object().children;
|
|
107
120
|
}
|
|
108
|
-
function
|
|
109
|
-
let
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
parseValue: !1,
|
|
113
|
-
parseRulePrelude: !1,
|
|
114
|
-
parseCustomProperty: !1
|
|
121
|
+
function w(a) {
|
|
122
|
+
let l = b(a, {
|
|
123
|
+
parse_selectors: !1,
|
|
124
|
+
parse_values: !1
|
|
115
125
|
});
|
|
116
|
-
return
|
|
126
|
+
return k(l);
|
|
117
127
|
}
|
|
118
128
|
export {
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
w as layer_tree,
|
|
130
|
+
k as layer_tree_from_ast
|
|
121
131
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-layer-tree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Discover the composition of your CSS @layers in a tree-based format.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,21 +25,17 @@
|
|
|
25
25
|
"scripts": {
|
|
26
26
|
"build": "vite build",
|
|
27
27
|
"test": "c8 --reporter=lcov uvu",
|
|
28
|
-
"check": "tsc",
|
|
28
|
+
"check": "tsc --noEmit",
|
|
29
29
|
"prettier": "prettier --check src/**/*.js test/**/*.js"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@codecov/vite-plugin": "^1.2.1",
|
|
33
|
-
"@types/css-tree": "^2.3.8",
|
|
34
33
|
"c8": "^10.1.2",
|
|
35
34
|
"prettier": "^3.3.3",
|
|
36
35
|
"typescript": "5.4.2",
|
|
37
36
|
"uvu": "^0.5.6",
|
|
38
37
|
"vite": "^5.4.10"
|
|
39
38
|
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"css-tree": "^3.0.0"
|
|
42
|
-
},
|
|
43
39
|
"files": [
|
|
44
40
|
"dist",
|
|
45
41
|
"index.d.ts"
|
|
@@ -58,5 +54,8 @@
|
|
|
58
54
|
"useTabs": true,
|
|
59
55
|
"printWidth": 140,
|
|
60
56
|
"singleQuote": true
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@projectwallace/css-parser": "^0.12.2"
|
|
61
60
|
}
|
|
62
|
-
}
|
|
61
|
+
}
|