Give canvas pans momentum #15

Merged
reudy merged 1 commit from momentum-pan into main 2026-09-30 23:18:25 +02:00
Member

Releasing a pan now lets the view keep gliding in the drag's direction and slow to a stop, like a phone's scroll momentum. Only the position moves; the zoom never changes.

Behaviour

  • Release velocity is measured over the last 100 ms of the drag, so a drag that stops before lifting doesn't glide.
  • Velocity decays exponentially with time constant GLIDE_TAU = 325 ms: the view coasts about 325 px per 1 px/ms of release speed. Speed is capped at 6 px/ms so a wild flick can't throw the view far.
  • The glide is frame-rate independent (exact exponential integration per frame).
  • Touching the canvas catches the glide; wheel, zoom, fit (Ctrl+0/Ctrl+9) and page jumps stop it.
  • Applies to finger, mouse (middle-drag, space-drag, background drag) and pen pans. Pinch release doesn't glide. The swipe-to-add-page flick still works alongside it.

Changes

  • src/lib/ink/fling.ts: releaseVelocity() (now also used by flingDir), glideStep() and the tuning constants.
  • src/lib/state/viewport.svelte.ts: glide() / stopGlide(); other view changes cancel a glide.
  • src/lib/components/CanvasView.svelte: starts the glide on pan release and stops it on pointer down.
  • Tests for release velocity and glide math; README note on where to tune the drag.

Testing

  • npm test: 55/55 passing; npm run check: 0 errors, 0 warnings (run in a node:24-alpine Podman container).
  • Not yet tried in a browser or on a touch device.

🤖 Generated with Claude Code

https://claude.ai/code/session_015cuSqnxerdvXU934U9DddL

Releasing a pan now lets the view keep gliding in the drag's direction and slow to a stop, like a phone's scroll momentum. Only the position moves; **the zoom never changes**. ## Behaviour - Release velocity is measured over the last 100 ms of the drag, so a drag that stops before lifting doesn't glide. - Velocity decays exponentially with time constant `GLIDE_TAU` = 325 ms: the view coasts about 325 px per 1 px/ms of release speed. Speed is capped at 6 px/ms so a wild flick can't throw the view far. - The glide is frame-rate independent (exact exponential integration per frame). - Touching the canvas catches the glide; wheel, zoom, fit (`Ctrl+0`/`Ctrl+9`) and page jumps stop it. - Applies to finger, mouse (middle-drag, space-drag, background drag) and pen pans. Pinch release doesn't glide. The swipe-to-add-page flick still works alongside it. ## Changes - `src/lib/ink/fling.ts`: `releaseVelocity()` (now also used by `flingDir`), `glideStep()` and the tuning constants. - `src/lib/state/viewport.svelte.ts`: `glide()` / `stopGlide()`; other view changes cancel a glide. - `src/lib/components/CanvasView.svelte`: starts the glide on pan release and stops it on pointer down. - Tests for release velocity and glide math; README note on where to tune the drag. ## Testing - `npm test`: 55/55 passing; `npm run check`: 0 errors, 0 warnings (run in a `node:24-alpine` Podman container). - Not yet tried in a browser or on a touch device. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015cuSqnxerdvXU934U9DddL
agent added 1 commit 2026-09-30 21:42:46 +02:00
Releasing a pan now lets the view glide on in the drag's direction,
slowing under exponential drag (time constant GLIDE_TAU = 325 ms, so it
coasts about 325 px per 1 px/ms of release speed). Only the position
moves; the zoom is untouched. A drag that stops before lifting doesn't
glide. Touching the canvas, wheel, zoom or fit stops a glide.

Applies to finger, mouse (middle/space/background drag) and pen pans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cuSqnxerdvXU934U9DddL
reudy merged commit 49923833c9 into main 2026-09-30 23:18:25 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: reudy-net/Papure#15
No description provided.