react-screenshots 0.5.21 → 0.6.0
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/README.md +145 -145
- package/dist/electron.html +1 -0
- package/dist/index.html +1 -0
- package/dist/static/css/electron.7eee95c8.css +1 -0
- package/dist/static/css/index.7eee95c8.css +1 -0
- package/dist/static/image/image.1ca17a04.jpg +0 -0
- package/dist/static/js/589.5602a0fa.js +12 -0
- package/dist/static/js/electron.1c6ab61b.js +1 -0
- package/dist/static/js/index.fbe72af7.js +1 -0
- package/dist/static/js/lib-react.6d1aa3cf.js +2 -0
- package/dist/static/js/lib-react.6d1aa3cf.js.LICENSE.txt +39 -0
- package/lib/{types → Screenshots}/ScreenshotsBackground/getBoundsByPoints.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsBackground/getBoundsByPoints.js +21 -0
- package/lib/Screenshots/ScreenshotsBackground/index.d.ts +3 -0
- package/lib/Screenshots/ScreenshotsBackground/index.js +100 -0
- package/lib/{types → Screenshots}/ScreenshotsButton/index.d.ts +2 -2
- package/lib/Screenshots/ScreenshotsButton/index.js +31 -0
- package/lib/{types → Screenshots}/ScreenshotsCanvas/getBoundsByPoints.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsCanvas/getBoundsByPoints.js +33 -0
- package/lib/{types → Screenshots}/ScreenshotsCanvas/getPoints.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsCanvas/getPoints.js +57 -0
- package/lib/{types → Screenshots}/ScreenshotsCanvas/index.d.ts +1 -2
- package/lib/Screenshots/ScreenshotsCanvas/index.js +199 -0
- package/lib/{types → Screenshots}/ScreenshotsCanvas/isPointInDraw.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsCanvas/isPointInDraw.js +24 -0
- package/lib/{types → Screenshots}/ScreenshotsColor/index.d.ts +1 -2
- package/lib/Screenshots/ScreenshotsColor/index.js +30 -0
- package/lib/{types → Screenshots}/ScreenshotsContext.d.ts +4 -3
- package/lib/Screenshots/ScreenshotsContext.js +32 -0
- package/lib/{types → Screenshots}/ScreenshotsMagnifier/index.d.ts +1 -2
- package/lib/Screenshots/ScreenshotsMagnifier/index.js +99 -0
- package/lib/{types → Screenshots}/ScreenshotsOperations/index.d.ts +1 -1
- package/lib/Screenshots/ScreenshotsOperations/index.js +64 -0
- package/lib/{types → Screenshots}/ScreenshotsOption/index.d.ts +3 -3
- package/lib/Screenshots/ScreenshotsOption/index.js +94 -0
- package/lib/{types → Screenshots}/ScreenshotsSize/index.d.ts +1 -2
- package/lib/Screenshots/ScreenshotsSize/index.js +31 -0
- package/lib/{types → Screenshots}/ScreenshotsSizeColor/index.d.ts +2 -3
- package/lib/Screenshots/ScreenshotsSizeColor/index.js +21 -0
- package/lib/Screenshots/ScreenshotsTextarea/calculateNodeSize.js +69 -0
- package/lib/{types → Screenshots}/ScreenshotsTextarea/index.d.ts +2 -2
- package/lib/Screenshots/ScreenshotsTextarea/index.js +54 -0
- package/lib/{types → Screenshots}/composeImage.d.ts +1 -1
- package/lib/Screenshots/composeImage.js +27 -0
- package/lib/Screenshots/exports.d.ts +4 -0
- package/lib/Screenshots/exports.js +2 -0
- package/lib/{types → Screenshots}/hooks/useBounds.d.ts +1 -1
- package/lib/Screenshots/hooks/useBounds.js +25 -0
- package/lib/Screenshots/hooks/useCall.js +12 -0
- package/lib/{types → Screenshots}/hooks/useCanvasContextRef.d.ts +1 -1
- package/lib/Screenshots/hooks/useCanvasContextRef.js +6 -0
- package/lib/Screenshots/hooks/useCanvasMousedown.js +15 -0
- package/lib/Screenshots/hooks/useCanvasMousemove.js +15 -0
- package/lib/Screenshots/hooks/useCanvasMouseup.js +15 -0
- package/lib/Screenshots/hooks/useCursor.js +25 -0
- package/lib/Screenshots/hooks/useDispatcher.d.ts +2 -0
- package/lib/Screenshots/hooks/useDispatcher.js +7 -0
- package/lib/{types → Screenshots}/hooks/useDrawSelect.d.ts +1 -1
- package/lib/Screenshots/hooks/useDrawSelect.js +15 -0
- package/lib/{types → Screenshots}/hooks/useEmiter.d.ts +1 -1
- package/lib/Screenshots/hooks/useEmiter.js +41 -0
- package/lib/{types → Screenshots}/hooks/useHistory.d.ts +1 -1
- package/lib/Screenshots/hooks/useHistory.js +122 -0
- package/lib/{types → Screenshots}/hooks/useLang.d.ts +1 -1
- package/lib/Screenshots/hooks/useLang.js +6 -0
- package/lib/Screenshots/hooks/useOperation.js +25 -0
- package/lib/Screenshots/hooks/useReset.js +28 -0
- package/lib/Screenshots/hooks/useStore.d.ts +2 -0
- package/lib/Screenshots/hooks/useStore.js +7 -0
- package/lib/{types → Screenshots}/index.d.ts +2 -2
- package/lib/Screenshots/index.js +140 -0
- package/lib/{types → Screenshots}/operations/Arrow/draw.d.ts +2 -2
- package/lib/Screenshots/operations/Arrow/draw.js +51 -0
- package/lib/{types → Screenshots}/operations/Arrow/index.d.ts +1 -1
- package/lib/Screenshots/operations/Arrow/index.js +153 -0
- package/lib/{types → Screenshots}/operations/Brush/draw.d.ts +2 -2
- package/lib/Screenshots/operations/Brush/draw.js +31 -0
- package/lib/{types → Screenshots}/operations/Brush/index.d.ts +2 -2
- package/lib/Screenshots/operations/Brush/index.js +138 -0
- package/lib/{types → Screenshots}/operations/Cancel/index.d.ts +1 -1
- package/lib/Screenshots/operations/Cancel/index.js +24 -0
- package/lib/{types → Screenshots}/operations/Ellipse/draw.d.ts +2 -2
- package/lib/Screenshots/operations/Ellipse/draw.js +81 -0
- package/lib/{types → Screenshots}/operations/Ellipse/index.d.ts +1 -1
- package/lib/Screenshots/operations/Ellipse/index.js +185 -0
- package/lib/{types → Screenshots}/operations/Mosaic/index.d.ts +1 -1
- package/lib/Screenshots/operations/Mosaic/index.js +174 -0
- package/lib/{types → Screenshots}/operations/Ok/index.d.ts +1 -1
- package/lib/Screenshots/operations/Ok/index.js +48 -0
- package/lib/{types → Screenshots}/operations/Rectangle/draw.d.ts +2 -2
- package/lib/Screenshots/operations/Rectangle/draw.js +66 -0
- package/lib/{types → Screenshots}/operations/Rectangle/index.d.ts +1 -1
- package/lib/Screenshots/operations/Rectangle/index.js +186 -0
- package/lib/{types → Screenshots}/operations/Redo/index.d.ts +1 -1
- package/lib/Screenshots/operations/Redo/index.js +21 -0
- package/lib/{types → Screenshots}/operations/Save/index.d.ts +1 -1
- package/lib/Screenshots/operations/Save/index.js +48 -0
- package/lib/{types → Screenshots}/operations/Text/index.d.ts +1 -1
- package/lib/Screenshots/operations/Text/index.js +220 -0
- package/lib/{types → Screenshots}/operations/Undo/index.d.ts +1 -1
- package/lib/Screenshots/operations/Undo/index.js +21 -0
- package/lib/Screenshots/operations/index.js +27 -0
- package/lib/{types → Screenshots}/operations/utils.d.ts +1 -1
- package/lib/Screenshots/operations/utils.js +23 -0
- package/lib/{types → Screenshots}/types.d.ts +1 -1
- package/lib/Screenshots/types.js +6 -0
- package/lib/Screenshots/useGetLoadedImage.js +22 -0
- package/lib/Screenshots/zh_CN.js +16 -0
- package/lib/electron/app.d.ts +10 -0
- package/lib/electron/app.js +80 -0
- package/lib/electron/index.d.ts +1 -0
- package/lib/electron/index.js +7 -0
- package/lib/web/app.d.ts +3 -0
- package/lib/web/app.js +41 -0
- package/lib/web/index.d.ts +1 -0
- package/lib/web/index.js +7 -0
- package/package.json +35 -41
- package/LICENSE +0 -21
- package/electron/assets/electron-ed141e06.css +0 -1
- package/electron/assets/index-73f470f6.js +0 -53
- package/electron/electron.html +0 -14
- package/lib/react-screenshots.cjs.js +0 -14
- package/lib/react-screenshots.es.js +0 -1716
- package/lib/style.css +0 -1
- package/lib/types/ScreenshotsBackground/index.d.ts +0 -4
- package/lib/types/exports.d.ts +0 -3
- package/lib/types/hooks/useDispatcher.d.ts +0 -2
- package/lib/types/hooks/useStore.d.ts +0 -2
- /package/lib/{types → Screenshots}/ScreenshotsTextarea/calculateNodeSize.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useCall.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useCanvasMousedown.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useCanvasMousemove.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useCanvasMouseup.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useCursor.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useOperation.d.ts +0 -0
- /package/lib/{types → Screenshots}/hooks/useReset.d.ts +0 -0
- /package/lib/{types → Screenshots}/operations/index.d.ts +0 -0
- /package/lib/{types → Screenshots}/useGetLoadedImage.d.ts +0 -0
- /package/lib/{types → Screenshots}/zh_CN.d.ts +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Point, Bounds } from '../types';
|
|
1
|
+
import type { Point, Bounds } from '../types';
|
|
2
2
|
export default function getBoundsByPoints(e: MouseEvent, resizeOrMove: string, point: Point, bounds: Bounds): Point[];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
function getBoundsByPoints(e, resizeOrMove, point, bounds) {
|
|
2
|
+
const x = e.clientX - point.x;
|
|
3
|
+
const y = e.clientY - point.y;
|
|
4
|
+
let x1 = bounds.x;
|
|
5
|
+
let y1 = bounds.y;
|
|
6
|
+
let x2 = bounds.x + bounds.width;
|
|
7
|
+
let y2 = bounds.y + bounds.height;
|
|
8
|
+
switch(resizeOrMove){
|
|
9
|
+
case 'top':
|
|
10
|
+
y1 += y;
|
|
11
|
+
break;
|
|
12
|
+
case 'top-right':
|
|
13
|
+
x2 += x;
|
|
14
|
+
y1 += y;
|
|
15
|
+
break;
|
|
16
|
+
case 'right':
|
|
17
|
+
x2 += x;
|
|
18
|
+
break;
|
|
19
|
+
case 'right-bottom':
|
|
20
|
+
x2 += x;
|
|
21
|
+
y2 += y;
|
|
22
|
+
break;
|
|
23
|
+
case 'bottom':
|
|
24
|
+
y2 += y;
|
|
25
|
+
break;
|
|
26
|
+
case 'bottom-left':
|
|
27
|
+
x1 += x;
|
|
28
|
+
y2 += y;
|
|
29
|
+
break;
|
|
30
|
+
case 'left':
|
|
31
|
+
x1 += x;
|
|
32
|
+
break;
|
|
33
|
+
case 'left-top':
|
|
34
|
+
x1 += x;
|
|
35
|
+
y1 += y;
|
|
36
|
+
break;
|
|
37
|
+
case 'move':
|
|
38
|
+
x1 += x;
|
|
39
|
+
y1 += y;
|
|
40
|
+
x2 += x;
|
|
41
|
+
y2 += y;
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
x: x1,
|
|
49
|
+
y: y1
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
x: x2,
|
|
53
|
+
y: y2
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
export { getBoundsByPoints as default };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import './index.less';
|
|
3
2
|
export declare enum ResizePoints {
|
|
4
3
|
ResizeTop = "top",
|
|
@@ -11,5 +10,5 @@ export declare enum ResizePoints {
|
|
|
11
10
|
ResizeLeftTop = "left-top",
|
|
12
11
|
Move = "move"
|
|
13
12
|
}
|
|
14
|
-
declare const _default:
|
|
13
|
+
declare const _default: import("react").NamedExoticComponent<import("react").RefAttributes<CanvasRenderingContext2D>>;
|
|
15
14
|
export default _default;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useRef } from "react";
|
|
3
|
+
import useBounds from "../hooks/useBounds.js";
|
|
4
|
+
import { HistoryItemType } from "../types.js";
|
|
5
|
+
import useCursor from "../hooks/useCursor.js";
|
|
6
|
+
import useEmiter from "../hooks/useEmiter.js";
|
|
7
|
+
import useHistory from "../hooks/useHistory.js";
|
|
8
|
+
import useOperation from "../hooks/useOperation.js";
|
|
9
|
+
import useStore from "../hooks/useStore.js";
|
|
10
|
+
import getBoundsByPoints from "./getBoundsByPoints.js";
|
|
11
|
+
import getPoints from "./getPoints.js";
|
|
12
|
+
import "./index.css";
|
|
13
|
+
import isPointInDraw from "./isPointInDraw.js";
|
|
14
|
+
const borders = [
|
|
15
|
+
'top',
|
|
16
|
+
'right',
|
|
17
|
+
'bottom',
|
|
18
|
+
'left'
|
|
19
|
+
];
|
|
20
|
+
var ScreenshotsCanvas_ResizePoints = /*#__PURE__*/ function(ResizePoints) {
|
|
21
|
+
ResizePoints["ResizeTop"] = "top";
|
|
22
|
+
ResizePoints["ResizetopRight"] = "top-right";
|
|
23
|
+
ResizePoints["ResizeRight"] = "right";
|
|
24
|
+
ResizePoints["ResizeRightBottom"] = "right-bottom";
|
|
25
|
+
ResizePoints["ResizeBottom"] = "bottom";
|
|
26
|
+
ResizePoints["ResizeBottomLeft"] = "bottom-left";
|
|
27
|
+
ResizePoints["ResizeLeft"] = "left";
|
|
28
|
+
ResizePoints["ResizeLeftTop"] = "left-top";
|
|
29
|
+
ResizePoints["Move"] = "move";
|
|
30
|
+
return ResizePoints;
|
|
31
|
+
}({});
|
|
32
|
+
const resizePoints = [
|
|
33
|
+
"top",
|
|
34
|
+
"top-right",
|
|
35
|
+
"right",
|
|
36
|
+
"right-bottom",
|
|
37
|
+
"bottom",
|
|
38
|
+
"bottom-left",
|
|
39
|
+
"left",
|
|
40
|
+
"left-top"
|
|
41
|
+
];
|
|
42
|
+
const Screenshots_ScreenshotsCanvas = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function(_props, ref) {
|
|
43
|
+
const { url, image, width, height } = useStore();
|
|
44
|
+
const emiter = useEmiter();
|
|
45
|
+
const [history] = useHistory();
|
|
46
|
+
const [cursor] = useCursor();
|
|
47
|
+
const [bounds, boundsDispatcher] = useBounds();
|
|
48
|
+
const [operation] = useOperation();
|
|
49
|
+
const resizeOrMoveRef = useRef(void 0);
|
|
50
|
+
const pointRef = useRef(null);
|
|
51
|
+
const boundsRef = useRef(null);
|
|
52
|
+
const canvasRef = useRef(null);
|
|
53
|
+
const ctxRef = useRef(null);
|
|
54
|
+
const isCanResize = bounds && !history.stack.length && !operation;
|
|
55
|
+
const draw = useCallback(()=>{
|
|
56
|
+
if (!bounds || !ctxRef.current) return;
|
|
57
|
+
const ctx = ctxRef.current;
|
|
58
|
+
ctx.imageSmoothingEnabled = true;
|
|
59
|
+
ctx.imageSmoothingQuality = 'low';
|
|
60
|
+
ctx.clearRect(0, 0, bounds.width, bounds.height);
|
|
61
|
+
history.stack.slice(0, history.index + 1).forEach((item)=>{
|
|
62
|
+
if (item.type === HistoryItemType.Source) item.draw(ctx, item);
|
|
63
|
+
});
|
|
64
|
+
}, [
|
|
65
|
+
bounds,
|
|
66
|
+
ctxRef,
|
|
67
|
+
history
|
|
68
|
+
]);
|
|
69
|
+
const onMouseDown = useCallback((e, resizeOrMove)=>{
|
|
70
|
+
if (0 !== e.button || !bounds) return;
|
|
71
|
+
if (operation) {
|
|
72
|
+
const draw = isPointInDraw(bounds, canvasRef.current, history, e.nativeEvent);
|
|
73
|
+
if (draw) emiter.emit('drawselect', draw, e.nativeEvent);
|
|
74
|
+
else emiter.emit('mousedown', e.nativeEvent);
|
|
75
|
+
} else {
|
|
76
|
+
resizeOrMoveRef.current = resizeOrMove;
|
|
77
|
+
pointRef.current = {
|
|
78
|
+
x: e.clientX,
|
|
79
|
+
y: e.clientY
|
|
80
|
+
};
|
|
81
|
+
boundsRef.current = {
|
|
82
|
+
x: bounds.x,
|
|
83
|
+
y: bounds.y,
|
|
84
|
+
width: bounds.width,
|
|
85
|
+
height: bounds.height
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}, [
|
|
89
|
+
bounds,
|
|
90
|
+
operation,
|
|
91
|
+
emiter,
|
|
92
|
+
history
|
|
93
|
+
]);
|
|
94
|
+
const updateBounds = useCallback((e)=>{
|
|
95
|
+
if (!resizeOrMoveRef.current || !pointRef.current || !boundsRef.current || !bounds) return;
|
|
96
|
+
const points = getPoints(e, resizeOrMoveRef.current, pointRef.current, boundsRef.current);
|
|
97
|
+
boundsDispatcher.set(getBoundsByPoints(points[0], points[1], bounds, width, height, resizeOrMoveRef.current));
|
|
98
|
+
}, [
|
|
99
|
+
width,
|
|
100
|
+
height,
|
|
101
|
+
bounds,
|
|
102
|
+
boundsDispatcher
|
|
103
|
+
]);
|
|
104
|
+
useLayoutEffect(()=>{
|
|
105
|
+
if (!image || !bounds || !canvasRef.current) {
|
|
106
|
+
ctxRef.current = null;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!ctxRef.current) ctxRef.current = canvasRef.current.getContext('2d');
|
|
110
|
+
draw();
|
|
111
|
+
}, [
|
|
112
|
+
image,
|
|
113
|
+
bounds,
|
|
114
|
+
draw
|
|
115
|
+
]);
|
|
116
|
+
useEffect(()=>{
|
|
117
|
+
const onMouseMove = (e)=>{
|
|
118
|
+
if (operation) emiter.emit('mousemove', e);
|
|
119
|
+
else {
|
|
120
|
+
if (!resizeOrMoveRef.current || !pointRef.current || !boundsRef.current) return;
|
|
121
|
+
updateBounds(e);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const onMouseUp = (e)=>{
|
|
125
|
+
if (operation) emiter.emit('mouseup', e);
|
|
126
|
+
else {
|
|
127
|
+
if (!resizeOrMoveRef.current || !pointRef.current || !boundsRef.current) return;
|
|
128
|
+
updateBounds(e);
|
|
129
|
+
resizeOrMoveRef.current = void 0;
|
|
130
|
+
pointRef.current = null;
|
|
131
|
+
boundsRef.current = null;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
window.addEventListener('mousemove', onMouseMove);
|
|
135
|
+
window.addEventListener('mouseup', onMouseUp);
|
|
136
|
+
return ()=>{
|
|
137
|
+
window.removeEventListener('mousemove', onMouseMove);
|
|
138
|
+
window.removeEventListener('mouseup', onMouseUp);
|
|
139
|
+
};
|
|
140
|
+
}, [
|
|
141
|
+
updateBounds,
|
|
142
|
+
operation,
|
|
143
|
+
emiter
|
|
144
|
+
]);
|
|
145
|
+
useImperativeHandle(ref, ()=>ctxRef.current);
|
|
146
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
147
|
+
className: "screenshots-canvas",
|
|
148
|
+
style: {
|
|
149
|
+
width: bounds?.width || 0,
|
|
150
|
+
height: bounds?.height || 0,
|
|
151
|
+
transform: bounds ? `translate(${bounds.x}px, ${bounds.y}px)` : 'none'
|
|
152
|
+
},
|
|
153
|
+
children: [
|
|
154
|
+
/*#__PURE__*/ jsxs("div", {
|
|
155
|
+
className: "screenshots-canvas-body",
|
|
156
|
+
children: [
|
|
157
|
+
/*#__PURE__*/ jsx("img", {
|
|
158
|
+
className: "screenshots-canvas-image",
|
|
159
|
+
src: url,
|
|
160
|
+
style: {
|
|
161
|
+
width,
|
|
162
|
+
height,
|
|
163
|
+
transform: bounds ? `translate(${-bounds.x}px, ${-bounds.y}px)` : 'none'
|
|
164
|
+
}
|
|
165
|
+
}),
|
|
166
|
+
/*#__PURE__*/ jsx("canvas", {
|
|
167
|
+
ref: canvasRef,
|
|
168
|
+
className: "screenshots-canvas-panel",
|
|
169
|
+
width: bounds?.width || 0,
|
|
170
|
+
height: bounds?.height || 0
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
}),
|
|
174
|
+
/*#__PURE__*/ jsx("div", {
|
|
175
|
+
className: "screenshots-canvas-mask",
|
|
176
|
+
style: {
|
|
177
|
+
cursor
|
|
178
|
+
},
|
|
179
|
+
onMouseDown: (e)=>onMouseDown(e, 'move'),
|
|
180
|
+
children: isCanResize && /*#__PURE__*/ jsxs("div", {
|
|
181
|
+
className: "screenshots-canvas-size",
|
|
182
|
+
children: [
|
|
183
|
+
bounds.width,
|
|
184
|
+
" \xd7 ",
|
|
185
|
+
bounds.height
|
|
186
|
+
]
|
|
187
|
+
})
|
|
188
|
+
}),
|
|
189
|
+
borders.map((border)=>/*#__PURE__*/ jsx("div", {
|
|
190
|
+
className: `screenshots-canvas-border-${border}`
|
|
191
|
+
}, border)),
|
|
192
|
+
isCanResize && resizePoints.map((resizePoint)=>/*#__PURE__*/ jsx("div", {
|
|
193
|
+
className: `screenshots-canvas-point-${resizePoint}`,
|
|
194
|
+
onMouseDown: (e)=>onMouseDown(e, resizePoint)
|
|
195
|
+
}, resizePoint))
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
}));
|
|
199
|
+
export { ScreenshotsCanvas_ResizePoints as ResizePoints, Screenshots_ScreenshotsCanvas as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Bounds, History } from '../types';
|
|
1
|
+
import type { Bounds, History } from '../types';
|
|
2
2
|
export default function isPointInDraw(bounds: Bounds, canvas: HTMLCanvasElement | null, history: History, e: MouseEvent): false | import("../types").HistoryItem<any, any> | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { HistoryItemType } from "../types.js";
|
|
2
|
+
function isPointInDraw(bounds, canvas, history, e) {
|
|
3
|
+
if (!canvas) return false;
|
|
4
|
+
const $canvas = document.createElement('canvas');
|
|
5
|
+
$canvas.width = bounds.width;
|
|
6
|
+
$canvas.height = bounds.height;
|
|
7
|
+
const ctx = $canvas.getContext('2d');
|
|
8
|
+
if (!ctx) return false;
|
|
9
|
+
const { left, top } = canvas.getBoundingClientRect();
|
|
10
|
+
const x = e.clientX - left;
|
|
11
|
+
const y = e.clientY - top;
|
|
12
|
+
const stack = [
|
|
13
|
+
...history.stack.slice(0, history.index + 1)
|
|
14
|
+
];
|
|
15
|
+
return stack.reverse().find((item)=>{
|
|
16
|
+
if (item.type !== HistoryItemType.Source) return false;
|
|
17
|
+
ctx.clearRect(0, 0, bounds.width, bounds.height);
|
|
18
|
+
return item.isHit?.(ctx, item, {
|
|
19
|
+
x,
|
|
20
|
+
y
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export { isPointInDraw as default };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import './index.less';
|
|
3
2
|
export interface ColorProps {
|
|
4
3
|
value: string;
|
|
5
4
|
onChange: (value: string) => void;
|
|
6
5
|
}
|
|
7
|
-
declare const _default:
|
|
6
|
+
declare const _default: import("react").NamedExoticComponent<ColorProps>;
|
|
8
7
|
export default _default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import "./index.css";
|
|
4
|
+
const Screenshots_ScreenshotsColor = /*#__PURE__*/ memo(function({ value, onChange }) {
|
|
5
|
+
const colors = [
|
|
6
|
+
'#ee5126',
|
|
7
|
+
'#fceb4d',
|
|
8
|
+
'#90e746',
|
|
9
|
+
'#51c0fa',
|
|
10
|
+
'#7a7a7a',
|
|
11
|
+
'#ffffff'
|
|
12
|
+
];
|
|
13
|
+
return /*#__PURE__*/ jsx("div", {
|
|
14
|
+
className: "screenshots-color",
|
|
15
|
+
children: colors.map((color)=>{
|
|
16
|
+
const classNames = [
|
|
17
|
+
'screenshots-color-item'
|
|
18
|
+
];
|
|
19
|
+
if (color === value) classNames.push('screenshots-color-active');
|
|
20
|
+
return /*#__PURE__*/ jsx("div", {
|
|
21
|
+
className: classNames.join(' '),
|
|
22
|
+
style: {
|
|
23
|
+
backgroundColor: color
|
|
24
|
+
},
|
|
25
|
+
onClick: ()=>onChange && onChange(color)
|
|
26
|
+
}, color);
|
|
27
|
+
})
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
export { Screenshots_ScreenshotsColor as default };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
import type { EmiterRef, History, Bounds, CanvasContextRef } from './types';
|
|
4
|
+
import type { Lang } from './zh_CN';
|
|
4
5
|
export interface ScreenshotsContextStore {
|
|
5
6
|
url?: string;
|
|
6
7
|
image: HTMLImageElement | null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import react from "react";
|
|
2
|
+
import zh_CN from "./zh_CN.js";
|
|
3
|
+
const ScreenshotsContext = react.createContext({
|
|
4
|
+
store: {
|
|
5
|
+
url: void 0,
|
|
6
|
+
image: null,
|
|
7
|
+
width: 0,
|
|
8
|
+
height: 0,
|
|
9
|
+
lang: zh_CN,
|
|
10
|
+
emiterRef: {
|
|
11
|
+
current: {}
|
|
12
|
+
},
|
|
13
|
+
canvasContextRef: {
|
|
14
|
+
current: null
|
|
15
|
+
},
|
|
16
|
+
history: {
|
|
17
|
+
index: -1,
|
|
18
|
+
stack: []
|
|
19
|
+
},
|
|
20
|
+
bounds: null,
|
|
21
|
+
cursor: 'move',
|
|
22
|
+
operation: void 0
|
|
23
|
+
},
|
|
24
|
+
dispatcher: {
|
|
25
|
+
call: void 0,
|
|
26
|
+
setHistory: void 0,
|
|
27
|
+
setBounds: void 0,
|
|
28
|
+
setCursor: void 0,
|
|
29
|
+
setOperation: void 0
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
export { ScreenshotsContext as default };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import './index.less';
|
|
3
2
|
export interface ScreenshotsMagnifierProps {
|
|
4
3
|
x: number;
|
|
5
4
|
y: number;
|
|
6
5
|
}
|
|
7
|
-
declare const _default:
|
|
6
|
+
declare const _default: import("react").NamedExoticComponent<ScreenshotsMagnifierProps>;
|
|
8
7
|
export default _default;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
3
|
+
import useLang from "../hooks/useLang.js";
|
|
4
|
+
import useStore from "../hooks/useStore.js";
|
|
5
|
+
import "./index.css";
|
|
6
|
+
const magnifierWidth = 100;
|
|
7
|
+
const magnifierHeight = 80;
|
|
8
|
+
const Screenshots_ScreenshotsMagnifier = /*#__PURE__*/ memo(function({ x, y }) {
|
|
9
|
+
const { width, height, image } = useStore();
|
|
10
|
+
const lang = useLang();
|
|
11
|
+
const [position, setPosition] = useState(null);
|
|
12
|
+
const elRef = useRef(null);
|
|
13
|
+
const canvasRef = useRef(null);
|
|
14
|
+
const ctxRef = useRef(null);
|
|
15
|
+
const [rgb, setRgb] = useState('000000');
|
|
16
|
+
useLayoutEffect(()=>{
|
|
17
|
+
if (!elRef.current) return;
|
|
18
|
+
const elRect = elRef.current.getBoundingClientRect();
|
|
19
|
+
let tx = x + 20;
|
|
20
|
+
let ty = y + 20;
|
|
21
|
+
if (tx + elRect.width > width) tx = x - elRect.width - 20;
|
|
22
|
+
if (ty + elRect.height > height) ty = y - elRect.height - 20;
|
|
23
|
+
if (tx < 0) tx = 0;
|
|
24
|
+
if (ty < 0) ty = 0;
|
|
25
|
+
setPosition({
|
|
26
|
+
x: tx,
|
|
27
|
+
y: ty
|
|
28
|
+
});
|
|
29
|
+
}, [
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
x,
|
|
33
|
+
y
|
|
34
|
+
]);
|
|
35
|
+
useEffect(()=>{
|
|
36
|
+
if (!image || !canvasRef.current) {
|
|
37
|
+
ctxRef.current = null;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!ctxRef.current) ctxRef.current = canvasRef.current.getContext('2d');
|
|
41
|
+
if (!ctxRef.current) return;
|
|
42
|
+
const ctx = ctxRef.current;
|
|
43
|
+
ctx.clearRect(0, 0, magnifierWidth, magnifierHeight);
|
|
44
|
+
const rx = image.naturalWidth / width;
|
|
45
|
+
const ry = image.naturalHeight / height;
|
|
46
|
+
ctx.drawImage(image, x * rx - magnifierWidth / 2, y * ry - magnifierHeight / 2, magnifierWidth, magnifierHeight, 0, 0, magnifierWidth, magnifierHeight);
|
|
47
|
+
const { data } = ctx.getImageData(Math.floor(magnifierWidth / 2), Math.floor(magnifierHeight / 2), 1, 1);
|
|
48
|
+
const hex = Array.from(data.slice(0, 3)).map((val)=>val >= 16 ? val.toString(16) : `0${val.toString(16)}`).join('').toUpperCase();
|
|
49
|
+
setRgb(hex);
|
|
50
|
+
}, [
|
|
51
|
+
width,
|
|
52
|
+
height,
|
|
53
|
+
image,
|
|
54
|
+
x,
|
|
55
|
+
y
|
|
56
|
+
]);
|
|
57
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
58
|
+
ref: elRef,
|
|
59
|
+
className: "screenshots-magnifier",
|
|
60
|
+
style: {
|
|
61
|
+
transform: `translate(${position?.x}px, ${position?.y}px)`
|
|
62
|
+
},
|
|
63
|
+
children: [
|
|
64
|
+
/*#__PURE__*/ jsx("div", {
|
|
65
|
+
className: "screenshots-magnifier-body",
|
|
66
|
+
children: /*#__PURE__*/ jsx("canvas", {
|
|
67
|
+
ref: canvasRef,
|
|
68
|
+
className: "screenshots-magnifier-body-canvas",
|
|
69
|
+
width: magnifierWidth,
|
|
70
|
+
height: magnifierHeight
|
|
71
|
+
})
|
|
72
|
+
}),
|
|
73
|
+
/*#__PURE__*/ jsxs("div", {
|
|
74
|
+
className: "screenshots-magnifier-footer",
|
|
75
|
+
children: [
|
|
76
|
+
/*#__PURE__*/ jsxs("div", {
|
|
77
|
+
className: "screenshots-magnifier-footer-item",
|
|
78
|
+
children: [
|
|
79
|
+
lang.magnifier_position_label,
|
|
80
|
+
": (",
|
|
81
|
+
x,
|
|
82
|
+
",",
|
|
83
|
+
y,
|
|
84
|
+
")"
|
|
85
|
+
]
|
|
86
|
+
}),
|
|
87
|
+
/*#__PURE__*/ jsxs("div", {
|
|
88
|
+
className: "screenshots-magnifier-footer-item",
|
|
89
|
+
children: [
|
|
90
|
+
"RGB: #",
|
|
91
|
+
rgb
|
|
92
|
+
]
|
|
93
|
+
})
|
|
94
|
+
]
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
export { Screenshots_ScreenshotsMagnifier as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Bounds } from '../types';
|
|
2
|
+
import type { Bounds } from '../types';
|
|
3
3
|
import './index.less';
|
|
4
4
|
export declare const ScreenshotsOperationsCtx: React.Context<Bounds | null>;
|
|
5
5
|
declare const _default: React.NamedExoticComponent<object>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import react, { memo, useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import useBounds from "../hooks/useBounds.js";
|
|
4
|
+
import useStore from "../hooks/useStore.js";
|
|
5
|
+
import operations from "../operations/index.js";
|
|
6
|
+
import "./index.css";
|
|
7
|
+
const ScreenshotsOperationsCtx = /*#__PURE__*/ react.createContext(null);
|
|
8
|
+
const Screenshots_ScreenshotsOperations = /*#__PURE__*/ memo(function() {
|
|
9
|
+
const { width, height } = useStore();
|
|
10
|
+
const [bounds] = useBounds();
|
|
11
|
+
const [operationsRect, setOperationsRect] = useState(null);
|
|
12
|
+
const [position, setPosition] = useState(null);
|
|
13
|
+
const elRef = useRef(null);
|
|
14
|
+
const onDoubleClick = useCallback((e)=>{
|
|
15
|
+
e.stopPropagation();
|
|
16
|
+
}, []);
|
|
17
|
+
const onContextMenu = useCallback((e)=>{
|
|
18
|
+
e.preventDefault();
|
|
19
|
+
e.stopPropagation();
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(()=>{
|
|
22
|
+
if (!bounds || !elRef.current) return;
|
|
23
|
+
const elRect = elRef.current.getBoundingClientRect();
|
|
24
|
+
let x = bounds.x + bounds.width - elRect.width;
|
|
25
|
+
let y = bounds.y + bounds.height + 10;
|
|
26
|
+
if (x < 0) x = 0;
|
|
27
|
+
if (x > width - elRect.width) x = width - elRect.width;
|
|
28
|
+
if (y > height - elRect.height) y = height - elRect.height - 10;
|
|
29
|
+
if (!position || Math.abs(position.x - x) > 1 || Math.abs(position.y - y) > 1) setPosition({
|
|
30
|
+
x,
|
|
31
|
+
y
|
|
32
|
+
});
|
|
33
|
+
if (!operationsRect || Math.abs(operationsRect.x - elRect.x) > 1 || Math.abs(operationsRect.y - elRect.y) > 1 || Math.abs(operationsRect.width - elRect.width) > 1 || Math.abs(operationsRect.height - elRect.height) > 1) setOperationsRect({
|
|
34
|
+
x: elRect.x,
|
|
35
|
+
y: elRect.y,
|
|
36
|
+
width: elRect.width,
|
|
37
|
+
height: elRect.height
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
if (!bounds) return null;
|
|
41
|
+
return /*#__PURE__*/ jsx(ScreenshotsOperationsCtx.Provider, {
|
|
42
|
+
value: operationsRect,
|
|
43
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
44
|
+
ref: elRef,
|
|
45
|
+
className: "screenshots-operations",
|
|
46
|
+
style: {
|
|
47
|
+
visibility: position ? 'visible' : 'hidden',
|
|
48
|
+
transform: `translate(${position?.x ?? 0}px, ${position?.y ?? 0}px)`
|
|
49
|
+
},
|
|
50
|
+
onDoubleClick: onDoubleClick,
|
|
51
|
+
onContextMenu: onContextMenu,
|
|
52
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
53
|
+
className: "screenshots-operations-buttons",
|
|
54
|
+
children: operations.map((OperationButton, index)=>{
|
|
55
|
+
if ('|' === OperationButton) return /*#__PURE__*/ jsx("div", {
|
|
56
|
+
className: "screenshots-operations-divider"
|
|
57
|
+
}, index);
|
|
58
|
+
return /*#__PURE__*/ jsx(OperationButton, {}, index);
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
export { ScreenshotsOperationsCtx, Screenshots_ScreenshotsOperations as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Point } from '../types';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { Point } from '../types';
|
|
3
3
|
import './index.less';
|
|
4
4
|
export interface ScreenshotsOptionProps {
|
|
5
5
|
open?: boolean;
|
|
@@ -11,5 +11,5 @@ export declare enum Placement {
|
|
|
11
11
|
Bottom = "bottom",
|
|
12
12
|
Top = "top"
|
|
13
13
|
}
|
|
14
|
-
declare const _default:
|
|
14
|
+
declare const _default: import("react").NamedExoticComponent<ScreenshotsOptionProps>;
|
|
15
15
|
export default _default;
|