@tsparticles/interaction-external-attract 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -0
- package/browser/Attractor.js +122 -0
- package/browser/Options/Classes/Attract.js +33 -0
- package/browser/Options/Classes/AttractOptions.js +1 -0
- package/browser/Options/Interfaces/IAttract.js +1 -0
- package/browser/Types.js +1 -0
- package/browser/index.js +6 -0
- package/cjs/Attractor.js +137 -0
- package/cjs/Options/Classes/Attract.js +37 -0
- package/cjs/Options/Classes/AttractOptions.js +2 -0
- package/cjs/Options/Interfaces/IAttract.js +2 -0
- package/cjs/Types.js +2 -0
- package/cjs/index.js +35 -0
- package/esm/Attractor.js +122 -0
- package/esm/Options/Classes/Attract.js +33 -0
- package/esm/Options/Classes/AttractOptions.js +1 -0
- package/esm/Options/Interfaces/IAttract.js +1 -0
- package/esm/Types.js +1 -0
- package/esm/index.js +6 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.interaction.external.attract.js +294 -0
- package/tsparticles.interaction.external.attract.min.js +2 -0
- package/tsparticles.interaction.external.attract.min.js.LICENSE.txt +8 -0
- package/types/Attractor.d.ts +17 -0
- package/types/Options/Classes/Attract.d.ts +13 -0
- package/types/Options/Classes/AttractOptions.d.ts +7 -0
- package/types/Options/Interfaces/IAttract.d.ts +9 -0
- package/types/Types.d.ts +24 -0
- package/types/index.d.ts +4 -0
- package/umd/Attractor.js +136 -0
- package/umd/Options/Classes/Attract.js +47 -0
- package/umd/Options/Classes/AttractOptions.js +12 -0
- package/umd/Options/Interfaces/IAttract.js +12 -0
- package/umd/Types.js +12 -0
- package/umd/index.js +34 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Author : Matteo Bruni
|
|
3
|
+
* MIT license: https://opensource.org/licenses/MIT
|
|
4
|
+
* Demo / Generator : https://particles.js.org/
|
|
5
|
+
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
|
+
* How to use? : Check the GitHub README
|
|
7
|
+
* v3.0.0-alpha.0
|
|
8
|
+
*/
|
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
|
11
|
+
module.exports = factory(require("@tsparticles/engine"));
|
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
|
13
|
+
define(["@tsparticles/engine"], factory);
|
|
14
|
+
else {
|
|
15
|
+
var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
|
|
16
|
+
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
|
17
|
+
}
|
|
18
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
|
|
19
|
+
return /******/ (() => { // webpackBootstrap
|
|
20
|
+
/******/ "use strict";
|
|
21
|
+
/******/ var __webpack_modules__ = ({
|
|
22
|
+
|
|
23
|
+
/***/ 533:
|
|
24
|
+
/***/ ((module) => {
|
|
25
|
+
|
|
26
|
+
module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
|
|
27
|
+
|
|
28
|
+
/***/ })
|
|
29
|
+
|
|
30
|
+
/******/ });
|
|
31
|
+
/************************************************************************/
|
|
32
|
+
/******/ // The module cache
|
|
33
|
+
/******/ var __webpack_module_cache__ = {};
|
|
34
|
+
/******/
|
|
35
|
+
/******/ // The require function
|
|
36
|
+
/******/ function __webpack_require__(moduleId) {
|
|
37
|
+
/******/ // Check if module is in cache
|
|
38
|
+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
39
|
+
/******/ if (cachedModule !== undefined) {
|
|
40
|
+
/******/ return cachedModule.exports;
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ // Create a new module (and put it into the cache)
|
|
43
|
+
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
44
|
+
/******/ // no module.id needed
|
|
45
|
+
/******/ // no module.loaded needed
|
|
46
|
+
/******/ exports: {}
|
|
47
|
+
/******/ };
|
|
48
|
+
/******/
|
|
49
|
+
/******/ // Execute the module function
|
|
50
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // Return the exports of the module
|
|
53
|
+
/******/ return module.exports;
|
|
54
|
+
/******/ }
|
|
55
|
+
/******/
|
|
56
|
+
/************************************************************************/
|
|
57
|
+
/******/ /* webpack/runtime/define property getters */
|
|
58
|
+
/******/ (() => {
|
|
59
|
+
/******/ // define getter functions for harmony exports
|
|
60
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
61
|
+
/******/ for(var key in definition) {
|
|
62
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
63
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
64
|
+
/******/ }
|
|
65
|
+
/******/ }
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/ })();
|
|
68
|
+
/******/
|
|
69
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
70
|
+
/******/ (() => {
|
|
71
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
72
|
+
/******/ })();
|
|
73
|
+
/******/
|
|
74
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
75
|
+
/******/ (() => {
|
|
76
|
+
/******/ // define __esModule on exports
|
|
77
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
78
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
79
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
80
|
+
/******/ }
|
|
81
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
82
|
+
/******/ };
|
|
83
|
+
/******/ })();
|
|
84
|
+
/******/
|
|
85
|
+
/************************************************************************/
|
|
86
|
+
var __webpack_exports__ = {};
|
|
87
|
+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
|
|
88
|
+
(() => {
|
|
89
|
+
// ESM COMPAT FLAG
|
|
90
|
+
__webpack_require__.r(__webpack_exports__);
|
|
91
|
+
|
|
92
|
+
// EXPORTS
|
|
93
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
94
|
+
"Attract": () => (/* reexport */ Attract),
|
|
95
|
+
"loadExternalAttractInteraction": () => (/* binding */ loadExternalAttractInteraction)
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
99
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
100
|
+
;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Attract.js
|
|
101
|
+
class Attract {
|
|
102
|
+
constructor() {
|
|
103
|
+
this.distance = 200;
|
|
104
|
+
this.duration = 0.4;
|
|
105
|
+
this.easing = "ease-out-quad";
|
|
106
|
+
this.factor = 1;
|
|
107
|
+
this.maxSpeed = 50;
|
|
108
|
+
this.speed = 1;
|
|
109
|
+
}
|
|
110
|
+
load(data) {
|
|
111
|
+
if (!data) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (data.distance !== undefined) {
|
|
115
|
+
this.distance = data.distance;
|
|
116
|
+
}
|
|
117
|
+
if (data.duration !== undefined) {
|
|
118
|
+
this.duration = data.duration;
|
|
119
|
+
}
|
|
120
|
+
if (data.easing !== undefined) {
|
|
121
|
+
this.easing = data.easing;
|
|
122
|
+
}
|
|
123
|
+
if (data.factor !== undefined) {
|
|
124
|
+
this.factor = data.factor;
|
|
125
|
+
}
|
|
126
|
+
if (data.maxSpeed !== undefined) {
|
|
127
|
+
this.maxSpeed = data.maxSpeed;
|
|
128
|
+
}
|
|
129
|
+
if (data.speed !== undefined) {
|
|
130
|
+
this.speed = data.speed;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
;// CONCATENATED MODULE: ./dist/browser/Attractor.js
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class Attractor extends engine_root_window_.ExternalInteractorBase {
|
|
138
|
+
constructor(engine, container) {
|
|
139
|
+
super(container);
|
|
140
|
+
this._engine = engine;
|
|
141
|
+
if (!container.attract) {
|
|
142
|
+
container.attract = {
|
|
143
|
+
particles: []
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
this.handleClickMode = mode => {
|
|
147
|
+
const options = this.container.actualOptions,
|
|
148
|
+
attract = options.interactivity.modes.attract;
|
|
149
|
+
if (!attract || mode !== "attract") {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (!container.attract) {
|
|
153
|
+
container.attract = {
|
|
154
|
+
particles: []
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
container.attract.clicking = true;
|
|
158
|
+
container.attract.count = 0;
|
|
159
|
+
for (const particle of container.attract.particles) {
|
|
160
|
+
if (!this.isEnabled(particle)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
particle.velocity.setTo(particle.initialVelocity);
|
|
164
|
+
}
|
|
165
|
+
container.attract.particles = [];
|
|
166
|
+
container.attract.finish = false;
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
if (!container.destroyed) {
|
|
169
|
+
if (!container.attract) {
|
|
170
|
+
container.attract = {
|
|
171
|
+
particles: []
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
container.attract.clicking = false;
|
|
175
|
+
}
|
|
176
|
+
}, attract.duration * 1000);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
clear() {}
|
|
180
|
+
init() {
|
|
181
|
+
const container = this.container,
|
|
182
|
+
attract = container.actualOptions.interactivity.modes.attract;
|
|
183
|
+
if (!attract) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
187
|
+
}
|
|
188
|
+
async interact() {
|
|
189
|
+
const container = this.container,
|
|
190
|
+
options = container.actualOptions,
|
|
191
|
+
mouseMoveStatus = container.interactivity.status === engine_root_window_.mouseMoveEvent,
|
|
192
|
+
events = options.interactivity.events,
|
|
193
|
+
hoverEnabled = events.onHover.enable,
|
|
194
|
+
hoverMode = events.onHover.mode,
|
|
195
|
+
clickEnabled = events.onClick.enable,
|
|
196
|
+
clickMode = events.onClick.mode;
|
|
197
|
+
if (mouseMoveStatus && hoverEnabled && (0,engine_root_window_.isInArray)("attract", hoverMode)) {
|
|
198
|
+
this.hoverAttract();
|
|
199
|
+
} else if (clickEnabled && (0,engine_root_window_.isInArray)("attract", clickMode)) {
|
|
200
|
+
this.clickAttract();
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
isEnabled(particle) {
|
|
204
|
+
var _a;
|
|
205
|
+
const container = this.container,
|
|
206
|
+
options = container.actualOptions,
|
|
207
|
+
mouse = container.interactivity.mouse,
|
|
208
|
+
events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
209
|
+
if ((!mouse.position || !events.onHover.enable) && (!mouse.clickPosition || !events.onClick.enable)) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
const hoverMode = events.onHover.mode,
|
|
213
|
+
clickMode = events.onClick.mode;
|
|
214
|
+
return (0,engine_root_window_.isInArray)("attract", hoverMode) || (0,engine_root_window_.isInArray)("attract", clickMode);
|
|
215
|
+
}
|
|
216
|
+
loadModeOptions(options, ...sources) {
|
|
217
|
+
if (!options.attract) {
|
|
218
|
+
options.attract = new Attract();
|
|
219
|
+
}
|
|
220
|
+
for (const source of sources) {
|
|
221
|
+
options.attract.load(source === null || source === void 0 ? void 0 : source.attract);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
reset() {}
|
|
225
|
+
clickAttract() {
|
|
226
|
+
const container = this.container;
|
|
227
|
+
if (!container.attract) {
|
|
228
|
+
container.attract = {
|
|
229
|
+
particles: []
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
if (!container.attract.finish) {
|
|
233
|
+
if (!container.attract.count) {
|
|
234
|
+
container.attract.count = 0;
|
|
235
|
+
}
|
|
236
|
+
container.attract.count++;
|
|
237
|
+
if (container.attract.count === container.particles.count) {
|
|
238
|
+
container.attract.finish = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (container.attract.clicking) {
|
|
242
|
+
const mousePos = container.interactivity.mouse.clickPosition,
|
|
243
|
+
attractRadius = container.retina.attractModeDistance;
|
|
244
|
+
if (!attractRadius || attractRadius < 0 || !mousePos) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
this.processAttract(mousePos, attractRadius, new engine_root_window_.Circle(mousePos.x, mousePos.y, attractRadius));
|
|
248
|
+
} else if (container.attract.clicking === false) {
|
|
249
|
+
container.attract.particles = [];
|
|
250
|
+
}
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
hoverAttract() {
|
|
254
|
+
const container = this.container,
|
|
255
|
+
mousePos = container.interactivity.mouse.position,
|
|
256
|
+
attractRadius = container.retina.attractModeDistance;
|
|
257
|
+
if (!attractRadius || attractRadius < 0 || !mousePos) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.processAttract(mousePos, attractRadius, new engine_root_window_.Circle(mousePos.x, mousePos.y, attractRadius));
|
|
261
|
+
}
|
|
262
|
+
processAttract(position, attractRadius, area) {
|
|
263
|
+
const container = this.container,
|
|
264
|
+
attractOptions = container.actualOptions.interactivity.modes.attract;
|
|
265
|
+
if (!attractOptions) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const query = container.particles.quadTree.query(area, p => this.isEnabled(p));
|
|
269
|
+
for (const particle of query) {
|
|
270
|
+
const {
|
|
271
|
+
dx,
|
|
272
|
+
dy,
|
|
273
|
+
distance
|
|
274
|
+
} = (0,engine_root_window_.getDistances)(particle.position, position);
|
|
275
|
+
const velocity = attractOptions.speed * attractOptions.factor;
|
|
276
|
+
const attractFactor = (0,engine_root_window_.clamp)((0,engine_root_window_.getEasing)(attractOptions.easing)(1 - distance / attractRadius) * velocity, 0, attractOptions.maxSpeed);
|
|
277
|
+
const normVec = engine_root_window_.Vector.create(distance === 0 ? velocity : dx / distance * attractFactor, distance === 0 ? velocity : dy / distance * attractFactor);
|
|
278
|
+
particle.position.subFrom(normVec);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
283
|
+
|
|
284
|
+
async function loadExternalAttractInteraction(engine) {
|
|
285
|
+
await engine.addInteractor("externalAttract", container => new Attractor(engine, container));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
})();
|
|
290
|
+
|
|
291
|
+
/******/ return __webpack_exports__;
|
|
292
|
+
/******/ })()
|
|
293
|
+
;
|
|
294
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.interaction.external.attract.min.js.LICENSE.txt */
|
|
2
|
+
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var a="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var i in a)("object"==typeof exports?exports:t)[i]=a[i]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},a={};function i(t){var r=a[t];if(void 0!==r)return r.exports;var c=a[t]={exports:{}};return e[t](c,c.exports,i),c.exports}i.d=(t,e)=>{for(var a in e)i.o(e,a)&&!i.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:e[a]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{i.r(r),i.d(r,{Attract:()=>e,loadExternalAttractInteraction:()=>c});var t=i(533);class e{constructor(){this.distance=200,this.duration=.4,this.easing="ease-out-quad",this.factor=1,this.maxSpeed=50,this.speed=1}load(t){t&&(void 0!==t.distance&&(this.distance=t.distance),void 0!==t.duration&&(this.duration=t.duration),void 0!==t.easing&&(this.easing=t.easing),void 0!==t.factor&&(this.factor=t.factor),void 0!==t.maxSpeed&&(this.maxSpeed=t.maxSpeed),void 0!==t.speed&&(this.speed=t.speed))}}class a extends t.ExternalInteractorBase{constructor(t,e){super(e),this._engine=t,e.attract||(e.attract={particles:[]}),this.handleClickMode=t=>{const a=this.container.actualOptions.interactivity.modes.attract;if(a&&"attract"===t){e.attract||(e.attract={particles:[]}),e.attract.clicking=!0,e.attract.count=0;for(const t of e.attract.particles)this.isEnabled(t)&&t.velocity.setTo(t.initialVelocity);e.attract.particles=[],e.attract.finish=!1,setTimeout((()=>{e.destroyed||(e.attract||(e.attract={particles:[]}),e.attract.clicking=!1)}),1e3*a.duration)}}}clear(){}init(){const t=this.container,e=t.actualOptions.interactivity.modes.attract;e&&(t.retina.attractModeDistance=e.distance*t.retina.pixelRatio)}async interact(){const e=this.container,a=e.actualOptions,i=e.interactivity.status===t.mouseMoveEvent,r=a.interactivity.events,c=r.onHover.enable,n=r.onHover.mode,o=r.onClick.enable,s=r.onClick.mode;i&&c&&(0,t.isInArray)("attract",n)?this.hoverAttract():o&&(0,t.isInArray)("attract",s)&&this.clickAttract()}isEnabled(e){var a;const i=this.container,r=i.actualOptions,c=i.interactivity.mouse,n=(null!==(a=null==e?void 0:e.interactivity)&&void 0!==a?a:r.interactivity).events;if(!(c.position&&n.onHover.enable||c.clickPosition&&n.onClick.enable))return!1;const o=n.onHover.mode,s=n.onClick.mode;return(0,t.isInArray)("attract",o)||(0,t.isInArray)("attract",s)}loadModeOptions(t,...a){t.attract||(t.attract=new e);for(const e of a)t.attract.load(null==e?void 0:e.attract)}reset(){}clickAttract(){const e=this.container;if(e.attract||(e.attract={particles:[]}),e.attract.finish||(e.attract.count||(e.attract.count=0),e.attract.count++,e.attract.count===e.particles.count&&(e.attract.finish=!0)),e.attract.clicking){const a=e.interactivity.mouse.clickPosition,i=e.retina.attractModeDistance;if(!i||i<0||!a)return;this.processAttract(a,i,new t.Circle(a.x,a.y,i))}else!1===e.attract.clicking&&(e.attract.particles=[])}hoverAttract(){const e=this.container,a=e.interactivity.mouse.position,i=e.retina.attractModeDistance;!i||i<0||!a||this.processAttract(a,i,new t.Circle(a.x,a.y,i))}processAttract(e,a,i){const r=this.container,c=r.actualOptions.interactivity.modes.attract;if(!c)return;const n=r.particles.quadTree.query(i,(t=>this.isEnabled(t)));for(const i of n){const{dx:r,dy:n,distance:o}=(0,t.getDistances)(i.position,e),s=c.speed*c.factor,d=(0,t.clamp)((0,t.getEasing)(c.easing)(1-o/a)*s,0,c.maxSpeed),l=t.Vector.create(0===o?s:r/o*d,0===o?s:n/o*d);i.position.subFrom(l)}}}async function c(t){await t.addInteractor("externalAttract",(e=>new a(t,e)))}})(),r})()));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AttractContainer, AttractMode, IAttractMode } from "./Types";
|
|
2
|
+
import { ExternalInteractorBase } from "@tsparticles/engine";
|
|
3
|
+
import type { Engine, IModes, Modes, Particle, RecursivePartial } from "@tsparticles/engine";
|
|
4
|
+
export declare class Attractor extends ExternalInteractorBase<AttractContainer> {
|
|
5
|
+
handleClickMode: (mode: string) => void;
|
|
6
|
+
private readonly _engine;
|
|
7
|
+
constructor(engine: Engine, container: AttractContainer);
|
|
8
|
+
clear(): void;
|
|
9
|
+
init(): void;
|
|
10
|
+
interact(): Promise<void>;
|
|
11
|
+
isEnabled(particle?: Particle): boolean;
|
|
12
|
+
loadModeOptions(options: Modes & AttractMode, ...sources: RecursivePartial<(IModes & IAttractMode) | undefined>[]): void;
|
|
13
|
+
reset(): void;
|
|
14
|
+
private clickAttract;
|
|
15
|
+
private hoverAttract;
|
|
16
|
+
private processAttract;
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EasingTypeAlt, IOptionLoader, RecursivePartial } from "@tsparticles/engine";
|
|
2
|
+
import { EasingType } from "@tsparticles/engine";
|
|
3
|
+
import type { IAttract } from "../Interfaces/IAttract";
|
|
4
|
+
export declare class Attract implements IAttract, IOptionLoader<IAttract> {
|
|
5
|
+
distance: number;
|
|
6
|
+
duration: number;
|
|
7
|
+
easing: EasingType | EasingTypeAlt;
|
|
8
|
+
factor: number;
|
|
9
|
+
maxSpeed: number;
|
|
10
|
+
speed: number;
|
|
11
|
+
constructor();
|
|
12
|
+
load(data?: RecursivePartial<IAttract>): void;
|
|
13
|
+
}
|
package/types/Types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Container, Particle } from "@tsparticles/engine";
|
|
2
|
+
import type { Attract } from "./Options/Classes/Attract";
|
|
3
|
+
import type { AttractOptions } from "./Options/Classes/AttractOptions";
|
|
4
|
+
import type { IAttract } from "./Options/Interfaces/IAttract";
|
|
5
|
+
export type IAttractMode = {
|
|
6
|
+
attract: IAttract;
|
|
7
|
+
};
|
|
8
|
+
export type AttractMode = {
|
|
9
|
+
attract?: Attract;
|
|
10
|
+
};
|
|
11
|
+
interface IContainerAttract {
|
|
12
|
+
clicking?: boolean;
|
|
13
|
+
count?: number;
|
|
14
|
+
finish?: boolean;
|
|
15
|
+
particles: Particle[];
|
|
16
|
+
}
|
|
17
|
+
export type AttractContainer = Container & {
|
|
18
|
+
actualOptions: AttractOptions;
|
|
19
|
+
attract?: IContainerAttract;
|
|
20
|
+
retina: {
|
|
21
|
+
attractModeDistance?: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export {};
|
package/types/index.d.ts
ADDED
package/umd/Attractor.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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/Attract"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Attractor = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const Attract_1 = require("./Options/Classes/Attract");
|
|
15
|
+
class Attractor extends engine_1.ExternalInteractorBase {
|
|
16
|
+
constructor(engine, container) {
|
|
17
|
+
super(container);
|
|
18
|
+
this._engine = engine;
|
|
19
|
+
if (!container.attract) {
|
|
20
|
+
container.attract = { particles: [] };
|
|
21
|
+
}
|
|
22
|
+
this.handleClickMode = (mode) => {
|
|
23
|
+
const options = this.container.actualOptions, attract = options.interactivity.modes.attract;
|
|
24
|
+
if (!attract || mode !== "attract") {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!container.attract) {
|
|
28
|
+
container.attract = { particles: [] };
|
|
29
|
+
}
|
|
30
|
+
container.attract.clicking = true;
|
|
31
|
+
container.attract.count = 0;
|
|
32
|
+
for (const particle of container.attract.particles) {
|
|
33
|
+
if (!this.isEnabled(particle)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
particle.velocity.setTo(particle.initialVelocity);
|
|
37
|
+
}
|
|
38
|
+
container.attract.particles = [];
|
|
39
|
+
container.attract.finish = false;
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
if (!container.destroyed) {
|
|
42
|
+
if (!container.attract) {
|
|
43
|
+
container.attract = { particles: [] };
|
|
44
|
+
}
|
|
45
|
+
container.attract.clicking = false;
|
|
46
|
+
}
|
|
47
|
+
}, attract.duration * 1000);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
}
|
|
52
|
+
init() {
|
|
53
|
+
const container = this.container, attract = container.actualOptions.interactivity.modes.attract;
|
|
54
|
+
if (!attract) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
|
58
|
+
}
|
|
59
|
+
async interact() {
|
|
60
|
+
const container = this.container, options = container.actualOptions, mouseMoveStatus = container.interactivity.status === engine_1.mouseMoveEvent, events = options.interactivity.events, hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, clickEnabled = events.onClick.enable, clickMode = events.onClick.mode;
|
|
61
|
+
if (mouseMoveStatus && hoverEnabled && (0, engine_1.isInArray)("attract", hoverMode)) {
|
|
62
|
+
this.hoverAttract();
|
|
63
|
+
}
|
|
64
|
+
else if (clickEnabled && (0, engine_1.isInArray)("attract", clickMode)) {
|
|
65
|
+
this.clickAttract();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
isEnabled(particle) {
|
|
69
|
+
var _a;
|
|
70
|
+
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
71
|
+
if ((!mouse.position || !events.onHover.enable) && (!mouse.clickPosition || !events.onClick.enable)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
const hoverMode = events.onHover.mode, clickMode = events.onClick.mode;
|
|
75
|
+
return (0, engine_1.isInArray)("attract", hoverMode) || (0, engine_1.isInArray)("attract", clickMode);
|
|
76
|
+
}
|
|
77
|
+
loadModeOptions(options, ...sources) {
|
|
78
|
+
if (!options.attract) {
|
|
79
|
+
options.attract = new Attract_1.Attract();
|
|
80
|
+
}
|
|
81
|
+
for (const source of sources) {
|
|
82
|
+
options.attract.load(source === null || source === void 0 ? void 0 : source.attract);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
reset() {
|
|
86
|
+
}
|
|
87
|
+
clickAttract() {
|
|
88
|
+
const container = this.container;
|
|
89
|
+
if (!container.attract) {
|
|
90
|
+
container.attract = { particles: [] };
|
|
91
|
+
}
|
|
92
|
+
if (!container.attract.finish) {
|
|
93
|
+
if (!container.attract.count) {
|
|
94
|
+
container.attract.count = 0;
|
|
95
|
+
}
|
|
96
|
+
container.attract.count++;
|
|
97
|
+
if (container.attract.count === container.particles.count) {
|
|
98
|
+
container.attract.finish = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (container.attract.clicking) {
|
|
102
|
+
const mousePos = container.interactivity.mouse.clickPosition, attractRadius = container.retina.attractModeDistance;
|
|
103
|
+
if (!attractRadius || attractRadius < 0 || !mousePos) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this.processAttract(mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius));
|
|
107
|
+
}
|
|
108
|
+
else if (container.attract.clicking === false) {
|
|
109
|
+
container.attract.particles = [];
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
hoverAttract() {
|
|
114
|
+
const container = this.container, mousePos = container.interactivity.mouse.position, attractRadius = container.retina.attractModeDistance;
|
|
115
|
+
if (!attractRadius || attractRadius < 0 || !mousePos) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.processAttract(mousePos, attractRadius, new engine_1.Circle(mousePos.x, mousePos.y, attractRadius));
|
|
119
|
+
}
|
|
120
|
+
processAttract(position, attractRadius, area) {
|
|
121
|
+
const container = this.container, attractOptions = container.actualOptions.interactivity.modes.attract;
|
|
122
|
+
if (!attractOptions) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const query = container.particles.quadTree.query(area, (p) => this.isEnabled(p));
|
|
126
|
+
for (const particle of query) {
|
|
127
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position);
|
|
128
|
+
const velocity = attractOptions.speed * attractOptions.factor;
|
|
129
|
+
const attractFactor = (0, engine_1.clamp)((0, engine_1.getEasing)(attractOptions.easing)(1 - distance / attractRadius) * velocity, 0, attractOptions.maxSpeed);
|
|
130
|
+
const normVec = engine_1.Vector.create(distance === 0 ? velocity : (dx / distance) * attractFactor, distance === 0 ? velocity : (dy / distance) * attractFactor);
|
|
131
|
+
particle.position.subFrom(normVec);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.Attractor = Attractor;
|
|
136
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Attract = void 0;
|
|
13
|
+
class Attract {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.distance = 200;
|
|
16
|
+
this.duration = 0.4;
|
|
17
|
+
this.easing = "ease-out-quad";
|
|
18
|
+
this.factor = 1;
|
|
19
|
+
this.maxSpeed = 50;
|
|
20
|
+
this.speed = 1;
|
|
21
|
+
}
|
|
22
|
+
load(data) {
|
|
23
|
+
if (!data) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (data.distance !== undefined) {
|
|
27
|
+
this.distance = data.distance;
|
|
28
|
+
}
|
|
29
|
+
if (data.duration !== undefined) {
|
|
30
|
+
this.duration = data.duration;
|
|
31
|
+
}
|
|
32
|
+
if (data.easing !== undefined) {
|
|
33
|
+
this.easing = data.easing;
|
|
34
|
+
}
|
|
35
|
+
if (data.factor !== undefined) {
|
|
36
|
+
this.factor = data.factor;
|
|
37
|
+
}
|
|
38
|
+
if (data.maxSpeed !== undefined) {
|
|
39
|
+
this.maxSpeed = data.maxSpeed;
|
|
40
|
+
}
|
|
41
|
+
if (data.speed !== undefined) {
|
|
42
|
+
this.speed = data.speed;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.Attract = Attract;
|
|
47
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/Types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
15
|
+
(function (factory) {
|
|
16
|
+
if (typeof module === "object" && typeof module.exports === "object") {
|
|
17
|
+
var v = factory(require, exports);
|
|
18
|
+
if (v !== undefined) module.exports = v;
|
|
19
|
+
}
|
|
20
|
+
else if (typeof define === "function" && define.amd) {
|
|
21
|
+
define(["require", "exports", "./Attractor", "./Options/Classes/Attract", "./Options/Interfaces/IAttract"], factory);
|
|
22
|
+
}
|
|
23
|
+
})(function (require, exports) {
|
|
24
|
+
"use strict";
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.loadExternalAttractInteraction = void 0;
|
|
27
|
+
const Attractor_1 = require("./Attractor");
|
|
28
|
+
async function loadExternalAttractInteraction(engine) {
|
|
29
|
+
await engine.addInteractor("externalAttract", (container) => new Attractor_1.Attractor(engine, container));
|
|
30
|
+
}
|
|
31
|
+
exports.loadExternalAttractInteraction = loadExternalAttractInteraction;
|
|
32
|
+
__exportStar(require("./Options/Classes/Attract"), exports);
|
|
33
|
+
__exportStar(require("./Options/Interfaces/IAttract"), exports);
|
|
34
|
+
});
|