mirror of
https://github.com/svg/svgo.git
synced 2025-07-31 07:44:22 +03:00
Refactor basic plugins with visitor api (#1518)
- cleanupAttrs - convertEllipseToCircle - removeDesc - removeDoctype - removeEmptyText - removeMetadata - removeRasterImages - removeScriptElement - removeStyleElement - removeTitle - removeXMLProcInst
This commit is contained in:
@ -1,9 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
exports.type = 'perItem';
|
||||
|
||||
exports.type = 'visitor';
|
||||
exports.active = true;
|
||||
|
||||
exports.description = 'converts non-eccentric <ellipse>s to <circle>s';
|
||||
|
||||
/**
|
||||
@ -11,26 +9,28 @@ exports.description = 'converts non-eccentric <ellipse>s to <circle>s';
|
||||
*
|
||||
* @see https://www.w3.org/TR/SVG11/shapes.html
|
||||
*
|
||||
* @param {Object} item current iteration item
|
||||
* @return {Boolean} if false, item will be filtered out
|
||||
*
|
||||
* @author Taylor Hunt
|
||||
*/
|
||||
exports.fn = function (item) {
|
||||
if (item.isElem('ellipse')) {
|
||||
const rx = item.attributes.rx || 0;
|
||||
const ry = item.attributes.ry || 0;
|
||||
|
||||
if (
|
||||
rx === ry ||
|
||||
rx === 'auto' ||
|
||||
ry === 'auto' // SVG2
|
||||
) {
|
||||
var radius = rx !== 'auto' ? rx : ry;
|
||||
item.renameElem('circle');
|
||||
delete item.attributes.rx;
|
||||
delete item.attributes.ry;
|
||||
item.attributes.r = radius;
|
||||
}
|
||||
}
|
||||
exports.fn = () => {
|
||||
return {
|
||||
element: {
|
||||
enter: (node) => {
|
||||
if (node.name === 'ellipse') {
|
||||
const rx = node.attributes.rx || 0;
|
||||
const ry = node.attributes.ry || 0;
|
||||
if (
|
||||
rx === ry ||
|
||||
rx === 'auto' ||
|
||||
ry === 'auto' // SVG2
|
||||
) {
|
||||
node.name = 'circle';
|
||||
const radius = rx === 'auto' ? ry : rx;
|
||||
delete node.attributes.rx;
|
||||
delete node.attributes.ry;
|
||||
node.attributes.r = radius;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user