Skip to content

Commit 85af3ae

Browse files
michael-yx-wubh213
authored andcommitted
Fix Viewer API definitions and include in CI
The Viewer API definitions do not compile because of missing imports and anonymous objects are typed as `Object`. These issues were not caught during CI because the test project was not compiling anything from the Viewer API. As an example of the first problem: ``` /** * @implements MyInterface */ export class MyClass { ... } ``` will generate a broken definition that doesn’t import MyInterface: ``` /** * @implements MyInterface */ export class MyClass implements MyInterface { ... } ``` This can be fixed by adding a typedef jsdoc to specify the import: ``` /** @typedef {import("./otherFile").MyInterface} MyInterface */ ``` See jsdoc/jsdoc#1537 and microsoft/TypeScript#22160 for more details. As an example of the second problem: ``` /** * Gets the size of the specified page, converted from PDF units to inches. * @param {Object} An Object containing the properties: {Array} `view`, * {number} `userUnit`, and {number} `rotate`. */ function getPageSizeInches({ view, userUnit, rotate }) { ... } ``` generates the broken definition: ``` function getPageSizeInches({ view, userUnit, rotate }: Object) { ... } ``` The jsdoc should specify the type of each nested property: ``` /** * Gets the size of the specified page, converted from PDF units to inches. * @param {Object} options An object containing the properties: {Array} `view`, * {number} `userUnit`, and {number} `rotate`. * @param {number[]} options.view * @param {number} options.userUnit * @param {number} options.rotate */ ```
1 parent 7ee910b commit 85af3ae

15 files changed

+47
-11
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "pdfjs-dist/types/web/pdf_viewer.component";
1+
export * from "../../types/web/pdf_viewer.component";

external/dist/web/pdf_viewer.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from "pdfjs-dist/types/web/pdf_viewer.component";
1+
export * from "../types/web/pdf_viewer.component";

test/types/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { getDocument } from "pdfjs-dist";
2+
import { EventBus } from "pdfjs-dist/web/pdf_viewer.component";
23

34
class MainTest {
5+
eventBus: EventBus;
46
task: ReturnType<typeof getDocument> | undefined;
57

68
constructor(public file: string) {
9+
this.eventBus = new EventBus({});
710
}
811

912
loadPdf() {

test/types/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"paths": {
1919
"pdfjs-dist": ["../../build/typestest"],
20-
"pdfjs-dist/*": ["../../build/typestest/build/*"]
20+
"pdfjs-dist/*": ["../../build/typestest/types/*"]
2121
}
2222
},
2323
"files": [

web/annotation_layer_builder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
// eslint-disable-next-line max-len
17+
/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
18+
1619
import { AnnotationLayer } from "pdfjs-lib";
1720
import { NullL10n } from "./l10n_utils.js";
1821
import { SimpleLinkService } from "./pdf_link_service.js";

web/base_viewer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ function isSameScale(oldScale, newScale) {
139139

140140
/**
141141
* Simple viewer control to display PDF content/pages.
142-
* @implements {IRenderableView}
143142
*/
144143
class BaseViewer {
145144
/**

web/interfaces.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class IPDFLinkService {
106106
* @interface
107107
*/
108108
class IRenderableView {
109+
constructor() {
110+
/** @type {function | null} */
111+
this.resume = null;
112+
}
113+
109114
/**
110115
* @type {string} - Unique ID for rendering queue.
111116
*/
@@ -120,8 +125,6 @@ class IRenderableView {
120125
* @returns {Promise} Resolved on draw completion.
121126
*/
122127
draw() {}
123-
124-
resume() {}
125128
}
126129

127130
/**

web/pdf_link_service.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
17+
1618
import { parseQueryString } from "./ui_utils.js";
1719

1820
/**

web/pdf_page_view.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("./interfaces").IRenderableView} IRenderableView */
17+
1618
import {
1719
AnnotationMode,
1820
createPromiseCapability,

web/pdf_rendering_queue.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class PDFRenderingQueue {
3333
this.pdfThumbnailViewer = null;
3434
this.onIdle = null;
3535
this.highestPriorityPage = null;
36+
/** @type {number} */
3637
this.idleTimeout = null;
3738
this.printing = false;
3839
this.isThumbnailViewEnabled = false;

web/struct_tree_layer_builder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
// eslint-disable-next-line max-len
17+
/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */
18+
1619
const PDF_ROLE_TO_HTML_ROLE = {
1720
// Document level structure types
1821
Document: null, // There's a "document" role, but it doesn't make sense here.

web/text_highlighter.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
/**
17-
* @typedef {Object} TextHighlighter
17+
* @typedef {Object} TextHighlighterOptions
1818
* @property {PDFFindController} findController
1919
* @property {EventBus} eventBus - The application event bus.
2020
* @property {number} pageIndex - The page index.
@@ -25,6 +25,9 @@
2525
* either the text layer or XFA layer depending on the type of document.
2626
*/
2727
class TextHighlighter {
28+
/**
29+
* @param {TextHighlighterOptions} options
30+
*/
2831
constructor({ findController, eventBus, pageIndex }) {
2932
this.findController = findController;
3033
this.matches = [];

web/text_layer_builder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
* limitations under the License.
1414
*/
1515

16+
// eslint-disable-next-line max-len
17+
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
18+
1619
import { renderTextLayer } from "pdfjs-lib";
1720

1821
const EXPAND_DIVS_TIMEOUT = 300; // ms

web/ui_utils.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,23 @@ function roundToDivide(x, div) {
284284
return r === 0 ? x : Math.round(x - r + div);
285285
}
286286

287+
/**
288+
* @typedef {Object} GetPageSizeInchesParameters
289+
* @property {number[]} view
290+
* @property {number} userUnit
291+
* @property {number} rotate
292+
*/
293+
294+
/**
295+
* @typedef {Object} PageSize
296+
* @property {number} width - In inches.
297+
* @property {number} height - In inches.
298+
*/
299+
287300
/**
288301
* Gets the size of the specified page, converted from PDF units to inches.
289-
* @param {Object} An Object containing the properties: {Array} `view`,
290-
* {number} `userUnit`, and {number} `rotate`.
291-
* @returns {Object} An Object containing the properties: {number} `width`
292-
* and {number} `height`, given in inches.
302+
* @param {GetPageSizeInchesParameters} params
303+
* @returns {PageSize}
293304
*/
294305
function getPageSizeInches({ view, userUnit, rotate }) {
295306
const [x1, y1, x2, y2] = view;

web/xfa_layer_builder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
* limitations under the License.
1414
*/
1515

16+
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
17+
1618
import { XfaLayer } from "pdfjs-lib";
1719

1820
/**
1921
* @typedef {Object} XfaLayerBuilderOptions
2022
* @property {HTMLDivElement} pageDiv
2123
* @property {PDFPage} pdfPage
24+
* @property {Object} [xfaHtml]
2225
* @property {AnnotationStorage} [annotationStorage]
2326
*/
2427

0 commit comments

Comments
 (0)