forked from Andrey-1988-dev/snowfall-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (56 loc) · 1.81 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Snowfall } from "./snowfall.js";
import { canRunAnimation } from "./canRunAnimation.js";
import {
switchesAppendToDOM,
switchesSetupEventHandlers,
switchesToggleOn,
} from "./switch.js";
import { setParams } from "./config/validateParams.js";
import { getAutoStart } from "./autoStart.js";
export const snowfallState = {
snowfallInstance: undefined,
isAnimationRunning: false,
};
import { logError, logInfo } from "./logger.js";
/**
* Global configuration parameters for the snowfall-js-plugin.
* @type {Object}
*/
export let params = {};
/**
* Start the snowfall animation based on the provided configuration parameters.
* @param {Object} configParams - Configuration parameters for the snowfall animation.
* @returns {void}
*/
export function snowAnimationStart(configParams = {}) {
if (configParams.logLevel === "info") params.logLevel = "info";
logInfo("Validating snowfall-js-plugin parameters...");
params = setParams(configParams);
const canRun = canRunAnimation(params);
if (canRun) {
const autoStart = getAutoStart(params);
switchesAppendToDOM(params);
switchesSetupEventHandlers(params);
if (autoStart) {
snowfallState.snowfallInstance = initSnowfall(params.snowfall);
snowfallState.isAnimationRunning = true;
switchesToggleOn();
logInfo("Done loading and starting animation.");
}
} else return;
}
/**
* Initializes and returns a Snowfall instance.
* @param {Object} params - Configuration parameters for Snowfall.
* @returns {Snowfall} - The initialized Snowfall instance.
* @throws {Error} - If an error occurs during the initialization.
*/
export function initSnowfall(params) {
try {
const snowfall = new Snowfall(params);
return snowfall;
} catch (err) {
logError("Error initializing Snowfall instance");
throw err;
}
}