fix(viewer): apply the PDF wheel stop as the page-width preset

This commit is contained in:
Kelvin Amoaba
2026-11-08 20:48:40 +00:00
parent c50a391792
commit 69ca99ac51
2 changed files with 9 additions and 8 deletions
@@ -22,11 +22,11 @@ const bounds = { min: 0.25, max: 5 }
describe('zoomPdfViewerWithWheel', () => {
it('stops on the fit-width scale when a step would pass it, then leaves it', () => {
const viewer = fakeViewer(1)
const below = fakeViewer(1)
expect(zoomPdfViewerWithWheel(below, zoomInEvent, bounds, () => 1.5)).toBe('page-width')
expect(below.currentScaleValue).toBe('page-width')
expect(zoomPdfViewerWithWheel(viewer, zoomInEvent, bounds, () => 1.5)).toBe('page-width')
expect(viewer.currentScale).toBe(1.5)
expect(zoomPdfViewerWithWheel(viewer, zoomInEvent, bounds, () => 1.5)).toBeGreaterThan(1.5)
const atFit = fakeViewer(1.5)
expect(zoomPdfViewerWithWheel(atFit, zoomInEvent, bounds, () => 1.5)).toBeGreaterThan(1.5)
})
})
@@ -87,12 +87,13 @@ export function zoomPdfViewerWithWheel(
}
const { container } = viewer
const rect = container.getBoundingClientRect()
// Why: an absolute scale avoids updateScale's 0.01 rounding, which swallows slow pinches.
viewer.currentScale = next
const fitted = next === fitScale
if (fitted) {
// Why: same scale, so pdf.js only records the preset resizes refit to; update() below may change the page it fits.
// Why: the preset is what resizes refit to; a numeric set first could move pdf.js to a page of another width.
viewer.currentScaleValue = 'page-width'
} else {
// Why: an absolute scale avoids updateScale's 0.01 rounding, which swallows slow pinches.
viewer.currentScale = next
}
// Why: pdf.js keeps the viewport's top-left fixed, so shift by the pointer's grown offset.
const growth = next / previous - 1