@projectwallace/format-css 0.1.0 → 1.0.0
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/README.md +5 -0
- package/dist/format.cjs +2 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.modern.js +2 -0
- package/dist/format.modern.js.map +1 -0
- package/dist/format.module.js +2 -0
- package/dist/format.module.js.map +1 -0
- package/dist/format.umd.js +2 -0
- package/dist/format.umd.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/package.json +5 -2
- package/.github/workflows/test.yml +0 -24
- package/index.js +0 -214
- package/test.js +0 -373
package/README.md
CHANGED
|
@@ -19,6 +19,11 @@ let old_css = "/* Your old CSS here */";
|
|
|
19
19
|
let new_css = format(old_css);
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
Need more examples?
|
|
23
|
+
|
|
24
|
+
- [StackBlitz example using CommonJS](https://stackblitz.com/edit/stackblitz-starters-phchci?file=index.js)
|
|
25
|
+
- [StackBlitz example using ES Modules](https://stackblitz.com/edit/stackblitz-starters-hrhsed?file=index.js)
|
|
26
|
+
|
|
22
27
|
## Formatting rules
|
|
23
28
|
|
|
24
29
|
1. Every **AtRule** starts on a new line
|
package/dist/format.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function r(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var e=/*#__PURE__*/r(require("css-tree/parser"));function t(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function n(r,e){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,e){if(r){if("string"==typeof r)return t(r,e);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}(r))||e&&r&&"number"==typeof r.length){n&&(r=n);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function o(r){return"\t".repeat(r)}function u(r,e){return r.loc?e.substring(r.loc.start.offset,r.loc.end.offset):""}function a(r,e,t){var o="";return r.prelude&&"SelectorList"===r.prelude.type&&(o+=function(r,e,t){for(var o,u="",a=n(r.children);!(o=a()).done;){var i=o.value;i!==r.children.first&&(u+="\n"),u+="Selector"===i.type?l(i,e,t):p(i,e,t),i!==r.children.last&&(u+=",")}return u}(r.prelude,e,t)),r.block&&"Block"===r.block.type&&(o+=i(r.block,e,t)),o}function l(r,e,t){return o(e)+u(r,t)}function i(r,e,t){var u=r.children;if(0===u.size)return" {}\n";var l=" {\n";e++;for(var i,s=n(u);!(i=s()).done;){var d=i.value;l+="Declaration"===d.type?f(d,e,t):"Rule"===d.type?a(d,e,t):"Atrule"===d.type?c(d,e,t):p(d,e,t),d!==u.last&&(l+="Declaration"===d.type?"\n":"\n\n")}return l+="\n",(l+=o(--e))+"}"}function c(r,e,t){var n=o(e);return n+="@"+r.name,r.prelude&&(n+=" "+u(r.prelude,t)),n+(r.block&&"Block"===r.block.type?i(r.block,e,t):";")}function f(r,e,t){return o(e)+r.property+": "+u(r.value,t)+";"}function p(r,e,t){return o(e)+u(r,t).trim()}exports.format=function(r){return function(r,e,t){void 0===e&&(e=0);for(var o,u="",l=r.children,i=n(l);!(o=i()).done;){var f=o.value;u+="Rule"===f.type?a(f,e,t):"Atrule"===f.type?c(f,e,t):p(f,e,t),f!==l.last&&(u+="\n\n")}return u}(e.default(r,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),0,r)};
|
|
2
|
+
//# sourceMappingURL=format.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.cjs","sources":["../index.js"],"sourcesContent":["import parse from 'css-tree/parser'\n\n/**\n * Indent a string\n * @param {number} size\n * @returns A string with {size} tabs\n */\nfunction indent(size) {\n\treturn '\\t'.repeat(size)\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {string} css\n * @returns A portion of the CSS\n */\nfunction substr(node, css) {\n\tif (node.loc) {\n\t\treturn css.substring(node.loc.start.offset, node.loc.end.offset)\n\t}\n\treturn ''\n}\n\n/**\n *\n * @param {import('css-tree').Rule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Rule\n */\nfunction print_rule(node, indent_level, css) {\n\tlet buffer = ''\n\n\tif (node.prelude && node.prelude.type === 'SelectorList') {\n\t\tbuffer += print_selectorlist(node.prelude, indent_level, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').SelectorList} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted SelectorList\n */\nfunction print_selectorlist(node, indent_level, css) {\n\tlet buffer = ''\n\n\tfor (let selector of node.children) {\n\t\tif (selector !== node.children.first) {\n\t\t\tbuffer += '\\n'\n\t\t}\n\n\t\tif (selector.type === 'Selector') {\n\t\t\tbuffer += print_selector(selector, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(selector, indent_level, css)\n\t\t}\n\n\t\tif (selector !== node.children.last) {\n\t\t\tbuffer += ','\n\t\t}\n\t}\n\treturn buffer\n}\n\n/**\n *\n * @param {import('css-tree').Selector} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Selector\n */\nfunction print_selector(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css)\n}\n\n/**\n * @param {import('css-tree').Block} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Block\n */\nfunction print_block(node, indent_level, css) {\n\tlet children = node.children\n\n\tif (children.size === 0) {\n\t\treturn ' {}\\n'\n\t}\n\n\tlet buffer = ' {\\n'\n\n\tindent_level++\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Declaration') {\n\t\t\tbuffer += print_declaration(child, indent_level, css)\n\t\t} else if (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tif (child.type === 'Declaration') {\n\t\t\t\tbuffer += '\\n'\n\t\t\t} else {\n\t\t\t\tbuffer += '\\n\\n'\n\t\t\t}\n\t\t}\n\t}\n\n\tindent_level--\n\n\tbuffer += '\\n'\n\tbuffer += indent(indent_level)\n\tbuffer += '}'\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Atrule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Atrule\n */\nfunction print_atrule(node, indent_level, css) {\n\tlet buffer = indent(indent_level)\n\tbuffer += '@' + node.name\n\n\t// @font-face has no prelude\n\tif (node.prelude) {\n\t\tbuffer += ' ' + substr(node.prelude, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t} else {\n\t\t// `@import url(style.css);` has no block, neither does `@layer layer1;`\n\t\tbuffer += ';'\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Declation} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Declaration\n */\nfunction print_declaration(node, indent_level, css) {\n\treturn indent(indent_level) + node.property + ': ' + substr(node.value, css) + ';'\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted unknown CSS string\n */\nfunction print_unknown(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css).trim()\n}\n\n/**\n * @param {import('css-tree').Stylesheet} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Stylesheet\n */\nfunction print(node, indent_level = 0, css) {\n\tlet buffer = ''\n\tlet children = node.children\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tbuffer += '\\n\\n'\n\t\t}\n\t}\n\n\treturn buffer\n}\n\n/**\n * Take a string of CSS (minified or not) and format it with some simple rules\n * @param {string} css The original CSS\n * @returns {string} The newly formatted CSS\n */\nexport function format(css) {\n\tlet ast = parse(css, {\n\t\tpositions: true,\n\t\tparseAtrulePrelude: false,\n\t\tparseCustomProperty: false,\n\t\tparseValue: false,\n\t})\n\treturn print(ast, 0, css)\n}\n"],"names":["indent","size","repeat","substr","node","css","loc","substring","start","offset","end","print_rule","indent_level","buffer","prelude","type","_step","_iterator","_createForOfIteratorHelperLoose","children","done","selector","value","first","print_selector","print_unknown","last","print_selectorlist","block","print_block","_step2","_iterator2","child","print_declaration","print_atrule","name","property","trim","_step3","_iterator3","print","parse","positions","parseAtrulePrelude","parseCustomProperty","parseValue"],"mappings":"+6BAOA,SAASA,EAAOC,GACf,MAAO,KAAKC,OAAOD,EACpB,CAOA,SAASE,EAAOC,EAAMC,GACrB,OAAID,EAAKE,IACDD,EAAIE,UAAUH,EAAKE,IAAIE,MAAMC,OAAQL,EAAKE,IAAII,IAAID,QAEnD,EACR,CASA,SAASE,EAAWP,EAAMQ,EAAcP,GACvC,IAAIQ,EAAS,GAUb,OARIT,EAAKU,SAAiC,iBAAtBV,EAAKU,QAAQC,OAChCF,GAgBF,SAA4BT,EAAMQ,EAAcP,GAG/C,IAFA,IAEkCW,EAF9BH,EAAS,GAEbI,EAAAC,EAAqBd,EAAKe,YAAQH,EAAAC,KAAAG,MAAE,CAA3B,IAAAC,EAAQL,E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hB,EAAcP,GAGtC,IAIZ,CAQA,SAAS4B,EAAkB7B,EAAMQ,EAAcP,GAC9C,OAAOL,EAAOY,GAAgBR,EAAKgC,SAAW,KAAOjC,EAAOC,EAAKkB,MAAOjB,GAAO,GAChF,CAQA,SAASoB,EAAcrB,EAAMQ,EAAcP,GAC1C,OAAOL,EAAOY,GAAgBT,EAAOC,EAAMC,GAAKgC,MACjD,gBAkCgB,SAAOhC,GAOtB,OAjCD,SAAeD,EAAMQ,EAAkBP,YAAlBO,IAAAA,EAAe,GAInC,IAHA,IAG0B0B,EAHtBzB,EAAS,GACTM,EAAWf,EAAKe,SAEpBoB,EAAArB,EAAkBC,KAAQmB,EAAAC,KAAAnB,MAAE,CAAnB,IAAAY,EAAKM,EAAAhB,MAEZT,GADkB,SAAfmB,EAAMjB,KACCJ,EAAWqB,EAAOpB,EAAcP,GACjB,WAAf2B,EAAMjB,KACNmB,EAAaF,EAAOpB,EAAcP,GAElCoB,EAAcO,EAAOpB,EAAcP,GAG1C2B,IAAUb,EAASO,OACtBb,GAAU,OAEZ,CAEA,OAAOA,CACR,CAcQ2B,CANGC,UAAMpC,EAAK,CACpBqC,WAAW,EACXC,oBAAoB,EACpBC,qBAAqB,EACrBC,YAAY,IAEK,EAAGxC,EACtB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"css-tree/parser";function t(e){return"\t".repeat(e)}function r(e,t){return e.loc?t.substring(e.loc.start.offset,e.loc.end.offset):""}function n(e,t,r){let n="";return e.prelude&&"SelectorList"===e.prelude.type&&(n+=function(e,t,r){let n="";for(let o of e.children)o!==e.children.first&&(n+="\n"),n+="Selector"===o.type?l(o,t,r):i(o,t,r),o!==e.children.last&&(n+=",");return n}(e.prelude,t,r)),e.block&&"Block"===e.block.type&&(n+=o(e.block,t,r)),n}function l(e,n,l){return t(n)+r(e,l)}function o(e,r,l){let o=e.children;if(0===o.size)return" {}\n";let p=" {\n";r++;for(let e of o)p+="Declaration"===e.type?c(e,r,l):"Rule"===e.type?n(e,r,l):"Atrule"===e.type?u(e,r,l):i(e,r,l),e!==o.last&&(p+="Declaration"===e.type?"\n":"\n\n");return p+="\n",p+=t(--r),p+="}",p}function u(e,n,l){let u=t(n);return u+="@"+e.name,e.prelude&&(u+=" "+r(e.prelude,l)),u+=e.block&&"Block"===e.block.type?o(e.block,n,l):";",u}function c(e,n,l){return t(n)+e.property+": "+r(e.value,l)+";"}function i(e,n,l){return t(n)+r(e,l).trim()}function p(t){return function(e,t=0,r){let l="",o=e.children;for(let e of o)l+="Rule"===e.type?n(e,t,r):"Atrule"===e.type?u(e,t,r):i(e,t,r),e!==o.last&&(l+="\n\n");return l}(e(t,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),0,t)}export{p as format};
|
|
2
|
+
//# sourceMappingURL=format.modern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.modern.js","sources":["../index.js"],"sourcesContent":["import parse from 'css-tree/parser'\n\n/**\n * Indent a string\n * @param {number} size\n * @returns A string with {size} tabs\n */\nfunction indent(size) {\n\treturn '\\t'.repeat(size)\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {string} css\n * @returns A portion of the CSS\n */\nfunction substr(node, css) {\n\tif (node.loc) {\n\t\treturn css.substring(node.loc.start.offset, node.loc.end.offset)\n\t}\n\treturn ''\n}\n\n/**\n *\n * @param {import('css-tree').Rule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Rule\n */\nfunction print_rule(node, indent_level, css) {\n\tlet buffer = ''\n\n\tif (node.prelude && node.prelude.type === 'SelectorList') {\n\t\tbuffer += print_selectorlist(node.prelude, indent_level, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').SelectorList} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted SelectorList\n */\nfunction print_selectorlist(node, indent_level, css) {\n\tlet buffer = ''\n\n\tfor (let selector of node.children) {\n\t\tif (selector !== node.children.first) {\n\t\t\tbuffer += '\\n'\n\t\t}\n\n\t\tif (selector.type === 'Selector') {\n\t\t\tbuffer += print_selector(selector, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(selector, indent_level, css)\n\t\t}\n\n\t\tif (selector !== node.children.last) {\n\t\t\tbuffer += ','\n\t\t}\n\t}\n\treturn buffer\n}\n\n/**\n *\n * @param {import('css-tree').Selector} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Selector\n */\nfunction print_selector(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css)\n}\n\n/**\n * @param {import('css-tree').Block} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Block\n */\nfunction print_block(node, indent_level, css) {\n\tlet children = node.children\n\n\tif (children.size === 0) {\n\t\treturn ' {}\\n'\n\t}\n\n\tlet buffer = ' {\\n'\n\n\tindent_level++\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Declaration') {\n\t\t\tbuffer += print_declaration(child, indent_level, css)\n\t\t} else if (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tif (child.type === 'Declaration') {\n\t\t\t\tbuffer += '\\n'\n\t\t\t} else {\n\t\t\t\tbuffer += '\\n\\n'\n\t\t\t}\n\t\t}\n\t}\n\n\tindent_level--\n\n\tbuffer += '\\n'\n\tbuffer += indent(indent_level)\n\tbuffer += '}'\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Atrule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Atrule\n */\nfunction print_atrule(node, indent_level, css) {\n\tlet buffer = indent(indent_level)\n\tbuffer += '@' + node.name\n\n\t// @font-face has no prelude\n\tif (node.prelude) {\n\t\tbuffer += ' ' + substr(node.prelude, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t} else {\n\t\t// `@import url(style.css);` has no block, neither does `@layer layer1;`\n\t\tbuffer += ';'\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Declation} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Declaration\n */\nfunction print_declaration(node, indent_level, css) {\n\treturn indent(indent_level) + node.property + ': ' + substr(node.value, css) + ';'\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted unknown CSS string\n */\nfunction print_unknown(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css).trim()\n}\n\n/**\n * @param {import('css-tree').Stylesheet} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Stylesheet\n */\nfunction print(node, indent_level = 0, css) {\n\tlet buffer = ''\n\tlet children = node.children\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tbuffer += '\\n\\n'\n\t\t}\n\t}\n\n\treturn buffer\n}\n\n/**\n * Take a string of CSS (minified or not) and format it with some simple rules\n * @param {string} css The original CSS\n * @returns {string} The newly formatted CSS\n */\nexport function format(css) {\n\tlet ast = parse(css, {\n\t\tpositions: true,\n\t\tparseAtrulePrelude: false,\n\t\tparseCustomProperty: false,\n\t\tparseValue: false,\n\t})\n\treturn print(ast, 0, css)\n}\n"],"names":["indent","size","repeat","substr","node","css","loc","substring","start","offset","end","print_rule","indent_level","buffer","prelude","type","selector","children","first","print_selector","print_unknown","last","print_selectorlist","block","print_block","child","print_declaration","print_atrule","name","property","value","trim","format","print","parse","positions","parseAtrulePrelude","parseCustomProperty","parseValue"],"mappings":"+BAOA,SAASA,EAAOC,GACf,MAAO,KAAKC,OAAOD,EACpB,CAOA,SAASE,EAAOC,EAAMC,GACrB,OAAID,EAAKE,IACDD,EAAIE,UAAUH,EAAKE,IAAIE,MAAMC,OAAQL,EAAKE,IAAII,IAAID,QAEnD,EACR,CASA,SAASE,EAAWP,EAAMQ,EAAcP,GACvC,IAAIQ,EAAS,GAUb,OARIT,EAAKU,SAAiC,iBAAtBV,EAAKU,QAAQC,OAChCF,GAgBF,SAA4BT,EAAMQ,EAAcP,GAC/C,IAAIQ,EAAS,GAEb,IAAK,IAAIG,KAAYZ,EAAKa,SACrBD,IAAaZ,EAAKa,SAASC,QAC9BL,GAAU,MAIVA,GADqB,aAAlBG,EAASD,KACFI,EAAeH,EAAUJ,EAAcP,GAEvCe,EAAcJ,EAAUJ,EAAcP,GAG7CW,IAAaZ,EAAKa,SAASI,OAC9BR,GAAU,KAGZ,OAAOA,CACR,CAnCYS,CAAmBlB,EAAKU,QAASF,EAAcP,IAGtDD,EAAKmB,OAA6B,UAApBnB,EAAKmB,MAAMR,OAC5BF,GAAUW,EAAYpB,EAAKmB,MAAOX,EAAcP,IAG1CQ,CACR,CAoCA,SAASM,EAAef,EAAMQ,EAAcP,GAC3C,OAAOL,EAAOY,GAAgBT,EAAOC,EAAMC,EAC5C,CAQA,SAASmB,EAAYpB,EAAMQ,EAAcP,GACxC,IAAIY,EAAWb,EAAKa,SAEpB,GAAsB,IAAlBA,EAAShB,KACZ,MAAO,QAGR,IAAIY,EAAS,OAEbD,IAEA,IAAK,IAAIa,KAASR,EAEhBJ,GADkB,gBAAfY,EAAMV,KACCW,EAAkBD,EAAOb,EAAcP,GACxB,SAAfoB,EAAMV,KACNJ,EAAWc,EAAOb,EAAcP,GACjB,WAAfoB,EAAMV,KACNY,EAAaF,EAAOb,EAAcP,GAElCe,EAAcK,EAAOb,EAAcP,GAG1CoB,IAAUR,EAASI,OAErBR,GADkB,gBAAfY,EAAMV,KACC,KAEA,QAWb,OAJAF,GAAU,KACVA,GAAUb,IAHVY,GAIAC,GAAU,IAEHA,CACR,CAQA,SAASc,EAAavB,EAAMQ,EAAcP,GACzC,IAAIQ,EAASb,EAAOY,GAepB,OAdAC,GAAU,IAAMT,EAAKwB,KAGjBxB,EAAKU,UACRD,GAAU,IAAMV,EAAOC,EAAKU,QAAST,IAIrCQ,GADGT,EAAKmB,OAA6B,UAApBnB,EAAKmB,MAAMR,KAClBS,EAAYpB,EAAKmB,MAAOX,EAAcP,GAGtC,IAGJQ,CACR,CAQA,SAASa,EAAkBtB,EAAMQ,EAAcP,GAC9C,OAAOL,EAAOY,GAAgBR,EAAKyB,SAAW,KAAO1B,EAAOC,EAAK0B,MAAOzB,GAAO,GAChF,CAQA,SAASe,EAAchB,EAAMQ,EAAcP,GAC1C,OAAOL,EAAOY,GAAgBT,EAAOC,EAAMC,GAAK0B,MACjD,CAkCO,SAASC,EAAO3B,GAOtB,OAjCD,SAAeD,EAAMQ,EAAe,EAAGP,GACtC,IAAIQ,EAAS,GACTI,EAAWb,EAAKa,SAEpB,IAAK,IAAIQ,KAASR,EAEhBJ,GADkB,SAAfY,EAAMV,KACCJ,EAAWc,EAAOb,EAAcP,GACjB,WAAfoB,EAAMV,KACNY,EAAaF,EAAOb,EAAcP,GAElCe,EAAcK,EAAOb,EAAcP,GAG1CoB,IAAUR,EAASI,OACtBR,GAAU,QAIZ,OAAOA,CACR,CAcQoB,CANGC,EAAM7B,EAAK,CACpB8B,WAAW,EACXC,oBAAoB,EACpBC,qBAAqB,EACrBC,YAAY,IAEK,EAAGjC,EACtB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import r from"css-tree/parser";function e(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=new Array(e);t<e;t++)n[t]=r[t];return n}function t(r,t){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,t){if(r){if("string"==typeof r)return e(r,t);var n=Object.prototype.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(r,t):void 0}}(r))||t&&r&&"number"==typeof r.length){n&&(r=n);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(r){return"\t".repeat(r)}function o(r,e){return r.loc?e.substring(r.loc.start.offset,r.loc.end.offset):""}function u(r,e,n){var o="";return r.prelude&&"SelectorList"===r.prelude.type&&(o+=function(r,e,n){for(var o,u="",a=t(r.children);!(o=a()).done;){var i=o.value;i!==r.children.first&&(u+="\n"),u+="Selector"===i.type?l(i,e,n):f(i,e,n),i!==r.children.last&&(u+=",")}return u}(r.prelude,e,n)),r.block&&"Block"===r.block.type&&(o+=a(r.block,e,n)),o}function l(r,e,t){return n(e)+o(r,t)}function a(r,e,o){var l=r.children;if(0===l.size)return" {}\n";var a=" {\n";e++;for(var p,s=t(l);!(p=s()).done;){var d=p.value;a+="Declaration"===d.type?c(d,e,o):"Rule"===d.type?u(d,e,o):"Atrule"===d.type?i(d,e,o):f(d,e,o),d!==l.last&&(a+="Declaration"===d.type?"\n":"\n\n")}return a+="\n",(a+=n(--e))+"}"}function i(r,e,t){var u=n(e);return u+="@"+r.name,r.prelude&&(u+=" "+o(r.prelude,t)),u+(r.block&&"Block"===r.block.type?a(r.block,e,t):";")}function c(r,e,t){return n(e)+r.property+": "+o(r.value,t)+";"}function f(r,e,t){return n(e)+o(r,t).trim()}function p(e){return function(r,e,n){void 0===e&&(e=0);for(var o,l="",a=r.children,c=t(a);!(o=c()).done;){var p=o.value;l+="Rule"===p.type?u(p,e,n):"Atrule"===p.type?i(p,e,n):f(p,e,n),p!==a.last&&(l+="\n\n")}return l}(r(e,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),0,e)}export{p as format};
|
|
2
|
+
//# sourceMappingURL=format.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.module.js","sources":["../index.js"],"sourcesContent":["import parse from 'css-tree/parser'\n\n/**\n * Indent a string\n * @param {number} size\n * @returns A string with {size} tabs\n */\nfunction indent(size) {\n\treturn '\\t'.repeat(size)\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {string} css\n * @returns A portion of the CSS\n */\nfunction substr(node, css) {\n\tif (node.loc) {\n\t\treturn css.substring(node.loc.start.offset, node.loc.end.offset)\n\t}\n\treturn ''\n}\n\n/**\n *\n * @param {import('css-tree').Rule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Rule\n */\nfunction print_rule(node, indent_level, css) {\n\tlet buffer = ''\n\n\tif (node.prelude && node.prelude.type === 'SelectorList') {\n\t\tbuffer += print_selectorlist(node.prelude, indent_level, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').SelectorList} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted SelectorList\n */\nfunction print_selectorlist(node, indent_level, css) {\n\tlet buffer = ''\n\n\tfor (let selector of node.children) {\n\t\tif (selector !== node.children.first) {\n\t\t\tbuffer += '\\n'\n\t\t}\n\n\t\tif (selector.type === 'Selector') {\n\t\t\tbuffer += print_selector(selector, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(selector, indent_level, css)\n\t\t}\n\n\t\tif (selector !== node.children.last) {\n\t\t\tbuffer += ','\n\t\t}\n\t}\n\treturn buffer\n}\n\n/**\n *\n * @param {import('css-tree').Selector} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Selector\n */\nfunction print_selector(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css)\n}\n\n/**\n * @param {import('css-tree').Block} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Block\n */\nfunction print_block(node, indent_level, css) {\n\tlet children = node.children\n\n\tif (children.size === 0) {\n\t\treturn ' {}\\n'\n\t}\n\n\tlet buffer = ' {\\n'\n\n\tindent_level++\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Declaration') {\n\t\t\tbuffer += print_declaration(child, indent_level, css)\n\t\t} else if (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tif (child.type === 'Declaration') {\n\t\t\t\tbuffer += '\\n'\n\t\t\t} else {\n\t\t\t\tbuffer += '\\n\\n'\n\t\t\t}\n\t\t}\n\t}\n\n\tindent_level--\n\n\tbuffer += '\\n'\n\tbuffer += indent(indent_level)\n\tbuffer += '}'\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Atrule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Atrule\n */\nfunction print_atrule(node, indent_level, css) {\n\tlet buffer = indent(indent_level)\n\tbuffer += '@' + node.name\n\n\t// @font-face has no prelude\n\tif (node.prelude) {\n\t\tbuffer += ' ' + substr(node.prelude, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t} else {\n\t\t// `@import url(style.css);` has no block, neither does `@layer layer1;`\n\t\tbuffer += ';'\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Declation} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Declaration\n */\nfunction print_declaration(node, indent_level, css) {\n\treturn indent(indent_level) + node.property + ': ' + substr(node.value, css) + ';'\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted unknown CSS string\n */\nfunction print_unknown(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css).trim()\n}\n\n/**\n * @param {import('css-tree').Stylesheet} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Stylesheet\n */\nfunction print(node, indent_level = 0, css) {\n\tlet buffer = ''\n\tlet children = node.children\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tbuffer += '\\n\\n'\n\t\t}\n\t}\n\n\treturn buffer\n}\n\n/**\n * Take a string of CSS (minified or not) and format it with some simple rules\n * @param {string} css The original CSS\n * @returns {string} The newly formatted CSS\n */\nexport function format(css) {\n\tlet ast = parse(css, {\n\t\tpositions: true,\n\t\tparseAtrulePrelude: false,\n\t\tparseCustomProperty: false,\n\t\tparseValue: false,\n\t})\n\treturn print(ast, 0, css)\n}\n"],"names":["indent","size","repeat","substr","node","css","loc","substring","start","offset","end","print_rule","indent_level","buffer","prelude","type","_step","_iterator","_createForOfIteratorHelperLoose","children","done","selector","value","first","print_selector","print_unknown","last","print_selectorlist","block","print_block","_step2","_iterator2","child","print_declaration","print_atrule","name","property","trim","format","_step3","_iterator3","print","parse","positions","parseAtrulePrelude","parseCustomProperty","parseValue"],"mappings":"q1BAOA,SAASA,EAAOC,GACf,MAAO,KAAKC,OAAOD,EACpB,CAOA,SAASE,EAAOC,EAAMC,GACrB,OAAID,EAAKE,IACDD,EAAIE,UAAUH,EAAKE,IAAIE,MAAMC,OAAQL,EAAKE,IAAII,IAAID,QAEnD,EACR,CASA,SAASE,EAAWP,EAAMQ,EAAcP,GACv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9B,EAAMQ,EAAcP,GACzC,IAAIQ,EAASb,EAAOY,GAepB,OAdAC,GAAU,IAAMT,EAAK+B,KAGjB/B,EAAKU,UACRD,GAAU,IAAMV,EAAOC,EAAKU,QAAST,IAIrCQ,GADGT,EAAKwB,OAA6B,UAApBxB,EAAKwB,MAAMb,KAClBc,EAAYzB,EAAKwB,MAAOhB,EAAcP,GAGtC,IAIZ,CAQA,SAAS4B,EAAkB7B,EAAMQ,EAAcP,GAC9C,OAAOL,EAAOY,GAAgBR,EAAKgC,SAAW,KAAOjC,EAAOC,EAAKkB,MAAOjB,GAAO,GAChF,CAQA,SAASoB,EAAcrB,EAAMQ,EAAcP,GAC1C,OAAOL,EAAOY,GAAgBT,EAAOC,EAAMC,GAAKgC,MACjD,CAkCgB,SAAAC,EAAOjC,GAOtB,OAjCD,SAAeD,EAAMQ,EAAkBP,YAAlBO,IAAAA,EAAe,GAInC,IAHA,IAG0B2B,EAHtB1B,EAAS,GACTM,EAAWf,EAAKe,SAEpBqB,EAAAtB,EAAkBC,KAAQoB,EAAAC,KAAApB,MAAE,CAAnB,IAAAY,EAAKO,EAAAjB,MAEZT,GADkB,SAAfmB,EAAMjB,KACCJ,EAAWqB,EAAOpB,EAAcP,GACjB,WAAf2B,EAAMjB,KACNmB,EAAaF,EAAOpB,EAAcP,GAElCoB,EAAcO,EAAOpB,EAAcP,GAG1C2B,IAAUb,EAASO,OACtBb,GAAU,OAEZ,CAEA,OAAOA,CACR,CAcQ4B,CANGC,EAAMrC,EAAK,CACpBsC,WAAW,EACXC,oBAAoB,EACpBC,qBAAqB,EACrBC,YAAY,IAEK,EAAGzC,EACtB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("css-tree/parser")):"function"==typeof define&&define.amd?define(["exports","css-tree/parser"],r):r((e||self).formatCss={},e.parse)}(this,function(e,r){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=/*#__PURE__*/t(r);function o(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function u(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return o(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(e){return"\t".repeat(e)}function l(e,r){return e.loc?r.substring(e.loc.start.offset,e.loc.end.offset):""}function i(e,r,t){var n="";return e.prelude&&"SelectorList"===e.prelude.type&&(n+=function(e,r,t){for(var n,o="",a=u(e.children);!(n=a()).done;){var l=n.value;l!==e.children.first&&(o+="\n"),o+="Selector"===l.type?c(l,r,t):d(l,r,t),l!==e.children.last&&(o+=",")}return o}(e.prelude,r,t)),e.block&&"Block"===e.block.type&&(n+=f(e.block,r,t)),n}function c(e,r,t){return a(r)+l(e,t)}function f(e,r,t){var n=e.children;if(0===n.size)return" {}\n";var o=" {\n";r++;for(var l,c=u(n);!(l=c()).done;){var f=l.value;o+="Declaration"===f.type?s(f,r,t):"Rule"===f.type?i(f,r,t):"Atrule"===f.type?p(f,r,t):d(f,r,t),f!==n.last&&(o+="Declaration"===f.type?"\n":"\n\n")}return o+="\n",(o+=a(--r))+"}"}function p(e,r,t){var n=a(r);return n+="@"+e.name,e.prelude&&(n+=" "+l(e.prelude,t)),n+(e.block&&"Block"===e.block.type?f(e.block,r,t):";")}function s(e,r,t){return a(r)+e.property+": "+l(e.value,t)+";"}function d(e,r,t){return a(r)+l(e,t).trim()}e.format=function(e){return function(e,r,t){void 0===r&&(r=0);for(var n,o="",a=e.children,l=u(a);!(n=l()).done;){var c=n.value;o+="Rule"===c.type?i(c,r,t):"Atrule"===c.type?p(c,r,t):d(c,r,t),c!==a.last&&(o+="\n\n")}return o}(n.default(e,{positions:!0,parseAtrulePrelude:!1,parseCustomProperty:!1,parseValue:!1}),0,e)}});
|
|
2
|
+
//# sourceMappingURL=format.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.umd.js","sources":["../index.js"],"sourcesContent":["import parse from 'css-tree/parser'\n\n/**\n * Indent a string\n * @param {number} size\n * @returns A string with {size} tabs\n */\nfunction indent(size) {\n\treturn '\\t'.repeat(size)\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {string} css\n * @returns A portion of the CSS\n */\nfunction substr(node, css) {\n\tif (node.loc) {\n\t\treturn css.substring(node.loc.start.offset, node.loc.end.offset)\n\t}\n\treturn ''\n}\n\n/**\n *\n * @param {import('css-tree').Rule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Rule\n */\nfunction print_rule(node, indent_level, css) {\n\tlet buffer = ''\n\n\tif (node.prelude && node.prelude.type === 'SelectorList') {\n\t\tbuffer += print_selectorlist(node.prelude, indent_level, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').SelectorList} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted SelectorList\n */\nfunction print_selectorlist(node, indent_level, css) {\n\tlet buffer = ''\n\n\tfor (let selector of node.children) {\n\t\tif (selector !== node.children.first) {\n\t\t\tbuffer += '\\n'\n\t\t}\n\n\t\tif (selector.type === 'Selector') {\n\t\t\tbuffer += print_selector(selector, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(selector, indent_level, css)\n\t\t}\n\n\t\tif (selector !== node.children.last) {\n\t\t\tbuffer += ','\n\t\t}\n\t}\n\treturn buffer\n}\n\n/**\n *\n * @param {import('css-tree').Selector} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Selector\n */\nfunction print_selector(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css)\n}\n\n/**\n * @param {import('css-tree').Block} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Block\n */\nfunction print_block(node, indent_level, css) {\n\tlet children = node.children\n\n\tif (children.size === 0) {\n\t\treturn ' {}\\n'\n\t}\n\n\tlet buffer = ' {\\n'\n\n\tindent_level++\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Declaration') {\n\t\t\tbuffer += print_declaration(child, indent_level, css)\n\t\t} else if (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tif (child.type === 'Declaration') {\n\t\t\t\tbuffer += '\\n'\n\t\t\t} else {\n\t\t\t\tbuffer += '\\n\\n'\n\t\t\t}\n\t\t}\n\t}\n\n\tindent_level--\n\n\tbuffer += '\\n'\n\tbuffer += indent(indent_level)\n\tbuffer += '}'\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Atrule} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Atrule\n */\nfunction print_atrule(node, indent_level, css) {\n\tlet buffer = indent(indent_level)\n\tbuffer += '@' + node.name\n\n\t// @font-face has no prelude\n\tif (node.prelude) {\n\t\tbuffer += ' ' + substr(node.prelude, css)\n\t}\n\n\tif (node.block && node.block.type === 'Block') {\n\t\tbuffer += print_block(node.block, indent_level, css)\n\t} else {\n\t\t// `@import url(style.css);` has no block, neither does `@layer layer1;`\n\t\tbuffer += ';'\n\t}\n\n\treturn buffer\n}\n\n/**\n * @param {import('css-tree').Declation} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Declaration\n */\nfunction print_declaration(node, indent_level, css) {\n\treturn indent(indent_level) + node.property + ': ' + substr(node.value, css) + ';'\n}\n\n/**\n * @param {import('css-tree').CssNode} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted unknown CSS string\n */\nfunction print_unknown(node, indent_level, css) {\n\treturn indent(indent_level) + substr(node, css).trim()\n}\n\n/**\n * @param {import('css-tree').Stylesheet} node\n * @param {number} indent_level\n * @param {string} css\n * @returns {string} A formatted Stylesheet\n */\nfunction print(node, indent_level = 0, css) {\n\tlet buffer = ''\n\tlet children = node.children\n\n\tfor (let child of children) {\n\t\tif (child.type === 'Rule') {\n\t\t\tbuffer += print_rule(child, indent_level, css)\n\t\t} else if (child.type === 'Atrule') {\n\t\t\tbuffer += print_atrule(child, indent_level, css)\n\t\t} else {\n\t\t\tbuffer += print_unknown(child, indent_level, css)\n\t\t}\n\n\t\tif (child !== children.last) {\n\t\t\tbuffer += '\\n\\n'\n\t\t}\n\t}\n\n\treturn buffer\n}\n\n/**\n * Take a string of CSS (minified or not) and format it with some simple rules\n * @param {string} css The original CSS\n * @returns {string} The newly formatted CSS\n */\nexport function format(css) {\n\tlet ast = parse(css, {\n\t\tpositions: true,\n\t\tparseAtrulePrelude: false,\n\t\tparseCustomProperty: false,\n\t\tparseValue: false,\n\t})\n\treturn print(ast, 0, css)\n}\n"],"names":["indent","size","repeat","substr","node","css","loc","substring","start","offset","end","print_rule","indent_level","buffer","prelude","type","_step","_iterator","_createForOfIteratorHelperLoose","children","done","selector","value","first","print_selector","print_unknown","last","print_selectorlist","block","print_block","_step2","_iterator2","child","print_declaration","print_atrule","name","property","trim","_step3","_iterator3","print","parse","positions","parseAtrulePrelude","parseCustomProperty","parseValue"],"mappings":"grCAOA,SAASA,EAAOC,GACf,MAAO,KAAKC,OAAOD,EACpB,CAOA,SAASE,EAAOC,EAAMC,GACrB,O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"@projectwallace/format-css",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"source": "index.js",
|
|
6
6
|
"exports": {
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"css-tree": "^2.3.1"
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
]
|
|
26
29
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
|
|
3
|
-
|
|
4
|
-
name: Tests
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
branches: [main]
|
|
9
|
-
pull_request:
|
|
10
|
-
branches: [main]
|
|
11
|
-
|
|
12
|
-
jobs:
|
|
13
|
-
test:
|
|
14
|
-
name: Unit tests
|
|
15
|
-
runs-on: ubuntu-latest
|
|
16
|
-
steps:
|
|
17
|
-
- uses: actions/checkout@v3
|
|
18
|
-
- name: Use Node.js 18
|
|
19
|
-
uses: actions/setup-node@v3
|
|
20
|
-
with:
|
|
21
|
-
node-version: 18
|
|
22
|
-
cache: "npm"
|
|
23
|
-
- run: npm install --ignore-scripts --no-audit
|
|
24
|
-
- run: npm test
|
package/index.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
import parse from 'css-tree/parser'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Indent a string
|
|
5
|
-
* @param {number} size
|
|
6
|
-
* @returns A string with {size} tabs
|
|
7
|
-
*/
|
|
8
|
-
function indent(size) {
|
|
9
|
-
return '\t'.repeat(size)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {import('css-tree').CssNode} node
|
|
14
|
-
* @param {string} css
|
|
15
|
-
* @returns A portion of the CSS
|
|
16
|
-
*/
|
|
17
|
-
function substr(node, css) {
|
|
18
|
-
if (node.loc) {
|
|
19
|
-
return css.substring(node.loc.start.offset, node.loc.end.offset)
|
|
20
|
-
}
|
|
21
|
-
return ''
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param {import('css-tree').Rule} node
|
|
27
|
-
* @param {number} indent_level
|
|
28
|
-
* @param {string} css
|
|
29
|
-
* @returns {string} A formatted Rule
|
|
30
|
-
*/
|
|
31
|
-
function print_rule(node, indent_level, css) {
|
|
32
|
-
let buffer = ''
|
|
33
|
-
|
|
34
|
-
if (node.prelude && node.prelude.type === 'SelectorList') {
|
|
35
|
-
buffer += print_selectorlist(node.prelude, indent_level, css)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (node.block && node.block.type === 'Block') {
|
|
39
|
-
buffer += print_block(node.block, indent_level, css)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return buffer
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @param {import('css-tree').SelectorList} node
|
|
47
|
-
* @param {number} indent_level
|
|
48
|
-
* @param {string} css
|
|
49
|
-
* @returns {string} A formatted SelectorList
|
|
50
|
-
*/
|
|
51
|
-
function print_selectorlist(node, indent_level, css) {
|
|
52
|
-
let buffer = ''
|
|
53
|
-
|
|
54
|
-
for (let selector of node.children) {
|
|
55
|
-
if (selector !== node.children.first) {
|
|
56
|
-
buffer += '\n'
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (selector.type === 'Selector') {
|
|
60
|
-
buffer += print_selector(selector, indent_level, css)
|
|
61
|
-
} else {
|
|
62
|
-
buffer += print_unknown(selector, indent_level, css)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (selector !== node.children.last) {
|
|
66
|
-
buffer += ','
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return buffer
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
* @param {import('css-tree').Selector} node
|
|
75
|
-
* @param {number} indent_level
|
|
76
|
-
* @param {string} css
|
|
77
|
-
* @returns {string} A formatted Selector
|
|
78
|
-
*/
|
|
79
|
-
function print_selector(node, indent_level, css) {
|
|
80
|
-
return indent(indent_level) + substr(node, css)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* @param {import('css-tree').Block} node
|
|
85
|
-
* @param {number} indent_level
|
|
86
|
-
* @param {string} css
|
|
87
|
-
* @returns {string} A formatted Block
|
|
88
|
-
*/
|
|
89
|
-
function print_block(node, indent_level, css) {
|
|
90
|
-
let children = node.children
|
|
91
|
-
|
|
92
|
-
if (children.size === 0) {
|
|
93
|
-
return ' {}\n'
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
let buffer = ' {\n'
|
|
97
|
-
|
|
98
|
-
indent_level++
|
|
99
|
-
|
|
100
|
-
for (let child of children) {
|
|
101
|
-
if (child.type === 'Declaration') {
|
|
102
|
-
buffer += print_declaration(child, indent_level, css)
|
|
103
|
-
} else if (child.type === 'Rule') {
|
|
104
|
-
buffer += print_rule(child, indent_level, css)
|
|
105
|
-
} else if (child.type === 'Atrule') {
|
|
106
|
-
buffer += print_atrule(child, indent_level, css)
|
|
107
|
-
} else {
|
|
108
|
-
buffer += print_unknown(child, indent_level, css)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (child !== children.last) {
|
|
112
|
-
if (child.type === 'Declaration') {
|
|
113
|
-
buffer += '\n'
|
|
114
|
-
} else {
|
|
115
|
-
buffer += '\n\n'
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
indent_level--
|
|
121
|
-
|
|
122
|
-
buffer += '\n'
|
|
123
|
-
buffer += indent(indent_level)
|
|
124
|
-
buffer += '}'
|
|
125
|
-
|
|
126
|
-
return buffer
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* @param {import('css-tree').Atrule} node
|
|
131
|
-
* @param {number} indent_level
|
|
132
|
-
* @param {string} css
|
|
133
|
-
* @returns {string} A formatted Atrule
|
|
134
|
-
*/
|
|
135
|
-
function print_atrule(node, indent_level, css) {
|
|
136
|
-
let buffer = indent(indent_level)
|
|
137
|
-
buffer += '@' + node.name
|
|
138
|
-
|
|
139
|
-
// @font-face has no prelude
|
|
140
|
-
if (node.prelude) {
|
|
141
|
-
buffer += ' ' + substr(node.prelude, css)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (node.block && node.block.type === 'Block') {
|
|
145
|
-
buffer += print_block(node.block, indent_level, css)
|
|
146
|
-
} else {
|
|
147
|
-
// `@import url(style.css);` has no block, neither does `@layer layer1;`
|
|
148
|
-
buffer += ';'
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return buffer
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @param {import('css-tree').Declation} node
|
|
156
|
-
* @param {number} indent_level
|
|
157
|
-
* @param {string} css
|
|
158
|
-
* @returns {string} A formatted Declaration
|
|
159
|
-
*/
|
|
160
|
-
function print_declaration(node, indent_level, css) {
|
|
161
|
-
return indent(indent_level) + node.property + ': ' + substr(node.value, css) + ';'
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* @param {import('css-tree').CssNode} node
|
|
166
|
-
* @param {number} indent_level
|
|
167
|
-
* @param {string} css
|
|
168
|
-
* @returns {string} A formatted unknown CSS string
|
|
169
|
-
*/
|
|
170
|
-
function print_unknown(node, indent_level, css) {
|
|
171
|
-
return indent(indent_level) + substr(node, css).trim()
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* @param {import('css-tree').Stylesheet} node
|
|
176
|
-
* @param {number} indent_level
|
|
177
|
-
* @param {string} css
|
|
178
|
-
* @returns {string} A formatted Stylesheet
|
|
179
|
-
*/
|
|
180
|
-
function print(node, indent_level = 0, css) {
|
|
181
|
-
let buffer = ''
|
|
182
|
-
let children = node.children
|
|
183
|
-
|
|
184
|
-
for (let child of children) {
|
|
185
|
-
if (child.type === 'Rule') {
|
|
186
|
-
buffer += print_rule(child, indent_level, css)
|
|
187
|
-
} else if (child.type === 'Atrule') {
|
|
188
|
-
buffer += print_atrule(child, indent_level, css)
|
|
189
|
-
} else {
|
|
190
|
-
buffer += print_unknown(child, indent_level, css)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (child !== children.last) {
|
|
194
|
-
buffer += '\n\n'
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return buffer
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Take a string of CSS (minified or not) and format it with some simple rules
|
|
203
|
-
* @param {string} css The original CSS
|
|
204
|
-
* @returns {string} The newly formatted CSS
|
|
205
|
-
*/
|
|
206
|
-
export function format(css) {
|
|
207
|
-
let ast = parse(css, {
|
|
208
|
-
positions: true,
|
|
209
|
-
parseAtrulePrelude: false,
|
|
210
|
-
parseCustomProperty: false,
|
|
211
|
-
parseValue: false,
|
|
212
|
-
})
|
|
213
|
-
return print(ast, 0, css)
|
|
214
|
-
}
|
package/test.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
import { test } from 'uvu'
|
|
2
|
-
import * as assert from 'uvu/assert'
|
|
3
|
-
import { format } from './index.js'
|
|
4
|
-
|
|
5
|
-
test('AtRules and Rules start on a new line', () => {
|
|
6
|
-
let actual = format(`
|
|
7
|
-
selector { property: value; }
|
|
8
|
-
@media (min-width: 1000px) {
|
|
9
|
-
selector { property: value; }
|
|
10
|
-
}
|
|
11
|
-
selector { property: value; }
|
|
12
|
-
@layer test {
|
|
13
|
-
selector { property: value; }
|
|
14
|
-
}
|
|
15
|
-
`)
|
|
16
|
-
let expected = `selector {
|
|
17
|
-
property: value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
@media (min-width: 1000px) {
|
|
21
|
-
selector {
|
|
22
|
-
property: value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
selector {
|
|
27
|
-
property: value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@layer test {
|
|
31
|
-
selector {
|
|
32
|
-
property: value;
|
|
33
|
-
}
|
|
34
|
-
}`
|
|
35
|
-
|
|
36
|
-
assert.equal(actual, expected)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('Atrule blocks are surrounded by {} with correct spacing and indentation', () => {
|
|
40
|
-
let actual = format(`
|
|
41
|
-
@media (min-width:1000px){selector{property:value}}
|
|
42
|
-
|
|
43
|
-
@media (min-width:1000px)
|
|
44
|
-
{
|
|
45
|
-
selector
|
|
46
|
-
{
|
|
47
|
-
property:value
|
|
48
|
-
}
|
|
49
|
-
}`)
|
|
50
|
-
let expected = `@media (min-width:1000px) {
|
|
51
|
-
selector {
|
|
52
|
-
property: value;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
@media (min-width:1000px) {
|
|
57
|
-
selector {
|
|
58
|
-
property: value;
|
|
59
|
-
}
|
|
60
|
-
}`
|
|
61
|
-
|
|
62
|
-
assert.equal(actual, expected)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
test('Does not do AtRule prelude formatting', () => {
|
|
66
|
-
let actual = format(`@media (min-width:1000px){}`)
|
|
67
|
-
let expected = `@media (min-width:1000px) {}
|
|
68
|
-
`
|
|
69
|
-
|
|
70
|
-
assert.equal(actual, expected)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
test('Selectors are placed on a new line, separated by commas', () => {
|
|
74
|
-
let actual = format(`
|
|
75
|
-
selector1,
|
|
76
|
-
selector1a,
|
|
77
|
-
selector1b,
|
|
78
|
-
selector1aa,
|
|
79
|
-
selector2,
|
|
80
|
-
|
|
81
|
-
selector3 {
|
|
82
|
-
}
|
|
83
|
-
`)
|
|
84
|
-
let expected = `selector1,
|
|
85
|
-
selector1a,
|
|
86
|
-
selector1b,
|
|
87
|
-
selector1aa,
|
|
88
|
-
selector2,
|
|
89
|
-
selector3 {}
|
|
90
|
-
`
|
|
91
|
-
|
|
92
|
-
assert.equal(actual, expected)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
test('Declarations end with a semicolon (;)', () => {
|
|
96
|
-
let actual = format(`
|
|
97
|
-
@font-face {
|
|
98
|
-
src: url('test');
|
|
99
|
-
font-family: Test;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
css {
|
|
103
|
-
property1: value2;
|
|
104
|
-
property2: value2;
|
|
105
|
-
|
|
106
|
-
& .nested {
|
|
107
|
-
property1: value2;
|
|
108
|
-
property2: value2
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
@media (min-width: 1000px) {
|
|
113
|
-
@layer test {
|
|
114
|
-
css {
|
|
115
|
-
property1: value1
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
`)
|
|
120
|
-
let expected = `@font-face {
|
|
121
|
-
src: url('test');
|
|
122
|
-
font-family: Test;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
css {
|
|
126
|
-
property1: value2;
|
|
127
|
-
property2: value2;
|
|
128
|
-
& .nested {
|
|
129
|
-
property1: value2;
|
|
130
|
-
property2: value2;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
@media (min-width: 1000px) {
|
|
135
|
-
@layer test {
|
|
136
|
-
css {
|
|
137
|
-
property1: value1;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}`
|
|
141
|
-
|
|
142
|
-
assert.equal(actual, expected)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
test('An empty line is rendered in between Rules', () => {
|
|
146
|
-
let actual = format(`
|
|
147
|
-
rule1 { property: value }
|
|
148
|
-
rule2 { property: value }
|
|
149
|
-
`)
|
|
150
|
-
let expected = `rule1 {
|
|
151
|
-
property: value;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
rule2 {
|
|
155
|
-
property: value;
|
|
156
|
-
}`
|
|
157
|
-
assert.equal(actual, expected)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
test('single empty line after a rule, before atrule', () => {
|
|
161
|
-
let actual = format(`
|
|
162
|
-
rule1 { property: value }
|
|
163
|
-
@media (min-width: 1000px) {
|
|
164
|
-
rule2 { property: value }
|
|
165
|
-
}
|
|
166
|
-
`)
|
|
167
|
-
let expected = `rule1 {
|
|
168
|
-
property: value;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
@media (min-width: 1000px) {
|
|
172
|
-
rule2 {
|
|
173
|
-
property: value;
|
|
174
|
-
}
|
|
175
|
-
}`
|
|
176
|
-
assert.equal(actual, expected)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
test('single empty line in between atrules', () => {
|
|
180
|
-
let actual = format(`
|
|
181
|
-
@layer test1;
|
|
182
|
-
@media (min-width: 1000px) {
|
|
183
|
-
rule2 { property: value }
|
|
184
|
-
}
|
|
185
|
-
`)
|
|
186
|
-
let expected = `@layer test1;
|
|
187
|
-
|
|
188
|
-
@media (min-width: 1000px) {
|
|
189
|
-
rule2 {
|
|
190
|
-
property: value;
|
|
191
|
-
}
|
|
192
|
-
}`
|
|
193
|
-
assert.equal(actual, expected)
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
test('handles comments', () => {
|
|
197
|
-
let actual = format(`
|
|
198
|
-
.async-hide {
|
|
199
|
-
opacity: 0;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/*!
|
|
203
|
-
* Library vx.x.x (http://css-lib.com)
|
|
204
|
-
* Copyright 1970-1800 CSS Inc.
|
|
205
|
-
* Licensed under MIT (https://example.com)
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
|
|
209
|
-
|
|
210
|
-
html /* comment */ {
|
|
211
|
-
font-family /* comment */ : /* comment */ sans-serif;
|
|
212
|
-
-webkit-text-size-adjust: 100%;
|
|
213
|
-
-ms-text-size-adjust: 100%;
|
|
214
|
-
}
|
|
215
|
-
`)
|
|
216
|
-
let expected = `.async-hide {
|
|
217
|
-
opacity: 0;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/*!
|
|
221
|
-
* Library vx.x.x (http://css-lib.com)
|
|
222
|
-
* Copyright 1970-1800 CSS Inc.
|
|
223
|
-
* Licensed under MIT (https://example.com)
|
|
224
|
-
*/
|
|
225
|
-
|
|
226
|
-
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
|
|
227
|
-
|
|
228
|
-
html {
|
|
229
|
-
font-family: sans-serif;
|
|
230
|
-
-webkit-text-size-adjust: 100%;
|
|
231
|
-
-ms-text-size-adjust: 100%;
|
|
232
|
-
}`
|
|
233
|
-
|
|
234
|
-
assert.equal(actual, expected)
|
|
235
|
-
})
|
|
236
|
-
|
|
237
|
-
test('css nesting chaos', () => {
|
|
238
|
-
let actual = format(`
|
|
239
|
-
/**
|
|
240
|
-
* Comment!
|
|
241
|
-
*/
|
|
242
|
-
no-layer-1, no-layer-2 { color: red; font-size: 1rem; COLOR: green; }
|
|
243
|
-
@layer components, deep;
|
|
244
|
-
@layer base { layer-base { color: green; } }
|
|
245
|
-
@layer { @layer named { anon-named { test: 1 } }}
|
|
246
|
-
@media (min-width: 1000px) {
|
|
247
|
-
@layer desktop { layer-desktop { color: blue; } }
|
|
248
|
-
@layer { layer-anon, no-2 { anonymous: 1; } }
|
|
249
|
-
@layer test {}
|
|
250
|
-
@supports (min-width: 1px) {
|
|
251
|
-
@layer deep { layer-deep {} }
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
test { a: 1}
|
|
255
|
-
@layer components {
|
|
256
|
-
@layer alert {}
|
|
257
|
-
@layer table {
|
|
258
|
-
@layer tbody, thead;
|
|
259
|
-
layer-components-table { color: yellow; }
|
|
260
|
-
@layer tbody { tbody { border: 1px solid; background: red; } }
|
|
261
|
-
@media (min-width: 30em) {
|
|
262
|
-
@supports (display: grid) {
|
|
263
|
-
@layer thead { thead { border: 1px solid; } }
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
@layer components.breadcrumb { layer-components-breadcrumb { } }
|
|
269
|
-
|
|
270
|
-
@font-face {
|
|
271
|
-
font-family: "Test";
|
|
272
|
-
src: url(some-url.woff2);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
;;;;;;;;;;;;;;;;;;;
|
|
276
|
-
`)
|
|
277
|
-
let expected = `no-layer-1,
|
|
278
|
-
no-layer-2 {
|
|
279
|
-
color: red;
|
|
280
|
-
font-size: 1rem;
|
|
281
|
-
COLOR: green;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
@layer components, deep;
|
|
285
|
-
|
|
286
|
-
@layer base {
|
|
287
|
-
layer-base {
|
|
288
|
-
color: green;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
@layer {
|
|
293
|
-
@layer named {
|
|
294
|
-
anon-named {
|
|
295
|
-
test: 1;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
@media (min-width: 1000px) {
|
|
301
|
-
@layer desktop {
|
|
302
|
-
layer-desktop {
|
|
303
|
-
color: blue;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
@layer {
|
|
308
|
-
layer-anon,
|
|
309
|
-
no-2 {
|
|
310
|
-
anonymous: 1;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
@layer test {}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
@supports (min-width: 1px) {
|
|
318
|
-
@layer deep {
|
|
319
|
-
layer-deep {}
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
test {
|
|
326
|
-
a: 1;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
@layer components {
|
|
330
|
-
@layer alert {}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
@layer table {
|
|
334
|
-
@layer tbody, thead;
|
|
335
|
-
|
|
336
|
-
layer-components-table {
|
|
337
|
-
color: yellow;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
@layer tbody {
|
|
341
|
-
tbody {
|
|
342
|
-
border: 1px solid;
|
|
343
|
-
background: red;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
@media (min-width: 30em) {
|
|
348
|
-
@supports (display: grid) {
|
|
349
|
-
@layer thead {
|
|
350
|
-
thead {
|
|
351
|
-
border: 1px solid;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
@layer components.breadcrumb {
|
|
360
|
-
layer-components-breadcrumb {}
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
@font-face {
|
|
365
|
-
font-family: "Test";
|
|
366
|
-
src: url(some-url.woff2);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
;;;;;;;;;;;;;;;;;;;`
|
|
370
|
-
assert.equal(actual, expected);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
test.run();
|