zoom persistenz
This commit is contained in:
@@ -126,10 +126,11 @@ async function loadPdf(index) {
|
||||
}
|
||||
loadedIndex = index;
|
||||
|
||||
const previousZoom = pdfViewer ? pdfViewer.zoom : 1;
|
||||
if (pdfViewer) {
|
||||
pdfViewer.destroy();
|
||||
}
|
||||
pdfViewer = new PdfViewer(pdfContainer);
|
||||
pdfViewer = new PdfViewer(pdfContainer, { initialZoom: previousZoom });
|
||||
viewer.classList.remove("loaded");
|
||||
pdfMessage.hidden = false;
|
||||
pdfMessage.textContent = "Loading PDF\u2026";
|
||||
|
||||
@@ -6,7 +6,7 @@ const ZOOM_MAX = 5;
|
||||
const ZOOM_STEP = 1.2; // multiplicative
|
||||
|
||||
class PdfViewer {
|
||||
constructor(container) {
|
||||
constructor(container, options = {}) {
|
||||
this.container = container;
|
||||
this.generation = 0;
|
||||
this.loadingTask = null;
|
||||
@@ -15,12 +15,18 @@ class PdfViewer {
|
||||
this.renderTasks = new Set();
|
||||
this.lastUrl = null;
|
||||
this.lastSize = null;
|
||||
this.zoom = 1; // multiplier on fit-to-width (1 = fit width)
|
||||
// multiplier on fit-to-width (1 = fit width); can be seeded from the
|
||||
// previous viewer instance so zoom survives switching documents
|
||||
this.zoom = Math.min(
|
||||
ZOOM_MAX,
|
||||
Math.max(ZOOM_MIN, options.initialZoom ?? 1),
|
||||
);
|
||||
this._lastRenderWidth = 0;
|
||||
this._resizeTimer = null;
|
||||
this._zoomTimer = null;
|
||||
this.resizeObserver = null;
|
||||
this._createDOM();
|
||||
this._updateZoomLabel();
|
||||
this._observeResize();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user