/** * Path or buffer for the ONNX layout analysis model. */ export interface ModelPathOptions { /** * ONNX file buffer or path for the layout analysis model. * If not provided, the default PP-DocLayoutV2 model will be fetched from GitHub. */ model?: ArrayBuffer | string; } /** * Controls verbose output for debugging. */ export interface DebuggingOptions { /** * Enable detailed logging of each processing step. * @default false */ verbose?: boolean; /** * Save annotated debug images to disk showing detected layout regions. * @default false */ debug?: boolean; /** * Directory where debug images will be written. * Relative to the current working directory. * @default "out" */ debugFolder?: string; } /** * Parameters for the layout analysis inference stage. */ export interface DetectionOptions { /** * Minimum confidence score to include a detected region. * @default 0.5 */ threshold?: number; /** * Fixed input size for the model (both width and height). * @default 800 */ modelInputSize?: number; /** * Whether to include segmentation masks in the result (only available for V3 models). * @default false */ includeMasks?: boolean; } /** * ONNX Runtime session configuration options. */ export interface SessionOptions { /** * Execution providers to use for inference (e.g., 'cpu', 'cuda'). * @default ['cpu'] */ executionProviders?: string[]; /** * Graph optimization level for ONNX Runtime. * @default 'all' */ graphOptimizationLevel?: "disabled" | "basic" | "extended" | "layout" | "all"; /** * Enable CPU memory arena for better memory management. * @default true */ enableCpuMemArena?: boolean; /** * Enable memory pattern optimization. * @default true */ enableMemPattern?: boolean; /** * Execution mode for the session. * @default 'sequential' */ executionMode?: "sequential" | "parallel"; /** * Number of inter-op threads. 0 lets ONNX decide. * @default 0 */ interOpNumThreads?: number; /** * Number of intra-op threads. 0 lets ONNX decide. * @default 0 */ intraOpNumThreads?: number; } /** * Full configuration for the DocLayout service. */ export interface DocLayoutOptions { /** File path or buffer for the ONNX model. */ model?: ModelPathOptions; /** Controls parameters for layout analysis inference. */ detection?: DetectionOptions; /** Controls logging behavior for debugging. */ debugging?: DebuggingOptions; /** ONNX Runtime session configuration options. */ session?: SessionOptions; } /** * A single detected layout region with label, confidence, and bounding box. * Bounding box coordinates are in original image space. */ export interface LayoutBox { /** Human-readable label for this region (e.g., "text", "table", "image"). */ label: string; /** Zero-based index into the LABELS array. */ labelIndex: number; /** Confidence score (0–1). */ score: number; /** Bounding box as [x1, y1, x2, y2] in original image coordinates. */ box: [number: number, number: number, number: number, number: number]; } /** * Result of layout analysis containing all detected regions in reading order. */ export interface DocLayoutResult { /** All detected layout regions, sorted in reading order by the model. */ boxes: LayoutBox[]; } /** * Extended result with per-region segmentation masks (V3 models only). */ export interface DocLayoutResultWithMasks extends DocLayoutResult { /** Per-region binary segmentation masks (200×200 Int32Array), indexed same as boxes. */ masks: Int32Array[]; }