@umituz/react-native-ai-generation-content 1.12.2 → 1.12.3

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 (40) hide show
  1. package/package.json +5 -1
  2. package/src/domains/prompts/domain/entities/AIPromptTemplate.ts +48 -0
  3. package/src/domains/prompts/domain/entities/BackgroundRemovalConfig.ts +86 -0
  4. package/src/domains/prompts/domain/entities/ColorizationConfig.ts +101 -0
  5. package/src/domains/prompts/domain/entities/FaceSwapConfig.ts +54 -0
  6. package/src/domains/prompts/domain/entities/FuturePredictionConfig.ts +93 -0
  7. package/src/domains/prompts/domain/entities/GeneratedPrompt.ts +32 -0
  8. package/src/domains/prompts/domain/entities/ImageEnhancementConfig.ts +93 -0
  9. package/src/domains/prompts/domain/entities/PhotoRestorationConfig.ts +64 -0
  10. package/src/domains/prompts/domain/entities/StyleTransferConfig.ts +80 -0
  11. package/src/domains/prompts/domain/entities/TextGenerationConfig.ts +100 -0
  12. package/src/domains/prompts/domain/entities/types.ts +27 -0
  13. package/src/domains/prompts/domain/entities/value-objects.ts +33 -0
  14. package/src/domains/prompts/domain/repositories/IAIPromptServices.ts +106 -0
  15. package/src/domains/prompts/domain/repositories/IPromptHistoryRepository.ts +10 -0
  16. package/src/domains/prompts/domain/repositories/ITemplateRepository.ts +11 -0
  17. package/src/domains/prompts/index.ts +318 -0
  18. package/src/domains/prompts/infrastructure/repositories/PromptHistoryRepository.ts +85 -0
  19. package/src/domains/prompts/infrastructure/repositories/TemplateRepository.ts +77 -0
  20. package/src/domains/prompts/infrastructure/services/BackgroundRemovalService.ts +209 -0
  21. package/src/domains/prompts/infrastructure/services/ColorizationService.ts +232 -0
  22. package/src/domains/prompts/infrastructure/services/FaceSwapService.ts +198 -0
  23. package/src/domains/prompts/infrastructure/services/FuturePredictionService.ts +176 -0
  24. package/src/domains/prompts/infrastructure/services/ImageEnhancementService.ts +181 -0
  25. package/src/domains/prompts/infrastructure/services/PhotoRestorationService.ts +160 -0
  26. package/src/domains/prompts/infrastructure/services/PromptGenerationService.ts +59 -0
  27. package/src/domains/prompts/infrastructure/services/StyleTransferService.ts +194 -0
  28. package/src/domains/prompts/infrastructure/services/TextGenerationService.ts +241 -0
  29. package/src/domains/prompts/presentation/hooks/useAIServices.ts +213 -0
  30. package/src/domains/prompts/presentation/hooks/useAsyncState.ts +56 -0
  31. package/src/domains/prompts/presentation/hooks/useFaceSwap.ts +100 -0
  32. package/src/domains/prompts/presentation/hooks/useImageEnhancement.ts +100 -0
  33. package/src/domains/prompts/presentation/hooks/usePhotoRestoration.ts +100 -0
  34. package/src/domains/prompts/presentation/hooks/usePromptGeneration.ts +144 -0
  35. package/src/domains/prompts/presentation/hooks/useStyleTransfer.ts +125 -0
  36. package/src/domains/prompts/presentation/hooks/useTemplateRepository.ts +113 -0
  37. package/src/domains/prompts/presentation/theme/theme.ts +16 -0
  38. package/src/domains/prompts/presentation/theme/types.ts +82 -0
  39. package/src/domains/prompts/presentation/theme/utils.ts +24 -0
  40. package/src/index.ts +6 -0
@@ -0,0 +1,77 @@
1
+ import type { ITemplateRepository } from '../../domain/repositories/ITemplateRepository';
2
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
3
+ import type { AIPromptCategory, AIPromptResult } from '../../domain/entities/types';
4
+
5
+ export class TemplateRepository implements ITemplateRepository {
6
+ private storage = new Map<string, AIPromptTemplate>();
7
+
8
+ async findById(id: string): Promise<AIPromptResult<AIPromptTemplate | null>> {
9
+ try {
10
+ const template = this.storage.get(id) || null;
11
+ return { success: true, data: template };
12
+ } catch (error) {
13
+ return {
14
+ success: false,
15
+ error: 'STORAGE_ERROR',
16
+ message: 'Failed to retrieve template'
17
+ };
18
+ }
19
+ }
20
+
21
+ async findByCategory(category: AIPromptCategory): Promise<AIPromptResult<AIPromptTemplate[]>> {
22
+ try {
23
+ const templates = Array.from(this.storage.values())
24
+ .filter(template => template.category === category);
25
+ return { success: true, data: templates };
26
+ } catch (error) {
27
+ return {
28
+ success: false,
29
+ error: 'STORAGE_ERROR',
30
+ message: 'Failed to retrieve templates by category'
31
+ };
32
+ }
33
+ }
34
+
35
+ async findAll(): Promise<AIPromptResult<AIPromptTemplate[]>> {
36
+ try {
37
+ const templates = Array.from(this.storage.values());
38
+ return { success: true, data: templates };
39
+ } catch (error) {
40
+ return {
41
+ success: false,
42
+ error: 'STORAGE_ERROR',
43
+ message: 'Failed to retrieve all templates'
44
+ };
45
+ }
46
+ }
47
+
48
+ async save(template: AIPromptTemplate): Promise<AIPromptResult<void>> {
49
+ try {
50
+ this.storage.set(template.id, template);
51
+ return { success: true, data: undefined };
52
+ } catch (error) {
53
+ return {
54
+ success: false,
55
+ error: 'STORAGE_ERROR',
56
+ message: 'Failed to save template'
57
+ };
58
+ }
59
+ }
60
+
61
+ async delete(id: string): Promise<AIPromptResult<void>> {
62
+ try {
63
+ this.storage.delete(id);
64
+ return { success: true, data: undefined };
65
+ } catch (error) {
66
+ return {
67
+ success: false,
68
+ error: 'STORAGE_ERROR',
69
+ message: 'Failed to delete template'
70
+ };
71
+ }
72
+ }
73
+
74
+ async exists(id: string): Promise<boolean> {
75
+ return this.storage.has(id);
76
+ }
77
+ }
@@ -0,0 +1,209 @@
1
+ import type { IBackgroundRemovalService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ BackgroundRemovalConfig,
4
+ } from '../../domain/entities/BackgroundRemovalConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import {
9
+ validateBackgroundRemovalConfig,
10
+ getProcessingTime,
11
+ getQualityScore
12
+ } from '../../domain/entities/BackgroundRemovalConfig';
13
+ import { PromptGenerationService } from '../services/PromptGenerationService';
14
+
15
+ const createBackgroundRemovalBaseTemplate = (config?: {
16
+ precision?: string;
17
+ edgeRefinement?: boolean;
18
+ }): string => {
19
+ const {
20
+ precision = 'accurate',
21
+ edgeRefinement = true
22
+ } = config || {};
23
+
24
+ return `
25
+ You are an expert AI background removal specialist.
26
+ This is a BACKGROUND REMOVAL task, not image generation.
27
+
28
+ BACKGROUND REMOVAL OBJECTIVES:
29
+ - Remove background with ${precision} precision
30
+ - ${edgeRefinement ? 'Refine edges for clean cutout' : 'Focus on speed over precision'}
31
+ - Preserve subject integrity and details
32
+ - Create professional-quality transparency
33
+
34
+ DETECTION PRINCIPLES:
35
+ - Accurately identify foreground subject
36
+ - Distinguish between subject and background
37
+ - Handle complex edges (hair, fur, transparent objects)
38
+ - Preserve fine details and textures
39
+
40
+ TECHNICAL REQUIREMENTS:
41
+ ${precision === 'ultra-accurate' ?
42
+ `- Maximum precision processing
43
+ - Advanced edge detection algorithms
44
+ - Multiple refinement passes
45
+ - Subpixel accuracy for edges` :
46
+ precision === 'accurate' ?
47
+ `- Standard precision processing
48
+ - Reliable edge detection
49
+ - Single refinement pass
50
+ - Good balance of speed/quality` :
51
+ `- Fast processing optimization
52
+ - Basic edge detection
53
+ - Quick subject isolation
54
+ - Suitable for simple backgrounds`}
55
+
56
+ EDGE HANDLING:
57
+ ${edgeRefinement ?
58
+ `- Feather edges naturally
59
+ - Preserve hair and fine details
60
+ - Remove halos and artifacts
61
+ - Smooth transitions` :
62
+ `- Focus on speed
63
+ - Basic edge processing
64
+ - Minimal refinement
65
+ - Quick turnaround time`}
66
+
67
+ SAFETY CONSTRAINTS:
68
+ - Preserve subject completely
69
+ - Do not alter foreground content
70
+ - Maintain important details
71
+ - Avoid over-removal of subject elements
72
+
73
+ OUTPUT:
74
+ Subject with transparent background,
75
+ ready for compositing or new background application.
76
+ `.trim();
77
+ };
78
+
79
+ export class BackgroundRemovalService implements IBackgroundRemovalService {
80
+ private promptService: PromptGenerationService;
81
+
82
+ constructor() {
83
+ this.promptService = new PromptGenerationService();
84
+ }
85
+
86
+ async generateTemplate(config: BackgroundRemovalConfig): Promise<AIPromptResult<AIPromptTemplate>> {
87
+ try {
88
+ if (!this.validateConfig(config)) {
89
+ return {
90
+ success: false,
91
+ error: 'VALIDATION_ERROR',
92
+ message: 'Invalid background removal configuration'
93
+ };
94
+ }
95
+
96
+ const template = this.createBackgroundRemovalTemplate(config);
97
+ return { success: true, data: template };
98
+ } catch (error) {
99
+ return {
100
+ success: false,
101
+ error: 'GENERATION_FAILED',
102
+ message: 'Failed to generate background removal template'
103
+ };
104
+ }
105
+ }
106
+
107
+ async generatePrompt(
108
+ template: AIPromptTemplate,
109
+ config: BackgroundRemovalConfig
110
+ ): Promise<AIPromptResult<string>> {
111
+ const variables = {
112
+ precision: config.precision,
113
+ edgeRefinement: config.edgeRefinement,
114
+ preserveHair: config.preserveHair,
115
+ outputFormat: config.outputFormat,
116
+ addNewBackground: config.addNewBackground,
117
+ processingTime: getProcessingTime(config.precision),
118
+ qualityScore: getQualityScore(config),
119
+ };
120
+
121
+ return this.promptService.generateFromTemplate(template, variables);
122
+ }
123
+
124
+ validateConfig(config: BackgroundRemovalConfig): boolean {
125
+ return validateBackgroundRemovalConfig(config);
126
+ }
127
+
128
+ estimateProcessingTime(config: BackgroundRemovalConfig): number {
129
+ return getProcessingTime(config.precision);
130
+ }
131
+
132
+ private createBackgroundRemovalTemplate(config: BackgroundRemovalConfig): AIPromptTemplate {
133
+ const templateId = `background-removal-${config.precision}`;
134
+
135
+ const baseTemplate = createBackgroundRemovalBaseTemplate({
136
+ precision: config.precision,
137
+ edgeRefinement: config.edgeRefinement,
138
+ });
139
+
140
+ return createAIPromptTemplate({
141
+ id: templateId,
142
+ name: `Background Removal: ${config.precision}`,
143
+ description: `Remove background with ${config.precision} precision`,
144
+ category: 'background-removal',
145
+ template: `${baseTemplate}
146
+
147
+ REMOVAL CONFIGURATION:
148
+ - Precision Level: ${config.precision}
149
+ - Edge Refinement: ${config.edgeRefinement}
150
+ - Preserve Hair: ${config.preserveHair}
151
+ - Output Format: ${config.outputFormat}
152
+ ${config.addNewBackground ? `- New Background: ${config.addNewBackground}` : ''}
153
+
154
+ SPECIFIC REQUIREMENTS:
155
+ ${this.getSpecificRequirements(config)}
156
+
157
+ PROCESSING EXPECTATIONS:
158
+ - Estimated Time: ${getProcessingTime(config.precision)} seconds
159
+ - Quality Score: ${Math.round(getQualityScore(config) * 100)}%
160
+ - Edge Detail: ${config.edgeRefinement ? 'High precision' : 'Standard precision'}
161
+ - Hair Handling: ${config.preserveHair ? 'Preserved with detail' : 'Standard processing'}
162
+
163
+ OUTPUT FORMAT:
164
+ ${config.outputFormat === 'transparent' ? 'Transparent PNG with alpha channel' :
165
+ config.outputFormat === 'png' ? 'PNG format with transparency' :
166
+ 'WebP format with transparency support'}
167
+
168
+ ${config.addNewBackground ? `NEW BACKGROUND:
169
+ Replace removed background with: ${config.addNewBackground}
170
+ Ensure proper blending and integration with subject.` : ''}
171
+
172
+ EXPECTED RESULT:
173
+ Clean subject with background removed,
174
+ ${config.edgeRefinement ? 'with refined edges and preserved details' : 'with standard edge quality'},
175
+ ready for ${config.outputFormat} output.
176
+ `.trim(),
177
+ variables: [],
178
+ safety: {
179
+ contentFilter: true,
180
+ adultContentFilter: true,
181
+ violenceFilter: true,
182
+ hateSpeechFilter: true,
183
+ copyrightFilter: true,
184
+ },
185
+ version: '1.0.0',
186
+ });
187
+ }
188
+
189
+ private getSpecificRequirements(config: BackgroundRemovalConfig): string {
190
+ const requirements: string[] = [];
191
+
192
+ if (config.preserveHair) {
193
+ requirements.push('- Advanced hair detection and preservation');
194
+ requirements.push('- Fine strand handling and transparency');
195
+ }
196
+
197
+ if (config.edgeRefinement) {
198
+ requirements.push('- Subpixel edge accuracy');
199
+ requirements.push('- Natural feathering and anti-aliasing');
200
+ }
201
+
202
+ if (config.precision === 'ultra-accurate') {
203
+ requirements.push('- Multi-pass refinement processing');
204
+ requirements.push('- Advanced artifact removal');
205
+ }
206
+
207
+ return requirements.join('\n') || '- Standard background removal processing';
208
+ }
209
+ }
@@ -0,0 +1,232 @@
1
+ import type { IColorizationService } from '../../domain/repositories/IAIPromptServices';
2
+ import type {
3
+ ColorizationConfig,
4
+ } from '../../domain/entities/ColorizationConfig';
5
+ import type { AIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
6
+ import type { AIPromptResult } from '../../domain/entities/types';
7
+ import { createAIPromptTemplate } from '../../domain/entities/AIPromptTemplate';
8
+ import {
9
+ validateColorizationConfig,
10
+ getColorizationQuality,
11
+ getEraDescription,
12
+ getSuggestedColorPalette
13
+ } from '../../domain/entities/ColorizationConfig';
14
+ import { PromptGenerationService } from '../services/PromptGenerationService';
15
+
16
+ const createColorizationBaseTemplate = (config?: {
17
+ targetType?: string;
18
+ colorMode?: string;
19
+ }): string => {
20
+ const {
21
+ targetType = 'black-and-white',
22
+ colorMode = 'realistic'
23
+ } = config || {};
24
+
25
+ return `
26
+ You are an expert AI colorization specialist.
27
+ This is a PHOTO COLORIZATION task, not image generation.
28
+
29
+ COLORIZATION OBJECTIVES:
30
+ - Add appropriate colors to ${targetType} images
31
+ - Apply ${colorMode} color treatment while preserving authenticity
32
+ - Maintain original composition and details
33
+ - Create natural, pleasing color relationships
34
+
35
+ COLORIZATION PRINCIPLES:
36
+ - Research appropriate color schemes for image era/content
37
+ - Apply colors that match scene context and lighting
38
+ - Preserve details and textures while adding color
39
+ - Ensure color harmony and balance throughout image
40
+
41
+ ${colorMode === 'realistic' ?
42
+ `REALISTIC COLORIZATION:
43
+ - Use historically accurate colors when appropriate
44
+ - Consider natural lighting conditions
45
+ - Apply realistic skin tones and environmental colors
46
+ - Maintain photographic authenticity` :
47
+ colorMode === 'vibrant' ?
48
+ `VIBRANT COLORIZATION:
49
+ - Use rich, saturated colors for visual impact
50
+ - Create bold color contrasts and relationships
51
+ - Apply artistic color interpretations
52
+ - Enhance visual interest and appeal` :
53
+ colorMode === 'artistic' ?
54
+ `ARTISTIC COLORIZATION:
55
+ - Apply creative color interpretations
56
+ - Use expressive color choices and combinations
57
+ - Create mood and atmosphere through color
58
+ - Allow artistic freedom in color selection` :
59
+ `VINTAGE COLORIZATION:
60
+ - Use period-appropriate color palettes
61
+ - Apply aged, authentic color treatments
62
+ - Maintain historical color sensibilities
63
+ - Create nostalgic, time-appropriate appearance`}
64
+
65
+ TECHNICAL REQUIREMENTS:
66
+ - Preserve edges and details during color application
67
+ - Apply colors smoothly and naturally
68
+ - Consider lighting and shadow relationships
69
+ - Maintain image quality and resolution
70
+
71
+ SAFETY CONSTRAINTS:
72
+ - Do not alter content or composition
73
+ - Preserve important details and features
74
+ - Avoid inappropriate or unrealistic colors
75
+ - Maintain appropriate content standards
76
+
77
+ OUTPUT:
78
+ Beautifully colorized version of the original ${targetType} image,
79
+ with ${colorMode} color treatment that enhances rather than dominates.
80
+ `.trim();
81
+ };
82
+
83
+ export class ColorizationService implements IColorizationService {
84
+ private promptService: PromptGenerationService;
85
+
86
+ constructor() {
87
+ this.promptService = new PromptGenerationService();
88
+ }
89
+
90
+ async generateTemplate(config: ColorizationConfig): Promise<AIPromptResult<AIPromptTemplate>> {
91
+ try {
92
+ if (!this.validateConfig(config)) {
93
+ return {
94
+ success: false,
95
+ error: 'VALIDATION_ERROR',
96
+ message: 'Invalid colorization configuration'
97
+ };
98
+ }
99
+
100
+ const template = this.createColorizationTemplate(config);
101
+ return { success: true, data: template };
102
+ } catch (error) {
103
+ return {
104
+ success: false,
105
+ error: 'GENERATION_FAILED',
106
+ message: 'Failed to generate colorization template'
107
+ };
108
+ }
109
+ }
110
+
111
+ async generatePrompt(
112
+ template: AIPromptTemplate,
113
+ config: ColorizationConfig
114
+ ): Promise<AIPromptResult<string>> {
115
+ const variables = {
116
+ targetType: config.targetType,
117
+ colorMode: config.colorMode,
118
+ preserveOriginal: config.preserveOriginal,
119
+ adjustLighting: config.adjustLighting,
120
+ skinTonePreservation: config.skinTonePreservation,
121
+ era: config.era || '',
122
+ qualityScore: getColorizationQuality(config),
123
+ colorPalette: this.getColorPalette(config),
124
+ };
125
+
126
+ return this.promptService.generateFromTemplate(template, variables);
127
+ }
128
+
129
+ validateConfig(config: ColorizationConfig): boolean {
130
+ return validateColorizationConfig(config);
131
+ }
132
+
133
+ getColorPalette(config: ColorizationConfig): string[] {
134
+ return getSuggestedColorPalette(config.targetType, config.colorMode);
135
+ }
136
+
137
+ getQualityScore(config: ColorizationConfig): number {
138
+ return getColorizationQuality(config);
139
+ }
140
+
141
+ private createColorizationTemplate(config: ColorizationConfig): AIPromptTemplate {
142
+ const templateId = `colorization-${config.targetType}-${config.colorMode}`;
143
+
144
+ const baseTemplate = createColorizationBaseTemplate({
145
+ targetType: config.targetType,
146
+ colorMode: config.colorMode,
147
+ });
148
+
149
+ return createAIPromptTemplate({
150
+ id: templateId,
151
+ name: `Colorization: ${config.targetType} to ${config.colorMode}`,
152
+ description: `Colorize ${config.targetType} images with ${config.colorMode} treatment`,
153
+ category: 'colorization',
154
+ template: `${baseTemplate}
155
+
156
+ COLORIZATION CONFIGURATION:
157
+ - Target Type: ${config.targetType}
158
+ - Color Mode: ${config.colorMode}
159
+ - Preserve Original: ${config.preserveOriginal}
160
+ - Adjust Lighting: ${config.adjustLighting}
161
+ - Skin Tone Preservation: ${config.skinTonePreservation}
162
+ ${config.era ? `- Era: ${config.era}` : ''}
163
+
164
+ COLOR REQUIREMENTS:
165
+ ${this.getColorRequirements(config)}
166
+
167
+ ${config.era ? `ERA-SPECIFIC GUIDELINES:
168
+ ${getEraDescription(config.era)}
169
+
170
+ ` : ''}QUALITY EXPECTATIONS:
171
+ - Quality Score: ${Math.round(getColorizationQuality(config) * 100)}%
172
+ - Color Mode: ${config.colorMode} treatment applied
173
+ - Preserved Elements: ${config.preserveOriginal ? 'Original content preserved' : 'Enhanced interpretation'}
174
+ - Skin Handling: ${config.skinTonePreservation ? 'Natural tones preserved' : 'Artistic interpretation allowed'}
175
+
176
+ ${this.getColorPalette(config).length > 0 ? `
177
+ SUGGESTED COLOR PALETTE:
178
+ ${this.getColorPalette(config).join(', ')}
179
+
180
+ ` : ''}EXPECTED RESULT:
181
+ Professionally colorized ${config.targetType} image,
182
+ with ${config.colorMode} color treatment,
183
+ ${config.skinTonePreservation ? 'maintaining natural appearance' : 'allowing artistic interpretation'}.
184
+ `.trim(),
185
+ variables: [],
186
+ safety: {
187
+ contentFilter: true,
188
+ adultContentFilter: true,
189
+ violenceFilter: true,
190
+ hateSpeechFilter: true,
191
+ copyrightFilter: true,
192
+ },
193
+ version: '1.0.0',
194
+ });
195
+ }
196
+
197
+ private getColorRequirements(config: ColorizationConfig): string {
198
+ const requirements: string[] = [];
199
+
200
+ if (config.targetType === 'black-and-white') {
201
+ requirements.push('- Add natural colors to monochrome image');
202
+ requirements.push('- Consider original grayscale values for color mapping');
203
+ }
204
+
205
+ if (config.targetType === 'sepia') {
206
+ requirements.push('- Refresh and enhance sepia-toned image');
207
+ requirements.push('- Maintain vintage character while adding color');
208
+ }
209
+
210
+ if (config.colorMode === 'realistic') {
211
+ requirements.push('- Use historically and naturally accurate colors');
212
+ requirements.push('- Apply appropriate skin tones and environmental colors');
213
+ }
214
+
215
+ if (config.colorMode === 'vibrant') {
216
+ requirements.push('- Use rich, saturated colors for visual impact');
217
+ requirements.push('- Create bold color contrasts and relationships');
218
+ }
219
+
220
+ if (config.adjustLighting) {
221
+ requirements.push('- Adjust colors for optimal lighting conditions');
222
+ requirements.push('- Ensure appropriate contrast and brightness');
223
+ }
224
+
225
+ if (config.skinTonePreservation) {
226
+ requirements.push('- Maintain natural, appropriate skin tones');
227
+ requirements.push('- Avoid unrealistic or inappropriate skin colors');
228
+ }
229
+
230
+ return requirements.join('\n') || '- Apply appropriate color treatment based on configuration';
231
+ }
232
+ }