@vaadin-component-factory/vcf-pdf-viewer 3.0.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,6 +14,16 @@ import { parseQueryString } from './ui_utils.js';
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
+ const DEFAULT_LINK_REL = "noopener noreferrer nofollow";
18
+ const LinkTarget = {
19
+ NONE: 0,
20
+ // Default value.
21
+ SELF: 1,
22
+ BLANK: 2,
23
+ PARENT: 3,
24
+ TOP: 4
25
+ };
26
+
17
27
  /**
18
28
  * @typedef {Object} PDFLinkServiceOptions
19
29
  * @property {EventBus} eventBus - The application event bus.
@@ -32,8 +42,9 @@ import { parseQueryString } from './ui_utils.js';
32
42
  * or destination.
33
43
  * @implements {IPDFLinkService}
34
44
  */
35
-
36
45
  class PDFLinkService {
46
+ externalLinkEnabled = true;
47
+
37
48
  /**
38
49
  * @param {PDFLinkServiceOptions} options
39
50
  */
@@ -46,105 +57,111 @@ class PDFLinkService {
46
57
  this.eventBus = eventBus;
47
58
  this.externalLinkTarget = externalLinkTarget;
48
59
  this.externalLinkRel = externalLinkRel;
49
- this.externalLinkEnabled = true;
50
60
  this._ignoreDestinationZoom = ignoreDestinationZoom;
51
61
  this.baseUrl = null;
52
62
  this.pdfDocument = null;
53
63
  this.pdfViewer = null;
54
64
  this.pdfHistory = null;
55
- this._pagesRefCache = null;
56
65
  }
57
-
58
66
  setDocument(pdfDocument, baseUrl = null) {
59
67
  this.baseUrl = baseUrl;
60
68
  this.pdfDocument = pdfDocument;
61
- this._pagesRefCache = Object.create(null);
62
69
  }
63
-
64
70
  setViewer(pdfViewer) {
65
71
  this.pdfViewer = pdfViewer;
66
72
  }
67
-
68
73
  setHistory(pdfHistory) {
69
74
  this.pdfHistory = pdfHistory;
70
75
  }
76
+
71
77
  /**
72
78
  * @type {number}
73
79
  */
74
-
75
-
76
80
  get pagesCount() {
77
81
  return this.pdfDocument ? this.pdfDocument.numPages : 0;
78
82
  }
83
+
79
84
  /**
80
85
  * @type {number}
81
86
  */
82
-
83
-
84
87
  get page() {
85
- return this.pdfViewer.currentPageNumber;
88
+ return this.pdfDocument ? this.pdfViewer.currentPageNumber : 1;
86
89
  }
90
+
87
91
  /**
88
92
  * @param {number} value
89
93
  */
90
-
91
-
92
94
  set page(value) {
93
- this.pdfViewer.currentPageNumber = value;
95
+ if (this.pdfDocument) {
96
+ this.pdfViewer.currentPageNumber = value;
97
+ }
94
98
  }
99
+
95
100
  /**
96
101
  * @type {number}
97
102
  */
98
-
99
-
100
103
  get rotation() {
101
- return this.pdfViewer.pagesRotation;
104
+ return this.pdfDocument ? this.pdfViewer.pagesRotation : 0;
102
105
  }
106
+
103
107
  /**
104
108
  * @param {number} value
105
109
  */
106
-
107
-
108
110
  set rotation(value) {
109
- this.pdfViewer.pagesRotation = value;
111
+ if (this.pdfDocument) {
112
+ this.pdfViewer.pagesRotation = value;
113
+ }
110
114
  }
115
+
111
116
  /**
112
- * @private
117
+ * @type {boolean}
113
118
  */
119
+ get isInPresentationMode() {
120
+ return this.pdfDocument ? this.pdfViewer.isInPresentationMode : false;
121
+ }
114
122
 
115
-
116
- _goToDestinationHelper(rawDest, namedDest = null, explicitDest) {
123
+ /**
124
+ * This method will, when available, also update the browser history.
125
+ *
126
+ * @param {string|Array} dest - The named, or explicit, PDF destination.
127
+ */
128
+ async goToDestination(dest) {
129
+ if (!this.pdfDocument) {
130
+ return;
131
+ }
132
+ let namedDest, explicitDest, pageNumber;
133
+ if (typeof dest === "string") {
134
+ namedDest = dest;
135
+ explicitDest = await this.pdfDocument.getDestination(dest);
136
+ } else {
137
+ namedDest = null;
138
+ explicitDest = await dest;
139
+ }
140
+ if (!Array.isArray(explicitDest)) {
141
+ console.error(`goToDestination: "${explicitDest}" is not a valid destination array, for dest="${dest}".`);
142
+ return;
143
+ }
117
144
  // Dest array looks like that: <page-ref> </XYZ|/FitXXX> <args..>
118
- const destRef = explicitDest[0];
119
- let pageNumber;
120
-
121
- if (typeof destRef === "object" && destRef !== null) {
122
- pageNumber = this._cachedPageNumber(destRef);
123
-
124
- if (pageNumber === null) {
145
+ const [destRef] = explicitDest;
146
+ if (destRef && typeof destRef === "object") {
147
+ pageNumber = this.pdfDocument.cachedPageNumber(destRef);
148
+ if (!pageNumber) {
125
149
  // Fetch the page reference if it's not yet available. This could
126
150
  // only occur during loading, before all pages have been resolved.
127
- this.pdfDocument.getPageIndex(destRef).then(pageIndex => {
128
- this.cachePageRef(pageIndex + 1, destRef);
129
-
130
- this._goToDestinationHelper(rawDest, namedDest, explicitDest);
131
- }).catch(() => {
132
- console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid page reference, for dest="${rawDest}".`);
133
- });
134
- return;
151
+ try {
152
+ pageNumber = (await this.pdfDocument.getPageIndex(destRef)) + 1;
153
+ } catch {
154
+ console.error(`goToDestination: "${destRef}" is not a valid page reference, for dest="${dest}".`);
155
+ return;
156
+ }
135
157
  }
136
158
  } else if (Number.isInteger(destRef)) {
137
159
  pageNumber = destRef + 1;
138
- } else {
139
- console.error(`PDFLinkService._goToDestinationHelper: "${destRef}" is not ` + `a valid destination reference, for dest="${rawDest}".`);
140
- return;
141
160
  }
142
-
143
161
  if (!pageNumber || pageNumber < 1 || pageNumber > this.pagesCount) {
144
- console.error(`PDFLinkService._goToDestinationHelper: "${pageNumber}" is not ` + `a valid page number, for dest="${rawDest}".`);
162
+ console.error(`goToDestination: "${pageNumber}" is not a valid page number, for dest="${dest}".`);
145
163
  return;
146
164
  }
147
-
148
165
  if (this.pdfHistory) {
149
166
  // Update the browser history before scrolling the new destination into
150
167
  // view, to be able to accurately capture the current document position.
@@ -155,78 +172,82 @@ class PDFLinkService {
155
172
  pageNumber
156
173
  });
157
174
  }
158
-
159
175
  this.pdfViewer.scrollPageIntoView({
160
176
  pageNumber,
161
177
  destArray: explicitDest,
162
178
  ignoreDestinationZoom: this._ignoreDestinationZoom
163
179
  });
164
180
  }
165
- /**
166
- * This method will, when available, also update the browser history.
167
- *
168
- * @param {string|Array} dest - The named, or explicit, PDF destination.
169
- */
170
-
171
-
172
- async goToDestination(dest) {
173
- if (!this.pdfDocument) {
174
- return;
175
- }
176
-
177
- let namedDest, explicitDest;
178
-
179
- if (typeof dest === "string") {
180
- namedDest = dest;
181
- explicitDest = await this.pdfDocument.getDestination(dest);
182
- } else {
183
- namedDest = null;
184
- explicitDest = await dest;
185
- }
186
-
187
- if (!Array.isArray(explicitDest)) {
188
- console.error(`PDFLinkService.goToDestination: "${explicitDest}" is not ` + `a valid destination array, for dest="${dest}".`);
189
- return;
190
- }
191
181
 
192
- this._goToDestinationHelper(dest, namedDest, explicitDest);
193
- }
194
182
  /**
195
183
  * This method will, when available, also update the browser history.
196
184
  *
197
185
  * @param {number|string} val - The page number, or page label.
198
186
  */
199
-
200
-
201
187
  goToPage(val) {
202
188
  if (!this.pdfDocument) {
203
189
  return;
204
190
  }
205
-
206
191
  const pageNumber = typeof val === "string" && this.pdfViewer.pageLabelToPageNumber(val) || val | 0;
207
-
208
192
  if (!(Number.isInteger(pageNumber) && pageNumber > 0 && pageNumber <= this.pagesCount)) {
209
193
  console.error(`PDFLinkService.goToPage: "${val}" is not a valid page.`);
210
194
  return;
211
195
  }
212
-
213
196
  if (this.pdfHistory) {
214
197
  // Update the browser history before scrolling the new page into view,
215
198
  // to be able to accurately capture the current document position.
216
199
  this.pdfHistory.pushCurrentPosition();
217
200
  this.pdfHistory.pushPage(pageNumber);
218
201
  }
219
-
220
202
  this.pdfViewer.scrollPageIntoView({
221
203
  pageNumber
222
204
  });
223
205
  }
206
+
207
+ /**
208
+ * Adds various attributes (href, title, target, rel) to hyperlinks.
209
+ * @param {HTMLAnchorElement} link
210
+ * @param {string} url
211
+ * @param {boolean} [newWindow]
212
+ */
213
+ addLinkAttributes(link, url, newWindow = false) {
214
+ if (!url || typeof url !== "string") {
215
+ throw new Error('A valid "url" parameter must provided.');
216
+ }
217
+ const target = newWindow ? LinkTarget.BLANK : this.externalLinkTarget,
218
+ rel = this.externalLinkRel;
219
+ if (this.externalLinkEnabled) {
220
+ link.href = link.title = url;
221
+ } else {
222
+ link.href = "";
223
+ link.title = `Disabled: ${url}`;
224
+ link.onclick = () => false;
225
+ }
226
+ let targetStr = ""; // LinkTarget.NONE
227
+ switch (target) {
228
+ case LinkTarget.NONE:
229
+ break;
230
+ case LinkTarget.SELF:
231
+ targetStr = "_self";
232
+ break;
233
+ case LinkTarget.BLANK:
234
+ targetStr = "_blank";
235
+ break;
236
+ case LinkTarget.PARENT:
237
+ targetStr = "_parent";
238
+ break;
239
+ case LinkTarget.TOP:
240
+ targetStr = "_top";
241
+ break;
242
+ }
243
+ link.target = targetStr;
244
+ link.rel = typeof rel === "string" ? rel : DEFAULT_LINK_REL;
245
+ }
246
+
224
247
  /**
225
248
  * @param {string|Array} dest - The PDF destination object.
226
249
  * @returns {string} The hyperlink to the PDF object.
227
250
  */
228
-
229
-
230
251
  getDestinationHash(dest) {
231
252
  if (typeof dest === "string") {
232
253
  if (dest.length > 0) {
@@ -234,89 +255,76 @@ class PDFLinkService {
234
255
  }
235
256
  } else if (Array.isArray(dest)) {
236
257
  const str = JSON.stringify(dest);
237
-
238
258
  if (str.length > 0) {
239
259
  return this.getAnchorUrl("#" + escape(str));
240
260
  }
241
261
  }
242
-
243
262
  return this.getAnchorUrl("");
244
263
  }
264
+
245
265
  /**
246
266
  * Prefix the full url on anchor links to make sure that links are resolved
247
267
  * relative to the current URL instead of the one defined in <base href>.
248
268
  * @param {string} anchor - The anchor hash, including the #.
249
269
  * @returns {string} The hyperlink to the PDF object.
250
270
  */
251
-
252
-
253
271
  getAnchorUrl(anchor) {
254
- return (this.baseUrl || "") + anchor;
272
+ return this.baseUrl ? this.baseUrl + anchor : anchor;
255
273
  }
274
+
256
275
  /**
257
276
  * @param {string} hash
258
277
  */
259
-
260
-
261
278
  setHash(hash) {
262
279
  if (!this.pdfDocument) {
263
280
  return;
264
281
  }
265
-
266
282
  let pageNumber, dest;
267
-
268
283
  if (hash.includes("=")) {
269
284
  const params = parseQueryString(hash);
270
-
271
- if ("search" in params) {
285
+ if (params.has("search")) {
286
+ const query = params.get("search").replaceAll('"', ""),
287
+ phrase = params.get("phrase") === "true";
272
288
  this.eventBus.dispatch("findfromurlhash", {
273
289
  source: this,
274
- query: params.search.replace(/"/g, ""),
275
- phraseSearch: params.phrase === "true"
290
+ query: phrase ? query : query.match(/\S+/g)
276
291
  });
277
- } // borrowing syntax from "Parameters for Opening PDF Files"
278
-
279
-
280
- if ("page" in params) {
281
- pageNumber = params.page | 0 || 1;
282
292
  }
283
-
284
- if ("zoom" in params) {
293
+ // borrowing syntax from "Parameters for Opening PDF Files"
294
+ if (params.has("page")) {
295
+ pageNumber = params.get("page") | 0 || 1;
296
+ }
297
+ if (params.has("zoom")) {
285
298
  // Build the destination array.
286
- const zoomArgs = params.zoom.split(","); // scale,left,top
287
-
299
+ const zoomArgs = params.get("zoom").split(","); // scale,left,top
288
300
  const zoomArg = zoomArgs[0];
289
301
  const zoomArgNumber = parseFloat(zoomArg);
290
-
291
302
  if (!zoomArg.includes("Fit")) {
292
303
  // If the zoomArg is a number, it has to get divided by 100. If it's
293
304
  // a string, it should stay as it is.
294
305
  dest = [null, {
295
306
  name: "XYZ"
296
307
  }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null, zoomArgs.length > 2 ? zoomArgs[2] | 0 : null, zoomArgNumber ? zoomArgNumber / 100 : zoomArg];
297
- } else {
298
- if (zoomArg === "Fit" || zoomArg === "FitB") {
299
- dest = [null, {
300
- name: zoomArg
301
- }];
302
- } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
308
+ } else if (zoomArg === "Fit" || zoomArg === "FitB") {
309
+ dest = [null, {
310
+ name: zoomArg
311
+ }];
312
+ } else if (zoomArg === "FitH" || zoomArg === "FitBH" || zoomArg === "FitV" || zoomArg === "FitBV") {
313
+ dest = [null, {
314
+ name: zoomArg
315
+ }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
316
+ } else if (zoomArg === "FitR") {
317
+ if (zoomArgs.length !== 5) {
318
+ console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
319
+ } else {
303
320
  dest = [null, {
304
321
  name: zoomArg
305
- }, zoomArgs.length > 1 ? zoomArgs[1] | 0 : null];
306
- } else if (zoomArg === "FitR") {
307
- if (zoomArgs.length !== 5) {
308
- console.error('PDFLinkService.setHash: Not enough parameters for "FitR".');
309
- } else {
310
- dest = [null, {
311
- name: zoomArg
312
- }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
313
- }
314
- } else {
315
- console.error(`PDFLinkService.setHash: "${zoomArg}" is not ` + "a valid zoom value.");
322
+ }, zoomArgs[1] | 0, zoomArgs[2] | 0, zoomArgs[3] | 0, zoomArgs[4] | 0];
316
323
  }
324
+ } else {
325
+ console.error(`PDFLinkService.setHash: "${zoomArg}" is not a valid zoom value.`);
317
326
  }
318
327
  }
319
-
320
328
  if (dest) {
321
329
  this.pdfViewer.scrollPageIntoView({
322
330
  pageNumber: pageNumber || this.page,
@@ -326,313 +334,149 @@ class PDFLinkService {
326
334
  } else if (pageNumber) {
327
335
  this.page = pageNumber; // simple page
328
336
  }
329
-
330
- if ("pagemode" in params) {
337
+ if (params.has("pagemode")) {
331
338
  this.eventBus.dispatch("pagemode", {
332
339
  source: this,
333
- mode: params.pagemode
340
+ mode: params.get("pagemode")
334
341
  });
335
- } // Ensure that this parameter is *always* handled last, in order to
342
+ }
343
+ // Ensure that this parameter is *always* handled last, in order to
336
344
  // guarantee that it won't be overridden (e.g. by the "page" parameter).
337
-
338
-
339
- if ("nameddest" in params) {
340
- this.goToDestination(params.nameddest);
345
+ if (params.has("nameddest")) {
346
+ this.goToDestination(params.get("nameddest"));
341
347
  }
342
- } else {
343
- // Named (or explicit) destination.
344
- dest = unescape(hash);
345
-
346
- try {
347
- dest = JSON.parse(dest);
348
-
349
- if (!Array.isArray(dest)) {
350
- // Avoid incorrectly rejecting a valid named destination, such as
351
- // e.g. "4.3" or "true", because `JSON.parse` converted its type.
352
- dest = dest.toString();
353
- }
354
- } catch (ex) {}
355
-
356
- if (typeof dest === "string" || isValidExplicitDestination(dest)) {
357
- this.goToDestination(dest);
348
+ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
349
+ return;
350
+ }
351
+ // Support opening of PDF attachments in the Firefox PDF Viewer,
352
+ // which uses a couple of non-standard hash parameters; refer to
353
+ // `DownloadManager.openOrDownloadData` in the firefoxcom.js file.
354
+ if (!params.has("filename") || !params.has("filedest")) {
358
355
  return;
359
356
  }
357
+ hash = params.get("filedest");
358
+ }
360
359
 
361
- console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not ` + "a valid destination.");
360
+ // Named (or explicit) destination.
361
+ dest = unescape(hash);
362
+ try {
363
+ dest = JSON.parse(dest);
364
+ if (!Array.isArray(dest)) {
365
+ // Avoid incorrectly rejecting a valid named destination, such as
366
+ // e.g. "4.3" or "true", because `JSON.parse` converted its type.
367
+ dest = dest.toString();
368
+ }
369
+ } catch {}
370
+ if (typeof dest === "string" || PDFLinkService.#isValidExplicitDest(dest)) {
371
+ this.goToDestination(dest);
372
+ return;
362
373
  }
374
+ console.error(`PDFLinkService.setHash: "${unescape(hash)}" is not a valid destination.`);
363
375
  }
376
+
364
377
  /**
365
378
  * @param {string} action
366
379
  */
367
-
368
-
369
380
  executeNamedAction(action) {
381
+ var _this$pdfHistory, _this$pdfHistory2;
382
+ if (!this.pdfDocument) {
383
+ return;
384
+ }
370
385
  // See PDF reference, table 8.45 - Named action
371
386
  switch (action) {
372
387
  case "GoBack":
373
- if (this.pdfHistory) {
374
- this.pdfHistory.back();
375
- }
376
-
388
+ (_this$pdfHistory = this.pdfHistory) === null || _this$pdfHistory === void 0 ? void 0 : _this$pdfHistory.back();
377
389
  break;
378
-
379
390
  case "GoForward":
380
- if (this.pdfHistory) {
381
- this.pdfHistory.forward();
382
- }
383
-
391
+ (_this$pdfHistory2 = this.pdfHistory) === null || _this$pdfHistory2 === void 0 ? void 0 : _this$pdfHistory2.forward();
384
392
  break;
385
-
386
393
  case "NextPage":
387
394
  this.pdfViewer.nextPage();
388
395
  break;
389
-
390
396
  case "PrevPage":
391
397
  this.pdfViewer.previousPage();
392
398
  break;
393
-
394
399
  case "LastPage":
395
400
  this.page = this.pagesCount;
396
401
  break;
397
-
398
402
  case "FirstPage":
399
403
  this.page = 1;
400
404
  break;
401
405
  // No action according to spec
402
406
  }
403
-
404
407
  this.eventBus.dispatch("namedaction", {
405
408
  source: this,
406
409
  action
407
410
  });
408
411
  }
412
+
409
413
  /**
410
- * @param {number} pageNum - page number.
411
- * @param {Object} pageRef - reference to the page.
414
+ * @param {Object} action
412
415
  */
413
-
414
-
415
- cachePageRef(pageNum, pageRef) {
416
- if (!pageRef) {
416
+ async executeSetOCGState(action) {
417
+ if (!this.pdfDocument) {
417
418
  return;
418
419
  }
419
-
420
- const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
421
- this._pagesRefCache[refStr] = pageNum;
422
- }
423
- /**
424
- * @private
425
- */
426
-
427
-
428
- _cachedPageNumber(pageRef) {
429
- var _this$_pagesRefCache;
430
-
431
- const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
432
- return ((_this$_pagesRefCache = this._pagesRefCache) === null || _this$_pagesRefCache === void 0 ? void 0 : _this$_pagesRefCache[refStr]) || null;
433
- }
434
- /**
435
- * @param {number} pageNumber
436
- */
437
-
438
-
439
- isPageVisible(pageNumber) {
440
- return this.pdfViewer.isPageVisible(pageNumber);
441
- }
442
- /**
443
- * @param {number} pageNumber
444
- */
445
-
446
-
447
- isPageCached(pageNumber) {
448
- return this.pdfViewer.isPageCached(pageNumber);
449
- }
450
-
451
- }
452
-
453
- function isValidExplicitDestination(dest) {
454
- if (!Array.isArray(dest)) {
455
- return false;
456
- }
457
-
458
- const destLength = dest.length;
459
-
460
- if (destLength < 2) {
461
- return false;
462
- }
463
-
464
- const page = dest[0];
465
-
466
- if (!(typeof page === "object" && Number.isInteger(page.num) && Number.isInteger(page.gen)) && !(Number.isInteger(page) && page >= 0)) {
467
- return false;
468
- }
469
-
470
- const zoom = dest[1];
471
-
472
- if (!(typeof zoom === "object" && typeof zoom.name === "string")) {
473
- return false;
420
+ const pdfDocument = this.pdfDocument,
421
+ optionalContentConfig = await this.pdfViewer.optionalContentConfigPromise;
422
+ if (pdfDocument !== this.pdfDocument) {
423
+ return; // The document was closed while the optional content resolved.
424
+ }
425
+ optionalContentConfig.setOCGState(action);
426
+ this.pdfViewer.optionalContentConfigPromise = Promise.resolve(optionalContentConfig);
474
427
  }
475
-
476
- let allowNull = true;
477
-
478
- switch (zoom.name) {
479
- case "XYZ":
480
- if (destLength !== 5) {
481
- return false;
482
- }
483
-
484
- break;
485
-
486
- case "Fit":
487
- case "FitB":
488
- return destLength === 2;
489
-
490
- case "FitH":
491
- case "FitBH":
492
- case "FitV":
493
- case "FitBV":
494
- if (destLength !== 3) {
428
+ static #isValidExplicitDest(dest) {
429
+ if (!Array.isArray(dest) || dest.length < 2) {
430
+ return false;
431
+ }
432
+ const [page, zoom, ...args] = dest;
433
+ if (!(typeof page === "object" && Number.isInteger(page === null || page === void 0 ? void 0 : page.num) && Number.isInteger(page === null || page === void 0 ? void 0 : page.gen)) && !Number.isInteger(page)) {
434
+ return false;
435
+ }
436
+ if (!(typeof zoom === "object" && typeof (zoom === null || zoom === void 0 ? void 0 : zoom.name) === "string")) {
437
+ return false;
438
+ }
439
+ let allowNull = true;
440
+ switch (zoom.name) {
441
+ case "XYZ":
442
+ if (args.length !== 3) {
443
+ return false;
444
+ }
445
+ break;
446
+ case "Fit":
447
+ case "FitB":
448
+ return args.length === 0;
449
+ case "FitH":
450
+ case "FitBH":
451
+ case "FitV":
452
+ case "FitBV":
453
+ if (args.length !== 1) {
454
+ return false;
455
+ }
456
+ break;
457
+ case "FitR":
458
+ if (args.length !== 4) {
459
+ return false;
460
+ }
461
+ allowNull = false;
462
+ break;
463
+ default:
495
464
  return false;
496
- }
497
-
498
- break;
499
-
500
- case "FitR":
501
- if (destLength !== 6) {
465
+ }
466
+ for (const arg of args) {
467
+ if (!(typeof arg === "number" || allowNull && arg === null)) {
502
468
  return false;
503
469
  }
504
-
505
- allowNull = false;
506
- break;
507
-
508
- default:
509
- return false;
510
- }
511
-
512
- for (let i = 2; i < destLength; i++) {
513
- const param = dest[i];
514
-
515
- if (!(typeof param === "number" || allowNull && param === null)) {
516
- return false;
517
470
  }
471
+ return true;
518
472
  }
519
-
520
- return true;
521
473
  }
474
+
522
475
  /**
523
476
  * @implements {IPDFLinkService}
524
477
  */
525
-
526
-
527
- class SimpleLinkService {
528
- constructor() {
529
- this.externalLinkTarget = null;
530
- this.externalLinkRel = null;
531
- this.externalLinkEnabled = true;
532
- this._ignoreDestinationZoom = false;
533
- }
534
- /**
535
- * @type {number}
536
- */
537
-
538
-
539
- get pagesCount() {
540
- return 0;
541
- }
542
- /**
543
- * @type {number}
544
- */
545
-
546
-
547
- get page() {
548
- return 0;
549
- }
550
- /**
551
- * @param {number} value
552
- */
553
-
554
-
555
- set page(value) {}
556
- /**
557
- * @type {number}
558
- */
559
-
560
-
561
- get rotation() {
562
- return 0;
563
- }
564
- /**
565
- * @param {number} value
566
- */
567
-
568
-
569
- set rotation(value) {}
570
- /**
571
- * @param {string|Array} dest - The named, or explicit, PDF destination.
572
- */
573
-
574
-
575
- async goToDestination(dest) {}
576
- /**
577
- * @param {number|string} val - The page number, or page label.
578
- */
579
-
580
-
581
- goToPage(val) {}
582
- /**
583
- * @param dest - The PDF destination object.
584
- * @returns {string} The hyperlink to the PDF object.
585
- */
586
-
587
-
588
- getDestinationHash(dest) {
589
- return "#";
590
- }
591
- /**
592
- * @param hash - The PDF parameters/hash.
593
- * @returns {string} The hyperlink to the PDF object.
594
- */
595
-
596
-
597
- getAnchorUrl(hash) {
598
- return "#";
599
- }
600
- /**
601
- * @param {string} hash
602
- */
603
-
604
-
605
- setHash(hash) {}
606
- /**
607
- * @param {string} action
608
- */
609
-
610
-
611
- executeNamedAction(action) {}
612
- /**
613
- * @param {number} pageNum - page number.
614
- * @param {Object} pageRef - reference to the page.
615
- */
616
-
617
-
618
- cachePageRef(pageNum, pageRef) {}
619
- /**
620
- * @param {number} pageNumber
621
- */
622
-
623
-
624
- isPageVisible(pageNumber) {
625
- return true;
626
- }
627
- /**
628
- * @param {number} pageNumber
629
- */
630
-
631
-
632
- isPageCached(pageNumber) {
633
- return true;
634
- }
635
-
478
+ class SimpleLinkService extends PDFLinkService {
479
+ setDocument(pdfDocument, baseUrl = null) {}
636
480
  }
637
481
 
638
- export { PDFLinkService, SimpleLinkService };
482
+ export { LinkTarget, PDFLinkService, SimpleLinkService };