@umituz/react-native-ai-generation-content 1.17.24 → 1.17.25
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/package.json +1 -1
- package/src/domain/interfaces/ai-provider.interface.ts +66 -0
- package/src/features/ai-hug/domain/types/ai-hug.types.ts +4 -13
- package/src/features/ai-hug/domain/types/index.ts +0 -1
- package/src/features/ai-hug/index.ts +1 -6
- package/src/features/ai-hug/presentation/components/AIHugFeature.tsx +14 -22
- package/src/features/ai-hug/presentation/hooks/useAIHugFeature.ts +16 -35
- package/src/features/ai-kiss/domain/types/ai-kiss.types.ts +4 -13
- package/src/features/ai-kiss/domain/types/index.ts +0 -1
- package/src/features/ai-kiss/index.ts +1 -6
- package/src/features/ai-kiss/presentation/components/AIKissFeature.tsx +13 -20
- package/src/features/ai-kiss/presentation/hooks/useAIKissFeature.ts +16 -35
- package/src/features/anime-selfie/domain/types/anime-selfie.types.ts +0 -8
- package/src/features/anime-selfie/domain/types/index.ts +0 -1
- package/src/features/anime-selfie/index.ts +0 -5
- package/src/features/anime-selfie/presentation/components/AnimeSelfieFeature.tsx +0 -3
- package/src/features/anime-selfie/presentation/hooks/useAnimeSelfieFeature.ts +9 -27
- package/src/features/face-swap/domain/types/face-swap.types.ts +0 -9
- package/src/features/face-swap/domain/types/index.ts +0 -1
- package/src/features/face-swap/index.ts +0 -5
- package/src/features/face-swap/presentation/components/FaceSwapFeature.tsx +0 -3
- package/src/features/face-swap/presentation/hooks/useFaceSwapFeature.ts +9 -28
- package/src/features/hd-touch-up/domain/types/hd-touch-up.types.ts +0 -8
- package/src/features/hd-touch-up/domain/types/index.ts +0 -1
- package/src/features/hd-touch-up/index.ts +0 -5
- package/src/features/hd-touch-up/presentation/components/HDTouchUpFeature.tsx +0 -3
- package/src/features/hd-touch-up/presentation/hooks/useHDTouchUpFeature.ts +9 -26
- package/src/features/photo-restoration/domain/types/index.ts +0 -1
- package/src/features/photo-restoration/domain/types/photo-restore.types.ts +0 -8
- package/src/features/photo-restoration/index.ts +0 -5
- package/src/features/photo-restoration/presentation/components/PhotoRestoreFeature.tsx +0 -4
- package/src/features/photo-restoration/presentation/hooks/usePhotoRestoreFeature.ts +9 -26
- package/src/features/remove-background/domain/types/index.ts +0 -1
- package/src/features/remove-background/domain/types/remove-background.types.ts +0 -8
- package/src/features/remove-background/index.ts +0 -5
- package/src/features/remove-background/presentation/components/RemoveBackgroundFeature.tsx +0 -3
- package/src/features/remove-background/presentation/hooks/useRemoveBackgroundFeature.ts +9 -26
- package/src/features/remove-object/domain/types/index.ts +0 -1
- package/src/features/remove-object/domain/types/remove-object.types.ts +0 -8
- package/src/features/remove-object/index.ts +0 -5
- package/src/features/remove-object/presentation/components/RemoveObjectFeature.tsx +0 -3
- package/src/features/remove-object/presentation/hooks/useRemoveObjectFeature.ts +9 -24
- package/src/features/replace-background/domain/types/index.ts +0 -1
- package/src/features/replace-background/domain/types/replace-background.types.ts +0 -9
- package/src/features/replace-background/index.ts +55 -82
- package/src/features/replace-background/infrastructure/constants/prompts.constants.ts +6 -6
- package/src/features/replace-background/infrastructure/index.ts +2 -2
- package/src/features/replace-background/presentation/components/ReplaceBackgroundFeature.tsx +0 -3
- package/src/features/replace-background/presentation/hooks/useReplaceBackgroundFeature.ts +8 -23
- package/src/features/upscaling/domain/types/upscale.types.ts +0 -8
- package/src/features/upscaling/index.ts +0 -5
- package/src/features/upscaling/presentation/components/UpscaleFeature.tsx +0 -4
- package/src/features/upscaling/presentation/hooks/useUpscaleFeature.ts +8 -23
- package/src/index.ts +4 -0
- package/src/infrastructure/services/image-feature-executor.service.ts +143 -0
- package/src/infrastructure/services/index.ts +20 -0
- package/src/infrastructure/services/video-feature-executor.service.ts +140 -0
- package/src/features/ai-hug/infrastructure/index.ts +0 -5
- package/src/features/ai-hug/infrastructure/services/ai-hug-executor.ts +0 -96
- package/src/features/ai-hug/infrastructure/services/index.ts +0 -6
- package/src/features/ai-kiss/infrastructure/index.ts +0 -5
- package/src/features/ai-kiss/infrastructure/services/ai-kiss-executor.ts +0 -96
- package/src/features/ai-kiss/infrastructure/services/index.ts +0 -6
- package/src/features/anime-selfie/infrastructure/index.ts +0 -5
- package/src/features/anime-selfie/infrastructure/services/anime-selfie-executor.ts +0 -95
- package/src/features/anime-selfie/infrastructure/services/index.ts +0 -6
- package/src/features/face-swap/infrastructure/index.ts +0 -5
- package/src/features/face-swap/infrastructure/services/face-swap-executor.ts +0 -96
- package/src/features/face-swap/infrastructure/services/index.ts +0 -6
- package/src/features/hd-touch-up/infrastructure/index.ts +0 -1
- package/src/features/hd-touch-up/infrastructure/services/hd-touch-up-executor.ts +0 -97
- package/src/features/hd-touch-up/infrastructure/services/index.ts +0 -2
- package/src/features/photo-restoration/infrastructure/index.ts +0 -1
- package/src/features/photo-restoration/infrastructure/services/index.ts +0 -2
- package/src/features/photo-restoration/infrastructure/services/photo-restore-executor.ts +0 -98
- package/src/features/remove-background/infrastructure/index.ts +0 -5
- package/src/features/remove-background/infrastructure/services/index.ts +0 -6
- package/src/features/remove-background/infrastructure/services/remove-background-executor.ts +0 -95
- package/src/features/remove-object/infrastructure/index.ts +0 -5
- package/src/features/remove-object/infrastructure/services/index.ts +0 -6
- package/src/features/remove-object/infrastructure/services/remove-object-executor.ts +0 -99
- package/src/features/replace-background/infrastructure/services/index.ts +0 -6
- package/src/features/replace-background/infrastructure/services/replace-background-executor.ts +0 -95
- package/src/features/upscaling/infrastructure/index.ts +0 -1
- package/src/features/upscaling/infrastructure/services/index.ts +0 -2
- package/src/features/upscaling/infrastructure/services/upscale-executor.ts +0 -98
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useState, useCallback } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { executeImageFeature } from "../../../../infrastructure/services";
|
|
8
8
|
import type {
|
|
9
9
|
RemoveBackgroundFeatureState,
|
|
10
10
|
RemoveBackgroundFeatureConfig,
|
|
11
11
|
RemoveBackgroundResult,
|
|
12
12
|
} from "../../domain/types";
|
|
13
13
|
|
|
14
|
-
declare const __DEV__: boolean;
|
|
15
|
-
|
|
16
14
|
export interface UseRemoveBackgroundFeatureProps {
|
|
17
15
|
config: RemoveBackgroundFeatureConfig;
|
|
18
|
-
userId: string;
|
|
19
16
|
onSelectImage: () => Promise<string | null>;
|
|
20
17
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
21
18
|
}
|
|
@@ -38,7 +35,7 @@ const initialState: RemoveBackgroundFeatureState = {
|
|
|
38
35
|
export function useRemoveBackgroundFeature(
|
|
39
36
|
props: UseRemoveBackgroundFeatureProps,
|
|
40
37
|
): UseRemoveBackgroundFeatureReturn {
|
|
41
|
-
const { config,
|
|
38
|
+
const { config, onSelectImage, onSaveImage } = props;
|
|
42
39
|
const [state, setState] = useState<RemoveBackgroundFeatureState>(initialState);
|
|
43
40
|
|
|
44
41
|
const selectImage = useCallback(async () => {
|
|
@@ -70,36 +67,22 @@ export function useRemoveBackgroundFeature(
|
|
|
70
67
|
|
|
71
68
|
config.onProcessingStart?.();
|
|
72
69
|
|
|
73
|
-
if (__DEV__) {
|
|
74
|
-
// eslint-disable-next-line no-console
|
|
75
|
-
console.log("[useRemoveBackgroundFeature] Starting background removal process");
|
|
76
|
-
}
|
|
77
|
-
|
|
78
70
|
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
79
71
|
|
|
80
|
-
const result
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
userId,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
model: config.model,
|
|
88
|
-
buildInput: config.buildInput,
|
|
89
|
-
extractResult: config.extractResult,
|
|
90
|
-
onProgress: handleProgress,
|
|
91
|
-
},
|
|
72
|
+
const result = await executeImageFeature(
|
|
73
|
+
"remove-background",
|
|
74
|
+
{ imageBase64 },
|
|
75
|
+
{ extractResult: config.extractResult, onProgress: handleProgress },
|
|
92
76
|
);
|
|
93
77
|
|
|
94
78
|
if (result.success && result.imageUrl) {
|
|
95
|
-
const url = result.imageUrl;
|
|
96
79
|
setState((prev) => ({
|
|
97
80
|
...prev,
|
|
98
81
|
isProcessing: false,
|
|
99
|
-
processedUrl:
|
|
82
|
+
processedUrl: result.imageUrl!,
|
|
100
83
|
progress: 100,
|
|
101
84
|
}));
|
|
102
|
-
config.onProcessingComplete?.(result);
|
|
85
|
+
config.onProcessingComplete?.(result as RemoveBackgroundResult);
|
|
103
86
|
} else {
|
|
104
87
|
const errorMessage = result.error || "Processing failed";
|
|
105
88
|
setState((prev) => ({
|
|
@@ -110,7 +93,7 @@ export function useRemoveBackgroundFeature(
|
|
|
110
93
|
}));
|
|
111
94
|
config.onError?.(errorMessage);
|
|
112
95
|
}
|
|
113
|
-
}, [state.imageUri,
|
|
96
|
+
}, [state.imageUri, config, handleProgress]);
|
|
114
97
|
|
|
115
98
|
const save = useCallback(async () => {
|
|
116
99
|
if (!state.processedUrl) return;
|
|
@@ -55,18 +55,10 @@ export interface RemoveObjectTranslations {
|
|
|
55
55
|
compareHint?: string;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export type RemoveObjectInputBuilder = (
|
|
59
|
-
base64: string,
|
|
60
|
-
options?: RemoveObjectOptions,
|
|
61
|
-
) => Record<string, unknown>;
|
|
62
|
-
|
|
63
58
|
export type RemoveObjectResultExtractor = (result: unknown) => string | undefined;
|
|
64
59
|
|
|
65
60
|
export interface RemoveObjectFeatureConfig {
|
|
66
|
-
providerId?: string;
|
|
67
61
|
creditCost?: number;
|
|
68
|
-
model: string;
|
|
69
|
-
buildInput: RemoveObjectInputBuilder;
|
|
70
62
|
extractResult?: RemoveObjectResultExtractor;
|
|
71
63
|
prepareImage: (imageUri: string) => Promise<string>;
|
|
72
64
|
onImageSelect?: (uri: string) => void;
|
|
@@ -11,14 +11,9 @@ export type {
|
|
|
11
11
|
RemoveObjectFeatureState,
|
|
12
12
|
RemoveObjectTranslations,
|
|
13
13
|
RemoveObjectFeatureConfig,
|
|
14
|
-
RemoveObjectInputBuilder,
|
|
15
14
|
RemoveObjectResultExtractor,
|
|
16
15
|
} from "./domain";
|
|
17
16
|
|
|
18
|
-
// Infrastructure Services
|
|
19
|
-
export { executeRemoveObject, hasRemoveObjectSupport } from "./infrastructure";
|
|
20
|
-
export type { ExecuteRemoveObjectOptions } from "./infrastructure";
|
|
21
|
-
|
|
22
17
|
// Presentation Hooks
|
|
23
18
|
export { useRemoveObjectFeature } from "./presentation";
|
|
24
19
|
export type {
|
|
@@ -21,7 +21,6 @@ import type {
|
|
|
21
21
|
|
|
22
22
|
export interface RemoveObjectFeatureProps {
|
|
23
23
|
config: RemoveObjectFeatureConfig;
|
|
24
|
-
userId: string;
|
|
25
24
|
translations: RemoveObjectTranslations;
|
|
26
25
|
onSelectImage: () => Promise<string | null>;
|
|
27
26
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
@@ -33,7 +32,6 @@ export interface RemoveObjectFeatureProps {
|
|
|
33
32
|
|
|
34
33
|
export const RemoveObjectFeature: React.FC<RemoveObjectFeatureProps> = ({
|
|
35
34
|
config,
|
|
36
|
-
userId,
|
|
37
35
|
translations,
|
|
38
36
|
onSelectImage,
|
|
39
37
|
onSaveImage,
|
|
@@ -42,7 +40,6 @@ export const RemoveObjectFeature: React.FC<RemoveObjectFeatureProps> = ({
|
|
|
42
40
|
const tokens = useAppDesignTokens();
|
|
43
41
|
const feature = useRemoveObjectFeature({
|
|
44
42
|
config,
|
|
45
|
-
userId,
|
|
46
43
|
onSelectImage,
|
|
47
44
|
onSaveImage,
|
|
48
45
|
});
|
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useState, useCallback } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { executeImageFeature } from "../../../../infrastructure/services";
|
|
8
8
|
import type {
|
|
9
9
|
RemoveObjectFeatureState,
|
|
10
10
|
RemoveObjectFeatureConfig,
|
|
11
11
|
RemoveObjectResult,
|
|
12
12
|
} from "../../domain/types";
|
|
13
13
|
|
|
14
|
-
declare const __DEV__: boolean;
|
|
15
|
-
|
|
16
14
|
export interface UseRemoveObjectFeatureProps {
|
|
17
15
|
config: RemoveObjectFeatureConfig;
|
|
18
|
-
userId: string;
|
|
19
16
|
onSelectImage: () => Promise<string | null>;
|
|
20
17
|
onSelectMask?: () => Promise<string | null>;
|
|
21
18
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
@@ -43,7 +40,7 @@ const initialState: RemoveObjectFeatureState = {
|
|
|
43
40
|
export function useRemoveObjectFeature(
|
|
44
41
|
props: UseRemoveObjectFeatureProps,
|
|
45
42
|
): UseRemoveObjectFeatureReturn {
|
|
46
|
-
const { config,
|
|
43
|
+
const { config, onSelectImage, onSelectMask, onSaveImage } = props;
|
|
47
44
|
const [state, setState] = useState<RemoveObjectFeatureState>(initialState);
|
|
48
45
|
|
|
49
46
|
const selectImage = useCallback(async () => {
|
|
@@ -94,41 +91,29 @@ export function useRemoveObjectFeature(
|
|
|
94
91
|
|
|
95
92
|
config.onProcessingStart?.();
|
|
96
93
|
|
|
97
|
-
if (__DEV__) {
|
|
98
|
-
// eslint-disable-next-line no-console
|
|
99
|
-
console.log("[useRemoveObjectFeature] Starting object removal process");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
94
|
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
103
95
|
const maskBase64 = state.maskUri
|
|
104
96
|
? await config.prepareImage(state.maskUri)
|
|
105
97
|
: undefined;
|
|
106
98
|
|
|
107
|
-
const result
|
|
99
|
+
const result = await executeImageFeature(
|
|
100
|
+
"remove-object",
|
|
108
101
|
{
|
|
109
|
-
imageUri: state.imageUri,
|
|
110
102
|
imageBase64,
|
|
111
|
-
maskBase64,
|
|
103
|
+
targetImageBase64: maskBase64,
|
|
112
104
|
prompt: state.prompt || undefined,
|
|
113
|
-
userId,
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
model: config.model,
|
|
117
|
-
buildInput: config.buildInput,
|
|
118
|
-
extractResult: config.extractResult,
|
|
119
|
-
onProgress: handleProgress,
|
|
120
105
|
},
|
|
106
|
+
{ extractResult: config.extractResult, onProgress: handleProgress },
|
|
121
107
|
);
|
|
122
108
|
|
|
123
109
|
if (result.success && result.imageUrl) {
|
|
124
|
-
const url = result.imageUrl;
|
|
125
110
|
setState((prev) => ({
|
|
126
111
|
...prev,
|
|
127
112
|
isProcessing: false,
|
|
128
|
-
processedUrl:
|
|
113
|
+
processedUrl: result.imageUrl!,
|
|
129
114
|
progress: 100,
|
|
130
115
|
}));
|
|
131
|
-
config.onProcessingComplete?.(result);
|
|
116
|
+
config.onProcessingComplete?.(result as RemoveObjectResult);
|
|
132
117
|
} else {
|
|
133
118
|
const errorMessage = result.error || "Processing failed";
|
|
134
119
|
setState((prev) => ({
|
|
@@ -139,7 +124,7 @@ export function useRemoveObjectFeature(
|
|
|
139
124
|
}));
|
|
140
125
|
config.onError?.(errorMessage);
|
|
141
126
|
}
|
|
142
|
-
}, [state.imageUri, state.maskUri, state.prompt,
|
|
127
|
+
}, [state.imageUri, state.maskUri, state.prompt, config, handleProgress]);
|
|
143
128
|
|
|
144
129
|
const save = useCallback(async () => {
|
|
145
130
|
if (!state.processedUrl) return;
|
|
@@ -59,20 +59,11 @@ export interface ReplaceBackgroundTranslations {
|
|
|
59
59
|
compareHint?: string;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
export type ReplaceBackgroundInputBuilder = (
|
|
63
|
-
base64: string,
|
|
64
|
-
prompt?: string,
|
|
65
|
-
options?: ReplaceBackgroundOptions,
|
|
66
|
-
) => Record<string, unknown>;
|
|
67
|
-
|
|
68
62
|
export type ReplaceBackgroundResultExtractor = (result: unknown) => string | undefined;
|
|
69
63
|
|
|
70
64
|
export interface ReplaceBackgroundFeatureConfig {
|
|
71
|
-
providerId?: string;
|
|
72
65
|
creditCost?: number;
|
|
73
66
|
defaultMode?: ReplaceBackgroundMode;
|
|
74
|
-
model: string;
|
|
75
|
-
buildInput: ReplaceBackgroundInputBuilder;
|
|
76
67
|
extractResult?: ReplaceBackgroundResultExtractor;
|
|
77
68
|
prepareImage: (imageUri: string) => Promise<string>;
|
|
78
69
|
onImageSelect?: (uri: string) => void;
|
|
@@ -1,101 +1,74 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Replace Background Feature
|
|
3
3
|
* AI-powered background replacement and removal feature for React Native
|
|
4
|
-
*
|
|
5
|
-
* Usage:
|
|
6
|
-
* import {
|
|
7
|
-
* BackgroundFeature,
|
|
8
|
-
* useBackgroundFeature,
|
|
9
|
-
* useReplaceBackgroundFeature,
|
|
10
|
-
* ImagePicker,
|
|
11
|
-
* ComparisonSlider,
|
|
12
|
-
* ModeSelector,
|
|
13
|
-
* } from '@umituz/react-native-ai-feature-background';
|
|
14
4
|
*/
|
|
15
5
|
|
|
16
|
-
//
|
|
17
|
-
// DOMAIN LAYER - Types & Interfaces (Legacy)
|
|
18
|
-
// =============================================================================
|
|
19
|
-
|
|
6
|
+
// Domain Types - Legacy
|
|
20
7
|
export type {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
8
|
+
BackgroundProcessRequest,
|
|
9
|
+
BackgroundProcessResult,
|
|
10
|
+
BackgroundFeatureState,
|
|
11
|
+
SamplePrompt,
|
|
12
|
+
StudioMode,
|
|
13
|
+
StudioModeConfig,
|
|
14
|
+
ComparisonState,
|
|
15
|
+
ImagePickerProps,
|
|
16
|
+
PromptInputProps,
|
|
17
|
+
GenerateButtonProps,
|
|
18
|
+
ResultDisplayProps,
|
|
19
|
+
ErrorDisplayProps,
|
|
20
|
+
ProcessingModalProps,
|
|
21
|
+
FeatureHeaderProps,
|
|
22
|
+
ModeSelectorProps,
|
|
23
|
+
ComparisonSliderProps,
|
|
24
|
+
ProcessRequestParams,
|
|
25
|
+
BackgroundFeatureConfig,
|
|
26
|
+
UseBackgroundFeatureConfig,
|
|
40
27
|
} from "./domain/entities";
|
|
41
28
|
|
|
42
|
-
//
|
|
43
|
-
// DOMAIN LAYER - New Provider-Agnostic Types
|
|
44
|
-
// =============================================================================
|
|
45
|
-
|
|
29
|
+
// Domain Types - Provider-Agnostic
|
|
46
30
|
export type {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
ReplaceBackgroundResultExtractor,
|
|
31
|
+
ReplaceBackgroundMode,
|
|
32
|
+
ReplaceBackgroundOptions,
|
|
33
|
+
ReplaceBackgroundRequest,
|
|
34
|
+
ReplaceBackgroundResult,
|
|
35
|
+
ReplaceBackgroundFeatureState,
|
|
36
|
+
ReplaceBackgroundTranslations,
|
|
37
|
+
ReplaceBackgroundFeatureConfig,
|
|
38
|
+
ReplaceBackgroundResultExtractor,
|
|
56
39
|
} from "./domain/types";
|
|
57
40
|
|
|
58
|
-
//
|
|
59
|
-
// INFRASTRUCTURE LAYER - Constants
|
|
60
|
-
// =============================================================================
|
|
61
|
-
|
|
41
|
+
// Constants
|
|
62
42
|
export { DEFAULT_SAMPLE_PROMPTS } from "./infrastructure/constants";
|
|
63
43
|
|
|
64
|
-
//
|
|
65
|
-
// INFRASTRUCTURE LAYER - Services
|
|
66
|
-
// =============================================================================
|
|
67
|
-
|
|
68
|
-
export { executeReplaceBackground, hasReplaceBackgroundSupport } from "./infrastructure";
|
|
69
|
-
export type { ExecuteReplaceBackgroundOptions } from "./infrastructure";
|
|
70
|
-
|
|
71
|
-
// =============================================================================
|
|
72
|
-
// PRESENTATION LAYER - Components
|
|
73
|
-
// =============================================================================
|
|
74
|
-
|
|
44
|
+
// Presentation Components
|
|
75
45
|
export {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
46
|
+
BackgroundFeature,
|
|
47
|
+
ReplaceBackgroundFeature,
|
|
48
|
+
ImagePicker,
|
|
49
|
+
PromptInput,
|
|
50
|
+
GenerateButton,
|
|
51
|
+
ResultDisplay,
|
|
52
|
+
ErrorDisplay,
|
|
53
|
+
ProcessingModal,
|
|
54
|
+
FeatureHeader,
|
|
55
|
+
ComparisonSlider,
|
|
56
|
+
ModeSelector,
|
|
87
57
|
} from "./presentation/components";
|
|
88
58
|
|
|
89
|
-
export type {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
// =============================================================================
|
|
59
|
+
export type {
|
|
60
|
+
BackgroundFeatureProps,
|
|
61
|
+
ReplaceBackgroundFeatureProps,
|
|
62
|
+
} from "./presentation/components";
|
|
94
63
|
|
|
95
|
-
|
|
64
|
+
// Presentation Hooks
|
|
65
|
+
export {
|
|
66
|
+
useBackgroundFeature,
|
|
67
|
+
useReplaceBackgroundFeature,
|
|
68
|
+
} from "./presentation/hooks";
|
|
96
69
|
|
|
97
70
|
export type {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
71
|
+
UseBackgroundFeatureReturn,
|
|
72
|
+
UseReplaceBackgroundFeatureProps,
|
|
73
|
+
UseReplaceBackgroundFeatureReturn,
|
|
101
74
|
} from "./presentation/hooks";
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
import type { SamplePrompt } from "../../domain/entities";
|
|
7
7
|
|
|
8
8
|
export const DEFAULT_SAMPLE_PROMPTS: readonly SamplePrompt[] = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
{ id: "beach", text: "Beach sunset with palm trees" },
|
|
10
|
+
{ id: "office", text: "Modern office with city view" },
|
|
11
|
+
{ id: "mountain", text: "Mountain landscape with snow" },
|
|
12
|
+
{ id: "living-room", text: "Cozy living room interior" },
|
|
13
|
+
{ id: "garden", text: "Japanese garden with cherry blossoms" },
|
|
14
|
+
{ id: "cityscape", text: "Futuristic cityscape at night" },
|
|
15
15
|
] as const;
|
package/src/features/replace-background/presentation/components/ReplaceBackgroundFeature.tsx
CHANGED
|
@@ -22,7 +22,6 @@ import type {
|
|
|
22
22
|
|
|
23
23
|
export interface ReplaceBackgroundFeatureProps {
|
|
24
24
|
config: ReplaceBackgroundFeatureConfig;
|
|
25
|
-
userId: string;
|
|
26
25
|
translations: ReplaceBackgroundTranslations;
|
|
27
26
|
onSelectImage: () => Promise<string | null>;
|
|
28
27
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
@@ -34,7 +33,6 @@ export interface ReplaceBackgroundFeatureProps {
|
|
|
34
33
|
|
|
35
34
|
export const ReplaceBackgroundFeature: React.FC<ReplaceBackgroundFeatureProps> = ({
|
|
36
35
|
config,
|
|
37
|
-
userId,
|
|
38
36
|
translations,
|
|
39
37
|
onSelectImage,
|
|
40
38
|
onSaveImage,
|
|
@@ -44,7 +42,6 @@ export const ReplaceBackgroundFeature: React.FC<ReplaceBackgroundFeatureProps> =
|
|
|
44
42
|
|
|
45
43
|
const feature = useReplaceBackgroundFeature({
|
|
46
44
|
config,
|
|
47
|
-
userId,
|
|
48
45
|
onSelectImage,
|
|
49
46
|
onSaveImage,
|
|
50
47
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { useState, useCallback } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { executeImageFeature } from "../../../../infrastructure/services";
|
|
8
8
|
import type {
|
|
9
9
|
ReplaceBackgroundFeatureState,
|
|
10
10
|
ReplaceBackgroundFeatureConfig,
|
|
@@ -12,11 +12,8 @@ import type {
|
|
|
12
12
|
ReplaceBackgroundMode,
|
|
13
13
|
} from "../../domain/types";
|
|
14
14
|
|
|
15
|
-
declare const __DEV__: boolean;
|
|
16
|
-
|
|
17
15
|
export interface UseReplaceBackgroundFeatureProps {
|
|
18
16
|
config: ReplaceBackgroundFeatureConfig;
|
|
19
|
-
userId: string;
|
|
20
17
|
onSelectImage: () => Promise<string | null>;
|
|
21
18
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
22
19
|
}
|
|
@@ -43,7 +40,7 @@ const initialState: ReplaceBackgroundFeatureState = {
|
|
|
43
40
|
export function useReplaceBackgroundFeature(
|
|
44
41
|
props: UseReplaceBackgroundFeatureProps,
|
|
45
42
|
): UseReplaceBackgroundFeatureReturn {
|
|
46
|
-
const { config,
|
|
43
|
+
const { config, onSelectImage, onSaveImage } = props;
|
|
47
44
|
const [state, setState] = useState<ReplaceBackgroundFeatureState>({
|
|
48
45
|
...initialState,
|
|
49
46
|
mode: config.defaultMode || "replace",
|
|
@@ -86,38 +83,26 @@ export function useReplaceBackgroundFeature(
|
|
|
86
83
|
|
|
87
84
|
config.onProcessingStart?.();
|
|
88
85
|
|
|
89
|
-
if (__DEV__) {
|
|
90
|
-
// eslint-disable-next-line no-console
|
|
91
|
-
console.log("[useReplaceBackgroundFeature] Starting background replacement process");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
86
|
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
95
87
|
|
|
96
|
-
const result
|
|
88
|
+
const result = await executeImageFeature(
|
|
89
|
+
"replace-background",
|
|
97
90
|
{
|
|
98
|
-
imageUri: state.imageUri,
|
|
99
91
|
imageBase64,
|
|
100
|
-
userId,
|
|
101
92
|
prompt: state.prompt || undefined,
|
|
102
93
|
options: { mode: state.mode },
|
|
103
94
|
},
|
|
104
|
-
{
|
|
105
|
-
model: config.model,
|
|
106
|
-
buildInput: config.buildInput,
|
|
107
|
-
extractResult: config.extractResult,
|
|
108
|
-
onProgress: handleProgress,
|
|
109
|
-
},
|
|
95
|
+
{ extractResult: config.extractResult, onProgress: handleProgress },
|
|
110
96
|
);
|
|
111
97
|
|
|
112
98
|
if (result.success && result.imageUrl) {
|
|
113
|
-
const url = result.imageUrl;
|
|
114
99
|
setState((prev) => ({
|
|
115
100
|
...prev,
|
|
116
101
|
isProcessing: false,
|
|
117
|
-
processedUrl:
|
|
102
|
+
processedUrl: result.imageUrl!,
|
|
118
103
|
progress: 100,
|
|
119
104
|
}));
|
|
120
|
-
config.onProcessingComplete?.(result);
|
|
105
|
+
config.onProcessingComplete?.(result as ReplaceBackgroundResult);
|
|
121
106
|
} else {
|
|
122
107
|
const errorMessage = result.error || "Processing failed";
|
|
123
108
|
setState((prev) => ({
|
|
@@ -128,7 +113,7 @@ export function useReplaceBackgroundFeature(
|
|
|
128
113
|
}));
|
|
129
114
|
config.onError?.(errorMessage);
|
|
130
115
|
}
|
|
131
|
-
}, [state.imageUri, state.prompt, state.mode,
|
|
116
|
+
}, [state.imageUri, state.prompt, state.mode, config, handleProgress]);
|
|
132
117
|
|
|
133
118
|
const save = useCallback(async () => {
|
|
134
119
|
if (!state.processedUrl) return;
|
|
@@ -49,21 +49,13 @@ export interface UpscaleTranslations {
|
|
|
49
49
|
compareHint?: string;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export type UpscaleInputBuilder = (
|
|
53
|
-
base64: string,
|
|
54
|
-
options?: UpscaleOptions,
|
|
55
|
-
) => Record<string, unknown>;
|
|
56
|
-
|
|
57
52
|
export type UpscaleResultExtractor = (
|
|
58
53
|
result: unknown,
|
|
59
54
|
) => string | undefined;
|
|
60
55
|
|
|
61
56
|
export interface UpscaleFeatureConfig {
|
|
62
|
-
providerId?: string;
|
|
63
57
|
defaultScaleFactor?: UpscaleScaleFactor;
|
|
64
58
|
creditCost?: number;
|
|
65
|
-
model: string;
|
|
66
|
-
buildInput: UpscaleInputBuilder;
|
|
67
59
|
extractResult?: UpscaleResultExtractor;
|
|
68
60
|
prepareImage: (imageUri: string) => Promise<string>;
|
|
69
61
|
onImageSelect?: (uri: string) => void;
|
|
@@ -12,14 +12,9 @@ export type {
|
|
|
12
12
|
UpscaleFeatureState,
|
|
13
13
|
UpscaleTranslations,
|
|
14
14
|
UpscaleFeatureConfig,
|
|
15
|
-
UpscaleInputBuilder,
|
|
16
15
|
UpscaleResultExtractor,
|
|
17
16
|
} from "./domain";
|
|
18
17
|
|
|
19
|
-
// Infrastructure Services
|
|
20
|
-
export { executeUpscale, hasUpscaleSupport } from "./infrastructure";
|
|
21
|
-
export type { ExecuteUpscaleOptions } from "./infrastructure";
|
|
22
|
-
|
|
23
18
|
// Presentation Hooks
|
|
24
19
|
export { useUpscaleFeature } from "./presentation";
|
|
25
20
|
export type {
|
|
@@ -22,8 +22,6 @@ import type {
|
|
|
22
22
|
export interface UpscaleFeatureProps {
|
|
23
23
|
/** Feature configuration with provider-specific settings */
|
|
24
24
|
config: UpscaleFeatureConfig;
|
|
25
|
-
/** User ID for the generation request */
|
|
26
|
-
userId: string;
|
|
27
25
|
/** Translations for all UI text */
|
|
28
26
|
translations: UpscaleTranslations;
|
|
29
27
|
/** Image picker callback */
|
|
@@ -39,7 +37,6 @@ export interface UpscaleFeatureProps {
|
|
|
39
37
|
|
|
40
38
|
export const UpscaleFeature: React.FC<UpscaleFeatureProps> = ({
|
|
41
39
|
config,
|
|
42
|
-
userId,
|
|
43
40
|
translations,
|
|
44
41
|
onSelectImage,
|
|
45
42
|
onSaveImage,
|
|
@@ -49,7 +46,6 @@ export const UpscaleFeature: React.FC<UpscaleFeatureProps> = ({
|
|
|
49
46
|
|
|
50
47
|
const feature = useUpscaleFeature({
|
|
51
48
|
config,
|
|
52
|
-
userId,
|
|
53
49
|
onSelectImage,
|
|
54
50
|
onSaveImage,
|
|
55
51
|
});
|