function createCanvasContext2D(width, height, canvasPool, settings) {
  /** @type {HTMLCanvasElement|OffscreenCanvas} */
  let canvas;
  if (canvasPool && canvasPool.length) {
    canvas = /** @type {HTMLCanvasElement} */ (canvasPool.shift());
  } else if (WORKER_OFFSCREEN_CANVAS) {
    canvas = new OffscreenCanvas(width || 300, height || 300);
  } else {
    canvas = document.createElement('canvas');
  }
  if (width) {
    canvas.width = width;
  }
  if (height) {
    canvas.height = height;
  }
  //FIXME Allow OffscreenCanvasRenderingContext2D as return type
  return /** @type {CanvasRenderingContext2D} */ (
    canvas.getContext('2d', settings)
  );
}
Create an html canvas element and returns its 2d context.
@param {number} [width] Canvas width.
@param {number} [height] Canvas height.
@param {Array<HTMLCanvasElement>} [canvasPool] Canvas pool to take existing canvas from.
@param {CanvasRenderingContext2DSettings} [settings] CanvasRenderingContext2DSettings
@return {CanvasRenderingContext2D} The context.