@cloudpdf/engine 3.0.0-next.12 → 3.0.0-next.14

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,4 +1,4 @@
1
- import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
1
+ import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentSignaturesService, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMeasureService, PageMeasurementViewport, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfMeasure, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
2
2
  import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
3
3
  import { SessionEventPublisher } from "@embedpdf/engine-services";
4
4
  //#region src/transport/HttpClient.d.ts
@@ -179,6 +179,7 @@ declare class HttpClient {
179
179
  /** PATCH counterpart of {@link postMultipartJson} (binary-carrying mutations). */
180
180
  patchMultipartJson<T>(path: string, body: FormData, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
181
181
  postJson<T>(path: string, body: unknown, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
182
+ putJson<T>(path: string, body: unknown, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
182
183
  /** POST a JSON body and return the raw binary response (pages.extract). */
183
184
  postJsonBytes(path: string, body: unknown, signal: AbortSignal): Promise<Uint8Array>;
184
185
  /** POST a raw binary body (FDF/XFDF import) and parse the JSON response. */
@@ -318,6 +319,7 @@ declare class CloudDocumentHandle implements DocumentHandle$1 {
318
319
  readonly annotations: DocumentAnnotationsService$1;
319
320
  readonly actions: DocumentActionsService;
320
321
  readonly attachments: DocumentAttachmentsService;
322
+ readonly signatures: DocumentSignaturesService;
321
323
  readonly forms: DocumentFormsService;
322
324
  readonly search: CloudDocumentSearchService;
323
325
  readonly pages: DocumentPagesService$1;
@@ -624,6 +626,21 @@ declare class CloudPageTextService implements PageTextService$1 {
624
626
  read(): AbortablePromise$1<PageTextSnapshot>;
625
627
  }
626
628
  //#endregion
629
+ //#region src/document/CloudPageMeasureService.d.ts
630
+ declare class CloudPageMeasureService implements PageMeasureService {
631
+ private readonly http;
632
+ private readonly docId;
633
+ private readonly layerName;
634
+ private readonly pon;
635
+ private readonly isClosed;
636
+ private readonly manifest;
637
+ private readonly publisher;
638
+ constructor(http: HttpClient, docId: string, layerName: string, pon: number, isClosed: () => boolean, manifest: ManifestAccessor, publisher: SessionEventPublisher);
639
+ viewports(): AbortablePromise$1<PageMeasurementViewport[]>;
640
+ setScale(measure: PdfMeasure | null): AbortablePromise$1<void>;
641
+ private check;
642
+ }
643
+ //#endregion
627
644
  //#region src/document/CloudPageHandle.d.ts
628
645
  declare class CloudPageHandle implements PageHandle$1 {
629
646
  readonly pageObjectNumber: PageObjectNumber;
@@ -632,6 +649,7 @@ declare class CloudPageHandle implements PageHandle$1 {
632
649
  readonly text: CloudPageTextService;
633
650
  readonly geometry: CloudPageGeometryService;
634
651
  readonly render: CloudPageRenderService;
652
+ readonly measure: CloudPageMeasureService;
635
653
  constructor(pageObjectNumber: PageObjectNumber, pageIndex: number, http: HttpClient, docId: string, layerName: string, isClosed: () => boolean, manifest: ManifestAccessor, publisher: SessionEventPublisher);
636
654
  }
637
655
  //#endregion
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
1
+ import { AbortError, AbortablePromise, AbortablePromise as AbortablePromise$1, AnnotationAppearanceImageOptions, AnnotationAppearanceImagesResult, AnnotationAppearanceRenderOptions, AnnotationAppearancesResult, AnnotationCreateResult, AnnotationDeleteResult, AnnotationDraft, AnnotationFlattenResult, AnnotationListPageSnapshot, AnnotationListSnapshotAllPages, AnnotationMoveResult, AnnotationPatch, AnnotationRef, AnnotationUpdateResult, AttachmentContent, AttachmentsCache, DocumentAccessInfo, DocumentActionsService, DocumentAnnotationsService, DocumentAnnotationsService as DocumentAnnotationsService$1, DocumentAttachmentsService, DocumentCapabilities, DocumentEventStream, DocumentFormsService, DocumentHandle, DocumentHandle as DocumentHandle$1, DocumentIdentity, DocumentMetadata, DocumentPagesService, DocumentPagesService as DocumentPagesService$1, DocumentRedactionService, DocumentRenderService, DocumentSearchService, DocumentSecurityService, DocumentSecurityService as DocumentSecurityService$1, DocumentSecurityState, DocumentSignaturesService, DocumentUnlockInput, DocumentUnlockResult, Engine, Engine as Engine$1, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineFactory, MetadataCache, MetadataPatch, MetadataService, MetadataService as MetadataService$1, MetadataUpdateResult, MutationMeta, OpenInput, OpenInput as OpenInput$1, OpenInputShare, OpenOptions, OpenOptions as OpenOptions$1, PageAnnotationsService, PageAnnotationsService as PageAnnotationsService$1, PageDeleteResult, PageFlattenResult, PageFlattenUsage, PageGeometryService, PageGeometryService as PageGeometryService$1, PageGeometrySnapshot, PageHandle, PageHandle as PageHandle$1, PageImageHandle, PageImageOptions, PageInsertBlankSpec, PageInsertResult, PageListSnapshot, PageMeasureService, PageMeasurementViewport, PageMoveResult, PageNameInput, PageNameResult, PageObjectNumber, PageRaster, PageRemoveNameInput, PageRenderOptions, PageRenderService, PageRenderService as PageRenderService$1, PageRotateResult, PageRotation, PageStructureCache, PageTextService, PageTextService as PageTextService$1, PageTextSnapshot, PdfMeasure, PdfSaveMode, PdfSaveMode as PdfSaveMode$1, SearchRequest, SearchSlice, TokenSource, WeakAnnotationEditSession } from "@embedpdf/engine-core/runtime";
2
2
  import { CdnAccessInfoForApply, DocumentHead, DocumentManifest, LayerScopePlane } from "@embedpdf/engine-core/wire";
3
3
  import { SessionEventPublisher } from "@embedpdf/engine-services";
4
4
  //#region src/transport/HttpClient.d.ts
@@ -179,6 +179,7 @@ declare class HttpClient {
179
179
  /** PATCH counterpart of {@link postMultipartJson} (binary-carrying mutations). */
180
180
  patchMultipartJson<T>(path: string, body: FormData, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
181
181
  postJson<T>(path: string, body: unknown, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
182
+ putJson<T>(path: string, body: unknown, parser: (raw: unknown) => T, signal: AbortSignal): Promise<T>;
182
183
  /** POST a JSON body and return the raw binary response (pages.extract). */
183
184
  postJsonBytes(path: string, body: unknown, signal: AbortSignal): Promise<Uint8Array>;
184
185
  /** POST a raw binary body (FDF/XFDF import) and parse the JSON response. */
@@ -318,6 +319,7 @@ declare class CloudDocumentHandle implements DocumentHandle$1 {
318
319
  readonly annotations: DocumentAnnotationsService$1;
319
320
  readonly actions: DocumentActionsService;
320
321
  readonly attachments: DocumentAttachmentsService;
322
+ readonly signatures: DocumentSignaturesService;
321
323
  readonly forms: DocumentFormsService;
322
324
  readonly search: CloudDocumentSearchService;
323
325
  readonly pages: DocumentPagesService$1;
@@ -624,6 +626,21 @@ declare class CloudPageTextService implements PageTextService$1 {
624
626
  read(): AbortablePromise$1<PageTextSnapshot>;
625
627
  }
626
628
  //#endregion
629
+ //#region src/document/CloudPageMeasureService.d.ts
630
+ declare class CloudPageMeasureService implements PageMeasureService {
631
+ private readonly http;
632
+ private readonly docId;
633
+ private readonly layerName;
634
+ private readonly pon;
635
+ private readonly isClosed;
636
+ private readonly manifest;
637
+ private readonly publisher;
638
+ constructor(http: HttpClient, docId: string, layerName: string, pon: number, isClosed: () => boolean, manifest: ManifestAccessor, publisher: SessionEventPublisher);
639
+ viewports(): AbortablePromise$1<PageMeasurementViewport[]>;
640
+ setScale(measure: PdfMeasure | null): AbortablePromise$1<void>;
641
+ private check;
642
+ }
643
+ //#endregion
627
644
  //#region src/document/CloudPageHandle.d.ts
628
645
  declare class CloudPageHandle implements PageHandle$1 {
629
646
  readonly pageObjectNumber: PageObjectNumber;
@@ -632,6 +649,7 @@ declare class CloudPageHandle implements PageHandle$1 {
632
649
  readonly text: CloudPageTextService;
633
650
  readonly geometry: CloudPageGeometryService;
634
651
  readonly render: CloudPageRenderService;
652
+ readonly measure: CloudPageMeasureService;
635
653
  constructor(pageObjectNumber: PageObjectNumber, pageIndex: number, http: HttpClient, docId: string, layerName: string, isClosed: () => boolean, manifest: ManifestAccessor, publisher: SessionEventPublisher);
636
654
  }
637
655
  //#endregion
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AbortError, AbortError as AbortError$1, AbortablePromise, AbortablePromise as AbortablePromise$1, CONTINUOUS_RENDER_POLICY, DEFAULT_PDF_SAVE_MODE, EngineError, EngineError as EngineError$1, EngineErrorCode, EngineErrorCode as EngineErrorCode$1, canonicalSearchQuery, checkCapability, checkCollab, checkSetGroup, createPageImageHandle, decodePdfBits, encodeFieldRefKey, encodeStableIdKey, expandRawScope, normalizeAnnotationDraft, normalizeAnnotationPatch, normalizeAttachmentFileSource, passwordPromptFromState, searchContentEpoch, securityStateFromHead } from "@embedpdf/engine-core/runtime";
2
- import { AccessResponseSchema, AnnotationAppearanceManifestSchema, AnnotationCreateResultSchema, AnnotationDeleteResultSchema, AnnotationFlattenResultSchema, AnnotationListPageSnapshotSchema, AnnotationListSnapshotAllPagesSchema, AnnotationMoveResultSchema, AnnotationUpdateResultSchema, AttachmentCreateResultSchema, AttachmentDeleteResultSchema, DEFAULT_LAYER_NAME, DocumentActionsSnapshotSchema, DocumentHeadSchema, DocumentManifestSchema, DocumentMetadataSchema, EmbeddedFileItemSchema, EngineErrorPayloadSchema, FormEffectsResultSchema, FormFieldCreateResultSchema, FormFieldDTOSchema, FormFieldDeleteResultSchema, FormFieldUpdateResultSchema, FormImportResultSchema, FormRepairResultSchema, FormSetValueResultSchema, FormSnapshotSchema, FormWidgetLinkResultSchema, MetadataUpdateResultSchema, PageDeleteResultSchema, PageFlattenResultSchema, PageGeometrySnapshotSchema, PageInsertResultSchema, PageListSnapshotSchema, PageMoveResultSchema, PageNameResultSchema, PageRotateResultSchema, PageTextSnapshotSchema, RedactionApplyResultSchema, SearchSliceSchema, WeakAnnotationSessionResponseSchema, annotationAppearancesImageOptionsToWire, applyCdnAccess, decodeSearchToken, decodeTokenText, encodeSearchToken, renderImageOptionsToWire, wirePaths } from "@embedpdf/engine-core/wire";
2
+ import { AccessResponseSchema, AnnotationAppearanceManifestSchema, AnnotationCreateResultSchema, AnnotationDeleteResultSchema, AnnotationFlattenResultSchema, AnnotationListPageSnapshotSchema, AnnotationListSnapshotAllPagesSchema, AnnotationMoveResultSchema, AnnotationUpdateResultSchema, AttachmentCreateResultSchema, AttachmentDeleteResultSchema, ChangeAnalysisSchema, DEFAULT_LAYER_NAME, DocumentActionsSnapshotSchema, DocumentHeadSchema, DocumentManifestSchema, DocumentMetadataSchema, EmbeddedFileItemSchema, EngineErrorPayloadSchema, FormEffectsResultSchema, FormFieldCreateResultSchema, FormFieldDTOSchema, FormFieldDeleteResultSchema, FormFieldUpdateResultSchema, FormImportResultSchema, FormRepairResultSchema, FormSetValueResultSchema, FormSnapshotSchema, FormWidgetLinkResultSchema, MetadataUpdateResultSchema, PageDeleteResultSchema, PageFlattenResultSchema, PageGeometrySnapshotSchema, PageInsertResultSchema, PageListSnapshotSchema, PageMeasurementViewportSchema, PageMoveResultSchema, PageNameResultSchema, PageRotateResultSchema, PageScaleResultSchema, PageTextSnapshotSchema, RedactionApplyResultSchema, SearchSliceSchema, SignatureAbortResultSchema, SignatureCompleteResultSchema, SignaturePreparedWireSchema, SignatureSnapshotSchema, WeakAnnotationSessionResponseSchema, annotationAppearancesImageOptionsToWire, applyCdnAccess, decodePrepared, decodeSearchToken, decodeTokenText, encodeSearchToken, renderImageOptionsToWire, toBase64, wirePaths } from "@embedpdf/engine-core/wire";
3
3
  import { EventHub, SessionEventPublisher, generateUuid } from "@embedpdf/engine-services";
4
4
  //#region src/document/planes.ts
5
5
  /**
@@ -434,6 +434,24 @@ var CloudDocumentFormsService = class {
434
434
  return this.absorbMutation(result, "form.fieldUpdated");
435
435
  });
436
436
  }
437
+ setSignatureAppearance(ref, appearance) {
438
+ const rejected = this.rejectIfClosed();
439
+ if (rejected) return rejected;
440
+ return AbortablePromise$1.run(async (signal) => {
441
+ const bytes = new ArrayBuffer(appearance.pdf.byteLength);
442
+ new Uint8Array(bytes).set(appearance.pdf);
443
+ const form = buildMutationForm({
444
+ resource: "r0",
445
+ pageIndex: appearance.pageIndex ?? 0
446
+ }, { r0: {
447
+ bytes,
448
+ mimeType: "application/pdf",
449
+ name: "appearance.pdf"
450
+ } });
451
+ const result = await this.http.postMultipartJson(wirePaths.layerFormFieldSignatureAppearance(this.docId, this.layerName, encodeFieldRefKey(ref)), form, (raw) => FormFieldUpdateResultSchema.parse(raw), signal);
452
+ return this.absorbMutation(result, "form.fieldUpdated");
453
+ });
454
+ }
437
455
  deleteField(ref) {
438
456
  const rejected = this.rejectIfClosed();
439
457
  if (rejected) return rejected;
@@ -775,7 +793,8 @@ function queryIdentity(query) {
775
793
  query.text,
776
794
  query.matchCase ? 1 : 0,
777
795
  query.matchDiacritics ? 1 : 0,
778
- query.wholeWord ? 1 : 0
796
+ query.wholeWord ? 1 : 0,
797
+ query.ignoreWhitespace ? 1 : 0
779
798
  ]);
780
799
  }
781
800
  //#endregion
@@ -1014,6 +1033,176 @@ function identityFromClaims(claims) {
1014
1033
  return Object.keys(out).length > 0 ? out : null;
1015
1034
  }
1016
1035
  //#endregion
1036
+ //#region src/document/CloudDocumentSignaturesService.ts
1037
+ /**
1038
+ * Cloud-side digital signatures. Two kinds of read, two kinds of URL:
1039
+ *
1040
+ * - The LAYER view (`list`, and `analyze` of the working copy) is pinned
1041
+ * by the manifest's `docVersion`, like every other layer read: a
1042
+ * signature is a layer state change, the immutable URL moves with it.
1043
+ * - Signed BYTES (`contents`, `digest`, `revisionBytes`, and `analyze`
1044
+ * of history) belong to a base VERSION and are content-addressed by
1045
+ * the manifest's `baseSha`: immutable forever, shared by every layer
1046
+ * and every caller.
1047
+ *
1048
+ * Signing is the server's two-phase protocol over the same wire shapes
1049
+ * the local engine uses. `prepare` and `complete` change the manifest in
1050
+ * ways no delta carries (a publish moves `baseSha` itself), so both
1051
+ * refresh it before returning.
1052
+ */
1053
+ var CloudDocumentSignaturesService = class {
1054
+ constructor(http, docId, layerName, isClosed, manifest, publisher) {
1055
+ this.http = http;
1056
+ this.docId = docId;
1057
+ this.layerName = layerName;
1058
+ this.isClosed = isClosed;
1059
+ this.manifest = manifest;
1060
+ this.publisher = publisher;
1061
+ }
1062
+ list() {
1063
+ const rejected = this.closedRejection();
1064
+ if (rejected) return rejected;
1065
+ return AbortablePromise$1.run(async (signal) => this.http.getJsonWithRefresh(async (s) => {
1066
+ const manifest = await this.manifest.get(s);
1067
+ return wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
1068
+ }, (raw) => SignatureSnapshotSchema.parse(raw), async (s) => {
1069
+ await this.manifest.refresh(s);
1070
+ }, signal));
1071
+ }
1072
+ contents(field) {
1073
+ const rejected = this.closedRejection();
1074
+ if (rejected) return rejected;
1075
+ return AbortablePromise$1.run(async (signal) => {
1076
+ const manifest = await this.manifest.get(signal);
1077
+ const name = await this.fieldName(field, signal);
1078
+ return this.http.getBytes(wirePaths.docVersionSignatureContents(this.docId, manifest.baseSha, name), signal);
1079
+ });
1080
+ }
1081
+ digest(field, algorithm) {
1082
+ const rejected = this.closedRejection();
1083
+ if (rejected) return rejected;
1084
+ return AbortablePromise$1.run(async (signal) => {
1085
+ const manifest = await this.manifest.get(signal);
1086
+ const name = await this.fieldName(field, signal);
1087
+ return this.http.getBytes(wirePaths.docVersionSignatureDigest(this.docId, manifest.baseSha, name, algorithm), signal);
1088
+ });
1089
+ }
1090
+ revisionBytes(revisionIndex) {
1091
+ const rejected = this.closedRejection();
1092
+ if (rejected) return rejected;
1093
+ return AbortablePromise$1.run(async (signal) => {
1094
+ const manifest = await this.manifest.get(signal);
1095
+ return this.http.getBytes(wirePaths.docVersionRevision(this.docId, manifest.baseSha, revisionIndex), signal);
1096
+ });
1097
+ }
1098
+ /**
1099
+ * `until: 'working-copy'` (or unset while the layer holds edits) judges
1100
+ * the layer's pending edits against the base at the layer URL; anything
1101
+ * else is history of the base version and resolves at the version URL.
1102
+ */
1103
+ analyze(input) {
1104
+ const rejected = this.closedRejection();
1105
+ if (rejected) return rejected;
1106
+ return AbortablePromise$1.run(async (signal) => {
1107
+ const manifest = await this.manifest.get(signal);
1108
+ if (input.until === "working-copy" || input.until === void 0 && manifest.working) return this.http.getJsonWithRefresh(async (s) => {
1109
+ const current = await this.manifest.get(s);
1110
+ return wirePaths.layerSignaturesAnalysis(this.docId, this.layerName, {
1111
+ docVersion: current.docVersion,
1112
+ since: input.since,
1113
+ ...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
1114
+ ...input.detail !== void 0 ? { detail: input.detail } : {}
1115
+ });
1116
+ }, (raw) => ChangeAnalysisSchema.parse(raw), async (s) => {
1117
+ await this.manifest.refresh(s);
1118
+ }, signal);
1119
+ return this.http.getJson(wirePaths.docVersionAnalysis(this.docId, manifest.baseSha, {
1120
+ since: input.since,
1121
+ ...typeof input.until === "object" ? { until: input.until.revisionIndex } : {},
1122
+ ...input.exploratoryLevel !== void 0 ? { exploratoryLevel: input.exploratoryLevel } : {},
1123
+ ...input.detail !== void 0 ? { detail: input.detail } : {}
1124
+ }), (raw) => ChangeAnalysisSchema.parse(raw), signal);
1125
+ });
1126
+ }
1127
+ prepare(input) {
1128
+ const rejected = this.closedRejection();
1129
+ if (rejected) return rejected;
1130
+ return AbortablePromise$1.run(async (signal) => {
1131
+ const { appearance, ...rest } = input;
1132
+ const form = buildMutationForm({
1133
+ ...rest,
1134
+ ...appearance ? { appearance: {
1135
+ resource: "appearance",
1136
+ ...appearance.pageIndex !== void 0 ? { pageIndex: appearance.pageIndex } : {}
1137
+ } } : {}
1138
+ }, appearance ? { appearance: {
1139
+ bytes: appearance.pdf.slice().buffer,
1140
+ mimeType: "application/pdf",
1141
+ name: "appearance.pdf"
1142
+ } } : {});
1143
+ const prepared = await this.http.postMultipartJson(wirePaths.layerSignaturesPrepare(this.docId, this.layerName), form, (raw) => decodePrepared(SignaturePreparedWireSchema.parse(raw)), signal);
1144
+ await this.manifest.refresh(signal);
1145
+ this.publisher.publishLocal({
1146
+ type: "signature.prepared",
1147
+ signingId: prepared.signingId,
1148
+ field: input.field
1149
+ });
1150
+ return prepared;
1151
+ });
1152
+ }
1153
+ complete(input) {
1154
+ const rejected = this.closedRejection();
1155
+ if (rejected) return rejected;
1156
+ return AbortablePromise$1.run(async (signal) => {
1157
+ const result = await this.http.postJson(wirePaths.layerSignatureComplete(this.docId, this.layerName, input.signingId), {
1158
+ cms: toBase64(input.cms),
1159
+ expectedVersion: input.expectedVersion
1160
+ }, (raw) => SignatureCompleteResultSchema.parse(raw), signal);
1161
+ await this.manifest.refresh(signal);
1162
+ if (result.status === "completed") {
1163
+ this.publisher.publishLocal({
1164
+ type: "signature.completed",
1165
+ signingId: input.signingId,
1166
+ ...result
1167
+ });
1168
+ this.publisher.publishLocal({
1169
+ type: "document.versioned",
1170
+ version: result.version
1171
+ });
1172
+ }
1173
+ return result;
1174
+ });
1175
+ }
1176
+ abort(signingId) {
1177
+ const rejected = this.closedRejection();
1178
+ if (rejected) return rejected;
1179
+ return AbortablePromise$1.run(async (signal) => {
1180
+ const result = await this.http.deleteJson(wirePaths.layerSignatureAbort(this.docId, this.layerName, signingId), (raw) => SignatureAbortResultSchema.parse(raw), signal);
1181
+ if (result.status === "aborted") this.publisher.publishLocal({
1182
+ type: "signature.aborted",
1183
+ signingId
1184
+ });
1185
+ return result;
1186
+ });
1187
+ }
1188
+ /** Version routes address a field by its fully qualified name; an object-number ref is resolved through the snapshot. */
1189
+ async fieldName(field, signal) {
1190
+ if (field.kind === "fqn") return field.name;
1191
+ const match = (await this.http.getJsonWithRefresh(async (s) => {
1192
+ const manifest = await this.manifest.get(s);
1193
+ return wirePaths.layerSignatures(this.docId, this.layerName, manifest.docVersion);
1194
+ }, (raw) => SignatureSnapshotSchema.parse(raw), async (s) => {
1195
+ await this.manifest.refresh(s);
1196
+ }, signal)).signatures.find((s) => s.field.kind === "objectNumber" && s.field.fieldObjectNumber === field.fieldObjectNumber);
1197
+ if (!match) throw new EngineError$1(EngineErrorCode$1.NotFound, `no signature field #${field.fieldObjectNumber}`);
1198
+ return match.fieldName;
1199
+ }
1200
+ closedRejection() {
1201
+ if (!this.isClosed()) return null;
1202
+ return AbortablePromise$1.rejectReason(new EngineError$1(EngineErrorCode$1.DocNotOpen, `document ${this.docId} is closed`));
1203
+ }
1204
+ };
1205
+ //#endregion
1017
1206
  //#region src/document/CloudMetadataService.ts
1018
1207
  var CloudMetadataService = class {
1019
1208
  constructor(http, docId, layerName, isClosed, manifest, publisher) {
@@ -1426,6 +1615,41 @@ var CloudPageTextService = class {
1426
1615
  }
1427
1616
  };
1428
1617
  //#endregion
1618
+ //#region src/document/CloudPageMeasureService.ts
1619
+ var CloudPageMeasureService = class {
1620
+ constructor(http, docId, layerName, pon, isClosed, manifest, publisher) {
1621
+ this.http = http;
1622
+ this.docId = docId;
1623
+ this.layerName = layerName;
1624
+ this.pon = pon;
1625
+ this.isClosed = isClosed;
1626
+ this.manifest = manifest;
1627
+ this.publisher = publisher;
1628
+ }
1629
+ viewports() {
1630
+ return AbortablePromise$1.run(async (signal) => {
1631
+ this.check();
1632
+ return this.http.getJson(wirePaths.layerPageViewports(this.docId, this.layerName, this.pon), (raw) => PageMeasurementViewportSchema.array().parse(raw), signal);
1633
+ });
1634
+ }
1635
+ setScale(measure) {
1636
+ return AbortablePromise$1.run(async (signal) => {
1637
+ await Promise.resolve();
1638
+ signal.throwIfAborted();
1639
+ this.check();
1640
+ const result = await this.http.putJson(wirePaths.layerPageScale(this.docId, this.layerName, this.pon), { measure }, (raw) => PageScaleResultSchema.parse(raw), signal);
1641
+ this.manifest.apply(result.meta, []);
1642
+ this.publisher.publishLocal({
1643
+ type: "page.viewportsChanged",
1644
+ ...result
1645
+ });
1646
+ });
1647
+ }
1648
+ check() {
1649
+ if (this.isClosed()) throw new EngineError$1(EngineErrorCode$1.DocNotOpen, `Document not open: ${this.docId}`);
1650
+ }
1651
+ };
1652
+ //#endregion
1429
1653
  //#region src/document/CloudPageHandle.ts
1430
1654
  var CloudPageHandle = class {
1431
1655
  constructor(pageObjectNumber, pageIndex, http, docId, layerName, isClosed, manifest, publisher) {
@@ -1435,6 +1659,8 @@ var CloudPageHandle = class {
1435
1659
  _defineProperty(this, "text", void 0);
1436
1660
  _defineProperty(this, "geometry", void 0);
1437
1661
  _defineProperty(this, "render", void 0);
1662
+ _defineProperty(this, "measure", void 0);
1663
+ this.measure = new CloudPageMeasureService(http, docId, layerName, pageObjectNumber, isClosed, manifest, publisher);
1438
1664
  this.annotations = new CloudPageAnnotationsService(http, docId, layerName, pageObjectNumber, isClosed, manifest, publisher);
1439
1665
  this.text = new CloudPageTextService(http, docId, layerName, pageObjectNumber, isClosed, manifest);
1440
1666
  this.geometry = new CloudPageGeometryService(http, docId, layerName, pageObjectNumber, isClosed, manifest);
@@ -1467,6 +1693,11 @@ function auditRowToEvent(row, mySessionId) {
1467
1693
  serverId: row.id
1468
1694
  };
1469
1695
  switch (row.kind) {
1696
+ case "measure.setScale": return {
1697
+ type: "page.viewportsChanged",
1698
+ origin,
1699
+ ...row.payload
1700
+ };
1470
1701
  case "annot.create": return {
1471
1702
  type: "annotation.created",
1472
1703
  pageObjectNumber: row.pageObjectNumber ?? row.affectedPages[0] ?? 0,
@@ -1561,7 +1792,8 @@ function auditRowToEvent(row, mySessionId) {
1561
1792
  origin,
1562
1793
  ...row.payload
1563
1794
  };
1564
- case "form.updateField": return {
1795
+ case "form.updateField":
1796
+ case "form.setSignatureAppearance": return {
1565
1797
  type: "form.fieldUpdated",
1566
1798
  origin,
1567
1799
  ...row.payload
@@ -1701,6 +1933,7 @@ var CloudDocumentHandle = class {
1701
1933
  _defineProperty(this, "annotations", void 0);
1702
1934
  _defineProperty(this, "actions", void 0);
1703
1935
  _defineProperty(this, "attachments", void 0);
1936
+ _defineProperty(this, "signatures", void 0);
1704
1937
  _defineProperty(this, "forms", void 0);
1705
1938
  _defineProperty(this, "search", void 0);
1706
1939
  _defineProperty(this, "pages", void 0);
@@ -1770,6 +2003,7 @@ var CloudDocumentHandle = class {
1770
2003
  this.annotations = new CloudDocumentAnnotationsService(http, id, layerName, () => this.closed, this.manifestAccessor);
1771
2004
  this.actions = new CloudDocumentActionsService(http, id, layerName, () => this.closed, this.manifestAccessor);
1772
2005
  this.attachments = new CloudDocumentAttachmentsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
2006
+ this.signatures = new CloudDocumentSignaturesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
1773
2007
  this.forms = new CloudDocumentFormsService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
1774
2008
  this.search = new CloudDocumentSearchService(http, id, layerName, () => this.closed, this.manifestAccessor);
1775
2009
  this.pages = new CloudDocumentPagesService(http, id, layerName, () => this.closed, this.manifestAccessor, this.publisher);
@@ -1872,6 +2106,8 @@ var CloudDocumentHandle = class {
1872
2106
  ...this.manifestCache,
1873
2107
  docVersion: delta?.docVersion ?? this.manifestCache.docVersion,
1874
2108
  ...delta?.annotationsVersion !== void 0 ? { annotationsVersion: delta.annotationsVersion } : {},
2109
+ ...delta?.layerVersion !== void 0 ? { layerVersion: delta.layerVersion } : {},
2110
+ ...delta?.working !== void 0 ? { working: delta.working } : {},
1875
2111
  pages: Array.from(byPageObjectNumber.values()).sort((a, b) => a.state.pageObjectNumber - b.state.pageObjectNumber)
1876
2112
  };
1877
2113
  }
@@ -2081,6 +2317,9 @@ var CloudDocumentHandle = class {
2081
2317
  * whose hand caused the change. */
2082
2318
  absorbRemoteEvent(event) {
2083
2319
  switch (event.type) {
2320
+ case "page.viewportsChanged":
2321
+ this.absorbMutation(event.meta, []);
2322
+ return;
2084
2323
  case "annotation.created":
2085
2324
  case "annotation.updated":
2086
2325
  case "annotation.deleted":
@@ -2497,6 +2736,9 @@ var HttpClient = class HttpClient {
2497
2736
  const res = await this.requestJson(path, "POST", body, signal);
2498
2737
  return await this.parseJsonResponse(res, parser);
2499
2738
  }
2739
+ async putJson(path, body, parser, signal) {
2740
+ return this.parseJsonResponse(await this.requestJson(path, "PUT", body, signal), parser);
2741
+ }
2500
2742
  /** POST a JSON body and return the raw binary response (pages.extract). */
2501
2743
  async postJsonBytes(path, body, signal) {
2502
2744
  const res = await this.requestJson(path, "POST", body, signal);