@deepnoid/canvas 0.1.80 → 0.1.81

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.
@@ -1,6 +1,6 @@
1
1
  import { cloneDeep } from '../../utils/cloneDeep';
2
2
  import { isMouseClickAction, isMouseDragAction, MouseAction } from '../../utils/mouseActions';
3
- import { isInsideImage, clampBoundingBoxToImage } from './rectangleMath';
3
+ import { isInsideImage, clampBoundingBoxToImage, ACTIVE_POINT_SIZE } from './rectangleMath';
4
4
  import { getCanvasMousePoint } from '../../utils/mousePoint';
5
5
  import { updateActiveRectangleAnchor } from './rectangleHitTest';
6
6
  import { selectAnnotationAtPoint } from '../hitTest';
@@ -46,13 +46,31 @@ export class RectangleController {
46
46
  this.hasMoved = false;
47
47
  const annotations = this.engine.getAnnotations();
48
48
  const currentSelected = this.engine.getSelectedAnnotation();
49
- const targetAnnotation = selectAnnotationAtPoint(zoom, mousePoint, annotations);
50
- if (targetAnnotation !== currentSelected) {
51
- this.engine.setSelectedAnnotation(targetAnnotation);
52
- this.engine.setAnnotations(annotations);
49
+ // Check if we hit the currently selected annotation first
50
+ let targetAnnotation = null;
51
+ if (currentSelected && currentSelected.type === DrawMode.RECTANGLE) {
52
+ const { x, y, width, height } = currentSelected;
53
+ const padding = ACTIVE_POINT_SIZE / zoom;
54
+ const isInsideSelected = mousePoint.x >= x - padding &&
55
+ mousePoint.x <= x + width + padding &&
56
+ mousePoint.y >= y - padding &&
57
+ mousePoint.y <= y + height + padding;
58
+ if (isInsideSelected) {
59
+ targetAnnotation = currentSelected;
60
+ }
61
+ }
62
+ if (targetAnnotation) {
63
+ this.targetIndexOnBegin = annotations.indexOf(targetAnnotation);
64
+ this.rectangleAnchor = updateActiveRectangleAnchor(zoom, mousePoint, targetAnnotation);
65
+ }
66
+ else {
67
+ this.targetIndexOnBegin = -1;
68
+ this.rectangleAnchor = null;
69
+ // We explicitly DO NOT call selectAnnotationAtPoint here.
70
+ // If the user drags, we draw a new rectangle.
71
+ // If the user clicks (releases without moving), end() will handle selecting whatever is under the mouse.
72
+ this.engine.setSelectedAnnotation(null);
53
73
  }
54
- this.targetIndexOnBegin = targetAnnotation ? annotations.indexOf(targetAnnotation) : -1;
55
- this.rectangleAnchor = updateActiveRectangleAnchor(zoom, mousePoint, targetAnnotation);
56
74
  return true;
57
75
  }
58
76
  move(event) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.80",
3
+ "version": "0.1.81",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",