From 8a851abfad7b2dafbf53ec1ee31d1adb899164ea Mon Sep 17 00:00:00 2001 From: Pei-Tang Huang Date: Tue, 24 May 2016 21:50:36 +0800 Subject: [PATCH] Html2canvas 0.5 (#9293) * Merge function with optional argument. * Align function to 0.5.0 (by replacing callback by Promise.) * Declare module for easier import. * Format. * Update version and author information. * Use ES6 Promise directly. Since DefinitelyTyped recommend compilation with `--target es6` and `--noImplicitAny` options. * Revert "Use ES6 Promise directly." Projects targeting es5 wouldn't compile due to the leak of ES6 Promise. This reverts commit 7d022d153c0601384d920671a3150fa7bcacd166. * Fixed header format. --- html2canvas/html2canvas.d.ts | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/html2canvas/html2canvas.d.ts b/html2canvas/html2canvas.d.ts index 1d5fd82fe7..e1fcbc7a1b 100644 --- a/html2canvas/html2canvas.d.ts +++ b/html2canvas/html2canvas.d.ts @@ -1,6 +1,6 @@ -// Type definitions for html2canvas.js v0.4.1 +// Type definitions for html2canvas.js v0.5.0-bata.4 // Project: https://github.com/niklasvh/html2canvas -// Definitions by: Richard Hepburn +// Definitions by: Richard Hepburn , Pei-Tang Huang // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -36,26 +36,14 @@ declare namespace Html2Canvas { /** Whether to attempt to load cross-origin images as CORS served, before reverting back to proxy. */ useCORS?: boolean; - + /** Use svg powered rendering where available (FF11+). */ svgRendering?: boolean; - - /** Callback providing the rendered canvas element after rendering */ - onrendered?(canvas: HTMLCanvasElement): void; } } interface Html2CanvasStatic { - /** - * Renders an HTML element to a canvas so that a screenshot can be generated. - * - * The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, - * but builds the screenshot based on the information available on the page. - * - * @param {HTMLElement} element The HTML element which will be rendered to the canvas. Use the root element to render the entire window. - */ - (element: HTMLElement): void; /** * Renders an HTML element to a canvas so that a screenshot can be generated. * @@ -65,7 +53,25 @@ interface Html2CanvasStatic { * @param {HTMLElement} element The HTML element which will be rendered to the canvas. Use the root element to render the entire window. * @param {Html2CanvasOptions} options The options object that controls how the element will be rendered. */ - (element: HTMLElement, options: Html2Canvas.Html2CanvasOptions): void; + (element: HTMLElement, options?: Html2Canvas.Html2CanvasOptions): Html2CanvasPromise; +} + +// FIXME: +// Find out a way to dependent on real Promise interface. +// And remove following custome Promise interface. +interface Html2CanvasThenable { + then(onFulfilled?: (value: R) => U | Html2CanvasThenable, onRejected?: (error: any) => U | Html2CanvasThenable): Html2CanvasThenable; + then(onFulfilled?: (value: R) => U | Html2CanvasThenable, onRejected?: (error: any) => void): Html2CanvasThenable; +} + +interface Html2CanvasPromise extends Html2CanvasThenable { + then(onFulfilled?: (value: R) => U | Html2CanvasThenable, onRejected?: (error: any) => U | Html2CanvasThenable): Html2CanvasPromise; + then(onFulfilled?: (value: R) => U | Html2CanvasThenable, onRejected?: (error: any) => void): Html2CanvasPromise; + catch(onRejected?: (error: any) => U | Html2CanvasThenable): Html2CanvasPromise; +} + +declare module 'html2canvas' { + export = html2canvas; } declare var html2canvas: Html2CanvasStatic;