Improve the JSDocs for the PDFObjects class

Given that we expose `PDFObjects`-instances, via the `commonObjs` and `objs` properties, on the `PDFPageProxy`-instances this ought to help provide slightly better TypeScript definitions.
This commit is contained in:
Jonas Jenwald 2022-02-20 12:52:28 +01:00
parent f4712bc0ad
commit bad15894fc

View File

@ -91,7 +91,7 @@ const DefaultStandardFontDataFactory =
*/ */
/** /**
* @type IPDFStreamFactory * @type {IPDFStreamFactory}
* @private * @private
*/ */
let createPDFNetworkStream; let createPDFNetworkStream;
@ -1229,6 +1229,7 @@ class PDFPageProxy {
this._transport = transport; this._transport = transport;
this._stats = pdfBug ? new StatTimer() : null; this._stats = pdfBug ? new StatTimer() : null;
this._pdfBug = pdfBug; this._pdfBug = pdfBug;
/** @type {PDFObjects} */
this.commonObjs = transport.commonObjs; this.commonObjs = transport.commonObjs;
this.objs = new PDFObjects(); this.objs = new PDFObjects();
@ -3046,13 +3047,15 @@ class WorkerTransport {
* A PDF document and page is built of many objects. E.g. there are objects for * A PDF document and page is built of many objects. E.g. there are objects for
* fonts, images, rendering code, etc. These objects may get processed inside of * fonts, images, rendering code, etc. These objects may get processed inside of
* a worker. This class implements some basic methods to manage these objects. * a worker. This class implements some basic methods to manage these objects.
* @ignore
*/ */
class PDFObjects { class PDFObjects {
#objs = Object.create(null); #objs = Object.create(null);
/** /**
* Ensures there is an object defined for `objId`. * Ensures there is an object defined for `objId`.
*
* @param {string} objId
* @returns {Object}
*/ */
#ensureObj(objId) { #ensureObj(objId) {
const obj = this.#objs[objId]; const obj = this.#objs[objId];
@ -3072,6 +3075,10 @@ class PDFObjects {
* If called *with* a callback, the callback is called with the data of the * If called *with* a callback, the callback is called with the data of the
* object once the object is resolved. That means, if you call this method * object once the object is resolved. That means, if you call this method
* and the object is already resolved, the callback gets called right away. * and the object is already resolved, the callback gets called right away.
*
* @param {string} objId
* @param {function} [callback]
* @returns {any}
*/ */
get(objId, callback = null) { get(objId, callback = null) {
// If there is a callback, then the get can be async and the object is // If there is a callback, then the get can be async and the object is
@ -3092,6 +3099,10 @@ class PDFObjects {
return obj.data; return obj.data;
} }
/**
* @param {string} objId
* @returns {boolean}
*/
has(objId) { has(objId) {
const obj = this.#objs[objId]; const obj = this.#objs[objId];
return obj?.capability.settled || false; return obj?.capability.settled || false;
@ -3099,6 +3110,9 @@ class PDFObjects {
/** /**
* Resolves the object `objId` with optional `data`. * Resolves the object `objId` with optional `data`.
*
* @param {string} objId
* @param {any} [data]
*/ */
resolve(objId, data = null) { resolve(objId, data = null) {
const obj = this.#ensureObj(objId); const obj = this.#ensureObj(objId);