use-vibes 0.4.15 → 0.5.0

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 (39) hide show
  1. package/README.md +480 -82
  2. package/dist/components/ImgGen.css +131 -0
  3. package/dist/components/ImgGen.d.ts +6 -0
  4. package/dist/components/ImgGen.js +238 -130
  5. package/dist/components/ImgGen.js.map +1 -1
  6. package/dist/components/ImgGenUtils/ImgGenDisplay.d.ts +1 -1
  7. package/dist/components/ImgGenUtils/ImgGenDisplay.js +23 -54
  8. package/dist/components/ImgGenUtils/ImgGenDisplay.js.map +1 -1
  9. package/dist/components/ImgGenUtils/ImgGenDisplayPlaceholder.js +13 -3
  10. package/dist/components/ImgGenUtils/ImgGenDisplayPlaceholder.js.map +1 -1
  11. package/dist/components/ImgGenUtils/ImgGenFileDrop.d.ts +21 -0
  12. package/dist/components/ImgGenUtils/ImgGenFileDrop.js +57 -0
  13. package/dist/components/ImgGenUtils/ImgGenFileDrop.js.map +1 -0
  14. package/dist/components/ImgGenUtils/ImgGenModeUtils.d.ts +16 -0
  15. package/dist/components/ImgGenUtils/ImgGenModeUtils.js +63 -0
  16. package/dist/components/ImgGenUtils/ImgGenModeUtils.js.map +1 -0
  17. package/dist/components/ImgGenUtils/ImgGenPromptWaiting.d.ts +12 -2
  18. package/dist/components/ImgGenUtils/ImgGenPromptWaiting.js +43 -2
  19. package/dist/components/ImgGenUtils/ImgGenPromptWaiting.js.map +1 -1
  20. package/dist/components/ImgGenUtils/ImgGenUploadWaiting.d.ts +30 -0
  21. package/dist/components/ImgGenUtils/ImgGenUploadWaiting.js +181 -0
  22. package/dist/components/ImgGenUtils/ImgGenUploadWaiting.js.map +1 -0
  23. package/dist/components/ImgGenUtils/index.d.ts +1 -0
  24. package/dist/components/ImgGenUtils/index.js +1 -0
  25. package/dist/components/ImgGenUtils/index.js.map +1 -1
  26. package/dist/components/ImgGenUtils/types.d.ts +5 -1
  27. package/dist/hooks/image-gen/image-generator.d.ts +4 -0
  28. package/dist/hooks/image-gen/image-generator.js +103 -5
  29. package/dist/hooks/image-gen/image-generator.js.map +1 -1
  30. package/dist/hooks/image-gen/use-image-gen.js +1 -1
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.js +2 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/utils/base64.d.ts +1 -0
  35. package/dist/utils/base64.js +17 -0
  36. package/dist/utils/base64.js.map +1 -0
  37. package/dist/utils/style-utils.d.ts +4 -0
  38. package/dist/utils/style-utils.js.map +1 -1
  39. package/package.json +1 -1
package/README.md CHANGED
@@ -8,11 +8,276 @@ A lightweight library that transforms any DOM element into an AI-powered micro-a
8
8
  pnpm add use-vibes
9
9
  ```
10
10
 
11
- ### CSS Loading
11
+ ## Basic Usage
12
12
 
13
- The ImgGen component requires CSS styles. You can include them in two ways:
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
+ {/* Includes a built-in form UI for prompt entry and image upload */}
43
+ <ImgGen />
44
+ ```
45
+
46
+ - **One-line Implementation**: Directly specify a prompt for immediate generation (bypasses the form UI)
47
+
48
+ ```jsx
49
+ {/* Starts generating immediately, no form shown to the user */}
50
+ <ImgGen prompt="A sunset over mountains" />
51
+ ```
52
+
53
+ - **Automatic Database Integration**: All images are automatically stored in Fireproof database with version history
54
+
55
+ ```jsx
56
+ // Custom database name
57
+ <ImgGen prompt="Forest landscape" database="MyCustomDB" />
58
+
59
+ // Or pass a database instance
60
+ <ImgGen prompt="Forest landscape" database={myDbInstance} />
61
+ ```
62
+
63
+ ### Prompt Management
64
+
65
+ - **Prompt Versioning**: Tracks the history of different prompts used to generate an image
66
+
67
+ - Uses a structured `prompts` object with timestamp-based keys
68
+ - Maintains `currentPromptKey` to reference the active prompt
69
+
70
+ - **Prompt Editing**: Users can edit prompts directly in the overlay UI
71
+ - Double-click the prompt text to edit
72
+ - Press Enter to submit and regenerate with new prompt
73
+ - App receives updates via `onPromptEdit` callback
74
+ ```jsx
75
+ <ImgGen
76
+ prompt="Initial prompt"
77
+ onPromptEdit={(id, newPrompt) => {
78
+ console.log(`Document ${id} updated with new prompt: ${newPrompt}`);
79
+ }}
80
+ />
81
+ ```
82
+
83
+ ### Image Control & Manipulation
84
+
85
+ - **Image Regeneration**: One-click regeneration with the same or edited prompt
86
+
87
+ - Preserves document history and adds new versions
88
+ - Uses a unique `generationId` to trigger regeneration while maintaining context
89
+
90
+ - **Image Quality Control**: Set quality levels for output images
91
+
92
+ ```jsx
93
+ <ImgGen prompt="Detailed artwork" options={{ quality: 'high' }} />
94
+ ```
95
+
96
+ - **Image Editing with Uploads**: Process existing images with AI
97
+
98
+ ```jsx
99
+ <ImgGen prompt="Turn this photo into a watercolor painting" images={[myImageFile]} />
100
+ ```
101
+
102
+ - **Multiple Image Inputs**: Combine multiple images in one generation
103
+ ```jsx
104
+ <ImgGen prompt="Create a collage of these photos" images={[photo1, photo2, photo3]} />
105
+ ```
106
+
107
+ ### User Interface Components
108
+
109
+ - **Interactive Overlay**: Toggle-able information and controls overlay
110
+
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
+
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
+
140
+ - Drag-and-drop capabilities
141
+ - File selection dialog
142
+ - Preview of uploaded content
143
+
144
+ - **Base64 Conversion**: Convert between base64 and File objects
145
+
146
+ ```jsx
147
+ import { base64ToFile } from 'use-vibes';
148
+
149
+ // Convert API response to a File object
150
+ const imageFile = base64ToFile(imageResponse.data[0].b64_json, 'my-image.png');
151
+ ```
152
+
153
+ ## Integration Features
154
+
155
+ ### Event Callbacks
156
+
157
+ - **Generation Lifecycle Events**: Track the complete generation process
158
+ ```jsx
159
+ <ImgGen
160
+ prompt="Track this generation"
161
+ onComplete={() => console.log('Generation complete!')}
162
+ onError={(error) => console.error('Generation failed:', error)}
163
+ onDelete={(id) => console.log(`Document ${id} deleted`)}
164
+ onDocumentCreated={(id) => console.log(`New document created: ${id}`)}
165
+ />
166
+ ```
14
167
 
15
- #### Option A: Explicit CSS link (recommended for production)
168
+ ### State Management
169
+
170
+ - **Loading States**: Component handles all loading states internally
171
+
172
+ - Initial waiting state
173
+ - Generation in progress state
174
+ - Upload waiting state
175
+ - Display state for completed images
176
+ - Error state
177
+
178
+ - **Document Identity Tracking**: Smart re-mounting based on document changes
179
+ - Uses internal `mountKey` system to ensure clean state transitions
180
+ - Detects identity changes through document ID, prompt, or uploaded file documents
181
+
182
+ ### UI Customization
183
+
184
+ - **Extensive Styling Options**: Multiple ways to customize appearance
185
+
186
+ - CSS Variables for global styling
187
+
188
+ ```css
189
+ :root {
190
+ --imggen-text-color: #222;
191
+ --imggen-overlay-bg: rgba(245, 245, 245, 0.85);
192
+ --imggen-accent: #0088ff;
193
+ --imggen-border-radius: 4px;
194
+ }
195
+ ```
196
+
197
+ - Custom classes for component-level styling
198
+
199
+ ```jsx
200
+ <ImgGen
201
+ prompt="Styled component"
202
+ classes={{
203
+ root: 'my-custom-container',
204
+ image: 'rounded-xl shadow-lg',
205
+ overlay: 'bg-slate-800/70 text-white',
206
+ progress: 'h-2 bg-green-500',
207
+ }}
208
+ />
209
+ ```
210
+
211
+ ### Gallery Integration
212
+
213
+ - **Thumbnail Support**: Easily create image galleries
214
+
215
+ ```jsx
216
+ <div className="image-grid">
217
+ {imageDocuments.map((doc) => (
218
+ <ImgGen key={doc._id} _id={doc._id} className="thumbnail" />
219
+ ))}
220
+ </div>
221
+ ```
222
+
223
+ - **Document Reuse**: Load existing documents by ID
224
+ ```jsx
225
+ <ImgGen _id="existing-document-id" />
226
+ ```
227
+
228
+ ## Implementation Modes
229
+
230
+ The ImgGen component has several operational modes that it switches between automatically:
231
+
232
+ 1. **Placeholder Mode**: Initial state when no prompt or document ID is provided
233
+ 2. **Upload Waiting Mode**: When files are uploaded but waiting for a prompt
234
+ 3. **Generating Mode**: During the image generation process
235
+ 4. **Display Mode**: When showing a generated image with controls
236
+ 5. **Error Mode**: When an error occurs during generation
237
+
238
+ The component automatically determines which mode to use based on the current state, providing a seamless experience for both developers and end-users.
239
+
240
+ ## Advanced Usage
241
+
242
+ ### Debug Mode
243
+
244
+ Enable debug mode to see detailed console logs about component state:
245
+
246
+ ```jsx
247
+ <ImgGen prompt="Debug this" options={{ debug: true }} />
248
+ ```
249
+
250
+ ### Custom Image Sizing
251
+
252
+ Control output image dimensions with the size option:
253
+
254
+ ```jsx
255
+ <ImgGen
256
+ prompt="Landscape format"
257
+ options={{ size: '1536x1024' }} // Landscape
258
+ />
259
+
260
+ <ImgGen
261
+ prompt="Portrait format"
262
+ options={{ size: '1024x1536' }} // Portrait
263
+ />
264
+ ```
265
+
266
+ # Advanced Usage
267
+
268
+ This guide covers the implementation, configuration, and best practices for using the ImgGen component from the use-vibes library.
269
+
270
+ ## Installation
271
+
272
+ ```bash
273
+ pnpm add use-vibes
274
+ ```
275
+
276
+ ### CSS Setup
277
+
278
+ The ImgGen component requires CSS styles. You have two options:
279
+
280
+ #### Option A: Explicit CSS Link (Recommended for Production)
16
281
 
17
282
  Add a CSS link tag to your HTML:
18
283
 
@@ -20,13 +285,13 @@ Add a CSS link tag to your HTML:
20
285
  <link rel="stylesheet" href="/node_modules/use-vibes/dist/components/ImgGen.css" />
21
286
  ```
22
287
 
23
- Or for ESM/CDN environments like importmap scenarios:
288
+ Or for ESM/CDN environments:
24
289
 
25
290
  ```html
26
- <link rel="stylesheet" href="https://esm.sh/use-vibes@0.4.11/dist/components/ImgGen.css" />
291
+ <link rel="stylesheet" href="https://esm.sh/use-vibes@latest/dist/components/ImgGen.css" />
27
292
  ```
28
293
 
29
- #### Option B: Automatic CSS loading (convenient for prototyping)
294
+ #### Option B: Automatic CSS Loading (Convenient for Prototyping)
30
295
 
31
296
  Import the style-loader early in your application:
32
297
 
@@ -34,13 +299,13 @@ Import the style-loader early in your application:
34
299
  import 'use-vibes/style-loader'; // Auto-loads CSS when imported
35
300
  ```
36
301
 
37
- This approach is perfect for quick prototypes but for production sites, Option A gives you better control over CSS loading order and timing.
302
+ This approach is perfect for quick prototypes, but for production sites, Option A gives you better control over CSS loading order and timing.
38
303
 
39
- ## Components
304
+ ## Basic Usage
40
305
 
41
- ### ImgGen
306
+ ### Simple Image Generation
42
307
 
43
- A React component for generating images with AI:
308
+ Add AI image generation to any React app with minimal code:
44
309
 
45
310
  ```jsx
46
311
  import { ImgGen } from 'use-vibes';
@@ -54,62 +319,161 @@ function MyComponent() {
54
319
  }
55
320
  ```
56
321
 
57
- #### Props
322
+ ### Configuration Options
323
+
324
+ Configure image generation with the `options` prop:
325
+
326
+ ```jsx
327
+ <ImgGen
328
+ prompt="A detailed cityscape"
329
+ options={{
330
+ model: 'gpt-image-1',
331
+ quality: 'high',
332
+ size: '1024x1024',
333
+ debug: false,
334
+ }}
335
+ />
336
+ ```
337
+
338
+ ### Available Props
339
+
340
+ | Prop | Type | Description |
341
+ | ------------------- | ------------------ | ----------------------------------------------------------------------- |
342
+ | `prompt` | string | Text prompt for image generation (required unless `_id` is provided) |
343
+ | `_id` | string | Document ID to load a specific image instead of generating a new one |
344
+ | `className` | string | CSS class name for the image element |
345
+ | `alt` | string | Alt text for the image (defaults to prompt) |
346
+ | `images` | File[] | Array of images to edit or combine with AI |
347
+ | `options` | object | Configuration options (see table below) |
348
+ | `database` | string \| Database | Database name or instance to use for storing images |
349
+ | `onComplete` | function | Callback when image load completes successfully |
350
+ | `onError` | function | Callback when image load fails, receives the error as parameter |
351
+ | `onDelete` | function | Callback when an image is deleted, receives the document ID |
352
+ | `onPromptEdit` | function | Callback when the prompt is edited, receives document ID and new prompt |
353
+ | `onDocumentCreated` | function | Callback when a new document is created via drop or file picker |
354
+ | `overlay` | boolean | Whether to show overlay controls and info button (default: `true`) |
355
+ | `classes` | object | Custom CSS classes for styling component parts |
356
+ | `debug` | boolean | Enable debug logging |
357
+
358
+ ### Options Object Properties
359
+
360
+ | Property | Type | Description |
361
+ | --------- | ------- | ------------------------------------------------------------------------ |
362
+ | `model` | string | Model to use for image generation, defaults to 'gpt-image-1' |
363
+ | `size` | string | Size of the generated image (1024x1024, 1536x1024, 1024x1536, or 'auto') |
364
+ | `quality` | string | Quality of the generated image (high, medium, low, or auto) |
365
+ | `debug` | boolean | Enable debug logging, defaults to false |
366
+
367
+ ## Advanced Features
368
+
369
+ ### Prompt Management
370
+
371
+ The ImgGen component tracks the history of different prompts used to generate an image:
372
+
373
+ ```jsx
374
+ <ImgGen
375
+ prompt="Initial prompt"
376
+ onPromptEdit={(id, newPrompt) => {
377
+ console.log(`Document ${id} updated with new prompt: ${newPrompt}`);
378
+ }}
379
+ />
380
+ ```
381
+
382
+ 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.
58
383
 
59
- - `prompt`: Text prompt for image generation (required unless `_id` is provided)
60
- - `_id`: Document ID to load a specific image instead of generating a new one
61
- - `options` (object, optional): Configuration options for image generation
384
+ ### Image Control & Manipulation
62
385
 
63
- - `model` (string, optional): Model to use for image generation, defaults to 'gpt-image-1'
64
- - `size` (string, optional): Size of the generated image (Must be one of 1024x1024, 1536x1024 (landscape), 1024x1536 (portrait), or 'auto' (default value) for gpt-image-1, and one of 256x256, 512x512, or 1024x1024 for dall-e-2.)
65
- - `quality` (string, optional): Quality of the generated image (high, medium and low are only supported for gpt-image-1. dall-e-2 only supports standard quality. Defaults to auto.)
66
- - `debug` (boolean, optional): Enable debug logging, defaults to false
386
+ #### Image Regeneration
67
387
 
68
- - `className`: CSS class name for the image element (optional)
69
- - `alt`: Alt text for the image (defaults to prompt)
70
- - `overlay`: Whether to show overlay controls and info button (default: `true`)
71
- - `database`: Database name or instance to use for storing images (default: `'ImgGen'`)
72
- - `onComplete`: Callback when image load completes successfully
73
- - `onError`: Callback when image load fails, receives the error as parameter
74
- - `onDelete`: Callback when an image is deleted, receives the document ID
75
- - `onPromptEdit`: Callback when the prompt is edited, receives document ID and new prompt
76
- - `editedPrompt`: Custom prompt text to use for regeneration (overrides document prompt)
77
- - `generationId`: Optional ID to trigger regeneration of existing images
78
- - `classes`: Object containing custom CSS classes for styling component parts (see Styling section)
388
+ The component supports one-click regeneration, preserving document history while adding new versions:
79
389
 
80
- #### Features
390
+ ```jsx
391
+ // The regeneration happens internally when the user clicks the refresh button
392
+ // or when a new prompt is submitted
393
+ ```
81
394
 
82
- ##### Overlay Controls
395
+ #### Image Quality Control
83
396
 
84
- By default, the ImgGen component shows an info button in the bottom-left corner. Clicking it reveals an overlay with:
397
+ Set quality levels for output images:
85
398
 
86
- - The prompt text (double-clickable to edit)
87
- - Version navigation buttons (if multiple versions exist)
88
- - Refresh button to generate a new version
89
- - Delete button
399
+ ```jsx
400
+ <ImgGen prompt="Detailed artwork" options={{ quality: 'high' }} />
401
+ ```
402
+
403
+ #### Image Editing with Uploads
404
+
405
+ Process existing images with AI:
406
+
407
+ ```jsx
408
+ <ImgGen prompt="Turn this photo into a watercolor painting" images={[myImageFile]} />
409
+ ```
410
+
411
+ #### Multiple Image Inputs
412
+
413
+ Combine multiple images in one generation:
90
414
 
91
- Setting `overlay={false}` will hide all these controls, showing only the image.
415
+ ```jsx
416
+ <ImgGen prompt="Create a collage of these photos" images={[photo1, photo2, photo3]} />
417
+ ```
418
+
419
+ ### Database Integration
420
+
421
+ All images are automatically stored in a Fireproof database with version history:
422
+
423
+ ```jsx
424
+ // Custom database name
425
+ <ImgGen prompt="Forest landscape" database="MyCustomDB" />
426
+
427
+ // Or pass a database instance
428
+ <ImgGen prompt="Forest landscape" database={myDbInstance} />
429
+ ```
430
+
431
+ ### Event Callbacks
432
+
433
+ Track the complete generation process with lifecycle events:
434
+
435
+ ```jsx
436
+ <ImgGen
437
+ prompt="Track this generation"
438
+ onComplete={() => console.log('Generation complete!')}
439
+ onError={(error) => console.error('Generation failed:', error)}
440
+ onDelete={(id) => console.log(`Document ${id} deleted`)}
441
+ onDocumentCreated={(id) => console.log(`New document created: ${id}`)}
442
+ />
443
+ ```
444
+
445
+ ### UI Controls
446
+
447
+ Toggle the information overlay and controls:
448
+
449
+ ```jsx
450
+ // Disable overlay for a minimal UI
451
+ <ImgGen prompt="Clean interface" overlay={false} />
452
+ ```
92
453
 
93
- ##### Prompt Editing
454
+ The overlay includes:
94
455
 
95
- Double-click the prompt text in the overlay to edit it. Press Enter to submit changes and regenerate the image with the new prompt.
456
+ - Prompt text (editable)
457
+ - Version navigation controls
458
+ - Regenerate/refresh button
459
+ - Delete button
96
460
 
97
- ##### Image Regeneration
461
+ ### File Management
98
462
 
99
- When regenerating images, the component will:
463
+ #### Base64 Conversion
100
464
 
101
- - Use the edited prompt if one has been provided (via `editedPrompt` prop, `onPromptEdit` callback, or direct editing in the UI)
102
- - Fall back to the original prompt from the document if no edits were made
103
- - Preserve versions under the same document ID to maintain history
104
- - Add the new image as a version to the existing document instead of creating a new one
465
+ Convert between base64 and File objects:
105
466
 
106
- This allows for iterative refinement of images while maintaining version history.
467
+ ```jsx
468
+ import { base64ToFile } from 'use-vibes';
107
469
 
108
- #### Styling
470
+ // Convert API response to a File object
471
+ const imageFile = base64ToFile(imageResponse.data[0].b64_json, 'my-image.png');
472
+ ```
109
473
 
110
- The ImgGen component uses CSS custom properties (variables) for styling, making it easy to customize the appearance while maintaining consistency. There are two primary ways to customize styling:
474
+ ## Styling and Customization
111
475
 
112
- ##### 1. CSS Variables
476
+ ### CSS Variables
113
477
 
114
478
  Override the default styles by setting CSS custom properties in your CSS:
115
479
 
@@ -130,13 +494,26 @@ Override the default styles by setting CSS custom properties in your CSS:
130
494
  }
131
495
  ```
132
496
 
133
- ##### 2. Custom Classes
497
+ ### Available CSS Variables
498
+
499
+ | Variable | Default | Description |
500
+ | ------------------------ | -------------------------- | --------------------------------- |
501
+ | `--imggen-text-color` | `#333` | Main text color |
502
+ | `--imggen-background` | `#333333` | Background color for placeholder |
503
+ | `--imggen-overlay-bg` | `rgba(255, 255, 255, 0.5)` | Overlay panel background |
504
+ | `--imggen-accent` | `#0066cc` | Accent color (progress bar, etc.) |
505
+ | `--imggen-error-text` | `#ff6666` | Error message text color |
506
+ | `--imggen-border-radius` | `8px` | Border radius for containers |
507
+ | `--imggen-button-bg` | `rgba(255, 255, 255, 0.7)` | Button background color |
508
+ | `--imggen-font-size` | `14px` | Default font size |
509
+
510
+ ### Custom Classes
134
511
 
135
512
  For more granular control, provide a `classes` object with custom CSS classes for specific component parts:
136
513
 
137
514
  ```jsx
138
515
  <ImgGen
139
- prompt="A futuristic cityscape"
516
+ prompt="Styled component"
140
517
  classes={{
141
518
  root: 'my-custom-container',
142
519
  image: 'rounded-xl shadow-lg',
@@ -147,22 +524,7 @@ For more granular control, provide a `classes` object with custom CSS classes fo
147
524
  />
148
525
  ```
149
526
 
150
- The component uses these classes in addition to the default ones, allowing you to extend or override styles as needed.
151
-
152
- ##### Available CSS Variables
153
-
154
- | Variable | Default | Description |
155
- | ------------------------ | -------------------------- | --------------------------------- |
156
- | `--imggen-text-color` | `#333` | Main text color |
157
- | `--imggen-background` | `#333333` | Background color for placeholder |
158
- | `--imggen-overlay-bg` | `rgba(255, 255, 255, 0.5)` | Overlay panel background |
159
- | `--imggen-accent` | `#0066cc` | Accent color (progress bar, etc.) |
160
- | `--imggen-error-text` | `#ff6666` | Error message text color |
161
- | `--imggen-border-radius` | `8px` | Border radius for containers |
162
- | `--imggen-button-bg` | `rgba(255, 255, 255, 0.7)` | Button background color |
163
- | `--imggen-font-size` | `14px` | Default font size |
164
-
165
- ##### Available Class Slots
527
+ ### Available Class Slots
166
528
 
167
529
  | Class Property | Description |
168
530
  | --------------- | -------------------------------- |
@@ -178,27 +540,63 @@ The component uses these classes in addition to the default ones, allowing you t
178
540
  | `prompt` | Prompt text/input container |
179
541
  | `deleteOverlay` | Delete confirmation dialog |
180
542
 
181
- ## Development
543
+ ## Gallery Implementation
182
544
 
183
- ```bash
184
- # Install dependencies
185
- pnpm install
545
+ ### Creating an Image Gallery
546
+
547
+ Easily create image galleries using document IDs:
548
+
549
+ ```jsx
550
+ <div className="image-grid">
551
+ {imageDocuments.map((doc) => (
552
+ <ImgGen key={doc._id} _id={doc._id} className="thumbnail" />
553
+ ))}
554
+ </div>
555
+ ```
556
+
557
+ ### Loading Existing Documents
186
558
 
187
- # Build the library
188
- pnpm build
559
+ Load existing documents by ID:
189
560
 
190
- # Run tests
191
- pnpm test
561
+ ```jsx
562
+ <ImgGen _id="existing-document-id" />
192
563
  ```
193
564
 
194
- ### Testing Notes
565
+ ## Operation Modes
566
+
567
+ The ImgGen component has several operational modes that it switches between automatically:
568
+
569
+ 1. **Placeholder Mode**: Initial state when no prompt or document ID is provided
570
+ 2. **Upload Waiting Mode**: When files are uploaded but waiting for a prompt
571
+ 3. **Generating Mode**: During the image generation process
572
+ 4. **Display Mode**: When showing a generated image with controls
573
+ 5. **Error Mode**: When an error occurs during generation
195
574
 
196
- When writing tests for components that use the image generation functionality:
575
+ ## Advanced Usage Examples
197
576
 
198
- - Use the provided mock implementations for `call-ai` and `use-fireproof`
199
- - Wrap React state updates in `act()` to prevent test warnings
200
- - Use `vi.useFakeTimers()` and `vi.advanceTimersByTime()` to control async behavior
201
- - Be aware that `imageGen` API calls need to be properly mocked
577
+ ### Debug Mode
578
+
579
+ Enable debug mode to see detailed console logs about component state:
580
+
581
+ ```jsx
582
+ <ImgGen prompt="Debug this" options={{ debug: true }} />
583
+ ```
584
+
585
+ ### Custom Image Sizing
586
+
587
+ Control output image dimensions with the size option:
588
+
589
+ ```jsx
590
+ <ImgGen
591
+ prompt="Landscape format"
592
+ options={{ size: '1536x1024' }} // Landscape
593
+ />
594
+
595
+ <ImgGen
596
+ prompt="Portrait format"
597
+ options={{ size: '1024x1536' }} // Portrait
598
+ />
599
+ ```
202
600
 
203
601
  ### Browser Compatibility
204
602
 
@@ -206,4 +604,4 @@ This library is compatible with all modern browsers that support React 18+ and E
206
604
 
207
605
  ## License
208
606
 
209
- MIT
607
+ MIT+Apache