UNPKG

2.63 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.Plugins = void 0;
4const plugins = [];
5const interactorsInitializers = new Map();
6const updatersInitializers = new Map();
7const interactors = new Map();
8const updaters = new Map();
9const presets = new Map();
10const drawers = new Map();
11const pathGenerators = new Map();
12class Plugins {
13 static getPlugin(plugin) {
14 return plugins.find((t) => t.id === plugin);
15 }
16 static addPlugin(plugin) {
17 if (!Plugins.getPlugin(plugin.id)) {
18 plugins.push(plugin);
19 }
20 }
21 static getAvailablePlugins(container) {
22 const res = new Map();
23 for (const plugin of plugins) {
24 if (!plugin.needsPlugin(container.actualOptions)) {
25 continue;
26 }
27 res.set(plugin.id, plugin.getPlugin(container));
28 }
29 return res;
30 }
31 static loadOptions(options, sourceOptions) {
32 for (const plugin of plugins) {
33 plugin.loadOptions(options, sourceOptions);
34 }
35 }
36 static getPreset(preset) {
37 return presets.get(preset);
38 }
39 static addPreset(presetKey, options, override = false) {
40 if (override || !Plugins.getPreset(presetKey)) {
41 presets.set(presetKey, options);
42 }
43 }
44 static addShapeDrawer(type, drawer) {
45 if (!Plugins.getShapeDrawer(type)) {
46 drawers.set(type, drawer);
47 }
48 }
49 static getShapeDrawer(type) {
50 return drawers.get(type);
51 }
52 static getSupportedShapes() {
53 return drawers.keys();
54 }
55 static getPathGenerator(type) {
56 return pathGenerators.get(type);
57 }
58 static addPathGenerator(type, pathGenerator) {
59 if (!Plugins.getPathGenerator(type)) {
60 pathGenerators.set(type, pathGenerator);
61 }
62 }
63 static getInteractors(container) {
64 let res = interactors.get(container);
65 if (!res) {
66 res = [...interactorsInitializers.values()].map((t) => t(container));
67 interactors.set(container, res);
68 }
69 return res;
70 }
71 static addInteractor(name, initInteractor) {
72 interactorsInitializers.set(name, initInteractor);
73 }
74 static getUpdaters(container) {
75 let res = updaters.get(container);
76 if (!res) {
77 res = [...updatersInitializers.values()].map((t) => t(container));
78 updaters.set(container, res);
79 }
80 return res;
81 }
82 static addParticleUpdater(name, initUpdater) {
83 updatersInitializers.set(name, initUpdater);
84 }
85}
86exports.Plugins = Plugins;