mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: emitted visible scene bounds not accounting for offsets (#7450)
This commit is contained in:
parent
561e919a2e
commit
6dfa89e846
8 changed files with 82 additions and 54 deletions
|
@ -9,7 +9,7 @@ import {
|
|||
import { distance2d, rotate, rotatePoint } from "../math";
|
||||
import rough from "roughjs/bin/rough";
|
||||
import { Drawable, Op } from "roughjs/bin/core";
|
||||
import { Point } from "../types";
|
||||
import { AppState, Point } from "../types";
|
||||
import { generateRoughOptions } from "../scene/Shape";
|
||||
import {
|
||||
isArrowElement,
|
||||
|
@ -35,7 +35,9 @@ export type RectangleBox = {
|
|||
|
||||
type MaybeQuadraticSolution = [number | null, number | null] | false;
|
||||
|
||||
// x and y position of top left corner, x and y position of bottom right corner
|
||||
/**
|
||||
* x and y position of top left corner, x and y position of bottom right corner
|
||||
*/
|
||||
export type Bounds = readonly [
|
||||
minX: number,
|
||||
minY: number,
|
||||
|
@ -43,6 +45,13 @@ export type Bounds = readonly [
|
|||
maxY: number,
|
||||
];
|
||||
|
||||
export type SceneBounds = readonly [
|
||||
sceneX: number,
|
||||
sceneY: number,
|
||||
sceneX2: number,
|
||||
sceneY2: number,
|
||||
];
|
||||
|
||||
export class ElementBounds {
|
||||
private static boundsCache = new WeakMap<
|
||||
ExcalidrawElement,
|
||||
|
@ -879,3 +888,21 @@ export const getCommonBoundingBox = (
|
|||
midY: (minY + maxY) / 2,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* returns scene coords of user's editor viewport (visible canvas area) bounds
|
||||
*/
|
||||
export const getVisibleSceneBounds = ({
|
||||
scrollX,
|
||||
scrollY,
|
||||
width,
|
||||
height,
|
||||
zoom,
|
||||
}: AppState): SceneBounds => {
|
||||
return [
|
||||
-scrollX,
|
||||
-scrollY,
|
||||
-scrollX + width / zoom.value,
|
||||
-scrollY + height / zoom.value,
|
||||
];
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue