@abidibo/react-cam-roi 0.12.1 → 0.13.1

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.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # React Cam ROI
2
2
 
3
3
  This is a react component which lets you draw regions of interest (ROI) over images, manage metadata and import/export everything.
4
- Metadata are dynamic information that can be attached to the whole image and/or to each ROI. The number of drawable ROIs can also be configured.
4
+ Metadata are dynamic information that can be attached as a whole and/or to each ROI. The number and type of drawable ROIs can also be configured.
5
5
 
6
6
  ![Screenshot](./react-cam-roi-s.png)
7
7
 
8
- It provides one component: `RoiEditor` and one provider: `UiProvider`. The editor lets you draw regions of interest over a given image (url). Each ROI can have dynamic metadata attached.
8
+ It provides one component: `RoiEditor` and one provider: `UiProvider`. The editor lets you add metadata and draw regions of interest over a given image (url).
9
9
 
10
10
  Export and import functionality is also provided.
11
11
 
package/dist/index.cjs.js CHANGED
@@ -115,7 +115,17 @@ var formatString = function (str, placeholders) {
115
115
  return str;
116
116
  };
117
117
  var abs2Perc = function (value, ref) { return Math.round((value / ref) * 100 * 100) / 100; };
118
- var perc2Abs = function (value, ref) { return Math.round(ref * value * 100 / 100) / 100; };
118
+ var perc2Abs = function (value, ref) { return Math.round((ref * value * 100) / 100) / 100; };
119
+ var defaultTo = function (dft) { return function (value) { return value !== null && value !== void 0 ? value : dft; }; };
120
+ var compose = function () {
121
+ var fns = [];
122
+ for (var _i = 0; _i < arguments.length; _i++) {
123
+ fns[_i] = arguments[_i];
124
+ }
125
+ return function (x) {
126
+ return fns.reduceRight(function (y, f) { return f(y); }, x);
127
+ };
128
+ };
119
129
 
120
130
  var styles$e = {"bool-field":"BoolField-module_bool-field__-Qg7I","bool-field-light":"BoolField-module_bool-field-light__CHITs","bool-field-dark":"BoolField-module_bool-field-dark__gy9uQ","bool-field-error":"BoolField-module_bool-field-error__qJV-E","bool-field-label":"BoolField-module_bool-field-label__LZbjy","bool-field-label-error":"BoolField-module_bool-field-label-error__gBzdk","bool-field-helper-text":"BoolField-module_bool-field-helper-text__fH8fC","bool-field-helper-text-error":"BoolField-module_bool-field-helper-text-error__McdWn"};
121
131
 
@@ -571,6 +581,7 @@ var DefaultUiContext = {
571
581
  pointer: 'Selection',
572
582
  pointerHelpText: 'click a shape to select it',
573
583
  rect: 'Rectangle',
584
+ rectangle: 'Rectangle',
574
585
  rectHelpText: 'click and drag to draw the rectangle',
575
586
  requiredField: 'This field is required',
576
587
  roiMultiplicityEqRule: 'a number of "{role}" ({type}) equal to {threshold}',
@@ -1461,7 +1472,7 @@ var RoisInfo = function () {
1461
1472
  var _d = useEditorContext(), configuration = _d.configuration, presetName = _d.presetName, setPresetName = _d.setPresetName, presetDescription = _d.presetDescription, setPresetDescription = _d.setPresetDescription;
1462
1473
  if (!((_a = configuration.rois) === null || _a === void 0 ? void 0 : _a.length))
1463
1474
  return null;
1464
- return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { style: { marginBottom: '1rem' }, children: jsxRuntime.jsx(TextField, { required: true, value: presetName, onChange: setPresetName, label: strings.presetName, fullWidth: true }) }), jsxRuntime.jsx("div", { style: { marginBottom: '1rem' }, children: jsxRuntime.jsx(TextField, { value: presetDescription, onChange: setPresetDescription, label: strings.presetDescription, fullWidth: true }) }), ((_b = configuration.options) === null || _b === void 0 ? void 0 : _b.description) && jsxRuntime.jsx(Typography, { children: configuration.options.description }), jsxRuntime.jsxs(Typography, { component: "div", children: [strings.roisToBeDrawn, ":"] }), jsxRuntime.jsx("ul", { children: configuration.rois.map(function (r) {
1475
+ return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { style: { marginBottom: '1rem' }, children: jsxRuntime.jsx(TextField, { required: true, value: presetName, onChange: compose(setPresetName, defaultTo('')), label: strings.presetName, fullWidth: true }) }), jsxRuntime.jsx("div", { style: { marginBottom: '1rem' }, children: jsxRuntime.jsx(TextField, { value: presetDescription, onChange: compose(setPresetDescription, defaultTo('')), label: strings.presetDescription, fullWidth: true }) }), ((_b = configuration.options) === null || _b === void 0 ? void 0 : _b.description) && jsxRuntime.jsx(Typography, { children: configuration.options.description }), jsxRuntime.jsxs(Typography, { component: "div", children: [strings.roisToBeDrawn, ":"] }), jsxRuntime.jsx("ul", { children: configuration.rois.map(function (r) {
1465
1476
  var _a, _b;
1466
1477
  var rule;
1467
1478
  var data = {
@@ -1579,7 +1590,7 @@ var ParametersModalForm = function (_a) {
1579
1590
  }
1580
1591
  }
1581
1592
  };
1582
- var form = (jsxRuntime.jsxs("div", { className: css('form', styles$4, null), children: [shapeType && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextField, { required: true, label: strings.name, type: "text", value: name, onChange: setName, error: !!errors.name, helperText: errors.name, readOnly: readOnly }), jsxRuntime.jsx(RoleField, { required: true, value: role, onChange: setRole, error: !!errors.role, helperText: errors.role, shapeType: shapeType, readOnly: readOnly, disabled: readOnly })] })), parameters.map(function (parameter) {
1593
+ var form = (jsxRuntime.jsxs("div", { className: css('form', styles$4, null), children: [shapeType && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(TextField, { required: true, label: strings.name, type: "text", value: name, onChange: compose(setName, defaultTo('')), error: !!errors.name, helperText: errors.name, readOnly: readOnly }), jsxRuntime.jsx(RoleField, { required: true, value: role, onChange: compose(setRole, defaultTo('')), error: !!errors.role, helperText: errors.role, shapeType: shapeType, readOnly: readOnly, disabled: readOnly })] })), parameters.map(function (parameter) {
1583
1594
  switch (parameter.type) {
1584
1595
  case 'string':
1585
1596
  return (jsxRuntime.jsx(ParameterField, { value: String((readOnly ? readonlyFields : fields)[parameter.codename]), onChange: setField(parameter.codename), parameter: parameter, errors: errors, readOnly: readOnly }, parameter.codename));
@@ -1723,6 +1734,8 @@ var Toolbar = function (_a) {
1723
1734
  var rectangleEnabled = configuration.rois.find(function (r) { return r.type === "rect" /* ToolEnum.Rectangle */; }) &&
1724
1735
  canDrawShape(configuration, "rect" /* ToolEnum.Rectangle */, shapes);
1725
1736
  var handleRenderFullImagePolygon = function () {
1737
+ if (!canvasRef.current)
1738
+ return;
1726
1739
  renderFullImagePolygon(editorId, canvasRef.current, activeColor, imageSize);
1727
1740
  };
1728
1741
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: css('toolbar', styles$1, themeMode), children: enableRois(configuration) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: strings.selection, children: jsxRuntime.jsx(IconButton, { onClick: setTool("pointer" /* ToolEnum.Pointer */), children: jsxRuntime.jsx(PointerIcon, { color: iconColor("pointer" /* ToolEnum.Pointer */) }) }) }), (!hideForbiddenTools || pointEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.point, children: jsxRuntime.jsx(IconButton, { onClick: setTool("point" /* ToolEnum.Point */), disabled: !pointEnabled, children: jsxRuntime.jsx(PointIcon, { color: iconColor("point" /* ToolEnum.Point */) }) }) })), (!hideForbiddenTools || polylineEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.polyline, children: jsxRuntime.jsx(IconButton, { onClick: setTool("polyline" /* ToolEnum.Polyline */), disabled: !polylineEnabled, children: jsxRuntime.jsx(PolylineIcon, { color: iconColor("polyline" /* ToolEnum.Polyline */) }) }) })), (!hideForbiddenTools || polygonEnabled) && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Tooltip, { title: strings.polygon, children: jsxRuntime.jsx(IconButton, { onClick: setTool("polygon" /* ToolEnum.Polygon */), disabled: !polygonEnabled, children: jsxRuntime.jsx(PolygonIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) }) }), jsxRuntime.jsx(Tooltip, { title: strings.fullImage, children: jsxRuntime.jsx(IconButton, { onClick: handleRenderFullImagePolygon, disabled: !polygonEnabled, children: jsxRuntime.jsx(FullRoiIcon, { color: iconColor("polygon" /* ToolEnum.Polygon */) }) }) })] })), (!hideForbiddenTools || rectangleEnabled) && (jsxRuntime.jsx(Tooltip, { title: strings.rect, children: jsxRuntime.jsx(IconButton, { onClick: setTool("rect" /* ToolEnum.Rectangle */), disabled: !rectangleEnabled, children: jsxRuntime.jsx(RectangleIcon, { color: iconColor("rect" /* ToolEnum.Rectangle */) }) }) })), jsxRuntime.jsx(ColorPicker, { style: { marginLeft: 'auto', marginRight: '.5rem' } })] })) }), enableRois(configuration) && (jsxRuntime.jsx("div", { className: css('toolbar-helper', styles$1, themeMode), children: jsxRuntime.jsxs(Typography, { children: [strings[activeTool], ": ", strings["".concat(activeTool, "HelpText")]] }) }))] }));