Skip to content

Commit

Permalink
Upgrade to PDF.js 4.7.76, tweak toolbar hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Oct 13, 2024
1 parent 30a42c8 commit bd34e12
Show file tree
Hide file tree
Showing 70 changed files with 3,142 additions and 1,285 deletions.
14 changes: 7 additions & 7 deletions dev/viewer/viewer.html.diff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/../../web/viewer.html b/../viewer/viewer.html
index 7c05f0ac5..4369c642c 100644
index 95d8aaf87..48b286276 100644
--- a/../../web/viewer.html
+++ b/../viewer/viewer.html
@@ -25,15 +25,17 @@ See https://github.com/adobe-type-tools/cmap-resources
Expand All @@ -21,13 +21,13 @@ index 7c05f0ac5..4369c642c 100644
+ <script src="out/viewer/latexworkshop.js" type="module"></script>
</head>

<body tabindex="1">
@@ -280,7 +282,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<button id="sidebarToggle" class="toolbarButton" type="button" title="Toggle Sidebar" tabindex="11" data-l10n-id="pdfjs-toggle-sidebar-button" aria-expanded="false" aria-controls="sidebarContainer">
<body tabindex="0">
@@ -89,7 +91,7 @@ See https://github.com/adobe-type-tools/cmap-resources
<button id="sidebarToggleButton" class="toolbarButton" type="button" title="Toggle Sidebar" tabindex="0" data-l10n-id="pdfjs-toggle-sidebar-button" aria-expanded="false" aria-haspopup="true" aria-controls="sidebarContainer">
<span data-l10n-id="pdfjs-toggle-sidebar-button-label">Toggle Sidebar</span>
</button>
- <div class="toolbarButtonSpacer"></div>
+ <!-- <div class="toolbarButtonSpacer"></div> -->
<button id="viewFind" class="toolbarButton" type="button" title="Find in Document" tabindex="12" data-l10n-id="pdfjs-findbar-button" aria-expanded="false" aria-controls="findbar">
<span data-l10n-id="pdfjs-findbar-button-label">Find</span>
</button>
<div class="toolbarButtonWithContainer">
<button id="viewFindButton" class="toolbarButton" type="button" title="Find in Document" tabindex="0" data-l10n-id="pdfjs-findbar-button" aria-expanded="false" aria-controls="findbar">
<span data-l10n-id="pdfjs-findbar-button-label">Find</span>
100 changes: 31 additions & 69 deletions dev/viewer/viewer.mjs.diff
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/../../web/viewer.mjs b/../viewer/viewer.mjs
index f6fcf25fc..743ed5ce4 100644
index a8fcc2a9d..f48339c2b 100644
--- a/../../web/viewer.mjs
+++ b/../viewer/viewer.mjs
@@ -763,7 +763,7 @@ const defaultOptions = {
@@ -758,7 +758,7 @@ const defaultOptions = {
kind: OptionKind.API
},
cMapUrl: {
Expand All @@ -11,7 +11,7 @@ index f6fcf25fc..743ed5ce4 100644
kind: OptionKind.API
},
disableAutoFetch: {
@@ -815,7 +815,7 @@ const defaultOptions = {
@@ -810,7 +810,7 @@ const defaultOptions = {
kind: OptionKind.API
},
standardFontDataUrl: {
Expand All @@ -20,7 +20,7 @@ index f6fcf25fc..743ed5ce4 100644
kind: OptionKind.API
},
useSystemFonts: {
@@ -832,7 +832,7 @@ const defaultOptions = {
@@ -827,7 +827,7 @@ const defaultOptions = {
kind: OptionKind.WORKER
},
workerSrc: {
Expand All @@ -29,7 +29,7 @@ index f6fcf25fc..743ed5ce4 100644
kind: OptionKind.WORKER
}
};
@@ -842,7 +842,7 @@ const defaultOptions = {
@@ -837,7 +837,7 @@ const defaultOptions = {
kind: OptionKind.VIEWER
};
defaultOptions.sandboxBundleSrc = {
Expand All @@ -38,7 +38,7 @@ index f6fcf25fc..743ed5ce4 100644
kind: OptionKind.VIEWER
};
defaultOptions.viewerCssTheme = {
@@ -2619,7 +2619,7 @@ class Localization {
@@ -2615,7 +2615,7 @@ class Localization {
if (typeof console !== "undefined") {
const locale = bundle.locales[0];
const ids = Array.from(missingIds).join(", ");
Expand All @@ -47,7 +47,7 @@ index f6fcf25fc..743ed5ce4 100644
}
}
if (!hasAtLeastOneBundle && typeof console !== "undefined") {
@@ -3099,11 +3099,11 @@ class GenericScripting {
@@ -3095,11 +3095,11 @@ class GenericScripting {
function initCom(app) {}
class Preferences extends BasePreferences {
async _writeToStorage(prefObj) {
Expand All @@ -61,7 +61,7 @@ index f6fcf25fc..743ed5ce4 100644
};
}
}
@@ -5138,7 +5138,7 @@ const FindState = {
@@ -5165,7 +5165,7 @@ const FindState = {
PENDING: 3
};
const FIND_TIMEOUT = 250;
Expand All @@ -70,7 +70,7 @@ index f6fcf25fc..743ed5ce4 100644
const MATCH_SCROLL_OFFSET_LEFT = -400;
const CHARACTERS_TO_NORMALIZE = {
"\u2010": "-",
@@ -7518,6 +7518,9 @@ function renderProgress(index, total) {
@@ -7567,6 +7567,9 @@ function renderProgress(index, total) {
}
window.addEventListener("keydown", function (event) {
if (event.keyCode === 80 && (event.ctrlKey || event.metaKey) && !event.altKey && (!event.shiftKey || window.chrome || window.opera)) {
Expand All @@ -80,7 +80,7 @@ index f6fcf25fc..743ed5ce4 100644
window.print();
event.preventDefault();
event.stopImmediatePropagation();
@@ -8102,7 +8105,7 @@ class PDFSidebar {
@@ -8151,7 +8154,7 @@ class PDFSidebar {
this.#dispatchEvent();
return;
}
Expand All @@ -89,7 +89,7 @@ index f6fcf25fc..743ed5ce4 100644
if (!this.isInitialEventDispatched) {
this.#dispatchEvent();
}
@@ -10714,7 +10717,7 @@ class PDFViewer {
@@ -10870,7 +10873,7 @@ class PDFViewer {
this.#enableNewAltTextWhenAddingImage = options.enableNewAltTextWhenAddingImage === true;
this.imageResourcesPath = options.imageResourcesPath || "";
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
Expand All @@ -98,59 +98,12 @@ index f6fcf25fc..743ed5ce4 100644
this.maxCanvasPixels = options.maxCanvasPixels;
this.l10n = options.l10n;
this.l10n ||= new genericl10n_GenericL10n();
@@ -11028,6 +11031,7 @@ class PDFViewer {
}
}
setDocument(pdfDocument) {
+ const oldScale = lwRecordRender(this);
if (this.pdfDocument) {
this.eventBus.dispatch("pagesdestroy", {
source: this
@@ -11094,7 +11098,7 @@ class PDFViewer {
eventBus._on("pagerendered", onAfterDraw, {
signal
});
- Promise.all([firstPagePromise, permissionsPromise]).then(([firstPdfPage, permissions]) => {
+ Promise.all([firstPagePromise, permissionsPromise]).then(async ([firstPdfPage, permissions]) => {
if (pdfDocument !== this.pdfDocument) {
return;
}
@@ -11131,7 +11135,7 @@ class PDFViewer {
@@ -11608,12 +11611,12 @@ class PDFViewer {
hPadding *= 2;
}
}
const viewerElement = this._scrollMode === ScrollMode.PAGE ? null : viewer;
- const scale = this.currentScale;
+ this._currentScale = oldScale; const scale = oldScale ? oldScale : this.currentScale;
const viewport = firstPdfPage.getViewport({
scale: scale * PixelsPerInch.PDF_TO_CSS_UNITS
});
@@ -11161,6 +11165,7 @@ class PDFViewer {
this._pages.push(pageView);
}
this._pages[0]?.setPdfPage(firstPdfPage);
+ await lwRenderSync(this, pdfDocument, pagesCount);
if (this._scrollMode === ScrollMode.PAGE) {
this.#ensurePageViewVisible();
} else if (this._spreadMode !== SpreadMode.NONE) {
@@ -11253,7 +11258,7 @@ class PDFViewer {
this._pages = [];
this._currentPageNumber = 1;
this._currentScale = UNKNOWN_SCALE;
- this._currentScaleValue = null;
+ // this._currentScaleValue = null;
this._pageLabels = null;
this.#buffer = new PDFPageViewBuffer(DEFAULT_CACHE_SIZE);
this._location = null;
@@ -11272,7 +11277,7 @@ class PDFViewer {
};
this.#eventAbortController?.abort();
this.#eventAbortController = null;
- this.viewer.textContent = "";
+ // this.viewer.textContent = "";
this._updateScrollMode();
this.viewer.removeAttribute("lang");
this.#hiddenCopyElement?.remove();
@@ -11453,8 +11458,8 @@ class PDFViewer {
} else if (this.removePageBorders) {
- hPadding = vPadding = 0;
+ if (this._scrollMode === ScrollMode.HORIZONTAL || this._spreadMode === SpreadMode.NONE) { hPadding = vPadding = 0; } else { hPadding = 10; vPadding = 0; }
} else if (this._scrollMode === ScrollMode.HORIZONTAL) {
[hPadding, vPadding] = [vPadding, hPadding];
}
Expand All @@ -161,7 +114,16 @@ index f6fcf25fc..743ed5ce4 100644
switch (value) {
case "page-actual":
scale = 1;
@@ -12793,10 +12798,10 @@ class ViewHistory {
@@ -11724,7 +11727,7 @@ class PDFViewer {
let hPadding = SCROLLBAR_PADDING,
vPadding = VERTICAL_PADDING;
if (this.removePageBorders) {
- hPadding = vPadding = 0;
+ if (this._scrollMode === ScrollMode.HORIZONTAL || this._spreadMode === SpreadMode.NONE) { hPadding = vPadding = 0; } else { hPadding = 10; vPadding = 0; }
}
widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS;
heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS;
@@ -12964,10 +12967,10 @@ class ViewHistory {
}
async _writeToStorage() {
const databaseStr = JSON.stringify(this.database);
Expand All @@ -174,7 +136,7 @@ index f6fcf25fc..743ed5ce4 100644
}
async set(name, val) {
await this._initializedPromise;
@@ -13381,7 +13386,7 @@ const PDFViewerApplication = {
@@ -13551,7 +13554,7 @@ const PDFViewerApplication = {
title = decodeURIComponent(getFilenameFromUrl(url));
} catch {}
}
Expand All @@ -183,7 +145,7 @@ index f6fcf25fc..743ed5ce4 100644
},
setTitle(title = this._title) {
this._title = title;
@@ -13805,7 +13810,7 @@ const PDFViewerApplication = {
@@ -13975,7 +13978,7 @@ const PDFViewerApplication = {
this.metadata = metadata;
this._contentDispositionFilename ??= contentDispositionFilename;
this._contentLength ??= contentLength;
Expand All @@ -192,7 +154,7 @@ index f6fcf25fc..743ed5ce4 100644
let pdfTitle = info.Title;
const metadataTitle = metadata?.get("dc:title");
if (metadataTitle) {
@@ -13936,9 +13941,9 @@ const PDFViewerApplication = {
@@ -14106,9 +14109,9 @@ const PDFViewerApplication = {
this.pdfSidebar?.setInitialView(sidebarView);
setViewerModes(scrollMode, spreadMode);
if (this.initialBookmark) {
Expand All @@ -204,7 +166,7 @@ index f6fcf25fc..743ed5ce4 100644
this.initialBookmark = null;
} else if (storedHash) {
setRotation(rotation);
@@ -15199,7 +15204,7 @@ function webViewerLoad() {
@@ -15370,7 +15373,7 @@ function webViewerLoad() {
try {
parent.document.dispatchEvent(event);
} catch (ex) {
Expand All @@ -213,7 +175,7 @@ index f6fcf25fc..743ed5ce4 100644
document.dispatchEvent(event);
}
PDFViewerApplication.run(config);
@@ -15216,4 +15221,3 @@ var __webpack_exports__PDFViewerApplicationConstants = __webpack_exports__.PDFVi
@@ -15387,4 +15390,3 @@ var __webpack_exports__PDFViewerApplicationConstants = __webpack_exports__.PDFVi
var __webpack_exports__PDFViewerApplicationOptions = __webpack_exports__.PDFViewerApplicationOptions;
export { __webpack_exports__PDFViewerApplication as PDFViewerApplication, __webpack_exports__PDFViewerApplicationConstants as PDFViewerApplicationConstants, __webpack_exports__PDFViewerApplicationOptions as PDFViewerApplicationOptions };

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2652,7 +2652,7 @@
"latex-utensils": "^6.2.0",
"mathjax-full": "^3.2.2",
"micromatch": "^4.0.8",
"pdfjs-dist": "4.6.82",
"pdfjs-dist": "4.7.76",
"tmp": "^0.2.3",
"workerpool": "^9.1.3",
"ws": "^8.18.0"
Expand Down
46 changes: 30 additions & 16 deletions viewer/components/gui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,37 @@ import type { PDFViewerApplicationType } from './interface.js'

declare const PDFViewerApplication: PDFViewerApplicationType

let hideToolbar: number | undefined
export function patchViewerUI() {
if (utils.isEmbedded()) {
// Cannot simply remove this element, as pdf.js indeed require it to
// bind listeners.
document.getElementById('print')!.style.display = 'none'
document.getElementById('printButton')!.style.display = 'none'
}

document.getElementById('outerContainer')!.onmousemove = (e) => {
if (e.clientY <= 64) {
if (hideToolbar) {
clearTimeout(hideToolbar)
hideToolbar = undefined
}
showToolbar()
} else {
if (hideToolbar === undefined && !PDFViewerApplication.findBar.opened && !PDFViewerApplication.pdfSidebar.isOpen && !PDFViewerApplication.secondaryToolbar.isOpen) {
hideToolbar = setTimeout(() => {
const toolbarDom = document.getElementsByClassName('toolbar')[0]
toolbarDom.classList.add('hide')
const containerDom = document.getElementById('viewerContainer')!
containerDom.classList.add('topped')
hideToolbar = undefined
}, 1000)
}
}
}

document.getElementById('sidebarResizer')?.classList.add('hidden')
document.getElementsByClassName('toolbar')[0]?.classList.add('hide')
document.getElementById('viewerContainer')!.classList.add('topped')
document.getElementById('firstPage')?.previousElementSibling?.classList.add('visibleLargeView')

const template = document.createElement('template')
Expand Down Expand Up @@ -55,7 +71,7 @@ export function patchViewerUI() {
<button class="toolbarButton findNext" title="${getL10n('navForward')} (⇧←)" id="historyForward">
<span>Forward</span>
</button>`
anchor = document.getElementById('sidebarToggle')!.nextElementSibling!
anchor = document.getElementById('sidebarToggleButton')!.nextElementSibling!
for (const node of template.content.childNodes) {
anchor.parentNode?.insertBefore(node, anchor)
}
Expand Down Expand Up @@ -212,18 +228,16 @@ export function repositionAnnotation() {
}
}

let hideToolbarInterval: number | undefined
function showToolbar(animate: boolean=true) {
if (hideToolbarInterval) {
clearInterval(hideToolbarInterval)
}
const d = document.getElementsByClassName('toolbar')[0]
d.className = d.className.replace(' hide', '') + (animate ? '' : ' notransition')

hideToolbarInterval = setInterval(() => {
if(!PDFViewerApplication.findBar.opened && !PDFViewerApplication.pdfSidebar.isOpen && !PDFViewerApplication.secondaryToolbar.isOpen) {
d.className = d.className.replace(' notransition', '') + ' hide'
clearInterval(hideToolbarInterval)
}
}, 3000)
function showToolbar() {
const toolbarDom = document.getElementsByClassName('toolbar')[0]
toolbarDom.classList.remove('hide')
const containerDom = document.getElementById('viewerContainer')!
containerDom.classList.remove('topped')

// hideToolbarInterval = setInterval(() => {
// if(!PDFViewerApplication.findBar.opened && !PDFViewerApplication.pdfSidebar.isOpen && !PDFViewerApplication.secondaryToolbar.isOpen) {
// d.className = d.className.replace(' notransition', '') + ' hide'
// clearInterval(hideToolbarInterval)
// }
// }, 3000)
}
Loading

0 comments on commit bd34e12

Please sign in to comment.