@dsai-io/tools 0.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.
@@ -0,0 +1,473 @@
1
+ import { R as ResolvedConfig } from '../types-Idj08nad.js';
2
+
3
+ /**
4
+ * Icon system type definitions
5
+ *
6
+ * @packageDocumentation
7
+ */
8
+ /**
9
+ * Raw SVG data from file
10
+ */
11
+ interface RawSVGData {
12
+ /** File path (absolute) */
13
+ filePath: string;
14
+ /** File name without extension */
15
+ fileName: string;
16
+ /** SVG content string */
17
+ content: string;
18
+ /** Original file size in bytes */
19
+ originalSize: number;
20
+ }
21
+ /**
22
+ * Parsed SVG data
23
+ */
24
+ interface ParsedSVG {
25
+ /** Icon name (normalized) */
26
+ name: string;
27
+ /** Component name (PascalCase) */
28
+ componentName: string;
29
+ /** Original file name */
30
+ fileName: string;
31
+ /** SVG viewBox */
32
+ viewBox: string;
33
+ /** SVG width */
34
+ width?: string | number;
35
+ /** SVG height */
36
+ height?: string | number;
37
+ /** SVG inner content (without <svg> wrapper) */
38
+ innerContent: string;
39
+ /** Full SVG content */
40
+ fullContent: string;
41
+ /** SVG attributes */
42
+ attributes: Record<string, string>;
43
+ /** Title for accessibility */
44
+ title?: string;
45
+ /** Description for accessibility */
46
+ description?: string;
47
+ }
48
+ /**
49
+ * Optimized SVG data
50
+ */
51
+ interface OptimizedSVG extends ParsedSVG {
52
+ /** Optimized file size in bytes */
53
+ optimizedSize: number;
54
+ /** Size reduction percentage */
55
+ sizeReduction: number;
56
+ }
57
+ /**
58
+ * Generated icon component
59
+ */
60
+ interface GeneratedIcon {
61
+ /** Icon name */
62
+ name: string;
63
+ /** Component name */
64
+ componentName: string;
65
+ /** Generated code */
66
+ code: string;
67
+ /** Output file path */
68
+ outputPath: string;
69
+ /** Format (react, vue, svg) */
70
+ format: IconFormat;
71
+ }
72
+ /**
73
+ * Icon format
74
+ */
75
+ type IconFormat = 'react' | 'vue' | 'svg' | 'svg-sprite';
76
+ /**
77
+ * Icon build options
78
+ */
79
+ interface IconBuildOptions {
80
+ /** Formats to generate */
81
+ formats?: IconFormat[];
82
+ /** Watch for changes */
83
+ watch?: boolean;
84
+ /** Specific icons to build (file names) */
85
+ icons?: string[];
86
+ /** Dry run - don't write files */
87
+ dryRun?: boolean;
88
+ }
89
+ /**
90
+ * Icon build result
91
+ */
92
+ interface IconBuildResult {
93
+ /** Build successful */
94
+ success: boolean;
95
+ /** Generated icons */
96
+ icons: GeneratedIcon[];
97
+ /** Total icons processed */
98
+ totalIcons: number;
99
+ /** Files written */
100
+ filesWritten: number;
101
+ /** Total size reduction percentage */
102
+ totalSizeReduction: number;
103
+ /** Build errors */
104
+ errors: IconError[];
105
+ /** Build warnings */
106
+ warnings: IconWarning[];
107
+ /** Build duration in milliseconds */
108
+ duration: number;
109
+ }
110
+ /**
111
+ * Icon error
112
+ */
113
+ interface IconError {
114
+ /** Icon name */
115
+ icon: string;
116
+ /** Error message */
117
+ message: string;
118
+ /** Error code */
119
+ code: IconErrorCode;
120
+ }
121
+ /**
122
+ * Icon error codes
123
+ */
124
+ type IconErrorCode = 'SCAN_ERROR' | 'PARSE_ERROR' | 'OPTIMIZE_ERROR' | 'GENERATE_ERROR' | 'WRITE_ERROR' | 'BUILD_ERROR';
125
+ /**
126
+ * Icon warning
127
+ */
128
+ interface IconWarning {
129
+ /** Icon name */
130
+ icon: string;
131
+ /** Warning message */
132
+ message: string;
133
+ }
134
+ /**
135
+ * SVGO configuration
136
+ */
137
+ interface SVGOConfig {
138
+ /** Enable multipass optimization */
139
+ multipass?: boolean;
140
+ /** Plugins to use */
141
+ plugins?: SVGOPlugin[];
142
+ }
143
+ /**
144
+ * SVGO plugin configuration
145
+ */
146
+ interface SVGOPlugin {
147
+ /** Plugin name */
148
+ name: string;
149
+ /** Plugin parameters */
150
+ params?: Record<string, unknown>;
151
+ }
152
+ /**
153
+ * Icon template function
154
+ */
155
+ type IconTemplate = (icon: OptimizedSVG) => string;
156
+ /**
157
+ * Index template function
158
+ */
159
+ type IndexTemplate = (icons: OptimizedSVG[]) => string;
160
+ /**
161
+ * Types template function
162
+ */
163
+ type TypesTemplate = (icons: OptimizedSVG[]) => string;
164
+ /**
165
+ * Scanner options
166
+ */
167
+ interface ScannerOptions {
168
+ /** Source directory */
169
+ sourceDir: string;
170
+ /** Glob patterns to include */
171
+ include?: string[];
172
+ /** Glob patterns to exclude */
173
+ exclude?: string[];
174
+ }
175
+ /**
176
+ * Generator options
177
+ */
178
+ interface GeneratorOptions {
179
+ /** Custom icon template */
180
+ template?: IconTemplate;
181
+ /** Custom index template */
182
+ indexTemplate?: IndexTemplate;
183
+ /** Custom types template */
184
+ typesTemplate?: TypesTemplate;
185
+ /** Dry run - don't write files */
186
+ dryRun?: boolean;
187
+ }
188
+
189
+ /**
190
+ * SVG file scanner
191
+ *
192
+ * Scans directories for SVG files and reads their contents.
193
+ *
194
+ * @packageDocumentation
195
+ */
196
+
197
+ /**
198
+ * Scan directory for SVG files
199
+ *
200
+ * Uses fast-glob to find SVG files matching the specified patterns.
201
+ *
202
+ * @param options - Scanner options
203
+ * @returns Array of raw SVG data
204
+ *
205
+ * @example
206
+ * ```typescript
207
+ * const files = await scanSVGFiles({
208
+ * sourceDir: './icons',
209
+ * include: ['**\/*.svg'],
210
+ * exclude: ['**\/node_modules\/**'],
211
+ * });
212
+ * ```
213
+ */
214
+ declare function scanSVGFiles(options: ScannerOptions): Promise<RawSVGData[]>;
215
+ /**
216
+ * Read a single SVG file
217
+ *
218
+ * @param filePath - Path to SVG file
219
+ * @returns Raw SVG data or null if failed
220
+ */
221
+ declare function readSVGFile(filePath: string): RawSVGData | null;
222
+
223
+ /**
224
+ * SVG parser
225
+ *
226
+ * Parses SVG content into structured data.
227
+ *
228
+ * @packageDocumentation
229
+ */
230
+
231
+ /**
232
+ * Parse raw SVG data into structured format
233
+ *
234
+ * Extracts viewBox, attributes, inner content, and accessibility info.
235
+ *
236
+ * @param raw - Raw SVG data
237
+ * @returns Parsed SVG data
238
+ */
239
+ declare function parseSVG(raw: RawSVGData): ParsedSVG;
240
+ /**
241
+ * Parse multiple SVG files
242
+ *
243
+ * @param rawFiles - Array of raw SVG data
244
+ * @returns Array of parsed SVG data
245
+ */
246
+ declare function parseSVGFiles(rawFiles: RawSVGData[]): ParsedSVG[];
247
+ /**
248
+ * Clean SVG content for React compatibility
249
+ *
250
+ * Converts kebab-case attributes to camelCase for JSX.
251
+ *
252
+ * @param svg - SVG content string
253
+ * @returns Cleaned SVG content
254
+ */
255
+ declare function cleanSVGForReact(svg: string): string;
256
+ /**
257
+ * Extract viewBox from SVG string
258
+ *
259
+ * @param svg - SVG content string
260
+ * @returns ViewBox string or default
261
+ */
262
+ declare function extractViewBox(svg: string): string;
263
+
264
+ /**
265
+ * SVG optimizer (SVGO integration)
266
+ *
267
+ * Optimizes SVG files using SVGO for smaller file sizes.
268
+ *
269
+ * @packageDocumentation
270
+ */
271
+
272
+ /**
273
+ * Default SVGO configuration
274
+ *
275
+ * Provides sensible defaults for icon optimization.
276
+ */
277
+ declare const defaultSVGOConfig: SVGOConfig;
278
+ /**
279
+ * Optimize a single SVG
280
+ *
281
+ * @param parsed - Parsed SVG data
282
+ * @param raw - Raw SVG data (for size comparison)
283
+ * @param config - SVGO configuration
284
+ * @returns Optimized SVG data
285
+ */
286
+ declare function optimizeSVG(parsed: ParsedSVG, raw: RawSVGData, config?: SVGOConfig): Promise<OptimizedSVG>;
287
+ /**
288
+ * Optimize multiple SVGs
289
+ *
290
+ * @param parsedFiles - Array of parsed SVG data
291
+ * @param rawFiles - Array of raw SVG data
292
+ * @param config - SVGO configuration
293
+ * @returns Array of optimized SVG data
294
+ */
295
+ declare function optimizeSVGFiles(parsedFiles: ParsedSVG[], rawFiles: RawSVGData[], config?: SVGOConfig): Promise<OptimizedSVG[]>;
296
+ /**
297
+ * Skip optimization and just add size metadata
298
+ *
299
+ * Useful when SVGO is not needed but the type structure is required.
300
+ *
301
+ * @param parsed - Parsed SVG data
302
+ * @param raw - Raw SVG data
303
+ * @returns Optimized SVG data (without actual optimization)
304
+ */
305
+ declare function skipOptimization(parsed: ParsedSVG, raw: RawSVGData): OptimizedSVG;
306
+
307
+ /**
308
+ * React component generator
309
+ *
310
+ * Generates React icon components from optimized SVG data.
311
+ *
312
+ * @packageDocumentation
313
+ */
314
+
315
+ /**
316
+ * Default React icon template
317
+ *
318
+ * Generates a forwardRef component with size, title, and aria support.
319
+ */
320
+ declare const defaultReactTemplate: IconTemplate;
321
+ /**
322
+ * Default React index template
323
+ *
324
+ * Exports all icon components from a single entry point.
325
+ */
326
+ declare const defaultReactIndexTemplate: IndexTemplate;
327
+ /**
328
+ * Default React types template
329
+ *
330
+ * Generates TypeScript types for all icons.
331
+ */
332
+ declare const defaultReactTypesTemplate: TypesTemplate;
333
+ /**
334
+ * Generate React icon components
335
+ *
336
+ * @param icons - Optimized SVG data
337
+ * @param outputDir - Output directory
338
+ * @param options - Generator options
339
+ * @returns Generated icons
340
+ *
341
+ * @example
342
+ * ```typescript
343
+ * const generated = await generateReactIcons(optimizedIcons, './dist/icons/react', {
344
+ * dryRun: false,
345
+ * });
346
+ * console.log(\`Generated \${generated.length} files\`);
347
+ * ```
348
+ */
349
+ declare function generateReactIcons(icons: OptimizedSVG[], outputDir: string, options?: GeneratorOptions): Promise<GeneratedIcon[]>;
350
+
351
+ /**
352
+ * SVG sprite generator
353
+ *
354
+ * Generates SVG sprite files with symbol definitions.
355
+ *
356
+ * @packageDocumentation
357
+ */
358
+
359
+ /**
360
+ * SVG sprite generator options
361
+ */
362
+ interface SpriteOptions {
363
+ /** Sprite file name */
364
+ fileName?: string;
365
+ /** Generate preview HTML file */
366
+ generatePreview?: boolean;
367
+ /** Dry run - don't write files */
368
+ dryRun?: boolean;
369
+ }
370
+ /**
371
+ * Generate SVG sprite
372
+ *
373
+ * Creates an SVG sprite with symbol definitions for all icons.
374
+ *
375
+ * @param icons - Optimized SVG data
376
+ * @param outputDir - Output directory
377
+ * @param options - Generator options
378
+ * @returns Generated files
379
+ *
380
+ * @example
381
+ * ```typescript
382
+ * const generated = await generateSVGSprite(optimizedIcons, './dist/icons/sprite', {
383
+ * fileName: 'icons.svg',
384
+ * generatePreview: true,
385
+ * });
386
+ * ```
387
+ */
388
+ declare function generateSVGSprite(icons: OptimizedSVG[], outputDir: string, options?: SpriteOptions): Promise<GeneratedIcon[]>;
389
+
390
+ /**
391
+ * Icon naming utilities
392
+ *
393
+ * @packageDocumentation
394
+ */
395
+ /**
396
+ * Convert string to PascalCase component name
397
+ *
398
+ * @param input - Input string (e.g., file name)
399
+ * @returns PascalCase component name
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * toComponentName('arrow-left') // 'ArrowLeft'
404
+ * toComponentName('24px-icon') // 'Icon24px'
405
+ * toComponentName('my_icon') // 'MyIcon'
406
+ * toComponentName('chevron-down-small') // 'ChevronDownSmall'
407
+ * ```
408
+ */
409
+ declare function toComponentName(input: string): string;
410
+ /**
411
+ * Convert string to kebab-case icon name
412
+ *
413
+ * @param input - Input string (e.g., component name)
414
+ * @returns kebab-case icon name
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * toIconName('ArrowLeft') // 'arrow-left'
419
+ * toIconName('ChevronDownSmall') // 'chevron-down-small'
420
+ * toIconName('Icon24px') // 'icon-24px'
421
+ * ```
422
+ */
423
+ declare function toIconName(input: string): string;
424
+ /**
425
+ * Validate icon name
426
+ *
427
+ * @param name - Icon name to validate
428
+ * @returns True if valid, false otherwise
429
+ */
430
+ declare function isValidIconName(name: string): boolean;
431
+ /**
432
+ * Normalize icon name from file name
433
+ *
434
+ * @param fileName - File name (without extension)
435
+ * @returns Normalized icon name
436
+ */
437
+ declare function normalizeIconName(fileName: string): string;
438
+
439
+ /**
440
+ * Icon tooling module for @dsai-io/tools
441
+ *
442
+ * Provides utilities for generating icon components from SVG source files.
443
+ * Supports React components, SVG sprites, with SVGO optimization.
444
+ *
445
+ * @packageDocumentation
446
+ */
447
+
448
+ /**
449
+ * Build icons from SVG source files
450
+ *
451
+ * Scans the source directory, parses and optimizes SVGs, then generates
452
+ * output in the specified formats (React, SVG sprite).
453
+ *
454
+ * @param config - Resolved DSAi configuration
455
+ * @param options - Build options
456
+ * @returns Build result with generated files
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * import { loadConfig } from '@dsai-io/tools/config';
461
+ * import { buildIcons } from '@dsai-io/tools/icons';
462
+ *
463
+ * const { config } = await loadConfig();
464
+ * const result = await buildIcons(config, {
465
+ * formats: ['react', 'svg-sprite'],
466
+ * });
467
+ *
468
+ * console.log(\`Generated \${result.totalIcons} icons\`);
469
+ * ```
470
+ */
471
+ declare function buildIcons(config: ResolvedConfig, options?: IconBuildOptions): Promise<IconBuildResult>;
472
+
473
+ export { type GeneratedIcon, type GeneratorOptions, type IconBuildOptions, type IconBuildResult, type IconError, type IconErrorCode, type IconFormat, type IconTemplate, type IconWarning, type IndexTemplate, type OptimizedSVG, type ParsedSVG, type RawSVGData, type SVGOConfig, type SVGOPlugin, type ScannerOptions, type TypesTemplate, buildIcons, cleanSVGForReact, defaultReactIndexTemplate, defaultReactTemplate, defaultReactTypesTemplate, defaultSVGOConfig, extractViewBox, generateReactIcons, generateSVGSprite, isValidIconName, normalizeIconName, optimizeSVG, optimizeSVGFiles, parseSVG, parseSVGFiles, readSVGFile, scanSVGFiles, skipOptimization, toComponentName, toIconName };