@laminapdf/sdk 0.2.0-alpha.2 → 0.2.0-alpha.4
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/README.md +63 -8
- package/dist/api.d.ts +8 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +4 -2
- package/dist/api.js.map +1 -1
- package/dist/builder.d.ts +43 -22
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +122 -83
- package/dist/builder.js.map +1 -1
- package/dist/document.d.ts +89 -22
- package/dist/document.d.ts.map +1 -1
- package/dist/document.js +177 -67
- package/dist/document.js.map +1 -1
- package/dist/errors.d.ts +5 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -16
- package/dist/errors.js.map +1 -1
- package/dist/extract-job.d.ts +100 -0
- package/dist/extract-job.d.ts.map +1 -0
- package/dist/extract-job.js +177 -0
- package/dist/extract-job.js.map +1 -0
- package/dist/extract.d.ts +57 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +5 -0
- package/dist/extract.js.map +1 -0
- package/dist/font.d.ts +13 -6
- package/dist/font.d.ts.map +1 -1
- package/dist/font.js +50 -20
- package/dist/font.js.map +1 -1
- package/dist/generated/builder-enums.d.ts +3 -3
- package/dist/generated/builder-enums.d.ts.map +1 -1
- package/dist/generated/builder-enums.js +10 -0
- package/dist/generated/builder-enums.js.map +1 -1
- package/dist/generated/codes.d.ts +18 -6
- package/dist/generated/codes.d.ts.map +1 -1
- package/dist/generated/codes.js +114 -5
- package/dist/generated/codes.js.map +1 -1
- package/dist/generated/explain.d.ts.map +1 -1
- package/dist/generated/explain.js +45 -11
- package/dist/generated/explain.js.map +1 -1
- package/dist/generated/extract.d.ts +282 -0
- package/dist/generated/extract.d.ts.map +1 -0
- package/dist/generated/extract.js +4 -0
- package/dist/generated/extract.js.map +1 -0
- package/dist/init.d.ts +13 -5
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +23 -11
- package/dist/init.js.map +1 -1
- package/dist/internal/handle.d.ts +58 -0
- package/dist/internal/handle.d.ts.map +1 -0
- package/dist/internal/handle.js +113 -0
- package/dist/internal/handle.js.map +1 -0
- package/dist/internal/instance.d.ts +56 -0
- package/dist/internal/instance.d.ts.map +1 -0
- package/dist/internal/instance.js +125 -0
- package/dist/internal/instance.js.map +1 -0
- package/dist/source/http.d.ts +1 -1
- package/dist/source/http.js +2 -2
- package/dist/source/http.js.map +1 -1
- package/dist/source/range.d.ts +6 -1
- package/dist/source/range.d.ts.map +1 -1
- package/dist/source/range.js +10 -6
- package/dist/source/range.js.map +1 -1
- package/dist/text.d.ts +3 -3
- package/dist/text.d.ts.map +1 -1
- package/dist/text.js +3 -3
- package/dist/text.js.map +1 -1
- package/dist/types.d.ts +19 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -2
- package/dist/version.js.map +1 -1
- package/dist/worker/client.d.ts +3 -2
- package/dist/worker/client.d.ts.map +1 -1
- package/dist/worker/client.js +6 -4
- package/dist/worker/client.js.map +1 -1
- package/dist/worker/entry.js +1 -1
- package/dist/worker/entry.js.map +1 -1
- package/dist/worker/server.d.ts.map +1 -1
- package/dist/worker/server.js +42 -9
- package/dist/worker/server.js.map +1 -1
- package/dist/worker/support.d.ts +13 -3
- package/dist/worker/support.d.ts.map +1 -1
- package/dist/worker/support.js +5 -0
- package/dist/worker/support.js.map +1 -1
- package/dist/worker/types.d.ts +8 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/docs/AGENTS.md +14 -0
- package/docs/api/README.md +166 -0
- package/docs/api/classes/Builder.md +467 -0
- package/docs/api/classes/Document.md +854 -0
- package/docs/api/classes/ExtractJob.md +236 -0
- package/docs/api/classes/Font.md +74 -0
- package/docs/api/classes/Image.md +140 -0
- package/docs/api/classes/LaminaPdfError.md +189 -0
- package/docs/api/classes/Page.md +178 -0
- package/docs/api/classes/PageRef.md +253 -0
- package/docs/api/classes/PageText.md +129 -0
- package/docs/api/classes/PageTextRun.md +167 -0
- package/docs/api/classes/PendingPath.md +97 -0
- package/docs/api/classes/SaveJob.md +205 -0
- package/docs/api/classes/Surface.md +331 -0
- package/docs/api/classes/Transaction.md +111 -0
- package/docs/api/functions/callbackSource.md +33 -0
- package/docs/api/functions/extractWithModels.md +70 -0
- package/docs/api/functions/httpRangeSource.md +48 -0
- package/docs/api/functions/init.md +36 -0
- package/docs/api/functions/isExtractLoaded.md +21 -0
- package/docs/api/functions/isInitialized.md +19 -0
- package/docs/api/functions/isLaminaPdfError.md +41 -0
- package/docs/api/functions/isTextLoaded.md +19 -0
- package/docs/api/functions/loadExtract.md +28 -0
- package/docs/api/functions/loadText.md +28 -0
- package/docs/api/functions/onLeak.md +29 -0
- package/docs/api/functions/reset.md +22 -0
- package/docs/api/functions/wasmMemory.md +22 -0
- package/docs/api/interfaces/BuilderOptions.md +108 -0
- package/docs/api/interfaces/ByteRange.md +29 -0
- package/docs/api/interfaces/ChunkOptions.md +37 -0
- package/docs/api/interfaces/Diagnostic.md +67 -0
- package/docs/api/interfaces/ExtractOptions.md +92 -0
- package/docs/api/interfaces/ExtractResult.md +37 -0
- package/docs/api/interfaces/FontInfo.md +37 -0
- package/docs/api/interfaces/HostModels.md +57 -0
- package/docs/api/interfaces/HttpRangeOptions.md +78 -0
- package/docs/api/interfaces/InitOptions.md +40 -0
- package/docs/api/interfaces/LayoutRegion.md +38 -0
- package/docs/api/interfaces/Leak.md +21 -0
- package/docs/api/interfaces/Location.md +53 -0
- package/docs/api/interfaces/ModelInfo.md +45 -0
- package/docs/api/interfaces/ModelRequest.md +45 -0
- package/docs/api/interfaces/Models.md +45 -0
- package/docs/api/interfaces/OcrWord.md +37 -0
- package/docs/api/interfaces/OpLog.md +25 -0
- package/docs/api/interfaces/OpenOptions.md +37 -0
- package/docs/api/interfaces/PageTextOptions.md +21 -0
- package/docs/api/interfaces/PathBuilder.md +195 -0
- package/docs/api/interfaces/QuadPoint.md +25 -0
- package/docs/api/interfaces/RangeOptions.md +54 -0
- package/docs/api/interfaces/RangeSource.md +59 -0
- package/docs/api/interfaces/StrokeStyle.md +61 -0
- package/docs/api/interfaces/TagSpec.md +69 -0
- package/docs/api/interfaces/TextBoxOptions.md +93 -0
- package/docs/api/interfaces/TextGlyph.md +29 -0
- package/docs/api/interfaces/TextOptions.md +101 -0
- package/docs/api/interfaces/WasmMemory.md +37 -0
- package/docs/api/type-aliases/AfRelationship.md +15 -0
- package/docs/api/type-aliases/Align.md +15 -0
- package/docs/api/type-aliases/ArtifactKind.md +15 -0
- package/docs/api/type-aliases/AttachmentOptions.md +15 -0
- package/docs/api/type-aliases/BlendMode.md +15 -0
- package/docs/api/type-aliases/BoxRect.md +15 -0
- package/docs/api/type-aliases/BuildOptions.md +15 -0
- package/docs/api/type-aliases/Cell.md +71 -0
- package/docs/api/type-aliases/Chunk.md +79 -0
- package/docs/api/type-aliases/Color.md +16 -0
- package/docs/api/type-aliases/Coordinates.md +55 -0
- package/docs/api/type-aliases/Direction.md +15 -0
- package/docs/api/type-aliases/DocumentInfo.md +15 -0
- package/docs/api/type-aliases/DropReason.md +15 -0
- package/docs/api/type-aliases/Dropped.md +59 -0
- package/docs/api/type-aliases/Edited.md +15 -0
- package/docs/api/type-aliases/ErrorCode.md +15 -0
- package/docs/api/type-aliases/ErrorKind.md +15 -0
- package/docs/api/type-aliases/ExtractFormat.md +15 -0
- package/docs/api/type-aliases/ExtractJobOptions.md +31 -0
- package/docs/api/type-aliases/ExtractStep.md +61 -0
- package/docs/api/type-aliases/ExtractedBlock.md +94 -0
- package/docs/api/type-aliases/ExtractedPage.md +73 -0
- package/docs/api/type-aliases/ExtractedSource.md +48 -0
- package/docs/api/type-aliases/Extraction.md +22 -0
- package/docs/api/type-aliases/FillRule.md +15 -0
- package/docs/api/type-aliases/Fit.md +15 -0
- package/docs/api/type-aliases/Flags.md +15 -0
- package/docs/api/type-aliases/Generator.md +43 -0
- package/docs/api/type-aliases/GlyphQuad.md +15 -0
- package/docs/api/type-aliases/InfoPatch.md +15 -0
- package/docs/api/type-aliases/LaminaPdfWarning.md +16 -0
- package/docs/api/type-aliases/LimitName.md +15 -0
- package/docs/api/type-aliases/Limits.md +15 -0
- package/docs/api/type-aliases/LineBox.md +15 -0
- package/docs/api/type-aliases/LineCap.md +15 -0
- package/docs/api/type-aliases/LineJoin.md +15 -0
- package/docs/api/type-aliases/LinkTarget.md +15 -0
- package/docs/api/type-aliases/Metadata.md +15 -0
- package/docs/api/type-aliases/ModelResult.md +15 -0
- package/docs/api/type-aliases/Op.md +15 -0
- package/docs/api/type-aliases/OutlineEntry.md +15 -0
- package/docs/api/type-aliases/OutlineNode.md +15 -0
- package/docs/api/type-aliases/Overflow.md +15 -0
- package/docs/api/type-aliases/PageInfo.md +15 -0
- package/docs/api/type-aliases/PageLabel.md +15 -0
- package/docs/api/type-aliases/PageSizeName.md +15 -0
- package/docs/api/type-aliases/Point.md +15 -0
- package/docs/api/type-aliases/Profile.md +15 -0
- package/docs/api/type-aliases/Progress.md +15 -0
- package/docs/api/type-aliases/ReadingOrder.md +15 -0
- package/docs/api/type-aliases/Rect.md +15 -0
- package/docs/api/type-aliases/Region.md +31 -0
- package/docs/api/type-aliases/RegionLabel.md +15 -0
- package/docs/api/type-aliases/RenderMode.md +15 -0
- package/docs/api/type-aliases/Rotation.md +15 -0
- package/docs/api/type-aliases/SaveOptions.md +15 -0
- package/docs/api/type-aliases/SaveReport.md +15 -0
- package/docs/api/type-aliases/Span.md +74 -0
- package/docs/api/type-aliases/SplitOn.md +15 -0
- package/docs/api/type-aliases/Standard14.md +15 -0
- package/docs/api/type-aliases/StructRef.md +41 -0
- package/docs/api/type-aliases/StructSource.md +17 -0
- package/docs/api/type-aliases/StructureKid.md +15 -0
- package/docs/api/type-aliases/StructureNode.md +16 -0
- package/docs/api/type-aliases/TableDetector.md +15 -0
- package/docs/api/type-aliases/TableMode.md +15 -0
- package/docs/api/type-aliases/TableScope.md +15 -0
- package/docs/api/type-aliases/Tag.md +15 -0
- package/docs/api/type-aliases/TagName.md +15 -0
- package/docs/api/type-aliases/Target.md +15 -0
- package/docs/api/type-aliases/TargetView.md +18 -0
- package/docs/api/type-aliases/TextLayer.md +72 -0
- package/docs/api/type-aliases/TextLayerStatus.md +15 -0
- package/docs/api/type-aliases/TextLayout.md +15 -0
- package/docs/api/type-aliases/TextRange.md +33 -0
- package/docs/api/type-aliases/TextRunInfo.md +15 -0
- package/docs/api/type-aliases/Transform.md +15 -0
- package/docs/api/type-aliases/UndoOutcome.md +15 -0
- package/docs/api/type-aliases/ViewerPreferences.md +15 -0
- package/docs/api/type-aliases/WarningCode.md +15 -0
- package/docs/api/type-aliases/WasmSource.md +16 -0
- package/docs/api/variables/Matrix.md +99 -0
- package/docs/api/variables/PAGE_SIZES.md +15 -0
- package/docs/api/variables/TAG_NAMES.md +15 -0
- package/docs/errors/README.md +173 -0
- package/docs/errors/aes-padding-invalid.md +34 -0
- package/docs/errors/already-initialized.md +34 -0
- package/docs/errors/binary-output-to-terminal.md +35 -0
- package/docs/errors/builder-finished.md +35 -0
- package/docs/errors/cancelled.md +35 -0
- package/docs/errors/cmap-invalid.md +42 -0
- package/docs/errors/collection-index.md +33 -0
- package/docs/errors/color-components.md +33 -0
- package/docs/errors/content-bad-operands.md +36 -0
- package/docs/errors/content-path-unpainted.md +36 -0
- package/docs/errors/content-resource-missing.md +37 -0
- package/docs/errors/content-syntax.md +36 -0
- package/docs/errors/content-unbalanced-bt.md +36 -0
- package/docs/errors/content-unbalanced-marked.md +36 -0
- package/docs/errors/content-unbalanced-q.md +36 -0
- package/docs/errors/content-unknown-operator.md +37 -0
- package/docs/errors/covered-text.md +33 -0
- package/docs/errors/data-pending.md +34 -0
- package/docs/errors/decompress.md +34 -0
- package/docs/errors/device-color-without-output-intent.md +33 -0
- package/docs/errors/direct-page.md +34 -0
- package/docs/errors/disposed.md +34 -0
- package/docs/errors/document-changed.md +34 -0
- package/docs/errors/embedded-file-forbidden.md +35 -0
- package/docs/errors/embedded-file-without-mime-type.md +36 -0
- package/docs/errors/encoding-full.md +34 -0
- package/docs/errors/encrypted-base.md +33 -0
- package/docs/errors/extract-column-order-uncertain.md +38 -0
- package/docs/errors/extract-limit-blocks.md +35 -0
- package/docs/errors/extract-module-not-loaded.md +37 -0
- package/docs/errors/extract-needs-ocr.md +37 -0
- package/docs/errors/extract-reading-order-ambiguous.md +32 -0
- package/docs/errors/extract-struct-tree-ignored.md +32 -0
- package/docs/errors/extract-table-ambiguous.md +32 -0
- package/docs/errors/extract-table-limit.md +35 -0
- package/docs/errors/extract-untagged-content.md +32 -0
- package/docs/errors/fetch-failed.md +34 -0
- package/docs/errors/flate-truncated.md +34 -0
- package/docs/errors/flow-content-too-large.md +34 -0
- package/docs/errors/flow-keep-broken.md +34 -0
- package/docs/errors/flow-layout-unstable.md +38 -0
- package/docs/errors/font-invalid.md +36 -0
- package/docs/errors/font-mismatch.md +34 -0
- package/docs/errors/font-not-embeddable.md +34 -0
- package/docs/errors/font-not-embedded.md +35 -0
- package/docs/errors/font-not-shapable.md +33 -0
- package/docs/errors/glyph-out-of-range.md +34 -0
- package/docs/errors/glyph-without-unicode.md +37 -0
- package/docs/errors/heading-level-skipped.md +36 -0
- package/docs/errors/image-data-length.md +33 -0
- package/docs/errors/image-too-large.md +32 -0
- package/docs/errors/inline-image-unterminated.md +36 -0
- package/docs/errors/input-unreadable.md +37 -0
- package/docs/errors/instance-reset.md +34 -0
- package/docs/errors/invalid-argument.md +33 -0
- package/docs/errors/invalid-axis-value.md +32 -0
- package/docs/errors/invalid-box.md +34 -0
- package/docs/errors/invalid-color.md +32 -0
- package/docs/errors/invalid-command-line.md +44 -0
- package/docs/errors/invalid-date.md +34 -0
- package/docs/errors/invalid-entry.md +34 -0
- package/docs/errors/invalid-feature.md +32 -0
- package/docs/errors/invalid-font.md +32 -0
- package/docs/errors/invalid-geometry.md +32 -0
- package/docs/errors/invalid-icc-profile.md +32 -0
- package/docs/errors/invalid-image.md +33 -0
- package/docs/errors/invalid-op-log.md +33 -0
- package/docs/errors/invalid-page-label.md +34 -0
- package/docs/errors/invalid-page-labels.md +32 -0
- package/docs/errors/invalid-page-range.md +37 -0
- package/docs/errors/invalid-rotate.md +34 -0
- package/docs/errors/invalid-spans.md +39 -0
- package/docs/errors/invalid-structure-nesting.md +38 -0
- package/docs/errors/invalid-structure.md +34 -0
- package/docs/errors/invalid-text-range.md +33 -0
- package/docs/errors/job-finished.md +34 -0
- package/docs/errors/limit-exceeded.md +38 -0
- package/docs/errors/link-without-contents.md +33 -0
- package/docs/errors/link-without-structure.md +37 -0
- package/docs/errors/markdown-html-ignored.md +33 -0
- package/docs/errors/markdown-image-missing.md +34 -0
- package/docs/errors/missing-alt-text.md +33 -0
- package/docs/errors/missing-glyph.md +33 -0
- package/docs/errors/missing-header.md +37 -0
- package/docs/errors/missing-lang.md +32 -0
- package/docs/errors/missing-root.md +34 -0
- package/docs/errors/missing-title.md +32 -0
- package/docs/errors/model-failed.md +33 -0
- package/docs/errors/model-needs-host.md +40 -0
- package/docs/errors/model-result-unexpected.md +36 -0
- package/docs/errors/name-tree-node-skipped.md +34 -0
- package/docs/errors/nested-transaction.md +34 -0
- package/docs/errors/no-pending-save.md +32 -0
- package/docs/errors/no-transaction.md +33 -0
- package/docs/errors/not-initialized.md +35 -0
- package/docs/errors/not-pdf.md +33 -0
- package/docs/errors/not-rebased.md +35 -0
- package/docs/errors/object-number-out-of-range.md +38 -0
- package/docs/errors/objstm-index-mismatch.md +36 -0
- package/docs/errors/out-of-memory.md +38 -0
- package/docs/errors/outline-cycle.md +34 -0
- package/docs/errors/outline-item-skipped.md +34 -0
- package/docs/errors/output-unwritable.md +37 -0
- package/docs/errors/overwrite-refused.md +36 -0
- package/docs/errors/page-count-mismatch.md +34 -0
- package/docs/errors/page-index-out-of-range.md +34 -0
- package/docs/errors/page-tree-node-skipped.md +35 -0
- package/docs/errors/password-required.md +36 -0
- package/docs/errors/path-outside-roots.md +32 -0
- package/docs/errors/perms-mismatch.md +34 -0
- package/docs/errors/profile-version-conflict.md +35 -0
- package/docs/errors/redaction-not-applied.md +32 -0
- package/docs/errors/reference-cycle.md +35 -0
- package/docs/errors/render-backend-unavailable.md +32 -0
- package/docs/errors/render-failed.md +33 -0
- package/docs/errors/render-too-large.md +36 -0
- package/docs/errors/repaired-base.md +34 -0
- package/docs/errors/requires-rewrite.md +38 -0
- package/docs/errors/revision-index-out-of-range.md +34 -0
- package/docs/errors/saved-not-rebased.md +34 -0
- package/docs/errors/sink-not-empty.md +33 -0
- package/docs/errors/sink.md +31 -0
- package/docs/errors/source-budget-exceeded.md +34 -0
- package/docs/errors/source-changed.md +33 -0
- package/docs/errors/source.md +30 -0
- package/docs/errors/stale-generation.md +34 -0
- package/docs/errors/stream-length-recovered.md +37 -0
- package/docs/errors/strict.md +34 -0
- package/docs/errors/subset-failed.md +31 -0
- package/docs/errors/syntax.md +34 -0
- package/docs/errors/tag-element-not-open.md +41 -0
- package/docs/errors/tag-element-unclosed.md +34 -0
- package/docs/errors/text-in-earlier-revision.md +36 -0
- package/docs/errors/text-module-not-loaded.md +36 -0
- package/docs/errors/text-overflow.md +34 -0
- package/docs/errors/tounicode-conflict.md +32 -0
- package/docs/errors/type.md +34 -0
- package/docs/errors/unexpected-eof.md +34 -0
- package/docs/errors/unknown-axis.md +33 -0
- package/docs/errors/unknown-code.md +36 -0
- package/docs/errors/unknown-destination.md +33 -0
- package/docs/errors/unknown-font.md +33 -0
- package/docs/errors/unknown-option.md +33 -0
- package/docs/errors/unknown-page.md +34 -0
- package/docs/errors/unmapped-glyph.md +36 -0
- package/docs/errors/unnumbered-heading-misused.md +34 -0
- package/docs/errors/unset-object.md +30 -0
- package/docs/errors/unsupported-filter.md +34 -0
- package/docs/errors/unsupported-image.md +33 -0
- package/docs/errors/unsupported-layout-option.md +33 -0
- package/docs/errors/unsupported-security-handler.md +34 -0
- package/docs/errors/unsupported-version.md +32 -0
- package/docs/errors/untagged-content.md +35 -0
- package/docs/errors/warnings-truncated.md +35 -0
- package/docs/errors/wasm-trap.md +37 -0
- package/docs/errors/whole-font-rebuilt.md +30 -0
- package/docs/errors/worker-crashed.md +33 -0
- package/docs/errors/worker-failed.md +32 -0
- package/docs/errors/worker-version-mismatch.md +34 -0
- package/docs/errors/would-invalidate-signatures.md +38 -0
- package/docs/errors/wrong-document.md +33 -0
- package/docs/errors/wrong-password.md +34 -0
- package/docs/errors/xobject-cycle.md +36 -0
- package/docs/errors/xref-repaired.md +36 -0
- package/docs/errors/xrefstm-ignored.md +34 -0
- package/docs/llms.txt +94 -0
- package/docs/pages/concepts/dependencies.md +44 -0
- package/docs/pages/concepts/drawing-pages.md +76 -0
- package/docs/pages/concepts/errors-and-warnings.md +68 -0
- package/docs/pages/concepts/how-lamina-thinks.md +98 -0
- package/docs/pages/concepts/pages-and-coordinates.md +75 -0
- package/docs/pages/guides/accessible-pdfs.md +262 -0
- package/docs/pages/guides/archival-pdfs.md +433 -0
- package/docs/pages/guides/edit-a-pdf.md +143 -0
- package/docs/pages/guides/flowing-pages.md +379 -0
- package/docs/pages/guides/fonts-and-text.md +204 -0
- package/docs/pages/guides/images-and-vectors.md +221 -0
- package/docs/pages/guides/keep-the-page-responsive.md +85 -0
- package/docs/pages/guides/links-outlines-and-metadata.md +224 -0
- package/docs/pages/guides/open-large-files.md +69 -0
- package/docs/pages/guides/password-protected-files.md +70 -0
- package/docs/pages/guides/save-a-pdf.md +154 -0
- package/docs/pages/guides/test-generated-pdfs.md +324 -0
- package/docs/pages/guides/untrusted-files.md +82 -0
- package/docs/pages/index.md +33 -0
- package/docs/pages/install.md +79 -0
- package/docs/pages/quick-start/browser.md +71 -0
- package/docs/pages/quick-start/bun.md +64 -0
- package/docs/pages/quick-start/deno.md +62 -0
- package/docs/pages/quick-start/node.md +65 -0
- package/docs/pages/quick-start/rust.md +62 -0
- package/docs/pages/quick-start/workers.md +139 -0
- package/docs/pages/recipes/cloudflare-worker.md +115 -0
- package/docs/pages/recipes/element-flow.md +248 -0
- package/docs/pages/recipes/extract-markdown.md +152 -0
- package/docs/pages/recipes/generate-then-edit.md +142 -0
- package/docs/pages/recipes/hello.md +101 -0
- package/docs/pages/recipes/images-and-vectors.md +216 -0
- package/docs/pages/recipes/invoice.md +233 -0
- package/docs/pages/recipes/links-and-outlines.md +222 -0
- package/docs/pages/recipes/multilingual.md +196 -0
- package/docs/pages/recipes/open-untrusted.md +65 -0
- package/docs/pages/recipes/pdf-a-archive.md +212 -0
- package/docs/pages/recipes/pdf-a3-invoice-with-xml.md +229 -0
- package/docs/pages/recipes/pdf-ua-report.md +244 -0
- package/docs/pages/recipes/report.md +125 -0
- package/docs/pages/recipes/web-worker-client.md +64 -0
- package/docs/pages/recipes.md +48 -0
- package/docs/pages/reference/benchmarks.md +93 -0
- package/docs/pages/reference/changelog.md +134 -0
- package/docs/pages/reference/codes.md +14 -0
- package/docs/pages/reference/glossary.md +108 -0
- package/docs/pages/reference/rust.md +36 -0
- package/docs/pages/reference/stability.md +59 -0
- package/docs/pages/start/coding-agents.md +45 -0
- package/docs/pages/start/first-pdf.md +81 -0
- package/docs/pages/troubleshooting.md +74 -0
- package/docs/renames.json +86 -0
- package/docs/schemas/error.schema.json +322 -0
- package/docs/schemas/renames.schema.json +29 -0
- package/package.json +7 -3
- package/schemas/error.schema.json +37 -3
package/dist/document.d.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import type { WasmDocument, WasmPage, WasmSaveJob } from "@laminapdf/wasm/base";
|
|
2
2
|
import { type LaminaPdfWarning } from "./errors.js";
|
|
3
|
+
import { type ExtractFormat, type ExtractOptions, type ExtractResult } from "./extract.js";
|
|
4
|
+
import { ExtractJob, type ExtractJobOptions } from "./extract-job.js";
|
|
5
|
+
import { type BaseGlue } from "./init.js";
|
|
6
|
+
import { Handle } from "./internal/handle.js";
|
|
7
|
+
import type { Instance } from "./internal/instance.js";
|
|
3
8
|
import { type RangeOptions, type RangeSource, type RangeState } from "./source/range.js";
|
|
4
9
|
import { PageText, type TextOptions } from "./text.js";
|
|
5
10
|
import { Transaction } from "./transaction.js";
|
|
6
|
-
import type { DocumentInfo, Edited, Op, OpenOptions, OpLog, PageInfo, Progress, SaveOptions, SaveReport, UndoOutcome } from "./types.js";
|
|
7
|
-
/**
|
|
8
|
-
|
|
11
|
+
import type { DocumentInfo, Edited, Op, OpenOptions, OpLog, OutlineNode, PageInfo, Progress, SaveOptions, SaveReport, StructureNode, Target, UndoOutcome } from "./types.js";
|
|
12
|
+
/**
|
|
13
|
+
* A page of a {@link Document}, held by its ID: moving pages doesn't retarget it (ADR 0028 F2).
|
|
14
|
+
* Freed with its document; every call after that throws `disposed`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PageRef extends Handle<BaseGlue> {
|
|
9
17
|
#private;
|
|
10
18
|
/** @internal */
|
|
11
|
-
constructor(page: WasmPage);
|
|
19
|
+
constructor(page: WasmPage, doc: Document, instance: Instance<BaseGlue>);
|
|
12
20
|
/** The page's stable ID (`p12.0`). */
|
|
13
21
|
get id(): string;
|
|
14
22
|
/** The page's current 0-based index. @throws {@link LaminaPdfError} `unknown-page` when it is gone. */
|
|
@@ -30,12 +38,16 @@ export declare class PageRef {
|
|
|
30
38
|
* module; `unknown-page`; reading errors (`data-pending` for a range document: use `ensure`).
|
|
31
39
|
*/
|
|
32
40
|
text(options?: TextOptions): PageText;
|
|
41
|
+
protected release(): void;
|
|
33
42
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
43
|
+
/**
|
|
44
|
+
* A save in progress, stepped by the caller with a budget of work units (ADR 0028 §3). Freed with
|
|
45
|
+
* its document; every call after that throws `disposed`.
|
|
46
|
+
*/
|
|
47
|
+
export declare class SaveJob extends Handle<BaseGlue> {
|
|
36
48
|
#private;
|
|
37
49
|
/** @internal */
|
|
38
|
-
constructor(job: WasmSaveJob);
|
|
50
|
+
constructor(job: WasmSaveJob, doc: Document, instance: Instance<BaseGlue>);
|
|
39
51
|
/**
|
|
40
52
|
* Runs at most `budget` work units.
|
|
41
53
|
*
|
|
@@ -51,25 +63,26 @@ export declare class SaveJob {
|
|
|
51
63
|
};
|
|
52
64
|
/** Stops the job: its next step fails with `cancelled`. */
|
|
53
65
|
cancel(): void;
|
|
54
|
-
|
|
55
|
-
free(): void;
|
|
66
|
+
protected release(): void;
|
|
56
67
|
}
|
|
57
68
|
/**
|
|
58
|
-
* An open PDF: read it, edit it with ops (atomic transactions with undo), save it.
|
|
69
|
+
* An open PDF: read it, edit it with ops (atomic transactions with undo), save it. It holds
|
|
70
|
+
* WebAssembly memory: free it with `using` or {@link Document.free} (an alias).
|
|
59
71
|
*
|
|
60
72
|
* @example
|
|
61
73
|
* ```ts
|
|
62
74
|
* await init();
|
|
63
|
-
*
|
|
75
|
+
* using doc = Document.open(bytes);
|
|
64
76
|
* doc.transact((tx) => tx.setInfo({ title: "Final" }));
|
|
65
77
|
* const updated = doc.save({ mode: "incremental" });
|
|
66
|
-
* doc.free();
|
|
67
78
|
* ```
|
|
68
79
|
*/
|
|
69
|
-
export declare class Document {
|
|
80
|
+
export declare class Document extends Handle<BaseGlue> {
|
|
70
81
|
#private;
|
|
71
|
-
/**
|
|
72
|
-
|
|
82
|
+
/**
|
|
83
|
+
* @internal Wraps a raw document (from `open`, `openRange` or `Builder.finish`) of `instance`.
|
|
84
|
+
*/
|
|
85
|
+
constructor(doc: WasmDocument, instance: Instance<BaseGlue>, range?: RangeState);
|
|
73
86
|
/**
|
|
74
87
|
* Opens a document whose bytes are fetched range by range ({@link httpRangeSource},
|
|
75
88
|
* {@link callbackSource}): only what the open needs is fetched (the end of the file, the xref,
|
|
@@ -147,8 +160,68 @@ export declare class Document {
|
|
|
147
160
|
* @throws {@link LaminaPdfError} `invalid-argument`, `unknown-page`.
|
|
148
161
|
*/
|
|
149
162
|
pageById(id: string): PageRef;
|
|
163
|
+
/**
|
|
164
|
+
* The outline (bookmarks): its top-level items in order, each with its children, and where
|
|
165
|
+
* each goes as a page and a view in page space; empty without one. Needs a document opened
|
|
166
|
+
* while the extract or text module was loaded.
|
|
167
|
+
*
|
|
168
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded` for a document opened in the base
|
|
169
|
+
* module; reading errors (`data-pending` for a range document: use `ensure`).
|
|
170
|
+
*/
|
|
171
|
+
outline(): OutlineNode[];
|
|
172
|
+
/**
|
|
173
|
+
* Where the named destination `name` goes (the names a link or a `#nameddest=` address uses),
|
|
174
|
+
* or `undefined` when the document has none by that name. Needs a document opened while the
|
|
175
|
+
* extract or text module was loaded.
|
|
176
|
+
*
|
|
177
|
+
* @throws {@link LaminaPdfError} as {@link Document.outline}.
|
|
178
|
+
*/
|
|
179
|
+
namedDestination(name: string): Target | undefined;
|
|
180
|
+
/**
|
|
181
|
+
* The document's text for retrieval and LLMs: Markdown or plain text in reading order, the
|
|
182
|
+
* `laminapdf.extract/1` JSON with a box for every block, or chunks sized for retrieval. Tables
|
|
183
|
+
* drawn with lines come out as tables, and text a reader can't see is left out. Needs a
|
|
184
|
+
* document opened while the extract or text module was loaded.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* await init({ extract: true });
|
|
189
|
+
* const doc = Document.open(bytes);
|
|
190
|
+
* const markdown = doc.extract({ format: "markdown" });
|
|
191
|
+
* const chunks = doc.extract({ format: "chunks", chunk: { maxTokens: 400 } });
|
|
192
|
+
* ```
|
|
193
|
+
* @returns a string for `"markdown"` and `"text"`, an {@link Extraction} for `"json"`,
|
|
194
|
+
* {@link Chunk}s for `"chunks"`.
|
|
195
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded` for a document opened in the base
|
|
196
|
+
* module; `page-index-out-of-range`; `unknown-option` (with `didYouMean`) / `invalid-argument`
|
|
197
|
+
* for bad options; reading errors (`data-pending` for a range document: use `ensure`).
|
|
198
|
+
*/
|
|
199
|
+
extract<F extends ExtractFormat>(options: ExtractOptions<F>): ExtractResult[F];
|
|
200
|
+
/**
|
|
201
|
+
* An extraction stepped a page at a time, for models the host runs: each step that needs a
|
|
202
|
+
* model's result stops with a `request` (the page and resolution to render), answered with
|
|
203
|
+
* {@link ExtractJob.provide}. {@link extractWithModels} loops one for async models. Needs a
|
|
204
|
+
* document opened while the extract or text module was loaded.
|
|
205
|
+
*
|
|
206
|
+
* @throws {@link LaminaPdfError} as {@link Document.extract}.
|
|
207
|
+
*/
|
|
208
|
+
extractJob<F extends ExtractFormat>(options: ExtractJobOptions<F>): ExtractJob<F>;
|
|
150
209
|
/** The Info dictionary's text entries (document text). @throws {@link LaminaPdfError} reading errors. */
|
|
151
210
|
get info(): DocumentInfo;
|
|
211
|
+
/**
|
|
212
|
+
* Whether the document says it is tagged (`/MarkInfo /Marked true`); it doesn't check the tree.
|
|
213
|
+
* Needs a document opened while the extract or text module was loaded, as `page.text()` does.
|
|
214
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded`; reading errors.
|
|
215
|
+
*/
|
|
216
|
+
get isTagged(): boolean;
|
|
217
|
+
/**
|
|
218
|
+
* The structure tree's top-level elements in reading order, or `undefined` for a document
|
|
219
|
+
* without one. A text run's `mcid` (on {@link PageTextRun}) links it to the element whose
|
|
220
|
+
* `{ type: "content", page, mcid }` kid names it. Needs the extract or text module, as
|
|
221
|
+
* `page.text()` does.
|
|
222
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded`; reading errors.
|
|
223
|
+
*/
|
|
224
|
+
structureTree(): StructureNode[] | undefined;
|
|
152
225
|
/** Every warning so far (build warnings first), each the ADR 0026 §1 object. */
|
|
153
226
|
get warnings(): readonly LaminaPdfWarning[];
|
|
154
227
|
/** Whether there are changes no save has written yet. */
|
|
@@ -230,12 +303,6 @@ export declare class Document {
|
|
|
230
303
|
* @throws {@link LaminaPdfError} `no-pending-save`; reading errors in `bytes`.
|
|
231
304
|
*/
|
|
232
305
|
rebase(bytes: Uint8Array): void;
|
|
233
|
-
|
|
234
|
-
* Frees the document's WASM memory now; without it, it is freed when garbage-collected.
|
|
235
|
-
* Calling it twice is harmless; using the document afterwards is not (L2b adds `disposed`).
|
|
236
|
-
*/
|
|
237
|
-
free(): void;
|
|
238
|
-
/** Frees the document at the end of a `using` block. */
|
|
239
|
-
[Symbol.dispose](): void;
|
|
306
|
+
protected release(): void;
|
|
240
307
|
}
|
|
241
308
|
//# sourceMappingURL=document.d.ts.map
|
package/dist/document.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAoB,KAAK,gBAAgB,EAAgB,MAAM,aAAa,CAAC;AACpF,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAgB,MAAM,cAAc,CAAC;AACzG,OAAO,EAAE,UAAU,EAAE,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,KAAK,QAAQ,EAA+B,MAAM,WAAW,CAAC;AACvE,OAAO,EAAE,MAAM,EAAS,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,WAAW,EAAE,KAAK,UAAU,EAAsB,MAAM,mBAAmB,CAAC;AAC7G,OAAO,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,EAAE,EACF,WAAW,EACX,KAAK,EACL,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,UAAU,EACV,aAAa,EACb,MAAM,EACN,WAAW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AK,EAAE,UAAU,GAAG,IAAI,CAG9B;IAED,SAAS,CAAC,OAAO,IAAI,IAAI,CAIxB;CACF"}
|
package/dist/document.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isLaminaPdfError, packageError } from "./errors.js";
|
|
2
|
+
import { parseExtract } from "./extract.js";
|
|
3
|
+
import { ExtractJob } from "./extract-job.js";
|
|
2
4
|
import { extractsText, readingModule } from "./init.js";
|
|
5
|
+
import { Handle, watch } from "./internal/handle.js";
|
|
3
6
|
import { settle, wholeBytes } from "./source/range.js";
|
|
4
7
|
import { PageText } from "./text.js";
|
|
5
8
|
import { Transaction } from "./transaction.js";
|
|
@@ -30,24 +33,28 @@ function passwordAttempts(options) {
|
|
|
30
33
|
function tryNext(e, attempt, attempts) {
|
|
31
34
|
return attempt + 1 < attempts && isLaminaPdfError(e, "wrong-password");
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
34
|
-
|
|
36
|
+
/**
|
|
37
|
+
* A page of a {@link Document}, held by its ID: moving pages doesn't retarget it (ADR 0028 F2).
|
|
38
|
+
* Freed with its document; every call after that throws `disposed`.
|
|
39
|
+
*/
|
|
40
|
+
export class PageRef extends Handle {
|
|
35
41
|
#page;
|
|
36
42
|
/** @internal */
|
|
37
|
-
constructor(page) {
|
|
43
|
+
constructor(page, doc, instance) {
|
|
44
|
+
super("PageRef", instance, doc);
|
|
38
45
|
this.#page = page;
|
|
39
46
|
}
|
|
40
47
|
/** The page's stable ID (`p12.0`). */
|
|
41
48
|
get id() {
|
|
42
|
-
return this.#page.id;
|
|
49
|
+
return this.call(() => this.#page.id);
|
|
43
50
|
}
|
|
44
51
|
/** The page's current 0-based index. @throws {@link LaminaPdfError} `unknown-page` when it is gone. */
|
|
45
52
|
get index() {
|
|
46
|
-
return
|
|
53
|
+
return this.call(() => this.#page.index());
|
|
47
54
|
}
|
|
48
55
|
/** The page's facts now. @throws {@link LaminaPdfError} `unknown-page` when it is gone. */
|
|
49
56
|
get info() {
|
|
50
|
-
return
|
|
57
|
+
return this.call(() => this.#page.info());
|
|
51
58
|
}
|
|
52
59
|
/**
|
|
53
60
|
* The page's text: lines in reading order, runs, and every glyph's quad in page space.
|
|
@@ -64,19 +71,27 @@ export class PageRef {
|
|
|
64
71
|
* module; `unknown-page`; reading errors (`data-pending` for a range document: use `ensure`).
|
|
65
72
|
*/
|
|
66
73
|
text(options) {
|
|
74
|
+
this.assertLive();
|
|
67
75
|
const page = this.#page;
|
|
68
76
|
if (typeof page.text !== "function") {
|
|
69
77
|
throw packageError("extract-module-not-loaded", "page.text() needs a document opened while the extract or text module was loaded");
|
|
70
78
|
}
|
|
71
79
|
const extract = page.text.bind(page);
|
|
72
|
-
return new PageText(
|
|
80
|
+
return new PageText(this.call(() => extract(options)));
|
|
81
|
+
}
|
|
82
|
+
release() {
|
|
83
|
+
this.#page.free();
|
|
73
84
|
}
|
|
74
85
|
}
|
|
75
|
-
/**
|
|
76
|
-
|
|
86
|
+
/**
|
|
87
|
+
* A save in progress, stepped by the caller with a budget of work units (ADR 0028 §3). Freed with
|
|
88
|
+
* its document; every call after that throws `disposed`.
|
|
89
|
+
*/
|
|
90
|
+
export class SaveJob extends Handle {
|
|
77
91
|
#job;
|
|
78
92
|
/** @internal */
|
|
79
|
-
constructor(job) {
|
|
93
|
+
constructor(job, doc, instance) {
|
|
94
|
+
super("SaveJob", instance, doc);
|
|
80
95
|
this.#job = job;
|
|
81
96
|
}
|
|
82
97
|
/**
|
|
@@ -86,40 +101,42 @@ export class SaveJob {
|
|
|
86
101
|
* @throws {@link LaminaPdfError} `cancelled`, `document-changed`, `job-finished`, or the save's errors.
|
|
87
102
|
*/
|
|
88
103
|
step(budget) {
|
|
89
|
-
return
|
|
104
|
+
return this.call(() => this.#job.step(budget));
|
|
90
105
|
}
|
|
91
106
|
/** Stops the job: its next step fails with `cancelled`. */
|
|
92
107
|
cancel() {
|
|
93
|
-
this.#job.cancel();
|
|
108
|
+
this.call(() => this.#job.cancel());
|
|
94
109
|
}
|
|
95
|
-
|
|
96
|
-
free() {
|
|
110
|
+
release() {
|
|
97
111
|
this.#job.free();
|
|
98
112
|
}
|
|
99
113
|
}
|
|
100
114
|
/**
|
|
101
|
-
* An open PDF: read it, edit it with ops (atomic transactions with undo), save it.
|
|
115
|
+
* An open PDF: read it, edit it with ops (atomic transactions with undo), save it. It holds
|
|
116
|
+
* WebAssembly memory: free it with `using` or {@link Document.free} (an alias).
|
|
102
117
|
*
|
|
103
118
|
* @example
|
|
104
119
|
* ```ts
|
|
105
120
|
* await init();
|
|
106
|
-
*
|
|
121
|
+
* using doc = Document.open(bytes);
|
|
107
122
|
* doc.transact((tx) => tx.setInfo({ title: "Final" }));
|
|
108
123
|
* const updated = doc.save({ mode: "incremental" });
|
|
109
|
-
* doc.free();
|
|
110
124
|
* ```
|
|
111
125
|
*/
|
|
112
|
-
export class Document {
|
|
126
|
+
export class Document extends Handle {
|
|
113
127
|
#doc;
|
|
114
128
|
/** Set for a document opened with {@link Document.openRange}: where more bytes come from. */
|
|
115
129
|
#range;
|
|
116
|
-
#freed = false;
|
|
117
130
|
/** Whether a `transact` callback of this document is running. */
|
|
118
131
|
#transacting = false;
|
|
119
|
-
/**
|
|
120
|
-
|
|
132
|
+
/**
|
|
133
|
+
* @internal Wraps a raw document (from `open`, `openRange` or `Builder.finish`) of `instance`.
|
|
134
|
+
*/
|
|
135
|
+
constructor(doc, instance, range) {
|
|
136
|
+
super("Document", instance);
|
|
121
137
|
this.#doc = doc;
|
|
122
138
|
this.#range = range;
|
|
139
|
+
watch(this, "Document");
|
|
123
140
|
}
|
|
124
141
|
/**
|
|
125
142
|
* Opens a document whose bytes are fetched range by range ({@link httpRangeSource},
|
|
@@ -143,9 +160,11 @@ export class Document {
|
|
|
143
160
|
const whole = wholeBytes(src);
|
|
144
161
|
if (whole !== undefined)
|
|
145
162
|
return Document.open(whole, open);
|
|
146
|
-
const
|
|
147
|
-
const sparse =
|
|
163
|
+
const instance = readingModule();
|
|
164
|
+
const sparse = instance.call((wasm) => new wasm.WasmSparseSource(src.size, budget));
|
|
148
165
|
const state = {
|
|
166
|
+
instance,
|
|
167
|
+
generation: instance.generation,
|
|
149
168
|
sparse,
|
|
150
169
|
source: src,
|
|
151
170
|
blockSize: blockSize ?? src.blockSize ?? 4096,
|
|
@@ -156,7 +175,10 @@ export class Document {
|
|
|
156
175
|
try {
|
|
157
176
|
for (let i = 0;; i++) {
|
|
158
177
|
try {
|
|
159
|
-
return await settle(state, () => new Document(
|
|
178
|
+
return await settle(state, () => new Document(instance.call((wasm) => {
|
|
179
|
+
instance.check(state.generation, "Document");
|
|
180
|
+
return wasm.WasmDocument.openSource(sparse, attempts[i]);
|
|
181
|
+
}), instance, state), signal);
|
|
160
182
|
}
|
|
161
183
|
catch (e) {
|
|
162
184
|
if (!tryNext(e, i, attempts.length))
|
|
@@ -165,8 +187,10 @@ export class Document {
|
|
|
165
187
|
}
|
|
166
188
|
}
|
|
167
189
|
catch (e) {
|
|
168
|
-
// Nothing holds the fetched bytes now: free them at once rather than at collection
|
|
169
|
-
|
|
190
|
+
// Nothing holds the fetched bytes now: free them at once rather than at collection, unless
|
|
191
|
+
// their instance was replaced (a trap, or reset() during a fetch).
|
|
192
|
+
if (instance.owns(state.generation))
|
|
193
|
+
sparse.free();
|
|
170
194
|
throw e;
|
|
171
195
|
}
|
|
172
196
|
}
|
|
@@ -188,6 +212,7 @@ export class Document {
|
|
|
188
212
|
* @throws what `f` throws, and as {@link Document.openRange}.
|
|
189
213
|
*/
|
|
190
214
|
async ensure(f, options = {}) {
|
|
215
|
+
this.assertLive();
|
|
191
216
|
return this.#range === undefined ? f() : settle(this.#range, f, options.signal);
|
|
192
217
|
}
|
|
193
218
|
/**
|
|
@@ -205,12 +230,12 @@ export class Document {
|
|
|
205
230
|
* `strict`, …; `unknown-option` / `invalid-argument` for bad options; `not-initialized`.
|
|
206
231
|
*/
|
|
207
232
|
static open(bytes, options) {
|
|
208
|
-
const
|
|
233
|
+
const instance = readingModule();
|
|
209
234
|
const data = bytesOf(bytes);
|
|
210
235
|
const attempts = passwordAttempts(options ?? {});
|
|
211
236
|
for (let i = 0;; i++) {
|
|
212
237
|
try {
|
|
213
|
-
return new Document(
|
|
238
|
+
return new Document(instance.call((wasm) => wasm.WasmDocument.openBytes(data, attempts[i])), instance);
|
|
214
239
|
}
|
|
215
240
|
catch (e) {
|
|
216
241
|
if (!tryNext(e, i, attempts.length))
|
|
@@ -224,15 +249,16 @@ export class Document {
|
|
|
224
249
|
* module; save and reopen it to move it.
|
|
225
250
|
*/
|
|
226
251
|
get canExtractText() {
|
|
252
|
+
this.assertLive();
|
|
227
253
|
return extractsText(this.#doc);
|
|
228
254
|
}
|
|
229
255
|
/** The number of pages. @throws {@link LaminaPdfError} reading errors. */
|
|
230
256
|
get pageCount() {
|
|
231
|
-
return
|
|
257
|
+
return this.call(() => this.#doc.pageCount());
|
|
232
258
|
}
|
|
233
259
|
/** Every page's facts, in order (one page-tree walk). @throws {@link LaminaPdfError} reading errors. */
|
|
234
260
|
get pages() {
|
|
235
|
-
return
|
|
261
|
+
return this.call(() => this.#doc.pageInfos());
|
|
236
262
|
}
|
|
237
263
|
/**
|
|
238
264
|
* Page `index`'s facts.
|
|
@@ -240,7 +266,7 @@ export class Document {
|
|
|
240
266
|
* @throws {@link LaminaPdfError} `page-index-out-of-range`.
|
|
241
267
|
*/
|
|
242
268
|
pageInfo(index) {
|
|
243
|
-
return
|
|
269
|
+
return this.call(() => this.#doc.pageInfo(index));
|
|
244
270
|
}
|
|
245
271
|
/**
|
|
246
272
|
* A handle on page `index` that follows the page by its ID.
|
|
@@ -248,7 +274,7 @@ export class Document {
|
|
|
248
274
|
* @throws {@link LaminaPdfError} `page-index-out-of-range`.
|
|
249
275
|
*/
|
|
250
276
|
page(index) {
|
|
251
|
-
return new PageRef(
|
|
277
|
+
return new PageRef(this.call(() => this.#doc.page(index)), this, this.instance);
|
|
252
278
|
}
|
|
253
279
|
/**
|
|
254
280
|
* A handle on the page with `id` (`p12.0`).
|
|
@@ -256,31 +282,125 @@ export class Document {
|
|
|
256
282
|
* @throws {@link LaminaPdfError} `invalid-argument`, `unknown-page`.
|
|
257
283
|
*/
|
|
258
284
|
pageById(id) {
|
|
259
|
-
return new PageRef(
|
|
285
|
+
return new PageRef(this.call(() => this.#doc.pageById(id)), this, this.instance);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The outline (bookmarks): its top-level items in order, each with its children, and where
|
|
289
|
+
* each goes as a page and a view in page space; empty without one. Needs a document opened
|
|
290
|
+
* while the extract or text module was loaded.
|
|
291
|
+
*
|
|
292
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded` for a document opened in the base
|
|
293
|
+
* module; reading errors (`data-pending` for a range document: use `ensure`).
|
|
294
|
+
*/
|
|
295
|
+
outline() {
|
|
296
|
+
return this.call(() => this.#extracting("doc.outline()").outline());
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Where the named destination `name` goes (the names a link or a `#nameddest=` address uses),
|
|
300
|
+
* or `undefined` when the document has none by that name. Needs a document opened while the
|
|
301
|
+
* extract or text module was loaded.
|
|
302
|
+
*
|
|
303
|
+
* @throws {@link LaminaPdfError} as {@link Document.outline}.
|
|
304
|
+
*/
|
|
305
|
+
namedDestination(name) {
|
|
306
|
+
return this.call(() => this.#extracting("doc.namedDestination()").namedDestination(name));
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The document's text for retrieval and LLMs: Markdown or plain text in reading order, the
|
|
310
|
+
* `laminapdf.extract/1` JSON with a box for every block, or chunks sized for retrieval. Tables
|
|
311
|
+
* drawn with lines come out as tables, and text a reader can't see is left out. Needs a
|
|
312
|
+
* document opened while the extract or text module was loaded.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* await init({ extract: true });
|
|
317
|
+
* const doc = Document.open(bytes);
|
|
318
|
+
* const markdown = doc.extract({ format: "markdown" });
|
|
319
|
+
* const chunks = doc.extract({ format: "chunks", chunk: { maxTokens: 400 } });
|
|
320
|
+
* ```
|
|
321
|
+
* @returns a string for `"markdown"` and `"text"`, an {@link Extraction} for `"json"`,
|
|
322
|
+
* {@link Chunk}s for `"chunks"`.
|
|
323
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded` for a document opened in the base
|
|
324
|
+
* module; `page-index-out-of-range`; `unknown-option` (with `didYouMean`) / `invalid-argument`
|
|
325
|
+
* for bad options; reading errors (`data-pending` for a range document: use `ensure`).
|
|
326
|
+
*/
|
|
327
|
+
extract(options) {
|
|
328
|
+
this.assertLive();
|
|
329
|
+
const doc = this.#doc;
|
|
330
|
+
if (typeof doc.extract !== "function") {
|
|
331
|
+
throw packageError("extract-module-not-loaded", "doc.extract() needs a document opened while the extract or text module was loaded");
|
|
332
|
+
}
|
|
333
|
+
const extract = doc.extract.bind(doc);
|
|
334
|
+
return parseExtract(options.format, this.call(() => extract(options)));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* An extraction stepped a page at a time, for models the host runs: each step that needs a
|
|
338
|
+
* model's result stops with a `request` (the page and resolution to render), answered with
|
|
339
|
+
* {@link ExtractJob.provide}. {@link extractWithModels} loops one for async models. Needs a
|
|
340
|
+
* document opened while the extract or text module was loaded.
|
|
341
|
+
*
|
|
342
|
+
* @throws {@link LaminaPdfError} as {@link Document.extract}.
|
|
343
|
+
*/
|
|
344
|
+
extractJob(options) {
|
|
345
|
+
this.assertLive();
|
|
346
|
+
const doc = this.#doc;
|
|
347
|
+
if (typeof doc.extractJob !== "function") {
|
|
348
|
+
throw packageError("extract-module-not-loaded", "doc.extractJob() needs a document opened while the extract or text module was loaded");
|
|
349
|
+
}
|
|
350
|
+
const extractJob = doc.extractJob.bind(doc);
|
|
351
|
+
return new ExtractJob(this.call(() => extractJob(options)), options.format, this, this.instance);
|
|
260
352
|
}
|
|
261
353
|
/** The Info dictionary's text entries (document text). @throws {@link LaminaPdfError} reading errors. */
|
|
262
354
|
get info() {
|
|
263
|
-
return
|
|
355
|
+
return this.call(() => this.#doc.info());
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Whether the document says it is tagged (`/MarkInfo /Marked true`); it doesn't check the tree.
|
|
359
|
+
* Needs a document opened while the extract or text module was loaded, as `page.text()` does.
|
|
360
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded`; reading errors.
|
|
361
|
+
*/
|
|
362
|
+
get isTagged() {
|
|
363
|
+
return this.call(() => this.#extracting("doc.isTagged").isTagged());
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* The structure tree's top-level elements in reading order, or `undefined` for a document
|
|
367
|
+
* without one. A text run's `mcid` (on {@link PageTextRun}) links it to the element whose
|
|
368
|
+
* `{ type: "content", page, mcid }` kid names it. Needs the extract or text module, as
|
|
369
|
+
* `page.text()` does.
|
|
370
|
+
* @throws {@link LaminaPdfError} `extract-module-not-loaded`; reading errors.
|
|
371
|
+
*/
|
|
372
|
+
structureTree() {
|
|
373
|
+
return this.call(() => this.#extracting("doc.structureTree()").structureTree());
|
|
374
|
+
}
|
|
375
|
+
/** The document as the extract module made it, or `extract-module-not-loaded` naming `what`. */
|
|
376
|
+
#extracting(what) {
|
|
377
|
+
const doc = this.#doc;
|
|
378
|
+
if (typeof doc.structureTree !== "function" || typeof doc.isTagged !== "function") {
|
|
379
|
+
throw packageError("extract-module-not-loaded", `${what} needs a document opened while the extract or text module was loaded`);
|
|
380
|
+
}
|
|
381
|
+
return doc;
|
|
264
382
|
}
|
|
265
383
|
/** Every warning so far (build warnings first), each the ADR 0026 §1 object. */
|
|
266
384
|
get warnings() {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
385
|
+
return this.call(() => {
|
|
386
|
+
const cursor = this.#doc.warnings();
|
|
387
|
+
try {
|
|
388
|
+
const out = [];
|
|
389
|
+
for (;;) {
|
|
390
|
+
const batch = cursor.nextBatch(WARNING_BATCH);
|
|
391
|
+
if (batch.length === 0)
|
|
392
|
+
return out;
|
|
393
|
+
out.push(...batch);
|
|
394
|
+
}
|
|
275
395
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
396
|
+
finally {
|
|
397
|
+
cursor.free();
|
|
398
|
+
}
|
|
399
|
+
});
|
|
280
400
|
}
|
|
281
401
|
/** Whether there are changes no save has written yet. */
|
|
282
402
|
get hasUnsavedChanges() {
|
|
283
|
-
return this.#doc.hasUnsavedChanges();
|
|
403
|
+
return this.call(() => this.#doc.hasUnsavedChanges());
|
|
284
404
|
}
|
|
285
405
|
/**
|
|
286
406
|
* Applies `ops` in order as one transaction: all of them, or none.
|
|
@@ -291,7 +411,7 @@ export class Document {
|
|
|
291
411
|
*/
|
|
292
412
|
apply(ops) {
|
|
293
413
|
this.#notInTransaction("apply");
|
|
294
|
-
return
|
|
414
|
+
return this.call(() => this.#doc.apply(ops));
|
|
295
415
|
}
|
|
296
416
|
/**
|
|
297
417
|
* Applies an op log (`{ v: 1, ops }`, as JSON text or an object) as one transaction.
|
|
@@ -301,7 +421,7 @@ export class Document {
|
|
|
301
421
|
applyLog(log) {
|
|
302
422
|
this.#notInTransaction("applyLog");
|
|
303
423
|
const json = typeof log === "string" ? log : JSON.stringify(log);
|
|
304
|
-
return
|
|
424
|
+
return this.call(() => this.#doc.applyLog(json));
|
|
305
425
|
}
|
|
306
426
|
/**
|
|
307
427
|
* Runs `edit` with a transaction handle and applies what it collected as one transaction
|
|
@@ -323,6 +443,7 @@ export class Document {
|
|
|
323
443
|
* ```
|
|
324
444
|
*/
|
|
325
445
|
transact(edit) {
|
|
446
|
+
this.assertLive();
|
|
326
447
|
this.#notInTransaction("transact");
|
|
327
448
|
this.#transacting = true;
|
|
328
449
|
const tx = new Transaction();
|
|
@@ -358,7 +479,7 @@ export class Document {
|
|
|
358
479
|
*/
|
|
359
480
|
undo() {
|
|
360
481
|
this.#notInTransaction("undo");
|
|
361
|
-
return
|
|
482
|
+
return this.call(() => this.#doc.undo());
|
|
362
483
|
}
|
|
363
484
|
/**
|
|
364
485
|
* Redoes the newest undone transaction.
|
|
@@ -368,7 +489,7 @@ export class Document {
|
|
|
368
489
|
*/
|
|
369
490
|
redo() {
|
|
370
491
|
this.#notInTransaction("redo");
|
|
371
|
-
return
|
|
492
|
+
return this.call(() => this.#doc.redo());
|
|
372
493
|
}
|
|
373
494
|
/**
|
|
374
495
|
* Saves and rebases onto the output (later edits and saves build on it).
|
|
@@ -387,7 +508,7 @@ export class Document {
|
|
|
387
508
|
*/
|
|
388
509
|
saveWithReport(options) {
|
|
389
510
|
this.#notInTransaction("save");
|
|
390
|
-
return
|
|
511
|
+
return this.call(() => this.#doc.save(options));
|
|
391
512
|
}
|
|
392
513
|
/**
|
|
393
514
|
* A save as a job stepped by the caller (to keep a UI responsive).
|
|
@@ -396,7 +517,7 @@ export class Document {
|
|
|
396
517
|
*/
|
|
397
518
|
saveJob(options) {
|
|
398
519
|
this.#notInTransaction("saveJob");
|
|
399
|
-
return new SaveJob(
|
|
520
|
+
return new SaveJob(this.call(() => this.#doc.saveJob(options)), this, this.instance);
|
|
400
521
|
}
|
|
401
522
|
/**
|
|
402
523
|
* Rebases onto `bytes`, the output of a save whose rebase failed (`not-rebased`).
|
|
@@ -405,23 +526,12 @@ export class Document {
|
|
|
405
526
|
*/
|
|
406
527
|
rebase(bytes) {
|
|
407
528
|
this.#notInTransaction("rebase");
|
|
408
|
-
|
|
529
|
+
this.call(() => this.#doc.rebase(bytes));
|
|
409
530
|
}
|
|
410
|
-
|
|
411
|
-
* Frees the document's WASM memory now; without it, it is freed when garbage-collected.
|
|
412
|
-
* Calling it twice is harmless; using the document afterwards is not (L2b adds `disposed`).
|
|
413
|
-
*/
|
|
414
|
-
free() {
|
|
415
|
-
if (this.#freed)
|
|
416
|
-
return;
|
|
417
|
-
this.#freed = true;
|
|
531
|
+
release() {
|
|
418
532
|
this.#doc.free();
|
|
419
533
|
// A range document's fetched bytes live in its sparse source.
|
|
420
534
|
this.#range?.sparse.free();
|
|
421
535
|
}
|
|
422
|
-
/** Frees the document at the end of a `using` block. */
|
|
423
|
-
[Symbol.dispose]() {
|
|
424
|
-
this.free();
|
|
425
|
-
}
|
|
426
536
|
}
|
|
427
537
|
//# sourceMappingURL=document.js.map
|