@stacksjs/iconify-generator 0.2.27 → 0.2.89

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/dist/index.js ADDED
@@ -0,0 +1,720 @@
1
+ // @bun
2
+ var __require = import.meta.require;
3
+
4
+ // src/index.ts
5
+ import { mkdir, writeFile } from "fs/promises";
6
+ import { join } from "path";
7
+ var ICONIFY_API = "https://api.iconify.design";
8
+ async function fetchCollections() {
9
+ const response = await fetch(`${ICONIFY_API}/collections`);
10
+ if (!response.ok) {
11
+ throw new Error(`Failed to fetch collections: ${response.statusText}`);
12
+ }
13
+ return await response.json();
14
+ }
15
+ async function fetchCollectionIcons(prefix, icons) {
16
+ try {
17
+ const iconifyJsonPath = __require.resolve("/home/runner/work/stx/stx/node_modules/@iconify/json/dist/index.cjs");
18
+ const basePath = `${iconifyJsonPath.substring(0, iconifyJsonPath.lastIndexOf("/node_modules/@iconify/json/"))}/node_modules/@iconify/json`;
19
+ const jsonPath = `${basePath}/json/${prefix}.json`;
20
+ const file = Bun.file(jsonPath);
21
+ if (await file.exists()) {
22
+ const data = await file.json();
23
+ if (icons && icons.length > 0) {
24
+ const filteredIcons = {};
25
+ for (const iconName of icons) {
26
+ if (data.icons[iconName]) {
27
+ filteredIcons[iconName] = data.icons[iconName];
28
+ }
29
+ }
30
+ return {
31
+ ...data,
32
+ icons: filteredIcons
33
+ };
34
+ }
35
+ return data;
36
+ }
37
+ } catch {}
38
+ const url = icons && icons.length > 0 ? `${ICONIFY_API}/${prefix}.json?icons=${icons.join(",")}` : `${ICONIFY_API}/${prefix}.json`;
39
+ const response = await fetch(url);
40
+ if (!response.ok) {
41
+ throw new Error(`Failed to fetch icons for ${prefix}: ${response.statusText}`);
42
+ }
43
+ return await response.json();
44
+ }
45
+ function convertIconData(data, defaultWidth = 24, defaultHeight = 24) {
46
+ return {
47
+ body: data.body,
48
+ width: data.width || defaultWidth,
49
+ height: data.height || defaultHeight,
50
+ viewBox: `0 0 ${data.width || defaultWidth} ${data.height || defaultHeight}`
51
+ };
52
+ }
53
+ function generateIconData(name, iconData) {
54
+ const camelCaseName = toCamelCase(name);
55
+ return `import type { IconData } from '@stacksjs/iconify-core'
56
+
57
+ export const ${camelCaseName}: IconData = ${JSON.stringify(iconData, null, 2)}
58
+
59
+ export default ${camelCaseName}
60
+ `;
61
+ }
62
+ function generateIconComponent(_name, iconData) {
63
+ return `<script>
64
+ // Get props with defaults (handle undefined)
65
+ const iconWidth = (typeof width !== 'undefined' ? width : null) || (typeof size !== 'undefined' ? size : null) || ${iconData.width || 24}
66
+ const iconHeight = (typeof height !== 'undefined' ? height : null) || (typeof size !== 'undefined' ? size : null) || ${iconData.height || 24}
67
+ const iconColor = typeof color !== 'undefined' ? color : 'currentColor'
68
+ const viewBox = "${iconData.viewBox || `0 0 ${iconData.width || 24} ${iconData.height || 24}`}"
69
+
70
+ // Build transform
71
+ const transforms = []
72
+ if (typeof hFlip !== 'undefined' && hFlip) transforms.push('scaleX(-1)')
73
+ if (typeof vFlip !== 'undefined' && vFlip) transforms.push('scaleY(-1)')
74
+ if (typeof rotate !== 'undefined' && rotate) {
75
+ const rotateNum = typeof rotate === 'string' ? parseInt(rotate, 10) : rotate
76
+ const deg = typeof rotateNum === 'number' && rotateNum < 4 ? rotateNum * 90 : rotateNum
77
+ transforms.push(\`rotate(\${deg}deg)\`)
78
+ }
79
+
80
+ const transform = transforms.length > 0 ? transforms.join(' ') : ''
81
+ const transformStyle = transform ? \`transform: \${transform};\` : ''
82
+
83
+ // Build style
84
+ const styles = []
85
+ if (transformStyle) styles.push(transformStyle)
86
+ if (typeof style !== 'undefined' && style) styles.push(style)
87
+
88
+ const styleAttr = styles.length > 0 ? \` style="\${styles.join(' ')}"\` : ''
89
+ const classAttr = typeof className !== 'undefined' && className ? \` class="\${className}"\` : ''
90
+
91
+ // Icon body
92
+ let body = ${JSON.stringify(iconData.body)}
93
+ if (iconColor && iconColor !== 'currentColor') {
94
+ body = body.replace(/currentColor/g, iconColor)
95
+ }
96
+
97
+ // Generate SVG
98
+ const svg = \`<svg xmlns="http://www.w3.org/2000/svg" width="\${iconWidth}" height="\${iconHeight}" viewBox="\${viewBox}"\${classAttr}\${styleAttr}>\${body}</svg>\`
99
+ </script>
100
+
101
+ {!! svg !!}
102
+ `;
103
+ }
104
+ function generateIndexFile(iconNames) {
105
+ const used = new Set;
106
+ const dataExports = iconNames.map((name) => {
107
+ const primary = toCamelCase(name);
108
+ let id = primary;
109
+ if (used.has(id)) {
110
+ let candidate = name.replace(/[^a-zA-Z0-9]/g, "_");
111
+ if (/^[0-9]/.test(candidate))
112
+ candidate = `_${candidate}`;
113
+ id = candidate;
114
+ let n = 2;
115
+ while (used.has(id)) {
116
+ id = `${candidate}_${n}`;
117
+ n++;
118
+ }
119
+ }
120
+ used.add(id);
121
+ return `export { default as ${id} } from './${name}.js'`;
122
+ }).join(`
123
+ `);
124
+ return `// Icon data exports
125
+ ${dataExports}
126
+
127
+ export * from './types.js'
128
+ `;
129
+ }
130
+ function generateTypesFile(prefix) {
131
+ return `import type { IconData, IconProps } from '@stacksjs/iconify-core'
132
+
133
+ export type { IconData, IconProps }
134
+
135
+ export type ${toPascalCase(prefix)}Icon = IconData
136
+ `;
137
+ }
138
+ function generatePackageJson(prefix, collectionInfo, _iconCount) {
139
+ const packageJson = {
140
+ name: `@stacksjs/iconify-${prefix}`,
141
+ type: "module",
142
+ version: "0.0.1",
143
+ description: `${collectionInfo.name} icons for stx from Iconify`,
144
+ author: collectionInfo.author?.name || "Iconify",
145
+ license: collectionInfo.license?.spdx || "MIT",
146
+ repository: {
147
+ type: "git",
148
+ url: "https://github.com/stacksjs/stx.git",
149
+ directory: `packages/iconify-${prefix}`
150
+ },
151
+ keywords: [
152
+ "iconify",
153
+ "icons",
154
+ "svg",
155
+ prefix,
156
+ collectionInfo.name,
157
+ "stx"
158
+ ],
159
+ sideEffects: false,
160
+ exports: {
161
+ ".": {
162
+ types: "./dist/index.d.ts",
163
+ import: "./dist/index.js"
164
+ },
165
+ "./*": "./dist/*"
166
+ },
167
+ main: "./dist/index.js",
168
+ module: "./dist/index.js",
169
+ types: "./dist/index.d.ts",
170
+ files: [
171
+ "dist"
172
+ ],
173
+ scripts: {
174
+ build: "bun build.ts",
175
+ prepublishOnly: "bun build.ts"
176
+ },
177
+ dependencies: {
178
+ "@stacksjs/iconify-core": "workspace:*"
179
+ }
180
+ };
181
+ return JSON.stringify(packageJson, null, 2);
182
+ }
183
+ function generateBuildFile(prefix) {
184
+ return `import { existsSync, readdirSync, statSync } from 'node:fs'
185
+ import { dirname, join } from 'node:path'
186
+ import { fileURLToPath } from 'node:url'
187
+ import dts from 'bun-plugin-dtsx'
188
+
189
+ const __dirname = dirname(fileURLToPath(import.meta.url))
190
+ const srcDir = join(__dirname, 'src')
191
+ const distDir = join(__dirname, 'dist')
192
+ const distEntry = join(distDir, 'index.js')
193
+
194
+ // Skip rebuild when dist is already up to date. Makes prepublishOnly a
195
+ // no-op when CI pre-built the package in parallel earlier in the
196
+ // pipeline \u2014 and a no-op for local re-runs that didn't touch src/.
197
+ //
198
+ // Walks src/ recursively so changes inside subdirectories (if we ever
199
+ // add them) properly invalidate the cached dist.
200
+ function isDistFresh() {
201
+ if (!existsSync(distEntry)) return false
202
+ const distMtime = statSync(distEntry).mtimeMs
203
+ function newer(dir) {
204
+ for (const name of readdirSync(dir)) {
205
+ const p = join(dir, name)
206
+ const s = statSync(p)
207
+ if (s.isDirectory()) {
208
+ if (newer(p)) return true
209
+ } else if (s.mtimeMs > distMtime) {
210
+ return true
211
+ }
212
+ }
213
+ return false
214
+ }
215
+ return !newer(srcDir)
216
+ }
217
+
218
+ if (isDistFresh()) {
219
+ console.log('\u2713 @stacksjs/iconify-${prefix} dist is fresh, skipping rebuild')
220
+ } else {
221
+ await Bun.build({
222
+ entrypoints: [join(srcDir, 'index.ts')],
223
+ outdir: distDir,
224
+ target: 'bun',
225
+ format: 'esm',
226
+ plugins: [dts()],
227
+ minify: false,
228
+ sourcemap: 'external',
229
+ splitting: true,
230
+ })
231
+ console.log('\u2713 Built @stacksjs/iconify-${prefix}')
232
+ }
233
+ `;
234
+ }
235
+ function generateReadme(prefix, collectionInfo, iconCount) {
236
+ return `# @stacksjs/iconify-${prefix}
237
+
238
+ ${collectionInfo.name} icons for stx from Iconify.
239
+
240
+ ## Installation
241
+
242
+ \`\`\`bash
243
+ bun add @stacksjs/iconify-${prefix}
244
+ \`\`\`
245
+
246
+ ## Usage
247
+
248
+ ### In stx templates
249
+
250
+ \`\`\`html
251
+ <script>
252
+ import { home } from '@stacksjs/iconify-${prefix}'
253
+ import { renderIcon } from '@stacksjs/iconify-core'
254
+
255
+ export const homeIcon = renderIcon(home, { size: 24, color: 'currentColor' })
256
+ </script>
257
+
258
+ <div class="icon">
259
+ {!! homeIcon !!}
260
+ </div>
261
+ \`\`\`
262
+
263
+ ### In TypeScript/JavaScript
264
+
265
+ \`\`\`typescript
266
+ import { home, account, settings } from '@stacksjs/iconify-${prefix}'
267
+ import { renderIcon } from '@stacksjs/iconify-core'
268
+
269
+ const svg = renderIcon(home, {
270
+ size: 24,
271
+ color: '#000000',
272
+ })
273
+ \`\`\`
274
+
275
+ ## Available Icons
276
+
277
+ This package contains ${iconCount} icons from ${collectionInfo.name}.
278
+
279
+ ## License
280
+
281
+ ${collectionInfo.license?.title || "MIT"}
282
+
283
+ ${collectionInfo.license?.url ? `License: ${collectionInfo.license.url}` : ""}
284
+
285
+ ## Credits
286
+
287
+ - Icons: ${collectionInfo.author?.name || "Iconify"}${collectionInfo.author?.url ? ` (${collectionInfo.author.url})` : ""}
288
+ - Iconify: https://iconify.design/
289
+ `;
290
+ }
291
+ function generateDocumentation(prefix, collectionInfo, iconNames) {
292
+ const iconCount = iconNames.length;
293
+ const exampleIcons = iconNames.slice(0, 5).map(toCamelCase);
294
+ const exampleComponents = exampleIcons.map((name) => `${name.charAt(0).toUpperCase()}${name.slice(1)}Icon`);
295
+ const allIconsList = iconNames.map((name) => {
296
+ const camelName = toCamelCase(name);
297
+ return `- \`${camelName}\``;
298
+ }).join(`
299
+ `);
300
+ return `# ${collectionInfo.name}
301
+
302
+ > ${collectionInfo.name} icons for stx from Iconify
303
+
304
+ ## Overview
305
+
306
+ This package provides access to ${iconCount} icons from the ${collectionInfo.name} collection through the stx iconify integration.
307
+
308
+ **Collection ID:** \`${prefix}\`
309
+ **Total Icons:** ${iconCount}
310
+ ${collectionInfo.author?.name ? `**Author:** ${collectionInfo.author.name}${collectionInfo.author.url ? ` ([Website](${collectionInfo.author.url}))` : ""}` : ""}
311
+ ${collectionInfo.license?.title ? `**License:** ${collectionInfo.license.title}${collectionInfo.license.url ? ` ([Details](${collectionInfo.license.url}))` : ""}` : ""}
312
+ ${collectionInfo.category ? `**Category:** ${collectionInfo.category}` : ""}
313
+ ${collectionInfo.palette !== undefined ? `**Palette:** ${collectionInfo.palette ? "Yes (color icons)" : "No (monotone icons)"}` : ""}
314
+
315
+ ## Installation
316
+
317
+ \`\`\`bash
318
+ bun add @stacksjs/iconify-${prefix}
319
+ \`\`\`
320
+
321
+ ## Quick Start
322
+
323
+ ### Component Usage (Recommended)
324
+
325
+ Icons are available as .stx components that can be used directly in templates:
326
+
327
+ \`\`\`html
328
+ <${exampleComponents[0] || "Icon"} height="1em" />
329
+ <${exampleComponents[0] || "Icon"} width="1em" height="1em" />
330
+ <${exampleComponents[0] || "Icon"} height="24" />
331
+ \`\`\`
332
+
333
+ ### With Properties
334
+
335
+ \`\`\`html
336
+ <!-- Using size property -->
337
+ <${exampleComponents[0] || "Icon"} size="24" />
338
+ <${exampleComponents[0] || "Icon"} size="1em" />
339
+
340
+ <!-- Using width and height -->
341
+ <${exampleComponents[0] || "Icon"} width="24" height="32" />
342
+
343
+ <!-- With color -->
344
+ <${exampleComponents[0] || "Icon"} size="24" color="red" />
345
+ <${exampleComponents[0] || "Icon"} size="24" color="#4a90e2" />
346
+
347
+ <!-- With CSS class -->
348
+ <${exampleComponents[0] || "Icon"} size="24" class="icon-primary" />
349
+
350
+ <!-- With all properties -->
351
+ <${exampleComponents[0] || "Icon"}
352
+ size="32"
353
+ color="#4a90e2"
354
+ class="my-icon"
355
+ style="opacity: 0.8;"
356
+ />
357
+ \`\`\`
358
+
359
+ ### In stx Templates
360
+
361
+ \`\`\`html
362
+ <!DOCTYPE html>
363
+ <html>
364
+ <head>
365
+ <title>Icon Demo</title>
366
+ <style>
367
+ .icon-grid {
368
+ display: flex;
369
+ gap: 1rem;
370
+ align-items: center;
371
+ }
372
+ </style>
373
+ </head>
374
+ <body>
375
+ <div class="icon-grid">
376
+ <${exampleComponents[0] || "Icon"} size="24" />
377
+ <${exampleComponents[1] || "Icon"} size="24" color="#4a90e2" />
378
+ <${exampleComponents[2] || "Icon"} size="32" class="my-icon" />
379
+ </div>
380
+ </body>
381
+ </html>
382
+ \`\`\`
383
+
384
+ ### Data-Only Import
385
+
386
+ You can also import icon data and use the \`renderIcon\` function directly:
387
+
388
+ \`\`\`typescript
389
+ import { ${exampleIcons.slice(0, 3).join(", ")} } from '@stacksjs/iconify-${prefix}'
390
+ import { renderIcon } from '@stacksjs/iconify-core'
391
+
392
+ const svg = renderIcon(${exampleIcons[0] || "icon"}, { size: 24 })
393
+ \`\`\`
394
+
395
+ ## Icon Properties
396
+
397
+ All icon component functions and \`renderIcon\` accept the following properties:
398
+
399
+ | Property | Type | Default | Description |
400
+ |----------|------|---------|-------------|
401
+ | \`size\` | \`string \\| number\` | - | Icon size (sets both width and height) |
402
+ | \`width\` | \`string \\| number\` | - | Icon width (overrides size) |
403
+ | \`height\` | \`string \\| number\` | - | Icon height (overrides size) |
404
+ | \`color\` | \`string\` | \`'currentColor'\` | Icon color (CSS color or hex) |
405
+ | \`hFlip\` | \`boolean\` | \`false\` | Flip horizontally |
406
+ | \`vFlip\` | \`boolean\` | \`false\` | Flip vertically |
407
+ | \`rotate\` | \`0 \\| 90 \\| 180 \\| 270\` | \`0\` | Rotation in degrees |
408
+ | \`class\` | \`string\` | - | Additional CSS classes |
409
+ | \`style\` | \`string\` | - | Inline styles |
410
+
411
+ ## Color
412
+
413
+ ${collectionInfo.palette ? `### Color Icons
414
+
415
+ This collection contains color icons. While you can still set a color property, it may override the original colors.` : "### Monotone Icons\n\nMonotone icons use `currentColor` by default, allowing you to change icon color via the `color` property or CSS:"}
416
+
417
+ \`\`\`html
418
+ <!-- Via color property -->
419
+ <${exampleComponents[0] || "Icon"} size="24" color="red" />
420
+ <${exampleComponents[0] || "Icon"} size="24" color="#4a90e2" />
421
+
422
+ <!-- Via inline style -->
423
+ <${exampleComponents[0] || "Icon"} size="24" style="color: green;" />
424
+
425
+ <!-- Via CSS class -->
426
+ <${exampleComponents[0] || "Icon"} size="24" class="text-primary" />
427
+ \`\`\`
428
+
429
+ ${!collectionInfo.palette ? `\`\`\`css
430
+ /* In your CSS */
431
+ .text-primary {
432
+ color: #4a90e2;
433
+ }
434
+
435
+ .icon:hover {
436
+ color: #357abd;
437
+ }
438
+ \`\`\`` : ""}
439
+
440
+ ## Size
441
+
442
+ Unlike other components, SVG + CSS components do not set icon size by default. This has advantages and disadvantages.
443
+
444
+ **Disadvantages:**
445
+ - You need to set size yourself.
446
+
447
+ **Advantages:**
448
+ - You have full control over icon size.
449
+
450
+ You can change icon size by:
451
+ - Setting \`width\` and \`height\` properties
452
+ - Using CSS
453
+
454
+ ### Properties
455
+
456
+ All icon components support \`width\` and \`height\` properties.
457
+
458
+ Value is a string or number.
459
+
460
+ You do not need to set both properties. If you set one property, the other property will automatically be calculated from the icon's width/height ratio.
461
+
462
+ **Examples:**
463
+
464
+ \`\`\`html
465
+ <${exampleComponents[0] || "DraftsIcon"} height="1em" />
466
+ <${exampleComponents[0] || "DraftsIcon"} width="1em" height="1em" />
467
+ <${exampleComponents[0] || "DraftsIcon"} height="24" />
468
+ \`\`\`
469
+
470
+ You can also use the \`size\` property as a shorthand for setting both width and height:
471
+
472
+ \`\`\`html
473
+ <${exampleComponents[0] || "DraftsIcon"} size="24" />
474
+ <${exampleComponents[0] || "DraftsIcon"} size="1em" />
475
+ \`\`\`
476
+
477
+ ### CSS Sizing
478
+
479
+ You can also control icon size via CSS:
480
+
481
+ \`\`\`css
482
+ .${toCamelCase(prefix)}-icon {
483
+ width: 1em;
484
+ height: 1em;
485
+ }
486
+ \`\`\`
487
+
488
+ \`\`\`html
489
+ <${exampleComponents[0] || "DraftsIcon"} class="${toCamelCase(prefix)}-icon" />
490
+ \`\`\`
491
+
492
+ ## Available Icons
493
+
494
+ This package contains **${iconCount}** icons:
495
+
496
+ ${allIconsList}
497
+
498
+ ## Usage Examples
499
+
500
+ ### Navigation Menu
501
+
502
+ \`\`\`html
503
+ <nav>
504
+ <a href="/"><${exampleComponents[0] || "Icon"} size="20" class="nav-icon" /> Home</a>
505
+ <a href="/about"><${exampleComponents[1] || "Icon"} size="20" class="nav-icon" /> About</a>
506
+ <a href="/contact"><${exampleComponents[2] || "Icon"} size="20" class="nav-icon" /> Contact</a>
507
+ <a href="/settings"><${exampleComponents[3] || "Icon"} size="20" class="nav-icon" /> Settings</a>
508
+ </nav>
509
+
510
+ <style>
511
+ nav {
512
+ display: flex;
513
+ gap: 1rem;
514
+ }
515
+ nav a {
516
+ display: flex;
517
+ align-items: center;
518
+ gap: 0.5rem;
519
+ }
520
+ .nav-icon {
521
+ color: currentColor;
522
+ }
523
+ </style>
524
+ \`\`\`
525
+
526
+ ### Custom Styling
527
+
528
+ \`\`\`html
529
+ <${exampleComponents[0] || "Icon"}
530
+ size="24"
531
+ class="icon icon-primary"
532
+ style="opacity: 0.8; transition: opacity 0.2s;"
533
+ />
534
+
535
+ <style>
536
+ .icon-primary {
537
+ color: #4a90e2;
538
+ }
539
+ .icon-primary:hover {
540
+ opacity: 1;
541
+ }
542
+ </style>
543
+ \`\`\`
544
+
545
+ ### Status Indicators
546
+
547
+ \`\`\`html
548
+ <div class="status-grid">
549
+ <div class="status-item">
550
+ <${exampleComponents[0] || "Icon"} size="16" color="#22c55e" />
551
+ <span>Success</span>
552
+ </div>
553
+ <div class="status-item">
554
+ <${exampleComponents[1] || "Icon"} size="16" color="#f59e0b" />
555
+ <span>Warning</span>
556
+ </div>
557
+ <div class="status-item">
558
+ <${exampleComponents[2] || "Icon"} size="16" color="#ef4444" />
559
+ <span>Error</span>
560
+ </div>
561
+ </div>
562
+ \`\`\`
563
+
564
+ ## Best Practices
565
+
566
+ 1. **Use Components Directly**: Import and use icon components in your templates
567
+ \`\`\`html
568
+ <!-- Recommended -->
569
+ <${exampleComponents[0] || "Icon"} size="24" />
570
+ <${exampleComponents[1] || "Icon"} size="24" color="#4a90e2" />
571
+ \`\`\`
572
+
573
+ 2. **Use CSS for Theming**: Apply consistent styling through CSS classes
574
+ \`\`\`css
575
+ .icon {
576
+ color: currentColor;
577
+ opacity: 0.8;
578
+ transition: opacity 0.2s;
579
+ }
580
+
581
+ .icon:hover {
582
+ opacity: 1;
583
+ }
584
+ \`\`\`
585
+
586
+ \`\`\`html
587
+ <${exampleComponents[0] || "Icon"} size="24" class="icon" />
588
+ \`\`\`
589
+
590
+ 3. **Set Appropriate Sizes**: Use \`1em\` for inline icons, fixed pixel sizes for standalone icons
591
+ \`\`\`html
592
+ <!-- Inline with text -->
593
+ <p>Click the <${exampleComponents[0] || "Icon"} height="1em" /> icon to continue</p>
594
+
595
+ <!-- Standalone -->
596
+ <${exampleComponents[0] || "Icon"} size="24" />
597
+ \`\`\`
598
+
599
+ 4. **Use Data Import for Advanced Use Cases**: When you need more control
600
+ \`\`\`html
601
+ @js
602
+ import { ${exampleIcons[0] || "icon"} } from '@stacksjs/iconify-${prefix}'
603
+ import { renderIcon } from '@stacksjs/iconify-core'
604
+ global.customIcon = renderIcon(${exampleIcons[0] || "icon"}, { size: 24 })
605
+ @endjs
606
+
607
+ {!! customIcon !!}
608
+ \`\`\`
609
+
610
+ ## TypeScript Support
611
+
612
+ This package includes full TypeScript support with type definitions for all icons.
613
+
614
+ \`\`\`typescript
615
+ import type { IconData } from '@stacksjs/iconify-core'
616
+ import { ${exampleIcons[0] || "icon"} } from '@stacksjs/iconify-${prefix}'
617
+
618
+ // Icons are typed as IconData
619
+ const myIcon: IconData = ${exampleIcons[0] || "icon"}
620
+ \`\`\`
621
+
622
+ ## Related Packages
623
+
624
+ - [\`@stacksjs/iconify-core\`](../iconify#installation) - Core rendering functions and utilities
625
+ - [Iconify Integration Guide](../iconify) - Complete guide to using Iconify with stx
626
+ - [stx Documentation](../) - Main stx documentation
627
+
628
+ ## License
629
+
630
+ ${collectionInfo.license?.title || "MIT"}
631
+
632
+ ${collectionInfo.license?.url ? `See [license details](${collectionInfo.license.url}) for more information.` : ""}
633
+
634
+ ## Credits
635
+
636
+ - **Icons**: ${collectionInfo.author?.name || "Iconify"}${collectionInfo.author?.url ? ` ([Website](${collectionInfo.author.url}))` : ""}
637
+ - **Iconify**: [https://iconify.design/](https://iconify.design/)
638
+ - **Icon Set**: [View on Iconify](https://icon-sets.iconify.design/${prefix}/)
639
+
640
+ ## Resources
641
+
642
+ - [Browse all icons in this collection](https://icon-sets.iconify.design/${prefix}/)
643
+ - [Iconify documentation](https://iconify.design/docs/)
644
+ - [stx iconify integration guide](../../docs/iconify.md)
645
+ `;
646
+ }
647
+ async function generatePackage(prefix, outputDir, icons, docsDir) {
648
+ console.log(`
649
+ \uD83D\uDCE6 Generating package for ${prefix}...`);
650
+ const collections = await fetchCollections();
651
+ const collectionInfo = collections[prefix];
652
+ if (!collectionInfo) {
653
+ throw new Error(`Collection ${prefix} not found`);
654
+ }
655
+ console.log(` Collection: ${collectionInfo.name}`);
656
+ console.log(` Total icons: ${collectionInfo.total}`);
657
+ const collectionData = await fetchCollectionIcons(prefix, icons);
658
+ const iconNames = Object.keys(collectionData.icons);
659
+ console.log(` Generating ${iconNames.length} icons...`);
660
+ const packageDir = join(outputDir, `iconify-${prefix}`);
661
+ const srcDir = join(packageDir, "src");
662
+ await mkdir(srcDir, { recursive: true });
663
+ const defaultWidth = collectionData.width || 24;
664
+ const defaultHeight = collectionData.height || 24;
665
+ for (const iconName of iconNames) {
666
+ const iconData = collectionData.icons[iconName];
667
+ const converted = convertIconData(iconData, defaultWidth, defaultHeight);
668
+ const dataFile = generateIconData(iconName, converted);
669
+ await writeFile(join(srcDir, `${iconName}.ts`), dataFile);
670
+ const componentFile = generateIconComponent(iconName, converted);
671
+ await writeFile(join(srcDir, `${iconName}-icon.stx`), componentFile);
672
+ }
673
+ const indexContent = generateIndexFile(iconNames);
674
+ await writeFile(join(srcDir, "index.ts"), indexContent);
675
+ const typesContent = generateTypesFile(prefix);
676
+ await writeFile(join(srcDir, "types.ts"), typesContent);
677
+ const packageJsonContent = generatePackageJson(prefix, collectionInfo, iconNames.length);
678
+ await writeFile(join(packageDir, "package.json"), packageJsonContent);
679
+ const buildContent = generateBuildFile(prefix);
680
+ await writeFile(join(packageDir, "build.ts"), buildContent);
681
+ const readmeContent = generateReadme(prefix, collectionInfo, iconNames.length);
682
+ await writeFile(join(packageDir, "README.md"), readmeContent);
683
+ if (docsDir) {
684
+ const docsPath = join(docsDir, `iconify-${prefix}.md`);
685
+ const docContent = generateDocumentation(prefix, collectionInfo, iconNames);
686
+ await mkdir(docsDir, { recursive: true });
687
+ await writeFile(docsPath, docContent);
688
+ console.log(` \u2713 Generated documentation in ${docsPath}`);
689
+ }
690
+ console.log(` \u2713 Generated ${iconNames.length} icons in ${packageDir}`);
691
+ }
692
+ function toCamelCase(str) {
693
+ let camel = str.replace(/-([a-z0-9])/g, (g) => g[1].toUpperCase());
694
+ camel = camel.replace(/[^a-zA-Z0-9_$]/g, "_");
695
+ if (/^[0-9]/.test(camel))
696
+ camel = `_${camel}`;
697
+ return camel;
698
+ }
699
+ function toPascalCase(str) {
700
+ const camel = toCamelCase(str);
701
+ return camel.charAt(0).toUpperCase() + camel.slice(1);
702
+ }
703
+ export {
704
+ toPascalCase,
705
+ toCamelCase,
706
+ generateTypesFile,
707
+ generateReadme,
708
+ generatePackageJson,
709
+ generatePackage,
710
+ generateIndexFile,
711
+ generateIconData,
712
+ generateIconComponent,
713
+ generateDocumentation,
714
+ generateBuildFile,
715
+ fetchCollections,
716
+ fetchCollectionIcons,
717
+ convertIconData
718
+ };
719
+
720
+ //# debugId=20ECFA5309C6E07C64756E2164756E21