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