@tsparticles/updater-out-modes 3.9.1 → 4.0.0-alpha.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/822.min.js +2 -0
- package/822.min.js.LICENSE.txt +1 -0
- package/browser/NoneOutMode.js +1 -1
- package/browser/OutOutMode.js +6 -6
- package/browser/index.js +8 -6
- package/cjs/BounceOutMode.js +8 -12
- package/cjs/DestroyOutMode.js +8 -12
- package/cjs/IBounceData.js +1 -2
- package/cjs/IOutModeManager.js +1 -2
- package/cjs/NoneOutMode.js +9 -13
- package/cjs/OutOfCanvasUpdater.js +14 -18
- package/cjs/OutOutMode.js +26 -30
- package/cjs/Utils.js +23 -27
- package/cjs/index.js +8 -9
- package/dist_browser_OutOfCanvasUpdater_js.js +80 -0
- package/esm/NoneOutMode.js +1 -1
- package/esm/OutOutMode.js +6 -6
- package/esm/index.js +8 -6
- package/package.json +4 -3
- package/report.html +5 -4
- package/tsparticles.updater.out-modes.js +209 -80
- package/tsparticles.updater.out-modes.min.js +1 -1
- package/tsparticles.updater.out-modes.min.js.LICENSE.txt +1 -1
- package/types/NoneOutMode.d.ts +1 -1
- package/types/OutOutMode.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/umd/NoneOutMode.js +1 -1
- package/umd/OutOutMode.js +5 -5
- package/umd/index.js +43 -7
package/822.min.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see 822.min.js.LICENSE.txt */
|
|
2
|
+
(this.webpackChunk_tsparticles_updater_out_modes=this.webpackChunk_tsparticles_updater_out_modes||[]).push([[822],{822(t,i,e){e.d(i,{OutOfCanvasUpdater:()=>d});var o=e(303);class n{constructor(t){this.container=t,this.modes=[o.OutMode.bounce,o.OutMode.split]}update(t,i,e,n){if(!this.modes.includes(n))return;const s=this.container;let r=!1;for(const o of s.plugins.values())if(void 0!==o.particleBounce&&(r=o.particleBounce(t,e,i)),r)break;if(r)return;const a=t.getPosition(),d=t.offset,c=t.getRadius(),u=(0,o.calculateBounds)(a,c),p=s.canvas.size;!function(t){if(t.outMode!==o.OutMode.bounce&&t.outMode!==o.OutMode.split||t.direction!==o.OutModeDirection.left&&t.direction!==o.OutModeDirection.right)return;t.bounds.right<0&&t.direction===o.OutModeDirection.left?t.particle.position.x=t.size+t.offset.x:t.bounds.left>t.canvasSize.width&&t.direction===o.OutModeDirection.right&&(t.particle.position.x=t.canvasSize.width-t.size-t.offset.x);const i=t.particle.velocity.x;let e=!1;if(t.direction===o.OutModeDirection.right&&t.bounds.right>=t.canvasSize.width&&i>0||t.direction===o.OutModeDirection.left&&t.bounds.left<=0&&i<0){const i=(0,o.getRangeValue)(t.particle.options.bounce.horizontal.value);t.particle.velocity.x*=-i,e=!0}if(!e)return;const n=t.offset.x+t.size;t.bounds.right>=t.canvasSize.width&&t.direction===o.OutModeDirection.right?t.particle.position.x=t.canvasSize.width-n:t.bounds.left<=0&&t.direction===o.OutModeDirection.left&&(t.particle.position.x=n),t.outMode===o.OutMode.split&&t.particle.destroy()}({particle:t,outMode:n,direction:i,bounds:u,canvasSize:p,offset:d,size:c}),function(t){if(t.outMode!==o.OutMode.bounce&&t.outMode!==o.OutMode.split||t.direction!==o.OutModeDirection.bottom&&t.direction!==o.OutModeDirection.top)return;t.bounds.bottom<0&&t.direction===o.OutModeDirection.top?t.particle.position.y=t.size+t.offset.y:t.bounds.top>t.canvasSize.height&&t.direction===o.OutModeDirection.bottom&&(t.particle.position.y=t.canvasSize.height-t.size-t.offset.y);const i=t.particle.velocity.y;let e=!1;if(t.direction===o.OutModeDirection.bottom&&t.bounds.bottom>=t.canvasSize.height&&i>0||t.direction===o.OutModeDirection.top&&t.bounds.top<=0&&i<0){const i=(0,o.getRangeValue)(t.particle.options.bounce.vertical.value);t.particle.velocity.y*=-i,e=!0}if(!e)return;const n=t.offset.y+t.size;t.bounds.bottom>=t.canvasSize.height&&t.direction===o.OutModeDirection.bottom?t.particle.position.y=t.canvasSize.height-n:t.bounds.top<=0&&t.direction===o.OutModeDirection.top&&(t.particle.position.y=n),t.outMode===o.OutMode.split&&t.particle.destroy()}({particle:t,outMode:n,direction:i,bounds:u,canvasSize:p,offset:d,size:c})}}class s{constructor(t){this.container=t,this.modes=[o.OutMode.destroy]}update(t,i,e,n){if(!this.modes.includes(n))return;const s=this.container;switch(t.outType){case o.ParticleOutType.normal:case o.ParticleOutType.outside:if((0,o.isPointInside)(t.position,s.canvas.size,o.Vector.origin,t.getRadius(),i))return;break;case o.ParticleOutType.inside:{const{dx:i,dy:e}=(0,o.getDistances)(t.position,t.moveCenter),{x:n,y:s}=t.velocity;if(n<0&&i>t.moveCenter.radius||s<0&&e>t.moveCenter.radius||n>=0&&i<-t.moveCenter.radius||s>=0&&e<-t.moveCenter.radius)return;break}}s.particles.remove(t,t.group,!0)}}class r{constructor(t){this.container=t,this.modes=[o.OutMode.none]}update(t,i,e,n){if(!this.modes.includes(n))return;if((t.options.move.distance.horizontal&&(i===o.OutModeDirection.left||i===o.OutModeDirection.right))??(t.options.move.distance.vertical&&(i===o.OutModeDirection.top||i===o.OutModeDirection.bottom)))return;const s=t.options.move.gravity,r=this.container,a=r.canvas.size,d=t.getRadius();if(s.enable){const e=t.position;(!s.inverse&&e.y>a.height+d&&i===o.OutModeDirection.bottom||s.inverse&&e.y<-d&&i===o.OutModeDirection.top)&&r.particles.remove(t)}else{if(t.velocity.y>0&&t.position.y<=a.height+d||t.velocity.y<0&&t.position.y>=-d||t.velocity.x>0&&t.position.x<=a.width+d||t.velocity.x<0&&t.position.x>=-d)return;(0,o.isPointInside)(t.position,r.canvas.size,o.Vector.origin,d,i)||r.particles.remove(t)}}}class a{constructor(t){this.container=t,this.modes=[o.OutMode.out]}update(t,i,e,n){if(!this.modes.includes(n))return;const s=this.container;switch(t.outType){case o.ParticleOutType.inside:{const{x:i,y:e}=t.velocity,n=o.Vector.origin;n.length=t.moveCenter.radius,n.angle=t.velocity.angle+Math.PI,n.addTo(o.Vector.create(t.moveCenter));const{dx:r,dy:a}=(0,o.getDistances)(t.position,n);if(i<=0&&r>=0||e<=0&&a>=0||i>=0&&r<=0||e>=0&&a<=0)return;t.position.x=Math.floor((0,o.randomInRangeValue)({min:0,max:s.canvas.size.width})),t.position.y=Math.floor((0,o.randomInRangeValue)({min:0,max:s.canvas.size.height}));const{dx:d,dy:c}=(0,o.getDistances)(t.position,t.moveCenter);t.direction=Math.atan2(-c,-d),t.velocity.angle=t.direction;break}default:if((0,o.isPointInside)(t.position,s.canvas.size,o.Vector.origin,t.getRadius(),i))return;switch(t.outType){case o.ParticleOutType.outside:{t.position.x=Math.floor((0,o.randomInRangeValue)({min:-t.moveCenter.radius,max:t.moveCenter.radius}))+t.moveCenter.x,t.position.y=Math.floor((0,o.randomInRangeValue)({min:-t.moveCenter.radius,max:t.moveCenter.radius}))+t.moveCenter.y;const{dx:i,dy:e}=(0,o.getDistances)(t.position,t.moveCenter);t.moveCenter.radius&&(t.direction=Math.atan2(e,i),t.velocity.angle=t.direction);break}case o.ParticleOutType.normal:{const e=t.options.move.warp,n=s.canvas.size,r={bottom:n.height+t.getRadius()+t.offset.y,left:-t.getRadius()-t.offset.x,right:n.width+t.getRadius()+t.offset.x,top:-t.getRadius()-t.offset.y},a=t.getRadius(),d=(0,o.calculateBounds)(t.position,a);i===o.OutModeDirection.right&&d.left>n.width+t.offset.x?(t.position.x=r.left,t.initialPosition.x=t.position.x,e||(t.position.y=(0,o.getRandom)()*n.height,t.initialPosition.y=t.position.y)):i===o.OutModeDirection.left&&d.right<-t.offset.x&&(t.position.x=r.right,t.initialPosition.x=t.position.x,e||(t.position.y=(0,o.getRandom)()*n.height,t.initialPosition.y=t.position.y)),i===o.OutModeDirection.bottom&&d.top>n.height+t.offset.y?(e||(t.position.x=(0,o.getRandom)()*n.width,t.initialPosition.x=t.position.x),t.position.y=r.top,t.initialPosition.y=t.position.y):i===o.OutModeDirection.top&&d.bottom<-t.offset.y&&(e||(t.position.x=(0,o.getRandom)()*n.width,t.initialPosition.x=t.position.x),t.position.y=r.bottom,t.initialPosition.y=t.position.y);break}}}}}class d{constructor(t){this._addUpdaterIfMissing=(t,i,e)=>{const o=t.options.move.outModes;!this.updaters.has(i)&&((t,i)=>t.default===i||t.bottom===i||t.left===i||t.right===i||t.top===i)(o,i)&&this.updaters.set(i,e(this.container))},this._updateOutMode=(t,i,e,o)=>{for(const n of this.updaters.values())n.update(t,o,i,e)},this.container=t,this.updaters=new Map}init(t){this._addUpdaterIfMissing(t,o.OutMode.bounce,(t=>new n(t))),this._addUpdaterIfMissing(t,o.OutMode.out,(t=>new a(t))),this._addUpdaterIfMissing(t,o.OutMode.destroy,(t=>new s(t))),this._addUpdaterIfMissing(t,o.OutMode.none,(t=>new r(t)))}isEnabled(t){return!t.destroyed&&!t.spawning}update(t,i){const e=t.options.move.outModes;this._updateOutMode(t,i,e.bottom??e.default,o.OutModeDirection.bottom),this._updateOutMode(t,i,e.left??e.default,o.OutModeDirection.left),this._updateOutMode(t,i,e.right??e.default,o.OutModeDirection.right),this._updateOutMode(t,i,e.top??e.default,o.OutModeDirection.top)}}}}]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/*! tsParticles Out Modes Updater v4.0.0-alpha.1 by Matteo Bruni */
|
package/browser/NoneOutMode.js
CHANGED
package/browser/OutOutMode.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { OutMode, OutModeDirection, ParticleOutType, Vector, calculateBounds, getDistances, getRandom, isPointInside,
|
|
1
|
+
import { OutMode, OutModeDirection, ParticleOutType, Vector, calculateBounds, getDistances, getRandom, isPointInside, randomInRangeValue, } from "@tsparticles/engine";
|
|
2
2
|
const minVelocity = 0, minDistance = 0;
|
|
3
3
|
export class OutOutMode {
|
|
4
4
|
constructor(container) {
|
|
5
5
|
this.container = container;
|
|
6
6
|
this.modes = [OutMode.out];
|
|
7
7
|
}
|
|
8
|
-
update(particle, direction,
|
|
8
|
+
update(particle, direction, _delta, outMode) {
|
|
9
9
|
if (!this.modes.includes(outMode)) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
@@ -24,11 +24,11 @@ export class OutOutMode {
|
|
|
24
24
|
(vy >= minVelocity && dy <= minDistance)) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
particle.position.x = Math.floor(
|
|
27
|
+
particle.position.x = Math.floor(randomInRangeValue({
|
|
28
28
|
min: 0,
|
|
29
29
|
max: container.canvas.size.width,
|
|
30
30
|
}));
|
|
31
|
-
particle.position.y = Math.floor(
|
|
31
|
+
particle.position.y = Math.floor(randomInRangeValue({
|
|
32
32
|
min: 0,
|
|
33
33
|
max: container.canvas.size.height,
|
|
34
34
|
}));
|
|
@@ -44,12 +44,12 @@ export class OutOutMode {
|
|
|
44
44
|
switch (particle.outType) {
|
|
45
45
|
case ParticleOutType.outside: {
|
|
46
46
|
particle.position.x =
|
|
47
|
-
Math.floor(
|
|
47
|
+
Math.floor(randomInRangeValue({
|
|
48
48
|
min: -particle.moveCenter.radius,
|
|
49
49
|
max: particle.moveCenter.radius,
|
|
50
50
|
})) + particle.moveCenter.x;
|
|
51
51
|
particle.position.y =
|
|
52
|
-
Math.floor(
|
|
52
|
+
Math.floor(randomInRangeValue({
|
|
53
53
|
min: -particle.moveCenter.radius,
|
|
54
54
|
max: particle.moveCenter.radius,
|
|
55
55
|
})) + particle.moveCenter.y;
|
package/browser/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
engine.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export function loadOutModesUpdater(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(e => {
|
|
4
|
+
e.addParticleUpdater("outModes", async (container) => {
|
|
5
|
+
const { OutOfCanvasUpdater } = await import("./OutOfCanvasUpdater.js");
|
|
6
|
+
return new OutOfCanvasUpdater(container);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
7
9
|
}
|
package/cjs/BounceOutMode.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const Utils_js_1 = require("./Utils.js");
|
|
6
|
-
class BounceOutMode {
|
|
1
|
+
import { OutMode, calculateBounds, } from "@tsparticles/engine";
|
|
2
|
+
import { bounceHorizontal, bounceVertical } from "./Utils.js";
|
|
3
|
+
export class BounceOutMode {
|
|
7
4
|
constructor(container) {
|
|
8
5
|
this.container = container;
|
|
9
6
|
this.modes = [
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
OutMode.bounce,
|
|
8
|
+
OutMode.split,
|
|
12
9
|
];
|
|
13
10
|
}
|
|
14
11
|
update(particle, direction, delta, outMode) {
|
|
@@ -28,9 +25,8 @@ class BounceOutMode {
|
|
|
28
25
|
if (handled) {
|
|
29
26
|
return;
|
|
30
27
|
}
|
|
31
|
-
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds =
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const pos = particle.getPosition(), offset = particle.offset, size = particle.getRadius(), bounds = calculateBounds(pos, size), canvasSize = container.canvas.size;
|
|
29
|
+
bounceHorizontal({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
30
|
+
bounceVertical({ particle, outMode, direction, bounds, canvasSize, offset, size });
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
|
-
exports.BounceOutMode = BounceOutMode;
|
package/cjs/DestroyOutMode.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DestroyOutMode = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { OutMode, ParticleOutType, Vector, getDistances, isPointInside, } from "@tsparticles/engine";
|
|
5
2
|
const minVelocity = 0;
|
|
6
|
-
class DestroyOutMode {
|
|
3
|
+
export class DestroyOutMode {
|
|
7
4
|
constructor(container) {
|
|
8
5
|
this.container = container;
|
|
9
|
-
this.modes = [
|
|
6
|
+
this.modes = [OutMode.destroy];
|
|
10
7
|
}
|
|
11
8
|
update(particle, direction, _delta, outMode) {
|
|
12
9
|
if (!this.modes.includes(outMode)) {
|
|
@@ -14,14 +11,14 @@ class DestroyOutMode {
|
|
|
14
11
|
}
|
|
15
12
|
const container = this.container;
|
|
16
13
|
switch (particle.outType) {
|
|
17
|
-
case
|
|
18
|
-
case
|
|
19
|
-
if (
|
|
14
|
+
case ParticleOutType.normal:
|
|
15
|
+
case ParticleOutType.outside:
|
|
16
|
+
if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
|
|
20
17
|
return;
|
|
21
18
|
}
|
|
22
19
|
break;
|
|
23
|
-
case
|
|
24
|
-
const { dx, dy } =
|
|
20
|
+
case ParticleOutType.inside: {
|
|
21
|
+
const { dx, dy } = getDistances(particle.position, particle.moveCenter), { x: vx, y: vy } = particle.velocity;
|
|
25
22
|
if ((vx < minVelocity && dx > particle.moveCenter.radius) ||
|
|
26
23
|
(vy < minVelocity && dy > particle.moveCenter.radius) ||
|
|
27
24
|
(vx >= minVelocity && dx < -particle.moveCenter.radius) ||
|
|
@@ -34,4 +31,3 @@ class DestroyOutMode {
|
|
|
34
31
|
container.particles.remove(particle, particle.group, true);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
|
-
exports.DestroyOutMode = DestroyOutMode;
|
package/cjs/IBounceData.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/IOutModeManager.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/cjs/NoneOutMode.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NoneOutMode = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { OutMode, OutModeDirection, Vector, isPointInside, } from "@tsparticles/engine";
|
|
5
2
|
const minVelocity = 0;
|
|
6
|
-
class NoneOutMode {
|
|
3
|
+
export class NoneOutMode {
|
|
7
4
|
constructor(container) {
|
|
8
5
|
this.container = container;
|
|
9
|
-
this.modes = [
|
|
6
|
+
this.modes = [OutMode.none];
|
|
10
7
|
}
|
|
11
|
-
update(particle, direction,
|
|
8
|
+
update(particle, direction, _delta, outMode) {
|
|
12
9
|
if (!this.modes.includes(outMode)) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
if ((particle.options.move.distance.horizontal &&
|
|
16
|
-
(direction ===
|
|
13
|
+
(direction === OutModeDirection.left || direction === OutModeDirection.right)) ??
|
|
17
14
|
(particle.options.move.distance.vertical &&
|
|
18
|
-
(direction ===
|
|
15
|
+
(direction === OutModeDirection.top || direction === OutModeDirection.bottom))) {
|
|
19
16
|
return;
|
|
20
17
|
}
|
|
21
18
|
const gravityOptions = particle.options.move.gravity, container = this.container, canvasSize = container.canvas.size, pRadius = particle.getRadius();
|
|
@@ -26,7 +23,7 @@ class NoneOutMode {
|
|
|
26
23
|
(particle.velocity.x < minVelocity && particle.position.x >= -pRadius)) {
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
|
-
if (!
|
|
26
|
+
if (!isPointInside(particle.position, container.canvas.size, Vector.origin, pRadius, direction)) {
|
|
30
27
|
container.particles.remove(particle);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
@@ -34,11 +31,10 @@ class NoneOutMode {
|
|
|
34
31
|
const position = particle.position;
|
|
35
32
|
if ((!gravityOptions.inverse &&
|
|
36
33
|
position.y > canvasSize.height + pRadius &&
|
|
37
|
-
direction ===
|
|
38
|
-
(gravityOptions.inverse && position.y < -pRadius && direction ===
|
|
34
|
+
direction === OutModeDirection.bottom) ||
|
|
35
|
+
(gravityOptions.inverse && position.y < -pRadius && direction === OutModeDirection.top)) {
|
|
39
36
|
container.particles.remove(particle);
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
}
|
|
44
|
-
exports.NoneOutMode = NoneOutMode;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const DestroyOutMode_js_1 = require("./DestroyOutMode.js");
|
|
7
|
-
const NoneOutMode_js_1 = require("./NoneOutMode.js");
|
|
8
|
-
const OutOutMode_js_1 = require("./OutOutMode.js");
|
|
1
|
+
import { OutMode, OutModeDirection, } from "@tsparticles/engine";
|
|
2
|
+
import { BounceOutMode } from "./BounceOutMode.js";
|
|
3
|
+
import { DestroyOutMode } from "./DestroyOutMode.js";
|
|
4
|
+
import { NoneOutMode } from "./NoneOutMode.js";
|
|
5
|
+
import { OutOutMode } from "./OutOutMode.js";
|
|
9
6
|
const checkOutMode = (outModes, outMode) => {
|
|
10
7
|
return (outModes.default === outMode ||
|
|
11
8
|
outModes.bottom === outMode ||
|
|
@@ -13,7 +10,7 @@ const checkOutMode = (outModes, outMode) => {
|
|
|
13
10
|
outModes.right === outMode ||
|
|
14
11
|
outModes.top === outMode);
|
|
15
12
|
};
|
|
16
|
-
class OutOfCanvasUpdater {
|
|
13
|
+
export class OutOfCanvasUpdater {
|
|
17
14
|
constructor(container) {
|
|
18
15
|
this._addUpdaterIfMissing = (particle, outMode, getUpdater) => {
|
|
19
16
|
const outModes = particle.options.move.outModes;
|
|
@@ -30,20 +27,19 @@ class OutOfCanvasUpdater {
|
|
|
30
27
|
this.updaters = new Map();
|
|
31
28
|
}
|
|
32
29
|
init(particle) {
|
|
33
|
-
this._addUpdaterIfMissing(particle,
|
|
34
|
-
this._addUpdaterIfMissing(particle,
|
|
35
|
-
this._addUpdaterIfMissing(particle,
|
|
36
|
-
this._addUpdaterIfMissing(particle,
|
|
30
|
+
this._addUpdaterIfMissing(particle, OutMode.bounce, container => new BounceOutMode(container));
|
|
31
|
+
this._addUpdaterIfMissing(particle, OutMode.out, container => new OutOutMode(container));
|
|
32
|
+
this._addUpdaterIfMissing(particle, OutMode.destroy, container => new DestroyOutMode(container));
|
|
33
|
+
this._addUpdaterIfMissing(particle, OutMode.none, container => new NoneOutMode(container));
|
|
37
34
|
}
|
|
38
35
|
isEnabled(particle) {
|
|
39
36
|
return !particle.destroyed && !particle.spawning;
|
|
40
37
|
}
|
|
41
38
|
update(particle, delta) {
|
|
42
39
|
const outModes = particle.options.move.outModes;
|
|
43
|
-
this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default,
|
|
44
|
-
this._updateOutMode(particle, delta, outModes.left ?? outModes.default,
|
|
45
|
-
this._updateOutMode(particle, delta, outModes.right ?? outModes.default,
|
|
46
|
-
this._updateOutMode(particle, delta, outModes.top ?? outModes.default,
|
|
40
|
+
this._updateOutMode(particle, delta, outModes.bottom ?? outModes.default, OutModeDirection.bottom);
|
|
41
|
+
this._updateOutMode(particle, delta, outModes.left ?? outModes.default, OutModeDirection.left);
|
|
42
|
+
this._updateOutMode(particle, delta, outModes.right ?? outModes.default, OutModeDirection.right);
|
|
43
|
+
this._updateOutMode(particle, delta, outModes.top ?? outModes.default, OutModeDirection.top);
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
|
-
exports.OutOfCanvasUpdater = OutOfCanvasUpdater;
|
package/cjs/OutOutMode.js
CHANGED
|
@@ -1,104 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OutOutMode = void 0;
|
|
4
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { OutMode, OutModeDirection, ParticleOutType, Vector, calculateBounds, getDistances, getRandom, isPointInside, randomInRangeValue, } from "@tsparticles/engine";
|
|
5
2
|
const minVelocity = 0, minDistance = 0;
|
|
6
|
-
class OutOutMode {
|
|
3
|
+
export class OutOutMode {
|
|
7
4
|
constructor(container) {
|
|
8
5
|
this.container = container;
|
|
9
|
-
this.modes = [
|
|
6
|
+
this.modes = [OutMode.out];
|
|
10
7
|
}
|
|
11
|
-
update(particle, direction,
|
|
8
|
+
update(particle, direction, _delta, outMode) {
|
|
12
9
|
if (!this.modes.includes(outMode)) {
|
|
13
10
|
return;
|
|
14
11
|
}
|
|
15
12
|
const container = this.container;
|
|
16
13
|
switch (particle.outType) {
|
|
17
|
-
case
|
|
14
|
+
case ParticleOutType.inside: {
|
|
18
15
|
const { x: vx, y: vy } = particle.velocity;
|
|
19
|
-
const circVec =
|
|
16
|
+
const circVec = Vector.origin;
|
|
20
17
|
circVec.length = particle.moveCenter.radius;
|
|
21
18
|
circVec.angle = particle.velocity.angle + Math.PI;
|
|
22
|
-
circVec.addTo(
|
|
23
|
-
const { dx, dy } =
|
|
19
|
+
circVec.addTo(Vector.create(particle.moveCenter));
|
|
20
|
+
const { dx, dy } = getDistances(particle.position, circVec);
|
|
24
21
|
if ((vx <= minVelocity && dx >= minDistance) ||
|
|
25
22
|
(vy <= minVelocity && dy >= minDistance) ||
|
|
26
23
|
(vx >= minVelocity && dx <= minDistance) ||
|
|
27
24
|
(vy >= minVelocity && dy <= minDistance)) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
|
-
particle.position.x = Math.floor((
|
|
27
|
+
particle.position.x = Math.floor(randomInRangeValue({
|
|
31
28
|
min: 0,
|
|
32
29
|
max: container.canvas.size.width,
|
|
33
30
|
}));
|
|
34
|
-
particle.position.y = Math.floor((
|
|
31
|
+
particle.position.y = Math.floor(randomInRangeValue({
|
|
35
32
|
min: 0,
|
|
36
33
|
max: container.canvas.size.height,
|
|
37
34
|
}));
|
|
38
|
-
const { dx: newDx, dy: newDy } =
|
|
35
|
+
const { dx: newDx, dy: newDy } = getDistances(particle.position, particle.moveCenter);
|
|
39
36
|
particle.direction = Math.atan2(-newDy, -newDx);
|
|
40
37
|
particle.velocity.angle = particle.direction;
|
|
41
38
|
break;
|
|
42
39
|
}
|
|
43
40
|
default: {
|
|
44
|
-
if (
|
|
41
|
+
if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
|
|
45
42
|
return;
|
|
46
43
|
}
|
|
47
44
|
switch (particle.outType) {
|
|
48
|
-
case
|
|
45
|
+
case ParticleOutType.outside: {
|
|
49
46
|
particle.position.x =
|
|
50
|
-
Math.floor((
|
|
47
|
+
Math.floor(randomInRangeValue({
|
|
51
48
|
min: -particle.moveCenter.radius,
|
|
52
49
|
max: particle.moveCenter.radius,
|
|
53
50
|
})) + particle.moveCenter.x;
|
|
54
51
|
particle.position.y =
|
|
55
|
-
Math.floor((
|
|
52
|
+
Math.floor(randomInRangeValue({
|
|
56
53
|
min: -particle.moveCenter.radius,
|
|
57
54
|
max: particle.moveCenter.radius,
|
|
58
55
|
})) + particle.moveCenter.y;
|
|
59
|
-
const { dx, dy } =
|
|
56
|
+
const { dx, dy } = getDistances(particle.position, particle.moveCenter);
|
|
60
57
|
if (particle.moveCenter.radius) {
|
|
61
58
|
particle.direction = Math.atan2(dy, dx);
|
|
62
59
|
particle.velocity.angle = particle.direction;
|
|
63
60
|
}
|
|
64
61
|
break;
|
|
65
62
|
}
|
|
66
|
-
case
|
|
63
|
+
case ParticleOutType.normal: {
|
|
67
64
|
const warp = particle.options.move.warp, canvasSize = container.canvas.size, newPos = {
|
|
68
65
|
bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
|
|
69
66
|
left: -particle.getRadius() - particle.offset.x,
|
|
70
67
|
right: canvasSize.width + particle.getRadius() + particle.offset.x,
|
|
71
68
|
top: -particle.getRadius() - particle.offset.y,
|
|
72
|
-
}, sizeValue = particle.getRadius(), nextBounds =
|
|
73
|
-
if (direction ===
|
|
69
|
+
}, sizeValue = particle.getRadius(), nextBounds = calculateBounds(particle.position, sizeValue);
|
|
70
|
+
if (direction === OutModeDirection.right &&
|
|
74
71
|
nextBounds.left > canvasSize.width + particle.offset.x) {
|
|
75
72
|
particle.position.x = newPos.left;
|
|
76
73
|
particle.initialPosition.x = particle.position.x;
|
|
77
74
|
if (!warp) {
|
|
78
|
-
particle.position.y =
|
|
75
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
79
76
|
particle.initialPosition.y = particle.position.y;
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
|
-
else if (direction ===
|
|
79
|
+
else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
|
|
83
80
|
particle.position.x = newPos.right;
|
|
84
81
|
particle.initialPosition.x = particle.position.x;
|
|
85
82
|
if (!warp) {
|
|
86
|
-
particle.position.y =
|
|
83
|
+
particle.position.y = getRandom() * canvasSize.height;
|
|
87
84
|
particle.initialPosition.y = particle.position.y;
|
|
88
85
|
}
|
|
89
86
|
}
|
|
90
|
-
if (direction ===
|
|
87
|
+
if (direction === OutModeDirection.bottom &&
|
|
91
88
|
nextBounds.top > canvasSize.height + particle.offset.y) {
|
|
92
89
|
if (!warp) {
|
|
93
|
-
particle.position.x =
|
|
90
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
94
91
|
particle.initialPosition.x = particle.position.x;
|
|
95
92
|
}
|
|
96
93
|
particle.position.y = newPos.top;
|
|
97
94
|
particle.initialPosition.y = particle.position.y;
|
|
98
95
|
}
|
|
99
|
-
else if (direction ===
|
|
96
|
+
else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
|
|
100
97
|
if (!warp) {
|
|
101
|
-
particle.position.x =
|
|
98
|
+
particle.position.x = getRandom() * canvasSize.width;
|
|
102
99
|
particle.initialPosition.x = particle.position.x;
|
|
103
100
|
}
|
|
104
101
|
particle.position.y = newPos.bottom;
|
|
@@ -112,4 +109,3 @@ class OutOutMode {
|
|
|
112
109
|
}
|
|
113
110
|
}
|
|
114
111
|
}
|
|
115
|
-
exports.OutOutMode = OutOutMode;
|
package/cjs/Utils.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.bounceHorizontal = bounceHorizontal;
|
|
4
|
-
exports.bounceVertical = bounceVertical;
|
|
5
|
-
const engine_1 = require("@tsparticles/engine");
|
|
1
|
+
import { OutMode, OutModeDirection, getRangeValue } from "@tsparticles/engine";
|
|
6
2
|
const minVelocity = 0, boundsMin = 0;
|
|
7
|
-
function bounceHorizontal(data) {
|
|
8
|
-
if ((data.outMode !==
|
|
9
|
-
(data.direction !==
|
|
3
|
+
export function bounceHorizontal(data) {
|
|
4
|
+
if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
|
|
5
|
+
(data.direction !== OutModeDirection.left && data.direction !== OutModeDirection.right)) {
|
|
10
6
|
return;
|
|
11
7
|
}
|
|
12
|
-
if (data.bounds.right < boundsMin && data.direction ===
|
|
8
|
+
if (data.bounds.right < boundsMin && data.direction === OutModeDirection.left) {
|
|
13
9
|
data.particle.position.x = data.size + data.offset.x;
|
|
14
10
|
}
|
|
15
|
-
else if (data.bounds.left > data.canvasSize.width && data.direction ===
|
|
11
|
+
else if (data.bounds.left > data.canvasSize.width && data.direction === OutModeDirection.right) {
|
|
16
12
|
data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
|
|
17
13
|
}
|
|
18
14
|
const velocity = data.particle.velocity.x;
|
|
19
15
|
let bounced = false;
|
|
20
|
-
if ((data.direction ===
|
|
16
|
+
if ((data.direction === OutModeDirection.right &&
|
|
21
17
|
data.bounds.right >= data.canvasSize.width &&
|
|
22
18
|
velocity > minVelocity) ||
|
|
23
|
-
(data.direction ===
|
|
24
|
-
const newVelocity =
|
|
19
|
+
(data.direction === OutModeDirection.left && data.bounds.left <= boundsMin && velocity < minVelocity)) {
|
|
20
|
+
const newVelocity = getRangeValue(data.particle.options.bounce.horizontal.value);
|
|
25
21
|
data.particle.velocity.x *= -newVelocity;
|
|
26
22
|
bounced = true;
|
|
27
23
|
}
|
|
@@ -29,34 +25,34 @@ function bounceHorizontal(data) {
|
|
|
29
25
|
return;
|
|
30
26
|
}
|
|
31
27
|
const minPos = data.offset.x + data.size;
|
|
32
|
-
if (data.bounds.right >= data.canvasSize.width && data.direction ===
|
|
28
|
+
if (data.bounds.right >= data.canvasSize.width && data.direction === OutModeDirection.right) {
|
|
33
29
|
data.particle.position.x = data.canvasSize.width - minPos;
|
|
34
30
|
}
|
|
35
|
-
else if (data.bounds.left <= boundsMin && data.direction ===
|
|
31
|
+
else if (data.bounds.left <= boundsMin && data.direction === OutModeDirection.left) {
|
|
36
32
|
data.particle.position.x = minPos;
|
|
37
33
|
}
|
|
38
|
-
if (data.outMode ===
|
|
34
|
+
if (data.outMode === OutMode.split) {
|
|
39
35
|
data.particle.destroy();
|
|
40
36
|
}
|
|
41
37
|
}
|
|
42
|
-
function bounceVertical(data) {
|
|
43
|
-
if ((data.outMode !==
|
|
44
|
-
(data.direction !==
|
|
38
|
+
export function bounceVertical(data) {
|
|
39
|
+
if ((data.outMode !== OutMode.bounce && data.outMode !== OutMode.split) ||
|
|
40
|
+
(data.direction !== OutModeDirection.bottom && data.direction !== OutModeDirection.top)) {
|
|
45
41
|
return;
|
|
46
42
|
}
|
|
47
|
-
if (data.bounds.bottom < boundsMin && data.direction ===
|
|
43
|
+
if (data.bounds.bottom < boundsMin && data.direction === OutModeDirection.top) {
|
|
48
44
|
data.particle.position.y = data.size + data.offset.y;
|
|
49
45
|
}
|
|
50
|
-
else if (data.bounds.top > data.canvasSize.height && data.direction ===
|
|
46
|
+
else if (data.bounds.top > data.canvasSize.height && data.direction === OutModeDirection.bottom) {
|
|
51
47
|
data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
|
|
52
48
|
}
|
|
53
49
|
const velocity = data.particle.velocity.y;
|
|
54
50
|
let bounced = false;
|
|
55
|
-
if ((data.direction ===
|
|
51
|
+
if ((data.direction === OutModeDirection.bottom &&
|
|
56
52
|
data.bounds.bottom >= data.canvasSize.height &&
|
|
57
53
|
velocity > minVelocity) ||
|
|
58
|
-
(data.direction ===
|
|
59
|
-
const newVelocity =
|
|
54
|
+
(data.direction === OutModeDirection.top && data.bounds.top <= boundsMin && velocity < minVelocity)) {
|
|
55
|
+
const newVelocity = getRangeValue(data.particle.options.bounce.vertical.value);
|
|
60
56
|
data.particle.velocity.y *= -newVelocity;
|
|
61
57
|
bounced = true;
|
|
62
58
|
}
|
|
@@ -64,13 +60,13 @@ function bounceVertical(data) {
|
|
|
64
60
|
return;
|
|
65
61
|
}
|
|
66
62
|
const minPos = data.offset.y + data.size;
|
|
67
|
-
if (data.bounds.bottom >= data.canvasSize.height && data.direction ===
|
|
63
|
+
if (data.bounds.bottom >= data.canvasSize.height && data.direction === OutModeDirection.bottom) {
|
|
68
64
|
data.particle.position.y = data.canvasSize.height - minPos;
|
|
69
65
|
}
|
|
70
|
-
else if (data.bounds.top <= boundsMin && data.direction ===
|
|
66
|
+
else if (data.bounds.top <= boundsMin && data.direction === OutModeDirection.top) {
|
|
71
67
|
data.particle.position.y = minPos;
|
|
72
68
|
}
|
|
73
|
-
if (data.outMode ===
|
|
69
|
+
if (data.outMode === OutMode.split) {
|
|
74
70
|
data.particle.destroy();
|
|
75
71
|
}
|
|
76
72
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, refresh);
|
|
1
|
+
export function loadOutModesUpdater(engine) {
|
|
2
|
+
engine.checkVersion("4.0.0-alpha.1");
|
|
3
|
+
engine.register(e => {
|
|
4
|
+
e.addParticleUpdater("outModes", async (container) => {
|
|
5
|
+
const { OutOfCanvasUpdater } = await import("./OutOfCanvasUpdater.js");
|
|
6
|
+
return new OutOfCanvasUpdater(container);
|
|
7
|
+
});
|
|
8
|
+
});
|
|
10
9
|
}
|