mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Implement intelligent panel detection for manga/comics using a three-tier fallback system that automatically selects the best detection method: - Tier 1: OpenCV edge detection (fast, accurate for clear panel borders) - Tier 2: COCO-SSD ML detection (handles irregular layouts) - Tier 3: Grid-based detection (lightweight, always works) The system automatically falls back through tiers if higher tiers fail or if CSP blocks 'unsafe-eval' required by ML libraries. Changes: - panel-detection/detector.js: Modified to use dynamic script loading * Calls loadMLLibraries() on first use for lazy loading * Checks if ML libraries loaded successfully before using them * Falls back to grid detection if CSP blocks eval or libraries fail * Uses globalThis.cv/tf/cocoSsd for UMD/global library access - panel-detection/load-scripts.js: Created dynamic script loader * Dynamically injects <script> tags when panel detection enabled * Checks CSP compatibility with canUseEval() function * Loads libraries in correct order: TensorFlow → OpenCV → COCO-SSD * Falls back to grid if ML libraries fail to load * Uses Promise-based API for clean async loading This library-native approach keeps all functionality within foliate-js without requiring changes to reader.html or consumer applications.