@projectwallace/format-css 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.
- package/dist/format-css.js +36 -33
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/format-css.js
CHANGED
|
@@ -5,28 +5,28 @@ function C(y) {
|
|
|
5
5
|
}
|
|
6
6
|
function ne(y, {
|
|
7
7
|
minify: O = !1,
|
|
8
|
-
tab_size:
|
|
8
|
+
tab_size: S = void 0
|
|
9
9
|
} = /* @__PURE__ */ Object.create(null)) {
|
|
10
|
-
if (
|
|
10
|
+
if (S !== void 0 && Number(S) < 1)
|
|
11
11
|
throw new TypeError("tab_size must be a number greater than 0");
|
|
12
|
-
let
|
|
12
|
+
let T = [], k = d(y, {
|
|
13
13
|
positions: !0,
|
|
14
14
|
parseAtrulePrelude: !1,
|
|
15
15
|
parseCustomProperty: !0,
|
|
16
16
|
parseValue: !0,
|
|
17
17
|
onComment: (n, e) => {
|
|
18
|
-
|
|
18
|
+
T.push(e.start.offset, e.end.offset);
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
const u = O ? c : `
|
|
22
22
|
`, p = O ? c : a, h = O ? c : x;
|
|
23
23
|
let s = 0;
|
|
24
24
|
function i(n) {
|
|
25
|
-
return O ? c :
|
|
25
|
+
return O === !0 ? c : S !== void 0 ? a.repeat(S * n) : " ".repeat(n);
|
|
26
26
|
}
|
|
27
27
|
function P(n) {
|
|
28
28
|
let e = n.loc;
|
|
29
|
-
return e ? y.slice(e.start.offset, e.end.offset)
|
|
29
|
+
return e == null ? c : y.slice(e.start.offset, e.end.offset);
|
|
30
30
|
}
|
|
31
31
|
function b(n) {
|
|
32
32
|
return /** @type {import('css-tree').CssLocation} */ n.loc.start.offset;
|
|
@@ -35,13 +35,13 @@ function ne(y, {
|
|
|
35
35
|
return /** @type {import('css-tree').CssLocation} */ n.loc.end.offset;
|
|
36
36
|
}
|
|
37
37
|
function m(n, e) {
|
|
38
|
-
if (O || n === void 0 || e === void 0)
|
|
38
|
+
if (O === !0 || n === void 0 || e === void 0)
|
|
39
39
|
return c;
|
|
40
40
|
let t = "";
|
|
41
|
-
for (let r = 0; r <
|
|
42
|
-
let l =
|
|
41
|
+
for (let r = 0; r < T.length; r += 2) {
|
|
42
|
+
let l = T[r];
|
|
43
43
|
if (l === void 0 || l < n) continue;
|
|
44
|
-
let f =
|
|
44
|
+
let f = T[r + 1];
|
|
45
45
|
if (f === void 0 || f > e) break;
|
|
46
46
|
t.length > 0 && (t += u + i(s)), t += y.slice(l, f);
|
|
47
47
|
}
|
|
@@ -56,12 +56,12 @@ function ne(y, {
|
|
|
56
56
|
function q(n) {
|
|
57
57
|
let e = c;
|
|
58
58
|
return n.children.forEach((t, r) => {
|
|
59
|
-
t.type === Y && (e += i(s) +
|
|
59
|
+
t.type === Y && (e += i(s) + A(t)), r.next !== null && (e += Z + u);
|
|
60
60
|
let l = r.next !== null ? b(r.next.data) : E(n), f = m(E(t), l);
|
|
61
61
|
f && (e += i(s) + f + u);
|
|
62
62
|
}), e;
|
|
63
63
|
}
|
|
64
|
-
function
|
|
64
|
+
function A(n) {
|
|
65
65
|
let e = c;
|
|
66
66
|
return (n.children || []).forEach((r) => {
|
|
67
67
|
switch (r.type) {
|
|
@@ -77,28 +77,31 @@ function ne(y, {
|
|
|
77
77
|
case "PseudoElementSelector": {
|
|
78
78
|
e += $;
|
|
79
79
|
let l = C(r.name);
|
|
80
|
-
(l === "before" || l === "after" || r.type === "PseudoElementSelector") && (e += $), e += l, r.children && (e += I +
|
|
80
|
+
(l === "before" || l === "after" || r.type === "PseudoElementSelector") && (e += $), e += l, r.children !== null && (e += I + A(r) + v);
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
case Q: {
|
|
84
84
|
r.children.forEach((l, f) => {
|
|
85
|
-
l.type === Y && (e +=
|
|
85
|
+
l.type === Y && (e += A(l)), f.next !== null && f.next.data.type === Y && (e += Z + p);
|
|
86
86
|
});
|
|
87
87
|
break;
|
|
88
88
|
}
|
|
89
89
|
case "Nth": {
|
|
90
90
|
let l = r.nth;
|
|
91
|
-
if (l)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
r.selector !== null && (e += a + "of" + a + S(r.selector));
|
|
91
|
+
if (l.type === "AnPlusB") {
|
|
92
|
+
let f = l.a, o = l.b;
|
|
93
|
+
f !== null && (e += f + "n"), f !== null && o !== null && (e += a), o !== null && (f !== null && !o.startsWith("-") && (e += "+" + a), e += o);
|
|
94
|
+
} else
|
|
95
|
+
e += P(l);
|
|
96
|
+
r.selector !== null && (e += a + "of" + a + A(r.selector));
|
|
98
97
|
break;
|
|
99
98
|
}
|
|
100
99
|
case "AttributeSelector": {
|
|
101
|
-
e += ee, e += r.name.name, r.matcher && r.value && (e += r.matcher, e += g, r.value.type === "String" ? e += r.value.value : r.value.type === "Identifier" && (e += r.value.name), e += g), r.flags && (e += a + r.flags), e += te;
|
|
100
|
+
e += ee, e += r.name.name, r.matcher !== null && r.value !== null && (e += r.matcher, e += g, r.value.type === "String" ? e += r.value.value : r.value.type === "Identifier" && (e += r.value.name), e += g), r.flags !== null && (e += a + r.flags), e += te;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case "NestingSelector": {
|
|
104
|
+
e += "&";
|
|
102
105
|
break;
|
|
103
106
|
}
|
|
104
107
|
default: {
|
|
@@ -124,7 +127,7 @@ function ne(y, {
|
|
|
124
127
|
let H = m(E(o.prev.data), b(f));
|
|
125
128
|
H && (t += i(s) + H + u);
|
|
126
129
|
}
|
|
127
|
-
f.type === w ? (t += X(f), o.next === null ? t += h : t += x) : (o.prev !== null && o.prev.data.type === w && (t += u), f.type === F ? t += M(f) : f.type === j ? t += U(f) : t +=
|
|
130
|
+
f.type === w ? (t += X(f), o.next === null ? t += h : t += x) : (o.prev !== null && o.prev.data.type === w && (t += u), f.type === F ? t += M(f) : f.type === j ? t += U(f) : t += R(f, s)), o.next !== null && (t += u, f.type !== w && (t += u));
|
|
128
131
|
});
|
|
129
132
|
let l = m(E(
|
|
130
133
|
/** @type {import('css-tree').CssNode} */
|
|
@@ -147,12 +150,12 @@ function ne(y, {
|
|
|
147
150
|
let e = n.property;
|
|
148
151
|
e.charCodeAt(0) === 45 && e.charCodeAt(1) === 45 || (e = C(e));
|
|
149
152
|
let t = D(n.value);
|
|
150
|
-
return e === "font" && (t = t.replace(/\s*\/\s*/, "/")), t === c && O && (t += a), n.important === !0 ? t += p + "!important" : typeof n.important == "string" && (t += p + "!" + C(n.important)), i(s) + e + $ + p + t;
|
|
153
|
+
return e === "font" && (t = t.replace(/\s*\/\s*/, "/")), t === c && O === !0 && (t += a), n.important === !0 ? t += p + "!important" : typeof n.important == "string" && (t += p + "!" + C(n.important)), i(s) + e + $ + p + t;
|
|
151
154
|
}
|
|
152
|
-
function
|
|
155
|
+
function N(n) {
|
|
153
156
|
let e = c;
|
|
154
157
|
return n.forEach((t, r) => {
|
|
155
|
-
t.type === "Identifier" ? e += t.name : t.type === "Function" ? e += C(t.name) + I +
|
|
158
|
+
t.type === "Identifier" ? e += t.name : t.type === "Function" ? e += C(t.name) + I + N(t.children) + v : t.type === "Dimension" ? e += t.value + C(t.unit) : t.type === "Value" ? e += D(t) : t.type === B ? e += z(t) : t.type === "Parentheses" ? e += I + N(t.children) + v : t.type === "Url" ? e += "url(" + g + t.value + g + v : e += P(t), t.type !== B && r.next !== null && r.next.data.type !== B && (e += a);
|
|
156
159
|
}), e;
|
|
157
160
|
}
|
|
158
161
|
function z(n) {
|
|
@@ -160,16 +163,16 @@ function ne(y, {
|
|
|
160
163
|
return r === 43 || r === 45 ? e += a : r !== 44 && (e += p), e += t, r === 43 || r === 45 ? e += a : e += p, e;
|
|
161
164
|
}
|
|
162
165
|
function D(n) {
|
|
163
|
-
return n.type === "Raw" ?
|
|
166
|
+
return n.type === "Raw" ? R(n, 0) : N(n.children);
|
|
164
167
|
}
|
|
165
|
-
function
|
|
168
|
+
function R(n, e) {
|
|
166
169
|
return i(e) + P(n).trim();
|
|
167
170
|
}
|
|
168
|
-
let L =
|
|
169
|
-
if (L.first) {
|
|
171
|
+
let L = k.children, _ = c;
|
|
172
|
+
if (L.first !== null) {
|
|
170
173
|
let n = m(0, b(L.first));
|
|
171
174
|
n && (_ += n + u), L.forEach((t, r) => {
|
|
172
|
-
if (t.type === F ? _ += M(t) : t.type === j ? _ += U(t) : _ +=
|
|
175
|
+
if (t.type === F ? _ += M(t) : t.type === j ? _ += U(t) : _ += R(t, s), r.next !== null) {
|
|
173
176
|
_ += u;
|
|
174
177
|
let l = m(E(t), b(r.next.data));
|
|
175
178
|
l && (_ += i(s) + l), _ += u;
|
|
@@ -178,10 +181,10 @@ function ne(y, {
|
|
|
178
181
|
let e = m(E(
|
|
179
182
|
/** @type {import('css-tree').CssNode} */
|
|
180
183
|
L.last
|
|
181
|
-
), E(
|
|
184
|
+
), E(k));
|
|
182
185
|
e && (_ += u + e);
|
|
183
186
|
} else
|
|
184
|
-
_ += m(0, E(
|
|
187
|
+
_ += m(0, E(k));
|
|
185
188
|
return _;
|
|
186
189
|
}
|
|
187
190
|
function fe(y) {
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Format a string of CSS using some simple rules
|
|
7
7
|
* @param {string} css The original CSS
|
|
8
|
-
* @param {Options} options
|
|
8
|
+
* @param {Options} [options]
|
|
9
9
|
* @returns {string} The formatted CSS
|
|
10
10
|
*/
|
|
11
11
|
export function format(css: string, { minify, tab_size, }?: Options): string;
|