@abidibo/react-cam-roi 0.0.12 → 0.1.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 (93) hide show
  1. package/README.md +44 -29
  2. package/package.json +29 -2
  3. package/dist/Components/BoolField/BoolField.module.css +0 -60
  4. package/dist/Components/BoolField/index.d.ts +0 -5
  5. package/dist/Components/BoolField/index.js +0 -13
  6. package/dist/Components/Button/Button.module.css +0 -27
  7. package/dist/Components/Button/index.d.ts +0 -8
  8. package/dist/Components/Button/index.js +0 -15
  9. package/dist/Components/EnumField/EnumField.module.css +0 -61
  10. package/dist/Components/EnumField/index.d.ts +0 -10
  11. package/dist/Components/EnumField/index.js +0 -16
  12. package/dist/Components/IconButton/IconButton.module.css +0 -20
  13. package/dist/Components/IconButton/index.d.ts +0 -7
  14. package/dist/Components/IconButton/index.js +0 -10
  15. package/dist/Components/Loader/Loader.module.css +0 -25
  16. package/dist/Components/Loader/index.d.ts +0 -1
  17. package/dist/Components/Loader/index.js +0 -9
  18. package/dist/Components/Modal/Modal.module.css +0 -92
  19. package/dist/Components/Modal/index.d.ts +0 -10
  20. package/dist/Components/Modal/index.js +0 -16
  21. package/dist/Components/NumberField/NumberField.module.css +0 -60
  22. package/dist/Components/NumberField/index.d.ts +0 -3
  23. package/dist/Components/NumberField/index.js +0 -13
  24. package/dist/Components/RoiEditor/Canvas.d.ts +0 -10
  25. package/dist/Components/RoiEditor/Canvas.js +0 -28
  26. package/dist/Components/RoiEditor/ColorPicker.d.ts +0 -5
  27. package/dist/Components/RoiEditor/ColorPicker.js +0 -12
  28. package/dist/Components/RoiEditor/ColorPicker.module.css +0 -17
  29. package/dist/Components/RoiEditor/Hooks.d.ts +0 -35
  30. package/dist/Components/RoiEditor/Hooks.js +0 -320
  31. package/dist/Components/RoiEditor/ParameterField.d.ts +0 -9
  32. package/dist/Components/RoiEditor/ParameterField.js +0 -27
  33. package/dist/Components/RoiEditor/ParametersModalForm/ParametersModalForm.module.css +0 -5
  34. package/dist/Components/RoiEditor/ParametersModalForm/index.d.ts +0 -10
  35. package/dist/Components/RoiEditor/ParametersModalForm/index.js +0 -31
  36. package/dist/Components/RoiEditor/Polygon.d.ts +0 -18
  37. package/dist/Components/RoiEditor/Polygon.js +0 -76
  38. package/dist/Components/RoiEditor/Polyline.d.ts +0 -28
  39. package/dist/Components/RoiEditor/Polyline.js +0 -74
  40. package/dist/Components/RoiEditor/Rectangle.d.ts +0 -21
  41. package/dist/Components/RoiEditor/Rectangle.js +0 -72
  42. package/dist/Components/RoiEditor/RoiEditor.module.css +0 -5
  43. package/dist/Components/RoiEditor/ShapesList.d.ts +0 -2
  44. package/dist/Components/RoiEditor/ShapesList.js +0 -47
  45. package/dist/Components/RoiEditor/ShapesList.module.css +0 -36
  46. package/dist/Components/RoiEditor/Toolbar.d.ts +0 -2
  47. package/dist/Components/RoiEditor/Toolbar.js +0 -33
  48. package/dist/Components/RoiEditor/Toolbar.module.css +0 -53
  49. package/dist/Components/RoiEditor/Types.d.ts +0 -115
  50. package/dist/Components/RoiEditor/Types.js +0 -15
  51. package/dist/Components/RoiEditor/Utils.d.ts +0 -22
  52. package/dist/Components/RoiEditor/Utils.js +0 -143
  53. package/dist/Components/RoiEditor/index.d.ts +0 -10
  54. package/dist/Components/RoiEditor/index.js +0 -74
  55. package/dist/Components/TextField/TextField.module.css +0 -61
  56. package/dist/Components/TextField/index.d.ts +0 -6
  57. package/dist/Components/TextField/index.js +0 -13
  58. package/dist/Components/Typography/index.d.ts +0 -9
  59. package/dist/Components/Typography/index.js +0 -6
  60. package/dist/Icons/AnnotateIcon.d.ts +0 -6
  61. package/dist/Icons/AnnotateIcon.js +0 -5
  62. package/dist/Icons/CloseIcon.d.ts +0 -6
  63. package/dist/Icons/CloseIcon.js +0 -5
  64. package/dist/Icons/CopyIcon.d.ts +0 -6
  65. package/dist/Icons/CopyIcon.js +0 -5
  66. package/dist/Icons/DeleteIcon.d.ts +0 -6
  67. package/dist/Icons/DeleteIcon.js +0 -5
  68. package/dist/Icons/EditIcon.d.ts +0 -6
  69. package/dist/Icons/EditIcon.js +0 -5
  70. package/dist/Icons/PointerIcon.d.ts +0 -6
  71. package/dist/Icons/PointerIcon.js +0 -5
  72. package/dist/Icons/PolygonIcon.d.ts +0 -6
  73. package/dist/Icons/PolygonIcon.js +0 -5
  74. package/dist/Icons/PolylineIcon.d.ts +0 -6
  75. package/dist/Icons/PolylineIcon.js +0 -5
  76. package/dist/Icons/RectangleIcon.d.ts +0 -6
  77. package/dist/Icons/RectangleIcon.js +0 -5
  78. package/dist/Icons/SaveIcon.d.ts +0 -6
  79. package/dist/Icons/SaveIcon.js +0 -5
  80. package/dist/Icons/SelectIcon.d.ts +0 -6
  81. package/dist/Icons/SelectIcon.js +0 -5
  82. package/dist/Providers/EditorProvider.d.ts +0 -26
  83. package/dist/Providers/EditorProvider.js +0 -29
  84. package/dist/Providers/UiProvider.d.ts +0 -73
  85. package/dist/Providers/UiProvider.js +0 -95
  86. package/dist/Types.d.ts +0 -10
  87. package/dist/Types.js +0 -1
  88. package/dist/Utils/Dispatcher.d.ts +0 -16
  89. package/dist/Utils/Dispatcher.js +0 -65
  90. package/dist/Utils/index.d.ts +0 -2
  91. package/dist/Utils/index.js +0 -2
  92. package/dist/index.d.ts +0 -4
  93. package/dist/index.js +0 -4
@@ -1,76 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { v4 as uuidv4 } from 'uuid';
3
- const addPoint = (event, canvas, color, points, setPoints, lines, setLines) => {
4
- const pointer = canvas.getScenePoint(event.e);
5
- const newPoint = { x: pointer.x, y: pointer.y };
6
- const newPolygonPoints = [...points, newPoint];
7
- setPoints(newPolygonPoints);
8
- if (newPolygonPoints.length > 0) {
9
- const line = new fabric.Line([
10
- newPolygonPoints[newPolygonPoints.length - 1].x,
11
- newPolygonPoints[newPolygonPoints.length - 1].y,
12
- pointer.x,
13
- pointer.y,
14
- ], {
15
- stroke: color,
16
- strokeWidth: 2,
17
- strokeUniform: true,
18
- selectable: false,
19
- hasControls: false,
20
- });
21
- canvas.add(line);
22
- setLines([...lines, line]);
23
- }
24
- };
25
- export const handleMouseDownPolygon = (event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
26
- setIsDrawing(true);
27
- addPoint(event, canvas, activeColor, points, setPoints, lines, setLines);
28
- };
29
- export const handleMouseMovePolygon = (event, canvas, isDrawing, lines) => {
30
- if (isDrawing && lines.length > 0) {
31
- const pointer = canvas.getScenePoint(event.e);
32
- lines[lines.length - 1].set({ x2: pointer.x, y2: pointer.y });
33
- canvas.renderAll();
34
- }
35
- };
36
- export const handleDoubleClickPolygon = (canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines, addShape) => {
37
- if (points.length > 2) {
38
- const id = uuidv4();
39
- const polygon = new fabric.Polygon(points, {
40
- fill: 'transparent',
41
- stroke: activeColor,
42
- strokeWidth: 2,
43
- selectable: false,
44
- hasControls: true,
45
- hoverCursor: 'default',
46
- // @ts-expect-error id is not included in types but the property is added and it works
47
- id,
48
- });
49
- canvas.add(polygon);
50
- addShape(polygon.id, "polygon" /* ToolEnum.Polygon */, polygon);
51
- setPoints([]);
52
- for (const line of lines) {
53
- canvas.remove(line); // Remove temporary lines
54
- }
55
- setLines([]);
56
- setIsDrawing(false);
57
- }
58
- };
59
- export const copyPolygon = (canvas, polygon, addShape) => {
60
- const id = uuidv4();
61
- const copy = new fabric.Polygon(polygon.points, {
62
- top: polygon.top + 10,
63
- left: polygon.left + 10,
64
- fill: 'transparent',
65
- stroke: polygon.stroke,
66
- strokeWidth: polygon.strokeWidth,
67
- selectable: false,
68
- hasControls: true,
69
- hoverCursor: 'default',
70
- // @ts-expect-error id is not included in types but the property is added and it works
71
- id,
72
- });
73
- canvas.add(copy);
74
- addShape(id, "polygon" /* ToolEnum.Polygon */, copy);
75
- return copy;
76
- };
@@ -1,28 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { FabricEvent, IAddShape, ShapeType } from './Types';
3
- export declare const handleMouseDownPolyline: (event: FabricEvent, canvas: fabric.Canvas, activeColor: string, setIsDrawing: (v: boolean) => void, points: {
4
- x: number;
5
- y: number;
6
- }[], setPoints: (v: {
7
- x: number;
8
- y: number;
9
- }[]) => void, lines: fabric.Line[], setLines: (v: fabric.Line[]) => void) => void;
10
- export declare const handleMouseMovePolyline: (event: FabricEvent, canvas: fabric.Canvas, isDrawing: boolean, lines: fabric.Line[]) => void;
11
- export declare const handleDoubleClickPolyline: (canvas: fabric.Canvas, activeColor: string, setIsDrawing: (v: boolean) => void, points: {
12
- x: number;
13
- y: number;
14
- }[], setPoints: (v: {
15
- x: number;
16
- y: number;
17
- }[]) => void, lines: fabric.Line[], setLines: (v: fabric.Line[]) => void, addShape: (id: string, type: ShapeType, shape: fabric.Polyline) => void) => void;
18
- export declare const copyPolyline: (canvas: fabric.Canvas, polyline: fabric.Polyline, addShape: IAddShape) => fabric.Polyline<{
19
- top: number;
20
- left: number;
21
- fill: string;
22
- stroke: string | fabric.TFiller | null;
23
- strokeWidth: number;
24
- selectable: false;
25
- hasControls: true;
26
- hoverCursor: string;
27
- id: string;
28
- }, fabric.SerializedPolylineProps, fabric.ObjectEvents>;
@@ -1,74 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { v4 as uuidv4 } from 'uuid';
3
- const addPoint = (event, canvas, color, points, setPoints, lines, setLines) => {
4
- const pointer = canvas.getScenePoint(event.e);
5
- const newPoint = { x: pointer.x, y: pointer.y };
6
- const newPolylinePoints = [...points, newPoint];
7
- setPoints(newPolylinePoints);
8
- if (newPolylinePoints.length > 0) {
9
- const line = new fabric.Line([
10
- newPolylinePoints[newPolylinePoints.length - 1].x,
11
- newPolylinePoints[newPolylinePoints.length - 1].y,
12
- pointer.x,
13
- pointer.y,
14
- ], {
15
- stroke: color,
16
- strokeWidth: 2,
17
- strokeUniform: true,
18
- selectable: false,
19
- hasControls: false,
20
- });
21
- canvas.add(line);
22
- setLines([...lines, line]);
23
- }
24
- };
25
- export const handleMouseDownPolyline = (event, canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines) => {
26
- setIsDrawing(true);
27
- addPoint(event, canvas, activeColor, points, setPoints, lines, setLines);
28
- };
29
- export const handleMouseMovePolyline = (event, canvas, isDrawing, lines) => {
30
- if (isDrawing && lines.length > 0) {
31
- const pointer = canvas.getScenePoint(event.e);
32
- lines[lines.length - 1].set({ x2: pointer.x, y2: pointer.y });
33
- canvas.renderAll();
34
- }
35
- };
36
- export const handleDoubleClickPolyline = (canvas, activeColor, setIsDrawing, points, setPoints, lines, setLines, addShape) => {
37
- if (points.length > 2) {
38
- const id = uuidv4();
39
- const polyline = new fabric.Polyline(points, {
40
- fill: 'transparent',
41
- stroke: activeColor,
42
- strokeWidth: 2,
43
- selectable: false,
44
- hasControls: true,
45
- lockRotation: false,
46
- id,
47
- });
48
- canvas.add(polyline);
49
- addShape(id, "polyline" /* ToolEnum.Polyline */, polyline);
50
- setPoints([]);
51
- for (const line of lines) {
52
- canvas.remove(line); // Remove temporary lines
53
- }
54
- setLines([]);
55
- setIsDrawing(false);
56
- }
57
- };
58
- export const copyPolyline = (canvas, polyline, addShape) => {
59
- const id = uuidv4();
60
- const copy = new fabric.Polyline(polyline.points, {
61
- top: polyline.top + 10,
62
- left: polyline.left + 10,
63
- fill: 'transparent',
64
- stroke: polyline.stroke,
65
- strokeWidth: polyline.strokeWidth,
66
- selectable: false,
67
- hasControls: true,
68
- hoverCursor: 'default',
69
- id,
70
- });
71
- canvas.add(copy);
72
- addShape(id, "polyline" /* ToolEnum.Polyline */, copy);
73
- return copy;
74
- };
@@ -1,21 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { FabricEvent, IAddShape, Shape, ShapeType } from './Types';
3
- export declare const handleMouseDownRect: (event: FabricEvent, canvas: fabric.Canvas, activeColor: string, setOriginX: (v: number) => void, setOriginY: (v: number) => void, setShape: (v: Shape) => void, setIsDrawing: (v: boolean) => void) => void;
4
- export declare const handleMouseMoveRect: (event: FabricEvent, canvas: fabric.Canvas, originX: number, originY: number, shape: Shape, isDrawing: boolean) => void;
5
- export declare const handleMouseUpRect: (canvas: fabric.Canvas, setIsDrawing: (v: boolean) => void, shape: Shape, setShape: (v: Shape | null) => void, addShape: (id: string, type: ShapeType, shape: Shape) => void) => void;
6
- export declare const copyRectangle: (canvas: fabric.Canvas, rectangle: fabric.Rect, addShape: IAddShape) => fabric.Rect<{
7
- left: number;
8
- top: number;
9
- originX: "left";
10
- originY: "top";
11
- width: number;
12
- height: number;
13
- fill: string;
14
- stroke: string | fabric.TFiller | null;
15
- strokeWidth: number;
16
- strokeUniform: true;
17
- selectable: false;
18
- hasControls: true;
19
- hoverCursor: string;
20
- id: string;
21
- }, fabric.SerializedRectProps, fabric.ObjectEvents>;
@@ -1,72 +0,0 @@
1
- import * as fabric from 'fabric';
2
- import { v4 as uuidv4 } from 'uuid';
3
- export const handleMouseDownRect = (event, canvas, activeColor, setOriginX, setOriginY, setShape, setIsDrawing) => {
4
- const pointer = canvas.getScenePoint(event.e);
5
- setOriginX(pointer.x);
6
- setOriginY(pointer.y);
7
- const id = uuidv4();
8
- const newRectangle = new fabric.Rect({
9
- left: pointer.x,
10
- top: pointer.y,
11
- originX: 'left',
12
- originY: 'top',
13
- width: 0,
14
- height: 0,
15
- fill: 'transparent',
16
- stroke: activeColor,
17
- strokeWidth: 2,
18
- strokeUniform: true,
19
- selectable: false,
20
- hasControls: true,
21
- hoverCursor: 'default',
22
- id,
23
- });
24
- canvas.add(newRectangle);
25
- setShape(newRectangle);
26
- setIsDrawing(true);
27
- };
28
- export const handleMouseMoveRect = (event, canvas, originX, originY, shape, isDrawing) => {
29
- if (isDrawing && shape) {
30
- const pointer = canvas.getScenePoint(event.e);
31
- shape.set({
32
- width: Math.abs(originX - pointer.x),
33
- height: Math.abs(originY - pointer.y),
34
- });
35
- if (originX > pointer.x) {
36
- shape.set({ left: pointer.x });
37
- }
38
- if (originY > pointer.y) {
39
- shape.set({ top: pointer.y });
40
- }
41
- canvas.renderAll();
42
- }
43
- };
44
- export const handleMouseUpRect = (canvas, setIsDrawing, shape, setShape, addShape) => {
45
- setIsDrawing(false);
46
- shape.setCoords();
47
- addShape(shape.id, "rect" /* ToolEnum.Rectangle */, shape);
48
- setShape(null);
49
- canvas.defaultCursor = 'default';
50
- };
51
- export const copyRectangle = (canvas, rectangle, addShape) => {
52
- const id = uuidv4();
53
- const copy = new fabric.Rect({
54
- left: rectangle.left + 10,
55
- top: rectangle.top + 10,
56
- originX: 'left',
57
- originY: 'top',
58
- width: rectangle.width,
59
- height: rectangle.height,
60
- fill: 'transparent',
61
- stroke: rectangle.stroke,
62
- strokeWidth: rectangle.strokeWidth,
63
- strokeUniform: true,
64
- selectable: false,
65
- hasControls: true,
66
- hoverCursor: 'default',
67
- id,
68
- });
69
- canvas.add(copy);
70
- addShape(id, "rect" /* ToolEnum.Rectangle */, copy);
71
- return copy;
72
- };
@@ -1,5 +0,0 @@
1
- .canvasWrapper {
2
- background-size: contain;
3
- background-repeat: no-repeat;
4
- position: relative;
5
- }
@@ -1,2 +0,0 @@
1
- declare const ShapesList: React.FC;
2
- export default ShapesList;
@@ -1,47 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useContext, useEffect, useState } from 'react';
3
- import { useEditorContext } from '../../Providers/EditorProvider';
4
- import { UiContext } from '../../Providers/UiProvider';
5
- import { css } from '../../Utils';
6
- import Dispatcher from '../../Utils/Dispatcher';
7
- import ParametersModalForm from './ParametersModalForm';
8
- import styles from './ShapesList.module.css';
9
- const ShapesList = () => {
10
- var _a, _b, _c, _d, _e, _f;
11
- const { strings, Typography, IconButton, DeleteIcon, AnnotateIcon, SelectIcon, CopyIcon, themeMode } = useContext(UiContext);
12
- const { shapes, removeShape, configuration, metadata, setMetadata } = useEditorContext();
13
- const [selected, setSelected] = useState([]);
14
- const [form, setForm] = useState({ isOpen: false, shapeId: '' });
15
- useEffect(() => {
16
- const setSelectedShapes = (_, event) => { var _a; return setSelected((_a = event === null || event === void 0 ? void 0 : event.map((s) => s.id)) !== null && _a !== void 0 ? _a : []); };
17
- Dispatcher.register('canvas:shapeSelected', setSelectedShapes);
18
- return () => {
19
- Dispatcher.unregister('canvas:shapeSelected', setSelectedShapes);
20
- };
21
- }, [shapes]);
22
- const handleCopyShape = (id) => () => {
23
- Dispatcher.emit('canvas:copyShape', id);
24
- };
25
- const handleRemoveShape = (id) => () => {
26
- Dispatcher.emit('canvas:removeShape', id);
27
- removeShape(id);
28
- };
29
- const handleSelectShape = (id) => () => {
30
- Dispatcher.emit('canvas:selectShape', id);
31
- };
32
- const handleEditShapeMetadata = (id) => () => {
33
- setForm({ isOpen: true, shapeId: id });
34
- };
35
- const handleSubmitMetadata = (shapeId) => (data) => {
36
- setMetadata(Object.assign(Object.assign({}, metadata), { rois: [
37
- ...metadata.rois.filter((r) => r.id !== shapeId),
38
- { id: shapeId, parameters: data },
39
- ] }));
40
- setForm({ isOpen: false, shapeId: '' });
41
- };
42
- const iconColor = themeMode === 'light' ? 'black' : 'white';
43
- return (_jsxs(_Fragment, { children: [_jsxs("table", { className: css('shapes-table', styles, themeMode), children: [Object.keys(shapes).length > 0 && (_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: _jsx(Typography, { style: { fontWeight: 'bold' }, children: strings.id }) }), _jsx("th", { children: _jsx(Typography, { style: { fontWeight: 'bold' }, children: strings.type }) }), _jsx("th", {})] }) })), _jsx("tbody", { children: Object.keys(shapes).map((id) => {
44
- return (_jsxs("tr", { className: selected.indexOf(id) > -1 ? css('shapes-row-selected', styles, themeMode) : '', children: [_jsx("td", { children: _jsx("div", { children: _jsx(Typography, { children: id.substring(0, 6) }) }) }), _jsx("td", { children: _jsx(Typography, { children: strings[shapes[id].type] }) }), _jsxs("td", { children: [_jsx(IconButton, { onClick: handleSelectShape(id), children: _jsx(SelectIcon, { color: iconColor }) }), _jsx(IconButton, { onClick: handleCopyShape(id), children: _jsx(CopyIcon, { color: iconColor }) }), _jsx(IconButton, { onClick: handleEditShapeMetadata(id), disabled: !configuration.rois.find((roi) => roi.type === shapes[id].type), children: _jsx(AnnotateIcon, { color: iconColor }) }), _jsx(IconButton, { onClick: handleRemoveShape(id), children: _jsx(DeleteIcon, { color: iconColor }) })] })] }, id));
45
- }) })] }), form.isOpen && (_jsx(ParametersModalForm, { parameters: (_b = (_a = configuration.rois.find((roi) => roi.type === shapes[form.shapeId].type)) === null || _a === void 0 ? void 0 : _a.parameters) !== null && _b !== void 0 ? _b : [], data: (_f = (_d = (_c = metadata.rois.find((roi) => roi.id === form.shapeId)) === null || _c === void 0 ? void 0 : _c.parameters) !== null && _d !== void 0 ? _d : (_e = configuration.rois.find((roi) => roi.type === shapes[form.shapeId].type)) === null || _e === void 0 ? void 0 : _e.parameters) !== null && _f !== void 0 ? _f : [], title: strings.mainParametersMetadata, onClose: () => setForm({ isOpen: false, shapeId: '' }), onSubmit: handleSubmitMetadata(form.shapeId) }))] }));
46
- };
47
- export default ShapesList;
@@ -1,36 +0,0 @@
1
- .shapes-table {
2
- border-collapse: collapse;
3
- width: 100%;
4
- }
5
-
6
- .shapes-table th {
7
- padding: .8rem .3rem .3rem;
8
- text-align: left;
9
- }
10
-
11
- .shapes-table td {
12
- padding: 0 .3rem;
13
- }
14
-
15
- .shapes-table tr td:last-child,
16
- .shapes-table tr th:last-child {
17
- text-align: right;
18
- }
19
-
20
- .shapes-table-light {
21
- background-color: #eee;
22
- color: #000;
23
- }
24
-
25
- .shapes-table-dark {
26
- background-color: #333;
27
- color: #fff;
28
- }
29
-
30
- .shapes-row-selected-light {
31
- background-color: #ccc;
32
- }
33
-
34
- .shapes-row-selected-dark {
35
- background-color: #666;
36
- }
@@ -1,2 +0,0 @@
1
- declare const Toolbar: () => import("react/jsx-runtime").JSX.Element;
2
- export default Toolbar;
@@ -1,33 +0,0 @@
1
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext, useState } from 'react';
3
- import AnnotateIcon from '../../Icons/AnnotateIcon';
4
- import PointerIcon from '../../Icons/PointerIcon';
5
- import PolygonIcon from '../../Icons/PolygonIcon';
6
- import PolylineIcon from '../../Icons/PolylineIcon';
7
- import RectangleIcon from '../../Icons/RectangleIcon';
8
- import SaveIcon from '../../Icons/SaveIcon';
9
- import { useEditorContext } from '../../Providers/EditorProvider';
10
- import { UiContext } from '../../Providers/UiProvider';
11
- import { css } from '../../Utils';
12
- import ColorPicker from './ColorPicker';
13
- import ParametersModalForm from './ParametersModalForm';
14
- import styles from './Toolbar.module.css';
15
- import { enableMainMetadata, enableRois } from './Utils';
16
- const Toolbar = () => {
17
- var _a, _b;
18
- const { IconButton, themeMode, primaryColor, Typography, strings } = useContext(UiContext);
19
- const { activeTool, setActiveTool, configuration, metadata, setMetadata, onSubmit } = useEditorContext();
20
- const [form, setForm] = useState({ isOpen: false });
21
- const iconColor = (tool) => (tool === activeTool ? primaryColor : themeMode === 'light' ? 'black' : 'white');
22
- const setTool = (tool) => () => setActiveTool(tool);
23
- const handleSubmitMetadata = (data) => {
24
- setMetadata(Object.assign(Object.assign({}, metadata), { parameters: data }));
25
- setForm({ isOpen: false });
26
- };
27
- const hideForbiddenTools = (_a = configuration.options) === null || _a === void 0 ? void 0 : _a.hideForbiddenTools;
28
- const polylineEnabled = configuration.rois.find((r) => r.type === "polyline" /* ToolEnum.Polyline */);
29
- const polygonEnabled = configuration.rois.find((r) => r.type === "polygon" /* ToolEnum.Polygon */);
30
- const rectangleEnabled = configuration.rois.find((r) => r.type === "rect" /* ToolEnum.Rectangle */);
31
- return (_jsxs(_Fragment, { children: [((_b = configuration.options) === null || _b === void 0 ? void 0 : _b.description) && (_jsx("div", { className: css('toolbar-info', styles, themeMode), children: _jsx(Typography, { children: configuration.options.description }) })), _jsxs("div", { className: css('toolbar', styles, themeMode), children: [enableRois(configuration) && (_jsxs(_Fragment, { children: [_jsx(IconButton, { onClick: setTool("pointer" /* ToolEnum.Pointer */), children: _jsx(PointerIcon, { color: iconColor("pointer" /* ToolEnum.Pointer */) }) }), (!hideForbiddenTools || polylineEnabled) && (_jsx(IconButton, { onClick: setTool("polyline" /* ToolEnum.Polyline */), disabled: !polylineEnabled, children: _jsx(PolylineIcon, { color: iconColor("polyline" /* ToolEnum.Polyline */) }) })), (!hideForbiddenTools || polygonEnabled) && (_jsx(IconButton, { onClick: setTool("polygon" /* ToolEnum.Polygon */), disabled: !polygonEnabled, children: _jsx(PolygonIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) })), (!hideForbiddenTools || rectangleEnabled) && (_jsx(IconButton, { onClick: setTool("rect" /* ToolEnum.Rectangle */), disabled: !rectangleEnabled, children: _jsx(RectangleIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) })), _jsx(ColorPicker, { style: { marginLeft: 'auto', marginRight: '.5rem' } })] })), enableRois(configuration) && enableMainMetadata(configuration) && (_jsx("div", { className: css('toolbar-spacer', styles, themeMode) })), enableMainMetadata(configuration) && (_jsx(IconButton, { onClick: () => setForm({ isOpen: true }), children: _jsx(AnnotateIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) })), _jsx("div", { className: css('toolbar-spacer', styles, themeMode) }), _jsx(IconButton, { onClick: onSubmit, children: _jsx(SaveIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) })] }), enableRois(configuration) && (_jsx("div", { className: css('toolbar-helper', styles, themeMode), children: _jsxs(Typography, { children: [strings[activeTool], ": ", strings[`${activeTool}HelpText`]] }) })), form.isOpen && (_jsx(ParametersModalForm, { parameters: configuration.parameters, data: metadata.parameters, title: strings.mainParametersMetadata, onClose: () => setForm({ isOpen: false }), onSubmit: handleSubmitMetadata }))] }));
32
- };
33
- export default Toolbar;
@@ -1,53 +0,0 @@
1
- .toolbar-info {
2
- padding: .5rem;
3
- }
4
- .toolbar-info-light {
5
- background-color: #ddd;;
6
- color: #000;
7
- }
8
- .toolbar-info-dark {
9
- background-color: #222;
10
- color: #fff;
11
- }
12
-
13
- .toolbar {
14
- align-items: center;
15
- display: flex;
16
- padding: .5rem;
17
- }
18
-
19
- .toolbar-light {
20
- background-color: #eee;;
21
- }
22
-
23
- .toolbar-dark {
24
- background-color: #333;
25
- }
26
-
27
- .toolbar-helper {
28
- padding: .5rem;
29
- }
30
-
31
- .toolbar-helper-light {
32
- background-color: #f7f7f7;;
33
- color: #000;
34
- }
35
-
36
- .toolbar-helper-dark {
37
- background-color: #222;
38
- color: #fff;
39
- }
40
-
41
- .toolbar-spacer {
42
- height: 20px;
43
- margin: 0 .5rem;
44
- width: 1px;
45
- }
46
-
47
- .toolbar-spacer-light {
48
- background-color: #ccc;
49
- }
50
-
51
- .toolbar-spacer-dark {
52
- background-color: #555;
53
- }
@@ -1,115 +0,0 @@
1
- import * as fabric from 'fabric';
2
- export declare const enum ToolEnum {
3
- Pointer = "pointer",
4
- Polyline = "polyline",
5
- Polygon = "polygon",
6
- Rectangle = "rect"
7
- }
8
- export type ShapeType = ToolEnum.Polyline | ToolEnum.Polygon | ToolEnum.Rectangle;
9
- export type Shape = (fabric.Rect | fabric.Polygon | fabric.Polyline) & {
10
- id?: string;
11
- };
12
- export type Shapes = Record<string, {
13
- type: ShapeType;
14
- shape: Shape;
15
- }>;
16
- export type FabricEvent = fabric.TPointerEventInfo<fabric.TPointerEvent>;
17
- export type FabricSelectionEvent = Partial<fabric.TEvent> & {
18
- selected: fabric.Object[];
19
- };
20
- export type IAddShape = (id: string, type: ShapeType, shape: Shape) => void;
21
- export declare enum DataTypeEnum {
22
- Integer = "int",
23
- Float = "float",
24
- String = "string",
25
- Boolean = "bool"
26
- }
27
- export declare enum OperatorEnum {
28
- Lt = "lt",
29
- Lte = "lte",
30
- Gt = "gt",
31
- Gte = "gte",
32
- Eq = "eq"
33
- }
34
- export type ConfigurationParameter = {
35
- codename: string;
36
- label: string;
37
- description: string;
38
- unit: string;
39
- type: DataTypeEnum;
40
- options: {
41
- value: number | string;
42
- label: string;
43
- }[];
44
- multiple?: boolean;
45
- required: boolean;
46
- value: number | string | boolean | string[] | number[] | null;
47
- };
48
- export type RoiConfiguration = {
49
- role: string;
50
- type: Omit<ShapeType, 'pointer'>;
51
- multiplicity: {
52
- operator: OperatorEnum;
53
- threshold: number;
54
- };
55
- parameters: ConfigurationParameter[];
56
- };
57
- export type Configuration = {
58
- parameters: ConfigurationParameter[];
59
- rois: RoiConfiguration[];
60
- options?: {
61
- hideForbiddenTools?: boolean;
62
- description?: string;
63
- };
64
- };
65
- export interface INotify {
66
- info: (message: string) => void;
67
- warn: (message: string) => void;
68
- error: (message: string) => void;
69
- success: (message: string) => void;
70
- }
71
- export type Metadata = {
72
- parameters: OutputParameter[];
73
- rois: {
74
- id: string;
75
- parameters: OutputParameter[];
76
- }[];
77
- };
78
- export type OutputShapeRect = {
79
- top: number;
80
- left: number;
81
- width: number;
82
- height: number;
83
- color: string;
84
- };
85
- export type OutputShapePolyline = {
86
- points: {
87
- x: number;
88
- y: number;
89
- }[];
90
- top: number;
91
- left: number;
92
- color: string;
93
- };
94
- export type OutputShapePolygon = {
95
- points: {
96
- x: number;
97
- y: number;
98
- }[];
99
- top: number;
100
- left: number;
101
- color: string;
102
- };
103
- export interface OutputParameter {
104
- codename: string;
105
- value: number | string | boolean | string[] | number[] | null;
106
- }
107
- export interface OutputRoi {
108
- parameters: OutputParameter[];
109
- type: ShapeType;
110
- shape: OutputShapeRect | OutputShapePolyline | OutputShapePolygon;
111
- }
112
- export interface Output {
113
- parameters: OutputParameter[];
114
- rois: OutputRoi[];
115
- }
@@ -1,15 +0,0 @@
1
- export var DataTypeEnum;
2
- (function (DataTypeEnum) {
3
- DataTypeEnum["Integer"] = "int";
4
- DataTypeEnum["Float"] = "float";
5
- DataTypeEnum["String"] = "string";
6
- DataTypeEnum["Boolean"] = "bool";
7
- })(DataTypeEnum || (DataTypeEnum = {}));
8
- export var OperatorEnum;
9
- (function (OperatorEnum) {
10
- OperatorEnum["Lt"] = "lt";
11
- OperatorEnum["Lte"] = "lte";
12
- OperatorEnum["Gt"] = "gt";
13
- OperatorEnum["Gte"] = "gte";
14
- OperatorEnum["Eq"] = "eq";
15
- })(OperatorEnum || (OperatorEnum = {}));
@@ -1,22 +0,0 @@
1
- import { Configuration, ConfigurationParameter, INotify, Metadata, Shape, Shapes, ShapeType, ToolEnum } from './Types';
2
- export declare const notify: INotify;
3
- export declare const enableRois: (configuration: Configuration) => boolean;
4
- export declare const enableMainMetadata: (configuration: Configuration) => boolean;
5
- export declare const canDrawShape: (configuration: Configuration, shapeType: Omit<ToolEnum, ToolEnum.Pointer>, shapes: Shapes, notify: INotify, message: string) => boolean;
6
- export declare const validateParametersForm: (parameters: ConfigurationParameter[], fields: Record<string, unknown>, setErrors: (errors: Record<string, string>) => void) => boolean;
7
- export declare const validate: (configuration: Configuration, shapes: Shapes, metadata: Metadata, strings: Record<string, string>) => [boolean, string[]];
8
- export declare const fabricShapeToOutputShape: (shape: Shape, type: ShapeType) => {
9
- top: number;
10
- left: number;
11
- width: number;
12
- height: number;
13
- color: string;
14
- points?: undefined;
15
- } | {
16
- points: any;
17
- top: number;
18
- left: number;
19
- color: string;
20
- width?: undefined;
21
- height?: undefined;
22
- };