@chialab/pdfjs-lib 1.0.0-alpha.1 → 1.0.0-alpha.11

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 (35) hide show
  1. package/dist/browser/{chunk-DYHYQ33L.js → chunk-AK2AE3GS.js} +177 -43
  2. package/dist/browser/index.js +934 -1003
  3. package/dist/browser/openjpeg-NLAGCGEG.js +9 -0
  4. package/dist/browser/qcms_bg-EPYCMBVV.js +9 -0
  5. package/dist/browser/worker.js +5828 -5390
  6. package/dist/index.d.ts +1 -0
  7. package/dist/lib/AnnotationData.d.ts +2 -1
  8. package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
  9. package/dist/lib/SvgCanvasContext.d.ts +2 -1
  10. package/dist/lib/TextLayer.d.ts +0 -6
  11. package/dist/lib/WasmFactory.d.ts +5 -0
  12. package/dist/lib/utils.d.ts +9 -1
  13. package/dist/node/{chunk-KTTVPO2G.js → chunk-WL32POZ2.js} +177 -43
  14. package/dist/node/index.js +941 -997
  15. package/dist/node/openjpeg-O3KQE6R6.js +9 -0
  16. package/dist/node/qcms_bg-5Z325MLG.js +9 -0
  17. package/dist/node/worker.js +5828 -5390
  18. package/dist/pdf.js/src/display/api.d.ts +30 -5
  19. package/dist/pdf.js/src/display/canvas.d.ts +19 -27
  20. package/dist/pdf.js/src/display/display_utils.d.ts +10 -0
  21. package/dist/pdf.js/src/display/editor/editor.d.ts +1 -1
  22. package/dist/pdf.js/src/display/editor/highlight.d.ts +1 -0
  23. package/dist/pdf.js/src/display/editor/ink.d.ts +1 -0
  24. package/dist/pdf.js/src/display/editor/signature.d.ts +1 -0
  25. package/dist/pdf.js/src/display/editor/stamp.d.ts +1 -2
  26. package/dist/pdf.js/src/display/editor/tools.d.ts +0 -6
  27. package/dist/pdf.js/src/display/pattern_helper.d.ts +4 -2
  28. package/dist/pdf.js/src/display/touch_manager.d.ts +5 -1
  29. package/dist/pdf.js/src/pdf.d.ts +3 -1
  30. package/dist/pdf.js/src/shared/util.d.ts +111 -95
  31. package/package.json +7 -5
  32. package/dist/browser/LiberationMono-Regular-UUOCTXY2.js +0 -9
  33. package/dist/browser/LiberationSerif-Regular-ASQ2LI3D.js +0 -9
  34. package/dist/node/LiberationMono-Regular-KMFXXO3B.js +0 -9
  35. package/dist/node/LiberationSerif-Regular-WAOWR76G.js +0 -9
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export type { DocumentInitParameters } from './pdf.js/src/display/api';
4
4
  export type { BaseCanvasFactory } from './pdf.js/src/display/canvas_factory';
5
5
  export * from './lib/utils';
6
6
  export * from './lib/Canvas';
7
+ export * from './lib/WasmFactory';
7
8
  export * from './lib/StandardFontDataFactory';
8
9
  export * from './lib/AnnotationData';
9
10
  export * from './lib/SvgCanvasContext';
@@ -1,3 +1,4 @@
1
+ import type { SvgRoot } from './SvgCanvasContext';
1
2
  type Rect = [number, number, number, number];
2
3
  type Color = [number, number, number];
3
4
  type Dir = 'ltr' | 'rtl';
@@ -106,7 +107,7 @@ export interface StrikeOutAnnotationData extends TextAnnotationData {
106
107
  }
107
108
  export interface StampAnnotationData extends TextAnnotationData {
108
109
  subtype: 'Stamp';
109
- graphics: Uint8Array;
110
+ graphics: SvgRoot;
110
111
  }
111
112
  export interface CaretAnnotationData extends TextAnnotationData {
112
113
  subtype: 'Caret';
@@ -0,0 +1,21 @@
1
+ import type { PDFOperatorList } from '../pdf.js/src/display/api';
2
+ export declare class AnnotationOperatorsList {
3
+ readonly map: Map<string, {
4
+ fn: number;
5
+ args: unknown[];
6
+ }[]>;
7
+ /**
8
+ * The list of operators to be executed.
9
+ * @param operatorList The list of operators to be executed.
10
+ */
11
+ constructor(operatorList: PDFOperatorList);
12
+ /**
13
+ * Get the list of operators for the given annotation id.
14
+ * @param id The id of the annotation.
15
+ * @return The list of operators for the given annotation id.
16
+ */
17
+ get(id: string): {
18
+ fn: number;
19
+ args: unknown[];
20
+ }[];
21
+ }
@@ -102,6 +102,7 @@ export declare class SvgCanvasContext {
102
102
  getNode(): SvgRoot;
103
103
  resize(width: number, height: number): void;
104
104
  save(): void;
105
+ clearRect(x: number, y: number, width: number, height: number): void;
105
106
  restore(): void;
106
107
  beginPath(): void;
107
108
  closePath(): void;
@@ -113,7 +114,7 @@ export declare class SvgCanvasContext {
113
114
  arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
114
115
  rect(x: number, y: number, width: number, height: number): void;
115
116
  ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: boolean): void;
116
- stroke(): void;
117
+ stroke(path?: Path2D): void;
117
118
  transform(...values: number[]): void;
118
119
  translate(x: number, y: number): void;
119
120
  scale(x: number, y: number): void;
@@ -37,12 +37,6 @@ export interface TextLayerImage extends TextLayerNode {
37
37
  export declare function isTextNode(node: TextLayerNode): node is TextLayerText;
38
38
  export declare function isAnchorNode(node: TextLayerNode): node is TextLayerAnchor;
39
39
  export declare function isImageNode(node: TextLayerNode): node is TextLayerImage;
40
- /**
41
- * Get the default font family.
42
- * @param type The font type.
43
- * @returns The default font family.
44
- */
45
- export declare function getDefaultFontFamily(type: string): string;
46
40
  export declare function createTextLayer(page: PDFPageProxy, { canvasFactory, viewport, outputScale, annotations, }: {
47
41
  canvasFactory: BaseCanvasFactory;
48
42
  viewport?: PageViewport;
@@ -0,0 +1,5 @@
1
+ export declare class WasmFactory {
2
+ fetch({ filename }: {
3
+ filename: string;
4
+ }): Promise<Uint8Array>;
5
+ }
@@ -8,6 +8,14 @@ export declare function canvasToData(canvas: HTMLCanvasElement | Canvas): Promis
8
8
  /**
9
9
  * Convert a buffer to a data url.
10
10
  * @param data The buffer to convert.
11
+ * @param type The type of the data url. Defaults to 'image/png'.
11
12
  * @returns A promise that resolves to the data url.
12
13
  */
13
- export declare function toDataUrl(data: Uint8Array): Promise<string>;
14
+ export declare function toDataUrl(data: Uint8Array, type?: string): Promise<string>;
15
+ /**
16
+ * Ensure the object can be serialized and unserialized as JSON.
17
+ * Internally it converts typed arrays to plain arrays.
18
+ * @param object The object to serialize.
19
+ * @returns The serialized object.
20
+ */
21
+ export declare function makeSerializable<T>(object: T): T;
@@ -324,7 +324,14 @@ var OPS = {
324
324
  paintSolidColorImageMask: 90,
325
325
  constructPath: 91,
326
326
  setStrokeTransparent: 92,
327
- setFillTransparent: 93
327
+ setFillTransparent: 93,
328
+ rawFillPath: 94
329
+ };
330
+ var DrawOPS = {
331
+ moveTo: 0,
332
+ lineTo: 1,
333
+ curveTo: 2,
334
+ closePath: 3
328
335
  };
329
336
  var PasswordResponses = {
330
337
  NEED_PASSWORD: 1,
@@ -634,29 +641,72 @@ var Util = class {
634
641
  }
635
642
  // For 2d affine transforms
636
643
  static applyTransform(p, m) {
637
- const xt = p[0] * m[0] + p[1] * m[2] + m[4];
638
- const yt = p[0] * m[1] + p[1] * m[3] + m[5];
639
- return [xt, yt];
644
+ const p0 = p[0];
645
+ const p1 = p[1];
646
+ p[0] = p0 * m[0] + p1 * m[2] + m[4];
647
+ p[1] = p0 * m[1] + p1 * m[3] + m[5];
648
+ }
649
+ // For 2d affine transforms
650
+ static applyTransformToBezier(p, transform) {
651
+ const m0 = transform[0];
652
+ const m1 = transform[1];
653
+ const m2 = transform[2];
654
+ const m3 = transform[3];
655
+ const m4 = transform[4];
656
+ const m5 = transform[5];
657
+ for (let i = 0; i < 6; i += 2) {
658
+ const pI = p[i];
659
+ const pI1 = p[i + 1];
660
+ p[i] = pI * m0 + pI1 * m2 + m4;
661
+ p[i + 1] = pI * m1 + pI1 * m3 + m5;
662
+ }
640
663
  }
641
664
  static applyInverseTransform(p, m) {
665
+ const p0 = p[0];
666
+ const p1 = p[1];
642
667
  const d = m[0] * m[3] - m[1] * m[2];
643
- const xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
644
- const yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
645
- return [xt, yt];
668
+ p[0] = (p0 * m[3] - p1 * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
669
+ p[1] = (-p0 * m[1] + p1 * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
646
670
  }
647
671
  // Applies the transform to the rectangle and finds the minimum axially
648
672
  // aligned bounding box.
649
- static getAxialAlignedBoundingBox(r, m) {
650
- const p1 = this.applyTransform(r, m);
651
- const p2 = this.applyTransform(r.slice(2, 4), m);
652
- const p3 = this.applyTransform([r[0], r[3]], m);
653
- const p4 = this.applyTransform([r[2], r[1]], m);
654
- return [
655
- Math.min(p1[0], p2[0], p3[0], p4[0]),
656
- Math.min(p1[1], p2[1], p3[1], p4[1]),
657
- Math.max(p1[0], p2[0], p3[0], p4[0]),
658
- Math.max(p1[1], p2[1], p3[1], p4[1])
659
- ];
673
+ static axialAlignedBoundingBox(rect, transform, output) {
674
+ const m0 = transform[0];
675
+ const m1 = transform[1];
676
+ const m2 = transform[2];
677
+ const m3 = transform[3];
678
+ const m4 = transform[4];
679
+ const m5 = transform[5];
680
+ const r0 = rect[0];
681
+ const r1 = rect[1];
682
+ const r2 = rect[2];
683
+ const r3 = rect[3];
684
+ let a0 = m0 * r0 + m4;
685
+ let a2 = a0;
686
+ let a1 = m0 * r2 + m4;
687
+ let a3 = a1;
688
+ let b0 = m3 * r1 + m5;
689
+ let b2 = b0;
690
+ let b1 = m3 * r3 + m5;
691
+ let b3 = b1;
692
+ if (m1 !== 0 || m2 !== 0) {
693
+ const m1r0 = m1 * r0;
694
+ const m1r2 = m1 * r2;
695
+ const m2r1 = m2 * r1;
696
+ const m2r3 = m2 * r3;
697
+ a0 += m2r1;
698
+ a3 += m2r1;
699
+ a1 += m2r3;
700
+ a2 += m2r3;
701
+ b0 += m1r0;
702
+ b3 += m1r0;
703
+ b1 += m1r2;
704
+ b2 += m1r2;
705
+ }
706
+ output[0] = Math.min(output[0], a0, a1, a2, a3);
707
+ output[1] = Math.min(output[1], b0, b1, b2, b3);
708
+ output[2] = Math.max(output[2], a0, a1, a2, a3);
709
+ output[3] = Math.max(output[3], b0, b1, b2, b3);
660
710
  }
661
711
  static inverseTransform(m) {
662
712
  const d = m[0] * m[3] - m[1] * m[2];
@@ -672,17 +722,18 @@ var Util = class {
672
722
  // This calculation uses Singular Value Decomposition.
673
723
  // The SVD can be represented with formula A = USV. We are interested in the
674
724
  // matrix S here because it represents the scale values.
675
- static singularValueDecompose2dScale(m) {
676
- const transpose = [m[0], m[2], m[1], m[3]];
677
- const a = m[0] * transpose[0] + m[1] * transpose[2];
678
- const b = m[0] * transpose[1] + m[1] * transpose[3];
679
- const c = m[2] * transpose[0] + m[3] * transpose[2];
680
- const d = m[2] * transpose[1] + m[3] * transpose[3];
681
- const first = (a + d) / 2;
682
- const second = Math.sqrt((a + d) ** 2 - 4 * (a * d - c * b)) / 2;
683
- const sx = first + second || 1;
684
- const sy = first - second || 1;
685
- return [Math.sqrt(sx), Math.sqrt(sy)];
725
+ static singularValueDecompose2dScale(matrix, output) {
726
+ const m0 = matrix[0];
727
+ const m1 = matrix[1];
728
+ const m2 = matrix[2];
729
+ const m3 = matrix[3];
730
+ const a = m0 ** 2 + m1 ** 2;
731
+ const b = m0 * m2 + m1 * m3;
732
+ const c = m2 ** 2 + m3 ** 2;
733
+ const first = (a + c) / 2;
734
+ const second = Math.sqrt(first ** 2 - (a * c - b ** 2));
735
+ output[0] = Math.sqrt(first + second || 1);
736
+ output[1] = Math.sqrt(first - second || 1);
686
737
  }
687
738
  // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
688
739
  // For coordinate systems whose origin lies in the bottom-left, this
@@ -728,24 +779,26 @@ var Util = class {
728
779
  }
729
780
  return [xLow, yLow, xHigh, yHigh];
730
781
  }
782
+ static pointBoundingBox(x, y, minMax) {
783
+ minMax[0] = Math.min(minMax[0], x);
784
+ minMax[1] = Math.min(minMax[1], y);
785
+ minMax[2] = Math.max(minMax[2], x);
786
+ minMax[3] = Math.max(minMax[3], y);
787
+ }
788
+ static rectBoundingBox(x0, y0, x1, y1, minMax) {
789
+ minMax[0] = Math.min(minMax[0], x0, x1);
790
+ minMax[1] = Math.min(minMax[1], y0, y1);
791
+ minMax[2] = Math.max(minMax[2], x0, x1);
792
+ minMax[3] = Math.max(minMax[3], y0, y1);
793
+ }
731
794
  // From https://github.com/adobe-webplatform/Snap.svg/blob/b365287722a72526000ac4bfcf0ce4cac2faa015/src/path.js#L852
732
795
  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
- }
796
+ minMax[0] = Math.min(minMax[0], x0, x3);
797
+ minMax[1] = Math.min(minMax[1], y0, y3);
798
+ minMax[2] = Math.max(minMax[2], x0, x3);
799
+ minMax[3] = Math.max(minMax[3], y0, y3);
746
800
  __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
801
  __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
802
  }
750
803
  };
751
804
  _Util_static = new WeakSet();
@@ -1035,6 +1088,56 @@ function getUuid() {
1035
1088
  return bytesToString(buf);
1036
1089
  }
1037
1090
  var AnnotationPrefix = "pdfjs_internal_id_";
1091
+ function _isValidExplicitDest(validRef, validName, dest) {
1092
+ if (!Array.isArray(dest) || dest.length < 2) {
1093
+ return false;
1094
+ }
1095
+ const [page, zoom, ...args] = dest;
1096
+ if (!validRef(page) && !Number.isInteger(page)) {
1097
+ return false;
1098
+ }
1099
+ if (!validName(zoom)) {
1100
+ return false;
1101
+ }
1102
+ const argsLen = args.length;
1103
+ let allowNull = true;
1104
+ switch (zoom.name) {
1105
+ case "XYZ":
1106
+ if (argsLen < 2 || argsLen > 3) {
1107
+ return false;
1108
+ }
1109
+ break;
1110
+ case "Fit":
1111
+ case "FitB":
1112
+ return argsLen === 0;
1113
+ case "FitH":
1114
+ case "FitBH":
1115
+ case "FitV":
1116
+ case "FitBV":
1117
+ if (argsLen > 1) {
1118
+ return false;
1119
+ }
1120
+ break;
1121
+ case "FitR":
1122
+ if (argsLen !== 4) {
1123
+ return false;
1124
+ }
1125
+ allowNull = false;
1126
+ break;
1127
+ default:
1128
+ return false;
1129
+ }
1130
+ for (const arg of args) {
1131
+ if (typeof arg === "number" || allowNull && arg === null) {
1132
+ continue;
1133
+ }
1134
+ return false;
1135
+ }
1136
+ return true;
1137
+ }
1138
+ function MathClamp(v, min, max) {
1139
+ return Math.min(Math.max(v, min), max);
1140
+ }
1038
1141
  function toHexUtil(arr) {
1039
1142
  if (Uint8Array.prototype.toHex) {
1040
1143
  return arr.toHex();
@@ -1060,6 +1163,34 @@ if (false) {
1060
1163
  });
1061
1164
  };
1062
1165
  }
1166
+ if (typeof Math.sumPrecise !== "function") {
1167
+ Math.sumPrecise = function(numbers) {
1168
+ return numbers.reduce((a, b) => a + b, 0);
1169
+ };
1170
+ }
1171
+ if (false) {
1172
+ AbortSignal.any = function(iterable) {
1173
+ const ac = new AbortController();
1174
+ const { signal } = ac;
1175
+ for (const s of iterable) {
1176
+ if (s.aborted) {
1177
+ ac.abort(s.reason);
1178
+ return signal;
1179
+ }
1180
+ }
1181
+ for (const s of iterable) {
1182
+ s.addEventListener(
1183
+ "abort",
1184
+ () => {
1185
+ ac.abort(s.reason);
1186
+ },
1187
+ { signal }
1188
+ // Automatically remove the listener.
1189
+ );
1190
+ }
1191
+ return signal;
1192
+ };
1193
+ }
1063
1194
 
1064
1195
  // src/pdf.js/src/shared/message_handler.js
1065
1196
  var CallbackKind = {
@@ -1732,6 +1863,7 @@ export {
1732
1863
  PageActionEventType,
1733
1864
  VerbosityLevel,
1734
1865
  OPS,
1866
+ DrawOPS,
1735
1867
  PasswordResponses,
1736
1868
  setVerbosityLevel,
1737
1869
  getVerbosityLevel,
@@ -1763,6 +1895,8 @@ export {
1763
1895
  normalizeUnicode,
1764
1896
  getUuid,
1765
1897
  AnnotationPrefix,
1898
+ _isValidExplicitDest,
1899
+ MathClamp,
1766
1900
  toHexUtil,
1767
1901
  toBase64Util,
1768
1902
  fromBase64Util,