diff --git a/src/jcanvas.d.ts b/src/jcanvas.d.ts index eff1658..e1bffae 100644 --- a/src/jcanvas.d.ts +++ b/src/jcanvas.d.ts @@ -378,6 +378,7 @@ interface JCanvasDefaults { type: keyof JCanvasMaps["drawings"] | null; visible: boolean; width: number | null; + willReadFrequently: boolean; x: number; y: number; each?: ( diff --git a/src/jcanvas.ts b/src/jcanvas.ts index 5d5ccb3..56eb3e1 100644 --- a/src/jcanvas.ts +++ b/src/jcanvas.ts @@ -204,6 +204,7 @@ class jCanvasDefaults implements JCanvasDefaults { type: keyof (typeof maps)["drawings"] | null = null; visible: boolean = true; width: number | null = null; + willReadFrequently: boolean = false; x: number = 0; y: number = 0; [key: `x${number}`]: number; @@ -265,7 +266,13 @@ function _isCanvas(element: HTMLElement): element is HTMLCanvasElement { function _getContext( canvas: HTMLCanvasElement ): CanvasRenderingContext2D | null { - return canvas.getContext("2d"); + if ($.jCanvas.defaults.willReadFrequently) { + return canvas.getContext("2d", { + willReadFrequently: $.jCanvas.defaults.willReadFrequently, + }); + } else { + return canvas.getContext("2d"); + } } // Coerce designated number properties from strings to numbers