/
index.ts
65 lines (58 loc) · 2.4 KB
/
index.ts
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
64
65
/**
* [[include:pjsMigration.md]]
* @packageDocumentation
*/
import type { Container, Engine, Particle, RecursivePartial } from "tsparticles-engine";
import type { IParticlesJS } from "./IParticlesJS";
import type { IParticlesJSOptions } from "./IParticlesJSOptions";
import { ParticlesJSPlugin } from "./ParticlesJSPlugin";
const initPjs = (engine: Engine): { particlesJS: IParticlesJS; pJSDom: Container[] } => {
engine.addPlugin(new ParticlesJSPlugin());
/**
* Loads the provided options to create a [[Container]] object.
* @deprecated this method is obsolete, please use the new tsParticles.load
* @param tagId the particles container element id
* @param options the options object to initialize the [[Container]]
*/
const particlesJS = (
tagId: string,
options: RecursivePartial<IParticlesJSOptions>
): Promise<Container | undefined> => {
return engine.load(tagId, options);
};
/**
* Loads the provided json with a GET request.
* The content will be used to create a [[Container]] object.
* @deprecated this method is obsolete, please use the new tsParticles.loadJSON
* @param tagId the particles container element id
* @param pathConfigJson the json path to use in the GET request
* @param callback called after the [[Container]] is loaded and it will be passed as a parameter
*/
particlesJS.load = (tagId: string, pathConfigJson: string, callback: (container?: Container) => void): void => {
engine
.loadJSON(tagId, pathConfigJson)
.then((container) => {
if (container) {
callback(container);
}
})
.catch(() => {
callback(undefined);
});
};
/**
* Adds an additional click handler to all the loaded [[Container]] objects.
* @deprecated this method is obsolete, please use the new tsParticles.setOnClickHandler
* @param callback the function called after the click event is fired
*/
particlesJS.setOnClickHandler = (callback: (e: Event, particles?: Particle[]) => void): void => {
engine.setOnClickHandler(callback);
};
/**
* All the [[Container]] objects loaded
* @deprecated this method is obsolete, please use the new tsParticles.dom
*/
const pJSDom = engine.dom();
return { particlesJS, pJSDom };
};
export { initPjs };