Skip to content

Commit

Permalink
Add fallback support for standard Canvas if OffscreenCanvas unavailab…
Browse files Browse the repository at this point in the history
…le (#1052)
  • Loading branch information
jeffpamer authored Dec 11, 2023
1 parent f39f30d commit 80b3c43
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/timeline/LayerLine.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,25 @@
return points;
}
function generateOffscreenPoint(lineColor: string, radius: number): OffscreenCanvas | null {
function generateOffscreenPoint(lineColor: string, radius: number): OffscreenCanvas | HTMLCanvasElement | null {
if (!radius) {
return null;
}
const tempCanvas = new OffscreenCanvas(radius * 2 * dpr, radius * 2 * dpr);
const tempCtx = tempCanvas.getContext('2d');
let tempCanvas: OffscreenCanvas | HTMLCanvasElement;
let tempCtx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D | null;
if ('OffscreenCanvas' in window) {
tempCanvas = new OffscreenCanvas(radius * 2 * dpr, radius * 2 * dpr);
} else {
tempCanvas = document.createElement('canvas');
tempCanvas.height = radius * 2 * dpr;
tempCanvas.width = radius * 2 * dpr;
tempCanvas.style.height = `${radius * 2}px`;
tempCanvas.style.width = `${radius * 2}px`;
}
tempCtx = tempCanvas.getContext('2d');
if (!tempCtx) {
return null;
Expand Down

0 comments on commit 80b3c43

Please sign in to comment.