From e0dba504d261443dc6e17e5e92f3f0261d454e3d Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 14 Dec 2021 23:59:17 +0100 Subject: [PATCH 1/2] Fix broken/missing JSDocs and `typedef`s, to allow updating TypeScript to the latest version (issue 14342) This patch circumvents the issues seen when trying to update TypeScript to version `4.5`, by "simply" fixing the broken/missing JSDocs and `typedef`s such that `gulp typestest` now passes. As always, given that I don't really know anything about TypeScript, I cannot tell if this is a "correct" and/or proper way of doing things; we'll need TypeScript users to help out with testing! *Please note:* I'm sorry about the size of this patch, but given how intertwined all of this unfortunately is it just didn't seem easy to split this into smaller parts. However, one good thing about this TypeScript update is that it helped uncover a number of pre-existing bugs in our JSDocs comments. --- package-lock.json | 36 ++++++----------- package.json | 2 +- src/display/annotation_layer.js | 16 +++++--- src/display/api.js | 4 +- src/display/xfa_layer.js | 24 ++++++++++-- test/driver.js | 10 ++--- web/annotation_layer_builder.js | 18 ++++++--- web/base_viewer.js | 33 +++++++++++++--- web/download_manager.js | 5 +++ web/genericl10n.js | 5 +++ web/interfaces.js | 66 ++++++++++++++++++++++++++++---- web/pdf_find_controller.js | 4 ++ web/pdf_history.js | 3 ++ web/pdf_link_service.js | 1 + web/pdf_page_view.js | 15 ++++++++ web/pdf_rendering_queue.js | 5 +++ web/pdf_scripting_manager.js | 2 + web/pdf_thumbnail_view.js | 6 +++ web/pdf_thumbnail_viewer.js | 12 +++++- web/struct_tree_layer_builder.js | 5 ++- web/text_highlighter.js | 4 ++ web/text_layer_builder.js | 4 ++ web/xfa_layer_builder.js | 26 ++++++++----- 23 files changed, 232 insertions(+), 74 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1b2a2a45a..59a6d0da4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,7 +59,7 @@ "terser": "^5.10.0", "through2": "^4.0.2", "ttest": "^3.0.0", - "typescript": "~4.4.4", + "typescript": "^4.5.4", "typogr": "^0.6.8", "vinyl": "^2.2.1", "vinyl-fs": "^3.0.3", @@ -12389,7 +12389,6 @@ }, "node_modules/npm/node_modules/lodash._baseindexof": { "version": "3.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -12405,19 +12404,16 @@ }, "node_modules/npm/node_modules/lodash._bindcallback": { "version": "3.0.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._cacheindexof": { "version": "3.0.2", - "extraneous": true, "inBundle": true, "license": "MIT" }, "node_modules/npm/node_modules/lodash._createcache": { "version": "3.1.2", - "extraneous": true, "inBundle": true, "license": "MIT", "dependencies": { @@ -12432,7 +12428,6 @@ }, "node_modules/npm/node_modules/lodash._getnative": { "version": "3.9.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -12450,7 +12445,6 @@ }, "node_modules/npm/node_modules/lodash.restparam": { "version": "3.6.1", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -17845,9 +17839,9 @@ } }, "node_modules/typescript": { - "version": "4.4.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", - "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", + "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -28465,8 +28459,7 @@ }, "lodash._baseindexof": { "version": "3.1.0", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._baseuniq": { "version": "4.6.0", @@ -28479,18 +28472,15 @@ }, "lodash._bindcallback": { "version": "3.0.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._cacheindexof": { "version": "3.0.2", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._createcache": { "version": "3.1.2", "bundled": true, - "extraneous": true, "requires": { "lodash._getnative": "^3.0.0" } @@ -28502,8 +28492,7 @@ }, "lodash._getnative": { "version": "3.9.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash._root": { "version": "3.0.1", @@ -28517,8 +28506,7 @@ }, "lodash.restparam": { "version": "3.6.1", - "bundled": true, - "extraneous": true + "bundled": true }, "lodash.union": { "version": "4.6.0", @@ -32730,9 +32718,9 @@ } }, "typescript": { - "version": "4.4.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz", - "integrity": "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==", + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.4.tgz", + "integrity": "sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg==", "dev": true }, "typogr": { diff --git a/package.json b/package.json index 5beb16d6f..61b93e973 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "terser": "^5.10.0", "through2": "^4.0.2", "ttest": "^3.0.0", - "typescript": "~4.4.4", + "typescript": "^4.5.4", "typogr": "^0.6.8", "vinyl": "^2.2.1", "vinyl-fs": "^3.0.3", diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index c52481a21..9e9cfbcaa 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -13,6 +13,11 @@ * limitations under the License. */ +/** @typedef {import("./api").PDFPageProxy} PDFPageProxy */ +/** @typedef {import("./display_utils").PageViewport} PageViewport */ +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ +/** @typedef {import("../../web/interfaces").IPDFLinkService} IPDFLinkService */ + import { AnnotationBorderStyleType, AnnotationType, @@ -39,10 +44,10 @@ const GetElementsByNameSet = new WeakSet(); * @typedef {Object} AnnotationElementParameters * @property {Object} data * @property {HTMLDivElement} layer - * @property {PDFPage} page + * @property {PDFPageProxy} page * @property {PageViewport} viewport * @property {IPDFLinkService} linkService - * @property {DownloadManager} downloadManager + * @property {IDownloadManager} downloadManager * @property {AnnotationStorage} [annotationStorage] * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. @@ -1700,7 +1705,7 @@ class PopupElement { (!this.contentsObj?.str || this.contentsObj.str === this.richText.str) ) { XfaLayer.render({ - xfa: this.richText.html, + xfaHtml: this.richText.html, intent: "richText", div: popup, }); @@ -2302,15 +2307,16 @@ class FileAttachmentAnnotationElement extends AnnotationElement { * @property {PageViewport} viewport * @property {HTMLDivElement} div * @property {Array} annotations - * @property {PDFPage} page + * @property {PDFPageProxy} page * @property {IPDFLinkService} linkService - * @property {DownloadManager} downloadManager + * @property {IDownloadManager} downloadManager * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. * @property {boolean} renderForms * @property {boolean} [enableScripting] - Enable embedded script execution. * @property {boolean} [hasJSActions] - Some fields have JS actions. * The default value is `false`. + * @property {Map} [annotationCanvasMap] */ class AnnotationLayer { diff --git a/src/display/api.js b/src/display/api.js index 416e8b0ca..beb6ba9f2 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -1168,8 +1168,8 @@ class PDFDocumentProxy { * created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`, * the configuration will be fetched automatically with the default visibility * states set. - * @property {Map} [annotationCanvasMap] - Map some annotation - * ids with canvases used to render them. + * @property {Map} [annotationCanvasMap] - Map some + * annotation ids with canvases used to render them. */ /** diff --git a/src/display/xfa_layer.js b/src/display/xfa_layer.js index a1417ebf8..b34ee33e0 100644 --- a/src/display/xfa_layer.js +++ b/src/display/xfa_layer.js @@ -13,9 +13,22 @@ * limitations under the License. */ +/** @typedef {import("./display_utils").PageViewport} PageViewport */ +/** @typedef {import("../../web/interfaces").IPDFLinkService} IPDFLinkService */ + import { warn } from "../shared/util.js"; import { XfaText } from "./xfa_text.js"; +/** + * @typedef {Object} XfaLayerParameters + * @property {PageViewport} viewport + * @property {HTMLDivElement} div + * @property {Object} xfaHtml + * @property {AnnotationStorage} [annotationStorage] + * @property {IPDFLinkService} linkService + * @property {string} [intent] - (default value is 'display'). + */ + class XfaLayer { static setupStorage(html, id, element, storage, intent) { const storedData = storage.getValue(id, { value: null }); @@ -143,10 +156,15 @@ class XfaLayer { } } + /** + * Render the XFA layer. + * + * @param {XfaLayerParameters} parameters + */ static render(parameters) { const storage = parameters.annotationStorage; const linkService = parameters.linkService; - const root = parameters.xfa; + const root = parameters.xfaHtml; const intent = parameters.intent || "display"; const rootHtml = document.createElement(root.name); if (root.attributes) { @@ -252,11 +270,9 @@ class XfaLayer { } /** - * Update the xfa layer. + * Update the XFA layer. * - * @public * @param {XfaLayerParameters} parameters - * @memberof XfaLayer */ static update(parameters) { const transform = `matrix(${parameters.viewport.transform.join(",")})`; diff --git a/test/driver.js b/test/driver.js index 5d5ebb628..52d933889 100644 --- a/test/driver.js +++ b/test/driver.js @@ -272,7 +272,7 @@ class Rasterize { static async xfaLayer( ctx, viewport, - xfa, + xfaHtml, fontRules, annotationStorage, isPrint @@ -285,9 +285,9 @@ class Rasterize { // Rendering XFA layer as HTML. XfaLayer.render({ - xfa, - div, viewport: viewport.clone({ dontFlip: true }), + div, + xfaHtml, annotationStorage, linkService: new SimpleLinkService(), intent: isPrint ? "print" : "display", @@ -688,11 +688,11 @@ class Driver { initPromise = page.getAnnotations({ intent: "display" }); annotationCanvasMap = new Map(); } else { - initPromise = page.getXfa().then(function (xfa) { + initPromise = page.getXfa().then(function (xfaHtml) { return Rasterize.xfaLayer( annotationLayerContext, viewport, - xfa, + xfaHtml, task.fontRules, task.pdfDoc.annotationStorage, task.renderPrint diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 3a55a87ef..de0f677b4 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -13,8 +13,14 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ +/** @typedef {import("./interfaces").IL10n} IL10n */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ import { AnnotationLayer } from "pdfjs-lib"; import { NullL10n } from "./l10n_utils.js"; @@ -23,20 +29,20 @@ import { SimpleLinkService } from "./pdf_link_service.js"; /** * @typedef {Object} AnnotationLayerBuilderOptions * @property {HTMLDivElement} pageDiv - * @property {PDFPage} pdfPage + * @property {PDFPageProxy} pdfPage * @property {AnnotationStorage} [annotationStorage] * @property {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. * @property {boolean} renderForms * @property {IPDFLinkService} linkService - * @property {DownloadManager} downloadManager + * @property {IDownloadManager} downloadManager * @property {IL10n} l10n - Localization service. * @property {boolean} [enableScripting] * @property {Promise} [hasJSActionsPromise] * @property {Promise> | null>} * [fieldObjectsPromise] * @property {Object} [mouseState] - * @property {Map} [annotationCanvasMap] + * @property {Map} [annotationCanvasMap] */ class AnnotationLayerBuilder { @@ -146,7 +152,7 @@ class AnnotationLayerBuilder { class DefaultAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] * @param {string} [imageResourcesPath] - Path for image resources, mainly * for annotation icons. Include trailing slash. @@ -157,8 +163,8 @@ class DefaultAnnotationLayerFactory { * @param {Object} [mouseState] * @param {Promise> | null>} * [fieldObjectsPromise] - * @param {Map | null} [annotationCanvasMap] - Map some - * annotation ids with canvases used to render them. + * @param {Map} [annotationCanvasMap] - Map some + * annotation ids with canvases used to render them. * @returns {AnnotationLayerBuilder} */ createAnnotationLayerBuilder( diff --git a/web/base_viewer.js b/web/base_viewer.js index affa751c4..ea95a0ed9 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -13,6 +13,22 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */ +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ +/** @typedef {import("./interfaces").IL10n} IL10n */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ +/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + import { AnnotationMode, createPromiseCapability, @@ -68,7 +84,7 @@ const PagesCountLimit = { * @property {HTMLDivElement} [viewer] - The viewer element. * @property {EventBus} eventBus - The application event bus. * @property {IPDFLinkService} linkService - The navigation/linking service. - * @property {DownloadManager} [downloadManager] - The download manager + * @property {IDownloadManager} [downloadManager] - The download manager * component. * @property {PDFFindController} [findController] - The find controller * component. @@ -171,6 +187,11 @@ class PDFPageViewBuffer { /** * Simple viewer control to display PDF content/pages. + * + * @implements {IPDFAnnotationLayerFactory} + * @implements {IPDFStructTreeLayerFactory} + * @implements {IPDFTextLayerFactory} + * @implements {IPDFXfaLayerFactory} */ class BaseViewer { #buffer = null; @@ -525,7 +546,7 @@ class BaseViewer { } /** - * @param pdfDocument {PDFDocument} + * @param {PDFDocumentProxy} pdfDocument */ setDocument(pdfDocument) { if (this.pdfDocument) { @@ -1587,7 +1608,7 @@ class BaseViewer { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] - Storage for annotation * data in forms. * @param {string} [imageResourcesPath] - Path for image resources, mainly @@ -1599,7 +1620,7 @@ class BaseViewer { * @param {Object} [mouseState] * @param {Promise> | null>} * [fieldObjectsPromise] - * @param {Map} [annotationCanvasMap] + * @param {Map} [annotationCanvasMap] * @returns {AnnotationLayerBuilder} */ createAnnotationLayerBuilder( @@ -1637,7 +1658,7 @@ class BaseViewer { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] - Storage for annotation * data in forms. * @returns {XfaLayerBuilder} @@ -1653,7 +1674,7 @@ class BaseViewer { } /** - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @returns {StructTreeLayerBuilder} */ createStructTreeLayerBuilder(pdfPage) { diff --git a/web/download_manager.js b/web/download_manager.js index a7a09a2b3..55cc7d732 100644 --- a/web/download_manager.js +++ b/web/download_manager.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ + import { createObjectURL, createValidAbsoluteUrl, isPdfFile } from "pdfjs-lib"; import { compatibilityParams } from "./app_options.js"; @@ -42,6 +44,9 @@ function download(blobUrl, filename) { a.remove(); } +/** + * @implements {IDownloadManager} + */ class DownloadManager { constructor() { this._openBlobUrls = new WeakMap(); diff --git a/web/genericl10n.js b/web/genericl10n.js index 2368a3022..323e430ae 100644 --- a/web/genericl10n.js +++ b/web/genericl10n.js @@ -13,11 +13,16 @@ * limitations under the License. */ +/** @typedef {import("./interfaces").IL10n} IL10n */ + import "../external/webL10n/l10n.js"; import { fixupLangCode, getL10nFallback } from "./l10n_utils.js"; const webL10n = document.webL10n; +/** + * @implements {IL10n} + */ class GenericL10n { constructor(lang) { this._lang = lang; diff --git a/web/interfaces.js b/web/interfaces.js index dd1afd814..cd01bb56c 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -14,6 +14,21 @@ */ /* eslint-disable getter-return */ +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +// eslint-disable-next-line max-len +/** @typedef {import("./annotation_layer_builder").AnnotationLayerBuilder} AnnotationLayerBuilder */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_rendering_queue").RenderingStates} RenderingStates */ +// eslint-disable-next-line max-len +/** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */ +/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ +// eslint-disable-next-line max-len +/** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ +/** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */ + /** * @interface */ @@ -163,7 +178,7 @@ class IPDFTextLayerFactory { class IPDFAnnotationLayerFactory { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] - Storage for annotation * data in forms. * @param {string} [imageResourcesPath] - Path for image resources, mainly @@ -175,8 +190,8 @@ class IPDFAnnotationLayerFactory { * @param {Object} [mouseState] * @param {Promise> | null>} * [fieldObjectsPromise] - * @property {Map | null} [annotationCanvasMap] - Map some - * annotation ids with canvases used to render them. + * @param {Map} [annotationCanvasMap] - Map some + * annotation ids with canvases used to render them. * @returns {AnnotationLayerBuilder} */ createAnnotationLayerBuilder( @@ -200,7 +215,7 @@ class IPDFAnnotationLayerFactory { class IPDFXfaLayerFactory { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] * @param {Object} [xfaHtml] * @returns {XfaLayerBuilder} @@ -218,12 +233,46 @@ class IPDFXfaLayerFactory { */ class IPDFStructTreeLayerFactory { /** - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @returns {StructTreeLayerBuilder} */ createStructTreeLayerBuilder(pdfPage) {} } +/** + * @interface + */ +class IDownloadManager { + /** + * @param {string} url + * @param {string} filename + */ + downloadUrl(url, filename) {} + + /** + * @param {Uint8Array} data + * @param {string} filename + * @param {string} [contentType] + */ + downloadData(data, filename, contentType) {} + + /** + * @param {HTMLElement} element + * @param {Uint8Array} data + * @param {string} filename + * @returns {boolean} Indicating if the data was opened. + */ + openOrDownloadData(element, data, filename) {} + + /** + * @param {Blob} blob + * @param {string} url + * @param {string} filename + * @param {string} [sourceEventType] + */ + download(blob, url, filename, sourceEventType = "download") {} +} + /** * @interface */ @@ -243,11 +292,11 @@ class IL10n { * property bag. If the key was not found, translation falls back to the * fallback text. * @param {string} key - * @param {object} args - * @param {string} fallback + * @param {Object | null} [args] + * @param {string} [fallback] * @returns {Promise} */ - async get(key, args, fallback) {} + async get(key, args = null, fallback) {} /** * Translates HTML element. @@ -258,6 +307,7 @@ class IL10n { } export { + IDownloadManager, IL10n, IPDFAnnotationLayerFactory, IPDFLinkService, diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 9e36a1631..76d826212 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -13,6 +13,10 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + import { createPromiseCapability } from "pdfjs-lib"; import { getCharacterType } from "./pdf_find_utils.js"; import { scrollIntoView } from "./ui_utils.js"; diff --git a/web/pdf_history.js b/web/pdf_history.js index 7fdc1e459..b1799de6d 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -13,6 +13,9 @@ * limitations under the License. */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + import { isValidRotation, parseQueryString, diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index b5732ffe3..e0d5d5b18 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -14,6 +14,7 @@ */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ import { addLinkAttributes, LinkTarget } from "pdfjs-lib"; import { parseQueryString } from "./ui_utils.js"; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index c103451c8..9e72ad3e4 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -13,7 +13,22 @@ * limitations under the License. */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */ +/** @typedef {import("./interfaces").IL10n} IL10n */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ +/** @typedef {import("./interfaces").IL10n} IPDFXfaLayerFactory */ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ import { AnnotationMode, diff --git a/web/pdf_rendering_queue.js b/web/pdf_rendering_queue.js index 9c28bd149..2d2e02943 100644 --- a/web/pdf_rendering_queue.js +++ b/web/pdf_rendering_queue.js @@ -13,6 +13,11 @@ * limitations under the License. */ +/** @typedef {import("./interfaces").IRenderableView} IRenderableView */ +/** @typedef {import("./pdf_viewer").PDFViewer} PDFViewer */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_thumbnail_viewer").PDFThumbnailViewer} PDFThumbnailViewer */ + import { RenderingCancelledException } from "pdfjs-lib"; const CLEANUP_TIMEOUT = 30000; diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index 7895404db..6d55ed0f3 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -13,6 +13,8 @@ * limitations under the License. */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + import { createPromiseCapability, shadow } from "pdfjs-lib"; import { apiPageLayoutToViewerModes } from "./ui_utils.js"; import { RenderingStates } from "./pdf_rendering_queue.js"; diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js index 0df790e90..6e8c60e23 100644 --- a/web/pdf_thumbnail_view.js +++ b/web/pdf_thumbnail_view.js @@ -13,6 +13,12 @@ * limitations under the License. */ +/** @typedef {import("./interfaces").IL10n} IL10n */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +/** @typedef {import("./interfaces").IRenderableView} IRenderableView */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ + import { getOutputScale } from "./ui_utils.js"; import { RenderingCancelledException } from "pdfjs-lib"; import { RenderingStates } from "./pdf_rendering_queue.js"; diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js index e30501455..a5b8fd6c8 100644 --- a/web/pdf_thumbnail_viewer.js +++ b/web/pdf_thumbnail_viewer.js @@ -13,6 +13,13 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */ +/** @typedef {import("./interfaces").IL10n} IL10n */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + import { getVisibleElements, isValidRotation, @@ -37,8 +44,6 @@ const THUMBNAIL_SELECTED_CLASS = "selected"; /** * Viewer control to display thumbnails for pages in a PDF document. - * - * @implements {IRenderableView} */ class PDFThumbnailViewer { /** @@ -172,6 +177,9 @@ class PDFThumbnailViewer { this.container.textContent = ""; } + /** + * @param {PDFDocumentProxy} pdfDocument + */ setDocument(pdfDocument) { if (this.pdfDocument) { this._cancelRendering(); diff --git a/web/struct_tree_layer_builder.js b/web/struct_tree_layer_builder.js index 5fc0409d4..f3bf4dea3 100644 --- a/web/struct_tree_layer_builder.js +++ b/web/struct_tree_layer_builder.js @@ -13,6 +13,7 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ @@ -76,7 +77,7 @@ const HEADING_PATTERN = /^H(\d+)$/; /** * @typedef {Object} StructTreeLayerBuilderOptions - * @property {PDFPage} pdfPage + * @property {PDFPageProxy} pdfPage */ class StructTreeLayerBuilder { @@ -142,7 +143,7 @@ class StructTreeLayerBuilder { */ class DefaultStructTreeLayerFactory { /** - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @returns {StructTreeLayerBuilder} */ createStructTreeLayerBuilder(pdfPage) { diff --git a/web/text_highlighter.js b/web/text_highlighter.js index c8a3d729a..20f9672ae 100644 --- a/web/text_highlighter.js +++ b/web/text_highlighter.js @@ -13,6 +13,10 @@ * limitations under the License. */ +// eslint-disable-next-line max-len +/** @typedef {import("./pdf_find_controller").PDFFindController} PDFFindController */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ + /** * @typedef {Object} TextHighlighterOptions * @property {PDFFindController} findController diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index eb54a0cff..8bd03dfad 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -13,8 +13,12 @@ * limitations under the License. */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ +/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ +/** @typedef {import("./ui_utils").EventBus} EventBus */ import { renderTextLayer } from "pdfjs-lib"; diff --git a/web/xfa_layer_builder.js b/web/xfa_layer_builder.js index fdab0c901..158c388f5 100644 --- a/web/xfa_layer_builder.js +++ b/web/xfa_layer_builder.js @@ -13,6 +13,10 @@ * limitations under the License. */ +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ import { SimpleLinkService } from "./pdf_link_service.js"; @@ -21,7 +25,7 @@ import { XfaLayer } from "pdfjs-lib"; /** * @typedef {Object} XfaLayerBuilderOptions * @property {HTMLDivElement} pageDiv - * @property {PDFPage} pdfPage + * @property {PDFPageProxy} pdfPage * @property {AnnotationStorage} [annotationStorage] * @property {IPDFLinkService} linkService * @property {Object} [xfaHtml] @@ -31,7 +35,13 @@ class XfaLayerBuilder { /** * @param {XfaLayerBuilderOptions} options */ - constructor({ pageDiv, pdfPage, annotationStorage, linkService, xfaHtml }) { + constructor({ + pageDiv, + pdfPage, + annotationStorage = null, + linkService, + xfaHtml = null, + }) { this.pageDiv = pageDiv; this.pdfPage = pdfPage; this.annotationStorage = annotationStorage; @@ -54,8 +64,7 @@ class XfaLayerBuilder { const parameters = { viewport: viewport.clone({ dontFlip: true }), div: this.div, - xfa: this.xfaHtml, - page: null, + xfaHtml: this.xfaHtml, annotationStorage: this.annotationStorage, linkService: this.linkService, intent, @@ -73,16 +82,15 @@ class XfaLayerBuilder { // intent === "display" return this.pdfPage .getXfa() - .then(xfa => { - if (this._cancelled || !xfa) { + .then(xfaHtml => { + if (this._cancelled || !xfaHtml) { return { textDivs: [] }; } const parameters = { viewport: viewport.clone({ dontFlip: true }), div: this.div, - xfa, - page: this.pdfPage, + xfaHtml, annotationStorage: this.annotationStorage, linkService: this.linkService, intent, @@ -120,7 +128,7 @@ class XfaLayerBuilder { class DefaultXfaLayerFactory { /** * @param {HTMLDivElement} pageDiv - * @param {PDFPage} pdfPage + * @param {PDFPageProxy} pdfPage * @param {AnnotationStorage} [annotationStorage] * @param {Object} [xfaHtml] */ From e19020c028d56e1965a27e6a8ea0c719fb2dc1e8 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 15 Dec 2021 13:54:29 +0100 Subject: [PATCH 2/2] Move the `Default{...}LayerFactory` into a new `web/default_factory.js` file This patch, first of all, removes circular dependencies in the TypeScript definitions. Secondly, it also moves `RenderingStates` into `web/ui_utils.js` to break another type-dependency and directly use the `XfaLayerBuilder` during XFA-printing. Finally, note that this patch *slightly* reduces the size of the default viewer (e.g. in the `MOZCENTRAL` build) by not having to bundle code which is completely unused. --- web/annotation_layer_builder.js | 56 +---------- web/app.js | 3 +- web/base_viewer.js | 5 +- web/default_factory.js | 168 +++++++++++++++++++++++++++++++ web/interfaces.js | 5 +- web/pdf_find_controller.js | 2 +- web/pdf_history.js | 2 +- web/pdf_link_service.js | 2 +- web/pdf_page_view.js | 4 +- web/pdf_rendering_queue.js | 10 +- web/pdf_scripting_manager.js | 5 +- web/pdf_sidebar.js | 7 +- web/pdf_thumbnail_view.js | 3 +- web/pdf_thumbnail_viewer.js | 4 +- web/pdf_viewer.component.js | 16 +-- web/print_utils.js | 18 ++-- web/struct_tree_layer_builder.js | 19 +--- web/text_highlighter.js | 2 +- web/text_layer_builder.js | 38 +------ web/ui_utils.js | 8 ++ web/xfa_layer_builder.js | 30 +----- 21 files changed, 221 insertions(+), 186 deletions(-) create mode 100644 web/default_factory.js diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index de0f677b4..6c6fea2a1 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -18,13 +18,10 @@ /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ /** @typedef {import("./interfaces").IL10n} IL10n */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ import { AnnotationLayer } from "pdfjs-lib"; import { NullL10n } from "./l10n_utils.js"; -import { SimpleLinkService } from "./pdf_link_service.js"; /** * @typedef {Object} AnnotationLayerBuilderOptions @@ -146,55 +143,4 @@ class AnnotationLayerBuilder { } } -/** - * @implements IPDFAnnotationLayerFactory - */ -class DefaultAnnotationLayerFactory { - /** - * @param {HTMLDivElement} pageDiv - * @param {PDFPageProxy} pdfPage - * @param {AnnotationStorage} [annotationStorage] - * @param {string} [imageResourcesPath] - Path for image resources, mainly - * for annotation icons. Include trailing slash. - * @param {boolean} renderForms - * @param {IL10n} l10n - * @param {boolean} [enableScripting] - * @param {Promise} [hasJSActionsPromise] - * @param {Object} [mouseState] - * @param {Promise> | null>} - * [fieldObjectsPromise] - * @param {Map} [annotationCanvasMap] - Map some - * annotation ids with canvases used to render them. - * @returns {AnnotationLayerBuilder} - */ - createAnnotationLayerBuilder( - pageDiv, - pdfPage, - annotationStorage = null, - imageResourcesPath = "", - renderForms = true, - l10n = NullL10n, - enableScripting = false, - hasJSActionsPromise = null, - mouseState = null, - fieldObjectsPromise = null, - annotationCanvasMap = null - ) { - return new AnnotationLayerBuilder({ - pageDiv, - pdfPage, - imageResourcesPath, - renderForms, - linkService: new SimpleLinkService(), - l10n, - annotationStorage, - enableScripting, - hasJSActionsPromise, - fieldObjectsPromise, - mouseState, - annotationCanvasMap, - }); - } -} - -export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory }; +export { AnnotationLayerBuilder }; diff --git a/web/app.js b/web/app.js index 50930c556..209ad0360 100644 --- a/web/app.js +++ b/web/app.js @@ -29,6 +29,7 @@ import { parseQueryString, ProgressBar, RendererType, + RenderingStates, ScrollMode, SidebarView, SpreadMode, @@ -56,7 +57,6 @@ import { version, } from "pdfjs-lib"; import { CursorTool, PDFCursorTools } from "./pdf_cursor_tools.js"; -import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.js"; import { OverlayManager } from "./overlay_manager.js"; import { PasswordPrompt } from "./password_prompt.js"; import { PDFAttachmentViewer } from "./pdf_attachment_viewer.js"; @@ -68,6 +68,7 @@ import { PDFLayerViewer } from "./pdf_layer_viewer.js"; import { PDFLinkService } from "./pdf_link_service.js"; import { PDFOutlineViewer } from "./pdf_outline_viewer.js"; import { PDFPresentationMode } from "./pdf_presentation_mode.js"; +import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { PDFScriptingManager } from "./pdf_scripting_manager.js"; import { PDFSidebar } from "./pdf_sidebar.js"; import { PDFSidebarResizer } from "./pdf_sidebar_resizer.js"; diff --git a/web/base_viewer.js b/web/base_viewer.js index ea95a0ed9..2714ad824 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -17,6 +17,7 @@ /** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ /** @typedef {import("./interfaces").IL10n} IL10n */ // eslint-disable-next-line max-len @@ -27,7 +28,6 @@ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ /** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { AnnotationMode, @@ -50,6 +50,7 @@ import { MIN_SCALE, PresentationModeState, RendererType, + RenderingStates, SCROLLBAR_PADDING, scrollIntoView, ScrollMode, @@ -59,10 +60,10 @@ import { VERTICAL_PADDING, watchScroll, } from "./ui_utils.js"; -import { PDFRenderingQueue, RenderingStates } from "./pdf_rendering_queue.js"; import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { NullL10n } from "./l10n_utils.js"; import { PDFPageView } from "./pdf_page_view.js"; +import { PDFRenderingQueue } from "./pdf_rendering_queue.js"; import { SimpleLinkService } from "./pdf_link_service.js"; import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; import { TextHighlighter } from "./text_highlighter.js"; diff --git a/web/default_factory.js b/web/default_factory.js new file mode 100644 index 000000000..f9289b552 --- /dev/null +++ b/web/default_factory.js @@ -0,0 +1,168 @@ +/* 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. + */ + +/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ +// eslint-disable-next-line max-len +/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ +/** @typedef {import("./event_utils").EventBus} EventBus */ +/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ +/** @typedef {import("./interfaces").IL10n} IL10n */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ +/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ +// eslint-disable-next-line max-len +/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ +/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ +/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ + +import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; +import { NullL10n } from "./l10n_utils.js"; +import { SimpleLinkService } from "./pdf_link_service.js"; +import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js"; +import { TextLayerBuilder } from "./text_layer_builder.js"; +import { XfaLayerBuilder } from "./xfa_layer_builder.js"; + +/** + * @implements IPDFAnnotationLayerFactory + */ +class DefaultAnnotationLayerFactory { + /** + * @param {HTMLDivElement} pageDiv + * @param {PDFPageProxy} pdfPage + * @param {AnnotationStorage} [annotationStorage] + * @param {string} [imageResourcesPath] - Path for image resources, mainly + * for annotation icons. Include trailing slash. + * @param {boolean} renderForms + * @param {IL10n} l10n + * @param {boolean} [enableScripting] + * @param {Promise} [hasJSActionsPromise] + * @param {Object} [mouseState] + * @param {Promise> | null>} + * [fieldObjectsPromise] + * @param {Map} [annotationCanvasMap] - Map some + * annotation ids with canvases used to render them. + * @returns {AnnotationLayerBuilder} + */ + createAnnotationLayerBuilder( + pageDiv, + pdfPage, + annotationStorage = null, + imageResourcesPath = "", + renderForms = true, + l10n = NullL10n, + enableScripting = false, + hasJSActionsPromise = null, + mouseState = null, + fieldObjectsPromise = null, + annotationCanvasMap = null + ) { + return new AnnotationLayerBuilder({ + pageDiv, + pdfPage, + imageResourcesPath, + renderForms, + linkService: new SimpleLinkService(), + l10n, + annotationStorage, + enableScripting, + hasJSActionsPromise, + fieldObjectsPromise, + mouseState, + annotationCanvasMap, + }); + } +} + +/** + * @implements IPDFStructTreeLayerFactory + */ +class DefaultStructTreeLayerFactory { + /** + * @param {PDFPageProxy} pdfPage + * @returns {StructTreeLayerBuilder} + */ + createStructTreeLayerBuilder(pdfPage) { + return new StructTreeLayerBuilder({ + pdfPage, + }); + } +} + +/** + * @implements IPDFTextLayerFactory + */ +class DefaultTextLayerFactory { + /** + * @param {HTMLDivElement} textLayerDiv + * @param {number} pageIndex + * @param {PageViewport} viewport + * @param {boolean} enhanceTextSelection + * @param {EventBus} eventBus + * @param {TextHighlighter} highlighter + * @returns {TextLayerBuilder} + */ + createTextLayerBuilder( + textLayerDiv, + pageIndex, + viewport, + enhanceTextSelection = false, + eventBus, + highlighter + ) { + return new TextLayerBuilder({ + textLayerDiv, + pageIndex, + viewport, + enhanceTextSelection, + eventBus, + highlighter, + }); + } +} + +/** + * @implements IPDFXfaLayerFactory + */ +class DefaultXfaLayerFactory { + /** + * @param {HTMLDivElement} pageDiv + * @param {PDFPageProxy} pdfPage + * @param {AnnotationStorage} [annotationStorage] + * @param {Object} [xfaHtml] + */ + createXfaLayerBuilder( + pageDiv, + pdfPage, + annotationStorage = null, + xfaHtml = null + ) { + return new XfaLayerBuilder({ + pageDiv, + pdfPage, + annotationStorage, + linkService: new SimpleLinkService(), + xfaHtml, + }); + } +} + +export { + DefaultAnnotationLayerFactory, + DefaultStructTreeLayerFactory, + DefaultTextLayerFactory, + DefaultXfaLayerFactory, +}; diff --git a/web/interfaces.js b/web/interfaces.js index cd01bb56c..93b4f3489 100644 --- a/web/interfaces.js +++ b/web/interfaces.js @@ -19,14 +19,13 @@ /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ // eslint-disable-next-line max-len /** @typedef {import("./annotation_layer_builder").AnnotationLayerBuilder} AnnotationLayerBuilder */ -// eslint-disable-next-line max-len -/** @typedef {import("./pdf_rendering_queue").RenderingStates} RenderingStates */ +/** @typedef {import("./event_utils").EventBus} EventBus */ // eslint-disable-next-line max-len /** @typedef {import("./struct_tree_builder").StructTreeLayerBuilder} StructTreeLayerBuilder */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ // eslint-disable-next-line max-len /** @typedef {import("./text_layer_builder").TextLayerBuilder} TextLayerBuilder */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ +/** @typedef {import("./ui_utils").RenderingStates} RenderingStates */ /** @typedef {import("./xfa_layer_builder").XfaLayerBuilder} XfaLayerBuilder */ /** diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 76d826212..1f0008b35 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -14,8 +14,8 @@ */ /** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { createPromiseCapability } from "pdfjs-lib"; import { getCharacterType } from "./pdf_find_utils.js"; diff --git a/web/pdf_history.js b/web/pdf_history.js index b1799de6d..c6ef42cc7 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -13,8 +13,8 @@ * limitations under the License. */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { isValidRotation, diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index e0d5d5b18..3f6e4eb25 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -13,8 +13,8 @@ * limitations under the License. */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { addLinkAttributes, LinkTarget } from "pdfjs-lib"; import { parseQueryString } from "./ui_utils.js"; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 9e72ad3e4..1740c59df 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -17,6 +17,7 @@ /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ // eslint-disable-next-line max-len /** @typedef {import("../src/display/optional_content_config").OptionalContentConfig} OptionalContentConfig */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IL10n} IL10n */ // eslint-disable-next-line max-len /** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */ @@ -28,7 +29,6 @@ /** @typedef {import("./interfaces").IRenderableView} IRenderableView */ // eslint-disable-next-line max-len /** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { AnnotationMode, @@ -42,12 +42,12 @@ import { DEFAULT_SCALE, getOutputScale, RendererType, + RenderingStates, roundToDivide, TextLayerMode, } from "./ui_utils.js"; import { compatibilityParams } from "./app_options.js"; import { NullL10n } from "./l10n_utils.js"; -import { RenderingStates } from "./pdf_rendering_queue.js"; /** * @typedef {Object} PDFPageViewOptions diff --git a/web/pdf_rendering_queue.js b/web/pdf_rendering_queue.js index 2d2e02943..94644df57 100644 --- a/web/pdf_rendering_queue.js +++ b/web/pdf_rendering_queue.js @@ -19,16 +19,10 @@ /** @typedef {import("./pdf_thumbnail_viewer").PDFThumbnailViewer} PDFThumbnailViewer */ import { RenderingCancelledException } from "pdfjs-lib"; +import { RenderingStates } from "./ui_utils.js"; const CLEANUP_TIMEOUT = 30000; -const RenderingStates = { - INITIAL: 0, - RUNNING: 1, - PAUSED: 2, - FINISHED: 3, -}; - /** * Controls rendering of the views for pages and thumbnails. */ @@ -216,4 +210,4 @@ class PDFRenderingQueue { } } -export { PDFRenderingQueue, RenderingStates }; +export { PDFRenderingQueue }; diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index 6d55ed0f3..a07cad2b3 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -13,11 +13,10 @@ * limitations under the License. */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ +/** @typedef {import("./event_utils").EventBus} EventBus */ +import { apiPageLayoutToViewerModes, RenderingStates } from "./ui_utils.js"; import { createPromiseCapability, shadow } from "pdfjs-lib"; -import { apiPageLayoutToViewerModes } from "./ui_utils.js"; -import { RenderingStates } from "./pdf_rendering_queue.js"; /** * @typedef {Object} PDFScriptingManagerOptions diff --git a/web/pdf_sidebar.js b/web/pdf_sidebar.js index 1e7e04ad0..f3f861c4e 100644 --- a/web/pdf_sidebar.js +++ b/web/pdf_sidebar.js @@ -13,8 +13,11 @@ * limitations under the License. */ -import { PresentationModeState, SidebarView } from "./ui_utils.js"; -import { RenderingStates } from "./pdf_rendering_queue.js"; +import { + PresentationModeState, + RenderingStates, + SidebarView, +} from "./ui_utils.js"; const UI_NOTIFICATION_CLASS = "pdfSidebarNotification"; diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js index 6e8c60e23..b2d5541fa 100644 --- a/web/pdf_thumbnail_view.js +++ b/web/pdf_thumbnail_view.js @@ -19,9 +19,8 @@ // eslint-disable-next-line max-len /** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ -import { getOutputScale } from "./ui_utils.js"; +import { getOutputScale, RenderingStates } from "./ui_utils.js"; import { RenderingCancelledException } from "pdfjs-lib"; -import { RenderingStates } from "./pdf_rendering_queue.js"; const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below. const MAX_NUM_SCALING_STEPS = 3; diff --git a/web/pdf_thumbnail_viewer.js b/web/pdf_thumbnail_viewer.js index a5b8fd6c8..d7e6221c1 100644 --- a/web/pdf_thumbnail_viewer.js +++ b/web/pdf_thumbnail_viewer.js @@ -14,20 +14,20 @@ */ /** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len /** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { getVisibleElements, isValidRotation, + RenderingStates, scrollIntoView, watchScroll, } from "./ui_utils.js"; import { PDFThumbnailView, TempImageFactory } from "./pdf_thumbnail_view.js"; -import { RenderingStates } from "./pdf_rendering_queue.js"; const THUMBNAIL_SCROLL_MARGIN = -19; const THUMBNAIL_SELECTED_CLASS = "selected"; diff --git a/web/pdf_viewer.component.js b/web/pdf_viewer.component.js index 63be97d16..dce7d9b93 100644 --- a/web/pdf_viewer.component.js +++ b/web/pdf_viewer.component.js @@ -14,23 +14,14 @@ */ import { - AnnotationLayerBuilder, DefaultAnnotationLayerFactory, -} from "./annotation_layer_builder.js"; -import { DefaultStructTreeLayerFactory, - StructTreeLayerBuilder, -} from "./struct_tree_layer_builder.js"; -import { DefaultTextLayerFactory, - TextLayerBuilder, -} from "./text_layer_builder.js"; -import { DefaultXfaLayerFactory, - XfaLayerBuilder, -} from "./xfa_layer_builder.js"; +} from "./default_factory.js"; import { PDFLinkService, SimpleLinkService } from "./pdf_link_service.js"; import { PDFSinglePageViewer, PDFViewer } from "./pdf_viewer.js"; +import { AnnotationLayerBuilder } from "./annotation_layer_builder.js"; import { DownloadManager } from "./download_manager.js"; import { EventBus } from "./event_utils.js"; import { GenericL10n } from "./genericl10n.js"; @@ -40,6 +31,9 @@ import { PDFHistory } from "./pdf_history.js"; import { PDFPageView } from "./pdf_page_view.js"; import { PDFScriptingManager } from "./pdf_scripting_manager.js"; import { ProgressBar } from "./ui_utils.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"); diff --git a/web/print_utils.js b/web/print_utils.js index 20482eaa5..19488aa28 100644 --- a/web/print_utils.js +++ b/web/print_utils.js @@ -14,11 +14,12 @@ */ import { getXfaPageViewport, PixelsPerInch } from "pdfjs-lib"; -import { DefaultXfaLayerFactory } from "./xfa_layer_builder.js"; +import { SimpleLinkService } from "./pdf_link_service.js"; +import { XfaLayerBuilder } from "./xfa_layer_builder.js"; function getXfaHtmlForPrinting(printContainer, pdfDocument) { const xfaHtml = pdfDocument.allXfaHtml; - const factory = new DefaultXfaLayerFactory(); + const linkService = new SimpleLinkService(); const scale = Math.round(PixelsPerInch.PDF_TO_CSS_UNITS * 100) / 100; for (const xfaPage of xfaHtml.children) { @@ -26,12 +27,13 @@ function getXfaHtmlForPrinting(printContainer, pdfDocument) { page.className = "xfaPrintedPage"; printContainer.appendChild(page); - const builder = factory.createXfaLayerBuilder( - /* pageDiv = */ page, - /* pdfPage = */ null, - /* annotationStorage = */ pdfDocument.annotationStorage, - /* xfaHtml = */ xfaPage - ); + const builder = new XfaLayerBuilder({ + pageDiv: page, + pdfPage: null, + annotationStorage: pdfDocument.annotationStorage, + linkService, + xfaHtml: xfaPage, + }); const viewport = getXfaPageViewport(xfaPage, { scale }); builder.render(viewport, "print"); diff --git a/web/struct_tree_layer_builder.js b/web/struct_tree_layer_builder.js index f3bf4dea3..a0b276417 100644 --- a/web/struct_tree_layer_builder.js +++ b/web/struct_tree_layer_builder.js @@ -14,8 +14,6 @@ */ /** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */ const PDF_ROLE_TO_HTML_ROLE = { // Document level structure types @@ -138,19 +136,4 @@ class StructTreeLayerBuilder { } } -/** - * @implements IPDFStructTreeLayerFactory - */ -class DefaultStructTreeLayerFactory { - /** - * @param {PDFPageProxy} pdfPage - * @returns {StructTreeLayerBuilder} - */ - createStructTreeLayerBuilder(pdfPage) { - return new StructTreeLayerBuilder({ - pdfPage, - }); - } -} - -export { DefaultStructTreeLayerFactory, StructTreeLayerBuilder }; +export { StructTreeLayerBuilder }; diff --git a/web/text_highlighter.js b/web/text_highlighter.js index 20f9672ae..27e84f01b 100644 --- a/web/text_highlighter.js +++ b/web/text_highlighter.js @@ -13,9 +13,9 @@ * limitations under the License. */ +/** @typedef {import("./event_utils").EventBus} EventBus */ // eslint-disable-next-line max-len /** @typedef {import("./pdf_find_controller").PDFFindController} PDFFindController */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ /** * @typedef {Object} TextHighlighterOptions diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index 8bd03dfad..8767ba360 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -15,10 +15,8 @@ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ -// eslint-disable-next-line max-len -/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */ +/** @typedef {import("./event_utils").EventBus} EventBus */ /** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */ -/** @typedef {import("./ui_utils").EventBus} EventBus */ import { renderTextLayer } from "pdfjs-lib"; @@ -221,36 +219,4 @@ class TextLayerBuilder { } } -/** - * @implements IPDFTextLayerFactory - */ -class DefaultTextLayerFactory { - /** - * @param {HTMLDivElement} textLayerDiv - * @param {number} pageIndex - * @param {PageViewport} viewport - * @param {boolean} enhanceTextSelection - * @param {EventBus} eventBus - * @param {TextHighlighter} highlighter - * @returns {TextLayerBuilder} - */ - createTextLayerBuilder( - textLayerDiv, - pageIndex, - viewport, - enhanceTextSelection = false, - eventBus, - highlighter - ) { - return new TextLayerBuilder({ - textLayerDiv, - pageIndex, - viewport, - enhanceTextSelection, - eventBus, - highlighter, - }); - } -} - -export { DefaultTextLayerFactory, TextLayerBuilder }; +export { TextLayerBuilder }; diff --git a/web/ui_utils.js b/web/ui_utils.js index c662f84cf..d446cda3d 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -25,6 +25,13 @@ const VERTICAL_PADDING = 5; const LOADINGBAR_END_OFFSET_VAR = "--loadingBar-end-offset"; +const RenderingStates = { + INITIAL: 0, + RUNNING: 1, + PAUSED: 2, + FINISHED: 3, +}; + const PresentationModeState = { UNKNOWN: 0, NORMAL: 1, @@ -832,6 +839,7 @@ export { PresentationModeState, ProgressBar, RendererType, + RenderingStates, roundToDivide, SCROLLBAR_PADDING, scrollIntoView, diff --git a/web/xfa_layer_builder.js b/web/xfa_layer_builder.js index 158c388f5..b4e933b35 100644 --- a/web/xfa_layer_builder.js +++ b/web/xfa_layer_builder.js @@ -17,9 +17,7 @@ // eslint-disable-next-line max-len /** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ -/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */ -import { SimpleLinkService } from "./pdf_link_service.js"; import { XfaLayer } from "pdfjs-lib"; /** @@ -122,30 +120,4 @@ class XfaLayerBuilder { } } -/** - * @implements IPDFXfaLayerFactory - */ -class DefaultXfaLayerFactory { - /** - * @param {HTMLDivElement} pageDiv - * @param {PDFPageProxy} pdfPage - * @param {AnnotationStorage} [annotationStorage] - * @param {Object} [xfaHtml] - */ - createXfaLayerBuilder( - pageDiv, - pdfPage, - annotationStorage = null, - xfaHtml = null - ) { - return new XfaLayerBuilder({ - pageDiv, - pdfPage, - annotationStorage, - linkService: new SimpleLinkService(), - xfaHtml, - }); - } -} - -export { DefaultXfaLayerFactory, XfaLayerBuilder }; +export { XfaLayerBuilder };