mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 19:32:52 +02:00
✨ Changes to svgclean
This commit is contained in:
parent
6e88d3a04c
commit
0f7596bacf
4 changed files with 32 additions and 28 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
vendor/svgclean/main.js
vendored
2
vendor/svgclean/main.js
vendored
|
@ -30,7 +30,7 @@ const plugins = [
|
||||||
{ "removeDimensions" : true },
|
{ "removeDimensions" : true },
|
||||||
{ "removeStyleElement" : true },
|
{ "removeStyleElement" : true },
|
||||||
{ "removeScriptElement" : true },
|
{ "removeScriptElement" : true },
|
||||||
{ "removeOffCanvasPaths" : true },
|
{ "removeOffCanvasPaths" : false },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,8 @@ exports.description = 'moves some group attributes to the content elements';
|
||||||
|
|
||||||
var collections = require('./_collections.js'),
|
var collections = require('./_collections.js'),
|
||||||
pathElems = collections.pathElems.concat(['g', 'text']),
|
pathElems = collections.pathElems.concat(['g', 'text']),
|
||||||
referencesProps = collections.referencesProps;
|
referencesProps = collections.referencesProps,
|
||||||
|
inheritableAttrs = collections.inheritableAttrs;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move group attrs to the content elements.
|
* Move group attrs to the content elements.
|
||||||
|
@ -31,30 +32,33 @@ var collections = require('./_collections.js'),
|
||||||
*/
|
*/
|
||||||
exports.fn = function(item) {
|
exports.fn = function(item) {
|
||||||
|
|
||||||
// move group transform attr to content's pathElems
|
if (item.isElem('g') && !item.isEmpty()) {
|
||||||
if (
|
|
||||||
item.isElem('g') &&
|
inheritableAttrs.forEach(function(currentAttr) {
|
||||||
item.hasAttr('transform') &&
|
|
||||||
!item.isEmpty() &&
|
if (item.hasAttr(currentAttr)) {
|
||||||
!item.someAttr(function(attr) {
|
var attr = item.attr(currentAttr);
|
||||||
return ~referencesProps.indexOf(attr.name) && ~attr.value.indexOf('url(');
|
|
||||||
})
|
item.content.forEach(function(inner) {
|
||||||
) {
|
|
||||||
item.content.forEach(function(inner) {
|
if (currentAttr === 'transform' && inner.hasAttr(currentAttr)) {
|
||||||
var attr = item.attr('transform');
|
// if attr is transform and the inner has transform we concatenate it
|
||||||
if (inner.hasAttr('transform')) {
|
inner.attr(currentAttr).value = attr.value + ' ' + inner.attr(currentAttr).value;
|
||||||
inner.attr('transform').value = attr.value + ' ' + inner.attr('transform').value;
|
} else if (!inner.hasAttr(currentAttr)){
|
||||||
} else {
|
// If the inner has the attr already we don't override it
|
||||||
inner.addAttr({
|
inner.addAttr({
|
||||||
'name': attr.name,
|
...attr
|
||||||
'local': attr.local,
|
});
|
||||||
'prefix': attr.prefix,
|
}
|
||||||
'value': attr.value
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
item.removeAttr(currentAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
item.removeAttr('transform');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue