Convert the PDFDocumentProxy class, in src/display/api.js, to ES6 syntax

Moreover, indicate that a member are private and improve the comments to
be more consistent.
This commit is contained in:
Tim van der Meij 2018-08-26 18:04:57 +02:00
parent d409c42068
commit 9c37599fd3
No known key found for this signature in database
GPG Key ID: 8C3FD2925A5F2762

View File

@ -577,92 +577,100 @@ var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
/** /**
* Proxy to a PDFDocument in the worker thread. Also, contains commonly used * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
* properties that can be read synchronously. * properties that can be read synchronously.
* @class
* @alias PDFDocumentProxy
*/ */
var PDFDocumentProxy = (function PDFDocumentProxyClosure() { class PDFDocumentProxy {
function PDFDocumentProxy(pdfInfo, transport, loadingTask) { constructor(pdfInfo, transport, loadingTask) {
this._pdfInfo = pdfInfo;
this.transport = transport;
this.loadingTask = loadingTask; this.loadingTask = loadingTask;
this._pdfInfo = pdfInfo;
this._transport = transport;
} }
PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
/** /**
* @return {number} Total number of pages the PDF contains. * @return {number} Total number of pages the PDF contains.
*/ */
get numPages() { get numPages() {
return this._pdfInfo.numPages; return this._pdfInfo.numPages;
}, }
/** /**
* @return {string} A unique ID to identify a PDF. Not guaranteed to be * @return {string} A (not guaranteed to be) unique ID to identify a PDF.
* unique.
*/ */
get fingerprint() { get fingerprint() {
return this._pdfInfo.fingerprint; return this._pdfInfo.fingerprint;
}, }
/** /**
* @param {number} pageNumber The page number to get. The first page is 1. * @param {number} pageNumber - The page number to get. The first page is 1.
* @return {Promise} A promise that is resolved with a {@link PDFPageProxy} * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
* object. * object.
*/ */
getPage(pageNumber) { getPage(pageNumber) {
return this.transport.getPage(pageNumber); return this._transport.getPage(pageNumber);
}, }
/** /**
* @param {{num: number, gen: number}} ref The page reference. Must have * @param {{num: number, gen: number}} ref - The page reference. Must have
* the 'num' and 'gen' properties. * the `num` and `gen` properties.
* @return {Promise} A promise that is resolved with the page index that is * @return {Promise} A promise that is resolved with the page index that is
* associated with the reference. * associated with the reference.
*/ */
getPageIndex: function PDFDocumentProxy_getPageIndex(ref) { getPageIndex(ref) {
return this.transport.getPageIndex(ref); return this._transport.getPageIndex(ref);
}, }
/** /**
* @return {Promise} A promise that is resolved with a lookup table for * @return {Promise} A promise that is resolved with a lookup table for
* mapping named destinations to reference numbers. * mapping named destinations to reference numbers.
* *
* This can be slow for large documents: use getDestination instead * This can be slow for large documents. Use `getDestination` instead.
*/ */
getDestinations: function PDFDocumentProxy_getDestinations() { getDestinations() {
return this.transport.getDestinations(); return this._transport.getDestinations();
}, }
/** /**
* @param {string} id - The named destination to get. * @param {string} id - The named destination to get.
* @return {Promise} A promise that is resolved with all information * @return {Promise} A promise that is resolved with all information
* of the given named destination. * of the given named destination.
*/ */
getDestination: function PDFDocumentProxy_getDestination(id) { getDestination(id) {
return this.transport.getDestination(id); return this._transport.getDestination(id);
}, }
/** /**
* @return {Promise} A promise that is resolved with: * @return {Promise} A promise that is resolved with an {Array} containing
* an Array containing the pageLabels that correspond to the pageIndexes, * the page labels that correspond to the page indexes, or `null` when
* or `null` when no pageLabels are present in the PDF file. * no page labels are present in the PDF file.
*/ */
getPageLabels: function PDFDocumentProxy_getPageLabels() { getPageLabels() {
return this.transport.getPageLabels(); return this._transport.getPageLabels();
}, }
/** /**
* @return {Promise} A promise that is resolved with a {string} containing * @return {Promise} A promise that is resolved with a {string} containing
* the PageMode name. * the page mode name.
*/ */
getPageMode() { getPageMode() {
return this.transport.getPageMode(); return this._transport.getPageMode();
}, }
/** /**
* @return {Promise} A promise that is resolved with a lookup table for * @return {Promise} A promise that is resolved with a lookup table for
* mapping named attachments to their content. * mapping named attachments to their content.
*/ */
getAttachments: function PDFDocumentProxy_getAttachments() { getAttachments() {
return this.transport.getAttachments(); return this._transport.getAttachments();
}, }
/** /**
* @return {Promise} A promise that is resolved with an {Array} of all the * @return {Promise} A promise that is resolved with an {Array} of all the
* JavaScript strings in the name tree, or `null` if no JavaScript exists. * JavaScript strings in the name tree, or `null` if no JavaScript exists.
*/ */
getJavaScript() { getJavaScript() {
return this.transport.getJavaScript(); return this._transport.getJavaScript();
}, }
/** /**
* @return {Promise} A promise that is resolved with an {Array} that is a * @return {Promise} A promise that is resolved with an {Array} that is a
* tree outline (if it has one) of the PDF. The tree is in the format of: * tree outline (if it has one) of the PDF. The tree is in the format of:
@ -677,54 +685,61 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* items: array of more items like this * items: array of more items like this
* }, * },
* ... * ...
* ]. * ]
*/ */
getOutline: function PDFDocumentProxy_getOutline() { getOutline() {
return this.transport.getOutline(); return this._transport.getOutline();
}, }
/** /**
* @return {Promise} A promise that is resolved with an {Object} that has * @return {Promise} A promise that is resolved with an {Object} that has
* info and metadata properties. Info is an {Object} filled with anything * `info` and `metadata` properties. `info` is an {Object} filled with
* available in the information dictionary and similarly metadata is a * anything available in the information dictionary and similarly
* {Metadata} object with information from the metadata section of the PDF. * `metadata` is a {Metadata} object with information from the metadata
* section of the PDF.
*/ */
getMetadata: function PDFDocumentProxy_getMetadata() { getMetadata() {
return this.transport.getMetadata(); return this._transport.getMetadata();
}, }
/** /**
* @return {Promise} A promise that is resolved with a TypedArray that has * @return {Promise} A promise that is resolved with a {TypedArray} that has
* the raw data from the PDF. * the raw data from the PDF.
*/ */
getData: function PDFDocumentProxy_getData() { getData() {
return this.transport.getData(); return this._transport.getData();
}, }
/** /**
* @return {Promise} A promise that is resolved when the document's data * @return {Promise} A promise that is resolved when the document's data
* is loaded. It is resolved with an {Object} that contains the length * is loaded. It is resolved with an {Object} that contains the `length`
* property that indicates size of the PDF data in bytes. * property that indicates size of the PDF data in bytes.
*/ */
getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() { getDownloadInfo() {
return this.transport.downloadInfoCapability.promise; return this._transport.downloadInfoCapability.promise;
}, }
/** /**
* @return {Promise} A promise this is resolved with current stats about * @return {Promise} A promise this is resolved with current statistics about
* document structures (see {@link PDFDocumentStats}). * document structures (see {@link PDFDocumentStats}).
*/ */
getStats: function PDFDocumentProxy_getStats() { getStats() {
return this.transport.getStats(); return this._transport.getStats();
}, }
/** /**
* Cleans up resources allocated by the document, e.g. created @font-face. * Cleans up resources allocated by the document, e.g. created `@font-face`.
*/ */
cleanup: function PDFDocumentProxy_cleanup() { cleanup() {
this.transport.startCleanup(); this._transport.startCleanup();
}, }
/** /**
* Destroys current document instance and terminates worker. * Destroys the current document instance and terminates the worker.
*/ */
destroy: function PDFDocumentProxy_destroy() { destroy() {
return this.loadingTask.destroy(); return this.loadingTask.destroy();
}, }
/** /**
* @return {Object} A subset of the current {DocumentInitParameters}, * @return {Object} A subset of the current {DocumentInitParameters},
@ -732,11 +747,9 @@ var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
* may be affected by the `apiCompatibilityParams`. * may be affected by the `apiCompatibilityParams`.
*/ */
get loadingParams() { get loadingParams() {
return this.transport.loadingParams; return this._transport.loadingParams;
}, }
}; }
return PDFDocumentProxy;
})();
/** /**
* Page getTextContent parameters. * Page getTextContent parameters.