Skip to content

Add mobile PDF navigation and bounded document previews to Viewer - #678

Merged
kvz merged 5 commits into
mainfrom
viewer-docs
Nov 28, 2026
Merged

kvz merged 5 commits into
mainfrom
viewer-docs

Conversation

@kvz

@kvz kvz commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Why

Students need to read entire slide decks on phones. Portal download permissions and 60-second media grants still apply when a reader jumps to a later page. This implements the Viewer portion of DAM-104 and DAM-105 phase 1.

PDF reader

  • Opt into mode="pdfjs" to render one page with a selectable, screen-reader-accessible text layer. Readers can jump by page number, swipe or use the keyboard. The two fit buttons announce the active mode, zoom buttons disable at their limits, and Retry returns keyboard focus to the reader. The old canvas stays visible until the new canvas and text are ready.
  • PDF.js schedules byte ranges and streams responses to its worker. A fetch binding scoped to the packaged parser validates MIME, omits credentials and referrers, rejects redirects, and applies a 30-second inactivity timeout. Range-capable hosts can expose Accept-Ranges and Content-Length to enable on-demand reads.
  • renew(signal) supplies a signed URL for the same immutable version. Portals can omit src and resolve the first grant on open. Set documentKey to an immutable asset/version identifier so prop-driven changes to src or expiresAt preserve the page and worker. Concurrent ranges share a renewal, and a 401/403 retries the affected range in place. A separate originalLink slot lets the application provide its own permission-checked action. The default reader exposes no original-file link.
  • Both PDF modes report typed errors. Invalid URL and MIME use error feedback. Missing reader support uses unsupportedFallback. Native frames require a verified PDF endpoint. They show loading feedback until the iframe loads, and offer Retry after a browser error or timeout (30 seconds by default). Browsers hide cross-origin HTTP status. PDF.js accepts octet-stream responses only for PDF filenames. viewerKind excludes SVG.

Documents and integration

  • useDocumentPreview supports lazy grants, optional version and expiry, autoOpen, cancellation and retry. Text and Markdown honor the MIME charset and display their first 2 MiB with a truncation notice.
  • The stylesheet covers Markdown typography, tables, code and literal text wrapping. Server-rendered text and aligned Markdown tables work with external stylesheets only. Sandboxed RTF accepts app-provided light/dark colors or the OS scheme and preserves explicit document colors.
  • The changeset records absolute frame src normalization and the widened text classifier. The integration guide covers deployment, CORS, CSP and short-lived grants.

Validation

  • Viewer typecheck, 643 Viewer unit tests and monorepo yarn verify:full passed locally.
  • All 20 Playwright tests passed across Chromium and iPhone-emulated WebKit. A five-page fixture stays on page five through an expiry update and URL rotation, serves the next byte range from the new URL, and reopens on page one when the version changes. Other regressions cover concurrent denials, lazy grants, Retry focus, frame timeout, touch navigation, fit and zoom limits.
  • Safari 17.0 compatibility was exercised by removing newer APIs in the page and PDF worker before loading a real PDF. The packaged parser and worker include compatibility for promise resolvers and fixed-length buffer transfer. Physical iOS 17 hardware was not tested.
  • The local Yarn tarball is 2,256,793 bytes (2.15 MiB). All 39 packed TypeScript declaration files are free of pdfjs-dist and #pdfjs references.

Bundle impact

With minified split ESM and React external, the initial Viewer entry and its static imports total 9,232 bytes gzip. Opening the PDF reader adds 162,701 bytes gzip and a 403,179-byte gzip worker. Fonts, character maps and scan decoders load on demand.

🤖 Claimed by kvz on studio1/node-sdk since 2026-11-28 · resume: codex resume 01a2225d-7217-7113-ad88-07483c94f530

@kvz
kvz marked this pull request as ready for review November 28, 2026 20:13
@kvz
kvz merged commit 952e827 into main Nov 28, 2026
17 checks passed
@kvz
kvz deleted the viewer-docs branch November 28, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant