@tsparticles/updater-tilt
Advanced tools
Comparing version 3.0.0-alpha.1 to 3.0.0-beta.0
import { TiltUpdater } from "./TiltUpdater"; | ||
export async function loadTiltUpdater(engine) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container)); | ||
export async function loadTiltUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container), refresh); | ||
} |
@@ -0,3 +1,3 @@ | ||
import { ValueWithRandom } from "@tsparticles/engine"; | ||
import { TiltAnimation } from "./TiltAnimation"; | ||
import { ValueWithRandom } from "@tsparticles/engine"; | ||
export class Tilt extends ValueWithRandom { | ||
@@ -4,0 +4,0 @@ constructor() { |
@@ -1,31 +0,4 @@ | ||
import { getRandom, getRangeValue } from "@tsparticles/engine"; | ||
import { getRandom, getRangeValue, } from "@tsparticles/engine"; | ||
import { Tilt } from "./Options/Classes/Tilt"; | ||
function updateTilt(particle, delta) { | ||
var _a, _b; | ||
if (!particle.tilt || !particle.options.tilt) { | ||
return; | ||
} | ||
const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1; | ||
if (!tiltAnimation.enable) { | ||
return; | ||
} | ||
switch (particle.tilt.status) { | ||
case "increasing": | ||
particle.tilt.value += speed; | ||
if (particle.tilt.value > max) { | ||
particle.tilt.value -= max; | ||
} | ||
break; | ||
case "decreasing": | ||
default: | ||
particle.tilt.value -= speed; | ||
if (particle.tilt.value < 0) { | ||
particle.tilt.value += max; | ||
} | ||
break; | ||
} | ||
if (particle.tilt.velocity && decay !== 1) { | ||
particle.tilt.velocity *= decay; | ||
} | ||
} | ||
import { updateTilt } from "./Utils"; | ||
export class TiltUpdater { | ||
@@ -36,4 +9,3 @@ constructor(container) { | ||
getTransformValues(particle) { | ||
var _a; | ||
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt; | ||
const tilt = particle.tilt?.enable && particle.tilt; | ||
return { | ||
@@ -45,3 +17,2 @@ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined, | ||
init(particle) { | ||
var _a; | ||
const tiltOptions = particle.options.tilt; | ||
@@ -71,4 +42,4 @@ if (!tiltOptions) { | ||
} | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) { | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
if (tiltAnimation?.enable) { | ||
particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay); | ||
@@ -82,5 +53,4 @@ particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor; | ||
isEnabled(particle) { | ||
var _a; | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable); | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable; | ||
} | ||
@@ -92,3 +62,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt); | ||
options.tilt.load(source?.tilt); | ||
} | ||
@@ -95,0 +65,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.loadTiltUpdater = void 0; | ||
const TiltUpdater_1 = require("./TiltUpdater"); | ||
function loadTiltUpdater(engine) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container)); | ||
}); | ||
async function loadTiltUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container), refresh); | ||
} | ||
exports.loadTiltUpdater = loadTiltUpdater; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Tilt = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const TiltAnimation_1 = require("./TiltAnimation"); | ||
const engine_1 = require("@tsparticles/engine"); | ||
class Tilt extends engine_1.ValueWithRandom { | ||
@@ -7,0 +7,0 @@ constructor() { |
@@ -6,30 +6,3 @@ "use strict"; | ||
const Tilt_1 = require("./Options/Classes/Tilt"); | ||
function updateTilt(particle, delta) { | ||
var _a, _b; | ||
if (!particle.tilt || !particle.options.tilt) { | ||
return; | ||
} | ||
const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1; | ||
if (!tiltAnimation.enable) { | ||
return; | ||
} | ||
switch (particle.tilt.status) { | ||
case "increasing": | ||
particle.tilt.value += speed; | ||
if (particle.tilt.value > max) { | ||
particle.tilt.value -= max; | ||
} | ||
break; | ||
case "decreasing": | ||
default: | ||
particle.tilt.value -= speed; | ||
if (particle.tilt.value < 0) { | ||
particle.tilt.value += max; | ||
} | ||
break; | ||
} | ||
if (particle.tilt.velocity && decay !== 1) { | ||
particle.tilt.velocity *= decay; | ||
} | ||
} | ||
const Utils_1 = require("./Utils"); | ||
class TiltUpdater { | ||
@@ -40,4 +13,3 @@ constructor(container) { | ||
getTransformValues(particle) { | ||
var _a; | ||
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt; | ||
const tilt = particle.tilt?.enable && particle.tilt; | ||
return { | ||
@@ -49,3 +21,2 @@ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined, | ||
init(particle) { | ||
var _a; | ||
const tiltOptions = particle.options.tilt; | ||
@@ -75,4 +46,4 @@ if (!tiltOptions) { | ||
} | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) { | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
if (tiltAnimation?.enable) { | ||
particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay); | ||
@@ -86,5 +57,4 @@ particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor; | ||
isEnabled(particle) { | ||
var _a; | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable); | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable; | ||
} | ||
@@ -96,3 +66,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt); | ||
options.tilt.load(source?.tilt); | ||
} | ||
@@ -104,5 +74,5 @@ } | ||
} | ||
updateTilt(particle, delta); | ||
(0, Utils_1.updateTilt)(particle, delta); | ||
} | ||
} | ||
exports.TiltUpdater = TiltUpdater; |
import { TiltUpdater } from "./TiltUpdater"; | ||
export async function loadTiltUpdater(engine) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container)); | ||
export async function loadTiltUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater(container), refresh); | ||
} |
@@ -0,3 +1,3 @@ | ||
import { ValueWithRandom } from "@tsparticles/engine"; | ||
import { TiltAnimation } from "./TiltAnimation"; | ||
import { ValueWithRandom } from "@tsparticles/engine"; | ||
export class Tilt extends ValueWithRandom { | ||
@@ -4,0 +4,0 @@ constructor() { |
@@ -1,31 +0,4 @@ | ||
import { getRandom, getRangeValue } from "@tsparticles/engine"; | ||
import { getRandom, getRangeValue, } from "@tsparticles/engine"; | ||
import { Tilt } from "./Options/Classes/Tilt"; | ||
function updateTilt(particle, delta) { | ||
var _a, _b; | ||
if (!particle.tilt || !particle.options.tilt) { | ||
return; | ||
} | ||
const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1; | ||
if (!tiltAnimation.enable) { | ||
return; | ||
} | ||
switch (particle.tilt.status) { | ||
case "increasing": | ||
particle.tilt.value += speed; | ||
if (particle.tilt.value > max) { | ||
particle.tilt.value -= max; | ||
} | ||
break; | ||
case "decreasing": | ||
default: | ||
particle.tilt.value -= speed; | ||
if (particle.tilt.value < 0) { | ||
particle.tilt.value += max; | ||
} | ||
break; | ||
} | ||
if (particle.tilt.velocity && decay !== 1) { | ||
particle.tilt.velocity *= decay; | ||
} | ||
} | ||
import { updateTilt } from "./Utils"; | ||
export class TiltUpdater { | ||
@@ -36,4 +9,3 @@ constructor(container) { | ||
getTransformValues(particle) { | ||
var _a; | ||
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt; | ||
const tilt = particle.tilt?.enable && particle.tilt; | ||
return { | ||
@@ -45,3 +17,2 @@ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined, | ||
init(particle) { | ||
var _a; | ||
const tiltOptions = particle.options.tilt; | ||
@@ -71,4 +42,4 @@ if (!tiltOptions) { | ||
} | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) { | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
if (tiltAnimation?.enable) { | ||
particle.tilt.decay = 1 - getRangeValue(tiltAnimation.decay); | ||
@@ -82,5 +53,4 @@ particle.tilt.velocity = (getRangeValue(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor; | ||
isEnabled(particle) { | ||
var _a; | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable); | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable; | ||
} | ||
@@ -92,3 +62,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt); | ||
options.tilt.load(source?.tilt); | ||
} | ||
@@ -95,0 +65,0 @@ } |
{ | ||
"name": "@tsparticles/updater-tilt", | ||
"version": "3.0.0-alpha.1", | ||
"version": "3.0.0-beta.0", | ||
"description": "tsParticles particles tilt 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-tilt/badge)](https://www.jsdelivr.com/package/npm/tsparticles-updater-tilt) | ||
[![npmjs](https://badge.fury.io/js/tsparticles-updater-tilt.svg)](https://www.npmjs.com/package/tsparticles-updater-tilt) | ||
[![npmjs](https://img.shields.io/npm/dt/tsparticles-updater-tilt)](https://www.npmjs.com/package/tsparticles-updater-tilt) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni) | ||
[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/updater-tilt/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/updater-tilt) | ||
[![npmjs](https://badge.fury.io/js/@tsparticles/updater-tilt.svg)](https://www.npmjs.com/package/@tsparticles/updater-tilt) | ||
[![npmjs](https://img.shields.io/npm/dt/@tsparticles/updater-tilt)](https://www.npmjs.com/package/@tsparticles/updater-tilt) [![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 tilt animations. | ||
(async () => { | ||
await loadTiltUpdater(); | ||
await loadTiltUpdater(tsParticles); | ||
@@ -47,3 +47,3 @@ await tsParticles.load({ | ||
```shell | ||
$ npm install tsparticles-updater-tilt | ||
$ npm install @tsparticles/updater-tilt | ||
``` | ||
@@ -54,3 +54,3 @@ | ||
```shell | ||
$ yarn add tsparticles-updater-tilt | ||
$ yarn add @tsparticles/updater-tilt | ||
``` | ||
@@ -61,6 +61,8 @@ | ||
```javascript | ||
const { tsParticles } = require("tsparticles-engine"); | ||
const { loadTiltUpdater } = require("tsparticles-updater-tilt"); | ||
const { tsParticles } = require("@tsparticles/engine"); | ||
const { loadTiltUpdater } = require("@tsparticles/updater-tilt"); | ||
loadTiltUpdater(tsParticles); | ||
(async () => { | ||
await loadTiltUpdater(tsParticles); | ||
})(); | ||
``` | ||
@@ -71,6 +73,8 @@ | ||
```javascript | ||
import { tsParticles } from "tsparticles-engine"; | ||
import { loadTiltUpdater } from "tsparticles-updater-tilt"; | ||
import { tsParticles } from "@tsparticles/engine"; | ||
import { loadTiltUpdater } from "@tsparticles/updater-tilt"; | ||
loadTiltUpdater(tsParticles); | ||
(async () => { | ||
await loadTiltUpdater(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__, { | ||
"loadTiltUpdater": () => (/* binding */ loadTiltUpdater) | ||
loadTiltUpdater: () => (/* binding */ loadTiltUpdater) | ||
}); | ||
@@ -153,7 +153,4 @@ | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/TiltUpdater.js | ||
;// CONCATENATED MODULE: ./dist/browser/Utils.js | ||
function updateTilt(particle, delta) { | ||
var _a, _b; | ||
if (!particle.tilt || !particle.options.tilt) { | ||
@@ -164,5 +161,5 @@ return; | ||
tiltAnimation = tilt.animation, | ||
speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, | ||
speed = (particle.tilt.velocity ?? 0) * delta.factor, | ||
max = 2 * Math.PI, | ||
decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1; | ||
decay = particle.tilt.decay ?? 1; | ||
if (!tiltAnimation.enable) { | ||
@@ -190,2 +187,6 @@ return; | ||
} | ||
;// CONCATENATED MODULE: ./dist/browser/TiltUpdater.js | ||
class TiltUpdater { | ||
@@ -196,4 +197,3 @@ constructor(container) { | ||
getTransformValues(particle) { | ||
var _a; | ||
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt; | ||
const tilt = particle.tilt?.enable && particle.tilt; | ||
return { | ||
@@ -205,3 +205,2 @@ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined, | ||
init(particle) { | ||
var _a; | ||
const tiltOptions = particle.options.tilt; | ||
@@ -231,4 +230,4 @@ if (!tiltOptions) { | ||
} | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) { | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
if (tiltAnimation?.enable) { | ||
particle.tilt.decay = 1 - (0,engine_root_window_.getRangeValue)(tiltAnimation.decay); | ||
@@ -242,5 +241,4 @@ particle.tilt.velocity = (0,engine_root_window_.getRangeValue)(tiltAnimation.speed) / 360 * this.container.retina.reduceFactor; | ||
isEnabled(particle) { | ||
var _a; | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable); | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable; | ||
} | ||
@@ -252,3 +250,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt); | ||
options.tilt.load(source?.tilt); | ||
} | ||
@@ -265,4 +263,4 @@ } | ||
async function loadTiltUpdater(engine) { | ||
await engine.addParticleUpdater("tilt", container => new TiltUpdater(container)); | ||
async function loadTiltUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("tilt", container => new TiltUpdater(container), refresh); | ||
} | ||
@@ -269,0 +267,0 @@ })(); |
/*! For license information please see tsparticles.updater.tilt.min.js.LICENSE.txt */ | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var a=i[t]={exports:{}};return e[t](a,a.exports,o),a.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadTiltUpdater:()=>l});var t=o(533);class e{constructor(){this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(e){e&&(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,t.setRangeValue)(e.speed)),void 0!==e.decay&&(this.decay=(0,t.setRangeValue)(e.decay)),void 0!==e.sync&&(this.sync=e.sync))}}class i extends t.ValueWithRandom{constructor(){super(),this.animation=new e,this.direction="clockwise",this.enable=!1,this.value=0}load(t){super.load(t),t&&(this.animation.load(t.animation),void 0!==t.direction&&(this.direction=t.direction),void 0!==t.enable&&(this.enable=t.enable))}}class a{constructor(t){this.container=t}getTransformValues(t){var e;const i=(null===(e=t.tilt)||void 0===e?void 0:e.enable)&&t.tilt;return{b:i?Math.cos(i.value)*i.cosDirection:void 0,c:i?Math.sin(i.value)*i.sinDirection:void 0}}init(e){var i;const o=e.options.tilt;if(!o)return;e.tilt={enable:o.enable,value:(0,t.getRangeValue)(o.value)*Math.PI/180,sinDirection:(0,t.getRandom)()>=.5?1:-1,cosDirection:(0,t.getRandom)()>=.5?1:-1};let n=o.direction;if("random"===n){n=Math.floor(2*(0,t.getRandom)())>0?"counter-clockwise":"clockwise"}switch(n){case"counter-clockwise":case"counterClockwise":e.tilt.status="decreasing";break;case"clockwise":e.tilt.status="increasing"}const a=null===(i=e.options.tilt)||void 0===i?void 0:i.animation;(null==a?void 0:a.enable)&&(e.tilt.decay=1-(0,t.getRangeValue)(a.decay),e.tilt.velocity=(0,t.getRangeValue)(a.speed)/360*this.container.retina.reduceFactor,a.sync||(e.tilt.velocity*=(0,t.getRandom)()))}isEnabled(t){var e;const i=null===(e=t.options.tilt)||void 0===e?void 0:e.animation;return!t.destroyed&&!t.spawning&&!!(null==i?void 0:i.enable)}loadOptions(t,...e){t.tilt||(t.tilt=new i);for(const i of e)t.tilt.load(null==i?void 0:i.tilt)}update(t,e){this.isEnabled(t)&&function(t,e){var i,o;if(!t.tilt||!t.options.tilt)return;const n=t.options.tilt.animation,a=(null!==(i=t.tilt.velocity)&&void 0!==i?i:0)*e.factor,l=2*Math.PI,s=null!==(o=t.tilt.decay)&&void 0!==o?o:1;n.enable&&("increasing"===t.tilt.status?(t.tilt.value+=a,t.tilt.value>l&&(t.tilt.value-=l)):(t.tilt.value-=a,t.tilt.value<0&&(t.tilt.value+=l)),t.tilt.velocity&&1!==s&&(t.tilt.velocity*=s))}(t,e)}}async function l(t){await t.addParticleUpdater("tilt",(t=>new a(t)))}})(),n})())); | ||
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,(t=>(()=>{"use strict";var e={533:e=>{e.exports=t}},i={};function o(t){var n=i[t];if(void 0!==n)return n.exports;var a=i[t]={exports:{}};return e[t](a,a.exports,o),a.exports}o.d=(t,e)=>{for(var i in e)o.o(e,i)&&!o.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return(()=>{o.r(n),o.d(n,{loadTiltUpdater:()=>s});var t=o(533);class e{constructor(){this.enable=!1,this.speed=0,this.decay=0,this.sync=!1}load(e){e&&(void 0!==e.enable&&(this.enable=e.enable),void 0!==e.speed&&(this.speed=(0,t.setRangeValue)(e.speed)),void 0!==e.decay&&(this.decay=(0,t.setRangeValue)(e.decay)),void 0!==e.sync&&(this.sync=e.sync))}}class i extends t.ValueWithRandom{constructor(){super(),this.animation=new e,this.direction="clockwise",this.enable=!1,this.value=0}load(t){super.load(t),t&&(this.animation.load(t.animation),void 0!==t.direction&&(this.direction=t.direction),void 0!==t.enable&&(this.enable=t.enable))}}class a{constructor(t){this.container=t}getTransformValues(t){const e=t.tilt?.enable&&t.tilt;return{b:e?Math.cos(e.value)*e.cosDirection:void 0,c:e?Math.sin(e.value)*e.sinDirection:void 0}}init(e){const i=e.options.tilt;if(!i)return;e.tilt={enable:i.enable,value:(0,t.getRangeValue)(i.value)*Math.PI/180,sinDirection:(0,t.getRandom)()>=.5?1:-1,cosDirection:(0,t.getRandom)()>=.5?1:-1};let o=i.direction;if("random"===o){o=Math.floor(2*(0,t.getRandom)())>0?"counter-clockwise":"clockwise"}switch(o){case"counter-clockwise":case"counterClockwise":e.tilt.status="decreasing";break;case"clockwise":e.tilt.status="increasing"}const n=e.options.tilt?.animation;n?.enable&&(e.tilt.decay=1-(0,t.getRangeValue)(n.decay),e.tilt.velocity=(0,t.getRangeValue)(n.speed)/360*this.container.retina.reduceFactor,n.sync||(e.tilt.velocity*=(0,t.getRandom)()))}isEnabled(t){const e=t.options.tilt?.animation;return!t.destroyed&&!t.spawning&&!!e?.enable}loadOptions(t,...e){t.tilt||(t.tilt=new i);for(const i of e)t.tilt.load(i?.tilt)}update(t,e){this.isEnabled(t)&&function(t,e){if(!t.tilt||!t.options.tilt)return;const i=t.options.tilt.animation,o=(t.tilt.velocity??0)*e.factor,n=2*Math.PI,a=t.tilt.decay??1;i.enable&&("increasing"===t.tilt.status?(t.tilt.value+=o,t.tilt.value>n&&(t.tilt.value-=n)):(t.tilt.value-=o,t.tilt.value<0&&(t.tilt.value+=n)),t.tilt.velocity&&1!==a&&(t.tilt.velocity*=a))}(t,e)}}async function s(t,e=!0){await t.addParticleUpdater("tilt",(t=>new a(t)),e)}})(),n})())); |
@@ -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 Tilt Updater v3.0.0-beta.0 by Matteo Bruni */ |
import type { Engine } from "@tsparticles/engine"; | ||
export declare function loadTiltUpdater(engine: Engine): Promise<void>; | ||
export declare function loadTiltUpdater(engine: Engine, refresh?: boolean): Promise<void>; |
@@ -1,2 +0,2 @@ | ||
import type { IOptionLoader, RecursivePartial } from "@tsparticles/engine"; | ||
import { type IOptionLoader, type RecursivePartial, ValueWithRandom } from "@tsparticles/engine"; | ||
import type { ITilt } from "../Interfaces/ITilt"; | ||
@@ -6,3 +6,2 @@ import { TiltAnimation } from "./TiltAnimation"; | ||
import type { TiltDirectionAlt } from "../../TiltDirection"; | ||
import { ValueWithRandom } from "@tsparticles/engine"; | ||
export declare class Tilt extends ValueWithRandom implements ITilt, IOptionLoader<ITilt> { | ||
@@ -9,0 +8,0 @@ animation: TiltAnimation; |
@@ -1,2 +0,2 @@ | ||
import type { IOptionLoader, RangeValue, RecursivePartial } from "@tsparticles/engine"; | ||
import { type IOptionLoader, type RangeValue, type RecursivePartial } from "@tsparticles/engine"; | ||
import type { ITiltAnimation } from "../Interfaces/ITiltAnimation"; | ||
@@ -3,0 +3,0 @@ export declare class TiltAnimation implements ITiltAnimation, IOptionLoader<ITiltAnimation> { |
@@ -1,18 +0,3 @@ | ||
import type { Container, IDelta, IParticleTransformValues, IParticleUpdater, IParticleValueAnimation, IParticlesOptions, Particle, ParticlesOptions, RecursivePartial } from "@tsparticles/engine"; | ||
import type { ITilt } from "./Options/Interfaces/ITilt"; | ||
import { Tilt } from "./Options/Classes/Tilt"; | ||
export interface IParticleTiltValueAnimation extends IParticleValueAnimation<number> { | ||
cosDirection: number; | ||
sinDirection: number; | ||
} | ||
type TiltParticle = Particle & { | ||
options: TiltParticlesOptions; | ||
tilt?: IParticleTiltValueAnimation; | ||
}; | ||
type ITiltParticlesOptions = IParticlesOptions & { | ||
tilt?: ITilt; | ||
}; | ||
type TiltParticlesOptions = ParticlesOptions & { | ||
tilt?: Tilt; | ||
}; | ||
import { type Container, type IDelta, type IParticleTransformValues, type IParticleUpdater, type Particle, type RecursivePartial } from "@tsparticles/engine"; | ||
import type { ITiltParticlesOptions, TiltParticle, TiltParticlesOptions } from "./Types"; | ||
export declare class TiltUpdater implements IParticleUpdater { | ||
@@ -27,2 +12,1 @@ private readonly container; | ||
} | ||
export {}; |
@@ -14,6 +14,6 @@ (function (factory) { | ||
const TiltUpdater_1 = require("./TiltUpdater"); | ||
async function loadTiltUpdater(engine) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container)); | ||
async function loadTiltUpdater(engine, refresh = true) { | ||
await engine.addParticleUpdater("tilt", (container) => new TiltUpdater_1.TiltUpdater(container), refresh); | ||
} | ||
exports.loadTiltUpdater = loadTiltUpdater; | ||
}); |
@@ -7,3 +7,3 @@ (function (factory) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "./TiltAnimation", "@tsparticles/engine"], factory); | ||
define(["require", "exports", "@tsparticles/engine", "./TiltAnimation"], factory); | ||
} | ||
@@ -14,4 +14,4 @@ })(function (require, exports) { | ||
exports.Tilt = void 0; | ||
const engine_1 = require("@tsparticles/engine"); | ||
const TiltAnimation_1 = require("./TiltAnimation"); | ||
const engine_1 = require("@tsparticles/engine"); | ||
class Tilt extends engine_1.ValueWithRandom { | ||
@@ -18,0 +18,0 @@ constructor() { |
@@ -7,3 +7,3 @@ (function (factory) { | ||
else if (typeof define === "function" && define.amd) { | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Tilt"], factory); | ||
define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Tilt", "./Utils"], factory); | ||
} | ||
@@ -16,30 +16,3 @@ })(function (require, exports) { | ||
const Tilt_1 = require("./Options/Classes/Tilt"); | ||
function updateTilt(particle, delta) { | ||
var _a, _b; | ||
if (!particle.tilt || !particle.options.tilt) { | ||
return; | ||
} | ||
const tilt = particle.options.tilt, tiltAnimation = tilt.animation, speed = ((_a = particle.tilt.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor, max = 2 * Math.PI, decay = (_b = particle.tilt.decay) !== null && _b !== void 0 ? _b : 1; | ||
if (!tiltAnimation.enable) { | ||
return; | ||
} | ||
switch (particle.tilt.status) { | ||
case "increasing": | ||
particle.tilt.value += speed; | ||
if (particle.tilt.value > max) { | ||
particle.tilt.value -= max; | ||
} | ||
break; | ||
case "decreasing": | ||
default: | ||
particle.tilt.value -= speed; | ||
if (particle.tilt.value < 0) { | ||
particle.tilt.value += max; | ||
} | ||
break; | ||
} | ||
if (particle.tilt.velocity && decay !== 1) { | ||
particle.tilt.velocity *= decay; | ||
} | ||
} | ||
const Utils_1 = require("./Utils"); | ||
class TiltUpdater { | ||
@@ -50,4 +23,3 @@ constructor(container) { | ||
getTransformValues(particle) { | ||
var _a; | ||
const tilt = ((_a = particle.tilt) === null || _a === void 0 ? void 0 : _a.enable) && particle.tilt; | ||
const tilt = particle.tilt?.enable && particle.tilt; | ||
return { | ||
@@ -59,3 +31,2 @@ b: tilt ? Math.cos(tilt.value) * tilt.cosDirection : undefined, | ||
init(particle) { | ||
var _a; | ||
const tiltOptions = particle.options.tilt; | ||
@@ -85,4 +56,4 @@ if (!tiltOptions) { | ||
} | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
if (tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable) { | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
if (tiltAnimation?.enable) { | ||
particle.tilt.decay = 1 - (0, engine_1.getRangeValue)(tiltAnimation.decay); | ||
@@ -96,5 +67,4 @@ particle.tilt.velocity = ((0, engine_1.getRangeValue)(tiltAnimation.speed) / 360) * this.container.retina.reduceFactor; | ||
isEnabled(particle) { | ||
var _a; | ||
const tiltAnimation = (_a = particle.options.tilt) === null || _a === void 0 ? void 0 : _a.animation; | ||
return !particle.destroyed && !particle.spawning && !!(tiltAnimation === null || tiltAnimation === void 0 ? void 0 : tiltAnimation.enable); | ||
const tiltAnimation = particle.options.tilt?.animation; | ||
return !particle.destroyed && !particle.spawning && !!tiltAnimation?.enable; | ||
} | ||
@@ -106,3 +76,3 @@ loadOptions(options, ...sources) { | ||
for (const source of sources) { | ||
options.tilt.load(source === null || source === void 0 ? void 0 : source.tilt); | ||
options.tilt.load(source?.tilt); | ||
} | ||
@@ -114,3 +84,3 @@ } | ||
} | ||
updateTilt(particle, delta); | ||
(0, Utils_1.updateTilt)(particle, delta); | ||
} | ||
@@ -117,0 +87,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
52
1069
75
325462