@tsparticles/interaction-external-particle 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.
Files changed (43) hide show
  1. package/207.min.js +2 -0
  2. package/207.min.js.LICENSE.txt +1 -0
  3. package/LICENSE +21 -0
  4. package/README.md +76 -0
  5. package/browser/InteractivityParticleMaker.js +102 -0
  6. package/browser/Options/Classes/InteractivityParticle.js +25 -0
  7. package/browser/Options/Classes/InteractivityParticleOptions.js +1 -0
  8. package/browser/Options/Interfaces/IInteractivityParticle.js +1 -0
  9. package/browser/Types.js +1 -0
  10. package/browser/index.js +6 -0
  11. package/browser/package.json +1 -0
  12. package/cjs/InteractivityParticleMaker.js +106 -0
  13. package/cjs/Options/Classes/InteractivityParticle.js +29 -0
  14. package/cjs/Options/Classes/InteractivityParticleOptions.js +2 -0
  15. package/cjs/Options/Interfaces/IInteractivityParticle.js +2 -0
  16. package/cjs/Types.js +2 -0
  17. package/cjs/index.js +33 -0
  18. package/cjs/package.json +1 -0
  19. package/dist_browser_InteractivityParticleMaker_js.js +40 -0
  20. package/esm/InteractivityParticleMaker.js +102 -0
  21. package/esm/Options/Classes/InteractivityParticle.js +25 -0
  22. package/esm/Options/Classes/InteractivityParticleOptions.js +1 -0
  23. package/esm/Options/Interfaces/IInteractivityParticle.js +1 -0
  24. package/esm/Types.js +1 -0
  25. package/esm/index.js +6 -0
  26. package/esm/package.json +1 -0
  27. package/package.json +95 -0
  28. package/report.html +39 -0
  29. package/tsparticles.interaction.external.particle.js +326 -0
  30. package/tsparticles.interaction.external.particle.min.js +2 -0
  31. package/tsparticles.interaction.external.particle.min.js.LICENSE.txt +1 -0
  32. package/types/InteractivityParticleMaker.d.ts +14 -0
  33. package/types/Options/Classes/InteractivityParticle.d.ts +10 -0
  34. package/types/Options/Classes/InteractivityParticleOptions.d.ts +7 -0
  35. package/types/Options/Interfaces/IInteractivityParticle.d.ts +7 -0
  36. package/types/Types.d.ts +13 -0
  37. package/types/index.d.ts +2 -0
  38. package/umd/InteractivityParticleMaker.js +116 -0
  39. package/umd/Options/Classes/InteractivityParticle.js +39 -0
  40. package/umd/Options/Classes/InteractivityParticleOptions.js +12 -0
  41. package/umd/Options/Interfaces/IInteractivityParticle.js +12 -0
  42. package/umd/Types.js +12 -0
  43. package/umd/index.js +44 -0
package/207.min.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see 207.min.js.LICENSE.txt */
2
+ (this.webpackChunk_tsparticles_interaction_external_particle=this.webpackChunk_tsparticles_interaction_external_particle||[]).push([[207],{207:(t,i,e)=>{e.d(i,{InteractivityParticleMaker:()=>r});var s=e(533);class o{constructor(){this.replaceCursor=!1,this.pauseOnStop=!1,this.stopDelay=0}load(t){t&&(void 0!==t.options&&(this.options=(0,s.deepExtend)({},t.options)),void 0!==t.replaceCursor&&(this.replaceCursor=t.replaceCursor),void 0!==t.pauseOnStop&&(this.pauseOnStop=t.pauseOnStop),void 0!==t.stopDelay&&(this.stopDelay=t.stopDelay))}}const n="particle";class r extends s.ExternalInteractorBase{constructor(t){super(t)}clear(){}init(){}async interact(){const t=this.container,{interactivity:i}=t,e=t.actualOptions;if(!t.retina.reduceFactor)return;const o=i.mouse.position,n=e.interactivity.modes.particle;if(!n)return;const r=n.pauseOnStop&&(i.mouse.position===this._lastPosition||i.mouse.position?.x===this._lastPosition?.x&&i.mouse.position?.y===this._lastPosition?.y),a=n.stopDelay;if(o?this._lastPosition={...o}:delete this._lastPosition,this._lastPosition)if(r){if(this._clearTimeout)return;this._clearTimeout=setTimeout((()=>{if(this._particle){if(n.replaceCursor){const t=i.element;t&&(t instanceof Window?document.body.style.cursor="":t.style.cursor="")}this.container.particles.remove(this._particle,void 0,!0),delete this._particle}}),a)}else{if(this._clearTimeout&&(clearTimeout(this._clearTimeout),delete this._clearTimeout),!this._particle){const e=(0,s.deepExtend)(n.options,{move:{enable:!1}});if(this._particle=await t.particles.addParticle(this._lastPosition,e),n.replaceCursor){const t=i.element;t&&(t instanceof Window?document.body.style.cursor="none":t.style.cursor="none")}}this._particle&&(this._particle.position.x=this._lastPosition.x,this._particle.position.y=this._lastPosition.y)}}isEnabled(t){const i=this.container,e=i.actualOptions,o=i.interactivity.mouse,r=(t?.interactivity??e.interactivity).events;return o.clicking&&o.inside&&!!o.position&&(0,s.isInArray)(n,r.onClick.mode)||o.inside&&!!o.position&&(0,s.isInArray)(n,r.onHover.mode)}loadModeOptions(t,...i){t.particle||(t.particle=new o);for(const e of i)t.particle.load(e?.particle)}reset(){}}}}]);
@@ -0,0 +1 @@
1
+ /*! tsParticles Particle External Interaction v3.2.0 by Matteo Bruni */
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles External Particle Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/interaction-external-particle/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-particle)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/interaction-external-particle.svg)](https://www.npmjs.com/package/@tsparticles/interaction-external-particle)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/interaction-external-particle)](https://www.npmjs.com/package/@tsparticles/interaction-external-particle) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
+
9
+ [tsParticles](https://github.com/tsparticles/tsparticles) interaction plugin for particle effect around mouse or HTML
10
+ elements.
11
+
12
+ ## How to use it
13
+
14
+ ### CDN / Vanilla JS / jQuery
15
+
16
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
17
+
18
+ Including the `tsparticles.interaction.external.particle.min.js` file will export the function to load the interaction
19
+ plugin:
20
+
21
+ ```javascript
22
+ loadExternalParticleInteraction;
23
+ ```
24
+
25
+ ### Usage
26
+
27
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
28
+
29
+ ```javascript
30
+ (async () => {
31
+ await loadExternalParticleInteraction(tsParticles);
32
+
33
+ await tsParticles.load({
34
+ id: "tsparticles",
35
+ options: {
36
+ /* options */
37
+ },
38
+ });
39
+ })();
40
+ ```
41
+
42
+ ### ESM / CommonJS
43
+
44
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
45
+
46
+ ```shell
47
+ $ npm install @tsparticles/interaction-external-particle
48
+ ```
49
+
50
+ or
51
+
52
+ ```shell
53
+ $ yarn add @tsparticles/interaction-external-particle
54
+ ```
55
+
56
+ Then you need to import it in the app, like this:
57
+
58
+ ```javascript
59
+ const { tsParticles } = require("@tsparticles/engine");
60
+ const { loadExternalParticleInteraction } = require("@tsparticles/interaction-external-particle");
61
+
62
+ (async () => {
63
+ await loadExternalParticleInteraction(tsParticles);
64
+ })();
65
+ ```
66
+
67
+ or
68
+
69
+ ```javascript
70
+ import { tsParticles } from "@tsparticles/engine";
71
+ import { loadExternalParticleInteraction } from "@tsparticles/interaction-external-particle";
72
+
73
+ (async () => {
74
+ await loadExternalParticleInteraction(tsParticles);
75
+ })();
76
+ ```
@@ -0,0 +1,102 @@
1
+ import { ExternalInteractorBase, deepExtend, isInArray, } from "@tsparticles/engine";
2
+ import { InteractivityParticle } from "./Options/Classes/InteractivityParticle.js";
3
+ const particleMode = "particle";
4
+ export class InteractivityParticleMaker extends ExternalInteractorBase {
5
+ constructor(container) {
6
+ super(container);
7
+ }
8
+ clear() {
9
+ }
10
+ init() {
11
+ }
12
+ async interact() {
13
+ const container = this.container, { interactivity } = container, options = container.actualOptions;
14
+ if (!container.retina.reduceFactor) {
15
+ return;
16
+ }
17
+ const mousePos = interactivity.mouse.position, interactivityParticleOptions = options.interactivity.modes.particle;
18
+ if (!interactivityParticleOptions) {
19
+ return;
20
+ }
21
+ const mouseStopped = interactivityParticleOptions.pauseOnStop &&
22
+ (interactivity.mouse.position === this._lastPosition ||
23
+ (interactivity.mouse.position?.x === this._lastPosition?.x &&
24
+ interactivity.mouse.position?.y === this._lastPosition?.y)), clearDelay = interactivityParticleOptions.stopDelay;
25
+ if (mousePos) {
26
+ this._lastPosition = { ...mousePos };
27
+ }
28
+ else {
29
+ delete this._lastPosition;
30
+ }
31
+ if (!this._lastPosition) {
32
+ return;
33
+ }
34
+ if (mouseStopped) {
35
+ if (this._clearTimeout) {
36
+ return;
37
+ }
38
+ this._clearTimeout = setTimeout(() => {
39
+ if (!this._particle) {
40
+ return;
41
+ }
42
+ if (interactivityParticleOptions.replaceCursor) {
43
+ const element = interactivity.element;
44
+ if (element) {
45
+ if (element instanceof Window) {
46
+ document.body.style.cursor = "";
47
+ }
48
+ else {
49
+ element.style.cursor = "";
50
+ }
51
+ }
52
+ }
53
+ this.container.particles.remove(this._particle, undefined, true);
54
+ delete this._particle;
55
+ }, clearDelay);
56
+ return;
57
+ }
58
+ if (this._clearTimeout) {
59
+ clearTimeout(this._clearTimeout);
60
+ delete this._clearTimeout;
61
+ }
62
+ if (!this._particle) {
63
+ const particleOptions = deepExtend(interactivityParticleOptions.options, {
64
+ move: {
65
+ enable: false,
66
+ },
67
+ });
68
+ this._particle = await container.particles.addParticle(this._lastPosition, particleOptions);
69
+ if (interactivityParticleOptions.replaceCursor) {
70
+ const element = interactivity.element;
71
+ if (element) {
72
+ if (element instanceof Window) {
73
+ document.body.style.cursor = "none";
74
+ }
75
+ else {
76
+ element.style.cursor = "none";
77
+ }
78
+ }
79
+ }
80
+ }
81
+ if (!this._particle) {
82
+ return;
83
+ }
84
+ this._particle.position.x = this._lastPosition.x;
85
+ this._particle.position.y = this._lastPosition.y;
86
+ }
87
+ isEnabled(particle) {
88
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
89
+ return ((mouse.clicking && mouse.inside && !!mouse.position && isInArray(particleMode, events.onClick.mode)) ||
90
+ (mouse.inside && !!mouse.position && isInArray(particleMode, events.onHover.mode)));
91
+ }
92
+ loadModeOptions(options, ...sources) {
93
+ if (!options.particle) {
94
+ options.particle = new InteractivityParticle();
95
+ }
96
+ for (const source of sources) {
97
+ options.particle.load(source?.particle);
98
+ }
99
+ }
100
+ reset() {
101
+ }
102
+ }
@@ -0,0 +1,25 @@
1
+ import { deepExtend } from "@tsparticles/engine";
2
+ export class InteractivityParticle {
3
+ constructor() {
4
+ this.replaceCursor = false;
5
+ this.pauseOnStop = false;
6
+ this.stopDelay = 0;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.options !== undefined) {
13
+ this.options = deepExtend({}, data.options);
14
+ }
15
+ if (data.replaceCursor !== undefined) {
16
+ this.replaceCursor = data.replaceCursor;
17
+ }
18
+ if (data.pauseOnStop !== undefined) {
19
+ this.pauseOnStop = data.pauseOnStop;
20
+ }
21
+ if (data.stopDelay !== undefined) {
22
+ this.stopDelay = data.stopDelay;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export async function loadExternalParticleInteraction(engine, refresh = true) {
2
+ await engine.addInteractor("externalParticle", async (container) => {
3
+ const { InteractivityParticleMaker } = await import("./InteractivityParticleMaker.js");
4
+ return new InteractivityParticleMaker(container);
5
+ }, refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InteractivityParticleMaker = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const InteractivityParticle_js_1 = require("./Options/Classes/InteractivityParticle.js");
6
+ const particleMode = "particle";
7
+ class InteractivityParticleMaker extends engine_1.ExternalInteractorBase {
8
+ constructor(container) {
9
+ super(container);
10
+ }
11
+ clear() {
12
+ }
13
+ init() {
14
+ }
15
+ async interact() {
16
+ const container = this.container, { interactivity } = container, options = container.actualOptions;
17
+ if (!container.retina.reduceFactor) {
18
+ return;
19
+ }
20
+ const mousePos = interactivity.mouse.position, interactivityParticleOptions = options.interactivity.modes.particle;
21
+ if (!interactivityParticleOptions) {
22
+ return;
23
+ }
24
+ const mouseStopped = interactivityParticleOptions.pauseOnStop &&
25
+ (interactivity.mouse.position === this._lastPosition ||
26
+ (interactivity.mouse.position?.x === this._lastPosition?.x &&
27
+ interactivity.mouse.position?.y === this._lastPosition?.y)), clearDelay = interactivityParticleOptions.stopDelay;
28
+ if (mousePos) {
29
+ this._lastPosition = { ...mousePos };
30
+ }
31
+ else {
32
+ delete this._lastPosition;
33
+ }
34
+ if (!this._lastPosition) {
35
+ return;
36
+ }
37
+ if (mouseStopped) {
38
+ if (this._clearTimeout) {
39
+ return;
40
+ }
41
+ this._clearTimeout = setTimeout(() => {
42
+ if (!this._particle) {
43
+ return;
44
+ }
45
+ if (interactivityParticleOptions.replaceCursor) {
46
+ const element = interactivity.element;
47
+ if (element) {
48
+ if (element instanceof Window) {
49
+ document.body.style.cursor = "";
50
+ }
51
+ else {
52
+ element.style.cursor = "";
53
+ }
54
+ }
55
+ }
56
+ this.container.particles.remove(this._particle, undefined, true);
57
+ delete this._particle;
58
+ }, clearDelay);
59
+ return;
60
+ }
61
+ if (this._clearTimeout) {
62
+ clearTimeout(this._clearTimeout);
63
+ delete this._clearTimeout;
64
+ }
65
+ if (!this._particle) {
66
+ const particleOptions = (0, engine_1.deepExtend)(interactivityParticleOptions.options, {
67
+ move: {
68
+ enable: false,
69
+ },
70
+ });
71
+ this._particle = await container.particles.addParticle(this._lastPosition, particleOptions);
72
+ if (interactivityParticleOptions.replaceCursor) {
73
+ const element = interactivity.element;
74
+ if (element) {
75
+ if (element instanceof Window) {
76
+ document.body.style.cursor = "none";
77
+ }
78
+ else {
79
+ element.style.cursor = "none";
80
+ }
81
+ }
82
+ }
83
+ }
84
+ if (!this._particle) {
85
+ return;
86
+ }
87
+ this._particle.position.x = this._lastPosition.x;
88
+ this._particle.position.y = this._lastPosition.y;
89
+ }
90
+ isEnabled(particle) {
91
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
92
+ return ((mouse.clicking && mouse.inside && !!mouse.position && (0, engine_1.isInArray)(particleMode, events.onClick.mode)) ||
93
+ (mouse.inside && !!mouse.position && (0, engine_1.isInArray)(particleMode, events.onHover.mode)));
94
+ }
95
+ loadModeOptions(options, ...sources) {
96
+ if (!options.particle) {
97
+ options.particle = new InteractivityParticle_js_1.InteractivityParticle();
98
+ }
99
+ for (const source of sources) {
100
+ options.particle.load(source?.particle);
101
+ }
102
+ }
103
+ reset() {
104
+ }
105
+ }
106
+ exports.InteractivityParticleMaker = InteractivityParticleMaker;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InteractivityParticle = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class InteractivityParticle {
6
+ constructor() {
7
+ this.replaceCursor = false;
8
+ this.pauseOnStop = false;
9
+ this.stopDelay = 0;
10
+ }
11
+ load(data) {
12
+ if (!data) {
13
+ return;
14
+ }
15
+ if (data.options !== undefined) {
16
+ this.options = (0, engine_1.deepExtend)({}, data.options);
17
+ }
18
+ if (data.replaceCursor !== undefined) {
19
+ this.replaceCursor = data.replaceCursor;
20
+ }
21
+ if (data.pauseOnStop !== undefined) {
22
+ this.pauseOnStop = data.pauseOnStop;
23
+ }
24
+ if (data.stopDelay !== undefined) {
25
+ this.stopDelay = data.stopDelay;
26
+ }
27
+ }
28
+ }
29
+ exports.InteractivityParticle = InteractivityParticle;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/Types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.loadExternalParticleInteraction = void 0;
27
+ async function loadExternalParticleInteraction(engine, refresh = true) {
28
+ await engine.addInteractor("externalParticle", async (container) => {
29
+ const { InteractivityParticleMaker } = await Promise.resolve().then(() => __importStar(require("./InteractivityParticleMaker.js")));
30
+ return new InteractivityParticleMaker(container);
31
+ }, refresh);
32
+ }
33
+ exports.loadExternalParticleInteraction = loadExternalParticleInteraction;
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -0,0 +1,40 @@
1
+ /*!
2
+ * Author : Matteo Bruni
3
+ * MIT license: https://opensource.org/licenses/MIT
4
+ * Demo / Generator : https://particles.js.org/
5
+ * GitHub : https://www.github.com/matteobruni/tsparticles
6
+ * How to use? : Check the GitHub README
7
+ * v3.2.0
8
+ */
9
+ "use strict";
10
+ /*
11
+ * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
12
+ * This devtool is neither made for production nor for readable output files.
13
+ * It uses "eval()" calls to create a separate source file in the browser devtools.
14
+ * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
15
+ * or disable the default devtool with "devtool: false".
16
+ * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
17
+ */
18
+ (this["webpackChunk_tsparticles_interaction_external_particle"] = this["webpackChunk_tsparticles_interaction_external_particle"] || []).push([["dist_browser_InteractivityParticleMaker_js"],{
19
+
20
+ /***/ "./dist/browser/InteractivityParticleMaker.js":
21
+ /*!****************************************************!*\
22
+ !*** ./dist/browser/InteractivityParticleMaker.js ***!
23
+ \****************************************************/
24
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
25
+
26
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ InteractivityParticleMaker: () => (/* binding */ InteractivityParticleMaker)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var _Options_Classes_InteractivityParticle_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Options/Classes/InteractivityParticle.js */ \"./dist/browser/Options/Classes/InteractivityParticle.js\");\n\n\nconst particleMode = \"particle\";\nclass InteractivityParticleMaker extends _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.ExternalInteractorBase {\n constructor(container) {\n super(container);\n }\n clear() {}\n init() {}\n async interact() {\n const container = this.container,\n {\n interactivity\n } = container,\n options = container.actualOptions;\n if (!container.retina.reduceFactor) {\n return;\n }\n const mousePos = interactivity.mouse.position,\n interactivityParticleOptions = options.interactivity.modes.particle;\n if (!interactivityParticleOptions) {\n return;\n }\n const mouseStopped = interactivityParticleOptions.pauseOnStop && (interactivity.mouse.position === this._lastPosition || interactivity.mouse.position?.x === this._lastPosition?.x && interactivity.mouse.position?.y === this._lastPosition?.y),\n clearDelay = interactivityParticleOptions.stopDelay;\n if (mousePos) {\n this._lastPosition = {\n ...mousePos\n };\n } else {\n delete this._lastPosition;\n }\n if (!this._lastPosition) {\n return;\n }\n if (mouseStopped) {\n if (this._clearTimeout) {\n return;\n }\n this._clearTimeout = setTimeout(() => {\n if (!this._particle) {\n return;\n }\n if (interactivityParticleOptions.replaceCursor) {\n const element = interactivity.element;\n if (element) {\n if (element instanceof Window) {\n document.body.style.cursor = \"\";\n } else {\n element.style.cursor = \"\";\n }\n }\n }\n this.container.particles.remove(this._particle, undefined, true);\n delete this._particle;\n }, clearDelay);\n return;\n }\n if (this._clearTimeout) {\n clearTimeout(this._clearTimeout);\n delete this._clearTimeout;\n }\n if (!this._particle) {\n const particleOptions = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)(interactivityParticleOptions.options, {\n move: {\n enable: false\n }\n });\n this._particle = await container.particles.addParticle(this._lastPosition, particleOptions);\n if (interactivityParticleOptions.replaceCursor) {\n const element = interactivity.element;\n if (element) {\n if (element instanceof Window) {\n document.body.style.cursor = \"none\";\n } else {\n element.style.cursor = \"none\";\n }\n }\n }\n }\n if (!this._particle) {\n return;\n }\n this._particle.position.x = this._lastPosition.x;\n this._particle.position.y = this._lastPosition.y;\n }\n isEnabled(particle) {\n const container = this.container,\n options = container.actualOptions,\n mouse = container.interactivity.mouse,\n events = (particle?.interactivity ?? options.interactivity).events;\n return mouse.clicking && mouse.inside && !!mouse.position && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(particleMode, events.onClick.mode) || mouse.inside && !!mouse.position && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isInArray)(particleMode, events.onHover.mode);\n }\n loadModeOptions(options, ...sources) {\n if (!options.particle) {\n options.particle = new _Options_Classes_InteractivityParticle_js__WEBPACK_IMPORTED_MODULE_1__.InteractivityParticle();\n }\n for (const source of sources) {\n options.particle.load(source?.particle);\n }\n }\n reset() {}\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-particle/./dist/browser/InteractivityParticleMaker.js?");
27
+
28
+ /***/ }),
29
+
30
+ /***/ "./dist/browser/Options/Classes/InteractivityParticle.js":
31
+ /*!***************************************************************!*\
32
+ !*** ./dist/browser/Options/Classes/InteractivityParticle.js ***!
33
+ \***************************************************************/
34
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
35
+
36
+ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ InteractivityParticle: () => (/* binding */ InteractivityParticle)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nclass InteractivityParticle {\n constructor() {\n this.replaceCursor = false;\n this.pauseOnStop = false;\n this.stopDelay = 0;\n }\n load(data) {\n if (!data) {\n return;\n }\n if (data.options !== undefined) {\n this.options = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, data.options);\n }\n if (data.replaceCursor !== undefined) {\n this.replaceCursor = data.replaceCursor;\n }\n if (data.pauseOnStop !== undefined) {\n this.pauseOnStop = data.pauseOnStop;\n }\n if (data.stopDelay !== undefined) {\n this.stopDelay = data.stopDelay;\n }\n }\n}\n\n//# sourceURL=webpack://@tsparticles/interaction-external-particle/./dist/browser/Options/Classes/InteractivityParticle.js?");
37
+
38
+ /***/ })
39
+
40
+ }]);
@@ -0,0 +1,102 @@
1
+ import { ExternalInteractorBase, deepExtend, isInArray, } from "@tsparticles/engine";
2
+ import { InteractivityParticle } from "./Options/Classes/InteractivityParticle.js";
3
+ const particleMode = "particle";
4
+ export class InteractivityParticleMaker extends ExternalInteractorBase {
5
+ constructor(container) {
6
+ super(container);
7
+ }
8
+ clear() {
9
+ }
10
+ init() {
11
+ }
12
+ async interact() {
13
+ const container = this.container, { interactivity } = container, options = container.actualOptions;
14
+ if (!container.retina.reduceFactor) {
15
+ return;
16
+ }
17
+ const mousePos = interactivity.mouse.position, interactivityParticleOptions = options.interactivity.modes.particle;
18
+ if (!interactivityParticleOptions) {
19
+ return;
20
+ }
21
+ const mouseStopped = interactivityParticleOptions.pauseOnStop &&
22
+ (interactivity.mouse.position === this._lastPosition ||
23
+ (interactivity.mouse.position?.x === this._lastPosition?.x &&
24
+ interactivity.mouse.position?.y === this._lastPosition?.y)), clearDelay = interactivityParticleOptions.stopDelay;
25
+ if (mousePos) {
26
+ this._lastPosition = { ...mousePos };
27
+ }
28
+ else {
29
+ delete this._lastPosition;
30
+ }
31
+ if (!this._lastPosition) {
32
+ return;
33
+ }
34
+ if (mouseStopped) {
35
+ if (this._clearTimeout) {
36
+ return;
37
+ }
38
+ this._clearTimeout = setTimeout(() => {
39
+ if (!this._particle) {
40
+ return;
41
+ }
42
+ if (interactivityParticleOptions.replaceCursor) {
43
+ const element = interactivity.element;
44
+ if (element) {
45
+ if (element instanceof Window) {
46
+ document.body.style.cursor = "";
47
+ }
48
+ else {
49
+ element.style.cursor = "";
50
+ }
51
+ }
52
+ }
53
+ this.container.particles.remove(this._particle, undefined, true);
54
+ delete this._particle;
55
+ }, clearDelay);
56
+ return;
57
+ }
58
+ if (this._clearTimeout) {
59
+ clearTimeout(this._clearTimeout);
60
+ delete this._clearTimeout;
61
+ }
62
+ if (!this._particle) {
63
+ const particleOptions = deepExtend(interactivityParticleOptions.options, {
64
+ move: {
65
+ enable: false,
66
+ },
67
+ });
68
+ this._particle = await container.particles.addParticle(this._lastPosition, particleOptions);
69
+ if (interactivityParticleOptions.replaceCursor) {
70
+ const element = interactivity.element;
71
+ if (element) {
72
+ if (element instanceof Window) {
73
+ document.body.style.cursor = "none";
74
+ }
75
+ else {
76
+ element.style.cursor = "none";
77
+ }
78
+ }
79
+ }
80
+ }
81
+ if (!this._particle) {
82
+ return;
83
+ }
84
+ this._particle.position.x = this._lastPosition.x;
85
+ this._particle.position.y = this._lastPosition.y;
86
+ }
87
+ isEnabled(particle) {
88
+ const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events;
89
+ return ((mouse.clicking && mouse.inside && !!mouse.position && isInArray(particleMode, events.onClick.mode)) ||
90
+ (mouse.inside && !!mouse.position && isInArray(particleMode, events.onHover.mode)));
91
+ }
92
+ loadModeOptions(options, ...sources) {
93
+ if (!options.particle) {
94
+ options.particle = new InteractivityParticle();
95
+ }
96
+ for (const source of sources) {
97
+ options.particle.load(source?.particle);
98
+ }
99
+ }
100
+ reset() {
101
+ }
102
+ }
@@ -0,0 +1,25 @@
1
+ import { deepExtend } from "@tsparticles/engine";
2
+ export class InteractivityParticle {
3
+ constructor() {
4
+ this.replaceCursor = false;
5
+ this.pauseOnStop = false;
6
+ this.stopDelay = 0;
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.options !== undefined) {
13
+ this.options = deepExtend({}, data.options);
14
+ }
15
+ if (data.replaceCursor !== undefined) {
16
+ this.replaceCursor = data.replaceCursor;
17
+ }
18
+ if (data.pauseOnStop !== undefined) {
19
+ this.pauseOnStop = data.pauseOnStop;
20
+ }
21
+ if (data.stopDelay !== undefined) {
22
+ this.stopDelay = data.stopDelay;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1 @@
1
+ export {};
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export async function loadExternalParticleInteraction(engine, refresh = true) {
2
+ await engine.addInteractor("externalParticle", async (container) => {
3
+ const { InteractivityParticleMaker } = await import("./InteractivityParticleMaker.js");
4
+ return new InteractivityParticleMaker(container);
5
+ }, refresh);
6
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }