@vaadin-component-factory/vcf-pdf-viewer 4.0.2 → 4.1.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,
@@ -169,10 +98,6 @@ const TextRenderingMode = {
169
98
  STROKE: 1,
170
99
  FILL_STROKE: 2,
171
100
  INVISIBLE: 3,
172
- FILL_ADD_TO_PATH: 4,
173
- STROKE_ADD_TO_PATH: 5,
174
- FILL_STROKE_ADD_TO_PATH: 6,
175
- ADD_TO_PATH: 7,
176
101
  FILL_STROKE_MASK: 3,
177
102
  ADD_TO_PATH_FLAG: 4
178
103
  };
@@ -199,16 +124,7 @@ const AnnotationType = {
199
124
  INK: 15,
200
125
  POPUP: 16,
201
126
  FILEATTACHMENT: 17,
202
- SOUND: 18,
203
- MOVIE: 19,
204
- WIDGET: 20,
205
- SCREEN: 21,
206
- PRINTERMARK: 22,
207
- TRAPNET: 23,
208
- WATERMARK: 24,
209
- THREED: 25,
210
- REDACT: 26
211
- };
127
+ WIDGET: 20};
212
128
  const AnnotationReplyType = {
213
129
  GROUP: "Group",
214
130
  REPLY: "R"
@@ -217,35 +133,23 @@ const AnnotationFlag = {
217
133
  INVISIBLE: 0x01,
218
134
  HIDDEN: 0x02,
219
135
  PRINT: 0x04,
220
- NOZOOM: 0x08,
221
136
  NOROTATE: 0x10,
222
137
  NOVIEW: 0x20,
223
- READONLY: 0x40,
224
138
  LOCKED: 0x80,
225
- TOGGLENOVIEW: 0x100,
226
139
  LOCKEDCONTENTS: 0x200
227
140
  };
228
141
  const AnnotationFieldFlag = {
229
142
  READONLY: 0x0000001,
230
143
  REQUIRED: 0x0000002,
231
- NOEXPORT: 0x0000004,
232
144
  MULTILINE: 0x0001000,
233
145
  PASSWORD: 0x0002000,
234
- NOTOGGLETOOFF: 0x0004000,
235
146
  RADIO: 0x0008000,
236
147
  PUSHBUTTON: 0x0010000,
237
148
  COMBO: 0x0020000,
238
- EDIT: 0x0040000,
239
- SORT: 0x0080000,
240
149
  FILESELECT: 0x0100000,
241
150
  MULTISELECT: 0x0200000,
242
- DONOTSPELLCHECK: 0x0400000,
243
151
  DONOTSCROLL: 0x0800000,
244
- COMB: 0x1000000,
245
- RICHTEXT: 0x2000000,
246
- RADIOSINUNISON: 0x2000000,
247
- COMMITONSELCHANGE: 0x4000000
248
- };
152
+ COMB: 0x1000000};
249
153
  const AnnotationBorderStyleType = {
250
154
  SOLID: 1,
251
155
  DASHED: 2,
@@ -280,33 +184,6 @@ const PageActionEventType = {
280
184
  O: "PageOpen",
281
185
  C: "PageClose"
282
186
  };
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
187
  const VerbosityLevel = {
311
188
  ERRORS: 0,
312
189
  WARNINGS: 1,
@@ -314,13 +191,15 @@ const VerbosityLevel = {
314
191
  };
315
192
  const CMapCompressionType = {
316
193
  NONE: 0,
317
- BINARY: 1,
318
- STREAM: 2
319
- }; // All the possible operations for an operator list.
194
+ BINARY: 1
195
+ };
320
196
 
197
+ // All the possible operations for an operator list.
321
198
  const OPS = {
322
199
  // Intentionally start from 1 so it is easy to spot bad operators that will be
323
200
  // 0's.
201
+ // PLEASE NOTE: We purposely keep any removed operators commented out, since
202
+ // re-numbering the list would risk breaking third-party users.
324
203
  dependency: 1,
325
204
  setLineWidth: 2,
326
205
  setLineCap: 3,
@@ -398,11 +277,11 @@ const OPS = {
398
277
  paintFormXObjectEnd: 75,
399
278
  beginGroup: 76,
400
279
  endGroup: 77,
401
- beginAnnotations: 78,
402
- endAnnotations: 79,
280
+ // beginAnnotations: 78,
281
+ // endAnnotations: 79,
403
282
  beginAnnotation: 80,
404
283
  endAnnotation: 81,
405
- paintJpegXObject: 82,
284
+ // paintJpegXObject: 82,
406
285
  paintImageMaskXObject: 83,
407
286
  paintImageMaskXObjectGroup: 84,
408
287
  paintImageXObject: 85,
@@ -413,335 +292,223 @@ const OPS = {
413
292
  paintSolidColorImageMask: 90,
414
293
  constructPath: 91
415
294
  };
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
295
  const PasswordResponses = {
443
296
  NEED_PASSWORD: 1,
444
297
  INCORRECT_PASSWORD: 2
445
298
  };
446
299
  let verbosity = VerbosityLevel.WARNINGS;
447
-
448
300
  function setVerbosityLevel(level) {
449
301
  if (Number.isInteger(level)) {
450
302
  verbosity = level;
451
303
  }
452
304
  }
453
-
454
305
  function getVerbosityLevel() {
455
306
  return verbosity;
456
- } // A notice for devs. These are good for things that are helpful to devs, such
307
+ }
308
+
309
+ // A notice for devs. These are good for things that are helpful to devs, such
457
310
  // as warning that Workers were disabled, which is important to devs but not
458
311
  // end users.
459
-
460
-
461
312
  function info(msg) {
462
313
  if (verbosity >= VerbosityLevel.INFOS) {
463
314
  console.log(`Info: ${msg}`);
464
315
  }
465
- } // Non-fatal warnings.
466
-
316
+ }
467
317
 
318
+ // Non-fatal warnings.
468
319
  function warn(msg) {
469
320
  if (verbosity >= VerbosityLevel.WARNINGS) {
470
321
  console.log(`Warning: ${msg}`);
471
322
  }
472
323
  }
473
-
474
324
  function unreachable(msg) {
475
325
  throw new Error(msg);
476
326
  }
477
-
478
327
  function assert(cond, msg) {
479
328
  if (!cond) {
480
329
  unreachable(msg);
481
330
  }
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
-
331
+ }
502
332
 
333
+ // Checks if URLs use one of the allowed protocols, e.g. to avoid XSS.
503
334
  function _isValidProtocol(url) {
504
- if (!url) {
505
- return false;
506
- }
507
-
508
- switch (url.protocol) {
335
+ switch (url === null || url === void 0 ? void 0 : url.protocol) {
509
336
  case "http:":
510
337
  case "https:":
511
338
  case "ftp:":
512
339
  case "mailto:":
513
340
  case "tel:":
514
341
  return true;
515
-
516
342
  default:
517
343
  return false;
518
344
  }
519
345
  }
346
+
520
347
  /**
521
348
  * Attempts to create a valid absolute URL.
522
349
  *
523
350
  * @param {URL|string} url - An absolute, or relative, URL.
524
- * @param {URL|string} baseUrl - An absolute URL.
351
+ * @param {URL|string} [baseUrl] - An absolute URL.
352
+ * @param {Object} [options]
525
353
  * @returns Either a valid {URL}, or `null` otherwise.
526
354
  */
527
-
528
-
529
- function createValidAbsoluteUrl(url, baseUrl) {
355
+ function createValidAbsoluteUrl(url, baseUrl = null, options = null) {
530
356
  if (!url) {
531
357
  return null;
532
358
  }
533
-
534
359
  try {
535
- const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
360
+ if (options && typeof url === "string") {
361
+ // Let URLs beginning with "www." default to using the "http://" protocol.
362
+ if (options.addDefaultProtocol && url.startsWith("www.")) {
363
+ const dots = url.match(/\./g);
364
+ // Avoid accidentally matching a *relative* URL pointing to a file named
365
+ // e.g. "www.pdf" or similar.
366
+ if ((dots === null || dots === void 0 ? void 0 : dots.length) >= 2) {
367
+ url = `http://${url}`;
368
+ }
369
+ }
536
370
 
371
+ // According to ISO 32000-1:2008, section 12.6.4.7, URIs should be encoded
372
+ // in 7-bit ASCII. Some bad PDFs use UTF-8 encoding; see bug 1122280.
373
+ if (options.tryConvertEncoding) {
374
+ try {
375
+ url = stringToUTF8String(url);
376
+ } catch {}
377
+ }
378
+ }
379
+ const absoluteUrl = baseUrl ? new URL(url, baseUrl) : new URL(url);
537
380
  if (_isValidProtocol(absoluteUrl)) {
538
381
  return absoluteUrl;
539
382
  }
540
- } catch (ex) {
383
+ } catch {
541
384
  /* `new URL()` will throw on incorrect data. */
542
385
  }
543
-
544
386
  return null;
545
387
  }
546
-
547
- function shadow(obj, prop, value) {
388
+ function shadow(obj, prop, value, nonSerializable = false) {
389
+ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
390
+ assert(prop in obj, `shadow: Property "${prop && prop.toString()}" not found in object.`);
391
+ }
548
392
  Object.defineProperty(obj, prop, {
549
393
  value,
550
- enumerable: true,
394
+ enumerable: !nonSerializable,
551
395
  configurable: true,
552
396
  writable: false
553
397
  });
554
398
  return value;
555
399
  }
400
+
556
401
  /**
557
402
  * @type {any}
558
403
  */
559
-
560
-
561
404
  const BaseException = function BaseExceptionClosure() {
562
405
  // eslint-disable-next-line no-shadow
563
- function BaseException(message) {
406
+ function BaseException(message, name) {
564
407
  if (this.constructor === BaseException) {
565
408
  unreachable("Cannot initialize BaseException.");
566
409
  }
567
-
568
410
  this.message = message;
569
- this.name = this.constructor.name;
411
+ this.name = name;
570
412
  }
571
-
572
413
  BaseException.prototype = new Error();
573
414
  BaseException.constructor = BaseException;
574
415
  return BaseException;
575
416
  }();
576
-
577
417
  class PasswordException extends BaseException {
578
418
  constructor(msg, code) {
579
- super(msg);
419
+ super(msg, "PasswordException");
580
420
  this.code = code;
581
421
  }
582
-
583
422
  }
584
-
585
423
  class UnknownErrorException extends BaseException {
586
424
  constructor(msg, details) {
587
- super(msg);
425
+ super(msg, "UnknownErrorException");
588
426
  this.details = details;
589
427
  }
590
-
591
428
  }
592
-
593
- class InvalidPDFException extends BaseException {}
594
-
595
- class MissingPDFException extends BaseException {}
596
-
429
+ class InvalidPDFException extends BaseException {
430
+ constructor(msg) {
431
+ super(msg, "InvalidPDFException");
432
+ }
433
+ }
434
+ class MissingPDFException extends BaseException {
435
+ constructor(msg) {
436
+ super(msg, "MissingPDFException");
437
+ }
438
+ }
597
439
  class UnexpectedResponseException extends BaseException {
598
440
  constructor(msg, status) {
599
- super(msg);
441
+ super(msg, "UnexpectedResponseException");
600
442
  this.status = status;
601
443
  }
602
-
603
444
  }
445
+
604
446
  /**
605
447
  * Error caused during parsing PDF data.
606
448
  */
449
+ class FormatError extends BaseException {
450
+ constructor(msg) {
451
+ super(msg, "FormatError");
452
+ }
453
+ }
607
454
 
608
-
609
- class FormatError extends BaseException {}
610
455
  /**
611
456
  * Error used to indicate task cancellation.
612
457
  */
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;
458
+ class AbortException extends BaseException {
459
+ constructor(msg) {
460
+ super(msg, "AbortException");
626
461
  }
627
-
628
- return str.replace(NullCharactersRegExp, "");
629
462
  }
630
-
631
463
  function bytesToString(bytes) {
632
- assert(bytes !== null && typeof bytes === "object" && bytes.length !== undefined, "Invalid argument for bytesToString");
464
+ if (typeof bytes !== "object" || (bytes === null || bytes === void 0 ? void 0 : bytes.length) === undefined) {
465
+ unreachable("Invalid argument for bytesToString");
466
+ }
633
467
  const length = bytes.length;
634
468
  const MAX_ARGUMENT_COUNT = 8192;
635
-
636
469
  if (length < MAX_ARGUMENT_COUNT) {
637
470
  return String.fromCharCode.apply(null, bytes);
638
471
  }
639
-
640
472
  const strBuf = [];
641
-
642
473
  for (let i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
643
474
  const chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
644
475
  const chunk = bytes.subarray(i, chunkEnd);
645
476
  strBuf.push(String.fromCharCode.apply(null, chunk));
646
477
  }
647
-
648
478
  return strBuf.join("");
649
479
  }
650
-
651
480
  function stringToBytes(str) {
652
- assert(typeof str === "string", "Invalid argument for stringToBytes");
481
+ if (typeof str !== "string") {
482
+ unreachable("Invalid argument for stringToBytes");
483
+ }
653
484
  const length = str.length;
654
485
  const bytes = new Uint8Array(length);
655
-
656
486
  for (let i = 0; i < length; ++i) {
657
487
  bytes[i] = str.charCodeAt(i) & 0xff;
658
488
  }
659
-
660
489
  return bytes;
661
490
  }
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
491
  function string32(value) {
721
- if (typeof PDFJSDev === "undefined" || PDFJSDev.test("!PRODUCTION || TESTING")) {
492
+ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
722
493
  assert(typeof value === "number" && Math.abs(value) < 2 ** 32, `string32: Unexpected input "${value}".`);
723
494
  }
724
-
725
495
  return String.fromCharCode(value >> 24 & 0xff, value >> 16 & 0xff, value >> 8 & 0xff, value & 0xff);
726
496
  }
727
-
728
497
  function objectSize(obj) {
729
498
  return Object.keys(obj).length;
730
- } // Ensure that the returned Object has a `null` prototype; hence why
731
- // `Object.fromEntries(...)` is not used.
732
-
499
+ }
733
500
 
501
+ // Ensure that the returned Object has a `null` prototype; hence why
502
+ // `Object.fromEntries(...)` is not used.
734
503
  function objectFromMap(map) {
735
504
  const obj = Object.create(null);
736
-
737
505
  for (const [key, value] of map) {
738
506
  obj[key] = value;
739
507
  }
740
-
741
508
  return obj;
742
- } // Checks the endianness of the platform.
743
-
509
+ }
744
510
 
511
+ // Checks the endianness of the platform.
745
512
  function isLittleEndian() {
746
513
  const buffer8 = new Uint8Array(4);
747
514
  buffer8[0] = 1;
@@ -749,318 +516,340 @@ function isLittleEndian() {
749
516
  return view32[0] === 1;
750
517
  }
751
518
 
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
-
519
+ // Checks if it's possible to eval JS expressions.
759
520
  function isEvalSupported() {
760
521
  try {
761
522
  new Function(""); // eslint-disable-line no-new, no-new-func
762
-
763
523
  return true;
764
- } catch (e) {
524
+ } catch {
765
525
  return false;
766
526
  }
767
527
  }
768
-
769
- const IsEvalSupportedCached = {
770
- get value() {
771
- return shadow(this, "value", isEvalSupported());
528
+ class FeatureTest {
529
+ static get isLittleEndian() {
530
+ return shadow(this, "isLittleEndian", isLittleEndian());
772
531
  }
773
-
774
- };
775
- const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
776
-
532
+ static get isEvalSupported() {
533
+ return shadow(this, "isEvalSupported", isEvalSupported());
534
+ }
535
+ static get isOffscreenCanvasSupported() {
536
+ return shadow(this, "isOffscreenCanvasSupported", typeof OffscreenCanvas !== "undefined");
537
+ }
538
+ static get platform() {
539
+ var _navigator;
540
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || typeof navigator !== "undefined" && typeof ((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.platform) === "string") {
541
+ return shadow(this, "platform", {
542
+ isMac: navigator.platform.includes("Mac")
543
+ });
544
+ }
545
+ return shadow(this, "platform", {
546
+ isMac: false
547
+ });
548
+ }
549
+ static get isCSSRoundSupported() {
550
+ var _globalThis$CSS, _globalThis$CSS$suppo;
551
+ 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)"));
552
+ }
553
+ }
554
+ const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0"));
777
555
  class Util {
778
556
  static makeHexColor(r, g, b) {
779
557
  return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
780
- } // Concatenates two transformation matrices together and returns the result.
558
+ }
781
559
 
560
+ // Apply a scaling matrix to some min/max values.
561
+ // If a scaling factor is negative then min and max must be
562
+ // swapped.
563
+ static scaleMinMax(transform, minMax) {
564
+ let temp;
565
+ if (transform[0]) {
566
+ if (transform[0] < 0) {
567
+ temp = minMax[0];
568
+ minMax[0] = minMax[2];
569
+ minMax[2] = temp;
570
+ }
571
+ minMax[0] *= transform[0];
572
+ minMax[2] *= transform[0];
573
+ if (transform[3] < 0) {
574
+ temp = minMax[1];
575
+ minMax[1] = minMax[3];
576
+ minMax[3] = temp;
577
+ }
578
+ minMax[1] *= transform[3];
579
+ minMax[3] *= transform[3];
580
+ } else {
581
+ temp = minMax[0];
582
+ minMax[0] = minMax[1];
583
+ minMax[1] = temp;
584
+ temp = minMax[2];
585
+ minMax[2] = minMax[3];
586
+ minMax[3] = temp;
587
+ if (transform[1] < 0) {
588
+ temp = minMax[1];
589
+ minMax[1] = minMax[3];
590
+ minMax[3] = temp;
591
+ }
592
+ minMax[1] *= transform[1];
593
+ minMax[3] *= transform[1];
594
+ if (transform[2] < 0) {
595
+ temp = minMax[0];
596
+ minMax[0] = minMax[2];
597
+ minMax[2] = temp;
598
+ }
599
+ minMax[0] *= transform[2];
600
+ minMax[2] *= transform[2];
601
+ }
602
+ minMax[0] += transform[4];
603
+ minMax[1] += transform[5];
604
+ minMax[2] += transform[4];
605
+ minMax[3] += transform[5];
606
+ }
782
607
 
608
+ // Concatenates two transformation matrices together and returns the result.
783
609
  static transform(m1, m2) {
784
610
  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
-
611
+ }
787
612
 
613
+ // For 2d affine transforms
788
614
  static applyTransform(p, m) {
789
615
  const xt = p[0] * m[0] + p[1] * m[2] + m[4];
790
616
  const yt = p[0] * m[1] + p[1] * m[3] + m[5];
791
617
  return [xt, yt];
792
618
  }
793
-
794
619
  static applyInverseTransform(p, m) {
795
620
  const d = m[0] * m[3] - m[1] * m[2];
796
621
  const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
797
622
  const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
798
623
  return [xt, yt];
799
- } // Applies the transform to the rectangle and finds the minimum axially
800
- // aligned bounding box.
801
-
624
+ }
802
625
 
626
+ // Applies the transform to the rectangle and finds the minimum axially
627
+ // aligned bounding box.
803
628
  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);
629
+ const p1 = this.applyTransform(r, m);
630
+ const p2 = this.applyTransform(r.slice(2, 4), m);
631
+ const p3 = this.applyTransform([r[0], r[3]], m);
632
+ const p4 = this.applyTransform([r[2], r[1]], m);
808
633
  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
634
  }
810
-
811
635
  static inverseTransform(m) {
812
636
  const d = m[0] * m[3] - m[1] * m[2];
813
637
  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
-
638
+ }
821
639
 
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.
640
+ // This calculation uses Singular Value Decomposition.
825
641
  // The SVD can be represented with formula A = USV. We are interested in the
826
642
  // matrix S here because it represents the scale values.
827
-
828
-
829
643
  static singularValueDecompose2dScale(m) {
830
- const transpose = [m[0], m[2], m[1], m[3]]; // Multiply matrix m with its transpose.
644
+ const transpose = [m[0], m[2], m[1], m[3]];
831
645
 
646
+ // Multiply matrix m with its transpose.
832
647
  const a = m[0] * transpose[0] + m[1] * transpose[2];
833
648
  const b = m[0] * transpose[1] + m[1] * transpose[3];
834
649
  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.
650
+ const d = m[2] * transpose[1] + m[3] * transpose[3];
836
651
 
652
+ // Solve the second degree polynomial to get roots.
837
653
  const first = (a + d) / 2;
838
654
  const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
839
655
  const sx = first + second || 1;
840
- const sy = first - second || 1; // Scale values are the square roots of the eigenvalues.
656
+ const sy = first - second || 1;
841
657
 
658
+ // Scale values are the square roots of the eigenvalues.
842
659
  return [Math.sqrt(sx), Math.sqrt(sy)];
843
- } // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
660
+ }
661
+
662
+ // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
844
663
  // For coordinate systems whose origin lies in the bottom-left, this
845
664
  // means normalization to (BL,TR) ordering. For systems with origin in the
846
665
  // top-left, this means (TL,BR) ordering.
847
-
848
-
849
666
  static normalizeRect(rect) {
850
667
  const r = rect.slice(0); // clone rect
851
-
852
668
  if (rect[0] > rect[2]) {
853
669
  r[0] = rect[2];
854
670
  r[2] = rect[0];
855
671
  }
856
-
857
672
  if (rect[1] > rect[3]) {
858
673
  r[1] = rect[3];
859
674
  r[3] = rect[1];
860
675
  }
861
-
862
676
  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
-
677
+ }
867
678
 
679
+ // Returns a rectangle [x1, y1, x2, y2] corresponding to the
680
+ // intersection of rect1 and rect2. If no intersection, returns 'null'
681
+ // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
868
682
  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 {
683
+ const xLow = Math.max(Math.min(rect1[0], rect1[2]), Math.min(rect2[0], rect2[2]));
684
+ const xHigh = Math.min(Math.max(rect1[0], rect1[2]), Math.max(rect2[0], rect2[2]));
685
+ if (xLow > xHigh) {
885
686
  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 {
687
+ }
688
+ const yLow = Math.max(Math.min(rect1[1], rect1[3]), Math.min(rect2[1], rect2[3]));
689
+ const yHigh = Math.min(Math.max(rect1[1], rect1[3]), Math.max(rect2[1], rect2[3]));
690
+ if (yLow > yHigh) {
894
691
  return null;
895
692
  }
896
-
897
- return result;
693
+ return [xLow, yLow, xHigh, yHigh];
898
694
  }
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)));
695
+ static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
696
+ if (t <= 0 || t >= 1) {
697
+ return;
698
+ }
699
+ const mt = 1 - t;
700
+ const tt = t * t;
701
+ const ttt = tt * t;
702
+ const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
703
+ const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
704
+ minMax[0] = Math.min(minMax[0], x);
705
+ minMax[1] = Math.min(minMax[1], y);
706
+ minMax[2] = Math.max(minMax[2], x);
707
+ minMax[3] = Math.max(minMax[3], y);
708
+ }
709
+ static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
710
+ if (Math.abs(a) < 1e-12) {
711
+ if (Math.abs(b) >= 1e-12) {
712
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
713
+ }
714
+ return;
912
715
  }
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)));
716
+ const delta = b ** 2 - 4 * c * a;
717
+ if (delta < 0) {
718
+ return;
917
719
  }
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));
720
+ const sqrtDelta = Math.sqrt(delta);
721
+ const a2 = 2 * a;
722
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
723
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
724
+ }
725
+
726
+ // From https://github.com/adobe-webplatform/Snap.svg/blob/b365287722a72526000ac4bfcf0ce4cac2faa015/src/path.js#L852
727
+ static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
728
+ if (minMax) {
729
+ minMax[0] = Math.min(minMax[0], x0, x3);
730
+ minMax[1] = Math.min(minMax[1], y0, y3);
731
+ minMax[2] = Math.max(minMax[2], x0, x3);
732
+ minMax[3] = Math.max(minMax[3], y0, y3);
733
+ } else {
734
+ minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
922
735
  }
736
+ 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);
737
+ 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);
738
+ return minMax;
923
739
  }
924
-
925
- return strBuf.join("");
926
740
  }
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";
741
+ 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];
742
+ function stringToPDFString(str) {
743
+ // See section 7.9.2.2 Text String Type.
744
+ // The string can contain some language codes bracketed with 0x0b,
745
+ // so we must remove them.
746
+ if (str[0] >= "\xEF") {
747
+ let encoding;
748
+ if (str[0] === "\xFE" && str[1] === "\xFF") {
749
+ encoding = "utf-16be";
750
+ if (str.length % 2 === 1) {
751
+ str = str.slice(0, -1);
752
+ }
753
+ } else if (str[0] === "\xFF" && str[1] === "\xFE") {
754
+ encoding = "utf-16le";
755
+ if (str.length % 2 === 1) {
756
+ str = str.slice(0, -1);
757
+ }
758
+ } else if (str[0] === "\xEF" && str[1] === "\xBB" && str[2] === "\xBF") {
759
+ encoding = "utf-8";
937
760
  }
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
-
761
+ if (encoding) {
762
+ try {
763
+ const decoder = new TextDecoder(encoding, {
764
+ fatal: true
765
+ });
766
+ const buffer = stringToBytes(str);
767
+ const decoded = decoder.decode(buffer);
768
+ if (!decoded.includes("\x1b")) {
769
+ return decoded;
770
+ }
771
+ return decoded.replaceAll(/\x1b[^\x1b]*(?:\x1b|$)/g, "");
772
+ } catch (ex) {
773
+ warn(`stringToPDFString: "${ex}".`);
774
+ }
775
+ }
776
+ }
777
+ // ISO Latin 1
778
+ const strBuf = [];
950
779
  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));
780
+ const charCode = str.charCodeAt(i);
781
+ if (charCode === 0x1b) {
782
+ // eslint-disable-next-line no-empty
783
+ while (++i < ii && str.charCodeAt(i) !== 0x1b) {}
784
+ continue;
785
+ }
786
+ const code = PDFStringTranslateTable[charCode];
787
+ strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
953
788
  }
954
-
955
- return buf.join("");
789
+ return strBuf.join("");
956
790
  }
957
-
958
791
  function stringToUTF8String(str) {
959
792
  return decodeURIComponent(escape(str));
960
793
  }
961
-
962
794
  function utf8StringToString(str) {
963
795
  return unescape(encodeURIComponent(str));
964
796
  }
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
797
  function isArrayEqual(arr1, arr2) {
983
798
  if (arr1.length !== arr2.length) {
984
799
  return false;
985
800
  }
986
-
987
801
  for (let i = 0, ii = arr1.length; i < ii; i++) {
988
802
  if (arr1[i] !== arr2[i]) {
989
803
  return false;
990
804
  }
991
805
  }
992
-
993
806
  return true;
994
807
  }
995
-
996
808
  function getModificationDate(date = new Date()) {
997
809
  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
810
  return buffer.join("");
999
811
  }
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;
812
+ let NormalizeRegex = null;
813
+ let NormalizationMap = null;
814
+ function normalizeUnicode(str) {
815
+ if (!NormalizeRegex) {
816
+ // In order to generate the following regex:
817
+ // - create a PDF containing all the chars in the range 0000-FFFF with
818
+ // a NFKC which is different of the char.
819
+ // - copy and paste all those chars and get the ones where NFKC is
820
+ // required.
821
+ // It appears that most the chars here contain some ligatures.
822
+ 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;
823
+ NormalizationMap = new Map([["ſt", "ſt"]]);
824
+ }
825
+ return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
826
+ }
827
+ function getUuid() {
828
+ var _crypto, _crypto2;
829
+ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("MOZCENTRAL") || typeof crypto !== "undefined" && typeof ((_crypto = crypto) === null || _crypto === void 0 ? void 0 : _crypto.randomUUID) === "function") {
830
+ return crypto.randomUUID();
831
+ }
832
+ const buf = new Uint8Array(32);
833
+ if (typeof crypto !== "undefined" && typeof ((_crypto2 = crypto) === null || _crypto2 === void 0 ? void 0 : _crypto2.getRandomValues) === "function") {
834
+ crypto.getRandomValues(buf);
835
+ } else {
836
+ for (let i = 0; i < 32; i++) {
837
+ buf[i] = Math.floor(Math.random() * 255);
1024
838
  }
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
839
  }
840
+ return bytesToString(buf);
841
+ }
842
+ const AnnotationPrefix = "pdfjs_internal_id_";
843
+ const FontRenderOps = {
844
+ BEZIER_CURVE_TO: 0,
845
+ MOVE_TO: 1,
846
+ LINE_TO: 2,
847
+ QUADRATIC_CURVE_TO: 3,
848
+ RESTORE: 4,
849
+ SAVE: 5,
850
+ SCALE: 6,
851
+ TRANSFORM: 7,
852
+ TRANSLATE: 8
853
+ };
1062
854
 
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 };
855
+ export { getModificationDate as $, AnnotationMode as A, MAX_IMAGE_SIZE_TO_CACHE as B, AnnotationBorderStyleType as C, AnnotationPrefix as D, AnnotationType as E, FeatureTest as F, CMapCompressionType as G, createValidAbsoluteUrl as H, IDENTITY_MATRIX as I, PasswordResponses as J, BaseException as K, LINE_FACTOR as L, MissingPDFException as M, objectSize as N, OPS as O, PermissionFlag 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 _, AbortException as a, AnnotationReplyType as a0, AnnotationFieldFlag as a1, BASELINE_FACTOR as a2, AnnotationActionEventType as a3, PageActionEventType as a4, AnnotationEditorType as b, AnnotationEditorParamsType as c, AnnotationEditorPrefix as d, assert as e, string32 as f, getUuid as g, bytesToString as h, isNodeJS as i, FontRenderOps as j, FormatError as k, info as l, FONT_IDENTITY_MATRIX as m, normalizeUnicode as n, objectFromMap as o, ImageKind as p, stringToBytes as q, setVerbosityLevel as r, shadow as s, getVerbosityLevel as t, unreachable as u, UnknownErrorException as v, warn as w, UnexpectedResponseException as x, InvalidPDFException as y, PasswordException as z };