@tsparticles/interaction-external-trail 4.0.0-alpha.8 → 4.0.0-beta.1
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/771.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 +6 -6
- 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 +6 -6
- 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 +6 -6
- package/package.json +3 -3
- package/report.html +84 -29
- 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 +6 -6
- 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/esm/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
|
+
_lastPosition;
|
|
9
|
+
_pluginManager;
|
|
10
|
+
constructor(pluginManager, container) {
|
|
7
11
|
super(container);
|
|
12
|
+
this._pluginManager = pluginManager;
|
|
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._pluginManager, 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/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export async function loadExternalTrailInteraction(engine) {
|
|
2
|
-
engine.checkVersion("4.0.0-
|
|
3
|
-
await engine.register(async (e) => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
6
|
-
e.addInteractor?.("externalTrail", async (container) => {
|
|
2
|
+
engine.checkVersion("4.0.0-beta.1");
|
|
3
|
+
await engine.pluginManager.register(async (e) => {
|
|
4
|
+
const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
|
|
5
|
+
ensureInteractivityPluginLoaded(e);
|
|
6
|
+
e.pluginManager.addInteractor?.("externalTrail", async (container) => {
|
|
7
7
|
const { TrailMaker } = await import("./TrailMaker.js");
|
|
8
|
-
return new TrailMaker(container);
|
|
8
|
+
return new TrailMaker(e.pluginManager, container);
|
|
9
9
|
});
|
|
10
10
|
});
|
|
11
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-trail",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "tsParticles trail external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
"./package.json": "./package.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@tsparticles/engine": "4.0.0-
|
|
91
|
-
"@tsparticles/plugin-interactivity": "4.0.0-
|
|
90
|
+
"@tsparticles/engine": "4.0.0-beta.1",
|
|
91
|
+
"@tsparticles/plugin-interactivity": "4.0.0-beta.1"
|
|
92
92
|
},
|
|
93
93
|
"publishConfig": {
|
|
94
94
|
"access": "public"
|