@tsparticles/interaction-external-trail 3.0.0-alpha.1 → 3.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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles External Trail Interaction
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-interaction-external-trail/badge)](https://www.jsdelivr.com/package/npm/tsparticles-interaction-external-trail)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-interaction-external-trail.svg)](https://www.npmjs.com/package/tsparticles-interaction-external-trail)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-interaction-external-trail)](https://www.npmjs.com/package/tsparticles-interaction-external-trail) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/interaction-external-trail/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-trail)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/interaction-external-trail.svg)](https://www.npmjs.com/package/@tsparticles/interaction-external-trail)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/interaction-external-trail)](https://www.npmjs.com/package/@tsparticles/interaction-external-trail) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](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
- loadExternalTrailInteraction(tsParticles);
31
-
32
- tsParticles.load({
33
- id: "tsparticles",
34
- options: {
35
- /* options */
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-interaction-external-trail
47
+ $ npm install @tsparticles/interaction-external-trail
46
48
  ```
47
49
 
48
50
  or
49
51
 
50
52
  ```shell
51
- $ yarn add tsparticles-interaction-external-trail
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-engine");
58
- const { loadExternalTrailInteraction } = require("tsparticles-interaction-external-trail");
59
+ const { tsParticles } = require("@tsparticles/engine");
60
+ const { loadExternalTrailInteraction } = require("@tsparticles/interaction-external-trail");
59
61
 
60
- loadExternalTrailInteraction(tsParticles);
62
+ (async () => {
63
+ await loadExternalTrailInteraction(tsParticles);
64
+ })();
61
65
  ```
62
66
 
63
67
  or
64
68
 
65
69
  ```javascript
66
- import { tsParticles } from "tsparticles-engine";
67
- import { loadExternalTrailInteraction } from "tsparticles-interaction-external-trail";
70
+ import { tsParticles } from "@tsparticles/engine";
71
+ import { loadExternalTrailInteraction } from "@tsparticles/interaction-external-trail";
68
72
 
69
- loadExternalTrailInteraction(tsParticles);
73
+ (async () => {
74
+ await loadExternalTrailInteraction(tsParticles);
75
+ })();
70
76
  ```
@@ -1,5 +1,5 @@
1
- import { ExternalInteractorBase, isInArray } from "@tsparticles/engine";
2
- import { Trail } from "./Options/Classes/Trail";
1
+ import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
2
+ import { Trail } from "./Options/Classes/Trail.js";
3
3
  export class TrailMaker extends ExternalInteractorBase {
4
4
  constructor(container) {
5
5
  super(container);
@@ -10,11 +10,11 @@ export class TrailMaker extends ExternalInteractorBase {
10
10
  init() {
11
11
  }
12
12
  async interact(delta) {
13
- var _a, _b, _c, _d;
14
- if (!this.container.retina.reduceFactor) {
13
+ const container = this.container, { interactivity } = container;
14
+ if (!container.retina.reduceFactor) {
15
15
  return;
16
16
  }
17
- const container = this.container, options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
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
- let canEmit = true;
29
- if (trailOptions.pauseOnStop) {
30
- if (container.interactivity.mouse.position === this._lastPosition ||
31
- (((_a = container.interactivity.mouse.position) === null || _a === void 0 ? void 0 : _a.x) === ((_b = this._lastPosition) === null || _b === void 0 ? void 0 : _b.x) &&
32
- ((_c = container.interactivity.mouse.position) === null || _c === void 0 ? void 0 : _c.y) === ((_d = this._lastPosition) === null || _d === void 0 ? void 0 : _d.y))) {
33
- canEmit = false;
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
- var _a;
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 === null || source === void 0 ? void 0 : source.trail);
54
+ options.trail.load(source?.trail);
62
55
  }
63
56
  }
64
57
  reset() {
package/browser/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { TrailMaker } from "./TrailMaker";
2
- export async function loadExternalTrailInteraction(engine) {
3
- await engine.addInteractor("externalTrail", (container) => new TrailMaker(container));
1
+ import { TrailMaker } from "./TrailMaker.js";
2
+ export async function loadExternalTrailInteraction(engine, refresh = true) {
3
+ await engine.addInteractor("externalTrail", (container) => new TrailMaker(container), refresh);
4
4
  }
5
- export * from "./Options/Classes/Trail";
6
- export * from "./Options/Interfaces/ITrail";
5
+ export * from "./Options/Classes/Trail.js";
6
+ export * from "./Options/Interfaces/ITrail.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/cjs/TrailMaker.js CHANGED
@@ -1,17 +1,8 @@
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");
14
- const Trail_1 = require("./Options/Classes/Trail");
5
+ const Trail_js_1 = require("./Options/Classes/Trail.js");
15
6
  class TrailMaker extends engine_1.ExternalInteractorBase {
16
7
  constructor(container) {
17
8
  super(container);
@@ -21,58 +12,49 @@ class TrailMaker extends engine_1.ExternalInteractorBase {
21
12
  }
22
13
  init() {
23
14
  }
24
- interact(delta) {
25
- var _a, _b, _c, _d;
26
- return __awaiter(this, void 0, void 0, function* () {
27
- if (!this.container.retina.reduceFactor) {
28
- return;
29
- }
30
- const container = this.container, options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
31
- if (!trailOptions) {
32
- return;
33
- }
34
- const optDelay = (trailOptions.delay * 1000) / this.container.retina.reduceFactor;
35
- if (this._delay < optDelay) {
36
- this._delay += delta.value;
37
- }
38
- if (this._delay < optDelay) {
39
- return;
40
- }
41
- let canEmit = true;
42
- if (trailOptions.pauseOnStop) {
43
- if (container.interactivity.mouse.position === this._lastPosition ||
44
- (((_a = container.interactivity.mouse.position) === null || _a === void 0 ? void 0 : _a.x) === ((_b = this._lastPosition) === null || _b === void 0 ? void 0 : _b.x) &&
45
- ((_c = container.interactivity.mouse.position) === null || _c === void 0 ? void 0 : _c.y) === ((_d = this._lastPosition) === null || _d === void 0 ? void 0 : _d.y))) {
46
- canEmit = false;
47
- }
48
- }
49
- if (container.interactivity.mouse.position) {
50
- this._lastPosition = {
51
- x: container.interactivity.mouse.position.x,
52
- y: container.interactivity.mouse.position.y,
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
- var _a;
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
  }
70
52
  loadModeOptions(options, ...sources) {
71
53
  if (!options.trail) {
72
- options.trail = new Trail_1.Trail();
54
+ options.trail = new Trail_js_1.Trail();
73
55
  }
74
56
  for (const source of sources) {
75
- options.trail.load(source === null || source === void 0 ? void 0 : source.trail);
57
+ options.trail.load(source?.trail);
76
58
  }
77
59
  }
78
60
  reset() {
package/cjs/index.js CHANGED
@@ -13,23 +13,12 @@ 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
- const TrailMaker_1 = require("./TrailMaker");
28
- function loadExternalTrailInteraction(engine) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- yield engine.addInteractor("externalTrail", (container) => new TrailMaker_1.TrailMaker(container));
31
- });
18
+ const TrailMaker_js_1 = require("./TrailMaker.js");
19
+ async function loadExternalTrailInteraction(engine, refresh = true) {
20
+ await engine.addInteractor("externalTrail", (container) => new TrailMaker_js_1.TrailMaker(container), refresh);
32
21
  }
33
22
  exports.loadExternalTrailInteraction = loadExternalTrailInteraction;
34
- __exportStar(require("./Options/Classes/Trail"), exports);
35
- __exportStar(require("./Options/Interfaces/ITrail"), exports);
23
+ __exportStar(require("./Options/Classes/Trail.js"), exports);
24
+ __exportStar(require("./Options/Interfaces/ITrail.js"), exports);
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
package/esm/TrailMaker.js CHANGED
@@ -1,5 +1,5 @@
1
- import { ExternalInteractorBase, isInArray } from "@tsparticles/engine";
2
- import { Trail } from "./Options/Classes/Trail";
1
+ import { ExternalInteractorBase, isInArray, } from "@tsparticles/engine";
2
+ import { Trail } from "./Options/Classes/Trail.js";
3
3
  export class TrailMaker extends ExternalInteractorBase {
4
4
  constructor(container) {
5
5
  super(container);
@@ -10,11 +10,11 @@ export class TrailMaker extends ExternalInteractorBase {
10
10
  init() {
11
11
  }
12
12
  async interact(delta) {
13
- var _a, _b, _c, _d;
14
- if (!this.container.retina.reduceFactor) {
13
+ const container = this.container, { interactivity } = container;
14
+ if (!container.retina.reduceFactor) {
15
15
  return;
16
16
  }
17
- const container = this.container, options = container.actualOptions, trailOptions = options.interactivity.modes.trail;
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
- let canEmit = true;
29
- if (trailOptions.pauseOnStop) {
30
- if (container.interactivity.mouse.position === this._lastPosition ||
31
- (((_a = container.interactivity.mouse.position) === null || _a === void 0 ? void 0 : _a.x) === ((_b = this._lastPosition) === null || _b === void 0 ? void 0 : _b.x) &&
32
- ((_c = container.interactivity.mouse.position) === null || _c === void 0 ? void 0 : _c.y) === ((_d = this._lastPosition) === null || _d === void 0 ? void 0 : _d.y))) {
33
- canEmit = false;
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
- var _a;
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 === null || source === void 0 ? void 0 : source.trail);
54
+ options.trail.load(source?.trail);
62
55
  }
63
56
  }
64
57
  reset() {
package/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { TrailMaker } from "./TrailMaker";
2
- export async function loadExternalTrailInteraction(engine) {
3
- await engine.addInteractor("externalTrail", (container) => new TrailMaker(container));
1
+ import { TrailMaker } from "./TrailMaker.js";
2
+ export async function loadExternalTrailInteraction(engine, refresh = true) {
3
+ await engine.addInteractor("externalTrail", (container) => new TrailMaker(container), refresh);
4
4
  }
5
- export * from "./Options/Classes/Trail";
6
- export * from "./Options/Interfaces/ITrail";
5
+ export * from "./Options/Classes/Trail.js";
6
+ export * from "./Options/Interfaces/ITrail.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/interaction-external-trail",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "tsParticles trail external interaction",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -68,15 +68,28 @@
68
68
  "bugs": {
69
69
  "url": "https://github.com/matteobruni/tsparticles/issues"
70
70
  },
71
- "main": "cjs/index.js",
71
+ "sideEffects": false,
72
72
  "jsdelivr": "tsparticles.interaction.external.trail.min.js",
73
73
  "unpkg": "tsparticles.interaction.external.trail.min.js",
74
+ "browser": "browser/index.js",
75
+ "main": "cjs/index.js",
74
76
  "module": "esm/index.js",
75
77
  "types": "types/index.d.ts",
76
- "publishConfig": {
77
- "access": "public"
78
+ "exports": {
79
+ ".": {
80
+ "types": "./types/index.d.ts",
81
+ "browser": "./browser/index.js",
82
+ "import": "./esm/index.js",
83
+ "require": "./cjs/index.js",
84
+ "umd": "./umd/index.js",
85
+ "default": "./cjs/index.js"
86
+ },
87
+ "./package.json": "./package.json"
78
88
  },
79
89
  "dependencies": {
80
- "@tsparticles/engine": "^3.0.0-alpha.1"
90
+ "@tsparticles/engine": "^3.0.0-beta.1"
91
+ },
92
+ "publishConfig": {
93
+ "access": "public"
81
94
  }
82
- }
95
+ }