Show PDF pages in one column that scrolls

The PDF tab shows all pages in one column. The wheel, Page Up, and
Page Down scroll. They do not change the page, and they draw nothing
again at the start or the end of the document.

- The zoom percent is a field. A typed percent sets the zoom. Ctrl and
  the wheel also change the zoom.
- The toolbar, the status line, and the password form are opaque, so a
  background image does not hide them.
- Ctrl+Tab and Ctrl+Shift+Tab give keyboard focus to the new plugin tab.

Cards: 9b7b246e, 59ff5dc1, 2e425cbc, 7bd092d2, 2142ca04, c0900ae8.
This commit is contained in:
Knotty Wyvern
2026-11-09 22:10:08 -07:00
parent 4408dfce5c
commit a4a8eaf4d2
9 changed files with 400 additions and 85 deletions
+33 -1
View File
@@ -4,7 +4,7 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import { featureEntry, featureOfOwner } from "../../../src/lib/features/catalog.ts";
import { identifyPdf } from "../../../src/lib/features/pdfDocument.ts";
import { nextRotation, outputScale, pageNumber, zoomLevel } from "../../../src/lib/features/pdf/model.ts";
import { PAGE_GAP, PAGE_MARGIN, fitZoom, mostVisiblePage, nextRotation, outputScale, pageBoxes, pageNumber, pagesInRange, zoomFromText, zoomLevel } from "../../../src/lib/features/pdf/model.ts";
import { FeatureSession } from "../../../src/lib/features/session.ts";
import type { FeatureContext, FeatureInstance } from "../../../src/lib/features/types.ts";
import type { PluginDocumentContext } from "../../../src/lib/plugins/sdk.ts";
@@ -26,6 +26,38 @@ test("page and zoom inputs stay within supported bounds", () => {
assert.deepEqual([0, 90, 180, 270].map(nextRotation), [90, 180, 270, 0]);
});
test("a typed zoom is a percent within the limits", () => {
assert.equal(zoomFromText("137"), 1.37);
assert.equal(zoomFromText(" 150 % "), 1.5);
assert.equal(zoomFromText("112,5"), 1.125);
assert.equal(zoomFromText("9000"), 4);
assert.equal(zoomFromText("1"), .25);
for (const text of ["", " ", "text", "-50", "0", "1e999"]) assert.equal(zoomFromText(text), null);
});
test("the pages are one column, and the scroll position gives the current page", () => {
const sizes = [{ width: 600, height: 800 }, { width: 800, height: 600 }, { width: 600, height: 800 }];
const boxes = pageBoxes(sizes, .5, 0);
assert.deepEqual(boxes, [
{ top: PAGE_MARGIN, width: 300, height: 400 },
{ top: PAGE_MARGIN + 400 + PAGE_GAP, width: 400, height: 300 },
{ top: PAGE_MARGIN + 700 + 2 * PAGE_GAP, width: 300, height: 400 },
]);
assert.deepEqual(pageBoxes(sizes, 1, 90).map(box => [box.width, box.height]), [[800, 600], [600, 800], [800, 600]]);
assert.equal(fitZoom(sizes, 0, 400), .5);
assert.equal(fitZoom(sizes, 90, 400), .5);
assert.equal(fitZoom([{ width: 600, height: 900 }], 90, 450), .5);
assert.equal(fitZoom([], 0, 400), 1);
assert.deepEqual(pagesInRange(boxes, 0, 100), [1]);
assert.deepEqual(pagesInRange(boxes, 400, 800), [1, 2, 3]);
assert.deepEqual(pagesInRange(boxes, 5000, 6000), []);
assert.equal(mostVisiblePage(boxes, 0, 300), 1);
assert.equal(mostVisiblePage(boxes, 300, 600), 2);
assert.equal(mostVisiblePage(boxes, 900, 1200), 3);
assert.equal(mostVisiblePage(boxes, 0, 2000), 1, "The first page wins when several pages show in full");
assert.equal(mostVisiblePage([], 0, 100), 1);
});
test("large PDF pages respect canvas dimension and memory limits", () => {
for (const [width, height] of [[612, 792], [20000, 500], [20000, 20000]]) {
const scale = outputScale(width, height, 3);