@mescius/dsimageviewer
Version:
Document Solutions Image Viewer
122 lines (121 loc) • 4.49 kB
TypeScript
import { ImageFormatCode, ImageLayer, ImageViewerAPI, ImageViewerPluginAPI, PluginType, Size } from "./ImageViewer";
/**
* Page tools toolbar button key.
*/
export type PageToolButtonKey = "rotate-image" | "flip-horizontal" | "flip-vertical" | "crop-image" | "resize-image" | "$split" | "edit-undo" | "edit-redo";
/**
* PageToolsPlugin options.
*/
export type PageToolsPluginOptions = {
/**
* The position where the "Page tools" button should be inserted. Use `false` or `-1` to skip insertion. Undefined means the position will be determined automatically.
*/
buttonPosition?: number | false;
/**
* The page tools toolbar layout.
* @default
* Default layout:
* ["rotate-image", "flip-horizontal", "flip-vertical", "crop-image", "resize-image"]
* @example
* ```javascript
* <script src="gcimageviewer.js"></script></head>
* <script src="plugins/pageTools.js"></script>
* <script>
* const viewer = new DsImageViewer("#root");
* const pageToolsPlugin = new PageToolsPlugin( { toolbarLayout: ["rotate-image", "flip-horizontal"] } );
* viewer.addPlugin(pageToolsPlugin);
* </script>
* ```
*/
toolbarLayout?: PageToolButtonKey[];
};
/**
* Defines Page Tools Plugin API.
* @ignore exclude API interface from docs since it is documented by implementing class.
*/
export interface PageToolsPluginAPI extends ImageViewerPluginAPI {
/**
* Plugin options
*/
options: PageToolsPluginOptions;
/**
* Gets current rotation in degrees.
*/
readonly totalRotation: number;
/**
* Rotate image.
* @param angle Angle to rotate an image.
*/
rotate(angle: number): Promise<boolean>;
/**
* Crop image.
* @param {number} x Leftmost point of a new image rectangle
* @param {number} y Topmost point of a new image rectangle
* @param {number} width Width a new image rectangle
* @param {number} height Height a new image rectangle
* @returns {Promise<boolean>} Whether transformation was applied successfully or not.
*/
crop(x: number, y: number, width: number, height: number): Promise<boolean>;
/**
* Resize image.
* @param {number} width New image width.
* @param {number} height New image height
* @param {boolean} keepAspectRatio Explicitly defines a need of keeping an original image aspect ratio. Defaults to true.
*/
resize(width: number, height: number, keepAspectRatio: boolean): Promise<boolean>;
/**
* Flip image.
* @param {boolean} horizontal Flip horizontally. True by default.
* @param {boolean} horizontal Flip horizontally. False by default.
* @returns {Promise<boolean>} Whether transformation was applied successfully or not.
*/
flip(horizontal: boolean, vertical: boolean): Promise<boolean>;
/**
* Flip image horizontally.
* @returns {Promise<boolean>} Whether transformation was applied successfully or not.
*/
flipHorizontal(): Promise<boolean>;
/**
* Flip image vertically.
* @returns {Promise<boolean>} Whether transformation was applied successfully or not.
*/
flipVertical(): Promise<boolean>;
}
/**
* Page Tools Plugin.
* Adds the "Page tools" button.
* @example
* ```html
* <script src="gcimageviewer.js"></script></head>
* <script src="plugins/pageTools.js"></script>
* <script>
* const viewer = new DsImageViewer("#root");
* viewer.addPlugin(new PageToolsPlugin());
* </script>
* ```
*/
export declare class PageToolsPlugin implements PageToolsPluginAPI {
constructor(options?: PageToolsPluginOptions);
viewer: ImageViewerAPI;
options: PageToolsPluginOptions;
totalRotation: number;
rotate(angle: number): Promise<boolean>;
crop(x: number, y: number, width: number, height: number): Promise<boolean>;
resize(width: number, height: number, keepAspectRatio: boolean): Promise<boolean>;
flip(horizontal: boolean, vertical: boolean): Promise<boolean>;
flipHorizontal(): Promise<boolean>;
flipVertical(): Promise<boolean>;
paintLayer: ImageLayer;
isReady: boolean;
naturalSize: Size;
isImageFormatSupported(imageFormat: string | ImageFormatCode, allowUnknown?: boolean): boolean;
dispose(): void;
removePaintLayer(): void;
id: PluginType;
initialize(viewer: ImageViewerAPI): void;
}
declare global {
interface Window {
PageToolsPlugin: typeof PageToolsPlugin;
}
}