tsparticles-interaction-external-bounce
Advanced tools
+43
-44
@@ -6,2 +6,41 @@ import { Circle, ExternalInteractorBase, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, divModeExecute, isDivModeEnabled, isInArray, mouseMoveEvent, rectBounce, } from "tsparticles-engine"; | ||
| super(container); | ||
| this._processBounce = (position, radius, area) => { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof Circle) { | ||
| circleBounce(circleBounceDataFromParticle(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: Vector.origin, | ||
| factor: Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof Rectangle) { | ||
| rectBounce(particle, calculateBounds(position, radius)); | ||
| } | ||
| } | ||
| }; | ||
| this._processMouseBounce = () => { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this._processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| }; | ||
| this._singleSelectorBounce = (selector, div) => { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new Circle(pos.x, pos.y, radius + tolerance) | ||
| : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this._processBounce(pos, radius, area); | ||
| }); | ||
| }; | ||
| } | ||
@@ -20,11 +59,10 @@ clear() { | ||
| if (mouseMoveStatus && hoverEnabled && isInArray("bounce", hoverMode)) { | ||
| this.processMouseBounce(); | ||
| this._processMouseBounce(); | ||
| } | ||
| else { | ||
| divModeExecute("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div)); | ||
| divModeExecute("bounce", divs, (selector, div) => this._singleSelectorBounce(selector, div)); | ||
| } | ||
| } | ||
| isEnabled(particle) { | ||
| var _a; | ||
| 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, divs = events.onDiv; | ||
| const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv; | ||
| return ((mouse.position && events.onHover.enable && isInArray("bounce", events.onHover.mode)) || | ||
@@ -38,3 +76,3 @@ isDivModeEnabled("bounce", divs)); | ||
| for (const source of sources) { | ||
| options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce); | ||
| options.bounce.load(source?.bounce); | ||
| } | ||
@@ -44,41 +82,2 @@ } | ||
| } | ||
| processBounce(position, radius, area) { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof Circle) { | ||
| circleBounce(circleBounceDataFromParticle(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: Vector.origin, | ||
| factor: Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof Rectangle) { | ||
| rectBounce(particle, calculateBounds(position, radius)); | ||
| } | ||
| } | ||
| } | ||
| processMouseBounce() { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this.processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| } | ||
| singleSelectorBounce(selector, div) { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new Circle(pos.x, pos.y, radius + tolerance) | ||
| : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this.processBounce(pos, radius, area); | ||
| }); | ||
| } | ||
| } |
+49
-61
| "use strict"; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,2 +9,41 @@ exports.Bouncer = void 0; | ||
| super(container); | ||
| this._processBounce = (position, radius, area) => { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof tsparticles_engine_1.Circle) { | ||
| (0, tsparticles_engine_1.circleBounce)((0, tsparticles_engine_1.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: tsparticles_engine_1.Vector.origin, | ||
| factor: tsparticles_engine_1.Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof tsparticles_engine_1.Rectangle) { | ||
| (0, tsparticles_engine_1.rectBounce)(particle, (0, tsparticles_engine_1.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| }; | ||
| this._processMouseBounce = () => { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this._processBounce(mousePos, radius, new tsparticles_engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| }; | ||
| this._singleSelectorBounce = (selector, div) => { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new tsparticles_engine_1.Circle(pos.x, pos.y, radius + tolerance) | ||
| : new tsparticles_engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this._processBounce(pos, radius, area); | ||
| }); | ||
| }; | ||
| } | ||
@@ -29,16 +59,13 @@ clear() { | ||
| } | ||
| interact() { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| const container = this.container, options = container.actualOptions, events = options.interactivity.events, mouseMoveStatus = container.interactivity.status === tsparticles_engine_1.mouseMoveEvent, hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv; | ||
| if (mouseMoveStatus && hoverEnabled && (0, tsparticles_engine_1.isInArray)("bounce", hoverMode)) { | ||
| this.processMouseBounce(); | ||
| } | ||
| else { | ||
| (0, tsparticles_engine_1.divModeExecute)("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div)); | ||
| } | ||
| }); | ||
| async interact() { | ||
| const container = this.container, options = container.actualOptions, events = options.interactivity.events, mouseMoveStatus = container.interactivity.status === tsparticles_engine_1.mouseMoveEvent, hoverEnabled = events.onHover.enable, hoverMode = events.onHover.mode, divs = events.onDiv; | ||
| if (mouseMoveStatus && hoverEnabled && (0, tsparticles_engine_1.isInArray)("bounce", hoverMode)) { | ||
| this._processMouseBounce(); | ||
| } | ||
| else { | ||
| (0, tsparticles_engine_1.divModeExecute)("bounce", divs, (selector, div) => this._singleSelectorBounce(selector, div)); | ||
| } | ||
| } | ||
| isEnabled(particle) { | ||
| var _a; | ||
| 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, divs = events.onDiv; | ||
| const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv; | ||
| return ((mouse.position && events.onHover.enable && (0, tsparticles_engine_1.isInArray)("bounce", events.onHover.mode)) || | ||
@@ -52,3 +79,3 @@ (0, tsparticles_engine_1.isDivModeEnabled)("bounce", divs)); | ||
| for (const source of sources) { | ||
| options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce); | ||
| options.bounce.load(source?.bounce); | ||
| } | ||
@@ -58,42 +85,3 @@ } | ||
| } | ||
| processBounce(position, radius, area) { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof tsparticles_engine_1.Circle) { | ||
| (0, tsparticles_engine_1.circleBounce)((0, tsparticles_engine_1.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: (Math.pow(radius, 2) * Math.PI) / 2, | ||
| velocity: tsparticles_engine_1.Vector.origin, | ||
| factor: tsparticles_engine_1.Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof tsparticles_engine_1.Rectangle) { | ||
| (0, tsparticles_engine_1.rectBounce)(particle, (0, tsparticles_engine_1.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| } | ||
| processMouseBounce() { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this.processBounce(mousePos, radius, new tsparticles_engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| } | ||
| singleSelectorBounce(selector, div) { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new tsparticles_engine_1.Circle(pos.x, pos.y, radius + tolerance) | ||
| : new tsparticles_engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this.processBounce(pos, radius, area); | ||
| }); | ||
| } | ||
| } | ||
| exports.Bouncer = Bouncer; |
+2
-13
@@ -16,18 +16,7 @@ "use strict"; | ||
| }; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| return new (P || (P = Promise))(function (resolve, reject) { | ||
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
| step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
| }); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.loadExternalBounceInteraction = void 0; | ||
| const Bouncer_1 = require("./Bouncer"); | ||
| function loadExternalBounceInteraction(engine) { | ||
| return __awaiter(this, void 0, void 0, function* () { | ||
| yield engine.addInteractor("externalBounce", (container) => new Bouncer_1.Bouncer(container)); | ||
| }); | ||
| async function loadExternalBounceInteraction(engine) { | ||
| await engine.addInteractor("externalBounce", (container) => new Bouncer_1.Bouncer(container)); | ||
| } | ||
@@ -34,0 +23,0 @@ exports.loadExternalBounceInteraction = loadExternalBounceInteraction; |
+43
-44
@@ -6,2 +6,41 @@ import { Circle, ExternalInteractorBase, Rectangle, Vector, calculateBounds, circleBounce, circleBounceDataFromParticle, divModeExecute, isDivModeEnabled, isInArray, mouseMoveEvent, rectBounce, } from "tsparticles-engine"; | ||
| super(container); | ||
| this._processBounce = (position, radius, area) => { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof Circle) { | ||
| circleBounce(circleBounceDataFromParticle(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: Vector.origin, | ||
| factor: Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof Rectangle) { | ||
| rectBounce(particle, calculateBounds(position, radius)); | ||
| } | ||
| } | ||
| }; | ||
| this._processMouseBounce = () => { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this._processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| }; | ||
| this._singleSelectorBounce = (selector, div) => { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new Circle(pos.x, pos.y, radius + tolerance) | ||
| : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this._processBounce(pos, radius, area); | ||
| }); | ||
| }; | ||
| } | ||
@@ -20,11 +59,10 @@ clear() { | ||
| if (mouseMoveStatus && hoverEnabled && isInArray("bounce", hoverMode)) { | ||
| this.processMouseBounce(); | ||
| this._processMouseBounce(); | ||
| } | ||
| else { | ||
| divModeExecute("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div)); | ||
| divModeExecute("bounce", divs, (selector, div) => this._singleSelectorBounce(selector, div)); | ||
| } | ||
| } | ||
| isEnabled(particle) { | ||
| var _a; | ||
| 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, divs = events.onDiv; | ||
| const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv; | ||
| return ((mouse.position && events.onHover.enable && isInArray("bounce", events.onHover.mode)) || | ||
@@ -38,3 +76,3 @@ isDivModeEnabled("bounce", divs)); | ||
| for (const source of sources) { | ||
| options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce); | ||
| options.bounce.load(source?.bounce); | ||
| } | ||
@@ -44,41 +82,2 @@ } | ||
| } | ||
| processBounce(position, radius, area) { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof Circle) { | ||
| circleBounce(circleBounceDataFromParticle(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: Vector.origin, | ||
| factor: Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof Rectangle) { | ||
| rectBounce(particle, calculateBounds(position, radius)); | ||
| } | ||
| } | ||
| } | ||
| processMouseBounce() { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this.processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| } | ||
| singleSelectorBounce(selector, div) { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new Circle(pos.x, pos.y, radius + tolerance) | ||
| : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this.processBounce(pos, radius, area); | ||
| }); | ||
| } | ||
| } |
+2
-2
| { | ||
| "name": "tsparticles-interaction-external-bounce", | ||
| "version": "2.9.3", | ||
| "version": "2.10.0", | ||
| "description": "tsParticles bounce external interaction", | ||
@@ -77,4 +77,4 @@ "homepage": "https://particles.js.org", | ||
| "dependencies": { | ||
| "tsparticles-engine": "^2.9.3" | ||
| "tsparticles-engine": "^2.10.0" | ||
| } | ||
| } |
@@ -7,3 +7,3 @@ /*! | ||
| * How to use? : Check the GitHub README | ||
| * v2.9.3 | ||
| * v2.10.0 | ||
| */ | ||
@@ -95,4 +95,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
| __webpack_require__.d(__webpack_exports__, { | ||
| "Bounce": () => (/* reexport */ Bounce), | ||
| "loadExternalBounceInteraction": () => (/* binding */ loadExternalBounceInteraction) | ||
| Bounce: () => (/* reexport */ Bounce), | ||
| loadExternalBounceInteraction: () => (/* binding */ loadExternalBounceInteraction) | ||
| }); | ||
@@ -122,2 +122,48 @@ | ||
| super(container); | ||
| this._processBounce = (position, radius, area) => { | ||
| const query = this.container.particles.quadTree.query(area, p => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle) { | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounce)((0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: radius ** 2 * Math.PI / 2, | ||
| velocity: external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Vector.origin, | ||
| factor: external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Vector.origin | ||
| }); | ||
| } else if (area instanceof external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Rectangle) { | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.rectBounce)(particle, (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| }; | ||
| this._processMouseBounce = () => { | ||
| const container = this.container, | ||
| pxRatio = container.retina.pixelRatio, | ||
| tolerance = 10 * pxRatio, | ||
| mousePos = container.interactivity.mouse.position, | ||
| radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this._processBounce(mousePos, radius, new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| }; | ||
| this._singleSelectorBounce = (selector, div) => { | ||
| const container = this.container, | ||
| query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach(item => { | ||
| const elem = item, | ||
| pxRatio = container.retina.pixelRatio, | ||
| pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio | ||
| }, | ||
| radius = elem.offsetWidth / 2 * pxRatio, | ||
| tolerance = 10 * pxRatio, | ||
| area = div.type === "circle" ? new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(pos.x, pos.y, radius + tolerance) : new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this._processBounce(pos, radius, area); | ||
| }); | ||
| }; | ||
| } | ||
@@ -142,13 +188,12 @@ clear() {} | ||
| if (mouseMoveStatus && hoverEnabled && (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("bounce", hoverMode)) { | ||
| this.processMouseBounce(); | ||
| this._processMouseBounce(); | ||
| } else { | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.divModeExecute)("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div)); | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.divModeExecute)("bounce", divs, (selector, div) => this._singleSelectorBounce(selector, div)); | ||
| } | ||
| } | ||
| isEnabled(particle) { | ||
| var _a; | ||
| 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, | ||
| events = (particle?.interactivity ?? options.interactivity).events, | ||
| divs = events.onDiv; | ||
@@ -162,52 +207,6 @@ return mouse.position && events.onHover.enable && (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isInArray)("bounce", events.onHover.mode) || (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.isDivModeEnabled)("bounce", divs); | ||
| for (const source of sources) { | ||
| options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce); | ||
| options.bounce.load(source?.bounce); | ||
| } | ||
| } | ||
| reset() {} | ||
| processBounce(position, radius, area) { | ||
| const query = this.container.particles.quadTree.query(area, p => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle) { | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounce)((0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: radius ** 2 * Math.PI / 2, | ||
| velocity: external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Vector.origin, | ||
| factor: external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Vector.origin | ||
| }); | ||
| } else if (area instanceof external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Rectangle) { | ||
| (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.rectBounce)(particle, (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| } | ||
| processMouseBounce() { | ||
| const container = this.container, | ||
| pxRatio = container.retina.pixelRatio, | ||
| tolerance = 10 * pxRatio, | ||
| mousePos = container.interactivity.mouse.position, | ||
| radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this.processBounce(mousePos, radius, new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| } | ||
| singleSelectorBounce(selector, div) { | ||
| const container = this.container, | ||
| query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach(item => { | ||
| const elem = item, | ||
| pxRatio = container.retina.pixelRatio, | ||
| pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio | ||
| }, | ||
| radius = elem.offsetWidth / 2 * pxRatio, | ||
| tolerance = 10 * pxRatio, | ||
| area = div.type === "circle" ? new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Circle(pos.x, pos.y, radius + tolerance) : new external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this.processBounce(pos, radius, area); | ||
| }); | ||
| } | ||
| } | ||
@@ -214,0 +213,0 @@ ;// CONCATENATED MODULE: ./dist/browser/index.js |
| /*! For license information please see tsparticles.interaction.external.bounce.min.js.LICENSE.txt */ | ||
| !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],t);else{var o="object"==typeof exports?t(require("tsparticles-engine")):t(e.window);for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(e=>(()=>{"use strict";var t={961:t=>{t.exports=e}},o={};function n(e){var i=o[e];if(void 0!==i)return i.exports;var r=o[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{Bounce:()=>t,loadExternalBounceInteraction:()=>r});var e=n(961);class t{constructor(){this.distance=200}load(e){e&&void 0!==e.distance&&(this.distance=e.distance)}}class o extends e.ExternalInteractorBase{constructor(e){super(e)}clear(){}init(){const e=this.container,t=e.actualOptions.interactivity.modes.bounce;t&&(e.retina.bounceModeDistance=t.distance*e.retina.pixelRatio)}async interact(){const t=this.container,o=t.actualOptions.interactivity.events,n=t.interactivity.status===e.mouseMoveEvent,i=o.onHover.enable,r=o.onHover.mode,c=o.onDiv;n&&i&&(0,e.isInArray)("bounce",r)?this.processMouseBounce():(0,e.divModeExecute)("bounce",c,((e,t)=>this.singleSelectorBounce(e,t)))}isEnabled(t){var o;const n=this.container,i=n.actualOptions,r=n.interactivity.mouse,c=(null!==(o=null==t?void 0:t.interactivity)&&void 0!==o?o:i.interactivity).events,s=c.onDiv;return r.position&&c.onHover.enable&&(0,e.isInArray)("bounce",c.onHover.mode)||(0,e.isDivModeEnabled)("bounce",s)}loadModeOptions(e,...o){e.bounce||(e.bounce=new t);for(const t of o)e.bounce.load(null==t?void 0:t.bounce)}reset(){}processBounce(t,o,n){const i=this.container.particles.quadTree.query(n,(e=>this.isEnabled(e)));for(const r of i)n instanceof e.Circle?(0,e.circleBounce)((0,e.circleBounceDataFromParticle)(r),{position:t,radius:o,mass:o**2*Math.PI/2,velocity:e.Vector.origin,factor:e.Vector.origin}):n instanceof e.Rectangle&&(0,e.rectBounce)(r,(0,e.calculateBounds)(t,o))}processMouseBounce(){const t=this.container,o=10*t.retina.pixelRatio,n=t.interactivity.mouse.position,i=t.retina.bounceModeDistance;!i||i<0||!n||this.processBounce(n,i,new e.Circle(n.x,n.y,i+o))}singleSelectorBounce(t,o){const n=this.container,i=document.querySelectorAll(t);i.length&&i.forEach((t=>{const i=t,r=n.retina.pixelRatio,c={x:(i.offsetLeft+i.offsetWidth/2)*r,y:(i.offsetTop+i.offsetHeight/2)*r},s=i.offsetWidth/2*r,a=10*r,u="circle"===o.type?new e.Circle(c.x,c.y,s+a):new e.Rectangle(i.offsetLeft*r-a,i.offsetTop*r-a,i.offsetWidth*r+2*a,i.offsetHeight*r+2*a);this.processBounce(c,s,u)}))}}async function r(e){await e.addInteractor("externalBounce",(e=>new o(e)))}})(),i})())); | ||
| !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],t);else{var o="object"==typeof exports?t(require("tsparticles-engine")):t(e.window);for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(e=>(()=>{"use strict";var t={961:t=>{t.exports=e}},o={};function n(e){var i=o[e];if(void 0!==i)return i.exports;var r=o[e]={exports:{}};return t[e](r,r.exports,n),r.exports}n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{n.r(i),n.d(i,{Bounce:()=>t,loadExternalBounceInteraction:()=>r});var e=n(961);class t{constructor(){this.distance=200}load(e){e&&void 0!==e.distance&&(this.distance=e.distance)}}class o extends e.ExternalInteractorBase{constructor(t){super(t),this._processBounce=(t,o,n)=>{const i=this.container.particles.quadTree.query(n,(e=>this.isEnabled(e)));for(const r of i)n instanceof e.Circle?(0,e.circleBounce)((0,e.circleBounceDataFromParticle)(r),{position:t,radius:o,mass:o**2*Math.PI/2,velocity:e.Vector.origin,factor:e.Vector.origin}):n instanceof e.Rectangle&&(0,e.rectBounce)(r,(0,e.calculateBounds)(t,o))},this._processMouseBounce=()=>{const t=this.container,o=10*t.retina.pixelRatio,n=t.interactivity.mouse.position,i=t.retina.bounceModeDistance;!i||i<0||!n||this._processBounce(n,i,new e.Circle(n.x,n.y,i+o))},this._singleSelectorBounce=(t,o)=>{const n=this.container,i=document.querySelectorAll(t);i.length&&i.forEach((t=>{const i=t,r=n.retina.pixelRatio,c={x:(i.offsetLeft+i.offsetWidth/2)*r,y:(i.offsetTop+i.offsetHeight/2)*r},s=i.offsetWidth/2*r,a=10*r,u="circle"===o.type?new e.Circle(c.x,c.y,s+a):new e.Rectangle(i.offsetLeft*r-a,i.offsetTop*r-a,i.offsetWidth*r+2*a,i.offsetHeight*r+2*a);this._processBounce(c,s,u)}))}}clear(){}init(){const e=this.container,t=e.actualOptions.interactivity.modes.bounce;t&&(e.retina.bounceModeDistance=t.distance*e.retina.pixelRatio)}async interact(){const t=this.container,o=t.actualOptions.interactivity.events,n=t.interactivity.status===e.mouseMoveEvent,i=o.onHover.enable,r=o.onHover.mode,c=o.onDiv;n&&i&&(0,e.isInArray)("bounce",r)?this._processMouseBounce():(0,e.divModeExecute)("bounce",c,((e,t)=>this._singleSelectorBounce(e,t)))}isEnabled(t){const o=this.container,n=o.actualOptions,i=o.interactivity.mouse,r=(t?.interactivity??n.interactivity).events,c=r.onDiv;return i.position&&r.onHover.enable&&(0,e.isInArray)("bounce",r.onHover.mode)||(0,e.isDivModeEnabled)("bounce",c)}loadModeOptions(e,...o){e.bounce||(e.bounce=new t);for(const t of o)e.bounce.load(t?.bounce)}reset(){}}async function r(e){await e.addInteractor("externalBounce",(e=>new o(e)))}})(),i})())); |
@@ -1,1 +0,1 @@ | ||
| /*! tsParticles Bounce External Interaction v2.9.3 by Matteo Bruni */ | ||
| /*! tsParticles Bounce External Interaction v2.10.0 by Matteo Bruni */ |
| import type { BounceContainer, BounceMode, IBounceMode } from "./Types"; | ||
| import { ExternalInteractorBase } from "tsparticles-engine"; | ||
| import type { IModes, Modes, Particle, RecursivePartial } from "tsparticles-engine"; | ||
| import { ExternalInteractorBase, type IModes, type Modes, type Particle, type RecursivePartial } from "tsparticles-engine"; | ||
| export declare class Bouncer extends ExternalInteractorBase<BounceContainer> { | ||
@@ -12,5 +11,5 @@ constructor(container: BounceContainer); | ||
| reset(): void; | ||
| private processBounce; | ||
| private processMouseBounce; | ||
| private singleSelectorBounce; | ||
| private readonly _processBounce; | ||
| private readonly _processMouseBounce; | ||
| private readonly _singleSelectorBounce; | ||
| } |
+43
-44
@@ -18,2 +18,41 @@ (function (factory) { | ||
| super(container); | ||
| this._processBounce = (position, radius, area) => { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof tsparticles_engine_1.Circle) { | ||
| (0, tsparticles_engine_1.circleBounce)((0, tsparticles_engine_1.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: tsparticles_engine_1.Vector.origin, | ||
| factor: tsparticles_engine_1.Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof tsparticles_engine_1.Rectangle) { | ||
| (0, tsparticles_engine_1.rectBounce)(particle, (0, tsparticles_engine_1.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| }; | ||
| this._processMouseBounce = () => { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this._processBounce(mousePos, radius, new tsparticles_engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| }; | ||
| this._singleSelectorBounce = (selector, div) => { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new tsparticles_engine_1.Circle(pos.x, pos.y, radius + tolerance) | ||
| : new tsparticles_engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this._processBounce(pos, radius, area); | ||
| }); | ||
| }; | ||
| } | ||
@@ -32,11 +71,10 @@ clear() { | ||
| if (mouseMoveStatus && hoverEnabled && (0, tsparticles_engine_1.isInArray)("bounce", hoverMode)) { | ||
| this.processMouseBounce(); | ||
| this._processMouseBounce(); | ||
| } | ||
| else { | ||
| (0, tsparticles_engine_1.divModeExecute)("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div)); | ||
| (0, tsparticles_engine_1.divModeExecute)("bounce", divs, (selector, div) => this._singleSelectorBounce(selector, div)); | ||
| } | ||
| } | ||
| isEnabled(particle) { | ||
| var _a; | ||
| 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, divs = events.onDiv; | ||
| const container = this.container, options = container.actualOptions, mouse = container.interactivity.mouse, events = (particle?.interactivity ?? options.interactivity).events, divs = events.onDiv; | ||
| return ((mouse.position && events.onHover.enable && (0, tsparticles_engine_1.isInArray)("bounce", events.onHover.mode)) || | ||
@@ -50,3 +88,3 @@ (0, tsparticles_engine_1.isDivModeEnabled)("bounce", divs)); | ||
| for (const source of sources) { | ||
| options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce); | ||
| options.bounce.load(source?.bounce); | ||
| } | ||
@@ -56,43 +94,4 @@ } | ||
| } | ||
| processBounce(position, radius, area) { | ||
| const query = this.container.particles.quadTree.query(area, (p) => this.isEnabled(p)); | ||
| for (const particle of query) { | ||
| if (area instanceof tsparticles_engine_1.Circle) { | ||
| (0, tsparticles_engine_1.circleBounce)((0, tsparticles_engine_1.circleBounceDataFromParticle)(particle), { | ||
| position, | ||
| radius, | ||
| mass: (radius ** 2 * Math.PI) / 2, | ||
| velocity: tsparticles_engine_1.Vector.origin, | ||
| factor: tsparticles_engine_1.Vector.origin, | ||
| }); | ||
| } | ||
| else if (area instanceof tsparticles_engine_1.Rectangle) { | ||
| (0, tsparticles_engine_1.rectBounce)(particle, (0, tsparticles_engine_1.calculateBounds)(position, radius)); | ||
| } | ||
| } | ||
| } | ||
| processMouseBounce() { | ||
| const container = this.container, pxRatio = container.retina.pixelRatio, tolerance = 10 * pxRatio, mousePos = container.interactivity.mouse.position, radius = container.retina.bounceModeDistance; | ||
| if (!radius || radius < 0 || !mousePos) { | ||
| return; | ||
| } | ||
| this.processBounce(mousePos, radius, new tsparticles_engine_1.Circle(mousePos.x, mousePos.y, radius + tolerance)); | ||
| } | ||
| singleSelectorBounce(selector, div) { | ||
| const container = this.container, query = document.querySelectorAll(selector); | ||
| if (!query.length) { | ||
| return; | ||
| } | ||
| query.forEach((item) => { | ||
| const elem = item, pxRatio = container.retina.pixelRatio, pos = { | ||
| x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio, | ||
| y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio, | ||
| }, radius = (elem.offsetWidth / 2) * pxRatio, tolerance = 10 * pxRatio, area = div.type === "circle" | ||
| ? new tsparticles_engine_1.Circle(pos.x, pos.y, radius + tolerance) | ||
| : new tsparticles_engine_1.Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2); | ||
| this.processBounce(pos, radius, area); | ||
| }); | ||
| } | ||
| } | ||
| exports.Bouncer = Bouncer; | ||
| }); |
Sorry, the diff of this file is too big to display
323559
-0.44%787
-3.44%Updated