mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-03 00:30:14 +00:00
[iv-viewer] Add iv viewer (#43728)
* [iv-viewer] Add iv-viewer * [iv-viewer] Add missing class fields types * [iv-viewer] Add default options
This commit is contained in:
181
types/iv-viewer/index.d.ts
vendored
Normal file
181
types/iv-viewer/index.d.ts
vendored
Normal file
@@ -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 <https://github.com/robert-wettstaedt>
|
||||
// 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;
|
||||
27
types/iv-viewer/iv-viewer-tests.ts
Normal file
27
types/iv-viewer/iv-viewer-tests.ts
Normal file
@@ -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
|
||||
25
types/iv-viewer/tsconfig.json
Normal file
25
types/iv-viewer/tsconfig.json
Normal file
@@ -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"
|
||||
]
|
||||
}
|
||||
1
types/iv-viewer/tslint.json
Normal file
1
types/iv-viewer/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user