node-canvasの型定義備忘

node-canvasの型定義を使うところだけ書いてみたけど目的に敵わなかったので、定義だけ備忘。いつか使うかも。

declare module 'canvas' {
    import * as Stream from 'stream';

    interface PNGOptions {
        palette: Uint8ClampedArray;
        backgroundIndex?: number;
    }

    interface JPEGOptions {
        bufsize?: number;
        quality?: number;
        progressive?: boolean;
        disableChromaSubsampling?: boolean;
    }

    interface Canvas extends HTMLCanvasElement {
        inspect(): string;
        pngStream(options?: PNGOptions): Stream.Readable;
        jpegStream(options?: JPEGOptions): Stream.Readable;
        // pdfStream(): Stream.Readable;
    }

    interface Image extends HTMLImageElement {
        inspect(): string;
    }

    interface FontFace {
        family: string;
        weight?: string;
        style?: string;
    }

    function registerFont(src: string, fontFace: FontFace): any;
    function createCanvas(width: number, height: number, type?: any): Canvas;
    // function loadImage(src: string | Buffer): Promise<Image>;
}

v2.0.0-alpha12でregisterFontしてcreateCanvasで作ったヘッドレスCanvasに描画してpngStream/jpegStreamで書き出す一連の流れは問題ないが、loadImageで爆死。pdfStreamも不調。