@embedpdf/engine-services 3.0.0-next.0 → 3.0.0-next.10

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, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, 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
@@ -626,29 +635,33 @@ declare class RedactionApplier {
626
635
  */
627
636
  private preflight;
628
637
  private applyAllOnPage;
638
+ private pageHasRedactAnnotations;
629
639
  private applyRefsOnPage;
630
640
  }
631
641
  //#endregion
632
642
  //#region src/features/text/PageTextReader.d.ts
633
643
  /**
634
644
  * Per-page slow-path text reader. Acquires a `pagePtr` from the
635
- * `PagePtrPool`, opens a PDFium text page (`FPDFText_LoadPage`),
636
- * extracts the full UTF-16 buffer with `FPDFText_GetText`, decodes,
637
- * and releases everything in reverse order.
645
+ * `PagePtrPool`, opens a PDFium text page (`FPDFText_LoadPage`), extracts
646
+ * the page text, and releases everything in reverse order.
647
+ *
648
+ * Index spaces (see engine-core `text/charmap.ts`): `charCount` is the
649
+ * CHARACTER space (`FPDFText_CountChars` — the space geometry runs tile);
650
+ * `text` is the TEXT projection. The two diverge when a character
651
+ * contributes zero text units (non-printing) or two (supplementary plane);
652
+ * `charMap` anchors encode exactly those deviations.
638
653
  *
639
- * Memory model:
640
- * - `count` is in UTF-16 code units (FPDFText's "char").
641
- * - The buffer needs `(count + 1) * 2` bytes (PDFium writes a
642
- * trailing NUL terminator).
643
- * - `mem.readU16String` walks the buffer up to the NUL and decodes
644
- * to a JS string, faithfully preserving surrogate pairs.
654
+ * Both come from the fork's batched extension calls, which share one
655
+ * encoding authority (`FX_UTF16Encode`) so text and map can never
656
+ * disagree:
645
657
  *
646
- * Errors:
647
- * - `EPDFDoc_LoadPageByObjectNumber` returning 0 is `NotFound`
648
- * (raised by `PagePtrPool.acquire`).
649
- * - `FPDFText_LoadPage` returning 0 is `RuntimeUnavailable` — should
650
- * not happen on a healthy page; treat it as a runtime bug rather
651
- * than user error.
658
+ * - `EPDFText_GetTextFull` — true UTF-16LE extraction; supplementary
659
+ * characters arrive as surrogate pairs instead of being silently
660
+ * dropped by `FPDFText_GetText`'s UCS-2 encoder. Called once with an
661
+ * upper-bound buffer (2 units per character + NUL), so no measure
662
+ * round-trip.
663
+ * - `EPDFText_GetCharToTextMap` — the anchors, measure-then-fill. Zero
664
+ * anchors is the common (identity) page and skips the fill call.
652
665
  */
653
666
  declare class PageTextReader {
654
667
  private readonly runtime;
@@ -658,21 +671,93 @@ declare class PageTextReader {
658
671
  }
659
672
  //#endregion
660
673
  //#region src/features/geometry/PageGeometryReader.d.ts
674
+ /**
675
+ * One glyph as read from `EPDFText_GetCharGeometry`, plus the run-grouping
676
+ * context sampled alongside it. Pure data — no native handles — so the
677
+ * grouping stage below is a pure function the tests can drive directly.
678
+ */
679
+ interface RawGeometryGlyphRecord {
680
+ /** Grouping key: the glyph's text object handle (opaque identity). */
681
+ objectKey: number | bigint;
682
+ /** Sampled at each text object's first glyph (run splits inherit it). */
683
+ fontSize?: number;
684
+ /**
685
+ * Wire flags (bit 1 = space, bit 2 = empty). Synthesized-but-visible
686
+ * glyphs (/ActualText pieces) stay 0, exactly like the legacy reader —
687
+ * they represent real, selectable text.
688
+ */
689
+ flags: number;
690
+ /** Page-space AABB (zeroed when empty). */
691
+ looseBox: PdfRect;
692
+ tightBox?: PdfRect;
693
+ /** Oriented cells — real glyphs with a usable (non-singular) matrix only. */
694
+ looseQuad?: PdfQuad;
695
+ tightQuad?: PdfQuad;
696
+ /** Native uprightness of the char matrix (empty glyphs: true, inert). */
697
+ upright: boolean;
698
+ /** Baseline angle (radians CCW, PDF y-up); 0 when upright. */
699
+ rotation: number;
700
+ /** True when the ascent vector maps opposite the rotated +y (det < 0). */
701
+ ascentFlip: boolean;
702
+ }
661
703
  /**
662
704
  * Geometry-only text layout reader.
663
705
  *
664
706
  * Emits geometry in PDF user space (y-up edges) — the canonical engine
665
707
  * geometry. The viewer converts to content/view space via the page geometry
666
708
  * matrix; this reader applies NO Y-flip or device transform.
709
+ *
710
+ * One `EPDFText_GetCharGeometry` call per glyph supplies boxes, oriented
711
+ * cells, and flags together; `buildRunsFromRawGlyphs` then groups glyphs
712
+ * into the upright/rotated run union. Upright runs are byte-identical to the
713
+ * pre-orientation reader (quads the native layer offers are deliberately
714
+ * dropped — the dominant case never pays for orientation).
667
715
  */
668
716
  declare class PageGeometryReader {
669
717
  private readonly runtime;
670
718
  private readonly session;
671
719
  constructor(runtime: PdfRuntimeModule, session: DocumentSession);
672
720
  read(pageObjectNumber: PageObjectNumber, signal: AbortSignal): PageGeometrySnapshot;
673
- private buildRunsFromGlyphs;
674
- private readGlyphInfo;
721
+ private readGlyphRaw;
675
722
  }
723
+ /**
724
+ * Group per-glyph records into the run union. Pure — exported for tests.
725
+ *
726
+ * Runs split on text-object change (the legacy rule) and on orientation
727
+ * change between classifiable glyphs (θ drift / mixed orientation). A run's
728
+ * variant is decided by its FIRST classifiable glyph:
729
+ * - empty glyphs never classify (they adopt the run's variant);
730
+ * - real glyphs WITHOUT an oriented cell (singular matrix, synthesized
731
+ * /ActualText pieces) classify as upright — box-only data degrades to
732
+ * exactly the legacy behavior;
733
+ * - real glyphs with a non-upright matrix classify as rotated.
734
+ * Runs that never see a classifiable glyph emit as upright (degenerate,
735
+ * legacy behavior).
736
+ */
737
+ declare function buildRunsFromRawGlyphs(records: RawGeometryGlyphRecord[]): PageGeometryRun[];
738
+ //#endregion
739
+ //#region src/runtime/memory/structs.d.ts
740
+ /** Generated from `EPDF_CHAR_GEOMETRY`; pinned by native static_asserts. */
741
+ declare const EPDF_CHAR_GEOMETRY_LAYOUT: {
742
+ readonly bytes: 124;
743
+ readonly offsets: {
744
+ readonly looseBox: 0;
745
+ readonly tightBox: 16;
746
+ readonly looseQuad: 32;
747
+ readonly tightQuad: 64;
748
+ readonly matrix: 96;
749
+ readonly flags: 120;
750
+ };
751
+ readonly flags: {
752
+ readonly hasTightBox: number;
753
+ readonly hasLooseQuad: number;
754
+ readonly hasTightQuad: number;
755
+ readonly upright: number;
756
+ readonly space: number;
757
+ readonly empty: number;
758
+ readonly synthesized: number;
759
+ };
760
+ };
676
761
  //#endregion
677
762
  //#region src/features/render/PageRenderReader.d.ts
678
763
  declare class PageRenderReader {
@@ -1338,6 +1423,29 @@ declare class DocumentActionsReader {
1338
1423
  }
1339
1424
  //#endregion
1340
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
+ }
1341
1449
  /**
1342
1450
  * The piece that runs "inside the worker": owns runtime, manages document
1343
1451
  * sessions, dispatches requests to the engine-services synchronous code.
@@ -1359,6 +1467,8 @@ declare class WorkerHost {
1359
1467
  * runs in.
1360
1468
  */
1361
1469
  private readonly post;
1470
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1471
+ private readonly options;
1362
1472
  private readonly sessions;
1363
1473
  private readonly baseDocuments;
1364
1474
  private readonly aborts;
@@ -1380,7 +1490,9 @@ declare class WorkerHost {
1380
1490
  * pack.transfer)` — the host doesn't know which environment it
1381
1491
  * runs in.
1382
1492
  */
1383
- post: (pack: WirePack<WorkerResponse>) => void);
1493
+ post: (pack: WirePack<WorkerResponse>) => void,
1494
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1495
+ options?: WorkerHostOptions);
1384
1496
  /**
1385
1497
  * Register deployment-owned fonts on this worker thread, after init and
1386
1498
  * before serving requests. Server-only: the cloud engine never exposes font
@@ -1410,6 +1522,7 @@ declare class WorkerHost {
1410
1522
  private handleRedactionApply;
1411
1523
  private handlePagesExtract;
1412
1524
  private handlePagesInsert;
1525
+ private handlePagesInsertBlank;
1413
1526
  private handleAttachmentsList;
1414
1527
  private handleAttachmentsReadFile;
1415
1528
  private handleAttachmentsCreate;
@@ -1423,6 +1536,11 @@ declare class WorkerHost {
1423
1536
  private handlePagesGeometry;
1424
1537
  private handleSearchQuery;
1425
1538
  private handlePagesRender;
1539
+ private receiveEncoded;
1540
+ private encodeRaster;
1541
+ private handlePagesRenderEncoded;
1542
+ private handleDocumentRenderPageFileEncoded;
1543
+ private handleAnnotationsRenderAppearancesEncoded;
1426
1544
  private handleDocumentSaveBuffer;
1427
1545
  private handleDocumentSaveFile;
1428
1546
  private handleDocumentSaveLayerBuffer;
@@ -1477,5 +1595,5 @@ declare class WorkerHost {
1477
1595
  private saveLayerArtifact;
1478
1596
  }
1479
1597
  //#endregion
1480
- export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, 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, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, WorkerHost, 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 };
1481
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, PageGeometrySnapshot, PageInsertResult, PageListSnapshot, PageMoveResult, PageObjectNumber, PageRenderOptions, PageRotateResult, PageRotation, PageState, PageTextSnapshot, PdfActionTree, 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
@@ -626,29 +635,33 @@ declare class RedactionApplier {
626
635
  */
627
636
  private preflight;
628
637
  private applyAllOnPage;
638
+ private pageHasRedactAnnotations;
629
639
  private applyRefsOnPage;
630
640
  }
631
641
  //#endregion
632
642
  //#region src/features/text/PageTextReader.d.ts
633
643
  /**
634
644
  * Per-page slow-path text reader. Acquires a `pagePtr` from the
635
- * `PagePtrPool`, opens a PDFium text page (`FPDFText_LoadPage`),
636
- * extracts the full UTF-16 buffer with `FPDFText_GetText`, decodes,
637
- * and releases everything in reverse order.
645
+ * `PagePtrPool`, opens a PDFium text page (`FPDFText_LoadPage`), extracts
646
+ * the page text, and releases everything in reverse order.
647
+ *
648
+ * Index spaces (see engine-core `text/charmap.ts`): `charCount` is the
649
+ * CHARACTER space (`FPDFText_CountChars` — the space geometry runs tile);
650
+ * `text` is the TEXT projection. The two diverge when a character
651
+ * contributes zero text units (non-printing) or two (supplementary plane);
652
+ * `charMap` anchors encode exactly those deviations.
638
653
  *
639
- * Memory model:
640
- * - `count` is in UTF-16 code units (FPDFText's "char").
641
- * - The buffer needs `(count + 1) * 2` bytes (PDFium writes a
642
- * trailing NUL terminator).
643
- * - `mem.readU16String` walks the buffer up to the NUL and decodes
644
- * to a JS string, faithfully preserving surrogate pairs.
654
+ * Both come from the fork's batched extension calls, which share one
655
+ * encoding authority (`FX_UTF16Encode`) so text and map can never
656
+ * disagree:
645
657
  *
646
- * Errors:
647
- * - `EPDFDoc_LoadPageByObjectNumber` returning 0 is `NotFound`
648
- * (raised by `PagePtrPool.acquire`).
649
- * - `FPDFText_LoadPage` returning 0 is `RuntimeUnavailable` — should
650
- * not happen on a healthy page; treat it as a runtime bug rather
651
- * than user error.
658
+ * - `EPDFText_GetTextFull` — true UTF-16LE extraction; supplementary
659
+ * characters arrive as surrogate pairs instead of being silently
660
+ * dropped by `FPDFText_GetText`'s UCS-2 encoder. Called once with an
661
+ * upper-bound buffer (2 units per character + NUL), so no measure
662
+ * round-trip.
663
+ * - `EPDFText_GetCharToTextMap` — the anchors, measure-then-fill. Zero
664
+ * anchors is the common (identity) page and skips the fill call.
652
665
  */
653
666
  declare class PageTextReader {
654
667
  private readonly runtime;
@@ -658,21 +671,93 @@ declare class PageTextReader {
658
671
  }
659
672
  //#endregion
660
673
  //#region src/features/geometry/PageGeometryReader.d.ts
674
+ /**
675
+ * One glyph as read from `EPDFText_GetCharGeometry`, plus the run-grouping
676
+ * context sampled alongside it. Pure data — no native handles — so the
677
+ * grouping stage below is a pure function the tests can drive directly.
678
+ */
679
+ interface RawGeometryGlyphRecord {
680
+ /** Grouping key: the glyph's text object handle (opaque identity). */
681
+ objectKey: number | bigint;
682
+ /** Sampled at each text object's first glyph (run splits inherit it). */
683
+ fontSize?: number;
684
+ /**
685
+ * Wire flags (bit 1 = space, bit 2 = empty). Synthesized-but-visible
686
+ * glyphs (/ActualText pieces) stay 0, exactly like the legacy reader —
687
+ * they represent real, selectable text.
688
+ */
689
+ flags: number;
690
+ /** Page-space AABB (zeroed when empty). */
691
+ looseBox: PdfRect;
692
+ tightBox?: PdfRect;
693
+ /** Oriented cells — real glyphs with a usable (non-singular) matrix only. */
694
+ looseQuad?: PdfQuad;
695
+ tightQuad?: PdfQuad;
696
+ /** Native uprightness of the char matrix (empty glyphs: true, inert). */
697
+ upright: boolean;
698
+ /** Baseline angle (radians CCW, PDF y-up); 0 when upright. */
699
+ rotation: number;
700
+ /** True when the ascent vector maps opposite the rotated +y (det < 0). */
701
+ ascentFlip: boolean;
702
+ }
661
703
  /**
662
704
  * Geometry-only text layout reader.
663
705
  *
664
706
  * Emits geometry in PDF user space (y-up edges) — the canonical engine
665
707
  * geometry. The viewer converts to content/view space via the page geometry
666
708
  * matrix; this reader applies NO Y-flip or device transform.
709
+ *
710
+ * One `EPDFText_GetCharGeometry` call per glyph supplies boxes, oriented
711
+ * cells, and flags together; `buildRunsFromRawGlyphs` then groups glyphs
712
+ * into the upright/rotated run union. Upright runs are byte-identical to the
713
+ * pre-orientation reader (quads the native layer offers are deliberately
714
+ * dropped — the dominant case never pays for orientation).
667
715
  */
668
716
  declare class PageGeometryReader {
669
717
  private readonly runtime;
670
718
  private readonly session;
671
719
  constructor(runtime: PdfRuntimeModule, session: DocumentSession);
672
720
  read(pageObjectNumber: PageObjectNumber, signal: AbortSignal): PageGeometrySnapshot;
673
- private buildRunsFromGlyphs;
674
- private readGlyphInfo;
721
+ private readGlyphRaw;
675
722
  }
723
+ /**
724
+ * Group per-glyph records into the run union. Pure — exported for tests.
725
+ *
726
+ * Runs split on text-object change (the legacy rule) and on orientation
727
+ * change between classifiable glyphs (θ drift / mixed orientation). A run's
728
+ * variant is decided by its FIRST classifiable glyph:
729
+ * - empty glyphs never classify (they adopt the run's variant);
730
+ * - real glyphs WITHOUT an oriented cell (singular matrix, synthesized
731
+ * /ActualText pieces) classify as upright — box-only data degrades to
732
+ * exactly the legacy behavior;
733
+ * - real glyphs with a non-upright matrix classify as rotated.
734
+ * Runs that never see a classifiable glyph emit as upright (degenerate,
735
+ * legacy behavior).
736
+ */
737
+ declare function buildRunsFromRawGlyphs(records: RawGeometryGlyphRecord[]): PageGeometryRun[];
738
+ //#endregion
739
+ //#region src/runtime/memory/structs.d.ts
740
+ /** Generated from `EPDF_CHAR_GEOMETRY`; pinned by native static_asserts. */
741
+ declare const EPDF_CHAR_GEOMETRY_LAYOUT: {
742
+ readonly bytes: 124;
743
+ readonly offsets: {
744
+ readonly looseBox: 0;
745
+ readonly tightBox: 16;
746
+ readonly looseQuad: 32;
747
+ readonly tightQuad: 64;
748
+ readonly matrix: 96;
749
+ readonly flags: 120;
750
+ };
751
+ readonly flags: {
752
+ readonly hasTightBox: number;
753
+ readonly hasLooseQuad: number;
754
+ readonly hasTightQuad: number;
755
+ readonly upright: number;
756
+ readonly space: number;
757
+ readonly empty: number;
758
+ readonly synthesized: number;
759
+ };
760
+ };
676
761
  //#endregion
677
762
  //#region src/features/render/PageRenderReader.d.ts
678
763
  declare class PageRenderReader {
@@ -1338,6 +1423,29 @@ declare class DocumentActionsReader {
1338
1423
  }
1339
1424
  //#endregion
1340
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
+ }
1341
1449
  /**
1342
1450
  * The piece that runs "inside the worker": owns runtime, manages document
1343
1451
  * sessions, dispatches requests to the engine-services synchronous code.
@@ -1359,6 +1467,8 @@ declare class WorkerHost {
1359
1467
  * runs in.
1360
1468
  */
1361
1469
  private readonly post;
1470
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1471
+ private readonly options;
1362
1472
  private readonly sessions;
1363
1473
  private readonly baseDocuments;
1364
1474
  private readonly aborts;
@@ -1380,7 +1490,9 @@ declare class WorkerHost {
1380
1490
  * pack.transfer)` — the host doesn't know which environment it
1381
1491
  * runs in.
1382
1492
  */
1383
- post: (pack: WirePack<WorkerResponse>) => void);
1493
+ post: (pack: WirePack<WorkerResponse>) => void,
1494
+ /** Optional capabilities. See {@link WorkerHostOptions}. */
1495
+ options?: WorkerHostOptions);
1384
1496
  /**
1385
1497
  * Register deployment-owned fonts on this worker thread, after init and
1386
1498
  * before serving requests. Server-only: the cloud engine never exposes font
@@ -1410,6 +1522,7 @@ declare class WorkerHost {
1410
1522
  private handleRedactionApply;
1411
1523
  private handlePagesExtract;
1412
1524
  private handlePagesInsert;
1525
+ private handlePagesInsertBlank;
1413
1526
  private handleAttachmentsList;
1414
1527
  private handleAttachmentsReadFile;
1415
1528
  private handleAttachmentsCreate;
@@ -1423,6 +1536,11 @@ declare class WorkerHost {
1423
1536
  private handlePagesGeometry;
1424
1537
  private handleSearchQuery;
1425
1538
  private handlePagesRender;
1539
+ private receiveEncoded;
1540
+ private encodeRaster;
1541
+ private handlePagesRenderEncoded;
1542
+ private handleDocumentRenderPageFileEncoded;
1543
+ private handleAnnotationsRenderAppearancesEncoded;
1426
1544
  private handleDocumentSaveBuffer;
1427
1545
  private handleDocumentSaveFile;
1428
1546
  private handleDocumentSaveLayerBuffer;
@@ -1477,5 +1595,5 @@ declare class WorkerHost {
1477
1595
  private saveLayerArtifact;
1478
1596
  }
1479
1597
  //#endregion
1480
- export { ALL_STANDARD_SECURITY_PERMISSIONS, type AcquiredBaseDocument, ActionReadBudgetTracker, AnnotationAppearanceReader, AnnotationMutator, AnnotationReader, AttachmentMutator, AttachmentReader, BaseDocumentRegistry, CloseStack, DocumentActionsReader, PagesMutator as DocumentPagesMutator, PagesMutator, DocumentSaver, DocumentSession, 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, RedactionApplier, type RevisionAuthority, SearchReader, SecurityReader, SessionEventPublisher, type StartupFontSpec, WorkerHost, 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 };
1481
1599
  //# sourceMappingURL=index.d.ts.map