1 | var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
2 | if (kind === "m") throw new TypeError("Private method is not writable");
|
3 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
4 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
5 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
6 | };
|
7 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11 | };
|
12 | var _Main_initialized;
|
13 | import { Plugins } from "./Utils";
|
14 | import { Loader } from "./Core/Loader";
|
15 | /**
|
16 | * Main class for creating the singleton on window.
|
17 | * It's a singleton proxy to the static [[Loader]] class for initializing [[Container]] instances
|
18 | * @category Main
|
19 | */
|
20 | export class Main {
|
21 | constructor() {
|
22 | _Main_initialized.set(this, void 0);
|
23 | __classPrivateFieldSet(this, _Main_initialized, false, "f");
|
24 | }
|
25 | /**
|
26 | * init method, used by imports
|
27 | */
|
28 | init() {
|
29 | if (!__classPrivateFieldGet(this, _Main_initialized, "f")) {
|
30 | __classPrivateFieldSet(this, _Main_initialized, true, "f");
|
31 | }
|
32 | }
|
33 | /**
|
34 | * Loads an options object from the provided array to create a [[Container]] object.
|
35 | * @param tagId The particles container element id
|
36 | * @param options The options array to get the item from
|
37 | * @param index If provided gets the corresponding item from the array
|
38 | * @returns A Promise with the [[Container]] object created
|
39 | */
|
40 | async loadFromArray(tagId, options, index) {
|
41 | return Loader.load(tagId, options, index);
|
42 | }
|
43 | /**
|
44 | * Loads the provided options to create a [[Container]] object.
|
45 | * @param tagId The particles container element id
|
46 | * @param options The options object to initialize the [[Container]]
|
47 | * @returns A Promise with the [[Container]] object created
|
48 | */
|
49 | async load(tagId, options) {
|
50 | return Loader.load(tagId, options);
|
51 | }
|
52 | /**
|
53 | * Loads the provided option to create a [[Container]] object using the element parameter as a container
|
54 | * @param id The particles container id
|
55 | * @param element The dom element used to contain the particles
|
56 | * @param options The options object to initialize the [[Container]]
|
57 | */
|
58 | async set(id, element, options) {
|
59 | return Loader.set(id, element, options);
|
60 | }
|
61 | /**
|
62 | * Loads the provided json with a GET request. The content will be used to create a [[Container]] object.
|
63 | * This method is async, so if you need a callback refer to JavaScript function `fetch`
|
64 | * @param tagId the particles container element id
|
65 | * @param pathConfigJson the json path (or paths array) to use in the GET request
|
66 | * @param index the index of the paths array, if a single path is passed this value is ignored
|
67 | * @returns A Promise with the [[Container]] object created
|
68 | */
|
69 | async loadJSON(tagId, pathConfigJson, index) {
|
70 | return Loader.loadJSON(tagId, pathConfigJson, index);
|
71 | }
|
72 | /**
|
73 | * Loads the provided option to create a [[Container]] object using the element parameter as a container
|
74 | * @param id The particles container id
|
75 | * @param element The dom element used to contain the particles
|
76 | * @param pathConfigJson the json path (or paths array) to use in the GET request
|
77 | * @param index the index of the paths array, if a single path is passed this value is ignored
|
78 | * @returns A Promise with the [[Container]] object created
|
79 | */
|
80 | async setJSON(id, element, pathConfigJson, index) {
|
81 | return Loader.setJSON(id, element, pathConfigJson, index);
|
82 | }
|
83 | /**
|
84 | * Adds an additional click handler to all the loaded [[Container]] objects.
|
85 | * @param callback The function called after the click event is fired
|
86 | */
|
87 | setOnClickHandler(callback) {
|
88 | Loader.setOnClickHandler(callback);
|
89 | }
|
90 | /**
|
91 | * All the [[Container]] objects loaded
|
92 | * @returns All the [[Container]] objects loaded
|
93 | */
|
94 | dom() {
|
95 | return Loader.dom();
|
96 | }
|
97 | /**
|
98 | * Retrieves a [[Container]] from all the objects loaded
|
99 | * @param index The object index
|
100 | * @returns The [[Container]] object at specified index, if present or not destroyed, otherwise undefined
|
101 | */
|
102 | domItem(index) {
|
103 | return Loader.domItem(index);
|
104 | }
|
105 | /**
|
106 | * addShape adds shape to tsParticles, it will be available to all future instances created
|
107 | * @param shape the shape name
|
108 | * @param drawer the shape drawer function or class instance that draws the shape in the canvas
|
109 | * @param init Optional: the shape drawer init function, used only if the drawer parameter is a function
|
110 | * @param afterEffect Optional: the shape drawer after effect function, used only if the drawer parameter is a function
|
111 | * @param destroy Optional: the shape drawer destroy function, used only if the drawer parameter is a function
|
112 | */
|
113 | addShape(shape, drawer, init, afterEffect, destroy) {
|
114 | let customDrawer;
|
115 | if (typeof drawer === "function") {
|
116 | customDrawer = {
|
117 | afterEffect: afterEffect,
|
118 | destroy: destroy,
|
119 | draw: drawer,
|
120 | init: init,
|
121 | };
|
122 | }
|
123 | else {
|
124 | customDrawer = drawer;
|
125 | }
|
126 | Plugins.addShapeDrawer(shape, customDrawer);
|
127 | }
|
128 | /**
|
129 | * addPreset adds preset to tsParticles, it will be available to all future instances created
|
130 | * @param preset the preset name
|
131 | * @param options the options to add to the preset
|
132 | * @param override if true, the preset will override any existing with the same name
|
133 | */
|
134 | addPreset(preset, options, override = false) {
|
135 | Plugins.addPreset(preset, options, override);
|
136 | }
|
137 | /**
|
138 | * addPlugin adds plugin to tsParticles, if an instance needs it it will be loaded
|
139 | * @param plugin the plugin implementation of [[IPlugin]]
|
140 | */
|
141 | addPlugin(plugin) {
|
142 | Plugins.addPlugin(plugin);
|
143 | }
|
144 | /**
|
145 | * addPathGenerator adds a named path generator to tsParticles, this can be called by options
|
146 | * @param name the path generator name
|
147 | * @param generator the path generator object
|
148 | */
|
149 | addPathGenerator(name, generator) {
|
150 | Plugins.addPathGenerator(name, generator);
|
151 | }
|
152 | /**
|
153 | *
|
154 | * @param name
|
155 | * @param interactorInitializer
|
156 | */
|
157 | addInteractor(name, interactorInitializer) {
|
158 | Plugins.addInteractor(name, interactorInitializer);
|
159 | }
|
160 | /**
|
161 | *
|
162 | * @param name
|
163 | * @param updaterInitializer
|
164 | */
|
165 | addParticleUpdater(name, updaterInitializer) {
|
166 | Plugins.addParticleUpdater(name, updaterInitializer);
|
167 | }
|
168 | }
|
169 | _Main_initialized = new WeakMap();
|