@hugeicons/svelte 1.0.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 ADDED
@@ -0,0 +1,240 @@
1
+ ![31c9262e-aeea-4403-9086-3c8b88885cab](https://github.com/hugeicons/hugeicons-react/assets/130147052/ff91f2f0-095a-4c6d-8942-3af4759f9021)
2
+
3
+ # @hugeicons/svelte
4
+
5
+ > HugeIcons Pro Svelte Component Library - Beautiful and customizable icons for your Svelte applications
6
+
7
+ ## What is HugeIcons?
8
+
9
+ HugeIcons is a comprehensive icon library designed for modern web and mobile applications. The free package includes 4,000+ carefully crafted icons in the Stroke Rounded style, while the pro version offers over 36,000 icons across 9 unique styles.
10
+
11
+ ### Key Highlights
12
+ - **4,000+ Free Icons**: Extensive collection of Stroke Rounded icons covering essential UI elements, actions, and concepts
13
+ - **Pixel Perfect**: Every icon is crafted on a 24x24 pixel grid ensuring crisp, clear display at any size
14
+ - **Customizable**: Easily adjust colors, sizes, and styles to match your design needs
15
+ - **Regular Updates**: New icons added regularly to keep up with evolving design trends
16
+
17
+ > 📚 **Looking for Pro Icons?** Check out our comprehensive documentation at [docs.hugeicons.com](https://docs.hugeicons.com) for detailed information about pro icons, styles, and advanced usage.
18
+
19
+ ![a40aa766-1b04-4a2a-a2e6-0ec3c492b96a](https://github.com/hugeicons/hugeicons-react/assets/130147052/f82c0e0e-60ae-4617-802f-812cdc7a58da)
20
+
21
+ ## Table of Contents
22
+ - [What is HugeIcons?](#what-is-hugeicons)
23
+ - [Features](#features)
24
+ - [Installation](#installation)
25
+ - [Usage](#usage)
26
+ - [Props](#props)
27
+ - [Examples](#examples)
28
+ - [Basic Usage](#basic-usage)
29
+ - [Custom Size and Color](#custom-size-and-color)
30
+ - [Interactive Examples](#interactive-examples)
31
+ - [Performance](#performance)
32
+ - [Troubleshooting](#troubleshooting)
33
+ - [Browser Support](#browser-support)
34
+ - [Related Packages](#related-packages)
35
+ - [Pro Version](#pro-version)
36
+ - [License](#license)
37
+ - [Related](#related)
38
+
39
+ ## Features
40
+
41
+ - 🎨 Customizable colors and sizes
42
+ - 💪 TypeScript support with full type definitions
43
+ - 🎯 Tree-shakeable for optimal bundle size
44
+ - 📦 Multiple bundle formats (ESM, CJS, UMD)
45
+ - âš¡ Lightweight and optimized
46
+ - 🔄 Alternate icon support for dynamic interactions
47
+
48
+ ## Installation
49
+
50
+ ```bash
51
+ # Using npm
52
+ npm install @hugeicons/svelte @hugeicons/core-free-icons
53
+
54
+ # Using yarn
55
+ yarn add @hugeicons/svelte @hugeicons/core-free-icons
56
+
57
+ # Using pnpm
58
+ pnpm add @hugeicons/svelte @hugeicons/core-free-icons
59
+
60
+ # Using bun
61
+ bun add @hugeicons/svelte @hugeicons/core-free-icons
62
+ ```
63
+
64
+ ## Usage
65
+
66
+ ```svelte
67
+ <script>
68
+ import { HugeiconsIcon } from '@hugeicons/svelte';
69
+ import { SearchIcon } from '@hugeicons/core-free-icons';
70
+ </script>
71
+
72
+ <HugeiconsIcon
73
+ icon={SearchIcon}
74
+ size={24}
75
+ color="currentColor"
76
+ strokeWidth={1.5}
77
+ />
78
+ ```
79
+
80
+ ## Props
81
+
82
+ | Prop | Type | Default | Description |
83
+ |------|------|---------|-------------|
84
+ | `icon` | `IconType` | Required | The main icon to display |
85
+ | `altIcon` | `IconType` | - | Alternative icon that can be used for states, interactions, animations, or dynamic icon swapping |
86
+ | `showAlt` | `boolean` | `false` | When true, displays the altIcon instead of the main icon |
87
+ | `size` | `number` | `24` | Icon size in pixels |
88
+ | `color` | `string` | `currentColor` | Icon color (CSS color value) |
89
+ | `strokeWidth` | `number` | `1.5` | Width of the icon strokes (works with stroke-style icons) |
90
+ | `absoluteStrokeWidth` | `boolean` | `false` | When true, strokeWidth will be absolute and won't scale with the icon size |
91
+ | `class` | `string` | - | Additional CSS classes |
92
+
93
+ ## Examples
94
+
95
+ ### Basic Usage
96
+ ```svelte
97
+ <script>
98
+ import { HugeiconsIcon } from '@hugeicons/svelte';
99
+ import { SearchIcon } from '@hugeicons/core-free-icons';
100
+ </script>
101
+
102
+ <HugeiconsIcon icon={SearchIcon} />
103
+ ```
104
+
105
+ ### Custom Size and Color
106
+ ```svelte
107
+ <script>
108
+ import { HugeiconsIcon } from '@hugeicons/svelte';
109
+ import { NotificationIcon } from '@hugeicons/core-free-icons';
110
+ </script>
111
+
112
+ <HugeiconsIcon
113
+ icon={NotificationIcon}
114
+ size={32}
115
+ color="#FF5733"
116
+ />
117
+ ```
118
+
119
+ ### Interactive Examples
120
+
121
+ #### Search Bar with Clear Button
122
+ ```svelte
123
+ <script>
124
+ import { HugeiconsIcon } from '@hugeicons/svelte';
125
+ import { SearchIcon, CloseCircleIcon } from '@hugeicons/core-free-icons';
126
+
127
+ let value = '';
128
+ </script>
129
+
130
+ <div>
131
+ <input
132
+ type="text"
133
+ bind:value
134
+ placeholder="Search..."
135
+ />
136
+ <HugeiconsIcon
137
+ icon={SearchIcon}
138
+ altIcon={CloseCircleIcon}
139
+ showAlt={value.length > 0}
140
+ on:click={() => value.length > 0 && (value = '')}
141
+ />
142
+ </div>
143
+ ```
144
+
145
+ #### Theme Toggle
146
+ ```svelte
147
+ <script>
148
+ import { HugeiconsIcon } from '@hugeicons/svelte';
149
+ import { SunIcon, MoonIcon } from '@hugeicons/core-free-icons';
150
+
151
+ let isDark = false;
152
+ </script>
153
+
154
+ <button on:click={() => isDark = !isDark}>
155
+ <HugeiconsIcon
156
+ icon={SunIcon}
157
+ altIcon={MoonIcon}
158
+ showAlt={isDark}
159
+ />
160
+ </button>
161
+ ```
162
+
163
+ #### Menu Toggle
164
+ ```svelte
165
+ <script>
166
+ import { HugeiconsIcon } from '@hugeicons/svelte';
167
+ import { MenuIcon, CancelIcon } from '@hugeicons/core-free-icons';
168
+
169
+ let isOpen = false;
170
+ </script>
171
+
172
+ <button on:click={() => isOpen = !isOpen}>
173
+ <HugeiconsIcon
174
+ icon={MenuIcon}
175
+ altIcon={CancelIcon}
176
+ showAlt={isOpen}
177
+ />
178
+ </button>
179
+ ```
180
+
181
+ ## Performance
182
+
183
+ - **Tree-shaking**: The package is fully tree-shakeable, ensuring only the icons you use are included in your final bundle
184
+ - **Optimized SVGs**: All icons are optimized for size and performance
185
+ - **Code Splitting**: Icons can be easily code-split when using dynamic imports
186
+
187
+ ## Troubleshooting
188
+
189
+ ### Common Issues
190
+
191
+ 1. **Icons not showing up?**
192
+ - Make sure you've installed both `@hugeicons/svelte` and `@hugeicons/core-free-icons`
193
+ - Check that the icon names are correctly imported
194
+
195
+ 2. **TypeScript errors?**
196
+ - Ensure your `tsconfig.json` includes the necessary type definitions
197
+ - Check that you're using the latest version of the package
198
+
199
+ 3. **Bundle size concerns?**
200
+ - Use named imports instead of importing the entire icon set
201
+ - Implement code splitting for different sections of your app
202
+
203
+ ## Browser Support
204
+
205
+ The library supports all modern browsers.
206
+
207
+ ## Related Packages
208
+
209
+ - [@hugeicons/react](https://www.npmjs.com/package/@hugeicons/react) - React component
210
+ - [@hugeicons/vue](https://www.npmjs.com/package/@hugeicons/vue) - Vue component
211
+ - [@hugeicons/angular](https://www.npmjs.com/package/@hugeicons/angular) - Angular component
212
+ - [@hugeicons/react-native](https://www.npmjs.com/package/@hugeicons/react-native) - React Native component
213
+
214
+ ## Pro Version
215
+
216
+ > 🌟 **Want access to 36,000+ icons and 9 unique styles?**
217
+ > Check out our [Pro Version](https://hugeicons.com/pricing) and visit [docs.hugeicons.com](https://docs.hugeicons.com) for comprehensive documentation.
218
+
219
+ ### Available Pro Styles
220
+ - **Stroke Styles**
221
+ - Stroke Rounded (`@hugeicons-pro/core-stroke-rounded`)
222
+ - Stroke Sharp (`@hugeicons-pro/core-stroke-sharp`)
223
+ - Stroke Standard (`@hugeicons-pro/core-stroke-standard`)
224
+ - **Solid Styles**
225
+ - Solid Rounded (`@hugeicons-pro/core-solid-rounded`)
226
+ - Solid Sharp (`@hugeicons-pro/core-solid-sharp`)
227
+ - Solid Standard (`@hugeicons-pro/core-solid-standard`)
228
+ - **Special Styles**
229
+ - Bulk Rounded (`@hugeicons-pro/core-bulk-rounded`)
230
+ - Duotone Rounded (`@hugeicons-pro/core-duotone-rounded`)
231
+ - Twotone Rounded (`@hugeicons-pro/core-twotone-rounded`)
232
+
233
+ ## License
234
+
235
+ This project is licensed under the [MIT License](LICENSE.md).
236
+
237
+ ## Related
238
+
239
+ - [@hugeicons/core-free-icons](https://www.npmjs.com/package/@hugeicons/core-free-icons) - Free icon package
240
+ - [HugeIcons Website](https://hugeicons.com) - Browse all available icons
@@ -0,0 +1,42 @@
1
+ <script lang="ts">import { onMount } from 'svelte';
2
+ import { createHugeiconSingleton } from '../create-hugeicon-singleton';
3
+ let props = $props();
4
+ let svgElement;
5
+ let hugeiconAction = $state();
6
+ let cleanup = $state();
7
+ const propsForUpdate = $derived({
8
+ size: props.size ?? 24,
9
+ strokeWidth: props.strokeWidth,
10
+ absoluteStrokeWidth: props.absoluteStrokeWidth ?? false,
11
+ color: props.color ?? 'currentColor',
12
+ altIcon: props.altIcon,
13
+ showAlt: props.showAlt ?? false,
14
+ class: props.className ?? ''
15
+ });
16
+ onMount(() => {
17
+ if (!svgElement)
18
+ return;
19
+ hugeiconAction = createHugeiconSingleton('HugeiconsIcon', props.icon);
20
+ cleanup = hugeiconAction.render(svgElement, propsForUpdate);
21
+ return () => {
22
+ cleanup?.destroy();
23
+ };
24
+ });
25
+ $effect(() => {
26
+ if (hugeiconAction && svgElement && cleanup) {
27
+ cleanup.update(propsForUpdate);
28
+ }
29
+ });
30
+ </script>
31
+
32
+ <svg
33
+ bind:this={svgElement}
34
+ xmlns="http://www.w3.org/2000/svg"
35
+ width={props.size ?? 24}
36
+ height={props.size ?? 24}
37
+ viewBox="0 0 24 24"
38
+ fill="none"
39
+ class={props.className}
40
+ >
41
+ <!-- SVG content will be managed by the action -->
42
+ </svg>
@@ -0,0 +1,14 @@
1
+ import type { IconSvgElement } from '../create-hugeicon-singleton';
2
+ type $$ComponentProps = {
3
+ icon: IconSvgElement;
4
+ altIcon?: IconSvgElement;
5
+ size?: string | number;
6
+ strokeWidth?: number;
7
+ absoluteStrokeWidth?: boolean;
8
+ color?: string;
9
+ showAlt?: boolean;
10
+ className?: string;
11
+ };
12
+ declare const HugeiconsIcon: import("svelte").Component<$$ComponentProps, {}, "">;
13
+ type HugeiconsIcon = ReturnType<typeof HugeiconsIcon>;
14
+ export default HugeiconsIcon;
@@ -0,0 +1,18 @@
1
+ export type IconSvgElement = readonly (readonly [string, {
2
+ readonly [key: string]: string | number;
3
+ }])[];
4
+ export interface HugeiconsProps extends Record<string, any> {
5
+ size?: string | number;
6
+ strokeWidth?: number;
7
+ absoluteStrokeWidth?: boolean;
8
+ color?: string;
9
+ class?: string;
10
+ altIcon?: IconSvgElement;
11
+ showAlt?: boolean;
12
+ }
13
+ export declare function createHugeiconSingleton(iconName: string, svgElements: IconSvgElement): {
14
+ render(node: SVGSVGElement, props: HugeiconsProps): {
15
+ update(newProps: HugeiconsProps): void;
16
+ destroy(): void;
17
+ };
18
+ };
@@ -0,0 +1,57 @@
1
+ const defaultAttributes = {
2
+ xmlns: 'http://www.w3.org/2000/svg',
3
+ width: 24,
4
+ height: 24,
5
+ viewBox: '0 0 24 24',
6
+ fill: 'none',
7
+ };
8
+ export function createHugeiconSingleton(iconName, svgElements) {
9
+ const renderIcon = (node, props) => {
10
+ const { color = 'currentColor', size = 24, strokeWidth, absoluteStrokeWidth = false, class: className = '', altIcon, showAlt = false, ...rest } = props;
11
+ const elementProps = {
12
+ ...defaultAttributes,
13
+ width: size,
14
+ height: size,
15
+ color,
16
+ class: className,
17
+ ...rest
18
+ };
19
+ const currentIcon = showAlt && altIcon ? altIcon : svgElements;
20
+ // Calculate stroke width if explicitly set
21
+ const calculatedStrokeWidth = strokeWidth !== undefined
22
+ ? (absoluteStrokeWidth ? (strokeWidth * (24 / Number(size))) : strokeWidth)
23
+ : undefined;
24
+ // Set SVG attributes
25
+ Object.entries(elementProps).forEach(([key, value]) => {
26
+ node.setAttribute(key, String(value));
27
+ });
28
+ // Clear existing content
29
+ node.innerHTML = '';
30
+ // Create and append SVG children
31
+ currentIcon.forEach(([tag, attrs]) => {
32
+ const element = document.createElementNS('http://www.w3.org/2000/svg', tag);
33
+ const updatedAttrs = { ...attrs };
34
+ if (calculatedStrokeWidth !== undefined) {
35
+ updatedAttrs['stroke-width'] = calculatedStrokeWidth;
36
+ updatedAttrs['stroke'] = 'currentColor';
37
+ }
38
+ Object.entries(updatedAttrs).forEach(([key, value]) => {
39
+ element.setAttribute(key, String(value));
40
+ });
41
+ node.appendChild(element);
42
+ });
43
+ };
44
+ return {
45
+ render(node, props) {
46
+ renderIcon(node, props);
47
+ return {
48
+ update(newProps) {
49
+ renderIcon(node, newProps);
50
+ },
51
+ destroy() {
52
+ node.innerHTML = '';
53
+ }
54
+ };
55
+ }
56
+ };
57
+ }
@@ -0,0 +1,3 @@
1
+ import HugeiconsIcon from './components/HugeiconsIcon.svelte';
2
+ export { HugeiconsIcon };
3
+ export type { IconSvgElement, HugeiconsProps } from './create-hugeicon-singleton';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import HugeiconsIcon from './components/HugeiconsIcon.svelte';
2
+ export { HugeiconsIcon };
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@hugeicons/svelte",
3
+ "version": "1.0.1",
4
+ "description": "Hugeicons component library for Svelte",
5
+ "type": "module",
6
+ "main": "./dist/index.umd.js",
7
+ "module": "./dist/index.es.js",
8
+ "types": "./dist/index.d.ts",
9
+ "svelte": "./dist/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.umd.js",
15
+ "svelte": "./dist/index.js"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "peerDependencies": {
22
+ "svelte": "^5.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@sveltejs/adapter-auto": "^4.0.0",
26
+ "@sveltejs/kit": "^2.0.0",
27
+ "@sveltejs/package": "^2.2.5",
28
+ "@sveltejs/vite-plugin-svelte": "^4.0.0-next.6",
29
+ "@tsconfig/svelte": "^5.0.2",
30
+ "svelte": "^5.0.0",
31
+ "svelte-check": "^3.6.3",
32
+ "svelte-preprocess": "^6.0.3",
33
+ "tslib": "^2.6.2",
34
+ "typescript": "^5.3.3",
35
+ "vite": "^5.0.10"
36
+ },
37
+ "keywords": [
38
+ "svelte",
39
+ "icons",
40
+ "hugeicons",
41
+ "components"
42
+ ],
43
+ "author": "Hugeicons",
44
+ "license": "MIT",
45
+ "scripts": {
46
+ "build": "vite build && pnpm run package",
47
+ "package": "svelte-kit sync && svelte-package",
48
+ "check": "svelte-check --tsconfig ./tsconfig.json"
49
+ }
50
+ }