UNPKG

6.19 kBTypeScriptView Raw
1import type { IOptions } from "./Options/Interfaces/IOptions";
2import type { Container } from "./Core/Container";
3import type { ShapeDrawerAfterEffectFunction, ShapeDrawerDestroyFunction, ShapeDrawerDrawFunction, ShapeDrawerInitFunction, RecursivePartial, SingleOrMultiple } from "./Types";
4import type { Particle } from "./Core/Particle";
5import type { IInteractor, IMovePathGenerator, IParticleUpdater, IPlugin, IShapeDrawer } from "./Core/Interfaces";
6/**
7 * Main class for creating the singleton on window.
8 * It's a singleton proxy to the static [[Loader]] class for initializing [[Container]] instances
9 * @category Main
10 */
11export declare class Main {
12 #private;
13 constructor();
14 /**
15 * init method, used by imports
16 */
17 init(): void;
18 /**
19 * Loads an options object from the provided array to create a [[Container]] object.
20 * @param tagId The particles container element id
21 * @param options The options array to get the item from
22 * @param index If provided gets the corresponding item from the array
23 * @returns A Promise with the [[Container]] object created
24 */
25 loadFromArray(tagId: string, options: RecursivePartial<IOptions>[], index?: number): Promise<Container | undefined>;
26 /**
27 * Loads the provided options to create a [[Container]] object.
28 * @param tagId The particles container element id
29 * @param options The options object to initialize the [[Container]]
30 * @returns A Promise with the [[Container]] object created
31 */
32 load(tagId: string | SingleOrMultiple<RecursivePartial<IOptions>>, options?: SingleOrMultiple<RecursivePartial<IOptions>>): Promise<Container | undefined>;
33 /**
34 * Loads the provided option to create a [[Container]] object using the element parameter as a container
35 * @param id The particles container id
36 * @param element The dom element used to contain the particles
37 * @param options The options object to initialize the [[Container]]
38 */
39 set(id: string | HTMLElement, element: HTMLElement | RecursivePartial<IOptions>, options?: RecursivePartial<IOptions>): Promise<Container | undefined>;
40 /**
41 * Loads the provided json with a GET request. The content will be used to create a [[Container]] object.
42 * This method is async, so if you need a callback refer to JavaScript function `fetch`
43 * @param tagId the particles container element id
44 * @param pathConfigJson the json path (or paths array) to use in the GET request
45 * @param index the index of the paths array, if a single path is passed this value is ignored
46 * @returns A Promise with the [[Container]] object created
47 */
48 loadJSON(tagId: string | SingleOrMultiple<string>, pathConfigJson?: SingleOrMultiple<string> | number, index?: number): Promise<Container | undefined>;
49 /**
50 * Loads the provided option to create a [[Container]] object using the element parameter as a container
51 * @param id The particles container id
52 * @param element The dom element used to contain the particles
53 * @param pathConfigJson the json path (or paths array) to use in the GET request
54 * @param index the index of the paths array, if a single path is passed this value is ignored
55 * @returns A Promise with the [[Container]] object created
56 */
57 setJSON(id: string | HTMLElement, element: HTMLElement | SingleOrMultiple<string>, pathConfigJson?: SingleOrMultiple<string> | number, index?: number): Promise<Container | undefined>;
58 /**
59 * Adds an additional click handler to all the loaded [[Container]] objects.
60 * @param callback The function called after the click event is fired
61 */
62 setOnClickHandler(callback: (e: Event, particles?: Particle[]) => void): void;
63 /**
64 * All the [[Container]] objects loaded
65 * @returns All the [[Container]] objects loaded
66 */
67 dom(): Container[];
68 /**
69 * Retrieves a [[Container]] from all the objects loaded
70 * @param index The object index
71 * @returns The [[Container]] object at specified index, if present or not destroyed, otherwise undefined
72 */
73 domItem(index: number): Container | undefined;
74 /**
75 * addShape adds shape to tsParticles, it will be available to all future instances created
76 * @param shape the shape name
77 * @param drawer the shape drawer function or class instance that draws the shape in the canvas
78 * @param init Optional: the shape drawer init function, used only if the drawer parameter is a function
79 * @param afterEffect Optional: the shape drawer after effect function, used only if the drawer parameter is a function
80 * @param destroy Optional: the shape drawer destroy function, used only if the drawer parameter is a function
81 */
82 addShape(shape: string, drawer: IShapeDrawer | ShapeDrawerDrawFunction, init?: ShapeDrawerInitFunction, afterEffect?: ShapeDrawerAfterEffectFunction, destroy?: ShapeDrawerDestroyFunction): void;
83 /**
84 * addPreset adds preset to tsParticles, it will be available to all future instances created
85 * @param preset the preset name
86 * @param options the options to add to the preset
87 * @param override if true, the preset will override any existing with the same name
88 */
89 addPreset(preset: string, options: RecursivePartial<IOptions>, override?: boolean): void;
90 /**
91 * addPlugin adds plugin to tsParticles, if an instance needs it it will be loaded
92 * @param plugin the plugin implementation of [[IPlugin]]
93 */
94 addPlugin(plugin: IPlugin): void;
95 /**
96 * addPathGenerator adds a named path generator to tsParticles, this can be called by options
97 * @param name the path generator name
98 * @param generator the path generator object
99 */
100 addPathGenerator(name: string, generator: IMovePathGenerator): void;
101 /**
102 *
103 * @param name
104 * @param interactorInitializer
105 */
106 addInteractor(name: string, interactorInitializer: (container: Container) => IInteractor): void;
107 /**
108 *
109 * @param name
110 * @param updaterInitializer
111 */
112 addParticleUpdater(name: string, updaterInitializer: (container: Container) => IParticleUpdater): void;
113}