use-vibes 0.0.6-dev-ci-test

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