canvas2d-wrapper 1.14.0 → 2.0.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 +3 -0
- package/dist/Canvas2D.js +158 -0
- package/dist/Canvas2D.spec.d.ts +0 -0
- package/dist/Canvas2D.spec.js +38101 -0
- package/dist/assets/Canvas2D.css +1 -0
- package/dist/collisions/collideElement.d.ts +3 -0
- package/dist/collisions/collideElement.js +53 -0
- package/dist/collisions/inCircle.d.ts +3 -0
- package/dist/collisions/inCircle.js +6 -0
- package/dist/collisions/inPoly.d.ts +2 -0
- package/dist/collisions/inPoly.js +20 -0
- package/dist/collisions/inRect.d.ts +2 -0
- package/dist/collisions/inRect.js +12 -0
- package/dist/collisions/onLinePath.d.ts +2 -0
- package/dist/collisions/onLinePath.js +45 -0
- package/dist/events/computeEventPositions.d.ts +9 -0
- package/dist/events/computeEventPositions.js +7 -0
- package/dist/events/elementClick.d.ts +4 -0
- package/dist/events/elementClick.js +18 -0
- package/dist/events/elementRightClick.d.ts +4 -0
- package/dist/events/elementRightClick.js +13 -0
- package/dist/events/mouseMove.d.ts +5 -0
- package/dist/events/mouseMove.js +37 -0
- package/dist/events/mouseWheel.d.ts +2 -0
- package/dist/events/mouseWheel.js +10 -0
- package/dist/functions/calcRatioForMinimap.d.ts +2 -0
- package/dist/functions/calcRatioForMinimap.js +15 -0
- package/dist/functions/calcTileSize.d.ts +1 -0
- package/dist/functions/calcTileSize.js +6 -0
- package/dist/functions/preloadImages.d.ts +1 -0
- package/dist/functions/preloadImages.js +7 -0
- package/dist/functions/sortElements.d.ts +2 -0
- package/dist/functions/sortElements.js +18 -0
- package/dist/generateTestData.d.ts +2 -0
- package/dist/generateTestData.js +48 -0
- package/dist/hooks/useGamepad.d.ts +1 -0
- package/dist/hooks/useGamepad.js +13 -0
- package/dist/hooks/useKeyboard.d.ts +5 -0
- package/dist/hooks/useKeyboard.js +19 -0
- package/dist/hooks/useMousePosition.d.ts +6 -0
- package/dist/hooks/useMousePosition.js +25 -0
- package/dist/hooks/useWindowDimensions.d.ts +4 -0
- package/dist/hooks/useWindowDimensions.js +20 -0
- package/dist/img/logo.png +0 -0
- package/dist/main.d.ts +20 -0
- package/dist/main.js +26 -0
- package/dist/render/renderCanvas.d.ts +3 -0
- package/dist/render/renderCanvas.js +35 -0
- package/dist/render/renderCircle.d.ts +2 -0
- package/dist/render/renderCircle.js +12 -0
- package/dist/render/renderImage.d.ts +2 -0
- package/dist/render/renderImage.js +41 -0
- package/dist/render/renderLinePath.d.ts +2 -0
- package/dist/render/renderLinePath.js +27 -0
- package/dist/render/renderPolygon.d.ts +2 -0
- package/dist/render/renderPolygon.js +18 -0
- package/dist/render/renderRect.d.ts +2 -0
- package/dist/render/renderRect.js +27 -0
- package/dist/shapes/CanvasImage.d.ts +40 -0
- package/dist/shapes/CanvasImage.js +38 -0
- package/dist/shapes/CanvasObject.d.ts +14 -0
- package/dist/shapes/CanvasObject.js +27 -0
- package/dist/shapes/Circle.d.ts +28 -0
- package/dist/shapes/Circle.js +25 -0
- package/dist/shapes/ColoredCanvasObject.d.ts +7 -0
- package/dist/shapes/ColoredCanvasObject.js +14 -0
- package/dist/shapes/LinePath.d.ts +31 -0
- package/dist/shapes/LinePath.js +28 -0
- package/dist/shapes/Polygon.d.ts +25 -0
- package/dist/shapes/Polygon.js +23 -0
- package/dist/shapes/Rect.d.ts +34 -0
- package/dist/shapes/Rect.js +29 -0
- package/dist/types/Canvas2DProps.d.ts +30 -0
- package/dist/types/Canvas2DProps.js +1 -0
- package/dist/types/Canvas2DState.d.ts +18 -0
- package/dist/types/Canvas2DState.js +1 -0
- package/dist/types/CollideElementResultItem.d.ts +9 -0
- package/dist/types/CollideElementResultItem.js +1 -0
- package/dist/types/Position2D.d.ts +5 -0
- package/dist/types/Position2D.js +1 -0
- package/dist/types/Surface2D.d.ts +7 -0
- package/dist/types/Surface2D.js +1 -0
- package/package.json +48 -56
- package/canvas2d-wrapper.d.ts +0 -285
- package/dist/index.css +0 -3
- package/dist/index.js +0 -1088
- package/dist/index.js.map +0 -1
- package/dist/index.modern.js +0 -1074
- package/dist/index.modern.js.map +0 -1
@@ -0,0 +1,41 @@
|
|
1
|
+
window.__canvas2dWrapper__ = { imgCache: {} };
|
2
|
+
function p(a, s, g, c, h) {
|
3
|
+
__canvas2dWrapper__.imgCache[s.src] || (__canvas2dWrapper__.imgCache[s.src] = new Image(), __canvas2dWrapper__.imgCache[s.src].src = s.src);
|
4
|
+
const i = g + s.x * h, d = c + s.y * h, r = s.width * h, _ = s.height * h;
|
5
|
+
s.rotation ? (a.save(), a.translate(i + r / 2, d + _ / 2), a.rotate(s.rotation), !s.sx || !s.sy || !s.swidth || !s.sheight ? a.drawImage(
|
6
|
+
__canvas2dWrapper__.imgCache[s.src],
|
7
|
+
-r / 2,
|
8
|
+
-_ / 2,
|
9
|
+
r,
|
10
|
+
_
|
11
|
+
) : a.drawImage(
|
12
|
+
__canvas2dWrapper__.imgCache[s.src],
|
13
|
+
s.sx,
|
14
|
+
s.sy,
|
15
|
+
s.swidth,
|
16
|
+
s.sheight,
|
17
|
+
-s.swidth / 2,
|
18
|
+
-s.sheight / 2,
|
19
|
+
r,
|
20
|
+
_
|
21
|
+
), a.restore()) : !s.sx || !s.sy || !s.swidth || !s.sheight ? a.drawImage(
|
22
|
+
__canvas2dWrapper__.imgCache[s.src],
|
23
|
+
i,
|
24
|
+
d,
|
25
|
+
r,
|
26
|
+
_
|
27
|
+
) : a.drawImage(
|
28
|
+
__canvas2dWrapper__.imgCache[s.src],
|
29
|
+
s.sx,
|
30
|
+
s.sy,
|
31
|
+
s.swidth,
|
32
|
+
s.sheight,
|
33
|
+
i,
|
34
|
+
d,
|
35
|
+
r,
|
36
|
+
_
|
37
|
+
);
|
38
|
+
}
|
39
|
+
export {
|
40
|
+
p as default
|
41
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
function L(n, r, g, l, i) {
|
2
|
+
const p = n.lineWidth, o = r.points.map((s) => ({
|
3
|
+
x: g + s.x * i,
|
4
|
+
y: l + s.y * i
|
5
|
+
}));
|
6
|
+
if (!(o.length < 2)) {
|
7
|
+
if (n.beginPath(), n.moveTo(o[0].x, o[0].y), r.smoothCorners && r.smoothCornersRadius) {
|
8
|
+
for (let s = 1; s < o.length - 1; s++) {
|
9
|
+
const h = o[s - 1], t = o[s], y = o[s + 1], d = t.x - h.x, f = t.y - h.y, a = y.x - t.x, u = y.y - t.y, c = Math.hypot(d, f), x = Math.hypot(a, u), R = d / c * r.smoothCornersRadius, W = f / c * r.smoothCornersRadius, v = a / x * r.smoothCornersRadius, T = u / x * r.smoothCornersRadius, e = {
|
10
|
+
x: t.x - R,
|
11
|
+
y: t.y - W
|
12
|
+
}, C = {
|
13
|
+
x: t.x + v,
|
14
|
+
y: t.y + T
|
15
|
+
};
|
16
|
+
n.lineTo(e.x, e.y), n.quadraticCurveTo(t.x, t.y, C.x, C.y);
|
17
|
+
}
|
18
|
+
n.lineTo(o[o.length - 1].x, o[o.length - 1].y);
|
19
|
+
} else
|
20
|
+
for (let s = 1; s < o.length; s++)
|
21
|
+
n.lineTo(o[s].x, o[s].y);
|
22
|
+
n.lineWidth = r.lineWidth * i, n.stroke(), n.lineWidth = p;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
export {
|
26
|
+
L as default
|
27
|
+
};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
function y(i, s, r, f, o) {
|
2
|
+
i.beginPath(), i.moveTo(
|
3
|
+
r + s.points[0].x * o,
|
4
|
+
f + s.points[0].y * o
|
5
|
+
);
|
6
|
+
for (let p = 0; p < s.points.length; p++)
|
7
|
+
i.lineTo(
|
8
|
+
r + s.points[p].x * o,
|
9
|
+
f + s.points[p].y * o
|
10
|
+
);
|
11
|
+
i.lineTo(
|
12
|
+
r + s.points[0].x * o,
|
13
|
+
f + s.points[0].y * o
|
14
|
+
), s.fill && i.fill(), s.stroke && i.stroke();
|
15
|
+
}
|
16
|
+
export {
|
17
|
+
y as default
|
18
|
+
};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
function d(r, s, a, R, o) {
|
2
|
+
const t = a + s.x * o, h = R + s.y * o, i = s.width * o, f = s.height * o;
|
3
|
+
s.rotation ? (r.save(), r.translate(t + i / 2, h + f / 2), r.rotate(s.rotation), s.fill && r.fillRect(
|
4
|
+
-i / 2,
|
5
|
+
-i / 2,
|
6
|
+
i,
|
7
|
+
f
|
8
|
+
), s.stroke && r.strokeRect(
|
9
|
+
-i / 2,
|
10
|
+
-i / 2,
|
11
|
+
i,
|
12
|
+
f
|
13
|
+
), r.restore()) : (s.fill && r.fillRect(
|
14
|
+
t,
|
15
|
+
h,
|
16
|
+
i,
|
17
|
+
f
|
18
|
+
), s.stroke && r.strokeRect(
|
19
|
+
t,
|
20
|
+
h,
|
21
|
+
i,
|
22
|
+
f
|
23
|
+
));
|
24
|
+
}
|
25
|
+
export {
|
26
|
+
d as default
|
27
|
+
};
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import { default as CanvasObject } from './CanvasObject';
|
2
|
+
export default class CanvasImage extends CanvasObject {
|
3
|
+
src: string;
|
4
|
+
width: number;
|
5
|
+
height: number;
|
6
|
+
rotation?: number;
|
7
|
+
swidth?: number;
|
8
|
+
sheight?: number;
|
9
|
+
sx?: number;
|
10
|
+
sy?: number;
|
11
|
+
/**
|
12
|
+
* Represents an Image that will be created on the canvas.
|
13
|
+
* Note: a cache to prevent too much loading is implemented, you can create as much
|
14
|
+
* images as you want of the same source without any performance issue.
|
15
|
+
*
|
16
|
+
* @param {string|number} id Identifier (used in click callback)
|
17
|
+
* @param {number} x Left coordinate of top-left corner of picture in canvas
|
18
|
+
* @param {number} y Top coordinate of top-left corner of picture in canvas
|
19
|
+
* @param {number} width Picture width in canvas
|
20
|
+
* @param {number} height Picture height in canvas
|
21
|
+
* @param {string} src Image source link
|
22
|
+
* @param {number} zIndex Stack order of the element
|
23
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
24
|
+
* @param {number} rotation The rotation in radians
|
25
|
+
*/
|
26
|
+
constructor({ id, x, y, width, height, src, zIndex, draggable, hasCollisions, rotation }: {
|
27
|
+
id: string;
|
28
|
+
x: number;
|
29
|
+
y: number;
|
30
|
+
width: number;
|
31
|
+
height: number;
|
32
|
+
src: string;
|
33
|
+
zIndex?: number;
|
34
|
+
draggable?: boolean;
|
35
|
+
hasCollisions?: boolean;
|
36
|
+
rotation?: number;
|
37
|
+
});
|
38
|
+
crop(sx: number, swidth: number, sheight: number): void;
|
39
|
+
get constructorName(): string;
|
40
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import g from "./CanvasObject.js";
|
2
|
+
class u extends g {
|
3
|
+
src;
|
4
|
+
width;
|
5
|
+
height;
|
6
|
+
rotation;
|
7
|
+
swidth;
|
8
|
+
sheight;
|
9
|
+
sx;
|
10
|
+
sy;
|
11
|
+
/**
|
12
|
+
* Represents an Image that will be created on the canvas.
|
13
|
+
* Note: a cache to prevent too much loading is implemented, you can create as much
|
14
|
+
* images as you want of the same source without any performance issue.
|
15
|
+
*
|
16
|
+
* @param {string|number} id Identifier (used in click callback)
|
17
|
+
* @param {number} x Left coordinate of top-left corner of picture in canvas
|
18
|
+
* @param {number} y Top coordinate of top-left corner of picture in canvas
|
19
|
+
* @param {number} width Picture width in canvas
|
20
|
+
* @param {number} height Picture height in canvas
|
21
|
+
* @param {string} src Image source link
|
22
|
+
* @param {number} zIndex Stack order of the element
|
23
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
24
|
+
* @param {number} rotation The rotation in radians
|
25
|
+
*/
|
26
|
+
constructor({ id: t, x: s, y: h, width: i, height: e, src: r, zIndex: a, draggable: o, hasCollisions: c, rotation: n }) {
|
27
|
+
super(t, s, h, a, o, c), this.width = i, this.height = e, this.src = r, this.rotation = n;
|
28
|
+
}
|
29
|
+
crop(t, s, h) {
|
30
|
+
this.sx = t, this.sy = t, this.swidth = s, this.sheight = h;
|
31
|
+
}
|
32
|
+
get constructorName() {
|
33
|
+
return "CanvasImage";
|
34
|
+
}
|
35
|
+
}
|
36
|
+
export {
|
37
|
+
u as default
|
38
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export default class CanvasObject {
|
2
|
+
id: string;
|
3
|
+
x: number;
|
4
|
+
y: number;
|
5
|
+
draggable?: boolean;
|
6
|
+
hasCollisions?: boolean;
|
7
|
+
['z-index']?: number;
|
8
|
+
fill?: string;
|
9
|
+
stroke?: string;
|
10
|
+
constructor(id: string, x: number, y: number, zIndex?: number, draggable?: boolean, hasCollisions?: boolean);
|
11
|
+
set zIndex(zIndex: number);
|
12
|
+
get zIndex(): number;
|
13
|
+
get constructorName(): string;
|
14
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class d {
|
2
|
+
id;
|
3
|
+
x;
|
4
|
+
y;
|
5
|
+
draggable;
|
6
|
+
hasCollisions;
|
7
|
+
"z-index";
|
8
|
+
fill;
|
9
|
+
// Always undefined here but needed for typescript to work with renderCanvas() sorting
|
10
|
+
stroke;
|
11
|
+
// Always undefined here but needed for typescript to work with renderCanvas() sorting
|
12
|
+
constructor(s, t, e, i, a, n) {
|
13
|
+
this.id = s, this.x = t, this.y = e, this["z-index"] = i, this.draggable = a, this.hasCollisions = n;
|
14
|
+
}
|
15
|
+
set zIndex(s) {
|
16
|
+
this["z-index"] = s;
|
17
|
+
}
|
18
|
+
get zIndex() {
|
19
|
+
return this["z-index"] || 0;
|
20
|
+
}
|
21
|
+
get constructorName() {
|
22
|
+
return "CanvasObject";
|
23
|
+
}
|
24
|
+
}
|
25
|
+
export {
|
26
|
+
d as default
|
27
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { default as ColoredCanvasObject } from './ColoredCanvasObject';
|
2
|
+
export default class Circle extends ColoredCanvasObject {
|
3
|
+
radius: number;
|
4
|
+
/**
|
5
|
+
* Represents a Rectangle that will be created on the canvas.
|
6
|
+
*
|
7
|
+
* @param {string|number} id Identifier (used in click callback)
|
8
|
+
* @param {number} x Left coordinate of circle center in canvas
|
9
|
+
* @param {number} y Top coordinate of circle center in canvas
|
10
|
+
* @param {number} radius Circle radius in canvas
|
11
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
12
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
13
|
+
* @param {number} zIndex Stack order of the element
|
14
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
15
|
+
*/
|
16
|
+
constructor({ id, x, y, radius, fill, stroke, zIndex, draggable, hasCollisions }: {
|
17
|
+
id: string;
|
18
|
+
x: number;
|
19
|
+
y: number;
|
20
|
+
radius: number;
|
21
|
+
fill?: string;
|
22
|
+
stroke?: string;
|
23
|
+
zIndex?: number;
|
24
|
+
draggable?: boolean;
|
25
|
+
hasCollisions?: boolean;
|
26
|
+
});
|
27
|
+
get constructorName(): string;
|
28
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import d from "./ColoredCanvasObject.js";
|
2
|
+
class C extends d {
|
3
|
+
radius;
|
4
|
+
/**
|
5
|
+
* Represents a Rectangle that will be created on the canvas.
|
6
|
+
*
|
7
|
+
* @param {string|number} id Identifier (used in click callback)
|
8
|
+
* @param {number} x Left coordinate of circle center in canvas
|
9
|
+
* @param {number} y Top coordinate of circle center in canvas
|
10
|
+
* @param {number} radius Circle radius in canvas
|
11
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
12
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
13
|
+
* @param {number} zIndex Stack order of the element
|
14
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
15
|
+
*/
|
16
|
+
constructor({ id: r, x: e, y: t, radius: s, fill: o, stroke: a, zIndex: c, draggable: u, hasCollisions: i }) {
|
17
|
+
super(r, e, t, o, a, c, u, i), this.radius = s;
|
18
|
+
}
|
19
|
+
get constructorName() {
|
20
|
+
return "Circle";
|
21
|
+
}
|
22
|
+
}
|
23
|
+
export {
|
24
|
+
C as default
|
25
|
+
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { default as CanvasObject } from './CanvasObject';
|
2
|
+
export default class ColoredCanvasObject extends CanvasObject {
|
3
|
+
fill?: string;
|
4
|
+
stroke?: string;
|
5
|
+
constructor(id: string, x: number, y: number, fill?: string, stroke?: string, zIndex?: number, draggable?: boolean, hasCollisions?: boolean);
|
6
|
+
get constructorName(): string;
|
7
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import n from "./CanvasObject.js";
|
2
|
+
class C extends n {
|
3
|
+
fill;
|
4
|
+
stroke;
|
5
|
+
constructor(t, e, r, s, o, a, c, l) {
|
6
|
+
super(t, e, r, a, c, l), this.fill = s, this.stroke = o;
|
7
|
+
}
|
8
|
+
get constructorName() {
|
9
|
+
return "ColoredCanvasObject";
|
10
|
+
}
|
11
|
+
}
|
12
|
+
export {
|
13
|
+
C as default
|
14
|
+
};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { default as Position2D } from '../types/Position2D';
|
2
|
+
import { default as ColoredCanvasObject } from './ColoredCanvasObject';
|
3
|
+
export default class LinePath extends ColoredCanvasObject {
|
4
|
+
points: Position2D[];
|
5
|
+
lineWidth: number;
|
6
|
+
smoothCorners?: boolean;
|
7
|
+
smoothCornersRadius?: number;
|
8
|
+
/**
|
9
|
+
* Represents a Line Path that will be created on the canvas.
|
10
|
+
*
|
11
|
+
* @param {string|number} id Identifier (used in click callback)
|
12
|
+
* @param {number} points Array of coordinates {x, y} of the polygon points
|
13
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
14
|
+
* @param {number} zIndex Stack order of the element
|
15
|
+
* @param {number} lineWidth Width of the stroked line
|
16
|
+
* @param {number} smoothCorners Should we have smooth corners ?
|
17
|
+
* @param {number} smoothCornersRadius Radius of smoothed corners
|
18
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
19
|
+
*/
|
20
|
+
constructor({ id, lineWidth, points, stroke, zIndex, smoothCorners, smoothCornersRadius, hasCollisions }: {
|
21
|
+
id: string;
|
22
|
+
lineWidth: number;
|
23
|
+
points: Position2D[];
|
24
|
+
stroke: string;
|
25
|
+
zIndex?: number;
|
26
|
+
smoothCorners?: boolean;
|
27
|
+
smoothCornersRadius?: number;
|
28
|
+
hasCollisions?: boolean;
|
29
|
+
});
|
30
|
+
get constructorName(): string;
|
31
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import a from "./ColoredCanvasObject.js";
|
2
|
+
class u extends a {
|
3
|
+
points;
|
4
|
+
lineWidth;
|
5
|
+
smoothCorners;
|
6
|
+
smoothCornersRadius;
|
7
|
+
/**
|
8
|
+
* Represents a Line Path that will be created on the canvas.
|
9
|
+
*
|
10
|
+
* @param {string|number} id Identifier (used in click callback)
|
11
|
+
* @param {number} points Array of coordinates {x, y} of the polygon points
|
12
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
13
|
+
* @param {number} zIndex Stack order of the element
|
14
|
+
* @param {number} lineWidth Width of the stroked line
|
15
|
+
* @param {number} smoothCorners Should we have smooth corners ?
|
16
|
+
* @param {number} smoothCornersRadius Radius of smoothed corners
|
17
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
18
|
+
*/
|
19
|
+
constructor({ id: t, lineWidth: o, points: s, stroke: e, zIndex: r, smoothCorners: n, smoothCornersRadius: i, hasCollisions: h }) {
|
20
|
+
super(t, s[0].x, s[0].y, "none", e, r, !1, h), this.points = s, this.lineWidth = o, this.smoothCorners = n, this.smoothCornersRadius = i;
|
21
|
+
}
|
22
|
+
get constructorName() {
|
23
|
+
return "LinePath";
|
24
|
+
}
|
25
|
+
}
|
26
|
+
export {
|
27
|
+
u as default
|
28
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { default as Position2D } from '../types/Position2D';
|
2
|
+
import { default as ColoredCanvasObject } from './ColoredCanvasObject';
|
3
|
+
export default class Polygon extends ColoredCanvasObject {
|
4
|
+
points: Position2D[];
|
5
|
+
/**
|
6
|
+
* Represents a Rectangle that will be created on the canvas.
|
7
|
+
*
|
8
|
+
* @param {string|number} id Identifier (used in click callback)
|
9
|
+
* @param {number} points Array of coordinates {x, y} of the polygon points
|
10
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
11
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
12
|
+
* @param {number} zIndex Stack order of the element
|
13
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
14
|
+
*/
|
15
|
+
constructor({ id, points, fill, stroke, zIndex, draggable, hasCollisions }: {
|
16
|
+
id: string;
|
17
|
+
points: Position2D[];
|
18
|
+
fill?: string;
|
19
|
+
stroke?: string;
|
20
|
+
zIndex?: number;
|
21
|
+
draggable?: boolean;
|
22
|
+
hasCollisions?: boolean;
|
23
|
+
});
|
24
|
+
get constructorName(): string;
|
25
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import c from "./ColoredCanvasObject.js";
|
2
|
+
class d extends c {
|
3
|
+
points;
|
4
|
+
/**
|
5
|
+
* Represents a Rectangle that will be created on the canvas.
|
6
|
+
*
|
7
|
+
* @param {string|number} id Identifier (used in click callback)
|
8
|
+
* @param {number} points Array of coordinates {x, y} of the polygon points
|
9
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
10
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
11
|
+
* @param {number} zIndex Stack order of the element
|
12
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
13
|
+
*/
|
14
|
+
constructor({ id: t, points: o, fill: r, stroke: e, zIndex: s, draggable: n, hasCollisions: a }) {
|
15
|
+
super(t, o[0].x, o[0].y, r, e, s, n, a), this.points = o;
|
16
|
+
}
|
17
|
+
get constructorName() {
|
18
|
+
return "Polygon";
|
19
|
+
}
|
20
|
+
}
|
21
|
+
export {
|
22
|
+
d as default
|
23
|
+
};
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { default as ColoredCanvasObject } from './ColoredCanvasObject';
|
2
|
+
export default class Rect extends ColoredCanvasObject {
|
3
|
+
width: number;
|
4
|
+
height: number;
|
5
|
+
rotation?: number;
|
6
|
+
/**
|
7
|
+
* Represents a Rectangle that will be created on the canvas.
|
8
|
+
*
|
9
|
+
* @param {string|number} id Identifier (used in click callback)
|
10
|
+
* @param {number} x Left coordinate of top-left corner of rectangle in canvas
|
11
|
+
* @param {number} y Top coordinate of top-left corner of rectangle in canvas
|
12
|
+
* @param {number} width Rectangle width in canvas
|
13
|
+
* @param {number} height Rectangle height in canvas
|
14
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
15
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
16
|
+
* @param {number} zIndex Stack order of the element
|
17
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
18
|
+
* @param {number} rotation The rotation in radians
|
19
|
+
*/
|
20
|
+
constructor({ id, x, y, width, height, fill, stroke, zIndex, draggable, hasCollisions, rotation }: {
|
21
|
+
id: string;
|
22
|
+
x: number;
|
23
|
+
y: number;
|
24
|
+
width: number;
|
25
|
+
height: number;
|
26
|
+
fill?: string;
|
27
|
+
stroke?: string;
|
28
|
+
zIndex?: number;
|
29
|
+
draggable?: boolean;
|
30
|
+
hasCollisions?: boolean;
|
31
|
+
rotation?: number;
|
32
|
+
});
|
33
|
+
get constructorName(): string;
|
34
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import u from "./ColoredCanvasObject.js";
|
2
|
+
class m extends u {
|
3
|
+
width;
|
4
|
+
height;
|
5
|
+
rotation;
|
6
|
+
/**
|
7
|
+
* Represents a Rectangle that will be created on the canvas.
|
8
|
+
*
|
9
|
+
* @param {string|number} id Identifier (used in click callback)
|
10
|
+
* @param {number} x Left coordinate of top-left corner of rectangle in canvas
|
11
|
+
* @param {number} y Top coordinate of top-left corner of rectangle in canvas
|
12
|
+
* @param {number} width Rectangle width in canvas
|
13
|
+
* @param {number} height Rectangle height in canvas
|
14
|
+
* @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
|
15
|
+
* @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
|
16
|
+
* @param {number} zIndex Stack order of the element
|
17
|
+
* @param {boolean} hasCollisions Does the object have collisions ?
|
18
|
+
* @param {number} rotation The rotation in radians
|
19
|
+
*/
|
20
|
+
constructor({ id: t, x: e, y: o, width: r, height: s, fill: i, stroke: h, zIndex: a, draggable: c, hasCollisions: n, rotation: d }) {
|
21
|
+
super(t, e, o, i, h, a, c, n), this.width = r, this.height = s, this.rotation = d;
|
22
|
+
}
|
23
|
+
get constructorName() {
|
24
|
+
return "Rect";
|
25
|
+
}
|
26
|
+
}
|
27
|
+
export {
|
28
|
+
m as default
|
29
|
+
};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { default as CanvasObject } from '../shapes/CanvasObject';
|
2
|
+
import { default as CollideElementResultItem } from './CollideElementResultItem';
|
3
|
+
import { default as Position2D } from './Position2D';
|
4
|
+
export type Canvas2DProps = {
|
5
|
+
width: number;
|
6
|
+
height: number;
|
7
|
+
trackMouseMove?: boolean;
|
8
|
+
minZoom?: number;
|
9
|
+
maxZoom?: number;
|
10
|
+
tileSize?: number;
|
11
|
+
onClick?: (collideRes: CollideElementResultItem) => void;
|
12
|
+
onRightClick?: (collideRes: CollideElementResultItem) => void;
|
13
|
+
onHover?: (collideRes: CollideElementResultItem | null, position?: Position2D) => void;
|
14
|
+
onElementMoved?: (collideRes: CollideElementResultItem, x: number, y: number) => void;
|
15
|
+
onWheel?: (e: Event) => void;
|
16
|
+
onFrame: () => CanvasObject[];
|
17
|
+
lockXAxis?: boolean;
|
18
|
+
lockYAxis?: boolean;
|
19
|
+
smoothingQuality?: ImageSmoothingQuality;
|
20
|
+
dragObjects?: boolean;
|
21
|
+
deltaLeft?: number;
|
22
|
+
deltaTop?: number;
|
23
|
+
id: string;
|
24
|
+
className?: string;
|
25
|
+
showMinimap?: boolean;
|
26
|
+
minimapWidth?: number;
|
27
|
+
minimapHeight?: number;
|
28
|
+
minimapFilter?: (e: CanvasObject) => boolean;
|
29
|
+
};
|
30
|
+
export default Canvas2DProps;
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
type Canvas2DState = {
|
2
|
+
boundingClientRect?: DOMRect;
|
3
|
+
canvas?: HTMLCanvasElement;
|
4
|
+
context?: CanvasRenderingContext2D;
|
5
|
+
minimapBoundingClientRect?: DOMRect;
|
6
|
+
minimapCanvas?: HTMLCanvasElement;
|
7
|
+
minimapContext?: CanvasRenderingContext2D;
|
8
|
+
left: number;
|
9
|
+
top: number;
|
10
|
+
width: number;
|
11
|
+
height: number;
|
12
|
+
zoom: number;
|
13
|
+
deltaTop: number;
|
14
|
+
deltaLeft: number;
|
15
|
+
prevX: number | null;
|
16
|
+
prevY: number | null;
|
17
|
+
};
|
18
|
+
export default Canvas2DState;
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { default as CanvasObject } from '../shapes/CanvasObject';
|
2
|
+
import { default as Position2D } from './Position2D';
|
3
|
+
type CollideElementResultItem = {
|
4
|
+
id: string | null;
|
5
|
+
element: CanvasObject | null;
|
6
|
+
originalEvent: Event;
|
7
|
+
posOnMap: Position2D;
|
8
|
+
};
|
9
|
+
export default CollideElementResultItem;
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|