omni-viewer-core 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -106,6 +106,9 @@ export async function mountPdfViewer(input, container, ctx, deps, options = {})
106
106
  let thumbRecords = [];
107
107
  let renderEpoch = 0;
108
108
  let currentPage = 1;
109
+ /** Page requested by an explicit navigation, held against the scroll event
110
+ * that navigation queues. Cleared once the reader scrolls themselves. */
111
+ let navigatedTo;
109
112
  let tool = 'view';
110
113
  let highlightColor = '#ffeb3b';
111
114
  let underlineColor = '#000000';
@@ -1359,12 +1362,29 @@ export async function mountPdfViewer(input, container, ctx, deps, options = {})
1359
1362
  // coordinate-based movement is enough. Combining this with
1360
1363
  // scrollIntoView applied the same offset twice.
1361
1364
  pages.scrollTop = Math.max(0, pages.scrollTop + page.top - viewport.top);
1365
+ // The scrollport clamps at its end, so pages inside the final screenful
1366
+ // — the pages appended by a merge, typically — never reach the top of
1367
+ // the viewport. Pin the requested page against the scroll event this
1368
+ // assignment queues; without it the listener re-selects the page that
1369
+ // does straddle the top and the click appears to land one page early.
1370
+ // Read the value back so the pin carries the clamped landing position.
1371
+ navigatedTo = { pageNumber: record.pageNumber, scrollTop: pages.scrollTop };
1362
1372
  requestAnimationFrame(() => {
1363
1373
  ctx.logger.log('info', `[pdf navigation] result page=${record.pageNumber} scrollTop=${pages.scrollTop} ` +
1364
1374
  `delta=${pages.scrollTop - before}`);
1365
1375
  });
1366
1376
  }
1367
1377
  function syncCurrentPageFromViewport() {
1378
+ if (navigatedTo) {
1379
+ // Still resting where the navigation left us: honour the request.
1380
+ // Any other offset means the reader has scrolled since, so the
1381
+ // viewport takes over again.
1382
+ if (Math.abs(pages.scrollTop - navigatedTo.scrollTop) <= 1) {
1383
+ setCurrentPage(navigatedTo.pageNumber);
1384
+ return;
1385
+ }
1386
+ navigatedTo = undefined;
1387
+ }
1368
1388
  const viewport = pages.getBoundingClientRect();
1369
1389
  const visible = records.filter((record) => {
1370
1390
  const box = record.wrapper.getBoundingClientRect();
@@ -1387,6 +1407,9 @@ export async function mountPdfViewer(input, container, ctx, deps, options = {})
1387
1407
  async function rebuildLayout() {
1388
1408
  if (!doc || disposed)
1389
1409
  return;
1410
+ // Page boxes are about to move (merge, reorder, delete, zoom), so a
1411
+ // pin taken against the old layout no longer describes anything.
1412
+ navigatedTo = undefined;
1390
1413
  // Preserve the source page the reader is actually viewing. `currentPage`
1391
1414
  // alone is not sufficient here: the lazy-render observer deliberately
1392
1415
  // observes pages outside the viewport as well.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omni-viewer-core",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Shared parsing + rendering core for Omni Viewer (vscode / chrome / obsidian / web)",
5
5
  "type": "module",
6
6
  "license": "MIT",