@tsparticles/interaction-particles-repulse 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # tsParticles Particles Repulsion Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-particles-repulse/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-particles-repulse)
6
+ [![npmjs](https://badge.fury.io/js/tsparticles-interaction-particles-repulse.svg)](https://www.npmjs.com/package/tsparticles-interaction-particles-repulse)
7
+ [![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-particles-repulse)](https://www.npmjs.com/package/tsparticles-interaction-particles-repulse) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for repulse effect between particles.
10
+
11
+ ## How to use it
12
+
13
+ ### CDN / Vanilla JS / jQuery
14
+
15
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
16
+
17
+ Including the `tsparticles.interaction.particles.repulse.min.js` file will export the function to load the interaction
18
+ plugin:
19
+
20
+ ```text
21
+ loadParticlesRepulseInteraction
22
+ ```
23
+
24
+ ### Usage
25
+
26
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
27
+
28
+ ```javascript
29
+ loadParticlesRepulseInteraction(tsParticles);
30
+
31
+ tsParticles.load({
32
+ id: "tsparticles",
33
+ options: {
34
+ /* options */
35
+ },
36
+ });
37
+ ```
38
+
39
+ ### ESM / CommonJS
40
+
41
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
42
+
43
+ ```shell
44
+ $ npm install tsparticles-interaction-particles-repulse
45
+ ```
46
+
47
+ or
48
+
49
+ ```shell
50
+ $ yarn add tsparticles-interaction-particles-repulse
51
+ ```
52
+
53
+ Then you need to import it in the app, like this:
54
+
55
+ ```javascript
56
+ const { tsParticles } = require("tsparticles-engine");
57
+ const { loadParticlesRepulseInteraction } = require("tsparticles-interaction-particles-repulse");
58
+
59
+ loadParticlesRepulseInteraction(tsParticles);
60
+ ```
61
+
62
+ or
63
+
64
+ ```javascript
65
+ import { tsParticles } from "tsparticles-engine";
66
+ import { loadParticlesRepulseInteraction } from "tsparticles-interaction-particles-repulse";
67
+
68
+ loadParticlesRepulseInteraction(tsParticles);
69
+ ```
@@ -0,0 +1,32 @@
1
+ import { ValueWithRandom, setRangeValue } from "@tsparticles/engine";
2
+ export class ParticlesRepulse extends ValueWithRandom {
3
+ constructor() {
4
+ super();
5
+ this.enabled = false;
6
+ this.distance = 1;
7
+ this.duration = 1;
8
+ this.factor = 1;
9
+ this.speed = 1;
10
+ }
11
+ load(data) {
12
+ super.load(data);
13
+ if (!data) {
14
+ return;
15
+ }
16
+ if (data.enabled !== undefined) {
17
+ this.enabled = data.enabled;
18
+ }
19
+ if (data.distance !== undefined) {
20
+ this.distance = setRangeValue(data.distance);
21
+ }
22
+ if (data.duration !== undefined) {
23
+ this.duration = setRangeValue(data.duration);
24
+ }
25
+ if (data.factor !== undefined) {
26
+ this.factor = setRangeValue(data.factor);
27
+ }
28
+ if (data.speed !== undefined) {
29
+ this.speed = setRangeValue(data.speed);
30
+ }
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { ParticlesInteractorBase, Vector, clamp, getDistances, getRangeValue } from "@tsparticles/engine";
2
+ import { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse";
3
+ export class Repulser extends ParticlesInteractorBase {
4
+ constructor(container) {
5
+ super(container);
6
+ }
7
+ clear() {
8
+ }
9
+ init() {
10
+ }
11
+ async interact(p1) {
12
+ const container = this.container;
13
+ if (!p1.repulse) {
14
+ const repulseOpt1 = p1.options.repulse;
15
+ if (!repulseOpt1) {
16
+ return;
17
+ }
18
+ p1.repulse = {
19
+ distance: getRangeValue(repulseOpt1.distance) * container.retina.pixelRatio,
20
+ speed: getRangeValue(repulseOpt1.speed),
21
+ factor: getRangeValue(repulseOpt1.factor),
22
+ };
23
+ }
24
+ const pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);
25
+ for (const p2 of query) {
26
+ if (p1 === p2 || p2.destroyed) {
27
+ continue;
28
+ }
29
+ const pos2 = p2.getPosition();
30
+ const { dx, dy, distance } = getDistances(pos2, pos1);
31
+ const velocity = p1.repulse.speed * p1.repulse.factor;
32
+ if (distance > 0) {
33
+ const repulseFactor = clamp((1 - Math.pow(distance / p1.repulse.distance, 2)) * velocity, 0, velocity);
34
+ const normVec = Vector.create((dx / distance) * repulseFactor, (dy / distance) * repulseFactor);
35
+ p2.position.addTo(normVec);
36
+ }
37
+ else {
38
+ const velocityVec = Vector.create(velocity, velocity);
39
+ p2.position.addTo(velocityVec);
40
+ }
41
+ }
42
+ }
43
+ isEnabled(particle) {
44
+ var _a, _b;
45
+ return (_b = (_a = particle.options.repulse) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
46
+ }
47
+ loadParticlesOptions(options, ...sources) {
48
+ if (!options.repulse) {
49
+ options.repulse = new ParticlesRepulse();
50
+ }
51
+ for (const source of sources) {
52
+ options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
53
+ }
54
+ }
55
+ reset() {
56
+ }
57
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { Repulser } from "./Repulser";
2
+ export function loadParticlesRepulseInteraction(engine) {
3
+ engine.addInteractor("particlesRepulse", (container) => new Repulser(container));
4
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParticlesRepulse = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class ParticlesRepulse extends engine_1.ValueWithRandom {
6
+ constructor() {
7
+ super();
8
+ this.enabled = false;
9
+ this.distance = 1;
10
+ this.duration = 1;
11
+ this.factor = 1;
12
+ this.speed = 1;
13
+ }
14
+ load(data) {
15
+ super.load(data);
16
+ if (!data) {
17
+ return;
18
+ }
19
+ if (data.enabled !== undefined) {
20
+ this.enabled = data.enabled;
21
+ }
22
+ if (data.distance !== undefined) {
23
+ this.distance = (0, engine_1.setRangeValue)(data.distance);
24
+ }
25
+ if (data.duration !== undefined) {
26
+ this.duration = (0, engine_1.setRangeValue)(data.duration);
27
+ }
28
+ if (data.factor !== undefined) {
29
+ this.factor = (0, engine_1.setRangeValue)(data.factor);
30
+ }
31
+ if (data.speed !== undefined) {
32
+ this.speed = (0, engine_1.setRangeValue)(data.speed);
33
+ }
34
+ }
35
+ }
36
+ exports.ParticlesRepulse = ParticlesRepulse;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Repulser = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const ParticlesRepulse_1 = require("./Options/Classes/ParticlesRepulse");
15
+ class Repulser extends engine_1.ParticlesInteractorBase {
16
+ constructor(container) {
17
+ super(container);
18
+ }
19
+ clear() {
20
+ }
21
+ init() {
22
+ }
23
+ interact(p1) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const container = this.container;
26
+ if (!p1.repulse) {
27
+ const repulseOpt1 = p1.options.repulse;
28
+ if (!repulseOpt1) {
29
+ return;
30
+ }
31
+ p1.repulse = {
32
+ distance: (0, engine_1.getRangeValue)(repulseOpt1.distance) * container.retina.pixelRatio,
33
+ speed: (0, engine_1.getRangeValue)(repulseOpt1.speed),
34
+ factor: (0, engine_1.getRangeValue)(repulseOpt1.factor),
35
+ };
36
+ }
37
+ const pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);
38
+ for (const p2 of query) {
39
+ if (p1 === p2 || p2.destroyed) {
40
+ continue;
41
+ }
42
+ const pos2 = p2.getPosition();
43
+ const { dx, dy, distance } = (0, engine_1.getDistances)(pos2, pos1);
44
+ const velocity = p1.repulse.speed * p1.repulse.factor;
45
+ if (distance > 0) {
46
+ const repulseFactor = (0, engine_1.clamp)((1 - Math.pow(distance / p1.repulse.distance, 2)) * velocity, 0, velocity);
47
+ const normVec = engine_1.Vector.create((dx / distance) * repulseFactor, (dy / distance) * repulseFactor);
48
+ p2.position.addTo(normVec);
49
+ }
50
+ else {
51
+ const velocityVec = engine_1.Vector.create(velocity, velocity);
52
+ p2.position.addTo(velocityVec);
53
+ }
54
+ }
55
+ });
56
+ }
57
+ isEnabled(particle) {
58
+ var _a, _b;
59
+ return (_b = (_a = particle.options.repulse) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
60
+ }
61
+ loadParticlesOptions(options, ...sources) {
62
+ if (!options.repulse) {
63
+ options.repulse = new ParticlesRepulse_1.ParticlesRepulse();
64
+ }
65
+ for (const source of sources) {
66
+ options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
67
+ }
68
+ }
69
+ reset() {
70
+ }
71
+ }
72
+ exports.Repulser = Repulser;
package/cjs/Types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadParticlesRepulseInteraction = void 0;
4
+ const Repulser_1 = require("./Repulser");
5
+ function loadParticlesRepulseInteraction(engine) {
6
+ engine.addInteractor("particlesRepulse", (container) => new Repulser_1.Repulser(container));
7
+ }
8
+ exports.loadParticlesRepulseInteraction = loadParticlesRepulseInteraction;
@@ -0,0 +1,32 @@
1
+ import { ValueWithRandom, setRangeValue } from "@tsparticles/engine";
2
+ export class ParticlesRepulse extends ValueWithRandom {
3
+ constructor() {
4
+ super();
5
+ this.enabled = false;
6
+ this.distance = 1;
7
+ this.duration = 1;
8
+ this.factor = 1;
9
+ this.speed = 1;
10
+ }
11
+ load(data) {
12
+ super.load(data);
13
+ if (!data) {
14
+ return;
15
+ }
16
+ if (data.enabled !== undefined) {
17
+ this.enabled = data.enabled;
18
+ }
19
+ if (data.distance !== undefined) {
20
+ this.distance = setRangeValue(data.distance);
21
+ }
22
+ if (data.duration !== undefined) {
23
+ this.duration = setRangeValue(data.duration);
24
+ }
25
+ if (data.factor !== undefined) {
26
+ this.factor = setRangeValue(data.factor);
27
+ }
28
+ if (data.speed !== undefined) {
29
+ this.speed = setRangeValue(data.speed);
30
+ }
31
+ }
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import { ParticlesInteractorBase, Vector, clamp, getDistances, getRangeValue } from "@tsparticles/engine";
2
+ import { ParticlesRepulse } from "./Options/Classes/ParticlesRepulse";
3
+ export class Repulser extends ParticlesInteractorBase {
4
+ constructor(container) {
5
+ super(container);
6
+ }
7
+ clear() {
8
+ }
9
+ init() {
10
+ }
11
+ async interact(p1) {
12
+ const container = this.container;
13
+ if (!p1.repulse) {
14
+ const repulseOpt1 = p1.options.repulse;
15
+ if (!repulseOpt1) {
16
+ return;
17
+ }
18
+ p1.repulse = {
19
+ distance: getRangeValue(repulseOpt1.distance) * container.retina.pixelRatio,
20
+ speed: getRangeValue(repulseOpt1.speed),
21
+ factor: getRangeValue(repulseOpt1.factor),
22
+ };
23
+ }
24
+ const pos1 = p1.getPosition(), query = container.particles.quadTree.queryCircle(pos1, p1.repulse.distance);
25
+ for (const p2 of query) {
26
+ if (p1 === p2 || p2.destroyed) {
27
+ continue;
28
+ }
29
+ const pos2 = p2.getPosition();
30
+ const { dx, dy, distance } = getDistances(pos2, pos1);
31
+ const velocity = p1.repulse.speed * p1.repulse.factor;
32
+ if (distance > 0) {
33
+ const repulseFactor = clamp((1 - Math.pow(distance / p1.repulse.distance, 2)) * velocity, 0, velocity);
34
+ const normVec = Vector.create((dx / distance) * repulseFactor, (dy / distance) * repulseFactor);
35
+ p2.position.addTo(normVec);
36
+ }
37
+ else {
38
+ const velocityVec = Vector.create(velocity, velocity);
39
+ p2.position.addTo(velocityVec);
40
+ }
41
+ }
42
+ }
43
+ isEnabled(particle) {
44
+ var _a, _b;
45
+ return (_b = (_a = particle.options.repulse) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false;
46
+ }
47
+ loadParticlesOptions(options, ...sources) {
48
+ if (!options.repulse) {
49
+ options.repulse = new ParticlesRepulse();
50
+ }
51
+ for (const source of sources) {
52
+ options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
53
+ }
54
+ }
55
+ reset() {
56
+ }
57
+ }
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { Repulser } from "./Repulser";
2
+ export function loadParticlesRepulseInteraction(engine) {
3
+ engine.addInteractor("particlesRepulse", (container) => new Repulser(container));
4
+ }
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@tsparticles/interaction-particles-repulse",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles repulse particles interaction",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "interactions/particles/repulse"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin",
64
+ "@tsparticles/interaction"
65
+ ],
66
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
67
+ "license": "MIT",
68
+ "bugs": {
69
+ "url": "https://github.com/matteobruni/tsparticles/issues"
70
+ },
71
+ "funding": [
72
+ {
73
+ "type": "github",
74
+ "url": "https://github.com/sponsors/matteobruni"
75
+ },
76
+ {
77
+ "type": "buymeacoffee",
78
+ "url": "https://www.buymeacoffee.com/matteobruni"
79
+ }
80
+ ],
81
+ "main": "cjs/index.js",
82
+ "jsdelivr": "tsparticles.interaction.particles.repulse.min.js",
83
+ "unpkg": "tsparticles.interaction.particles.repulse.min.js",
84
+ "module": "esm/index.js",
85
+ "types": "types/index.d.ts",
86
+ "publishConfig": {
87
+ "access": "public"
88
+ },
89
+ "dependencies": {
90
+ "@tsparticles/engine": "^3.0.0-alpha.0"
91
+ }
92
+ }