mirror of
https://github.com/svg/svgo.git
synced 2025-07-29 20:21:14 +03:00
Convert element children to xast
Ref https://github.com/syntax-tree/xast Renamed content to children to match xast spec.
This commit is contained in:
@ -17,28 +17,25 @@ exports.description = 'Sorts children of <defs> to improve compression';
|
||||
*/
|
||||
exports.fn = function (item) {
|
||||
if (item.isElem('defs')) {
|
||||
if (item.content) {
|
||||
var frequency = item.content.reduce(function (frequency, child) {
|
||||
if (child.name in frequency) {
|
||||
frequency[child.name]++;
|
||||
} else {
|
||||
frequency[child.name] = 1;
|
||||
}
|
||||
return frequency;
|
||||
}, {});
|
||||
item.content.sort(function (a, b) {
|
||||
var frequencyComparison = frequency[b.name] - frequency[a.name];
|
||||
if (frequencyComparison !== 0) {
|
||||
return frequencyComparison;
|
||||
}
|
||||
var lengthComparison = b.name.length - a.name.length;
|
||||
if (lengthComparison !== 0) {
|
||||
return lengthComparison;
|
||||
}
|
||||
return a.name != b.name ? (a.name > b.name ? -1 : 1) : 0;
|
||||
});
|
||||
}
|
||||
|
||||
var frequency = item.children.reduce(function (frequency, child) {
|
||||
if (child.name in frequency) {
|
||||
frequency[child.name]++;
|
||||
} else {
|
||||
frequency[child.name] = 1;
|
||||
}
|
||||
return frequency;
|
||||
}, {});
|
||||
item.children.sort(function (a, b) {
|
||||
var frequencyComparison = frequency[b.name] - frequency[a.name];
|
||||
if (frequencyComparison !== 0) {
|
||||
return frequencyComparison;
|
||||
}
|
||||
var lengthComparison = b.name.length - a.name.length;
|
||||
if (lengthComparison !== 0) {
|
||||
return lengthComparison;
|
||||
}
|
||||
return a.name != b.name ? (a.name > b.name ? -1 : 1) : 0;
|
||||
});
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user