simplify code
This commit is contained in:
parent
19608b712f
commit
2e9c8851b3
@ -1,5 +1,7 @@
|
|||||||
import { isShallowEqual } from "@excalidraw/common";
|
import { isShallowEqual } from "@excalidraw/common";
|
||||||
|
|
||||||
|
import { clamp } from "@excalidraw/math";
|
||||||
|
|
||||||
import { getNormalizedZoom } from "./normalize";
|
import { getNormalizedZoom } from "./normalize";
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
@ -45,12 +47,10 @@ const calculateZoomLevel = (
|
|||||||
height: AppState["height"],
|
height: AppState["height"],
|
||||||
) => {
|
) => {
|
||||||
const viewportZoomFactor = scrollConstraints.viewportZoomFactor
|
const viewportZoomFactor = scrollConstraints.viewportZoomFactor
|
||||||
? Math.min(
|
? clamp(
|
||||||
MAX_VIEWPORT_ZOOM_FACTOR,
|
|
||||||
Math.max(
|
|
||||||
scrollConstraints.viewportZoomFactor,
|
scrollConstraints.viewportZoomFactor,
|
||||||
MIN_VIEWPORT_ZOOM_FACTOR,
|
MIN_VIEWPORT_ZOOM_FACTOR,
|
||||||
),
|
MAX_VIEWPORT_ZOOM_FACTOR,
|
||||||
)
|
)
|
||||||
: DEFAULT_VIEWPORT_ZOOM_FACTOR;
|
: DEFAULT_VIEWPORT_ZOOM_FACTOR;
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ const calculateScrollBounds = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const overscrollAllowance =
|
const overscrollAllowance =
|
||||||
scrollConstraints.overscrollAllowance ?? DEFAULT_OVERSCROLL_ALLOWANCE;
|
scrollConstraints.overscrollAllowance ?? DEFAULT_OVERSCROLL_ALLOWANCE;
|
||||||
const validatedOverscroll = Math.min(Math.max(overscrollAllowance, 0), 1);
|
const validatedOverscroll = clamp(overscrollAllowance, 0, 1);
|
||||||
|
|
||||||
const calculateCenter = (zoom: number) => {
|
const calculateCenter = (zoom: number) => {
|
||||||
const centerX =
|
const centerX =
|
||||||
@ -254,14 +254,8 @@ const constrainScrollValues = ({
|
|||||||
maxScrollY: number;
|
maxScrollY: number;
|
||||||
constrainedZoom: AppState["zoom"];
|
constrainedZoom: AppState["zoom"];
|
||||||
}): CanvasTranslate => {
|
}): CanvasTranslate => {
|
||||||
const constrainedScrollX = Math.min(
|
const constrainedScrollX = clamp(scrollX, minScrollX, maxScrollX);
|
||||||
maxScrollX,
|
const constrainedScrollY = clamp(scrollY, minScrollY, maxScrollY);
|
||||||
Math.max(scrollX, minScrollX),
|
|
||||||
);
|
|
||||||
const constrainedScrollY = Math.min(
|
|
||||||
maxScrollY,
|
|
||||||
Math.max(scrollY, minScrollY),
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
scrollX: constrainedScrollX,
|
scrollX: constrainedScrollX,
|
||||||
scrollY: constrainedScrollY,
|
scrollY: constrainedScrollY,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user