@tsparticles/interaction-particles-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 +69 -0
- package/browser/Attractor.js +29 -0
- package/browser/index.js +4 -0
- package/cjs/Attractor.js +44 -0
- package/cjs/index.js +19 -0
- package/esm/Attractor.js +29 -0
- package/esm/index.js +4 -0
- package/package.json +82 -0
- package/report.html +39 -0
- package/tsparticles.interaction.particles.attract.js +148 -0
- package/tsparticles.interaction.particles.attract.min.js +2 -0
- package/tsparticles.interaction.particles.attract.min.js.LICENSE.txt +8 -0
- package/types/Attractor.d.ts +10 -0
- package/types/index.d.ts +2 -0
- package/umd/Attractor.js +43 -0
- package/umd/index.js +18 -0
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
"loadParticlesAttractInteraction": () => (/* binding */ loadParticlesAttractInteraction)
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
|
|
98
|
+
var engine_root_window_ = __webpack_require__(533);
|
|
99
|
+
;// CONCATENATED MODULE: ./dist/browser/Attractor.js
|
|
100
|
+
|
|
101
|
+
class Attractor extends engine_root_window_.ParticlesInteractorBase {
|
|
102
|
+
constructor(container) {
|
|
103
|
+
super(container);
|
|
104
|
+
}
|
|
105
|
+
clear() {}
|
|
106
|
+
init() {}
|
|
107
|
+
async interact(p1) {
|
|
108
|
+
var _a;
|
|
109
|
+
const container = this.container,
|
|
110
|
+
distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance,
|
|
111
|
+
pos1 = p1.getPosition(),
|
|
112
|
+
query = container.particles.quadTree.queryCircle(pos1, distance);
|
|
113
|
+
for (const p2 of query) {
|
|
114
|
+
if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const pos2 = p2.getPosition(),
|
|
118
|
+
{
|
|
119
|
+
dx,
|
|
120
|
+
dy
|
|
121
|
+
} = (0,engine_root_window_.getDistances)(pos1, pos2),
|
|
122
|
+
rotate = p1.options.move.attract.rotate,
|
|
123
|
+
ax = dx / (rotate.x * 1000),
|
|
124
|
+
ay = dy / (rotate.y * 1000),
|
|
125
|
+
p1Factor = p2.size.value / p1.size.value,
|
|
126
|
+
p2Factor = 1 / p1Factor;
|
|
127
|
+
p1.velocity.x -= ax * p1Factor;
|
|
128
|
+
p1.velocity.y -= ay * p1Factor;
|
|
129
|
+
p2.velocity.x += ax * p2Factor;
|
|
130
|
+
p2.velocity.y += ay * p2Factor;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
isEnabled(particle) {
|
|
134
|
+
return particle.options.move.attract.enable;
|
|
135
|
+
}
|
|
136
|
+
reset() {}
|
|
137
|
+
}
|
|
138
|
+
;// CONCATENATED MODULE: ./dist/browser/index.js
|
|
139
|
+
|
|
140
|
+
async function loadParticlesAttractInteraction(engine) {
|
|
141
|
+
await engine.addInteractor("particlesAttract", container => new Attractor(container));
|
|
142
|
+
}
|
|
143
|
+
})();
|
|
144
|
+
|
|
145
|
+
/******/ return __webpack_exports__;
|
|
146
|
+
/******/ })()
|
|
147
|
+
;
|
|
148
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! For license information please see tsparticles.interaction.particles.attract.min.js.LICENSE.txt */
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(e=>(()=>{"use strict";var t={533:t=>{t.exports=e}},r={};function o(e){var n=r[e];if(void 0!==n)return n.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,o),i.exports}o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadParticlesAttractInteraction:()=>r});var e=o(533);class t extends e.ParticlesInteractorBase{constructor(e){super(e)}clear(){}init(){}async interact(t){var r;const o=this.container,n=null!==(r=t.retina.attractDistance)&&void 0!==r?r:o.retina.attractDistance,i=t.getPosition(),a=o.particles.quadTree.queryCircle(i,n);for(const r of a){if(t===r||!r.options.move.attract.enable||r.destroyed||r.spawning)continue;const o=r.getPosition(),{dx:n,dy:a}=(0,e.getDistances)(i,o),s=t.options.move.attract.rotate,c=n/(1e3*s.x),l=a/(1e3*s.y),p=r.size.value/t.size.value,d=1/p;t.velocity.x-=c*p,t.velocity.y-=l*p,r.velocity.x+=c*d,r.velocity.y+=l*d}}isEnabled(e){return e.options.move.attract.enable}reset(){}}async function r(e){await e.addInteractor("particlesAttract",(e=>new t(e)))}})(),n})()));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Container, IParticle, Particle } from "@tsparticles/engine";
|
|
2
|
+
import { ParticlesInteractorBase } from "@tsparticles/engine";
|
|
3
|
+
export declare class Attractor extends ParticlesInteractorBase {
|
|
4
|
+
constructor(container: Container);
|
|
5
|
+
clear(): void;
|
|
6
|
+
init(): void;
|
|
7
|
+
interact(p1: IParticle): Promise<void>;
|
|
8
|
+
isEnabled(particle: Particle): boolean;
|
|
9
|
+
reset(): void;
|
|
10
|
+
}
|
package/types/index.d.ts
ADDED
package/umd/Attractor.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
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.Attractor = void 0;
|
|
13
|
+
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
class Attractor extends engine_1.ParticlesInteractorBase {
|
|
15
|
+
constructor(container) {
|
|
16
|
+
super(container);
|
|
17
|
+
}
|
|
18
|
+
clear() {
|
|
19
|
+
}
|
|
20
|
+
init() {
|
|
21
|
+
}
|
|
22
|
+
async interact(p1) {
|
|
23
|
+
var _a;
|
|
24
|
+
const container = this.container, distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance, pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, distance);
|
|
25
|
+
for (const p2 of query) {
|
|
26
|
+
if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const pos2 = p2.getPosition(), { dx, dy } = (0, engine_1.getDistances)(pos1, pos2), rotate = p1.options.move.attract.rotate, ax = dx / (rotate.x * 1000), ay = dy / (rotate.y * 1000), p1Factor = p2.size.value / p1.size.value, p2Factor = 1 / p1Factor;
|
|
30
|
+
p1.velocity.x -= ax * p1Factor;
|
|
31
|
+
p1.velocity.y -= ay * p1Factor;
|
|
32
|
+
p2.velocity.x += ax * p2Factor;
|
|
33
|
+
p2.velocity.y += ay * p2Factor;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
isEnabled(particle) {
|
|
37
|
+
return particle.options.move.attract.enable;
|
|
38
|
+
}
|
|
39
|
+
reset() {
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Attractor = Attractor;
|
|
43
|
+
});
|
package/umd/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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", "./Attractor"], factory);
|
|
8
|
+
}
|
|
9
|
+
})(function (require, exports) {
|
|
10
|
+
"use strict";
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadParticlesAttractInteraction = void 0;
|
|
13
|
+
const Attractor_1 = require("./Attractor");
|
|
14
|
+
async function loadParticlesAttractInteraction(engine) {
|
|
15
|
+
await engine.addInteractor("particlesAttract", (container) => new Attractor_1.Attractor(container));
|
|
16
|
+
}
|
|
17
|
+
exports.loadParticlesAttractInteraction = loadParticlesAttractInteraction;
|
|
18
|
+
});
|