@katlux/toolkit 0.1.1-alpha.116 → 0.1.1-alpha.118

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/bin/cli.mjs ADDED
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @katlux/toolkit CLI Dispatcher
4
+ *
5
+ * Supported commands:
6
+ * npx @katlux/toolkit create-preset <preset-name> [--base=<base>]
7
+ * npx @katlux/toolkit katlux-add-ref
8
+ */
9
+
10
+ import { spawn } from 'child_process'
11
+ import { resolve, dirname } from 'path'
12
+ import { fileURLToPath } from 'url'
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url))
15
+
16
+ const RESET = '\x1b[0m'
17
+ const CYAN = '\x1b[36m'
18
+ const BOLD = '\x1b[1m'
19
+ const RED = '\x1b[31m'
20
+
21
+ const args = process.argv.slice(2)
22
+ const command = args[0]
23
+
24
+ function printHelp() {
25
+ console.log(`
26
+ ${BOLD}Katlux Toolkit CLI${RESET}
27
+
28
+ ${BOLD}Usage:${RESET}
29
+ npx @katlux/toolkit <command> [options]
30
+
31
+ ${BOLD}Commands:${RESET}
32
+ ${CYAN}create-preset <name> [--base=<base>]${RESET}
33
+ Scaffold a new custom preset (e.g. "cyber-brand --base=modern").
34
+ Any preset can be token-only. Base presets leverage cascading inheritance without copying files.
35
+
36
+ ${CYAN}katlux-add-ref${RESET}
37
+ Download or update the Katlux AI Reference Guide at .agents/skills/KATLUX_AI_REFERENCE.md.
38
+
39
+ ${BOLD}Examples:${RESET}
40
+ npx @katlux/toolkit create-preset cyber-brand --base=modern
41
+ npx @katlux/toolkit create-preset my-theme
42
+ npx @katlux/toolkit katlux-add-ref
43
+ `)
44
+ }
45
+
46
+ if (!command || command === '--help' || command === '-h' || command === 'help') {
47
+ printHelp()
48
+ process.exit(0)
49
+ }
50
+
51
+ let scriptPath = null
52
+ let forwardedArgs = []
53
+
54
+ if (command === 'create-preset') {
55
+ scriptPath = resolve(__dirname, 'create-preset.mjs')
56
+ forwardedArgs = args.slice(1)
57
+ } else if (command === 'katlux-add-ref' || command === 'add-ref') {
58
+ scriptPath = resolve(__dirname, 'add-ai-reference.mjs')
59
+ forwardedArgs = args.slice(1)
60
+ } else {
61
+ console.log(`${RED}${BOLD}[katlux] ✖${RESET} Unknown command: "${command}"`)
62
+ printHelp()
63
+ process.exit(1)
64
+ }
65
+
66
+ const child = spawn(process.execPath, [scriptPath, ...forwardedArgs], {
67
+ stdio: 'inherit',
68
+ })
69
+
70
+ child.on('exit', (code) => {
71
+ process.exit(code ?? 0)
72
+ })
@@ -0,0 +1,584 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * create-preset
4
+ * Scaffolds a new Katlux preset in the consumer's Nuxt project.
5
+ *
6
+ * Usage:
7
+ * npx @katlux/toolkit create-preset <preset-name> [--base=<base-preset>]
8
+ *
9
+ * Example:
10
+ * npx @katlux/toolkit create-preset cyber-brand --base=modern
11
+ */
12
+
13
+ import { existsSync, mkdirSync, writeFileSync } from 'fs'
14
+ import { resolve, join, relative } from 'path'
15
+
16
+ const RESET = '\x1b[0m'
17
+ const GREEN = '\x1b[32m'
18
+ const CYAN = '\x1b[36m'
19
+ const YELLOW = '\x1b[33m'
20
+ const RED = '\x1b[31m'
21
+ const BOLD = '\x1b[1m'
22
+ const DIM = '\x1b[2m'
23
+
24
+ function log(color, prefix, message) {
25
+ console.log(`${color}${BOLD}${prefix}${RESET} ${message}`)
26
+ }
27
+
28
+ function toTitleCase(str) {
29
+ return str
30
+ .split('-')
31
+ .map(word => word.charAt(0).toUpperCase() + word.slice(1))
32
+ .join(' ')
33
+ }
34
+
35
+ /**
36
+ * Core preset scaffolding logic
37
+ */
38
+ export function createPreset({ name, base = null, cwd = process.cwd() }) {
39
+ if (!name || typeof name !== 'string') {
40
+ throw new Error('Preset name is required.')
41
+ }
42
+
43
+ const trimmedName = name.trim().toLowerCase()
44
+ if (!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(trimmedName)) {
45
+ throw new Error(
46
+ `Invalid preset name "${name}". Preset name must be kebab-case (e.g. "cyber-brand", "my-theme").`
47
+ )
48
+ }
49
+
50
+ // Detect if project uses Nuxt 4 / custom srcDir pattern (e.g. "app/" directory)
51
+ const hasAppDir = existsSync(resolve(cwd, 'app'))
52
+ const baseDir = hasAppDir ? resolve(cwd, 'app', 'presets') : resolve(cwd, 'presets')
53
+ const targetDir = resolve(baseDir, trimmedName)
54
+ const assetsDir = resolve(targetDir, 'assets')
55
+ const componentsDir = resolve(targetDir, 'components')
56
+ const cssVarsFile = resolve(assetsDir, 'css-variables.scss')
57
+
58
+ if (existsSync(targetDir)) {
59
+ throw new Error(
60
+ `Directory already exists at ${targetDir}. Please choose a different preset name or remove the existing directory.`
61
+ )
62
+ }
63
+
64
+ // Create directory structure: assets/ and empty components/
65
+ mkdirSync(assetsDir, { recursive: true })
66
+ mkdirSync(componentsDir, { recursive: true })
67
+
68
+ // Starter CSS variables template
69
+ // NOTE: Any preset can be token-only. Never copy files from base preset because Katlux resolution cascades!
70
+ const scssContent = `// Katlux Preset: ${trimmedName}
71
+ // In Katlux, any preset can be token-only.
72
+ // When based on another preset, tokens & components cascade automatically via app.config.ts.
73
+ // Do not copy files from the base preset. Uncomment any tokens below to customize your theme.
74
+
75
+ [data-preset~="${trimmedName}"] {
76
+ // ==========================================================================
77
+ // 1. Primary Brand Palette
78
+ // ==========================================================================
79
+ // --primary-100: #e0e7ff;
80
+ // --primary-200: #c7d2fe;
81
+ // --primary-300: #a5b4fc;
82
+ // --primary-400: #818cf8;
83
+ // --primary-500: #6366f1;
84
+ // --primary-600: #4f46e5;
85
+ // --primary-700: #4338ca;
86
+ // --primary-900: #312e81;
87
+ // --primary-color: var(--primary-500);
88
+ // --primary-500-rgb: 99, 102, 241;
89
+
90
+ // ==========================================================================
91
+ // 2. Accent Palette
92
+ // ==========================================================================
93
+ // --accent-100: #cffafe;
94
+ // --accent-300: #67e8f9;
95
+ // --accent-500: #06b6d4;
96
+ // --accent-700: #0e7490;
97
+ // --accent-900: #164e63;
98
+
99
+ // ==========================================================================
100
+ // 3. Neutral Palette
101
+ // ==========================================================================
102
+ // --neutral-50: #f8fafc;
103
+ // --neutral-100: #f1f5f9;
104
+ // --neutral-200: #e2e8f0;
105
+ // --neutral-300: #cbd5e1;
106
+ // --neutral-400: #94a3b8;
107
+ // --neutral-500: #64748b;
108
+ // --neutral-600: #475569;
109
+ // --neutral-700: #334155;
110
+ // --neutral-800: #1e293b;
111
+ // --neutral-900: #0f172a;
112
+
113
+ // ==========================================================================
114
+ // 4. Extended Color Palettes
115
+ // ==========================================================================
116
+ // --yellow-100: #fef9c3;
117
+ // --yellow-300: #fde047;
118
+ // --yellow-500: #eab308;
119
+ // --yellow-700: #a16207;
120
+ // --yellow-900: #713f12;
121
+
122
+ // --red-100: #fee2e2;
123
+ // --red-300: #fca5a5;
124
+ // --red-500: #ef4444;
125
+ // --red-700: #b91c1c;
126
+ // --red-900: #7f1d1d;
127
+
128
+ // --blue-100: #dbeafe;
129
+ // --blue-300: #93c5fd;
130
+ // --blue-500: #3b82f6;
131
+ // --blue-700: #1d4ed8;
132
+ // --blue-900: #1e3a8a;
133
+
134
+ // --pink-100: #fce7f3;
135
+ // --pink-300: #f9a8d4;
136
+ // --pink-500: #ec4899;
137
+ // --pink-700: #be185d;
138
+ // --pink-900: #831843;
139
+
140
+ // --cyan-100: #cffafe;
141
+ // --cyan-300: #67e8f9;
142
+ // --cyan-500: #06b6d4;
143
+ // --cyan-700: #0e7490;
144
+ // --cyan-900: #164e63;
145
+
146
+ // --green-100: #dcfce7;
147
+ // --green-300: #86efac;
148
+ // --green-500: #10b981;
149
+ // --green-700: #047857;
150
+ // --green-900: #064e3b;
151
+
152
+ // ==========================================================================
153
+ // 5. Semantic Status Colors
154
+ // ==========================================================================
155
+ // --success-color: #10b981;
156
+ // --success-color-light: #dcfce7;
157
+ // --success-500: #10b981;
158
+ // --warning-color: #f59e0b;
159
+ // --warning-color-light: #fef3c7;
160
+ // --warning-500: #f59e0b;
161
+ // --error-color: #f43f5e;
162
+ // --error-color-light: #ffe4e6;
163
+ // --error-500: #f43f5e;
164
+ // --info-color: #0ea5e9;
165
+ // --info-color-light: #e0f2fe;
166
+
167
+ // ==========================================================================
168
+ // 6. Typography & Text Hierarchy
169
+ // ==========================================================================
170
+ // --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
171
+ // --font-family-mono: 'Fira Code', 'Roboto Mono', monospace;
172
+ // --font-size-xs: 12px;
173
+ // --font-size-sm: 14px;
174
+ // --font-size-md: 16px;
175
+ // --font-size-lg: 18px;
176
+ // --font-size-xl: 20px;
177
+ // --font-weight-normal: 400;
178
+ // --font-weight-medium: 500;
179
+ // --font-weight-semibold: 600;
180
+ // --font-weight-bold: 700;
181
+
182
+ // --font-color-primary: #0f172a;
183
+ // --font-color-secondary: #64748b;
184
+ // --font-color-heading: #0f172a;
185
+ // --font-color-light: #ffffff;
186
+ // --font-color-default: var(--font-color-primary);
187
+
188
+ // --text-color: var(--font-color-primary);
189
+ // --text-color-primary: var(--font-color-primary);
190
+ // --text-color-secondary: var(--font-color-secondary);
191
+ // --text-color-muted: var(--neutral-400);
192
+ // --text-font-family: var(--font-family);
193
+ // --text-font-size: var(--font-size-md);
194
+ // --text-font-weight: var(--font-weight-normal);
195
+
196
+ // --header-color: var(--font-color-heading);
197
+ // --header-font-family: var(--font-family);
198
+ // --header-font-weight: var(--font-weight-bold);
199
+ // --header-margin-top: 0;
200
+ // --header-margin-bottom: 0.5em;
201
+ // --h1-font-size: 2.5rem;
202
+ // --h2-font-size: 2rem;
203
+ // --h3-font-size: 1.75rem;
204
+ // --h4-font-size: 1.5rem;
205
+ // --h5-font-size: 1.25rem;
206
+ // --h6-font-size: 1rem;
207
+
208
+ // --link-color: var(--primary-500);
209
+ // --link-hover-color: var(--primary-700);
210
+ // --link-font-weight: var(--font-weight-medium);
211
+ // --link-text-decoration: none;
212
+ // --link-hover-text-decoration: underline;
213
+
214
+ // ==========================================================================
215
+ // 7. Backgrounds & Surfaces
216
+ // ==========================================================================
217
+ // --background-color: #ffffff;
218
+ // --background-color-light: #f8fafc;
219
+ // --background-color-medium: #f1f5f9;
220
+ // --background-color-dark: #0f172a;
221
+ // --bg-color-surface: #ffffff;
222
+ // --bg-color-elevated: #ffffff;
223
+ // --bg-color-muted: #f8fafc;
224
+
225
+ // ==========================================================================
226
+ // 8. Borders & Dividers
227
+ // ==========================================================================
228
+ // --border-color-light: #f1f5f9;
229
+ // --border-color-medium: #e2e8f0;
230
+ // --border-color-dark: #94a3b8;
231
+
232
+ // ==========================================================================
233
+ // 9. Spacing & Layout Gaps
234
+ // ==========================================================================
235
+ // --gap-xs: 4px;
236
+ // --gap-sm: 8px;
237
+ // --gap-md: 16px;
238
+ // --gap-lg: 24px;
239
+ // --gap-xl: 32px;
240
+ // --grid-gap: var(--gap-md);
241
+ // --component-gap: var(--gap-sm);
242
+
243
+ // ==========================================================================
244
+ // 10. Corner Radii
245
+ // ==========================================================================
246
+ // --border-radius-sm: 6px;
247
+ // --border-radius-md: 10px;
248
+ // --border-radius-lg: 14px;
249
+ // --border-radius-xl: 20px;
250
+ // --border-radius-full: 9999px;
251
+ // --radius-md: var(--border-radius-md);
252
+
253
+ // ==========================================================================
254
+ // 11. Shadows & Elevations
255
+ // ==========================================================================
256
+ // --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
257
+ // --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
258
+ // --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
259
+ // --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
260
+ // --shadow-glow-primary: 0 10px 15px -3px rgba(99, 102, 241, 0.4), 0 4px 6px -2px rgba(99, 102, 241, 0.2);
261
+ // --shadow-glow-danger: 0 10px 15px -3px rgba(244, 63, 94, 0.4), 0 4px 6px -2px rgba(244, 63, 94, 0.2);
262
+ // --shadow-glow-success: 0 10px 15px -3px rgba(16, 185, 129, 0.4), 0 4px 6px -2px rgba(16, 185, 129, 0.2);
263
+
264
+ // ==========================================================================
265
+ // 12. Animation Transitions
266
+ // ==========================================================================
267
+ // --transition-fast: 0.15s ease;
268
+ // --transition-normal: 0.3s ease;
269
+ // --transition-slow: 0.5s ease;
270
+ // --transition-bounce: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
271
+
272
+ // ==========================================================================
273
+ // 13. Button Controls
274
+ // ==========================================================================
275
+ // --button-border-radius: var(--border-radius-md);
276
+ // --button-font-size-sm: var(--font-size-sm);
277
+ // --button-font-size-md: var(--font-size-md);
278
+ // --button-font-size-lg: var(--font-size-lg);
279
+
280
+ // --button-bg-default: #f1f5f9;
281
+ // --button-text-default: #0f172a;
282
+ // --button-hover-bg-default: #e2e8f0;
283
+ // --button-hover-text-default: #0f172a;
284
+
285
+ // --button-bg-primary: #6366f1;
286
+ // --button-text-primary: #ffffff;
287
+ // --button-hover-bg-primary: #4f46e5;
288
+ // --button-hover-text-primary: #ffffff;
289
+
290
+ // --button-bg-success: #10b981;
291
+ // --button-text-success: #ffffff;
292
+ // --button-hover-bg-success: #059669;
293
+ // --button-hover-text-success: #ffffff;
294
+
295
+ // --button-bg-warning: #f59e0b;
296
+ // --button-text-warning: #0f172a;
297
+ // --button-hover-bg-warning: #d97706;
298
+ // --button-hover-text-warning: #0f172a;
299
+
300
+ // --button-bg-danger: #f43f5e;
301
+ // --button-text-danger: #ffffff;
302
+ // --button-hover-bg-danger: #e11d48;
303
+ // --button-hover-text-danger: #ffffff;
304
+
305
+ // --button-bg-info: #0ea5e9;
306
+ // --button-text-info: #ffffff;
307
+ // --button-hover-bg-info: #0284c7;
308
+ // --button-hover-text-info: #ffffff;
309
+
310
+ // --button-bg-light: #ffffff;
311
+ // --button-text-light: #0f172a;
312
+ // --button-hover-bg-light: #f8fafc;
313
+ // --button-hover-text-light: #0f172a;
314
+
315
+ // --button-bg-dark: #0f172a;
316
+ // --button-text-dark: #ffffff;
317
+ // --button-hover-bg-dark: #1e293b;
318
+ // --button-hover-text-dark: #ffffff;
319
+
320
+ // ==========================================================================
321
+ // 14. Form Inputs & Textboxes
322
+ // ==========================================================================
323
+ // --input-bg: #ffffff;
324
+ // --input-border-radius: var(--border-radius-sm);
325
+ // --input-border-color: #cbd5e1;
326
+ // --input-border: 1px solid var(--input-border-color);
327
+ // --input-hover-border-color: #94a3b8;
328
+ // --input-focus-border-color: var(--primary-500);
329
+ // --input-focus-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
330
+ // --input-height: 44px;
331
+ // --input-label-color: var(--font-color-primary);
332
+ // --input-button-bg: #f1f5f9;
333
+ // --input-button-hover-bg: #e2e8f0;
334
+ // --input-button-font-color: var(--font-color-primary);
335
+
336
+ // ==========================================================================
337
+ // 15. Selection Controls (Checkbox / Radiobox / Switch)
338
+ // ==========================================================================
339
+ // --checkbox-bg: #ffffff;
340
+ // --checkbox-checked-bg: var(--primary-500);
341
+ // --checkbox-border-color: #94a3b8;
342
+ // --checkbox-border-radius: var(--border-radius-sm);
343
+
344
+ // ==========================================================================
345
+ // 16. Tables & Datatables
346
+ // ==========================================================================
347
+ // --table-border-color: #e2e8f0;
348
+ // --table-header-bg: #f8fafc;
349
+ // --table-header-color: #475569;
350
+ // --table-row-bg: #ffffff;
351
+ // --table-row-alt-bg: #f8fafc;
352
+ // --table-row-hover: #f1f5f9;
353
+ // --table-row-hover-bg: #f1f5f9;
354
+ // --table-row-selected: #e0e7ff;
355
+ // --table-row-selected-bg: #e0e7ff;
356
+ // --table-row-selected-text: #312e81;
357
+ // --table-row-text-color: var(--font-color-primary);
358
+ // --page-height: 48px;
359
+ // --page-size: 10;
360
+
361
+ // ==========================================================================
362
+ // 17. Panels, Cards & Containers
363
+ // ==========================================================================
364
+ // --panel-bg-opacity: 1;
365
+ // --panel-blur: 0px;
366
+ // --panel-bg-default: #ffffff;
367
+ // --panel-header-bg-default: #f8fafc;
368
+ // --panel-footer-bg-default: #ffffff;
369
+
370
+ // --panel-bg-primary: #e0e7ff;
371
+ // --panel-header-bg-primary: #6366f1;
372
+ // --panel-footer-bg-primary: #c7d2fe;
373
+
374
+ // --panel-bg-success: #dcfce7;
375
+ // --panel-header-bg-success: #10b981;
376
+ // --panel-footer-bg-success: #bbf7d0;
377
+
378
+ // --panel-bg-warning: #fef3c7;
379
+ // --panel-header-bg-warning: #f59e0b;
380
+ // --panel-footer-bg-warning: #fde68a;
381
+
382
+ // --panel-bg-danger: #ffe4e6;
383
+ // --panel-header-bg-danger: #f43f5e;
384
+ // --panel-footer-bg-danger: #fecdd3;
385
+
386
+ // --panel-bg-info: #e0f2fe;
387
+ // --panel-header-bg-info: #0ea5e9;
388
+ // --panel-footer-bg-info: #bae6fd;
389
+
390
+ // --box-border-radius: var(--border-radius-md);
391
+ // --box-border: 1px solid var(--border-color-medium);
392
+ // --box-shadow: var(--shadow-md);
393
+ // --box-padding: var(--gap-md);
394
+
395
+ // ==========================================================================
396
+ // 18. Tooltips
397
+ // ==========================================================================
398
+ // --tooltip-bg: #0f172a;
399
+ // --tooltip-color: #ffffff;
400
+ // --tooltip-border-radius: var(--border-radius-sm);
401
+ // --tooltip-font-size: var(--font-size-sm);
402
+ // --tooltip-font-family: var(--font-family);
403
+ // --tooltip-shadow: var(--shadow-md);
404
+
405
+ // ==========================================================================
406
+ // 19. Overlays & Modals
407
+ // ==========================================================================
408
+ // --layover: #475569;
409
+ // --component-overlay-bg: rgba(255, 255, 255, 0.75);
410
+ // --table-overlay-bg: var(--component-overlay-bg);
411
+ // --modal-overlay-bg: rgba(15, 23, 42, 0.5);
412
+ // --modal-backdrop-blur: 0px;
413
+
414
+ // ==========================================================================
415
+ // 20. Application Layout Dimensions
416
+ // ==========================================================================
417
+ // --layout-header-height: 60px;
418
+ // --layout-header-bg: #ffffff;
419
+ // --layout-sidebar-width: 240px;
420
+ // --layout-sidebar-bg: #f8fafc;
421
+ // --layout-content-bg: #ffffff;
422
+ // --layout-margin: 0;
423
+ // --layout-padding: 0;
424
+
425
+ // ==========================================================================
426
+ // 21. Icons
427
+ // ==========================================================================
428
+ // --icon-color-light: #f1f5f9;
429
+ // --icon-color-medium: #94a3b8;
430
+ // --icon-color-dark: #475569;
431
+
432
+ // ==========================================================================
433
+ // 22. Tree & Hierarchical Navigation
434
+ // ==========================================================================
435
+ // --tree-depth: 0;
436
+ // --tree-indent: 16px;
437
+ }`
438
+
439
+ writeFileSync(cssVarsFile, scssContent, 'utf-8')
440
+
441
+ return {
442
+ presetName: trimmedName,
443
+ basePreset: base ? base.trim().toLowerCase() : null,
444
+ targetDir,
445
+ assetsDir,
446
+ componentsDir,
447
+ cssVarsFile,
448
+ hasAppDir,
449
+ }
450
+ }
451
+
452
+ // ── CLI Execution ─────────────────────────────────────────────────────────────
453
+
454
+ function runCli() {
455
+ const args = process.argv.slice(2)
456
+
457
+ if (args.includes('--help') || args.includes('-h') || args.length === 0) {
458
+ console.log(`
459
+ ${BOLD}Katlux Preset Scaffolding Tool${RESET}
460
+
461
+ ${BOLD}Usage:${RESET}
462
+ npx @katlux/toolkit create-preset <preset-name> [--base=<base-preset>]
463
+
464
+ ${BOLD}Arguments:${RESET}
465
+ <preset-name> Name of your new preset in kebab-case (e.g. "cyber-brand")
466
+
467
+ ${BOLD}Options:${RESET}
468
+ --base=<base-preset> Base preset to inherit from (e.g. "--base=modern").
469
+ No files are copied; multi-preset cascading inheritance is used.
470
+ -h, --help Show this help message
471
+
472
+ ${BOLD}Examples:${RESET}
473
+ npx @katlux/toolkit create-preset cyber-brand --base=modern
474
+ npx @katlux/toolkit create-preset my-theme
475
+ `)
476
+ if (args.length === 0) {
477
+ process.exit(1)
478
+ }
479
+ process.exit(0)
480
+ }
481
+
482
+ let presetName = null
483
+ let basePreset = null
484
+
485
+ for (const arg of args) {
486
+ if (arg.startsWith('--base=')) {
487
+ basePreset = arg.slice('--base='.length)
488
+ } else if (arg === '-b' || arg === '--base') {
489
+ const idx = args.indexOf(arg)
490
+ if (idx !== -1 && args[idx + 1]) {
491
+ basePreset = args[idx + 1]
492
+ }
493
+ } else if (!arg.startsWith('-') && !presetName) {
494
+ presetName = arg
495
+ }
496
+ }
497
+
498
+ if (!presetName) {
499
+ log(RED, '[create-preset] ✖', 'Preset name is required.')
500
+ console.log('Run with --help for usage instructions.')
501
+ process.exit(1)
502
+ }
503
+
504
+ try {
505
+ console.log()
506
+ log(CYAN, '[create-preset]', `Scaffolding preset "${presetName}"...`)
507
+
508
+ const result = createPreset({
509
+ name: presetName,
510
+ base: basePreset,
511
+ cwd: process.cwd(),
512
+ })
513
+
514
+ const relTarget = relative(process.cwd(), result.targetDir)
515
+ const relFile = relative(process.cwd(), result.cssVarsFile)
516
+ const relComponents = relative(process.cwd(), result.componentsDir)
517
+
518
+ console.log()
519
+ log(GREEN, '[create-preset] ✔', `Preset created successfully!`)
520
+ console.log(` ${CYAN}Directory:${RESET} ${relTarget}`)
521
+ console.log(` ${CYAN}Tokens File:${RESET} ${relFile}`)
522
+ console.log(` ${CYAN}Components:${RESET} ${relComponents} (empty for custom overrides)`)
523
+ console.log()
524
+
525
+ const presetTitle = toTitleCase(result.presetName)
526
+
527
+ if (result.basePreset) {
528
+ const baseTitle = toTitleCase(result.basePreset)
529
+ console.log(` ${YELLOW}Inheritance Architecture:${RESET}`)
530
+ console.log(` Preset is based on ${BOLD}"${result.basePreset}"${RESET}.`)
531
+ console.log(` No files were copied from "${result.basePreset}" because Katlux cascades automatically!`)
532
+ console.log(` Any token or component not defined in "${result.presetName}" will fall back to "${result.basePreset}", then "default".`)
533
+ console.log()
534
+ console.log(` ${BOLD}Configure in your app.config.ts:${RESET}`)
535
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
536
+ console.log(`export default defineAppConfig({
537
+ katluxToolkit: {
538
+ presetList: [
539
+ { name: 'Default', value: 'default' },
540
+ { name: '${baseTitle}', value: '${result.basePreset}' },
541
+ { name: '${presetTitle}', value: ['${result.presetName}', '${result.basePreset}'] }
542
+ ],
543
+ // Multi-preset configuration: '${result.presetName}' overrides '${result.basePreset}'
544
+ activePreset: ['${result.presetName}', '${result.basePreset}']
545
+ }
546
+ })`)
547
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
548
+ } else {
549
+ console.log(` ${YELLOW}Single Preset Architecture:${RESET}`)
550
+ console.log(` No base preset specified. Any token or component not defined in "${result.presetName}"`)
551
+ console.log(` will automatically fall back to the built-in "default" preset.`)
552
+ console.log()
553
+ console.log(` ${BOLD}Configure in your app.config.ts:${RESET}`)
554
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
555
+ console.log(`export default defineAppConfig({
556
+ katluxToolkit: {
557
+ presetList: [
558
+ { name: 'Default', value: 'default' },
559
+ { name: '${presetTitle}', value: '${result.presetName}' }
560
+ ],
561
+ // Single preset configuration: falls back directly to 'default'
562
+ activePreset: '${result.presetName}'
563
+ }
564
+ })`)
565
+ console.log(`${DIM}------------------------------------------------------------${RESET}`)
566
+ }
567
+
568
+ console.log()
569
+ } catch (err) {
570
+ console.log()
571
+ log(RED, '[create-preset] ✖', err.message)
572
+ console.log()
573
+ process.exit(1)
574
+ }
575
+ }
576
+
577
+ // Run CLI directly if invoked as script
578
+ const isMain = process.argv[1] && (
579
+ process.argv[1].endsWith('create-preset.mjs') ||
580
+ process.argv[1].endsWith('create-preset')
581
+ )
582
+ if (isMain) {
583
+ runCli()
584
+ }
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
3
  "configKey": "katluxToolkit",
4
- "version": "0.1.1-alpha.116",
4
+ "version": "0.1.1-alpha.118",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -11,6 +11,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
11
11
  openIndexes: import("vue").Ref<number[], number[]>;
12
12
  toggleItem: (index: number) => void;
13
13
  isOpen: (index: number) => boolean;
14
+ onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
14
15
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
16
  "update:modelValue": (value: string | number) => any;
16
17
  change: (value: string | number) => any;
@@ -5,20 +5,22 @@ import { computed } from "vue";
5
5
  import KTabsDefault from "../../presets/default/components/KTabs/KTabs.vue";
6
6
  const props = defineProps(KTabsDefaultProps);
7
7
  const emit = defineEmits(["update:modelValue", "update:activeTab", "change"]);
8
- const { items, openIndexes, toggleItem, isOpen } = useKTabsLogic(
8
+ const { items, openIndexes, toggleItem, isOpen, onTabKeyDown } = useKTabsLogic(
9
9
  props,
10
10
  emit
11
11
  );
12
12
  defineExpose({
13
13
  openIndexes,
14
14
  toggleItem,
15
- isOpen
15
+ isOpen,
16
+ onTabKeyDown
16
17
  });
17
18
  const presetComponent = usePresetComponent("KTabs", KTabsDefault);
18
19
  const templateProps = computed(() => ({
19
20
  items: items.value,
20
21
  toggleItem,
21
- isOpen
22
+ isOpen,
23
+ onTabKeyDown
22
24
  }));
23
25
  </script>
24
26
 
@@ -11,6 +11,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
11
11
  openIndexes: import("vue").Ref<number[], number[]>;
12
12
  toggleItem: (index: number) => void;
13
13
  isOpen: (index: number) => boolean;
14
+ onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
14
15
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
15
16
  "update:modelValue": (value: string | number) => any;
16
17
  change: (value: string | number) => any;
@@ -24,4 +24,5 @@ export declare function useKTabsLogic(props?: KTabsProps, emit?: KTabsEmits): {
24
24
  openIndexes: import("vue").Ref<number[], number[]>;
25
25
  toggleItem: (index: number) => void;
26
26
  isOpen: (index: number) => boolean;
27
+ onTabKeyDown: (e: KeyboardEvent, index: number) => number | void;
27
28
  };
@@ -146,10 +146,41 @@ export function useKTabsLogic(props = {}, emit) {
146
146
  provide("tabIsControlled", isControlled);
147
147
  } catch (e) {
148
148
  }
149
+ function onTabKeyDown(e, index) {
150
+ const allItems = items.value.length > 0 ? items.value : registeredItems.value;
151
+ const total = allItems.length;
152
+ if (total <= 1) return;
153
+ let targetIndex = -1;
154
+ switch (e.key) {
155
+ case "ArrowRight":
156
+ e.preventDefault();
157
+ targetIndex = (index + 1) % total;
158
+ break;
159
+ case "ArrowLeft":
160
+ e.preventDefault();
161
+ targetIndex = (index - 1 + total) % total;
162
+ break;
163
+ case "Home":
164
+ e.preventDefault();
165
+ targetIndex = 0;
166
+ break;
167
+ case "End":
168
+ e.preventDefault();
169
+ targetIndex = total - 1;
170
+ break;
171
+ default:
172
+ return;
173
+ }
174
+ if (targetIndex !== -1 && targetIndex !== index) {
175
+ toggleItem(targetIndex);
176
+ return targetIndex;
177
+ }
178
+ }
149
179
  return {
150
180
  items,
151
181
  openIndexes,
152
182
  toggleItem,
153
- isOpen
183
+ isOpen,
184
+ onTabKeyDown
154
185
  };
155
186
  }
@@ -27,7 +27,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
27
27
  }>> & Readonly<{}>, {
28
28
  disabled: boolean;
29
29
  text: string;
30
- position: "left" | "right" | "top" | "bottom";
30
+ position: "top" | "left" | "right" | "bottom";
31
31
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
32
32
  declare const _default: typeof __VLS_export;
33
33
  export default _default;
@@ -27,7 +27,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
27
27
  }>> & Readonly<{}>, {
28
28
  disabled: boolean;
29
29
  text: string;
30
- position: "left" | "right" | "top" | "bottom";
30
+ position: "top" | "left" | "right" | "bottom";
31
31
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
32
32
  declare const _default: typeof __VLS_export;
33
33
  export default _default;
@@ -6,6 +6,10 @@
6
6
  ref="internalMenuRef"
7
7
  v-click-outside="clickoutside"
8
8
  :style="menuStyle"
9
+ role="menu"
10
+ aria-orientation="vertical"
11
+ tabindex="-1"
12
+ @keydown="handleKeydown"
9
13
  v-bind="$attrs"
10
14
  )
11
15
  KPanel.KContextMenu-container(:style="containerStyle")
@@ -13,7 +17,7 @@
13
17
  </template>
14
18
 
15
19
  <script lang="ts" setup>
16
- import { ref, computed, watch, onBeforeUnmount } from 'vue'
20
+ import { ref, computed, watch, nextTick, onBeforeUnmount } from 'vue'
17
21
  import KPanel from '../KPanel/KPanel.vue'
18
22
 
19
23
  defineOptions({
@@ -42,8 +46,78 @@ const containerStyle = computed(() => ({
42
46
  maxHeight: `${props.menuRect.maxHeight}px`
43
47
  }))
44
48
 
49
+ const getFocusableItems = (): HTMLElement[] => {
50
+ if (!internalMenuRef.value) return []
51
+ return Array.from(
52
+ internalMenuRef.value.querySelectorAll<HTMLElement>(
53
+ 'a[href], button:not([disabled]), [role="menuitem"], [tabindex]:not([tabindex="-1"])'
54
+ )
55
+ ).filter(el => el.offsetParent !== null)
56
+ }
57
+
45
58
  const handleKeydown = (e: KeyboardEvent) => {
59
+ if (!props.open) return
60
+
61
+ if (e.key === 'Escape') {
62
+ e.preventDefault()
63
+ e.stopPropagation()
64
+ props.clickoutside()
65
+ return
66
+ }
67
+
68
+ if (e.key === 'Tab') {
69
+ e.stopPropagation()
70
+ props.clickoutside()
71
+ return
72
+ }
73
+
74
+ const items = getFocusableItems()
75
+ if (items.length === 0) return
76
+
77
+ const activeEl = typeof document !== 'undefined' ? (document.activeElement as HTMLElement) : null
78
+ const currentIndex = activeEl ? items.indexOf(activeEl) : -1
79
+
80
+ switch (e.key) {
81
+ case 'ArrowDown': {
82
+ e.preventDefault()
83
+ e.stopPropagation()
84
+ const nextIndex = currentIndex < items.length - 1 ? currentIndex + 1 : 0
85
+ items[nextIndex]?.focus()
86
+ break
87
+ }
88
+ case 'ArrowUp': {
89
+ e.preventDefault()
90
+ e.stopPropagation()
91
+ const prevIndex = currentIndex > 0 ? currentIndex - 1 : items.length - 1
92
+ items[prevIndex]?.focus()
93
+ break
94
+ }
95
+ case 'Home': {
96
+ e.preventDefault()
97
+ e.stopPropagation()
98
+ items[0]?.focus()
99
+ break
100
+ }
101
+ case 'End': {
102
+ e.preventDefault()
103
+ e.stopPropagation()
104
+ items[items.length - 1]?.focus()
105
+ break
106
+ }
107
+ case ' ': {
108
+ if (activeEl && activeEl.tagName === 'A') {
109
+ e.preventDefault()
110
+ e.stopPropagation()
111
+ activeEl.click()
112
+ }
113
+ break
114
+ }
115
+ }
116
+ }
117
+
118
+ const handleWindowKeydown = (e: KeyboardEvent) => {
46
119
  if (e.key === 'Escape' && props.open) {
120
+ e.preventDefault()
47
121
  props.clickoutside()
48
122
  }
49
123
  }
@@ -51,16 +125,24 @@ const handleKeydown = (e: KeyboardEvent) => {
51
125
  watch(() => props.open, (isOpen) => {
52
126
  if (typeof window !== 'undefined') {
53
127
  if (isOpen) {
54
- window.addEventListener('keydown', handleKeydown)
128
+ window.addEventListener('keydown', handleWindowKeydown)
129
+ nextTick(() => {
130
+ const items = getFocusableItems()
131
+ if (items.length > 0) {
132
+ items[0].focus()
133
+ } else if (internalMenuRef.value) {
134
+ internalMenuRef.value.focus()
135
+ }
136
+ })
55
137
  } else {
56
- window.removeEventListener('keydown', handleKeydown)
138
+ window.removeEventListener('keydown', handleWindowKeydown)
57
139
  }
58
140
  }
59
141
  }, { immediate: true })
60
142
 
61
143
  onBeforeUnmount(() => {
62
144
  if (typeof window !== 'undefined') {
63
- window.removeEventListener('keydown', handleKeydown)
145
+ window.removeEventListener('keydown', handleWindowKeydown)
64
146
  }
65
147
  })
66
148
 
@@ -2,6 +2,7 @@ type __VLS_Props = {
2
2
  items: any[];
3
3
  toggleItem: (index: number) => void;
4
4
  isOpen: (index: number) => boolean;
5
+ onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void;
5
6
  };
6
7
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
8
  declare const _default: typeof __VLS_export;
@@ -10,6 +10,7 @@
10
10
  v-for="(item, index) of items"
11
11
  :key="index"
12
12
  @click="toggleItem(index)"
13
+ @keydown="handleTabKeyDown($event, index)"
13
14
  size="small"
14
15
  :type="isOpen(index) ? 'primary' : 'default'"
15
16
  :class="{ 'is-active': isOpen(index) }"
@@ -31,12 +32,34 @@ const props = defineProps<{
31
32
  items: any[]
32
33
  toggleItem: (index: number) => void
33
34
  isOpen: (index: number) => boolean
35
+ onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void
34
36
  }>()
35
37
 
36
38
  const scrollArea = ref<HTMLElement | null>(null)
37
39
  const hasOverflow = ref(false)
38
40
  let resizeObserver: ResizeObserver | null = null
39
41
 
42
+ const focusTab = (index: number) => {
43
+ if (!scrollArea.value) return
44
+ const buttons = scrollArea.value.querySelectorAll<HTMLElement>('.k-tab-btn')
45
+ const targetBtn = buttons[index]
46
+ if (targetBtn) {
47
+ targetBtn.focus()
48
+ targetBtn.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'nearest' })
49
+ }
50
+ }
51
+
52
+ const handleTabKeyDown = (e: KeyboardEvent, index: number) => {
53
+ if (props.onTabKeyDown) {
54
+ const newIndex = props.onTabKeyDown(e, index)
55
+ if (typeof newIndex === 'number') {
56
+ nextTick(() => {
57
+ focusTab(newIndex)
58
+ })
59
+ }
60
+ }
61
+ }
62
+
40
63
  const checkOverflow = () => {
41
64
  if (!scrollArea.value) return
42
65
  const el = scrollArea.value
@@ -2,6 +2,7 @@ type __VLS_Props = {
2
2
  items: any[];
3
3
  toggleItem: (index: number) => void;
4
4
  isOpen: (index: number) => boolean;
5
+ onTabKeyDown?: (e: KeyboardEvent, index: number) => number | void;
5
6
  };
6
7
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
8
  declare const _default: typeof __VLS_export;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/toolkit",
3
- "version": "0.1.1-alpha.116",
3
+ "version": "0.1.1-alpha.118",
4
4
  "description": "Core UI toolkit and utilities for the Katlux ecosystem",
5
5
  "author": "Katlux",
6
6
  "license": "Apache-2.0",
@@ -9,6 +9,10 @@
9
9
  },
10
10
  "main": "./dist/module.mjs",
11
11
  "bin": {
12
+ "@katlux/toolkit": "./bin/cli.mjs",
13
+ "katlux": "./bin/cli.mjs",
14
+ "katlux-toolkit": "./bin/cli.mjs",
15
+ "create-preset": "./bin/create-preset.mjs",
12
16
  "katlux-add-ref": "./bin/add-ai-reference.mjs"
13
17
  },
14
18
  "scripts": {