diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:10:59 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:41:44 +0800 |
| commit | fc87c009806dcc98867f6b58efe29b042aa01dee (patch) | |
| tree | 8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/svgo/plugins/sortDefsChildren.js | |
| parent | 3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff) | |
node: updatemain
Diffstat (limited to 'node_modules/svgo/plugins/sortDefsChildren.js')
| -rw-r--r-- | node_modules/svgo/plugins/sortDefsChildren.js | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/node_modules/svgo/plugins/sortDefsChildren.js b/node_modules/svgo/plugins/sortDefsChildren.js deleted file mode 100644 index 6ae5d421..00000000 --- a/node_modules/svgo/plugins/sortDefsChildren.js +++ /dev/null @@ -1,58 +0,0 @@ -'use strict'; - -exports.name = 'sortDefsChildren'; -exports.description = 'Sorts children of <defs> to improve compression'; - -/** - * Sorts children of defs in order to improve compression. - * Sorted first by frequency then by element name length then by element name (to ensure grouping). - * - * @author David Leston - * - * @type {import('./plugins-types').Plugin<'sortDefsChildren'>} - */ -exports.fn = () => { - return { - element: { - enter: (node) => { - if (node.name === 'defs') { - /** - * @type {Map<string, number>} - */ - const frequencies = new Map(); - for (const child of node.children) { - if (child.type === 'element') { - const frequency = frequencies.get(child.name); - if (frequency == null) { - frequencies.set(child.name, 1); - } else { - frequencies.set(child.name, frequency + 1); - } - } - } - node.children.sort((a, b) => { - if (a.type !== 'element' || b.type !== 'element') { - return 0; - } - const aFrequency = frequencies.get(a.name); - const bFrequency = frequencies.get(b.name); - if (aFrequency != null && bFrequency != null) { - const frequencyComparison = bFrequency - aFrequency; - if (frequencyComparison !== 0) { - return frequencyComparison; - } - } - const lengthComparison = b.name.length - a.name.length; - if (lengthComparison !== 0) { - return lengthComparison; - } - if (a.name !== b.name) { - return a.name > b.name ? -1 : 1; - } - return 0; - }); - } - }, - }, - }; -}; |
