license import { VisorComponent } from './components/visor' ; import { SurfaceInfo , SurfaceInfoStrict } from './types' ; let visorSingleton ; const DEFAULT_TAB = 'Visor' ; const VISOR_CONTAINER_ID = 'tfjs-visor-container' ; /**
 * The primary interface to the visor is the visor() function.
 *
 * This returns a singleton instance of the Visor class. The
 * singleton object will be replaced if the visor is removed from the DOM for
 * some reason.
 *
 * ```js
 * // Show the visor
 * tfvis.visor();
 * ```
 *
 */ doc export function visor ( ) { if ( typeof document === 'undefined' ) { throw new Error ( 'No document defined. This library needs a browser/dom to work' ) ; } if ( document . getElementById ( VISOR_CONTAINER_ID ) && visorSingleton != null ) { return visorSingleton ; } let visorEl = document . getElementById ( VISOR_CONTAINER_ID ) ; if ( visorEl == null ) { visorEl = document . createElement ( 'div' ) ; visorEl . id = VISOR_CONTAINER_ID ; document . body . appendChild ( visorEl ) ; } let renderRoot ; function renderVisor ( domNode , surfaceList ) { let visorInstance ; renderRoot = VisorComponent . render ( domNode , renderRoot , { ref : ( r ) => visorInstance = r , surfaceList : Array . from ( surfaceList . values ( ) ) , } ) ; return visorInstance ! ; } const surfaceList = new Map ( ) ; const visorComponentInstance = renderVisor ( visorEl , surfaceList ) ; visorSingleton = new Visor ( visorComponentInstance , visorEl , surfaceList , renderVisor ) ; return visorSingleton ; } /**
 * An instance of the visor. An instance of this class is created using the
 * `visor()` function.
 */ doc export class Visor { private visorComponent : VisorComponent ; private surfaceList : Map < string , SurfaceInfoStrict > ; private renderVisor : ( domNode : HTMLElement , surfaceList : Map < string , SurfaceInfoStrict > ) => VisorComponent ; /**
     * The underlying html element of the visor.
     */ public el : HTMLElement ; constructor ( visorComponent , visorEl , surfaceList , renderVisor ) { this . visorComponent = visorComponent ; this . el = visorEl ; this . surfaceList = surfaceList ; this . renderVisor = renderVisor ; } param options doc surface ( options ) { const { name } = options ; const tab = options . tab == null ? DEFAULT_TAB : options . tab ; if ( name == null || ! ( typeof name === 'string' || name as any instanceof String ) ) { throw new Error ( 'You must pass a config object with a \'name\' property to create or retrieve a surface' ) ; } const finalOptions = { ... options , tab , } ; const key = `${ name }-${ tab }` ; if ( ! this . surfaceList . has ( key ) ) { this . surfaceList . set ( key , finalOptions ) ; } this . renderVisor ( this . el as HTMLElement , this . surfaceList ) ; return this . visorComponent . getSurface ( name , tab ) ; } /**
     * Returns a boolean indicating if the visor is in 'fullscreen' mode
     */ doc isFullscreen ( ) { return this . visorComponent . isFullscreen ( ) ; } /**
     * Returns a boolean indicating if the visor is open
     */ doc isOpen ( ) { return this . visorComponent . isOpen ( ) ; } /**
     * Closes the visor.
     */ doc close ( ) { return this . visorComponent . close ( ) ; } /**
     * Opens the visor.
     */ doc open ( ) { return this . visorComponent . open ( ) ; } /**
     * Toggles the visor (closed vs open).
     */ doc toggle ( ) { return this . visorComponent . toggle ( ) ; } doc toggleFullScreen ( ) { return this . visorComponent . toggleFullScreen ( ) ; } /**
     * Binds the ~ (tilde) key to toggle the visor.
     *
     * This is called by default when the visor is initially created.
     */ doc bindKeys ( ) { return this . visorComponent . bindKeys ( ) ; } /**
     * Unbinds the keyboard control to toggle the visor.
     */ doc unbindKeys ( ) { return this . visorComponent . unbindKeys ( ) ; } /**
     * Sets the active tab for the visor.
     */ doc setActiveTab ( tabName ) { const tabs = this . visorComponent . state . tabs ; if ( ! tabs . has ( tabName ) ) { throw new Error ( `Tab '${ tabName }' does not exist` ) ; } this . visorComponent . setState ( { activeTab : tabName } ) ; } }