This repository has been archived on 2023-03-25. You can view files and clone it, but cannot push or open issues or pull requests.
mightyscape-1.1-deprecated/extensions/fablabchemnitz/svgo_output/node_modules/svgo/plugins/sortAttrs.js
2021-07-23 02:36:56 +02:00

57 lines
1.0 KiB
JavaScript

'use strict';
exports.type = 'perItem';
exports.active = false;
exports.description = 'sorts element attributes (disabled by default)';
exports.params = {
order: [
'xmlns',
'id',
'width', 'height',
'x', 'x1', 'x2',
'y', 'y1', 'y2',
'cx', 'cy', 'r',
'fill', 'fill-opacity', 'fill-rule',
'stroke', 'stroke-opacity', 'stroke-width', 'stroke-miterlimit', 'stroke-dashoffset',
'd', 'points'
]
};
/**
* Sort element attributes for epic readability.
*
* @param {Object} item current iteration item
* @param {Object} params plugin params
*
* @author Nikolay Frantsev
*/
exports.fn = function(item, params) {
var attrs = [],
sorted = {},
orderlen = params.order.length + 1;
if (item.elem) {
item.eachAttr(function(attr) {
attrs.push(attr);
});
attrs.sort(function(a, b) {
return ((a = params.order.indexOf(a.name)) > -1 ? a : orderlen) -
((b = params.order.indexOf(b.name)) > -1 ? b : orderlen);
});
attrs.forEach(function (attr) {
sorted[attr.name] = attr;
});
item.attrs = sorted;
}
};