/// import { EventEmitter } from 'events'; import Composition from '../Composition'; import ViewState from '../ViewState'; import { Tool } from '../tool/Tool'; import Annotation from '../annotation/Annotation'; /** * Viewer is the main component of CIRCUS RS, and wraps a HTML canvas element * and displays a specified image along with various annotations. * Displayed object is determined by `viewState` and `imageSource`. */ export default class Viewer extends EventEmitter { canvas: HTMLCanvasElement; private rootDiv; private viewState; private composition; private activeTool; private cachedSourceImage; private hoveringAnnotation; /** * primaryEventTarget captures all UI events happened within the canvas * before other elements handle this, typically while dragging. */ primaryEventTarget: any; /** * backgroundEventTarget handles all UI events after other elements. */ backgroundEventTarget: any; private boundRender; private boundEventHandler; private imageReady; private isDragging; /** * When render() is called while there is already another rendering procedure in progress, * We will keep that render Promise with a "suspended" status. * After the current rendering is finished, the last suspended one will be used. * This can prevent the imageSource's draw() method from being called too frequently. */ private nextRender; /** * Holds the current rendering promise which is actually processing ImageSource#draw(). */ private currentRender; private isObservingDivSize; /** * Change state when viewer size is changed. This function is provided by ImageSource. */ private viewStateResizeTransformer; private createCanvas; resizeCanvas(): void; constructor(div: HTMLDivElement); /** * Begin observation of wrapper element size. */ private activateResizeObserver; private stopResizeObserver; getViewport(): [number, number]; getResolution(): [number, number]; setResolution(width: number, height: number): void; private canvasEventHandler; setHoveringAnnotation(anno: Annotation | undefined): void; getHoveringAnnotation(): Annotation | undefined; setCursorStyle(cursor: string): void; /** * Synchronously draws the image fetched from the image source, along with * all the annotations associated with the composition. * This function is automatically called when ImageSource.draw() has finished, * but can be called arbitrary times when annotations are updated. * This function does nothing when ImageSource.draw() is in progress * (i.e., this.currentRender is not empty). */ renderAnnotations(viewState?: ViewState | null): void; private renderImageDataToCanvas; /** * Requests the rendering of the viewer using the current view state. * This can be called very frequently (eg, 60 times/sec), * but it may not trigger the actual rendering procedure because * you cannot have more than one rendering paths running simultaneously. * The returned promise will be rejected when this request was skipped. * @return {Promise} A promise object that resolves with a * boolean indicating whether actual rendering happened (true) or not (false). */ render(): Promise; /** * Cancels the render */ cancelNextRender(): void; /** * Sets the view state and re-renders the viewer. */ setState(state: ViewState): void; /** * Returns the current view state. */ getState(): ViewState; private detachCurrentComposition; /** * ImageSource handling methods */ setComposition(composition: Composition): void; getComposition(): Composition | undefined; setActiveTool(tool: Tool): void; getActiveTool(): Tool | undefined; handleResize(): void; /** * Dispose viewer */ dispose(): void; }