canvas2d-wrapper 2.2.1 → 2.3.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.
Files changed (92) hide show
  1. package/dist/Canvas2D.js +122 -158
  2. package/dist/collisions/collideElement.js +64 -61
  3. package/dist/collisions/lineWithLine.js +9 -6
  4. package/dist/collisions/pointInCircle.js +5 -5
  5. package/dist/collisions/pointInPolygon.js +18 -20
  6. package/dist/collisions/pointInRectangle.js +10 -10
  7. package/dist/collisions/pointOnLinePath.js +23 -44
  8. package/dist/events/computeEventPositions.js +13 -6
  9. package/dist/events/elementClick.js +13 -17
  10. package/dist/events/elementRightClick.js +15 -12
  11. package/dist/events/mouseMove.js +23 -36
  12. package/dist/events/mouseWheel.js +10 -9
  13. package/dist/functions/calcRatioForMinimap.js +14 -14
  14. package/dist/functions/calcTileSize.js +5 -5
  15. package/dist/functions/preloadImages.js +5 -6
  16. package/dist/functions/sortElements.js +13 -17
  17. package/dist/generateTestData.js +46 -47
  18. package/dist/hooks/useGamepad.js +8 -12
  19. package/dist/hooks/useKeyboard.js +18 -18
  20. package/dist/hooks/useMousePosition.js +25 -24
  21. package/dist/hooks/useWindowDimensions.js +17 -17
  22. package/dist/{main.d.ts → lib/main.d.ts} +2 -1
  23. package/dist/lib/render/renderText.d.ts +2 -0
  24. package/dist/lib/shapes/Text.d.ts +38 -0
  25. package/dist/main.js +22 -42
  26. package/dist/maths/getLineLength.js +6 -6
  27. package/dist/maths/normalOnLine.js +9 -6
  28. package/dist/maths/segmentAngle.js +6 -6
  29. package/dist/render/renderCanvas.js +69 -33
  30. package/dist/render/renderCircle.js +5 -11
  31. package/dist/render/renderImage.js +7 -39
  32. package/dist/render/renderLinePath.js +24 -26
  33. package/dist/render/renderPolygon.js +7 -17
  34. package/dist/render/renderRect.js +6 -26
  35. package/dist/render/renderText.js +7 -0
  36. package/dist/shapes/CanvasImage.js +22 -37
  37. package/dist/shapes/CanvasObject.js +24 -26
  38. package/dist/shapes/Circle.js +12 -24
  39. package/dist/shapes/ColoredCanvasObject.js +13 -13
  40. package/dist/shapes/LinePath.js +15 -27
  41. package/dist/shapes/Polygon.js +12 -22
  42. package/dist/shapes/Rect.js +14 -28
  43. package/dist/shapes/Text.js +15 -0
  44. package/dist/types/Canvas2DProps.js +0 -1
  45. package/dist/types/Canvas2DState.js +0 -1
  46. package/dist/types/CollideElementResultItem.js +0 -1
  47. package/dist/types/Position2D.js +0 -1
  48. package/dist/types/Surface2D.js +0 -1
  49. package/package.json +20 -20
  50. /package/dist/{Canvas2D.d.ts → lib/Canvas2D.d.ts} +0 -0
  51. /package/dist/{Canvas2D.spec.d.ts → lib/Canvas2D.spec.d.ts} +0 -0
  52. /package/dist/{collisions → lib/collisions}/collideElement.d.ts +0 -0
  53. /package/dist/{collisions → lib/collisions}/lineWithLine.d.ts +0 -0
  54. /package/dist/{collisions → lib/collisions}/pointInCircle.d.ts +0 -0
  55. /package/dist/{collisions → lib/collisions}/pointInPolygon.d.ts +0 -0
  56. /package/dist/{collisions → lib/collisions}/pointInRectangle.d.ts +0 -0
  57. /package/dist/{collisions → lib/collisions}/pointOnLinePath.d.ts +0 -0
  58. /package/dist/{events → lib/events}/computeEventPositions.d.ts +0 -0
  59. /package/dist/{events → lib/events}/elementClick.d.ts +0 -0
  60. /package/dist/{events → lib/events}/elementRightClick.d.ts +0 -0
  61. /package/dist/{events → lib/events}/mouseMove.d.ts +0 -0
  62. /package/dist/{events → lib/events}/mouseWheel.d.ts +0 -0
  63. /package/dist/{functions → lib/functions}/calcRatioForMinimap.d.ts +0 -0
  64. /package/dist/{functions → lib/functions}/calcTileSize.d.ts +0 -0
  65. /package/dist/{functions → lib/functions}/preloadImages.d.ts +0 -0
  66. /package/dist/{functions → lib/functions}/sortElements.d.ts +0 -0
  67. /package/dist/{generateTestData.d.ts → lib/generateTestData.d.ts} +0 -0
  68. /package/dist/{hooks → lib/hooks}/useGamepad.d.ts +0 -0
  69. /package/dist/{hooks → lib/hooks}/useKeyboard.d.ts +0 -0
  70. /package/dist/{hooks → lib/hooks}/useMousePosition.d.ts +0 -0
  71. /package/dist/{hooks → lib/hooks}/useWindowDimensions.d.ts +0 -0
  72. /package/dist/{maths → lib/maths}/getLineLength.d.ts +0 -0
  73. /package/dist/{maths → lib/maths}/normalOnLine.d.ts +0 -0
  74. /package/dist/{maths → lib/maths}/segmentAngle.d.ts +0 -0
  75. /package/dist/{render → lib/render}/renderCanvas.d.ts +0 -0
  76. /package/dist/{render → lib/render}/renderCircle.d.ts +0 -0
  77. /package/dist/{render → lib/render}/renderImage.d.ts +0 -0
  78. /package/dist/{render → lib/render}/renderLinePath.d.ts +0 -0
  79. /package/dist/{render → lib/render}/renderPolygon.d.ts +0 -0
  80. /package/dist/{render → lib/render}/renderRect.d.ts +0 -0
  81. /package/dist/{shapes → lib/shapes}/CanvasImage.d.ts +0 -0
  82. /package/dist/{shapes → lib/shapes}/CanvasObject.d.ts +0 -0
  83. /package/dist/{shapes → lib/shapes}/Circle.d.ts +0 -0
  84. /package/dist/{shapes → lib/shapes}/ColoredCanvasObject.d.ts +0 -0
  85. /package/dist/{shapes → lib/shapes}/LinePath.d.ts +0 -0
  86. /package/dist/{shapes → lib/shapes}/Polygon.d.ts +0 -0
  87. /package/dist/{shapes → lib/shapes}/Rect.d.ts +0 -0
  88. /package/dist/{types → lib/types}/Canvas2DProps.d.ts +0 -0
  89. /package/dist/{types → lib/types}/Canvas2DState.d.ts +0 -0
  90. /package/dist/{types → lib/types}/CollideElementResultItem.d.ts +0 -0
  91. /package/dist/{types → lib/types}/Position2D.d.ts +0 -0
  92. /package/dist/{types → lib/types}/Surface2D.d.ts +0 -0
@@ -1,13 +1,16 @@
1
- import p from "../collisions/collideElement.js";
2
- function c(l, r, n, o) {
3
- const t = -o.left - o.deltaLeft + l.pageX - l.target.offsetLeft, e = -o.top - o.deltaTop + l.pageY - l.target.offsetTop, f = p(l, r, t, e, n, o.zoom);
4
- return f !== null ? f : {
5
- id: null,
6
- element: null,
7
- originalEvent: l,
8
- posOnMap: { x: Math.floor(t / n / o.zoom), y: Math.floor(e / n / o.zoom) }
9
- };
1
+ import e from "../collisions/collideElement.js";
2
+ //#region lib/events/elementRightClick.ts
3
+ function t(t, n, r, i) {
4
+ let a = -i.left - i.deltaLeft + t.pageX - t.target.offsetLeft, o = -i.top - i.deltaTop + t.pageY - t.target.offsetTop, s = e(t, n, a, o, r, i.zoom);
5
+ return s === null ? {
6
+ id: null,
7
+ element: null,
8
+ originalEvent: t,
9
+ posOnMap: {
10
+ x: Math.floor(a / r / i.zoom),
11
+ y: Math.floor(o / r / i.zoom)
12
+ }
13
+ } : s;
10
14
  }
11
- export {
12
- c as default
13
- };
15
+ //#endregion
16
+ export { t as default };
@@ -1,37 +1,24 @@
1
- import X from "../collisions/collideElement.js";
2
- import b from "./computeEventPositions.js";
3
- const g = 1;
4
- let l = null;
5
- const s = 300;
6
- function O(t, c, f, e, u, T, Y, r, m, n) {
7
- const i = {
8
- ...e
9
- }, {
10
- left: a,
11
- top: o,
12
- posOnMap: d
13
- } = b(e, t, f);
14
- if (t.nativeEvent.buttons === g && e.prevX) {
15
- let E = !1;
16
- r && (l === null && (l = X(t.nativeEvent, c, a, o, f, e.zoom)), l !== null && l.element.draggable && (l.element.x = -e.left - e.deltaLeft + (t.clientX - e.boundingClientRect.left) - (l.element.width ?? 0) / 2, l.element.y = -e.top - e.deltaLeft + (t.clientY - e.boundingClientRect.top) - (l.element.height ?? 0) / 2, E = !0, m && m(
17
- l,
18
- t.screenX - e.prevX,
19
- t.screenY - e.prevY
20
- ), n && n(null, d))), E || (T || (i.left += t.screenX - e.prevX), Y || (i.top += t.screenY - e.prevY)), t.nativeEvent.pointerType !== "mouse" && setTimeout(() => {
21
- l = null, u({
22
- ...i,
23
- prevX: null,
24
- prevY: null
25
- });
26
- }, s);
27
- } else
28
- n && n(X(t.nativeEvent, c, a, o, f, e.zoom), d), l = null;
29
- u({
30
- ...i,
31
- prevX: t.screenX,
32
- prevY: t.screenY
33
- });
1
+ import e from "../collisions/collideElement.js";
2
+ import t from "./computeEventPositions.js";
3
+ //#region lib/events/mouseMove.ts
4
+ var n = 1, r = null, i = 300;
5
+ function a(a, o, s, c, l, u, d, f, p, m) {
6
+ let h = { ...c }, { left: g, top: _, posOnMap: v } = t(c, a, s);
7
+ if (a.nativeEvent.buttons === n && c.prevX) {
8
+ let t = !1;
9
+ f && (r === null && (r = e(a.nativeEvent, o, g, _, s, c.zoom)), r !== null && r.element.draggable && (r.element.x = -c.left - c.deltaLeft + (a.clientX - c.boundingClientRect.left) - (r.element.width ?? 0) / 2, r.element.y = -c.top - c.deltaLeft + (a.clientY - c.boundingClientRect.top) - (r.element.height ?? 0) / 2, t = !0, p && p(r, a.screenX - c.prevX, a.screenY - c.prevY), m && m(null, v))), t || (u || (h.left += a.screenX - c.prevX), d || (h.top += a.screenY - c.prevY)), a.nativeEvent.pointerType !== "mouse" && setTimeout(() => {
10
+ r = null, l({
11
+ ...h,
12
+ prevX: null,
13
+ prevY: null
14
+ });
15
+ }, i);
16
+ } else m && m(e(a.nativeEvent, o, g, _, s, c.zoom), v), r = null;
17
+ l({
18
+ ...h,
19
+ prevX: a.screenX,
20
+ prevY: a.screenY
21
+ });
34
22
  }
35
- export {
36
- O as default
37
- };
23
+ //#endregion
24
+ export { a as default };
@@ -1,10 +1,11 @@
1
- function l(t, E, o, a, L) {
2
- let e = E.zoom;
3
- t.deltaY < 0 ? e += 0.05 : e -= 0.05, e = Math.max(e, a), e = Math.min(e, L), o({
4
- ...E,
5
- zoom: e
6
- });
1
+ //#region lib/events/mouseWheel.ts
2
+ var e = .05;
3
+ function t(t, n, r, i, a) {
4
+ let o = n.zoom;
5
+ t.deltaY < 0 ? o += e : o -= e, o = Math.max(o, i), o = Math.min(o, a), r({
6
+ ...n,
7
+ zoom: o
8
+ });
7
9
  }
8
- export {
9
- l as default
10
- };
10
+ //#endregion
11
+ export { t as default };
@@ -1,15 +1,15 @@
1
- function h(m, r, o, p, x, n) {
2
- const c = m.map((a) => {
3
- const t = a;
4
- return Array.isArray(t.points) ? t.points.map((s) => s.x * n) : [a.x * n];
5
- }).flat(), M = Math.min(...c), u = Math.max(...c);
6
- r = Math.max(2 * u, -2 * M, r);
7
- const i = m.map((a) => {
8
- const t = a;
9
- return Array.isArray(t.points) ? t.points.map((s) => s.y * n) : [a.y * n];
10
- }).flat(), f = Math.min(...i), y = Math.max(...i);
11
- return o = Math.max(2 * y, -2 * f, o), Math.max(r / p, o / x);
1
+ //#region lib/functions/calcRatioForMinimap.ts
2
+ function e(e, t, n, r, i, a) {
3
+ let o = e.map((e) => {
4
+ let t = e;
5
+ return Array.isArray(t.points) ? t.points.map((e) => e.x * a) : [e.x * a];
6
+ }).flat(), s = Math.min(...o), c = Math.max(...o);
7
+ t = Math.max(2 * c, -2 * s, t);
8
+ let l = e.map((e) => {
9
+ let t = e;
10
+ return Array.isArray(t.points) ? t.points.map((e) => e.y * a) : [e.y * a];
11
+ }).flat(), u = Math.min(...l), d = Math.max(...l);
12
+ return n = Math.max(2 * d, -2 * u, n), Math.max(t / r, n / i);
12
13
  }
13
- export {
14
- h as default
15
- };
14
+ //#endregion
15
+ export { e as default };
@@ -1,6 +1,6 @@
1
- function a(e, t) {
2
- return e * t;
1
+ //#region lib/functions/calcTileSize.ts
2
+ function e(e, t) {
3
+ return e * t;
3
4
  }
4
- export {
5
- a as default
6
- };
5
+ //#endregion
6
+ export { e as default };
@@ -1,7 +1,6 @@
1
- function r(e) {
2
- for (const a of e)
3
- __canvas2dWrapper__.imgCache[a] = new Image(), __canvas2dWrapper__.imgCache[a].src = a;
1
+ //#region lib/functions/preloadImages.ts
2
+ function e(e) {
3
+ for (let t of e) __canvas2dWrapper__.imgCache[t] = new Image(), __canvas2dWrapper__.imgCache[t].src = t;
4
4
  }
5
- export {
6
- r as default
7
- };
5
+ //#endregion
6
+ export { e as default };
@@ -1,18 +1,14 @@
1
- function f(t) {
2
- return t.sort((r, e) => {
3
- if (r.zIndex !== e.zIndex)
4
- return r.zIndex - e.zIndex;
5
- if (r.fill === e.fill && r.stroke && e.stroke)
6
- return r.stroke === e.stroke ? 0 : r.stroke < e.stroke ? 1 : -1;
7
- if (r.fill && e.fill) {
8
- if (r.fill < e.fill)
9
- return 1;
10
- if (r.fill > e.fill)
11
- return -1;
12
- }
13
- return 0;
14
- }), t;
1
+ //#region lib/functions/sortElements.ts
2
+ function e(e) {
3
+ return e.sort((e, t) => {
4
+ if (e.zIndex !== t.zIndex) return e.zIndex - t.zIndex;
5
+ if (e.fill === t.fill && e.stroke && t.stroke) return e.stroke === t.stroke ? 0 : e.stroke < t.stroke ? 1 : -1;
6
+ if (e.fill && t.fill) {
7
+ if (e.fill < t.fill) return 1;
8
+ if (e.fill > t.fill) return -1;
9
+ }
10
+ return 0;
11
+ }), e;
15
12
  }
16
- export {
17
- f as default
18
- };
13
+ //#endregion
14
+ export { e as default };
@@ -1,48 +1,47 @@
1
- import l from "./shapes/Circle.js";
2
- import e from "./shapes/Polygon.js";
3
- import i from "./shapes/Rect.js";
4
- function M() {
5
- const r = [];
6
- for (let o = 0; o < 998; o++) {
7
- let t = null;
8
- Math.random() > 0.5 ? t = new i({
9
- id: o.toString(),
10
- x: 500 - Math.round(Math.random() * 1e3),
11
- y: 500 - Math.round(Math.random() * 1e3),
12
- width: 32,
13
- height: 32,
14
- fill: Math.random() > 0.5 ? "black" : void 0,
15
- stroke: Math.random() > 0.5 ? "black" : void 0,
16
- draggable: !0
17
- }) : t = new l({
18
- id: o.toString(),
19
- x: 500 - Math.round(Math.random() * 1e3),
20
- y: 500 - Math.round(Math.random() * 1e3),
21
- radius: 16,
22
- fill: Math.random() > 0.5 ? "black" : void 0,
23
- stroke: Math.random() > 0.5 ? "black" : void 0
24
- }), !t.fill && !t.stroke && (t.fill = "green"), r.push(t);
25
- }
26
- const a = [];
27
- for (let o = 0; o < 5; o++)
28
- a.push({
29
- x: 500 - Math.round(Math.random() * 1e3),
30
- y: 500 - Math.round(Math.random() * 1e3)
31
- });
32
- const n = new e({
33
- id: "poly",
34
- points: a,
35
- stroke: "red"
36
- });
37
- r.push(n);
38
- const d = new e({
39
- id: "poly",
40
- points: a,
41
- fill: "orange",
42
- zIndex: -1
43
- });
44
- return r.push(d), r;
1
+ import e from "./shapes/Circle.js";
2
+ import t from "./shapes/Polygon.js";
3
+ import n from "./shapes/Rect.js";
4
+ //#region lib/generateTestData.ts
5
+ function r() {
6
+ let r = [];
7
+ for (let t = 0; t < 998; t++) {
8
+ let i = null;
9
+ i = Math.random() > .5 ? new n({
10
+ id: t.toString(),
11
+ x: 500 - Math.round(Math.random() * 1e3),
12
+ y: 500 - Math.round(Math.random() * 1e3),
13
+ width: 32,
14
+ height: 32,
15
+ fill: Math.random() > .5 ? "black" : void 0,
16
+ stroke: Math.random() > .5 ? "black" : void 0,
17
+ draggable: !0
18
+ }) : new e({
19
+ id: t.toString(),
20
+ x: 500 - Math.round(Math.random() * 1e3),
21
+ y: 500 - Math.round(Math.random() * 1e3),
22
+ radius: 16,
23
+ fill: Math.random() > .5 ? "black" : void 0,
24
+ stroke: Math.random() > .5 ? "black" : void 0
25
+ }), !i.fill && !i.stroke && (i.fill = "green"), r.push(i);
26
+ }
27
+ let i = [];
28
+ for (let e = 0; e < 5; e++) i.push({
29
+ x: 500 - Math.round(Math.random() * 1e3),
30
+ y: 500 - Math.round(Math.random() * 1e3)
31
+ });
32
+ let a = new t({
33
+ id: "poly",
34
+ points: i,
35
+ stroke: "red"
36
+ });
37
+ r.push(a);
38
+ let o = new t({
39
+ id: "poly",
40
+ points: i,
41
+ fill: "orange",
42
+ zIndex: -1
43
+ });
44
+ return r.push(o), r;
45
45
  }
46
- export {
47
- M as default
48
- };
46
+ //#endregion
47
+ export { r as default };
@@ -1,13 +1,9 @@
1
- import { useState as r, useEffect as n } from "react";
2
- let e;
3
- const l = 15;
4
- function u() {
5
- const [t, a] = r(null);
6
- return n(() => (clearInterval(e), e = setInterval(
7
- () => a(navigator.getGamepads()[0]),
8
- l
9
- ), () => clearInterval(e)), []), t;
1
+ import { useEffect as e, useState as t } from "react";
2
+ //#region lib/hooks/useGamepad.ts
3
+ var n, r = 15;
4
+ function i() {
5
+ let [i, a] = t(null);
6
+ return e(() => (clearInterval(n), n = setInterval(() => a(navigator.getGamepads()[0]), r), () => clearInterval(n)), []), i;
10
7
  }
11
- export {
12
- u as default
13
- };
8
+ //#endregion
9
+ export { i as default };
@@ -1,19 +1,19 @@
1
- import { useState as s, useEffect as d } from "react";
2
- function y() {
3
- const [e, n] = s({});
4
- return d(() => {
5
- const r = (t) => {
6
- e[t.key] = !0, n(JSON.parse(JSON.stringify(e)));
7
- };
8
- document.addEventListener("keydown", r);
9
- const o = (t) => {
10
- e[t.key] = !1, n(JSON.parse(JSON.stringify(e)));
11
- };
12
- return document.addEventListener("keyup", o), () => {
13
- document.removeEventListener("keydown", r), document.removeEventListener("keyup", o);
14
- };
15
- }, []), e;
1
+ import { useEffect as e, useState as t } from "react";
2
+ //#region lib/hooks/useKeyboard.ts
3
+ function n() {
4
+ let [n, r] = t({});
5
+ return e(() => {
6
+ let e = (e) => {
7
+ n[e.key] = !0, r(JSON.parse(JSON.stringify(n)));
8
+ };
9
+ document.addEventListener("keydown", e);
10
+ let t = (e) => {
11
+ n[e.key] = !1, r(JSON.parse(JSON.stringify(n)));
12
+ };
13
+ return document.addEventListener("keyup", t), () => {
14
+ document.removeEventListener("keydown", e), document.removeEventListener("keyup", t);
15
+ };
16
+ }, []), n;
16
17
  }
17
- export {
18
- y as default
19
- };
18
+ //#endregion
19
+ export { n as default };
@@ -1,25 +1,26 @@
1
- import { useState as m, useEffect as v } from "react";
2
- function d(o = !0) {
3
- const [
4
- u,
5
- r
6
- ] = m({ x: null, y: null });
7
- return v(() => {
8
- const e = (c) => {
9
- const t = c;
10
- let n, s;
11
- if (t.touches) {
12
- const i = t.touches[0];
13
- [n, s] = [i.clientX, i.clientY];
14
- } else
15
- [n, s] = [t.clientX, t.clientY];
16
- r({ x: n, y: s });
17
- };
18
- return window.addEventListener("mousemove", e), o && window.addEventListener("touchmove", e), () => {
19
- window.removeEventListener("mousemove", e), o && window.removeEventListener("touchmove", e);
20
- };
21
- }, [o]), u;
1
+ import { useEffect as e, useState as t } from "react";
2
+ //#region lib/hooks/useMousePosition.ts
3
+ function n(n = !0) {
4
+ let [r, i] = t({
5
+ x: null,
6
+ y: null
7
+ });
8
+ return e(() => {
9
+ let e = (e) => {
10
+ let t = e, n, r;
11
+ if (t.touches) {
12
+ let e = t.touches[0];
13
+ [n, r] = [e.clientX, e.clientY];
14
+ } else [n, r] = [t.clientX, t.clientY];
15
+ i({
16
+ x: n,
17
+ y: r
18
+ });
19
+ };
20
+ return window.addEventListener("mousemove", e), n && window.addEventListener("touchmove", e), () => {
21
+ window.removeEventListener("mousemove", e), n && window.removeEventListener("touchmove", e);
22
+ };
23
+ }, [n]), r;
22
24
  }
23
- export {
24
- d as default
25
- };
25
+ //#endregion
26
+ export { n as default };
@@ -1,20 +1,20 @@
1
- import { useState as o, useEffect as s } from "react";
2
- function t() {
3
- const { clientWidth: e, clientHeight: n } = document.documentElement;
4
- return {
5
- width: e,
6
- height: n
7
- };
1
+ import { useEffect as e, useState as t } from "react";
2
+ //#region lib/hooks/useWindowDimensions.ts
3
+ function n() {
4
+ let { clientWidth: e, clientHeight: t } = document.documentElement;
5
+ return {
6
+ width: e,
7
+ height: t
8
+ };
8
9
  }
9
10
  function r() {
10
- const [e, n] = o(t());
11
- return s(() => {
12
- function i() {
13
- n(t());
14
- }
15
- return window.addEventListener("resize", i), () => window.removeEventListener("resize", i);
16
- }, []), e;
11
+ let [r, i] = t(n());
12
+ return e(() => {
13
+ function e() {
14
+ i(n());
15
+ }
16
+ return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
17
+ }, []), r;
17
18
  }
18
- export {
19
- r as default
20
- };
19
+ //#endregion
20
+ export { r as default };
@@ -18,6 +18,7 @@ import { default as Circle } from './shapes/Circle';
18
18
  import { default as LinePath } from './shapes/LinePath';
19
19
  import { default as Polygon } from './shapes/Polygon';
20
20
  import { default as Rect } from './shapes/Rect';
21
+ import { default as Text } from './shapes/Text';
21
22
  import { default as Canvas2DProps } from './types/Canvas2DProps';
22
23
  import { default as CollideElementResultItem } from './types/CollideElementResultItem';
23
24
  import { default as Position2D } from './types/Position2D';
@@ -30,7 +31,7 @@ declare global {
30
31
  };
31
32
  }
32
33
  export { Canvas2D };
33
- export { CanvasImage, CanvasObject, Circle, LinePath, Polygon, Rect };
34
+ export { CanvasImage, CanvasObject, Circle, LinePath, Polygon, Rect, Text };
34
35
  export { lineWithLine, pointInCircle, pointInPolygon, pointInRectangle, pointOnLinePath };
35
36
  export { preloadImages };
36
37
  export { useGamepad, useKeyboard, useMousePosition, useWindowDimensions };
@@ -0,0 +1,2 @@
1
+ import { default as Text } from '../shapes/Text';
2
+ export default function renderText(context: CanvasRenderingContext2D, element: Text, left: number, top: number, localTileSize: number): void;
@@ -0,0 +1,38 @@
1
+ import { default as ColoredCanvasObject } from './ColoredCanvasObject';
2
+ export default class Text extends ColoredCanvasObject {
3
+ text: string;
4
+ maxWidth?: number;
5
+ font?: string;
6
+ /**
7
+ * Represents an Image that will be created on the canvas.
8
+ * Note: a cache to prevent too much loading is implemented, you can create as much
9
+ * images as you want of the same source without any performance issue.
10
+ *
11
+ * @param {string|number} id Identifier (used in click callback)
12
+ * @param {number} x Left coordinate of top-left corner of picture in canvas
13
+ * @param {number} y Top coordinate of top-left corner of picture in canvas
14
+ * @param {number} text Text to show
15
+ * @param {number} maxWidth Maximum width of this text
16
+ * @param {number} font Text font
17
+ * @param {string} fill DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.fillStyle
18
+ * @param {string} stroke DOMString, CanvasGradient or CanvsPattern representing what should be put in CanvasRenderingContext2D.strokeStyle
19
+ * @param {number} zIndex Stack order of the element
20
+ * @param {boolean} hasCollisions Does the object have collisions ?
21
+ * @param {number} rotation The rotation in radians
22
+ */
23
+ constructor({ id, x, y, text, maxWidth, font, fill, stroke, zIndex, draggable, hasCollisions }: {
24
+ id: string;
25
+ x: number;
26
+ y: number;
27
+ text: string;
28
+ maxWidth?: number;
29
+ font?: string;
30
+ fill?: string;
31
+ stroke?: string;
32
+ zIndex?: number;
33
+ draggable?: boolean;
34
+ hasCollisions?: boolean;
35
+ rotation?: number;
36
+ });
37
+ get constructorName(): string;
38
+ }
package/dist/main.js CHANGED
@@ -1,42 +1,22 @@
1
- import { default as o } from "./Canvas2D.js";
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";
21
- export {
22
- o as Canvas2D,
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
42
- };
1
+ import e from "./collisions/pointInCircle.js";
2
+ import t from "./collisions/pointInPolygon.js";
3
+ import n from "./collisions/pointInRectangle.js";
4
+ import r from "./collisions/pointOnLinePath.js";
5
+ import i from "./shapes/CanvasObject.js";
6
+ import a from "./shapes/CanvasImage.js";
7
+ import o from "./shapes/Circle.js";
8
+ import s from "./shapes/LinePath.js";
9
+ import c from "./shapes/Polygon.js";
10
+ import l from "./shapes/Rect.js";
11
+ import u from "./shapes/Text.js";
12
+ import d from "./Canvas2D.js";
13
+ import f from "./collisions/lineWithLine.js";
14
+ import p from "./functions/preloadImages.js";
15
+ import m from "./hooks/useGamepad.js";
16
+ import h from "./hooks/useKeyboard.js";
17
+ import g from "./hooks/useMousePosition.js";
18
+ import _ from "./hooks/useWindowDimensions.js";
19
+ import v from "./maths/getLineLength.js";
20
+ import y from "./maths/normalOnLine.js";
21
+ import b from "./maths/segmentAngle.js";
22
+ export { d as Canvas2D, a as CanvasImage, i as CanvasObject, o as Circle, s as LinePath, c as Polygon, l as Rect, u as Text, v as getLineLength, f as lineWithLine, y as normalOnLine, e as pointInCircle, t as pointInPolygon, n as pointInRectangle, r as pointOnLinePath, p as preloadImages, b as segmentAngle, m as useGamepad, h as useKeyboard, g as useMousePosition, _ as useWindowDimensions };
@@ -1,7 +1,7 @@
1
- function i(t, n) {
2
- const e = n.x - t.x, f = n.y - t.y;
3
- return Math.sqrt(e * e + f * f);
1
+ //#region lib/maths/getLineLength.ts
2
+ function e(e, t) {
3
+ let n = t.x - e.x, r = t.y - e.y;
4
+ return Math.sqrt(n * n + r * r);
4
5
  }
5
- export {
6
- i as default
7
- };
6
+ //#endregion
7
+ export { e as default };
@@ -1,7 +1,10 @@
1
- function f(n, t, o = !1) {
2
- const s = t.x - n.x, x = t.y - n.y, y = Math.hypot(s, x), c = s / y, u = x / y, a = o ? u : -u, d = o ? -c : c;
3
- return { x: a, y: d };
1
+ //#region lib/maths/normalOnLine.ts
2
+ function e(e, t, n = !1) {
3
+ let r = t.x - e.x, i = t.y - e.y, a = Math.hypot(r, i), o = r / a, s = i / a;
4
+ return {
5
+ x: n ? s : -s,
6
+ y: n ? -o : o
7
+ };
4
8
  }
5
- export {
6
- f as default
7
- };
9
+ //#endregion
10
+ export { e as default };
@@ -1,7 +1,7 @@
1
- function r(t, n) {
2
- const e = n.x - t.x, a = n.y - t.y;
3
- return e === 0 && a === 0 ? 0 : Math.atan2(a, e) + Math.PI / 2;
1
+ //#region lib/maths/segmentAngle.ts
2
+ function e(e, t) {
3
+ let n = t.x - e.x, r = t.y - e.y;
4
+ return n === 0 && r === 0 ? 0 : Math.atan2(r, n) + Math.PI / 2;
4
5
  }
5
- export {
6
- r as default
7
- };
6
+ //#endregion
7
+ export { e as default };