@deepnoid/canvas 0.1.38 → 0.1.40
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/components/{AnnotationViewer → AnnotationCanvas}/_hooks/useImagePanZoom.d.ts +7 -13
- package/dist/components/{AnnotationViewer → AnnotationCanvas}/_hooks/useImagePanZoom.js +33 -23
- package/dist/components/AnnotationCanvas/_utils/createHistory.d.ts +11 -0
- package/dist/components/AnnotationCanvas/_utils/createHistory.js +34 -0
- package/dist/components/AnnotationCanvas/_utils/panZoom.d.ts +10 -0
- package/dist/components/AnnotationCanvas/_utils/panZoom.js +29 -0
- package/dist/components/AnnotationCanvas/index.d.ts +26 -0
- package/dist/components/AnnotationCanvas/index.js +83 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangle.d.ts +5 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangle.js +75 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.d.ts +30 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/rectangleUtils.js +211 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/useDrawEvents.d.ts +25 -0
- package/dist/components/AnnotationLayer/_hooks/drawEvents/useDrawEvents.js +42 -0
- package/dist/components/AnnotationLayer/_hooks/useCanvasDraw.d.ts +13 -0
- package/dist/components/AnnotationLayer/_hooks/useCanvasDraw.js +115 -0
- package/dist/components/AnnotationLayer/_hooks/useHotkeys.d.ts +7 -0
- package/dist/components/AnnotationLayer/_hooks/useHotkeys.js +15 -0
- package/dist/components/AnnotationLayer/_hooks/useMouse.d.ts +21 -0
- package/dist/components/AnnotationLayer/_hooks/useMouse.js +34 -0
- package/dist/components/AnnotationLayer/index.d.ts +10 -13
- package/dist/components/AnnotationLayer/index.js +116 -22
- package/dist/components/index.d.ts +8 -0
- package/dist/components/index.js +8 -0
- package/dist/enum/common.d.ts +13 -0
- package/dist/enum/common.js +15 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/types/index.d.ts +56 -0
- package/dist/utils/canvas.d.ts +3 -0
- package/dist/utils/canvas.js +37 -0
- package/dist/utils/common/cloneDeep.d.ts +1 -0
- package/dist/utils/common/cloneDeep.js +18 -0
- package/dist/utils/common/cloneDeepWith.d.ts +1 -0
- package/dist/utils/common/cloneDeepWith.js +34 -0
- package/dist/utils/common/isEqualWith.d.ts +2 -0
- package/dist/utils/common/isEqualWith.js +70 -0
- package/dist/utils/mouseActions.d.ts +8 -0
- package/dist/utils/mouseActions.js +19 -0
- package/dist/utils/pointTransform.d.ts +2 -0
- package/dist/utils/pointTransform.js +46 -0
- package/package.json +2 -1
- package/dist/components/AnnotationViewer/index.d.ts +0 -22
- package/dist/components/AnnotationViewer/index.js +0 -80
- package/dist/constants/graphic.d.ts +0 -1
- package/dist/constants/graphic.js +0 -1
- package/dist/types/coordinate.d.ts +0 -10
- package/dist/utils/graphic.d.ts +0 -48
- package/dist/utils/graphic.js +0 -158
- /package/dist/types/{coordinate.js → index.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const DRAW_LINE_SIZE = 4;
|
package/dist/utils/graphic.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Coordinate } from '../types/coordinate';
|
|
2
|
-
export declare const canvasCenterPoint: (canvas: HTMLCanvasElement, image: HTMLImageElement) => {
|
|
3
|
-
x: number;
|
|
4
|
-
y: number;
|
|
5
|
-
};
|
|
6
|
-
export declare const calculatorZoomPoint: (canvas: HTMLCanvasElement, movementX: number, movementY: number, dx: number, dy: number) => {
|
|
7
|
-
x: number;
|
|
8
|
-
y: number;
|
|
9
|
-
};
|
|
10
|
-
export declare const calculateInitZoom: (canvas: HTMLCanvasElement, image: HTMLImageElement) => number;
|
|
11
|
-
export declare const drawCanvas: (moveX: number, moveY: number, zoomX: number, zoomY: number, zoom: number, dx: number, dy: number, canvas_el?: HTMLCanvasElement, image?: HTMLImageElement, isClear?: boolean) => void;
|
|
12
|
-
export declare const drawRect: (context: CanvasRenderingContext2D, coordinate: Coordinate) => void;
|
|
13
|
-
export declare const setRectangleStyle: (context: CanvasRenderingContext2D, coordinate: Coordinate) => void;
|
|
14
|
-
export declare const resolutionCanvas: (canvas: HTMLCanvasElement | null | undefined, width?: number, height?: number) => HTMLCanvasElement | undefined;
|
|
15
|
-
type Point = {
|
|
16
|
-
x: number;
|
|
17
|
-
y: number;
|
|
18
|
-
};
|
|
19
|
-
export declare const __origin: (mouse: Point, origin: Point) => Point;
|
|
20
|
-
export declare const __move: (mouse: Point, move: Point) => Point;
|
|
21
|
-
export declare const __zoom: (mouse: Point, zoomPoint: Point, zoom: number, canvas_el: HTMLCanvasElement) => Point;
|
|
22
|
-
export declare const __rotate: (mouse: Point, rotate: number, center: Point) => Point;
|
|
23
|
-
/**
|
|
24
|
-
* [좌표 변형] 마우스 포인트 형태 변형
|
|
25
|
-
* 실행 순서 중요(graphic draw 순서와 동일)
|
|
26
|
-
*
|
|
27
|
-
* @param mousePoint: Point 현재 마우스 좌표
|
|
28
|
-
* @param movePoint: Point 이동 좌표
|
|
29
|
-
* @param zoomPoint: Point 확대 좌표
|
|
30
|
-
* @param originPoint: Point 원점 좌표
|
|
31
|
-
* @param zoom: number 확대 비율
|
|
32
|
-
* @param canvas_el: 캔버스 엘리먼트
|
|
33
|
-
* @param rotate: number 회전 각도 0~360
|
|
34
|
-
* @returns 캔버스 크기 해상도에 맞춰 변형된 마우스 좌표
|
|
35
|
-
*/
|
|
36
|
-
export declare const getMousePointTransform: (mousePoint: Point, movePoint: Point, zoomPoint: Point, originPoint: Point, zoom: number, canvas_el: HTMLCanvasElement, rotate?: number) => Point;
|
|
37
|
-
export declare const clearCanvasRect: (canvas: HTMLCanvasElement | null | undefined) => void;
|
|
38
|
-
/**
|
|
39
|
-
* 마우스 휠 기반 확대/축소 계산
|
|
40
|
-
* @param currentZoom 현재 zoom 값
|
|
41
|
-
* @param deltaY wheelEvent.deltaY
|
|
42
|
-
* @param minZoom 최소 zoom
|
|
43
|
-
* @param maxZoom 최대 zoom
|
|
44
|
-
* @param zoomUnit 확대/축소 단위
|
|
45
|
-
* @returns 계산된 zoom 값
|
|
46
|
-
*/
|
|
47
|
-
export declare const calculateZoom: (currentZoom: number, deltaY: number, minZoom: number, maxZoom: number, zoomUnit: number) => number;
|
|
48
|
-
export {};
|
package/dist/utils/graphic.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { DRAW_LINE_SIZE } from '../constants/graphic';
|
|
2
|
-
// [캔버스] 중앙포인트
|
|
3
|
-
export const canvasCenterPoint = (canvas, image) => {
|
|
4
|
-
const centerX = canvas.width / 2 - image.width / 2;
|
|
5
|
-
const centerY = canvas.height / 2 - image.height / 2;
|
|
6
|
-
return { x: centerX, y: centerY };
|
|
7
|
-
};
|
|
8
|
-
export const calculatorZoomPoint = (canvas, movementX, movementY, dx, dy) => {
|
|
9
|
-
let x = 0;
|
|
10
|
-
let y = 0;
|
|
11
|
-
if (canvas) {
|
|
12
|
-
x = -dx - movementX + canvas.width / 2;
|
|
13
|
-
y = -dy - movementY + canvas.height / 2;
|
|
14
|
-
}
|
|
15
|
-
return { x, y };
|
|
16
|
-
};
|
|
17
|
-
export const calculateInitZoom = (canvas, image) => {
|
|
18
|
-
if (!canvas || !image.naturalWidth)
|
|
19
|
-
return 1;
|
|
20
|
-
const canvasRatio = canvas.clientWidth / canvas.clientHeight;
|
|
21
|
-
const imageRatio = image.naturalWidth / image.naturalHeight;
|
|
22
|
-
return canvasRatio < imageRatio ? canvas.clientWidth / image.naturalWidth : canvas.clientHeight / image.naturalHeight;
|
|
23
|
-
};
|
|
24
|
-
// [캔버스] 그리기
|
|
25
|
-
export const drawCanvas = (moveX, moveY, zoomX, zoomY, zoom, dx, dy, canvas_el, image, isClear) => {
|
|
26
|
-
if (canvas_el) {
|
|
27
|
-
const context = canvas_el.getContext('2d');
|
|
28
|
-
if (isClear)
|
|
29
|
-
context?.clearRect(0, 0, canvas_el.width, canvas_el.height);
|
|
30
|
-
const resolution_ratio_x = canvas_el.width / canvas_el.clientWidth;
|
|
31
|
-
const resolution_ratio_y = canvas_el.height / canvas_el.clientHeight;
|
|
32
|
-
context?.translate(dx * resolution_ratio_x, dy * resolution_ratio_y);
|
|
33
|
-
context?.translate(moveX * resolution_ratio_x, moveY * resolution_ratio_y);
|
|
34
|
-
context?.translate(zoomX, zoomY);
|
|
35
|
-
context?.scale(zoom, zoom);
|
|
36
|
-
context?.translate(-zoomX, -zoomY);
|
|
37
|
-
try {
|
|
38
|
-
if (image)
|
|
39
|
-
context?.drawImage(image, 0, 0, image.width, image.height);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error('Failed to draw image', error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
export const drawRect = (context, coordinate) => {
|
|
47
|
-
setRectangleStyle(context, coordinate);
|
|
48
|
-
const { x, y, width, height } = coordinate;
|
|
49
|
-
context.lineWidth = DRAW_LINE_SIZE;
|
|
50
|
-
context.strokeRect(x, y, width, height);
|
|
51
|
-
};
|
|
52
|
-
export const setRectangleStyle = (context, coordinate) => {
|
|
53
|
-
if (coordinate.color === 'danger') {
|
|
54
|
-
context.strokeStyle = 'rgba(255, 70, 132, 1)';
|
|
55
|
-
}
|
|
56
|
-
if (coordinate.color === 'warning') {
|
|
57
|
-
context.strokeStyle = 'rgba(237, 164, 16, 1)';
|
|
58
|
-
}
|
|
59
|
-
if (coordinate.color === 'success') {
|
|
60
|
-
context.strokeStyle = 'rgba(36, 162, 91, 1)';
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
export const resolutionCanvas = (canvas, width, height) => {
|
|
64
|
-
if (!canvas)
|
|
65
|
-
return undefined;
|
|
66
|
-
const newCanvas = canvas;
|
|
67
|
-
newCanvas.width = width || newCanvas.clientWidth;
|
|
68
|
-
newCanvas.height = height || newCanvas.clientHeight;
|
|
69
|
-
return newCanvas;
|
|
70
|
-
};
|
|
71
|
-
// [좌표 변형] 원점
|
|
72
|
-
export const __origin = (mouse, origin) => {
|
|
73
|
-
const x = mouse.x - origin.x;
|
|
74
|
-
const y = mouse.y - origin.y;
|
|
75
|
-
return {
|
|
76
|
-
x,
|
|
77
|
-
y,
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
// [좌표 변형] 이동
|
|
81
|
-
export const __move = (mouse, move) => {
|
|
82
|
-
const x = mouse.x - move.x;
|
|
83
|
-
const y = mouse.y - move.y;
|
|
84
|
-
return {
|
|
85
|
-
x,
|
|
86
|
-
y,
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
// [좌표 변형] 확대, 축소
|
|
90
|
-
export const __zoom = (mouse, zoomPoint, zoom, canvas_el) => {
|
|
91
|
-
const resolution_ratio_x = canvas_el.width / canvas_el.clientWidth;
|
|
92
|
-
const resolution_ratio_y = canvas_el.height / canvas_el.clientHeight;
|
|
93
|
-
let x = mouse.x * (1 / zoom) * resolution_ratio_x;
|
|
94
|
-
let y = mouse.y * (1 / zoom) * resolution_ratio_y;
|
|
95
|
-
x = x + zoomPoint.x;
|
|
96
|
-
y = y + zoomPoint.y;
|
|
97
|
-
x = x - zoomPoint.x * (1 / zoom);
|
|
98
|
-
y = y - zoomPoint.y * (1 / zoom);
|
|
99
|
-
return {
|
|
100
|
-
x,
|
|
101
|
-
y,
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
// [좌표 변형] 회전
|
|
105
|
-
export const __rotate = (mouse, rotate, center) => {
|
|
106
|
-
const rad = (rotate * Math.PI) / 180; // Convert degree to radian
|
|
107
|
-
const cos = Math.cos(rad);
|
|
108
|
-
const sin = Math.sin(rad);
|
|
109
|
-
const x = cos * (mouse.x - center.x) - sin * (mouse.y - center.y) + center.x;
|
|
110
|
-
const y = sin * (mouse.x - center.x) + cos * (mouse.y - center.y) + center.y;
|
|
111
|
-
return { x, y };
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* [좌표 변형] 마우스 포인트 형태 변형
|
|
115
|
-
* 실행 순서 중요(graphic draw 순서와 동일)
|
|
116
|
-
*
|
|
117
|
-
* @param mousePoint: Point 현재 마우스 좌표
|
|
118
|
-
* @param movePoint: Point 이동 좌표
|
|
119
|
-
* @param zoomPoint: Point 확대 좌표
|
|
120
|
-
* @param originPoint: Point 원점 좌표
|
|
121
|
-
* @param zoom: number 확대 비율
|
|
122
|
-
* @param canvas_el: 캔버스 엘리먼트
|
|
123
|
-
* @param rotate: number 회전 각도 0~360
|
|
124
|
-
* @returns 캔버스 크기 해상도에 맞춰 변형된 마우스 좌표
|
|
125
|
-
*/
|
|
126
|
-
export const getMousePointTransform = (mousePoint, movePoint, zoomPoint, originPoint, zoom, canvas_el, rotate = 0) => {
|
|
127
|
-
let mouse = mousePoint;
|
|
128
|
-
mouse = __rotate(mouse, rotate, { x: canvas_el.width / 2, y: canvas_el.height / 2 });
|
|
129
|
-
mouse = __origin(mouse, originPoint);
|
|
130
|
-
mouse = __move(mouse, movePoint);
|
|
131
|
-
mouse = __zoom(mouse, zoomPoint, zoom, canvas_el);
|
|
132
|
-
return mouse;
|
|
133
|
-
};
|
|
134
|
-
export const clearCanvasRect = (canvas) => {
|
|
135
|
-
if (!canvas)
|
|
136
|
-
return;
|
|
137
|
-
const ctx = canvas.getContext('2d');
|
|
138
|
-
const resolvedCanvas = resolutionCanvas(canvas);
|
|
139
|
-
if (resolvedCanvas)
|
|
140
|
-
ctx?.clearRect(0, 0, resolvedCanvas.width, resolvedCanvas.height);
|
|
141
|
-
};
|
|
142
|
-
/**
|
|
143
|
-
* 마우스 휠 기반 확대/축소 계산
|
|
144
|
-
* @param currentZoom 현재 zoom 값
|
|
145
|
-
* @param deltaY wheelEvent.deltaY
|
|
146
|
-
* @param minZoom 최소 zoom
|
|
147
|
-
* @param maxZoom 최대 zoom
|
|
148
|
-
* @param zoomUnit 확대/축소 단위
|
|
149
|
-
* @returns 계산된 zoom 값
|
|
150
|
-
*/
|
|
151
|
-
export const calculateZoom = (currentZoom, deltaY, minZoom, maxZoom, zoomUnit) => {
|
|
152
|
-
let newZoom = deltaY < 0 ? currentZoom * (1 / zoomUnit) : currentZoom * zoomUnit;
|
|
153
|
-
if (newZoom > maxZoom)
|
|
154
|
-
newZoom = maxZoom;
|
|
155
|
-
if (newZoom < minZoom)
|
|
156
|
-
newZoom = minZoom;
|
|
157
|
-
return newZoom;
|
|
158
|
-
};
|
|
File without changes
|