fix: this.canvas.ownerDocument is undefined (#2590)

This commit is contained in:
MoyuScript 2021-07-15 17:08:43 +08:00
parent 197933edee
commit 1332c3b306

View File

@ -552,7 +552,8 @@ export class CanvasRenderer {
return image;
}
const canvas = (this.canvas.ownerDocument as Document).createElement('canvas');
const ownerDocument = this.canvas.ownerDocument ?? document;
const canvas = ownerDocument.createElement('canvas');
canvas.width = Math.max(1, width);
canvas.height = Math.max(1, height);
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D;