feat(lucide-static): add icon aliases to the SVG sprite
Aliases were only written as separate SVG files, so `<use href="#home" />` did not work with the sprite. Each alias is now added as a symbol that references the original icon's symbol with a nested `<use>`, instead of duplicating its elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9u8FgapYRzb6uRJnZpW7N
This commit is contained in:
parent
c55aab36b5
commit
1a8a98e80d
2 changed files with 31 additions and 2 deletions
|
|
@ -42,12 +42,13 @@ const aliases = (await Promise.all(
|
|||
return aliases.map(alias => ({
|
||||
...svg,
|
||||
name: typeof alias === 'string' ? alias : alias.name,
|
||||
aliasOf: svgName,
|
||||
}));
|
||||
})
|
||||
)).flat();
|
||||
|
||||
await Promise.all([
|
||||
generateSprite(svgs, PACKAGE_DIR, license),
|
||||
generateSprite(svgs, aliases, PACKAGE_DIR, license),
|
||||
generateIconNodes(svgs, PACKAGE_DIR),
|
||||
copyIcons([...svgs, ...aliases], PACKAGE_DIR, license),
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,14 @@ import { format } from 'prettier';
|
|||
import { appendFile } from '@lucide/helpers';
|
||||
import { type SVGFile } from './readSvgs.mts';
|
||||
|
||||
export type AliasSVGFile = SVGFile & {
|
||||
/** Name of the icon this alias points to. */
|
||||
aliasOf: string;
|
||||
};
|
||||
|
||||
export default async function generateSprite(
|
||||
svgs: SVGFile[],
|
||||
aliases: AliasSVGFile[],
|
||||
packageDir: string,
|
||||
license: string
|
||||
) {
|
||||
|
|
@ -19,6 +25,28 @@ export default async function generateSprite(
|
|||
children: parsedSvg.children,
|
||||
}));
|
||||
|
||||
// Aliases reference the original icon's symbol instead of duplicating its elements.
|
||||
const aliasSymbols = aliases.map<INode>(({ name, aliasOf, parsedSvg }) => ({
|
||||
name: 'symbol',
|
||||
type: 'element',
|
||||
value: '',
|
||||
attributes: {
|
||||
id: name,
|
||||
viewBox: parsedSvg.attributes.viewBox,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'use',
|
||||
type: 'element',
|
||||
value: '',
|
||||
attributes: {
|
||||
href: `#${aliasOf}`,
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
}));
|
||||
|
||||
const spriteSvgObject: INode = {
|
||||
name: 'svg',
|
||||
type: 'element',
|
||||
|
|
@ -31,7 +59,7 @@ export default async function generateSprite(
|
|||
{
|
||||
name: 'defs',
|
||||
type: 'element',
|
||||
children: symbols,
|
||||
children: [...symbols, ...aliasSymbols],
|
||||
value: '',
|
||||
} as INode,
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue