@chialab/pdfjs-lib 1.0.0-alpha.4 → 1.0.0-alpha.6

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.
@@ -326,6 +326,12 @@ var OPS = {
326
326
  setStrokeTransparent: 92,
327
327
  setFillTransparent: 93
328
328
  };
329
+ var DrawOPS = {
330
+ moveTo: 0,
331
+ lineTo: 1,
332
+ curveTo: 2,
333
+ closePath: 3
334
+ };
329
335
  var PasswordResponses = {
330
336
  NEED_PASSWORD: 1,
331
337
  INCORRECT_PASSWORD: 2
@@ -574,53 +580,6 @@ var Util = class {
574
580
  static makeHexColor(r, g, b) {
575
581
  return `#${hexNumbers[r]}${hexNumbers[g]}${hexNumbers[b]}`;
576
582
  }
577
- // Apply a scaling matrix to some min/max values.
578
- // If a scaling factor is negative then min and max must be
579
- // swapped.
580
- static scaleMinMax(transform, minMax) {
581
- let temp;
582
- if (transform[0]) {
583
- if (transform[0] < 0) {
584
- temp = minMax[0];
585
- minMax[0] = minMax[2];
586
- minMax[2] = temp;
587
- }
588
- minMax[0] *= transform[0];
589
- minMax[2] *= transform[0];
590
- if (transform[3] < 0) {
591
- temp = minMax[1];
592
- minMax[1] = minMax[3];
593
- minMax[3] = temp;
594
- }
595
- minMax[1] *= transform[3];
596
- minMax[3] *= transform[3];
597
- } else {
598
- temp = minMax[0];
599
- minMax[0] = minMax[1];
600
- minMax[1] = temp;
601
- temp = minMax[2];
602
- minMax[2] = minMax[3];
603
- minMax[3] = temp;
604
- if (transform[1] < 0) {
605
- temp = minMax[1];
606
- minMax[1] = minMax[3];
607
- minMax[3] = temp;
608
- }
609
- minMax[1] *= transform[1];
610
- minMax[3] *= transform[1];
611
- if (transform[2] < 0) {
612
- temp = minMax[0];
613
- minMax[0] = minMax[2];
614
- minMax[2] = temp;
615
- }
616
- minMax[0] *= transform[2];
617
- minMax[2] *= transform[2];
618
- }
619
- minMax[0] += transform[4];
620
- minMax[1] += transform[5];
621
- minMax[2] += transform[4];
622
- minMax[3] += transform[5];
623
- }
624
583
  // Concatenates two transformation matrices together and returns the result.
625
584
  static transform(m1, m2) {
626
585
  return [
@@ -728,24 +687,26 @@ var Util = class {
728
687
  }
729
688
  return [xLow, yLow, xHigh, yHigh];
730
689
  }
690
+ static pointBoundingBox(x, y, minMax) {
691
+ minMax[0] = Math.min(minMax[0], x);
692
+ minMax[1] = Math.min(minMax[1], y);
693
+ minMax[2] = Math.max(minMax[2], x);
694
+ minMax[3] = Math.max(minMax[3], y);
695
+ }
696
+ static rectBoundingBox(x0, y0, x1, y1, minMax) {
697
+ minMax[0] = Math.min(minMax[0], x0, x1);
698
+ minMax[1] = Math.min(minMax[1], y0, y1);
699
+ minMax[2] = Math.max(minMax[2], x0, x1);
700
+ minMax[3] = Math.max(minMax[3], y0, y1);
701
+ }
731
702
  // From https://github.com/adobe-webplatform/Snap.svg/blob/b365287722a72526000ac4bfcf0ce4cac2faa015/src/path.js#L852
732
703
  static bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
733
- if (minMax) {
734
- minMax[0] = Math.min(minMax[0], x0, x3);
735
- minMax[1] = Math.min(minMax[1], y0, y3);
736
- minMax[2] = Math.max(minMax[2], x0, x3);
737
- minMax[3] = Math.max(minMax[3], y0, y3);
738
- } else {
739
- minMax = [
740
- Math.min(x0, x3),
741
- Math.min(y0, y3),
742
- Math.max(x0, x3),
743
- Math.max(y0, y3)
744
- ];
745
- }
704
+ minMax[0] = Math.min(minMax[0], x0, x3);
705
+ minMax[1] = Math.min(minMax[1], y0, y3);
706
+ minMax[2] = Math.max(minMax[2], x0, x3);
707
+ minMax[3] = Math.max(minMax[3], y0, y3);
746
708
  __privateMethod(this, _Util_static, getExtremum_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-x0 + 3 * (x1 - x2) + x3), 6 * (x0 - 2 * x1 + x2), 3 * (x1 - x0), minMax);
747
709
  __privateMethod(this, _Util_static, getExtremum_fn).call(this, x0, x1, x2, x3, y0, y1, y2, y3, 3 * (-y0 + 3 * (y1 - y2) + y3), 6 * (y0 - 2 * y1 + y2), 3 * (y1 - y0), minMax);
748
- return minMax;
749
710
  }
750
711
  };
751
712
  _Util_static = new WeakSet();
@@ -1035,6 +996,56 @@ function getUuid() {
1035
996
  return bytesToString(buf);
1036
997
  }
1037
998
  var AnnotationPrefix = "pdfjs_internal_id_";
999
+ function _isValidExplicitDest(validRef, validName, dest) {
1000
+ if (!Array.isArray(dest) || dest.length < 2) {
1001
+ return false;
1002
+ }
1003
+ const [page, zoom, ...args] = dest;
1004
+ if (!validRef(page) && !Number.isInteger(page)) {
1005
+ return false;
1006
+ }
1007
+ if (!validName(zoom)) {
1008
+ return false;
1009
+ }
1010
+ const argsLen = args.length;
1011
+ let allowNull = true;
1012
+ switch (zoom.name) {
1013
+ case "XYZ":
1014
+ if (argsLen < 2 || argsLen > 3) {
1015
+ return false;
1016
+ }
1017
+ break;
1018
+ case "Fit":
1019
+ case "FitB":
1020
+ return argsLen === 0;
1021
+ case "FitH":
1022
+ case "FitBH":
1023
+ case "FitV":
1024
+ case "FitBV":
1025
+ if (argsLen > 1) {
1026
+ return false;
1027
+ }
1028
+ break;
1029
+ case "FitR":
1030
+ if (argsLen !== 4) {
1031
+ return false;
1032
+ }
1033
+ allowNull = false;
1034
+ break;
1035
+ default:
1036
+ return false;
1037
+ }
1038
+ for (const arg of args) {
1039
+ if (typeof arg === "number" || allowNull && arg === null) {
1040
+ continue;
1041
+ }
1042
+ return false;
1043
+ }
1044
+ return true;
1045
+ }
1046
+ function MathClamp(v, min, max) {
1047
+ return Math.min(Math.max(v, min), max);
1048
+ }
1038
1049
  function toHexUtil(arr) {
1039
1050
  if (Uint8Array.prototype.toHex) {
1040
1051
  return arr.toHex();
@@ -1060,6 +1071,34 @@ if (false) {
1060
1071
  });
1061
1072
  };
1062
1073
  }
1074
+ if (typeof Math.sumPrecise !== "function") {
1075
+ Math.sumPrecise = function(numbers) {
1076
+ return numbers.reduce((a, b) => a + b, 0);
1077
+ };
1078
+ }
1079
+ if (false) {
1080
+ AbortSignal.any = function(iterable) {
1081
+ const ac = new AbortController();
1082
+ const { signal } = ac;
1083
+ for (const s of iterable) {
1084
+ if (s.aborted) {
1085
+ ac.abort(s.reason);
1086
+ return signal;
1087
+ }
1088
+ }
1089
+ for (const s of iterable) {
1090
+ s.addEventListener(
1091
+ "abort",
1092
+ () => {
1093
+ ac.abort(s.reason);
1094
+ },
1095
+ { signal }
1096
+ // Automatically remove the listener.
1097
+ );
1098
+ }
1099
+ return signal;
1100
+ };
1101
+ }
1063
1102
 
1064
1103
  // src/pdf.js/src/shared/message_handler.js
1065
1104
  var CallbackKind = {
@@ -1732,6 +1771,7 @@ export {
1732
1771
  PageActionEventType,
1733
1772
  VerbosityLevel,
1734
1773
  OPS,
1774
+ DrawOPS,
1735
1775
  PasswordResponses,
1736
1776
  setVerbosityLevel,
1737
1777
  getVerbosityLevel,
@@ -1763,6 +1803,8 @@ export {
1763
1803
  normalizeUnicode,
1764
1804
  getUuid,
1765
1805
  AnnotationPrefix,
1806
+ _isValidExplicitDest,
1807
+ MathClamp,
1766
1808
  toHexUtil,
1767
1809
  toBase64Util,
1768
1810
  fromBase64Util,