mirror of
https://github.com/firecrawl/anydoc.git
synced 2026-09-14 14:18:33 +08:00
8f05b1a3db
- `code` on the rejection names the ConvertError variant, so callers branch on it rather than on the message text - napi fills `code` from the error's status, so the rejection is rebuilt in Task::reject, the one place with an Env to build a JS error with - ConvertErrorCode reaches index.d.ts through a dts header file, which survives regeneration
294 lines
7.7 KiB
TypeScript
294 lines
7.7 KiB
TypeScript
/* auto-generated by NAPI-RS */
|
|
/* eslint-disable */
|
|
/**
|
|
* `code` on the `Error` a failed conversion rejects with. Conversion fails
|
|
* only when no meaningful Markdown could be produced; producer quirks are
|
|
* recovered or skipped instead.
|
|
*/
|
|
export type ConvertErrorCode =
|
|
/** Unknown format, or one that cannot be converted (an image-only PDF). */
|
|
| 'unsupported'
|
|
/** Structurally unusable: no meaningful content could be extracted. */
|
|
| 'malformed'
|
|
/** Encrypted or password-protected. */
|
|
| 'encrypted'
|
|
/** Crossed a fixed safety limit (decompression, nesting, node count). */
|
|
| 'resourceLimit'
|
|
/** A part required for any meaningful output is absent. */
|
|
| 'missingPart'
|
|
/** The file could not be read, from `toMarkdown` only. */
|
|
| 'io'
|
|
/**
|
|
* An embedded binary asset (image, object payload). Bytes are always
|
|
* retained, so a document stays self-contained.
|
|
*/
|
|
export interface Asset {
|
|
/** Index into `Document.assets`, as referenced by an image source. */
|
|
id: number
|
|
/** MIME type, e.g. `image/png`. */
|
|
mediaType: string
|
|
/** Package part or stream the asset came from, for provenance. */
|
|
originPart: string
|
|
data: Buffer
|
|
}
|
|
|
|
export interface Block {
|
|
kind: BlockKind
|
|
/** heading: 1-6. */
|
|
level?: number
|
|
/** heading: stable anchor id when the document targets this heading. */
|
|
anchor?: string
|
|
/** heading, paragraph. */
|
|
content?: Array<Inline>
|
|
list?: List
|
|
table?: Table
|
|
/** blockQuote. */
|
|
blocks?: Array<Block>
|
|
/** codeBlock. */
|
|
lang?: string
|
|
/** codeBlock. */
|
|
text?: string
|
|
}
|
|
|
|
export declare const enum BlockKind {
|
|
heading = 'heading',
|
|
paragraph = 'paragraph',
|
|
list = 'list',
|
|
table = 'table',
|
|
blockQuote = 'blockQuote',
|
|
codeBlock = 'codeBlock',
|
|
rule = 'rule'
|
|
}
|
|
|
|
export interface Cell {
|
|
blocks: Array<Block>
|
|
colSpan: number
|
|
rowSpan: number
|
|
}
|
|
|
|
export interface CellSlot {
|
|
kind: CellSlotKind
|
|
/** origin. */
|
|
cell?: Cell
|
|
/** covered: row of the origin this position belongs to. */
|
|
originRow?: number
|
|
/** covered: column of the origin this position belongs to. */
|
|
originCol?: number
|
|
}
|
|
|
|
export declare const enum CellSlotKind {
|
|
origin = 'origin',
|
|
covered = 'covered'
|
|
}
|
|
|
|
export interface Document {
|
|
blocks: Array<Block>
|
|
/**
|
|
* Footnote and endnote bodies, referenced from text by a `noteRef`
|
|
* inline.
|
|
*/
|
|
notes: Array<Note>
|
|
assets: Array<Asset>
|
|
}
|
|
|
|
/**
|
|
* Input format, named after the extension that identifies it. Container
|
|
* variants that share a parser (`.docm`, `.xlsm`, `.ppsx`, ...) map onto
|
|
* these.
|
|
*/
|
|
export declare const enum Format {
|
|
doc = 'doc',
|
|
docx = 'docx',
|
|
odt = 'odt',
|
|
/**
|
|
* Converted with pdf-inspector, which emits Markdown directly:
|
|
* `toDocument` is unsupported for PDFs. Scanned or image-only PDFs
|
|
* (needing OCR) error as unsupported.
|
|
*/
|
|
pdf = 'pdf',
|
|
ppt = 'ppt',
|
|
pptx = 'pptx',
|
|
rtf = 'rtf',
|
|
epub = 'epub',
|
|
xlsx = 'xlsx',
|
|
ods = 'ods',
|
|
odp = 'odp',
|
|
csv = 'csv'
|
|
}
|
|
|
|
/**
|
|
* Detect the format from the content itself: the signature and identity each
|
|
* container specification designates (PDF header, RTF open group, OLE stream
|
|
* names, ZIP package mimetype/content types). Plain-text formats (CSV) carry
|
|
* no signature and return `null`; so does anything unrecognized.
|
|
*/
|
|
export declare function formatFromBytes(bytes: Uint8Array): Format | null
|
|
|
|
/** The format an extension names, with or without a leading dot. */
|
|
export declare function formatFromExtension(extension: string): Format | null
|
|
|
|
/** The format a path's extension names. */
|
|
export declare function formatFromPath(path: string): Format | null
|
|
|
|
export interface ImageSource {
|
|
kind: ImageSourceKind
|
|
/** external. */
|
|
url?: string
|
|
/** asset: index into `Document.assets`. */
|
|
assetId?: number
|
|
}
|
|
|
|
export declare const enum ImageSourceKind {
|
|
/** Absolute URL with a scheme. */
|
|
external = 'external',
|
|
/** Embedded image, carried in `Document.assets`. */
|
|
asset = 'asset',
|
|
/**
|
|
* No usable source: the image's part is missing or unreadable and it has
|
|
* no URL. Only the alt text remains.
|
|
*/
|
|
unavailable = 'unavailable'
|
|
}
|
|
|
|
export interface Inline {
|
|
kind: InlineKind
|
|
/** text. */
|
|
text?: string
|
|
/** text. */
|
|
style?: Style
|
|
/** link. */
|
|
content?: Array<Inline>
|
|
/** link. */
|
|
target?: LinkTarget
|
|
/** image. */
|
|
alt?: string
|
|
/** image. */
|
|
source?: ImageSource
|
|
/** anchor: the anchor id. */
|
|
anchor?: string
|
|
/** noteRef: the id of the note in `Document.notes`. */
|
|
noteId?: string
|
|
}
|
|
|
|
export declare const enum InlineKind {
|
|
text = 'text',
|
|
link = 'link',
|
|
image = 'image',
|
|
/** Zero-width marker for an internal link target at this position. */
|
|
anchor = 'anchor',
|
|
noteRef = 'noteRef',
|
|
lineBreak = 'lineBreak'
|
|
}
|
|
|
|
export interface LinkTarget {
|
|
kind: LinkTargetKind
|
|
/** The URL, relative reference, or anchor id. */
|
|
value: string
|
|
}
|
|
|
|
export declare const enum LinkTargetKind {
|
|
/** Absolute URL with a scheme. */
|
|
external = 'external',
|
|
/** Scheme-less relative reference, preserved as written. */
|
|
relative = 'relative',
|
|
/** Internal target: a heading anchor or an `anchor` inline. */
|
|
anchor = 'anchor'
|
|
}
|
|
|
|
export interface List {
|
|
marker: MarkerKind
|
|
/** Ordinal the first item counts from. */
|
|
start: number
|
|
items: Array<ListItem>
|
|
}
|
|
|
|
export interface ListItem {
|
|
blocks: Array<Block>
|
|
/** Task-list state, when the item carries a checkbox. */
|
|
checked?: boolean
|
|
/**
|
|
* Literal marker text that overrides the list marker when the source
|
|
* number text cannot be reproduced from the marker and position alone
|
|
* (composite number text such as `1-a)`).
|
|
*/
|
|
markerLabel?: string
|
|
}
|
|
|
|
/** The marker family a list uses in the source document. */
|
|
export declare const enum MarkerKind {
|
|
bullet = 'bullet',
|
|
decimal = 'decimal',
|
|
lowerAlpha = 'lowerAlpha',
|
|
upperAlpha = 'upperAlpha',
|
|
lowerRoman = 'lowerRoman',
|
|
upperRoman = 'upperRoman'
|
|
}
|
|
|
|
export interface Note {
|
|
id: string
|
|
kind: NoteKind
|
|
blocks: Array<Block>
|
|
}
|
|
|
|
export declare const enum NoteKind {
|
|
footnote = 'footnote',
|
|
endnote = 'endnote'
|
|
}
|
|
|
|
/** Fully resolved character style. */
|
|
export interface Style {
|
|
bold: boolean
|
|
italic: boolean
|
|
strike: boolean
|
|
code: boolean
|
|
}
|
|
|
|
/**
|
|
* Canonical table grid: every logical grid position appears exactly once.
|
|
* Content and spans live on the origin slot, and each position a span covers
|
|
* holds a `covered` slot pointing back at that origin.
|
|
*/
|
|
export interface Table {
|
|
grid: Array<Array<CellSlot>>
|
|
/** Number of leading rows that are header rows (0 = no header). */
|
|
headerRows: number
|
|
kind: TableKind
|
|
}
|
|
|
|
export declare const enum TableKind {
|
|
/** A real data table. */
|
|
data = 'data',
|
|
/** Layout scaffolding (text boxes, positioning tables). */
|
|
layout = 'layout'
|
|
}
|
|
|
|
/**
|
|
* Parse an in-memory document into the document model, which also carries
|
|
* the embedded assets. Without a format, it is detected from the content.
|
|
*
|
|
* Unsupported for `pdf`: PDF conversion produces Markdown directly and has
|
|
* no document-model form; use `toMarkdownBytes`.
|
|
*
|
|
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`.
|
|
*/
|
|
export declare function toDocument(bytes: Uint8Array, format?: Format | undefined | null): Promise<Document>
|
|
|
|
/**
|
|
* Convert a document file to Markdown. The format is detected from the file
|
|
* content; the extension is the fallback for signature-less formats (CSV)
|
|
* and unrecognizable containers.
|
|
*
|
|
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`; a file
|
|
* that cannot be read is `'io'`.
|
|
*/
|
|
export declare function toMarkdown(path: string): Promise<string>
|
|
|
|
/**
|
|
* Convert an in-memory document to Markdown. Without a format, it is
|
|
* detected from the content, which signature-less formats (CSV) have to name
|
|
* explicitly.
|
|
*
|
|
* Rejects with an `Error` carrying a `ConvertErrorCode` on `code`.
|
|
*/
|
|
export declare function toMarkdownBytes(bytes: Uint8Array, format?: Format | undefined | null): Promise<string>
|