@allternit/gizzi-code 1.0.0 → 1.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.
Files changed (158) hide show
  1. package/bin/gizzi +4 -0
  2. package/bin/gizzi-ink +5 -0
  3. package/package.json +137 -31
  4. package/src/Tool.ts +26 -0
  5. package/src/bootstrap/state.ts +165 -322
  6. package/src/commands.ts +209 -0
  7. package/src/context/QueuedMessageContext.tsx +63 -0
  8. package/src/context/fpsMetrics.tsx +30 -0
  9. package/src/context/mailbox.tsx +38 -0
  10. package/src/context/modalContext.tsx +58 -0
  11. package/src/context/notifications.tsx +240 -0
  12. package/src/context/overlayContext.tsx +151 -0
  13. package/src/context/promptOverlayContext.tsx +125 -0
  14. package/src/context/stats.tsx +220 -0
  15. package/src/context/voice.tsx +88 -0
  16. package/src/hooks/useCanUseTool.ts +11 -0
  17. package/src/hooks/useExitOnCtrlCD.ts +40 -187
  18. package/src/hooks/useExitOnCtrlCDWithKeybindings.ts +68 -0
  19. package/src/hooks/useKeybinding.ts +68 -209
  20. package/src/hooks/useTerminalSize.ts +31 -99
  21. package/src/hooks.ts +37 -0
  22. package/src/ink.ts +204 -0
  23. package/src/main.ts +7 -0
  24. package/src/types/command.ts +216 -0
  25. package/src/types/connectorText.ts +39 -0
  26. package/src/types/fileSuggestion.ts +15 -0
  27. package/src/types/generated/events_mono/claude_code/v1/claude_code_internal_event.ts +865 -0
  28. package/src/types/generated/events_mono/common/v1/auth.ts +100 -0
  29. package/src/types/generated/events_mono/growthbook/v1/growthbook_experiment_event.ts +223 -0
  30. package/src/types/generated/google/protobuf/timestamp.ts +187 -0
  31. package/src/types/hooks.ts +319 -0
  32. package/src/types/ids.ts +44 -0
  33. package/src/types/logs.ts +331 -0
  34. package/src/types/merged/index.ts +5 -0
  35. package/src/types/merged/message.ts +552 -0
  36. package/src/types/message.ts +927 -186
  37. package/src/types/messageQueueTypes.ts +21 -0
  38. package/src/types/notebook.ts +72 -0
  39. package/src/types/permissions.ts +447 -0
  40. package/src/types/plugin.ts +363 -0
  41. package/src/types/statusLine.ts +15 -0
  42. package/src/types/textInputTypes.ts +387 -0
  43. package/src/types/tools.ts +149 -0
  44. package/src/types/utils.ts +20 -0
  45. package/src/utils/advisor.ts +12 -0
  46. package/src/utils/api.ts +29 -0
  47. package/src/utils/array.ts +7 -0
  48. package/src/utils/attachments.ts +60 -0
  49. package/src/utils/auth.ts +3 -0
  50. package/src/utils/claudeInChrome/chromeNativeHost.ts +15 -0
  51. package/src/utils/claudeInChrome/common.ts +12 -0
  52. package/src/utils/claudeInChrome/mcpServer.ts +15 -0
  53. package/src/utils/computerUse/common.ts +19 -0
  54. package/src/utils/computerUse/mcpServer.ts +15 -0
  55. package/src/utils/config.ts +35 -0
  56. package/src/utils/context.ts +19 -0
  57. package/src/utils/cwd.ts +3 -0
  58. package/src/utils/debug.ts +3 -0
  59. package/src/utils/earlyInput.ts +7 -0
  60. package/src/utils/effort.ts +13 -0
  61. package/src/utils/embeddedTools.ts +12 -0
  62. package/src/utils/envUtils.ts +3 -0
  63. package/src/utils/errors.ts +3 -0
  64. package/src/utils/execFileNoThrow.ts +24 -0
  65. package/src/utils/feature-flags.ts +112 -0
  66. package/src/utils/file.ts +3 -0
  67. package/src/utils/fileHistory.ts +17 -0
  68. package/src/utils/fingerprint.ts +7 -0
  69. package/src/utils/format.ts +75 -305
  70. package/src/utils/frontmatterParser.ts +33 -0
  71. package/src/utils/fsOperations.ts +31 -0
  72. package/src/utils/fullscreen.ts +40 -350
  73. package/src/utils/git.ts +15 -0
  74. package/src/utils/imageResizer.ts +30 -0
  75. package/src/utils/lazySchema.ts +9 -0
  76. package/src/utils/log.ts +3 -0
  77. package/src/utils/markdownConfigLoader.ts +12 -0
  78. package/src/utils/messages.ts +13 -0
  79. package/src/utils/migration.ts +137 -0
  80. package/src/utils/model/providers.ts +15 -0
  81. package/src/utils/path.ts +3 -0
  82. package/src/utils/permissions/PermissionResult.ts +14 -0
  83. package/src/utils/permissions/autoModeState.ts +12 -0
  84. package/src/utils/permissions/filesystem.ts +12 -0
  85. package/src/utils/plugins/loadPluginOutputStyles.ts +12 -0
  86. package/src/utils/plugins/schemas.ts +25 -0
  87. package/src/utils/process.ts +16 -0
  88. package/src/utils/sandbox/sandbox-adapter.ts +19 -0
  89. package/src/utils/sessionStorage.ts +238 -472
  90. package/src/utils/settings/constants.ts +10 -0
  91. package/src/utils/settings/settings.ts +19 -0
  92. package/src/utils/settings/types.ts +18 -0
  93. package/src/utils/shell/shellToolUtils.ts +9 -0
  94. package/src/utils/sinks.ts +11 -0
  95. package/src/utils/sleep.ts +7 -0
  96. package/src/utils/sliceAnsi.ts +7 -0
  97. package/src/utils/slowOperations.ts +3 -0
  98. package/src/utils/startupProfiler.ts +11 -0
  99. package/src/utils/stringUtils.ts +106 -0
  100. package/src/utils/systemPromptType.ts +9 -0
  101. package/src/utils/teleport/api.ts +15 -0
  102. package/src/utils/textHighlighting.ts +16 -0
  103. package/src/utils/theme.ts +17 -0
  104. package/src/utils/thinking.ts +58 -0
  105. package/src/utils/tokens.ts +11 -0
  106. package/src/utils/toolResultStorage.ts +17 -0
  107. package/src/utils/worktreeModeEnabled.ts +7 -0
  108. package/WORKSPACE_INTEGRATION.md +0 -290
  109. package/chat-sessions/sessions-index.json +0 -98
  110. package/package.json.original +0 -31
  111. package/package.json.publish +0 -47
  112. package/src/bootstrap/state.d.ts +0 -169
  113. package/src/bootstrap/state.js +0 -261
  114. package/src/context/pack-builder.d.ts +0 -24
  115. package/src/context/pack-builder.js +0 -281
  116. package/src/hooks/useExitOnCtrlCD.d.ts +0 -86
  117. package/src/hooks/useExitOnCtrlCD.js +0 -130
  118. package/src/hooks/useKeybinding.d.ts +0 -89
  119. package/src/hooks/useKeybinding.js +0 -163
  120. package/src/hooks/useTerminalSize.d.ts +0 -41
  121. package/src/hooks/useTerminalSize.js +0 -90
  122. package/src/index.d.ts +0 -23
  123. package/src/index.js +0 -24
  124. package/src/runtime/brand/brand.d.ts +0 -488
  125. package/src/runtime/brand/brand.js +0 -464
  126. package/src/runtime/brand/brand.ts +0 -667
  127. package/src/runtime/services/tokenEstimation.d.ts +0 -187
  128. package/src/runtime/services/tokenEstimation.js +0 -423
  129. package/src/runtime/services/tokenEstimation.ts +0 -547
  130. package/src/runtime/tools/Tool.d.ts +0 -239
  131. package/src/runtime/tools/Tool.js +0 -285
  132. package/src/runtime/tools/Tool.ts +0 -524
  133. package/src/scheduler/TaskScheduler.d.ts +0 -98
  134. package/src/scheduler/TaskScheduler.js +0 -201
  135. package/src/scheduler/TaskScheduler.ts +0 -259
  136. package/src/state/AppStateStore.d.ts +0 -347
  137. package/src/state/AppStateStore.js +0 -439
  138. package/src/state/AppStateStore.ts +0 -658
  139. package/src/state/WorkspaceStateStore.d.ts +0 -43
  140. package/src/state/WorkspaceStateStore.js +0 -224
  141. package/src/state/WorkspaceStateStore.ts +0 -297
  142. package/src/types/message.d.ts +0 -190
  143. package/src/types/message.js +0 -77
  144. package/src/utils/format.d.ts +0 -126
  145. package/src/utils/format.js +0 -230
  146. package/src/utils/fullscreen.d.ts +0 -161
  147. package/src/utils/fullscreen.js +0 -277
  148. package/src/utils/sessionStorage.d.ts +0 -210
  149. package/src/utils/sessionStorage.js +0 -435
  150. package/src/watcher/WorkspaceWatcher.d.ts +0 -70
  151. package/src/watcher/WorkspaceWatcher.js +0 -191
  152. package/src/watcher/WorkspaceWatcher.ts +0 -251
  153. package/src/workspace/loader.d.ts +0 -30
  154. package/src/workspace/loader.js +0 -117
  155. package/src/workspace/types.d.ts +0 -91
  156. package/src/workspace/types.js +0 -7
  157. package/threads/thread_1775361175022.json +0 -9
  158. package/tsconfig.json +0 -14
@@ -1,667 +0,0 @@
1
- /**
2
- * @fileoverview Branding utilities and configuration for gizzi-code
3
- * @module runtime/brand/brand
4
- *
5
- * Provides centralized brand constants, color schemes, and theming
6
- * configuration for the gizzi-code runtime environment.
7
- */
8
-
9
- /**
10
- * Brand name constants
11
- * @constant {Readonly<{FULL: string; SHORT: string; CODE: string; PACKAGE: string}>}
12
- */
13
- export const Brand = {
14
- /** Full brand name */
15
- FULL: 'gizzi-code',
16
-
17
- /** Short brand name */
18
- SHORT: 'gizzi',
19
-
20
- /** Code identifier */
21
- CODE: 'gizzi-code',
22
-
23
- /** Package name */
24
- PACKAGE: '@gizzi/code',
25
- } as const;
26
-
27
- /**
28
- * Brand version information
29
- * @constant {Readonly<{MAJOR: number; MINOR: number; PATCH: number; STRING: string}>}
30
- */
31
- export const BrandVersion = {
32
- /** Major version */
33
- MAJOR: 0,
34
-
35
- /** Minor version */
36
- MINOR: 1,
37
-
38
- /** Patch version */
39
- PATCH: 0,
40
-
41
- /** Full version string */
42
- STRING: '0.1.0',
43
- } as const;
44
-
45
- /**
46
- * Color hex value type
47
- * @typedef {`#${string}`} HexColor
48
- */
49
- export type HexColor = `#${string}`;
50
-
51
- /**
52
- * RGB color values
53
- * @interface RGBColor
54
- */
55
- export interface RGBColor {
56
- readonly r: number;
57
- readonly g: number;
58
- readonly b: number;
59
- }
60
-
61
- /**
62
- * RGBA color values with alpha
63
- * @interface RGBAColor
64
- */
65
- export interface RGBAColor extends RGBColor {
66
- readonly a: number;
67
- }
68
-
69
- /**
70
- * Complete color palette for a theme variant
71
- * @interface BrandColorPalette
72
- */
73
- export interface BrandColorPalette {
74
- /** Primary brand color */
75
- readonly primary: HexColor;
76
-
77
- /** Secondary brand color */
78
- readonly secondary: HexColor;
79
-
80
- /** Accent color for highlights */
81
- readonly accent: HexColor;
82
-
83
- /** Background color */
84
- readonly background: HexColor;
85
-
86
- /** Surface color for cards/elevated elements */
87
- readonly surface: HexColor;
88
-
89
- /** Primary text color */
90
- readonly text: HexColor;
91
-
92
- /** Secondary/muted text color */
93
- readonly textMuted: HexColor;
94
-
95
- /** Error color */
96
- readonly error: HexColor;
97
-
98
- /** Warning color */
99
- readonly warning: HexColor;
100
-
101
- /** Success color */
102
- readonly success: HexColor;
103
-
104
- /** Info color */
105
- readonly info: HexColor;
106
-
107
- /** Border color */
108
- readonly border: HexColor;
109
-
110
- /** Divider color */
111
- readonly divider: HexColor;
112
- }
113
-
114
- /**
115
- * Complete brand color scheme with all theme variants
116
- * @interface BrandColorScheme
117
- */
118
- export interface BrandColorScheme {
119
- /** Light theme colors */
120
- readonly light: BrandColorPalette;
121
-
122
- /** Dark theme colors */
123
- readonly dark: BrandColorPalette;
124
-
125
- /** High contrast theme colors */
126
- readonly highContrast: BrandColorPalette;
127
- }
128
-
129
- /**
130
- * Theme mode options
131
- * @typedef {'light' | 'dark' | 'high-contrast' | 'auto'} ThemeMode
132
- */
133
- export type ThemeMode = 'light' | 'dark' | 'high-contrast' | 'auto';
134
-
135
- /**
136
- * Default light theme color palette
137
- * @constant {Readonly<BrandColorPalette>}
138
- */
139
- export const LightColors: BrandColorPalette = {
140
- primary: '#2563eb',
141
- secondary: '#64748b',
142
- accent: '#8b5cf6',
143
- background: '#ffffff',
144
- surface: '#f8fafc',
145
- text: '#0f172a',
146
- textMuted: '#64748b',
147
- error: '#ef4444',
148
- warning: '#f59e0b',
149
- success: '#10b981',
150
- info: '#3b82f6',
151
- border: '#e2e8f0',
152
- divider: '#cbd5e1',
153
- } as const;
154
-
155
- /**
156
- * Default dark theme color palette
157
- * @constant {Readonly<BrandColorPalette>}
158
- */
159
- export const DarkColors: BrandColorPalette = {
160
- primary: '#3b82f6',
161
- secondary: '#94a3b8',
162
- accent: '#a78bfa',
163
- background: '#0f172a',
164
- surface: '#1e293b',
165
- text: '#f8fafc',
166
- textMuted: '#94a3b8',
167
- error: '#f87171',
168
- warning: '#fbbf24',
169
- success: '#34d399',
170
- info: '#60a5fa',
171
- border: '#334155',
172
- divider: '#475569',
173
- } as const;
174
-
175
- /**
176
- * High contrast theme for accessibility
177
- * @constant {Readonly<BrandColorPalette>}
178
- */
179
- export const HighContrastColors: BrandColorPalette = {
180
- primary: '#005fcc',
181
- secondary: '#404040',
182
- accent: '#6622cc',
183
- background: '#000000',
184
- surface: '#0a0a0a',
185
- text: '#ffffff',
186
- textMuted: '#cccccc',
187
- error: '#ff3333',
188
- warning: '#ffaa00',
189
- success: '#00cc66',
190
- info: '#0099ff',
191
- border: '#666666',
192
- divider: '#555555',
193
- } as const;
194
-
195
- /**
196
- * Complete brand color scheme
197
- * @constant {Readonly<BrandColorScheme>}
198
- */
199
- export const BrandColors: BrandColorScheme = {
200
- light: LightColors,
201
- dark: DarkColors,
202
- highContrast: HighContrastColors,
203
- } as const;
204
-
205
- /**
206
- * Brand typography configuration
207
- * @interface BrandTypography
208
- */
209
- export interface BrandTypography {
210
- /** Font family stack */
211
- readonly fontFamily: string;
212
-
213
- /** Monospace font family for code */
214
- readonly fontFamilyMono: string;
215
-
216
- /** Base font size in pixels */
217
- readonly baseSize: number;
218
-
219
- /** Line height ratio */
220
- readonly lineHeight: number;
221
-
222
- /** Font weights */
223
- readonly weights: {
224
- readonly normal: number;
225
- readonly medium: number;
226
- readonly semibold: number;
227
- readonly bold: number;
228
- };
229
-
230
- /** Type scale sizes */
231
- readonly scale: {
232
- readonly xs: number;
233
- readonly sm: number;
234
- readonly base: number;
235
- readonly lg: number;
236
- readonly xl: number;
237
- readonly '2xl': number;
238
- readonly '3xl': number;
239
- readonly '4xl': number;
240
- };
241
- }
242
-
243
- /**
244
- * Default brand typography
245
- * @constant {Readonly<BrandTypography>}
246
- */
247
- export const BrandTypography: BrandTypography = {
248
- fontFamily:
249
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
250
- fontFamilyMono:
251
- 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',
252
- baseSize: 16,
253
- lineHeight: 1.5,
254
- weights: {
255
- normal: 400,
256
- medium: 500,
257
- semibold: 600,
258
- bold: 700,
259
- },
260
- scale: {
261
- xs: 0.75, // 12px
262
- sm: 0.875, // 14px
263
- base: 1, // 16px
264
- lg: 1.125, // 18px
265
- xl: 1.25, // 20px
266
- '2xl': 1.5, // 24px
267
- '3xl': 1.875,// 30px
268
- '4xl': 2.25, // 36px
269
- },
270
- } as const;
271
-
272
- /**
273
- * Brand spacing configuration (in rem units base)
274
- * @constant {Readonly<Record<string, number>>}
275
- */
276
- export const BrandSpacing = {
277
- none: 0,
278
- xs: 0.25, // 4px
279
- sm: 0.5, // 8px
280
- md: 1, // 16px
281
- lg: 1.5, // 24px
282
- xl: 2, // 32px
283
- '2xl': 3, // 48px
284
- '3xl': 4, // 64px
285
- '4xl': 6, // 96px
286
- '5xl': 8, // 128px
287
- } as const;
288
-
289
- /**
290
- * Brand border radius values
291
- * @constant {Readonly<Record<string, string>>}
292
- */
293
- export const BrandBorderRadius = {
294
- none: '0',
295
- sm: '0.125rem', // 2px
296
- md: '0.25rem', // 4px
297
- lg: '0.5rem', // 8px
298
- xl: '0.75rem', // 12px
299
- '2xl': '1rem', // 16px
300
- full: '9999px',
301
- } as const;
302
-
303
- /**
304
- * Brand shadow values
305
- * @constant {Readonly<Record<string, string>>}
306
- */
307
- export const BrandShadows = {
308
- none: 'none',
309
- sm: '0 1px 2px 0 rgb(0 0 0 / 0.05)',
310
- md: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
311
- lg: '0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
312
- xl: '0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)',
313
- '2xl': '0 25px 50px -12px rgb(0 0 0 / 0.25)',
314
- inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
315
- } as const;
316
-
317
- /**
318
- * Brand breakpoints for responsive design
319
- * @constant {Readonly<Record<string, number>>}
320
- */
321
- export const BrandBreakpoints = {
322
- xs: 0,
323
- sm: 640,
324
- md: 768,
325
- lg: 1024,
326
- xl: 1280,
327
- '2xl': 1536,
328
- } as const;
329
-
330
- /**
331
- * Animation timing values
332
- * @constant {Readonly<Record<string, number>>}
333
- */
334
- export const BrandAnimation = {
335
- instant: 0,
336
- fast: 100,
337
- normal: 200,
338
- slow: 300,
339
- slower: 500,
340
- } as const;
341
-
342
- /**
343
- * Easing functions
344
- * @constant {Readonly<Record<string, string>>}
345
- */
346
- export const BrandEasing = {
347
- linear: 'linear',
348
- ease: 'ease',
349
- easeIn: 'ease-in',
350
- easeOut: 'ease-out',
351
- easeInOut: 'ease-in-out',
352
- spring: 'cubic-bezier(0.34, 1.56, 0.64, 1)',
353
- } as const;
354
-
355
- /**
356
- * Complete brand configuration object
357
- * @interface BrandConfig
358
- */
359
- export interface BrandConfig {
360
- readonly name: typeof Brand;
361
- readonly version: typeof BrandVersion;
362
- readonly colors: BrandColorScheme;
363
- readonly typography: BrandTypography;
364
- readonly spacing: typeof BrandSpacing;
365
- readonly borderRadius: typeof BrandBorderRadius;
366
- readonly shadows: typeof BrandShadows;
367
- readonly breakpoints: typeof BrandBreakpoints;
368
- readonly animation: typeof BrandAnimation;
369
- readonly easing: typeof BrandEasing;
370
- }
371
-
372
- /**
373
- * Complete brand configuration
374
- * @constant {Readonly<BrandConfig>}
375
- */
376
- export const BrandConfig: BrandConfig = {
377
- name: Brand,
378
- version: BrandVersion,
379
- colors: BrandColors,
380
- typography: BrandTypography,
381
- spacing: BrandSpacing,
382
- borderRadius: BrandBorderRadius,
383
- shadows: BrandShadows,
384
- breakpoints: BrandBreakpoints,
385
- animation: BrandAnimation,
386
- easing: BrandEasing,
387
- } as const;
388
-
389
- /**
390
- * Get brand colors for a specific theme mode
391
- *
392
- * @param {ThemeMode} mode - Theme mode to get colors for
393
- * @param {BrandColorScheme} colors - Color scheme to use (defaults to BrandColors)
394
- * @returns {BrandColorPalette} Color palette for the specified mode
395
- *
396
- * @example
397
- * ```typescript
398
- * const darkColors = getBrandColors('dark');
399
- * console.log(darkColors.background); // '#0f172a'
400
- * ```
401
- */
402
- export function getBrandColors(
403
- mode: ThemeMode,
404
- colors: BrandColorScheme = BrandColors
405
- ): BrandColorPalette {
406
- switch (mode) {
407
- case 'light':
408
- return colors.light;
409
- case 'dark':
410
- return colors.dark;
411
- case 'high-contrast':
412
- return colors.highContrast;
413
- case 'auto':
414
- // Auto-detect based on system preference
415
- if (typeof window !== 'undefined' && window.matchMedia) {
416
- const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
417
- return prefersDark ? colors.dark : colors.light;
418
- }
419
- return colors.light;
420
- default:
421
- return colors.light;
422
- }
423
- }
424
-
425
- /**
426
- * Convert hex color to RGB values
427
- *
428
- * @param {HexColor} hex - Hex color value
429
- * @returns {RGBColor | null} RGB values or null if invalid
430
- *
431
- * @example
432
- * ```typescript
433
- * const rgb = hexToRgb('#2563eb');
434
- * console.log(rgb); // { r: 37, g: 99, b: 235 }
435
- * ```
436
- */
437
- export function hexToRgb(hex: HexColor): RGBColor | null {
438
- const cleanHex = hex.replace('#', '');
439
-
440
- if (!/^[0-9a-fA-F]{6}$/.test(cleanHex)) {
441
- return null;
442
- }
443
-
444
- const r = parseInt(cleanHex.substring(0, 2), 16);
445
- const g = parseInt(cleanHex.substring(2, 4), 16);
446
- const b = parseInt(cleanHex.substring(4, 6), 16);
447
-
448
- return { r, g, b };
449
- }
450
-
451
- /**
452
- * Convert RGB values to hex color
453
- *
454
- * @param {number} r - Red value (0-255)
455
- * @param {number} g - Green value (0-255)
456
- * @param {number} b - Blue value (0-255)
457
- * @returns {HexColor} Hex color value
458
- *
459
- * @example
460
- * ```typescript
461
- * const hex = rgbToHex(37, 99, 235);
462
- * console.log(hex); // '#2563eb'
463
- * ```
464
- */
465
- export function rgbToHex(r: number, g: number, b: number): HexColor {
466
- const clamp = (n: number) => Math.max(0, Math.min(255, n));
467
- const toHex = (n: number) => clamp(n).toString(16).padStart(2, '0');
468
-
469
- return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
470
- }
471
-
472
- /**
473
- * Convert hex color to RGBA with alpha
474
- *
475
- * @param {HexColor} hex - Hex color value
476
- * @param {number} alpha - Alpha value (0-1)
477
- * @returns {string} RGBA color string
478
- *
479
- * @example
480
- * ```typescript
481
- * const rgba = hexToRgba('#2563eb', 0.5);
482
- * console.log(rgba); // 'rgba(37, 99, 235, 0.5)'
483
- * ```
484
- */
485
- export function hexToRgba(hex: HexColor, alpha: number): string {
486
- const rgb = hexToRgb(hex);
487
- if (!rgb) {
488
- throw new Error(`Invalid hex color: ${hex}`);
489
- }
490
- return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${Math.max(0, Math.min(1, alpha))})`;
491
- }
492
-
493
- /**
494
- * Lighten a hex color by a percentage
495
- *
496
- * @param {HexColor} hex - Hex color value
497
- * @param {number} percent - Percentage to lighten (0-100)
498
- * @returns {HexColor} Lightened hex color
499
- *
500
- * @example
501
- * ```typescript
502
- * const lightBlue = lightenColor('#2563eb', 20);
503
- * ```
504
- */
505
- export function lightenColor(hex: HexColor, percent: number): HexColor {
506
- const rgb = hexToRgb(hex);
507
- if (!rgb) {
508
- throw new Error(`Invalid hex color: ${hex}`);
509
- }
510
-
511
- const amount = Math.floor((255 * percent) / 100);
512
-
513
- return rgbToHex(
514
- rgb.r + amount,
515
- rgb.g + amount,
516
- rgb.b + amount
517
- );
518
- }
519
-
520
- /**
521
- * Darken a hex color by a percentage
522
- *
523
- * @param {HexColor} hex - Hex color value
524
- * @param {number} percent - Percentage to darken (0-100)
525
- * @returns {HexColor} Darkened hex color
526
- *
527
- * @example
528
- * ```typescript
529
- * const darkBlue = darkenColor('#2563eb', 20);
530
- * ```
531
- */
532
- export function darkenColor(hex: HexColor, percent: number): HexColor {
533
- const rgb = hexToRgb(hex);
534
- if (!rgb) {
535
- throw new Error(`Invalid hex color: ${hex}`);
536
- }
537
-
538
- const amount = Math.floor((255 * percent) / 100);
539
-
540
- return rgbToHex(
541
- rgb.r - amount,
542
- rgb.g - amount,
543
- rgb.b - amount
544
- );
545
- }
546
-
547
- /**
548
- * Check if a color is light (for determining text contrast)
549
- *
550
- * @param {HexColor} hex - Hex color value
551
- * @returns {boolean} True if the color is light
552
- *
553
- * @example
554
- * ```typescript
555
- * const isLight = isLightColor('#ffffff'); // true
556
- * const isDark = isLightColor('#000000'); // false
557
- * ```
558
- */
559
- export function isLightColor(hex: HexColor): boolean {
560
- const rgb = hexToRgb(hex);
561
- if (!rgb) {
562
- return false;
563
- }
564
-
565
- // Calculate relative luminance
566
- const luminance = (0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b) / 255;
567
-
568
- return luminance > 0.5;
569
- }
570
-
571
- /**
572
- * Get the appropriate text color (light or dark) for contrast against a background
573
- *
574
- * @param {HexColor} backgroundColor - Background hex color
575
- * @returns {{ light: HexColor; dark: HexColor }} Text colors for contrast
576
- *
577
- * @example
578
- * ```typescript
579
- * const textColors = getContrastText('#2563eb');
580
- * console.log(textColors.light); // '#ffffff' (use this for dark backgrounds)
581
- * ```
582
- */
583
- export function getContrastText(backgroundColor: HexColor): {
584
- light: HexColor;
585
- dark: HexColor;
586
- } {
587
- return {
588
- light: '#ffffff',
589
- dark: '#0f172a',
590
- };
591
- }
592
-
593
- /**
594
- * Get the best text color for contrast against a background
595
- *
596
- * @param {HexColor} backgroundColor - Background hex color
597
- * @returns {HexColor} Best text color for contrast
598
- *
599
- * @example
600
- * ```typescript
601
- * const textColor = getBestContrastText('#0f172a'); // '#ffffff'
602
- * ```
603
- */
604
- export function getBestContrastText(backgroundColor: HexColor): HexColor {
605
- return isLightColor(backgroundColor) ? '#0f172a' : '#ffffff';
606
- }
607
-
608
- /**
609
- * CSS custom properties (variables) generator for brand colors
610
- *
611
- * @param {ThemeMode} mode - Theme mode
612
- * @returns {Record<string, string>} CSS variable names and values
613
- *
614
- * @example
615
- * ```typescript
616
- * const cssVars = generateCSSVariables('dark');
617
- * // { '--gizzi-primary': '#3b82f6', ... }
618
- * ```
619
- */
620
- export function generateCSSVariables(mode: ThemeMode): Record<string, string> {
621
- const colors = getBrandColors(mode);
622
- const prefix = '--gizzi';
623
-
624
- return {
625
- [`${prefix}-primary`]: colors.primary,
626
- [`${prefix}-secondary`]: colors.secondary,
627
- [`${prefix}-accent`]: colors.accent,
628
- [`${prefix}-background`]: colors.background,
629
- [`${prefix}-surface`]: colors.surface,
630
- [`${prefix}-text`]: colors.text,
631
- [`${prefix}-text-muted`]: colors.textMuted,
632
- [`${prefix}-error`]: colors.error,
633
- [`${prefix}-warning`]: colors.warning,
634
- [`${prefix}-success`]: colors.success,
635
- [`${prefix}-info`]: colors.info,
636
- [`${prefix}-border`]: colors.border,
637
- [`${prefix}-divider`]: colors.divider,
638
- };
639
- }
640
-
641
- // Default export
642
- export default {
643
- Brand,
644
- BrandVersion,
645
- BrandColors,
646
- BrandConfig,
647
- LightColors,
648
- DarkColors,
649
- HighContrastColors,
650
- BrandTypography,
651
- BrandSpacing,
652
- BrandBorderRadius,
653
- BrandShadows,
654
- BrandBreakpoints,
655
- BrandAnimation,
656
- BrandEasing,
657
- getBrandColors,
658
- hexToRgb,
659
- rgbToHex,
660
- hexToRgba,
661
- lightenColor,
662
- darkenColor,
663
- isLightColor,
664
- getContrastText,
665
- getBestContrastText,
666
- generateCSSVariables,
667
- };