@abidibo/react-cam-roi 0.2.3 → 0.2.4

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 (94) hide show
  1. package/README.md +0 -2
  2. package/dist/index.cjs.css +2 -0
  3. package/dist/index.cjs.css.map +1 -0
  4. package/dist/index.cjs.js +1582 -0
  5. package/dist/index.cjs.js.map +1 -0
  6. package/dist/index.esm.css +2 -0
  7. package/dist/index.esm.css.map +1 -0
  8. package/dist/index.esm.js +1576 -0
  9. package/dist/index.esm.js.map +1 -0
  10. package/package.json +17 -6
  11. package/dist/Components/BoolField/index.js +0 -13
  12. package/dist/Components/Button/index.js +0 -15
  13. package/dist/Components/EnumField/index.js +0 -16
  14. package/dist/Components/IconButton/index.js +0 -10
  15. package/dist/Components/Loader/index.js +0 -9
  16. package/dist/Components/Modal/index.js +0 -16
  17. package/dist/Components/NumberField/index.js +0 -13
  18. package/dist/Components/RoiEditor/Canvas.js +0 -30
  19. package/dist/Components/RoiEditor/ColorPicker.js +0 -12
  20. package/dist/Components/RoiEditor/Header.js +0 -14
  21. package/dist/Components/RoiEditor/Hooks.js +0 -328
  22. package/dist/Components/RoiEditor/ParameterField.js +0 -27
  23. package/dist/Components/RoiEditor/ParametersModalForm/index.js +0 -42
  24. package/dist/Components/RoiEditor/Polygon.js +0 -77
  25. package/dist/Components/RoiEditor/Polyline.js +0 -75
  26. package/dist/Components/RoiEditor/Rectangle.js +0 -73
  27. package/dist/Components/RoiEditor/RoisInfo.js +0 -43
  28. package/dist/Components/RoiEditor/ShapesList.js +0 -77
  29. package/dist/Components/RoiEditor/Toolbar.js +0 -27
  30. package/dist/Components/RoiEditor/TopBar.js +0 -21
  31. package/dist/Components/RoiEditor/Types.js +0 -23
  32. package/dist/Components/RoiEditor/Utils.js +0 -161
  33. package/dist/Components/RoiEditor/index.js +0 -99
  34. package/dist/Components/RoleField.js +0 -49
  35. package/dist/Components/TextField/index.js +0 -13
  36. package/dist/Components/Typography/index.js +0 -6
  37. package/dist/Icons/AnnotateIcon.js +0 -5
  38. package/dist/Icons/CloseIcon.js +0 -5
  39. package/dist/Icons/CopyIcon.js +0 -5
  40. package/dist/Icons/DeleteIcon.js +0 -5
  41. package/dist/Icons/EditIcon.js +0 -5
  42. package/dist/Icons/PointerIcon.js +0 -5
  43. package/dist/Icons/PolygonIcon.js +0 -5
  44. package/dist/Icons/PolylineIcon.js +0 -5
  45. package/dist/Icons/RectangleIcon.js +0 -5
  46. package/dist/Icons/SaveIcon.js +0 -5
  47. package/dist/Providers/EditorProvider.js +0 -29
  48. package/dist/Providers/UiProvider.js +0 -104
  49. package/dist/Types.js +0 -1
  50. package/dist/Utils/Dispatcher.js +0 -65
  51. package/dist/Utils/index.js +0 -16
  52. package/dist/index.js +0 -4
  53. /package/dist/{Components → types/Components}/BoolField/index.d.ts +0 -0
  54. /package/dist/{Components → types/Components}/Button/index.d.ts +0 -0
  55. /package/dist/{Components → types/Components}/EnumField/index.d.ts +0 -0
  56. /package/dist/{Components → types/Components}/IconButton/index.d.ts +0 -0
  57. /package/dist/{Components → types/Components}/Loader/index.d.ts +0 -0
  58. /package/dist/{Components → types/Components}/Modal/index.d.ts +0 -0
  59. /package/dist/{Components → types/Components}/NumberField/index.d.ts +0 -0
  60. /package/dist/{Components → types/Components}/RoiEditor/Canvas.d.ts +0 -0
  61. /package/dist/{Components → types/Components}/RoiEditor/ColorPicker.d.ts +0 -0
  62. /package/dist/{Components → types/Components}/RoiEditor/Header.d.ts +0 -0
  63. /package/dist/{Components → types/Components}/RoiEditor/Hooks.d.ts +0 -0
  64. /package/dist/{Components → types/Components}/RoiEditor/ParameterField.d.ts +0 -0
  65. /package/dist/{Components → types/Components}/RoiEditor/ParametersModalForm/index.d.ts +0 -0
  66. /package/dist/{Components → types/Components}/RoiEditor/Polygon.d.ts +0 -0
  67. /package/dist/{Components → types/Components}/RoiEditor/Polyline.d.ts +0 -0
  68. /package/dist/{Components → types/Components}/RoiEditor/Rectangle.d.ts +0 -0
  69. /package/dist/{Components → types/Components}/RoiEditor/RoisInfo.d.ts +0 -0
  70. /package/dist/{Components → types/Components}/RoiEditor/ShapesList.d.ts +0 -0
  71. /package/dist/{Components → types/Components}/RoiEditor/Toolbar.d.ts +0 -0
  72. /package/dist/{Components → types/Components}/RoiEditor/TopBar.d.ts +0 -0
  73. /package/dist/{Components → types/Components}/RoiEditor/Types.d.ts +0 -0
  74. /package/dist/{Components → types/Components}/RoiEditor/Utils.d.ts +0 -0
  75. /package/dist/{Components → types/Components}/RoiEditor/index.d.ts +0 -0
  76. /package/dist/{Components → types/Components}/RoleField.d.ts +0 -0
  77. /package/dist/{Components → types/Components}/TextField/index.d.ts +0 -0
  78. /package/dist/{Components → types/Components}/Typography/index.d.ts +0 -0
  79. /package/dist/{Icons → types/Icons}/AnnotateIcon.d.ts +0 -0
  80. /package/dist/{Icons → types/Icons}/CloseIcon.d.ts +0 -0
  81. /package/dist/{Icons → types/Icons}/CopyIcon.d.ts +0 -0
  82. /package/dist/{Icons → types/Icons}/DeleteIcon.d.ts +0 -0
  83. /package/dist/{Icons → types/Icons}/EditIcon.d.ts +0 -0
  84. /package/dist/{Icons → types/Icons}/PointerIcon.d.ts +0 -0
  85. /package/dist/{Icons → types/Icons}/PolygonIcon.d.ts +0 -0
  86. /package/dist/{Icons → types/Icons}/PolylineIcon.d.ts +0 -0
  87. /package/dist/{Icons → types/Icons}/RectangleIcon.d.ts +0 -0
  88. /package/dist/{Icons → types/Icons}/SaveIcon.d.ts +0 -0
  89. /package/dist/{Providers → types/Providers}/EditorProvider.d.ts +0 -0
  90. /package/dist/{Providers → types/Providers}/UiProvider.d.ts +0 -0
  91. /package/dist/{Types.d.ts → types/Types.d.ts} +0 -0
  92. /package/dist/{Utils → types/Utils}/Dispatcher.d.ts +0 -0
  93. /package/dist/{Utils → types/Utils}/index.d.ts +0 -0
  94. /package/dist/{index.d.ts → types/index.d.ts} +0 -0
@@ -1,99 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useCallback, useContext, useEffect, useRef, useState } from 'react';
3
- import EditorProvider from '../../Providers/EditorProvider';
4
- import { UiContext } from '../../Providers/UiProvider';
5
- import { css, log } from '../../Utils';
6
- import { Loader } from '../Loader';
7
- import Canvas from './Canvas';
8
- import Header from './Header';
9
- import { useCanvasSize } from './Hooks';
10
- import styles from './RoiEditor.module.css';
11
- import ShapesList from './ShapesList';
12
- import Toolbar from './Toolbar';
13
- import { fabricShapeToOutputShape, validate } from './Utils';
14
- import TopBar from './TopBar';
15
- // https://github.com/n-mazaheri/image-editor
16
- const RoiEditor = ({ imageUrl, configuration, onSubmit, onUpdate, initialData, editorId, }) => {
17
- var _a, _b, _c;
18
- log('info', true, 'react-cam-roi', 'React', React);
19
- const firstUpdate = useRef(true);
20
- log('info', true, 'react-cam-roi', 'After first useRef');
21
- const { themeMode, enableLogs, pickerColors, strings, notify } = useContext(UiContext);
22
- const { imageSize, canvasSize, wrapperRef, isReady } = useCanvasSize(imageUrl);
23
- const [activeTool, setActiveTool] = useState("pointer" /* ToolEnum.Pointer */);
24
- const [activeColor, setActiveColor] = useState(pickerColors[0]);
25
- // metadata
26
- const [metadata, setMetadata] = useState({
27
- parameters: [
28
- ...((_a = configuration.parameters.map((p) => {
29
- var _a;
30
- const initial = (_a = initialData === null || initialData === void 0 ? void 0 : initialData.parameters) === null || _a === void 0 ? void 0 : _a.find((initP) => initP.codename === p.codename);
31
- return {
32
- codename: p.codename,
33
- value: initial ? initial.value : p.value,
34
- };
35
- })) !== null && _a !== void 0 ? _a : []),
36
- ],
37
- rois: [],
38
- });
39
- // fabric shapes
40
- const [shapes, setShapes] = useState({});
41
- const addShape = useCallback((id, type, shape) => setShapes(Object.assign(Object.assign({}, shapes), { [id]: { type, shape } })), [shapes]);
42
- const addShapes = useCallback((s) => setShapes(Object.assign(Object.assign({}, shapes), s.reduce((r, s) => (Object.assign(Object.assign({}, r), { [s.id]: s })), {}))), [shapes]);
43
- const removeShape = useCallback((id) => {
44
- const newShapes = Object.assign({}, shapes);
45
- delete newShapes[id];
46
- setShapes(newShapes);
47
- setMetadata(Object.assign(Object.assign({}, metadata), { rois: metadata.rois.filter((r) => r.id !== id) }));
48
- }, [shapes, metadata]);
49
- const prepareOutput = useCallback((metadata, shapes) => {
50
- var _a, _b;
51
- return {
52
- parameters: (_b = (_a = metadata.parameters) === null || _a === void 0 ? void 0 : _a.map((p) => ({ codename: p.codename, value: p.value }))) !== null && _b !== void 0 ? _b : [],
53
- rois: Object.keys(shapes).map((shapeId) => {
54
- var _a, _b, _c, _d, _e, _f, _g;
55
- return ({
56
- parameters: (_c = (_b = (_a = metadata.rois
57
- .find((r) => r.id === shapeId)) === null || _a === void 0 ? void 0 : _a.parameters) === null || _b === void 0 ? void 0 : _b.map((p) => ({ codename: p.codename, value: p.value }))) !== null && _c !== void 0 ? _c : [],
58
- name: (_e = (_d = metadata.rois.find((r) => r.id === shapeId)) === null || _d === void 0 ? void 0 : _d.name) !== null && _e !== void 0 ? _e : '',
59
- role: (_g = (_f = metadata.rois.find((r) => r.id === shapeId)) === null || _f === void 0 ? void 0 : _f.role) !== null && _g !== void 0 ? _g : '',
60
- type: shapes[shapeId].type,
61
- id: shapeId,
62
- shape: fabricShapeToOutputShape(shapes[shapeId].shape, shapes[shapeId].shape.type, imageSize),
63
- });
64
- }),
65
- };
66
- }, [imageSize.width, imageSize.height]); // eslint-disable-line
67
- useEffect(() => {
68
- // do not run on first update
69
- if (firstUpdate.current) {
70
- firstUpdate.current = false;
71
- return;
72
- }
73
- else if (onUpdate) {
74
- // notify every update
75
- onUpdate(prepareOutput(metadata, shapes));
76
- }
77
- }, [metadata, shapes, onUpdate, prepareOutput]);
78
- const handleSubmit = useCallback(() => {
79
- const [isValid, errors] = validate(configuration, shapes, metadata, strings);
80
- if (isValid) {
81
- onSubmit(prepareOutput(metadata, shapes));
82
- }
83
- else {
84
- notify.error(strings.invalidSubmission + '\n' + errors.map((e) => `- ${e}`).join('\n'));
85
- }
86
- }, [onSubmit, configuration, shapes, metadata, prepareOutput, strings, notify]);
87
- log('info', enableLogs, 'react-cam-roi', 'active tool', activeTool);
88
- log('info', enableLogs, 'react-cam-roi', 'canvas size', canvasSize);
89
- log('info', enableLogs, 'react-cam-roi', 'metadata', metadata);
90
- if (!isReady) {
91
- return _jsx(Loader, {});
92
- }
93
- return (_jsx(EditorProvider, { editorId: editorId, hideForbiddenTools: (_c = (_b = configuration.options) === null || _b === void 0 ? void 0 : _b.hideForbiddenTools) !== null && _c !== void 0 ? _c : false, activeTool: activeTool, setActiveTool: setActiveTool, activeColor: activeColor, setActiveColor: setActiveColor, shapes: shapes, addShape: addShape, addShapes: addShapes, removeShape: removeShape, configuration: configuration, metadata: metadata, setMetadata: setMetadata, onSubmit: handleSubmit, children: _jsxs("div", { style: { maxWidth: '100%', width: `${imageSize.width}px` }, ref: wrapperRef, children: [_jsx(TopBar, {}), _jsx(Header, {}), _jsx(Toolbar, {}), _jsx("div", { className: css('canvas-wrapper', styles, themeMode), style: {
94
- width: `${canvasSize.width}px`,
95
- height: `${canvasSize.height}px`,
96
- backgroundImage: `url(${imageUrl})`,
97
- }, children: _jsx(Canvas, { imageSize: imageSize, canvasSize: canvasSize, initialData: initialData }) }), _jsx(ShapesList, {})] }) }));
98
- };
99
- export default RoiEditor;
@@ -1,49 +0,0 @@
1
- var __rest = (this && this.__rest) || function (s, e) {
2
- var t = {};
3
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
- t[p] = s[p];
5
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
- t[p[i]] = s[p[i]];
9
- }
10
- return t;
11
- };
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useContext, useEffect } from 'react';
14
- import { useEditorContext } from '../Providers/EditorProvider';
15
- import { UiContext } from '../Providers/UiProvider';
16
- import { humanize } from '../Utils';
17
- import { OperatorEnum } from './RoiEditor/Types';
18
- const isAllowed = (role, multiplicity, metadata) => {
19
- switch (multiplicity.operator) {
20
- case OperatorEnum.Eq:
21
- case OperatorEnum.Lte:
22
- return metadata.rois.filter((m) => m.role === role).length < multiplicity.threshold;
23
- case OperatorEnum.Lt:
24
- return metadata.rois.filter((m) => m.role === role).length < multiplicity.threshold - 1;
25
- default:
26
- return true;
27
- }
28
- };
29
- const RoleField = (_a) => {
30
- var { onChange, value, required, shapeType } = _a, props = __rest(_a, ["onChange", "value", "required", "shapeType"]);
31
- const { strings, EnumField } = useContext(UiContext);
32
- const { configuration, metadata } = useEditorContext();
33
- const options = [];
34
- const rois = configuration.rois || [];
35
- rois
36
- .filter((r) => r.type === shapeType)
37
- .forEach((r) => {
38
- if (!options.includes(r.role) && (!r.multiplicity || isAllowed(r.role, r.multiplicity, metadata))) {
39
- options.push(r.role);
40
- }
41
- });
42
- useEffect(() => {
43
- if (required) {
44
- onChange(options[0]);
45
- }
46
- }, []); // eslint-disable-line react-hooks/exhaustive-deps
47
- return (_jsx(EnumField, Object.assign({ required: required, label: strings.role, value: value, onChange: (value) => onChange(value), options: options.map((o) => ({ value: o, label: humanize(o) })) }, props)));
48
- };
49
- export default RoleField;
@@ -1,13 +0,0 @@
1
- import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
- import { useContext } from 'react';
3
- import { UiContext } from '../../Providers/UiProvider';
4
- import { css } from '../../Utils';
5
- import styles from './TextField.module.css';
6
- const TextField = ({ onChange, type = 'text', value, label, helperText, error, required = false, readOnly = false, disabled = false, }) => {
7
- const { themeMode, Typography } = useContext(UiContext);
8
- const handleChange = (e) => {
9
- onChange(e.target.value);
10
- };
11
- return (_jsxs("div", { className: css('text-field-wrapper', styles, themeMode), children: [_jsx("label", { className: `${css('text-field-label', styles, themeMode)} ${error ? css('text-field-label-error', styles, null) : ''}`, children: _jsxs(Typography, { children: [label, required && ' *'] }) }), _jsx("input", { type: type, className: `${css('text-field', styles, themeMode)} ${error ? css('text-field-error', styles, null) : ''}`, onChange: handleChange, value: value, readOnly: readOnly, disabled: disabled }), helperText && (_jsx(Typography, { component: 'div', className: `${css('text-field-helper-text', styles, themeMode)} ${error ? css('text-field-helper-text-error', styles, null) : ''}`, children: helperText }))] }));
12
- };
13
- export default TextField;
@@ -1,6 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const Typography = ({ children, style = {}, className = '', component = 'span' }) => {
3
- const Tag = component;
4
- return _jsx(Tag, { className: className, style: style, children: children });
5
- };
6
- export default Typography;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const AnnotateIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 -960 960 960", width: "24px", style: style, children: _jsx("path", { fill: color, d: "M280-280h84l240-238-86-86-238 238v86Zm352-266 42-44q6-6 6-14t-6-14l-56-56q-6-6-14-6t-14 6l-44 42 86 86ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h168q13-36 43.5-58t68.5-22q38 0 68.5 22t43.5 58h168q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm280-590q13 0 21.5-8.5T510-820q0-13-8.5-21.5T480-850q-13 0-21.5 8.5T450-820q0 13 8.5 21.5T480-790ZM200-200v-560 560Z" }) }));
4
- };
5
- export default AnnotateIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const CloseIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 -960 960 960", width: "24px", style: style, children: _jsx("path", { fill: color, d: "m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z" }) }));
4
- };
5
- export default CloseIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const CopyIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", width: "24px", viewBox: "0 -960 960 960", style: style, children: _jsx("path", { fill: color, d: "M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z" }) }));
4
- };
5
- export default CopyIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const DeleteIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 -960 960 960", width: "24px", style: style, children: _jsx("path", { fill: color, d: "M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z" }) }));
4
- };
5
- export default DeleteIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const EditIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 -960 960 960", width: "24px", style: style, children: _jsx("path", { fill: color, d: "M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z" }) }));
4
- };
5
- export default EditIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const PointerIcon = ({ color = 'black', style = { height: '32px' } }) => {
3
- return (_jsx("svg", { style: style, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 25 25", children: _jsx("path", { fill: color, d: "M13.3891,20.923l-3.1995-6.8869-3.47,4.8454V4.077l11.5606,9.0859h-5.9695l3.1679,6.7828-2.0893.9773h-.0002Z" }) }));
4
- };
5
- export default PointerIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const PolygonIcon = ({ color = 'black', style = { height: '32px' } }) => {
3
- return (_jsx("svg", { style: style, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 25 25", children: _jsx("path", { fill: color, d: "M17.3836,17.058v-2.9301h2.1705v4.341l-9.7673,4.341-7.5967-7.5968L6.5311,5.4459h4.341v2.1705h-2.9301l-3.1472,7.1627,5.4263,5.4263,7.1627-3.1472M22.8099,5.4459v2.1705h-3.2558v3.2558h-2.1705v-3.2558h-3.2558v-2.1705h3.2558v-3.2558h2.1705v3.2558h3.2558Z" }) }));
4
- };
5
- export default PolygonIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- const PolylineIcon = ({ color = 'black', style = { height: '32px' } }) => {
3
- return (_jsxs("svg", { style: style, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 25 25", children: [_jsx("polygon", { fill: color, points: "20.5216 8.6492 20.5216 5.4658 18.3992 5.4658 18.3992 8.6492 15.2159 8.6492 15.2159 10.7715 18.3992 10.7715 18.3992 13.955 20.5216 13.955 20.5216 10.7715 23.705 10.7715 23.705 8.6492 20.5216 8.6492" }), _jsx("polygon", { fill: color, points: "12.3027 17.2 7.011 14.4951 7.011 11.5067 8.9251 9.2929 13.103 9.2929 13.103 3.577 7.3871 3.577 7.3871 7.7797 4.7908 10.7826 1.295 10.7826 1.295 16.4985 6.2004 16.4985 12.3027 19.6175 12.3027 21.423 18.0186 21.423 18.0186 15.7071 12.3027 15.7071 12.3027 17.2" })] }));
4
- };
5
- export default PolylineIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const RectangleIcon = ({ color = 'black', style = { height: '32px' } }) => {
3
- return (_jsx("svg", { style: style, xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 25 25", children: _jsx("path", { fill: color, d: "M19.5541,7.0738h3.2558v2.1705h-3.2558v3.2558h-2.1705v-3.2558h-3.2558v-2.1705h3.2558v-3.2558h2.1705v3.2558M17.3836,19.0115v-3.2558h2.1705v5.4263H2.1901V7.0738h8.682v2.1705h-6.5115v9.7673h13.023,0Z" }) }));
4
- };
5
- export default RectangleIcon;
@@ -1,5 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- const SaveIcon = ({ color = 'black', style = {} }) => {
3
- return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", height: "24px", viewBox: "0 -960 960 960", width: "24px", style: style, children: _jsx("path", { fill: color, d: "M840-680v480q0 33-23.5 56.5T760-120H200q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h480l160 160Zm-80 34L646-760H200v560h560v-446ZM480-240q50 0 85-35t35-85q0-50-35-85t-85-35q-50 0-85 35t-35 85q0 50 35 85t85 35ZM240-560h360v-160H240v160Zm-40-86v446-560 114Z" }) }));
4
- };
5
- export default SaveIcon;
@@ -1,29 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext } from 'react';
3
- export const EditorContext = createContext(undefined); // eslint-disable-line
4
- export function useEditorContext() {
5
- const context = useContext(EditorContext);
6
- if (context === undefined) {
7
- throw new Error('useEditorContext must be within a EditorProvider');
8
- }
9
- return context;
10
- }
11
- const EditorProvider = ({ children, editorId, hideForbiddenTools, activeTool, setActiveTool, activeColor, setActiveColor, shapes, addShape, addShapes, removeShape, configuration, metadata, setMetadata, onSubmit, }) => {
12
- return (_jsx(EditorContext.Provider, { value: {
13
- editorId,
14
- hideForbiddenTools,
15
- activeTool,
16
- setActiveTool,
17
- activeColor,
18
- setActiveColor,
19
- shapes,
20
- addShape,
21
- addShapes,
22
- removeShape,
23
- configuration,
24
- metadata,
25
- setMetadata,
26
- onSubmit,
27
- }, children: children }));
28
- };
29
- export default EditorProvider;
@@ -1,104 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext } from 'react';
3
- import Typography from '../Components/Typography';
4
- import IconButton from '../Components/IconButton';
5
- import DeleteIcon from '../Icons/DeleteIcon';
6
- import EditIcon from '../Icons/EditIcon';
7
- import { notify } from '../Components/RoiEditor/Utils';
8
- import CopyIcon from '../Icons/CopyIcon';
9
- import AnnotateIcon from '../Icons/AnnotateIcon';
10
- import Modal from '../Components/Modal';
11
- import CloseIcon from '../Icons/CloseIcon';
12
- import TextField from '../Components/TextField';
13
- import NumberField from '../Components/NumberField';
14
- import BoolField from '../Components/BoolField';
15
- import EnumField from '../Components/EnumField';
16
- import Button from '../Components/Button';
17
- import SaveIcon from '../Icons/SaveIcon';
18
- export const DefaultUiContext = {
19
- enableLogs: true,
20
- themeMode: 'light',
21
- primaryColor: '#1976d2',
22
- primaryFgColor: '#fff',
23
- Typography,
24
- IconButton,
25
- Modal,
26
- DeleteIcon,
27
- EditIcon,
28
- CopyIcon,
29
- AnnotateIcon,
30
- SaveIcon,
31
- CloseIcon,
32
- TextField,
33
- NumberField,
34
- BoolField,
35
- EnumField,
36
- Button,
37
- pickerColors: ['#ffffff', '#000000', '#ff9900', '#0099ff'],
38
- notify,
39
- strings: {
40
- cancel: 'Cancel',
41
- cannotDrawMorePolygons: 'You cannot draw more polygons',
42
- cannotDrawMorePolylines: 'You cannot draw more polylines',
43
- cannotDrawMoreRectangles: 'You cannot draw more rectangles',
44
- id: 'ID',
45
- invalidSubmission: 'Invalid submission',
46
- mainParametersMetadata: 'Main parameters',
47
- missingRequiredValuesInMainParameters: 'Missing required values in main parameters',
48
- missingRequiredValuesInShapeParameters: 'Missing required values in shape {id} parameters',
49
- name: 'Name',
50
- polygon: 'Polygon',
51
- polygonHelpText: 'click to draw all the polygon points, double click on the last point to close the polygon',
52
- polyline: 'Polyline',
53
- polylineHelpText: 'click to draw all the polyline points, double click on the last point to stop drawing',
54
- rect: 'Rectangle',
55
- rectHelpText: 'click and drag to draw the rectangle',
56
- pointer: 'Selection',
57
- pointerHelpText: 'click a shape to select it',
58
- requiredField: 'This field is required',
59
- roiMultiplicityEqRule: 'a number of {role} ({type}) equal to {threshold}',
60
- roiMultiplicityGtRule: 'a number of {role} ({type}) greater than {threshold}',
61
- roiMultiplicityGteRule: 'a number of {role} ({type}) greater than or equal to {threshold}',
62
- roiMultiplicityLtRule: 'a number of {role} ({type}) less than {threshold}',
63
- roiMultiplicityLteRule: 'a number of {role} ({type}) less than or equal to {threshold}',
64
- roiMultiplicityNoRule: 'a number of {role} ({type})',
65
- roisToBeDrawn: 'ROIs to be drawn',
66
- role: 'Role',
67
- save: 'Save',
68
- shapeParametersMetadata: 'Shape parameters',
69
- shapesOfRoleShouldBeEqualToThreshold: 'Shapes of role {role} should be equal to {threshold}',
70
- shapesOfRoleShouldBeGreaterThanThreshold: 'Shapes of role {role} should be greater than {threshold}',
71
- shapesOfRoleShouldBeGreaterThanOrEqualToThreshold: 'Shapes of role {role} should be greater than or equal to {threshold}',
72
- shapesOfRoleShouldBeLessThanThreshold: 'Shapes of role {role} should be less than {threshold}',
73
- shapesOfRoleShouldBeLessThanOrEqualToThreshold: 'Shapes of role {role} should be less than or equal to {threshold}',
74
- type: 'Type',
75
- },
76
- };
77
- export const UiContext = createContext(DefaultUiContext);
78
- const UiProvider = ({ children, enableLogs, themeMode, primaryColor, primaryFgColor, Typography, Modal, IconButton, DeleteIcon, EditIcon, CopyIcon, AnnotateIcon, SaveIcon, CloseIcon, TextField, NumberField, BoolField, EnumField, Button, pickerColors, notify, strings, }) => {
79
- const ctx = {
80
- enableLogs: enableLogs !== null && enableLogs !== void 0 ? enableLogs : DefaultUiContext.enableLogs,
81
- Typography: Typography !== null && Typography !== void 0 ? Typography : DefaultUiContext.Typography,
82
- Modal: Modal !== null && Modal !== void 0 ? Modal : DefaultUiContext.Modal,
83
- IconButton: IconButton !== null && IconButton !== void 0 ? IconButton : DefaultUiContext.IconButton,
84
- DeleteIcon: DeleteIcon !== null && DeleteIcon !== void 0 ? DeleteIcon : DefaultUiContext.DeleteIcon,
85
- EditIcon: EditIcon !== null && EditIcon !== void 0 ? EditIcon : DefaultUiContext.EditIcon,
86
- CopyIcon: CopyIcon !== null && CopyIcon !== void 0 ? CopyIcon : DefaultUiContext.CopyIcon,
87
- AnnotateIcon: AnnotateIcon !== null && AnnotateIcon !== void 0 ? AnnotateIcon : DefaultUiContext.AnnotateIcon,
88
- SaveIcon: SaveIcon !== null && SaveIcon !== void 0 ? SaveIcon : DefaultUiContext.SaveIcon,
89
- CloseIcon: CloseIcon !== null && CloseIcon !== void 0 ? CloseIcon : DefaultUiContext.CloseIcon,
90
- TextField: TextField !== null && TextField !== void 0 ? TextField : DefaultUiContext.TextField,
91
- NumberField: NumberField !== null && NumberField !== void 0 ? NumberField : DefaultUiContext.NumberField,
92
- BoolField: BoolField !== null && BoolField !== void 0 ? BoolField : DefaultUiContext.BoolField,
93
- EnumField: EnumField !== null && EnumField !== void 0 ? EnumField : DefaultUiContext.EnumField,
94
- Button: Button !== null && Button !== void 0 ? Button : DefaultUiContext.Button,
95
- themeMode: themeMode !== null && themeMode !== void 0 ? themeMode : DefaultUiContext.themeMode,
96
- primaryColor: primaryColor !== null && primaryColor !== void 0 ? primaryColor : DefaultUiContext.primaryColor,
97
- primaryFgColor: primaryFgColor !== null && primaryFgColor !== void 0 ? primaryFgColor : DefaultUiContext.primaryFgColor,
98
- pickerColors: pickerColors !== null && pickerColors !== void 0 ? pickerColors : DefaultUiContext.pickerColors,
99
- notify: notify !== null && notify !== void 0 ? notify : DefaultUiContext.notify,
100
- strings: strings ? Object.assign(Object.assign({}, DefaultUiContext.strings), strings) : DefaultUiContext.strings,
101
- };
102
- return _jsx(UiContext.Provider, { value: ctx, children: children });
103
- };
104
- export default UiProvider;
package/dist/Types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,65 +0,0 @@
1
- /**
2
- * Event Dispatcher
3
- *
4
- * Implementation of an event dispatcher following the Mediator pattern
5
- * @namespace
6
- */
7
- const Dispatcher = {
8
- _prefix: 'on_',
9
- _listeners: {},
10
- /**
11
- * Adds a prefix to the event name
12
- *
13
- * Assures that event name doesn't match a standard Object property name
14
- */
15
- evtName: function (evtName) {
16
- return this._prefix + evtName;
17
- },
18
- /**
19
- * Registers a callback to an event
20
- */
21
- register: function (evtName, callback, bind) {
22
- const _evtName = this.evtName(evtName);
23
- if (typeof this._listeners[_evtName] === 'undefined') {
24
- this._listeners[_evtName] = [];
25
- }
26
- this._listeners[_evtName].push([!bind ? this : bind, callback]);
27
- },
28
- /**
29
- * Unregisters one or all callbacks binded to the given event
30
- *
31
- * @param {String} evtName name of the event
32
- * @param {Function} callback function to unregister. All callbacks if empty
33
- * @return void
34
- */
35
- unregister: function (evtName, callback) {
36
- const _evtName = this.evtName(evtName);
37
- if (typeof callback === 'undefined') {
38
- delete this._listeners[_evtName];
39
- }
40
- else {
41
- // splice re-indexes the array, so I'm not declaring `var len`
42
- // but array length is re-computed at every loop cycle
43
- for (let i = 0; i < this._listeners[_evtName].length; i++) {
44
- const listener = this._listeners[_evtName][i];
45
- if (listener[1] === callback) {
46
- this._listeners[_evtName].splice(i, 1);
47
- }
48
- }
49
- }
50
- },
51
- /**
52
- * Emits an event, all registered callbacks are called
53
- */
54
- emit: function (evtName, ...params) {
55
- const _evtName = this.evtName(evtName);
56
- if (typeof this._listeners[_evtName] !== 'undefined') {
57
- for (let i = 0, l = this._listeners[_evtName].length; i < l; i++) {
58
- const l = this._listeners[_evtName][i];
59
- // @ts-expect-error but it works
60
- l[1].call(this._listeners[_evtName][i][0], evtName, ...params);
61
- }
62
- }
63
- }
64
- };
65
- export default Dispatcher;
@@ -1,16 +0,0 @@
1
- export const log = (level, enable, ...args) => enable && console[level](...args);
2
- export const css = (name, styles, themeMode) => `${styles[name]} ${styles[`${name}-${themeMode}`]} react-cam-roi-${name}${themeMode ? `react-cam-roi-${name}-${themeMode}` : ''}`;
3
- export const humanize = (str) => {
4
- return str
5
- .replace(/([A-Z])/g, ' $1')
6
- .replace('_', ' ')
7
- .replace(/^./, (str) => str.toUpperCase());
8
- };
9
- export const formatString = (str, placeholders) => {
10
- Object.keys(placeholders).forEach((key) => {
11
- str = str.replace(`{${key}}`, placeholders[key].toString());
12
- });
13
- return str;
14
- };
15
- export const abs2Perc = (value, ref) => Math.round((value / ref) * 100 * 100) / 100;
16
- export const perc2Abs = (value, ref) => Math.round(ref * value * 100 / 100) / 100;
package/dist/index.js DELETED
@@ -1,4 +0,0 @@
1
- import RoiEditor from "./Components/RoiEditor";
2
- import UiProvider, { UiContext, DefaultUiContext } from "./Providers/UiProvider";
3
- import * as Types from "./Components/RoiEditor/Types";
4
- export { RoiEditor, UiProvider, UiContext, DefaultUiContext, Types };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes