mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
bump csso to 1.8.0 and use minifyBlock for style attribute content compression
This commit is contained in:
@ -53,7 +53,7 @@
|
|||||||
"colors": "~1.1.2",
|
"colors": "~1.1.2",
|
||||||
"whet.extend": "~0.9.9",
|
"whet.extend": "~0.9.9",
|
||||||
"mkdirp": "~0.5.1",
|
"mkdirp": "~0.5.1",
|
||||||
"csso": "~1.6.4"
|
"csso": "~1.8.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "~2.4.5",
|
"mocha": "~2.4.5",
|
||||||
|
@ -12,25 +12,6 @@ exports.description = 'minifies existing styles in svg';
|
|||||||
|
|
||||||
var csso = require('csso');
|
var csso = require('csso');
|
||||||
|
|
||||||
|
|
||||||
// wraps css rules into a selector to make it parseable
|
|
||||||
var rulesToDummySelector = function(str) {
|
|
||||||
return '.dummy { ' + str + ' }';
|
|
||||||
};
|
|
||||||
|
|
||||||
// helper to extract css rules from full css selector
|
|
||||||
var extractRuleCss = function(str) {
|
|
||||||
var strEx = str.match(/\.dummy{(.*)}/i)[1];
|
|
||||||
return strEx;
|
|
||||||
};
|
|
||||||
|
|
||||||
// minifies css using csso
|
|
||||||
var minifyCss = function(css, options) {
|
|
||||||
return csso.minify(css, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minifies styles (<style> element + style attribute) using svgo
|
* Minifies styles (<style> element + style attribute) using svgo
|
||||||
*
|
*
|
||||||
@ -46,7 +27,7 @@ exports.fn = function(item, svgoOptions) {
|
|||||||
var styleCss = item.content[0].text || item.content[0].cdata || [],
|
var styleCss = item.content[0].text || item.content[0].cdata || [],
|
||||||
DATA = styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0 ? 'cdata' : 'text';
|
DATA = styleCss.indexOf('>') >= 0 || styleCss.indexOf('<') >= 0 ? 'cdata' : 'text';
|
||||||
if(styleCss.length > 0) {
|
if(styleCss.length > 0) {
|
||||||
var styleCssMinified = minifyCss(styleCss, svgoOptions);
|
var styleCssMinified = csso.minify(styleCss, svgoOptions);
|
||||||
item.content[0][DATA] = styleCssMinified;
|
item.content[0][DATA] = styleCssMinified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,15 +35,7 @@ exports.fn = function(item, svgoOptions) {
|
|||||||
if(item.hasAttr('style')) {
|
if(item.hasAttr('style')) {
|
||||||
var itemCss = item.attr('style').value;
|
var itemCss = item.attr('style').value;
|
||||||
if(itemCss.length > 0) {
|
if(itemCss.length > 0) {
|
||||||
var itemCssMinified =
|
var itemCssMinified = csso.minifyBlock(itemCss, svgoOptions);
|
||||||
extractRuleCss(
|
|
||||||
minifyCss(
|
|
||||||
rulesToDummySelector(
|
|
||||||
itemCss
|
|
||||||
),
|
|
||||||
svgoOptions
|
|
||||||
)
|
|
||||||
);
|
|
||||||
item.attr('style').value = itemCssMinified;
|
item.attr('style').value = itemCssMinified;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user