@umituz/react-native-ai-generation-content 1.17.147 → 1.17.148

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 (29) hide show
  1. package/package.json +1 -1
  2. package/src/features/face-swap/domain/types/face-swap.types.ts +13 -41
  3. package/src/features/face-swap/domain/types/index.ts +0 -1
  4. package/src/features/face-swap/index.ts +1 -5
  5. package/src/features/face-swap/presentation/hooks/index.ts +1 -4
  6. package/src/features/face-swap/presentation/hooks/useFaceSwapFeature.ts +17 -121
  7. package/src/features/image-to-image/domain/index.ts +1 -0
  8. package/src/features/image-to-image/domain/types/base.types.ts +189 -0
  9. package/src/features/image-to-image/domain/types/index.ts +1 -0
  10. package/src/features/image-to-image/index.ts +2 -0
  11. package/src/features/image-to-image/presentation/hooks/index.ts +3 -0
  12. package/src/features/image-to-image/presentation/hooks/useDualImageFeature.ts +154 -0
  13. package/src/features/image-to-image/presentation/hooks/useImageWithPromptFeature.ts +180 -0
  14. package/src/features/image-to-image/presentation/hooks/useSingleImageFeature.ts +132 -0
  15. package/src/features/image-to-image/presentation/index.ts +1 -0
  16. package/src/features/remove-background/domain/types/index.ts +0 -1
  17. package/src/features/remove-background/domain/types/remove-background.types.ts +14 -40
  18. package/src/features/remove-background/index.ts +1 -5
  19. package/src/features/remove-background/presentation/hooks/index.ts +1 -4
  20. package/src/features/remove-background/presentation/hooks/useRemoveBackgroundFeature.ts +15 -100
  21. package/src/features/replace-background/domain/types/index.ts +1 -2
  22. package/src/features/replace-background/domain/types/replace-background.types.ts +14 -39
  23. package/src/features/replace-background/index.ts +0 -1
  24. package/src/features/replace-background/presentation/hooks/useReplaceBackgroundFeature.ts +30 -118
  25. package/src/features/upscaling/domain/types/upscale.types.ts +12 -42
  26. package/src/features/upscaling/index.ts +1 -5
  27. package/src/features/upscaling/presentation/hooks/index.ts +1 -4
  28. package/src/features/upscaling/presentation/hooks/useUpscaleFeature.ts +15 -106
  29. package/src/index.ts +6 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-generation-content",
3
- "version": "1.17.147",
3
+ "version": "1.17.148",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,8 +1,15 @@
1
1
  /**
2
2
  * Face Swap Feature Types
3
- * Request, Result, Config types for face swap generation
3
+ * Extends base image-to-image types for dual image processing
4
4
  */
5
5
 
6
+ import type {
7
+ BaseImageResult,
8
+ BaseDualImageState,
9
+ BaseDualImageTranslations,
10
+ DualImageConfig,
11
+ } from "../../../image-to-image/domain/types";
12
+
6
13
  export interface FaceSwapOptions {
7
14
  enhanceFace?: boolean;
8
15
  preserveSkinTone?: boolean;
@@ -17,47 +24,12 @@ export interface FaceSwapRequest {
17
24
  options?: FaceSwapOptions;
18
25
  }
19
26
 
20
- export interface FaceSwapResult {
21
- success: boolean;
22
- imageUrl?: string;
23
- imageBase64?: string;
24
- error?: string;
25
- requestId?: string;
26
- }
27
+ export type FaceSwapResult = BaseImageResult;
27
28
 
28
- export interface FaceSwapFeatureState {
29
- sourceImageUri: string | null;
30
- targetImageUri: string | null;
31
- processedUrl: string | null;
32
- isProcessing: boolean;
33
- progress: number;
34
- error: string | null;
35
- }
36
-
37
- export interface FaceSwapTranslations {
38
- sourceUploadTitle: string;
39
- sourceUploadSubtitle: string;
40
- targetUploadTitle: string;
41
- targetUploadSubtitle: string;
42
- uploadChange: string;
43
- uploadAnalyzing: string;
44
- description: string;
45
- processingText: string;
46
- processButtonText: string;
47
- successText: string;
48
- saveButtonText: string;
49
- tryAnotherText: string;
50
- }
29
+ export type FaceSwapFeatureState = BaseDualImageState;
51
30
 
52
- export type FaceSwapResultExtractor = (result: unknown) => string | undefined;
31
+ export type FaceSwapTranslations = BaseDualImageTranslations;
53
32
 
54
- export interface FaceSwapFeatureConfig {
55
- creditCost?: number;
56
- extractResult?: FaceSwapResultExtractor;
57
- prepareImage: (imageUri: string) => Promise<string>;
58
- onSourceImageSelect?: (uri: string) => void;
59
- onTargetImageSelect?: (uri: string) => void;
60
- onProcessingStart?: () => void;
61
- onProcessingComplete?: (result: FaceSwapResult) => void;
62
- onError?: (error: string) => void;
33
+ export interface FaceSwapFeatureConfig extends DualImageConfig<FaceSwapResult> {
34
+ defaultOptions?: FaceSwapOptions;
63
35
  }
@@ -8,6 +8,5 @@ export type {
8
8
  FaceSwapResult,
9
9
  FaceSwapFeatureState,
10
10
  FaceSwapTranslations,
11
- FaceSwapResultExtractor,
12
11
  FaceSwapFeatureConfig,
13
12
  } from "./face-swap.types";
@@ -11,15 +11,11 @@ export type {
11
11
  FaceSwapFeatureState,
12
12
  FaceSwapTranslations,
13
13
  FaceSwapFeatureConfig,
14
- FaceSwapResultExtractor,
15
14
  } from "./domain";
16
15
 
17
16
  // Presentation Hooks
18
17
  export { useFaceSwapFeature } from "./presentation";
19
- export type {
20
- UseFaceSwapFeatureProps,
21
- UseFaceSwapFeatureReturn,
22
- } from "./presentation";
18
+ export type { UseFaceSwapFeatureProps } from "./presentation";
23
19
 
24
20
  // Presentation Components
25
21
  export { FaceSwapFeature } from "./presentation";
@@ -3,7 +3,4 @@
3
3
  */
4
4
 
5
5
  export { useFaceSwapFeature } from "./useFaceSwapFeature";
6
- export type {
7
- UseFaceSwapFeatureProps,
8
- UseFaceSwapFeatureReturn,
9
- } from "./useFaceSwapFeature";
6
+ export type { UseFaceSwapFeatureProps } from "./useFaceSwapFeature";
@@ -1,15 +1,13 @@
1
1
  /**
2
2
  * useFaceSwapFeature Hook
3
- * Manages face swap feature state and actions
3
+ * Uses base dual image hook for face swap processing
4
4
  */
5
5
 
6
- import { useState, useCallback } from "react";
7
- import { executeImageFeature } from "../../../../infrastructure/services";
8
- import type {
9
- FaceSwapFeatureState,
10
- FaceSwapFeatureConfig,
11
- FaceSwapResult,
12
- } from "../../domain/types";
6
+ import {
7
+ useDualImageFeature,
8
+ type BaseDualImageHookReturn,
9
+ } from "../../../image-to-image";
10
+ import type { FaceSwapFeatureConfig, FaceSwapResult } from "../../domain/types";
13
11
 
14
12
  export interface UseFaceSwapFeatureProps {
15
13
  config: FaceSwapFeatureConfig;
@@ -18,121 +16,19 @@ export interface UseFaceSwapFeatureProps {
18
16
  onSaveImage: (imageUrl: string) => Promise<void>;
19
17
  }
20
18
 
21
- export interface UseFaceSwapFeatureReturn extends FaceSwapFeatureState {
22
- selectSourceImage: () => Promise<void>;
23
- selectTargetImage: () => Promise<void>;
24
- process: () => Promise<void>;
25
- save: () => Promise<void>;
26
- reset: () => void;
27
- }
28
-
29
- const initialState: FaceSwapFeatureState = {
30
- sourceImageUri: null,
31
- targetImageUri: null,
32
- processedUrl: null,
33
- isProcessing: false,
34
- progress: 0,
35
- error: null,
36
- };
37
-
38
19
  export function useFaceSwapFeature(
39
20
  props: UseFaceSwapFeatureProps,
40
- ): UseFaceSwapFeatureReturn {
21
+ ): BaseDualImageHookReturn {
41
22
  const { config, onSelectSourceImage, onSelectTargetImage, onSaveImage } = props;
42
- const [state, setState] = useState<FaceSwapFeatureState>(initialState);
43
-
44
- const selectSourceImage = useCallback(async () => {
45
- try {
46
- const uri = await onSelectSourceImage();
47
- if (uri) {
48
- setState((prev) => ({ ...prev, sourceImageUri: uri, error: null }));
49
- config.onSourceImageSelect?.(uri);
50
- }
51
- } catch (error) {
52
- const message = error instanceof Error ? error.message : String(error);
53
- setState((prev) => ({ ...prev, error: message }));
54
- }
55
- }, [onSelectSourceImage, config]);
56
-
57
- const selectTargetImage = useCallback(async () => {
58
- try {
59
- const uri = await onSelectTargetImage();
60
- if (uri) {
61
- setState((prev) => ({ ...prev, targetImageUri: uri, error: null }));
62
- config.onTargetImageSelect?.(uri);
63
- }
64
- } catch (error) {
65
- const message = error instanceof Error ? error.message : String(error);
66
- setState((prev) => ({ ...prev, error: message }));
67
- }
68
- }, [onSelectTargetImage, config]);
69
-
70
- const handleProgress = useCallback((progress: number) => {
71
- setState((prev) => ({ ...prev, progress }));
72
- }, []);
73
-
74
- const process = useCallback(async () => {
75
- if (!state.sourceImageUri || !state.targetImageUri) return;
76
-
77
- setState((prev) => ({
78
- ...prev,
79
- isProcessing: true,
80
- progress: 0,
81
- error: null,
82
- }));
83
-
84
- config.onProcessingStart?.();
85
-
86
- const sourceImageBase64 = await config.prepareImage(state.sourceImageUri);
87
- const targetImageBase64 = await config.prepareImage(state.targetImageUri);
88
-
89
- const result = await executeImageFeature(
90
- "face-swap",
91
- { imageBase64: sourceImageBase64, targetImageBase64 },
92
- { extractResult: config.extractResult, onProgress: handleProgress },
93
- );
94
-
95
- if (result.success && result.imageUrl) {
96
- setState((prev) => ({
97
- ...prev,
98
- isProcessing: false,
99
- processedUrl: result.imageUrl!,
100
- progress: 100,
101
- }));
102
- config.onProcessingComplete?.(result as FaceSwapResult);
103
- } else {
104
- const errorMessage = result.error || "Processing failed";
105
- setState((prev) => ({
106
- ...prev,
107
- isProcessing: false,
108
- error: errorMessage,
109
- progress: 0,
110
- }));
111
- config.onError?.(errorMessage);
112
- }
113
- }, [state.sourceImageUri, state.targetImageUri, config, handleProgress]);
114
-
115
- const save = useCallback(async () => {
116
- if (!state.processedUrl) return;
117
-
118
- try {
119
- await onSaveImage(state.processedUrl);
120
- } catch (error) {
121
- const message = error instanceof Error ? error.message : String(error);
122
- setState((prev) => ({ ...prev, error: message }));
123
- }
124
- }, [state.processedUrl, onSaveImage]);
125
-
126
- const reset = useCallback(() => {
127
- setState(initialState);
128
- }, []);
129
23
 
130
- return {
131
- ...state,
132
- selectSourceImage,
133
- selectTargetImage,
134
- process,
135
- save,
136
- reset,
137
- };
24
+ return useDualImageFeature<FaceSwapFeatureConfig, FaceSwapResult>(
25
+ { config, onSelectSourceImage, onSelectTargetImage, onSaveImage },
26
+ {
27
+ buildInput: (sourceBase64, targetBase64, cfg) => ({
28
+ imageBase64: sourceBase64,
29
+ targetImageBase64: targetBase64,
30
+ options: cfg.defaultOptions,
31
+ }),
32
+ },
33
+ );
138
34
  }
@@ -0,0 +1 @@
1
+ export * from "./types";
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Base Image-to-Image Types
3
+ * Common types for all image processing features
4
+ */
5
+
6
+ import type { ImageFeatureType } from "../../../../domain/interfaces";
7
+
8
+ /**
9
+ * Image processing categories
10
+ */
11
+ export type ImageProcessingCategory =
12
+ | "enhancement"
13
+ | "editing"
14
+ | "transformation"
15
+ | "composition";
16
+
17
+ /**
18
+ * Input mode for image processing
19
+ */
20
+ export type ImageInputMode = "single" | "single-with-prompt" | "dual";
21
+
22
+ /**
23
+ * Base result for all image processing features
24
+ */
25
+ export interface BaseImageResult {
26
+ success: boolean;
27
+ imageUrl?: string;
28
+ imageBase64?: string;
29
+ error?: string;
30
+ requestId?: string;
31
+ }
32
+
33
+ /**
34
+ * Base state for single image features
35
+ */
36
+ export interface BaseSingleImageState {
37
+ imageUri: string | null;
38
+ processedUrl: string | null;
39
+ isProcessing: boolean;
40
+ progress: number;
41
+ error: string | null;
42
+ }
43
+
44
+ /**
45
+ * Base state for single image + prompt features
46
+ */
47
+ export interface BaseImageWithPromptState extends BaseSingleImageState {
48
+ prompt: string;
49
+ }
50
+
51
+ /**
52
+ * Base state for dual image features
53
+ */
54
+ export interface BaseDualImageState {
55
+ sourceImageUri: string | null;
56
+ targetImageUri: string | null;
57
+ processedUrl: string | null;
58
+ isProcessing: boolean;
59
+ progress: number;
60
+ error: string | null;
61
+ }
62
+
63
+ /**
64
+ * Base translations for image features
65
+ */
66
+ export interface BaseImageTranslations {
67
+ uploadTitle: string;
68
+ uploadSubtitle: string;
69
+ uploadChange: string;
70
+ uploadAnalyzing: string;
71
+ description: string;
72
+ processingText: string;
73
+ processButtonText: string;
74
+ successText: string;
75
+ saveButtonText: string;
76
+ tryAnotherText: string;
77
+ beforeLabel?: string;
78
+ afterLabel?: string;
79
+ compareHint?: string;
80
+ }
81
+
82
+ /**
83
+ * Base translations for dual image features
84
+ */
85
+ export interface BaseDualImageTranslations {
86
+ sourceUploadTitle: string;
87
+ sourceUploadSubtitle: string;
88
+ targetUploadTitle: string;
89
+ targetUploadSubtitle: string;
90
+ uploadChange: string;
91
+ uploadAnalyzing: string;
92
+ description: string;
93
+ processingText: string;
94
+ processButtonText: string;
95
+ successText: string;
96
+ saveButtonText: string;
97
+ tryAnotherText: string;
98
+ }
99
+
100
+ /**
101
+ * Result extractor function type
102
+ */
103
+ export type ImageResultExtractor = (result: unknown) => string | undefined;
104
+
105
+ /**
106
+ * Base config for all image features
107
+ */
108
+ export interface BaseImageConfig<TResult extends BaseImageResult = BaseImageResult> {
109
+ featureType: ImageFeatureType;
110
+ creditCost?: number;
111
+ extractResult?: ImageResultExtractor;
112
+ prepareImage: (imageUri: string) => Promise<string>;
113
+ onProcessingStart?: () => void;
114
+ onProcessingComplete?: (result: TResult) => void;
115
+ onError?: (error: string) => void;
116
+ }
117
+
118
+ /**
119
+ * Config for single image features
120
+ */
121
+ export interface SingleImageConfig<TResult extends BaseImageResult = BaseImageResult>
122
+ extends BaseImageConfig<TResult> {
123
+ onImageSelect?: (uri: string) => void;
124
+ }
125
+
126
+ /**
127
+ * Config for dual image features
128
+ */
129
+ export interface DualImageConfig<TResult extends BaseImageResult = BaseImageResult>
130
+ extends BaseImageConfig<TResult> {
131
+ onSourceImageSelect?: (uri: string) => void;
132
+ onTargetImageSelect?: (uri: string) => void;
133
+ }
134
+
135
+ /**
136
+ * Base hook props for single image features
137
+ */
138
+ export interface BaseSingleImageHookProps<
139
+ TConfig extends SingleImageConfig = SingleImageConfig,
140
+ > {
141
+ config: TConfig;
142
+ onSelectImage: () => Promise<string | null>;
143
+ onSaveImage: (imageUrl: string) => Promise<void>;
144
+ }
145
+
146
+ /**
147
+ * Base hook props for dual image features
148
+ */
149
+ export interface BaseDualImageHookProps<
150
+ TConfig extends DualImageConfig = DualImageConfig,
151
+ > {
152
+ config: TConfig;
153
+ onSelectSourceImage: () => Promise<string | null>;
154
+ onSelectTargetImage: () => Promise<string | null>;
155
+ onSaveImage: (imageUrl: string) => Promise<void>;
156
+ }
157
+
158
+ /**
159
+ * Base hook return for single image features
160
+ */
161
+ export interface BaseSingleImageHookReturn extends BaseSingleImageState {
162
+ selectImage: () => Promise<void>;
163
+ process: () => Promise<void>;
164
+ save: () => Promise<void>;
165
+ reset: () => void;
166
+ }
167
+
168
+ /**
169
+ * Base hook return for dual image features
170
+ */
171
+ export interface BaseDualImageHookReturn extends BaseDualImageState {
172
+ selectSourceImage: () => Promise<void>;
173
+ selectTargetImage: () => Promise<void>;
174
+ process: () => Promise<void>;
175
+ save: () => Promise<void>;
176
+ reset: () => void;
177
+ }
178
+
179
+ /**
180
+ * Feature metadata for categorization
181
+ */
182
+ export interface ImageFeatureMetadata {
183
+ name: string;
184
+ category: ImageProcessingCategory;
185
+ inputMode: ImageInputMode;
186
+ featureType: ImageFeatureType;
187
+ requiresPrompt?: boolean;
188
+ requiresMask?: boolean;
189
+ }
@@ -0,0 +1 @@
1
+ export * from "./base.types";
@@ -0,0 +1,2 @@
1
+ export * from "./domain";
2
+ export * from "./presentation";
@@ -0,0 +1,3 @@
1
+ export * from "./useSingleImageFeature";
2
+ export * from "./useDualImageFeature";
3
+ export * from "./useImageWithPromptFeature";
@@ -0,0 +1,154 @@
1
+ /**
2
+ * useDualImageFeature Hook Factory
3
+ * Base hook for dual image processing features (e.g., face-swap)
4
+ */
5
+
6
+ import { useState, useCallback } from "react";
7
+ import { executeImageFeature } from "../../../../infrastructure/services";
8
+ import type {
9
+ BaseDualImageState,
10
+ BaseDualImageHookProps,
11
+ BaseDualImageHookReturn,
12
+ DualImageConfig,
13
+ BaseImageResult,
14
+ } from "../../domain/types";
15
+
16
+ const INITIAL_STATE: BaseDualImageState = {
17
+ sourceImageUri: null,
18
+ targetImageUri: null,
19
+ processedUrl: null,
20
+ isProcessing: false,
21
+ progress: 0,
22
+ error: null,
23
+ };
24
+
25
+ export interface DualImageFeatureOptions<TConfig extends DualImageConfig> {
26
+ buildInput?: (
27
+ sourceBase64: string,
28
+ targetBase64: string,
29
+ config: TConfig,
30
+ ) => Record<string, unknown>;
31
+ }
32
+
33
+ export function useDualImageFeature<
34
+ TConfig extends DualImageConfig = DualImageConfig,
35
+ TResult extends BaseImageResult = BaseImageResult,
36
+ >(
37
+ props: BaseDualImageHookProps<TConfig>,
38
+ options?: DualImageFeatureOptions<TConfig>,
39
+ ): BaseDualImageHookReturn {
40
+ const { config, onSelectSourceImage, onSelectTargetImage, onSaveImage } = props;
41
+ const [state, setState] = useState<BaseDualImageState>(INITIAL_STATE);
42
+
43
+ const selectSourceImage = useCallback(async () => {
44
+ try {
45
+ const uri = await onSelectSourceImage();
46
+ if (uri) {
47
+ setState((prev) => ({ ...prev, sourceImageUri: uri, error: null }));
48
+ config.onSourceImageSelect?.(uri);
49
+ }
50
+ } catch (error) {
51
+ const message = error instanceof Error ? error.message : String(error);
52
+ setState((prev) => ({ ...prev, error: message }));
53
+ }
54
+ }, [onSelectSourceImage, config]);
55
+
56
+ const selectTargetImage = useCallback(async () => {
57
+ try {
58
+ const uri = await onSelectTargetImage();
59
+ if (uri) {
60
+ setState((prev) => ({ ...prev, targetImageUri: uri, error: null }));
61
+ config.onTargetImageSelect?.(uri);
62
+ }
63
+ } catch (error) {
64
+ const message = error instanceof Error ? error.message : String(error);
65
+ setState((prev) => ({ ...prev, error: message }));
66
+ }
67
+ }, [onSelectTargetImage, config]);
68
+
69
+ const handleProgress = useCallback((progress: number) => {
70
+ setState((prev) => ({ ...prev, progress }));
71
+ }, []);
72
+
73
+ const process = useCallback(async () => {
74
+ if (!state.sourceImageUri || !state.targetImageUri) return;
75
+
76
+ setState((prev) => ({
77
+ ...prev,
78
+ isProcessing: true,
79
+ progress: 0,
80
+ error: null,
81
+ }));
82
+
83
+ config.onProcessingStart?.();
84
+
85
+ try {
86
+ const [sourceBase64, targetBase64] = await Promise.all([
87
+ config.prepareImage(state.sourceImageUri),
88
+ config.prepareImage(state.targetImageUri),
89
+ ]);
90
+
91
+ const input = options?.buildInput
92
+ ? options.buildInput(sourceBase64, targetBase64, config)
93
+ : { sourceImageBase64: sourceBase64, targetImageBase64: targetBase64 };
94
+
95
+ const result = await executeImageFeature(
96
+ config.featureType,
97
+ input,
98
+ { extractResult: config.extractResult, onProgress: handleProgress },
99
+ );
100
+
101
+ if (result.success && result.imageUrl) {
102
+ setState((prev) => ({
103
+ ...prev,
104
+ isProcessing: false,
105
+ processedUrl: result.imageUrl!,
106
+ progress: 100,
107
+ }));
108
+ config.onProcessingComplete?.(result as TResult);
109
+ } else {
110
+ const errorMessage = result.error || "Processing failed";
111
+ setState((prev) => ({
112
+ ...prev,
113
+ isProcessing: false,
114
+ error: errorMessage,
115
+ progress: 0,
116
+ }));
117
+ config.onError?.(errorMessage);
118
+ }
119
+ } catch (error) {
120
+ const message = error instanceof Error ? error.message : String(error);
121
+ setState((prev) => ({
122
+ ...prev,
123
+ isProcessing: false,
124
+ error: message,
125
+ progress: 0,
126
+ }));
127
+ config.onError?.(message);
128
+ }
129
+ }, [state.sourceImageUri, state.targetImageUri, config, options, handleProgress]);
130
+
131
+ const save = useCallback(async () => {
132
+ if (!state.processedUrl) return;
133
+
134
+ try {
135
+ await onSaveImage(state.processedUrl);
136
+ } catch (error) {
137
+ const message = error instanceof Error ? error.message : String(error);
138
+ setState((prev) => ({ ...prev, error: message }));
139
+ }
140
+ }, [state.processedUrl, onSaveImage]);
141
+
142
+ const reset = useCallback(() => {
143
+ setState(INITIAL_STATE);
144
+ }, []);
145
+
146
+ return {
147
+ ...state,
148
+ selectSourceImage,
149
+ selectTargetImage,
150
+ process,
151
+ save,
152
+ reset,
153
+ };
154
+ }