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