@projectwallace/format-css 1.4.2 → 1.4.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 +59 -59
- package/dist/format-css.umd.cjs +2 -2
- package/package.json +9 -2
package/dist/format-css.js
CHANGED
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import
|
|
2
|
-
const f = " ", u = "", b = ":", m = ";", S = '"', L = "(",
|
|
3
|
-
function
|
|
4
|
-
return /[A-Z]/.test(
|
|
1
|
+
import Z from "css-tree/parser";
|
|
2
|
+
const f = " ", u = "", b = ":", m = ";", S = '"', L = "(", A = ")", z = "[", F = "]", x = "Atrule", Y = "Rule", $ = "Block", w = "SelectorList", B = "Selector", k = "Declaration", v = "Operator";
|
|
3
|
+
function o(a) {
|
|
4
|
+
return /[A-Z]/.test(a) ? a.toLowerCase() : a;
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
let U =
|
|
6
|
+
function G(a, { minify: c = !1 } = {}) {
|
|
7
|
+
let U = Z(a, {
|
|
8
8
|
positions: !0,
|
|
9
9
|
parseAtrulePrelude: !1,
|
|
10
10
|
parseCustomProperty: !0,
|
|
11
11
|
parseValue: !0
|
|
12
12
|
});
|
|
13
|
-
const
|
|
14
|
-
`,
|
|
15
|
-
let
|
|
13
|
+
const s = c ? u : `
|
|
14
|
+
`, _ = c ? u : f, D = c ? u : m;
|
|
15
|
+
let i = 0;
|
|
16
16
|
function E(n) {
|
|
17
|
-
return
|
|
17
|
+
return c ? u : " ".repeat(n);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function y(n) {
|
|
20
20
|
let e = n.loc;
|
|
21
|
-
return e ?
|
|
22
|
-
}
|
|
23
|
-
function M(n) {
|
|
24
|
-
let e = n.loc;
|
|
25
|
-
return e ? s.slice(e.start.offset, e.end.offset) : u;
|
|
21
|
+
return e ? a.slice(e.start.offset, e.end.offset) : u;
|
|
26
22
|
}
|
|
27
23
|
function R(n) {
|
|
28
24
|
let e, r = n.prelude, t = n.block;
|
|
29
|
-
return r.type ===
|
|
25
|
+
return r.type === w && (e = K(r)), t.type === $ && (e += N(t)), e;
|
|
30
26
|
}
|
|
31
|
-
function
|
|
27
|
+
function K(n) {
|
|
32
28
|
let e = u;
|
|
33
29
|
return n.children.forEach((r, t) => {
|
|
34
|
-
r.type ===
|
|
30
|
+
r.type === B && (e += E(i) + T(r)), t.next !== null && (e += "," + s);
|
|
35
31
|
}), e;
|
|
36
32
|
}
|
|
37
33
|
function T(n) {
|
|
38
34
|
let e = u;
|
|
39
35
|
return (n.children || []).forEach((t) => {
|
|
40
36
|
switch (t.type) {
|
|
37
|
+
case "TypeSelector": {
|
|
38
|
+
e += o(t.name);
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
41
|
case "Combinator": {
|
|
42
42
|
e += f, t.name !== " " && (e += t.name + f);
|
|
43
43
|
break;
|
|
44
44
|
}
|
|
45
45
|
case "PseudoElementSelector": {
|
|
46
|
-
e += b + b, e +=
|
|
46
|
+
e += b + b, e += o(t.name);
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
49
|
case "PseudoClassSelector": {
|
|
50
50
|
e += b;
|
|
51
|
-
let l =
|
|
52
|
-
(l === "before" || l === "after") && (e += b), e += l, t.children && (e += L + T(t) +
|
|
51
|
+
let l = o(t.name);
|
|
52
|
+
(l === "before" || l === "after") && (e += b), e += l, t.children && (e += L + T(t) + A);
|
|
53
53
|
break;
|
|
54
54
|
}
|
|
55
|
-
case
|
|
56
|
-
t.children.forEach((l,
|
|
57
|
-
l.type ===
|
|
55
|
+
case w: {
|
|
56
|
+
t.children.forEach((l, p) => {
|
|
57
|
+
l.type === B && (e += T(l)), p.next && (e += "," + f);
|
|
58
58
|
});
|
|
59
59
|
break;
|
|
60
60
|
}
|
|
@@ -62,72 +62,72 @@ function j(s, { minify: c = !1 } = {}) {
|
|
|
62
62
|
let l = t.nth;
|
|
63
63
|
if (l)
|
|
64
64
|
if (l.type === "AnPlusB") {
|
|
65
|
-
let
|
|
66
|
-
|
|
65
|
+
let p = l.a, P = l.b;
|
|
66
|
+
p !== null && (e += p + "n"), p !== null && P !== null && (e += f), P !== null && (p !== null && !P.startsWith("-") && (e += "+" + f), e += P);
|
|
67
67
|
} else
|
|
68
|
-
e +=
|
|
68
|
+
e += y(l);
|
|
69
69
|
t.selector !== null && (e += f + "of" + f + T(t.selector));
|
|
70
70
|
break;
|
|
71
71
|
}
|
|
72
72
|
case "AttributeSelector": {
|
|
73
|
-
e +=
|
|
73
|
+
e += z, e += t.name.name, t.matcher && t.value && (e += t.matcher, e += S, t.value.type === "String" ? e += t.value.value : t.value.type === "Identifier" && (e += t.value.name), e += S), t.flags && (e += f + t.flags), e += F;
|
|
74
74
|
break;
|
|
75
75
|
}
|
|
76
76
|
default: {
|
|
77
|
-
e +=
|
|
77
|
+
e += y(t);
|
|
78
78
|
break;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}), e;
|
|
82
82
|
}
|
|
83
83
|
function N(n) {
|
|
84
|
-
let e = n.children, r =
|
|
85
|
-
return e.isEmpty ? r + "{}" : (r += "{" +
|
|
86
|
-
t.type ===
|
|
87
|
-
}),
|
|
84
|
+
let e = n.children, r = _;
|
|
85
|
+
return e.isEmpty ? r + "{}" : (r += "{" + s, i++, e.forEach((t, l) => {
|
|
86
|
+
t.type === k ? (r += H(t), l.next === null ? r += D : r += m) : (l.prev !== null && l.prev.data.type === k && (r += s), t.type === Y ? r += R(t) : t.type === x ? r += g(t) : r += O(t, i)), l.next !== null && (r += s, t.type !== k && (r += s));
|
|
87
|
+
}), i--, r += s, r += E(i) + "}", r);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
let e = E(
|
|
91
|
-
return e +=
|
|
89
|
+
function g(n) {
|
|
90
|
+
let e = E(i) + "@", r = n.prelude, t = n.block;
|
|
91
|
+
return e += o(n.name), r !== null && (e += f + M(r)), t === null ? e += m : t.type === $ && (e += N(t)), e;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
let e =
|
|
95
|
-
return e.replace(/\s*([:,])/g, e.includes("selector(") ? "$1" : "$1 ").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(/\)([a-zA-Z])/g, ") $1").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])", "g"), " $1 ").replace(/\s+/g, f);
|
|
93
|
+
function M(n) {
|
|
94
|
+
let e = y(n);
|
|
95
|
+
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, f).replace(/selector|url|supports|layer\(/ig, (r) => o(r));
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function H(n) {
|
|
98
98
|
let e = n.property;
|
|
99
|
-
e.charCodeAt(0) === 45 && e.charCodeAt(1) === 45 || (e =
|
|
100
|
-
let r =
|
|
101
|
-
return e === "font" && (r = r.replace(/\s*\/\s*/, "/")), r === u && c && (r += f), E(
|
|
99
|
+
e.charCodeAt(0) === 45 && e.charCodeAt(1) === 45 || (e = o(e));
|
|
100
|
+
let r = I(n.value);
|
|
101
|
+
return e === "font" && (r = r.replace(/\s*\/\s*/, "/")), r === u && c && (r += f), E(i) + e + b + _ + r;
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function C(n) {
|
|
104
104
|
let e = u;
|
|
105
105
|
return n.forEach((r, t) => {
|
|
106
|
-
r.type === "Identifier" ? e += r.name : r.type === "Function" ? e +=
|
|
106
|
+
r.type === "Identifier" ? e += r.name : r.type === "Function" ? e += o(r.name) + L + C(r.children) + A : r.type === "Dimension" ? e += r.value + o(r.unit) : r.type === "Value" ? e += I(r) : r.type === v ? e += V(r) : r.type === "Parentheses" ? e += L + C(r.children) + A : r.type === "Url" ? e += "url(" + S + r.value + S + A : e += y(r), r.type !== v && t.next !== null && t.next.data.type !== v && (e += f);
|
|
107
107
|
}), e;
|
|
108
108
|
}
|
|
109
|
-
function
|
|
109
|
+
function V(n) {
|
|
110
110
|
let e = u, r = n.value.trim(), t = r.charCodeAt(0);
|
|
111
|
-
return t === 43 || t === 45 ? e += f : t !== 44 && (e +=
|
|
111
|
+
return t === 43 || t === 45 ? e += f : t !== 44 && (e += _), e += r, t === 43 || t === 45 ? e += f : e += _, e;
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
return n.type === "Raw" ?
|
|
113
|
+
function I(n) {
|
|
114
|
+
return n.type === "Raw" ? O(n, 0) : C(n.children);
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
return E(e) +
|
|
116
|
+
function O(n, e) {
|
|
117
|
+
return E(e) + y(n).trim();
|
|
118
118
|
}
|
|
119
|
-
function
|
|
119
|
+
function W(n) {
|
|
120
120
|
let e = u;
|
|
121
121
|
return n.children.forEach((t, l) => {
|
|
122
|
-
t.type ===
|
|
122
|
+
t.type === Y ? e += R(t) : t.type === x ? e += g(t) : e += O(t, i), l.next !== null && (e += s + s);
|
|
123
123
|
}), e;
|
|
124
124
|
}
|
|
125
|
-
return
|
|
125
|
+
return W(U);
|
|
126
126
|
}
|
|
127
|
-
function
|
|
128
|
-
return
|
|
127
|
+
function j(a) {
|
|
128
|
+
return G(a, { minify: !0 });
|
|
129
129
|
}
|
|
130
130
|
export {
|
|
131
|
-
|
|
132
|
-
|
|
131
|
+
G as format,
|
|
132
|
+
j as minify
|
|
133
133
|
};
|
package/dist/format-css.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`,
|
|
1
|
+
(function(s,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("css-tree/parser")):typeof define=="function"&&define.amd?define(["exports","css-tree/parser"],E):(s=typeof globalThis<"u"?globalThis:s||self,E(s.formatCss={},s.parse))})(this,function(s,E){"use strict";const f=" ",u="",y=":",O=";",S='"',L="(",P=")",K="[",j="]",g="Atrule",I="Rule",x="Block",Y="SelectorList",$="Selector",v="Declaration",k="Operator";function a(i){return/[A-Z]/.test(i)?i.toLowerCase():i}function w(i,{minify:b=!1}={}){let V=E(i,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!0,parseValue:!0});const o=b?u:`
|
|
2
|
+
`,m=b?u:f,W=b?u:O;let p=0;function _(n){return b?u:" ".repeat(n)}function T(n){let e=n.loc;return e?i.slice(e.start.offset,e.end.offset):u}function B(n){let e,r=n.prelude,t=n.block;return r.type===Y&&(e=Z(r)),t.type===x&&(e+=M(t)),e}function Z(n){let e=u;return n.children.forEach((r,t)=>{r.type===$&&(e+=_(p)+C(r)),t.next!==null&&(e+=","+o)}),e}function C(n){let e=u;return(n.children||[]).forEach(t=>{switch(t.type){case"TypeSelector":{e+=a(t.name);break}case"Combinator":{e+=f,t.name!==" "&&(e+=t.name+f);break}case"PseudoElementSelector":{e+=y+y,e+=a(t.name);break}case"PseudoClassSelector":{e+=y;let l=a(t.name);(l==="before"||l==="after")&&(e+=y),e+=l,t.children&&(e+=L+C(t)+P);break}case Y:{t.children.forEach((l,c)=>{l.type===$&&(e+=C(l)),c.next&&(e+=","+f)});break}case"Nth":{let l=t.nth;if(l)if(l.type==="AnPlusB"){let c=l.a,A=l.b;c!==null&&(e+=c+"n"),c!==null&&A!==null&&(e+=f),A!==null&&(c!==null&&!A.startsWith("-")&&(e+="+"+f),e+=A)}else e+=T(l);t.selector!==null&&(e+=f+"of"+f+C(t.selector));break}case"AttributeSelector":{e+=K,e+=t.name.name,t.matcher&&t.value&&(e+=t.matcher,e+=S,t.value.type==="String"?e+=t.value.value:t.value.type==="Identifier"&&(e+=t.value.name),e+=S),t.flags&&(e+=f+t.flags),e+=j;break}default:{e+=T(t);break}}}),e}function M(n){let e=n.children,r=m;return e.isEmpty?r+"{}":(r+="{"+o,p++,e.forEach((t,l)=>{t.type===v?(r+=z(t),l.next===null?r+=W:r+=O):(l.prev!==null&&l.prev.data.type===v&&(r+=o),t.type===I?r+=B(t):t.type===g?r+=U(t):r+=N(t,p)),l.next!==null&&(r+=o,t.type!==v&&(r+=o))}),p--,r+=o,r+=_(p)+"}",r)}function U(n){let e=_(p)+"@",r=n.prelude,t=n.block;return e+=a(n.name),r!==null&&(e+=f+q(r)),t===null?e+=O:t.type===x&&(e+=M(t)),e}function q(n){let e=T(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,f).replace(/selector|url|supports|layer\(/ig,r=>a(r))}function z(n){let e=n.property;e.charCodeAt(0)===45&&e.charCodeAt(1)===45||(e=a(e));let r=D(n.value);return e==="font"&&(r=r.replace(/\s*\/\s*/,"/")),r===u&&b&&(r+=f),_(p)+e+y+m+r}function R(n){let e=u;return n.forEach((r,t)=>{r.type==="Identifier"?e+=r.name:r.type==="Function"?e+=a(r.name)+L+R(r.children)+P:r.type==="Dimension"?e+=r.value+a(r.unit):r.type==="Value"?e+=D(r):r.type===k?e+=F(r):r.type==="Parentheses"?e+=L+R(r.children)+P:r.type==="Url"?e+="url("+S+r.value+S+P:e+=T(r),r.type!==k&&t.next!==null&&t.next.data.type!==k&&(e+=f)}),e}function F(n){let e=u,r=n.value.trim(),t=r.charCodeAt(0);return t===43||t===45?e+=f:t!==44&&(e+=m),e+=r,t===43||t===45?e+=f:e+=m,e}function D(n){return n.type==="Raw"?N(n,0):R(n.children)}function N(n,e){return _(e)+T(n).trim()}function G(n){let e=u;return n.children.forEach((t,l)=>{t.type===I?e+=B(t):t.type===g?e+=U(t):e+=N(t,p),l.next!==null&&(e+=o+o)}),e}return G(V)}function H(i){return w(i,{minify:!0})}s.format=w,s.minify=H,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/format-css",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Fast, small, zero-config library to format CSS with basic rules.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/projectwallace/format-css.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/projectwallace/format-css",
|
|
10
|
+
"issues": "https://github.com/projectwallace/format-css/issues",
|
|
11
|
+
"license": "MIT",
|
|
5
12
|
"type": "module",
|
|
6
13
|
"source": "index.js",
|
|
7
14
|
"exports": {
|
|
@@ -32,7 +39,7 @@
|
|
|
32
39
|
"vite-plugin-dts": "^4.0.0-beta.1"
|
|
33
40
|
},
|
|
34
41
|
"dependencies": {
|
|
35
|
-
"css-tree": "^
|
|
42
|
+
"css-tree": "^3.0.0"
|
|
36
43
|
},
|
|
37
44
|
"files": [
|
|
38
45
|
"dist"
|