UNPKG

1.58 kBJavaScriptView Raw
1const plugins = [];
2const presets = new Map();
3const drawers = new Map();
4const pathGenerators = new Map();
5export class Plugins {
6 static getPlugin(plugin) {
7 return plugins.find((t) => t.id === plugin);
8 }
9 static addPlugin(plugin) {
10 if (!Plugins.getPlugin(plugin.id)) {
11 plugins.push(plugin);
12 }
13 }
14 static getAvailablePlugins(container) {
15 const res = new Map();
16 for (const plugin of plugins) {
17 if (!plugin.needsPlugin(container.actualOptions)) {
18 continue;
19 }
20 res.set(plugin.id, plugin.getPlugin(container));
21 }
22 return res;
23 }
24 static loadOptions(options, sourceOptions) {
25 for (const plugin of plugins) {
26 plugin.loadOptions(options, sourceOptions);
27 }
28 }
29 static getPreset(preset) {
30 return presets.get(preset);
31 }
32 static addPreset(presetKey, options) {
33 if (!Plugins.getPreset(presetKey)) {
34 presets.set(presetKey, options);
35 }
36 }
37 static addShapeDrawer(type, drawer) {
38 if (!Plugins.getShapeDrawer(type)) {
39 drawers.set(type, drawer);
40 }
41 }
42 static getShapeDrawer(type) {
43 return drawers.get(type);
44 }
45 static getSupportedShapes() {
46 return drawers.keys();
47 }
48 static getPathGenerator(type) {
49 return pathGenerators.get(type);
50 }
51 static addPathGenerator(type, pathGenerator) {
52 if (!Plugins.getPathGenerator(type)) {
53 pathGenerators.set(type, pathGenerator);
54 }
55 }
56}