@vibes.diy/use-vibes-types 0.15.16-dev-types-fix

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 ADDED
@@ -0,0 +1,232 @@
1
+ The contents of this repository are Copyright (c) corresponding authors and
2
+ contributors, licensed under the `Permissive License Stack` meaning either of:
3
+
4
+ - Apache-2.0 Software License: https://www.apache.org/licenses/LICENSE-2.0
5
+ ([...4tr2kfsq](https://dweb.link/ipfs/bafkreiankqxazcae4onkp436wag2lj3ccso4nawxqkkfckd6cg4tr2kfsq))
6
+
7
+ - MIT Software License: https://opensource.org/licenses/MIT
8
+ ([...vljevcba](https://dweb.link/ipfs/bafkreiepofszg4gfe2gzuhojmksgemsub2h4uy2gewdnr35kswvljevcba))
9
+
10
+ You may not use the contents of this repository except in compliance
11
+ with one of the listed Licenses. For an extended clarification of the
12
+ intent behind the choice of Licensing please refer to
13
+ https://protocol.ai/blog/announcing-the-permissive-license-stack/
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the terms listed in this notice is distributed on
17
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
18
+ either express or implied. See each License for the specific language
19
+ governing permissions and limitations under that License.
20
+
21
+ <!--- SPDX-License-Identifier: Apache-2.0 OR MIT -->
22
+
23
+ `SPDX-License-Identifier: Apache-2.0 OR MIT`
24
+
25
+ Verbatim copies of both licenses are included below:
26
+
27
+ <details><summary>Apache-2.0 Software License</summary>
28
+
29
+ ```
30
+ Apache License
31
+ Version 2.0, January 2004
32
+ http://www.apache.org/licenses/
33
+
34
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
35
+
36
+ 1. Definitions.
37
+
38
+ "License" shall mean the terms and conditions for use, reproduction,
39
+ and distribution as defined by Sections 1 through 9 of this document.
40
+
41
+ "Licensor" shall mean the copyright owner or entity authorized by
42
+ the copyright owner that is granting the License.
43
+
44
+ "Legal Entity" shall mean the union of the acting entity and all
45
+ other entities that control, are controlled by, or are under common
46
+ control with that entity. For the purposes of this definition,
47
+ "control" means (i) the power, direct or indirect, to cause the
48
+ direction or management of such entity, whether by contract or
49
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
50
+ outstanding shares, or (iii) beneficial ownership of such entity.
51
+
52
+ "You" (or "Your") shall mean an individual or Legal Entity
53
+ exercising permissions granted by this License.
54
+
55
+ "Source" form shall mean the preferred form for making modifications,
56
+ including but not limited to software source code, documentation
57
+ source, and configuration files.
58
+
59
+ "Object" form shall mean any form resulting from mechanical
60
+ transformation or translation of a Source form, including but
61
+ not limited to compiled object code, generated documentation,
62
+ and conversions to other media types.
63
+
64
+ "Work" shall mean the work of authorship, whether in Source or
65
+ Object form, made available under the License, as indicated by a
66
+ copyright notice that is included in or attached to the work
67
+ (an example is provided in the Appendix below).
68
+
69
+ "Derivative Works" shall mean any work, whether in Source or Object
70
+ form, that is based on (or derived from) the Work and for which the
71
+ editorial revisions, annotations, elaborations, or other modifications
72
+ represent, as a whole, an original work of authorship. For the purposes
73
+ of this License, Derivative Works shall not include works that remain
74
+ separable from, or merely link (or bind by name) to the interfaces of,
75
+ the Work and Derivative Works thereof.
76
+
77
+ "Contribution" shall mean any work of authorship, including
78
+ the original version of the Work and any modifications or additions
79
+ to that Work or Derivative Works thereof, that is intentionally
80
+ submitted to Licensor for inclusion in the Work by the copyright owner
81
+ or by an individual or Legal Entity authorized to submit on behalf of
82
+ the copyright owner. For the purposes of this definition, "submitted"
83
+ means any form of electronic, verbal, or written communication sent
84
+ to the Licensor or its representatives, including but not limited to
85
+ communication on electronic mailing lists, source code control systems,
86
+ and issue tracking systems that are managed by, or on behalf of, the
87
+ Licensor for the purpose of discussing and improving the Work, but
88
+ excluding communication that is conspicuously marked or otherwise
89
+ designated in writing by the copyright owner as "Not a Contribution."
90
+
91
+ "Contributor" shall mean Licensor and any individual or Legal Entity
92
+ on behalf of whom a Contribution has been received by Licensor and
93
+ subsequently incorporated within the Work.
94
+
95
+ 2. Grant of Copyright License. Subject to the terms and conditions of
96
+ this License, each Contributor hereby grants to You a perpetual,
97
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
98
+ copyright license to reproduce, prepare Derivative Works of,
99
+ publicly display, publicly perform, sublicense, and distribute the
100
+ Work and such Derivative Works in Source or Object form.
101
+
102
+ 3. Grant of Patent License. Subject to the terms and conditions of
103
+ this License, each Contributor hereby grants to You a perpetual,
104
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
105
+ (except as stated in this section) patent license to make, have made,
106
+ use, offer to sell, sell, import, and otherwise transfer the Work,
107
+ where such license applies only to those patent claims licensable
108
+ by such Contributor that are necessarily infringed by their
109
+ Contribution(s) alone or by combination of their Contribution(s)
110
+ with the Work to which such Contribution(s) was submitted. If You
111
+ institute patent litigation against any entity (including a
112
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
113
+ or a Contribution incorporated within the Work constitutes direct
114
+ or contributory patent infringement, then any patent licenses
115
+ granted to You under this License for that Work shall terminate
116
+ as of the date such litigation is filed.
117
+
118
+ 4. Redistribution. You may reproduce and distribute copies of the
119
+ Work or Derivative Works thereof in any medium, with or without
120
+ modifications, and in Source or Object form, provided that You
121
+ meet the following conditions:
122
+
123
+ (a) You must give any other recipients of the Work or
124
+ Derivative Works a copy of this License; and
125
+
126
+ (b) You must cause any modified files to carry prominent notices
127
+ stating that You changed the files; and
128
+
129
+ (c) You must retain, in the Source form of any Derivative Works
130
+ that You distribute, all copyright, patent, trademark, and
131
+ attribution notices from the Source form of the Work,
132
+ excluding those notices that do not pertain to any part of
133
+ the Derivative Works; and
134
+
135
+ (d) If the Work includes a "NOTICE" text file as part of its
136
+ distribution, then any Derivative Works that You distribute must
137
+ include a readable copy of the attribution notices contained
138
+ within such NOTICE file, excluding those notices that do not
139
+ pertain to any part of the Derivative Works, in at least one
140
+ of the following places: within a NOTICE text file distributed
141
+ as part of the Derivative Works; within the Source form or
142
+ documentation, if provided along with the Derivative Works; or,
143
+ within a display generated by the Derivative Works, if and
144
+ wherever such third-party notices normally appear. The contents
145
+ of the NOTICE file are for informational purposes only and
146
+ do not modify the License. You may add Your own attribution
147
+ notices within Derivative Works that You distribute, alongside
148
+ or as an addendum to the NOTICE text from the Work, provided
149
+ that such additional attribution notices cannot be construed
150
+ as modifying the License.
151
+
152
+ You may add Your own copyright statement to Your modifications and
153
+ may provide additional or different license terms and conditions
154
+ for use, reproduction, or distribution of Your modifications, or
155
+ for any such Derivative Works as a whole, provided Your use,
156
+ reproduction, and distribution of the Work otherwise complies with
157
+ the conditions stated in this License.
158
+
159
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
160
+ any Contribution intentionally submitted for inclusion in the Work
161
+ by You to the Licensor shall be under the terms and conditions of
162
+ this License, without any additional terms or conditions.
163
+ Notwithstanding the above, nothing herein shall supersede or modify
164
+ the terms of any separate license agreement you may have executed
165
+ with Licensor regarding such Contributions.
166
+
167
+ 6. Trademarks. This License does not grant permission to use the trade
168
+ names, trademarks, service marks, or product names of the Licensor,
169
+ except as required for reasonable and customary use in describing the
170
+ origin of the Work and reproducing the content of the NOTICE file.
171
+
172
+ 7. Disclaimer of Warranty. Unless required by applicable law or
173
+ agreed to in writing, Licensor provides the Work (and each
174
+ Contributor provides its Contributions) on an "AS IS" BASIS,
175
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
176
+ implied, including, without limitation, any warranties or conditions
177
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
178
+ PARTICULAR PURPOSE. You are solely responsible for determining the
179
+ appropriateness of using or redistributing the Work and assume any
180
+ risks associated with Your exercise of permissions under this License.
181
+
182
+ 8. Limitation of Liability. In no event and under no legal theory,
183
+ whether in tort (including negligence), contract, or otherwise,
184
+ unless required by applicable law (such as deliberate and grossly
185
+ negligent acts) or agreed to in writing, shall any Contributor be
186
+ liable to You for damages, including any direct, indirect, special,
187
+ incidental, or consequential damages of any character arising as a
188
+ result of this License or out of the use or inability to use the
189
+ Work (including but not limited to damages for loss of goodwill,
190
+ work stoppage, computer failure or malfunction, or any and all
191
+ other commercial damages or losses), even if such Contributor
192
+ has been advised of the possibility of such damages.
193
+
194
+ 9. Accepting Warranty or Additional Liability. While redistributing
195
+ the Work or Derivative Works thereof, You may choose to offer,
196
+ and charge a fee for, acceptance of support, warranty, indemnity,
197
+ or other liability obligations and/or rights consistent with this
198
+ License. However, in accepting such obligations, You may act only
199
+ on Your own behalf and on Your sole responsibility, not on behalf
200
+ of any other Contributor, and only if You agree to indemnify,
201
+ defend, and hold each Contributor harmless for any liability
202
+ incurred by, or claims asserted against, such Contributor by reason
203
+ of your accepting any such warranty or additional liability.
204
+
205
+ END OF TERMS AND CONDITIONS
206
+ ```
207
+
208
+ </details>
209
+
210
+ <details><summary>MIT Software License</summary>
211
+
212
+ ```
213
+ Permission is hereby granted, free of charge, to any person obtaining a copy
214
+ of this software and associated documentation files (the "Software"), to deal
215
+ in the Software without restriction, including without limitation the rights
216
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
217
+ copies of the Software, and to permit persons to whom the Software is
218
+ furnished to do so, subject to the following conditions:
219
+
220
+ The above copyright notice and this permission notice shall be included in
221
+ all copies or substantial portions of the Software.
222
+
223
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
224
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
225
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
226
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
227
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
228
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
229
+ THE SOFTWARE.
230
+ ```
231
+
232
+ </details>
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,66 @@
1
+ import type { Database, DocWithId } from 'use-fireproof';
2
+ import { ImageGenOptions, ImageResponse } from 'call-ai';
3
+ export interface PromptEntry {
4
+ readonly text: string;
5
+ readonly created: number;
6
+ }
7
+ export interface ImageDocumentPlain {
8
+ readonly _rev?: string;
9
+ readonly type: 'image';
10
+ readonly prompt?: string;
11
+ readonly prompts?: Record<string, PromptEntry>;
12
+ readonly created: number;
13
+ readonly currentVersion: number;
14
+ readonly versions: VersionInfo[];
15
+ readonly currentPromptKey: string;
16
+ }
17
+ export type ImageDocument = DocWithId<ImageDocumentPlain>;
18
+ export type PartialImageDocument = DocWithId<Partial<ImageDocumentPlain>>;
19
+ export interface VersionInfo {
20
+ readonly id: string;
21
+ readonly created: number;
22
+ readonly promptKey?: string;
23
+ }
24
+ export type GenerationPhase = 'idle' | 'generating' | 'complete' | 'error';
25
+ export interface UseImageGenOptions {
26
+ readonly prompt: string;
27
+ readonly _id: string;
28
+ readonly _rev?: string;
29
+ readonly database: string | Database;
30
+ readonly options: Partial<ImageGenOptions>;
31
+ readonly generationId: string;
32
+ readonly skip: boolean;
33
+ readonly type?: string;
34
+ readonly currentVersion?: number;
35
+ readonly versions?: {
36
+ readonly id: string;
37
+ readonly created: number;
38
+ readonly promptKey: string;
39
+ }[];
40
+ readonly _files?: Record<string, File>;
41
+ readonly prompts?: Record<string, PromptEntry>;
42
+ readonly editedPrompt: string;
43
+ }
44
+ export interface UseImageGenResult {
45
+ readonly imageData?: string | null;
46
+ readonly loading: boolean;
47
+ readonly progress: number;
48
+ readonly error?: Error | null;
49
+ readonly size?: {
50
+ readonly width: number;
51
+ readonly height: number;
52
+ };
53
+ readonly document?: PartialImageDocument | null;
54
+ }
55
+ export interface ModuleState {
56
+ readonly pendingImageGenCalls: Map<string, Promise<ImageResponse>>;
57
+ readonly pendingPrompts: Set<string>;
58
+ readonly processingRequests: Set<string>;
59
+ readonly requestTimestamps: Map<string, number>;
60
+ requestCounter: number;
61
+ readonly createdDocuments: Map<string, string>;
62
+ readonly pendingDocumentCreations: Map<string, Promise<{
63
+ id: string;
64
+ doc: ImageDocument;
65
+ }>>;
66
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=image-gen-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-gen-types.js","sourceRoot":"","sources":["../jsr/image-gen-types.ts"],"names":[],"mappings":""}
package/index.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ export interface ImgGenClasses {
2
+ readonly root: string;
3
+ readonly container: string;
4
+ readonly image: string;
5
+ readonly overlay: string;
6
+ readonly progress: string;
7
+ readonly placeholder: string;
8
+ readonly error: string;
9
+ readonly controls: string;
10
+ readonly button: string;
11
+ readonly prompt: string;
12
+ readonly deleteOverlay: string;
13
+ readonly dropZone: string;
14
+ readonly uploadWaiting: string;
15
+ }
16
+ export interface RuntimeError {
17
+ type: string;
18
+ message: string;
19
+ source?: string;
20
+ lineno?: number;
21
+ colno?: number;
22
+ stack?: string;
23
+ reason?: string;
24
+ timestamp: string;
25
+ errorType?: 'SyntaxError' | 'ReferenceError' | 'TypeError' | 'DatabaseError' | 'Other';
26
+ }
27
+ export * from './vibes-gen-types.js';
28
+ export * from './image-gen-types.js';
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './vibes-gen-types.js';
2
+ export * from './image-gen-types.js';
3
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../jsr/index.ts"],"names":[],"mappings":"AA4CA,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@vibes.diy/use-vibes-types",
3
+ "version": "0.15.16-dev-types-fix",
4
+ "type": "module",
5
+ "description": "Core components and utilities for use-vibes (internal workspace package)",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./index.d.ts",
9
+ "import": "./index.js"
10
+ }
11
+ },
12
+ "license": "Apache-2.0",
13
+ "dependencies": {
14
+ "call-ai": "^0.15.16-dev-types-fix",
15
+ "use-fireproof": "^0.23.15"
16
+ },
17
+ "peerDependencies": {
18
+ "react": ">=19.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@fireproof/core-cli": "^0.23.15",
22
+ "@types/react": "~19.2.2",
23
+ "@vitest/browser-playwright": "^4.0.2",
24
+ "typescript": "^5.9.3"
25
+ },
26
+ "scripts": {
27
+ "build": "core-cli tsc"
28
+ }
29
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": [
3
+ "/home/runner/work/vibes.diy/vibes.diy/tsconfig.dist.json"
4
+ ],
5
+ "compilerOptions": {
6
+ "outDir": "../npm/",
7
+ "noEmit": false
8
+ },
9
+ "include": [
10
+ "**/*"
11
+ ],
12
+ "exclude": [
13
+ "node_modules",
14
+ "dist",
15
+ ".git",
16
+ ".vscode"
17
+ ]
18
+ }
@@ -0,0 +1,42 @@
1
+ import { ComponentType } from 'react';
2
+ export type GeneratedComponentProps = Record<string, unknown>;
3
+ export interface UseVibesOptions {
4
+ database?: string;
5
+ model?: string;
6
+ skip?: boolean;
7
+ regenerate?: boolean;
8
+ dependencies?: string[];
9
+ _id?: string;
10
+ }
11
+ export interface UseVibesResult {
12
+ App: ComponentType<GeneratedComponentProps> | null;
13
+ code: string | null;
14
+ loading: boolean;
15
+ error: Error | null;
16
+ progress: number;
17
+ regenerate: () => void;
18
+ document?: VibeDocument | null;
19
+ }
20
+ export interface VibeDocument {
21
+ _id: string;
22
+ prompt: string;
23
+ code: string;
24
+ title: string;
25
+ dependencies: string[];
26
+ model: string;
27
+ created_at: number;
28
+ version: number;
29
+ metadata?: {
30
+ tokens_used?: number;
31
+ generation_time?: number;
32
+ options_hash?: string;
33
+ };
34
+ }
35
+ export interface UseVibesState {
36
+ App: ComponentType<GeneratedComponentProps> | null;
37
+ code: string | null;
38
+ loading: boolean;
39
+ error: Error | null;
40
+ progress: number;
41
+ document: VibeDocument | null;
42
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vibes-gen-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vibes-gen-types.js","sourceRoot":"","sources":["../jsr/vibes-gen-types.ts"],"names":[],"mappings":""}