Improve cleanupEnableBackground plugin.
@ -1,12 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.type = 'perItem';
|
exports.type = 'full';
|
||||||
|
|
||||||
exports.active = true;
|
exports.active = true;
|
||||||
|
|
||||||
var regEnableBackground = /^new\s0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)$/,
|
|
||||||
elems = ['svg', 'mask', 'pattern'];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove or cleanup enable-background attr which coincides with a width/height box.
|
* Remove or cleanup enable-background attr which coincides with a width/height box.
|
||||||
*
|
*
|
||||||
@ -22,30 +19,64 @@ var regEnableBackground = /^new\s0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]
|
|||||||
*
|
*
|
||||||
* @author Kir Belevich
|
* @author Kir Belevich
|
||||||
*/
|
*/
|
||||||
exports.fn = function(item) {
|
exports.fn = function(data) {
|
||||||
|
|
||||||
if (
|
var regEnableBackground = /^new\s0\s0\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)\s([\-+]?\d*\.?\d+([eE][\-+]?\d+)?)$/,
|
||||||
item.isElem(elems) &&
|
hasFilter = false,
|
||||||
item.hasAttr('enable-background') &&
|
elems = ['svg', 'mask', 'pattern'];
|
||||||
item.hasAttr('width') &&
|
|
||||||
item.hasAttr('height')
|
|
||||||
) {
|
|
||||||
|
|
||||||
var match = item.attr('enable-background').value.match(regEnableBackground);
|
function checkEnableBackground(item) {
|
||||||
|
if (
|
||||||
|
item.isElem(elems) &&
|
||||||
|
item.hasAttr('enable-background') &&
|
||||||
|
item.hasAttr('width') &&
|
||||||
|
item.hasAttr('height')
|
||||||
|
) {
|
||||||
|
|
||||||
if (match) {
|
var match = item.attr('enable-background').value.match(regEnableBackground);
|
||||||
if (
|
|
||||||
item.attr('width').value === match[1] &&
|
if (match) {
|
||||||
item.attr('height').value === match[3]
|
if (
|
||||||
) {
|
item.attr('width').value === match[1] &&
|
||||||
if (item.isElem('svg')) {
|
item.attr('height').value === match[3]
|
||||||
item.removeAttr('enable-background');
|
) {
|
||||||
} else {
|
if (item.isElem('svg')) {
|
||||||
item.attr('enable-background').value = 'new';
|
item.removeAttr('enable-background');
|
||||||
|
} else {
|
||||||
|
item.attr('enable-background').value = 'new';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkForFilter(item) {
|
||||||
|
if (item.isElem('filter')) {
|
||||||
|
hasFilter = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function monkeys(items, fn) {
|
||||||
|
items.content.forEach(function(item) {
|
||||||
|
fn(item);
|
||||||
|
|
||||||
|
if (item.content) {
|
||||||
|
monkeys(item, fn);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
var firstStep = monkeys(data, function(item) {
|
||||||
|
checkEnableBackground(item);
|
||||||
|
if (!hasFilter) {
|
||||||
|
checkForFilter(item);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return hasFilter ? firstStep : monkeys(firstStep, function(item) {
|
||||||
|
//we don't need 'enable-background' if we have no filters
|
||||||
|
item.removeAttr('enable-background');
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5" enable-background="new 0 0 100.5 .5">
|
<svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5" enable-background="new 0 0 100.5 .5">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
test
|
test
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
@@@
|
@@@
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5">
|
<svg xmlns="http://www.w3.org/2000/svg" width="100.5" height=".5">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
test
|
test
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 209 B After Width: | Height: | Size: 443 B |
@ -1,9 +1,19 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50">
|
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
test
|
test
|
||||||
</svg>
|
</svg>
|
||||||
|
|
||||||
@@@
|
@@@
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50">
|
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" enable-background="new 0 0 100 50">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
test
|
test
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 470 B |
@ -1,4 +1,9 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
<mask width="100" height="50" enable-background="new 0 0 100 50">
|
<mask width="100" height="50" enable-background="new 0 0 100 50">
|
||||||
test
|
test
|
||||||
</mask>
|
</mask>
|
||||||
@ -7,6 +12,11 @@
|
|||||||
@@@
|
@@@
|
||||||
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg">
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<defs>
|
||||||
|
<filter id="ShiftBGAndBlur">
|
||||||
|
<feOffset dx="0" dy="75"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
<mask width="100" height="50" enable-background="new">
|
<mask width="100" height="50" enable-background="new">
|
||||||
test
|
test
|
||||||
</mask>
|
</mask>
|
||||||
|
Before Width: | Height: | Size: 281 B After Width: | Height: | Size: 515 B |
13
test/plugins/cleanupEnableBackground.04.svg
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<mask width="100" height="50" enable-background="new 0 0 100 50">
|
||||||
|
test
|
||||||
|
</mask>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
@@@
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<mask width="100" height="50">
|
||||||
|
test
|
||||||
|
</mask>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 257 B |