@projectwallace/format-css 2.2.2 → 2.2.4

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.
Files changed (2) hide show
  1. package/dist/format-css.js +108 -107
  2. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { parse as X, NODE_TYPES as n, ATTR_FLAG_CASE_INSENSITIVE as z, ATTR_FLAG_CASE_SENSITIVE as tt, ATTR_OPERATOR_EQUAL as et, ATTR_OPERATOR_STAR_EQUAL as rt, ATTR_OPERATOR_DOLLAR_EQUAL as st, ATTR_OPERATOR_CARET_EQUAL as it, ATTR_OPERATOR_PIPE_EQUAL as lt, ATTR_OPERATOR_TILDE_EQUAL as nt } from "@projectwallace/css-parser";
1
+ import { parse as X, NODE_TYPES as u, ATTR_FLAG_CASE_INSENSITIVE as z, ATTR_FLAG_CASE_SENSITIVE as tt, ATTR_OPERATOR_EQUAL as et, ATTR_OPERATOR_STAR_EQUAL as rt, ATTR_OPERATOR_DOLLAR_EQUAL as st, ATTR_OPERATOR_CARET_EQUAL as it, ATTR_OPERATOR_PIPE_EQUAL as lt, ATTR_OPERATOR_TILDE_EQUAL as nt } from "@projectwallace/css-parser";
2
2
  const _ = " ", p = "", k = ":", b = ";", w = '"', P = "(", N = ")", ut = "[", pt = "]", d = "{", g = "}", D = ",";
3
3
  function ct(R, { minify: O = !1, tab_size: L = void 0 } = /* @__PURE__ */ Object.create(null)) {
4
4
  if (L !== void 0 && Number(L) < 1)
@@ -10,68 +10,68 @@ function ct(R, { minify: O = !1, tab_size: L = void 0 } = /* @__PURE__ */ Object
10
10
  A.push(t, e);
11
11
  }
12
12
  }), a = 0;
13
- function h(t) {
13
+ function o(t) {
14
14
  return O === !0 ? p : L !== void 0 ? _.repeat(L * t) : " ".repeat(t);
15
15
  }
16
- function f(t, e, r = a) {
16
+ function f(t, e, s = a) {
17
17
  if (O || t === void 0 || e === void 0)
18
18
  return p;
19
- let s = p;
20
- for (let i = 0; i < A.length; i += 2) {
21
- let l = A[i];
22
- if (l === void 0 || l < t) continue;
23
- let u = A[i + 1];
24
- if (u === void 0 || u > e) break;
25
- s.length > 0 && (s += E + h(r)), s += R.slice(l, u);
19
+ let r = p;
20
+ for (let l = 0; l < A.length; l += 2) {
21
+ let i = A[l];
22
+ if (i === void 0 || i < t) continue;
23
+ let n = A[l + 1];
24
+ if (n === void 0 || n > e) break;
25
+ r.length > 0 && (r += E + o(s)), r += R.slice(i, n);
26
26
  }
27
- return s;
27
+ return r;
28
28
  }
29
29
  function I(t) {
30
30
  return t.replace(/(?:^['"])|(?:['"]$)/g, p);
31
31
  }
32
- function m(t) {
32
+ function S(t) {
33
33
  return t = (t == null ? void 0 : t.toString()) || "", w + I(t) + w;
34
34
  }
35
35
  function B(t) {
36
- let e = [], r = t.text, s = r.charCodeAt(0);
37
- return s === 43 || s === 45 ? e.push(_) : s !== 44 && e.push(c), e.push(r), s === 43 || s === 45 ? e.push(_) : e.push(c), e.join(p);
36
+ let e = [], s = t.text, r = s.charCodeAt(0);
37
+ return r === 43 || r === 45 ? e.push(_) : r !== 44 && e.push(c), e.push(s), r === 43 || r === 45 ? e.push(_) : e.push(c), e.join(p);
38
38
  }
39
- function S(t) {
40
- var r, s;
39
+ function m(t) {
40
+ var s, r, l;
41
41
  let e = [];
42
42
  for (let i of t) {
43
- if (i.type === n.FUNCTION) {
44
- let l = i.name.toLowerCase();
45
- e.push(l, P), e.push(S(i.children)), e.push(N);
46
- } else if (i.type === n.DIMENSION)
43
+ if (i.type === u.FUNCTION) {
44
+ let n = (s = i.name) == null ? void 0 : s.toLowerCase();
45
+ e.push(n, P), e.push(m(i.children)), e.push(N);
46
+ } else if (i.type === u.DIMENSION)
47
47
  e.push(i.value, (r = i.unit) == null ? void 0 : r.toLowerCase());
48
- else if (i.type === n.STRING)
49
- e.push(m(i.text));
50
- else if (i.type === n.OPERATOR)
48
+ else if (i.type === u.STRING)
49
+ e.push(S(i.text));
50
+ else if (i.type === u.OPERATOR)
51
51
  e.push(B(i));
52
- else if (i.type === n.PARENTHESIS)
53
- e.push(P, S(i.children), N);
54
- else if (i.type === n.URL && typeof i.value == "string") {
52
+ else if (i.type === u.PARENTHESIS)
53
+ e.push(P, m(i.children), N);
54
+ else if (i.type === u.URL && typeof i.value == "string") {
55
55
  e.push("url(");
56
- let { value: l } = i;
57
- /^['"]?data:/i.test(l) ? e.push(I(l)) : e.push(m(l)), e.push(N);
56
+ let { value: n } = i;
57
+ /^['"]?data:/i.test(n) ? e.push(I(n)) : e.push(S(n)), e.push(N);
58
58
  } else
59
59
  e.push(i.text);
60
- i.type !== n.OPERATOR && i.has_next && ((s = i.next_sibling) == null ? void 0 : s.type) !== n.OPERATOR && e.push(_);
60
+ i.type !== u.OPERATOR && i.has_next && ((l = i.next_sibling) == null ? void 0 : l.type) !== u.OPERATOR && e.push(_);
61
61
  }
62
62
  return e.join(p);
63
63
  }
64
64
  function H(t) {
65
- return t === null ? p : S(t);
65
+ return t === null ? p : m(t);
66
66
  }
67
67
  function F(t) {
68
68
  let e = [];
69
69
  if (t.is_important) {
70
- let i = t.text, l = i.endsWith(b), u = i.lastIndexOf("!"), T = l ? -1 : void 0;
71
- e.push(c, i.slice(u, T).toLowerCase());
70
+ let l = t.text, i = l.endsWith(b), n = l.lastIndexOf("!"), T = i ? -1 : void 0;
71
+ e.push(c, l.slice(n, T).toLowerCase());
72
72
  }
73
- let r = H(t.value), s = t.property;
74
- return s === "font" && (r = r.replace(/\s*\/\s*/, "/")), r === p && O === !0 && (r += _), s.startsWith("--") || (s = s.toLowerCase()), s + k + c + r + e.join(p);
73
+ let s = H(t.value), r = t.property;
74
+ return r === "font" && (s = s.replace(/\s*\/\s*/, "/")), s === p && O === !0 && (s += _), r.startsWith("--") || (r = r.toLowerCase()), r + k + c + s + e.join(p);
75
75
  }
76
76
  function G(t) {
77
77
  switch (t) {
@@ -91,65 +91,66 @@ function ct(R, { minify: O = !1, tab_size: L = void 0 } = /* @__PURE__ */ Object
91
91
  }
92
92
  }
93
93
  function v(t) {
94
- let e = [], r = t.nth_a, s = t.nth_b;
95
- return r && e.push(r), r && s && e.push(c), s && (r && !s.startsWith("-") && e.push("+", c), e.push(parseFloat(s))), e.join(p);
94
+ let e = [], s = t.nth_a, r = t.nth_b;
95
+ return s && e.push(s), s && r && e.push(c), r && (s && !r.startsWith("-") && e.push("+", c), e.push(parseFloat(r))), e.join(p);
96
96
  }
97
97
  function Y(t) {
98
- var r, s;
98
+ var s, r;
99
99
  let e = [];
100
- return ((r = t.children[0]) == null ? void 0 : r.type) === n.NTH_SELECTOR && (e.push(v(t.children[0])), e.push(_, "of", _)), ((s = t.children[1]) == null ? void 0 : s.type) === n.SELECTOR_LIST && e.push(y(t.children[1])), e.join(p);
100
+ return ((s = t.children[0]) == null ? void 0 : s.type) === u.NTH_SELECTOR && (e.push(v(t.children[0])), e.push(_, "of", _)), ((r = t.children[1]) == null ? void 0 : r.type) === u.SELECTOR_LIST && e.push(y(t.children[1])), e.join(p);
101
101
  }
102
102
  function W(t, e = !1) {
103
+ let s = t.name ?? "";
103
104
  switch (t.type) {
104
- case n.TYPE_SELECTOR:
105
- return t.name.toLowerCase();
106
- case n.COMBINATOR: {
105
+ case u.TYPE_SELECTOR:
106
+ return s.toLowerCase() ?? "";
107
+ case u.COMBINATOR: {
107
108
  let r = t.text;
108
109
  return /^\s+$/.test(r) ? _ : (e ? p : c) + r + c;
109
110
  }
110
- case n.PSEUDO_ELEMENT_SELECTOR:
111
- case n.PSEUDO_CLASS_SELECTOR: {
112
- let r = [k], s = t.name.toLowerCase();
113
- return (s === "before" || s === "after" || t.type === n.PSEUDO_ELEMENT_SELECTOR) && r.push(k), r.push(s), t.has_children && (r.push(P), t.children.length > 0 && (s === "highlight" ? r.push(S(t.children)) : r.push(y(t))), r.push(N)), r.join(p);
111
+ case u.PSEUDO_ELEMENT_SELECTOR:
112
+ case u.PSEUDO_CLASS_SELECTOR: {
113
+ let r = [k];
114
+ return s = s.toLowerCase(), (s === "before" || s === "after" || t.type === u.PSEUDO_ELEMENT_SELECTOR) && r.push(k), r.push(s), t.has_children && (r.push(P), t.children.length > 0 && (s === "highlight" ? r.push(m(t.children)) : r.push(y(t))), r.push(N)), r.join(p);
114
115
  }
115
- case n.ATTRIBUTE_SELECTOR: {
116
- let r = [ut, t.name.toLowerCase()];
117
- return t.attr_operator && (r.push(G(t.attr_operator)), typeof t.value == "string" && r.push(m(t.value)), t.attr_flags === z ? r.push(_, "i") : t.attr_flags === tt && r.push(_, "s")), r.push(pt), r.join(p);
116
+ case u.ATTRIBUTE_SELECTOR: {
117
+ let r = [ut, s.toLowerCase()];
118
+ return t.attr_operator && (r.push(G(t.attr_operator)), typeof t.value == "string" && r.push(S(t.value)), t.attr_flags === z ? r.push(_, "i") : t.attr_flags === tt && r.push(_, "s")), r.push(pt), r.join(p);
118
119
  }
119
120
  default:
120
121
  return t.text;
121
122
  }
122
123
  }
123
124
  function x(t) {
124
- if (t.type === n.NTH_SELECTOR)
125
+ if (t.type === u.NTH_SELECTOR)
125
126
  return v(t);
126
- if (t.type === n.NTH_OF_SELECTOR)
127
+ if (t.type === u.NTH_OF_SELECTOR)
127
128
  return Y(t);
128
- if (t.type === n.SELECTOR_LIST)
129
+ if (t.type === u.SELECTOR_LIST)
129
130
  return y(t);
130
- if (t.type === n.LANG_SELECTOR)
131
- return m(t.text);
131
+ if (t.type === u.LANG_SELECTOR)
132
+ return S(t.text);
132
133
  let e = [];
133
- return t.children.forEach((r, s) => {
134
- const i = W(r, s === 0);
135
- e.push(i);
134
+ return t.children.forEach((s, r) => {
135
+ const l = W(s, r === 0);
136
+ e.push(l);
136
137
  }), e.join(p);
137
138
  }
138
139
  function y(t) {
139
140
  let e = [];
140
- for (let r of t)
141
- e.push(x(r)), r.has_next && e.push(D, c);
141
+ for (let s of t)
142
+ e.push(x(s)), s.has_next && e.push(D, c);
142
143
  return e.join(p);
143
144
  }
144
145
  function K(t) {
145
- let e = [], r;
146
- for (let s of t) {
147
- if (r !== void 0) {
148
- let l = f(r, s.start);
149
- l && e.push(h(a) + l);
146
+ let e = [], s;
147
+ for (let r of t) {
148
+ if (s !== void 0) {
149
+ let i = f(s, r.start);
150
+ i && e.push(o(a) + i);
150
151
  }
151
- let i = x(s);
152
- s.has_next && (i += D), e.push(h(a) + i), r = s.end;
152
+ let l = x(r);
153
+ r.has_next && (l += D), e.push(o(a) + l), s = r.end;
153
154
  }
154
155
  return e.join(E);
155
156
  }
@@ -157,68 +158,68 @@ function ct(R, { minify: O = !1, tab_size: L = void 0 } = /* @__PURE__ */ Object
157
158
  var T;
158
159
  let e = [];
159
160
  a++;
160
- let r = t.children;
161
- if (r.length === 0) {
162
- let o = f(t.start, t.end);
163
- if (o)
164
- return e.push(h(a) + o), a--, e.push(h(a) + g), e.join(E);
161
+ let s = t.children;
162
+ if (s.length === 0) {
163
+ let h = f(t.start, t.end);
164
+ if (h)
165
+ return e.push(o(a) + h), a--, e.push(o(a) + g), e.join(E);
165
166
  }
166
- let s = r[0], i = f(t.start, s == null ? void 0 : s.start);
167
- i && e.push(h(a) + i);
168
- let l;
169
- for (let o of r) {
170
- if (l !== void 0) {
171
- let C = f(l, o.start);
172
- C && e.push(h(a) + C);
167
+ let r = s[0], l = f(t.start, r == null ? void 0 : r.start);
168
+ l && e.push(o(a) + l);
169
+ let i;
170
+ for (let h of s) {
171
+ if (i !== void 0) {
172
+ let C = f(i, h.start);
173
+ C && e.push(o(a) + C);
173
174
  }
174
- let Z = ((T = o.next_sibling) == null ? void 0 : T.type) !== n.DECLARATION;
175
- if (o.type === n.DECLARATION) {
176
- let C = F(o), J = Z ? M : b;
177
- e.push(h(a) + C + J);
178
- } else o.type === n.STYLE_RULE ? (l !== void 0 && e.length !== 0 && e.push(p), e.push(U(o))) : o.type === n.AT_RULE && (l !== void 0 && e.length !== 0 && e.push(p), e.push(h(a) + $(o)));
179
- l = o.end;
175
+ let Z = ((T = h.next_sibling) == null ? void 0 : T.type) !== u.DECLARATION;
176
+ if (h.type === u.DECLARATION) {
177
+ let C = F(h), J = Z ? M : b;
178
+ e.push(o(a) + C + J);
179
+ } else h.type === u.STYLE_RULE ? (i !== void 0 && e.length !== 0 && e.push(p), e.push(U(h))) : h.type === u.AT_RULE && (i !== void 0 && e.length !== 0 && e.push(p), e.push(o(a) + $(h)));
180
+ i = h.end;
180
181
  }
181
- let u = f(l, t.end);
182
- return u && e.push(h(a) + u), a--, e.push(h(a) + g), e.join(E);
182
+ let n = f(i, t.end);
183
+ return n && e.push(o(a) + n), a--, e.push(o(a) + g), e.join(E);
183
184
  }
184
185
  function U(t) {
185
- var r, s;
186
+ var s, r;
186
187
  let e = [];
187
- if (((r = t.first_child) == null ? void 0 : r.type) === n.SELECTOR_LIST) {
188
- let i = K(t.first_child), l = f(t.first_child.end, (s = t.block) == null ? void 0 : s.start);
189
- l && (i += E + h(a) + l), i += c + d, t.block && (t.block.has_children || f(t.block.start, t.block.end)) || (i += g), e.push(i);
188
+ if (((s = t.first_child) == null ? void 0 : s.type) === u.SELECTOR_LIST) {
189
+ let l = K(t.first_child), i = f(t.first_child.end, (r = t.block) == null ? void 0 : r.start);
190
+ i && (l += E + o(a) + i), l += c + d, t.block && (t.block.has_children || f(t.block.start, t.block.end)) || (l += g), e.push(l);
190
191
  }
191
192
  return t.block && (t.block.has_children || f(t.block.start, t.block.end)) && e.push(j(t.block)), e.join(E);
192
193
  }
193
194
  function V(t) {
194
- return t.replace(/\s*([:,])/g, t.toLowerCase().includes("selector(") ? "$1" : "$1 ").replace(/\)([a-zA-Z])/g, ") $1").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(/([^<>=\s])([<>])([^<>=\s])/g, `$1${c}$2${c}$3`).replace(/\s+/g, c).replace(/calc\(\s*([^()+\-*/]+)\s*([*/+-])\s*([^()+\-*/]+)\s*\)/g, (e, r, s, i) => {
195
- let l = s === "+" || s === "-" ? _ : c;
196
- return `calc(${r.trim()}${l}${s}${l}${i.trim()})`;
195
+ return t.replace(/\s*([:,])/g, t.toLowerCase().includes("selector(") ? "$1" : "$1 ").replace(/\)([a-zA-Z])/g, ") $1").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(/([^<>=\s])([<>])([^<>=\s])/g, `$1${c}$2${c}$3`).replace(/\s+/g, c).replace(/calc\(\s*([^()+\-*/]+)\s*([*/+-])\s*([^()+\-*/]+)\s*\)/g, (e, s, r, l) => {
196
+ let i = r === "+" || r === "-" ? _ : c;
197
+ return `calc(${s.trim()}${i}${r}${i}${l.trim()})`;
197
198
  }).replace(/selector|url|supports|layer\(/gi, (e) => e.toLowerCase());
198
199
  }
199
200
  function $(t) {
200
- let e = [], r = ["@", t.name.toLowerCase()];
201
- return t.prelude && r.push(_, V(t.prelude.text)), t.block === null ? r.push(b) : (r.push(c, d), !t.block.is_empty || f(t.block.start, t.block.end) || r.push(g)), e.push(r.join(p)), t.block !== null && (!t.block.is_empty || f(t.block.start, t.block.end)) && e.push(j(t.block)), e.join(E);
201
+ let e = [], s = ["@", t.name.toLowerCase()];
202
+ return t.prelude && s.push(_, V(t.prelude.text)), t.block === null ? s.push(b) : (s.push(c, d), !t.block.is_empty || f(t.block.start, t.block.end) || s.push(g)), e.push(s.join(p)), t.block !== null && (!t.block.is_empty || f(t.block.start, t.block.end)) && e.push(j(t.block)), e.join(E);
202
203
  }
203
204
  function q(t) {
204
- let e = [], r = t.children;
205
- if (r.length === 0)
205
+ let e = [], s = t.children;
206
+ if (s.length === 0)
206
207
  return f(0, t.end, 0);
207
- let s = r[0];
208
- if (s) {
209
- let u = f(0, s.start, 0);
210
- u && e.push(u);
208
+ let r = s[0];
209
+ if (r) {
210
+ let n = f(0, r.start, 0);
211
+ n && e.push(n);
211
212
  }
212
- let i;
213
- for (let u of t) {
214
- if (i !== void 0) {
215
- let T = f(i, u.start, 0);
213
+ let l;
214
+ for (let n of t) {
215
+ if (l !== void 0) {
216
+ let T = f(l, n.start, 0);
216
217
  T && e.push(T);
217
218
  }
218
- u.type === n.STYLE_RULE ? e.push(U(u)) : u.type === n.AT_RULE && e.push($(u)), i = u.end, u.has_next && (u.next_sibling && f(u.end, u.next_sibling.start, 0) || e.push(p));
219
+ n.type === u.STYLE_RULE ? e.push(U(n)) : n.type === u.AT_RULE && e.push($(n)), l = n.end, n.has_next && (n.next_sibling && f(n.end, n.next_sibling.start, 0) || e.push(p));
219
220
  }
220
- let l = f(i, t.end, 0);
221
- return l && e.push(l), e.join(E);
221
+ let i = f(l, t.end, 0);
222
+ return i && e.push(i), e.join(E);
222
223
  }
223
224
  return q(Q).trimEnd();
224
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/format-css",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Fast, small, zero-config library to format or minify CSS with basic rules.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,6 +60,6 @@
60
60
  "singleQuote": true
61
61
  },
62
62
  "dependencies": {
63
- "@projectwallace/css-parser": "^0.12.3"
63
+ "@projectwallace/css-parser": "^0.13.1"
64
64
  }
65
65
  }