@embedpdf/engine-services 3.0.0-next.6 → 3.0.0-next.8

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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { PdfFunctions, PdfRuntimeMemory, PdfRuntimeModule, Ptr } from "@embedpdf/engine-runtime";
2
- import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
2
+ import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
3
3
  //#region src/runtime/lifecycle/bootstrap.d.ts
4
4
  /**
5
5
  * Initialize the thread-confined PDFium runtime for the calling thread. Each
@@ -1414,6 +1414,29 @@ declare class DocumentActionsReader {
1414
1414
  }
1415
1415
  //#endregion
1416
1416
  //#region src/worker-host/WorkerHost.d.ts
1417
+ /** The image a {@link WorkerImageEncoder} produced. `bytes` must OWN its
1418
+ * buffer (a fresh allocation, not a pooled `Buffer` slab view) — it is
1419
+ * placed on the transfer manifest and moved zero-copy. */
1420
+ interface WorkerEncodedImage {
1421
+ contentType: string;
1422
+ bytes: Uint8Array;
1423
+ }
1424
+ /**
1425
+ * Injected image-encode capability for the `*.renderEncoded` wire kinds.
1426
+ * Dependency inversion keeps the native encoder OUT of this shared
1427
+ * package: the cloud server's worker entry injects a sharp/libvips
1428
+ * implementation; browser/local entries inject nothing (they encode via
1429
+ * canvas) and the encoded kinds reject with `NotImplemented`.
1430
+ */
1431
+ interface WorkerImageEncoder {
1432
+ encode(raster: PageRaster, opts: {
1433
+ format: PageNetworkRenderFormat;
1434
+ quality?: number;
1435
+ }): Promise<WorkerEncodedImage>;
1436
+ }
1437
+ interface WorkerHostOptions {
1438
+ imageEncoder?: WorkerImageEncoder;
1439
+ }
1417
1440
  /**
1418
1441
  * The piece that runs "inside the worker": owns runtime, manages document
1419
1442
  * sessions, dispatches requests to the engine-services synchronous code.
@@ -1435,6 +1458,8 @@ declare class WorkerHost {
1435
1458
  * runs in.
1436
1459
  */
1437
1460
  private readonly post;
1461
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1462
+ private readonly options;
1438
1463
  private readonly sessions;
1439
1464
  private readonly baseDocuments;
1440
1465
  private readonly aborts;
@@ -1456,7 +1481,9 @@ declare class WorkerHost {
1456
1481
  * pack.transfer)` — the host doesn't know which environment it
1457
1482
  * runs in.
1458
1483
  */
1459
- post: (pack: WirePack<WorkerResponse>) => void);
1484
+ post: (pack: WirePack<WorkerResponse>) => void,
1485
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1486
+ options?: WorkerHostOptions);
1460
1487
  /**
1461
1488
  * Register deployment-owned fonts on this worker thread, after init and
1462
1489
  * before serving requests. Server-only: the cloud engine never exposes font
@@ -1499,6 +1526,11 @@ declare class WorkerHost {
1499
1526
  private handlePagesGeometry;
1500
1527
  private handleSearchQuery;
1501
1528
  private handlePagesRender;
1529
+ private receiveEncoded;
1530
+ private encodeRaster;
1531
+ private handlePagesRenderEncoded;
1532
+ private handleDocumentRenderPageFileEncoded;
1533
+ private handleAnnotationsRenderAppearancesEncoded;
1502
1534
  private handleDocumentSaveBuffer;
1503
1535
  private handleDocumentSaveFile;
1504
1536
  private handleDocumentSaveLayerBuffer;
@@ -1553,5 +1585,5 @@ declare class WorkerHost {
1553
1585
  private saveLayerArtifact;
1554
1586
  }
1555
1587
  //#endregion
1556
- export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, type ImpactInputs, type LayerSource, LocalRevisionAuthority, MetadataMutator, MetadataReader, type MutationKind, type OpenedPdfDocument, type OpenedPdfDocumentKind, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, type PageRecord, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, type RawGeometryGlyphRecord, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, WorkerHost, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
1588
+ export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, type ImpactInputs, type LayerSource, LocalRevisionAuthority, MetadataMutator, MetadataReader, type MutationKind, type OpenedPdfDocument, type OpenedPdfDocumentKind, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, type PageRecord, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, type RawGeometryGlyphRecord, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, type WorkerEncodedImage, WorkerHost, type WorkerHostOptions, type WorkerImageEncoder, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
1557
1589
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
1
+ import { ActionReadBudget, AnnotationActor, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationListMutationMeta, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationMutationKind, AnnotationRef, AnnotationStableId, AnnotationUpdateResult, AttachmentCreateResult, AttachmentDeleteResult, AttachmentFileInfo, AttachmentFileWorkerPayload, DocumentActionsSnapshot, DocumentEvent, DocumentEventInit, DocumentEventStream, DocumentMetadata, DocumentSecurityProbeInfo, EmbeddedFileItem, EmbeddedFileRef, FormDataFormat, FormEffect, FormEffectsResult, FormFieldDTO, FormFieldDraft, FormFieldPatch, FormFieldRef, FormFieldValue, FormImportResult, FormRepairResult, FormSetValueResult, FormSnapshot, FormWidgetRef, MetadataPatch, MetadataUpdateResult, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryRun, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageNetworkRenderFormat, PageObjectNumber, PageRaster, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, PdfQuad, PdfRect, PdfSaveMode, RedactionApplyResult, RedactionApplyScope, RevisionToken, SearchRequest, SearchSlice, WeakAnnotationState, WireAnnotationDraft, WireAnnotationPatch, WireAttachmentFile, WirePack, WireResource, WireResourceMap, WorkerRequest, WorkerResponse } from "@embedpdf/engine-core/runtime";
2
2
  import { PdfFunctions, PdfRuntimeMemory, PdfRuntimeModule, Ptr } from "@embedpdf/engine-runtime";
3
3
  //#region src/runtime/lifecycle/bootstrap.d.ts
4
4
  /**
@@ -1414,6 +1414,29 @@ declare class DocumentActionsReader {
1414
1414
  }
1415
1415
  //#endregion
1416
1416
  //#region src/worker-host/WorkerHost.d.ts
1417
+ /** The image a {@link WorkerImageEncoder} produced. `bytes` must OWN its
1418
+ * buffer (a fresh allocation, not a pooled `Buffer` slab view) — it is
1419
+ * placed on the transfer manifest and moved zero-copy. */
1420
+ interface WorkerEncodedImage {
1421
+ contentType: string;
1422
+ bytes: Uint8Array;
1423
+ }
1424
+ /**
1425
+ * Injected image-encode capability for the `*.renderEncoded` wire kinds.
1426
+ * Dependency inversion keeps the native encoder OUT of this shared
1427
+ * package: the cloud server's worker entry injects a sharp/libvips
1428
+ * implementation; browser/local entries inject nothing (they encode via
1429
+ * canvas) and the encoded kinds reject with `NotImplemented`.
1430
+ */
1431
+ interface WorkerImageEncoder {
1432
+ encode(raster: PageRaster, opts: {
1433
+ format: PageNetworkRenderFormat;
1434
+ quality?: number;
1435
+ }): Promise<WorkerEncodedImage>;
1436
+ }
1437
+ interface WorkerHostOptions {
1438
+ imageEncoder?: WorkerImageEncoder;
1439
+ }
1417
1440
  /**
1418
1441
  * The piece that runs "inside the worker": owns runtime, manages document
1419
1442
  * sessions, dispatches requests to the engine-services synchronous code.
@@ -1435,6 +1458,8 @@ declare class WorkerHost {
1435
1458
  * runs in.
1436
1459
  */
1437
1460
  private readonly post;
1461
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1462
+ private readonly options;
1438
1463
  private readonly sessions;
1439
1464
  private readonly baseDocuments;
1440
1465
  private readonly aborts;
@@ -1456,7 +1481,9 @@ declare class WorkerHost {
1456
1481
  * pack.transfer)` — the host doesn't know which environment it
1457
1482
  * runs in.
1458
1483
  */
1459
- post: (pack: WirePack<WorkerResponse>) => void);
1484
+ post: (pack: WirePack<WorkerResponse>) => void,
1485
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1486
+ options?: WorkerHostOptions);
1460
1487
  /**
1461
1488
  * Register deployment-owned fonts on this worker thread, after init and
1462
1489
  * before serving requests. Server-only: the cloud engine never exposes font
@@ -1499,6 +1526,11 @@ declare class WorkerHost {
1499
1526
  private handlePagesGeometry;
1500
1527
  private handleSearchQuery;
1501
1528
  private handlePagesRender;
1529
+ private receiveEncoded;
1530
+ private encodeRaster;
1531
+ private handlePagesRenderEncoded;
1532
+ private handleDocumentRenderPageFileEncoded;
1533
+ private handleAnnotationsRenderAppearancesEncoded;
1502
1534
  private handleDocumentSaveBuffer;
1503
1535
  private handleDocumentSaveFile;
1504
1536
  private handleDocumentSaveLayerBuffer;
@@ -1553,5 +1585,5 @@ declare class WorkerHost {
1553
1585
  private saveLayerArtifact;
1554
1586
  }
1555
1587
  //#endregion
1556
- export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, type ImpactInputs, type LayerSource, LocalRevisionAuthority, MetadataMutator, MetadataReader, type MutationKind, type OpenedPdfDocument, type OpenedPdfDocumentKind, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, type PageRecord, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, type RawGeometryGlyphRecord, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, WorkerHost, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
1588
+ export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, EPDF_CHAR_GEOMETRY_LAYOUT, EventHub, FontRegistrar, FormMutator, FormReader, FormsEffectsApplier, type ImpactInputs, type LayerSource, LocalRevisionAuthority, MetadataMutator, MetadataReader, type MutationKind, type OpenedPdfDocument, type OpenedPdfDocumentKind, PageGeometryReader, PagesReader as PageLayoutReader, PagesReader, PagePtrPool, PageRenderReader as PageRasterReader, PageRenderReader, type PageRecord, PageTextReader, PagesExtractor, PagesFlattener, PagesInserter, RawAnnotationReader, type RawGeometryGlyphRecord, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, type WorkerEncodedImage, WorkerHost, type WorkerHostOptions, type WorkerImageEncoder, buildRunsFromRawGlyphs, computeMutationImpact, destroyLibrary, disposeFormModel, ensureInitialized, formatPdfDate, generateUuid, hasAllStandardSecurityPermissions, normalizeU32, openFatMemoryDocument, openLayerDocument, pdfDateToIso, readActionModel, readAttachmentFileInfo, throwIfAborted, writeAttachmentFilePayload };
1557
1589
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -9250,9 +9250,10 @@ function validatePatchValue(key, value) {
9250
9250
  * worker wire shape from @embedpdf/engine-core.
9251
9251
  */
9252
9252
  var WorkerHost = class {
9253
- constructor(runtime, post) {
9253
+ constructor(runtime, post, options = {}) {
9254
9254
  this.runtime = runtime;
9255
9255
  this.post = post;
9256
+ this.options = options;
9256
9257
  _defineProperty(this, "sessions", /* @__PURE__ */ new Map());
9257
9258
  _defineProperty(this, "baseDocuments", void 0);
9258
9259
  _defineProperty(this, "aborts", /* @__PURE__ */ new Map());
@@ -9278,6 +9279,10 @@ var WorkerHost = class {
9278
9279
  this.aborts.get(msg.jobId)?.abort();
9279
9280
  return;
9280
9281
  }
9282
+ if (msg.kind === "pages.renderEncoded" || msg.kind === "document.renderPageFileEncoded" || msg.kind === "annotations.renderAppearancesEncoded") {
9283
+ this.receiveEncoded(msg);
9284
+ return;
9285
+ }
9281
9286
  const ctrl = new AbortController();
9282
9287
  this.aborts.set(msg.jobId, ctrl);
9283
9288
  let resultPack;
@@ -9765,6 +9770,105 @@ var WorkerHost = class {
9765
9770
  raster
9766
9771
  }, [raster.data]);
9767
9772
  }
9773
+ async receiveEncoded(msg) {
9774
+ if (!this.options.imageEncoder) {
9775
+ this.post(wirePack({
9776
+ kind: "reject",
9777
+ jobId: msg.jobId,
9778
+ error: serializeError(new EngineError(EngineErrorCode.NotImplemented, "this engine has no image encoder (the *.renderEncoded kinds are cloud-server surface)"))
9779
+ }, EMPTY_TRANSFER));
9780
+ return;
9781
+ }
9782
+ const ctrl = new AbortController();
9783
+ this.aborts.set(msg.jobId, ctrl);
9784
+ try {
9785
+ let resultPack;
9786
+ switch (msg.kind) {
9787
+ case "pages.renderEncoded":
9788
+ resultPack = await this.handlePagesRenderEncoded(msg, ctrl.signal);
9789
+ break;
9790
+ case "document.renderPageFileEncoded":
9791
+ resultPack = await this.handleDocumentRenderPageFileEncoded(msg, ctrl.signal);
9792
+ break;
9793
+ case "annotations.renderAppearancesEncoded":
9794
+ resultPack = await this.handleAnnotationsRenderAppearancesEncoded(msg, ctrl.signal);
9795
+ break;
9796
+ }
9797
+ this.post(wirePack({
9798
+ kind: "resolve",
9799
+ jobId: msg.jobId,
9800
+ result: resultPack.payload
9801
+ }, resultPack.transfer));
9802
+ } catch (err) {
9803
+ this.post(wirePack({
9804
+ kind: "reject",
9805
+ jobId: msg.jobId,
9806
+ error: serializeError(err)
9807
+ }, EMPTY_TRANSFER));
9808
+ } finally {
9809
+ this.aborts.delete(msg.jobId);
9810
+ }
9811
+ }
9812
+ async encodeRaster(raster, encode, signal) {
9813
+ const encoder = this.options.imageEncoder;
9814
+ if (!encoder) throw new EngineError(EngineErrorCode.NotImplemented, "this engine has no image encoder (the *.renderEncoded kinds are cloud-server surface)");
9815
+ const { bytes, contentType } = await encoder.encode(raster, encode);
9816
+ if (signal.aborted) throw new EngineError(EngineErrorCode.Aborted, "aborted during image encode");
9817
+ return {
9818
+ contentType,
9819
+ width: raster.width,
9820
+ height: raster.height,
9821
+ bytes
9822
+ };
9823
+ }
9824
+ async handlePagesRenderEncoded(req, signal) {
9825
+ const inner = this.handlePagesRender({
9826
+ ...req,
9827
+ kind: "pages.render"
9828
+ }, signal);
9829
+ if (inner.payload.tag !== "pages.render") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
9830
+ const image = await this.encodeRaster(inner.payload.raster, req.encode, signal);
9831
+ return wirePack({
9832
+ tag: "pages.renderEncoded",
9833
+ image
9834
+ }, [image.bytes.buffer]);
9835
+ }
9836
+ async handleDocumentRenderPageFileEncoded(req, signal) {
9837
+ const inner = this.handleDocumentRenderPageFile({
9838
+ ...req,
9839
+ kind: "document.renderPageFile"
9840
+ }, signal);
9841
+ if (inner.payload.tag !== "document.renderPageFile") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
9842
+ const image = await this.encodeRaster(inner.payload.raster, req.encode, signal);
9843
+ return wirePack({
9844
+ tag: "document.renderPageFileEncoded",
9845
+ pageObjectNumber: inner.payload.pageObjectNumber,
9846
+ pageCount: inner.payload.pageCount,
9847
+ image
9848
+ }, [image.bytes.buffer]);
9849
+ }
9850
+ async handleAnnotationsRenderAppearancesEncoded(req, signal) {
9851
+ const inner = this.handleAnnotationsRenderAppearances({
9852
+ ...req,
9853
+ kind: "annotations.renderAppearances"
9854
+ }, signal);
9855
+ if (inner.payload.tag !== "annotations.renderAppearances") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
9856
+ const { pageState, appearances } = inner.payload.result;
9857
+ const encoded = [];
9858
+ for (const a of appearances) encoded.push({
9859
+ ref: a.ref,
9860
+ mode: a.mode,
9861
+ rect: a.rect,
9862
+ image: await this.encodeRaster(a.raster, req.encode, signal)
9863
+ });
9864
+ return wirePack({
9865
+ tag: "annotations.renderAppearancesEncoded",
9866
+ result: {
9867
+ pageState,
9868
+ appearances: encoded
9869
+ }
9870
+ }, encoded.map((e) => e.image.bytes.buffer));
9871
+ }
9768
9872
  handleDocumentSaveBuffer(req) {
9769
9873
  const session = this.requireSession(req);
9770
9874
  const saved = new DocumentSaver(this.runtime, session).saveStandaloneToBuffer(req.mode);