mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Stop using getTransform (#950)
* Stop using getTransform Fixes #861 The original motivation behind this is to make it work with Firefox. But it also helped make the code more intentional. Test Plan: - Create one square, select it, zoom in repeatedly, make sure that it zooms centered in the screen and everything looks good - Scroll at various zoom levels, things look good - Export a small scene at 1x and 3x, make sure the background is properly set and look good * fix selection element
This commit is contained in:
parent
dbfc8bee57
commit
b20d4539c0
6 changed files with 29 additions and 76 deletions
|
@ -42,6 +42,7 @@ export function exportToCanvas(
|
|||
elements,
|
||||
appState,
|
||||
null,
|
||||
scale,
|
||||
rough.canvas(tempCanvas),
|
||||
tempCanvas,
|
||||
{
|
||||
|
|
|
@ -17,4 +17,4 @@ export {
|
|||
hasText,
|
||||
} from "./comparisons";
|
||||
export { createScene } from "./createScene";
|
||||
export { getZoomOrigin, getZoomTranslation, getNormalizedZoom } from "./zoom";
|
||||
export { getZoomOrigin, getNormalizedZoom } from "./zoom";
|
||||
|
|
|
@ -16,19 +16,6 @@ export function getZoomOrigin(canvas: HTMLCanvasElement | null) {
|
|||
};
|
||||
}
|
||||
|
||||
export function getZoomTranslation(canvas: HTMLCanvasElement, zoom: number) {
|
||||
const diffMiddleOfTheCanvas = {
|
||||
x: (canvas.width / 2) * (zoom - 1),
|
||||
y: (canvas.height / 2) * (zoom - 1),
|
||||
};
|
||||
|
||||
// Due to JavaScript float precision, we fix to fix decimals count to have symmetric zoom
|
||||
return {
|
||||
x: parseFloat(diffMiddleOfTheCanvas.x.toFixed(8)),
|
||||
y: parseFloat(diffMiddleOfTheCanvas.y.toFixed(8)),
|
||||
};
|
||||
}
|
||||
|
||||
export function getNormalizedZoom(zoom: number): number {
|
||||
const normalizedZoom = parseFloat(zoom.toFixed(2));
|
||||
const clampedZoom = Math.max(0.1, Math.min(normalizedZoom, 2));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue