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.
@@ -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 = ({ userName = "Гость" }) => {
5
- return (_jsxs("div", { style: { position: "relative" }, children: [_jsx(Tools, { userName: userName }), _jsx(Canvas, { userName: userName })] }));
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, jsxs as _jsxs } from "react/jsx-runtime";
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
- import TextHoverTool from "../tools/TextHoverTool";
7
- const Canvas = ({ userName = "Гость" }) => {
8
- const mainRef = useRef(null);
9
- const overlayRef = useRef(null);
6
+ const Canvas = () => {
7
+ const canvasRef = useRef(null);
10
8
  useEffect(() => {
11
- const mainCanvas = mainRef.current;
12
- const overlayCanvas = overlayRef.current;
13
- if (!mainCanvas || !overlayCanvas)
14
- return;
15
- CanvasState.setCanvas(mainCanvas);
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;
@@ -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 = ({ userName = "Гость" }) => {
9
+ const Tools = () => {
10
10
  const selectTool = (ToolClass) => {
11
11
  var _a, _b;
12
12
  if (!CanvasState.canvas)
@@ -1,4 +1,3 @@
1
- // CanvasState.ts
2
1
  import { makeAutoObservable } from "mobx";
3
2
  class CanvasState {
4
3
  constructor() {
@@ -1,4 +1,3 @@
1
- // ToolState.ts
2
1
  import { makeAutoObservable } from "mobx";
3
2
  class ToolState {
4
3
  constructor() {
@@ -1,6 +1,3 @@
1
1
  import React from "react";
2
- interface BorderProps {
3
- userName?: string;
4
- }
5
- declare const Border: React.FC<BorderProps>;
2
+ declare const Border: React.FC;
6
3
  export default Border;
@@ -1,6 +1,3 @@
1
1
  import React from "react";
2
- interface CanvasProps {
3
- userName?: string;
4
- }
5
- declare const Canvas: React.FC<CanvasProps>;
2
+ declare const Canvas: React.FC;
6
3
  export default Canvas;
@@ -1,6 +1,3 @@
1
1
  import React from "react";
2
- interface ToolsProps {
3
- userName?: string;
4
- }
5
- declare const Tools: React.FC<ToolsProps>;
2
+ declare const Tools: React.FC;
6
3
  export default Tools;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-react-easy",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/types/index.d.ts",
6
6
  "license": "MIT",
@@ -2,15 +2,11 @@ import React from "react";
2
2
  import Tools from "./Tools";
3
3
  import Canvas from "./Canvas";
4
4
 
5
- interface BorderProps {
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 userName={userName} />
13
- <Canvas userName={userName} />
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
- interface CanvasProps {
12
- userName?: string;
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
- const mainCanvas = mainRef.current;
21
- const overlayCanvas = overlayRef.current;
22
- if (!mainCanvas || !overlayCanvas) return;
23
-
24
- CanvasState.setCanvas(mainCanvas);
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
- <div style={{ position: "relative" }}>
46
- <canvas
47
- ref={mainRef}
48
- width={1600}
49
- height={900}
50
- style={{ border: "1px solid black", display: "block" }}
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
 
@@ -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
- interface ToolsProps {
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
 
@@ -1,4 +1,3 @@
1
- // CanvasState.ts
2
1
  import { makeAutoObservable } from "mobx";
3
2
 
4
3
  class CanvasState {
@@ -1,6 +1,5 @@
1
- // ToolState.ts
2
1
  import { makeAutoObservable } from "mobx";
3
- import Tool from "../tools/Tool"; // путь к Tool.ts
2
+ import Tool from "../tools/Tool";
4
3
 
5
4
  class ToolState {
6
5
  tool: Tool | null = null;