Function scaleCanvas

Scales a canvas to account for retina displays.

const r = scaleCanvas(`#my-canvas`);
r.ctx; // CanvasRendering2D
r.element; // HTMLCanvasElement
r.bounds; // {x:number,y:number,width:number,height:number}

Eg:

const { ctx } = scaleCanvas(`#my-canvas`);
ctx.fillStyle = `red`;
ctx.fillRect(0,0,100,100);

Throws an error if domQueryOrElement does not resolve.w

  • Parameters

    • domQueryOrElement: string | HTMLCanvasElement

    Returns {
        bounds: DOMRect;
        ctx: CanvasRenderingContext2D;
        element: HTMLCanvasElement;
    }

    • bounds: DOMRect
    • ctx: CanvasRenderingContext2D
    • element: HTMLCanvasElement