canvas2d-wrapper 2.0.0 → 2.1.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/dist/Canvas2D.d.ts +1 -1
- package/dist/Canvas2D.js +28 -27
- package/dist/collisions/collideElement.js +1 -1
- package/dist/collisions/inPoly.d.ts +1 -1
- package/dist/collisions/inPoly.js +12 -11
- package/dist/types/Canvas2DProps.d.ts +2 -1
- package/package.json +14 -17
package/dist/Canvas2D.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Canvas2DProps } from './types/Canvas2DProps';
|
|
3
|
-
export default function Canvas2D({ width, height, trackMouseMove, minZoom, maxZoom, tileSize, onClick, onRightClick, onHover, onElementMoved, onWheel, onFrame, lockXAxis, lockYAxis, smoothingQuality, dragObjects, deltaLeft, deltaTop, showMinimap, minimapWidth, minimapHeight,
|
|
3
|
+
export default function Canvas2D({ width, height, trackMouseMove, minZoom, maxZoom, tileSize, onClick, onRightClick, onHover, onElementMoved, onWheel, onFrame, lockXAxis, lockYAxis, smoothingQuality, dragObjects, deltaLeft, deltaTop, showMinimap, minimapWidth, minimapHeight, minimapDisplayFilter, minimapAutomaticZoomFilter, ...otherProps }: Canvas2DProps): React.JSX.Element;
|
package/dist/Canvas2D.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import { jsxs as K, Fragment as O, jsx as B } from "react/jsx-runtime";
|
|
2
|
+
import { useState as Q, useCallback as j, useEffect as p } from "react";
|
|
3
|
+
import S from "./events/elementClick.js";
|
|
4
|
+
import U from "./events/elementRightClick.js";
|
|
5
|
+
import V from "./events/mouseMove.js";
|
|
6
|
+
import $ from "./events/mouseWheel.js";
|
|
7
|
+
import z from "./functions/calcRatioForMinimap.js";
|
|
8
|
+
import W from "./functions/sortElements.js";
|
|
9
9
|
import k from "./render/renderCanvas.js";
|
|
10
10
|
import './assets/Canvas2D.css';const l = {};
|
|
11
|
-
function
|
|
11
|
+
function fe({
|
|
12
12
|
width: o,
|
|
13
13
|
height: r,
|
|
14
14
|
trackMouseMove: q = !0,
|
|
@@ -24,17 +24,18 @@ function re({
|
|
|
24
24
|
lockXAxis: N = !1,
|
|
25
25
|
lockYAxis: T = !1,
|
|
26
26
|
smoothingQuality: R = "medium",
|
|
27
|
-
dragObjects:
|
|
27
|
+
dragObjects: _ = !1,
|
|
28
28
|
deltaLeft: b = 0,
|
|
29
29
|
deltaTop: g = 0,
|
|
30
30
|
showMinimap: F = !1,
|
|
31
31
|
minimapWidth: m = 240,
|
|
32
32
|
minimapHeight: i = 120,
|
|
33
|
-
|
|
33
|
+
minimapDisplayFilter: X = (t) => !0,
|
|
34
|
+
minimapAutomaticZoomFilter: Y = (t) => !0,
|
|
34
35
|
...f
|
|
35
36
|
}) {
|
|
36
37
|
l[f.id] || (l[f.id] = []);
|
|
37
|
-
const [t, c] =
|
|
38
|
+
const [t, c] = Q({
|
|
38
39
|
left: 0,
|
|
39
40
|
top: 0,
|
|
40
41
|
width: 0,
|
|
@@ -44,7 +45,7 @@ function re({
|
|
|
44
45
|
deltaLeft: b,
|
|
45
46
|
prevX: null,
|
|
46
47
|
prevY: null
|
|
47
|
-
}),
|
|
48
|
+
}), y = j((e) => {
|
|
48
49
|
if (e !== null) {
|
|
49
50
|
const n = e.getContext("2d");
|
|
50
51
|
if (!n)
|
|
@@ -61,7 +62,7 @@ function re({
|
|
|
61
62
|
zoom: 1
|
|
62
63
|
}));
|
|
63
64
|
}
|
|
64
|
-
}, []),
|
|
65
|
+
}, []), G = j((e) => {
|
|
65
66
|
if (e !== null) {
|
|
66
67
|
const n = e.getContext("2d");
|
|
67
68
|
if (!n)
|
|
@@ -77,14 +78,14 @@ function re({
|
|
|
77
78
|
if (t.deltaTop = g, t.deltaLeft = b, d > v)
|
|
78
79
|
throw new Error("minZoom should be lower than maxZoom.");
|
|
79
80
|
let L;
|
|
80
|
-
q && (L = (e) =>
|
|
81
|
-
const
|
|
82
|
-
E && E(e.nativeEvent), d !== v &&
|
|
81
|
+
q && (L = (e) => V(e, l[f.id], a, t, c, N, T, _, D, A));
|
|
82
|
+
const I = (e) => {
|
|
83
|
+
E && E(e.nativeEvent), d !== v && $(e, t, c, d, v);
|
|
83
84
|
};
|
|
84
85
|
let M;
|
|
85
|
-
return x && (M = (e) => x(
|
|
86
|
+
return x && (M = (e) => x(S(e, l[f.id], a, t))), p(() => {
|
|
86
87
|
function e(n) {
|
|
87
|
-
n.preventDefault(), u && u(
|
|
88
|
+
n.preventDefault(), u && u(U(n, l[f.id], a, t));
|
|
88
89
|
}
|
|
89
90
|
if (u && t.canvas)
|
|
90
91
|
return t.canvas.addEventListener("contextmenu", e), () => {
|
|
@@ -96,7 +97,7 @@ function re({
|
|
|
96
97
|
if (!e)
|
|
97
98
|
return;
|
|
98
99
|
l[f.id] = C();
|
|
99
|
-
const s =
|
|
100
|
+
const s = W(l[f.id]);
|
|
100
101
|
if (t.context && k(
|
|
101
102
|
t.context,
|
|
102
103
|
o,
|
|
@@ -105,13 +106,13 @@ function re({
|
|
|
105
106
|
a,
|
|
106
107
|
t
|
|
107
108
|
), F && t.minimapContext) {
|
|
108
|
-
const w = s.filter(
|
|
109
|
+
const w = s.filter(X), J = z(w.filter(Y), o, r, m, i, a);
|
|
109
110
|
k(
|
|
110
111
|
t.minimapContext,
|
|
111
112
|
m,
|
|
112
113
|
i,
|
|
113
114
|
w,
|
|
114
|
-
a /
|
|
115
|
+
a / J,
|
|
115
116
|
{ left: m / 2, top: i / 2, deltaLeft: 0, deltaTop: 0, zoom: 1 }
|
|
116
117
|
);
|
|
117
118
|
}
|
|
@@ -128,15 +129,15 @@ function re({
|
|
|
128
129
|
width: o,
|
|
129
130
|
height: r
|
|
130
131
|
}));
|
|
131
|
-
}, [o, r]), /* @__PURE__ */
|
|
132
|
+
}, [o, r]), /* @__PURE__ */ K(O, { children: [
|
|
132
133
|
/* @__PURE__ */ B(
|
|
133
134
|
"canvas",
|
|
134
135
|
{
|
|
135
|
-
ref:
|
|
136
|
+
ref: y,
|
|
136
137
|
width: o,
|
|
137
138
|
height: r,
|
|
138
139
|
onPointerMove: L,
|
|
139
|
-
onWheel:
|
|
140
|
+
onWheel: I,
|
|
140
141
|
onClick: M,
|
|
141
142
|
className: "canvas2d-wrapper",
|
|
142
143
|
...f
|
|
@@ -145,7 +146,7 @@ function re({
|
|
|
145
146
|
F && /* @__PURE__ */ B(
|
|
146
147
|
"canvas",
|
|
147
148
|
{
|
|
148
|
-
ref:
|
|
149
|
+
ref: G,
|
|
149
150
|
width: m,
|
|
150
151
|
height: i,
|
|
151
152
|
className: "canvas2d-wrapper-minimap"
|
|
@@ -154,5 +155,5 @@ function re({
|
|
|
154
155
|
] });
|
|
155
156
|
}
|
|
156
157
|
export {
|
|
157
|
-
|
|
158
|
+
fe as default
|
|
158
159
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { default as Polygon } from '../shapes/Polygon';
|
|
2
|
-
export default function inPoly(element: Polygon,
|
|
2
|
+
export default function inPoly(element: Polygon, mouseX: number, mouseY: number, localTileSize: number): boolean;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
function y(t,
|
|
2
|
-
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (u === i && c === n)
|
|
1
|
+
function y(t, u, i, o) {
|
|
2
|
+
let f = !1;
|
|
3
|
+
for (let n = 0; n < t.points.length; n++) {
|
|
4
|
+
const p = t.points[n].x * o, r = t.points[n].y * o;
|
|
5
|
+
if (u === p && i === r)
|
|
7
6
|
return !0;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
let s = n + 1;
|
|
8
|
+
s >= t.points.length && (s = 0);
|
|
9
|
+
const x = t.points[s].x * o, c = t.points[s].y * o;
|
|
10
|
+
if (r > i != c > i) {
|
|
11
|
+
const j = (u - p) * (c - r) - (x - p) * (i - r);
|
|
11
12
|
if (j === 0)
|
|
12
13
|
return !0;
|
|
13
|
-
j < 0 !=
|
|
14
|
+
j < 0 != c < r && (f = !f);
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return f;
|
|
17
18
|
}
|
|
18
19
|
export {
|
|
19
20
|
y as default
|
|
@@ -25,6 +25,7 @@ export type Canvas2DProps = {
|
|
|
25
25
|
showMinimap?: boolean;
|
|
26
26
|
minimapWidth?: number;
|
|
27
27
|
minimapHeight?: number;
|
|
28
|
-
|
|
28
|
+
minimapDisplayFilter?: (e: CanvasObject) => boolean;
|
|
29
|
+
minimapAutomaticZoomFilter?: (e: CanvasObject) => boolean;
|
|
29
30
|
};
|
|
30
31
|
export default Canvas2DProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canvas2d-wrapper",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -20,31 +20,28 @@
|
|
|
20
20
|
"react-dom": "^19.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@eslint/js": "^9.
|
|
23
|
+
"@eslint/js": "^9.39.0",
|
|
24
24
|
"@testing-library/jest-dom": "^6.9.1",
|
|
25
25
|
"@testing-library/react": "^16.3.0",
|
|
26
26
|
"@types/jest": "^30.0.0",
|
|
27
|
-
"@types/node": "^24.
|
|
27
|
+
"@types/node": "^24.9.2",
|
|
28
28
|
"@types/react": "^19.2.2",
|
|
29
|
-
"@types/react-dom": "^19.2.
|
|
30
|
-
"@vitejs/plugin-react": "^5.0
|
|
31
|
-
"@vitest/coverage-v8": "^
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"eslint-plugin-react-hooks": "^7.0.
|
|
34
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
29
|
+
"@types/react-dom": "^19.2.2",
|
|
30
|
+
"@vitejs/plugin-react": "^5.1.0",
|
|
31
|
+
"@vitest/coverage-v8": "^4.0.6",
|
|
32
|
+
"eslint": "^9.39.0",
|
|
33
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
34
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
35
35
|
"glob": "^11.0.3",
|
|
36
|
-
"globals": "^16.
|
|
37
|
-
"jsdom": "^27.
|
|
36
|
+
"globals": "^16.5.0",
|
|
37
|
+
"jsdom": "^27.1.0",
|
|
38
38
|
"react": "^19.2.0",
|
|
39
39
|
"react-dom": "^19.2.0",
|
|
40
40
|
"typescript": "5.9",
|
|
41
|
-
"typescript-eslint": "^8.46.
|
|
42
|
-
"vite": "^7.1.
|
|
41
|
+
"typescript-eslint": "^8.46.2",
|
|
42
|
+
"vite": "^7.1.12",
|
|
43
43
|
"vite-plugin-dts": "^4.5.4",
|
|
44
44
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
45
|
-
"vitest": "^
|
|
46
|
-
},
|
|
47
|
-
"dependencies": {
|
|
48
|
-
"canvas2d-wrapper": "^1.14.1"
|
|
45
|
+
"vitest": "^4.0.6"
|
|
49
46
|
}
|
|
50
47
|
}
|