@vibes.diy/use-vibes-base 0.12.0-dev-preview

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 (89) hide show
  1. package/LICENSE.md +232 -0
  2. package/README.md +549 -0
  3. package/components/ControlsBar.d.ts +20 -0
  4. package/components/ControlsBar.js +84 -0
  5. package/components/ControlsBar.js.map +1 -0
  6. package/components/ImgGen.css +675 -0
  7. package/components/ImgGen.d.ts +24 -0
  8. package/components/ImgGen.js +256 -0
  9. package/components/ImgGen.js.map +1 -0
  10. package/components/ImgGenUtils/ImgGenDisplay.d.ts +3 -0
  11. package/components/ImgGenUtils/ImgGenDisplay.js +192 -0
  12. package/components/ImgGenUtils/ImgGenDisplay.js.map +1 -0
  13. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.d.ts +3 -0
  14. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js +90 -0
  15. package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js.map +1 -0
  16. package/components/ImgGenUtils/ImgGenDisplayUtils.d.ts +27 -0
  17. package/components/ImgGenUtils/ImgGenDisplayUtils.js +95 -0
  18. package/components/ImgGenUtils/ImgGenDisplayUtils.js.map +1 -0
  19. package/components/ImgGenUtils/ImgGenError.d.ts +3 -0
  20. package/components/ImgGenUtils/ImgGenError.js +7 -0
  21. package/components/ImgGenUtils/ImgGenError.js.map +1 -0
  22. package/components/ImgGenUtils/ImgGenFileDrop.d.ts +11 -0
  23. package/components/ImgGenUtils/ImgGenFileDrop.js +49 -0
  24. package/components/ImgGenUtils/ImgGenFileDrop.js.map +1 -0
  25. package/components/ImgGenUtils/ImgGenModal.d.ts +24 -0
  26. package/components/ImgGenUtils/ImgGenModal.js +63 -0
  27. package/components/ImgGenUtils/ImgGenModal.js.map +1 -0
  28. package/components/ImgGenUtils/ImgGenModeUtils.d.ts +9 -0
  29. package/components/ImgGenUtils/ImgGenModeUtils.js +48 -0
  30. package/components/ImgGenUtils/ImgGenModeUtils.js.map +1 -0
  31. package/components/ImgGenUtils/ImgGenPromptWaiting.d.ts +11 -0
  32. package/components/ImgGenUtils/ImgGenPromptWaiting.js +36 -0
  33. package/components/ImgGenUtils/ImgGenPromptWaiting.js.map +1 -0
  34. package/components/ImgGenUtils/ImgGenUploadWaiting.d.ts +16 -0
  35. package/components/ImgGenUtils/ImgGenUploadWaiting.js +131 -0
  36. package/components/ImgGenUtils/ImgGenUploadWaiting.js.map +1 -0
  37. package/components/ImgGenUtils/index.d.ts +6 -0
  38. package/components/ImgGenUtils/index.js +7 -0
  39. package/components/ImgGenUtils/index.js.map +1 -0
  40. package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.d.ts +9 -0
  41. package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.js +30 -0
  42. package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.js.map +1 -0
  43. package/components/ImgGenUtils/overlays/ImageOverlay.d.ts +22 -0
  44. package/components/ImgGenUtils/overlays/ImageOverlay.js +8 -0
  45. package/components/ImgGenUtils/overlays/ImageOverlay.js.map +1 -0
  46. package/components/ImgGenUtils/types.d.ts +29 -0
  47. package/components/ImgGenUtils/types.js +2 -0
  48. package/components/ImgGenUtils/types.js.map +1 -0
  49. package/components/ImgGenUtils.d.ts +2 -0
  50. package/components/ImgGenUtils.js +3 -0
  51. package/components/ImgGenUtils.js.map +1 -0
  52. package/components/PromptBar.d.ts +11 -0
  53. package/components/PromptBar.js +23 -0
  54. package/components/PromptBar.js.map +1 -0
  55. package/hooks/image-gen/image-generator.d.ts +11 -0
  56. package/hooks/image-gen/image-generator.js +136 -0
  57. package/hooks/image-gen/image-generator.js.map +1 -0
  58. package/hooks/image-gen/index.d.ts +7 -0
  59. package/hooks/image-gen/index.js +6 -0
  60. package/hooks/image-gen/index.js.map +1 -0
  61. package/hooks/image-gen/types.d.ts +66 -0
  62. package/hooks/image-gen/types.js +2 -0
  63. package/hooks/image-gen/types.js.map +1 -0
  64. package/hooks/image-gen/use-image-gen.d.ts +4 -0
  65. package/hooks/image-gen/use-image-gen.js +544 -0
  66. package/hooks/image-gen/use-image-gen.js.map +1 -0
  67. package/hooks/image-gen/utils.d.ts +20 -0
  68. package/hooks/image-gen/utils.js +159 -0
  69. package/hooks/image-gen/utils.js.map +1 -0
  70. package/hooks/use-image-gen.d.ts +1 -0
  71. package/hooks/use-image-gen.js +2 -0
  72. package/hooks/use-image-gen.js.map +1 -0
  73. package/index.d.ts +22 -0
  74. package/index.js +21 -0
  75. package/index.js.map +1 -0
  76. package/package.json +30 -0
  77. package/tsconfig.json +22 -0
  78. package/utils/base64.d.ts +1 -0
  79. package/utils/base64.js +13 -0
  80. package/utils/base64.js.map +1 -0
  81. package/utils/debug.d.ts +2 -0
  82. package/utils/debug.js +8 -0
  83. package/utils/debug.js.map +1 -0
  84. package/utils/style-utils.d.ts +17 -0
  85. package/utils/style-utils.js +15 -0
  86. package/utils/style-utils.js.map +1 -0
  87. package/utils/styles.d.ts +227 -0
  88. package/utils/styles.js +230 -0
  89. package/utils/styles.js.map +1 -0
package/README.md ADDED
@@ -0,0 +1,549 @@
1
+ # use-vibes
2
+
3
+ A lightweight library that transforms any DOM element into an AI-powered micro-app.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add use-vibes
9
+ ```
10
+
11
+ ## Basic Usage
12
+
13
+ ```jsx
14
+ import { ImgGen } from 'use-vibes';
15
+
16
+ function MyComponent() {
17
+ // You can use ImgGen without any props - it includes its own form UI
18
+ return <ImgGen />;
19
+
20
+ // Or provide a prompt directly (bypasses the form UI completely)
21
+ // return <ImgGen prompt="A futuristic cityscape with flying cars" />;
22
+ }
23
+ ```
24
+
25
+ For image manipulation using base64 data:
26
+
27
+ ```jsx
28
+ import { base64ToFile } from 'use-vibes';
29
+
30
+ // Convert API response to a File object
31
+ const imageFile = base64ToFile(imageResponse.data[0].b64_json, 'my-image.png');
32
+ ```
33
+
34
+ ## Core Features
35
+
36
+ ### Interactive Image Generation
37
+
38
+ - **Zero-config Implementation**: Add AI image generation to any React app without any configuration
39
+
40
+ ```jsx
41
+ {
42
+ /* Includes a built-in form UI for prompt entry and image upload */
43
+ }
44
+ <ImgGen />;
45
+ ```
46
+
47
+ - **One-line Implementation**: Directly specify a prompt for immediate generation (bypasses the form UI)
48
+
49
+ ```jsx
50
+ {
51
+ /* Starts generating immediately, no form shown to the user */
52
+ }
53
+ <ImgGen prompt="A sunset over mountains" />;
54
+ ```
55
+
56
+ - **Automatic Database Integration**: All images are automatically stored in Fireproof database with version history
57
+
58
+ ```jsx
59
+ // Custom database name
60
+ <ImgGen prompt="Forest landscape" database="MyCustomDB" />
61
+
62
+ // Or pass a database instance
63
+ <ImgGen prompt="Forest landscape" database={myDbInstance} />
64
+ ```
65
+
66
+ ### Prompt Management
67
+
68
+ - **Prompt Versioning**: Tracks the history of different prompts used to generate an image
69
+ - Uses a structured `prompts` object with timestamp-based keys
70
+ - Maintains `currentPromptKey` to reference the active prompt
71
+
72
+ - **Prompt Editing**: Users can edit prompts directly in the overlay UI
73
+ - Double-click the prompt text to edit
74
+ - Press Enter to submit and regenerate with new prompt
75
+ - App receives updates via `onPromptEdit` callback
76
+ ```jsx
77
+ <ImgGen
78
+ prompt="Initial prompt"
79
+ onPromptEdit={(id, newPrompt) => {
80
+ console.log(`Document ${id} updated with new prompt: ${newPrompt}`);
81
+ }}
82
+ />
83
+ ```
84
+
85
+ ### Image Control & Manipulation
86
+
87
+ - **Image Regeneration**: One-click regeneration with the same or edited prompt
88
+ - Preserves document history and adds new versions
89
+ - Uses a unique `generationId` to trigger regeneration while maintaining context
90
+
91
+ - **Image Quality Control**: Set quality levels for output images
92
+
93
+ ```jsx
94
+ <ImgGen prompt="Detailed artwork" options={{ quality: 'high' }} />
95
+ ```
96
+
97
+ - **Image Editing with Uploads**: Process existing images with AI
98
+
99
+ ```jsx
100
+ <ImgGen prompt="Turn this photo into a watercolor painting" images={[myImageFile]} />
101
+ ```
102
+
103
+ - **Multiple Image Inputs**: Combine multiple images in one generation
104
+ ```jsx
105
+ <ImgGen prompt="Create a collage of these photos" images={[photo1, photo2, photo3]} />
106
+ ```
107
+
108
+ ### User Interface Components
109
+
110
+ - **Interactive Overlay**: Toggle-able information and controls overlay
111
+ - Shows prompt text (editable)
112
+ - Version navigation controls
113
+ - Regenerate/refresh button
114
+ - Delete button
115
+
116
+ ```jsx
117
+ // Disable overlay for a minimal UI
118
+ <ImgGen prompt="Clean interface" overlay={false} />
119
+ ```
120
+
121
+ - **Progress Visualization**: Shows generation progress with visual indicators
122
+ - Progress bar updates in real-time
123
+ - Automatic placeholder display during generation
124
+
125
+ - **Error Handling UI**: Clean error states with informative messages
126
+ ```jsx
127
+ <ImgGen
128
+ prompt="Test error handling"
129
+ onError={(error) => {
130
+ console.error('Generation failed:', error.message);
131
+ }}
132
+ />
133
+ ```
134
+
135
+ ### File Management
136
+
137
+ - **File Upload Interface**: Built-in support for image uploads
138
+ - Drag-and-drop capabilities
139
+ - File selection dialog
140
+ - Preview of uploaded content
141
+
142
+ - **Base64 Conversion**: Convert between base64 and File objects
143
+
144
+ ```jsx
145
+ import { base64ToFile } from 'use-vibes';
146
+
147
+ // Convert API response to a File object
148
+ const imageFile = base64ToFile(imageResponse.data[0].b64_json, 'my-image.png');
149
+ ```
150
+
151
+ ## Integration Features
152
+
153
+ ### Event Callbacks
154
+
155
+ - **Generation Lifecycle Events**: Track the complete generation process
156
+ ```jsx
157
+ <ImgGen
158
+ prompt="Track this generation"
159
+ onComplete={() => console.log('Generation complete!')}
160
+ onError={(error) => console.error('Generation failed:', error)}
161
+ onDelete={(id) => console.log(`Document ${id} deleted`)}
162
+ onDocumentCreated={(id) => console.log(`New document created: ${id}`)}
163
+ />
164
+ ```
165
+
166
+ ### State Management
167
+
168
+ - **Loading States**: Component handles all loading states internally
169
+ - Initial waiting state
170
+ - Generation in progress state
171
+ - Upload waiting state
172
+ - Display state for completed images
173
+ - Error state
174
+
175
+ - **Document Identity Tracking**: Smart re-mounting based on document changes
176
+ - Uses internal `mountKey` system to ensure clean state transitions
177
+ - Detects identity changes through document ID, prompt, or uploaded file documents
178
+
179
+ ### UI Customization
180
+
181
+ - **Extensive Styling Options**: Multiple ways to customize appearance
182
+ - CSS Variables for global styling
183
+
184
+ ```css
185
+ :root {
186
+ --imggen-text-color: #222;
187
+ --imggen-overlay-bg: rgba(245, 245, 245, 0.85);
188
+ --imggen-accent: #0088ff;
189
+ --imggen-border-radius: 4px;
190
+ }
191
+ ```
192
+
193
+ - Custom classes for component-level styling
194
+
195
+ ```jsx
196
+ <ImgGen
197
+ prompt="Styled component"
198
+ classes={{
199
+ root: 'my-custom-container',
200
+ image: 'rounded-xl shadow-lg',
201
+ overlay: 'bg-slate-800/70 text-white',
202
+ progress: 'h-2 bg-green-500',
203
+ }}
204
+ />
205
+ ```
206
+
207
+ ### Gallery Integration
208
+
209
+ - **Thumbnail Support**: Easily create image galleries
210
+
211
+ ```jsx
212
+ <div className="image-grid">
213
+ {imageDocuments.map((doc) => (
214
+ <ImgGen key={doc._id} _id={doc._id} className="thumbnail" />
215
+ ))}
216
+ </div>
217
+ ```
218
+
219
+ - **Document Reuse**: Load existing documents by ID
220
+ ```jsx
221
+ <ImgGen _id="existing-document-id" />
222
+ ```
223
+
224
+ ## Implementation Modes
225
+
226
+ The ImgGen component has several operational modes that it switches between automatically:
227
+
228
+ 1. **Placeholder Mode**: Initial state when no prompt or document ID is provided
229
+ 2. **Upload Waiting Mode**: When files are uploaded but waiting for a prompt
230
+ 3. **Generating Mode**: During the image generation process
231
+ 4. **Display Mode**: When showing a generated image with controls
232
+ 5. **Error Mode**: When an error occurs during generation
233
+
234
+ The component automatically determines which mode to use based on the current state, providing a seamless experience for both developers and end-users.
235
+
236
+ ## Advanced Usage
237
+
238
+ ### Debug Mode
239
+
240
+ Enable debug mode to see detailed console logs about component state:
241
+
242
+ ```jsx
243
+ <ImgGen prompt="Debug this" options={{ debug: true }} />
244
+ ```
245
+
246
+ ### Custom Image Sizing
247
+
248
+ Control output image dimensions with the size option:
249
+
250
+ ```jsx
251
+ <ImgGen
252
+ prompt="Landscape format"
253
+ options={{ size: '1536x1024' }} // Landscape
254
+ />
255
+
256
+ <ImgGen
257
+ prompt="Portrait format"
258
+ options={{ size: '1024x1536' }} // Portrait
259
+ />
260
+ ```
261
+
262
+ # Advanced Usage
263
+
264
+ This guide covers the implementation, configuration, and best practices for using the ImgGen component from the use-vibes library.
265
+
266
+ ## Installation
267
+
268
+ ```bash
269
+ pnpm add use-vibes
270
+ ```
271
+
272
+ ### Styling
273
+
274
+ The ImgGen component uses inline styles with centralized theme constants, so **no separate CSS setup is required**. All styling is self-contained within the component.
275
+
276
+ ## Basic Usage
277
+
278
+ ### Simple Image Generation
279
+
280
+ Add AI image generation to any React app with minimal code:
281
+
282
+ ```jsx
283
+ import { ImgGen } from 'use-vibes';
284
+
285
+ function MyComponent() {
286
+ return (
287
+ <div>
288
+ <ImgGen prompt="A sunset over mountains" />
289
+ </div>
290
+ );
291
+ }
292
+ ```
293
+
294
+ ### Configuration Options
295
+
296
+ Configure image generation with the `options` prop:
297
+
298
+ ```jsx
299
+ <ImgGen
300
+ prompt="A detailed cityscape"
301
+ options={{
302
+ model: 'gpt-image-1',
303
+ quality: 'high',
304
+ size: '1024x1024',
305
+ debug: false,
306
+ }}
307
+ />
308
+ ```
309
+
310
+ ### Available Props
311
+
312
+ | Prop | Type | Description |
313
+ | ------------------- | ------------------ | ----------------------------------------------------------------------- |
314
+ | `prompt` | string | Text prompt for image generation (required unless `_id` is provided) |
315
+ | `_id` | string | Document ID to load a specific image instead of generating a new one |
316
+ | `className` | string | CSS class name for the image element |
317
+ | `alt` | string | Alt text for the image (defaults to prompt) |
318
+ | `images` | File[] | Array of images to edit or combine with AI |
319
+ | `options` | object | Configuration options (see table below) |
320
+ | `database` | string \| Database | Database name or instance to use for storing images |
321
+ | `onComplete` | function | Callback when image load completes successfully |
322
+ | `onError` | function | Callback when image load fails, receives the error as parameter |
323
+ | `onDelete` | function | Callback when an image is deleted, receives the document ID |
324
+ | `onPromptEdit` | function | Callback when the prompt is edited, receives document ID and new prompt |
325
+ | `onDocumentCreated` | function | Callback when a new document is created via drop or file picker |
326
+ | `overlay` | boolean | Whether to show overlay controls and info button (default: `true`) |
327
+ | `classes` | object | Custom CSS classes for styling component parts |
328
+ | `debug` | boolean | Enable debug logging |
329
+
330
+ ### Options Object Properties
331
+
332
+ | Property | Type | Description |
333
+ | --------- | ------- | ------------------------------------------------------------------------ |
334
+ | `model` | string | Model to use for image generation, defaults to 'gpt-image-1' |
335
+ | `size` | string | Size of the generated image (1024x1024, 1536x1024, 1024x1536, or 'auto') |
336
+ | `quality` | string | Quality of the generated image (high, medium, low, or auto) |
337
+ | `debug` | boolean | Enable debug logging, defaults to false |
338
+
339
+ ## Advanced Features
340
+
341
+ ### Prompt Management
342
+
343
+ The ImgGen component tracks the history of different prompts used to generate an image:
344
+
345
+ ```jsx
346
+ <ImgGen
347
+ prompt="Initial prompt"
348
+ onPromptEdit={(id, newPrompt) => {
349
+ console.log(`Document ${id} updated with new prompt: ${newPrompt}`);
350
+ }}
351
+ />
352
+ ```
353
+
354
+ Users can edit prompts directly by double-clicking the prompt text in the overlay UI, then pressing Enter to submit and regenerate with the new prompt.
355
+
356
+ ### Image Control & Manipulation
357
+
358
+ #### Image Regeneration
359
+
360
+ The component supports one-click regeneration, preserving document history while adding new versions:
361
+
362
+ ```jsx
363
+ // The regeneration happens internally when the user clicks the refresh button
364
+ // or when a new prompt is submitted
365
+ ```
366
+
367
+ #### Image Quality Control
368
+
369
+ Set quality levels for output images:
370
+
371
+ ```jsx
372
+ <ImgGen prompt="Detailed artwork" options={{ quality: 'high' }} />
373
+ ```
374
+
375
+ #### Image Editing with Uploads
376
+
377
+ Process existing images with AI:
378
+
379
+ ```jsx
380
+ <ImgGen prompt="Turn this photo into a watercolor painting" images={[myImageFile]} />
381
+ ```
382
+
383
+ #### Multiple Image Inputs
384
+
385
+ Combine multiple images in one generation:
386
+
387
+ ```jsx
388
+ <ImgGen prompt="Create a collage of these photos" images={[photo1, photo2, photo3]} />
389
+ ```
390
+
391
+ ### Database Integration
392
+
393
+ All images are automatically stored in a Fireproof database with version history:
394
+
395
+ ```jsx
396
+ // Custom database name
397
+ <ImgGen prompt="Forest landscape" database="MyCustomDB" />
398
+
399
+ // Or pass a database instance
400
+ <ImgGen prompt="Forest landscape" database={myDbInstance} />
401
+ ```
402
+
403
+ ### Event Callbacks
404
+
405
+ Track the complete generation process with lifecycle events:
406
+
407
+ ```jsx
408
+ <ImgGen
409
+ prompt="Track this generation"
410
+ onComplete={() => console.log('Generation complete!')}
411
+ onError={(error) => console.error('Generation failed:', error)}
412
+ onDelete={(id) => console.log(`Document ${id} deleted`)}
413
+ onDocumentCreated={(id) => console.log(`New document created: ${id}`)}
414
+ />
415
+ ```
416
+
417
+ ### UI Controls
418
+
419
+ Toggle the information overlay and controls:
420
+
421
+ ```jsx
422
+ // Disable overlay for a minimal UI
423
+ <ImgGen prompt="Clean interface" overlay={false} />
424
+ ```
425
+
426
+ The overlay includes:
427
+
428
+ - Prompt text (editable)
429
+ - Version navigation controls
430
+ - Regenerate/refresh button
431
+ - Delete button
432
+
433
+ ### File Management
434
+
435
+ #### Base64 Conversion
436
+
437
+ Convert between base64 and File objects:
438
+
439
+ ```jsx
440
+ import { base64ToFile } from 'use-vibes';
441
+
442
+ // Convert API response to a File object
443
+ const imageFile = base64ToFile(imageResponse.data[0].b64_json, 'my-image.png');
444
+ ```
445
+
446
+ ## Styling and Customization
447
+
448
+ ### CSS Variables
449
+
450
+ The component uses centralized theme constants from `imgGenTheme` for consistent styling. All styles are applied inline using JavaScript objects, eliminating the need for external CSS files.
451
+
452
+ ### Custom Classes
453
+
454
+ For more granular control, provide a `classes` object with custom CSS classes for specific component parts:
455
+
456
+ ```jsx
457
+ <ImgGen
458
+ prompt="Styled component"
459
+ classes={{
460
+ root: 'my-custom-container',
461
+ image: 'rounded-xl shadow-lg',
462
+ overlay: 'bg-slate-800/70 text-white',
463
+ progress: 'h-2 bg-green-500',
464
+ button: 'hover:bg-blue-600',
465
+ }}
466
+ />
467
+ ```
468
+
469
+ ### Available Class Slots
470
+
471
+ | Class Property | Description |
472
+ | --------------- | -------------------------------- |
473
+ | `root` | Main container element |
474
+ | `image` | The image element |
475
+ | `container` | Container for image and controls |
476
+ | `overlay` | Overlay panel with controls |
477
+ | `progress` | Progress indicator |
478
+ | `placeholder` | Placeholder shown during loading |
479
+ | `error` | Error message container |
480
+ | `controls` | Control buttons container |
481
+ | `button` | Individual buttons |
482
+ | `prompt` | Prompt text/input container |
483
+ | `deleteOverlay` | Delete confirmation dialog |
484
+
485
+ ## Gallery Implementation
486
+
487
+ ### Creating an Image Gallery
488
+
489
+ Easily create image galleries using document IDs:
490
+
491
+ ```jsx
492
+ <div className="image-grid">
493
+ {imageDocuments.map((doc) => (
494
+ <ImgGen key={doc._id} _id={doc._id} className="thumbnail" />
495
+ ))}
496
+ </div>
497
+ ```
498
+
499
+ ### Loading Existing Documents
500
+
501
+ Load existing documents by ID:
502
+
503
+ ```jsx
504
+ <ImgGen _id="existing-document-id" />
505
+ ```
506
+
507
+ ## Operation Modes
508
+
509
+ The ImgGen component has several operational modes that it switches between automatically:
510
+
511
+ 1. **Placeholder Mode**: Initial state when no prompt or document ID is provided
512
+ 2. **Upload Waiting Mode**: When files are uploaded but waiting for a prompt
513
+ 3. **Generating Mode**: During the image generation process
514
+ 4. **Display Mode**: When showing a generated image with controls
515
+ 5. **Error Mode**: When an error occurs during generation
516
+
517
+ ## Advanced Usage Examples
518
+
519
+ ### Debug Mode
520
+
521
+ Enable debug mode to see detailed console logs about component state:
522
+
523
+ ```jsx
524
+ <ImgGen prompt="Debug this" options={{ debug: true }} />
525
+ ```
526
+
527
+ ### Custom Image Sizing
528
+
529
+ Control output image dimensions with the size option:
530
+
531
+ ```jsx
532
+ <ImgGen
533
+ prompt="Landscape format"
534
+ options={{ size: '1536x1024' }} // Landscape
535
+ />
536
+
537
+ <ImgGen
538
+ prompt="Portrait format"
539
+ options={{ size: '1024x1536' }} // Portrait
540
+ />
541
+ ```
542
+
543
+ ### Browser Compatibility
544
+
545
+ This library is compatible with all modern browsers that support React 18+ and ES6 features.
546
+
547
+ ## License
548
+
549
+ MIT+Apache
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import { ImgGenClasses } from '../utils/style-utils.js';
3
+ interface ControlsBarProps {
4
+ readonly handleDeleteConfirm: () => void;
5
+ readonly handlePrevVersion: () => void;
6
+ readonly handleNextVersion: () => void;
7
+ readonly handleRegen: () => void;
8
+ readonly versionIndex: number;
9
+ readonly totalVersions: number;
10
+ readonly classes?: Partial<ImgGenClasses>;
11
+ readonly showControls?: boolean;
12
+ readonly editedPrompt: string | null;
13
+ readonly promptText: string;
14
+ readonly progress?: number;
15
+ readonly showDelete?: boolean;
16
+ readonly versionFlash?: boolean;
17
+ readonly isRegenerating?: boolean;
18
+ }
19
+ export declare function ControlsBar({ handleDeleteConfirm, handlePrevVersion, handleNextVersion, handleRegen, versionIndex, totalVersions, classes, showControls, editedPrompt, promptText, progress, showDelete, versionFlash, isRegenerating }: ControlsBarProps): React.JSX.Element;
20
+ export {};
@@ -0,0 +1,84 @@
1
+ import * as React from 'react';
2
+ import { combineClasses, defaultClasses } from '../utils/style-utils.js';
3
+ import { imgGenStyles, imgGenTheme } from '../utils/styles.js';
4
+ import { logDebug } from '../utils/debug.js';
5
+ export function ControlsBar({ handleDeleteConfirm, handlePrevVersion, handleNextVersion, handleRegen, versionIndex, totalVersions, classes = defaultClasses, showControls = true, editedPrompt, promptText, progress = 100, showDelete = true, versionFlash = false, isRegenerating = false, }) {
6
+ const [showConfirmation, setShowConfirmation] = React.useState(false);
7
+ const cancelTimerRef = React.useRef(null);
8
+ const isConfirming = showConfirmation;
9
+ const onDeleteClick = () => {
10
+ if (isConfirming) {
11
+ logDebug('ControlsBar: Delete confirmed, calling handleDeleteConfirm');
12
+ handleDeleteConfirm();
13
+ setShowConfirmation(false);
14
+ if (cancelTimerRef.current) {
15
+ window.clearTimeout(cancelTimerRef.current);
16
+ cancelTimerRef.current = null;
17
+ }
18
+ }
19
+ else {
20
+ logDebug('ControlsBar: Showing delete confirmation');
21
+ setShowConfirmation(true);
22
+ cancelTimerRef.current = window.setTimeout(() => {
23
+ setShowConfirmation(false);
24
+ }, 6500);
25
+ }
26
+ };
27
+ React.useEffect(() => {
28
+ return () => {
29
+ if (cancelTimerRef.current) {
30
+ window.clearTimeout(cancelTimerRef.current);
31
+ }
32
+ };
33
+ }, []);
34
+ return (React.createElement(React.Fragment, null, progress < 100 && (React.createElement("div", { className: "imggen-progress", style: {
35
+ ...imgGenStyles.progress,
36
+ width: `${progress}%`,
37
+ } })), React.createElement("div", { className: combineClasses(classes.controls), style: imgGenStyles.controls }, showControls ? (React.createElement(React.Fragment, null, React.createElement("div", { style: { display: 'flex', gap: '6px', alignItems: 'center', flex: 1 } }, showDelete && (React.createElement("div", { style: { display: 'flex', alignItems: 'center', gap: '8px' } }, React.createElement("button", { "aria-label": "Delete image", onClick: onDeleteClick, className: combineClasses('imggen-button imggen-delete-button', classes.button), style: {
38
+ ...imgGenStyles.button,
39
+ backgroundColor: isConfirming
40
+ ? imgGenTheme.colors.errorBorder
41
+ : imgGenStyles.button.background,
42
+ color: isConfirming ? 'white' : imgGenStyles.button.color,
43
+ opacity: isConfirming ? 1 : imgGenStyles.button.opacity,
44
+ } }), isConfirming && (React.createElement("div", { className: "fade-transition", style: { animationDelay: '6s' } }, React.createElement("button", { onClick: () => {
45
+ handleDeleteConfirm();
46
+ setShowConfirmation(false);
47
+ }, "aria-label": "Confirm delete", style: {
48
+ fontSize: imgGenTheme.typography.fontSize,
49
+ fontWeight: 'bold',
50
+ whiteSpace: 'nowrap',
51
+ border: `1px solid ${imgGenTheme.colors.errorBorder}`,
52
+ background: imgGenTheme.colors.errorBorder,
53
+ color: 'white',
54
+ borderRadius: imgGenTheme.dimensions.borderRadius,
55
+ cursor: 'pointer',
56
+ padding: '2px 8px',
57
+ } }, "Delete image"), React.createElement("button", { onClick: () => {
58
+ logDebug('ControlsBar: Delete canceled');
59
+ setShowConfirmation(false);
60
+ if (cancelTimerRef.current) {
61
+ window.clearTimeout(cancelTimerRef.current);
62
+ }
63
+ }, "aria-label": "Cancel delete", style: {
64
+ fontSize: imgGenTheme.typography.fontSize,
65
+ whiteSpace: 'nowrap',
66
+ border: 'none',
67
+ background: 'none',
68
+ color: imgGenTheme.colors.text,
69
+ cursor: 'pointer',
70
+ padding: '0 4px',
71
+ } }, "Cance")))))), React.createElement("div", { className: "imggen-control-group", style: imgGenStyles.controlGroup }, totalVersions > 1 && (React.createElement("button", { "aria-label": "Previous version", disabled: versionIndex === 0, onClick: handlePrevVersion, className: combineClasses('imggen-button', classes.button), style: imgGenStyles.button }, "\u25C0")), totalVersions > 1 && (React.createElement("span", { className: `imggen-version-indicator version-indicator ${versionFlash ? 'imggen-version-flash' : ''}`, "aria-live": "polite" }, versionIndex + 1, " / ", totalVersions)), totalVersions > 1 && (React.createElement("button", { "aria-label": "Next version", disabled: versionIndex >= totalVersions - 1, onClick: handleNextVersion, className: combineClasses('imggen-button', classes.button), style: imgGenStyles.button }, "\u25B6")), React.createElement("button", { "aria-label": "Regenerate image", onClick: () => {
72
+ handleRegen();
73
+ }, disabled: isRegenerating, className: combineClasses('imggen-button', classes.button, editedPrompt !== null && editedPrompt.trim() !== promptText
74
+ ? 'imggen-button-highlight'
75
+ : '', isRegenerating ? 'imggen-button-disabled' : ''), style: {
76
+ ...imgGenStyles.button,
77
+ backgroundColor: editedPrompt !== null && editedPrompt.trim() !== promptText
78
+ ? imgGenTheme.colors.accent
79
+ : imgGenStyles.button.background,
80
+ opacity: isRegenerating ? 0.3 : imgGenStyles.button.opacity,
81
+ cursor: isRegenerating ? 'not-allowed' : imgGenStyles.button.cursor,
82
+ } }, React.createElement("span", { className: isRegenerating ? 'imggen-regen-spinning' : '' }, "\u27F3"))))) : progress < 100 ? (React.createElement("div", { className: "imggen-status-text", style: imgGenStyles.statusText }, "Generating..")) : null)));
83
+ }
84
+ //# sourceMappingURL=ControlsBar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ControlsBar.js","sourceRoot":"","sources":["../../jsr/components/ControlsBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAiB,MAAM,yBAAyB,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAgC7C,MAAM,UAAU,WAAW,CAAC,EAC1B,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,OAAO,GAAG,cAAc,EACxB,YAAY,GAAG,IAAI,EACnB,YAAY,EACZ,UAAU,EACV,QAAQ,GAAG,GAAG,EACd,UAAU,GAAG,IAAI,EACjB,YAAY,GAAG,KAAK,EACpB,cAAc,GAAG,KAAK,GACL,EAAE;IAEnB,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAGtE,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAgB,IAAI,CAAC,CAAC;IAGzD,MAAM,YAAY,GAAG,gBAAgB,CAAC;IAGtC,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC;QAC1B,IAAI,YAAY,EAAE,CAAC;YAEjB,QAAQ,CAAC,4DAA4D,CAAC,CAAC;YAEvE,mBAAmB,EAAE,CAAC;YAGtB,mBAAmB,CAAC,KAAK,CAAC,CAAC;YAC3B,IAAI,cAAc,CAAC,OAAO,EAAE,CAAC;gBAC3B,MAAM,CAAC,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;gBAC5C,cAAc,CAAC,OAAO,GAAG,IAAI,CAAC;YAChC,CAAC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