mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-18 18:10:43 +08:00
This commit is contained in:
parent
45b26e1f3f
commit
80d27c830e
@ -328,12 +328,13 @@ class PDFViewerApplication {
|
|||||||
case 'shadow':
|
case 'shadow':
|
||||||
case 'hover':
|
case 'hover':
|
||||||
viewerContainer.classList.add(`textLayer-${params.get('textlayer')}`)
|
viewerContainer.classList.add(`textLayer-${params.get('textlayer')}`)
|
||||||
try {
|
// NOTE
|
||||||
await loadPDFBug(this)
|
// try {
|
||||||
this._PDFBug.loadCSS()
|
// await loadPDFBug(this)
|
||||||
} catch (ex) {
|
// this._PDFBug.loadCSS()
|
||||||
console.error(`_parseHashParameters: "${ex.message}".`)
|
// } catch (ex) {
|
||||||
}
|
// console.error(`_parseHashParameters: "${ex.message}".`)
|
||||||
|
// }
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,12 +343,13 @@ class PDFViewerApplication {
|
|||||||
AppOptions.set('fontExtraProperties', true)
|
AppOptions.set('fontExtraProperties', true)
|
||||||
|
|
||||||
const enabled = params.get('pdfbug').split(',')
|
const enabled = params.get('pdfbug').split(',')
|
||||||
try {
|
// NOTE
|
||||||
await loadPDFBug(this)
|
// try {
|
||||||
this._PDFBug.init({OPS}, mainContainer, enabled)
|
// await loadPDFBug(this)
|
||||||
} catch (ex) {
|
// this._PDFBug.init({OPS}, mainContainer, enabled)
|
||||||
console.error(`_parseHashParameters: "${ex.message}".`)
|
// } catch (ex) {
|
||||||
}
|
// console.error(`_parseHashParameters: "${ex.message}".`)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
// It is not possible to change locale for the (various) extension builds.
|
// It is not possible to change locale for the (various) extension builds.
|
||||||
if (
|
if (
|
||||||
@ -2126,21 +2128,22 @@ async function loadFakeWorker () {
|
|||||||
|
|
||||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||||
// NOTE
|
// 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
|
return
|
||||||
}
|
}
|
||||||
await loadScript(PDFWorker.workerSrc)
|
await loadScript(PDFWorker.workerSrc)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadPDFBug (self) {
|
// NOTE
|
||||||
const {debuggerScriptPath} = self.appConfig
|
// async function loadPDFBug (self) {
|
||||||
const {PDFBug} =
|
// const {debuggerScriptPath} = self.appConfig
|
||||||
typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')
|
// const {PDFBug} =
|
||||||
? await import(debuggerScriptPath) // eslint-disable-line no-unsanitized/method
|
// typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')
|
||||||
: await __non_webpack_import__(debuggerScriptPath) // eslint-disable-line no-undef
|
// ? await import(debuggerScriptPath) // eslint-disable-line no-unsanitized/method
|
||||||
|
// : await __non_webpack_import__(debuggerScriptPath) // eslint-disable-line no-undef
|
||||||
self._PDFBug = PDFBug
|
//
|
||||||
}
|
// self._PDFBug = PDFBug
|
||||||
|
// }
|
||||||
|
|
||||||
function reportPageStatsPDFBug ({pageNumber}) {
|
function reportPageStatsPDFBug ({pageNumber}) {
|
||||||
if (!globalThis.Stats?.enabled) {
|
if (!globalThis.Stats?.enabled) {
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
// <a> 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 };
|
|
@ -14,7 +14,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { BasePreferences } from "./preferences.js";
|
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 { GenericScripting } from "./generic_scripting.js";
|
||||||
import { shadow } from './pdfjs'
|
import { shadow } from './pdfjs'
|
||||||
|
|
||||||
@ -72,7 +73,8 @@ class GenericExternalServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static createDownloadManager(options) {
|
static createDownloadManager(options) {
|
||||||
return new DownloadManager();
|
// NOTE
|
||||||
|
// return new DownloadManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
static createPreferences() {
|
static createPreferences() {
|
||||||
|
@ -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,
|
|
||||||
};
|
|
@ -266,6 +266,5 @@ document.blockUnblockOnload?.(true)
|
|||||||
|
|
||||||
// NOTE
|
// NOTE
|
||||||
export {
|
export {
|
||||||
PDFViewerApplication,
|
|
||||||
webViewerLoad
|
webViewerLoad
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user