Skip to content

Commit

Permalink
Add support for willReadFrequently flag
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Jun 9, 2024
1 parent c3b6422 commit 01c1087
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/jcanvas.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ interface JCanvasDefaults {
type: keyof JCanvasMaps["drawings"] | null;
visible: boolean;
width: number | null;
willReadFrequently: boolean;
x: number;
y: number;
each?: (
Expand Down
9 changes: 8 additions & 1 deletion src/jcanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 01c1087

Please sign in to comment.