Skip to content

Commit

Permalink
Update to PDF.js v4.0.189
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Nov 16, 2023
1 parent add9692 commit 2d1e7ae
Show file tree
Hide file tree
Showing 238 changed files with 45,696 additions and 40,723 deletions.
3 changes: 1 addition & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
test/utils/decycle.ts
dev/*.js
src/lib/**/*.*
types/**/*.ts
resources/**/*.js
out
node_modules
viewer/viewer.js
viewer/viewer.mjs
.idea/
__pycache__/
.mypy_cache/
Expand Down
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ node_modules/pegjs-backtrace/
node_modules/commander/

node_modules/pdfjs-dist/build/*.min.js
node_modules/pdfjs-dist/build/*.min.mjs
node_modules/pdfjs-dist/legacy/
node_modules/pdfjs-dist/image_decoders/
node_modules/pdfjs-dist/lib/
Expand Down
23 changes: 12 additions & 11 deletions dev/editviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,31 @@
fout.write(
line.replace('''<title>PDF.js viewer</title>''', '''<meta http-equiv="Content-Security-Policy" content="default-src 'self'; base-uri 'none'; connect-src 'self' ws://127.0.0.1:*; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:;">\n <title>PDF.js viewer</title>''')
.replace('''<link rel="stylesheet" href="viewer.css">''', '''<link rel="stylesheet" href="viewer.css">\n <link rel="stylesheet" href="latexworkshop.css">''')
.replace('''<script src="../build/pdf.js"></script>''', '''<script src="build/pdf.js" defer></script>''')
.replace('''<script src="viewer.js"></script>''', '''<script src="out/viewer/latexworkshop.js" type="module"></script>''')
.replace('''<script src="../build/pdf.mjs" type="module"></script>''', '''<script src="build/pdf.mjs" type="module"></script>''')
.replace('''<script src="viewer.mjs" type="module"></script>''', '''<script src="out/viewer/latexworkshop.js" type="module"></script>''')
)

with open(args.web + '/viewer.js', 'rt', encoding='utf-8') as fin:
with open(args.viewer + '/viewer.js', 'wt', encoding='utf-8') as fout:
with open(args.web + '/viewer.mjs', 'rt', encoding='utf-8') as fin:
with open(args.viewer + '/viewer.mjs', 'wt', encoding='utf-8') as fout:
for line in fin:
fout.write(
line.replace('''this.setTitle(title);''', '''// this.setTitle(title);''')
.replace('''const MATCH_SCROLL_OFFSET_TOP = -50;''', '''const MATCH_SCROLL_OFFSET_TOP = -100;''')
line.replace('''const MATCH_SCROLL_OFFSET_TOP = -50;''', '''const MATCH_SCROLL_OFFSET_TOP = -100;''')
.replace('''this.switchView(view, true);''', '''this.switchView(view, false);''')
.replace('''console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);''', '''// console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);''')
.replace('''this.removePageBorders = options.removePageBorders || false;''', '''this.removePageBorders = options.removePageBorders || true;''')
.replace('''localStorage.setItem("pdfjs.history", databaseStr);''', '''// localStorage.setItem("pdfjs.history", databaseStr);''')
.replace('''return localStorage.getItem("pdfjs.history");''', '''return // localStorage.getItem("pdfjs.history");''')
.replace('''this.setTitle(title);''', '''// this.setTitle(title);''')
.replace('''localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));''', '''// localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));''')
.replace('''return JSON.parse(localStorage.getItem("pdfjs.preferences"));''', '''return // JSON.parse(localStorage.getItem("pdfjs.preferences"));''')
.replace('''console.warn('#' + key + ' is undefined.');''', '''// console.warn('#' + key + ' is undefined.');''')
.replace('''prefs: JSON.parse(localStorage.getItem("pdfjs.preferences"))''', '''prefs: undefined // JSON.parse(localStorage.getItem("pdfjs.preferences"))''')
.replace('''(!event.shiftKey || window.chrome || window.opera)) {''', '''(!event.shiftKey || window.chrome || window.opera)) {\n if (window.parent !== window) {\n return;\n }''')
.replace('''console.error(`webviewerloaded: ''', '''// console.error(`webviewerloaded: ''')
.replace('''//# sourceMappingURL=viewer.mjs.map''', '''''')
.replace('''console.log(`PDF ${pdfDocument.''', '''// console.log(`PDF ${pdfDocument.''')
# .replace('''pdfjsLib = require("../build/pdf.js");''','''pdfjsLib = require("./build/pdf.js");''')
.replace('''value: "../build/pdf.worker.js",''', '''value: "./build/pdf.worker.js",''')
.replace('''value: "../build/pdf.worker.mjs",''', '''value: "./build/pdf.worker.mjs",''')
.replace('''value: "../build/pdf.sandbox.mjs",''', '''value: "./build/pdf.sandbox.mjs",''')
.replace('''parent.document.dispatchEvent(event);''', '''parent.document.dispatchEvent(event); \n document.dispatchEvent(event);''')
)

os.system(f'git diff --no-index {args.web}/viewer.html {args.viewer}/viewer.html > {args.viewer}/../dev/viewer/viewer.html.diff')
os.system(f'git diff --no-index {args.web}/viewer.js {args.viewer}/viewer.js > {args.viewer}/../dev/viewer/viewer.js.diff')
os.system(f'git diff --no-index {args.web}/viewer.mjs {args.viewer}/viewer.mjs > {args.viewer}/../dev/viewer/viewer.mjs.diff')
14 changes: 7 additions & 7 deletions dev/viewer/viewer.html.diff
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/../web/viewer.html b/../viewer/viewer.html
index 5763b86d..6adbd130 100644
diff --git a/../web/viewer.html b/viewer/viewer.html
index 263f6246..b3d67daf 100644
--- a/../web/viewer.html
+++ b/../viewer/viewer.html
+++ b/viewer/viewer.html
@@ -25,15 +25,17 @@ See https://github.com/adobe-type-tools/cmap-resources
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
Expand All @@ -10,14 +10,14 @@ index 5763b86d..6adbd130 100644
<title>PDF.js viewer</title>

<!-- This snippet is used in production (included from viewer.html) -->
<link rel="resource" type="application/l10n" href="locale/locale.properties">
-<script src="../build/pdf.js"></script>
+<script src="build/pdf.js" defer></script>
<link rel="resource" type="application/l10n" href="locale/locale.json">
-<script src="../build/pdf.mjs" type="module"></script>
+<script src="build/pdf.mjs" type="module"></script>

<link rel="stylesheet" href="viewer.css">
+ <link rel="stylesheet" href="latexworkshop.css">

- <script src="viewer.js"></script>
- <script src="viewer.mjs" type="module"></script>
+ <script src="out/viewer/latexworkshop.js" type="module"></script>
</head>

Expand Down
132 changes: 74 additions & 58 deletions dev/viewer/viewer.js.diff → dev/viewer/viewer.mjs.diff
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
diff --git a/../web/viewer.js b/../viewer/viewer.js
index 2043b5a4..eadaa52e 100644
--- a/../web/viewer.js
+++ b/../viewer/viewer.js
@@ -43,10 +43,10 @@ const GenericCom = {};
exports.GenericCom = GenericCom;
class GenericPreferences extends _preferences.BasePreferences {
async _writeToStorage(prefObj) {
- localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
+ // localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
}
async _readFromStorage(prefObj) {
- return JSON.parse(localStorage.getItem("pdfjs.preferences"));
+ return // JSON.parse(localStorage.getItem("pdfjs.preferences"));
}
}
class GenericExternalServices extends _app.DefaultExternalServices {
@@ -683,7 +683,7 @@ const PDFViewerApplication = {
title = url;
}
}
- this.setTitle(title);
+ // this.setTitle(title);
},
setTitle(title = this._title) {
this._title = title;
@@ -1152,7 +1152,7 @@ const PDFViewerApplication = {
this.metadata = metadata;
this._contentDispositionFilename ??= contentDispositionFilename;
this._contentLength ??= contentLength;
- console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
+ // console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${_pdfjsLib.version || "?"} [${_pdfjsLib.build || "?"}])`);
let pdfTitle = info.Title;
const metadataTitle = metadata?.get("dc:title");
if (metadataTitle) {
@@ -3184,7 +3184,7 @@ const defaultOptions = {
diff --git a/../web/viewer.mjs b/viewer/viewer.mjs
index 1326dc12..038d4c53 100644
--- a/../web/viewer.mjs
+++ b/viewer/viewer.mjs
@@ -795,7 +795,7 @@ const defaultOptions = {
kind: OptionKind.WORKER
},
workerSrc: {
- value: "../build/pdf.worker.js",
+ value: "./build/pdf.worker.js",
- value: "../build/pdf.worker.mjs",
+ value: "./build/pdf.worker.mjs",
kind: OptionKind.WORKER
}
};
@@ -5155,7 +5155,7 @@ const FindState = {
@@ -813,7 +813,7 @@ const defaultOptions = {
kind: OptionKind.VIEWER
};
defaultOptions.sandboxBundleSrc = {
- value: "../build/pdf.sandbox.mjs",
+ value: "./build/pdf.sandbox.mjs",
kind: OptionKind.VIEWER
};
}
@@ -2539,7 +2539,7 @@ const FindState = {
PENDING: 3
};
exports.FindState = FindState;
const FIND_TIMEOUT = 250;
-const MATCH_SCROLL_OFFSET_TOP = -50;
+const MATCH_SCROLL_OFFSET_TOP = -100;
const MATCH_SCROLL_OFFSET_LEFT = -400;
const CHARACTERS_TO_NORMALIZE = {
"\u2010": "-",
@@ -7755,7 +7755,7 @@ class PDFSidebar {
@@ -5136,7 +5136,7 @@ class PDFSidebar {
this.#dispatchEvent();
return;
}
Expand All @@ -60,16 +38,25 @@ index 2043b5a4..eadaa52e 100644
if (!this.isInitialEventDispatched) {
this.#dispatchEvent();
}
@@ -8655,7 +8655,7 @@ class PDFViewer {
this.#annotationEditorMode = options.annotationEditorMode ?? _pdfjsLib.AnnotationEditorType.NONE;
@@ -6948,7 +6948,7 @@ class Localization {
if (typeof console !== "undefined") {
const locale = bundle.locales[0];
const ids = Array.from(missingIds).join(", ");
- console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);
+ // console.warn(`[fluent] Missing translations in ${locale}: ${ids}`);
}
}
if (!hasAtLeastOneBundle && typeof console !== "undefined") {
@@ -9089,7 +9089,7 @@ class PDFViewer {
this.#annotationEditorMode = options.annotationEditorMode ?? AnnotationEditorType.NONE;
this.imageResourcesPath = options.imageResourcesPath || "";
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
- this.removePageBorders = options.removePageBorders || false;
+ this.removePageBorders = options.removePageBorders || true;
if (options.useOnlyCssZoom) {
console.error("useOnlyCssZoom was removed, please use `maxCanvasPixels = 0` instead.");
options.maxCanvasPixels = 0;
@@ -12516,10 +12516,10 @@ class ViewHistory {
this.isOffscreenCanvasSupported = options.isOffscreenCanvasSupported ?? true;
this.maxCanvasPixels = options.maxCanvasPixels;
this.l10n = options.l10n || NullL10n;
@@ -11034,10 +11034,10 @@ class ViewHistory {
}
async _writeToStorage() {
const databaseStr = JSON.stringify(this.database);
Expand All @@ -82,16 +69,39 @@ index 2043b5a4..eadaa52e 100644
}
async set(name, val) {
await this._initializedPromise;
@@ -13365,7 +13365,7 @@ document.webL10n = function (window, document) {
function getL10nData(key, args, fallback) {
var data = gL10nData[key];
if (!data) {
- console.warn('#' + key + ' is undefined.');
+ // console.warn('#' + key + ' is undefined.');
if (!fallback) {
return null;
@@ -11597,7 +11597,7 @@ const PDFViewerApplication = {
title = url;
}
@@ -13801,6 +13801,9 @@ function renderProgress(index, total, l10n) {
}
- this.setTitle(title);
+ // this.setTitle(title);
},
setTitle(title = this._title) {
this._title = title;
@@ -12049,7 +12049,7 @@ const PDFViewerApplication = {
this.metadata = metadata;
this._contentDispositionFilename ??= contentDispositionFilename;
this._contentLength ??= contentLength;
- console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${version || "?"} [${build || "?"}])`);
+ // console.log(`PDF ${pdfDocument.fingerprints[0]} [${info.PDFFormatVersion} ` + `${(info.Producer || "-").trim()} / ${(info.Creator || "-").trim()}] ` + `(PDF.js: ${version || "?"} [${build || "?"}])`);
let pdfTitle = info.Title;
const metadataTitle = metadata?.get("dc:title");
if (metadataTitle) {
@@ -13630,11 +13630,11 @@ class GenericScripting {
const GenericCom = {};
class GenericPreferences extends BasePreferences {
async _writeToStorage(prefObj) {
- localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
+ // localStorage.setItem("pdfjs.preferences", JSON.stringify(prefObj));
}
async _readFromStorage(prefObj) {
return {
- prefs: JSON.parse(localStorage.getItem("pdfjs.preferences"))
+ prefs: undefined // JSON.parse(localStorage.getItem("pdfjs.preferences"))
};
}
}
@@ -13884,6 +13884,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 @@ -101,7 +111,7 @@ index 2043b5a4..eadaa52e 100644
window.print();
event.preventDefault();
event.stopImmediatePropagation();
@@ -14079,9 +14082,10 @@ function webViewerLoad() {
@@ -14077,9 +14080,10 @@ function webViewerLoad() {
}
});
try {
Expand All @@ -113,4 +123,10 @@ index 2043b5a4..eadaa52e 100644
+ // console.error(`webviewerloaded: ${ex}`);
document.dispatchEvent(event);
}
_app.PDFViewerApplication.run(config);
PDFViewerApplication.run(config);
@@ -14096,4 +14100,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 };

-//# sourceMappingURL=viewer.mjs.map
\ No newline at end of file
14 changes: 7 additions & 7 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 @@ -2576,7 +2576,7 @@
"latex-utensils": "6.1.0",
"mathjax-full": "3.2.2",
"micromatch": "4.0.5",
"pdfjs-dist": "3.11.174",
"pdfjs-dist": "^4.0.189",
"tmp": "0.2.1",
"workerpool": "6.4.0",
"ws": "8.11.0"
Expand Down
4 changes: 2 additions & 2 deletions resources/snippetview/pdfrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ window.addEventListener('message', async (event) => {

// https://github.com/microsoft/vscode/issues/87282#issuecomment-919464403
async function createPdfWorker() {
const result = await fetch(pdfjsDistUri + '/build/pdf.worker.js');
const result = await fetch(pdfjsDistUri + '/build/pdf.worker.mjs');
const blob = await result.blob();
const blobUrl = URL.createObjectURL(blob);
pdfjsLib.GlobalWorkerOptions.workerPort = new Worker(blobUrl);
pdfjsLib.GlobalWorkerOptions.workerPort = new Worker(blobUrl, { type: 'module' });
}

async function renderPdfFile(url, opts) {
Expand Down
2 changes: 1 addition & 1 deletion resources/snippetview/snippetview.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script>
var pdfjsDistUri = '%VSCODE_PDFJS_DIST%';
</script>
<script src="%VSCODE_PDFJS_DIST%/build/pdf.js" defer></script>
<script src="%VSCODE_PDFJS_DIST%/build/pdf.mjs" type="module"></script>
<script src="%VSCODE_RES%/snippetview/pdfrenderer.js" defer></script>
<link rel="stylesheet" href="%VSCODE_RES%/snippetview/snippetview.css">
</head>
Expand Down
1 change: 1 addition & 0 deletions src/components/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class Server {
contentType = 'text/html'
break
}
case '.mjs':
case '.js': {
contentType = 'text/javascript'
break
Expand Down
6 changes: 3 additions & 3 deletions viewer/latexworkshop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
}

private async setupAppOptions() {
const workerPort = new Worker('build/pdf.worker.js')
const workerPort = new Worker('build/pdf.worker.mjs', { type: 'module' })
const params = await this.fetchParams()
document.addEventListener('webviewerloaded', () => {
const color = this.isPrefersColorSchemeDark(params.codeColorTheme) ? params.color.dark : params.color.light
Expand All @@ -224,7 +224,7 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
sidebarViewOnLoad: 0,
standardFontDataUrl: '/standard_fonts/',
workerPort,
workerSrc: 'build/pdf.worker.js',
workerSrc: 'build/pdf.worker.mjs',
forcePageColors: true,
...color
}
Expand Down Expand Up @@ -772,4 +772,4 @@ class LateXWorkshopPdfViewer implements ILatexWorkshopPdfViewer {
const extension = new LateXWorkshopPdfViewer()
await extension.waitSetupAppOptionsFinished()
// @ts-expect-error
await import('../../viewer/viewer.js')
await import('../../viewer/viewer.mjs')
Loading

0 comments on commit 2d1e7ae

Please sign in to comment.