Skip to content

Commit 2645a0c

Browse files
committed
Fix broken/missing JSDocs and typedefs, 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.
1 parent a425c9c commit 2645a0c

23 files changed

+234
-73
lines changed

package-lock.json

+12-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"terser": "^5.10.0",
5353
"through2": "^4.0.2",
5454
"ttest": "^3.0.0",
55-
"typescript": "~4.4.4",
55+
"typescript": "^4.5.4",
5656
"typogr": "^0.6.8",
5757
"vinyl": "^2.2.1",
5858
"vinyl-fs": "^3.0.3",

src/display/annotation_layer.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("./api").PDFPageProxy} PDFPageProxy */
17+
/** @typedef {import("./display_utils").PageViewport} PageViewport */
18+
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
19+
/** @typedef {import("../../web/interfaces").IPDFLinkService} IPDFLinkService */
20+
1621
import {
1722
AnnotationBorderStyleType,
1823
AnnotationType,
@@ -39,10 +44,10 @@ const GetElementsByNameSet = new WeakSet();
3944
* @typedef {Object} AnnotationElementParameters
4045
* @property {Object} data
4146
* @property {HTMLDivElement} layer
42-
* @property {PDFPage} page
47+
* @property {PDFPageProxy} page
4348
* @property {PageViewport} viewport
4449
* @property {IPDFLinkService} linkService
45-
* @property {DownloadManager} downloadManager
50+
* @property {IDownloadManager} downloadManager
4651
* @property {AnnotationStorage} [annotationStorage]
4752
* @property {string} [imageResourcesPath] - Path for image resources, mainly
4853
* for annotation icons. Include trailing slash.
@@ -1700,7 +1705,7 @@ class PopupElement {
17001705
(!this.contentsObj?.str || this.contentsObj.str === this.richText.str)
17011706
) {
17021707
XfaLayer.render({
1703-
xfa: this.richText.html,
1708+
xfaHtml: this.richText.html,
17041709
intent: "richText",
17051710
div: popup,
17061711
});
@@ -2302,15 +2307,16 @@ class FileAttachmentAnnotationElement extends AnnotationElement {
23022307
* @property {PageViewport} viewport
23032308
* @property {HTMLDivElement} div
23042309
* @property {Array} annotations
2305-
* @property {PDFPage} page
2310+
* @property {PDFPageProxy} page
23062311
* @property {IPDFLinkService} linkService
2307-
* @property {DownloadManager} downloadManager
2312+
* @property {IDownloadManager} downloadManager
23082313
* @property {string} [imageResourcesPath] - Path for image resources, mainly
23092314
* for annotation icons. Include trailing slash.
23102315
* @property {boolean} renderForms
23112316
* @property {boolean} [enableScripting] - Enable embedded script execution.
23122317
* @property {boolean} [hasJSActions] - Some fields have JS actions.
23132318
* The default value is `false`.
2319+
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
23142320
*/
23152321

23162322
class AnnotationLayer {

src/display/api.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,8 @@ class PDFDocumentProxy {
11681168
* created from `PDFDocumentProxy.getOptionalContentConfig`. If `null`,
11691169
* the configuration will be fetched automatically with the default visibility
11701170
* states set.
1171-
* @property {Map<string, Canvas>} [annotationCanvasMap] - Map some annotation
1172-
* ids with canvases used to render them.
1171+
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
1172+
* annotation ids with canvases used to render them.
11731173
*/
11741174

11751175
/**

src/display/xfa_layer.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,23 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("./display_utils").PageViewport} PageViewport */
17+
/** @typedef {import("../../web/interfaces").IPDFLinkService} IPDFLinkService */
18+
1619
import { warn } from "../shared/util.js";
1720
import { XfaText } from "./xfa_text.js";
1821

22+
/**
23+
* @typedef {Object} XfaLayerParameters
24+
* @property {PageViewport} viewport
25+
* @property {HTMLDivElement} div
26+
* @property {Object} xfaHtml
27+
* @property {PDFPageProxy} [pdfPage]
28+
* @property {AnnotationStorage} [annotationStorage]
29+
* @property {IPDFLinkService} linkService
30+
* @property {string} [intent] - (default value is 'display').
31+
*/
32+
1933
class XfaLayer {
2034
static setupStorage(html, id, element, storage, intent) {
2135
const storedData = storage.getValue(id, { value: null });
@@ -143,10 +157,15 @@ class XfaLayer {
143157
}
144158
}
145159

160+
/**
161+
* Render the XFA layer.
162+
*
163+
* @param {XfaLayerParameters} parameters
164+
*/
146165
static render(parameters) {
147166
const storage = parameters.annotationStorage;
148167
const linkService = parameters.linkService;
149-
const root = parameters.xfa;
168+
const root = parameters.xfaHtml;
150169
const intent = parameters.intent || "display";
151170
const rootHtml = document.createElement(root.name);
152171
if (root.attributes) {
@@ -252,11 +271,9 @@ class XfaLayer {
252271
}
253272

254273
/**
255-
* Update the xfa layer.
274+
* Update the XFA layer.
256275
*
257-
* @public
258276
* @param {XfaLayerParameters} parameters
259-
* @memberof XfaLayer
260277
*/
261278
static update(parameters) {
262279
const transform = `matrix(${parameters.viewport.transform.join(",")})`;

test/driver.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ class Rasterize {
272272
static async xfaLayer(
273273
ctx,
274274
viewport,
275-
xfa,
275+
xfaHtml,
276276
fontRules,
277277
annotationStorage,
278278
isPrint
@@ -285,7 +285,7 @@ class Rasterize {
285285

286286
// Rendering XFA layer as HTML.
287287
XfaLayer.render({
288-
xfa,
288+
xfaHtml,
289289
div,
290290
viewport: viewport.clone({ dontFlip: true }),
291291
annotationStorage,
@@ -688,11 +688,11 @@ class Driver {
688688
initPromise = page.getAnnotations({ intent: "display" });
689689
annotationCanvasMap = new Map();
690690
} else {
691-
initPromise = page.getXfa().then(function (xfa) {
691+
initPromise = page.getXfa().then(function (xfaHtml) {
692692
return Rasterize.xfaLayer(
693693
annotationLayerContext,
694694
viewport,
695-
xfa,
695+
xfaHtml,
696696
task.fontRules,
697697
task.pdfDoc.annotationStorage,
698698
task.renderPrint

web/annotation_layer_builder.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
17+
// eslint-disable-next-line max-len
18+
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
19+
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
20+
/** @typedef {import("./interfaces").IL10n} IL10n */
1621
// eslint-disable-next-line max-len
1722
/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
23+
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
1824

1925
import { AnnotationLayer } from "pdfjs-lib";
2026
import { NullL10n } from "./l10n_utils.js";
@@ -23,20 +29,20 @@ import { SimpleLinkService } from "./pdf_link_service.js";
2329
/**
2430
* @typedef {Object} AnnotationLayerBuilderOptions
2531
* @property {HTMLDivElement} pageDiv
26-
* @property {PDFPage} pdfPage
32+
* @property {PDFPageProxy} pdfPage
2733
* @property {AnnotationStorage} [annotationStorage]
2834
* @property {string} [imageResourcesPath] - Path for image resources, mainly
2935
* for annotation icons. Include trailing slash.
3036
* @property {boolean} renderForms
3137
* @property {IPDFLinkService} linkService
32-
* @property {DownloadManager} downloadManager
38+
* @property {IDownloadManager} downloadManager
3339
* @property {IL10n} l10n - Localization service.
3440
* @property {boolean} [enableScripting]
3541
* @property {Promise<boolean>} [hasJSActionsPromise]
3642
* @property {Promise<Object<string, Array<Object>> | null>}
3743
* [fieldObjectsPromise]
3844
* @property {Object} [mouseState]
39-
* @property {Map<string, Canvas>} [annotationCanvasMap]
45+
* @property {Map<string, HTMLCanvasElement>} [annotationCanvasMap]
4046
*/
4147

4248
class AnnotationLayerBuilder {
@@ -146,7 +152,7 @@ class AnnotationLayerBuilder {
146152
class DefaultAnnotationLayerFactory {
147153
/**
148154
* @param {HTMLDivElement} pageDiv
149-
* @param {PDFPage} pdfPage
155+
* @param {PDFPageProxy} pdfPage
150156
* @param {AnnotationStorage} [annotationStorage]
151157
* @param {string} [imageResourcesPath] - Path for image resources, mainly
152158
* for annotation icons. Include trailing slash.
@@ -157,8 +163,8 @@ class DefaultAnnotationLayerFactory {
157163
* @param {Object} [mouseState]
158164
* @param {Promise<Object<string, Array<Object>> | null>}
159165
* [fieldObjectsPromise]
160-
* @param {Map<string, Canvas> | null} [annotationCanvasMap] - Map some
161-
* annotation ids with canvases used to render them.
166+
* @param {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
167+
* annotation ids with canvases used to render them.
162168
* @returns {AnnotationLayerBuilder}
163169
*/
164170
createAnnotationLayerBuilder(

0 commit comments

Comments
 (0)