- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
import { BaseImageResource } from './BaseImageResource';
/**
* @interface OffscreenCanvas
*/
/**
* Resource type for HTMLCanvasElement.
* @memberof PIXI
*/
export class CanvasResource extends BaseImageResource
{
/**
* @param source - Canvas element to use
*/
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
constructor(source: HTMLCanvasElement)
{
super(source);
}
/**
* Used to auto-detect the type of resource.
* @param {*} source - The source object
* @returns {boolean} `true` if source is HTMLCanvasElement or OffscreenCanvas
*/
static test(source: unknown): source is OffscreenCanvas | HTMLCanvasElement
{
const { OffscreenCanvas } = globalThis;
// Check for browsers that don't yet support OffscreenCanvas
if (OffscreenCanvas && source instanceof OffscreenCanvas)
{
return true;
}
return globalThis.HTMLCanvasElement && source instanceof HTMLCanvasElement;
}
}