@embedpdf/engine-services 3.0.0-next.7 → 3.0.0-next.9
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.cjs +155 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +156 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
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, PageInsertBlankSpec, 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
|
|
@@ -580,6 +580,15 @@ declare class PagesInserter {
|
|
|
580
580
|
private readonly session;
|
|
581
581
|
constructor(runtime: PdfRuntimeModule, session: DocumentSession);
|
|
582
582
|
insert(bytes: ArrayBuffer, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
|
|
583
|
+
/**
|
|
584
|
+
* Create `count` blank pages of `size` at `destIndex`. Same mutation
|
|
585
|
+
* contract as `insert`, but native creation (`FPDFPage_New`) instead of a
|
|
586
|
+
* deep copy: no source document, so none of the retain-until-close
|
|
587
|
+
* lifetime hazard above. Each page gets an empty content stream
|
|
588
|
+
* (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
|
|
589
|
+
* third-party viewers.
|
|
590
|
+
*/
|
|
591
|
+
insertBlank(spec: PageInsertBlankSpec, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
|
|
583
592
|
}
|
|
584
593
|
//#endregion
|
|
585
594
|
//#region src/features/pages/PagesFlattener.d.ts
|
|
@@ -1414,6 +1423,29 @@ declare class DocumentActionsReader {
|
|
|
1414
1423
|
}
|
|
1415
1424
|
//#endregion
|
|
1416
1425
|
//#region src/worker-host/WorkerHost.d.ts
|
|
1426
|
+
/** The image a {@link WorkerImageEncoder} produced. `bytes` must OWN its
|
|
1427
|
+
* buffer (a fresh allocation, not a pooled `Buffer` slab view) — it is
|
|
1428
|
+
* placed on the transfer manifest and moved zero-copy. */
|
|
1429
|
+
interface WorkerEncodedImage {
|
|
1430
|
+
contentType: string;
|
|
1431
|
+
bytes: Uint8Array;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Injected image-encode capability for the `*.renderEncoded` wire kinds.
|
|
1435
|
+
* Dependency inversion keeps the native encoder OUT of this shared
|
|
1436
|
+
* package: the cloud server's worker entry injects a sharp/libvips
|
|
1437
|
+
* implementation; browser/local entries inject nothing (they encode via
|
|
1438
|
+
* canvas) and the encoded kinds reject with `NotImplemented`.
|
|
1439
|
+
*/
|
|
1440
|
+
interface WorkerImageEncoder {
|
|
1441
|
+
encode(raster: PageRaster, opts: {
|
|
1442
|
+
format: PageNetworkRenderFormat;
|
|
1443
|
+
quality?: number;
|
|
1444
|
+
}): Promise<WorkerEncodedImage>;
|
|
1445
|
+
}
|
|
1446
|
+
interface WorkerHostOptions {
|
|
1447
|
+
imageEncoder?: WorkerImageEncoder;
|
|
1448
|
+
}
|
|
1417
1449
|
/**
|
|
1418
1450
|
* The piece that runs "inside the worker": owns runtime, manages document
|
|
1419
1451
|
* sessions, dispatches requests to the engine-services synchronous code.
|
|
@@ -1435,6 +1467,8 @@ declare class WorkerHost {
|
|
|
1435
1467
|
* runs in.
|
|
1436
1468
|
*/
|
|
1437
1469
|
private readonly post;
|
|
1470
|
+
/** Optional capabilities. See {@link WorkerHostOptions}. */
|
|
1471
|
+
private readonly options;
|
|
1438
1472
|
private readonly sessions;
|
|
1439
1473
|
private readonly baseDocuments;
|
|
1440
1474
|
private readonly aborts;
|
|
@@ -1456,7 +1490,9 @@ declare class WorkerHost {
|
|
|
1456
1490
|
* pack.transfer)` — the host doesn't know which environment it
|
|
1457
1491
|
* runs in.
|
|
1458
1492
|
*/
|
|
1459
|
-
post: (pack: WirePack<WorkerResponse>) => void
|
|
1493
|
+
post: (pack: WirePack<WorkerResponse>) => void,
|
|
1494
|
+
/** Optional capabilities. See {@link WorkerHostOptions}. */
|
|
1495
|
+
options?: WorkerHostOptions);
|
|
1460
1496
|
/**
|
|
1461
1497
|
* Register deployment-owned fonts on this worker thread, after init and
|
|
1462
1498
|
* before serving requests. Server-only: the cloud engine never exposes font
|
|
@@ -1486,6 +1522,7 @@ declare class WorkerHost {
|
|
|
1486
1522
|
private handleRedactionApply;
|
|
1487
1523
|
private handlePagesExtract;
|
|
1488
1524
|
private handlePagesInsert;
|
|
1525
|
+
private handlePagesInsertBlank;
|
|
1489
1526
|
private handleAttachmentsList;
|
|
1490
1527
|
private handleAttachmentsReadFile;
|
|
1491
1528
|
private handleAttachmentsCreate;
|
|
@@ -1499,6 +1536,11 @@ declare class WorkerHost {
|
|
|
1499
1536
|
private handlePagesGeometry;
|
|
1500
1537
|
private handleSearchQuery;
|
|
1501
1538
|
private handlePagesRender;
|
|
1539
|
+
private receiveEncoded;
|
|
1540
|
+
private encodeRaster;
|
|
1541
|
+
private handlePagesRenderEncoded;
|
|
1542
|
+
private handleDocumentRenderPageFileEncoded;
|
|
1543
|
+
private handleAnnotationsRenderAppearancesEncoded;
|
|
1502
1544
|
private handleDocumentSaveBuffer;
|
|
1503
1545
|
private handleDocumentSaveFile;
|
|
1504
1546
|
private handleDocumentSaveLayerBuffer;
|
|
@@ -1553,5 +1595,5 @@ declare class WorkerHost {
|
|
|
1553
1595
|
private saveLayerArtifact;
|
|
1554
1596
|
}
|
|
1555
1597
|
//#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 };
|
|
1598
|
+
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
1599
|
//# 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, PageInsertBlankSpec, 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
|
/**
|
|
@@ -580,6 +580,15 @@ declare class PagesInserter {
|
|
|
580
580
|
private readonly session;
|
|
581
581
|
constructor(runtime: PdfRuntimeModule, session: DocumentSession);
|
|
582
582
|
insert(bytes: ArrayBuffer, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
|
|
583
|
+
/**
|
|
584
|
+
* Create `count` blank pages of `size` at `destIndex`. Same mutation
|
|
585
|
+
* contract as `insert`, but native creation (`FPDFPage_New`) instead of a
|
|
586
|
+
* deep copy: no source document, so none of the retain-until-close
|
|
587
|
+
* lifetime hazard above. Each page gets an empty content stream
|
|
588
|
+
* (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
|
|
589
|
+
* third-party viewers.
|
|
590
|
+
*/
|
|
591
|
+
insertBlank(spec: PageInsertBlankSpec, destIndex: number | undefined, signal: AbortSignal): PageInsertResult;
|
|
583
592
|
}
|
|
584
593
|
//#endregion
|
|
585
594
|
//#region src/features/pages/PagesFlattener.d.ts
|
|
@@ -1414,6 +1423,29 @@ declare class DocumentActionsReader {
|
|
|
1414
1423
|
}
|
|
1415
1424
|
//#endregion
|
|
1416
1425
|
//#region src/worker-host/WorkerHost.d.ts
|
|
1426
|
+
/** The image a {@link WorkerImageEncoder} produced. `bytes` must OWN its
|
|
1427
|
+
* buffer (a fresh allocation, not a pooled `Buffer` slab view) — it is
|
|
1428
|
+
* placed on the transfer manifest and moved zero-copy. */
|
|
1429
|
+
interface WorkerEncodedImage {
|
|
1430
|
+
contentType: string;
|
|
1431
|
+
bytes: Uint8Array;
|
|
1432
|
+
}
|
|
1433
|
+
/**
|
|
1434
|
+
* Injected image-encode capability for the `*.renderEncoded` wire kinds.
|
|
1435
|
+
* Dependency inversion keeps the native encoder OUT of this shared
|
|
1436
|
+
* package: the cloud server's worker entry injects a sharp/libvips
|
|
1437
|
+
* implementation; browser/local entries inject nothing (they encode via
|
|
1438
|
+
* canvas) and the encoded kinds reject with `NotImplemented`.
|
|
1439
|
+
*/
|
|
1440
|
+
interface WorkerImageEncoder {
|
|
1441
|
+
encode(raster: PageRaster, opts: {
|
|
1442
|
+
format: PageNetworkRenderFormat;
|
|
1443
|
+
quality?: number;
|
|
1444
|
+
}): Promise<WorkerEncodedImage>;
|
|
1445
|
+
}
|
|
1446
|
+
interface WorkerHostOptions {
|
|
1447
|
+
imageEncoder?: WorkerImageEncoder;
|
|
1448
|
+
}
|
|
1417
1449
|
/**
|
|
1418
1450
|
* The piece that runs "inside the worker": owns runtime, manages document
|
|
1419
1451
|
* sessions, dispatches requests to the engine-services synchronous code.
|
|
@@ -1435,6 +1467,8 @@ declare class WorkerHost {
|
|
|
1435
1467
|
* runs in.
|
|
1436
1468
|
*/
|
|
1437
1469
|
private readonly post;
|
|
1470
|
+
/** Optional capabilities. See {@link WorkerHostOptions}. */
|
|
1471
|
+
private readonly options;
|
|
1438
1472
|
private readonly sessions;
|
|
1439
1473
|
private readonly baseDocuments;
|
|
1440
1474
|
private readonly aborts;
|
|
@@ -1456,7 +1490,9 @@ declare class WorkerHost {
|
|
|
1456
1490
|
* pack.transfer)` — the host doesn't know which environment it
|
|
1457
1491
|
* runs in.
|
|
1458
1492
|
*/
|
|
1459
|
-
post: (pack: WirePack<WorkerResponse>) => void
|
|
1493
|
+
post: (pack: WirePack<WorkerResponse>) => void,
|
|
1494
|
+
/** Optional capabilities. See {@link WorkerHostOptions}. */
|
|
1495
|
+
options?: WorkerHostOptions);
|
|
1460
1496
|
/**
|
|
1461
1497
|
* Register deployment-owned fonts on this worker thread, after init and
|
|
1462
1498
|
* before serving requests. Server-only: the cloud engine never exposes font
|
|
@@ -1486,6 +1522,7 @@ declare class WorkerHost {
|
|
|
1486
1522
|
private handleRedactionApply;
|
|
1487
1523
|
private handlePagesExtract;
|
|
1488
1524
|
private handlePagesInsert;
|
|
1525
|
+
private handlePagesInsertBlank;
|
|
1489
1526
|
private handleAttachmentsList;
|
|
1490
1527
|
private handleAttachmentsReadFile;
|
|
1491
1528
|
private handleAttachmentsCreate;
|
|
@@ -1499,6 +1536,11 @@ declare class WorkerHost {
|
|
|
1499
1536
|
private handlePagesGeometry;
|
|
1500
1537
|
private handleSearchQuery;
|
|
1501
1538
|
private handlePagesRender;
|
|
1539
|
+
private receiveEncoded;
|
|
1540
|
+
private encodeRaster;
|
|
1541
|
+
private handlePagesRenderEncoded;
|
|
1542
|
+
private handleDocumentRenderPageFileEncoded;
|
|
1543
|
+
private handleAnnotationsRenderAppearancesEncoded;
|
|
1502
1544
|
private handleDocumentSaveBuffer;
|
|
1503
1545
|
private handleDocumentSaveFile;
|
|
1504
1546
|
private handleDocumentSaveLayerBuffer;
|
|
@@ -1553,5 +1595,5 @@ declare class WorkerHost {
|
|
|
1553
1595
|
private saveLayerArtifact;
|
|
1554
1596
|
}
|
|
1555
1597
|
//#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 };
|
|
1598
|
+
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
1599
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbortError, EMPTY_TRANSFER, EngineError, EngineErrorCode, NO_ANNOTATION_FLAGS, PDF_SUBTYPE_TO_CODE, PdfAnnotationSubtypeCode, UNKNOWN_WEAK_ANNOTATION_STATE, appearanceImpactOf, buildPageTextLayout, buildSnippet, charMapViolation, charRangeForTextOffsets, foldOptionsFor, foldText, invalidatesWeakIndexRefs, isValidPageObjectNumber, knownWeakAnnotationState, matchLiteral, matchRegex, normalizePdfRect, pdfQuadBounds, revisionTokensEqual, serializeError, shiftsExistingAnnotationIndices, sniffBinaryMetadata, subtypeFromCode, textSegmentsForRange, validateSearchQuery, wirePack } from "@embedpdf/engine-core/runtime";
|
|
1
|
+
import { AbortError, EMPTY_TRANSFER, EngineError, EngineErrorCode, NO_ANNOTATION_FLAGS, PAGE_INSERT_BLANK_MAX_COUNT, PDF_SUBTYPE_TO_CODE, PdfAnnotationSubtypeCode, UNKNOWN_WEAK_ANNOTATION_STATE, appearanceImpactOf, buildPageTextLayout, buildSnippet, charMapViolation, charRangeForTextOffsets, foldOptionsFor, foldText, invalidatesWeakIndexRefs, isValidPageObjectNumber, knownWeakAnnotationState, matchLiteral, matchRegex, normalizePdfRect, pdfQuadBounds, revisionTokensEqual, serializeError, shiftsExistingAnnotationIndices, sniffBinaryMetadata, subtypeFromCode, textSegmentsForRange, validateSearchQuery, wirePack } from "@embedpdf/engine-core/runtime";
|
|
2
2
|
import { NULL_PTR } from "@embedpdf/engine-runtime";
|
|
3
3
|
//#region src/runtime/lifecycle/bootstrap.ts
|
|
4
4
|
const initialized = /* @__PURE__ */ new WeakSet();
|
|
@@ -1726,6 +1726,42 @@ var PagesInserter = class {
|
|
|
1726
1726
|
cache: null
|
|
1727
1727
|
};
|
|
1728
1728
|
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Create `count` blank pages of `size` at `destIndex`. Same mutation
|
|
1731
|
+
* contract as `insert`, but native creation (`FPDFPage_New`) instead of a
|
|
1732
|
+
* deep copy: no source document, so none of the retain-until-close
|
|
1733
|
+
* lifetime hazard above. Each page gets an empty content stream
|
|
1734
|
+
* (`FPDFPage_GenerateContent`) so the saved PDF renders identically in
|
|
1735
|
+
* third-party viewers.
|
|
1736
|
+
*/
|
|
1737
|
+
insertBlank(spec, destIndex, signal) {
|
|
1738
|
+
throwIfAborted(signal);
|
|
1739
|
+
const { size } = spec;
|
|
1740
|
+
const count = spec.count ?? 1;
|
|
1741
|
+
if (!Number.isFinite(size?.width) || !Number.isFinite(size?.height) || size.width <= 0 || size.height <= 0) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank size must have positive finite dimensions, got ${size?.width}x${size?.height}`);
|
|
1742
|
+
if (!Number.isInteger(count) || count < 1 || count > PAGE_INSERT_BLANK_MAX_COUNT) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank count ${count} out of range [1, ${PAGE_INSERT_BLANK_MAX_COUNT}]`);
|
|
1743
|
+
const { fn } = this.runtime;
|
|
1744
|
+
const destPtr = this.session.requireDocPtr();
|
|
1745
|
+
const beforeCount = fn.FPDF_GetPageCount(destPtr);
|
|
1746
|
+
const at = destIndex ?? beforeCount;
|
|
1747
|
+
if (!Number.isInteger(at) || at < 0 || at > beforeCount) throw new EngineError(EngineErrorCode.InvalidArg, `pages.insertBlank destIndex ${at} out of range [0, ${beforeCount}]`);
|
|
1748
|
+
for (let i = 0; i < count; i++) {
|
|
1749
|
+
const pagePtr = fn.FPDFPage_New(destPtr, at + i, size.width, size.height);
|
|
1750
|
+
if (!pagePtr) {
|
|
1751
|
+
for (let j = 0; j < i; j++) fn.FPDFPage_Delete(destPtr, at);
|
|
1752
|
+
throw new EngineError(EngineErrorCode.Unknown, `FPDFPage_New rejected page ${i + 1}/${count} at index ${at + i}`);
|
|
1753
|
+
}
|
|
1754
|
+
fn.FPDFPage_GenerateContent(pagePtr);
|
|
1755
|
+
fn.FPDF_ClosePage(pagePtr);
|
|
1756
|
+
}
|
|
1757
|
+
this.session.refreshPageRegistry();
|
|
1758
|
+
const layout = new PagesReader(this.runtime, this.session).read(signal);
|
|
1759
|
+
return {
|
|
1760
|
+
insertedPageObjectNumbers: layout.pages.slice(at, at + count).map((page) => page.pageObjectNumber),
|
|
1761
|
+
layout,
|
|
1762
|
+
cache: null
|
|
1763
|
+
};
|
|
1764
|
+
}
|
|
1729
1765
|
};
|
|
1730
1766
|
//#endregion
|
|
1731
1767
|
//#region src/features/annotations/internal/read/annotationReadContext.ts
|
|
@@ -9250,9 +9286,10 @@ function validatePatchValue(key, value) {
|
|
|
9250
9286
|
* worker wire shape from @embedpdf/engine-core.
|
|
9251
9287
|
*/
|
|
9252
9288
|
var WorkerHost = class {
|
|
9253
|
-
constructor(runtime, post) {
|
|
9289
|
+
constructor(runtime, post, options = {}) {
|
|
9254
9290
|
this.runtime = runtime;
|
|
9255
9291
|
this.post = post;
|
|
9292
|
+
this.options = options;
|
|
9256
9293
|
_defineProperty(this, "sessions", /* @__PURE__ */ new Map());
|
|
9257
9294
|
_defineProperty(this, "baseDocuments", void 0);
|
|
9258
9295
|
_defineProperty(this, "aborts", /* @__PURE__ */ new Map());
|
|
@@ -9278,6 +9315,10 @@ var WorkerHost = class {
|
|
|
9278
9315
|
this.aborts.get(msg.jobId)?.abort();
|
|
9279
9316
|
return;
|
|
9280
9317
|
}
|
|
9318
|
+
if (msg.kind === "pages.renderEncoded" || msg.kind === "document.renderPageFileEncoded" || msg.kind === "annotations.renderAppearancesEncoded") {
|
|
9319
|
+
this.receiveEncoded(msg);
|
|
9320
|
+
return;
|
|
9321
|
+
}
|
|
9281
9322
|
const ctrl = new AbortController();
|
|
9282
9323
|
this.aborts.set(msg.jobId, ctrl);
|
|
9283
9324
|
let resultPack;
|
|
@@ -9381,6 +9422,9 @@ var WorkerHost = class {
|
|
|
9381
9422
|
case "pages.insert":
|
|
9382
9423
|
resultPack = this.handlePagesInsert(msg, ctrl.signal);
|
|
9383
9424
|
break;
|
|
9425
|
+
case "pages.insertBlank":
|
|
9426
|
+
resultPack = this.handlePagesInsertBlank(msg, ctrl.signal);
|
|
9427
|
+
break;
|
|
9384
9428
|
case "attachments.list":
|
|
9385
9429
|
resultPack = this.handleAttachmentsList(msg, ctrl.signal);
|
|
9386
9430
|
break;
|
|
@@ -9673,6 +9717,17 @@ var WorkerHost = class {
|
|
|
9673
9717
|
result
|
|
9674
9718
|
}, req.artifactPath);
|
|
9675
9719
|
}
|
|
9720
|
+
handlePagesInsertBlank(req, signal) {
|
|
9721
|
+
const session = this.requireSession(req);
|
|
9722
|
+
const result = new PagesInserter(this.runtime, session).insertBlank({
|
|
9723
|
+
size: req.size,
|
|
9724
|
+
count: req.count
|
|
9725
|
+
}, req.destIndex, signal);
|
|
9726
|
+
return this.finishMutation(session, {
|
|
9727
|
+
tag: "pages.insertBlank",
|
|
9728
|
+
result
|
|
9729
|
+
}, req.artifactPath);
|
|
9730
|
+
}
|
|
9676
9731
|
handleAttachmentsList(req, signal) {
|
|
9677
9732
|
const session = this.requireSession(req);
|
|
9678
9733
|
return wirePack({
|
|
@@ -9765,6 +9820,105 @@ var WorkerHost = class {
|
|
|
9765
9820
|
raster
|
|
9766
9821
|
}, [raster.data]);
|
|
9767
9822
|
}
|
|
9823
|
+
async receiveEncoded(msg) {
|
|
9824
|
+
if (!this.options.imageEncoder) {
|
|
9825
|
+
this.post(wirePack({
|
|
9826
|
+
kind: "reject",
|
|
9827
|
+
jobId: msg.jobId,
|
|
9828
|
+
error: serializeError(new EngineError(EngineErrorCode.NotImplemented, "this engine has no image encoder (the *.renderEncoded kinds are cloud-server surface)"))
|
|
9829
|
+
}, EMPTY_TRANSFER));
|
|
9830
|
+
return;
|
|
9831
|
+
}
|
|
9832
|
+
const ctrl = new AbortController();
|
|
9833
|
+
this.aborts.set(msg.jobId, ctrl);
|
|
9834
|
+
try {
|
|
9835
|
+
let resultPack;
|
|
9836
|
+
switch (msg.kind) {
|
|
9837
|
+
case "pages.renderEncoded":
|
|
9838
|
+
resultPack = await this.handlePagesRenderEncoded(msg, ctrl.signal);
|
|
9839
|
+
break;
|
|
9840
|
+
case "document.renderPageFileEncoded":
|
|
9841
|
+
resultPack = await this.handleDocumentRenderPageFileEncoded(msg, ctrl.signal);
|
|
9842
|
+
break;
|
|
9843
|
+
case "annotations.renderAppearancesEncoded":
|
|
9844
|
+
resultPack = await this.handleAnnotationsRenderAppearancesEncoded(msg, ctrl.signal);
|
|
9845
|
+
break;
|
|
9846
|
+
}
|
|
9847
|
+
this.post(wirePack({
|
|
9848
|
+
kind: "resolve",
|
|
9849
|
+
jobId: msg.jobId,
|
|
9850
|
+
result: resultPack.payload
|
|
9851
|
+
}, resultPack.transfer));
|
|
9852
|
+
} catch (err) {
|
|
9853
|
+
this.post(wirePack({
|
|
9854
|
+
kind: "reject",
|
|
9855
|
+
jobId: msg.jobId,
|
|
9856
|
+
error: serializeError(err)
|
|
9857
|
+
}, EMPTY_TRANSFER));
|
|
9858
|
+
} finally {
|
|
9859
|
+
this.aborts.delete(msg.jobId);
|
|
9860
|
+
}
|
|
9861
|
+
}
|
|
9862
|
+
async encodeRaster(raster, encode, signal) {
|
|
9863
|
+
const encoder = this.options.imageEncoder;
|
|
9864
|
+
if (!encoder) throw new EngineError(EngineErrorCode.NotImplemented, "this engine has no image encoder (the *.renderEncoded kinds are cloud-server surface)");
|
|
9865
|
+
const { bytes, contentType } = await encoder.encode(raster, encode);
|
|
9866
|
+
if (signal.aborted) throw new EngineError(EngineErrorCode.Aborted, "aborted during image encode");
|
|
9867
|
+
return {
|
|
9868
|
+
contentType,
|
|
9869
|
+
width: raster.width,
|
|
9870
|
+
height: raster.height,
|
|
9871
|
+
bytes
|
|
9872
|
+
};
|
|
9873
|
+
}
|
|
9874
|
+
async handlePagesRenderEncoded(req, signal) {
|
|
9875
|
+
const inner = this.handlePagesRender({
|
|
9876
|
+
...req,
|
|
9877
|
+
kind: "pages.render"
|
|
9878
|
+
}, signal);
|
|
9879
|
+
if (inner.payload.tag !== "pages.render") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
|
|
9880
|
+
const image = await this.encodeRaster(inner.payload.raster, req.encode, signal);
|
|
9881
|
+
return wirePack({
|
|
9882
|
+
tag: "pages.renderEncoded",
|
|
9883
|
+
image
|
|
9884
|
+
}, [image.bytes.buffer]);
|
|
9885
|
+
}
|
|
9886
|
+
async handleDocumentRenderPageFileEncoded(req, signal) {
|
|
9887
|
+
const inner = this.handleDocumentRenderPageFile({
|
|
9888
|
+
...req,
|
|
9889
|
+
kind: "document.renderPageFile"
|
|
9890
|
+
}, signal);
|
|
9891
|
+
if (inner.payload.tag !== "document.renderPageFile") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
|
|
9892
|
+
const image = await this.encodeRaster(inner.payload.raster, req.encode, signal);
|
|
9893
|
+
return wirePack({
|
|
9894
|
+
tag: "document.renderPageFileEncoded",
|
|
9895
|
+
pageObjectNumber: inner.payload.pageObjectNumber,
|
|
9896
|
+
pageCount: inner.payload.pageCount,
|
|
9897
|
+
image
|
|
9898
|
+
}, [image.bytes.buffer]);
|
|
9899
|
+
}
|
|
9900
|
+
async handleAnnotationsRenderAppearancesEncoded(req, signal) {
|
|
9901
|
+
const inner = this.handleAnnotationsRenderAppearances({
|
|
9902
|
+
...req,
|
|
9903
|
+
kind: "annotations.renderAppearances"
|
|
9904
|
+
}, signal);
|
|
9905
|
+
if (inner.payload.tag !== "annotations.renderAppearances") throw new EngineError(EngineErrorCode.WireFormat, `unexpected ${inner.payload.tag}`);
|
|
9906
|
+
const { pageState, appearances } = inner.payload.result;
|
|
9907
|
+
const encoded = [];
|
|
9908
|
+
for (const a of appearances) encoded.push({
|
|
9909
|
+
ref: a.ref,
|
|
9910
|
+
mode: a.mode,
|
|
9911
|
+
rect: a.rect,
|
|
9912
|
+
image: await this.encodeRaster(a.raster, req.encode, signal)
|
|
9913
|
+
});
|
|
9914
|
+
return wirePack({
|
|
9915
|
+
tag: "annotations.renderAppearancesEncoded",
|
|
9916
|
+
result: {
|
|
9917
|
+
pageState,
|
|
9918
|
+
appearances: encoded
|
|
9919
|
+
}
|
|
9920
|
+
}, encoded.map((e) => e.image.bytes.buffer));
|
|
9921
|
+
}
|
|
9768
9922
|
handleDocumentSaveBuffer(req) {
|
|
9769
9923
|
const session = this.requireSession(req);
|
|
9770
9924
|
const saved = new DocumentSaver(this.runtime, session).saveStandaloneToBuffer(req.mode);
|