mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-04 11:38:12 +08:00
Split out viewport handling into its own message handler (#3331)
* extract viewport handeling * fix web overlays * some cleanup * remove some physical conversions * fix resize snapping * fixup * apply some review feedback * make viewport api more ergonomic * fix * fix web overlay canvas clear size * clear workaround for canvas * rename trigger message --------- Co-authored-by: Dennis Kobert <dennis@kobert.dev>
This commit is contained in:
@@ -2,13 +2,11 @@ import { type Editor } from "@graphite/editor";
|
||||
|
||||
export function updateBoundsOfViewports(editor: Editor) {
|
||||
const viewports = Array.from(window.document.querySelectorAll("[data-viewport-container]"));
|
||||
const boundsOfViewports = viewports.map((canvas) => {
|
||||
const bounds = canvas.getBoundingClientRect();
|
||||
return [bounds.left, bounds.top, bounds.right, bounds.bottom];
|
||||
});
|
||||
|
||||
const flattened = boundsOfViewports.flat();
|
||||
const data = Float64Array.from(flattened);
|
||||
if (viewports.length <= 0) return;
|
||||
|
||||
if (boundsOfViewports.length > 0) editor.handle.boundsOfViewports(data);
|
||||
const bounds = viewports[0].getBoundingClientRect();
|
||||
const scale = window.devicePixelRatio || 1;
|
||||
|
||||
editor.handle.updateViewport(bounds.x, bounds.y, bounds.width, bounds.height, scale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user