From 7dbd62a30c631f5dad8948e14859d21aefa5c295 Mon Sep 17 00:00:00 2001 From: barnabasmolnar Date: Tue, 7 Apr 2026 19:19:43 +0200 Subject: [PATCH] implement snap-free scroll constraints --- .../with-nextjs/src/excalidrawWrapper.tsx | 15 +- .../components/ExampleApp.tsx | 42 ++ packages/excalidraw/actions/actionCanvas.tsx | 72 ++- packages/excalidraw/actions/manager.tsx | 7 + packages/excalidraw/appState.ts | 2 + packages/excalidraw/components/App.tsx | 488 ++++++++++++--- .../excalidraw/scene/scrollConstraints.ts | 590 ++++++++++++++++++ packages/excalidraw/scene/zoom.ts | 53 ++ packages/excalidraw/types.ts | 72 +++ 9 files changed, 1244 insertions(+), 97 deletions(-) create mode 100644 packages/excalidraw/scene/scrollConstraints.ts diff --git a/examples/with-nextjs/src/excalidrawWrapper.tsx b/examples/with-nextjs/src/excalidrawWrapper.tsx index fab4df6512..fefff9d8f6 100644 --- a/examples/with-nextjs/src/excalidrawWrapper.tsx +++ b/examples/with-nextjs/src/excalidrawWrapper.tsx @@ -5,6 +5,17 @@ import { Excalidraw } from "@excalidraw/excalidraw"; import "@excalidraw/excalidraw/index.css"; import App from "../../with-script-in-browser/components/ExampleApp"; +import type { ScrollConstraints } from "@excalidraw/excalidraw/types"; + +const scrollConstraints: ScrollConstraints = { + x: 0, + y: 0, + width: 850, + height: 400, + lockZoom: true, + overscrollAllowance: 0, + viewportZoomFactor: 1, +}; const ExcalidrawWrapper: React.FC = () => { return ( @@ -14,7 +25,9 @@ const ExcalidrawWrapper: React.FC = () => { useCustom={(api: any, args?: any[]) => {}} excalidrawLib={excalidrawLib} > - + ); diff --git a/examples/with-script-in-browser/components/ExampleApp.tsx b/examples/with-script-in-browser/components/ExampleApp.tsx index 294a11a58d..7b5e192c90 100644 --- a/examples/with-script-in-browser/components/ExampleApp.tsx +++ b/examples/with-script-in-browser/components/ExampleApp.tsx @@ -820,6 +820,48 @@ export default function ExampleApp({ /> Export with embed scene + +