From 071d967f8ff18c8eb581764a8759dcfebbef2e78 Mon Sep 17 00:00:00 2001 From: Richard Roberson Date: Sat, 15 Nov 2025 14:06:44 -0700 Subject: [PATCH] feat(pdf): modernize text highlighting and parsing for fluidity - Offload computationally intensive text matching for real-time highlighting to a dedicated Web Worker, ensuring the main thread remains responsive during playback. - Implement a new overlay-based highlighting system that renders independently of the PDF's text layer, providing smoother and more reliable visual feedback without interfering with document rendering. - Introduce a new setting allowing users to enable or disable real-time text highlighting in PDFs, offering personalized control over the reading interface. - Upgrade the underlying text comparison algorithm to Dice similarity for more accurate and context-aware matching of spoken words to on-screen text, improving synchronization precision. - Improve sentence boundary detection, especially for quoted dialogue and complex structures, by enhancing the NLP processing logic, leading to a more natural audio-text flow. --- src/components/DocumentSettings.tsx | 19 +- src/components/PDFViewer.tsx | 58 +---- src/contexts/ConfigContext.tsx | 27 +- src/contexts/PDFContext.tsx | 3 +- src/utils/nlp.ts | 30 +-- src/utils/pdf.ts | 387 +++++++++++++++++++++++++--- src/utils/pdfHighlightWorker.ts | 135 ++++++++++ 7 files changed, 545 insertions(+), 114 deletions(-) create mode 100644 src/utils/pdfHighlightWorker.ts diff --git a/src/components/DocumentSettings.tsx b/src/components/DocumentSettings.tsx index 72ac593..49d1d42 100644 --- a/src/components/DocumentSettings.tsx +++ b/src/components/DocumentSettings.tsx @@ -32,7 +32,8 @@ export function DocumentSettings({ isOpen, setIsOpen, epub, html }: { footerMargin, leftMargin, rightMargin, - updateConfigKey + updateConfigKey, + pdfHighlightEnabled, } = useConfig(); const { createFullAudioBook: createEPUBAudioBook, regenerateChapter: regenerateEPUBChapter } = useEPUB(); const { createFullAudioBook: createPDFAudioBook, regenerateChapter: regeneratePDFChapter } = usePDF(); @@ -327,6 +328,22 @@ export function DocumentSettings({ isOpen, setIsOpen, epub, html }: {

)} + {!epub && !html && ( +
+ +

+ Show visual highlighting in the PDF viewer while TTS is reading. +

+
+ )} {epub && (