19 lines
669 B
JavaScript
19 lines
669 B
JavaScript
// Gemeinsame Erzeugung temporärer Canvas-Flächen für Views und Meter.
|
|
export function createCanvasSurface(width, height) {
|
|
const w = Math.max(1, Math.ceil(width));
|
|
const h = Math.max(1, Math.ceil(height));
|
|
if (typeof OffscreenCanvas === 'function') {
|
|
const canvas = new OffscreenCanvas(w, h);
|
|
const ctx = canvas.getContext('2d');
|
|
if (ctx) return { canvas, ctx, width: w, height: h };
|
|
}
|
|
if (typeof document !== 'undefined') {
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = w;
|
|
canvas.height = h;
|
|
const ctx = canvas.getContext('2d');
|
|
if (ctx) return { canvas, ctx, width: w, height: h };
|
|
}
|
|
return null;
|
|
}
|