@laminapdf/sdk 0.0.0-stage → 0.2.0-alpha.3
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 +243 -2
- package/dist/api.d.ts +26 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +12 -0
- package/dist/api.js.map +1 -0
- package/dist/builder.d.ts +335 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +574 -0
- package/dist/builder.js.map +1 -0
- package/dist/defined.d.ts +5 -0
- package/dist/defined.d.ts.map +1 -0
- package/dist/defined.js +7 -0
- package/dist/defined.js.map +1 -0
- package/dist/document.d.ts +267 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +472 -0
- package/dist/document.js.map +1 -0
- package/dist/entry/node.d.ts +30 -0
- package/dist/entry/node.d.ts.map +1 -0
- package/dist/entry/node.js +37 -0
- package/dist/entry/node.js.map +1 -0
- package/dist/entry/workerd.d.ts +30 -0
- package/dist/entry/workerd.d.ts.map +1 -0
- package/dist/entry/workerd.js +37 -0
- package/dist/entry/workerd.js.map +1 -0
- package/dist/errors.d.ts +102 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +131 -0
- package/dist/errors.js.map +1 -0
- package/dist/explain.d.ts +20 -0
- package/dist/explain.d.ts.map +1 -0
- package/dist/explain.js +14 -0
- package/dist/explain.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 +73 -0
- package/dist/font.d.ts.map +1 -0
- package/dist/font.js +133 -0
- package/dist/font.js.map +1 -0
- package/dist/generated/builder-enums.d.ts +29 -0
- package/dist/generated/builder-enums.d.ts.map +1 -0
- package/dist/generated/builder-enums.js +80 -0
- package/dist/generated/builder-enums.js.map +1 -0
- package/dist/generated/codes.d.ts +109 -0
- package/dist/generated/codes.d.ts.map +1 -0
- package/dist/generated/codes.js +508 -0
- package/dist/generated/codes.js.map +1 -0
- package/dist/generated/explain.d.ts +6 -0
- package/dist/generated/explain.d.ts.map +1 -0
- package/dist/generated/explain.js +155 -0
- package/dist/generated/explain.js.map +1 -0
- package/dist/generated/extract.d.ts +235 -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/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +88 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +139 -0
- package/dist/init.js.map +1 -0
- 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/loader/fetch.d.ts +3 -0
- package/dist/loader/fetch.d.ts.map +1 -0
- package/dist/loader/fetch.js +2 -0
- package/dist/loader/fetch.js.map +1 -0
- package/dist/loader/node.d.ts +3 -0
- package/dist/loader/node.d.ts.map +1 -0
- package/dist/loader/node.js +9 -0
- package/dist/loader/node.js.map +1 -0
- package/dist/loader/workerd.d.ts +3 -0
- package/dist/loader/workerd.d.ts.map +1 -0
- package/dist/loader/workerd.js +15 -0
- package/dist/loader/workerd.js.map +1 -0
- package/dist/matrix.d.ts +16 -0
- package/dist/matrix.d.ts.map +1 -0
- package/dist/matrix.js +36 -0
- package/dist/matrix.js.map +1 -0
- package/dist/path.d.ts +34 -0
- package/dist/path.d.ts.map +1 -0
- package/dist/path.js +49 -0
- package/dist/path.js.map +1 -0
- package/dist/source/http.d.ts +36 -0
- package/dist/source/http.d.ts.map +1 -0
- package/dist/source/http.js +211 -0
- package/dist/source/http.js.map +1 -0
- package/dist/source/range.d.ts +75 -0
- package/dist/source/range.d.ts.map +1 -0
- package/dist/source/range.js +100 -0
- package/dist/source/range.js.map +1 -0
- package/dist/text.d.ts +90 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +127 -0
- package/dist/text.js.map +1 -0
- package/dist/transaction.d.ts +36 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +47 -0
- package/dist/transaction.js.map +1 -0
- package/dist/types.d.ts +79 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/worker/client.d.ts +88 -0
- package/dist/worker/client.d.ts.map +1 -0
- package/dist/worker/client.js +407 -0
- package/dist/worker/client.js.map +1 -0
- package/dist/worker/emitter.d.ts +12 -0
- package/dist/worker/emitter.d.ts.map +1 -0
- package/dist/worker/emitter.js +34 -0
- package/dist/worker/emitter.js.map +1 -0
- package/dist/worker/entry.d.ts +2 -0
- package/dist/worker/entry.d.ts.map +1 -0
- package/dist/worker/entry.js +4 -0
- package/dist/worker/entry.js.map +1 -0
- package/dist/worker/index.d.ts +7 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +4 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/protocol.d.ts +82 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/protocol.js +11 -0
- package/dist/worker/protocol.js.map +1 -0
- package/dist/worker/server.d.ts +51 -0
- package/dist/worker/server.d.ts.map +1 -0
- package/dist/worker/server.js +493 -0
- package/dist/worker/server.js.map +1 -0
- package/dist/worker/support.d.ts +43 -0
- package/dist/worker/support.d.ts.map +1 -0
- package/dist/worker/support.js +26 -0
- package/dist/worker/support.js.map +1 -0
- package/dist/worker/transfer.d.ts +3 -0
- package/dist/worker/transfer.d.ts.map +1 -0
- package/dist/worker/transfer.js +13 -0
- package/dist/worker/transfer.js.map +1 -0
- package/dist/worker/types.d.ts +50 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +2 -0
- package/dist/worker/types.js.map +1 -0
- package/docs/AGENTS.md +14 -0
- package/docs/api/README.md +147 -0
- package/docs/api/classes/Builder.md +467 -0
- package/docs/api/classes/Document.md +742 -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 +326 -0
- package/docs/api/classes/Transaction.md +111 -0
- package/docs/api/functions/callbackSource.md +33 -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/HttpRangeOptions.md +78 -0
- package/docs/api/interfaces/InitOptions.md +40 -0
- package/docs/api/interfaces/Leak.md +21 -0
- package/docs/api/interfaces/Location.md +53 -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/ExtractedBlock.md +82 -0
- package/docs/api/type-aliases/ExtractedPage.md +65 -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 +41 -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/Op.md +15 -0
- package/docs/api/type-aliases/OutlineEntry.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/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 +63 -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/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/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 +156 -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/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-limit-blocks.md +35 -0
- package/docs/errors/extract-module-not-loaded.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/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 +35 -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-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/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/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/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/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/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 +88 -0
- package/docs/pages/concepts/dependencies.md +44 -0
- package/docs/pages/concepts/errors-and-warnings.md +64 -0
- package/docs/pages/concepts/how-lamina-thinks.md +86 -0
- package/docs/pages/concepts/pages-and-coordinates.md +67 -0
- package/docs/pages/guides/accessible-pdfs.md +260 -0
- package/docs/pages/guides/archival-pdfs.md +429 -0
- package/docs/pages/guides/edit-a-pdf.md +137 -0
- package/docs/pages/guides/fonts-and-text.md +202 -0
- package/docs/pages/guides/images-and-vectors.md +219 -0
- package/docs/pages/guides/keep-the-page-responsive.md +81 -0
- package/docs/pages/guides/links-outlines-and-metadata.md +222 -0
- package/docs/pages/guides/password-protected-files.md +70 -0
- package/docs/pages/guides/save-a-pdf.md +144 -0
- package/docs/pages/guides/untrusted-files.md +80 -0
- package/docs/pages/index.md +33 -0
- package/docs/pages/install.md +75 -0
- package/docs/pages/quick-start/browser.md +67 -0
- package/docs/pages/quick-start/bun.md +60 -0
- package/docs/pages/quick-start/deno.md +58 -0
- package/docs/pages/quick-start/node.md +61 -0
- package/docs/pages/quick-start/rust.md +58 -0
- package/docs/pages/quick-start/workers.md +139 -0
- package/docs/pages/recipes/cloudflare-worker.md +115 -0
- package/docs/pages/recipes/extract-markdown.md +114 -0
- package/docs/pages/recipes/generate-then-edit.md +135 -0
- package/docs/pages/recipes/hello.md +94 -0
- package/docs/pages/recipes/images-and-vectors.md +209 -0
- package/docs/pages/recipes/invoice.md +226 -0
- package/docs/pages/recipes/links-and-outlines.md +215 -0
- package/docs/pages/recipes/multilingual.md +189 -0
- package/docs/pages/recipes/open-untrusted.md +65 -0
- package/docs/pages/recipes/pdf-a-archive.md +205 -0
- package/docs/pages/recipes/pdf-a3-invoice-with-xml.md +222 -0
- package/docs/pages/recipes/pdf-ua-report.md +237 -0
- package/docs/pages/recipes/report.md +125 -0
- package/docs/pages/recipes/web-worker-client.md +64 -0
- package/docs/pages/recipes.md +47 -0
- package/docs/pages/reference/changelog.md +86 -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 +77 -0
- package/docs/pages/troubleshooting.md +74 -0
- package/docs/renames.json +86 -0
- package/docs/schemas/error.schema.json +305 -0
- package/docs/schemas/renames.schema.json +29 -0
- package/package.json +93 -3
- package/schemas/error.schema.json +305 -0
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
// httpRangeSource: a remote PDF read with HTTP Range requests. Errors never carry the URL
|
|
2
|
+
// (ADR 0026 §4): it may hold tokens.
|
|
3
|
+
import { packageError } from "../errors.js";
|
|
4
|
+
import { WHOLE } from "./range.js";
|
|
5
|
+
/** `bytes start-end/size` → its numbers. */
|
|
6
|
+
function contentRange(header) {
|
|
7
|
+
const m = /^bytes (\d+)-(\d+)\/(\d+)$/.exec(header?.trim() ?? "");
|
|
8
|
+
if (m === null)
|
|
9
|
+
return undefined;
|
|
10
|
+
return { start: Number(m[1]), end: Number(m[2]), size: Number(m[3]) };
|
|
11
|
+
}
|
|
12
|
+
function failed(reason, status, cause) {
|
|
13
|
+
const e = packageError("fetch-failed", "fetching a range of the remote file failed", {
|
|
14
|
+
data: status === undefined ? { reason } : { reason, status },
|
|
15
|
+
});
|
|
16
|
+
if (cause !== undefined)
|
|
17
|
+
Object.defineProperty(e, "cause", { value: cause });
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
function changed() {
|
|
21
|
+
return packageError("source-changed", "the remote file changed while it was being read");
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A {@link RangeSource} over a URL, for `Document.openRange`. The first request asks for the
|
|
25
|
+
* last `tail` bytes, which gives the size and the part of the file a reader needs first (the
|
|
26
|
+
* xref is at the end). Every later request sends `If-Range` with the first strong `ETag` (else
|
|
27
|
+
* its `Last-Modified`); a response whose `ETag`, `Last-Modified` or total size differs fails
|
|
28
|
+
* with `source-changed`. A server that ignores
|
|
29
|
+
* `Range` (it answers `200`) is read with that one full download.
|
|
30
|
+
*
|
|
31
|
+
* The server must allow `Range` (across origins: `Access-Control-Allow-Headers: Range` and
|
|
32
|
+
* `Access-Control-Expose-Headers: Content-Range, Content-Length, ETag`) and must not compress
|
|
33
|
+
* the response.
|
|
34
|
+
*
|
|
35
|
+
* @param url - the file.
|
|
36
|
+
* @param options - headers, credentials, signal, block size.
|
|
37
|
+
* @returns the source, once the first request has answered.
|
|
38
|
+
* @throws {@link LaminaPdfError} `fetch-failed` (with `data.status`), `source-changed`.
|
|
39
|
+
*/
|
|
40
|
+
export async function httpRangeSource(url, options = {}) {
|
|
41
|
+
// A whole number of bytes, at least 1 (a fraction would make a malformed Range header).
|
|
42
|
+
const tail = Number.isFinite(options.tail) ? Math.max(1, Math.floor(options.tail ?? 0)) : 65_536;
|
|
43
|
+
const request = rangeRequester(url, options);
|
|
44
|
+
const first = await request(`bytes=-${tail}`, options.signal);
|
|
45
|
+
if (first.status === 200) {
|
|
46
|
+
// No range support: this response is the whole file.
|
|
47
|
+
const whole = new Uint8Array(await first.arrayBuffer());
|
|
48
|
+
// Tagged, so Document.openRange opens these bytes directly instead of copying them again.
|
|
49
|
+
return {
|
|
50
|
+
size: whole.length,
|
|
51
|
+
read: async (offset, length) => whole.slice(offset, offset + length),
|
|
52
|
+
[WHOLE]: whole,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
if (first.status === 416 && /^bytes \*\/0$/.test(first.headers.get("Content-Range")?.trim() ?? "")) {
|
|
56
|
+
// An empty file has no last bytes to send: open it as empty (Lamina PDF then says what it is).
|
|
57
|
+
await first.body?.cancel();
|
|
58
|
+
return { size: 0, read: async () => new Uint8Array() };
|
|
59
|
+
}
|
|
60
|
+
const file = new RangedFile(request, await readProbe(first));
|
|
61
|
+
return {
|
|
62
|
+
size: file.size,
|
|
63
|
+
read: (offset, length, opts) => file.read(offset, length, opts?.signal),
|
|
64
|
+
blockSize: options.blockSize ?? 16_384,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Cancels `res`'s body (nothing will read it) and rejects with `error`. */
|
|
68
|
+
async function discard(res, error) {
|
|
69
|
+
await res.body?.cancel();
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
function rangeRequester(url, options) {
|
|
73
|
+
const doFetch = options.fetch ?? fetch;
|
|
74
|
+
return async (range, signal, ifRange) => {
|
|
75
|
+
const headers = new Headers(options.headers);
|
|
76
|
+
headers.set("Range", range);
|
|
77
|
+
if (ifRange !== undefined)
|
|
78
|
+
headers.set("If-Range", ifRange);
|
|
79
|
+
try {
|
|
80
|
+
return await doFetch(url, {
|
|
81
|
+
headers,
|
|
82
|
+
...(options.credentials === undefined ? {} : { credentials: options.credentials }),
|
|
83
|
+
...(signal === undefined ? {} : { signal }),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
if (signal?.aborted)
|
|
88
|
+
throw signal.reason;
|
|
89
|
+
throw failed("network", undefined, e);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/** Checks the first answer is a `206` with the file's last bytes, and reads them. */
|
|
94
|
+
async function readProbe(first) {
|
|
95
|
+
if (first.status !== 206) {
|
|
96
|
+
return discard(first, failed("status", first.status));
|
|
97
|
+
}
|
|
98
|
+
const range = contentRange(first.headers.get("Content-Range"));
|
|
99
|
+
if (range === undefined || range.end !== range.size - 1) {
|
|
100
|
+
return discard(first, failed("content-range", 206));
|
|
101
|
+
}
|
|
102
|
+
const tailBytes = new Uint8Array(await first.arrayBuffer());
|
|
103
|
+
if (tailBytes.length !== range.size - range.start)
|
|
104
|
+
throw failed("content-range", 206);
|
|
105
|
+
return {
|
|
106
|
+
size: range.size,
|
|
107
|
+
tailStart: range.start,
|
|
108
|
+
tailBytes,
|
|
109
|
+
etag: first.headers.get("ETag") ?? undefined,
|
|
110
|
+
lastModified: first.headers.get("Last-Modified") ?? undefined,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/** The reads after the probe: from its tail, by ranged requests, or from one whole download. */
|
|
114
|
+
class RangedFile {
|
|
115
|
+
#request;
|
|
116
|
+
#probe;
|
|
117
|
+
// If-Range needs a strong ETag, else a Last-Modified date; a weak ETag is only compared.
|
|
118
|
+
#ifRange;
|
|
119
|
+
// Set once a ranged request is answered 200: the whole file, downloaded once and shared by
|
|
120
|
+
// every read (reads already in flight cancel their own bodies and wait for it).
|
|
121
|
+
#whole;
|
|
122
|
+
constructor(request, probe) {
|
|
123
|
+
this.#request = request;
|
|
124
|
+
this.#probe = probe;
|
|
125
|
+
const { etag, lastModified } = probe;
|
|
126
|
+
this.#ifRange = etag !== undefined && !etag.startsWith("W/") ? etag : lastModified;
|
|
127
|
+
}
|
|
128
|
+
get size() {
|
|
129
|
+
return this.#probe.size;
|
|
130
|
+
}
|
|
131
|
+
async read(offset, length, signal) {
|
|
132
|
+
const { tailStart, tailBytes } = this.#probe;
|
|
133
|
+
const end = offset + length;
|
|
134
|
+
if (offset >= tailStart)
|
|
135
|
+
return tailBytes.slice(offset - tailStart, end - tailStart);
|
|
136
|
+
if (end <= tailStart)
|
|
137
|
+
return this.#fetchRange(offset, end, signal);
|
|
138
|
+
// Straddles the tail the probe brought: fetch only the part before it.
|
|
139
|
+
const out = new Uint8Array(length);
|
|
140
|
+
out.set(await this.#fetchRange(offset, tailStart, signal));
|
|
141
|
+
out.set(tailBytes.subarray(0, end - tailStart), tailStart - offset);
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
/** Whether `res` shows a different version than the first response (ETag, then Last-Modified). */
|
|
145
|
+
#differs(res) {
|
|
146
|
+
const { etag, lastModified } = this.#probe;
|
|
147
|
+
const tag = res.headers.get("ETag") ?? undefined;
|
|
148
|
+
if (etag !== undefined && tag !== undefined)
|
|
149
|
+
return tag !== etag;
|
|
150
|
+
const modified = res.headers.get("Last-Modified") ?? undefined;
|
|
151
|
+
return lastModified !== undefined && modified !== undefined && modified !== lastModified;
|
|
152
|
+
}
|
|
153
|
+
/** The bytes `offset..end` from the network (or from the whole file, once there is one). */
|
|
154
|
+
async #fetchRange(offset, end, signal) {
|
|
155
|
+
if (this.#whole !== undefined)
|
|
156
|
+
return (await this.#whole).slice(offset, end);
|
|
157
|
+
const res = await this.#request(`bytes=${offset}-${end - 1}`, signal, this.#ifRange);
|
|
158
|
+
if (this.#differs(res)) {
|
|
159
|
+
return discard(res, changed());
|
|
160
|
+
}
|
|
161
|
+
if (res.status === 200)
|
|
162
|
+
return this.#fromWhole(res, offset, end);
|
|
163
|
+
return this.#fromPartial(res, offset, end);
|
|
164
|
+
}
|
|
165
|
+
/** The server ignored Range (or If-Range found the file changed and sent it whole). */
|
|
166
|
+
async #fromWhole(res, offset, end) {
|
|
167
|
+
if (this.#probe.etag !== undefined && res.headers.get("ETag") === null) {
|
|
168
|
+
return discard(res, changed());
|
|
169
|
+
}
|
|
170
|
+
let whole = this.#whole;
|
|
171
|
+
if (whole === undefined)
|
|
172
|
+
whole = this.#download(res);
|
|
173
|
+
else
|
|
174
|
+
await res.body?.cancel();
|
|
175
|
+
return (await whole).slice(offset, end);
|
|
176
|
+
}
|
|
177
|
+
#download(res) {
|
|
178
|
+
const download = res.arrayBuffer().then((buffer) => {
|
|
179
|
+
const bytes = new Uint8Array(buffer);
|
|
180
|
+
if (bytes.length !== this.#probe.size)
|
|
181
|
+
throw changed();
|
|
182
|
+
return bytes;
|
|
183
|
+
});
|
|
184
|
+
this.#whole = download;
|
|
185
|
+
// A failed or aborted download (its read's signal) must not stick: the next read that
|
|
186
|
+
// gets a 200 starts a new one.
|
|
187
|
+
download.catch(() => {
|
|
188
|
+
if (this.#whole === download)
|
|
189
|
+
this.#whole = undefined;
|
|
190
|
+
});
|
|
191
|
+
return download;
|
|
192
|
+
}
|
|
193
|
+
/** A `206` with exactly the bytes asked for, from the same file. */
|
|
194
|
+
async #fromPartial(res, offset, end) {
|
|
195
|
+
if (res.status !== 206) {
|
|
196
|
+
return discard(res, failed("status", res.status));
|
|
197
|
+
}
|
|
198
|
+
const got = contentRange(res.headers.get("Content-Range"));
|
|
199
|
+
if (got !== undefined && got.size !== this.#probe.size) {
|
|
200
|
+
return discard(res, changed());
|
|
201
|
+
}
|
|
202
|
+
if (got === undefined || got.start !== offset || got.end !== end - 1) {
|
|
203
|
+
return discard(res, failed("content-range", 206));
|
|
204
|
+
}
|
|
205
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
206
|
+
if (bytes.length !== end - offset)
|
|
207
|
+
throw failed("content-range", 206);
|
|
208
|
+
return bytes;
|
|
209
|
+
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,YAAY,CAAC,GAAa,EAAE,MAAc,EAAE,GAAW;QAC3D,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;YACvB,OAAO,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,GAAG,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QAC3D,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACvD,OAAO,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC;YACrE,OAAO,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC;QACtD,IAAI,KAAK,CAAC,MAAM,KAAK,GAAG,GAAG,MAAM;YAAE,MAAM,MAAM,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { WasmSparseSource } from "@laminapdf/wasm/base";
|
|
2
|
+
import type { BaseGlue } from "../init.js";
|
|
3
|
+
import type { Instance } from "../internal/instance.js";
|
|
4
|
+
/** A byte range of the input. */
|
|
5
|
+
export interface ByteRange {
|
|
6
|
+
/** First byte. */
|
|
7
|
+
readonly offset: number;
|
|
8
|
+
/** Number of bytes. */
|
|
9
|
+
readonly length: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Random access to a file whose bytes are fetched on demand (a remote file, a `Blob`, a file
|
|
13
|
+
* handle). `@laminapdf/viewer`'s document worker reads a `Blob` through it too.
|
|
14
|
+
*/
|
|
15
|
+
export interface RangeSource {
|
|
16
|
+
/** The file's size in bytes. */
|
|
17
|
+
readonly size: number;
|
|
18
|
+
/**
|
|
19
|
+
* The `length` bytes at `offset` (exactly that many: the file is at least `offset + length`
|
|
20
|
+
* long). Rejects when `signal` aborts.
|
|
21
|
+
*/
|
|
22
|
+
read(offset: number, length: number, options?: {
|
|
23
|
+
readonly signal?: AbortSignal;
|
|
24
|
+
}): Promise<Uint8Array>;
|
|
25
|
+
/** The block size this source prefers fetches aligned to (HTTP: fewer, larger requests). */
|
|
26
|
+
readonly blockSize?: number;
|
|
27
|
+
}
|
|
28
|
+
/** How a range document fetches. */
|
|
29
|
+
export interface RangeOptions {
|
|
30
|
+
/** Aborts the open's fetches: it rejects with the signal's reason. Later calls take their own
|
|
31
|
+
* signal ({@link Document.ensure}). */
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
/** Fetches are widened to whole blocks of this many bytes (default: the source's, else 4096). */
|
|
34
|
+
readonly blockSize?: number;
|
|
35
|
+
/** Extra bytes fetched after each range (default 0). */
|
|
36
|
+
readonly readahead?: number;
|
|
37
|
+
/** Rounds of fetches per call before giving up with the last `data-pending` (default 1024). */
|
|
38
|
+
readonly maxRounds?: number;
|
|
39
|
+
/** The most bytes the document may hold (default: no limit); more is `source-budget-exceeded`. */
|
|
40
|
+
readonly budget?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A {@link RangeSource} over a caller's read function (a `Blob.slice`, a file handle, an IPC call).
|
|
44
|
+
*
|
|
45
|
+
* @param size - the file's size in bytes.
|
|
46
|
+
* @param read - returns the `length` bytes at `offset`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function callbackSource(size: number, read: (offset: number, length: number, signal?: AbortSignal) => Promise<Uint8Array>): RangeSource;
|
|
49
|
+
/** @internal Marks a source whose bytes are all in memory already (`httpRangeSource` after a `200`). */
|
|
50
|
+
export declare const WHOLE: unique symbol;
|
|
51
|
+
/** @internal The whole file, when `source` already has it in memory. */
|
|
52
|
+
export declare function wholeBytes(source: RangeSource): Uint8Array | undefined;
|
|
53
|
+
/** @internal What a range document keeps to fetch more: never the password or a signal. */
|
|
54
|
+
export interface RangeState {
|
|
55
|
+
/** The instance the sparse source lives in, and its generation then. */
|
|
56
|
+
readonly instance: Instance<BaseGlue>;
|
|
57
|
+
readonly generation: number;
|
|
58
|
+
readonly sparse: WasmSparseSource;
|
|
59
|
+
readonly source: RangeSource;
|
|
60
|
+
readonly blockSize: number;
|
|
61
|
+
readonly readahead: number;
|
|
62
|
+
readonly maxRounds: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Runs `call` until it stops throwing (or rejecting with) `data-pending`: fetches the ranges
|
|
66
|
+
* asked for (widened to blocks, minus what the source holds), supplies them and calls again.
|
|
67
|
+
* Gives up with the last `data-pending` after `maxRounds`, or when a round asks again for
|
|
68
|
+
* exactly what the round before asked (no progress). The fetches of a round share one abort
|
|
69
|
+
* controller: `signal` aborts them all, and the first failure aborts the others; the round waits
|
|
70
|
+
* for every fetch before it throws, so nothing is supplied after it returns.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
export declare function settle<T>(state: RangeState, call: () => T | Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
75
|
+
//# sourceMappingURL=range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/source/range.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yB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UAAU,GAAG,SAAS,CAGtE;AAED,2FAA2F;AAC3F,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAsB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAuB/G"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isLaminaPdfError, packageError } from "../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link RangeSource} over a caller's read function (a `Blob.slice`, a file handle, an IPC call).
|
|
4
|
+
*
|
|
5
|
+
* @param size - the file's size in bytes.
|
|
6
|
+
* @param read - returns the `length` bytes at `offset`.
|
|
7
|
+
*/
|
|
8
|
+
export function callbackSource(size, read) {
|
|
9
|
+
return { size, read: (offset, length, options) => read(offset, length, options?.signal) };
|
|
10
|
+
}
|
|
11
|
+
/** The ranges of a `data-pending` error. */
|
|
12
|
+
function rangesOf(e) {
|
|
13
|
+
return e.ranges ?? [];
|
|
14
|
+
}
|
|
15
|
+
/** @internal Marks a source whose bytes are all in memory already (`httpRangeSource` after a `200`). */
|
|
16
|
+
export const WHOLE = Symbol("lamina.wholeBytes");
|
|
17
|
+
/** @internal The whole file, when `source` already has it in memory. */
|
|
18
|
+
export function wholeBytes(source) {
|
|
19
|
+
const bytes = source[WHOLE];
|
|
20
|
+
return bytes instanceof Uint8Array ? bytes : undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Runs `call` until it stops throwing (or rejecting with) `data-pending`: fetches the ranges
|
|
24
|
+
* asked for (widened to blocks, minus what the source holds), supplies them and calls again.
|
|
25
|
+
* Gives up with the last `data-pending` after `maxRounds`, or when a round asks again for
|
|
26
|
+
* exactly what the round before asked (no progress). The fetches of a round share one abort
|
|
27
|
+
* controller: `signal` aborts them all, and the first failure aborts the others; the round waits
|
|
28
|
+
* for every fetch before it throws, so nothing is supplied after it returns.
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
export async function settle(state, call, signal) {
|
|
33
|
+
const { instance, generation, sparse, blockSize, readahead, maxRounds } = state;
|
|
34
|
+
let previous;
|
|
35
|
+
for (let round = 0;; round++) {
|
|
36
|
+
let error;
|
|
37
|
+
try {
|
|
38
|
+
return await call();
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (!isLaminaPdfError(e, "data-pending"))
|
|
42
|
+
throw e;
|
|
43
|
+
error = e;
|
|
44
|
+
}
|
|
45
|
+
const asked = rangesOf(error);
|
|
46
|
+
const key = JSON.stringify(asked);
|
|
47
|
+
const flat = new Float64Array(asked.flatMap((r) => [r.offset, r.offset + r.length]));
|
|
48
|
+
// The planning is laminapdf-source's (`SparseSource::to_fetch`), shared with the Rust loop.
|
|
49
|
+
// The fetches await: a reset() or a trap may have replaced the sparse source's instance.
|
|
50
|
+
instance.check(generation, "Document");
|
|
51
|
+
const todo = instance.call(() => sparse.toFetch(flat, blockSize, readahead));
|
|
52
|
+
if (round >= maxRounds || todo.length === 0 || key === previous)
|
|
53
|
+
throw error;
|
|
54
|
+
signal?.throwIfAborted();
|
|
55
|
+
await fetchRound(state, todo, signal);
|
|
56
|
+
previous = key;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Fetches and supplies the flat `[start, end, …]` ranges of one round. */
|
|
60
|
+
async function fetchRound(state, todo, signal) {
|
|
61
|
+
const { instance, generation, sparse, source } = state;
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
64
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
65
|
+
let failure;
|
|
66
|
+
const fetches = [];
|
|
67
|
+
for (let i = 0; i + 1 < todo.length; i += 2) {
|
|
68
|
+
const start = todo[i] ?? 0;
|
|
69
|
+
const end = todo[i + 1] ?? 0;
|
|
70
|
+
fetches.push(source
|
|
71
|
+
.read(start, end - start, { signal: controller.signal })
|
|
72
|
+
.then((bytes) => {
|
|
73
|
+
if (bytes.length !== end - start) {
|
|
74
|
+
throw packageError("fetch-failed", "a range source returned a different number of bytes than asked for", {
|
|
75
|
+
data: { reason: "length", expected: end - start, got: bytes.length },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (controller.signal.aborted)
|
|
79
|
+
return;
|
|
80
|
+
instance.check(generation, "Document");
|
|
81
|
+
instance.call(() => sparse.supply(start, bytes));
|
|
82
|
+
})
|
|
83
|
+
.catch((e) => {
|
|
84
|
+
// The first failure wins; the aborts it causes in the other fetches don't replace it.
|
|
85
|
+
failure ??= { reason: e };
|
|
86
|
+
controller.abort(e);
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
await Promise.all(fetches);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
signal?.removeEventListener("abort", onAbort);
|
|
94
|
+
}
|
|
95
|
+
if (signal?.aborted)
|
|
96
|
+
throw signal.reason;
|
|
97
|
+
if (failure !== undefined)
|
|
98
|
+
throw failure.reason;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/source/range.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gB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AAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;YAAS,CAAC;QACT,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAChD,CAAC;IACD,IAAI,MAAM,EAAE,OAAO;QAAE,MAAM,MAAM,CAAC,MAAM,CAAC;IACzC,IAAI,OAAO,KAAK,SAAS;QAAE,MAAM,OAAO,CAAC,MAAM,CAAC;AAClD,CAAC"}
|
package/dist/text.d.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { PageTextJs, TextRunJs } from "@laminapdf/wasm/extract";
|
|
2
|
+
/** Options for {@link PageRef.text}. */
|
|
3
|
+
export interface TextOptions {
|
|
4
|
+
/** Leave out text drawn invisibly (rendering modes 3 and 7: OCR layers, hidden text). */
|
|
5
|
+
readonly skipInvisible?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/** A point in page space (ADR 0027: top-left of the displayed CropBox, y down, points). */
|
|
8
|
+
export interface QuadPoint {
|
|
9
|
+
readonly x: number;
|
|
10
|
+
readonly y: number;
|
|
11
|
+
}
|
|
12
|
+
/** A glyph's quad: its four corners, in drawing order (bottom-left, bottom-right, top-right, top-left of the glyph box). */
|
|
13
|
+
export type GlyphQuad = readonly [QuadPoint, QuadPoint, QuadPoint, QuadPoint];
|
|
14
|
+
/** One glyph of a run. */
|
|
15
|
+
export interface TextGlyph {
|
|
16
|
+
/** The glyph's text (document text; U+FFFD when its Unicode is unknown). */
|
|
17
|
+
readonly text: string;
|
|
18
|
+
/** Its quad in page space. */
|
|
19
|
+
readonly quad: GlyphQuad;
|
|
20
|
+
}
|
|
21
|
+
/** A run: glyphs of one font, size, direction and marked content on one baseline, in logical order. */
|
|
22
|
+
export declare class PageTextRun {
|
|
23
|
+
#private;
|
|
24
|
+
/** @internal */
|
|
25
|
+
constructor(page: PageText, run: TextRunJs);
|
|
26
|
+
/** The run's text in logical order (document text). */
|
|
27
|
+
get text(): string;
|
|
28
|
+
/** The font's `/BaseFont` (document text). */
|
|
29
|
+
get font(): string;
|
|
30
|
+
/** Font size, the text matrix applied. */
|
|
31
|
+
get size(): number;
|
|
32
|
+
/** Vertical writing. */
|
|
33
|
+
get vertical(): boolean;
|
|
34
|
+
/** The marked-content ID the run is in, if any (structure tree links). */
|
|
35
|
+
get mcid(): number | undefined;
|
|
36
|
+
/** The text comes from an `/ActualText` span. */
|
|
37
|
+
get actualText(): boolean;
|
|
38
|
+
/** Drawn invisibly (`Tr` 3 or 7: an OCR layer, hidden text). */
|
|
39
|
+
get invisible(): boolean;
|
|
40
|
+
/** The bounds of its glyph quads in page space: `{ x, y, width, height }`. */
|
|
41
|
+
get bounds(): {
|
|
42
|
+
readonly x: number;
|
|
43
|
+
readonly y: number;
|
|
44
|
+
readonly width: number;
|
|
45
|
+
readonly height: number;
|
|
46
|
+
};
|
|
47
|
+
/** The `[start, end)` range of its glyphs in the page's glyph arrays ({@link PageText.buffers}). */
|
|
48
|
+
get glyphRange(): readonly [number, number];
|
|
49
|
+
/** Its glyphs, with their quads (built on each call). */
|
|
50
|
+
glyphs(): TextGlyph[];
|
|
51
|
+
}
|
|
52
|
+
/** @internal The raw arrays of a PageText (the worker client sends them). */
|
|
53
|
+
export declare let rawOf: (text: PageText) => PageTextJs;
|
|
54
|
+
/** A page's extracted text: lines in reading order, and runs with their glyphs' quads. */
|
|
55
|
+
export declare class PageText {
|
|
56
|
+
#private;
|
|
57
|
+
/** @internal */
|
|
58
|
+
constructor(raw: PageTextJs);
|
|
59
|
+
/** The text by line (runs on one baseline joined, trimmed), in content order. */
|
|
60
|
+
get lines(): readonly string[];
|
|
61
|
+
/** The page's text: its lines joined with `\n`. */
|
|
62
|
+
text(): string;
|
|
63
|
+
/** The runs, in content order (made on first use). */
|
|
64
|
+
get runs(): readonly PageTextRun[];
|
|
65
|
+
/** Glyphs whose Unicode is unknown (shown as U+FFFD). */
|
|
66
|
+
get unmapped(): number;
|
|
67
|
+
/** The number of glyphs. */
|
|
68
|
+
readonly glyphCount: number;
|
|
69
|
+
/**
|
|
70
|
+
* Glyph `i`'s text and quad.
|
|
71
|
+
*
|
|
72
|
+
* @throws `RangeError` for an index outside `0 … glyphCount - 1`; `TypeError` once
|
|
73
|
+
* {@link PageText.buffers}' arrays were transferred to another thread.
|
|
74
|
+
*/
|
|
75
|
+
glyph(i: number): TextGlyph;
|
|
76
|
+
/**
|
|
77
|
+
* The arrays as the WASM returned them: `quads` (8 numbers per glyph), `glyphText` and
|
|
78
|
+
* `glyphOffsets` (glyph i is `glyphText.slice(glyphOffsets[i], glyphOffsets[i + 1])`). Post
|
|
79
|
+
* `quads.buffer` and `glyphOffsets.buffer` as transferables to move them to another thread;
|
|
80
|
+
* that detaches them here, and this PageText's `glyph()` and `glyphs()` then throw (`lines`
|
|
81
|
+
* and `runs` keep working). They are this PageText's own arrays, not copies: writing to them
|
|
82
|
+
* changes what `glyph()` returns.
|
|
83
|
+
*/
|
|
84
|
+
get buffers(): {
|
|
85
|
+
readonly quads: Float32Array;
|
|
86
|
+
readonly glyphText: string;
|
|
87
|
+
readonly glyphOffsets: Uint32Array;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErE,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,yFAAyF;IACzF,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;CAClC;AAED,2FAA2F;AAC3F,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,4HAA4H;AAC5H,MAAM,MAAM,SAAS,GAAG,SAAS,CAA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AAU,EAK1B;IAED,iFAAiF;IACjF,IAAI,KAAK,IAAI,SAAS,MAAM,EAAE,CAE7B;IAED,mDAAmD;IACnD,IAAI,IAAI,MAAM,CAEb;IAED,sDAAsD;IACtD,IAAI,IAAI,IAAI,SAAS,WAAW,EAAE,CAGjC;IAED,yDAAyD;IACzD,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,4BAA4B;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAE5B;;;;;OAKG;IACH,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAc1B;IAED;;;;;;;OAOG;IACH,IAAI,OAAO,IAAI;QAAE,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAA;KAAE,CAE9G;CACF"}
|
package/dist/text.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** A run: glyphs of one font, size, direction and marked content on one baseline, in logical order. */
|
|
2
|
+
export class PageTextRun {
|
|
3
|
+
#page;
|
|
4
|
+
#run;
|
|
5
|
+
#range;
|
|
6
|
+
/** @internal */
|
|
7
|
+
constructor(page, run) {
|
|
8
|
+
this.#page = page;
|
|
9
|
+
this.#run = run;
|
|
10
|
+
this.#range = Object.freeze([run.glyphs[0], run.glyphs[1]]);
|
|
11
|
+
}
|
|
12
|
+
/** The run's text in logical order (document text). */
|
|
13
|
+
get text() {
|
|
14
|
+
return this.#run.text;
|
|
15
|
+
}
|
|
16
|
+
/** The font's `/BaseFont` (document text). */
|
|
17
|
+
get font() {
|
|
18
|
+
return this.#run.font;
|
|
19
|
+
}
|
|
20
|
+
/** Font size, the text matrix applied. */
|
|
21
|
+
get size() {
|
|
22
|
+
return this.#run.size;
|
|
23
|
+
}
|
|
24
|
+
/** Vertical writing. */
|
|
25
|
+
get vertical() {
|
|
26
|
+
return this.#run.vertical;
|
|
27
|
+
}
|
|
28
|
+
/** The marked-content ID the run is in, if any (structure tree links). */
|
|
29
|
+
get mcid() {
|
|
30
|
+
return this.#run.mcid;
|
|
31
|
+
}
|
|
32
|
+
/** The text comes from an `/ActualText` span. */
|
|
33
|
+
get actualText() {
|
|
34
|
+
return this.#run.actualText;
|
|
35
|
+
}
|
|
36
|
+
/** Drawn invisibly (`Tr` 3 or 7: an OCR layer, hidden text). */
|
|
37
|
+
get invisible() {
|
|
38
|
+
return this.#run.invisible;
|
|
39
|
+
}
|
|
40
|
+
/** The bounds of its glyph quads in page space: `{ x, y, width, height }`. */
|
|
41
|
+
get bounds() {
|
|
42
|
+
const [x, y, width, height] = this.#run.bounds;
|
|
43
|
+
return { x, y, width, height };
|
|
44
|
+
}
|
|
45
|
+
/** The `[start, end)` range of its glyphs in the page's glyph arrays ({@link PageText.buffers}). */
|
|
46
|
+
get glyphRange() {
|
|
47
|
+
return this.#range;
|
|
48
|
+
}
|
|
49
|
+
/** Its glyphs, with their quads (built on each call). */
|
|
50
|
+
glyphs() {
|
|
51
|
+
const [start, end] = this.#run.glyphs;
|
|
52
|
+
const out = [];
|
|
53
|
+
for (let i = start; i < end; i++)
|
|
54
|
+
out.push(this.#page.glyph(i));
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** @internal The raw arrays of a PageText (the worker client sends them). */
|
|
59
|
+
export let rawOf;
|
|
60
|
+
/** A page's extracted text: lines in reading order, and runs with their glyphs' quads. */
|
|
61
|
+
export class PageText {
|
|
62
|
+
#raw;
|
|
63
|
+
#runs;
|
|
64
|
+
static {
|
|
65
|
+
rawOf = (text) => text.#raw;
|
|
66
|
+
}
|
|
67
|
+
#lines;
|
|
68
|
+
/** @internal */
|
|
69
|
+
constructor(raw) {
|
|
70
|
+
this.#raw = raw;
|
|
71
|
+
this.#lines = Object.freeze([...raw.lines]);
|
|
72
|
+
// Kept from the start: transferring the buffers detaches glyphOffsets.
|
|
73
|
+
this.glyphCount = Math.max(0, raw.glyphOffsets.length - 1);
|
|
74
|
+
}
|
|
75
|
+
/** The text by line (runs on one baseline joined, trimmed), in content order. */
|
|
76
|
+
get lines() {
|
|
77
|
+
return this.#lines;
|
|
78
|
+
}
|
|
79
|
+
/** The page's text: its lines joined with `\n`. */
|
|
80
|
+
text() {
|
|
81
|
+
return this.#lines.join("\n");
|
|
82
|
+
}
|
|
83
|
+
/** The runs, in content order (made on first use). */
|
|
84
|
+
get runs() {
|
|
85
|
+
this.#runs ??= this.#raw.runs.map((r) => new PageTextRun(this, r));
|
|
86
|
+
return this.#runs;
|
|
87
|
+
}
|
|
88
|
+
/** Glyphs whose Unicode is unknown (shown as U+FFFD). */
|
|
89
|
+
get unmapped() {
|
|
90
|
+
return this.#raw.unmapped;
|
|
91
|
+
}
|
|
92
|
+
/** The number of glyphs. */
|
|
93
|
+
glyphCount;
|
|
94
|
+
/**
|
|
95
|
+
* Glyph `i`'s text and quad.
|
|
96
|
+
*
|
|
97
|
+
* @throws `RangeError` for an index outside `0 … glyphCount - 1`; `TypeError` once
|
|
98
|
+
* {@link PageText.buffers}' arrays were transferred to another thread.
|
|
99
|
+
*/
|
|
100
|
+
glyph(i) {
|
|
101
|
+
if (!Number.isInteger(i) || i < 0 || i >= this.glyphCount) {
|
|
102
|
+
throw new RangeError(`glyph index ${i} is outside 0..${this.glyphCount - 1}`);
|
|
103
|
+
}
|
|
104
|
+
const q = this.#raw.quads;
|
|
105
|
+
if (q.length < (i + 1) * 8 || this.#raw.glyphOffsets.length <= i + 1) {
|
|
106
|
+
throw new TypeError("the glyph arrays were transferred (buffers): this PageText no longer holds them");
|
|
107
|
+
}
|
|
108
|
+
const o = i * 8;
|
|
109
|
+
const point = (k) => ({ x: q[o + 2 * k] ?? 0, y: q[o + 2 * k + 1] ?? 0 });
|
|
110
|
+
return {
|
|
111
|
+
text: this.#raw.glyphText.slice(this.#raw.glyphOffsets[i] ?? 0, this.#raw.glyphOffsets[i + 1] ?? 0),
|
|
112
|
+
quad: [point(0), point(1), point(2), point(3)],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The arrays as the WASM returned them: `quads` (8 numbers per glyph), `glyphText` and
|
|
117
|
+
* `glyphOffsets` (glyph i is `glyphText.slice(glyphOffsets[i], glyphOffsets[i + 1])`). Post
|
|
118
|
+
* `quads.buffer` and `glyphOffsets.buffer` as transferables to move them to another thread;
|
|
119
|
+
* that detaches them here, and this PageText's `glyph()` and `glyphs()` then throw (`lines`
|
|
120
|
+
* and `runs` keep working). They are this PageText's own arrays, not copies: writing to them
|
|
121
|
+
* changes what `glyph()` returns.
|
|
122
|
+
*/
|
|
123
|
+
get buffers() {
|
|
124
|
+
return { quads: this.#raw.quads, glyphText: this.#raw.glyphText, glyphOffsets: this.#raw.glyphOffsets };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=text.js.map
|
package/dist/text.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AA6BA,uGAAuG;AACvG,MAAM,OAAO,WAAW;IACb,KAAK,CAAW;IAChB,IAAI,CAAY;IAEhB,MAAM,CAA4B;IAE3C,gBAAgB;IAChB,YAAY,IAAc,EAAE,GAAc;QACxC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAU,CAAC,CAAC;IACvE,CAAC;IAED,uDAAuD;IACvD,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IACxB,CAAC;IAED,8CAA8C;IAC9C,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;I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