@ntlab/ntjs-assets 2.0.11 → 2.0.13

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.
Files changed (92) hide show
  1. package/.github/workflows/publish.yml +2 -1
  2. package/assets/js/DataTables/Extensions/ColReorder/js/dataTables.colReorder.js +4 -55
  3. package/assets/js/DataTables/Extensions/ColReorder/js/dataTables.colReorder.min.js +4 -4
  4. package/assets/js/DataTables/Extensions/SearchBuilder/css/searchBuilder.bootstrap5.css +1 -1
  5. package/assets/js/DataTables/Extensions/SearchBuilder/css/searchBuilder.bootstrap5.min.css +1 -1
  6. package/assets/js/DataTables/Extensions/SearchBuilder/css/searchBuilder.dataTables.css +1 -1
  7. package/assets/js/DataTables/Extensions/SearchBuilder/css/searchBuilder.dataTables.min.css +1 -1
  8. package/assets/js/DataTables/Extensions/SearchBuilder/js/dataTables.searchBuilder.js +8 -8
  9. package/assets/js/DataTables/Extensions/SearchBuilder/js/dataTables.searchBuilder.min.js +3 -3
  10. package/assets/js/DataTables/Extensions/SearchBuilder/js/searchBuilder.bootstrap5.js +2 -2
  11. package/assets/js/DataTables/Extensions/SearchBuilder/js/searchBuilder.bootstrap5.min.js +1 -1
  12. package/assets/js/DataTables/Extensions/Select/js/dataTables.select.js +34 -10
  13. package/assets/js/DataTables/Extensions/Select/js/dataTables.select.min.js +2 -2
  14. package/assets/js/DataTables/Extensions/StateRestore/js/StateRestore.js +19 -3
  15. package/assets/js/DataTables/Extensions/StateRestore/js/StateRestoreCollection.js +4 -4
  16. package/assets/js/DataTables/Extensions/StateRestore/js/dataTables.stateRestore.js +29 -13
  17. package/assets/js/DataTables/Extensions/StateRestore/js/dataTables.stateRestore.min.js +2 -2
  18. package/assets/js/DataTables/Extensions/StateRestore/js/index.js +6 -6
  19. package/assets/js/cdn.json +4 -4
  20. package/assets/js/pdfjs/build/pdf.mjs +2314 -898
  21. package/assets/js/pdfjs/build/pdf.mjs.map +1 -1
  22. package/assets/js/pdfjs/build/pdf.sandbox.mjs +5 -7
  23. package/assets/js/pdfjs/build/pdf.sandbox.mjs.map +1 -1
  24. package/assets/js/pdfjs/build/pdf.worker.mjs +655 -435
  25. package/assets/js/pdfjs/build/pdf.worker.mjs.map +1 -1
  26. package/assets/js/pdfjs/web/debugger.css +1 -1
  27. package/assets/js/pdfjs/web/images/cursor-editorFreeHighlight.svg +6 -0
  28. package/assets/js/pdfjs/web/images/cursor-editorTextHighlight.svg +8 -0
  29. package/assets/js/pdfjs/web/images/toolbarButton-editorFreeText.svg +3 -1
  30. package/assets/js/pdfjs/web/images/toolbarButton-editorStamp.svg +1 -1
  31. package/assets/js/pdfjs/web/locale/ar/viewer.ftl +25 -0
  32. package/assets/js/pdfjs/web/locale/be/viewer.ftl +20 -2
  33. package/assets/js/pdfjs/web/locale/bg/viewer.ftl +137 -0
  34. package/assets/js/pdfjs/web/locale/br/viewer.ftl +22 -0
  35. package/assets/js/pdfjs/web/locale/cs/viewer.ftl +20 -2
  36. package/assets/js/pdfjs/web/locale/cy/viewer.ftl +22 -8
  37. package/assets/js/pdfjs/web/locale/da/viewer.ftl +28 -2
  38. package/assets/js/pdfjs/web/locale/de/viewer.ftl +21 -3
  39. package/assets/js/pdfjs/web/locale/dsb/viewer.ftl +20 -2
  40. package/assets/js/pdfjs/web/locale/el/viewer.ftl +20 -2
  41. package/assets/js/pdfjs/web/locale/en-CA/viewer.ftl +25 -0
  42. package/assets/js/pdfjs/web/locale/en-GB/viewer.ftl +20 -2
  43. package/assets/js/pdfjs/web/locale/en-US/viewer.ftl +15 -8
  44. package/assets/js/pdfjs/web/locale/eo/viewer.ftl +57 -8
  45. package/assets/js/pdfjs/web/locale/es-AR/viewer.ftl +20 -2
  46. package/assets/js/pdfjs/web/locale/es-CL/viewer.ftl +20 -2
  47. package/assets/js/pdfjs/web/locale/es-ES/viewer.ftl +20 -2
  48. package/assets/js/pdfjs/web/locale/eu/viewer.ftl +53 -0
  49. package/assets/js/pdfjs/web/locale/fi/viewer.ftl +20 -2
  50. package/assets/js/pdfjs/web/locale/fr/viewer.ftl +16 -2
  51. package/assets/js/pdfjs/web/locale/fur/viewer.ftl +41 -2
  52. package/assets/js/pdfjs/web/locale/fy-NL/viewer.ftl +20 -2
  53. package/assets/js/pdfjs/web/locale/gl/viewer.ftl +17 -0
  54. package/assets/js/pdfjs/web/locale/gn/viewer.ftl +7 -2
  55. package/assets/js/pdfjs/web/locale/he/viewer.ftl +20 -2
  56. package/assets/js/pdfjs/web/locale/hsb/viewer.ftl +20 -2
  57. package/assets/js/pdfjs/web/locale/hu/viewer.ftl +16 -2
  58. package/assets/js/pdfjs/web/locale/ia/viewer.ftl +7 -2
  59. package/assets/js/pdfjs/web/locale/is/viewer.ftl +20 -2
  60. package/assets/js/pdfjs/web/locale/it/viewer.ftl +20 -2
  61. package/assets/js/pdfjs/web/locale/ja/viewer.ftl +39 -4
  62. package/assets/js/pdfjs/web/locale/ka/viewer.ftl +45 -9
  63. package/assets/js/pdfjs/web/locale/kk/viewer.ftl +20 -2
  64. package/assets/js/pdfjs/web/locale/ko/viewer.ftl +22 -4
  65. package/assets/js/pdfjs/web/locale/nb-NO/viewer.ftl +7 -2
  66. package/assets/js/pdfjs/web/locale/nl/viewer.ftl +20 -2
  67. package/assets/js/pdfjs/web/locale/nn-NO/viewer.ftl +19 -2
  68. package/assets/js/pdfjs/web/locale/oc/viewer.ftl +36 -0
  69. package/assets/js/pdfjs/web/locale/pa-IN/viewer.ftl +28 -2
  70. package/assets/js/pdfjs/web/locale/pl/viewer.ftl +7 -2
  71. package/assets/js/pdfjs/web/locale/pt-BR/viewer.ftl +20 -2
  72. package/assets/js/pdfjs/web/locale/pt-PT/viewer.ftl +49 -0
  73. package/assets/js/pdfjs/web/locale/rm/viewer.ftl +16 -2
  74. package/assets/js/pdfjs/web/locale/ru/viewer.ftl +20 -2
  75. package/assets/js/pdfjs/web/locale/sk/viewer.ftl +23 -5
  76. package/assets/js/pdfjs/web/locale/skr/viewer.ftl +22 -0
  77. package/assets/js/pdfjs/web/locale/sl/viewer.ftl +7 -2
  78. package/assets/js/pdfjs/web/locale/sq/viewer.ftl +7 -2
  79. package/assets/js/pdfjs/web/locale/sv-SE/viewer.ftl +20 -2
  80. package/assets/js/pdfjs/web/locale/tg/viewer.ftl +7 -2
  81. package/assets/js/pdfjs/web/locale/th/viewer.ftl +49 -0
  82. package/assets/js/pdfjs/web/locale/tr/viewer.ftl +25 -7
  83. package/assets/js/pdfjs/web/locale/uk/viewer.ftl +29 -11
  84. package/assets/js/pdfjs/web/locale/vi/viewer.ftl +21 -3
  85. package/assets/js/pdfjs/web/locale/zh-CN/viewer.ftl +20 -2
  86. package/assets/js/pdfjs/web/locale/zh-TW/viewer.ftl +20 -2
  87. package/assets/js/pdfjs/web/viewer.css +556 -100
  88. package/assets/js/pdfjs/web/viewer.html +20 -9
  89. package/assets/js/pdfjs/web/viewer.mjs +1100 -817
  90. package/assets/js/pdfjs/web/viewer.mjs.map +1 -1
  91. package/package.json +1 -1
  92. package/assets/js/pdfjs/web/images/gv-toolbarButton-openinapp.svg +0 -11
@@ -92,7 +92,10 @@ const AnnotationEditorParamsType = {
92
92
  INK_THICKNESS: 22,
93
93
  INK_OPACITY: 23,
94
94
  HIGHLIGHT_COLOR: 31,
95
- HIGHLIGHT_DEFAULT_COLOR: 32
95
+ HIGHLIGHT_DEFAULT_COLOR: 32,
96
+ HIGHLIGHT_THICKNESS: 33,
97
+ HIGHLIGHT_FREE: 34,
98
+ HIGHLIGHT_SHOW_ALL: 35
96
99
  };
97
100
  const PermissionFlag = {
98
101
  PRINT: 0x04,
@@ -525,7 +528,7 @@ class FeatureTest {
525
528
  return shadow(this, "isCSSRoundSupported", globalThis.CSS?.supports?.("width: round(1.5px, 1px)"));
526
529
  }
527
530
  }
528
- const hexNumbers = [...Array(256).keys()].map(n => n.toString(16).padStart(2, "0"));
531
+ const hexNumbers = Array.from(Array(256).keys(), n => n.toString(16).padStart(2, "0"));
529
532
  class Util {
530
533
  static makeHexColor(r, g, b) {
531
534
  return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
@@ -535,43 +538,43 @@ class Util {
535
538
  if (transform[0]) {
536
539
  if (transform[0] < 0) {
537
540
  temp = minMax[0];
538
- minMax[0] = minMax[1];
539
- minMax[1] = temp;
541
+ minMax[0] = minMax[2];
542
+ minMax[2] = temp;
540
543
  }
541
544
  minMax[0] *= transform[0];
542
- minMax[1] *= transform[0];
545
+ minMax[2] *= transform[0];
543
546
  if (transform[3] < 0) {
544
- temp = minMax[2];
545
- minMax[2] = minMax[3];
547
+ temp = minMax[1];
548
+ minMax[1] = minMax[3];
546
549
  minMax[3] = temp;
547
550
  }
548
- minMax[2] *= transform[3];
551
+ minMax[1] *= transform[3];
549
552
  minMax[3] *= transform[3];
550
553
  } else {
551
554
  temp = minMax[0];
552
- minMax[0] = minMax[2];
553
- minMax[2] = temp;
554
- temp = minMax[1];
555
- minMax[1] = minMax[3];
555
+ minMax[0] = minMax[1];
556
+ minMax[1] = temp;
557
+ temp = minMax[2];
558
+ minMax[2] = minMax[3];
556
559
  minMax[3] = temp;
557
560
  if (transform[1] < 0) {
558
- temp = minMax[2];
559
- minMax[2] = minMax[3];
561
+ temp = minMax[1];
562
+ minMax[1] = minMax[3];
560
563
  minMax[3] = temp;
561
564
  }
562
- minMax[2] *= transform[1];
565
+ minMax[1] *= transform[1];
563
566
  minMax[3] *= transform[1];
564
567
  if (transform[2] < 0) {
565
568
  temp = minMax[0];
566
- minMax[0] = minMax[1];
567
- minMax[1] = temp;
569
+ minMax[0] = minMax[2];
570
+ minMax[2] = temp;
568
571
  }
569
572
  minMax[0] *= transform[2];
570
- minMax[1] *= transform[2];
573
+ minMax[2] *= transform[2];
571
574
  }
572
575
  minMax[0] += transform[4];
573
- minMax[1] += transform[4];
574
- minMax[2] += transform[5];
576
+ minMax[1] += transform[5];
577
+ minMax[2] += transform[4];
575
578
  minMax[3] += transform[5];
576
579
  }
577
580
  static transform(m1, m2) {
@@ -636,59 +639,48 @@ class Util {
636
639
  }
637
640
  return [xLow, yLow, xHigh, yHigh];
638
641
  }
639
- static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3) {
640
- const tvalues = [],
641
- bounds = [[], []];
642
- let a, b, c, t, t1, t2, b2ac, sqrtb2ac;
643
- for (let i = 0; i < 2; ++i) {
644
- if (i === 0) {
645
- b = 6 * x0 - 12 * x1 + 6 * x2;
646
- a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3;
647
- c = 3 * x1 - 3 * x0;
648
- } else {
649
- b = 6 * y0 - 12 * y1 + 6 * y2;
650
- a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3;
651
- c = 3 * y1 - 3 * y0;
652
- }
653
- if (Math.abs(a) < 1e-12) {
654
- if (Math.abs(b) < 1e-12) {
655
- continue;
656
- }
657
- t = -c / b;
658
- if (0 < t && t < 1) {
659
- tvalues.push(t);
660
- }
661
- continue;
662
- }
663
- b2ac = b * b - 4 * c * a;
664
- sqrtb2ac = Math.sqrt(b2ac);
665
- if (b2ac < 0) {
666
- continue;
667
- }
668
- t1 = (-b + sqrtb2ac) / (2 * a);
669
- if (0 < t1 && t1 < 1) {
670
- tvalues.push(t1);
671
- }
672
- t2 = (-b - sqrtb2ac) / (2 * a);
673
- if (0 < t2 && t2 < 1) {
674
- tvalues.push(t2);
642
+ static #getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, t, minMax) {
643
+ if (t <= 0 || t >= 1) {
644
+ return;
645
+ }
646
+ const mt = 1 - t;
647
+ const tt = t * t;
648
+ const ttt = tt * t;
649
+ const x = mt * (mt * (mt * x0 + 3 * t * x1) + 3 * tt * x2) + ttt * x3;
650
+ const y = mt * (mt * (mt * y0 + 3 * t * y1) + 3 * tt * y2) + ttt * y3;
651
+ minMax[0] = Math.min(minMax[0], x);
652
+ minMax[1] = Math.min(minMax[1], y);
653
+ minMax[2] = Math.max(minMax[2], x);
654
+ minMax[3] = Math.max(minMax[3], y);
655
+ }
656
+ static #getExtremum(x0, x1, x2, x3, y0, y1, y2, y3, a, b, c, minMax) {
657
+ if (Math.abs(a) < 1e-12) {
658
+ if (Math.abs(b) >= 1e-12) {
659
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, -c / b, minMax);
675
660
  }
661
+ return;
662
+ }
663
+ const delta = b ** 2 - 4 * c * a;
664
+ if (delta < 0) {
665
+ return;
676
666
  }
677
- let j = tvalues.length,
678
- mt;
679
- const jlen = j;
680
- while (j--) {
681
- t = tvalues[j];
682
- mt = 1 - t;
683
- bounds[0][j] = mt * mt * mt * x0 + 3 * mt * mt * t * x1 + 3 * mt * t * t * x2 + t * t * t * x3;
684
- bounds[1][j] = mt * mt * mt * y0 + 3 * mt * mt * t * y1 + 3 * mt * t * t * y2 + t * t * t * y3;
667
+ const sqrtDelta = Math.sqrt(delta);
668
+ const a2 = 2 * a;
669
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b + sqrtDelta) / a2, minMax);
670
+ this.#getExtremumOnCurve(x0, x1, x2, x3, y0, y1, y2, y3, (-b - sqrtDelta) / a2, minMax);
671
+ }
672
+ static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
673
+ if (minMax) {
674
+ minMax[0] = Math.min(minMax[0], x0, x3);
675
+ minMax[1] = Math.min(minMax[1], y0, y3);
676
+ minMax[2] = Math.max(minMax[2], x0, x3);
677
+ minMax[3] = Math.max(minMax[3], y0, y3);
678
+ } else {
679
+ minMax = [Math.min(x0, x3), Math.min(y0, y3), Math.max(x0, x3), Math.max(y0, y3)];
685
680
  }
686
- bounds[0][jlen] = x0;
687
- bounds[1][jlen] = y0;
688
- bounds[0][jlen + 1] = x3;
689
- bounds[1][jlen + 1] = y3;
690
- bounds[0].length = bounds[1].length = jlen + 2;
691
- return [Math.min(...bounds[0]), Math.min(...bounds[1]), Math.max(...bounds[0]), Math.max(...bounds[1])];
681
+ 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);
682
+ 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);
683
+ return minMax;
692
684
  }
693
685
  }
694
686
  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,9 +734,6 @@ function stringToUTF8String(str) {
742
734
  function utf8StringToString(str) {
743
735
  return unescape(encodeURIComponent(str));
744
736
  }
745
- function isArrayBuffer(v) {
746
- return typeof v === "object" && v?.byteLength !== undefined;
747
- }
748
737
  function isArrayEqual(arr1, arr2) {
749
738
  if (arr1.length !== arr2.length) {
750
739
  return false;
@@ -760,24 +749,6 @@ function getModificationDate(date = new Date()) {
760
749
  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")];
761
750
  return buffer.join("");
762
751
  }
763
- class PromiseCapability {
764
- #settled = false;
765
- constructor() {
766
- this.promise = new Promise((resolve, reject) => {
767
- this.resolve = data => {
768
- this.#settled = true;
769
- resolve(data);
770
- };
771
- this.reject = reason => {
772
- this.#settled = true;
773
- reject(reason);
774
- };
775
- });
776
- }
777
- get settled() {
778
- return this.#settled;
779
- }
780
- }
781
752
  let NormalizeRegex = null;
782
753
  let NormalizationMap = null;
783
754
  function normalizeUnicode(str) {
@@ -785,9 +756,7 @@ function normalizeUnicode(str) {
785
756
  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;
786
757
  NormalizationMap = new Map([["ſt", "ſt"]]);
787
758
  }
788
- return str.replaceAll(NormalizeRegex, (_, p1, p2) => {
789
- return p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2);
790
- });
759
+ return str.replaceAll(NormalizeRegex, (_, p1, p2) => p1 ? p1.normalize("NFKC") : NormalizationMap.get(p2));
791
760
  }
792
761
  function getUuid() {
793
762
  if (typeof crypto !== "undefined" && typeof crypto?.randomUUID === "function") {
@@ -1382,6 +1351,15 @@ const XMLEntities = {
1382
1351
  0x22: "&quot;",
1383
1352
  0x27: "&apos;"
1384
1353
  };
1354
+ function* codePointIter(str) {
1355
+ for (let i = 0, ii = str.length; i < ii; i++) {
1356
+ const char = str.codePointAt(i);
1357
+ if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
1358
+ i++;
1359
+ }
1360
+ yield char;
1361
+ }
1362
+ }
1385
1363
  function encodeToXmlString(str) {
1386
1364
  const buffer = [];
1387
1365
  let start = 0;
@@ -1537,6 +1515,9 @@ function getRotationMatrix(rotation, width, height) {
1537
1515
  throw new Error("Invalid rotation");
1538
1516
  }
1539
1517
  }
1518
+ function getSizeInBytes(x) {
1519
+ return Math.ceil(Math.ceil(Math.log2(1 + x)) / 8);
1520
+ }
1540
1521
 
1541
1522
  ;// CONCATENATED MODULE: ./src/core/stream.js
1542
1523
 
@@ -1806,7 +1787,7 @@ class ChunkedStreamManager {
1806
1787
  this._promisesByRequest = new Map();
1807
1788
  this.progressiveDataLength = 0;
1808
1789
  this.aborted = false;
1809
- this._loadedStreamCapability = new PromiseCapability();
1790
+ this._loadedStreamCapability = Promise.withResolvers();
1810
1791
  }
1811
1792
  sendRequest(begin, end) {
1812
1793
  const rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
@@ -1869,7 +1850,7 @@ class ChunkedStreamManager {
1869
1850
  if (chunksNeeded.size === 0) {
1870
1851
  return Promise.resolve();
1871
1852
  }
1872
- const capability = new PromiseCapability();
1853
+ const capability = Promise.withResolvers();
1873
1854
  this._promisesByRequest.set(requestId, capability);
1874
1855
  const chunksToRequest = [];
1875
1856
  for (const chunk of chunksNeeded) {
@@ -5092,6 +5073,18 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue,
5092
5073
  symbolHeight += rdh;
5093
5074
  symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);
5094
5075
  }
5076
+ let increment = 0;
5077
+ if (!transposed) {
5078
+ if (referenceCorner > 1) {
5079
+ currentS += symbolWidth - 1;
5080
+ } else {
5081
+ increment = symbolWidth - 1;
5082
+ }
5083
+ } else if (!(referenceCorner & 1)) {
5084
+ currentS += symbolHeight - 1;
5085
+ } else {
5086
+ increment = symbolHeight - 1;
5087
+ }
5095
5088
  const offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);
5096
5089
  const offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);
5097
5090
  let s2, t2, symbolRow;
@@ -5118,7 +5111,6 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue,
5118
5111
  throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
5119
5112
  }
5120
5113
  }
5121
- currentS += symbolHeight - 1;
5122
5114
  } else {
5123
5115
  for (t2 = 0; t2 < symbolHeight; t2++) {
5124
5116
  row = bitmap[offsetT + t2];
@@ -5141,14 +5133,13 @@ function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue,
5141
5133
  throw new Jbig2Error(`operator ${combinationOperator} is not supported`);
5142
5134
  }
5143
5135
  }
5144
- currentS += symbolWidth - 1;
5145
5136
  }
5146
5137
  i++;
5147
5138
  const deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, "IADS", decoder);
5148
5139
  if (deltaS === null) {
5149
5140
  break;
5150
5141
  }
5151
- currentS += deltaS + dsOffset;
5142
+ currentS += increment + deltaS + dsOffset;
5152
5143
  } while (true);
5153
5144
  }
5154
5145
  return bitmap;
@@ -11306,9 +11297,7 @@ async function createBuiltInCMap(name, fetchBuiltInCMap) {
11306
11297
  } = await fetchBuiltInCMap(name);
11307
11298
  const cMap = new CMap(true);
11308
11299
  if (compressionType === CMapCompressionType.BINARY) {
11309
- return new BinaryCMapReader().process(cMapData, cMap, useCMap => {
11310
- return extendCMap(cMap, fetchBuiltInCMap, useCMap);
11311
- });
11300
+ return new BinaryCMapReader().process(cMapData, cMap, useCMap => extendCMap(cMap, fetchBuiltInCMap, useCMap));
11312
11301
  }
11313
11302
  if (compressionType === CMapCompressionType.NONE) {
11314
11303
  const lexer = new Lexer(new Stream(cMapData));
@@ -24487,7 +24476,7 @@ class Font {
24487
24476
  this._glyphCache = Object.create(null);
24488
24477
  let isSerifFont = !!(properties.flags & FontFlags.Serif);
24489
24478
  if (!isSerifFont && !properties.isSimulatedFlags) {
24490
- const baseName = name.replaceAll(/[,_]/g, "-").split("-")[0],
24479
+ const baseName = name.replaceAll(/[,_]/g, "-").split("-", 1)[0],
24491
24480
  serifFonts = getSerifFonts();
24492
24481
  for (const namePart of baseName.split("+")) {
24493
24482
  if (serifFonts[namePart]) {
@@ -24709,7 +24698,7 @@ class Font {
24709
24698
  this.toFontChar = map;
24710
24699
  }
24711
24700
  amendFallbackToUnicode(properties);
24712
- this.loadedName = fontName.split("-")[0];
24701
+ this.loadedName = fontName.split("-", 1)[0];
24713
24702
  }
24714
24703
  checkAndRepair(name, font, properties) {
24715
24704
  const VALID_TABLES = ["OS/2", "cmap", "head", "hhea", "hmtx", "maxp", "name", "post", "loca", "glyf", "fpgm", "prep", "cvt ", "CFF "];
@@ -25295,15 +25284,11 @@ class Font {
25295
25284
  endOffset: 0
25296
25285
  });
25297
25286
  }
25298
- locaEntries.sort((a, b) => {
25299
- return a.offset - b.offset;
25300
- });
25287
+ locaEntries.sort((a, b) => a.offset - b.offset);
25301
25288
  for (i = 0; i < numGlyphs; i++) {
25302
25289
  locaEntries[i].endOffset = locaEntries[i + 1].offset;
25303
25290
  }
25304
- locaEntries.sort((a, b) => {
25305
- return a.index - b.index;
25306
- });
25291
+ locaEntries.sort((a, b) => a.index - b.index);
25307
25292
  for (i = 0; i < numGlyphs; i++) {
25308
25293
  const {
25309
25294
  offset,
@@ -25319,6 +25304,10 @@ class Font {
25319
25304
  locaEntries[i].endOffset = nextOffset;
25320
25305
  break;
25321
25306
  }
25307
+ const last = locaEntries.at(-2);
25308
+ if (last.offset !== 0 && last.endOffset === 0) {
25309
+ last.endOffset = oldGlyfDataLength;
25310
+ }
25322
25311
  const missingGlyphs = Object.create(null);
25323
25312
  let writeOffset = 0;
25324
25313
  itemEncode(locaData, 0, writeOffset);
@@ -25960,14 +25949,18 @@ class Font {
25960
25949
  charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
25961
25950
  }
25962
25951
  forcePostTable = true;
25963
- } else {
25952
+ } else if (cmapPlatformId === 3 && cmapEncodingId === 0) {
25964
25953
  for (const mapping of cmapMappings) {
25965
25954
  let charCode = mapping.charCode;
25966
- if (cmapPlatformId === 3 && charCode >= 0xf000 && charCode <= 0xf0ff) {
25955
+ if (charCode >= 0xf000 && charCode <= 0xf0ff) {
25967
25956
  charCode &= 0xff;
25968
25957
  }
25969
25958
  charCodeToGlyphId[charCode] = mapping.glyphId;
25970
25959
  }
25960
+ } else {
25961
+ for (const mapping of cmapMappings) {
25962
+ charCodeToGlyphId[mapping.charCode] = mapping.glyphId;
25963
+ }
25971
25964
  }
25972
25965
  if (properties.glyphNames && (baseEncoding.length || this.differences.length)) {
25973
25966
  for (let i = 0; i < 256; ++i) {
@@ -27099,7 +27092,13 @@ class MeshShading extends BaseShading {
27099
27092
  }
27100
27093
  }
27101
27094
  getIR() {
27102
- return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, this.bounds, this.bbox, this.background];
27095
+ const {
27096
+ bounds
27097
+ } = this;
27098
+ if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) {
27099
+ throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`);
27100
+ }
27101
+ return ["Mesh", this.shadingType, this.coords, this.colors, this.figures, bounds, this.bbox, this.background];
27103
27102
  }
27104
27103
  }
27105
27104
  class DummyShading extends BaseShading {
@@ -29121,7 +29120,7 @@ const BOLDITALIC = {
29121
29120
  weight: "bold"
29122
29121
  };
29123
29122
  const substitutionMap = new Map([["Times-Roman", {
29124
- local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"],
29123
+ local: ["Times New Roman", "Times-Roman", "Times", "Liberation Serif", "Nimbus Roman", "Nimbus Roman L", "Tinos", "Thorndale", "TeX Gyre Termes", "FreeSerif", "Linux Libertine O", "Libertinus Serif", "DejaVu Serif", "Bitstream Vera Serif", "Ubuntu"],
29125
29124
  style: NORMAL,
29126
29125
  ultimate: "serif"
29127
29126
  }], ["Times-Bold", {
@@ -29157,7 +29156,7 @@ const substitutionMap = new Map([["Times-Roman", {
29157
29156
  style: BOLDITALIC,
29158
29157
  ultimate: "sans-serif"
29159
29158
  }], ["Courier", {
29160
- local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono"],
29159
+ local: ["Courier", "Courier New", "Liberation Mono", "Nimbus Mono", "Nimbus Mono L", "Cousine", "Cumberland", "TeX Gyre Cursor", "FreeMono", "Linux Libertine Mono O", "Libertinus Mono"],
29161
29160
  style: NORMAL,
29162
29161
  ultimate: "monospace"
29163
29162
  }], ["Courier-Bold", {
@@ -29249,6 +29248,10 @@ function getStyleToAppend(style) {
29249
29248
  }
29250
29249
  return "";
29251
29250
  }
29251
+ function getFamilyName(str) {
29252
+ const keywords = new Set(["thin", "extralight", "ultralight", "demilight", "semilight", "light", "book", "regular", "normal", "medium", "demibold", "semibold", "bold", "extrabold", "ultrabold", "black", "heavy", "extrablack", "ultrablack", "roman", "italic", "oblique", "ultracondensed", "extracondensed", "condensed", "semicondensed", "normal", "semiexpanded", "expanded", "extraexpanded", "ultraexpanded", "bolditalic"]);
29253
+ return str.split(/[- ,+]+/g).filter(tok => !keywords.has(tok.toLowerCase())).join(" ");
29254
+ }
29252
29255
  function generateFont({
29253
29256
  alias,
29254
29257
  local,
@@ -29325,7 +29328,7 @@ function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFont
29325
29328
  const italic = /oblique|italic/gi.test(baseFontName);
29326
29329
  const style = bold && italic && BOLDITALIC || bold && BOLD || italic && ITALIC || NORMAL;
29327
29330
  substitutionInfo = {
29328
- css: loadedName,
29331
+ css: `"${getFamilyName(baseFontName)}",${loadedName}`,
29329
29332
  guessFallback: true,
29330
29333
  loadedName,
29331
29334
  baseFontName,
@@ -29346,7 +29349,7 @@ function getFontSubstitution(systemFontCache, idFactory, localFontPath, baseFont
29346
29349
  const guessFallback = ultimate === null;
29347
29350
  const fallback = guessFallback ? "" : `,${ultimate}`;
29348
29351
  substitutionInfo = {
29349
- css: `${loadedName}${fallback}`,
29352
+ css: `"${getFamilyName(baseFontName)}",${loadedName}${fallback}`,
29350
29353
  guessFallback,
29351
29354
  loadedName,
29352
29355
  baseFontName,
@@ -29602,7 +29605,6 @@ class ImageResizer {
29602
29605
  ImageResizer._goodSquareLength = MIN_IMAGE_DIM;
29603
29606
 
29604
29607
  ;// CONCATENATED MODULE: ./src/shared/murmurhash3.js
29605
-
29606
29608
  const SEED = 0xc3d2e1f0;
29607
29609
  const MASK_HIGH = 0xffff0000;
29608
29610
  const MASK_LOW = 0xffff;
@@ -29625,11 +29627,11 @@ class MurmurHash3_64 {
29625
29627
  data[length++] = code & 0xff;
29626
29628
  }
29627
29629
  }
29628
- } else if (isArrayBuffer(input)) {
29630
+ } else if (ArrayBuffer.isView(input)) {
29629
29631
  data = input.slice();
29630
29632
  length = data.byteLength;
29631
29633
  } else {
29632
- throw new Error("Wrong data format in MurmurHash3_64_update. " + "Input must be a string or array.");
29634
+ throw new Error("Invalid data format, must be a string or TypedArray.");
29633
29635
  }
29634
29636
  const blockCounts = length >> 2;
29635
29637
  const tailLength = length - blockCounts * 4;
@@ -31324,21 +31326,20 @@ class PartialEvaluator {
31324
31326
  }
31325
31327
  const args = group ? [matrix, null] : [matrix, bbox];
31326
31328
  operatorList.addOp(OPS.paintFormXObjectBegin, args);
31327
- return this.getOperatorList({
31329
+ await this.getOperatorList({
31328
31330
  stream: xobj,
31329
31331
  task,
31330
31332
  resources: dict.get("Resources") || resources,
31331
31333
  operatorList,
31332
31334
  initialState
31333
- }).then(function () {
31334
- operatorList.addOp(OPS.paintFormXObjectEnd, []);
31335
- if (group) {
31336
- operatorList.addOp(OPS.endGroup, [groupOptions]);
31337
- }
31338
- if (optionalContent !== undefined) {
31339
- operatorList.addOp(OPS.endMarkedContent, []);
31340
- }
31341
31335
  });
31336
+ operatorList.addOp(OPS.paintFormXObjectEnd, []);
31337
+ if (group) {
31338
+ operatorList.addOp(OPS.endGroup, [groupOptions]);
31339
+ }
31340
+ if (optionalContent !== undefined) {
31341
+ operatorList.addOp(OPS.endMarkedContent, []);
31342
+ }
31342
31343
  }
31343
31344
  _sendImgData(objId, imgData, cacheGlobally = false) {
31344
31345
  const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
@@ -31460,17 +31461,25 @@ class PartialEvaluator {
31460
31461
  }
31461
31462
  const SMALL_IMAGE_DIMENSIONS = 200;
31462
31463
  if (isInline && !dict.has("SMask") && !dict.has("Mask") && w + h < SMALL_IMAGE_DIMENSIONS) {
31463
- const imageObj = new PDFImage({
31464
- xref: this.xref,
31465
- res: resources,
31466
- image,
31467
- isInline,
31468
- pdfFunctionFactory: this._pdfFunctionFactory,
31469
- localColorSpaceCache
31470
- });
31471
- imgData = await imageObj.createImageData(true, false);
31472
- operatorList.isOffscreenCanvasSupported = this.options.isOffscreenCanvasSupported;
31473
- operatorList.addImageOps(OPS.paintInlineImageXObject, [imgData], optionalContent);
31464
+ try {
31465
+ const imageObj = new PDFImage({
31466
+ xref: this.xref,
31467
+ res: resources,
31468
+ image,
31469
+ isInline,
31470
+ pdfFunctionFactory: this._pdfFunctionFactory,
31471
+ localColorSpaceCache
31472
+ });
31473
+ imgData = await imageObj.createImageData(true, false);
31474
+ operatorList.isOffscreenCanvasSupported = this.options.isOffscreenCanvasSupported;
31475
+ operatorList.addImageOps(OPS.paintInlineImageXObject, [imgData], optionalContent);
31476
+ } catch (reason) {
31477
+ const msg = `Unable to decode inline image: "${reason}".`;
31478
+ if (!this.options.ignoreErrors) {
31479
+ throw new Error(msg);
31480
+ }
31481
+ warn(msg);
31482
+ }
31474
31483
  return;
31475
31484
  }
31476
31485
  let objId = `img_${this.idFactory.createObjId()}`,
@@ -31636,28 +31645,25 @@ class PartialEvaluator {
31636
31645
  throw reason;
31637
31646
  });
31638
31647
  }
31639
- handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) {
31648
+ async handleSetFont(resources, fontArgs, fontRef, operatorList, task, state, fallbackFontDict = null, cssFontInfo = null) {
31640
31649
  const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
31641
- return this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo).then(translated => {
31642
- if (!translated.font.isType3Font) {
31643
- return translated;
31644
- }
31645
- return translated.loadType3Data(this, resources, task).then(function () {
31650
+ let translated = await this.loadFont(fontName, fontRef, resources, fallbackFontDict, cssFontInfo);
31651
+ if (translated.font.isType3Font) {
31652
+ try {
31653
+ await translated.loadType3Data(this, resources, task);
31646
31654
  operatorList.addDependencies(translated.type3Dependencies);
31647
- return translated;
31648
- }).catch(reason => {
31649
- return new TranslatedFont({
31655
+ } catch (reason) {
31656
+ translated = new TranslatedFont({
31650
31657
  loadedName: "g_font_error",
31651
31658
  font: new ErrorFont(`Type3 font load error: ${reason}`),
31652
31659
  dict: translated.font,
31653
31660
  evaluatorOptions: this.options
31654
31661
  });
31655
- });
31656
- }).then(translated => {
31657
- state.font = translated.font;
31658
- translated.send(this.handler);
31659
- return translated.loadedName;
31660
- });
31662
+ }
31663
+ }
31664
+ state.font = translated.font;
31665
+ translated.send(this.handler);
31666
+ return translated.loadedName;
31661
31667
  }
31662
31668
  handleText(chars, state) {
31663
31669
  const font = state.font;
@@ -31713,12 +31719,10 @@ class PartialEvaluator {
31713
31719
  break;
31714
31720
  case "Font":
31715
31721
  isSimpleGState = false;
31716
- promise = promise.then(() => {
31717
- return this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
31718
- operatorList.addDependency(loadedName);
31719
- gStateObj.push([key, [loadedName, value[1]]]);
31720
- });
31721
- });
31722
+ promise = promise.then(() => this.handleSetFont(resources, null, value[0], operatorList, task, stateManager.state).then(function (loadedName) {
31723
+ operatorList.addDependency(loadedName);
31724
+ gStateObj.push([key, [loadedName, value[1]]]);
31725
+ }));
31722
31726
  break;
31723
31727
  case "BM":
31724
31728
  gStateObj.push([key, normalizeBlendMode(value)]);
@@ -31730,9 +31734,7 @@ class PartialEvaluator {
31730
31734
  }
31731
31735
  if (value instanceof Dict) {
31732
31736
  isSimpleGState = false;
31733
- promise = promise.then(() => {
31734
- return this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache);
31735
- });
31737
+ promise = promise.then(() => this.handleSMask(value, resources, operatorList, task, stateManager, localColorSpaceCache));
31736
31738
  gStateObj.push([key, true]);
31737
31739
  } else {
31738
31740
  warn("Unsupported SMask type");
@@ -31762,14 +31764,13 @@ class PartialEvaluator {
31762
31764
  break;
31763
31765
  }
31764
31766
  }
31765
- return promise.then(function () {
31766
- if (gStateObj.length > 0) {
31767
- operatorList.addOp(OPS.setGState, [gStateObj]);
31768
- }
31769
- if (isSimpleGState) {
31770
- localGStateCache.set(cacheKey, gStateRef, gStateObj);
31771
- }
31772
- });
31767
+ await promise;
31768
+ if (gStateObj.length > 0) {
31769
+ operatorList.addOp(OPS.setGState, [gStateObj]);
31770
+ }
31771
+ if (isSimpleGState) {
31772
+ localGStateCache.set(cacheKey, gStateRef, gStateObj);
31773
+ }
31773
31774
  }
31774
31775
  loadFont(fontName, font, resources, fallbackFontDict = null, cssFontInfo = null) {
31775
31776
  const errorFont = async () => {
@@ -31811,7 +31812,10 @@ class PartialEvaluator {
31811
31812
  if (font.cacheKey && this.fontCache.has(font.cacheKey)) {
31812
31813
  return this.fontCache.get(font.cacheKey);
31813
31814
  }
31814
- const fontCapability = new PromiseCapability();
31815
+ const {
31816
+ promise,
31817
+ resolve
31818
+ } = Promise.withResolvers();
31815
31819
  let preEvaluatedFont;
31816
31820
  try {
31817
31821
  preEvaluatedFont = this.preEvaluateFont(font);
@@ -31848,14 +31852,14 @@ class PartialEvaluator {
31848
31852
  }
31849
31853
  assert(fontID?.startsWith("f"), 'The "fontID" must be (correctly) defined.');
31850
31854
  if (fontRefIsRef) {
31851
- this.fontCache.put(fontRef, fontCapability.promise);
31855
+ this.fontCache.put(fontRef, promise);
31852
31856
  } else {
31853
31857
  font.cacheKey = `cacheKey_${fontID}`;
31854
- this.fontCache.put(font.cacheKey, fontCapability.promise);
31858
+ this.fontCache.put(font.cacheKey, promise);
31855
31859
  }
31856
31860
  font.loadedName = `${this.idFactory.getDocId()}_${fontID}`;
31857
31861
  this.translateFont(preEvaluatedFont).then(translatedFont => {
31858
- fontCapability.resolve(new TranslatedFont({
31862
+ resolve(new TranslatedFont({
31859
31863
  loadedName: font.loadedName,
31860
31864
  font: translatedFont,
31861
31865
  dict: font,
@@ -31863,14 +31867,14 @@ class PartialEvaluator {
31863
31867
  }));
31864
31868
  }).catch(reason => {
31865
31869
  warn(`loadFont - translateFont failed: "${reason}".`);
31866
- fontCapability.resolve(new TranslatedFont({
31870
+ resolve(new TranslatedFont({
31867
31871
  loadedName: font.loadedName,
31868
31872
  font: new ErrorFont(reason instanceof Error ? reason.message : reason),
31869
31873
  dict: font,
31870
31874
  evaluatorOptions: this.options
31871
31875
  }));
31872
31876
  });
31873
- return fontCapability.promise;
31877
+ return promise;
31874
31878
  }
31875
31879
  buildPath(operatorList, fn, args, parsingText = false) {
31876
31880
  const lastIndex = operatorList.length - 1;
@@ -31887,14 +31891,14 @@ class PartialEvaluator {
31887
31891
  case OPS.rectangle:
31888
31892
  const x = args[0] + args[2];
31889
31893
  const y = args[1] + args[3];
31890
- minMax = [Math.min(args[0], x), Math.max(args[0], x), Math.min(args[1], y), Math.max(args[1], y)];
31894
+ minMax = [Math.min(args[0], x), Math.min(args[1], y), Math.max(args[0], x), Math.max(args[1], y)];
31891
31895
  break;
31892
31896
  case OPS.moveTo:
31893
31897
  case OPS.lineTo:
31894
- minMax = [args[0], args[0], args[1], args[1]];
31898
+ minMax = [args[0], args[1], args[0], args[1]];
31895
31899
  break;
31896
31900
  default:
31897
- minMax = [Infinity, -Infinity, Infinity, -Infinity];
31901
+ minMax = [Infinity, Infinity, -Infinity, -Infinity];
31898
31902
  break;
31899
31903
  }
31900
31904
  operatorList.addOp(OPS.constructPath, [[fn], args, minMax]);
@@ -31911,15 +31915,15 @@ class PartialEvaluator {
31911
31915
  const x = args[0] + args[2];
31912
31916
  const y = args[1] + args[3];
31913
31917
  minMax[0] = Math.min(minMax[0], args[0], x);
31914
- minMax[1] = Math.max(minMax[1], args[0], x);
31915
- minMax[2] = Math.min(minMax[2], args[1], y);
31918
+ minMax[1] = Math.min(minMax[1], args[1], y);
31919
+ minMax[2] = Math.max(minMax[2], args[0], x);
31916
31920
  minMax[3] = Math.max(minMax[3], args[1], y);
31917
31921
  break;
31918
31922
  case OPS.moveTo:
31919
31923
  case OPS.lineTo:
31920
31924
  minMax[0] = Math.min(minMax[0], args[0]);
31921
- minMax[1] = Math.max(minMax[1], args[0]);
31922
- minMax[2] = Math.min(minMax[2], args[1]);
31925
+ minMax[1] = Math.min(minMax[1], args[1]);
31926
+ minMax[2] = Math.max(minMax[2], args[0]);
31923
31927
  minMax[3] = Math.max(minMax[3], args[1]);
31924
31928
  break;
31925
31929
  }
@@ -31954,19 +31958,33 @@ class PartialEvaluator {
31954
31958
  localShadingPatternCache
31955
31959
  }) {
31956
31960
  let id = localShadingPatternCache.get(shading);
31957
- if (!id) {
31958
- var shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache);
31959
- const patternIR = shadingFill.getIR();
31960
- id = `pattern_${this.idFactory.createObjId()}`;
31961
- if (this.parsingType3Font) {
31962
- id = `${this.idFactory.getDocId()}_type3_${id}`;
31961
+ if (id) {
31962
+ return id;
31963
+ }
31964
+ let patternIR;
31965
+ try {
31966
+ const shadingFill = Pattern.parseShading(shading, this.xref, resources, this._pdfFunctionFactory, localColorSpaceCache);
31967
+ patternIR = shadingFill.getIR();
31968
+ } catch (reason) {
31969
+ if (reason instanceof AbortException) {
31970
+ return null;
31963
31971
  }
31964
- localShadingPatternCache.set(shading, id);
31965
- if (this.parsingType3Font) {
31966
- this.handler.send("commonobj", [id, "Pattern", patternIR]);
31967
- } else {
31968
- this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
31972
+ if (this.options.ignoreErrors) {
31973
+ warn(`parseShading - ignoring shading: "${reason}".`);
31974
+ localShadingPatternCache.set(shading, null);
31975
+ return null;
31969
31976
  }
31977
+ throw reason;
31978
+ }
31979
+ id = `pattern_${this.idFactory.createObjId()}`;
31980
+ if (this.parsingType3Font) {
31981
+ id = `${this.idFactory.getDocId()}_type3_${id}`;
31982
+ }
31983
+ localShadingPatternCache.set(shading, id);
31984
+ if (this.parsingType3Font) {
31985
+ this.handler.send("commonobj", [id, "Pattern", patternIR]);
31986
+ } else {
31987
+ this.handler.send("obj", [id, this.pageIndex, "Pattern", patternIR]);
31970
31988
  }
31971
31989
  return id;
31972
31990
  }
@@ -31992,14 +32010,16 @@ class PartialEvaluator {
31992
32010
  return this.handleTilingType(fn, color, resources, pattern, dict, operatorList, task, localTilingPatternCache);
31993
32011
  } else if (typeNum === PatternType.SHADING) {
31994
32012
  const shading = dict.get("Shading");
31995
- const matrix = dict.getArray("Matrix");
31996
32013
  const objId = this.parseShading({
31997
32014
  shading,
31998
32015
  resources,
31999
32016
  localColorSpaceCache,
32000
32017
  localShadingPatternCache
32001
32018
  });
32002
- operatorList.addOp(fn, ["Shading", objId, matrix]);
32019
+ if (objId) {
32020
+ const matrix = dict.getArray("Matrix");
32021
+ operatorList.addOp(fn, ["Shading", objId, matrix]);
32022
+ }
32003
32023
  return undefined;
32004
32024
  }
32005
32025
  throw new FormatError(`Unknown PatternType: ${typeNum}`);
@@ -32410,6 +32430,9 @@ class PartialEvaluator {
32410
32430
  localColorSpaceCache,
32411
32431
  localShadingPatternCache
32412
32432
  });
32433
+ if (!patternId) {
32434
+ continue;
32435
+ }
32413
32436
  args = [patternId];
32414
32437
  fn = OPS.shadingFill;
32415
32438
  break;
@@ -32476,6 +32499,7 @@ class PartialEvaluator {
32476
32499
  case OPS.beginMarkedContentProps:
32477
32500
  if (!(args[0] instanceof Name)) {
32478
32501
  warn(`Expected name for beginMarkedContentProps arg0=${args[0]}`);
32502
+ operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
32479
32503
  continue;
32480
32504
  }
32481
32505
  if (args[0].name === "OC") {
@@ -32487,6 +32511,7 @@ class PartialEvaluator {
32487
32511
  }
32488
32512
  if (self.options.ignoreErrors) {
32489
32513
  warn(`getOperatorList - ignoring beginMarkedContentProps: "${reason}".`);
32514
+ operatorList.addOp(OPS.beginMarkedContentProps, ["OC", null]);
32490
32515
  return;
32491
32516
  }
32492
32517
  throw reason;
@@ -32540,7 +32565,8 @@ class PartialEvaluator {
32540
32565
  seenStyles = new Set(),
32541
32566
  viewBox,
32542
32567
  markedContentData = null,
32543
- disableNormalization = false
32568
+ disableNormalization = false,
32569
+ keepWhiteSpace = false
32544
32570
  }) {
32545
32571
  resources ||= Dict.empty;
32546
32572
  stateManager ||= new StateManager(new TextState());
@@ -32579,10 +32605,10 @@ class PartialEvaluator {
32579
32605
  const ret = twoLastChars[twoLastCharsPos] !== " " && twoLastChars[nextPos] === " ";
32580
32606
  twoLastChars[twoLastCharsPos] = char;
32581
32607
  twoLastCharsPos = nextPos;
32582
- return ret;
32608
+ return !keepWhiteSpace && ret;
32583
32609
  }
32584
32610
  function shouldAddWhitepsace() {
32585
- return twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
32611
+ return !keepWhiteSpace && twoLastChars[twoLastCharsPos] !== " " && twoLastChars[(twoLastCharsPos + 1) % 2] === " ";
32586
32612
  }
32587
32613
  function resetLastChars() {
32588
32614
  twoLastChars[0] = twoLastChars[1] = " ";
@@ -32712,19 +32738,16 @@ class PartialEvaluator {
32712
32738
  hasEOL: textChunk.hasEOL
32713
32739
  };
32714
32740
  }
32715
- function handleSetFont(fontName, fontRef) {
32716
- return self.loadFont(fontName, fontRef, resources).then(function (translated) {
32717
- if (!translated.font.isType3Font) {
32718
- return translated;
32719
- }
32720
- return translated.loadType3Data(self, resources, task).catch(function () {}).then(function () {
32721
- return translated;
32722
- });
32723
- }).then(function (translated) {
32724
- textState.loadedName = translated.loadedName;
32725
- textState.font = translated.font;
32726
- textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
32727
- });
32741
+ async function handleSetFont(fontName, fontRef) {
32742
+ const translated = await self.loadFont(fontName, fontRef, resources);
32743
+ if (translated.font.isType3Font) {
32744
+ try {
32745
+ await translated.loadType3Data(self, resources, task);
32746
+ } catch {}
32747
+ }
32748
+ textState.loadedName = translated.loadedName;
32749
+ textState.font = translated.font;
32750
+ textState.fontMatrix = translated.font.fontMatrix || FONT_IDENTITY_MATRIX;
32728
32751
  }
32729
32752
  function applyInverseRotation(x, y, matrix) {
32730
32753
  const scale = Math.hypot(matrix[0], matrix[1]);
@@ -32876,6 +32899,9 @@ class PartialEvaluator {
32876
32899
  textState.translateTextMatrix(0, -charSpacing);
32877
32900
  }
32878
32901
  }
32902
+ if (keepWhiteSpace) {
32903
+ compareWithLastPosition(0);
32904
+ }
32879
32905
  return;
32880
32906
  }
32881
32907
  const glyphs = font.charsToGlyphs(chars);
@@ -32894,7 +32920,7 @@ class PartialEvaluator {
32894
32920
  glyphWidth = glyph.vmetric ? glyph.vmetric[0] : -glyphWidth;
32895
32921
  }
32896
32922
  let scaledDim = glyphWidth * scale;
32897
- if (category.isWhitespace) {
32923
+ if (!keepWhiteSpace && category.isWhitespace) {
32898
32924
  if (!font.vertical) {
32899
32925
  charSpacing += scaledDim + textState.wordSpacing;
32900
32926
  textState.translateTextMatrix(charSpacing * textState.textHScale, 0);
@@ -33216,7 +33242,8 @@ class PartialEvaluator {
33216
33242
  seenStyles,
33217
33243
  viewBox,
33218
33244
  markedContentData,
33219
- disableNormalization
33245
+ disableNormalization,
33246
+ keepWhiteSpace
33220
33247
  }).then(function () {
33221
33248
  if (!sinkWrapper.enqueueInvoked) {
33222
33249
  emptyXObjectCache.set(name, xobj.dict.objId, true);
@@ -33341,10 +33368,10 @@ class PartialEvaluator {
33341
33368
  throw reason;
33342
33369
  });
33343
33370
  }
33344
- extractDataStructures(dict, baseDict, properties) {
33371
+ async extractDataStructures(dict, properties) {
33345
33372
  const xref = this.xref;
33346
33373
  let cidToGidBytes;
33347
- const toUnicodePromise = this.readToUnicode(properties.toUnicode || dict.get("ToUnicode") || baseDict.get("ToUnicode"));
33374
+ const toUnicodePromise = this.readToUnicode(properties.toUnicode);
33348
33375
  if (properties.composite) {
33349
33376
  const cidSystemInfo = dict.get("CIDSystemInfo");
33350
33377
  if (cidSystemInfo instanceof Dict) {
@@ -33433,16 +33460,13 @@ class PartialEvaluator {
33433
33460
  properties.baseEncodingName = baseEncodingName;
33434
33461
  properties.hasEncoding = !!baseEncodingName || differences.length > 0;
33435
33462
  properties.dict = dict;
33436
- return toUnicodePromise.then(readToUnicode => {
33437
- properties.toUnicode = readToUnicode;
33438
- return this.buildToUnicode(properties);
33439
- }).then(builtToUnicode => {
33440
- properties.toUnicode = builtToUnicode;
33441
- if (cidToGidBytes) {
33442
- properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
33443
- }
33444
- return properties;
33445
- });
33463
+ properties.toUnicode = await toUnicodePromise;
33464
+ const builtToUnicode = await this.buildToUnicode(properties);
33465
+ properties.toUnicode = builtToUnicode;
33466
+ if (cidToGidBytes) {
33467
+ properties.cidToGidMap = this.readCidToGidMap(cidToGidBytes, builtToUnicode);
33468
+ }
33469
+ return properties;
33446
33470
  }
33447
33471
  _simpleFontToUnicode(properties, forceGlyphs = false) {
33448
33472
  assert(!properties.composite, "Must be a simple font.");
@@ -33534,7 +33558,7 @@ class PartialEvaluator {
33534
33558
  if (!properties.composite) {
33535
33559
  return new ToUnicodeMap(this._simpleFontToUnicode(properties));
33536
33560
  }
33537
- if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo.registry === "Adobe" && (properties.cidSystemInfo.ordering === "GB1" || properties.cidSystemInfo.ordering === "CNS1" || properties.cidSystemInfo.ordering === "Japan1" || properties.cidSystemInfo.ordering === "Korea1"))) {
33561
+ if (properties.composite && (properties.cMap.builtInCMap && !(properties.cMap instanceof IdentityCMap) || properties.cidSystemInfo?.registry === "Adobe" && (properties.cidSystemInfo.ordering === "GB1" || properties.cidSystemInfo.ordering === "CNS1" || properties.cidSystemInfo.ordering === "Japan1" || properties.cidSystemInfo.ordering === "Korea1"))) {
33538
33562
  const {
33539
33563
  registry,
33540
33564
  ordering
@@ -33564,27 +33588,28 @@ class PartialEvaluator {
33564
33588
  }
33565
33589
  return new IdentityToUnicodeMap(properties.firstChar, properties.lastChar);
33566
33590
  }
33567
- readToUnicode(cmapObj) {
33591
+ async readToUnicode(cmapObj) {
33568
33592
  if (!cmapObj) {
33569
- return Promise.resolve(null);
33593
+ return null;
33570
33594
  }
33571
33595
  if (cmapObj instanceof Name) {
33572
- return CMapFactory.create({
33596
+ const cmap = await CMapFactory.create({
33573
33597
  encoding: cmapObj,
33574
33598
  fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33575
33599
  useCMap: null
33576
- }).then(function (cmap) {
33577
- if (cmap instanceof IdentityCMap) {
33578
- return new IdentityToUnicodeMap(0, 0xffff);
33579
- }
33580
- return new ToUnicodeMap(cmap.getMap());
33581
33600
  });
33582
- } else if (cmapObj instanceof BaseStream) {
33583
- return CMapFactory.create({
33584
- encoding: cmapObj,
33585
- fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33586
- useCMap: null
33587
- }).then(function (cmap) {
33601
+ if (cmap instanceof IdentityCMap) {
33602
+ return new IdentityToUnicodeMap(0, 0xffff);
33603
+ }
33604
+ return new ToUnicodeMap(cmap.getMap());
33605
+ }
33606
+ if (cmapObj instanceof BaseStream) {
33607
+ try {
33608
+ const cmap = await CMapFactory.create({
33609
+ encoding: cmapObj,
33610
+ fetchBuiltInCMap: this._fetchBuiltInCMapBound,
33611
+ useCMap: null
33612
+ });
33588
33613
  if (cmap instanceof IdentityCMap) {
33589
33614
  return new IdentityToUnicodeMap(0, 0xffff);
33590
33615
  }
@@ -33608,7 +33633,7 @@ class PartialEvaluator {
33608
33633
  map[charCode] = String.fromCodePoint(...str);
33609
33634
  });
33610
33635
  return new ToUnicodeMap(map);
33611
- }, reason => {
33636
+ } catch (reason) {
33612
33637
  if (reason instanceof AbortException) {
33613
33638
  return null;
33614
33639
  }
@@ -33617,9 +33642,9 @@ class PartialEvaluator {
33617
33642
  return null;
33618
33643
  }
33619
33644
  throw reason;
33620
- });
33645
+ }
33621
33646
  }
33622
- return Promise.resolve(null);
33647
+ return null;
33623
33648
  }
33624
33649
  readCidToGidMap(glyphsData, toUnicode) {
33625
33650
  const result = [];
@@ -33725,7 +33750,7 @@ class PartialEvaluator {
33725
33750
  properties.vmetrics = glyphsVMetrics;
33726
33751
  }
33727
33752
  isSerifFont(baseFontName) {
33728
- const fontNameWoStyle = baseFontName.split("-")[0];
33753
+ const fontNameWoStyle = baseFontName.split("-", 1)[0];
33729
33754
  return fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle);
33730
33755
  }
33731
33756
  getBaseFontMetrics(name) {
@@ -33774,7 +33799,7 @@ class PartialEvaluator {
33774
33799
  throw new FormatError("invalid font Subtype");
33775
33800
  }
33776
33801
  let composite = false;
33777
- let hash, toUnicode;
33802
+ let hash;
33778
33803
  if (type.name === "Type0") {
33779
33804
  const df = dict.get("DescendantFonts");
33780
33805
  if (!df) {
@@ -33793,6 +33818,7 @@ class PartialEvaluator {
33793
33818
  const firstChar = dict.get("FirstChar") || 0,
33794
33819
  lastChar = dict.get("LastChar") || (composite ? 0xffff : 0xff);
33795
33820
  const descriptor = dict.get("FontDescriptor");
33821
+ const toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
33796
33822
  if (descriptor) {
33797
33823
  hash = new MurmurHash3_64();
33798
33824
  const encoding = baseDict.getRaw("Encoding");
@@ -33822,7 +33848,6 @@ class PartialEvaluator {
33822
33848
  }
33823
33849
  }
33824
33850
  hash.update(`${firstChar}-${lastChar}`);
33825
- toUnicode = dict.get("ToUnicode") || baseDict.get("ToUnicode");
33826
33851
  if (toUnicode instanceof BaseStream) {
33827
33852
  const stream = toUnicode.str || toUnicode;
33828
33853
  const uint8array = stream.buffer ? new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) : new Uint8Array(stream.bytes.buffer, stream.start, stream.end - stream.start);
@@ -33894,7 +33919,6 @@ class PartialEvaluator {
33894
33919
  cssFontInfo
33895
33920
  }) {
33896
33921
  const isType3Font = type === "Type3";
33897
- let properties;
33898
33922
  if (!descriptor) {
33899
33923
  if (isType3Font) {
33900
33924
  descriptor = new Dict(null);
@@ -33907,9 +33931,9 @@ class PartialEvaluator {
33907
33931
  }
33908
33932
  baseFontName = baseFontName.name.replaceAll(/[,_]/g, "-");
33909
33933
  const metrics = this.getBaseFontMetrics(baseFontName);
33910
- const fontNameWoStyle = baseFontName.split("-")[0];
33934
+ const fontNameWoStyle = baseFontName.split("-", 1)[0];
33911
33935
  const flags = (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) | (metrics.monospace ? FontFlags.FixedPitch : 0) | (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic : FontFlags.Nonsymbolic);
33912
- properties = {
33936
+ const properties = {
33913
33937
  type,
33914
33938
  name: baseFontName,
33915
33939
  loadedName: baseDict.loadedName,
@@ -33936,19 +33960,18 @@ class PartialEvaluator {
33936
33960
  if (!properties.isInternalFont && this.options.useSystemFonts) {
33937
33961
  properties.systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, baseFontName, standardFontName);
33938
33962
  }
33939
- return this.extractDataStructures(dict, dict, properties).then(newProperties => {
33940
- if (widths) {
33941
- const glyphWidths = [];
33942
- let j = firstChar;
33943
- for (const width of widths) {
33944
- glyphWidths[j++] = this.xref.fetchIfRef(width);
33945
- }
33946
- newProperties.widths = glyphWidths;
33947
- } else {
33948
- newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
33963
+ const newProperties = await this.extractDataStructures(dict, properties);
33964
+ if (widths) {
33965
+ const glyphWidths = [];
33966
+ let j = firstChar;
33967
+ for (const width of widths) {
33968
+ glyphWidths[j++] = this.xref.fetchIfRef(width);
33949
33969
  }
33950
- return new Font(baseFontName, file, newProperties);
33951
- });
33970
+ newProperties.widths = glyphWidths;
33971
+ } else {
33972
+ newProperties.widths = this.buildCharCodeToWidth(metrics.widths, newProperties);
33973
+ }
33974
+ return new Font(baseFontName, file, newProperties);
33952
33975
  }
33953
33976
  }
33954
33977
  let fontName = descriptor.get("FontName");
@@ -34015,7 +34038,7 @@ class PartialEvaluator {
34015
34038
  systemFontInfo = getFontSubstitution(this.systemFontCache, this.idFactory, this.options.standardFontDataUrl, fontName.name, standardFontName);
34016
34039
  }
34017
34040
  }
34018
- properties = {
34041
+ const properties = {
34019
34042
  type,
34020
34043
  name: fontName.name,
34021
34044
  subtype,
@@ -34056,10 +34079,9 @@ class PartialEvaluator {
34056
34079
  properties.cMap = cMap;
34057
34080
  properties.vertical = properties.cMap.vertical;
34058
34081
  }
34059
- return this.extractDataStructures(dict, baseDict, properties).then(newProperties => {
34060
- this.extractWidths(dict, descriptor, newProperties);
34061
- return new Font(fontName.name, fontFile, newProperties);
34062
- });
34082
+ const newProperties = await this.extractDataStructures(dict, properties);
34083
+ this.extractWidths(dict, descriptor, newProperties);
34084
+ return new Font(fontName.name, fontFile, newProperties);
34063
34085
  }
34064
34086
  static buildFontPaths(font, glyphs, handler, evaluatorOptions) {
34065
34087
  function buildPath(fontChar) {
@@ -34339,7 +34361,7 @@ class EvalState {
34339
34361
  }
34340
34362
  class EvaluatorPreprocessor {
34341
34363
  static get opMap() {
34342
- return shadow(this, "opMap", {
34364
+ return shadow(this, "opMap", Object.assign(Object.create(null), {
34343
34365
  w: {
34344
34366
  id: OPS.setLineWidth,
34345
34367
  numArgs: 1,
@@ -34715,7 +34737,7 @@ class EvaluatorPreprocessor {
34715
34737
  nu: null,
34716
34738
  nul: null,
34717
34739
  null: null
34718
- });
34740
+ }));
34719
34741
  }
34720
34742
  static MAX_INVALID_PATH_OPS = 10;
34721
34743
  constructor(stream, xref, stateManager = new StateManager()) {
@@ -35015,31 +35037,6 @@ class FakeUnicodeFont {
35015
35037
  }
35016
35038
  this.fontName = Name.get(`InvalidPDFjsFont_${fontFamily}_${FakeUnicodeFont._fontNameId++}`);
35017
35039
  }
35018
- get toUnicodeRef() {
35019
- if (!FakeUnicodeFont._toUnicodeRef) {
35020
- const toUnicode = `/CIDInit /ProcSet findresource begin
35021
- 12 dict begin
35022
- begincmap
35023
- /CIDSystemInfo
35024
- << /Registry (Adobe)
35025
- /Ordering (UCS) /Supplement 0 >> def
35026
- /CMapName /Adobe-Identity-UCS def
35027
- /CMapType 2 def
35028
- 1 begincodespacerange
35029
- <0000> <FFFF>
35030
- endcodespacerange
35031
- 1 beginbfrange
35032
- <0000> <FFFF> <0000>
35033
- endbfrange
35034
- endcmap CMapName currentdict /CMap defineresource pop end end`;
35035
- const toUnicodeStream = FakeUnicodeFont.toUnicodeStream = new StringStream(toUnicode);
35036
- const toUnicodeDict = new Dict(this.xref);
35037
- toUnicodeStream.dict = toUnicodeDict;
35038
- toUnicodeDict.set("Length", toUnicode.length);
35039
- FakeUnicodeFont._toUnicodeRef = this.xref.getNewPersistentRef(toUnicodeStream);
35040
- }
35041
- return FakeUnicodeFont._toUnicodeRef;
35042
- }
35043
35040
  get fontDescriptorRef() {
35044
35041
  if (!FakeUnicodeFont._fontDescriptorRef) {
35045
35042
  const fontDescriptor = new Dict(this.xref);
@@ -35100,7 +35097,7 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
35100
35097
  baseFont.set("Subtype", Name.get("Type0"));
35101
35098
  baseFont.set("Encoding", Name.get("Identity-H"));
35102
35099
  baseFont.set("DescendantFonts", [this.descendantFontRef]);
35103
- baseFont.set("ToUnicode", this.toUnicodeRef);
35100
+ baseFont.set("ToUnicode", Name.get("Identity-H"));
35104
35101
  return this.xref.getNewPersistentRef(baseFont);
35105
35102
  }
35106
35103
  get resources() {
@@ -35132,6 +35129,21 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
35132
35129
  }
35133
35130
  return this.resources;
35134
35131
  }
35132
+ static getFirstPositionInfo(rect, rotation, fontSize) {
35133
+ const [x1, y1, x2, y2] = rect;
35134
+ let w = x2 - x1;
35135
+ let h = y2 - y1;
35136
+ if (rotation % 180 !== 0) {
35137
+ [w, h] = [h, w];
35138
+ }
35139
+ const lineHeight = LINE_FACTOR * fontSize;
35140
+ const lineDescent = LINE_DESCENT_FACTOR * fontSize;
35141
+ return {
35142
+ coords: [0, h + lineDescent - lineHeight],
35143
+ bbox: [0, 0, w, h],
35144
+ matrix: rotation !== 0 ? getRotationMatrix(rotation, h, lineHeight) : undefined
35145
+ };
35146
+ }
35135
35147
  createAppearance(text, rect, rotation, fontSize, bgColor, strokeAlpha) {
35136
35148
  const ctx = this._createContext();
35137
35149
  const lines = [];
@@ -35140,8 +35152,8 @@ endcmap CMapName currentdict /CMap defineresource pop end end`;
35140
35152
  lines.push(line);
35141
35153
  const lineWidth = ctx.measureText(line).width;
35142
35154
  maxWidth = Math.max(maxWidth, lineWidth);
35143
- for (const char of line.split("")) {
35144
- const code = char.charCodeAt(0);
35155
+ for (const code of codePointIter(line)) {
35156
+ const char = String.fromCodePoint(code);
35145
35157
  let width = this.widths.get(code);
35146
35158
  if (width === undefined) {
35147
35159
  const metrics = ctx.measureText(char);
@@ -35355,7 +35367,8 @@ function pickPlatformItem(dict) {
35355
35367
  return null;
35356
35368
  }
35357
35369
  class FileSpec {
35358
- constructor(root, xref) {
35370
+ #contentAvailable = false;
35371
+ constructor(root, xref, skipContent = false) {
35359
35372
  if (!(root instanceof Dict)) {
35360
35373
  return;
35361
35374
  }
@@ -35368,10 +35381,12 @@ class FileSpec {
35368
35381
  if (root.has("RF")) {
35369
35382
  warn("Related file specifications are not supported");
35370
35383
  }
35371
- this.contentAvailable = true;
35372
- if (!root.has("EF")) {
35373
- this.contentAvailable = false;
35374
- warn("Non-embedded file specifications are not supported");
35384
+ if (!skipContent) {
35385
+ if (root.has("EF")) {
35386
+ this.#contentAvailable = true;
35387
+ } else {
35388
+ warn("Non-embedded file specifications are not supported");
35389
+ }
35375
35390
  }
35376
35391
  }
35377
35392
  get filename() {
@@ -35382,7 +35397,7 @@ class FileSpec {
35382
35397
  return this._filename;
35383
35398
  }
35384
35399
  get content() {
35385
- if (!this.contentAvailable) {
35400
+ if (!this.#contentAvailable) {
35386
35401
  return null;
35387
35402
  }
35388
35403
  if (!this.contentRef && this.root) {
@@ -37238,6 +37253,7 @@ class CipherTransformFactory {
37238
37253
 
37239
37254
 
37240
37255
 
37256
+
37241
37257
  async function writeObject(ref, obj, buffer, {
37242
37258
  encrypt = null
37243
37259
  }) {
@@ -37247,7 +37263,7 @@ async function writeObject(ref, obj, buffer, {
37247
37263
  await writeDict(obj, buffer, transform);
37248
37264
  } else if (obj instanceof BaseStream) {
37249
37265
  await writeStream(obj, buffer, transform);
37250
- } else if (Array.isArray(obj)) {
37266
+ } else if (Array.isArray(obj) || ArrayBuffer.isView(obj)) {
37251
37267
  await writeArray(obj, buffer, transform);
37252
37268
  }
37253
37269
  buffer.push("\nendobj\n");
@@ -37322,7 +37338,7 @@ async function writeValue(value, buffer, transform) {
37322
37338
  buffer.push(`/${escapePDFName(value.name)}`);
37323
37339
  } else if (value instanceof Ref) {
37324
37340
  buffer.push(`${value.num} ${value.gen} R`);
37325
- } else if (Array.isArray(value)) {
37341
+ } else if (Array.isArray(value) || ArrayBuffer.isView(value)) {
37326
37342
  await writeArray(value, buffer, transform);
37327
37343
  } else if (typeof value === "string") {
37328
37344
  if (transform) {
@@ -37458,6 +37474,103 @@ function updateXFA({
37458
37474
  data
37459
37475
  });
37460
37476
  }
37477
+ async function getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
37478
+ buffer.push("xref\n");
37479
+ const indexes = getIndexes(newRefs);
37480
+ let indexesPosition = 0;
37481
+ for (const {
37482
+ ref,
37483
+ data
37484
+ } of newRefs) {
37485
+ if (ref.num === indexes[indexesPosition]) {
37486
+ buffer.push(`${indexes[indexesPosition]} ${indexes[indexesPosition + 1]}\n`);
37487
+ indexesPosition += 2;
37488
+ }
37489
+ buffer.push(`${baseOffset.toString().padStart(10, "0")} ${Math.min(ref.gen, 0xffff).toString().padStart(5, "0")} n\r\n`);
37490
+ baseOffset += data.length;
37491
+ }
37492
+ computeIDs(baseOffset, xrefInfo, newXref);
37493
+ buffer.push("trailer\n");
37494
+ await writeDict(newXref, buffer);
37495
+ buffer.push("\nstartxref\n", baseOffset.toString(), "\n%%EOF\n");
37496
+ }
37497
+ function getIndexes(newRefs) {
37498
+ const indexes = [];
37499
+ for (const {
37500
+ ref
37501
+ } of newRefs) {
37502
+ if (ref.num === indexes.at(-2) + indexes.at(-1)) {
37503
+ indexes[indexes.length - 1] += 1;
37504
+ } else {
37505
+ indexes.push(ref.num, 1);
37506
+ }
37507
+ }
37508
+ return indexes;
37509
+ }
37510
+ async function getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) {
37511
+ const xrefTableData = [];
37512
+ let maxOffset = 0;
37513
+ let maxGen = 0;
37514
+ for (const {
37515
+ ref,
37516
+ data
37517
+ } of newRefs) {
37518
+ maxOffset = Math.max(maxOffset, baseOffset);
37519
+ const gen = Math.min(ref.gen, 0xffff);
37520
+ maxGen = Math.max(maxGen, gen);
37521
+ xrefTableData.push([1, baseOffset, gen]);
37522
+ baseOffset += data.length;
37523
+ }
37524
+ newXref.set("Index", getIndexes(newRefs));
37525
+ const offsetSize = getSizeInBytes(maxOffset);
37526
+ const maxGenSize = getSizeInBytes(maxGen);
37527
+ const sizes = [1, offsetSize, maxGenSize];
37528
+ newXref.set("W", sizes);
37529
+ computeIDs(baseOffset, xrefInfo, newXref);
37530
+ const structSize = sizes.reduce((a, x) => a + x, 0);
37531
+ const data = new Uint8Array(structSize * xrefTableData.length);
37532
+ const stream = new Stream(data);
37533
+ stream.dict = newXref;
37534
+ let offset = 0;
37535
+ for (const [type, objOffset, gen] of xrefTableData) {
37536
+ offset = writeInt(type, sizes[0], offset, data);
37537
+ offset = writeInt(objOffset, sizes[1], offset, data);
37538
+ offset = writeInt(gen, sizes[2], offset, data);
37539
+ }
37540
+ await writeObject(xrefInfo.newRef, stream, buffer, {});
37541
+ buffer.push("startxref\n", baseOffset.toString(), "\n%%EOF\n");
37542
+ }
37543
+ function computeIDs(baseOffset, xrefInfo, newXref) {
37544
+ if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
37545
+ const md5 = computeMD5(baseOffset, xrefInfo);
37546
+ newXref.set("ID", [xrefInfo.fileIds[0], md5]);
37547
+ }
37548
+ }
37549
+ function getTrailerDict(xrefInfo, newRefs, useXrefStream) {
37550
+ const newXref = new Dict(null);
37551
+ newXref.set("Prev", xrefInfo.startXRef);
37552
+ const refForXrefTable = xrefInfo.newRef;
37553
+ if (useXrefStream) {
37554
+ newRefs.push({
37555
+ ref: refForXrefTable,
37556
+ data: ""
37557
+ });
37558
+ newXref.set("Size", refForXrefTable.num + 1);
37559
+ newXref.set("Type", Name.get("XRef"));
37560
+ } else {
37561
+ newXref.set("Size", refForXrefTable.num);
37562
+ }
37563
+ if (xrefInfo.rootRef !== null) {
37564
+ newXref.set("Root", xrefInfo.rootRef);
37565
+ }
37566
+ if (xrefInfo.infoRef !== null) {
37567
+ newXref.set("Info", xrefInfo.infoRef);
37568
+ }
37569
+ if (xrefInfo.encryptRef !== null) {
37570
+ newXref.set("Encrypt", xrefInfo.encryptRef);
37571
+ }
37572
+ return newXref;
37573
+ }
37461
37574
  async function incrementalUpdate({
37462
37575
  originalData,
37463
37576
  xrefInfo,
@@ -37469,7 +37582,8 @@ async function incrementalUpdate({
37469
37582
  needAppearances,
37470
37583
  acroFormRef = null,
37471
37584
  acroForm = null,
37472
- xfaData = null
37585
+ xfaData = null,
37586
+ useXrefStream = false
37473
37587
  }) {
37474
37588
  await updateAcroform({
37475
37589
  xref,
@@ -37489,8 +37603,6 @@ async function incrementalUpdate({
37489
37603
  xref
37490
37604
  });
37491
37605
  }
37492
- const newXref = new Dict(null);
37493
- const refForXrefTable = xrefInfo.newRef;
37494
37606
  let buffer, baseOffset;
37495
37607
  const lastByte = originalData.at(-1);
37496
37608
  if (lastByte === 0x0a || lastByte === 0x0d) {
@@ -37500,67 +37612,22 @@ async function incrementalUpdate({
37500
37612
  buffer = ["\n"];
37501
37613
  baseOffset = originalData.length + 1;
37502
37614
  }
37503
- newXref.set("Size", refForXrefTable.num + 1);
37504
- newXref.set("Prev", xrefInfo.startXRef);
37505
- newXref.set("Type", Name.get("XRef"));
37506
- if (xrefInfo.rootRef !== null) {
37507
- newXref.set("Root", xrefInfo.rootRef);
37508
- }
37509
- if (xrefInfo.infoRef !== null) {
37510
- newXref.set("Info", xrefInfo.infoRef);
37511
- }
37512
- if (xrefInfo.encryptRef !== null) {
37513
- newXref.set("Encrypt", xrefInfo.encryptRef);
37514
- }
37515
- newRefs.push({
37516
- ref: refForXrefTable,
37517
- data: ""
37518
- });
37519
- newRefs = newRefs.sort((a, b) => {
37520
- return a.ref.num - b.ref.num;
37521
- });
37522
- const xrefTableData = [[0, 1, 0xffff]];
37523
- const indexes = [0, 1];
37524
- let maxOffset = 0;
37615
+ const newXref = getTrailerDict(xrefInfo, newRefs, useXrefStream);
37616
+ newRefs = newRefs.sort((a, b) => a.ref.num - b.ref.num);
37525
37617
  for (const {
37526
- ref,
37527
37618
  data
37528
37619
  } of newRefs) {
37529
- maxOffset = Math.max(maxOffset, baseOffset);
37530
- xrefTableData.push([1, baseOffset, Math.min(ref.gen, 0xffff)]);
37531
- baseOffset += data.length;
37532
- indexes.push(ref.num, 1);
37533
37620
  buffer.push(data);
37534
37621
  }
37535
- newXref.set("Index", indexes);
37536
- if (Array.isArray(xrefInfo.fileIds) && xrefInfo.fileIds.length > 0) {
37537
- const md5 = computeMD5(baseOffset, xrefInfo);
37538
- newXref.set("ID", [xrefInfo.fileIds[0], md5]);
37539
- }
37540
- const offsetSize = Math.ceil(Math.log2(maxOffset) / 8);
37541
- const sizes = [1, offsetSize, 2];
37542
- const structSize = sizes[0] + sizes[1] + sizes[2];
37543
- const tableLength = structSize * xrefTableData.length;
37544
- newXref.set("W", sizes);
37545
- newXref.set("Length", tableLength);
37546
- buffer.push(`${refForXrefTable.num} ${refForXrefTable.gen} obj\n`);
37547
- await writeDict(newXref, buffer, null);
37548
- buffer.push(" stream\n");
37549
- const bufferLen = buffer.reduce((a, str) => a + str.length, 0);
37550
- const footer = `\nendstream\nendobj\nstartxref\n${baseOffset}\n%%EOF\n`;
37551
- const array = new Uint8Array(originalData.length + bufferLen + tableLength + footer.length);
37622
+ await (useXrefStream ? getXRefStreamTable(xrefInfo, baseOffset, newRefs, newXref, buffer) : getXRefTable(xrefInfo, baseOffset, newRefs, newXref, buffer));
37623
+ const totalLength = buffer.reduce((a, str) => a + str.length, originalData.length);
37624
+ const array = new Uint8Array(totalLength);
37552
37625
  array.set(originalData);
37553
37626
  let offset = originalData.length;
37554
37627
  for (const str of buffer) {
37555
37628
  writeString(str, offset, array);
37556
37629
  offset += str.length;
37557
37630
  }
37558
- for (const [type, objOffset, gen] of xrefTableData) {
37559
- offset = writeInt(type, sizes[0], offset, array);
37560
- offset = writeInt(objOffset, sizes[1], offset, array);
37561
- offset = writeInt(gen, sizes[2], offset, array);
37562
- }
37563
- writeString(footer, offset, array);
37564
37631
  return array;
37565
37632
  }
37566
37633
 
@@ -38539,7 +38606,7 @@ class Catalog {
38539
38606
  continue;
38540
38607
  }
38541
38608
  if (!outlineDict.has("Title")) {
38542
- throw new FormatError("Invalid outline item encountered.");
38609
+ warn("Invalid outline item encountered.");
38543
38610
  }
38544
38611
  const data = {
38545
38612
  url: null,
@@ -38568,7 +38635,7 @@ class Catalog {
38568
38635
  unsafeUrl: data.unsafeUrl,
38569
38636
  newWindow: data.newWindow,
38570
38637
  setOCGState: data.setOCGState,
38571
- title: stringToPDFString(title),
38638
+ title: typeof title === "string" ? stringToPDFString(title) : "",
38572
38639
  color: rgbColor,
38573
38640
  count: Number.isInteger(count) ? count : undefined,
38574
38641
  bold: !!(flags & 2),
@@ -38648,14 +38715,9 @@ class Catalog {
38648
38715
  continue;
38649
38716
  }
38650
38717
  groupRefs.put(groupRef);
38651
- const group = this.xref.fetch(groupRef);
38652
- groups.push({
38653
- id: groupRef.toString(),
38654
- name: typeof group.get("Name") === "string" ? stringToPDFString(group.get("Name")) : null,
38655
- intent: typeof group.get("Intent") === "string" ? stringToPDFString(group.get("Intent")) : null
38656
- });
38718
+ groups.push(this.#readOptionalContentGroup(groupRef));
38657
38719
  }
38658
- config = this._readOptionalContentConfig(defaultConfig, groupRefs);
38720
+ config = this.#readOptionalContentConfig(defaultConfig, groupRefs);
38659
38721
  config.groups = groups;
38660
38722
  } catch (ex) {
38661
38723
  if (ex instanceof MissingDataException) {
@@ -38665,7 +38727,62 @@ class Catalog {
38665
38727
  }
38666
38728
  return shadow(this, "optionalContentConfig", config);
38667
38729
  }
38668
- _readOptionalContentConfig(config, contentGroupRefs) {
38730
+ #readOptionalContentGroup(groupRef) {
38731
+ const group = this.xref.fetch(groupRef);
38732
+ const obj = {
38733
+ id: groupRef.toString(),
38734
+ name: null,
38735
+ intent: null,
38736
+ usage: {
38737
+ print: null,
38738
+ view: null
38739
+ }
38740
+ };
38741
+ const name = group.get("Name");
38742
+ if (typeof name === "string") {
38743
+ obj.name = stringToPDFString(name);
38744
+ }
38745
+ let intent = group.getArray("Intent");
38746
+ if (!Array.isArray(intent)) {
38747
+ intent = [intent];
38748
+ }
38749
+ if (intent.every(i => i instanceof Name)) {
38750
+ obj.intent = intent.map(i => i.name);
38751
+ }
38752
+ const usage = group.get("Usage");
38753
+ if (!(usage instanceof Dict)) {
38754
+ return obj;
38755
+ }
38756
+ const usageObj = obj.usage;
38757
+ const print = usage.get("Print");
38758
+ if (print instanceof Dict) {
38759
+ const printState = print.get("PrintState");
38760
+ if (printState instanceof Name) {
38761
+ switch (printState.name) {
38762
+ case "ON":
38763
+ case "OFF":
38764
+ usageObj.print = {
38765
+ printState: printState.name
38766
+ };
38767
+ }
38768
+ }
38769
+ }
38770
+ const view = usage.get("View");
38771
+ if (view instanceof Dict) {
38772
+ const viewState = view.get("ViewState");
38773
+ if (viewState instanceof Name) {
38774
+ switch (viewState.name) {
38775
+ case "ON":
38776
+ case "OFF":
38777
+ usageObj.view = {
38778
+ viewState: viewState.name
38779
+ };
38780
+ }
38781
+ }
38782
+ }
38783
+ return obj;
38784
+ }
38785
+ #readOptionalContentConfig(config, contentGroupRefs) {
38669
38786
  function parseOnOff(refs) {
38670
38787
  const onParsed = [];
38671
38788
  if (Array.isArray(refs)) {
@@ -39028,9 +39145,7 @@ class Catalog {
39028
39145
  break;
39029
39146
  case "PrintPageRange":
39030
39147
  if (Array.isArray(value) && value.length % 2 === 0) {
39031
- const isValid = value.every((page, i, arr) => {
39032
- return Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages;
39033
- });
39148
+ const isValid = value.every((page, i, arr) => Number.isInteger(page) && page > 0 && (i === 0 || page >= arr[i - 1]) && page <= this.numPages);
39034
39149
  if (isValid) {
39035
39150
  prefValue = value;
39036
39151
  }
@@ -39526,7 +39641,11 @@ class Catalog {
39526
39641
  case "GoToR":
39527
39642
  const urlDict = action.get("F");
39528
39643
  if (urlDict instanceof Dict) {
39529
- url = urlDict.get("F") || null;
39644
+ const fs = new FileSpec(urlDict, null, true);
39645
+ const {
39646
+ filename
39647
+ } = fs.serializable;
39648
+ url = filename;
39530
39649
  } else if (typeof urlDict === "string") {
39531
39650
  url = urlDict;
39532
39651
  }
@@ -40002,12 +40121,10 @@ function getRelevant(data) {
40002
40121
  if (!data) {
40003
40122
  return [];
40004
40123
  }
40005
- return data.trim().split(/\s+/).map(e => {
40006
- return {
40007
- excluded: e[0] === "-",
40008
- viewname: e.substring(1)
40009
- };
40010
- });
40124
+ return data.trim().split(/\s+/).map(e => ({
40125
+ excluded: e[0] === "-",
40126
+ viewname: e.substring(1)
40127
+ }));
40011
40128
  }
40012
40129
  function getColor(data, def = [0, 0, 0]) {
40013
40130
  let [r, g, b] = def;
@@ -50645,7 +50762,11 @@ class AnnotationFactory {
50645
50762
  }));
50646
50763
  break;
50647
50764
  case AnnotationEditorType.HIGHLIGHT:
50648
- promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
50765
+ if (annotation.quadPoints) {
50766
+ promises.push(HighlightAnnotation.createNewAnnotation(xref, annotation, dependencies));
50767
+ } else {
50768
+ promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
50769
+ }
50649
50770
  break;
50650
50771
  case AnnotationEditorType.INK:
50651
50772
  promises.push(InkAnnotation.createNewAnnotation(xref, annotation, dependencies));
@@ -50712,9 +50833,15 @@ class AnnotationFactory {
50712
50833
  }));
50713
50834
  break;
50714
50835
  case AnnotationEditorType.HIGHLIGHT:
50715
- promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50716
- evaluatorOptions: options
50717
- }));
50836
+ if (annotation.quadPoints) {
50837
+ promises.push(HighlightAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50838
+ evaluatorOptions: options
50839
+ }));
50840
+ } else {
50841
+ promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
50842
+ evaluatorOptions: options
50843
+ }));
50844
+ }
50718
50845
  break;
50719
50846
  case AnnotationEditorType.INK:
50720
50847
  promises.push(InkAnnotation.createNewPrintAnnotation(annotationGlobals, xref, annotation, {
@@ -51092,9 +51219,21 @@ class Annotation {
51092
51219
  });
51093
51220
  }
51094
51221
  async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
51095
- const data = this.data;
51222
+ const {
51223
+ hasOwnCanvas,
51224
+ id,
51225
+ rect
51226
+ } = this.data;
51096
51227
  let appearance = this.appearance;
51097
- const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
51228
+ const isUsingOwnCanvas = !!(hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
51229
+ if (isUsingOwnCanvas && (rect[0] === rect[2] || rect[1] === rect[3])) {
51230
+ this.data.hasOwnCanvas = false;
51231
+ return {
51232
+ opList: new OperatorList(),
51233
+ separateForm: false,
51234
+ separateCanvas: false
51235
+ };
51236
+ }
51098
51237
  if (!appearance) {
51099
51238
  if (!isUsingOwnCanvas) {
51100
51239
  return {
@@ -51110,7 +51249,7 @@ class Annotation {
51110
51249
  const resources = await this.loadResources(["ExtGState", "ColorSpace", "Pattern", "Shading", "XObject", "Font"], appearance);
51111
51250
  const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
51112
51251
  const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
51113
- const transform = getTransformMatrix(data.rect, bbox, matrix);
51252
+ const transform = getTransformMatrix(rect, bbox, matrix);
51114
51253
  const opList = new OperatorList();
51115
51254
  let optionalContent;
51116
51255
  if (this.oc) {
@@ -51119,7 +51258,7 @@ class Annotation {
51119
51258
  if (optionalContent !== undefined) {
51120
51259
  opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
51121
51260
  }
51122
- opList.addOp(OPS.beginAnnotation, [data.id, data.rect, transform, matrix, isUsingOwnCanvas]);
51261
+ opList.addOp(OPS.beginAnnotation, [id, rect, transform, matrix, isUsingOwnCanvas]);
51123
51262
  await evaluator.getOperatorList({
51124
51263
  stream: appearance,
51125
51264
  task,
@@ -51163,7 +51302,7 @@ class Annotation {
51163
51302
  firstPosition ||= item.transform.slice(-2);
51164
51303
  buffer.push(item.str);
51165
51304
  if (item.hasEOL) {
51166
- text.push(buffer.join(""));
51305
+ text.push(buffer.join("").trimEnd());
51167
51306
  buffer.length = 0;
51168
51307
  }
51169
51308
  }
@@ -51174,27 +51313,32 @@ class Annotation {
51174
51313
  task,
51175
51314
  resources,
51176
51315
  includeMarkedContent: true,
51316
+ keepWhiteSpace: true,
51177
51317
  sink,
51178
51318
  viewBox
51179
51319
  });
51180
51320
  this.reset();
51181
51321
  if (buffer.length) {
51182
- text.push(buffer.join(""));
51322
+ text.push(buffer.join("").trimEnd());
51183
51323
  }
51184
51324
  if (text.length > 1 || text[0]) {
51185
51325
  const appearanceDict = this.appearance.dict;
51186
- const bbox = appearanceDict.getArray("BBox") || [0, 0, 1, 1];
51187
- const matrix = appearanceDict.getArray("Matrix") || [1, 0, 0, 1, 0, 0];
51188
- const rect = this.data.rect;
51189
- const transform = getTransformMatrix(rect, bbox, matrix);
51190
- transform[4] -= rect[0];
51191
- transform[5] -= rect[1];
51192
- firstPosition = Util.applyTransform(firstPosition, transform);
51193
- firstPosition = Util.applyTransform(firstPosition, matrix);
51194
- this.data.textPosition = firstPosition;
51326
+ this.data.textPosition = this._transformPoint(firstPosition, appearanceDict.getArray("BBox"), appearanceDict.getArray("Matrix"));
51195
51327
  this.data.textContent = text;
51196
51328
  }
51197
51329
  }
51330
+ _transformPoint(coords, bbox, matrix) {
51331
+ const {
51332
+ rect
51333
+ } = this.data;
51334
+ bbox ||= [0, 0, 1, 1];
51335
+ matrix ||= [1, 0, 0, 1, 0, 0];
51336
+ const transform = getTransformMatrix(rect, bbox, matrix);
51337
+ transform[4] -= rect[0];
51338
+ transform[5] -= rect[1];
51339
+ coords = Util.applyTransform(coords, transform);
51340
+ return Util.applyTransform(coords, matrix);
51341
+ }
51198
51342
  getFieldObject() {
51199
51343
  if (this.data.kidIds) {
51200
51344
  return {
@@ -51298,7 +51442,7 @@ class AnnotationBorderStyle {
51298
51442
  }
51299
51443
  }
51300
51444
  setDashArray(dashArray, forceStyle = false) {
51301
- if (Array.isArray(dashArray) && dashArray.length > 0) {
51445
+ if (Array.isArray(dashArray)) {
51302
51446
  let isValid = true;
51303
51447
  let allZeros = true;
51304
51448
  for (const element of dashArray) {
@@ -51310,7 +51454,7 @@ class AnnotationBorderStyle {
51310
51454
  allZeros = false;
51311
51455
  }
51312
51456
  }
51313
- if (isValid && !allZeros) {
51457
+ if (dashArray.length === 0 || isValid && !allZeros) {
51314
51458
  this.dashArray = dashArray;
51315
51459
  if (forceStyle) {
51316
51460
  this.setStyle(Name.get("D"));
@@ -51750,9 +51894,7 @@ class WidgetAnnotation extends Annotation {
51750
51894
  path: this.data.fieldName,
51751
51895
  value
51752
51896
  };
51753
- const encoder = val => {
51754
- return isAscii(val) ? val : stringToUTF16String(val, true);
51755
- };
51897
+ const encoder = val => isAscii(val) ? val : stringToUTF16String(val, true);
51756
51898
  dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
51757
51899
  this.amendSavedDict(annotationStorage, dict);
51758
51900
  const maybeMK = this._getMKDict(rotation);
@@ -52789,6 +52931,7 @@ class LinkAnnotation extends Annotation {
52789
52931
  annotationGlobals
52790
52932
  } = params;
52791
52933
  this.data.annotationType = AnnotationType.LINK;
52934
+ this.data.noHTML = false;
52792
52935
  const quadPoints = getQuadPoints(dict, this.rectangle);
52793
52936
  if (quadPoints) {
52794
52937
  this.data.quadPoints = quadPoints;
@@ -52863,29 +53006,41 @@ class FreeTextAnnotation extends MarkupAnnotation {
52863
53006
  } = params;
52864
53007
  this.data.annotationType = AnnotationType.FREETEXT;
52865
53008
  this.setDefaultAppearance(params);
52866
- if (this.appearance) {
53009
+ this._hasAppearance = !!this.appearance;
53010
+ if (this._hasAppearance) {
52867
53011
  const {
52868
53012
  fontColor,
52869
53013
  fontSize
52870
53014
  } = parseAppearanceStream(this.appearance, evaluatorOptions, xref);
52871
53015
  this.data.defaultAppearanceData.fontColor = fontColor;
52872
53016
  this.data.defaultAppearanceData.fontSize = fontSize || 10;
52873
- } else if (this._isOffscreenCanvasSupported) {
52874
- const strokeAlpha = params.dict.get("CA");
52875
- const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
53017
+ } else {
52876
53018
  this.data.defaultAppearanceData.fontSize ||= 10;
52877
53019
  const {
52878
53020
  fontColor,
52879
53021
  fontSize
52880
53022
  } = this.data.defaultAppearanceData;
52881
- this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
52882
- this._streams.push(this.appearance, FakeUnicodeFont.toUnicodeStream);
52883
- } else {
52884
- warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
53023
+ if (this._contents.str) {
53024
+ this.data.textContent = this._contents.str.split(/\r\n?|\n/).map(line => line.trimEnd());
53025
+ const {
53026
+ coords,
53027
+ bbox,
53028
+ matrix
53029
+ } = FakeUnicodeFont.getFirstPositionInfo(this.rectangle, this.rotation, fontSize);
53030
+ this.data.textPosition = this._transformPoint(coords, bbox, matrix);
53031
+ }
53032
+ if (this._isOffscreenCanvasSupported) {
53033
+ const strokeAlpha = params.dict.get("CA");
53034
+ const fakeUnicodeFont = new FakeUnicodeFont(xref, "sans-serif");
53035
+ this.appearance = fakeUnicodeFont.createAppearance(this._contents.str, this.rectangle, this.rotation, fontSize, fontColor, strokeAlpha);
53036
+ this._streams.push(this.appearance);
53037
+ } else {
53038
+ warn("FreeTextAnnotation: OffscreenCanvas is not supported, annotation may not render correctly.");
53039
+ }
52885
53040
  }
52886
53041
  }
52887
53042
  get hasTextContent() {
52888
- return !!this.appearance;
53043
+ return this._hasAppearance;
52889
53044
  }
52890
53045
  static createNewDict(annotation, xref, {
52891
53046
  apRef,
@@ -53300,6 +53455,7 @@ class InkAnnotation extends MarkupAnnotation {
53300
53455
  color,
53301
53456
  opacity,
53302
53457
  paths,
53458
+ outlines,
53303
53459
  rect,
53304
53460
  rotation,
53305
53461
  thickness
@@ -53309,9 +53465,12 @@ class InkAnnotation extends MarkupAnnotation {
53309
53465
  ink.set("Subtype", Name.get("Ink"));
53310
53466
  ink.set("CreationDate", `D:${getModificationDate()}`);
53311
53467
  ink.set("Rect", rect);
53312
- ink.set("InkList", paths.map(p => p.points));
53468
+ ink.set("InkList", outlines?.points || paths.map(p => p.points));
53313
53469
  ink.set("F", 4);
53314
53470
  ink.set("Rotate", rotation);
53471
+ if (outlines) {
53472
+ ink.set("IT", Name.get("InkHighlight"));
53473
+ }
53315
53474
  const bs = new Dict(xref);
53316
53475
  ink.set("BS", bs);
53317
53476
  bs.set("W", thickness);
@@ -53327,6 +53486,9 @@ class InkAnnotation extends MarkupAnnotation {
53327
53486
  return ink;
53328
53487
  }
53329
53488
  static async createNewAppearanceStream(annotation, xref, params) {
53489
+ if (annotation.outlines) {
53490
+ return this.createNewAppearanceStreamForHighlight(annotation, xref, params);
53491
+ }
53330
53492
  const {
53331
53493
  color,
53332
53494
  rect,
@@ -53344,11 +53506,15 @@ class InkAnnotation extends MarkupAnnotation {
53344
53506
  } of paths) {
53345
53507
  buffer.length = 0;
53346
53508
  buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} m`);
53347
- for (let i = 2, ii = bezier.length; i < ii; i += 6) {
53348
- const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
53349
- buffer.push(`${curve} c`);
53509
+ if (bezier.length === 2) {
53510
+ buffer.push(`${numberToString(bezier[0])} ${numberToString(bezier[1])} l S`);
53511
+ } else {
53512
+ for (let i = 2, ii = bezier.length; i < ii; i += 6) {
53513
+ const curve = bezier.slice(i, i + 6).map(numberToString).join(" ");
53514
+ buffer.push(`${curve} c`);
53515
+ }
53516
+ buffer.push("S");
53350
53517
  }
53351
- buffer.push("S");
53352
53518
  appearanceBuffer.push(buffer.join("\n"));
53353
53519
  }
53354
53520
  const appearance = appearanceBuffer.join("\n");
@@ -53372,6 +53538,48 @@ class InkAnnotation extends MarkupAnnotation {
53372
53538
  ap.dict = appearanceStreamDict;
53373
53539
  return ap;
53374
53540
  }
53541
+ static async createNewAppearanceStreamForHighlight(annotation, xref, params) {
53542
+ const {
53543
+ color,
53544
+ rect,
53545
+ outlines: {
53546
+ outline
53547
+ },
53548
+ opacity
53549
+ } = annotation;
53550
+ const appearanceBuffer = [`${getPdfColor(color, true)}`, "/R0 gs"];
53551
+ appearanceBuffer.push(`${numberToString(outline[4])} ${numberToString(outline[5])} m`);
53552
+ for (let i = 6, ii = outline.length; i < ii; i += 6) {
53553
+ if (isNaN(outline[i]) || outline[i] === null) {
53554
+ appearanceBuffer.push(`${numberToString(outline[i + 4])} ${numberToString(outline[i + 5])} l`);
53555
+ } else {
53556
+ const curve = outline.slice(i, i + 6).map(numberToString).join(" ");
53557
+ appearanceBuffer.push(`${curve} c`);
53558
+ }
53559
+ }
53560
+ appearanceBuffer.push("h f");
53561
+ const appearance = appearanceBuffer.join("\n");
53562
+ const appearanceStreamDict = new Dict(xref);
53563
+ appearanceStreamDict.set("FormType", 1);
53564
+ appearanceStreamDict.set("Subtype", Name.get("Form"));
53565
+ appearanceStreamDict.set("Type", Name.get("XObject"));
53566
+ appearanceStreamDict.set("BBox", rect);
53567
+ appearanceStreamDict.set("Length", appearance.length);
53568
+ const resources = new Dict(xref);
53569
+ const extGState = new Dict(xref);
53570
+ resources.set("ExtGState", extGState);
53571
+ appearanceStreamDict.set("Resources", resources);
53572
+ const r0 = new Dict(xref);
53573
+ extGState.set("R0", r0);
53574
+ r0.set("BM", Name.get("Multiply"));
53575
+ if (opacity !== 1) {
53576
+ r0.set("ca", opacity);
53577
+ r0.set("Type", Name.get("ExtGState"));
53578
+ }
53579
+ const ap = new StringStream(appearance);
53580
+ ap.dict = appearanceStreamDict;
53581
+ return ap;
53582
+ }
53375
53583
  }
53376
53584
  class HighlightAnnotation extends MarkupAnnotation {
53377
53585
  constructor(params) {
@@ -53606,9 +53814,7 @@ class StampAnnotation extends MarkupAnnotation {
53606
53814
  const jpegBufferPromise = canvas.convertToBlob({
53607
53815
  type: "image/jpeg",
53608
53816
  quality: 1
53609
- }).then(blob => {
53610
- return blob.arrayBuffer();
53611
- });
53817
+ }).then(blob => blob.arrayBuffer());
53612
53818
  const xobjectName = Name.get("XObject");
53613
53819
  const imageName = Name.get("Image");
53614
53820
  const image = new Dict(xref);
@@ -55025,17 +55231,24 @@ class Page {
55025
55231
  }));
55026
55232
  }
55027
55233
  const sortedAnnotations = [];
55028
- let popupAnnotations;
55234
+ let popupAnnotations, widgetAnnotations;
55029
55235
  for (const annotation of await Promise.all(annotationPromises)) {
55030
55236
  if (!annotation) {
55031
55237
  continue;
55032
55238
  }
55239
+ if (annotation instanceof WidgetAnnotation) {
55240
+ (widgetAnnotations ||= []).push(annotation);
55241
+ continue;
55242
+ }
55033
55243
  if (annotation instanceof PopupAnnotation) {
55034
55244
  (popupAnnotations ||= []).push(annotation);
55035
55245
  continue;
55036
55246
  }
55037
55247
  sortedAnnotations.push(annotation);
55038
55248
  }
55249
+ if (widgetAnnotations) {
55250
+ sortedAnnotations.push(...widgetAnnotations);
55251
+ }
55039
55252
  if (popupAnnotations) {
55040
55253
  sortedAnnotations.push(...popupAnnotations);
55041
55254
  }
@@ -55140,7 +55353,13 @@ class PDFDocument {
55140
55353
  if (this.linearization) {
55141
55354
  stream.reset();
55142
55355
  if (find(stream, ENDOBJ_SIGNATURE)) {
55143
- startXRef = stream.pos + 6 - stream.start;
55356
+ stream.skip(6);
55357
+ let ch = stream.peekByte();
55358
+ while (isWhiteSpace(ch)) {
55359
+ stream.pos++;
55360
+ ch = stream.peekByte();
55361
+ }
55362
+ startXRef = stream.pos - stream.start;
55144
55363
  }
55145
55364
  } else {
55146
55365
  const step = 1024;
@@ -56151,7 +56370,7 @@ class MessageHandler {
56151
56370
  }
56152
56371
  sendWithPromise(actionName, data, transfers) {
56153
56372
  const callbackId = this.callbackId++;
56154
- const capability = new PromiseCapability();
56373
+ const capability = Promise.withResolvers();
56155
56374
  this.callbackCapabilities[callbackId] = capability;
56156
56375
  try {
56157
56376
  this.comObj.postMessage({
@@ -56173,7 +56392,7 @@ class MessageHandler {
56173
56392
  comObj = this.comObj;
56174
56393
  return new ReadableStream({
56175
56394
  start: controller => {
56176
- const startCapability = new PromiseCapability();
56395
+ const startCapability = Promise.withResolvers();
56177
56396
  this.streamControllers[streamId] = {
56178
56397
  controller,
56179
56398
  startCall: startCapability,
@@ -56192,7 +56411,7 @@ class MessageHandler {
56192
56411
  return startCapability.promise;
56193
56412
  },
56194
56413
  pull: controller => {
56195
- const pullCapability = new PromiseCapability();
56414
+ const pullCapability = Promise.withResolvers();
56196
56415
  this.streamControllers[streamId].pullCall = pullCapability;
56197
56416
  comObj.postMessage({
56198
56417
  sourceName,
@@ -56205,7 +56424,7 @@ class MessageHandler {
56205
56424
  },
56206
56425
  cancel: reason => {
56207
56426
  assert(reason instanceof Error, "cancel must have a valid reason");
56208
- const cancelCapability = new PromiseCapability();
56427
+ const cancelCapability = Promise.withResolvers();
56209
56428
  this.streamControllers[streamId].cancelCall = cancelCapability;
56210
56429
  this.streamControllers[streamId].isClosed = true;
56211
56430
  comObj.postMessage({
@@ -56234,7 +56453,7 @@ class MessageHandler {
56234
56453
  const lastDesiredSize = this.desiredSize;
56235
56454
  this.desiredSize -= size;
56236
56455
  if (lastDesiredSize > 0 && this.desiredSize <= 0) {
56237
- this.sinkCapability = new PromiseCapability();
56456
+ this.sinkCapability = Promise.withResolvers();
56238
56457
  this.ready = this.sinkCapability.promise;
56239
56458
  }
56240
56459
  comObj.postMessage({
@@ -56272,7 +56491,7 @@ class MessageHandler {
56272
56491
  reason: wrapReason(reason)
56273
56492
  });
56274
56493
  },
56275
- sinkCapability: new PromiseCapability(),
56494
+ sinkCapability: Promise.withResolvers(),
56276
56495
  onPull: null,
56277
56496
  onCancel: null,
56278
56497
  isCancelled: false,
@@ -56550,7 +56769,7 @@ class WorkerTask {
56550
56769
  constructor(name) {
56551
56770
  this.name = name;
56552
56771
  this.terminated = false;
56553
- this._capability = new PromiseCapability();
56772
+ this._capability = Promise.withResolvers();
56554
56773
  }
56555
56774
  get finished() {
56556
56775
  return this._capability.promise;
@@ -56594,7 +56813,7 @@ class WorkerMessageHandler {
56594
56813
  docId,
56595
56814
  apiVersion
56596
56815
  } = docParams;
56597
- const workerVersion = '4.0.379';
56816
+ const workerVersion = "4.1.392";
56598
56817
  if (apiVersion !== workerVersion) {
56599
56818
  throw new Error(`The API version "${apiVersion}" does not match ` + `the Worker version "${workerVersion}".`);
56600
56819
  }
@@ -56661,7 +56880,7 @@ class WorkerMessageHandler {
56661
56880
  password,
56662
56881
  rangeChunkSize
56663
56882
  };
56664
- const pdfManagerCapability = new PromiseCapability();
56883
+ const pdfManagerCapability = Promise.withResolvers();
56665
56884
  let newPdfManager;
56666
56885
  if (data) {
56667
56886
  try {
@@ -57043,7 +57262,8 @@ class WorkerMessageHandler {
57043
57262
  needAppearances,
57044
57263
  acroFormRef,
57045
57264
  acroForm,
57046
- xfaData
57265
+ xfaData,
57266
+ useXrefStream: isDict(xref.topDict, "XRef")
57047
57267
  }).finally(() => {
57048
57268
  xref.resetNewTemporaryRef();
57049
57269
  });
@@ -57162,8 +57382,8 @@ if (typeof window === "undefined" && !isNodeJS && typeof self !== "undefined" &&
57162
57382
 
57163
57383
  ;// CONCATENATED MODULE: ./src/pdf.worker.js
57164
57384
 
57165
- const pdfjsVersion = '4.0.379';
57166
- const pdfjsBuild = '9e14d04fd';
57385
+ const pdfjsVersion = "4.1.392";
57386
+ const pdfjsBuild = "fcb76a78d";
57167
57387
 
57168
57388
  var __webpack_exports__WorkerMessageHandler = __webpack_exports__.WorkerMessageHandler;
57169
57389
  export { __webpack_exports__WorkerMessageHandler as WorkerMessageHandler };