react-screenshots 0.6.0 → 0.6.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/dist/electron.html +1 -1
- package/dist/index.html +1 -1
- package/dist/static/css/{electron.7eee95c8.css → electron.23cabfe1.css} +1 -1
- package/dist/static/css/{index.7eee95c8.css → index.23cabfe1.css} +1 -1
- package/dist/static/js/233.d0e4a692.js +12 -0
- package/dist/static/js/electron.08760a25.js +1 -0
- package/dist/static/js/{index.fbe72af7.js → index.a28d0d1c.js} +1 -1
- package/lib/Screenshots/ScreenshotsBackground/getBoundsByPoints.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsBackground/index.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsBackground/index.js +8 -8
- package/lib/Screenshots/ScreenshotsCanvas/getPoints.d.ts +2 -2
- package/lib/Screenshots/ScreenshotsCanvas/index.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsCanvas/index.js +26 -26
- package/lib/Screenshots/ScreenshotsCanvas/isPointInDraw.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsColor/index.js +1 -1
- package/lib/Screenshots/ScreenshotsContext.d.ts +3 -3
- package/lib/Screenshots/ScreenshotsContext.js +1 -1
- package/lib/Screenshots/ScreenshotsOption/index.d.ts +3 -3
- package/lib/Screenshots/ScreenshotsOption/index.js +2 -2
- package/lib/Screenshots/ScreenshotsSize/index.js +1 -1
- package/lib/Screenshots/ScreenshotsSizeColor/index.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsSizeColor/index.js +1 -1
- package/lib/Screenshots/ScreenshotsTextarea/index.js +2 -2
- package/lib/Screenshots/composeImage.d.ts +1 -1
- package/lib/Screenshots/exports.d.ts +2 -2
- package/lib/Screenshots/hooks/useCanvasPointerDown.d.ts +1 -0
- package/lib/Screenshots/hooks/useCanvasPointerDown.js +15 -0
- package/lib/Screenshots/hooks/useCanvasPointerMove.d.ts +1 -0
- package/lib/Screenshots/hooks/useCanvasPointerMove.js +15 -0
- package/lib/Screenshots/hooks/useCanvasPointerUp.d.ts +1 -0
- package/lib/Screenshots/hooks/useCanvasPointerUp.js +15 -0
- package/lib/Screenshots/hooks/useDrawSelect.d.ts +1 -1
- package/lib/Screenshots/hooks/useDrawSelect.js +5 -5
- package/lib/Screenshots/hooks/useEmitter.d.ts +8 -0
- package/lib/Screenshots/hooks/useEmitter.js +43 -0
- package/lib/Screenshots/hooks/useReset.js +4 -4
- package/lib/Screenshots/index.js +13 -11
- package/lib/Screenshots/operations/Arrow/draw.d.ts +1 -1
- package/lib/Screenshots/operations/Arrow/draw.js +1 -1
- package/lib/Screenshots/operations/Arrow/index.js +15 -15
- package/lib/Screenshots/operations/Brush/draw.d.ts +1 -1
- package/lib/Screenshots/operations/Brush/index.js +15 -15
- package/lib/Screenshots/operations/Ellipse/draw.d.ts +1 -1
- package/lib/Screenshots/operations/Ellipse/draw.js +1 -1
- package/lib/Screenshots/operations/Ellipse/index.js +9 -9
- package/lib/Screenshots/operations/Mosaic/index.js +16 -16
- package/lib/Screenshots/operations/Ok/index.js +2 -2
- package/lib/Screenshots/operations/Rectangle/draw.d.ts +1 -1
- package/lib/Screenshots/operations/Rectangle/draw.js +1 -1
- package/lib/Screenshots/operations/Rectangle/index.js +9 -9
- package/lib/Screenshots/operations/Redo/index.js +1 -1
- package/lib/Screenshots/operations/Save/index.js +1 -1
- package/lib/Screenshots/operations/Text/index.js +14 -14
- package/lib/Screenshots/operations/Undo/index.js +1 -1
- package/lib/Screenshots/operations/index.js +8 -8
- package/lib/Screenshots/operations/utils.d.ts +1 -1
- package/lib/Screenshots/types.d.ts +4 -4
- package/lib/electron/app.js +1 -3
- package/package.json +6 -6
- package/dist/static/js/589.5602a0fa.js +0 -12
- package/dist/static/js/electron.1c6ab61b.js +0 -1
- package/lib/Screenshots/hooks/useCanvasMousedown.d.ts +0 -1
- package/lib/Screenshots/hooks/useCanvasMousedown.js +0 -15
- package/lib/Screenshots/hooks/useCanvasMousemove.d.ts +0 -1
- package/lib/Screenshots/hooks/useCanvasMousemove.js +0 -15
- package/lib/Screenshots/hooks/useCanvasMouseup.d.ts +0 -1
- package/lib/Screenshots/hooks/useCanvasMouseup.js +0 -15
- package/lib/Screenshots/hooks/useEmiter.d.ts +0 -8
- package/lib/Screenshots/hooks/useEmiter.js +0 -41
|
@@ -17,7 +17,7 @@ const Screenshots_ScreenshotsOption = /*#__PURE__*/ memo(function({ open, conten
|
|
|
17
17
|
const [position, setPosition] = useState(null);
|
|
18
18
|
const [offsetX, setOffsetX] = useState(0);
|
|
19
19
|
const getPopoverEl = ()=>{
|
|
20
|
-
if (!popoverRef.current) popoverRef.current = document.createElement(
|
|
20
|
+
if (!popoverRef.current) popoverRef.current = document.createElement("div");
|
|
21
21
|
return popoverRef.current;
|
|
22
22
|
};
|
|
23
23
|
useEffect(()=>{
|
|
@@ -71,7 +71,7 @@ const Screenshots_ScreenshotsOption = /*#__PURE__*/ memo(function({ open, conten
|
|
|
71
71
|
ref: contentRef,
|
|
72
72
|
className: "screenshots-option",
|
|
73
73
|
style: {
|
|
74
|
-
visibility: position ?
|
|
74
|
+
visibility: position ? "visible" : "hidden",
|
|
75
75
|
transform: `translate(${position?.x ?? 0}px, ${position?.y ?? 0}px)`
|
|
76
76
|
},
|
|
77
77
|
"data-placement": placement,
|
|
@@ -16,7 +16,7 @@ const Screenshots_ScreenshotsSize = /*#__PURE__*/ memo(function({ value, onChang
|
|
|
16
16
|
if (size === value) classNames.push('screenshots-size-active');
|
|
17
17
|
return /*#__PURE__*/ jsx("div", {
|
|
18
18
|
className: classNames.join(' '),
|
|
19
|
-
onClick: ()=>onChange
|
|
19
|
+
onClick: ()=>onChange?.(size),
|
|
20
20
|
children: /*#__PURE__*/ jsx("div", {
|
|
21
21
|
className: "screenshots-size-pointer",
|
|
22
22
|
style: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { memo } from "react";
|
|
3
|
-
import ScreenshotsSize from "../ScreenshotsSize/index.js";
|
|
4
3
|
import ScreenshotsColor from "../ScreenshotsColor/index.js";
|
|
4
|
+
import ScreenshotsSize from "../ScreenshotsSize/index.js";
|
|
5
5
|
import "./index.css";
|
|
6
6
|
const Screenshots_ScreenshotsSizeColor = /*#__PURE__*/ memo(function({ size, color, onSizeChange, onColorChange }) {
|
|
7
7
|
return /*#__PURE__*/ jsxs("div", {
|
|
@@ -47,8 +47,8 @@ const Screenshots_ScreenshotsTextarea = /*#__PURE__*/ memo(function({ x, y, maxW
|
|
|
47
47
|
transform: `translate(${x}px, ${y}px)`
|
|
48
48
|
},
|
|
49
49
|
value: value,
|
|
50
|
-
onChange: (e)=>onChange
|
|
51
|
-
onBlur: (e)=>onBlur
|
|
50
|
+
onChange: (e)=>onChange?.(e.target.value),
|
|
51
|
+
onBlur: (e)=>onBlur?.(e)
|
|
52
52
|
}), getPopoverEl());
|
|
53
53
|
});
|
|
54
54
|
export { Screenshots_ScreenshotsTextarea as default };
|
|
@@ -6,5 +6,5 @@ interface ComposeImageOpts {
|
|
|
6
6
|
history: History;
|
|
7
7
|
bounds: Bounds;
|
|
8
8
|
}
|
|
9
|
-
export default function composeImage({ image, width, height, history, bounds }: ComposeImageOpts): Promise<Blob>;
|
|
9
|
+
export default function composeImage({ image, width, height, history, bounds, }: ComposeImageOpts): Promise<Blob>;
|
|
10
10
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useCanvasPointerDown(onPointerDown: (e: PointerEvent) => unknown): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import useEmitter from "./useEmitter.js";
|
|
3
|
+
function useCanvasPointerDown(onPointerDown) {
|
|
4
|
+
const emitter = useEmitter();
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
emitter.on('pointerdown', onPointerDown);
|
|
7
|
+
return ()=>{
|
|
8
|
+
emitter.off('pointerdown', onPointerDown);
|
|
9
|
+
};
|
|
10
|
+
}, [
|
|
11
|
+
onPointerDown,
|
|
12
|
+
emitter
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
export { useCanvasPointerDown as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useCanvasPointerMove(onPointerMove: (e: PointerEvent) => unknown): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import useEmitter from "./useEmitter.js";
|
|
3
|
+
function useCanvasPointerMove(onPointerMove) {
|
|
4
|
+
const emitter = useEmitter();
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
emitter.on('pointermove', onPointerMove);
|
|
7
|
+
return ()=>{
|
|
8
|
+
emitter.off('pointermove', onPointerMove);
|
|
9
|
+
};
|
|
10
|
+
}, [
|
|
11
|
+
onPointerMove,
|
|
12
|
+
emitter
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
export { useCanvasPointerMove as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useCanvasPointerUp(onPointerUp: (e: PointerEvent) => unknown): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import useEmitter from "./useEmitter.js";
|
|
3
|
+
function useCanvasPointerUp(onPointerUp) {
|
|
4
|
+
const emitter = useEmitter();
|
|
5
|
+
useEffect(()=>{
|
|
6
|
+
emitter.on("pointerup", onPointerUp);
|
|
7
|
+
return ()=>{
|
|
8
|
+
emitter.off("pointerup", onPointerUp);
|
|
9
|
+
};
|
|
10
|
+
}, [
|
|
11
|
+
onPointerUp,
|
|
12
|
+
emitter
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
export { useCanvasPointerUp as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { HistoryItemSource } from '../types';
|
|
2
|
-
export default function useDrawSelect(onDrawSelect: (action: HistoryItemSource<unknown, unknown>, e:
|
|
2
|
+
export default function useDrawSelect(onDrawSelect: (action: HistoryItemSource<unknown, unknown>, e: PointerEvent) => unknown): void;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
|
-
import
|
|
2
|
+
import useEmitter from "./useEmitter.js";
|
|
3
3
|
function useDrawSelect(onDrawSelect) {
|
|
4
|
-
const
|
|
4
|
+
const emitter = useEmitter();
|
|
5
5
|
useEffect(()=>{
|
|
6
|
-
|
|
6
|
+
emitter.on('drawselect', onDrawSelect);
|
|
7
7
|
return ()=>{
|
|
8
|
-
|
|
8
|
+
emitter.off('drawselect', onDrawSelect);
|
|
9
9
|
};
|
|
10
10
|
}, [
|
|
11
11
|
onDrawSelect,
|
|
12
|
-
|
|
12
|
+
emitter
|
|
13
13
|
]);
|
|
14
14
|
}
|
|
15
15
|
export { useDrawSelect as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { EmitterListener } from '../types';
|
|
2
|
+
export interface EmitterDispatcher {
|
|
3
|
+
on: (event: string, listener: EmitterListener) => void;
|
|
4
|
+
off: (event: string, listener: EmitterListener) => void;
|
|
5
|
+
emit: (event: string, ...args: unknown[]) => void;
|
|
6
|
+
reset: () => void;
|
|
7
|
+
}
|
|
8
|
+
export default function useEmitter(): EmitterDispatcher;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import useStore from "./useStore.js";
|
|
3
|
+
function useEmitter() {
|
|
4
|
+
const { emitterRef } = useStore();
|
|
5
|
+
const on = useCallback((event, listener)=>{
|
|
6
|
+
const emitter = emitterRef.current;
|
|
7
|
+
if (Array.isArray(emitter[event])) emitter[event].push(listener);
|
|
8
|
+
else emitter[event] = [
|
|
9
|
+
listener
|
|
10
|
+
];
|
|
11
|
+
}, [
|
|
12
|
+
emitterRef
|
|
13
|
+
]);
|
|
14
|
+
const off = useCallback((event, listener)=>{
|
|
15
|
+
const emitter = emitterRef.current;
|
|
16
|
+
if (Array.isArray(emitter[event])) {
|
|
17
|
+
const index = emitter[event].indexOf(listener);
|
|
18
|
+
if (-1 !== index) emitter[event].splice(index, 1);
|
|
19
|
+
}
|
|
20
|
+
}, [
|
|
21
|
+
emitterRef
|
|
22
|
+
]);
|
|
23
|
+
const emit = useCallback((event, ...args)=>{
|
|
24
|
+
const emitter = emitterRef.current;
|
|
25
|
+
if (Array.isArray(emitter[event])) emitter[event].forEach((listener)=>{
|
|
26
|
+
listener(...args);
|
|
27
|
+
});
|
|
28
|
+
}, [
|
|
29
|
+
emitterRef
|
|
30
|
+
]);
|
|
31
|
+
const reset = useCallback(()=>{
|
|
32
|
+
emitterRef.current = {};
|
|
33
|
+
}, [
|
|
34
|
+
emitterRef
|
|
35
|
+
]);
|
|
36
|
+
return {
|
|
37
|
+
on,
|
|
38
|
+
off,
|
|
39
|
+
emit,
|
|
40
|
+
reset
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export { useEmitter as default };
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
import useBounds from "./useBounds.js";
|
|
3
3
|
import useCursor from "./useCursor.js";
|
|
4
|
-
import
|
|
4
|
+
import useEmitter from "./useEmitter.js";
|
|
5
5
|
import useHistory from "./useHistory.js";
|
|
6
6
|
import useOperation from "./useOperation.js";
|
|
7
7
|
function useReset() {
|
|
8
|
-
const
|
|
8
|
+
const emitter = useEmitter();
|
|
9
9
|
const [, boundsDispatcher] = useBounds();
|
|
10
10
|
const [, cursorDispatcher] = useCursor();
|
|
11
11
|
const [, historyDispatcher] = useHistory();
|
|
12
12
|
const [, operatioDispatcher] = useOperation();
|
|
13
13
|
const reset = useCallback(()=>{
|
|
14
|
-
|
|
14
|
+
emitter.reset();
|
|
15
15
|
historyDispatcher.reset();
|
|
16
16
|
boundsDispatcher.reset();
|
|
17
17
|
cursorDispatcher.reset();
|
|
18
18
|
operatioDispatcher.reset();
|
|
19
19
|
}, [
|
|
20
|
-
|
|
20
|
+
emitter,
|
|
21
21
|
historyDispatcher,
|
|
22
22
|
boundsDispatcher,
|
|
23
23
|
cursorDispatcher,
|
package/lib/Screenshots/index.js
CHANGED
|
@@ -10,9 +10,11 @@ import ScreenshotsOperations from "./ScreenshotsOperations/index.js";
|
|
|
10
10
|
import useGetLoadedImage from "./useGetLoadedImage.js";
|
|
11
11
|
import zh_CN from "./zh_CN.js";
|
|
12
12
|
function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
13
|
+
const propsRef = useRef(props);
|
|
14
|
+
propsRef.current = props;
|
|
13
15
|
const image = useGetLoadedImage(url);
|
|
14
16
|
const canvasContextRef = useRef(null);
|
|
15
|
-
const
|
|
17
|
+
const emitterRef = useRef({});
|
|
16
18
|
const [history, setHistory] = useState({
|
|
17
19
|
index: -1,
|
|
18
20
|
stack: []
|
|
@@ -29,7 +31,7 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
29
31
|
...zh_CN,
|
|
30
32
|
...lang
|
|
31
33
|
},
|
|
32
|
-
|
|
34
|
+
emitterRef,
|
|
33
35
|
canvasContextRef,
|
|
34
36
|
history,
|
|
35
37
|
bounds,
|
|
@@ -37,11 +39,9 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
37
39
|
operation
|
|
38
40
|
};
|
|
39
41
|
const call = useCallback((funcName, ...args)=>{
|
|
40
|
-
const func =
|
|
42
|
+
const func = propsRef.current[funcName];
|
|
41
43
|
if ('function' == typeof func) func(...args);
|
|
42
|
-
}, [
|
|
43
|
-
props
|
|
44
|
-
]);
|
|
44
|
+
}, []);
|
|
45
45
|
const dispatcher = {
|
|
46
46
|
call,
|
|
47
47
|
setHistory,
|
|
@@ -53,8 +53,8 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
53
53
|
'screenshots'
|
|
54
54
|
];
|
|
55
55
|
if (className) classNames.push(className);
|
|
56
|
-
const reset = ()=>{
|
|
57
|
-
|
|
56
|
+
const reset = useCallback(()=>{
|
|
57
|
+
emitterRef.current = {};
|
|
58
58
|
setHistory({
|
|
59
59
|
index: -1,
|
|
60
60
|
stack: []
|
|
@@ -62,7 +62,7 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
62
62
|
setBounds(null);
|
|
63
63
|
setCursor('move');
|
|
64
64
|
setOperation(void 0);
|
|
65
|
-
};
|
|
65
|
+
}, []);
|
|
66
66
|
const onDoubleClick = useCallback(async (e)=>{
|
|
67
67
|
if (0 !== e.button || !image) return;
|
|
68
68
|
if (bounds && canvasContextRef.current) composeImage({
|
|
@@ -99,7 +99,8 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
99
99
|
bounds,
|
|
100
100
|
width,
|
|
101
101
|
height,
|
|
102
|
-
call
|
|
102
|
+
call,
|
|
103
|
+
reset
|
|
103
104
|
]);
|
|
104
105
|
const onContextMenu = useCallback((e)=>{
|
|
105
106
|
if (2 !== e.button) return;
|
|
@@ -107,7 +108,8 @@ function Screenshots({ url, width, height, lang, className, ...props }) {
|
|
|
107
108
|
call('onCancel');
|
|
108
109
|
reset();
|
|
109
110
|
}, [
|
|
110
|
-
call
|
|
111
|
+
call,
|
|
112
|
+
reset
|
|
111
113
|
]);
|
|
112
114
|
useLayoutEffect(()=>{
|
|
113
115
|
reset();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ArrowData, ArrowEditData } from '.';
|
|
2
1
|
import type { HistoryItemSource } from '../../types';
|
|
2
|
+
import type { ArrowData, ArrowEditData } from '.';
|
|
3
3
|
export declare function getEditedArrowData(action: HistoryItemSource<ArrowData, ArrowEditData>): {
|
|
4
4
|
x1: number;
|
|
5
5
|
x2: number;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
4
|
+
import useCanvasPointerDown from "../../hooks/useCanvasPointerDown.js";
|
|
5
|
+
import useCanvasPointerMove from "../../hooks/useCanvasPointerMove.js";
|
|
6
|
+
import useCanvasPointerUp from "../../hooks/useCanvasPointerUp.js";
|
|
7
|
+
import useCursor from "../../hooks/useCursor.js";
|
|
8
|
+
import useDrawSelect from "../../hooks/useDrawSelect.js";
|
|
9
|
+
import useHistory from "../../hooks/useHistory.js";
|
|
10
|
+
import useLang from "../../hooks/useLang.js";
|
|
11
|
+
import useOperation from "../../hooks/useOperation.js";
|
|
3
12
|
import ScreenshotsButton from "../../ScreenshotsButton/index.js";
|
|
4
13
|
import ScreenshotsSizeColor from "../../ScreenshotsSizeColor/index.js";
|
|
5
|
-
import useCanvasMousedown from "../../hooks/useCanvasMousedown.js";
|
|
6
|
-
import useCanvasMousemove from "../../hooks/useCanvasMousemove.js";
|
|
7
|
-
import useCanvasMouseup from "../../hooks/useCanvasMouseup.js";
|
|
8
14
|
import { HistoryItemType } from "../../types.js";
|
|
9
|
-
import useCursor from "../../hooks/useCursor.js";
|
|
10
|
-
import useOperation from "../../hooks/useOperation.js";
|
|
11
|
-
import useHistory from "../../hooks/useHistory.js";
|
|
12
|
-
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
13
15
|
import { isHit, isHitCircle } from "../utils.js";
|
|
14
|
-
import useDrawSelect from "../../hooks/useDrawSelect.js";
|
|
15
16
|
import draw, { getEditedArrowData } from "./draw.js";
|
|
16
|
-
import useLang from "../../hooks/useLang.js";
|
|
17
17
|
var Arrow_ArrowEditType = /*#__PURE__*/ function(ArrowEditType) {
|
|
18
18
|
ArrowEditType[ArrowEditType["Move"] = 0] = "Move";
|
|
19
19
|
ArrowEditType[ArrowEditType["MoveStart"] = 1] = "MoveStart";
|
|
@@ -78,7 +78,7 @@ function Arrow() {
|
|
|
78
78
|
selectArrow,
|
|
79
79
|
historyDispatcher
|
|
80
80
|
]);
|
|
81
|
-
const
|
|
81
|
+
const onPointerDown = useCallback((e)=>{
|
|
82
82
|
if (!checked || arrowRef.current || !canvasContextRef.current) return;
|
|
83
83
|
const { left, top } = canvasContextRef.current.canvas.getBoundingClientRect();
|
|
84
84
|
arrowRef.current = {
|
|
@@ -102,7 +102,7 @@ function Arrow() {
|
|
|
102
102
|
size,
|
|
103
103
|
canvasContextRef
|
|
104
104
|
]);
|
|
105
|
-
const
|
|
105
|
+
const onPointerMove = useCallback((e)=>{
|
|
106
106
|
if (!checked || !canvasContextRef.current) return;
|
|
107
107
|
if (arrowEditRef.current) {
|
|
108
108
|
arrowEditRef.current.data.x2 = e.clientX;
|
|
@@ -124,7 +124,7 @@ function Arrow() {
|
|
|
124
124
|
canvasContextRef,
|
|
125
125
|
historyDispatcher
|
|
126
126
|
]);
|
|
127
|
-
const
|
|
127
|
+
const onPointerUp = useCallback(()=>{
|
|
128
128
|
if (!checked) return;
|
|
129
129
|
if (arrowRef.current) historyDispatcher.clearSelect();
|
|
130
130
|
arrowRef.current = null;
|
|
@@ -134,9 +134,9 @@ function Arrow() {
|
|
|
134
134
|
historyDispatcher
|
|
135
135
|
]);
|
|
136
136
|
useDrawSelect(onDrawSelect);
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
useCanvasPointerDown(onPointerDown);
|
|
138
|
+
useCanvasPointerMove(onPointerMove);
|
|
139
|
+
useCanvasPointerUp(onPointerUp);
|
|
140
140
|
return /*#__PURE__*/ jsx(ScreenshotsButton, {
|
|
141
141
|
title: lang.operation_arrow_title,
|
|
142
142
|
icon: "icon-arrow",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { BrushData, BrushEditData } from '.';
|
|
2
1
|
import type { HistoryItemSource } from '../../types';
|
|
2
|
+
import type { BrushData, BrushEditData } from '.';
|
|
3
3
|
export default function draw(ctx: CanvasRenderingContext2D, action: HistoryItemSource<BrushData, BrushEditData>): void;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useRef, useState } from "react";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import ScreenshotsSizeColor from "../../ScreenshotsSizeColor/index.js";
|
|
3
|
+
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
4
|
+
import useCanvasPointerDown from "../../hooks/useCanvasPointerDown.js";
|
|
5
|
+
import useCanvasPointerMove from "../../hooks/useCanvasPointerMove.js";
|
|
6
|
+
import useCanvasPointerUp from "../../hooks/useCanvasPointerUp.js";
|
|
8
7
|
import useCursor from "../../hooks/useCursor.js";
|
|
9
|
-
import
|
|
8
|
+
import useDrawSelect from "../../hooks/useDrawSelect.js";
|
|
10
9
|
import useHistory from "../../hooks/useHistory.js";
|
|
11
|
-
import
|
|
10
|
+
import useLang from "../../hooks/useLang.js";
|
|
11
|
+
import useOperation from "../../hooks/useOperation.js";
|
|
12
|
+
import ScreenshotsButton from "../../ScreenshotsButton/index.js";
|
|
13
|
+
import ScreenshotsSizeColor from "../../ScreenshotsSizeColor/index.js";
|
|
12
14
|
import { HistoryItemType } from "../../types.js";
|
|
13
|
-
import useDrawSelect from "../../hooks/useDrawSelect.js";
|
|
14
15
|
import { isHit } from "../utils.js";
|
|
15
16
|
import draw from "./draw.js";
|
|
16
|
-
import useLang from "../../hooks/useLang.js";
|
|
17
17
|
function Brush() {
|
|
18
18
|
const lang = useLang();
|
|
19
19
|
const [, cursorDispatcher] = useCursor();
|
|
@@ -59,7 +59,7 @@ function Brush() {
|
|
|
59
59
|
selectBrush,
|
|
60
60
|
historyDispatcher
|
|
61
61
|
]);
|
|
62
|
-
const
|
|
62
|
+
const onPointerDown = useCallback((e)=>{
|
|
63
63
|
if (!checked || brushRef.current || !canvasContextRef.current) return;
|
|
64
64
|
const { left, top } = canvasContextRef.current.canvas.getBoundingClientRect();
|
|
65
65
|
brushRef.current = {
|
|
@@ -85,7 +85,7 @@ function Brush() {
|
|
|
85
85
|
size,
|
|
86
86
|
color
|
|
87
87
|
]);
|
|
88
|
-
const
|
|
88
|
+
const onPointerMove = useCallback((e)=>{
|
|
89
89
|
if (!checked || !canvasContextRef.current) return;
|
|
90
90
|
if (brushEditRef.current) {
|
|
91
91
|
brushEditRef.current.data.x2 = e.clientX;
|
|
@@ -109,7 +109,7 @@ function Brush() {
|
|
|
109
109
|
canvasContextRef,
|
|
110
110
|
historyDispatcher
|
|
111
111
|
]);
|
|
112
|
-
const
|
|
112
|
+
const onPointerUp = useCallback(()=>{
|
|
113
113
|
if (!checked) return;
|
|
114
114
|
if (brushRef.current) historyDispatcher.clearSelect();
|
|
115
115
|
brushRef.current = null;
|
|
@@ -119,9 +119,9 @@ function Brush() {
|
|
|
119
119
|
historyDispatcher
|
|
120
120
|
]);
|
|
121
121
|
useDrawSelect(onDrawSelect);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
useCanvasPointerDown(onPointerDown);
|
|
123
|
+
useCanvasPointerMove(onPointerMove);
|
|
124
|
+
useCanvasPointerUp(onPointerUp);
|
|
125
125
|
return /*#__PURE__*/ jsx(ScreenshotsButton, {
|
|
126
126
|
title: lang.operation_brush_title,
|
|
127
127
|
icon: "icon-brush",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EllipseData, EllipseEditData } from '.';
|
|
2
1
|
import type { HistoryItemSource } from '../../types';
|
|
2
|
+
import type { EllipseData, EllipseEditData } from '.';
|
|
3
3
|
export declare function getEditedEllipseData(action: HistoryItemSource<EllipseData, EllipseEditData>): {
|
|
4
4
|
x1: number;
|
|
5
5
|
x2: number;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useRef, useState } from "react";
|
|
3
3
|
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
4
|
+
import useCanvasPointerDown from "../../hooks/useCanvasPointerDown.js";
|
|
5
|
+
import useCanvasPointerMove from "../../hooks/useCanvasPointerMove.js";
|
|
6
|
+
import useCanvasPointerUp from "../../hooks/useCanvasPointerUp.js";
|
|
7
7
|
import useCursor from "../../hooks/useCursor.js";
|
|
8
8
|
import useDrawSelect from "../../hooks/useDrawSelect.js";
|
|
9
9
|
import useHistory from "../../hooks/useHistory.js";
|
|
@@ -108,7 +108,7 @@ function Ellipse() {
|
|
|
108
108
|
selectEllipse,
|
|
109
109
|
historyDispatcher
|
|
110
110
|
]);
|
|
111
|
-
const
|
|
111
|
+
const onPointerDown = useCallback((e)=>{
|
|
112
112
|
if (!checked || !canvasContextRef.current || ellipseRef.current) return;
|
|
113
113
|
const { left, top } = canvasContextRef.current.canvas.getBoundingClientRect();
|
|
114
114
|
const x = e.clientX - left;
|
|
@@ -134,7 +134,7 @@ function Ellipse() {
|
|
|
134
134
|
color,
|
|
135
135
|
canvasContextRef
|
|
136
136
|
]);
|
|
137
|
-
const
|
|
137
|
+
const onPointerMove = useCallback((e)=>{
|
|
138
138
|
if (!checked || !canvasContextRef.current) return;
|
|
139
139
|
if (ellipseEditRef.current) {
|
|
140
140
|
ellipseEditRef.current.data.x2 = e.clientX;
|
|
@@ -156,7 +156,7 @@ function Ellipse() {
|
|
|
156
156
|
history,
|
|
157
157
|
historyDispatcher
|
|
158
158
|
]);
|
|
159
|
-
const
|
|
159
|
+
const onPointerUp = useCallback(()=>{
|
|
160
160
|
if (!checked) return;
|
|
161
161
|
if (ellipseRef.current) historyDispatcher.clearSelect();
|
|
162
162
|
ellipseRef.current = null;
|
|
@@ -166,9 +166,9 @@ function Ellipse() {
|
|
|
166
166
|
historyDispatcher
|
|
167
167
|
]);
|
|
168
168
|
useDrawSelect(onDrawSelect);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
useCanvasPointerDown(onPointerDown);
|
|
170
|
+
useCanvasPointerMove(onPointerMove);
|
|
171
|
+
useCanvasPointerUp(onPointerUp);
|
|
172
172
|
return /*#__PURE__*/ jsx(ScreenshotsButton, {
|
|
173
173
|
title: lang.operation_ellipse_title,
|
|
174
174
|
icon: "icon-ellipse",
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
import ScreenshotsButton from "../../ScreenshotsButton/index.js";
|
|
4
|
-
import ScreenshotsSize from "../../ScreenshotsSize/index.js";
|
|
5
|
-
import useCanvasMousedown from "../../hooks/useCanvasMousedown.js";
|
|
6
|
-
import useCanvasMousemove from "../../hooks/useCanvasMousemove.js";
|
|
7
|
-
import useCanvasMouseup from "../../hooks/useCanvasMouseup.js";
|
|
8
|
-
import { HistoryItemType } from "../../types.js";
|
|
9
|
-
import useOperation from "../../hooks/useOperation.js";
|
|
10
|
-
import useCursor from "../../hooks/useCursor.js";
|
|
11
|
-
import useStore from "../../hooks/useStore.js";
|
|
12
3
|
import useBounds from "../../hooks/useBounds.js";
|
|
13
|
-
import useHistory from "../../hooks/useHistory.js";
|
|
14
4
|
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
5
|
+
import useCanvasPointerDown from "../../hooks/useCanvasPointerDown.js";
|
|
6
|
+
import useCanvasPointerMove from "../../hooks/useCanvasPointerMove.js";
|
|
7
|
+
import useCanvasPointerUp from "../../hooks/useCanvasPointerUp.js";
|
|
8
|
+
import useCursor from "../../hooks/useCursor.js";
|
|
9
|
+
import useHistory from "../../hooks/useHistory.js";
|
|
15
10
|
import useLang from "../../hooks/useLang.js";
|
|
11
|
+
import useOperation from "../../hooks/useOperation.js";
|
|
12
|
+
import useStore from "../../hooks/useStore.js";
|
|
13
|
+
import ScreenshotsButton from "../../ScreenshotsButton/index.js";
|
|
14
|
+
import ScreenshotsSize from "../../ScreenshotsSize/index.js";
|
|
15
|
+
import { HistoryItemType } from "../../types.js";
|
|
16
16
|
function getColor(x, y, imageData) {
|
|
17
17
|
if (!imageData) return [
|
|
18
18
|
0,
|
|
@@ -63,7 +63,7 @@ function Mosaic() {
|
|
|
63
63
|
selectMosaic,
|
|
64
64
|
historyDispatcher
|
|
65
65
|
]);
|
|
66
|
-
const
|
|
66
|
+
const onPointerDown = useCallback((e)=>{
|
|
67
67
|
if (!checked || mosaicRef.current || !imageDataRef.current || !canvasContextRef.current) return;
|
|
68
68
|
const rect = canvasContextRef.current.canvas.getBoundingClientRect();
|
|
69
69
|
const x = e.clientX - rect.x;
|
|
@@ -90,7 +90,7 @@ function Mosaic() {
|
|
|
90
90
|
size,
|
|
91
91
|
canvasContextRef
|
|
92
92
|
]);
|
|
93
|
-
const
|
|
93
|
+
const onPointerMove = useCallback((e)=>{
|
|
94
94
|
if (!checked || !mosaicRef.current || !canvasContextRef.current || !imageDataRef.current) return;
|
|
95
95
|
const rect = canvasContextRef.current.canvas.getBoundingClientRect();
|
|
96
96
|
const x = e.clientX - rect.x;
|
|
@@ -133,15 +133,15 @@ function Mosaic() {
|
|
|
133
133
|
history,
|
|
134
134
|
historyDispatcher
|
|
135
135
|
]);
|
|
136
|
-
const
|
|
136
|
+
const onPointerUp = useCallback(()=>{
|
|
137
137
|
if (!checked) return;
|
|
138
138
|
mosaicRef.current = null;
|
|
139
139
|
}, [
|
|
140
140
|
checked
|
|
141
141
|
]);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
useCanvasPointerDown(onPointerDown);
|
|
143
|
+
useCanvasPointerMove(onPointerMove);
|
|
144
|
+
useCanvasPointerUp(onPointerUp);
|
|
145
145
|
useEffect(()=>{
|
|
146
146
|
if (!bounds || !image || !checked) return;
|
|
147
147
|
const $canvas = document.createElement('canvas');
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback } from "react";
|
|
3
|
-
import
|
|
3
|
+
import composeImage from "../../composeImage.js";
|
|
4
4
|
import useCall from "../../hooks/useCall.js";
|
|
5
5
|
import useCanvasContextRef from "../../hooks/useCanvasContextRef.js";
|
|
6
6
|
import useHistory from "../../hooks/useHistory.js";
|
|
7
7
|
import useReset from "../../hooks/useReset.js";
|
|
8
|
+
import useStore from "../../hooks/useStore.js";
|
|
8
9
|
import ScreenshotsButton from "../../ScreenshotsButton/index.js";
|
|
9
|
-
import composeImage from "../../composeImage.js";
|
|
10
10
|
function Ok() {
|
|
11
11
|
const { image, width, height, history, bounds, lang } = useStore();
|
|
12
12
|
const canvasContextRef = useCanvasContextRef();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RectangleData, RectangleEditData } from '.';
|
|
2
1
|
import type { HistoryItemSource } from '../../types';
|
|
2
|
+
import type { RectangleData, RectangleEditData } from '.';
|
|
3
3
|
export declare function getEditedRectangleData(action: HistoryItemSource<RectangleData, RectangleEditData>): {
|
|
4
4
|
x1: number;
|
|
5
5
|
x2: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RectangleEditType } from "./index.js";
|
|
2
1
|
import { drawDragCircle } from "../utils.js";
|
|
2
|
+
import { RectangleEditType } from "./index.js";
|
|
3
3
|
function getEditedRectangleData(action) {
|
|
4
4
|
let { x1, y1, x2, y2 } = action.data;
|
|
5
5
|
action.editHistory.forEach(({ data })=>{
|