@projectwallace/format-css 1.5.1 → 1.5.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/dist/format-css.js +62 -65
- package/dist/format-css.umd.cjs +2 -2
- package/package.json +1 -1
package/dist/format-css.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import X from "css-tree/parser";
|
|
2
|
-
const a = " ",
|
|
3
|
-
function
|
|
2
|
+
const a = " ", i = "", N = ":", x = ";", L = '"', I = "(", v = ")", h = "[", d = "]", D = "{", H = "}", ee = "{}", V = "Atrule", W = "Rule", Z = "Block", z = "SelectorList", F = "Selector", Y = "Declaration", B = "Operator";
|
|
3
|
+
function b(_) {
|
|
4
4
|
return /[A-Z]/.test(_) ? _.toLowerCase() : _;
|
|
5
5
|
}
|
|
6
6
|
function te(_, { minify: C = !1 } = {}) {
|
|
7
|
-
let
|
|
7
|
+
let T = [], R = X(_, {
|
|
8
8
|
positions: !0,
|
|
9
9
|
parseAtrulePrelude: !1,
|
|
10
10
|
parseCustomProperty: !0,
|
|
11
11
|
parseValue: !0,
|
|
12
12
|
onComment: (n, e) => {
|
|
13
|
-
|
|
13
|
+
T.push(e.start.offset, e.end.offset);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
const u = C ?
|
|
17
|
-
`, P = C ?
|
|
16
|
+
const u = C ? i : `
|
|
17
|
+
`, P = C ? i : a, G = C ? i : x;
|
|
18
18
|
let s = 0;
|
|
19
|
-
function
|
|
20
|
-
return C ?
|
|
19
|
+
function o(n) {
|
|
20
|
+
return C ? i : " ".repeat(n);
|
|
21
21
|
}
|
|
22
|
-
function
|
|
22
|
+
function S(n) {
|
|
23
23
|
let e = n.loc;
|
|
24
|
-
return e ? _.slice(e.start.offset, e.end.offset) :
|
|
24
|
+
return e ? _.slice(e.start.offset, e.end.offset) : i;
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function y(n) {
|
|
27
27
|
return /** @type {import('css-tree').CssLocation} */ n.loc.start.offset;
|
|
28
28
|
}
|
|
29
29
|
function c(n) {
|
|
@@ -31,56 +31,53 @@ function te(_, { minify: C = !1 } = {}) {
|
|
|
31
31
|
}
|
|
32
32
|
function E(n, e) {
|
|
33
33
|
if (C || n === void 0 || e === void 0)
|
|
34
|
-
return
|
|
34
|
+
return i;
|
|
35
35
|
let t = "";
|
|
36
|
-
for (let r = 0; r <
|
|
37
|
-
let l =
|
|
36
|
+
for (let r = 0; r < T.length; r += 2) {
|
|
37
|
+
let l = T[r];
|
|
38
38
|
if (l === void 0 || l < n) continue;
|
|
39
|
-
let f =
|
|
39
|
+
let f = T[r + 1];
|
|
40
40
|
if (f === void 0 || f > e) break;
|
|
41
|
-
t.length > 0 && (t += u +
|
|
41
|
+
t.length > 0 && (t += u + o(s)), t += _.slice(l, f);
|
|
42
42
|
}
|
|
43
43
|
return t;
|
|
44
44
|
}
|
|
45
45
|
function $(n) {
|
|
46
46
|
let e, t = n.prelude, r = n.block;
|
|
47
47
|
t.type === z && (e = Q(t));
|
|
48
|
-
let l = E(c(t),
|
|
49
|
-
return l && (e += u +
|
|
48
|
+
let l = E(c(t), y(r));
|
|
49
|
+
return l && (e += u + o(s) + l), r.type === Z && (e += w(r)), e;
|
|
50
50
|
}
|
|
51
51
|
function Q(n) {
|
|
52
|
-
let e =
|
|
52
|
+
let e = i;
|
|
53
53
|
return n.children.forEach((t, r) => {
|
|
54
|
-
t.type === F && (e +=
|
|
55
|
-
let l = r.next !== null ?
|
|
56
|
-
f && (e +=
|
|
54
|
+
t.type === F && (e += o(s) + A(t)), r.next !== null && (e += "," + u);
|
|
55
|
+
let l = r.next !== null ? y(r.next.data) : c(n), f = E(c(t), l);
|
|
56
|
+
f && (e += o(s) + f + u);
|
|
57
57
|
}), e;
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
let e =
|
|
59
|
+
function A(n) {
|
|
60
|
+
let e = i;
|
|
61
61
|
return (n.children || []).forEach((r) => {
|
|
62
62
|
switch (r.type) {
|
|
63
63
|
case "TypeSelector": {
|
|
64
|
-
e +=
|
|
64
|
+
e += b(r.name);
|
|
65
65
|
break;
|
|
66
66
|
}
|
|
67
67
|
case "Combinator": {
|
|
68
68
|
e += a, r.name !== " " && (e += r.name + a);
|
|
69
69
|
break;
|
|
70
70
|
}
|
|
71
|
+
case "PseudoClassSelector":
|
|
71
72
|
case "PseudoElementSelector": {
|
|
72
|
-
e +=
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
case "PseudoClassSelector": {
|
|
76
|
-
e += A;
|
|
77
|
-
let l = y(r.name);
|
|
78
|
-
(l === "before" || l === "after") && (e += A), e += l, r.children && (e += I + S(r) + k);
|
|
73
|
+
e += N;
|
|
74
|
+
let l = b(r.name);
|
|
75
|
+
(l === "before" || l === "after" || r.type === "PseudoElementSelector") && (e += N), e += l, r.children && (e += I + A(r) + v);
|
|
79
76
|
break;
|
|
80
77
|
}
|
|
81
78
|
case z: {
|
|
82
79
|
r.children.forEach((l, f) => {
|
|
83
|
-
l.type === F && (e +=
|
|
80
|
+
l.type === F && (e += A(l)), f.next && (e += "," + a);
|
|
84
81
|
});
|
|
85
82
|
break;
|
|
86
83
|
}
|
|
@@ -91,16 +88,16 @@ function te(_, { minify: C = !1 } = {}) {
|
|
|
91
88
|
let f = l.a, p = l.b;
|
|
92
89
|
f !== null && (e += f + "n"), f !== null && p !== null && (e += a), p !== null && (f !== null && !p.startsWith("-") && (e += "+" + a), e += p);
|
|
93
90
|
} else
|
|
94
|
-
e +=
|
|
95
|
-
r.selector !== null && (e += a + "of" + a +
|
|
91
|
+
e += S(l);
|
|
92
|
+
r.selector !== null && (e += a + "of" + a + A(r.selector));
|
|
96
93
|
break;
|
|
97
94
|
}
|
|
98
95
|
case "AttributeSelector": {
|
|
99
|
-
e += h, e += r.name.name, r.matcher && r.value && (e += r.matcher, e +=
|
|
96
|
+
e += h, e += r.name.name, r.matcher && r.value && (e += r.matcher, e += L, r.value.type === "String" ? e += r.value.value : r.value.type === "Identifier" && (e += r.value.name), e += L), r.flags && (e += a + r.flags), e += d;
|
|
100
97
|
break;
|
|
101
98
|
}
|
|
102
99
|
default: {
|
|
103
|
-
e +=
|
|
100
|
+
e += S(r);
|
|
104
101
|
break;
|
|
105
102
|
}
|
|
106
103
|
}
|
|
@@ -109,70 +106,70 @@ function te(_, { minify: C = !1 } = {}) {
|
|
|
109
106
|
function w(n) {
|
|
110
107
|
let e = n.children, t = P;
|
|
111
108
|
if (e.isEmpty) {
|
|
112
|
-
let f = E(
|
|
113
|
-
return f ? (t += D + u, t +=
|
|
109
|
+
let f = E(y(n), c(n));
|
|
110
|
+
return f ? (t += D + u, t += o(s + 1) + f, t += u + o(s) + H, t) : t + ee;
|
|
114
111
|
}
|
|
115
112
|
t += D + u, s++;
|
|
116
|
-
let r = E(
|
|
113
|
+
let r = E(y(n), y(
|
|
117
114
|
/** @type {import('css-tree').CssNode} */
|
|
118
115
|
e.first
|
|
119
116
|
));
|
|
120
|
-
r && (t +=
|
|
117
|
+
r && (t += o(s) + r + u), e.forEach((f, p) => {
|
|
121
118
|
if (p.prev !== null) {
|
|
122
|
-
let U = E(c(p.prev.data),
|
|
123
|
-
U && (t +=
|
|
119
|
+
let U = E(c(p.prev.data), y(f));
|
|
120
|
+
U && (t += o(s) + U + u);
|
|
124
121
|
}
|
|
125
|
-
f.type === Y ? (t += q(f), p.next === null ? t += G : t += x) : (p.prev !== null && p.prev.data.type === Y && (t += u), f.type === W ? t += $(f) : f.type === V ? t += K(f) : t +=
|
|
122
|
+
f.type === Y ? (t += q(f), p.next === null ? t += G : t += x) : (p.prev !== null && p.prev.data.type === Y && (t += u), f.type === W ? t += $(f) : f.type === V ? t += K(f) : t += k(f, s)), p.next !== null && (t += u, f.type !== Y && (t += u));
|
|
126
123
|
});
|
|
127
124
|
let l = E(c(
|
|
128
125
|
/** @type {import('css-tree').CssNode} */
|
|
129
126
|
e.last
|
|
130
127
|
), c(n));
|
|
131
|
-
return l && (t += u +
|
|
128
|
+
return l && (t += u + o(s) + l), s--, t += u + o(s) + H, t;
|
|
132
129
|
}
|
|
133
130
|
function K(n) {
|
|
134
|
-
let e =
|
|
135
|
-
return e +=
|
|
131
|
+
let e = o(s) + "@", t = n.prelude, r = n.block;
|
|
132
|
+
return e += b(n.name), t !== null && (e += a + j(t)), r === null ? e += x : r.type === Z && (e += w(r)), e;
|
|
136
133
|
}
|
|
137
134
|
function j(n) {
|
|
138
|
-
let e =
|
|
139
|
-
return e.replace(/\s*([:,])/g, e.toLowerCase().includes("selector(") ? "$1" : "$1 ").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(/\)([a-zA-Z])/g, ") $1").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])", "g"), " $1 ").replace(/calc\(([^*]*)\*([^*])/g, "calc($1 * $2").replace(/\s+/g, a).replace(/selector|url|supports|layer\(/ig, (t) =>
|
|
135
|
+
let e = S(n);
|
|
136
|
+
return e.replace(/\s*([:,])/g, e.toLowerCase().includes("selector(") ? "$1" : "$1 ").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(/\)([a-zA-Z])/g, ") $1").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])", "g"), " $1 ").replace(/calc\(([^*]*)\*([^*])/g, "calc($1 * $2").replace(/\s+/g, a).replace(/selector|url|supports|layer\(/ig, (t) => b(t));
|
|
140
137
|
}
|
|
141
138
|
function q(n) {
|
|
142
139
|
let e = n.property;
|
|
143
|
-
e.charCodeAt(0) === 45 && e.charCodeAt(1) === 45 || (e =
|
|
140
|
+
e.charCodeAt(0) === 45 && e.charCodeAt(1) === 45 || (e = b(e));
|
|
144
141
|
let t = M(n.value);
|
|
145
|
-
return e === "font" && (t = t.replace(/\s*\/\s*/, "/")), t ===
|
|
142
|
+
return e === "font" && (t = t.replace(/\s*\/\s*/, "/")), t === i && C && (t += a), n.important && (t += P + "!important"), o(s) + e + N + P + t;
|
|
146
143
|
}
|
|
147
144
|
function g(n) {
|
|
148
|
-
let e =
|
|
145
|
+
let e = i;
|
|
149
146
|
return n.forEach((t, r) => {
|
|
150
|
-
t.type === "Identifier" ? e += t.name : t.type === "Function" ? e +=
|
|
147
|
+
t.type === "Identifier" ? e += t.name : t.type === "Function" ? e += b(t.name) + I + g(t.children) + v : t.type === "Dimension" ? e += t.value + b(t.unit) : t.type === "Value" ? e += M(t) : t.type === B ? e += J(t) : t.type === "Parentheses" ? e += I + g(t.children) + v : t.type === "Url" ? e += "url(" + L + t.value + L + v : e += S(t), t.type !== B && r.next !== null && r.next.data.type !== B && (e += a);
|
|
151
148
|
}), e;
|
|
152
149
|
}
|
|
153
150
|
function J(n) {
|
|
154
|
-
let e =
|
|
151
|
+
let e = i, t = n.value.trim(), r = t.charCodeAt(0);
|
|
155
152
|
return r === 43 || r === 45 ? e += a : r !== 44 && (e += P), e += t, r === 43 || r === 45 ? e += a : e += P, e;
|
|
156
153
|
}
|
|
157
154
|
function M(n) {
|
|
158
|
-
return n.type === "Raw" ?
|
|
155
|
+
return n.type === "Raw" ? k(n, 0) : g(n.children);
|
|
159
156
|
}
|
|
160
|
-
function
|
|
161
|
-
return
|
|
157
|
+
function k(n, e) {
|
|
158
|
+
return o(e) + S(n).trim();
|
|
162
159
|
}
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
let n = E(0,
|
|
166
|
-
n && (m += n + u),
|
|
167
|
-
if (t.type === W ? m += $(t) : t.type === V ? m += K(t) : m +=
|
|
160
|
+
let O = R.children, m = i;
|
|
161
|
+
if (O.first) {
|
|
162
|
+
let n = E(0, y(O.first));
|
|
163
|
+
n && (m += n + u), O.forEach((t, r) => {
|
|
164
|
+
if (t.type === W ? m += $(t) : t.type === V ? m += K(t) : m += k(t, s), r.next !== null) {
|
|
168
165
|
m += u;
|
|
169
|
-
let l = E(c(t),
|
|
170
|
-
l && (m +=
|
|
166
|
+
let l = E(c(t), y(r.next.data));
|
|
167
|
+
l && (m += o(s) + l), m += u;
|
|
171
168
|
}
|
|
172
169
|
});
|
|
173
170
|
let e = E(c(
|
|
174
171
|
/** @type {import('css-tree').CssNode} */
|
|
175
|
-
|
|
172
|
+
O.last
|
|
176
173
|
), c(R));
|
|
177
174
|
e && (m += u + e);
|
|
178
175
|
} else
|
package/dist/format-css.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(y,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("css-tree/parser")):typeof define=="function"&&define.amd?define(["exports","css-tree/parser"],P):(y=typeof globalThis<"u"?globalThis:y||self,P(y.formatCss={},y.parse))})(this,function(y,P){"use strict";const i=" ",
|
|
2
|
-
`,
|
|
1
|
+
(function(y,P){typeof exports=="object"&&typeof module<"u"?P(exports,require("css-tree/parser")):typeof define=="function"&&define.amd?define(["exports","css-tree/parser"],P):(y=typeof globalThis<"u"?globalThis:y||self,P(y.formatCss={},y.parse))})(this,function(y,P){"use strict";const i=" ",a="",k=":",N=";",A='"',x="(",L=")",Q="[",h="]",M="{",K="}",J="{}",U="Atrule",D="Rule",j="Block",H="SelectorList",V="Selector",I="Declaration",Y="Operator";function C(_){return/[A-Z]/.test(_)?_.toLowerCase():_}function W(_,{minify:T=!1}={}){let v=[],B=P(_,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!0,parseValue:!0,onComment:(n,e)=>{v.push(e.start.offset,e.end.offset)}});const u=T?a:`
|
|
2
|
+
`,S=T?a:i,d=T?a:N;let s=0;function o(n){return T?a:" ".repeat(n)}function O(n){let e=n.loc;return e?_.slice(e.start.offset,e.end.offset):a}function b(n){return n.loc.start.offset}function c(n){return n.loc.end.offset}function E(n,e){if(T||n===void 0||e===void 0)return a;let t="";for(let r=0;r<v.length;r+=2){let l=v[r];if(l===void 0||l<n)continue;let f=v[r+1];if(f===void 0||f>e)break;t.length>0&&(t+=u+o(s)),t+=_.slice(l,f)}return t}function Z(n){let e,t=n.prelude,r=n.block;t.type===H&&(e=ee(t));let l=E(c(t),b(r));return l&&(e+=u+o(s)+l),r.type===j&&(e+=q(r)),e}function ee(n){let e=a;return n.children.forEach((t,r)=>{t.type===V&&(e+=o(s)+g(t)),r.next!==null&&(e+=","+u);let l=r.next!==null?b(r.next.data):c(n),f=E(c(t),l);f&&(e+=o(s)+f+u)}),e}function g(n){let e=a;return(n.children||[]).forEach(r=>{switch(r.type){case"TypeSelector":{e+=C(r.name);break}case"Combinator":{e+=i,r.name!==" "&&(e+=r.name+i);break}case"PseudoClassSelector":case"PseudoElementSelector":{e+=k;let l=C(r.name);(l==="before"||l==="after"||r.type==="PseudoElementSelector")&&(e+=k),e+=l,r.children&&(e+=x+g(r)+L);break}case H:{r.children.forEach((l,f)=>{l.type===V&&(e+=g(l)),f.next&&(e+=","+i)});break}case"Nth":{let l=r.nth;if(l)if(l.type==="AnPlusB"){let f=l.a,p=l.b;f!==null&&(e+=f+"n"),f!==null&&p!==null&&(e+=i),p!==null&&(f!==null&&!p.startsWith("-")&&(e+="+"+i),e+=p)}else e+=O(l);r.selector!==null&&(e+=i+"of"+i+g(r.selector));break}case"AttributeSelector":{e+=Q,e+=r.name.name,r.matcher&&r.value&&(e+=r.matcher,e+=A,r.value.type==="String"?e+=r.value.value:r.value.type==="Identifier"&&(e+=r.value.name),e+=A),r.flags&&(e+=i+r.flags),e+=h;break}default:{e+=O(r);break}}}),e}function q(n){let e=n.children,t=S;if(e.isEmpty){let f=E(b(n),c(n));return f?(t+=M+u,t+=o(s+1)+f,t+=u+o(s)+K,t):t+J}t+=M+u,s++;let r=E(b(n),b(e.first));r&&(t+=o(s)+r+u),e.forEach((f,p)=>{if(p.prev!==null){let G=E(c(p.prev.data),b(f));G&&(t+=o(s)+G+u)}f.type===I?(t+=re(f),p.next===null?t+=d:t+=N):(p.prev!==null&&p.prev.data.type===I&&(t+=u),f.type===D?t+=Z(f):f.type===U?t+=z(f):t+=w(f,s)),p.next!==null&&(t+=u,f.type!==I&&(t+=u))});let l=E(c(e.last),c(n));return l&&(t+=u+o(s)+l),s--,t+=u+o(s)+K,t}function z(n){let e=o(s)+"@",t=n.prelude,r=n.block;return e+=C(n.name),t!==null&&(e+=i+te(t)),r===null?e+=N:r.type===j&&(e+=q(r)),e}function te(n){let e=O(n);return e.replace(/\s*([:,])/g,e.toLowerCase().includes("selector(")?"$1":"$1 ").replace(/\s*(=>|<=)\s*/g," $1 ").replace(/\)([a-zA-Z])/g,") $1").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])","g")," $1 ").replace(/calc\(([^*]*)\*([^*])/g,"calc($1 * $2").replace(/\s+/g,i).replace(/selector|url|supports|layer\(/ig,t=>C(t))}function re(n){let e=n.property;e.charCodeAt(0)===45&&e.charCodeAt(1)===45||(e=C(e));let t=F(n.value);return e==="font"&&(t=t.replace(/\s*\/\s*/,"/")),t===a&&T&&(t+=i),n.important&&(t+=S+"!important"),o(s)+e+k+S+t}function $(n){let e=a;return n.forEach((t,r)=>{t.type==="Identifier"?e+=t.name:t.type==="Function"?e+=C(t.name)+x+$(t.children)+L:t.type==="Dimension"?e+=t.value+C(t.unit):t.type==="Value"?e+=F(t):t.type===Y?e+=ne(t):t.type==="Parentheses"?e+=x+$(t.children)+L:t.type==="Url"?e+="url("+A+t.value+A+L:e+=O(t),t.type!==Y&&r.next!==null&&r.next.data.type!==Y&&(e+=i)}),e}function ne(n){let e=a,t=n.value.trim(),r=t.charCodeAt(0);return r===43||r===45?e+=i:r!==44&&(e+=S),e+=t,r===43||r===45?e+=i:e+=S,e}function F(n){return n.type==="Raw"?w(n,0):$(n.children)}function w(n,e){return o(e)+O(n).trim()}let R=B.children,m=a;if(R.first){let n=E(0,b(R.first));n&&(m+=n+u),R.forEach((t,r)=>{if(t.type===D?m+=Z(t):t.type===U?m+=z(t):m+=w(t,s),r.next!==null){m+=u;let l=E(c(t),b(r.next.data));l&&(m+=o(s)+l),m+=u}});let e=E(c(R.last),c(B));e&&(m+=u+e)}else m+=E(0,c(B));return m}function X(_){return W(_,{minify:!0})}y.format=W,y.minify=X,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|