141 Commits

Author SHA1 Message Date
Gaurav Dubey
12ec1f8754 fix(reading): flag oversized files before uploading reading materials (#3152)
The Add Materials dialog sent any file the user picked. A file over the
reader's 200 MiB single-file limit then crossed the Next proxy's 210 MiB
body cap, was truncated, and the submit button kept spinning with no
explanation.

Read the limit from /api/reading/supported-formats (already the server's
source of truth for the picker), mark an oversized file as soon as it is
chosen, and keep submit disabled until it is removed. If the limit cannot
be loaded, behaviour is unchanged and the server's own check still applies.

Closes #3151
2026-12-01 21:51:46 +08:00
1zrj
24aa2632d9 fix learning activity (ReadingCompanion, MasteryStudy, NoteCompanion) chat auto-follow (#2935) 2026-11-30 11:12:23 +08:00
mocias
23189ca690 fix(reading): keep Invidious picker controls inside its dialog (#3025) 2026-11-29 14:52:01 +08:00
Bingxi Zhao (Frank)
706ce1db38 fix(reading): zoom document images and synchronize annotations
Fixes #2499, #2472
2026-11-15 01:20:52 +08:00
Bingxi Zhao (Frank)
b9287142df fix(reading): retain the library picker during multiple selections
Local dev repairs for #2478.

UI interaction test verifies two selections, preserved search and no premature write. Web typecheck, 1407 Node tests, eslint and i18n passed.
2026-11-15 00:50:30 +08:00
Bingxi Zhao (Frank)
fa1edb75a2 fix: reconcile provider branding and locale contracts after PR integration
Register the verified SearchApi favicon with provenance, complete Italian many plurals and translated counts, and review the Italian/Hungarian language endonyms in Portuguese. Align labeled-stream fixtures with preserved Markdown examples and accepted thinking-tag aliases. Keep PDF layout memoization tied to the effective page ratio.
2026-11-14 23:47:30 +08:00
Bingxi Zhao (Frank)
3b267f2b8d Merge PR #2500: feat(reading): fit the page to its text, step zoom, and open a picture inside a PDF
Reconcile PDF zoom with cached text layers and 150 ms final repaint; let text gaps reach image hotspots; keep pointer-captured pan clicks from dismissing image preview. 97 PDF unit tests and 7 Chromium zoom/resize audits pass; real mouse image hotspot click verified.
2026-11-14 23:31:59 +08:00
Bingxi Zhao (Frank)
47eaab3c3c Merge PR #2648: perf(web): optimize PDF page rendering 2026-11-14 23:01:19 +08:00
Bingxi Zhao (Frank)
c60e0e0331 Merge PR #2576: feat(reading): record question-linked help without replacing the quiz
Keep server-only quiz answer keys before persisting help results; retain relationship and extension-policy revalidation.
2026-11-14 22:59:16 +08:00
zrj
9427c7543d perf(web): optimize PDF page rendering 2026-11-12 21:41:40 +08:00
LaiYongqiang
5b3feff863 feat(reading): open a picture inside a PDF
A PDF page is one bitmap by the time it reaches the DOM, so a picture inside it
has no element to click and no way to be read at its own size. A thumbnail in a
600-page scan could not be opened at all.

The operator list still knows where each picture was placed: `paintImageXObject`
draws the unit square through the current transformation matrix, so replaying
save/restore/transform/form-object pairing recovers the rectangle each picture
covers. Those rectangles become hotspots; clicking one opens the picture whole in
a preview with pan and zoom.

Four things that only show up once this meets real documents:

- **Hotspots sit UNDER the text layer, not over it.** They were DOM siblings
  after the text layer, so they stacked above it — and on an OCR scan, where one
  image covers the whole page, a single button sat over every word: selection,
  highlighting and clicking an existing annotation all stopped responding. A box
  covering most of the page is dropped in the geometry layer (it is the page
  bitmap, not a picture in it), the hotspots render before the text layer, and
  the mouseup guard that swallowed a selection ending on a picture is gone.
- **Only the active page is measured.** `getOperatorList` runs its own rendering
  intent, cached separately from the display one, so measuring the whole retained
  window parsed and decoded thirteen pages of images twice — full-resolution
  bitmaps kept on the main thread, past the canvas budget the visible ones obey.
- **Pictures inside annotation streams are skipped.** A stamp or signature is
  painted into the annotation's own canvas after the renderer resets the
  transform, so replaying its matrix as page space put the hotspot near the page
  origin, over whatever happened to be there.
- **The preview is a real modal.** It declared itself one but never took focus,
  so ⌘+/− acted on the page behind it and closing dropped focus on `<body>`. It
  focuses itself on open, restores the previous element on close, and stops
  Escape from also reaching the Guided Learning handler — both listeners sit on
  `window`, so `preventDefault` was never going to work. The stage no longer
  swallows every click either: a click on the empty area closes the overlay, a
  click on the picture does not.

The preview also sizes the canvas from the picture's box rather than its width
alone: a scanned page — one full-page hotspot — opened at 2.7x showing its middle
third, with zoom clamped at 1 and no way out.
2026-11-11 19:51:06 +08:00
LaiYongqiang
1e9e615fe2 feat(reading): fit the page to its text, and step zoom continuously
A PDF page was drawn at the pane's width, so the document's own white margins
sat on screen twice over — the page's margins plus the pane's padding. On a
1440px window that is roughly 735px of page inside a ~1165px pane, and the type
was about a fifth smaller than the pane could show. Zooming fixed the size but
cost horizontal scrolling: past Fit, reading meant dragging the page left and
right on every line.

**Fit text** trims the page's white margins by measuring where the ink actually
stops, then draws the page wider than the pane and clips it to the text block —
so the type fills the column without horizontal scrolling. **Fit page** is the
old behaviour, kept as its own mode. The zoom step became continuous (a factor
rather than a ladder), so a pinch settles anywhere and the next press starts
from what is on screen.

The measurement is the part that is easy to get wrong. It renders the page into
a 200px-wide scratch canvas rather than reading the operator list, because a page
that paints a white rectangle behind its text — which most do — would report a
full-page box from the operators alone, while the pixels show where the text
actually stops. Two consequences are handled here: a page whose render promise
never settles (some embedded browsers paint but never resolve) is given a
one-second bound and drawn uncropped, and a timed-out answer is not cached, so a
remount measures again instead of inheriting "nothing to crop" from a browser
that never replied.

Marks and paints are stored and converted in page space, not strip space: the
annotation layer paints on the full page while the visible strip is a crop of it,
so a rect normalised against the strip was stretched and shifted — a rect at
100px rendered at 62px.

A step is measured against the width that actually landed, and past the canvas
budget's ceiling the control disables rather than asking for a size below what is
drawn: a small page in a wide pane, trimmed to a half-width text block, can be
drawn above 400%, and clamping the ratio then stepping made "zoom in" shrink it.
A zoom that lands on the committed width drops its scroll anchor instead of
leaving one behind for the next pane resize to consume.

The crop ratio is state rather than a ref: the toolbar's enablement is derived
from it, and a ref write does not re-render — so the button stayed live until
something else happened to render.
2026-11-11 19:50:33 +08:00
LaiYongqiang
b29ffffe52 feat(reading): zoom the PDF reader
A PDF page was drawn at `clamp(panel - 48, 240, 1100)` with no zoom control, so
on a 1440px window roughly 735px of page sat inside a ~1165px pane — the page's
own white margins were still on screen, and the type was about a fifth smaller
than the pane could show.

Two modes. **Fit** is the historical behaviour, word for word the old width
formula, so nothing changes for a reader who never touches the bar. **Fixed** is
a percentage of the page's real size (96/72 of its `scale: 1` width — the same
reading Acrobat and Preview show), stepped along a ladder rather than by a fixed
percentage so the displayed number, the checked menu row and the next press all
describe the same size. Gestures: ⌘+/⌘−/⌘0, ctrl+wheel and pinch, each anchored
on the pointer so the page grows from where the reader is looking, in both axes.

The canvas budget is the part that is easy to get wrong. Safari silently drops a
bitmap past roughly 16.7M device pixels and answers with a blank page, so the
shared CSS width is clamped from page one's aspect ratio — and then each page
clamps its own bitmap again, because every page inherits that width while its
height follows its own ratio. The bitmap gives, never the layout, so the column
does not change size from page to page.

**Every step is measured against the width that actually landed.** The budget
clamps the drawn width, so a stored 4x on a tall page lands at 211%: multiplying
the *request* left the first several notches of a zoom-out drawing the same
width, and a zoom-in from there did nothing at all. The button step walks past
the stops the budget has flattened, the wheel gesture starts from what landed,
and the bar disables a control whose press cannot change the width. A zoom that
lands on the committed width drops its scroll anchor instead of leaving one
behind for the next pane resize to consume.

**A reader typing in a field keeps the keys.** The reader binds the same ⌘+ / ⌘−
/ ⌘0 the browser does, and with the pointer over a page those fired while the
reader typed in a note — `preventDefault` swallowed the browser's zoom, so the
field lost the keystroke and the page did not zoom either. The shortcut matcher
takes an `editableTarget` flag now, and `lib/shortcuts.ts` holds the one
predicate both readers use: the text reader binds the same three combinations and
had the same gap.

**The row a reader picks is the size they get.** `MIN_PAGE_WIDTH` (240px) is
above a Letter page's 25% (204px), so picking "25%" drew 29% while the toolbar
said 29% and the row still claimed 25%. Rows print the landed value.

The bar floats over the pane rather than inside the scroll container, so it does
not scroll away; its wrapper is transparent to pointers and only the toolbar
opts back in, or it would swallow wheel, selection and annotation clicks across
the bottom band of every page. It reveals on hover near that band and on focus —
`opacity-0` does not remove an element from the tab order. The menu is a radio
group (`menuitemradio` + `aria-checked`) with arrow keys, Home/End, and Escape
handled in the capture phase so it does not also reach the Guided Learning
handler — `preventDefault()` cannot stop a sibling listener on the same node. The
percentage is announced with `aria-live`, because it is the only feedback a step
produces for a reader who cannot see the page resize.

Safari reports a trackpad pinch as `gesturestart`/`gesturechange` rather than
ctrl+wheel, so those are cancelled on the pane: without it the browser zooms the
whole page. A zoom changed inside the 150ms debounce is flushed on `pagehide` and
on `visibilitychange`, not only on unmount — a closing tab or a backgrounded
phone never unmounts the component.

The bar's locale keys are filed with the reader's own display-control keys rather
than appended at the end of the catalog, which is what keeps this PR and the
lightbox PR from conflicting on the same files.
2026-11-11 18:31:38 +08:00
Yin
054769a139 feat(reading): keep recorded help inside each quiz question 2026-11-10 00:23:38 +08:00
Yin
5d16a6a2f0 fix(reading): keep quiz answer keys on the server 2026-11-09 22:17:03 +08:00
Bingxi Zhao (Frank)
20b7fa8c13 Load the document reader only for document tabs 2026-11-06 02:27:50 +08:00
FSOTM
70031420a6 feat(voice): read selected passages in chat, mastery and reading 2026-11-01 22:52:30 +08:00
Bingxi Zhao (Frank)
983b97148d Merge commit 'a7900033f202ddd942aa203e799656d340b669bb' into codex/validate-reviewed-integration 2026-10-31 18:52:31 +08:00
Rimcat-JA
697249df56 fix(reading): don't adopt a /chat conversation as the collection's
The chat state is shared app-wide, so a /chat thread is still loaded when
a reading collection mounts. The effect that names the first turn's
session in the URL ran before the boot effect and wrote that thread's id;
the boot then took it for its own and never started a reading draft, so
Explain / Translate / Guide went to the /chat thread without the page or
selection. Bind the URL only after the collection has started its own
draft, and never to the session that was open when it did.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 15:24:02 +09:00
Rimcat-JA
f75d44eb03 fix(reading): render uploaded Markdown files, including math
Uploaded .md / .markdown files were stored as plain_text, so immersive
reading showed their literal source and every formula stayed raw LaTeX.
Record them as web_markdown so they take the existing safe rich renderer
(KaTeX, no raw HTML). Images stay off for uploads, since their links can
point at any host; web snapshots keep their localized images.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 14:12:08 +09:00
Bingxi Zhao (Frank)
4ba34ecd46 Merge remote-tracking branch 'origin/dev' into HEAD 2026-10-27 21:40:18 +08:00
Bingxi Zhao (Frank)
c4f6b4972e fix(web): keep reading history controls reachable and refresh audit fixtures 2026-10-27 02:04:21 +08:00
Bingxi Zhao (Frank)
6bbcc00c55 Merge dev into preview, preserving preview features
Integrate dev fixes with preview's Python/TypeScript schedulers, chat queue, learning navigation, and live turn persistence.
2026-10-27 01:16:58 +08:00
Bingxi Zhao (Frank)
28c11e2ae8 feat: update notes, chat interactions and workspace UI on preview
Remove course pages, APIs and the course_study capability. Add anchored note
threads and reviewed learning-block generation, queued and withdrawable chat
messages, quote attachments, side chats, and the calendar/favorites/navigation
updates.

Keep preview's existing backend architecture. Wire the new features through
its Python application and existing chat engine, retain legacy selected-text
requests, persist mid-turn messages in replay, and restore note context when
regenerating. Leave stored user data intact.

Validate frontend contracts, dependency boundaries, types, 1290 node tests,
840 rendered tests, lint, localization and the production build. Exercise
session/notes/API regressions, 53 chat-engine tests and 20 Python/native
integration tests with isolated runtime data.
2026-10-26 22:13:34 +08:00
LaiYongqiang
c446acade0 fix(web): pass cMapUrl so CID fonts are not dropped
Released builds ship only public/pdfjs/wasm and pass just wasmUrl to
getDocument, so PDF.js cannot translate any font that depends on a
predefined CMap. Those fonts (Adobe-GB1/Japan1/Korea1, i.e. most CJK
documents) are then dropped entirely: no glyphs are painted and no text
items are produced, so headings disappear while their line height stays
reserved, and the affected runs cannot be selected, copied or searched.

Copy pdfjs-dist/cmaps next to the decoder assets, expose pdfjsCMapUrl()
and pass cMapUrl + cMapPacked.

Refs #2055
2026-10-26 16:24:32 +08:00
Bingxi Zhao (Frank)
583bdfc714 Merge PR #1945: fence edited submissions and isolate recovery by account and backend support 2026-10-19 01:03:40 +08:00
Bingxi Zhao (Frank)
399297e7f0 feat: preserve TypeScript engine migration and workspace updates 2026-10-18 23:09:10 +08:00
Mrmo072
adcf7dfa25 fix(chat): resolve browser-local unsent submission recovery 2026-10-15 14:41:46 +08:00
Bingxi Zhao (Frank)
33dea073bb perf(reading): load Markdown export only when requested 2026-10-15 01:52:08 +08:00
yepyhun
f986774b87 fix(chat): durably replace uncertain submissions and isolate recovery owners 2026-10-13 12:07:47 +02:00
Bingxi Zhao (Frank)
8986c31580 feat(reading): complete Watching convergence with safe legacy migration (#1378)
Adapted the migration foundation from PR #1384 while preserving current workspace, caption and turn-admission safeguards.

Co-authored-by: XZH <cto@xzh.ai>
2026-10-08 02:48:50 +08:00
Bingxi Zhao (Frank)
ecdc146d13 fix(reading): keep Markdown pagination visible in narrow panels (#1641) 2026-10-08 00:10:24 +08:00
Bingxi Zhao (Frank)
4cdf4fffcb perf(reading): load workspace dialogs only when opened 2026-10-07 20:58:20 +08:00
Bingxi Zhao (Frank)
e49f518669 Reconcile user setup and provider changes with all reviewed PRs 2026-10-07 20:54:24 +08:00
flower-moon
849ab28716 feat(web): fully resizable reading workspace panels + focus preset (#1310)
* feat(web): let the reading companion claim half the window with a focus preset

The companion column was drag-resizable only within a hard 640px cap, which
left readers with a narrow chat pane on wide monitors; leaving immersive
reading for the full chat loses the viewport-grounded context, so widening
the pane in place is the better escape hatch.

- Raise the drag ceiling to half the window width (the reader track keeps
  its minmax(360px,1fr) floor; the stored-width validator follows).
- Add a focus preset next to the panel toggles: one click collapses the
  contents navigator and sets the companion to half the window; exiting
  restores the previous width and navigator state. Ephemeral like the
  navigator collapse state - only the width persists.
- Hide the preset on narrow screens where the companion renders as a sheet.

* feat(web): fully resizable reading workspace panels

Extend the reading workspace from a companion-only drag handle to fully
user-sized panels:

- The contents navigator gains its own drag divider (184-400px, persisted
  in dt.reader.navigatorWidth) instead of a fixed 184-230px track.
- The companion's ceiling is now the reader's minimum width, not half the
  window: with the navigator collapsed the companion can claim all but
  360px, so readers on wide monitors can make the chat pane as large as
  the layout physically allows.
- The grid renders both dividers as dedicated 5px tracks so each handle
  owns one column and auto-placement lines the panels up.
- A persisted width that no longer fits (window moved to a smaller screen)
  is clamped at render time so the reader never drops below its floor.

* fix(web): measure the reading grid, not the window, for panel ceilings

The app sidebar sits outside the reading grid, so innerWidth overstates
the space the panels share and a companion dragged past the container
overflowed off-screen. Track the grid container with a ResizeObserver and
derive the companion ceiling (drag-time and render-time) plus the focus
preset from the measured frame, accounting for the divider tracks.

* Adapt reading panel resize and focus to current workspace layout

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-10-07 20:51:05 +08:00
Bingxi Zhao (Frank)
f8be756906 Integrate saved user workspace changes with reviewed dev updates 2026-10-07 20:37:55 +08:00
evan188199-tech
a597998134 fix(reading): converge the mobile header and dock the selection panel (#1734)
Below 768px the reader header converges to back, title + chapter,
bookmark and more: forward moves into the more menu (also when the
workspace hosts it), the file icon yields its width, and the chapter
indicator truncates inside a bounded share of the row instead of
disappearing. The selection panel becomes a bottom card on phones:
collapsed rows for short content, a capped scrollable body for the
note editor and overflow actions, a drag handle for pull-down-to-
dismiss, and safe-area padding; the desktop popover is unchanged.

Refs #916

Co-authored-by: XZH <cto@xzh.ai>
2026-10-07 20:29:14 +08:00
Bingxi Zhao (Frank)
8ccca47bac fix(reading): track EPUB text progress within chapters (#1673) 2026-10-04 18:20:29 +08:00
Bingxi Zhao (Frank)
ed3f9e9b4e fix(chat): distinguish unconfirmed replies from expired questions (#1648) 2026-10-04 18:14:40 +08:00
Bingxi Zhao (Frank)
0d8f4a4c87 perf(reading): defer EPUB and video marks until needed 2026-10-04 15:51:09 +08:00
Bingxi Zhao (Frank)
8b51caf055 fix(reading): isolate audio cleanup across delayed playback and unmount 2026-10-04 15:07:00 +08:00
Bingxi Zhao
90d2d06366 Merge pull request #1655 from evan188199-tech/codex/feat/reading-natural-tts
feat(reading): add material-scoped natural read-aloud audio (#1654)
2026-10-04 15:04:37 +08:00
Bingxi Zhao (Frank)
dfeb2fb4f3 Merge dev into PR #1657 and preserve integrated behavior 2026-10-04 14:22:45 +08:00
Bingxi Zhao
891493b7b1 Merge pull request #1686 from evan188199-tech/codex/fix/epub-toc-anchors
fix(reading): preserve EPUB outline anchors (#1673)
2026-10-04 14:20:41 +08:00
Bingxi Zhao
1ae435ef87 Merge pull request #1688 from ZyPulse-zy/fix/pdf-resize-reading-position
fix(reading): preserve PDF reading position across resizes
2026-10-04 14:19:54 +08:00
ZyPulse
c0a51ce90e fix(reading): preserve PDF reading position across resizes 2026-10-02 14:44:13 +08:00
XZH
95e913a787 fix(reading): preserve EPUB outline anchors 2026-10-01 17:26:44 -07:00
larryluozhang
c764de69ed fix(learning): mint quiz submission ids via randomUuid on plain HTTP
Two quiz submit paths still called crypto.randomUUID() directly, which
exists only in secure contexts. Over plain HTTP (LAN box, VPS without
TLS) the call throws inside the click handler before the request is
staged — the save silently never happens. PracticeSession already mints
ids via lib/random-uuid for exactly this reason; switch the two
remaining call sites to the same helper:

- BooksRoute recordQuizAttempt (book page quiz blocks)
- ReadingExtensionBar submitReadingQuizAnswers (reading quiz answers)
2026-09-29 23:27:49 +08:00
XZH
cd474bc824 feat(reading): add server-owned quiz star rewards (#1656) 2026-09-29 06:17:54 -07:00
XZH
eeb360f66a feat(reading): add material-scoped natural read-aloud audio (#1654) 2026-09-29 05:56:41 -07:00