@tsparticles/interaction-external-destroy 4.0.0-beta.11

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 (39) hide show
  1. package/799.min.js +1 -0
  2. package/LICENSE +21 -0
  3. package/README.md +121 -0
  4. package/browser/Destroyer.js +55 -0
  5. package/browser/Options/Classes/Destroy.js +15 -0
  6. package/browser/Options/Classes/DestroyOptions.js +1 -0
  7. package/browser/Options/Interfaces/IDestroy.js +1 -0
  8. package/browser/Types.js +1 -0
  9. package/browser/Utils.js +36 -0
  10. package/browser/index.js +12 -0
  11. package/browser/package.json +1 -0
  12. package/cjs/Destroyer.js +55 -0
  13. package/cjs/Options/Classes/Destroy.js +15 -0
  14. package/cjs/Options/Classes/DestroyOptions.js +1 -0
  15. package/cjs/Options/Interfaces/IDestroy.js +1 -0
  16. package/cjs/Types.js +1 -0
  17. package/cjs/Utils.js +36 -0
  18. package/cjs/index.js +12 -0
  19. package/cjs/package.json +1 -0
  20. package/dist_browser_Destroyer_js.js +40 -0
  21. package/esm/Destroyer.js +55 -0
  22. package/esm/Options/Classes/Destroy.js +15 -0
  23. package/esm/Options/Classes/DestroyOptions.js +1 -0
  24. package/esm/Options/Interfaces/IDestroy.js +1 -0
  25. package/esm/Types.js +1 -0
  26. package/esm/Utils.js +36 -0
  27. package/esm/index.js +12 -0
  28. package/esm/package.json +1 -0
  29. package/package.json +100 -0
  30. package/report.html +95 -0
  31. package/tsparticles.interaction.external.destroy.js +367 -0
  32. package/tsparticles.interaction.external.destroy.min.js +2 -0
  33. package/types/Destroyer.d.ts +14 -0
  34. package/types/Options/Classes/Destroy.d.ts +7 -0
  35. package/types/Options/Classes/DestroyOptions.d.ts +7 -0
  36. package/types/Options/Interfaces/IDestroy.d.ts +3 -0
  37. package/types/Types.d.ts +16 -0
  38. package/types/Utils.d.ts +5 -0
  39. package/types/index.d.ts +4 -0
package/799.min.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";(this.webpackChunk_tsparticles_interaction_external_destroy=this.webpackChunk_tsparticles_interaction_external_destroy||[]).push([[799],{799(e,t,i){i.d(t,{Destroyer:()=>c});var o=i(702),n=i(303);function s(e,t){for(let i of e.particles.grid.query(t))i.destroy()}var r=i(198);let a="destroy";class c extends o.ExternalInteractorBase{_maxDistance;constructor(e){super(e),this._maxDistance=0}get maxDistance(){return this._maxDistance}clear(){}init(){let e=this.container,t=e.actualOptions.interactivity?.modes.destroy;t&&(this._maxDistance=t.distance,e.retina.destroyModeDistance=t.distance*e.retina.pixelRatio)}interact(e){var t,i;let r=this.container.actualOptions,c=r.interactivity?.events,l=e.status===o.mouseMoveEvent;if(!c)return;let d=c.onHover.enable,f=c.onHover.mode,u=c.onDiv;if(l&&d&&(0,n.isInArray)(a,f)){let i,o,r;t=this.container,i=t.retina.pixelRatio,o=e.mouse.position,(r=t.retina.destroyModeDistance)&&!(r<0)&&o&&s(t,new n.Circle(o.x,o.y,r+10*i))}else i=this.container,(0,o.divModeExecute)(a,u,(e,t)=>{let r;(r=(0,n.safeDocument)().querySelectorAll(e)).length&&r.forEach(e=>{let r=i.retina.pixelRatio,a={x:(e.offsetLeft+.5*e.offsetWidth)*r,y:(e.offsetTop+.5*e.offsetHeight)*r},c=.5*e.offsetWidth*r,l=10*r;s(i,t.type===o.DivType.circle?new n.Circle(a.x,a.y,c+l):new n.Rectangle(e.offsetLeft*r-l,e.offsetTop*r-l,e.offsetWidth*r+l*n.double,e.offsetHeight*r+l*n.double))})})}isEnabled(e,t){let i=this.container.actualOptions,s=e.mouse,r=(t?.interactivity??i.interactivity)?.events;if(!r)return!1;let c=r.onDiv;return!!s.position&&r.onHover.enable&&(0,n.isInArray)(a,r.onHover.mode)||(0,o.isDivModeEnabled)(a,c)}loadModeOptions(e,...t){for(let i of(e.destroy??=new r.F,t))e.destroy.load(i?.destroy)}reset(){}}}}]);
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2025 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,121 @@
1
+ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
+
3
+ # tsParticles External Destroy Interaction
4
+
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/interaction-external-destroy/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/interaction-external-destroy)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/interaction-external-destroy.svg)](https://www.npmjs.com/package/@tsparticles/interaction-external-destroy)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/interaction-external-destroy)](https://www.npmjs.com/package/@tsparticles/interaction-external-destroy) [![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 destroy effect around mouse or HTML
10
+ elements.
11
+
12
+ ## Quick checklist
13
+
14
+ 1. Install `@tsparticles/engine` (or use the CDN bundle below)
15
+ 2. Call the package loader function(s) before `tsParticles.load(...)`
16
+ 3. Apply the package options in your `tsParticles.load(...)` config
17
+
18
+ ## How to use it
19
+
20
+ ### CDN / Vanilla JS / jQuery
21
+
22
+ The CDN/Vanilla version JS has one required file in vanilla configuration:
23
+
24
+ Including the `tsparticles.interaction.external.destroy.min.js` file will export the function to load the interaction
25
+ plugin:
26
+
27
+ ```javascript
28
+ loadExternalDestroyInteraction;
29
+ ```
30
+
31
+ ### Usage
32
+
33
+ Once the scripts are loaded you can set up `tsParticles` and the interaction plugin like this:
34
+
35
+ ```javascript
36
+ (async () => {
37
+ await loadInteractivityPlugin(tsParticles);
38
+ await loadExternalDestroyInteraction(tsParticles);
39
+
40
+ await tsParticles.load({
41
+ id: "tsparticles",
42
+ options: {
43
+ /* options */
44
+ },
45
+ });
46
+ })();
47
+ ```
48
+
49
+ ### ESM / CommonJS
50
+
51
+ This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
52
+
53
+ ```shell
54
+ $ npm install @tsparticles/interaction-external-destroy
55
+ ```
56
+
57
+ or
58
+
59
+ ```shell
60
+ $ yarn add @tsparticles/interaction-external-destroy
61
+ ```
62
+
63
+ Then you need to import it in the app, like this:
64
+
65
+ ```javascript
66
+ const { tsParticles } = require("@tsparticles/engine");
67
+ const { loadInteractivityPlugin } = require("@tsparticles/plugin-interactivity");
68
+ const { loadExternalDestroyInteraction } = require("@tsparticles/interaction-external-destroy");
69
+
70
+ (async () => {
71
+ await loadInteractivityPlugin(tsParticles);
72
+ await loadExternalDestroyInteraction(tsParticles);
73
+ })();
74
+ ```
75
+
76
+ or
77
+
78
+ ```javascript
79
+ import { tsParticles } from "@tsparticles/engine";
80
+ import { loadInteractivityPlugin } from "@tsparticles/plugin-interactivity";
81
+ import { loadExternalDestroyInteraction } from "@tsparticles/interaction-external-destroy";
82
+
83
+ (async () => {
84
+ await loadInteractivityPlugin(tsParticles);
85
+ await loadExternalDestroyInteraction(tsParticles);
86
+ })();
87
+ ```
88
+
89
+ ## Option mapping
90
+
91
+ - Event mode key: `interactivity.events.onHover.mode` with value `"destroy"`
92
+ - Mode options key: `interactivity.modes.destroy`
93
+
94
+ ```json
95
+ {
96
+ "interactivity": {
97
+ "events": {
98
+ "onHover": {
99
+ "enable": true,
100
+ "mode": "destroy"
101
+ }
102
+ },
103
+ "modes": {
104
+ "destroy": {
105
+ "distance": 200
106
+ }
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ ## Common pitfalls
113
+
114
+ - Calling `tsParticles.load(...)` before `loadInteractivityPlugin(...)`
115
+ - Verify required peer packages before enabling advanced options
116
+ - Change one option group at a time to isolate regressions quickly
117
+
118
+ ## Related docs
119
+
120
+ - All packages catalog: <https://github.com/tsparticles/tsparticles>
121
+ - Main docs: <https://particles.js.org/docs/>
@@ -0,0 +1,55 @@
1
+ import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
2
+ import { isInArray } from "@tsparticles/engine";
3
+ import { divDestroy, mouseDestroy } from "./Utils.js";
4
+ import { Destroy } from "./Options/Classes/Destroy.js";
5
+ const destroyMode = "destroy";
6
+ export class Destroyer extends ExternalInteractorBase {
7
+ _maxDistance;
8
+ constructor(container) {
9
+ super(container);
10
+ this._maxDistance = 0;
11
+ }
12
+ get maxDistance() {
13
+ return this._maxDistance;
14
+ }
15
+ clear() {
16
+ }
17
+ init() {
18
+ const container = this.container, destroy = container.actualOptions.interactivity?.modes.destroy;
19
+ if (!destroy) {
20
+ return;
21
+ }
22
+ this._maxDistance = destroy.distance;
23
+ container.retina.destroyModeDistance = destroy.distance * container.retina.pixelRatio;
24
+ }
25
+ interact(interactivityData) {
26
+ const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
27
+ if (!events) {
28
+ return;
29
+ }
30
+ const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
31
+ if (mouseMoveStatus && hoverEnabled && isInArray(destroyMode, hoverMode)) {
32
+ mouseDestroy(this.container, interactivityData);
33
+ }
34
+ else {
35
+ divDestroy(this.container, divs, destroyMode);
36
+ }
37
+ }
38
+ isEnabled(interactivityData, particle) {
39
+ const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
40
+ if (!events) {
41
+ return false;
42
+ }
43
+ const divs = events.onDiv;
44
+ return ((!!mouse.position && events.onHover.enable && isInArray(destroyMode, events.onHover.mode)) ||
45
+ isDivModeEnabled(destroyMode, divs));
46
+ }
47
+ loadModeOptions(options, ...sources) {
48
+ options.destroy ??= new Destroy();
49
+ for (const source of sources) {
50
+ options.destroy.load(source?.destroy);
51
+ }
52
+ }
53
+ reset() {
54
+ }
55
+ }
@@ -0,0 +1,15 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ export class Destroy {
3
+ distance;
4
+ constructor() {
5
+ this.distance = 200;
6
+ }
7
+ load(data) {
8
+ if (isNull(data)) {
9
+ return;
10
+ }
11
+ if (data.distance !== undefined) {
12
+ this.distance = data.distance;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { Circle, Rectangle, double, safeDocument } from "@tsparticles/engine";
2
+ import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
3
+ const half = 0.5, toleranceFactor = 10, minRadius = 0;
4
+ function processDestroy(container, area) {
5
+ const query = container.particles.grid.query(area);
6
+ for (const particle of query) {
7
+ particle.destroy();
8
+ }
9
+ }
10
+ function singleSelectorDestroy(container, selector, div) {
11
+ const query = safeDocument().querySelectorAll(selector);
12
+ if (!query.length) {
13
+ return;
14
+ }
15
+ query.forEach(item => {
16
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
17
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
18
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
19
+ }, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === DivType.circle
20
+ ? new Circle(pos.x, pos.y, radius + tolerance)
21
+ : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
22
+ processDestroy(container, area);
23
+ });
24
+ }
25
+ export function divDestroy(container, divs, destroyMode) {
26
+ divModeExecute(destroyMode, divs, (selector, div) => {
27
+ singleSelectorDestroy(container, selector, div);
28
+ });
29
+ }
30
+ export function mouseDestroy(container, interactivityData) {
31
+ const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.destroyModeDistance;
32
+ if (!radius || radius < minRadius || !mousePos) {
33
+ return;
34
+ }
35
+ processDestroy(container, new Circle(mousePos.x, mousePos.y, radius + tolerance));
36
+ }
@@ -0,0 +1,12 @@
1
+ export async function loadExternalDestroyInteraction(engine) {
2
+ engine.checkVersion("4.0.0-beta.11");
3
+ await engine.pluginManager.register(async (e) => {
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
+ e.pluginManager.addInteractor?.("externalDestroy", async (container) => {
7
+ const { Destroyer } = await import("./Destroyer.js");
8
+ return new Destroyer(container);
9
+ });
10
+ });
11
+ }
12
+ export * from "./Options/Classes/Destroy.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,55 @@
1
+ import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
2
+ import { isInArray } from "@tsparticles/engine";
3
+ import { divDestroy, mouseDestroy } from "./Utils.js";
4
+ import { Destroy } from "./Options/Classes/Destroy.js";
5
+ const destroyMode = "destroy";
6
+ export class Destroyer extends ExternalInteractorBase {
7
+ _maxDistance;
8
+ constructor(container) {
9
+ super(container);
10
+ this._maxDistance = 0;
11
+ }
12
+ get maxDistance() {
13
+ return this._maxDistance;
14
+ }
15
+ clear() {
16
+ }
17
+ init() {
18
+ const container = this.container, destroy = container.actualOptions.interactivity?.modes.destroy;
19
+ if (!destroy) {
20
+ return;
21
+ }
22
+ this._maxDistance = destroy.distance;
23
+ container.retina.destroyModeDistance = destroy.distance * container.retina.pixelRatio;
24
+ }
25
+ interact(interactivityData) {
26
+ const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
27
+ if (!events) {
28
+ return;
29
+ }
30
+ const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
31
+ if (mouseMoveStatus && hoverEnabled && isInArray(destroyMode, hoverMode)) {
32
+ mouseDestroy(this.container, interactivityData);
33
+ }
34
+ else {
35
+ divDestroy(this.container, divs, destroyMode);
36
+ }
37
+ }
38
+ isEnabled(interactivityData, particle) {
39
+ const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
40
+ if (!events) {
41
+ return false;
42
+ }
43
+ const divs = events.onDiv;
44
+ return ((!!mouse.position && events.onHover.enable && isInArray(destroyMode, events.onHover.mode)) ||
45
+ isDivModeEnabled(destroyMode, divs));
46
+ }
47
+ loadModeOptions(options, ...sources) {
48
+ options.destroy ??= new Destroy();
49
+ for (const source of sources) {
50
+ options.destroy.load(source?.destroy);
51
+ }
52
+ }
53
+ reset() {
54
+ }
55
+ }
@@ -0,0 +1,15 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ export class Destroy {
3
+ distance;
4
+ constructor() {
5
+ this.distance = 200;
6
+ }
7
+ load(data) {
8
+ if (isNull(data)) {
9
+ return;
10
+ }
11
+ if (data.distance !== undefined) {
12
+ this.distance = data.distance;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/cjs/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/cjs/Utils.js ADDED
@@ -0,0 +1,36 @@
1
+ import { Circle, Rectangle, double, safeDocument } from "@tsparticles/engine";
2
+ import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
3
+ const half = 0.5, toleranceFactor = 10, minRadius = 0;
4
+ function processDestroy(container, area) {
5
+ const query = container.particles.grid.query(area);
6
+ for (const particle of query) {
7
+ particle.destroy();
8
+ }
9
+ }
10
+ function singleSelectorDestroy(container, selector, div) {
11
+ const query = safeDocument().querySelectorAll(selector);
12
+ if (!query.length) {
13
+ return;
14
+ }
15
+ query.forEach(item => {
16
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
17
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
18
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
19
+ }, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === DivType.circle
20
+ ? new Circle(pos.x, pos.y, radius + tolerance)
21
+ : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
22
+ processDestroy(container, area);
23
+ });
24
+ }
25
+ export function divDestroy(container, divs, destroyMode) {
26
+ divModeExecute(destroyMode, divs, (selector, div) => {
27
+ singleSelectorDestroy(container, selector, div);
28
+ });
29
+ }
30
+ export function mouseDestroy(container, interactivityData) {
31
+ const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.destroyModeDistance;
32
+ if (!radius || radius < minRadius || !mousePos) {
33
+ return;
34
+ }
35
+ processDestroy(container, new Circle(mousePos.x, mousePos.y, radius + tolerance));
36
+ }
package/cjs/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export async function loadExternalDestroyInteraction(engine) {
2
+ engine.checkVersion("4.0.0-beta.11");
3
+ await engine.pluginManager.register(async (e) => {
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
+ e.pluginManager.addInteractor?.("externalDestroy", async (container) => {
7
+ const { Destroyer } = await import("./Destroyer.js");
8
+ return new Destroyer(container);
9
+ });
10
+ });
11
+ }
12
+ export * from "./Options/Classes/Destroy.js";
@@ -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
+ * v4.0.0-beta.11
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_destroy"] = this["webpackChunk_tsparticles_interaction_external_destroy"] || []).push([["dist_browser_Destroyer_js"],{
19
+
20
+ /***/ "./dist/browser/Destroyer.js"
21
+ /*!***********************************!*\
22
+ !*** ./dist/browser/Destroyer.js ***!
23
+ \***********************************/
24
+ (__unused_webpack___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 */ Destroyer: () => (/* binding */ Destroyer)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/plugin-interactivity */ \"@tsparticles/plugin-interactivity\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _Options_Classes_Destroy_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./Options/Classes/Destroy.js */ \"./dist/browser/Options/Classes/Destroy.js\");\n\n\n\n\nconst destroyMode = \"destroy\";\nclass Destroyer extends _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.ExternalInteractorBase {\n _maxDistance;\n constructor(container){\n super(container);\n this._maxDistance = 0;\n }\n get maxDistance() {\n return this._maxDistance;\n }\n clear() {}\n init() {\n const container = this.container, destroy = container.actualOptions.interactivity?.modes.destroy;\n if (!destroy) {\n return;\n }\n this._maxDistance = destroy.distance;\n container.retina.destroyModeDistance = destroy.distance * container.retina.pixelRatio;\n }\n interact(interactivityData) {\n const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.mouseMoveEvent;\n if (!events) {\n return;\n }\n const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;\n if (mouseMoveStatus && hoverEnabled && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.isInArray)(destroyMode, hoverMode)) {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.mouseDestroy)(this.container, interactivityData);\n } else {\n (0,_Utils_js__WEBPACK_IMPORTED_MODULE_2__.divDestroy)(this.container, divs, destroyMode);\n }\n }\n isEnabled(interactivityData, particle) {\n const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;\n if (!events) {\n return false;\n }\n const divs = events.onDiv;\n return !!mouse.position && events.onHover.enable && (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_1__.isInArray)(destroyMode, events.onHover.mode) || (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_0__.isDivModeEnabled)(destroyMode, divs);\n }\n loadModeOptions(options, ...sources) {\n options.destroy ??= new _Options_Classes_Destroy_js__WEBPACK_IMPORTED_MODULE_3__.Destroy();\n for (const source of sources){\n options.destroy.load(source?.destroy);\n }\n }\n reset() {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-destroy/./dist/browser/Destroyer.js?\n}");
27
+
28
+ /***/ },
29
+
30
+ /***/ "./dist/browser/Utils.js"
31
+ /*!*******************************!*\
32
+ !*** ./dist/browser/Utils.js ***!
33
+ \*******************************/
34
+ (__unused_webpack___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 */ divDestroy: () => (/* binding */ divDestroy),\n/* harmony export */ mouseDestroy: () => (/* binding */ mouseDestroy)\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\n\nconst half = 0.5, toleranceFactor = 10, minRadius = 0;\nfunction processDestroy(container, area) {\n const query = container.particles.grid.query(area);\n for (const particle of query){\n particle.destroy();\n }\n}\nfunction singleSelectorDestroy(container, selector, div) {\n const query = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().querySelectorAll(selector);\n if (!query.length) {\n return;\n }\n query.forEach((item)=>{\n const elem = item, pxRatio = container.retina.pixelRatio, pos = {\n x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,\n y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio\n }, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === _tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.DivType.circle ? new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(pos.x, pos.y, radius + tolerance) : new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double, elem.offsetHeight * pxRatio + tolerance * _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.double);\n processDestroy(container, area);\n });\n}\nfunction divDestroy(container, divs, destroyMode) {\n (0,_tsparticles_plugin_interactivity__WEBPACK_IMPORTED_MODULE_1__.divModeExecute)(destroyMode, divs, (selector, div)=>{\n singleSelectorDestroy(container, selector, div);\n });\n}\nfunction mouseDestroy(container, interactivityData) {\n const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.destroyModeDistance;\n if (!radius || radius < minRadius || !mousePos) {\n return;\n }\n processDestroy(container, new _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.Circle(mousePos.x, mousePos.y, radius + tolerance));\n}\n\n\n//# sourceURL=webpack://@tsparticles/interaction-external-destroy/./dist/browser/Utils.js?\n}");
37
+
38
+ /***/ }
39
+
40
+ }]);
@@ -0,0 +1,55 @@
1
+ import { ExternalInteractorBase, isDivModeEnabled, mouseMoveEvent, } from "@tsparticles/plugin-interactivity";
2
+ import { isInArray } from "@tsparticles/engine";
3
+ import { divDestroy, mouseDestroy } from "./Utils.js";
4
+ import { Destroy } from "./Options/Classes/Destroy.js";
5
+ const destroyMode = "destroy";
6
+ export class Destroyer extends ExternalInteractorBase {
7
+ _maxDistance;
8
+ constructor(container) {
9
+ super(container);
10
+ this._maxDistance = 0;
11
+ }
12
+ get maxDistance() {
13
+ return this._maxDistance;
14
+ }
15
+ clear() {
16
+ }
17
+ init() {
18
+ const container = this.container, destroy = container.actualOptions.interactivity?.modes.destroy;
19
+ if (!destroy) {
20
+ return;
21
+ }
22
+ this._maxDistance = destroy.distance;
23
+ container.retina.destroyModeDistance = destroy.distance * container.retina.pixelRatio;
24
+ }
25
+ interact(interactivityData) {
26
+ const container = this.container, options = container.actualOptions, events = options.interactivity?.events, mouseMoveStatus = interactivityData.status === mouseMoveEvent;
27
+ if (!events) {
28
+ return;
29
+ }
30
+ const hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv;
31
+ if (mouseMoveStatus && hoverEnabled && isInArray(destroyMode, hoverMode)) {
32
+ mouseDestroy(this.container, interactivityData);
33
+ }
34
+ else {
35
+ divDestroy(this.container, divs, destroyMode);
36
+ }
37
+ }
38
+ isEnabled(interactivityData, particle) {
39
+ const container = this.container, options = container.actualOptions, mouse = interactivityData.mouse, events = (particle?.interactivity ?? options.interactivity)?.events;
40
+ if (!events) {
41
+ return false;
42
+ }
43
+ const divs = events.onDiv;
44
+ return ((!!mouse.position && events.onHover.enable && isInArray(destroyMode, events.onHover.mode)) ||
45
+ isDivModeEnabled(destroyMode, divs));
46
+ }
47
+ loadModeOptions(options, ...sources) {
48
+ options.destroy ??= new Destroy();
49
+ for (const source of sources) {
50
+ options.destroy.load(source?.destroy);
51
+ }
52
+ }
53
+ reset() {
54
+ }
55
+ }
@@ -0,0 +1,15 @@
1
+ import { isNull } from "@tsparticles/engine";
2
+ export class Destroy {
3
+ distance;
4
+ constructor() {
5
+ this.distance = 200;
6
+ }
7
+ load(data) {
8
+ if (isNull(data)) {
9
+ return;
10
+ }
11
+ if (data.distance !== undefined) {
12
+ this.distance = data.distance;
13
+ }
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/esm/Types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/esm/Utils.js ADDED
@@ -0,0 +1,36 @@
1
+ import { Circle, Rectangle, double, safeDocument } from "@tsparticles/engine";
2
+ import { DivType, divModeExecute } from "@tsparticles/plugin-interactivity";
3
+ const half = 0.5, toleranceFactor = 10, minRadius = 0;
4
+ function processDestroy(container, area) {
5
+ const query = container.particles.grid.query(area);
6
+ for (const particle of query) {
7
+ particle.destroy();
8
+ }
9
+ }
10
+ function singleSelectorDestroy(container, selector, div) {
11
+ const query = safeDocument().querySelectorAll(selector);
12
+ if (!query.length) {
13
+ return;
14
+ }
15
+ query.forEach(item => {
16
+ const elem = item, pxRatio = container.retina.pixelRatio, pos = {
17
+ x: (elem.offsetLeft + elem.offsetWidth * half) * pxRatio,
18
+ y: (elem.offsetTop + elem.offsetHeight * half) * pxRatio,
19
+ }, radius = elem.offsetWidth * half * pxRatio, tolerance = toleranceFactor * pxRatio, area = div.type === DivType.circle
20
+ ? new Circle(pos.x, pos.y, radius + tolerance)
21
+ : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * double, elem.offsetHeight * pxRatio + tolerance * double);
22
+ processDestroy(container, area);
23
+ });
24
+ }
25
+ export function divDestroy(container, divs, destroyMode) {
26
+ divModeExecute(destroyMode, divs, (selector, div) => {
27
+ singleSelectorDestroy(container, selector, div);
28
+ });
29
+ }
30
+ export function mouseDestroy(container, interactivityData) {
31
+ const pxRatio = container.retina.pixelRatio, tolerance = toleranceFactor * pxRatio, mousePos = interactivityData.mouse.position, radius = container.retina.destroyModeDistance;
32
+ if (!radius || radius < minRadius || !mousePos) {
33
+ return;
34
+ }
35
+ processDestroy(container, new Circle(mousePos.x, mousePos.y, radius + tolerance));
36
+ }
package/esm/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export async function loadExternalDestroyInteraction(engine) {
2
+ engine.checkVersion("4.0.0-beta.11");
3
+ await engine.pluginManager.register(async (e) => {
4
+ const { ensureInteractivityPluginLoaded } = await import("@tsparticles/plugin-interactivity");
5
+ ensureInteractivityPluginLoaded(e);
6
+ e.pluginManager.addInteractor?.("externalDestroy", async (container) => {
7
+ const { Destroyer } = await import("./Destroyer.js");
8
+ return new Destroyer(container);
9
+ });
10
+ });
11
+ }
12
+ export * from "./Options/Classes/Destroy.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }