@umituz/react-native-ai-generation-content 1.17.230 → 1.17.232

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.
@@ -1,228 +1,394 @@
1
- # Text to Image
1
+ # Text to Image Feature
2
2
 
3
- Generate images from text prompts using AI.
3
+ Generate images from text prompts using AI models.
4
4
 
5
- ## Features
5
+ ## 📍 Import Path
6
6
 
7
- - Generate images from natural language descriptions
8
- - Support for multiple aspect ratios and sizes
9
- - Style presets for different artistic effects
10
- - Multiple image generation in one request
11
- - Progress tracking during generation
7
+ ```typescript
8
+ import { useTextToImageFeature } from '@umituz/react-native-ai-generation-content';
9
+ ```
12
10
 
13
- ## Installation
11
+ **Location**: `src/features/text-to-image/`
14
12
 
15
- This feature is part of `@umituz/react-native-ai-generation-content`.
13
+ ## 🎯 Feature Purpose
16
14
 
17
- ```bash
18
- npm install @umituz/react-native-ai-generation-content
19
- ```
15
+ Convert natural language text descriptions into AI-generated images. Supports various aspect ratios, styles, and quality settings.
20
16
 
21
- ## Basic Usage
17
+ ---
22
18
 
23
- ### Using the Hook
19
+ ## 📋 Usage Strategy
24
20
 
25
- ```tsx
26
- import { useTextToImageFeature } from '@umituz/react-native-ai-generation-content';
21
+ ### When to Use This Feature
27
22
 
28
- function TextToImageScreen() {
29
- const feature = useTextToImageFeature({
30
- config: {
31
- model: 'imagen-3',
32
- onPromptChange: (prompt) => console.log('Prompt changed:', prompt),
33
- onProcessingStart: () => console.log('Starting generation...'),
34
- onProcessingComplete: (result) => console.log('Generation complete:', result),
35
- onError: (error) => console.error('Error:', error),
36
- },
37
- userId: 'user-123',
38
- });
39
-
40
- return (
41
- <View>
42
- <TextInput
43
- placeholder="Describe the image you want to create..."
44
- onChangeText={feature.setPrompt}
45
- value={feature.state.prompt}
46
- />
47
-
48
- <Button
49
- title="Generate Image"
50
- onPress={() => feature.generate()}
51
- disabled={!feature.isReady}
52
- />
53
-
54
- {feature.state.isProcessing && (
55
- <Text>Progress: {feature.state.progress}%</Text>
56
- )}
57
-
58
- {feature.state.imageUrl && (
59
- <Image source={{ uri: feature.state.imageUrl }} />
60
- )}
61
-
62
- {feature.state.error && (
63
- <Text>Error: {feature.state.error}</Text>
64
- )}
65
- </View>
66
- );
67
- }
68
- ```
23
+ **Use Cases:**
24
+ - Generating original images from text descriptions
25
+ - Creating visual content for marketing materials
26
+ - Generating concept art and prototypes
27
+ - Creating social media visuals
28
+ - Product visualization from descriptions
29
+ - Storyboarding and creative planning
69
30
 
70
- ### Using the Unified AI Feature Screen
31
+ **When NOT to Use:**
32
+ - Image manipulation of existing photos (use Image-to-Image)
33
+ - Photo restoration (use Photo Restoration)
34
+ - Style transfer on existing images (use Style Transfer)
35
+ - Face swapping (use Face Swap)
71
36
 
72
- ```tsx
73
- import { AIFeatureScreen } from '@umituz/react-native-ai-generation-content';
37
+ ### Implementation Strategy
74
38
 
75
- function App() {
76
- return (
77
- <AIFeatureScreen
78
- featureId="text-to-image"
79
- userId="user-123"
80
- />
81
- );
82
- }
83
- ```
39
+ 1. **Use the feature hook** at component level
40
+ 2. **Initialize with config** before first render
41
+ 3. **Handle all states** - loading, success, error
42
+ 4. **Implement progress tracking** for better UX
43
+ 5. **Store generated images** for later use
84
44
 
85
- ## Configuration Options
45
+ ---
86
46
 
87
- ### Feature Config
47
+ ## ⚠️ Critical Rules (MUST FOLLOW)
88
48
 
89
- ```tsx
90
- interface TextToImageFeatureConfig {
91
- model?: string; // AI model to use (default: 'imagen-3')
92
- onPromptChange?: (prompt: string) => void;
93
- onProcessingStart?: () => void;
94
- onProcessingComplete?: (result: TextToImageResult) => void;
95
- onError?: (error: string) => void;
96
- buildInput?: (prompt: string, options: TextToImageOptions) => any;
97
- extractResult?: (response: any) => TextToImageResult;
98
- }
99
- ```
49
+ ### 1. Prompt Engineering
50
+ - **MUST** use descriptive, specific prompts
51
+ - **MUST** include subject, action, and context
52
+ - **MUST** specify art style if important
53
+ - **MUST** use English for best results
54
+ - **MUST NOT** exceed character limits (check model limits)
100
55
 
101
- ### Generation Options
56
+ ### 2. Configuration
57
+ - **MUST** provide valid `userId` for tracking
58
+ - **MUST** implement `onError` callback
59
+ - **MUST** handle `isProcessing` state to prevent duplicate requests
60
+ - **MUST** validate prompts before generation
61
+ - **MUST NOT** call `generate()` when `isReady` is false
62
+
63
+ ### 3. State Management
64
+ - **MUST** check `isReady` before enabling generate button
65
+ - **MUST** handle `isProcessing` state with loading indicators
66
+ - **MUST** display `error` state to users
67
+ - **MUST** handle `result.imageUrl` existence check
68
+ - **MUST** implement proper cleanup on unmount
69
+
70
+ ### 4. Performance
71
+ - **MUST** implement debouncing for prompt inputs (>500ms)
72
+ - **MUST** limit concurrent requests (max 1 per user)
73
+ - **MUST** cache generated images locally
74
+ - **MUST** implement retry logic (max 3 attempts)
75
+ - **MUST NOT** generate multiple images simultaneously
76
+
77
+ ### 5. Security & Privacy
78
+ - **MUST** validate and sanitize user prompts
79
+ - **MUST** implement content moderation
80
+ - **MUST** check for inappropriate content
81
+ - **MUST** store userId securely
82
+ - **MUST NOT** expose API keys in client code
83
+
84
+ ---
85
+
86
+ ## 🚫 Prohibitions (MUST AVOID)
87
+
88
+ ### Strictly Forbidden
89
+
90
+ ❌ **NEVER** do the following:
91
+
92
+ 1. **No Empty Prompts**
93
+ - Always validate prompt has meaningful content
94
+ - Minimum 10 characters recommended
95
+
96
+ 2. **No Concurrent Generation**
97
+ - Never call `generate()` while `isProcessing === true`
98
+ - Always disable generate button during processing
99
+
100
+ 3. **No Hardcoded Credentials**
101
+ - Never store API keys in component files
102
+ - Use environment variables or secure storage
103
+
104
+ 4. **No Unhandled Errors**
105
+ - Never ignore error states
106
+ - Always implement error boundaries
107
+
108
+ 5. **No Memory Leaks**
109
+ - Never forget cleanup on unmount
110
+ - Always cancel pending requests
111
+
112
+ 6. **No Excessive Re-renders**
113
+ - Never pass new config objects on each render
114
+ - Always memoize configuration objects
115
+
116
+ 7. **No Blocked Main Thread**
117
+ - Never perform heavy operations in render
118
+ - Use web workers or background tasks for processing
119
+
120
+ ---
121
+
122
+ ## 🤖 AI Agent Directions
123
+
124
+ ### For AI Code Generation Tools
125
+
126
+ When using this feature with AI code generation tools, follow these guidelines:
127
+
128
+ #### Prompt Template for AI Agents
102
129
 
103
- ```tsx
104
- interface TextToImageOptions {
105
- aspectRatio?: '1:1' | '16:9' | '9:16' | '4:3' | '3:4';
106
- numberOfImages?: number; // 1-4
107
- style?: 'realistic' | 'artistic' | 'anime' | '3d' | 'painting';
108
- negativePrompt?: string;
109
- }
110
130
  ```
131
+ You are implementing a text-to-image generation feature using @umituz/react-native-ai-generation-content.
132
+
133
+ REQUIREMENTS:
134
+ 1. Import from: @umituz/react-native-ai-generation-content
135
+ 2. Use the useTextToImageFeature hook
136
+ 3. Implement all state handlers (loading, success, error)
137
+ 4. Add debouncing for prompt input
138
+ 5. Validate prompts before generation
139
+ 6. Handle isReady and isProcessing states correctly
140
+ 7. Implement proper error handling with user feedback
141
+ 8. Add loading indicators during generation
142
+ 9. Display results safely with null checks
143
+ 10. Implement cleanup on unmount
144
+
145
+ CRITICAL RULES:
146
+ - NEVER call generate() when isProcessing is true
147
+ - ALWAYS validate prompt before calling generate()
148
+ - MUST handle error state with user-friendly message
149
+ - MUST disable generate button during processing
150
+ - MUST implement debouncing (500ms minimum)
151
+
152
+ CONFIGURATION:
153
+ - Provide valid userId (string)
154
+ - Set model (default: 'imagen-3')
155
+ - Configure callbacks: onProcessingStart, onProcessingComplete, onError
156
+
157
+ GENERATION OPTIONS:
158
+ - aspectRatio: '1:1' | '16:9' | '9:16' | '4:3' | '3:4'
159
+ - numberOfImages: 1-4
160
+ - style: 'realistic' | 'artistic' | 'anime' | '3d' | 'painting'
161
+ - negativePrompt: string (optional)
162
+
163
+ STRICTLY FORBIDDEN:
164
+ - No empty prompts
165
+ - No concurrent generation calls
166
+ - No hardcoded API keys
167
+ - No unhandled errors
168
+ - No memory leaks
169
+ ```
170
+
171
+ #### AI Implementation Checklist
111
172
 
112
- ## Advanced Usage
173
+ Use this checklist when generating code:
113
174
 
114
- ### Custom Style Selector
175
+ - [ ] Feature imported from correct path
176
+ - [ ] Hook initialized with proper config
177
+ - [ ] All state handlers implemented
178
+ - [ ] Debouncing added to input
179
+ - [ ] Validation before generate()
180
+ - [ ] Loading indicator during processing
181
+ - [ ] Error display with user-friendly message
182
+ - [ ] Button disabled when processing
183
+ - [ ] Cleanup on unmount
184
+ - [ ] Null checks on result
185
+ - [ ] Retry logic implemented
186
+ - [ ] Image caching configured
115
187
 
116
- ```tsx
117
- import { StyleSelector } from '@umituz/react-native-ai-generation-content';
188
+ ---
118
189
 
119
- const styles = [
120
- { id: 'realistic', name: 'Realistic', preview: '...' },
121
- { id: 'artistic', name: 'Artistic', preview: '...' },
122
- { id: 'anime', name: 'Anime', preview: '...' },
123
- ];
190
+ ## 🛠️ Configuration Strategy
124
191
 
125
- function MyScreen() {
126
- const [selectedStyle, setSelectedStyle] = useState('realistic');
192
+ ### Essential Configuration
127
193
 
128
- return (
129
- <StyleSelector
130
- styles={styles}
131
- selectedStyle={selectedStyle}
132
- onSelectStyle={setSelectedStyle}
133
- />
134
- );
194
+ ```typescript
195
+ // Required fields
196
+ {
197
+ userId: string // User identifier for tracking
198
+ }
199
+
200
+ // Optional callbacks
201
+ {
202
+ onProcessingStart?: () => void
203
+ onProcessingComplete?: (result) => void
204
+ onError?: (error: string) => void
135
205
  }
136
206
  ```
137
207
 
138
- ### Aspect Ratio Selection
208
+ ### Recommended Settings
209
+
210
+ 1. **Model Selection**
211
+ - Default: `imagen-3`
212
+ - Fastest: `imagen-2-fast`
213
+ - Highest quality: `imagen-3`
214
+
215
+ 2. **Generation Options**
216
+ - Aspect Ratio: Match your UI layout
217
+ - Number of Images: 1-2 for speed, 3-4 for variety
218
+ - Style: Choose based on use case
219
+
220
+ 3. **Performance Settings**
221
+ - Enable image caching
222
+ - Set reasonable timeouts (30s default)
223
+ - Implement retry with backoff
224
+
225
+ ---
226
+
227
+ ## 📊 State Management
139
228
 
140
- ```tsx
141
- import { AspectRatioSelector } from '@umituz/react-native-ai-generation-content';
229
+ ### Feature States
142
230
 
143
- function MyScreen() {
144
- const [aspectRatio, setAspectRatio] = useState('1:1');
231
+ **isReady**: boolean
232
+ - Feature initialized and ready to use
233
+ - Check before enabling generate button
145
234
 
146
- return (
147
- <AspectRatioSelector
148
- selectedAspectRatio={aspectRatio}
149
- onSelectAspectRatio={setAspectRatio}
150
- />
151
- );
235
+ **isProcessing**: boolean
236
+ - Generation in progress
237
+ - Show loading indicator
238
+ - Disable generate button
239
+
240
+ **progress**: number (0-100)
241
+ - Generation progress percentage
242
+ - Update progress bar
243
+
244
+ **error**: string | null
245
+ - Error message if generation failed
246
+ - Display to user with clear message
247
+
248
+ **result**: {
249
+ imageUrl: string
250
+ imageUrls?: string[]
251
+ metadata?: any
152
252
  }
153
- ```
154
253
 
155
- ## Examples
254
+ ---
156
255
 
157
- ### Basic Image Generation
256
+ ## 🔐 Security Considerations
158
257
 
159
- ```tsx
160
- const result = await feature.generate({
161
- aspectRatio: '16:9',
162
- numberOfImages: 2,
163
- });
164
- ```
258
+ ### Content Moderation
165
259
 
166
- ### With Style Preset
260
+ - **MUST** implement prompt content filtering
261
+ - **MUST** check for inappropriate content
262
+ - **MUST** block harmful or illegal prompts
263
+ - **MUST** log moderation actions
167
264
 
168
- ```tsx
169
- const result = await feature.generate({
170
- style: 'artistic',
171
- negativePrompt: 'blurry, low quality',
172
- });
173
- ```
265
+ ### API Security
174
266
 
175
- ### Multiple Images
267
+ - **MUST** use environment variables for API keys
268
+ - **MUST** implement rate limiting
269
+ - **MUST** validate all user inputs
270
+ - **MUST** use HTTPS for all API calls
176
271
 
177
- ```tsx
178
- const result = await feature.generate({
179
- numberOfImages: 4,
180
- });
272
+ ### Data Privacy
181
273
 
182
- // Access all generated images
183
- result.imageUrls.forEach(url => {
184
- console.log('Generated image:', url);
185
- });
186
- ```
274
+ - **MUST** comply with data protection regulations
275
+ - **MUST** obtain user consent for generation
276
+ - **MUST** provide privacy policy
277
+ - **MUST** allow data deletion requests
187
278
 
188
- ## Example Prompts
279
+ ---
189
280
 
190
- ```tsx
191
- const examplePrompts = [
192
- 'A beautiful sunset over mountains with vibrant colors',
193
- 'Futuristic cityscape at night with neon lights',
194
- 'Enchanted forest with magical glowing mushrooms',
195
- 'Cozy coffee shop interior on a rainy day',
196
- 'Dragon flying over snow-capped mountain peaks',
197
- ];
198
- ```
281
+ ## 🎨 Best Practices
199
282
 
200
- ## Error Handling
283
+ ### Prompt Engineering
201
284
 
202
- ```tsx
203
- const { state, generate } = useTextToImageFeature({ ...config });
285
+ 1. **Be Specific**
286
+ - Good: "A majestic lion standing on a rock at sunset, detailed fur, dramatic lighting"
287
+ - Bad: "A lion"
204
288
 
205
- useEffect(() => {
206
- if (state.error) {
207
- Alert.alert('Generation Failed', state.error);
208
- }
209
- }, [state.error]);
210
- ```
289
+ 2. **Include Style**
290
+ - Specify art style, mood, atmosphere
291
+ - Example: "in the style of oil painting, romantic mood"
292
+
293
+ 3. **Add Technical Details**
294
+ - Lighting, camera angle, composition
295
+ - Example: "golden hour lighting, wide angle shot"
296
+
297
+ 4. **Use Negative Prompts**
298
+ - Specify what to avoid
299
+ - Example: "blurry, low quality, distorted"
300
+
301
+ ### Performance Optimization
302
+
303
+ 1. **Debounce Input**
304
+ - Wait 500ms after user stops typing
305
+ - Prevents unnecessary validations
306
+
307
+ 2. **Lazy Loading**
308
+ - Load images on demand
309
+ - Use pagination for multiple results
310
+
311
+ 3. **Cache Results**
312
+ - Store generated images locally
313
+ - Implement cache invalidation strategy
314
+
315
+ 4. **Progressive Enhancement**
316
+ - Show placeholder while loading
317
+ - Display low-res first, then high-res
318
+
319
+ ---
320
+
321
+ ## 🐛 Common Pitfalls
322
+
323
+ ### Memory Issues
324
+
325
+ ❌ **Problem**: Storing all generated images in state
326
+ ✅ **Solution**: Implement pagination or virtualized lists
327
+
328
+ ### Performance Issues
329
+
330
+ ❌ **Problem**: Re-generating on every prompt change
331
+ ✅ **Solution**: Require explicit user action to generate
332
+
333
+ ### UX Issues
334
+
335
+ ❌ **Problem**: No feedback during generation
336
+ ✅ **Solution**: Always show progress indicator
337
+
338
+ ### Error Handling
339
+
340
+ ❌ **Problem**: Generic error messages
341
+ ✅ **Solution**: Provide specific, actionable error messages
342
+
343
+ ---
344
+
345
+ ## 📦 Related Components
346
+
347
+ Use these components from the library:
348
+
349
+ - **GenerationProgressModal**: Progress display
350
+ - **StyleSelector**: Style selection UI
351
+ - **AspectRatioSelector**: Aspect ratio picker
352
+ - **ImageGallery**: Display multiple results
353
+ - **PromptInput**: Enhanced text input
354
+
355
+ Located at: `src/presentation/components/`
356
+
357
+ ---
358
+
359
+ ## 🔄 Migration Strategy
360
+
361
+ If migrating from previous implementation:
362
+
363
+ 1. **Update imports** to new path
364
+ 2. **Replace old config** with new structure
365
+ 3. **Update state handling** to match new interface
366
+ 4. **Test all error cases**
367
+ 5. **Update UI components** for new state structure
368
+
369
+ ---
370
+
371
+ ## 📚 Additional Resources
372
+
373
+ - Main documentation: `/docs/`
374
+ - API reference: `/docs/api/`
375
+ - Examples: `/docs/examples/basic/text-to-image/`
376
+ - Architecture: `/ARCHITECTURE.md`
211
377
 
212
- ## Best Practices
378
+ ---
213
379
 
214
- 1. **Prompt Quality**: Use detailed, descriptive prompts for better results
215
- 2. **Aspect Ratio**: Choose the right aspect ratio for your use case
216
- 3. **Batch Generation**: Generate multiple images to get more options
217
- 4. **Negative Prompts**: Use negative prompts to avoid unwanted elements
218
- 5. **Error Handling**: Always handle errors gracefully in production
380
+ **Last Updated**: 2025-01-08
381
+ **Version**: 2.0.0 (Strategy-based Documentation)
219
382
 
220
- ## Related Features
383
+ ---
221
384
 
222
- - [Text to Video](../text-to-video) - Generate videos from text
223
- - [Image to Image](../image-to-image) - Transform images with AI
224
- - [Style Transfer](../style-transfer) - Apply artistic styles to images
385
+ ## 📝 Changelog
225
386
 
226
- ## License
387
+ ### v2.0.0 - 2025-01-08
388
+ - **BREAKING**: Documentation format changed to strategy-based
389
+ - Removed extensive code examples
390
+ - Added rules, prohibitions, and AI agent directions
391
+ - Focus on best practices and implementation guidance
227
392
 
228
- MIT
393
+ ### v1.0.0 - Initial Release
394
+ - Initial feature documentation