diff --git a/types/iv-viewer/index.d.ts b/types/iv-viewer/index.d.ts new file mode 100644 index 0000000000..ca88ced5b4 --- /dev/null +++ b/types/iv-viewer/index.d.ts @@ -0,0 +1,181 @@ +// Type definitions for iv-viewer 2.0 +// Project: https://github.com/s-yadav/iv-viewer#readme +// Definitions by: Robert Wettstädt +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Minimum TypeScript Version: 3.7 + +interface Options { + zoomValue?: number; + snapView?: boolean; + maxZoom?: number; + refreshOnResize?: boolean; + zoomOnMouseWheel?: boolean; +} + +interface SliderOptions { + isSliderEnabled: () => boolean; + onStart: () => void; + onMove: () => void; + onEnd: () => void; +} + +declare class Slider { + constructor(container: Element | null, options: SliderOptions); + + container: Element | null; + isSliderEnabled: () => boolean; + onStart: () => void; + onMove: () => void; + onEnd: () => void; + + startHandler(event: Event): void; + moveHandler(event: Event): void; + endHandler(): void; + removeListeners(): void; + init(): void; + destroy(): void; +} + +interface Elements { + container: Element | null; + domElement: Element | null; + image?: Element | null; + imageWrap?: Element | null; + snapHandle?: Element | null; + snapImage?: Element | null; + snapImageWrap?: Element | null; + snapView?: Element | null; + zoomHandle?: Element | null; +} + +type IVEvent = () => void; + +interface Events { + hiResImageLoad?: IVEvent; + imageLoad?: IVEvent; + mouseEnterSnapView?: IVEvent; + mouseLeaveSnapView?: IVEvent; + onWindowResize?: IVEvent; + pinchStart?: IVEvent; + snapViewOnMouseMove?: IVEvent; +} + +interface Frames { + slideMomentumCheck?: number; + sliderMomentumFrame?: number; + snapViewTimeout?: number; + zoomFrame?: number; +} + +interface Sliders { + imageSlider?: Slider; + snapSlider?: Slider; + zoomSlider?: Slider; +} + +type IVImage = string | null; + +interface Images { + imageSrc: IVImage; + hiResImageSrc: IVImage; +} + +interface Dim { + w: number; + h: number; +} + +interface State { + containerDim?: Dim; + imageDim?: Dim; + loaded?: boolean; + snapHandleDim?: Dim; + snapImageDim?: Dim; + snapViewVisible?: boolean; + zooming?: boolean; + zoomSliderLength?: number; + zoomValue?: number; +} + +declare class ImageViewer { + constructor(element: Element | null, options?: Options); + + static defaults: Options; + + protected _elements: Elements; + protected _events: Events; + protected _frames: Frames; + protected _images: Images; + protected _options: Options; + protected _sliders: Sliders; + protected _state: State; + + protected _calculateDimensions(): void; + protected _doubleTapToZoom(): void; + protected _findContainerAndImageSrc( + element: string | Element | null, + ): { + container: Element | null; + domElement: Element | null; + imageSrc: IVImage; + hiResImageSrc: IVImage; + }; + protected _getImageCurrentDim(): void; + protected _init(): void; + protected _initDom(): void; + protected _initEvents(): void; + protected _initImageSlider(): void; + protected _initSnapSlider(): void; + protected _initZoomSlider(): void; + protected _loadHighResImage(): void; + protected _loadImages(): void; + protected _pinchAndZoom(): void; + protected _scrollZoom(): void; + protected _snapViewEvents(): void; + + destroy(): void; + hideSnapView(): void; + load(imageSrc: string, hiResImageSrc?: string): void; + refresh(): void; + resetZoom(animate?: boolean): void; + showSnapView(noTimeout?: boolean): void; + zoom(perc: number, point?: { x: number; y: number }): void; +} + +interface FullScreenElements extends Elements { + fullScreen: Element | null; +} + +interface FullScreenEvents extends Events { + onCloseBtnClick?: IVEvent; + onWindowResize?: IVEvent; +} + +declare class FullScreenViewer extends ImageViewer { + constructor(options?: Options); + + protected _elements: FullScreenElements; + protected _events: FullScreenEvents; + + protected _initFullScreenEvents(): void; + hide(): void; + show(imageSrc: string, hiResImageSrc?: string): void; +} + +declare namespace ImageViewer { + export { + Elements, + Events, + Frames, + FullScreenElements, + FullScreenEvents, + FullScreenViewer, + Images, + ImageViewer, + Options, + Sliders, + State, + }; +} + +export = ImageViewer; diff --git a/types/iv-viewer/iv-viewer-tests.ts b/types/iv-viewer/iv-viewer-tests.ts new file mode 100644 index 0000000000..4cf98b2bcf --- /dev/null +++ b/types/iv-viewer/iv-viewer-tests.ts @@ -0,0 +1,27 @@ +import ImageViewer, { FullScreenViewer, ImageViewer as DestructuredImageViewer, Options } from 'iv-viewer'; + +const iv = new ImageViewer(new Element()); +iv.destroy(); // $ExpectType void +iv.destroy(); // $ExpectType void +iv.hideSnapView(); // $ExpectType void +iv.load(''); // $ExpectType void +iv.refresh(); // $ExpectType void +iv.resetZoom(); // $ExpectType void +iv.showSnapView(); // $ExpectType void +iv.zoom(0); // $ExpectType void + +new DestructuredImageViewer(new Element(), ImageViewer.defaults); + +const options: Options = {}; + +const fsv = new FullScreenViewer(options); +fsv.destroy(); // $ExpectType void +fsv.destroy(); // $ExpectType void +fsv.hide(); // $ExpectType void +fsv.hideSnapView(); // $ExpectType void +fsv.load(''); // $ExpectType void +fsv.refresh(); // $ExpectType void +fsv.resetZoom(); // $ExpectType void +fsv.show(''); // $ExpectType void +fsv.showSnapView(); // $ExpectType void +fsv.zoom(0); // $ExpectType void diff --git a/types/iv-viewer/tsconfig.json b/types/iv-viewer/tsconfig.json new file mode 100644 index 0000000000..a83661a28a --- /dev/null +++ b/types/iv-viewer/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true + }, + "files": [ + "index.d.ts", + "iv-viewer-tests.ts" + ] +} diff --git a/types/iv-viewer/tslint.json b/types/iv-viewer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/iv-viewer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }