@deepnoid/canvas 0.1.84 → 0.1.85

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.
@@ -22,6 +22,7 @@ export type AnnotationCanvasProps = {
22
22
  };
23
23
  enableHotkeys?: boolean;
24
24
  editable?: boolean;
25
+ keepCrossOnImageChange?: boolean;
25
26
  };
26
27
  export interface AnnotationCanvasHandle {
27
28
  resetImageSize: () => void;
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useEffect, useRef, useState, forwardRef, useImperativeHandle } from 'react';
3
+ import { useEffect, useRef, useState, forwardRef, useImperativeHandle, } from 'react';
4
4
  import { AnnotationEngine } from '../engine/public/annotationEngine';
5
5
  import useResizeObserver from './hooks/useResizeObserver';
6
6
  import { useDebounce } from './hooks/useDebounce';
@@ -12,7 +12,7 @@ function safeRemove(parent, child) {
12
12
  parent.removeChild(child);
13
13
  }
14
14
  }
15
- const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations, options, drawing, events, enableHotkeys = true, editable = true, }, ref) => {
15
+ const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations, options, drawing, events, enableHotkeys = true, editable = true, keepCrossOnImageChange = false, }, ref) => {
16
16
  const { panZoomEnabled, zoom, ZoomButton, resetOnImageChange = false } = options || {};
17
17
  const { onImageLoadSuccess, onImageLoadError } = events || {};
18
18
  const containerRef = useRef(null);
@@ -20,6 +20,7 @@ const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations,
20
20
  const pendingAnnotationsRef = useRef(null);
21
21
  const imageLoadingRef = useRef(false);
22
22
  const engineIdRef = useRef(0);
23
+ const clientMousePointRef = useRef(null);
23
24
  const [, forceRender] = useState(0);
24
25
  /* ---------- Resize Observer ---------- */
25
26
  useResizeObserver({
@@ -110,6 +111,12 @@ const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations,
110
111
  container.insertBefore(imageCanvas, firstChild);
111
112
  container.insertBefore(annotationsCanvas, firstChild);
112
113
  engine.initImageCanvas(resetOnImageChange);
114
+ if (keepCrossOnImageChange && clientMousePointRef.current) {
115
+ engine.onMouseMove({
116
+ clientX: clientMousePointRef.current.x,
117
+ clientY: clientMousePointRef.current.y,
118
+ });
119
+ }
113
120
  if (prevEngine) {
114
121
  safeRemove(container, prevEngine.getImageCanvas());
115
122
  safeRemove(container, prevEngine.getAnnotationsCanvas());
@@ -164,10 +171,16 @@ const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations,
164
171
  useImperativeHandle(ref, () => ({
165
172
  resetImageSize: () => {
166
173
  engineRef.current?.initImageCanvas(true);
167
- }
174
+ },
168
175
  }));
169
176
  /* ---------- Render ---------- */
170
- return (_jsx("div", { ref: containerRef, style: { width: '100%', height: '100%', position: 'relative', flex: 1, outline: 'none' }, onWheel: (e) => engineRef.current?.onWheel(e.nativeEvent), onMouseDown: (e) => engineRef.current?.onMouseDown(e.nativeEvent), onMouseMove: (e) => engineRef.current?.onMouseMove(e.nativeEvent), onMouseUp: (e) => engineRef.current?.onMouseUp(e.nativeEvent), onMouseLeave: (e) => engineRef.current?.onMouseLeave(e.nativeEvent), onContextMenu: (e) => e.preventDefault(), tabIndex: 0, onKeyDown: (e) => {
177
+ return (_jsx("div", { ref: containerRef, style: { width: '100%', height: '100%', position: 'relative', flex: 1, outline: 'none' }, onWheel: (e) => engineRef.current?.onWheel(e.nativeEvent), onMouseDown: (e) => engineRef.current?.onMouseDown(e.nativeEvent), onMouseMove: (e) => {
178
+ clientMousePointRef.current = { x: e.clientX, y: e.clientY };
179
+ engineRef.current?.onMouseMove(e.nativeEvent);
180
+ }, onMouseUp: (e) => engineRef.current?.onMouseUp(e.nativeEvent), onMouseLeave: (e) => {
181
+ clientMousePointRef.current = null;
182
+ engineRef.current?.onMouseLeave(e.nativeEvent);
183
+ }, onContextMenu: (e) => e.preventDefault(), tabIndex: 0, onKeyDown: (e) => {
171
184
  if (e.key === 'Escape' || e.code === 'Escape') {
172
185
  engineRef.current?.onKeyDown(e.nativeEvent);
173
186
  }
@@ -8,5 +8,9 @@ export declare const AnnotationViewer: import("react").ForwardRefExoticComponent
8
8
  drawing: Pick<AnnotationCanvasProps["drawing"], "lineSize" | "applyStyle">;
9
9
  events: Pick<AnnotationCanvasProps["events"], "onImageLoadSuccess" | "onImageLoadError">;
10
10
  } & import("react").RefAttributes<AnnotationCanvasHandle>>;
11
- export type AnnotationEditorProps = AnnotationCanvasProps;
12
- export declare const AnnotationEditor: import("react").ForwardRefExoticComponent<AnnotationCanvasProps & import("react").RefAttributes<AnnotationCanvasHandle>>;
11
+ export type AnnotationEditorProps = AnnotationCanvasProps & {
12
+ keepCrossOnImageChange?: boolean;
13
+ };
14
+ export declare const AnnotationEditor: import("react").ForwardRefExoticComponent<AnnotationCanvasProps & {
15
+ keepCrossOnImageChange?: boolean;
16
+ } & import("react").RefAttributes<AnnotationCanvasHandle>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.84",
3
+ "version": "0.1.85",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",