mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
parent
fdc462ec01
commit
e9067de173
32 changed files with 1369 additions and 464 deletions
|
@ -110,9 +110,18 @@ export const updateSceneData = (data: SceneData) => {
|
|||
const originalGetBoundingClientRect =
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect;
|
||||
|
||||
export const mockBoundingClientRect = () => {
|
||||
// override getBoundingClientRect as by default it will always return all values as 0 even if customized in html
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = () => ({
|
||||
export const mockBoundingClientRect = (
|
||||
{
|
||||
top = 0,
|
||||
left = 0,
|
||||
bottom = 0,
|
||||
right = 0,
|
||||
width = 1920,
|
||||
height = 1080,
|
||||
x = 0,
|
||||
y = 0,
|
||||
toJSON = () => {},
|
||||
} = {
|
||||
top: 10,
|
||||
left: 20,
|
||||
bottom: 10,
|
||||
|
@ -121,10 +130,39 @@ export const mockBoundingClientRect = () => {
|
|||
x: 10,
|
||||
y: 20,
|
||||
height: 100,
|
||||
toJSON: () => {},
|
||||
},
|
||||
) => {
|
||||
// override getBoundingClientRect as by default it will always return all values as 0 even if customized in html
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect = () => ({
|
||||
top,
|
||||
left,
|
||||
bottom,
|
||||
right,
|
||||
width,
|
||||
height,
|
||||
x,
|
||||
y,
|
||||
toJSON,
|
||||
});
|
||||
};
|
||||
|
||||
export const withExcalidrawDimensions = async (
|
||||
dimensions: { width: number; height: number },
|
||||
cb: () => void,
|
||||
) => {
|
||||
mockBoundingClientRect(dimensions);
|
||||
// @ts-ignore
|
||||
window.h.app.refreshDeviceState(h.app.excalidrawContainerRef.current!);
|
||||
window.h.app.refresh();
|
||||
|
||||
await cb();
|
||||
|
||||
restoreOriginalGetBoundingClientRect();
|
||||
// @ts-ignore
|
||||
window.h.app.refreshDeviceState(h.app.excalidrawContainerRef.current!);
|
||||
window.h.app.refresh();
|
||||
};
|
||||
|
||||
export const restoreOriginalGetBoundingClientRect = () => {
|
||||
global.window.HTMLDivElement.prototype.getBoundingClientRect =
|
||||
originalGetBoundingClientRect;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue