@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.
@@ -1,4 +1,4 @@
1
- /* Copyright 2018 Mozilla Foundation
1
+ /* Copyright 2012 Mozilla Foundation
2
2
  *
3
3
  * Licensed under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License.
@@ -12,148 +12,77 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
-
16
15
  /* globals process */
16
+
17
17
  // NW.js / Electron is a browser context, but copies some Node.js objects; see
18
18
  // http://docs.nwjs.io/en/latest/For%20Users/Advanced/JavaScript%20Contexts%20in%20NW.js/#access-nodejs-and-nwjs-api-in-browser-context
19
19
  // https://www.electronjs.org/docs/api/process#processversionselectron-readonly
20
20
  // https://www.electronjs.org/docs/api/process#processtype-readonly
21
- const isNodeJS = typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
22
-
23
- /* Copyright 2017 Mozilla Foundation
24
- *
25
- * Licensed under the Apache License, Version 2.0 (the "License");
26
- * you may not use this file except in compliance with the License.
27
- * You may obtain a copy of the License at
28
- *
29
- * http://www.apache.org/licenses/LICENSE-2.0
30
- *
31
- * Unless required by applicable law or agreed to in writing, software
32
- * distributed under the License is distributed on an "AS IS" BASIS,
33
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
- * See the License for the specific language governing permissions and
35
- * limitations under the License.
36
- */
37
-
38
- if ((typeof PDFJSDev === "undefined" || !PDFJSDev.test("SKIP_BABEL")) && (typeof globalThis === "undefined" || !globalThis._pdfjsCompatibilityChecked)) {
39
- // Provides support for globalThis in legacy browsers.
40
- // Support: Firefox<65, Chrome<71, Safari<12.1
41
- if (typeof globalThis === "undefined" || globalThis.Math !== Math) {
42
- // eslint-disable-next-line no-global-assign
43
- globalThis = require("core-js/es/global-this");
44
- }
45
-
46
- globalThis._pdfjsCompatibilityChecked = true; // Support: Node.js
47
-
48
- (function checkNodeBtoa() {
49
- if (globalThis.btoa || !isNodeJS) {
50
- return;
51
- }
52
-
53
- globalThis.btoa = function (chars) {
54
- // eslint-disable-next-line no-undef
55
- return Buffer.from(chars, "binary").toString("base64");
56
- };
57
- })(); // Support: Node.js
58
-
59
-
60
- (function checkNodeAtob() {
61
- if (globalThis.atob || !isNodeJS) {
62
- return;
63
- }
64
-
65
- globalThis.atob = function (input) {
66
- // eslint-disable-next-line no-undef
67
- return Buffer.from(input, "base64").toString("binary");
68
- };
69
- })(); // Support: Node.js
70
-
71
-
72
- (function checkDOMMatrix() {
73
- if (globalThis.DOMMatrix || !isNodeJS) {
74
- return;
75
- }
76
-
77
- globalThis.DOMMatrix = require("dommatrix/dist/dommatrix.js");
78
- })(); // Provides support for Object.fromEntries in legacy browsers.
79
- // Support: Firefox<63, Chrome<73, Safari<12.1, Node.js<12.0.0
80
-
81
-
82
- (function checkObjectFromEntries() {
83
- if (Object.fromEntries) {
84
- return;
85
- }
86
-
87
- require("core-js/es/object/from-entries.js");
88
- })(); // Provides support for *recent* additions to the Promise specification,
89
- // however basic Promise support is assumed to be available natively.
90
- // Support: Firefox<71, Chrome<76, Safari<13, Node.js<12.9.0
91
-
92
-
93
- (function checkPromise() {
94
- if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
95
- // The current image decoders are synchronous, hence `Promise` shouldn't
96
- // need to be polyfilled for the IMAGE_DECODERS build target.
97
- return;
98
- }
99
-
100
- if (globalThis.Promise.allSettled) {
101
- return;
102
- }
103
-
104
- globalThis.Promise = require("core-js/es/promise/index.js");
105
- })(); // Support: Node.js
106
-
107
-
108
- (function checkReadableStream() {
109
- if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
110
- // The current image decoders are synchronous, hence `ReadableStream`
111
- // shouldn't need to be polyfilled for the IMAGE_DECODERS build target.
112
- return;
113
- }
114
-
115
- let isReadableStreamSupported = false;
116
-
117
- if (typeof ReadableStream !== "undefined") {
118
- // MS Edge may say it has ReadableStream but they are not up to spec yet.
119
- try {
120
- // eslint-disable-next-line no-new
121
- new ReadableStream({
122
- start(controller) {
123
- controller.close();
124
- }
125
-
126
- });
127
- isReadableStreamSupported = true;
128
- } catch (e) {// The ReadableStream constructor cannot be used.
129
- }
130
- }
131
-
132
- if (isReadableStreamSupported) {
133
- return;
134
- }
21
+ const isNodeJS = (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) && typeof process === "object" && process + "" === "[object process]" && !process.versions.nw && !(process.versions.electron && process.type && process.type !== "browser");
22
+ const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
23
+ const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
24
+ const MAX_IMAGE_SIZE_TO_CACHE = 10e6; // Ten megabytes.
135
25
 
136
- globalThis.ReadableStream = require("web-streams-polyfill/dist/ponyfill.js").ReadableStream;
137
- })();
138
- }
26
+ // Represent the percentage of the height of a single-line field over
27
+ // the font size. Acrobat seems to use this value.
28
+ const LINE_FACTOR = 1.35;
29
+ const LINE_DESCENT_FACTOR = 0.35;
30
+ const BASELINE_FACTOR = LINE_DESCENT_FACTOR / LINE_FACTOR;
139
31
 
140
- /* Copyright 2012 Mozilla Foundation
141
- *
142
- * Licensed under the Apache License, Version 2.0 (the "License");
143
- * you may not use this file except in compliance with the License.
144
- * You may obtain a copy of the License at
145
- *
146
- * http://www.apache.org/licenses/LICENSE-2.0
147
- *
148
- * Unless required by applicable law or agreed to in writing, software
149
- * distributed under the License is distributed on an "AS IS" BASIS,
150
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151
- * See the License for the specific language governing permissions and
152
- * limitations under the License.
32
+ /**
33
+ * Refer to the `WorkerTransport.getRenderingIntent`-method in the API, to see
34
+ * how these flags are being used:
35
+ * - ANY, DISPLAY, and PRINT are the normal rendering intents, note the
36
+ * `PDFPageProxy.{render, getOperatorList, getAnnotations}`-methods.
37
+ * - ANNOTATIONS_FORMS, ANNOTATIONS_STORAGE, ANNOTATIONS_DISABLE control which
38
+ * annotations are rendered onto the canvas (i.e. by being included in the
39
+ * operatorList), note the `PDFPageProxy.{render, getOperatorList}`-methods
40
+ * and their `annotationMode`-option.
41
+ * - OPLIST is used with the `PDFPageProxy.getOperatorList`-method, note the
42
+ * `OperatorList`-constructor (on the worker-thread).
153
43
  */
154
- const IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
155
- const FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0]; // Permission flags from Table 22, Section 7.6.3.2 of the PDF specification.
44
+ const RenderingIntentFlag = {
45
+ ANY: 0x01,
46
+ DISPLAY: 0x02,
47
+ PRINT: 0x04,
48
+ SAVE: 0x08,
49
+ ANNOTATIONS_FORMS: 0x10,
50
+ ANNOTATIONS_STORAGE: 0x20,
51
+ ANNOTATIONS_DISABLE: 0x40,
52
+ OPLIST: 0x100
53
+ };
54
+ const AnnotationMode = {
55
+ DISABLE: 0,
56
+ ENABLE: 1,
57
+ ENABLE_FORMS: 2,
58
+ ENABLE_STORAGE: 3
59
+ };
60
+ const AnnotationEditorPrefix = "pdfjs_internal_editor_";
61
+ const AnnotationEditorType = {
62
+ DISABLE: -1,
63
+ NONE: 0,
64
+ FREETEXT: 3,
65
+ HIGHLIGHT: 9,
66
+ STAMP: 13,
67
+ INK: 15
68
+ };
69
+ const AnnotationEditorParamsType = {
70
+ RESIZE: 1,
71
+ CREATE: 2,
72
+ FREETEXT_SIZE: 11,
73
+ FREETEXT_COLOR: 12,
74
+ FREETEXT_OPACITY: 13,
75
+ INK_COLOR: 21,
76
+ INK_THICKNESS: 22,
77
+ INK_OPACITY: 23,
78
+ HIGHLIGHT_COLOR: 31,
79
+ HIGHLIGHT_DEFAULT_COLOR: 32,
80
+ HIGHLIGHT_THICKNESS: 33,
81
+ HIGHLIGHT_FREE: 34,
82
+ HIGHLIGHT_SHOW_ALL: 35
83
+ };
156
84
 
85
+ // Permission flags from Table 22, Section 7.6.3.2 of the PDF specification.
157
86
  const PermissionFlag = {
158
87
  PRINT: 0x04,
159
88
  MODIFY_CONTENTS: 0x08,
@@ -280,33 +209,6 @@ const PageActionEventType = {
280
209
  O: "PageOpen",
281
210
  C: "PageClose"
282
211
  };
283
- const StreamType = {
284
- UNKNOWN: "UNKNOWN",
285
- FLATE: "FLATE",
286
- LZW: "LZW",
287
- DCT: "DCT",
288
- JPX: "JPX",
289
- JBIG: "JBIG",
290
- A85: "A85",
291
- AHX: "AHX",
292
- CCF: "CCF",
293
- RLX: "RLX" // PDF short name is 'RL', but telemetry requires three chars.
294
-
295
- };
296
- const FontType = {
297
- UNKNOWN: "UNKNOWN",
298
- TYPE1: "TYPE1",
299
- TYPE1STANDARD: "TYPE1STANDARD",
300
- TYPE1C: "TYPE1C",
301
- CIDFONTTYPE0: "CIDFONTTYPE0",
302
- CIDFONTTYPE0C: "CIDFONTTYPE0C",
303
- TRUETYPE: "TRUETYPE",
304
- CIDFONTTYPE2: "CIDFONTTYPE2",
305
- TYPE3: "TYPE3",
306
- OPENTYPE: "OPENTYPE",
307
- TYPE0: "TYPE0",
308
- MMTYPE1: "MMTYPE1"
309
- };
310
212
  const VerbosityLevel = {
311
213
  ERRORS: 0,
312
214
  WARNINGS: 1,
@@ -314,13 +216,15 @@ const VerbosityLevel = {
314
216
  };
315
217
  const CMapCompressionType = {
316
218
  NONE: 0,
317
- BINARY: 1,
318
- STREAM: 2
319
- }; // All the possible operations for an operator list.
219
+ BINARY: 1
220
+ };
320
221
 
222
+ // All the possible operations for an operator list.
321
223
  const OPS = {
322
224
  // Intentionally start from 1 so it is easy to spot bad operators that will be
323
225
  // 0's.
226
+ // PLEASE NOTE: We purposely keep any removed operators commented out, since
227
+ // re-numbering the list would risk breaking third-party users.
324
228
  dependency: 1,
325
229
  setLineWidth: 2,
326
230
  setLineCap: 3,
@@ -398,11 +302,11 @@ const OPS = {
398
302
  paintFormXObjectEnd: 75,
399
303
  beginGroup: 76,
400
304
  endGroup: 77,
401
- beginAnnotations: 78,
402
- endAnnotations: 79,
305
+ // beginAnnotations: 78,
306
+ // endAnnotations: 79,
403
307
  beginAnnotation: 80,
404
308
  endAnnotation: 81,
405
- paintJpegXObject: 82,
309
+ // paintJpegXObject: 82,
406
310
  paintImageMaskXObject: 83,
407
311
  paintImageMaskXObjectGroup: 84,
408
312
  paintImageXObject: 85,
@@ -413,335 +317,223 @@ const OPS = {
413
317
  paintSolidColorImageMask: 90,
414
318
  constructPath: 91
415
319
  };
416
- const UNSUPPORTED_FEATURES = {
417
- /** @deprecated unused */
418
- unknown: "unknown",
419
- forms: "forms",
420
- javaScript: "javaScript",
421
- signatures: "signatures",
422
- smask: "smask",
423
- shadingPattern: "shadingPattern",
424
-
425
- /** @deprecated unused */
426
- font: "font",
427
- errorTilingPattern: "errorTilingPattern",
428
- errorExtGState: "errorExtGState",
429
- errorXObject: "errorXObject",
430
- errorFontLoadType3: "errorFontLoadType3",
431
- errorFontState: "errorFontState",
432
- errorFontMissing: "errorFontMissing",
433
- errorFontTranslate: "errorFontTranslate",
434
- errorColorSpace: "errorColorSpace",
435
- errorOperatorList: "errorOperatorList",
436
- errorFontToUnicode: "errorFontToUnicode",
437
- errorFontLoadNative: "errorFontLoadNative",
438
- errorFontBuildPath: "errorFontBuildPath",
439
- errorFontGetPath: "errorFontGetPath",
440
- errorMarkedContent: "errorMarkedContent"
441
- };
442
320
  const PasswordResponses = {
443
321
  NEED_PASSWORD: 1,
444
322
  INCORRECT_PASSWORD: 2
445
323
  };
446
324
  let verbosity = VerbosityLevel.WARNINGS;
447
-
448
325
  function setVerbosityLevel(level) {
449
326
  if (Number.isInteger(level)) {
450
327
  verbosity = level;
451
328
  }
452
329
  }
453
-
454
330
  function getVerbosityLevel() {
455
331
  return verbosity;
456
- } // A notice for devs. These are good for things that are helpful to devs, such
332
+ }
333
+
334
+ // A notice for devs. These are good for things that are helpful to devs, such
457
335
  // as warning that Workers were disabled, which is important to devs but not
458
336
  // end users.
459
-
460
-
461
337
  function info(msg) {
462
338
  if (verbosity >= VerbosityLevel.INFOS) {
463
339
  console.log(`Info: ${msg}`);
464
340
  }
465
- } // Non-fatal warnings.
466
-
341
+ }
467
342
 
343
+ // Non-fatal warnings.
468
344
  function warn(msg) {
469
345
  if (verbosity >= VerbosityLevel.WARNINGS) {
470
346
  console.log(`Warning: ${msg}`);
471
347
  }
472
348
  }
473
-
474
349
  function unreachable(msg) {
475
350
  throw new Error(msg);
476
351
  }
477
-
478
352
  function assert(cond, msg) {
479
353
  if (!cond) {
480
354
  unreachable(msg);
481
355
  }
482
- } // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
483
-
484
-
485
- function isSameOrigin(baseUrl, otherUrl) {
486
- let base;
487
-
488
- try {
489
- base = new URL(baseUrl);
490
-
491
- if (!base.origin || base.origin === "null") {
492
- return false; // non-HTTP url
493
- }
494
- } catch (e) {
495
- return false;
496
- }
497
-
498
- const other = new URL(otherUrl, base);
499
- return base.origin === other.origin;
500
- } // Checks if URLs use one of the allowed protocols, e.g. to avoid XSS.
501
-
356
+ }
502
357
 
358
+ // Checks if URLs use one of the allowed protocols, e.g. to avoid XSS.
503
359
  function _isValidProtocol(url) {
504
- if (!url) {
505
- return false;
506
- }
507
-
508
- switch (url.protocol) {
360
+ switch (url === null || url === void 0 ? void 0 : url.protocol) {
509
361
  case "http:":
510
362
  case "https:":
511
363
  case "ftp:":
512
364
  case "mailto:":
513
365
  case "tel:":
514
366
  return true;
515
-
516
367
  default:
517
368
  return false;
518
369
  }
519
370
  }
371
+
520
372
  /**
521
373
  * Attempts to create a valid absolute URL.
522
374
  *
523
375
  * @param {URL|string} url - An absolute, or relative, URL.
524
- * @param {URL|string} baseUrl - An absolute URL.
376
+ * @param {URL|string} [baseUrl] - An absolute URL.
377
+ * @param {Object} [options]
525
378
  * @returns Either a valid {URL}, or `null` otherwise.
526
379
  */
527
-
528
-
529
- function createValidAbsoluteUrl(url, baseUrl) {
380
+ function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
530
381
  if (!url) {
531
382
  return null;
532
383
  }
533
-
534
384
  try {
535
- const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
385
+ if (options && typeof url === "string") {
386
+ // Let URLs beginning with "www." default to using the "http://" protocol.
387
+ if (options.addDefaultProtocol && url.startsWith("www.")) {
388
+ const dots = url.match(/\./g);
389
+ // Avoid accidentally matching a *relative* URL pointing to a file named
390
+ // e.g. "www.pdf" or similar.
391
+ if ((dots === null || dots === void 0 ? void 0 : dots.length) >= 2) {
392
+ url = `http://${url}`;
393
+ }
394
+ }
536
395
 
396
+ // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
397
+ // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding; see bug 1122280.
398
+ if (options.tryConvertEncoding) {
399
+ try {
400
+ url = stringToUTF8String(url);
401
+ } catch {}
402
+ }
403
+ }
404
+ const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
537
405
  if (_isValidProtocol(absoluteUrl)) {
538
406
  return absoluteUrl;
539
407
  }
540
- } catch (ex) {
408
+ } catch {
541
409
  /* `new URL()` will throw on incorrect data. */
542
410
  }
543
-
544
411
  return null;
545
412
  }
546
-
547
- function shadow(obj, prop, value) {
413
+ function shadow(obj, prop, value, nonSerializable = false) {
414
+ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
415
+ assert(prop in obj, `shadow: Property "${prop && prop.toString()}" not found in object.`);
416
+ }
548
417
  Object.defineProperty(obj, prop, {
549
418
  value,
550
- enumerable: true,
419
+ enumerable: !nonSerializable,
551
420
  configurable: true,
552
421
  writable: false
553
422
  });
554
423
  return value;
555
424
  }
425
+
556
426
  /**
557
427
  * @type {any}
558
428
  */
559
-
560
-
561
429
  const BaseException = function BaseExceptionClosure() {
562
430
  // eslint-disable-next-line no-shadow
563
- function BaseException(message) {
431
+ function BaseException(message, name) {
564
432
  if (this.constructor === BaseException) {
565
433
  unreachable("Cannot initialize BaseException.");
566
434
  }
567
-
568
435
  this.message = message;
569
- this.name = this.constructor.name;
436
+ this.name = name;
570
437
  }
571
-
572
438
  BaseException.prototype = new Error();
573
439
  BaseException.constructor = BaseException;
574
440
  return BaseException;
575
441
  }();
576
-
577
442
  class PasswordException extends BaseException {
578
443
  constructor(msg, code) {
579
- super(msg);
444
+ super(msg, "PasswordException");
580
445
  this.code = code;
581
446
  }
582
-
583
447
  }
584
-
585
448
  class UnknownErrorException extends BaseException {
586
449
  constructor(msg, details) {
587
- super(msg);
450
+ super(msg, "UnknownErrorException");
588
451
  this.details = details;
589
452
  }
590
-
591
453
  }
592
-
593
- class InvalidPDFException extends BaseException {}
594
-
595
- class MissingPDFException extends BaseException {}
596
-
454
+ class InvalidPDFException extends BaseException {
455
+ constructor(msg) {
456
+ super(msg, "InvalidPDFException");
457
+ }
458
+ }
459
+ class MissingPDFException extends BaseException {
460
+ constructor(msg) {
461
+ super(msg, "MissingPDFException");
462
+ }
463
+ }
597
464
  class UnexpectedResponseException extends BaseException {
598
465
  constructor(msg, status) {
599
- super(msg);
466
+ super(msg, "UnexpectedResponseException");
600
467
  this.status = status;
601
468
  }
602
-
603
469
  }
470
+
604
471
  /**
605
472
  * Error caused during parsing PDF data.
606
473
  */
474
+ class FormatError extends BaseException {
475
+ constructor(msg) {
476
+ super(msg, "FormatError");
477
+ }
478
+ }
607
479
 
608
-
609
- class FormatError extends BaseException {}
610
480
  /**
611
481
  * Error used to indicate task cancellation.
612
482
  */
613
-
614
-
615
- class AbortException extends BaseException {}
616
-
617
- const NullCharactersRegExp = /\x00/g;
618
- /**
619
- * @param {string} str
620
- */
621
-
622
- function removeNullCharacters(str) {
623
- if (typeof str !== "string") {
624
- warn("The argument for removeNullCharacters must be a string.");
625
- return str;
483
+ class AbortException extends BaseException {
484
+ constructor(msg) {
485
+ super(msg, "AbortException");
626
486
  }
627
-
628
- return str.replace(NullCharactersRegExp, "");
629
487
  }
630
-
631
488
  function bytesToString(bytes) {
632
- assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
489
+ if (typeof bytes !== "object" || (bytes === null || bytes === void 0 ? void 0 : bytes.length) === undefined) {
490
+ unreachable("Invalid argument for bytesToString");
491
+ }
633
492
  const length = bytes.length;
634
493
  const MAX_ARGUMENT_COUNT = 8192;
635
-
636
494
  if (length < MAX_ARGUMENT_COUNT) {
637
495
  return String.fromCharCode.apply(null, bytes);
638
496
  }
639
-
640
497
  const strBuf = [];
641
-
642
498
  for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
643
499
  const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
644
500
  const chunk = bytes.subarray(i, chunkEnd);
645
501
  strBuf.push(String.fromCharCode.apply(null, chunk));
646
502
  }
647
-
648
503
  return strBuf.join("");
649
504
  }
650
-
651
505
  function stringToBytes(str) {
652
- assert(typeof str === "string", "Invalid argument for stringToBytes");
506
+ if (typeof str !== "string") {
507
+ unreachable("Invalid argument for stringToBytes");
508
+ }
653
509
  const length = str.length;
654
510
  const bytes = new Uint8Array(length);
655
-
656
511
  for (let i = 0; i < length; ++i) {
657
512
  bytes[i] = str.charCodeAt(i) & 0xff;
658
513
  }
659
-
660
514
  return bytes;
661
515
  }
662
- /**
663
- * Gets length of the array (Array, Uint8Array, or string) in bytes.
664
- * @param {Array<any>|Uint8Array|string} arr
665
- * @returns {number}
666
- */
667
-
668
-
669
- function arrayByteLength(arr) {
670
- if (arr.length !== undefined) {
671
- return arr.length;
672
- }
673
-
674
- assert(arr.byteLength !== undefined, "arrayByteLength - invalid argument.");
675
- return arr.byteLength;
676
- }
677
- /**
678
- * Combines array items (arrays) into single Uint8Array object.
679
- * @param {Array<Array<any>|Uint8Array|string>} arr - the array of the arrays
680
- * (Array, Uint8Array, or string).
681
- * @returns {Uint8Array}
682
- */
683
-
684
-
685
- function arraysToBytes(arr) {
686
- const length = arr.length; // Shortcut: if first and only item is Uint8Array, return it.
687
-
688
- if (length === 1 && arr[0] instanceof Uint8Array) {
689
- return arr[0];
690
- }
691
-
692
- let resultLength = 0;
693
-
694
- for (let i = 0; i < length; i++) {
695
- resultLength += arrayByteLength(arr[i]);
696
- }
697
-
698
- let pos = 0;
699
- const data = new Uint8Array(resultLength);
700
-
701
- for (let i = 0; i < length; i++) {
702
- let item = arr[i];
703
-
704
- if (!(item instanceof Uint8Array)) {
705
- if (typeof item === "string") {
706
- item = stringToBytes(item);
707
- } else {
708
- item = new Uint8Array(item);
709
- }
710
- }
711
-
712
- const itemLength = item.byteLength;
713
- data.set(item, pos);
714
- pos += itemLength;
715
- }
716
-
717
- return data;
718
- }
719
-
720
516
  function string32(value) {
721
- if (typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")) {
517
+ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
722
518
  assert(typeof value === "number" && Math.abs(value) < 2 ** 32, `string32: Unexpected input "${value}".`);
723
519
  }
724
-
725
520
  return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
726
521
  }
727
-
728
522
  function objectSize(obj) {
729
523
  return Object.keys(obj).length;
730
- } // Ensure that the returned Object has a `null` prototype; hence why
731
- // `Object.fromEntries(...)` is not used.
732
-
524
+ }
733
525
 
526
+ // Ensure that the returned Object has a `null` prototype; hence why
527
+ // `Object.fromEntries(...)` is not used.
734
528
  function objectFromMap(map) {
735
529
  const obj = Object.create(null);
736
-
737
530
  for (const [key, value] of map) {
738
531
  obj[key] = value;
739
532
  }
740
-
741
533
  return obj;
742
- } // Checks the endianness of the platform.
743
-
534
+ }
744
535
 
536
+ // Checks the endianness of the platform.
745
537
  function isLittleEndian() {
746
538
  const buffer8 = new Uint8Array(4);
747
539
  buffer8[0] = 1;
@@ -749,318 +541,340 @@ function isLittleEndian() {
749
541
  return view32[0] === 1;
750
542
  }
751
543
 
752
- const IsLittleEndianCached = {
753
- get value() {
754
- return shadow(this, "value", isLittleEndian());
755
- }
756
-
757
- }; // Checks if it's possible to eval JS expressions.
758
-
544
+ // Checks if it's possible to eval JS expressions.
759
545
  function isEvalSupported() {
760
546
  try {
761
547
  new Function(""); // eslint-disable-line no-new, no-new-func
762
-
763
548
  return true;
764
- } catch (e) {
549
+ } catch {
765
550
  return false;
766
551
  }
767
552
  }
768
-
769
- const IsEvalSupportedCached = {
770
- get value() {
771
- return shadow(this, "value", isEvalSupported());
553
+ class FeatureTest {
554
+ static get isLittleEndian() {
555
+ return shadow(this, "isLittleEndian", isLittleEndian());
772
556
  }
773
-
774
- };
775
- const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
776
-
557
+ static get isEvalSupported() {
558
+ return shadow(this, "isEvalSupported", isEvalSupported());
559
+ }
560
+ static get isOffscreenCanvasSupported() {
561
+ return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
562
+ }
563
+ static get platform() {
564
+ var _navigator;
565
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || typeof navigator !== "undefined" && typeof ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.platform) === "string") {
566
+ return shadow(this, "platform", {
567
+ isMac: navigator.platform.includes("Mac")
568
+ });
569
+ }
570
+ return shadow(this, "platform", {
571
+ isMac: false
572
+ });
573
+ }
574
+ static get isCSSRoundSupported() {
575
+ var _globalThis$CSS, _globalThis$CSS$suppo;
576
+ return shadow(this, "isCSSRoundSupported", (_globalThis$CSS = globalThis.CSS) === null || _globalThis$CSS === void 0 ? void 0 : (_globalThis$CSS$suppo = _globalThis$CSS.supports) === null || _globalThis$CSS$suppo === void 0 ? void 0 : _globalThis$CSS$suppo.call(_globalThis$CSS, "width: round(1.5px, 1px)"));
577
+ }
578
+ }
579
+ const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0"));
777
580
  class Util {
778
581
  static makeHexColor(r, g, b) {
779
582
  return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
780
- } // Concatenates two transformation matrices together and returns the result.
583
+ }
781
584
 
585
+ // Apply a scaling matrix to some min/max values.
586
+ // If a scaling factor is negative then min and max must be
587
+ // swapped.
588
+ static scaleMinMax(transform, minMax) {
589
+ let temp;
590
+ if (transform[0]) {
591
+ if (transform[0] < 0) {
592
+ temp = minMax[0];
593
+ minMax[0] = minMax[2];
594
+ minMax[2] = temp;
595
+ }
596
+ minMax[0] *= transform[0];
597
+ minMax[2] *= transform[0];
598
+ if (transform[3] < 0) {
599
+ temp = minMax[1];
600
+ minMax[1] = minMax[3];
601
+ minMax[3] = temp;
602
+ }
603
+ minMax[1] *= transform[3];
604
+ minMax[3] *= transform[3];
605
+ } else {
606
+ temp = minMax[0];
607
+ minMax[0] = minMax[1];
608
+ minMax[1] = temp;
609
+ temp = minMax[2];
610
+ minMax[2] = minMax[3];
611
+ minMax[3] = temp;
612
+ if (transform[1] < 0) {
613
+ temp = minMax[1];
614
+ minMax[1] = minMax[3];
615
+ minMax[3] = temp;
616
+ }
617
+ minMax[1] *= transform[1];
618
+ minMax[3] *= transform[1];
619
+ if (transform[2] < 0) {
620
+ temp = minMax[0];
621
+ minMax[0] = minMax[2];
622
+ minMax[2] = temp;
623
+ }
624
+ minMax[0] *= transform[2];
625
+ minMax[2] *= transform[2];
626
+ }
627
+ minMax[0] += transform[4];
628
+ minMax[1] += transform[5];
629
+ minMax[2] += transform[4];
630
+ minMax[3] += transform[5];
631
+ }
782
632
 
633
+ // Concatenates two transformation matrices together and returns the result.
783
634
  static transform(m1, m2) {
784
635
  return [m1[0] * m2[0] + m1[2] * m2[1], m1[1] * m2[0] + m1[3] * m2[1], m1[0] * m2[2] + m1[2] * m2[3], m1[1] * m2[2] + m1[3] * m2[3], m1[0] * m2[4] + m1[2] * m2[5] + m1[4], m1[1] * m2[4] + m1[3] * m2[5] + m1[5]];
785
- } // For 2d affine transforms
786
-
636
+ }
787
637
 
638
+ // For 2d affine transforms
788
639
  static applyTransform(p, m) {
789
640
  const xt = p[0] * m[0] + p[1] * m[2] + m[4];
790
641
  const yt = p[0] * m[1] + p[1] * m[3] + m[5];
791
642
  return [xt, yt];
792
643
  }
793
-
794
644
  static applyInverseTransform(p, m) {
795
645
  const d = m[0] * m[3] - m[1] * m[2];
796
646
  const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
797
647
  const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
798
648
  return [xt, yt];
799
- } // Applies the transform to the rectangle and finds the minimum axially
800
- // aligned bounding box.
801
-
649
+ }
802
650
 
651
+ // Applies the transform to the rectangle and finds the minimum axially
652
+ // aligned bounding box.
803
653
  static getAxialAlignedBoundingBox(r, m) {
804
- const p1 = Util.applyTransform(r, m);
805
- const p2 = Util.applyTransform(r.slice(2, 4), m);
806
- const p3 = Util.applyTransform([r[0], r[3]], m);
807
- const p4 = Util.applyTransform([r[2], r[1]], m);
654
+ const p1 = this.applyTransform(r, m);
655
+ const p2 = this.applyTransform(r.slice(2, 4), m);
656
+ const p3 = this.applyTransform([r[0], r[3]], m);
657
+ const p4 = this.applyTransform([r[2], r[1]], m);
808
658
  return [Math.min(p1[0], p2[0], p3[0], p4[0]), Math.min(p1[1], p2[1], p3[1], p4[1]), Math.max(p1[0], p2[0], p3[0], p4[0]), Math.max(p1[1], p2[1], p3[1], p4[1])];
809
659
  }
810
-
811
660
  static inverseTransform(m) {
812
661
  const d = m[0] * m[3] - m[1] * m[2];
813
662
  return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d, (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
814
- } // Apply a generic 3d matrix M on a 3-vector v:
815
- // | a b c | | X |
816
- // | d e f | x | Y |
817
- // | g h i | | Z |
818
- // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
819
- // with v as [X,Y,Z]
820
-
663
+ }
821
664
 
822
- static apply3dTransform(m, v) {
823
- return [m[0] * v[0] + m[1] * v[1] + m[2] * v[2], m[3] * v[0] + m[4] * v[1] + m[5] * v[2], m[6] * v[0] + m[7] * v[1] + m[8] * v[2]];
824
- } // This calculation uses Singular Value Decomposition.
665
+ // This calculation uses Singular Value Decomposition.
825
666
  // The SVD can be represented with formula A = USV. We are interested in the
826
667
  // matrix S here because it represents the scale values.
827
-
828
-
829
668
  static singularValueDecompose2dScale(m) {
830
- const transpose = [m[0], m[2], m[1], m[3]]; // Multiply matrix m with its transpose.
669
+ const transpose = [m[0], m[2], m[1], m[3]];
831
670
 
671
+ // Multiply matrix m with its transpose.
832
672
  const a = m[0] * transpose[0] + m[1] * transpose[2];
833
673
  const b = m[0] * transpose[1] + m[1] * transpose[3];
834
674
  const c = m[2] * transpose[0] + m[3] * transpose[2];
835
- const d = m[2] * transpose[1] + m[3] * transpose[3]; // Solve the second degree polynomial to get roots.
675
+ const d = m[2] * transpose[1] + m[3] * transpose[3];
836
676
 
677
+ // Solve the second degree polynomial to get roots.
837
678
  const first = (a + d) / 2;
838
679
  const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
839
680
  const sx = first + second || 1;
840
- const sy = first - second || 1; // Scale values are the square roots of the eigenvalues.
681
+ const sy = first - second || 1;
841
682
 
683
+ // Scale values are the square roots of the eigenvalues.
842
684
  return [Math.sqrt(sx), Math.sqrt(sy)];
843
- } // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
685
+ }
686
+
687
+ // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
844
688
  // For coordinate systems whose origin lies in the bottom-left, this
845
689
  // means normalization to (BL,TR) ordering. For systems with origin in the
846
690
  // top-left, this means (TL,BR) ordering.
847
-
848
-
849
691
  static normalizeRect(rect) {
850
692
  const r = rect.slice(0); // clone rect
851
-
852
693
  if (rect[0] > rect[2]) {
853
694
  r[0] = rect[2];
854
695
  r[2] = rect[0];
855
696
  }
856
-
857
697
  if (rect[1] > rect[3]) {
858
698
  r[1] = rect[3];
859
699
  r[3] = rect[1];
860
700
  }
861
-
862
701
  return r;
863
- } // Returns a rectangle [x1, y1, x2, y2] corresponding to the
864
- // intersection of rect1 and rect2. If no intersection, returns 'false'
865
- // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
866
-
702
+ }
867
703
 
704
+ // Returns a rectangle [x1, y1, x2, y2] corresponding to the
705
+ // intersection of rect1 and rect2. If no intersection, returns 'null'
706
+ // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
868
707
  static intersect(rect1, rect2) {
869
- function compare(a, b) {
870
- return a - b;
871
- } // Order points along the axes
872
-
873
-
874
- const orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare);
875
- const orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare);
876
- const result = [];
877
- rect1 = Util.normalizeRect(rect1);
878
- rect2 = Util.normalizeRect(rect2); // X: first and second points belong to different rectangles?
879
-
880
- if (orderedX[0] === rect1[0] && orderedX[1] === rect2[0] || orderedX[0] === rect2[0] && orderedX[1] === rect1[0]) {
881
- // Intersection must be between second and third points
882
- result[0] = orderedX[1];
883
- result[2] = orderedX[2];
884
- } else {
708
+ const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
709
+ const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
710
+ if (xLow > xHigh) {
885
711
  return null;
886
- } // Y: first and second points belong to different rectangles?
887
-
888
-
889
- if (orderedY[0] === rect1[1] && orderedY[1] === rect2[1] || orderedY[0] === rect2[1] && orderedY[1] === rect1[1]) {
890
- // Intersection must be between second and third points
891
- result[1] = orderedY[1];
892
- result[3] = orderedY[2];
893
- } else {
712
+ }
713
+ const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
714
+ const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
715
+ if (yLow > yHigh) {
894
716
  return null;
895
717
  }
896
-
897
- return result;
718
+ return [xLow, yLow, xHigh, yHigh];
898
719
  }
899
-
900
- }
901
-
902
- const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
903
-
904
- function stringToPDFString(str) {
905
- const length = str.length,
906
- strBuf = [];
907
-
908
- if (str[0] === "\xFE" && str[1] === "\xFF") {
909
- // UTF16BE BOM
910
- for (let i = 2; i < length; i += 2) {
911
- strBuf.push(String.fromCharCode(str.charCodeAt(i) << 8 | str.charCodeAt(i + 1)));
720
+ static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
721
+ if (t <= 0 || t >= 1) {
722
+ return;
912
723
  }
913
- } else if (str[0] === "\xFF" && str[1] === "\xFE") {
914
- // UTF16LE BOM
915
- for (let i = 2; i < length; i += 2) {
916
- strBuf.push(String.fromCharCode(str.charCodeAt(i + 1) << 8 | str.charCodeAt(i)));
724
+ const mt = 1 - t;
725
+ const tt = t * t;
726
+ const ttt = tt * t;
727
+ const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
728
+ const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
729
+ minMax[0] = Math.min(minMax[0], x);
730
+ minMax[1] = Math.min(minMax[1], y);
731
+ minMax[2] = Math.max(minMax[2], x);
732
+ minMax[3] = Math.max(minMax[3], y);
733
+ }
734
+ static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
735
+ if (Math.abs(a) < 1e-12) {
736
+ if (Math.abs(b) >= 1e-12) {
737
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
738
+ }
739
+ return;
917
740
  }
918
- } else {
919
- for (let i = 0; i < length; ++i) {
920
- const code = PDFStringTranslateTable[str.charCodeAt(i)];
921
- strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
741
+ const delta = b ** 2 - 4 * c * a;
742
+ if (delta < 0) {
743
+ return;
744
+ }
745
+ const sqrtDelta = Math.sqrt(delta);
746
+ const a2 = 2 * a;
747
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
748
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
749
+ }
750
+
751
+ // From https://github.com/adobe-webplatform/Snap.svg/blob/b365287722a72526000ac4bfcf0ce4cac2faa015/src/path.js#L852
752
+ static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
753
+ if (minMax) {
754
+ minMax[0] = Math.min(minMax[0], x0, x3);
755
+ minMax[1] = Math.min(minMax[1], y0, y3);
756
+ minMax[2] = Math.max(minMax[2], x0, x3);
757
+ minMax[3] = Math.max(minMax[3], y0, y3);
758
+ } else {
759
+ minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
922
760
  }
761
+ this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
762
+ this.#getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
763
+ return minMax;
923
764
  }
924
-
925
- return strBuf.join("");
926
765
  }
927
-
928
- function escapeString(str) {
929
- // replace "(", ")", "\n", "\r" and "\"
930
- // by "\(", "\)", "\\n", "\\r" and "\\"
931
- // in order to write it in a PDF file.
932
- return str.replace(/([()\\\n\r])/g, match => {
933
- if (match === "\n") {
934
- return "\\n";
935
- } else if (match === "\r") {
936
- return "\\r";
766
+ const PDFStringTranslateTable = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2d8, 0x2c7, 0x2c6, 0x2d9, 0x2dd, 0x2db, 0x2da, 0x2dc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014, 0x2013, 0x192, 0x2044, 0x2039, 0x203a, 0x2212, 0x2030, 0x201e, 0x201c, 0x201d, 0x2018, 0x2019, 0x201a, 0x2122, 0xfb01, 0xfb02, 0x141, 0x152, 0x160, 0x178, 0x17d, 0x131, 0x142, 0x153, 0x161, 0x17e, 0, 0x20ac];
767
+ function stringToPDFString(str) {
768
+ // See section 7.9.2.2 Text String Type.
769
+ // The string can contain some language codes bracketed with 0x0b,
770
+ // so we must remove them.
771
+ if (str[0] >= "\xEF") {
772
+ let encoding;
773
+ if (str[0] === "\xFE" && str[1] === "\xFF") {
774
+ encoding = "utf-16be";
775
+ if (str.length % 2 === 1) {
776
+ str = str.slice(0, -1);
777
+ }
778
+ } else if (str[0] === "\xFF" && str[1] === "\xFE") {
779
+ encoding = "utf-16le";
780
+ if (str.length % 2 === 1) {
781
+ str = str.slice(0, -1);
782
+ }
783
+ } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
784
+ encoding = "utf-8";
937
785
  }
938
-
939
- return `\\${match}`;
940
- });
941
- }
942
-
943
- function isAscii(str) {
944
- return /^[\x00-\x7F]*$/.test(str);
945
- }
946
-
947
- function stringToUTF16BEString(str) {
948
- const buf = ["\xFE\xFF"];
949
-
786
+ if (encoding) {
787
+ try {
788
+ const decoder = new TextDecoder(encoding, {
789
+ fatal: true
790
+ });
791
+ const buffer = stringToBytes(str);
792
+ const decoded = decoder.decode(buffer);
793
+ if (!decoded.includes("\x1b")) {
794
+ return decoded;
795
+ }
796
+ return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
797
+ } catch (ex) {
798
+ warn(`stringToPDFString: "${ex}".`);
799
+ }
800
+ }
801
+ }
802
+ // ISO Latin 1
803
+ const strBuf = [];
950
804
  for (let i = 0, ii = str.length; i < ii; i++) {
951
- const char = str.charCodeAt(i);
952
- buf.push(String.fromCharCode(char >> 8 & 0xff), String.fromCharCode(char & 0xff));
805
+ const charCode = str.charCodeAt(i);
806
+ if (charCode === 0x1b) {
807
+ // eslint-disable-next-line no-empty
808
+ while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
809
+ continue;
810
+ }
811
+ const code = PDFStringTranslateTable[charCode];
812
+ strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
953
813
  }
954
-
955
- return buf.join("");
814
+ return strBuf.join("");
956
815
  }
957
-
958
816
  function stringToUTF8String(str) {
959
817
  return decodeURIComponent(escape(str));
960
818
  }
961
-
962
819
  function utf8StringToString(str) {
963
820
  return unescape(encodeURIComponent(str));
964
821
  }
965
-
966
- function isBool(v) {
967
- return typeof v === "boolean";
968
- }
969
-
970
- function isNum(v) {
971
- return typeof v === "number";
972
- }
973
-
974
- function isString(v) {
975
- return typeof v === "string";
976
- }
977
-
978
- function isArrayBuffer(v) {
979
- return typeof v === "object" && v !== null && v.byteLength !== undefined;
980
- }
981
-
982
822
  function isArrayEqual(arr1, arr2) {
983
823
  if (arr1.length !== arr2.length) {
984
824
  return false;
985
825
  }
986
-
987
826
  for (let i = 0, ii = arr1.length; i < ii; i++) {
988
827
  if (arr1[i] !== arr2[i]) {
989
828
  return false;
990
829
  }
991
830
  }
992
-
993
831
  return true;
994
832
  }
995
-
996
833
  function getModificationDate(date = new Date()) {
997
834
  const buffer = [date.getUTCFullYear().toString(), (date.getUTCMonth() + 1).toString().padStart(2, "0"), date.getUTCDate().toString().padStart(2, "0"), date.getUTCHours().toString().padStart(2, "0"), date.getUTCMinutes().toString().padStart(2, "0"), date.getUTCSeconds().toString().padStart(2, "0")];
998
835
  return buffer.join("");
999
836
  }
1000
- /**
1001
- * Promise Capability object.
1002
- *
1003
- * @typedef {Object} PromiseCapability
1004
- * @property {Promise<any>} promise - A Promise object.
1005
- * @property {boolean} settled - If the Promise has been fulfilled/rejected.
1006
- * @property {function} resolve - Fulfills the Promise.
1007
- * @property {function} reject - Rejects the Promise.
1008
- */
1009
-
1010
- /**
1011
- * Creates a promise capability object.
1012
- * @alias createPromiseCapability
1013
- *
1014
- * @returns {PromiseCapability}
1015
- */
1016
-
1017
-
1018
- function createPromiseCapability() {
1019
- const capability = Object.create(null);
1020
- let isSettled = false;
1021
- Object.defineProperty(capability, "settled", {
1022
- get() {
1023
- return isSettled;
837
+ let NormalizeRegex = null;
838
+ let NormalizationMap = null;
839
+ function normalizeUnicode(str) {
840
+ if (!NormalizeRegex) {
841
+ // In order to generate the following regex:
842
+ // - create a PDF containing all the chars in the range 0000-FFFF with
843
+ // a NFKC which is different of the char.
844
+ // - copy and paste all those chars and get the ones where NFKC is
845
+ // required.
846
+ // It appears that most the chars here contain some ligatures.
847
+ NormalizeRegex = /([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc-\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa-\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;
848
+ NormalizationMap = new Map([["ſt", "ſt"]]);
849
+ }
850
+ return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
851
+ }
852
+ function getUuid() {
853
+ var _crypto, _crypto2;
854
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || typeof crypto !== "undefined" && typeof ((_crypto = crypto) === null || _crypto === void 0 ? void 0 : _crypto.randomUUID) === "function") {
855
+ return crypto.randomUUID();
856
+ }
857
+ const buf = new Uint8Array(32);
858
+ if (typeof crypto !== "undefined" && typeof ((_crypto2 = crypto) === null || _crypto2 === void 0 ? void 0 : _crypto2.getRandomValues) === "function") {
859
+ crypto.getRandomValues(buf);
860
+ } else {
861
+ for (let i = 0; i < 32; i++) {
862
+ buf[i] = Math.floor(Math.random() * 255);
1024
863
  }
1025
-
1026
- });
1027
- capability.promise = new Promise(function (resolve, reject) {
1028
- capability.resolve = function (data) {
1029
- isSettled = true;
1030
- resolve(data);
1031
- };
1032
-
1033
- capability.reject = function (reason) {
1034
- isSettled = true;
1035
- reject(reason);
1036
- };
1037
- });
1038
- return capability;
1039
- }
1040
-
1041
- function createObjectURL(data, contentType = "", forceDataSchema = false) {
1042
- if (URL.createObjectURL && !forceDataSchema) {
1043
- return URL.createObjectURL(new Blob([data], {
1044
- type: contentType
1045
- }));
1046
- } // Blob/createObjectURL is not available, falling back to data schema.
1047
-
1048
-
1049
- const digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
1050
- let buffer = `data:${contentType};base64,`;
1051
-
1052
- for (let i = 0, ii = data.length; i < ii; i += 3) {
1053
- const b1 = data[i] & 0xff;
1054
- const b2 = data[i + 1] & 0xff;
1055
- const b3 = data[i + 2] & 0xff;
1056
- const d1 = b1 >> 2,
1057
- d2 = (b1 & 3) << 4 | b2 >> 4;
1058
- const d3 = i + 1 < ii ? (b2 & 0xf) << 2 | b3 >> 6 : 64;
1059
- const d4 = i + 2 < ii ? b3 & 0x3f : 64;
1060
- buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
1061
864
  }
865
+ return bytesToString(buf);
866
+ }
867
+ const AnnotationPrefix = "pdfjs_internal_id_";
868
+ const FontRenderOps = {
869
+ BEZIER_CURVE_TO: 0,
870
+ MOVE_TO: 1,
871
+ LINE_TO: 2,
872
+ QUADRATIC_CURVE_TO: 3,
873
+ RESTORE: 4,
874
+ SAVE: 5,
875
+ SCALE: 6,
876
+ TRANSFORM: 7,
877
+ TRANSLATE: 8
878
+ };
1062
879
 
1063
- return buffer;
1064
- }
1065
-
1066
- export { utf8StringToString as $, AbortException as A, stringToPDFString as B, createObjectURL as C, CMapCompressionType as D, createValidAbsoluteUrl as E, FormatError as F, PasswordResponses as G, PermissionFlag as H, IsEvalSupportedCached as I, removeNullCharacters as J, BaseException as K, isString as L, MissingPDFException as M, objectSize as N, OPS as O, PasswordException as P, arrayByteLength as Q, arraysToBytes as R, StreamType as S, TextRenderingMode as T, UNSUPPORTED_FEATURES as U, VerbosityLevel as V, FontType as W, isBool as X, isArrayEqual as Y, stringToUTF8String as Z, DocumentActionEventType as _, string32 as a, escapeString as a0, AnnotationFlag as a1, AnnotationFieldFlag as a2, isAscii as a3, stringToUTF16BEString as a4, getModificationDate as a5, AnnotationReplyType as a6, AnnotationActionEventType as a7, PageActionEventType as a8, bytesToString as b, assert as c, info as d, Util as e, IDENTITY_MATRIX as f, FONT_IDENTITY_MATRIX as g, isNum as h, isNodeJS as i, ImageKind as j, IsLittleEndianCached as k, createPromiseCapability as l, isArrayBuffer as m, stringToBytes as n, objectFromMap as o, setVerbosityLevel as p, getVerbosityLevel as q, isSameOrigin as r, shadow as s, UnknownErrorException as t, unreachable as u, UnexpectedResponseException as v, warn as w, InvalidPDFException as x, AnnotationType as y, AnnotationBorderStyleType as z };
880
+ export { AnnotationFieldFlag as $, AnnotationEditorType as A, AnnotationType as B, AnnotationBorderStyleType as C, CMapCompressionType as D, createValidAbsoluteUrl as E, FeatureTest as F, normalizeUnicode as G, PasswordResponses as H, IDENTITY_MATRIX as I, PermissionFlag as J, BaseException as K, LINE_FACTOR as L, MissingPDFException as M, objectSize as N, OPS as O, PasswordException as P, stringToPDFString as Q, RenderingIntentFlag as R, isArrayEqual as S, TextRenderingMode as T, Util as U, VerbosityLevel as V, LINE_DESCENT_FACTOR as W, utf8StringToString as X, stringToUTF8String as Y, DocumentActionEventType as Z, AnnotationFlag as _, AnnotationEditorParamsType as a, getModificationDate as a0, AnnotationActionEventType as a1, AnnotationReplyType as a2, BASELINE_FACTOR as a3, PageActionEventType as a4, AnnotationEditorPrefix as b, assert as c, string32 as d, bytesToString as e, FontRenderOps as f, getUuid as g, info as h, isNodeJS as i, FormatError as j, FONT_IDENTITY_MATRIX as k, ImageKind as l, AbortException as m, stringToBytes as n, objectFromMap as o, setVerbosityLevel as p, getVerbosityLevel as q, AnnotationMode as r, shadow as s, UnknownErrorException as t, unreachable as u, UnexpectedResponseException as v, warn as w, InvalidPDFException as x, MAX_IMAGE_SIZE_TO_CACHE as y, AnnotationPrefix as z };