canvas-react-easy 1.1.3 → 1.1.4
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/Border.js +2 -2
- package/dist/components/Canvas.js +9 -30
- package/dist/components/Tools.js +1 -1
- package/dist/store/CanvasState.js +0 -1
- package/dist/store/ToolState.js +0 -1
- package/dist/types/components/Border.d.ts +1 -4
- package/dist/types/components/Canvas.d.ts +1 -4
- package/dist/types/components/Tools.d.ts +1 -4
- package/package.json +1 -1
- package/src/components/Border.tsx +3 -7
- package/src/components/Canvas.tsx +13 -54
- package/src/components/Tools.tsx +1 -5
- package/src/store/CanvasState.ts +0 -1
- package/src/store/ToolState.ts +1 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Tools from "./Tools";
|
|
3
3
|
import Canvas from "./Canvas";
|
|
4
|
-
const Border = (
|
|
5
|
-
return (_jsxs("div", { style: { position: "relative" }, children: [_jsx(Tools, {
|
|
4
|
+
const Border = () => {
|
|
5
|
+
return (_jsxs("div", { style: { position: "relative" }, children: [_jsx(Tools, {}), _jsx(Canvas, {})] }));
|
|
6
6
|
};
|
|
7
7
|
export default Border;
|
|
@@ -1,37 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
3
|
import CanvasState from "../store/CanvasState";
|
|
4
4
|
import toolState from "../store/ToolState";
|
|
5
5
|
import { Brush } from "../tools/Brush";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const mainRef = useRef(null);
|
|
9
|
-
const overlayRef = useRef(null);
|
|
6
|
+
const Canvas = () => {
|
|
7
|
+
const canvasRef = useRef(null);
|
|
10
8
|
useEffect(() => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const brush = new Brush(mainCanvas);
|
|
18
|
-
toolState.setTool(brush);
|
|
19
|
-
// Подключаем TextHoverTool для отображения имени пользователя
|
|
20
|
-
const hover = new TextHoverTool(mainCanvas, overlayCanvas, userName);
|
|
21
|
-
hover.listen();
|
|
22
|
-
// Ставим hover tool как текущий инструмент (можно потом переключать через кнопки)
|
|
23
|
-
toolState.setTool(hover);
|
|
24
|
-
// Очистка при размонтировании
|
|
25
|
-
return () => {
|
|
26
|
-
brush.clearEvents();
|
|
27
|
-
hover.clearEvents();
|
|
28
|
-
};
|
|
29
|
-
}, [userName]);
|
|
30
|
-
return (_jsxs("div", { style: { position: "relative" }, children: [_jsx("canvas", { ref: mainRef, width: 1600, height: 900, style: { border: "1px solid black", display: "block" } }), _jsx("canvas", { ref: overlayRef, width: 1600, height: 900, style: {
|
|
31
|
-
position: "absolute",
|
|
32
|
-
top: 0,
|
|
33
|
-
left: 0,
|
|
34
|
-
pointerEvents: "none",
|
|
35
|
-
} })] }));
|
|
9
|
+
if (canvasRef.current) {
|
|
10
|
+
CanvasState.setCanvas(canvasRef.current);
|
|
11
|
+
toolState.setTool(new Brush(canvasRef.current));
|
|
12
|
+
}
|
|
13
|
+
}, []);
|
|
14
|
+
return (_jsx("canvas", { ref: canvasRef, width: 1600, height: 900, style: { border: "1px solid black", display: "block" } }));
|
|
36
15
|
};
|
|
37
16
|
export default Canvas;
|
package/dist/components/Tools.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Rectangle } from "../tools/Rectangle";
|
|
|
6
6
|
import { Circle } from "../tools/Circle";
|
|
7
7
|
import { TextTool } from "../tools/Text";
|
|
8
8
|
import { ImageTool } from "../tools/ImageTool";
|
|
9
|
-
const Tools = (
|
|
9
|
+
const Tools = () => {
|
|
10
10
|
const selectTool = (ToolClass) => {
|
|
11
11
|
var _a, _b;
|
|
12
12
|
if (!CanvasState.canvas)
|
package/dist/store/ToolState.js
CHANGED
package/package.json
CHANGED
|
@@ -2,15 +2,11 @@ import React from "react";
|
|
|
2
2
|
import Tools from "./Tools";
|
|
3
3
|
import Canvas from "./Canvas";
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
userName?: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const Border: React.FC<BorderProps> = ({ userName = "Гость" }) => {
|
|
5
|
+
const Border: React.FC = () => {
|
|
10
6
|
return (
|
|
11
7
|
<div style={{ position: "relative" }}>
|
|
12
|
-
<Tools
|
|
13
|
-
<Canvas
|
|
8
|
+
<Tools />
|
|
9
|
+
<Canvas />
|
|
14
10
|
</div>
|
|
15
11
|
);
|
|
16
12
|
};
|
|
@@ -2,65 +2,24 @@ import React, { useEffect, useRef } from "react";
|
|
|
2
2
|
import CanvasState from "../store/CanvasState";
|
|
3
3
|
import toolState from "../store/ToolState";
|
|
4
4
|
import { Brush } from "../tools/Brush";
|
|
5
|
-
import { Rectangle } from "../tools/Rectangle";
|
|
6
|
-
import { Circle } from "../tools/Circle";
|
|
7
|
-
import { TextTool } from "../tools/Text";
|
|
8
|
-
import { ImageTool } from "../tools/ImageTool";
|
|
9
|
-
import TextHoverTool from "../tools/TextHoverTool";
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const Canvas: React.FC<CanvasProps> = ({ userName = "Гость" }) => {
|
|
16
|
-
const mainRef = useRef<HTMLCanvasElement>(null);
|
|
17
|
-
const overlayRef = useRef<HTMLCanvasElement>(null);
|
|
6
|
+
const Canvas: React.FC = () => {
|
|
7
|
+
const canvasRef = useRef<HTMLCanvasElement>(null);
|
|
18
8
|
|
|
19
9
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// По умолчанию включаем кисть
|
|
27
|
-
const brush = new Brush(mainCanvas);
|
|
28
|
-
toolState.setTool(brush);
|
|
29
|
-
|
|
30
|
-
// Подключаем TextHoverTool для отображения имени пользователя
|
|
31
|
-
const hover = new TextHoverTool(mainCanvas, overlayCanvas, userName);
|
|
32
|
-
hover.listen();
|
|
33
|
-
|
|
34
|
-
// Ставим hover tool как текущий инструмент (можно потом переключать через кнопки)
|
|
35
|
-
toolState.setTool(hover);
|
|
36
|
-
|
|
37
|
-
// Очистка при размонтировании
|
|
38
|
-
return () => {
|
|
39
|
-
brush.clearEvents();
|
|
40
|
-
hover.clearEvents();
|
|
41
|
-
};
|
|
42
|
-
}, [userName]);
|
|
10
|
+
if (canvasRef.current) {
|
|
11
|
+
CanvasState.setCanvas(canvasRef.current);
|
|
12
|
+
toolState.setTool(new Brush(canvasRef.current));
|
|
13
|
+
}
|
|
14
|
+
}, []);
|
|
43
15
|
|
|
44
16
|
return (
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
/>
|
|
52
|
-
<canvas
|
|
53
|
-
ref={overlayRef}
|
|
54
|
-
width={1600}
|
|
55
|
-
height={900}
|
|
56
|
-
style={{
|
|
57
|
-
position: "absolute",
|
|
58
|
-
top: 0,
|
|
59
|
-
left: 0,
|
|
60
|
-
pointerEvents: "none",
|
|
61
|
-
}}
|
|
62
|
-
/>
|
|
63
|
-
</div>
|
|
17
|
+
<canvas
|
|
18
|
+
ref={canvasRef}
|
|
19
|
+
width={1600}
|
|
20
|
+
height={900}
|
|
21
|
+
style={{ border: "1px solid black", display: "block" }}
|
|
22
|
+
/>
|
|
64
23
|
);
|
|
65
24
|
};
|
|
66
25
|
|
package/src/components/Tools.tsx
CHANGED
|
@@ -7,11 +7,7 @@ import { Circle } from "../tools/Circle";
|
|
|
7
7
|
import { TextTool } from "../tools/Text";
|
|
8
8
|
import { ImageTool } from "../tools/ImageTool";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
userName?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const Tools: React.FC<ToolsProps> = ({ userName = "Гость" }) => {
|
|
10
|
+
const Tools: React.FC = () => {
|
|
15
11
|
const selectTool = (ToolClass: any) => {
|
|
16
12
|
if (!CanvasState.canvas) return;
|
|
17
13
|
|
package/src/store/CanvasState.ts
CHANGED