@embedpdf/engines 2.6.1 → 2.7.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.
Files changed (43) hide show
  1. package/dist/{direct-engine-BmntIHbH.js → direct-engine-BfstxIRP.js} +225 -11
  2. package/dist/direct-engine-BfstxIRP.js.map +1 -0
  3. package/dist/direct-engine-DzwAVTnQ.cjs +2 -0
  4. package/dist/direct-engine-DzwAVTnQ.cjs.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +8 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/orchestrator/pdf-engine.d.ts +10 -2
  10. package/dist/lib/orchestrator/remote-executor.d.ts +5 -2
  11. package/dist/lib/pdfium/engine.d.ts +19 -2
  12. package/dist/lib/pdfium/index.cjs +1 -1
  13. package/dist/lib/pdfium/index.js +3 -3
  14. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  15. package/dist/lib/pdfium/web/direct-engine.js +2 -2
  16. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  17. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  18. package/dist/lib/pdfium/web/worker-engine.js +7 -4
  19. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  20. package/dist/lib/webworker/engine.cjs +1 -1
  21. package/dist/lib/webworker/engine.cjs.map +1 -1
  22. package/dist/lib/webworker/engine.d.ts +6 -2
  23. package/dist/lib/webworker/engine.js +27 -2
  24. package/dist/lib/webworker/engine.js.map +1 -1
  25. package/dist/pdf-engine-DeyImjZt.cjs +2 -0
  26. package/dist/pdf-engine-DeyImjZt.cjs.map +1 -0
  27. package/dist/{pdf-engine-C07l7iNd.js → pdf-engine-ZvReuoDb.js} +84 -3
  28. package/dist/pdf-engine-ZvReuoDb.js.map +1 -0
  29. package/dist/preact/index.cjs +1 -1
  30. package/dist/preact/index.js +1 -1
  31. package/dist/react/index.cjs +1 -1
  32. package/dist/react/index.js +1 -1
  33. package/dist/svelte/index.cjs +1 -1
  34. package/dist/svelte/index.js +1 -1
  35. package/dist/vue/index.cjs +1 -1
  36. package/dist/vue/index.js +1 -1
  37. package/package.json +6 -6
  38. package/dist/direct-engine-BaKyNZkO.cjs +0 -2
  39. package/dist/direct-engine-BaKyNZkO.cjs.map +0 -1
  40. package/dist/direct-engine-BmntIHbH.js.map +0 -1
  41. package/dist/pdf-engine-C07l7iNd.js.map +0 -1
  42. package/dist/pdf-engine-DUjCt3HC.cjs +0 -2
  43. package/dist/pdf-engine-DUjCt3HC.cjs.map +0 -1
@@ -1,6 +1,6 @@
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, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
- import { P as PdfEngine } from "./pdf-engine-C07l7iNd.js";
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";
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) {
6
6
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
@@ -1704,7 +1704,7 @@ class PdfiumNative {
1704
1704
  *
1705
1705
  * @returns PdfTask<boolean> – true on success
1706
1706
  */
1707
- updatePageAnnotation(doc, page, annotation) {
1707
+ updatePageAnnotation(doc, page, annotation, options) {
1708
1708
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "updatePageAnnotation", doc, page, annotation);
1709
1709
  this.logger.perf(
1710
1710
  LOG_SOURCE,
@@ -1873,7 +1873,7 @@ class PdfiumNative {
1873
1873
  default:
1874
1874
  ok = false;
1875
1875
  }
1876
- if (ok) {
1876
+ if (ok && (options == null ? void 0 : options.regenerateAppearance) !== false) {
1877
1877
  if (annotation.blendMode !== void 0) {
1878
1878
  this.pdfiumModule.EPDFAnnot_GenerateAppearanceWithBlend(annotPtr, annotation.blendMode);
1879
1879
  } else {
@@ -3732,7 +3732,8 @@ class PdfiumNative {
3732
3732
  height: g.size.height
3733
3733
  },
3734
3734
  charStart: i,
3735
- glyphs: []
3735
+ glyphs: [],
3736
+ fontSize: this.pdfiumModule.FPDFText_GetFontSize(textPagePtr, i)
3736
3737
  };
3737
3738
  bounds = {
3738
3739
  minX: g.origin.x,
@@ -3747,7 +3748,9 @@ class PdfiumNative {
3747
3748
  y: g.origin.y,
3748
3749
  width: g.size.width,
3749
3750
  height: g.size.height,
3750
- flags: g.isEmpty ? 2 : g.isSpace ? 1 : 0
3751
+ flags: g.isEmpty ? 2 : g.isSpace ? 1 : 0,
3752
+ ...g.tightOrigin && { tightX: g.tightOrigin.x, tightY: g.tightOrigin.y },
3753
+ ...g.tightSize && { tightWidth: g.tightSize.width, tightHeight: g.tightSize.height }
3751
3754
  });
3752
3755
  if (g.isEmpty) {
3753
3756
  continue;
@@ -3959,14 +3962,31 @@ class PdfiumNative {
3959
3962
  const dx2Ptr = this.memoryManager.malloc(4);
3960
3963
  const dy2Ptr = this.memoryManager.malloc(4);
3961
3964
  const rectPtr = this.memoryManager.malloc(16);
3965
+ const tLeftPtr = this.memoryManager.malloc(8);
3966
+ const tRightPtr = this.memoryManager.malloc(8);
3967
+ const tBottomPtr = this.memoryManager.malloc(8);
3968
+ const tTopPtr = this.memoryManager.malloc(8);
3969
+ const allPtrs = [
3970
+ rectPtr,
3971
+ dx1Ptr,
3972
+ dy1Ptr,
3973
+ dx2Ptr,
3974
+ dy2Ptr,
3975
+ tLeftPtr,
3976
+ tRightPtr,
3977
+ tBottomPtr,
3978
+ tTopPtr
3979
+ ];
3962
3980
  let x = 0, y = 0, width = 0, height = 0, isSpace = false;
3981
+ let tightOrigin;
3982
+ let tightSize;
3963
3983
  if (this.pdfiumModule.FPDFText_GetLooseCharBox(textPagePtr, charIndex, rectPtr)) {
3964
3984
  const left = this.pdfiumModule.pdfium.getValue(rectPtr, "float");
3965
3985
  const top = this.pdfiumModule.pdfium.getValue(rectPtr + 4, "float");
3966
3986
  const right = this.pdfiumModule.pdfium.getValue(rectPtr + 8, "float");
3967
3987
  const bottom = this.pdfiumModule.pdfium.getValue(rectPtr + 12, "float");
3968
3988
  if (left === right || top === bottom) {
3969
- [rectPtr, dx1Ptr, dy1Ptr, dx2Ptr, dy2Ptr].forEach((p) => this.memoryManager.free(p));
3989
+ allPtrs.forEach((p) => this.memoryManager.free(p));
3970
3990
  return {
3971
3991
  origin: { x: 0, y: 0 },
3972
3992
  size: { width: 0, height: 0 },
@@ -3979,7 +3999,6 @@ class PdfiumNative {
3979
3999
  0,
3980
4000
  page.size.width,
3981
4001
  page.size.height,
3982
- /*rotate=*/
3983
4002
  0,
3984
4003
  left,
3985
4004
  top,
@@ -3992,7 +4011,6 @@ class PdfiumNative {
3992
4011
  0,
3993
4012
  page.size.width,
3994
4013
  page.size.height,
3995
- /*rotate=*/
3996
4014
  0,
3997
4015
  right,
3998
4016
  bottom,
@@ -4007,13 +4025,61 @@ class PdfiumNative {
4007
4025
  y = Math.min(y1, y2);
4008
4026
  width = Math.max(1, Math.abs(x2 - x1));
4009
4027
  height = Math.max(1, Math.abs(y2 - y1));
4028
+ if (this.pdfiumModule.FPDFText_GetCharBox(
4029
+ textPagePtr,
4030
+ charIndex,
4031
+ tLeftPtr,
4032
+ tRightPtr,
4033
+ tBottomPtr,
4034
+ tTopPtr
4035
+ )) {
4036
+ const tLeft = this.pdfiumModule.pdfium.getValue(tLeftPtr, "double");
4037
+ const tRight = this.pdfiumModule.pdfium.getValue(tRightPtr, "double");
4038
+ const tBottom = this.pdfiumModule.pdfium.getValue(tBottomPtr, "double");
4039
+ const tTop = this.pdfiumModule.pdfium.getValue(tTopPtr, "double");
4040
+ this.pdfiumModule.FPDF_PageToDevice(
4041
+ pagePtr,
4042
+ 0,
4043
+ 0,
4044
+ page.size.width,
4045
+ page.size.height,
4046
+ 0,
4047
+ tLeft,
4048
+ tTop,
4049
+ dx1Ptr,
4050
+ dy1Ptr
4051
+ );
4052
+ this.pdfiumModule.FPDF_PageToDevice(
4053
+ pagePtr,
4054
+ 0,
4055
+ 0,
4056
+ page.size.width,
4057
+ page.size.height,
4058
+ 0,
4059
+ tRight,
4060
+ tBottom,
4061
+ dx2Ptr,
4062
+ dy2Ptr
4063
+ );
4064
+ const tx1 = this.pdfiumModule.pdfium.getValue(dx1Ptr, "i32");
4065
+ const ty1 = this.pdfiumModule.pdfium.getValue(dy1Ptr, "i32");
4066
+ const tx2 = this.pdfiumModule.pdfium.getValue(dx2Ptr, "i32");
4067
+ const ty2 = this.pdfiumModule.pdfium.getValue(dy2Ptr, "i32");
4068
+ tightOrigin = { x: Math.min(tx1, tx2), y: Math.min(ty1, ty2) };
4069
+ tightSize = {
4070
+ width: Math.max(1, Math.abs(tx2 - tx1)),
4071
+ height: Math.max(1, Math.abs(ty2 - ty1))
4072
+ };
4073
+ }
4010
4074
  const uc = this.pdfiumModule.FPDFText_GetUnicode(textPagePtr, charIndex);
4011
4075
  isSpace = uc === 32;
4012
4076
  }
4013
- [rectPtr, dx1Ptr, dy1Ptr, dx2Ptr, dy2Ptr].forEach((p) => this.memoryManager.free(p));
4077
+ allPtrs.forEach((p) => this.memoryManager.free(p));
4014
4078
  return {
4015
4079
  origin: { x, y },
4016
4080
  size: { width, height },
4081
+ ...tightOrigin && { tightOrigin },
4082
+ ...tightSize && { tightSize },
4017
4083
  ...isSpace && { isSpace }
4018
4084
  };
4019
4085
  }
@@ -4326,6 +4392,10 @@ class PdfiumNative {
4326
4392
  }
4327
4393
  if (annotation) {
4328
4394
  annotation = this.reverseRotateAnnotationOnLoad(annotation);
4395
+ const apModes = this.pdfiumModule.EPDFAnnot_GetAvailableAppearanceModes(annotationPtr);
4396
+ if (apModes) {
4397
+ annotation.appearanceModes = apModes;
4398
+ }
4329
4399
  }
4330
4400
  return annotation;
4331
4401
  }
@@ -6987,6 +7057,150 @@ class PdfiumNative {
6987
7057
  this.memoryManager.free(heapPtr);
6988
7058
  return task;
6989
7059
  }
7060
+ /**
7061
+ * Batch-render all annotation appearance streams for a page in one call.
7062
+ * Returns a map of annotation ID -> rendered appearances (Normal/Rollover/Down).
7063
+ * Skips annotations that have rotation + unrotatedRect (EmbedPDF-rotated)
7064
+ * and annotations without any appearance stream.
7065
+ *
7066
+ * @public
7067
+ */
7068
+ renderPageAnnotationsRaw(doc, page, options) {
7069
+ const { scaleFactor = 1, rotation = Rotation.Degree0, dpr = 1 } = options ?? {};
7070
+ this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderPageAnnotationsRaw", doc, page, options);
7071
+ this.logger.perf(
7072
+ LOG_SOURCE,
7073
+ LOG_CATEGORY,
7074
+ "RenderPageAnnotationsRaw",
7075
+ "Begin",
7076
+ `${doc.id}-${page.index}`
7077
+ );
7078
+ const ctx = this.cache.getContext(doc.id);
7079
+ if (!ctx) {
7080
+ this.logger.perf(
7081
+ LOG_SOURCE,
7082
+ LOG_CATEGORY,
7083
+ "RenderPageAnnotationsRaw",
7084
+ "End",
7085
+ `${doc.id}-${page.index}`
7086
+ );
7087
+ return PdfTaskHelper.reject({
7088
+ code: PdfErrorCode.DocNotOpen,
7089
+ message: "document does not open"
7090
+ });
7091
+ }
7092
+ const pageCtx = ctx.acquirePage(page.index);
7093
+ const result = {};
7094
+ const finalScale = Math.max(0.01, scaleFactor * dpr);
7095
+ const annotCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
7096
+ for (let i = 0; i < annotCount; i++) {
7097
+ const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, i);
7098
+ if (!annotPtr) continue;
7099
+ try {
7100
+ const nm = this.getAnnotString(annotPtr, "NM");
7101
+ if (!nm) continue;
7102
+ const extRotation = this.getAnnotExtendedRotation(annotPtr);
7103
+ if (extRotation !== 0) {
7104
+ const unrotatedRaw = this.readAnnotUnrotatedRect(annotPtr);
7105
+ if (unrotatedRaw) continue;
7106
+ }
7107
+ const apModes = this.pdfiumModule.EPDFAnnot_GetAvailableAppearanceModes(annotPtr);
7108
+ if (!apModes) continue;
7109
+ const appearances = {};
7110
+ const modesToRender = [
7111
+ { bit: AP_MODE_NORMAL, mode: AppearanceMode.Normal, key: "normal" },
7112
+ { bit: AP_MODE_ROLLOVER, mode: AppearanceMode.Rollover, key: "rollover" },
7113
+ { bit: AP_MODE_DOWN, mode: AppearanceMode.Down, key: "down" }
7114
+ ];
7115
+ for (const { bit, mode, key } of modesToRender) {
7116
+ if (!(apModes & bit)) continue;
7117
+ const rendered = this.renderSingleAnnotAppearance(
7118
+ doc,
7119
+ page,
7120
+ pageCtx,
7121
+ annotPtr,
7122
+ mode,
7123
+ rotation,
7124
+ finalScale
7125
+ );
7126
+ if (rendered) {
7127
+ appearances[key] = rendered;
7128
+ }
7129
+ }
7130
+ if (appearances.normal || appearances.rollover || appearances.down) {
7131
+ result[nm] = appearances;
7132
+ }
7133
+ } finally {
7134
+ this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
7135
+ }
7136
+ }
7137
+ pageCtx.release();
7138
+ this.logger.perf(
7139
+ LOG_SOURCE,
7140
+ LOG_CATEGORY,
7141
+ "RenderPageAnnotationsRaw",
7142
+ "End",
7143
+ `${doc.id}-${page.index}`
7144
+ );
7145
+ const task = new Task();
7146
+ task.resolve(result);
7147
+ return task;
7148
+ }
7149
+ /**
7150
+ * Render a single annotation's appearance for a given mode.
7151
+ * Returns the image data and rect, or null on failure.
7152
+ * @private
7153
+ */
7154
+ renderSingleAnnotAppearance(doc, page, pageCtx, annotPtr, mode, rotation, finalScale) {
7155
+ const pageRect = this.readPageAnnoRect(annotPtr);
7156
+ const annotRect = this.convertPageRectToDeviceRect(doc, page, pageRect);
7157
+ const rect = toIntRect(annotRect);
7158
+ const devRect = toIntRect(transformRect(page.size, rect, rotation, finalScale));
7159
+ const wDev = Math.max(1, devRect.size.width);
7160
+ const hDev = Math.max(1, devRect.size.height);
7161
+ const stride = wDev * 4;
7162
+ const bytes = stride * hDev;
7163
+ const heapPtr = this.memoryManager.malloc(bytes);
7164
+ const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(
7165
+ wDev,
7166
+ hDev,
7167
+ 4,
7168
+ heapPtr,
7169
+ stride
7170
+ );
7171
+ this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, 0);
7172
+ const M = buildUserToDeviceMatrix(rect, rotation, wDev, hDev);
7173
+ const mPtr = this.memoryManager.malloc(6 * 4);
7174
+ const mView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, mPtr, 6);
7175
+ mView.set([M.a, M.b, M.c, M.d, M.e, M.f]);
7176
+ const FLAGS = 16;
7177
+ let ok = false;
7178
+ try {
7179
+ ok = !!this.pdfiumModule.EPDF_RenderAnnotBitmap(
7180
+ bitmapPtr,
7181
+ pageCtx.pagePtr,
7182
+ annotPtr,
7183
+ mode,
7184
+ mPtr,
7185
+ FLAGS
7186
+ );
7187
+ } finally {
7188
+ this.memoryManager.free(mPtr);
7189
+ this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
7190
+ }
7191
+ if (!ok) {
7192
+ this.memoryManager.free(heapPtr);
7193
+ return null;
7194
+ }
7195
+ const data = this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes);
7196
+ const imageData = {
7197
+ data: new Uint8ClampedArray(data),
7198
+ width: wDev,
7199
+ height: hDev
7200
+ };
7201
+ this.memoryManager.free(heapPtr);
7202
+ return { data: imageData, rect: annotRect };
7203
+ }
6990
7204
  renderRectEncoded(doc, page, rect, options) {
6991
7205
  const task = new Task();
6992
7206
  const rotation = (options == null ? void 0 : options.rotation) ?? Rotation.Degree0;
@@ -8198,4 +8412,4 @@ export {
8198
8412
  isValidCustomKey as i,
8199
8413
  readArrayBuffer as r
8200
8414
  };
8201
- //# sourceMappingURL=direct-engine-BmntIHbH.js.map
8415
+ //# sourceMappingURL=direct-engine-BfstxIRP.js.map