1 | import { deepExtend } from "tsparticles-engine";
|
2 | export class ConfettiOptions {
|
3 | constructor() {
|
4 | this.angle = 90;
|
5 | this.count = 50;
|
6 | this.spread = 45;
|
7 | this.startVelocity = 45;
|
8 | this.decay = 0.9;
|
9 | this.gravity = 1;
|
10 | this.drift = 0;
|
11 | this.ticks = 200;
|
12 | this.position = {
|
13 | x: 50,
|
14 | y: 50,
|
15 | };
|
16 | this.colors = ["#26ccff", "#a25afd", "#ff5e7e", "#88ff5a", "#fcff42", "#ffa62d", "#ff36ff"];
|
17 | this.shapes = ["square", "circle"];
|
18 | this.scalar = 1;
|
19 | this.zIndex = 100;
|
20 | this.disableForReducedMotion = true;
|
21 | this.shapeOptions = {};
|
22 | }
|
23 | get origin() {
|
24 | return {
|
25 | x: this.position.x / 100,
|
26 | y: this.position.y / 100,
|
27 | };
|
28 | }
|
29 | set origin(value) {
|
30 | this.position.x = value.x * 100;
|
31 | this.position.y = value.y * 100;
|
32 | }
|
33 | get particleCount() {
|
34 | return this.count;
|
35 | }
|
36 | set particleCount(value) {
|
37 | this.count = value;
|
38 | }
|
39 | load(data) {
|
40 | var _a, _b;
|
41 | if (!data) {
|
42 | return;
|
43 | }
|
44 | if (data.angle !== undefined) {
|
45 | this.angle = data.angle;
|
46 | }
|
47 | const count = (_a = data.count) !== null && _a !== void 0 ? _a : data.particleCount;
|
48 | if (count !== undefined) {
|
49 | this.count = count;
|
50 | }
|
51 | if (data.spread !== undefined) {
|
52 | this.spread = data.spread;
|
53 | }
|
54 | if (data.startVelocity !== undefined) {
|
55 | this.startVelocity = data.startVelocity;
|
56 | }
|
57 | if (data.decay !== undefined) {
|
58 | this.decay = data.decay;
|
59 | }
|
60 | if (data.gravity !== undefined) {
|
61 | this.gravity = data.gravity;
|
62 | }
|
63 | if (data.drift !== undefined) {
|
64 | this.drift = data.drift;
|
65 | }
|
66 | if (data.ticks !== undefined) {
|
67 | this.ticks = data.ticks;
|
68 | }
|
69 | const origin = data.origin;
|
70 | if (origin && !data.position) {
|
71 | data.position = {
|
72 | x: origin.x !== undefined ? origin.x * 100 : undefined,
|
73 | y: origin.y !== undefined ? origin.y * 100 : undefined,
|
74 | };
|
75 | }
|
76 | const position = data.position;
|
77 | if (position) {
|
78 | if (position.x !== undefined) {
|
79 | this.position.x = position.x;
|
80 | }
|
81 | if (position.y !== undefined) {
|
82 | this.position.y = position.y;
|
83 | }
|
84 | }
|
85 | if (data.colors !== undefined) {
|
86 | if (data.colors instanceof Array) {
|
87 | this.colors = [...data.colors];
|
88 | }
|
89 | else {
|
90 | this.colors = data.colors;
|
91 | }
|
92 | }
|
93 | const options = data.shapeOptions;
|
94 | if (options !== undefined) {
|
95 | for (const shape in options) {
|
96 | const item = options[shape];
|
97 | if (item) {
|
98 | this.shapeOptions[shape] = deepExtend((_b = this.shapeOptions[shape]) !== null && _b !== void 0 ? _b : {}, item);
|
99 | }
|
100 | }
|
101 | }
|
102 | if (data.shapes !== undefined) {
|
103 | if (data.shapes instanceof Array) {
|
104 | this.shapes = [...data.shapes];
|
105 | }
|
106 | else {
|
107 | this.shapes = data.shapes;
|
108 | }
|
109 | }
|
110 | if (data.scalar !== undefined) {
|
111 | this.scalar = data.scalar;
|
112 | }
|
113 | if (data.zIndex !== undefined) {
|
114 | this.zIndex = data.zIndex;
|
115 | }
|
116 | if (data.disableForReducedMotion !== undefined) {
|
117 | this.disableForReducedMotion = data.disableForReducedMotion;
|
118 | }
|
119 | }
|
120 | }
|