@vibes.diy/use-vibes-base 0.0.0-dev-fresh-data
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +232 -0
- package/ManualRedirectStrategy.d.ts +24 -0
- package/ManualRedirectStrategy.js +289 -0
- package/ManualRedirectStrategy.js.map +1 -0
- package/README.md +549 -0
- package/components/AuthWall/AuthWall.d.ts +8 -0
- package/components/AuthWall/AuthWall.js +161 -0
- package/components/AuthWall/AuthWall.js.map +1 -0
- package/components/AuthWall/AuthWall.styles.d.ts +24 -0
- package/components/AuthWall/AuthWall.styles.js +82 -0
- package/components/AuthWall/AuthWall.styles.js.map +1 -0
- package/components/BrutalistCard/BrutalistCard.d.ts +8 -0
- package/components/BrutalistCard/BrutalistCard.js +11 -0
- package/components/BrutalistCard/BrutalistCard.js.map +1 -0
- package/components/BrutalistCard/BrutalistCard.styles.d.ts +4 -0
- package/components/BrutalistCard/BrutalistCard.styles.js +66 -0
- package/components/BrutalistCard/BrutalistCard.styles.js.map +1 -0
- package/components/BrutalistCard/index.d.ts +3 -0
- package/components/BrutalistCard/index.js +2 -0
- package/components/BrutalistCard/index.js.map +1 -0
- package/components/ControlsBar.d.ts +20 -0
- package/components/ControlsBar.js +108 -0
- package/components/ControlsBar.js.map +1 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.d.ts +7 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.js +103 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.js.map +1 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.styles.d.ts +31 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.styles.js +86 -0
- package/components/HiddenMenuWrapper/HiddenMenuWrapper.styles.js.map +1 -0
- package/components/ImgGen.css +675 -0
- package/components/ImgGen.d.ts +23 -0
- package/components/ImgGen.js +260 -0
- package/components/ImgGen.js.map +1 -0
- package/components/ImgGenUtils/AsyncImg.d.ts +7 -0
- package/components/ImgGenUtils/AsyncImg.js +41 -0
- package/components/ImgGenUtils/AsyncImg.js.map +1 -0
- package/components/ImgGenUtils/ImgGenDisplay.d.ts +3 -0
- package/components/ImgGenUtils/ImgGenDisplay.js +240 -0
- package/components/ImgGenUtils/ImgGenDisplay.js.map +1 -0
- package/components/ImgGenUtils/ImgGenDisplayPlaceholder.d.ts +3 -0
- package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js +99 -0
- package/components/ImgGenUtils/ImgGenDisplayPlaceholder.js.map +1 -0
- package/components/ImgGenUtils/ImgGenDisplayUtils.d.ts +27 -0
- package/components/ImgGenUtils/ImgGenDisplayUtils.js +95 -0
- package/components/ImgGenUtils/ImgGenDisplayUtils.js.map +1 -0
- package/components/ImgGenUtils/ImgGenError.d.ts +3 -0
- package/components/ImgGenUtils/ImgGenError.js +9 -0
- package/components/ImgGenUtils/ImgGenError.js.map +1 -0
- package/components/ImgGenUtils/ImgGenFileDrop.d.ts +11 -0
- package/components/ImgGenUtils/ImgGenFileDrop.js +56 -0
- package/components/ImgGenUtils/ImgGenFileDrop.js.map +1 -0
- package/components/ImgGenUtils/ImgGenModal.d.ts +25 -0
- package/components/ImgGenUtils/ImgGenModal.js +67 -0
- package/components/ImgGenUtils/ImgGenModal.js.map +1 -0
- package/components/ImgGenUtils/ImgGenModeUtils.d.ts +9 -0
- package/components/ImgGenUtils/ImgGenModeUtils.js +59 -0
- package/components/ImgGenUtils/ImgGenModeUtils.js.map +1 -0
- package/components/ImgGenUtils/ImgGenPromptWaiting.d.ts +11 -0
- package/components/ImgGenUtils/ImgGenPromptWaiting.js +40 -0
- package/components/ImgGenUtils/ImgGenPromptWaiting.js.map +1 -0
- package/components/ImgGenUtils/ImgGenUploadWaiting.d.ts +16 -0
- package/components/ImgGenUtils/ImgGenUploadWaiting.js +155 -0
- package/components/ImgGenUtils/ImgGenUploadWaiting.js.map +1 -0
- package/components/ImgGenUtils/index.d.ts +6 -0
- package/components/ImgGenUtils/index.js +7 -0
- package/components/ImgGenUtils/index.js.map +1 -0
- package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.d.ts +9 -0
- package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.js +31 -0
- package/components/ImgGenUtils/overlays/DeleteConfirmationOverlay.js.map +1 -0
- package/components/ImgGenUtils/overlays/ImageOverlay.d.ts +22 -0
- package/components/ImgGenUtils/overlays/ImageOverlay.js +11 -0
- package/components/ImgGenUtils/overlays/ImageOverlay.js.map +1 -0
- package/components/ImgGenUtils/types.d.ts +29 -0
- package/components/ImgGenUtils/types.js +2 -0
- package/components/ImgGenUtils/types.js.map +1 -0
- package/components/ImgGenUtils.d.ts +2 -0
- package/components/ImgGenUtils.js +3 -0
- package/components/ImgGenUtils.js.map +1 -0
- package/components/PromptBar.d.ts +11 -0
- package/components/PromptBar.js +24 -0
- package/components/PromptBar.js.map +1 -0
- package/components/VibeControl.d.ts +13 -0
- package/components/VibeControl.js +74 -0
- package/components/VibeControl.js.map +1 -0
- package/components/VibesButton/VibesButton.d.ts +10 -0
- package/components/VibesButton/VibesButton.js +20 -0
- package/components/VibesButton/VibesButton.js.map +1 -0
- package/components/VibesButton/VibesButton.styles.d.ts +6 -0
- package/components/VibesButton/VibesButton.styles.js +35 -0
- package/components/VibesButton/VibesButton.styles.js.map +1 -0
- package/components/VibesPanel/VibesPanel.d.ts +6 -0
- package/components/VibesPanel/VibesPanel.js +115 -0
- package/components/VibesPanel/VibesPanel.js.map +1 -0
- package/components/VibesPanel/index.d.ts +1 -0
- package/components/VibesPanel/index.js +2 -0
- package/components/VibesPanel/index.js.map +1 -0
- package/components/VibesSwitch/VibesSwitch.d.ts +6 -0
- package/components/VibesSwitch/VibesSwitch.js +54 -0
- package/components/VibesSwitch/VibesSwitch.js.map +1 -0
- package/components/VibesSwitch/VibesSwitch.styles.d.ts +4 -0
- package/components/VibesSwitch/VibesSwitch.styles.js +5 -0
- package/components/VibesSwitch/VibesSwitch.styles.js.map +1 -0
- package/constants.d.ts +4 -0
- package/constants.js +5 -0
- package/constants.js.map +1 -0
- package/events.d.ts +7 -0
- package/events.js +4 -0
- package/events.js.map +1 -0
- package/hooks/image-gen/image-generator.d.ts +11 -0
- package/hooks/image-gen/image-generator.js +146 -0
- package/hooks/image-gen/image-generator.js.map +1 -0
- package/hooks/image-gen/index.d.ts +7 -0
- package/hooks/image-gen/index.js +6 -0
- package/hooks/image-gen/index.js.map +1 -0
- package/hooks/image-gen/use-image-gen.d.ts +2 -0
- package/hooks/image-gen/use-image-gen.js +554 -0
- package/hooks/image-gen/use-image-gen.js.map +1 -0
- package/hooks/image-gen/utils.d.ts +19 -0
- package/hooks/image-gen/utils.js +150 -0
- package/hooks/image-gen/utils.js.map +1 -0
- package/hooks/use-image-gen.d.ts +1 -0
- package/hooks/use-image-gen.js +2 -0
- package/hooks/use-image-gen.js.map +1 -0
- package/hooks/vibes-gen/IframeVibesComponent.d.ts +10 -0
- package/hooks/vibes-gen/IframeVibesComponent.js +67 -0
- package/hooks/vibes-gen/IframeVibesComponent.js.map +1 -0
- package/hooks/vibes-gen/index.d.ts +2 -0
- package/hooks/vibes-gen/index.js +2 -0
- package/hooks/vibes-gen/index.js.map +1 -0
- package/hooks/vibes-gen/use-vibes.d.ts +3 -0
- package/hooks/vibes-gen/use-vibes.js +185 -0
- package/hooks/vibes-gen/use-vibes.js.map +1 -0
- package/index.d.ts +68 -0
- package/index.js +340 -0
- package/index.js.map +1 -0
- package/install-tracker.d.ts +30 -0
- package/install-tracker.js +246 -0
- package/install-tracker.js.map +1 -0
- package/package.json +47 -0
- package/stories/VibeControl.stories.d.ts +13 -0
- package/stories/VibeControl.stories.js +195 -0
- package/stories/VibeControl.stories.js.map +1 -0
- package/tsconfig.json +18 -0
- package/utils/appSlug.d.ts +17 -0
- package/utils/appSlug.js +175 -0
- package/utils/appSlug.js.map +1 -0
- package/utils/base64.d.ts +1 -0
- package/utils/base64.js +13 -0
- package/utils/base64.js.map +1 -0
- package/utils/debug.d.ts +2 -0
- package/utils/debug.js +8 -0
- package/utils/debug.js.map +1 -0
- package/utils/style-utils.d.ts +4 -0
- package/utils/style-utils.js +15 -0
- package/utils/style-utils.js.map +1 -0
- package/utils/styles.d.ts +325 -0
- package/utils/styles.js +328 -0
- package/utils/styles.js.map +1 -0
- package/utils/vibe-control-styles.d.ts +148 -0
- package/utils/vibe-control-styles.js +170 -0
- package/utils/vibe-control-styles.js.map +1 -0
- package/vibe-app-mount.d.ts +13 -0
- package/vibe-app-mount.js +124 -0
- package/vibe-app-mount.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
|