@tsparticles/interaction-external-cannon 4.0.5 → 4.1.1
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/browser/Cannoner.js +24 -24
- package/browser/Options/Classes/Cannon.js +4 -1
- package/browser/index.js +1 -1
- package/browser/index.lazy.js +1 -1
- package/cjs/Cannoner.js +24 -24
- package/cjs/Options/Classes/Cannon.js +4 -1
- package/cjs/index.js +1 -1
- package/cjs/index.lazy.js +1 -1
- package/esm/Cannoner.js +24 -24
- package/esm/Options/Classes/Cannon.js +4 -1
- package/esm/index.js +1 -1
- package/esm/index.lazy.js +1 -1
- package/package.json +3 -3
- package/report.html +1 -1
- package/tsparticles.interaction.external.cannon.js +30 -27
- package/tsparticles.interaction.external.cannon.min.js +1 -1
- package/types/Cannoner.d.ts +1 -6
- package/types/index.d.ts +1 -1
- package/types/index.lazy.d.ts +1 -1
package/browser/Cannoner.js
CHANGED
|
@@ -13,14 +13,14 @@ function angleRad(x0, y0, x1, y1) {
|
|
|
13
13
|
}
|
|
14
14
|
export class Cannoner extends ExternalInteractorBase {
|
|
15
15
|
maxDistance = 0;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
#data;
|
|
17
|
+
#gesture = {
|
|
18
18
|
origin: Vector.origin,
|
|
19
19
|
current: Vector.origin,
|
|
20
20
|
active: false,
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
#lastDownPosition = undefined;
|
|
23
|
+
#state = CannonState.idle;
|
|
24
24
|
constructor(container) {
|
|
25
25
|
super(container);
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
28
28
|
}
|
|
29
29
|
init() {
|
|
30
30
|
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
31
|
-
this
|
|
31
|
+
this.#data = {
|
|
32
32
|
spread: degToRad(options.spread),
|
|
33
33
|
maxDragDistance: options.maxDragDistance,
|
|
34
34
|
velocityFactor: options.velocityFactor,
|
|
@@ -41,27 +41,27 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
41
41
|
}
|
|
42
42
|
interact(interactivityData, _delta) {
|
|
43
43
|
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
44
|
-
if (clicking && downPos && downPos !== this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
44
|
+
if (clicking && downPos && downPos !== this.#lastDownPosition && this.#state === CannonState.idle) {
|
|
45
|
+
this.#lastDownPosition = downPos;
|
|
46
|
+
this.#gesture = {
|
|
47
47
|
origin: { x: downPos.x, y: downPos.y },
|
|
48
48
|
current: { x: downPos.x, y: downPos.y },
|
|
49
49
|
active: true,
|
|
50
50
|
};
|
|
51
|
-
this
|
|
51
|
+
this.#state = CannonState.aiming;
|
|
52
52
|
}
|
|
53
|
-
if (this
|
|
54
|
-
this.
|
|
55
|
-
this
|
|
53
|
+
if (this.#state === CannonState.aiming && mousePos) {
|
|
54
|
+
this.#gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
55
|
+
this.#drawVector();
|
|
56
56
|
}
|
|
57
|
-
if (!clicking && this
|
|
58
|
-
this.
|
|
59
|
-
this
|
|
60
|
-
this
|
|
57
|
+
if (!clicking && this.#state === CannonState.aiming) {
|
|
58
|
+
this.#gesture.active = false;
|
|
59
|
+
this.#fire();
|
|
60
|
+
this.#state = CannonState.idle;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
isEnabled(interactivityData) {
|
|
64
|
-
const
|
|
64
|
+
const container = this.container, events = container.actualOptions.interactivity?.events;
|
|
65
65
|
if (!events?.onClick.enable) {
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
@@ -69,7 +69,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
69
69
|
if (!modeEnabled) {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
return this
|
|
72
|
+
return this.#state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
73
73
|
}
|
|
74
74
|
loadModeOptions(options, ...sources) {
|
|
75
75
|
options.cannon ??= new Cannon();
|
|
@@ -79,13 +79,13 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
79
79
|
}
|
|
80
80
|
reset(_interactivityData, _particle) {
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
#drawVector() {
|
|
83
83
|
this.container.canvas.render.draw(ctx => {
|
|
84
|
-
const opts = this
|
|
84
|
+
const opts = this.#data;
|
|
85
85
|
if (!opts) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
const { origin, current } = this
|
|
88
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dragDist = getDistance(origin, current), clampedDist = opts.maxDragDistance > none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : dragDist, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
89
89
|
ctx.save();
|
|
90
90
|
ctx.strokeStyle = opts.vectorColor;
|
|
91
91
|
ctx.lineWidth = double * pxRatio;
|
|
@@ -102,12 +102,12 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
102
102
|
ctx.restore();
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
const opts = this
|
|
105
|
+
#fire() {
|
|
106
|
+
const opts = this.#data;
|
|
107
107
|
if (!opts) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const { origin, current } = this
|
|
110
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dist = getDistance(origin, current), dragLength = opts.maxDragDistance > none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
111
111
|
if (dragLength < minTapsLength) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -11,7 +11,7 @@ export class Cannon {
|
|
|
11
11
|
this.spread = 30;
|
|
12
12
|
this.velocityFactor = 0.5;
|
|
13
13
|
this.particleFactor = 0.2;
|
|
14
|
-
this.maxDragDistance =
|
|
14
|
+
this.maxDragDistance = 0;
|
|
15
15
|
this.minParticles = 5;
|
|
16
16
|
this.maxParticles = 200;
|
|
17
17
|
this.drawVector = true;
|
|
@@ -36,6 +36,9 @@ export class Cannon {
|
|
|
36
36
|
if (data.maxParticles !== undefined) {
|
|
37
37
|
this.maxParticles = data.maxParticles;
|
|
38
38
|
}
|
|
39
|
+
if (data.maxDragDistance !== undefined) {
|
|
40
|
+
this.maxDragDistance = data.maxDragDistance;
|
|
41
|
+
}
|
|
39
42
|
if (data.drawVector !== undefined) {
|
|
40
43
|
this.drawVector = data.drawVector;
|
|
41
44
|
}
|
package/browser/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureInteractivityPluginLoaded } from "@tsparticles/plugin-interactivi
|
|
|
2
2
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
3
3
|
import { Cannoner } from "./Cannoner.js";
|
|
4
4
|
export async function loadExternalCannonInteraction(engine) {
|
|
5
|
-
engine.checkVersion("4.
|
|
5
|
+
engine.checkVersion("4.1.1");
|
|
6
6
|
await engine.pluginManager.register((e) => {
|
|
7
7
|
ensureInteractivityPluginLoaded(e);
|
|
8
8
|
e.pluginManager.addInteractor?.("externalCannon", container => {
|
package/browser/index.lazy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
2
2
|
export async function loadExternalCannonInteraction(engine) {
|
|
3
|
-
engine.checkVersion("4.
|
|
3
|
+
engine.checkVersion("4.1.1");
|
|
4
4
|
await engine.pluginManager.register(async (e) => {
|
|
5
5
|
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity/lazy");
|
|
6
6
|
ensureInteractivityPluginLoaded(e);
|
package/cjs/Cannoner.js
CHANGED
|
@@ -13,14 +13,14 @@ function angleRad(x0, y0, x1, y1) {
|
|
|
13
13
|
}
|
|
14
14
|
export class Cannoner extends ExternalInteractorBase {
|
|
15
15
|
maxDistance = 0;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
#data;
|
|
17
|
+
#gesture = {
|
|
18
18
|
origin: Vector.origin,
|
|
19
19
|
current: Vector.origin,
|
|
20
20
|
active: false,
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
#lastDownPosition = undefined;
|
|
23
|
+
#state = CannonState.idle;
|
|
24
24
|
constructor(container) {
|
|
25
25
|
super(container);
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
28
28
|
}
|
|
29
29
|
init() {
|
|
30
30
|
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
31
|
-
this
|
|
31
|
+
this.#data = {
|
|
32
32
|
spread: degToRad(options.spread),
|
|
33
33
|
maxDragDistance: options.maxDragDistance,
|
|
34
34
|
velocityFactor: options.velocityFactor,
|
|
@@ -41,27 +41,27 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
41
41
|
}
|
|
42
42
|
interact(interactivityData, _delta) {
|
|
43
43
|
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
44
|
-
if (clicking && downPos && downPos !== this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
44
|
+
if (clicking && downPos && downPos !== this.#lastDownPosition && this.#state === CannonState.idle) {
|
|
45
|
+
this.#lastDownPosition = downPos;
|
|
46
|
+
this.#gesture = {
|
|
47
47
|
origin: { x: downPos.x, y: downPos.y },
|
|
48
48
|
current: { x: downPos.x, y: downPos.y },
|
|
49
49
|
active: true,
|
|
50
50
|
};
|
|
51
|
-
this
|
|
51
|
+
this.#state = CannonState.aiming;
|
|
52
52
|
}
|
|
53
|
-
if (this
|
|
54
|
-
this.
|
|
55
|
-
this
|
|
53
|
+
if (this.#state === CannonState.aiming && mousePos) {
|
|
54
|
+
this.#gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
55
|
+
this.#drawVector();
|
|
56
56
|
}
|
|
57
|
-
if (!clicking && this
|
|
58
|
-
this.
|
|
59
|
-
this
|
|
60
|
-
this
|
|
57
|
+
if (!clicking && this.#state === CannonState.aiming) {
|
|
58
|
+
this.#gesture.active = false;
|
|
59
|
+
this.#fire();
|
|
60
|
+
this.#state = CannonState.idle;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
isEnabled(interactivityData) {
|
|
64
|
-
const
|
|
64
|
+
const container = this.container, events = container.actualOptions.interactivity?.events;
|
|
65
65
|
if (!events?.onClick.enable) {
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
@@ -69,7 +69,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
69
69
|
if (!modeEnabled) {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
return this
|
|
72
|
+
return this.#state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
73
73
|
}
|
|
74
74
|
loadModeOptions(options, ...sources) {
|
|
75
75
|
options.cannon ??= new Cannon();
|
|
@@ -79,13 +79,13 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
79
79
|
}
|
|
80
80
|
reset(_interactivityData, _particle) {
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
#drawVector() {
|
|
83
83
|
this.container.canvas.render.draw(ctx => {
|
|
84
|
-
const opts = this
|
|
84
|
+
const opts = this.#data;
|
|
85
85
|
if (!opts) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
const { origin, current } = this
|
|
88
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dragDist = getDistance(origin, current), clampedDist = opts.maxDragDistance > none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : dragDist, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
89
89
|
ctx.save();
|
|
90
90
|
ctx.strokeStyle = opts.vectorColor;
|
|
91
91
|
ctx.lineWidth = double * pxRatio;
|
|
@@ -102,12 +102,12 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
102
102
|
ctx.restore();
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
const opts = this
|
|
105
|
+
#fire() {
|
|
106
|
+
const opts = this.#data;
|
|
107
107
|
if (!opts) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const { origin, current } = this
|
|
110
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dist = getDistance(origin, current), dragLength = opts.maxDragDistance > none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
111
111
|
if (dragLength < minTapsLength) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -11,7 +11,7 @@ export class Cannon {
|
|
|
11
11
|
this.spread = 30;
|
|
12
12
|
this.velocityFactor = 0.5;
|
|
13
13
|
this.particleFactor = 0.2;
|
|
14
|
-
this.maxDragDistance =
|
|
14
|
+
this.maxDragDistance = 0;
|
|
15
15
|
this.minParticles = 5;
|
|
16
16
|
this.maxParticles = 200;
|
|
17
17
|
this.drawVector = true;
|
|
@@ -36,6 +36,9 @@ export class Cannon {
|
|
|
36
36
|
if (data.maxParticles !== undefined) {
|
|
37
37
|
this.maxParticles = data.maxParticles;
|
|
38
38
|
}
|
|
39
|
+
if (data.maxDragDistance !== undefined) {
|
|
40
|
+
this.maxDragDistance = data.maxDragDistance;
|
|
41
|
+
}
|
|
39
42
|
if (data.drawVector !== undefined) {
|
|
40
43
|
this.drawVector = data.drawVector;
|
|
41
44
|
}
|
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureInteractivityPluginLoaded } from "@tsparticles/plugin-interactivi
|
|
|
2
2
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
3
3
|
import { Cannoner } from "./Cannoner.js";
|
|
4
4
|
export async function loadExternalCannonInteraction(engine) {
|
|
5
|
-
engine.checkVersion("4.
|
|
5
|
+
engine.checkVersion("4.1.1");
|
|
6
6
|
await engine.pluginManager.register((e) => {
|
|
7
7
|
ensureInteractivityPluginLoaded(e);
|
|
8
8
|
e.pluginManager.addInteractor?.("externalCannon", container => {
|
package/cjs/index.lazy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
2
2
|
export async function loadExternalCannonInteraction(engine) {
|
|
3
|
-
engine.checkVersion("4.
|
|
3
|
+
engine.checkVersion("4.1.1");
|
|
4
4
|
await engine.pluginManager.register(async (e) => {
|
|
5
5
|
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity/lazy");
|
|
6
6
|
ensureInteractivityPluginLoaded(e);
|
package/esm/Cannoner.js
CHANGED
|
@@ -13,14 +13,14 @@ function angleRad(x0, y0, x1, y1) {
|
|
|
13
13
|
}
|
|
14
14
|
export class Cannoner extends ExternalInteractorBase {
|
|
15
15
|
maxDistance = 0;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
#data;
|
|
17
|
+
#gesture = {
|
|
18
18
|
origin: Vector.origin,
|
|
19
19
|
current: Vector.origin,
|
|
20
20
|
active: false,
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
#lastDownPosition = undefined;
|
|
23
|
+
#state = CannonState.idle;
|
|
24
24
|
constructor(container) {
|
|
25
25
|
super(container);
|
|
26
26
|
}
|
|
@@ -28,7 +28,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
28
28
|
}
|
|
29
29
|
init() {
|
|
30
30
|
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
31
|
-
this
|
|
31
|
+
this.#data = {
|
|
32
32
|
spread: degToRad(options.spread),
|
|
33
33
|
maxDragDistance: options.maxDragDistance,
|
|
34
34
|
velocityFactor: options.velocityFactor,
|
|
@@ -41,27 +41,27 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
41
41
|
}
|
|
42
42
|
interact(interactivityData, _delta) {
|
|
43
43
|
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
44
|
-
if (clicking && downPos && downPos !== this
|
|
45
|
-
this
|
|
46
|
-
this
|
|
44
|
+
if (clicking && downPos && downPos !== this.#lastDownPosition && this.#state === CannonState.idle) {
|
|
45
|
+
this.#lastDownPosition = downPos;
|
|
46
|
+
this.#gesture = {
|
|
47
47
|
origin: { x: downPos.x, y: downPos.y },
|
|
48
48
|
current: { x: downPos.x, y: downPos.y },
|
|
49
49
|
active: true,
|
|
50
50
|
};
|
|
51
|
-
this
|
|
51
|
+
this.#state = CannonState.aiming;
|
|
52
52
|
}
|
|
53
|
-
if (this
|
|
54
|
-
this.
|
|
55
|
-
this
|
|
53
|
+
if (this.#state === CannonState.aiming && mousePos) {
|
|
54
|
+
this.#gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
55
|
+
this.#drawVector();
|
|
56
56
|
}
|
|
57
|
-
if (!clicking && this
|
|
58
|
-
this.
|
|
59
|
-
this
|
|
60
|
-
this
|
|
57
|
+
if (!clicking && this.#state === CannonState.aiming) {
|
|
58
|
+
this.#gesture.active = false;
|
|
59
|
+
this.#fire();
|
|
60
|
+
this.#state = CannonState.idle;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
isEnabled(interactivityData) {
|
|
64
|
-
const
|
|
64
|
+
const container = this.container, events = container.actualOptions.interactivity?.events;
|
|
65
65
|
if (!events?.onClick.enable) {
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
@@ -69,7 +69,7 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
69
69
|
if (!modeEnabled) {
|
|
70
70
|
return false;
|
|
71
71
|
}
|
|
72
|
-
return this
|
|
72
|
+
return this.#state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
73
73
|
}
|
|
74
74
|
loadModeOptions(options, ...sources) {
|
|
75
75
|
options.cannon ??= new Cannon();
|
|
@@ -79,13 +79,13 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
79
79
|
}
|
|
80
80
|
reset(_interactivityData, _particle) {
|
|
81
81
|
}
|
|
82
|
-
|
|
82
|
+
#drawVector() {
|
|
83
83
|
this.container.canvas.render.draw(ctx => {
|
|
84
|
-
const opts = this
|
|
84
|
+
const opts = this.#data;
|
|
85
85
|
if (!opts) {
|
|
86
86
|
return;
|
|
87
87
|
}
|
|
88
|
-
const { origin, current } = this
|
|
88
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dragDist = getDistance(origin, current), clampedDist = opts.maxDragDistance > none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : dragDist, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
89
89
|
ctx.save();
|
|
90
90
|
ctx.strokeStyle = opts.vectorColor;
|
|
91
91
|
ctx.lineWidth = double * pxRatio;
|
|
@@ -102,12 +102,12 @@ export class Cannoner extends ExternalInteractorBase {
|
|
|
102
102
|
ctx.restore();
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
const opts = this
|
|
105
|
+
#fire() {
|
|
106
|
+
const opts = this.#data;
|
|
107
107
|
if (!opts) {
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const { origin, current } = this
|
|
110
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dist = getDistance(origin, current), dragLength = opts.maxDragDistance > none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
111
111
|
if (dragLength < minTapsLength) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
@@ -11,7 +11,7 @@ export class Cannon {
|
|
|
11
11
|
this.spread = 30;
|
|
12
12
|
this.velocityFactor = 0.5;
|
|
13
13
|
this.particleFactor = 0.2;
|
|
14
|
-
this.maxDragDistance =
|
|
14
|
+
this.maxDragDistance = 0;
|
|
15
15
|
this.minParticles = 5;
|
|
16
16
|
this.maxParticles = 200;
|
|
17
17
|
this.drawVector = true;
|
|
@@ -36,6 +36,9 @@ export class Cannon {
|
|
|
36
36
|
if (data.maxParticles !== undefined) {
|
|
37
37
|
this.maxParticles = data.maxParticles;
|
|
38
38
|
}
|
|
39
|
+
if (data.maxDragDistance !== undefined) {
|
|
40
|
+
this.maxDragDistance = data.maxDragDistance;
|
|
41
|
+
}
|
|
39
42
|
if (data.drawVector !== undefined) {
|
|
40
43
|
this.drawVector = data.drawVector;
|
|
41
44
|
}
|
package/esm/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ensureInteractivityPluginLoaded } from "@tsparticles/plugin-interactivi
|
|
|
2
2
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
3
3
|
import { Cannoner } from "./Cannoner.js";
|
|
4
4
|
export async function loadExternalCannonInteraction(engine) {
|
|
5
|
-
engine.checkVersion("4.
|
|
5
|
+
engine.checkVersion("4.1.1");
|
|
6
6
|
await engine.pluginManager.register((e) => {
|
|
7
7
|
ensureInteractivityPluginLoaded(e);
|
|
8
8
|
e.pluginManager.addInteractor?.("externalCannon", container => {
|
package/esm/index.lazy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
2
2
|
export async function loadExternalCannonInteraction(engine) {
|
|
3
|
-
engine.checkVersion("4.
|
|
3
|
+
engine.checkVersion("4.1.1");
|
|
4
4
|
await engine.pluginManager.register(async (e) => {
|
|
5
5
|
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity/lazy");
|
|
6
6
|
ensureInteractivityPluginLoaded(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-cannon",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "tsParticles cannon external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"type": "module",
|
|
99
99
|
"peerDependencies": {
|
|
100
|
-
"@tsparticles/engine": "4.
|
|
101
|
-
"@tsparticles/plugin-interactivity": "4.
|
|
100
|
+
"@tsparticles/engine": "4.1.1",
|
|
101
|
+
"@tsparticles/plugin-interactivity": "4.1.1"
|
|
102
102
|
}
|
|
103
103
|
}
|
package/report.html
CHANGED
|
@@ -4930,7 +4930,7 @@ var drawChart = (function (exports) {
|
|
|
4930
4930
|
</script>
|
|
4931
4931
|
<script>
|
|
4932
4932
|
/*<!--*/
|
|
4933
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"tsparticles.interaction.external.cannon.js","children":[{"name":"dist/browser","children":[{"name":"Options/Classes/Cannon.js","uid":"
|
|
4933
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"tsparticles.interaction.external.cannon.js","children":[{"name":"dist/browser","children":[{"name":"Options/Classes/Cannon.js","uid":"a2346b6e-1"},{"uid":"a2346b6e-3","name":"Cannoner.js"},{"uid":"a2346b6e-5","name":"index.js"},{"uid":"a2346b6e-7","name":"browser.js"}]}]}],"isRoot":true},"nodeParts":{"a2346b6e-1":{"renderedLength":1578,"gzipLength":0,"brotliLength":0,"metaUid":"a2346b6e-0"},"a2346b6e-3":{"renderedLength":6101,"gzipLength":0,"brotliLength":0,"metaUid":"a2346b6e-2"},"a2346b6e-5":{"renderedLength":393,"gzipLength":0,"brotliLength":0,"metaUid":"a2346b6e-4"},"a2346b6e-7":{"renderedLength":201,"gzipLength":0,"brotliLength":0,"metaUid":"a2346b6e-6"}},"nodeMetas":{"a2346b6e-0":{"id":"/dist/browser/Options/Classes/Cannon.js","moduleParts":{"tsparticles.interaction.external.cannon.js":"a2346b6e-1"},"imported":[],"importedBy":[{"uid":"a2346b6e-4"},{"uid":"a2346b6e-2"}]},"a2346b6e-2":{"id":"/dist/browser/Cannoner.js","moduleParts":{"tsparticles.interaction.external.cannon.js":"a2346b6e-3"},"imported":[{"uid":"a2346b6e-8"},{"uid":"a2346b6e-9"},{"uid":"a2346b6e-0"}],"importedBy":[{"uid":"a2346b6e-4"}]},"a2346b6e-4":{"id":"/dist/browser/index.js","moduleParts":{"tsparticles.interaction.external.cannon.js":"a2346b6e-5"},"imported":[{"uid":"a2346b6e-8"},{"uid":"a2346b6e-0"},{"uid":"a2346b6e-2"}],"importedBy":[{"uid":"a2346b6e-6"}]},"a2346b6e-6":{"id":"/dist/browser/browser.js","moduleParts":{"tsparticles.interaction.external.cannon.js":"a2346b6e-7"},"imported":[{"uid":"a2346b6e-4"}],"importedBy":[],"isEntry":true},"a2346b6e-8":{"id":"@tsparticles/plugin-interactivity","moduleParts":{},"imported":[],"importedBy":[{"uid":"a2346b6e-4"},{"uid":"a2346b6e-2"}],"isExternal":true},"a2346b6e-9":{"id":"@tsparticles/engine","moduleParts":{},"imported":[],"importedBy":[{"uid":"a2346b6e-2"}],"isExternal":true}},"env":{"rollup":"4.60.4"},"options":{"gzip":false,"brotli":false,"sourcemap":false}};
|
|
4934
4934
|
|
|
4935
4935
|
const run = () => {
|
|
4936
4936
|
const width = window.innerWidth;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
|
|
2
|
-
/* External Interaction v4.
|
|
2
|
+
/* External Interaction v4.1.1 */
|
|
3
3
|
(function (global, factory) {
|
|
4
4
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/plugin-interactivity'), require('@tsparticles/engine')) :
|
|
5
5
|
typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/plugin-interactivity', '@tsparticles/engine'], factory) :
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
this.spread = 30;
|
|
20
20
|
this.velocityFactor = 0.5;
|
|
21
21
|
this.particleFactor = 0.2;
|
|
22
|
-
this.maxDragDistance =
|
|
22
|
+
this.maxDragDistance = 0;
|
|
23
23
|
this.minParticles = 5;
|
|
24
24
|
this.maxParticles = 200;
|
|
25
25
|
this.drawVector = true;
|
|
@@ -44,6 +44,9 @@
|
|
|
44
44
|
if (data.maxParticles !== undefined) {
|
|
45
45
|
this.maxParticles = data.maxParticles;
|
|
46
46
|
}
|
|
47
|
+
if (data.maxDragDistance !== undefined) {
|
|
48
|
+
this.maxDragDistance = data.maxDragDistance;
|
|
49
|
+
}
|
|
47
50
|
if (data.drawVector !== undefined) {
|
|
48
51
|
this.drawVector = data.drawVector;
|
|
49
52
|
}
|
|
@@ -65,14 +68,14 @@
|
|
|
65
68
|
}
|
|
66
69
|
class Cannoner extends pluginInteractivity.ExternalInteractorBase {
|
|
67
70
|
maxDistance = 0;
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
#data;
|
|
72
|
+
#gesture = {
|
|
70
73
|
origin: engine.Vector.origin,
|
|
71
74
|
current: engine.Vector.origin,
|
|
72
75
|
active: false,
|
|
73
76
|
};
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
#lastDownPosition = undefined;
|
|
78
|
+
#state = CannonState.idle;
|
|
76
79
|
constructor(container) {
|
|
77
80
|
super(container);
|
|
78
81
|
}
|
|
@@ -80,7 +83,7 @@
|
|
|
80
83
|
}
|
|
81
84
|
init() {
|
|
82
85
|
const options = this.container.actualOptions.interactivity?.modes.cannon ?? new Cannon();
|
|
83
|
-
this
|
|
86
|
+
this.#data = {
|
|
84
87
|
spread: engine.degToRad(options.spread),
|
|
85
88
|
maxDragDistance: options.maxDragDistance,
|
|
86
89
|
velocityFactor: options.velocityFactor,
|
|
@@ -93,27 +96,27 @@
|
|
|
93
96
|
}
|
|
94
97
|
interact(interactivityData, _delta) {
|
|
95
98
|
const mouse = interactivityData.mouse, mousePos = mouse.position, clicking = mouse.clicking, downPos = mouse.downPosition;
|
|
96
|
-
if (clicking && downPos && downPos !== this
|
|
97
|
-
this
|
|
98
|
-
this
|
|
99
|
+
if (clicking && downPos && downPos !== this.#lastDownPosition && this.#state === CannonState.idle) {
|
|
100
|
+
this.#lastDownPosition = downPos;
|
|
101
|
+
this.#gesture = {
|
|
99
102
|
origin: { x: downPos.x, y: downPos.y },
|
|
100
103
|
current: { x: downPos.x, y: downPos.y },
|
|
101
104
|
active: true,
|
|
102
105
|
};
|
|
103
|
-
this
|
|
106
|
+
this.#state = CannonState.aiming;
|
|
104
107
|
}
|
|
105
|
-
if (this
|
|
106
|
-
this.
|
|
107
|
-
this
|
|
108
|
+
if (this.#state === CannonState.aiming && mousePos) {
|
|
109
|
+
this.#gesture.current = { x: mousePos.x, y: mousePos.y };
|
|
110
|
+
this.#drawVector();
|
|
108
111
|
}
|
|
109
|
-
if (!clicking && this
|
|
110
|
-
this.
|
|
111
|
-
this
|
|
112
|
-
this
|
|
112
|
+
if (!clicking && this.#state === CannonState.aiming) {
|
|
113
|
+
this.#gesture.active = false;
|
|
114
|
+
this.#fire();
|
|
115
|
+
this.#state = CannonState.idle;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
isEnabled(interactivityData) {
|
|
116
|
-
const
|
|
119
|
+
const container = this.container, events = container.actualOptions.interactivity?.events;
|
|
117
120
|
if (!events?.onClick.enable) {
|
|
118
121
|
return false;
|
|
119
122
|
}
|
|
@@ -121,7 +124,7 @@
|
|
|
121
124
|
if (!modeEnabled) {
|
|
122
125
|
return false;
|
|
123
126
|
}
|
|
124
|
-
return this
|
|
127
|
+
return this.#state !== CannonState.idle || interactivityData.mouse.clicking;
|
|
125
128
|
}
|
|
126
129
|
loadModeOptions(options, ...sources) {
|
|
127
130
|
options.cannon ??= new Cannon();
|
|
@@ -131,13 +134,13 @@
|
|
|
131
134
|
}
|
|
132
135
|
reset(_interactivityData, _particle) {
|
|
133
136
|
}
|
|
134
|
-
|
|
137
|
+
#drawVector() {
|
|
135
138
|
this.container.canvas.render.draw(ctx => {
|
|
136
|
-
const opts = this
|
|
139
|
+
const opts = this.#data;
|
|
137
140
|
if (!opts) {
|
|
138
141
|
return;
|
|
139
142
|
}
|
|
140
|
-
const { origin, current } = this
|
|
143
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dragDist = engine.getDistance(origin, current), clampedDist = opts.maxDragDistance > engine.none ? Math.min(dragDist, opts.maxDragDistance * pxRatio) : dragDist, clampRatio = dragDist > minDistance ? clampedDist / dragDist : minDistance, clampedX = origin.x + (current.x - origin.x) * clampRatio, clampedY = origin.y + (current.y - origin.y) * clampRatio;
|
|
141
144
|
ctx.save();
|
|
142
145
|
ctx.strokeStyle = opts.vectorColor;
|
|
143
146
|
ctx.lineWidth = engine.double * pxRatio;
|
|
@@ -154,12 +157,12 @@
|
|
|
154
157
|
ctx.restore();
|
|
155
158
|
});
|
|
156
159
|
}
|
|
157
|
-
|
|
158
|
-
const opts = this
|
|
160
|
+
#fire() {
|
|
161
|
+
const opts = this.#data;
|
|
159
162
|
if (!opts) {
|
|
160
163
|
return;
|
|
161
164
|
}
|
|
162
|
-
const { origin, current } = this
|
|
165
|
+
const { origin, current } = this.#gesture, pxRatio = this.container.retina.pixelRatio, dist = engine.getDistance(origin, current), dragLength = opts.maxDragDistance > engine.none ? Math.min(dist, opts.maxDragDistance * pxRatio) : dist;
|
|
163
166
|
if (dragLength < minTapsLength) {
|
|
164
167
|
return;
|
|
165
168
|
}
|
|
@@ -178,7 +181,7 @@
|
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
async function loadExternalCannonInteraction(engine) {
|
|
181
|
-
engine.checkVersion("4.
|
|
184
|
+
engine.checkVersion("4.1.1");
|
|
182
185
|
await engine.pluginManager.register((e) => {
|
|
183
186
|
pluginInteractivity.ensureInteractivityPluginLoaded(e);
|
|
184
187
|
e.pluginManager.addInteractor?.("externalCannon", container => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t){t.__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.bundles=t.__tsParticlesInternals.bundles||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.engine=t.__tsParticlesInternals.engine||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.palettes=t.__tsParticlesInternals.palettes||{},t.__tsParticlesInternals.paths=t.__tsParticlesInternals.paths||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins.emittersShapes=t.__tsParticlesInternals.plugins.emittersShapes||{},t.__tsParticlesInternals.presets=t.__tsParticlesInternals.presets||{},t.__tsParticlesInternals.shapes=t.__tsParticlesInternals.shapes||{},t.__tsParticlesInternals.updaters=t.__tsParticlesInternals.updaters||{},t.__tsParticlesInternals.utils=t.__tsParticlesInternals.utils||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path.utils=t.__tsParticlesInternals.path.utils||{};var e="undefined"!=typeof Proxy?function(t){return new Proxy(t,{get:function(t,e){return e in t||(t[e]={}),t[e]}})}:function(t){return t};t.__tsParticlesInternals.bundles=e(t.__tsParticlesInternals.bundles),t.__tsParticlesInternals.effects=e(t.__tsParticlesInternals.effects),t.__tsParticlesInternals.interactions=e(t.__tsParticlesInternals.interactions),t.__tsParticlesInternals.palettes=e(t.__tsParticlesInternals.palettes),t.__tsParticlesInternals.paths=e(t.__tsParticlesInternals.paths),t.__tsParticlesInternals.plugins=e(t.__tsParticlesInternals.plugins),t.__tsParticlesInternals.plugins.emittersShapes=e(t.__tsParticlesInternals.plugins.emittersShapes),t.__tsParticlesInternals.presets=e(t.__tsParticlesInternals.presets),t.__tsParticlesInternals.shapes=e(t.__tsParticlesInternals.shapes),t.__tsParticlesInternals.updaters=e(t.__tsParticlesInternals.updaters),t.__tsParticlesInternals.utils=e(t.__tsParticlesInternals.utils),t.__tsParticlesInternals.canvas=e(t.__tsParticlesInternals.canvas),t.__tsParticlesInternals.path=e(t.__tsParticlesInternals.path),t.tsparticlesInternalExports=t.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/plugin-interactivity","@tsparticles/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.interactions.externalCannon=t.__tsParticlesInternals.interactions.externalCannon||{}),t.__tsParticlesInternals.plugins.interactivity,t.__tsParticlesInternals.engine)}(this,function(t,e,s){"use strict";class a{drawVector;maxDragDistance;maxParticles;minParticles;particleFactor;spread;vectorColor;velocityFactor;constructor(){this.spread=30,this.velocityFactor=.5,this.particleFactor=.2,this.maxDragDistance=
|
|
1
|
+
!function(t){t.__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.bundles=t.__tsParticlesInternals.bundles||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.engine=t.__tsParticlesInternals.engine||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.palettes=t.__tsParticlesInternals.palettes||{},t.__tsParticlesInternals.paths=t.__tsParticlesInternals.paths||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins.emittersShapes=t.__tsParticlesInternals.plugins.emittersShapes||{},t.__tsParticlesInternals.presets=t.__tsParticlesInternals.presets||{},t.__tsParticlesInternals.shapes=t.__tsParticlesInternals.shapes||{},t.__tsParticlesInternals.updaters=t.__tsParticlesInternals.updaters||{},t.__tsParticlesInternals.utils=t.__tsParticlesInternals.utils||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path.utils=t.__tsParticlesInternals.path.utils||{};var e="undefined"!=typeof Proxy?function(t){return new Proxy(t,{get:function(t,e){return e in t||(t[e]={}),t[e]}})}:function(t){return t};t.__tsParticlesInternals.bundles=e(t.__tsParticlesInternals.bundles),t.__tsParticlesInternals.effects=e(t.__tsParticlesInternals.effects),t.__tsParticlesInternals.interactions=e(t.__tsParticlesInternals.interactions),t.__tsParticlesInternals.palettes=e(t.__tsParticlesInternals.palettes),t.__tsParticlesInternals.paths=e(t.__tsParticlesInternals.paths),t.__tsParticlesInternals.plugins=e(t.__tsParticlesInternals.plugins),t.__tsParticlesInternals.plugins.emittersShapes=e(t.__tsParticlesInternals.plugins.emittersShapes),t.__tsParticlesInternals.presets=e(t.__tsParticlesInternals.presets),t.__tsParticlesInternals.shapes=e(t.__tsParticlesInternals.shapes),t.__tsParticlesInternals.updaters=e(t.__tsParticlesInternals.updaters),t.__tsParticlesInternals.utils=e(t.__tsParticlesInternals.utils),t.__tsParticlesInternals.canvas=e(t.__tsParticlesInternals.canvas),t.__tsParticlesInternals.path=e(t.__tsParticlesInternals.path),t.tsparticlesInternalExports=t.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@tsparticles/plugin-interactivity"),require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/plugin-interactivity","@tsparticles/engine"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.interactions.externalCannon=t.__tsParticlesInternals.interactions.externalCannon||{}),t.__tsParticlesInternals.plugins.interactivity,t.__tsParticlesInternals.engine)}(this,function(t,e,s){"use strict";class a{drawVector;maxDragDistance;maxParticles;minParticles;particleFactor;spread;vectorColor;velocityFactor;constructor(){this.spread=30,this.velocityFactor=.5,this.particleFactor=.2,this.maxDragDistance=0,this.minParticles=5,this.maxParticles=200,this.drawVector=!0,this.vectorColor="#ffffff80"}load(t){t&&(void 0!==t.spread&&(this.spread=t.spread),void 0!==t.velocityFactor&&(this.velocityFactor=t.velocityFactor),void 0!==t.particleFactor&&(this.particleFactor=t.particleFactor),void 0!==t.minParticles&&(this.minParticles=t.minParticles),void 0!==t.maxParticles&&(this.maxParticles=t.maxParticles),void 0!==t.maxDragDistance&&(this.maxDragDistance=t.maxDragDistance),void 0!==t.drawVector&&(this.drawVector=t.drawVector),void 0!==t.vectorColor&&(this.vectorColor=t.vectorColor))}}var n;!function(t){t[t.idle=0]="idle",t[t.aiming=1]="aiming",t[t.fired=2]="fired"}(n||(n={}));const r="cannon",i=s.identity/20;class l extends e.ExternalInteractorBase{maxDistance=0;#t;#e={origin:s.Vector.origin,current:s.Vector.origin,active:!1};#s=void 0;#a=n.idle;constructor(t){super(t)}clear(t,e){}init(){const t=this.container.actualOptions.interactivity?.modes.cannon??new a;this.#t={spread:s.degToRad(t.spread),maxDragDistance:t.maxDragDistance,velocityFactor:t.velocityFactor,particleFactor:t.particleFactor,minParticles:t.minParticles,maxParticles:t.maxParticles,drawVector:t.drawVector,vectorColor:t.vectorColor}}interact(t,e){const s=t.mouse,a=s.position,r=s.clicking,i=s.downPosition;r&&i&&i!==this.#s&&this.#a===n.idle&&(this.#s=i,this.#e={origin:{x:i.x,y:i.y},current:{x:i.x,y:i.y},active:!0},this.#a=n.aiming),this.#a===n.aiming&&a&&(this.#e.current={x:a.x,y:a.y},this.#n()),r||this.#a!==n.aiming||(this.#e.active=!1,this.#r(),this.#a=n.idle)}isEnabled(t){const e=this.container,s=e.actualOptions.interactivity?.events;if(!s?.onClick.enable)return!1;const a=s.onClick.mode;return!!(Array.isArray(a)?a.includes(r):a===r)&&(this.#a!==n.idle||t.mouse.clicking)}loadModeOptions(t,...e){t.cannon??=new a;for(const s of e)t.cannon.load(s?.cannon)}reset(t,e){}#n(){this.container.canvas.render.draw(t=>{const e=this.#t;if(!e)return;const{origin:a,current:n}=this.#e,r=this.container.retina.pixelRatio,l=s.getDistance(a,n),c=e.maxDragDistance>s.none?Math.min(l,e.maxDragDistance*r):l,o=l>0?c/l:0,_=a.x+(n.x-a.x)*o,P=a.y+(n.y-a.y)*o;t.save(),t.strokeStyle=e.vectorColor,t.lineWidth=s.double*r,t.beginPath(),t.moveTo(a.x,a.y),t.lineTo(_,P),t.stroke();const d=Math.max(4,c*i)*r;t.beginPath(),t.arc(a.x,a.y,d,0,s.doublePI),t.strokeStyle=e.vectorColor,t.lineWidth=s.double*r,t.stroke(),t.restore()})}#r(){const t=this.#t;if(!t)return;const{origin:e,current:a}=this.#e,n=this.container.retina.pixelRatio,r=s.getDistance(e,a),i=t.maxDragDistance>s.none?Math.min(r,t.maxDragDistance*n):r;if(i<2)return;const l=s.identity/n,c=(d=a.x,p=a.y,I=e.x,h=e.y,Math.atan2(h-p,I-d)),o=i*l*t.velocityFactor,_=Math.min(t.maxParticles,Math.max(t.minParticles,Math.round(i*t.particleFactor))),P=180/Math.PI;var d,p,I,h;for(let a=0;a<_;a++){const a=c+s.getRandomInRange(-t.spread,t.spread),n=s.getRandomInRange(.25*o,o);this.container.particles.addParticle(e,{move:{enable:!0,speed:n,direction:a*P}})}}}async function c(t){t.checkVersion("4.1.1"),await t.pluginManager.register(t=>{e.ensureInteractivityPluginLoaded(t),t.pluginManager.addInteractor?.("externalCannon",t=>Promise.resolve(new l(t)))})}const o=globalThis;o.__tsParticlesInternals=o.__tsParticlesInternals??{},o.loadExternalCannonInteraction=c,t.Cannon=a,t.loadExternalCannonInteraction=c}),Object.assign(globalThis.window||globalThis,{loadExternalCannonInteraction:(globalThis.__tsParticlesInternals.interactions.externalCannon||{}).loadExternalCannonInteraction}),delete(globalThis.window||globalThis).tsparticlesInternalExports;
|
package/types/Cannoner.d.ts
CHANGED
|
@@ -2,11 +2,8 @@ import type { CannonContainer, CannonMode, ICannonMode } from "./Types.js";
|
|
|
2
2
|
import { ExternalInteractorBase, type IInteractivityData, type IModes, type InteractivityParticle, type Modes } from "@tsparticles/plugin-interactivity";
|
|
3
3
|
import { type IDelta, type RecursivePartial } from "@tsparticles/engine";
|
|
4
4
|
export declare class Cannoner extends ExternalInteractorBase<CannonContainer> {
|
|
5
|
+
#private;
|
|
5
6
|
readonly maxDistance = 0;
|
|
6
|
-
private _data?;
|
|
7
|
-
private _gesture;
|
|
8
|
-
private _lastDownPosition;
|
|
9
|
-
private _state;
|
|
10
7
|
constructor(container: CannonContainer);
|
|
11
8
|
clear(_particle: InteractivityParticle, _delta: IDelta): void;
|
|
12
9
|
init(): void;
|
|
@@ -14,6 +11,4 @@ export declare class Cannoner extends ExternalInteractorBase<CannonContainer> {
|
|
|
14
11
|
isEnabled(interactivityData: IInteractivityData): boolean;
|
|
15
12
|
loadModeOptions(options: Modes & CannonMode, ...sources: RecursivePartial<(IModes & ICannonMode) | undefined>[]): void;
|
|
16
13
|
reset(_interactivityData: IInteractivityData, _particle: InteractivityParticle): void;
|
|
17
|
-
private _drawVector;
|
|
18
|
-
private _fire;
|
|
19
14
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export type { CannonContainer, CannonMode, ICannonMode } from "./Types.js";
|
|
1
2
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
2
3
|
import { type Engine } from "@tsparticles/engine";
|
|
3
4
|
export type { ICannon } from "./Options/Interfaces/ICannon.js";
|
|
4
|
-
export type { CannonContainer, CannonMode, ICannonMode } from "./Types.js";
|
|
5
5
|
export declare function loadExternalCannonInteraction(engine: Engine): Promise<void>;
|
package/types/index.lazy.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export type { CannonContainer, CannonMode, ICannonMode } from "./Types.js";
|
|
1
2
|
import { type Engine } from "@tsparticles/engine/lazy";
|
|
2
3
|
export type { ICannon } from "./Options/Interfaces/ICannon.js";
|
|
3
|
-
export type { CannonContainer, CannonMode, ICannonMode } from "./Types.js";
|
|
4
4
|
export { Cannon } from "./Options/Classes/Cannon.js";
|
|
5
5
|
export declare function loadExternalCannonInteraction(engine: Engine): Promise<void>;
|