@sdeck/icons 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@sdeck/icons`: every Lucide, Lucide Lab and react-icons icon, addressed as
3
+ * `icon:<pack>/<name>` and loaded on demand. Browser-safe; `@sdeck/icons/svg` turns a reference
4
+ * into an SVG image.
5
+ */
6
+ export { type IconComponent, iconNames, kebab, loadIcon } from "./load.ts";
7
+ export { ICON_PACKS, type IconPack } from "./packs.ts";
8
+ export { formatIconRef, type IconRef, isIconRef, parseIconRef } from "./ref.ts";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,KAAK,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,KAAK,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,155 @@
1
+ // src/load.ts
2
+ import { Icon } from "lucide-react";
3
+ import { createElement } from "react";
4
+ var REACT_ICONS = {
5
+ ai: () => import("react-icons/ai"),
6
+ bi: () => import("react-icons/bi"),
7
+ bs: () => import("react-icons/bs"),
8
+ cg: () => import("react-icons/cg"),
9
+ ci: () => import("react-icons/ci"),
10
+ di: () => import("react-icons/di"),
11
+ fa: () => import("react-icons/fa"),
12
+ fa6: () => import("react-icons/fa6"),
13
+ fc: () => import("react-icons/fc"),
14
+ fi: () => import("react-icons/fi"),
15
+ gi: () => import("react-icons/gi"),
16
+ go: () => import("react-icons/go"),
17
+ gr: () => import("react-icons/gr"),
18
+ hi: () => import("react-icons/hi"),
19
+ hi2: () => import("react-icons/hi2"),
20
+ im: () => import("react-icons/im"),
21
+ io: () => import("react-icons/io"),
22
+ io5: () => import("react-icons/io5"),
23
+ lia: () => import("react-icons/lia"),
24
+ lu: () => import("react-icons/lu"),
25
+ md: () => import("react-icons/md"),
26
+ pi: () => import("react-icons/pi"),
27
+ ri: () => import("react-icons/ri"),
28
+ rx: () => import("react-icons/rx"),
29
+ si: () => import("react-icons/si"),
30
+ sl: () => import("react-icons/sl"),
31
+ tb: () => import("react-icons/tb"),
32
+ tfi: () => import("react-icons/tfi"),
33
+ ti: () => import("react-icons/ti"),
34
+ vsc: () => import("react-icons/vsc"),
35
+ wi: () => import("react-icons/wi")
36
+ };
37
+ var lucide;
38
+ var lucideImports = () => {
39
+ lucide ??= import("lucide-react/dynamicIconImports").then((m) => m.default);
40
+ return lucide;
41
+ };
42
+ function kebab(camel) {
43
+ return camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([a-zA-Z])(\d)/g, "$1-$2").toLowerCase();
44
+ }
45
+ var lab;
46
+ var labIcons = () => {
47
+ lab ??= import("@lucide/lab").then((icons) => new Map(Object.entries(icons).filter(([, node]) => Array.isArray(node)).map(([name, node]) => {
48
+ const component = (props) => createElement(Icon, { ...props, iconNode: node });
49
+ return [kebab(name), component];
50
+ })));
51
+ return lab;
52
+ };
53
+ var packs = new Map;
54
+ function reactIcons(pack) {
55
+ if (!Object.hasOwn(REACT_ICONS, pack))
56
+ return;
57
+ let loaded = packs.get(pack);
58
+ if (!loaded) {
59
+ loaded = REACT_ICONS[pack]();
60
+ loaded.catch(() => packs.delete(pack));
61
+ packs.set(pack, loaded);
62
+ }
63
+ return loaded;
64
+ }
65
+ async function iconNames(pack) {
66
+ if (pack === "lucide")
67
+ return Object.keys(await lucideImports()).sort();
68
+ if (pack === "lab")
69
+ return [...(await labIcons()).keys()].sort();
70
+ const module = await reactIcons(pack);
71
+ if (!module)
72
+ return [];
73
+ return Object.keys(module).filter((name) => typeof module[name] === "function").sort();
74
+ }
75
+ async function loadIcon(pack, name) {
76
+ if (pack === "lucide") {
77
+ const imports = await lucideImports();
78
+ return Object.hasOwn(imports, name) ? (await imports[name]?.())?.default : undefined;
79
+ }
80
+ if (pack === "lab")
81
+ return (await labIcons()).get(name);
82
+ const module = await reactIcons(pack);
83
+ if (!module || !Object.hasOwn(module, name))
84
+ return;
85
+ const icon = module[name];
86
+ return typeof icon === "function" ? icon : undefined;
87
+ }
88
+ // src/packs.ts
89
+ var pack = (id, name, license, url) => ({
90
+ id,
91
+ name,
92
+ license,
93
+ url
94
+ });
95
+ var ICON_PACKS = [
96
+ pack("lucide", "Lucide", "ISC", "https://lucide.dev/icons"),
97
+ pack("lab", "Lucide Lab", "ISC", "https://lucide.dev/lab"),
98
+ pack("ai", "Ant Design", "MIT", "https://github.com/ant-design/ant-design-icons"),
99
+ pack("bi", "BoxIcons", "MIT", "https://github.com/atisawd/boxicons"),
100
+ pack("bs", "Bootstrap", "MIT", "https://github.com/twbs/icons"),
101
+ pack("cg", "css.gg", "MIT", "https://github.com/astrit/css.gg"),
102
+ pack("ci", "Circum", "MPL-2.0", "https://circumicons.com/"),
103
+ pack("di", "Devicons", "MIT", "https://vorillaz.github.io/devicons/"),
104
+ pack("fa", "Font Awesome 5", "CC BY 4.0", "https://fontawesome.com/"),
105
+ pack("fa6", "Font Awesome 6", "CC BY 4.0", "https://fontawesome.com/"),
106
+ pack("fc", "Flat Color", "MIT", "https://github.com/icons8/flat-color-icons"),
107
+ pack("fi", "Feather", "MIT", "https://feathericons.com/"),
108
+ pack("gi", "Game Icons", "CC BY 3.0", "https://game-icons.net/"),
109
+ pack("go", "Octicons", "MIT", "https://primer.style/octicons/"),
110
+ pack("gr", "Grommet", "Apache-2.0", "https://github.com/grommet/grommet-icons"),
111
+ pack("hi", "Heroicons", "MIT", "https://github.com/tailwindlabs/heroicons"),
112
+ pack("hi2", "Heroicons 2", "MIT", "https://github.com/tailwindlabs/heroicons"),
113
+ pack("im", "IcoMoon Free", "CC BY 4.0", "https://github.com/Keyamoon/IcoMoon-Free"),
114
+ pack("io", "Ionicons 4", "MIT", "https://ionicons.com/"),
115
+ pack("io5", "Ionicons 5", "MIT", "https://ionicons.com/"),
116
+ pack("lia", "Line Awesome", "MIT", "https://icons8.com/line-awesome"),
117
+ pack("lu", "Lucide (react-icons)", "ISC", "https://lucide.dev/"),
118
+ pack("md", "Material Design", "Apache-2.0", "https://google.github.io/material-design-icons/"),
119
+ pack("pi", "Phosphor", "MIT", "https://github.com/phosphor-icons/core"),
120
+ pack("ri", "Remix Icon", "Apache-2.0", "https://github.com/Remix-Design/RemixIcon"),
121
+ pack("rx", "Radix", "MIT", "https://icons.radix-ui.com/"),
122
+ pack("si", "Simple Icons (brands)", "CC0 1.0", "https://simpleicons.org/"),
123
+ pack("sl", "Simple Line", "MIT", "https://github.com/thesabbir/simple-line-icons"),
124
+ pack("tb", "Tabler", "MIT", "https://github.com/tabler/tabler-icons"),
125
+ pack("tfi", "Themify", "MIT", "https://github.com/lykmapipo/themify-icons"),
126
+ pack("ti", "Typicons", "CC BY-SA 3.0", "https://github.com/stephenhutchings/typicons.font"),
127
+ pack("vsc", "VS Code", "CC BY 4.0", "https://github.com/microsoft/vscode-codicons"),
128
+ pack("wi", "Weather Icons", "SIL OFL 1.1", "https://erikflowers.github.io/weather-icons/")
129
+ ];
130
+ // src/ref.ts
131
+ var REF = /^icon:([a-z0-9]{1,12})\/([A-Za-z0-9-]{1,80})(#[0-9a-fA-F]{6})?$/;
132
+ function isIconRef(value) {
133
+ return REF.test(value);
134
+ }
135
+ function parseIconRef(value) {
136
+ const match = REF.exec(value);
137
+ if (!match)
138
+ return;
139
+ const [, pack = "", name = "", color] = match;
140
+ return { pack, name, ...color && { color: color.toLowerCase() } };
141
+ }
142
+ function formatIconRef({ pack, name, color }) {
143
+ return `icon:${pack}/${name}${color ?? ""}`;
144
+ }
145
+ export {
146
+ ICON_PACKS,
147
+ formatIconRef,
148
+ iconNames,
149
+ isIconRef,
150
+ kebab,
151
+ loadIcon,
152
+ parseIconRef
153
+ };
154
+
155
+ //# debugId=001A1335BB62733B64756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/load.ts", "../src/packs.ts", "../src/ref.ts"],
4
+ "sourcesContent": [
5
+ "/** Loads icons as React components. Each pack is only loaded when first used. */\n// A named import, so bundlers keep only this from lucide-react's thousands of icons.\nimport { Icon } from \"lucide-react\";\nimport { type ComponentType, createElement } from \"react\";\n\nexport type IconComponent = ComponentType<{\n size?: number | string;\n color?: string;\n className?: string;\n}>;\n\ntype Module = Record<string, unknown>;\n\n/** One literal import per pack, so bundlers can find (and split) them. */\nconst REACT_ICONS: Record<string, () => Promise<Module>> = {\n ai: () => import(\"react-icons/ai\"),\n bi: () => import(\"react-icons/bi\"),\n bs: () => import(\"react-icons/bs\"),\n cg: () => import(\"react-icons/cg\"),\n ci: () => import(\"react-icons/ci\"),\n di: () => import(\"react-icons/di\"),\n fa: () => import(\"react-icons/fa\"),\n fa6: () => import(\"react-icons/fa6\"),\n fc: () => import(\"react-icons/fc\"),\n fi: () => import(\"react-icons/fi\"),\n gi: () => import(\"react-icons/gi\"),\n go: () => import(\"react-icons/go\"),\n gr: () => import(\"react-icons/gr\"),\n hi: () => import(\"react-icons/hi\"),\n hi2: () => import(\"react-icons/hi2\"),\n im: () => import(\"react-icons/im\"),\n io: () => import(\"react-icons/io\"),\n io5: () => import(\"react-icons/io5\"),\n lia: () => import(\"react-icons/lia\"),\n lu: () => import(\"react-icons/lu\"),\n md: () => import(\"react-icons/md\"),\n pi: () => import(\"react-icons/pi\"),\n ri: () => import(\"react-icons/ri\"),\n rx: () => import(\"react-icons/rx\"),\n si: () => import(\"react-icons/si\"),\n sl: () => import(\"react-icons/sl\"),\n tb: () => import(\"react-icons/tb\"),\n tfi: () => import(\"react-icons/tfi\"),\n ti: () => import(\"react-icons/ti\"),\n vsc: () => import(\"react-icons/vsc\"),\n wi: () => import(\"react-icons/wi\"),\n};\n\ntype LucideImports = Record<string, () => Promise<{ default: IconComponent }>>;\n\nlet lucide: Promise<LucideImports> | undefined;\nconst lucideImports = () => {\n lucide ??= import(\"lucide-react/dynamicIconImports\").then(\n (m) => m.default as unknown as LucideImports,\n );\n return lucide;\n};\n\n/** `arrowDown01` → `arrow-down-0-1`, as Lucide spells names. */\nexport function kebab(camel: string): string {\n return camel\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\n .replace(/([a-zA-Z])(\\d)/g, \"$1-$2\")\n .toLowerCase();\n}\n\nlet lab: Promise<Map<string, IconComponent>> | undefined;\nconst labIcons = () => {\n lab ??= import(\"@lucide/lab\").then(\n (icons) =>\n new Map(\n Object.entries(icons as unknown as Module)\n .filter(([, node]) => Array.isArray(node))\n .map(([name, node]) => {\n const component: IconComponent = (props) =>\n createElement(Icon, { ...props, iconNode: node as never });\n return [kebab(name), component];\n }),\n ),\n );\n return lab;\n};\n\nconst packs = new Map<string, Promise<Module>>();\nfunction reactIcons(pack: string): Promise<Module> | undefined {\n if (!Object.hasOwn(REACT_ICONS, pack)) return undefined;\n let loaded = packs.get(pack);\n if (!loaded) {\n loaded = (REACT_ICONS[pack] as () => Promise<Module>)();\n loaded.catch(() => packs.delete(pack));\n packs.set(pack, loaded);\n }\n return loaded;\n}\n\n/** The names in a pack, sorted. Empty for an unknown pack. */\nexport async function iconNames(pack: string): Promise<string[]> {\n if (pack === \"lucide\") return Object.keys(await lucideImports()).sort();\n if (pack === \"lab\") return [...(await labIcons()).keys()].sort();\n const module = await reactIcons(pack);\n if (!module) return [];\n return Object.keys(module)\n .filter((name) => typeof module[name] === \"function\")\n .sort();\n}\n\n/** The component of an icon, or `undefined` when there is no such icon. */\nexport async function loadIcon(pack: string, name: string): Promise<IconComponent | undefined> {\n if (pack === \"lucide\") {\n const imports = await lucideImports();\n return Object.hasOwn(imports, name) ? (await imports[name]?.())?.default : undefined;\n }\n if (pack === \"lab\") return (await labIcons()).get(name);\n const module = await reactIcons(pack);\n if (!module || !Object.hasOwn(module, name)) return undefined;\n const icon = module[name];\n return typeof icon === \"function\" ? (icon as IconComponent) : undefined;\n}\n",
6
+ "/** The icon packs: Lucide, Lucide Lab, and every pack of react-icons. */\n\nexport interface IconPack {\n id: string;\n name: string;\n license: string;\n url: string;\n}\n\nconst pack = (id: string, name: string, license: string, url: string): IconPack => ({\n id,\n name,\n license,\n url,\n});\n\nexport const ICON_PACKS: readonly IconPack[] = [\n pack(\"lucide\", \"Lucide\", \"ISC\", \"https://lucide.dev/icons\"),\n pack(\"lab\", \"Lucide Lab\", \"ISC\", \"https://lucide.dev/lab\"),\n pack(\"ai\", \"Ant Design\", \"MIT\", \"https://github.com/ant-design/ant-design-icons\"),\n pack(\"bi\", \"BoxIcons\", \"MIT\", \"https://github.com/atisawd/boxicons\"),\n pack(\"bs\", \"Bootstrap\", \"MIT\", \"https://github.com/twbs/icons\"),\n pack(\"cg\", \"css.gg\", \"MIT\", \"https://github.com/astrit/css.gg\"),\n pack(\"ci\", \"Circum\", \"MPL-2.0\", \"https://circumicons.com/\"),\n pack(\"di\", \"Devicons\", \"MIT\", \"https://vorillaz.github.io/devicons/\"),\n pack(\"fa\", \"Font Awesome 5\", \"CC BY 4.0\", \"https://fontawesome.com/\"),\n pack(\"fa6\", \"Font Awesome 6\", \"CC BY 4.0\", \"https://fontawesome.com/\"),\n pack(\"fc\", \"Flat Color\", \"MIT\", \"https://github.com/icons8/flat-color-icons\"),\n pack(\"fi\", \"Feather\", \"MIT\", \"https://feathericons.com/\"),\n pack(\"gi\", \"Game Icons\", \"CC BY 3.0\", \"https://game-icons.net/\"),\n pack(\"go\", \"Octicons\", \"MIT\", \"https://primer.style/octicons/\"),\n pack(\"gr\", \"Grommet\", \"Apache-2.0\", \"https://github.com/grommet/grommet-icons\"),\n pack(\"hi\", \"Heroicons\", \"MIT\", \"https://github.com/tailwindlabs/heroicons\"),\n pack(\"hi2\", \"Heroicons 2\", \"MIT\", \"https://github.com/tailwindlabs/heroicons\"),\n pack(\"im\", \"IcoMoon Free\", \"CC BY 4.0\", \"https://github.com/Keyamoon/IcoMoon-Free\"),\n pack(\"io\", \"Ionicons 4\", \"MIT\", \"https://ionicons.com/\"),\n pack(\"io5\", \"Ionicons 5\", \"MIT\", \"https://ionicons.com/\"),\n pack(\"lia\", \"Line Awesome\", \"MIT\", \"https://icons8.com/line-awesome\"),\n pack(\"lu\", \"Lucide (react-icons)\", \"ISC\", \"https://lucide.dev/\"),\n pack(\"md\", \"Material Design\", \"Apache-2.0\", \"https://google.github.io/material-design-icons/\"),\n pack(\"pi\", \"Phosphor\", \"MIT\", \"https://github.com/phosphor-icons/core\"),\n pack(\"ri\", \"Remix Icon\", \"Apache-2.0\", \"https://github.com/Remix-Design/RemixIcon\"),\n pack(\"rx\", \"Radix\", \"MIT\", \"https://icons.radix-ui.com/\"),\n pack(\"si\", \"Simple Icons (brands)\", \"CC0 1.0\", \"https://simpleicons.org/\"),\n pack(\"sl\", \"Simple Line\", \"MIT\", \"https://github.com/thesabbir/simple-line-icons\"),\n pack(\"tb\", \"Tabler\", \"MIT\", \"https://github.com/tabler/tabler-icons\"),\n pack(\"tfi\", \"Themify\", \"MIT\", \"https://github.com/lykmapipo/themify-icons\"),\n pack(\"ti\", \"Typicons\", \"CC BY-SA 3.0\", \"https://github.com/stephenhutchings/typicons.font\"),\n pack(\"vsc\", \"VS Code\", \"CC BY 4.0\", \"https://github.com/microsoft/vscode-codicons\"),\n pack(\"wi\", \"Weather Icons\", \"SIL OFL 1.1\", \"https://erikflowers.github.io/weather-icons/\"),\n];\n",
7
+ "/**\n * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its\n * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export\n * names (`icon:si/SiDiscord`).\n */\n\nexport interface IconRef {\n pack: string;\n name: string;\n /** `#rrggbb`, when the reference carries its own colour. */\n color?: string;\n}\n\nconst REF = /^icon:([a-z0-9]{1,12})\\/([A-Za-z0-9-]{1,80})(#[0-9a-fA-F]{6})?$/;\n\nexport function isIconRef(value: string): boolean {\n return REF.test(value);\n}\n\nexport function parseIconRef(value: string): IconRef | undefined {\n const match = REF.exec(value);\n if (!match) return undefined;\n const [, pack = \"\", name = \"\", color] = match;\n return { pack, name, ...(color && { color: color.toLowerCase() }) };\n}\n\nexport function formatIconRef({ pack, name, color }: IconRef): string {\n return `icon:${pack}/${name}${color ?? \"\"}`;\n}\n"
8
+ ],
9
+ "mappings": ";AAEA;AACA;AAWA,IAAM,cAAqD;AAAA,EACzD,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AACZ;AAIA,IAAI;AACJ,IAAM,gBAAgB,MAAM;AAAA,EAC1B,WAAW,0CAA0C,KACnD,CAAC,MAAQ,SACX;AAAA,EACA,OAAO;AAAA;AAIF,SAAS,KAAK,CAAC,OAAuB;AAAA,EAC3C,OAAO,M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ACpE,OAAO,QAAQ,QAAQ,OAAO,SAAS;AAAA;",
10
+ "debugId": "001A1335BB62733B64756E2164756E21",
11
+ "names": []
12
+ }
package/dist/load.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { type ComponentType } from "react";
2
+ export type IconComponent = ComponentType<{
3
+ size?: number | string;
4
+ color?: string;
5
+ className?: string;
6
+ }>;
7
+ /** `arrowDown01` → `arrow-down-0-1`, as Lucide spells names. */
8
+ export declare function kebab(camel: string): string;
9
+ /** The names in a pack, sorted. Empty for an unknown pack. */
10
+ export declare function iconNames(pack: string): Promise<string[]>;
11
+ /** The component of an icon, or `undefined` when there is no such icon. */
12
+ export declare function loadIcon(pack: string, name: string): Promise<IconComponent | undefined>;
13
+ //# sourceMappingURL=load.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,OAAO,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,aAAa,CAAC;IACxC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC,CAAC;AAiDH,gEAAgE;AAChE,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAK3C;AA+BD,8DAA8D;AAC9D,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ/D;AAED,2EAA2E;AAC3E,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAU7F"}
@@ -0,0 +1,9 @@
1
+ /** The icon packs: Lucide, Lucide Lab, and every pack of react-icons. */
2
+ export interface IconPack {
3
+ id: string;
4
+ name: string;
5
+ license: string;
6
+ url: string;
7
+ }
8
+ export declare const ICON_PACKS: readonly IconPack[];
9
+ //# sourceMappingURL=packs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packs.d.ts","sourceRoot":"","sources":["../src/packs.ts"],"names":[],"mappings":"AAAA,yEAAyE;AAEzE,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AASD,eAAO,MAAM,UAAU,EAAE,SAAS,QAAQ,EAkCzC,CAAC"}
package/dist/ref.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its
3
+ * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export
4
+ * names (`icon:si/SiDiscord`).
5
+ */
6
+ export interface IconRef {
7
+ pack: string;
8
+ name: string;
9
+ /** `#rrggbb`, when the reference carries its own colour. */
10
+ color?: string;
11
+ }
12
+ export declare function isIconRef(value: string): boolean;
13
+ export declare function parseIconRef(value: string): IconRef | undefined;
14
+ export declare function formatIconRef({ pack, name, color }: IconRef): string;
15
+ //# sourceMappingURL=ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref.d.ts","sourceRoot":"","sources":["../src/ref.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAID,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAK/D;AAED,wBAAgB,aAAa,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,GAAG,MAAM,CAEpE"}
package/dist/svg.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The SVG of an icon reference. `color` (or else the reference's own colour, or white) fills
3
+ * whatever the icon draws in the current colour; multicolour icons keep their colours.
4
+ * `undefined` when there is no such icon.
5
+ */
6
+ export declare function iconSvg(ref: string, color?: string): Promise<string | undefined>;
7
+ /** {@link iconSvg} as a `data:` URI. */
8
+ export declare function iconDataUri(ref: string, color?: string): Promise<string | undefined>;
9
+ //# sourceMappingURL=svg.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"svg.d.ts","sourceRoot":"","sources":["../src/svg.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAYtF;AAED,wCAAwC;AACxC,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG1F"}
package/dist/svg.js ADDED
@@ -0,0 +1,133 @@
1
+ // src/svg.ts
2
+ import { createElement as createElement2 } from "react";
3
+ import { renderToStaticMarkup } from "react-dom/server";
4
+
5
+ // src/load.ts
6
+ import { Icon } from "lucide-react";
7
+ import { createElement } from "react";
8
+ var REACT_ICONS = {
9
+ ai: () => import("react-icons/ai"),
10
+ bi: () => import("react-icons/bi"),
11
+ bs: () => import("react-icons/bs"),
12
+ cg: () => import("react-icons/cg"),
13
+ ci: () => import("react-icons/ci"),
14
+ di: () => import("react-icons/di"),
15
+ fa: () => import("react-icons/fa"),
16
+ fa6: () => import("react-icons/fa6"),
17
+ fc: () => import("react-icons/fc"),
18
+ fi: () => import("react-icons/fi"),
19
+ gi: () => import("react-icons/gi"),
20
+ go: () => import("react-icons/go"),
21
+ gr: () => import("react-icons/gr"),
22
+ hi: () => import("react-icons/hi"),
23
+ hi2: () => import("react-icons/hi2"),
24
+ im: () => import("react-icons/im"),
25
+ io: () => import("react-icons/io"),
26
+ io5: () => import("react-icons/io5"),
27
+ lia: () => import("react-icons/lia"),
28
+ lu: () => import("react-icons/lu"),
29
+ md: () => import("react-icons/md"),
30
+ pi: () => import("react-icons/pi"),
31
+ ri: () => import("react-icons/ri"),
32
+ rx: () => import("react-icons/rx"),
33
+ si: () => import("react-icons/si"),
34
+ sl: () => import("react-icons/sl"),
35
+ tb: () => import("react-icons/tb"),
36
+ tfi: () => import("react-icons/tfi"),
37
+ ti: () => import("react-icons/ti"),
38
+ vsc: () => import("react-icons/vsc"),
39
+ wi: () => import("react-icons/wi")
40
+ };
41
+ var lucide;
42
+ var lucideImports = () => {
43
+ lucide ??= import("lucide-react/dynamicIconImports").then((m) => m.default);
44
+ return lucide;
45
+ };
46
+ function kebab(camel) {
47
+ return camel.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([a-zA-Z])(\d)/g, "$1-$2").toLowerCase();
48
+ }
49
+ var lab;
50
+ var labIcons = () => {
51
+ lab ??= import("@lucide/lab").then((icons) => new Map(Object.entries(icons).filter(([, node]) => Array.isArray(node)).map(([name, node]) => {
52
+ const component = (props) => createElement(Icon, { ...props, iconNode: node });
53
+ return [kebab(name), component];
54
+ })));
55
+ return lab;
56
+ };
57
+ var packs = new Map;
58
+ function reactIcons(pack) {
59
+ if (!Object.hasOwn(REACT_ICONS, pack))
60
+ return;
61
+ let loaded = packs.get(pack);
62
+ if (!loaded) {
63
+ loaded = REACT_ICONS[pack]();
64
+ loaded.catch(() => packs.delete(pack));
65
+ packs.set(pack, loaded);
66
+ }
67
+ return loaded;
68
+ }
69
+ async function iconNames(pack) {
70
+ if (pack === "lucide")
71
+ return Object.keys(await lucideImports()).sort();
72
+ if (pack === "lab")
73
+ return [...(await labIcons()).keys()].sort();
74
+ const module = await reactIcons(pack);
75
+ if (!module)
76
+ return [];
77
+ return Object.keys(module).filter((name) => typeof module[name] === "function").sort();
78
+ }
79
+ async function loadIcon(pack, name) {
80
+ if (pack === "lucide") {
81
+ const imports = await lucideImports();
82
+ return Object.hasOwn(imports, name) ? (await imports[name]?.())?.default : undefined;
83
+ }
84
+ if (pack === "lab")
85
+ return (await labIcons()).get(name);
86
+ const module = await reactIcons(pack);
87
+ if (!module || !Object.hasOwn(module, name))
88
+ return;
89
+ const icon = module[name];
90
+ return typeof icon === "function" ? icon : undefined;
91
+ }
92
+
93
+ // src/ref.ts
94
+ var REF = /^icon:([a-z0-9]{1,12})\/([A-Za-z0-9-]{1,80})(#[0-9a-fA-F]{6})?$/;
95
+ function isIconRef(value) {
96
+ return REF.test(value);
97
+ }
98
+ function parseIconRef(value) {
99
+ const match = REF.exec(value);
100
+ if (!match)
101
+ return;
102
+ const [, pack = "", name = "", color] = match;
103
+ return { pack, name, ...color && { color: color.toLowerCase() } };
104
+ }
105
+ function formatIconRef({ pack, name, color }) {
106
+ return `icon:${pack}/${name}${color ?? ""}`;
107
+ }
108
+
109
+ // src/svg.ts
110
+ var HEX = /^#[0-9a-f]{6}$/i;
111
+ var SIZE = 96;
112
+ async function iconSvg(ref, color) {
113
+ const parsed = parseIconRef(ref);
114
+ if (!parsed)
115
+ return;
116
+ const component = await loadIcon(parsed.pack, parsed.name);
117
+ if (!component)
118
+ return;
119
+ const wanted = color && HEX.test(color) ? color : parsed.color ?? "#ffffff";
120
+ const markup = renderToStaticMarkup(createElement2(component, { size: SIZE, color: wanted }));
121
+ const filled = markup.replaceAll("currentColor", wanted);
122
+ return filled.includes("xmlns=") ? filled : filled.replace("<svg", '<svg xmlns="http://www.w3.org/2000/svg"');
123
+ }
124
+ async function iconDataUri(ref, color) {
125
+ const svg = await iconSvg(ref, color);
126
+ return svg && `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
127
+ }
128
+ export {
129
+ iconDataUri,
130
+ iconSvg
131
+ };
132
+
133
+ //# debugId=3A10A27D600194DA64756E2164756E21
@@ -0,0 +1,12 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/svg.ts", "../src/load.ts", "../src/ref.ts"],
4
+ "sourcesContent": [
5
+ "/** Icons as standalone SVG images, for renderers that draw pictures rather than React. */\nimport { createElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { loadIcon } from \"./load.ts\";\nimport { parseIconRef } from \"./ref.ts\";\n\nconst HEX = /^#[0-9a-f]{6}$/i;\nconst SIZE = 96;\n\n/**\n * The SVG of an icon reference. `color` (or else the reference's own colour, or white) fills\n * whatever the icon draws in the current colour; multicolour icons keep their colours.\n * `undefined` when there is no such icon.\n */\nexport async function iconSvg(ref: string, color?: string): Promise<string | undefined> {\n const parsed = parseIconRef(ref);\n if (!parsed) return undefined;\n const component = await loadIcon(parsed.pack, parsed.name);\n if (!component) return undefined;\n const wanted = color && HEX.test(color) ? color : (parsed.color ?? \"#ffffff\");\n const markup = renderToStaticMarkup(createElement(component, { size: SIZE, color: wanted }));\n // Standalone images have no surrounding text colour to inherit.\n const filled = markup.replaceAll(\"currentColor\", wanted);\n return filled.includes(\"xmlns=\")\n ? filled\n : filled.replace(\"<svg\", '<svg xmlns=\"http://www.w3.org/2000/svg\"');\n}\n\n/** {@link iconSvg} as a `data:` URI. */\nexport async function iconDataUri(ref: string, color?: string): Promise<string | undefined> {\n const svg = await iconSvg(ref, color);\n return svg && `data:image/svg+xml;base64,${Buffer.from(svg).toString(\"base64\")}`;\n}\n",
6
+ "/** Loads icons as React components. Each pack is only loaded when first used. */\n// A named import, so bundlers keep only this from lucide-react's thousands of icons.\nimport { Icon } from \"lucide-react\";\nimport { type ComponentType, createElement } from \"react\";\n\nexport type IconComponent = ComponentType<{\n size?: number | string;\n color?: string;\n className?: string;\n}>;\n\ntype Module = Record<string, unknown>;\n\n/** One literal import per pack, so bundlers can find (and split) them. */\nconst REACT_ICONS: Record<string, () => Promise<Module>> = {\n ai: () => import(\"react-icons/ai\"),\n bi: () => import(\"react-icons/bi\"),\n bs: () => import(\"react-icons/bs\"),\n cg: () => import(\"react-icons/cg\"),\n ci: () => import(\"react-icons/ci\"),\n di: () => import(\"react-icons/di\"),\n fa: () => import(\"react-icons/fa\"),\n fa6: () => import(\"react-icons/fa6\"),\n fc: () => import(\"react-icons/fc\"),\n fi: () => import(\"react-icons/fi\"),\n gi: () => import(\"react-icons/gi\"),\n go: () => import(\"react-icons/go\"),\n gr: () => import(\"react-icons/gr\"),\n hi: () => import(\"react-icons/hi\"),\n hi2: () => import(\"react-icons/hi2\"),\n im: () => import(\"react-icons/im\"),\n io: () => import(\"react-icons/io\"),\n io5: () => import(\"react-icons/io5\"),\n lia: () => import(\"react-icons/lia\"),\n lu: () => import(\"react-icons/lu\"),\n md: () => import(\"react-icons/md\"),\n pi: () => import(\"react-icons/pi\"),\n ri: () => import(\"react-icons/ri\"),\n rx: () => import(\"react-icons/rx\"),\n si: () => import(\"react-icons/si\"),\n sl: () => import(\"react-icons/sl\"),\n tb: () => import(\"react-icons/tb\"),\n tfi: () => import(\"react-icons/tfi\"),\n ti: () => import(\"react-icons/ti\"),\n vsc: () => import(\"react-icons/vsc\"),\n wi: () => import(\"react-icons/wi\"),\n};\n\ntype LucideImports = Record<string, () => Promise<{ default: IconComponent }>>;\n\nlet lucide: Promise<LucideImports> | undefined;\nconst lucideImports = () => {\n lucide ??= import(\"lucide-react/dynamicIconImports\").then(\n (m) => m.default as unknown as LucideImports,\n );\n return lucide;\n};\n\n/** `arrowDown01` → `arrow-down-0-1`, as Lucide spells names. */\nexport function kebab(camel: string): string {\n return camel\n .replace(/([a-z0-9])([A-Z])/g, \"$1-$2\")\n .replace(/([a-zA-Z])(\\d)/g, \"$1-$2\")\n .toLowerCase();\n}\n\nlet lab: Promise<Map<string, IconComponent>> | undefined;\nconst labIcons = () => {\n lab ??= import(\"@lucide/lab\").then(\n (icons) =>\n new Map(\n Object.entries(icons as unknown as Module)\n .filter(([, node]) => Array.isArray(node))\n .map(([name, node]) => {\n const component: IconComponent = (props) =>\n createElement(Icon, { ...props, iconNode: node as never });\n return [kebab(name), component];\n }),\n ),\n );\n return lab;\n};\n\nconst packs = new Map<string, Promise<Module>>();\nfunction reactIcons(pack: string): Promise<Module> | undefined {\n if (!Object.hasOwn(REACT_ICONS, pack)) return undefined;\n let loaded = packs.get(pack);\n if (!loaded) {\n loaded = (REACT_ICONS[pack] as () => Promise<Module>)();\n loaded.catch(() => packs.delete(pack));\n packs.set(pack, loaded);\n }\n return loaded;\n}\n\n/** The names in a pack, sorted. Empty for an unknown pack. */\nexport async function iconNames(pack: string): Promise<string[]> {\n if (pack === \"lucide\") return Object.keys(await lucideImports()).sort();\n if (pack === \"lab\") return [...(await labIcons()).keys()].sort();\n const module = await reactIcons(pack);\n if (!module) return [];\n return Object.keys(module)\n .filter((name) => typeof module[name] === \"function\")\n .sort();\n}\n\n/** The component of an icon, or `undefined` when there is no such icon. */\nexport async function loadIcon(pack: string, name: string): Promise<IconComponent | undefined> {\n if (pack === \"lucide\") {\n const imports = await lucideImports();\n return Object.hasOwn(imports, name) ? (await imports[name]?.())?.default : undefined;\n }\n if (pack === \"lab\") return (await labIcons()).get(name);\n const module = await reactIcons(pack);\n if (!module || !Object.hasOwn(module, name)) return undefined;\n const icon = module[name];\n return typeof icon === \"function\" ? (icon as IconComponent) : undefined;\n}\n",
7
+ "/**\n * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its\n * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export\n * names (`icon:si/SiDiscord`).\n */\n\nexport interface IconRef {\n pack: string;\n name: string;\n /** `#rrggbb`, when the reference carries its own colour. */\n color?: string;\n}\n\nconst REF = /^icon:([a-z0-9]{1,12})\\/([A-Za-z0-9-]{1,80})(#[0-9a-fA-F]{6})?$/;\n\nexport function isIconRef(value: string): boolean {\n return REF.test(value);\n}\n\nexport function parseIconRef(value: string): IconRef | undefined {\n const match = REF.exec(value);\n if (!match) return undefined;\n const [, pack = \"\", name = \"\", color] = match;\n return { pack, name, ...(color && { color: color.toLowerCase() }) };\n}\n\nexport function formatIconRef({ pack, name, color }: IconRef): string {\n return `icon:${pack}/${name}${color ?? \"\"}`;\n}\n"
8
+ ],
9
+ "mappings": ";AACA,0BAAS;AACT;;;ACAA;AACA;AAWA,IAAM,cAAqD;AAAA,EACzD,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AAAA,EACV,KAAK,MAAM;AAAA,EACX,IAAI,MAAM;AACZ;AAIA,IAAI;AACJ,IAAM,gBAAgB,MAAM;AAAA,EAC1B,WAAW,0CAA0C,KACnD,CAAC,MAAQ,SACX;AAAA,EACA,OAAO;AAAA;AAIF,SAAS,KAAK,CAAC,OAAuB;AAAA,EAC3C,OAAO,MACJ,QAAQ,sBAAsB,OAAO,EACrC,QAAQ,mBAAmB,OAAO,EAClC,YAAY;AAAA;AAGjB,IAAI;AACJ,IAAM,WAAW,MAAM;AAAA,EACrB,QAAQ,sBAAsB,KAC5B,CAAC,UACC,IAA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QAAQ,yCAAyC;AAAA;AAI/D,eAAe,WAAW,CAAC,KAAa,OAA6C;AAAA,EAC1F,MAAM,MAAM,MAAM,QAAQ,KAAK,KAAK;AAAA,EACpC,OAAO,OAAO,6BAA6B,OAAO,KAAK,GAAG,EAAE,SAAS,QAAQ;AAAA;",
10
+ "debugId": "3A10A27D600194DA64756E2164756E21",
11
+ "names": []
12
+ }
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@sdeck/icons",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Every Lucide, Lucide Lab and react-icons icon by reference (icon:pack/name), loaded on demand.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "files": [
9
+ "dist",
10
+ "src"
11
+ ],
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "bun": "./src/index.ts",
18
+ "import": "./dist/index.js"
19
+ },
20
+ "./svg": {
21
+ "types": "./dist/svg.d.ts",
22
+ "bun": "./src/svg.ts",
23
+ "import": "./dist/svg.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "scripts": {
28
+ "build": "bun ../../scripts/build-package.ts --entry=src/index.ts --entry=src/svg.ts",
29
+ "clean": "rm -rf dist",
30
+ "test": "bun test"
31
+ },
32
+ "dependencies": {
33
+ "@lucide/lab": "0.19.0",
34
+ "lucide-react": "^1.84.0",
35
+ "react-icons": "^5.7.0"
36
+ },
37
+ "peerDependencies": {
38
+ "react": ">=19.3",
39
+ "react-dom": ">=19.3"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/ivanoliverfabra/sdeck.git",
44
+ "directory": "packages/icons"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ }
49
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@sdeck/icons`: every Lucide, Lucide Lab and react-icons icon, addressed as
3
+ * `icon:<pack>/<name>` and loaded on demand. Browser-safe; `@sdeck/icons/svg` turns a reference
4
+ * into an SVG image.
5
+ */
6
+ export { type IconComponent, iconNames, kebab, loadIcon } from "./load.ts";
7
+ export { ICON_PACKS, type IconPack } from "./packs.ts";
8
+ export { formatIconRef, type IconRef, isIconRef, parseIconRef } from "./ref.ts";
package/src/load.ts ADDED
@@ -0,0 +1,118 @@
1
+ /** Loads icons as React components. Each pack is only loaded when first used. */
2
+ // A named import, so bundlers keep only this from lucide-react's thousands of icons.
3
+ import { Icon } from "lucide-react";
4
+ import { type ComponentType, createElement } from "react";
5
+
6
+ export type IconComponent = ComponentType<{
7
+ size?: number | string;
8
+ color?: string;
9
+ className?: string;
10
+ }>;
11
+
12
+ type Module = Record<string, unknown>;
13
+
14
+ /** One literal import per pack, so bundlers can find (and split) them. */
15
+ const REACT_ICONS: Record<string, () => Promise<Module>> = {
16
+ ai: () => import("react-icons/ai"),
17
+ bi: () => import("react-icons/bi"),
18
+ bs: () => import("react-icons/bs"),
19
+ cg: () => import("react-icons/cg"),
20
+ ci: () => import("react-icons/ci"),
21
+ di: () => import("react-icons/di"),
22
+ fa: () => import("react-icons/fa"),
23
+ fa6: () => import("react-icons/fa6"),
24
+ fc: () => import("react-icons/fc"),
25
+ fi: () => import("react-icons/fi"),
26
+ gi: () => import("react-icons/gi"),
27
+ go: () => import("react-icons/go"),
28
+ gr: () => import("react-icons/gr"),
29
+ hi: () => import("react-icons/hi"),
30
+ hi2: () => import("react-icons/hi2"),
31
+ im: () => import("react-icons/im"),
32
+ io: () => import("react-icons/io"),
33
+ io5: () => import("react-icons/io5"),
34
+ lia: () => import("react-icons/lia"),
35
+ lu: () => import("react-icons/lu"),
36
+ md: () => import("react-icons/md"),
37
+ pi: () => import("react-icons/pi"),
38
+ ri: () => import("react-icons/ri"),
39
+ rx: () => import("react-icons/rx"),
40
+ si: () => import("react-icons/si"),
41
+ sl: () => import("react-icons/sl"),
42
+ tb: () => import("react-icons/tb"),
43
+ tfi: () => import("react-icons/tfi"),
44
+ ti: () => import("react-icons/ti"),
45
+ vsc: () => import("react-icons/vsc"),
46
+ wi: () => import("react-icons/wi"),
47
+ };
48
+
49
+ type LucideImports = Record<string, () => Promise<{ default: IconComponent }>>;
50
+
51
+ let lucide: Promise<LucideImports> | undefined;
52
+ const lucideImports = () => {
53
+ lucide ??= import("lucide-react/dynamicIconImports").then(
54
+ (m) => m.default as unknown as LucideImports,
55
+ );
56
+ return lucide;
57
+ };
58
+
59
+ /** `arrowDown01` → `arrow-down-0-1`, as Lucide spells names. */
60
+ export function kebab(camel: string): string {
61
+ return camel
62
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
63
+ .replace(/([a-zA-Z])(\d)/g, "$1-$2")
64
+ .toLowerCase();
65
+ }
66
+
67
+ let lab: Promise<Map<string, IconComponent>> | undefined;
68
+ const labIcons = () => {
69
+ lab ??= import("@lucide/lab").then(
70
+ (icons) =>
71
+ new Map(
72
+ Object.entries(icons as unknown as Module)
73
+ .filter(([, node]) => Array.isArray(node))
74
+ .map(([name, node]) => {
75
+ const component: IconComponent = (props) =>
76
+ createElement(Icon, { ...props, iconNode: node as never });
77
+ return [kebab(name), component];
78
+ }),
79
+ ),
80
+ );
81
+ return lab;
82
+ };
83
+
84
+ const packs = new Map<string, Promise<Module>>();
85
+ function reactIcons(pack: string): Promise<Module> | undefined {
86
+ if (!Object.hasOwn(REACT_ICONS, pack)) return undefined;
87
+ let loaded = packs.get(pack);
88
+ if (!loaded) {
89
+ loaded = (REACT_ICONS[pack] as () => Promise<Module>)();
90
+ loaded.catch(() => packs.delete(pack));
91
+ packs.set(pack, loaded);
92
+ }
93
+ return loaded;
94
+ }
95
+
96
+ /** The names in a pack, sorted. Empty for an unknown pack. */
97
+ export async function iconNames(pack: string): Promise<string[]> {
98
+ if (pack === "lucide") return Object.keys(await lucideImports()).sort();
99
+ if (pack === "lab") return [...(await labIcons()).keys()].sort();
100
+ const module = await reactIcons(pack);
101
+ if (!module) return [];
102
+ return Object.keys(module)
103
+ .filter((name) => typeof module[name] === "function")
104
+ .sort();
105
+ }
106
+
107
+ /** The component of an icon, or `undefined` when there is no such icon. */
108
+ export async function loadIcon(pack: string, name: string): Promise<IconComponent | undefined> {
109
+ if (pack === "lucide") {
110
+ const imports = await lucideImports();
111
+ return Object.hasOwn(imports, name) ? (await imports[name]?.())?.default : undefined;
112
+ }
113
+ if (pack === "lab") return (await labIcons()).get(name);
114
+ const module = await reactIcons(pack);
115
+ if (!module || !Object.hasOwn(module, name)) return undefined;
116
+ const icon = module[name];
117
+ return typeof icon === "function" ? (icon as IconComponent) : undefined;
118
+ }
package/src/packs.ts ADDED
@@ -0,0 +1,51 @@
1
+ /** The icon packs: Lucide, Lucide Lab, and every pack of react-icons. */
2
+
3
+ export interface IconPack {
4
+ id: string;
5
+ name: string;
6
+ license: string;
7
+ url: string;
8
+ }
9
+
10
+ const pack = (id: string, name: string, license: string, url: string): IconPack => ({
11
+ id,
12
+ name,
13
+ license,
14
+ url,
15
+ });
16
+
17
+ export const ICON_PACKS: readonly IconPack[] = [
18
+ pack("lucide", "Lucide", "ISC", "https://lucide.dev/icons"),
19
+ pack("lab", "Lucide Lab", "ISC", "https://lucide.dev/lab"),
20
+ pack("ai", "Ant Design", "MIT", "https://github.com/ant-design/ant-design-icons"),
21
+ pack("bi", "BoxIcons", "MIT", "https://github.com/atisawd/boxicons"),
22
+ pack("bs", "Bootstrap", "MIT", "https://github.com/twbs/icons"),
23
+ pack("cg", "css.gg", "MIT", "https://github.com/astrit/css.gg"),
24
+ pack("ci", "Circum", "MPL-2.0", "https://circumicons.com/"),
25
+ pack("di", "Devicons", "MIT", "https://vorillaz.github.io/devicons/"),
26
+ pack("fa", "Font Awesome 5", "CC BY 4.0", "https://fontawesome.com/"),
27
+ pack("fa6", "Font Awesome 6", "CC BY 4.0", "https://fontawesome.com/"),
28
+ pack("fc", "Flat Color", "MIT", "https://github.com/icons8/flat-color-icons"),
29
+ pack("fi", "Feather", "MIT", "https://feathericons.com/"),
30
+ pack("gi", "Game Icons", "CC BY 3.0", "https://game-icons.net/"),
31
+ pack("go", "Octicons", "MIT", "https://primer.style/octicons/"),
32
+ pack("gr", "Grommet", "Apache-2.0", "https://github.com/grommet/grommet-icons"),
33
+ pack("hi", "Heroicons", "MIT", "https://github.com/tailwindlabs/heroicons"),
34
+ pack("hi2", "Heroicons 2", "MIT", "https://github.com/tailwindlabs/heroicons"),
35
+ pack("im", "IcoMoon Free", "CC BY 4.0", "https://github.com/Keyamoon/IcoMoon-Free"),
36
+ pack("io", "Ionicons 4", "MIT", "https://ionicons.com/"),
37
+ pack("io5", "Ionicons 5", "MIT", "https://ionicons.com/"),
38
+ pack("lia", "Line Awesome", "MIT", "https://icons8.com/line-awesome"),
39
+ pack("lu", "Lucide (react-icons)", "ISC", "https://lucide.dev/"),
40
+ pack("md", "Material Design", "Apache-2.0", "https://google.github.io/material-design-icons/"),
41
+ pack("pi", "Phosphor", "MIT", "https://github.com/phosphor-icons/core"),
42
+ pack("ri", "Remix Icon", "Apache-2.0", "https://github.com/Remix-Design/RemixIcon"),
43
+ pack("rx", "Radix", "MIT", "https://icons.radix-ui.com/"),
44
+ pack("si", "Simple Icons (brands)", "CC0 1.0", "https://simpleicons.org/"),
45
+ pack("sl", "Simple Line", "MIT", "https://github.com/thesabbir/simple-line-icons"),
46
+ pack("tb", "Tabler", "MIT", "https://github.com/tabler/tabler-icons"),
47
+ pack("tfi", "Themify", "MIT", "https://github.com/lykmapipo/themify-icons"),
48
+ pack("ti", "Typicons", "CC BY-SA 3.0", "https://github.com/stephenhutchings/typicons.font"),
49
+ pack("vsc", "VS Code", "CC BY 4.0", "https://github.com/microsoft/vscode-codicons"),
50
+ pack("wi", "Weather Icons", "SIL OFL 1.1", "https://erikflowers.github.io/weather-icons/"),
51
+ ];
package/src/ref.ts ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its
3
+ * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export
4
+ * names (`icon:si/SiDiscord`).
5
+ */
6
+
7
+ export interface IconRef {
8
+ pack: string;
9
+ name: string;
10
+ /** `#rrggbb`, when the reference carries its own colour. */
11
+ color?: string;
12
+ }
13
+
14
+ const REF = /^icon:([a-z0-9]{1,12})\/([A-Za-z0-9-]{1,80})(#[0-9a-fA-F]{6})?$/;
15
+
16
+ export function isIconRef(value: string): boolean {
17
+ return REF.test(value);
18
+ }
19
+
20
+ export function parseIconRef(value: string): IconRef | undefined {
21
+ const match = REF.exec(value);
22
+ if (!match) return undefined;
23
+ const [, pack = "", name = "", color] = match;
24
+ return { pack, name, ...(color && { color: color.toLowerCase() }) };
25
+ }
26
+
27
+ export function formatIconRef({ pack, name, color }: IconRef): string {
28
+ return `icon:${pack}/${name}${color ?? ""}`;
29
+ }
package/src/svg.ts ADDED
@@ -0,0 +1,33 @@
1
+ /** Icons as standalone SVG images, for renderers that draw pictures rather than React. */
2
+ import { createElement } from "react";
3
+ import { renderToStaticMarkup } from "react-dom/server";
4
+ import { loadIcon } from "./load.ts";
5
+ import { parseIconRef } from "./ref.ts";
6
+
7
+ const HEX = /^#[0-9a-f]{6}$/i;
8
+ const SIZE = 96;
9
+
10
+ /**
11
+ * The SVG of an icon reference. `color` (or else the reference's own colour, or white) fills
12
+ * whatever the icon draws in the current colour; multicolour icons keep their colours.
13
+ * `undefined` when there is no such icon.
14
+ */
15
+ export async function iconSvg(ref: string, color?: string): Promise<string | undefined> {
16
+ const parsed = parseIconRef(ref);
17
+ if (!parsed) return undefined;
18
+ const component = await loadIcon(parsed.pack, parsed.name);
19
+ if (!component) return undefined;
20
+ const wanted = color && HEX.test(color) ? color : (parsed.color ?? "#ffffff");
21
+ const markup = renderToStaticMarkup(createElement(component, { size: SIZE, color: wanted }));
22
+ // Standalone images have no surrounding text colour to inherit.
23
+ const filled = markup.replaceAll("currentColor", wanted);
24
+ return filled.includes("xmlns=")
25
+ ? filled
26
+ : filled.replace("<svg", '<svg xmlns="http://www.w3.org/2000/svg"');
27
+ }
28
+
29
+ /** {@link iconSvg} as a `data:` URI. */
30
+ export async function iconDataUri(ref: string, color?: string): Promise<string | undefined> {
31
+ const svg = await iconSvg(ref, color);
32
+ return svg && `data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`;
33
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.