feat: increase max zoom (#2881)
This commit is contained in:
parent
6abf4f52ff
commit
10cd6a24b0
@ -3,6 +3,7 @@ import { getDefaultAppState } from "../appState";
|
|||||||
import { ColorPicker } from "../components/ColorPicker";
|
import { ColorPicker } from "../components/ColorPicker";
|
||||||
import { resetZoom, trash, zoomIn, zoomOut } from "../components/icons";
|
import { resetZoom, trash, zoomIn, zoomOut } from "../components/icons";
|
||||||
import { ToolButton } from "../components/ToolButton";
|
import { ToolButton } from "../components/ToolButton";
|
||||||
|
import { ZOOM_STEP } from "../constants";
|
||||||
import { getCommonBounds, getNonDeletedElements } from "../element";
|
import { getCommonBounds, getNonDeletedElements } from "../element";
|
||||||
import { newElementWith } from "../element/mutateElement";
|
import { newElementWith } from "../element/mutateElement";
|
||||||
import { ExcalidrawElement } from "../element/types";
|
import { ExcalidrawElement } from "../element/types";
|
||||||
@ -75,8 +76,6 @@ export const actionClearCanvas = register({
|
|||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ZOOM_STEP = 0.1;
|
|
||||||
|
|
||||||
export const actionZoomIn = register({
|
export const actionZoomIn = register({
|
||||||
name: "zoomIn",
|
name: "zoomIn",
|
||||||
perform: (_elements, appState) => {
|
perform: (_elements, appState) => {
|
||||||
|
@ -52,6 +52,7 @@ import {
|
|||||||
TAP_TWICE_TIMEOUT,
|
TAP_TWICE_TIMEOUT,
|
||||||
TEXT_TO_CENTER_SNAP_THRESHOLD,
|
TEXT_TO_CENTER_SNAP_THRESHOLD,
|
||||||
TOUCH_CTX_MENU_TIMEOUT,
|
TOUCH_CTX_MENU_TIMEOUT,
|
||||||
|
ZOOM_STEP,
|
||||||
} from "../constants";
|
} from "../constants";
|
||||||
import { loadFromBlob } from "../data";
|
import { loadFromBlob } from "../data";
|
||||||
import { isValidLibrary } from "../data/json";
|
import { isValidLibrary } from "../data/json";
|
||||||
@ -3709,9 +3710,15 @@ class App extends React.Component<ExcalidrawProps, AppState> {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let newZoom = this.state.zoom.value - delta / 100;
|
||||||
|
// increase zoom steps the more zoomed-in we are (applies to >100% only)
|
||||||
|
newZoom += Math.log10(Math.max(1, this.state.zoom.value)) * -sign;
|
||||||
|
// round to nearest step
|
||||||
|
newZoom = Math.round(newZoom * ZOOM_STEP * 100) / (ZOOM_STEP * 100);
|
||||||
|
|
||||||
this.setState(({ zoom, offsetLeft, offsetTop }) => ({
|
this.setState(({ zoom, offsetLeft, offsetTop }) => ({
|
||||||
zoom: getNewZoom(
|
zoom: getNewZoom(
|
||||||
getNormalizedZoom(zoom.value - delta / 100),
|
getNormalizedZoom(newZoom),
|
||||||
zoom,
|
zoom,
|
||||||
{ left: offsetLeft, top: offsetTop },
|
{ left: offsetLeft, top: offsetTop },
|
||||||
{
|
{
|
||||||
|
@ -91,3 +91,5 @@ export const TOUCH_CTX_MENU_TIMEOUT = 500;
|
|||||||
export const TITLE_TIMEOUT = 10000;
|
export const TITLE_TIMEOUT = 10000;
|
||||||
export const TOAST_TIMEOUT = 5000;
|
export const TOAST_TIMEOUT = 5000;
|
||||||
export const VERSION_TIMEOUT = 30000;
|
export const VERSION_TIMEOUT = 30000;
|
||||||
|
|
||||||
|
export const ZOOM_STEP = 0.1;
|
||||||
|
@ -25,6 +25,6 @@ export const getNewZoom = (
|
|||||||
|
|
||||||
export const getNormalizedZoom = (zoom: number): NormalizedZoomValue => {
|
export const getNormalizedZoom = (zoom: number): NormalizedZoomValue => {
|
||||||
const normalizedZoom = parseFloat(zoom.toFixed(2));
|
const normalizedZoom = parseFloat(zoom.toFixed(2));
|
||||||
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 2));
|
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 10));
|
||||||
return clampedZoom as NormalizedZoomValue;
|
return clampedZoom as NormalizedZoomValue;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user