@tsparticles/plugin-absorbers 4.0.0-beta.1 → 4.0.0-beta.10
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/523.min.js +1 -0
- package/547.min.js +1 -0
- package/555.min.js +1 -0
- package/{285.min.js → 564.min.js} +1 -1
- package/63.min.js +1 -0
- package/986.min.js +1 -0
- package/README.md +29 -2
- package/browser/getAbsorbersInstancesManager.js +15 -0
- package/browser/index.js +4 -14
- package/browser/interaction.js +14 -0
- package/browser/plugin.js +10 -0
- package/cjs/getAbsorbersInstancesManager.js +15 -0
- package/cjs/index.js +4 -14
- package/cjs/interaction.js +14 -0
- package/cjs/plugin.js +10 -0
- package/dist_browser_AbsorberInstance_js.js +1 -1
- package/dist_browser_AbsorbersInstancesManager_js.js +1 -1
- package/dist_browser_AbsorbersInteractor_js.js +1 -1
- package/dist_browser_AbsorbersPluginInstance_js.js +1 -1
- package/dist_browser_AbsorbersPlugin_js.js +1 -1
- package/dist_browser_getAbsorbersInstancesManager_js.js +30 -0
- package/esm/getAbsorbersInstancesManager.js +15 -0
- package/esm/index.js +4 -14
- package/esm/interaction.js +14 -0
- package/esm/plugin.js +10 -0
- package/package.json +24 -6
- package/report.html +1 -1
- package/tsparticles.plugin.absorbers.js +22 -2
- package/tsparticles.plugin.absorbers.min.js +2 -2
- package/types/getAbsorbersInstancesManager.d.ts +3 -0
- package/types/interaction.d.ts +3 -0
- package/types/plugin.d.ts +3 -0
- package/122.min.js +0 -1
- package/677.min.js +0 -1
- package/698.min.js +0 -1
- package/998.min.js +0 -1
- package/umd/AbsorberContainer.js +0 -12
- package/umd/AbsorberInstance.js +0 -211
- package/umd/AbsorbersInstancesManager.js +0 -97
- package/umd/AbsorbersInteractor.js +0 -109
- package/umd/AbsorbersPlugin.js +0 -86
- package/umd/AbsorbersPluginInstance.js +0 -56
- package/umd/Options/Classes/Absorber.js +0 -74
- package/umd/Options/Classes/AbsorberLife.js +0 -41
- package/umd/Options/Classes/AbsorberSize.js +0 -41
- package/umd/Options/Classes/AbsorberSizeLimit.js +0 -34
- package/umd/Options/Interfaces/IAbsorber.js +0 -12
- package/umd/Options/Interfaces/IAbsorberLife.js +0 -12
- package/umd/Options/Interfaces/IAbsorberSize.js +0 -12
- package/umd/Options/Interfaces/IAbsorberSizeLimit.js +0 -12
- package/umd/index.js +0 -63
- package/umd/types.js +0 -12
package/umd/AbsorberInstance.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Absorber.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbsorberInstance = void 0;
|
|
13
|
-
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const Absorber_js_1 = require("./Options/Classes/Absorber.js");
|
|
15
|
-
const squareExp = 2, absorbFactor = 0.033, minOrbitLength = 0, minRadius = 0, minMass = 0, minAngle = 0, maxAngle = engine_1.doublePI, maxDegreeAngle = 360, angleIncrementFactor = engine_1.identity / maxDegreeAngle, minVelocity = 0, defaultLifeDelay = 0, minLifeCount = 0, defaultSpawnDelay = 0, defaultLifeCount = -1;
|
|
16
|
-
class AbsorberInstance {
|
|
17
|
-
color;
|
|
18
|
-
limit;
|
|
19
|
-
mass;
|
|
20
|
-
name;
|
|
21
|
-
opacity;
|
|
22
|
-
options;
|
|
23
|
-
position;
|
|
24
|
-
size;
|
|
25
|
-
_container;
|
|
26
|
-
_currentDuration;
|
|
27
|
-
_currentSpawnDelay;
|
|
28
|
-
_duration;
|
|
29
|
-
_firstSpawn;
|
|
30
|
-
_immortal;
|
|
31
|
-
_lifeCount;
|
|
32
|
-
_pluginManager;
|
|
33
|
-
_spawnDelay;
|
|
34
|
-
initialPosition;
|
|
35
|
-
constructor(pluginManager, container, options, position) {
|
|
36
|
-
this._container = container;
|
|
37
|
-
this._pluginManager = pluginManager;
|
|
38
|
-
this._currentDuration = 0;
|
|
39
|
-
this._currentSpawnDelay = 0;
|
|
40
|
-
this.initialPosition = position ? engine_1.Vector.create(position.x, position.y) : undefined;
|
|
41
|
-
if (options instanceof Absorber_js_1.Absorber) {
|
|
42
|
-
this.options = options;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
this.options = new Absorber_js_1.Absorber();
|
|
46
|
-
this.options.load(options);
|
|
47
|
-
}
|
|
48
|
-
this.name = this.options.name;
|
|
49
|
-
this.opacity = this.options.opacity;
|
|
50
|
-
this.size = (0, engine_1.getRangeValue)(this.options.size.value) * container.retina.pixelRatio;
|
|
51
|
-
this.mass = this.size * this.options.size.density * container.retina.reduceFactor;
|
|
52
|
-
const limit = this.options.size.limit;
|
|
53
|
-
this.limit = {
|
|
54
|
-
radius: limit.radius * container.retina.pixelRatio * container.retina.reduceFactor,
|
|
55
|
-
mass: limit.mass,
|
|
56
|
-
};
|
|
57
|
-
this.color = (0, engine_1.rangeColorToRgb)(this._pluginManager, this.options.color) ?? {
|
|
58
|
-
b: 0,
|
|
59
|
-
g: 0,
|
|
60
|
-
r: 0,
|
|
61
|
-
};
|
|
62
|
-
this.position = this.initialPosition?.copy() ?? this._calcPosition();
|
|
63
|
-
this._firstSpawn = !this.options.life.wait;
|
|
64
|
-
this._lifeCount = this.options.life.count ?? defaultLifeCount;
|
|
65
|
-
this._immortal = this._lifeCount <= minLifeCount;
|
|
66
|
-
this._spawnDelay = container.retina.reduceFactor
|
|
67
|
-
? ((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) /
|
|
68
|
-
container.retina.reduceFactor
|
|
69
|
-
: Infinity;
|
|
70
|
-
}
|
|
71
|
-
attract(particle, delta) {
|
|
72
|
-
const container = this._container, options = this.options, pos = particle.getPosition(), { dx, dy, distance } = (0, engine_1.getDistances)(this.position, pos), v = engine_1.Vector.create(dx, dy);
|
|
73
|
-
v.length = (this.mass / Math.pow(distance, squareExp)) * container.retina.reduceFactor;
|
|
74
|
-
if (distance < this.size + particle.getRadius()) {
|
|
75
|
-
const sizeFactor = particle.getRadius() * absorbFactor * container.retina.pixelRatio * delta.factor;
|
|
76
|
-
if ((this.size > particle.getRadius() && distance < this.size - particle.getRadius()) ||
|
|
77
|
-
(particle.absorberOrbit !== undefined && particle.absorberOrbit.length < minOrbitLength)) {
|
|
78
|
-
if (options.destroy) {
|
|
79
|
-
particle.destroy();
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
particle.needsNewPosition = true;
|
|
83
|
-
this._updateParticlePosition(particle, delta, v);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
if (options.destroy) {
|
|
88
|
-
particle.size.value -= sizeFactor;
|
|
89
|
-
}
|
|
90
|
-
this._updateParticlePosition(particle, delta, v);
|
|
91
|
-
}
|
|
92
|
-
if (this.limit.radius <= minRadius || this.size < this.limit.radius) {
|
|
93
|
-
this.size += sizeFactor;
|
|
94
|
-
}
|
|
95
|
-
if (this.limit.mass <= minMass || this.mass < this.limit.mass) {
|
|
96
|
-
this.mass += sizeFactor * this.options.size.density * container.retina.reduceFactor;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this._updateParticlePosition(particle, delta, v);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
draw(context) {
|
|
104
|
-
context.translate(this.position.x, this.position.y);
|
|
105
|
-
context.beginPath();
|
|
106
|
-
context.arc(engine_1.originPoint.x, engine_1.originPoint.y, this.size, minAngle, maxAngle, false);
|
|
107
|
-
context.closePath();
|
|
108
|
-
context.fillStyle = (0, engine_1.getStyleFromRgb)(this.color, this._container.hdr, this.opacity);
|
|
109
|
-
context.fill();
|
|
110
|
-
}
|
|
111
|
-
resize() {
|
|
112
|
-
const initialPosition = this.initialPosition;
|
|
113
|
-
this.position =
|
|
114
|
-
initialPosition && (0, engine_1.isPointInside)(initialPosition, this._container.canvas.size, engine_1.Vector.origin)
|
|
115
|
-
? initialPosition
|
|
116
|
-
: this._calcPosition();
|
|
117
|
-
}
|
|
118
|
-
update(delta) {
|
|
119
|
-
if (this._firstSpawn) {
|
|
120
|
-
this._firstSpawn = false;
|
|
121
|
-
this._currentSpawnDelay = this._spawnDelay ?? defaultSpawnDelay;
|
|
122
|
-
}
|
|
123
|
-
if (this._duration !== undefined) {
|
|
124
|
-
this._currentDuration += delta.value;
|
|
125
|
-
if (this._currentDuration >= this._duration) {
|
|
126
|
-
if (!this._immortal) {
|
|
127
|
-
this._lifeCount--;
|
|
128
|
-
}
|
|
129
|
-
if (this._lifeCount > minLifeCount || this._immortal) {
|
|
130
|
-
this.position = this._calcPosition();
|
|
131
|
-
this._spawnDelay = this._container.retina.reduceFactor
|
|
132
|
-
? ((0, engine_1.getRangeValue)(this.options.life.delay ?? defaultLifeDelay) * engine_1.millisecondsToSeconds) /
|
|
133
|
-
this._container.retina.reduceFactor
|
|
134
|
-
: Infinity;
|
|
135
|
-
}
|
|
136
|
-
this._currentDuration -= this._duration;
|
|
137
|
-
delete this._duration;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (this._spawnDelay !== undefined) {
|
|
141
|
-
this._currentSpawnDelay += delta.value;
|
|
142
|
-
if (this._currentSpawnDelay >= this._spawnDelay) {
|
|
143
|
-
this.play();
|
|
144
|
-
this._currentSpawnDelay -= this._spawnDelay;
|
|
145
|
-
delete this._spawnDelay;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
_calcPosition = () => {
|
|
150
|
-
const exactPosition = (0, engine_1.calcPositionOrRandomFromSizeRanged)({
|
|
151
|
-
size: this._container.canvas.size,
|
|
152
|
-
position: this.options.position,
|
|
153
|
-
});
|
|
154
|
-
return engine_1.Vector.create(exactPosition.x, exactPosition.y);
|
|
155
|
-
};
|
|
156
|
-
_prepareToDie = () => {
|
|
157
|
-
const duration = this.options.life.duration !== undefined ? (0, engine_1.getRangeValue)(this.options.life.duration) : undefined, minDuration = 0;
|
|
158
|
-
if ((this._lifeCount > minLifeCount || this._immortal) && duration !== undefined && duration > minDuration) {
|
|
159
|
-
this._duration = duration * engine_1.millisecondsToSeconds;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
_updateParticlePosition = (particle, delta, v) => {
|
|
163
|
-
if (particle.destroyed) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
const container = this._container, canvasSize = container.canvas.size;
|
|
167
|
-
if (particle.needsNewPosition) {
|
|
168
|
-
const newPosition = (0, engine_1.calcPositionOrRandomFromSize)({ size: canvasSize });
|
|
169
|
-
particle.position.setTo(newPosition);
|
|
170
|
-
particle.velocity.setTo(particle.initialVelocity);
|
|
171
|
-
particle.absorberOrbit = undefined;
|
|
172
|
-
particle.needsNewPosition = false;
|
|
173
|
-
}
|
|
174
|
-
if (this.options.orbits) {
|
|
175
|
-
if (particle.absorberOrbit === undefined) {
|
|
176
|
-
particle.absorberOrbit = engine_1.Vector.origin;
|
|
177
|
-
particle.absorberOrbit.length = (0, engine_1.getDistance)(particle.getPosition(), this.position);
|
|
178
|
-
particle.absorberOrbit.angle = (0, engine_1.getRandom)() * maxAngle;
|
|
179
|
-
}
|
|
180
|
-
if (particle.absorberOrbit.length <= this.size && !this.options.destroy) {
|
|
181
|
-
const minSize = Math.min(canvasSize.width, canvasSize.height), offset = 1, randomOffset = 0.1, randomFactor = 0.2;
|
|
182
|
-
particle.absorberOrbit.length = minSize * (offset + ((0, engine_1.getRandom)() * randomFactor - randomOffset));
|
|
183
|
-
}
|
|
184
|
-
particle.absorberOrbitDirection ??=
|
|
185
|
-
particle.velocity.x >= minVelocity ? engine_1.RotateDirection.clockwise : engine_1.RotateDirection.counterClockwise;
|
|
186
|
-
const orbitRadius = particle.absorberOrbit.length, orbitAngle = particle.absorberOrbit.angle, orbitDirection = particle.absorberOrbitDirection;
|
|
187
|
-
particle.velocity.setTo(engine_1.Vector.origin);
|
|
188
|
-
const maxSize = (0, engine_1.getRangeMax)(particle.options.size.value) * container.retina.pixelRatio, sizeFactor = particle.options.move.size ? particle.getRadius() / maxSize : engine_1.identity, deltaFactor = delta.factor || engine_1.identity, baseSpeed = particle.retina.moveSpeed, moveSpeed = baseSpeed * sizeFactor * deltaFactor * engine_1.half;
|
|
189
|
-
particle.position.x = this.position.x + orbitRadius * Math.cos(orbitAngle);
|
|
190
|
-
particle.position.y =
|
|
191
|
-
this.position.y +
|
|
192
|
-
orbitRadius * (orbitDirection === engine_1.RotateDirection.clockwise ? engine_1.identity : -engine_1.identity) * Math.sin(orbitAngle);
|
|
193
|
-
particle.absorberOrbit.length = Math.max(minOrbitLength, particle.absorberOrbit.length - v.length);
|
|
194
|
-
particle.absorberOrbit.angle += moveSpeed * angleIncrementFactor * container.retina.reduceFactor;
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
particle.velocity.addTo(v);
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
play = () => {
|
|
201
|
-
if (!((this._lifeCount > minLifeCount || this._immortal || !this.options.life.count) &&
|
|
202
|
-
(this._firstSpawn || this._currentSpawnDelay >= (this._spawnDelay ?? defaultSpawnDelay)))) {
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (this._lifeCount > minLifeCount || this._immortal) {
|
|
206
|
-
this._prepareToDie();
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
exports.AbsorberInstance = AbsorberInstance;
|
|
211
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
-
if (k2 === undefined) k2 = k;
|
|
3
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
-
}
|
|
7
|
-
Object.defineProperty(o, k2, desc);
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
18
|
-
var ownKeys = function(o) {
|
|
19
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
20
|
-
var ar = [];
|
|
21
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
22
|
-
return ar;
|
|
23
|
-
};
|
|
24
|
-
return ownKeys(o);
|
|
25
|
-
};
|
|
26
|
-
return function (mod) {
|
|
27
|
-
if (mod && mod.__esModule) return mod;
|
|
28
|
-
var result = {};
|
|
29
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
30
|
-
__setModuleDefault(result, mod);
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
})();
|
|
34
|
-
(function (factory) {
|
|
35
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
36
|
-
var v = factory(require, exports);
|
|
37
|
-
if (v !== undefined) module.exports = v;
|
|
38
|
-
}
|
|
39
|
-
else if (typeof define === "function" && define.amd) {
|
|
40
|
-
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
41
|
-
}
|
|
42
|
-
})(function (require, exports) {
|
|
43
|
-
"use strict";
|
|
44
|
-
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.AbsorbersInstancesManager = void 0;
|
|
47
|
-
const engine_1 = require("@tsparticles/engine");
|
|
48
|
-
const defaultIndex = 0;
|
|
49
|
-
class AbsorbersInstancesManager {
|
|
50
|
-
_containerArrays;
|
|
51
|
-
_pluginManager;
|
|
52
|
-
constructor(pluginManager) {
|
|
53
|
-
this._pluginManager = pluginManager;
|
|
54
|
-
this._containerArrays = new Map();
|
|
55
|
-
}
|
|
56
|
-
async addAbsorber(container, options, position) {
|
|
57
|
-
const { AbsorberInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./AbsorberInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./AbsorberInstance.js"], resolve_1, reject_1); }).then(__importStar)), absorber = new AbsorberInstance(this._pluginManager, container, options, position), array = this.getArray(container);
|
|
58
|
-
array.push(absorber);
|
|
59
|
-
return absorber;
|
|
60
|
-
}
|
|
61
|
-
clear(container) {
|
|
62
|
-
this.initContainer(container);
|
|
63
|
-
this._containerArrays.set(container, []);
|
|
64
|
-
}
|
|
65
|
-
getArray(container) {
|
|
66
|
-
this.initContainer(container);
|
|
67
|
-
let array = this._containerArrays.get(container);
|
|
68
|
-
if (!array) {
|
|
69
|
-
array = [];
|
|
70
|
-
this._containerArrays.set(container, array);
|
|
71
|
-
}
|
|
72
|
-
return array;
|
|
73
|
-
}
|
|
74
|
-
initContainer(container) {
|
|
75
|
-
if (this._containerArrays.has(container)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
this._containerArrays.set(container, []);
|
|
79
|
-
container.getAbsorber ??= (idxOrName) => {
|
|
80
|
-
const array = this.getArray(container);
|
|
81
|
-
return idxOrName === undefined || (0, engine_1.isNumber)(idxOrName)
|
|
82
|
-
? array[idxOrName ?? defaultIndex]
|
|
83
|
-
: array.find(t => t.name === idxOrName);
|
|
84
|
-
};
|
|
85
|
-
container.addAbsorber ??= (options, position) => {
|
|
86
|
-
return this.addAbsorber(container, options, position);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
removeAbsorber(container, absorber) {
|
|
90
|
-
const index = this.getArray(container).indexOf(absorber), deleteCount = 1;
|
|
91
|
-
if (index >= defaultIndex) {
|
|
92
|
-
this.getArray(container).splice(index, deleteCount);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.AbsorbersInstancesManager = AbsorbersInstancesManager;
|
|
97
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/plugin-interactivity", "@tsparticles/engine", "./Options/Classes/Absorber.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbsorbersInteractor = void 0;
|
|
13
|
-
const plugin_interactivity_1 = require("@tsparticles/plugin-interactivity");
|
|
14
|
-
const engine_1 = require("@tsparticles/engine");
|
|
15
|
-
const Absorber_js_1 = require("./Options/Classes/Absorber.js");
|
|
16
|
-
const absorbersMode = "absorbers";
|
|
17
|
-
class AbsorbersInteractor extends plugin_interactivity_1.ExternalInteractorBase {
|
|
18
|
-
handleClickMode;
|
|
19
|
-
maxDistance;
|
|
20
|
-
_dragging = false;
|
|
21
|
-
_draggingAbsorber;
|
|
22
|
-
_instancesManager;
|
|
23
|
-
constructor(container, instancesManager) {
|
|
24
|
-
super(container);
|
|
25
|
-
this.maxDistance = 0;
|
|
26
|
-
this._instancesManager = instancesManager;
|
|
27
|
-
this._instancesManager.initContainer(container);
|
|
28
|
-
this.handleClickMode = (mode, interactivityData) => {
|
|
29
|
-
const container = this.container, options = container.actualOptions, absorbers = options.interactivity.modes.absorbers;
|
|
30
|
-
if (!absorbers || mode !== absorbersMode) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
const { clickPosition } = interactivityData.mouse;
|
|
34
|
-
if (clickPosition) {
|
|
35
|
-
const existingAbsorber = instancesManager
|
|
36
|
-
.getArray(this.container)
|
|
37
|
-
.some(t => (0, engine_1.getDistance)(t.position, clickPosition) < t.size);
|
|
38
|
-
if (existingAbsorber) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const absorbersModeOptions = (0, engine_1.itemFromArray)(absorbers) ?? new Absorber_js_1.Absorber();
|
|
43
|
-
void this._instancesManager.addAbsorber(container, absorbersModeOptions, clickPosition);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
clear() {
|
|
47
|
-
}
|
|
48
|
-
init() {
|
|
49
|
-
}
|
|
50
|
-
interact(interactivityData, delta) {
|
|
51
|
-
for (const particle of this.container.particles.filter(p => this.isEnabled(interactivityData, p))) {
|
|
52
|
-
for (const absorber of this._instancesManager.getArray(this.container)) {
|
|
53
|
-
if (absorber.options.draggable) {
|
|
54
|
-
const mouse = interactivityData.mouse;
|
|
55
|
-
if (mouse.clicking && mouse.downPosition) {
|
|
56
|
-
const mouseDist = (0, engine_1.getDistance)(absorber.position, mouse.downPosition);
|
|
57
|
-
if (mouseDist <= absorber.size) {
|
|
58
|
-
this._dragging = true;
|
|
59
|
-
this._draggingAbsorber = absorber;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
this._dragging = false;
|
|
64
|
-
this._draggingAbsorber = undefined;
|
|
65
|
-
}
|
|
66
|
-
if (this._dragging && this._draggingAbsorber == absorber && mouse.position) {
|
|
67
|
-
absorber.position.x = mouse.position.x;
|
|
68
|
-
absorber.position.y = mouse.position.y;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
absorber.attract(particle, delta);
|
|
72
|
-
if (particle.destroyed) {
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
isEnabled(interactivityData, particle) {
|
|
79
|
-
const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity).events;
|
|
80
|
-
if (!mouse.clickPosition || !events.onClick.enable) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
return (0, engine_1.isInArray)(absorbersMode, events.onClick.mode);
|
|
84
|
-
}
|
|
85
|
-
loadModeOptions(options, ...sources) {
|
|
86
|
-
options.absorbers ??= [];
|
|
87
|
-
for (const source of sources) {
|
|
88
|
-
if (!source) {
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if ((0, engine_1.isArray)(source.absorbers)) {
|
|
92
|
-
for (const absorber of source.absorbers) {
|
|
93
|
-
const tmp = new Absorber_js_1.Absorber();
|
|
94
|
-
tmp.load(absorber);
|
|
95
|
-
options.absorbers.push(tmp);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
const tmp = new Absorber_js_1.Absorber();
|
|
100
|
-
tmp.load(source.absorbers);
|
|
101
|
-
options.absorbers.push(tmp);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
reset() {
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.AbsorbersInteractor = AbsorbersInteractor;
|
|
109
|
-
});
|
package/umd/AbsorbersPlugin.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
-
if (k2 === undefined) k2 = k;
|
|
3
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
-
}
|
|
7
|
-
Object.defineProperty(o, k2, desc);
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
18
|
-
var ownKeys = function(o) {
|
|
19
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
20
|
-
var ar = [];
|
|
21
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
22
|
-
return ar;
|
|
23
|
-
};
|
|
24
|
-
return ownKeys(o);
|
|
25
|
-
};
|
|
26
|
-
return function (mod) {
|
|
27
|
-
if (mod && mod.__esModule) return mod;
|
|
28
|
-
var result = {};
|
|
29
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
30
|
-
__setModuleDefault(result, mod);
|
|
31
|
-
return result;
|
|
32
|
-
};
|
|
33
|
-
})();
|
|
34
|
-
(function (factory) {
|
|
35
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
36
|
-
var v = factory(require, exports);
|
|
37
|
-
if (v !== undefined) module.exports = v;
|
|
38
|
-
}
|
|
39
|
-
else if (typeof define === "function" && define.amd) {
|
|
40
|
-
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Absorber.js"], factory);
|
|
41
|
-
}
|
|
42
|
-
})(function (require, exports) {
|
|
43
|
-
"use strict";
|
|
44
|
-
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
45
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.AbsorbersPlugin = void 0;
|
|
47
|
-
const engine_1 = require("@tsparticles/engine");
|
|
48
|
-
const Absorber_js_1 = require("./Options/Classes/Absorber.js");
|
|
49
|
-
class AbsorbersPlugin {
|
|
50
|
-
id = "absorbers";
|
|
51
|
-
_instancesManager;
|
|
52
|
-
constructor(instancesManager) {
|
|
53
|
-
this._instancesManager = instancesManager;
|
|
54
|
-
}
|
|
55
|
-
async getPlugin(container) {
|
|
56
|
-
const { AbsorbersPluginInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./AbsorbersPluginInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./AbsorbersPluginInstance.js"], resolve_1, reject_1); }).then(__importStar));
|
|
57
|
-
return new AbsorbersPluginInstance(container, this._instancesManager);
|
|
58
|
-
}
|
|
59
|
-
loadOptions(_container, options, source) {
|
|
60
|
-
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (source?.absorbers) {
|
|
64
|
-
options.absorbers = (0, engine_1.executeOnSingleOrMultiple)(source.absorbers, absorber => {
|
|
65
|
-
const tmp = new Absorber_js_1.Absorber();
|
|
66
|
-
tmp.load(absorber);
|
|
67
|
-
return tmp;
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
needsPlugin(options) {
|
|
72
|
-
if (!options) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
const absorbers = options.absorbers;
|
|
76
|
-
if ((0, engine_1.isArray)(absorbers)) {
|
|
77
|
-
return !!absorbers.length;
|
|
78
|
-
}
|
|
79
|
-
else if (absorbers) {
|
|
80
|
-
return true;
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.AbsorbersPlugin = AbsorbersPlugin;
|
|
86
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbsorbersPluginInstance = void 0;
|
|
13
|
-
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
class AbsorbersPluginInstance {
|
|
15
|
-
_container;
|
|
16
|
-
_instancesManager;
|
|
17
|
-
constructor(container, instancesManager) {
|
|
18
|
-
this._container = container;
|
|
19
|
-
this._instancesManager = instancesManager;
|
|
20
|
-
this._instancesManager.initContainer(container);
|
|
21
|
-
}
|
|
22
|
-
draw(context) {
|
|
23
|
-
for (const absorber of this._instancesManager.getArray(this._container)) {
|
|
24
|
-
absorber.draw(context);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async init() {
|
|
28
|
-
const absorbers = this._container.actualOptions.absorbers, promises = (0, engine_1.executeOnSingleOrMultiple)(absorbers, async (absorber) => {
|
|
29
|
-
await this._instancesManager.addAbsorber(this._container, absorber);
|
|
30
|
-
});
|
|
31
|
-
if ((0, engine_1.isArray)(promises)) {
|
|
32
|
-
await Promise.all(promises);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
await promises;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
particleUpdate(particle, delta) {
|
|
39
|
-
for (const absorber of this._instancesManager.getArray(this._container)) {
|
|
40
|
-
absorber.attract(particle, delta);
|
|
41
|
-
if (particle.destroyed) {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
resize() {
|
|
47
|
-
for (const absorber of this._instancesManager.getArray(this._container)) {
|
|
48
|
-
absorber.resize();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
stop() {
|
|
52
|
-
this._instancesManager.clear(this._container);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.AbsorbersPluginInstance = AbsorbersPluginInstance;
|
|
56
|
-
});
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine", "./AbsorberLife.js", "./AbsorberSize.js"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Absorber = void 0;
|
|
13
|
-
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
const AbsorberLife_js_1 = require("./AbsorberLife.js");
|
|
15
|
-
const AbsorberSize_js_1 = require("./AbsorberSize.js");
|
|
16
|
-
class Absorber {
|
|
17
|
-
color;
|
|
18
|
-
destroy;
|
|
19
|
-
draggable;
|
|
20
|
-
life;
|
|
21
|
-
name;
|
|
22
|
-
opacity;
|
|
23
|
-
orbits;
|
|
24
|
-
position;
|
|
25
|
-
size;
|
|
26
|
-
constructor() {
|
|
27
|
-
this.color = new engine_1.OptionsColor();
|
|
28
|
-
this.color.value = "#000000";
|
|
29
|
-
this.draggable = false;
|
|
30
|
-
this.opacity = 1;
|
|
31
|
-
this.destroy = true;
|
|
32
|
-
this.orbits = false;
|
|
33
|
-
this.life = new AbsorberLife_js_1.AbsorberLife();
|
|
34
|
-
this.size = new AbsorberSize_js_1.AbsorberSize();
|
|
35
|
-
}
|
|
36
|
-
load(data) {
|
|
37
|
-
if ((0, engine_1.isNull)(data)) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (data.color !== undefined) {
|
|
41
|
-
this.color = engine_1.OptionsColor.create(this.color, data.color);
|
|
42
|
-
}
|
|
43
|
-
if (data.draggable !== undefined) {
|
|
44
|
-
this.draggable = data.draggable;
|
|
45
|
-
}
|
|
46
|
-
if (data.life !== undefined) {
|
|
47
|
-
this.life.load(data.life);
|
|
48
|
-
}
|
|
49
|
-
this.name = data.name;
|
|
50
|
-
if (data.opacity !== undefined) {
|
|
51
|
-
this.opacity = data.opacity;
|
|
52
|
-
}
|
|
53
|
-
if (data.position !== undefined) {
|
|
54
|
-
this.position = {};
|
|
55
|
-
if (data.position.x !== undefined) {
|
|
56
|
-
this.position.x = (0, engine_1.setRangeValue)(data.position.x);
|
|
57
|
-
}
|
|
58
|
-
if (data.position.y !== undefined) {
|
|
59
|
-
this.position.y = (0, engine_1.setRangeValue)(data.position.y);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (data.size !== undefined) {
|
|
63
|
-
this.size.load(data.size);
|
|
64
|
-
}
|
|
65
|
-
if (data.destroy !== undefined) {
|
|
66
|
-
this.destroy = data.destroy;
|
|
67
|
-
}
|
|
68
|
-
if (data.orbits !== undefined) {
|
|
69
|
-
this.orbits = data.orbits;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.Absorber = Absorber;
|
|
74
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
(function (factory) {
|
|
2
|
-
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
|
-
var v = factory(require, exports);
|
|
4
|
-
if (v !== undefined) module.exports = v;
|
|
5
|
-
}
|
|
6
|
-
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports", "@tsparticles/engine"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbsorberLife = void 0;
|
|
13
|
-
const engine_1 = require("@tsparticles/engine");
|
|
14
|
-
class AbsorberLife {
|
|
15
|
-
count;
|
|
16
|
-
delay;
|
|
17
|
-
duration;
|
|
18
|
-
wait;
|
|
19
|
-
constructor() {
|
|
20
|
-
this.wait = false;
|
|
21
|
-
}
|
|
22
|
-
load(data) {
|
|
23
|
-
if ((0, engine_1.isNull)(data)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (data.count !== undefined) {
|
|
27
|
-
this.count = data.count;
|
|
28
|
-
}
|
|
29
|
-
if (data.delay !== undefined) {
|
|
30
|
-
this.delay = (0, engine_1.setRangeValue)(data.delay);
|
|
31
|
-
}
|
|
32
|
-
if (data.duration !== undefined) {
|
|
33
|
-
this.duration = (0, engine_1.setRangeValue)(data.duration);
|
|
34
|
-
}
|
|
35
|
-
if (data.wait !== undefined) {
|
|
36
|
-
this.wait = data.wait;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.AbsorberLife = AbsorberLife;
|
|
41
|
-
});
|