@ai-matrx/icons

中文文档
0.3.96发布于 2026/10/28MITTypeScriptESM + CJS近 30 天下载 7.7万

The AI Matrx icon resolver: turn any icon NAME into a rendered component — a curated static map of ~140 hot Lucide icons for zero-latency hits, a validated dynamic import for the rest of the Lucide catalog, a module-level cache, kebab/PascalCase name norm

原始使用文档
文档目录4 节
  1. Usage
  2. Registering your app's SVG assets
  3. Keeping your own hot icons synchronous
  4. Design

@ai-matrx/icons

Turn any icon name into a rendered component. One resolver, four sources, zero flash-of-nothing:

  • A curated static map of ~140 hot Lucide icons — a hit renders synchronously, no dynamic-import latency. The map is exported (staticLucideIconMap) and extensible (extendStaticIcons).
  • The full Lucide catalog via a validated dynamic import("lucide-react") — resolved once, cached at module level, with the export checked to actually be a renderable component before it is ever rendered.
  • Curated brand icons from the react-icons optional dependency — installed by default, lazy-imported on first use; when react-icons is absent (install with --omit=optional, or a failed optional install) the resolver degrades to the fallback icon instead of failing. lucide-react itself is a real dependency — the package carries its own catalog; react is the only peer.
  • Your own SVG assets via svg: ids — an injectable registry maps svg:icons/Home → /icons/Home.svg and renders an <img>; you register your app's asset paths once at startup.

While a dynamic icon loads, the fallback icon (default Zap) renders in its place — the layout never jumps and nothing flashes empty.

npm install @ai-matrx/icons lucide-react
# optional, for the curated brand icons (FcGoogle, FaBrave, …):
npm install react-icons

Peers: react >= 18, lucide-react >= 0.400.0, and optionally react-icons >= 5.

Usage

import { IconResolver, DynamicIcon, getIconComponent, renderIcon } from "@ai-matrx/icons";

// The unified component — static, dynamic, custom, and svg: names all work:
<IconResolver iconName="AlarmClock" className="h-4 w-4" />

// Color/size convenience wrapper (Tailwind color names or hex):
<DynamicIcon name="Home" color="blue" size={5} />
<DynamicIcon name="Home" color="#ff6600" size={5} />

// Synchronous lookup (static map + already-cached icons only; always returns a component):
const Icon = getIconComponent("Settings");

// Direct element render:
{renderIcon("Check", { className: "h-4 w-4" })}

Existence checks (never infer existence from getIconComponent, which always returns a component): isIconRegisteredSync(name) for the synchronous registries, await isRegisteredOrLucideIconName(name) for the full check including the Lucide catalog.

Name normalization for user-typed/pasted input: collectLucideIconNameCandidates("alarm-clock") → ["alarm-clock", "Alarm-clock", "AlarmClock"], and extractLucideJsxIconName("<BugPlay />") → "BugPlay" — validate candidates with isRegisteredOrLucideIconName.

Icon pickers: getCuratedIconIdsForPicker() returns the finite, sorted set of every static Lucide name, curated brand id, and registered svg: id.

Registering your app's SVG assets

The package ships with an empty svg: registry — register your public asset paths once at startup (any module that runs before icons render):

import { registerSvgIcons } from "@ai-matrx/icons";

registerSvgIcons({
  "icons/Home": "/icons/Home.svg",
  "icons/brands/microsoft": "/icons/brands/microsoft.svg",
  "icons/copy": "/icons/copy.svg",
  "icons/hamburger": "/icons/hamburger.svg",
  "icons/loading-circle": "/icons/loading-circle.svg",
  "icons/logo": "/icons/logo.svg",
  "icons/play": "/icons/play.svg",
  "icons/share": "/icons/share.svg",
  "icons/three-dots": "/icons/three-dots.svg",
  "matrx/matrx-icon": "/matrx/matrx-icon.svg",
  "matrx/matrx-icon-blue": "/matrx/matrx-icon-blue.svg",
  "matrx/matrx-icon-cyan": "/matrx/matrx-icon-cyan.svg",
  "matrx/matrx-icon-green": "/matrx/matrx-icon-green.svg",
  "matrx/matrx-icon-indigo": "/matrx/matrx-icon-indigo.svg",
  "matrx/matrx-icon-orange": "/matrx/matrx-icon-orange.svg",
  "matrx/matrx-icon-pink": "/matrx/matrx-icon-pink.svg",
  "matrx/matrx-icon-purple": "/matrx/matrx-icon-purple.svg",
  "matrx/matrx-icon-slate": "/matrx/matrx-icon-slate.svg",
  "matrx/matrx-icon-teal": "/matrx/matrx-icon-teal.svg",
  "matrx/matrx-icon-yellow": "/matrx/matrx-icon-yellow.svg",
  "matrx/matrx-imagen-logo-text": "/matrx/matrx-imagen-logo-text.svg",
  "matrx/safari-pinned-tab": "/matrx/safari-pinned-tab.svg",
  "dark-turbulence-noise": "/dark-turbulence-noise.svg",
});

Then <IconResolver iconName="svg:matrx/matrx-icon" size={24} /> renders <img src="/matrx/matrx-icon.svg" …>. Calls merge, so features can register their own ids independently. An unregistered svg: id falls back like any unknown name.

Keeping your own hot icons synchronous

import { BrainCircuit } from "lucide-react";
import { extendStaticIcons } from "@ai-matrx/icons";

extendStaticIcons({ BrainCircuit }); // now a zero-latency static hit everywhere

Design

  • The static map + validated dynamic import + module cache + fallback-while-loading architecture is the product; the curated hot set ships in the package.
  • react-icons is optional by construction: it is only ever loaded lazily, and every path degrades to the fallback icon when it is absent.
  • Class names in helpers (getTextColorClass, DynamicIcon sizing) are Tailwind-shaped strings; the package ships no CSS.
  • ESM + CommonJS conditions with matching declarations, proven from the packed tarball, "use client" stamped on every built chunk.

MIT © AI Matrx

版本与发布记录

@ai-matrx/icons 共发布 110 个版本,首次发布于 2026/08/29;过去 12 个月发布了 110 个版本。

版本发布日期距今
0.3.96latest2026/10/288 天前
0.3.952026/10/288 天前
0.3.942026/10/2710 天前
0.3.932026/10/2610 天前
0.3.922026/10/2610 天前
0.3.912026/10/2611 天前

关于 @ai-matrx/icons 的常见问题

@ai-matrx/icons 是什么?

The AI Matrx icon resolver: turn any icon NAME into a rendered component — a curated static map of ~140 hot Lucide icons for zero-latency hits, a validated dynamic import for the rest of the Lucide catalog, a module-level cache, kebab/PascalCase name norm

如何安装 @ai-matrx/icons?

在项目目录运行 npm install @ai-matrx/icons,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ai-matrx/icons 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ai-matrx/icons 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ai-matrx/icons 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ai-matrx/icons 可以商用吗?

@ai-matrx/icons 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ai-matrx/icons 的下载量有多少?

根据 npm 官方下载统计,@ai-matrx/icons 在 2026/10/05 – 2026/11/03 这 30 天内被下载 77,169 次,日均约 2,572 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ai-matrx/icons 还在维护吗?

最新版本 0.3.96 发布于 2026/10/28(8 天前);至今共发布 110 个版本,其中过去 12 个月发布了 110 个;首次发布于 2026/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。