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

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 (29) hide show
  1. package/dist/browser/{chunk-DYHYQ33L.js → chunk-AK2AE3GS.js} +177 -43
  2. package/dist/browser/index.js +907 -998
  3. package/dist/browser/worker.js +5827 -5389
  4. package/dist/lib/AnnotationData.d.ts +2 -1
  5. package/dist/lib/AnnotationOperatorsList.d.ts +21 -0
  6. package/dist/lib/SvgCanvasContext.d.ts +2 -1
  7. package/dist/lib/TextLayer.d.ts +0 -6
  8. package/dist/lib/utils.d.ts +9 -1
  9. package/dist/node/{chunk-KTTVPO2G.js → chunk-WL32POZ2.js} +177 -43
  10. package/dist/node/index.js +914 -992
  11. package/dist/node/worker.js +5827 -5389
  12. package/dist/pdf.js/src/display/api.d.ts +30 -5
  13. package/dist/pdf.js/src/display/canvas.d.ts +19 -27
  14. package/dist/pdf.js/src/display/display_utils.d.ts +10 -0
  15. package/dist/pdf.js/src/display/editor/editor.d.ts +1 -1
  16. package/dist/pdf.js/src/display/editor/highlight.d.ts +1 -0
  17. package/dist/pdf.js/src/display/editor/ink.d.ts +1 -0
  18. package/dist/pdf.js/src/display/editor/signature.d.ts +1 -0
  19. package/dist/pdf.js/src/display/editor/stamp.d.ts +1 -2
  20. package/dist/pdf.js/src/display/editor/tools.d.ts +0 -6
  21. package/dist/pdf.js/src/display/pattern_helper.d.ts +4 -2
  22. package/dist/pdf.js/src/display/touch_manager.d.ts +5 -1
  23. package/dist/pdf.js/src/pdf.d.ts +3 -1
  24. package/dist/pdf.js/src/shared/util.d.ts +111 -95
  25. package/package.json +7 -5
  26. package/dist/browser/LiberationMono-Regular-UUOCTXY2.js +0 -9
  27. package/dist/browser/LiberationSerif-Regular-ASQ2LI3D.js +0 -9
  28. package/dist/node/LiberationMono-Regular-KMFXXO3B.js +0 -9
  29. package/dist/node/LiberationSerif-Regular-WAOWR76G.js +0 -9
@@ -8,13 +8,14 @@ import {
8
8
  AnnotationPrefix,
9
9
  AnnotationType,
10
10
  BaseException,
11
+ DrawOPS,
11
12
  FONT_IDENTITY_MATRIX,
12
13
  FeatureTest,
13
14
  FormatError,
14
- IDENTITY_MATRIX,
15
15
  ImageKind,
16
16
  InvalidPDFException,
17
17
  LINE_FACTOR,
18
+ MathClamp,
18
19
  MessageHandler,
19
20
  MurmurHash3_64,
20
21
  OPS,
@@ -25,6 +26,7 @@ import {
25
26
  TextRenderingMode,
26
27
  Util,
27
28
  VerbosityLevel,
29
+ _isValidExplicitDest,
28
30
  assert,
29
31
  convertBlackAndWhiteToRGBA,
30
32
  createValidAbsoluteUrl,
@@ -43,7 +45,7 @@ import {
43
45
  unreachable,
44
46
  warn,
45
47
  wrapReason
46
- } from "./chunk-DYHYQ33L.js";
48
+ } from "./chunk-AK2AE3GS.js";
47
49
  import {
48
50
  __privateAdd,
49
51
  __privateGet,
@@ -237,7 +239,9 @@ var PageViewport = class _PageViewport {
237
239
  * @see {@link convertToViewportRectangle}
238
240
  */
239
241
  convertToViewportPoint(x, y) {
240
- return Util.applyTransform([x, y], this.transform);
242
+ const p = [x, y];
243
+ Util.applyTransform(p, this.transform);
244
+ return p;
241
245
  }
242
246
  /**
243
247
  * Converts PDF rectangle to the viewport coordinates.
@@ -247,8 +251,10 @@ var PageViewport = class _PageViewport {
247
251
  * @see {@link convertToViewportPoint}
248
252
  */
249
253
  convertToViewportRectangle(rect) {
250
- const topLeft = Util.applyTransform([rect[0], rect[1]], this.transform);
251
- const bottomRight = Util.applyTransform([rect[2], rect[3]], this.transform);
254
+ const topLeft = [rect[0], rect[1]];
255
+ Util.applyTransform(topLeft, this.transform);
256
+ const bottomRight = [rect[2], rect[3]];
257
+ Util.applyTransform(bottomRight, this.transform);
252
258
  return [topLeft[0], topLeft[1], bottomRight[0], bottomRight[1]];
253
259
  }
254
260
  /**
@@ -261,7 +267,9 @@ var PageViewport = class _PageViewport {
261
267
  * @see {@link convertToViewportPoint}
262
268
  */
263
269
  convertToPdfPoint(x, y) {
264
- return Util.applyInverseTransform([x, y], this.transform);
270
+ const p = [x, y];
271
+ Util.applyInverseTransform(p, this.transform);
272
+ return p;
265
273
  }
266
274
  };
267
275
  var RenderingCancelledException = class extends BaseException {
@@ -491,9 +499,9 @@ function setLayerDimensions(div, viewport, mustFlip = false, mustRotate = true)
491
499
  div.setAttribute("data-main-rotation", viewport.rotation);
492
500
  }
493
501
  }
494
- var OutputScale = class {
502
+ var OutputScale = class _OutputScale {
495
503
  constructor() {
496
- const pixelRatio = window.devicePixelRatio || 1;
504
+ const { pixelRatio } = _OutputScale;
497
505
  this.sx = pixelRatio;
498
506
  this.sy = pixelRatio;
499
507
  }
@@ -503,9 +511,37 @@ var OutputScale = class {
503
511
  get scaled() {
504
512
  return this.sx !== 1 || this.sy !== 1;
505
513
  }
514
+ /**
515
+ * @type {boolean} Returns `true` when scaling is symmetric,
516
+ * `false` otherwise.
517
+ */
506
518
  get symmetric() {
507
519
  return this.sx === this.sy;
508
520
  }
521
+ /**
522
+ * @returns {boolean} Returns `true` if scaling was limited,
523
+ * `false` otherwise.
524
+ */
525
+ limitCanvas(width, height, maxPixels, maxDim) {
526
+ let maxAreaScale = Infinity, maxWidthScale = Infinity, maxHeightScale = Infinity;
527
+ if (maxPixels > 0) {
528
+ maxAreaScale = Math.sqrt(maxPixels / (width * height));
529
+ }
530
+ if (maxDim !== -1) {
531
+ maxWidthScale = maxDim / width;
532
+ maxHeightScale = maxDim / height;
533
+ }
534
+ const maxScale = Math.min(maxAreaScale, maxWidthScale, maxHeightScale);
535
+ if (this.sx > maxScale || this.sy > maxScale) {
536
+ this.sx = maxScale;
537
+ this.sy = maxScale;
538
+ return true;
539
+ }
540
+ return false;
541
+ }
542
+ static get pixelRatio() {
543
+ return globalThis.devicePixelRatio || 1;
544
+ }
509
545
  };
510
546
  var SupportedImageMimeTypes = [
511
547
  "image/apng",
@@ -3169,7 +3205,7 @@ setState_fn = async function() {
3169
3205
  if (!tooltip.parentNode) {
3170
3206
  button.append(tooltip);
3171
3207
  }
3172
- const element = __privateGet(this, _editor2).getImageForAltText();
3208
+ const element = __privateGet(this, _editor2).getElementForAltText();
3173
3209
  element?.setAttribute("aria-describedby", tooltip.id);
3174
3210
  };
3175
3211
  __privateAdd(_AltText, _l10nNewButton, null);
@@ -3214,12 +3250,12 @@ var _TouchManager = class _TouchManager {
3214
3250
  signal: __privateGet(this, _signal)
3215
3251
  });
3216
3252
  }
3253
+ /**
3254
+ * NOTE: Don't shadow this value since `devicePixelRatio` may change if the
3255
+ * window resolution changes, e.g. if the viewer is moved to another monitor.
3256
+ */
3217
3257
  get MIN_TOUCH_DISTANCE_TO_PINCH() {
3218
- return shadow(
3219
- this,
3220
- "MIN_TOUCH_DISTANCE_TO_PINCH",
3221
- 35 / (window.devicePixelRatio || 1)
3222
- );
3258
+ return 35 / OutputScale.pixelRatio;
3223
3259
  }
3224
3260
  destroy() {
3225
3261
  __privateGet(this, _touchManagerAC)?.abort();
@@ -3801,20 +3837,20 @@ var _AnnotationEditor = class _AnnotationEditor {
3801
3837
  if (this._mustFixPosition) {
3802
3838
  switch (rotation) {
3803
3839
  case 0:
3804
- x = Math.max(0, Math.min(pageWidth - width, x));
3805
- y = Math.max(0, Math.min(pageHeight - height, y));
3840
+ x = MathClamp(x, 0, pageWidth - width);
3841
+ y = MathClamp(y, 0, pageHeight - height);
3806
3842
  break;
3807
3843
  case 90:
3808
- x = Math.max(0, Math.min(pageWidth - height, x));
3809
- y = Math.min(pageHeight, Math.max(width, y));
3844
+ x = MathClamp(x, 0, pageWidth - height);
3845
+ y = MathClamp(y, width, pageHeight);
3810
3846
  break;
3811
3847
  case 180:
3812
- x = Math.min(pageWidth, Math.max(width, x));
3813
- y = Math.min(pageHeight, Math.max(height, y));
3848
+ x = MathClamp(x, width, pageWidth);
3849
+ y = MathClamp(y, height, pageHeight);
3814
3850
  break;
3815
3851
  case 270:
3816
- x = Math.min(pageWidth, Math.max(height, x));
3817
- y = Math.max(0, Math.min(pageHeight - width, y));
3852
+ x = MathClamp(x, height, pageWidth);
3853
+ y = MathClamp(y, 0, pageHeight - width);
3818
3854
  break;
3819
3855
  }
3820
3856
  }
@@ -3991,29 +4027,35 @@ var _AnnotationEditor = class _AnnotationEditor {
3991
4027
  * @returns {HTMLDivElement | null}
3992
4028
  */
3993
4029
  render() {
3994
- this.div = document.createElement("div");
3995
- this.div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
3996
- this.div.className = this.name;
3997
- this.div.setAttribute("id", this.id);
3998
- this.div.tabIndex = __privateGet(this, _disabled) ? -1 : 0;
4030
+ const div = this.div = document.createElement("div");
4031
+ div.setAttribute("data-editor-rotation", (360 - this.rotation) % 360);
4032
+ div.className = this.name;
4033
+ div.setAttribute("id", this.id);
4034
+ div.tabIndex = __privateGet(this, _disabled) ? -1 : 0;
4035
+ div.setAttribute("role", "application");
4036
+ if (this.defaultL10nId) {
4037
+ div.setAttribute("data-l10n-id", this.defaultL10nId);
4038
+ }
3999
4039
  if (!this._isVisible) {
4000
- this.div.classList.add("hidden");
4040
+ div.classList.add("hidden");
4001
4041
  }
4002
4042
  this.setInForeground();
4003
4043
  __privateMethod(this, _AnnotationEditor_instances, addFocusListeners_fn).call(this);
4004
4044
  const [parentWidth, parentHeight] = this.parentDimensions;
4005
4045
  if (this.parentRotation % 180 !== 0) {
4006
- this.div.style.maxWidth = `${(100 * parentHeight / parentWidth).toFixed(
4046
+ div.style.maxWidth = `${(100 * parentHeight / parentWidth).toFixed(
4047
+ 2
4048
+ )}%`;
4049
+ div.style.maxHeight = `${(100 * parentWidth / parentHeight).toFixed(
4007
4050
  2
4008
4051
  )}%`;
4009
- this.div.style.maxHeight = `${(100 * parentWidth / parentHeight).toFixed(2)}%`;
4010
4052
  }
4011
4053
  const [tx, ty] = this.getInitialTranslation();
4012
4054
  this.translate(tx, ty);
4013
- bindEvents(this, this.div, ["pointerdown"]);
4055
+ bindEvents(this, div, ["keydown", "pointerdown"]);
4014
4056
  if (this.isResizable && this._uiManager._supportsPinchToZoom) {
4015
4057
  __privateGet(this, _touchManager) || __privateSet(this, _touchManager, new TouchManager({
4016
- container: this.div,
4058
+ container: div,
4017
4059
  isPinchingDisabled: () => !this.isSelected,
4018
4060
  onPinchStart: __privateMethod(this, _AnnotationEditor_instances, touchPinchStartCallback_fn).bind(this),
4019
4061
  onPinching: __privateMethod(this, _AnnotationEditor_instances, touchPinchCallback_fn).bind(this),
@@ -4022,7 +4064,7 @@ var _AnnotationEditor = class _AnnotationEditor {
4022
4064
  }));
4023
4065
  }
4024
4066
  this._uiManager._editorUndoBar?.hide();
4025
- return this.div;
4067
+ return div;
4026
4068
  }
4027
4069
  /**
4028
4070
  * Onpointerdown callback.
@@ -4312,7 +4354,6 @@ var _AnnotationEditor = class _AnnotationEditor {
4312
4354
  if (this.isResizable) {
4313
4355
  __privateMethod(this, _AnnotationEditor_instances, createResizers_fn).call(this);
4314
4356
  __privateGet(this, _resizersDiv).classList.remove("hidden");
4315
- bindEvents(this, this.div, ["keydown"]);
4316
4357
  }
4317
4358
  }
4318
4359
  get toolbarPosition() {
@@ -4454,8 +4495,8 @@ var _AnnotationEditor = class _AnnotationEditor {
4454
4495
  /**
4455
4496
  * @returns {HTMLElement | null} the element requiring an alt text.
4456
4497
  */
4457
- getImageForAltText() {
4458
- return null;
4498
+ getElementForAltText() {
4499
+ return this.div;
4459
4500
  }
4460
4501
  /**
4461
4502
  * Get the div which really contains the displayed content.
@@ -4859,14 +4900,12 @@ resizerPointermove_fn = function(name, event) {
4859
4900
  minHeight / savedHeight
4860
4901
  );
4861
4902
  } else if (isHorizontal) {
4862
- ratioX = Math.max(
4863
- minWidth,
4864
- Math.min(1, Math.abs(oppositePoint[0] - point[0] - deltaX))
4865
- ) / savedWidth;
4903
+ ratioX = MathClamp(Math.abs(oppositePoint[0] - point[0] - deltaX), minWidth, 1) / savedWidth;
4866
4904
  } else {
4867
- ratioY = Math.max(
4905
+ ratioY = MathClamp(
4906
+ Math.abs(oppositePoint[1] - point[1] - deltaY),
4868
4907
  minHeight,
4869
- Math.min(1, Math.abs(oppositePoint[1] - point[1] - deltaY))
4908
+ 1
4870
4909
  ) / savedHeight;
4871
4910
  }
4872
4911
  const newWidth = _AnnotationEditor._round(savedWidth * ratioX);
@@ -5343,35 +5382,12 @@ async function createCanvas(width, height) {
5343
5382
  var loadingFontPromise = null;
5344
5383
  async function loadDefaultFonts() {
5345
5384
  if (loadingFontPromise === null) {
5346
- loadingFontPromise = Promise.all([
5347
- import("./LiberationMono-Regular-UUOCTXY2.js").then(
5348
- (module) => new Blob([module.default], { type: "font/ttf" })
5349
- ),
5350
- import("./LiberationSans-Regular-KIF3IRJY.js").then((module) => new Blob([module.default], { type: "font/ttf" })),
5351
- import("./LiberationSerif-Regular-ASQ2LI3D.js").then(
5352
- (module) => new Blob([module.default], { type: "font/ttf" })
5353
- )
5354
- ]).then(async ([monoBlob, sansBlob, serifBlob]) => {
5355
- const fontMono = new FontFace(
5356
- "Liberation Mono",
5357
- `url(${URL.createObjectURL(monoBlob)})`
5358
- );
5385
+ loadingFontPromise = import("./LiberationSans-Regular-KIF3IRJY.js").then((module) => new Blob([module.default], { type: "font/ttf" })).then(async (sansBlob) => {
5359
5386
  const fontSans = new FontFace(
5360
5387
  "Liberation Sans",
5361
5388
  `url(${URL.createObjectURL(sansBlob)})`
5362
5389
  );
5363
- const fontSerif = new FontFace(
5364
- "Liberation Serif",
5365
- `url(${URL.createObjectURL(serifBlob)})`
5366
- );
5367
- const fonts = await Promise.all([
5368
- fontMono.load(),
5369
- fontSans.load(),
5370
- fontSerif.load()
5371
- ]);
5372
- for (const font of fonts) {
5373
- document.fonts.add(font);
5374
- }
5390
+ document.fonts.add(await fontSans.load());
5375
5391
  });
5376
5392
  }
5377
5393
  return loadingFontPromise;
@@ -6060,6 +6076,9 @@ var BaseShadingPattern = class {
6060
6076
  unreachable("Cannot initialize BaseShadingPattern.");
6061
6077
  }
6062
6078
  }
6079
+ isModifyingCurrentTransform() {
6080
+ return false;
6081
+ }
6063
6082
  getPattern() {
6064
6083
  unreachable("Abstract method `getPattern` called.");
6065
6084
  }
@@ -6358,17 +6377,22 @@ var MeshShadingPattern = class extends BaseShadingPattern {
6358
6377
  scaleY
6359
6378
  };
6360
6379
  }
6380
+ isModifyingCurrentTransform() {
6381
+ return true;
6382
+ }
6361
6383
  getPattern(ctx, owner, inverse, pathType) {
6362
6384
  applyBoundingBox(ctx, this._bbox);
6363
- let scale;
6385
+ const scale = new Float32Array(2);
6364
6386
  if (pathType === PathType.SHADING) {
6365
- scale = Util.singularValueDecompose2dScale(getCurrentTransform(ctx));
6387
+ Util.singularValueDecompose2dScale(getCurrentTransform(ctx), scale);
6388
+ } else if (this.matrix) {
6389
+ Util.singularValueDecompose2dScale(this.matrix, scale);
6390
+ const [matrixScaleX, matrixScaleY] = scale;
6391
+ Util.singularValueDecompose2dScale(owner.baseTransform, scale);
6392
+ scale[0] *= matrixScaleX;
6393
+ scale[1] *= matrixScaleY;
6366
6394
  } else {
6367
- scale = Util.singularValueDecompose2dScale(owner.baseTransform);
6368
- if (this.matrix) {
6369
- const matrixScale = Util.singularValueDecompose2dScale(this.matrix);
6370
- scale = [scale[0] * matrixScale[0], scale[1] * matrixScale[1]];
6371
- }
6395
+ Util.singularValueDecompose2dScale(owner.baseTransform, scale);
6372
6396
  }
6373
6397
  const temporaryPatternCanvas = this._createMeshCanvas(
6374
6398
  scale,
@@ -6410,7 +6434,8 @@ var PaintType = {
6410
6434
  UNCOLORED: 2
6411
6435
  };
6412
6436
  var _TilingPattern = class _TilingPattern {
6413
- constructor(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
6437
+ constructor(IR, ctx, canvasGraphicsFactory, baseTransform) {
6438
+ this.color = IR[1];
6414
6439
  this.operatorList = IR[2];
6415
6440
  this.matrix = IR[3];
6416
6441
  this.bbox = IR[4];
@@ -6418,7 +6443,6 @@ var _TilingPattern = class _TilingPattern {
6418
6443
  this.ystep = IR[6];
6419
6444
  this.paintType = IR[7];
6420
6445
  this.tilingType = IR[8];
6421
- this.color = color;
6422
6446
  this.ctx = ctx;
6423
6447
  this.canvasGraphicsFactory = canvasGraphicsFactory;
6424
6448
  this.baseTransform = baseTransform;
@@ -6439,12 +6463,12 @@ var _TilingPattern = class _TilingPattern {
6439
6463
  const x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
6440
6464
  const width = x1 - x0;
6441
6465
  const height = y1 - y0;
6442
- const matrixScale = Util.singularValueDecompose2dScale(this.matrix);
6443
- const curMatrixScale = Util.singularValueDecompose2dScale(
6444
- this.baseTransform
6445
- );
6446
- const combinedScaleX = matrixScale[0] * curMatrixScale[0];
6447
- const combinedScaleY = matrixScale[1] * curMatrixScale[1];
6466
+ const scale = new Float32Array(2);
6467
+ Util.singularValueDecompose2dScale(this.matrix, scale);
6468
+ const [matrixScaleX, matrixScaleY] = scale;
6469
+ Util.singularValueDecompose2dScale(this.baseTransform, scale);
6470
+ const combinedScaleX = matrixScaleX * scale[0];
6471
+ const combinedScaleY = matrixScaleY * scale[1];
6448
6472
  let canvasWidth = width, canvasHeight = height, redrawHorizontally = false, redrawVertically = false;
6449
6473
  const xScaledStep = Math.ceil(xstep * combinedScaleX);
6450
6474
  const yScaledStep = Math.ceil(ystep * combinedScaleY);
@@ -6560,12 +6584,11 @@ var _TilingPattern = class _TilingPattern {
6560
6584
  const bboxWidth = x1 - x0;
6561
6585
  const bboxHeight = y1 - y0;
6562
6586
  graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
6563
- graphics.current.updateRectMinMax(getCurrentTransform(graphics.ctx), [
6564
- x0,
6565
- y0,
6566
- x1,
6567
- y1
6568
- ]);
6587
+ Util.axialAlignedBoundingBox(
6588
+ [x0, y0, x1, y1],
6589
+ getCurrentTransform(graphics.ctx),
6590
+ graphics.current.minMax
6591
+ );
6569
6592
  graphics.clip();
6570
6593
  graphics.endPath();
6571
6594
  }
@@ -6590,6 +6613,9 @@ var _TilingPattern = class _TilingPattern {
6590
6613
  throw new FormatError(`Unsupported paint type: ${paintType}`);
6591
6614
  }
6592
6615
  }
6616
+ isModifyingCurrentTransform() {
6617
+ return false;
6618
+ }
6593
6619
  getPattern(ctx, owner, inverse, pathType) {
6594
6620
  let matrix = inverse;
6595
6621
  if (pathType !== PathType.SHADING) {
@@ -6622,8 +6648,15 @@ var MIN_FONT_SIZE = 16;
6622
6648
  var MAX_FONT_SIZE = 100;
6623
6649
  var EXECUTION_TIME = 15;
6624
6650
  var EXECUTION_STEPS = 10;
6625
- var MAX_SIZE_TO_COMPILE = 1e3;
6626
6651
  var FULL_CHUNK_HEIGHT = 16;
6652
+ var SCALE_MATRIX = new DOMMatrix();
6653
+ var XY = new Float32Array(2);
6654
+ var MIN_MAX_INIT = new Float32Array([
6655
+ Infinity,
6656
+ Infinity,
6657
+ -Infinity,
6658
+ -Infinity
6659
+ ]);
6627
6660
  function mirrorContextOperations(ctx, destCtx) {
6628
6661
  if (ctx._removeMirroring) {
6629
6662
  throw new Error("Context is already forwarding operations.");
@@ -6661,39 +6694,39 @@ function mirrorContextOperations(ctx, destCtx) {
6661
6694
  ctx.beginPath = ctx.__originalBeginPath;
6662
6695
  delete ctx._removeMirroring;
6663
6696
  };
6664
- ctx.save = function ctxSave() {
6697
+ ctx.save = function() {
6665
6698
  destCtx.save();
6666
6699
  this.__originalSave();
6667
6700
  };
6668
- ctx.restore = function ctxRestore() {
6701
+ ctx.restore = function() {
6669
6702
  destCtx.restore();
6670
6703
  this.__originalRestore();
6671
6704
  };
6672
- ctx.translate = function ctxTranslate(x, y) {
6705
+ ctx.translate = function(x, y) {
6673
6706
  destCtx.translate(x, y);
6674
6707
  this.__originalTranslate(x, y);
6675
6708
  };
6676
- ctx.scale = function ctxScale(x, y) {
6709
+ ctx.scale = function(x, y) {
6677
6710
  destCtx.scale(x, y);
6678
6711
  this.__originalScale(x, y);
6679
6712
  };
6680
- ctx.transform = function ctxTransform(a, b, c, d, e, f) {
6713
+ ctx.transform = function(a, b, c, d, e, f) {
6681
6714
  destCtx.transform(a, b, c, d, e, f);
6682
6715
  this.__originalTransform(a, b, c, d, e, f);
6683
6716
  };
6684
- ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
6717
+ ctx.setTransform = function(a, b, c, d, e, f) {
6685
6718
  destCtx.setTransform(a, b, c, d, e, f);
6686
6719
  this.__originalSetTransform(a, b, c, d, e, f);
6687
6720
  };
6688
- ctx.resetTransform = function ctxResetTransform() {
6721
+ ctx.resetTransform = function() {
6689
6722
  destCtx.resetTransform();
6690
6723
  this.__originalResetTransform();
6691
6724
  };
6692
- ctx.rotate = function ctxRotate(angle) {
6725
+ ctx.rotate = function(angle) {
6693
6726
  destCtx.rotate(angle);
6694
6727
  this.__originalRotate(angle);
6695
6728
  };
6696
- ctx.clip = function ctxRotate(rule) {
6729
+ ctx.clip = function(rule) {
6697
6730
  destCtx.clip(rule);
6698
6731
  this.__originalClip(rule);
6699
6732
  };
@@ -6784,227 +6817,57 @@ function drawImageAtIntegerCoords(ctx, srcImg, srcX, srcY, srcW, srcH, destX, de
6784
6817
  const scaleY = Math.hypot(c, d);
6785
6818
  return [scaleX * destW, scaleY * destH];
6786
6819
  }
6787
- function compileType3Glyph(imgData) {
6788
- const { width, height } = imgData;
6789
- if (width > MAX_SIZE_TO_COMPILE || height > MAX_SIZE_TO_COMPILE) {
6790
- return null;
6791
- }
6792
- const POINT_TO_PROCESS_LIMIT = 1e3;
6793
- const POINT_TYPES = new Uint8Array([
6794
- 0,
6795
- 2,
6796
- 4,
6797
- 0,
6798
- 1,
6799
- 0,
6800
- 5,
6801
- 4,
6802
- 8,
6803
- 10,
6804
- 0,
6805
- 8,
6806
- 0,
6807
- 2,
6808
- 1,
6809
- 0
6810
- ]);
6811
- const width1 = width + 1;
6812
- let points = new Uint8Array(width1 * (height + 1));
6813
- let i, j, j0;
6814
- const lineSize = width + 7 & ~7;
6815
- let data = new Uint8Array(lineSize * height), pos = 0;
6816
- for (const elem of imgData.data) {
6817
- let mask = 128;
6818
- while (mask > 0) {
6819
- data[pos++] = elem & mask ? 0 : 255;
6820
- mask >>= 1;
6821
- }
6822
- }
6823
- let count = 0;
6824
- pos = 0;
6825
- if (data[pos] !== 0) {
6826
- points[0] = 1;
6827
- ++count;
6828
- }
6829
- for (j = 1; j < width; j++) {
6830
- if (data[pos] !== data[pos + 1]) {
6831
- points[j] = data[pos] ? 2 : 1;
6832
- ++count;
6833
- }
6834
- pos++;
6835
- }
6836
- if (data[pos] !== 0) {
6837
- points[j] = 2;
6838
- ++count;
6839
- }
6840
- for (i = 1; i < height; i++) {
6841
- pos = i * lineSize;
6842
- j0 = i * width1;
6843
- if (data[pos - lineSize] !== data[pos]) {
6844
- points[j0] = data[pos] ? 1 : 8;
6845
- ++count;
6846
- }
6847
- let sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
6848
- for (j = 1; j < width; j++) {
6849
- sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) + (data[pos - lineSize + 1] ? 8 : 0);
6850
- if (POINT_TYPES[sum]) {
6851
- points[j0 + j] = POINT_TYPES[sum];
6852
- ++count;
6853
- }
6854
- pos++;
6855
- }
6856
- if (data[pos - lineSize] !== data[pos]) {
6857
- points[j0 + j] = data[pos] ? 2 : 4;
6858
- ++count;
6859
- }
6860
- if (count > POINT_TO_PROCESS_LIMIT) {
6861
- return null;
6862
- }
6863
- }
6864
- pos = lineSize * (height - 1);
6865
- j0 = i * width1;
6866
- if (data[pos] !== 0) {
6867
- points[j0] = 8;
6868
- ++count;
6869
- }
6870
- for (j = 1; j < width; j++) {
6871
- if (data[pos] !== data[pos + 1]) {
6872
- points[j0 + j] = data[pos] ? 4 : 8;
6873
- ++count;
6874
- }
6875
- pos++;
6876
- }
6877
- if (data[pos] !== 0) {
6878
- points[j0 + j] = 4;
6879
- ++count;
6880
- }
6881
- if (count > POINT_TO_PROCESS_LIMIT) {
6882
- return null;
6883
- }
6884
- const steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
6885
- const path = new SvgPath2D();
6886
- for (i = 0; count && i <= height; i++) {
6887
- let p = i * width1;
6888
- const end = p + width;
6889
- while (p < end && !points[p]) {
6890
- p++;
6891
- }
6892
- if (p === end) {
6893
- continue;
6894
- }
6895
- path.moveTo(p % width1, i);
6896
- const p0 = p;
6897
- let type = points[p];
6898
- do {
6899
- const step = steps[type];
6900
- do {
6901
- p += step;
6902
- } while (!points[p]);
6903
- const pp = points[p];
6904
- if (pp !== 5 && pp !== 10) {
6905
- type = pp;
6906
- points[p] = 0;
6907
- } else {
6908
- type = pp & 51 * type >> 4;
6909
- points[p] &= type >> 2 | type << 2;
6910
- }
6911
- path.lineTo(p % width1, p / width1 | 0);
6912
- if (!points[p]) {
6913
- --count;
6914
- }
6915
- } while (p0 !== p);
6916
- --i;
6917
- }
6918
- data = null;
6919
- points = null;
6920
- const drawOutline = function(c) {
6921
- c.save();
6922
- c.scale(1 / width, -1 / height);
6923
- c.translate(0, -height);
6924
- c.fill(path);
6925
- c.beginPath();
6926
- c.restore();
6927
- };
6928
- return drawOutline;
6929
- }
6930
6820
  var CanvasExtraState = class {
6931
6821
  constructor(width, height) {
6932
- this.alphaIsShape = false;
6933
- this.fontSize = 0;
6934
- this.fontSizeScale = 1;
6935
- this.textMatrix = IDENTITY_MATRIX;
6936
- this.textMatrixScale = 1;
6937
- this.fontMatrix = FONT_IDENTITY_MATRIX;
6938
- this.leading = 0;
6939
- this.x = 0;
6940
- this.y = 0;
6941
- this.lineX = 0;
6942
- this.lineY = 0;
6943
- this.charSpacing = 0;
6944
- this.wordSpacing = 0;
6945
- this.textHScale = 1;
6946
- this.textRenderingMode = TextRenderingMode.FILL;
6947
- this.textRise = 0;
6948
- this.fillColor = "#000000";
6949
- this.strokeColor = "#000000";
6950
- this.patternFill = false;
6951
- this.patternStroke = false;
6952
- this.fillAlpha = 1;
6953
- this.strokeAlpha = 1;
6954
- this.lineWidth = 1;
6955
- this.activeSMask = null;
6956
- this.transferMaps = "none";
6957
- this.startNewPathAndClipBox([0, 0, width, height]);
6822
+ // Are soft masks and alpha values shapes or opacities?
6823
+ __publicField(this, "alphaIsShape", false);
6824
+ __publicField(this, "fontSize", 0);
6825
+ __publicField(this, "fontSizeScale", 1);
6826
+ __publicField(this, "textMatrix", null);
6827
+ __publicField(this, "textMatrixScale", 1);
6828
+ __publicField(this, "fontMatrix", FONT_IDENTITY_MATRIX);
6829
+ __publicField(this, "leading", 0);
6830
+ // Current point (in user coordinates)
6831
+ __publicField(this, "x", 0);
6832
+ __publicField(this, "y", 0);
6833
+ // Start of text line (in text coordinates)
6834
+ __publicField(this, "lineX", 0);
6835
+ __publicField(this, "lineY", 0);
6836
+ // Character and word spacing
6837
+ __publicField(this, "charSpacing", 0);
6838
+ __publicField(this, "wordSpacing", 0);
6839
+ __publicField(this, "textHScale", 1);
6840
+ __publicField(this, "textRenderingMode", TextRenderingMode.FILL);
6841
+ __publicField(this, "textRise", 0);
6842
+ // Default fore and background colors
6843
+ __publicField(this, "fillColor", "#000000");
6844
+ __publicField(this, "strokeColor", "#000000");
6845
+ __publicField(this, "patternFill", false);
6846
+ __publicField(this, "patternStroke", false);
6847
+ // Note: fill alpha applies to all non-stroking operations
6848
+ __publicField(this, "fillAlpha", 1);
6849
+ __publicField(this, "strokeAlpha", 1);
6850
+ __publicField(this, "lineWidth", 1);
6851
+ __publicField(this, "activeSMask", null);
6852
+ __publicField(this, "transferMaps", "none");
6853
+ this.clipBox = new Float32Array([0, 0, width, height]);
6854
+ this.minMax = MIN_MAX_INIT.slice();
6958
6855
  }
6959
6856
  clone() {
6960
6857
  const clone = Object.create(this);
6961
6858
  clone.clipBox = this.clipBox.slice();
6859
+ clone.minMax = this.minMax.slice();
6962
6860
  return clone;
6963
6861
  }
6964
- setCurrentPoint(x, y) {
6965
- this.x = x;
6966
- this.y = y;
6967
- }
6968
- updatePathMinMax(transform, x, y) {
6969
- [x, y] = Util.applyTransform([x, y], transform);
6970
- this.minX = Math.min(this.minX, x);
6971
- this.minY = Math.min(this.minY, y);
6972
- this.maxX = Math.max(this.maxX, x);
6973
- this.maxY = Math.max(this.maxY, y);
6974
- }
6975
- updateRectMinMax(transform, rect) {
6976
- const p1 = Util.applyTransform(rect, transform);
6977
- const p2 = Util.applyTransform(rect.slice(2), transform);
6978
- const p3 = Util.applyTransform([rect[0], rect[3]], transform);
6979
- const p4 = Util.applyTransform([rect[2], rect[1]], transform);
6980
- this.minX = Math.min(this.minX, p1[0], p2[0], p3[0], p4[0]);
6981
- this.minY = Math.min(this.minY, p1[1], p2[1], p3[1], p4[1]);
6982
- this.maxX = Math.max(this.maxX, p1[0], p2[0], p3[0], p4[0]);
6983
- this.maxY = Math.max(this.maxY, p1[1], p2[1], p3[1], p4[1]);
6984
- }
6985
- updateScalingPathMinMax(transform, minMax) {
6986
- Util.scaleMinMax(transform, minMax);
6987
- this.minX = Math.min(this.minX, minMax[0]);
6988
- this.minY = Math.min(this.minY, minMax[1]);
6989
- this.maxX = Math.max(this.maxX, minMax[2]);
6990
- this.maxY = Math.max(this.maxY, minMax[3]);
6991
- }
6992
- updateCurvePathMinMax(transform, x0, y0, x1, y1, x2, y2, x3, y3, minMax) {
6993
- const box = Util.bezierBoundingBox(x0, y0, x1, y1, x2, y2, x3, y3, minMax);
6994
- if (minMax) {
6995
- return;
6996
- }
6997
- this.updateRectMinMax(transform, box);
6998
- }
6999
6862
  getPathBoundingBox(pathType = PathType.FILL, transform = null) {
7000
- const box = [this.minX, this.minY, this.maxX, this.maxY];
6863
+ const box = this.minMax.slice();
7001
6864
  if (pathType === PathType.STROKE) {
7002
6865
  if (!transform) {
7003
6866
  unreachable("Stroke bounding box must include transform.");
7004
6867
  }
7005
- const scale = Util.singularValueDecompose2dScale(transform);
7006
- const xStrokePad = scale[0] * this.lineWidth / 2;
7007
- const yStrokePad = scale[1] * this.lineWidth / 2;
6868
+ Util.singularValueDecompose2dScale(transform, XY);
6869
+ const xStrokePad = XY[0] * this.lineWidth / 2;
6870
+ const yStrokePad = XY[1] * this.lineWidth / 2;
7008
6871
  box[0] -= xStrokePad;
7009
6872
  box[1] -= yStrokePad;
7010
6873
  box[2] += xStrokePad;
@@ -7017,14 +6880,11 @@ var CanvasExtraState = class {
7017
6880
  this.startNewPathAndClipBox(intersect || [0, 0, 0, 0]);
7018
6881
  }
7019
6882
  isEmptyClip() {
7020
- return this.minX === Infinity;
6883
+ return this.minMax[0] === Infinity;
7021
6884
  }
7022
6885
  startNewPathAndClipBox(box) {
7023
- this.clipBox = box;
7024
- this.minX = Infinity;
7025
- this.minY = Infinity;
7026
- this.maxX = 0;
7027
- this.maxY = 0;
6886
+ this.clipBox.set(box, 0);
6887
+ this.minMax.set(MIN_MAX_INIT, 0);
7028
6888
  }
7029
6889
  getClippedPathBoundingBox(pathType = PathType.FILL, transform = null) {
7030
6890
  return Util.intersect(
@@ -7188,24 +7048,20 @@ function resetCtxToDefault(ctx) {
7188
7048
  ctx.setLineDash([]);
7189
7049
  ctx.lineDashOffset = 0;
7190
7050
  }
7191
- if (!isNodeJS) {
7192
- const { filter } = ctx;
7193
- if (filter !== "none" && filter !== "") {
7194
- ctx.filter = "none";
7195
- }
7051
+ const { filter } = ctx;
7052
+ if (filter !== "none" && filter !== "") {
7053
+ ctx.filter = "none";
7196
7054
  }
7197
7055
  }
7198
7056
  function getImageSmoothingEnabled(transform, interpolate) {
7199
7057
  if (interpolate) {
7200
7058
  return true;
7201
7059
  }
7202
- const scale = Util.singularValueDecompose2dScale(transform);
7203
- scale[0] = Math.fround(scale[0]);
7204
- scale[1] = Math.fround(scale[1]);
7060
+ Util.singularValueDecompose2dScale(transform, XY);
7205
7061
  const actualScale = Math.fround(
7206
- (globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS
7062
+ OutputScale.pixelRatio * PixelsPerInch.PDF_TO_CSS_UNITS
7207
7063
  );
7208
- return scale[0] <= actualScale && scale[1] <= actualScale;
7064
+ return XY[0] <= actualScale && XY[1] <= actualScale;
7209
7065
  }
7210
7066
  var LINE_CAP_STYLES = ["butt", "round", "square"];
7211
7067
  var LINE_JOIN_STYLES = ["miter", "round", "bevel"];
@@ -7230,7 +7086,6 @@ var _CanvasGraphics = class _CanvasGraphics {
7230
7086
  this.canvasFactory = canvasFactory;
7231
7087
  this.filterFactory = filterFactory;
7232
7088
  this.groupStack = [];
7233
- this.processingType3 = null;
7234
7089
  this.baseTransform = null;
7235
7090
  this.baseTransformStack = [];
7236
7091
  this.groupLevel = 0;
@@ -7451,10 +7306,9 @@ var _CanvasGraphics = class _CanvasGraphics {
7451
7306
  0
7452
7307
  ]);
7453
7308
  maskToCanvas = Util.transform(maskToCanvas, [1, 0, 0, 1, 0, -height]);
7454
- const [minX, minY, maxX, maxY] = Util.getAxialAlignedBoundingBox(
7455
- [0, 0, width, height],
7456
- maskToCanvas
7457
- );
7309
+ const minMax = MIN_MAX_INIT.slice();
7310
+ Util.axialAlignedBoundingBox([0, 0, width, height], maskToCanvas, minMax);
7311
+ const [minX, minY, maxX, maxY] = minMax;
7458
7312
  const drawnWidth = Math.round(maxX - minX) || 1;
7459
7313
  const drawnHeight = Math.round(maxY - minY) || 1;
7460
7314
  const fillCanvas = this.cachedCanvases.getCanvas(
@@ -7573,8 +7427,7 @@ var _CanvasGraphics = class _CanvasGraphics {
7573
7427
  this.current.strokeAlpha = value;
7574
7428
  break;
7575
7429
  case "ca":
7576
- this.current.fillAlpha = value;
7577
- this.ctx.globalAlpha = value;
7430
+ this.ctx.globalAlpha = this.current.fillAlpha = value;
7578
7431
  break;
7579
7432
  case "BM":
7580
7433
  this.ctx.globalCompositeOperation = value;
@@ -7623,16 +7476,11 @@ var _CanvasGraphics = class _CanvasGraphics {
7623
7476
  drawnHeight
7624
7477
  );
7625
7478
  this.suspendedCtx = this.ctx;
7626
- this.ctx = scratchCanvas.context;
7627
- const ctx = this.ctx;
7628
- ctx.setTransform(...getCurrentTransform(this.suspendedCtx));
7479
+ const ctx = this.ctx = scratchCanvas.context;
7480
+ ctx.setTransform(this.suspendedCtx.getTransform());
7629
7481
  copyCtxState(this.suspendedCtx, ctx);
7630
7482
  mirrorContextOperations(ctx, this.suspendedCtx);
7631
- this.setGState([
7632
- ["BM", "source-over"],
7633
- ["ca", 1],
7634
- ["CA", 1]
7635
- ]);
7483
+ this.setGState([["BM", "source-over"]]);
7636
7484
  }
7637
7485
  endSMaskMode() {
7638
7486
  if (!this.inSMaskMode) {
@@ -7752,31 +7600,28 @@ var _CanvasGraphics = class _CanvasGraphics {
7752
7600
  save() {
7753
7601
  if (this.inSMaskMode) {
7754
7602
  copyCtxState(this.ctx, this.suspendedCtx);
7755
- this.suspendedCtx.save();
7756
- } else {
7757
- this.ctx.save();
7758
7603
  }
7604
+ this.ctx.save();
7759
7605
  const old = this.current;
7760
7606
  this.stateStack.push(old);
7761
7607
  this.current = old.clone();
7762
7608
  }
7763
7609
  restore() {
7764
- if (this.stateStack.length === 0 && this.inSMaskMode) {
7765
- this.endSMaskMode();
7766
- }
7767
- if (this.stateStack.length !== 0) {
7768
- this.current = this.stateStack.pop();
7610
+ if (this.stateStack.length === 0) {
7769
7611
  if (this.inSMaskMode) {
7770
- this.suspendedCtx.restore();
7771
- copyCtxState(this.suspendedCtx, this.ctx);
7772
- } else {
7773
- this.ctx.restore();
7612
+ this.endSMaskMode();
7774
7613
  }
7775
- this.checkSMaskState();
7776
- this.pendingClip = null;
7777
- this._cachedScaleForStroking[0] = -1;
7778
- this._cachedGetSinglePixelWidth = null;
7614
+ return;
7615
+ }
7616
+ this.current = this.stateStack.pop();
7617
+ this.ctx.restore();
7618
+ if (this.inSMaskMode) {
7619
+ copyCtxState(this.suspendedCtx, this.ctx);
7779
7620
  }
7621
+ this.checkSMaskState();
7622
+ this.pendingClip = null;
7623
+ this._cachedScaleForStroking[0] = -1;
7624
+ this._cachedGetSinglePixelWidth = null;
7780
7625
  }
7781
7626
  transform(a, b, c, d, e, f) {
7782
7627
  this.ctx.transform(a, b, c, d, e, f);
@@ -7784,145 +7629,60 @@ var _CanvasGraphics = class _CanvasGraphics {
7784
7629
  this._cachedGetSinglePixelWidth = null;
7785
7630
  }
7786
7631
  // Path
7787
- constructPath(ops, args, minMax) {
7788
- const ctx = this.ctx;
7789
- const current = this.current;
7790
- let x = current.x, y = current.y;
7791
- let startX, startY;
7792
- const currentTransform = getCurrentTransform(ctx);
7793
- const isScalingMatrix = currentTransform[0] === 0 && currentTransform[3] === 0 || currentTransform[1] === 0 && currentTransform[2] === 0;
7794
- const minMaxForBezier = isScalingMatrix ? minMax.slice(0) : null;
7795
- for (let i = 0, j = 0, ii = ops.length; i < ii; i++) {
7796
- switch (ops[i] | 0) {
7797
- case OPS.rectangle:
7798
- x = args[j++];
7799
- y = args[j++];
7800
- const width = args[j++];
7801
- const height = args[j++];
7802
- const xw = x + width;
7803
- const yh = y + height;
7804
- ctx.moveTo(x, y);
7805
- if (width === 0 || height === 0) {
7806
- ctx.lineTo(xw, yh);
7807
- } else {
7808
- ctx.lineTo(xw, y);
7809
- ctx.lineTo(xw, yh);
7810
- ctx.lineTo(x, yh);
7811
- }
7812
- if (!isScalingMatrix) {
7813
- current.updateRectMinMax(currentTransform, [x, y, xw, yh]);
7814
- }
7815
- ctx.closePath();
7816
- break;
7817
- case OPS.moveTo:
7818
- x = args[j++];
7819
- y = args[j++];
7820
- ctx.moveTo(x, y);
7821
- if (!isScalingMatrix) {
7822
- current.updatePathMinMax(currentTransform, x, y);
7823
- }
7824
- break;
7825
- case OPS.lineTo:
7826
- x = args[j++];
7827
- y = args[j++];
7828
- ctx.lineTo(x, y);
7829
- if (!isScalingMatrix) {
7830
- current.updatePathMinMax(currentTransform, x, y);
7831
- }
7832
- break;
7833
- case OPS.curveTo:
7834
- startX = x;
7835
- startY = y;
7836
- x = args[j + 4];
7837
- y = args[j + 5];
7838
- ctx.bezierCurveTo(
7839
- args[j],
7840
- args[j + 1],
7841
- args[j + 2],
7842
- args[j + 3],
7843
- x,
7844
- y
7845
- );
7846
- current.updateCurvePathMinMax(
7847
- currentTransform,
7848
- startX,
7849
- startY,
7850
- args[j],
7851
- args[j + 1],
7852
- args[j + 2],
7853
- args[j + 3],
7854
- x,
7855
- y,
7856
- minMaxForBezier
7857
- );
7858
- j += 6;
7859
- break;
7860
- case OPS.curveTo2:
7861
- startX = x;
7862
- startY = y;
7863
- ctx.bezierCurveTo(
7864
- x,
7865
- y,
7866
- args[j],
7867
- args[j + 1],
7868
- args[j + 2],
7869
- args[j + 3]
7870
- );
7871
- current.updateCurvePathMinMax(
7872
- currentTransform,
7873
- startX,
7874
- startY,
7875
- x,
7876
- y,
7877
- args[j],
7878
- args[j + 1],
7879
- args[j + 2],
7880
- args[j + 3],
7881
- minMaxForBezier
7882
- );
7883
- x = args[j + 2];
7884
- y = args[j + 3];
7885
- j += 4;
7886
- break;
7887
- case OPS.curveTo3:
7888
- startX = x;
7889
- startY = y;
7890
- x = args[j + 2];
7891
- y = args[j + 3];
7892
- ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
7893
- current.updateCurvePathMinMax(
7894
- currentTransform,
7895
- startX,
7896
- startY,
7897
- args[j],
7898
- args[j + 1],
7899
- x,
7900
- y,
7901
- x,
7902
- y,
7903
- minMaxForBezier
7904
- );
7905
- j += 4;
7906
- break;
7907
- case OPS.closePath:
7908
- ctx.closePath();
7909
- break;
7910
- }
7632
+ constructPath(op, data, minMax) {
7633
+ let [path] = data;
7634
+ if (!minMax) {
7635
+ path || (path = data[0] = new SvgPath2D());
7636
+ this[op](path);
7637
+ return;
7911
7638
  }
7912
- if (isScalingMatrix) {
7913
- current.updateScalingPathMinMax(currentTransform, minMaxForBezier);
7639
+ if (!(path instanceof SvgPath2D)) {
7640
+ const path2d = data[0] = new SvgPath2D();
7641
+ for (let i = 0, ii = path.length; i < ii; ) {
7642
+ switch (path[i++]) {
7643
+ case DrawOPS.moveTo:
7644
+ path2d.moveTo(path[i++], path[i++]);
7645
+ break;
7646
+ case DrawOPS.lineTo:
7647
+ path2d.lineTo(path[i++], path[i++]);
7648
+ break;
7649
+ case DrawOPS.curveTo:
7650
+ path2d.bezierCurveTo(
7651
+ path[i++],
7652
+ path[i++],
7653
+ path[i++],
7654
+ path[i++],
7655
+ path[i++],
7656
+ path[i++]
7657
+ );
7658
+ break;
7659
+ case DrawOPS.closePath:
7660
+ path2d.closePath();
7661
+ break;
7662
+ default:
7663
+ warn(`Unrecognized drawing path operator: ${path[i - 1]}`);
7664
+ break;
7665
+ }
7666
+ }
7667
+ path = path2d;
7914
7668
  }
7915
- current.setCurrentPoint(x, y);
7669
+ Util.axialAlignedBoundingBox(
7670
+ minMax,
7671
+ getCurrentTransform(this.ctx),
7672
+ this.current.minMax
7673
+ );
7674
+ this[op](path);
7916
7675
  }
7917
7676
  closePath() {
7918
7677
  this.ctx.closePath();
7919
7678
  }
7920
- stroke(consumePath = true) {
7679
+ stroke(path, consumePath = true) {
7921
7680
  const ctx = this.ctx;
7922
7681
  const strokeColor = this.current.strokeColor;
7923
7682
  ctx.globalAlpha = this.current.strokeAlpha;
7924
7683
  if (this.contentVisible) {
7925
7684
  if (typeof strokeColor === "object" && strokeColor?.getPattern) {
7685
+ const baseTransform = strokeColor.isModifyingCurrentTransform() ? ctx.getTransform() : null;
7926
7686
  ctx.save();
7927
7687
  ctx.strokeStyle = strokeColor.getPattern(
7928
7688
  ctx,
@@ -7930,33 +7690,49 @@ var _CanvasGraphics = class _CanvasGraphics {
7930
7690
  getCurrentTransformInverse(ctx),
7931
7691
  PathType.STROKE
7932
7692
  );
7693
+ if (baseTransform) {
7694
+ const newPath = new SvgPath2D();
7695
+ newPath.addPath(
7696
+ path,
7697
+ ctx.getTransform().invertSelf().multiplySelf(baseTransform)
7698
+ );
7699
+ path = newPath;
7700
+ }
7933
7701
  this.rescaleAndStroke(
7702
+ path,
7934
7703
  /* saveRestore */
7935
7704
  false
7936
7705
  );
7937
7706
  ctx.restore();
7938
7707
  } else {
7939
7708
  this.rescaleAndStroke(
7709
+ path,
7940
7710
  /* saveRestore */
7941
7711
  true
7942
7712
  );
7943
7713
  }
7944
7714
  }
7945
7715
  if (consumePath) {
7946
- this.consumePath(this.current.getClippedPathBoundingBox());
7716
+ this.consumePath(
7717
+ path,
7718
+ this.current.getClippedPathBoundingBox(
7719
+ PathType.STROKE,
7720
+ getCurrentTransform(this.ctx)
7721
+ )
7722
+ );
7947
7723
  }
7948
7724
  ctx.globalAlpha = this.current.fillAlpha;
7949
7725
  }
7950
- closeStroke() {
7951
- this.closePath();
7952
- this.stroke();
7726
+ closeStroke(path) {
7727
+ this.stroke(path);
7953
7728
  }
7954
- fill(consumePath = true) {
7729
+ fill(path, consumePath = true) {
7955
7730
  const ctx = this.ctx;
7956
7731
  const fillColor = this.current.fillColor;
7957
7732
  const isPatternFill = this.current.patternFill;
7958
7733
  let needRestore = false;
7959
7734
  if (isPatternFill) {
7735
+ const baseTransform = fillColor.isModifyingCurrentTransform() ? ctx.getTransform() : null;
7960
7736
  ctx.save();
7961
7737
  ctx.fillStyle = fillColor.getPattern(
7962
7738
  ctx,
@@ -7964,48 +7740,57 @@ var _CanvasGraphics = class _CanvasGraphics {
7964
7740
  getCurrentTransformInverse(ctx),
7965
7741
  PathType.FILL
7966
7742
  );
7743
+ if (baseTransform) {
7744
+ const newPath = new SvgPath2D();
7745
+ newPath.addPath(
7746
+ path,
7747
+ ctx.getTransform().invertSelf().multiplySelf(baseTransform)
7748
+ );
7749
+ path = newPath;
7750
+ }
7967
7751
  needRestore = true;
7968
7752
  }
7969
7753
  const intersect = this.current.getClippedPathBoundingBox();
7970
7754
  if (this.contentVisible && intersect !== null) {
7971
7755
  if (this.pendingEOFill) {
7972
- ctx.fill("evenodd");
7756
+ ctx.fill(path, "evenodd");
7973
7757
  this.pendingEOFill = false;
7974
7758
  } else {
7975
- ctx.fill();
7759
+ ctx.fill(path);
7976
7760
  }
7977
7761
  }
7978
7762
  if (needRestore) {
7979
7763
  ctx.restore();
7980
7764
  }
7981
7765
  if (consumePath) {
7982
- this.consumePath(intersect);
7766
+ this.consumePath(path, intersect);
7983
7767
  }
7984
7768
  }
7985
- eoFill() {
7769
+ eoFill(path) {
7986
7770
  this.pendingEOFill = true;
7987
- this.fill();
7771
+ this.fill(path);
7988
7772
  }
7989
- fillStroke() {
7990
- this.fill(false);
7991
- this.stroke(false);
7992
- this.consumePath();
7773
+ fillStroke(path) {
7774
+ this.fill(path, false);
7775
+ this.stroke(path, false);
7776
+ this.consumePath(path);
7993
7777
  }
7994
- eoFillStroke() {
7778
+ eoFillStroke(path) {
7995
7779
  this.pendingEOFill = true;
7996
- this.fillStroke();
7780
+ this.fillStroke(path);
7997
7781
  }
7998
- closeFillStroke() {
7999
- this.closePath();
8000
- this.fillStroke();
7782
+ closeFillStroke(path) {
7783
+ this.fillStroke(path);
8001
7784
  }
8002
- closeEOFillStroke() {
7785
+ closeEOFillStroke(path) {
8003
7786
  this.pendingEOFill = true;
8004
- this.closePath();
8005
- this.fillStroke();
7787
+ this.fillStroke(path);
8006
7788
  }
8007
- endPath() {
8008
- this.consumePath();
7789
+ endPath(path) {
7790
+ this.consumePath(path);
7791
+ }
7792
+ rawFillPath(path) {
7793
+ this.ctx.fill(path);
8009
7794
  }
8010
7795
  // Clipping
8011
7796
  clip() {
@@ -8016,7 +7801,7 @@ var _CanvasGraphics = class _CanvasGraphics {
8016
7801
  }
8017
7802
  // Text
8018
7803
  beginText() {
8019
- this.current.textMatrix = IDENTITY_MATRIX;
7804
+ this.current.textMatrix = null;
8020
7805
  this.current.textMatrixScale = 1;
8021
7806
  this.current.x = this.current.lineX = 0;
8022
7807
  this.current.y = this.current.lineY = 0;
@@ -8025,7 +7810,6 @@ var _CanvasGraphics = class _CanvasGraphics {
8025
7810
  const paths = this.pendingTextPaths;
8026
7811
  const ctx = this.ctx;
8027
7812
  if (paths === void 0) {
8028
- ctx.beginPath();
8029
7813
  return;
8030
7814
  }
8031
7815
  const newPath = new SvgPath2D();
@@ -8037,7 +7821,6 @@ var _CanvasGraphics = class _CanvasGraphics {
8037
7821
  );
8038
7822
  }
8039
7823
  ctx.clip(newPath);
8040
- ctx.beginPath();
8041
7824
  delete this.pendingTextPaths;
8042
7825
  }
8043
7826
  setCharSpacing(spacing) {
@@ -8105,11 +7888,12 @@ var _CanvasGraphics = class _CanvasGraphics {
8105
7888
  this.setLeading(-y);
8106
7889
  this.moveText(x, y);
8107
7890
  }
8108
- setTextMatrix(a, b, c, d, e, f) {
8109
- this.current.textMatrix = [a, b, c, d, e, f];
8110
- this.current.textMatrixScale = Math.hypot(a, b);
8111
- this.current.x = this.current.lineX = 0;
8112
- this.current.y = this.current.lineY = 0;
7891
+ setTextMatrix(matrix) {
7892
+ const { current } = this;
7893
+ current.textMatrix = matrix;
7894
+ current.textMatrixScale = Math.hypot(matrix[0], matrix[1]);
7895
+ current.x = current.lineX = 0;
7896
+ current.y = current.lineY = 0;
8113
7897
  }
8114
7898
  nextLine() {
8115
7899
  this.moveText(0, this.current.leading);
@@ -8156,8 +7940,8 @@ var _CanvasGraphics = class _CanvasGraphics {
8156
7940
  [a, b, c, d, 0, 0],
8157
7941
  invPatternTransform
8158
7942
  );
8159
- const [sx, sy] = Util.singularValueDecompose2dScale(transf);
8160
- ctx.lineWidth *= Math.max(sx, sy) / fontSize;
7943
+ Util.singularValueDecompose2dScale(transf, XY);
7944
+ ctx.lineWidth *= Math.max(XY[0], XY[1]) / fontSize;
8161
7945
  ctx.stroke(
8162
7946
  __privateMethod(this, _CanvasGraphics_instances, getScaledPath_fn).call(this, path, currentTransform, patternStrokeTransform)
8163
7947
  );
@@ -8227,7 +8011,9 @@ var _CanvasGraphics = class _CanvasGraphics {
8227
8011
  const widthAdvanceScale = fontSize * current.fontMatrix[0];
8228
8012
  const simpleFillText = current.textRenderingMode === TextRenderingMode.FILL && !font.disableFontFace && !current.patternFill;
8229
8013
  ctx.save();
8230
- ctx.transform(...current.textMatrix);
8014
+ if (current.textMatrix) {
8015
+ ctx.transform(...current.textMatrix);
8016
+ }
8231
8017
  ctx.translate(current.x, current.y + current.textRise);
8232
8018
  if (fontDirection > 0) {
8233
8019
  ctx.scale(textHScale, -1);
@@ -8382,7 +8168,9 @@ var _CanvasGraphics = class _CanvasGraphics {
8382
8168
  this._cachedScaleForStroking[0] = -1;
8383
8169
  this._cachedGetSinglePixelWidth = null;
8384
8170
  ctx.save();
8385
- ctx.transform(...current.textMatrix);
8171
+ if (current.textMatrix) {
8172
+ ctx.transform(...current.textMatrix);
8173
+ }
8386
8174
  ctx.translate(current.x, current.y + current.textRise);
8387
8175
  ctx.scale(textHScale, fontDirection);
8388
8176
  for (i = 0; i < glyphsLength; ++i) {
@@ -8397,37 +8185,34 @@ var _CanvasGraphics = class _CanvasGraphics {
8397
8185
  const operatorList = font.charProcOperatorList[glyph.operatorListId];
8398
8186
  if (!operatorList) {
8399
8187
  warn(`Type3 character "${glyph.operatorListId}" is not available.`);
8400
- continue;
8401
- }
8402
- if (this.contentVisible) {
8403
- this.processingType3 = glyph;
8188
+ } else if (this.contentVisible) {
8404
8189
  this.save();
8405
8190
  ctx.scale(fontSize, fontSize);
8406
8191
  ctx.transform(...fontMatrix);
8407
8192
  this.executeOperatorList(operatorList);
8408
8193
  this.restore();
8409
8194
  }
8410
- const transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
8411
- width = transformed[0] * fontSize + spacing;
8195
+ const p = [glyph.width, 0];
8196
+ Util.applyTransform(p, fontMatrix);
8197
+ width = p[0] * fontSize + spacing;
8412
8198
  ctx.translate(width, 0);
8413
8199
  current.x += width * textHScale;
8414
8200
  }
8415
8201
  ctx.restore();
8416
- this.processingType3 = null;
8417
8202
  }
8418
8203
  // Type3 fonts
8419
8204
  setCharWidth(xWidth, yWidth) {
8420
8205
  }
8421
8206
  setCharWidthAndBounds(xWidth, yWidth, llx, lly, urx, ury) {
8422
- this.ctx.rect(llx, lly, urx - llx, ury - lly);
8423
- this.ctx.clip();
8207
+ const clip = new SvgPath2D();
8208
+ clip.rect(llx, lly, urx - llx, ury - lly);
8209
+ this.ctx.clip(clip);
8424
8210
  this.endPath();
8425
8211
  }
8426
8212
  // Color
8427
8213
  getColorN_Pattern(IR) {
8428
8214
  let pattern;
8429
8215
  if (IR[0] === "TilingPattern") {
8430
- const color = IR[1];
8431
8216
  const baseTransform = this.baseTransform || getCurrentTransform(this.ctx);
8432
8217
  const canvasGraphicsFactory = {
8433
8218
  createCanvasGraphics: (ctx) => new _CanvasGraphics(
@@ -8444,7 +8229,6 @@ var _CanvasGraphics = class _CanvasGraphics {
8444
8229
  };
8445
8230
  pattern = new TilingPattern(
8446
8231
  IR,
8447
- color,
8448
8232
  this.ctx,
8449
8233
  canvasGraphicsFactory,
8450
8234
  baseTransform
@@ -8511,10 +8295,9 @@ var _CanvasGraphics = class _CanvasGraphics {
8511
8295
  const inv = getCurrentTransformInverse(ctx);
8512
8296
  if (inv) {
8513
8297
  const { width, height } = ctx.canvas;
8514
- const [x0, y0, x1, y1] = Util.getAxialAlignedBoundingBox(
8515
- [0, 0, width, height],
8516
- inv
8517
- );
8298
+ const minMax = MIN_MAX_INIT.slice();
8299
+ Util.axialAlignedBoundingBox([0, 0, width, height], inv, minMax);
8300
+ const [x0, y0, x1, y1] = minMax;
8518
8301
  this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
8519
8302
  } else {
8520
8303
  this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
@@ -8540,11 +8323,15 @@ var _CanvasGraphics = class _CanvasGraphics {
8540
8323
  }
8541
8324
  this.baseTransform = getCurrentTransform(this.ctx);
8542
8325
  if (bbox) {
8543
- const width = bbox[2] - bbox[0];
8544
- const height = bbox[3] - bbox[1];
8545
- this.ctx.rect(bbox[0], bbox[1], width, height);
8546
- this.current.updateRectMinMax(getCurrentTransform(this.ctx), bbox);
8547
- this.clip();
8326
+ Util.axialAlignedBoundingBox(
8327
+ bbox,
8328
+ this.baseTransform,
8329
+ this.current.minMax
8330
+ );
8331
+ const [x0, y0, x1, y1] = bbox;
8332
+ const clip = new SvgPath2D();
8333
+ clip.rect(x0, y0, x1 - x0, y1 - y0);
8334
+ this.ctx.clip(clip);
8548
8335
  this.endPath();
8549
8336
  }
8550
8337
  }
@@ -8578,9 +8365,11 @@ var _CanvasGraphics = class _CanvasGraphics {
8578
8365
  if (!group.bbox) {
8579
8366
  throw new Error("Bounding box is required.");
8580
8367
  }
8581
- let bounds = Util.getAxialAlignedBoundingBox(
8368
+ let bounds = MIN_MAX_INIT.slice();
8369
+ Util.axialAlignedBoundingBox(
8582
8370
  group.bbox,
8583
- getCurrentTransform(currentCtx)
8371
+ getCurrentTransform(currentCtx),
8372
+ bounds
8584
8373
  );
8585
8374
  const canvasBounds = [
8586
8375
  0,
@@ -8606,6 +8395,15 @@ var _CanvasGraphics = class _CanvasGraphics {
8606
8395
  const groupCtx = scratchCanvas.context;
8607
8396
  groupCtx.translate(-offsetX, -offsetY);
8608
8397
  groupCtx.transform(...currentTransform);
8398
+ let clip = new SvgPath2D();
8399
+ const [x0, y0, x1, y1] = group.bbox;
8400
+ clip.rect(x0, y0, x1 - x0, y1 - y0);
8401
+ if (group.matrix) {
8402
+ const path = new SvgPath2D();
8403
+ path.addPath(clip, new DOMMatrix(group.matrix));
8404
+ clip = path;
8405
+ }
8406
+ groupCtx.clip(clip);
8609
8407
  if (group.smask) {
8610
8408
  this.smaskStack.push({
8611
8409
  canvas: scratchCanvas.canvas,
@@ -8651,9 +8449,11 @@ var _CanvasGraphics = class _CanvasGraphics {
8651
8449
  this.restore();
8652
8450
  this.ctx.save();
8653
8451
  this.ctx.setTransform(...currentMtx);
8654
- const dirtyBox = Util.getAxialAlignedBoundingBox(
8452
+ const dirtyBox = MIN_MAX_INIT.slice();
8453
+ Util.axialAlignedBoundingBox(
8655
8454
  [0, 0, groupCtx.canvas.width, groupCtx.canvas.height],
8656
- currentMtx
8455
+ currentMtx,
8456
+ dirtyBox
8657
8457
  );
8658
8458
  this.ctx.drawImage(groupCtx.canvas, 0, 0);
8659
8459
  this.ctx.restore();
@@ -8679,9 +8479,7 @@ var _CanvasGraphics = class _CanvasGraphics {
8679
8479
  rect[0] = rect[1] = 0;
8680
8480
  rect[2] = width;
8681
8481
  rect[3] = height;
8682
- const [scaleX, scaleY] = Util.singularValueDecompose2dScale(
8683
- getCurrentTransform(this.ctx)
8684
- );
8482
+ Util.singularValueDecompose2dScale(getCurrentTransform(this.ctx), XY);
8685
8483
  const { viewportScale } = this;
8686
8484
  const canvasWidth = Math.ceil(
8687
8485
  width * this.outputScaleX * viewportScale
@@ -8698,14 +8496,14 @@ var _CanvasGraphics = class _CanvasGraphics {
8698
8496
  this.annotationCanvas.savedCtx = this.ctx;
8699
8497
  this.ctx = context;
8700
8498
  this.ctx.save();
8701
- this.ctx.setTransform(scaleX, 0, 0, -scaleY, 0, height * scaleY);
8499
+ this.ctx.setTransform(XY[0], 0, 0, -XY[1], 0, height * XY[1]);
8702
8500
  resetCtxToDefault(this.ctx);
8703
8501
  } else {
8704
8502
  resetCtxToDefault(this.ctx);
8705
8503
  this.endPath();
8706
- this.ctx.rect(rect[0], rect[1], width, height);
8707
- this.ctx.clip();
8708
- this.ctx.beginPath();
8504
+ const clip = new SvgPath2D();
8505
+ clip.rect(rect[0], rect[1], width, height);
8506
+ this.ctx.clip(clip);
8709
8507
  }
8710
8508
  }
8711
8509
  this.current = new CanvasExtraState(
@@ -8732,16 +8530,6 @@ var _CanvasGraphics = class _CanvasGraphics {
8732
8530
  img = this.getObject(img.data, img);
8733
8531
  img.count = count;
8734
8532
  const ctx = this.ctx;
8735
- const glyph = this.processingType3;
8736
- if (glyph) {
8737
- if (glyph.compiled === void 0) {
8738
- glyph.compiled = compileType3Glyph(img);
8739
- }
8740
- if (glyph.compiled) {
8741
- glyph.compiled(ctx);
8742
- return;
8743
- }
8744
- }
8745
8533
  const mask = this._createMaskCanvas(img);
8746
8534
  const maskCanvas = mask.canvas;
8747
8535
  ctx.save();
@@ -8777,8 +8565,7 @@ var _CanvasGraphics = class _CanvasGraphics {
8777
8565
  positions[i],
8778
8566
  positions[i + 1]
8779
8567
  ]);
8780
- const [x, y] = Util.applyTransform([0, 0], trans);
8781
- ctx.drawImage(mask.canvas, x, y);
8568
+ ctx.drawImage(mask.canvas, trans[4], trans[5]);
8782
8569
  }
8783
8570
  ctx.restore();
8784
8571
  this.compose();
@@ -8895,11 +8682,9 @@ var _CanvasGraphics = class _CanvasGraphics {
8895
8682
  const height = imgData.height;
8896
8683
  const ctx = this.ctx;
8897
8684
  this.save();
8898
- if (!isNodeJS) {
8899
- const { filter } = ctx;
8900
- if (filter !== "none" && filter !== "") {
8901
- ctx.filter = "none";
8902
- }
8685
+ const { filter } = ctx;
8686
+ if (filter !== "none" && filter !== "") {
8687
+ ctx.filter = "none";
8903
8688
  }
8904
8689
  ctx.scale(1 / width, -1 / height);
8905
8690
  let imgToPaint;
@@ -9015,7 +8800,7 @@ var _CanvasGraphics = class _CanvasGraphics {
9015
8800
  endCompat() {
9016
8801
  }
9017
8802
  // Helper functions
9018
- consumePath(clipBox) {
8803
+ consumePath(path, clipBox) {
9019
8804
  const isEmpty = this.current.isEmptyClip();
9020
8805
  if (this.pendingClip) {
9021
8806
  this.current.updateClipFromPath();
@@ -9027,15 +8812,14 @@ var _CanvasGraphics = class _CanvasGraphics {
9027
8812
  if (this.pendingClip) {
9028
8813
  if (!isEmpty) {
9029
8814
  if (this.pendingClip === EO_CLIP) {
9030
- ctx.clip("evenodd");
8815
+ ctx.clip(path, "evenodd");
9031
8816
  } else {
9032
- ctx.clip();
8817
+ ctx.clip(path);
9033
8818
  }
9034
8819
  }
9035
8820
  this.pendingClip = null;
9036
8821
  }
9037
8822
  this.current.startNewPathAndClipBox(this.current.clipBox);
9038
- ctx.beginPath();
9039
8823
  }
9040
8824
  getSinglePixelWidth() {
9041
8825
  if (!this._cachedGetSinglePixelWidth) {
@@ -9095,13 +8879,15 @@ var _CanvasGraphics = class _CanvasGraphics {
9095
8879
  }
9096
8880
  // Rescale before stroking in order to have a final lineWidth
9097
8881
  // with both thicknesses greater or equal to 1.
9098
- rescaleAndStroke(saveRestore) {
9099
- const { ctx } = this;
9100
- const { lineWidth } = this.current;
8882
+ rescaleAndStroke(path, saveRestore) {
8883
+ const {
8884
+ ctx,
8885
+ current: { lineWidth }
8886
+ } = this;
9101
8887
  const [scaleX, scaleY] = this.getScaleForStroking();
9102
- ctx.lineWidth = lineWidth || 1;
9103
- if (scaleX === 1 && scaleY === 1) {
9104
- ctx.stroke();
8888
+ if (scaleX === scaleY) {
8889
+ ctx.lineWidth = (lineWidth || 1) * scaleX;
8890
+ ctx.stroke(path);
9105
8891
  return;
9106
8892
  }
9107
8893
  const dashes = ctx.getLineDash();
@@ -9109,12 +8895,17 @@ var _CanvasGraphics = class _CanvasGraphics {
9109
8895
  ctx.save();
9110
8896
  }
9111
8897
  ctx.scale(scaleX, scaleY);
8898
+ SCALE_MATRIX.a = 1 / scaleX;
8899
+ SCALE_MATRIX.d = 1 / scaleY;
8900
+ const newPath = new SvgPath2D();
8901
+ newPath.addPath(path, SCALE_MATRIX);
9112
8902
  if (dashes.length > 0) {
9113
8903
  const scale = Math.max(scaleX, scaleY);
9114
8904
  ctx.setLineDash(dashes.map((x) => x / scale));
9115
8905
  ctx.lineDashOffset /= scale;
9116
8906
  }
9117
- ctx.stroke();
8907
+ ctx.lineWidth = lineWidth || 1;
8908
+ ctx.stroke(newPath);
9118
8909
  if (saveRestore) {
9119
8910
  ctx.restore();
9120
8911
  }
@@ -11165,7 +10956,7 @@ var _TextLayer = class _TextLayer {
11165
10956
  throw new Error('No "textContentSource" parameter specified.');
11166
10957
  }
11167
10958
  __privateSet(this, _container3, __privateSet(this, _rootContainer, container));
11168
- __privateSet(this, _scale, viewport.scale * (globalThis.devicePixelRatio || 1));
10959
+ __privateSet(this, _scale, viewport.scale * OutputScale.pixelRatio);
11169
10960
  __privateSet(this, _rotation, viewport.rotation);
11170
10961
  __privateSet(this, _layoutTextParams, {
11171
10962
  div: null,
@@ -11243,7 +11034,7 @@ var _TextLayer = class _TextLayer {
11243
11034
  */
11244
11035
  update({ viewport, onBefore = null }) {
11245
11036
  var _a2;
11246
- const scale = viewport.scale * (globalThis.devicePixelRatio || 1);
11037
+ const scale = viewport.scale * OutputScale.pixelRatio;
11247
11038
  const rotation = viewport.rotation;
11248
11039
  if (rotation !== __privateGet(this, _rotation)) {
11249
11040
  onBefore?.();
@@ -11623,6 +11414,7 @@ function getDocument(src = {}) {
11623
11414
  const cMapUrl = getFactoryUrlProp(src.cMapUrl);
11624
11415
  const cMapPacked = src.cMapPacked !== false;
11625
11416
  const CMapReaderFactory = src.CMapReaderFactory || (isNodeJS ? NodeCMapReaderFactory : DOMCMapReaderFactory);
11417
+ const iccUrl = getFactoryUrlProp(src.iccUrl);
11626
11418
  const standardFontDataUrl = getFactoryUrlProp(src.standardFontDataUrl);
11627
11419
  const StandardFontDataFactory2 = src.StandardFontDataFactory || (isNodeJS ? NodeStandardFontDataFactory : DOMStandardFontDataFactory);
11628
11420
  const wasmUrl = getFactoryUrlProp(src.wasmUrl);
@@ -11694,6 +11486,7 @@ function getDocument(src = {}) {
11694
11486
  useWasm,
11695
11487
  useWorkerFetch,
11696
11488
  cMapUrl,
11489
+ iccUrl,
11697
11490
  standardFontDataUrl,
11698
11491
  wasmUrl
11699
11492
  }
@@ -11827,19 +11620,54 @@ function getFactoryUrlProp(val) {
11827
11620
  }
11828
11621
  throw new Error(`Invalid factory url: "${val}" must include trailing slash.`);
11829
11622
  }
11830
- function isRefProxy(ref) {
11831
- return typeof ref === "object" && Number.isInteger(ref?.num) && ref.num >= 0 && Number.isInteger(ref?.gen) && ref.gen >= 0;
11832
- }
11623
+ var isRefProxy = (v) => typeof v === "object" && Number.isInteger(v?.num) && v.num >= 0 && Number.isInteger(v?.gen) && v.gen >= 0;
11624
+ var isNameProxy = (v) => typeof v === "object" && typeof v?.name === "string";
11625
+ var isValidExplicitDest = _isValidExplicitDest.bind(
11626
+ null,
11627
+ /* validRef = */
11628
+ isRefProxy,
11629
+ /* validName = */
11630
+ isNameProxy
11631
+ );
11833
11632
  var _docId2;
11834
11633
  var _PDFDocumentLoadingTask = class _PDFDocumentLoadingTask {
11835
11634
  constructor() {
11836
- this._capability = Promise.withResolvers();
11837
- this._transport = null;
11838
- this._worker = null;
11839
- this.docId = `d${__privateWrapper(_PDFDocumentLoadingTask, _docId2)._++}`;
11840
- this.destroyed = false;
11841
- this.onPassword = null;
11842
- this.onProgress = null;
11635
+ /**
11636
+ * @private
11637
+ */
11638
+ __publicField(this, "_capability", Promise.withResolvers());
11639
+ /**
11640
+ * @private
11641
+ */
11642
+ __publicField(this, "_transport", null);
11643
+ /**
11644
+ * @private
11645
+ */
11646
+ __publicField(this, "_worker", null);
11647
+ /**
11648
+ * Unique identifier for the document loading task.
11649
+ * @type {string}
11650
+ */
11651
+ __publicField(this, "docId", `d${__privateWrapper(_PDFDocumentLoadingTask, _docId2)._++}`);
11652
+ /**
11653
+ * Whether the loading task is destroyed or not.
11654
+ * @type {boolean}
11655
+ */
11656
+ __publicField(this, "destroyed", false);
11657
+ /**
11658
+ * Callback to request a password if a wrong or no password was provided.
11659
+ * The callback receives two parameters: a function that should be called
11660
+ * with the new password, and a reason (see {@link PasswordResponses}).
11661
+ * @type {function}
11662
+ */
11663
+ __publicField(this, "onPassword", null);
11664
+ /**
11665
+ * Callback to be able to monitor the loading progress of the PDF file
11666
+ * (necessary to implement e.g. a loading bar).
11667
+ * The callback receives an {@link OnProgressParameters} argument.
11668
+ * @type {function}
11669
+ */
11670
+ __publicField(this, "onProgress", null);
11843
11671
  }
11844
11672
  /**
11845
11673
  * Promise for document loading task completion.
@@ -11874,6 +11702,15 @@ var _PDFDocumentLoadingTask = class _PDFDocumentLoadingTask {
11874
11702
  this._worker?.destroy();
11875
11703
  this._worker = null;
11876
11704
  }
11705
+ /**
11706
+ * Attempt to fetch the raw data of the PDF document, when e.g.
11707
+ * - An exception was thrown during document initialization.
11708
+ * - An `onPassword` callback is delaying initialization.
11709
+ * @returns {Promise<Uint8Array>}
11710
+ */
11711
+ async getData() {
11712
+ return this._transport.getData();
11713
+ }
11877
11714
  };
11878
11715
  _docId2 = new WeakMap();
11879
11716
  __privateAdd(_PDFDocumentLoadingTask, _docId2, 0);
@@ -13050,6 +12887,7 @@ var _PDFWorker = class _PDFWorker {
13050
12887
  }
13051
12888
  /**
13052
12889
  * @param {PDFWorkerParameters} params - The worker initialization parameters.
12890
+ * @returns {PDFWorker}
13053
12891
  */
13054
12892
  static fromPort(params) {
13055
12893
  if (false) {
@@ -13085,7 +12923,7 @@ var _PDFWorker = class _PDFWorker {
13085
12923
  if (__privateGet(this, _PDFWorker_static, mainThreadWorkerMessageHandler_get)) {
13086
12924
  return __privateGet(this, _PDFWorker_static, mainThreadWorkerMessageHandler_get);
13087
12925
  }
13088
- const worker = true ? await import("./worker.js") : await __non_webpack_import__(this.workerSrc);
12926
+ const worker = true ? await import("./worker.js") : await __raw_import__(this.workerSrc);
13089
12927
  return worker.WorkerMessageHandler;
13090
12928
  };
13091
12929
  return shadow(this, "_setupFakeWorkerGlobal", loader());
@@ -17614,7 +17452,7 @@ var _FreeTextEditor = class _FreeTextEditor extends AnnotationEditor {
17614
17452
  __privateSet(this, _content, `${bufferBefore.join("\n")}${paste}${bufferAfter.join("\n")}`);
17615
17453
  __privateMethod(this, _FreeTextEditor_instances, setContent_fn).call(this);
17616
17454
  const newRange = new Range();
17617
- let beforeLength = bufferBefore.reduce((acc, line) => acc + line.length, 0);
17455
+ let beforeLength = Math.sumPrecise(bufferBefore.map((line) => line.length));
17618
17456
  for (const { firstChild } of this.editorDiv.childNodes) {
17619
17457
  if (firstChild.nodeType === Node.TEXT_NODE) {
17620
17458
  const length = firstChild.nodeValue.length;
@@ -18464,35 +18302,24 @@ computeMinMax_fn = function(isLTR) {
18464
18302
  const outline = __privateGet(this, _outline);
18465
18303
  let lastX = outline[4];
18466
18304
  let lastY = outline[5];
18467
- let minX = lastX;
18468
- let minY = lastY;
18469
- let maxX = lastX;
18470
- let maxY = lastY;
18305
+ const minMax = [lastX, lastY, lastX, lastY];
18471
18306
  let lastPointX = lastX;
18472
18307
  let lastPointY = lastY;
18473
18308
  const ltrCallback = isLTR ? Math.max : Math.min;
18474
18309
  for (let i = 6, ii = outline.length; i < ii; i += 6) {
18310
+ const x = outline[i + 4], y = outline[i + 5];
18475
18311
  if (isNaN(outline[i])) {
18476
- minX = Math.min(minX, outline[i + 4]);
18477
- minY = Math.min(minY, outline[i + 5]);
18478
- maxX = Math.max(maxX, outline[i + 4]);
18479
- maxY = Math.max(maxY, outline[i + 5]);
18480
- if (lastPointY < outline[i + 5]) {
18481
- lastPointX = outline[i + 4];
18482
- lastPointY = outline[i + 5];
18483
- } else if (lastPointY === outline[i + 5]) {
18484
- lastPointX = ltrCallback(lastPointX, outline[i + 4]);
18312
+ Util.pointBoundingBox(x, y, minMax);
18313
+ if (lastPointY < y) {
18314
+ lastPointX = x;
18315
+ lastPointY = y;
18316
+ } else if (lastPointY === y) {
18317
+ lastPointX = ltrCallback(lastPointX, x);
18485
18318
  }
18486
18319
  } else {
18487
- const bbox2 = Util.bezierBoundingBox(
18488
- lastX,
18489
- lastY,
18490
- ...outline.slice(i, i + 6)
18491
- );
18492
- minX = Math.min(minX, bbox2[0]);
18493
- minY = Math.min(minY, bbox2[1]);
18494
- maxX = Math.max(maxX, bbox2[2]);
18495
- maxY = Math.max(maxY, bbox2[3]);
18320
+ const bbox2 = [Infinity, Infinity, -Infinity, -Infinity];
18321
+ Util.bezierBoundingBox(lastX, lastY, ...outline.slice(i, i + 6), bbox2);
18322
+ Util.rectBoundingBox(...bbox2, minMax);
18496
18323
  if (lastPointY < bbox2[3]) {
18497
18324
  lastPointX = bbox2[2];
18498
18325
  lastPointY = bbox2[3];
@@ -18500,14 +18327,14 @@ computeMinMax_fn = function(isLTR) {
18500
18327
  lastPointX = ltrCallback(lastPointX, bbox2[2]);
18501
18328
  }
18502
18329
  }
18503
- lastX = outline[i + 4];
18504
- lastY = outline[i + 5];
18330
+ lastX = x;
18331
+ lastY = y;
18505
18332
  }
18506
18333
  const bbox = __privateGet(this, _bbox);
18507
- bbox[0] = minX - __privateGet(this, _innerMargin2);
18508
- bbox[1] = minY - __privateGet(this, _innerMargin2);
18509
- bbox[2] = maxX - minX + 2 * __privateGet(this, _innerMargin2);
18510
- bbox[3] = maxY - minY + 2 * __privateGet(this, _innerMargin2);
18334
+ bbox[0] = minMax[0] - __privateGet(this, _innerMargin2);
18335
+ bbox[1] = minMax[1] - __privateGet(this, _innerMargin2);
18336
+ bbox[2] = minMax[2] - minMax[0] + 2 * __privateGet(this, _innerMargin2);
18337
+ bbox[3] = minMax[3] - minMax[1] + 2 * __privateGet(this, _innerMargin2);
18511
18338
  this.lastPoint = [lastPointX, lastPointY];
18512
18339
  };
18513
18340
 
@@ -18532,10 +18359,7 @@ var HighlightOutliner = class {
18532
18359
  __privateAdd(this, _lastPoint);
18533
18360
  __privateAdd(this, _verticalEdges, []);
18534
18361
  __privateAdd(this, _intervals, []);
18535
- let minX = Infinity;
18536
- let maxX = -Infinity;
18537
- let minY = Infinity;
18538
- let maxY = -Infinity;
18362
+ const minMax = [Infinity, Infinity, -Infinity, -Infinity];
18539
18363
  const NUMBER_OF_DIGITS = 4;
18540
18364
  const EPSILON = 10 ** -NUMBER_OF_DIGITS;
18541
18365
  for (const { x, y, width, height } of boxes) {
@@ -18546,15 +18370,12 @@ var HighlightOutliner = class {
18546
18370
  const left = [x1, y1, y2, true];
18547
18371
  const right = [x2, y1, y2, false];
18548
18372
  __privateGet(this, _verticalEdges).push(left, right);
18549
- minX = Math.min(minX, x1);
18550
- maxX = Math.max(maxX, x2);
18551
- minY = Math.min(minY, y1);
18552
- maxY = Math.max(maxY, y2);
18553
- }
18554
- const bboxWidth = maxX - minX + 2 * innerMargin;
18555
- const bboxHeight = maxY - minY + 2 * innerMargin;
18556
- const shiftedMinX = minX - innerMargin;
18557
- const shiftedMinY = minY - innerMargin;
18373
+ Util.rectBoundingBox(x1, y1, x2, y2, minMax);
18374
+ }
18375
+ const bboxWidth = minMax[2] - minMax[0] + 2 * innerMargin;
18376
+ const bboxHeight = minMax[3] - minMax[1] + 2 * innerMargin;
18377
+ const shiftedMinX = minMax[0] - innerMargin;
18378
+ const shiftedMinY = minMax[1] - innerMargin;
18558
18379
  const lastEdge = __privateGet(this, _verticalEdges).at(isLTR ? -1 : -2);
18559
18380
  const lastPoint = [lastEdge[0], lastEdge[2]];
18560
18381
  for (const edge of __privateGet(this, _verticalEdges)) {
@@ -19083,6 +18904,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
19083
18904
  __privateSet(this, _methodOfCreation, params.methodOfCreation || "");
19084
18905
  __privateSet(this, _text, params.text || "");
19085
18906
  this._isDraggable = false;
18907
+ this.defaultL10nId = "pdfjs-editor-highlight-editor";
19086
18908
  if (params.highlightId > -1) {
19087
18909
  __privateSet(this, _isFreeHighlight, true);
19088
18910
  __privateMethod(this, _HighlightEditor_instances, createFreeOutlines_fn).call(this, params);
@@ -19597,6 +19419,7 @@ var _HighlightEditor = class _HighlightEditor extends AnnotationEditor {
19597
19419
  clipPathId
19598
19420
  });
19599
19421
  __privateMethod(_d = editor, _HighlightEditor_instances, addToDrawLayer_fn).call(_d);
19422
+ editor.rotate(editor.parentRotation);
19600
19423
  }
19601
19424
  return editor;
19602
19425
  }
@@ -21506,11 +21329,7 @@ computeBbox_fn = function() {
21506
21329
  for (const { line } of __privateGet(this, _lines2)) {
21507
21330
  if (line.length <= 12) {
21508
21331
  for (let i = 4, ii = line.length; i < ii; i += 6) {
21509
- const [x, y] = line.subarray(i, i + 2);
21510
- bbox[0] = Math.min(bbox[0], x);
21511
- bbox[1] = Math.min(bbox[1], y);
21512
- bbox[2] = Math.max(bbox[2], x);
21513
- bbox[3] = Math.max(bbox[3], y);
21332
+ Util.pointBoundingBox(line[i], line[i + 1], bbox);
21514
21333
  }
21515
21334
  continue;
21516
21335
  }
@@ -21523,10 +21342,10 @@ computeBbox_fn = function() {
21523
21342
  }
21524
21343
  }
21525
21344
  const [marginX, marginY] = __privateMethod(this, _InkDrawOutline_instances, getMarginComponents_fn).call(this);
21526
- bbox[0] = Math.min(1, Math.max(0, bbox[0] - marginX));
21527
- bbox[1] = Math.min(1, Math.max(0, bbox[1] - marginY));
21528
- bbox[2] = Math.min(1, Math.max(0, bbox[2] + marginX));
21529
- bbox[3] = Math.min(1, Math.max(0, bbox[3] + marginY));
21345
+ bbox[0] = MathClamp(bbox[0] - marginX, 0, 1);
21346
+ bbox[1] = MathClamp(bbox[1] - marginY, 0, 1);
21347
+ bbox[2] = MathClamp(bbox[2] + marginX, 0, 1);
21348
+ bbox[3] = MathClamp(bbox[3] + marginY, 0, 1);
21530
21349
  bbox[2] -= bbox[0];
21531
21350
  bbox[3] -= bbox[1];
21532
21351
  };
@@ -21580,6 +21399,7 @@ var _InkEditor = class _InkEditor extends DrawingEditor {
21580
21399
  super({ ...params, name: "inkEditor" });
21581
21400
  __privateAdd(this, _InkEditor_instances);
21582
21401
  this._willKeepAspectRatio = true;
21402
+ this.defaultL10nId = "pdfjs-editor-ink-editor";
21583
21403
  }
21584
21404
  /** @inheritdoc */
21585
21405
  static initialize(l10n, uiManager) {
@@ -22473,6 +22293,7 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
22473
22293
  this._willKeepAspectRatio = true;
22474
22294
  __privateSet(this, _signatureData, params.signatureData || null);
22475
22295
  __privateSet(this, _description, null);
22296
+ this.defaultL10nId = "pdfjs-editor-signature-editor1";
22476
22297
  }
22477
22298
  /** @inheritdoc */
22478
22299
  static initialize(l10n, uiManager) {
@@ -22536,7 +22357,6 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
22536
22357
  baseY = this.y;
22537
22358
  }
22538
22359
  super.render();
22539
- this.div.setAttribute("role", "figure");
22540
22360
  if (this._drawId === null) {
22541
22361
  if (__privateGet(this, _signatureData)) {
22542
22362
  const {
@@ -22562,6 +22382,10 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
22562
22382
  });
22563
22383
  this.addSignature(outline, heightInPage, description, uuid);
22564
22384
  } else {
22385
+ this.div.setAttribute(
22386
+ "data-l10n-args",
22387
+ JSON.stringify({ description: "" })
22388
+ );
22565
22389
  this.div.hidden = true;
22566
22390
  this._uiManager.getSignature(this);
22567
22391
  }
@@ -22628,6 +22452,7 @@ var _SignatureEditor = class _SignatureEditor extends DrawingEditor {
22628
22452
  const { outline } = __privateSet(this, _signatureData, data);
22629
22453
  __privateSet(this, _isExtracted, outline instanceof ContourDrawOutline);
22630
22454
  __privateSet(this, _description, description);
22455
+ this.div.setAttribute("data-l10n-args", JSON.stringify({ description }));
22631
22456
  let drawingOptions;
22632
22457
  if (__privateGet(this, _isExtracted)) {
22633
22458
  drawingOptions = _SignatureEditor.getDefaultDrawingOptions();
@@ -22808,6 +22633,7 @@ var StampEditor = class extends AnnotationEditor {
22808
22633
  __privateAdd(this, _hasBeenAddedInUndoStack, false);
22809
22634
  __privateSet(this, _bitmapUrl, params.bitmapUrl);
22810
22635
  __privateSet(this, _bitmapFile, params.bitmapFile);
22636
+ this.defaultL10nId = "pdfjs-editor-stamp-editor";
22811
22637
  }
22812
22638
  /** @inheritdoc */
22813
22639
  static initialize(l10n, uiManager) {
@@ -22949,7 +22775,6 @@ var StampEditor = class extends AnnotationEditor {
22949
22775
  }
22950
22776
  super.render();
22951
22777
  this.div.hidden = true;
22952
- this.div.setAttribute("role", "figure");
22953
22778
  this.addAltTextButton();
22954
22779
  if (!__privateGet(this, _missingCanvas)) {
22955
22780
  if (__privateGet(this, _bitmap)) {
@@ -23097,10 +22922,6 @@ var StampEditor = class extends AnnotationEditor {
23097
22922
  return { canvas, width, height, imageData };
23098
22923
  }
23099
22924
  /** @inheritdoc */
23100
- getImageForAltText() {
23101
- return __privateGet(this, _canvas);
23102
- }
23103
- /** @inheritdoc */
23104
22925
  static async deserialize(data, parent, uiManager) {
23105
22926
  let initialData = null;
23106
22927
  let missingCanvas = false;
@@ -23416,7 +23237,7 @@ createCanvas_fn = function() {
23416
23237
  action: "inserted_image"
23417
23238
  });
23418
23239
  if (__privateGet(this, _bitmapFileName)) {
23419
- canvas.setAttribute("aria-label", __privateGet(this, _bitmapFileName));
23240
+ this.div.setAttribute("aria-description", __privateGet(this, _bitmapFileName));
23420
23241
  }
23421
23242
  };
23422
23243
  scaleBitmap_fn = function(width, height) {
@@ -24539,320 +24360,39 @@ if (false) {
24539
24360
  };
24540
24361
  }
24541
24362
 
24542
- // src/lib/utils.ts
24543
- async function canvasToData(canvas) {
24544
- if ("toBlob" in canvas) {
24545
- const blob = await new Promise(
24546
- (resolve) => canvas.toBlob((data) => resolve(data))
24547
- );
24548
- if (!blob) {
24549
- throw new Error("Failed to generate graphics");
24363
+ // src/lib/AnnotationOperatorsList.ts
24364
+ var AnnotationOperatorsList = class {
24365
+ /**
24366
+ * The list of operators to be executed.
24367
+ * @param operatorList The list of operators to be executed.
24368
+ */
24369
+ constructor(operatorList) {
24370
+ __publicField(this, "map", /* @__PURE__ */ new Map());
24371
+ let currentId = null;
24372
+ let currentList = [];
24373
+ for (const [index, op] of operatorList.fnArray.entries()) {
24374
+ const args = operatorList.argsArray[index];
24375
+ if (op === OPS.beginAnnotation) {
24376
+ currentId = args[0];
24377
+ currentList.push({ fn: op, args });
24378
+ } else if (op === OPS.endAnnotation && currentId) {
24379
+ currentList.push({ fn: op, args });
24380
+ this.map.set(currentId, currentList);
24381
+ currentList = [];
24382
+ } else if (currentId) {
24383
+ currentList.push({ fn: op, args });
24384
+ }
24550
24385
  }
24551
- return new Uint8Array(await blob.arrayBuffer());
24552
24386
  }
24553
- const buffer = await canvas.encode("png");
24554
- return new Uint8Array(buffer);
24555
- }
24556
- async function toDataUrl(data) {
24557
- if (typeof FileReader !== "undefined") {
24558
- return new Promise((resolve) => {
24559
- const reader = new FileReader();
24560
- reader.onload = () => {
24561
- resolve(reader.result);
24562
- };
24563
- reader.readAsDataURL(new Blob([data], { type: "image/png" }));
24564
- });
24387
+ /**
24388
+ * Get the list of operators for the given annotation id.
24389
+ * @param id The id of the annotation.
24390
+ * @return The list of operators for the given annotation id.
24391
+ */
24392
+ get(id) {
24393
+ return this.map.get(id) ?? [];
24565
24394
  }
24566
- return `data:image/png;base64,${Buffer.from(data).toString("base64")}`;
24567
- }
24568
-
24569
- // src/lib/PDFPageProxy.ts
24570
- var getAnnotations = PDFPageProxy.prototype.getAnnotations;
24571
- PDFPageProxy.prototype.getAnnotations = async function(params) {
24572
- const annotations = await getAnnotations.call(this, params);
24573
- const operatorList = await this.getOperatorList({
24574
- annotationMode: AnnotationMode.ENABLE_FORMS
24575
- });
24576
- const annotationsOperatorList = /* @__PURE__ */ new Map();
24577
- let currentId = null;
24578
- let currentList = [];
24579
- for (const [index, op] of operatorList.fnArray.entries()) {
24580
- const args = operatorList.argsArray[index];
24581
- if (op === OPS.beginAnnotation) {
24582
- currentId = args[0];
24583
- currentList.push({ fn: op, args });
24584
- } else if (op === OPS.endAnnotation && currentId) {
24585
- currentList.push({ fn: op, args });
24586
- annotationsOperatorList.set(currentId, currentList);
24587
- currentList = [];
24588
- } else if (currentId) {
24589
- currentList.push({ fn: op, args });
24590
- }
24591
- }
24592
- for (const annotation of annotations) {
24593
- const opList = annotationsOperatorList.get(annotation.id);
24594
- if (opList) {
24595
- if (annotation.subtype === "Stamp") {
24596
- try {
24597
- const canvasFactory = isNodeJS ? new NodeCanvasFactory({}) : new DOMCanvasFactory({});
24598
- const scale = 2;
24599
- const viewport = this.getViewport({ scale });
24600
- const { context: canvasContext } = canvasFactory.create(
24601
- viewport.width,
24602
- viewport.height
24603
- );
24604
- const gsx = new CanvasGraphics(
24605
- canvasContext,
24606
- this.commonObjs,
24607
- this.objs,
24608
- canvasFactory,
24609
- this.filterFactory,
24610
- { optionalContentConfig: null }
24611
- );
24612
- gsx.beginDrawing({
24613
- transform: null,
24614
- viewport
24615
- });
24616
- canvasContext.clearRect(0, 0, viewport.width, viewport.height);
24617
- gsx.executeOperatorList({
24618
- fnArray: opList.map((op) => op.fn),
24619
- argsArray: opList.map((op) => op.args)
24620
- });
24621
- const width = annotation.rect[2] - annotation.rect[0];
24622
- const height = annotation.rect[3] - annotation.rect[1];
24623
- const { context: croppedCanvasContext } = canvasFactory.create(
24624
- width * scale,
24625
- height * scale
24626
- );
24627
- croppedCanvasContext.drawImage(
24628
- canvasContext.canvas,
24629
- annotation.rect[0] * scale,
24630
- (this.view[3] - annotation.rect[1] - height) * scale,
24631
- width * scale,
24632
- height * scale,
24633
- 0,
24634
- 0,
24635
- width * scale,
24636
- height * scale
24637
- );
24638
- annotation.graphics = await canvasToData(croppedCanvasContext.canvas);
24639
- } catch (e) {
24640
- console.error(e);
24641
- }
24642
- } else {
24643
- let firstStroke = true;
24644
- let firstFill = true;
24645
- let currentFillColor = null;
24646
- let currentLineWidth = null;
24647
- for (const { fn, args } of opList) {
24648
- if (fn === OPS.fill) {
24649
- if (currentFillColor) {
24650
- annotation.interiorColor = currentFillColor;
24651
- currentFillColor = null;
24652
- }
24653
- firstFill = false;
24654
- continue;
24655
- }
24656
- if (fn === OPS.beginText) {
24657
- firstFill = false;
24658
- continue;
24659
- }
24660
- if (fn === OPS.stroke) {
24661
- if (currentLineWidth === null) {
24662
- annotation.borderStyle.width = 1;
24663
- }
24664
- firstStroke = false;
24665
- currentLineWidth = null;
24666
- continue;
24667
- }
24668
- if (fn === OPS.fillStroke) {
24669
- if (currentFillColor) {
24670
- annotation.interiorColor = currentFillColor;
24671
- currentFillColor = null;
24672
- }
24673
- if (currentLineWidth === null) {
24674
- annotation.borderStyle.width = 1;
24675
- }
24676
- firstStroke = false;
24677
- currentLineWidth = null;
24678
- break;
24679
- }
24680
- if (!firstFill && !firstStroke) {
24681
- break;
24682
- }
24683
- if (fn === OPS.setLineWidth && firstStroke) {
24684
- currentLineWidth = args[0];
24685
- annotation.borderStyle.width = currentLineWidth;
24686
- }
24687
- if (fn === OPS.setStrokeRGBColor && firstStroke) {
24688
- if (!annotation.borderStyle.width) {
24689
- annotation.borderStyle.width = 1;
24690
- }
24691
- annotation.color = args;
24692
- }
24693
- if (fn === OPS.setFillRGBColor && firstFill) {
24694
- currentFillColor = args;
24695
- }
24696
- if (fn === OPS.setGState) {
24697
- for (const entry of args[0]) {
24698
- if (!Array.isArray(entry)) {
24699
- continue;
24700
- }
24701
- if (entry[0] === "ca" && firstFill) {
24702
- annotation.interiorColorOpacity = entry[1];
24703
- }
24704
- if (entry[0] === "CA" && firstStroke) {
24705
- annotation.borderColorOpacity = entry[1];
24706
- }
24707
- }
24708
- }
24709
- }
24710
- }
24711
- }
24712
- }
24713
- return annotations;
24714
- };
24715
-
24716
- // src/lib/StandardFontDataFactory.ts
24717
- var StandardFontDataFactory = class extends BaseStandardFontDataFactory {
24718
- constructor() {
24719
- super({
24720
- baseUrl: null
24721
- });
24722
- }
24723
- /**
24724
- * Fetch the corresponding standard font data.
24725
- * We need to use specific dynamic imports for each font file for the bundler to include them.
24726
- */
24727
- async fetch({ filename }) {
24728
- switch (filename) {
24729
- case "FoxitDingbats.pfb":
24730
- return import("./FoxitDingbats-SB6TO3S5.js").then((module) => module.default);
24731
- case "FoxitFixed.pfb":
24732
- return import("./FoxitFixed-UIGSMBQB.js").then(
24733
- (module) => module.default
24734
- );
24735
- case "FoxitFixedBold.pfb":
24736
- return import("./FoxitFixedBold-2PAEIZAT.js").then((module) => module.default);
24737
- case "FoxitFixedBoldItalic.pfb":
24738
- return import("./FoxitFixedBoldItalic-OSQUQDEE.js").then((module) => module.default);
24739
- case "FoxitFixedItalic.pfb":
24740
- return import("./FoxitFixedItalic-W73RDK22.js").then((module) => module.default);
24741
- case "FoxitSerif.pfb":
24742
- return import("./FoxitSerif-3HH3SOZF.js").then(
24743
- (module) => module.default
24744
- );
24745
- case "FoxitSerifBold.pfb":
24746
- return import("./FoxitSerifBold-HXP2QOO7.js").then((module) => module.default);
24747
- case "FoxitSerifBoldItalic.pfb":
24748
- return import("./FoxitSerifBoldItalic-FZXLNWD7.js").then((module) => module.default);
24749
- case "FoxitSerifItalic.pfb":
24750
- return import("./FoxitSerifItalic-WQFHUBI2.js").then((module) => module.default);
24751
- case "FoxitSymbol.pfb":
24752
- return import("./FoxitSymbol-OVWU7LKS.js").then(
24753
- (module) => module.default
24754
- );
24755
- case "LiberationSans-Bold.ttf":
24756
- return import("./LiberationSans-Bold-GSJN42N5.js").then((module) => module.default);
24757
- case "LiberationSans-BoldItalic.ttf":
24758
- return import("./LiberationSans-BoldItalic-UCPQJ3L2.js").then((module) => module.default);
24759
- case "LiberationSans-Italic.ttf":
24760
- return import("./LiberationSans-Italic-6CIHEALY.js").then((module) => module.default);
24761
- case "LiberationSans-Regular.ttf":
24762
- return import("./LiberationSans-Regular-KIF3IRJY.js").then((module) => module.default);
24763
- }
24764
- return Uint8Array.from([]);
24765
- }
24766
- };
24767
-
24768
- // src/lib/AnnotationData.ts
24769
- function isTextAnnotation(annotation) {
24770
- return annotation.subtype === "Text";
24771
- }
24772
- function isLinkAnnotation(annotation) {
24773
- return annotation.subtype === "Link";
24774
- }
24775
- function isFreeTextAnnotation(annotation) {
24776
- return annotation.subtype === "FreeText";
24777
- }
24778
- function isLineAnnotation(annotation) {
24779
- return annotation.subtype === "Line";
24780
- }
24781
- function isSquareAnnotation(annotation) {
24782
- return annotation.subtype === "Square";
24783
- }
24784
- function isCircleAnnotation(annotation) {
24785
- return annotation.subtype === "Circle";
24786
- }
24787
- function isPolygonAnnotation(annotation) {
24788
- return annotation.subtype === "Polygon";
24789
- }
24790
- function isPolylineAnnotation(annotation) {
24791
- return annotation.subtype === "PolyLine";
24792
- }
24793
- function isHighlightAnnotation(annotation) {
24794
- return annotation.subtype === "Highlight";
24795
- }
24796
- function isUnderlineAnnotation(annotation) {
24797
- return annotation.subtype === "Underline";
24798
- }
24799
- function isSquigglyAnnotation(annotation) {
24800
- return annotation.subtype === "Squiggly";
24801
- }
24802
- function isStrikeOutAnnotation(annotation) {
24803
- return annotation.subtype === "StrikeOut";
24804
- }
24805
- function isStampAnnotation(annotation) {
24806
- return annotation.subtype === "Stamp";
24807
- }
24808
- function isCaretAnnotation(annotation) {
24809
- return annotation.subtype === "Caret";
24810
- }
24811
- function isInkAnnotation(annotation) {
24812
- return annotation.subtype === "Ink";
24813
- }
24814
- function isPopupAnnotation(annotation) {
24815
- return annotation.subtype === "Popup";
24816
- }
24817
- function isFileAttachmentAnnotation(annotation) {
24818
- return annotation.subtype === "FileAttachment";
24819
- }
24820
- function isSoundAnnotation(annotation) {
24821
- return annotation.subtype === "Sound";
24822
- }
24823
- function isMovieAnnotation(annotation) {
24824
- return annotation.subtype === "Movie";
24825
- }
24826
- function isWidgetAnnotation(annotation) {
24827
- return annotation.subtype === "Widget";
24828
- }
24829
- function isTextWidgetAnnotation(annotation) {
24830
- return annotation.subtype === "Widget" && annotation.fieldType === "Tx";
24831
- }
24832
- function isChoiceWidgetAnnotation(annotation) {
24833
- return annotation.subtype === "Widget" && annotation.fieldType === "Ch";
24834
- }
24835
- function isButtonWidgetAnnotation(annotation) {
24836
- return annotation.subtype === "Widget" && annotation.fieldType === "Btn";
24837
- }
24838
- function isScreenAnnotation(annotation) {
24839
- return annotation.subtype === "Screen";
24840
- }
24841
- function isPrinterMarkAnnotation(annotation) {
24842
- return annotation.subtype === "PrinterMark";
24843
- }
24844
- function isTrapNetAnnotation(annotation) {
24845
- return annotation.subtype === "TrapNet";
24846
- }
24847
- function isWatermarkAnnotation(annotation) {
24848
- return annotation.subtype === "Watermark";
24849
- }
24850
- function isThreeDAnnotation(annotation) {
24851
- return annotation.subtype === "3D";
24852
- }
24853
- function isRedactAnnotation(annotation) {
24854
- return annotation.subtype === "Redact";
24855
- }
24395
+ };
24856
24396
 
24857
24397
  // src/lib/SvgCanvasContext.ts
24858
24398
  function parseTransformMatrix(transformString) {
@@ -25147,19 +24687,33 @@ var SvgCanvasContext = class {
25147
24687
  this._styleStack.push(this._getStyleState());
25148
24688
  this._transformMatrixStack.push(this.getTransform());
25149
24689
  }
24690
+ clearRect(x, y, width, height) {
24691
+ if (x !== 0 || y !== 0 || this._width !== width || this._height !== height) {
24692
+ throw new Error("clearRect is not supported in SVG");
24693
+ }
24694
+ this._clearCanvas();
24695
+ }
25150
24696
  restore() {
25151
- const group = this._groupStack.pop();
25152
- if (!this._isTransformationGroup(this._currentGroup)) {
25153
- group.children = group.children.filter(
25154
- (child) => child !== this._currentGroup
25155
- );
25156
- group.children.push(...this._currentGroup.children);
24697
+ if (this._groupStack.length) {
24698
+ const group = this._groupStack.pop();
24699
+ if (!this._isTransformationGroup(this._currentGroup)) {
24700
+ group.children = group.children.filter(
24701
+ (child) => child !== this._currentGroup
24702
+ );
24703
+ group.children.push(...this._currentGroup.children);
24704
+ }
24705
+ this._currentGroup = group;
24706
+ } else {
24707
+ this._currentGroup = this._root;
24708
+ }
24709
+ if (this._styleStack.length) {
24710
+ const state = this._styleStack.pop();
24711
+ this._applyStyleState(state);
24712
+ }
24713
+ if (this._transformMatrixStack.length) {
24714
+ const { a, b, c, d, e, f } = this._transformMatrixStack.pop();
24715
+ this.setTransform(a, b, c, d, e, f);
25157
24716
  }
25158
- this._currentGroup = group;
25159
- const state = this._styleStack.pop();
25160
- this._applyStyleState(state);
25161
- const { a, b, c, d, e, f } = this._transformMatrixStack.pop();
25162
- this.setTransform(a, b, c, d, e, f);
25163
24717
  }
25164
24718
  beginPath() {
25165
24719
  this._currentPosition = {};
@@ -25330,8 +24884,25 @@ var SvgCanvasContext = class {
25330
24884
  );
25331
24885
  this._currentPosition = { x: endX, y: endY };
25332
24886
  }
25333
- stroke() {
25334
- if (this._currentElement) {
24887
+ stroke(path) {
24888
+ if (path instanceof SvgPath2D) {
24889
+ const d = toCommands(path);
24890
+ if (d && d !== "Z") {
24891
+ const parent = this._currentGroup;
24892
+ const pathElement = {
24893
+ tag: "path",
24894
+ attrs: {
24895
+ d,
24896
+ fill: "none",
24897
+ stroke: "none",
24898
+ "stroke-width": "0"
24899
+ }
24900
+ };
24901
+ this._applyTransformation(pathElement);
24902
+ this._applyStyle(pathElement, "stroke");
24903
+ parent.children.push(pathElement);
24904
+ }
24905
+ } else if (this._currentElement) {
25335
24906
  this._applyStyle(this._currentElement, "stroke");
25336
24907
  }
25337
24908
  }
@@ -25480,6 +25051,9 @@ var SvgCanvasContext = class {
25480
25051
  const fillRuleValue = fillRule ?? path;
25481
25052
  this._currentStyle.fillRule = fillRuleValue;
25482
25053
  }
25054
+ if (path instanceof SvgPath2D && path.commands.length === 0) {
25055
+ return;
25056
+ }
25483
25057
  const id = `clip_${crypto.randomUUID()}`;
25484
25058
  const clipPath = {
25485
25059
  tag: "clipPath",
@@ -25642,7 +25216,6 @@ var SvgCanvasContext = class {
25642
25216
  }
25643
25217
  } else {
25644
25218
  const strokeStyle = this._currentStyle.strokeStyle;
25645
- const lineWidth = this._currentStyle.lineWidth * Math.max(scale.x, scale.y);
25646
25219
  if (strokeStyle instanceof SvgPattern) {
25647
25220
  const path = transformPath(commands, transform);
25648
25221
  const bbox = calculateBoundingBox(path);
@@ -25673,9 +25246,7 @@ var SvgCanvasContext = class {
25673
25246
  currentElement.attrs["stroke-miterlimit"] = `${this._currentStyle.miterLimit}`;
25674
25247
  }
25675
25248
  if (this._currentStyle.lineWidth !== 1) {
25676
- currentElement.attrs["stroke-width"] = `${lineWidth}`;
25677
- } else {
25678
- currentElement.attrs["vector-effect"] = "non-scaling-stroke";
25249
+ currentElement.attrs["stroke-width"] = `${this._currentStyle.lineWidth}`;
25679
25250
  }
25680
25251
  if (this._currentStyle.lineDash.length > 0) {
25681
25252
  currentElement.attrs["stroke-dasharray"] = `${this._currentStyle.lineDash.map((entry) => `${entry * Math.max(scale.x, scale.y)}`).join(",")}`;
@@ -25719,17 +25290,9 @@ var SvgCanvasContext = class {
25719
25290
  parent.children.push(textElement);
25720
25291
  }
25721
25292
  _clearCanvas() {
25722
- const rootGroup = this._root.children[1];
25723
25293
  this._defs.children = [];
25724
- this._root.children = this._root.children.filter(
25725
- (child) => child === rootGroup
25726
- );
25727
- this._currentGroup = {
25728
- tag: "g",
25729
- attrs: {},
25730
- children: []
25731
- };
25732
- this._root.children.push(this._currentGroup);
25294
+ this._root.children = [this._defs];
25295
+ this._currentGroup = this._root;
25733
25296
  this._groupStack = [];
25734
25297
  }
25735
25298
  };
@@ -25748,6 +25311,359 @@ async function toSvgNode(ctx) {
25748
25311
  return ctx.getNode();
25749
25312
  }
25750
25313
 
25314
+ // src/lib/utils.ts
25315
+ async function canvasToData(canvas) {
25316
+ if ("toBlob" in canvas) {
25317
+ const blob = await new Promise(
25318
+ (resolve) => canvas.toBlob((data) => resolve(data))
25319
+ );
25320
+ if (!blob) {
25321
+ throw new Error("Failed to generate graphics");
25322
+ }
25323
+ return new Uint8Array(await blob.arrayBuffer());
25324
+ }
25325
+ const buffer = await canvas.encode("png");
25326
+ return new Uint8Array(buffer);
25327
+ }
25328
+ async function toDataUrl(data, type = "image/png") {
25329
+ if (typeof FileReader !== "undefined") {
25330
+ return new Promise((resolve) => {
25331
+ const reader = new FileReader();
25332
+ reader.onload = () => {
25333
+ resolve(reader.result);
25334
+ };
25335
+ reader.readAsDataURL(new Blob([data], { type }));
25336
+ });
25337
+ }
25338
+ return `data:${type};base64,${Buffer.from(data).toString("base64")}`;
25339
+ }
25340
+ function makeSerializable(object) {
25341
+ if (typeof object !== "object" || object === null) {
25342
+ return object;
25343
+ }
25344
+ if (object instanceof Int8Array || object instanceof Uint8Array || object instanceof Uint8ClampedArray || object instanceof Int16Array || object instanceof Uint16Array || object instanceof Int32Array || object instanceof Uint32Array || object instanceof Float32Array || object instanceof Float64Array) {
25345
+ return makeSerializable(Array.from(object));
25346
+ }
25347
+ if (object instanceof BigInt64Array || object instanceof BigUint64Array) {
25348
+ return makeSerializable(Array.from(object));
25349
+ }
25350
+ if (Array.isArray(object)) {
25351
+ return object.map(makeSerializable);
25352
+ }
25353
+ return Object.fromEntries(
25354
+ Object.entries(object).map(([key, value]) => [
25355
+ key,
25356
+ makeSerializable(value)
25357
+ ])
25358
+ );
25359
+ }
25360
+
25361
+ // src/lib/PDFPageProxy.ts
25362
+ var getAnnotations = PDFPageProxy.prototype.getAnnotations;
25363
+ PDFPageProxy.prototype.getAnnotations = async function(params) {
25364
+ const annotations = await getAnnotations.call(this, params);
25365
+ const operatorList = await this.getOperatorList({
25366
+ annotationMode: AnnotationMode.ENABLE_FORMS
25367
+ });
25368
+ const annotationOperatorsList = new AnnotationOperatorsList(operatorList);
25369
+ for (const annotation of annotations) {
25370
+ const opList = annotationOperatorsList.get(annotation.id);
25371
+ if (opList) {
25372
+ if (annotation.subtype === "Stamp") {
25373
+ try {
25374
+ const canvasFactory = isNodeJS ? new NodeCanvasFactory({}) : new DOMCanvasFactory({});
25375
+ const scale = 2;
25376
+ const viewport = this.getViewport({ scale });
25377
+ const svgContext = await createSvgContext(
25378
+ viewport.width,
25379
+ viewport.height
25380
+ );
25381
+ const gsx = new CanvasGraphics(
25382
+ svgContext,
25383
+ this.commonObjs,
25384
+ this.objs,
25385
+ canvasFactory,
25386
+ this.filterFactory,
25387
+ { optionalContentConfig: null }
25388
+ );
25389
+ gsx.beginDrawing({
25390
+ transform: null,
25391
+ viewport
25392
+ });
25393
+ svgContext.clearRect(0, 0, viewport.width, viewport.height);
25394
+ gsx.executeOperatorList({
25395
+ fnArray: opList.map((op) => op.fn),
25396
+ argsArray: opList.map((op) => op.args)
25397
+ });
25398
+ const width = annotation.rect[2] - annotation.rect[0];
25399
+ const height = annotation.rect[3] - annotation.rect[1];
25400
+ annotation.graphics = {
25401
+ tag: "svg",
25402
+ attrs: {
25403
+ version: "1.1",
25404
+ xmlns: "http://www.w3.org/2000/svg",
25405
+ width: `${width}`,
25406
+ height: `${height}`,
25407
+ viewBox: `0 0 ${width * scale} ${height * scale}`,
25408
+ preserveAspectRatio: "none",
25409
+ "xml:space": "preserve"
25410
+ },
25411
+ children: [
25412
+ {
25413
+ tag: "g",
25414
+ attrs: {
25415
+ transform: `translate(-${annotation.rect[0] * scale}, -${(this.view[3] - annotation.rect[1] - height) * scale})`
25416
+ },
25417
+ children: [await toSvgNode(svgContext)]
25418
+ }
25419
+ ]
25420
+ };
25421
+ } catch (e) {
25422
+ console.error(e);
25423
+ }
25424
+ } else {
25425
+ switch (annotation.subtype) {
25426
+ case "Square":
25427
+ case "Circle":
25428
+ case "Polygon":
25429
+ case "Line":
25430
+ case "PolyLine":
25431
+ case "FreeText":
25432
+ case "Ink": {
25433
+ let firstStroke = true;
25434
+ let firstFill = true;
25435
+ let firstText = true;
25436
+ let currentFillColor = null;
25437
+ let currentLineWidth = null;
25438
+ for (const { fn, args } of opList) {
25439
+ const finalFn = fn === OPS.constructPath ? args[0] : fn;
25440
+ if (finalFn === OPS.fill) {
25441
+ if (currentFillColor && firstFill) {
25442
+ annotation.interiorColor = currentFillColor;
25443
+ currentFillColor = null;
25444
+ }
25445
+ firstFill = false;
25446
+ continue;
25447
+ }
25448
+ if (fn === OPS.beginText) {
25449
+ if (firstFill) {
25450
+ annotation.interiorColor = null;
25451
+ }
25452
+ firstFill = false;
25453
+ currentFillColor = null;
25454
+ continue;
25455
+ }
25456
+ if (finalFn === OPS.stroke || finalFn === OPS.closeStroke) {
25457
+ if (currentLineWidth === null && firstStroke) {
25458
+ annotation.borderStyle.width = 1;
25459
+ }
25460
+ firstStroke = false;
25461
+ currentLineWidth = null;
25462
+ continue;
25463
+ }
25464
+ if (finalFn === OPS.fillStroke || finalFn === OPS.closeFillStroke) {
25465
+ if (currentFillColor && firstFill) {
25466
+ annotation.interiorColor = currentFillColor;
25467
+ }
25468
+ if (currentLineWidth === null && firstStroke) {
25469
+ annotation.borderStyle.width = 1;
25470
+ }
25471
+ firstFill = false;
25472
+ firstStroke = false;
25473
+ currentFillColor = null;
25474
+ currentLineWidth = null;
25475
+ break;
25476
+ }
25477
+ if (!firstFill && !firstStroke) {
25478
+ break;
25479
+ }
25480
+ if (fn === OPS.setLineWidth && firstStroke) {
25481
+ currentLineWidth = args[0];
25482
+ annotation.borderStyle.width = currentLineWidth;
25483
+ }
25484
+ if (fn === OPS.setStrokeRGBColor && firstStroke) {
25485
+ annotation.color = args;
25486
+ }
25487
+ if (fn === OPS.setFillRGBColor && firstFill) {
25488
+ currentFillColor = args;
25489
+ }
25490
+ if (fn === OPS.setGState) {
25491
+ for (const entry of args[0]) {
25492
+ if (!Array.isArray(entry)) {
25493
+ continue;
25494
+ }
25495
+ if (entry[0] === "ca" && firstFill) {
25496
+ annotation.interiorColorOpacity = entry[1];
25497
+ }
25498
+ if (entry[0] === "CA" && firstStroke) {
25499
+ annotation.borderColorOpacity = entry[1];
25500
+ }
25501
+ }
25502
+ }
25503
+ if (fn === OPS.setFont && firstText) {
25504
+ const fontName = args[0];
25505
+ const font = fontName.startsWith("g_") ? this.commonObjs.get(fontName) : this.objs.get(fontName);
25506
+ if (font) {
25507
+ annotation.defaultAppearanceData.fontName = font.fallbackName;
25508
+ }
25509
+ }
25510
+ if (fn === OPS.endText) {
25511
+ firstText = false;
25512
+ }
25513
+ }
25514
+ if (firstStroke) {
25515
+ annotation.borderStyle.width = 0;
25516
+ }
25517
+ break;
25518
+ }
25519
+ }
25520
+ }
25521
+ }
25522
+ }
25523
+ return makeSerializable(annotations);
25524
+ };
25525
+
25526
+ // src/lib/StandardFontDataFactory.ts
25527
+ var StandardFontDataFactory = class extends BaseStandardFontDataFactory {
25528
+ constructor() {
25529
+ super({
25530
+ baseUrl: null
25531
+ });
25532
+ }
25533
+ /**
25534
+ * Fetch the corresponding standard font data.
25535
+ * We need to use specific dynamic imports for each font file for the bundler to include them.
25536
+ */
25537
+ async fetch({ filename }) {
25538
+ switch (filename) {
25539
+ case "FoxitDingbats.pfb":
25540
+ return import("./FoxitDingbats-SB6TO3S5.js").then((module) => module.default);
25541
+ case "FoxitFixed.pfb":
25542
+ return import("./FoxitFixed-UIGSMBQB.js").then(
25543
+ (module) => module.default
25544
+ );
25545
+ case "FoxitFixedBold.pfb":
25546
+ return import("./FoxitFixedBold-2PAEIZAT.js").then((module) => module.default);
25547
+ case "FoxitFixedBoldItalic.pfb":
25548
+ return import("./FoxitFixedBoldItalic-OSQUQDEE.js").then((module) => module.default);
25549
+ case "FoxitFixedItalic.pfb":
25550
+ return import("./FoxitFixedItalic-W73RDK22.js").then((module) => module.default);
25551
+ case "FoxitSerif.pfb":
25552
+ return import("./FoxitSerif-3HH3SOZF.js").then(
25553
+ (module) => module.default
25554
+ );
25555
+ case "FoxitSerifBold.pfb":
25556
+ return import("./FoxitSerifBold-HXP2QOO7.js").then((module) => module.default);
25557
+ case "FoxitSerifBoldItalic.pfb":
25558
+ return import("./FoxitSerifBoldItalic-FZXLNWD7.js").then((module) => module.default);
25559
+ case "FoxitSerifItalic.pfb":
25560
+ return import("./FoxitSerifItalic-WQFHUBI2.js").then((module) => module.default);
25561
+ case "FoxitSymbol.pfb":
25562
+ return import("./FoxitSymbol-OVWU7LKS.js").then(
25563
+ (module) => module.default
25564
+ );
25565
+ case "LiberationSans-Bold.ttf":
25566
+ return import("./LiberationSans-Bold-GSJN42N5.js").then((module) => module.default);
25567
+ case "LiberationSans-BoldItalic.ttf":
25568
+ return import("./LiberationSans-BoldItalic-UCPQJ3L2.js").then((module) => module.default);
25569
+ case "LiberationSans-Italic.ttf":
25570
+ return import("./LiberationSans-Italic-6CIHEALY.js").then((module) => module.default);
25571
+ case "LiberationSans-Regular.ttf":
25572
+ return import("./LiberationSans-Regular-KIF3IRJY.js").then((module) => module.default);
25573
+ }
25574
+ return Uint8Array.from([]);
25575
+ }
25576
+ };
25577
+
25578
+ // src/lib/AnnotationData.ts
25579
+ function isTextAnnotation(annotation) {
25580
+ return annotation.subtype === "Text";
25581
+ }
25582
+ function isLinkAnnotation(annotation) {
25583
+ return annotation.subtype === "Link";
25584
+ }
25585
+ function isFreeTextAnnotation(annotation) {
25586
+ return annotation.subtype === "FreeText";
25587
+ }
25588
+ function isLineAnnotation(annotation) {
25589
+ return annotation.subtype === "Line";
25590
+ }
25591
+ function isSquareAnnotation(annotation) {
25592
+ return annotation.subtype === "Square";
25593
+ }
25594
+ function isCircleAnnotation(annotation) {
25595
+ return annotation.subtype === "Circle";
25596
+ }
25597
+ function isPolygonAnnotation(annotation) {
25598
+ return annotation.subtype === "Polygon";
25599
+ }
25600
+ function isPolylineAnnotation(annotation) {
25601
+ return annotation.subtype === "PolyLine";
25602
+ }
25603
+ function isHighlightAnnotation(annotation) {
25604
+ return annotation.subtype === "Highlight";
25605
+ }
25606
+ function isUnderlineAnnotation(annotation) {
25607
+ return annotation.subtype === "Underline";
25608
+ }
25609
+ function isSquigglyAnnotation(annotation) {
25610
+ return annotation.subtype === "Squiggly";
25611
+ }
25612
+ function isStrikeOutAnnotation(annotation) {
25613
+ return annotation.subtype === "StrikeOut";
25614
+ }
25615
+ function isStampAnnotation(annotation) {
25616
+ return annotation.subtype === "Stamp";
25617
+ }
25618
+ function isCaretAnnotation(annotation) {
25619
+ return annotation.subtype === "Caret";
25620
+ }
25621
+ function isInkAnnotation(annotation) {
25622
+ return annotation.subtype === "Ink";
25623
+ }
25624
+ function isPopupAnnotation(annotation) {
25625
+ return annotation.subtype === "Popup";
25626
+ }
25627
+ function isFileAttachmentAnnotation(annotation) {
25628
+ return annotation.subtype === "FileAttachment";
25629
+ }
25630
+ function isSoundAnnotation(annotation) {
25631
+ return annotation.subtype === "Sound";
25632
+ }
25633
+ function isMovieAnnotation(annotation) {
25634
+ return annotation.subtype === "Movie";
25635
+ }
25636
+ function isWidgetAnnotation(annotation) {
25637
+ return annotation.subtype === "Widget";
25638
+ }
25639
+ function isTextWidgetAnnotation(annotation) {
25640
+ return annotation.subtype === "Widget" && annotation.fieldType === "Tx";
25641
+ }
25642
+ function isChoiceWidgetAnnotation(annotation) {
25643
+ return annotation.subtype === "Widget" && annotation.fieldType === "Ch";
25644
+ }
25645
+ function isButtonWidgetAnnotation(annotation) {
25646
+ return annotation.subtype === "Widget" && annotation.fieldType === "Btn";
25647
+ }
25648
+ function isScreenAnnotation(annotation) {
25649
+ return annotation.subtype === "Screen";
25650
+ }
25651
+ function isPrinterMarkAnnotation(annotation) {
25652
+ return annotation.subtype === "PrinterMark";
25653
+ }
25654
+ function isTrapNetAnnotation(annotation) {
25655
+ return annotation.subtype === "TrapNet";
25656
+ }
25657
+ function isWatermarkAnnotation(annotation) {
25658
+ return annotation.subtype === "Watermark";
25659
+ }
25660
+ function isThreeDAnnotation(annotation) {
25661
+ return annotation.subtype === "3D";
25662
+ }
25663
+ function isRedactAnnotation(annotation) {
25664
+ return annotation.subtype === "Redact";
25665
+ }
25666
+
25751
25667
  // src/lib/TextLayer.ts
25752
25668
  function isTextNode(node) {
25753
25669
  return node.role === "text";
@@ -25762,16 +25678,6 @@ var MAX_TEXT_DIVS_TO_RENDER2 = 1e5;
25762
25678
  var DEFAULT_FONT_SIZE3 = 30;
25763
25679
  var DEFAULT_FONT_ASCENT = 0.8;
25764
25680
  var HYPHEN_REGEX = /-\n+$/;
25765
- function getDefaultFontFamily(type) {
25766
- switch (type) {
25767
- case "serif":
25768
- return "Liberation Serif";
25769
- case "monospace":
25770
- return "Liberation Mono";
25771
- default:
25772
- return "Liberation Sans";
25773
- }
25774
- }
25775
25681
  async function createTextLayer(page, {
25776
25682
  canvasFactory,
25777
25683
  viewport = page.getViewport({ scale: 1 }),
@@ -25911,7 +25817,7 @@ async function createTextLayer(page, {
25911
25817
  }
25912
25818
  if (shouldScaleText) {
25913
25819
  if (canvasContext) {
25914
- canvasContext.font = `${fontHeight * outputScale}px ${getDefaultFontFamily(fontFamily)}`;
25820
+ canvasContext.font = `400 ${fontHeight * outputScale}px 'Liberation Sans'`;
25915
25821
  const { width } = canvasContext.measureText(geom.str);
25916
25822
  if (width > 0) {
25917
25823
  textDiv.scale = (style.vertical ? geom.height : geom.width) * outputScale / width;
@@ -25941,7 +25847,7 @@ async function createTextLayer(page, {
25941
25847
  }
25942
25848
  const savedFont = canvasContext.font;
25943
25849
  canvasContext.canvas.width = canvasContext.canvas.height = DEFAULT_FONT_SIZE3;
25944
- canvasContext.font = `${DEFAULT_FONT_SIZE3}px ${getDefaultFontFamily(fontFamily)}`;
25850
+ canvasContext.font = `400 ${DEFAULT_FONT_SIZE3}px 'Liberation Sans'`;
25945
25851
  const metrics = canvasContext.measureText(" ");
25946
25852
  let ascent = metrics.fontBoundingBoxAscent;
25947
25853
  let descent = Math.abs(metrics.fontBoundingBoxDescent);
@@ -26213,6 +26119,7 @@ async function createTextLayer(page, {
26213
26119
  }
26214
26120
  return null;
26215
26121
  };
26122
+ await loadDefaultFonts();
26216
26123
  const reader = textContentSource.getReader();
26217
26124
  while (true) {
26218
26125
  const { value, done } = await reader.read();
@@ -26246,6 +26153,7 @@ export {
26246
26153
  GlobalWorkerOptions,
26247
26154
  ImageKind,
26248
26155
  InvalidPDFException,
26156
+ MathClamp,
26249
26157
  OPS,
26250
26158
  OutputScale,
26251
26159
  PDFDataRangeTransport,
@@ -26273,7 +26181,6 @@ export {
26273
26181
  createTextLayer,
26274
26182
  createValidAbsoluteUrl,
26275
26183
  fetchData,
26276
- getDefaultFontFamily,
26277
26184
  getDocument,
26278
26185
  getFilenameFromUrl,
26279
26186
  getPdfFilenameFromUrl,
@@ -26313,9 +26220,11 @@ export {
26313
26220
  isThreeDAnnotation,
26314
26221
  isTrapNetAnnotation,
26315
26222
  isUnderlineAnnotation,
26223
+ isValidExplicitDest,
26316
26224
  isWatermarkAnnotation,
26317
26225
  isWidgetAnnotation,
26318
26226
  loadDefaultFonts,
26227
+ makeSerializable,
26319
26228
  noContextMenu,
26320
26229
  normalizeUnicode,
26321
26230
  setLayerDimensions,