svgfusion 1.25.2 → 1.27.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.
- package/README.md +42 -613
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,661 +3,90 @@
|
|
|
3
3
|
|
|
4
4
|
# SVGFusion
|
|
5
5
|
|
|
6
|
-
**
|
|
7
|
-
|
|
8
|
-
Convert SVG files into blazing-fast React and Vue 3 components with automatic color extraction, full TypeScript support, and seamless integration into any modern workflow.
|
|
6
|
+
**Convert SVG files into React and Vue 3 components**
|
|
9
7
|
|
|
10
8
|
[](https://www.npmjs.com/package/svgfusion)
|
|
11
9
|
[](https://www.typescriptlang.org/)
|
|
12
10
|
[](https://reactjs.org/)
|
|
13
11
|
[](https://vuejs.org/)
|
|
14
12
|
|
|
15
|
-
[Documentation](https://svgfusion.netlify.app) • [CLI Reference](https://svgfusion.netlify.app/docs/cli-usage) • [
|
|
13
|
+
[Documentation](https://svgfusion.netlify.app) • [CLI Reference](https://svgfusion.netlify.app/docs/cli-usage) • [Interactive Playground](https://svgfusion.netlify.app/playground)
|
|
16
14
|
|
|
17
15
|
</div>
|
|
18
16
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
SVGFusion is now available as a monorepo with specialized packages:
|
|
22
|
-
|
|
23
|
-
- **[svgfusion](https://www.npmjs.com/package/svgfusion)** - Complete toolkit (this package)
|
|
24
|
-
- **[svgfusion-cli](https://www.npmjs.com/package/svgfusion-cli)** - Command-line interface
|
|
25
|
-
- **[svgfusion-browser](https://www.npmjs.com/package/svgfusion-browser)** - Browser-optimized package
|
|
26
|
-
- **[svgfusion-core](https://www.npmjs.com/package/svgfusion-core)** - Core engine
|
|
27
|
-
- **[svgfusion-react](https://www.npmjs.com/package/svgfusion-react)** - React utilities
|
|
28
|
-
- **[svgfusion-vue](https://www.npmjs.com/package/svgfusion-vue)** - Vue utilities
|
|
29
|
-
|
|
30
|
-
> **Note**: This package (`svgfusion`) includes everything you need. Install individual packages only if you need specific functionality.
|
|
31
|
-
|
|
32
|
-
## Features
|
|
33
|
-
|
|
34
|
-
- **Advanced Transformations**: Comprehensive transformation options including color splitting, stroke width extraction, fixed stroke width, and fill/stroke normalization
|
|
35
|
-
- **Stroke Width Splitting**: Extract and convert stroke widths to props for responsive design
|
|
36
|
-
- **Browser API**: Use SVGFusion directly in the browser with full feature support
|
|
37
|
-
- **Smart Component Naming**: Automatic prefix/suffix handling with proper PascalCase conversion
|
|
38
|
-
- **Advanced Color Splitting**: Intelligent color extraction with fill/stroke optimization
|
|
39
|
-
- **Native SVG Props**: Generated components extend React.SVGProps\<SVGSVGElement\> and Vue SVGAttributes
|
|
40
|
-
- **React & Vue Support**: Generate both React and Vue 3 components from the same SVG
|
|
41
|
-
- **Complex SVG Support**: Handles gradients, masks, filters, patterns, and Figma exports
|
|
42
|
-
- **TypeScript Ready**: Full TypeScript support with proper type definitions
|
|
43
|
-
- **Batch Processing**: Convert entire directories of SVG files
|
|
44
|
-
- **Production Ready**: Optimized output, error handling, and accessibility
|
|
45
|
-
- **Simple CLI**: Direct, intuitive command structure
|
|
46
|
-
|
|
47
|
-
## Try It Live
|
|
48
|
-
|
|
49
|
-
**Experience SVGFusion instantly in your browser!** - [**Launch Interactive Playground →**](https://svgfusion.dev/playground)
|
|
50
|
-
|
|
51
|
-
Upload your SVG files, experiment with different options, and see the generated React/Vue components in real-time. No installation required!
|
|
52
|
-
|
|
53
|
-
## Quick Start
|
|
54
|
-
|
|
55
|
-
### Simple as One Command
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
# Convert all SVG files in a directory to React components
|
|
59
|
-
npx svgfusion ./icons --output ./components
|
|
17
|
+
## What's Included
|
|
60
18
|
|
|
61
|
-
|
|
62
|
-
npx svgfusion ./icons --prefix Icon --suffix Component --index
|
|
19
|
+
This package includes everything you need for SVG to component conversion:
|
|
63
20
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
21
|
+
- **CLI Tool** - Convert SVG files from command line
|
|
22
|
+
- **Node.js API** - Programmatic conversion in Node.js
|
|
23
|
+
- **Module API** - Browser-compatible module for web apps
|
|
24
|
+
- **React & Vue Support** - Generate components for both frameworks
|
|
25
|
+
- **TypeScript Ready** - Full TypeScript support with proper types
|
|
67
26
|
|
|
68
|
-
|
|
27
|
+
## Installation
|
|
69
28
|
|
|
70
29
|
```bash
|
|
71
|
-
# Install globally (recommended for CLI usage)
|
|
72
|
-
npm install -g svgfusion
|
|
73
|
-
|
|
74
|
-
# Or use npx (no installation needed)
|
|
75
|
-
npx svgfusion ./icons --output ./components
|
|
76
|
-
|
|
77
|
-
# Or install locally for programmatic usage
|
|
78
30
|
npm install svgfusion
|
|
79
|
-
# or
|
|
80
|
-
yarn add svgfusion
|
|
81
|
-
# or
|
|
82
|
-
pnpm add svgfusion
|
|
83
31
|
```
|
|
84
32
|
|
|
85
|
-
##
|
|
86
|
-
|
|
87
|
-
<img src="https://i.ibb.co/mfRb84x/cli.png" alt="SVGFusion CLI" width="512" >
|
|
88
|
-
|
|
89
|
-
svgfusion ./icons --output ./components --prefix Icon --suffix Svg
|
|
90
|
-
|
|
91
|
-
You can add a prefix and/or suffix to the generated component names using the `--prefix` and `--suffix` options:
|
|
92
|
-
|
|
93
|
-
```sh
|
|
94
|
-
npx svgfusion ./svgs --prefix Icon --suffix Svg
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
This will generate components like `IconStarSvg`, `IconUserSvg`, etc.
|
|
98
|
-
|
|
99
|
-
Both options sanitize input to remove symbols and spaces. If omitted, no prefix/suffix is added.
|
|
100
|
-
|
|
101
|
-
#### Example
|
|
102
|
-
|
|
103
|
-
```sh
|
|
104
|
-
npx svgfusion ./svgs --prefix App --suffix Widget
|
|
105
|
-
# Output: AppStarWidget, AppUserWidget, ...
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
For more details, run:
|
|
109
|
-
|
|
110
|
-
```sh
|
|
111
|
-
npx svgfusion --help
|
|
112
|
-
```
|
|
33
|
+
## Quick Start
|
|
113
34
|
|
|
114
35
|
### CLI Usage
|
|
115
36
|
|
|
116
37
|
```bash
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
svgfusion ./icons --output ./components --framework vue
|
|
122
|
-
|
|
123
|
-
# Single file conversion with TypeScript
|
|
124
|
-
svgfusion ./star.svg --output ./components --typescript
|
|
38
|
+
# Clone the repository
|
|
39
|
+
git clone https://github.com/lolvOid/svgfusion
|
|
40
|
+
cd svgfusion
|
|
41
|
+
pnpm install
|
|
125
42
|
|
|
126
|
-
#
|
|
127
|
-
|
|
43
|
+
# Build first (required)
|
|
44
|
+
pnpm build
|
|
128
45
|
|
|
129
|
-
#
|
|
130
|
-
svgfusion
|
|
131
|
-
|
|
132
|
-
# Advanced: Split colors for maximum customization
|
|
133
|
-
svgfusion ./icons --output ./components --split-colors
|
|
134
|
-
|
|
135
|
-
# Advanced: Fixed stroke width with split colors
|
|
136
|
-
svgfusion ./icons --output ./components --split-colors --fixed-stroke-width
|
|
137
|
-
|
|
138
|
-
# Using npx (no global install needed)
|
|
139
|
-
npx svgfusion ./icons --output ./components --framework react
|
|
46
|
+
# Use the CLI
|
|
47
|
+
pnpm svgfusion icon.svg --framework react --output ./components
|
|
48
|
+
pnpm svgfusion ./icons --framework vue --typescript --output ./components
|
|
140
49
|
```
|
|
141
50
|
|
|
142
|
-
###
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
svgfusion <input> [options]
|
|
146
|
-
|
|
147
|
-
Arguments:
|
|
148
|
-
<input> SVG file or directory to convert
|
|
149
|
-
|
|
150
|
-
Options:
|
|
151
|
-
-o, --output <dir> Output directory for generated components (default: "./components")
|
|
152
|
-
-f, --framework <framework> Target framework: react or vue (default: "react")
|
|
153
|
-
--typescript Generate TypeScript components (default: true)
|
|
154
|
-
--javascript Generate JavaScript components
|
|
155
|
-
--split-colors Enable color splitting feature
|
|
156
|
-
--fixed-stroke-width Enable fixed stroke width feature
|
|
157
|
-
--memo Wrap component with React.memo (default: true)
|
|
158
|
-
--no-memo Disable React.memo wrapping
|
|
159
|
-
--forward-ref Enable forwardRef support (default: true)
|
|
160
|
-
--no-forward-ref Disable forwardRef support
|
|
161
|
-
-n, --name <name> Custom component name
|
|
162
|
-
--optimize Enable SVG optimization (default: true)
|
|
163
|
-
--no-optimize Disable SVG optimization
|
|
164
|
-
--recursive Process directories recursively
|
|
165
|
-
--prefix <prefix> Add prefix to component names
|
|
166
|
-
--suffix <suffix> Add suffix to component names
|
|
167
|
-
--index Generate index.ts file for directory processing
|
|
168
|
-
-h, --help Show help
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
--prefix `<prefix>` Add prefix to component name (sanitized)
|
|
172
|
-
--suffix `<suffix>` Add suffix to component name (sanitized)
|
|
173
|
-
--split-colors Extract individual color props for each SVG color
|
|
174
|
-
--fixed-stroke-width Add support for non-scaling stroke width
|
|
175
|
-
-h, --help Show help
|
|
176
|
-
|
|
177
|
-
````
|
|
178
|
-
|
|
179
|
-
### Using with npx (No Installation Required)
|
|
180
|
-
|
|
181
|
-
Perfect for trying out SVGFusion or one-time conversions:
|
|
182
|
-
|
|
183
|
-
```bash
|
|
184
|
-
# Convert React components
|
|
185
|
-
npx svgfusion ./assets/icons --output ./src/components/icons
|
|
186
|
-
|
|
187
|
-
# Convert Vue components with TypeScript
|
|
188
|
-
npx svgfusion ./assets/icons --output ./src/components --framework vue --typescript
|
|
189
|
-
|
|
190
|
-
# Convert single file
|
|
191
|
-
npx svgfusion ./logo.svg --output ./src/components --framework react
|
|
192
|
-
|
|
193
|
-
# Batch convert with index generation
|
|
194
|
-
npx svgfusion ./assets/icons --output ./src/components --recursive --index
|
|
195
|
-
|
|
196
|
-
# Convert with custom naming
|
|
197
|
-
npx svgfusion ./assets/icons --output ./src/components --prefix Icon --suffix Component --index
|
|
51
|
+
### Module Usage (Browser/Web Apps)
|
|
198
52
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
# Advanced: Fixed stroke width with split colors
|
|
203
|
-
npx svgfusion ./assets/icons --output ./src/components --split-colors --fixed-stroke-width
|
|
204
|
-
````
|
|
205
|
-
|
|
206
|
-
### Programmatic Usage
|
|
207
|
-
|
|
208
|
-
#### Single File Conversion
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
import { SVGFusion } from 'svgfusion';
|
|
212
|
-
|
|
213
|
-
const engine = new SVGFusion();
|
|
214
|
-
const svgContent = `<svg viewBox="0 0 24 24"><path fill="#FF0000" stroke="#00FF00" d="..."/></svg>`;
|
|
215
|
-
|
|
216
|
-
const result = await engine.convert(svgContent, {
|
|
217
|
-
framework: 'react', // or 'vue'
|
|
218
|
-
transformation: { splitColors: true },
|
|
219
|
-
generator: { componentName: 'MyIcon', typescript: true },
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
console.log(result.code); // The generated component code
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
## API Reference
|
|
226
|
-
|
|
227
|
-
For the complete API documentation, visit [svgfusion.netlify.app](https://svgfusion.netlify.app/docs/api-reference).
|
|
228
|
-
|
|
229
|
-
## Examples
|
|
230
|
-
|
|
231
|
-
### Input SVG
|
|
232
|
-
|
|
233
|
-
```svg
|
|
234
|
-
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
|
235
|
-
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
|
236
|
-
fill="currentColor" class="star-fill"/>
|
|
237
|
-
</svg>
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### Generated React Component
|
|
241
|
-
|
|
242
|
-
```tsx
|
|
243
|
-
import type { SVGProps } from 'react';
|
|
244
|
-
|
|
245
|
-
interface StarIconProps extends SVGProps<SVGSVGElement> {}
|
|
246
|
-
|
|
247
|
-
const StarIcon = (props: StarIconProps) => {
|
|
248
|
-
return (
|
|
249
|
-
<svg viewBox="0 0 24 24" {...props}>
|
|
250
|
-
<path
|
|
251
|
-
d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
|
252
|
-
fill="currentColor"
|
|
253
|
-
className="star-fill"
|
|
254
|
-
/>
|
|
255
|
-
</svg>
|
|
256
|
-
);
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
export { StarIcon };
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### Generated React Component with Color Splitting
|
|
263
|
-
|
|
264
|
-
```tsx
|
|
265
|
-
import type { SVGProps } from 'react';
|
|
266
|
-
|
|
267
|
-
interface StarIconProps extends SVGProps<SVGSVGElement> {
|
|
268
|
-
fillColor?: string;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const StarIcon = ({ fillColor = 'currentColor', ...props }: StarIconProps) => {
|
|
272
|
-
return (
|
|
273
|
-
<svg viewBox="0 0 24 24" {...props}>
|
|
274
|
-
<path
|
|
275
|
-
d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
|
276
|
-
fill={fillColor}
|
|
277
|
-
className="star-fill"
|
|
278
|
-
/>
|
|
279
|
-
</svg>
|
|
280
|
-
);
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
export { StarIcon };
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### Generated Vue Component
|
|
287
|
-
|
|
288
|
-
```vue
|
|
289
|
-
<script setup lang="ts">
|
|
290
|
-
import type { SVGAttributes } from 'vue';
|
|
291
|
-
|
|
292
|
-
interface StarIconProps extends SVGAttributes {}
|
|
293
|
-
|
|
294
|
-
defineOptions({ inheritAttrs: false });
|
|
295
|
-
</script>
|
|
296
|
-
|
|
297
|
-
<template>
|
|
298
|
-
<svg v-bind="$attrs" viewBox="0 0 24 24">
|
|
299
|
-
<path
|
|
300
|
-
d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
|
301
|
-
fill="currentColor"
|
|
302
|
-
class="star-fill"
|
|
303
|
-
/>
|
|
304
|
-
</svg>
|
|
305
|
-
</template>
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
### Generated Vue Component with Color Splitting
|
|
309
|
-
|
|
310
|
-
```vue
|
|
311
|
-
<script setup lang="ts">
|
|
312
|
-
import type { SVGAttributes } from 'vue';
|
|
53
|
+
```javascript
|
|
54
|
+
import { convertToReact, convertToVue } from 'svgfusion/browser';
|
|
313
55
|
|
|
314
|
-
|
|
315
|
-
fillColor?: string;
|
|
316
|
-
}
|
|
56
|
+
const svgCode = `<svg viewBox="0 0 24 24"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"/></svg>`;
|
|
317
57
|
|
|
318
|
-
|
|
319
|
-
|
|
58
|
+
// React component
|
|
59
|
+
const reactResult = await convertToReact(svgCode, {
|
|
60
|
+
componentName: 'StarIcon',
|
|
61
|
+
typescript: true,
|
|
62
|
+
splitColors: true,
|
|
320
63
|
});
|
|
321
64
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
<template>
|
|
326
|
-
<svg v-bind="$attrs" viewBox="0 0 24 24">
|
|
327
|
-
<path
|
|
328
|
-
d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
|
329
|
-
:fill="fillColor"
|
|
330
|
-
class="star-fill"
|
|
331
|
-
/>
|
|
332
|
-
</svg>
|
|
333
|
-
</template>
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
</script>
|
|
337
|
-
|
|
338
|
-
<template>
|
|
339
|
-
<svg v-bind="$attrs" viewBox="0 0 24 24">
|
|
340
|
-
<path
|
|
341
|
-
d="m12 2 3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01z"
|
|
342
|
-
fill="currentColor"
|
|
343
|
-
class="star-fill"
|
|
344
|
-
/>
|
|
345
|
-
</svg>
|
|
346
|
-
</template>
|
|
347
|
-
|
|
348
|
-
<style scoped>
|
|
349
|
-
/* Add component-specific styles here */
|
|
350
|
-
</style>
|
|
351
|
-
|
|
352
|
-
````
|
|
353
|
-
|
|
354
|
-
## Advanced Configuration
|
|
355
|
-
|
|
356
|
-
### Split Colors with Intelligent Attribute Handling
|
|
357
|
-
|
|
358
|
-
The `splitColors` option extracts individual color properties from SVG elements and intelligently manages fill/stroke attributes:
|
|
359
|
-
|
|
360
|
-
```typescript
|
|
361
|
-
// Input SVG with mixed attributes
|
|
362
|
-
const svgContent = `
|
|
363
|
-
<svg viewBox="0 0 24 24">
|
|
364
|
-
<path fill="#FF0000" d="..." /> <!-- Has fill only -->
|
|
365
|
-
<path stroke="#00FF00" d="..." /> <!-- Has stroke only -->
|
|
366
|
-
<path fill="#0000FF" stroke="#FFFF00" /> <!-- Has both -->
|
|
367
|
-
<path d="..." /> <!-- Has neither -->
|
|
368
|
-
</svg>
|
|
369
|
-
`;
|
|
370
|
-
|
|
371
|
-
// Convert with split colors
|
|
372
|
-
const result = await convertToReact(svgContent, {
|
|
373
|
-
name: 'MultiColorIcon',
|
|
374
|
-
splitColors: true,
|
|
65
|
+
// Vue component
|
|
66
|
+
const vueResult = await convertToVue(svgCode, {
|
|
67
|
+
componentName: 'StarIcon',
|
|
375
68
|
typescript: true,
|
|
69
|
+
splitColors: true,
|
|
376
70
|
});
|
|
377
|
-
|
|
378
|
-
// Generated component behavior:
|
|
379
|
-
// - Path with fill only: gets stroke="none" (prevents unwanted stroke)
|
|
380
|
-
// - Path with stroke only: gets fill="none" (prevents black fill default)
|
|
381
|
-
// - Path with both: keeps both as dynamic props
|
|
382
|
-
// - Path with neither: remains unchanged (no unnecessary attributes)
|
|
383
|
-
|
|
384
|
-
// Generated component props:
|
|
385
|
-
// - color, color2, color3 (for extracted colors in order)
|
|
386
|
-
// - colorClass, color2Class, color3Class (for CSS classes)
|
|
387
|
-
// - Colors are automatically converted to hex format
|
|
388
71
|
```
|
|
389
72
|
|
|
390
|
-
|
|
391
|
-
- Colors are extracted from `fill`, `stroke`, and `stop-color` attributes
|
|
392
|
-
- All colors are converted to lowercase hex format (e.g., `#ff0000`)
|
|
393
|
-
- Empty or invalid color values are ignored
|
|
394
|
-
- Duplicate colors are automatically deduplicated
|
|
395
|
-
- Colors are assigned as `color`, `color2`, `color3`, etc. in order
|
|
396
|
-
|
|
397
|
-
**Intelligent Attribute Handling:**
|
|
398
|
-
- Elements with `fill` only → adds `stroke="none"`
|
|
399
|
-
- Elements with `stroke` only → adds `fill="none"`
|
|
400
|
-
- Elements with both `fill` and `stroke` → keeps both as props
|
|
401
|
-
- Elements with neither → no attributes added
|
|
402
|
-
- Empty attribute values (`fill=""`) are treated as non-existent
|
|
403
|
-
````
|
|
404
|
-
|
|
405
|
-
### Transformation Options
|
|
73
|
+
### Node.js API
|
|
406
74
|
|
|
407
|
-
|
|
75
|
+
```javascript
|
|
76
|
+
import { SVGFusion } from 'svgfusion';
|
|
408
77
|
|
|
409
|
-
|
|
78
|
+
const engine = new SVGFusion();
|
|
410
79
|
const result = await engine.convert(svgContent, {
|
|
411
80
|
framework: 'react',
|
|
412
|
-
transformation: {
|
|
413
|
-
|
|
414
|
-
splitStrokeWidths: true, // Extract stroke width props
|
|
415
|
-
fixedStrokeWidth: true, // Non-scaling stroke support
|
|
416
|
-
normalizeFillStroke: true, // Normalize fill/stroke attributes
|
|
417
|
-
accessibility: true, // Add accessibility features
|
|
418
|
-
optimize: true, // Apply SVG optimizations
|
|
419
|
-
removeComments: true, // Remove XML comments
|
|
420
|
-
removeDuplicates: true, // Remove duplicate elements
|
|
421
|
-
minifyPaths: false, // Minify path data
|
|
422
|
-
},
|
|
423
|
-
generator: { componentName: 'MyIcon', typescript: true },
|
|
424
|
-
});
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
#### Fixed Stroke Width Support
|
|
428
|
-
|
|
429
|
-
The `fixedStrokeWidth` transformation adds support for non-scaling stroke width:
|
|
430
|
-
|
|
431
|
-
```typescript
|
|
432
|
-
const result = await convertToReact(svgContent, {
|
|
433
|
-
name: 'StrokeIcon',
|
|
434
|
-
isFixedStrokeWidth: true,
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
// Generated component includes:
|
|
438
|
-
// - isFixedStrokeWidth prop
|
|
439
|
-
// - vector-effect="non-scaling-stroke" when prop is true
|
|
440
|
-
```
|
|
441
|
-
|
|
442
|
-
#### Fill/Stroke Normalization
|
|
443
|
-
|
|
444
|
-
The `normalizeFillStroke` transformation intelligently handles fill and stroke attributes:
|
|
445
|
-
|
|
446
|
-
- Normalizes attribute values across all SVG elements
|
|
447
|
-
- Ensures consistent color and stroke width application
|
|
448
|
-
- Optimizes attribute inheritance and cascading
|
|
449
|
-
|
|
450
|
-
### Custom SVGO Configuration
|
|
451
|
-
|
|
452
|
-
```typescript
|
|
453
|
-
import { createSvgoConfig, optimizeSvg } from 'svgfusion';
|
|
454
|
-
|
|
455
|
-
const customConfig = createSvgoConfig({
|
|
456
|
-
removeViewBox: false,
|
|
457
|
-
preserveColors: true,
|
|
458
|
-
preserveClasses: true,
|
|
81
|
+
transformation: { splitColors: true },
|
|
82
|
+
generator: { typescript: true, componentName: 'MyIcon' },
|
|
459
83
|
});
|
|
460
|
-
|
|
461
|
-
const optimizedSvg = optimizeSvg(svgContent, customConfig);
|
|
462
84
|
```
|
|
463
85
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
```typescript
|
|
467
|
-
import { SVGFusion, readSvgDirectory } from 'svgfusion';
|
|
468
|
-
import { writeFileSync } from 'fs';
|
|
469
|
-
import path from 'path';
|
|
470
|
-
|
|
471
|
-
const engine = new SVGFusion();
|
|
472
|
-
const svgFiles = await readSvgDirectory('./icons', true); // recursive
|
|
473
|
-
|
|
474
|
-
for (const svgFile of svgFiles) {
|
|
475
|
-
const svgContent = readFileSync(svgFile, 'utf-8');
|
|
476
|
-
const result = await engine.convert(svgContent, {
|
|
477
|
-
framework: 'react',
|
|
478
|
-
generator: {
|
|
479
|
-
componentName: path.basename(svgFile, '.svg'),
|
|
480
|
-
typescript: true,
|
|
481
|
-
},
|
|
482
|
-
transformation: {
|
|
483
|
-
splitColors: true,
|
|
484
|
-
},
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
writeFileSync(`./components/${result.filename}`, result.code);
|
|
488
|
-
}
|
|
489
|
-
```
|
|
490
|
-
|
|
491
|
-
### Index File Generation
|
|
492
|
-
|
|
493
|
-
When using the `--index` flag or `generateIndex: true` option, SVGFusion creates an optimized index file for tree-shaking:
|
|
494
|
-
|
|
495
|
-
#### Named Exports (Default)
|
|
496
|
-
|
|
497
|
-
```typescript
|
|
498
|
-
// Auto-generated index file for tree-shaking
|
|
499
|
-
// This file exports all components for optimal bundling
|
|
86
|
+
## Documentation
|
|
500
87
|
|
|
501
|
-
|
|
502
|
-
export { default as IconUser } from './IconUser';
|
|
503
|
-
export { default as IconHome } from './IconHome';
|
|
504
|
-
|
|
505
|
-
// Barrel export for convenience
|
|
506
|
-
export { IconStar, IconUser, IconHome };
|
|
507
|
-
|
|
508
|
-
// TypeScript component types
|
|
509
|
-
export type IconComponent = React.ComponentType<React.SVGProps<SVGSVGElement>>;
|
|
510
|
-
export type IconComponents = {
|
|
511
|
-
IconStar: IconComponent;
|
|
512
|
-
IconUser: IconComponent;
|
|
513
|
-
IconHome: IconComponent;
|
|
514
|
-
};
|
|
515
|
-
```
|
|
516
|
-
|
|
517
|
-
#### Default Exports
|
|
518
|
-
|
|
519
|
-
```typescript
|
|
520
|
-
// Auto-generated index file
|
|
521
|
-
// Warning: Default exports are less tree-shakeable
|
|
522
|
-
|
|
523
|
-
import IconStar from './IconStar';
|
|
524
|
-
import IconUser from './IconUser';
|
|
525
|
-
import IconHome from './IconHome';
|
|
526
|
-
|
|
527
|
-
export default {
|
|
528
|
-
IconStar,
|
|
529
|
-
IconUser,
|
|
530
|
-
IconHome,
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
// Individual exports for flexibility
|
|
534
|
-
export { default as IconStar } from './IconStar';
|
|
535
|
-
export { default as IconUser } from './IconUser';
|
|
536
|
-
export { default as IconHome } from './IconHome';
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
#### Usage
|
|
540
|
-
|
|
541
|
-
```typescript
|
|
542
|
-
// Tree-shakeable named imports (recommended)
|
|
543
|
-
import { IconStar, IconUser } from './components';
|
|
544
|
-
|
|
545
|
-
// Default import
|
|
546
|
-
import * as Icons from './components';
|
|
547
|
-
const { IconStar, IconUser } = Icons;
|
|
548
|
-
```
|
|
549
|
-
|
|
550
|
-
## Complex Filename Support
|
|
551
|
-
|
|
552
|
-
SVGFusion handles complex filenames from design systems:
|
|
553
|
-
|
|
554
|
-
```bash
|
|
555
|
-
# Design system metadata
|
|
556
|
-
"Size=xl, Color=Brand, Type=Glass.svg" → GlassBrandXl
|
|
557
|
-
"User Profile Avatar, Type=Solid.svg" → UserProfileAvatarTypeSolid
|
|
558
|
-
|
|
559
|
-
# Standard patterns
|
|
560
|
-
"icon-star.svg" → IconStar
|
|
561
|
-
"user-profile-avatar.svg" → UserProfileAvatar
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
## Styling Support
|
|
565
|
-
|
|
566
|
-
### CSS Classes
|
|
567
|
-
|
|
568
|
-
```svg
|
|
569
|
-
<path class="primary-color" />
|
|
570
|
-
<circle class="bg-blue-500" /> <!-- Tailwind -->
|
|
571
|
-
```
|
|
572
|
-
|
|
573
|
-
### CSS Variables
|
|
574
|
-
|
|
575
|
-
```svg
|
|
576
|
-
<path fill="var(--primary-color)" />
|
|
577
|
-
<circle fill="currentColor" />
|
|
578
|
-
```
|
|
579
|
-
|
|
580
|
-
### Gradients & Patterns
|
|
581
|
-
|
|
582
|
-
```svg
|
|
583
|
-
<defs>
|
|
584
|
-
<linearGradient id="gradient">
|
|
585
|
-
<stop offset="0%" style="stop-color:#ff6b6b" />
|
|
586
|
-
<stop offset="100%" style="stop-color:#4ecdc4" />
|
|
587
|
-
</linearGradient>
|
|
588
|
-
</defs>
|
|
589
|
-
<path fill="url(#gradient)" />
|
|
590
|
-
```
|
|
591
|
-
|
|
592
|
-
## Testing
|
|
593
|
-
|
|
594
|
-
```bash
|
|
595
|
-
npm test # Run tests
|
|
596
|
-
npm run test:coverage # Run with coverage
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
## Development
|
|
600
|
-
|
|
601
|
-
```bash
|
|
602
|
-
npm run dev # Watch mode
|
|
603
|
-
npm run build # Build for production
|
|
604
|
-
npm run lint # Lint code
|
|
605
|
-
npm run format # Format code
|
|
606
|
-
```
|
|
88
|
+
For complete guides, API reference, and examples visit [svgfusion.netlify.app](https://svgfusion.netlify.app)
|
|
607
89
|
|
|
608
90
|
## License
|
|
609
91
|
|
|
610
|
-
MIT
|
|
611
|
-
|
|
612
|
-
## Contributing
|
|
613
|
-
|
|
614
|
-
Contributions are welcome! Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details.
|
|
615
|
-
|
|
616
|
-
## Changelog
|
|
617
|
-
|
|
618
|
-
See [CHANGELOG.md](./CHANGELOG.md) for details.
|
|
619
|
-
|
|
620
|
-
### Browser Usage
|
|
621
|
-
|
|
622
|
-
SVGFusion now supports browser environments! Convert SVG strings to component code without writing files.
|
|
623
|
-
|
|
624
|
-
**Try the Interactive Playground**: [svgfusion.netlify.app/playground](https://svgfusion.netlify.app/playground)
|
|
625
|
-
|
|
626
|
-
```javascript
|
|
627
|
-
import { convertToReact, convertToVue } from 'svgfusion/browser';
|
|
628
|
-
|
|
629
|
-
const svgContent = `<svg viewBox="0 0 24 24"><path fill="#3B82F6" d="..."/></svg>`;
|
|
630
|
-
|
|
631
|
-
// Convert to React component string
|
|
632
|
-
const reactResult = await convertToReact(svgContent, {
|
|
633
|
-
componentName: 'MyIcon',
|
|
634
|
-
typescript: true,
|
|
635
|
-
splitColors: true,
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
console.log(reactResult.code); // Generated React component code
|
|
639
|
-
|
|
640
|
-
// Convert to Vue component string
|
|
641
|
-
const vueResult = await convertToVue(svgContent, {
|
|
642
|
-
componentName: 'MyIcon',
|
|
643
|
-
typescript: true,
|
|
644
|
-
sfc: true,
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
console.log(vueResult.code); // Generated Vue component code
|
|
648
|
-
```
|
|
649
|
-
|
|
650
|
-
**Browser Features:**
|
|
651
|
-
|
|
652
|
-
- All conversion features (color splitting, stroke fixing, etc.)
|
|
653
|
-
- React and Vue component generation
|
|
654
|
-
- TypeScript support
|
|
655
|
-
- Batch conversion
|
|
656
|
-
- Color extraction and validation
|
|
657
|
-
- Index file generation
|
|
658
|
-
- Works in all modern browsers
|
|
659
|
-
- **Interactive Playground** with Monaco Editor
|
|
660
|
-
|
|
661
|
-
#### [Browser API Documentation](./docs/docs/browser-api.md)
|
|
662
|
-
|
|
663
|
-
#### [Node API Documentation](./docs/docs/node-api.md)
|
|
92
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svgfusion",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.27.0",
|
|
4
4
|
"description": "Convert SVG files into blazing-fast React and Vue 3 components with automatic color extraction, full TypeScript support, and seamless integration into any modern workflow.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|