@searpent/react-image-annotate 2.0.5 → 2.0.8

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 +268 -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/{src/Editor → Editor}/annotation-plugin/annotation.css +0 -0
  19. package/Editor/annotation-plugin/annotation.js +613 -0
  20. package/Editor/index.js +57 -0
  21. package/{src/Editor → Editor}/tools.js +2 -3
  22. package/FullImageSegmentationAnnotator/index.js +7 -0
  23. package/GroupSelectorSidebarBox/index.js +63 -0
  24. package/HighlightBox/index.js +99 -0
  25. package/HistorySidebarBox/index.js +71 -0
  26. package/ImageCanvas/index.js +429 -0
  27. package/ImageCanvas/region-tools.js +165 -0
  28. package/{src/ImageCanvas → ImageCanvas}/styles.js +12 -8
  29. package/ImageCanvas/use-mouse.js +180 -0
  30. package/ImageCanvas/use-project-box.js +27 -0
  31. package/ImageCanvas/use-wasd-mode.js +62 -0
  32. package/ImageMask/index.js +133 -0
  33. package/ImageMask/load-image.js +25 -0
  34. package/ImageSelectorSidebarBox/index.js +60 -0
  35. package/KeyframeTimeline/get-time-string.js +27 -0
  36. package/KeyframeTimeline/index.js +233 -0
  37. package/KeyframesSelectorSidebarBox/index.js +93 -0
  38. package/LandingPage/index.js +159 -0
  39. package/MainLayout/icon-dictionary.js +104 -0
  40. package/MainLayout/index.js +469 -0
  41. package/{src/MainLayout → MainLayout}/styles.js +6 -7
  42. package/MainLayout/types.js +0 -0
  43. package/MainLayout/use-implied-video-regions.js +13 -0
  44. package/MetadataEditorSidebarBox/index.js +126 -0
  45. package/PageSelector/index.js +69 -0
  46. package/{src/PageSelector → PageSelector}/page-selector.css +18 -0
  47. package/PointDistances/index.js +73 -0
  48. package/PreventScrollToParents/index.js +51 -0
  49. package/RegionLabel/index.js +205 -0
  50. package/{src/RegionLabel → RegionLabel}/styles.js +12 -15
  51. package/RegionSelectAndTransformBoxes/index.js +167 -0
  52. package/RegionSelectorSidebarBox/index.js +248 -0
  53. package/{src/RegionSelectorSidebarBox → RegionSelectorSidebarBox}/styles.js +13 -14
  54. package/RegionShapes/index.js +294 -0
  55. package/RegionTags/index.js +142 -0
  56. package/SettingsDialog/index.js +52 -0
  57. package/SettingsProvider/index.js +58 -0
  58. package/Shortcuts/ShortcutField.js +46 -0
  59. package/Shortcuts/index.js +133 -0
  60. package/ShortcutsManager/index.js +155 -0
  61. package/Sidebar/index.js +69 -0
  62. package/SidebarBoxContainer/index.js +93 -0
  63. package/SmallToolButton/index.js +42 -0
  64. package/TagsSidebarBox/index.js +105 -0
  65. package/TaskDescriptionSidebarBox/index.js +58 -0
  66. package/Theme/index.js +30 -0
  67. package/VideoOrImageCanvasBackground/index.js +151 -0
  68. package/colors.js +14 -0
  69. package/hooks/use-colors.js +101 -0
  70. package/hooks/use-event-callback.js +10 -0
  71. package/hooks/use-exclude-pattern.js +24 -0
  72. package/hooks/use-load-image.js +26 -0
  73. package/hooks/use-window-size.js +46 -0
  74. package/{src/hooks → hooks}/xpattern.js +1 -1
  75. package/index.js +3 -0
  76. package/lib.js +3 -0
  77. package/package.json +1 -1
  78. package/stories.js +5 -0
  79. package/{src/utils → utils}/filter-only-unique.js +1 -1
  80. package/utils/get-from-local-storage.js +7 -0
  81. package/utils/get-hotkey-help-text.js +9 -0
  82. package/utils/get-landmarks-with-transform.js +40 -0
  83. package/utils/photosToImages.js +53 -0
  84. package/utils/regions-to-blocks.js +16 -0
  85. package/utils/set-in-local-storage.js +3 -0
  86. package/.babelrc +0 -6
  87. package/.env +0 -1
  88. package/.flowconfig +0 -2
  89. package/.github/workflows/release-on-master.yml +0 -32
  90. package/.github/workflows/test.yml +0 -16
  91. package/.prettierrc +0 -3
  92. package/.releaserc.js +0 -18
  93. package/.storybook/addons.js +0 -2
  94. package/.storybook/config.js +0 -16
  95. package/LICENSE +0 -21
  96. package/public/favicon.ico +0 -0
  97. package/public/index.html +0 -38
  98. package/src/Annotator/bike-pic.png +0 -0
  99. package/src/Annotator/bike-pic2.png +0 -0
  100. package/src/Annotator/dab-keyframes.story.json +0 -1
  101. package/src/Annotator/examplePhotos.js +0 -7601
  102. package/src/Annotator/index.js +0 -291
  103. package/src/Annotator/index.story.js +0 -807
  104. package/src/Annotator/poses.story.js +0 -150
  105. package/src/Annotator/reducers/combine-reducers.js +0 -7
  106. package/src/Annotator/reducers/convert-expanding-line-to-polygon.js +0 -53
  107. package/src/Annotator/reducers/general-reducer.js +0 -996
  108. package/src/Annotator/reducers/get-active-image.js +0 -21
  109. package/src/Annotator/reducers/get-implied-video-regions.js +0 -115
  110. package/src/Annotator/reducers/history-handler.js +0 -60
  111. package/src/Annotator/reducers/image-reducer.js +0 -23
  112. package/src/Annotator/reducers/video-reducer.js +0 -85
  113. package/src/Annotator/video.story.js +0 -51
  114. package/src/ClassSelectionMenu/index.js +0 -108
  115. package/src/Crosshairs/index.js +0 -64
  116. package/src/DebugSidebarBox/index.js +0 -36
  117. package/src/DemoSite/Editor.js +0 -235
  118. package/src/DemoSite/ErrorBoundaryDialog.js +0 -34
  119. package/src/DemoSite/index.js +0 -41
  120. package/src/DemoSite/index.story.js +0 -10
  121. package/src/DemoSite/simple-segmentation-example.json +0 -572
  122. package/src/Editor/annotation-plugin/annotation.js +0 -515
  123. package/src/Editor/index.js +0 -24
  124. package/src/FullImageSegmentationAnnotator/hard1.story.jpg +0 -0
  125. package/src/FullImageSegmentationAnnotator/hard2.story.jpg +0 -0
  126. package/src/FullImageSegmentationAnnotator/hard3.story.jpg +0 -0
  127. package/src/FullImageSegmentationAnnotator/index.js +0 -7
  128. package/src/FullImageSegmentationAnnotator/index.story.js +0 -177
  129. package/src/FullImageSegmentationAnnotator/orange.story.png +0 -0
  130. package/src/GroupSelectorSidebarBox/index.js +0 -48
  131. package/src/HighlightBox/index.js +0 -143
  132. package/src/HistorySidebarBox/index.js +0 -78
  133. package/src/ImageCanvas/dancing-man.story.jpg +0 -0
  134. package/src/ImageCanvas/index.js +0 -494
  135. package/src/ImageCanvas/index.story.js +0 -314
  136. package/src/ImageCanvas/mouse_mask.story.png +0 -0
  137. package/src/ImageCanvas/region-tools.js +0 -171
  138. package/src/ImageCanvas/seves_desk.story.jpg +0 -0
  139. package/src/ImageCanvas/use-mouse.js +0 -168
  140. package/src/ImageCanvas/use-project-box.js +0 -23
  141. package/src/ImageCanvas/use-wasd-mode.js +0 -50
  142. package/src/ImageMask/index.js +0 -127
  143. package/src/ImageMask/load-image.js +0 -32
  144. package/src/ImageSelectorSidebarBox/index.js +0 -54
  145. package/src/KeyframeTimeline/get-time-string.js +0 -25
  146. package/src/KeyframeTimeline/index.js +0 -223
  147. package/src/KeyframesSelectorSidebarBox/index.js +0 -93
  148. package/src/LandingPage/content.md +0 -57
  149. package/src/LandingPage/github-markdown.css +0 -964
  150. package/src/LandingPage/index.js +0 -147
  151. package/src/MainLayout/icon-dictionary.js +0 -79
  152. package/src/MainLayout/index.js +0 -510
  153. package/src/MainLayout/index.story.js +0 -240
  154. package/src/MainLayout/types.js +0 -164
  155. package/src/MainLayout/use-implied-video-regions.js +0 -17
  156. package/src/MetadataEditorSidebarBox/index.js +0 -98
  157. package/src/PageSelector/index.js +0 -76
  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,93 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useState, memo } from "react";
3
+ import Paper from "@mui/material/Paper";
4
+ import { makeStyles } from "@mui/styles";
5
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
6
+ import ExpandIcon from "@mui/icons-material/ExpandMore";
7
+ import IconButton from "@mui/material/IconButton";
8
+ import Collapse from "@mui/material/Collapse";
9
+ import { grey } from "@mui/material/colors";
10
+ import classnames from "classnames";
11
+ import useEventCallback from "use-event-callback";
12
+ import SidebarBox from "react-material-workspace-layout/SidebarBox";
13
+ var theme = createTheme();
14
+ var useStyles = makeStyles(function (theme) {
15
+ return {
16
+ container: {
17
+ margin: 8
18
+ },
19
+ header: {
20
+ display: "flex",
21
+ flexDirection: "row",
22
+ alignItems: "center",
23
+ padding: 8,
24
+ paddingLeft: 16,
25
+ paddingRight: 16
26
+ },
27
+ title: {
28
+ fontSize: 14,
29
+ fontWeight: "bold",
30
+ flexGrow: 1,
31
+ paddingLeft: 8,
32
+ color: grey[800],
33
+ "& span": {
34
+ color: grey[600],
35
+ fontSize: 12
36
+ }
37
+ },
38
+ expandButton: {
39
+ padding: 0,
40
+ width: 30,
41
+ height: 30,
42
+ "& .icon": {
43
+ marginTop: -6,
44
+ width: 20,
45
+ height: 20,
46
+ transition: "500ms transform",
47
+ "&.expanded": {
48
+ transform: "rotate(180deg)"
49
+ }
50
+ }
51
+ },
52
+ expandedContent: {
53
+ maxHeight: 300,
54
+ overflowY: "auto",
55
+ "&.noScroll": {
56
+ overflowY: "visible",
57
+ overflow: "visible"
58
+ }
59
+ }
60
+ };
61
+ });
62
+ export var SidebarBoxContainer = function SidebarBoxContainer(_ref) {
63
+ var icon = _ref.icon,
64
+ title = _ref.title,
65
+ subTitle = _ref.subTitle,
66
+ children = _ref.children,
67
+ _ref$noScroll = _ref.noScroll,
68
+ noScroll = _ref$noScroll === void 0 ? false : _ref$noScroll,
69
+ _ref$expandedByDefaul = _ref.expandedByDefault,
70
+ expandedByDefault = _ref$expandedByDefaul === void 0 ? false : _ref$expandedByDefaul;
71
+ var classes = useStyles();
72
+ var content = React.createElement("div", {
73
+ className: classnames(classes.expandedContent, noScroll && "noScroll")
74
+ }, children);
75
+
76
+ var _useState = useState(expandedByDefault),
77
+ _useState2 = _slicedToArray(_useState, 2),
78
+ expanded = _useState2[0],
79
+ changeExpanded = _useState2[1];
80
+
81
+ var toggleExpanded = useEventCallback(function () {
82
+ return changeExpanded(!expanded);
83
+ });
84
+ return React.createElement(ThemeProvider, {
85
+ theme: theme
86
+ }, React.createElement(SidebarBox, {
87
+ icon: icon,
88
+ title: title
89
+ }, children));
90
+ };
91
+ export default memo(SidebarBoxContainer, function (prev, next) {
92
+ return prev.title === next.title && prev.children === next.children;
93
+ });
@@ -0,0 +1,42 @@
1
+ import React, { createContext, useContext, memo } from "react";
2
+ import IconButton from "@mui/material/IconButton";
3
+ import Tooltip from "@mui/material/Tooltip";
4
+ import { blue } from "@mui/material/colors";
5
+ export var SelectedTool = createContext();
6
+ export var SmallToolButton = function SmallToolButton(_ref) {
7
+ var id = _ref.id,
8
+ name = _ref.name,
9
+ icon = _ref.icon,
10
+ selected = _ref.selected,
11
+ togglable = _ref.togglable,
12
+ _ref$alwaysShowing = _ref.alwaysShowing,
13
+ alwaysShowing = _ref$alwaysShowing === void 0 ? false : _ref$alwaysShowing;
14
+
15
+ var _useContext = useContext(SelectedTool),
16
+ enabledTools = _useContext.enabledTools,
17
+ selectedTool = _useContext.selectedTool,
18
+ onClickTool = _useContext.onClickTool;
19
+
20
+ if (!enabledTools.includes(id) && !alwaysShowing) return null;
21
+ selected = selected || selectedTool === id;
22
+ return React.createElement(Tooltip, {
23
+ placement: "right",
24
+ title: name
25
+ }, React.createElement("div", null, React.createElement(IconButton, {
26
+ disabled: !togglable ? selected : undefined,
27
+ "aria-label": name,
28
+ onClick: function onClick() {
29
+ return onClickTool(id);
30
+ },
31
+ size: "small",
32
+ style: {
33
+ width: 50,
34
+ height: 50,
35
+ margin: 1,
36
+ color: selected ? blue[500] : undefined
37
+ }
38
+ }, icon)));
39
+ };
40
+ export default memo(SmallToolButton, function (prevProps, nextProps) {
41
+ return prevProps.togglable === nextProps.togglable && prevProps.selected === nextProps.selected && prevProps.name === nextProps.name && prevProps.id === nextProps.id;
42
+ });
@@ -0,0 +1,105 @@
1
+ import React, { useMemo, memo } from "react";
2
+ import SidebarBoxContainer from "../SidebarBoxContainer";
3
+ import StyleIcon from "@mui/icons-material/Style";
4
+ import { grey } from "@mui/material/colors";
5
+ import Select from "react-select";
6
+ import useEventCallback from "use-event-callback";
7
+ import { asMutable } from "seamless-immutable";
8
+ var emptyArr = [];
9
+
10
+ var noop = function noop() {
11
+ return null;
12
+ };
13
+
14
+ export var TagsSidebarBox = function TagsSidebarBox(_ref) {
15
+ var currentImage = _ref.currentImage,
16
+ _ref$imageClsList = _ref.imageClsList,
17
+ imageClsList = _ref$imageClsList === void 0 ? emptyArr : _ref$imageClsList,
18
+ _ref$imageTagList = _ref.imageTagList,
19
+ imageTagList = _ref$imageTagList === void 0 ? emptyArr : _ref$imageTagList,
20
+ _ref$onChangeImage = _ref.onChangeImage,
21
+ onChangeImage = _ref$onChangeImage === void 0 ? noop : _ref$onChangeImage;
22
+
23
+ var _ref2 = currentImage || {},
24
+ _ref2$tags = _ref2.tags,
25
+ tags = _ref2$tags === void 0 ? [] : _ref2$tags,
26
+ _ref2$cls = _ref2.cls,
27
+ cls = _ref2$cls === void 0 ? null : _ref2$cls;
28
+
29
+ var onChangeClassification = useEventCallback(function (o) {
30
+ return onChangeImage({
31
+ cls: o.value
32
+ });
33
+ });
34
+ var onChangeTags = useEventCallback(function (o) {
35
+ return onChangeImage({
36
+ tags: o.map(function (a) {
37
+ return a.value;
38
+ })
39
+ });
40
+ });
41
+ var selectValue = useMemo(function () {
42
+ return cls ? {
43
+ value: cls,
44
+ label: cls
45
+ } : null;
46
+ }, [cls]);
47
+ var memoImgClsList = useMemo(function () {
48
+ return asMutable(imageClsList.map(function (c) {
49
+ return {
50
+ value: c,
51
+ label: c
52
+ };
53
+ }));
54
+ }, [imageClsList]);
55
+ var memoImgTagList = useMemo(function () {
56
+ return asMutable(imageTagList.map(function (c) {
57
+ return {
58
+ value: c,
59
+ label: c
60
+ };
61
+ }));
62
+ }, [imageTagList]);
63
+ var memoCurrentTags = useMemo(function () {
64
+ return tags.map(function (r) {
65
+ return {
66
+ value: r,
67
+ label: r
68
+ };
69
+ });
70
+ }, [tags]);
71
+ if (!currentImage) return null;
72
+ return React.createElement(SidebarBoxContainer, {
73
+ title: "Image Tags",
74
+ expandedByDefault: true,
75
+ noScroll: true,
76
+ icon: React.createElement(StyleIcon, {
77
+ style: {
78
+ color: grey[700]
79
+ }
80
+ })
81
+ }, imageClsList.length > 0 && React.createElement("div", {
82
+ style: {
83
+ padding: 8
84
+ }
85
+ }, React.createElement(Select, {
86
+ placeholder: "Image Classification",
87
+ onChange: onChangeClassification,
88
+ value: selectValue,
89
+ options: memoImgClsList
90
+ })), imageTagList.length > 0 && React.createElement("div", {
91
+ style: {
92
+ padding: 8,
93
+ paddingTop: 0
94
+ }
95
+ }, React.createElement(Select, {
96
+ isMulti: true,
97
+ placeholder: "Image Tags",
98
+ onChange: onChangeTags,
99
+ value: memoCurrentTags,
100
+ options: memoImgTagList
101
+ })));
102
+ };
103
+ export default memo(TagsSidebarBox, function (prevProps, nextProps) {
104
+ return prevProps.currentImage.cls === nextProps.currentImage.cls && prevProps.currentImage.tags === nextProps.currentImage.tags && prevProps.imageClsList === nextProps.imageClsList && prevProps.imageTagList === nextProps.imageTagList;
105
+ });
@@ -0,0 +1,58 @@
1
+ import React, { memo } from "react";
2
+ import SidebarBoxContainer from "../SidebarBoxContainer";
3
+ import DescriptionIcon from "@mui/icons-material/Description";
4
+ import { styled } from "@mui/material/styles";
5
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
6
+ import { grey } from "@mui/material/colors";
7
+ import Markdown from "react-markdown";
8
+ var theme = createTheme();
9
+ var MarkdownContainer = styled("div")(function (_ref) {
10
+ var theme = _ref.theme;
11
+ return {
12
+ paddingLeft: 16,
13
+ paddingRight: 16,
14
+ fontSize: 12,
15
+ "& h1": {
16
+ fontSize: 18
17
+ },
18
+ "& h2": {
19
+ fontSize: 14
20
+ },
21
+ "& h3": {
22
+ fontSize: 12
23
+ },
24
+ "& h4": {
25
+ fontSize: 12
26
+ },
27
+ "& h5": {
28
+ fontSize: 12
29
+ },
30
+ "& h6": {
31
+ fontSize: 12
32
+ },
33
+ "& p": {
34
+ fontSize: 12
35
+ },
36
+ "& a": {},
37
+ "& img": {
38
+ width: "100%"
39
+ }
40
+ };
41
+ });
42
+ export var TaskDescriptionSidebarBox = function TaskDescriptionSidebarBox(_ref2) {
43
+ var description = _ref2.description;
44
+ return React.createElement(ThemeProvider, {
45
+ theme: theme
46
+ }, React.createElement(SidebarBoxContainer, {
47
+ title: "Task Description",
48
+ icon: React.createElement(DescriptionIcon, {
49
+ style: {
50
+ color: grey[700]
51
+ }
52
+ }),
53
+ expandedByDefault: description && description !== "" ? false : true
54
+ }, React.createElement(MarkdownContainer, null, React.createElement(Markdown, {
55
+ source: description
56
+ }))));
57
+ };
58
+ export default memo(TaskDescriptionSidebarBox);
package/Theme/index.js ADDED
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { ThemeProvider, createTheme } from "@mui/material/styles";
3
+ import { makeStyles } from "@mui/styles";
4
+ var useStyles = makeStyles(function (theme) {
5
+ return {
6
+ container: {
7
+ fontFamily: '"Inter", sans-serif'
8
+ }
9
+ };
10
+ });
11
+ var theme = createTheme({
12
+ typography: {
13
+ fontFamily: '"Inter", "Roboto", sans-serif'
14
+ },
15
+ overrides: {
16
+ MuiButton: {
17
+ root: {
18
+ textTransform: "none"
19
+ }
20
+ }
21
+ }
22
+ });
23
+ export var Theme = function Theme(_ref) {
24
+ var children = _ref.children;
25
+ var classes = useStyles();
26
+ return React.createElement(ThemeProvider, {
27
+ theme: theme
28
+ }, React.createElement("div", null, children));
29
+ };
30
+ export default Theme;
@@ -0,0 +1,151 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import React, { useRef, useEffect, useMemo, useState } from "react";
3
+ import { styled } from "@mui/material/styles";
4
+ import { createTheme, ThemeProvider } from "@mui/material/styles";
5
+ import useEventCallback from "use-event-callback";
6
+ import { useSettings } from "../SettingsProvider";
7
+ var theme = createTheme();
8
+ var Video = styled("video")(function (_ref) {
9
+ var theme = _ref.theme;
10
+ return {
11
+ zIndex: 0,
12
+ position: "absolute"
13
+ };
14
+ });
15
+ var StyledImage = styled("img")(function (_ref2) {
16
+ var theme = _ref2.theme;
17
+ return {
18
+ zIndex: 0,
19
+ position: "absolute"
20
+ };
21
+ });
22
+ var Error = styled("div")(function (_ref3) {
23
+ var theme = _ref3.theme;
24
+ return {
25
+ zIndex: 0,
26
+ position: "absolute",
27
+ left: 0,
28
+ right: 0,
29
+ bottom: 0,
30
+ top: 0,
31
+ backgroundColor: "rgba(255,0,0,0.2)",
32
+ color: "#ff0000",
33
+ fontWeight: "bold",
34
+ whiteSpace: "pre-wrap",
35
+ padding: 50
36
+ };
37
+ });
38
+ export default (function (_ref4) {
39
+ var imagePosition = _ref4.imagePosition,
40
+ mouseEvents = _ref4.mouseEvents,
41
+ videoTime = _ref4.videoTime,
42
+ videoSrc = _ref4.videoSrc,
43
+ imageSrc = _ref4.imageSrc,
44
+ onLoad = _ref4.onLoad,
45
+ _ref4$useCrossOrigin = _ref4.useCrossOrigin,
46
+ useCrossOrigin = _ref4$useCrossOrigin === void 0 ? false : _ref4$useCrossOrigin,
47
+ videoPlaying = _ref4.videoPlaying,
48
+ onChangeVideoTime = _ref4.onChangeVideoTime,
49
+ onChangeVideoPlaying = _ref4.onChangeVideoPlaying;
50
+ var settings = useSettings();
51
+ var videoRef = useRef();
52
+ var imageRef = useRef();
53
+
54
+ var _useState = useState(),
55
+ _useState2 = _slicedToArray(_useState, 2),
56
+ error = _useState2[0],
57
+ setError = _useState2[1];
58
+
59
+ useEffect(function () {
60
+ if (!videoPlaying && videoRef.current) {
61
+ videoRef.current.currentTime = (videoTime || 0) / 1000;
62
+ }
63
+ }, [videoTime]);
64
+ useEffect(function () {
65
+ var renderLoopRunning = false;
66
+
67
+ if (videoRef.current) {
68
+ if (videoPlaying) {
69
+ videoRef.current.play();
70
+ renderLoopRunning = true;
71
+
72
+ if (settings.videoPlaybackSpeed) {
73
+ videoRef.current.playbackRate = parseFloat(settings.videoPlaybackSpeed);
74
+ }
75
+ } else {
76
+ videoRef.current.pause();
77
+ }
78
+ }
79
+
80
+ function checkForNewFrame() {
81
+ if (!renderLoopRunning) return;
82
+ if (!videoRef.current) return;
83
+ var newVideoTime = Math.floor(videoRef.current.currentTime * 1000);
84
+
85
+ if (videoTime !== newVideoTime) {
86
+ onChangeVideoTime(newVideoTime);
87
+ }
88
+
89
+ if (videoRef.current.paused) {
90
+ renderLoopRunning = false;
91
+ onChangeVideoPlaying(false);
92
+ }
93
+
94
+ requestAnimationFrame(checkForNewFrame);
95
+ }
96
+
97
+ checkForNewFrame();
98
+ return function () {
99
+ renderLoopRunning = false;
100
+ };
101
+ }, [videoPlaying]);
102
+ var onLoadedVideoMetadata = useEventCallback(function (event) {
103
+ var videoElm = event.currentTarget;
104
+ videoElm.currentTime = (videoTime || 0) / 1000;
105
+ if (onLoad) onLoad({
106
+ naturalWidth: videoElm.videoWidth,
107
+ naturalHeight: videoElm.videoHeight,
108
+ videoElm: videoElm,
109
+ duration: videoElm.duration
110
+ });
111
+ });
112
+ var onImageLoaded = useEventCallback(function (event) {
113
+ var imageElm = event.currentTarget;
114
+ if (onLoad) onLoad({
115
+ naturalWidth: imageElm.naturalWidth,
116
+ naturalHeight: imageElm.naturalHeight,
117
+ imageElm: imageElm
118
+ });
119
+ });
120
+ var onImageError = useEventCallback(function (event) {
121
+ setError("Could not load image\n\nMake sure your image works by visiting ".concat(imageSrc || videoSrc, " in a web browser. If that URL works, the server hosting the URL may be not allowing you to access the image from your current domain. Adjust server settings to enable the image to be viewed.").concat(!useCrossOrigin ? "" : "\n\nYour image may be blocked because it's not being sent with CORs headers. To do pixel segmentation, browser web security requires CORs headers in order for the algorithm to read the pixel data from the image. CORs headers are easy to add if you're using an S3 bucket or own the server hosting your images.", "\n\n If you need a hand, reach out to the community at universaldatatool.slack.com"));
122
+ });
123
+ var stylePosition = useMemo(function () {
124
+ var width = imagePosition.bottomRight.x - imagePosition.topLeft.x;
125
+ var height = imagePosition.bottomRight.y - imagePosition.topLeft.y;
126
+ return {
127
+ imageRendering: "pixelated",
128
+ left: imagePosition.topLeft.x,
129
+ top: imagePosition.topLeft.y,
130
+ width: isNaN(width) ? 0 : width,
131
+ height: isNaN(height) ? 0 : height
132
+ };
133
+ }, [imagePosition.topLeft.x, imagePosition.topLeft.y, imagePosition.bottomRight.x, imagePosition.bottomRight.y]);
134
+ if (!videoSrc && !imageSrc) return React.createElement(Error, null, "No imageSrc or videoSrc provided");
135
+ if (error) return React.createElement(Error, null, error);
136
+ return React.createElement(ThemeProvider, {
137
+ theme: theme
138
+ }, imageSrc && videoTime === undefined ? React.createElement(StyledImage, Object.assign({}, mouseEvents, {
139
+ src: imageSrc,
140
+ ref: imageRef,
141
+ style: stylePosition,
142
+ onLoad: onImageLoaded,
143
+ onError: onImageError,
144
+ crossOrigin: useCrossOrigin ? "anonymous" : undefined
145
+ })) : React.createElement(Video, Object.assign({}, mouseEvents, {
146
+ ref: videoRef,
147
+ style: stylePosition,
148
+ onLoadedMetadata: onLoadedVideoMetadata,
149
+ src: videoSrc || imageSrc
150
+ })));
151
+ });
package/colors.js ADDED
@@ -0,0 +1,14 @@
1
+ import * as muiColors from "@mui/material/colors";
2
+ export var colors = [muiColors.red[500], muiColors.blue[500], muiColors.green[500], muiColors.orange[800], muiColors.brown[500], muiColors.lightGreen[700], muiColors.pink[500], muiColors.purple[500], muiColors.indigo[500], muiColors.teal[500], muiColors.lime[500], muiColors.blueGrey[500]];
3
+ var transparency = 0x88000000;
4
+
5
+ function reverseParseColor(rrggbb) {
6
+ rrggbb = rrggbb.replace("#", "");
7
+ var bbggrr = rrggbb.substr(4, 2) + rrggbb.substr(2, 2) + rrggbb.substr(0, 2);
8
+ return parseInt(bbggrr, 16);
9
+ }
10
+
11
+ export var colorInts = colors.map(function (c) {
12
+ return (reverseParseColor(c) | transparency) >>> 0;
13
+ });
14
+ export default colors;
@@ -0,0 +1,101 @@
1
+ import { useSettings } from "../SettingsProvider";
2
+
3
+ function defaultClsColor(cls) {
4
+ switch (cls) {
5
+ case 'title':
6
+ return '#f70202';
7
+
8
+ case 'subtitle':
9
+ return "#ffb405";
10
+
11
+ case 'text':
12
+ return "#14deef";
13
+
14
+ case 'author':
15
+ return "#f8d51e";
16
+
17
+ case 'appendix':
18
+ return "#bfede2";
19
+
20
+ case 'photo_author':
21
+ return "#9a17bb";
22
+
23
+ case 'photo_caption':
24
+ return "#ff84f6";
25
+
26
+ case 'advertisement':
27
+ return "#ffb201";
28
+
29
+ case 'other_graphics':
30
+ return "#ff5400";
31
+
32
+ case 'unknown':
33
+ return "#bfede2";
34
+
35
+ case 'about_author':
36
+ return "#9a17bb";
37
+
38
+ case 'image':
39
+ return "#14deef";
40
+
41
+ case 'interview':
42
+ return "#23b20f";
43
+
44
+ case 'table':
45
+ return "#02b4ba";
46
+
47
+ default:
48
+ return "#02b4ba";
49
+ }
50
+ }
51
+
52
+ function defaultGroupColor(groupId) {
53
+ switch (groupId) {
54
+ case "0":
55
+ return "#FDDFDF";
56
+
57
+ case "1":
58
+ return "#FCF7DE";
59
+
60
+ case "2":
61
+ return "#DEFDE0";
62
+
63
+ case "3":
64
+ return "#DEF3FD";
65
+
66
+ case "4":
67
+ return "#F0DEFD";
68
+
69
+ default:
70
+ return "#F0DEFD";
71
+ }
72
+ }
73
+
74
+ var useColors = function useColors() {
75
+ var _useSettings = useSettings(),
76
+ clsColors = _useSettings.clsColors,
77
+ groupColors = _useSettings.groupColors;
78
+
79
+ var clsColor = function clsColor(cls) {
80
+ if (clsColors[cls]) {
81
+ return clsColors[cls];
82
+ }
83
+
84
+ return defaultClsColor(cls);
85
+ };
86
+
87
+ var groupColor = function groupColor(groupId) {
88
+ if (groupColors[groupId]) {
89
+ return groupColors[groupId];
90
+ }
91
+
92
+ return defaultGroupColor(groupId);
93
+ };
94
+
95
+ return {
96
+ clsColor: clsColor,
97
+ groupColor: groupColor
98
+ };
99
+ };
100
+
101
+ export default useColors;
@@ -0,0 +1,10 @@
1
+ import { useRef, useCallback, useLayoutEffect, useEffect } from "react";
2
+ export default (function (fn) {
3
+ var ref = useRef();
4
+ useLayoutEffect(function () {
5
+ ref.current = fn;
6
+ });
7
+ return useCallback(function () {
8
+ return (0, ref.current).apply(void 0, arguments);
9
+ }, []);
10
+ });
@@ -0,0 +1,24 @@
1
+ import { useRef } from "react";
2
+ import excludePatternSrc from "./xpattern.js";
3
+ export default (function () {
4
+ var excludePattern = useRef(null);
5
+
6
+ if (excludePattern.current === null) {
7
+ excludePattern.current = {
8
+ image: new Image(),
9
+ pattern: null
10
+ };
11
+ var canvas = document.createElement("canvas");
12
+ canvas.width = 100;
13
+ canvas.height = 100;
14
+ var context = canvas.getContext("2d");
15
+
16
+ excludePattern.current.image.onload = function () {
17
+ excludePattern.current.pattern = context.createPattern(excludePattern.current.image, "repeat");
18
+ };
19
+
20
+ excludePattern.current.image.src = excludePatternSrc;
21
+ }
22
+
23
+ return excludePattern.current.pattern;
24
+ });
@@ -0,0 +1,26 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import { useRef, useState } from "react";
3
+ export default (function (imageSrc, onImageLoaded) {
4
+ var _useState = useState(false),
5
+ _useState2 = _slicedToArray(_useState, 2),
6
+ imageLoaded = _useState2[0],
7
+ changeImageLoaded = _useState2[1];
8
+
9
+ var image = useRef(null);
10
+
11
+ if (image.current === null) {
12
+ image.current = new Image();
13
+
14
+ image.current.onload = function () {
15
+ changeImageLoaded(true);
16
+ if (onImageLoaded) onImageLoaded({
17
+ width: image.current.naturalWidth,
18
+ height: image.current.naturalHeight
19
+ });
20
+ };
21
+
22
+ image.current.src = imageSrc;
23
+ }
24
+
25
+ return [image.current, imageLoaded];
26
+ });