@embedpdf/engines 2.6.2 → 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-CmsmBgWP.js → direct-engine-BfstxIRP.js} +153 -5
  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 +5 -5
  38. package/dist/direct-engine-CCVjfywm.cjs +0 -2
  39. package/dist/direct-engine-CCVjfywm.cjs.map +0 -1
  40. package/dist/direct-engine-CmsmBgWP.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 {
@@ -4392,6 +4392,10 @@ class PdfiumNative {
4392
4392
  }
4393
4393
  if (annotation) {
4394
4394
  annotation = this.reverseRotateAnnotationOnLoad(annotation);
4395
+ const apModes = this.pdfiumModule.EPDFAnnot_GetAvailableAppearanceModes(annotationPtr);
4396
+ if (apModes) {
4397
+ annotation.appearanceModes = apModes;
4398
+ }
4395
4399
  }
4396
4400
  return annotation;
4397
4401
  }
@@ -7053,6 +7057,150 @@ class PdfiumNative {
7053
7057
  this.memoryManager.free(heapPtr);
7054
7058
  return task;
7055
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
+ }
7056
7204
  renderRectEncoded(doc, page, rect, options) {
7057
7205
  const task = new Task();
7058
7206
  const rotation = (options == null ? void 0 : options.rotation) ?? Rotation.Degree0;
@@ -8264,4 +8412,4 @@ export {
8264
8412
  isValidCustomKey as i,
8265
8413
  readArrayBuffer as r
8266
8414
  };
8267
- //# sourceMappingURL=direct-engine-CmsmBgWP.js.map
8415
+ //# sourceMappingURL=direct-engine-BfstxIRP.js.map