Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
41
node_modules/svgo/plugins/removeEmptyContainers.js
generated
vendored
41
node_modules/svgo/plugins/removeEmptyContainers.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
import { elemsGroups } from './_collections.js';
|
||||
import { detachNodeFromParent } from '../lib/xast.js';
|
||||
import { collectStylesheet, computeStyle } from '../lib/style.js';
|
||||
import { findReferences } from '../lib/svgo/tools.js';
|
||||
|
||||
export const name = 'removeEmptyContainers';
|
||||
export const description = 'removes empty container elements';
|
||||
@@ -22,9 +23,33 @@ export const description = 'removes empty container elements';
|
||||
*/
|
||||
export const fn = (root) => {
|
||||
const stylesheet = collectStylesheet(root);
|
||||
const removedIds = new Set();
|
||||
/**
|
||||
* @type {Map<string, {
|
||||
* node: import('../lib/types.js').XastElement,
|
||||
* parent: import('../lib/types.js').XastParent,
|
||||
* }[]>}
|
||||
*/
|
||||
const usesById = new Map();
|
||||
|
||||
return {
|
||||
element: {
|
||||
enter: (node, parentNode) => {
|
||||
if (node.name === 'use') {
|
||||
// Record uses so those referencing empty containers can be removed.
|
||||
for (const [name, value] of Object.entries(node.attributes)) {
|
||||
const ids = findReferences(name, value);
|
||||
for (const id of ids) {
|
||||
let references = usesById.get(id);
|
||||
if (references === undefined) {
|
||||
references = [];
|
||||
usesById.set(id, references);
|
||||
}
|
||||
references.push({ node: node, parent: parentNode });
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
exit: (node, parentNode) => {
|
||||
// remove only empty non-svg containers
|
||||
if (
|
||||
@@ -61,6 +86,22 @@ export const fn = (root) => {
|
||||
}
|
||||
|
||||
detachNodeFromParent(node, parentNode);
|
||||
if (node.attributes.id) {
|
||||
removedIds.add(node.attributes.id);
|
||||
}
|
||||
},
|
||||
},
|
||||
root: {
|
||||
exit: () => {
|
||||
// Remove any <use> elements that referenced an empty container.
|
||||
for (const id of removedIds) {
|
||||
const uses = usesById.get(id);
|
||||
if (uses) {
|
||||
for (const use of uses) {
|
||||
detachNodeFromParent(use.node, use.parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user