@sdeck/icons 0.3.0 → 0.4.1

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.
package/dist/index.js.map CHANGED
@@ -4,7 +4,7 @@
4
4
  "sourcesContent": [
5
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
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"
7
+ "/**\n * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a color 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 color. */\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
8
  ],
9
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,MA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D;AAAA,EAC1F,KAAK,OAAO,WAAW,aAAa,8CAA8C;AAAA,EAClF,KAAK,MAAM,iBAAiB,eAAe,8CAA8C;AAC3F;;ACrCA,IAAM,MAAM;AAEL,SAAS,SAAS,CAAC,OAAwB;AAAA,EAChD,OAAO,IAAI,KAAK,KAAK;AAAA;AAGhB,SAAS,YAAY,CAAC,OAAoC;AAAA,EAC/D,MAAM,QAAQ,IAAI,KAAK,KAAK;AAAA,EAC5B,IAAI,CAAC;AAAA,IAAO;AAAA,EACZ,SAAS,OAAO,IAAI,OAAO,IAAI,SAAS;AAAA,EACxC,OAAO,EAAE,MAAM,SAAU,SAAS,EAAE,OAAO,MAAM,YAAY,EAAE,EAAG;AAAA;AAG7D,SAAS,aAAa,GAAG,MAAM,MAAM,SAA0B;AAAA,EACpE,OAAO,QAAQ,QAAQ,OAAO,SAAS;AAAA;",
10
10
  "debugId": "001A1335BB62733B64756E2164756E21",
package/dist/ref.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its
2
+ * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a color of its
3
3
  * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export
4
4
  * names (`icon:si/SiDiscord`).
5
5
  */
6
6
  export interface IconRef {
7
7
  pack: string;
8
8
  name: string;
9
- /** `#rrggbb`, when the reference carries its own colour. */
9
+ /** `#rrggbb`, when the reference carries its own color. */
10
10
  color?: string;
11
11
  }
12
12
  export declare function isIconRef(value: string): boolean;
package/dist/ref.d.ts.map CHANGED
@@ -1 +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"}
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,2DAA2D;IAC3D,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 CHANGED
@@ -1,6 +1,6 @@
1
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.
2
+ * The SVG of an icon reference. `color` (or else the reference's own color, or white) fills
3
+ * whatever the icon draws in the current color; multicolor icons keep their colors.
4
4
  * `undefined` when there is no such icon.
5
5
  */
6
6
  export declare function iconSvg(ref: string, color?: string): Promise<string | undefined>;
package/dist/svg.js.map CHANGED
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/svg.ts", "../src/load.ts", "../src/ref.ts"],
4
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",
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 color, or white) fills\n * whatever the icon draws in the current color; multicolor icons keep their colors.\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 color 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
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"
7
+ "/**\n * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a color 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 color. */\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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EACpC,OAAO,OAAO,6BAA6B,OAAO,KAAK,GAAG,EAAE,SAAS,QAAQ;AAAA;",
10
10
  "debugId": "3A10A27D600194DA64756E2164756E21",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeck/icons",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Every Lucide, Lucide Lab and react-icons icon by reference (icon:pack/name), loaded on demand.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/ref.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a colour of its
2
+ * Icon references: `icon:<pack>/<name>`, optionally followed by `#rrggbb` for a color of its
3
3
  * own. Lucide names are kebab case (`icon:lucide/volume-2`); react-icons ones are their export
4
4
  * names (`icon:si/SiDiscord`).
5
5
  */
@@ -7,7 +7,7 @@
7
7
  export interface IconRef {
8
8
  pack: string;
9
9
  name: string;
10
- /** `#rrggbb`, when the reference carries its own colour. */
10
+ /** `#rrggbb`, when the reference carries its own color. */
11
11
  color?: string;
12
12
  }
13
13
 
package/src/svg.ts CHANGED
@@ -8,8 +8,8 @@ const HEX = /^#[0-9a-f]{6}$/i;
8
8
  const SIZE = 96;
9
9
 
10
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.
11
+ * The SVG of an icon reference. `color` (or else the reference's own color, or white) fills
12
+ * whatever the icon draws in the current color; multicolor icons keep their colors.
13
13
  * `undefined` when there is no such icon.
14
14
  */
15
15
  export async function iconSvg(ref: string, color?: string): Promise<string | undefined> {
@@ -19,7 +19,7 @@ export async function iconSvg(ref: string, color?: string): Promise<string | und
19
19
  if (!component) return undefined;
20
20
  const wanted = color && HEX.test(color) ? color : (parsed.color ?? "#ffffff");
21
21
  const markup = renderToStaticMarkup(createElement(component, { size: SIZE, color: wanted }));
22
- // Standalone images have no surrounding text colour to inherit.
22
+ // Standalone images have no surrounding text color to inherit.
23
23
  const filled = markup.replaceAll("currentColor", wanted);
24
24
  return filled.includes("xmlns=")
25
25
  ? filled