svger-cli 2.0.5 → 2.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.
@@ -59,328 +59,328 @@ export class FrameworkTemplateEngine {
59
59
  }
60
60
  generateReactComponent(componentName, svgContent, typescript, options) {
61
61
  const { attributes, innerContent } = this.parseSVG(svgContent);
62
- return `import React from "react";
63
- import type { SVGProps } from "react";
64
-
65
- export interface ${componentName}Props extends SVGProps<SVGSVGElement> {
66
- size?: number | string;
67
- }
68
-
69
- const ${componentName} = React.forwardRef<SVGSVGElement, ${componentName}Props>(
70
- ({ size, className, style, ...props }, ref) => {
71
- const dimensions = size ? { width: size, height: size } : {
72
- width: props.width || ${attributes.width || 24},
73
- height: props.height || ${attributes.height || 24}
74
- };
75
-
76
- return (
77
- <svg
78
- ref={ref}
79
- viewBox="${attributes.viewBox || '0 0 24 24'}"
80
- xmlns="http://www.w3.org/2000/svg"
81
- width={dimensions.width}
82
- height={dimensions.height}
83
- fill={props.fill || "${attributes.fill || 'currentColor'}"}
84
- className={className}
85
- style={style}
86
- {...props}
87
- >
88
- ${innerContent}
89
- </svg>
90
- );
91
- }
92
- );
93
-
94
- ${componentName}.displayName = "${componentName}";
95
-
96
- export default ${componentName};
62
+ return `import React from "react";
63
+ import type { SVGProps } from "react";
64
+
65
+ export interface ${componentName}Props extends SVGProps<SVGSVGElement> {
66
+ size?: number | string;
67
+ }
68
+
69
+ const ${componentName} = React.forwardRef<SVGSVGElement, ${componentName}Props>(
70
+ ({ size, className, style, ...props }, ref) => {
71
+ const dimensions = size ? { width: size, height: size } : {
72
+ width: props.width || ${attributes.width || 24},
73
+ height: props.height || ${attributes.height || 24}
74
+ };
75
+
76
+ return (
77
+ <svg
78
+ ref={ref}
79
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
80
+ xmlns="http://www.w3.org/2000/svg"
81
+ width={dimensions.width}
82
+ height={dimensions.height}
83
+ fill={props.fill || "${attributes.fill || 'currentColor'}"}
84
+ className={className}
85
+ style={style}
86
+ {...props}
87
+ >
88
+ ${innerContent}
89
+ </svg>
90
+ );
91
+ }
92
+ );
93
+
94
+ ${componentName}.displayName = "${componentName}";
95
+
96
+ export default ${componentName};
97
97
  `;
98
98
  }
99
99
  generateVueComponent(componentName, svgContent, typescript, options) {
100
100
  const { attributes, innerContent } = this.parseSVG(svgContent);
101
101
  const { scriptSetup = true } = options;
102
102
  if (scriptSetup && typescript) {
103
- return `<template>
104
- <svg
105
- :class="className"
106
- :style="style"
107
- :width="width || ${attributes.width || 24}"
108
- :height="height || ${attributes.height || 24}"
109
- :fill="fill || '${attributes.fill || 'currentColor'}'"
110
- :stroke="stroke"
111
- viewBox="${attributes.viewBox || '0 0 24 24'}"
112
- xmlns="http://www.w3.org/2000/svg"
113
- v-bind="$attrs"
114
- >
115
- ${innerContent}
116
- </svg>
117
- </template>
118
-
119
- <script setup lang="ts">
120
- interface Props {
121
- className?: string;
122
- style?: string | Record<string, any>;
123
- width?: string | number;
124
- height?: string | number;
125
- fill?: string;
126
- stroke?: string;
127
- }
128
-
129
- withDefaults(defineProps<Props>(), {
130
- className: '',
131
- fill: '${attributes.fill || 'currentColor'}',
132
- width: ${attributes.width || 24},
133
- height: ${attributes.height || 24}
134
- });
135
- </script>
103
+ return `<template>
104
+ <svg
105
+ :class="className"
106
+ :style="style"
107
+ :width="width || ${attributes.width || 24}"
108
+ :height="height || ${attributes.height || 24}"
109
+ :fill="fill || '${attributes.fill || 'currentColor'}'"
110
+ :stroke="stroke"
111
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
112
+ xmlns="http://www.w3.org/2000/svg"
113
+ v-bind="$attrs"
114
+ >
115
+ ${innerContent}
116
+ </svg>
117
+ </template>
118
+
119
+ <script setup lang="ts">
120
+ interface Props {
121
+ className?: string;
122
+ style?: string | Record<string, any>;
123
+ width?: string | number;
124
+ height?: string | number;
125
+ fill?: string;
126
+ stroke?: string;
127
+ }
128
+
129
+ withDefaults(defineProps<Props>(), {
130
+ className: '',
131
+ fill: '${attributes.fill || 'currentColor'}',
132
+ width: ${attributes.width || 24},
133
+ height: ${attributes.height || 24}
134
+ });
135
+ </script>
136
136
  `;
137
137
  }
138
- return `<template>
139
- <svg
140
- :class="className"
141
- :style="style"
142
- :width="width"
143
- :height="height"
144
- :fill="fill"
145
- :stroke="stroke"
146
- viewBox="${attributes.viewBox || '0 0 24 24'}"
147
- xmlns="http://www.w3.org/2000/svg"
148
- v-bind="$attrs"
149
- >
150
- ${innerContent}
151
- </svg>
152
- </template>
153
-
154
- <script${typescript ? ' lang="ts"' : ''}>
155
- import { defineComponent } from 'vue';
156
-
157
- export default defineComponent({
158
- name: '${componentName}',
159
- props: {
160
- className: { type: String, default: '' },
161
- style: { type: [String, Object], default: '' },
162
- width: { type: [String, Number], default: ${attributes.width || 24} },
163
- height: { type: [String, Number], default: ${attributes.height || 24} },
164
- fill: { type: String, default: '${attributes.fill || 'currentColor'}' },
165
- stroke: { type: String, default: '' }
166
- }
167
- });
168
- </script>
138
+ return `<template>
139
+ <svg
140
+ :class="className"
141
+ :style="style"
142
+ :width="width"
143
+ :height="height"
144
+ :fill="fill"
145
+ :stroke="stroke"
146
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
147
+ xmlns="http://www.w3.org/2000/svg"
148
+ v-bind="$attrs"
149
+ >
150
+ ${innerContent}
151
+ </svg>
152
+ </template>
153
+
154
+ <script${typescript ? ' lang="ts"' : ''}>
155
+ import { defineComponent } from 'vue';
156
+
157
+ export default defineComponent({
158
+ name: '${componentName}',
159
+ props: {
160
+ className: { type: String, default: '' },
161
+ style: { type: [String, Object], default: '' },
162
+ width: { type: [String, Number], default: ${attributes.width || 24} },
163
+ height: { type: [String, Number], default: ${attributes.height || 24} },
164
+ fill: { type: String, default: '${attributes.fill || 'currentColor'}' },
165
+ stroke: { type: String, default: '' }
166
+ }
167
+ });
168
+ </script>
169
169
  `;
170
170
  }
171
171
  generateSvelteComponent(componentName, svgContent, typescript) {
172
172
  const { attributes, innerContent } = this.parseSVG(svgContent);
173
- return `<script${typescript ? ' lang="ts"' : ''}>
174
- export let className${typescript ? ': string' : ''} = '';
175
- export let style${typescript ? ': string' : ''} = '';
176
- export let width${typescript ? ': string | number' : ''} = ${attributes.width || 24};
177
- export let height${typescript ? ': string | number' : ''} = ${attributes.height || 24};
178
- export let fill${typescript ? ': string' : ''} = '${attributes.fill || 'currentColor'}';
179
- export let stroke${typescript ? ': string' : ''} = '';
180
- </script>
181
-
182
- <svg
183
- class={className}
184
- {style}
185
- {width}
186
- {height}
187
- {fill}
188
- {stroke}
189
- viewBox="${attributes.viewBox || '0 0 24 24'}"
190
- xmlns="http://www.w3.org/2000/svg"
191
- {...$$restProps}
192
- >
193
- ${innerContent}
194
- </svg>
173
+ return `<script${typescript ? ' lang="ts"' : ''}>
174
+ export let className${typescript ? ': string' : ''} = '';
175
+ export let style${typescript ? ': string' : ''} = '';
176
+ export let width${typescript ? ': string | number' : ''} = ${attributes.width || 24};
177
+ export let height${typescript ? ': string | number' : ''} = ${attributes.height || 24};
178
+ export let fill${typescript ? ': string' : ''} = '${attributes.fill || 'currentColor'}';
179
+ export let stroke${typescript ? ': string' : ''} = '';
180
+ </script>
181
+
182
+ <svg
183
+ class={className}
184
+ {style}
185
+ {width}
186
+ {height}
187
+ {fill}
188
+ {stroke}
189
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
190
+ xmlns="http://www.w3.org/2000/svg"
191
+ {...$$restProps}
192
+ >
193
+ ${innerContent}
194
+ </svg>
195
195
  `;
196
196
  }
197
197
  generateAngularComponent(componentName, svgContent, typescript, options) {
198
198
  const { attributes, innerContent } = this.parseSVG(svgContent);
199
199
  const { standalone = true } = options;
200
200
  const kebabName = this.toKebabCase(componentName);
201
- return `import { Component, Input${standalone ? ', ChangeDetectionStrategy' : ''} } from '@angular/core';
202
-
203
- @Component({
204
- selector: '${kebabName}',
205
- ${standalone ? 'standalone: true,' : ''}
206
- template: \`
207
- <svg
208
- [attr.class]="className"
209
- [attr.width]="width"
210
- [attr.height]="height"
211
- [attr.fill]="fill"
212
- [attr.stroke]="stroke"
213
- viewBox="${attributes.viewBox || '0 0 24 24'}"
214
- xmlns="http://www.w3.org/2000/svg"
215
- >
216
- ${innerContent}
217
- </svg>
201
+ return `import { Component, Input${standalone ? ', ChangeDetectionStrategy' : ''} } from '@angular/core';
202
+
203
+ @Component({
204
+ selector: '${kebabName}',
205
+ ${standalone ? 'standalone: true,' : ''}
206
+ template: \`
207
+ <svg
208
+ [attr.class]="className"
209
+ [attr.width]="width"
210
+ [attr.height]="height"
211
+ [attr.fill]="fill"
212
+ [attr.stroke]="stroke"
213
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
214
+ xmlns="http://www.w3.org/2000/svg"
215
+ >
216
+ ${innerContent}
217
+ </svg>
218
218
  \`,${standalone
219
- ? `
219
+ ? `
220
220
  changeDetection: ChangeDetectionStrategy.OnPush`
221
- : ''}
222
- })
223
- export class ${componentName}Component {
224
- @Input() className: string = '';
225
- @Input() width: string | number = ${attributes.width || 24};
226
- @Input() height: string | number = ${attributes.height || 24};
227
- @Input() fill: string = '${attributes.fill || 'currentColor'}';
228
- @Input() stroke: string = '';
229
- }
221
+ : ''}
222
+ })
223
+ export class ${componentName}Component {
224
+ @Input() className: string = '';
225
+ @Input() width: string | number = ${attributes.width || 24};
226
+ @Input() height: string | number = ${attributes.height || 24};
227
+ @Input() fill: string = '${attributes.fill || 'currentColor'}';
228
+ @Input() stroke: string = '';
229
+ }
230
230
  `;
231
231
  }
232
232
  generateSolidComponent(componentName, svgContent, typescript) {
233
233
  const { attributes, innerContent } = this.parseSVG(svgContent);
234
- return `import { Component, JSX } from 'solid-js';
235
-
236
- export interface ${componentName}Props extends JSX.SvgSVGAttributes<SVGSVGElement> {
237
- className?: string;
238
- width?: string | number;
239
- height?: string | number;
240
- fill?: string;
241
- stroke?: string;
242
- }
243
-
244
- const ${componentName}: Component<${componentName}Props> = (props) => (
245
- <svg
246
- class={props.className}
247
- style={props.style}
248
- width={props.width || ${attributes.width || 24}}
249
- height={props.height || ${attributes.height || 24}}
250
- fill={props.fill || '${attributes.fill || 'currentColor'}'}
251
- stroke={props.stroke}
252
- viewBox="${attributes.viewBox || '0 0 24 24'}"
253
- xmlns="http://www.w3.org/2000/svg"
254
- {...props}
255
- >
256
- ${innerContent}
257
- </svg>
258
- );
259
-
260
- export default ${componentName};
234
+ return `import { Component, JSX } from 'solid-js';
235
+
236
+ export interface ${componentName}Props extends JSX.SvgSVGAttributes<SVGSVGElement> {
237
+ className?: string;
238
+ width?: string | number;
239
+ height?: string | number;
240
+ fill?: string;
241
+ stroke?: string;
242
+ }
243
+
244
+ const ${componentName}: Component<${componentName}Props> = (props) => (
245
+ <svg
246
+ class={props.className}
247
+ style={props.style}
248
+ width={props.width || ${attributes.width || 24}}
249
+ height={props.height || ${attributes.height || 24}}
250
+ fill={props.fill || '${attributes.fill || 'currentColor'}'}
251
+ stroke={props.stroke}
252
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
253
+ xmlns="http://www.w3.org/2000/svg"
254
+ {...props}
255
+ >
256
+ ${innerContent}
257
+ </svg>
258
+ );
259
+
260
+ export default ${componentName};
261
261
  `;
262
262
  }
263
263
  generatePreactComponent(componentName, svgContent, typescript) {
264
264
  const { attributes, innerContent } = this.parseSVG(svgContent);
265
- return `import { h, FunctionComponent } from 'preact';
266
- import { JSX } from 'preact/jsx-runtime';
267
-
268
- export interface ${componentName}Props extends JSX.SVGAttributes<SVGSVGElement> {
269
- className?: string;
270
- width?: string | number;
271
- height?: string | number;
272
- fill?: string;
273
- stroke?: string;
274
- }
275
-
276
- const ${componentName}: FunctionComponent<${componentName}Props> = ({
277
- className,
278
- style,
279
- width,
280
- height,
281
- fill,
282
- stroke,
283
- ...props
284
- }) => {
285
- return (
286
- <svg
287
- class={className}
288
- style={style}
289
- width={width || ${attributes.width || 24}}
290
- height={height || ${attributes.height || 24}}
291
- fill={fill || '${attributes.fill || 'currentColor'}'}
292
- stroke={stroke}
293
- viewBox="${attributes.viewBox || '0 0 24 24'}"
294
- xmlns="http://www.w3.org/2000/svg"
295
- {...props}
296
- >
297
- ${innerContent}
298
- </svg>
299
- );
300
- };
301
-
302
- export default ${componentName};
265
+ return `import { h, FunctionComponent } from 'preact';
266
+ import { JSX } from 'preact/jsx-runtime';
267
+
268
+ export interface ${componentName}Props extends JSX.SVGAttributes<SVGSVGElement> {
269
+ className?: string;
270
+ width?: string | number;
271
+ height?: string | number;
272
+ fill?: string;
273
+ stroke?: string;
274
+ }
275
+
276
+ const ${componentName}: FunctionComponent<${componentName}Props> = ({
277
+ className,
278
+ style,
279
+ width,
280
+ height,
281
+ fill,
282
+ stroke,
283
+ ...props
284
+ }) => {
285
+ return (
286
+ <svg
287
+ class={className}
288
+ style={style}
289
+ width={width || ${attributes.width || 24}}
290
+ height={height || ${attributes.height || 24}}
291
+ fill={fill || '${attributes.fill || 'currentColor'}'}
292
+ stroke={stroke}
293
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
294
+ xmlns="http://www.w3.org/2000/svg"
295
+ {...props}
296
+ >
297
+ ${innerContent}
298
+ </svg>
299
+ );
300
+ };
301
+
302
+ export default ${componentName};
303
303
  `;
304
304
  }
305
305
  generateLitComponent(componentName, svgContent, typescript) {
306
306
  const { attributes, innerContent } = this.parseSVG(svgContent);
307
307
  const kebabName = this.toKebabCase(componentName);
308
- return `import { LitElement, html, css, svg } from 'lit';
309
- import { customElement, property } from 'lit/decorators.js';
310
-
311
- @customElement('${kebabName}')
312
- export class ${componentName} extends LitElement {
313
- @property({ type: String }) className = '';
314
- @property({ type: String, reflect: true }) width = '${attributes.width || 24}';
315
- @property({ type: String, reflect: true }) height = '${attributes.height || 24}';
316
- @property({ type: String, reflect: true }) fill = '${attributes.fill || 'currentColor'}';
317
- @property({ type: String, reflect: true }) stroke = '';
318
-
319
- static styles = css\`:host { display: inline-block; }\`;
320
-
321
- render() {
322
- return svg\`
323
- <svg
324
- class="\${this.className}"
325
- width="\${this.width}"
326
- height="\${this.height}"
327
- fill="\${this.fill}"
328
- stroke="\${this.stroke}"
329
- viewBox="${attributes.viewBox || '0 0 24 24'}"
330
- xmlns="http://www.w3.org/2000/svg"
331
- >
332
- ${innerContent}
333
- </svg>
334
- \`;
335
- }
336
- }
337
-
338
- declare global {
339
- interface HTMLElementTagNameMap {
340
- '${kebabName}': ${componentName};
341
- }
342
- }
308
+ return `import { LitElement, html, css, svg } from 'lit';
309
+ import { customElement, property } from 'lit/decorators.js';
310
+
311
+ @customElement('${kebabName}')
312
+ export class ${componentName} extends LitElement {
313
+ @property({ type: String }) className = '';
314
+ @property({ type: String, reflect: true }) width = '${attributes.width || 24}';
315
+ @property({ type: String, reflect: true }) height = '${attributes.height || 24}';
316
+ @property({ type: String, reflect: true }) fill = '${attributes.fill || 'currentColor'}';
317
+ @property({ type: String, reflect: true }) stroke = '';
318
+
319
+ static styles = css\`:host { display: inline-block; }\`;
320
+
321
+ render() {
322
+ return svg\`
323
+ <svg
324
+ class="\${this.className}"
325
+ width="\${this.width}"
326
+ height="\${this.height}"
327
+ fill="\${this.fill}"
328
+ stroke="\${this.stroke}"
329
+ viewBox="${attributes.viewBox || '0 0 24 24'}"
330
+ xmlns="http://www.w3.org/2000/svg"
331
+ >
332
+ ${innerContent}
333
+ </svg>
334
+ \`;
335
+ }
336
+ }
337
+
338
+ declare global {
339
+ interface HTMLElementTagNameMap {
340
+ '${kebabName}': ${componentName};
341
+ }
342
+ }
343
343
  `;
344
344
  }
345
345
  generateVanillaComponent(componentName, svgContent, typescript) {
346
346
  const { attributes, innerContent } = this.parseSVG(svgContent);
347
- return `export interface ${componentName}Options {
348
- className?: string;
349
- width?: string | number;
350
- height?: string | number;
351
- fill?: string;
352
- stroke?: string;
353
- [key: string]: any;
354
- }
355
-
356
- export function ${componentName}(options: ${componentName}Options = {}): SVGSVGElement {
357
- const {
358
- className = '',
359
- width = ${attributes.width || 24},
360
- height = ${attributes.height || 24},
361
- fill = '${attributes.fill || 'currentColor'}',
362
- stroke = '',
363
- ...attrs
364
- } = options;
365
-
366
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
367
- svg.setAttribute('viewBox', '${attributes.viewBox || '0 0 24 24'}');
368
- svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
369
-
370
- if (className) svg.setAttribute('class', className);
371
- svg.setAttribute('width', String(width));
372
- svg.setAttribute('height', String(height));
373
- svg.setAttribute('fill', fill);
374
- if (stroke) svg.setAttribute('stroke', stroke);
375
-
376
- Object.entries(attrs).forEach(([key, value]) => {
377
- svg.setAttribute(key, String(value));
378
- });
379
-
380
- svg.innerHTML = \`${innerContent}\`;
381
-
382
- return svg;
383
- }
347
+ return `export interface ${componentName}Options {
348
+ className?: string;
349
+ width?: string | number;
350
+ height?: string | number;
351
+ fill?: string;
352
+ stroke?: string;
353
+ [key: string]: any;
354
+ }
355
+
356
+ export function ${componentName}(options: ${componentName}Options = {}): SVGSVGElement {
357
+ const {
358
+ className = '',
359
+ width = ${attributes.width || 24},
360
+ height = ${attributes.height || 24},
361
+ fill = '${attributes.fill || 'currentColor'}',
362
+ stroke = '',
363
+ ...attrs
364
+ } = options;
365
+
366
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
367
+ svg.setAttribute('viewBox', '${attributes.viewBox || '0 0 24 24'}');
368
+ svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
369
+
370
+ if (className) svg.setAttribute('class', className);
371
+ svg.setAttribute('width', String(width));
372
+ svg.setAttribute('height', String(height));
373
+ svg.setAttribute('fill', fill);
374
+ if (stroke) svg.setAttribute('stroke', stroke);
375
+
376
+ Object.entries(attrs).forEach(([key, value]) => {
377
+ svg.setAttribute(key, String(value));
378
+ });
379
+
380
+ svg.innerHTML = \`${innerContent}\`;
381
+
382
+ return svg;
383
+ }
384
384
  `;
385
385
  }
386
386
  toKebabCase(str) {