Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import type {
SvgNode,
SvgPlugin,
SvgPluginOptions,
} from "../../types/common.js";
export const collapseGroups: SvgPlugin = {
name: "collapseGroups",
apply(node: SvgNode, _options: SvgPluginOptions): SvgNode | null {
if (node.type !== "element" || node.name !== "g") return node;
const children = node.children ?? [];
if (children.length !== 1) return node;
const child = children[0]!;
if (child.type !== "element") return node;
const groupAttrs = node.attributes ?? {};
// Never collapse if group has an id (may be referenced)
if ("id" in groupAttrs) return node;
const childAttrs = child.attributes ?? {};
// Check for conflicting attributes
for (const key of Object.keys(groupAttrs)) {
if (key in childAttrs) return node;
}
// Merge group attrs onto child
return {
...child,
attributes: { ...groupAttrs, ...childAttrs },
};
},
};