Implement streaming EPUB reader with on-demand loading (#2350)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
@@ -88,9 +88,11 @@
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="loading-container">
|
||||
<p-progressSpinner class="custom-spinner"></p-progressSpinner>
|
||||
<p class="loading-text">Processing pages... This may take a few seconds on first load. Future loads will be significantly faster.</p>
|
||||
<div class="loader-overlay">
|
||||
<div class="loader-content">
|
||||
<div class="spinner"></div>
|
||||
<p class="loader-text">Loading book...</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -458,3 +458,45 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.loader-overlay {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: rgba(0, 0, 0, 0.8);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 9999;
|
||||
}
|
||||
|
||||
.loader-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 1.5rem;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border: 4px solid rgba(255, 255, 255, 0.2);
|
||||
border-top-color: #fff;
|
||||
border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
|
||||
.loader-text {
|
||||
color: #fff;
|
||||
font-size: 1.1rem;
|
||||
margin: 0;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -313,11 +313,14 @@ $transition-fast: 150ms ease;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page-nav-left,
|
||||
.page-nav-right {
|
||||
.page-nav-left {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.page-nav-right {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.page-nav-left {
|
||||
margin: 0 auto;
|
||||
justify-content: center;
|
||||
|
||||
+22
-18
@@ -1,21 +1,25 @@
|
||||
<div class="cbx-header" [class.visible]="isVisible">
|
||||
<button class="icon-btn" (click)="onOpenSidebar()" title="Contents">
|
||||
<app-reader-icon name="menu" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onToggleBookmark()" [title]="isCurrentPageBookmarked ? 'Remove Bookmark' : 'Add Bookmark'" [class.active]="isCurrentPageBookmarked">
|
||||
<app-reader-icon name="bookmark" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onOpenNoteDialog()" [title]="currentPageHasNotes ? 'Page has notes - Add another' : 'Add Note'" [class.has-notes]="currentPageHasNotes">
|
||||
<app-reader-icon name="note" [size]="20" />
|
||||
@if (currentPageHasNotes) {
|
||||
<span class="indicator-dot"></span>
|
||||
}
|
||||
</button>
|
||||
<div class="header-left">
|
||||
<button class="icon-btn" (click)="onOpenSidebar()" title="Contents">
|
||||
<app-reader-icon name="menu" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onToggleBookmark()" [title]="isCurrentPageBookmarked ? 'Remove Bookmark' : 'Add Bookmark'" [class.active]="isCurrentPageBookmarked">
|
||||
<app-reader-icon name="bookmark" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onOpenNoteDialog()" [title]="currentPageHasNotes ? 'Page has notes - Add another' : 'Add Note'" [class.has-notes]="currentPageHasNotes">
|
||||
<app-reader-icon name="note" [size]="20" />
|
||||
@if (currentPageHasNotes) {
|
||||
<span class="indicator-dot"></span>
|
||||
}
|
||||
</button>
|
||||
</div>
|
||||
<span class="book-title">{{ bookTitle }}</span>
|
||||
<button class="icon-btn" (click)="onOpenSettings()" title="Settings">
|
||||
<app-reader-icon name="settings" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn close-btn" (click)="onClose(); $event.stopPropagation()" title="Close Reader">
|
||||
<app-reader-icon name="close" [size]="20" />
|
||||
</button>
|
||||
<div class="header-right">
|
||||
<button class="icon-btn" (click)="onOpenSettings()" title="Settings">
|
||||
<app-reader-icon name="settings" [size]="20" />
|
||||
</button>
|
||||
<button class="icon-btn close-btn" (click)="onClose(); $event.stopPropagation()" title="Close Reader">
|
||||
<app-reader-icon name="close" [size]="20" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+21
-7
@@ -25,6 +25,13 @@
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
|
||||
.header-left,
|
||||
.header-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
@@ -47,7 +54,7 @@
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
&:last-child {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
@@ -85,7 +92,10 @@
|
||||
}
|
||||
|
||||
.book-title {
|
||||
flex: 1;
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
max-width: calc(100% - 240px);
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
@@ -96,21 +106,25 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
min-height: 1.2em;
|
||||
padding: 0 16px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.cbx-header {
|
||||
padding: 0 8px;
|
||||
padding: 0 4px;
|
||||
|
||||
.icon-btn {
|
||||
padding: 10px;
|
||||
padding: 5px;
|
||||
margin-right: 6px;
|
||||
|
||||
app-reader-icon {
|
||||
transform: scale(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
.book-title {
|
||||
font-size: 13px;
|
||||
padding: 0 8px;
|
||||
font-size: 12px;
|
||||
max-width: calc(100% - 160px);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import {Component, inject, Input, OnDestroy, OnInit} from '@angular/core';
|
||||
import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {CbxHeaderService} from './cbx-header.service';
|
||||
import {ReaderIconComponent} from '../../../ebook-reader/shared/icon.component';
|
||||
import {ReaderIconComponent} from '../../../ebook-reader';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Observable} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
import {AuthService} from '../../../../shared/service/auth.service';
|
||||
|
||||
export interface EpubSpineItem {
|
||||
idref: string;
|
||||
href: string;
|
||||
mediaType: string;
|
||||
linear: boolean;
|
||||
}
|
||||
|
||||
export interface EpubManifestItem {
|
||||
id: string;
|
||||
href: string;
|
||||
mediaType: string;
|
||||
properties?: string[];
|
||||
size: number;
|
||||
}
|
||||
|
||||
export interface EpubTocItem {
|
||||
label: string;
|
||||
href: string;
|
||||
children?: EpubTocItem[];
|
||||
}
|
||||
|
||||
export interface EpubBookInfo {
|
||||
containerPath: string;
|
||||
rootPath: string;
|
||||
spine: EpubSpineItem[];
|
||||
manifest: EpubManifestItem[];
|
||||
toc: EpubTocItem;
|
||||
metadata: Record<string, any>;
|
||||
coverPath?: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class EpubStreamingService {
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/epub`;
|
||||
private http = inject(HttpClient);
|
||||
private authService = inject(AuthService);
|
||||
|
||||
getBookInfo(bookId: number): Observable<EpubBookInfo> {
|
||||
return this.http.get<EpubBookInfo>(`${this.baseUrl}/${bookId}/info`);
|
||||
}
|
||||
|
||||
getBaseUrl(): string {
|
||||
return this.baseUrl;
|
||||
}
|
||||
|
||||
getAuthToken(): string | null {
|
||||
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import {catchError, map, switchMap} from 'rxjs/operators';
|
||||
import {ReaderAnnotationService, Annotation} from '../features/annotations/annotation-renderer.service';
|
||||
import {ReaderEventService, ViewEvent, TextSelection} from './event.service';
|
||||
import {PageInfo, ThemeInfo, PageDecorator} from '../shared/header-footer.util';
|
||||
import {EpubStreamingService, EpubBookInfo} from './epub-streaming.service';
|
||||
|
||||
export type {ViewEvent, TextSelection} from './event.service';
|
||||
export type {PageInfo, ThemeInfo} from '../shared/header-footer.util';
|
||||
@@ -32,6 +33,7 @@ export interface BookMetadata {
|
||||
export class ReaderViewManagerService {
|
||||
private annotationService = inject(ReaderAnnotationService);
|
||||
private eventService = inject(ReaderEventService);
|
||||
private epubStreamingService = inject(EpubStreamingService);
|
||||
private view: any;
|
||||
|
||||
public get events$(): Observable<ViewEvent> {
|
||||
@@ -77,6 +79,29 @@ export class ReaderViewManagerService {
|
||||
);
|
||||
}
|
||||
|
||||
loadEpubStreaming(bookId: number): Observable<void> {
|
||||
if (!this.view) {
|
||||
return throwError(() => new Error('View not created'));
|
||||
}
|
||||
|
||||
return this.epubStreamingService.getBookInfo(bookId).pipe(
|
||||
switchMap(bookInfo => from(this.openStreamingBook(bookId, bookInfo))),
|
||||
map(() => undefined),
|
||||
catchError(err => throwError(() => err))
|
||||
);
|
||||
}
|
||||
|
||||
private async openStreamingBook(bookId: number, bookInfo: EpubBookInfo): Promise<void> {
|
||||
const makeStreamingBook = (window as any).makeStreamingBook;
|
||||
if (!makeStreamingBook) {
|
||||
throw new Error('makeStreamingBook not available - Foliate script may not be loaded');
|
||||
}
|
||||
const baseUrl = this.epubStreamingService.getBaseUrl();
|
||||
const authToken = this.epubStreamingService.getAuthToken();
|
||||
const book = await makeStreamingBook(bookId, baseUrl, bookInfo, authToken);
|
||||
await this.view.open(book);
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.eventService.destroy();
|
||||
this.view?.remove();
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
class="reader"
|
||||
[style.background-color]="stateService.currentState.theme.bg ?? ''">
|
||||
|
||||
<div class="header-trigger-zone"
|
||||
[class.inactive]="headerVisible"
|
||||
(mouseenter)="onHeaderTriggerZoneEnter()"></div>
|
||||
<div class="footer-trigger-zone"
|
||||
[class.inactive]="forceNavbarVisible"
|
||||
(mouseenter)="onFooterTriggerZoneEnter()"></div>
|
||||
|
||||
@if (isLoading) {
|
||||
<div class="loader-overlay">
|
||||
<div class="loader-content">
|
||||
|
||||
@@ -11,6 +11,34 @@
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.header-trigger-zone {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 20px;
|
||||
z-index: 9998;
|
||||
pointer-events: auto;
|
||||
|
||||
&.inactive {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.footer-trigger-zone {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 30px;
|
||||
z-index: 9998;
|
||||
pointer-events: auto;
|
||||
|
||||
&.inactive {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
.reader-content {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
|
||||
@@ -96,6 +96,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
showMetadata = false;
|
||||
isCurrentCfiBookmarked = false;
|
||||
forceNavbarVisible = false;
|
||||
headerVisible = false;
|
||||
book: Book | null = null;
|
||||
sectionFractions: number[] = [];
|
||||
|
||||
@@ -115,6 +116,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
ngOnInit() {
|
||||
this.visibilityManager = new ReaderHeaderFooterVisibilityManager(window.innerHeight);
|
||||
this.visibilityManager.onStateChange((state) => {
|
||||
this.headerVisible = state.headerVisible;
|
||||
this.headerService.setForceVisible(state.headerVisible);
|
||||
this.forceNavbarVisible = state.footerVisible;
|
||||
});
|
||||
@@ -209,19 +211,22 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
return this.stateService.initializeState(this.bookId).pipe(
|
||||
switchMap(() => forkJoin({
|
||||
state: this.stateService.initializeState(this.bookId),
|
||||
book: this.bookService.getBookByIdFromAPI(this.bookId, false),
|
||||
fileBlob: this.bookService.getFileContent(this.bookId)
|
||||
book: this.bookService.getBookByIdFromAPI(this.bookId, false)
|
||||
})),
|
||||
switchMap(({book, fileBlob}) => {
|
||||
switchMap(({book}) => {
|
||||
this.book = book;
|
||||
const fileUrl = URL.createObjectURL(fileBlob);
|
||||
this._fileUrl = fileUrl;
|
||||
|
||||
this.progressService.initialize(this.bookId, book.bookType!);
|
||||
this.selectionService.initialize(this.bookId, this.destroy$);
|
||||
this.headerService.initialize(this.bookId, book.metadata?.title || '', this.destroy$);
|
||||
|
||||
return this.viewManager.loadEpub(fileUrl).pipe(
|
||||
// Use streaming for EPUB if query param is set, blob loading otherwise (default)
|
||||
const useStreaming = this.route.snapshot.queryParamMap.get('streaming') === 'true';
|
||||
const loadBook$ = book.bookType === 'EPUB' && useStreaming
|
||||
? this.viewManager.loadEpubStreaming(this.bookId)
|
||||
: this.loadBookBlob();
|
||||
|
||||
return loadBook$.pipe(
|
||||
tap(() => {
|
||||
this.applyStyles();
|
||||
this.sidebarService.initialize(this.bookId, book, this.destroy$);
|
||||
@@ -241,6 +246,16 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
private loadBookBlob(): Observable<void> {
|
||||
return this.bookService.getFileContent(this.bookId).pipe(
|
||||
switchMap(fileBlob => {
|
||||
const fileUrl = URL.createObjectURL(fileBlob);
|
||||
this._fileUrl = fileUrl;
|
||||
return this.viewManager.loadEpub(fileUrl);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private subscribeToStateChanges(): void {
|
||||
this.stateService.state$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
@@ -291,6 +306,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
this.isCurrentCfiBookmarked = currentCfi
|
||||
? bookmarks.some(b => b.cfi === currentCfi)
|
||||
: false;
|
||||
this.headerService.setCurrentCfiBookmarked(this.isCurrentCfiBookmarked);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -329,6 +345,14 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
this.visibilityManager.updateWindowHeight(window.innerHeight);
|
||||
}
|
||||
|
||||
onHeaderTriggerZoneEnter(): void {
|
||||
this.visibilityManager.handleHeaderZoneEnter();
|
||||
}
|
||||
|
||||
onFooterTriggerZoneEnter(): void {
|
||||
this.visibilityManager.handleFooterZoneEnter();
|
||||
}
|
||||
|
||||
handleSelectionAction(action: TextSelectionAction): void {
|
||||
if (action.type === 'note') {
|
||||
this.noteService.openNewNoteDialog();
|
||||
|
||||
+5
-2
@@ -2,13 +2,16 @@
|
||||
<button class="icon-btn" (click)="onShowChapters()" title="Chapters">
|
||||
<app-reader-icon name="menu" [size]="20"></app-reader-icon>
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onCreateBookmark()" title="Create Bookmark">
|
||||
<button class="icon-btn" (click)="onCreateBookmark()" [title]="isCurrentCfiBookmarked ? 'Remove Bookmark' : 'Add Bookmark'" [class.active]="isCurrentCfiBookmarked">
|
||||
<app-reader-icon name="bookmark"></app-reader-icon>
|
||||
</button>
|
||||
<span class="chapter-title">{{ bookTitle }}</span>
|
||||
<button class="icon-btn" (click)="onOpenSearch()" title="Search">
|
||||
<app-reader-icon name="search"></app-reader-icon>
|
||||
</button>
|
||||
<span class="chapter-title">{{ bookTitle }}</span>
|
||||
<button class="icon-btn" (click)="onOpenNotes()" title="Notes">
|
||||
<app-reader-icon name="note"></app-reader-icon>
|
||||
</button>
|
||||
<button class="icon-btn" (click)="onShowControls()" title="Settings">
|
||||
<app-reader-icon name="settings"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
+13
-7
@@ -29,23 +29,28 @@
|
||||
border: none;
|
||||
color: inherit;
|
||||
cursor: pointer;
|
||||
padding: 6px;
|
||||
border-radius: 50%;
|
||||
transition: background 0.15s, box-shadow 0.15s;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
transition: color 0.15s, opacity 0.15s;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 8px;
|
||||
margin-right: 4px;
|
||||
opacity: 0.85;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.14);
|
||||
box-shadow: 0 2px 8px 0 rgba(0,0,0,0.10);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
&:last-of-type {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: #ef4444;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.pi {
|
||||
font-size: 16px;
|
||||
}
|
||||
@@ -68,10 +73,11 @@
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.reader-header {
|
||||
padding: 0 6px;
|
||||
padding: 0 2px;
|
||||
|
||||
.icon-btn {
|
||||
padding: 10px;
|
||||
margin-right: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-1
@@ -3,6 +3,7 @@ import {Subject} from 'rxjs';
|
||||
import {takeUntil} from 'rxjs/operators';
|
||||
import {ReaderHeaderService} from './header.service';
|
||||
import {ReaderIconComponent} from '../../shared/icon.component';
|
||||
import {Router} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-header',
|
||||
@@ -13,9 +14,11 @@ import {ReaderIconComponent} from '../../shared/icon.component';
|
||||
})
|
||||
export class ReaderHeaderComponent implements OnInit, OnDestroy {
|
||||
private headerService = inject(ReaderHeaderService);
|
||||
private router = inject(Router);
|
||||
private destroy$ = new Subject<void>();
|
||||
|
||||
isVisible = false;
|
||||
isCurrentCfiBookmarked = false;
|
||||
|
||||
get bookTitle(): string {
|
||||
return this.headerService.title;
|
||||
@@ -29,6 +32,10 @@ export class ReaderHeaderComponent implements OnInit, OnDestroy {
|
||||
this.headerService.forceVisible$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(visible => this.isVisible = visible);
|
||||
|
||||
this.headerService.isCurrentCfiBookmarked$
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.subscribe(bookmarked => this.isCurrentCfiBookmarked = bookmarked);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
@@ -40,6 +47,10 @@ export class ReaderHeaderComponent implements OnInit, OnDestroy {
|
||||
this.headerService.openSidebar();
|
||||
}
|
||||
|
||||
onOpenNotes(): void {
|
||||
this.headerService.openLeftSidebar('notes');
|
||||
}
|
||||
|
||||
onOpenSearch(): void {
|
||||
this.headerService.openLeftSidebar('search');
|
||||
}
|
||||
@@ -53,6 +64,10 @@ export class ReaderHeaderComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
this.headerService.close();
|
||||
if (window.history.length <= 2) {
|
||||
this.router.navigate(['/dashboard']);
|
||||
} else {
|
||||
this.headerService.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ export class ReaderHeaderService {
|
||||
private _forceVisible = new BehaviorSubject<boolean>(false);
|
||||
forceVisible$ = this._forceVisible.asObservable();
|
||||
|
||||
private _isCurrentCfiBookmarked = new BehaviorSubject<boolean>(false);
|
||||
isCurrentCfiBookmarked$ = this._isCurrentCfiBookmarked.asObservable();
|
||||
|
||||
private _showControls = new Subject<void>();
|
||||
private _showMetadata = new Subject<void>();
|
||||
showControls$ = this._showControls.asObservable();
|
||||
@@ -50,6 +53,10 @@ export class ReaderHeaderService {
|
||||
this._forceVisible.next(visible);
|
||||
}
|
||||
|
||||
setCurrentCfiBookmarked(bookmarked: boolean): void {
|
||||
this._isCurrentCfiBookmarked.next(bookmarked);
|
||||
}
|
||||
|
||||
openSidebar(): void {
|
||||
this.sidebarService.open();
|
||||
}
|
||||
@@ -59,7 +66,7 @@ export class ReaderHeaderService {
|
||||
}
|
||||
|
||||
createBookmark(): void {
|
||||
this.sidebarService.createBookmark();
|
||||
this.sidebarService.toggleBookmark();
|
||||
}
|
||||
|
||||
openControls(): void {
|
||||
@@ -84,26 +91,6 @@ export class ReaderHeaderService {
|
||||
this.syncSettingsToBackend();
|
||||
}
|
||||
|
||||
decreaseFontSize(): void {
|
||||
this.stateService.updateFontSize(-1);
|
||||
this.syncSettingsToBackend();
|
||||
}
|
||||
|
||||
increaseLineHeight(): void {
|
||||
this.stateService.updateLineHeight(0.1);
|
||||
this.syncSettingsToBackend();
|
||||
}
|
||||
|
||||
decreaseLineHeight(): void {
|
||||
this.stateService.updateLineHeight(-0.1);
|
||||
this.syncSettingsToBackend();
|
||||
}
|
||||
|
||||
setFlow(flow: 'paginated' | 'scrolled'): void {
|
||||
this.stateService.setFlow(flow);
|
||||
this.syncSettingsToBackend();
|
||||
}
|
||||
|
||||
private syncSettingsToBackend(): void {
|
||||
const state = this.stateService.currentState;
|
||||
const setting: EbookViewerSetting = {
|
||||
@@ -129,6 +116,7 @@ export class ReaderHeaderService {
|
||||
|
||||
reset(): void {
|
||||
this._forceVisible.next(false);
|
||||
this._isCurrentCfiBookmarked.next(false);
|
||||
this.bookTitle = '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,6 +234,18 @@ export class ReaderSidebarService {
|
||||
});
|
||||
}
|
||||
|
||||
toggleBookmark(): void {
|
||||
const currentCfi = this.progressService.currentCfi;
|
||||
if (!currentCfi) return;
|
||||
|
||||
const existingBookmark = this._bookmarks.value.find(b => b.cfi === currentCfi);
|
||||
if (existingBookmark) {
|
||||
this.deleteBookmark(existingBookmark.id!);
|
||||
} else {
|
||||
this.createBookmark();
|
||||
}
|
||||
}
|
||||
|
||||
deleteBookmark(bookmarkId: number): void {
|
||||
this.bookMarkHttpService.deleteBookmark(bookmarkId)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
|
||||
@@ -41,6 +41,20 @@ export class ReaderHeaderFooterVisibilityManager {
|
||||
}
|
||||
}
|
||||
|
||||
handleHeaderZoneEnter(): void {
|
||||
if (!this.isPinned) {
|
||||
this.setHeaderVisible(true);
|
||||
this.notifyStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
handleFooterZoneEnter(): void {
|
||||
if (!this.isPinned) {
|
||||
this.setFooterVisible(true);
|
||||
this.notifyStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
togglePinned(): void {
|
||||
this.isPinned = !this.isPinned;
|
||||
this.updateVisibility();
|
||||
|
||||
Reference in New Issue
Block a user