Closes #1392 Built in dictionary mode #1475
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add Built-in Dictionary Mode to BookReader
Overview
Closes #1392
This PR implements a built-in dictionary feature that allows users to click on words in the text layer to view definitions, pronunciation, synonyms, and translations. The feature enhances the reading experience by providing instant vocabulary assistance without leaving the book.
Features Implemented
Dictionary Mode Toggle
Word Lookup
Multi-language Support
Automatic language detection for:
Definition Popup
The popup displays:
User Interface
Technical Implementation
Modified Files
src/BookReader/Navbar.js
Added dictionary mode toggle methods:
enableDictionaryMode()- Activates dictionary featuresdisableDictionaryMode()- Deactivates and cleans upenableTextLayers()- Makes text layers interactivedisableTextLayers()- Restores default behaviorImplemented word lookup functionality:
handleWordSelection()- Extracts clicked wordshowDefinition()- Orchestrates the lookup processdetectLanguage()- Auto-detects word language using Unicode rangesgetDefinition()- Fetches definition from Free Dictionary APICreated popup display methods:
displayDefinitionPopup()- Renders the definition popupshowLoadingPopup()- Shows loading stateshowErrorPopup()- Handles lookup failurescloseDefinitionPopup()- Cleanup methodAdded auxiliary features:
speakWord()- Text-to-speech pronunciationtranslateWord()- Translation via MyMemory APIshowDictionaryModeMessage()- User guidance overlayUpdated
init()method to:textLayerRenderedevents for dynamic pagessrc/css/BRnav.scss
.dictionary-buttonstyles for the toggle control.dictionary-mode-activestate styles.dictionary-popupcomponent with gradient header, structured body layout, and interactive footer buttons.dictionary-mode-overlayfor helper messagespopupFadeIn,slideDown)APIs Used
Free Dictionary API (api.dictionaryapi.dev)
MyMemory Translation API (api.mymemory.translated.net)
Web Speech API (Browser native)
How It Works
.BRtextLayerand words become clickable with hover effectsUser Experience Improvements
Browser Compatibility
Testing Recommendations
Manual Testing Steps
Edge Cases to Test
Future Enhancements (Not in this PR)
Breaking Changes
None. This is a purely additive feature.
Dependencies
No new npm dependencies added. Uses:
Checklist
Related Issues
Closes #1392
Demo Instructions
To test this feature:
npm install && npm run serve-devReviewer Notes
Navbar.js(dictionary methods)BRnav.scss(dictionary classes)