expressCart/public/javascripts/cssbeautify.min.js

1 line
2.9 KiB
JavaScript

!function(){"use strict";function e(e,t){function n(e){return" "===e||"\n"===e||"\t"===e||"\r"===e||"\f"===e}function i(e){return"'"===e||'"'===e}function r(e){return s>="a"&&s<="z"||s>="A"&&s<="Z"||s>="0"&&s<="9"||"-_*.:#[]".indexOf(e)>=0}function o(){var e;for(e=A;e>0;e-=1)b+=f.indent}function l(){b=R(b),k?b+=" {":(b+="\n",o(),b+="{"),"\n"!==a&&(b+="\n"),A+=1}function c(){var e;A-=1,b=R(b),b.length>0&&B&&(e=b.charAt(b.length-1),";"!==e&&"{"!==e&&(b+=";")),b+="\n",o(),b+="}",u.push(b),b=""}var f,u,s,a,h,p,g,A,S,d,R,x=0,y=e.length,b="",k=!0,B=!1;for(f=arguments.length>1?t:{},"undefined"==typeof f.indent&&(f.indent=" "),"string"==typeof f.openbrace&&(k="end-of-line"===f.openbrace),"boolean"==typeof f.autosemicolon&&(B=f.autosemicolon),R=String.prototype.trimRight?function(e){return e.trimRight()}:function(e){return e.replace(/\s+$/,"")},g={Start:0,AtRule:1,Block:2,Selector:3,Ruleset:4,Property:5,Separator:6,Expression:7,URL:8},A=0,p=g.Start,d=!1,u=[],e=e.replace(/\r\n/g,"\n");x<y;)if(s=e.charAt(x),a=e.charAt(x+1),x+=1,i(S))b+=s,s===S&&(S=null),"\\"===s&&a===S&&(b+=a,x+=1);else if(i(s))b+=s,S=s;else if(d)b+=s,"*"===s&&"/"===a&&(d=!1,b+=a,x+=1);else if("/"!==s||"*"!==a){if(p===g.Start){if(0===u.length&&n(s)&&0===b.length)continue;if(s<=" "||s.charCodeAt(0)>=128){p=g.Start,b+=s;continue}if(r(s)||"@"===s){if(h=R(b),0===h.length)u.length>0&&(b="\n\n");else if("}"===h.charAt(h.length-1)||";"===h.charAt(h.length-1))b=h+"\n\n";else for(;;){if(a=b.charAt(b.length-1)," "!==a&&9!==a.charCodeAt(0))break;b=b.substr(0,b.length-1)}b+=s,p="@"===s?g.AtRule:g.Selector;continue}}if(p!==g.AtRule)if(p!==g.Block)if(p!==g.Selector)if(p!==g.Ruleset)if(p!==g.Property)if(p!==g.Separator)if(p!==g.Expression)p===g.URL&&")"===s&&b.charAt(b.length-1!=="\\")?(b+=s,p=g.Expression):b+=s;else{if("}"===s){c(),p=g.Start,A>0&&(p=g.Block);continue}if(";"===s){b=R(b),b+=";\n",p=g.Ruleset;continue}if(b+=s,"("===s&&"l"===b.charAt(b.length-2)&&"r"===b.charAt(b.length-3)&&"u"===b.charAt(b.length-4)){p=g.URL;continue}}else{if(!n(s)){b+=s,p=g.Expression;continue}i(a)&&(p=g.Expression)}else{if(":"===s){b=R(b),b+=": ",p=g.Expression,n(a)&&(p=g.Separator);continue}if("}"===s){c(),p=g.Start,A>0&&(p=g.Block);continue}b+=s}else{if("}"===s){c(),p=g.Start,A>0&&(p=g.Block);continue}if("\n"===s){b=R(b),b+="\n";continue}if(!n(s)){b=R(b),b+="\n",o(),b+=s,p=g.Property;continue}b+=s}else{if("{"===s){l(),p=g.Ruleset;continue}if("}"===s){c(),p=g.Start;continue}b+=s}else{if(r(s)){if(h=R(b),0===h.length)u.length>0&&(b="\n\n");else if("}"===h.charAt(h.length-1))b=h+"\n\n";else for(;;){if(a=b.charAt(b.length-1)," "!==a&&9!==a.charCodeAt(0))break;b=b.substr(0,b.length-1)}o(),b+=s,p=g.Selector;continue}if("}"===s){c(),p=g.Start;continue}b+=s}else{if(";"===s){b+=s,p=g.Start;continue}if("{"===s){h=R(b),l(),p="@font-face"===h?g.Ruleset:g.Block;continue}b+=s}}else d=!0,b+=s,b+=a,x+=1;return b=u.join("")+b}"undefined"!=typeof exports?module.exports=exports=e:"object"==typeof window&&(window.cssbeautify=e)}();