svger-cli 1.0.0 → 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.
@@ -27,20 +27,32 @@
27
27
  * console.log(componentCode);
28
28
  */
29
29
  export function reactTemplate({ componentName, svgContent, defaultWidth = 24, defaultHeight = 24, defaultFill = "currentColor", }) {
30
- const cleaned = svgContent
31
- .replace(/<\?xml.*?\?>/g, "") // Remove XML declarations
32
- .replace(/<!DOCTYPE.*?>/g, "") // Remove DOCTYPE lines
33
- .replace(/\r?\n|\r/g, "") // Remove newlines
30
+ // پاکسازی XML/DOCTYPE و حذف style های inline که React قبول نداره
31
+ let cleaned = svgContent
32
+ .replace(/<\?xml.*?\?>/g, "")
33
+ .replace(/<!DOCTYPE.*?>/g, "")
34
+ .replace(/\r?\n|\r/g, "")
35
+ .replace(/style="[^"]*"/g, "") // حذف style های inline
36
+ .replace(/\s(class|id)=["'][^"']*["']/g, "") // حذف class/id مستقیم
34
37
  .trim();
38
+ // تغییر attribute های SVG به React-compatible و اضافه کردن props
39
+ cleaned = cleaned.replace(/<svg([^>]*)>/, `<svg$1
40
+ width={width}
41
+ height={height}
42
+ fill={fill}
43
+ stroke={props.stroke || "none"}
44
+ className={props.className}
45
+ {...props}>`);
35
46
  return `import * as React from "react";
47
+ import type { SVGProps } from "react";
36
48
 
37
- export const ${componentName}: React.FC<React.SVGProps<SVGSVGElement>> = ({
49
+ export const ${componentName}: React.FC<SVGProps<SVGSVGElement>> = ({
38
50
  width = ${defaultWidth},
39
51
  height = ${defaultHeight},
40
52
  fill = "${defaultFill}",
41
53
  ...props
42
54
  }) => (
43
- ${cleaned.replace(/<svg/, `<svg width={width} height={height} fill={fill} {...props}`)}
55
+ ${cleaned}
44
56
  );
45
57
 
46
58
  export default ${componentName};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svger-cli",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "CLI and runtime for converting SVGs to React components with watch support",
5
5
  "main": "dist/cli.js",
6
6
  "type": "module",
@@ -39,24 +39,37 @@ export function reactTemplate({
39
39
  defaultHeight?: number;
40
40
  defaultFill?: string;
41
41
  }) {
42
- const cleaned = svgContent
43
- .replace(/<\?xml.*?\?>/g, "") // Remove XML declarations
44
- .replace(/<!DOCTYPE.*?>/g, "") // Remove DOCTYPE lines
45
- .replace(/\r?\n|\r/g, "") // Remove newlines
42
+ // پاکسازی XML/DOCTYPE و حذف style های inline که React قبول نداره
43
+ let cleaned = svgContent
44
+ .replace(/<\?xml.*?\?>/g, "")
45
+ .replace(/<!DOCTYPE.*?>/g, "")
46
+ .replace(/\r?\n|\r/g, "")
47
+ .replace(/style="[^"]*"/g, "") // حذف style های inline
48
+ .replace(/\s(class|id)=["'][^"']*["']/g, "") // حذف class/id مستقیم
46
49
  .trim();
47
50
 
51
+ // تغییر attribute های SVG به React-compatible و اضافه کردن props
52
+ cleaned = cleaned.replace(
53
+ /<svg([^>]*)>/,
54
+ `<svg$1
55
+ width={width}
56
+ height={height}
57
+ fill={fill}
58
+ stroke={props.stroke || "none"}
59
+ className={props.className}
60
+ {...props}>`
61
+ );
62
+
48
63
  return `import * as React from "react";
64
+ import type { SVGProps } from "react";
49
65
 
50
- export const ${componentName}: React.FC<React.SVGProps<SVGSVGElement>> = ({
66
+ export const ${componentName}: React.FC<SVGProps<SVGSVGElement>> = ({
51
67
  width = ${defaultWidth},
52
68
  height = ${defaultHeight},
53
69
  fill = "${defaultFill}",
54
70
  ...props
55
71
  }) => (
56
- ${cleaned.replace(
57
- /<svg/,
58
- `<svg width={width} height={height} fill={fill} {...props}`
59
- )}
72
+ ${cleaned}
60
73
  );
61
74
 
62
75
  export default ${componentName};
package/.svg-lock DELETED
@@ -1 +0,0 @@
1
- []