@antscorp/antsomi-ui 1.3.5-beta.261 → 1.3.5-beta.263
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/es/components/common/ConfigProvider/GlobalStyle.js +5 -0
- package/es/components/molecules/ImageEditor/ImageEditor.d.ts +18 -0
- package/es/components/molecules/ImageEditor/ImageEditor.js +774 -0
- package/es/components/molecules/ImageEditor/index.d.ts +1 -7
- package/es/components/molecules/ImageEditor/index.js +1 -555
- package/es/components/molecules/ImageEditor/reducer.d.ts +1 -1
- package/es/components/molecules/ImageEditor/styled.d.ts +4 -3
- package/es/components/molecules/ImageEditor/styled.js +12 -6
- package/es/components/molecules/ImageResizeTuiEditor/ImageResizeTuiEditor.d.ts +12 -0
- package/es/components/molecules/ImageResizeTuiEditor/ImageResizeTuiEditor.js +73 -0
- package/es/components/molecules/ImageResizeTuiEditor/index.d.ts +1 -0
- package/es/components/molecules/ImageResizeTuiEditor/index.js +1 -0
- package/es/components/molecules/ImageResizeTuiEditor/types.d.ts +5 -0
- package/es/components/molecules/ImageResizeTuiEditor/types.js +1 -0
- package/es/components/molecules/TemplateSaveAs/TemplateSaveAs.d.ts +4 -0
- package/es/components/molecules/TemplateSaveAs/TemplateSaveAs.js +5 -3
- package/es/components/molecules/TemplateSaveAs/components/ImageSlider/BigImage.d.ts +2 -0
- package/es/components/molecules/TemplateSaveAs/components/ImageSlider/BigImage.js +12 -6
- package/es/components/molecules/TemplateSaveAs/components/ImageSlider/ImageSlider.d.ts +5 -0
- package/es/components/molecules/TemplateSaveAs/components/ImageSlider/ImageSlider.js +92 -8
- package/es/components/molecules/TemplateSaveAs/components/ImageSlider/styled.js +70 -5
- package/es/components/molecules/TemplateSaveAs/styled.js +22 -0
- package/es/components/molecules/index.d.ts +2 -0
- package/es/components/molecules/index.js +1 -0
- package/es/providers/ConfigProvider/GlobalStyle.js +5 -0
- package/es/test.js +4 -4
- package/package.json +2 -1
|
@@ -1,555 +1 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/* eslint-disable default-case */
|
|
11
|
-
import Icon from '@antscorp/icons';
|
|
12
|
-
import { Flex } from 'antd';
|
|
13
|
-
import * as Konva from 'konva';
|
|
14
|
-
import { cloneDeep } from 'lodash';
|
|
15
|
-
import React, { useCallback, useReducer, useRef, useState } from 'react';
|
|
16
|
-
import { SketchPicker } from 'react-color';
|
|
17
|
-
import { Arrow as KonvaArrow, Circle as KonvaCircle, Image as KonvaImage, Line as KonvaLine, Rect as KonvaRect, Layer, Stage, Transformer, } from 'react-konva';
|
|
18
|
-
import { v4 as uuidV4 } from 'uuid';
|
|
19
|
-
import { Button, Popover } from '../../atoms';
|
|
20
|
-
import ModalShortcut from './components/ModalShortcut';
|
|
21
|
-
import { useDropFile, useKeyEventCanvas } from '@antscorp/antsomi-ui/es/hooks';
|
|
22
|
-
import { DEFAULT_TRANSFORM, DrawAction, PAINT_OPTIONS, ShapeObject } from './constants';
|
|
23
|
-
import { initialReducer, reducer } from './reducer';
|
|
24
|
-
import { IconButtonStyled } from './styled';
|
|
25
|
-
import { downloadURI, getTransformData } from './utils';
|
|
26
|
-
export const ImageEditor = React.memo(({ width, height }) => {
|
|
27
|
-
const [color, setColor] = useState('#000');
|
|
28
|
-
const [drawAction, setDrawAction] = useState(DrawAction.Select);
|
|
29
|
-
const [cropZone, setCropZone] = useState();
|
|
30
|
-
const [selectedId, setSelectedId] = useState();
|
|
31
|
-
const [selectedShape, setSelectedShape] = useState();
|
|
32
|
-
const [openHelper, setOpenHelper] = useState(false);
|
|
33
|
-
// TODO: START - handle selection
|
|
34
|
-
const [selectionPosition, setSelectionPosition] = useState({
|
|
35
|
-
x: 0,
|
|
36
|
-
y: 0,
|
|
37
|
-
width: 0,
|
|
38
|
-
height: 0,
|
|
39
|
-
visible: false,
|
|
40
|
-
});
|
|
41
|
-
// Konva.default.Util.haveIntersection
|
|
42
|
-
const [state, dispatch] = useReducer(reducer, initialReducer);
|
|
43
|
-
const { current: { arrows, circles, imageCoordinate, rectangles, scribbles, image }, } = state;
|
|
44
|
-
const stageRef = useRef(null);
|
|
45
|
-
const transformerRef = useRef(null);
|
|
46
|
-
const selectionRectangleRef = useRef(null);
|
|
47
|
-
const isPaintRef = useRef(false);
|
|
48
|
-
const changeImage = useCallback((imageUrl) => {
|
|
49
|
-
const image = new Image();
|
|
50
|
-
image.src = imageUrl;
|
|
51
|
-
image.decode().then(() => {
|
|
52
|
-
const originalWidth = image.width;
|
|
53
|
-
const originalHeight = image.height;
|
|
54
|
-
const ratio = originalWidth / originalHeight;
|
|
55
|
-
image.width = originalWidth > originalHeight ? width * 0.8 : height * 0.96 * ratio;
|
|
56
|
-
image.height = originalWidth > originalHeight ? (width * 0.8) / ratio : height * 0.96;
|
|
57
|
-
dispatch({
|
|
58
|
-
type: 'SET_NEW_STATE',
|
|
59
|
-
payload: {
|
|
60
|
-
image,
|
|
61
|
-
imageCoordinate: Object.assign(Object.assign({}, imageCoordinate), { id: uuidV4(), x: (width - image.width) / 2, y: (height - image.height) / 2, width: image.width, height: image.height }),
|
|
62
|
-
saveHistory: true,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}, [height, width, imageCoordinate]);
|
|
67
|
-
const onImportImageSelect = useCallback((e) => {
|
|
68
|
-
var _a;
|
|
69
|
-
if ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0]) {
|
|
70
|
-
changeImage(URL.createObjectURL(e.target.files[0]));
|
|
71
|
-
}
|
|
72
|
-
e.target.files = null;
|
|
73
|
-
}, [changeImage]);
|
|
74
|
-
const fileRef = useRef(null);
|
|
75
|
-
const onImportImageClick = useCallback(() => {
|
|
76
|
-
var _a;
|
|
77
|
-
(_a = fileRef === null || fileRef === void 0 ? void 0 : fileRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
78
|
-
}, []);
|
|
79
|
-
const onExportClick = useCallback(() => {
|
|
80
|
-
var _a;
|
|
81
|
-
const dataUri = (_a = stageRef === null || stageRef === void 0 ? void 0 : stageRef.current) === null || _a === void 0 ? void 0 : _a.toDataURL();
|
|
82
|
-
downloadURI(dataUri, 'image.png');
|
|
83
|
-
}, []);
|
|
84
|
-
const onClear = useCallback(() => {
|
|
85
|
-
var _a;
|
|
86
|
-
dispatch({ type: 'SET_RECTANGLES', payload: { rectangles: [] } });
|
|
87
|
-
dispatch({ type: 'SET_CIRCLES', payload: { circles: [] } });
|
|
88
|
-
dispatch({ type: 'SET_SCRIBBLES', payload: { scribbles: [] } });
|
|
89
|
-
dispatch({ type: 'SET_ARROWS', payload: { arrows: [] } });
|
|
90
|
-
dispatch({ type: 'SET_IMAGE', payload: { image: undefined, saveHistory: true } });
|
|
91
|
-
setCropZone(undefined);
|
|
92
|
-
setDrawAction(DrawAction.Select);
|
|
93
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
94
|
-
}, []);
|
|
95
|
-
const removeOrDuplicateShape = useCallback((isDuplicate) => {
|
|
96
|
-
var _a;
|
|
97
|
-
if (!selectedShape)
|
|
98
|
-
return;
|
|
99
|
-
switch (selectedShape) {
|
|
100
|
-
case ShapeObject.Arrows: {
|
|
101
|
-
const currSelect = arrows.findIndex(item => item.id === selectedId);
|
|
102
|
-
if (isDuplicate)
|
|
103
|
-
dispatch({
|
|
104
|
-
type: 'SET_ARROWS',
|
|
105
|
-
payload: {
|
|
106
|
-
saveHistory: true,
|
|
107
|
-
arrows: [
|
|
108
|
-
...arrows,
|
|
109
|
-
Object.assign(Object.assign({}, arrows[currSelect]), { points: arrows[currSelect].points.map((item, idx) => idx % 2 === 0 ? item + 25 : item + 10), id: uuidV4() }),
|
|
110
|
-
],
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
else {
|
|
114
|
-
const cloneObject = cloneDeep(arrows);
|
|
115
|
-
cloneObject.splice(currSelect, 1);
|
|
116
|
-
dispatch({ type: 'SET_ARROWS', payload: { saveHistory: true, arrows: cloneObject } });
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
case ShapeObject.Scribbles: {
|
|
121
|
-
const currSelect = scribbles.findIndex(item => item.id === selectedId);
|
|
122
|
-
if (isDuplicate) {
|
|
123
|
-
dispatch({
|
|
124
|
-
type: 'SET_SCRIBBLES',
|
|
125
|
-
payload: {
|
|
126
|
-
saveHistory: true,
|
|
127
|
-
scribbles: [
|
|
128
|
-
...scribbles,
|
|
129
|
-
Object.assign(Object.assign({}, scribbles[currSelect]), { points: scribbles[currSelect].points.map(item => item + 25), id: uuidV4() }),
|
|
130
|
-
],
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
const cloneObject = cloneDeep(scribbles);
|
|
136
|
-
cloneObject.splice(currSelect, 1);
|
|
137
|
-
dispatch({
|
|
138
|
-
type: 'SET_SCRIBBLES',
|
|
139
|
-
payload: { saveHistory: true, scribbles: cloneObject },
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case ShapeObject.Rectangles: {
|
|
145
|
-
const currSelect = rectangles.findIndex(item => item.id === selectedId);
|
|
146
|
-
if (isDuplicate) {
|
|
147
|
-
dispatch({
|
|
148
|
-
type: 'SET_RECTANGLES',
|
|
149
|
-
payload: {
|
|
150
|
-
saveHistory: true,
|
|
151
|
-
rectangles: [
|
|
152
|
-
...rectangles,
|
|
153
|
-
Object.assign(Object.assign({}, rectangles[currSelect]), { x: rectangles[currSelect].x + 25, y: rectangles[currSelect].y + 25, id: uuidV4() }),
|
|
154
|
-
],
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
const cloneObject = cloneDeep(rectangles);
|
|
160
|
-
cloneObject.splice(currSelect, 1);
|
|
161
|
-
dispatch({
|
|
162
|
-
type: 'SET_RECTANGLES',
|
|
163
|
-
payload: { saveHistory: true, rectangles: cloneObject },
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
case ShapeObject.Circles: {
|
|
169
|
-
const currSelect = circles.findIndex(item => item.id === selectedId);
|
|
170
|
-
if (isDuplicate) {
|
|
171
|
-
dispatch({
|
|
172
|
-
type: 'SET_CIRCLES',
|
|
173
|
-
payload: {
|
|
174
|
-
saveHistory: true,
|
|
175
|
-
circles: [
|
|
176
|
-
...circles,
|
|
177
|
-
Object.assign(Object.assign({}, circles[currSelect]), { x: circles[currSelect].x + 25, y: circles[currSelect].y + 25, id: uuidV4() }),
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
const cloneObject = cloneDeep(circles);
|
|
184
|
-
cloneObject.splice(currSelect, 1);
|
|
185
|
-
dispatch({ type: 'SET_CIRCLES', payload: { saveHistory: true, circles: cloneObject } });
|
|
186
|
-
}
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
case ShapeObject.Image: {
|
|
190
|
-
if (isDuplicate)
|
|
191
|
-
return;
|
|
192
|
-
dispatch({ type: 'SET_IMAGE', payload: { image: undefined, saveHistory: true } });
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
setSelectedId(undefined);
|
|
197
|
-
setSelectedShape(undefined);
|
|
198
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
199
|
-
}, [arrows, circles, rectangles, scribbles, selectedId, selectedShape]);
|
|
200
|
-
useKeyEventCanvas('keydown', event => {
|
|
201
|
-
var _a, _b;
|
|
202
|
-
event.preventDefault();
|
|
203
|
-
switch (true) {
|
|
204
|
-
case event.code === 'Delete':
|
|
205
|
-
removeOrDuplicateShape();
|
|
206
|
-
break;
|
|
207
|
-
case event.code === 'KeyD' && event.ctrlKey:
|
|
208
|
-
removeOrDuplicateShape(true);
|
|
209
|
-
break;
|
|
210
|
-
case event.code === 'KeyZ' && event.ctrlKey && !event.shiftKey:
|
|
211
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
212
|
-
dispatch({ type: 'UNDO' });
|
|
213
|
-
break;
|
|
214
|
-
case event.code === 'KeyZ' && event.ctrlKey && event.shiftKey:
|
|
215
|
-
(_b = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _b === void 0 ? void 0 : _b.nodes([]);
|
|
216
|
-
dispatch({ type: 'REDO' });
|
|
217
|
-
break;
|
|
218
|
-
case event.code === 'KeyV' && event.ctrlKey:
|
|
219
|
-
navigator.clipboard.read().then(clipboardContents => {
|
|
220
|
-
if (!clipboardContents[0].types.includes('image/png'))
|
|
221
|
-
return;
|
|
222
|
-
clipboardContents[0]
|
|
223
|
-
.getType('image/png')
|
|
224
|
-
.then(blob => changeImage(URL.createObjectURL(blob)));
|
|
225
|
-
});
|
|
226
|
-
break;
|
|
227
|
-
default:
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
useDropFile('#image-editor', e => {
|
|
232
|
-
var _a, _b;
|
|
233
|
-
if (!((_a = e === null || e === void 0 ? void 0 : e.dataTransfer) === null || _a === void 0 ? void 0 : _a.files[0]))
|
|
234
|
-
return;
|
|
235
|
-
changeImage(URL.createObjectURL((_b = e === null || e === void 0 ? void 0 : e.dataTransfer) === null || _b === void 0 ? void 0 : _b.files[0]));
|
|
236
|
-
});
|
|
237
|
-
const onStageMouseUp = useCallback(() => {
|
|
238
|
-
var _a, _b, _c;
|
|
239
|
-
isPaintRef.current = false;
|
|
240
|
-
if (drawAction !== DrawAction.Select)
|
|
241
|
-
dispatch({ type: 'SAVE_HISTORY' });
|
|
242
|
-
if (selectionPosition.visible) {
|
|
243
|
-
setSelectionPosition(prev => (Object.assign(Object.assign({}, prev), { visible: false })));
|
|
244
|
-
const shapes = (_a = stageRef.current) === null || _a === void 0 ? void 0 : _a.find('.shape');
|
|
245
|
-
const box = (_b = selectionRectangleRef.current) === null || _b === void 0 ? void 0 : _b.getClientRect();
|
|
246
|
-
const selected = shapes.filter(shape => Konva.default.Util.haveIntersection(box, shape.getClientRect()));
|
|
247
|
-
(_c = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _c === void 0 ? void 0 : _c.nodes(selected);
|
|
248
|
-
}
|
|
249
|
-
}, [drawAction, selectionPosition.visible]);
|
|
250
|
-
const currentShapeRef = useRef();
|
|
251
|
-
const onStageMouseDown = useCallback(() => {
|
|
252
|
-
if (drawAction !== DrawAction.Crop)
|
|
253
|
-
setCropZone(undefined);
|
|
254
|
-
// if (drawAction === DrawAction.Select) return;
|
|
255
|
-
isPaintRef.current = true;
|
|
256
|
-
const stage = stageRef === null || stageRef === void 0 ? void 0 : stageRef.current;
|
|
257
|
-
const pos = stage === null || stage === void 0 ? void 0 : stage.getPointerPosition();
|
|
258
|
-
const x = (pos === null || pos === void 0 ? void 0 : pos.x) || 0;
|
|
259
|
-
const y = (pos === null || pos === void 0 ? void 0 : pos.y) || 0;
|
|
260
|
-
const id = uuidV4();
|
|
261
|
-
currentShapeRef.current = id;
|
|
262
|
-
switch (drawAction) {
|
|
263
|
-
case DrawAction.Select: {
|
|
264
|
-
setSelectionPosition({ x, y, width: 1, height: 1, visible: false });
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
case DrawAction.Scribble: {
|
|
268
|
-
dispatch({
|
|
269
|
-
type: 'SET_SCRIBBLES',
|
|
270
|
-
payload: {
|
|
271
|
-
scribbles: [...scribbles, Object.assign({ id, points: [x, y], color }, DEFAULT_TRANSFORM)],
|
|
272
|
-
},
|
|
273
|
-
});
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case DrawAction.Circle: {
|
|
277
|
-
dispatch({
|
|
278
|
-
type: 'SET_CIRCLES',
|
|
279
|
-
payload: {
|
|
280
|
-
circles: [...circles, Object.assign({ id, x, y, radius: 1, color }, DEFAULT_TRANSFORM)],
|
|
281
|
-
},
|
|
282
|
-
});
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
case DrawAction.Rectangle: {
|
|
286
|
-
dispatch({
|
|
287
|
-
type: 'SET_RECTANGLES',
|
|
288
|
-
payload: {
|
|
289
|
-
rectangles: [
|
|
290
|
-
...rectangles,
|
|
291
|
-
Object.assign({ id, x, y, width: 1, height: 1, color }, DEFAULT_TRANSFORM),
|
|
292
|
-
],
|
|
293
|
-
},
|
|
294
|
-
});
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
case DrawAction.Crop: {
|
|
298
|
-
setCropZone({ id, x, y, width: 1, height: 1 });
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
case DrawAction.Arrow: {
|
|
302
|
-
dispatch({
|
|
303
|
-
type: 'SET_ARROWS',
|
|
304
|
-
payload: {
|
|
305
|
-
arrows: [...arrows, Object.assign({ id, points: [x, y, x, y], color }, DEFAULT_TRANSFORM)],
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}, [drawAction, color, arrows, circles, rectangles, scribbles]);
|
|
312
|
-
const onStageMouseMove = useCallback(() => {
|
|
313
|
-
if (!isPaintRef.current)
|
|
314
|
-
return;
|
|
315
|
-
const stage = stageRef === null || stageRef === void 0 ? void 0 : stageRef.current;
|
|
316
|
-
const id = currentShapeRef.current;
|
|
317
|
-
const pos = stage === null || stage === void 0 ? void 0 : stage.getPointerPosition();
|
|
318
|
-
const x = (pos === null || pos === void 0 ? void 0 : pos.x) || 0;
|
|
319
|
-
const y = (pos === null || pos === void 0 ? void 0 : pos.y) || 0;
|
|
320
|
-
switch (drawAction) {
|
|
321
|
-
case DrawAction.Select: {
|
|
322
|
-
// setSelectionVisible(true);
|
|
323
|
-
setSelectionPosition(prev => (Object.assign(Object.assign({}, prev), { width: x - prev.x, height: y - prev.y, visible: Math.abs(x - prev.x) > 4 || Math.abs(y - prev.y) > 4 })));
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
case DrawAction.Scribble: {
|
|
327
|
-
dispatch({
|
|
328
|
-
type: 'SET_SCRIBBLES',
|
|
329
|
-
payload: {
|
|
330
|
-
scribbles: scribbles === null || scribbles === void 0 ? void 0 : scribbles.map(prevScribble => prevScribble.id === id
|
|
331
|
-
? Object.assign(Object.assign({}, prevScribble), { points: [...prevScribble.points, x, y] }) : prevScribble),
|
|
332
|
-
},
|
|
333
|
-
});
|
|
334
|
-
break;
|
|
335
|
-
}
|
|
336
|
-
case DrawAction.Circle: {
|
|
337
|
-
dispatch({
|
|
338
|
-
type: 'SET_CIRCLES',
|
|
339
|
-
payload: {
|
|
340
|
-
circles: circles === null || circles === void 0 ? void 0 : circles.map(prevCircle => prevCircle.id === id
|
|
341
|
-
? Object.assign(Object.assign({}, prevCircle), { radius: Math.pow((Math.pow((x - prevCircle.x), 2) + Math.pow((y - prevCircle.y), 2)), 0.5) }) : prevCircle),
|
|
342
|
-
},
|
|
343
|
-
});
|
|
344
|
-
break;
|
|
345
|
-
}
|
|
346
|
-
case DrawAction.Rectangle: {
|
|
347
|
-
dispatch({
|
|
348
|
-
type: 'SET_RECTANGLES',
|
|
349
|
-
payload: {
|
|
350
|
-
rectangles: rectangles === null || rectangles === void 0 ? void 0 : rectangles.map(prevRectangle => prevRectangle.id === id
|
|
351
|
-
? Object.assign(Object.assign({}, prevRectangle), { height: y - prevRectangle.y, width: x - prevRectangle.x }) : prevRectangle),
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
case DrawAction.Crop: {
|
|
357
|
-
setCropZone(prevRectangle => prevRectangle
|
|
358
|
-
? Object.assign(Object.assign({}, prevRectangle), { height: y - prevRectangle.y, width: x - prevRectangle.x }) : prevRectangle);
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
case DrawAction.Arrow: {
|
|
362
|
-
dispatch({
|
|
363
|
-
type: 'SET_ARROWS',
|
|
364
|
-
payload: {
|
|
365
|
-
arrows: arrows.map(prevArrow => prevArrow.id === id
|
|
366
|
-
? Object.assign(Object.assign({}, prevArrow), { points: [prevArrow.points[0], prevArrow.points[1], x, y] }) : prevArrow),
|
|
367
|
-
},
|
|
368
|
-
});
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}, [drawAction, arrows, circles, rectangles, scribbles]);
|
|
373
|
-
const onApplyCropClick = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
374
|
-
var _a;
|
|
375
|
-
if (!cropZone)
|
|
376
|
-
return;
|
|
377
|
-
const dataUri = yield ((_a = stageRef === null || stageRef === void 0 ? void 0 : stageRef.current) === null || _a === void 0 ? void 0 : _a.toDataURL({
|
|
378
|
-
x: (cropZone === null || cropZone === void 0 ? void 0 : cropZone.x) + 2,
|
|
379
|
-
y: (cropZone === null || cropZone === void 0 ? void 0 : cropZone.y) + 2,
|
|
380
|
-
width: (cropZone === null || cropZone === void 0 ? void 0 : cropZone.width) - 4,
|
|
381
|
-
height: (cropZone === null || cropZone === void 0 ? void 0 : cropZone.height) - 4,
|
|
382
|
-
}));
|
|
383
|
-
onClear();
|
|
384
|
-
changeImage(dataUri);
|
|
385
|
-
}), [cropZone, changeImage, onClear]);
|
|
386
|
-
const onShapeClick = useCallback((e, id, shape) => {
|
|
387
|
-
var _a;
|
|
388
|
-
if (drawAction !== DrawAction.Select)
|
|
389
|
-
return;
|
|
390
|
-
const { currentTarget } = e || {};
|
|
391
|
-
setSelectedId(id);
|
|
392
|
-
setSelectedShape(shape);
|
|
393
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([currentTarget]);
|
|
394
|
-
}, [drawAction]);
|
|
395
|
-
const isDraggable = drawAction === DrawAction.Select;
|
|
396
|
-
const onBgClick = useCallback(() => {
|
|
397
|
-
var _a;
|
|
398
|
-
if (selectionPosition.visible)
|
|
399
|
-
return;
|
|
400
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
401
|
-
}, [selectionPosition.visible]);
|
|
402
|
-
return (React.createElement("div", { style: { width: `${width}px` } },
|
|
403
|
-
React.createElement(Flex, { justify: "space-between", align: "center", style: { marginBottom: '6px' } },
|
|
404
|
-
React.createElement(Flex, { gap: 4 },
|
|
405
|
-
PAINT_OPTIONS.map(({ id, label, icon }) => (React.createElement(IconButtonStyled, { key: id, "aria-label": label, icon: React.createElement(Icon, { type: icon, style: { fontSize: '16px' } }), onClick: () => {
|
|
406
|
-
var _a;
|
|
407
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
408
|
-
setCropZone(undefined);
|
|
409
|
-
setDrawAction(id);
|
|
410
|
-
}, type: id === drawAction ? 'primary' : 'default' }))),
|
|
411
|
-
React.createElement(Popover, { content: React.createElement(SketchPicker, { color: color, onChangeComplete: selectedColor => setColor(selectedColor.hex) }) },
|
|
412
|
-
React.createElement("div", { style: {
|
|
413
|
-
backgroundColor: color,
|
|
414
|
-
height: '30px',
|
|
415
|
-
width: '30px',
|
|
416
|
-
borderRadius: '3px',
|
|
417
|
-
cursor: 'pointer',
|
|
418
|
-
} })),
|
|
419
|
-
React.createElement(IconButtonStyled, { "aria-label": "Clear", icon: React.createElement(Icon, { type: "icon-ants-remove-circle", style: { fontSize: '16px' } }), onClick: onClear })),
|
|
420
|
-
React.createElement(Flex, { gap: 4, align: "center", style: { height: '100%' } },
|
|
421
|
-
React.createElement(IconButtonStyled, { "aria-label": "Help", icon: React.createElement(Icon, { type: "icon-ants-help", style: { fontSize: '16px' } }), onClick: () => setOpenHelper(true) }),
|
|
422
|
-
React.createElement("input", { type: "file", ref: fileRef, onChange: onImportImageSelect, style: { display: 'none' }, accept: "image/*" }),
|
|
423
|
-
React.createElement(Button, { onClick: onImportImageClick }, "Import Image"),
|
|
424
|
-
React.createElement(Button, { onClick: onExportClick }, "Export"))),
|
|
425
|
-
React.createElement(Flex, { gap: 4 },
|
|
426
|
-
React.createElement(Button, { onClick: () => {
|
|
427
|
-
var _a;
|
|
428
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
429
|
-
setDrawAction(DrawAction.Crop);
|
|
430
|
-
}, type: DrawAction.Crop === drawAction ? 'primary' : 'default' }, "Crop"),
|
|
431
|
-
DrawAction.Crop === drawAction ? (React.createElement(React.Fragment, null,
|
|
432
|
-
React.createElement(Button, { onClick: () => setCropZone(undefined), danger: true }, "Cancel Crop"),
|
|
433
|
-
React.createElement(Button, { onClick: () => onApplyCropClick() }, "Apply Crop"))) : null,
|
|
434
|
-
React.createElement(Button, { onClick: () => {
|
|
435
|
-
var _a;
|
|
436
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
437
|
-
dispatch({ type: 'UNDO' });
|
|
438
|
-
}, style: { marginLeft: 'auto' } }, "Undo"),
|
|
439
|
-
React.createElement(Button, { onClick: () => {
|
|
440
|
-
var _a;
|
|
441
|
-
(_a = transformerRef === null || transformerRef === void 0 ? void 0 : transformerRef.current) === null || _a === void 0 ? void 0 : _a.nodes([]);
|
|
442
|
-
dispatch({ type: 'REDO' });
|
|
443
|
-
} }, "Redo")),
|
|
444
|
-
React.createElement(Flex, { style: {
|
|
445
|
-
width: `${width}px`,
|
|
446
|
-
height: `${height}px`,
|
|
447
|
-
border: '1px solid #666',
|
|
448
|
-
marginTop: '16px',
|
|
449
|
-
} },
|
|
450
|
-
React.createElement(Stage, { id: "image-editor", width: width, height: height, ref: stageRef, onMouseUp: onStageMouseUp, onMouseDown: onStageMouseDown, onMouseMove: onStageMouseMove },
|
|
451
|
-
React.createElement(Layer, null,
|
|
452
|
-
React.createElement(KonvaRect, { x: 0, y: 0, height: width, width: height, fill: "white", id: "bg", onClick: onBgClick }),
|
|
453
|
-
image && (React.createElement(KonvaImage, Object.assign({ image: image }, imageCoordinate, { name: "shape", onClick: e => onShapeClick(e, imageCoordinate.id, ShapeObject.Image), onTap: e => onShapeClick(e, imageCoordinate.id, ShapeObject.Image), draggable: isDraggable, onDragEnd: ({ target: { attrs } }) => {
|
|
454
|
-
if (isDraggable)
|
|
455
|
-
dispatch({
|
|
456
|
-
type: 'SET_IMAGE_COORDINATE',
|
|
457
|
-
payload: {
|
|
458
|
-
imageCoordinate: Object.assign(Object.assign({}, imageCoordinate), { x: attrs.x, y: attrs.y }),
|
|
459
|
-
saveHistory: true,
|
|
460
|
-
},
|
|
461
|
-
});
|
|
462
|
-
}, onTransformEnd: e => {
|
|
463
|
-
dispatch({
|
|
464
|
-
type: 'SET_IMAGE_COORDINATE',
|
|
465
|
-
payload: {
|
|
466
|
-
imageCoordinate: Object.assign(Object.assign(Object.assign({}, imageCoordinate), { width: e.target.width(), height: e.target.height() }), getTransformData(e)),
|
|
467
|
-
saveHistory: true,
|
|
468
|
-
},
|
|
469
|
-
});
|
|
470
|
-
} }))),
|
|
471
|
-
arrows.map(arrow => (React.createElement(KonvaArrow, Object.assign({ key: arrow.id }, arrow, { name: "shape", fill: arrow.color, stroke: arrow.color, strokeWidth: 4, onClick: e => onShapeClick(e, arrow.id, ShapeObject.Arrows), onTap: e => onShapeClick(e, arrow.id, ShapeObject.Arrows), draggable: isDraggable, strokeScaleEnabled: false, onDragEnd: ({ target: { attrs } }) => {
|
|
472
|
-
if (isDraggable)
|
|
473
|
-
dispatch({
|
|
474
|
-
type: 'SET_ARROWS',
|
|
475
|
-
payload: {
|
|
476
|
-
arrows: arrows.map(item => item.id === arrow.id ? Object.assign(Object.assign({}, item), { x: attrs.x, y: attrs.y }) : item),
|
|
477
|
-
saveHistory: true,
|
|
478
|
-
},
|
|
479
|
-
});
|
|
480
|
-
}, onTransformEnd: e => {
|
|
481
|
-
dispatch({
|
|
482
|
-
type: 'SET_ARROWS',
|
|
483
|
-
payload: {
|
|
484
|
-
arrows: arrows.map(item => item.id === arrow.id
|
|
485
|
-
? Object.assign(Object.assign(Object.assign({}, item), { points: e.target.attrs.points }), getTransformData(e)) : item),
|
|
486
|
-
saveHistory: true,
|
|
487
|
-
},
|
|
488
|
-
});
|
|
489
|
-
} })))),
|
|
490
|
-
rectangles.map(rectangle => (React.createElement(KonvaRect, Object.assign({ key: rectangle.id }, rectangle, { name: "shape", stroke: rectangle === null || rectangle === void 0 ? void 0 : rectangle.color, strokeWidth: 4, onClick: e => onShapeClick(e, rectangle.id, ShapeObject.Rectangles), onTap: e => onShapeClick(e, rectangle.id, ShapeObject.Rectangles), draggable: isDraggable, strokeScaleEnabled: false, onDragEnd: ({ target: { attrs } }) => {
|
|
491
|
-
if (isDraggable)
|
|
492
|
-
dispatch({
|
|
493
|
-
type: 'SET_RECTANGLES',
|
|
494
|
-
payload: {
|
|
495
|
-
rectangles: rectangles.map(item => item.id === rectangle.id ? Object.assign(Object.assign({}, item), { x: attrs.x, y: attrs.y }) : item),
|
|
496
|
-
saveHistory: true,
|
|
497
|
-
},
|
|
498
|
-
});
|
|
499
|
-
}, onTransformEnd: e => {
|
|
500
|
-
dispatch({
|
|
501
|
-
type: 'SET_RECTANGLES',
|
|
502
|
-
payload: {
|
|
503
|
-
rectangles: rectangles.map(item => item.id === rectangle.id
|
|
504
|
-
? Object.assign(Object.assign(Object.assign({}, item), { width: e.target.width(), height: e.target.height() }), getTransformData(e)) : item),
|
|
505
|
-
saveHistory: true,
|
|
506
|
-
},
|
|
507
|
-
});
|
|
508
|
-
} })))),
|
|
509
|
-
circles.map(circle => (React.createElement(KonvaCircle, Object.assign({ key: circle.id }, circle, { name: "shape", stroke: circle === null || circle === void 0 ? void 0 : circle.color, strokeWidth: 4, onClick: e => onShapeClick(e, circle.id, ShapeObject.Circles), onTap: e => onShapeClick(e, circle.id, ShapeObject.Circles), draggable: isDraggable, strokeScaleEnabled: false, onDragEnd: ({ target: { attrs } }) => {
|
|
510
|
-
if (isDraggable)
|
|
511
|
-
dispatch({
|
|
512
|
-
type: 'SET_CIRCLES',
|
|
513
|
-
payload: {
|
|
514
|
-
circles: circles.map(item => item.id === circle.id ? Object.assign(Object.assign({}, item), { x: attrs.x, y: attrs.y }) : item),
|
|
515
|
-
saveHistory: true,
|
|
516
|
-
},
|
|
517
|
-
});
|
|
518
|
-
}, onTransformEnd: e => {
|
|
519
|
-
dispatch({
|
|
520
|
-
type: 'SET_CIRCLES',
|
|
521
|
-
payload: {
|
|
522
|
-
circles: circles.map(item => item.id === circle.id
|
|
523
|
-
? Object.assign(Object.assign(Object.assign({}, item), { radius: e.target.attrs.radius }), getTransformData(e)) : item),
|
|
524
|
-
saveHistory: true,
|
|
525
|
-
},
|
|
526
|
-
});
|
|
527
|
-
} })))),
|
|
528
|
-
scribbles.map(scribble => (React.createElement(KonvaLine, Object.assign({ key: scribble.id }, scribble, { name: "shape", lineCap: "round", lineJoin: "round", stroke: scribble === null || scribble === void 0 ? void 0 : scribble.color, strokeWidth: 4, onClick: e => onShapeClick(e, scribble.id, ShapeObject.Scribbles), onTap: e => onShapeClick(e, scribble.id, ShapeObject.Scribbles), draggable: isDraggable, strokeScaleEnabled: false, onDragEnd: ({ target: { attrs } }) => {
|
|
529
|
-
if (isDraggable)
|
|
530
|
-
dispatch({
|
|
531
|
-
type: 'SET_SCRIBBLES',
|
|
532
|
-
payload: {
|
|
533
|
-
scribbles: scribbles.map(item => item.id === scribble.id ? Object.assign(Object.assign({}, item), { x: attrs.x, y: attrs.y }) : item),
|
|
534
|
-
saveHistory: true,
|
|
535
|
-
},
|
|
536
|
-
});
|
|
537
|
-
}, onTransformEnd: e => {
|
|
538
|
-
dispatch({
|
|
539
|
-
type: 'SET_SCRIBBLES',
|
|
540
|
-
payload: {
|
|
541
|
-
scribbles: scribbles.map(item => item.id === scribble.id
|
|
542
|
-
? Object.assign(Object.assign(Object.assign({}, item), { points: e.target.attrs.points }), getTransformData(e)) : item),
|
|
543
|
-
saveHistory: true,
|
|
544
|
-
},
|
|
545
|
-
});
|
|
546
|
-
} })))),
|
|
547
|
-
cropZone ? (React.createElement(KonvaRect, Object.assign({}, cropZone, { dashEnabled: true, dash: [6], stroke: "red", strokeWidth: 2 }))) : null,
|
|
548
|
-
React.createElement(KonvaRect, Object.assign({}, selectionPosition, { ref: selectionRectangleRef, fill: "rgba(0,0,200,0.4)" })),
|
|
549
|
-
React.createElement(Transformer, { ref: transformerRef, ignoreStroke: true }))),
|
|
550
|
-
DrawAction.Select === drawAction && selectedId ? (React.createElement(Flex, { style: { marginLeft: '16px' } },
|
|
551
|
-
React.createElement(Flex, { vertical: true, gap: 4 },
|
|
552
|
-
React.createElement(Button, { onClick: () => removeOrDuplicateShape(), icon: React.createElement(Icon, { type: "icon-ants-outline-delete" }), danger: true }),
|
|
553
|
-
React.createElement(Button, { onClick: () => removeOrDuplicateShape(true), icon: React.createElement(Icon, { type: "icon-ants-copy-report" }) })))) : null,
|
|
554
|
-
React.createElement(ModalShortcut, { open: openHelper, onCancel: () => setOpenHelper(false) }))));
|
|
555
|
-
});
|
|
1
|
+
export { ImageEditor } from './ImageEditor';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
export declare const
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const StageWrapperStyled: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/flex/interface").FlexProps<import("antd/es/_util/type").AnyObject> & import("react").RefAttributes<HTMLElement>>, any, {
|
|
3
|
+
$width: number;
|
|
4
|
+
$height: number;
|
|
5
|
+
}, never>;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
import {
|
|
3
|
-
export const IconButtonStyled = styled(Button)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { Flex } from '../../atoms';
|
|
3
|
+
// export const IconButtonStyled = styled(Button)`
|
|
4
|
+
// &.antsomi-btn-default.antsomi-btn-icon-only {
|
|
5
|
+
// width: 30px !important;
|
|
6
|
+
// height: 30px !important;
|
|
7
|
+
// }
|
|
8
|
+
// `;
|
|
9
|
+
export const StageWrapperStyled = styled(Flex) `
|
|
10
|
+
width: ${props => `${props.$width}px`};
|
|
11
|
+
height: ${props => `${props.$height}px`};
|
|
12
|
+
border: 1px solid #666;
|
|
13
|
+
margin-top: 16px;
|
|
8
14
|
`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ImageResizeHandle } from './types';
|
|
3
|
+
interface ImageResizeTuiEditorProps {
|
|
4
|
+
className: string;
|
|
5
|
+
imageUrl: string | undefined;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
defaultValue: any;
|
|
9
|
+
hideAction: boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const ImageResizeTuiEditor: React.ForwardRefExoticComponent<ImageResizeTuiEditorProps & React.RefAttributes<ImageResizeHandle>>;
|
|
12
|
+
export { ImageResizeTuiEditor };
|