From 69462e5e146d3102a24e074896471639ab1df5d6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Aug 2022 15:41:30 +0200 Subject: [PATCH 1/2] Export additional constants in the viewer components In addition to the existing `LinkTarget` constant, used by the `PDFLinkService`-constructor, this patch exports the following constants in the viewer components: - `ScrollMode` and `SpreadMode`, since the `BaseViewer` has getters/setters which work with those constants. - `RenderingStates`, since that one may be helpful when using `PDFPageView` directly. --- web/pdf_viewer.component.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index 51d01d05e..e4ca1417e 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -24,7 +24,13 @@ import { PDFLinkService, SimpleLinkService, } from "./pdf_link_service.js"; -import { parseQueryString, ProgressBar } from "./ui_utils.js"; +import { + parseQueryString, + ProgressBar, + RenderingStates, + ScrollMode, + SpreadMode, +} from "./ui_utils.js"; import { PDFSinglePageViewer, PDFViewer } from "./pdf_viewer.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { DownloadManager } from "./download_manager.js"; @@ -64,7 +70,10 @@ export { PDFSinglePageViewer, PDFViewer, ProgressBar, + RenderingStates, + ScrollMode, SimpleLinkService, + SpreadMode, StructTreeLayerBuilder, TextLayerBuilder, XfaLayerBuilder, From b8bb1d67d4a8af8a98cd13c82045428b8326dee2 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 11 Aug 2022 15:47:30 +0200 Subject: [PATCH 2/2] [GENERIC viewer] Export some viewer constants in the default viewer (issue 15294) This exports the same constants as the viewer components, but in the default viewer. To avoid bloating the global-scope the constants are added to a new `PDFViewerApplicationConstants` object[1], which also allows us to skip this in builds where it's not actually needed (e.g. the Firefox *built-in* PDF Viewer). *Please note:* I'm not completely sold on this idea, and thus wouldn't mind the patch being rejected, since we probably don't want to export every single viewer constant this way. (And it may seem a bit arbitrary, to users, why some constants are exported and others are not.) --- [1] Somewhat similar to the existing `PDFViewerApplicationOptions` structure. --- web/viewer.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/viewer.js b/web/viewer.js index a79b6fa39..c08208544 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -13,7 +13,9 @@ * limitations under the License. */ +import { RenderingStates, ScrollMode, SpreadMode } from "./ui_utils.js"; import { AppOptions } from "./app_options.js"; +import { LinkTarget } from "./pdf_link_service.js"; import { PDFViewerApplication } from "./app.js"; /* eslint-disable-next-line no-unused-vars */ @@ -23,7 +25,13 @@ const pdfjsVersion = const pdfjsBuild = typeof PDFJSDev !== "undefined" ? PDFJSDev.eval("BUNDLE_BUILD") : void 0; +const AppConstants = + typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC") + ? { LinkTarget, RenderingStates, ScrollMode, SpreadMode } + : null; + window.PDFViewerApplication = PDFViewerApplication; +window.PDFViewerApplicationConstants = AppConstants; window.PDFViewerApplicationOptions = AppOptions; if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) { @@ -270,4 +278,8 @@ if ( document.addEventListener("DOMContentLoaded", webViewerLoad, true); } -export { PDFViewerApplication, AppOptions as PDFViewerApplicationOptions }; +export { + PDFViewerApplication, + AppConstants as PDFViewerApplicationConstants, + AppOptions as PDFViewerApplicationOptions, +};