Open History to see the last commit
1/* oxlint-disable eslint/no-restricted-imports -- Resolves saved project icons by name, so it needs the whole set. */
2// Project icon overrides save lucide icons by kebab-case name. Import this module
3// lazily: it holds every lucide icon as one chunk, where `lucide-react/dynamic`
4// emits a separate chunk per icon (~1,900), which dominated build output.
5import * as Lucide from "lucide-react";
6import type { LucideIcon } from "lucide-react";
7
8const iconComponents = new Set<unknown>(Object.values(Lucide.icons));
9const lucideExports: Record<string, unknown> = Lucide;
10
11// Lucide derives export names this way, so it also resolves its deprecated
12// aliases ("alarm-check" -> AlarmCheck) that older overrides may have saved.
13function toPascalName(name: string): string {
14 return name
15 .split("-")
16 .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
17 .join("");
18}
19
20// Inverse of toPascalName for canonical exports: "ArrowDown01" -> "arrow-down-01".
21// Lucide spells a handful of digit names differently ("arrow-down-0-1"); both
22// forms resolve to the same icon through toPascalName.
23function toKebabName(pascalName: string): string {
24 return (pascalName.match(/[A-Z][a-z]*|[0-9]+[a-z]*/g) ?? []).join("-").toLowerCase();
25}
26
27export const lucideIconNames: ReadonlyArray<string> = Object.keys(Lucide.icons).map(toKebabName);
28
29export function lucideIconByName(name: string): LucideIcon | undefined {
30 const icon = lucideExports[toPascalName(name)];
31 return iconComponents.has(icon) ? (icon as LucideIcon) : undefined;
32}