lost-sia 2.0.1-alpha8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/README.md +4 -0
  2. package/dist/Annotation/logic/Annotation.d.ts +17 -0
  3. package/dist/Annotation/logic/Annotation.js +1 -0
  4. package/dist/Annotation/ui/AnnotationComponent.d.ts +24 -0
  5. package/dist/Annotation/ui/AnnotationComponent.js +1 -0
  6. package/dist/Annotation/ui/atoms/AnnoBar.d.ts +15 -0
  7. package/dist/Annotation/ui/atoms/AnnoBar.js +1 -0
  8. package/dist/Annotation/ui/atoms/DaviIcon.d.ts +9 -0
  9. package/dist/Annotation/ui/atoms/DaviIcon.js +19 -0
  10. package/dist/Annotation/ui/atoms/Edge.d.ts +17 -0
  11. package/dist/Annotation/ui/atoms/Edge.js +1 -0
  12. package/dist/Annotation/ui/atoms/Node.d.ts +17 -0
  13. package/dist/Annotation/ui/atoms/Node.js +1 -0
  14. package/dist/Annotation/ui/atoms/PolygonArea.d.ts +16 -0
  15. package/dist/Annotation/ui/atoms/PolygonArea.js +1 -0
  16. package/dist/Annotation/ui/tools/BBox.d.ts +21 -0
  17. package/dist/Annotation/ui/tools/BBox.js +1 -0
  18. package/dist/Annotation/ui/tools/Line.d.ts +21 -0
  19. package/dist/Annotation/ui/tools/Line.js +1 -0
  20. package/dist/Annotation/ui/tools/Point.d.ts +16 -0
  21. package/dist/Annotation/ui/tools/Point.js +1 -0
  22. package/dist/Annotation/ui/tools/Polygon.d.ts +23 -0
  23. package/dist/Annotation/ui/tools/Polygon.js +1 -0
  24. package/dist/Canvas/Canvas.d.ts +31 -0
  25. package/dist/Canvas/Canvas.js +1 -0
  26. package/dist/Canvas/LabelInput.d.ts +11 -0
  27. package/dist/Canvas/LabelInput.js +1 -0
  28. package/dist/IconButton.d.ts +25 -0
  29. package/dist/IconButton.js +1 -0
  30. package/dist/Sia.d.ts +33 -0
  31. package/dist/Sia.js +1 -0
  32. package/dist/Toolbar/Toolbar.d.ts +21 -0
  33. package/dist/Toolbar/Toolbar.js +1 -0
  34. package/dist/Toolbar/ToolbarItems/AccessibilityTools.d.ts +7 -0
  35. package/dist/Toolbar/ToolbarItems/AccessibilityTools.js +1 -0
  36. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.d.ts +11 -0
  37. package/dist/Toolbar/ToolbarItems/AnnoToolSelector.js +1 -0
  38. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.d.ts +11 -0
  39. package/dist/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.js +1 -0
  40. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.d.ts +11 -0
  41. package/dist/Toolbar/ToolbarItems/ImageToolItems/TagLabel.js +1 -0
  42. package/dist/Toolbar/ToolbarItems/ImageTools.d.ts +13 -0
  43. package/dist/Toolbar/ToolbarItems/ImageTools.js +1 -0
  44. package/dist/Toolbar/ToolbarItems/Instructions.d.ts +2 -0
  45. package/dist/Toolbar/ToolbarItems/Instructions.js +1 -0
  46. package/dist/Toolbar/ToolbarItems/InstructionsModal.d.ts +6 -0
  47. package/dist/Toolbar/ToolbarItems/InstructionsModal.js +1 -0
  48. package/dist/assets/SIA-BV1tYu3P.css +1 -0
  49. package/dist/assets/brand-icons-Cu_C0hZ4.svg +1008 -0
  50. package/dist/assets/brand-icons-F3SPCeH1.woff +0 -0
  51. package/dist/assets/brand-icons-XL9sxUpA.woff2 +0 -0
  52. package/dist/assets/brand-icons-sqJ2Pg7a.eot +0 -0
  53. package/dist/assets/brand-icons-ubhWoxly.ttf +0 -0
  54. package/dist/assets/flags-DOLqOU7Y.png +0 -0
  55. package/dist/assets/icons-BOCtAERH.woff +0 -0
  56. package/dist/assets/icons-CHzK1VD9.eot +0 -0
  57. package/dist/assets/icons-D29ZQHHw.ttf +0 -0
  58. package/dist/assets/icons-Du6TOHnR.woff2 +0 -0
  59. package/dist/assets/icons-RwhydX30.svg +1518 -0
  60. package/dist/assets/node_modules/semantic-ui-css/semantic.min-Bvulf91l.css +346 -0
  61. package/dist/assets/outline-icons-BfdLr8tr.svg +366 -0
  62. package/dist/assets/outline-icons-DD8jm0uy.ttf +0 -0
  63. package/dist/assets/outline-icons-DInHoiqI.woff2 +0 -0
  64. package/dist/assets/outline-icons-LX8adJ4n.eot +0 -0
  65. package/dist/assets/outline-icons-aQ88nltS.woff +0 -0
  66. package/dist/index.d.ts +5 -0
  67. package/dist/index.js +1 -0
  68. package/dist/models/AnnotationMode.d.ts +11 -0
  69. package/dist/models/AnnotationMode.js +1 -0
  70. package/dist/models/AnnotationStatus.d.ts +8 -0
  71. package/dist/models/AnnotationStatus.js +1 -0
  72. package/dist/models/AnnotationTool.d.ts +7 -0
  73. package/dist/models/AnnotationTool.js +1 -0
  74. package/dist/models/CanvasAction.d.ts +28 -0
  75. package/dist/models/CanvasAction.js +1 -0
  76. package/dist/models/Direction.d.ts +7 -0
  77. package/dist/models/Direction.js +1 -0
  78. package/dist/models/EditorModes.d.ts +11 -0
  79. package/dist/models/EditorModes.js +1 -0
  80. package/dist/models/KeyAction.d.ts +22 -0
  81. package/dist/models/KeyAction.js +1 -0
  82. package/dist/models/NotificationType.d.ts +7 -0
  83. package/dist/models/NotificationType.js +1 -0
  84. package/dist/models/index.d.ts +6 -0
  85. package/dist/models/index.js +1 -0
  86. package/dist/stories/AnnotationTools.stories.d.ts +40 -0
  87. package/dist/stories/Canvas/Canvas.stories.d.ts +50 -0
  88. package/dist/stories/Canvas/CanvasOffset.d.ts +13 -0
  89. package/dist/stories/Canvas/CanvasWithOffset.stories.d.ts +36 -0
  90. package/dist/stories/FilterDropdown.stories.d.ts +19 -0
  91. package/dist/stories/MinimalSia.stories.d.ts +66 -0
  92. package/dist/stories/SIA/DemoWrapper.d.ts +8 -0
  93. package/dist/stories/SIA/DemoWrapper.stories.d.ts +27 -0
  94. package/dist/stories/SIA/SIA.stories.d.ts +72 -0
  95. package/dist/stories/Toolbar/ImageTools/TagLabel.stories.d.ts +21 -0
  96. package/dist/stories/Toolbar/Instructions.stories.d.ts +11 -0
  97. package/dist/stories/Toolbar/Toolbar.stories.d.ts +37 -0
  98. package/dist/stories/exampleData/exampleAnnotations.d.ts +8 -0
  99. package/dist/stories/exampleData/exampleExternalAnnotations.d.ts +8 -0
  100. package/dist/stories/exampleData/exampleImage.d.ts +2 -0
  101. package/dist/stories/exampleData/exampleLabels.d.ts +6 -0
  102. package/dist/types.d.ts +57 -0
  103. package/dist/types.js +1 -0
  104. package/dist/utils/KeyMapper.d.ts +9 -0
  105. package/dist/utils/KeyMapper.js +1 -0
  106. package/dist/utils/TimeUtils.d.ts +4 -0
  107. package/dist/utils/TimeUtils.js +1 -0
  108. package/dist/utils/color.d.ts +2 -0
  109. package/dist/utils/color.js +1 -0
  110. package/dist/utils/index.d.ts +2 -0
  111. package/dist/utils/index.js +1 -0
  112. package/dist/utils/mouse.d.ts +6 -0
  113. package/dist/utils/mouse.js +1 -0
  114. package/dist/utils/siaIcons.js +12 -0
  115. package/dist/utils/transform.d.ts +28 -0
  116. package/dist/utils/transform.js +1 -0
  117. package/dist/utils/uiConfig.js +1 -0
  118. package/dist/utils/windowViewport.d.ts +22 -0
  119. package/dist/utils/windowViewport.js +1 -0
  120. package/package.json +19 -16
  121. package/src/AnnoExampleViewer.jsx +18 -18
  122. package/src/Annotation/logic/Annotation.ts +24 -26
  123. package/src/Annotation/ui/AnnotationComponent.tsx +115 -86
  124. package/src/Annotation/ui/atoms/AnnoBar.tsx +51 -53
  125. package/src/Annotation/ui/atoms/DaviIcon.tsx +12 -22
  126. package/src/Annotation/ui/atoms/Edge.tsx +25 -22
  127. package/src/Annotation/ui/atoms/Node.tsx +56 -50
  128. package/src/Annotation/ui/atoms/PolygonArea.tsx +30 -35
  129. package/src/Annotation/ui/tools/BBox.tsx +136 -150
  130. package/src/Annotation/ui/tools/Line.tsx +94 -91
  131. package/src/Annotation/ui/tools/Point.tsx +19 -17
  132. package/src/Annotation/ui/tools/Polygon.tsx +126 -95
  133. package/src/Canvas/Canvas.tsx +748 -594
  134. package/src/Canvas/LabelInput.tsx +68 -45
  135. package/src/IconButton.tsx +119 -0
  136. package/src/InfoBoxes/AnnoDetails.jsx +53 -53
  137. package/src/InfoBoxes/AnnoStats.jsx +41 -41
  138. package/src/InfoBoxes/InfoBox.jsx +16 -16
  139. package/src/InfoBoxes/InfoBoxArea.jsx +32 -34
  140. package/src/InfoBoxes/LabelInfo.jsx +30 -30
  141. package/src/SIASettingButton.jsx +25 -25
  142. package/src/Sia.tsx +484 -0
  143. package/src/Toolbar/Toolbar.tsx +38 -31
  144. package/src/Toolbar/ToolbarItems/AccessibilityTools.tsx +26 -46
  145. package/src/Toolbar/ToolbarItems/AnnoToolSelector.tsx +53 -46
  146. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabelInput.tsx +127 -0
  147. package/src/Toolbar/ToolbarItems/ImageToolItems/TagLabel.tsx +29 -28
  148. package/src/Toolbar/ToolbarItems/ImageTools.tsx +43 -40
  149. package/src/Toolbar/ToolbarItems/Instructions.tsx +47 -50
  150. package/src/Toolbar/ToolbarItems/InstructionsModal.tsx +8 -8
  151. package/src/index.ts +9 -13
  152. package/src/models/{AnnotationMode.tsx → AnnotationMode.ts} +1 -1
  153. package/src/models/{AnnotationStatus.tsx → AnnotationStatus.ts} +1 -1
  154. package/src/models/{AnnotationTool.tsx → AnnotationTool.ts} +1 -1
  155. package/src/models/{CanvasAction.tsx → CanvasAction.ts} +1 -1
  156. package/src/models/{Direction.tsx → Direction.ts} +1 -1
  157. package/src/models/{EditorModes.tsx → EditorModes.ts} +1 -1
  158. package/src/models/{KeyAction.tsx → KeyAction.ts} +3 -1
  159. package/src/models/NotificationType.ts +8 -0
  160. package/src/models/index.ts +6 -7
  161. package/src/siaDummyData.js +71 -71
  162. package/src/stories/AnnotationTools.mdx +27 -0
  163. package/src/stories/AnnotationTools.stories.tsx +104 -0
  164. package/src/stories/Canvas/Canvas.stories.tsx +59 -113
  165. package/src/stories/Canvas/CanvasOffset.tsx +54 -38
  166. package/src/stories/Canvas/CanvasWithOffset.stories.tsx +42 -113
  167. package/src/stories/FilterDropdown.stories.ts +13 -11
  168. package/src/stories/MinimalSIA.mdx +20 -0
  169. package/src/stories/MinimalSia.stories.tsx +90 -0
  170. package/src/stories/SIA/DemoWrapper.stories.tsx +71 -0
  171. package/src/stories/SIA/DemoWrapper.tsx +55 -0
  172. package/src/stories/SIA/SIA.stories.tsx +79 -45
  173. package/src/stories/Toolbar/ImageTools/TagLabel.stories.tsx +11 -12
  174. package/src/stories/Toolbar/Instructions.stories.tsx +11 -11
  175. package/src/stories/Toolbar/Toolbar.stories.tsx +32 -47
  176. package/src/stories/Welcome.mdx +5 -0
  177. package/src/stories/development/CoordinateSystems.mdx +25 -0
  178. package/src/stories/exampleData/exampleAnnotations.ts +65 -0
  179. package/src/stories/exampleData/exampleExternalAnnotations.ts +115 -0
  180. package/src/stories/{siaDummyData2.ts → exampleData/exampleImage.ts} +3 -264
  181. package/src/stories/exampleData/exampleLabels.ts +146 -0
  182. package/src/stories/main.scss +6 -0
  183. package/src/styles/style.scss +1 -26
  184. package/src/types.ts +67 -0
  185. package/src/utils/KeyMapper.ts +76 -74
  186. package/src/utils/TimeUtils.ts +11 -0
  187. package/src/utils/color.ts +25 -25
  188. package/src/utils/hist.js +22 -22
  189. package/src/utils/index.ts +2 -3
  190. package/src/utils/mouse.ts +45 -0
  191. package/src/utils/siaIcons.jsx +5 -7
  192. package/src/utils/transform.ts +186 -0
  193. package/src/utils/uiConfig.js +19 -22
  194. package/src/utils/windowViewport.ts +34 -0
  195. package/src/AnnoLabelInput.jsx +0 -109
  196. package/src/AnnoToolBar.jsx +0 -153
  197. package/src/Annotation/AnnoBar.jsx +0 -154
  198. package/src/Annotation/Annotation.jsx +0 -395
  199. package/src/Annotation/Annotation.scss +0 -47
  200. package/src/Annotation/BBox.jsx +0 -299
  201. package/src/Annotation/Edge.jsx +0 -92
  202. package/src/Annotation/InfSelectionArea.jsx +0 -72
  203. package/src/Annotation/Line.jsx +0 -68
  204. package/src/Annotation/Node.jsx +0 -282
  205. package/src/Annotation/Point.jsx +0 -200
  206. package/src/Annotation/Polygon.jsx +0 -404
  207. package/src/Annotation/logic/AnnotationUtils.ts +0 -30
  208. package/src/Canvas.jsx +0 -2194
  209. package/src/ImgBar.jsx +0 -131
  210. package/src/LabelInput.jsx +0 -238
  211. package/src/Prompt.jsx +0 -45
  212. package/src/SIAFilterButton.jsx +0 -186
  213. package/src/Sia.jsx +0 -478
  214. package/src/Sia2.tsx +0 -392
  215. package/src/SiaPopup.jsx +0 -15
  216. package/src/ToolBar.jsx +0 -463
  217. package/src/Toolbar/NavigationButtons.tsx +0 -21
  218. package/src/Toolbar/ToolbarItem.jsx +0 -30
  219. package/src/Toolbar/ToolbarItems/ImageToolItems/ImageLabel.tsx +0 -62
  220. package/src/Toolbar.css +0 -13
  221. package/src/ToolbarItem.jsx +0 -31
  222. package/src/filterTools.js +0 -5
  223. package/src/models/AllowedTools.tsx +0 -9
  224. package/src/models/AnnotationSettings.tsx +0 -9
  225. package/src/models/ExternalAnnotation.ts +0 -15
  226. package/src/models/Label.tsx +0 -8
  227. package/src/models/UiConfig.tsx +0 -6
  228. package/src/stories/Button.jsx +0 -54
  229. package/src/stories/Button.stories.js +0 -48
  230. package/src/stories/Header.jsx +0 -69
  231. package/src/stories/Header.stories.js +0 -28
  232. package/src/stories/Page.jsx +0 -87
  233. package/src/stories/Page.stories.js +0 -28
  234. package/src/stories/SIA2/DemoWrapper.stories.tsx +0 -167
  235. package/src/stories/SIA2/DemoWrapper.tsx +0 -54
  236. package/src/stories/SIA2/Sia2.stories.tsx +0 -62
  237. package/src/stories/Toolbar/ImageTools/ImageLabel.stories.tsx +0 -32
  238. package/src/stories/assets/accessibility.png +0 -0
  239. package/src/stories/assets/accessibility.svg +0 -5
  240. package/src/stories/assets/addon-library.png +0 -0
  241. package/src/stories/assets/assets.png +0 -0
  242. package/src/stories/assets/avif-test-image.avif +0 -0
  243. package/src/stories/assets/context.png +0 -0
  244. package/src/stories/assets/discord.svg +0 -15
  245. package/src/stories/assets/docs.png +0 -0
  246. package/src/stories/assets/figma-plugin.png +0 -0
  247. package/src/stories/assets/github.svg +0 -3
  248. package/src/stories/assets/share.png +0 -0
  249. package/src/stories/assets/styling.png +0 -0
  250. package/src/stories/assets/testing.png +0 -0
  251. package/src/stories/assets/theming.png +0 -0
  252. package/src/stories/assets/tutorials.svg +0 -12
  253. package/src/stories/assets/youtube.svg +0 -4
  254. package/src/stories/button.css +0 -30
  255. package/src/stories/header.css +0 -32
  256. package/src/stories/lost.js +0 -54
  257. package/src/stories/page.css +0 -69
  258. package/src/stories/siaDummyData.js +0 -263
  259. package/src/stories/store.js +0 -18
  260. package/src/test.js +0 -7
  261. package/src/types/annoStatus.js +0 -4
  262. package/src/types/canvasActions.js +0 -58
  263. package/src/types/cursorstyles.js +0 -3
  264. package/src/types/modes.js +0 -9
  265. package/src/types/notificationType.js +0 -11
  266. package/src/types/toolbarEvents.js +0 -35
  267. package/src/types/tools.js +0 -17
  268. package/src/types.tsx +0 -11
  269. package/src/utils/annoConversion.js +0 -145
  270. package/src/utils/annoConversion2.ts +0 -145
  271. package/src/utils/colorlut.js +0 -68
  272. package/src/utils/constraints.js +0 -81
  273. package/src/utils/index.js +0 -1
  274. package/src/utils/keyActions.js +0 -113
  275. package/src/utils/mouse.js +0 -14
  276. package/src/utils/mouse2.ts +0 -35
  277. package/src/utils/transform.js +0 -336
  278. package/src/utils/transform2.ts +0 -343
  279. package/src/utils/windowViewport.js +0 -34
  280. package/src/utils/windowViewport2.ts +0 -50
@@ -1,29 +1,29 @@
1
- import { CSSProperties, useEffect, useRef, useState } from "react";
1
+ import { CSSProperties, MouseEvent, useEffect, useRef, useState } from 'react'
2
2
 
3
3
  // rename type to avoid naming conflict
4
- import { Point } from "../../../types";
5
- import Node from "../atoms/Node";
6
- import AnnotationSettings from "../../../models/AnnotationSettings";
7
- import AnnotationMode from "../../../models/AnnotationMode";
8
- import mouse2 from "../../../utils/mouse2";
9
- import PolygonArea from "../atoms/PolygonArea";
10
- import Edge from "../atoms/Edge";
4
+ import { AnnotationSettings, Point } from '../../../types'
5
+ import Node from '../atoms/Node'
6
+ import AnnotationMode from '../../../models/AnnotationMode'
7
+ import mouse from '../../../utils/mouse'
8
+ import PolygonArea from '../atoms/PolygonArea'
9
+ import Edge from '../atoms/Edge'
11
10
 
12
11
  type BBoxProps = {
13
- annotationMode: AnnotationMode;
14
- annotationSettings: AnnotationSettings;
15
- pageToStageOffset: Point;
16
- startCoords: Point;
17
- endCoords: Point;
18
- svgScale: number;
19
- isSelected: boolean;
20
- style: CSSProperties;
21
- onDeleteNode: (coordinates: Point[]) => void;
22
- onFinishAnnoCreate: () => void;
23
- onIsDraggingStateChanged: (bool) => void;
24
- onMoving: (coordinates: Point[]) => void; // during moving - update coordinates in parent
25
- onMoved: () => void; // moving finished - send annotation changed event
26
- };
12
+ annotationMode: AnnotationMode
13
+ annotationSettings: AnnotationSettings
14
+ pageToStageOffset: Point
15
+ startCoords: Point
16
+ endCoords: Point
17
+ svgScale: number
18
+ svgTranslation: Point
19
+ isSelected: boolean
20
+ style: CSSProperties
21
+ onDeleteNode: (coordinates: Point[]) => void
22
+ onFinishAnnoCreate: () => void
23
+ onIsDraggingStateChanged: (newDraggingState: boolean) => void
24
+ onMoving: (coordinates: Point[]) => void // during moving - update coordinates in parent
25
+ onMoved: () => void // moving finished - send annotation changed event
26
+ }
27
27
 
28
28
  const BBox = ({
29
29
  annotationMode,
@@ -32,6 +32,7 @@ const BBox = ({
32
32
  startCoords,
33
33
  endCoords,
34
34
  svgScale,
35
+ svgTranslation,
35
36
  isSelected,
36
37
  style,
37
38
  onDeleteNode,
@@ -46,143 +47,132 @@ const BBox = ({
46
47
  { x: startCoords.x, y: endCoords.y },
47
48
  endCoords,
48
49
  { x: endCoords.x, y: startCoords.y },
49
- ];
50
+ ]
50
51
 
51
52
  const [isAnnoCreating, setIsAnnoCreating] = useState<boolean>(
52
53
  annotationMode === AnnotationMode.CREATE,
53
- );
54
- const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false);
55
- const [isEdgeDragging, setIsEdgeDragging] = useState<boolean>(false);
56
- const [dragSelectedEdgeIndex, setDragSelectedEdgeIndex] = useState<number>(0);
54
+ )
55
+ const [isAnnoDragging, setIsAnnoDragging] = useState<boolean>(false)
56
+ const [isEdgeDragging, setIsEdgeDragging] = useState<boolean>(false)
57
+ const [dragSelectedEdgeIndex, setDragSelectedEdgeIndex] = useState<number>(0)
57
58
 
58
59
  // onMove and onMouseUp events are fired in the same frame
59
60
  // use a ref to access the updated value without waiting until the next frame
60
- const [didAnnoActuallyMove, setDidAnnoActuallyMove] =
61
- useState<boolean>(false);
62
- const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove);
61
+ const [didAnnoActuallyMove, setDidAnnoActuallyMove] = useState<boolean>(false)
62
+ const didAnnoActuallyMoveRef = useRef<boolean>(didAnnoActuallyMove)
63
63
 
64
64
  useEffect(() => {
65
- didAnnoActuallyMoveRef.current = didAnnoActuallyMove;
66
- }, [didAnnoActuallyMove]);
65
+ didAnnoActuallyMoveRef.current = didAnnoActuallyMove
66
+ }, [didAnnoActuallyMove])
67
67
 
68
68
  const onMouseDown = (e: MouseEvent) => {
69
- if (annotationSettings.canEdit === false) return;
69
+ if (annotationSettings.canEdit === false) return
70
70
 
71
- if (
72
- isSelected &&
73
- annotationMode !== AnnotationMode.CREATE &&
74
- e.button === 0
75
- )
76
- setIsAnnoDragging(true);
77
- };
71
+ if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
72
+ setIsAnnoDragging(true)
73
+ }
78
74
 
79
75
  const onMouseEdgeDown = (e: MouseEvent) => {
80
- if (annotationSettings.canEdit === false) return;
76
+ if (annotationSettings.canEdit === false) return
81
77
 
82
- if (
83
- isSelected &&
84
- annotationMode !== AnnotationMode.CREATE &&
85
- e.button === 0
86
- )
87
- setIsEdgeDragging(true);
88
- };
78
+ if (isSelected && annotationMode !== AnnotationMode.CREATE && e.button === 0)
79
+ setIsEdgeDragging(true)
80
+ }
89
81
 
90
82
  const onMouseMove = (e: MouseEvent) => {
91
83
  if (isAnnoDragging) {
92
84
  // we always get 4 coordinates (the rectangle corners)
93
85
  // only the top left and bottom right corner are important - other coordinates are redundant
94
- const newRectangle: Point[] = [
95
- { ...coordinates[0] },
96
- { ...coordinates[2] },
97
- ];
86
+ const newRectangle: Point[] = [{ ...coordinates[0] }, { ...coordinates[2] }]
98
87
 
99
88
  // apply mouse move to the rectangle coordinates
100
- const movedCoordinates: Point[] = newRectangle.map(
101
- (coordinate: Point) => {
102
- return {
103
- // counter the canvas scaling (it will be automatically applied when rendering the annotation coordinates)
104
- x: (coordinate.x += e.movementX / svgScale),
105
- y: (coordinate.y += e.movementY / svgScale),
106
- };
107
- },
108
- );
89
+ const movedCoordinates: Point[] = newRectangle.map((coordinate: Point) => {
90
+ // counter the canvas scaling (it will be automatically applied when rendering the annotation coordinates)
91
+ const newX = (coordinate.x += e.movementX / svgScale)
92
+ const newY = (coordinate.y += e.movementY / svgScale)
93
+ return {
94
+ x: newX,
95
+ y: newY,
96
+ }
97
+ })
109
98
 
110
99
  // only escalate event when mouse actually moved
111
100
  if (e.movementX !== 0 || e.movementY !== 0) {
112
- setDidAnnoActuallyMove(true);
113
- onMoving(movedCoordinates);
101
+ setDidAnnoActuallyMove(true)
102
+ onMoving(movedCoordinates)
114
103
  }
115
104
  }
116
105
 
117
106
  if (annotationMode === AnnotationMode.CREATE) {
118
- const mousePointInStage = mouse2.getAntiScaledMouseStagePosition(
107
+ const mousePointInStage = mouse.getAntiScaledMouseStagePosition(
119
108
  e,
120
109
  pageToStageOffset,
121
110
  svgScale,
122
- );
111
+ svgTranslation,
112
+ )
123
113
 
124
- let newCoords: Point[] = [...coordinates];
114
+ const newCoords: Point[] = [...coordinates]
125
115
 
126
116
  // we always get 4 coordinates (the rectangle corners)
127
117
  // only the top left (start) is important - the end will be our mouse position and the others are redundant
128
- const newRectangle: Point[] = [newCoords[0], mousePointInStage];
118
+ const newRectangle: Point[] = [newCoords[0], mousePointInStage]
129
119
 
130
- onMoving(newRectangle);
120
+ onMoving(newRectangle)
131
121
  }
132
- };
122
+ }
133
123
 
134
124
  useEffect(() => {
135
- if (!isAnnoCreating) return;
125
+ if (!isAnnoCreating) return
136
126
 
137
- const handleMouseUp = (e: MouseEvent) => {
127
+ const handleMouseUp = (e: globalThis.MouseEvent) => {
138
128
  if (e.button === 2) {
139
- onFinishAnnoCreate();
140
- setIsAnnoCreating(false);
129
+ onFinishAnnoCreate()
130
+ setIsAnnoCreating(false)
141
131
  }
142
- };
132
+ }
143
133
 
144
- window.addEventListener("mouseup", handleMouseUp);
134
+ globalThis.addEventListener('mouseup', handleMouseUp)
145
135
 
146
136
  return () => {
147
- window.removeEventListener("mouseup", handleMouseUp);
148
- };
149
- }, [isAnnoCreating]);
137
+ globalThis.removeEventListener('mouseup', handleMouseUp)
138
+ }
139
+ }, [isAnnoCreating])
150
140
 
151
141
  useEffect(() => {
152
- onIsDraggingStateChanged(isAnnoDragging);
153
- if (!isAnnoDragging) return;
142
+ onIsDraggingStateChanged(isAnnoDragging)
143
+ if (!isAnnoDragging) return
154
144
 
155
145
  const handleMouseUp = () => {
156
- setIsAnnoDragging(false);
146
+ setIsAnnoDragging(false)
157
147
 
158
- if (didAnnoActuallyMoveRef.current) onMoved();
159
- setDidAnnoActuallyMove(false);
160
- };
148
+ if (didAnnoActuallyMoveRef.current) onMoved()
149
+ setDidAnnoActuallyMove(false)
150
+ }
161
151
 
162
- window.addEventListener("mouseup", handleMouseUp);
152
+ globalThis.addEventListener('mouseup', handleMouseUp)
163
153
 
164
154
  return () => {
165
- window.removeEventListener("mouseup", handleMouseUp);
166
- };
167
- }, [isAnnoDragging]);
155
+ globalThis.removeEventListener('mouseup', handleMouseUp)
156
+ }
157
+ }, [isAnnoDragging])
168
158
 
169
159
  useEffect(() => {
170
- onIsDraggingStateChanged(isEdgeDragging);
171
- if (!isEdgeDragging) return;
160
+ onIsDraggingStateChanged(isEdgeDragging)
161
+ if (!isEdgeDragging) return
172
162
 
173
163
  const handleMouseUp = () => {
174
- setIsEdgeDragging(false);
164
+ setIsEdgeDragging(false)
175
165
 
176
- if (didAnnoActuallyMoveRef.current) onMoved();
177
- setDidAnnoActuallyMove(false);
178
- };
166
+ if (didAnnoActuallyMoveRef.current) onMoved()
167
+ setDidAnnoActuallyMove(false)
168
+ }
179
169
 
180
- window.addEventListener("mouseup", handleMouseUp);
170
+ globalThis.addEventListener('mouseup', handleMouseUp)
181
171
 
182
172
  return () => {
183
- window.removeEventListener("mouseup", handleMouseUp);
184
- };
185
- }, [isEdgeDragging]);
173
+ globalThis.removeEventListener('mouseup', handleMouseUp)
174
+ }
175
+ }, [isEdgeDragging])
186
176
 
187
177
  const renderNodes = () => {
188
178
  const svgNodes = coordinates.map((coordinate: Point, index: number) => (
@@ -193,80 +183,79 @@ const BBox = ({
193
183
  coordinates={coordinate}
194
184
  pageToStageOffset={pageToStageOffset}
195
185
  svgScale={svgScale}
186
+ svgTranslation={svgTranslation}
196
187
  style={style}
197
188
  onDeleteNode={() => {
198
- const newCoordinates = [...coordinates];
199
- newCoordinates.splice(index, 1);
200
- onDeleteNode(newCoordinates);
189
+ const newCoordinates = [...coordinates]
190
+ newCoordinates.splice(index, 1)
191
+ onDeleteNode(newCoordinates)
201
192
  }}
202
193
  onMoving={(index: number, newPoint: Point) => {
203
194
  // we always get 4 coordinates (the rectangle corners)
204
195
  // only the top left and bottom right corner are important - other coordinates are redundant
205
- const newRectangle: Point[] = [coordinates[0], coordinates[2]];
196
+ const newRectangle: Point[] = [coordinates[0], coordinates[2]]
206
197
 
207
198
  // update start + end coordinates depending on which corner is moved
208
199
  switch (index) {
209
200
  case 0: // top left corner
210
- newRectangle[0] = newPoint;
211
- break;
201
+ newRectangle[0] = newPoint
202
+ break
212
203
  case 1: // bottom left corner
213
- newRectangle[0].x = newPoint.x;
214
- newRectangle[1].y = newPoint.y;
215
- break;
204
+ newRectangle[0].x = newPoint.x
205
+ newRectangle[1].y = newPoint.y
206
+ break
216
207
  case 2: // bottom right corner
217
- newRectangle[1] = newPoint;
218
- break;
208
+ newRectangle[1] = newPoint
209
+ break
219
210
  case 3: // top right corner
220
- newRectangle[1].x = newPoint.x;
221
- newRectangle[0].y = newPoint.y;
222
- break;
211
+ newRectangle[1].x = newPoint.x
212
+ newRectangle[0].y = newPoint.y
213
+ break
223
214
  }
224
215
 
225
- onMoving(newRectangle);
216
+ onMoving(newRectangle)
226
217
  }}
227
218
  onMoved={() => onMoved()}
228
219
  onIsDraggingStateChanged={onIsDraggingStateChanged}
229
220
  />
230
- ));
221
+ ))
231
222
 
232
- return svgNodes;
233
- };
223
+ return svgNodes
224
+ }
234
225
 
235
226
  const moveEdge = (edgeIndex: number, e: MouseEvent) => {
236
227
  // we always get 4 coordinates (the rectangle corners)
237
228
  // only the top left and bottom right corner are important - other coordinates are redundant
238
- const newRectangle: Point[] = [coordinates[0], coordinates[2]];
229
+ const newRectangle: Point[] = [coordinates[0], coordinates[2]]
239
230
  switch (edgeIndex) {
240
231
  case 0:
241
- newRectangle[0].x += e.movementX / svgScale;
242
- break;
232
+ newRectangle[0].x += e.movementX / svgScale
233
+ break
243
234
  case 1:
244
- newRectangle[1].y += e.movementY / svgScale;
245
- break;
235
+ newRectangle[1].y += e.movementY / svgScale
236
+ break
246
237
  case 2:
247
- newRectangle[1].x += e.movementX / svgScale;
248
- break;
238
+ newRectangle[1].x += e.movementX / svgScale
239
+ break
249
240
  case 3:
250
- newRectangle[0].y += e.movementY / svgScale;
251
- break;
241
+ newRectangle[0].y += e.movementY / svgScale
242
+ break
252
243
  }
253
244
 
254
245
  // only escalate event when mouse actually moved
255
246
  if (e.movementX !== 0 || e.movementY !== 0) {
256
- setDidAnnoActuallyMove(true);
257
- onMoving(newRectangle);
247
+ setDidAnnoActuallyMove(true)
248
+ onMoving(newRectangle)
258
249
  }
259
- };
250
+ }
260
251
 
261
252
  const renderEdges = () => {
262
253
  const svgEdges = coordinates.map((coordinate: Point, index: number) => {
263
254
  const endCoordinates: Point =
264
- index + 1 < coordinates.length
265
- ? coordinates[index + 1]
266
- : coordinates[0];
255
+ index + 1 < coordinates.length ? coordinates[index + 1] : coordinates[0]
267
256
 
268
257
  // corresponding cursor for horizontal or vertical edges
269
- const cursor = index % 2 === 0 ? "ew-resize" : "ns-resize";
258
+ const cursor = index % 2 === 0 ? 'ew-resize' : 'ns-resize'
270
259
 
271
260
  return (
272
261
  <Edge
@@ -275,48 +264,45 @@ const BBox = ({
275
264
  endCoordinate={endCoordinates}
276
265
  pageToStageOffset={pageToStageOffset}
277
266
  svgScale={svgScale}
267
+ svgTranslation={svgTranslation}
278
268
  style={{ ...style, cursor }}
279
269
  onMouseDown={onMouseEdgeDown}
280
270
  onMouseMove={(e: MouseEvent) => {
281
- setDragSelectedEdgeIndex(index);
282
- isEdgeDragging && moveEdge(index, e);
271
+ setDragSelectedEdgeIndex(index)
272
+ if (isEdgeDragging) moveEdge(index, e)
283
273
  }}
284
274
  />
285
- );
286
- });
287
- return svgEdges;
288
- };
275
+ )
276
+ })
277
+ return svgEdges
278
+ }
289
279
 
290
280
  const renderInfiniteSelectionArea = (isForEdge: boolean) => {
291
281
  return (
292
282
  <circle
293
283
  cx={coordinates[0].x}
294
284
  cy={coordinates[0].y}
295
- r={"100%"}
285
+ r={'100%'}
296
286
  style={{ opacity: 0 }}
297
287
  onMouseDown={onMouseDown}
298
288
  onMouseMove={(e: MouseEvent) => {
299
- isForEdge && isEdgeDragging && moveEdge(dragSelectedEdgeIndex, e);
300
- !isForEdge && onMouseMove(e);
289
+ if (isForEdge && isEdgeDragging) moveEdge(dragSelectedEdgeIndex, e)
290
+ if (!isForEdge) onMouseMove(e)
301
291
  }}
302
292
  onContextMenu={(e) => e.preventDefault()}
303
293
  />
304
- );
305
- };
294
+ )
295
+ }
306
296
 
307
297
  return (
308
298
  <g>
309
299
  {(isAnnoDragging || annotationMode === AnnotationMode.CREATE) &&
310
300
  renderInfiniteSelectionArea(false)}
311
301
  <PolygonArea
312
- annotationSettings={annotationSettings}
313
302
  coordinates={coordinates}
314
303
  isSelected={isSelected}
315
304
  annotationMode={annotationMode}
316
- pageToStageOffset={pageToStageOffset}
317
305
  style={style}
318
- svgScale={svgScale}
319
- onIsDraggingStateChanged={onIsDraggingStateChanged}
320
306
  onMouseDown={onMouseDown}
321
307
  onMouseMove={onMouseMove}
322
308
  />
@@ -324,7 +310,7 @@ const BBox = ({
324
310
  {isSelected && annotationSettings.canEdit && renderEdges()}
325
311
  {isSelected && annotationMode !== AnnotationMode.CREATE && renderNodes()}
326
312
  </g>
327
- );
328
- };
313
+ )
314
+ }
329
315
 
330
- export default BBox;
316
+ export default BBox