if (typeof HTMLCanvasElement !== "undefined") { const context = { clearRect() {}, drawImage() {}, fillRect() {}, fillText() {}, restore() {}, rotate() {}, save() {}, scale() {}, translate() {}, measureText: () => ({ width: 0 }), getImageData: (_sx: number, _sy: number, width: number, height: number) => ({ data: new Uint8ClampedArray(width * height * 4), width, height, colorSpace: "srgb", }), } as unknown as CanvasRenderingContext2D; Object.defineProperty(HTMLCanvasElement.prototype, "getContext", { configurable: true, value: () => context, }); }