svger-cli 1.0.6 → 1.0.8
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/CODE_OF_CONDUCT.md +79 -0
- package/CONTRIBUTING.md +146 -0
- package/LICENSE +21 -0
- package/README.md +1862 -73
- package/TESTING.md +143 -0
- package/cli-framework.test.js +16 -0
- package/cli-test-angular/Arrowbenddownleft.component.ts +27 -0
- package/cli-test-angular/Vite.component.ts +27 -0
- package/cli-test-angular/index.ts +25 -0
- package/{my-icons/ArrowBendDownLeft.tsx → cli-test-output/Arrowbenddownleft.vue} +28 -12
- package/{my-icons/Vite.tsx → cli-test-output/Vite.vue} +28 -12
- package/cli-test-output/index.ts +25 -0
- package/cli-test-react/Arrowbenddownleft.tsx +39 -0
- package/cli-test-react/Vite.tsx +39 -0
- package/cli-test-react/index.ts +25 -0
- package/cli-test-svelte/Arrowbenddownleft.svelte +22 -0
- package/cli-test-svelte/Vite.svelte +22 -0
- package/cli-test-svelte/index.ts +25 -0
- package/dist/builder.js +12 -13
- package/dist/clean.js +3 -3
- package/dist/cli.js +139 -61
- package/dist/config.d.ts +1 -1
- package/dist/config.js +5 -7
- package/dist/lock.js +1 -1
- package/dist/templates/ComponentTemplate.d.ts +15 -0
- package/dist/templates/ComponentTemplate.js +15 -0
- package/dist/watch.d.ts +2 -1
- package/dist/watch.js +30 -33
- package/docs/ADR-SVG-INTRGRATION-METHODS-002.adr.md +550 -0
- package/docs/FRAMEWORK-GUIDE.md +768 -0
- package/docs/IMPLEMENTATION-SUMMARY.md +376 -0
- package/frameworks.test.js +170 -0
- package/package.json +8 -10
- package/src/builder.ts +12 -13
- package/src/clean.ts +3 -3
- package/src/cli.ts +148 -59
- package/src/config.ts +5 -6
- package/src/core/error-handler.ts +303 -0
- package/src/core/framework-templates.ts +428 -0
- package/src/core/logger.ts +104 -0
- package/src/core/performance-engine.ts +327 -0
- package/src/core/plugin-manager.ts +228 -0
- package/src/core/style-compiler.ts +605 -0
- package/src/core/template-manager.ts +619 -0
- package/src/index.ts +235 -0
- package/src/lock.ts +1 -1
- package/src/processors/svg-processor.ts +288 -0
- package/src/services/config.ts +241 -0
- package/src/services/file-watcher.ts +218 -0
- package/src/services/svg-service.ts +468 -0
- package/src/types/index.ts +169 -0
- package/src/utils/native.ts +352 -0
- package/src/watch.ts +36 -36
- package/test-output-mulit/TestIcon-angular-module.component.ts +26 -0
- package/test-output-mulit/TestIcon-angular-standalone.component.ts +27 -0
- package/test-output-mulit/TestIcon-lit.ts +35 -0
- package/test-output-mulit/TestIcon-preact.tsx +38 -0
- package/test-output-mulit/TestIcon-react.tsx +35 -0
- package/test-output-mulit/TestIcon-solid.tsx +27 -0
- package/test-output-mulit/TestIcon-svelte.svelte +22 -0
- package/test-output-mulit/TestIcon-vanilla.ts +37 -0
- package/test-output-mulit/TestIcon-vue-composition.vue +33 -0
- package/test-output-mulit/TestIcon-vue-options.vue +31 -0
- package/tsconfig.json +11 -9
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
import { ComponentGenerationOptions, FrameworkType, FrameworkOptions } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
// Re-export types for convenience
|
|
4
|
+
export type { FrameworkType, FrameworkOptions } from '../types/index.js';
|
|
5
|
+
|
|
6
|
+
interface SVGAttributes {
|
|
7
|
+
viewBox?: string;
|
|
8
|
+
width?: string;
|
|
9
|
+
height?: string;
|
|
10
|
+
fill?: string;
|
|
11
|
+
stroke?: string;
|
|
12
|
+
xmlns?: string;
|
|
13
|
+
[key: string]: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class FrameworkTemplateEngine {
|
|
17
|
+
|
|
18
|
+
public generateComponent(options: ComponentGenerationOptions): string {
|
|
19
|
+
const { framework, componentName, svgContent, typescript = true, frameworkOptions = {} } = options;
|
|
20
|
+
|
|
21
|
+
switch (framework) {
|
|
22
|
+
case 'react':
|
|
23
|
+
return this.generateReactComponent(componentName, svgContent, typescript, frameworkOptions);
|
|
24
|
+
case 'vue':
|
|
25
|
+
return this.generateVueComponent(componentName, svgContent, typescript, frameworkOptions);
|
|
26
|
+
case 'svelte':
|
|
27
|
+
return this.generateSvelteComponent(componentName, svgContent, typescript);
|
|
28
|
+
case 'angular':
|
|
29
|
+
return this.generateAngularComponent(componentName, svgContent, typescript, frameworkOptions);
|
|
30
|
+
case 'solid':
|
|
31
|
+
return this.generateSolidComponent(componentName, svgContent, typescript);
|
|
32
|
+
case 'preact':
|
|
33
|
+
return this.generatePreactComponent(componentName, svgContent, typescript);
|
|
34
|
+
case 'lit':
|
|
35
|
+
return this.generateLitComponent(componentName, svgContent, typescript);
|
|
36
|
+
case 'vanilla':
|
|
37
|
+
return this.generateVanillaComponent(componentName, svgContent, typescript);
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unsupported framework: ${framework}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public getFileExtension(framework: FrameworkType, typescript: boolean = true): string {
|
|
44
|
+
const tsExt = typescript ? 'ts' : 'js';
|
|
45
|
+
|
|
46
|
+
switch (framework) {
|
|
47
|
+
case 'react':
|
|
48
|
+
case 'preact':
|
|
49
|
+
case 'solid':
|
|
50
|
+
return typescript ? 'tsx' : 'jsx';
|
|
51
|
+
case 'vue':
|
|
52
|
+
return 'vue';
|
|
53
|
+
case 'svelte':
|
|
54
|
+
return 'svelte';
|
|
55
|
+
case 'angular':
|
|
56
|
+
return `component.${tsExt}`;
|
|
57
|
+
case 'lit':
|
|
58
|
+
case 'vanilla':
|
|
59
|
+
return `${tsExt}`;
|
|
60
|
+
default:
|
|
61
|
+
return `${tsExt}`;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private parseSVG(svgContent: string): { attributes: SVGAttributes; innerContent: string } {
|
|
66
|
+
const svgMatch = svgContent.match(/<svg([^>]*)>([\s\S]*?)<\/svg>/);
|
|
67
|
+
if (!svgMatch) {
|
|
68
|
+
return { attributes: {}, innerContent: svgContent };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const attributesString = svgMatch[1];
|
|
72
|
+
const innerContent = svgMatch[2].trim();
|
|
73
|
+
const attributes: SVGAttributes = {};
|
|
74
|
+
|
|
75
|
+
const attrRegex = /(\w+(?:-\w+)*)="([^"]*)"/g;
|
|
76
|
+
let match;
|
|
77
|
+
while ((match = attrRegex.exec(attributesString)) !== null) {
|
|
78
|
+
attributes[match[1]] = match[2];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { attributes, innerContent };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private generateReactComponent(componentName: string, svgContent: string, typescript: boolean, options: FrameworkOptions): string {
|
|
85
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
86
|
+
return `import React from "react";
|
|
87
|
+
import type { SVGProps } from "react";
|
|
88
|
+
|
|
89
|
+
export interface ${componentName}Props extends SVGProps<SVGSVGElement> {
|
|
90
|
+
size?: number | string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const ${componentName} = React.forwardRef<SVGSVGElement, ${componentName}Props>(
|
|
94
|
+
({ size, className, style, ...props }, ref) => {
|
|
95
|
+
const dimensions = size ? { width: size, height: size } : {
|
|
96
|
+
width: props.width || ${attributes.width || 24},
|
|
97
|
+
height: props.height || ${attributes.height || 24}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<svg
|
|
102
|
+
ref={ref}
|
|
103
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
104
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
105
|
+
width={dimensions.width}
|
|
106
|
+
height={dimensions.height}
|
|
107
|
+
fill={props.fill || "${attributes.fill || 'currentColor'}"}
|
|
108
|
+
className={className}
|
|
109
|
+
style={style}
|
|
110
|
+
{...props}
|
|
111
|
+
>
|
|
112
|
+
${innerContent}
|
|
113
|
+
</svg>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
${componentName}.displayName = "${componentName}";
|
|
119
|
+
|
|
120
|
+
export default ${componentName};
|
|
121
|
+
`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private generateVueComponent(componentName: string, svgContent: string, typescript: boolean, options: FrameworkOptions): string {
|
|
125
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
126
|
+
const { scriptSetup = true } = options;
|
|
127
|
+
|
|
128
|
+
if (scriptSetup && typescript) {
|
|
129
|
+
return `<template>
|
|
130
|
+
<svg
|
|
131
|
+
:class="className"
|
|
132
|
+
:style="style"
|
|
133
|
+
:width="width || ${attributes.width || 24}"
|
|
134
|
+
:height="height || ${attributes.height || 24}"
|
|
135
|
+
:fill="fill || '${attributes.fill || 'currentColor'}'"
|
|
136
|
+
:stroke="stroke"
|
|
137
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
138
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
139
|
+
v-bind="$attrs"
|
|
140
|
+
>
|
|
141
|
+
${innerContent}
|
|
142
|
+
</svg>
|
|
143
|
+
</template>
|
|
144
|
+
|
|
145
|
+
<script setup lang="ts">
|
|
146
|
+
interface Props {
|
|
147
|
+
className?: string;
|
|
148
|
+
style?: string | Record<string, any>;
|
|
149
|
+
width?: string | number;
|
|
150
|
+
height?: string | number;
|
|
151
|
+
fill?: string;
|
|
152
|
+
stroke?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
withDefaults(defineProps<Props>(), {
|
|
156
|
+
className: '',
|
|
157
|
+
fill: '${attributes.fill || 'currentColor'}',
|
|
158
|
+
width: ${attributes.width || 24},
|
|
159
|
+
height: ${attributes.height || 24}
|
|
160
|
+
});
|
|
161
|
+
</script>
|
|
162
|
+
`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return `<template>
|
|
166
|
+
<svg
|
|
167
|
+
:class="className"
|
|
168
|
+
:style="style"
|
|
169
|
+
:width="width"
|
|
170
|
+
:height="height"
|
|
171
|
+
:fill="fill"
|
|
172
|
+
:stroke="stroke"
|
|
173
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
174
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
175
|
+
v-bind="$attrs"
|
|
176
|
+
>
|
|
177
|
+
${innerContent}
|
|
178
|
+
</svg>
|
|
179
|
+
</template>
|
|
180
|
+
|
|
181
|
+
<script${typescript ? ' lang="ts"' : ''}>
|
|
182
|
+
import { defineComponent } from 'vue';
|
|
183
|
+
|
|
184
|
+
export default defineComponent({
|
|
185
|
+
name: '${componentName}',
|
|
186
|
+
props: {
|
|
187
|
+
className: { type: String, default: '' },
|
|
188
|
+
style: { type: [String, Object], default: '' },
|
|
189
|
+
width: { type: [String, Number], default: ${attributes.width || 24} },
|
|
190
|
+
height: { type: [String, Number], default: ${attributes.height || 24} },
|
|
191
|
+
fill: { type: String, default: '${attributes.fill || 'currentColor'}' },
|
|
192
|
+
stroke: { type: String, default: '' }
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
</script>
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
private generateSvelteComponent(componentName: string, svgContent: string, typescript: boolean): string {
|
|
200
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
201
|
+
return `<script${typescript ? ' lang="ts"' : ''}>
|
|
202
|
+
export let className${typescript ? ': string' : ''} = '';
|
|
203
|
+
export let style${typescript ? ': string' : ''} = '';
|
|
204
|
+
export let width${typescript ? ': string | number' : ''} = ${attributes.width || 24};
|
|
205
|
+
export let height${typescript ? ': string | number' : ''} = ${attributes.height || 24};
|
|
206
|
+
export let fill${typescript ? ': string' : ''} = '${attributes.fill || 'currentColor'}';
|
|
207
|
+
export let stroke${typescript ? ': string' : ''} = '';
|
|
208
|
+
</script>
|
|
209
|
+
|
|
210
|
+
<svg
|
|
211
|
+
class={className}
|
|
212
|
+
{style}
|
|
213
|
+
{width}
|
|
214
|
+
{height}
|
|
215
|
+
{fill}
|
|
216
|
+
{stroke}
|
|
217
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
218
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
219
|
+
{...$$restProps}
|
|
220
|
+
>
|
|
221
|
+
${innerContent}
|
|
222
|
+
</svg>
|
|
223
|
+
`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private generateAngularComponent(componentName: string, svgContent: string, typescript: boolean, options: FrameworkOptions): string {
|
|
227
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
228
|
+
const { standalone = true } = options;
|
|
229
|
+
const kebabName = this.toKebabCase(componentName);
|
|
230
|
+
|
|
231
|
+
return `import { Component, Input${standalone ? ', ChangeDetectionStrategy' : ''} } from '@angular/core';
|
|
232
|
+
|
|
233
|
+
@Component({
|
|
234
|
+
selector: '${kebabName}',
|
|
235
|
+
${standalone ? 'standalone: true,' : ''}
|
|
236
|
+
template: \`
|
|
237
|
+
<svg
|
|
238
|
+
[attr.class]="className"
|
|
239
|
+
[attr.width]="width"
|
|
240
|
+
[attr.height]="height"
|
|
241
|
+
[attr.fill]="fill"
|
|
242
|
+
[attr.stroke]="stroke"
|
|
243
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
244
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
245
|
+
>
|
|
246
|
+
${innerContent}
|
|
247
|
+
</svg>
|
|
248
|
+
\`,${standalone ? `
|
|
249
|
+
changeDetection: ChangeDetectionStrategy.OnPush` : ''}
|
|
250
|
+
})
|
|
251
|
+
export class ${componentName}Component {
|
|
252
|
+
@Input() className: string = '';
|
|
253
|
+
@Input() width: string | number = ${attributes.width || 24};
|
|
254
|
+
@Input() height: string | number = ${attributes.height || 24};
|
|
255
|
+
@Input() fill: string = '${attributes.fill || 'currentColor'}';
|
|
256
|
+
@Input() stroke: string = '';
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private generateSolidComponent(componentName: string, svgContent: string, typescript: boolean): string {
|
|
262
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
263
|
+
return `import { Component, JSX } from 'solid-js';
|
|
264
|
+
|
|
265
|
+
export interface ${componentName}Props extends JSX.SvgSVGAttributes<SVGSVGElement> {
|
|
266
|
+
className?: string;
|
|
267
|
+
width?: string | number;
|
|
268
|
+
height?: string | number;
|
|
269
|
+
fill?: string;
|
|
270
|
+
stroke?: string;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const ${componentName}: Component<${componentName}Props> = (props) => (
|
|
274
|
+
<svg
|
|
275
|
+
class={props.className}
|
|
276
|
+
style={props.style}
|
|
277
|
+
width={props.width || ${attributes.width || 24}}
|
|
278
|
+
height={props.height || ${attributes.height || 24}}
|
|
279
|
+
fill={props.fill || '${attributes.fill || 'currentColor'}'}
|
|
280
|
+
stroke={props.stroke}
|
|
281
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
282
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
283
|
+
{...props}
|
|
284
|
+
>
|
|
285
|
+
${innerContent}
|
|
286
|
+
</svg>
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
export default ${componentName};
|
|
290
|
+
`;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private generatePreactComponent(componentName: string, svgContent: string, typescript: boolean): string {
|
|
294
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
295
|
+
return `import { h, FunctionComponent } from 'preact';
|
|
296
|
+
import { JSX } from 'preact/jsx-runtime';
|
|
297
|
+
|
|
298
|
+
export interface ${componentName}Props extends JSX.SVGAttributes<SVGSVGElement> {
|
|
299
|
+
className?: string;
|
|
300
|
+
width?: string | number;
|
|
301
|
+
height?: string | number;
|
|
302
|
+
fill?: string;
|
|
303
|
+
stroke?: string;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const ${componentName}: FunctionComponent<${componentName}Props> = ({
|
|
307
|
+
className,
|
|
308
|
+
style,
|
|
309
|
+
width,
|
|
310
|
+
height,
|
|
311
|
+
fill,
|
|
312
|
+
stroke,
|
|
313
|
+
...props
|
|
314
|
+
}) => {
|
|
315
|
+
return (
|
|
316
|
+
<svg
|
|
317
|
+
class={className}
|
|
318
|
+
style={style}
|
|
319
|
+
width={width || ${attributes.width || 24}}
|
|
320
|
+
height={height || ${attributes.height || 24}}
|
|
321
|
+
fill={fill || '${attributes.fill || 'currentColor'}'}
|
|
322
|
+
stroke={stroke}
|
|
323
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
324
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
325
|
+
{...props}
|
|
326
|
+
>
|
|
327
|
+
${innerContent}
|
|
328
|
+
</svg>
|
|
329
|
+
);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
export default ${componentName};
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private generateLitComponent(componentName: string, svgContent: string, typescript: boolean): string {
|
|
337
|
+
const { attributes, innerContent } = this.parseSVG(svgContent);
|
|
338
|
+
const kebabName = this.toKebabCase(componentName);
|
|
339
|
+
|
|
340
|
+
return `import { LitElement, html, css, svg } from 'lit';
|
|
341
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
342
|
+
|
|
343
|
+
@customElement('${kebabName}')
|
|
344
|
+
export class ${componentName} extends LitElement {
|
|
345
|
+
@property({ type: String }) className = '';
|
|
346
|
+
@property({ type: String, reflect: true }) width = '${attributes.width || 24}';
|
|
347
|
+
@property({ type: String, reflect: true }) height = '${attributes.height || 24}';
|
|
348
|
+
@property({ type: String, reflect: true }) fill = '${attributes.fill || 'currentColor'}';
|
|
349
|
+
@property({ type: String, reflect: true }) stroke = '';
|
|
350
|
+
|
|
351
|
+
static styles = css\`:host { display: inline-block; }\`;
|
|
352
|
+
|
|
353
|
+
render() {
|
|
354
|
+
return svg\`
|
|
355
|
+
<svg
|
|
356
|
+
class="\${this.className}"
|
|
357
|
+
width="\${this.width}"
|
|
358
|
+
height="\${this.height}"
|
|
359
|
+
fill="\${this.fill}"
|
|
360
|
+
stroke="\${this.stroke}"
|
|
361
|
+
viewBox="${attributes.viewBox || '0 0 24 24'}"
|
|
362
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
363
|
+
>
|
|
364
|
+
${innerContent}
|
|
365
|
+
</svg>
|
|
366
|
+
\`;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
declare global {
|
|
371
|
+
interface HTMLElementTagNameMap {
|
|
372
|
+
'${kebabName}': ${componentName};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
`;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private generateVanillaComponent(componentName: string, svgContent: string, typescript: boolean): string {
|
|
379
|
+
const { attributes, innerContent} = this.parseSVG(svgContent);
|
|
380
|
+
return `export interface ${componentName}Options {
|
|
381
|
+
className?: string;
|
|
382
|
+
width?: string | number;
|
|
383
|
+
height?: string | number;
|
|
384
|
+
fill?: string;
|
|
385
|
+
stroke?: string;
|
|
386
|
+
[key: string]: any;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
export function ${componentName}(options: ${componentName}Options = {}): SVGSVGElement {
|
|
390
|
+
const {
|
|
391
|
+
className = '',
|
|
392
|
+
width = ${attributes.width || 24},
|
|
393
|
+
height = ${attributes.height || 24},
|
|
394
|
+
fill = '${attributes.fill || 'currentColor'}',
|
|
395
|
+
stroke = '',
|
|
396
|
+
...attrs
|
|
397
|
+
} = options;
|
|
398
|
+
|
|
399
|
+
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
400
|
+
svg.setAttribute('viewBox', '${attributes.viewBox || '0 0 24 24'}');
|
|
401
|
+
svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
|
|
402
|
+
|
|
403
|
+
if (className) svg.setAttribute('class', className);
|
|
404
|
+
svg.setAttribute('width', String(width));
|
|
405
|
+
svg.setAttribute('height', String(height));
|
|
406
|
+
svg.setAttribute('fill', fill);
|
|
407
|
+
if (stroke) svg.setAttribute('stroke', stroke);
|
|
408
|
+
|
|
409
|
+
Object.entries(attrs).forEach(([key, value]) => {
|
|
410
|
+
svg.setAttribute(key, String(value));
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
svg.innerHTML = \`${innerContent}\`;
|
|
414
|
+
|
|
415
|
+
return svg;
|
|
416
|
+
}
|
|
417
|
+
`;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
private toKebabCase(str: string): string {
|
|
421
|
+
return str
|
|
422
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
423
|
+
.replace(/([A-Z])([A-Z])([a-z])/g, '$1-$2$3')
|
|
424
|
+
.toLowerCase();
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export const frameworkTemplateEngine = new FrameworkTemplateEngine();
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Logger, LogLevel } from '../types/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Professional logging service with configurable levels and formatted output
|
|
5
|
+
*/
|
|
6
|
+
export class LoggerService implements Logger {
|
|
7
|
+
private static instance: LoggerService;
|
|
8
|
+
private logLevel: LogLevel = 'info';
|
|
9
|
+
private enableColors: boolean = true;
|
|
10
|
+
|
|
11
|
+
private constructor() {}
|
|
12
|
+
|
|
13
|
+
public static getInstance(): LoggerService {
|
|
14
|
+
if (!LoggerService.instance) {
|
|
15
|
+
LoggerService.instance = new LoggerService();
|
|
16
|
+
}
|
|
17
|
+
return LoggerService.instance;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public setLogLevel(level: LogLevel): void {
|
|
21
|
+
this.logLevel = level;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public setColors(enabled: boolean): void {
|
|
25
|
+
this.enableColors = enabled;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private shouldLog(level: LogLevel): boolean {
|
|
29
|
+
const levels: LogLevel[] = ['debug', 'info', 'warn', 'error'];
|
|
30
|
+
const currentIndex = levels.indexOf(this.logLevel);
|
|
31
|
+
const messageIndex = levels.indexOf(level);
|
|
32
|
+
return messageIndex >= currentIndex;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private formatMessage(level: LogLevel, message: string): string {
|
|
36
|
+
const timestamp = new Date().toISOString();
|
|
37
|
+
const prefix = this.getPrefix(level);
|
|
38
|
+
return `${timestamp} ${prefix} ${message}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private getPrefix(level: LogLevel): string {
|
|
42
|
+
if (!this.enableColors) {
|
|
43
|
+
return `[${level.toUpperCase()}]`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const colors = {
|
|
47
|
+
debug: '\x1b[36m', // Cyan
|
|
48
|
+
info: '\x1b[34m', // Blue
|
|
49
|
+
warn: '\x1b[33m', // Yellow
|
|
50
|
+
error: '\x1b[31m', // Red
|
|
51
|
+
success: '\x1b[32m', // Green
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const reset = '\x1b[0m';
|
|
55
|
+
const color = colors[level as keyof typeof colors] || colors.info;
|
|
56
|
+
|
|
57
|
+
const icons = {
|
|
58
|
+
debug: '🔍',
|
|
59
|
+
info: 'ℹ️',
|
|
60
|
+
warn: '⚠️',
|
|
61
|
+
error: '❌',
|
|
62
|
+
success: '✅',
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const icon = icons[level as keyof typeof icons] || icons.info;
|
|
66
|
+
return `${color}${icon} [${level.toUpperCase()}]${reset}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public debug(message: string, ...args: any[]): void {
|
|
70
|
+
if (this.shouldLog('debug')) {
|
|
71
|
+
console.debug(this.formatMessage('debug', message), ...args);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public info(message: string, ...args: any[]): void {
|
|
76
|
+
if (this.shouldLog('info')) {
|
|
77
|
+
console.info(this.formatMessage('info', message), ...args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public warn(message: string, ...args: any[]): void {
|
|
82
|
+
if (this.shouldLog('warn')) {
|
|
83
|
+
console.warn(this.formatMessage('warn', message), ...args);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public error(message: string, ...args: any[]): void {
|
|
88
|
+
if (this.shouldLog('error')) {
|
|
89
|
+
console.error(this.formatMessage('error', message), ...args);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public success(message: string, ...args: any[]): void {
|
|
94
|
+
if (this.shouldLog('info')) {
|
|
95
|
+
const timestamp = new Date().toISOString();
|
|
96
|
+
const prefix = this.getPrefix('info');
|
|
97
|
+
const successPrefix = this.enableColors ? '✅ [SUCCESS]' : '[SUCCESS]';
|
|
98
|
+
console.log(`${timestamp} ${successPrefix} ${message}`, ...args);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Export singleton instance
|
|
104
|
+
export const logger = LoggerService.getInstance();
|