Add typescript definitions

This PR adds typescript definitions from the JSDoc already present.
It adds a new gulp-target 'types' that calls 'tsc', the typescript
compiler, to create the definitions.

To use the definitions, users can simply do the following:

```
import {getDocument, GlobalWorkerOptions} from "pdfjs-dist";
import pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
GlobalWorkerOptions.workerSrc = pdfjsWorker;

const pdf = await getDocument("file:///some.pdf").promise;
```

Co-authored-by: @oBusk
Co-authored-by: @tamuratak
This commit is contained in:
Linus Gasser 2020-07-22 22:38:04 +02:00 committed by Linus Gasser
parent 6537e64cb8
commit f1bbfdc16d
12 changed files with 344 additions and 139 deletions

View file

@ -23,24 +23,35 @@ import {
* Text layer render parameters.
*
* @typedef {Object} TextLayerRenderParameters
* @property {TextContent} [textContent] - Text content to render (the object
* is returned by the page's `getTextContent` method).
* @property {import("./api").TextContent} [textContent] - Text content to
* render (the object is returned by the page's `getTextContent` method).
* @property {ReadableStream} [textContentStream] - Text content stream to
* render (the stream is returned by the page's `streamTextContent` method).
* @property {HTMLElement} container - HTML element that will contain text runs.
* @property {PageViewport} viewport - The target viewport to properly
* layout the text runs.
* @property {Array} [textDivs] - HTML elements that are correspond to the
* text items of the textContent input. This is output and shall be
* @property {import("./display_utils").PageViewport} viewport - The target
* viewport to properly layout the text runs.
* @property {Array<HTMLElement>} [textDivs] - HTML elements that are correspond
* to the text items of the textContent input. This is output and shall be
* initially be set to empty array.
* @property {Array} [textContentItemsStr] - Strings that correspond to the
* `str` property of the text items of textContent input. This is output
* @property {Array<string>} [textContentItemsStr] - Strings that correspond to
* the `str` property of the text items of textContent input. This is output
* and shall be initially be set to empty array.
* @property {number} [timeout] - Delay in milliseconds before rendering of the
* text runs occurs.
* @property {boolean} [enhanceTextSelection] - Whether to turn on the text
* selection enhancement.
*/
/**
* @typedef {Object} TextLayerRenderTask
* @property {Promise<void>} promise
* @property {() => void} cancel
* @property {(expandDivs: boolean) => void} expandTextDivs
*/
/**
* @type {(renderParameters: TextLayerRenderParameters) => TextLayerRenderTask}
*/
var renderTextLayer = (function renderTextLayerClosure() {
var MAX_TEXT_DIVS_TO_RENDER = 100000;
@ -728,12 +739,6 @@ var renderTextLayer = (function renderTextLayerClosure() {
},
};
/**
* Starts rendering of the text layer.
*
* @param {TextLayerRenderParameters} renderParameters
* @returns {TextLayerRenderTask}
*/
// eslint-disable-next-line no-shadow
function renderTextLayer(renderParameters) {
var task = new TextLayerRenderTask({