@projectwallace/css-layer-tree 2.0.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.
@@ -1,5 +1,5 @@
1
- import * as u from "css-tree";
2
- class f {
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, l, p) {
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(l))
17
- s.children.get(l).locations.push(p);
16
+ }), s.children.has(a))
17
+ u !== void 0 && s.children.get(a).locations.push(u);
18
18
  else {
19
- const t = new f(l);
20
- t.locations.push(p), t.is_anonymous = l.startsWith("__anonymous"), s.children.set(l, t);
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 _(a) {
44
- let e = a.loc;
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 d(a) {
54
- return a.name.toLowerCase() === "layer";
53
+ function h(i) {
54
+ return i.name.toLowerCase() === "layer";
55
55
  }
56
- function c(a) {
57
- return u.generate(a).split(".").map((e) => e.trim());
56
+ function c(i) {
57
+ return p.generate(i).split(".").map((e) => e.trim());
58
58
  }
59
- function h(a) {
60
- let e = [], l = new f("root"), p = 0;
59
+ function g(i) {
60
+ let e = [], a = new d("root"), u = 0;
61
61
  function s() {
62
- return p++, `__anonymous-${p}__`;
62
+ return u++, `__anonymous-${u}__`;
63
63
  }
64
- return u.walk(a, {
64
+ return p.walk(i, {
65
65
  visit: "Atrule",
66
66
  enter(t) {
67
- if (d(t)) {
68
- let i = _(t);
67
+ if (h(t)) {
68
+ let n = _(t);
69
69
  if (t.prelude === null) {
70
70
  let r = s();
71
- l.add_child(e, r, i), e.push(r);
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 = u.findAll(t.prelude, (n) => n.type === "Layer").map((n) => n.name);
75
- for (let n of r)
76
- l.add_child(e, n, i);
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
- l.add_child(e, r, i), e.push(r);
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 i = _(t), r = t.prelude, n = u.find(r, (o) => o.type === "Layer");
82
- if (n) {
83
- for (let o of c(n))
84
- l.add_child(e, o, i), e.push(o);
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 (u.find(r, (o) => o.type === "Identifier" && o.name.toLowerCase() === "layer"))
88
- return l.add_child([], s(), i), this.skip;
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 (d(t))
97
+ if (h(t))
93
98
  if (t.prelude !== null && t.prelude.type === "AtrulePrelude") {
94
- let i = c(t.prelude);
95
- for (let r = 0; r < i.length; 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
- }), l.to_plain_object().children;
106
+ }), a.to_plain_object().children;
102
107
  }
103
- function m(a) {
104
- let e = u.parse(a, {
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 h(e);
116
+ return g(e);
112
117
  }
113
118
  export {
114
- m as layer_tree,
115
- h as layer_tree_from_ast
119
+ k as layer_tree,
120
+ g as layer_tree_from_ast
116
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-layer-tree",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Discover the composition of your CSS @layers in a tree-based format.",
5
5
  "repository": {
6
6
  "type": "git",