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.
@@ -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, minimapFilter, ...otherProps }: Canvas2DProps): React.JSX.Element;
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 J, Fragment as K, jsx as B } from "react/jsx-runtime";
2
- import { useState as O, useCallback as j, useEffect as p } from "react";
3
- import Q from "./events/elementClick.js";
4
- import S from "./events/elementRightClick.js";
5
- import U from "./events/mouseMove.js";
6
- import V from "./events/mouseWheel.js";
7
- import $ from "./functions/calcRatioForMinimap.js";
8
- import z from "./functions/sortElements.js";
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 re({
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: X = !1,
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
- minimapFilter: Y = (t) => !0,
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] = O({
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
- }), _ = j((e) => {
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
- }, []), y = j((e) => {
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) => U(e, l[f.id], a, t, c, N, T, X, D, A));
81
- const G = (e) => {
82
- E && E(e.nativeEvent), d !== v && V(e, t, c, 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(Q(e, l[f.id], a, t))), p(() => {
86
+ return x && (M = (e) => x(S(e, l[f.id], a, t))), p(() => {
86
87
  function e(n) {
87
- n.preventDefault(), u && u(S(n, l[f.id], a, t));
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 = z(l[f.id]);
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(Y), I = $(w, o, r, m, i, a);
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 / I,
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__ */ J(K, { children: [
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: G,
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: y,
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
- re as default
158
+ fe as default
158
159
  };
@@ -29,7 +29,7 @@ function I(o, c, a, s, m, d) {
29
29
  });
30
30
  break;
31
31
  case "Polygon":
32
- p(e, n, l, a, s, r) && i.push({
32
+ p(e, a, s, r) && i.push({
33
33
  id: e.id,
34
34
  element: e,
35
35
  originalEvent: o,
@@ -1,2 +1,2 @@
1
1
  import { default as Polygon } from '../shapes/Polygon';
2
- export default function inPoly(element: Polygon, _x: number, y: number, mouseX: number, mouseY: number, localTileSize: number): boolean;
2
+ export default function inPoly(element: Polygon, mouseX: number, mouseY: number, localTileSize: number): boolean;
@@ -1,19 +1,20 @@
1
- function y(t, h, p, u, c, o) {
2
- const x = t.points.length - 1;
3
- let r = !1;
4
- for (let s = 0; s < t.points.length; s++) {
5
- const i = t.points[s].x * o, n = t.points[s].y * o;
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
- const g = t.points[x].x * o, f = t.points[x].y * o;
9
- if (n > p != f > p) {
10
- const j = (u - i) * (f - n) - (g - i) * (c - n);
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 != f < n && (r = !r);
14
+ j < 0 != c < r && (f = !f);
14
15
  }
15
16
  }
16
- return r;
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
- minimapFilter?: (e: CanvasObject) => boolean;
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.0.0",
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.37.0",
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.7.1",
27
+ "@types/node": "^24.9.2",
28
28
  "@types/react": "^19.2.2",
29
- "@types/react-dom": "^19.2.1",
30
- "@vitejs/plugin-react": "^5.0.4",
31
- "@vitest/coverage-v8": "^3.2.4",
32
- "eslint": "^9.37.0",
33
- "eslint-plugin-react-hooks": "^7.0.0",
34
- "eslint-plugin-react-refresh": "^0.4.23",
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.4.0",
37
- "jsdom": "^27.0.0",
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.0",
42
- "vite": "^7.1.9",
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": "^3.2.4"
46
- },
47
- "dependencies": {
48
- "canvas2d-wrapper": "^1.14.1"
45
+ "vitest": "^4.0.6"
49
46
  }
50
47
  }