@deepnoid/canvas 0.1.82 → 0.1.84
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/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AnnotationViewer, AnnotationEditor } from './react';
|
|
2
|
+
export type { AnnotationCanvasHandle } from './react';
|
|
2
3
|
export type { Label, ApplyAnnotationStyle } from './engine/types';
|
|
3
4
|
export type { Rectangle, Annotation } from './engine/annotation/annotationTypes';
|
|
4
5
|
export { DrawMode } from './engine/annotation/annotationTypes';
|
|
@@ -23,5 +23,8 @@ export type AnnotationCanvasProps = {
|
|
|
23
23
|
enableHotkeys?: boolean;
|
|
24
24
|
editable?: boolean;
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
export interface AnnotationCanvasHandle {
|
|
27
|
+
resetImageSize: () => void;
|
|
28
|
+
}
|
|
29
|
+
declare const AnnotationCanvas: import("react").ForwardRefExoticComponent<AnnotationCanvasProps & import("react").RefAttributes<AnnotationCanvasHandle>>;
|
|
27
30
|
export default AnnotationCanvas;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useEffect, useRef, useState } 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 = ({ image, annotations = [], setAnnotations, options, drawing, events, enableHotkeys = true, editable = true, }) => {
|
|
15
|
+
const AnnotationCanvas = forwardRef(({ image, annotations = [], setAnnotations, options, drawing, events, enableHotkeys = true, editable = true, }, ref) => {
|
|
16
16
|
const { panZoomEnabled, zoom, ZoomButton, resetOnImageChange = false } = options || {};
|
|
17
17
|
const { onImageLoadSuccess, onImageLoadError } = events || {};
|
|
18
18
|
const containerRef = useRef(null);
|
|
@@ -160,11 +160,17 @@ const AnnotationCanvas = ({ image, annotations = [], setAnnotations, options, dr
|
|
|
160
160
|
useEffect(() => engineRef.current?.setPanZoomEnabled(!!panZoomEnabled), [panZoomEnabled]);
|
|
161
161
|
useEffect(() => engineRef.current?.setEditable(editable), [editable]);
|
|
162
162
|
useEffect(() => engineRef.current?.setDrawing(drawing), [drawing]);
|
|
163
|
+
/* ---------- Imperative Handle ---------- */
|
|
164
|
+
useImperativeHandle(ref, () => ({
|
|
165
|
+
resetImageSize: () => {
|
|
166
|
+
engineRef.current?.initImageCanvas(true);
|
|
167
|
+
}
|
|
168
|
+
}));
|
|
163
169
|
/* ---------- Render ---------- */
|
|
164
|
-
return (_jsx("div", { ref: containerRef, style: { width: '100%', height: '100%', position: 'relative', flex: 1 }, 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) => {
|
|
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) => {
|
|
165
171
|
if (e.key === 'Escape' || e.code === 'Escape') {
|
|
166
172
|
engineRef.current?.onKeyDown(e.nativeEvent);
|
|
167
173
|
}
|
|
168
174
|
}, children: ZoomButton && (_jsx(ZoomButton, { onClick: () => engineRef.current?.initImageCanvas(true), children: engineRef.current?.getZoomRatioLabel() })) }));
|
|
169
|
-
};
|
|
175
|
+
});
|
|
170
176
|
export default AnnotationCanvas;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
import { AnnotationCanvasProps } from './AnnotationCanvas';
|
|
1
|
+
import { AnnotationCanvasProps, AnnotationCanvasHandle } from './AnnotationCanvas';
|
|
2
|
+
export type { AnnotationCanvasHandle };
|
|
2
3
|
export type AnnotationViewerProps = Omit<AnnotationCanvasProps, 'editable' | 'drawing' | 'events'> & {
|
|
3
4
|
drawing: Pick<AnnotationCanvasProps['drawing'], 'lineSize' | 'applyStyle'>;
|
|
4
5
|
events: Pick<AnnotationCanvasProps['events'], 'onImageLoadSuccess' | 'onImageLoadError'>;
|
|
5
6
|
};
|
|
6
|
-
export declare const AnnotationViewer:
|
|
7
|
+
export declare const AnnotationViewer: import("react").ForwardRefExoticComponent<Omit<AnnotationCanvasProps, "drawing" | "events" | "editable"> & {
|
|
8
|
+
drawing: Pick<AnnotationCanvasProps["drawing"], "lineSize" | "applyStyle">;
|
|
9
|
+
events: Pick<AnnotationCanvasProps["events"], "onImageLoadSuccess" | "onImageLoadError">;
|
|
10
|
+
} & import("react").RefAttributes<AnnotationCanvasHandle>>;
|
|
7
11
|
export type AnnotationEditorProps = AnnotationCanvasProps;
|
|
8
|
-
export declare const AnnotationEditor: (
|
|
12
|
+
export declare const AnnotationEditor: import("react").ForwardRefExoticComponent<AnnotationCanvasProps & import("react").RefAttributes<AnnotationCanvasHandle>>;
|
package/dist/react/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef } from 'react';
|
|
2
3
|
import AnnotationCanvas from './AnnotationCanvas';
|
|
3
|
-
export const AnnotationViewer = (props) => {
|
|
4
|
-
return (_jsx(AnnotationCanvas, { ...props, editable: false }));
|
|
5
|
-
};
|
|
6
|
-
export const AnnotationEditor = (props) => {
|
|
7
|
-
return (_jsx(AnnotationCanvas, { ...props, editable: true }));
|
|
8
|
-
};
|
|
4
|
+
export const AnnotationViewer = forwardRef((props, ref) => {
|
|
5
|
+
return (_jsx(AnnotationCanvas, { ...props, editable: false, ref: ref }));
|
|
6
|
+
});
|
|
7
|
+
export const AnnotationEditor = forwardRef((props, ref) => {
|
|
8
|
+
return (_jsx(AnnotationCanvas, { ...props, editable: true, ref: ref }));
|
|
9
|
+
});
|