UNPKG

@stringsync/vexml

Version:

MusicXML to Vexflow

54 lines (53 loc) 2.3 kB
import * as components from '../components'; import { Topic } from './topic'; import { EventListener } from './types'; export type EventMapping<V extends string[]> = { src: 'scroll' | 'overlay'; vexml: V; native: { [K in keyof HTMLElementEventMap]?: EventListener<HTMLElementEventMap[K]>; }; }; /** * This class is responsible for lazily managing the activation and deactivation of native events on a host element. * * - Activation is the process initializing the native event machinery needed for a given vexml event. * - Deactivation is the process of cleaning up the native event machinery when a given vexml event is no longer needed. * - Native events are only added to the host element when they are needed. */ export declare class NativeBridge<V extends string> { private root; private mappings; private nativeEventTopic; private nativeEventOpts; private handles; constructor(root: components.Root, mappings: Array<EventMapping<V[]>>, nativeEventTopic: Topic<HTMLElementEventMap>, nativeEventOpts: { [K in keyof HTMLElementEventMap]?: AddEventListenerOptions; }); /** Returns whether the vexml event is activated. */ isActivated(vexmlEventName: V): boolean; /** * Activates a vexml event, initializing the native event machinery if needed. * * NOTE: vexml events cannot be activated if they are already active. It is the caller's responsibility to ensure that * the event is not already active. */ activate(vexmlEventName: V): void; /** * Deactivates a vexml event, cleaning up the native event machinery if needed. * * NOTE: vexml events cannot be deactivated if they are already inactive. It is the caller's responsibility to ensure * that the event is not already inactive. */ deactivate(vexmlEventName: V): void; /** Deactivates all vexml events. */ deactivateAll(): void; /** * Forwards a native event to its respective topic. * * NOTE: This is done in this manner so we can have a reference to the function that is added as a native event * listener. This is necessary for unsubscribing from the native event listener when the dependent vexml events are * deactivated. */ private publishNativeEvent; }