import { F as Filter } from '../Filter-BGcyIAvO.js'; import { L as Language, F as FilterConfig, C as CheckProfanityResult } from '../types-B9c_ik4k.js'; /** * OCR (Optical Character Recognition) Integration for glin-profanity * * Extracts text from images and checks for profanity. * Uses Tesseract.js as an optional peer dependency. * * @example * ```typescript * import { createOCRChecker, checkImageForProfanity } from 'glin-profanity/ocr'; * * // Quick check * const result = await checkImageForProfanity(imageBuffer); * console.log(result.containsProfanity); * * // With custom config * const checker = createOCRChecker({ * languages: ['english', 'spanish'], * tesseractLangs: ['eng', 'spa'], * detectLeetspeak: true, * }); * const result = await checker.checkImage(imageBuffer); * ``` * * @packageDocumentation * @module glin-profanity/ocr */ type ImageLike = string | Buffer | Uint8Array | Blob | File | HTMLImageElement | HTMLCanvasElement; /** * OCR checker configuration */ interface OCRCheckerConfig { /** Languages for profanity detection */ languages?: Language[]; /** Tesseract language codes (e.g., 'eng', 'spa', 'fra') */ tesseractLangs?: string[]; /** Enable leetspeak detection */ detectLeetspeak?: boolean; /** Enable Unicode normalization */ normalizeUnicode?: boolean; /** Minimum OCR confidence to process text (0-100) */ minConfidence?: number; /** Custom filter configuration */ filterConfig?: Partial; } /** * OCR check result */ interface OCRCheckResult { /** Whether profanity was found in the extracted text */ containsProfanity: boolean; /** Extracted text from the image */ extractedText: string; /** OCR confidence score (0-100) */ ocrConfidence: number; /** Profane words found */ profaneWords: string[]; /** Full profanity check result */ profanityResult: CheckProfanityResult; /** Processing time in milliseconds */ processingTimeMs: number; } /** * Creates an OCR profanity checker * * @example * ```typescript * const checker = createOCRChecker({ * languages: ['english'], * tesseractLangs: ['eng'], * detectLeetspeak: true, * }); * * // Check an image * const result = await checker.checkImage('./screenshot.png'); * * // Check multiple images * const results = await checker.checkImages([image1, image2, image3]); * * // Clean up when done * await checker.terminate(); * ``` */ declare function createOCRChecker(config?: OCRCheckerConfig): { /** * Check a single image for profanity */ checkImage(image: ImageLike): Promise; /** * Check multiple images for profanity */ checkImages(images: ImageLike[]): Promise; /** * Extract text from image without profanity check */ extractText(image: ImageLike): Promise<{ text: string; confidence: number; }>; /** * Check extracted text (if you already have text from another OCR) */ checkText(text: string): CheckProfanityResult; /** * Terminate the Tesseract worker (clean up resources) */ terminate(): Promise; /** * Get the underlying filter instance */ getFilter(): Filter; }; /** * Quick function to check an image for profanity * Creates a temporary worker, checks the image, and terminates * * @example * ```typescript * import { checkImageForProfanity } from 'glin-profanity/ocr'; * * const result = await checkImageForProfanity('./meme.png'); * if (result.containsProfanity) { * console.log('Found profanity:', result.profaneWords); * } * ``` */ declare function checkImageForProfanity(image: ImageLike, config?: OCRCheckerConfig): Promise; /** * Batch check multiple images for profanity * More efficient than calling checkImageForProfanity multiple times * * @example * ```typescript * import { batchCheckImages } from 'glin-profanity/ocr'; * * const images = ['./img1.png', './img2.png', './img3.png']; * const results = await batchCheckImages(images); * * const flagged = results.filter(r => r.containsProfanity); * console.log(`${flagged.length} images contain profanity`); * ``` */ declare function batchCheckImages(images: ImageLike[], config?: OCRCheckerConfig): Promise; /** * Supported Tesseract language codes * Map from glin-profanity language to Tesseract code */ declare const LANGUAGE_TO_TESSERACT: Record; /** * Helper to convert glin-profanity languages to Tesseract codes */ declare function languagesToTesseract(languages: Language[]): string[]; export { CheckProfanityResult, FilterConfig, LANGUAGE_TO_TESSERACT, Language, type OCRCheckResult, type OCRCheckerConfig, batchCheckImages, checkImageForProfanity, createOCRChecker, languagesToTesseract };