@projectwallace/css-layer-tree 2.1.0 → 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.
@@ -1,23 +1,23 @@
1
- import { traverse as g, AT_RULE as m, LAYER_NAME as f, parse as b } from "@projectwallace/css-parser";
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(t) {
5
- this.name = t, this.is_anonymous = !1, this.children = /* @__PURE__ */ new Map(), this.locations = [];
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(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);
12
+ add_child(l, i, c) {
13
+ let s = this;
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 e = new _(r);
20
- n !== void 0 && e.locations.push(n), e.is_anonymous = r.startsWith("__anonymous"), a.children.set(r, e);
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,59 +36,67 @@ class _ {
36
36
  name: this.name,
37
37
  is_anonymous: this.is_anonymous,
38
38
  locations: this.locations,
39
- children: Array.from(this.children.values(), (t) => t.to_plain_object())
39
+ children: Array.from(this.children.values(), (l) => l.to_plain_object())
40
40
  };
41
41
  }
42
42
  }
43
- function h(s) {
44
- return s.split(".").map((t) => t.trim());
43
+ function d(a) {
44
+ return a.split(".").map((l) => l.trim());
45
45
  }
46
- function u(s) {
46
+ function u(a) {
47
47
  return {
48
- line: s.line,
49
- column: s.column,
50
- start: s.start,
51
- end: s.end
48
+ line: a.line,
49
+ column: a.column,
50
+ start: a.start,
51
+ end: a.end
52
52
  };
53
53
  }
54
- function k(s) {
55
- let t = [], r = new _("root"), n = 0;
56
- function a() {
57
- return n++, `__anonymous-${n}__`;
54
+ function k(a) {
55
+ let l = [], i = new p("root"), c = 0;
56
+ function s() {
57
+ return c++, `__anonymous-${c}__`;
58
58
  }
59
- return g(s, {
59
+ return g(a, {
60
60
  enter(e) {
61
61
  if (e.type === m) {
62
62
  if (e.name === "layer")
63
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);
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);
76
84
  }
77
85
  }
78
86
  }
79
87
  } else {
80
- let i = a();
81
- r.add_child(t, i, u(e)), t.push(i);
88
+ let n = s();
89
+ i.add_child(l, n, u(e)), l.push(n);
82
90
  }
83
91
  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);
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);
89
97
  else {
90
- let l = a();
91
- r.add_child([], l, u(e));
98
+ let t = s();
99
+ i.add_child([], t, u(e));
92
100
  }
93
101
  break;
94
102
  }
@@ -99,27 +107,25 @@ function k(s) {
99
107
  if (e.type === m)
100
108
  if (e.name === "layer")
101
109
  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
- }
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();
109
115
  } else
110
- t.pop();
111
- else e.name === "import" && (t.length = 0);
116
+ l.pop();
117
+ else e.name === "import" && (l.length = 0);
112
118
  }
113
- }), r.to_plain_object().children;
119
+ }), i.to_plain_object().children;
114
120
  }
115
- function v(s) {
116
- let t = b(s, {
121
+ function w(a) {
122
+ let l = b(a, {
117
123
  parse_selectors: !1,
118
124
  parse_values: !1
119
125
  });
120
- return k(t);
126
+ return k(l);
121
127
  }
122
128
  export {
123
- v as layer_tree,
129
+ w as layer_tree,
124
130
  k as layer_tree_from_ast
125
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/css-layer-tree",
3
- "version": "2.1.0",
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",