Re-factor PDFPrintServiceFactory
to use import maps
This is very old code, which can (ever so slightly) be simplified now that import maps are available.
This commit is contained in:
parent
60fd9d583d
commit
898172e9d2
17
web/app.js
17
web/app.js
@ -70,6 +70,7 @@ import { PDFHistory } from "./pdf_history.js";
|
||||
import { PDFLayerViewer } from "web-pdf_layer_viewer";
|
||||
import { PDFOutlineViewer } from "web-pdf_outline_viewer";
|
||||
import { PDFPresentationMode } from "web-pdf_presentation_mode";
|
||||
import { PDFPrintServiceFactory } from "web-print_service";
|
||||
import { PDFRenderingQueue } from "./pdf_rendering_queue.js";
|
||||
import { PDFScriptingManager } from "./pdf_scripting_manager.js";
|
||||
import { PDFSidebar } from "web-pdf_sidebar";
|
||||
@ -731,7 +732,7 @@ const PDFViewerApplication = {
|
||||
},
|
||||
|
||||
get supportsPrinting() {
|
||||
return PDFPrintServiceFactory.instance.supportsPrinting;
|
||||
return PDFPrintServiceFactory.supportsPrinting;
|
||||
},
|
||||
|
||||
get supportsFullscreen() {
|
||||
@ -1786,7 +1787,7 @@ const PDFViewerApplication = {
|
||||
const optionalContentConfigPromise =
|
||||
this.pdfViewer.optionalContentConfigPromise;
|
||||
|
||||
const printService = PDFPrintServiceFactory.instance.createPrintService(
|
||||
const printService = PDFPrintServiceFactory.createPrintService(
|
||||
this.pdfDocument,
|
||||
pagesOverview,
|
||||
printContainer,
|
||||
@ -3234,14 +3235,4 @@ function webViewerReportTelemetry({ details }) {
|
||||
PDFViewerApplication.externalServices.reportTelemetry(details);
|
||||
}
|
||||
|
||||
/* Abstract factory for the print service. */
|
||||
const PDFPrintServiceFactory = {
|
||||
instance: {
|
||||
supportsPrinting: false,
|
||||
createPrintService() {
|
||||
throw new Error("Not implemented: createPrintService");
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export { PDFPrintServiceFactory, PDFViewerApplication };
|
||||
export { PDFViewerApplication };
|
||||
|
@ -20,7 +20,6 @@ import {
|
||||
shadow,
|
||||
} from "pdfjs-lib";
|
||||
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
||||
import { PDFPrintServiceFactory } from "./app.js";
|
||||
|
||||
// Creates a placeholder with div and canvas with right size for the page.
|
||||
function composePage(
|
||||
@ -194,15 +193,16 @@ class FirefoxPrintService {
|
||||
}
|
||||
}
|
||||
|
||||
PDFPrintServiceFactory.instance = {
|
||||
get supportsPrinting() {
|
||||
/**
|
||||
* @implements {IPDFPrintServiceFactory}
|
||||
*/
|
||||
class PDFPrintServiceFactory {
|
||||
static get supportsPrinting() {
|
||||
const canvas = document.createElement("canvas");
|
||||
const value = "mozPrintCallback" in canvas;
|
||||
return shadow(this, "supportsPrinting", "mozPrintCallback" in canvas);
|
||||
}
|
||||
|
||||
return shadow(this, "supportsPrinting", value);
|
||||
},
|
||||
|
||||
createPrintService(
|
||||
static createPrintService(
|
||||
pdfDocument,
|
||||
pagesOverview,
|
||||
printContainer,
|
||||
@ -218,7 +218,7 @@ PDFPrintServiceFactory.instance = {
|
||||
optionalContentConfigPromise,
|
||||
printAnnotationStoragePromise
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { FirefoxPrintService };
|
||||
export { PDFPrintServiceFactory };
|
||||
|
@ -217,4 +217,23 @@ class IL10n {
|
||||
resume() {}
|
||||
}
|
||||
|
||||
export { IDownloadManager, IL10n, IPDFLinkService, IRenderableView };
|
||||
/**
|
||||
* @interface
|
||||
*/
|
||||
class IPDFPrintServiceFactory {
|
||||
static get supportsPrinting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
static createPrintService() {
|
||||
throw new Error("Not implemented: createPrintService");
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
IDownloadManager,
|
||||
IL10n,
|
||||
IPDFLinkService,
|
||||
IPDFPrintServiceFactory,
|
||||
IRenderableView,
|
||||
};
|
||||
|
@ -13,9 +13,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AnnotationMode, PixelsPerInch } from "pdfjs-lib";
|
||||
import { PDFPrintServiceFactory, PDFViewerApplication } from "./app.js";
|
||||
import { AnnotationMode, PixelsPerInch, shadow } from "pdfjs-lib";
|
||||
import { getXfaHtmlForPrinting } from "./print_utils.js";
|
||||
import { PDFViewerApplication } from "./app.js";
|
||||
|
||||
let activeService = null;
|
||||
let dialog = null;
|
||||
@ -355,10 +355,15 @@ function ensureOverlay() {
|
||||
return overlayPromise;
|
||||
}
|
||||
|
||||
PDFPrintServiceFactory.instance = {
|
||||
supportsPrinting: true,
|
||||
/**
|
||||
* @implements {IPDFPrintServiceFactory}
|
||||
*/
|
||||
class PDFPrintServiceFactory {
|
||||
static get supportsPrinting() {
|
||||
return shadow(this, "supportsPrinting", true);
|
||||
}
|
||||
|
||||
createPrintService(
|
||||
static createPrintService(
|
||||
pdfDocument,
|
||||
pagesOverview,
|
||||
printContainer,
|
||||
@ -378,7 +383,7 @@ PDFPrintServiceFactory.instance = {
|
||||
printAnnotationStoragePromise
|
||||
);
|
||||
return activeService;
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { PDFPrintService };
|
||||
export { PDFPrintServiceFactory };
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
import "web-com";
|
||||
import "web-print_service";
|
||||
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
|
||||
import { AppOptions } from "./app_options.js";
|
||||
import { LinkTarget } from "./pdf_link_service.js";
|
||||
|
@ -14,7 +14,6 @@
|
||||
*/
|
||||
|
||||
import "web-com";
|
||||
import "web-print_service";
|
||||
import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js";
|
||||
import { AppOptions } from "./app_options.js";
|
||||
import { LinkTarget } from "./pdf_link_service.js";
|
||||
|
Loading…
Reference in New Issue
Block a user