From 80d27c830e3e537754d8f6ac911b15e23f0be36b Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 1 Oct 2022 23:12:24 +0800 Subject: [PATCH] :arrow_up: fix https://github.com/siyuan-note/siyuan/issues/6035 --- app/src/asset/pdf/app.js | 47 +++++---- app/src/asset/pdf/download_manager.js | 118 ---------------------- app/src/asset/pdf/genericcom.js | 6 +- app/src/asset/pdf/pdf_viewer.component.js | 79 --------------- app/src/asset/pdf/viewer.js | 1 - 5 files changed, 29 insertions(+), 222 deletions(-) delete mode 100644 app/src/asset/pdf/download_manager.js delete mode 100644 app/src/asset/pdf/pdf_viewer.component.js diff --git a/app/src/asset/pdf/app.js b/app/src/asset/pdf/app.js index e6a6899a9..6d82d4b2d 100644 --- a/app/src/asset/pdf/app.js +++ b/app/src/asset/pdf/app.js @@ -328,12 +328,13 @@ class PDFViewerApplication { case 'shadow': case 'hover': viewerContainer.classList.add(`textLayer-${params.get('textlayer')}`) - try { - await loadPDFBug(this) - this._PDFBug.loadCSS() - } catch (ex) { - console.error(`_parseHashParameters: "${ex.message}".`) - } + // NOTE + // try { + // await loadPDFBug(this) + // this._PDFBug.loadCSS() + // } catch (ex) { + // console.error(`_parseHashParameters: "${ex.message}".`) + // } break } } @@ -342,12 +343,13 @@ class PDFViewerApplication { AppOptions.set('fontExtraProperties', true) const enabled = params.get('pdfbug').split(',') - try { - await loadPDFBug(this) - this._PDFBug.init({OPS}, mainContainer, enabled) - } catch (ex) { - console.error(`_parseHashParameters: "${ex.message}".`) - } + // NOTE + // try { + // await loadPDFBug(this) + // this._PDFBug.init({OPS}, mainContainer, enabled) + // } catch (ex) { + // console.error(`_parseHashParameters: "${ex.message}".`) + // } } // It is not possible to change locale for the (various) extension builds. if ( @@ -2126,21 +2128,22 @@ async function loadFakeWorker () { if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) { // NOTE - window.pdfjsWorker = await import(`${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=2.14.102`) + window.pdfjsWorker = await import(`${Constants.PROTYLE_CDN}/js/pdf/pdf.worker.js?v=3.0.150`) return } await loadScript(PDFWorker.workerSrc) } -async function loadPDFBug (self) { - const {debuggerScriptPath} = self.appConfig - const {PDFBug} = - typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION') - ? await import(debuggerScriptPath) // eslint-disable-line no-unsanitized/method - : await __non_webpack_import__(debuggerScriptPath) // eslint-disable-line no-undef - - self._PDFBug = PDFBug -} +// NOTE +// async function loadPDFBug (self) { +// const {debuggerScriptPath} = self.appConfig +// const {PDFBug} = +// typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION') +// ? await import(debuggerScriptPath) // eslint-disable-line no-unsanitized/method +// : await __non_webpack_import__(debuggerScriptPath) // eslint-disable-line no-undef +// +// self._PDFBug = PDFBug +// } function reportPageStatsPDFBug ({pageNumber}) { if (!globalThis.Stats?.enabled) { diff --git a/app/src/asset/pdf/download_manager.js b/app/src/asset/pdf/download_manager.js deleted file mode 100644 index d0feccd98..000000000 --- a/app/src/asset/pdf/download_manager.js +++ /dev/null @@ -1,118 +0,0 @@ -/* Copyright 2013 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ - -import { createValidAbsoluteUrl, isPdfFile } from "./pdfjs"; - -if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("CHROME || GENERIC")) { - throw new Error( - 'Module "pdfjs-web/download_manager" shall not be used ' + - "outside CHROME and GENERIC builds." - ); -} - -function download(blobUrl, filename) { - const a = document.createElement("a"); - if (!a.click) { - throw new Error('DownloadManager: "a.click()" is not supported.'); - } - a.href = blobUrl; - a.target = "_parent"; - // Use a.download if available. This increases the likelihood that - // the file is downloaded instead of opened by another PDF plugin. - if ("download" in a) { - a.download = filename; - } - // must be in the document for recent Firefox versions, - // otherwise .click() is ignored. - (document.body || document.documentElement).append(a); - a.click(); - a.remove(); -} - -/** - * @implements {IDownloadManager} - */ -class DownloadManager { - constructor() { - this._openBlobUrls = new WeakMap(); - } - - downloadUrl(url, filename) { - if (!createValidAbsoluteUrl(url, "http://example.com")) { - console.error(`downloadUrl - not a valid URL: ${url}`); - return; // restricted/invalid URL - } - download(url + "#pdfjs.action=download", filename); - } - - downloadData(data, filename, contentType) { - const blobUrl = URL.createObjectURL( - new Blob([data], { type: contentType }) - ); - download(blobUrl, filename); - } - - /** - * @returns {boolean} Indicating if the data was opened. - */ - openOrDownloadData(element, data, filename) { - const isPdfData = isPdfFile(filename); - const contentType = isPdfData ? "application/pdf" : ""; - - if (isPdfData) { - let blobUrl = this._openBlobUrls.get(element); - if (!blobUrl) { - blobUrl = URL.createObjectURL(new Blob([data], { type: contentType })); - this._openBlobUrls.set(element, blobUrl); - } - let viewerUrl; - if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) { - // The current URL is the viewer, let's use it and append the file. - viewerUrl = "?file=" + encodeURIComponent(blobUrl + "#" + filename); - } else if (PDFJSDev.test("CHROME")) { - // In the Chrome extension, the URL is rewritten using the history API - // in viewer.js, so an absolute URL must be generated. - viewerUrl = - // eslint-disable-next-line no-undef - chrome.runtime.getURL("/content/web/viewer.html") + - "?file=" + - encodeURIComponent(blobUrl + "#" + filename); - } - - try { - window.open(viewerUrl); - return true; - } catch (ex) { - console.error(`openOrDownloadData: ${ex}`); - // Release the `blobUrl`, since opening it failed, and fallback to - // downloading the PDF file. - URL.revokeObjectURL(blobUrl); - this._openBlobUrls.delete(element); - } - } - - this.downloadData(data, filename, contentType); - return false; - } - - download(blob, url, filename) { - const blobUrl = URL.createObjectURL(blob); - download(blobUrl, filename); - } -} - -export { DownloadManager }; diff --git a/app/src/asset/pdf/genericcom.js b/app/src/asset/pdf/genericcom.js index c45e1e046..d43918804 100644 --- a/app/src/asset/pdf/genericcom.js +++ b/app/src/asset/pdf/genericcom.js @@ -14,7 +14,8 @@ */ import { BasePreferences } from "./preferences.js"; -import { DownloadManager } from "./download_manager.js"; +// NOTE +// import { DownloadManager } from "./download_manager.js"; import { GenericScripting } from "./generic_scripting.js"; import { shadow } from './pdfjs' @@ -72,7 +73,8 @@ class GenericExternalServices { } static createDownloadManager(options) { - return new DownloadManager(); + // NOTE + // return new DownloadManager(); } static createPreferences() { diff --git a/app/src/asset/pdf/pdf_viewer.component.js b/app/src/asset/pdf/pdf_viewer.component.js deleted file mode 100644 index 73a792548..000000000 --- a/app/src/asset/pdf/pdf_viewer.component.js +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright 2014 Mozilla Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { - DefaultAnnotationLayerFactory, - DefaultStructTreeLayerFactory, - DefaultTextLayerFactory, - DefaultXfaLayerFactory, -} from "./default_factory.js"; -import { - LinkTarget, - PDFLinkService, - SimpleLinkService, -} from "./pdf_link_service.js"; -import { - parseQueryString, - ProgressBar, - RenderingStates, - ScrollMode, - SpreadMode, -} from "./ui_utils.js"; -import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; -import { DownloadManager } from "./download_manager.js"; -import { EventBus } from "./event_utils.js"; -import { NullL10n } from "./l10n_utils.js"; -import { PDFFindController } from "./pdf_find_controller.js"; -import { PDFHistory } from "./pdf_history.js"; -import { PDFPageView } from "./pdf_page_view.js"; -import { PDFScriptingManager } from "./pdf_scripting_manager.js"; -import { PDFSinglePageViewer } from "./pdf_single_page_viewer.js"; -import { PDFViewer } from "./pdf_viewer.js"; -import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; -import { TextLayerBuilder } from "./text_layer_builder.js"; -import { XfaLayerBuilder } from "./xfa_layer_builder.js"; - -// eslint-disable-next-line no-unused-vars -const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION"); -// eslint-disable-next-line no-unused-vars -const pdfjsBuild = PDFJSDev.eval("BUNDLE_BUILD"); - -export { - AnnotationLayerBuilder, - DefaultAnnotationLayerFactory, - DefaultStructTreeLayerFactory, - DefaultTextLayerFactory, - DefaultXfaLayerFactory, - DownloadManager, - EventBus, - LinkTarget, - NullL10n, - parseQueryString, - PDFFindController, - PDFHistory, - PDFLinkService, - PDFPageView, - PDFScriptingManager, - PDFSinglePageViewer, - PDFViewer, - ProgressBar, - RenderingStates, - ScrollMode, - SimpleLinkService, - SpreadMode, - StructTreeLayerBuilder, - TextLayerBuilder, - XfaLayerBuilder, -}; diff --git a/app/src/asset/pdf/viewer.js b/app/src/asset/pdf/viewer.js index b070ab2aa..df5920fd8 100644 --- a/app/src/asset/pdf/viewer.js +++ b/app/src/asset/pdf/viewer.js @@ -266,6 +266,5 @@ document.blockUnblockOnload?.(true) // NOTE export { - PDFViewerApplication, webViewerLoad }