@tsparticles/interaction-external-trail 4.0.0-alpha.5 → 4.0.0-beta.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/983.min.js +1 -0
- package/README.md +5 -0
- package/browser/Options/Classes/Trail.js +14 -4
- package/browser/Options/Classes/TrailColorComponent.js +21 -0
- package/browser/Options/Classes/TrailColorCoords.js +28 -0
- package/browser/Options/Classes/TrailColorWeight.js +19 -0
- package/browser/Options/Interfaces/ITrailColorComponent.js +1 -0
- package/browser/Options/Interfaces/ITrailColorCoords.js +1 -0
- package/browser/Options/Interfaces/ITrailColorWeight.js +1 -0
- package/browser/TrailMaker.js +44 -15
- package/browser/index.js +4 -4
- package/cjs/Options/Classes/Trail.js +14 -4
- package/cjs/Options/Classes/TrailColorComponent.js +21 -0
- package/cjs/Options/Classes/TrailColorCoords.js +28 -0
- package/cjs/Options/Classes/TrailColorWeight.js +19 -0
- package/cjs/Options/Interfaces/ITrailColorComponent.js +1 -0
- package/cjs/Options/Interfaces/ITrailColorCoords.js +1 -0
- package/cjs/Options/Interfaces/ITrailColorWeight.js +1 -0
- package/cjs/TrailMaker.js +44 -15
- package/cjs/index.js +4 -4
- package/dist_browser_TrailMaker_js.js +2 -2
- package/esm/Options/Classes/Trail.js +14 -4
- package/esm/Options/Classes/TrailColorComponent.js +21 -0
- package/esm/Options/Classes/TrailColorCoords.js +28 -0
- package/esm/Options/Classes/TrailColorWeight.js +19 -0
- package/esm/Options/Interfaces/ITrailColorComponent.js +1 -0
- package/esm/Options/Interfaces/ITrailColorCoords.js +1 -0
- package/esm/Options/Interfaces/ITrailColorWeight.js +1 -0
- package/esm/TrailMaker.js +44 -15
- package/esm/index.js +4 -4
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.interaction.external.trail.js +69 -27
- package/tsparticles.interaction.external.trail.min.js +2 -2
- package/types/Options/Classes/Trail.d.ts +2 -0
- package/types/Options/Classes/TrailColorComponent.d.ts +9 -0
- package/types/Options/Classes/TrailColorCoords.d.ts +10 -0
- package/types/Options/Classes/TrailColorWeight.d.ts +8 -0
- package/types/Options/Interfaces/ITrail.d.ts +2 -0
- package/types/Options/Interfaces/ITrailColorComponent.d.ts +6 -0
- package/types/Options/Interfaces/ITrailColorCoords.d.ts +6 -0
- package/types/Options/Interfaces/ITrailColorWeight.d.ts +4 -0
- package/types/TrailMaker.d.ts +4 -2
- package/types/index.d.ts +3 -0
- package/umd/Options/Classes/Trail.js +15 -5
- package/umd/Options/Classes/TrailColorComponent.js +35 -0
- package/umd/Options/Classes/TrailColorCoords.js +42 -0
- package/umd/Options/Classes/TrailColorWeight.js +33 -0
- package/umd/Options/Interfaces/ITrailColorComponent.js +12 -0
- package/umd/Options/Interfaces/ITrailColorCoords.js +12 -0
- package/umd/Options/Interfaces/ITrailColorWeight.js +12 -0
- package/umd/TrailMaker.js +45 -16
- package/umd/index.js +4 -4
- package/323.min.js +0 -2
- package/323.min.js.LICENSE.txt +0 -1
- package/tsparticles.interaction.external.trail.min.js.LICENSE.txt +0 -1
package/983.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(this.webpackChunk_tsparticles_interaction_external_trail=this.webpackChunk_tsparticles_interaction_external_trail||[]).push([[983],{983(t,i,e){e.d(i,{TrailMaker:()=>r});var a=e(303),s=e(702),l=e(170);let n="trail";class r extends s.ExternalInteractorBase{maxDistance=0;_delay;_engine;_lastPosition;constructor(t,i){super(i),this._engine=t,this._delay=0}clear(){}init(){}interact(t,i){let e=this.container;if(!e.retina.reduceFactor)return;let s=e.actualOptions,l=s.interactivity?.modes.trail;if(!l)return;let n=l.delay*a.millisecondsToSeconds/this.container.retina.reduceFactor;if(this._delay<n&&(this._delay+=i.value),this._delay<n)return;let r=t.mouse.position,o=!(l.pauseOnStop&&(r===this._lastPosition||r?.x===this._lastPosition?.x&&r?.y===this._lastPosition?.y));if(r?this._lastPosition={...r}:delete this._lastPosition,o&&r){let t=l.particles,i=l.colorCoords;if(i){let{width:s,height:n}=e.canvas.size,o={x:r.x/s,y:r.y/n},c=(t,i,e)=>{if(!(t?.weights?.x??t?.weights?.y))return;let s=t?.weights,l=o.x*(s?.x??0)+o.y*(s?.y??0),n=t?.value??i,r=(0,a.getRangeMin)(n??0),c=(0,a.getRangeMax)(n??e);return Math.min(c,Math.max(r,r+l*(c-r)))},d=l.particles?.fill?(0,a.itemFromSingleOrMultiple)(l.particles.fill):void 0,h=d?(0,a.rangeColorToHsl)(this._engine,a.AnimatableColor.create(void 0,d.color)):void 0,u=c(i.h,h?.h,a.hMax),_=c(i.s,h?.s,a.sMax),p=c(i.l,h?.l,a.lMax);(void 0!==u||void 0!==_||void 0!==p)&&(t=(0,a.deepExtend)({},l.particles,{color:{value:{h:u??h?.h,s:_??h?.s,l:p??h?.l}}}))}e.particles.push(l.quantity,r,t)}this._delay-=n}isEnabled(t,i){let e=this.container.actualOptions,s=t.mouse,l=(i?.interactivity??e.interactivity)?.events;return!!l&&(s.clicking&&s.inside&&!!s.position&&(0,a.isInArray)(n,l.onClick.mode)||s.inside&&!!s.position&&(0,a.isInArray)(n,l.onHover.mode))}loadModeOptions(t,...i){for(let e of(t.trail??=new l.X,i))t.trail.load(e?.trail)}reset(){}}}}]);
|
package/README.md
CHANGED
|
@@ -28,6 +28,7 @@ Once the scripts are loaded you can set up `tsParticles` and the interaction plu
|
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
30
|
(async () => {
|
|
31
|
+
await loadInteractivityPlugin(tsParticles);
|
|
31
32
|
await loadExternalTrailInteraction(tsParticles);
|
|
32
33
|
|
|
33
34
|
await tsParticles.load({
|
|
@@ -57,9 +58,11 @@ Then you need to import it in the app, like this:
|
|
|
57
58
|
|
|
58
59
|
```javascript
|
|
59
60
|
const { tsParticles } = require("@tsparticles/engine");
|
|
61
|
+
const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
|
|
60
62
|
const { loadExternalTrailInteraction } = require("@tsparticles/interaction-external-trail");
|
|
61
63
|
|
|
62
64
|
(async () => {
|
|
65
|
+
await loadInteractivityPlugin(tsParticles);
|
|
63
66
|
await loadExternalTrailInteraction(tsParticles);
|
|
64
67
|
})();
|
|
65
68
|
```
|
|
@@ -68,9 +71,11 @@ or
|
|
|
68
71
|
|
|
69
72
|
```javascript
|
|
70
73
|
import { tsParticles } from "@tsparticles/engine";
|
|
74
|
+
import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
|
|
71
75
|
import { loadExternalTrailInteraction } from "@tsparticles/interaction-external-trail";
|
|
72
76
|
|
|
73
77
|
(async () => {
|
|
78
|
+
await loadInteractivityPlugin(tsParticles);
|
|
74
79
|
await loadExternalTrailInteraction(tsParticles);
|
|
75
80
|
})();
|
|
76
81
|
```
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorCoords } from "./TrailColorCoords.js";
|
|
2
3
|
export class Trail {
|
|
4
|
+
colorCoords;
|
|
5
|
+
delay;
|
|
6
|
+
particles;
|
|
7
|
+
pauseOnStop;
|
|
8
|
+
quantity;
|
|
3
9
|
constructor() {
|
|
4
10
|
this.delay = 1;
|
|
5
11
|
this.pauseOnStop = false;
|
|
6
12
|
this.quantity = 1;
|
|
13
|
+
this.colorCoords = new TrailColorCoords();
|
|
7
14
|
}
|
|
8
15
|
load(data) {
|
|
9
|
-
if (isNull(data))
|
|
16
|
+
if (isNull(data))
|
|
10
17
|
return;
|
|
11
|
-
}
|
|
12
18
|
if (data.delay !== undefined) {
|
|
13
19
|
this.delay = data.delay;
|
|
14
20
|
}
|
|
15
21
|
if (data.quantity !== undefined) {
|
|
16
22
|
this.quantity = data.quantity;
|
|
17
23
|
}
|
|
24
|
+
if (data.pauseOnStop !== undefined) {
|
|
25
|
+
this.pauseOnStop = data.pauseOnStop;
|
|
26
|
+
}
|
|
18
27
|
if (data.particles !== undefined) {
|
|
19
28
|
this.particles = deepExtend({}, data.particles);
|
|
20
29
|
}
|
|
21
|
-
if (data.
|
|
22
|
-
this.
|
|
30
|
+
if (data.colorCoords) {
|
|
31
|
+
this.colorCoords ??= new TrailColorCoords();
|
|
32
|
+
this.colorCoords.load(data.colorCoords);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isNull, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorWeight } from "./TrailColorWeight.js";
|
|
3
|
+
export class TrailColorComponent {
|
|
4
|
+
value;
|
|
5
|
+
weights;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.weights = new TrailColorWeight();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.weights) {
|
|
14
|
+
this.weights ??= new TrailColorWeight();
|
|
15
|
+
this.weights.load(data.weights);
|
|
16
|
+
}
|
|
17
|
+
if (!isNull(data.value)) {
|
|
18
|
+
this.value = setRangeValue(data.value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TrailColorComponent } from "./TrailColorComponent.js";
|
|
2
|
+
export class TrailColorCoords {
|
|
3
|
+
h;
|
|
4
|
+
l;
|
|
5
|
+
s;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.h = new TrailColorComponent();
|
|
8
|
+
this.s = new TrailColorComponent();
|
|
9
|
+
this.l = new TrailColorComponent();
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.h) {
|
|
16
|
+
this.h ??= new TrailColorComponent();
|
|
17
|
+
this.h.load(data.h);
|
|
18
|
+
}
|
|
19
|
+
if (data.s) {
|
|
20
|
+
this.s ??= new TrailColorComponent();
|
|
21
|
+
this.s.load(data.s);
|
|
22
|
+
}
|
|
23
|
+
if (data.l) {
|
|
24
|
+
this.l ??= new TrailColorComponent();
|
|
25
|
+
this.l.load(data.l);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class TrailColorWeight {
|
|
2
|
+
x;
|
|
3
|
+
y;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.x = 0;
|
|
6
|
+
this.y = 0;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.x !== undefined) {
|
|
13
|
+
this.x = data.x;
|
|
14
|
+
}
|
|
15
|
+
if (data.y !== undefined) {
|
|
16
|
+
this.y = data.y;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/browser/TrailMaker.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { AnimatableColor, deepExtend, getRangeMax, getRangeMin, hMax, isInArray, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, rangeColorToHsl, sMax, } from "@tsparticles/engine";
|
|
1
2
|
import { ExternalInteractorBase, } from "@tsparticles/plugin-interactivity";
|
|
2
|
-
import { isInArray, millisecondsToSeconds, } from "@tsparticles/engine";
|
|
3
3
|
import { Trail } from "./Options/Classes/Trail.js";
|
|
4
|
-
const trailMode = "trail";
|
|
4
|
+
const trailMode = "trail", defaultMin = 0, defaultWeight = 0;
|
|
5
5
|
export class TrailMaker extends ExternalInteractorBase {
|
|
6
|
-
|
|
6
|
+
maxDistance = 0;
|
|
7
|
+
_delay;
|
|
8
|
+
_engine;
|
|
9
|
+
_lastPosition;
|
|
10
|
+
constructor(engine, container) {
|
|
7
11
|
super(container);
|
|
12
|
+
this._engine = engine;
|
|
8
13
|
this._delay = 0;
|
|
9
14
|
}
|
|
10
15
|
clear() {
|
|
@@ -13,32 +18,56 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
13
18
|
}
|
|
14
19
|
interact(interactivityData, delta) {
|
|
15
20
|
const container = this.container;
|
|
16
|
-
if (!container.retina.reduceFactor)
|
|
21
|
+
if (!container.retina.reduceFactor)
|
|
17
22
|
return;
|
|
18
|
-
}
|
|
19
23
|
const options = container.actualOptions, trailOptions = options.interactivity?.modes.trail;
|
|
20
|
-
if (!trailOptions)
|
|
24
|
+
if (!trailOptions)
|
|
21
25
|
return;
|
|
22
|
-
}
|
|
23
26
|
const optDelay = (trailOptions.delay * millisecondsToSeconds) / this.container.retina.reduceFactor;
|
|
24
27
|
if (this._delay < optDelay) {
|
|
25
28
|
this._delay += delta.value;
|
|
26
29
|
}
|
|
27
|
-
if (this._delay < optDelay)
|
|
30
|
+
if (this._delay < optDelay)
|
|
28
31
|
return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(interactivityData.mouse.position?.x === this._lastPosition?.x &&
|
|
33
|
-
interactivityData.mouse.position?.y === this._lastPosition?.y))), mousePos = interactivityData.mouse.position;
|
|
32
|
+
const mousePos = interactivityData.mouse.position, canEmit = !(trailOptions.pauseOnStop &&
|
|
33
|
+
(mousePos === this._lastPosition ||
|
|
34
|
+
(mousePos?.x === this._lastPosition?.x && mousePos?.y === this._lastPosition?.y)));
|
|
34
35
|
if (mousePos) {
|
|
35
36
|
this._lastPosition = { ...mousePos };
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
delete this._lastPosition;
|
|
39
40
|
}
|
|
40
|
-
if (canEmit) {
|
|
41
|
-
|
|
41
|
+
if (canEmit && mousePos) {
|
|
42
|
+
let particleOptions = trailOptions.particles;
|
|
43
|
+
const colorCoords = trailOptions.colorCoords;
|
|
44
|
+
if (colorCoords) {
|
|
45
|
+
const { width, height } = container.canvas.size, norm = {
|
|
46
|
+
x: mousePos.x / width,
|
|
47
|
+
y: mousePos.y / height,
|
|
48
|
+
}, hasWeights = (comp) => {
|
|
49
|
+
return !!(comp?.weights?.x ?? comp?.weights?.y);
|
|
50
|
+
}, calculateValue = (comp, originalValue, defaultMax) => {
|
|
51
|
+
if (!hasWeights(comp))
|
|
52
|
+
return undefined;
|
|
53
|
+
const w = comp?.weights, factor = norm.x * (w?.x ?? defaultWeight) + norm.y * (w?.y ?? defaultWeight), rangeSource = comp?.value ?? originalValue, min = getRangeMin(rangeSource ?? defaultMin), max = getRangeMax(rangeSource ?? defaultMax), result = min + factor * (max - min);
|
|
54
|
+
return Math.min(max, Math.max(min, result));
|
|
55
|
+
}, fillData = trailOptions.particles?.fill ? itemFromSingleOrMultiple(trailOptions.particles.fill) : undefined, baseHsl = fillData
|
|
56
|
+
? rangeColorToHsl(this._engine, AnimatableColor.create(undefined, fillData.color))
|
|
57
|
+
: undefined, h = calculateValue(colorCoords.h, baseHsl?.h, hMax), s = calculateValue(colorCoords.s, baseHsl?.s, sMax), l = calculateValue(colorCoords.l, baseHsl?.l, lMax);
|
|
58
|
+
if (h !== undefined || s !== undefined || l !== undefined) {
|
|
59
|
+
particleOptions = deepExtend({}, trailOptions.particles, {
|
|
60
|
+
color: {
|
|
61
|
+
value: {
|
|
62
|
+
h: h ?? baseHsl?.h,
|
|
63
|
+
s: s ?? baseHsl?.s,
|
|
64
|
+
l: l ?? baseHsl?.l,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
container.particles.push(trailOptions.quantity, mousePos, particleOptions);
|
|
42
71
|
}
|
|
43
72
|
this._delay -= optDelay;
|
|
44
73
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export async function loadExternalTrailInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("externalTrail", async (container) => {
|
|
7
7
|
const { TrailMaker } = await import("./TrailMaker.js");
|
|
8
|
-
return new TrailMaker(container);
|
|
8
|
+
return new TrailMaker(e, container);
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
}
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorCoords } from "./TrailColorCoords.js";
|
|
2
3
|
export class Trail {
|
|
4
|
+
colorCoords;
|
|
5
|
+
delay;
|
|
6
|
+
particles;
|
|
7
|
+
pauseOnStop;
|
|
8
|
+
quantity;
|
|
3
9
|
constructor() {
|
|
4
10
|
this.delay = 1;
|
|
5
11
|
this.pauseOnStop = false;
|
|
6
12
|
this.quantity = 1;
|
|
13
|
+
this.colorCoords = new TrailColorCoords();
|
|
7
14
|
}
|
|
8
15
|
load(data) {
|
|
9
|
-
if (isNull(data))
|
|
16
|
+
if (isNull(data))
|
|
10
17
|
return;
|
|
11
|
-
}
|
|
12
18
|
if (data.delay !== undefined) {
|
|
13
19
|
this.delay = data.delay;
|
|
14
20
|
}
|
|
15
21
|
if (data.quantity !== undefined) {
|
|
16
22
|
this.quantity = data.quantity;
|
|
17
23
|
}
|
|
24
|
+
if (data.pauseOnStop !== undefined) {
|
|
25
|
+
this.pauseOnStop = data.pauseOnStop;
|
|
26
|
+
}
|
|
18
27
|
if (data.particles !== undefined) {
|
|
19
28
|
this.particles = deepExtend({}, data.particles);
|
|
20
29
|
}
|
|
21
|
-
if (data.
|
|
22
|
-
this.
|
|
30
|
+
if (data.colorCoords) {
|
|
31
|
+
this.colorCoords ??= new TrailColorCoords();
|
|
32
|
+
this.colorCoords.load(data.colorCoords);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isNull, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorWeight } from "./TrailColorWeight.js";
|
|
3
|
+
export class TrailColorComponent {
|
|
4
|
+
value;
|
|
5
|
+
weights;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.weights = new TrailColorWeight();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.weights) {
|
|
14
|
+
this.weights ??= new TrailColorWeight();
|
|
15
|
+
this.weights.load(data.weights);
|
|
16
|
+
}
|
|
17
|
+
if (!isNull(data.value)) {
|
|
18
|
+
this.value = setRangeValue(data.value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TrailColorComponent } from "./TrailColorComponent.js";
|
|
2
|
+
export class TrailColorCoords {
|
|
3
|
+
h;
|
|
4
|
+
l;
|
|
5
|
+
s;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.h = new TrailColorComponent();
|
|
8
|
+
this.s = new TrailColorComponent();
|
|
9
|
+
this.l = new TrailColorComponent();
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.h) {
|
|
16
|
+
this.h ??= new TrailColorComponent();
|
|
17
|
+
this.h.load(data.h);
|
|
18
|
+
}
|
|
19
|
+
if (data.s) {
|
|
20
|
+
this.s ??= new TrailColorComponent();
|
|
21
|
+
this.s.load(data.s);
|
|
22
|
+
}
|
|
23
|
+
if (data.l) {
|
|
24
|
+
this.l ??= new TrailColorComponent();
|
|
25
|
+
this.l.load(data.l);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class TrailColorWeight {
|
|
2
|
+
x;
|
|
3
|
+
y;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.x = 0;
|
|
6
|
+
this.y = 0;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.x !== undefined) {
|
|
13
|
+
this.x = data.x;
|
|
14
|
+
}
|
|
15
|
+
if (data.y !== undefined) {
|
|
16
|
+
this.y = data.y;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/cjs/TrailMaker.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { AnimatableColor, deepExtend, getRangeMax, getRangeMin, hMax, isInArray, itemFromSingleOrMultiple, lMax, millisecondsToSeconds, rangeColorToHsl, sMax, } from "@tsparticles/engine";
|
|
1
2
|
import { ExternalInteractorBase, } from "@tsparticles/plugin-interactivity";
|
|
2
|
-
import { isInArray, millisecondsToSeconds, } from "@tsparticles/engine";
|
|
3
3
|
import { Trail } from "./Options/Classes/Trail.js";
|
|
4
|
-
const trailMode = "trail";
|
|
4
|
+
const trailMode = "trail", defaultMin = 0, defaultWeight = 0;
|
|
5
5
|
export class TrailMaker extends ExternalInteractorBase {
|
|
6
|
-
|
|
6
|
+
maxDistance = 0;
|
|
7
|
+
_delay;
|
|
8
|
+
_engine;
|
|
9
|
+
_lastPosition;
|
|
10
|
+
constructor(engine, container) {
|
|
7
11
|
super(container);
|
|
12
|
+
this._engine = engine;
|
|
8
13
|
this._delay = 0;
|
|
9
14
|
}
|
|
10
15
|
clear() {
|
|
@@ -13,32 +18,56 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
13
18
|
}
|
|
14
19
|
interact(interactivityData, delta) {
|
|
15
20
|
const container = this.container;
|
|
16
|
-
if (!container.retina.reduceFactor)
|
|
21
|
+
if (!container.retina.reduceFactor)
|
|
17
22
|
return;
|
|
18
|
-
}
|
|
19
23
|
const options = container.actualOptions, trailOptions = options.interactivity?.modes.trail;
|
|
20
|
-
if (!trailOptions)
|
|
24
|
+
if (!trailOptions)
|
|
21
25
|
return;
|
|
22
|
-
}
|
|
23
26
|
const optDelay = (trailOptions.delay * millisecondsToSeconds) / this.container.retina.reduceFactor;
|
|
24
27
|
if (this._delay < optDelay) {
|
|
25
28
|
this._delay += delta.value;
|
|
26
29
|
}
|
|
27
|
-
if (this._delay < optDelay)
|
|
30
|
+
if (this._delay < optDelay)
|
|
28
31
|
return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
(interactivityData.mouse.position?.x === this._lastPosition?.x &&
|
|
33
|
-
interactivityData.mouse.position?.y === this._lastPosition?.y))), mousePos = interactivityData.mouse.position;
|
|
32
|
+
const mousePos = interactivityData.mouse.position, canEmit = !(trailOptions.pauseOnStop &&
|
|
33
|
+
(mousePos === this._lastPosition ||
|
|
34
|
+
(mousePos?.x === this._lastPosition?.x && mousePos?.y === this._lastPosition?.y)));
|
|
34
35
|
if (mousePos) {
|
|
35
36
|
this._lastPosition = { ...mousePos };
|
|
36
37
|
}
|
|
37
38
|
else {
|
|
38
39
|
delete this._lastPosition;
|
|
39
40
|
}
|
|
40
|
-
if (canEmit) {
|
|
41
|
-
|
|
41
|
+
if (canEmit && mousePos) {
|
|
42
|
+
let particleOptions = trailOptions.particles;
|
|
43
|
+
const colorCoords = trailOptions.colorCoords;
|
|
44
|
+
if (colorCoords) {
|
|
45
|
+
const { width, height } = container.canvas.size, norm = {
|
|
46
|
+
x: mousePos.x / width,
|
|
47
|
+
y: mousePos.y / height,
|
|
48
|
+
}, hasWeights = (comp) => {
|
|
49
|
+
return !!(comp?.weights?.x ?? comp?.weights?.y);
|
|
50
|
+
}, calculateValue = (comp, originalValue, defaultMax) => {
|
|
51
|
+
if (!hasWeights(comp))
|
|
52
|
+
return undefined;
|
|
53
|
+
const w = comp?.weights, factor = norm.x * (w?.x ?? defaultWeight) + norm.y * (w?.y ?? defaultWeight), rangeSource = comp?.value ?? originalValue, min = getRangeMin(rangeSource ?? defaultMin), max = getRangeMax(rangeSource ?? defaultMax), result = min + factor * (max - min);
|
|
54
|
+
return Math.min(max, Math.max(min, result));
|
|
55
|
+
}, fillData = trailOptions.particles?.fill ? itemFromSingleOrMultiple(trailOptions.particles.fill) : undefined, baseHsl = fillData
|
|
56
|
+
? rangeColorToHsl(this._engine, AnimatableColor.create(undefined, fillData.color))
|
|
57
|
+
: undefined, h = calculateValue(colorCoords.h, baseHsl?.h, hMax), s = calculateValue(colorCoords.s, baseHsl?.s, sMax), l = calculateValue(colorCoords.l, baseHsl?.l, lMax);
|
|
58
|
+
if (h !== undefined || s !== undefined || l !== undefined) {
|
|
59
|
+
particleOptions = deepExtend({}, trailOptions.particles, {
|
|
60
|
+
color: {
|
|
61
|
+
value: {
|
|
62
|
+
h: h ?? baseHsl?.h,
|
|
63
|
+
s: s ?? baseHsl?.s,
|
|
64
|
+
l: l ?? baseHsl?.l,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
container.particles.push(trailOptions.quantity, mousePos, particleOptions);
|
|
42
71
|
}
|
|
43
72
|
this._delay -= optDelay;
|
|
44
73
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export async function loadExternalTrailInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
2
|
+
engine.checkVersion("4.0.0-beta.0");
|
|
3
3
|
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
6
|
e.addInteractor?.("externalTrail", async (container) => {
|
|
7
7
|
const { TrailMaker } = await import("./TrailMaker.js");
|
|
8
|
-
return new TrailMaker(container);
|
|
8
|
+
return new TrailMaker(e, container);
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v4.0.0-
|
|
7
|
+
* v4.0.0-beta.0
|
|
8
8
|
*/
|
|
9
9
|
"use strict";
|
|
10
10
|
/*
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
\************************************/
|
|
24
24
|
(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
25
25
|
|
|
26
|
-
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ TrailMaker: () => (/* binding */ TrailMaker)\n/* harmony export */ });\n/* harmony import */ var
|
|
26
|
+
eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ TrailMaker: () => (/* binding */ TrailMaker)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _Options_Classes_Trail_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Options/Classes/Trail.js */ \"./dist/browser/Options/Classes/Trail.js\");\n\n\n\nconst trailMode = \"trail\", defaultMin = 0, defaultWeight = 0;\nclass TrailMaker extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.ExternalInteractorBase {\n maxDistance = 0;\n _delay;\n _engine;\n _lastPosition;\n constructor(engine, container){\n super(container);\n this._engine = engine;\n this._delay = 0;\n }\n clear() {}\n init() {}\n interact(interactivityData, delta) {\n const container = this.container;\n if (!container.retina.reduceFactor) return;\n const options = container.actualOptions, trailOptions = options.interactivity?.modes.trail;\n if (!trailOptions) return;\n const optDelay = trailOptions.delay * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.millisecondsToSeconds / this.container.retina.reduceFactor;\n if (this._delay < optDelay) {\n this._delay += delta.value;\n }\n if (this._delay < optDelay) return;\n const mousePos = interactivityData.mouse.position, canEmit = !(trailOptions.pauseOnStop && (mousePos === this._lastPosition || mousePos?.x === this._lastPosition?.x && mousePos?.y === this._lastPosition?.y));\n if (mousePos) {\n this._lastPosition = {\n ...mousePos\n };\n } else {\n delete this._lastPosition;\n }\n if (canEmit && mousePos) {\n let particleOptions = trailOptions.particles;\n const colorCoords = trailOptions.colorCoords;\n if (colorCoords) {\n const { width, height } = container.canvas.size, norm = {\n x: mousePos.x / width,\n y: mousePos.y / height\n }, hasWeights = (comp)=>{\n return !!(comp?.weights?.x ?? comp?.weights?.y);\n }, calculateValue = (comp, originalValue, defaultMax)=>{\n if (!hasWeights(comp)) return undefined;\n const w = comp?.weights, factor = norm.x * (w?.x ?? defaultWeight) + norm.y * (w?.y ?? defaultWeight), rangeSource = comp?.value ?? originalValue, min = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMin)(rangeSource ?? defaultMin), max = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getRangeMax)(rangeSource ?? defaultMax), result = min + factor * (max - min);\n return Math.min(max, Math.max(min, result));\n }, fillData = trailOptions.particles?.fill ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.itemFromSingleOrMultiple)(trailOptions.particles.fill) : undefined, baseHsl = fillData ? (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.rangeColorToHsl)(this._engine, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.AnimatableColor.create(undefined, fillData.color)) : undefined, h = calculateValue(colorCoords.h, baseHsl?.h, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.hMax), s = calculateValue(colorCoords.s, baseHsl?.s, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.sMax), l = calculateValue(colorCoords.l, baseHsl?.l, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.lMax);\n if (h !== undefined || s !== undefined || l !== undefined) {\n particleOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, trailOptions.particles, {\n color: {\n value: {\n h: h ?? baseHsl?.h,\n s: s ?? baseHsl?.s,\n l: l ?? baseHsl?.l\n }\n }\n });\n }\n }\n container.particles.push(trailOptions.quantity, mousePos, particleOptions);\n }\n this._delay -= optDelay;\n }\n isEnabled(interactivityData, particle) {\n const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;\n return !!events && (mouse.clicking && mouse.inside && !!mouse.position && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(trailMode, events.onClick.mode) || mouse.inside && !!mouse.position && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(trailMode, events.onHover.mode));\n }\n loadModeOptions(options, ...sources) {\n options.trail ??= new _Options_Classes_Trail_js__WEBPACK_IMPORTED_MODULE_2__.Trail();\n for (const source of sources){\n options.trail.load(source?.trail);\n }\n }\n reset() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-trail/./dist/browser/TrailMaker.js?\n}");
|
|
27
27
|
|
|
28
28
|
/***/ }
|
|
29
29
|
|
|
@@ -1,25 +1,35 @@
|
|
|
1
1
|
import { deepExtend, isNull, } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorCoords } from "./TrailColorCoords.js";
|
|
2
3
|
export class Trail {
|
|
4
|
+
colorCoords;
|
|
5
|
+
delay;
|
|
6
|
+
particles;
|
|
7
|
+
pauseOnStop;
|
|
8
|
+
quantity;
|
|
3
9
|
constructor() {
|
|
4
10
|
this.delay = 1;
|
|
5
11
|
this.pauseOnStop = false;
|
|
6
12
|
this.quantity = 1;
|
|
13
|
+
this.colorCoords = new TrailColorCoords();
|
|
7
14
|
}
|
|
8
15
|
load(data) {
|
|
9
|
-
if (isNull(data))
|
|
16
|
+
if (isNull(data))
|
|
10
17
|
return;
|
|
11
|
-
}
|
|
12
18
|
if (data.delay !== undefined) {
|
|
13
19
|
this.delay = data.delay;
|
|
14
20
|
}
|
|
15
21
|
if (data.quantity !== undefined) {
|
|
16
22
|
this.quantity = data.quantity;
|
|
17
23
|
}
|
|
24
|
+
if (data.pauseOnStop !== undefined) {
|
|
25
|
+
this.pauseOnStop = data.pauseOnStop;
|
|
26
|
+
}
|
|
18
27
|
if (data.particles !== undefined) {
|
|
19
28
|
this.particles = deepExtend({}, data.particles);
|
|
20
29
|
}
|
|
21
|
-
if (data.
|
|
22
|
-
this.
|
|
30
|
+
if (data.colorCoords) {
|
|
31
|
+
this.colorCoords ??= new TrailColorCoords();
|
|
32
|
+
this.colorCoords.load(data.colorCoords);
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isNull, setRangeValue } from "@tsparticles/engine";
|
|
2
|
+
import { TrailColorWeight } from "./TrailColorWeight.js";
|
|
3
|
+
export class TrailColorComponent {
|
|
4
|
+
value;
|
|
5
|
+
weights;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.weights = new TrailColorWeight();
|
|
8
|
+
}
|
|
9
|
+
load(data) {
|
|
10
|
+
if (!data) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (data.weights) {
|
|
14
|
+
this.weights ??= new TrailColorWeight();
|
|
15
|
+
this.weights.load(data.weights);
|
|
16
|
+
}
|
|
17
|
+
if (!isNull(data.value)) {
|
|
18
|
+
this.value = setRangeValue(data.value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TrailColorComponent } from "./TrailColorComponent.js";
|
|
2
|
+
export class TrailColorCoords {
|
|
3
|
+
h;
|
|
4
|
+
l;
|
|
5
|
+
s;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.h = new TrailColorComponent();
|
|
8
|
+
this.s = new TrailColorComponent();
|
|
9
|
+
this.l = new TrailColorComponent();
|
|
10
|
+
}
|
|
11
|
+
load(data) {
|
|
12
|
+
if (!data) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
if (data.h) {
|
|
16
|
+
this.h ??= new TrailColorComponent();
|
|
17
|
+
this.h.load(data.h);
|
|
18
|
+
}
|
|
19
|
+
if (data.s) {
|
|
20
|
+
this.s ??= new TrailColorComponent();
|
|
21
|
+
this.s.load(data.s);
|
|
22
|
+
}
|
|
23
|
+
if (data.l) {
|
|
24
|
+
this.l ??= new TrailColorComponent();
|
|
25
|
+
this.l.load(data.l);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export class TrailColorWeight {
|
|
2
|
+
x;
|
|
3
|
+
y;
|
|
4
|
+
constructor() {
|
|
5
|
+
this.x = 0;
|
|
6
|
+
this.y = 0;
|
|
7
|
+
}
|
|
8
|
+
load(data) {
|
|
9
|
+
if (!data) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (data.x !== undefined) {
|
|
13
|
+
this.x = data.x;
|
|
14
|
+
}
|
|
15
|
+
if (data.y !== undefined) {
|
|
16
|
+
this.y = data.y;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|