@ai-matrx/icons 0.1.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,178 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+
4
+ /**
5
+ * Props every icon component in this registry accepts. Structural on purpose:
6
+ * the registry holds Lucide's ForwardRefExoticComponent icons AND (when the host
7
+ * installs the optional `react-icons` peer) react-icons' function components,
8
+ * without this package's public types depending on either library's type exports.
9
+ */
10
+ interface IconRenderProps {
11
+ className?: string;
12
+ size?: string | number;
13
+ style?: React.CSSProperties;
14
+ color?: string;
15
+ strokeWidth?: string | number;
16
+ }
17
+ /**
18
+ * The one component shape this registry stores and renders. Lucide icons are
19
+ * assignable as-is; lazily loaded react-icons components are cast on entry.
20
+ */
21
+ type IconComponentType = React.ComponentType<IconRenderProps>;
22
+
23
+ declare const staticLucideIconMap: Record<string, IconComponentType>;
24
+ /**
25
+ * Extend the static (synchronous, zero-latency) icon map with host-supplied
26
+ * components — extra statically imported Lucide icons a host uses on hot paths,
27
+ * or any component matching {@link IconComponentType}. Merges in place; later
28
+ * registrations override earlier entries of the same name.
29
+ */
30
+ declare function extendStaticIcons(map: Record<string, IconComponentType>): void;
31
+
32
+ /**
33
+ * Curated brand/custom icon names served from the OPTIONAL `react-icons` peer.
34
+ *
35
+ * Coupling inversion vs. the original (which statically imported react-icons):
36
+ * `react-icons` is an optional peerDependency, so these are lazy-imported on first
37
+ * use and cached at module level. When the host has not installed `react-icons`,
38
+ * loading degrades to null and the resolver renders the fallback icon instead —
39
+ * no install-time or import-time failure.
40
+ */
41
+
42
+ /** True when `name` is one of the curated custom (react-icons) ids. */
43
+ declare function isCustomIconName(name: string): boolean;
44
+ /** The curated custom icon ids (known without loading react-icons). */
45
+ declare function listCustomIconNames(): string[];
46
+ /**
47
+ * Lazy-load a curated custom icon from the optional `react-icons` peer.
48
+ * Returns null for unknown names, a missing export, or when `react-icons`
49
+ * is not installed — the caller degrades to the fallback icon.
50
+ */
51
+ declare function loadCustomIcon(name: string): Promise<IconComponentType | null>;
52
+
53
+ /**
54
+ * Register (or override) `svg:` icon ids → asset URLs. Merges into the module-level
55
+ * registry, so multiple calls compose. Ids are stored without the `svg:` prefix.
56
+ */
57
+ declare function registerSvgIcons(map: Record<string, string>): void;
58
+ /** The registered asset URL for a `svg:…` icon value, or null when not a registered svg icon. */
59
+ declare function parseSvgIconPath(value: string): string | null;
60
+ /** True if `value` is a `svg:…` id with a registered asset path. */
61
+ declare function isSvgIconValue(value: string | null | undefined): boolean;
62
+ /** Every registered svg icon value, `svg:` prefix included (for pickers/galleries). */
63
+ declare function listSvgIconValues(): string[];
64
+
65
+ /**
66
+ * Lucide.dev lists icons in kebab-case (e.g. `alarm-clock`); the React package
67
+ * exports PascalCase (`AlarmClock`). Normalize pasted / typed names into candidates
68
+ * to validate against `lucide-react` exports.
69
+ */
70
+ /**
71
+ * If the user pasted Lucide's JSX snippet (e.g. `'<BugPlay />'` or `<AlignCenterHorizontal />`),
72
+ * return the component name only. Otherwise return null.
73
+ *
74
+ * Supports optional outer quotes and optional attributes before the closing `/>`.
75
+ */
76
+ declare function extractLucideJsxIconName(raw: string): string | null;
77
+ /** `alarm-clock` → `AlarmClock`, `a-arrow-down` → `AArrowDown` */
78
+ declare function kebabCaseToLucidePascalCase(raw: string): string;
79
+ /**
80
+ * Ordered unique candidates: exact input, first-letter fix, kebab → Pascal variants.
81
+ * Skip Lucide heuristics for `svg:…` asset values (caller should pass only those as `[trimmed]`).
82
+ */
83
+ declare function collectLucideIconNameCandidates(raw: string): string[];
84
+
85
+ /**
86
+ * True if `exported` is the value of a Lucide icon entry for `name` in `import * as Lucide`.
87
+ * Does not mean the icon exists in the static resolver map — only that the lucide-react
88
+ * module exposes this name as a renderable component type.
89
+ */
90
+ declare function isLucideModuleIconExport(name: string, exported: unknown): boolean;
91
+
92
+ /**
93
+ * Finite list for a curated icon gallery: every statically bundled Lucide name,
94
+ * curated custom ids (react-icons), and all registered `svg:…` assets.
95
+ */
96
+ declare function getCuratedIconIdsForPicker(): string[];
97
+ /**
98
+ * True if this exact name maps to a known icon (static Lucide, curated custom id, or
99
+ * previously resolved dynamic Lucide cached under this key).
100
+ *
101
+ * Does not import lucide-react — use with {@link isRegisteredOrLucideIconName} for full checks.
102
+ */
103
+ declare function isIconRegisteredSync(iconName: string | null | undefined): boolean;
104
+ /**
105
+ * True if `iconName` is a real icon id: custom/static/cached, a registered `svg:…`
106
+ * asset, or a Lucide export that is a renderable component (not the fallback Zap).
107
+ *
108
+ * Prefer this over truthiness on {@link getIconComponent}, which always returns a component.
109
+ */
110
+ declare function isRegisteredOrLucideIconName(iconName: string | null | undefined): Promise<boolean>;
111
+ /**
112
+ * HOW TO ADD MORE STATIC ICONS:
113
+ *
114
+ * The curated hot set ships in the package (src/static-icons.ts). A host that
115
+ * frequently renders an icon outside the set keeps it zero-latency by statically
116
+ * importing it and registering it once at startup:
117
+ *
118
+ * import { YourIcon } from "lucide-react";
119
+ * import { extendStaticIcons } from "@ai-matrx/icons";
120
+ * extendStaticIcons({ YourIcon });
121
+ */
122
+ interface IconResolverProps {
123
+ iconName: string | null;
124
+ className?: string | undefined;
125
+ size?: number | undefined;
126
+ fallbackIcon?: string | undefined;
127
+ style?: React__default.CSSProperties | undefined;
128
+ }
129
+ /**
130
+ * IconResolver - A unified component for resolving and rendering icons by name
131
+ * Uses hybrid approach: static imports for common icons, dynamic imports for others
132
+ * Supports all lucide-react icons, curated custom icons (optional react-icons peer),
133
+ * and registered `svg:…` public assets.
134
+ */
135
+ declare const IconResolver: React__default.FC<IconResolverProps>;
136
+
137
+ /**
138
+ * Synchronous utility function for getting icon components directly
139
+ * Only works with statically imported icons plus already-loaded custom/dynamic icons.
140
+ * For dynamic Lucide icons not in the static map, use the IconResolver component instead
141
+ *
142
+ * **Always returns a component** (default/fallback Zap when unknown). Do not use the return
143
+ * value to infer whether `iconName` exists — use {@link isIconRegisteredSync} or
144
+ * {@link isRegisteredOrLucideIconName} instead.
145
+ */
146
+ declare const getIconComponent: (iconName: string | null | undefined, fallbackIcon?: string) => IconComponentType;
147
+ /**
148
+ * Renders an icon element directly with optional props
149
+ * This is the preferred method for rendering icons in JSX
150
+ */
151
+ declare const renderIcon: (iconName: string | null | undefined, props?: IconRenderProps, fallbackIcon?: string) => React__default.JSX.Element;
152
+ /**
153
+ * Utility to detect if a string is a hex color code
154
+ */
155
+ declare const isHexColor: (color: string) => boolean;
156
+ declare const getTextColorClass: (color?: string) => string | null;
157
+ /**
158
+ * Utility function for rendering an icon with color and size
159
+ * Note: This is synchronous and only works with statically imported icons
160
+ * For dynamic icons, use the DynamicIcon component instead
161
+ */
162
+ declare const getIconWithColorAndSize: (iconName: string | null, color?: string, size?: number) => React__default.JSX.Element;
163
+ /**
164
+ * Simple Icon component for direct usage with color and size support
165
+ * Uses IconResolver internally to support both static and dynamic icons
166
+ *
167
+ * Supports both Tailwind color names (e.g., "blue", "red", "zinc") and hex colors (e.g., "#ff0000", "#666")
168
+ */
169
+ interface DynamicIconProps {
170
+ name: string | null;
171
+ color?: string | undefined;
172
+ size?: number | undefined;
173
+ className?: string | undefined;
174
+ fallbackIcon?: string | undefined;
175
+ }
176
+ declare const DynamicIcon: React__default.FC<DynamicIconProps>;
177
+
178
+ export { DynamicIcon, type DynamicIconProps, type IconComponentType, type IconRenderProps, IconResolver, type IconResolverProps, collectLucideIconNameCandidates, extendStaticIcons, extractLucideJsxIconName, getCuratedIconIdsForPicker, getIconComponent, getIconWithColorAndSize, getTextColorClass, isCustomIconName, isHexColor, isIconRegisteredSync, isLucideModuleIconExport, isRegisteredOrLucideIconName, isSvgIconValue, kebabCaseToLucidePascalCase, listCustomIconNames, listSvgIconValues, loadCustomIcon, parseSvgIconPath, registerSvgIcons, renderIcon, staticLucideIconMap };
@@ -0,0 +1,178 @@
1
+ import * as React from 'react';
2
+ import React__default from 'react';
3
+
4
+ /**
5
+ * Props every icon component in this registry accepts. Structural on purpose:
6
+ * the registry holds Lucide's ForwardRefExoticComponent icons AND (when the host
7
+ * installs the optional `react-icons` peer) react-icons' function components,
8
+ * without this package's public types depending on either library's type exports.
9
+ */
10
+ interface IconRenderProps {
11
+ className?: string;
12
+ size?: string | number;
13
+ style?: React.CSSProperties;
14
+ color?: string;
15
+ strokeWidth?: string | number;
16
+ }
17
+ /**
18
+ * The one component shape this registry stores and renders. Lucide icons are
19
+ * assignable as-is; lazily loaded react-icons components are cast on entry.
20
+ */
21
+ type IconComponentType = React.ComponentType<IconRenderProps>;
22
+
23
+ declare const staticLucideIconMap: Record<string, IconComponentType>;
24
+ /**
25
+ * Extend the static (synchronous, zero-latency) icon map with host-supplied
26
+ * components — extra statically imported Lucide icons a host uses on hot paths,
27
+ * or any component matching {@link IconComponentType}. Merges in place; later
28
+ * registrations override earlier entries of the same name.
29
+ */
30
+ declare function extendStaticIcons(map: Record<string, IconComponentType>): void;
31
+
32
+ /**
33
+ * Curated brand/custom icon names served from the OPTIONAL `react-icons` peer.
34
+ *
35
+ * Coupling inversion vs. the original (which statically imported react-icons):
36
+ * `react-icons` is an optional peerDependency, so these are lazy-imported on first
37
+ * use and cached at module level. When the host has not installed `react-icons`,
38
+ * loading degrades to null and the resolver renders the fallback icon instead —
39
+ * no install-time or import-time failure.
40
+ */
41
+
42
+ /** True when `name` is one of the curated custom (react-icons) ids. */
43
+ declare function isCustomIconName(name: string): boolean;
44
+ /** The curated custom icon ids (known without loading react-icons). */
45
+ declare function listCustomIconNames(): string[];
46
+ /**
47
+ * Lazy-load a curated custom icon from the optional `react-icons` peer.
48
+ * Returns null for unknown names, a missing export, or when `react-icons`
49
+ * is not installed — the caller degrades to the fallback icon.
50
+ */
51
+ declare function loadCustomIcon(name: string): Promise<IconComponentType | null>;
52
+
53
+ /**
54
+ * Register (or override) `svg:` icon ids → asset URLs. Merges into the module-level
55
+ * registry, so multiple calls compose. Ids are stored without the `svg:` prefix.
56
+ */
57
+ declare function registerSvgIcons(map: Record<string, string>): void;
58
+ /** The registered asset URL for a `svg:…` icon value, or null when not a registered svg icon. */
59
+ declare function parseSvgIconPath(value: string): string | null;
60
+ /** True if `value` is a `svg:…` id with a registered asset path. */
61
+ declare function isSvgIconValue(value: string | null | undefined): boolean;
62
+ /** Every registered svg icon value, `svg:` prefix included (for pickers/galleries). */
63
+ declare function listSvgIconValues(): string[];
64
+
65
+ /**
66
+ * Lucide.dev lists icons in kebab-case (e.g. `alarm-clock`); the React package
67
+ * exports PascalCase (`AlarmClock`). Normalize pasted / typed names into candidates
68
+ * to validate against `lucide-react` exports.
69
+ */
70
+ /**
71
+ * If the user pasted Lucide's JSX snippet (e.g. `'<BugPlay />'` or `<AlignCenterHorizontal />`),
72
+ * return the component name only. Otherwise return null.
73
+ *
74
+ * Supports optional outer quotes and optional attributes before the closing `/>`.
75
+ */
76
+ declare function extractLucideJsxIconName(raw: string): string | null;
77
+ /** `alarm-clock` → `AlarmClock`, `a-arrow-down` → `AArrowDown` */
78
+ declare function kebabCaseToLucidePascalCase(raw: string): string;
79
+ /**
80
+ * Ordered unique candidates: exact input, first-letter fix, kebab → Pascal variants.
81
+ * Skip Lucide heuristics for `svg:…` asset values (caller should pass only those as `[trimmed]`).
82
+ */
83
+ declare function collectLucideIconNameCandidates(raw: string): string[];
84
+
85
+ /**
86
+ * True if `exported` is the value of a Lucide icon entry for `name` in `import * as Lucide`.
87
+ * Does not mean the icon exists in the static resolver map — only that the lucide-react
88
+ * module exposes this name as a renderable component type.
89
+ */
90
+ declare function isLucideModuleIconExport(name: string, exported: unknown): boolean;
91
+
92
+ /**
93
+ * Finite list for a curated icon gallery: every statically bundled Lucide name,
94
+ * curated custom ids (react-icons), and all registered `svg:…` assets.
95
+ */
96
+ declare function getCuratedIconIdsForPicker(): string[];
97
+ /**
98
+ * True if this exact name maps to a known icon (static Lucide, curated custom id, or
99
+ * previously resolved dynamic Lucide cached under this key).
100
+ *
101
+ * Does not import lucide-react — use with {@link isRegisteredOrLucideIconName} for full checks.
102
+ */
103
+ declare function isIconRegisteredSync(iconName: string | null | undefined): boolean;
104
+ /**
105
+ * True if `iconName` is a real icon id: custom/static/cached, a registered `svg:…`
106
+ * asset, or a Lucide export that is a renderable component (not the fallback Zap).
107
+ *
108
+ * Prefer this over truthiness on {@link getIconComponent}, which always returns a component.
109
+ */
110
+ declare function isRegisteredOrLucideIconName(iconName: string | null | undefined): Promise<boolean>;
111
+ /**
112
+ * HOW TO ADD MORE STATIC ICONS:
113
+ *
114
+ * The curated hot set ships in the package (src/static-icons.ts). A host that
115
+ * frequently renders an icon outside the set keeps it zero-latency by statically
116
+ * importing it and registering it once at startup:
117
+ *
118
+ * import { YourIcon } from "lucide-react";
119
+ * import { extendStaticIcons } from "@ai-matrx/icons";
120
+ * extendStaticIcons({ YourIcon });
121
+ */
122
+ interface IconResolverProps {
123
+ iconName: string | null;
124
+ className?: string | undefined;
125
+ size?: number | undefined;
126
+ fallbackIcon?: string | undefined;
127
+ style?: React__default.CSSProperties | undefined;
128
+ }
129
+ /**
130
+ * IconResolver - A unified component for resolving and rendering icons by name
131
+ * Uses hybrid approach: static imports for common icons, dynamic imports for others
132
+ * Supports all lucide-react icons, curated custom icons (optional react-icons peer),
133
+ * and registered `svg:…` public assets.
134
+ */
135
+ declare const IconResolver: React__default.FC<IconResolverProps>;
136
+
137
+ /**
138
+ * Synchronous utility function for getting icon components directly
139
+ * Only works with statically imported icons plus already-loaded custom/dynamic icons.
140
+ * For dynamic Lucide icons not in the static map, use the IconResolver component instead
141
+ *
142
+ * **Always returns a component** (default/fallback Zap when unknown). Do not use the return
143
+ * value to infer whether `iconName` exists — use {@link isIconRegisteredSync} or
144
+ * {@link isRegisteredOrLucideIconName} instead.
145
+ */
146
+ declare const getIconComponent: (iconName: string | null | undefined, fallbackIcon?: string) => IconComponentType;
147
+ /**
148
+ * Renders an icon element directly with optional props
149
+ * This is the preferred method for rendering icons in JSX
150
+ */
151
+ declare const renderIcon: (iconName: string | null | undefined, props?: IconRenderProps, fallbackIcon?: string) => React__default.JSX.Element;
152
+ /**
153
+ * Utility to detect if a string is a hex color code
154
+ */
155
+ declare const isHexColor: (color: string) => boolean;
156
+ declare const getTextColorClass: (color?: string) => string | null;
157
+ /**
158
+ * Utility function for rendering an icon with color and size
159
+ * Note: This is synchronous and only works with statically imported icons
160
+ * For dynamic icons, use the DynamicIcon component instead
161
+ */
162
+ declare const getIconWithColorAndSize: (iconName: string | null, color?: string, size?: number) => React__default.JSX.Element;
163
+ /**
164
+ * Simple Icon component for direct usage with color and size support
165
+ * Uses IconResolver internally to support both static and dynamic icons
166
+ *
167
+ * Supports both Tailwind color names (e.g., "blue", "red", "zinc") and hex colors (e.g., "#ff0000", "#666")
168
+ */
169
+ interface DynamicIconProps {
170
+ name: string | null;
171
+ color?: string | undefined;
172
+ size?: number | undefined;
173
+ className?: string | undefined;
174
+ fallbackIcon?: string | undefined;
175
+ }
176
+ declare const DynamicIcon: React__default.FC<DynamicIconProps>;
177
+
178
+ export { DynamicIcon, type DynamicIconProps, type IconComponentType, type IconRenderProps, IconResolver, type IconResolverProps, collectLucideIconNameCandidates, extendStaticIcons, extractLucideJsxIconName, getCuratedIconIdsForPicker, getIconComponent, getIconWithColorAndSize, getTextColorClass, isCustomIconName, isHexColor, isIconRegisteredSync, isLucideModuleIconExport, isRegisteredOrLucideIconName, isSvgIconValue, kebabCaseToLucidePascalCase, listCustomIconNames, listSvgIconValues, loadCustomIcon, parseSvgIconPath, registerSvgIcons, renderIcon, staticLucideIconMap };