feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer (#306)

* feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer

* feat(reader): improve reader settings with brightness, emulate book mode, and click-to-paginate options

* feat(reader): add long strip scroll mode and update related settings
This commit is contained in:
brios
2026-04-22 17:26:57 -04:00
committed by Zach Yale
parent a3add5ded9
commit 61b9b53a60
47 changed files with 4458 additions and 874 deletions
@@ -69,7 +69,8 @@ export type ViewEvent =
| { type: 'go-last-section' }
| { type: 'toggle-toc' }
| { type: 'toggle-search' }
| { type: 'toggle-notes' };
| { type: 'toggle-notes' }
| { type: 'toggle-immersive' };
interface ViewCallbacks {
prev: () => void;
@@ -218,6 +219,9 @@ export class ReaderEventService {
} else if (k === 'n' || k === 'N') {
this.eventSubject.next({type: 'toggle-notes'});
event.preventDefault();
} else if (k === 'i' || k === 'I') {
this.eventSubject.next({type: 'toggle-immersive'});
event.preventDefault();
} else if (k === '?') {
this.eventSubject.next({type: 'toggle-shortcuts-help'});
event.preventDefault();
@@ -53,6 +53,7 @@ export class EbookShortcutsHelpComponent {
title: this.t.translate('readerEbook.shortcutsHelp.display'),
shortcuts: [
{keys: ['F'], description: this.t.translate('readerEbook.shortcutsHelp.toggleFullscreen')},
{keys: ['I'], description: this.t.translate('readerEbook.shortcutsHelp.toggleImmersive')},
{keys: ['Escape'], description: this.t.translate('readerEbook.shortcutsHelp.exitFullscreenCloseDialogs')}
]
},
@@ -1,12 +1,13 @@
<div
class="reader"
[class.immersive]="immersiveMode"
[style.background-color]="readerState().theme.bg ?? ''">
<div class="header-trigger-zone"
[class.inactive]="headerVisible"
[class.inactive]="headerVisible || immersiveMode"
(mouseenter)="onHeaderTriggerZoneEnter()"></div>
<div class="footer-trigger-zone"
[class.inactive]="forceNavbarVisible"
[class.inactive]="forceNavbarVisible || immersiveMode"
(mouseenter)="onFooterTriggerZoneEnter()"></div>
@if (isLoading) {
@@ -148,3 +148,14 @@ foliate-view::part(foot) {
min-height: 32px;
box-sizing: border-box;
}
.reader.immersive {
::ng-deep foliate-view::part(head),
::ng-deep foliate-view::part(foot) {
display: none !important;
}
.bookmark-indicator {
display: none;
}
}
@@ -33,6 +33,7 @@ import {NoteDialogResult, ReaderNoteDialogComponent} from './dialogs/note-dialog
import {EbookShortcutsHelpComponent} from './dialogs/shortcuts-help.component';
import {TranslocoPipe} from '@jsverse/transloco';
import {RelocateProgressData} from './state/progress.service';
import {WakeLockService} from '../../../shared/service/wake-lock.service';
@Component({
selector: 'app-ebook-reader',
@@ -83,6 +84,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
private selectionService = inject(ReaderSelectionService);
private headerService = inject(ReaderHeaderService);
private noteService = inject(ReaderNoteService);
private wakeLockService = inject(WakeLockService);
public sidebarService = inject(ReaderSidebarService);
public leftSidebarService = inject(ReaderLeftSidebarService);
@@ -108,6 +110,8 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
sectionFractions: number[] = [];
isFullscreen = false;
showShortcutsHelp = false;
immersiveMode = false;
private immersiveAutoHideTimer?: ReturnType<typeof setTimeout>;
readonly readerState = this.stateService.state;
readonly selectionState = this.selectionService.state;
@@ -161,6 +165,9 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.showShortcutsHelp = true);
// Enable wake lock after a short delay
setTimeout(() => this.wakeLockService.enable(), 1000);
this.isLoading = true;
this.initializeFoliate().pipe(
switchMap(() => this.epubCustomFontService.loadAndCacheFonts()),
@@ -180,6 +187,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
this.wakeLockService.disable();
this.destroy$.next();
this.destroy$.complete();
this.viewManager.destroy();
@@ -193,6 +201,9 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
this.noteService.reset();
this.epubCustomFontService.cleanup();
if (this.immersiveAutoHideTimer) {
clearTimeout(this.immersiveAutoHideTimer);
}
if (this._fileUrl) {
URL.revokeObjectURL(this._fileUrl);
this._fileUrl = null;
@@ -315,7 +326,11 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
}, 500);
break;
case 'middle-single-tap':
this.toggleHeaderNavbarPinned();
if (this.immersiveMode) {
this.immersiveTemporaryShow();
} else {
this.toggleHeaderNavbarPinned();
}
break;
case 'text-selected':
this.selectionService.handleTextSelected(event.detail, event.popupPosition);
@@ -326,6 +341,9 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
case 'toggle-shortcuts-help':
this.showShortcutsHelp = !this.showShortcutsHelp;
break;
case 'toggle-immersive':
this.toggleImmersiveMode();
break;
case 'go-first-section':
this.viewManager.goToSection(0).subscribe();
break;
@@ -442,6 +460,24 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
this.visibilityManager.handleFooterZoneEnter();
}
toggleImmersiveMode(): void {
this.immersiveMode = !this.immersiveMode;
if (this.immersiveMode) {
this.visibilityManager.setImmersive(true);
} else {
this.visibilityManager.setImmersive(false);
}
}
private immersiveTemporaryShow(): void {
if (!this.immersiveMode) return;
this.visibilityManager.temporaryShow();
if (this.immersiveAutoHideTimer) clearTimeout(this.immersiveAutoHideTimer);
this.immersiveAutoHideTimer = setTimeout(() => {
this.visibilityManager.hideTemporary();
}, 3000);
}
handleSelectionAction(action: TextSelectionAction): void {
if (action.type === 'note') {
this.noteService.openNewNoteDialog();
@@ -5,6 +5,7 @@ export interface HeaderFooterVisibilityState {
export class ReaderHeaderFooterVisibilityManager {
private isPinned = false;
private isImmersive = false;
private mouseY: number;
private readonly HEADER_HEIGHT = 20;
@@ -31,11 +32,13 @@ export class ReaderHeaderFooterVisibilityManager {
handleMouseMove(mouseY: number): void {
this.mouseY = mouseY;
this.updateVisibility();
if (!this.isImmersive) {
this.updateVisibility();
}
}
handleMouseLeave(): void {
if (!this.isPinned) {
if (!this.isPinned && !this.isImmersive) {
this.setHeaderVisible(false);
this.setFooterVisible(false);
this.notifyStateChange();
@@ -43,14 +46,14 @@ export class ReaderHeaderFooterVisibilityManager {
}
handleHeaderZoneEnter(): void {
if (!this.isPinned) {
if (!this.isPinned && !this.isImmersive) {
this.setHeaderVisible(true);
this.notifyStateChange();
}
}
handleFooterZoneEnter(): void {
if (!this.isPinned) {
if (!this.isPinned && !this.isImmersive) {
this.setFooterVisible(true);
this.notifyStateChange();
}
@@ -61,6 +64,37 @@ export class ReaderHeaderFooterVisibilityManager {
this.updateVisibility();
}
unpinIfPinned(): void {
if (this.isPinned) {
this.isPinned = false;
this.updateVisibility();
}
}
setImmersive(immersive: boolean): void {
this.isImmersive = immersive;
if (immersive) {
this.isPinned = false;
this.setHeaderVisible(false);
this.setFooterVisible(false);
this.notifyStateChange();
}
}
temporaryShow(): void {
this.setHeaderVisible(true);
this.setFooterVisible(true);
this.notifyStateChange();
}
hideTemporary(): void {
if (this.isImmersive) {
this.setHeaderVisible(false);
this.setFooterVisible(false);
this.notifyStateChange();
}
}
getVisibilityState(): HeaderFooterVisibilityState {
return {
headerVisible: this.headerVisible,