canvas2d-wrapper 2.1.0 → 2.2.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.spec.js +0 -88
- package/dist/collisions/collideElement.js +43 -34
- package/dist/collisions/lineWithLine.d.ts +2 -0
- package/dist/collisions/lineWithLine.js +7 -0
- package/dist/collisions/pointInCircle.d.ts +1 -0
- package/dist/collisions/pointInCircle.js +6 -0
- package/dist/collisions/pointInPolygon.d.ts +2 -0
- package/dist/collisions/pointInPolygon.js +21 -0
- package/dist/collisions/pointInRectangle.d.ts +1 -0
- package/dist/collisions/pointInRectangle.js +11 -0
- package/dist/collisions/pointOnLinePath.d.ts +2 -0
- package/dist/collisions/pointOnLinePath.js +45 -0
- package/dist/main.d.ts +19 -1
- package/dist/main.js +38 -22
- package/dist/maths/getLineLength.d.ts +2 -0
- package/dist/maths/getLineLength.js +7 -0
- package/dist/maths/normalOnLine.d.ts +2 -0
- package/dist/maths/normalOnLine.js +7 -0
- package/dist/maths/segmentAngle.d.ts +2 -0
- package/dist/maths/segmentAngle.js +7 -0
- package/package.json +13 -13
- package/dist/collisions/inCircle.d.ts +0 -3
- package/dist/collisions/inCircle.js +0 -6
- package/dist/collisions/inPoly.d.ts +0 -2
- package/dist/collisions/inPoly.js +0 -21
- package/dist/collisions/inRect.d.ts +0 -2
- package/dist/collisions/inRect.js +0 -12
- package/dist/collisions/onLinePath.d.ts +0 -2
- package/dist/collisions/onLinePath.js +0 -45
package/dist/Canvas2D.spec.js
CHANGED
|
@@ -570,14 +570,6 @@ var KU = AD((ew, Qm) => {
|
|
|
570
570
|
return Ho.default = H, Ho;
|
|
571
571
|
}
|
|
572
572
|
var jo = {}, cS = { exports: {} }, Lt = {};
|
|
573
|
-
/** @license React v17.0.2
|
|
574
|
-
* react-is.production.min.js
|
|
575
|
-
*
|
|
576
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
577
|
-
*
|
|
578
|
-
* This source code is licensed under the MIT license found in the
|
|
579
|
-
* LICENSE file in the root directory of this source tree.
|
|
580
|
-
*/
|
|
581
573
|
var lA;
|
|
582
574
|
function ND() {
|
|
583
575
|
if (lA) return Lt;
|
|
@@ -648,14 +640,6 @@ var KU = AD((ew, Qm) => {
|
|
|
648
640
|
}, Lt.typeOf = te, Lt;
|
|
649
641
|
}
|
|
650
642
|
var Yt = {};
|
|
651
|
-
/** @license React v17.0.2
|
|
652
|
-
* react-is.development.js
|
|
653
|
-
*
|
|
654
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
655
|
-
*
|
|
656
|
-
* This source code is licensed under the MIT license found in the
|
|
657
|
-
* LICENSE file in the root directory of this source tree.
|
|
658
|
-
*/
|
|
659
643
|
var aA;
|
|
660
644
|
function BD() {
|
|
661
645
|
return aA || (aA = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
@@ -10020,15 +10004,6 @@ Unable to find an ` + (R === !1 ? "accessible " : "") + 'element with the role "
|
|
|
10020
10004
|
throw new TypeError("For queries bound to document.body a global document has to be available... Learn more: https://testing-library.com/s/screen-global-error");
|
|
10021
10005
|
}, s), rO);
|
|
10022
10006
|
var dS = { exports: {} }, uT = {};
|
|
10023
|
-
/**
|
|
10024
|
-
* @license React
|
|
10025
|
-
* react-dom-test-utils.production.js
|
|
10026
|
-
*
|
|
10027
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10028
|
-
*
|
|
10029
|
-
* This source code is licensed under the MIT license found in the
|
|
10030
|
-
* LICENSE file in the root directory of this source tree.
|
|
10031
|
-
*/
|
|
10032
10007
|
var iO;
|
|
10033
10008
|
function MU() {
|
|
10034
10009
|
if (iO) return uT;
|
|
@@ -10041,15 +10016,6 @@ Unable to find an ` + (R === !1 ? "accessible " : "") + 'element with the role "
|
|
|
10041
10016
|
}, uT;
|
|
10042
10017
|
}
|
|
10043
10018
|
var rT = {};
|
|
10044
|
-
/**
|
|
10045
|
-
* @license React
|
|
10046
|
-
* react-dom-test-utils.development.js
|
|
10047
|
-
*
|
|
10048
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10049
|
-
*
|
|
10050
|
-
* This source code is licensed under the MIT license found in the
|
|
10051
|
-
* LICENSE file in the root directory of this source tree.
|
|
10052
|
-
*/
|
|
10053
10019
|
var oO;
|
|
10054
10020
|
function DU() {
|
|
10055
10021
|
return oO || (oO = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
@@ -10066,15 +10032,6 @@ Unable to find an ` + (R === !1 ? "accessible " : "") + 'element with the role "
|
|
|
10066
10032
|
return cO || (cO = 1, process.env.NODE_ENV === "production" ? dS.exports = MU() : dS.exports = DU()), dS.exports;
|
|
10067
10033
|
}
|
|
10068
10034
|
var xU = zU(), pS = { exports: {} }, Ua = {};
|
|
10069
|
-
/**
|
|
10070
|
-
* @license React
|
|
10071
|
-
* react-dom.production.js
|
|
10072
|
-
*
|
|
10073
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10074
|
-
*
|
|
10075
|
-
* This source code is licensed under the MIT license found in the
|
|
10076
|
-
* LICENSE file in the root directory of this source tree.
|
|
10077
|
-
*/
|
|
10078
10035
|
var sO;
|
|
10079
10036
|
function UU() {
|
|
10080
10037
|
if (sO) return Ua;
|
|
@@ -10209,15 +10166,6 @@ Unable to find an ` + (R === !1 ? "accessible " : "") + 'element with the role "
|
|
|
10209
10166
|
}, Ua.version = "19.2.0", Ua;
|
|
10210
10167
|
}
|
|
10211
10168
|
var wa = {};
|
|
10212
|
-
/**
|
|
10213
|
-
* @license React
|
|
10214
|
-
* react-dom.development.js
|
|
10215
|
-
*
|
|
10216
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10217
|
-
*
|
|
10218
|
-
* This source code is licensed under the MIT license found in the
|
|
10219
|
-
* LICENSE file in the root directory of this source tree.
|
|
10220
|
-
*/
|
|
10221
10169
|
var fO;
|
|
10222
10170
|
function wU() {
|
|
10223
10171
|
return fO || (fO = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
@@ -10451,15 +10399,6 @@ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix
|
|
|
10451
10399
|
var NU = wT();
|
|
10452
10400
|
const bS = /* @__PURE__ */ SO(NU);
|
|
10453
10401
|
var mS = { exports: {} }, x0 = {}, hS = { exports: {} }, iT = {};
|
|
10454
|
-
/**
|
|
10455
|
-
* @license React
|
|
10456
|
-
* scheduler.production.js
|
|
10457
|
-
*
|
|
10458
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10459
|
-
*
|
|
10460
|
-
* This source code is licensed under the MIT license found in the
|
|
10461
|
-
* LICENSE file in the root directory of this source tree.
|
|
10462
|
-
*/
|
|
10463
10402
|
var pO;
|
|
10464
10403
|
function BU() {
|
|
10465
10404
|
return pO || (pO = 1, (function(s) {
|
|
@@ -10681,15 +10620,6 @@ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix
|
|
|
10681
10620
|
})(iT)), iT;
|
|
10682
10621
|
}
|
|
10683
10622
|
var oT = {};
|
|
10684
|
-
/**
|
|
10685
|
-
* @license React
|
|
10686
|
-
* scheduler.development.js
|
|
10687
|
-
*
|
|
10688
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10689
|
-
*
|
|
10690
|
-
* This source code is licensed under the MIT license found in the
|
|
10691
|
-
* LICENSE file in the root directory of this source tree.
|
|
10692
|
-
*/
|
|
10693
10623
|
var mO;
|
|
10694
10624
|
function HU() {
|
|
10695
10625
|
return mO || (mO = 1, (function(s) {
|
|
@@ -10917,15 +10847,6 @@ See https://react.dev/link/invalid-hook-call for tips about how to debug and fix
|
|
|
10917
10847
|
function tM() {
|
|
10918
10848
|
return hO || (hO = 1, process.env.NODE_ENV === "production" ? hS.exports = BU() : hS.exports = HU()), hS.exports;
|
|
10919
10849
|
}
|
|
10920
|
-
/**
|
|
10921
|
-
* @license React
|
|
10922
|
-
* react-dom-client.production.js
|
|
10923
|
-
*
|
|
10924
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10925
|
-
*
|
|
10926
|
-
* This source code is licensed under the MIT license found in the
|
|
10927
|
-
* LICENSE file in the root directory of this source tree.
|
|
10928
|
-
*/
|
|
10929
10850
|
var yO;
|
|
10930
10851
|
function jU() {
|
|
10931
10852
|
if (yO) return x0;
|
|
@@ -20700,15 +20621,6 @@ Error generating stack: ` + i.message + `
|
|
|
20700
20621
|
}, x0.version = "19.2.0", x0;
|
|
20701
20622
|
}
|
|
20702
20623
|
var U0 = {};
|
|
20703
|
-
/**
|
|
20704
|
-
* @license React
|
|
20705
|
-
* react-dom-client.development.js
|
|
20706
|
-
*
|
|
20707
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
20708
|
-
*
|
|
20709
|
-
* This source code is licensed under the MIT license found in the
|
|
20710
|
-
* LICENSE file in the root directory of this source tree.
|
|
20711
|
-
*/
|
|
20712
20624
|
var vO;
|
|
20713
20625
|
function LU() {
|
|
20714
20626
|
return vO || (vO = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
@@ -1,53 +1,62 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
function
|
|
7
|
-
const
|
|
8
|
-
for (const
|
|
9
|
-
if (!
|
|
1
|
+
import u from "../functions/calcTileSize.js";
|
|
2
|
+
import f from "./pointInCircle.js";
|
|
3
|
+
import x from "./pointInPolygon.js";
|
|
4
|
+
import h from "./pointInRectangle.js";
|
|
5
|
+
import g from "./pointOnLinePath.js";
|
|
6
|
+
function O(r, d, s, l, p, m) {
|
|
7
|
+
const e = u(p, m), i = [];
|
|
8
|
+
for (const n of d) {
|
|
9
|
+
if (!n.hasCollisions)
|
|
10
10
|
continue;
|
|
11
|
-
const
|
|
12
|
-
switch (
|
|
11
|
+
const t = n.x * e, a = n.y * e;
|
|
12
|
+
switch (n.constructorName) {
|
|
13
13
|
case "Rect":
|
|
14
14
|
case "CanvasImage":
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const o = n;
|
|
16
|
+
h(
|
|
17
|
+
t,
|
|
18
|
+
a,
|
|
19
|
+
o.width * e,
|
|
20
|
+
o.height * e,
|
|
21
|
+
s,
|
|
22
|
+
l,
|
|
23
|
+
o.rotation
|
|
24
|
+
) && i.push({
|
|
25
|
+
id: o.id,
|
|
26
|
+
element: n,
|
|
27
|
+
originalEvent: r,
|
|
28
|
+
posOnMap: { x: o.x, y: o.y }
|
|
21
29
|
});
|
|
22
30
|
break;
|
|
23
31
|
case "Circle":
|
|
24
|
-
|
|
25
|
-
id:
|
|
26
|
-
element:
|
|
27
|
-
originalEvent:
|
|
28
|
-
posOnMap: { x:
|
|
32
|
+
f(t, a, n.radius * e, s, l) && i.push({
|
|
33
|
+
id: n.id,
|
|
34
|
+
element: n,
|
|
35
|
+
originalEvent: r,
|
|
36
|
+
posOnMap: { x: n.x, y: n.y }
|
|
29
37
|
});
|
|
30
38
|
break;
|
|
31
39
|
case "Polygon":
|
|
32
|
-
|
|
33
|
-
id:
|
|
34
|
-
element:
|
|
35
|
-
originalEvent:
|
|
36
|
-
posOnMap: { x:
|
|
40
|
+
x(n.points, s, l, e) && i.push({
|
|
41
|
+
id: n.id,
|
|
42
|
+
element: n,
|
|
43
|
+
originalEvent: r,
|
|
44
|
+
posOnMap: { x: n.x, y: n.y }
|
|
37
45
|
});
|
|
38
46
|
break;
|
|
39
47
|
case "LinePath":
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
const c = n;
|
|
49
|
+
g(c.points, c.lineWidth, s, l, e) && i.push({
|
|
50
|
+
id: n.id,
|
|
51
|
+
element: n,
|
|
52
|
+
originalEvent: r,
|
|
53
|
+
posOnMap: { x: n.x, y: n.y }
|
|
45
54
|
});
|
|
46
55
|
break;
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
|
-
return i.length === 0 ? null : (i.length === 1 || i.sort((
|
|
58
|
+
return i.length === 0 ? null : (i.length === 1 || i.sort((n, t) => n.element.zIndex > t.element.zIndex ? -1 : n.element.zIndex < t.element.zIndex || n.id > t.id ? 1 : n.id < t.id ? -1 : 0), i[0]);
|
|
50
59
|
}
|
|
51
60
|
export {
|
|
52
|
-
|
|
61
|
+
O as default
|
|
53
62
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function c(x, e, y, f) {
|
|
2
|
+
var v = e.x - x.x, d = e.y - x.y, u = f.x - y.x, _ = f.y - y.y, t = (-d * (x.x - y.x) + v * (x.y - y.y)) / (-u * d + v * _), l = (+u * (x.y - y.y) - _ * (x.x - y.x)) / (-u * d + v * _);
|
|
3
|
+
return t >= 0 && t <= 1 && l >= 0 && l <= 1 ? { x: x.x + l * v, y: x.y + l * d } : null;
|
|
4
|
+
}
|
|
5
|
+
export {
|
|
6
|
+
c as default
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function pointInCircle(centerX: number, centerY: number, radius: number, pointX: number, pointY: number): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function s(r, a, t, u = 1) {
|
|
2
|
+
let n = !1;
|
|
3
|
+
for (let e = 0; e < r.length; e++) {
|
|
4
|
+
const l = r[e].x * u, f = r[e].y * u;
|
|
5
|
+
if (a === l && t === f)
|
|
6
|
+
return !0;
|
|
7
|
+
let c = e + 1;
|
|
8
|
+
c >= r.length && (c = 0);
|
|
9
|
+
const j = r[c].x * u, o = r[c].y * u;
|
|
10
|
+
if (f > t != o > t) {
|
|
11
|
+
const g = (a - l) * (o - f) - (j - l) * (t - f);
|
|
12
|
+
if (g === 0)
|
|
13
|
+
return !0;
|
|
14
|
+
g < 0 != o < f && (n = !n);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
s as default
|
|
21
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function pointInRectangle(rectangleX: number, rectangleY: number, rectangleWidth: number, rectangleHeight: number, pointX: number, pointY: number, rotation?: number): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function L(f, M, x, I, u, c, s) {
|
|
2
|
+
let d = u, h = c;
|
|
3
|
+
if (s) {
|
|
4
|
+
const e = f + x / 2, t = M + I / 2;
|
|
5
|
+
d = e + (u - e) * Math.cos(-s) - (c - t) * Math.sin(-s), h = t + (c - t) * Math.cos(-s) + (u - e) * Math.sin(-s);
|
|
6
|
+
}
|
|
7
|
+
return f <= d && d <= f + x && M <= h && h <= M + I;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
L as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import h from "./pointInCircle.js";
|
|
2
|
+
function q(r, m, u, n, x = 1) {
|
|
3
|
+
const a = m / 2;
|
|
4
|
+
if (h(
|
|
5
|
+
r[0].x * x,
|
|
6
|
+
r[0].y * x,
|
|
7
|
+
a * x,
|
|
8
|
+
u,
|
|
9
|
+
n
|
|
10
|
+
) || h(
|
|
11
|
+
r[r.length - 1].x * x,
|
|
12
|
+
r[r.length - 1].y * x,
|
|
13
|
+
a * x,
|
|
14
|
+
u,
|
|
15
|
+
n
|
|
16
|
+
))
|
|
17
|
+
return !0;
|
|
18
|
+
for (let f = 1; f < r.length; f++) {
|
|
19
|
+
const y = {
|
|
20
|
+
x: r[f - 1].x * x,
|
|
21
|
+
y: r[f - 1].y * x
|
|
22
|
+
}, c = {
|
|
23
|
+
x: r[f].x * x,
|
|
24
|
+
y: r[f].y * x
|
|
25
|
+
}, d = y.x - c.x, o = y.y - c.y, s = Math.sqrt(d * d + o * o), t = ((u - y.x) * (c.x - y.x) + (n - y.y) * (c.y - y.y)) / Math.pow(s, 2);
|
|
26
|
+
if (t < 0 || t > 1)
|
|
27
|
+
continue;
|
|
28
|
+
const g = {
|
|
29
|
+
x: y.x + t * (c.x - y.x),
|
|
30
|
+
y: y.y + t * (c.y - y.y)
|
|
31
|
+
};
|
|
32
|
+
if (h(
|
|
33
|
+
g.x,
|
|
34
|
+
g.y,
|
|
35
|
+
a * x,
|
|
36
|
+
u,
|
|
37
|
+
n
|
|
38
|
+
))
|
|
39
|
+
return !0;
|
|
40
|
+
}
|
|
41
|
+
return !1;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
q as default
|
|
45
|
+
};
|
package/dist/main.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
1
|
import { default as Canvas2D } from './Canvas2D';
|
|
2
|
+
import { default as lineWithLine } from './collisions/lineWithLine';
|
|
3
|
+
import { default as pointInCircle } from './collisions/pointInCircle';
|
|
4
|
+
import { default as pointInPolygon } from './collisions/pointInPolygon';
|
|
5
|
+
import { default as pointInRectangle } from './collisions/pointInRectangle';
|
|
6
|
+
import { default as pointOnLinePath } from './collisions/pointOnLinePath';
|
|
2
7
|
import { default as preloadImages } from './functions/preloadImages';
|
|
3
8
|
import { default as useGamepad } from './hooks/useGamepad';
|
|
4
9
|
import { default as useKeyboard } from './hooks/useKeyboard';
|
|
5
10
|
import { default as useMousePosition } from './hooks/useMousePosition';
|
|
6
11
|
import { default as useWindowDimensions } from './hooks/useWindowDimensions';
|
|
12
|
+
import { default as getLineLength } from './maths/getLineLength';
|
|
13
|
+
import { default as normalOnLine } from './maths/normalOnLine';
|
|
14
|
+
import { default as segmentAngle } from './maths/segmentAngle';
|
|
7
15
|
import { default as CanvasImage } from './shapes/CanvasImage';
|
|
8
16
|
import { default as CanvasObject } from './shapes/CanvasObject';
|
|
9
17
|
import { default as Circle } from './shapes/Circle';
|
|
10
18
|
import { default as LinePath } from './shapes/LinePath';
|
|
11
19
|
import { default as Polygon } from './shapes/Polygon';
|
|
12
20
|
import { default as Rect } from './shapes/Rect';
|
|
21
|
+
import { default as Canvas2DProps } from './types/Canvas2DProps';
|
|
22
|
+
import { default as CollideElementResultItem } from './types/CollideElementResultItem';
|
|
23
|
+
import { default as Position2D } from './types/Position2D';
|
|
24
|
+
import { default as Surface2D } from './types/Surface2D';
|
|
13
25
|
declare global {
|
|
14
26
|
var __canvas2dWrapper__: {
|
|
15
27
|
imgCache: {
|
|
@@ -17,4 +29,10 @@ declare global {
|
|
|
17
29
|
};
|
|
18
30
|
};
|
|
19
31
|
}
|
|
20
|
-
export { Canvas2D
|
|
32
|
+
export { Canvas2D };
|
|
33
|
+
export { CanvasImage, CanvasObject, Circle, LinePath, Polygon, Rect };
|
|
34
|
+
export { lineWithLine, pointInCircle, pointInPolygon, pointInRectangle, pointOnLinePath };
|
|
35
|
+
export { preloadImages };
|
|
36
|
+
export { useGamepad, useKeyboard, useMousePosition, useWindowDimensions };
|
|
37
|
+
export { getLineLength, normalOnLine, segmentAngle };
|
|
38
|
+
export { type Canvas2DProps, type CollideElementResultItem, type Position2D, type Surface2D };
|
package/dist/main.js
CHANGED
|
@@ -1,26 +1,42 @@
|
|
|
1
1
|
import { default as o } from "./Canvas2D.js";
|
|
2
|
-
import { default as r } from "./
|
|
3
|
-
import { default as s } from "./
|
|
4
|
-
import { default as
|
|
5
|
-
import { default as
|
|
6
|
-
import { default as
|
|
7
|
-
import { default as i } from "./
|
|
8
|
-
import { default as
|
|
9
|
-
import { default as
|
|
10
|
-
import { default as
|
|
11
|
-
import { default as
|
|
12
|
-
import { default as
|
|
2
|
+
import { default as r } from "./collisions/lineWithLine.js";
|
|
3
|
+
import { default as s } from "./collisions/pointInCircle.js";
|
|
4
|
+
import { default as n } from "./collisions/pointInPolygon.js";
|
|
5
|
+
import { default as p } from "./collisions/pointInRectangle.js";
|
|
6
|
+
import { default as d } from "./collisions/pointOnLinePath.js";
|
|
7
|
+
import { default as i } from "./functions/preloadImages.js";
|
|
8
|
+
import { default as L } from "./hooks/useGamepad.js";
|
|
9
|
+
import { default as C } from "./hooks/useKeyboard.js";
|
|
10
|
+
import { default as P } from "./hooks/useMousePosition.js";
|
|
11
|
+
import { default as v } from "./hooks/useWindowDimensions.js";
|
|
12
|
+
import { default as O } from "./maths/getLineLength.js";
|
|
13
|
+
import { default as D } from "./maths/normalOnLine.js";
|
|
14
|
+
import { default as W } from "./maths/segmentAngle.js";
|
|
15
|
+
import { default as w } from "./shapes/CanvasImage.js";
|
|
16
|
+
import { default as G } from "./shapes/CanvasObject.js";
|
|
17
|
+
import { default as M } from "./shapes/Circle.js";
|
|
18
|
+
import { default as q } from "./shapes/LinePath.js";
|
|
19
|
+
import { default as B } from "./shapes/Polygon.js";
|
|
20
|
+
import { default as F } from "./shapes/Rect.js";
|
|
13
21
|
export {
|
|
14
22
|
o as Canvas2D,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
w as CanvasImage,
|
|
24
|
+
G as CanvasObject,
|
|
25
|
+
M as Circle,
|
|
26
|
+
q as LinePath,
|
|
27
|
+
B as Polygon,
|
|
28
|
+
F as Rect,
|
|
29
|
+
O as getLineLength,
|
|
30
|
+
r as lineWithLine,
|
|
31
|
+
D as normalOnLine,
|
|
32
|
+
s as pointInCircle,
|
|
33
|
+
n as pointInPolygon,
|
|
34
|
+
p as pointInRectangle,
|
|
35
|
+
d as pointOnLinePath,
|
|
36
|
+
i as preloadImages,
|
|
37
|
+
W as segmentAngle,
|
|
38
|
+
L as useGamepad,
|
|
39
|
+
C as useKeyboard,
|
|
40
|
+
P as useMousePosition,
|
|
41
|
+
v as useWindowDimensions
|
|
26
42
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canvas2d-wrapper",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -20,28 +20,28 @@
|
|
|
20
20
|
"react-dom": "^19.0.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@eslint/js": "^9.39.
|
|
23
|
+
"@eslint/js": "^9.39.1",
|
|
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.
|
|
28
|
-
"@types/react": "^19.2.
|
|
29
|
-
"@types/react-dom": "^19.2.
|
|
30
|
-
"@vitejs/plugin-react": "^5.1.
|
|
31
|
-
"@vitest/coverage-v8": "^4.0.
|
|
32
|
-
"eslint": "^9.39.
|
|
27
|
+
"@types/node": "^24.10.1",
|
|
28
|
+
"@types/react": "^19.2.7",
|
|
29
|
+
"@types/react-dom": "^19.2.3",
|
|
30
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
31
|
+
"@vitest/coverage-v8": "^4.0.13",
|
|
32
|
+
"eslint": "^9.39.1",
|
|
33
33
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
34
34
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
35
|
-
"glob": "^
|
|
35
|
+
"glob": "^13.0.0",
|
|
36
36
|
"globals": "^16.5.0",
|
|
37
|
-
"jsdom": "^27.
|
|
37
|
+
"jsdom": "^27.2.0",
|
|
38
38
|
"react": "^19.2.0",
|
|
39
39
|
"react-dom": "^19.2.0",
|
|
40
40
|
"typescript": "5.9",
|
|
41
|
-
"typescript-eslint": "^8.
|
|
42
|
-
"vite": "^7.
|
|
41
|
+
"typescript-eslint": "^8.48.0",
|
|
42
|
+
"vite": "^7.2.4",
|
|
43
43
|
"vite-plugin-dts": "^4.5.4",
|
|
44
44
|
"vite-plugin-lib-inject-css": "^2.2.2",
|
|
45
|
-
"vitest": "^4.0.
|
|
45
|
+
"vitest": "^4.0.13"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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)
|
|
6
|
-
return !0;
|
|
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);
|
|
12
|
-
if (j === 0)
|
|
13
|
-
return !0;
|
|
14
|
-
j < 0 != c < r && (f = !f);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return f;
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
y as default
|
|
21
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function g(i, h, c, s, e, r, t) {
|
|
2
|
-
const u = i.width * r, f = i.height * r;
|
|
3
|
-
let n = s, d = e;
|
|
4
|
-
if (t) {
|
|
5
|
-
const M = h + u / 2, a = c + f / 2;
|
|
6
|
-
n = M + (s - M) * Math.cos(-t) - (e - a) * Math.sin(-t), d = a + (e - a) * Math.cos(-t) + (s - M) * Math.sin(-t);
|
|
7
|
-
}
|
|
8
|
-
return h <= n && n <= h + u && c <= d && d <= c + f;
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
g as default
|
|
12
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import f from "./inCircle.js";
|
|
2
|
-
function q(t, x, y, n) {
|
|
3
|
-
const p = t.lineWidth;
|
|
4
|
-
if (f(
|
|
5
|
-
{ radius: p },
|
|
6
|
-
t.points[0].x * n,
|
|
7
|
-
t.points[0].y * n,
|
|
8
|
-
x,
|
|
9
|
-
y,
|
|
10
|
-
n
|
|
11
|
-
) || f(
|
|
12
|
-
{ radius: p },
|
|
13
|
-
t.points[t.points.length - 1].x * n,
|
|
14
|
-
t.points[t.points.length - 1].y * n,
|
|
15
|
-
x,
|
|
16
|
-
y,
|
|
17
|
-
n
|
|
18
|
-
))
|
|
19
|
-
return !0;
|
|
20
|
-
for (let r = 1; r < t.points.length; r++) {
|
|
21
|
-
const s = {
|
|
22
|
-
x: t.points[r - 1].x * n,
|
|
23
|
-
y: t.points[r - 1].y * n
|
|
24
|
-
}, o = {
|
|
25
|
-
x: t.points[r].x * n,
|
|
26
|
-
y: t.points[r].y * n
|
|
27
|
-
}, u = s.x - o.x, h = s.y - o.y, g = Math.sqrt(u * u + h * h), d = ((x - s.x) * (o.x - s.x) + (y - s.y) * (o.y - s.y)) / Math.pow(g, 2), i = {
|
|
28
|
-
x: s.x + d * (o.x - s.x),
|
|
29
|
-
y: s.y + d * (o.y - s.y)
|
|
30
|
-
};
|
|
31
|
-
if (f(
|
|
32
|
-
{ radius: p },
|
|
33
|
-
i.x,
|
|
34
|
-
i.y,
|
|
35
|
-
x,
|
|
36
|
-
y,
|
|
37
|
-
n
|
|
38
|
-
))
|
|
39
|
-
return !0;
|
|
40
|
-
}
|
|
41
|
-
return !1;
|
|
42
|
-
}
|
|
43
|
-
export {
|
|
44
|
-
q as default
|
|
45
|
-
};
|