Skip to content

Commit

Permalink
add missing type imports for viewer, fix BaseTreeViewer type inheri…
Browse files Browse the repository at this point in the history
…tance, add type definition for `AnnotationEditorParamsOptions`, make `GrabToPan` constructor type compatible with typescript
  • Loading branch information
ex37 committed Apr 12, 2024
1 parent 2e52829 commit d5eb60d
Show file tree
Hide file tree
Showing 17 changed files with 92 additions and 15 deletions.
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"display-node_utils": ["./src/display/node_utils"],
"fluent-bundle": ["./node_modules/@fluent/bundle/esm/index.js"],
"fluent-dom": ["./node_modules/@fluent/dom/esm/index.js"],
"web-null_l10n": ["../web/genericl10n.js"]
"web-null_l10n": ["./web/genericl10n"]
}
},
"files": ["src/pdf.js", "web/pdf_viewer.component.js"]
Expand Down
17 changes: 17 additions & 0 deletions web/annotation_editor_params.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */

import { AnnotationEditorParamsType } from "pdfjs-lib";

/**
* @typedef {Object} AnnotationEditorParamsOptions
* @property {HTMLInputElement} editorFreeTextFontSize
* @property {HTMLInputElement} editorFreeTextColor
* @property {HTMLInputElement} editorInkColor
* @property {HTMLInputElement} editorInkThickness
* @property {HTMLInputElement} editorInkOpacity
* @property {HTMLButtonElement} editorStampAddImage
* @property {HTMLInputElement} editorFreeHighlightThickness
* @property {HTMLButtonElement} editorHighlightShowAll
*/

class AnnotationEditorParams {
/**
* @param {AnnotationEditorParamsOptions} options
Expand All @@ -25,6 +39,9 @@ class AnnotationEditorParams {
this.#bindListeners(options);
}

/**
* @param {AnnotationEditorParamsOptions} options
*/
#bindListeners({
editorFreeTextFontSize,
editorFreeTextColor,
Expand Down
8 changes: 8 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* limitations under the License.
*/

/** @typedef {import("./interfaces.js").IL10n} IL10n */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/api.js").PDFDocumentProxy} PDFDocumentProxy */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/api.js").PDFDocumentLoadingTask} PDFDocumentLoadingTask */

import {
animationStarted,
apiPageLayoutToViewerModes,
Expand Down Expand Up @@ -96,7 +102,9 @@ const PDFViewerApplication = {
settled: false,
},
appConfig: null,
/** @type {PDFDocumentProxy} */
pdfDocument: null,
/** @type {PDFDocumentLoadingTask} */
pdfLoadingTask: null,
printService: null,
/** @type {PDFViewer} */
Expand Down
8 changes: 5 additions & 3 deletions web/base_tree_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ class BaseTreeViewer {
}

/**
* @private
* @protected
*/
_dispatchEvent(count) {
throw new Error("Not implemented: _dispatchEvent");
}

/**
* @private
* @protected
*/
_bindLink(element, params) {
throw new Error("Not implemented: _bindLink");
Expand All @@ -71,7 +71,9 @@ class BaseTreeViewer {
/**
* Prepend a button before a tree item which allows the user to collapse or
* expand all tree items at that level; see `_toggleTreeItem`.
* @private
* @param {HTMLDivElement} div
* @param {boolean|object} [hidden=false]
* @protected
*/
_addToggleButton(div, hidden = false) {
const toggler = document.createElement("div");
Expand Down
5 changes: 5 additions & 0 deletions web/external_services.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/** @typedef {import("./interfaces.js").IL10n} IL10n */

class BaseExternalServices {
constructor() {
if (this.constructor === BaseExternalServices) {
Expand All @@ -28,6 +30,9 @@ class BaseExternalServices {

reportTelemetry(data) {}

/**
* @returns {Promise<IL10n>}
*/
async createL10n() {
throw new Error("Not implemented: createL10n");
}
Expand Down
7 changes: 6 additions & 1 deletion web/grab_to_pan.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@
// Class name of element which can be grabbed.
const CSS_CLASS_GRAB = "grab-to-pan-grab";

/**
* @typedef {Object} GrabToPanOptions
* @property {HTMLElement} element
*/

class GrabToPan {
/**
* Construct a GrabToPan instance for a given HTML element.
* @param {Element} options.element
* @param {GrabToPanOptions} options
*/
constructor({ element }) {
this.element = element;
Expand Down
2 changes: 2 additions & 0 deletions web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/** @typedef {import("./overlay_manager.js").OverlayManager} OverlayManager */

import { PasswordResponses } from "pdfjs-lib";

/**
Expand Down
9 changes: 7 additions & 2 deletions web/pdf_attachment_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
// eslint-disable-next-line max-len
/** @typedef {import("./download_manager.js").DownloadManager} DownloadManager */

import { BaseTreeViewer } from "./base_tree_viewer.js";
import { getFilenameFromUrl } from "pdfjs-lib";
import { waitOnEventOrTimeout } from "./event_utils.js";
Expand All @@ -27,6 +31,7 @@ import { waitOnEventOrTimeout } from "./event_utils.js";
/**
* @typedef {Object} PDFAttachmentViewerRenderParameters
* @property {Object|null} attachments - A lookup table of attachment objects.
* @property {boolean} [keepRenderedCapability]
*/

class PDFAttachmentViewer extends BaseTreeViewer {
Expand Down Expand Up @@ -56,7 +61,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
async _dispatchEvent(attachmentsCount) {
this._renderedCapability.resolve();
Expand Down Expand Up @@ -87,7 +92,7 @@ class PDFAttachmentViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_bindLink(element, { content, filename }) {
element.onclick = () => {
Expand Down
2 changes: 2 additions & 0 deletions web/pdf_cursor_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */

import { AnnotationEditorType, shadow } from "pdfjs-lib";
import { CursorTool, PresentationModeState } from "./ui_utils.js";
import { GrabToPan } from "./grab_to_pan.js";
Expand Down
5 changes: 5 additions & 0 deletions web/pdf_document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
/** @typedef {import("./interfaces.js").IL10n} IL10n */
/** @typedef {import("./overlay_manager.js").OverlayManager} OverlayManager */
/** @typedef {import("../src/display/api").PDFDocumentProxy} PDFDocumentProxy */

import { getPageSizeInches, isPortraitOrientation } from "./ui_utils.js";
import { PDFDateString } from "pdfjs-lib";

Expand Down
14 changes: 10 additions & 4 deletions web/pdf_layer_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
// eslint-disable-next-line max-len
/** @typedef {import("../src/optional_content_config.js").OptionalContentConfig} OptionalContentConfig */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/api.js").PDFDocumentProxy} PDFDocumentProxy */

import { BaseTreeViewer } from "./base_tree_viewer.js";

/**
Expand All @@ -25,7 +31,7 @@ import { BaseTreeViewer } from "./base_tree_viewer.js";
* @typedef {Object} PDFLayerViewerRenderParameters
* @property {OptionalContentConfig|null} optionalContentConfig - An
* {OptionalContentConfig} instance.
* @property {PDFDocument} pdfDocument - A {PDFDocument} instance.
* @property {PDFDocumentProxy} pdfDocument - A {PDFDocument} instance.
*/

class PDFLayerViewer extends BaseTreeViewer {
Expand All @@ -48,7 +54,7 @@ class PDFLayerViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_dispatchEvent(layersCount) {
this.eventBus.dispatch("layersloaded", {
Expand All @@ -58,7 +64,7 @@ class PDFLayerViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_bindLink(element, { groupId, input }) {
const setVisibility = () => {
Expand Down Expand Up @@ -97,7 +103,7 @@ class PDFLayerViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_addToggleButton(div, { name = null }) {
super._addToggleButton(div, /* hidden = */ name === null);
Expand Down
15 changes: 11 additions & 4 deletions web/pdf_outline_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
// eslint-disable-next-line max-len
/** @typedef {import("./download_manager.js").DownloadManager} DownloadManager */
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
// eslint-disable-next-line max-len
/** @typedef {import("../src/display/api.js").PDFDocumentProxy} PDFDocumentProxy */

import { BaseTreeViewer } from "./base_tree_viewer.js";
import { SidebarView } from "./ui_utils.js";

Expand All @@ -27,7 +34,7 @@ import { SidebarView } from "./ui_utils.js";
/**
* @typedef {Object} PDFOutlineViewerRenderParameters
* @property {Array|null} outline - An array of outline objects.
* @property {PDFDocument} pdfDocument - A {PDFDocument} instance.
* @property {PDFDocumentProxy} pdfDocument - A {PDFDocument} instance.
*/

class PDFOutlineViewer extends BaseTreeViewer {
Expand Down Expand Up @@ -75,7 +82,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_dispatchEvent(outlineCount) {
this._currentOutlineItemCapability = Promise.withResolvers();
Expand All @@ -98,7 +105,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_bindLink(
element,
Expand Down Expand Up @@ -162,7 +169,7 @@ class PDFOutlineViewer extends BaseTreeViewer {
}

/**
* @private
* @protected
*/
_addToggleButton(div, { count, items }) {
let hidden = false;
Expand Down
3 changes: 3 additions & 0 deletions web/pdf_presentation_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
/** @typedef {import("./pdf_viewer.js").PDFViewer} PDFViewer */

import {
normalizeWheelEventDelta,
PresentationModeState,
Expand Down
3 changes: 3 additions & 0 deletions web/pdf_print_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* limitations under the License.
*/

// eslint-disable-next-line max-len
/** @typedef {import("./interfaces.js").IPDFPrintServiceFactory} IPDFPrintServiceFactory */

import {
AnnotationMode,
PixelsPerInch,
Expand Down
3 changes: 3 additions & 0 deletions web/pdf_sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */
/** @typedef {import("./interfaces.js").IL10n} IL10n */

import {
docStyle,
PresentationModeState,
Expand Down
2 changes: 2 additions & 0 deletions web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */

import {
CursorTool,
ScrollMode,
Expand Down
2 changes: 2 additions & 0 deletions web/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* limitations under the License.
*/

/** @typedef {import("./event_utils.js").EventBus} EventBus */

import { AnnotationEditorType, ColorPicker, noContextMenu } from "pdfjs-lib";
import {
DEFAULT_SCALE,
Expand Down

0 comments on commit d5eb60d

Please sign in to comment.