@projectwallace/format-css 1.3.4 → 1.3.5

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.
@@ -1,5 +1,5 @@
1
1
  import g from "css-tree/parser";
2
- const i = " ", a = "", s = ":", T = ";", P = "Atrule", A = "Rule", O = "Block", _ = "SelectorList", k = "Selector", L = "Declaration", m = "Operator";
2
+ const i = " ", a = "", s = ":", T = ";", A = "Atrule", P = "Rule", O = "Block", _ = "SelectorList", k = "Selector", L = "Declaration", m = "Operator";
3
3
  let o = `
4
4
  `, S = " ", c = " ", w = ";";
5
5
  function E(n) {
@@ -15,15 +15,15 @@ function C(n, r) {
15
15
  let t = e.start, f = e.end, u = r.substring(t.offset, f.offset);
16
16
  return t.line === f.line ? u : u.replace(/\s+/g, i);
17
17
  }
18
- function B(n, r) {
18
+ function $(n, r) {
19
19
  let e = n.loc;
20
20
  return e ? r.substring(e.start.offset, e.end.offset) : a;
21
21
  }
22
22
  function R(n, r, e) {
23
23
  let t, f = n.prelude, u = n.block;
24
- return f.type === _ ? t = $(f, r, e) : t = b(f, r, e), u.type === O && (t += N(u, r, e)), t;
24
+ return f.type === _ ? t = B(f, r, e) : t = b(f, r, e), u.type === O && (t += N(u, r, e)), t;
25
25
  }
26
- function $(n, r, e) {
26
+ function B(n, r, e) {
27
27
  let t = a;
28
28
  return n.children.forEach((u, l) => {
29
29
  u.type === k ? t += h(u, r, e) : t += b(u, r, e), l.next !== null && (t += "," + o);
@@ -77,7 +77,7 @@ function h(n, r, e) {
77
77
  function N(n, r, e) {
78
78
  let t = n.children, f = c;
79
79
  return t.isEmpty ? f + "{}" : (f += "{" + o, e++, t.forEach((u, l) => {
80
- u.type === L ? (f += M(u, r, e), l.next === null ? f += w : f += T) : (l.prev !== null && l.prev.data.type === L && (f += o), u.type === A ? f += R(u, r, e) : u.type === P ? f += x(u, r, e) : f += b(u, r, e)), l.next !== null && (f += o, u.type !== L && (f += o));
80
+ u.type === L ? (f += M(u, r, e), l.next === null ? f += w : f += T) : (l.prev !== null && l.prev.data.type === L && (f += o), u.type === P ? f += R(u, r, e) : u.type === A ? f += x(u, r, e) : f += b(u, r, e)), l.next !== null && (f += o, u.type !== L && (f += o));
81
81
  }), e--, f += o, f += E(e) + "}", f);
82
82
  }
83
83
  function x(n, r, e) {
@@ -86,7 +86,7 @@ function x(n, r, e) {
86
86
  }
87
87
  function D(n, r) {
88
88
  let e = C(n, r);
89
- return e.replace(/\s*([:,])/g, e.includes("selector(") ? "$1" : "$1 ").replace(/\s*(=>|<=)\s*/g, " $1 ").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])", "g"), " $1 ").replace(/\s+/g, i);
89
+ 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, i);
90
90
  }
91
91
  function M(n, r, e) {
92
92
  let t = n.property;
@@ -125,15 +125,15 @@ function V(n, r) {
125
125
  return p(e) && (t = e.toLowerCase()), t += "(", t += I(n.children, r), t += ")", t;
126
126
  }
127
127
  function b(n, r, e) {
128
- return E(e) + B(n, r).trim();
128
+ return E(e) + $(n, r).trim();
129
129
  }
130
130
  function W(n, r, e = 0) {
131
131
  let t = a;
132
132
  return n.children.forEach((u, l) => {
133
- u.type === A ? t += R(u, r, e) : u.type === P ? t += x(u, r, e) : t += b(u, r, e), l.next !== null && (t += o + o);
133
+ u.type === P ? t += R(u, r, e) : u.type === A ? t += x(u, r, e) : t += b(u, r, e), l.next !== null && (t += o + o);
134
134
  }), t;
135
135
  }
136
- function F(n, { minify: r = !1 } = {}) {
136
+ function Z(n, { minify: r = !1 } = {}) {
137
137
  let e = g(n, {
138
138
  positions: !0,
139
139
  parseAtrulePrelude: !1,
@@ -143,10 +143,10 @@ function F(n, { minify: r = !1 } = {}) {
143
143
  return S = r ? a : " ", o = r ? a : `
144
144
  `, c = r ? a : i, w = r ? a : T, W(e, n, 0);
145
145
  }
146
- function K(n) {
147
- return F(n, { minify: !0 });
146
+ function F(n) {
147
+ return Z(n, { minify: !0 });
148
148
  }
149
149
  export {
150
- F as format,
151
- K as minify
150
+ Z as format,
151
+ F as minify
152
152
  };
@@ -1,3 +1,3 @@
1
1
  (function(s,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("css-tree/parser")):typeof define=="function"&&define.amd?define(["exports","css-tree/parser"],c):(s=typeof globalThis<"u"?globalThis:s||self,c(s.formatCss={},s.parse))})(this,function(s,c){"use strict";const i=" ",o="",b=":",L=";",O="Atrule",S="Rule",_="Block",k="SelectorList",w="Selector",P="Declaration",A="Operator";let a=`
2
- `,R=" ",y=" ",N=";";function E(n){return R.repeat(n)}function p(n){return/[A-Z]/.test(n)}function C(n,r){let e=n.loc;if(!e)return o;let t=e.start,f=e.end,u=r.substring(t.offset,f.offset);return t.line===f.line?u:u.replace(/\s+/g,i)}function M(n,r){let e=n.loc;return e?r.substring(e.start.offset,e.end.offset):o}function x(n,r,e){let t,f=n.prelude,u=n.block;return f.type===k?t=$(f,r,e):t=m(f,r,e),u.type===_&&(t+=I(u,r,e)),t}function $(n,r,e){let t=o;return n.children.forEach((u,l)=>{u.type===w?t+=D(u,r,e):t+=m(u,r,e),l.next!==null&&(t+=","+a)}),t}function T(n,r){let e=o;return n.children&&n.children.forEach(t=>{switch(t.type){case"Combinator":{e+=i,t.name!==" "&&(e+=t.name+i);break}case"PseudoElementSelector":{e+=b+b,e+=p(t.name)?t.name.toLowerCase():t.name;break}case"PseudoClassSelector":{e+=b;let f=t.name,u=p(f)?f.toLowerCase():f;(u==="before"||u==="after")&&(e+=b),e+=u,t.children&&(e+="("+T(t,r)+")");break}case k:{t.children.forEach((f,u)=>{f.type===w&&(e+=T(f,r)),u.next&&(e+=","+i)});break}case"Nth":{let f=t.nth;if(f)if(f.type==="AnPlusB"){let u=f.a,l=f.b;u!==null&&(e+=u+"n"),u!==null&&l!==null&&(e+=i),l!==null&&(u!==null&&!l.startsWith("-")&&(e+="+"+i),e+=l)}else e+=C(t.nth,r);t.selector!==null&&(e+=i+"of"+i+T(t.selector,r));break}default:{e+=C(t,r);break}}}),e}function D(n,r,e){return E(e)+T(n,r)}function I(n,r,e){let t=n.children,f=y;return t.isEmpty?f+"{}":(f+="{"+a,e++,t.forEach((u,l)=>{u.type===P?(f+=U(u,r,e),l.next===null?f+=N:f+=L):(l.prev!==null&&l.prev.data.type===P&&(f+=a),u.type===S?f+=x(u,r,e):u.type===O?f+=Y(u,r,e):f+=m(u,r,e)),l.next!==null&&(f+=a,u.type!==P&&(f+=a))}),e--,f+=a,f+=E(e)+"}",f)}function Y(n,r,e){let t=E(e)+"@",f=n.name,u=n.prelude,l=n.block;return t+=p(f)?f.toLowerCase():f,u!==null&&(t+=i+j(u,r)),l===null?t+=L:l.type===_&&(t+=I(l,r,e)),t}function j(n,r){let e=C(n,r);return e.replace(/\s*([:,])/g,e.includes("selector(")?"$1":"$1 ").replace(/\s*(=>|<=)\s*/g," $1 ").replace(new RegExp("(?<!<=)(?<!=>)(?<!<= )([<>])(?![<= ])(?![=> ])(?![ =>])","g")," $1 ").replace(/\s+/g,i)}function U(n,r,e){let t=n.property;t.charCodeAt(0)===45&&t.charCodeAt(1)===45||p(t)&&(t=t.toLowerCase());let f=h(n.value,r);return t==="font"&&(f=f.replace(/\s*\/\s*/,"/")),E(e)+t+b+y+f}function g(n,r){let e=o;return n.forEach((t,f)=>{if(t.type==="Identifier")e+=t.name;else if(t.type==="Function")e+=W(t,r);else if(t.type==="Dimension")e+=V(t);else if(t.type==="Value")e+=h(t,r);else if(t.type===A){let u=t.value.trim(),l=u.charCodeAt(0);l===43||l===45?e+=i:l!==44&&(e+=y),e+=u,l===43||l===45?e+=i:e+=y}else e+=C(t,r);t.type!==A&&f.next!==null&&f.next.data.type!==A&&(e+=i)}),e}function V(n){let r=n.unit,e=n.value;return e+=p(r)?r.toLowerCase():r,e}function h(n,r){return n.type==="Raw"?m(n,r,0):g(n.children,r)}function W(n,r){let e=n.name,t=e;return p(e)&&(t=e.toLowerCase()),t+="(",t+=g(n.children,r),t+=")",t}function m(n,r,e){return E(e)+M(n,r).trim()}function q(n,r,e=0){let t=o;return n.children.forEach((u,l)=>{u.type===S?t+=x(u,r,e):u.type===O?t+=Y(u,r,e):t+=m(u,r,e),l.next!==null&&(t+=a+a)}),t}function B(n,{minify:r=!1}={}){let e=c(n,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!0,parseValue:!0});return R=r?o:" ",a=r?o:`
3
- `,y=r?o:i,N=r?o:L,q(e,n,0)}function F(n){return B(n,{minify:!0})}s.format=B,s.minify=F,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
2
+ `,R=" ",y=" ",N=";";function E(n){return R.repeat(n)}function p(n){return/[A-Z]/.test(n)}function C(n,r){let e=n.loc;if(!e)return o;let t=e.start,f=e.end,u=r.substring(t.offset,f.offset);return t.line===f.line?u:u.replace(/\s+/g,i)}function B(n,r){let e=n.loc;return e?r.substring(e.start.offset,e.end.offset):o}function g(n,r,e){let t,f=n.prelude,u=n.block;return f.type===k?t=M(f,r,e):t=m(f,r,e),u.type===_&&(t+=x(u,r,e)),t}function M(n,r,e){let t=o;return n.children.forEach((u,l)=>{u.type===w?t+=D(u,r,e):t+=m(u,r,e),l.next!==null&&(t+=","+a)}),t}function T(n,r){let e=o;return n.children&&n.children.forEach(t=>{switch(t.type){case"Combinator":{e+=i,t.name!==" "&&(e+=t.name+i);break}case"PseudoElementSelector":{e+=b+b,e+=p(t.name)?t.name.toLowerCase():t.name;break}case"PseudoClassSelector":{e+=b;let f=t.name,u=p(f)?f.toLowerCase():f;(u==="before"||u==="after")&&(e+=b),e+=u,t.children&&(e+="("+T(t,r)+")");break}case k:{t.children.forEach((f,u)=>{f.type===w&&(e+=T(f,r)),u.next&&(e+=","+i)});break}case"Nth":{let f=t.nth;if(f)if(f.type==="AnPlusB"){let u=f.a,l=f.b;u!==null&&(e+=u+"n"),u!==null&&l!==null&&(e+=i),l!==null&&(u!==null&&!l.startsWith("-")&&(e+="+"+i),e+=l)}else e+=C(t.nth,r);t.selector!==null&&(e+=i+"of"+i+T(t.selector,r));break}default:{e+=C(t,r);break}}}),e}function D(n,r,e){return E(e)+T(n,r)}function x(n,r,e){let t=n.children,f=y;return t.isEmpty?f+"{}":(f+="{"+a,e++,t.forEach((u,l)=>{u.type===P?(f+=U(u,r,e),l.next===null?f+=N:f+=L):(l.prev!==null&&l.prev.data.type===P&&(f+=a),u.type===S?f+=g(u,r,e):u.type===O?f+=I(u,r,e):f+=m(u,r,e)),l.next!==null&&(f+=a,u.type!==P&&(f+=a))}),e--,f+=a,f+=E(e)+"}",f)}function I(n,r,e){let t=E(e)+"@",f=n.name,u=n.prelude,l=n.block;return t+=p(f)?f.toLowerCase():f,u!==null&&(t+=i+j(u,r)),l===null?t+=L:l.type===_&&(t+=x(l,r,e)),t}function j(n,r){let e=C(n,r);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,i)}function U(n,r,e){let t=n.property;t.charCodeAt(0)===45&&t.charCodeAt(1)===45||p(t)&&(t=t.toLowerCase());let f=h(n.value,r);return t==="font"&&(f=f.replace(/\s*\/\s*/,"/")),E(e)+t+b+y+f}function Y(n,r){let e=o;return n.forEach((t,f)=>{if(t.type==="Identifier")e+=t.name;else if(t.type==="Function")e+=W(t,r);else if(t.type==="Dimension")e+=V(t);else if(t.type==="Value")e+=h(t,r);else if(t.type===A){let u=t.value.trim(),l=u.charCodeAt(0);l===43||l===45?e+=i:l!==44&&(e+=y),e+=u,l===43||l===45?e+=i:e+=y}else e+=C(t,r);t.type!==A&&f.next!==null&&f.next.data.type!==A&&(e+=i)}),e}function V(n){let r=n.unit,e=n.value;return e+=p(r)?r.toLowerCase():r,e}function h(n,r){return n.type==="Raw"?m(n,r,0):Y(n.children,r)}function W(n,r){let e=n.name,t=e;return p(e)&&(t=e.toLowerCase()),t+="(",t+=Y(n.children,r),t+=")",t}function m(n,r,e){return E(e)+B(n,r).trim()}function Z(n,r,e=0){let t=o;return n.children.forEach((u,l)=>{u.type===S?t+=g(u,r,e):u.type===O?t+=I(u,r,e):t+=m(u,r,e),l.next!==null&&(t+=a+a)}),t}function $(n,{minify:r=!1}={}){let e=c(n,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!0,parseValue:!0});return R=r?o:" ",a=r?o:`
3
+ `,y=r?o:i,N=r?o:L,Z(e,n,0)}function q(n){return $(n,{minify:!0})}s.format=$,s.minify=q,Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectwallace/format-css",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "Fast, small, zero-config library to format CSS with basic rules.",
5
5
  "type": "module",
6
6
  "source": "index.js",