@tsparticles/interaction-external-repulse 3.0.3 → 3.2.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/858.min.js +2 -0
- package/858.min.js.LICENSE.txt +1 -0
- package/browser/Repulser.js +14 -13
- package/browser/index.js +4 -2
- package/cjs/Repulser.js +13 -12
- package/cjs/index.js +16 -2
- package/dist_browser_Repulser_js.js +30 -0
- package/esm/Repulser.js +14 -13
- package/esm/index.js +4 -2
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.interaction.external.repulse.js +271 -311
- package/tsparticles.interaction.external.repulse.min.js +1 -1
- package/tsparticles.interaction.external.repulse.min.js.LICENSE.txt +1 -1
- package/types/Types.d.ts +4 -4
- package/umd/Repulser.js +13 -12
- package/umd/index.js +18 -3
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.interaction.external.repulse.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
|
|
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=>(()=>{var t,r,o={378:(e,t,r)=>{r.d(t,{H:()=>a});var o=r(533),i=r(960),n=r(772);class a extends i.H{load(e){super.load(e),e&&(this.divs=(0,o.executeOnSingleOrMultiple)(e.divs,(e=>{const t=new n.z;return t.load(e),t})))}}},960:(e,t,r)=>{r.d(t,{H:()=>o});class o{constructor(){this.distance=200,this.duration=.4,this.factor=100,this.speed=1,this.maxSpeed=50,this.easing="ease-out-quad"}load(e){e&&(void 0!==e.distance&&(this.distance=e.distance),void 0!==e.duration&&(this.duration=e.duration),void 0!==e.easing&&(this.easing=e.easing),void 0!==e.factor&&(this.factor=e.factor),void 0!==e.speed&&(this.speed=e.speed),void 0!==e.maxSpeed&&(this.maxSpeed=e.maxSpeed))}}},772:(e,t,r)=>{r.d(t,{z:()=>i});var o=r(960);class i extends o.H{constructor(){super(),this.selectors=[]}load(e){super.load(e),e&&void 0!==e.selectors&&(this.selectors=e.selectors)}}},533:t=>{t.exports=e}},i={};function n(e){var t=i[e];if(void 0!==t)return t.exports;var r=i[e]={exports:{}};return o[e](r,r.exports,n),r.exports}n.m=o,n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".min.js",n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/interaction-external-repulse:",n.l=(e,o,i,a)=>{if(t[e])t[e].push(o);else{var s,l;if(void 0!==i)for(var d=document.getElementsByTagName("script"),c=0;c<d.length;c++){var u=d[c];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==r+i){s=u;break}}s||(l=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,n.nc&&s.setAttribute("nonce",n.nc),s.setAttribute("data-webpack",r+i),s.src=e),t[e]=[o];var p=(r,o)=>{s.onerror=s.onload=null,clearTimeout(f);var i=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),i&&i.forEach((e=>e(o))),r)return r(o)},f=setTimeout(p.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=p.bind(null,s.onerror),s.onload=p.bind(null,s.onload),l&&document.head.appendChild(s)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;n.g.importScripts&&(e=n.g.location+"");var t=n.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&!e;)e=r[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{var e={920:0};n.f.j=(t,r)=>{var o=n.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var i=new Promise(((r,i)=>o=e[t]=[r,i]));r.push(o[2]=i);var a=n.p+n.u(t),s=new Error;n.l(a,(r=>{if(n.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",s.name="ChunkLoadError",s.type=i,s.request=a,o[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var o,i,a=r[0],s=r[1],l=r[2],d=0;if(a.some((t=>0!==e[t]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(l)l(n)}for(t&&t(r);d<a.length;d++)i=a[d],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=this.webpackChunk_tsparticles_interaction_external_repulse=this.webpackChunk_tsparticles_interaction_external_repulse||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};return(()=>{n.r(a),n.d(a,{Repulse:()=>r.H,RepulseBase:()=>e.H,RepulseDiv:()=>t.z,loadExternalRepulseInteraction:()=>o});var e=n(960),t=n(772),r=n(378);async function o(e,t=!0){await e.addInteractor("externalRepulse",(async t=>{const{Repulser:r}=await n.e(858).then(n.bind(n,858));return new r(e,t)}),t)}})(),a})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Repulse External Interaction v3.0
|
|
1
|
+
/*! tsParticles Repulse External Interaction v3.2.0 by Matteo Bruni */
|
package/types/Types.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ import type { Container, Particle } from "@tsparticles/engine";
|
|
|
2
2
|
import type { IRepulse } from "./Options/Interfaces/IRepulse.js";
|
|
3
3
|
import type { Repulse } from "./Options/Classes/Repulse.js";
|
|
4
4
|
import type { RepulseOptions } from "./Options/Classes/RepulseOptions.js";
|
|
5
|
-
export
|
|
5
|
+
export interface IRepulseMode {
|
|
6
6
|
repulse: IRepulse;
|
|
7
|
-
}
|
|
8
|
-
export
|
|
7
|
+
}
|
|
8
|
+
export interface RepulseMode {
|
|
9
9
|
repulse?: Repulse;
|
|
10
|
-
}
|
|
10
|
+
}
|
|
11
11
|
interface IContainerRepulse {
|
|
12
12
|
clicking?: boolean;
|
|
13
13
|
count?: number;
|
package/umd/Repulser.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
exports.Repulser = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
14
|
const Repulse_js_1 = require("./Options/Classes/Repulse.js");
|
|
15
|
-
const repulseMode = "repulse";
|
|
15
|
+
const repulseMode = "repulse", minDistance = 0, repulseRadiusFactor = 6, repulseRadiusPower = 3, squarePower = 2, minRadius = 0, minSpeed = 0, easingOffset = 1, half = 0.5;
|
|
16
16
|
class Repulser extends engine_1.ExternalInteractorBase {
|
|
17
17
|
constructor(engine, container) {
|
|
18
18
|
super(container);
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
if (!repulseOptions) {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
const repulse = container.repulse
|
|
24
|
+
const repulse = container.repulse ?? { particles: [] };
|
|
25
25
|
if (!repulse.finish) {
|
|
26
26
|
if (!repulse.count) {
|
|
27
27
|
repulse.count = 0;
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
}
|
|
34
34
|
if (repulse.clicking) {
|
|
35
35
|
const repulseDistance = container.retina.repulseModeDistance;
|
|
36
|
-
if (!repulseDistance || repulseDistance <
|
|
36
|
+
if (!repulseDistance || repulseDistance < minDistance) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
const repulseRadius = Math.pow(repulseDistance /
|
|
39
|
+
const repulseRadius = Math.pow(repulseDistance / repulseRadiusFactor, repulseRadiusPower), mouseClickPos = container.interactivity.mouse.clickPosition;
|
|
40
40
|
if (mouseClickPos === undefined) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
const range = new engine_1.Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius), query = container.particles.quadTree.query(range, (p) => this.isEnabled(p));
|
|
44
44
|
for (const particle of query) {
|
|
45
|
-
const { dx, dy, distance } = (0, engine_1.getDistances)(mouseClickPos, particle.position), d = distance **
|
|
45
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(mouseClickPos, particle.position), d = distance ** squarePower, velocity = repulseOptions.speed, force = (-repulseRadius * velocity) / d;
|
|
46
46
|
if (d <= repulseRadius) {
|
|
47
47
|
repulse.particles.push(particle);
|
|
48
48
|
const vect = engine_1.Vector.create(dx, dy);
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
};
|
|
61
61
|
this._hoverRepulse = () => {
|
|
62
62
|
const container = this.container, mousePos = container.interactivity.mouse.position, repulseRadius = container.retina.repulseModeDistance;
|
|
63
|
-
if (!repulseRadius || repulseRadius <
|
|
63
|
+
if (!repulseRadius || repulseRadius < minRadius || !mousePos) {
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
66
|
this._processRepulse(mousePos, repulseRadius, new engine_1.Circle(mousePos.x, mousePos.y, repulseRadius));
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
}
|
|
73
73
|
const { easing, speed, factor, maxSpeed } = repulseOptions, easingFunc = (0, engine_1.getEasing)(easing), velocity = (divRepulse?.speed ?? speed) * factor;
|
|
74
74
|
for (const particle of query) {
|
|
75
|
-
const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), repulseFactor = (0, engine_1.clamp)(easingFunc(
|
|
75
|
+
const { dx, dy, distance } = (0, engine_1.getDistances)(particle.position, position), repulseFactor = (0, engine_1.clamp)(easingFunc(easingOffset - distance / repulseRadius) * velocity, minSpeed, maxSpeed), normVec = engine_1.Vector.create(!distance ? velocity : (dx / distance) * repulseFactor, !distance ? velocity : (dy / distance) * repulseFactor);
|
|
76
76
|
particle.position.addTo(normVec);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
@@ -87,9 +87,9 @@
|
|
|
87
87
|
}
|
|
88
88
|
query.forEach((item) => {
|
|
89
89
|
const elem = item, pxRatio = container.retina.pixelRatio, pos = {
|
|
90
|
-
x: (elem.offsetLeft + elem.offsetWidth
|
|
91
|
-
y: (elem.offsetTop + elem.offsetHeight
|
|
92
|
-
}, repulseRadius =
|
|
90
|
+
x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
|
|
91
|
+
y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
|
|
92
|
+
}, repulseRadius = elem.offsetWidth * half * pxRatio, area = div.type === "circle"
|
|
93
93
|
? new engine_1.Circle(pos.x, pos.y, repulseRadius)
|
|
94
94
|
: new engine_1.Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio), divs = repulse.divs, divRepulse = (0, engine_1.divMode)(divs, elem);
|
|
95
95
|
this._processRepulse(pos, repulseRadius, area, divRepulse);
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
repulse.clicking = false;
|
|
126
|
-
}, repulseOpts.duration *
|
|
126
|
+
}, repulseOpts.duration * engine_1.millisecondsToSeconds);
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
clear() {
|
|
@@ -146,10 +146,11 @@
|
|
|
146
146
|
else {
|
|
147
147
|
(0, engine_1.divModeExecute)(repulseMode, divs, (selector, div) => this._singleSelectorRepulse(selector, div));
|
|
148
148
|
}
|
|
149
|
+
await Promise.resolve();
|
|
149
150
|
}
|
|
150
151
|
isEnabled(particle) {
|
|
151
152
|
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv, hover = events.onHover, click = events.onClick, divRepulse = (0, engine_1.isDivModeEnabled)(repulseMode, divs);
|
|
152
|
-
if (!(divRepulse || (hover.enable && mouse.position) || (click.enable && mouse.clickPosition))) {
|
|
153
|
+
if (!(divRepulse || (hover.enable && !!mouse.position) || (click.enable && mouse.clickPosition))) {
|
|
153
154
|
return false;
|
|
154
155
|
}
|
|
155
156
|
const hoverMode = hover.mode, clickMode = click.mode;
|
package/umd/index.js
CHANGED
|
@@ -9,6 +9,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
9
9
|
if (k2 === undefined) k2 = k;
|
|
10
10
|
o[k2] = m[k];
|
|
11
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 (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
12
24
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
25
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
26
|
};
|
|
@@ -18,15 +30,18 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
30
|
if (v !== undefined) module.exports = v;
|
|
19
31
|
}
|
|
20
32
|
else if (typeof define === "function" && define.amd) {
|
|
21
|
-
define(["require", "exports", "./
|
|
33
|
+
define(["require", "exports", "./Options/Classes/RepulseBase.js", "./Options/Classes/RepulseDiv.js", "./Options/Classes/Repulse.js", "./Options/Interfaces/IRepulseBase.js", "./Options/Interfaces/IRepulseDiv.js", "./Options/Interfaces/IRepulse.js"], factory);
|
|
22
34
|
}
|
|
23
35
|
})(function (require, exports) {
|
|
24
36
|
"use strict";
|
|
37
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
25
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
39
|
exports.loadExternalRepulseInteraction = void 0;
|
|
27
|
-
const Repulser_js_1 = require("./Repulser.js");
|
|
28
40
|
async function loadExternalRepulseInteraction(engine, refresh = true) {
|
|
29
|
-
await engine.addInteractor("externalRepulse", (container) =>
|
|
41
|
+
await engine.addInteractor("externalRepulse", async (container) => {
|
|
42
|
+
const { Repulser } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./Repulser.js"))) : new Promise((resolve_1, reject_1) => { require(["./Repulser.js"], resolve_1, reject_1); }).then(__importStar));
|
|
43
|
+
return new Repulser(engine, container);
|
|
44
|
+
}, refresh);
|
|
30
45
|
}
|
|
31
46
|
exports.loadExternalRepulseInteraction = loadExternalRepulseInteraction;
|
|
32
47
|
__exportStar(require("./Options/Classes/RepulseBase.js"), exports);
|