Fixed document ref in hitdetect
fixed lint
This commit is contained in:
@@ -10,9 +10,15 @@ import {WORKER_OFFSCREEN_CANVAS} from './has.js';
|
||||
* @param {number} [opt_width] Canvas width.
|
||||
* @param {number} [opt_height] Canvas height.
|
||||
* @param {Array<HTMLCanvasElement>} [opt_canvasPool] Canvas pool to take existing canvas from.
|
||||
* @param {CanvasRenderingContext2DSettings} [opt_Context2DSettings] CanvasRenderingContext2DSettings
|
||||
* @return {CanvasRenderingContext2D} The context.
|
||||
*/
|
||||
export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
|
||||
export function createCanvasContext2D(
|
||||
opt_width,
|
||||
opt_height,
|
||||
opt_canvasPool,
|
||||
opt_Context2DSettings
|
||||
) {
|
||||
const canvas =
|
||||
opt_canvasPool && opt_canvasPool.length
|
||||
? opt_canvasPool.shift()
|
||||
@@ -26,7 +32,10 @@ export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
|
||||
canvas.height = opt_height;
|
||||
}
|
||||
//FIXME Allow OffscreenCanvasRenderingContext2D as return type
|
||||
return /** @type {CanvasRenderingContext2D} */ (canvas.getContext('2d'));
|
||||
return /** @type {CanvasRenderingContext2D} */ (canvas.getContext(
|
||||
'2d',
|
||||
opt_Context2DSettings
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,10 +91,13 @@ export function createHitDetectionImageData(
|
||||
continue;
|
||||
}
|
||||
|
||||
const img = document.createElement('canvas');
|
||||
img.width = imgSize[0];
|
||||
img.height = imgSize[1];
|
||||
const imgContext = img.getContext('2d', {alpha: false});
|
||||
const imgContext = createCanvasContext2D(
|
||||
imgSize[0],
|
||||
imgSize[1],
|
||||
undefined,
|
||||
{alpha: false}
|
||||
);
|
||||
const img = imgContext.canvas;
|
||||
imgContext.fillStyle = color;
|
||||
imgContext.fillRect(0, 0, img.width, img.height);
|
||||
style.setImage(
|
||||
|
||||
Reference in New Issue
Block a user