fela-beautifier
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -510,9 +510,10 @@ (function (global, factory) { | ||
var defaultOptions = { | ||
indent: ' ', | ||
openbrace: 'end-of-line', | ||
autosemicolon: false | ||
}; | ||
function beautifier(renderer, options) { | ||
/** | ||
* beautifies CSS output of renderToString | ||
* | ||
* @param {Object} renderer - renderer which gets enhanced | ||
* @param {Object} options - beautifier options | ||
* @return {Object} enhanced renderer | ||
*/ | ||
function addBeautifier(renderer, options) { | ||
var existingRenderToString = renderer.renderToString.bind(renderer); | ||
@@ -522,4 +523,3 @@ | ||
var css = existingRenderToString(); | ||
return cssbeautify$1(css, babelHelpers.extends({}, defaultOptions, options)); | ||
return cssbeautify$1(css, options); | ||
}; | ||
@@ -530,11 +530,17 @@ | ||
var beautifier$1 = (function (options) { | ||
var defaultOptions = { | ||
indent: ' ', | ||
openbrace: 'end-of-line', | ||
autosemicolon: false | ||
}; | ||
var beautifier = (function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return function (renderer) { | ||
return beautifier(renderer, options); | ||
return addBeautifier(renderer, babelHelpers.extends({}, defaultOptions, options)); | ||
}; | ||
}); | ||
return beautifier$1; | ||
return beautifier; | ||
})); | ||
//# sourceMappingURL=fela-beautifier.js.map |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.FelaBeautifier=n()}(this,function(){"use strict";function e(e,n){return n={exports:{}},e(n,n.exports),n.exports}function n(e,n){var o=e.renderToString.bind(e);return e.renderToString=function(){var e=o();return r(e,t.extends({},i,n))},e}var t={};t.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};var o=e(function(e,n){!function(){function o(e,n){function t(e){return" "===e||"\n"===e||"\t"===e||"\r"===e||"\f"===e}function o(e){return"'"===e||'"'===e}function r(e){return a>="a"&&a<="z"||a>="A"&&a<="Z"||a>="0"&&a<="9"||"-_*.:#[]".indexOf(e)>=0}function i(){var e;for(e=y;e>0;e-=1)x+=u.indent}function f(){x=b(x),R?x+=" {":(x+="\n",i(),x+="{"),"\n"!==s&&(x+="\n"),y+=1}function c(){var e;y-=1,x=b(x),x.length>0&&v&&(e=x.charAt(x.length-1),";"!==e&&"{"!==e&&(x+=";")),x+="\n",i(),x+="}",l.push(x),x=""}var u,l,a,s,p,h,d,y,g,S,b,A=0,m=e.length,x="",R=!0,v=!1;for(u=arguments.length>1?n:{},"undefined"==typeof u.indent&&(u.indent=" "),"string"==typeof u.openbrace&&(R="end-of-line"===u.openbrace),"boolean"==typeof u.autosemicolon&&(v=u.autosemicolon),b=String.prototype.trimRight?function(e){return e.trimRight()}:function(e){return e.replace(/\s+$/,"")},d={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},y=0,h=d.Start,S=!1,l=[],e=e.replace(/\r\n/g,"\n");A<m;)if(a=e.charAt(A),s=e.charAt(A+1),A+=1,o(g))x+=a,a===g&&(g=null),"\\"===a&&s===g&&(x+=s,A+=1);else if(o(a))x+=a,g=a;else if(S)x+=a,"*"===a&&"/"===s&&(S=!1,x+=s,A+=1);else if("/"!==a||"*"!==s){if(h===d.Start){if(0===l.length&&t(a)&&0===x.length)continue;if(a<=" "||a.charCodeAt(0)>=128){h=d.Start,x+=a;continue}if(r(a)||"@"===a){if(p=b(x),0===p.length)l.length>0&&(x="\n\n");else if("}"===p.charAt(p.length-1)||";"===p.charAt(p.length-1))x=p+"\n\n";else for(;;){if(s=x.charAt(x.length-1)," "!==s&&9!==s.charCodeAt(0))break;x=x.substr(0,x.length-1)}x+=a,h="@"===a?d.AtRule:d.Selector;continue}}if(h!==d.AtRule)if(h!==d.Block)if(h!==d.Selector)if(h!==d.Ruleset)if(h!==d.Property)if(h!==d.Separator)if(h!==d.Expression)h===d.URL&&")"===a&&x.charAt(x.length-1!=="\\")?(x+=a,h=d.Expression):x+=a;else{if("}"===a){c(),h=d.Start,y>0&&(h=d.Block);continue}if(";"===a){x=b(x),x+=";\n",h=d.Ruleset;continue}if(x+=a,"("===a&&"l"===x.charAt(x.length-2)&&"r"===x.charAt(x.length-3)&&"u"===x.charAt(x.length-4)){h=d.URL;continue}}else{if(!t(a)){x+=a,h=d.Expression;continue}o(s)&&(h=d.Expression)}else{if(":"===a){x=b(x),x+=": ",h=d.Expression,t(s)&&(h=d.Separator);continue}if("}"===a){c(),h=d.Start,y>0&&(h=d.Block);continue}x+=a}else{if("}"===a){c(),h=d.Start,y>0&&(h=d.Block);continue}if("\n"===a){x=b(x),x+="\n";continue}if(!t(a)){x=b(x),x+="\n",i(),x+=a,h=d.Property;continue}x+=a}else{if("{"===a){f(),h=d.Ruleset;continue}if("}"===a){c(),h=d.Start;continue}x+=a}else{if(r(a)){if(p=b(x),0===p.length)l.length>0&&(x="\n\n");else if("}"===p.charAt(p.length-1))x=p+"\n\n";else for(;;){if(s=x.charAt(x.length-1)," "!==s&&9!==s.charCodeAt(0))break;x=x.substr(0,x.length-1)}i(),x+=a,h=d.Selector;continue}if("}"===a){c(),h=d.Start;continue}x+=a}else{if(";"===a){x+=a,h=d.Start;continue}if("{"===a){p=b(x),f(),h="@font-face"===p?d.Ruleset:d.Block;continue}x+=a}}else S=!0,x+=a,x+=s,A+=1;return x=l.join("")+x}"undefined"!=typeof n?e.exports=n=o:"object"===("undefined"==typeof window?"undefined":t.typeof(window))&&(window.cssbeautify=o)}()}),r=o&&"object"==typeof o&&"default"in o?o.default:o,i={indent:" ",openbrace:"end-of-line",autosemicolon:!1},f=function(e){return function(t){return n(t,e)}};return f}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.FelaBeautifier=n()}(this,function(){"use strict";function e(e,n){return n={exports:{}},e(n,n.exports),n.exports}function n(e,n){var t=e.renderToString.bind(e);return e.renderToString=function(){var e=t();return r(e,n)},e}var t={};t.typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.extends=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e};var o=e(function(e,n){!function(){function o(e,n){function t(e){return" "===e||"\n"===e||"\t"===e||"\r"===e||"\f"===e}function o(e){return"'"===e||'"'===e}function r(e){return a>="a"&&a<="z"||a>="A"&&a<="Z"||a>="0"&&a<="9"||"-_*.:#[]".indexOf(e)>=0}function i(){var e;for(e=g;e>0;e-=1)x+=u.indent}function f(){x=b(x),R?x+=" {":(x+="\n",i(),x+="{"),"\n"!==s&&(x+="\n"),g+=1}function c(){var e;g-=1,x=b(x),x.length>0&&v&&(e=x.charAt(x.length-1),";"!==e&&"{"!==e&&(x+=";")),x+="\n",i(),x+="}",l.push(x),x=""}var u,l,a,s,p,h,d,g,y,S,b,A=0,m=e.length,x="",R=!0,v=!1;for(u=arguments.length>1?n:{},"undefined"==typeof u.indent&&(u.indent=" "),"string"==typeof u.openbrace&&(R="end-of-line"===u.openbrace),"boolean"==typeof u.autosemicolon&&(v=u.autosemicolon),b=String.prototype.trimRight?function(e){return e.trimRight()}:function(e){return e.replace(/\s+$/,"")},d={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},g=0,h=d.Start,S=!1,l=[],e=e.replace(/\r\n/g,"\n");A<m;)if(a=e.charAt(A),s=e.charAt(A+1),A+=1,o(y))x+=a,a===y&&(y=null),"\\"===a&&s===y&&(x+=s,A+=1);else if(o(a))x+=a,y=a;else if(S)x+=a,"*"===a&&"/"===s&&(S=!1,x+=s,A+=1);else if("/"!==a||"*"!==s){if(h===d.Start){if(0===l.length&&t(a)&&0===x.length)continue;if(a<=" "||a.charCodeAt(0)>=128){h=d.Start,x+=a;continue}if(r(a)||"@"===a){if(p=b(x),0===p.length)l.length>0&&(x="\n\n");else if("}"===p.charAt(p.length-1)||";"===p.charAt(p.length-1))x=p+"\n\n";else for(;;){if(s=x.charAt(x.length-1)," "!==s&&9!==s.charCodeAt(0))break;x=x.substr(0,x.length-1)}x+=a,h="@"===a?d.AtRule:d.Selector;continue}}if(h!==d.AtRule)if(h!==d.Block)if(h!==d.Selector)if(h!==d.Ruleset)if(h!==d.Property)if(h!==d.Separator)if(h!==d.Expression)h===d.URL&&")"===a&&x.charAt(x.length-1!=="\\")?(x+=a,h=d.Expression):x+=a;else{if("}"===a){c(),h=d.Start,g>0&&(h=d.Block);continue}if(";"===a){x=b(x),x+=";\n",h=d.Ruleset;continue}if(x+=a,"("===a&&"l"===x.charAt(x.length-2)&&"r"===x.charAt(x.length-3)&&"u"===x.charAt(x.length-4)){h=d.URL;continue}}else{if(!t(a)){x+=a,h=d.Expression;continue}o(s)&&(h=d.Expression)}else{if(":"===a){x=b(x),x+=": ",h=d.Expression,t(s)&&(h=d.Separator);continue}if("}"===a){c(),h=d.Start,g>0&&(h=d.Block);continue}x+=a}else{if("}"===a){c(),h=d.Start,g>0&&(h=d.Block);continue}if("\n"===a){x=b(x),x+="\n";continue}if(!t(a)){x=b(x),x+="\n",i(),x+=a,h=d.Property;continue}x+=a}else{if("{"===a){f(),h=d.Ruleset;continue}if("}"===a){c(),h=d.Start;continue}x+=a}else{if(r(a)){if(p=b(x),0===p.length)l.length>0&&(x="\n\n");else if("}"===p.charAt(p.length-1))x=p+"\n\n";else for(;;){if(s=x.charAt(x.length-1)," "!==s&&9!==s.charCodeAt(0))break;x=x.substr(0,x.length-1)}i(),x+=a,h=d.Selector;continue}if("}"===a){c(),h=d.Start;continue}x+=a}else{if(";"===a){x+=a,h=d.Start;continue}if("{"===a){p=b(x),f(),h="@font-face"===p?d.Ruleset:d.Block;continue}x+=a}}else S=!0,x+=a,x+=s,A+=1;return x=l.join("")+x}"undefined"!=typeof n?e.exports=n=o:"object"===("undefined"==typeof window?"undefined":t.typeof(window))&&(window.cssbeautify=o)}()}),r=o&&"object"==typeof o&&"default"in o?o.default:o,i={indent:" ",openbrace:"end-of-line",autosemicolon:!1},f=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(o){return n(o,t.extends({},i,e))}};return f}); |
{ | ||
"name": "fela-beautifier", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Fela enhancer to beautify CSS output", | ||
@@ -29,4 +29,4 @@ "main": "index.js", | ||
"peerDependencies": { | ||
"fela": "3.0.1" | ||
"fela": "3.0.2" | ||
} | ||
} |
# fela-beautifier | ||
<img alt="npm downloads" src="https://img.shields.io/npm/dm/fela-beautifier.svg"> | ||
<img alt="gzipped size" src="https://img.shields.io/badge/gzipped-1.49kb-brightgreen.svg"> | ||
<img alt="gzipped size" src="https://img.shields.io/badge/gzipped-1.51kb-brightgreen.svg"> | ||
@@ -16,10 +16,7 @@ The beautifier enhancer is a developer tool that automatically formats the rendered CSS markup on every change. It uses [cssbeautify](https://github.com/senchalabs/cssbeautify) to achieve this. | ||
<!-- Fela (Development): Unminified version including all warnings --> | ||
<script src="https://unpkg.com/fela-beautifier@3.0.1/dist/fela-beautifier.js"></script> | ||
<script src="https://unpkg.com/fela-beautifier@3.0.2/dist/fela-beautifier.js"></script> | ||
<!-- Fela (Production): Minified version --> | ||
<script src="https://unpkg.com/fela-beautifier@3.0.1/dist/fela-beautifier.min.js"></script> | ||
<script src="https://unpkg.com/fela-beautifier@3.0.2/dist/fela-beautifier.min.js"></script> | ||
``` | ||
## Example | ||
![Preview](preview.png) | ||
## Usage | ||
@@ -30,20 +27,37 @@ ```javascript | ||
const enhancer = beautifier({ | ||
ident: ' ', | ||
openbrace: 'separate-line', | ||
autosemicolon: 'false' | ||
const renderer = createRenderer({ | ||
enhancers: [ beautifier() ] | ||
}) | ||
const renderer = createRenderer({ enhancers: [enhancer] }) | ||
``` | ||
## Configuration | ||
### Configuration | ||
##### Options | ||
Uses the same options as [cssbeautify](https://github.com/senchalabs/cssbeautify) does. | ||
| option | value | default |description | | ||
| Option | Value | Default | Description | | ||
| ------ | --- | ------------ | --- | | ||
|ident| `string` |` ` (2 spaces)| a string used for the indentation of the declaration | | ||
|ident| *(string)* |` ` (2 spaces)| a string used for the indentation of the declaration | | ||
|openbrace| `end-of-line`, `separate-line` |`end-of-line`| placement of open curly brace | | ||
| autosemicolon | `boolean`| `false` | insert semicolon after the last rule | | ||
| autosemicolon | *(boolean)* | `false` | insert semicolon after the last rule | | ||
##### Example | ||
```javascript | ||
import { createRenderer } from 'fela' | ||
import beautifier from 'fela-beautifier' | ||
const beautifyEnhancer = beautifier({ | ||
openbrace: 'separate-line', | ||
autosemicolon: 'false', | ||
ident: ' ', | ||
}) | ||
const renderer = createRenderer({ | ||
enhancers: [ beautifyEnhancer ] | ||
}) | ||
``` | ||
## Example | ||
![Preview](preview.png) | ||
## License | ||
@@ -50,0 +64,0 @@ Fela is licensed under the [MIT License](http://opensource.org/licenses/MIT).<br> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50609
455
65