@tsparticles/confetti
Version:
tsParticles confetti bundle — easily create confetti, confetti cannon, confetti explosions, confetti falling, and confetti parade animations with presets. Ready to use components available for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact,
122 lines (121 loc) • 3.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfettiOptions = void 0;
const engine_1 = require("@tsparticles/engine");
class ConfettiOptions {
angle;
colors;
count;
decay;
disableForReducedMotion;
drift;
flat;
gravity;
position;
scalar;
shapeOptions;
shapes;
spread;
startVelocity;
ticks;
zIndex;
constructor() {
this.angle = 90;
this.count = 50;
this.spread = 45;
this.startVelocity = 45;
this.decay = 0.9;
this.gravity = 1;
this.drift = 0;
this.ticks = 200;
this.position = {
x: 50,
y: 50,
};
this.colors = ["#26ccff", "#a25afd", "#ff5e7e", "#88ff5a", "#fcff42", "#ffa62d", "#ff36ff"];
this.shapes = ["square", "circle"];
this.scalar = 1;
this.zIndex = 100;
this.disableForReducedMotion = true;
this.flat = false;
this.shapeOptions = {};
}
get origin() {
return {
x: this.position.x / engine_1.percentDenominator,
y: this.position.y / engine_1.percentDenominator,
};
}
set origin(value) {
this.position.x = value.x * engine_1.percentDenominator;
this.position.y = value.y * engine_1.percentDenominator;
}
get particleCount() {
return this.count;
}
set particleCount(value) {
this.count = value;
}
load(data) {
if ((0, engine_1.isNull)(data)) {
return;
}
(0, engine_1.loadProperty)(this, "angle", data.angle);
const count = data.count ?? data.particleCount;
if (count !== undefined) {
this.count = count;
}
(0, engine_1.loadProperty)(this, "spread", data.spread);
(0, engine_1.loadProperty)(this, "startVelocity", data.startVelocity);
(0, engine_1.loadProperty)(this, "decay", data.decay);
(0, engine_1.loadProperty)(this, "flat", data.flat);
(0, engine_1.loadProperty)(this, "gravity", data.gravity);
(0, engine_1.loadProperty)(this, "drift", data.drift);
(0, engine_1.loadProperty)(this, "ticks", data.ticks);
const origin = data.origin;
if (origin && !data.position) {
data.position = {
x: origin.x === undefined ? undefined : origin.x * engine_1.percentDenominator,
y: origin.y === undefined ? undefined : origin.y * engine_1.percentDenominator,
};
}
const position = data.position;
if (position) {
if (position.x !== undefined) {
this.position.x = position.x;
}
if (position.y !== undefined) {
this.position.y = position.y;
}
}
if (data.colors !== undefined) {
if ((0, engine_1.isArray)(data.colors)) {
this.colors = [...data.colors];
}
else {
this.colors = data.colors;
}
}
const options = data.shapeOptions;
if (options !== undefined) {
for (const shape in options) {
const item = options[shape];
if (item) {
this.shapeOptions[shape] = (0, engine_1.deepExtend)(this.shapeOptions[shape] ?? {}, item);
}
}
}
if (data.shapes !== undefined) {
if ((0, engine_1.isArray)(data.shapes)) {
this.shapes = [...data.shapes];
}
else {
this.shapes = data.shapes;
}
}
(0, engine_1.loadProperty)(this, "scalar", data.scalar);
(0, engine_1.loadProperty)(this, "zIndex", data.zIndex);
(0, engine_1.loadProperty)(this, "disableForReducedMotion", data.disableForReducedMotion);
}
}
exports.ConfettiOptions = ConfettiOptions;