@projectwallace/css-layer-tree 0.0.1 → 0.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/README.md +5 -0
- package/dist/css-layer-tree.js +39 -41
- package/dist/css-layer-tree.umd.cjs +1 -1
- package/index.d.ts +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/css-layer-tree.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as u from "css-tree";
|
|
2
2
|
class f {
|
|
3
3
|
/** @param {string} name */
|
|
4
4
|
constructor(e) {
|
|
@@ -10,15 +10,15 @@ class f {
|
|
|
10
10
|
* @param {string} name
|
|
11
11
|
* @param {T} location
|
|
12
12
|
*/
|
|
13
|
-
add_child(e, l,
|
|
13
|
+
add_child(e, l, p) {
|
|
14
14
|
let n = this;
|
|
15
|
-
if (e.forEach((
|
|
16
|
-
n = n.children.get(
|
|
15
|
+
if (e.forEach((t) => {
|
|
16
|
+
n = n.children.get(t);
|
|
17
17
|
}), n.children.has(l))
|
|
18
|
-
n.children.get(l).locations.push(
|
|
18
|
+
n.children.get(l).locations.push(p);
|
|
19
19
|
else {
|
|
20
|
-
const
|
|
21
|
-
|
|
20
|
+
const t = new f(l);
|
|
21
|
+
t.locations.push(p), n.children.set(l, t);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
@@ -35,12 +35,12 @@ class f {
|
|
|
35
35
|
return {
|
|
36
36
|
name: this.name,
|
|
37
37
|
locations: this.locations,
|
|
38
|
-
children: Array.from(this.children.values()
|
|
38
|
+
children: Array.from(this.children.values(), (e) => e.to_plain_object())
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
function d(
|
|
43
|
-
let e =
|
|
42
|
+
function d(i) {
|
|
43
|
+
let e = i.loc;
|
|
44
44
|
if (e)
|
|
45
45
|
return {
|
|
46
46
|
line: e.start.line,
|
|
@@ -49,53 +49,51 @@ function d(u) {
|
|
|
49
49
|
end: e.end.offset
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
function _(
|
|
53
|
-
return
|
|
52
|
+
function _(i) {
|
|
53
|
+
return i.name.toLowerCase() === "layer";
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
55
|
+
function c(i) {
|
|
56
|
+
return u.generate(i).split(".").map((e) => e.trim());
|
|
57
|
+
}
|
|
58
|
+
function h(i) {
|
|
59
|
+
let e = [], l = new f("root"), p = 0;
|
|
57
60
|
function n() {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
function s(t) {
|
|
61
|
-
return p.generate(t).split(".").map((a) => a.trim());
|
|
61
|
+
return p++, `__anonymous-${p}__`;
|
|
62
62
|
}
|
|
63
|
-
return
|
|
63
|
+
return u.walk(i, {
|
|
64
64
|
visit: "Atrule",
|
|
65
65
|
enter(t) {
|
|
66
66
|
if (_(t)) {
|
|
67
|
-
let
|
|
67
|
+
let s = d(t);
|
|
68
68
|
if (t.prelude === null) {
|
|
69
69
|
let r = n();
|
|
70
|
-
l.add_child(e, r,
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
if (t.prelude.type === "AtrulePrelude")
|
|
70
|
+
l.add_child(e, r, s), e.push(r);
|
|
71
|
+
} else if (t.prelude.type === "AtrulePrelude")
|
|
74
72
|
if (t.block === null) {
|
|
75
|
-
let r =
|
|
73
|
+
let r = u.findAll(t.prelude, (o) => o.type === "Layer").map((o) => o.name);
|
|
76
74
|
for (let o of r)
|
|
77
|
-
l.add_child(e, o,
|
|
75
|
+
l.add_child(e, o, s);
|
|
78
76
|
} else
|
|
79
|
-
for (let r of
|
|
80
|
-
l.add_child(e, r,
|
|
77
|
+
for (let r of c(t.prelude))
|
|
78
|
+
l.add_child(e, r, s), e.push(r);
|
|
81
79
|
} else if (t.name.toLowerCase() === "import" && t.prelude !== null && t.prelude.type === "AtrulePrelude") {
|
|
82
|
-
let
|
|
80
|
+
let s = d(t), r = t.prelude, o = u.find(r, (a) => a.type === "Layer");
|
|
83
81
|
if (o) {
|
|
84
|
-
for (let
|
|
85
|
-
l.add_child(e,
|
|
82
|
+
for (let a of c(o))
|
|
83
|
+
l.add_child(e, a, s), e.push(a);
|
|
86
84
|
return this.skip;
|
|
87
85
|
}
|
|
88
|
-
if (
|
|
89
|
-
return l.add_child([], n(),
|
|
90
|
-
if (
|
|
91
|
-
return l.add_child([], n(),
|
|
86
|
+
if (u.find(r, (a) => a.type === "Function" && a.name.toLowerCase() === "layer"))
|
|
87
|
+
return l.add_child([], n(), s), this.skip;
|
|
88
|
+
if (u.find(r, (a) => a.type === "Identifier" && a.name.toLowerCase() === "layer"))
|
|
89
|
+
return l.add_child([], n(), s), this.skip;
|
|
92
90
|
}
|
|
93
91
|
},
|
|
94
92
|
leave(t) {
|
|
95
93
|
if (_(t))
|
|
96
94
|
if (t.prelude !== null && t.prelude.type === "AtrulePrelude") {
|
|
97
|
-
let
|
|
98
|
-
for (let r = 0; r <
|
|
95
|
+
let s = c(t.prelude);
|
|
96
|
+
for (let r = 0; r < s.length; r++)
|
|
99
97
|
e.pop();
|
|
100
98
|
} else
|
|
101
99
|
e.pop();
|
|
@@ -103,8 +101,8 @@ function h(u) {
|
|
|
103
101
|
}
|
|
104
102
|
}), l.to_plain_object().children;
|
|
105
103
|
}
|
|
106
|
-
function w(
|
|
107
|
-
let e =
|
|
104
|
+
function w(i) {
|
|
105
|
+
let e = u.parse(i, {
|
|
108
106
|
positions: !0,
|
|
109
107
|
parseAtrulePrelude: !0,
|
|
110
108
|
parseValue: !1,
|
|
@@ -114,6 +112,6 @@ function w(u) {
|
|
|
114
112
|
return h(e);
|
|
115
113
|
}
|
|
116
114
|
export {
|
|
117
|
-
w as
|
|
118
|
-
h as
|
|
115
|
+
w as layer_tree,
|
|
116
|
+
h as layer_tree_from_ast
|
|
119
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(o,
|
|
1
|
+
(function(o,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("css-tree")):typeof define=="function"&&define.amd?define(["exports","css-tree"],p):(o=typeof globalThis<"u"?globalThis:o||self,p(o.cssLayerTree={},o.csstree))})(this,function(o,p){"use strict";function g(l){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(l){for(const r in l)if(r!=="default"){const u=Object.getOwnPropertyDescriptor(l,r);Object.defineProperty(e,r,u.get?u:{enumerable:!0,get:()=>l[r]})}}return e.default=l,Object.freeze(e)}const f=g(p);class d{constructor(e){this.name=e,this.children=new Map,this.locations=[]}add_child(e,r,u){let a=this;if(e.forEach(t=>{a=a.children.get(t)}),a.children.has(r))a.children.get(r).locations.push(u);else{const t=new d(r);t.locations.push(u),a.children.set(r,t)}}to_plain_object(){return{name:this.name,locations:this.locations,children:Array.from(this.children.values(),e=>e.to_plain_object())}}}function y(l){let e=l.loc;if(e)return{line:e.start.line,column:e.start.column,start:e.start.offset,end:e.end.offset}}function h(l){return l.name.toLowerCase()==="layer"}function _(l){return f.generate(l).split(".").map(e=>e.trim())}function m(l){let e=[],r=new d("root"),u=0;function a(){return u++,`__anonymous-${u}__`}return f.walk(l,{visit:"Atrule",enter(t){if(h(t)){let s=y(t);if(t.prelude===null){let n=a();r.add_child(e,n,s),e.push(n)}else if(t.prelude.type==="AtrulePrelude")if(t.block===null){let n=f.findAll(t.prelude,c=>c.type==="Layer").map(c=>c.name);for(let c of n)r.add_child(e,c,s)}else for(let n of _(t.prelude))r.add_child(e,n,s),e.push(n)}else if(t.name.toLowerCase()==="import"&&t.prelude!==null&&t.prelude.type==="AtrulePrelude"){let s=y(t),n=t.prelude,c=f.find(n,i=>i.type==="Layer");if(c){for(let i of _(c))r.add_child(e,i,s),e.push(i);return this.skip}if(f.find(n,i=>i.type==="Function"&&i.name.toLowerCase()==="layer"))return r.add_child([],a(),s),this.skip;if(f.find(n,i=>i.type==="Identifier"&&i.name.toLowerCase()==="layer"))return r.add_child([],a(),s),this.skip}},leave(t){if(h(t))if(t.prelude!==null&&t.prelude.type==="AtrulePrelude"){let s=_(t.prelude);for(let n=0;n<s.length;n++)e.pop()}else e.pop();else t.name.toLowerCase()==="import"&&(e.length=0)}}),r.to_plain_object().children}function w(l){let e=f.parse(l,{positions:!0,parseAtrulePrelude:!0,parseValue:!1,parseRulePrelude:!1,parseCustomProperty:!1});return m(e)}o.layer_tree=w,o.layer_tree_from_ast=m,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|
package/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ export type TreeNode = {
|
|
|
13
13
|
locations: Location[];
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function
|
|
17
|
-
export function
|
|
16
|
+
export function layer_tree_from_ast(ast: CssNode): TreeNode[];
|
|
17
|
+
export function layer_tree(css: string): TreeNode[];
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-layer-tree",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Discover the composition of your CSS @layers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/projectwallace/css-
|
|
7
|
+
"url": "git+https://github.com/projectwallace/css-layer-tree.git"
|
|
8
8
|
},
|
|
9
9
|
"homepage": "https://github.com/projectwallace/css-layer-tree",
|
|
10
10
|
"issues": "https://github.com/projectwallace/css-layer-tree/issues",
|