@solostylist/image-editor 1.0.8 → 1.0.10
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/lib/actions/add-filter.js +11 -1
- package/lib/actions/change-pointer-icon.js +10 -1
- package/lib/actions/change-rotation.js +13 -1
- package/lib/actions/clear-annotations-selections.js +10 -1
- package/lib/actions/duplicate-annotations.js +26 -1
- package/lib/actions/enable-text-content-edit.js +10 -1
- package/lib/actions/hide-loader.js +10 -1
- package/lib/actions/index.js +36 -1
- package/lib/actions/redo.js +27 -1
- package/lib/actions/remove-annotations.js +27 -1
- package/lib/actions/reset.js +26 -1
- package/lib/actions/select-annotation.js +27 -1
- package/lib/actions/select-tab.js +16 -1
- package/lib/actions/select-tool.js +11 -1
- package/lib/actions/set-annotation.js +28 -1
- package/lib/actions/set-canvas-size.js +31 -1
- package/lib/actions/set-crop.js +25 -1
- package/lib/actions/set-feedback.js +11 -1
- package/lib/actions/set-finetune.js +13 -1
- package/lib/actions/set-latest-color.js +10 -1
- package/lib/actions/set-original-image.js +13 -1
- package/lib/actions/set-resize.js +14 -1
- package/lib/actions/set-saved.js +10 -1
- package/lib/actions/set-saving.js +11 -1
- package/lib/actions/set-show-tabs-menu.js +10 -1
- package/lib/actions/set-shown-image-dimensions.js +12 -1
- package/lib/actions/show-loader.js +10 -1
- package/lib/actions/toggle-flip.js +13 -1
- package/lib/actions/toggle-original-image-display.js +10 -1
- package/lib/actions/undo.js +27 -1
- package/lib/actions/update-state.js +7 -1
- package/lib/actions/zoom-canvas.js +37 -1
- package/lib/components/app/index.js +283 -1
- package/lib/components/assembly-point/index.js +23 -1
- package/lib/components/common/annotation-options/annotation-options.constants.js +10 -1
- package/lib/components/common/annotation-options/index.js +140 -1
- package/lib/components/common/annotation-options/opacity-field.js +23 -1
- package/lib/components/common/annotation-options/position-fields.js +39 -1
- package/lib/components/common/annotation-options/shadow-fields.js +62 -1
- package/lib/components/common/annotation-options/stroke-fields.js +33 -1
- package/lib/components/common/button-with-menu/index.js +86 -1
- package/lib/components/common/color-input/index.js +101 -1
- package/lib/components/common/color-picker-modal/index.js +70 -1
- package/lib/components/common/hidden-upload-input/index.js +17 -1
- package/lib/components/common/icon-wrapper/index.js +40 -1
- package/lib/components/common/image-preview-tile/index.js +57 -1
- package/lib/components/common/slider/index.js +38 -1
- package/lib/components/feedback-popup/index.js +41 -1
- package/lib/components/layers/design-layer/annotation-nodes/annotation-nodes.constants.js +10 -1
- package/lib/components/layers/design-layer/annotation-nodes/arrow-node.js +62 -1
- package/lib/components/layers/design-layer/annotation-nodes/ellipse-node.js +64 -1
- package/lib/components/layers/design-layer/annotation-nodes/image-node.js +78 -1
- package/lib/components/layers/design-layer/annotation-nodes/index.js +22 -1
- package/lib/components/layers/design-layer/annotation-nodes/line-node.js +60 -1
- package/lib/components/layers/design-layer/annotation-nodes/memoized-annotation.js +16 -1
- package/lib/components/layers/design-layer/annotation-nodes/polygon-node.js +63 -1
- package/lib/components/layers/design-layer/annotation-nodes/rect-node.js +65 -1
- package/lib/components/layers/design-layer/annotation-nodes/text-node.js +80 -1
- package/lib/components/layers/design-layer/index.js +202 -1
- package/lib/components/layers/design-layer/nodes-common-prop-types.js +16 -1
- package/lib/components/layers/design-layer/preview-group.js +9 -1
- package/lib/components/layers/index.js +2 -1
- package/lib/components/layers/transformers-layer/crop-transformer.js +248 -1
- package/lib/components/layers/transformers-layer/index.js +16 -1
- package/lib/components/layers/transformers-layer/nodes-transformer.js +73 -1
- package/lib/components/layers/transformers-layer/transformers-layer.utils.js +93 -1
- package/lib/components/main-canvas/canvas-node.js +177 -1
- package/lib/components/main-canvas/index.js +51 -1
- package/lib/components/main-canvas/touch-zooming-events.js +69 -1
- package/lib/components/node-controls/index.js +79 -1
- package/lib/components/tabs/index.js +66 -1
- package/lib/components/tabs/tabs.constants.js +27 -1
- package/lib/components/tabs-drawer/index.js +109 -1
- package/lib/components/tools/arrow/arrow-button.js +17 -1
- package/lib/components/tools/arrow/arrow-options.js +19 -1
- package/lib/components/tools/arrow/index.js +2 -1
- package/lib/components/tools/blur/blur-options.js +35 -1
- package/lib/components/tools/blur/blur.js +17 -1
- package/lib/components/tools/blur/index.js +2 -1
- package/lib/components/tools/brightness/brightness-options.js +36 -1
- package/lib/components/tools/brightness/brightness.js +17 -1
- package/lib/components/tools/brightness/index.js +2 -1
- package/lib/components/tools/contrast/contrast-options.js +35 -1
- package/lib/components/tools/contrast/contrast.js +17 -1
- package/lib/components/tools/contrast/index.js +2 -1
- package/lib/components/tools/crop/crop.constants.js +31 -1
- package/lib/components/tools/crop/crop.js +122 -1
- package/lib/components/tools/crop/index.js +1 -1
- package/lib/components/tools/ellipse/ellipse-button.js +17 -1
- package/lib/components/tools/ellipse/ellipse-options.js +17 -1
- package/lib/components/tools/ellipse/index.js +2 -1
- package/lib/components/tools/filters/filter-item.js +77 -1
- package/lib/components/tools/filters/filters.constants.js +139 -1
- package/lib/components/tools/filters/filters.js +74 -1
- package/lib/components/tools/filters/index.js +1 -1
- package/lib/components/tools/flip/flip-x.js +48 -1
- package/lib/components/tools/flip/flip-y.js +50 -1
- package/lib/components/tools/flip/index.js +2 -1
- package/lib/components/tools/hsv/hsv.js +17 -1
- package/lib/components/tools/hsv/hsvoptions.js +60 -1
- package/lib/components/tools/hsv/index.js +2 -1
- package/lib/components/tools/image/image-button.js +17 -1
- package/lib/components/tools/image/image-controls.js +12 -1
- package/lib/components/tools/image/image-options.js +162 -1
- package/lib/components/tools/image/images-gallery.js +55 -1
- package/lib/components/tools/image/index.js +2 -1
- package/lib/components/tools/line/index.js +2 -1
- package/lib/components/tools/line/line-button.js +17 -1
- package/lib/components/tools/line/line-options.js +19 -1
- package/lib/components/tools/pen/index.js +2 -1
- package/lib/components/tools/pen/pen-button.js +17 -1
- package/lib/components/tools/pen/pen-options.js +120 -1
- package/lib/components/tools/polygon/index.js +2 -1
- package/lib/components/tools/polygon/polygon-button.js +17 -1
- package/lib/components/tools/polygon/polygon-options.js +22 -1
- package/lib/components/tools/polygon/polygon-sides-field.js +23 -1
- package/lib/components/tools/polygon/polygon.constants.js +10 -1
- package/lib/components/tools/rect/index.js +2 -1
- package/lib/components/tools/rect/rect-button.js +17 -1
- package/lib/components/tools/rect/rect-corner-field.js +24 -1
- package/lib/components/tools/rect/rect-options.js +21 -1
- package/lib/components/tools/rect/rect.constants.js +10 -1
- package/lib/components/tools/resize/index.js +1 -1
- package/lib/components/tools/resize/resize.js +141 -1
- package/lib/components/tools/rotate/index.js +2 -1
- package/lib/components/tools/rotate/rotate-button.js +17 -1
- package/lib/components/tools/rotate/rotate-options.js +97 -1
- package/lib/components/tools/text/index.js +2 -1
- package/lib/components/tools/text/text-button.js +17 -1
- package/lib/components/tools/text/text-options/handle-text-change-area.js +122 -1
- package/lib/components/tools/text/text-options/index.js +17 -1
- package/lib/components/tools/text/text-options/text-alignment-fields.js +38 -1
- package/lib/components/tools/text/text-options/text-controls.js +147 -1
- package/lib/components/tools/text/text-options/text-options.constants.js +16 -1
- package/lib/components/tools/text/text-options/text-spacings-fields.js +34 -1
- package/lib/components/tools/tools.constants.js +98 -1
- package/lib/components/tools/warmth/index.js +2 -1
- package/lib/components/tools/warmth/warmth-options.js +35 -1
- package/lib/components/tools/warmth/warmth.js +17 -1
- package/lib/components/tools/watermark/index.js +1 -1
- package/lib/components/tools/watermark/watermark-padding.js +59 -1
- package/lib/components/tools/watermark/watermark.js +221 -1
- package/lib/components/tools/watermark/watermarks-gallery.js +77 -1
- package/lib/components/tools-bar/index.js +113 -1
- package/lib/components/tools-bar/tools-bar-item-button.js +39 -1
- package/lib/components/topbar/canvas-zooming.js +119 -1
- package/lib/components/topbar/confirmation-modal.js +53 -1
- package/lib/components/topbar/image-dimensions-and-display-toggle.js +68 -1
- package/lib/components/topbar/index.js +47 -1
- package/lib/components/topbar/redo-button.js +25 -1
- package/lib/components/topbar/reset-button.js +21 -1
- package/lib/components/topbar/save-button.js +251 -1
- package/lib/components/topbar/topbar.constants.js +31 -1
- package/lib/components/topbar/undo-button.js +27 -1
- package/lib/context/app-context.js +3 -1
- package/lib/context/app-provider-overriden-value.js +9 -1
- package/lib/context/app-provider.js +48 -1
- package/lib/context/app-reducer.js +5 -1
- package/lib/context/default-config.js +75 -1
- package/lib/context/default-translations.js +115 -1
- package/lib/context/get-initial-app-state.js +61 -1
- package/lib/context/index.js +4 -1
- package/lib/custom/filters/aden.js +8 -1
- package/lib/custom/filters/amaro.js +8 -1
- package/lib/custom/filters/ashby.js +8 -1
- package/lib/custom/filters/base-filters.js +82 -1
- package/lib/custom/filters/black-and-white.js +11 -1
- package/lib/custom/filters/brannan.js +8 -1
- package/lib/custom/filters/brooklyn.js +8 -1
- package/lib/custom/filters/charmes.js +8 -1
- package/lib/custom/filters/clarendon.js +9 -1
- package/lib/custom/filters/crema.js +8 -1
- package/lib/custom/filters/dogpatch.js +8 -1
- package/lib/custom/filters/earlybird.js +7 -1
- package/lib/custom/filters/gingham.js +8 -1
- package/lib/custom/filters/ginza.js +8 -1
- package/lib/custom/filters/hefe.js +8 -1
- package/lib/custom/filters/helena.js +8 -1
- package/lib/custom/filters/hudson.js +9 -1
- package/lib/custom/filters/index.js +40 -1
- package/lib/custom/filters/juno.js +8 -1
- package/lib/custom/filters/kelvin.js +9 -1
- package/lib/custom/filters/lark.js +9 -1
- package/lib/custom/filters/lo-fi.js +8 -1
- package/lib/custom/filters/ludwig.js +8 -1
- package/lib/custom/filters/maven.js +9 -1
- package/lib/custom/filters/mayfair.js +8 -1
- package/lib/custom/filters/moon.js +7 -1
- package/lib/custom/filters/nashville.js +8 -1
- package/lib/custom/filters/ninteen-seventy-seven.js +8 -1
- package/lib/custom/filters/perpetua.js +7 -1
- package/lib/custom/filters/reyes.js +9 -1
- package/lib/custom/filters/rise.js +9 -1
- package/lib/custom/filters/sierra.js +8 -1
- package/lib/custom/filters/skyline.js +8 -1
- package/lib/custom/filters/slumber.js +8 -1
- package/lib/custom/filters/stinson.js +8 -1
- package/lib/custom/filters/sutro.js +8 -1
- package/lib/custom/filters/toaster.js +8 -1
- package/lib/custom/filters/valencia.js +9 -1
- package/lib/custom/filters/vesper.js +9 -1
- package/lib/custom/filters/walden.js +8 -1
- package/lib/custom/filters/willow.js +8 -1
- package/lib/custom/filters/xpro2.js +9 -1
- package/lib/custom/finetunes/custom-threshold.js +19 -1
- package/lib/custom/finetunes/index.js +2 -1
- package/lib/custom/finetunes/warmth.js +15 -1
- package/lib/demo/app.js +175 -1
- package/lib/demo/index.js +1 -1
- package/lib/hooks/index.js +12 -1
- package/lib/hooks/use-annotation/get-bounding-rect-un-scaled.js +14 -1
- package/lib/hooks/use-annotation/get-new-annotation-preview.js +83 -1
- package/lib/hooks/use-annotation/index.js +138 -1
- package/lib/hooks/use-annotation/preview-then-call-annotation-adding.js +159 -1
- package/lib/hooks/use-annotation-events.js +83 -1
- package/lib/hooks/use-app-reducer.js +53 -1
- package/lib/hooks/use-debounced-callback.js +7 -1
- package/lib/hooks/use-drag.js +37 -1
- package/lib/hooks/use-filter.js +20 -1
- package/lib/hooks/use-finetune.js +31 -1
- package/lib/hooks/use-phone-screen.js +5 -1
- package/lib/hooks/use-popover.js +27 -1
- package/lib/hooks/use-resize-observer.js +60 -1
- package/lib/hooks/use-store.js +6 -1
- package/lib/hooks/use-transformed-img-data.js +156 -1
- package/lib/hooks/use-update-effect.js +18 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +4 -1
- package/lib/types/actions.js +31 -1
- package/lib/types/annotations.js +42 -1
- package/lib/types/common.js +1 -1
- package/lib/types/config.js +34 -1
- package/lib/types/index.js +5 -1
- package/lib/types/state.js +1 -1
- package/lib/utils/assign-finetune-names-to-konva.js +7 -1
- package/lib/utils/calculate-zoom-data.js +36 -1
- package/lib/utils/compare-ratios.js +5 -1
- package/lib/utils/constants.js +84 -1
- package/lib/utils/crop-image.js +10 -1
- package/lib/utils/debounce.js +19 -1
- package/lib/utils/deep-merge.js +26 -1
- package/lib/utils/extract-current-design-state.js +15 -1
- package/lib/utils/extract-name-from-url.js +5 -1
- package/lib/utils/filter-str-to-class.js +9 -1
- package/lib/utils/finetunes-strs-to-classes.js +13 -1
- package/lib/utils/get-center-rotated-point.js +34 -1
- package/lib/utils/get-default-save-quality.js +5 -1
- package/lib/utils/get-dimensions-minimal-ratio.js +6 -1
- package/lib/utils/get-elem-document-coords.js +24 -1
- package/lib/utils/get-file-full-name.js +21 -1
- package/lib/utils/get-pointer-offset-position-bounded-to-object.js +26 -1
- package/lib/utils/get-proper-dimensions.js +21 -1
- package/lib/utils/get-proper-image-to-canvas-spacing.js +6 -1
- package/lib/utils/get-scroll-offset.js +13 -1
- package/lib/utils/get-size-after-rotation.js +31 -1
- package/lib/utils/get-zoom-fit-factor.js +5 -1
- package/lib/utils/image-to-base64.js +12 -1
- package/lib/utils/is-default-zero-values-only.js +6 -1
- package/lib/utils/is-same-image.js +4 -1
- package/lib/utils/load-image.js +19 -1
- package/lib/utils/map-crop-box.js +16 -1
- package/lib/utils/map-number.js +4 -1
- package/lib/utils/map-position-string-to-point.js +92 -1
- package/lib/utils/random-id.js +5 -1
- package/lib/utils/restrict-number.js +7 -1
- package/lib/utils/serialize-design-state.js +62 -1
- package/lib/utils/to-precised-float.js +5 -1
- package/lib/utils/translator.js +14 -1
- package/package.json +1 -1
|
@@ -1 +1,83 @@
|
|
|
1
|
-
import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
var _excluded = ["width", "height", "startedX", "startedY"];
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
import Konva from 'konva';
|
|
7
|
+
import { TOOLS_IDS } from 'utils/constants';
|
|
8
|
+
var annotationsNamesToKonvaClasses = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TOOLS_IDS.RECT, Konva.Rect), TOOLS_IDS.ELLIPSE, Konva.Ellipse), TOOLS_IDS.POLYGON, Konva.RegularPolygon), TOOLS_IDS.LINE, Konva.Line), TOOLS_IDS.IMAGE, Konva.Image), TOOLS_IDS.TEXT, Konva.Text), TOOLS_IDS.ARROW, Konva.Arrow);
|
|
9
|
+
var ANNOTATIONS_WITH_POINTS = [TOOLS_IDS.LINE, TOOLS_IDS.ARROW];
|
|
10
|
+
export var NO_WIDTH_HEIGHT_ANNOTATIONS = [].concat(ANNOTATIONS_WITH_POINTS, [TOOLS_IDS.ELLIPSE, TOOLS_IDS.POLYGON]);
|
|
11
|
+
var getNewAnnotationPreview = function getNewAnnotationPreview(annotation) {
|
|
12
|
+
var _annotation$opacity, _annotation$x, _annotation$y;
|
|
13
|
+
return new annotationsNamesToKonvaClasses[annotation.name](_objectSpread(_objectSpread({}, annotation), {}, {
|
|
14
|
+
opacity: (_annotation$opacity = annotation.opacity) !== null && _annotation$opacity !== void 0 ? _annotation$opacity : 0.7,
|
|
15
|
+
x: (_annotation$x = annotation.x) !== null && _annotation$x !== void 0 ? _annotation$x : 0,
|
|
16
|
+
y: (_annotation$y = annotation.y) !== null && _annotation$y !== void 0 ? _annotation$y : 0,
|
|
17
|
+
width: Math.abs(annotation.width) || 0,
|
|
18
|
+
height: Math.abs(annotation.height) || 0
|
|
19
|
+
}, ANNOTATIONS_WITH_POINTS.includes(annotation.name) ? {
|
|
20
|
+
stroke: annotation.stroke || '#000000'
|
|
21
|
+
} : {}));
|
|
22
|
+
};
|
|
23
|
+
export var dimensToProperAnnotationDimens = function dimensToProperAnnotationDimens(currentDimensions, annotationName, isShiftKeyPressed) {
|
|
24
|
+
var width = currentDimensions.width,
|
|
25
|
+
height = currentDimensions.height,
|
|
26
|
+
startedX = currentDimensions.startedX,
|
|
27
|
+
startedY = currentDimensions.startedY,
|
|
28
|
+
newAnnotationDimens = _objectWithoutProperties(currentDimensions, _excluded);
|
|
29
|
+
var absWidth = Math.abs(width);
|
|
30
|
+
var absHeight = Math.abs(height);
|
|
31
|
+
var isReversedX = width < 0;
|
|
32
|
+
var isReversedY = height < 0;
|
|
33
|
+
switch (annotationName) {
|
|
34
|
+
case TOOLS_IDS.RECT:
|
|
35
|
+
if (isShiftKeyPressed) {
|
|
36
|
+
newAnnotationDimens.width = Math.sqrt(absWidth * absWidth + absHeight * absHeight);
|
|
37
|
+
newAnnotationDimens.height = newAnnotationDimens.width;
|
|
38
|
+
newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.width - absWidth : 0;
|
|
39
|
+
newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.height - absHeight : 0;
|
|
40
|
+
} else {
|
|
41
|
+
newAnnotationDimens.width = absWidth;
|
|
42
|
+
newAnnotationDimens.height = absHeight;
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
case TOOLS_IDS.ELLIPSE:
|
|
46
|
+
if (isShiftKeyPressed) {
|
|
47
|
+
newAnnotationDimens.radiusX = Math.sqrt(absWidth * absWidth + absHeight * absHeight) / 2;
|
|
48
|
+
newAnnotationDimens.radiusY = newAnnotationDimens.radiusX;
|
|
49
|
+
newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.radiusX * 2 - absWidth : 0;
|
|
50
|
+
newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.radiusY * 2 - absHeight : 0;
|
|
51
|
+
} else {
|
|
52
|
+
newAnnotationDimens.radiusX = absWidth / 2;
|
|
53
|
+
newAnnotationDimens.radiusY = absHeight / 2;
|
|
54
|
+
}
|
|
55
|
+
newAnnotationDimens.offsetX = -newAnnotationDimens.radiusX;
|
|
56
|
+
newAnnotationDimens.offsetY = -newAnnotationDimens.radiusY;
|
|
57
|
+
break;
|
|
58
|
+
case TOOLS_IDS.POLYGON:
|
|
59
|
+
newAnnotationDimens.radius = (absWidth + absHeight) / 2;
|
|
60
|
+
newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.radius * 2 - absWidth : 0;
|
|
61
|
+
newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.radius * 2 - absHeight : 0;
|
|
62
|
+
newAnnotationDimens.offsetX = -newAnnotationDimens.radius;
|
|
63
|
+
newAnnotationDimens.offsetY = -newAnnotationDimens.radius;
|
|
64
|
+
break;
|
|
65
|
+
case TOOLS_IDS.LINE:
|
|
66
|
+
case TOOLS_IDS.ARROW:
|
|
67
|
+
newAnnotationDimens.x = startedX;
|
|
68
|
+
newAnnotationDimens.y = startedY;
|
|
69
|
+
newAnnotationDimens.points = [0, 0];
|
|
70
|
+
if (isShiftKeyPressed) {
|
|
71
|
+
newAnnotationDimens.points.push(absWidth >= absHeight ? width : 0, absHeight > absWidth ? height : 0);
|
|
72
|
+
} else {
|
|
73
|
+
newAnnotationDimens.points = [0, 0, width, height];
|
|
74
|
+
}
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
newAnnotationDimens.width = absWidth;
|
|
78
|
+
newAnnotationDimens.height = absHeight;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return newAnnotationDimens;
|
|
82
|
+
};
|
|
83
|
+
export default getNewAnnotationPreview;
|
|
@@ -1 +1,138 @@
|
|
|
1
|
-
import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
var _excluded = ["fonts", "onFontChange"],
|
|
5
|
+
_excluded2 = ["x", "y", "width", "height", "radius", "radiusX", "radiusY", "points", "image", "text", "scaleX", "scaleY", "rotation"],
|
|
6
|
+
_excluded3 = ["shouldSave", "neverSave"];
|
|
7
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
|
+
import { SELECT_ANNOTATION, SET_ANNOTATION } from 'actions';
|
|
11
|
+
import randomId from 'utils/random-id';
|
|
12
|
+
import debounce from 'utils/debounce';
|
|
13
|
+
import { TOOLS_IDS } from 'utils/constants';
|
|
14
|
+
import { useStore } from 'hooks';
|
|
15
|
+
import previewThenCallAnnotationAdding from "./preview-then-call-annotation-adding";
|
|
16
|
+
import useDebouncedCallback from "../use-debounced-callback";
|
|
17
|
+
var useAnnotation = function useAnnotation() {
|
|
18
|
+
var _annotations$selectio;
|
|
19
|
+
var annotation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
20
|
+
var enablePreview = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
21
|
+
var _useStore = useStore(),
|
|
22
|
+
dispatch = _useStore.dispatch,
|
|
23
|
+
previewGroup = _useStore.previewGroup,
|
|
24
|
+
annotations = _useStore.annotations,
|
|
25
|
+
_useStore$selectionsI = _useStore.selectionsIds,
|
|
26
|
+
selectionsIds = _useStore$selectionsI === void 0 ? [] : _useStore$selectionsI,
|
|
27
|
+
config = _useStore.config;
|
|
28
|
+
var annotationDefaults = _objectSpread(_objectSpread({}, config.annotationsCommon), config[((_annotations$selectio = annotations[selectionsIds[0]]) === null || _annotations$selectio === void 0 ? void 0 : _annotations$selectio.name) || annotation.name]);
|
|
29
|
+
var _useState = useState(function () {
|
|
30
|
+
return _objectSpread(_objectSpread(_objectSpread({}, annotationDefaults), annotation), annotations[selectionsIds[0]]);
|
|
31
|
+
}),
|
|
32
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
+
tmpAnnotation = _useState2[0],
|
|
34
|
+
setTmpAnnotation = _useState2[1];
|
|
35
|
+
var annotationBeforeSelection = useRef(null);
|
|
36
|
+
var canvas = previewGroup === null || previewGroup === void 0 ? void 0 : previewGroup.getStage();
|
|
37
|
+
var saveAnnotation = useCallback(function (annotationData) {
|
|
38
|
+
var _fonts = annotationData.fonts,
|
|
39
|
+
_onFontChange = annotationData.onFontChange,
|
|
40
|
+
savableAnnotationData = _objectWithoutProperties(annotationData, _excluded);
|
|
41
|
+
dispatch({
|
|
42
|
+
type: SET_ANNOTATION,
|
|
43
|
+
payload: savableAnnotationData
|
|
44
|
+
});
|
|
45
|
+
if (savableAnnotationData.id && annotation.name !== TOOLS_IDS.PEN) {
|
|
46
|
+
debounce(function () {
|
|
47
|
+
dispatch({
|
|
48
|
+
type: SELECT_ANNOTATION,
|
|
49
|
+
payload: {
|
|
50
|
+
annotationId: savableAnnotationData.id
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}, 30)();
|
|
54
|
+
}
|
|
55
|
+
}, [annotation.name, dispatch]);
|
|
56
|
+
var updateTmpAnnotation = useDebouncedCallback(function (updatesObjOrFn) {
|
|
57
|
+
setTmpAnnotation(function (latest) {
|
|
58
|
+
return _objectSpread(_objectSpread({}, latest), {}, {
|
|
59
|
+
shouldSave: false,
|
|
60
|
+
neverSave: false
|
|
61
|
+
}, typeof updatesObjOrFn === 'function' ? updatesObjOrFn(latest) : updatesObjOrFn);
|
|
62
|
+
});
|
|
63
|
+
}, 15);
|
|
64
|
+
var getAnnotationInitialProps = useCallback(function (currentAnnotation, newAnnotationName) {
|
|
65
|
+
if (currentAnnotation.name === newAnnotationName) {
|
|
66
|
+
var _x = currentAnnotation.x,
|
|
67
|
+
_y = currentAnnotation.y,
|
|
68
|
+
_width = currentAnnotation.width,
|
|
69
|
+
_height = currentAnnotation.height,
|
|
70
|
+
_radius = currentAnnotation.radius,
|
|
71
|
+
_radiusX = currentAnnotation.radiusX,
|
|
72
|
+
_radiusY = currentAnnotation.radiusY,
|
|
73
|
+
_points = currentAnnotation.points,
|
|
74
|
+
_image = currentAnnotation.image,
|
|
75
|
+
_text = currentAnnotation.text,
|
|
76
|
+
_scaleX = currentAnnotation.scaleX,
|
|
77
|
+
_scaleY = currentAnnotation.scaleY,
|
|
78
|
+
_rotation = currentAnnotation.rotation,
|
|
79
|
+
dimensionlessProps = _objectWithoutProperties(currentAnnotation, _excluded2);
|
|
80
|
+
return _objectSpread(_objectSpread(_objectSpread({}, annotationDefaults), annotation), dimensionlessProps);
|
|
81
|
+
}
|
|
82
|
+
return _objectSpread(_objectSpread({}, annotationDefaults), annotation);
|
|
83
|
+
}, [annotationDefaults, annotation]);
|
|
84
|
+
var saveAnnotationNoDebounce = useCallback(function (newAnnotationData) {
|
|
85
|
+
setTmpAnnotation(function (latest) {
|
|
86
|
+
var initialProps = getAnnotationInitialProps(latest, newAnnotationData.name || annotation.name);
|
|
87
|
+
return _objectSpread(_objectSpread(_objectSpread({}, initialProps), newAnnotationData), {}, {
|
|
88
|
+
id: newAnnotationData.id || randomId(newAnnotationData.name || latest.name),
|
|
89
|
+
shouldSave: true,
|
|
90
|
+
neverSave: false
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}, [annotation.name, getAnnotationInitialProps]);
|
|
94
|
+
useEffect(function () {
|
|
95
|
+
var shouldSave = tmpAnnotation.shouldSave,
|
|
96
|
+
neverSave = tmpAnnotation.neverSave,
|
|
97
|
+
savableAnnotation = _objectWithoutProperties(tmpAnnotation, _excluded3);
|
|
98
|
+
var selection = selectionsIds.length === 1 && annotations[selectionsIds[0]];
|
|
99
|
+
if (!neverSave && (shouldSave || selection)) {
|
|
100
|
+
saveAnnotation(_objectSpread(_objectSpread({}, savableAnnotation), {}, {
|
|
101
|
+
id: shouldSave ? savableAnnotation.id : selection.id
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
}, [tmpAnnotation, selectionsIds, annotations, saveAnnotation]);
|
|
105
|
+
useEffect(function () {
|
|
106
|
+
setTimeout(function () {
|
|
107
|
+
if (selectionsIds.length === 1) {
|
|
108
|
+
annotationBeforeSelection.current = tmpAnnotation;
|
|
109
|
+
setTmpAnnotation(_objectSpread(_objectSpread({}, annotations[selectionsIds[0]]), {}, {
|
|
110
|
+
neverSave: true
|
|
111
|
+
}));
|
|
112
|
+
} else if (annotationBeforeSelection.current) {
|
|
113
|
+
setTmpAnnotation(_objectSpread(_objectSpread({}, annotationBeforeSelection.current), {}, {
|
|
114
|
+
neverSave: true
|
|
115
|
+
}));
|
|
116
|
+
annotationBeforeSelection.current = null;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}, [selectionsIds, annotations]);
|
|
120
|
+
useEffect(function () {
|
|
121
|
+
var stopAnnotationEventsListening = null;
|
|
122
|
+
if (canvas && enablePreview) {
|
|
123
|
+
var annotationInitialProps = getAnnotationInitialProps(tmpAnnotation, annotation.name);
|
|
124
|
+
stopAnnotationEventsListening = previewThenCallAnnotationAdding(canvas, _objectSpread(_objectSpread({}, annotationInitialProps), {}, {
|
|
125
|
+
name: annotation.name
|
|
126
|
+
}), previewGroup, saveAnnotationNoDebounce);
|
|
127
|
+
}
|
|
128
|
+
return function () {
|
|
129
|
+
if (stopAnnotationEventsListening) {
|
|
130
|
+
stopAnnotationEventsListening();
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}, [canvas, tmpAnnotation, previewGroup, getAnnotationInitialProps, annotation.name, saveAnnotationNoDebounce]);
|
|
134
|
+
return useMemo(function () {
|
|
135
|
+
return [tmpAnnotation, updateTmpAnnotation, saveAnnotationNoDebounce];
|
|
136
|
+
}, [tmpAnnotation, updateTmpAnnotation, saveAnnotationNoDebounce]);
|
|
137
|
+
};
|
|
138
|
+
export default useAnnotation;
|
|
@@ -1 +1,159 @@
|
|
|
1
|
-
import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
var _excluded = ["id", "x", "y", "points"],
|
|
4
|
+
_excluded2 = ["startedX", "startedY", "offsetX", "offsetY", "width", "height"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { TOOLS_IDS } from 'utils/constants';
|
|
8
|
+
import getElemDocumentCoords from 'utils/get-elem-document-coords';
|
|
9
|
+
import getPointerOffsetPositionBoundedToObject from 'utils/get-pointer-offset-position-bounded-to-object';
|
|
10
|
+
import getBoundingRectUnScaled from "./get-bounding-rect-un-scaled";
|
|
11
|
+
import getNewAnnotationPreview, { dimensToProperAnnotationDimens, NO_WIDTH_HEIGHT_ANNOTATIONS } from "./get-new-annotation-preview";
|
|
12
|
+
var pointerDown = {
|
|
13
|
+
startedX: undefined,
|
|
14
|
+
startedY: undefined,
|
|
15
|
+
isOutOfCanvas: false
|
|
16
|
+
};
|
|
17
|
+
var eventsOptions = {
|
|
18
|
+
passive: true
|
|
19
|
+
};
|
|
20
|
+
var MIN_PIXELS = 1;
|
|
21
|
+
var shownAnnotationPreview = null;
|
|
22
|
+
var textAnnotationWrappedRect = null;
|
|
23
|
+
var latestAnnotationProps = null;
|
|
24
|
+
var previewThenCallAnnotationAdding = function previewThenCallAnnotationAdding(canvas, annotation, previewGroup, callbkAfterPreview) {
|
|
25
|
+
var getCanvasBoundingRect = function getCanvasBoundingRect() {
|
|
26
|
+
return getElemDocumentCoords(canvas.content);
|
|
27
|
+
};
|
|
28
|
+
var wrapTextBoundsPreviewByRect = function wrapTextBoundsPreviewByRect(textAnnotation) {
|
|
29
|
+
textAnnotationWrappedRect = getNewAnnotationPreview(_objectSpread(_objectSpread({}, textAnnotation), {}, {
|
|
30
|
+
name: TOOLS_IDS.RECT,
|
|
31
|
+
fill: '',
|
|
32
|
+
stroke: '#000000',
|
|
33
|
+
strokeWidth: 2,
|
|
34
|
+
shadowColor: '#ffffff',
|
|
35
|
+
shadowBlur: 1,
|
|
36
|
+
shadowOpacity: 0.7
|
|
37
|
+
}));
|
|
38
|
+
previewGroup.add(textAnnotationWrappedRect);
|
|
39
|
+
};
|
|
40
|
+
var previewAnnotation = function previewAnnotation(preparedAnnotation) {
|
|
41
|
+
shownAnnotationPreview = getNewAnnotationPreview(preparedAnnotation);
|
|
42
|
+
previewGroup.add(shownAnnotationPreview);
|
|
43
|
+
if (preparedAnnotation.name === TOOLS_IDS.TEXT) {
|
|
44
|
+
wrapTextBoundsPreviewByRect(preparedAnnotation);
|
|
45
|
+
}
|
|
46
|
+
latestAnnotationProps = preparedAnnotation;
|
|
47
|
+
};
|
|
48
|
+
var updateAnnotationPreview = function updateAnnotationPreview(preparedBoundingRect, isShiftKeyPressed) {
|
|
49
|
+
if (!latestAnnotationProps) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
var transformedAnnotation = dimensToProperAnnotationDimens(preparedBoundingRect, latestAnnotationProps.name, isShiftKeyPressed);
|
|
53
|
+
if (textAnnotationWrappedRect) {
|
|
54
|
+
textAnnotationWrappedRect.setAttrs(transformedAnnotation);
|
|
55
|
+
}
|
|
56
|
+
shownAnnotationPreview.setAttrs(transformedAnnotation);
|
|
57
|
+
latestAnnotationProps = _objectSpread(_objectSpread({}, latestAnnotationProps), transformedAnnotation);
|
|
58
|
+
};
|
|
59
|
+
var updatePreviewWithBoundedDimens = function updatePreviewWithBoundedDimens(e) {
|
|
60
|
+
var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
|
|
61
|
+
updateAnnotationPreview(getBoundingRectUnScaled(pointerOffsets, pointerDown, previewGroup), e.shiftKey);
|
|
62
|
+
};
|
|
63
|
+
var destroyShownPreview = function destroyShownPreview() {
|
|
64
|
+
if (previewGroup && shownAnnotationPreview) {
|
|
65
|
+
previewGroup.destroyChildren();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var handlePointerMove = function handlePointerMove(e) {
|
|
69
|
+
var _e$evt$touches;
|
|
70
|
+
if (((_e$evt$touches = e.evt.touches) === null || _e$evt$touches === void 0 ? void 0 : _e$evt$touches.length) > 1) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
|
|
74
|
+
if (pointerDown.isOutOfCanvas) {
|
|
75
|
+
document.removeEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
76
|
+
document.removeEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
77
|
+
pointerDown.isOutOfCanvas = false;
|
|
78
|
+
}
|
|
79
|
+
var boundingRect = getBoundingRectUnScaled(pointerOffsets, pointerDown, previewGroup);
|
|
80
|
+
if (shownAnnotationPreview) {
|
|
81
|
+
updateAnnotationPreview(boundingRect, e.evt.shiftKey);
|
|
82
|
+
} else {
|
|
83
|
+
var _id = annotation.id,
|
|
84
|
+
_x = annotation.x,
|
|
85
|
+
_y = annotation.y,
|
|
86
|
+
_points = annotation.points,
|
|
87
|
+
currentAnnotationProps = _objectWithoutProperties(annotation, _excluded);
|
|
88
|
+
previewAnnotation(_objectSpread(_objectSpread({}, currentAnnotationProps), boundingRect));
|
|
89
|
+
}
|
|
90
|
+
canvas.setAttrs({
|
|
91
|
+
isDrawing: true
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
var handlePointerOut = function handlePointerOut() {
|
|
95
|
+
if (!pointerDown.isOutOfCanvas) {
|
|
96
|
+
document.addEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
97
|
+
document.addEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
98
|
+
pointerDown.isOutOfCanvas = true;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var _handlePointerUp = function handlePointerUp() {
|
|
102
|
+
var _latestAnnotationProp, _latestAnnotationProp2;
|
|
103
|
+
destroyShownPreview();
|
|
104
|
+
if (latestAnnotationProps && (latestAnnotationProps.width >= MIN_PIXELS && latestAnnotationProps.height >= MIN_PIXELS || latestAnnotationProps.radiusX >= MIN_PIXELS && latestAnnotationProps.radiusY >= MIN_PIXELS || (_latestAnnotationProp = latestAnnotationProps.points) !== null && _latestAnnotationProp !== void 0 && _latestAnnotationProp[2] || (_latestAnnotationProp2 = latestAnnotationProps.points) !== null && _latestAnnotationProp2 !== void 0 && _latestAnnotationProp2[3] || latestAnnotationProps.radius >= MIN_PIXELS)) {
|
|
105
|
+
var _latestAnnotationProp3 = latestAnnotationProps,
|
|
106
|
+
_startedX = _latestAnnotationProp3.startedX,
|
|
107
|
+
_startedY = _latestAnnotationProp3.startedY,
|
|
108
|
+
_offsetX = _latestAnnotationProp3.offsetX,
|
|
109
|
+
_offsetY = _latestAnnotationProp3.offsetY,
|
|
110
|
+
width = _latestAnnotationProp3.width,
|
|
111
|
+
height = _latestAnnotationProp3.height,
|
|
112
|
+
savableAnnotation = _objectWithoutProperties(_latestAnnotationProp3, _excluded2);
|
|
113
|
+
if (!NO_WIDTH_HEIGHT_ANNOTATIONS.includes(annotation.name)) {
|
|
114
|
+
savableAnnotation.width = width;
|
|
115
|
+
savableAnnotation.height = height;
|
|
116
|
+
}
|
|
117
|
+
callbkAfterPreview(savableAnnotation, true);
|
|
118
|
+
}
|
|
119
|
+
shownAnnotationPreview = null;
|
|
120
|
+
textAnnotationWrappedRect = null;
|
|
121
|
+
latestAnnotationProps = null;
|
|
122
|
+
canvas.setAttrs({
|
|
123
|
+
isDrawing: false
|
|
124
|
+
});
|
|
125
|
+
canvas.off('mousemove touchmove', handlePointerMove);
|
|
126
|
+
canvas.off('mouseleave touchcancel', handlePointerOut);
|
|
127
|
+
document.removeEventListener('mouseup', _handlePointerUp, eventsOptions);
|
|
128
|
+
document.removeEventListener('touchend', _handlePointerUp, eventsOptions);
|
|
129
|
+
document.removeEventListener('mouseleave', _handlePointerUp, eventsOptions);
|
|
130
|
+
document.removeEventListener('touchcancel', _handlePointerUp, eventsOptions);
|
|
131
|
+
document.removeEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
132
|
+
document.removeEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
|
|
133
|
+
pointerDown.isOutOfCanvas = false;
|
|
134
|
+
};
|
|
135
|
+
var handlePointerDown = function handlePointerDown(e) {
|
|
136
|
+
var _e$evt$touches2;
|
|
137
|
+
e.evt.preventDefault();
|
|
138
|
+
if (e.target.attrs.draggable || ((_e$evt$touches2 = e.evt.touches) === null || _e$evt$touches2 === void 0 ? void 0 : _e$evt$touches2.length) > 1) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
destroyShownPreview();
|
|
142
|
+
var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
|
|
143
|
+
pointerDown.startedX = pointerOffsets.offsetX;
|
|
144
|
+
pointerDown.startedY = pointerOffsets.offsetY;
|
|
145
|
+
pointerDown.isOutOfCanvas = false;
|
|
146
|
+
canvas.on('mousemove touchmove', handlePointerMove);
|
|
147
|
+
canvas.on('mouseleave touchcancel', handlePointerOut);
|
|
148
|
+
document.addEventListener('mouseup', _handlePointerUp, eventsOptions);
|
|
149
|
+
document.addEventListener('touchend', _handlePointerUp, eventsOptions);
|
|
150
|
+
document.addEventListener('mouseleave', _handlePointerUp, eventsOptions);
|
|
151
|
+
document.addEventListener('touchcancel', _handlePointerUp, eventsOptions);
|
|
152
|
+
};
|
|
153
|
+
canvas.on('mousedown touchstart', handlePointerDown);
|
|
154
|
+
return function () {
|
|
155
|
+
destroyShownPreview();
|
|
156
|
+
canvas.off('mousedown touchstart', handlePointerDown);
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
export default previewThenCallAnnotationAdding;
|
|
@@ -1 +1,83 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useMemo, useCallback } from 'react';
|
|
2
|
+
import { SET_ANNOTATION, SELECT_ANNOTATION, SELECT_TOOL } from 'actions';
|
|
3
|
+
import { TOOLS_IDS, TABS_IDS, WATERMARK_ANNOTATION_ID } from 'utils/constants';
|
|
4
|
+
import useStore from "./use-store";
|
|
5
|
+
var useAnnotationEvents = function useAnnotationEvents() {
|
|
6
|
+
var _useStore = useStore(),
|
|
7
|
+
tabId = _useStore.tabId,
|
|
8
|
+
dispatch = _useStore.dispatch;
|
|
9
|
+
var isAnnotationEventsDisabled = useMemo(function () {
|
|
10
|
+
return tabId !== TABS_IDS.ANNOTATE && tabId !== TABS_IDS.WATERMARK;
|
|
11
|
+
}, [tabId]);
|
|
12
|
+
var updateAnnotation = useCallback(function (annotationProps) {
|
|
13
|
+
dispatch({
|
|
14
|
+
type: SET_ANNOTATION,
|
|
15
|
+
payload: annotationProps
|
|
16
|
+
});
|
|
17
|
+
}, []);
|
|
18
|
+
var updatePositionOnDragEnd = useCallback(function (e) {
|
|
19
|
+
updateAnnotation({
|
|
20
|
+
id: e.target.id(),
|
|
21
|
+
x: e.target.x(),
|
|
22
|
+
y: e.target.y()
|
|
23
|
+
});
|
|
24
|
+
}, []);
|
|
25
|
+
var getAnnotationTransformProps = useCallback(function (e) {
|
|
26
|
+
var transformProps = {
|
|
27
|
+
id: e.target.id(),
|
|
28
|
+
rotation: e.target.rotation(),
|
|
29
|
+
x: e.target.x(),
|
|
30
|
+
y: e.target.y()
|
|
31
|
+
};
|
|
32
|
+
if (e.target.name() === TOOLS_IDS.TEXT) {
|
|
33
|
+
transformProps.width = e.target.width() * e.target.scaleX();
|
|
34
|
+
transformProps.height = e.target.height() * e.target.scaleY();
|
|
35
|
+
transformProps.scaleX = 1;
|
|
36
|
+
transformProps.scaleY = 1;
|
|
37
|
+
} else {
|
|
38
|
+
transformProps.scaleX = e.target.scaleX();
|
|
39
|
+
transformProps.scaleY = e.target.scaleY();
|
|
40
|
+
}
|
|
41
|
+
return transformProps;
|
|
42
|
+
}, []);
|
|
43
|
+
var updateAnnotationTransform = useCallback(function (e) {
|
|
44
|
+
updateAnnotation(getAnnotationTransformProps(e));
|
|
45
|
+
}, []);
|
|
46
|
+
var updateTextAnnotationOnTransform = useCallback(function (e) {
|
|
47
|
+
if (e.target.name() === TOOLS_IDS.TEXT) {
|
|
48
|
+
e.target.setAttrs(getAnnotationTransformProps(e));
|
|
49
|
+
}
|
|
50
|
+
}, []);
|
|
51
|
+
var selectAnnotationOnClick = useCallback(function (e) {
|
|
52
|
+
var _e$target$getStage;
|
|
53
|
+
if (e.target.id() === WATERMARK_ANNOTATION_ID || (_e$target$getStage = e.target.getStage()) !== null && _e$target$getStage !== void 0 && _e$target$getStage.attrs.isDrawing) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
var evt = e.evt;
|
|
57
|
+
var multiple = 'ctrlKey' in evt && (evt.ctrlKey || evt.shiftKey || evt.metaKey) || false;
|
|
58
|
+
dispatch({
|
|
59
|
+
type: SELECT_ANNOTATION,
|
|
60
|
+
payload: {
|
|
61
|
+
annotationId: e.target.id(),
|
|
62
|
+
multiple: multiple
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
dispatch({
|
|
66
|
+
type: SELECT_TOOL,
|
|
67
|
+
payload: {
|
|
68
|
+
toolId: e.target.name(),
|
|
69
|
+
keepSelections: multiple
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}, []);
|
|
73
|
+
return useMemo(function () {
|
|
74
|
+
return isAnnotationEventsDisabled ? {} : {
|
|
75
|
+
onTransform: updateTextAnnotationOnTransform,
|
|
76
|
+
onTransformEnd: updateAnnotationTransform,
|
|
77
|
+
onDragEnd: updatePositionOnDragEnd,
|
|
78
|
+
onClick: selectAnnotationOnClick,
|
|
79
|
+
onTap: selectAnnotationOnClick
|
|
80
|
+
};
|
|
81
|
+
}, [isAnnotationEventsDisabled]);
|
|
82
|
+
};
|
|
83
|
+
export default useAnnotationEvents;
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
var _excluded = ["isDesignState"];
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { useReducer } from 'react';
|
|
8
|
+
import { REDO, RESET, UNDO } from 'actions';
|
|
9
|
+
import extractCurrentDesignState from 'utils/extract-current-design-state';
|
|
10
|
+
var timeout;
|
|
11
|
+
var applyModifyFn = function applyModifyFn(onModify, newState) {
|
|
12
|
+
timeout = setTimeout(function () {
|
|
13
|
+
clearTimeout(timeout);
|
|
14
|
+
if (typeof onModify === 'function' && newState) {
|
|
15
|
+
onModify(newState);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var useAppReducer = function useAppReducer(reducer, initialState) {
|
|
20
|
+
var passedConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
21
|
+
var initialStateWithUndoRedo = _objectSpread(_objectSpread({}, initialState), {}, {
|
|
22
|
+
pastDesignStates: [],
|
|
23
|
+
futureDesignStates: [],
|
|
24
|
+
hasRedo: false,
|
|
25
|
+
hasUndo: false
|
|
26
|
+
});
|
|
27
|
+
var undoRedoResetReducer = function undoRedoResetReducer(state, action) {
|
|
28
|
+
var newPresentState = reducer(state, action) || initialStateWithUndoRedo;
|
|
29
|
+
if ([UNDO, REDO, RESET].includes(action.type)) {
|
|
30
|
+
applyModifyFn(passedConfig.onModify, newPresentState);
|
|
31
|
+
return newPresentState;
|
|
32
|
+
}
|
|
33
|
+
if (newPresentState.isDesignState) {
|
|
34
|
+
var currentState = extractCurrentDesignState(state, false);
|
|
35
|
+
var _isDesignState = newPresentState.isDesignState,
|
|
36
|
+
neededNewPresentState = _objectWithoutProperties(newPresentState, _excluded);
|
|
37
|
+
var newState = _objectSpread(_objectSpread({}, neededNewPresentState), {}, {
|
|
38
|
+
isDesignState: false,
|
|
39
|
+
pastDesignStates: [currentState].concat(_toConsumableArray(state.pastDesignStates)),
|
|
40
|
+
hasUndo: true,
|
|
41
|
+
hasRedo: false,
|
|
42
|
+
futureDesignStates: [],
|
|
43
|
+
isResetted: false,
|
|
44
|
+
haveNotSavedChanges: true
|
|
45
|
+
});
|
|
46
|
+
applyModifyFn(passedConfig.onModify, newState);
|
|
47
|
+
return newState;
|
|
48
|
+
}
|
|
49
|
+
return newPresentState;
|
|
50
|
+
};
|
|
51
|
+
return useReducer(undoRedoResetReducer, initialStateWithUndoRedo);
|
|
52
|
+
};
|
|
53
|
+
export default useAppReducer;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import debounce from 'utils/debounce';
|
|
3
|
+
var useDebouncedCallback = function useDebouncedCallback(func, timeout) {
|
|
4
|
+
var dependencies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
5
|
+
return useCallback(debounce(func, timeout), dependencies);
|
|
6
|
+
};
|
|
7
|
+
export default useDebouncedCallback;
|
package/lib/hooks/use-drag.js
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
var useDrag=
|
|
1
|
+
var useDrag = function useDrag(onMove, onStart, onEnd) {
|
|
2
|
+
var onDragging = function onDragging(e) {
|
|
3
|
+
if (typeof onMove === 'function') {
|
|
4
|
+
var _touches;
|
|
5
|
+
onMove(((_touches = e.touches) === null || _touches === void 0 ? void 0 : _touches[0]) || e);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var _disableSliding = function disableSliding(e) {
|
|
9
|
+
document.removeEventListener('mousemove', onDragging);
|
|
10
|
+
document.removeEventListener('mouseup', _disableSliding);
|
|
11
|
+
document.removeEventListener('mouseleave', _disableSliding);
|
|
12
|
+
document.removeEventListener('touchmove', onDragging);
|
|
13
|
+
document.removeEventListener('touchend', _disableSliding);
|
|
14
|
+
document.removeEventListener('touchcancel', _disableSliding);
|
|
15
|
+
if (typeof onEnd === 'function') {
|
|
16
|
+
var _touches2;
|
|
17
|
+
onEnd(((_touches2 = e.touches) === null || _touches2 === void 0 ? void 0 : _touches2[0]) || e);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var enableDrag = function enableDrag(e) {
|
|
21
|
+
document.addEventListener('mousemove', onDragging);
|
|
22
|
+
document.addEventListener('mouseup', _disableSliding);
|
|
23
|
+
document.addEventListener('mouseleave', _disableSliding);
|
|
24
|
+
document.addEventListener('touchmove', onDragging);
|
|
25
|
+
document.addEventListener('touchend', _disableSliding);
|
|
26
|
+
document.addEventListener('touchcancel', _disableSliding);
|
|
27
|
+
if (typeof onStart === 'function') {
|
|
28
|
+
var _touches3;
|
|
29
|
+
onStart(((_touches3 = e.touches) === null || _touches3 === void 0 ? void 0 : _touches3[0]) || e);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
onMouseDown: enableDrag,
|
|
34
|
+
onTouchStart: enableDrag
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export default useDrag;
|
package/lib/hooks/use-filter.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { ADD_FILTER } from 'actions';
|
|
3
|
+
import useStore from "./use-store";
|
|
4
|
+
var useFilter = function useFilter() {
|
|
5
|
+
var _useStore = useStore(),
|
|
6
|
+
dispatch = _useStore.dispatch,
|
|
7
|
+
filter = _useStore.filter;
|
|
8
|
+
var setFilter = useCallback(function (filterToApply) {
|
|
9
|
+
dispatch({
|
|
10
|
+
type: ADD_FILTER,
|
|
11
|
+
payload: {
|
|
12
|
+
filter: filterToApply
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}, []);
|
|
16
|
+
return useMemo(function () {
|
|
17
|
+
return [filter, setFilter];
|
|
18
|
+
}, [filter]);
|
|
19
|
+
};
|
|
20
|
+
export default useFilter;
|