diff --git a/Appraisals b/Appraisals index a48ac4f..6a5cd90 100644 --- a/Appraisals +++ b/Appraisals @@ -12,6 +12,7 @@ end appraise "sprockets-4" do gem "sprockets", "~>4.0.0.beta2" + gem 'sass', '>=3.3' end appraise "rails-4" do diff --git a/gemfiles/rails_4.gemfile.lock b/gemfiles/rails_4.gemfile.lock index ba361c4..7ea5b69 100644 --- a/gemfiles/rails_4.gemfile.lock +++ b/gemfiles/rails_4.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - csso-rails (0.4.0) + csso-rails (0.4.1) execjs (>= 1) GEM @@ -115,4 +115,4 @@ DEPENDENCIES rake BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/gemfiles/sprockets_2.gemfile.lock b/gemfiles/sprockets_2.gemfile.lock index 683d80b..9f1fdb4 100644 --- a/gemfiles/sprockets_2.gemfile.lock +++ b/gemfiles/sprockets_2.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - csso-rails (0.4.0) + csso-rails (0.4.1) execjs (>= 1) GEM diff --git a/gemfiles/sprockets_3.gemfile.lock b/gemfiles/sprockets_3.gemfile.lock index 6b45ffb..92ae951 100644 --- a/gemfiles/sprockets_3.gemfile.lock +++ b/gemfiles/sprockets_3.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - csso-rails (0.4.0) + csso-rails (0.4.1) execjs (>= 1) GEM diff --git a/gemfiles/sprockets_4.gemfile b/gemfiles/sprockets_4.gemfile index 2403cea..e76083d 100644 --- a/gemfiles/sprockets_4.gemfile +++ b/gemfiles/sprockets_4.gemfile @@ -3,5 +3,6 @@ source "https://rubygems.org" gem "sprockets", "~>4.0.0.beta2" +gem "sass", ">=3.3" gemspec :path => "../" diff --git a/gemfiles/sprockets_4.gemfile.lock b/gemfiles/sprockets_4.gemfile.lock index 973e732..3ea1290 100644 --- a/gemfiles/sprockets_4.gemfile.lock +++ b/gemfiles/sprockets_4.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - csso-rails (0.4.0) + csso-rails (0.4.1) execjs (>= 1) GEM @@ -16,6 +16,7 @@ GEM minitest (5.8.4) rack (1.6.4) rake (11.1.0) + sass (3.4.21) sprockets (4.0.0.beta2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -29,7 +30,8 @@ DEPENDENCIES csso-rails! minitest rake + sass (>= 3.3) sprockets (~> 4.0.0.beta2) BUNDLED WITH - 1.10.6 + 1.11.2 diff --git a/gemfiles/therubyracer.gemfile.lock b/gemfiles/therubyracer.gemfile.lock index 3b06713..fbb1016 100644 --- a/gemfiles/therubyracer.gemfile.lock +++ b/gemfiles/therubyracer.gemfile.lock @@ -1,7 +1,7 @@ PATH remote: ../ specs: - csso-rails (0.4.0) + csso-rails (0.4.1) execjs (>= 1) GEM diff --git a/lib/csso.rb b/lib/csso.rb index f853dcb..8d334e2 100644 --- a/lib/csso.rb +++ b/lib/csso.rb @@ -36,6 +36,12 @@ def self.optimize(css, maniac_mode=false, structural_optimization=true) end end + def self.optimize_with_sourcemap css, filename, structural_optimization=true + return nil unless css.is_a?(String) + return css if css.size <= 3 + Csso.js_api.compress_with_sourcemap(css, filename, structural_optimization) + end + class Optimizer def optimize(css, structural_optimization=true) diff --git a/lib/csso/compressor.rb b/lib/csso/compressor.rb index 78d6ff7..d19e474 100644 --- a/lib/csso/compressor.rb +++ b/lib/csso/compressor.rb @@ -3,10 +3,20 @@ class Compressor def self.call(input) require 'csso' #TODO: settings? - #TODO: handle metadata somehow? - { - data: Csso.optimize(input[:data], true) - } + if input[:metadata] && input[:metadata][:map] + css, map = Csso.optimize_with_sourcemap(input[:data], + # Sprockets::PathUtils.split_subpath(input[:load_path], input[:filename]) + # sprockets seems to ignore filenames here, so we may save some mem: + 'uri' + ) + map = Sprockets::SourceMapUtils.combine_source_maps( + input[:metadata][:map], + Sprockets::SourceMapUtils.decode_json_source_map(map)["mappings"] + ) + { data: css, map: map } + else + { data: Csso.optimize(input[:data], true) } + end end # sprockets 2: diff --git a/lib/csso/csso.js.erb b/lib/csso/csso.js.erb index e7c9340..daaae5c 100644 --- a/lib/csso/csso.js.erb +++ b/lib/csso/csso.js.erb @@ -30,3 +30,12 @@ do_compression = function(css, disable_structural){ restructure: !disable_structural }); }; + +do_compression_with_map = function(css, filename, structural){ + var result = csso.minify(css, { + restructure: structural, + filename: filename, + sourceMap: true + }); + return [result.css, result.map.toString()]; +}; diff --git a/lib/csso/js_lib.rb b/lib/csso/js_lib.rb index 74a7887..5b50814 100644 --- a/lib/csso/js_lib.rb +++ b/lib/csso/js_lib.rb @@ -15,7 +15,11 @@ def initialize end def compress css, structural_optimization=true - @csso.call("do_compression", css, !structural_optimization) + @csso.call("do_compression", css, structural_optimization) + end + + def compress_with_sourcemap css, filename, structural_optimization=true + @csso.call("do_compression_with_map", css, filename, structural_optimization) end end diff --git a/spec/csso/sprockets_integration_spec.rb b/spec/csso/sprockets_integration_spec.rb index 3c3d393..7d0a7f5 100644 --- a/spec/csso/sprockets_integration_spec.rb +++ b/spec/csso/sprockets_integration_spec.rb @@ -9,10 +9,16 @@ describe Csso do subject { Csso } - let(:sprockets_env){ + let(:sprockets_env_without_csso){ + begin + require 'sprockets' + rescue LoadError + skip "Skipping sprockets integration, as there's no sprockets in this env" + end e = Sprockets::Environment.new(File.expand_path('../', File.dirname(__FILE__))) e.append_path 'fixtures' e.config = e.config.merge(gzip_enabled: false).freeze if e.respond_to? :config + # e.logger = Logger.new STDOUT e } let(:result_dir){ @@ -24,17 +30,15 @@ File.expand_path('manifest.json', result_dir) } let(:manifest){ + sprockets_env Sprockets::Manifest.new(sprockets_env, result_dir, manifest_file) } + let(:sprockets_env){ + subject.install(sprockets_env_without_csso) + sprockets_env_without_csso + } it "installs" do - begin - require 'sprockets' - rescue LoadError - skip "Skipping sprockets integration, as there's no sprockets in this env" - end - - subject.install(sprockets_env) sprockets_env.css_compressor.must_equal Csso::Compressor manifest.environment.must_equal(sprockets_env) manifest.clobber @@ -46,6 +50,23 @@ manifest.clobber end + it "compiles with sourcemap" do + manifest.clobber + begin + require 'sass' + rescue LoadError + skip 'No sass in this env, skipping' + end + manifest.compile('test2.css') + manifest.compile('test2.css.map') + json = JSON.load File.read(manifest_file) + json["assets"]["test2.css"].must_match /\.css$/ + sprockets_env['test2.css'].source.must_equal '.class,.class .other_class{color:red}.something{color:#000}.test2{color:#00f}' + map = JSON.load(sprockets_env['test2.css.map'].source) + map["sources"].size.must_equal 4 + manifest.clobber + end + it "loads into rails" do begin require "rails" diff --git a/spec/fixtures/test2.css b/spec/fixtures/test2.css new file mode 100644 index 0000000..34e6f18 --- /dev/null +++ b/spec/fixtures/test2.css @@ -0,0 +1,7 @@ +/* LaLaLa */ +//= require ./test.css +//= require ./test4.css + +.test2{ + color: #0000ff; +} diff --git a/spec/fixtures/test3.scss b/spec/fixtures/test3.scss new file mode 100644 index 0000000..dc995bd --- /dev/null +++ b/spec/fixtures/test3.scss @@ -0,0 +1,3 @@ +.something{ + color: #000000; +} diff --git a/spec/fixtures/test4.scss b/spec/fixtures/test4.scss new file mode 100644 index 0000000..0bbb67d --- /dev/null +++ b/spec/fixtures/test4.scss @@ -0,0 +1,10 @@ +@import 'test3'; + +$color: #ff0000; + +.class { + .other_class{ + // comment blablabla + color: $color; + } +} diff --git a/vendor/csso/csso.js b/vendor/csso/csso.js index 95d649e..b8a0349 100644 --- a/vendor/csso/csso.js +++ b/vendor/csso/csso.js @@ -17,8 +17,16 @@ type:"Declaration",info:r.info,property:r.getProperty(),value:r.getValue(),id:0, simpleselector:d,string:ae,stylesheet:u,unary:ie,unknown:se,uri:N,value:v,vhash:ue};t.exports=function(e,t,r){var n;return r=r||{},r===!0&&(r={positions:!0,needInfo:!0}),le="positions"in r?r.positions||!1:r.needPositions||!1,ce=r.filename||"",t=t||"stylesheet",fe=0,pe=me(e,r.line,r.column),pe.length&&(n=we[t]()),pe=null,n||"stylesheet"!==t||(n=[{},t]),n&&!r.needInfo&&(n=ge(n)),n}},{"../utils/cleanInfo.js":43,"./const.js":40,"./tokenize.js":42}],42:[function(e,t,r){"use strict";function n(e,t,r){function n(e,t,r,n){y.push({type:e,value:n,offset:b,line:t,column:r}),b=h}if(!e)return[];var o,m,g,y=[],v=!1,b=0,k=0;for(h=65279===e.charCodeAt(0)?1:0,b=h,f="undefined"==typeof t?1:t,p="undefined"==typeof r?-1:-r;ho?I[o]:0){case R:n(d.DecimalNumber,f,h-p,l(e));break;case M:case O:n(d.String,f,h-p,u(e,o));break;case L:n(d.Space,f,h-p,a(e));break;case T:if(o===A){if(m=e.charCodeAt(h+1),m===C){n(d.Comment,f,h-p,i(e));continue}if(m===A&&!v){if(k>0){for(var w=2;e.charCodeAt(h+w)===A;)w++;n(d.Identifier,f,h-p,g=c(e,w)),v=v||"url"===g}else n(d.Unknown,f,h-p,s(e));continue}}n(E[o],f,h-p,String.fromCharCode(o)),o===S?v=!1:o===j?k++:o===P&&k--;break;default:n(d.Identifier,f,h-p,g=c(e,0)),v=v||"url"===g}return y}function o(e,t){return e===g||e===y||e===v?(e===v&&h+1t||t>57));h++);return h--,e.substring(r,h+1)}function c(e,t){var r=h;for(h+=t;ha&&h+a=48&&57>=n||n>=65&&70>=n||n>=97&&102>=n)){a>0&&(h+=a-1,(n===b||n===m||o(n,e))&&h++);break}}else if(q>n&&N[n]===T)break}return h--,e.substring(r,h+1)}var p,f,h,d=e("./const.js").TokenType,m=9,g=10,y=12,v=13,b=32,k=34,w=39,S=41,C=42,A=47,x=92,_=95,j=123,P=125,L=1,T=2,R=3,M=4,O=5,E={9:d.Tab,10:d.Newline,13:d.Newline,32:d.Space,33:d.ExclamationMark,34:d.QuotationMark,35:d.NumberSign,36:d.DollarSign,37:d.PercentSign,38:d.Ampersand,39:d.Apostrophe,40:d.LeftParenthesis,41:d.RightParenthesis,42:d.Asterisk,43:d.PlusSign,44:d.Comma,45:d.HyphenMinus,46:d.FullStop,47:d.Solidus,58:d.Colon,59:d.Semicolon,60:d.LessThanSign,61:d.EqualsSign,62:d.GreaterThanSign,63:d.QuestionMark,64:d.CommercialAt,91:d.LeftSquareBracket,93:d.RightSquareBracket,94:d.CircumflexAccent,95:d.LowLine,123:d.LeftCurlyBracket,124:d.VerticalLine,125:d.RightCurlyBracket,126:d.Tilde},q=Math.max.apply(null,Object.keys(E))+1,I=new Uint32Array(q),N=new Uint32Array(q);Object.keys(E).forEach(function(e){I[Number(e)]=T,N[Number(e)]=T},I),N[_]=0;for(var B=48;57>=B;B++)I[B]=R;I[b]=L,I[m]=L,I[g]=L,I[v]=L,I[y]=L,I[w]=M,I[k]=O,t.exports=n},{"./const.js":40}],43:[function(e,t,r){t.exports=function n(e){for(var t,r=e.slice(1),o=1;t=r[o];o++)Array.isArray(t)&&(r[o]=n(t));return r}},{}],44:[function(e,t,r){function n(e){return{data:e,next:null,prev:null}}var o=function(e){if(this.cursor=null,this.head=null,this.tail=null,Array.isArray(e)){for(var t=null,r=0;ro;o++)r.add(e[o],t);return r},n.prototype.size=function(){return Object.getOwnPropertyNames(this._set).length},n.prototype.add=function(e,t){var r=o.toSetString(e),n=this._set.hasOwnProperty(r),a=this._array.length;(!n||t)&&this._array.push(e),n||(this._set[r]=a)},n.prototype.has=function(e){var t=o.toSetString(e);return this._set.hasOwnProperty(t)},n.prototype.indexOf=function(e){var t=o.toSetString(e);if(this._set.hasOwnProperty(t))return this._set[t];throw new Error('"'+e+'" is not in the set.')},n.prototype.at=function(e){if(e>=0&&ee?(-e<<1)+1:(e<<1)+0}function o(e){var t=1===(1&e),r=e>>1;return t?-r:r}var a=e("./base64"),i=5,s=1<>>=i,o>0&&(t|=l),r+=a.encode(t);while(o>0);return r},r.decode=function(e,t,r){var n,s,c=e.length,p=0,f=0;do{if(t>=c)throw new Error("Expected more digits in base 64 VLQ value.");if(s=a.decode(e.charCodeAt(t++)),-1===s)throw new Error("Invalid base64 digit: "+e.charAt(t-1));n=!!(s&l),s&=u,p+=s<=0&&e=t&&r>=e?e-t:e>=n&&o>=e?e-n+l:e>=a&&i>=e?e-a+c:e==s?62:e==u?63:-1}},{}],51:[function(e,t,r){function n(e,t,o,a,i,s){var u=Math.floor((t-e)/2)+e,l=i(o,a[u],!0);return 0===l?u:l>0?t-u>1?n(u,t,o,a,i,s):s==r.LEAST_UPPER_BOUND?t1?n(e,u,o,a,i,s):s==r.LEAST_UPPER_BOUND?u:0>e?-1:e}r.GREATEST_LOWER_BOUND=1,r.LEAST_UPPER_BOUND=2,r.search=function(e,t,o,a){if(0===t.length)return-1;var i=n(-1,t.length,e,t,o,a||r.GREATEST_LOWER_BOUND);if(0>i)return-1;for(;i-1>=0&&0===o(t[i],t[i-1],!0);)--i;return i}},{}],52:[function(e,t,r){function n(e,t){var r=e.generatedLine,n=t.generatedLine,o=e.generatedColumn,i=t.generatedColumn;return n>r||n==r&&i>=o||a.compareByGeneratedPositionsInflated(e,t)<=0}function o(){this._array=[],this._sorted=!0,this._last={generatedLine:-1,generatedColumn:0}}var a=e("./util");o.prototype.unsortedForEach=function(e,t){this._array.forEach(e,t)},o.prototype.add=function(e){n(this._last,e)?(this._last=e,this._array.push(e)):(this._sorted=!1,this._array.push(e))},o.prototype.toArray=function(){return this._sorted||(this._array.sort(a.compareByGeneratedPositionsInflated),this._sorted=!0),this._array},r.MappingList=o},{"./util":57}],53:[function(e,t,r){function n(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function o(e,t){return Math.round(e+Math.random()*(t-e))}function a(e,t,r,i){if(i>r){var s=o(r,i),u=r-1;n(e,s,i);for(var l=e[i],c=r;i>c;c++)t(e[c],l)<=0&&(u+=1,n(e,u,c));n(e,u+1,c);var p=u+1;a(e,t,r,p-1),a(e,t,p+1,i)}}r.quickSort=function(e,t){a(e,t,0,e.length-1)}},{}],54:[function(e,t,r){function n(e){var t=e;return"string"==typeof e&&(t=JSON.parse(e.replace(/^\)\]\}'/,""))),null!=t.sections?new i(t):new o(t)}function o(e){var t=e;"string"==typeof e&&(t=JSON.parse(e.replace(/^\)\]\}'/,"")));var r=s.getArg(t,"version"),n=s.getArg(t,"sources"),o=s.getArg(t,"names",[]),a=s.getArg(t,"sourceRoot",null),i=s.getArg(t,"sourcesContent",null),u=s.getArg(t,"mappings"),c=s.getArg(t,"file",null);if(r!=this._version)throw new Error("Unsupported version: "+r);n=n.map(s.normalize).map(function(e){return a&&s.isAbsolute(a)&&s.isAbsolute(e)?s.relative(a,e):e}),this._names=l.fromArray(o,!0),this._sources=l.fromArray(n,!0),this.sourceRoot=a,this.sourcesContent=i,this._mappings=u,this.file=c}function a(){this.generatedLine=0,this.generatedColumn=0,this.source=null,this.originalLine=null,this.originalColumn=null,this.name=null}function i(e){var t=e;"string"==typeof e&&(t=JSON.parse(e.replace(/^\)\]\}'/,"")));var r=s.getArg(t,"version"),o=s.getArg(t,"sections");if(r!=this._version)throw new Error("Unsupported version: "+r);this._sources=new l,this._names=new l;var a={line:-1,column:0};this._sections=o.map(function(e){if(e.url)throw new Error("Support for url field in sections not implemented.");var t=s.getArg(e,"offset"),r=s.getArg(t,"line"),o=s.getArg(t,"column");if(r=0){var a=this._originalMappings[o];if(void 0===e.column)for(var i=a.originalLine;a&&a.originalLine===i;)n.push({line:s.getArg(a,"generatedLine",null),column:s.getArg(a,"generatedColumn",null),lastColumn:s.getArg(a,"lastGeneratedColumn",null)}),a=this._originalMappings[++o];else for(var l=a.originalColumn;a&&a.originalLine===t&&a.originalColumn==l;)n.push({line:s.getArg(a,"generatedLine",null),column:s.getArg(a,"generatedColumn",null),lastColumn:s.getArg(a,"lastGeneratedColumn",null)}),a=this._originalMappings[++o]}return n},r.SourceMapConsumer=n,o.prototype=Object.create(n.prototype),o.prototype.consumer=n,o.fromSourceMap=function(e){var t=Object.create(o.prototype),r=t._names=l.fromArray(e._names.toArray(),!0),n=t._sources=l.fromArray(e._sources.toArray(),!0);t.sourceRoot=e._sourceRoot,t.sourcesContent=e._generateSourcesContent(t._sources.toArray(),t.sourceRoot),t.file=e._file;for(var i=e._mappings.toArray().slice(),u=t.__generatedMappings=[],c=t.__originalMappings=[],f=0,h=i.length;h>f;f++){var d=i[f],m=new a;m.generatedLine=d.generatedLine,m.generatedColumn=d.generatedColumn,d.source&&(m.source=n.indexOf(d.source),m.originalLine=d.originalLine,m.originalColumn=d.originalColumn,d.name&&(m.name=r.indexOf(d.name)),c.push(m)),u.push(m)}return p(t.__originalMappings,s.compareByOriginalPositions),t},o.prototype._version=3,Object.defineProperty(o.prototype,"sources",{get:function(){return this._sources.toArray().map(function(e){return null!=this.sourceRoot?s.join(this.sourceRoot,e):e},this)}}),o.prototype._parseMappings=function(e,t){for(var r,n,o,i,u,l=1,f=0,h=0,d=0,m=0,g=0,y=e.length,v=0,b={},k={},w=[],S=[];y>v;)if(";"===e.charAt(v))l++,v++,f=0;else if(","===e.charAt(v))v++;else{for(r=new a,r.generatedLine=l,i=v;y>i&&!this._charIsMappingSeparator(e,i);i++);if(n=e.slice(v,i),o=b[n])v+=n.length;else{for(o=[];i>v;)c.decode(e,v,k),u=k.value,v=k.rest,o.push(u);if(2===o.length)throw new Error("Found a source, but no line and column");if(3===o.length)throw new Error("Found a source and line, but no column");b[n]=o}r.generatedColumn=f+o[0],f=r.generatedColumn,o.length>1&&(r.source=m+o[1],m+=o[1],r.originalLine=h+o[2],h=r.originalLine,r.originalLine+=1,r.originalColumn=d+o[3],d=r.originalColumn,o.length>4&&(r.name=g+o[4],g+=o[4])),S.push(r),"number"==typeof r.originalLine&&w.push(r)}p(S,s.compareByGeneratedPositionsDeflated),this.__generatedMappings=S,p(w,s.compareByOriginalPositions),this.__originalMappings=w},o.prototype._findMapping=function(e,t,r,n,o,a){if(e[r]<=0)throw new TypeError("Line must be greater than or equal to 1, got "+e[r]);if(e[n]<0)throw new TypeError("Column must be greater than or equal to 0, got "+e[n]);return u.search(e,t,o,a)},o.prototype.computeColumnSpans=function(){for(var e=0;e=0){var o=this._generatedMappings[r];if(o.generatedLine===t.generatedLine){var a=s.getArg(o,"source",null);null!==a&&(a=this._sources.at(a),null!=this.sourceRoot&&(a=s.join(this.sourceRoot,a)));var i=s.getArg(o,"name",null);return null!==i&&(i=this._names.at(i)),{source:a,line:s.getArg(o,"originalLine",null),column:s.getArg(o,"originalColumn",null),name:i}}}return{source:null,line:null,column:null,name:null}},o.prototype.hasContentsOfAllSources=function(){return this.sourcesContent?this.sourcesContent.length>=this._sources.size()&&!this.sourcesContent.some(function(e){return null==e}):!1},o.prototype.sourceContentFor=function(e,t){if(!this.sourcesContent)return null;if(null!=this.sourceRoot&&(e=s.relative(this.sourceRoot,e)),this._sources.has(e))return this.sourcesContent[this._sources.indexOf(e)];var r;if(null!=this.sourceRoot&&(r=s.urlParse(this.sourceRoot))){var n=e.replace(/^file:\/\//,"");if("file"==r.scheme&&this._sources.has(n))return this.sourcesContent[this._sources.indexOf(n)];if((!r.path||"/"==r.path)&&this._sources.has("/"+e))return this.sourcesContent[this._sources.indexOf("/"+e)]}if(t)return null;throw new Error('"'+e+'" is not in the SourceMap.')},o.prototype.generatedPositionFor=function(e){var t=s.getArg(e,"source");if(null!=this.sourceRoot&&(t=s.relative(this.sourceRoot,t)),!this._sources.has(t))return{line:null,column:null,lastColumn:null};t=this._sources.indexOf(t);var r={source:t,originalLine:s.getArg(e,"line"),originalColumn:s.getArg(e,"column")},o=this._findMapping(r,this._originalMappings,"originalLine","originalColumn",s.compareByOriginalPositions,s.getArg(e,"bias",n.GREATEST_LOWER_BOUND));if(o>=0){var a=this._originalMappings[o];if(a.source===r.source)return{line:s.getArg(a,"generatedLine",null),column:s.getArg(a,"generatedColumn",null),lastColumn:s.getArg(a,"lastGeneratedColumn",null)}}return{line:null,column:null,lastColumn:null}},r.BasicSourceMapConsumer=o,i.prototype=Object.create(n.prototype),i.prototype.constructor=n,i.prototype._version=3,Object.defineProperty(i.prototype,"sources",{get:function(){for(var e=[],t=0;t0&&e.column>=0)||t||r||n)&&!(e&&"line"in e&&"column"in e&&t&&"line"in t&&"column"in t&&e.line>0&&e.column>=0&&t.line>0&&t.column>=0&&r))throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:r,original:t,name:n}))},n.prototype._serializeMappings=function(){for(var e,t,r,n=0,i=1,s=0,u=0,l=0,c=0,p="",f=this._mappings.toArray(),h=0,d=f.length;d>h;h++){if(e=f[h],e.generatedLine!==i)for(n=0;e.generatedLine!==i;)p+=";",i++;else if(h>0){if(!a.compareByGeneratedPositionsInflated(e,f[h-1]))continue;p+=","}p+=o.encode(e.generatedColumn-n),n=e.generatedColumn,null!=e.source&&(r=this._sources.indexOf(e.source),p+=o.encode(r-c),c=r,p+=o.encode(e.originalLine-1-u),u=e.originalLine-1,p+=o.encode(e.originalColumn-s),s=e.originalColumn,null!=e.name&&(t=this._names.indexOf(e.name),p+=o.encode(t-l),l=t))}return p},n.prototype._generateSourcesContent=function(e,t){return e.map(function(e){if(!this._sourcesContents)return null;null!=t&&(e=a.relative(t,e));var r=a.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,r)?this._sourcesContents[r]:null},this)},n.prototype.toJSON=function(){var e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(e.file=this._file),null!=this._sourceRoot&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e},n.prototype.toString=function(){return JSON.stringify(this.toJSON())},r.SourceMapGenerator=n},{"./array-set":48,"./base64-vlq":49,"./mapping-list":52,"./util":57}],56:[function(e,t,r){function n(e,t,r,n,o){this.children=[],this.sourceContents={},this.line=null==e?null:e,this.column=null==t?null:t,this.source=null==r?null:r,this.name=null==o?null:o,this[u]=!0,null!=n&&this.add(n)}var o=e("./source-map-generator").SourceMapGenerator,a=e("./util"),i=/(\r?\n)/,s=10,u="$$$isSourceNode$$$";n.fromStringWithSourceMap=function(e,t,r){function o(e,t){if(null===e||void 0===e.source)s.add(t);else{var o=r?a.join(r,e.source):e.source;s.add(new n(e.originalLine,e.originalColumn,o,t,e.name))}}var s=new n,u=e.split(i),l=function(){var e=u.shift(),t=u.shift()||"";return e+t},c=1,p=0,f=null;return t.eachMapping(function(e){if(null!==f){if(!(c0&&(f&&o(f,l()),s.add(u.join(""))),t.sources.forEach(function(e){var n=t.sourceContentFor(e);null!=n&&(null!=r&&(e=a.join(r,e)),s.setSourceContent(e,n))}),s},n.prototype.add=function(e){if(Array.isArray(e))e.forEach(function(e){this.add(e)},this);else{if(!e[u]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);e&&this.children.push(e)}return this},n.prototype.prepend=function(e){if(Array.isArray(e))for(var t=e.length-1;t>=0;t--)this.prepend(e[t]);else{if(!e[u]&&"string"!=typeof e)throw new TypeError("Expected a SourceNode, string, or an array of SourceNodes and strings. Got "+e);this.children.unshift(e)}return this},n.prototype.walk=function(e){for(var t,r=0,n=this.children.length;n>r;r++)t=this.children[r],t[u]?t.walk(e):""!==t&&e(t,{source:this.source,line:this.line,column:this.column,name:this.name})},n.prototype.join=function(e){var t,r,n=this.children.length;if(n>0){for(t=[],r=0;n-1>r;r++)t.push(this.children[r]),t.push(e);t.push(this.children[r]),this.children=t}return this},n.prototype.replaceRight=function(e,t){var r=this.children[this.children.length-1];return r[u]?r.replaceRight(e,t):"string"==typeof r?this.children[this.children.length-1]=r.replace(e,t):this.children.push("".replace(e,t)),this},n.prototype.setSourceContent=function(e,t){this.sourceContents[a.toSetString(e)]=t},n.prototype.walkSourceContents=function(e){for(var t=0,r=this.children.length;r>t;t++)this.children[t][u]&&this.children[t].walkSourceContents(e);for(var n=Object.keys(this.sourceContents),t=0,r=n.length;r>t;t++)e(a.fromSetString(n[t]),this.sourceContents[n[t]])},n.prototype.toString=function(){var e="";return this.walk(function(t){e+=t}),e},n.prototype.toStringWithSourceMap=function(e){var t={code:"",line:1,column:0},r=new o(e),n=!1,a=null,i=null,u=null,l=null;return this.walk(function(e,o){t.code+=e,null!==o.source&&null!==o.line&&null!==o.column?((a!==o.source||i!==o.line||u!==o.column||l!==o.name)&&r.addMapping({source:o.source,original:{line:o.line,column:o.column},generated:{line:t.line,column:t.column},name:o.name}),a=o.source,i=o.line,u=o.column,l=o.name,n=!0):n&&(r.addMapping({ generated:{line:t.line,column:t.column}}),a=null,n=!1);for(var c=0,p=e.length;p>c;c++)e.charCodeAt(c)===s?(t.line++,t.column=0,c+1===p?(a=null,n=!1):n&&r.addMapping({source:o.source,original:{line:o.line,column:o.column},generated:{line:t.line,column:t.column},name:o.name})):t.column++}),this.walkSourceContents(function(e,t){r.setSourceContent(e,t)}),{code:t.code,map:r}},r.SourceNode=n},{"./source-map-generator":55,"./util":57}],57:[function(e,t,r){function n(e,t,r){if(t in e)return e[t];if(3===arguments.length)return r;throw new Error('"'+t+'" is a required argument.')}function o(e){var t=e.match(m);return t?{scheme:t[1],auth:t[2],host:t[3],port:t[4],path:t[5]}:null}function a(e){var t="";return e.scheme&&(t+=e.scheme+":"),t+="//",e.auth&&(t+=e.auth+"@"),e.host&&(t+=e.host),e.port&&(t+=":"+e.port),e.path&&(t+=e.path),t}function i(e){var t=e,n=o(e);if(n){if(!n.path)return e;t=n.path}for(var i,s=r.isAbsolute(t),u=t.split(/\/+/),l=0,c=u.length-1;c>=0;c--)i=u[c],"."===i?u.splice(c,1):".."===i?l++:l>0&&(""===i?(u.splice(c+1,l),l=0):(u.splice(c,2),l--));return t=u.join("/"),""===t&&(t=s?"/":"."),n?(n.path=t,a(n)):t}function s(e,t){""===e&&(e="."),""===t&&(t=".");var r=o(t),n=o(e);if(n&&(e=n.path||"/"),r&&!r.scheme)return n&&(r.scheme=n.scheme),a(r);if(r||t.match(g))return t;if(n&&!n.host&&!n.path)return n.host=t,a(n);var s="/"===t.charAt(0)?t:i(e.replace(/\/+$/,"")+"/"+t);return n?(n.path=s,a(n)):s}function u(e,t){""===e&&(e="."),e=e.replace(/\/$/,"");for(var r=0;0!==t.indexOf(e+"/");){var n=e.lastIndexOf("/");if(0>n)return t;if(e=e.slice(0,n),e.match(/^([^\/]+:\/)?\/*$/))return t;++r}return Array(r+1).join("../")+t.substr(e.length+1)}function l(e){return"$"+e}function c(e){return e.substr(1)}function p(e,t,r){var n=e.source-t.source;return 0!==n?n:(n=e.originalLine-t.originalLine,0!==n?n:(n=e.originalColumn-t.originalColumn,0!==n||r?n:(n=e.generatedColumn-t.generatedColumn,0!==n?n:(n=e.generatedLine-t.generatedLine,0!==n?n:e.name-t.name))))}function f(e,t,r){var n=e.generatedLine-t.generatedLine;return 0!==n?n:(n=e.generatedColumn-t.generatedColumn,0!==n||r?n:(n=e.source-t.source,0!==n?n:(n=e.originalLine-t.originalLine,0!==n?n:(n=e.originalColumn-t.originalColumn,0!==n?n:e.name-t.name))))}function h(e,t){return e===t?0:e>t?1:-1}function d(e,t){var r=e.generatedLine-t.generatedLine;return 0!==r?r:(r=e.generatedColumn-t.generatedColumn,0!==r?r:(r=h(e.source,t.source),0!==r?r:(r=e.originalLine-t.originalLine,0!==r?r:(r=e.originalColumn-t.originalColumn,0!==r?r:h(e.name,t.name)))))}r.getArg=n;var m=/^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/,g=/^data:.+\,.+$/;r.urlParse=o,r.urlGenerate=a,r.normalize=i,r.join=s,r.isAbsolute=function(e){return"/"===e.charAt(0)||!!e.match(m)},r.relative=u,r.toSetString=l,r.fromSetString=c,r.compareByOriginalPositions=p,r.compareByGeneratedPositionsDeflated=f,r.compareByGeneratedPositionsInflated=d},{}],58:[function(e,t,r){r.SourceMapGenerator=e("./lib/source-map-generator").SourceMapGenerator,r.SourceMapConsumer=e("./lib/source-map-consumer").SourceMapConsumer,r.SourceNode=e("./lib/source-node").SourceNode},{"./lib/source-map-consumer":54,"./lib/source-map-generator":55,"./lib/source-node":56}],59:[function(e,t,r){t.exports={name:"csso",version:"1.7.0",description:"CSSO (CSS Optimizer) is a CSS minifier with structural optimisations",keywords:["css","minifier","minify","compress","optimisation"],homepage:"https://github.com/css/csso",author:"Sergey Kryzhanovsky (https://github.com/afelix)",maintainers:[{name:"Roman Dvornov",email:"rdvornov@gmail.com","github-username":"lahmatiy"}],license:"MIT",repository:"css/csso",bugs:{url:"https://github.com/css/csso/issues"},bin:{csso:"./bin/csso"},main:"./lib/index",eslintConfig:{env:{node:!0,mocha:!0,es6:!0},rules:{"no-undef":2,"no-unused-vars":[2,{vars:"all",args:"after-used"}]}},scripts:{test:"jscs lib && eslint lib test && mocha --reporter dot",hydrogen:"node --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces --redirect-code-traces-to=code.asm --trace_hydrogen_file=code.cfg --print-opt-code bin/csso --stat -o /dev/null",coverage:"istanbul cover _mocha -- -R dot",coveralls:"istanbul cover _mocha --report lcovonly -- -R dot && cat ./coverage/lcov.info | coveralls",travis:"npm run test && npm run coveralls",browserify:"browserify --standalone csso lib/index.js | uglifyjs --compress --mangle -o dist/csso-browser.js","gh-pages":'git clone -b gh-pages https://github.com/css/csso.git .gh-pages && npm run browserify && cp dist/csso-browser.js .gh-pages/ && cd .gh-pages && git commit -am "update" && git push && cd .. && rm -rf .gh-pages',prepublish:"npm run browserify"},dependencies:{clap:"^1.0.9","source-map":"^0.5.3"},devDependencies:{browserify:"^13.0.0",coveralls:"^2.11.6",eslint:"^2.2.0",istanbul:"^0.4.2",jscs:"~2.10.0",mocha:"~2.4.2","uglify-js":"^2.6.1"},engines:{node:">=0.10.0"},files:["bin","dist/csso-browser.js","lib","HISTORY.md","LICENSE","README.md"]}},{}]},{},[39])(39)}); -do_compression = function(css, disable_structural){ +do_compression = function(css, structural){ return csso.minify(css, { - restructure: !disable_structural + restructure: structural }); }; +do_compression_with_map = function(css, filename, structural){ + var result = csso.minify(css, { + restructure: structural, + filename: filename, + sourceMap: true + }); + return [result.css, result.map.toString()]; +};