import Vizzu from './vizzu.js'; import * as Anim from './types/anim.js'; import { Events, EventType, EventHandler, EventMap } from './events.js'; import { AnimCompleting } from './animcompleting.js'; /** Available hooks for plugins in Vizzu. */ export declare enum Hooks { /** Called when the animate() parameters gets set in the library to prepare the animation. */ prepareAnimation = "prepareAnimation", /** Called when the animate() method called, and the lib shedules the call to the animation queue. */ registerAnimation = "registerAnimation", /** Called when all animate() parameter set and animation can be started. */ runAnimation = "runAnimation" } /** Plugin metainfo. */ export interface PluginMeta { /** Name of the plugin. If not set, the class name will be used with a lowercase first char. */ name?: string; /** Version of the plugin. Not used for now. */ version?: string; /** List of plugins this plugin depends on. Dependent plugins should be registered beforehand. */ depends?: string[]; } export interface PrepareAnimationContext { target: Anim.AnimTarget; options?: Anim.ControlOptions; } export interface RegisterAnimationContext { target: Anim.AnimTarget; options?: Anim.ControlOptions; promise: AnimCompleting; } export interface RunAnimationContext { callback: (ok: boolean) => void; } export interface HookContexts { [Hooks.prepareAnimation]: PrepareAnimationContext; [Hooks.registerAnimation]: RegisterAnimationContext; [Hooks.runAnimation]: RunAnimationContext; } type Next = () => void; /** Plugin hook implementation. Plugin hooks gets called by Vizzu in priority order. Each hook should call the next hook in the chain, or the default implementation won't run. */ type PluginHook = { (ctx: T, next: Next): void; priority?: number; }; /** Set of plugin hook implementations. */ export type PluginHooks = { [key in T]?: PluginHook; }; export type PluginListeners = { [event in EventType]?: EventHandler; }; export interface PluginApi { [apiMethod: string]: unknown; } /** Vizzu plugin interface. */ export interface Plugin { /** Metainfo about the plugin. */ meta?: PluginMeta; /** Hooks the plugin implemenst. They work only if the plugin is enabled. */ hooks?: PluginHooks; /** Event listeners the plugin implements. They work only if the plugin is enabled. */ listeners?: PluginListeners; /** Any parameter or method the Plugin exposes for the user. */ api?: PluginApi; /** Register called when the plugin added to vizzu, receiving the Vizzu instance. */ register?: (ctx: Vizzu) => void; /** Unregister is called when detach() called on the Vizzu instance. */ unregister?: (ctx: Vizzu) => void; /** Method called by Vizzu indicating for the plugin that it got switched on/off. If switched off, its event listeners gets removed and its hooks won't be called. */ enable?: (enabled: boolean) => void; } interface HookExecutor { default: (last?: (ctx: HookContexts[T]) => void) => void; } export declare class PluginRegistry { private _parent; private _plugins; private _events?; constructor(parent: Vizzu, plugins?: Plugin[]); init(events: Events): void; enable(name: string, enabled: boolean): void; getRegisteredName(instance: Plugin): string | undefined; register(instance: Plugin, enabled?: boolean): string; destruct(): void; unregister(name: string): void; api(name: string): PluginApi; hook(type: T, ctx: HookContexts[T]): HookExecutor; private _setEnabled; private _enableEvents; private _disableEvents; private _validate; private _validateName; private _discoverName; private _firstToLower; private _validateDepends; private _getByName; private _exec; private _getHooks; private _executeHooks; } export {};