@embedpdf/engines 2.2.0 → 2.3.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, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
2
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
3
  import { P as PdfEngine } from "./pdf-engine-ChjNHvQd.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-awZxztMA.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
@@ -1595,6 +1595,9 @@ class PdfiumNative {
1595
1595
  case PdfAnnotationSubtype.HIGHLIGHT:
1596
1596
  isSucceed = this.addTextMarkupContent(page, pageCtx.pagePtr, annotationPtr, annotation);
1597
1597
  break;
1598
+ case PdfAnnotationSubtype.LINK:
1599
+ isSucceed = this.addLinkContent(ctx.docPtr, pageCtx.pagePtr, annotationPtr, annotation);
1600
+ break;
1598
1601
  }
1599
1602
  if (!isSucceed) {
1600
1603
  this.pdfiumModule.FPDFPage_RemoveAnnot(pageCtx.pagePtr, annotationPtr);
@@ -1735,6 +1738,11 @@ class PdfiumNative {
1735
1738
  ok = this.addTextMarkupContent(page, pageCtx.pagePtr, annotPtr, annotation);
1736
1739
  break;
1737
1740
  }
1741
+ /* ── Link ─────────────────────────────────────────────────────────────── */
1742
+ case PdfAnnotationSubtype.LINK: {
1743
+ ok = this.addLinkContent(ctx.docPtr, pageCtx.pagePtr, annotPtr, annotation);
1744
+ break;
1745
+ }
1738
1746
  /* ── Unsupported edits – fall through to error ───────────────────────── */
1739
1747
  default:
1740
1748
  ok = false;
@@ -2717,37 +2725,21 @@ class PdfiumNative {
2717
2725
  * @private
2718
2726
  */
2719
2727
  addTextContent(page, pagePtr, annotationPtr, annotation) {
2720
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2721
- return false;
2722
- }
2723
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2724
- return false;
2725
- }
2726
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2727
- return false;
2728
- }
2729
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2730
- return false;
2731
- }
2732
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2733
- return false;
2734
- }
2735
- if (annotation.inReplyToId && !this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
2736
- return false;
2737
- }
2738
2728
  if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {
2739
2729
  return false;
2740
2730
  }
2741
- if (!this.setAnnotationFlags(annotationPtr, annotation.flags || ["print", "noZoom", "noRotate"])) {
2742
- return false;
2743
- }
2744
2731
  if (annotation.state && !this.setAnnotString(annotationPtr, "State", annotation.state)) {
2745
2732
  return false;
2746
2733
  }
2747
2734
  if (annotation.stateModel && !this.setAnnotString(annotationPtr, "StateModel", annotation.stateModel)) {
2748
2735
  return false;
2749
2736
  }
2750
- return true;
2737
+ if (!annotation.flags) {
2738
+ if (!this.setAnnotationFlags(annotationPtr, ["print", "noZoom", "noRotate"])) {
2739
+ return false;
2740
+ }
2741
+ }
2742
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2751
2743
  }
2752
2744
  /**
2753
2745
  * Add free text content to annotation
@@ -2760,27 +2752,9 @@ class PdfiumNative {
2760
2752
  * @private
2761
2753
  */
2762
2754
  addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
2763
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2764
- return false;
2765
- }
2766
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2767
- return false;
2768
- }
2769
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2770
- return false;
2771
- }
2772
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2773
- return false;
2774
- }
2775
2755
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
2776
2756
  return false;
2777
2757
  }
2778
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2779
- return false;
2780
- }
2781
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2782
- return false;
2783
- }
2784
2758
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2785
2759
  return false;
2786
2760
  }
@@ -2801,18 +2775,15 @@ class PdfiumNative {
2801
2775
  if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2802
2776
  return false;
2803
2777
  }
2804
- if (!annotation.backgroundColor || annotation.backgroundColor === "transparent") {
2778
+ const bgColor = annotation.color ?? annotation.backgroundColor;
2779
+ if (!bgColor || bgColor === "transparent") {
2805
2780
  if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
2806
2781
  return false;
2807
2782
  }
2808
- } else if (!this.setAnnotationColor(
2809
- annotationPtr,
2810
- annotation.backgroundColor ?? "#FFFFFF",
2811
- PdfAnnotationColorType.Color
2812
- )) {
2783
+ } else if (!this.setAnnotationColor(annotationPtr, bgColor ?? "#FFFFFF", PdfAnnotationColorType.Color)) {
2813
2784
  return false;
2814
2785
  }
2815
- return true;
2786
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2816
2787
  }
2817
2788
  /**
2818
2789
  * Set the rect of specified annotation
@@ -2825,41 +2796,20 @@ class PdfiumNative {
2825
2796
  * @private
2826
2797
  */
2827
2798
  addInkStroke(page, pagePtr, annotationPtr, annotation) {
2828
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2829
- return false;
2830
- }
2831
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2832
- return false;
2833
- }
2834
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2835
- return false;
2836
- }
2837
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2838
- return false;
2839
- }
2840
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2841
- return false;
2842
- }
2843
2799
  if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)) {
2844
2800
  return false;
2845
2801
  }
2846
2802
  if (!this.setInkList(page, annotationPtr, annotation.inkList)) {
2847
2803
  return false;
2848
2804
  }
2849
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2850
- return false;
2851
- }
2852
2805
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2853
2806
  return false;
2854
2807
  }
2855
- if (!this.setAnnotationColor(
2856
- annotationPtr,
2857
- annotation.color ?? "#FFFF00",
2858
- PdfAnnotationColorType.Color
2859
- )) {
2808
+ const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
2809
+ if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
2860
2810
  return false;
2861
2811
  }
2862
- return true;
2812
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2863
2813
  }
2864
2814
  /**
2865
2815
  * Add line content to annotation
@@ -2873,18 +2823,6 @@ class PdfiumNative {
2873
2823
  */
2874
2824
  addLineContent(page, pagePtr, annotationPtr, annotation) {
2875
2825
  var _a, _b;
2876
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2877
- return false;
2878
- }
2879
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2880
- return false;
2881
- }
2882
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2883
- return false;
2884
- }
2885
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2886
- return false;
2887
- }
2888
2826
  if (!this.setLinePoints(
2889
2827
  page,
2890
2828
  annotationPtr,
@@ -2900,12 +2838,6 @@ class PdfiumNative {
2900
2838
  )) {
2901
2839
  return false;
2902
2840
  }
2903
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2904
- return false;
2905
- }
2906
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2907
- return false;
2908
- }
2909
2841
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2910
2842
  return false;
2911
2843
  }
@@ -2936,7 +2868,7 @@ class PdfiumNative {
2936
2868
  )) {
2937
2869
  return false;
2938
2870
  }
2939
- return true;
2871
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2940
2872
  }
2941
2873
  /**
2942
2874
  * Add polygon or polyline content to annotation
@@ -2950,18 +2882,6 @@ class PdfiumNative {
2950
2882
  */
2951
2883
  addPolyContent(page, pagePtr, annotationPtr, annotation) {
2952
2884
  var _a, _b;
2953
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
2954
- return false;
2955
- }
2956
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
2957
- return false;
2958
- }
2959
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
2960
- return false;
2961
- }
2962
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2963
- return false;
2964
- }
2965
2885
  if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
2966
2886
  annotationPtr,
2967
2887
  ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
@@ -2972,12 +2892,6 @@ class PdfiumNative {
2972
2892
  if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
2973
2893
  return false;
2974
2894
  }
2975
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2976
- return false;
2977
- }
2978
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2979
- return false;
2980
- }
2981
2895
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2982
2896
  return false;
2983
2897
  }
@@ -3008,7 +2922,42 @@ class PdfiumNative {
3008
2922
  )) {
3009
2923
  return false;
3010
2924
  }
3011
- return true;
2925
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
2926
+ }
2927
+ /**
2928
+ * Add link content (action or destination) to a link annotation
2929
+ * @param docPtr - pointer to pdf document
2930
+ * @param pagePtr - pointer to the page
2931
+ * @param annotationPtr - pointer to pdf annotation
2932
+ * @param annotation - the link annotation object
2933
+ * @returns true if successful
2934
+ *
2935
+ * @private
2936
+ */
2937
+ addLinkContent(docPtr, pagePtr, annotationPtr, annotation) {
2938
+ const style = annotation.strokeStyle ?? PdfAnnotationBorderStyle.UNDERLINE;
2939
+ const width = annotation.strokeWidth ?? 2;
2940
+ if (!this.setBorderStyle(annotationPtr, style, width)) {
2941
+ return false;
2942
+ }
2943
+ if (annotation.strokeDashArray && !this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray)) {
2944
+ return false;
2945
+ }
2946
+ if (annotation.strokeColor) {
2947
+ if (!this.setAnnotationColor(
2948
+ annotationPtr,
2949
+ annotation.strokeColor,
2950
+ PdfAnnotationColorType.Color
2951
+ )) {
2952
+ return false;
2953
+ }
2954
+ }
2955
+ if (annotation.target) {
2956
+ if (!this.applyLinkTarget(docPtr, annotationPtr, annotation.target)) {
2957
+ return false;
2958
+ }
2959
+ }
2960
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3012
2961
  }
3013
2962
  /**
3014
2963
  * Add shape content to annotation
@@ -3021,30 +2970,12 @@ class PdfiumNative {
3021
2970
  * @private
3022
2971
  */
3023
2972
  addShapeContent(page, pagePtr, annotationPtr, annotation) {
3024
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3025
- return false;
3026
- }
3027
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3028
- return false;
3029
- }
3030
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3031
- return false;
3032
- }
3033
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3034
- return false;
3035
- }
3036
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3037
- return false;
3038
- }
3039
2973
  if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
3040
2974
  return false;
3041
2975
  }
3042
2976
  if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
3043
2977
  return false;
3044
2978
  }
3045
- if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3046
- return false;
3047
- }
3048
2979
  if (!annotation.color || annotation.color === "transparent") {
3049
2980
  if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
3050
2981
  return false;
@@ -3066,7 +2997,7 @@ class PdfiumNative {
3066
2997
  )) {
3067
2998
  return false;
3068
2999
  }
3069
- return true;
3000
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3070
3001
  }
3071
3002
  /**
3072
3003
  * Add highlight content to annotation
@@ -3078,38 +3009,17 @@ class PdfiumNative {
3078
3009
  * @private
3079
3010
  */
3080
3011
  addTextMarkupContent(page, pagePtr, annotationPtr, annotation) {
3081
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3082
- return false;
3083
- }
3084
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3085
- return false;
3086
- }
3087
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3088
- return false;
3089
- }
3090
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3091
- return false;
3092
- }
3093
3012
  if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
3094
3013
  return false;
3095
3014
  }
3096
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3097
- return false;
3098
- }
3099
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3100
- return false;
3101
- }
3102
3015
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
3103
3016
  return false;
3104
3017
  }
3105
- if (!this.setAnnotationColor(
3106
- annotationPtr,
3107
- annotation.color ?? "#FFFF00",
3108
- PdfAnnotationColorType.Color
3109
- )) {
3018
+ const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
3019
+ if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
3110
3020
  return false;
3111
3021
  }
3112
- return true;
3022
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3113
3023
  }
3114
3024
  /**
3115
3025
  * Add contents to stamp annotation
@@ -3124,30 +3034,12 @@ class PdfiumNative {
3124
3034
  * @private
3125
3035
  */
3126
3036
  addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
3127
- if (annotation.created && !this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
3128
- return false;
3129
- }
3130
- if (annotation.custom && !this.setAnnotCustom(annotationPtr, annotation.custom)) {
3131
- return false;
3132
- }
3133
- if (annotation.flags && !this.setAnnotationFlags(annotationPtr, annotation.flags)) {
3134
- return false;
3135
- }
3136
- if (annotation.modified && !this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
3137
- return false;
3138
- }
3139
3037
  if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {
3140
3038
  return false;
3141
3039
  }
3142
- if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
3143
- return false;
3144
- }
3145
3040
  if (annotation.subject && !this.setAnnotString(annotationPtr, "Subj", annotation.subject)) {
3146
3041
  return false;
3147
3042
  }
3148
- if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
3149
- return false;
3150
- }
3151
3043
  if (imageData) {
3152
3044
  for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
3153
3045
  this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
@@ -3159,7 +3051,7 @@ class PdfiumNative {
3159
3051
  if (!this.pdfiumModule.EPDFAnnot_UpdateAppearanceToRect(annotationPtr, PdfStampFit.Cover)) {
3160
3052
  return false;
3161
3053
  }
3162
- return true;
3054
+ return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
3163
3055
  }
3164
3056
  /**
3165
3057
  * Add image object to annotation
@@ -4290,6 +4182,28 @@ class PdfiumNative {
4290
4182
  setAnnotationIcon(annotationPtr, icon) {
4291
4183
  return this.pdfiumModule.EPDFAnnot_SetIcon(annotationPtr, icon);
4292
4184
  }
4185
+ /**
4186
+ * Get the reply type of the annotation (RT property per ISO 32000-2)
4187
+ *
4188
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
4189
+ * @returns `PdfAnnotationReplyType`
4190
+ */
4191
+ getReplyType(annotationPtr) {
4192
+ return this.pdfiumModule.EPDFAnnot_GetReplyType(annotationPtr);
4193
+ }
4194
+ /**
4195
+ * Set the reply type of the annotation (RT property per ISO 32000-2)
4196
+ *
4197
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
4198
+ * @param replyType - `PdfAnnotationReplyType`
4199
+ * @returns `true` on success
4200
+ */
4201
+ setReplyType(annotationPtr, replyType) {
4202
+ return this.pdfiumModule.EPDFAnnot_SetReplyType(
4203
+ annotationPtr,
4204
+ replyType ?? PdfAnnotationReplyType.Unknown
4205
+ );
4206
+ }
4293
4207
  /**
4294
4208
  * Border-effect (“cloudy”) helper
4295
4209
  *
@@ -4774,37 +4688,24 @@ class PdfiumNative {
4774
4688
  * @private
4775
4689
  */
4776
4690
  readPdfTextAnno(page, annotationPtr, index) {
4777
- const custom = this.getAnnotCustom(annotationPtr);
4778
4691
  const annoRect = this.readPageAnnoRect(annotationPtr);
4779
4692
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4780
- const author = this.getAnnotString(annotationPtr, "T");
4781
- const modified = this.getAnnotationDate(annotationPtr, "M");
4782
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4783
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4784
4693
  const state = this.getAnnotString(annotationPtr, "State");
4785
4694
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
4786
4695
  const color = this.getAnnotationColor(annotationPtr);
4787
4696
  const opacity = this.getAnnotationOpacity(annotationPtr);
4788
- const inReplyToId = this.getInReplyToId(annotationPtr);
4789
- const flags = this.getAnnotationFlags(annotationPtr);
4790
4697
  const icon = this.getAnnotationIcon(annotationPtr);
4791
4698
  return {
4792
4699
  pageIndex: page.index,
4793
- custom,
4794
4700
  id: index,
4795
4701
  type: PdfAnnotationSubtype.TEXT,
4796
- flags,
4797
- contents,
4702
+ rect,
4798
4703
  color: color ?? "#FFFF00",
4799
4704
  opacity,
4800
- rect,
4801
- inReplyToId,
4802
- author,
4803
- modified,
4804
- created,
4805
4705
  state,
4806
4706
  stateModel,
4807
- icon
4707
+ icon,
4708
+ ...this.readBaseAnnotationProperties(annotationPtr)
4808
4709
  };
4809
4710
  }
4810
4711
  /**
@@ -4817,41 +4718,33 @@ class PdfiumNative {
4817
4718
  * @private
4818
4719
  */
4819
4720
  readPdfFreeTextAnno(page, annotationPtr, index) {
4820
- const custom = this.getAnnotCustom(annotationPtr);
4821
4721
  const annoRect = this.readPageAnnoRect(annotationPtr);
4822
4722
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4823
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4824
- const author = this.getAnnotString(annotationPtr, "T");
4825
- const modified = this.getAnnotationDate(annotationPtr, "M");
4826
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4827
4723
  const defaultStyle = this.getAnnotString(annotationPtr, "DS");
4828
4724
  const da = this.getAnnotationDefaultAppearance(annotationPtr);
4829
- const backgroundColor = this.getAnnotationColor(annotationPtr);
4725
+ const bgColor = this.getAnnotationColor(annotationPtr);
4830
4726
  const textAlign = this.getAnnotationTextAlignment(annotationPtr);
4831
4727
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
4832
4728
  const opacity = this.getAnnotationOpacity(annotationPtr);
4833
4729
  const richContent = this.getAnnotRichContent(annotationPtr);
4834
- const flags = this.getAnnotationFlags(annotationPtr);
4835
4730
  return {
4836
4731
  pageIndex: page.index,
4837
- custom,
4838
4732
  id: index,
4839
4733
  type: PdfAnnotationSubtype.FREETEXT,
4734
+ rect,
4840
4735
  fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
4841
4736
  fontSize: (da == null ? void 0 : da.fontSize) ?? 12,
4842
4737
  fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
4843
4738
  verticalAlign,
4844
- backgroundColor,
4845
- flags,
4739
+ color: bgColor,
4740
+ // fill color (matches shape convention)
4741
+ backgroundColor: bgColor,
4742
+ // deprecated alias
4846
4743
  opacity,
4847
4744
  textAlign,
4848
4745
  defaultStyle,
4849
4746
  richContent,
4850
- contents,
4851
- author,
4852
- modified,
4853
- created,
4854
- rect
4747
+ ...this.readBaseAnnotationProperties(annotationPtr)
4855
4748
  };
4856
4749
  }
4857
4750
  /**
@@ -4865,17 +4758,21 @@ class PdfiumNative {
4865
4758
  * @private
4866
4759
  */
4867
4760
  readPdfLinkAnno(page, docPtr, annotationPtr, index) {
4868
- const custom = this.getAnnotCustom(annotationPtr);
4869
4761
  const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);
4870
4762
  if (!linkPtr) {
4871
4763
  return;
4872
4764
  }
4873
4765
  const annoRect = this.readPageAnnoRect(annotationPtr);
4874
4766
  const rect = this.convertPageRectToDeviceRect(page, annoRect);
4875
- const author = this.getAnnotString(annotationPtr, "T");
4876
- const modified = this.getAnnotationDate(annotationPtr, "M");
4877
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4878
- const flags = this.getAnnotationFlags(annotationPtr);
4767
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4768
+ const strokeColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.Color);
4769
+ let strokeDashArray;
4770
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
4771
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
4772
+ if (ok) {
4773
+ strokeDashArray = pattern;
4774
+ }
4775
+ }
4879
4776
  const target = this.readPdfLinkAnnoTarget(
4880
4777
  docPtr,
4881
4778
  () => {
@@ -4887,15 +4784,15 @@ class PdfiumNative {
4887
4784
  );
4888
4785
  return {
4889
4786
  pageIndex: page.index,
4890
- custom,
4891
4787
  id: index,
4892
4788
  type: PdfAnnotationSubtype.LINK,
4893
- flags,
4894
- target,
4895
4789
  rect,
4896
- author,
4897
- modified,
4898
- created
4790
+ target,
4791
+ strokeColor,
4792
+ strokeWidth,
4793
+ strokeStyle,
4794
+ strokeDashArray,
4795
+ ...this.readBaseAnnotationProperties(annotationPtr)
4899
4796
  };
4900
4797
  }
4901
4798
  /**
@@ -4909,25 +4806,16 @@ class PdfiumNative {
4909
4806
  * @private
4910
4807
  */
4911
4808
  readPdfWidgetAnno(page, annotationPtr, formHandle, index) {
4912
- const custom = this.getAnnotCustom(annotationPtr);
4913
4809
  const pageRect = this.readPageAnnoRect(annotationPtr);
4914
4810
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4915
- const author = this.getAnnotString(annotationPtr, "T");
4916
- const modified = this.getAnnotationDate(annotationPtr, "M");
4917
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4918
- const flags = this.getAnnotationFlags(annotationPtr);
4919
4811
  const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
4920
4812
  return {
4921
4813
  pageIndex: page.index,
4922
- custom,
4923
4814
  id: index,
4924
4815
  type: PdfAnnotationSubtype.WIDGET,
4925
- flags,
4926
4816
  rect,
4927
4817
  field,
4928
- author,
4929
- modified,
4930
- created
4818
+ ...this.readBaseAnnotationProperties(annotationPtr)
4931
4819
  };
4932
4820
  }
4933
4821
  /**
@@ -4940,23 +4828,14 @@ class PdfiumNative {
4940
4828
  * @private
4941
4829
  */
4942
4830
  readPdfFileAttachmentAnno(page, annotationPtr, index) {
4943
- const custom = this.getAnnotCustom(annotationPtr);
4944
4831
  const pageRect = this.readPageAnnoRect(annotationPtr);
4945
4832
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4946
- const author = this.getAnnotString(annotationPtr, "T");
4947
- const modified = this.getAnnotationDate(annotationPtr, "M");
4948
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4949
- const flags = this.getAnnotationFlags(annotationPtr);
4950
4833
  return {
4951
4834
  pageIndex: page.index,
4952
- custom,
4953
4835
  id: index,
4954
4836
  type: PdfAnnotationSubtype.FILEATTACHMENT,
4955
- flags,
4956
4837
  rect,
4957
- author,
4958
- modified,
4959
- created
4838
+ ...this.readBaseAnnotationProperties(annotationPtr)
4960
4839
  };
4961
4840
  }
4962
4841
  /**
@@ -4969,37 +4848,28 @@ class PdfiumNative {
4969
4848
  * @private
4970
4849
  */
4971
4850
  readPdfInkAnno(page, annotationPtr, index) {
4972
- const custom = this.getAnnotCustom(annotationPtr);
4973
4851
  const pageRect = this.readPageAnnoRect(annotationPtr);
4974
4852
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
4975
- const author = this.getAnnotString(annotationPtr, "T");
4976
- const modified = this.getAnnotationDate(annotationPtr, "M");
4977
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4978
- const color = this.getAnnotationColor(annotationPtr);
4853
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
4979
4854
  const opacity = this.getAnnotationOpacity(annotationPtr);
4980
4855
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
4981
4856
  const inkList = this.getInkList(page, annotationPtr);
4982
4857
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4983
4858
  const intent = this.getAnnotIntent(annotationPtr);
4984
- const flags = this.getAnnotationFlags(annotationPtr);
4985
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4986
4859
  return {
4987
4860
  pageIndex: page.index,
4988
- custom,
4989
4861
  id: index,
4990
4862
  type: PdfAnnotationSubtype.INK,
4863
+ rect,
4991
4864
  ...intent && { intent },
4992
- contents,
4993
4865
  blendMode,
4994
- flags,
4995
- color: color ?? "#FF0000",
4866
+ strokeColor,
4867
+ color: strokeColor,
4868
+ // deprecated alias
4996
4869
  opacity,
4997
4870
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
4998
- rect,
4999
4871
  inkList,
5000
- author,
5001
- modified,
5002
- created
4872
+ ...this.readBaseAnnotationProperties(annotationPtr)
5003
4873
  };
5004
4874
  }
5005
4875
  /**
@@ -5012,22 +4882,16 @@ class PdfiumNative {
5012
4882
  * @private
5013
4883
  */
5014
4884
  readPdfPolygonAnno(page, annotationPtr, index) {
5015
- const custom = this.getAnnotCustom(annotationPtr);
5016
4885
  const pageRect = this.readPageAnnoRect(annotationPtr);
5017
4886
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5018
- const author = this.getAnnotString(annotationPtr, "T");
5019
- const modified = this.getAnnotationDate(annotationPtr, "M");
5020
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5021
4887
  const vertices = this.readPdfAnnoVertices(page, annotationPtr);
5022
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5023
- const flags = this.getAnnotationFlags(annotationPtr);
5024
4888
  const strokeColor = this.getAnnotationColor(annotationPtr);
5025
4889
  const interiorColor = this.getAnnotationColor(
5026
4890
  annotationPtr,
5027
4891
  PdfAnnotationColorType.InteriorColor
5028
4892
  );
5029
4893
  const opacity = this.getAnnotationOpacity(annotationPtr);
5030
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4894
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5031
4895
  let strokeDashArray;
5032
4896
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5033
4897
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5044,22 +4908,17 @@ class PdfiumNative {
5044
4908
  }
5045
4909
  return {
5046
4910
  pageIndex: page.index,
5047
- custom,
5048
4911
  id: index,
5049
4912
  type: PdfAnnotationSubtype.POLYGON,
5050
- contents,
5051
- flags,
4913
+ rect,
5052
4914
  strokeColor: strokeColor ?? "#FF0000",
5053
4915
  color: interiorColor ?? "transparent",
5054
4916
  opacity,
5055
4917
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
5056
4918
  strokeStyle,
5057
4919
  strokeDashArray,
5058
- rect,
5059
4920
  vertices,
5060
- author,
5061
- modified,
5062
- created
4921
+ ...this.readBaseAnnotationProperties(annotationPtr)
5063
4922
  };
5064
4923
  }
5065
4924
  /**
@@ -5072,22 +4931,16 @@ class PdfiumNative {
5072
4931
  * @private
5073
4932
  */
5074
4933
  readPdfPolylineAnno(page, annotationPtr, index) {
5075
- const custom = this.getAnnotCustom(annotationPtr);
5076
4934
  const pageRect = this.readPageAnnoRect(annotationPtr);
5077
4935
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5078
- const author = this.getAnnotString(annotationPtr, "T");
5079
- const modified = this.getAnnotationDate(annotationPtr, "M");
5080
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5081
4936
  const vertices = this.readPdfAnnoVertices(page, annotationPtr);
5082
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5083
4937
  const strokeColor = this.getAnnotationColor(annotationPtr);
5084
- const flags = this.getAnnotationFlags(annotationPtr);
5085
4938
  const interiorColor = this.getAnnotationColor(
5086
4939
  annotationPtr,
5087
4940
  PdfAnnotationColorType.InteriorColor
5088
4941
  );
5089
4942
  const opacity = this.getAnnotationOpacity(annotationPtr);
5090
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4943
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5091
4944
  let strokeDashArray;
5092
4945
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5093
4946
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5098,11 +4951,9 @@ class PdfiumNative {
5098
4951
  const lineEndings = this.getLineEndings(annotationPtr);
5099
4952
  return {
5100
4953
  pageIndex: page.index,
5101
- custom,
5102
4954
  id: index,
5103
4955
  type: PdfAnnotationSubtype.POLYLINE,
5104
- contents,
5105
- flags,
4956
+ rect,
5106
4957
  strokeColor: strokeColor ?? "#FF0000",
5107
4958
  color: interiorColor ?? "transparent",
5108
4959
  opacity,
@@ -5110,11 +4961,8 @@ class PdfiumNative {
5110
4961
  strokeStyle,
5111
4962
  strokeDashArray,
5112
4963
  lineEndings,
5113
- rect,
5114
4964
  vertices,
5115
- author,
5116
- modified,
5117
- created
4965
+ ...this.readBaseAnnotationProperties(annotationPtr)
5118
4966
  };
5119
4967
  }
5120
4968
  /**
@@ -5127,23 +4975,17 @@ class PdfiumNative {
5127
4975
  * @private
5128
4976
  */
5129
4977
  readPdfLineAnno(page, annotationPtr, index) {
5130
- const custom = this.getAnnotCustom(annotationPtr);
5131
4978
  const pageRect = this.readPageAnnoRect(annotationPtr);
5132
4979
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5133
- const author = this.getAnnotString(annotationPtr, "T");
5134
- const modified = this.getAnnotationDate(annotationPtr, "M");
5135
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5136
4980
  const linePoints = this.getLinePoints(page, annotationPtr);
5137
4981
  const lineEndings = this.getLineEndings(annotationPtr);
5138
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5139
4982
  const strokeColor = this.getAnnotationColor(annotationPtr);
5140
- const flags = this.getAnnotationFlags(annotationPtr);
5141
4983
  const interiorColor = this.getAnnotationColor(
5142
4984
  annotationPtr,
5143
4985
  PdfAnnotationColorType.InteriorColor
5144
4986
  );
5145
4987
  const opacity = this.getAnnotationOpacity(annotationPtr);
5146
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4988
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5147
4989
  let strokeDashArray;
5148
4990
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5149
4991
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5153,12 +4995,9 @@ class PdfiumNative {
5153
4995
  }
5154
4996
  return {
5155
4997
  pageIndex: page.index,
5156
- custom,
5157
4998
  id: index,
5158
4999
  type: PdfAnnotationSubtype.LINE,
5159
- flags,
5160
5000
  rect,
5161
- contents,
5162
5001
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
5163
5002
  strokeStyle,
5164
5003
  strokeDashArray,
@@ -5170,9 +5009,7 @@ class PdfiumNative {
5170
5009
  start: PdfAnnotationLineEnding.None,
5171
5010
  end: PdfAnnotationLineEnding.None
5172
5011
  },
5173
- author,
5174
- modified,
5175
- created
5012
+ ...this.readBaseAnnotationProperties(annotationPtr)
5176
5013
  };
5177
5014
  }
5178
5015
  /**
@@ -5185,33 +5022,24 @@ class PdfiumNative {
5185
5022
  * @private
5186
5023
  */
5187
5024
  readPdfHighlightAnno(page, annotationPtr, index) {
5188
- const custom = this.getAnnotCustom(annotationPtr);
5189
5025
  const pageRect = this.readPageAnnoRect(annotationPtr);
5190
5026
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5191
5027
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5192
- const color = this.getAnnotationColor(annotationPtr);
5028
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FFFF00";
5193
5029
  const opacity = this.getAnnotationOpacity(annotationPtr);
5194
5030
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5195
- const author = this.getAnnotString(annotationPtr, "T");
5196
- const modified = this.getAnnotationDate(annotationPtr, "M");
5197
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5198
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5199
- const flags = this.getAnnotationFlags(annotationPtr);
5200
5031
  return {
5201
5032
  pageIndex: page.index,
5202
- custom,
5203
5033
  id: index,
5204
- blendMode,
5205
5034
  type: PdfAnnotationSubtype.HIGHLIGHT,
5206
5035
  rect,
5207
- flags,
5208
- contents,
5036
+ blendMode,
5209
5037
  segmentRects,
5210
- color: color ?? "#FFFF00",
5038
+ strokeColor,
5039
+ color: strokeColor,
5040
+ // deprecated alias
5211
5041
  opacity,
5212
- author,
5213
- modified,
5214
- created
5042
+ ...this.readBaseAnnotationProperties(annotationPtr)
5215
5043
  };
5216
5044
  }
5217
5045
  /**
@@ -5224,33 +5052,24 @@ class PdfiumNative {
5224
5052
  * @private
5225
5053
  */
5226
5054
  readPdfUnderlineAnno(page, annotationPtr, index) {
5227
- const custom = this.getAnnotCustom(annotationPtr);
5228
5055
  const pageRect = this.readPageAnnoRect(annotationPtr);
5229
5056
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5230
- const author = this.getAnnotString(annotationPtr, "T");
5231
- const modified = this.getAnnotationDate(annotationPtr, "M");
5232
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5233
5057
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5234
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5235
- const color = this.getAnnotationColor(annotationPtr);
5058
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5236
5059
  const opacity = this.getAnnotationOpacity(annotationPtr);
5237
5060
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5238
- const flags = this.getAnnotationFlags(annotationPtr);
5239
5061
  return {
5240
5062
  pageIndex: page.index,
5241
- custom,
5242
5063
  id: index,
5243
- blendMode,
5244
5064
  type: PdfAnnotationSubtype.UNDERLINE,
5245
5065
  rect,
5246
- flags,
5247
- contents,
5066
+ blendMode,
5248
5067
  segmentRects,
5249
- color: color ?? "#FF0000",
5068
+ strokeColor,
5069
+ color: strokeColor,
5070
+ // deprecated alias
5250
5071
  opacity,
5251
- author,
5252
- modified,
5253
- created
5072
+ ...this.readBaseAnnotationProperties(annotationPtr)
5254
5073
  };
5255
5074
  }
5256
5075
  /**
@@ -5263,33 +5082,24 @@ class PdfiumNative {
5263
5082
  * @private
5264
5083
  */
5265
5084
  readPdfStrikeOutAnno(page, annotationPtr, index) {
5266
- const custom = this.getAnnotCustom(annotationPtr);
5267
5085
  const pageRect = this.readPageAnnoRect(annotationPtr);
5268
5086
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5269
- const author = this.getAnnotString(annotationPtr, "T");
5270
- const modified = this.getAnnotationDate(annotationPtr, "M");
5271
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5272
5087
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5273
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5274
- const color = this.getAnnotationColor(annotationPtr);
5088
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5275
5089
  const opacity = this.getAnnotationOpacity(annotationPtr);
5276
5090
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5277
- const flags = this.getAnnotationFlags(annotationPtr);
5278
5091
  return {
5279
5092
  pageIndex: page.index,
5280
- custom,
5281
5093
  id: index,
5282
- blendMode,
5283
5094
  type: PdfAnnotationSubtype.STRIKEOUT,
5284
- flags,
5285
5095
  rect,
5286
- contents,
5096
+ blendMode,
5287
5097
  segmentRects,
5288
- color: color ?? "#FF0000",
5098
+ strokeColor,
5099
+ color: strokeColor,
5100
+ // deprecated alias
5289
5101
  opacity,
5290
- author,
5291
- modified,
5292
- created
5102
+ ...this.readBaseAnnotationProperties(annotationPtr)
5293
5103
  };
5294
5104
  }
5295
5105
  /**
@@ -5302,33 +5112,24 @@ class PdfiumNative {
5302
5112
  * @private
5303
5113
  */
5304
5114
  readPdfSquigglyAnno(page, annotationPtr, index) {
5305
- const custom = this.getAnnotCustom(annotationPtr);
5306
5115
  const pageRect = this.readPageAnnoRect(annotationPtr);
5307
5116
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5308
- const author = this.getAnnotString(annotationPtr, "T");
5309
- const modified = this.getAnnotationDate(annotationPtr, "M");
5310
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5311
5117
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
5312
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5313
- const color = this.getAnnotationColor(annotationPtr);
5118
+ const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
5314
5119
  const opacity = this.getAnnotationOpacity(annotationPtr);
5315
5120
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
5316
- const flags = this.getAnnotationFlags(annotationPtr);
5317
5121
  return {
5318
5122
  pageIndex: page.index,
5319
- custom,
5320
5123
  id: index,
5321
- blendMode,
5322
5124
  type: PdfAnnotationSubtype.SQUIGGLY,
5323
5125
  rect,
5324
- flags,
5325
- contents,
5126
+ blendMode,
5326
5127
  segmentRects,
5327
- color: color ?? "#FF0000",
5128
+ strokeColor,
5129
+ color: strokeColor,
5130
+ // deprecated alias
5328
5131
  opacity,
5329
- author,
5330
- modified,
5331
- created
5132
+ ...this.readBaseAnnotationProperties(annotationPtr)
5332
5133
  };
5333
5134
  }
5334
5135
  /**
@@ -5341,23 +5142,14 @@ class PdfiumNative {
5341
5142
  * @private
5342
5143
  */
5343
5144
  readPdfCaretAnno(page, annotationPtr, index) {
5344
- const custom = this.getAnnotCustom(annotationPtr);
5345
5145
  const pageRect = this.readPageAnnoRect(annotationPtr);
5346
5146
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5347
- const author = this.getAnnotString(annotationPtr, "T");
5348
- const modified = this.getAnnotationDate(annotationPtr, "M");
5349
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5350
- const flags = this.getAnnotationFlags(annotationPtr);
5351
5147
  return {
5352
5148
  pageIndex: page.index,
5353
- custom,
5354
5149
  id: index,
5355
5150
  type: PdfAnnotationSubtype.CARET,
5356
5151
  rect,
5357
- flags,
5358
- author,
5359
- modified,
5360
- created
5152
+ ...this.readBaseAnnotationProperties(annotationPtr)
5361
5153
  };
5362
5154
  }
5363
5155
  /**
@@ -5370,25 +5162,14 @@ class PdfiumNative {
5370
5162
  * @private
5371
5163
  */
5372
5164
  readPdfStampAnno(page, annotationPtr, index) {
5373
- const custom = this.getAnnotCustom(annotationPtr);
5374
5165
  const pageRect = this.readPageAnnoRect(annotationPtr);
5375
5166
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5376
- const author = this.getAnnotString(annotationPtr, "T");
5377
- const modified = this.getAnnotationDate(annotationPtr, "M");
5378
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5379
- const flags = this.getAnnotationFlags(annotationPtr);
5380
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5381
5167
  return {
5382
5168
  pageIndex: page.index,
5383
- custom,
5384
5169
  id: index,
5385
5170
  type: PdfAnnotationSubtype.STAMP,
5386
- contents,
5387
5171
  rect,
5388
- author,
5389
- modified,
5390
- created,
5391
- flags
5172
+ ...this.readBaseAnnotationProperties(annotationPtr)
5392
5173
  };
5393
5174
  }
5394
5175
  /**
@@ -5624,21 +5405,15 @@ class PdfiumNative {
5624
5405
  * @private
5625
5406
  */
5626
5407
  readPdfCircleAnno(page, annotationPtr, index) {
5627
- const custom = this.getAnnotCustom(annotationPtr);
5628
- const flags = this.getAnnotationFlags(annotationPtr);
5629
5408
  const pageRect = this.readPageAnnoRect(annotationPtr);
5630
5409
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5631
- const author = this.getAnnotString(annotationPtr, "T");
5632
- const modified = this.getAnnotationDate(annotationPtr, "M");
5633
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5634
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5635
5410
  const interiorColor = this.getAnnotationColor(
5636
5411
  annotationPtr,
5637
5412
  PdfAnnotationColorType.InteriorColor
5638
5413
  );
5639
5414
  const strokeColor = this.getAnnotationColor(annotationPtr);
5640
5415
  const opacity = this.getAnnotationOpacity(annotationPtr);
5641
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5416
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5642
5417
  let strokeDashArray;
5643
5418
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5644
5419
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5648,21 +5423,16 @@ class PdfiumNative {
5648
5423
  }
5649
5424
  return {
5650
5425
  pageIndex: page.index,
5651
- custom,
5652
5426
  id: index,
5653
5427
  type: PdfAnnotationSubtype.CIRCLE,
5654
- flags,
5428
+ rect,
5655
5429
  color: interiorColor ?? "transparent",
5656
5430
  opacity,
5657
- contents,
5658
5431
  strokeWidth,
5659
5432
  strokeColor: strokeColor ?? "#FF0000",
5660
5433
  strokeStyle,
5661
- rect,
5662
- author,
5663
- modified,
5664
- created,
5665
- ...strokeDashArray !== void 0 && { strokeDashArray }
5434
+ ...strokeDashArray !== void 0 && { strokeDashArray },
5435
+ ...this.readBaseAnnotationProperties(annotationPtr)
5666
5436
  };
5667
5437
  }
5668
5438
  /**
@@ -5675,21 +5445,15 @@ class PdfiumNative {
5675
5445
  * @private
5676
5446
  */
5677
5447
  readPdfSquareAnno(page, annotationPtr, index) {
5678
- const custom = this.getAnnotCustom(annotationPtr);
5679
- const flags = this.getAnnotationFlags(annotationPtr);
5680
5448
  const pageRect = this.readPageAnnoRect(annotationPtr);
5681
5449
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5682
- const author = this.getAnnotString(annotationPtr, "T");
5683
- const modified = this.getAnnotationDate(annotationPtr, "M");
5684
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5685
- const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5686
5450
  const interiorColor = this.getAnnotationColor(
5687
5451
  annotationPtr,
5688
5452
  PdfAnnotationColorType.InteriorColor
5689
5453
  );
5690
5454
  const strokeColor = this.getAnnotationColor(annotationPtr);
5691
5455
  const opacity = this.getAnnotationOpacity(annotationPtr);
5692
- let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5456
+ const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
5693
5457
  let strokeDashArray;
5694
5458
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
5695
5459
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -5699,21 +5463,16 @@ class PdfiumNative {
5699
5463
  }
5700
5464
  return {
5701
5465
  pageIndex: page.index,
5702
- custom,
5703
5466
  id: index,
5704
5467
  type: PdfAnnotationSubtype.SQUARE,
5705
- flags,
5468
+ rect,
5706
5469
  color: interiorColor ?? "transparent",
5707
5470
  opacity,
5708
- contents,
5709
5471
  strokeColor: strokeColor ?? "#FF0000",
5710
5472
  strokeWidth,
5711
5473
  strokeStyle,
5712
- rect,
5713
- author,
5714
- modified,
5715
- created,
5716
- ...strokeDashArray !== void 0 && { strokeDashArray }
5474
+ ...strokeDashArray !== void 0 && { strokeDashArray },
5475
+ ...this.readBaseAnnotationProperties(annotationPtr)
5717
5476
  };
5718
5477
  }
5719
5478
  /**
@@ -5727,23 +5486,14 @@ class PdfiumNative {
5727
5486
  * @private
5728
5487
  */
5729
5488
  readPdfAnno(page, type, annotationPtr, index) {
5730
- const custom = this.getAnnotCustom(annotationPtr);
5731
5489
  const pageRect = this.readPageAnnoRect(annotationPtr);
5732
5490
  const rect = this.convertPageRectToDeviceRect(page, pageRect);
5733
- const author = this.getAnnotString(annotationPtr, "T");
5734
- const modified = this.getAnnotationDate(annotationPtr, "M");
5735
- const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5736
- const flags = this.getAnnotationFlags(annotationPtr);
5737
5491
  return {
5738
5492
  pageIndex: page.index,
5739
- custom,
5740
5493
  id: index,
5741
- flags,
5742
5494
  type,
5743
5495
  rect,
5744
- author,
5745
- modified,
5746
- created
5496
+ ...this.readBaseAnnotationProperties(annotationPtr)
5747
5497
  };
5748
5498
  }
5749
5499
  /**
@@ -5768,10 +5518,86 @@ class PdfiumNative {
5768
5518
  * @returns `true` on success
5769
5519
  */
5770
5520
  setInReplyToId(pagePtr, annotationPtr, id) {
5521
+ if (!id) {
5522
+ return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", 0);
5523
+ }
5771
5524
  const parentPtr = this.getAnnotationByName(pagePtr, id);
5772
5525
  if (!parentPtr) return false;
5773
5526
  return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", parentPtr);
5774
5527
  }
5528
+ /**
5529
+ * Apply all base annotation properties from PdfAnnotationObjectBase.
5530
+ * The setInReplyToId and setReplyType functions handle clearing when undefined.
5531
+ *
5532
+ * @param pagePtr - pointer to page object
5533
+ * @param annotationPtr - pointer to annotation object
5534
+ * @param annotation - the annotation object containing properties to apply
5535
+ * @returns `true` on success
5536
+ */
5537
+ applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation) {
5538
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
5539
+ return false;
5540
+ }
5541
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
5542
+ return false;
5543
+ }
5544
+ if (annotation.modified) {
5545
+ if (!this.setAnnotationDate(annotationPtr, "M", annotation.modified)) {
5546
+ return false;
5547
+ }
5548
+ }
5549
+ if (annotation.created) {
5550
+ if (!this.setAnnotationDate(annotationPtr, "CreationDate", annotation.created)) {
5551
+ return false;
5552
+ }
5553
+ }
5554
+ if (annotation.flags) {
5555
+ if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
5556
+ return false;
5557
+ }
5558
+ }
5559
+ if (annotation.custom) {
5560
+ if (!this.setAnnotCustom(annotationPtr, annotation.custom)) {
5561
+ return false;
5562
+ }
5563
+ }
5564
+ if (!this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
5565
+ return false;
5566
+ }
5567
+ if (!this.setReplyType(annotationPtr, annotation.replyType)) {
5568
+ return false;
5569
+ }
5570
+ return true;
5571
+ }
5572
+ /**
5573
+ * Read all base annotation properties from PdfAnnotationObjectBase.
5574
+ * Returns an object that can be spread into the annotation return value.
5575
+ *
5576
+ * @param annotationPtr - pointer to annotation object
5577
+ * @returns object with base annotation properties
5578
+ */
5579
+ readBaseAnnotationProperties(annotationPtr) {
5580
+ const author = this.getAnnotString(annotationPtr, "T");
5581
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
5582
+ const modified = this.getAnnotationDate(annotationPtr, "M");
5583
+ const created = this.getAnnotationDate(annotationPtr, "CreationDate");
5584
+ const flags = this.getAnnotationFlags(annotationPtr);
5585
+ const custom = this.getAnnotCustom(annotationPtr);
5586
+ const inReplyToId = this.getInReplyToId(annotationPtr);
5587
+ const replyType = this.getReplyType(annotationPtr);
5588
+ return {
5589
+ author,
5590
+ contents,
5591
+ modified,
5592
+ created,
5593
+ flags,
5594
+ custom,
5595
+ // Only include IRT if present
5596
+ ...inReplyToId && { inReplyToId },
5597
+ // Only include RT if present and not the default (Reply)
5598
+ ...replyType && replyType !== PdfAnnotationReplyType.Reply && { replyType }
5599
+ };
5600
+ }
5775
5601
  /**
5776
5602
  * Fetch a string value (`/T`, `/M`, `/State`, …) from an annotation.
5777
5603
  *
@@ -6486,6 +6312,51 @@ class PdfiumNative {
6486
6312
  return false;
6487
6313
  }
6488
6314
  }
6315
+ /**
6316
+ * Apply a link target (action or destination) to a link annotation
6317
+ * @param docPtr - pointer to pdf document
6318
+ * @param annotationPtr - pointer to the link annotation
6319
+ * @param target - the link target to apply
6320
+ * @returns true if successful
6321
+ *
6322
+ * @private
6323
+ */
6324
+ applyLinkTarget(docPtr, annotationPtr, target) {
6325
+ if (target.type === "destination") {
6326
+ const destPtr = this.createLocalDestPtr(docPtr, target.destination);
6327
+ if (!destPtr) return false;
6328
+ const actPtr = this.pdfiumModule.EPDFAction_CreateGoTo(docPtr, destPtr);
6329
+ if (!actPtr) return false;
6330
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6331
+ }
6332
+ const action = target.action;
6333
+ switch (action.type) {
6334
+ case PdfActionType.Goto: {
6335
+ const destPtr = this.createLocalDestPtr(docPtr, action.destination);
6336
+ if (!destPtr) return false;
6337
+ const actPtr = this.pdfiumModule.EPDFAction_CreateGoTo(docPtr, destPtr);
6338
+ if (!actPtr) return false;
6339
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6340
+ }
6341
+ case PdfActionType.URI: {
6342
+ const actPtr = this.pdfiumModule.EPDFAction_CreateURI(docPtr, action.uri);
6343
+ if (!actPtr) return false;
6344
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6345
+ }
6346
+ case PdfActionType.LaunchAppOrOpenFile: {
6347
+ const actPtr = this.withWString(
6348
+ action.path,
6349
+ (wptr) => this.pdfiumModule.EPDFAction_CreateLaunch(docPtr, wptr)
6350
+ );
6351
+ if (!actPtr) return false;
6352
+ return !!this.pdfiumModule.EPDFAnnot_SetAction(annotationPtr, actPtr);
6353
+ }
6354
+ case PdfActionType.RemoteGoto:
6355
+ case PdfActionType.Unsupported:
6356
+ default:
6357
+ return false;
6358
+ }
6359
+ }
6489
6360
  /**
6490
6361
  * Read pdf action from pdf document
6491
6362
  * @param docPtr - pointer to pdf document object
@@ -7422,4 +7293,4 @@ export {
7422
7293
  isValidCustomKey as i,
7423
7294
  readString as r
7424
7295
  };
7425
- //# sourceMappingURL=direct-engine-DGRkMlJ8.js.map
7296
+ //# sourceMappingURL=direct-engine-nrX_KvVy.js.map