Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ragaeeb/kokokor/llms.txt

Use this file to discover all available pages before exploring further.

Overview

BoundingBox is used to define the location and size of text elements and structural components within a document coordinate system.

Type Definition

type BoundingBox = Size & {
  x: number;
  y: number;
};

type Size = {
  readonly height: number;
  readonly width: number;
};
Expanded:
type BoundingBox = {
  x: number;
  y: number;
  width: number;
  height: number;
};

Coordinate System

The coordinate system typically uses:
  • Origin (0,0) at the top-left corner of the document
  • X-axis extending rightward (for LTR text) or leftward (for RTL text after normalization)
  • Y-axis extending downward

Fields

x
number
required
The x-coordinate of the top-left corner of the bounding box in pixels.This coordinate may be normalized depending on text direction:
  • For LTR (left-to-right) text: represents distance from left edge
  • For RTL (right-to-left) text: may be adjusted during processing
y
number
required
The y-coordinate of the top-left corner of the bounding box in pixels.Represents the distance from the top edge of the document.
width
number
required
The width of the rectangular area in pixels.
height
number
required
The height of the rectangular area in pixels.

Usage Example

import type { BoundingBox } from 'kokokor';

// Define a text observation with its bounding box
const observation = {
  bbox: {
    x: 100,      // 100px from left edge
    y: 200,      // 200px from top edge
    width: 150,  // 150px wide
    height: 30   // 30px tall
  },
  text: 'Hello world'
};

// Use bounding boxes for layout elements
const horizontalLine: BoundingBox = {
  x: 50,
  y: 2800,
  width: 2450,
  height: 5
};

const result = await reconstructParagraphs({
  observations: [observation],
  page: { width: 2550, height: 3300, dpiX: 300, dpiY: 300 },
  layout: {
    horizontalLines: [horizontalLine]
  }
});

RTL Text Handling

For RTL (right-to-left) languages, coordinates may be normalized during processing:
const result = await reconstructParagraphs(
  {
    observations: [...],
    page: { width: 2550, height: 3300, dpiX: 300, dpiY: 300 }
  },
  {
    line: {
      isRTL: true  // Enable RTL coordinate normalization
    }
  }
);

See Also

Build docs developers (and LLMs) love