@umituz/react-native-ai-generation-content 1.17.225 → 1.17.226

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 (30) hide show
  1. package/package.json +1 -1
  2. package/src/features/ai-hug/presentation/components/AIHugFeature.tsx +2 -2
  3. package/src/features/ai-kiss/presentation/components/AIKissFeature.tsx +5 -2
  4. package/src/features/anime-selfie/presentation/components/AnimeSelfieFeature.tsx +7 -3
  5. package/src/features/face-swap/presentation/components/FaceSwapFeature.tsx +7 -3
  6. package/src/features/hd-touch-up/presentation/components/HDTouchUpFeature.tsx +7 -3
  7. package/src/features/image-to-image/domain/types/base.types.ts +41 -226
  8. package/src/features/image-to-image/domain/types/partials/config.types.ts +37 -0
  9. package/src/features/image-to-image/domain/types/partials/hook.types.ts +55 -0
  10. package/src/features/image-to-image/domain/types/partials/metadata.types.ts +32 -0
  11. package/src/features/image-to-image/domain/types/partials/result.types.ts +44 -0
  12. package/src/features/image-to-image/domain/types/partials/state.types.ts +34 -0
  13. package/src/features/image-to-image/domain/types/partials/translation.types.ts +57 -0
  14. package/src/features/photo-restoration/presentation/components/PhotoRestoreFeature.tsx +7 -3
  15. package/src/features/remove-background/presentation/components/RemoveBackgroundFeature.tsx +3 -3
  16. package/src/features/remove-object/presentation/components/RemoveObjectFeature.tsx +3 -3
  17. package/src/features/replace-background/presentation/components/ReplaceBackgroundFeature.tsx +7 -3
  18. package/src/features/upscaling/presentation/components/UpscaleFeature.tsx +7 -3
  19. package/src/infrastructure/utils/error-classifier.util.ts +8 -40
  20. package/src/infrastructure/utils/error-patterns.constants.ts +41 -0
  21. package/src/presentation/hooks/base/use-dual-image-feature.ts +68 -76
  22. package/src/presentation/hooks/base/use-image-with-prompt-feature.ts +70 -73
  23. package/src/presentation/hooks/base/utils/feature-state.factory.ts +133 -0
  24. package/src/presentation/layouts/index.ts +14 -11
  25. package/src/presentation/layouts/types/feature-states.ts +38 -0
  26. package/src/presentation/layouts/types/index.ts +35 -0
  27. package/src/presentation/layouts/types/input-props.ts +34 -0
  28. package/src/presentation/layouts/{types.ts → types/layout-props.ts} +22 -125
  29. package/src/presentation/layouts/types/result-props.ts +33 -0
  30. package/src/presentation/layouts/types/translations.ts +35 -0
@@ -0,0 +1,133 @@
1
+ /**
2
+ * Feature State Factory
3
+ * Factory functions for creating feature state handlers
4
+ * Reduces code duplication across feature hooks
5
+ */
6
+
7
+ import { useCallback } from "react";
8
+
9
+ export interface FeatureStateActions {
10
+ reset: () => void;
11
+ clearError: () => void;
12
+ }
13
+
14
+ export interface CreateStateHandlersParams<TState> {
15
+ setState: React.Dispatch<React.SetStateAction<TState>>;
16
+ initialState: TState;
17
+ }
18
+
19
+ /**
20
+ * Creates reset and clearError handlers for feature state
21
+ */
22
+ export function createFeatureStateHandlers<TState extends { error: string | null }>({
23
+ setState,
24
+ initialState,
25
+ }: CreateStateHandlersParams<TState>): FeatureStateActions {
26
+ const reset = useCallback(() => {
27
+ setState(initialState);
28
+ }, [setState, initialState]);
29
+
30
+ const clearError = useCallback(() => {
31
+ setState((prev) => ({
32
+ ...prev,
33
+ error: null,
34
+ }));
35
+ }, [setState]);
36
+
37
+ return { reset, clearError };
38
+ }
39
+
40
+ /**
41
+ * Creates error handler with logging
42
+ */
43
+ export interface ErrorHandlerParams {
44
+ setError: (error: string | null) => void;
45
+ onError?: (error: string) => void;
46
+ errorKey: string;
47
+ }
48
+
49
+ export function createErrorHandler({
50
+ setError,
51
+ onError,
52
+ errorKey,
53
+ }: ErrorHandlerParams) {
54
+ return useCallback((error: unknown) => {
55
+ const message = error instanceof Error ? error.message : errorKey;
56
+ setError(message);
57
+ onError?.(message);
58
+ }, [setError, onError, errorKey]);
59
+ }
60
+
61
+ /**
62
+ * Creates process handler with common logic
63
+ */
64
+ export interface ProcessHandlerParams<TData, TResult> {
65
+ canProcess: () => boolean;
66
+ setError: (error: string | null) => void;
67
+ setProcessing: (processing: boolean) => void;
68
+ onError?: (error: string) => void;
69
+ processFn: () => Promise<TResult>;
70
+ onSuccess?: (result: TResult) => void;
71
+ onProgress?: (progress: number) => void;
72
+ }
73
+
74
+ export async function executeProcess<TData, TResult>({
75
+ canProcess,
76
+ setError,
77
+ setProcessing,
78
+ onError,
79
+ processFn,
80
+ onSuccess,
81
+ onProgress,
82
+ }: ProcessHandlerParams<TData, TResult>): Promise<TResult | null> {
83
+ if (!canProcess()) {
84
+ return null;
85
+ }
86
+
87
+ setProcessing(true);
88
+ setError(null);
89
+ onProgress?.(0);
90
+
91
+ try {
92
+ const result = await processFn();
93
+ onProgress?.(100);
94
+ onSuccess?.(result);
95
+ return result;
96
+ } catch (err) {
97
+ const message = err instanceof Error ? err.message : "error.processing";
98
+ setError(message);
99
+ onError?.(message);
100
+ return null;
101
+ } finally {
102
+ setProcessing(false);
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Creates save handler
108
+ */
109
+ export interface SaveHandlerParams {
110
+ processedUrl: string | null;
111
+ onSave?: (url: string) => Promise<void>;
112
+ setError: (error: string | null) => void;
113
+ onError?: (error: string) => void;
114
+ }
115
+
116
+ export async function executeSave({
117
+ processedUrl,
118
+ onSave,
119
+ setError,
120
+ onError,
121
+ }: SaveHandlerParams): Promise<void> {
122
+ if (!processedUrl || !onSave) {
123
+ return;
124
+ }
125
+
126
+ try {
127
+ await onSave(processedUrl);
128
+ } catch (err) {
129
+ const message = err instanceof Error ? err.message : "error.save";
130
+ setError(message);
131
+ onError?.(message);
132
+ }
133
+ }
@@ -1,26 +1,29 @@
1
1
  /**
2
- * Feature Layouts
3
- * Centralized layout components for image/video processing features
2
+ * Feature Layout Types
3
+ * Shared types for SingleImageFeatureLayout and DualImageFeatureLayout
4
4
  */
5
5
 
6
- export { SingleImageFeatureLayout } from "./SingleImageFeatureLayout";
7
- export { SingleImageWithPromptFeatureLayout } from "./SingleImageWithPromptFeatureLayout";
8
- export { DualImageFeatureLayout } from "./DualImageFeatureLayout";
9
- export { DualImageVideoFeatureLayout } from "./DualImageVideoFeatureLayout";
6
+ // Re-export all partial types
10
7
  export type {
11
8
  ModalTranslations,
12
9
  BaseLayoutTranslations,
13
10
  PhotoUploadTranslations,
14
11
  SingleImageInputRenderProps,
15
- SingleImageWithPromptInputRenderProps,
16
- SingleImageWithPromptFeatureState,
17
- SingleImageWithPromptFeatureLayoutProps,
18
12
  DualImageInputRenderProps,
13
+ SingleImageWithPromptInputRenderProps,
19
14
  ResultRenderProps,
20
- CustomResultRenderProps,
21
15
  ProcessingModalRenderProps,
16
+ CustomResultRenderProps,
17
+ DualImageVideoFeatureState,
18
+ SingleImageWithPromptFeatureState,
22
19
  SingleImageFeatureLayoutProps,
23
20
  DualImageFeatureLayoutProps,
24
- DualImageVideoFeatureState,
25
21
  DualImageVideoFeatureLayoutProps,
22
+ SingleImageWithPromptFeatureLayoutProps,
26
23
  } from "./types";
24
+
25
+ // Export layout components
26
+ export { SingleImageFeatureLayout } from "./SingleImageFeatureLayout";
27
+ export { SingleImageWithPromptFeatureLayout } from "./SingleImageWithPromptFeatureLayout";
28
+ export { DualImageFeatureLayout } from "./DualImageFeatureLayout";
29
+ export { DualImageVideoFeatureLayout } from "./DualImageVideoFeatureLayout";
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Feature State Types
3
+ * State interfaces for different feature types
4
+ */
5
+
6
+ /**
7
+ * Dual image video feature state (for ai-kiss, ai-hug)
8
+ */
9
+ export interface DualImageVideoFeatureState {
10
+ sourceImageUri: string | null;
11
+ targetImageUri: string | null;
12
+ processedVideoUrl: string | null;
13
+ isProcessing: boolean;
14
+ progress: number;
15
+ error: string | null;
16
+ selectSourceImage: () => Promise<void>;
17
+ selectTargetImage: () => Promise<void>;
18
+ process: () => Promise<void>;
19
+ save: () => Promise<void>;
20
+ reset: () => void;
21
+ }
22
+
23
+ /**
24
+ * Single image with prompt feature state
25
+ */
26
+ export interface SingleImageWithPromptFeatureState {
27
+ imageUri: string | null;
28
+ prompt: string;
29
+ processedUrl: string | null;
30
+ isProcessing: boolean;
31
+ progress: number;
32
+ error: string | null;
33
+ selectImage: () => Promise<void>;
34
+ setPrompt: (prompt: string) => void;
35
+ process: () => Promise<void>;
36
+ save: () => Promise<void>;
37
+ reset: () => void;
38
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Feature Layout Types
3
+ * Central index for all layout types
4
+ */
5
+
6
+ // Re-export all partial types
7
+ export type {
8
+ ModalTranslations,
9
+ BaseLayoutTranslations,
10
+ PhotoUploadTranslations,
11
+ } from "./translations";
12
+
13
+ export type {
14
+ SingleImageInputRenderProps,
15
+ DualImageInputRenderProps,
16
+ SingleImageWithPromptInputRenderProps,
17
+ } from "./input-props";
18
+
19
+ export type {
20
+ ResultRenderProps,
21
+ ProcessingModalRenderProps,
22
+ CustomResultRenderProps,
23
+ } from "./result-props";
24
+
25
+ export type {
26
+ DualImageVideoFeatureState,
27
+ SingleImageWithPromptFeatureState,
28
+ } from "./feature-states";
29
+
30
+ export type {
31
+ SingleImageFeatureLayoutProps,
32
+ DualImageFeatureLayoutProps,
33
+ DualImageVideoFeatureLayoutProps,
34
+ SingleImageWithPromptFeatureLayoutProps,
35
+ } from "./layout-props";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Layout Input Render Props Types
3
+ * Input section render props for feature layouts
4
+ */
5
+
6
+ /**
7
+ * Input render props for single image
8
+ */
9
+ export interface SingleImageInputRenderProps {
10
+ imageUri: string | null;
11
+ onSelect: () => void;
12
+ isDisabled: boolean;
13
+ isProcessing: boolean;
14
+ }
15
+
16
+ /**
17
+ * Input render props for dual image
18
+ */
19
+ export interface DualImageInputRenderProps {
20
+ sourceImageUri: string | null;
21
+ targetImageUri: string | null;
22
+ onSelectSource: () => void;
23
+ onSelectTarget: () => void;
24
+ isDisabled: boolean;
25
+ isProcessing: boolean;
26
+ }
27
+
28
+ /**
29
+ * Input render props for single image with prompt
30
+ */
31
+ export interface SingleImageWithPromptInputRenderProps extends SingleImageInputRenderProps {
32
+ prompt: string;
33
+ onPromptChange: (prompt: string) => void;
34
+ }
@@ -1,93 +1,32 @@
1
1
  /**
2
- * Feature Layout Types
3
- * Shared types for SingleImageFeatureLayout and DualImageFeatureLayout
2
+ * Layout Props Types
3
+ * Main layout component props interfaces
4
4
  */
5
5
 
6
6
  import type { ReactNode } from "react";
7
7
  import type {
8
8
  BaseSingleImageHookReturn,
9
9
  BaseDualImageHookReturn,
10
- } from "../../features/image-to-image/domain/types";
11
-
12
- /**
13
- * Modal translations for processing modal
14
- */
15
- export interface ModalTranslations {
16
- title: string;
17
- message: string;
18
- hint: string;
19
- backgroundHint: string;
20
- }
21
-
22
- /**
23
- * Base translations required by layouts
24
- */
25
- export interface BaseLayoutTranslations {
26
- successText: string;
27
- saveButtonText: string;
28
- tryAnotherText: string;
29
- processButtonText: string;
30
- processingText: string;
31
- }
32
-
33
- /**
34
- * Photo upload translations
35
- */
36
- export interface PhotoUploadTranslations {
37
- uploadTitle: string;
38
- uploadSubtitle: string;
39
- uploadChange: string;
40
- uploadAnalyzing: string;
41
- }
42
-
43
- /**
44
- * Input render props for single image
45
- */
46
- export interface SingleImageInputRenderProps {
47
- imageUri: string | null;
48
- onSelect: () => void;
49
- isDisabled: boolean;
50
- isProcessing: boolean;
51
- }
52
-
53
- /**
54
- * Input render props for dual image
55
- */
56
- export interface DualImageInputRenderProps {
57
- sourceImageUri: string | null;
58
- targetImageUri: string | null;
59
- onSelectSource: () => void;
60
- onSelectTarget: () => void;
61
- isDisabled: boolean;
62
- isProcessing: boolean;
63
- }
64
-
65
- /**
66
- * Result render props
67
- */
68
- export interface ResultRenderProps {
69
- imageUrl: string;
70
- imageSize: number;
71
- }
72
-
73
- /**
74
- * Processing modal render props
75
- */
76
- export interface ProcessingModalRenderProps {
77
- visible: boolean;
78
- progress: number;
79
- }
80
-
81
- /**
82
- * Custom result render props (includes feature state for comparison views)
83
- */
84
- export interface CustomResultRenderProps {
85
- processedUrl: string;
86
- originalImageUri: string;
87
- imageSize: number;
88
- onSave: () => void;
89
- onReset: () => void;
90
- }
10
+ } from "../../../../../features/image-to-image/domain/types";
11
+ import type {
12
+ ModalTranslations,
13
+ BaseLayoutTranslations,
14
+ PhotoUploadTranslations,
15
+ } from "./translations";
16
+ import type {
17
+ SingleImageInputRenderProps,
18
+ DualImageInputRenderProps,
19
+ SingleImageWithPromptInputRenderProps,
20
+ } from "./input-props";
21
+ import type {
22
+ ResultRenderProps,
23
+ ProcessingModalRenderProps,
24
+ CustomResultRenderProps,
25
+ } from "./result-props";
26
+ import type {
27
+ DualImageVideoFeatureState,
28
+ SingleImageWithPromptFeatureState,
29
+ } from "./feature-states";
91
30
 
92
31
  /**
93
32
  * Single image feature layout props
@@ -139,23 +78,6 @@ export interface DualImageFeatureLayoutProps {
139
78
  children?: ReactNode;
140
79
  }
141
80
 
142
- /**
143
- * Dual image video feature state (for ai-kiss, ai-hug)
144
- */
145
- export interface DualImageVideoFeatureState {
146
- sourceImageUri: string | null;
147
- targetImageUri: string | null;
148
- processedVideoUrl: string | null;
149
- isProcessing: boolean;
150
- progress: number;
151
- error: string | null;
152
- selectSourceImage: () => Promise<void>;
153
- selectTargetImage: () => Promise<void>;
154
- process: () => Promise<void>;
155
- save: () => Promise<void>;
156
- reset: () => void;
157
- }
158
-
159
81
  /**
160
82
  * Dual image video feature layout props
161
83
  */
@@ -178,31 +100,6 @@ export interface DualImageVideoFeatureLayoutProps {
178
100
  children?: ReactNode;
179
101
  }
180
102
 
181
- /**
182
- * Single image with prompt feature state
183
- */
184
- export interface SingleImageWithPromptFeatureState {
185
- imageUri: string | null;
186
- prompt: string;
187
- processedUrl: string | null;
188
- isProcessing: boolean;
189
- progress: number;
190
- error: string | null;
191
- selectImage: () => Promise<void>;
192
- setPrompt: (prompt: string) => void;
193
- process: () => Promise<void>;
194
- save: () => Promise<void>;
195
- reset: () => void;
196
- }
197
-
198
- /**
199
- * Input render props for single image with prompt
200
- */
201
- export interface SingleImageWithPromptInputRenderProps extends SingleImageInputRenderProps {
202
- prompt: string;
203
- onPromptChange: (prompt: string) => void;
204
- }
205
-
206
103
  /**
207
104
  * Single image with prompt feature layout props
208
105
  */
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Layout Result Render Props Types
3
+ * Result section render props for feature layouts
4
+ */
5
+
6
+ import type { ReactNode } from "react";
7
+
8
+ /**
9
+ * Result render props
10
+ */
11
+ export interface ResultRenderProps {
12
+ imageUrl: string;
13
+ imageSize: number;
14
+ }
15
+
16
+ /**
17
+ * Processing modal render props
18
+ */
19
+ export interface ProcessingModalRenderProps {
20
+ visible: boolean;
21
+ progress: number;
22
+ }
23
+
24
+ /**
25
+ * Custom result render props (includes feature state for comparison views)
26
+ */
27
+ export interface CustomResultRenderProps {
28
+ processedUrl: string;
29
+ originalImageUri: string;
30
+ imageSize: number;
31
+ onSave: () => void;
32
+ onReset: () => void;
33
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Layout Translation Types
3
+ * Translation interfaces for feature layouts
4
+ */
5
+
6
+ /**
7
+ * Modal translations for processing modal
8
+ */
9
+ export interface ModalTranslations {
10
+ title: string;
11
+ message: string;
12
+ hint: string;
13
+ backgroundHint: string;
14
+ }
15
+
16
+ /**
17
+ * Base translations required by layouts
18
+ */
19
+ export interface BaseLayoutTranslations {
20
+ successText: string;
21
+ saveButtonText: string;
22
+ tryAnotherText: string;
23
+ processButtonText: string;
24
+ processingText: string;
25
+ }
26
+
27
+ /**
28
+ * Photo upload translations
29
+ */
30
+ export interface PhotoUploadTranslations {
31
+ uploadTitle: string;
32
+ uploadSubtitle: string;
33
+ uploadChange: string;
34
+ uploadAnalyzing: string;
35
+ }