Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfig committed Aug 16, 2023
2 parents e607014 + 526c028 commit 5bb2ee7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export interface IViewportTransformState
}

const DEFAULT_VIEWPORT_OPTIONS: Partial<ICompleteViewportOptions> = {
screenWidth: window.innerWidth,
screenHeight: window.innerHeight,
screenWidth: typeof window === 'undefined' ? 0 : window.innerWidth,
screenHeight: typeof window === 'undefined' ? 0 : window.innerHeight,
worldWidth: null,
worldHeight: null,
threshold: 5,
Expand Down Expand Up @@ -326,8 +326,8 @@ export class Viewport extends Container
* @param {number} [worldHeight]
*/
resize(
screenWidth: number = window.innerWidth,
screenHeight: number = window.innerHeight,
screenWidth: number = typeof window === 'undefined' ? 0 : window.innerWidth,
screenHeight: number = typeof window === 'undefined' ? 0 : window.innerHeight,
worldWidth?: number,
worldHeight?: number
): void
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/Drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ export class Drag extends Plugin

private addWindowEventHandler(event: string, handler: (e: any) => void): void
{
if (typeof window === 'undefined') return;
window.addEventListener(event, handler);
this.windowEventHandlers.push({ event, handler });
}

public override destroy(): void
{
if (typeof window === 'undefined') return;
this.windowEventHandlers.forEach(({ event, handler }) =>
{
window.removeEventListener(event, handler);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/Wheel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class Wheel extends Plugin
*/
protected handleKeyPresses(codes: string[]): void
{
if (typeof window === 'undefined') return;
window.addEventListener('keydown', (e) =>
{
if (codes.includes(e.code))
Expand Down

0 comments on commit 5bb2ee7

Please sign in to comment.