/** * OCR and Receipt Scanning Types * * Types for text recognition and receipt parsing functionality. * Uses MLKit Text Recognition on-device with server fallback. */ import type { BaseDetectionResult, BoundingBox } from './index'; /** * A line of recognized text */ export interface TextLine { /** The recognized text content */ text: string; /** Confidence score (0-1) */ confidence: number; /** Bounding box of the text line */ boundingBox: BoundingBox; /** Language code if detected */ language?: string; } /** * A block of text (paragraph) */ export interface TextBlock { /** All text in the block */ text: string; /** Individual lines */ lines: TextLine[]; /** Bounding box of the entire block */ boundingBox: BoundingBox; /** Confidence score (0-1) */ confidence: number; } /** * Complete text recognition result */ export interface TextRecognitionResult { /** All recognized text concatenated */ fullText: string; /** Text blocks (paragraphs) */ blocks: TextBlock[]; /** All lines across all blocks */ lines: TextLine[]; /** Detected language */ language?: string; /** Overall confidence */ confidence: number; /** Processing source */ source: 'on_device' | 'server'; /** Processing time in ms */ processingTimeMs: number; } /** * A parsed item from a receipt */ export interface ReceiptItem { /** Item name as it appears on receipt */ name: string; /** Cleaned/normalized item name */ normalizedName?: string; /** Quantity purchased */ quantity?: number; /** Unit of measurement */ unit?: string; /** Price per unit */ unitPrice?: number; /** Total price for this item */ totalPrice?: number; /** Confidence in the parsing (0-1) */ confidence: number; /** Original text from receipt */ rawText: string; /** Line number in receipt */ lineNumber: number; /** Whether this item needs manual review */ needsReview: boolean; /** Suggested product matches from database */ suggestedMatches?: { productId: string; name: string; confidence: number; }[]; } /** * Receipt metadata */ export interface ReceiptMetadata { /** Store name if detected */ storeName?: string; /** Store location/address */ storeAddress?: string; /** Receipt date if detected */ date?: Date; /** Receipt time */ time?: string; /** Transaction/receipt number */ transactionId?: string; /** Subtotal before tax */ subtotal?: number; /** Tax amount */ tax?: number; /** Total amount */ total?: number; /** Payment method */ paymentMethod?: string; } /** * Complete receipt scan result */ export interface ReceiptScanResult extends BaseDetectionResult { type: 'receipt'; /** Parsed items from the receipt */ items: ReceiptItem[]; /** Receipt metadata */ metadata: ReceiptMetadata; /** Raw OCR result */ rawText: string; /** All text lines */ textLines: TextLine[]; /** Overall parsing confidence */ confidence: number; /** Number of items that need review */ itemsNeedingReview: number; } /** * Known store formats for optimized parsing */ export type KnownStore = 'walmart' | 'target' | 'kroger' | 'safeway' | 'costco' | 'trader_joes' | 'whole_foods' | 'publix' | 'aldi' | 'unknown'; /** * Options for useReceiptScanner hook */ export interface UseReceiptScannerOptions { /** Enable server fallback for complex receipts (default: true) */ serverFallback?: boolean; /** Server URL (uses MLVisionProvider config if not specified) */ serverUrl?: string; /** Minimum confidence to accept an item (default: 0.7) */ minConfidence?: number; /** Known store formats for optimized parsing */ recognizedStores?: KnownStore[]; /** Callback when items are detected */ onItemDetected?: (item: ReceiptItem) => void; /** Callback when parsing is complete */ onParseComplete?: (result: ReceiptScanResult) => void; /** Callback on error */ onError?: (error: Error) => void; } /** * Return type for useReceiptScanner hook */ export interface UseReceiptScannerReturn { /** Whether currently processing */ isProcessing: boolean; /** Parsed receipt items */ items: ReceiptItem[]; /** Receipt metadata */ metadata: ReceiptMetadata | null; /** Raw OCR text */ rawText: string; /** Overall confidence */ confidence: number; /** Processing source */ source: 'on_device' | 'server' | null; /** Current error if any */ error: Error | null; /** Scan a receipt photo */ scanReceipt: (uri: string) => Promise; /** Scan current camera frame */ scanFrame: () => Promise; /** Confirm an item is correct */ confirmItem: (item: ReceiptItem) => void; /** Reject/remove an item */ rejectItem: (item: ReceiptItem) => void; /** Edit an item */ editItem: (item: ReceiptItem, updates: Partial) => void; /** Clear all results */ clearResults: () => void; frameProcessor: unknown; } /** * Receipt line classification */ export type ReceiptLineType = 'item' | 'subtotal' | 'tax' | 'total' | 'payment' | 'store_info' | 'date_time' | 'transaction' | 'discount' | 'unknown'; /** * Parsed receipt line before item extraction */ export interface ParsedReceiptLine { /** Original text */ text: string; /** Classified line type */ type: ReceiptLineType; /** Extracted values */ values: { name?: string; quantity?: number; price?: number; }; /** Line number */ lineNumber: number; /** Confidence in classification */ confidence: number; } //# sourceMappingURL=ocr.d.ts.map