svgfusion 1.14.0 → 1.15.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 +70 -13
- package/dist/browser.d.mts +223 -0
- package/dist/browser.mjs +141 -0
- package/dist/cli.js +472 -54
- package/dist/index.d.mts +107 -6
- package/dist/index.d.ts +107 -6
- package/dist/index.js +358 -353
- package/dist/index.mjs +358 -353
- package/package.json +7 -6
package/README.md
CHANGED
|
@@ -12,22 +12,17 @@ A powerful Node.js CLI tool and library that converts SVG files into optimized R
|
|
|
12
12
|
[](https://reactjs.org/)
|
|
13
13
|
[](https://vuejs.org/)
|
|
14
14
|
|
|
15
|
-
[
|
|
15
|
+
[Documentation](https://svgfusion.netlify.app) • [CLI Reference](https://svgfusion.netlify.app/docs/cli-usage) • [NPM](https://www.npmjs.com/package/svgfusion) • **[Try Interactive Playground →](https://svgfusion.netlify.app/playground)**
|
|
16
16
|
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
## What's New in v1.12.0
|
|
20
|
-
|
|
21
|
-
- **Enhanced Color Splitting**: Smart color extraction with intelligent fill/stroke="none" handling
|
|
22
|
-
- **Improved CLI**: Streamlined command structure with better option handling
|
|
23
|
-
- **Native SVG Props**: Full React.SVGProps and Vue SVGAttributes support
|
|
24
|
-
- **Enhanced Type Safety**: Better TypeScript integration and type inference
|
|
25
|
-
- **SVGFusion Engine**: Built-in SVG parser with reliable transformations
|
|
26
|
-
- **Better Control**: Fine-grained control over SVG transformations and output
|
|
27
|
-
|
|
28
19
|
## Features
|
|
29
20
|
|
|
30
|
-
**
|
|
21
|
+
**Stroke Width Splitting**: Extract and convert stroke widths to props for responsive design
|
|
22
|
+
**Browser API**: Use SVGFusion directly in the browser with full feature support
|
|
23
|
+
**Smart Component Naming**: Automatic prefix/suffix handling with proper PascalCase conversion
|
|
24
|
+
**Advanced Color Splitting**: Intelligent color extraction with fill/stroke optimization
|
|
25
|
+
**Native SVG Props**: Generated components extend React.SVGProps\<SVGSVGElement\> and Vue SVGAttributes
|
|
31
26
|
**React & Vue Support**: Generate both React and Vue 3 components from the same SVG
|
|
32
27
|
**Complex SVG Support**: Handles gradients, masks, filters, patterns, and Figma exports
|
|
33
28
|
**TypeScript Ready**: Full TypeScript support with proper type definitions
|
|
@@ -35,6 +30,16 @@ A powerful Node.js CLI tool and library that converts SVG files into optimized R
|
|
|
35
30
|
**Production Ready**: Optimized output, error handling, and accessibility
|
|
36
31
|
**Simple CLI**: Direct, intuitive command structure
|
|
37
32
|
|
|
33
|
+
### Stroke Width Splitting
|
|
34
|
+
|
|
35
|
+
Extract stroke widths from SVG elements and convert them to component props for responsive designs:
|
|
36
|
+
|
|
37
|
+
```jsx
|
|
38
|
+
// Original SVG: <path stroke-width="2" d="..."/>
|
|
39
|
+
// Generated React component:
|
|
40
|
+
<MyIcon strokeWidth1={4} /> // Scales the stroke width
|
|
41
|
+
```
|
|
42
|
+
|
|
38
43
|
### Color Splitting (splitColors)
|
|
39
44
|
|
|
40
45
|
Extracts all unique fill, stroke, and gradient colors from your SVG and generates props for each color and color class. Automatically adds `fill="none"` or `stroke="none"` to prevent unwanted browser defaults:
|
|
@@ -44,6 +49,14 @@ Extracts all unique fill, stroke, and gradient colors from your SVG and generate
|
|
|
44
49
|
- Path with both → keeps both as props
|
|
45
50
|
- Path with neither → stays unchanged
|
|
46
51
|
|
|
52
|
+
## Try It Live
|
|
53
|
+
|
|
54
|
+
**Experience SVGFusion instantly in your browser!**
|
|
55
|
+
|
|
56
|
+
[**Launch Interactive Playground →**](https://svgfusion.dev/playground)
|
|
57
|
+
|
|
58
|
+
Upload your SVG files, experiment with different options, and see the generated React/Vue components in real-time. No installation required!
|
|
59
|
+
|
|
47
60
|
## Quick Start
|
|
48
61
|
|
|
49
62
|
### Simple as One Command
|
|
@@ -162,8 +175,8 @@ Options:
|
|
|
162
175
|
-h, --help Show help
|
|
163
176
|
```
|
|
164
177
|
|
|
165
|
-
--prefix
|
|
166
|
-
--suffix
|
|
178
|
+
--prefix `<prefix>` Add prefix to component name (sanitized)
|
|
179
|
+
--suffix `<suffix>` Add suffix to component name (sanitized)
|
|
167
180
|
--split-colors Extract individual color props for each SVG color
|
|
168
181
|
--fixed-stroke-width Add support for non-scaling stroke width
|
|
169
182
|
-h, --help Show help
|
|
@@ -580,3 +593,47 @@ Contributions are welcome! Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for
|
|
|
580
593
|
## Changelog
|
|
581
594
|
|
|
582
595
|
See [CHANGELOG.md](./CHANGELOG.md) for details.
|
|
596
|
+
|
|
597
|
+
### Browser Usage (New!)
|
|
598
|
+
|
|
599
|
+
SVGFusion now supports browser environments! Convert SVG strings to component code without writing files.
|
|
600
|
+
|
|
601
|
+
**Try the Interactive Playground**: [svgfusion.netlify.app/playground](https://svgfusion.netlify.app/playground)
|
|
602
|
+
|
|
603
|
+
```javascript
|
|
604
|
+
import { convertToReact, convertToVue } from 'svgfusion/browser';
|
|
605
|
+
|
|
606
|
+
const svgContent = `<svg viewBox="0 0 24 24"><path fill="#3B82F6" d="..."/></svg>`;
|
|
607
|
+
|
|
608
|
+
// Convert to React component string
|
|
609
|
+
const reactResult = await convertToReact(svgContent, {
|
|
610
|
+
componentName: 'MyIcon',
|
|
611
|
+
typescript: true,
|
|
612
|
+
splitColors: true,
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
console.log(reactResult.code); // Generated React component code
|
|
616
|
+
|
|
617
|
+
// Convert to Vue component string
|
|
618
|
+
const vueResult = await convertToVue(svgContent, {
|
|
619
|
+
componentName: 'MyIcon',
|
|
620
|
+
typescript: true,
|
|
621
|
+
sfc: true,
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
console.log(vueResult.code); // Generated Vue component code
|
|
625
|
+
```
|
|
626
|
+
|
|
627
|
+
**Browser Features:**
|
|
628
|
+
|
|
629
|
+
- All conversion features (color splitting, stroke fixing, etc.)
|
|
630
|
+
- React and Vue component generation
|
|
631
|
+
- TypeScript support
|
|
632
|
+
- Batch conversion
|
|
633
|
+
- Color extraction and validation
|
|
634
|
+
- Index file generation
|
|
635
|
+
- Works in all modern browsers
|
|
636
|
+
- **Interactive Playground** with Monaco Editor
|
|
637
|
+
|
|
638
|
+
[Full Browser API Documentation](./docs/docs/browser-api.md)
|
|
639
|
+
[Full Node API Documentation](./docs/docs/node-api.md)
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core transformation engine for SVG processing
|
|
3
|
+
* Handles optimization, color manipulation, and feature application
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
interface TransformationOptions {
|
|
7
|
+
optimize?: boolean;
|
|
8
|
+
splitColors?: boolean;
|
|
9
|
+
splitStrokeWidths?: boolean;
|
|
10
|
+
fixedStrokeWidth?: boolean;
|
|
11
|
+
accessibility?: boolean;
|
|
12
|
+
removeComments?: boolean;
|
|
13
|
+
removeDuplicates?: boolean;
|
|
14
|
+
minifyPaths?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Abstract component generator base class
|
|
19
|
+
* Provides common functionality for all component generators
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
interface GeneratorOptions {
|
|
23
|
+
typescript?: boolean;
|
|
24
|
+
memo?: boolean;
|
|
25
|
+
forwardRef?: boolean;
|
|
26
|
+
exportDefault?: boolean;
|
|
27
|
+
componentName?: string;
|
|
28
|
+
prefix?: string;
|
|
29
|
+
suffix?: string;
|
|
30
|
+
includeTypes?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* React component generator
|
|
35
|
+
* Generates production-ready React components with TypeScript support
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
interface ReactGeneratorOptions extends GeneratorOptions {
|
|
39
|
+
memo?: boolean;
|
|
40
|
+
forwardRef?: boolean;
|
|
41
|
+
propTypes?: boolean;
|
|
42
|
+
defaultProps?: boolean;
|
|
43
|
+
namedExport?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Vue component generator
|
|
48
|
+
* Generates production-ready Vue 3 components with TypeScript support
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
interface VueGeneratorOptions extends GeneratorOptions {
|
|
52
|
+
composition?: boolean;
|
|
53
|
+
scriptSetup?: boolean;
|
|
54
|
+
sfc?: boolean;
|
|
55
|
+
defineComponent?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Main SVGFusion engine
|
|
60
|
+
* Orchestrates parsing, transformation, and code generation
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
interface SVGFusionOptions {
|
|
64
|
+
framework: 'react' | 'vue';
|
|
65
|
+
transformation?: TransformationOptions;
|
|
66
|
+
generator?: ReactGeneratorOptions | VueGeneratorOptions;
|
|
67
|
+
}
|
|
68
|
+
interface ConversionResult {
|
|
69
|
+
code: string;
|
|
70
|
+
filename: string;
|
|
71
|
+
componentName: string;
|
|
72
|
+
dependencies: string[];
|
|
73
|
+
metadata: {
|
|
74
|
+
originalColors: string[];
|
|
75
|
+
originalStrokeWidths: string[];
|
|
76
|
+
optimizationApplied: boolean;
|
|
77
|
+
features: string[];
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Main SVGFusion engine
|
|
82
|
+
*/
|
|
83
|
+
declare class SVGFusion {
|
|
84
|
+
private parser;
|
|
85
|
+
private transformer;
|
|
86
|
+
constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Convert SVG content to component code
|
|
89
|
+
*/
|
|
90
|
+
convert(svgContent: string, options: SVGFusionOptions): Promise<ConversionResult>;
|
|
91
|
+
/**
|
|
92
|
+
* Extract colors from SVG for preview/analysis
|
|
93
|
+
*/
|
|
94
|
+
extractColors(svgContent: string): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Validate SVG content
|
|
97
|
+
*/
|
|
98
|
+
validate(svgContent: string): {
|
|
99
|
+
valid: boolean;
|
|
100
|
+
errors: string[];
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
declare const pascalCase: (str: string) => string;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Convert SVG filename to a valid React component name
|
|
108
|
+
* @param filename - The SVG filename
|
|
109
|
+
* @returns PascalCase component name
|
|
110
|
+
*/
|
|
111
|
+
declare function svgToComponentName(filename: string, prefix?: string, suffix?: string): string;
|
|
112
|
+
declare function svgToComponentName(filename: string): string;
|
|
113
|
+
/**
|
|
114
|
+
* Sanitize component name to ensure it's valid
|
|
115
|
+
* @param name - The component name to sanitize
|
|
116
|
+
* @param type - The type of component part: 'main', 'prefix', or 'suffix'
|
|
117
|
+
* @returns Sanitized component name
|
|
118
|
+
*/
|
|
119
|
+
declare function sanitizeComponentName(name: string, type?: 'main' | 'prefix' | 'suffix'): string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Add prefix/suffix to component name with automatic hyphen separators
|
|
123
|
+
* @param name - Base component name
|
|
124
|
+
* @param prefix - Optional prefix (hyphen will be added after)
|
|
125
|
+
* @param suffix - Optional suffix (hyphen will be added before)
|
|
126
|
+
* @returns Component name with prefix/suffix in proper PascalCase
|
|
127
|
+
*/
|
|
128
|
+
declare function formatComponentName(name: string, prefix?: string, suffix?: string): string;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Browser-compatible SVGFusion API
|
|
132
|
+
* Returns converted component strings instead of writing to files
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
interface BrowserConversionOptions {
|
|
136
|
+
framework: 'react' | 'vue';
|
|
137
|
+
typescript?: boolean;
|
|
138
|
+
componentName?: string;
|
|
139
|
+
prefix?: string;
|
|
140
|
+
suffix?: string;
|
|
141
|
+
splitColors?: boolean;
|
|
142
|
+
splitStrokeWidths?: boolean;
|
|
143
|
+
fixedStrokeWidth?: boolean;
|
|
144
|
+
memo?: boolean;
|
|
145
|
+
forwardRef?: boolean;
|
|
146
|
+
sfc?: boolean;
|
|
147
|
+
scriptSetup?: boolean;
|
|
148
|
+
optimize?: boolean;
|
|
149
|
+
}
|
|
150
|
+
interface BrowserConversionResult {
|
|
151
|
+
code: string;
|
|
152
|
+
componentName: string;
|
|
153
|
+
filename: string;
|
|
154
|
+
framework: 'react' | 'vue';
|
|
155
|
+
typescript: boolean;
|
|
156
|
+
metadata: {
|
|
157
|
+
originalColors: string[];
|
|
158
|
+
optimizationApplied: boolean;
|
|
159
|
+
features: string[];
|
|
160
|
+
};
|
|
161
|
+
dependencies: string[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Browser-compatible SVGFusion class
|
|
165
|
+
*/
|
|
166
|
+
declare class SVGFusionBrowser {
|
|
167
|
+
private engine;
|
|
168
|
+
constructor();
|
|
169
|
+
/**
|
|
170
|
+
* Convert SVG content to component string (browser-compatible)
|
|
171
|
+
*/
|
|
172
|
+
convert(svgContent: string, options: BrowserConversionOptions): Promise<BrowserConversionResult>;
|
|
173
|
+
/**
|
|
174
|
+
* Extract colors from SVG (browser-compatible)
|
|
175
|
+
*/
|
|
176
|
+
extractColors(svgContent: string): string[];
|
|
177
|
+
/**
|
|
178
|
+
* Validate SVG content - focused on XML structure validation only
|
|
179
|
+
*/
|
|
180
|
+
validate(svgContent: string): {
|
|
181
|
+
valid: boolean;
|
|
182
|
+
errors: string[];
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Basic XML structure validation for critical malformed cases
|
|
186
|
+
*/
|
|
187
|
+
private validateXMLStructure;
|
|
188
|
+
/**
|
|
189
|
+
* Fallback validation using regex patterns (for Node.js environment)
|
|
190
|
+
*/
|
|
191
|
+
private validateWithRegex;
|
|
192
|
+
/**
|
|
193
|
+
* Convert multiple SVG contents to components (browser-compatible)
|
|
194
|
+
*/
|
|
195
|
+
convertBatch(svgContents: Array<{
|
|
196
|
+
content: string;
|
|
197
|
+
name: string;
|
|
198
|
+
}>, options: BrowserConversionOptions): Promise<BrowserConversionResult[]>;
|
|
199
|
+
/**
|
|
200
|
+
* Generate index file content for multiple components (browser-compatible)
|
|
201
|
+
*/
|
|
202
|
+
generateIndexFile(results: BrowserConversionResult[], options?: {
|
|
203
|
+
exportType?: 'named' | 'default';
|
|
204
|
+
typescript?: boolean;
|
|
205
|
+
}): string;
|
|
206
|
+
/**
|
|
207
|
+
* Get import path from filename
|
|
208
|
+
*/
|
|
209
|
+
private getImportPath;
|
|
210
|
+
}
|
|
211
|
+
declare function convertToReact(svgContent: string, options?: Omit<BrowserConversionOptions, 'framework'>): Promise<BrowserConversionResult>;
|
|
212
|
+
declare function convertToVue(svgContent: string, options?: Omit<BrowserConversionOptions, 'framework'>): Promise<BrowserConversionResult>;
|
|
213
|
+
declare function convertBatch(svgContents: Array<{
|
|
214
|
+
content: string;
|
|
215
|
+
name: string;
|
|
216
|
+
}>, options: BrowserConversionOptions): Promise<BrowserConversionResult[]>;
|
|
217
|
+
declare function extractColors(svgContent: string): string[];
|
|
218
|
+
declare function validateSvg(svgContent: string): {
|
|
219
|
+
valid: boolean;
|
|
220
|
+
errors: string[];
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
export { type BrowserConversionOptions, type BrowserConversionResult, type ConversionResult, type ReactGeneratorOptions, SVGFusion, SVGFusionBrowser, type SVGFusionOptions, type VueGeneratorOptions, convertBatch, convertToReact, convertToVue, extractColors, formatComponentName, pascalCase, sanitizeComponentName, svgToComponentName, validateSvg };
|