-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathworkspace.ts
32 lines (27 loc) · 1.21 KB
/
workspace.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { ids } from "@/constants";
export const getWorkspaceWidth = () => {
const workspace = document.getElementById(ids.workspaceContainer);
return workspace ? workspace.clientWidth : 0;
};
export const getWorkspaceHeight = () => {
const workspace = document.getElementById(ids.workspaceContainer);
return workspace ? workspace.clientHeight : 0;
};
export const getWorkspaceCenterX = () => {
const workspaceContainer = document.getElementById(ids.workspaceContainer);
if (typeof window === "undefined") return 0;
return window.innerWidth / 2 - (workspaceContainer?.offsetLeft ?? 0) - 8;
};
export const getWorkspaceCenterY = () => {
const workspaceContainer = document.getElementById(ids.workspaceContainer);
if (typeof window === "undefined") return 0;
return window.innerHeight / 2 - (workspaceContainer?.offsetTop ?? 0);
};
export const getScaleFactorAccountingForViewBoxWidth = (scaleFactor: number, initialViewBoxScaleForWidth?: number) => {
if (initialViewBoxScaleForWidth) {
const currentWidth = document.getElementById(ids.workspace)?.clientWidth;
const ratio = currentWidth / initialViewBoxScaleForWidth;
scaleFactor *= ratio >= 1 ? ratio : ratio * 1.25;
}
return scaleFactor;
};