@embedpdf/engines 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
- import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
2
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
3
  import { P as PdfEngine } from "./pdf-engine-ZvReuoDb.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-BISJ9naB.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
@@ -1653,6 +1653,15 @@ class PdfiumNative {
1653
1653
  saveAnnotation
1654
1654
  );
1655
1655
  break;
1656
+ case PdfAnnotationSubtype.CARET:
1657
+ isSucceed = this.addCaretContent(
1658
+ doc,
1659
+ page,
1660
+ pageCtx.pagePtr,
1661
+ annotationPtr,
1662
+ saveAnnotation
1663
+ );
1664
+ break;
1656
1665
  case PdfAnnotationSubtype.REDACT:
1657
1666
  isSucceed = this.addRedactContent(
1658
1667
  doc,
@@ -1858,6 +1867,17 @@ class PdfiumNative {
1858
1867
  );
1859
1868
  break;
1860
1869
  }
1870
+ /* ── Caret ────────────────────────────────────────────────────────────── */
1871
+ case PdfAnnotationSubtype.CARET: {
1872
+ ok = this.addCaretContent(
1873
+ doc,
1874
+ page,
1875
+ pageCtx.pagePtr,
1876
+ annotPtr,
1877
+ saveAnnotation
1878
+ );
1879
+ break;
1880
+ }
1861
1881
  /* ── Redact ───────────────────────────────────────────────────────────── */
1862
1882
  case PdfAnnotationSubtype.REDACT: {
1863
1883
  ok = this.addRedactContent(
@@ -2860,6 +2880,13 @@ class PdfiumNative {
2860
2880
  if (annotation.stateModel && !this.setAnnotString(annotationPtr, "StateModel", annotation.stateModel)) {
2861
2881
  return false;
2862
2882
  }
2883
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2884
+ return false;
2885
+ }
2886
+ const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
2887
+ if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
2888
+ return false;
2889
+ }
2863
2890
  if (!annotation.flags) {
2864
2891
  if (!this.setAnnotationFlags(annotationPtr, ["print", "noZoom", "noRotate"])) {
2865
2892
  return false;
@@ -2867,6 +2894,30 @@ class PdfiumNative {
2867
2894
  }
2868
2895
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
2869
2896
  }
2897
+ /**
2898
+ * Add caret content to annotation
2899
+ * @param doc - document object
2900
+ * @param page - page info
2901
+ * @param pagePtr - pointer to page object
2902
+ * @param annotationPtr - pointer to caret annotation
2903
+ * @param annotation - caret annotation
2904
+ * @returns whether caret content is added to annotation
2905
+ *
2906
+ * @private
2907
+ */
2908
+ addCaretContent(doc, page, pagePtr, annotationPtr, annotation) {
2909
+ if (annotation.strokeColor) {
2910
+ this.setAnnotationColor(annotationPtr, annotation.strokeColor, PdfAnnotationColorType.Color);
2911
+ }
2912
+ if (annotation.opacity !== void 0) {
2913
+ this.setAnnotationOpacity(annotationPtr, annotation.opacity);
2914
+ }
2915
+ if (annotation.intent) {
2916
+ this.setAnnotIntent(annotationPtr, annotation.intent);
2917
+ }
2918
+ this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
2919
+ return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
2920
+ }
2870
2921
  /**
2871
2922
  * Add free text content to annotation
2872
2923
  * @param page - page info
@@ -2909,6 +2960,7 @@ class PdfiumNative {
2909
2960
  } else if (!this.setAnnotationColor(annotationPtr, bgColor ?? "#FFFFFF", PdfAnnotationColorType.Color)) {
2910
2961
  return false;
2911
2962
  }
2963
+ this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
2912
2964
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
2913
2965
  }
2914
2966
  /**
@@ -3049,6 +3101,12 @@ class PdfiumNative {
3049
3101
  )) {
3050
3102
  return false;
3051
3103
  }
3104
+ if (annotation.type === PdfAnnotationSubtype.POLYGON) {
3105
+ this.setRectangleDifferences(
3106
+ annotationPtr,
3107
+ annotation.rectangleDifferences
3108
+ );
3109
+ }
3052
3110
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
3053
3111
  }
3054
3112
  /**
@@ -3124,6 +3182,7 @@ class PdfiumNative {
3124
3182
  )) {
3125
3183
  return false;
3126
3184
  }
3185
+ this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
3127
3186
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
3128
3187
  }
3129
3188
  /**
@@ -4939,6 +4998,25 @@ class PdfiumNative {
4939
4998
  this.memoryManager.free(bPtr);
4940
4999
  return { ok, left, top, right, bottom };
4941
5000
  }
5001
+ /**
5002
+ * Sets the /RD array on an annotation.
5003
+ *
5004
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
5005
+ * @param rd the four inset values, or `undefined` to clear
5006
+ * @returns `true` on success
5007
+ */
5008
+ setRectangleDifferences(annotationPtr, rd) {
5009
+ if (!rd) {
5010
+ return this.pdfiumModule.EPDFAnnot_ClearRectangleDifferences(annotationPtr);
5011
+ }
5012
+ return this.pdfiumModule.EPDFAnnot_SetRectangleDifferences(
5013
+ annotationPtr,
5014
+ rd.left,
5015
+ rd.top,
5016
+ rd.right,
5017
+ rd.bottom
5018
+ );
5019
+ }
4942
5020
  /**
4943
5021
  * Get the date of the annotation
4944
5022
  *
@@ -5516,6 +5594,7 @@ class PdfiumNative {
5516
5594
  id: index,
5517
5595
  type: PdfAnnotationSubtype.TEXT,
5518
5596
  rect,
5597
+ strokeColor: color ?? "#FFFF00",
5519
5598
  color: color ?? "#FFFF00",
5520
5599
  opacity,
5521
5600
  state,
@@ -5543,6 +5622,7 @@ class PdfiumNative {
5543
5622
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
5544
5623
  const opacity = this.getAnnotationOpacity(annotationPtr);
5545
5624
  const richContent = this.getAnnotRichContent(annotationPtr);
5625
+ const rd = this.getRectangleDifferences(annotationPtr);
5546
5626
  return {
5547
5627
  pageIndex: page.index,
5548
5628
  id: index,
@@ -5560,6 +5640,14 @@ class PdfiumNative {
5560
5640
  textAlign,
5561
5641
  defaultStyle,
5562
5642
  richContent,
5643
+ ...rd.ok && {
5644
+ rectangleDifferences: {
5645
+ left: rd.left,
5646
+ top: rd.top,
5647
+ right: rd.right,
5648
+ bottom: rd.bottom
5649
+ }
5650
+ },
5563
5651
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5564
5652
  };
5565
5653
  }
@@ -5722,6 +5810,7 @@ class PdfiumNative {
5722
5810
  vertices.pop();
5723
5811
  }
5724
5812
  }
5813
+ const rd = this.getRectangleDifferences(annotationPtr);
5725
5814
  return {
5726
5815
  pageIndex: page.index,
5727
5816
  id: index,
@@ -5734,6 +5823,14 @@ class PdfiumNative {
5734
5823
  strokeStyle,
5735
5824
  strokeDashArray,
5736
5825
  vertices,
5826
+ ...rd.ok && {
5827
+ rectangleDifferences: {
5828
+ left: rd.left,
5829
+ top: rd.top,
5830
+ right: rd.right,
5831
+ bottom: rd.bottom
5832
+ }
5833
+ },
5737
5834
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5738
5835
  };
5739
5836
  }
@@ -5960,11 +6057,26 @@ class PdfiumNative {
5960
6057
  readPdfCaretAnno(doc, page, annotationPtr, index) {
5961
6058
  const pageRect = this.readPageAnnoRect(annotationPtr);
5962
6059
  const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
6060
+ const strokeColor = this.getAnnotationColor(annotationPtr);
6061
+ const opacity = this.getAnnotationOpacity(annotationPtr);
6062
+ const intent = this.getAnnotIntent(annotationPtr);
6063
+ const rd = this.getRectangleDifferences(annotationPtr);
5963
6064
  return {
5964
6065
  pageIndex: page.index,
5965
6066
  id: index,
5966
6067
  type: PdfAnnotationSubtype.CARET,
5967
6068
  rect,
6069
+ strokeColor,
6070
+ opacity,
6071
+ intent,
6072
+ ...rd.ok && {
6073
+ rectangleDifferences: {
6074
+ left: rd.left,
6075
+ top: rd.top,
6076
+ right: rd.right,
6077
+ bottom: rd.bottom
6078
+ }
6079
+ },
5968
6080
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5969
6081
  };
5970
6082
  }
@@ -6280,6 +6392,7 @@ class PdfiumNative {
6280
6392
  strokeDashArray = pattern;
6281
6393
  }
6282
6394
  }
6395
+ const rd = this.getRectangleDifferences(annotationPtr);
6283
6396
  return {
6284
6397
  pageIndex: page.index,
6285
6398
  id: index,
@@ -6291,6 +6404,14 @@ class PdfiumNative {
6291
6404
  strokeColor: strokeColor ?? "#FF0000",
6292
6405
  strokeStyle,
6293
6406
  ...strokeDashArray !== void 0 && { strokeDashArray },
6407
+ ...rd.ok && {
6408
+ rectangleDifferences: {
6409
+ left: rd.left,
6410
+ top: rd.top,
6411
+ right: rd.right,
6412
+ bottom: rd.bottom
6413
+ }
6414
+ },
6294
6415
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6295
6416
  };
6296
6417
  }
@@ -6320,6 +6441,7 @@ class PdfiumNative {
6320
6441
  strokeDashArray = pattern;
6321
6442
  }
6322
6443
  }
6444
+ const rd = this.getRectangleDifferences(annotationPtr);
6323
6445
  return {
6324
6446
  pageIndex: page.index,
6325
6447
  id: index,
@@ -6331,6 +6453,14 @@ class PdfiumNative {
6331
6453
  strokeWidth,
6332
6454
  strokeStyle,
6333
6455
  ...strokeDashArray !== void 0 && { strokeDashArray },
6456
+ ...rd.ok && {
6457
+ rectangleDifferences: {
6458
+ left: rd.left,
6459
+ top: rd.top,
6460
+ right: rd.right,
6461
+ bottom: rd.bottom
6462
+ }
6463
+ },
6334
6464
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6335
6465
  };
6336
6466
  }
@@ -6367,7 +6497,13 @@ class PdfiumNative {
6367
6497
  getInReplyToId(annotationPtr) {
6368
6498
  const parentPtr = this.pdfiumModule.FPDFAnnot_GetLinkedAnnot(annotationPtr, "IRT");
6369
6499
  if (!parentPtr) return;
6370
- return this.getAnnotString(parentPtr, "NM");
6500
+ let nm = this.getAnnotString(parentPtr, "NM");
6501
+ if (!nm || !isUuidV4(nm)) {
6502
+ nm = uuidV4();
6503
+ this.setAnnotString(parentPtr, "NM", nm);
6504
+ }
6505
+ this.pdfiumModule.FPDFPage_CloseAnnot(parentPtr);
6506
+ return nm;
6371
6507
  }
6372
6508
  /**
6373
6509
  * Set the in reply to id of the annotation
@@ -8412,4 +8548,4 @@ export {
8412
8548
  isValidCustomKey as i,
8413
8549
  readArrayBuffer as r
8414
8550
  };
8415
- //# sourceMappingURL=direct-engine-BfstxIRP.js.map
8551
+ //# sourceMappingURL=direct-engine-BOkKwXM0.js.map