Skip to content

Commit

Permalink
fix: Avoid referencing HEMLCanvasElement in node
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Sep 18, 2024
1 parent b673476 commit 49a8a79
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions modules/core/src/adapter/canvas-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export abstract class CanvasContext {
this.canvas = props.canvas;
}

if (this.canvas instanceof HTMLCanvasElement) {
if (typeof HTMLCanvasElement !== 'undefined' && this.canvas instanceof HTMLCanvasElement) {
this.id = props.id || this.canvas.id;
this.type = 'html-canvas';
this.htmlCanvas = this.canvas;
Expand All @@ -137,7 +137,7 @@ export abstract class CanvasContext {
this.drawingBufferHeight = this.canvas.height;
this.devicePixelRatio = globalThis.devicePixelRatio || 1;

if (this.canvas instanceof HTMLCanvasElement) {
if (typeof HTMLCanvasElement !== 'undefined' && this.canvas instanceof HTMLCanvasElement) {
// Track visibility changes
this._intersectionObserver = new IntersectionObserver(entries =>
this._handleIntersection(entries)
Expand Down Expand Up @@ -172,7 +172,7 @@ export abstract class CanvasContext {
* @note This is independent of the canvas' internal drawing buffer size (.width, .height).
*/
getCSSSize(): [number, number] {
if (this.canvas instanceof HTMLCanvasElement) {
if (typeof HTMLCanvasElement !== 'undefined' && this.canvas instanceof HTMLCanvasElement) {
return [this.canvas.clientWidth, this.canvas.clientHeight];
}
return [this.pixelWidth, this.pixelHeight];
Expand Down

0 comments on commit 49a8a79

Please sign in to comment.