vectify 2.0.0 → 2.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/dist/{chunk-4BWKFV7W.mjs → chunk-F3AM6WVC.mjs} +1 -1
- package/dist/cli.js +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/templates/react/component.jsx.hbs +2 -0
- package/dist/templates/react/component.tsx.hbs +3 -1
- package/dist/templates/react/createIcon.jsx.hbs +2 -0
- package/dist/templates/react/createIcon.tsx.hbs +18 -14
- package/package.json +13 -11
|
@@ -770,7 +770,7 @@ async function generateIndexFile(svgFiles, config, dryRun = false) {
|
|
|
770
770
|
const typescript = config.typescript ?? true;
|
|
771
771
|
const strategy = getFrameworkStrategy(config.framework);
|
|
772
772
|
const ext = strategy.getIndexExtension(typescript);
|
|
773
|
-
const usesDefaultExport =
|
|
773
|
+
const usesDefaultExport = ["vue", "svelte", "react", "preact"].includes(config.framework);
|
|
774
774
|
const exports = svgFiles.map((svgFile) => {
|
|
775
775
|
const fileName = path3.basename(svgFile);
|
|
776
776
|
const componentName = getComponentName(
|
package/dist/cli.js
CHANGED
|
@@ -909,7 +909,7 @@ async function generateIndexFile(svgFiles, config, dryRun = false) {
|
|
|
909
909
|
const typescript = config.typescript ?? true;
|
|
910
910
|
const strategy = getFrameworkStrategy(config.framework);
|
|
911
911
|
const ext = strategy.getIndexExtension(typescript);
|
|
912
|
-
const usesDefaultExport =
|
|
912
|
+
const usesDefaultExport = ["vue", "svelte", "react", "preact"].includes(config.framework);
|
|
913
913
|
const exports2 = svgFiles.map((svgFile) => {
|
|
914
914
|
const fileName = import_node_path3.default.basename(svgFile);
|
|
915
915
|
const componentName = getComponentName(
|
package/dist/cli.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -917,7 +917,7 @@ async function generateIndexFile(svgFiles, config, dryRun = false) {
|
|
|
917
917
|
const typescript = config.typescript ?? true;
|
|
918
918
|
const strategy = getFrameworkStrategy(config.framework);
|
|
919
919
|
const ext = strategy.getIndexExtension(typescript);
|
|
920
|
-
const usesDefaultExport =
|
|
920
|
+
const usesDefaultExport = ["vue", "svelte", "react", "preact"].includes(config.framework);
|
|
921
921
|
const exports2 = svgFiles.map((svgFile) => {
|
|
922
922
|
const fileName = import_node_path3.default.basename(svgFile);
|
|
923
923
|
const componentName = getComponentName(
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
1
3
|
{{#if typescript}}
|
|
2
4
|
import type { IconNode } from 'vectify'
|
|
3
5
|
{{/if}}
|
|
4
6
|
import { createIcon } from './createIcon'
|
|
5
7
|
|
|
6
8
|
export const iconNode{{#if typescript}}: IconNode[]{{/if}} = [
|
|
7
|
-
{{{formattedNodes}}}
|
|
9
|
+
{{{formattedNodes}}},
|
|
8
10
|
]
|
|
9
11
|
|
|
10
12
|
const {{componentName}} = createIcon('{{componentName}}', iconNode, {{keepColors}})
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import type { ForwardRefExoticComponent, ReactNode, RefAttributes, SVGProps } from 'react'
|
|
2
4
|
import type { IconNode, IconProps } from 'vectify'
|
|
3
|
-
import
|
|
5
|
+
import { createElement, forwardRef } from 'react'
|
|
4
6
|
|
|
5
7
|
export interface CreateIconProps extends IconProps, Omit<SVGProps<SVGSVGElement>, keyof IconProps> {
|
|
6
|
-
size?: number | string
|
|
7
|
-
color?: string
|
|
8
|
-
strokeWidth?: number | string
|
|
9
|
-
className?: string
|
|
10
|
-
title?: string
|
|
8
|
+
'size'?: number | string
|
|
9
|
+
'color'?: string
|
|
10
|
+
'strokeWidth'?: number | string
|
|
11
|
+
'className'?: string
|
|
12
|
+
'title'?: string
|
|
11
13
|
'aria-label'?: string
|
|
12
14
|
'aria-hidden'?: boolean | 'true' | 'false'
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
export function createIcon(name: string, iconNode: IconNode[], keepColors = false) {
|
|
17
|
+
export function createIcon(name: string, iconNode: IconNode[], keepColors = false): ForwardRefExoticComponent<CreateIconProps & RefAttributes<SVGSVGElement>> {
|
|
16
18
|
const Icon = forwardRef<SVGSVGElement, CreateIconProps>(({
|
|
17
19
|
size = 24,
|
|
18
20
|
color = 'currentColor',
|
|
@@ -56,7 +58,7 @@ function renderIconNode(
|
|
|
56
58
|
nodes: IconNode[],
|
|
57
59
|
keepColors: boolean,
|
|
58
60
|
color: string,
|
|
59
|
-
strokeWidth: number | string
|
|
61
|
+
strokeWidth: number | string,
|
|
60
62
|
): ReactNode {
|
|
61
63
|
return nodes.map((node, index) => {
|
|
62
64
|
const [type, attrs, children] = node
|
|
@@ -65,7 +67,8 @@ function renderIconNode(
|
|
|
65
67
|
|
|
66
68
|
if (keepColors) {
|
|
67
69
|
cleanedAttrs = attrs
|
|
68
|
-
}
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
69
72
|
// Track color attributes to determine icon type
|
|
70
73
|
let hasFill = false
|
|
71
74
|
let hasStroke = false
|
|
@@ -86,14 +89,15 @@ function renderIconNode(
|
|
|
86
89
|
// Keep non-color attributes
|
|
87
90
|
cleanedAttrs = Object.fromEntries(
|
|
88
91
|
Object.entries(attrs).filter(([key]) =>
|
|
89
|
-
!['stroke', 'fill', 'strokeWidth', 'stroke-width'].includes(key)
|
|
90
|
-
)
|
|
92
|
+
!['stroke', 'fill', 'strokeWidth', 'stroke-width'].includes(key),
|
|
93
|
+
),
|
|
91
94
|
)
|
|
92
95
|
|
|
93
96
|
// Apply color based on original attributes
|
|
94
97
|
if (hasFill) {
|
|
95
98
|
cleanedAttrs.fill = color
|
|
96
|
-
}
|
|
99
|
+
}
|
|
100
|
+
else if (hasStroke) {
|
|
97
101
|
cleanedAttrs.fill = 'none'
|
|
98
102
|
cleanedAttrs.stroke = color
|
|
99
103
|
cleanedAttrs.strokeWidth = originalStrokeWidth ?? strokeWidth
|
|
@@ -108,7 +112,7 @@ function renderIconNode(
|
|
|
108
112
|
return createElement(
|
|
109
113
|
type,
|
|
110
114
|
props,
|
|
111
|
-
renderIconNode(children, keepColors, color, strokeWidth)
|
|
115
|
+
renderIconNode(children, keepColors, color, strokeWidth),
|
|
112
116
|
)
|
|
113
117
|
}
|
|
114
118
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vectify",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"packageManager": "pnpm@9.15.9",
|
|
4
5
|
"description": "A powerful command-line tool to generate React, Vue, and Svelte icon components from SVG files",
|
|
5
6
|
"author": "Xiaobing Zhu <hellozxb252@gmail.com>",
|
|
6
7
|
"license": "MIT",
|
|
@@ -44,6 +45,16 @@
|
|
|
44
45
|
"engines": {
|
|
45
46
|
"node": ">=18.0.0"
|
|
46
47
|
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"dev": "tsup --watch",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"lint:fix": "eslint . --fix",
|
|
55
|
+
"prepublishOnly": "pnpm build",
|
|
56
|
+
"clean": "rm -rf dist"
|
|
57
|
+
},
|
|
47
58
|
"dependencies": {
|
|
48
59
|
"chalk": "^5.3.0",
|
|
49
60
|
"cheerio": "^1.1.2",
|
|
@@ -65,14 +76,5 @@
|
|
|
65
76
|
"tsup": "^8.5.1",
|
|
66
77
|
"typescript": "^5.9.3",
|
|
67
78
|
"vitest": "^4.0.17"
|
|
68
|
-
},
|
|
69
|
-
"scripts": {
|
|
70
|
-
"build": "tsup",
|
|
71
|
-
"dev": "tsup --watch",
|
|
72
|
-
"test": "vitest run",
|
|
73
|
-
"test:watch": "vitest",
|
|
74
|
-
"lint": "eslint .",
|
|
75
|
-
"lint:fix": "eslint . --fix",
|
|
76
|
-
"clean": "rm -rf dist"
|
|
77
79
|
}
|
|
78
|
-
}
|
|
80
|
+
}
|