(
node: T,
options: Options = {},
)
| 26 | } |
| 27 | |
| 28 | export async function toCanvas<T extends HTMLElement>( |
| 29 | node: T, |
| 30 | options: Options = {}, |
| 31 | ): Promise<HTMLCanvasElement> { |
| 32 | const { width, height } = getImageSize(node, options) |
| 33 | const svg = await toSvg(node, options) |
| 34 | const img = await createImage(svg) |
| 35 | |
| 36 | const canvas = document.createElement('canvas') |
| 37 | const context = canvas.getContext('2d')! |
| 38 | const ratio = options.pixelRatio || getPixelRatio() |
| 39 | const canvasWidth = options.canvasWidth || width |
| 40 | const canvasHeight = options.canvasHeight || height |
| 41 | |
| 42 | canvas.width = canvasWidth * ratio |
| 43 | canvas.height = canvasHeight * ratio |
| 44 | |
| 45 | if (!options.skipAutoScale) { |
| 46 | checkCanvasDimensions(canvas) |
| 47 | } |
| 48 | canvas.style.width = `${canvasWidth}` |
| 49 | canvas.style.height = `${canvasHeight}` |
| 50 | |
| 51 | if (options.backgroundColor) { |
| 52 | context.fillStyle = options.backgroundColor |
| 53 | context.fillRect(0, 0, canvas.width, canvas.height) |
| 54 | } |
| 55 | |
| 56 | context.drawImage(img, 0, 0, canvas.width, canvas.height) |
| 57 | |
| 58 | return canvas |
| 59 | } |
| 60 | |
| 61 | export async function toPixelData<T extends HTMLElement>( |
| 62 | node: T, |
no test coverage detected
searching dependent graphs…