@archireport/react-native-svg-draw 2.3.2 → 3.1.0

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 (50) hide show
  1. package/README.md +34 -35
  2. package/lib/commonjs/components/DrawCore/DrawContext.js +4 -1
  3. package/lib/commonjs/components/DrawCore/DrawContext.js.map +1 -1
  4. package/lib/commonjs/components/DrawCore/DrawPad.js +9 -3
  5. package/lib/commonjs/components/DrawCore/DrawPad.js.map +1 -1
  6. package/lib/commonjs/components/DrawCore/DrawProvider.js +16 -2
  7. package/lib/commonjs/components/DrawCore/DrawProvider.js.map +1 -1
  8. package/lib/commonjs/components/DrawCore/Item.js +12 -35
  9. package/lib/commonjs/components/DrawCore/Item.js.map +1 -1
  10. package/lib/commonjs/components/DrawCore/index.js +574 -576
  11. package/lib/commonjs/components/DrawCore/index.js.map +1 -1
  12. package/lib/commonjs/components/DrawCore/useDrawHook.js +15 -13
  13. package/lib/commonjs/components/DrawCore/useDrawHook.js.map +1 -1
  14. package/lib/commonjs/components/DrawWithOptions/index.js +7 -11
  15. package/lib/commonjs/components/DrawWithOptions/index.js.map +1 -1
  16. package/lib/module/components/DrawCore/DrawContext.js +4 -1
  17. package/lib/module/components/DrawCore/DrawContext.js.map +1 -1
  18. package/lib/module/components/DrawCore/DrawPad.js +10 -4
  19. package/lib/module/components/DrawCore/DrawPad.js.map +1 -1
  20. package/lib/module/components/DrawCore/DrawProvider.js +17 -3
  21. package/lib/module/components/DrawCore/DrawProvider.js.map +1 -1
  22. package/lib/module/components/DrawCore/Item.js +14 -37
  23. package/lib/module/components/DrawCore/Item.js.map +1 -1
  24. package/lib/module/components/DrawCore/index.js +575 -577
  25. package/lib/module/components/DrawCore/index.js.map +1 -1
  26. package/lib/module/components/DrawCore/useDrawHook.js +15 -13
  27. package/lib/module/components/DrawCore/useDrawHook.js.map +1 -1
  28. package/lib/module/components/DrawWithOptions/index.js +8 -12
  29. package/lib/module/components/DrawWithOptions/index.js.map +1 -1
  30. package/lib/typescript/components/DrawCore/DrawContext.d.ts +3 -0
  31. package/lib/typescript/components/DrawCore/DrawContext.d.ts.map +1 -1
  32. package/lib/typescript/components/DrawCore/DrawPad.d.ts +2 -1
  33. package/lib/typescript/components/DrawCore/DrawPad.d.ts.map +1 -1
  34. package/lib/typescript/components/DrawCore/DrawProvider.d.ts.map +1 -1
  35. package/lib/typescript/components/DrawCore/Item.d.ts.map +1 -1
  36. package/lib/typescript/components/DrawCore/index.d.ts +2 -1
  37. package/lib/typescript/components/DrawCore/index.d.ts.map +1 -1
  38. package/lib/typescript/components/DrawCore/useDrawHook.d.ts +4 -1
  39. package/lib/typescript/components/DrawCore/useDrawHook.d.ts.map +1 -1
  40. package/lib/typescript/components/DrawWithOptions/index.d.ts +1 -1
  41. package/lib/typescript/components/DrawWithOptions/index.d.ts.map +1 -1
  42. package/package.json +5 -1
  43. package/src/components/DrawCore/DrawContext.tsx +6 -0
  44. package/src/components/DrawCore/DrawPad.tsx +76 -67
  45. package/src/components/DrawCore/DrawProvider.tsx +23 -1
  46. package/src/components/DrawCore/Item.tsx +15 -47
  47. package/src/components/DrawCore/index.tsx +109 -114
  48. package/src/components/DrawCore/useDrawHook.tsx +12 -7
  49. package/src/components/DrawWithOptions/index.tsx +10 -11
  50. package/src/types.d.ts +5 -3
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import { StyleSheet, TextInput, View, Keyboard, ImageBackground, Image, KeyboardAvoidingView } from 'react-native';
3
- import Animated, { runOnJS, useAnimatedGestureHandler, useAnimatedKeyboard, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
4
- import { PanGestureHandler } from 'react-native-gesture-handler';
3
+ import Animated, { runOnJS, useAnimatedKeyboard, useAnimatedReaction, useSharedValue } from 'react-native-reanimated';
4
+ import { Gesture, GestureDetector } from 'react-native-gesture-handler';
5
5
  import DrawPad from './DrawPad';
6
6
  import ViewShot from 'react-native-view-shot';
7
7
  import useDrawHook from './useDrawHook';
@@ -178,7 +178,8 @@ const DrawCore = _ref => {
178
178
  var _textInputRef$current4;
179
179
  let {
180
180
  image,
181
- backgroundColor
181
+ backgroundColor,
182
+ actionWithSnapShotUri
182
183
  } = _ref;
183
184
  const {
184
185
  drawState,
@@ -188,8 +189,34 @@ const DrawCore = _ref => {
188
189
  currentItem,
189
190
  itemIsSelected,
190
191
  viewShot,
191
- doubleArrowTextInput
192
+ doubleArrowTextInput,
193
+ captureSnapshot,
194
+ snapShotRequested,
195
+ setSnapShotRequested
192
196
  } = useDrawHook();
197
+ const [drawRegion, setDrawRegion] = useState(null);
198
+ const [imageSize, setImageSize] = useState(null);
199
+ const [originalImageSize, setOriginalImageSize] = useState(null);
200
+ useEffect(() => {
201
+ if (snapShotRequested) {
202
+ setSnapShotRequested(false);
203
+ setNewLayoutRequested(true);
204
+ if (imageSize !== null && imageSize !== void 0 && imageSize.height && originalImageSize !== null && originalImageSize !== void 0 && originalImageSize.height && originalImageSize !== null && originalImageSize !== void 0 && originalImageSize.width && image) {
205
+ setOpacity(0);
206
+ setRatioImage(originalImageSize.height / (imageSize === null || imageSize === void 0 ? void 0 : imageSize.height));
207
+ setImageSize(originalImageSize);
208
+ } else if (!image && drawRegion !== null && drawRegion !== void 0 && drawRegion.height) {
209
+ const width = 1500;
210
+ const height = width / 1.3333333;
211
+ setOpacity(0);
212
+ setRatioImage(height / drawRegion.height);
213
+ setImageSize({
214
+ width,
215
+ height
216
+ });
217
+ }
218
+ }
219
+ }, [snapShotRequested, drawRegion === null || drawRegion === void 0 ? void 0 : drawRegion.height, image, imageSize === null || imageSize === void 0 ? void 0 : imageSize.height, originalImageSize, setSnapShotRequested]);
193
220
  const onCancelChangeWrapper = arg => {
194
221
  dispatchDrawStates({
195
222
  type: 'SET_CANCEL_ENABLED',
@@ -197,13 +224,15 @@ const DrawCore = _ref => {
197
224
  });
198
225
  };
199
226
  const mode = useSharedValue('pen');
200
- const [drawRegion, setDrawRegion] = useState(null);
201
- const [originalImageSize, setOriginalImageSize] = useState(null);
202
- const [imageSize, setImageSize] = useState(null);
203
227
  const drawContainer = useRef(null);
204
228
  const [textVal, setTextVal] = useState('');
205
229
  const initialItem = useSharedValue(null);
206
230
  const textBaseHeight = useSharedValue(null);
231
+ const gestureContext = useSharedValue({
232
+ startX: 0,
233
+ startY: 0,
234
+ newlyCreated: false
235
+ });
207
236
  const addDoneItem = useCallback(item => {
208
237
  dispatchDrawStates({
209
238
  type: 'ADD_DONE_ITEM',
@@ -234,19 +263,16 @@ const DrawCore = _ref => {
234
263
 
235
264
  const textFocusState = useCallback(() => {
236
265
  var _doubleArrowTextInput;
237
- //setShowTextInputState(true);
238
- console.log('textFocusState');
239
266
  doubleArrowTextInput === null || doubleArrowTextInput === void 0 ? void 0 : (_doubleArrowTextInput = doubleArrowTextInput.current) === null || _doubleArrowTextInput === void 0 ? void 0 : _doubleArrowTextInput.focus();
240
267
  }, [doubleArrowTextInput]);
241
268
  const textFocus = useCallback(() => {
242
269
  var _textInputRef$current;
243
- console.log('textFocus');
244
270
  (_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
245
271
  }, []);
246
272
  useEffect(() => {
247
273
  var _currentItem$value2;
248
274
  if (((_currentItem$value2 = currentItem.value) === null || _currentItem$value2 === void 0 ? void 0 : _currentItem$value2.type) === 'text') {
249
- console.log('use effect text');
275
+ console.log('Updating text value:');
250
276
  showTextInput.value = true;
251
277
  textFocus();
252
278
  currentItem.value = {
@@ -258,541 +284,527 @@ const DrawCore = _ref => {
258
284
  };
259
285
  }
260
286
  }, [currentItem, showTextInput, textFocus, textVal]);
261
- const onGestureEvent = useAnimatedGestureHandler({
262
- onStart: (_ref2, ctx) => {
263
- var _currentItem$value3, _currentItem$value4;
264
- let {
265
- x: startX,
266
- y: startY
267
- } = _ref2;
268
- ctx.startX = startX;
269
- ctx.startY = startY;
270
- ctx.newlyCreated = false;
271
- console.log('**********************************');
272
- console.log('onGestureEvent');
273
- //panPosition.value = withTiming(RIGHT_PANE_WIDTH);
274
- console.log('onStart', (_currentItem$value3 = currentItem.value) === null || _currentItem$value3 === void 0 ? void 0 : _currentItem$value3.type);
275
- initialItem.value = currentItem.value;
276
- switch ((_currentItem$value4 = currentItem.value) === null || _currentItem$value4 === void 0 ? void 0 : _currentItem$value4.type) {
277
- case 'ellipse':
278
- const cx = typeof currentItem.value.data.cx === 'string' ? parseFloat(currentItem.value.data.cx) : currentItem.value.data.cx || 0;
279
- const cy = typeof currentItem.value.data.cy === 'string' ? parseFloat(currentItem.value.data.cy) : currentItem.value.data.cy || 0;
280
- const rx = typeof currentItem.value.data.rx === 'string' ? parseFloat(currentItem.value.data.rx) : currentItem.value.data.rx || 0;
281
- const ry = typeof currentItem.value.data.ry === 'string' ? parseFloat(currentItem.value.data.ry) : currentItem.value.data.ry || 0;
282
- if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy - ry + THRESHOLD && startY >= cy - ry - THRESHOLD) {
283
- ctx.zone = 'TOP';
284
- } else if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy + ry + THRESHOLD && startY >= cy + ry - THRESHOLD) {
285
- ctx.zone = 'BOTTOM';
286
- } else if (startY <= cy + THRESHOLD && startY >= cy - THRESHOLD && startX <= cx - rx + THRESHOLD && startX >= cx - rx - THRESHOLD) {
287
- ctx.zone = 'LEFT';
288
- } else if (startY <= cy + THRESHOLD && startY >= cy - THRESHOLD && startX <= cx + rx + THRESHOLD && startX >= cx + rx - THRESHOLD) {
289
- ctx.zone = 'RIGHT';
290
- } else if ((rx > 0 && startX > cx - rx && startX < cx + rx || rx < 0 && startX < cx - rx && startX > cx + rx) && (ry > 0 && startY > cy - ry && startY < cy + ry || ry < 0 && startY < cy - ry && startY > cy + ry)) {
291
- ctx.zone = 'CENTER';
292
- } else {
293
- ctx.zone = 'OUT';
294
- initialItem.value = null;
287
+ const panGesture = Gesture.Pan().onStart(event => {
288
+ var _currentItem$value3;
289
+ const {
290
+ x: startX,
291
+ y: startY
292
+ } = event;
293
+ gestureContext.value = {
294
+ startX,
295
+ startY,
296
+ newlyCreated: false
297
+ };
298
+ initialItem.value = currentItem.value;
299
+ switch ((_currentItem$value3 = currentItem.value) === null || _currentItem$value3 === void 0 ? void 0 : _currentItem$value3.type) {
300
+ case 'ellipse':
301
+ const cx = typeof currentItem.value.data.cx === 'string' ? parseFloat(currentItem.value.data.cx) : currentItem.value.data.cx || 0;
302
+ const cy = typeof currentItem.value.data.cy === 'string' ? parseFloat(currentItem.value.data.cy) : currentItem.value.data.cy || 0;
303
+ const rx = typeof currentItem.value.data.rx === 'string' ? parseFloat(currentItem.value.data.rx) : currentItem.value.data.rx || 0;
304
+ const ry = typeof currentItem.value.data.ry === 'string' ? parseFloat(currentItem.value.data.ry) : currentItem.value.data.ry || 0;
305
+ if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy - ry + THRESHOLD && startY >= cy - ry - THRESHOLD) {
306
+ gestureContext.value.zone = 'TOP';
307
+ } else if (startX <= cx + THRESHOLD && startX >= cx - THRESHOLD && startY <= cy + ry + THRESHOLD && startY >= cy + ry - THRESHOLD) {
308
+ gestureContext.value.zone = 'BOTTOM';
309
+ } else if (startY <= cy + THRESHOLD && startY >= cy - THRESHOLD && startX <= cx - rx + THRESHOLD && startX >= cx - rx - THRESHOLD) {
310
+ gestureContext.value.zone = 'LEFT';
311
+ } else if (startY <= cy + THRESHOLD && startY >= cy - THRESHOLD && startX <= cx + rx + THRESHOLD && startX >= cx + rx - THRESHOLD) {
312
+ gestureContext.value.zone = 'RIGHT';
313
+ } else if ((rx > 0 && startX > cx - rx && startX < cx + rx || rx < 0 && startX < cx - rx && startX > cx + rx) && (ry > 0 && startY > cy - ry && startY < cy + ry || ry < 0 && startY < cy - ry && startY > cy + ry)) {
314
+ gestureContext.value.zone = 'CENTER';
315
+ } else {
316
+ gestureContext.value.zone = 'OUT';
317
+ initialItem.value = null;
318
+ }
319
+ break;
320
+ case 'rectangle':
321
+ const x = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
322
+ const y = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
323
+ const height = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
324
+ const width = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
325
+ if (startX <= x + THRESHOLD && startX >= x - THRESHOLD) {
326
+ if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
327
+ gestureContext.value.zone = 'TOP_LEFT';
328
+ } else if (startY <= y + height + THRESHOLD && startY >= y + height - THRESHOLD) {
329
+ gestureContext.value.zone = 'BOTTOM_LEFT';
295
330
  }
296
- break;
297
- case 'rectangle':
298
- const x = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
299
- const y = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
300
- const height = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
301
- const width = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
302
- if (startX <= x + THRESHOLD && startX >= x - THRESHOLD) {
303
- if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
304
- ctx.zone = 'TOP_LEFT';
305
- } else if (startY <= y + height + THRESHOLD && startY >= y + height - THRESHOLD) {
306
- ctx.zone = 'BOTTOM_LEFT';
307
- }
308
- } else if (startX <= x + width + THRESHOLD && startX >= x + width - THRESHOLD) {
309
- if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
310
- ctx.zone = 'TOP_RIGHT';
311
- } else if (startY <= y + height + THRESHOLD && startY >= y + height - THRESHOLD) {
312
- ctx.zone = 'BOTTOM_RIGHT';
313
- }
314
- } else if ((width > 0 && startX > x && startX < x + width || width < 0 && startX < x && startX > x + width) && (height > 0 && startY > y && startY < y + height || height < 0 && startY < y && startY > y + height)) {
315
- ctx.zone = 'CENTER';
316
- } else {
317
- ctx.zone = 'OUT';
318
- initialItem.value = null;
331
+ } else if (startX <= x + width + THRESHOLD && startX >= x + width - THRESHOLD) {
332
+ if (startY <= y + THRESHOLD && startY >= y - THRESHOLD) {
333
+ gestureContext.value.zone = 'TOP_RIGHT';
334
+ } else if (startY <= y + height + THRESHOLD && startY >= y + height - THRESHOLD) {
335
+ gestureContext.value.zone = 'BOTTOM_RIGHT';
319
336
  }
320
- break;
321
- case 'doubleHead':
322
- case 'doubleArrows':
323
- case 'singleHead':
324
- const x1 = typeof currentItem.value.data.x1 === 'string' ? parseFloat(currentItem.value.data.x1) : currentItem.value.data.x1 || 0;
325
- const y1 = typeof currentItem.value.data.y1 === 'string' ? parseFloat(currentItem.value.data.y1) : currentItem.value.data.y1 || 0;
326
- const x2 = typeof currentItem.value.data.x2 === 'string' ? parseFloat(currentItem.value.data.x2) : currentItem.value.data.x2 || 0;
327
- const y2 = typeof currentItem.value.data.y2 === 'string' ? parseFloat(currentItem.value.data.y2) : currentItem.value.data.y2 || 0;
328
- if (startX <= x1 + THRESHOLD && startX >= x1 - THRESHOLD && startY <= y1 + THRESHOLD && startY >= y1 - THRESHOLD) {
329
- ctx.zone = 'TOP';
330
- } else if (startX <= x2 + THRESHOLD && startX >= x2 - THRESHOLD && startY - THRESHOLD <= y2 + THRESHOLD && startY + THRESHOLD >= y2 - THRESHOLD) {
331
- ctx.zone = 'BOTTOM';
332
- } else if (pDistance({
337
+ } else if ((width > 0 && startX > x && startX < x + width || width < 0 && startX < x && startX > x + width) && (height > 0 && startY > y && startY < y + height || height < 0 && startY < y && startY > y + height)) {
338
+ gestureContext.value.zone = 'CENTER';
339
+ } else {
340
+ gestureContext.value.zone = 'OUT';
341
+ initialItem.value = null;
342
+ }
343
+ break;
344
+ case 'doubleHead':
345
+ case 'doubleArrows':
346
+ case 'singleHead':
347
+ const x1 = typeof currentItem.value.data.x1 === 'string' ? parseFloat(currentItem.value.data.x1) : currentItem.value.data.x1 || 0;
348
+ const y1 = typeof currentItem.value.data.y1 === 'string' ? parseFloat(currentItem.value.data.y1) : currentItem.value.data.y1 || 0;
349
+ const x2 = typeof currentItem.value.data.x2 === 'string' ? parseFloat(currentItem.value.data.x2) : currentItem.value.data.x2 || 0;
350
+ const y2 = typeof currentItem.value.data.y2 === 'string' ? parseFloat(currentItem.value.data.y2) : currentItem.value.data.y2 || 0;
351
+ if (startX <= x1 + THRESHOLD && startX >= x1 - THRESHOLD && startY <= y1 + THRESHOLD && startY >= y1 - THRESHOLD) {
352
+ gestureContext.value.zone = 'TOP';
353
+ } else if (startX <= x2 + THRESHOLD && startX >= x2 - THRESHOLD && startY - THRESHOLD <= y2 + THRESHOLD && startY + THRESHOLD >= y2 - THRESHOLD) {
354
+ gestureContext.value.zone = 'BOTTOM';
355
+ } else if (pDistance({
356
+ x: startX,
357
+ y: startY
358
+ }, {
359
+ x1,
360
+ x2,
361
+ y1,
362
+ y2
363
+ }) <= THRESHOLD && (startX > x1 && startX < x2 || startX < x1 && startX > x2) && (startY > y1 && startY < y2 || startY < y1 && startY > y2)) {
364
+ gestureContext.value.zone = 'CENTER';
365
+ } else {
366
+ gestureContext.value.zone = 'OUT';
367
+ initialItem.value = null;
368
+ }
369
+ break;
370
+ case 'text':
371
+ const xText = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
372
+ const yText = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
373
+ const widthText = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
374
+ const heightText = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
375
+ if (startX <= xText + THRESHOLD && startX >= xText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
376
+ gestureContext.value.zone = 'LEFT';
377
+ } else if (startX <= xText + widthText + THRESHOLD && startX >= xText + widthText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
378
+ gestureContext.value.zone = 'RIGHT';
379
+ } else if ((widthText > 0 && startX > xText && startX < xText + widthText || widthText < 0 && startX < xText && startX > xText + widthText) && (heightText > 0 && startY > yText && startY < yText + heightText || heightText < 0 && startY < yText && startY > yText + heightText)) {
380
+ gestureContext.value.zone = 'CENTER';
381
+ } else {
382
+ gestureContext.value.zone = 'OUT';
383
+ initialItem.value = null;
384
+ gestureContext.value.newlyCreated = true;
385
+ runOnJS(setTextVal)('');
386
+ drawNewItem(mode, currentItem, addDoneItem, {
333
387
  x: startX,
334
388
  y: startY
335
389
  }, {
336
- x1,
337
- x2,
338
- y1,
339
- y2
340
- }) <= THRESHOLD && (startX > x1 && startX < x2 || startX < x1 && startX > x2) && (startY > y1 && startY < y2 || startY < y1 && startY > y2)) {
341
- ctx.zone = 'CENTER';
342
- } else {
343
- ctx.zone = 'OUT';
344
- initialItem.value = null;
345
- }
346
- break;
347
- case 'text':
348
- const xText = typeof currentItem.value.data.x === 'string' ? parseFloat(currentItem.value.data.x) : currentItem.value.data.x || 0;
349
- const yText = typeof currentItem.value.data.y === 'string' ? parseFloat(currentItem.value.data.y) : currentItem.value.data.y || 0;
350
- const widthText = typeof currentItem.value.data.width === 'string' ? parseFloat(currentItem.value.data.width) : currentItem.value.data.width || 0;
351
- const heightText = typeof currentItem.value.data.height === 'string' ? parseFloat(currentItem.value.data.height) : currentItem.value.data.height || 0;
352
- console.log(heightText);
353
- console.log(widthText);
354
- if (startX <= xText + THRESHOLD && startX >= xText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
355
- ctx.zone = 'LEFT';
356
- } else if (startX <= xText + widthText + THRESHOLD && startX >= xText + widthText - THRESHOLD && startY <= yText + heightText / 2 + THRESHOLD && startY >= yText + heightText / 2 - THRESHOLD) {
357
- ctx.zone = 'RIGHT';
358
- } else if ((widthText > 0 && startX > xText && startX < xText + widthText || widthText < 0 && startX < xText && startX > xText + widthText) && (heightText > 0 && startY > yText && startY < yText + heightText || heightText < 0 && startY < yText && startY > yText + heightText)) {
359
- ctx.zone = 'CENTER';
360
- console.log('on active center');
361
- } else {
362
- ctx.zone = 'OUT';
363
- console.log('on active out');
364
- initialItem.value = null;
365
- ctx.newlyCreated = true;
366
- runOnJS(setTextVal)('');
367
- drawNewItem(mode, currentItem, addDoneItem, {
368
- x: startX,
369
- y: startY
370
- }, {
371
- textBaseHeight,
372
- strokeWidth,
373
- color
374
- });
375
- itemIsSelected.value = true;
376
- onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
377
- runOnJS(textFocus)();
378
- }
379
- break;
380
- case 'pen':
381
- if (currentItem.value.data.some(p => startX <= p.x + THRESHOLD && startX >= p.x - THRESHOLD && startY <= p.y + THRESHOLD && startY >= p.y - THRESHOLD)) {
382
- ctx.zone = 'CENTER';
383
- } else {
384
- ctx.zone = 'OUT';
385
- initialItem.value = null;
386
- }
387
- break;
388
- default:
389
- ctx.zone = 'OUT';
390
+ textBaseHeight,
391
+ strokeWidth,
392
+ color
393
+ });
394
+ itemIsSelected.value = true;
395
+ onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
396
+ runOnJS(textFocus)();
397
+ }
398
+ break;
399
+ case 'pen':
400
+ if (currentItem.value.data.some(p => startX <= p.x + THRESHOLD && startX >= p.x - THRESHOLD && startY <= p.y + THRESHOLD && startY >= p.y - THRESHOLD)) {
401
+ gestureContext.value.zone = 'CENTER';
402
+ } else {
403
+ gestureContext.value.zone = 'OUT';
390
404
  initialItem.value = null;
391
- if (drawState.drawingMode === 'text') {
392
- /* NEW GEOFF */
393
- console.log('on active out');
394
- ctx.newlyCreated = true;
395
- runOnJS(setTextVal)('');
396
- drawNewItem(mode, currentItem, addDoneItem, {
397
- x: startX,
398
- y: startY
399
- }, {
400
- textBaseHeight,
401
- strokeWidth,
402
- color
403
- });
404
- itemIsSelected.value = true;
405
- onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
406
- runOnJS(textFocus)();
407
- }
408
- break;
409
- }
410
- },
411
- onActive: (_ref3, ctx) => {
412
- var _currentItem$value5, _initialItem$value, _initialItem$value2, _initialItem$value4, _initialItem$value17, _initialItem$value30;
413
- let {
414
- x: currentX,
415
- y: currentY,
416
- translationX,
417
- translationY
418
- } = _ref3;
419
- const {
420
- startX,
421
- startY,
422
- zone,
423
- newlyCreated
424
- } = ctx;
425
- if (zone === 'OUT' && newlyCreated === false && mode.value !== 'text') {
426
- console.log('on active out');
427
- ctx.newlyCreated = true;
428
- /*
429
- if (mode.value === 'text') {
405
+ }
406
+ break;
407
+ default:
408
+ gestureContext.value.zone = 'OUT';
409
+ initialItem.value = null;
410
+ if (drawState.drawingMode === 'text') {
411
+ gestureContext.value.newlyCreated = true;
430
412
  runOnJS(setTextVal)('');
431
- }*/
432
- drawNewItem(mode, currentItem, addDoneItem, {
433
- x: startX,
434
- y: startY
435
- }, {
436
- textBaseHeight,
437
- strokeWidth,
438
- color
439
- });
440
- itemIsSelected.value = true;
441
- onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
442
- }
443
- switch ((_currentItem$value5 = currentItem.value) === null || _currentItem$value5 === void 0 ? void 0 : _currentItem$value5.type) {
444
- case 'pen':
445
- if (((_initialItem$value = initialItem.value) === null || _initialItem$value === void 0 ? void 0 : _initialItem$value.type) === currentItem.value.type && zone === 'CENTER') {
446
- currentItem.value = {
447
- type: 'pen',
448
- strokeWidth: currentItem.value.strokeWidth,
449
- color: currentItem.value.color,
450
- data: initialItem.value.data.map(p => ({
451
- x: p.x + translationX,
452
- y: p.y + translationY
453
- }))
454
- };
455
- } else {
456
- currentItem.value = {
457
- type: 'pen',
458
- strokeWidth: currentItem.value.strokeWidth,
459
- color: currentItem.value.color,
460
- data: currentItem.value.data.concat({
461
- x: currentX,
462
- y: currentY
463
- })
464
- };
413
+ drawNewItem(mode, currentItem, addDoneItem, {
414
+ x: startX,
415
+ y: startY
416
+ }, {
417
+ textBaseHeight,
418
+ strokeWidth,
419
+ color
420
+ });
421
+ itemIsSelected.value = true;
422
+ onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
423
+ runOnJS(textFocus)();
424
+ }
425
+ break;
426
+ }
427
+ }).onUpdate(event => {
428
+ var _currentItem$value4, _initialItem$value, _initialItem$value2, _initialItem$value4, _initialItem$value17, _initialItem$value30;
429
+ const {
430
+ x: currentX,
431
+ y: currentY,
432
+ translationX,
433
+ translationY
434
+ } = event;
435
+ const {
436
+ startX,
437
+ startY,
438
+ zone,
439
+ newlyCreated
440
+ } = gestureContext.value;
441
+ if (zone === 'OUT' && newlyCreated === false && mode.value !== 'text') {
442
+ gestureContext.value.newlyCreated = true;
443
+ /*
444
+ if (mode.value === 'text') {
445
+ runOnJS(setTextVal)('');
446
+ }*/
447
+ drawNewItem(mode, currentItem, addDoneItem, {
448
+ x: startX,
449
+ y: startY
450
+ }, {
451
+ textBaseHeight,
452
+ strokeWidth,
453
+ color
454
+ });
455
+ itemIsSelected.value = true;
456
+ onCancelChangeWrapper && runOnJS(onCancelChangeWrapper)(true);
457
+ }
458
+ switch ((_currentItem$value4 = currentItem.value) === null || _currentItem$value4 === void 0 ? void 0 : _currentItem$value4.type) {
459
+ case 'pen':
460
+ if (((_initialItem$value = initialItem.value) === null || _initialItem$value === void 0 ? void 0 : _initialItem$value.type) === currentItem.value.type && zone === 'CENTER') {
461
+ currentItem.value = {
462
+ type: 'pen',
463
+ strokeWidth: currentItem.value.strokeWidth,
464
+ color: currentItem.value.color,
465
+ data: initialItem.value.data.map(p => ({
466
+ x: p.x + translationX,
467
+ y: p.y + translationY
468
+ }))
469
+ };
470
+ } else {
471
+ currentItem.value = {
472
+ type: 'pen',
473
+ strokeWidth: currentItem.value.strokeWidth,
474
+ color: currentItem.value.color,
475
+ data: currentItem.value.data.concat({
476
+ x: currentX,
477
+ y: currentY
478
+ })
479
+ };
480
+ }
481
+ break;
482
+ case 'ellipse':
483
+ if (((_initialItem$value2 = initialItem.value) === null || _initialItem$value2 === void 0 ? void 0 : _initialItem$value2.type) === currentItem.value.type) {
484
+ var _initialItem$value3;
485
+ const rx = typeof initialItem.value.data.rx === 'string' ? parseFloat((_initialItem$value3 = initialItem.value) === null || _initialItem$value3 === void 0 ? void 0 : _initialItem$value3.data.rx) : initialItem.value.data.rx || 0;
486
+ const ry = typeof initialItem.value.data.ry === 'string' ? parseFloat(initialItem.value.data.ry) : initialItem.value.data.ry || 0;
487
+ const cx = typeof initialItem.value.data.cx === 'string' ? parseFloat(initialItem.value.data.cx) : initialItem.value.data.cx || 0;
488
+ const cy = typeof initialItem.value.data.cy === 'string' ? parseFloat(initialItem.value.data.cy) : initialItem.value.data.cy || 0;
489
+ switch (zone) {
490
+ case 'TOP':
491
+ currentItem.value = {
492
+ type: currentItem.value.type,
493
+ strokeWidth: currentItem.value.strokeWidth,
494
+ color: currentItem.value.color,
495
+ data: {
496
+ cx: cx,
497
+ cy: cy + translationY,
498
+ rx: rx,
499
+ ry: ry - translationY
500
+ }
501
+ };
502
+ break;
503
+ case 'BOTTOM':
504
+ currentItem.value = {
505
+ type: currentItem.value.type,
506
+ strokeWidth: currentItem.value.strokeWidth,
507
+ color: currentItem.value.color,
508
+ data: {
509
+ cx: cx,
510
+ cy: cy + translationY,
511
+ rx: rx,
512
+ ry: ry + translationY
513
+ }
514
+ };
515
+ break;
516
+ case 'LEFT':
517
+ currentItem.value = {
518
+ type: currentItem.value.type,
519
+ strokeWidth: currentItem.value.strokeWidth,
520
+ color: currentItem.value.color,
521
+ data: {
522
+ cx: cx + translationX,
523
+ cy: cy,
524
+ rx: rx - translationX,
525
+ ry: ry
526
+ }
527
+ };
528
+ break;
529
+ case 'RIGHT':
530
+ currentItem.value = {
531
+ type: currentItem.value.type,
532
+ strokeWidth: currentItem.value.strokeWidth,
533
+ color: currentItem.value.color,
534
+ data: {
535
+ cx: cx + translationX,
536
+ cy: cy,
537
+ rx: rx + translationX,
538
+ ry: ry
539
+ }
540
+ };
541
+ break;
542
+ case 'CENTER':
543
+ currentItem.value = {
544
+ type: currentItem.value.type,
545
+ strokeWidth: currentItem.value.strokeWidth,
546
+ color: currentItem.value.color,
547
+ data: {
548
+ cx: cx + translationX,
549
+ cy: cy + translationY,
550
+ rx: rx,
551
+ ry: ry
552
+ }
553
+ };
554
+ break;
465
555
  }
466
- break;
467
- case 'ellipse':
468
- if (((_initialItem$value2 = initialItem.value) === null || _initialItem$value2 === void 0 ? void 0 : _initialItem$value2.type) === currentItem.value.type) {
469
- var _initialItem$value3;
470
- const rx = typeof initialItem.value.data.rx === 'string' ? parseFloat((_initialItem$value3 = initialItem.value) === null || _initialItem$value3 === void 0 ? void 0 : _initialItem$value3.data.rx) : initialItem.value.data.rx || 0;
471
- const ry = typeof initialItem.value.data.ry === 'string' ? parseFloat(initialItem.value.data.ry) : initialItem.value.data.ry || 0;
472
- const cx = typeof initialItem.value.data.cx === 'string' ? parseFloat(initialItem.value.data.cx) : initialItem.value.data.cx || 0;
473
- const cy = typeof initialItem.value.data.cy === 'string' ? parseFloat(initialItem.value.data.cy) : initialItem.value.data.cy || 0;
474
- switch (zone) {
475
- case 'TOP':
476
- currentItem.value = {
477
- type: currentItem.value.type,
478
- strokeWidth: currentItem.value.strokeWidth,
479
- color: currentItem.value.color,
480
- data: {
481
- cx: cx,
482
- cy: cy + translationY,
483
- rx: rx,
484
- ry: ry - translationY
485
- }
486
- };
487
- break;
488
- case 'BOTTOM':
489
- currentItem.value = {
490
- type: currentItem.value.type,
491
- strokeWidth: currentItem.value.strokeWidth,
492
- color: currentItem.value.color,
493
- data: {
494
- cx: cx,
495
- cy: cy + translationY,
496
- rx: rx,
497
- ry: ry + translationY
498
- }
499
- };
500
- break;
501
- case 'LEFT':
502
- currentItem.value = {
503
- type: currentItem.value.type,
504
- strokeWidth: currentItem.value.strokeWidth,
505
- color: currentItem.value.color,
506
- data: {
507
- cx: cx + translationX,
508
- cy: cy,
509
- rx: rx - translationX,
510
- ry: ry
511
- }
512
- };
513
- break;
514
- case 'RIGHT':
515
- currentItem.value = {
516
- type: currentItem.value.type,
517
- strokeWidth: currentItem.value.strokeWidth,
518
- color: currentItem.value.color,
519
- data: {
520
- cx: cx + translationX,
521
- cy: cy,
522
- rx: rx + translationX,
523
- ry: ry
524
- }
525
- };
526
- break;
527
- case 'CENTER':
528
- currentItem.value = {
529
- type: currentItem.value.type,
530
- strokeWidth: currentItem.value.strokeWidth,
531
- color: currentItem.value.color,
532
- data: {
533
- cx: cx + translationX,
534
- cy: cy + translationY,
535
- rx: rx,
536
- ry: ry
537
- }
538
- };
539
- break;
556
+ } else {
557
+ currentItem.value = {
558
+ type: currentItem.value.type,
559
+ strokeWidth: currentItem.value.strokeWidth,
560
+ color: currentItem.value.color,
561
+ data: {
562
+ cx: startX + translationX,
563
+ cy: startY + translationY,
564
+ rx: translationX,
565
+ ry: translationY
540
566
  }
541
- } else {
542
- currentItem.value = {
543
- type: currentItem.value.type,
544
- strokeWidth: currentItem.value.strokeWidth,
545
- color: currentItem.value.color,
546
- data: {
547
- cx: startX + translationX,
548
- cy: startY + translationY,
549
- rx: translationX,
550
- ry: translationY
551
- }
552
- };
567
+ };
568
+ }
569
+ break;
570
+ case 'rectangle':
571
+ if (((_initialItem$value4 = initialItem.value) === null || _initialItem$value4 === void 0 ? void 0 : _initialItem$value4.type) === currentItem.value.type) {
572
+ var _initialItem$value5, _initialItem$value6, _initialItem$value7, _initialItem$value8, _initialItem$value9, _initialItem$value10, _initialItem$value11, _initialItem$value12, _initialItem$value13, _initialItem$value14, _initialItem$value15, _initialItem$value16;
573
+ const height = typeof ((_initialItem$value5 = initialItem.value) === null || _initialItem$value5 === void 0 ? void 0 : _initialItem$value5.data.height) === 'string' ? parseFloat((_initialItem$value6 = initialItem.value) === null || _initialItem$value6 === void 0 ? void 0 : _initialItem$value6.data.height) : ((_initialItem$value7 = initialItem.value) === null || _initialItem$value7 === void 0 ? void 0 : _initialItem$value7.data.height) || 0;
574
+ const width = typeof ((_initialItem$value8 = initialItem.value) === null || _initialItem$value8 === void 0 ? void 0 : _initialItem$value8.data.width) === 'string' ? parseFloat((_initialItem$value9 = initialItem.value) === null || _initialItem$value9 === void 0 ? void 0 : _initialItem$value9.data.width) : ((_initialItem$value10 = initialItem.value) === null || _initialItem$value10 === void 0 ? void 0 : _initialItem$value10.data.width) || 0;
575
+ const x = typeof ((_initialItem$value11 = initialItem.value) === null || _initialItem$value11 === void 0 ? void 0 : _initialItem$value11.data.x) === 'string' ? parseFloat((_initialItem$value12 = initialItem.value) === null || _initialItem$value12 === void 0 ? void 0 : _initialItem$value12.data.x) : ((_initialItem$value13 = initialItem.value) === null || _initialItem$value13 === void 0 ? void 0 : _initialItem$value13.data.x) || 0;
576
+ const y = typeof ((_initialItem$value14 = initialItem.value) === null || _initialItem$value14 === void 0 ? void 0 : _initialItem$value14.data.y) === 'string' ? parseFloat((_initialItem$value15 = initialItem.value) === null || _initialItem$value15 === void 0 ? void 0 : _initialItem$value15.data.y) : ((_initialItem$value16 = initialItem.value) === null || _initialItem$value16 === void 0 ? void 0 : _initialItem$value16.data.y) || 0;
577
+ switch (zone) {
578
+ case 'TOP_LEFT':
579
+ currentItem.value = {
580
+ type: 'rectangle',
581
+ strokeWidth: currentItem.value.strokeWidth,
582
+ color: currentItem.value.color,
583
+ data: {
584
+ x: startX + translationX,
585
+ y: startY + translationY,
586
+ width: width - translationX,
587
+ height: height - translationY
588
+ }
589
+ };
590
+ break;
591
+ case 'TOP_RIGHT':
592
+ currentItem.value = {
593
+ type: 'rectangle',
594
+ strokeWidth: currentItem.value.strokeWidth,
595
+ color: currentItem.value.color,
596
+ data: {
597
+ x: x,
598
+ y: startY + translationY,
599
+ width: width + translationX,
600
+ height: height - translationY
601
+ }
602
+ };
603
+ break;
604
+ case 'BOTTOM_LEFT':
605
+ currentItem.value = {
606
+ type: 'rectangle',
607
+ strokeWidth: currentItem.value.strokeWidth,
608
+ color: currentItem.value.color,
609
+ data: {
610
+ x: startX + translationX,
611
+ y: y,
612
+ width: width - translationX,
613
+ height: height + translationY
614
+ }
615
+ };
616
+ break;
617
+ case 'BOTTOM_RIGHT':
618
+ currentItem.value = {
619
+ type: 'rectangle',
620
+ strokeWidth: currentItem.value.strokeWidth,
621
+ color: currentItem.value.color,
622
+ data: {
623
+ x: x,
624
+ y: y,
625
+ width: width + translationX,
626
+ height: height + translationY
627
+ }
628
+ };
629
+ break;
630
+ case 'CENTER':
631
+ currentItem.value = {
632
+ type: 'rectangle',
633
+ strokeWidth: currentItem.value.strokeWidth,
634
+ color: currentItem.value.color,
635
+ data: {
636
+ x: x + translationX,
637
+ y: y + translationY,
638
+ width: width,
639
+ height: height
640
+ }
641
+ };
642
+ break;
553
643
  }
554
- break;
555
- case 'rectangle':
556
- if (((_initialItem$value4 = initialItem.value) === null || _initialItem$value4 === void 0 ? void 0 : _initialItem$value4.type) === currentItem.value.type) {
557
- var _initialItem$value5, _initialItem$value6, _initialItem$value7, _initialItem$value8, _initialItem$value9, _initialItem$value10, _initialItem$value11, _initialItem$value12, _initialItem$value13, _initialItem$value14, _initialItem$value15, _initialItem$value16;
558
- const height = typeof ((_initialItem$value5 = initialItem.value) === null || _initialItem$value5 === void 0 ? void 0 : _initialItem$value5.data.height) === 'string' ? parseFloat((_initialItem$value6 = initialItem.value) === null || _initialItem$value6 === void 0 ? void 0 : _initialItem$value6.data.height) : ((_initialItem$value7 = initialItem.value) === null || _initialItem$value7 === void 0 ? void 0 : _initialItem$value7.data.height) || 0;
559
- const width = typeof ((_initialItem$value8 = initialItem.value) === null || _initialItem$value8 === void 0 ? void 0 : _initialItem$value8.data.width) === 'string' ? parseFloat((_initialItem$value9 = initialItem.value) === null || _initialItem$value9 === void 0 ? void 0 : _initialItem$value9.data.width) : ((_initialItem$value10 = initialItem.value) === null || _initialItem$value10 === void 0 ? void 0 : _initialItem$value10.data.width) || 0;
560
- const x = typeof ((_initialItem$value11 = initialItem.value) === null || _initialItem$value11 === void 0 ? void 0 : _initialItem$value11.data.x) === 'string' ? parseFloat((_initialItem$value12 = initialItem.value) === null || _initialItem$value12 === void 0 ? void 0 : _initialItem$value12.data.x) : ((_initialItem$value13 = initialItem.value) === null || _initialItem$value13 === void 0 ? void 0 : _initialItem$value13.data.x) || 0;
561
- const y = typeof ((_initialItem$value14 = initialItem.value) === null || _initialItem$value14 === void 0 ? void 0 : _initialItem$value14.data.y) === 'string' ? parseFloat((_initialItem$value15 = initialItem.value) === null || _initialItem$value15 === void 0 ? void 0 : _initialItem$value15.data.y) : ((_initialItem$value16 = initialItem.value) === null || _initialItem$value16 === void 0 ? void 0 : _initialItem$value16.data.y) || 0;
562
- switch (zone) {
563
- case 'TOP_LEFT':
564
- currentItem.value = {
565
- type: 'rectangle',
566
- strokeWidth: currentItem.value.strokeWidth,
567
- color: currentItem.value.color,
568
- data: {
569
- x: startX + translationX,
570
- y: startY + translationY,
571
- width: width - translationX,
572
- height: height - translationY
573
- }
574
- };
575
- break;
576
- case 'TOP_RIGHT':
577
- currentItem.value = {
578
- type: 'rectangle',
579
- strokeWidth: currentItem.value.strokeWidth,
580
- color: currentItem.value.color,
581
- data: {
582
- x: x,
583
- y: startY + translationY,
584
- width: width + translationX,
585
- height: height - translationY
586
- }
587
- };
588
- break;
589
- case 'BOTTOM_LEFT':
590
- currentItem.value = {
591
- type: 'rectangle',
592
- strokeWidth: currentItem.value.strokeWidth,
593
- color: currentItem.value.color,
594
- data: {
595
- x: startX + translationX,
596
- y: y,
597
- width: width - translationX,
598
- height: height + translationY
599
- }
600
- };
601
- break;
602
- case 'BOTTOM_RIGHT':
603
- currentItem.value = {
604
- type: 'rectangle',
605
- strokeWidth: currentItem.value.strokeWidth,
606
- color: currentItem.value.color,
607
- data: {
608
- x: x,
609
- y: y,
610
- width: width + translationX,
611
- height: height + translationY
612
- }
613
- };
614
- break;
615
- case 'CENTER':
616
- currentItem.value = {
617
- type: 'rectangle',
618
- strokeWidth: currentItem.value.strokeWidth,
619
- color: currentItem.value.color,
620
- data: {
621
- x: x + translationX,
622
- y: y + translationY,
623
- width: width,
624
- height: height
625
- }
626
- };
627
- break;
644
+ } else {
645
+ currentItem.value = {
646
+ type: 'rectangle',
647
+ strokeWidth: currentItem.value.strokeWidth,
648
+ color: currentItem.value.color,
649
+ data: {
650
+ x: currentItem.value.data.x,
651
+ y: currentItem.value.data.y,
652
+ width: translationX,
653
+ height: translationY
628
654
  }
629
- } else {
630
- currentItem.value = {
631
- type: 'rectangle',
632
- strokeWidth: currentItem.value.strokeWidth,
633
- color: currentItem.value.color,
634
- data: {
635
- x: currentItem.value.data.x,
636
- y: currentItem.value.data.y,
637
- width: translationX,
638
- height: translationY
639
- }
640
- };
655
+ };
656
+ }
657
+ break;
658
+ case 'singleHead':
659
+ case 'doubleHead':
660
+ case 'doubleArrows':
661
+ if (((_initialItem$value17 = initialItem.value) === null || _initialItem$value17 === void 0 ? void 0 : _initialItem$value17.type) === currentItem.value.type) {
662
+ var _initialItem$value18, _initialItem$value19, _initialItem$value20, _initialItem$value21, _initialItem$value22, _initialItem$value23, _initialItem$value24, _initialItem$value25, _initialItem$value26, _initialItem$value27, _initialItem$value28, _initialItem$value29;
663
+ const x1 = typeof ((_initialItem$value18 = initialItem.value) === null || _initialItem$value18 === void 0 ? void 0 : _initialItem$value18.data.x1) === 'string' ? parseFloat((_initialItem$value19 = initialItem.value) === null || _initialItem$value19 === void 0 ? void 0 : _initialItem$value19.data.x1) : ((_initialItem$value20 = initialItem.value) === null || _initialItem$value20 === void 0 ? void 0 : _initialItem$value20.data.x1) || 0;
664
+ const y1 = typeof ((_initialItem$value21 = initialItem.value) === null || _initialItem$value21 === void 0 ? void 0 : _initialItem$value21.data.y1) === 'string' ? parseFloat((_initialItem$value22 = initialItem.value) === null || _initialItem$value22 === void 0 ? void 0 : _initialItem$value22.data.y1) : ((_initialItem$value23 = initialItem.value) === null || _initialItem$value23 === void 0 ? void 0 : _initialItem$value23.data.y1) || 0;
665
+ const x2 = typeof ((_initialItem$value24 = initialItem.value) === null || _initialItem$value24 === void 0 ? void 0 : _initialItem$value24.data.x2) === 'string' ? parseFloat((_initialItem$value25 = initialItem.value) === null || _initialItem$value25 === void 0 ? void 0 : _initialItem$value25.data.x2) : ((_initialItem$value26 = initialItem.value) === null || _initialItem$value26 === void 0 ? void 0 : _initialItem$value26.data.x2) || 0;
666
+ const y2 = typeof ((_initialItem$value27 = initialItem.value) === null || _initialItem$value27 === void 0 ? void 0 : _initialItem$value27.data.y2) === 'string' ? parseFloat((_initialItem$value28 = initialItem.value) === null || _initialItem$value28 === void 0 ? void 0 : _initialItem$value28.data.y2) : ((_initialItem$value29 = initialItem.value) === null || _initialItem$value29 === void 0 ? void 0 : _initialItem$value29.data.y2) || 0;
667
+ switch (zone) {
668
+ case 'TOP':
669
+ currentItem.value = {
670
+ type: currentItem.value.type,
671
+ strokeWidth: currentItem.value.strokeWidth,
672
+ color: currentItem.value.color,
673
+ text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
674
+ data: {
675
+ x1: x1 + translationX,
676
+ y1: y1 + translationY,
677
+ x2: x2,
678
+ y2: y2
679
+ }
680
+ };
681
+ break;
682
+ case 'BOTTOM':
683
+ currentItem.value = {
684
+ type: currentItem.value.type,
685
+ strokeWidth: currentItem.value.strokeWidth,
686
+ color: currentItem.value.color,
687
+ text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
688
+ data: {
689
+ x1: x1,
690
+ y1: y1,
691
+ x2: x2 + translationX,
692
+ y2: y2 + translationY
693
+ }
694
+ };
695
+ break;
696
+ case 'CENTER':
697
+ currentItem.value = {
698
+ type: currentItem.value.type,
699
+ strokeWidth: currentItem.value.strokeWidth,
700
+ color: currentItem.value.color,
701
+ text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
702
+ data: {
703
+ x1: x1 + translationX,
704
+ y1: y1 + translationY,
705
+ x2: x2 + translationX,
706
+ y2: y2 + translationY
707
+ }
708
+ };
709
+ break;
641
710
  }
642
- break;
643
- case 'singleHead':
644
- case 'doubleHead':
645
- case 'doubleArrows':
646
- if (((_initialItem$value17 = initialItem.value) === null || _initialItem$value17 === void 0 ? void 0 : _initialItem$value17.type) === currentItem.value.type) {
647
- var _initialItem$value18, _initialItem$value19, _initialItem$value20, _initialItem$value21, _initialItem$value22, _initialItem$value23, _initialItem$value24, _initialItem$value25, _initialItem$value26, _initialItem$value27, _initialItem$value28, _initialItem$value29;
648
- const x1 = typeof ((_initialItem$value18 = initialItem.value) === null || _initialItem$value18 === void 0 ? void 0 : _initialItem$value18.data.x1) === 'string' ? parseFloat((_initialItem$value19 = initialItem.value) === null || _initialItem$value19 === void 0 ? void 0 : _initialItem$value19.data.x1) : ((_initialItem$value20 = initialItem.value) === null || _initialItem$value20 === void 0 ? void 0 : _initialItem$value20.data.x1) || 0;
649
- const y1 = typeof ((_initialItem$value21 = initialItem.value) === null || _initialItem$value21 === void 0 ? void 0 : _initialItem$value21.data.y1) === 'string' ? parseFloat((_initialItem$value22 = initialItem.value) === null || _initialItem$value22 === void 0 ? void 0 : _initialItem$value22.data.y1) : ((_initialItem$value23 = initialItem.value) === null || _initialItem$value23 === void 0 ? void 0 : _initialItem$value23.data.y1) || 0;
650
- const x2 = typeof ((_initialItem$value24 = initialItem.value) === null || _initialItem$value24 === void 0 ? void 0 : _initialItem$value24.data.x2) === 'string' ? parseFloat((_initialItem$value25 = initialItem.value) === null || _initialItem$value25 === void 0 ? void 0 : _initialItem$value25.data.x2) : ((_initialItem$value26 = initialItem.value) === null || _initialItem$value26 === void 0 ? void 0 : _initialItem$value26.data.x2) || 0;
651
- const y2 = typeof ((_initialItem$value27 = initialItem.value) === null || _initialItem$value27 === void 0 ? void 0 : _initialItem$value27.data.y2) === 'string' ? parseFloat((_initialItem$value28 = initialItem.value) === null || _initialItem$value28 === void 0 ? void 0 : _initialItem$value28.data.y2) : ((_initialItem$value29 = initialItem.value) === null || _initialItem$value29 === void 0 ? void 0 : _initialItem$value29.data.y2) || 0;
652
- switch (zone) {
653
- case 'TOP':
654
- currentItem.value = {
655
- type: currentItem.value.type,
656
- strokeWidth: currentItem.value.strokeWidth,
657
- color: currentItem.value.color,
658
- text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
659
- data: {
660
- x1: x1 + translationX,
661
- y1: y1 + translationY,
662
- x2: x2,
663
- y2: y2
664
- }
665
- };
666
- break;
667
- case 'BOTTOM':
668
- currentItem.value = {
669
- type: currentItem.value.type,
670
- strokeWidth: currentItem.value.strokeWidth,
671
- color: currentItem.value.color,
672
- text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
673
- data: {
674
- x1: x1,
675
- y1: y1,
676
- x2: x2 + translationX,
677
- y2: y2 + translationY
678
- }
679
- };
680
- break;
681
- case 'CENTER':
682
- currentItem.value = {
683
- type: currentItem.value.type,
684
- strokeWidth: currentItem.value.strokeWidth,
685
- color: currentItem.value.color,
686
- text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
687
- data: {
688
- x1: x1 + translationX,
689
- y1: y1 + translationY,
690
- x2: x2 + translationX,
691
- y2: y2 + translationY
692
- }
693
- };
694
- break;
711
+ } else {
712
+ currentItem.value = {
713
+ type: currentItem.value.type,
714
+ strokeWidth: currentItem.value.strokeWidth,
715
+ color: currentItem.value.color,
716
+ text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
717
+ data: {
718
+ x1: startX,
719
+ y1: startY,
720
+ x2: startX + translationX,
721
+ y2: startY + translationY
695
722
  }
696
- } else {
697
- currentItem.value = {
698
- type: currentItem.value.type,
699
- strokeWidth: currentItem.value.strokeWidth,
700
- color: currentItem.value.color,
701
- text: currentItem.value.type === 'doubleArrows' ? currentItem.value.text ?? '' : '',
702
- data: {
703
- x1: startX,
704
- y1: startY,
705
- x2: startX + translationX,
706
- y2: startY + translationY
707
- }
708
- };
723
+ };
724
+ }
725
+ break;
726
+ case 'text':
727
+ if (((_initialItem$value30 = initialItem.value) === null || _initialItem$value30 === void 0 ? void 0 : _initialItem$value30.type) === currentItem.value.type) {
728
+ var _initialItem$value31, _initialItem$value32, _initialItem$value33, _initialItem$value34, _initialItem$value35, _initialItem$value36, _initialItem$value37, _initialItem$value38, _initialItem$value39, _initialItem$value40, _initialItem$value41, _initialItem$value42;
729
+ const xText = typeof ((_initialItem$value31 = initialItem.value) === null || _initialItem$value31 === void 0 ? void 0 : _initialItem$value31.data.x) === 'string' ? parseFloat((_initialItem$value32 = initialItem.value) === null || _initialItem$value32 === void 0 ? void 0 : _initialItem$value32.data.x) : ((_initialItem$value33 = initialItem.value) === null || _initialItem$value33 === void 0 ? void 0 : _initialItem$value33.data.x) || 0;
730
+ const yText = typeof ((_initialItem$value34 = initialItem.value) === null || _initialItem$value34 === void 0 ? void 0 : _initialItem$value34.data.y) === 'string' ? parseFloat((_initialItem$value35 = initialItem.value) === null || _initialItem$value35 === void 0 ? void 0 : _initialItem$value35.data.y) : ((_initialItem$value36 = initialItem.value) === null || _initialItem$value36 === void 0 ? void 0 : _initialItem$value36.data.y) || 0;
731
+ const widthText = typeof ((_initialItem$value37 = initialItem.value) === null || _initialItem$value37 === void 0 ? void 0 : _initialItem$value37.data.width) === 'string' ? parseFloat((_initialItem$value38 = initialItem.value) === null || _initialItem$value38 === void 0 ? void 0 : _initialItem$value38.data.width) : ((_initialItem$value39 = initialItem.value) === null || _initialItem$value39 === void 0 ? void 0 : _initialItem$value39.data.width) || 0;
732
+ const heightText = typeof ((_initialItem$value40 = initialItem.value) === null || _initialItem$value40 === void 0 ? void 0 : _initialItem$value40.data.height) === 'string' ? parseFloat((_initialItem$value41 = initialItem.value) === null || _initialItem$value41 === void 0 ? void 0 : _initialItem$value41.data.height) : ((_initialItem$value42 = initialItem.value) === null || _initialItem$value42 === void 0 ? void 0 : _initialItem$value42.data.height) || 0;
733
+ switch (zone) {
734
+ case 'LEFT':
735
+ currentItem.value = {
736
+ type: currentItem.value.type,
737
+ strokeWidth: currentItem.value.strokeWidth,
738
+ color: currentItem.value.color,
739
+ text: currentItem.value.text,
740
+ data: {
741
+ x: xText + translationX,
742
+ y: yText,
743
+ width: widthText - translationX,
744
+ height: heightText
745
+ }
746
+ };
747
+ break;
748
+ case 'RIGHT':
749
+ currentItem.value = {
750
+ type: currentItem.value.type,
751
+ strokeWidth: currentItem.value.strokeWidth,
752
+ color: currentItem.value.color,
753
+ text: currentItem.value.text,
754
+ data: {
755
+ x: xText,
756
+ y: yText,
757
+ width: widthText + translationX,
758
+ height: heightText
759
+ }
760
+ };
761
+ break;
762
+ case 'CENTER':
763
+ currentItem.value = {
764
+ type: currentItem.value.type,
765
+ strokeWidth: currentItem.value.strokeWidth,
766
+ color: currentItem.value.color,
767
+ text: currentItem.value.text,
768
+ data: {
769
+ x: xText + translationX,
770
+ y: yText + translationY,
771
+ width: widthText,
772
+ height: heightText
773
+ }
774
+ };
775
+ break;
709
776
  }
710
- break;
711
- case 'text':
712
- console.log('on active text');
713
- if (((_initialItem$value30 = initialItem.value) === null || _initialItem$value30 === void 0 ? void 0 : _initialItem$value30.type) === currentItem.value.type) {
714
- var _initialItem$value31, _initialItem$value32, _initialItem$value33, _initialItem$value34, _initialItem$value35, _initialItem$value36, _initialItem$value37, _initialItem$value38, _initialItem$value39, _initialItem$value40, _initialItem$value41, _initialItem$value42;
715
- const xText = typeof ((_initialItem$value31 = initialItem.value) === null || _initialItem$value31 === void 0 ? void 0 : _initialItem$value31.data.x) === 'string' ? parseFloat((_initialItem$value32 = initialItem.value) === null || _initialItem$value32 === void 0 ? void 0 : _initialItem$value32.data.x) : ((_initialItem$value33 = initialItem.value) === null || _initialItem$value33 === void 0 ? void 0 : _initialItem$value33.data.x) || 0;
716
- const yText = typeof ((_initialItem$value34 = initialItem.value) === null || _initialItem$value34 === void 0 ? void 0 : _initialItem$value34.data.y) === 'string' ? parseFloat((_initialItem$value35 = initialItem.value) === null || _initialItem$value35 === void 0 ? void 0 : _initialItem$value35.data.y) : ((_initialItem$value36 = initialItem.value) === null || _initialItem$value36 === void 0 ? void 0 : _initialItem$value36.data.y) || 0;
717
- const widthText = typeof ((_initialItem$value37 = initialItem.value) === null || _initialItem$value37 === void 0 ? void 0 : _initialItem$value37.data.width) === 'string' ? parseFloat((_initialItem$value38 = initialItem.value) === null || _initialItem$value38 === void 0 ? void 0 : _initialItem$value38.data.width) : ((_initialItem$value39 = initialItem.value) === null || _initialItem$value39 === void 0 ? void 0 : _initialItem$value39.data.width) || 0;
718
- const heightText = typeof ((_initialItem$value40 = initialItem.value) === null || _initialItem$value40 === void 0 ? void 0 : _initialItem$value40.data.height) === 'string' ? parseFloat((_initialItem$value41 = initialItem.value) === null || _initialItem$value41 === void 0 ? void 0 : _initialItem$value41.data.height) : ((_initialItem$value42 = initialItem.value) === null || _initialItem$value42 === void 0 ? void 0 : _initialItem$value42.data.height) || 0;
719
- switch (zone) {
720
- case 'LEFT':
721
- currentItem.value = {
722
- type: currentItem.value.type,
723
- strokeWidth: currentItem.value.strokeWidth,
724
- color: currentItem.value.color,
725
- text: currentItem.value.text,
726
- data: {
727
- x: xText + translationX,
728
- y: yText,
729
- width: widthText - translationX,
730
- height: heightText
731
- }
732
- };
733
- break;
734
- case 'RIGHT':
735
- currentItem.value = {
736
- type: currentItem.value.type,
737
- strokeWidth: currentItem.value.strokeWidth,
738
- color: currentItem.value.color,
739
- text: currentItem.value.text,
740
- data: {
741
- x: xText,
742
- y: yText,
743
- width: widthText + translationX,
744
- height: heightText
745
- }
746
- };
747
- break;
748
- case 'CENTER':
749
- currentItem.value = {
750
- type: currentItem.value.type,
751
- strokeWidth: currentItem.value.strokeWidth,
752
- color: currentItem.value.color,
753
- text: currentItem.value.text,
754
- data: {
755
- x: xText + translationX,
756
- y: yText + translationY,
757
- width: widthText,
758
- height: heightText
759
- }
760
- };
761
- break;
777
+ } else {
778
+ currentItem.value = {
779
+ type: currentItem.value.type,
780
+ strokeWidth: currentItem.value.strokeWidth,
781
+ color: currentItem.value.color,
782
+ text: currentItem.value.text,
783
+ data: {
784
+ x: startX + translationX,
785
+ y: startY + translationY,
786
+ width: currentItem.value.data.width,
787
+ height: currentItem.value.data.height
762
788
  }
763
- } else {
764
- currentItem.value = {
765
- type: currentItem.value.type,
766
- strokeWidth: currentItem.value.strokeWidth,
767
- color: currentItem.value.color,
768
- text: currentItem.value.text,
769
- data: {
770
- x: startX + translationX,
771
- y: startY + translationY,
772
- width: currentItem.value.data.width,
773
- height: currentItem.value.data.height
774
- }
775
- };
776
- }
777
- }
778
- },
779
- onEnd: _event => {
780
- var _currentItem$value6, _currentItem$value7;
781
- if (((_currentItem$value6 = currentItem.value) === null || _currentItem$value6 === void 0 ? void 0 : _currentItem$value6.type) === 'doubleArrows') {
782
- runOnJS(textFocusState)();
783
- }
784
- if (((_currentItem$value7 = currentItem.value) === null || _currentItem$value7 === void 0 ? void 0 : _currentItem$value7.type) === 'text') {
785
- runOnJS(textFocus)();
786
- currentItem.value = {
787
- type: currentItem.value.type,
788
- strokeWidth: currentItem.value.strokeWidth,
789
- color: currentItem.value.color,
790
- data: currentItem.value.data,
791
- text: currentItem.value.text !== DEFAULT_TEXT ? currentItem.value.text ?? '' : ''
792
- };
793
- }
794
- runOnJS(addScreenStates)(currentItem.value);
789
+ };
790
+ }
791
+ }
792
+ }).onEnd(() => {
793
+ var _currentItem$value5, _currentItem$value6;
794
+ if (((_currentItem$value5 = currentItem.value) === null || _currentItem$value5 === void 0 ? void 0 : _currentItem$value5.type) === 'doubleArrows') {
795
+ runOnJS(textFocusState)();
796
+ }
797
+ if (((_currentItem$value6 = currentItem.value) === null || _currentItem$value6 === void 0 ? void 0 : _currentItem$value6.type) === 'text') {
798
+ runOnJS(textFocus)();
799
+ currentItem.value = {
800
+ type: currentItem.value.type,
801
+ strokeWidth: currentItem.value.strokeWidth,
802
+ color: currentItem.value.color,
803
+ data: currentItem.value.data,
804
+ text: currentItem.value.text !== DEFAULT_TEXT ? currentItem.value.text ?? '' : ''
805
+ };
795
806
  }
807
+ runOnJS(addScreenStates)(currentItem.value);
796
808
  });
797
809
  useEffect(() => {
798
810
  const sudDidHide = Keyboard.addListener('keyboardDidHide', () => {
@@ -800,7 +812,6 @@ const DrawCore = _ref => {
800
812
  });
801
813
  const sudDidShow = Keyboard.addListener('keyboardDidShow', event => {
802
814
  // avoid events triggered by InputAccessoryView
803
- console.log('keyboardDidShow dc');
804
815
  if (event.endCoordinates.height > 100) {
805
816
  showTextInput.value = true;
806
817
  }
@@ -818,13 +829,13 @@ const DrawCore = _ref => {
818
829
  strokeWidth: strokeWidth.value,
819
830
  color: color === null || color === void 0 ? void 0 : color.value
820
831
  };
821
- }, _ref4 => {
822
- var _currentItem$value8;
832
+ }, _ref2 => {
833
+ var _currentItem$value7;
823
834
  let {
824
835
  strokeWidth: sw,
825
836
  color: c
826
- } = _ref4;
827
- switch ((_currentItem$value8 = currentItem.value) === null || _currentItem$value8 === void 0 ? void 0 : _currentItem$value8.type) {
837
+ } = _ref2;
838
+ switch ((_currentItem$value7 = currentItem.value) === null || _currentItem$value7 === void 0 ? void 0 : _currentItem$value7.type) {
828
839
  case 'singleHead':
829
840
  case 'doubleHead':
830
841
  case 'doubleArrows':
@@ -850,12 +861,10 @@ const DrawCore = _ref => {
850
861
  }
851
862
  }, [strokeWidth.value, color === null || color === void 0 ? void 0 : color.value]);
852
863
  const onPressItem = useCallback((item, index) => () => {
853
- console.log('onPressItem');
854
- itemIsSelected.value = true;
855
864
  const previousItem = currentItem.value;
865
+ itemIsSelected.value = true;
856
866
  strokeWidth.value = item.strokeWidth;
857
867
  color.value = item.color;
858
- console.log('item', item);
859
868
  currentItem.value = item;
860
869
  deleteDoneItem(index);
861
870
  if (previousItem) {
@@ -906,11 +915,11 @@ const DrawCore = _ref => {
906
915
  onTextHeightUpdate(currentItem, textBaseHeight, height);
907
916
  }, [currentItem, textBaseHeight]);
908
917
  const calculateSizes = useCallback((imageWidth, imageHeight) => {
918
+ setOriginalImageSize({
919
+ width: imageWidth,
920
+ height: imageHeight
921
+ });
909
922
  if (drawRegion) {
910
- setOriginalImageSize({
911
- width: imageWidth,
912
- height: imageHeight
913
- });
914
923
  const ratioImageHeight = Math.round(imageHeight * drawRegion.width / imageWidth * 100) / 100;
915
924
  if (ratioImageHeight < drawRegion.height) {
916
925
  setImageSize({
@@ -940,35 +949,18 @@ const DrawCore = _ref => {
940
949
 
941
950
  // do not remove keyboard will appear over the drawing frame and not shift it
942
951
  useAnimatedKeyboard();
943
-
944
- /*
945
- const onEndEditingTextInput = useCallback(() => {
946
- console.log('onEndEditingTextInput');
947
- setShowTextInputState(false);
948
- if (currentItem.value && currentItem.value.type === 'doubleArrows') {
949
- console.log(currentItem.value.text);
950
- addScreenStates(currentItem.value);
951
- }
952
- }, [currentItem, addScreenStates]);
953
- const onChangeText = useCallback(
954
- (value: string) => {
955
- if (
956
- value &&
957
- currentItem.value &&
958
- currentItem.value.type === 'doubleArrows'
959
- ) {
960
- console.log('******************');
961
- console.log(value);
962
- console.log(currentItem.value);
963
- currentItem.value = {
964
- ...currentItem.value,
965
- text: value,
966
- };
952
+ const [newLayoutRequested, setNewLayoutRequested] = useState(false);
953
+ const onLayout = useCallback(async () => {
954
+ if (newLayoutRequested) {
955
+ setNewLayoutRequested(false);
956
+ const uri = await captureSnapshot();
957
+ if (uri && typeof actionWithSnapShotUri === 'function') {
958
+ await actionWithSnapShotUri(uri);
967
959
  }
968
- },
969
- [currentItem]
970
- );
971
- */
960
+ }
961
+ }, [actionWithSnapShotUri, newLayoutRequested, captureSnapshot]);
962
+ const [ratioImage, setRatioImage] = useState(1);
963
+ const [opacity, setOpacity] = useState(1);
972
964
  return /*#__PURE__*/React.createElement(View, {
973
965
  style: styles.container
974
966
  }, /*#__PURE__*/React.createElement(View, {
@@ -984,10 +976,14 @@ const DrawCore = _ref => {
984
976
  }, /*#__PURE__*/React.createElement(KeyboardAvoidingView, {
985
977
  behavior: "position",
986
978
  keyboardVerticalOffset: 70
987
- }, /*#__PURE__*/React.createElement(PanGestureHandler, {
988
- onGestureEvent: onGestureEvent
979
+ }, /*#__PURE__*/React.createElement(GestureDetector, {
980
+ gesture: panGesture
989
981
  }, /*#__PURE__*/React.createElement(Animated.View, {
990
- style: imageSize || drawRegion
982
+ style: {
983
+ ...(imageSize || drawRegion),
984
+ opacity: opacity
985
+ },
986
+ onLayout: onLayout
991
987
  }, /*#__PURE__*/React.createElement(View, {
992
988
  ref: drawContainer
993
989
  }, image ? imageSize && originalImageSize ? /*#__PURE__*/React.createElement(ViewShot, {
@@ -1004,21 +1000,23 @@ const DrawCore = _ref => {
1004
1000
  currentItem: currentItem,
1005
1001
  doneItems: drawState.doneItems,
1006
1002
  onPressItem: onPressItem,
1007
- onTextHeightChange: onTextHeightChange
1003
+ onTextHeightChange: onTextHeightChange,
1004
+ ratioImage: ratioImage
1008
1005
  }))) : null : drawRegion ? /*#__PURE__*/React.createElement(ViewShot, {
1009
1006
  ref: viewShot,
1010
1007
  options: {
1011
1008
  format: 'jpg',
1012
1009
  quality: 1,
1013
- ...drawRegion
1010
+ ...(imageSize || drawRegion)
1014
1011
  },
1015
- style: drawRegion
1012
+ style: imageSize || drawRegion
1016
1013
  }, /*#__PURE__*/React.createElement(DrawPad, {
1017
1014
  addBackground: true,
1018
1015
  currentItem: currentItem,
1019
1016
  doneItems: drawState.doneItems,
1020
1017
  onPressItem: onPressItem,
1021
- onTextHeightChange: onTextHeightChange
1018
+ onTextHeightChange: onTextHeightChange,
1019
+ ratioImage: ratioImage
1022
1020
  })) : null))), /*#__PURE__*/React.createElement(TextInput, {
1023
1021
  ref: textInputRef,
1024
1022
  style: styles.textInput,