1 | import Vizzu from './vizzu.js';
|
2 | import * as Anim from './types/anim.js';
|
3 | import { Events, EventType, EventHandler, EventMap } from './events.js';
|
4 | import { AnimCompleting } from './animcompleting.js';
|
5 |
|
6 | export declare enum Hooks {
|
7 | |
8 |
|
9 | prepareAnimation = "prepareAnimation",
|
10 | |
11 |
|
12 | registerAnimation = "registerAnimation",
|
13 |
|
14 | runAnimation = "runAnimation"
|
15 | }
|
16 |
|
17 | export interface PluginMeta {
|
18 | |
19 |
|
20 | name?: string;
|
21 |
|
22 | version?: string;
|
23 | |
24 |
|
25 | depends?: string[];
|
26 | }
|
27 | export interface PrepareAnimationContext {
|
28 | target: Anim.AnimTarget;
|
29 | options?: Anim.ControlOptions;
|
30 | }
|
31 | export interface RegisterAnimationContext {
|
32 | target: Anim.AnimTarget;
|
33 | options?: Anim.ControlOptions;
|
34 | promise: AnimCompleting;
|
35 | }
|
36 | export interface RunAnimationContext {
|
37 | callback: (ok: boolean) => void;
|
38 | }
|
39 | export interface HookContexts {
|
40 | [Hooks.prepareAnimation]: PrepareAnimationContext;
|
41 | [Hooks.registerAnimation]: RegisterAnimationContext;
|
42 | [Hooks.runAnimation]: RunAnimationContext;
|
43 | }
|
44 | type Next = () => void;
|
45 |
|
46 |
|
47 |
|
48 | type PluginHook<T> = {
|
49 | (ctx: T, next: Next): void;
|
50 | priority?: number;
|
51 | };
|
52 |
|
53 | export type PluginHooks<T extends Hooks = Hooks> = {
|
54 | [key in T]?: PluginHook<HookContexts[key]>;
|
55 | };
|
56 | export type PluginListeners = {
|
57 | [event in EventType]?: EventHandler<EventMap[event]>;
|
58 | };
|
59 | export interface PluginApi {
|
60 | [apiMethod: string]: unknown;
|
61 | }
|
62 |
|
63 | export interface Plugin {
|
64 |
|
65 | meta?: PluginMeta;
|
66 |
|
67 | hooks?: PluginHooks;
|
68 |
|
69 | listeners?: PluginListeners;
|
70 |
|
71 | api?: PluginApi;
|
72 |
|
73 | register?: (ctx: Vizzu) => void;
|
74 |
|
75 | unregister?: (ctx: Vizzu) => void;
|
76 | |
77 |
|
78 | enable?: (enabled: boolean) => void;
|
79 | }
|
80 | interface HookExecutor<T extends Hooks> {
|
81 | default: (last?: (ctx: HookContexts[T]) => void) => void;
|
82 | }
|
83 | export declare class PluginRegistry {
|
84 | private _parent;
|
85 | private _plugins;
|
86 | private _events?;
|
87 | constructor(parent: Vizzu, plugins?: Plugin[]);
|
88 | init(events: Events): void;
|
89 | enable(name: string, enabled: boolean): void;
|
90 | getRegisteredName(instance: Plugin): string | undefined;
|
91 | register(instance: Plugin, enabled?: boolean): string;
|
92 | destruct(): void;
|
93 | unregister(name: string): void;
|
94 | api(name: string): PluginApi;
|
95 | hook<T extends Hooks>(type: T, ctx: HookContexts[T]): HookExecutor<T>;
|
96 | private _setEnabled;
|
97 | private _enableEvents;
|
98 | private _disableEvents;
|
99 | private _validate;
|
100 | private _validateName;
|
101 | private _discoverName;
|
102 | private _firstToLower;
|
103 | private _validateDepends;
|
104 | private _getByName;
|
105 | private _exec;
|
106 | private _getHooks;
|
107 | private _executeHooks;
|
108 | }
|
109 | export {};
|