@umituz/react-native-ai-generation-content 1.12.3 → 1.12.5
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 +30 -6
- package/src/domains/content-moderation/domain/entities/moderation.types.ts +84 -0
- package/src/domains/content-moderation/domain/interfaces/content-filter.interface.ts +24 -0
- package/src/domains/content-moderation/index.ts +67 -0
- package/src/domains/content-moderation/infrastructure/rules/default-rules.data.ts +144 -0
- package/src/domains/content-moderation/infrastructure/rules/rules-registry.ts +75 -0
- package/src/domains/content-moderation/infrastructure/services/content-moderation.service.ts +150 -0
- package/src/domains/content-moderation/infrastructure/services/index.ts +8 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/base.moderator.ts +62 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/image.moderator.ts +64 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/index.ts +10 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/text.moderator.ts +144 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/video.moderator.ts +64 -0
- package/src/domains/content-moderation/infrastructure/services/moderators/voice.moderator.ts +74 -0
- package/src/domains/content-moderation/infrastructure/services/pattern-matcher.service.ts +51 -0
- package/src/domains/content-moderation/presentation/exceptions/content-policy-violation.exception.ts +48 -0
- package/src/domains/creations/application/services/CreationsService.ts +71 -0
- package/src/domains/creations/domain/entities/Creation.ts +51 -0
- package/src/domains/creations/domain/entities/index.ts +6 -0
- package/src/domains/creations/domain/repositories/ICreationsRepository.ts +23 -0
- package/src/domains/creations/domain/repositories/index.ts +5 -0
- package/src/domains/creations/domain/services/ICreationsStorageService.ts +13 -0
- package/src/domains/creations/domain/value-objects/CreationsConfig.ts +76 -0
- package/src/domains/creations/domain/value-objects/index.ts +12 -0
- package/src/domains/creations/index.ts +84 -0
- package/src/domains/creations/infrastructure/adapters/createRepository.ts +54 -0
- package/src/domains/creations/infrastructure/adapters/index.ts +5 -0
- package/src/domains/creations/infrastructure/repositories/CreationsRepository.ts +233 -0
- package/src/domains/creations/infrastructure/repositories/index.ts +8 -0
- package/src/domains/creations/infrastructure/services/CreationsStorageService.ts +48 -0
- package/src/domains/creations/presentation/components/CreationCard.tsx +136 -0
- package/src/domains/creations/presentation/components/CreationDetail/DetailActions.tsx +76 -0
- package/src/domains/creations/presentation/components/CreationDetail/DetailHeader.tsx +81 -0
- package/src/domains/creations/presentation/components/CreationDetail/DetailImage.tsx +41 -0
- package/src/domains/creations/presentation/components/CreationDetail/DetailStory.tsx +67 -0
- package/src/domains/creations/presentation/components/CreationDetail/index.ts +4 -0
- package/src/domains/creations/presentation/components/CreationImageViewer.tsx +43 -0
- package/src/domains/creations/presentation/components/CreationThumbnail.tsx +63 -0
- package/src/domains/creations/presentation/components/CreationsGrid.tsx +75 -0
- package/src/domains/creations/presentation/components/CreationsHomeCard.tsx +176 -0
- package/src/domains/creations/presentation/components/EmptyState.tsx +75 -0
- package/src/domains/creations/presentation/components/FilterBottomSheet.tsx +158 -0
- package/src/domains/creations/presentation/components/FilterChips.tsx +105 -0
- package/src/domains/creations/presentation/components/GalleryHeader.tsx +106 -0
- package/src/domains/creations/presentation/components/index.ts +19 -0
- package/src/domains/creations/presentation/hooks/index.ts +7 -0
- package/src/domains/creations/presentation/hooks/useCreations.ts +33 -0
- package/src/domains/creations/presentation/hooks/useCreationsFilter.ts +70 -0
- package/src/domains/creations/presentation/hooks/useDeleteCreation.ts +51 -0
- package/src/domains/creations/presentation/screens/CreationDetailScreen.tsx +71 -0
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +217 -0
- package/src/domains/creations/presentation/screens/index.ts +5 -0
- package/src/domains/creations/presentation/utils/filterUtils.ts +52 -0
- package/src/domains/creations/types.d.ts +107 -0
- package/src/domains/face-detection/domain/constants/faceDetectionConstants.ts +16 -0
- package/src/domains/face-detection/domain/entities/FaceDetection.ts +19 -0
- package/src/domains/face-detection/index.ts +26 -0
- package/src/domains/face-detection/infrastructure/analyzers/faceAnalyzer.ts +36 -0
- package/src/domains/face-detection/infrastructure/validators/faceValidator.ts +52 -0
- package/src/domains/face-detection/presentation/components/FaceValidationStatus.tsx +111 -0
- package/src/domains/face-detection/presentation/hooks/useFaceDetection.ts +58 -0
- package/src/domains/feature-background/domain/entities/background.types.ts +77 -0
- package/src/domains/feature-background/domain/entities/component.types.ts +96 -0
- package/src/domains/feature-background/domain/entities/config.types.ts +41 -0
- package/src/domains/feature-background/domain/entities/index.ts +31 -0
- package/src/domains/feature-background/index.ts +72 -0
- package/src/domains/feature-background/infrastructure/constants/index.ts +5 -0
- package/src/domains/feature-background/infrastructure/constants/prompts.constants.ts +15 -0
- package/src/domains/feature-background/presentation/components/BackgroundFeature.tsx +145 -0
- package/src/domains/feature-background/presentation/components/ComparisonSlider.tsx +199 -0
- package/src/domains/feature-background/presentation/components/ErrorDisplay.tsx +58 -0
- package/src/domains/feature-background/presentation/components/FeatureHeader.tsx +80 -0
- package/src/domains/feature-background/presentation/components/GenerateButton.tsx +86 -0
- package/src/domains/feature-background/presentation/components/ImagePicker.tsx +136 -0
- package/src/domains/feature-background/presentation/components/ModeSelector.tsx +78 -0
- package/src/domains/feature-background/presentation/components/ProcessingModal.tsx +113 -0
- package/src/domains/feature-background/presentation/components/PromptInput.tsx +142 -0
- package/src/domains/feature-background/presentation/components/ResultDisplay.tsx +123 -0
- package/src/domains/feature-background/presentation/components/index.ts +16 -0
- package/src/domains/feature-background/presentation/hooks/index.ts +7 -0
- package/src/domains/feature-background/presentation/hooks/useBackgroundFeature.ts +118 -0
- package/src/index.ts +24 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Processing Modal Component
|
|
3
|
+
* @description Modal shown during processing with progress
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo } from "react";
|
|
7
|
+
import { Modal, View, StyleSheet, ActivityIndicator } from "react-native";
|
|
8
|
+
import {
|
|
9
|
+
AtomicText,
|
|
10
|
+
useAppDesignTokens,
|
|
11
|
+
} from "@umituz/react-native-design-system";
|
|
12
|
+
import type { ProcessingModalProps } from "../../domain/entities";
|
|
13
|
+
|
|
14
|
+
export const ProcessingModal: React.FC<ProcessingModalProps> = memo(
|
|
15
|
+
function ProcessingModal({ visible, progress = 0, title }) {
|
|
16
|
+
const tokens = useAppDesignTokens();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<Modal
|
|
20
|
+
visible={visible}
|
|
21
|
+
transparent
|
|
22
|
+
animationType="fade"
|
|
23
|
+
statusBarTranslucent
|
|
24
|
+
>
|
|
25
|
+
<View style={styles.overlay}>
|
|
26
|
+
<View
|
|
27
|
+
style={[
|
|
28
|
+
styles.content,
|
|
29
|
+
{ backgroundColor: tokens.colors.surface },
|
|
30
|
+
]}
|
|
31
|
+
>
|
|
32
|
+
<ActivityIndicator
|
|
33
|
+
size="large"
|
|
34
|
+
color={tokens.colors.primary}
|
|
35
|
+
/>
|
|
36
|
+
{title && (
|
|
37
|
+
<AtomicText
|
|
38
|
+
type="bodyLarge"
|
|
39
|
+
style={[
|
|
40
|
+
styles.title,
|
|
41
|
+
{ color: tokens.colors.textPrimary },
|
|
42
|
+
]}
|
|
43
|
+
>
|
|
44
|
+
{title}
|
|
45
|
+
</AtomicText>
|
|
46
|
+
)}
|
|
47
|
+
{progress > 0 && (
|
|
48
|
+
<View style={styles.progressContainer}>
|
|
49
|
+
<View
|
|
50
|
+
style={[
|
|
51
|
+
styles.progressBar,
|
|
52
|
+
{ backgroundColor: tokens.colors.surfaceSecondary },
|
|
53
|
+
]}
|
|
54
|
+
>
|
|
55
|
+
<View
|
|
56
|
+
style={[
|
|
57
|
+
styles.progressFill,
|
|
58
|
+
{
|
|
59
|
+
backgroundColor: tokens.colors.primary,
|
|
60
|
+
width: `${Math.min(progress, 100)}%`,
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
/>
|
|
64
|
+
</View>
|
|
65
|
+
<AtomicText
|
|
66
|
+
type="bodySmall"
|
|
67
|
+
style={{ color: tokens.colors.textSecondary }}
|
|
68
|
+
>
|
|
69
|
+
{Math.round(progress)}%
|
|
70
|
+
</AtomicText>
|
|
71
|
+
</View>
|
|
72
|
+
)}
|
|
73
|
+
</View>
|
|
74
|
+
</View>
|
|
75
|
+
</Modal>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const styles = StyleSheet.create({
|
|
81
|
+
overlay: {
|
|
82
|
+
flex: 1,
|
|
83
|
+
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
|
84
|
+
justifyContent: "center",
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
},
|
|
87
|
+
content: {
|
|
88
|
+
padding: 32,
|
|
89
|
+
borderRadius: 20,
|
|
90
|
+
alignItems: "center",
|
|
91
|
+
minWidth: 200,
|
|
92
|
+
},
|
|
93
|
+
title: {
|
|
94
|
+
marginTop: 16,
|
|
95
|
+
textAlign: "center",
|
|
96
|
+
},
|
|
97
|
+
progressContainer: {
|
|
98
|
+
marginTop: 16,
|
|
99
|
+
alignItems: "center",
|
|
100
|
+
width: "100%",
|
|
101
|
+
},
|
|
102
|
+
progressBar: {
|
|
103
|
+
width: "100%",
|
|
104
|
+
height: 6,
|
|
105
|
+
borderRadius: 3,
|
|
106
|
+
overflow: "hidden",
|
|
107
|
+
marginBottom: 8,
|
|
108
|
+
},
|
|
109
|
+
progressFill: {
|
|
110
|
+
height: "100%",
|
|
111
|
+
borderRadius: 3,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt Input Component
|
|
3
|
+
* @description Text input with sample prompt chips
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo } from "react";
|
|
7
|
+
import { View, TextInput, StyleSheet, TouchableOpacity } from "react-native";
|
|
8
|
+
import {
|
|
9
|
+
AtomicText,
|
|
10
|
+
useAppDesignTokens,
|
|
11
|
+
} from "@umituz/react-native-design-system";
|
|
12
|
+
import type { PromptInputProps } from "../../domain/entities";
|
|
13
|
+
import { DEFAULT_SAMPLE_PROMPTS } from "../../infrastructure/constants";
|
|
14
|
+
|
|
15
|
+
export const PromptInput: React.FC<PromptInputProps> = memo(
|
|
16
|
+
function PromptInput({
|
|
17
|
+
value,
|
|
18
|
+
onChangeText,
|
|
19
|
+
isProcessing,
|
|
20
|
+
label,
|
|
21
|
+
placeholder,
|
|
22
|
+
samplePrompts = DEFAULT_SAMPLE_PROMPTS,
|
|
23
|
+
samplePromptsLabel,
|
|
24
|
+
}) {
|
|
25
|
+
const tokens = useAppDesignTokens();
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<View style={styles.container}>
|
|
29
|
+
{label && (
|
|
30
|
+
<AtomicText
|
|
31
|
+
type="labelLarge"
|
|
32
|
+
style={[
|
|
33
|
+
styles.label,
|
|
34
|
+
{
|
|
35
|
+
color: tokens.colors.textPrimary,
|
|
36
|
+
marginBottom: tokens.spacing.sm,
|
|
37
|
+
},
|
|
38
|
+
]}
|
|
39
|
+
>
|
|
40
|
+
{label}
|
|
41
|
+
</AtomicText>
|
|
42
|
+
)}
|
|
43
|
+
|
|
44
|
+
<TextInput
|
|
45
|
+
value={value}
|
|
46
|
+
onChangeText={onChangeText}
|
|
47
|
+
placeholder={placeholder}
|
|
48
|
+
placeholderTextColor={tokens.colors.textTertiary}
|
|
49
|
+
multiline
|
|
50
|
+
numberOfLines={4}
|
|
51
|
+
editable={!isProcessing}
|
|
52
|
+
style={[
|
|
53
|
+
styles.input,
|
|
54
|
+
{
|
|
55
|
+
backgroundColor: tokens.colors.surface,
|
|
56
|
+
borderColor: tokens.colors.border,
|
|
57
|
+
color: tokens.colors.textPrimary,
|
|
58
|
+
},
|
|
59
|
+
]}
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
{samplePrompts.length > 0 && (
|
|
63
|
+
<>
|
|
64
|
+
{samplePromptsLabel && (
|
|
65
|
+
<AtomicText
|
|
66
|
+
type="labelMedium"
|
|
67
|
+
style={[
|
|
68
|
+
styles.sampleLabel,
|
|
69
|
+
{
|
|
70
|
+
color: tokens.colors.textSecondary,
|
|
71
|
+
marginTop: tokens.spacing.md,
|
|
72
|
+
marginBottom: tokens.spacing.sm,
|
|
73
|
+
},
|
|
74
|
+
]}
|
|
75
|
+
>
|
|
76
|
+
{samplePromptsLabel}
|
|
77
|
+
</AtomicText>
|
|
78
|
+
)}
|
|
79
|
+
|
|
80
|
+
<View style={styles.sampleContainer}>
|
|
81
|
+
{samplePrompts.map((prompt) => (
|
|
82
|
+
<TouchableOpacity
|
|
83
|
+
key={prompt.id}
|
|
84
|
+
style={[
|
|
85
|
+
styles.sampleChip,
|
|
86
|
+
{
|
|
87
|
+
backgroundColor: tokens.colors.surfaceSecondary,
|
|
88
|
+
borderColor: tokens.colors.border,
|
|
89
|
+
},
|
|
90
|
+
]}
|
|
91
|
+
onPress={() => onChangeText(prompt.text)}
|
|
92
|
+
disabled={isProcessing}
|
|
93
|
+
>
|
|
94
|
+
<AtomicText
|
|
95
|
+
type="bodySmall"
|
|
96
|
+
style={{ color: tokens.colors.textSecondary }}
|
|
97
|
+
numberOfLines={1}
|
|
98
|
+
>
|
|
99
|
+
{prompt.text}
|
|
100
|
+
</AtomicText>
|
|
101
|
+
</TouchableOpacity>
|
|
102
|
+
))}
|
|
103
|
+
</View>
|
|
104
|
+
</>
|
|
105
|
+
)}
|
|
106
|
+
</View>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const styles = StyleSheet.create({
|
|
112
|
+
container: {
|
|
113
|
+
marginVertical: 16,
|
|
114
|
+
},
|
|
115
|
+
label: {
|
|
116
|
+
fontWeight: "600",
|
|
117
|
+
},
|
|
118
|
+
input: {
|
|
119
|
+
minHeight: 120,
|
|
120
|
+
borderWidth: 1,
|
|
121
|
+
borderRadius: 16,
|
|
122
|
+
paddingHorizontal: 16,
|
|
123
|
+
paddingVertical: 14,
|
|
124
|
+
fontSize: 16,
|
|
125
|
+
textAlignVertical: "top",
|
|
126
|
+
lineHeight: 24,
|
|
127
|
+
},
|
|
128
|
+
sampleLabel: {
|
|
129
|
+
fontWeight: "500",
|
|
130
|
+
},
|
|
131
|
+
sampleContainer: {
|
|
132
|
+
flexDirection: "row",
|
|
133
|
+
flexWrap: "wrap",
|
|
134
|
+
gap: 8,
|
|
135
|
+
},
|
|
136
|
+
sampleChip: {
|
|
137
|
+
paddingHorizontal: 12,
|
|
138
|
+
paddingVertical: 8,
|
|
139
|
+
borderRadius: 20,
|
|
140
|
+
borderWidth: 1,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result Display Component
|
|
3
|
+
* @description Displays processed image with save/reset actions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo } from "react";
|
|
7
|
+
import { View, StyleSheet, Image, TouchableOpacity } from "react-native";
|
|
8
|
+
import {
|
|
9
|
+
AtomicText,
|
|
10
|
+
AtomicIcon,
|
|
11
|
+
useAppDesignTokens,
|
|
12
|
+
} from "@umituz/react-native-design-system";
|
|
13
|
+
import type { ResultDisplayProps } from "../../domain/entities";
|
|
14
|
+
|
|
15
|
+
export const ResultDisplay: React.FC<ResultDisplayProps> = memo(
|
|
16
|
+
function ResultDisplay({
|
|
17
|
+
imageUrl,
|
|
18
|
+
isProcessing,
|
|
19
|
+
onSave,
|
|
20
|
+
onReset,
|
|
21
|
+
saveButtonText,
|
|
22
|
+
resetButtonText,
|
|
23
|
+
}) {
|
|
24
|
+
const tokens = useAppDesignTokens();
|
|
25
|
+
|
|
26
|
+
if (!imageUrl || isProcessing) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<View style={styles.container}>
|
|
32
|
+
<View style={styles.resultContainer}>
|
|
33
|
+
<Image
|
|
34
|
+
source={{ uri: imageUrl }}
|
|
35
|
+
style={styles.resultImage}
|
|
36
|
+
resizeMode="cover"
|
|
37
|
+
/>
|
|
38
|
+
</View>
|
|
39
|
+
|
|
40
|
+
<View style={styles.actionsContainer}>
|
|
41
|
+
<TouchableOpacity
|
|
42
|
+
style={[
|
|
43
|
+
styles.actionButton,
|
|
44
|
+
{ backgroundColor: tokens.colors.backgroundSecondary },
|
|
45
|
+
]}
|
|
46
|
+
onPress={onReset}
|
|
47
|
+
>
|
|
48
|
+
<AtomicIcon
|
|
49
|
+
name="refresh-cw"
|
|
50
|
+
size={20}
|
|
51
|
+
color="onSurface"
|
|
52
|
+
/>
|
|
53
|
+
<AtomicText
|
|
54
|
+
type="labelLarge"
|
|
55
|
+
style={[styles.actionText, { color: tokens.colors.textPrimary }]}
|
|
56
|
+
>
|
|
57
|
+
{resetButtonText}
|
|
58
|
+
</AtomicText>
|
|
59
|
+
</TouchableOpacity>
|
|
60
|
+
|
|
61
|
+
<TouchableOpacity
|
|
62
|
+
style={[
|
|
63
|
+
styles.actionButton,
|
|
64
|
+
{ backgroundColor: tokens.colors.success },
|
|
65
|
+
]}
|
|
66
|
+
onPress={onSave}
|
|
67
|
+
>
|
|
68
|
+
<AtomicIcon
|
|
69
|
+
name="download"
|
|
70
|
+
size={20}
|
|
71
|
+
color="onPrimary"
|
|
72
|
+
/>
|
|
73
|
+
<AtomicText
|
|
74
|
+
type="labelLarge"
|
|
75
|
+
style={[
|
|
76
|
+
styles.actionText,
|
|
77
|
+
{ color: tokens.colors.backgroundPrimary },
|
|
78
|
+
]}
|
|
79
|
+
>
|
|
80
|
+
{saveButtonText}
|
|
81
|
+
</AtomicText>
|
|
82
|
+
</TouchableOpacity>
|
|
83
|
+
</View>
|
|
84
|
+
</View>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const styles = StyleSheet.create({
|
|
90
|
+
container: {
|
|
91
|
+
marginTop: 24,
|
|
92
|
+
marginBottom: 16,
|
|
93
|
+
},
|
|
94
|
+
resultContainer: {
|
|
95
|
+
width: "100%",
|
|
96
|
+
aspectRatio: 1,
|
|
97
|
+
borderRadius: 24,
|
|
98
|
+
overflow: "hidden",
|
|
99
|
+
marginBottom: 16,
|
|
100
|
+
borderWidth: 1,
|
|
101
|
+
borderColor: "rgba(255,255,255,0.1)",
|
|
102
|
+
},
|
|
103
|
+
resultImage: {
|
|
104
|
+
width: "100%",
|
|
105
|
+
height: "100%",
|
|
106
|
+
},
|
|
107
|
+
actionsContainer: {
|
|
108
|
+
flexDirection: "row",
|
|
109
|
+
gap: 12,
|
|
110
|
+
},
|
|
111
|
+
actionButton: {
|
|
112
|
+
flex: 1,
|
|
113
|
+
flexDirection: "row",
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
justifyContent: "center",
|
|
116
|
+
paddingVertical: 14,
|
|
117
|
+
borderRadius: 16,
|
|
118
|
+
gap: 8,
|
|
119
|
+
},
|
|
120
|
+
actionText: {
|
|
121
|
+
fontWeight: "600",
|
|
122
|
+
},
|
|
123
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation Components Export
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { BackgroundFeature } from "./BackgroundFeature";
|
|
6
|
+
export type { BackgroundFeatureProps } from "./BackgroundFeature";
|
|
7
|
+
|
|
8
|
+
export { ImagePicker } from "./ImagePicker";
|
|
9
|
+
export { PromptInput } from "./PromptInput";
|
|
10
|
+
export { GenerateButton } from "./GenerateButton";
|
|
11
|
+
export { ResultDisplay } from "./ResultDisplay";
|
|
12
|
+
export { ErrorDisplay } from "./ErrorDisplay";
|
|
13
|
+
export { ProcessingModal } from "./ProcessingModal";
|
|
14
|
+
export { FeatureHeader } from "./FeatureHeader";
|
|
15
|
+
export { ComparisonSlider } from "./ComparisonSlider";
|
|
16
|
+
export { ModeSelector } from "./ModeSelector";
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useBackgroundFeature Hook
|
|
3
|
+
* @description Main hook for background feature state and actions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useCallback, useState } from "react";
|
|
7
|
+
import type {
|
|
8
|
+
BackgroundFeatureState,
|
|
9
|
+
BackgroundProcessResult,
|
|
10
|
+
UseBackgroundFeatureConfig,
|
|
11
|
+
StudioMode,
|
|
12
|
+
} from "../../domain/entities";
|
|
13
|
+
|
|
14
|
+
export interface UseBackgroundFeatureReturn extends BackgroundFeatureState {
|
|
15
|
+
readonly selectImage: () => Promise<void>;
|
|
16
|
+
readonly process: (prompt?: string) => Promise<void>;
|
|
17
|
+
readonly save: () => Promise<void>;
|
|
18
|
+
readonly reset: () => void;
|
|
19
|
+
readonly setPrompt: (prompt: string) => void;
|
|
20
|
+
readonly setMode: (mode: StudioMode) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useBackgroundFeature(
|
|
24
|
+
config: UseBackgroundFeatureConfig
|
|
25
|
+
): UseBackgroundFeatureReturn {
|
|
26
|
+
const [imageUri, setImageUri] = useState<string | null>(null);
|
|
27
|
+
const [prompt, setPrompt] = useState<string>("");
|
|
28
|
+
const [processedUrl, setProcessedUrl] = useState<string | null>(null);
|
|
29
|
+
const [isProcessing, setIsProcessing] = useState(false);
|
|
30
|
+
const [progress, setProgress] = useState(0);
|
|
31
|
+
const [error, setError] = useState<string | null>(null);
|
|
32
|
+
const [mode, setMode] = useState<StudioMode>(
|
|
33
|
+
config.defaultMode ?? "transparent"
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const selectImage = useCallback(async (): Promise<void> => {
|
|
37
|
+
if (!config.onSelectImage) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const uri = await config.onSelectImage();
|
|
43
|
+
if (uri) {
|
|
44
|
+
setImageUri(uri);
|
|
45
|
+
setError(null);
|
|
46
|
+
setProcessedUrl(null);
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
setError(err instanceof Error ? err.message : "Failed to select image");
|
|
50
|
+
}
|
|
51
|
+
}, [config]);
|
|
52
|
+
|
|
53
|
+
const process = useCallback(
|
|
54
|
+
async (newPrompt?: string): Promise<void> => {
|
|
55
|
+
if (!imageUri) {
|
|
56
|
+
setError("Please select an image first");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const currentPrompt = newPrompt ?? prompt;
|
|
61
|
+
setIsProcessing(true);
|
|
62
|
+
setProgress(0);
|
|
63
|
+
setError(null);
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const result: BackgroundProcessResult = await config.processRequest({
|
|
67
|
+
imageUri,
|
|
68
|
+
prompt: currentPrompt,
|
|
69
|
+
mode,
|
|
70
|
+
onProgress: setProgress,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (result.success && result.imageUrl) {
|
|
74
|
+
setProcessedUrl(result.imageUrl);
|
|
75
|
+
} else {
|
|
76
|
+
setError(result.error || "Processing failed");
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
setError(err instanceof Error ? err.message : "Processing failed");
|
|
80
|
+
} finally {
|
|
81
|
+
setIsProcessing(false);
|
|
82
|
+
setProgress(0);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
[imageUri, prompt, mode, config]
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const save = useCallback(async (): Promise<void> => {
|
|
89
|
+
if (!processedUrl) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
}, [processedUrl]);
|
|
93
|
+
|
|
94
|
+
const reset = useCallback((): void => {
|
|
95
|
+
setImageUri(null);
|
|
96
|
+
setPrompt("");
|
|
97
|
+
setProcessedUrl(null);
|
|
98
|
+
setIsProcessing(false);
|
|
99
|
+
setProgress(0);
|
|
100
|
+
setError(null);
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
imageUri,
|
|
105
|
+
prompt,
|
|
106
|
+
processedUrl,
|
|
107
|
+
isProcessing,
|
|
108
|
+
progress,
|
|
109
|
+
error,
|
|
110
|
+
mode,
|
|
111
|
+
selectImage,
|
|
112
|
+
process,
|
|
113
|
+
save,
|
|
114
|
+
reset,
|
|
115
|
+
setPrompt,
|
|
116
|
+
setMode,
|
|
117
|
+
};
|
|
118
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -227,3 +227,27 @@ export type {
|
|
|
227
227
|
// =============================================================================
|
|
228
228
|
|
|
229
229
|
export * from "./domains/prompts";
|
|
230
|
+
|
|
231
|
+
// =============================================================================
|
|
232
|
+
// DOMAINS - Content Moderation
|
|
233
|
+
// =============================================================================
|
|
234
|
+
|
|
235
|
+
export * from "./domains/content-moderation";
|
|
236
|
+
|
|
237
|
+
// =============================================================================
|
|
238
|
+
// DOMAINS - AI Creations
|
|
239
|
+
// =============================================================================
|
|
240
|
+
|
|
241
|
+
export * from "./domains/creations";
|
|
242
|
+
|
|
243
|
+
// =============================================================================
|
|
244
|
+
// DOMAINS - Face Detection
|
|
245
|
+
// =============================================================================
|
|
246
|
+
|
|
247
|
+
export * from "./domains/face-detection";
|
|
248
|
+
|
|
249
|
+
// =============================================================================
|
|
250
|
+
// DOMAINS - Feature Background
|
|
251
|
+
// =============================================================================
|
|
252
|
+
|
|
253
|
+
export * from "./domains/feature-background";
|