@hugeicons/core-free-icons 1.2.0 → 1.2.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/README.md CHANGED
@@ -60,7 +60,7 @@ Loads the entire icon library (use when you need many icons dynamically):
60
60
  const { Home01Icon } = await import('@hugeicons/core-free-icons');
61
61
  ```
62
62
 
63
- #### 3. Dynamic Import - Individual Icons
63
+ #### 3. Dynamic Import - Individual Icons (NEW ✨)
64
64
  Loads only the specific icon you need (99% smaller bundle size):
65
65
 
66
66
  ```javascript
@@ -69,125 +69,16 @@ const icon = await import('@hugeicons/core-free-icons/Home01Icon');
69
69
  const Home01Icon = icon.default;
70
70
  ```
71
71
 
72
- #### 4. Dynamic Loader Functions (NEW ✨ Recommended)
73
- The most efficient way to load icons dynamically with built-in caching:
74
-
75
- ```javascript
76
- import { loadIcon, loadIcons } from '@hugeicons/core-free-icons/loader';
77
-
78
- // Load single icon
79
- const homeIcon = await loadIcon('Home01Icon');
80
-
81
- // Load multiple icons (parallel loading)
82
- const icons = await loadIcons(['Calendar01Icon', 'UserIcon', 'SearchIcon']);
83
-
84
- // Check if icon exists
85
- const exists = await iconExists('Home01Icon'); // true
86
- ```
87
-
88
- **Loader Benefits:**
89
- - ✅ **Automatic Caching** - Icons are cached after first load
90
- - ✅ **TypeScript Support** - Full type definitions included
91
- - ✅ **On-Demand Loading** - Only loads what you request
92
- - ✅ **Parallel Loading** - `loadIcons` loads multiple icons simultaneously
93
- - ✅ **Error Handling** - Clear error messages for missing icons
94
- - ✅ **Zero Vite Overhead** - No dev server slowdown
95
-
96
- **React Example with Loader:**
97
- ```jsx
98
- import { useState, useEffect } from 'react';
99
- import { loadIcon } from '@hugeicons/core-free-icons/loader';
100
- import { HugeiconsIcon } from '@hugeicons/react';
101
-
102
- function DynamicIcon({ iconName }) {
103
- const [icon, setIcon] = useState(null);
104
- const [loading, setLoading] = useState(true);
105
-
106
- useEffect(() => {
107
- loadIcon(iconName)
108
- .then(setIcon)
109
- .catch(console.error)
110
- .finally(() => setLoading(false));
111
- }, [iconName]);
112
-
113
- if (loading) return <div>Loading...</div>;
114
- if (!icon) return <div>Icon not found</div>;
115
-
116
- return <HugeiconsIcon icon={icon} size={24} />;
117
- }
118
- ```
119
-
120
72
  ### Performance Comparison
121
73
 
122
- | Import Method | Bundle Size | Load Time | Caching | Best For |
123
- |--------------|-------------|-----------|---------|----------|
124
- | Static Import | ~2-3KB per icon | 0ms (bundled) | N/A | Production builds |
125
- | Dynamic Full Bundle | ~5MB | 100-200ms | No | Many dynamic icons |
126
- | Dynamic Individual | ~0.75KB | 10-20ms | No | Icon pickers, lazy loading |
127
- | **Loader Functions** ⭐ | **~2KB + 0.75KB per icon** | **8-20ms** | **Yes** | **Dynamic apps, CMS, config-driven UIs** |
74
+ | Import Method | Bundle Size | Load Time | Best For |
75
+ |--------------|-------------|-----------|----------|
76
+ | Static Import | ~2-3KB per icon | 0ms (bundled) | Production builds |
77
+ | Dynamic Full Bundle | ~5MB | 100-200ms | Many dynamic icons |
78
+ | Dynamic Individual | ~0.75KB | 10-20ms | Icon pickers, lazy loading |
128
79
 
129
80
  For real-world applications, we recommend using our framework-specific packages that provide optimized components and additional features. Check out the Framework Support section below for more details.
130
81
 
131
- ## Loader API Reference
132
-
133
- The loader provides a complete API for dynamic icon management:
134
-
135
- ### Available Functions
136
-
137
- ```typescript
138
- // Load single icon with caching
139
- loadIcon(iconName: string): Promise<IconSvgObject>
140
-
141
- // Load multiple icons in parallel
142
- loadIcons(iconNames: string[]): Promise<IconSvgObject[]>
143
-
144
- // Check if an icon exists
145
- iconExists(iconName: string): Promise<boolean>
146
-
147
- // Clear icon cache
148
- clearIconCache(): void
149
-
150
- // Get cache size
151
- getCacheSize(): number
152
-
153
- // Style-specific aliases (for multi-package usage)
154
- loadIconFreeIcons(iconName: string): Promise<IconSvgObject>
155
- loadIconsFreeIcons(iconNames: string[]): Promise<IconSvgObject[]>
156
- ```
157
-
158
- ### Complete Usage Example
159
-
160
- ```javascript
161
- import {
162
- loadIcon,
163
- loadIcons,
164
- iconExists,
165
- clearIconCache,
166
- getCacheSize
167
- } from '@hugeicons/core-free-icons/loader';
168
-
169
- // Load single icon
170
- const home = await loadIcon('Home01Icon');
171
- console.log('Loaded:', home); // Array of SVG path data
172
-
173
- // Load multiple icons
174
- const [calendar, user, search] = await loadIcons([
175
- 'Calendar01Icon',
176
- 'UserIcon',
177
- 'Search01Icon'
178
- ]);
179
-
180
- // Check existence before loading
181
- if (await iconExists('Rocket01Icon')) {
182
- const rocket = await loadIcon('Rocket01Icon');
183
- }
184
-
185
- // Cache management
186
- console.log('Cached icons:', getCacheSize()); // 4
187
- clearIconCache();
188
- console.log('After clear:', getCacheSize()); // 0
189
- ```
190
-
191
82
  ## Tree-Shaking Support
192
83
 
193
84
  This package is optimized for tree-shaking with modern bundlers (Webpack, Rollup, Vite, etc.). When you import icons using the standard syntax, bundlers will automatically eliminate unused icons:
@@ -207,14 +98,12 @@ import { UserIcon, HomeIcon } from '@hugeicons/core-free-icons';
207
98
 
208
99
  ## Features
209
100
 
210
- - ⭐ **Dynamic Loader Functions**: NEW! Load icons on-demand with automatic caching
211
101
  - 🎯 **Individual Icon Imports**: Load only what you need with 99% bundle size reduction
212
102
  - 🌳 **Tree-shakeable**: Optimized for modern bundlers
213
- - 📦 **Multiple Import Methods**: Static, dynamic bundle, dynamic individual, or loader
103
+ - 📦 **Multiple Import Methods**: Static, dynamic bundle, or dynamic individual
214
104
  - 🔷 **TypeScript Support**: Full type definitions included
215
105
  - 📱 **Framework Agnostic**: Works with any JavaScript framework
216
106
  - ⚡ **Optimized Performance**: Lazy load icons on demand
217
- - 💾 **Built-in Caching**: In-memory cache for faster subsequent loads
218
107
  - 🎨 **Customizable**: Easy to style with CSS or inline styles
219
108
  - ✅ **ESM & CommonJS**: Support for both module systems
220
109
  - 🚀 **Zero Dependencies**: No external dependencies
package/dist/cjs/index.js CHANGED
@@ -29114,94 +29114,6 @@ const ZzzIcon = /*#__PURE__*/ [
29114
29114
  ["path", { d: "M14 9H20L14 15H20", stroke: "currentColor", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "1.5", key: "2" }]
29115
29115
  ];
29116
29116
 
29117
- /**
29118
- * Dynamic Icon Loader
29119
- *
29120
- * Load icons dynamically by name without importing all icons upfront.
29121
- * This is perfect for applications that need to load icons based on
29122
- * user data, CMS content, or configuration files.
29123
- *
29124
- * @example
29125
- * import { loadIcon } from '@hugeicons/core-free-icons/loader';
29126
- *
29127
- * const icon = await loadIcon('Home01Icon');
29128
- * // Use icon with @hugeicons/react or any other renderer
29129
- */
29130
-
29131
- // In-memory cache for loaded icons
29132
- const iconCache = new Map();
29133
-
29134
- /**
29135
- * Load a single icon by name
29136
- * @param iconName - The name of the icon (e.g., 'Home01Icon', 'Calendar01Icon')
29137
- * @returns Promise resolving to the icon data
29138
- * @throws Error if icon not found
29139
- */
29140
- async function loadIcon(iconName) {
29141
- // Check cache first
29142
- if (iconCache.has(iconName)) {
29143
- return iconCache.get(iconName);
29144
- }
29145
-
29146
- try {
29147
- // Dynamic import - pre-built by rollup, no overhead in dev!
29148
- // @vite-ignore tells Vite to skip static analysis
29149
- const module = await import(/* @vite-ignore */ `./${iconName}.js`);
29150
- const iconData = module.default ;
29151
-
29152
- if (!iconData) {
29153
- throw new Error(`Icon data not found for "${iconName}"`);
29154
- }
29155
-
29156
- // Cache the loaded icon
29157
- iconCache.set(iconName, iconData);
29158
-
29159
- return iconData;
29160
- } catch (error) {
29161
- throw new Error(
29162
- `Failed to load icon "${iconName}". Make sure the icon exists in this package. Error: ${error instanceof Error ? error.message : String(error)}`
29163
- );
29164
- }
29165
- }
29166
-
29167
- /**
29168
- * Load multiple icons at once
29169
- * @param iconNames - Array of icon names to load
29170
- * @returns Promise resolving to array of icon data in the same order
29171
- */
29172
- async function loadIcons(iconNames) {
29173
- return Promise.all(iconNames.map(name => loadIcon(name)));
29174
- }
29175
-
29176
- /**
29177
- * Check if an icon exists without loading it
29178
- * @param iconName - The name of the icon to check
29179
- * @returns Promise resolving to true if icon exists, false otherwise
29180
- */
29181
- async function iconExists(iconName) {
29182
- try {
29183
- await loadIcon(iconName);
29184
- return true;
29185
- } catch (e) {
29186
- return false;
29187
- }
29188
- }
29189
-
29190
- /**
29191
- * Clear the icon cache
29192
- * Useful for memory management in long-running applications
29193
- */
29194
- function clearIconCache() {
29195
- iconCache.clear();
29196
- }
29197
-
29198
- /**
29199
- * Get the number of cached icons
29200
- */
29201
- function getCacheSize() {
29202
- return iconCache.size;
29203
- }
29204
-
29205
29117
  exports.AbacusFreeIcons = AbacusIcon;
29206
29118
  exports.AbacusIcon = AbacusIcon;
29207
29119
  exports.AbsoluteFreeIcons = AbsoluteIcon;
@@ -39693,10 +39605,5 @@ exports.ZshFreeIcons = ZshIcon;
39693
39605
  exports.ZshIcon = ZshIcon;
39694
39606
  exports.ZzzFreeIcons = ZzzIcon;
39695
39607
  exports.ZzzIcon = ZzzIcon;
39696
- exports.clearIconCache = clearIconCache;
39697
- exports.getCacheSize = getCacheSize;
39698
- exports.iconExists = iconExists;
39699
39608
  exports.jarIconFreeIcons = IconjarIcon;
39700
- exports.loadIcon = loadIcon;
39701
- exports.loadIcons = loadIcons;
39702
39609
  //# sourceMappingURL=index.js.map