@tsparticles/interaction-external-trail 3.0.0-alpha.1 → 3.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/README.md +25 -19
- package/browser/TrailMaker.js +13 -20
- package/browser/index.js +2 -2
- package/cjs/TrailMaker.js +33 -51
- package/cjs/index.js +2 -13
- package/esm/TrailMaker.js +13 -20
- package/esm/index.js +2 -2
- package/package.json +6 -5
- package/report.html +4 -4
- package/tsparticles.interaction.external.trail.js +17 -21
- package/tsparticles.interaction.external.trail.min.js +1 -1
- package/tsparticles.interaction.external.trail.min.js.LICENSE.txt +1 -8
- package/types/Options/Classes/Trail.d.ts +1 -1
- package/types/TrailMaker.d.ts +1 -2
- package/types/index.d.ts +1 -1
- package/umd/TrailMaker.js +12 -19
- package/umd/index.js +2 -2
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles External Trail Interaction
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-trail)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-external-trail)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/interaction-external-trail) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) interaction plugin for trail effect around mouse or HTML
|
|
10
10
|
elements.
|
|
@@ -27,14 +27,16 @@ loadExternalTrailInteraction;
|
|
|
27
27
|
Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
30
|
+
(async () => {
|
|
31
|
+
await loadExternalTrailInteraction(tsParticles);
|
|
32
|
+
|
|
33
|
+
await tsParticles.load({
|
|
34
|
+
id: "tsparticles",
|
|
35
|
+
options: {
|
|
36
|
+
/* options */
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
### ESM / CommonJS
|
|
@@ -42,29 +44,33 @@ tsParticles.load({
|
|
|
42
44
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
43
45
|
|
|
44
46
|
```shell
|
|
45
|
-
$ npm install tsparticles
|
|
47
|
+
$ npm install @tsparticles/interaction-external-trail
|
|
46
48
|
```
|
|
47
49
|
|
|
48
50
|
or
|
|
49
51
|
|
|
50
52
|
```shell
|
|
51
|
-
$ yarn add tsparticles
|
|
53
|
+
$ yarn add @tsparticles/interaction-external-trail
|
|
52
54
|
```
|
|
53
55
|
|
|
54
56
|
Then you need to import it in the app, like this:
|
|
55
57
|
|
|
56
58
|
```javascript
|
|
57
|
-
const { tsParticles } = require("tsparticles
|
|
58
|
-
const { loadExternalTrailInteraction } = require("tsparticles
|
|
59
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
60
|
+
const { loadExternalTrailInteraction } = require("@tsparticles/interaction-external-trail");
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
(async () => {
|
|
63
|
+
await loadExternalTrailInteraction(tsParticles);
|
|
64
|
+
})();
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
or
|
|
64
68
|
|
|
65
69
|
```javascript
|
|
66
|
-
import { tsParticles } from "tsparticles
|
|
67
|
-
import { loadExternalTrailInteraction } from "tsparticles
|
|
70
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
71
|
+
import { loadExternalTrailInteraction } from "@tsparticles/interaction-external-trail";
|
|
68
72
|
|
|
69
|
-
|
|
73
|
+
(async () => {
|
|
74
|
+
await loadExternalTrailInteraction(tsParticles);
|
|
75
|
+
})();
|
|
70
76
|
```
|
package/browser/TrailMaker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray } from "@tsparticles/engine";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
|
|
2
2
|
import { Trail } from "./Options/Classes/Trail";
|
|
3
3
|
export class TrailMaker extends ExternalInteractorBase {
|
|
4
4
|
constructor(container) {
|
|
@@ -10,11 +10,11 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
10
10
|
init() {
|
|
11
11
|
}
|
|
12
12
|
async interact(delta) {
|
|
13
|
-
|
|
14
|
-
if (!
|
|
13
|
+
const container = this.container, { interactivity } = container;
|
|
14
|
+
if (!container.retina.reduceFactor) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
|
|
18
18
|
if (!trailOptions) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
@@ -25,19 +25,13 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
25
25
|
if (this._delay < optDelay) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (container.interactivity.mouse.position) {
|
|
37
|
-
this._lastPosition = {
|
|
38
|
-
x: container.interactivity.mouse.position.x,
|
|
39
|
-
y: container.interactivity.mouse.position.y,
|
|
40
|
-
};
|
|
28
|
+
const canEmit = !(trailOptions.pauseOnStop &&
|
|
29
|
+
(interactivity.mouse.position === this._lastPosition ||
|
|
30
|
+
(interactivity.mouse.position?.x === this._lastPosition?.x &&
|
|
31
|
+
interactivity.mouse.position?.y === this._lastPosition?.y)));
|
|
32
|
+
const mousePos = container.interactivity.mouse.position;
|
|
33
|
+
if (mousePos) {
|
|
34
|
+
this._lastPosition = { ...mousePos };
|
|
41
35
|
}
|
|
42
36
|
else {
|
|
43
37
|
delete this._lastPosition;
|
|
@@ -48,8 +42,7 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
48
42
|
this._delay -= optDelay;
|
|
49
43
|
}
|
|
50
44
|
isEnabled(particle) {
|
|
51
|
-
|
|
52
|
-
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
45
|
+
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
|
|
53
46
|
return ((mouse.clicking && mouse.inside && !!mouse.position && isInArray("trail", events.onClick.mode)) ||
|
|
54
47
|
(mouse.inside && !!mouse.position && isInArray("trail", events.onHover.mode)));
|
|
55
48
|
}
|
|
@@ -58,7 +51,7 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
58
51
|
options.trail = new Trail();
|
|
59
52
|
}
|
|
60
53
|
for (const source of sources) {
|
|
61
|
-
options.trail.load(source
|
|
54
|
+
options.trail.load(source?.trail);
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
reset() {
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TrailMaker } from "./TrailMaker";
|
|
2
|
-
export async function loadExternalTrailInteraction(engine) {
|
|
3
|
-
await engine.addInteractor("externalTrail", (container) => new TrailMaker(container));
|
|
2
|
+
export async function loadExternalTrailInteraction(engine, refresh = true) {
|
|
3
|
+
await engine.addInteractor("externalTrail", (container) => new TrailMaker(container), refresh);
|
|
4
4
|
}
|
|
5
5
|
export * from "./Options/Classes/Trail";
|
|
6
6
|
export * from "./Options/Interfaces/ITrail";
|
package/cjs/TrailMaker.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
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
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TrailMaker = void 0;
|
|
13
4
|
const engine_1 = require("@tsparticles/engine");
|
|
@@ -21,49 +12,40 @@ class TrailMaker extends engine_1.ExternalInteractorBase {
|
|
|
21
12
|
}
|
|
22
13
|
init() {
|
|
23
14
|
}
|
|
24
|
-
interact(delta) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
else {
|
|
56
|
-
delete this._lastPosition;
|
|
57
|
-
}
|
|
58
|
-
if (canEmit) {
|
|
59
|
-
container.particles.push(trailOptions.quantity, container.interactivity.mouse, trailOptions.particles);
|
|
60
|
-
}
|
|
61
|
-
this._delay -= optDelay;
|
|
62
|
-
});
|
|
15
|
+
async interact(delta) {
|
|
16
|
+
const container = this.container, { interactivity } = container;
|
|
17
|
+
if (!container.retina.reduceFactor) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
|
|
21
|
+
if (!trailOptions) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const optDelay = (trailOptions.delay * 1000) / this.container.retina.reduceFactor;
|
|
25
|
+
if (this._delay < optDelay) {
|
|
26
|
+
this._delay += delta.value;
|
|
27
|
+
}
|
|
28
|
+
if (this._delay < optDelay) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const canEmit = !(trailOptions.pauseOnStop &&
|
|
32
|
+
(interactivity.mouse.position === this._lastPosition ||
|
|
33
|
+
(interactivity.mouse.position?.x === this._lastPosition?.x &&
|
|
34
|
+
interactivity.mouse.position?.y === this._lastPosition?.y)));
|
|
35
|
+
const mousePos = container.interactivity.mouse.position;
|
|
36
|
+
if (mousePos) {
|
|
37
|
+
this._lastPosition = { ...mousePos };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
delete this._lastPosition;
|
|
41
|
+
}
|
|
42
|
+
if (canEmit) {
|
|
43
|
+
container.particles.push(trailOptions.quantity, container.interactivity.mouse, trailOptions.particles);
|
|
44
|
+
}
|
|
45
|
+
this._delay -= optDelay;
|
|
63
46
|
}
|
|
64
47
|
isEnabled(particle) {
|
|
65
|
-
|
|
66
|
-
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
48
|
+
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
|
|
67
49
|
return ((mouse.clicking && mouse.inside && !!mouse.position && (0, engine_1.isInArray)("trail", events.onClick.mode)) ||
|
|
68
50
|
(mouse.inside && !!mouse.position && (0, engine_1.isInArray)("trail", events.onHover.mode)));
|
|
69
51
|
}
|
|
@@ -72,7 +54,7 @@ class TrailMaker extends engine_1.ExternalInteractorBase {
|
|
|
72
54
|
options.trail = new Trail_1.Trail();
|
|
73
55
|
}
|
|
74
56
|
for (const source of sources) {
|
|
75
|
-
options.trail.load(source
|
|
57
|
+
options.trail.load(source?.trail);
|
|
76
58
|
}
|
|
77
59
|
}
|
|
78
60
|
reset() {
|
package/cjs/index.js
CHANGED
|
@@ -13,22 +13,11 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
17
|
exports.loadExternalTrailInteraction = void 0;
|
|
27
18
|
const TrailMaker_1 = require("./TrailMaker");
|
|
28
|
-
function loadExternalTrailInteraction(engine) {
|
|
29
|
-
|
|
30
|
-
yield engine.addInteractor("externalTrail", (container) => new TrailMaker_1.TrailMaker(container));
|
|
31
|
-
});
|
|
19
|
+
async function loadExternalTrailInteraction(engine, refresh = true) {
|
|
20
|
+
await engine.addInteractor("externalTrail", (container) => new TrailMaker_1.TrailMaker(container), refresh);
|
|
32
21
|
}
|
|
33
22
|
exports.loadExternalTrailInteraction = loadExternalTrailInteraction;
|
|
34
23
|
__exportStar(require("./Options/Classes/Trail"), exports);
|
package/esm/TrailMaker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExternalInteractorBase, isInArray } from "@tsparticles/engine";
|
|
1
|
+
import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
|
|
2
2
|
import { Trail } from "./Options/Classes/Trail";
|
|
3
3
|
export class TrailMaker extends ExternalInteractorBase {
|
|
4
4
|
constructor(container) {
|
|
@@ -10,11 +10,11 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
10
10
|
init() {
|
|
11
11
|
}
|
|
12
12
|
async interact(delta) {
|
|
13
|
-
|
|
14
|
-
if (!
|
|
13
|
+
const container = this.container, { interactivity } = container;
|
|
14
|
+
if (!container.retina.reduceFactor) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
|
-
const
|
|
17
|
+
const options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
|
|
18
18
|
if (!trailOptions) {
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
@@ -25,19 +25,13 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
25
25
|
if (this._delay < optDelay) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (container.interactivity.mouse.position) {
|
|
37
|
-
this._lastPosition = {
|
|
38
|
-
x: container.interactivity.mouse.position.x,
|
|
39
|
-
y: container.interactivity.mouse.position.y,
|
|
40
|
-
};
|
|
28
|
+
const canEmit = !(trailOptions.pauseOnStop &&
|
|
29
|
+
(interactivity.mouse.position === this._lastPosition ||
|
|
30
|
+
(interactivity.mouse.position?.x === this._lastPosition?.x &&
|
|
31
|
+
interactivity.mouse.position?.y === this._lastPosition?.y)));
|
|
32
|
+
const mousePos = container.interactivity.mouse.position;
|
|
33
|
+
if (mousePos) {
|
|
34
|
+
this._lastPosition = { ...mousePos };
|
|
41
35
|
}
|
|
42
36
|
else {
|
|
43
37
|
delete this._lastPosition;
|
|
@@ -48,8 +42,7 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
48
42
|
this._delay -= optDelay;
|
|
49
43
|
}
|
|
50
44
|
isEnabled(particle) {
|
|
51
|
-
|
|
52
|
-
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
|
45
|
+
const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
|
|
53
46
|
return ((mouse.clicking && mouse.inside && !!mouse.position && isInArray("trail", events.onClick.mode)) ||
|
|
54
47
|
(mouse.inside && !!mouse.position && isInArray("trail", events.onHover.mode)));
|
|
55
48
|
}
|
|
@@ -58,7 +51,7 @@ export class TrailMaker extends ExternalInteractorBase {
|
|
|
58
51
|
options.trail = new Trail();
|
|
59
52
|
}
|
|
60
53
|
for (const source of sources) {
|
|
61
|
-
options.trail.load(source
|
|
54
|
+
options.trail.load(source?.trail);
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
reset() {
|
package/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TrailMaker } from "./TrailMaker";
|
|
2
|
-
export async function loadExternalTrailInteraction(engine) {
|
|
3
|
-
await engine.addInteractor("externalTrail", (container) => new TrailMaker(container));
|
|
2
|
+
export async function loadExternalTrailInteraction(engine, refresh = true) {
|
|
3
|
+
await engine.addInteractor("externalTrail", (container) => new TrailMaker(container), refresh);
|
|
4
4
|
}
|
|
5
5
|
export * from "./Options/Classes/Trail";
|
|
6
6
|
export * from "./Options/Interfaces/ITrail";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/interaction-external-trail",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles trail external interaction",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -73,10 +73,11 @@
|
|
|
73
73
|
"unpkg": "tsparticles.interaction.external.trail.min.js",
|
|
74
74
|
"module": "esm/index.js",
|
|
75
75
|
"types": "types/index.d.ts",
|
|
76
|
+
"sideEffects": false,
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
79
|
+
},
|
|
76
80
|
"publishConfig": {
|
|
77
81
|
"access": "public"
|
|
78
|
-
},
|
|
79
|
-
"dependencies": {
|
|
80
|
-
"@tsparticles/engine": "^3.0.0-alpha.1"
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
+
}
|