tsparticles-move-base
Advanced tools
Comparing version 2.9.3 to 2.10.0
@@ -1,14 +0,12 @@ | ||
import { getDistance, getRangeMax, getRangeValue } from "tsparticles-engine"; | ||
import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils"; | ||
import { getDistance, getRangeMax, getRangeValue, } from "tsparticles-engine"; | ||
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils"; | ||
const diffFactor = 2; | ||
export class BaseMover { | ||
init(particle) { | ||
var _a; | ||
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: getRangeValue(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
if (spinOptions.enable) { | ||
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = { | ||
constructor() { | ||
this._initSpin = (particle) => { | ||
const container = particle.container, options = particle.options, spinOptions = options.move.spin; | ||
if (!spinOptions.enable) { | ||
return; | ||
} | ||
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = { | ||
x: (spinPos.x / 100) * container.canvas.size.width, | ||
@@ -25,4 +23,13 @@ y: (spinPos.y / 100) * container.canvas.size.height, | ||
}; | ||
} | ||
}; | ||
} | ||
init(particle) { | ||
const options = particle.options, gravityOptions = options.move.gravity; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: getRangeValue(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
this._initSpin(particle); | ||
} | ||
isEnabled(particle) { | ||
@@ -32,4 +39,2 @@ return !particle.destroyed && particle.options.move.enable; | ||
move(particle, delta) { | ||
var _a, _b, _c; | ||
var _d, _e; | ||
const particleOptions = particle.options, moveOptions = particleOptions.move; | ||
@@ -39,4 +44,4 @@ if (!moveOptions.enable) { | ||
} | ||
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) * | ||
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor; | ||
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) * | ||
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed; | ||
if (moveOptions.spin.enable) { | ||
@@ -46,34 +51,3 @@ spin(particle, moveSpeed); | ||
else { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) { | ||
particle.velocity.y += | ||
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
if (decay != 1) { | ||
particle.velocity.multTo(decay); | ||
} | ||
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
if (zVelocityFactor != 1) { | ||
velocity.multTo(zVelocityFactor); | ||
} | ||
particle.position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y)); | ||
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x)); | ||
} | ||
move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta); | ||
} | ||
@@ -80,0 +54,0 @@ applyDistance(particle); |
@@ -1,4 +0,4 @@ | ||
import { clamp, getDistances, getRandom } from "tsparticles-engine"; | ||
import { clamp, getDistances, getRandom, } from "tsparticles-engine"; | ||
export function applyDistance(particle) { | ||
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical; | ||
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical; | ||
if (!hDistance && !vDistance) { | ||
@@ -29,2 +29,32 @@ return; | ||
} | ||
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1; | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
if (gravityOptions?.enable && moveSpeed) { | ||
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
particle.velocity.multTo(decay); | ||
const velocity = particle.velocity.mult(moveSpeed); | ||
if (gravityOptions?.enable && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
velocity.multTo(zVelocityFactor); | ||
const { position } = particle; | ||
position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
position.x += Math.sin(position.x * Math.cos(position.y)); | ||
position.y += Math.cos(position.y * Math.sin(position.x)); | ||
} | ||
} | ||
export function spin(particle, moveSpeed) { | ||
@@ -54,3 +84,2 @@ const container = particle.container; | ||
export function applyPath(particle, delta) { | ||
var _a; | ||
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable; | ||
@@ -64,3 +93,3 @@ if (!pathEnabled) { | ||
} | ||
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle); | ||
const path = particle.pathGenerator?.generate(particle, delta); | ||
if (path) { | ||
@@ -67,0 +96,0 @@ particle.velocity.addTo(path); |
@@ -6,13 +6,11 @@ "use strict"; | ||
const Utils_1 = require("./Utils"); | ||
const diffFactor = 2; | ||
class BaseMover { | ||
init(particle) { | ||
var _a; | ||
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0, tsparticles_engine_1.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
if (spinOptions.enable) { | ||
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = { | ||
constructor() { | ||
this._initSpin = (particle) => { | ||
const container = particle.container, options = particle.options, spinOptions = options.move.spin; | ||
if (!spinOptions.enable) { | ||
return; | ||
} | ||
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = { | ||
x: (spinPos.x / 100) * container.canvas.size.width, | ||
@@ -29,4 +27,13 @@ y: (spinPos.y / 100) * container.canvas.size.height, | ||
}; | ||
} | ||
}; | ||
} | ||
init(particle) { | ||
const options = particle.options, gravityOptions = options.move.gravity; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0, tsparticles_engine_1.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
this._initSpin(particle); | ||
} | ||
isEnabled(particle) { | ||
@@ -36,4 +43,2 @@ return !particle.destroyed && particle.options.move.enable; | ||
move(particle, delta) { | ||
var _a, _b, _c; | ||
var _d, _e; | ||
const particleOptions = particle.options, moveOptions = particleOptions.move; | ||
@@ -43,4 +48,4 @@ if (!moveOptions.enable) { | ||
} | ||
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, tsparticles_engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) * | ||
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, tsparticles_engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, tsparticles_engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor; | ||
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = (particle.retina.moveSpeed ??= (0, tsparticles_engine_1.getRangeValue)(moveOptions.speed) * pxRatio) * | ||
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= (0, tsparticles_engine_1.getRangeValue)(particle.options.move.drift) * pxRatio), maxSize = (0, tsparticles_engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed; | ||
if (moveOptions.spin.enable) { | ||
@@ -50,34 +55,3 @@ (0, Utils_1.spin)(particle, moveSpeed); | ||
else { | ||
(0, Utils_1.applyPath)(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) { | ||
particle.velocity.y += | ||
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
if (decay != 1) { | ||
particle.velocity.multTo(decay); | ||
} | ||
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = Math.pow((1 - particle.zIndexFactor), zIndexOptions.velocityRate); | ||
if (zVelocityFactor != 1) { | ||
velocity.multTo(zVelocityFactor); | ||
} | ||
particle.position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y)); | ||
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x)); | ||
} | ||
(0, Utils_1.move)(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta); | ||
} | ||
@@ -84,0 +58,0 @@ (0, Utils_1.applyDistance)(particle); |
"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.loadBaseMover = void 0; | ||
const BaseMover_1 = require("./BaseMover"); | ||
function loadBaseMover(engine) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
engine.addMover("base", () => new BaseMover_1.BaseMover()); | ||
}); | ||
async function loadBaseMover(engine) { | ||
engine.addMover("base", () => new BaseMover_1.BaseMover()); | ||
} | ||
exports.loadBaseMover = loadBaseMover; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0; | ||
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0; | ||
const tsparticles_engine_1 = require("tsparticles-engine"); | ||
function applyDistance(particle) { | ||
const initialPosition = particle.initialPosition, { dx, dy } = (0, tsparticles_engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical; | ||
const initialPosition = particle.initialPosition, { dx, dy } = (0, tsparticles_engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical; | ||
if (!hDistance && !vDistance) { | ||
@@ -33,2 +33,33 @@ return; | ||
exports.applyDistance = applyDistance; | ||
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1; | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
if (gravityOptions?.enable && moveSpeed) { | ||
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
particle.velocity.multTo(decay); | ||
const velocity = particle.velocity.mult(moveSpeed); | ||
if (gravityOptions?.enable && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
velocity.multTo(zVelocityFactor); | ||
const { position } = particle; | ||
position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
position.x += Math.sin(position.x * Math.cos(position.y)); | ||
position.y += Math.cos(position.y * Math.sin(position.x)); | ||
} | ||
} | ||
exports.move = move; | ||
function spin(particle, moveSpeed) { | ||
@@ -59,3 +90,2 @@ const container = particle.container; | ||
function applyPath(particle, delta) { | ||
var _a; | ||
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable; | ||
@@ -69,3 +99,3 @@ if (!pathEnabled) { | ||
} | ||
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle); | ||
const path = particle.pathGenerator?.generate(particle, delta); | ||
if (path) { | ||
@@ -72,0 +102,0 @@ particle.velocity.addTo(path); |
@@ -1,14 +0,12 @@ | ||
import { getDistance, getRangeMax, getRangeValue } from "tsparticles-engine"; | ||
import { applyDistance, applyPath, getProximitySpeedFactor, spin } from "./Utils"; | ||
import { getDistance, getRangeMax, getRangeValue, } from "tsparticles-engine"; | ||
import { applyDistance, getProximitySpeedFactor, move, spin } from "./Utils"; | ||
const diffFactor = 2; | ||
export class BaseMover { | ||
init(particle) { | ||
var _a; | ||
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: getRangeValue(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
if (spinOptions.enable) { | ||
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = { | ||
constructor() { | ||
this._initSpin = (particle) => { | ||
const container = particle.container, options = particle.options, spinOptions = options.move.spin; | ||
if (!spinOptions.enable) { | ||
return; | ||
} | ||
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = { | ||
x: (spinPos.x / 100) * container.canvas.size.width, | ||
@@ -25,4 +23,13 @@ y: (spinPos.y / 100) * container.canvas.size.height, | ||
}; | ||
} | ||
}; | ||
} | ||
init(particle) { | ||
const options = particle.options, gravityOptions = options.move.gravity; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: getRangeValue(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
this._initSpin(particle); | ||
} | ||
isEnabled(particle) { | ||
@@ -32,4 +39,2 @@ return !particle.destroyed && particle.options.move.enable; | ||
move(particle, delta) { | ||
var _a, _b, _c; | ||
var _d, _e; | ||
const particleOptions = particle.options, moveOptions = particleOptions.move; | ||
@@ -39,4 +44,4 @@ if (!moveOptions.enable) { | ||
} | ||
const container = particle.container, slowFactor = getProximitySpeedFactor(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio)) * | ||
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor; | ||
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = getProximitySpeedFactor(particle), baseSpeed = (particle.retina.moveSpeed ??= getRangeValue(moveOptions.speed) * pxRatio) * | ||
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= getRangeValue(particle.options.move.drift) * pxRatio), maxSize = getRangeMax(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed; | ||
if (moveOptions.spin.enable) { | ||
@@ -46,34 +51,3 @@ spin(particle, moveSpeed); | ||
else { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) { | ||
particle.velocity.y += | ||
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
if (decay != 1) { | ||
particle.velocity.multTo(decay); | ||
} | ||
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
if (zVelocityFactor != 1) { | ||
velocity.multTo(zVelocityFactor); | ||
} | ||
particle.position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y)); | ||
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x)); | ||
} | ||
move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta); | ||
} | ||
@@ -80,0 +54,0 @@ applyDistance(particle); |
@@ -1,4 +0,4 @@ | ||
import { clamp, getDistances, getRandom } from "tsparticles-engine"; | ||
import { clamp, getDistances, getRandom, } from "tsparticles-engine"; | ||
export function applyDistance(particle) { | ||
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical; | ||
const initialPosition = particle.initialPosition, { dx, dy } = getDistances(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical; | ||
if (!hDistance && !vDistance) { | ||
@@ -29,2 +29,32 @@ return; | ||
} | ||
export function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1; | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
if (gravityOptions?.enable && moveSpeed) { | ||
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
particle.velocity.multTo(decay); | ||
const velocity = particle.velocity.mult(moveSpeed); | ||
if (gravityOptions?.enable && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
velocity.multTo(zVelocityFactor); | ||
const { position } = particle; | ||
position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
position.x += Math.sin(position.x * Math.cos(position.y)); | ||
position.y += Math.cos(position.y * Math.sin(position.x)); | ||
} | ||
} | ||
export function spin(particle, moveSpeed) { | ||
@@ -54,3 +84,2 @@ const container = particle.container; | ||
export function applyPath(particle, delta) { | ||
var _a; | ||
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable; | ||
@@ -64,3 +93,3 @@ if (!pathEnabled) { | ||
} | ||
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle); | ||
const path = particle.pathGenerator?.generate(particle, delta); | ||
if (path) { | ||
@@ -67,0 +96,0 @@ particle.velocity.addTo(path); |
{ | ||
"name": "tsparticles-move-base", | ||
"version": "2.9.3", | ||
"version": "2.10.0", | ||
"description": "tsParticles Base movement", | ||
@@ -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,3 +95,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
__webpack_require__.d(__webpack_exports__, { | ||
"loadBaseMover": () => (/* binding */ loadBaseMover) | ||
loadBaseMover: () => (/* binding */ loadBaseMover) | ||
}); | ||
@@ -111,4 +111,7 @@ | ||
dyFixed = Math.abs(dy), | ||
hDistance = particle.retina.maxDistance.horizontal, | ||
vDistance = particle.retina.maxDistance.vertical; | ||
{ | ||
maxDistance | ||
} = particle.retina, | ||
hDistance = maxDistance.horizontal, | ||
vDistance = maxDistance.vertical; | ||
if (!hDistance && !vDistance) { | ||
@@ -138,2 +141,33 @@ return; | ||
} | ||
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, | ||
gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1; | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed); | ||
} | ||
if (gravityOptions?.enable && moveSpeed) { | ||
particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
particle.velocity.multTo(decay); | ||
const velocity = particle.velocity.mult(moveSpeed); | ||
if (gravityOptions?.enable && maxSpeed > 0 && (!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed)) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, | ||
zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
velocity.multTo(zVelocityFactor); | ||
const { | ||
position | ||
} = particle; | ||
position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
position.x += Math.sin(position.x * Math.cos(position.y)); | ||
position.y += Math.cos(position.y * Math.sin(position.x)); | ||
} | ||
} | ||
function spin(particle, moveSpeed) { | ||
@@ -162,3 +196,2 @@ const container = particle.container; | ||
function applyPath(particle, delta) { | ||
var _a; | ||
const particlesOptions = particle.options, | ||
@@ -174,3 +207,3 @@ pathOptions = particlesOptions.move.path, | ||
} | ||
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle); | ||
const path = particle.pathGenerator?.generate(particle, delta); | ||
if (path) { | ||
@@ -191,16 +224,13 @@ particle.velocity.addTo(path); | ||
const diffFactor = 2; | ||
class BaseMover { | ||
init(particle) { | ||
var _a; | ||
const container = particle.container, | ||
options = particle.options, | ||
gravityOptions = options.move.gravity, | ||
spinOptions = options.move.spin; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse | ||
}; | ||
if (spinOptions.enable) { | ||
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { | ||
constructor() { | ||
this._initSpin = particle => { | ||
const container = particle.container, | ||
options = particle.options, | ||
spinOptions = options.move.spin; | ||
if (!spinOptions.enable) { | ||
return; | ||
} | ||
const spinPos = spinOptions.position ?? { | ||
x: 50, | ||
@@ -224,4 +254,14 @@ y: 50 | ||
}; | ||
} | ||
}; | ||
} | ||
init(particle) { | ||
const options = particle.options, | ||
gravityOptions = options.move.gravity; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse | ||
}; | ||
this._initSpin(particle); | ||
} | ||
isEnabled(particle) { | ||
@@ -231,4 +271,2 @@ return !particle.destroyed && particle.options.move.enable; | ||
move(particle, delta) { | ||
var _a, _b, _c; | ||
var _d, _e; | ||
const particleOptions = particle.options, | ||
@@ -240,44 +278,14 @@ moveOptions = particleOptions.move; | ||
const container = particle.container, | ||
pxRatio = container.retina.pixelRatio, | ||
slowFactor = getProximitySpeedFactor(particle), | ||
baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : _d.moveSpeed = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio) * container.retina.reduceFactor, | ||
moveDrift = (_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : _e.moveDrift = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio, | ||
maxSize = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, | ||
baseSpeed = (particle.retina.moveSpeed ??= (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(moveOptions.speed) * pxRatio) * container.retina.reduceFactor, | ||
moveDrift = particle.retina.moveDrift ??= (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeValue)(particle.options.move.drift) * pxRatio, | ||
maxSize = (0,external_commonjs_tsparticles_engine_commonjs2_tsparticles_engine_amd_tsparticles_engine_root_window_.getRangeMax)(particleOptions.size.value) * pxRatio, | ||
sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, | ||
speedFactor = sizeFactor * slowFactor * (delta.factor || 1), | ||
diffFactor = 2, | ||
moveSpeed = baseSpeed * speedFactor / diffFactor; | ||
moveSpeed = baseSpeed * sizeFactor * slowFactor * (delta.factor || 1) / diffFactor, | ||
maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed; | ||
if (moveOptions.spin.enable) { | ||
spin(particle, moveSpeed); | ||
} else { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, | ||
gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) { | ||
particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (60 * moveSpeed); | ||
} | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
if (decay != 1) { | ||
particle.velocity.multTo(decay); | ||
} | ||
const velocity = particle.velocity.mult(moveSpeed), | ||
maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && maxSpeed > 0 && (!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed)) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, | ||
zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
if (zVelocityFactor != 1) { | ||
velocity.multTo(zVelocityFactor); | ||
} | ||
particle.position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y)); | ||
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x)); | ||
} | ||
move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta); | ||
} | ||
@@ -284,0 +292,0 @@ applyDistance(particle); |
/*! For license information please see tsparticles.move.base.min.js.LICENSE.txt */ | ||
!function(e,i){if("object"==typeof exports&&"object"==typeof module)module.exports=i(require("tsparticles-engine"));else if("function"==typeof define&&define.amd)define(["tsparticles-engine"],i);else{var t="object"==typeof exports?i(require("tsparticles-engine")):i(e.window);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,(e=>(()=>{"use strict";var i={961:i=>{i.exports=e}},t={};function n(e){var o=t[e];if(void 0!==o)return o.exports;var a=t[e]={exports:{}};return i[e](a,a.exports,n),a.exports}n.d=(e,i)=>{for(var t in i)n.o(i,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:i[t]})},n.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{loadBaseMover:()=>t});var e=n(961);class i{init(i){var t;const n=i.container,o=i.options,a=o.move.gravity,s=o.move.spin;if(i.gravity={enable:a.enable,acceleration:(0,e.getRangeValue)(a.acceleration),inverse:a.inverse},s.enable){const o=null!==(t=s.position)&&void 0!==t?t:{x:50,y:50},a={x:o.x/100*n.canvas.size.width,y:o.y/100*n.canvas.size.height},r=i.getPosition(),c=(0,e.getDistance)(r,a),l=(0,e.getRangeValue)(s.acceleration);i.retina.spinAcceleration=l*n.retina.pixelRatio,i.spin={center:a,direction:i.velocity.x>=0?"clockwise":"counter-clockwise",angle:i.velocity.angle,radius:c,acceleration:i.retina.spinAcceleration}}}isEnabled(e){return!e.destroyed&&e.options.move.enable}move(i,t){var n,o,a,s,r;const c=i.options,l=c.move;if(!l.enable)return;const p=i.container,v=function(e){return e.slow.inRange?e.slow.factor:1}(i),y=(null!==(n=(s=i.retina).moveSpeed)&&void 0!==n?n:s.moveSpeed=(0,e.getRangeValue)(l.speed)*p.retina.pixelRatio)*p.retina.reduceFactor,d=null!==(o=(r=i.retina).moveDrift)&&void 0!==o?o:r.moveDrift=(0,e.getRangeValue)(i.options.move.drift)*p.retina.pixelRatio,u=(0,e.getRangeMax)(c.size.value)*p.retina.pixelRatio,x=y*((l.size?i.getRadius()/u:1)*v*(t.factor||1))/2;if(l.spin.enable)!function(e,i){const t=e.container;if(!e.spin)return;const n={x:"clockwise"===e.spin.direction?Math.cos:Math.sin,y:"clockwise"===e.spin.direction?Math.sin:Math.cos};e.position.x=e.spin.center.x+e.spin.radius*n.x(e.spin.angle),e.position.y=e.spin.center.y+e.spin.radius*n.y(e.spin.angle),e.spin.radius+=e.spin.acceleration;const o=Math.max(t.canvas.size.width,t.canvas.size.height);e.spin.radius>o/2?(e.spin.radius=o/2,e.spin.acceleration*=-1):e.spin.radius<0&&(e.spin.radius=0,e.spin.acceleration*=-1),e.spin.angle+=i/100*(1-e.spin.radius/o)}(i,x);else{!function(i,t){var n;const o=i.options.move.path;if(!o.enable)return;if(i.lastPathTime<=i.pathDelay)return void(i.lastPathTime+=t.value);const a=null===(n=i.pathGenerator)||void 0===n?void 0:n.generate(i);a&&i.velocity.addTo(a),o.clamp&&(i.velocity.x=(0,e.clamp)(i.velocity.x,-1,1),i.velocity.y=(0,e.clamp)(i.velocity.y,-1,1)),i.lastPathTime-=i.pathDelay}(i,t);const n=i.gravity,o=(null==n?void 0:n.enable)&&n.inverse?-1:1;(null==n?void 0:n.enable)&&x&&(i.velocity.y+=o*(n.acceleration*t.factor)/(60*x)),d&&x&&(i.velocity.x+=d*t.factor/(60*x));const s=i.moveDecay;1!=s&&i.velocity.multTo(s);const r=i.velocity.mult(x),c=null!==(a=i.retina.maxSpeed)&&void 0!==a?a:p.retina.maxSpeed;(null==n?void 0:n.enable)&&c>0&&(!n.inverse&&r.y>=0&&r.y>=c||n.inverse&&r.y<=0&&r.y<=-c)&&(r.y=o*c,x&&(i.velocity.y=r.y/x));const v=i.options.zIndex,y=(1-i.zIndexFactor)**v.velocityRate;1!=y&&r.multTo(y),i.position.addTo(r),l.vibrate&&(i.position.x+=Math.sin(i.position.x*Math.cos(i.position.y)),i.position.y+=Math.cos(i.position.y*Math.sin(i.position.x)))}!function(i){const t=i.initialPosition,{dx:n,dy:o}=(0,e.getDistances)(t,i.position),a=Math.abs(n),s=Math.abs(o),r=i.retina.maxDistance.horizontal,c=i.retina.maxDistance.vertical;if(r||c)if((r&&a>=r||c&&s>=c)&&!i.misplaced)i.misplaced=!!r&&a>r||!!c&&s>c,r&&(i.velocity.x=i.velocity.y/2-i.velocity.x),c&&(i.velocity.y=i.velocity.x/2-i.velocity.y);else if((!r||a<r)&&(!c||s<c)&&i.misplaced)i.misplaced=!1;else if(i.misplaced){const n=i.position,o=i.velocity;r&&(n.x<t.x&&o.x<0||n.x>t.x&&o.x>0)&&(o.x*=-(0,e.getRandom)()),c&&(n.y<t.y&&o.y<0||n.y>t.y&&o.y>0)&&(o.y*=-(0,e.getRandom)())}}(i)}}async function t(e){e.addMover("base",(()=>new i))}})(),o})())); | ||
!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 i="object"==typeof exports?t(require("tsparticles-engine")):t(e.window);for(var n in i)("object"==typeof exports?exports:e)[n]=i[n]}}(this,(e=>(()=>{"use strict";var t={961:t=>{t.exports=e}},i={};function n(e){var o=i[e];if(void 0!==o)return o.exports;var a=i[e]={exports:{}};return t[e](a,a.exports,n),a.exports}n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},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 o={};return(()=>{n.r(o),n.d(o,{loadBaseMover:()=>a});var e=n(961);function t(t,i,n,o,a,s){!function(t,i){const n=t.options,o=n.move.path;if(!o.enable)return;if(t.lastPathTime<=t.pathDelay)return void(t.lastPathTime+=i.value);const a=t.pathGenerator?.generate(t,i);a&&t.velocity.addTo(a);o.clamp&&(t.velocity.x=(0,e.clamp)(t.velocity.x,-1,1),t.velocity.y=(0,e.clamp)(t.velocity.y,-1,1));t.lastPathTime-=t.pathDelay}(t,s);const c=t.gravity,r=c?.enable&&c.inverse?-1:1;a&&n&&(t.velocity.x+=a*s.factor/(60*n)),c?.enable&&n&&(t.velocity.y+=r*(c.acceleration*s.factor)/(60*n));const l=t.moveDecay;t.velocity.multTo(l);const p=t.velocity.mult(n);c?.enable&&o>0&&(!c.inverse&&p.y>=0&&p.y>=o||c.inverse&&p.y<=0&&p.y<=-o)&&(p.y=r*o,n&&(t.velocity.y=p.y/n));const y=t.options.zIndex,d=(1-t.zIndexFactor)**y.velocityRate;p.multTo(d);const{position:v}=t;v.addTo(p),i.vibrate&&(v.x+=Math.sin(v.x*Math.cos(v.y)),v.y+=Math.cos(v.y*Math.sin(v.x)))}class i{constructor(){this._initSpin=t=>{const i=t.container,n=t.options.move.spin;if(!n.enable)return;const o=n.position??{x:50,y:50},a={x:o.x/100*i.canvas.size.width,y:o.y/100*i.canvas.size.height},s=t.getPosition(),c=(0,e.getDistance)(s,a),r=(0,e.getRangeValue)(n.acceleration);t.retina.spinAcceleration=r*i.retina.pixelRatio,t.spin={center:a,direction:t.velocity.x>=0?"clockwise":"counter-clockwise",angle:t.velocity.angle,radius:c,acceleration:t.retina.spinAcceleration}}}init(t){const i=t.options.move.gravity;t.gravity={enable:i.enable,acceleration:(0,e.getRangeValue)(i.acceleration),inverse:i.inverse},this._initSpin(t)}isEnabled(e){return!e.destroyed&&e.options.move.enable}move(i,n){const o=i.options,a=o.move;if(!a.enable)return;const s=i.container,c=s.retina.pixelRatio,r=function(e){return e.slow.inRange?e.slow.factor:1}(i),l=(i.retina.moveSpeed??=(0,e.getRangeValue)(a.speed)*c)*s.retina.reduceFactor,p=i.retina.moveDrift??=(0,e.getRangeValue)(i.options.move.drift)*c,y=(0,e.getRangeMax)(o.size.value)*c,d=l*(a.size?i.getRadius()/y:1)*r*(n.factor||1)/2,v=i.retina.maxSpeed??s.retina.maxSpeed;a.spin.enable?function(e,t){const i=e.container;if(!e.spin)return;const n={x:"clockwise"===e.spin.direction?Math.cos:Math.sin,y:"clockwise"===e.spin.direction?Math.sin:Math.cos};e.position.x=e.spin.center.x+e.spin.radius*n.x(e.spin.angle),e.position.y=e.spin.center.y+e.spin.radius*n.y(e.spin.angle),e.spin.radius+=e.spin.acceleration;const o=Math.max(i.canvas.size.width,i.canvas.size.height);e.spin.radius>o/2?(e.spin.radius=o/2,e.spin.acceleration*=-1):e.spin.radius<0&&(e.spin.radius=0,e.spin.acceleration*=-1),e.spin.angle+=t/100*(1-e.spin.radius/o)}(i,d):t(i,a,d,v,p,n),function(t){const i=t.initialPosition,{dx:n,dy:o}=(0,e.getDistances)(i,t.position),a=Math.abs(n),s=Math.abs(o),{maxDistance:c}=t.retina,r=c.horizontal,l=c.vertical;if(r||l)if((r&&a>=r||l&&s>=l)&&!t.misplaced)t.misplaced=!!r&&a>r||!!l&&s>l,r&&(t.velocity.x=t.velocity.y/2-t.velocity.x),l&&(t.velocity.y=t.velocity.x/2-t.velocity.y);else if((!r||a<r)&&(!l||s<l)&&t.misplaced)t.misplaced=!1;else if(t.misplaced){const n=t.position,o=t.velocity;r&&(n.x<i.x&&o.x<0||n.x>i.x&&o.x>0)&&(o.x*=-(0,e.getRandom)()),l&&(n.y<i.y&&o.y<0||n.y>i.y&&o.y>0)&&(o.y*=-(0,e.getRandom)())}}(i)}}async function a(e){e.addMover("base",(()=>new i))}})(),o})())); |
@@ -1,1 +0,1 @@ | ||
/*! tsParticles Base Move v2.9.3 by Matteo Bruni */ | ||
/*! tsParticles Base Move v2.10.0 by Matteo Bruni */ |
@@ -1,2 +0,2 @@ | ||
import type { IDelta, IParticleMover, Particle } from "tsparticles-engine"; | ||
import { type IDelta, type IParticleMover, type Particle } from "tsparticles-engine"; | ||
import type { MoveParticle } from "./Types"; | ||
@@ -7,2 +7,3 @@ export declare class BaseMover implements IParticleMover { | ||
move(particle: MoveParticle, delta: IDelta): void; | ||
private readonly _initSpin; | ||
} |
@@ -1,6 +0,7 @@ | ||
import type { IDelta, Particle } from "tsparticles-engine"; | ||
import { type IDelta, type Move, type Particle } from "tsparticles-engine"; | ||
import type { MoveParticle } from "./Types"; | ||
export declare function applyDistance(particle: MoveParticle): void; | ||
export declare function move(particle: MoveParticle, moveOptions: Move, moveSpeed: number, maxSpeed: number, moveDrift: number, delta: IDelta): void; | ||
export declare function spin(particle: MoveParticle, moveSpeed: number): void; | ||
export declare function applyPath(particle: Particle, delta: IDelta): void; | ||
export declare function getProximitySpeedFactor(particle: Particle): number; |
@@ -15,13 +15,11 @@ (function (factory) { | ||
const Utils_1 = require("./Utils"); | ||
const diffFactor = 2; | ||
class BaseMover { | ||
init(particle) { | ||
var _a; | ||
const container = particle.container, options = particle.options, gravityOptions = options.move.gravity, spinOptions = options.move.spin; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0, tsparticles_engine_1.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
if (spinOptions.enable) { | ||
const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : { x: 50, y: 50 }, spinCenter = { | ||
constructor() { | ||
this._initSpin = (particle) => { | ||
const container = particle.container, options = particle.options, spinOptions = options.move.spin; | ||
if (!spinOptions.enable) { | ||
return; | ||
} | ||
const spinPos = spinOptions.position ?? { x: 50, y: 50 }, spinCenter = { | ||
x: (spinPos.x / 100) * container.canvas.size.width, | ||
@@ -38,4 +36,13 @@ y: (spinPos.y / 100) * container.canvas.size.height, | ||
}; | ||
} | ||
}; | ||
} | ||
init(particle) { | ||
const options = particle.options, gravityOptions = options.move.gravity; | ||
particle.gravity = { | ||
enable: gravityOptions.enable, | ||
acceleration: (0, tsparticles_engine_1.getRangeValue)(gravityOptions.acceleration), | ||
inverse: gravityOptions.inverse, | ||
}; | ||
this._initSpin(particle); | ||
} | ||
isEnabled(particle) { | ||
@@ -45,4 +52,2 @@ return !particle.destroyed && particle.options.move.enable; | ||
move(particle, delta) { | ||
var _a, _b, _c; | ||
var _d, _e; | ||
const particleOptions = particle.options, moveOptions = particleOptions.move; | ||
@@ -52,4 +57,4 @@ if (!moveOptions.enable) { | ||
} | ||
const container = particle.container, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : (_d.moveSpeed = (0, tsparticles_engine_1.getRangeValue)(moveOptions.speed) * container.retina.pixelRatio)) * | ||
container.retina.reduceFactor, moveDrift = ((_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : (_e.moveDrift = (0, tsparticles_engine_1.getRangeValue)(particle.options.move.drift) * container.retina.pixelRatio)), maxSize = (0, tsparticles_engine_1.getRangeMax)(particleOptions.size.value) * container.retina.pixelRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, speedFactor = sizeFactor * slowFactor * (delta.factor || 1), diffFactor = 2, moveSpeed = (baseSpeed * speedFactor) / diffFactor; | ||
const container = particle.container, pxRatio = container.retina.pixelRatio, slowFactor = (0, Utils_1.getProximitySpeedFactor)(particle), baseSpeed = (particle.retina.moveSpeed ??= (0, tsparticles_engine_1.getRangeValue)(moveOptions.speed) * pxRatio) * | ||
container.retina.reduceFactor, moveDrift = (particle.retina.moveDrift ??= (0, tsparticles_engine_1.getRangeValue)(particle.options.move.drift) * pxRatio), maxSize = (0, tsparticles_engine_1.getRangeMax)(particleOptions.size.value) * pxRatio, sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1, moveSpeed = (baseSpeed * sizeFactor * slowFactor * (delta.factor || 1)) / diffFactor, maxSpeed = particle.retina.maxSpeed ?? container.retina.maxSpeed; | ||
if (moveOptions.spin.enable) { | ||
@@ -59,34 +64,3 @@ (0, Utils_1.spin)(particle, moveSpeed); | ||
else { | ||
(0, Utils_1.applyPath)(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) { | ||
particle.velocity.y += | ||
(gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
if (decay != 1) { | ||
particle.velocity.multTo(decay); | ||
} | ||
const velocity = particle.velocity.mult(moveSpeed), maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed; | ||
if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
if (zVelocityFactor != 1) { | ||
velocity.multTo(zVelocityFactor); | ||
} | ||
particle.position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y)); | ||
particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x)); | ||
} | ||
(0, Utils_1.move)(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta); | ||
} | ||
@@ -93,0 +67,0 @@ (0, Utils_1.applyDistance)(particle); |
@@ -12,6 +12,6 @@ (function (factory) { | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.applyDistance = void 0; | ||
exports.getProximitySpeedFactor = exports.applyPath = exports.spin = exports.move = exports.applyDistance = void 0; | ||
const tsparticles_engine_1 = require("tsparticles-engine"); | ||
function applyDistance(particle) { | ||
const initialPosition = particle.initialPosition, { dx, dy } = (0, tsparticles_engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), hDistance = particle.retina.maxDistance.horizontal, vDistance = particle.retina.maxDistance.vertical; | ||
const initialPosition = particle.initialPosition, { dx, dy } = (0, tsparticles_engine_1.getDistances)(initialPosition, particle.position), dxFixed = Math.abs(dx), dyFixed = Math.abs(dy), { maxDistance } = particle.retina, hDistance = maxDistance.horizontal, vDistance = maxDistance.vertical; | ||
if (!hDistance && !vDistance) { | ||
@@ -43,2 +43,33 @@ return; | ||
exports.applyDistance = applyDistance; | ||
function move(particle, moveOptions, moveSpeed, maxSpeed, moveDrift, delta) { | ||
applyPath(particle, delta); | ||
const gravityOptions = particle.gravity, gravityFactor = gravityOptions?.enable && gravityOptions.inverse ? -1 : 1; | ||
if (moveDrift && moveSpeed) { | ||
particle.velocity.x += (moveDrift * delta.factor) / (60 * moveSpeed); | ||
} | ||
if (gravityOptions?.enable && moveSpeed) { | ||
particle.velocity.y += (gravityFactor * (gravityOptions.acceleration * delta.factor)) / (60 * moveSpeed); | ||
} | ||
const decay = particle.moveDecay; | ||
particle.velocity.multTo(decay); | ||
const velocity = particle.velocity.mult(moveSpeed); | ||
if (gravityOptions?.enable && | ||
maxSpeed > 0 && | ||
((!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed) || | ||
(gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed))) { | ||
velocity.y = gravityFactor * maxSpeed; | ||
if (moveSpeed) { | ||
particle.velocity.y = velocity.y / moveSpeed; | ||
} | ||
} | ||
const zIndexOptions = particle.options.zIndex, zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate; | ||
velocity.multTo(zVelocityFactor); | ||
const { position } = particle; | ||
position.addTo(velocity); | ||
if (moveOptions.vibrate) { | ||
position.x += Math.sin(position.x * Math.cos(position.y)); | ||
position.y += Math.cos(position.y * Math.sin(position.x)); | ||
} | ||
} | ||
exports.move = move; | ||
function spin(particle, moveSpeed) { | ||
@@ -69,3 +100,2 @@ const container = particle.container; | ||
function applyPath(particle, delta) { | ||
var _a; | ||
const particlesOptions = particle.options, pathOptions = particlesOptions.move.path, pathEnabled = pathOptions.enable; | ||
@@ -79,3 +109,3 @@ if (!pathEnabled) { | ||
} | ||
const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle); | ||
const path = particle.pathGenerator?.generate(particle, delta); | ||
if (path) { | ||
@@ -82,0 +112,0 @@ particle.velocity.addTo(path); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1076
337548
Updatedtsparticles-engine@^2.10.0