@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,1152 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
4
+ import { moveRegion } from "../../ImageCanvas/region-tools.js";
5
+ import { getIn, setIn, updateIn } from "seamless-immutable";
6
+ import moment from "moment";
7
+ import isEqual from "lodash/isEqual";
8
+ import getActiveImage from "./get-active-image";
9
+ import { saveToHistory } from "./history-handler.js";
10
+ import colors from "../../colors";
11
+ import fixTwisted from "./fix-twisted";
12
+ import convertExpandingLineToPolygon from "./convert-expanding-line-to-polygon";
13
+ import clamp from "clamp";
14
+ import getLandmarksWithTransform from "../../utils/get-landmarks-with-transform";
15
+ import setInLocalStorage from "../../utils/set-in-local-storage";
16
+ import onlyUnique from "../../utils/filter-only-unique";
17
+
18
+ var getRandomId = function getRandomId() {
19
+ return Math.random().toString().split(".")[1];
20
+ };
21
+
22
+ export default (function (state, action) {
23
+ if (state.allowedArea && state.selectedTool !== "modify-allowed-area" && ["MOUSE_DOWN", "MOUSE_UP", "MOUSE_MOVE"].includes(action.type)) {
24
+ var aa = state.allowedArea;
25
+ action.x = clamp(action.x, aa.x, aa.x + aa.w);
26
+ action.y = clamp(action.y, aa.y, aa.y + aa.h);
27
+ }
28
+
29
+ if (action.type === "ON_CLS_ADDED" && action.cls && action.cls !== "") {
30
+ var oldRegionClsList = state.regionClsList;
31
+
32
+ var newState = _objectSpread({}, state, {
33
+ regionClsList: oldRegionClsList.concat(action.cls)
34
+ });
35
+
36
+ return newState;
37
+ } // Throttle certain actions
38
+
39
+
40
+ if (action.type === "MOUSE_MOVE") {
41
+ if (Date.now() - (state.lastMouseMoveCall || 0) < 16) return state;
42
+ state = setIn(state, ["lastMouseMoveCall"], Date.now());
43
+ }
44
+
45
+ if (!action.type.includes("MOUSE")) {
46
+ state = setIn(state, ["lastAction"], action);
47
+ }
48
+
49
+ var _getActiveImage = getActiveImage(state),
50
+ currentImageIndex = _getActiveImage.currentImageIndex,
51
+ pathToActiveImage = _getActiveImage.pathToActiveImage,
52
+ activeImage = _getActiveImage.activeImage;
53
+
54
+ var getRegionIndex = function getRegionIndex(region) {
55
+ var regionId = typeof region === "string" || typeof region === "number" ? region : region.id;
56
+ if (!activeImage) return null;
57
+ var regionIndex = (activeImage.regions || []).findIndex(function (r) {
58
+ return r.id === regionId;
59
+ });
60
+ return regionIndex === -1 ? null : regionIndex;
61
+ };
62
+
63
+ var getRegion = function getRegion(regionId) {
64
+ if (!activeImage) return null;
65
+ var regionIndex = getRegionIndex(regionId);
66
+ if (regionIndex === null) return [null, null];
67
+ var region = activeImage.regions[regionIndex];
68
+ return [region, regionIndex];
69
+ };
70
+
71
+ var modifyRegion = function modifyRegion(regionId, obj) {
72
+ var _getRegion = getRegion(regionId),
73
+ _getRegion2 = _slicedToArray(_getRegion, 2),
74
+ region = _getRegion2[0],
75
+ regionIndex = _getRegion2[1];
76
+
77
+ if (!region) return state;
78
+
79
+ if (obj !== null) {
80
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", regionIndex]), _objectSpread({}, region, obj));
81
+ } else {
82
+ // delete region
83
+ var regions = activeImage.regions;
84
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), (regions || []).filter(function (r) {
85
+ return r.id !== region.id;
86
+ }));
87
+ }
88
+ };
89
+
90
+ var unselectRegions = function unselectRegions(state) {
91
+ if (!activeImage) return state;
92
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), (activeImage.regions || []).map(function (r) {
93
+ return _objectSpread({}, r, {
94
+ highlighted: false
95
+ });
96
+ }));
97
+ };
98
+
99
+ var closeEditors = function closeEditors(state) {
100
+ if (currentImageIndex === null) return state;
101
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), (activeImage.regions || []).map(function (r) {
102
+ return _objectSpread({}, r, {
103
+ editingLabels: false
104
+ });
105
+ }));
106
+ };
107
+
108
+ var setNewImage = function setNewImage(img, index) {
109
+ var _ref = typeof img === "object" ? img : {
110
+ src: img
111
+ },
112
+ src = _ref.src,
113
+ frameTime = _ref.frameTime;
114
+
115
+ return setIn(setIn(state, ["selectedImage"], index), ["selectedImageFrameTime"], frameTime);
116
+ };
117
+
118
+ switch (action.type) {
119
+ case "@@INIT":
120
+ {
121
+ return state;
122
+ }
123
+
124
+ case "SELECT_IMAGE":
125
+ {
126
+ return setNewImage(action.image, action.imageIndex);
127
+ }
128
+
129
+ case "SELECT_CLASSIFICATION":
130
+ {
131
+ return setIn(state, ["selectedCls"], action.cls);
132
+ }
133
+
134
+ case "CHANGE_REGION":
135
+ {
136
+ var regionIndex = getRegionIndex(action.region);
137
+ if (regionIndex === null) return state;
138
+ var oldRegion = activeImage.regions[regionIndex];
139
+
140
+ if (oldRegion.cls !== action.region.cls) {
141
+ state = saveToHistory(state, "Change Region Classification");
142
+ var clsIndex = state.regionClsList.indexOf(action.region.cls);
143
+
144
+ if (clsIndex !== -1) {
145
+ state = setIn(state, ["selectedCls"], action.region.cls);
146
+ action.region.color = colors[clsIndex % colors.length];
147
+ }
148
+ }
149
+
150
+ if (!isEqual(oldRegion.tags, action.region.tags)) {
151
+ state = saveToHistory(state, "Change Region Tags");
152
+ }
153
+
154
+ if (!isEqual(oldRegion.comment, action.region.comment)) {
155
+ state = saveToHistory(state, "Change Region Comment");
156
+ }
157
+
158
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", regionIndex]), action.region);
159
+ }
160
+
161
+ case "CHANGE_IMAGE":
162
+ {
163
+ if (!activeImage) return state;
164
+ var delta = action.delta;
165
+
166
+ for (var _i = 0, _Object$keys = Object.keys(delta); _i < _Object$keys.length; _i++) {
167
+ var key = _Object$keys[_i];
168
+ if (key === "cls") saveToHistory(state, "Change Image Class");
169
+ if (key === "tags") saveToHistory(state, "Change Image Tags");
170
+ state = setIn(state, [].concat(_toConsumableArray(pathToActiveImage), [key]), delta[key]);
171
+ }
172
+
173
+ return state;
174
+ }
175
+
176
+ case "SELECT_REGION":
177
+ {
178
+ var region = action.region;
179
+
180
+ var _regionIndex = getRegionIndex(action.region);
181
+
182
+ if (_regionIndex === null) return state;
183
+
184
+ var regions = _toConsumableArray(activeImage.regions || []).map(function (r) {
185
+ return _objectSpread({}, r, {
186
+ highlighted: r.id === region.id,
187
+ groupHighlighted: r.groupId && r.groupId === region.groupId ? true : false,
188
+ editingLabels: r.id === region.id
189
+ });
190
+ });
191
+
192
+ var selectedGroupIds = regions.filter(function (i) {
193
+ return i.highlighted;
194
+ }).map(function (r) {
195
+ return r.groupId || '';
196
+ }).filter(onlyUnique);
197
+
198
+ if (selectedGroupIds.length === 1) {
199
+ state = setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["selectedGroupId"]), selectedGroupIds[0]);
200
+ }
201
+
202
+ if (selectedGroupIds.length === 0) {
203
+ state = setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["selectedGroupId"]), null);
204
+ }
205
+
206
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), regions);
207
+ }
208
+
209
+ case "BEGIN_MOVE_POINT":
210
+ {
211
+ state = closeEditors(state);
212
+ return setIn(state, ["mode"], {
213
+ mode: "MOVE_REGION",
214
+ regionId: action.point.id
215
+ });
216
+ }
217
+
218
+ case "BEGIN_BOX_TRANSFORM":
219
+ {
220
+ var box = action.box,
221
+ directions = action.directions;
222
+ state = closeEditors(state);
223
+
224
+ if (directions[0] === 0 && directions[1] === 0) {
225
+ return setIn(state, ["mode"], {
226
+ mode: "MOVE_REGION",
227
+ regionId: box.id
228
+ });
229
+ } else {
230
+ return setIn(state, ["mode"], {
231
+ mode: "RESIZE_BOX",
232
+ regionId: box.id,
233
+ freedom: directions,
234
+ original: {
235
+ x: box.x,
236
+ y: box.y,
237
+ w: box.w,
238
+ h: box.h
239
+ }
240
+ });
241
+ }
242
+ }
243
+
244
+ case "BEGIN_MOVE_POLYGON_POINT":
245
+ {
246
+ var polygon = action.polygon,
247
+ pointIndex = action.pointIndex;
248
+ state = closeEditors(state);
249
+
250
+ if (state.mode && state.mode.mode === "DRAW_POLYGON" && pointIndex === 0) {
251
+ return setIn(modifyRegion(polygon, {
252
+ points: polygon.points.slice(0, -1),
253
+ open: false
254
+ }), ["mode"], null);
255
+ } else {
256
+ state = saveToHistory(state, "Move Polygon Point");
257
+ }
258
+
259
+ return setIn(state, ["mode"], {
260
+ mode: "MOVE_POLYGON_POINT",
261
+ regionId: polygon.id,
262
+ pointIndex: pointIndex
263
+ });
264
+ }
265
+
266
+ case "BEGIN_MOVE_KEYPOINT":
267
+ {
268
+ var _region = action.region,
269
+ keypointId = action.keypointId;
270
+ state = closeEditors(state);
271
+ state = saveToHistory(state, "Move Keypoint");
272
+ return setIn(state, ["mode"], {
273
+ mode: "MOVE_KEYPOINT",
274
+ regionId: _region.id,
275
+ keypointId: keypointId
276
+ });
277
+ }
278
+
279
+ case "ADD_POLYGON_POINT":
280
+ {
281
+ var _polygon = action.polygon,
282
+ point = action.point,
283
+ _pointIndex = action.pointIndex;
284
+
285
+ var _regionIndex2 = getRegionIndex(_polygon);
286
+
287
+ if (_regionIndex2 === null) return state;
288
+
289
+ var points = _toConsumableArray(_polygon.points);
290
+
291
+ points.splice(_pointIndex, 0, point);
292
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex2]), _objectSpread({}, _polygon, {
293
+ points: points
294
+ }));
295
+ }
296
+
297
+ case "MOUSE_MOVE":
298
+ {
299
+ var x = action.x,
300
+ y = action.y;
301
+ if (!state.mode) return state;
302
+ if (!activeImage) return state;
303
+ var _state = state,
304
+ mouseDownAt = _state.mouseDownAt;
305
+
306
+ switch (state.mode.mode) {
307
+ case "MOVE_POLYGON_POINT":
308
+ {
309
+ var _state$mode = state.mode,
310
+ _pointIndex2 = _state$mode.pointIndex,
311
+ regionId = _state$mode.regionId;
312
+
313
+ var _regionIndex3 = getRegionIndex(regionId);
314
+
315
+ if (_regionIndex3 === null) return state;
316
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex3, "points", _pointIndex2]), [x, y]);
317
+ }
318
+
319
+ case "MOVE_KEYPOINT":
320
+ {
321
+ var _state$mode2 = state.mode,
322
+ _keypointId = _state$mode2.keypointId,
323
+ _regionId = _state$mode2.regionId;
324
+
325
+ var _getRegion3 = getRegion(_regionId),
326
+ _getRegion4 = _slicedToArray(_getRegion3, 2),
327
+ _region2 = _getRegion4[0],
328
+ _regionIndex4 = _getRegion4[1];
329
+
330
+ if (_regionIndex4 === null) return state;
331
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex4, "points", _keypointId]), _objectSpread({}, _region2.points[_keypointId], {
332
+ x: x,
333
+ y: y
334
+ }));
335
+ }
336
+
337
+ case "MOVE_REGION":
338
+ {
339
+ var _regionId2 = state.mode.regionId;
340
+
341
+ if (_regionId2 === "$$allowed_area") {
342
+ var _state2 = state,
343
+ _state2$allowedArea = _state2.allowedArea,
344
+ w = _state2$allowedArea.w,
345
+ h = _state2$allowedArea.h;
346
+ return setIn(state, ["allowedArea"], {
347
+ x: x - w / 2,
348
+ y: y - h / 2,
349
+ w: w,
350
+ h: h
351
+ });
352
+ }
353
+
354
+ var _regionIndex5 = getRegionIndex(_regionId2);
355
+
356
+ if (_regionIndex5 === null) return state;
357
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex5]), moveRegion(activeImage.regions[_regionIndex5], x, y));
358
+ }
359
+
360
+ case "RESIZE_BOX":
361
+ {
362
+ var _state$mode3 = state.mode,
363
+ _regionId3 = _state$mode3.regionId,
364
+ _state$mode3$freedom = _slicedToArray(_state$mode3.freedom, 2),
365
+ xFree = _state$mode3$freedom[0],
366
+ yFree = _state$mode3$freedom[1],
367
+ _state$mode3$original = _state$mode3.original,
368
+ ox = _state$mode3$original.x,
369
+ oy = _state$mode3$original.y,
370
+ ow = _state$mode3$original.w,
371
+ oh = _state$mode3$original.h;
372
+
373
+ var dx = xFree === 0 ? ox : xFree === -1 ? Math.min(ox + ow, x) : ox;
374
+ var dw = xFree === 0 ? ow : xFree === -1 ? ow + (ox - dx) : Math.max(0, ow + (x - ox - ow));
375
+ var dy = yFree === 0 ? oy : yFree === -1 ? Math.min(oy + oh, y) : oy;
376
+ var dh = yFree === 0 ? oh : yFree === -1 ? oh + (oy - dy) : Math.max(0, oh + (y - oy - oh)); // determine if we should switch the freedom
377
+
378
+ if (dw <= 0.001) {
379
+ state = setIn(state, ["mode", "freedom"], [xFree * -1, yFree]);
380
+ }
381
+
382
+ if (dh <= 0.001) {
383
+ state = setIn(state, ["mode", "freedom"], [xFree, yFree * -1]);
384
+ }
385
+
386
+ if (_regionId3 === "$$allowed_area") {
387
+ return setIn(state, ["allowedArea"], {
388
+ x: dx,
389
+ w: dw,
390
+ y: dy,
391
+ h: dh
392
+ });
393
+ }
394
+
395
+ var _regionIndex6 = getRegionIndex(_regionId3);
396
+
397
+ if (_regionIndex6 === null) return state;
398
+ var _box = activeImage.regions[_regionIndex6];
399
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex6]), _objectSpread({}, _box, {
400
+ x: dx,
401
+ w: dw,
402
+ y: dy,
403
+ h: dh
404
+ }));
405
+ }
406
+
407
+ case "RESIZE_KEYPOINTS":
408
+ {
409
+ var _state$mode4 = state.mode,
410
+ _regionId4 = _state$mode4.regionId,
411
+ landmarks = _state$mode4.landmarks,
412
+ centerX = _state$mode4.centerX,
413
+ centerY = _state$mode4.centerY;
414
+ var distFromCenter = Math.sqrt(Math.pow(centerX - x, 2) + Math.pow(centerY - y, 2));
415
+ var scale = distFromCenter / 0.15;
416
+ return modifyRegion(_regionId4, {
417
+ points: getLandmarksWithTransform({
418
+ landmarks: landmarks,
419
+ center: {
420
+ x: centerX,
421
+ y: centerY
422
+ },
423
+ scale: scale
424
+ })
425
+ });
426
+ }
427
+
428
+ case "DRAW_POLYGON":
429
+ {
430
+ var _regionId5 = state.mode.regionId;
431
+
432
+ var _getRegion5 = getRegion(_regionId5),
433
+ _getRegion6 = _slicedToArray(_getRegion5, 2),
434
+ _region3 = _getRegion6[0],
435
+ _regionIndex7 = _getRegion6[1];
436
+
437
+ if (!_region3) return setIn(state, ["mode"], null);
438
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex7, "points", _region3.points.length - 1]), [x, y]);
439
+ }
440
+
441
+ case "DRAW_LINE":
442
+ {
443
+ var _regionId6 = state.mode.regionId;
444
+
445
+ var _getRegion7 = getRegion(_regionId6),
446
+ _getRegion8 = _slicedToArray(_getRegion7, 2),
447
+ _region4 = _getRegion8[0],
448
+ _regionIndex8 = _getRegion8[1];
449
+
450
+ if (!_region4) return setIn(state, ["mode"], null);
451
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex8]), _objectSpread({}, _region4, {
452
+ x2: x,
453
+ y2: y
454
+ }));
455
+ }
456
+
457
+ case "DRAW_EXPANDING_LINE":
458
+ {
459
+ var _regionId7 = state.mode.regionId;
460
+
461
+ var _getRegion9 = getRegion(_regionId7),
462
+ _getRegion10 = _slicedToArray(_getRegion9, 2),
463
+ expandingLine = _getRegion10[0],
464
+ _regionIndex9 = _getRegion10[1];
465
+
466
+ if (!expandingLine) return state;
467
+ var isMouseDown = Boolean(state.mouseDownAt);
468
+
469
+ if (isMouseDown) {
470
+ // If the mouse is down, set width/angle
471
+ var lastPoint = expandingLine.points.slice(-1)[0];
472
+ var mouseDistFromLastPoint = Math.sqrt(Math.pow(lastPoint.x - x, 2) + Math.pow(lastPoint.y - y, 2));
473
+ if (mouseDistFromLastPoint < 0.002 && !lastPoint.width) return state;
474
+
475
+ var _newState = setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex9, "points"]), expandingLine.points.slice(0, -1).concat([_objectSpread({}, lastPoint, {
476
+ width: mouseDistFromLastPoint * 2,
477
+ angle: Math.atan2(lastPoint.x - x, lastPoint.y - y)
478
+ })]));
479
+
480
+ return _newState;
481
+ } else {
482
+ // If mouse is up, move the next candidate point
483
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex9]), _objectSpread({}, expandingLine, {
484
+ candidatePoint: {
485
+ x: x,
486
+ y: y
487
+ }
488
+ }));
489
+ }
490
+
491
+ return state;
492
+ }
493
+
494
+ case "SET_EXPANDING_LINE_WIDTH":
495
+ {
496
+ var _regionId8 = state.mode.regionId;
497
+
498
+ var _getRegion11 = getRegion(_regionId8),
499
+ _getRegion12 = _slicedToArray(_getRegion11, 2),
500
+ _expandingLine = _getRegion12[0],
501
+ _regionIndex10 = _getRegion12[1];
502
+
503
+ if (!_expandingLine) return state;
504
+
505
+ var _lastPoint = _expandingLine.points.slice(-1)[0];
506
+
507
+ var _state3 = state,
508
+ _mouseDownAt = _state3.mouseDownAt;
509
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex10, "expandingWidth"]), Math.sqrt(Math.pow(_lastPoint.x - x, 2) + Math.pow(_lastPoint.y - y, 2)));
510
+ }
511
+
512
+ default:
513
+ return state;
514
+ }
515
+ }
516
+
517
+ case "MOUSE_DOWN":
518
+ {
519
+ if (!activeImage) return state;
520
+ var _x = action.x,
521
+ _y = action.y;
522
+ state = setIn(state, ["mouseDownAt"], {
523
+ x: _x,
524
+ y: _y
525
+ });
526
+
527
+ if (state.mode) {
528
+ switch (state.mode.mode) {
529
+ case "DRAW_POLYGON":
530
+ {
531
+ var _getRegion13 = getRegion(state.mode.regionId),
532
+ _getRegion14 = _slicedToArray(_getRegion13, 2),
533
+ _polygon2 = _getRegion14[0],
534
+ _regionIndex11 = _getRegion14[1];
535
+
536
+ if (!_polygon2) break;
537
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex11]), _objectSpread({}, _polygon2, {
538
+ points: _polygon2.points.concat([[_x, _y]])
539
+ }));
540
+ }
541
+
542
+ case "DRAW_LINE":
543
+ {
544
+ var _getRegion15 = getRegion(state.mode.regionId),
545
+ _getRegion16 = _slicedToArray(_getRegion15, 2),
546
+ line = _getRegion16[0],
547
+ _regionIndex12 = _getRegion16[1];
548
+
549
+ if (!line) break;
550
+ setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex12]), _objectSpread({}, line, {
551
+ x2: _x,
552
+ y2: _y
553
+ }));
554
+ return setIn(state, ["mode"], null);
555
+ }
556
+
557
+ case "DRAW_EXPANDING_LINE":
558
+ {
559
+ var _getRegion17 = getRegion(state.mode.regionId),
560
+ _getRegion18 = _slicedToArray(_getRegion17, 2),
561
+ _expandingLine2 = _getRegion18[0],
562
+ _regionIndex13 = _getRegion18[1];
563
+
564
+ if (!_expandingLine2) break;
565
+
566
+ var _lastPoint2 = _expandingLine2.points.slice(-1)[0];
567
+
568
+ if (_expandingLine2.points.length > 1 && Math.sqrt(Math.pow(_lastPoint2.x - _x, 2) + Math.pow(_lastPoint2.y - _y, 2)) < 0.002) {
569
+ if (!_lastPoint2.width) {
570
+ return setIn(state, ["mode"], {
571
+ mode: "SET_EXPANDING_LINE_WIDTH",
572
+ regionId: state.mode.regionId
573
+ });
574
+ } else {
575
+ return state.setIn([].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex13]), convertExpandingLineToPolygon(_expandingLine2)).setIn(["mode"], null);
576
+ }
577
+ } // Create new point
578
+
579
+
580
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex13, "points"]), _expandingLine2.points.concat([{
581
+ x: _x,
582
+ y: _y,
583
+ angle: null,
584
+ width: null
585
+ }]));
586
+ }
587
+
588
+ case "SET_EXPANDING_LINE_WIDTH":
589
+ {
590
+ var _getRegion19 = getRegion(state.mode.regionId),
591
+ _getRegion20 = _slicedToArray(_getRegion19, 2),
592
+ _expandingLine3 = _getRegion20[0],
593
+ _regionIndex14 = _getRegion20[1];
594
+
595
+ if (!_expandingLine3) break;
596
+ var expandingWidth = _expandingLine3.expandingWidth;
597
+ return state.setIn([].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex14]), convertExpandingLineToPolygon(_objectSpread({}, _expandingLine3, {
598
+ points: _expandingLine3.points.map(function (p) {
599
+ return p.width ? p : _objectSpread({}, p, {
600
+ width: expandingWidth
601
+ });
602
+ }),
603
+ expandingWidth: undefined
604
+ }))).setIn(["mode"], null);
605
+ }
606
+
607
+ default:
608
+ break;
609
+ }
610
+ }
611
+
612
+ var newRegion;
613
+ var defaultRegionCls = state.selectedCls,
614
+ defaultRegionColor = "#ff0000";
615
+
616
+ var _clsIndex = (state.regionClsList || []).indexOf(defaultRegionCls);
617
+
618
+ if (_clsIndex !== -1) {
619
+ defaultRegionColor = colors[_clsIndex % colors.length];
620
+ }
621
+
622
+ switch (state.selectedTool) {
623
+ case "create-point":
624
+ {
625
+ state = saveToHistory(state, "Create Point");
626
+ newRegion = {
627
+ type: "point",
628
+ x: _x,
629
+ y: _y,
630
+ highlighted: true,
631
+ editingLabels: true,
632
+ color: defaultRegionColor,
633
+ id: getRandomId(),
634
+ cls: defaultRegionCls
635
+ };
636
+ break;
637
+ }
638
+
639
+ case "create-box":
640
+ {
641
+ state = saveToHistory(state, "Create Box");
642
+ newRegion = {
643
+ type: "box",
644
+ x: _x,
645
+ y: _y,
646
+ w: 0,
647
+ h: 0,
648
+ highlighted: true,
649
+ editingLabels: false,
650
+ color: defaultRegionColor,
651
+ cls: defaultRegionCls,
652
+ id: getRandomId()
653
+ };
654
+ state = setIn(state, ["mode"], {
655
+ mode: "RESIZE_BOX",
656
+ editLabelEditorAfter: true,
657
+ regionId: newRegion.id,
658
+ freedom: [1, 1],
659
+ original: {
660
+ x: _x,
661
+ y: _y,
662
+ w: newRegion.w,
663
+ h: newRegion.h
664
+ },
665
+ isNew: true
666
+ });
667
+ break;
668
+ }
669
+
670
+ case "create-polygon":
671
+ {
672
+ if (state.mode && state.mode.mode === "DRAW_POLYGON") break;
673
+ state = saveToHistory(state, "Create Polygon");
674
+ newRegion = {
675
+ type: "polygon",
676
+ points: [[_x, _y], [_x, _y]],
677
+ open: true,
678
+ highlighted: true,
679
+ color: defaultRegionColor,
680
+ cls: defaultRegionCls,
681
+ id: getRandomId()
682
+ };
683
+ state = setIn(state, ["mode"], {
684
+ mode: "DRAW_POLYGON",
685
+ regionId: newRegion.id
686
+ });
687
+ break;
688
+ }
689
+
690
+ case "create-expanding-line":
691
+ {
692
+ state = saveToHistory(state, "Create Expanding Line");
693
+ newRegion = {
694
+ type: "expanding-line",
695
+ unfinished: true,
696
+ points: [{
697
+ x: _x,
698
+ y: _y,
699
+ angle: null,
700
+ width: null
701
+ }],
702
+ open: true,
703
+ highlighted: true,
704
+ color: defaultRegionColor,
705
+ cls: defaultRegionCls,
706
+ id: getRandomId()
707
+ };
708
+ state = setIn(state, ["mode"], {
709
+ mode: "DRAW_EXPANDING_LINE",
710
+ regionId: newRegion.id
711
+ });
712
+ break;
713
+ }
714
+
715
+ case "create-line":
716
+ {
717
+ if (state.mode && state.mode.mode === "DRAW_LINE") break;
718
+ state = saveToHistory(state, "Create Line");
719
+ newRegion = {
720
+ type: "line",
721
+ x1: _x,
722
+ y1: _y,
723
+ x2: _x,
724
+ y2: _y,
725
+ highlighted: true,
726
+ editingLabels: false,
727
+ color: defaultRegionColor,
728
+ cls: defaultRegionCls,
729
+ id: getRandomId()
730
+ };
731
+ state = setIn(state, ["mode"], {
732
+ mode: "DRAW_LINE",
733
+ regionId: newRegion.id
734
+ });
735
+ break;
736
+ }
737
+
738
+ case "create-keypoints":
739
+ {
740
+ state = saveToHistory(state, "Create Keypoints");
741
+
742
+ var _ref2 = Object.entries(state.keypointDefinitions),
743
+ _ref3 = _slicedToArray(_ref2, 1),
744
+ _ref3$ = _slicedToArray(_ref3[0], 2),
745
+ keypointsDefinitionId = _ref3$[0],
746
+ _ref3$$ = _ref3$[1],
747
+ _landmarks = _ref3$$.landmarks,
748
+ connections = _ref3$$.connections;
749
+
750
+ newRegion = {
751
+ type: "keypoints",
752
+ keypointsDefinitionId: keypointsDefinitionId,
753
+ points: getLandmarksWithTransform({
754
+ landmarks: _landmarks,
755
+ center: {
756
+ x: _x,
757
+ y: _y
758
+ },
759
+ scale: 1
760
+ }),
761
+ highlighted: true,
762
+ editingLabels: false,
763
+ id: getRandomId()
764
+ };
765
+ state = setIn(state, ["mode"], {
766
+ mode: "RESIZE_KEYPOINTS",
767
+ landmarks: _landmarks,
768
+ centerX: _x,
769
+ centerY: _y,
770
+ regionId: newRegion.id,
771
+ isNew: true
772
+ });
773
+ break;
774
+ }
775
+
776
+ default:
777
+ break;
778
+ }
779
+
780
+ var _regions = _toConsumableArray(getIn(state, pathToActiveImage).regions || []).map(function (r) {
781
+ return setIn(r, ["editingLabels"], false).setIn(["highlighted"], false).setIn(["groupHighlighted"], false);
782
+ }).concat(newRegion ? [newRegion] : []);
783
+
784
+ state = setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["selectedGroupId"]), null);
785
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), _regions);
786
+ }
787
+
788
+ case "MOUSE_UP":
789
+ {
790
+ var _x2 = action.x,
791
+ _y2 = action.y;
792
+
793
+ var _state4 = state,
794
+ _state4$mouseDownAt = _state4.mouseDownAt,
795
+ _mouseDownAt2 = _state4$mouseDownAt === void 0 ? {
796
+ x: _x2,
797
+ y: _y2
798
+ } : _state4$mouseDownAt;
799
+
800
+ if (!state.mode) return state;
801
+ state = setIn(state, ["mouseDownAt"], null);
802
+
803
+ switch (state.mode.mode) {
804
+ case "RESIZE_BOX":
805
+ {
806
+ if (state.mode.isNew) {
807
+ if (Math.abs(state.mode.original.x - _x2) < 0.002 || Math.abs(state.mode.original.y - _y2) < 0.002) {
808
+ return setIn(modifyRegion(state.mode.regionId, null), ["mode"], null);
809
+ }
810
+ }
811
+
812
+ if (state.mode.editLabelEditorAfter) {
813
+ return _objectSpread({}, modifyRegion(state.mode.regionId, {
814
+ editingLabels: true
815
+ }), {
816
+ mode: null
817
+ });
818
+ }
819
+ }
820
+
821
+ case "MOVE_REGION":
822
+ case "RESIZE_KEYPOINTS":
823
+ case "MOVE_POLYGON_POINT":
824
+ {
825
+ return _objectSpread({}, state, {
826
+ mode: null
827
+ });
828
+ }
829
+
830
+ case "MOVE_KEYPOINT":
831
+ {
832
+ return _objectSpread({}, state, {
833
+ mode: null
834
+ });
835
+ }
836
+
837
+ case "CREATE_POINT_LINE":
838
+ {
839
+ return state;
840
+ }
841
+
842
+ case "DRAW_EXPANDING_LINE":
843
+ {
844
+ var _getRegion21 = getRegion(state.mode.regionId),
845
+ _getRegion22 = _slicedToArray(_getRegion21, 2),
846
+ _expandingLine4 = _getRegion22[0],
847
+ _regionIndex15 = _getRegion22[1];
848
+
849
+ if (!_expandingLine4) return state;
850
+ var newExpandingLine = _expandingLine4;
851
+
852
+ var _lastPoint3 = _expandingLine4.points.length !== 0 ? _expandingLine4.points.slice(-1)[0] : _mouseDownAt2;
853
+
854
+ var jointStart;
855
+
856
+ if (_expandingLine4.points.length > 1) {
857
+ jointStart = _expandingLine4.points.slice(-2)[0];
858
+ } else {
859
+ jointStart = _lastPoint3;
860
+ }
861
+
862
+ var _mouseDistFromLastPoint = Math.sqrt(Math.pow(_lastPoint3.x - _x2, 2) + Math.pow(_lastPoint3.y - _y2, 2));
863
+
864
+ if (_mouseDistFromLastPoint > 0.002) {
865
+ // The user is drawing has drawn the width for the last point
866
+ var newPoints = _toConsumableArray(_expandingLine4.points);
867
+
868
+ for (var i = 0; i < newPoints.length - 1; i++) {
869
+ if (newPoints[i].width) continue;
870
+ newPoints[i] = _objectSpread({}, newPoints[i], {
871
+ width: _lastPoint3.width
872
+ });
873
+ }
874
+
875
+ newExpandingLine = setIn(_expandingLine4, ["points"], fixTwisted(newPoints));
876
+ } else {
877
+ return state;
878
+ }
879
+
880
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex15]), newExpandingLine);
881
+ }
882
+
883
+ default:
884
+ return state;
885
+ }
886
+ }
887
+
888
+ case "OPEN_REGION_EDITOR":
889
+ {
890
+ var _region5 = action.region;
891
+
892
+ var _regionIndex16 = getRegionIndex(action.region);
893
+
894
+ if (_regionIndex16 === null) return state;
895
+ var newRegions = setIn(activeImage.regions.map(function (r) {
896
+ return _objectSpread({}, r, {
897
+ highlighted: false,
898
+ editingLabels: false
899
+ });
900
+ }), [_regionIndex16], _objectSpread({}, (activeImage.regions || [])[_regionIndex16], {
901
+ highlighted: true,
902
+ editingLabels: true
903
+ }));
904
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), newRegions);
905
+ }
906
+
907
+ case "CLOSE_REGION_EDITOR":
908
+ {
909
+ var _region6 = action.region;
910
+
911
+ var _regionIndex17 = getRegionIndex(action.region);
912
+
913
+ if (_regionIndex17 === null) return state;
914
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions", _regionIndex17]), _objectSpread({}, (activeImage.regions || [])[_regionIndex17], {
915
+ editingLabels: false
916
+ }));
917
+ }
918
+
919
+ case "DELETE_REGION":
920
+ {
921
+ var _regionIndex18 = getRegionIndex(action.region);
922
+
923
+ if (_regionIndex18 === null) return state;
924
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), (activeImage.regions || []).filter(function (r) {
925
+ return r.id !== action.region.id;
926
+ }));
927
+ }
928
+
929
+ case "DELETE_SELECTED_REGION":
930
+ {
931
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), (activeImage.regions || []).filter(function (r) {
932
+ return !r.highlighted;
933
+ }));
934
+ }
935
+
936
+ case "HEADER_BUTTON_CLICKED":
937
+ {
938
+ var buttonName = action.buttonName.toLowerCase();
939
+
940
+ switch (buttonName) {
941
+ case "prev":
942
+ {
943
+ if (currentImageIndex === null) return state;
944
+ if (currentImageIndex === 0) return state;
945
+ return setNewImage(state.images[currentImageIndex - 1], currentImageIndex - 1);
946
+ }
947
+
948
+ case "next":
949
+ {
950
+ if (currentImageIndex === null) return state;
951
+ if (currentImageIndex === state.images.length - 1) return state;
952
+ return setNewImage(state.images[currentImageIndex + 1], currentImageIndex + 1);
953
+ }
954
+
955
+ case "clone":
956
+ {
957
+ if (currentImageIndex === null) return state;
958
+ if (currentImageIndex === state.images.length - 1) return state;
959
+ return setIn(setNewImage(state.images[currentImageIndex + 1], currentImageIndex + 1), ["images", currentImageIndex + 1, "regions"], activeImage.regions);
960
+ }
961
+
962
+ case "settings":
963
+ {
964
+ return setIn(state, ["settingsOpen"], !state.settingsOpen);
965
+ }
966
+
967
+ case "help":
968
+ {
969
+ return state;
970
+ }
971
+
972
+ case "fullscreen":
973
+ {
974
+ return setIn(state, ["fullScreen"], true);
975
+ }
976
+
977
+ case "exit fullscreen":
978
+ case "window":
979
+ {
980
+ return setIn(state, ["fullScreen"], false);
981
+ }
982
+
983
+ case "hotkeys":
984
+ {
985
+ return state;
986
+ }
987
+
988
+ case "exit":
989
+ case "done":
990
+ {
991
+ return state;
992
+ }
993
+
994
+ default:
995
+ return state;
996
+ }
997
+ }
998
+
999
+ case "SELECT_TOOL":
1000
+ {
1001
+ if (action.selectedTool === "show-tags") {
1002
+ setInLocalStorage("showTags", !state.showTags);
1003
+ return setIn(state, ["showTags"], !state.showTags);
1004
+ } else if (action.selectedTool === "show-mask") {
1005
+ return setIn(state, ["showMask"], !state.showMask);
1006
+ }
1007
+
1008
+ if (action.selectedTool === "modify-allowed-area" && !state.allowedArea) {
1009
+ state = setIn(state, ["allowedArea"], {
1010
+ x: 0,
1011
+ y: 0,
1012
+ w: 1,
1013
+ h: 1
1014
+ });
1015
+ }
1016
+
1017
+ state = setIn(state, ["mode"], null);
1018
+ return setIn(state, ["selectedTool"], action.selectedTool);
1019
+ }
1020
+
1021
+ case "CANCEL":
1022
+ {
1023
+ var _state5 = state,
1024
+ mode = _state5.mode;
1025
+
1026
+ if (mode) {
1027
+ switch (mode.mode) {
1028
+ case "DRAW_EXPANDING_LINE":
1029
+ case "SET_EXPANDING_LINE_WIDTH":
1030
+ case "DRAW_POLYGON":
1031
+ {
1032
+ var _regionId9 = mode.regionId;
1033
+ return modifyRegion(_regionId9, null);
1034
+ }
1035
+
1036
+ case "MOVE_POLYGON_POINT":
1037
+ case "RESIZE_BOX":
1038
+ case "MOVE_REGION":
1039
+ {
1040
+ return setIn(state, ["mode"], null);
1041
+ }
1042
+
1043
+ default:
1044
+ return state;
1045
+ }
1046
+ } // Close any open boxes
1047
+
1048
+
1049
+ var _regions2 = activeImage.regions;
1050
+
1051
+ if (_regions2 && _regions2.some(function (r) {
1052
+ return r.editingLabels;
1053
+ })) {
1054
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), _regions2.map(function (r) {
1055
+ return _objectSpread({}, r, {
1056
+ editingLabels: false
1057
+ });
1058
+ }));
1059
+ } else if (_regions2) {
1060
+ return setIn(state, [].concat(_toConsumableArray(pathToActiveImage), ["regions"]), _regions2.map(function (r) {
1061
+ return _objectSpread({}, r, {
1062
+ highlighted: false
1063
+ });
1064
+ }));
1065
+ }
1066
+
1067
+ break;
1068
+ }
1069
+
1070
+ case "UPDATE_REGIONS":
1071
+ {
1072
+ var imageIndex = action.imageIndex,
1073
+ _newRegions = action.regions;
1074
+ var updatedRegions = state.images[imageIndex].regions.map(function (r) {
1075
+ var updatedRegion = _newRegions.find(function (i) {
1076
+ return i.id === r.id;
1077
+ });
1078
+
1079
+ if (!updatedRegion) {
1080
+ return r;
1081
+ }
1082
+
1083
+ return _objectSpread({}, r, {
1084
+ cls: updatedRegion.cls,
1085
+ text: updatedRegion.text
1086
+ });
1087
+ }); // TODO: add mutation of order and deletion of regions - SI-1967
1088
+
1089
+ return setIn(state, ["images", imageIndex, "regions"], updatedRegions);
1090
+ }
1091
+
1092
+ case "IMAGES_UPDATED":
1093
+ {
1094
+ var updatedAt = action.updatedAt;
1095
+ return setIn(state, ["imagesUpdatedAt"], updatedAt);
1096
+ }
1097
+
1098
+ case "IMAGES_SAVED":
1099
+ {
1100
+ var savedAt = action.savedAt;
1101
+ return setIn(state, ["imagesSavedAt"], savedAt);
1102
+ }
1103
+
1104
+ case "UPDATE_METADATA":
1105
+ {
1106
+ var name = action.name,
1107
+ value = action.value,
1108
+ _imageIndex = action.imageIndex;
1109
+
1110
+ if (isNaN(_imageIndex)) {
1111
+ var _state$metadata;
1112
+
1113
+ // update global metadata
1114
+ var metadataIndex = (_state$metadata = state.metadata) === null || _state$metadata === void 0 ? void 0 : _state$metadata.findIndex(function (mt) {
1115
+ return mt.key === name;
1116
+ });
1117
+
1118
+ if (metadataIndex < 0) {
1119
+ console.error("can't find metadata by key \"".concat(name, "\""));
1120
+ return;
1121
+ }
1122
+
1123
+ return setIn(state, ["metadata", metadataIndex], {
1124
+ key: name,
1125
+ value: value
1126
+ });
1127
+ } else {
1128
+ var _state$images$_imageI, _state$images$_imageI2;
1129
+
1130
+ // update local metadata of imageIndex
1131
+ var _metadataIndex = (_state$images$_imageI = state.images[_imageIndex]) === null || _state$images$_imageI === void 0 ? void 0 : (_state$images$_imageI2 = _state$images$_imageI.metadata) === null || _state$images$_imageI2 === void 0 ? void 0 : _state$images$_imageI2.findIndex(function (mt) {
1132
+ return mt.key === name;
1133
+ });
1134
+
1135
+ if (_metadataIndex < 0) {
1136
+ console.error("can't find metadata by key \"".concat(name, "\""));
1137
+ return;
1138
+ }
1139
+
1140
+ return setIn(state, ["images", _imageIndex, "metadata", _metadataIndex], {
1141
+ key: name,
1142
+ value: value
1143
+ });
1144
+ }
1145
+ }
1146
+
1147
+ default:
1148
+ break;
1149
+ }
1150
+
1151
+ return state;
1152
+ });