@searpent/react-image-annotate 2.0.5 → 2.0.6

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 (195) hide show
  1. package/Annotator/examplePhotos.js +6976 -0
  2. package/Annotator/index.js +262 -0
  3. package/Annotator/reducers/combine-reducers.js +14 -0
  4. package/Annotator/reducers/convert-expanding-line-to-polygon.js +73 -0
  5. package/{src/Annotator → Annotator}/reducers/fix-twisted.js +3 -5
  6. package/Annotator/reducers/general-reducer.js +1152 -0
  7. package/Annotator/reducers/get-active-image.js +27 -0
  8. package/Annotator/reducers/get-implied-video-regions.js +180 -0
  9. package/Annotator/reducers/history-handler.js +38 -0
  10. package/Annotator/reducers/image-reducer.js +20 -0
  11. package/Annotator/reducers/video-reducer.js +88 -0
  12. package/ClassSelectionMenu/index.js +135 -0
  13. package/Crosshairs/index.js +53 -0
  14. package/DebugSidebarBox/index.js +20 -0
  15. package/DemoSite/Editor.js +194 -0
  16. package/DemoSite/ErrorBoundaryDialog.js +64 -0
  17. package/DemoSite/index.js +40 -0
  18. package/Editor/annotation-plugin/annotation.js +613 -0
  19. package/Editor/index.js +57 -0
  20. package/{src/Editor → Editor}/tools.js +2 -3
  21. package/FullImageSegmentationAnnotator/index.js +7 -0
  22. package/GroupSelectorSidebarBox/index.js +63 -0
  23. package/HighlightBox/index.js +99 -0
  24. package/HistorySidebarBox/index.js +71 -0
  25. package/ImageCanvas/index.js +429 -0
  26. package/ImageCanvas/region-tools.js +165 -0
  27. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  28. package/ImageCanvas/use-mouse.js +180 -0
  29. package/ImageCanvas/use-project-box.js +27 -0
  30. package/ImageCanvas/use-wasd-mode.js +62 -0
  31. package/ImageMask/index.js +133 -0
  32. package/ImageMask/load-image.js +25 -0
  33. package/ImageSelectorSidebarBox/index.js +60 -0
  34. package/KeyframeTimeline/get-time-string.js +27 -0
  35. package/KeyframeTimeline/index.js +233 -0
  36. package/KeyframesSelectorSidebarBox/index.js +93 -0
  37. package/LandingPage/index.js +159 -0
  38. package/MainLayout/icon-dictionary.js +104 -0
  39. package/MainLayout/index.js +469 -0
  40. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  41. package/MainLayout/types.js +0 -0
  42. package/MainLayout/use-implied-video-regions.js +13 -0
  43. package/MetadataEditorSidebarBox/index.js +126 -0
  44. package/PageSelector/index.js +67 -0
  45. package/PointDistances/index.js +73 -0
  46. package/PreventScrollToParents/index.js +51 -0
  47. package/RegionLabel/index.js +205 -0
  48. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  49. package/RegionSelectAndTransformBoxes/index.js +167 -0
  50. package/RegionSelectorSidebarBox/index.js +248 -0
  51. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  52. package/RegionShapes/index.js +294 -0
  53. package/RegionTags/index.js +142 -0
  54. package/SettingsDialog/index.js +52 -0
  55. package/SettingsProvider/index.js +58 -0
  56. package/Shortcuts/ShortcutField.js +46 -0
  57. package/Shortcuts/index.js +133 -0
  58. package/ShortcutsManager/index.js +155 -0
  59. package/Sidebar/index.js +69 -0
  60. package/SidebarBoxContainer/index.js +93 -0
  61. package/SmallToolButton/index.js +42 -0
  62. package/TagsSidebarBox/index.js +105 -0
  63. package/TaskDescriptionSidebarBox/index.js +58 -0
  64. package/Theme/index.js +30 -0
  65. package/VideoOrImageCanvasBackground/index.js +151 -0
  66. package/colors.js +14 -0
  67. package/hooks/use-colors.js +101 -0
  68. package/hooks/use-event-callback.js +10 -0
  69. package/hooks/use-exclude-pattern.js +24 -0
  70. package/hooks/use-load-image.js +26 -0
  71. package/hooks/use-window-size.js +46 -0
  72. package/{src/hooks → hooks}/xpattern.js +1 -1
  73. package/index.js +3 -0
  74. package/lib.js +3 -0
  75. package/package.json +1 -1
  76. package/stories.js +5 -0
  77. package/{src/utils → utils}/filter-only-unique.js +1 -1
  78. package/utils/get-from-local-storage.js +7 -0
  79. package/utils/get-hotkey-help-text.js +9 -0
  80. package/utils/get-landmarks-with-transform.js +40 -0
  81. package/utils/photosToImages.js +53 -0
  82. package/utils/regions-to-blocks.js +16 -0
  83. package/utils/set-in-local-storage.js +3 -0
  84. package/.babelrc +0 -6
  85. package/.env +0 -1
  86. package/.flowconfig +0 -2
  87. package/.github/workflows/release-on-master.yml +0 -32
  88. package/.github/workflows/test.yml +0 -16
  89. package/.prettierrc +0 -3
  90. package/.releaserc.js +0 -18
  91. package/.storybook/addons.js +0 -2
  92. package/.storybook/config.js +0 -16
  93. package/LICENSE +0 -21
  94. package/public/favicon.ico +0 -0
  95. package/public/index.html +0 -38
  96. package/src/Annotator/bike-pic.png +0 -0
  97. package/src/Annotator/bike-pic2.png +0 -0
  98. package/src/Annotator/dab-keyframes.story.json +0 -1
  99. package/src/Annotator/examplePhotos.js +0 -7601
  100. package/src/Annotator/index.js +0 -291
  101. package/src/Annotator/index.story.js +0 -807
  102. package/src/Annotator/poses.story.js +0 -150
  103. package/src/Annotator/reducers/combine-reducers.js +0 -7
  104. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  105. package/src/Annotator/reducers/general-reducer.js +0 -996
  106. package/src/Annotator/reducers/get-active-image.js +0 -21
  107. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  108. package/src/Annotator/reducers/history-handler.js +0 -60
  109. package/src/Annotator/reducers/image-reducer.js +0 -23
  110. package/src/Annotator/reducers/video-reducer.js +0 -85
  111. package/src/Annotator/video.story.js +0 -51
  112. package/src/ClassSelectionMenu/index.js +0 -108
  113. package/src/Crosshairs/index.js +0 -64
  114. package/src/DebugSidebarBox/index.js +0 -36
  115. package/src/DemoSite/Editor.js +0 -235
  116. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  117. package/src/DemoSite/index.js +0 -41
  118. package/src/DemoSite/index.story.js +0 -10
  119. package/src/DemoSite/simple-segmentation-example.json +0 -572
  120. package/src/Editor/annotation-plugin/annotation.css +0 -46
  121. package/src/Editor/annotation-plugin/annotation.js +0 -515
  122. package/src/Editor/index.js +0 -24
  123. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  124. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  125. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  126. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  127. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  128. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  129. package/src/GroupSelectorSidebarBox/index.js +0 -48
  130. package/src/HighlightBox/index.js +0 -143
  131. package/src/HistorySidebarBox/index.js +0 -78
  132. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  133. package/src/ImageCanvas/index.js +0 -494
  134. package/src/ImageCanvas/index.story.js +0 -314
  135. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  136. package/src/ImageCanvas/region-tools.js +0 -171
  137. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  138. package/src/ImageCanvas/use-mouse.js +0 -168
  139. package/src/ImageCanvas/use-project-box.js +0 -23
  140. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  141. package/src/ImageMask/index.js +0 -127
  142. package/src/ImageMask/load-image.js +0 -32
  143. package/src/ImageSelectorSidebarBox/index.js +0 -54
  144. package/src/KeyframeTimeline/get-time-string.js +0 -25
  145. package/src/KeyframeTimeline/index.js +0 -223
  146. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  147. package/src/LandingPage/content.md +0 -57
  148. package/src/LandingPage/github-markdown.css +0 -964
  149. package/src/LandingPage/index.js +0 -147
  150. package/src/MainLayout/icon-dictionary.js +0 -79
  151. package/src/MainLayout/index.js +0 -510
  152. package/src/MainLayout/index.story.js +0 -240
  153. package/src/MainLayout/types.js +0 -164
  154. package/src/MainLayout/use-implied-video-regions.js +0 -17
  155. package/src/MetadataEditorSidebarBox/index.js +0 -98
  156. package/src/PageSelector/index.js +0 -76
  157. package/src/PageSelector/page-selector.css +0 -69
  158. package/src/PointDistances/index.js +0 -90
  159. package/src/PreventScrollToParents/index.js +0 -48
  160. package/src/PreventScrollToParents/index.story.js +0 -23
  161. package/src/RegionLabel/index.js +0 -222
  162. package/src/RegionSelectAndTransformBoxes/index.js +0 -234
  163. package/src/RegionSelectorSidebarBox/index.js +0 -216
  164. package/src/RegionShapes/index.js +0 -254
  165. package/src/RegionTags/index.js +0 -134
  166. package/src/SettingsDialog/index.js +0 -58
  167. package/src/SettingsProvider/index.js +0 -48
  168. package/src/Shortcuts/ShortcutField.js +0 -44
  169. package/src/Shortcuts/index.js +0 -129
  170. package/src/ShortcutsManager/index.js +0 -162
  171. package/src/Sidebar/index.js +0 -117
  172. package/src/SidebarBoxContainer/index.js +0 -93
  173. package/src/SmallToolButton/index.js +0 -57
  174. package/src/TagsSidebarBox/index.js +0 -93
  175. package/src/TaskDescriptionSidebarBox/index.js +0 -43
  176. package/src/Theme/index.js +0 -36
  177. package/src/VideoOrImageCanvasBackground/index.js +0 -170
  178. package/src/colors.js +0 -32
  179. package/src/hooks/use-colors.js +0 -74
  180. package/src/hooks/use-event-callback.js +0 -11
  181. package/src/hooks/use-exclude-pattern.js +0 -27
  182. package/src/hooks/use-load-image.js +0 -21
  183. package/src/hooks/use-window-size.js +0 -46
  184. package/src/hooks/xpattern.png +0 -0
  185. package/src/index.js +0 -18
  186. package/src/lib.js +0 -7
  187. package/src/screenshot.png +0 -0
  188. package/src/site.css +0 -5
  189. package/src/stories.js +0 -2
  190. package/src/utils/get-from-local-storage.js +0 -7
  191. package/src/utils/get-hotkey-help-text.js +0 -11
  192. package/src/utils/get-landmarks-with-transform.js +0 -23
  193. package/src/utils/photosToImages.js +0 -40
  194. package/src/utils/regions-to-blocks.js +0 -14
  195. package/src/utils/set-in-local-storage.js +0 -6
@@ -0,0 +1,63 @@
1
+ import React, { memo } from "react";
2
+ import { makeStyles } from "@mui/styles";
3
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
4
+ import SidebarBoxContainer from "../SidebarBoxContainer";
5
+ import CollectionsIcon from "@mui/icons-material/Collections";
6
+ import { grey } from "@mui/material/colors";
7
+ import List from "@mui/material/List";
8
+ import ListItem from "@mui/material/ListItem";
9
+ import ListItemText from "@mui/material/ListItemText";
10
+ import isEqual from "lodash/isEqual";
11
+ var theme = createTheme();
12
+ var useStyles = makeStyles(function (theme) {
13
+ return {
14
+ img: {
15
+ width: 40,
16
+ height: 40,
17
+ borderRadius: 8
18
+ }
19
+ };
20
+ });
21
+ export var GroupSelectorSidebarBox = function GroupSelectorSidebarBox(_ref) {
22
+ var title = _ref.title,
23
+ subtitle = _ref.subtitle,
24
+ groups = _ref.groups,
25
+ onSelect = _ref.onSelect,
26
+ selectedGroupId = _ref.selectedGroupId;
27
+ var classes = useStyles();
28
+ return React.createElement(ThemeProvider, {
29
+ theme: theme
30
+ }, React.createElement(SidebarBoxContainer, {
31
+ title: title || '',
32
+ subTitle: subtitle || '',
33
+ icon: React.createElement(CollectionsIcon, {
34
+ style: {
35
+ color: grey[700]
36
+ }
37
+ })
38
+ }, React.createElement(List, null, groups.map(function (_ref2, i) {
39
+ var id = _ref2.id,
40
+ groupTitle = _ref2.title,
41
+ groupSubtitle = _ref2.subtitle,
42
+ color = _ref2.color;
43
+ return React.createElement(ListItem, {
44
+ button: true,
45
+ onClick: function onClick() {
46
+ return onSelect(id);
47
+ },
48
+ dense: true,
49
+ key: id,
50
+ style: {
51
+ backgroundColor: id === selectedGroupId ? '#bbdefb' : null
52
+ }
53
+ }, React.createElement(ListItemText, {
54
+ primary: React.createElement("strong", {
55
+ style: {
56
+ color: color
57
+ }
58
+ }, groupTitle),
59
+ secondary: groupSubtitle
60
+ }));
61
+ }))));
62
+ };
63
+ export default GroupSelectorSidebarBox;
@@ -0,0 +1,99 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import React from "react";
3
+ import classnames from "classnames";
4
+ import { makeStyles } from "@mui/styles";
5
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
6
+ var theme = createTheme();
7
+ var useStyles = makeStyles(function (theme) {
8
+ return {
9
+ "@keyframes borderDance": {
10
+ from: {
11
+ strokeDashoffset: 0
12
+ },
13
+ to: {
14
+ strokeDashoffset: 100
15
+ }
16
+ },
17
+ highlightBox: {
18
+ zIndex: 2,
19
+ transition: "opacity 500ms",
20
+ "&.highlighted": {
21
+ zIndex: 3
22
+ },
23
+ "&:not(.highlighted)": {
24
+ opacity: 0
25
+ },
26
+ "&:not(.highlighted):hover": {
27
+ opacity: 0.6
28
+ },
29
+ "& path": {
30
+ vectorEffect: "non-scaling-stroke",
31
+ strokeWidth: 2,
32
+ stroke: "#FFF",
33
+ fill: "none",
34
+ strokeDasharray: 5,
35
+ animationName: "$borderDance",
36
+ animationDuration: "4s",
37
+ animationTimingFunction: "linear",
38
+ animationIterationCount: "infinite",
39
+ animationPlayState: "running"
40
+ }
41
+ }
42
+ };
43
+ });
44
+ export var HighlightBox = function HighlightBox(_ref) {
45
+ var mouseEvents = _ref.mouseEvents,
46
+ dragWithPrimary = _ref.dragWithPrimary,
47
+ zoomWithPrimary = _ref.zoomWithPrimary,
48
+ createWithPrimary = _ref.createWithPrimary,
49
+ onBeginMovePoint = _ref.onBeginMovePoint,
50
+ onSelectRegion = _ref.onSelectRegion,
51
+ r = _ref.region,
52
+ pbox = _ref.pbox;
53
+ var classes = useStyles();
54
+ if (!pbox.w || pbox.w === Infinity) return null;
55
+ if (!pbox.h || pbox.h === Infinity) return null;
56
+ if (r.unfinished) return null;
57
+ var styleCoords = r.type === "point" ? {
58
+ left: pbox.x + pbox.w / 2 - 30,
59
+ top: pbox.y + pbox.h / 2 - 30,
60
+ width: 60,
61
+ height: 60
62
+ } : {
63
+ left: pbox.x - 5,
64
+ top: pbox.y - 5,
65
+ width: pbox.w + 10,
66
+ height: pbox.h + 10
67
+ };
68
+ var pathD = r.type === "point" ? "M5,5 L".concat(styleCoords.width - 5, " 5L").concat(styleCoords.width - 5, " ").concat(styleCoords.height - 5, "L5 ").concat(styleCoords.height - 5, "Z") : "M5,5 L".concat(pbox.w + 5, ",5 L").concat(pbox.w + 5, ",").concat(pbox.h + 5, " L5,").concat(pbox.h + 5, " Z");
69
+ return React.createElement(ThemeProvider, {
70
+ theme: theme
71
+ }, React.createElement("svg", Object.assign({
72
+ key: r.id,
73
+ className: classnames(classes.highlightBox, {
74
+ highlighted: r.highlighted
75
+ })
76
+ }, mouseEvents, !zoomWithPrimary && !dragWithPrimary ? {
77
+ onMouseDown: function onMouseDown(e) {
78
+ if (!r.locked && r.type === "point" && r.highlighted && e.button === 0) {
79
+ return onBeginMovePoint(r);
80
+ }
81
+
82
+ if (e.button === 0 && !createWithPrimary) return onSelectRegion(r);
83
+ mouseEvents.onMouseDown(e);
84
+ }
85
+ } : {}, {
86
+ style: _objectSpread({}, r.highlighted ? {
87
+ pointerEvents: r.type !== "point" ? "none" : undefined,
88
+ cursor: "grab"
89
+ } : {
90
+ cursor: !(zoomWithPrimary || dragWithPrimary || createWithPrimary) ? "pointer" : undefined,
91
+ pointerEvents: zoomWithPrimary || dragWithPrimary || createWithPrimary && !r.highlighted ? "none" : undefined
92
+ }, {
93
+ position: "absolute"
94
+ }, styleCoords)
95
+ }), React.createElement("path", {
96
+ d: pathD
97
+ })));
98
+ };
99
+ export default HighlightBox;
@@ -0,0 +1,71 @@
1
+ import React, { setState, memo } from "react";
2
+ import { makeStyles } from "@mui/styles";
3
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
4
+ import SidebarBoxContainer from "../SidebarBoxContainer";
5
+ import HistoryIcon from "@mui/icons-material/History";
6
+ import List from "@mui/material/List";
7
+ import ListItem from "@mui/material/ListItem";
8
+ import ListItemText from "@mui/material/ListItemText";
9
+ import IconButton from "@mui/material/IconButton";
10
+ import ListItemSecondaryAction from "@mui/material/ListItemSecondaryAction";
11
+ import UndoIcon from "@mui/icons-material/Undo";
12
+ import moment from "moment";
13
+ import { grey } from "@mui/material/colors";
14
+ import isEqual from "lodash/isEqual";
15
+ import Box from "@mui/material/Box";
16
+ var theme = createTheme();
17
+ var useStyles = makeStyles(function (theme) {
18
+ return {
19
+ emptyText: {
20
+ fontSize: 14,
21
+ fontWeight: "bold",
22
+ color: grey[500],
23
+ textAlign: "center",
24
+ padding: 20
25
+ }
26
+ };
27
+ });
28
+ var listItemTextStyle = {
29
+ paddingLeft: 16
30
+ };
31
+ export var HistorySidebarBox = function HistorySidebarBox(_ref) {
32
+ var history = _ref.history,
33
+ onRestoreHistory = _ref.onRestoreHistory;
34
+ var classes = useStyles();
35
+ return React.createElement(ThemeProvider, {
36
+ theme: theme
37
+ }, React.createElement(SidebarBoxContainer, {
38
+ title: "History",
39
+ icon: React.createElement(HistoryIcon, {
40
+ style: {
41
+ color: grey[700]
42
+ }
43
+ }),
44
+ expandedByDefault: true
45
+ }, React.createElement(List, null, history.length === 0 && React.createElement("div", {
46
+ className: classes.emptyText
47
+ }, "No History Yet"), history.map(function (_ref2, i) {
48
+ var name = _ref2.name,
49
+ time = _ref2.time;
50
+ return React.createElement(ListItem, {
51
+ button: true,
52
+ dense: true,
53
+ key: i
54
+ }, React.createElement(ListItemText, {
55
+ style: listItemTextStyle,
56
+ primary: name,
57
+ secondary: moment(time).format("LT")
58
+ }), i === 0 && React.createElement(ListItemSecondaryAction, {
59
+ onClick: function onClick() {
60
+ return onRestoreHistory();
61
+ }
62
+ }, React.createElement(IconButton, null, React.createElement(UndoIcon, null))));
63
+ }))));
64
+ };
65
+ export default memo(HistorySidebarBox, function (prevProps, nextProps) {
66
+ return isEqual(prevProps.history.map(function (a) {
67
+ return [a.name, a.time];
68
+ }), nextProps.history.map(function (a) {
69
+ return [a.name, a.time];
70
+ }));
71
+ });
@@ -0,0 +1,429 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import React, { useRef, useState, useLayoutEffect, useEffect, useMemo } from "react";
5
+ import { Matrix } from "transformation-matrix-js";
6
+ import Crosshairs from "../Crosshairs";
7
+ import { makeStyles } from "@mui/styles";
8
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
9
+ import styles from "./styles";
10
+ import PreventScrollToParents from "../PreventScrollToParents";
11
+ import useWindowSize from "../hooks/use-window-size.js";
12
+ import useMouse from "./use-mouse";
13
+ import useProjectRegionBox from "./use-project-box";
14
+ import useExcludePattern from "../hooks/use-exclude-pattern";
15
+ import { useRafState } from "react-use";
16
+ import PointDistances from "../PointDistances";
17
+ import RegionTags from "../RegionTags";
18
+ import RegionLabel from "../RegionLabel";
19
+ import ImageMask from "../ImageMask";
20
+ import RegionSelectAndTransformBoxes from "../RegionSelectAndTransformBoxes";
21
+ import VideoOrImageCanvasBackground from "../VideoOrImageCanvasBackground";
22
+ import useEventCallback from "use-event-callback";
23
+ import RegionShapes from "../RegionShapes";
24
+ import useWasdMode from "./use-wasd-mode";
25
+ var theme = createTheme();
26
+ var useStyles = makeStyles(function (theme) {
27
+ return styles;
28
+ });
29
+
30
+ var getDefaultMat = function getDefaultMat() {
31
+ var allowedArea = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
32
+
33
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
34
+ iw = _ref.iw,
35
+ ih = _ref.ih;
36
+
37
+ var mat = Matrix.from(1, 0, 0, 1, -10, -10);
38
+
39
+ if (allowedArea && iw) {
40
+ mat = mat.translate(allowedArea.x * iw, allowedArea.y * ih).scaleU(allowedArea.w + 0.05);
41
+ }
42
+
43
+ return mat;
44
+ };
45
+
46
+ export var ImageCanvas = function ImageCanvas(_ref2) {
47
+ var regions = _ref2.regions,
48
+ imageSrc = _ref2.imageSrc,
49
+ videoSrc = _ref2.videoSrc,
50
+ videoTime = _ref2.videoTime,
51
+ realSize = _ref2.realSize,
52
+ showTags = _ref2.showTags,
53
+ _ref2$onMouseMove = _ref2.onMouseMove,
54
+ onMouseMove = _ref2$onMouseMove === void 0 ? function (p) {
55
+ return null;
56
+ } : _ref2$onMouseMove,
57
+ _ref2$onMouseDown = _ref2.onMouseDown,
58
+ onMouseDown = _ref2$onMouseDown === void 0 ? function (p) {
59
+ return null;
60
+ } : _ref2$onMouseDown,
61
+ _ref2$onMouseUp = _ref2.onMouseUp,
62
+ onMouseUp = _ref2$onMouseUp === void 0 ? function (p) {
63
+ return null;
64
+ } : _ref2$onMouseUp,
65
+ _ref2$dragWithPrimary = _ref2.dragWithPrimary,
66
+ dragWithPrimary = _ref2$dragWithPrimary === void 0 ? false : _ref2$dragWithPrimary,
67
+ _ref2$zoomWithPrimary = _ref2.zoomWithPrimary,
68
+ zoomWithPrimary = _ref2$zoomWithPrimary === void 0 ? false : _ref2$zoomWithPrimary,
69
+ _ref2$createWithPrima = _ref2.createWithPrimary,
70
+ createWithPrimary = _ref2$createWithPrima === void 0 ? false : _ref2$createWithPrima,
71
+ _ref2$pointDistancePr = _ref2.pointDistancePrecision,
72
+ pointDistancePrecision = _ref2$pointDistancePr === void 0 ? 0 : _ref2$pointDistancePr,
73
+ regionClsList = _ref2.regionClsList,
74
+ regionTagList = _ref2.regionTagList,
75
+ showCrosshairs = _ref2.showCrosshairs,
76
+ _ref2$showHighlightBo = _ref2.showHighlightBox,
77
+ showHighlightBox = _ref2$showHighlightBo === void 0 ? true : _ref2$showHighlightBo,
78
+ showPointDistances = _ref2.showPointDistances,
79
+ allowedArea = _ref2.allowedArea,
80
+ _ref2$RegionEditLabel = _ref2.RegionEditLabel,
81
+ RegionEditLabel = _ref2$RegionEditLabel === void 0 ? null : _ref2$RegionEditLabel,
82
+ _ref2$videoPlaying = _ref2.videoPlaying,
83
+ videoPlaying = _ref2$videoPlaying === void 0 ? false : _ref2$videoPlaying,
84
+ _ref2$showMask = _ref2.showMask,
85
+ showMask = _ref2$showMask === void 0 ? true : _ref2$showMask,
86
+ fullImageSegmentationMode = _ref2.fullImageSegmentationMode,
87
+ autoSegmentationOptions = _ref2.autoSegmentationOptions,
88
+ onImageOrVideoLoaded = _ref2.onImageOrVideoLoaded,
89
+ onChangeRegion = _ref2.onChangeRegion,
90
+ onBeginRegionEdit = _ref2.onBeginRegionEdit,
91
+ onCloseRegionEdit = _ref2.onCloseRegionEdit,
92
+ onBeginBoxTransform = _ref2.onBeginBoxTransform,
93
+ onBeginMovePolygonPoint = _ref2.onBeginMovePolygonPoint,
94
+ onAddPolygonPoint = _ref2.onAddPolygonPoint,
95
+ onBeginMoveKeypoint = _ref2.onBeginMoveKeypoint,
96
+ onSelectRegion = _ref2.onSelectRegion,
97
+ onBeginMovePoint = _ref2.onBeginMovePoint,
98
+ onDeleteRegion = _ref2.onDeleteRegion,
99
+ onChangeVideoTime = _ref2.onChangeVideoTime,
100
+ onChangeVideoPlaying = _ref2.onChangeVideoPlaying,
101
+ onRegionClassAdded = _ref2.onRegionClassAdded,
102
+ _ref2$zoomOnAllowedAr = _ref2.zoomOnAllowedArea,
103
+ zoomOnAllowedArea = _ref2$zoomOnAllowedAr === void 0 ? true : _ref2$zoomOnAllowedAr,
104
+ _ref2$modifyingAllowe = _ref2.modifyingAllowedArea,
105
+ modifyingAllowedArea = _ref2$modifyingAllowe === void 0 ? false : _ref2$modifyingAllowe,
106
+ keypointDefinitions = _ref2.keypointDefinitions,
107
+ allowComments = _ref2.allowComments,
108
+ _ref2$hideNotEditingL = _ref2.hideNotEditingLabel,
109
+ hideNotEditingLabel = _ref2$hideNotEditingL === void 0 ? false : _ref2$hideNotEditingL,
110
+ allowedGroups = _ref2.allowedGroups;
111
+ var classes = useStyles();
112
+ var canvasEl = useRef(null);
113
+ var layoutParams = useRef({});
114
+
115
+ var _useRafState = useRafState(false),
116
+ _useRafState2 = _slicedToArray(_useRafState, 2),
117
+ dragging = _useRafState2[0],
118
+ changeDragging = _useRafState2[1];
119
+
120
+ var _useRafState3 = useRafState(0),
121
+ _useRafState4 = _slicedToArray(_useRafState3, 2),
122
+ maskImagesLoaded = _useRafState4[0],
123
+ changeMaskImagesLoaded = _useRafState4[1];
124
+
125
+ var _useRafState5 = useRafState(null),
126
+ _useRafState6 = _slicedToArray(_useRafState5, 2),
127
+ zoomStart = _useRafState6[0],
128
+ changeZoomStart = _useRafState6[1];
129
+
130
+ var _useRafState7 = useRafState(null),
131
+ _useRafState8 = _slicedToArray(_useRafState7, 2),
132
+ zoomEnd = _useRafState8[0],
133
+ changeZoomEnd = _useRafState8[1];
134
+
135
+ var _useRafState9 = useRafState(getDefaultMat()),
136
+ _useRafState10 = _slicedToArray(_useRafState9, 2),
137
+ mat = _useRafState10[0],
138
+ changeMat = _useRafState10[1];
139
+
140
+ var maskImages = useRef({});
141
+ var windowSize = useWindowSize();
142
+ var getLatestMat = useEventCallback(function () {
143
+ return mat;
144
+ });
145
+ useWasdMode({
146
+ getLatestMat: getLatestMat,
147
+ changeMat: changeMat
148
+ });
149
+
150
+ var _useMouse = useMouse({
151
+ canvasEl: canvasEl,
152
+ dragging: dragging,
153
+ mat: mat,
154
+ layoutParams: layoutParams,
155
+ changeMat: changeMat,
156
+ zoomStart: zoomStart,
157
+ zoomEnd: zoomEnd,
158
+ changeZoomStart: changeZoomStart,
159
+ changeZoomEnd: changeZoomEnd,
160
+ changeDragging: changeDragging,
161
+ zoomWithPrimary: zoomWithPrimary,
162
+ dragWithPrimary: dragWithPrimary,
163
+ onMouseMove: onMouseMove,
164
+ onMouseDown: onMouseDown,
165
+ onMouseUp: onMouseUp
166
+ }),
167
+ mouseEvents = _useMouse.mouseEvents,
168
+ mousePosition = _useMouse.mousePosition;
169
+
170
+ useLayoutEffect(function () {
171
+ return changeMat(mat.clone());
172
+ }, [windowSize]);
173
+ var innerMousePos = mat.applyToPoint(mousePosition.current.x, mousePosition.current.y);
174
+ var projectRegionBox = useProjectRegionBox({
175
+ layoutParams: layoutParams,
176
+ mat: mat
177
+ });
178
+
179
+ var _useState = useState(),
180
+ _useState2 = _slicedToArray(_useState, 2),
181
+ imageDimensions = _useState2[0],
182
+ changeImageDimensions = _useState2[1];
183
+
184
+ var imageLoaded = Boolean(imageDimensions && imageDimensions.naturalWidth);
185
+ var onVideoOrImageLoaded = useEventCallback(function (_ref3) {
186
+ var naturalWidth = _ref3.naturalWidth,
187
+ naturalHeight = _ref3.naturalHeight,
188
+ duration = _ref3.duration;
189
+ var dims = {
190
+ naturalWidth: naturalWidth,
191
+ naturalHeight: naturalHeight,
192
+ duration: duration
193
+ };
194
+ if (onImageOrVideoLoaded) onImageOrVideoLoaded(dims);
195
+ changeImageDimensions(dims); // Redundant update to fix rerendering issues
196
+
197
+ setTimeout(function () {
198
+ return changeImageDimensions(dims);
199
+ }, 10);
200
+ });
201
+ var excludePattern = useExcludePattern();
202
+ var canvas = canvasEl.current;
203
+
204
+ if (canvas && imageLoaded) {
205
+ var clientWidth = canvas.clientWidth,
206
+ clientHeight = canvas.clientHeight;
207
+ var fitScale = Math.max(imageDimensions.naturalWidth / (clientWidth - 20), imageDimensions.naturalHeight / (clientHeight - 20));
208
+
209
+ var _iw = imageDimensions.naturalWidth / fitScale,
210
+ _ih = imageDimensions.naturalHeight / fitScale;
211
+
212
+ layoutParams.current = {
213
+ iw: _iw,
214
+ ih: _ih,
215
+ fitScale: fitScale,
216
+ canvasWidth: clientWidth,
217
+ canvasHeight: clientHeight
218
+ };
219
+ }
220
+
221
+ useEffect(function () {
222
+ if (!imageLoaded) return;
223
+ changeMat(getDefaultMat(zoomOnAllowedArea ? allowedArea : null, layoutParams.current)); // eslint-disable-next-line
224
+ }, [imageLoaded]);
225
+ useLayoutEffect(function () {
226
+ if (!imageDimensions) return;
227
+ var clientWidth = canvas.clientWidth,
228
+ clientHeight = canvas.clientHeight;
229
+ canvas.width = clientWidth;
230
+ canvas.height = clientHeight;
231
+ var context = canvas.getContext("2d");
232
+ context.save();
233
+ context.transform.apply(context, _toConsumableArray(mat.clone().inverse().toArray()));
234
+ var _layoutParams$current = layoutParams.current,
235
+ iw = _layoutParams$current.iw,
236
+ ih = _layoutParams$current.ih;
237
+
238
+ if (allowedArea) {
239
+ // Pattern to indicate the NOT allowed areas
240
+ var x = allowedArea.x,
241
+ y = allowedArea.y,
242
+ w = allowedArea.w,
243
+ h = allowedArea.h;
244
+ context.save();
245
+ context.globalAlpha = 1;
246
+ var outer = [[0, 0], [iw, 0], [iw, ih], [0, ih]];
247
+ var inner = [[x * iw, y * ih], [x * iw + w * iw, y * ih], [x * iw + w * iw, y * ih + h * ih], [x * iw, y * ih + h * ih]];
248
+ context.moveTo.apply(context, _toConsumableArray(outer[0]));
249
+ outer.forEach(function (p) {
250
+ return context.lineTo.apply(context, _toConsumableArray(p));
251
+ });
252
+ context.lineTo.apply(context, _toConsumableArray(outer[0]));
253
+ context.closePath();
254
+ inner.reverse();
255
+ context.moveTo.apply(context, _toConsumableArray(inner[0]));
256
+ inner.forEach(function (p) {
257
+ return context.lineTo.apply(context, _toConsumableArray(p));
258
+ });
259
+ context.lineTo.apply(context, _toConsumableArray(inner[0]));
260
+ context.fillStyle = excludePattern || "#f00";
261
+ context.fill();
262
+ context.restore();
263
+ }
264
+
265
+ context.restore();
266
+ });
267
+ var _layoutParams$current2 = layoutParams.current,
268
+ iw = _layoutParams$current2.iw,
269
+ ih = _layoutParams$current2.ih;
270
+ var zoomBox = !zoomStart || !zoomEnd ? null : _objectSpread({}, mat.clone().inverse().applyToPoint(zoomStart.x, zoomStart.y), {
271
+ w: (zoomEnd.x - zoomStart.x) / mat.a,
272
+ h: (zoomEnd.y - zoomStart.y) / mat.d
273
+ });
274
+
275
+ if (zoomBox) {
276
+ if (zoomBox.w < 0) {
277
+ zoomBox.x += zoomBox.w;
278
+ zoomBox.w *= -1;
279
+ }
280
+
281
+ if (zoomBox.h < 0) {
282
+ zoomBox.y += zoomBox.h;
283
+ zoomBox.h *= -1;
284
+ }
285
+ }
286
+
287
+ var imagePosition = {
288
+ topLeft: mat.clone().inverse().applyToPoint(0, 0),
289
+ bottomRight: mat.clone().inverse().applyToPoint(iw, ih)
290
+ };
291
+ var highlightedRegion = useMemo(function () {
292
+ var highlightedRegions = regions.filter(function (r) {
293
+ return r.highlighted;
294
+ });
295
+ if (highlightedRegions.length !== 1) return null;
296
+ return highlightedRegions[0];
297
+ }, [regions]);
298
+ return React.createElement(ThemeProvider, {
299
+ theme: theme
300
+ }, React.createElement("div", {
301
+ style: {
302
+ width: "100%",
303
+ height: "100%",
304
+ maxHeight: "calc(100vh - 68px)",
305
+ position: "relative",
306
+ overflow: "hidden",
307
+ cursor: createWithPrimary ? "crosshair" : dragging ? "grabbing" : dragWithPrimary ? "grab" : zoomWithPrimary ? mat.a < 1 ? "zoom-out" : "zoom-in" : undefined
308
+ }
309
+ }, showCrosshairs && React.createElement(Crosshairs, {
310
+ key: "crossHairs",
311
+ mousePosition: mousePosition
312
+ }), imageLoaded && !dragging && React.createElement(RegionSelectAndTransformBoxes, {
313
+ key: "regionSelectAndTransformBoxes",
314
+ regions: !modifyingAllowedArea || !allowedArea ? regions : [{
315
+ type: "box",
316
+ id: "$$allowed_area",
317
+ cls: "allowed_area",
318
+ highlighted: true,
319
+ x: allowedArea.x,
320
+ y: allowedArea.y,
321
+ w: allowedArea.w,
322
+ h: allowedArea.h,
323
+ visible: true,
324
+ color: "#ff0"
325
+ }],
326
+ mouseEvents: mouseEvents,
327
+ projectRegionBox: projectRegionBox,
328
+ dragWithPrimary: dragWithPrimary,
329
+ createWithPrimary: createWithPrimary,
330
+ zoomWithPrimary: zoomWithPrimary,
331
+ onBeginMovePoint: onBeginMovePoint,
332
+ onSelectRegion: onSelectRegion,
333
+ layoutParams: layoutParams,
334
+ mat: mat,
335
+ onBeginBoxTransform: onBeginBoxTransform,
336
+ onBeginMovePolygonPoint: onBeginMovePolygonPoint,
337
+ onBeginMoveKeypoint: onBeginMoveKeypoint,
338
+ onAddPolygonPoint: onAddPolygonPoint,
339
+ showHighlightBox: showHighlightBox
340
+ }), imageLoaded && showTags && !dragging && React.createElement(PreventScrollToParents, {
341
+ key: "regionTags"
342
+ }, React.createElement(RegionTags, {
343
+ regions: regions,
344
+ projectRegionBox: projectRegionBox,
345
+ mouseEvents: mouseEvents,
346
+ regionClsList: regionClsList,
347
+ regionTagList: regionTagList,
348
+ onBeginRegionEdit: onBeginRegionEdit,
349
+ onChangeRegion: onChangeRegion,
350
+ onCloseRegionEdit: onCloseRegionEdit,
351
+ onDeleteRegion: onDeleteRegion,
352
+ layoutParams: layoutParams,
353
+ imageSrc: imageSrc,
354
+ RegionEditLabel: RegionEditLabel,
355
+ onRegionClassAdded: onRegionClassAdded,
356
+ allowComments: allowComments,
357
+ hideNotEditingLabel: hideNotEditingLabel,
358
+ allowedGroups: allowedGroups
359
+ })), !showTags && highlightedRegion && React.createElement("div", {
360
+ key: "topLeftTag",
361
+ className: classes.fixedRegionLabel
362
+ }, React.createElement(RegionLabel, {
363
+ disableClose: true,
364
+ allowedClasses: regionClsList,
365
+ allowedTags: regionTagList,
366
+ onChange: onChangeRegion,
367
+ onDelete: onDeleteRegion,
368
+ editing: true,
369
+ region: highlightedRegion,
370
+ imageSrc: imageSrc,
371
+ allowComments: allowComments
372
+ })), zoomWithPrimary && zoomBox !== null && React.createElement("div", {
373
+ key: "zoomBox",
374
+ style: {
375
+ position: "absolute",
376
+ zIndex: 1,
377
+ border: "1px solid #fff",
378
+ pointerEvents: "none",
379
+ left: zoomBox.x,
380
+ top: zoomBox.y,
381
+ width: zoomBox.w,
382
+ height: zoomBox.h
383
+ }
384
+ }), showPointDistances && React.createElement(PointDistances, {
385
+ key: "pointDistances",
386
+ regions: regions,
387
+ realSize: realSize,
388
+ projectRegionBox: projectRegionBox,
389
+ pointDistancePrecision: pointDistancePrecision
390
+ }), React.createElement(PreventScrollToParents, Object.assign({
391
+ style: {
392
+ width: "100%",
393
+ height: "100%"
394
+ }
395
+ }, mouseEvents), React.createElement(React.Fragment, null, fullImageSegmentationMode && React.createElement(ImageMask, {
396
+ hide: !showMask,
397
+ autoSegmentationOptions: autoSegmentationOptions,
398
+ imagePosition: imagePosition,
399
+ regionClsList: regionClsList,
400
+ imageSrc: imageSrc,
401
+ regions: regions
402
+ }), React.createElement("canvas", {
403
+ style: {
404
+ opacity: 0.25
405
+ },
406
+ className: classes.canvas,
407
+ ref: canvasEl
408
+ }), React.createElement(RegionShapes, {
409
+ mat: mat,
410
+ keypointDefinitions: keypointDefinitions,
411
+ imagePosition: imagePosition,
412
+ regions: regions,
413
+ fullSegmentationMode: fullImageSegmentationMode
414
+ }), React.createElement(VideoOrImageCanvasBackground, {
415
+ videoPlaying: videoPlaying,
416
+ imagePosition: imagePosition,
417
+ mouseEvents: mouseEvents,
418
+ onLoad: onVideoOrImageLoaded,
419
+ videoTime: videoTime,
420
+ videoSrc: videoSrc,
421
+ imageSrc: imageSrc,
422
+ useCrossOrigin: fullImageSegmentationMode,
423
+ onChangeVideoTime: onChangeVideoTime,
424
+ onChangeVideoPlaying: onChangeVideoPlaying
425
+ }))), React.createElement("div", {
426
+ className: classes.zoomIndicator
427
+ }, (1 / mat.a * 100).toFixed(0), "%")));
428
+ };
429
+ export default ImageCanvas;