@embedpdf/engines 2.7.0 → 2.9.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,11 @@ class PdfiumNative {
3049
3101
  )) {
3050
3102
  return false;
3051
3103
  }
3104
+ if (annotation.type === PdfAnnotationSubtype.POLYGON) {
3105
+ const poly = annotation;
3106
+ this.setRectangleDifferences(annotationPtr, poly.rectangleDifferences);
3107
+ this.setBorderEffect(annotationPtr, poly.cloudyBorderIntensity);
3108
+ }
3052
3109
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
3053
3110
  }
3054
3111
  /**
@@ -3124,6 +3181,8 @@ class PdfiumNative {
3124
3181
  )) {
3125
3182
  return false;
3126
3183
  }
3184
+ this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
3185
+ this.setBorderEffect(annotationPtr, annotation.cloudyBorderIntensity);
3127
3186
  return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
3128
3187
  }
3129
3188
  /**
@@ -4939,6 +4998,38 @@ 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
+ }
5020
+ /**
5021
+ * Sets or clears the /BE (border effect) dictionary on an annotation.
5022
+ *
5023
+ * @param annotationPtr pointer to an `FPDF_ANNOTATION`
5024
+ * @param intensity cloudy border intensity, or `undefined` to clear
5025
+ * @returns `true` on success
5026
+ */
5027
+ setBorderEffect(annotationPtr, intensity) {
5028
+ if (intensity === void 0 || intensity <= 0) {
5029
+ return this.pdfiumModule.EPDFAnnot_ClearBorderEffect(annotationPtr);
5030
+ }
5031
+ return this.pdfiumModule.EPDFAnnot_SetBorderEffect(annotationPtr, intensity);
5032
+ }
4942
5033
  /**
4943
5034
  * Get the date of the annotation
4944
5035
  *
@@ -5516,6 +5607,7 @@ class PdfiumNative {
5516
5607
  id: index,
5517
5608
  type: PdfAnnotationSubtype.TEXT,
5518
5609
  rect,
5610
+ strokeColor: color ?? "#FFFF00",
5519
5611
  color: color ?? "#FFFF00",
5520
5612
  opacity,
5521
5613
  state,
@@ -5543,6 +5635,7 @@ class PdfiumNative {
5543
5635
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
5544
5636
  const opacity = this.getAnnotationOpacity(annotationPtr);
5545
5637
  const richContent = this.getAnnotRichContent(annotationPtr);
5638
+ const rd = this.getRectangleDifferences(annotationPtr);
5546
5639
  return {
5547
5640
  pageIndex: page.index,
5548
5641
  id: index,
@@ -5560,6 +5653,14 @@ class PdfiumNative {
5560
5653
  textAlign,
5561
5654
  defaultStyle,
5562
5655
  richContent,
5656
+ ...rd.ok && {
5657
+ rectangleDifferences: {
5658
+ left: rd.left,
5659
+ top: rd.top,
5660
+ right: rd.right,
5661
+ bottom: rd.bottom
5662
+ }
5663
+ },
5563
5664
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5564
5665
  };
5565
5666
  }
@@ -5670,7 +5771,6 @@ class PdfiumNative {
5670
5771
  const opacity = this.getAnnotationOpacity(annotationPtr);
5671
5772
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
5672
5773
  const inkList = this.getInkList(doc, page, annotationPtr);
5673
- const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5674
5774
  const intent = this.getAnnotIntent(annotationPtr);
5675
5775
  return {
5676
5776
  pageIndex: page.index,
@@ -5678,7 +5778,6 @@ class PdfiumNative {
5678
5778
  type: PdfAnnotationSubtype.INK,
5679
5779
  rect,
5680
5780
  ...intent && { intent },
5681
- blendMode,
5682
5781
  strokeColor,
5683
5782
  color: strokeColor,
5684
5783
  // deprecated alias
@@ -5722,6 +5821,8 @@ class PdfiumNative {
5722
5821
  vertices.pop();
5723
5822
  }
5724
5823
  }
5824
+ const rd = this.getRectangleDifferences(annotationPtr);
5825
+ const be = this.getBorderEffect(annotationPtr);
5725
5826
  return {
5726
5827
  pageIndex: page.index,
5727
5828
  id: index,
@@ -5734,6 +5835,15 @@ class PdfiumNative {
5734
5835
  strokeStyle,
5735
5836
  strokeDashArray,
5736
5837
  vertices,
5838
+ ...be.ok && { cloudyBorderIntensity: be.intensity },
5839
+ ...rd.ok && {
5840
+ rectangleDifferences: {
5841
+ left: rd.left,
5842
+ top: rd.top,
5843
+ right: rd.right,
5844
+ bottom: rd.bottom
5845
+ }
5846
+ },
5737
5847
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5738
5848
  };
5739
5849
  }
@@ -5843,13 +5953,11 @@ class PdfiumNative {
5843
5953
  const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
5844
5954
  const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FFFF00";
5845
5955
  const opacity = this.getAnnotationOpacity(annotationPtr);
5846
- const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5847
5956
  return {
5848
5957
  pageIndex: page.index,
5849
5958
  id: index,
5850
5959
  type: PdfAnnotationSubtype.HIGHLIGHT,
5851
5960
  rect,
5852
- blendMode,
5853
5961
  segmentRects,
5854
5962
  strokeColor,
5855
5963
  color: strokeColor,
@@ -5873,13 +5981,11 @@ class PdfiumNative {
5873
5981
  const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
5874
5982
  const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5875
5983
  const opacity = this.getAnnotationOpacity(annotationPtr);
5876
- const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5877
5984
  return {
5878
5985
  pageIndex: page.index,
5879
5986
  id: index,
5880
5987
  type: PdfAnnotationSubtype.UNDERLINE,
5881
5988
  rect,
5882
- blendMode,
5883
5989
  segmentRects,
5884
5990
  strokeColor,
5885
5991
  color: strokeColor,
@@ -5903,13 +6009,11 @@ class PdfiumNative {
5903
6009
  const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
5904
6010
  const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5905
6011
  const opacity = this.getAnnotationOpacity(annotationPtr);
5906
- const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5907
6012
  return {
5908
6013
  pageIndex: page.index,
5909
6014
  id: index,
5910
6015
  type: PdfAnnotationSubtype.STRIKEOUT,
5911
6016
  rect,
5912
- blendMode,
5913
6017
  segmentRects,
5914
6018
  strokeColor,
5915
6019
  color: strokeColor,
@@ -5933,13 +6037,11 @@ class PdfiumNative {
5933
6037
  const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
5934
6038
  const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5935
6039
  const opacity = this.getAnnotationOpacity(annotationPtr);
5936
- const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5937
6040
  return {
5938
6041
  pageIndex: page.index,
5939
6042
  id: index,
5940
6043
  type: PdfAnnotationSubtype.SQUIGGLY,
5941
6044
  rect,
5942
- blendMode,
5943
6045
  segmentRects,
5944
6046
  strokeColor,
5945
6047
  color: strokeColor,
@@ -5960,11 +6062,26 @@ class PdfiumNative {
5960
6062
  readPdfCaretAnno(doc, page, annotationPtr, index) {
5961
6063
  const pageRect = this.readPageAnnoRect(annotationPtr);
5962
6064
  const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
6065
+ const strokeColor = this.getAnnotationColor(annotationPtr);
6066
+ const opacity = this.getAnnotationOpacity(annotationPtr);
6067
+ const intent = this.getAnnotIntent(annotationPtr);
6068
+ const rd = this.getRectangleDifferences(annotationPtr);
5963
6069
  return {
5964
6070
  pageIndex: page.index,
5965
6071
  id: index,
5966
6072
  type: PdfAnnotationSubtype.CARET,
5967
6073
  rect,
6074
+ strokeColor,
6075
+ opacity,
6076
+ intent,
6077
+ ...rd.ok && {
6078
+ rectangleDifferences: {
6079
+ left: rd.left,
6080
+ top: rd.top,
6081
+ right: rd.right,
6082
+ bottom: rd.bottom
6083
+ }
6084
+ },
5968
6085
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
5969
6086
  };
5970
6087
  }
@@ -6280,6 +6397,8 @@ class PdfiumNative {
6280
6397
  strokeDashArray = pattern;
6281
6398
  }
6282
6399
  }
6400
+ const rd = this.getRectangleDifferences(annotationPtr);
6401
+ const be = this.getBorderEffect(annotationPtr);
6283
6402
  return {
6284
6403
  pageIndex: page.index,
6285
6404
  id: index,
@@ -6291,6 +6410,15 @@ class PdfiumNative {
6291
6410
  strokeColor: strokeColor ?? "#FF0000",
6292
6411
  strokeStyle,
6293
6412
  ...strokeDashArray !== void 0 && { strokeDashArray },
6413
+ ...be.ok && { cloudyBorderIntensity: be.intensity },
6414
+ ...rd.ok && {
6415
+ rectangleDifferences: {
6416
+ left: rd.left,
6417
+ top: rd.top,
6418
+ right: rd.right,
6419
+ bottom: rd.bottom
6420
+ }
6421
+ },
6294
6422
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6295
6423
  };
6296
6424
  }
@@ -6320,6 +6448,8 @@ class PdfiumNative {
6320
6448
  strokeDashArray = pattern;
6321
6449
  }
6322
6450
  }
6451
+ const rd = this.getRectangleDifferences(annotationPtr);
6452
+ const be = this.getBorderEffect(annotationPtr);
6323
6453
  return {
6324
6454
  pageIndex: page.index,
6325
6455
  id: index,
@@ -6331,6 +6461,15 @@ class PdfiumNative {
6331
6461
  strokeWidth,
6332
6462
  strokeStyle,
6333
6463
  ...strokeDashArray !== void 0 && { strokeDashArray },
6464
+ ...be.ok && { cloudyBorderIntensity: be.intensity },
6465
+ ...rd.ok && {
6466
+ rectangleDifferences: {
6467
+ left: rd.left,
6468
+ top: rd.top,
6469
+ right: rd.right,
6470
+ bottom: rd.bottom
6471
+ }
6472
+ },
6334
6473
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6335
6474
  };
6336
6475
  }
@@ -6367,7 +6506,13 @@ class PdfiumNative {
6367
6506
  getInReplyToId(annotationPtr) {
6368
6507
  const parentPtr = this.pdfiumModule.FPDFAnnot_GetLinkedAnnot(annotationPtr, "IRT");
6369
6508
  if (!parentPtr) return;
6370
- return this.getAnnotString(parentPtr, "NM");
6509
+ let nm = this.getAnnotString(parentPtr, "NM");
6510
+ if (!nm || !isUuidV4(nm)) {
6511
+ nm = uuidV4();
6512
+ this.setAnnotString(parentPtr, "NM", nm);
6513
+ }
6514
+ this.pdfiumModule.FPDFPage_CloseAnnot(parentPtr);
6515
+ return nm;
6371
6516
  }
6372
6517
  /**
6373
6518
  * Set the in reply to id of the annotation
@@ -6534,6 +6679,7 @@ class PdfiumNative {
6534
6679
  const custom = this.getAnnotCustom(annotationPtr);
6535
6680
  const inReplyToId = this.getInReplyToId(annotationPtr);
6536
6681
  const replyType = this.getReplyType(annotationPtr);
6682
+ const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
6537
6683
  const pdfRotation = this.getAnnotExtendedRotation(annotationPtr);
6538
6684
  const rotation = pdfRotation !== 0 ? (360 - pdfRotation) % 360 : 0;
6539
6685
  const rawUnrotatedRect = this.readAnnotUnrotatedRect(annotationPtr);
@@ -6545,6 +6691,7 @@ class PdfiumNative {
6545
6691
  created,
6546
6692
  flags,
6547
6693
  custom,
6694
+ blendMode,
6548
6695
  // Only include IRT if present
6549
6696
  ...inReplyToId && { inReplyToId },
6550
6697
  // Only include RT if present and not the default (Reply)
@@ -8412,4 +8559,4 @@ export {
8412
8559
  isValidCustomKey as i,
8413
8560
  readArrayBuffer as r
8414
8561
  };
8415
- //# sourceMappingURL=direct-engine-BfstxIRP.js.map
8562
+ //# sourceMappingURL=direct-engine-D-Jf9yyY.js.map