Skip to content

Commit

Permalink
Make it possible to use with SSR;
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Jun 5, 2019
1 parent 43bb6bc commit 8adb218
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ type IECompatibleWindow = Window & {
};
};

declare var global: {
window?: IECompatibleWindow;
};

const zoomLevelDetector = (
matchMedia: Window["matchMedia"],
currentLevel: number,
Expand Down Expand Up @@ -45,7 +49,11 @@ function calculatePageZoomLevel(win: Window): number {
}

function zoomLevel(win?: IECompatibleWindow): number {
win = win || window;
win = win || global.window;

if (!win) {
return 1;
}

if (typeof win.devicePixelRatio !== "undefined") {
return win.devicePixelRatio;
Expand All @@ -68,8 +76,6 @@ function zoomLevel(win?: IECompatibleWindow): number {
}

function elementZoomLevel(element: HTMLElement, elementStyles?: CSSStyleDeclaration, win?: IECompatibleWindow): number {
win = win || window;

elementStyles = elementStyles || getComputedStyle(element);

// @ts-ignore
Expand Down

0 comments on commit 8adb218

Please sign in to comment.