@tsparticles/updater-wobble
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-beta.0
import { WobbleUpdater } from "./WobbleUpdater"; | ||
export async function loadWobbleUpdater(engine) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container)); | ||
export async function loadWobbleUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container), refresh); | ||
} |
@@ -0,3 +1,3 @@ | ||
import { isNumber, setRangeValue, } from "@tsparticles/engine"; | ||
import { WobbleSpeed } from "./WobbleSpeed"; | ||
import { setRangeValue } from "@tsparticles/engine"; | ||
export class Wobble { | ||
@@ -20,3 +20,3 @@ constructor() { | ||
if (data.speed !== undefined) { | ||
if (typeof data.speed === "number") { | ||
if (isNumber(data.speed)) { | ||
this.speed.load({ angle: data.speed }); | ||
@@ -23,0 +23,0 @@ } |
@@ -1,17 +0,4 @@ | ||
import { getRandom, getRangeValue } from "@tsparticles/engine"; | ||
import { getRandom, getRangeValue, } from "@tsparticles/engine"; | ||
import { Wobble } from "./Options/Classes/Wobble"; | ||
function updateWobble(particle, delta) { | ||
var _a; | ||
const wobble = particle.options.wobble; | ||
if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) { | ||
return; | ||
} | ||
const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI; | ||
particle.wobble.angle += angleSpeed; | ||
if (particle.wobble.angle > max) { | ||
particle.wobble.angle -= max; | ||
} | ||
particle.position.x += distance * Math.cos(particle.wobble.angle); | ||
particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle)); | ||
} | ||
import { updateWobble } from "./Utils"; | ||
export class WobbleUpdater { | ||
@@ -22,5 +9,4 @@ constructor(container) { | ||
init(particle) { | ||
var _a; | ||
const wobbleOpt = particle.options.wobble; | ||
if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) { | ||
if (wobbleOpt?.enable) { | ||
particle.wobble = { | ||
@@ -39,7 +25,6 @@ angle: getRandom() * Math.PI * 2, | ||
} | ||
particle.retina.wobbleDistance = getRangeValue((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio; | ||
particle.retina.wobbleDistance = getRangeValue(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio; | ||
} | ||
isEnabled(particle) { | ||
var _a; | ||
return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable); | ||
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable; | ||
} | ||
@@ -51,3 +36,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble); | ||
options.wobble.load(source?.wobble); | ||
} | ||
@@ -54,0 +39,0 @@ } |
"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.loadWobbleUpdater = void 0; | ||
const WobbleUpdater_1 = require("./WobbleUpdater"); | ||
function loadWobbleUpdater(engine) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container)); | ||
}); | ||
async function loadWobbleUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container), refresh); | ||
} | ||
exports.loadWobbleUpdater = loadWobbleUpdater; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Wobble = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const WobbleSpeed_1 = require("./WobbleSpeed"); | ||
const engine_1 = require("@tsparticles/engine"); | ||
class Wobble { | ||
@@ -23,3 +23,3 @@ constructor() { | ||
if (data.speed !== undefined) { | ||
if (typeof data.speed === "number") { | ||
if ((0, engine_1.isNumber)(data.speed)) { | ||
this.speed.load({ angle: data.speed }); | ||
@@ -26,0 +26,0 @@ } |
@@ -6,16 +6,3 @@ "use strict"; | ||
const Wobble_1 = require("./Options/Classes/Wobble"); | ||
function updateWobble(particle, delta) { | ||
var _a; | ||
const wobble = particle.options.wobble; | ||
if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) { | ||
return; | ||
} | ||
const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI; | ||
particle.wobble.angle += angleSpeed; | ||
if (particle.wobble.angle > max) { | ||
particle.wobble.angle -= max; | ||
} | ||
particle.position.x += distance * Math.cos(particle.wobble.angle); | ||
particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle)); | ||
} | ||
const Utils_1 = require("./Utils"); | ||
class WobbleUpdater { | ||
@@ -26,5 +13,4 @@ constructor(container) { | ||
init(particle) { | ||
var _a; | ||
const wobbleOpt = particle.options.wobble; | ||
if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) { | ||
if (wobbleOpt?.enable) { | ||
particle.wobble = { | ||
@@ -43,7 +29,6 @@ angle: (0, engine_1.getRandom)() * Math.PI * 2, | ||
} | ||
particle.retina.wobbleDistance = (0, engine_1.getRangeValue)((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio; | ||
particle.retina.wobbleDistance = (0, engine_1.getRangeValue)(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio; | ||
} | ||
isEnabled(particle) { | ||
var _a; | ||
return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable); | ||
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable; | ||
} | ||
@@ -55,3 +40,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble); | ||
options.wobble.load(source?.wobble); | ||
} | ||
@@ -63,5 +48,5 @@ } | ||
} | ||
updateWobble(particle, delta); | ||
(0, Utils_1.updateWobble)(particle, delta); | ||
} | ||
} | ||
exports.WobbleUpdater = WobbleUpdater; |
import { WobbleUpdater } from "./WobbleUpdater"; | ||
export async function loadWobbleUpdater(engine) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container)); | ||
export async function loadWobbleUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater(container), refresh); | ||
} |
@@ -0,3 +1,3 @@ | ||
import { isNumber, setRangeValue, } from "@tsparticles/engine"; | ||
import { WobbleSpeed } from "./WobbleSpeed"; | ||
import { setRangeValue } from "@tsparticles/engine"; | ||
export class Wobble { | ||
@@ -20,3 +20,3 @@ constructor() { | ||
if (data.speed !== undefined) { | ||
if (typeof data.speed === "number") { | ||
if (isNumber(data.speed)) { | ||
this.speed.load({ angle: data.speed }); | ||
@@ -23,0 +23,0 @@ } |
@@ -1,17 +0,4 @@ | ||
import { getRandom, getRangeValue } from "@tsparticles/engine"; | ||
import { getRandom, getRangeValue, } from "@tsparticles/engine"; | ||
import { Wobble } from "./Options/Classes/Wobble"; | ||
function updateWobble(particle, delta) { | ||
var _a; | ||
const wobble = particle.options.wobble; | ||
if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) { | ||
return; | ||
} | ||
const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI; | ||
particle.wobble.angle += angleSpeed; | ||
if (particle.wobble.angle > max) { | ||
particle.wobble.angle -= max; | ||
} | ||
particle.position.x += distance * Math.cos(particle.wobble.angle); | ||
particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle)); | ||
} | ||
import { updateWobble } from "./Utils"; | ||
export class WobbleUpdater { | ||
@@ -22,5 +9,4 @@ constructor(container) { | ||
init(particle) { | ||
var _a; | ||
const wobbleOpt = particle.options.wobble; | ||
if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) { | ||
if (wobbleOpt?.enable) { | ||
particle.wobble = { | ||
@@ -39,7 +25,6 @@ angle: getRandom() * Math.PI * 2, | ||
} | ||
particle.retina.wobbleDistance = getRangeValue((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio; | ||
particle.retina.wobbleDistance = getRangeValue(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio; | ||
} | ||
isEnabled(particle) { | ||
var _a; | ||
return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable); | ||
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable; | ||
} | ||
@@ -51,3 +36,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble); | ||
options.wobble.load(source?.wobble); | ||
} | ||
@@ -54,0 +39,0 @@ } |
{ | ||
"name": "@tsparticles/updater-wobble", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-beta.0", | ||
"description": "tsParticles particles wobble updater", | ||
@@ -76,8 +76,9 @@ "homepage": "https://particles.js.org", | ||
"types": "types/index.d.ts", | ||
"sideEffects": false, | ||
"dependencies": { | ||
"@tsparticles/engine": "^3.0.0-beta.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@tsparticles/engine": "^3.0.0-alpha.1" | ||
} | ||
} | ||
} |
@@ -5,5 +5,5 @@ [![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org) | ||
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-updater-wobble/badge)](https://www.jsdelivr.com/package/npm/tsparticles-updater-wobble) | ||
[![npmjs](https://badge.fury.io/js/tsparticles-updater-wobble.svg)](https://www.npmjs.com/package/tsparticles-updater-wobble) | ||
[![npmjs](https://img.shields.io/npm/dt/tsparticles-updater-wobble)](https://www.npmjs.com/package/tsparticles-updater-wobble) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni) | ||
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/updater-wobble/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/updater-wobble) | ||
[![npmjs](https://badge.fury.io/js/@tsparticles/updater-wobble.svg)](https://www.npmjs.com/package/@tsparticles/updater-wobble) | ||
[![npmjs](https://img.shields.io/npm/dt/@tsparticles/updater-wobble)](https://www.npmjs.com/package/@tsparticles/updater-wobble) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni) | ||
@@ -30,3 +30,3 @@ [tsParticles](https://github.com/matteobruni/tsparticles) updater plugin for wobble animations. | ||
(async () => { | ||
await loadWobbleUpdater(); | ||
await loadWobbleUpdater(tsParticles); | ||
@@ -47,3 +47,3 @@ await tsParticles.load({ | ||
```shell | ||
$ npm install tsparticles-updater-wobble | ||
$ npm install @tsparticles/updater-wobble | ||
``` | ||
@@ -54,3 +54,3 @@ | ||
```shell | ||
$ yarn add tsparticles-updater-wobble | ||
$ yarn add @tsparticles/updater-wobble | ||
``` | ||
@@ -61,6 +61,8 @@ | ||
```javascript | ||
const { tsParticles } = require("tsparticles-engine"); | ||
const { loadWobbleUpdater } = require("tsparticles-updater-wobble"); | ||
const { tsParticles } = require("@tsparticles/engine"); | ||
const { loadWobbleUpdater } = require("@tsparticles/updater-wobble"); | ||
loadWobbleUpdater(tsParticles); | ||
(async () => { | ||
await loadWobbleUpdater(tsParticles); | ||
})(); | ||
``` | ||
@@ -71,6 +73,8 @@ | ||
```javascript | ||
import { tsParticles } from "tsparticles-engine"; | ||
import { loadWobbleUpdater } from "tsparticles-updater-wobble"; | ||
import { tsParticles } from "@tsparticles/engine"; | ||
import { loadWobbleUpdater } from "@tsparticles/updater-wobble"; | ||
loadWobbleUpdater(tsParticles); | ||
(async () => { | ||
await loadWobbleUpdater(tsParticles); | ||
})(); | ||
``` |
@@ -7,3 +7,3 @@ /*! | ||
* How to use? : Check the GitHub README | ||
* v3.0.0-alpha.1 | ||
* v3.0.0-beta.0 | ||
*/ | ||
@@ -95,3 +95,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
__webpack_require__.d(__webpack_exports__, { | ||
"loadWobbleUpdater": () => (/* binding */ loadWobbleUpdater) | ||
loadWobbleUpdater: () => (/* binding */ loadWobbleUpdater) | ||
}); | ||
@@ -140,3 +140,3 @@ | ||
if (data.speed !== undefined) { | ||
if (typeof data.speed === "number") { | ||
if ((0,engine_root_window_.isNumber)(data.speed)) { | ||
this.speed.load({ | ||
@@ -158,22 +158,31 @@ angle: data.speed | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/WobbleUpdater.js | ||
;// CONCATENATED MODULE: ./dist/browser/Utils.js | ||
function updateWobble(particle, delta) { | ||
var _a; | ||
const wobble = particle.options.wobble; | ||
if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) { | ||
const { | ||
wobble: wobbleOptions | ||
} = particle.options, | ||
{ | ||
wobble | ||
} = particle; | ||
if (!wobbleOptions?.enable || !wobble) { | ||
return; | ||
} | ||
const angleSpeed = particle.wobble.angleSpeed * delta.factor, | ||
moveSpeed = particle.wobble.moveSpeed * delta.factor, | ||
distance = moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor) / (1000 / 60), | ||
max = 2 * Math.PI; | ||
particle.wobble.angle += angleSpeed; | ||
if (particle.wobble.angle > max) { | ||
particle.wobble.angle -= max; | ||
const angleSpeed = wobble.angleSpeed * delta.factor, | ||
moveSpeed = wobble.moveSpeed * delta.factor, | ||
distance = moveSpeed * ((particle.retina.wobbleDistance ?? 0) * delta.factor) / (1000 / 60), | ||
max = 2 * Math.PI, | ||
{ | ||
position | ||
} = particle; | ||
wobble.angle += angleSpeed; | ||
if (wobble.angle > max) { | ||
wobble.angle -= max; | ||
} | ||
particle.position.x += distance * Math.cos(particle.wobble.angle); | ||
particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle)); | ||
position.x += distance * Math.cos(wobble.angle); | ||
position.y += distance * Math.abs(Math.sin(wobble.angle)); | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/WobbleUpdater.js | ||
class WobbleUpdater { | ||
@@ -184,5 +193,4 @@ constructor(container) { | ||
init(particle) { | ||
var _a; | ||
const wobbleOpt = particle.options.wobble; | ||
if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) { | ||
if (wobbleOpt?.enable) { | ||
particle.wobble = { | ||
@@ -200,7 +208,6 @@ angle: (0,engine_root_window_.getRandom)() * Math.PI * 2, | ||
} | ||
particle.retina.wobbleDistance = (0,engine_root_window_.getRangeValue)((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio; | ||
particle.retina.wobbleDistance = (0,engine_root_window_.getRangeValue)(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio; | ||
} | ||
isEnabled(particle) { | ||
var _a; | ||
return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable); | ||
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable; | ||
} | ||
@@ -212,3 +219,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble); | ||
options.wobble.load(source?.wobble); | ||
} | ||
@@ -225,4 +232,4 @@ } | ||
async function loadWobbleUpdater(engine) { | ||
await engine.addParticleUpdater("wobble", container => new WobbleUpdater(container)); | ||
async function loadWobbleUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("wobble", container => new WobbleUpdater(container), refresh); | ||
} | ||
@@ -229,0 +236,0 @@ })(); |
/*! For license information please see tsparticles.updater.wobble.min.js.LICENSE.txt */ | ||
!function(e,o){if("object"==typeof exports&&"object"==typeof module)module.exports=o(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],o);else{var t="object"==typeof exports?o(require("@tsparticles/engine")):o(e.window);for(var n in t)("object"==typeof exports?exports:e)[n]=t[n]}}(this,(e=>(()=>{"use strict";var o={533:o=>{o.exports=e}},t={};function n(e){var a=t[e];if(void 0!==a)return a.exports;var l=t[e]={exports:{}};return o[e](l,l.exports,n),l.exports}n.d=(e,o)=>{for(var t in o)n.o(o,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},n.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{n.r(a),n.d(a,{loadWobbleUpdater:()=>i});var e=n(533);class o{constructor(){this.angle=50,this.move=10}load(o){o&&(void 0!==o.angle&&(this.angle=(0,e.setRangeValue)(o.angle)),void 0!==o.move&&(this.move=(0,e.setRangeValue)(o.move)))}}class t{constructor(){this.distance=5,this.enable=!1,this.speed=new o}load(o){if(o&&(void 0!==o.distance&&(this.distance=(0,e.setRangeValue)(o.distance)),void 0!==o.enable&&(this.enable=o.enable),void 0!==o.speed))if("number"==typeof o.speed)this.speed.load({angle:o.speed});else{const e=o.speed;void 0!==e.min?this.speed.load({angle:e}):this.speed.load(o.speed)}}}class l{constructor(e){this.container=e}init(o){var t;const n=o.options.wobble;(null==n?void 0:n.enable)?o.wobble={angle:(0,e.getRandom)()*Math.PI*2,angleSpeed:(0,e.getRangeValue)(n.speed.angle)/360,moveSpeed:(0,e.getRangeValue)(n.speed.move)/10}:o.wobble={angle:0,angleSpeed:0,moveSpeed:0},o.retina.wobbleDistance=(0,e.getRangeValue)(null!==(t=null==n?void 0:n.distance)&&void 0!==t?t:0)*this.container.retina.pixelRatio}isEnabled(e){var o;return!e.destroyed&&!e.spawning&&!!(null===(o=e.options.wobble)||void 0===o?void 0:o.enable)}loadOptions(e,...o){e.wobble||(e.wobble=new t);for(const t of o)e.wobble.load(null==t?void 0:t.wobble)}update(e,o){this.isEnabled(e)&&function(e,o){var t;const n=e.options.wobble;if(!(null==n?void 0:n.enable)||!e.wobble)return;const a=e.wobble.angleSpeed*o.factor,l=e.wobble.moveSpeed*o.factor*((null!==(t=e.retina.wobbleDistance)&&void 0!==t?t:0)*o.factor)/(1e3/60),i=2*Math.PI;e.wobble.angle+=a,e.wobble.angle>i&&(e.wobble.angle-=i),e.position.x+=l*Math.cos(e.wobble.angle),e.position.y+=l*Math.abs(Math.sin(e.wobble.angle))}(e,o)}}async function i(e){await e.addParticleUpdater("wobble",(e=>new l(e)))}})(),a})())); | ||
!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={533:t=>{t.exports=e}},o={};function n(e){var a=o[e];if(void 0!==a)return a.exports;var s=o[e]={exports:{}};return t[e](s,s.exports,n),s.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 a={};return(()=>{n.r(a),n.d(a,{loadWobbleUpdater:()=>i});var e=n(533);class t{constructor(){this.angle=50,this.move=10}load(t){t&&(void 0!==t.angle&&(this.angle=(0,e.setRangeValue)(t.angle)),void 0!==t.move&&(this.move=(0,e.setRangeValue)(t.move)))}}class o{constructor(){this.distance=5,this.enable=!1,this.speed=new t}load(t){if(t&&(void 0!==t.distance&&(this.distance=(0,e.setRangeValue)(t.distance)),void 0!==t.enable&&(this.enable=t.enable),void 0!==t.speed))if((0,e.isNumber)(t.speed))this.speed.load({angle:t.speed});else{const e=t.speed;void 0!==e.min?this.speed.load({angle:e}):this.speed.load(t.speed)}}}class s{constructor(e){this.container=e}init(t){const o=t.options.wobble;t.wobble=o?.enable?{angle:(0,e.getRandom)()*Math.PI*2,angleSpeed:(0,e.getRangeValue)(o.speed.angle)/360,moveSpeed:(0,e.getRangeValue)(o.speed.move)/10}:{angle:0,angleSpeed:0,moveSpeed:0},t.retina.wobbleDistance=(0,e.getRangeValue)(o?.distance??0)*this.container.retina.pixelRatio}isEnabled(e){return!e.destroyed&&!e.spawning&&!!e.options.wobble?.enable}loadOptions(e,...t){e.wobble||(e.wobble=new o);for(const o of t)e.wobble.load(o?.wobble)}update(e,t){this.isEnabled(e)&&function(e,t){const{wobble:o}=e.options,{wobble:n}=e;if(!o?.enable||!n)return;const a=n.angleSpeed*t.factor,s=n.moveSpeed*t.factor*((e.retina.wobbleDistance??0)*t.factor)/(1e3/60),i=2*Math.PI,{position:l}=e;n.angle+=a,n.angle>i&&(n.angle-=i),l.x+=s*Math.cos(n.angle),l.y+=s*Math.abs(Math.sin(n.angle))}(e,t)}}async function i(e,t=!0){await e.addParticleUpdater("wobble",(e=>new s(e)),t)}})(),a})())); |
@@ -1,8 +0,1 @@ | ||
/*! | ||
* Author : Matteo Bruni | ||
* MIT license: https://opensource.org/licenses/MIT | ||
* Demo / Generator : https://particles.js.org/ | ||
* GitHub : https://www.github.com/matteobruni/tsparticles | ||
* How to use? : Check the GitHub README | ||
* v3.0.0-alpha.1 | ||
*/ | ||
/*! tsParticles Wobble Updater v3.0.0-beta.0 by Matteo Bruni */ |
import type { Engine } from "@tsparticles/engine"; | ||
export declare function loadWobbleUpdater(engine: Engine): Promise<void>; | ||
export declare function loadWobbleUpdater(engine: Engine, refresh?: boolean): Promise<void>; |
@@ -1,2 +0,2 @@ | ||
import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine"; | ||
import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine"; | ||
import type { IWobble } from "../Interfaces/IWobble"; | ||
@@ -3,0 +3,0 @@ import { WobbleSpeed } from "./WobbleSpeed"; |
@@ -1,2 +0,2 @@ | ||
import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine"; | ||
import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine"; | ||
import type { IWobbleSpeed } from "../Interfaces/IWobbleSpeed"; | ||
@@ -3,0 +3,0 @@ export declare class WobbleSpeed implements IWobbleSpeed, IOptionLoader<IWobbleSpeed> { |
@@ -1,22 +0,3 @@ | ||
import type { Container, IDelta, IParticleUpdater, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial } from "@tsparticles/engine"; | ||
import type { IWobble } from "./Options/Interfaces/IWobble"; | ||
import { Wobble } from "./Options/Classes/Wobble"; | ||
interface IParticleWobble { | ||
angle: number; | ||
angleSpeed: number; | ||
moveSpeed: number; | ||
} | ||
type WobbleParticle = Particle & { | ||
options: WobbleParticlesOptions; | ||
retina: { | ||
wobbleDistance?: number; | ||
}; | ||
wobble?: IParticleWobble; | ||
}; | ||
type IWobbleParticlesOptions = IParticlesOptions & { | ||
wobble?: IWobble; | ||
}; | ||
type WobbleParticlesOptions = ParticlesOptions & { | ||
wobble?: Wobble; | ||
}; | ||
import { type Container, type IDelta, type IParticleUpdater, type RecursivePartial } from "@tsparticles/engine"; | ||
import type { IWobbleParticlesOptions, WobbleParticle, WobbleParticlesOptions } from "./Types"; | ||
export declare class WobbleUpdater implements IParticleUpdater { | ||
@@ -30,2 +11,1 @@ private readonly container; | ||
} | ||
export {}; |
@@ -14,6 +14,6 @@ (function (factory) { | ||
const WobbleUpdater_1 = require("./WobbleUpdater"); | ||
async function loadWobbleUpdater(engine) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container)); | ||
async function loadWobbleUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("wobble", (container) => new WobbleUpdater_1.WobbleUpdater(container), refresh); | ||
} | ||
exports.loadWobbleUpdater = loadWobbleUpdater; | ||
}); |
@@ -7,3 +7,3 @@ (function (factory) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./WobbleSpeed", "@tsparticles/engine"], factory); | ||
define(["require", "exports", "@tsparticles/engine", "./WobbleSpeed"], factory); | ||
} | ||
@@ -14,4 +14,4 @@ })(function (require, exports) { | ||
exports.Wobble = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const WobbleSpeed_1 = require("./WobbleSpeed"); | ||
const engine_1 = require("@tsparticles/engine"); | ||
class Wobble { | ||
@@ -34,3 +34,3 @@ constructor() { | ||
if (data.speed !== undefined) { | ||
if (typeof data.speed === "number") { | ||
if ((0, engine_1.isNumber)(data.speed)) { | ||
this.speed.load({ angle: data.speed }); | ||
@@ -37,0 +37,0 @@ } |
@@ -7,3 +7,3 @@ (function (factory) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Wobble"], factory); | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Wobble", "./Utils"], factory); | ||
} | ||
@@ -16,16 +16,3 @@ })(function (require, exports) { | ||
const Wobble_1 = require("./Options/Classes/Wobble"); | ||
function updateWobble(particle, delta) { | ||
var _a; | ||
const wobble = particle.options.wobble; | ||
if (!(wobble === null || wobble === void 0 ? void 0 : wobble.enable) || !particle.wobble) { | ||
return; | ||
} | ||
const angleSpeed = particle.wobble.angleSpeed * delta.factor, moveSpeed = particle.wobble.moveSpeed * delta.factor, distance = (moveSpeed * (((_a = particle.retina.wobbleDistance) !== null && _a !== void 0 ? _a : 0) * delta.factor)) / (1000 / 60), max = 2 * Math.PI; | ||
particle.wobble.angle += angleSpeed; | ||
if (particle.wobble.angle > max) { | ||
particle.wobble.angle -= max; | ||
} | ||
particle.position.x += distance * Math.cos(particle.wobble.angle); | ||
particle.position.y += distance * Math.abs(Math.sin(particle.wobble.angle)); | ||
} | ||
const Utils_1 = require("./Utils"); | ||
class WobbleUpdater { | ||
@@ -36,5 +23,4 @@ constructor(container) { | ||
init(particle) { | ||
var _a; | ||
const wobbleOpt = particle.options.wobble; | ||
if (wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.enable) { | ||
if (wobbleOpt?.enable) { | ||
particle.wobble = { | ||
@@ -53,7 +39,6 @@ angle: (0, engine_1.getRandom)() * Math.PI * 2, | ||
} | ||
particle.retina.wobbleDistance = (0, engine_1.getRangeValue)((_a = wobbleOpt === null || wobbleOpt === void 0 ? void 0 : wobbleOpt.distance) !== null && _a !== void 0 ? _a : 0) * this.container.retina.pixelRatio; | ||
particle.retina.wobbleDistance = (0, engine_1.getRangeValue)(wobbleOpt?.distance ?? 0) * this.container.retina.pixelRatio; | ||
} | ||
isEnabled(particle) { | ||
var _a; | ||
return !particle.destroyed && !particle.spawning && !!((_a = particle.options.wobble) === null || _a === void 0 ? void 0 : _a.enable); | ||
return !particle.destroyed && !particle.spawning && !!particle.options.wobble?.enable; | ||
} | ||
@@ -65,3 +50,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.wobble.load(source === null || source === void 0 ? void 0 : source.wobble); | ||
options.wobble.load(source?.wobble); | ||
} | ||
@@ -73,3 +58,3 @@ } | ||
} | ||
updateWobble(particle, delta); | ||
(0, Utils_1.updateWobble)(particle, delta); | ||
} | ||
@@ -76,0 +61,0 @@ } |
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
47
872
75
317917