@vaadin-component-factory/vcf-pdf-viewer 3.1.0 → 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.
@@ -0,0 +1,1754 @@
1
+ import { u as unreachable, D as CMapCompressionType, U as Util, n as stringToBytes, K as BaseException, w as warn, F as FeatureTest, s as shadow, c as assert, M as MissingPDFException, v as UnexpectedResponseException, i as isNodeJS, m as AbortException } from './util.js';
2
+
3
+ /* Copyright 2015 Mozilla Foundation
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ class BaseFilterFactory {
18
+ constructor() {
19
+ if (this.constructor === BaseFilterFactory) {
20
+ unreachable("Cannot initialize BaseFilterFactory.");
21
+ }
22
+ }
23
+ addFilter(maps) {
24
+ return "none";
25
+ }
26
+ addHCMFilter(fgColor, bgColor) {
27
+ return "none";
28
+ }
29
+ addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
30
+ return "none";
31
+ }
32
+ destroy(keepHCM = false) {}
33
+ }
34
+ class BaseCanvasFactory {
35
+ constructor() {
36
+ if (this.constructor === BaseCanvasFactory) {
37
+ unreachable("Cannot initialize BaseCanvasFactory.");
38
+ }
39
+ }
40
+ create(width, height) {
41
+ if (width <= 0 || height <= 0) {
42
+ throw new Error("Invalid canvas size");
43
+ }
44
+ const canvas = this._createCanvas(width, height);
45
+ return {
46
+ canvas,
47
+ context: canvas.getContext("2d")
48
+ };
49
+ }
50
+ reset(canvasAndContext, width, height) {
51
+ if (!canvasAndContext.canvas) {
52
+ throw new Error("Canvas is not specified");
53
+ }
54
+ if (width <= 0 || height <= 0) {
55
+ throw new Error("Invalid canvas size");
56
+ }
57
+ canvasAndContext.canvas.width = width;
58
+ canvasAndContext.canvas.height = height;
59
+ }
60
+ destroy(canvasAndContext) {
61
+ if (!canvasAndContext.canvas) {
62
+ throw new Error("Canvas is not specified");
63
+ }
64
+ // Zeroing the width and height cause Firefox to release graphics
65
+ // resources immediately, which can greatly reduce memory consumption.
66
+ canvasAndContext.canvas.width = 0;
67
+ canvasAndContext.canvas.height = 0;
68
+ canvasAndContext.canvas = null;
69
+ canvasAndContext.context = null;
70
+ }
71
+
72
+ /**
73
+ * @ignore
74
+ */
75
+ _createCanvas(width, height) {
76
+ unreachable("Abstract method `_createCanvas` called.");
77
+ }
78
+ }
79
+ class BaseCMapReaderFactory {
80
+ constructor({
81
+ baseUrl = null,
82
+ isCompressed = true
83
+ }) {
84
+ if (this.constructor === BaseCMapReaderFactory) {
85
+ unreachable("Cannot initialize BaseCMapReaderFactory.");
86
+ }
87
+ this.baseUrl = baseUrl;
88
+ this.isCompressed = isCompressed;
89
+ }
90
+ async fetch({
91
+ name
92
+ }) {
93
+ if (!this.baseUrl) {
94
+ throw new Error('The CMap "baseUrl" parameter must be specified, ensure that ' + 'the "cMapUrl" and "cMapPacked" API parameters are provided.');
95
+ }
96
+ if (!name) {
97
+ throw new Error("CMap name must be specified.");
98
+ }
99
+ const url = this.baseUrl + name + (this.isCompressed ? ".bcmap" : "");
100
+ const compressionType = this.isCompressed ? CMapCompressionType.BINARY : CMapCompressionType.NONE;
101
+ return this._fetchData(url, compressionType).catch(reason => {
102
+ throw new Error(`Unable to load ${this.isCompressed ? "binary " : ""}CMap at: ${url}`);
103
+ });
104
+ }
105
+
106
+ /**
107
+ * @ignore
108
+ */
109
+ _fetchData(url, compressionType) {
110
+ unreachable("Abstract method `_fetchData` called.");
111
+ }
112
+ }
113
+ class BaseStandardFontDataFactory {
114
+ constructor({
115
+ baseUrl = null
116
+ }) {
117
+ if (this.constructor === BaseStandardFontDataFactory) {
118
+ unreachable("Cannot initialize BaseStandardFontDataFactory.");
119
+ }
120
+ this.baseUrl = baseUrl;
121
+ }
122
+ async fetch({
123
+ filename
124
+ }) {
125
+ if (!this.baseUrl) {
126
+ throw new Error('The standard font "baseUrl" parameter must be specified, ensure that ' + 'the "standardFontDataUrl" API parameter is provided.');
127
+ }
128
+ if (!filename) {
129
+ throw new Error("Font filename must be specified.");
130
+ }
131
+ const url = `${this.baseUrl}${filename}`;
132
+ return this._fetchData(url).catch(reason => {
133
+ throw new Error(`Unable to load font data at: ${url}`);
134
+ });
135
+ }
136
+
137
+ /**
138
+ * @ignore
139
+ */
140
+ _fetchData(url) {
141
+ unreachable("Abstract method `_fetchData` called.");
142
+ }
143
+ }
144
+ class BaseSVGFactory {
145
+ constructor() {
146
+ if (this.constructor === BaseSVGFactory) {
147
+ unreachable("Cannot initialize BaseSVGFactory.");
148
+ }
149
+ }
150
+ create(width, height, skipDimensions = false) {
151
+ if (width <= 0 || height <= 0) {
152
+ throw new Error("Invalid SVG dimensions");
153
+ }
154
+ const svg = this._createSVG("svg:svg");
155
+ svg.setAttribute("version", "1.1");
156
+ if (!skipDimensions) {
157
+ svg.setAttribute("width", `${width}px`);
158
+ svg.setAttribute("height", `${height}px`);
159
+ }
160
+ svg.setAttribute("preserveAspectRatio", "none");
161
+ svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
162
+ return svg;
163
+ }
164
+ createElement(type) {
165
+ if (typeof type !== "string") {
166
+ throw new Error("Invalid SVG element type");
167
+ }
168
+ return this._createSVG(type);
169
+ }
170
+
171
+ /**
172
+ * @ignore
173
+ */
174
+ _createSVG(type) {
175
+ unreachable("Abstract method `_createSVG` called.");
176
+ }
177
+ }
178
+
179
+ /* Copyright 2015 Mozilla Foundation
180
+ *
181
+ * Licensed under the Apache License, Version 2.0 (the "License");
182
+ * you may not use this file except in compliance with the License.
183
+ * You may obtain a copy of the License at
184
+ *
185
+ * http://www.apache.org/licenses/LICENSE-2.0
186
+ *
187
+ * Unless required by applicable law or agreed to in writing, software
188
+ * distributed under the License is distributed on an "AS IS" BASIS,
189
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ * See the License for the specific language governing permissions and
191
+ * limitations under the License.
192
+ */
193
+ const SVG_NS = "http://www.w3.org/2000/svg";
194
+ class PixelsPerInch {
195
+ static CSS = 96.0;
196
+ static PDF = 72.0;
197
+ static PDF_TO_CSS_UNITS = this.CSS / this.PDF;
198
+ }
199
+
200
+ /**
201
+ * FilterFactory aims to create some SVG filters we can use when drawing an
202
+ * image (or whatever) on a canvas.
203
+ * Filters aren't applied with ctx.putImageData because it just overwrites the
204
+ * underlying pixels.
205
+ * With these filters, it's possible for example to apply some transfer maps on
206
+ * an image without the need to apply them on the pixel arrays: the renderer
207
+ * does the magic for us.
208
+ */
209
+ class DOMFilterFactory extends BaseFilterFactory {
210
+ #_cache;
211
+ #_defs;
212
+ #docId;
213
+ #document;
214
+ #_hcmCache;
215
+ #id = 0;
216
+ constructor({
217
+ docId,
218
+ ownerDocument = globalThis.document
219
+ } = {}) {
220
+ super();
221
+ this.#docId = docId;
222
+ this.#document = ownerDocument;
223
+ }
224
+ get #cache() {
225
+ return this.#_cache || (this.#_cache = new Map());
226
+ }
227
+ get #hcmCache() {
228
+ return this.#_hcmCache || (this.#_hcmCache = new Map());
229
+ }
230
+ get #defs() {
231
+ if (!this.#_defs) {
232
+ const div = this.#document.createElement("div");
233
+ const {
234
+ style
235
+ } = div;
236
+ style.visibility = "hidden";
237
+ style.contain = "strict";
238
+ style.width = style.height = 0;
239
+ style.position = "absolute";
240
+ style.top = style.left = 0;
241
+ style.zIndex = -1;
242
+ const svg = this.#document.createElementNS(SVG_NS, "svg");
243
+ svg.setAttribute("width", 0);
244
+ svg.setAttribute("height", 0);
245
+ this.#_defs = this.#document.createElementNS(SVG_NS, "defs");
246
+ div.append(svg);
247
+ svg.append(this.#_defs);
248
+ this.#document.body.append(div);
249
+ }
250
+ return this.#_defs;
251
+ }
252
+ addFilter(maps) {
253
+ if (!maps) {
254
+ return "none";
255
+ }
256
+
257
+ // When a page is zoomed the page is re-drawn but the maps are likely
258
+ // the same.
259
+ let value = this.#cache.get(maps);
260
+ if (value) {
261
+ return value;
262
+ }
263
+ let tableR, tableG, tableB, key;
264
+ if (maps.length === 1) {
265
+ const mapR = maps[0];
266
+ const buffer = new Array(256);
267
+ for (let i = 0; i < 256; i++) {
268
+ buffer[i] = mapR[i] / 255;
269
+ }
270
+ key = tableR = tableG = tableB = buffer.join(",");
271
+ } else {
272
+ const [mapR, mapG, mapB] = maps;
273
+ const bufferR = new Array(256);
274
+ const bufferG = new Array(256);
275
+ const bufferB = new Array(256);
276
+ for (let i = 0; i < 256; i++) {
277
+ bufferR[i] = mapR[i] / 255;
278
+ bufferG[i] = mapG[i] / 255;
279
+ bufferB[i] = mapB[i] / 255;
280
+ }
281
+ tableR = bufferR.join(",");
282
+ tableG = bufferG.join(",");
283
+ tableB = bufferB.join(",");
284
+ key = `${tableR}${tableG}${tableB}`;
285
+ }
286
+ value = this.#cache.get(key);
287
+ if (value) {
288
+ this.#cache.set(maps, value);
289
+ return value;
290
+ }
291
+
292
+ // We create a SVG filter: feComponentTransferElement
293
+ // https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement
294
+
295
+ const id = `g_${this.#docId}_transfer_map_${this.#id++}`;
296
+ const url = `url(#${id})`;
297
+ this.#cache.set(maps, url);
298
+ this.#cache.set(key, url);
299
+ const filter = this.#createFilter(id);
300
+ this.#addTransferMapConversion(tableR, tableG, tableB, filter);
301
+ return url;
302
+ }
303
+ addHCMFilter(fgColor, bgColor) {
304
+ var _info;
305
+ const key = `${fgColor}-${bgColor}`;
306
+ const filterName = "base";
307
+ let info = this.#hcmCache.get(filterName);
308
+ if (((_info = info) === null || _info === void 0 ? void 0 : _info.key) === key) {
309
+ return info.url;
310
+ }
311
+ if (info) {
312
+ var _info$filter;
313
+ (_info$filter = info.filter) === null || _info$filter === void 0 ? void 0 : _info$filter.remove();
314
+ info.key = key;
315
+ info.url = "none";
316
+ info.filter = null;
317
+ } else {
318
+ info = {
319
+ key,
320
+ url: "none",
321
+ filter: null
322
+ };
323
+ this.#hcmCache.set(filterName, info);
324
+ }
325
+ if (!fgColor || !bgColor) {
326
+ return info.url;
327
+ }
328
+ const fgRGB = this.#getRGB(fgColor);
329
+ fgColor = Util.makeHexColor(...fgRGB);
330
+ const bgRGB = this.#getRGB(bgColor);
331
+ bgColor = Util.makeHexColor(...bgRGB);
332
+ this.#defs.style.color = "";
333
+ if (fgColor === "#000000" && bgColor === "#ffffff" || fgColor === bgColor) {
334
+ return info.url;
335
+ }
336
+
337
+ // https://developer.mozilla.org/en-US/docs/Web/Accessibility/Understanding_Colors_and_Luminance
338
+ //
339
+ // Relative luminance:
340
+ // https://www.w3.org/TR/WCAG20/#relativeluminancedef
341
+ //
342
+ // We compute the rounded luminance of the default background color.
343
+ // Then for every color in the pdf, if its rounded luminance is the
344
+ // same as the background one then it's replaced by the new
345
+ // background color else by the foreground one.
346
+ const map = new Array(256);
347
+ for (let i = 0; i <= 255; i++) {
348
+ const x = i / 255;
349
+ map[i] = x <= 0.03928 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
350
+ }
351
+ const table = map.join(",");
352
+ const id = `g_${this.#docId}_hcm_filter`;
353
+ const filter = info.filter = this.#createFilter(id);
354
+ this.#addTransferMapConversion(table, table, table, filter);
355
+ this.#addGrayConversion(filter);
356
+ const getSteps = (c, n) => {
357
+ const start = fgRGB[c] / 255;
358
+ const end = bgRGB[c] / 255;
359
+ const arr = new Array(n + 1);
360
+ for (let i = 0; i <= n; i++) {
361
+ arr[i] = start + i / n * (end - start);
362
+ }
363
+ return arr.join(",");
364
+ };
365
+ this.#addTransferMapConversion(getSteps(0, 5), getSteps(1, 5), getSteps(2, 5), filter);
366
+ info.url = `url(#${id})`;
367
+ return info.url;
368
+ }
369
+ addHighlightHCMFilter(filterName, fgColor, bgColor, newFgColor, newBgColor) {
370
+ var _info2;
371
+ const key = `${fgColor}-${bgColor}-${newFgColor}-${newBgColor}`;
372
+ let info = this.#hcmCache.get(filterName);
373
+ if (((_info2 = info) === null || _info2 === void 0 ? void 0 : _info2.key) === key) {
374
+ return info.url;
375
+ }
376
+ if (info) {
377
+ var _info$filter2;
378
+ (_info$filter2 = info.filter) === null || _info$filter2 === void 0 ? void 0 : _info$filter2.remove();
379
+ info.key = key;
380
+ info.url = "none";
381
+ info.filter = null;
382
+ } else {
383
+ info = {
384
+ key,
385
+ url: "none",
386
+ filter: null
387
+ };
388
+ this.#hcmCache.set(filterName, info);
389
+ }
390
+ if (!fgColor || !bgColor) {
391
+ return info.url;
392
+ }
393
+ const [fgRGB, bgRGB] = [fgColor, bgColor].map(this.#getRGB.bind(this));
394
+ let fgGray = Math.round(0.2126 * fgRGB[0] + 0.7152 * fgRGB[1] + 0.0722 * fgRGB[2]);
395
+ let bgGray = Math.round(0.2126 * bgRGB[0] + 0.7152 * bgRGB[1] + 0.0722 * bgRGB[2]);
396
+ let [newFgRGB, newBgRGB] = [newFgColor, newBgColor].map(this.#getRGB.bind(this));
397
+ if (bgGray < fgGray) {
398
+ [fgGray, bgGray, newFgRGB, newBgRGB] = [bgGray, fgGray, newBgRGB, newFgRGB];
399
+ }
400
+ this.#defs.style.color = "";
401
+
402
+ // Now we can create the filters to highlight some canvas parts.
403
+ // The colors in the pdf will almost be Canvas and CanvasText, hence we
404
+ // want to filter them to finally get Highlight and HighlightText.
405
+ // Since we're in HCM the background color and the foreground color should
406
+ // be really different when converted to grayscale (if they're not then it
407
+ // means that we've a poor contrast). Once the canvas colors are converted
408
+ // to grayscale we can easily map them on their new colors.
409
+ // The grayscale step is important because if we've something like:
410
+ // fgColor = #FF....
411
+ // bgColor = #FF....
412
+ // then we are enable to map the red component on the new red components
413
+ // which can be different.
414
+
415
+ const getSteps = (fg, bg, n) => {
416
+ const arr = new Array(256);
417
+ const step = (bgGray - fgGray) / n;
418
+ const newStart = fg / 255;
419
+ const newStep = (bg - fg) / (255 * n);
420
+ let prev = 0;
421
+ for (let i = 0; i <= n; i++) {
422
+ const k = Math.round(fgGray + i * step);
423
+ const value = newStart + i * newStep;
424
+ for (let j = prev; j <= k; j++) {
425
+ arr[j] = value;
426
+ }
427
+ prev = k + 1;
428
+ }
429
+ for (let i = prev; i < 256; i++) {
430
+ arr[i] = arr[prev - 1];
431
+ }
432
+ return arr.join(",");
433
+ };
434
+ const id = `g_${this.#docId}_hcm_${filterName}_filter`;
435
+ const filter = info.filter = this.#createFilter(id);
436
+ this.#addGrayConversion(filter);
437
+ this.#addTransferMapConversion(getSteps(newFgRGB[0], newBgRGB[0], 5), getSteps(newFgRGB[1], newBgRGB[1], 5), getSteps(newFgRGB[2], newBgRGB[2], 5), filter);
438
+ info.url = `url(#${id})`;
439
+ return info.url;
440
+ }
441
+ destroy(keepHCM = false) {
442
+ if (keepHCM && this.#hcmCache.size !== 0) {
443
+ return;
444
+ }
445
+ if (this.#_defs) {
446
+ this.#_defs.parentNode.parentNode.remove();
447
+ this.#_defs = null;
448
+ }
449
+ if (this.#_cache) {
450
+ this.#_cache.clear();
451
+ this.#_cache = null;
452
+ }
453
+ this.#id = 0;
454
+ }
455
+ #addGrayConversion(filter) {
456
+ const feColorMatrix = this.#document.createElementNS(SVG_NS, "feColorMatrix");
457
+ feColorMatrix.setAttribute("type", "matrix");
458
+ feColorMatrix.setAttribute("values", "0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0");
459
+ filter.append(feColorMatrix);
460
+ }
461
+ #createFilter(id) {
462
+ const filter = this.#document.createElementNS(SVG_NS, "filter");
463
+ filter.setAttribute("color-interpolation-filters", "sRGB");
464
+ filter.setAttribute("id", id);
465
+ this.#defs.append(filter);
466
+ return filter;
467
+ }
468
+ #appendFeFunc(feComponentTransfer, func, table) {
469
+ const feFunc = this.#document.createElementNS(SVG_NS, func);
470
+ feFunc.setAttribute("type", "discrete");
471
+ feFunc.setAttribute("tableValues", table);
472
+ feComponentTransfer.append(feFunc);
473
+ }
474
+ #addTransferMapConversion(rTable, gTable, bTable, filter) {
475
+ const feComponentTransfer = this.#document.createElementNS(SVG_NS, "feComponentTransfer");
476
+ filter.append(feComponentTransfer);
477
+ this.#appendFeFunc(feComponentTransfer, "feFuncR", rTable);
478
+ this.#appendFeFunc(feComponentTransfer, "feFuncG", gTable);
479
+ this.#appendFeFunc(feComponentTransfer, "feFuncB", bTable);
480
+ }
481
+ #getRGB(color) {
482
+ this.#defs.style.color = color;
483
+ return getRGB(getComputedStyle(this.#defs).getPropertyValue("color"));
484
+ }
485
+ }
486
+ class DOMCanvasFactory extends BaseCanvasFactory {
487
+ constructor({
488
+ ownerDocument = globalThis.document
489
+ } = {}) {
490
+ super();
491
+ this._document = ownerDocument;
492
+ }
493
+
494
+ /**
495
+ * @ignore
496
+ */
497
+ _createCanvas(width, height) {
498
+ const canvas = this._document.createElement("canvas");
499
+ canvas.width = width;
500
+ canvas.height = height;
501
+ return canvas;
502
+ }
503
+ }
504
+ async function fetchData(url, type = "text") {
505
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || isValidFetchUrl(url, document.baseURI)) {
506
+ const response = await fetch(url);
507
+ if (!response.ok) {
508
+ throw new Error(response.statusText);
509
+ }
510
+ switch (type) {
511
+ case "arraybuffer":
512
+ return response.arrayBuffer();
513
+ case "blob":
514
+ return response.blob();
515
+ case "json":
516
+ return response.json();
517
+ }
518
+ return response.text();
519
+ }
520
+
521
+ // The Fetch API is not supported.
522
+ return new Promise((resolve, reject) => {
523
+ const request = new XMLHttpRequest();
524
+ request.open("GET", url, /* async = */true);
525
+ request.responseType = type;
526
+ request.onreadystatechange = () => {
527
+ if (request.readyState !== XMLHttpRequest.DONE) {
528
+ return;
529
+ }
530
+ if (request.status === 200 || request.status === 0) {
531
+ switch (type) {
532
+ case "arraybuffer":
533
+ case "blob":
534
+ case "json":
535
+ resolve(request.response);
536
+ return;
537
+ }
538
+ resolve(request.responseText);
539
+ return;
540
+ }
541
+ reject(new Error(request.statusText));
542
+ };
543
+ request.send(null);
544
+ });
545
+ }
546
+ class DOMCMapReaderFactory extends BaseCMapReaderFactory {
547
+ /**
548
+ * @ignore
549
+ */
550
+ _fetchData(url, compressionType) {
551
+ return fetchData(url, /* type = */this.isCompressed ? "arraybuffer" : "text").then(data => ({
552
+ cMapData: data instanceof ArrayBuffer ? new Uint8Array(data) : stringToBytes(data),
553
+ compressionType
554
+ }));
555
+ }
556
+ }
557
+ class DOMStandardFontDataFactory extends BaseStandardFontDataFactory {
558
+ /**
559
+ * @ignore
560
+ */
561
+ _fetchData(url) {
562
+ return fetchData(url, /* type = */"arraybuffer").then(data => new Uint8Array(data));
563
+ }
564
+ }
565
+ class DOMSVGFactory extends BaseSVGFactory {
566
+ /**
567
+ * @ignore
568
+ */
569
+ _createSVG(type) {
570
+ return document.createElementNS(SVG_NS, type);
571
+ }
572
+ }
573
+
574
+ /**
575
+ * @typedef {Object} PageViewportParameters
576
+ * @property {Array<number>} viewBox - The xMin, yMin, xMax and
577
+ * yMax coordinates.
578
+ * @property {number} scale - The scale of the viewport.
579
+ * @property {number} rotation - The rotation, in degrees, of the viewport.
580
+ * @property {number} [offsetX] - The horizontal, i.e. x-axis, offset. The
581
+ * default value is `0`.
582
+ * @property {number} [offsetY] - The vertical, i.e. y-axis, offset. The
583
+ * default value is `0`.
584
+ * @property {boolean} [dontFlip] - If true, the y-axis will not be flipped.
585
+ * The default value is `false`.
586
+ */
587
+
588
+ /**
589
+ * @typedef {Object} PageViewportCloneParameters
590
+ * @property {number} [scale] - The scale, overriding the one in the cloned
591
+ * viewport. The default value is `this.scale`.
592
+ * @property {number} [rotation] - The rotation, in degrees, overriding the one
593
+ * in the cloned viewport. The default value is `this.rotation`.
594
+ * @property {number} [offsetX] - The horizontal, i.e. x-axis, offset.
595
+ * The default value is `this.offsetX`.
596
+ * @property {number} [offsetY] - The vertical, i.e. y-axis, offset.
597
+ * The default value is `this.offsetY`.
598
+ * @property {boolean} [dontFlip] - If true, the x-axis will not be flipped.
599
+ * The default value is `false`.
600
+ */
601
+
602
+ /**
603
+ * PDF page viewport created based on scale, rotation and offset.
604
+ */
605
+ class PageViewport {
606
+ /**
607
+ * @param {PageViewportParameters}
608
+ */
609
+ constructor({
610
+ viewBox,
611
+ scale,
612
+ rotation,
613
+ offsetX = 0,
614
+ offsetY = 0,
615
+ dontFlip = false
616
+ }) {
617
+ this.viewBox = viewBox;
618
+ this.scale = scale;
619
+ this.rotation = rotation;
620
+ this.offsetX = offsetX;
621
+ this.offsetY = offsetY;
622
+
623
+ // creating transform to convert pdf coordinate system to the normal
624
+ // canvas like coordinates taking in account scale and rotation
625
+ const centerX = (viewBox[2] + viewBox[0]) / 2;
626
+ const centerY = (viewBox[3] + viewBox[1]) / 2;
627
+ let rotateA, rotateB, rotateC, rotateD;
628
+ // Normalize the rotation, by clamping it to the [0, 360) range.
629
+ rotation %= 360;
630
+ if (rotation < 0) {
631
+ rotation += 360;
632
+ }
633
+ switch (rotation) {
634
+ case 180:
635
+ rotateA = -1;
636
+ rotateB = 0;
637
+ rotateC = 0;
638
+ rotateD = 1;
639
+ break;
640
+ case 90:
641
+ rotateA = 0;
642
+ rotateB = 1;
643
+ rotateC = 1;
644
+ rotateD = 0;
645
+ break;
646
+ case 270:
647
+ rotateA = 0;
648
+ rotateB = -1;
649
+ rotateC = -1;
650
+ rotateD = 0;
651
+ break;
652
+ case 0:
653
+ rotateA = 1;
654
+ rotateB = 0;
655
+ rotateC = 0;
656
+ rotateD = -1;
657
+ break;
658
+ default:
659
+ throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.");
660
+ }
661
+ if (dontFlip) {
662
+ rotateC = -rotateC;
663
+ rotateD = -rotateD;
664
+ }
665
+ let offsetCanvasX, offsetCanvasY;
666
+ let width, height;
667
+ if (rotateA === 0) {
668
+ offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
669
+ offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
670
+ width = (viewBox[3] - viewBox[1]) * scale;
671
+ height = (viewBox[2] - viewBox[0]) * scale;
672
+ } else {
673
+ offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
674
+ offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
675
+ width = (viewBox[2] - viewBox[0]) * scale;
676
+ height = (viewBox[3] - viewBox[1]) * scale;
677
+ }
678
+ // creating transform for the following operations:
679
+ // translate(-centerX, -centerY), rotate and flip vertically,
680
+ // scale, and translate(offsetCanvasX, offsetCanvasY)
681
+ this.transform = [rotateA * scale, rotateB * scale, rotateC * scale, rotateD * scale, offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY, offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY];
682
+ this.width = width;
683
+ this.height = height;
684
+ }
685
+
686
+ /**
687
+ * The original, un-scaled, viewport dimensions.
688
+ * @type {Object}
689
+ */
690
+ get rawDims() {
691
+ const {
692
+ viewBox
693
+ } = this;
694
+ return shadow(this, "rawDims", {
695
+ pageWidth: viewBox[2] - viewBox[0],
696
+ pageHeight: viewBox[3] - viewBox[1],
697
+ pageX: viewBox[0],
698
+ pageY: viewBox[1]
699
+ });
700
+ }
701
+
702
+ /**
703
+ * Clones viewport, with optional additional properties.
704
+ * @param {PageViewportCloneParameters} [params]
705
+ * @returns {PageViewport} Cloned viewport.
706
+ */
707
+ clone({
708
+ scale = this.scale,
709
+ rotation = this.rotation,
710
+ offsetX = this.offsetX,
711
+ offsetY = this.offsetY,
712
+ dontFlip = false
713
+ } = {}) {
714
+ return new PageViewport({
715
+ viewBox: this.viewBox.slice(),
716
+ scale,
717
+ rotation,
718
+ offsetX,
719
+ offsetY,
720
+ dontFlip
721
+ });
722
+ }
723
+
724
+ /**
725
+ * Converts PDF point to the viewport coordinates. For examples, useful for
726
+ * converting PDF location into canvas pixel coordinates.
727
+ * @param {number} x - The x-coordinate.
728
+ * @param {number} y - The y-coordinate.
729
+ * @returns {Array} Array containing `x`- and `y`-coordinates of the
730
+ * point in the viewport coordinate space.
731
+ * @see {@link convertToPdfPoint}
732
+ * @see {@link convertToViewportRectangle}
733
+ */
734
+ convertToViewportPoint(x, y) {
735
+ return Util.applyTransform([x, y], this.transform);
736
+ }
737
+
738
+ /**
739
+ * Converts PDF rectangle to the viewport coordinates.
740
+ * @param {Array} rect - The xMin, yMin, xMax and yMax coordinates.
741
+ * @returns {Array} Array containing corresponding coordinates of the
742
+ * rectangle in the viewport coordinate space.
743
+ * @see {@link convertToViewportPoint}
744
+ */
745
+ convertToViewportRectangle(rect) {
746
+ const topLeft = Util.applyTransform([rect[0], rect[1]], this.transform);
747
+ const bottomRight = Util.applyTransform([rect[2], rect[3]], this.transform);
748
+ return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
749
+ }
750
+
751
+ /**
752
+ * Converts viewport coordinates to the PDF location. For examples, useful
753
+ * for converting canvas pixel location into PDF one.
754
+ * @param {number} x - The x-coordinate.
755
+ * @param {number} y - The y-coordinate.
756
+ * @returns {Array} Array containing `x`- and `y`-coordinates of the
757
+ * point in the PDF coordinate space.
758
+ * @see {@link convertToViewportPoint}
759
+ */
760
+ convertToPdfPoint(x, y) {
761
+ return Util.applyInverseTransform([x, y], this.transform);
762
+ }
763
+ }
764
+ class RenderingCancelledException extends BaseException {
765
+ constructor(msg, extraDelay = 0) {
766
+ super(msg, "RenderingCancelledException");
767
+ this.extraDelay = extraDelay;
768
+ }
769
+ }
770
+ function isDataScheme(url) {
771
+ const ii = url.length;
772
+ let i = 0;
773
+ while (i < ii && url[i].trim() === "") {
774
+ i++;
775
+ }
776
+ return url.substring(i, i + 5).toLowerCase() === "data:";
777
+ }
778
+ function isPdfFile(filename) {
779
+ return typeof filename === "string" && /\.pdf$/i.test(filename);
780
+ }
781
+
782
+ /**
783
+ * Gets the filename from a given URL.
784
+ * @param {string} url
785
+ * @param {boolean} [onlyStripPath]
786
+ * @returns {string}
787
+ */
788
+ function getFilenameFromUrl(url, onlyStripPath = false) {
789
+ if (!onlyStripPath) {
790
+ [url] = url.split(/[#?]/, 1);
791
+ }
792
+ return url.substring(url.lastIndexOf("/") + 1);
793
+ }
794
+
795
+ /**
796
+ * Returns the filename or guessed filename from the url (see issue 3455).
797
+ * @param {string} url - The original PDF location.
798
+ * @param {string} defaultFilename - The value returned if the filename is
799
+ * unknown, or the protocol is unsupported.
800
+ * @returns {string} Guessed PDF filename.
801
+ */
802
+ function getPdfFilenameFromUrl(url, defaultFilename = "document.pdf") {
803
+ if (typeof url !== "string") {
804
+ return defaultFilename;
805
+ }
806
+ if (isDataScheme(url)) {
807
+ warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');
808
+ return defaultFilename;
809
+ }
810
+ const reURI = /^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/;
811
+ // SCHEME HOST 1.PATH 2.QUERY 3.REF
812
+ // Pattern to get last matching NAME.pdf
813
+ const reFilename = /[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i;
814
+ const splitURI = reURI.exec(url);
815
+ let suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3]);
816
+ if (suggestedFilename) {
817
+ suggestedFilename = suggestedFilename[0];
818
+ if (suggestedFilename.includes("%")) {
819
+ // URL-encoded %2Fpath%2Fto%2Ffile.pdf should be file.pdf
820
+ try {
821
+ suggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0];
822
+ } catch {
823
+ // Possible (extremely rare) errors:
824
+ // URIError "Malformed URI", e.g. for "%AA.pdf"
825
+ // TypeError "null has no properties", e.g. for "%2F.pdf"
826
+ }
827
+ }
828
+ }
829
+ return suggestedFilename || defaultFilename;
830
+ }
831
+ class StatTimer {
832
+ started = Object.create(null);
833
+ times = [];
834
+ time(name) {
835
+ if (name in this.started) {
836
+ warn(`Timer is already running for ${name}`);
837
+ }
838
+ this.started[name] = Date.now();
839
+ }
840
+ timeEnd(name) {
841
+ if (!(name in this.started)) {
842
+ warn(`Timer has not been started for ${name}`);
843
+ }
844
+ this.times.push({
845
+ name,
846
+ start: this.started[name],
847
+ end: Date.now()
848
+ });
849
+ // Remove timer from started so it can be called again.
850
+ delete this.started[name];
851
+ }
852
+ toString() {
853
+ // Find the longest name for padding purposes.
854
+ const outBuf = [];
855
+ let longest = 0;
856
+ for (const {
857
+ name
858
+ } of this.times) {
859
+ longest = Math.max(name.length, longest);
860
+ }
861
+ for (const {
862
+ name,
863
+ start,
864
+ end
865
+ } of this.times) {
866
+ outBuf.push(`${name.padEnd(longest)} ${end - start}ms\n`);
867
+ }
868
+ return outBuf.join("");
869
+ }
870
+ }
871
+ function isValidFetchUrl(url, baseUrl) {
872
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
873
+ throw new Error("Not implemented: isValidFetchUrl");
874
+ }
875
+ try {
876
+ const {
877
+ protocol
878
+ } = baseUrl ? new URL(url, baseUrl) : new URL(url);
879
+ // The Fetch API only supports the http/https protocols, and not file/ftp.
880
+ return protocol === "http:" || protocol === "https:";
881
+ } catch {
882
+ return false; // `new URL()` will throw on incorrect data.
883
+ }
884
+ }
885
+
886
+ /**
887
+ * Event handler to suppress context menu.
888
+ */
889
+ function noContextMenu(e) {
890
+ e.preventDefault();
891
+ }
892
+ let pdfDateStringRegex;
893
+ class PDFDateString {
894
+ /**
895
+ * Convert a PDF date string to a JavaScript `Date` object.
896
+ *
897
+ * The PDF date string format is described in section 7.9.4 of the official
898
+ * PDF 32000-1:2008 specification. However, in the PDF 1.7 reference (sixth
899
+ * edition) Adobe describes the same format including a trailing apostrophe.
900
+ * This syntax in incorrect, but Adobe Acrobat creates PDF files that contain
901
+ * them. We ignore all apostrophes as they are not necessary for date parsing.
902
+ *
903
+ * Moreover, Adobe Acrobat doesn't handle changing the date to universal time
904
+ * and doesn't use the user's time zone (effectively ignoring the HH' and mm'
905
+ * parts of the date string).
906
+ *
907
+ * @param {string} input
908
+ * @returns {Date|null}
909
+ */
910
+ static toDateObject(input) {
911
+ if (!input || typeof input !== "string") {
912
+ return null;
913
+ }
914
+
915
+ // Lazily initialize the regular expression.
916
+ pdfDateStringRegex || (pdfDateStringRegex = new RegExp("^D:" +
917
+ // Prefix (required)
918
+ "(\\d{4})" +
919
+ // Year (required)
920
+ "(\\d{2})?" +
921
+ // Month (optional)
922
+ "(\\d{2})?" +
923
+ // Day (optional)
924
+ "(\\d{2})?" +
925
+ // Hour (optional)
926
+ "(\\d{2})?" +
927
+ // Minute (optional)
928
+ "(\\d{2})?" +
929
+ // Second (optional)
930
+ "([Z|+|-])?" +
931
+ // Universal time relation (optional)
932
+ "(\\d{2})?" +
933
+ // Offset hour (optional)
934
+ "'?" +
935
+ // Splitting apostrophe (optional)
936
+ "(\\d{2})?" +
937
+ // Offset minute (optional)
938
+ "'?" // Trailing apostrophe (optional)
939
+ ));
940
+
941
+ // Optional fields that don't satisfy the requirements from the regular
942
+ // expression (such as incorrect digit counts or numbers that are out of
943
+ // range) will fall back the defaults from the specification.
944
+ const matches = pdfDateStringRegex.exec(input);
945
+ if (!matches) {
946
+ return null;
947
+ }
948
+
949
+ // JavaScript's `Date` object expects the month to be between 0 and 11
950
+ // instead of 1 and 12, so we have to correct for that.
951
+ const year = parseInt(matches[1], 10);
952
+ let month = parseInt(matches[2], 10);
953
+ month = month >= 1 && month <= 12 ? month - 1 : 0;
954
+ let day = parseInt(matches[3], 10);
955
+ day = day >= 1 && day <= 31 ? day : 1;
956
+ let hour = parseInt(matches[4], 10);
957
+ hour = hour >= 0 && hour <= 23 ? hour : 0;
958
+ let minute = parseInt(matches[5], 10);
959
+ minute = minute >= 0 && minute <= 59 ? minute : 0;
960
+ let second = parseInt(matches[6], 10);
961
+ second = second >= 0 && second <= 59 ? second : 0;
962
+ const universalTimeRelation = matches[7] || "Z";
963
+ let offsetHour = parseInt(matches[8], 10);
964
+ offsetHour = offsetHour >= 0 && offsetHour <= 23 ? offsetHour : 0;
965
+ let offsetMinute = parseInt(matches[9], 10) || 0;
966
+ offsetMinute = offsetMinute >= 0 && offsetMinute <= 59 ? offsetMinute : 0;
967
+
968
+ // Universal time relation 'Z' means that the local time is equal to the
969
+ // universal time, whereas the relations '+'/'-' indicate that the local
970
+ // time is later respectively earlier than the universal time. Every date
971
+ // is normalized to universal time.
972
+ if (universalTimeRelation === "-") {
973
+ hour += offsetHour;
974
+ minute += offsetMinute;
975
+ } else if (universalTimeRelation === "+") {
976
+ hour -= offsetHour;
977
+ minute -= offsetMinute;
978
+ }
979
+ return new Date(Date.UTC(year, month, day, hour, minute, second));
980
+ }
981
+ }
982
+
983
+ /**
984
+ * NOTE: This is (mostly) intended to support printing of XFA forms.
985
+ */
986
+ function getXfaPageViewport(xfaPage, {
987
+ scale = 1,
988
+ rotation = 0
989
+ }) {
990
+ const {
991
+ width,
992
+ height
993
+ } = xfaPage.attributes.style;
994
+ const viewBox = [0, 0, parseInt(width), parseInt(height)];
995
+ return new PageViewport({
996
+ viewBox,
997
+ scale,
998
+ rotation
999
+ });
1000
+ }
1001
+ function getRGB(color) {
1002
+ if (color.startsWith("#")) {
1003
+ const colorRGB = parseInt(color.slice(1), 16);
1004
+ return [(colorRGB & 0xff0000) >> 16, (colorRGB & 0x00ff00) >> 8, colorRGB & 0x0000ff];
1005
+ }
1006
+ if (color.startsWith("rgb(")) {
1007
+ // getComputedStyle(...).color returns a `rgb(R, G, B)` color.
1008
+ return color.slice(/* "rgb(".length */4, -1) // Strip out "rgb(" and ")".
1009
+ .split(",").map(x => parseInt(x));
1010
+ }
1011
+ if (color.startsWith("rgba(")) {
1012
+ return color.slice(/* "rgba(".length */5, -1) // Strip out "rgba(" and ")".
1013
+ .split(",").map(x => parseInt(x)).slice(0, 3);
1014
+ }
1015
+ warn(`Not a valid color format: "${color}"`);
1016
+ return [0, 0, 0];
1017
+ }
1018
+ function getColorValues(colors) {
1019
+ const span = document.createElement("span");
1020
+ span.style.visibility = "hidden";
1021
+ document.body.append(span);
1022
+ for (const name of colors.keys()) {
1023
+ span.style.color = name;
1024
+ const computedColor = window.getComputedStyle(span).color;
1025
+ colors.set(name, getRGB(computedColor));
1026
+ }
1027
+ span.remove();
1028
+ }
1029
+ function getCurrentTransform(ctx) {
1030
+ const {
1031
+ a,
1032
+ b,
1033
+ c,
1034
+ d,
1035
+ e,
1036
+ f
1037
+ } = ctx.getTransform();
1038
+ return [a, b, c, d, e, f];
1039
+ }
1040
+ function getCurrentTransformInverse(ctx) {
1041
+ const {
1042
+ a,
1043
+ b,
1044
+ c,
1045
+ d,
1046
+ e,
1047
+ f
1048
+ } = ctx.getTransform().invertSelf();
1049
+ return [a, b, c, d, e, f];
1050
+ }
1051
+
1052
+ /**
1053
+ * @param {HTMLDivElement} div
1054
+ * @param {PageViewport} viewport
1055
+ * @param {boolean} mustFlip
1056
+ * @param {boolean} mustRotate
1057
+ */
1058
+ function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true) {
1059
+ if (viewport instanceof PageViewport) {
1060
+ const {
1061
+ pageWidth,
1062
+ pageHeight
1063
+ } = viewport.rawDims;
1064
+ const {
1065
+ style
1066
+ } = div;
1067
+ const useRound = FeatureTest.isCSSRoundSupported;
1068
+ const w = `var(--scale-factor) * ${pageWidth}px`,
1069
+ h = `var(--scale-factor) * ${pageHeight}px`;
1070
+ const widthStr = useRound ? `round(${w}, 1px)` : `calc(${w})`,
1071
+ heightStr = useRound ? `round(${h}, 1px)` : `calc(${h})`;
1072
+ if (!mustFlip || viewport.rotation % 180 === 0) {
1073
+ style.width = widthStr;
1074
+ style.height = heightStr;
1075
+ } else {
1076
+ style.width = heightStr;
1077
+ style.height = widthStr;
1078
+ }
1079
+ }
1080
+ if (mustRotate) {
1081
+ div.setAttribute("data-main-rotation", viewport.rotation);
1082
+ }
1083
+ }
1084
+
1085
+ /* Copyright 2017 Mozilla Foundation
1086
+ *
1087
+ * Licensed under the Apache License, Version 2.0 (the "License");
1088
+ * you may not use this file except in compliance with the License.
1089
+ * You may obtain a copy of the License at
1090
+ *
1091
+ * http://www.apache.org/licenses/LICENSE-2.0
1092
+ *
1093
+ * Unless required by applicable law or agreed to in writing, software
1094
+ * distributed under the License is distributed on an "AS IS" BASIS,
1095
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1096
+ * See the License for the specific language governing permissions and
1097
+ * limitations under the License.
1098
+ */
1099
+
1100
+ // This getFilenameFromContentDispositionHeader function is adapted from
1101
+ // https://github.com/Rob--W/open-in-browser/blob/7e2e35a38b8b4e981b11da7b2f01df0149049e92/extension/content-disposition.js
1102
+ // with the following changes:
1103
+ // - Modified to conform to PDF.js's coding style.
1104
+ // - Move return to the end of the function to prevent Babel from dropping the
1105
+ // function declarations.
1106
+
1107
+ /**
1108
+ * Extract file name from the Content-Disposition HTTP response header.
1109
+ *
1110
+ * @param {string} contentDisposition
1111
+ * @returns {string} Filename, if found in the Content-Disposition header.
1112
+ */
1113
+ function getFilenameFromContentDispositionHeader(contentDisposition) {
1114
+ let needsEncodingFixup = true;
1115
+
1116
+ // filename*=ext-value ("ext-value" from RFC 5987, referenced by RFC 6266).
1117
+ let tmp = toParamRegExp("filename\\*", "i").exec(contentDisposition);
1118
+ if (tmp) {
1119
+ tmp = tmp[1];
1120
+ let filename = rfc2616unquote(tmp);
1121
+ filename = unescape(filename);
1122
+ filename = rfc5987decode(filename);
1123
+ filename = rfc2047decode(filename);
1124
+ return fixupEncoding(filename);
1125
+ }
1126
+
1127
+ // Continuations (RFC 2231 section 3, referenced by RFC 5987 section 3.1).
1128
+ // filename*n*=part
1129
+ // filename*n=part
1130
+ tmp = rfc2231getparam(contentDisposition);
1131
+ if (tmp) {
1132
+ // RFC 2047, section
1133
+ const filename = rfc2047decode(tmp);
1134
+ return fixupEncoding(filename);
1135
+ }
1136
+
1137
+ // filename=value (RFC 5987, section 4.1).
1138
+ tmp = toParamRegExp("filename", "i").exec(contentDisposition);
1139
+ if (tmp) {
1140
+ tmp = tmp[1];
1141
+ let filename = rfc2616unquote(tmp);
1142
+ filename = rfc2047decode(filename);
1143
+ return fixupEncoding(filename);
1144
+ }
1145
+
1146
+ // After this line there are only function declarations. We cannot put
1147
+ // "return" here for readability because babel would then drop the function
1148
+ // declarations...
1149
+ function toParamRegExp(attributePattern, flags) {
1150
+ return new RegExp("(?:^|;)\\s*" + attributePattern + "\\s*=\\s*" +
1151
+ // Captures: value = token | quoted-string
1152
+ // (RFC 2616, section 3.6 and referenced by RFC 6266 4.1)
1153
+ "(" + '[^";\\s][^;\\s]*' + "|" + '"(?:[^"\\\\]|\\\\"?)+"?' + ")", flags);
1154
+ }
1155
+ function textdecode(encoding, value) {
1156
+ if (encoding) {
1157
+ if (!/^[\x00-\xFF]+$/.test(value)) {
1158
+ return value;
1159
+ }
1160
+ try {
1161
+ const decoder = new TextDecoder(encoding, {
1162
+ fatal: true
1163
+ });
1164
+ const buffer = stringToBytes(value);
1165
+ value = decoder.decode(buffer);
1166
+ needsEncodingFixup = false;
1167
+ } catch {
1168
+ // TextDecoder constructor threw - unrecognized encoding.
1169
+ }
1170
+ }
1171
+ return value;
1172
+ }
1173
+ function fixupEncoding(value) {
1174
+ if (needsEncodingFixup && /[\x80-\xff]/.test(value)) {
1175
+ // Maybe multi-byte UTF-8.
1176
+ value = textdecode("utf-8", value);
1177
+ if (needsEncodingFixup) {
1178
+ // Try iso-8859-1 encoding.
1179
+ value = textdecode("iso-8859-1", value);
1180
+ }
1181
+ }
1182
+ return value;
1183
+ }
1184
+ function rfc2231getparam(contentDispositionStr) {
1185
+ const matches = [];
1186
+ let match;
1187
+ // Iterate over all filename*n= and filename*n*= with n being an integer
1188
+ // of at least zero. Any non-zero number must not start with '0'.
1189
+ const iter = toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)", "ig");
1190
+ while ((match = iter.exec(contentDispositionStr)) !== null) {
1191
+ let [, n, quot, part] = match; // eslint-disable-line prefer-const
1192
+ n = parseInt(n, 10);
1193
+ if (n in matches) {
1194
+ // Ignore anything after the invalid second filename*0.
1195
+ if (n === 0) {
1196
+ break;
1197
+ }
1198
+ continue;
1199
+ }
1200
+ matches[n] = [quot, part];
1201
+ }
1202
+ const parts = [];
1203
+ for (let n = 0; n < matches.length; ++n) {
1204
+ if (!(n in matches)) {
1205
+ // Numbers must be consecutive. Truncate when there is a hole.
1206
+ break;
1207
+ }
1208
+ let [quot, part] = matches[n]; // eslint-disable-line prefer-const
1209
+ part = rfc2616unquote(part);
1210
+ if (quot) {
1211
+ part = unescape(part);
1212
+ if (n === 0) {
1213
+ part = rfc5987decode(part);
1214
+ }
1215
+ }
1216
+ parts.push(part);
1217
+ }
1218
+ return parts.join("");
1219
+ }
1220
+ function rfc2616unquote(value) {
1221
+ if (value.startsWith('"')) {
1222
+ const parts = value.slice(1).split('\\"');
1223
+ // Find the first unescaped " and terminate there.
1224
+ for (let i = 0; i < parts.length; ++i) {
1225
+ const quotindex = parts[i].indexOf('"');
1226
+ if (quotindex !== -1) {
1227
+ parts[i] = parts[i].slice(0, quotindex);
1228
+ parts.length = i + 1; // Truncates and stop the iteration.
1229
+ }
1230
+ parts[i] = parts[i].replaceAll(/\\(.)/g, "$1");
1231
+ }
1232
+ value = parts.join('"');
1233
+ }
1234
+ return value;
1235
+ }
1236
+ function rfc5987decode(extvalue) {
1237
+ // Decodes "ext-value" from RFC 5987.
1238
+ const encodingend = extvalue.indexOf("'");
1239
+ if (encodingend === -1) {
1240
+ // Some servers send "filename*=" without encoding 'language' prefix,
1241
+ // e.g. in https://github.com/Rob--W/open-in-browser/issues/26
1242
+ // Let's accept the value like Firefox (57) (Chrome 62 rejects it).
1243
+ return extvalue;
1244
+ }
1245
+ const encoding = extvalue.slice(0, encodingend);
1246
+ const langvalue = extvalue.slice(encodingend + 1);
1247
+ // Ignore language (RFC 5987 section 3.2.1, and RFC 6266 section 4.1 ).
1248
+ const value = langvalue.replace(/^[^']*'/, "");
1249
+ return textdecode(encoding, value);
1250
+ }
1251
+ function rfc2047decode(value) {
1252
+ // RFC 2047-decode the result. Firefox tried to drop support for it, but
1253
+ // backed out because some servers use it - https://bugzil.la/875615
1254
+ // Firefox's condition for decoding is here: https://searchfox.org/mozilla-central/rev/4a590a5a15e35d88a3b23dd6ac3c471cf85b04a8/netwerk/mime/nsMIMEHeaderParamImpl.cpp#742-748
1255
+
1256
+ // We are more strict and only recognize RFC 2047-encoding if the value
1257
+ // starts with "=?", since then it is likely that the full value is
1258
+ // RFC 2047-encoded.
1259
+
1260
+ // Firefox also decodes words even where RFC 2047 section 5 states:
1261
+ // "An 'encoded-word' MUST NOT appear within a 'quoted-string'."
1262
+ if (!value.startsWith("=?") || /[\x00-\x19\x80-\xff]/.test(value)) {
1263
+ return value;
1264
+ }
1265
+ // RFC 2047, section 2.4
1266
+ // encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
1267
+ // charset = token (but let's restrict to characters that denote a
1268
+ // possibly valid encoding).
1269
+ // encoding = q or b
1270
+ // encoded-text = any printable ASCII character other than ? or space.
1271
+ // ... but Firefox permits ? and space.
1272
+ return value.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g, function (matches, charset, encoding, text) {
1273
+ if (encoding === "q" || encoding === "Q") {
1274
+ // RFC 2047 section 4.2.
1275
+ text = text.replaceAll("_", " ");
1276
+ text = text.replaceAll(/=([0-9a-fA-F]{2})/g, function (match, hex) {
1277
+ return String.fromCharCode(parseInt(hex, 16));
1278
+ });
1279
+ return textdecode(charset, text);
1280
+ } // else encoding is b or B - base64 (RFC 2047 section 4.1)
1281
+ try {
1282
+ text = atob(text);
1283
+ } catch {}
1284
+ return textdecode(charset, text);
1285
+ });
1286
+ }
1287
+ return "";
1288
+ }
1289
+
1290
+ /* Copyright 2012 Mozilla Foundation
1291
+ *
1292
+ * Licensed under the Apache License, Version 2.0 (the "License");
1293
+ * you may not use this file except in compliance with the License.
1294
+ * You may obtain a copy of the License at
1295
+ *
1296
+ * http://www.apache.org/licenses/LICENSE-2.0
1297
+ *
1298
+ * Unless required by applicable law or agreed to in writing, software
1299
+ * distributed under the License is distributed on an "AS IS" BASIS,
1300
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1301
+ * See the License for the specific language governing permissions and
1302
+ * limitations under the License.
1303
+ */
1304
+ function validateRangeRequestCapabilities({
1305
+ getResponseHeader,
1306
+ isHttp,
1307
+ rangeChunkSize,
1308
+ disableRange
1309
+ }) {
1310
+ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
1311
+ assert(Number.isInteger(rangeChunkSize) && rangeChunkSize > 0, "rangeChunkSize must be an integer larger than zero.");
1312
+ }
1313
+ const returnValues = {
1314
+ allowRangeRequests: false,
1315
+ suggestedLength: undefined
1316
+ };
1317
+ const length = parseInt(getResponseHeader("Content-Length"), 10);
1318
+ if (!Number.isInteger(length)) {
1319
+ return returnValues;
1320
+ }
1321
+ returnValues.suggestedLength = length;
1322
+ if (length <= 2 * rangeChunkSize) {
1323
+ // The file size is smaller than the size of two chunks, so it does not
1324
+ // make any sense to abort the request and retry with a range request.
1325
+ return returnValues;
1326
+ }
1327
+ if (disableRange || !isHttp) {
1328
+ return returnValues;
1329
+ }
1330
+ if (getResponseHeader("Accept-Ranges") !== "bytes") {
1331
+ return returnValues;
1332
+ }
1333
+ const contentEncoding = getResponseHeader("Content-Encoding") || "identity";
1334
+ if (contentEncoding !== "identity") {
1335
+ return returnValues;
1336
+ }
1337
+ returnValues.allowRangeRequests = true;
1338
+ return returnValues;
1339
+ }
1340
+ function extractFilenameFromHeader(getResponseHeader) {
1341
+ const contentDisposition = getResponseHeader("Content-Disposition");
1342
+ if (contentDisposition) {
1343
+ let filename = getFilenameFromContentDispositionHeader(contentDisposition);
1344
+ if (filename.includes("%")) {
1345
+ try {
1346
+ filename = decodeURIComponent(filename);
1347
+ } catch {}
1348
+ }
1349
+ if (isPdfFile(filename)) {
1350
+ return filename;
1351
+ }
1352
+ }
1353
+ return null;
1354
+ }
1355
+ function createResponseStatusError(status, url) {
1356
+ if (status === 404 || status === 0 && url.startsWith("file:")) {
1357
+ return new MissingPDFException('Missing PDF "' + url + '".');
1358
+ }
1359
+ return new UnexpectedResponseException(`Unexpected server response (${status}) while retrieving PDF "${url}".`, status);
1360
+ }
1361
+ function validateResponseStatus(status) {
1362
+ return status === 200 || status === 206;
1363
+ }
1364
+
1365
+ /* Copyright 2012 Mozilla Foundation
1366
+ *
1367
+ * Licensed under the Apache License, Version 2.0 (the "License");
1368
+ * you may not use this file except in compliance with the License.
1369
+ * You may obtain a copy of the License at
1370
+ *
1371
+ * http://www.apache.org/licenses/LICENSE-2.0
1372
+ *
1373
+ * Unless required by applicable law or agreed to in writing, software
1374
+ * distributed under the License is distributed on an "AS IS" BASIS,
1375
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1376
+ * See the License for the specific language governing permissions and
1377
+ * limitations under the License.
1378
+ */
1379
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL")) {
1380
+ throw new Error('Module "./node_stream.js" shall not be used with MOZCENTRAL builds.');
1381
+ }
1382
+ let fs, http, https, url;
1383
+ if (isNodeJS) {
1384
+ // Native packages.
1385
+ fs = await __non_webpack_import__("fs");
1386
+ http = await __non_webpack_import__("http");
1387
+ https = await __non_webpack_import__("https");
1388
+ url = await __non_webpack_import__("url");
1389
+ }
1390
+ const fileUriRegex = /^file:\/\/\/[a-zA-Z]:\//;
1391
+ function parseUrl(sourceUrl) {
1392
+ const parsedUrl = url.parse(sourceUrl);
1393
+ if (parsedUrl.protocol === "file:" || parsedUrl.host) {
1394
+ return parsedUrl;
1395
+ }
1396
+ // Prepending 'file:///' to Windows absolute path.
1397
+ if (/^[a-z]:[/\\]/i.test(sourceUrl)) {
1398
+ return url.parse(`file:///${sourceUrl}`);
1399
+ }
1400
+ // Changes protocol to 'file:' if url refers to filesystem.
1401
+ if (!parsedUrl.host) {
1402
+ parsedUrl.protocol = "file:";
1403
+ }
1404
+ return parsedUrl;
1405
+ }
1406
+ class PDFNodeStream {
1407
+ constructor(source) {
1408
+ this.source = source;
1409
+ this.url = parseUrl(source.url);
1410
+ this.isHttp = this.url.protocol === "http:" || this.url.protocol === "https:";
1411
+ // Check if url refers to filesystem.
1412
+ this.isFsUrl = this.url.protocol === "file:";
1413
+ this.httpHeaders = this.isHttp && source.httpHeaders || {};
1414
+ this._fullRequestReader = null;
1415
+ this._rangeRequestReaders = [];
1416
+ }
1417
+ get _progressiveDataLength() {
1418
+ var _this$_fullRequestRea, _this$_fullRequestRea2;
1419
+ return (_this$_fullRequestRea = (_this$_fullRequestRea2 = this._fullRequestReader) === null || _this$_fullRequestRea2 === void 0 ? void 0 : _this$_fullRequestRea2._loaded) !== null && _this$_fullRequestRea !== void 0 ? _this$_fullRequestRea : 0;
1420
+ }
1421
+ getFullReader() {
1422
+ assert(!this._fullRequestReader, "PDFNodeStream.getFullReader can only be called once.");
1423
+ this._fullRequestReader = this.isFsUrl ? new PDFNodeStreamFsFullReader(this) : new PDFNodeStreamFullReader(this);
1424
+ return this._fullRequestReader;
1425
+ }
1426
+ getRangeReader(start, end) {
1427
+ if (end <= this._progressiveDataLength) {
1428
+ return null;
1429
+ }
1430
+ const rangeReader = this.isFsUrl ? new PDFNodeStreamFsRangeReader(this, start, end) : new PDFNodeStreamRangeReader(this, start, end);
1431
+ this._rangeRequestReaders.push(rangeReader);
1432
+ return rangeReader;
1433
+ }
1434
+ cancelAllRequests(reason) {
1435
+ var _this$_fullRequestRea3;
1436
+ (_this$_fullRequestRea3 = this._fullRequestReader) === null || _this$_fullRequestRea3 === void 0 ? void 0 : _this$_fullRequestRea3.cancel(reason);
1437
+ for (const reader of this._rangeRequestReaders.slice(0)) {
1438
+ reader.cancel(reason);
1439
+ }
1440
+ }
1441
+ }
1442
+ class BaseFullReader {
1443
+ constructor(stream) {
1444
+ this._url = stream.url;
1445
+ this._done = false;
1446
+ this._storedError = null;
1447
+ this.onProgress = null;
1448
+ const source = stream.source;
1449
+ this._contentLength = source.length; // optional
1450
+ this._loaded = 0;
1451
+ this._filename = null;
1452
+ this._disableRange = source.disableRange || false;
1453
+ this._rangeChunkSize = source.rangeChunkSize;
1454
+ if (!this._rangeChunkSize && !this._disableRange) {
1455
+ this._disableRange = true;
1456
+ }
1457
+ this._isStreamingSupported = !source.disableStream;
1458
+ this._isRangeSupported = !source.disableRange;
1459
+ this._readableStream = null;
1460
+ this._readCapability = Promise.withResolvers();
1461
+ this._headersCapability = Promise.withResolvers();
1462
+ }
1463
+ get headersReady() {
1464
+ return this._headersCapability.promise;
1465
+ }
1466
+ get filename() {
1467
+ return this._filename;
1468
+ }
1469
+ get contentLength() {
1470
+ return this._contentLength;
1471
+ }
1472
+ get isRangeSupported() {
1473
+ return this._isRangeSupported;
1474
+ }
1475
+ get isStreamingSupported() {
1476
+ return this._isStreamingSupported;
1477
+ }
1478
+ async read() {
1479
+ var _this$onProgress;
1480
+ await this._readCapability.promise;
1481
+ if (this._done) {
1482
+ return {
1483
+ value: undefined,
1484
+ done: true
1485
+ };
1486
+ }
1487
+ if (this._storedError) {
1488
+ throw this._storedError;
1489
+ }
1490
+ const chunk = this._readableStream.read();
1491
+ if (chunk === null) {
1492
+ this._readCapability = Promise.withResolvers();
1493
+ return this.read();
1494
+ }
1495
+ this._loaded += chunk.length;
1496
+ (_this$onProgress = this.onProgress) === null || _this$onProgress === void 0 ? void 0 : _this$onProgress.call(this, {
1497
+ loaded: this._loaded,
1498
+ total: this._contentLength
1499
+ });
1500
+
1501
+ // Ensure that `read()` method returns ArrayBuffer.
1502
+ const buffer = new Uint8Array(chunk).buffer;
1503
+ return {
1504
+ value: buffer,
1505
+ done: false
1506
+ };
1507
+ }
1508
+ cancel(reason) {
1509
+ // Call `this._error()` method when cancel is called
1510
+ // before _readableStream is set.
1511
+ if (!this._readableStream) {
1512
+ this._error(reason);
1513
+ return;
1514
+ }
1515
+ this._readableStream.destroy(reason);
1516
+ }
1517
+ _error(reason) {
1518
+ this._storedError = reason;
1519
+ this._readCapability.resolve();
1520
+ }
1521
+ _setReadableStream(readableStream) {
1522
+ this._readableStream = readableStream;
1523
+ readableStream.on("readable", () => {
1524
+ this._readCapability.resolve();
1525
+ });
1526
+ readableStream.on("end", () => {
1527
+ // Destroy readable to minimize resource usage.
1528
+ readableStream.destroy();
1529
+ this._done = true;
1530
+ this._readCapability.resolve();
1531
+ });
1532
+ readableStream.on("error", reason => {
1533
+ this._error(reason);
1534
+ });
1535
+
1536
+ // We need to stop reading when range is supported and streaming is
1537
+ // disabled.
1538
+ if (!this._isStreamingSupported && this._isRangeSupported) {
1539
+ this._error(new AbortException("streaming is disabled"));
1540
+ }
1541
+
1542
+ // Destroy ReadableStream if already in errored state.
1543
+ if (this._storedError) {
1544
+ this._readableStream.destroy(this._storedError);
1545
+ }
1546
+ }
1547
+ }
1548
+ class BaseRangeReader {
1549
+ constructor(stream) {
1550
+ this._url = stream.url;
1551
+ this._done = false;
1552
+ this._storedError = null;
1553
+ this.onProgress = null;
1554
+ this._loaded = 0;
1555
+ this._readableStream = null;
1556
+ this._readCapability = Promise.withResolvers();
1557
+ const source = stream.source;
1558
+ this._isStreamingSupported = !source.disableStream;
1559
+ }
1560
+ get isStreamingSupported() {
1561
+ return this._isStreamingSupported;
1562
+ }
1563
+ async read() {
1564
+ var _this$onProgress2;
1565
+ await this._readCapability.promise;
1566
+ if (this._done) {
1567
+ return {
1568
+ value: undefined,
1569
+ done: true
1570
+ };
1571
+ }
1572
+ if (this._storedError) {
1573
+ throw this._storedError;
1574
+ }
1575
+ const chunk = this._readableStream.read();
1576
+ if (chunk === null) {
1577
+ this._readCapability = Promise.withResolvers();
1578
+ return this.read();
1579
+ }
1580
+ this._loaded += chunk.length;
1581
+ (_this$onProgress2 = this.onProgress) === null || _this$onProgress2 === void 0 ? void 0 : _this$onProgress2.call(this, {
1582
+ loaded: this._loaded
1583
+ });
1584
+
1585
+ // Ensure that `read()` method returns ArrayBuffer.
1586
+ const buffer = new Uint8Array(chunk).buffer;
1587
+ return {
1588
+ value: buffer,
1589
+ done: false
1590
+ };
1591
+ }
1592
+ cancel(reason) {
1593
+ // Call `this._error()` method when cancel is called
1594
+ // before _readableStream is set.
1595
+ if (!this._readableStream) {
1596
+ this._error(reason);
1597
+ return;
1598
+ }
1599
+ this._readableStream.destroy(reason);
1600
+ }
1601
+ _error(reason) {
1602
+ this._storedError = reason;
1603
+ this._readCapability.resolve();
1604
+ }
1605
+ _setReadableStream(readableStream) {
1606
+ this._readableStream = readableStream;
1607
+ readableStream.on("readable", () => {
1608
+ this._readCapability.resolve();
1609
+ });
1610
+ readableStream.on("end", () => {
1611
+ // Destroy readableStream to minimize resource usage.
1612
+ readableStream.destroy();
1613
+ this._done = true;
1614
+ this._readCapability.resolve();
1615
+ });
1616
+ readableStream.on("error", reason => {
1617
+ this._error(reason);
1618
+ });
1619
+
1620
+ // Destroy readableStream if already in errored state.
1621
+ if (this._storedError) {
1622
+ this._readableStream.destroy(this._storedError);
1623
+ }
1624
+ }
1625
+ }
1626
+ function createRequestOptions(parsedUrl, headers) {
1627
+ return {
1628
+ protocol: parsedUrl.protocol,
1629
+ auth: parsedUrl.auth,
1630
+ host: parsedUrl.hostname,
1631
+ port: parsedUrl.port,
1632
+ path: parsedUrl.path,
1633
+ method: "GET",
1634
+ headers
1635
+ };
1636
+ }
1637
+ class PDFNodeStreamFullReader extends BaseFullReader {
1638
+ constructor(stream) {
1639
+ super(stream);
1640
+ const handleResponse = response => {
1641
+ if (response.statusCode === 404) {
1642
+ const error = new MissingPDFException(`Missing PDF "${this._url}".`);
1643
+ this._storedError = error;
1644
+ this._headersCapability.reject(error);
1645
+ return;
1646
+ }
1647
+ this._headersCapability.resolve();
1648
+ this._setReadableStream(response);
1649
+
1650
+ // Make sure that headers name are in lower case, as mentioned
1651
+ // here: https://nodejs.org/api/http.html#http_message_headers.
1652
+ const getResponseHeader = name => this._readableStream.headers[name.toLowerCase()];
1653
+ const {
1654
+ allowRangeRequests,
1655
+ suggestedLength
1656
+ } = validateRangeRequestCapabilities({
1657
+ getResponseHeader,
1658
+ isHttp: stream.isHttp,
1659
+ rangeChunkSize: this._rangeChunkSize,
1660
+ disableRange: this._disableRange
1661
+ });
1662
+ this._isRangeSupported = allowRangeRequests;
1663
+ // Setting right content length.
1664
+ this._contentLength = suggestedLength || this._contentLength;
1665
+ this._filename = extractFilenameFromHeader(getResponseHeader);
1666
+ };
1667
+ this._request = null;
1668
+ if (this._url.protocol === "http:") {
1669
+ this._request = http.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
1670
+ } else {
1671
+ this._request = https.request(createRequestOptions(this._url, stream.httpHeaders), handleResponse);
1672
+ }
1673
+ this._request.on("error", reason => {
1674
+ this._storedError = reason;
1675
+ this._headersCapability.reject(reason);
1676
+ });
1677
+ // Note: `request.end(data)` is used to write `data` to request body
1678
+ // and notify end of request. But one should always call `request.end()`
1679
+ // even if there is no data to write -- (to notify the end of request).
1680
+ this._request.end();
1681
+ }
1682
+ }
1683
+ class PDFNodeStreamRangeReader extends BaseRangeReader {
1684
+ constructor(stream, start, end) {
1685
+ super(stream);
1686
+ this._httpHeaders = {};
1687
+ for (const property in stream.httpHeaders) {
1688
+ const value = stream.httpHeaders[property];
1689
+ if (value === undefined) {
1690
+ continue;
1691
+ }
1692
+ this._httpHeaders[property] = value;
1693
+ }
1694
+ this._httpHeaders.Range = `bytes=${start}-${end - 1}`;
1695
+ const handleResponse = response => {
1696
+ if (response.statusCode === 404) {
1697
+ const error = new MissingPDFException(`Missing PDF "${this._url}".`);
1698
+ this._storedError = error;
1699
+ return;
1700
+ }
1701
+ this._setReadableStream(response);
1702
+ };
1703
+ this._request = null;
1704
+ if (this._url.protocol === "http:") {
1705
+ this._request = http.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
1706
+ } else {
1707
+ this._request = https.request(createRequestOptions(this._url, this._httpHeaders), handleResponse);
1708
+ }
1709
+ this._request.on("error", reason => {
1710
+ this._storedError = reason;
1711
+ });
1712
+ this._request.end();
1713
+ }
1714
+ }
1715
+ class PDFNodeStreamFsFullReader extends BaseFullReader {
1716
+ constructor(stream) {
1717
+ super(stream);
1718
+ let path = decodeURIComponent(this._url.path);
1719
+
1720
+ // Remove the extra slash to get right path from url like `file:///C:/`
1721
+ if (fileUriRegex.test(this._url.href)) {
1722
+ path = path.replace(/^\//, "");
1723
+ }
1724
+ fs.promises.lstat(path).then(stat => {
1725
+ // Setting right content length.
1726
+ this._contentLength = stat.size;
1727
+ this._setReadableStream(fs.createReadStream(path));
1728
+ this._headersCapability.resolve();
1729
+ }, error => {
1730
+ if (error.code === "ENOENT") {
1731
+ error = new MissingPDFException(`Missing PDF "${path}".`);
1732
+ }
1733
+ this._storedError = error;
1734
+ this._headersCapability.reject(error);
1735
+ });
1736
+ }
1737
+ }
1738
+ class PDFNodeStreamFsRangeReader extends BaseRangeReader {
1739
+ constructor(stream, start, end) {
1740
+ super(stream);
1741
+ let path = decodeURIComponent(this._url.path);
1742
+
1743
+ // Remove the extra slash to get right path from url like `file:///C:/`
1744
+ if (fileUriRegex.test(this._url.href)) {
1745
+ path = path.replace(/^\//, "");
1746
+ }
1747
+ this._setReadableStream(fs.createReadStream(path, {
1748
+ start,
1749
+ end: end - 1
1750
+ }));
1751
+ }
1752
+ }
1753
+
1754
+ export { getXfaPageViewport as A, BaseFilterFactory as B, DOMCanvasFactory as D, PixelsPerInch as P, RenderingCancelledException as R, StatTimer as S, getRGB as a, BaseCanvasFactory as b, BaseCMapReaderFactory as c, BaseStandardFontDataFactory as d, getCurrentTransform as e, fetchData as f, getColorValues as g, getCurrentTransformInverse as h, isPdfFile as i, createResponseStatusError as j, validateRangeRequestCapabilities as k, extractFilenameFromHeader as l, DOMCMapReaderFactory as m, noContextMenu as n, DOMFilterFactory as o, DOMStandardFontDataFactory as p, isDataScheme as q, isValidFetchUrl as r, setLayerDimensions as s, PDFNodeStream as t, PageViewport as u, validateResponseStatus as v, DOMSVGFactory as w, PDFDateString as x, getFilenameFromUrl as y, getPdfFilenameFromUrl as z };