$ show zotero/reader
This repository provides a fully-featured, cross-platform document reader and annotator for PDF, EPUB, and HTML snapshots, used as the core reading interface within the Zotero reference management ecosystem. It integrates PDF.js and EPUB.js for rendering, and a custom Structured Document Text (SDT) pipeline for cross-format search, reading mode (reflow), and read-aloud (TTS) with both browser-native and remote voice providers. The architecture is modular: a platform-agnostic common layer defines core abstractions (View, AnnotationManager, FocusManager, KeyboardManager, ReaderUI), with platform-specific bindings for Zotero desktop, web, iOS WebKit, and Android. The UI is built with React and features annotation tools (highlight, underline, note, ink, image, text), sidebar with thumbnails/annotations/outline, find-in-document via a web worker, and extensive keyboard navigation. Annotation management supports undo/redo, debounced saving, filtering, and export. The codebase demonstrates strong engineering practices with reusable design patterns (LRU cache, approximate string matching, navigation history, popup delay), but also contains large monolithic controller classes (Reader, PDFView) that handle many responsibilities. Overall, it is a high-quality, actively maintained application with sophisticated document processing capabilities.
The LLM identified 4 files worth highlighting for reuse:
A TypeScript implementation of an LRU (Least Recently Used) cache with configurable maximum size, entry TTL (time-to-live), and automatic eviction of stale items. The cache supports `get`, `set`, `delete`, `clear`, and `entries` methods, all with O(1) average time complexity using a combination of a Map and a doubly-linked list. It can be extracted and reused in any JavaScript/TypeScript project needing a bounded, time-aware cache.
Implements the Myers bit-vector algorithm for efficient approximate string matching, supporting configurable edit distance (k). The function returns the start index and edit distance of the best match for a pattern within a text. It is self-contained, requires no internal project dependencies, and can be extracted for use in other projects needing fuzzy text search.
A generic navigation history manager that maintains a stack of states with support for grouping (`beginNavigation`/`endNavigation`), undo (back), redo (forward), and limit on stack size. It uses a `HistoryGroup` class to group multiple state changes into a single history entry. The implementation is isolated, with no dependencies on the project's other modules, making it reusable for any client-side or server-side navigation/undo pattern.
Provides a helper class that debounces the opening and closing of UI popups to prevent flicker during rapid hover or focus transitions. It manages separate delay timers for showing and hiding, and supports canceling pending operations. The pattern is self-contained and can be reused in any web application that needs smooth popup interactions.