svger-cli 1.0.5 → 1.0.6

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "defaultHeight": 32
3
+ }
package/dist/cli.js CHANGED
File without changes
@@ -1,9 +1,7 @@
1
- interface TemplateProps {
1
+ export declare function reactTemplate({ componentName, svgContent, defaultWidth, defaultHeight, defaultFill, }: {
2
2
  componentName: string;
3
3
  svgContent: string;
4
4
  defaultWidth?: number;
5
5
  defaultHeight?: number;
6
6
  defaultFill?: string;
7
- }
8
- export declare const reactTemplate: ({ componentName, svgContent, defaultWidth, defaultHeight, defaultFill, }: TemplateProps) => string;
9
- export {};
7
+ }): string;
@@ -1,20 +1,29 @@
1
- export const reactTemplate = ({ componentName, svgContent, defaultWidth = 24, defaultHeight = 24, defaultFill = "currentColor", }) => {
2
- const cleanedSvg = svgContent
1
+ export function reactTemplate({ componentName, svgContent, defaultWidth = 24, defaultHeight = 24, defaultFill = "currentColor", }) {
2
+ const cleaned = svgContent
3
+ .replace(/<\?xml.*?\?>/g, "")
4
+ .replace(/<!DOCTYPE.*?>/g, "")
5
+ .replace(/\r?\n|\r/g, "")
6
+ .replace(/\s{2,}/g, " ")
3
7
  .replace(/style="[^"]*"/g, "")
4
- .replace(/\s+xmlns:xlink=/g, " xmlnsXlink=");
8
+ .replace(/\s+xmlns(:xlink)?="[^"]*"/g, "")
9
+ .trim()
10
+ .replace(/^.*?<svg[^>]*>(.*?)<\/svg>.*$/i, "$1");
5
11
  return `import type { SVGProps } from "react";
6
-
7
- const ${componentName} = (props: SVGProps<SVGSVGElement>) => (
8
- ${cleanedSvg
9
- .replace(/<svg([^>]*)>/, `<svg$1
12
+ const Svg${componentName} = (props: SVGProps<SVGSVGElement>) => (
13
+ <svg
14
+ viewBox="0 0 ${defaultWidth} ${defaultHeight}"
15
+ xmlns="http://www.w3.org/2000/svg"
16
+ xmlnsXlink="http://www.w3.org/1999/xlink"
10
17
  width={props.width || ${defaultWidth}}
11
18
  height={props.height || ${defaultHeight}}
12
19
  fill={props.fill || "${defaultFill}"}
13
20
  stroke={props.stroke || "none"}
14
21
  className={props.className}
15
- {...props}>`)}
22
+ {...props}
23
+ >
24
+ ${cleaned}
25
+ </svg>
16
26
  );
17
-
18
- export default ${componentName};
27
+ export default Svg${componentName};
19
28
  `;
20
- };
29
+ }
@@ -0,0 +1,17 @@
1
+ import type { SVGProps } from "react";
2
+ const SvgArrowBendDownLeft = (props: SVGProps<SVGSVGElement>) => (
3
+ <svg
4
+ viewBox="0 0 24 32"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ xmlnsXlink="http://www.w3.org/1999/xlink"
7
+ width={props.width || 24}
8
+ height={props.height || 32}
9
+ fill={props.fill || "currentColor"}
10
+ stroke={props.stroke || "none"}
11
+ className={props.className}
12
+ {...props}
13
+ >
14
+ <g id="surface1"><path d="M 2.25 5.25 C 2.253906 7.835938 3.28125 10.3125 5.109375 12.140625 C 6.9375 13.96875 9.414062 14.996094 12 15 L 19.1875 15 L 15.96875 18.21875 C 15.828125 18.359375 15.75 18.550781 15.75 18.75 C 15.75 18.949219 15.828125 19.140625 15.96875 19.28125 C 16.109375 19.421875 16.300781 19.5 16.5 19.5 C 16.699219 19.5 16.890625 19.421875 17.03125 19.28125 L 21.53125 14.78125 C 21.601562 14.710938 21.65625 14.628906 21.691406 14.539062 C 21.730469 14.445312 21.75 14.347656 21.75 14.25 C 21.75 14.152344 21.730469 14.054688 21.691406 13.960938 C 21.65625 13.871094 21.601562 13.789062 21.53125 13.71875 L 17.03125 9.21875 C 16.890625 9.078125 16.699219 9 16.5 9 C 16.300781 9 16.109375 9.078125 15.96875 9.21875 C 15.828125 9.359375 15.75 9.550781 15.75 9.75 C 15.75 9.949219 15.828125 10.140625 15.96875 10.28125 L 19.1875 13.5 L 12 13.5 C 9.8125 13.496094 7.714844 12.628906 6.167969 11.082031 C 4.621094 9.535156 3.75 7.4375 3.75 5.25 C 3.75 5.050781 3.671875 4.859375 3.53125 4.71875 C 3.390625 4.578125 3.199219 4.5 3 4.5 C 2.800781 4.5 2.609375 4.578125 2.46875 4.71875 C 2.328125 4.859375 2.25 5.050781 2.25 5.25 Z M 2.25 5.25 "/></g>
15
+ </svg>
16
+ );
17
+ export default SvgArrowBendDownLeft;
@@ -0,0 +1,17 @@
1
+ import type { SVGProps } from "react";
2
+ const SvgVite = (props: SVGProps<SVGSVGElement>) => (
3
+ <svg
4
+ viewBox="0 0 24 32"
5
+ xmlns="http://www.w3.org/2000/svg"
6
+ xmlnsXlink="http://www.w3.org/1999/xlink"
7
+ width={props.width || 24}
8
+ height={props.height || 32}
9
+ fill={props.fill || "currentColor"}
10
+ stroke={props.stroke || "none"}
11
+ className={props.className}
12
+ {...props}
13
+ >
14
+ <defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path>
15
+ </svg>
16
+ );
17
+ export default SvgVite;
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
3
+ <g id="surface1">
4
+ <path style=" stroke:none;fill-rule:nonzero;fill:rgb(0%,48.235294%,82.352942%);fill-opacity:1;" d="M 2.25 5.25 C 2.253906 7.835938 3.28125 10.3125 5.109375 12.140625 C 6.9375 13.96875 9.414062 14.996094 12 15 L 19.1875 15 L 15.96875 18.21875 C 15.828125 18.359375 15.75 18.550781 15.75 18.75 C 15.75 18.949219 15.828125 19.140625 15.96875 19.28125 C 16.109375 19.421875 16.300781 19.5 16.5 19.5 C 16.699219 19.5 16.890625 19.421875 17.03125 19.28125 L 21.53125 14.78125 C 21.601562 14.710938 21.65625 14.628906 21.691406 14.539062 C 21.730469 14.445312 21.75 14.347656 21.75 14.25 C 21.75 14.152344 21.730469 14.054688 21.691406 13.960938 C 21.65625 13.871094 21.601562 13.789062 21.53125 13.71875 L 17.03125 9.21875 C 16.890625 9.078125 16.699219 9 16.5 9 C 16.300781 9 16.109375 9.078125 15.96875 9.21875 C 15.828125 9.359375 15.75 9.550781 15.75 9.75 C 15.75 9.949219 15.828125 10.140625 15.96875 10.28125 L 19.1875 13.5 L 12 13.5 C 9.8125 13.496094 7.714844 12.628906 6.167969 11.082031 C 4.621094 9.535156 3.75 7.4375 3.75 5.25 C 3.75 5.050781 3.671875 4.859375 3.53125 4.71875 C 3.390625 4.578125 3.199219 4.5 3 4.5 C 2.800781 4.5 2.609375 4.578125 2.46875 4.71875 C 2.328125 4.859375 2.25 5.050781 2.25 5.25 Z M 2.25 5.25 "/>
5
+ </g>
6
+ </svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svger-cli",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
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",
package/src/builder.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import { pascalCase } from "change-case";
4
- import { isLocked } from "./lock.js";
4
+ import { isLocked } from "./lock.js";
5
5
  import { readConfig } from "./config.js";
6
6
  import { reactTemplate } from "./templates/ComponentTemplate.js";
7
7
 
@@ -1,40 +1,57 @@
1
-
2
- interface TemplateProps {
3
- componentName: string;
4
- svgContent: string;
5
- defaultWidth?: number;
6
- defaultHeight?: number;
7
- defaultFill?: string;
8
- }
9
-
10
- export const reactTemplate = ({
1
+ /**
2
+ * Generates a React SVG component template from provided SVG content.
3
+ *
4
+ * This function processes raw SVG content by cleaning it (removing XML declarations,
5
+ * DOCTYPE, extra whitespace, inline styles, and xmlns attributes), then wraps it in
6
+ * a React functional component that accepts standard SVGProps for flexibility.
7
+ *
8
+ * @param options - Configuration object for generating the component.
9
+ * @param options.componentName - The name of the React component (e.g., "IconName").
10
+ * @param options.svgContent - The raw SVG markup as a string.
11
+ * @param [options.defaultWidth=24] - The default width attribute for the SVG.
12
+ * @param [options.defaultHeight=24] - The default height attribute for the SVG.
13
+ * @param [options.defaultFill="currentColor"] - The default fill color for the SVG.
14
+ * @returns A string containing the complete TypeScript code for the React SVG component.
15
+ */
16
+ export function reactTemplate({
11
17
  componentName,
12
18
  svgContent,
13
19
  defaultWidth = 24,
14
20
  defaultHeight = 24,
15
21
  defaultFill = "currentColor",
16
- }: TemplateProps) => {
17
-
18
- const cleanedSvg = svgContent
19
- .replace(/style="[^"]*"/g, "")
20
- .replace(/\s+xmlns:xlink=/g, " xmlnsXlink=");
22
+ }: {
23
+ componentName: string;
24
+ svgContent: string;
25
+ defaultWidth?: number;
26
+ defaultHeight?: number;
27
+ defaultFill?: string;
28
+ }) {
29
+ const cleaned = svgContent
30
+ .replace(/<\?xml.*?\?>/g, "")
31
+ .replace(/<!DOCTYPE.*?>/g, "")
32
+ .replace(/\r?\n|\r/g, "")
33
+ .replace(/\s{2,}/g, " ")
34
+ .replace(/style="[^"]*"/g, "")
35
+ .replace(/\s+xmlns(:xlink)?="[^"]*"/g, "")
36
+ .trim()
37
+ .replace(/^.*?<svg[^>]*>(.*?)<\/svg>.*$/i, "$1");
21
38
 
22
39
  return `import type { SVGProps } from "react";
23
-
24
- const ${componentName} = (props: SVGProps<SVGSVGElement>) => (
25
- ${cleanedSvg
26
- .replace(
27
- /<svg([^>]*)>/,
28
- `<svg$1
40
+ const Svg${componentName} = (props: SVGProps<SVGSVGElement>) => (
41
+ <svg
42
+ viewBox="0 0 ${defaultWidth} ${defaultHeight}"
43
+ xmlns="http://www.w3.org/2000/svg"
44
+ xmlnsXlink="http://www.w3.org/1999/xlink"
29
45
  width={props.width || ${defaultWidth}}
30
46
  height={props.height || ${defaultHeight}}
31
47
  fill={props.fill || "${defaultFill}"}
32
48
  stroke={props.stroke || "none"}
33
49
  className={props.className}
34
- {...props}>`
35
- )}
50
+ {...props}
51
+ >
52
+ ${cleaned}
53
+ </svg>
36
54
  );
37
-
38
- export default ${componentName};
55
+ export default Svg${componentName};
39
56
  `;
40
- };
57
+ }