@umituz/react-native-photo-editor 2.0.21 → 2.0.23
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/ARCHITECTURE.md +104 -0
- package/MIGRATION.md +100 -0
- package/package.json +1 -5
- package/src/PhotoEditor.tsx +56 -44
- package/src/application/hooks/useEditor.ts +67 -0
- package/src/application/hooks/useEditorUI.ts +145 -0
- package/src/application/stores/EditorStore.ts +137 -0
- package/src/constants.ts +5 -52
- package/src/domain/entities/Filters.ts +72 -0
- package/src/domain/entities/Layer.ts +126 -0
- package/src/domain/entities/Transform.ts +55 -0
- package/src/domain/services/HistoryService.ts +60 -0
- package/src/domain/services/LayerService.ts +105 -0
- package/src/index.ts +25 -5
- package/src/infrastructure/gesture/types.ts +27 -0
- package/src/infrastructure/gesture/useTransformGesture.ts +136 -0
- package/src/infrastructure/history/HistoryManager.ts +38 -0
- package/src/presentation/components/DraggableLayer.tsx +114 -0
- package/src/presentation/components/EditorCanvas.tsx +90 -0
- package/src/presentation/components/EditorToolbar.tsx +192 -0
- package/src/presentation/components/FontControls.tsx +99 -0
- package/src/presentation/components/sheets/AIMagicSheet.tsx +99 -0
- package/src/presentation/components/sheets/AdjustmentsSheet.tsx +113 -0
- package/src/presentation/components/sheets/FilterSheet.tsx +128 -0
- package/src/presentation/components/sheets/LayerManager.tsx +151 -0
- package/src/presentation/components/sheets/StickerPicker.tsx +67 -0
- package/src/presentation/components/sheets/TextEditorSheet.tsx +159 -0
- package/src/presentation/components/ui/ColorPicker.tsx +78 -0
- package/src/presentation/components/ui/Slider.tsx +116 -0
- package/src/types.ts +13 -58
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text Editor Sheet Component
|
|
3
|
+
* Bottom sheet for editing text layers
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo } from "react";
|
|
7
|
+
import { View, TextInput, TouchableOpacity, StyleSheet } from "react-native";
|
|
8
|
+
import { AtomicText, AtomicButton } from "@umituz/react-native-design-system/atoms";
|
|
9
|
+
import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
|
|
10
|
+
import { ColorPicker } from "../ui/ColorPicker";
|
|
11
|
+
import type { TextAlign } from "../../../domain/entities/Layer";
|
|
12
|
+
|
|
13
|
+
interface TextEditorSheetProps {
|
|
14
|
+
value: string;
|
|
15
|
+
onChange: (text: string) => void;
|
|
16
|
+
onSave: () => void;
|
|
17
|
+
t: (key: string) => string;
|
|
18
|
+
color?: string;
|
|
19
|
+
onColorChange?: (color: string) => void;
|
|
20
|
+
textAlign?: TextAlign;
|
|
21
|
+
onTextAlignChange?: (align: TextAlign) => void;
|
|
22
|
+
isBold?: boolean;
|
|
23
|
+
onBoldChange?: (bold: boolean) => void;
|
|
24
|
+
isItalic?: boolean;
|
|
25
|
+
onItalicChange?: (italic: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ALIGN_OPTIONS: { value: TextAlign; icon: string }[] = [
|
|
29
|
+
{ value: "left", icon: "«" },
|
|
30
|
+
{ value: "center", icon: "≡" },
|
|
31
|
+
{ value: "right", icon: "»" },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
const StyleButton = memo<{ label: string; isActive: boolean; onPress: () => void; children: React.ReactNode }>(
|
|
35
|
+
({ label, isActive, onPress, children }) => {
|
|
36
|
+
const tokens = useAppDesignTokens();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<TouchableOpacity
|
|
40
|
+
style={{
|
|
41
|
+
width: 44,
|
|
42
|
+
height: 44,
|
|
43
|
+
borderRadius: tokens.borders.radius.sm,
|
|
44
|
+
borderWidth: 1.5,
|
|
45
|
+
borderColor: isActive ? tokens.colors.primary : tokens.colors.border,
|
|
46
|
+
alignItems: "center",
|
|
47
|
+
justifyContent: "center",
|
|
48
|
+
backgroundColor: isActive ? tokens.colors.primary + "20" : tokens.colors.surfaceVariant,
|
|
49
|
+
}}
|
|
50
|
+
onPress={onPress}
|
|
51
|
+
accessibilityLabel={label}
|
|
52
|
+
accessibilityRole="button"
|
|
53
|
+
accessibilityState={{ selected: isActive }}
|
|
54
|
+
>
|
|
55
|
+
{children}
|
|
56
|
+
</TouchableOpacity>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
StyleButton.displayName = "StyleButton";
|
|
62
|
+
|
|
63
|
+
export const TextEditorSheet = memo<TextEditorSheetProps>(({
|
|
64
|
+
value,
|
|
65
|
+
onChange,
|
|
66
|
+
onSave,
|
|
67
|
+
t,
|
|
68
|
+
color = "#FFFFFF",
|
|
69
|
+
onColorChange,
|
|
70
|
+
textAlign = "center",
|
|
71
|
+
onTextAlignChange,
|
|
72
|
+
isBold = false,
|
|
73
|
+
onBoldChange,
|
|
74
|
+
isItalic = false,
|
|
75
|
+
onItalicChange,
|
|
76
|
+
}) => {
|
|
77
|
+
const tokens = useAppDesignTokens();
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<View style={styles.container}>
|
|
81
|
+
<AtomicText type="headlineSmall">{t("photo_editor.add_text") || "Edit Text"}</AtomicText>
|
|
82
|
+
|
|
83
|
+
<TextInput
|
|
84
|
+
value={value}
|
|
85
|
+
onChangeText={onChange}
|
|
86
|
+
placeholder={t("photo_editor.tap_to_edit") || "Enter text…"}
|
|
87
|
+
placeholderTextColor={tokens.colors.textSecondary}
|
|
88
|
+
style={styles.input}
|
|
89
|
+
multiline
|
|
90
|
+
autoFocus
|
|
91
|
+
/>
|
|
92
|
+
|
|
93
|
+
<View style={styles.row}>
|
|
94
|
+
{onBoldChange && (
|
|
95
|
+
<StyleButton label="Bold" isActive={isBold} onPress={() => onBoldChange(!isBold)}>
|
|
96
|
+
<AtomicText fontWeight="bold" color={isBold ? "primary" : "textSecondary"}>
|
|
97
|
+
B
|
|
98
|
+
</AtomicText>
|
|
99
|
+
</StyleButton>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
{onItalicChange && (
|
|
103
|
+
<StyleButton label="Italic" isActive={isItalic} onPress={() => onItalicChange(!isItalic)}>
|
|
104
|
+
<AtomicText color={isItalic ? "primary" : "textSecondary"} style={{ fontStyle: "italic" }}>
|
|
105
|
+
I
|
|
106
|
+
</AtomicText>
|
|
107
|
+
</StyleButton>
|
|
108
|
+
)}
|
|
109
|
+
|
|
110
|
+
{onTextAlignChange && (
|
|
111
|
+
<View style={[styles.row, { marginLeft: tokens.spacing.sm }]}>
|
|
112
|
+
{ALIGN_OPTIONS.map(({ value: align, icon }) => (
|
|
113
|
+
<StyleButton
|
|
114
|
+
key={align}
|
|
115
|
+
label={`Align ${align}`}
|
|
116
|
+
isActive={textAlign === align}
|
|
117
|
+
onPress={() => onTextAlignChange(align)}
|
|
118
|
+
>
|
|
119
|
+
<AtomicText color={textAlign === align ? "primary" : "textSecondary"}>{icon}</AtomicText>
|
|
120
|
+
</StyleButton>
|
|
121
|
+
))}
|
|
122
|
+
</View>
|
|
123
|
+
)}
|
|
124
|
+
</View>
|
|
125
|
+
|
|
126
|
+
{onColorChange && (
|
|
127
|
+
<ColorPicker
|
|
128
|
+
label="Text Color"
|
|
129
|
+
selectedColor={color}
|
|
130
|
+
onSelectColor={onColorChange}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
<AtomicButton variant="primary" onPress={onSave}>
|
|
135
|
+
{t("common.save") || "Save"}
|
|
136
|
+
</AtomicButton>
|
|
137
|
+
</View>
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
TextEditorSheet.displayName = "TextEditorSheet";
|
|
142
|
+
|
|
143
|
+
const styles = StyleSheet.create({
|
|
144
|
+
container: { padding: 16, gap: 16 },
|
|
145
|
+
input: {
|
|
146
|
+
backgroundColor: "#F5F5F5",
|
|
147
|
+
borderRadius: 8,
|
|
148
|
+
padding: 16,
|
|
149
|
+
fontSize: 18,
|
|
150
|
+
color: "#000",
|
|
151
|
+
textAlign: "center",
|
|
152
|
+
minHeight: 90,
|
|
153
|
+
},
|
|
154
|
+
row: {
|
|
155
|
+
flexDirection: "row",
|
|
156
|
+
alignItems: "center",
|
|
157
|
+
gap: 8,
|
|
158
|
+
},
|
|
159
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color Picker Component
|
|
3
|
+
* Grid of color options
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo } from "react";
|
|
7
|
+
import { View, TouchableOpacity, StyleSheet } from "react-native";
|
|
8
|
+
import { AtomicText } from "@umituz/react-native-design-system/atoms";
|
|
9
|
+
import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
|
|
10
|
+
|
|
11
|
+
const DEFAULT_COLORS = [
|
|
12
|
+
"#FFFFFF", "#000000", "#888888", "#CCCCCC",
|
|
13
|
+
"#FF3B30", "#FF9500", "#FFCC00", "#FF2D55",
|
|
14
|
+
"#34C759", "#30B0C7", "#007AFF", "#5AC8FA",
|
|
15
|
+
"#5856D6", "#AF52DE", "#FF6B6B", "#FFD93D",
|
|
16
|
+
"#6BCB77", "#4D96FF", "#C77DFF", "#F72585",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
interface ColorPickerProps {
|
|
20
|
+
label?: string;
|
|
21
|
+
selectedColor: string;
|
|
22
|
+
onSelectColor: (color: string) => void;
|
|
23
|
+
colors?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ColorPicker = memo<ColorPickerProps>(({
|
|
27
|
+
label,
|
|
28
|
+
selectedColor,
|
|
29
|
+
onSelectColor,
|
|
30
|
+
colors = DEFAULT_COLORS,
|
|
31
|
+
}) => {
|
|
32
|
+
const tokens = useAppDesignTokens();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<View style={styles.container}>
|
|
36
|
+
{label && (
|
|
37
|
+
<AtomicText type="labelMedium" color="textSecondary" style={{ marginBottom: tokens.spacing.sm }}>
|
|
38
|
+
{label}
|
|
39
|
+
</AtomicText>
|
|
40
|
+
)}
|
|
41
|
+
<View style={styles.grid}>
|
|
42
|
+
{colors.map((color) => (
|
|
43
|
+
<TouchableOpacity
|
|
44
|
+
key={color}
|
|
45
|
+
style={[
|
|
46
|
+
styles.color,
|
|
47
|
+
{
|
|
48
|
+
backgroundColor: color,
|
|
49
|
+
borderWidth: selectedColor === color ? 3 : 1,
|
|
50
|
+
borderColor: selectedColor === color ? tokens.colors.primary : "#E0E0E0",
|
|
51
|
+
},
|
|
52
|
+
]}
|
|
53
|
+
onPress={() => onSelectColor(color)}
|
|
54
|
+
accessibilityLabel={`Color ${color}`}
|
|
55
|
+
accessibilityRole="button"
|
|
56
|
+
accessibilityState={{ selected: selectedColor === color }}
|
|
57
|
+
/>
|
|
58
|
+
))}
|
|
59
|
+
</View>
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
ColorPicker.displayName = "ColorPicker";
|
|
65
|
+
|
|
66
|
+
const styles = StyleSheet.create({
|
|
67
|
+
container: { gap: 8 },
|
|
68
|
+
grid: {
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
flexWrap: "wrap",
|
|
71
|
+
gap: 12,
|
|
72
|
+
},
|
|
73
|
+
color: {
|
|
74
|
+
width: 36,
|
|
75
|
+
height: 36,
|
|
76
|
+
borderRadius: 18,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slider Component
|
|
3
|
+
* Custom slider for numeric values
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { memo, useRef, useState } from "react";
|
|
7
|
+
import { View } from "react-native";
|
|
8
|
+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
9
|
+
import { AtomicText } from "@umituz/react-native-design-system/atoms";
|
|
10
|
+
import { useAppDesignTokens } from "@umituz/react-native-design-system/theme";
|
|
11
|
+
|
|
12
|
+
interface SliderProps {
|
|
13
|
+
label: string;
|
|
14
|
+
value: number;
|
|
15
|
+
min: number;
|
|
16
|
+
max: number;
|
|
17
|
+
step?: number;
|
|
18
|
+
onValueChange: (val: number) => void;
|
|
19
|
+
formatValue?: (val: number) => string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const Slider = memo<SliderProps>(({
|
|
23
|
+
label,
|
|
24
|
+
value,
|
|
25
|
+
min,
|
|
26
|
+
max,
|
|
27
|
+
step = 0.05,
|
|
28
|
+
onValueChange,
|
|
29
|
+
formatValue,
|
|
30
|
+
}) => {
|
|
31
|
+
const tokens = useAppDesignTokens();
|
|
32
|
+
const [trackWidth, setTrackWidth] = useState(200);
|
|
33
|
+
const trackWidthRef = useRef(200);
|
|
34
|
+
const startValueRef = useRef(value);
|
|
35
|
+
const valueRef = useRef(value);
|
|
36
|
+
valueRef.current = value;
|
|
37
|
+
|
|
38
|
+
const clamp = (v: number) => Math.max(min, Math.min(max, v));
|
|
39
|
+
const snap = (v: number) => parseFloat((Math.round(v / step) * step).toFixed(4));
|
|
40
|
+
|
|
41
|
+
const panGesture = Gesture.Pan()
|
|
42
|
+
.runOnJS(true)
|
|
43
|
+
.onStart(() => {
|
|
44
|
+
startValueRef.current = valueRef.current;
|
|
45
|
+
})
|
|
46
|
+
.onUpdate((e) => {
|
|
47
|
+
const ratio = e.translationX / trackWidthRef.current;
|
|
48
|
+
const delta = ratio * (max - min);
|
|
49
|
+
onValueChange(snap(clamp(startValueRef.current + delta)));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const percent = Math.max(0, Math.min(1, (value - min) / (max - min)));
|
|
53
|
+
const thumbOffset = percent * trackWidth - 12;
|
|
54
|
+
const displayValue = formatValue ? formatValue(value) : value.toFixed(1);
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<View style={{ gap: tokens.spacing.xs }}>
|
|
58
|
+
<View
|
|
59
|
+
style={{
|
|
60
|
+
flexDirection: "row",
|
|
61
|
+
justifyContent: "space-between",
|
|
62
|
+
alignItems: "center",
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<AtomicText type="labelMedium" color="textSecondary">
|
|
66
|
+
{label}
|
|
67
|
+
</AtomicText>
|
|
68
|
+
<AtomicText type="labelMedium" color="primary" fontWeight="bold">
|
|
69
|
+
{displayValue}
|
|
70
|
+
</AtomicText>
|
|
71
|
+
</View>
|
|
72
|
+
<GestureDetector gesture={panGesture}>
|
|
73
|
+
<View
|
|
74
|
+
style={{ height: 44, justifyContent: "center", paddingHorizontal: 12 }}
|
|
75
|
+
onLayout={(e) => {
|
|
76
|
+
const w = Math.max(1, e.nativeEvent.layout.width - 24);
|
|
77
|
+
setTrackWidth(w);
|
|
78
|
+
trackWidthRef.current = w;
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<View
|
|
82
|
+
style={{
|
|
83
|
+
height: 4,
|
|
84
|
+
backgroundColor: tokens.colors.surfaceVariant,
|
|
85
|
+
borderRadius: 2,
|
|
86
|
+
}}
|
|
87
|
+
>
|
|
88
|
+
<View
|
|
89
|
+
style={{
|
|
90
|
+
width: `${percent * 100}%`,
|
|
91
|
+
height: "100%",
|
|
92
|
+
backgroundColor: tokens.colors.primary,
|
|
93
|
+
borderRadius: 2,
|
|
94
|
+
}}
|
|
95
|
+
/>
|
|
96
|
+
</View>
|
|
97
|
+
<View
|
|
98
|
+
style={{
|
|
99
|
+
position: "absolute",
|
|
100
|
+
left: thumbOffset + 12,
|
|
101
|
+
width: 24,
|
|
102
|
+
height: 24,
|
|
103
|
+
borderRadius: 12,
|
|
104
|
+
backgroundColor: tokens.colors.primary,
|
|
105
|
+
borderWidth: 2.5,
|
|
106
|
+
borderColor: tokens.colors.surface,
|
|
107
|
+
top: 10,
|
|
108
|
+
}}
|
|
109
|
+
/>
|
|
110
|
+
</View>
|
|
111
|
+
</GestureDetector>
|
|
112
|
+
</View>
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
Slider.displayName = "Slider";
|
package/src/types.ts
CHANGED
|
@@ -1,70 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Legacy Types (for backward compatibility)
|
|
3
|
+
*
|
|
4
|
+
* @deprecated Use types from src/domain/entities/ instead
|
|
3
5
|
*/
|
|
4
6
|
|
|
5
|
-
export type TextAlign
|
|
7
|
+
export type { TextAlign } from "./domain/entities/Layer";
|
|
8
|
+
export type { Layer, TextLayer, StickerLayer } from "./domain/entities/Layer";
|
|
9
|
+
export type { Transform } from "./domain/entities/Transform";
|
|
10
|
+
export type { FilterValues as ImageFilters, DEFAULT_FILTERS as DEFAULT_IMAGE_FILTERS } from "./domain/entities/Filters";
|
|
6
11
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
contrast: number;
|
|
10
|
-
saturation: number;
|
|
11
|
-
sepia: number;
|
|
12
|
-
grayscale: number;
|
|
13
|
-
hueRotate?: number; // 0-360 degrees
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const DEFAULT_IMAGE_FILTERS: ImageFilters = {
|
|
17
|
-
brightness: 1,
|
|
18
|
-
contrast: 1,
|
|
19
|
-
saturation: 1,
|
|
20
|
-
sepia: 0,
|
|
21
|
-
grayscale: 0,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export interface BaseLayer {
|
|
25
|
-
id: string;
|
|
26
|
-
x: number;
|
|
27
|
-
y: number;
|
|
28
|
-
rotation: number;
|
|
29
|
-
scale: number;
|
|
30
|
-
opacity: number;
|
|
31
|
-
zIndex: number;
|
|
32
|
-
type: "text" | "sticker";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface TextLayer extends BaseLayer {
|
|
36
|
-
type: "text";
|
|
37
|
-
text: string;
|
|
38
|
-
fontSize: number;
|
|
39
|
-
fontFamily: string;
|
|
40
|
-
color: string;
|
|
41
|
-
backgroundColor: string;
|
|
42
|
-
textAlign: TextAlign;
|
|
43
|
-
isBold?: boolean;
|
|
44
|
-
isItalic?: boolean;
|
|
45
|
-
strokeColor?: string;
|
|
46
|
-
strokeWidth?: number;
|
|
47
|
-
}
|
|
12
|
+
// Re-export type guards
|
|
13
|
+
export { isTextLayer, isStickerLayer } from "./domain/entities/Layer";
|
|
48
14
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export type Layer = TextLayer | StickerLayer;
|
|
15
|
+
// Legacy type alias
|
|
16
|
+
export interface TextLayerData extends TextLayer {}
|
|
17
|
+
export interface StickerLayerData extends StickerLayer {}
|
|
55
18
|
|
|
19
|
+
// Legacy EditorState (kept for compatibility)
|
|
56
20
|
export interface EditorState {
|
|
57
21
|
layers: Layer[];
|
|
58
22
|
activeLayerId: string | null;
|
|
59
23
|
canvasSize: { width: number; height: number };
|
|
60
24
|
filters: ImageFilters;
|
|
61
25
|
}
|
|
62
|
-
|
|
63
|
-
// Type guards for discriminating union types
|
|
64
|
-
export function isTextLayer(layer: Layer): layer is TextLayer {
|
|
65
|
-
return layer.type === "text";
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function isStickerLayer(layer: Layer): layer is StickerLayer {
|
|
69
|
-
return layer.type === "sticker";
|
|
70
|
-
}
|