feat(reader): add PDF annotations, Range streaming, and optimized chunk loading (#2701)

This commit is contained in:
ACX
2026-02-11 16:51:59 -07:00
committed by GitHub
parent 16de2d006f
commit 9ed6a3fe72
31 changed files with 450 additions and 749 deletions
@@ -270,7 +270,7 @@ export class BookService {
/*------------------ Reading & Viewer Settings ------------------*/
readBook(bookId: number, reader?: 'pdf-streaming' | 'epub-streaming', explicitBookType?: BookType): void {
readBook(bookId: number, reader?: 'epub-streaming', explicitBookType?: BookType): void {
const book = this.bookStateService
.getCurrentBookState()
.books?.find(b => b.id === bookId);
@@ -289,7 +289,7 @@ export class BookService {
switch (bookType) {
case 'PDF':
baseUrl = reader === 'pdf-streaming' ? 'cbx-reader' : 'pdf-reader';
baseUrl = 'pdf-reader';
break;
case 'EPUB':
@@ -1,64 +0,0 @@
import {Injectable, inject} from '@angular/core';
import {API_CONFIG} from '../../../core/config/api-config';
import {HttpClient} from '@angular/common/http';
import {AuthService} from '../../../shared/service/auth.service';
export interface PdfInfoPage {
pageNumber: number;
displayName: string;
}
export interface PdfOutlineItem {
title: string;
pageNumber: number;
children: PdfOutlineItem[] | null;
}
export interface PdfInfo {
pageCount: number;
outline: PdfOutlineItem[] | null;
}
@Injectable({
providedIn: 'root'
})
export class NewPdfReaderService {
private readonly pagesUrl = `${API_CONFIG.BASE_URL}/api/v1/pdf`;
private readonly imageUrl = `${API_CONFIG.BASE_URL}/api/v1/media/book`;
private authService = inject(AuthService);
private http = inject(HttpClient);
private getToken(): string | null {
return this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
}
private appendToken(url: string): string {
const token = this.getToken();
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
}
getAvailablePages(bookId: number, bookType?: string) {
let url = `${this.pagesUrl}/${bookId}/pages`;
if (bookType) {
url += `?bookType=${bookType}`;
}
return this.http.get<number[]>(this.appendToken(url));
}
getPageInfo(bookId: number, bookType?: string) {
let url = `${this.pagesUrl}/${bookId}/info`;
if (bookType) {
url += `?bookType=${bookType}`;
}
return this.http.get<PdfInfo>(this.appendToken(url));
}
getPageImageUrl(bookId: number, page: number, bookType?: string): string {
let url = `${this.imageUrl}/${bookId}/pdf/pages/${page}`;
if (bookType) {
url += `?bookType=${bookType}`;
}
return this.appendToken(url);
}
}
@@ -145,26 +145,7 @@
<span class="file-size">{{ getFileSizeInMB(book.primaryFile) }}</span>
</div>
<div class="file-actions">
@if (book.primaryFile.bookType === 'PDF') {
<p-button
icon="pi pi-book"
size="small"
text
severity="primary"
[pTooltip]="t('readTooltip')"
tooltipPosition="top"
(onClick)="read(book.id)">
</p-button>
<p-button
icon="pi pi-play"
size="small"
text
severity="info"
[pTooltip]="t('streamingReaderTooltip')"
tooltipPosition="top"
(onClick)="read(book.id, 'pdf-streaming')">
</p-button>
} @else if (book.primaryFile.bookType === 'EPUB') {
@if (book.primaryFile.bookType === 'EPUB') {
<p-button
icon="pi pi-book"
size="small"
@@ -183,7 +164,7 @@
tooltipPosition="top"
(onClick)="read(book.id, 'epub-streaming')">
</p-button>
} @else if (book.primaryFile.bookType && ['FB2', 'MOBI', 'AZW3', 'CBX'].includes(book.primaryFile.bookType)) {
} @else if (book.primaryFile.bookType && ['PDF', 'FB2', 'MOBI', 'AZW3', 'CBX'].includes(book.primaryFile.bookType)) {
<p-button
icon="pi pi-book"
size="small"
@@ -241,7 +222,7 @@
<span class="file-size">{{ getFileSizeInMB(format) }}</span>
</div>
<div class="file-actions">
@if (format.bookType === 'PDF' || format.bookType === 'EPUB') {
@if (format.bookType === 'EPUB') {
<p-button
icon="pi pi-book"
size="small"
@@ -258,9 +239,9 @@
severity="info"
[pTooltip]="t('streamingReaderTooltip')"
tooltipPosition="top"
(onClick)="read(book.id, format.bookType === 'PDF' ? 'pdf-streaming' : 'epub-streaming', format.bookType)">
(onClick)="read(book.id, 'epub-streaming', format.bookType)">
</p-button>
} @else if (format.bookType && ['FB2', 'MOBI', 'AZW3', 'CBX'].includes(format.bookType)) {
} @else if (format.bookType && ['PDF', 'FB2', 'MOBI', 'AZW3', 'CBX'].includes(format.bookType)) {
<p-button
icon="pi pi-book"
size="small"
@@ -16,7 +16,7 @@ import {TranslocoDirective} from '@jsverse/transloco';
export interface ReadEvent {
bookId: number;
reader?: 'pdf-streaming' | 'epub-streaming';
reader?: 'epub-streaming';
bookType?: BookType;
}
@@ -89,7 +89,7 @@ export class MetadataTabsComponent {
return this.bookInSeries && this.bookInSeries.length > 1 ? 'series' : 'similar';
}
read(bookId: number, reader?: 'pdf-streaming' | 'epub-streaming', bookType?: BookType): void {
read(bookId: number, reader?: 'epub-streaming', bookType?: BookType): void {
this.readBook.emit({ bookId, reader, bookType });
}
@@ -105,13 +105,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
map((book): MenuItem[] => {
const items: MenuItem[] = [];
const primaryType = book.primaryFile?.bookType;
if (primaryType === 'PDF') {
items.push({
label: this.t.translate('metadata.viewer.menuStreamingReader'),
icon: 'pi pi-play',
command: () => this.read(book.id, 'pdf-streaming')
});
} else if (primaryType === 'EPUB') {
if (primaryType === 'EPUB') {
items.push({
label: this.t.translate('metadata.viewer.menuStreamingReader'),
icon: 'pi pi-play',
@@ -133,8 +127,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
}
uniqueAltTypes.forEach(formatType => {
if (formatType === 'PDF' || formatType === 'EPUB') {
// For PDF/EPUB, offer both standard and streaming readers
if (formatType === 'EPUB') {
// For EPUB, offer both standard and streaming readers
items.push({
label: formatType,
icon: this.getFileIcon(formatType),
@@ -147,7 +141,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
{
label: this.t.translate('metadata.viewer.menuStreamingReader'),
icon: 'pi pi-play',
command: () => this.read(book.id, formatType === 'PDF' ? 'pdf-streaming' : 'epub-streaming', formatType)
command: () => this.read(book.id, 'epub-streaming', formatType)
}
]
});
@@ -474,7 +468,7 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
this.isExpanded = !this.isExpanded;
}
read(bookId: number | undefined, reader?: "pdf-streaming" | "epub-streaming", bookType?: BookType): void {
read(bookId: number | undefined, reader?: "epub-streaming", bookType?: BookType): void {
if (bookId) this.bookService.readBook(bookId, reader, bookType);
}
@@ -6,13 +6,12 @@ import {filter, first, map, switchMap, takeUntil, timeout} from 'rxjs/operators'
import {PageTitleService} from "../../../shared/service/page-title.service";
import {CbxReaderService} from '../../book/service/cbx-reader.service';
import {BookService} from '../../book/service/book.service';
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserService} from '../../settings/user-management/user.service';
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, UserService} from '../../settings/user-management/user.service';
import {MessageService} from 'primeng/api';
import {Book, BookSetting, BookType} from '../../book/model/book.model';
import {BookState} from '../../book/model/state/book-state.model';
import {ProgressSpinner} from 'primeng/progressspinner';
import {FormsModule} from "@angular/forms";
import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
import {ReaderHeaderFooterVisibilityManager} from '../ebook-reader';
@@ -63,11 +62,11 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
currentPage = 0;
isLoading = true;
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
backgroundColor: CbxBackgroundColor | PdfBackgroundColor = CbxBackgroundColor.GRAY;
fitMode: CbxFitMode | PdfFitMode = CbxFitMode.FIT_PAGE;
scrollMode: CbxScrollMode | PdfScrollMode = CbxScrollMode.PAGINATED;
pageSpread: CbxPageSpread = CbxPageSpread.ODD;
pageViewMode: CbxPageViewMode = CbxPageViewMode.SINGLE_PAGE;
backgroundColor: CbxBackgroundColor = CbxBackgroundColor.GRAY;
fitMode: CbxFitMode = CbxFitMode.FIT_PAGE;
scrollMode: CbxScrollMode = CbxScrollMode.PAGINATED;
private touchStartX = 0;
private touchEndX = 0;
@@ -110,7 +109,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
// Double-tap zoom
private lastTapTime = 0;
private originalFitMode: CbxFitMode | PdfFitMode | null = null;
private originalFitMode: CbxFitMode | null = null;
// Shortcuts help dialog
showShortcutsHelp = false;
@@ -124,7 +123,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private route = inject(ActivatedRoute);
private router = inject(Router);
private cbxReaderService = inject(CbxReaderService);
private pdfReaderService = inject(NewPdfReaderService);
private bookService = inject(BookService);
private userService = inject(UserService);
private messageService = inject(MessageService);
@@ -141,7 +139,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
protected readonly CbxPageViewMode = CbxPageViewMode;
protected readonly CbxPageSpread = CbxPageSpread;
private static readonly TYPE_PDF = 'PDF';
private static readonly TYPE_CBX = 'CBX';
private static readonly SETTING_GLOBAL = 'Global';
@@ -203,9 +200,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.loadSeriesNavigationAsync(book);
}
const pagesObservable = this.bookType === CbxReaderComponent.TYPE_PDF
? this.pdfReaderService.getAvailablePages(this.bookId, this.altBookType)
: this.cbxReaderService.getAvailablePages(this.bookId, this.altBookType);
const pagesObservable = this.cbxReaderService.getAvailablePages(this.bookId, this.altBookType);
pagesObservable.subscribe({
next: (pages) => {
@@ -239,30 +234,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
}
if (this.bookType === CbxReaderComponent.TYPE_PDF) {
const global = userSettings.perBookSetting.pdf === CbxReaderComponent.SETTING_GLOBAL;
this.pageViewMode = global
? PdfPageViewMode[userSettings.newPdfReaderSetting.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode.SINGLE_PAGE
: PdfPageViewMode[bookSettings.newPdfSettings?.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode[userSettings.newPdfReaderSetting.pageViewMode as keyof typeof PdfPageViewMode] || PdfPageViewMode.SINGLE_PAGE;
this.pageSpread = global
? PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD
: PdfPageSpread[bookSettings.newPdfSettings?.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD;
this.fitMode = global
? PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE
: PdfFitMode[bookSettings.newPdfSettings?.fitMode as keyof typeof PdfFitMode] || PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE;
this.scrollMode = global
? PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED
: PdfScrollMode[bookSettings.newPdfSettings?.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED;
this.backgroundColor = global
? PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY
: PdfBackgroundColor[bookSettings.newPdfSettings?.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY;
this.currentPage = (book.pdfProgress?.page || 1) - 1;
}
this.alignCurrentPageToParity();
this.updateServiceStates();
this.updateBookmarkState();
@@ -610,7 +581,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
get isTwoPageView(): boolean {
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE;
}
get hasSeries(): boolean {
@@ -688,7 +659,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private alignCurrentPageToParity() {
if (!this.pages.length || !this.isTwoPageView) return;
const desiredOdd = this.pageSpread === CbxPageSpread.ODD || this.pageSpread === PdfPageSpread.ODD;
const desiredOdd = this.pageSpread === CbxPageSpread.ODD;
for (let i = this.currentPage; i >= 0; i--) {
if ((this.pages[i] % 2 === 1) === desiredOdd) {
this.currentPage = i;
@@ -813,9 +784,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
private getPageImageUrl(pageIndex: number): string {
return this.bookType === CbxReaderComponent.TYPE_PDF
? this.pdfReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType)
: this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType);
return this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex], this.altBookType);
}
get infiniteScrollImageUrls(): string[] {
@@ -823,25 +792,15 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
private updateViewerSetting(): void {
const bookSetting: BookSetting = this.bookType === CbxReaderComponent.TYPE_CBX
? {
cbxSettings: {
pageSpread: this.pageSpread as CbxPageSpread,
pageViewMode: this.pageViewMode as CbxPageViewMode,
fitMode: this.fitMode as CbxFitMode,
scrollMode: this.scrollMode as CbxScrollMode,
backgroundColor: this.backgroundColor as CbxBackgroundColor,
}
const bookSetting: BookSetting = {
cbxSettings: {
pageSpread: this.pageSpread,
pageViewMode: this.pageViewMode,
fitMode: this.fitMode,
scrollMode: this.scrollMode,
backgroundColor: this.backgroundColor,
}
: {
newPdfSettings: {
pageSpread: this.pageSpread as PdfPageSpread,
pageViewMode: this.pageViewMode as PdfPageViewMode,
fitMode: this.fitMode as PdfFitMode,
scrollMode: this.scrollMode as PdfScrollMode,
backgroundColor: this.backgroundColor as PdfBackgroundColor,
}
};
};
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
}
@@ -850,12 +809,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10
: 0;
if (this.bookType === CbxReaderComponent.TYPE_CBX) {
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
}
if (this.bookType === CbxReaderComponent.TYPE_PDF) {
this.bookService.savePdfProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
}
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage, this.bookFileId).subscribe();
}
private updateSessionProgress(): void {
@@ -1049,7 +1003,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private enforcePortraitSinglePageView() {
if (this.isPhonePortrait() && this.isTwoPageView) {
this.pageViewMode = this.bookType === CbxReaderComponent.TYPE_CBX ? CbxPageViewMode.SINGLE_PAGE : PdfPageViewMode.SINGLE_PAGE;
this.pageViewMode = CbxPageViewMode.SINGLE_PAGE;
this.quickSettingsService.setPageViewMode(this.pageViewMode);
this.footerService.setTwoPageView(false);
this.updateViewerSetting();
@@ -9,9 +9,7 @@ import {
CbxPageSpread,
CbxBackgroundColor,
CbxReadingDirection,
CbxSlideshowInterval,
PdfPageViewMode,
PdfPageSpread
CbxSlideshowInterval
} from '../../../../settings/user-management/user.service';
import {ReaderIconComponent, ReaderIconName} from '../../../ebook-reader/shared/icon.component';
import {CbxQuickSettingsService, CbxQuickSettingsState} from './cbx-quick-settings.service';
@@ -85,7 +83,7 @@ export class CbxQuickSettingsComponent implements OnInit, OnDestroy {
}
get isTwoPageView(): boolean {
return this.state.pageViewMode === CbxPageViewMode.TWO_PAGE || this.state.pageViewMode === PdfPageViewMode.TWO_PAGE;
return this.state.pageViewMode === CbxPageViewMode.TWO_PAGE;
}
get isPaginated(): boolean {
@@ -1,13 +1,13 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode} from '../../../../settings/user-management/user.service';
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval} from '../../../../settings/user-management/user.service';
export interface CbxQuickSettingsState {
fitMode: CbxFitMode | PdfFitMode;
scrollMode: CbxScrollMode | PdfScrollMode;
pageViewMode: CbxPageViewMode | PdfPageViewMode;
pageSpread: CbxPageSpread | PdfPageSpread;
backgroundColor: CbxBackgroundColor | PdfBackgroundColor;
fitMode: CbxFitMode;
scrollMode: CbxScrollMode;
pageViewMode: CbxPageViewMode;
pageSpread: CbxPageSpread;
backgroundColor: CbxBackgroundColor;
readingDirection: CbxReadingDirection;
slideshowInterval: CbxSlideshowInterval;
}
@@ -77,11 +77,11 @@ export class CbxQuickSettingsService {
this.updateState({scrollMode: mode});
}
setPageViewMode(mode: CbxPageViewMode | PdfPageViewMode): void {
setPageViewMode(mode: CbxPageViewMode): void {
this.updateState({pageViewMode: mode});
}
setPageSpread(spread: CbxPageSpread | PdfPageSpread): void {
setPageSpread(spread: CbxPageSpread): void {
this.updateState({pageSpread: spread});
}
@@ -50,59 +50,24 @@
<div class="content">
@switch (activeTab) {
@case ('pages') {
@if (isPdf && hasOutline) {
<ul class="outline-list">
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: pdfOutline, depth: 0 }"></ng-container>
</ul>
<ng-template #outlineTemplate let-items="items" let-depth="depth">
@for (item of items; track item.title + item.pageNumber) {
<li class="outline-item">
<button
class="outline-row"
[class.active]="isOutlineItemActive(item, items)"
[class.has-children]="item.children && item.children.length > 0"
[style.padding-left.px]="16 + depth * 16"
(click)="onOutlineItemClick(item)">
@if (item.children && item.children.length > 0) {
<span
class="expand-icon"
[class.expanded]="isOutlineItemExpanded(item)"
(click)="toggleOutlineItem(item); $event.stopPropagation()">
<app-reader-icon name="chevron-right" [size]="14"></app-reader-icon>
</span>
}
<span class="outline-title">{{ item.title }}</span>
<span class="outline-page">{{ item.pageNumber }}</span>
</button>
@if (item.children && item.children.length > 0 && isOutlineItemExpanded(item)) {
<ul class="outline-children">
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: item.children, depth: depth + 1 }"></ng-container>
</ul>
}
</li>
}
</ng-template>
} @else {
<ul class="page-list">
@for (page of pages; track page.pageNumber) {
<li>
<button
class="page-row"
[class.active]="isPageActive(page.pageNumber)"
(click)="onPageClick(page.pageNumber)">
<span class="page-number">{{ page.pageNumber }}</span>
<span class="page-label">{{ page.displayName }}</span>
</button>
</li>
}
</ul>
@if (pages.length === 0 && !hasOutline) {
<div class="empty-state">
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
<p>No pages found</p>
</div>
<ul class="page-list">
@for (page of pages; track page.pageNumber) {
<li>
<button
class="page-row"
[class.active]="isPageActive(page.pageNumber)"
(click)="onPageClick(page.pageNumber)">
<span class="page-number">{{ page.pageNumber }}</span>
<span class="page-label">{{ page.displayName }}</span>
</button>
</li>
}
</ul>
@if (pages.length === 0) {
<div class="empty-state">
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
<p>No pages found</p>
</div>
}
}
@case ('bookmarks') {
@@ -5,7 +5,6 @@ import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {CbxSidebarService, CbxSidebarTab, SidebarBookInfo} from './cbx-sidebar.service';
import {CbxPageInfo} from '../../../../book/service/cbx-reader.service';
import {PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
import {BookMark} from '../../../../../shared/service/book-mark.service';
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
import {ReaderIconComponent} from '../../../ebook-reader';
@@ -26,9 +25,6 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
activeTab: CbxSidebarTab = 'pages';
bookInfo: SidebarBookInfo = { id: null, title: '', authors: '', coverUrl: null };
pages: CbxPageInfo[] = [];
pdfOutline: PdfOutlineItem[] | null = null;
pdfPageCount = 0;
expandedOutlineItems = new Set<string>();
currentPage = 1;
bookmarks: BookMark[] = [];
notes: BookNoteV2[] = [];
@@ -58,23 +54,9 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(pages => this.pages = pages);
this.sidebarService.pdfOutline$
.pipe(takeUntil(this.destroy$))
.subscribe(outline => {
this.pdfOutline = outline;
this.autoExpandToCurrentPage();
});
this.sidebarService.pdfPageCount$
.pipe(takeUntil(this.destroy$))
.subscribe(count => this.pdfPageCount = count);
this.sidebarService.currentPage$
.pipe(takeUntil(this.destroy$))
.subscribe(page => {
this.currentPage = page;
this.autoExpandToCurrentPage();
});
.subscribe(page => this.currentPage = page);
this.sidebarService.bookmarks$
.pipe(takeUntil(this.destroy$))
@@ -114,75 +96,6 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
return this.currentPage === pageNumber;
}
get isPdf(): boolean {
return this.sidebarService.isPdf;
}
get hasOutline(): boolean {
return this.pdfOutline !== null && this.pdfOutline.length > 0;
}
toggleOutlineItem(item: PdfOutlineItem): void {
const key = `${item.title}-${item.pageNumber}`;
if (this.expandedOutlineItems.has(key)) {
this.expandedOutlineItems.delete(key);
} else {
this.expandedOutlineItems.add(key);
}
}
isOutlineItemExpanded(item: PdfOutlineItem): boolean {
const key = `${item.title}-${item.pageNumber}`;
return this.expandedOutlineItems.has(key);
}
onOutlineItemClick(item: PdfOutlineItem): void {
this.sidebarService.navigateToPage(item.pageNumber);
}
isOutlineItemActive(item: PdfOutlineItem, siblings: PdfOutlineItem[] | null): boolean {
if (!siblings) return this.currentPage >= item.pageNumber;
const itemIndex = siblings.findIndex(s => s.title === item.title && s.pageNumber === item.pageNumber);
const nextSibling = siblings[itemIndex + 1];
if (nextSibling) {
return this.currentPage >= item.pageNumber && this.currentPage < nextSibling.pageNumber;
} else {
return this.currentPage >= item.pageNumber;
}
}
hasActiveChild(item: PdfOutlineItem): boolean {
if (!item.children || item.children.length === 0) return false;
return item.children.some((child, index) => {
if (this.isOutlineItemActive(child, item.children)) return true;
if (this.hasActiveChild(child)) return true;
return false;
});
}
private autoExpandToCurrentPage(): void {
if (!this.pdfOutline) return;
const expandParents = (items: PdfOutlineItem[] | null): void => {
if (!items) return;
for (const item of items) {
if (item.children && item.children.length > 0) {
if (this.hasActiveChild(item) || this.isOutlineItemActive(item, items)) {
const key = `${item.title}-${item.pageNumber}`;
this.expandedOutlineItems.add(key);
}
expandParents(item.children);
}
}
};
expandParents(this.pdfOutline);
}
onBookmarkClick(cfi: string): void {
this.sidebarService.navigateToBookmark(cfi);
}
@@ -2,9 +2,8 @@ import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {CbxPageInfo, CbxReaderService} from '../../../../book/service/cbx-reader.service';
import {NewPdfReaderService, PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
import {Book, BookType} from '../../../../book/model/book.model';
import {Book} from '../../../../book/model/book.model';
import {BookMark, BookMarkService, CreateBookMarkRequest} from '../../../../../shared/service/book-mark.service';
import {BookNoteV2, BookNoteV2Service, CreateBookNoteV2Request, UpdateBookNoteV2Request} from '../../../../../shared/service/book-note-v2.service';
@@ -21,14 +20,12 @@ export type CbxSidebarTab = 'pages' | 'bookmarks' | 'notes';
export class CbxSidebarService {
private urlHelper = inject(UrlHelperService);
private cbxReaderService = inject(CbxReaderService);
private pdfReaderService = inject(NewPdfReaderService);
private bookMarkService = inject(BookMarkService);
private bookNoteV2Service = inject(BookNoteV2Service);
private destroy$ = new Subject<void>();
private bookId!: number;
private altBookType?: string;
private bookType!: BookType;
private _isOpen = new BehaviorSubject<boolean>(false);
private _activeTab = new BehaviorSubject<CbxSidebarTab>('pages');
@@ -39,8 +36,6 @@ export class CbxSidebarService {
coverUrl: null
});
private _pages = new BehaviorSubject<CbxPageInfo[]>([]);
private _pdfOutline = new BehaviorSubject<PdfOutlineItem[] | null>(null);
private _pdfPageCount = new BehaviorSubject<number>(0);
private _currentPage = new BehaviorSubject<number>(1);
private _bookmarks = new BehaviorSubject<BookMark[]>([]);
private _notes = new BehaviorSubject<BookNoteV2[]>([]);
@@ -54,8 +49,6 @@ export class CbxSidebarService {
activeTab$ = this._activeTab.asObservable();
bookInfo$ = this._bookInfo.asObservable();
pages$ = this._pages.asObservable();
pdfOutline$ = this._pdfOutline.asObservable();
pdfPageCount$ = this._pdfPageCount.asObservable();
currentPage$ = this._currentPage.asObservable();
bookmarks$ = this._bookmarks.asObservable();
notes$ = this._notes.asObservable();
@@ -63,14 +56,9 @@ export class CbxSidebarService {
editNote$ = this._editNote.asObservable();
bookmarksChanged$ = this._bookmarksChanged.asObservable();
get isPdf(): boolean {
return this.bookType === 'PDF';
}
initialize(bookId: number, book: Book, destroy$: Subject<void>, altBookType?: string): void {
this.bookId = bookId;
this.altBookType = altBookType;
this.bookType = (altBookType as BookType) ?? book.primaryFile?.bookType!;
this.destroy$ = destroy$;
this._bookInfo.next({
@@ -86,25 +74,9 @@ export class CbxSidebarService {
}
private loadPageInfo(): void {
if (this.bookType === 'PDF') {
this.pdfReaderService.getPageInfo(this.bookId, this.altBookType)
.pipe(takeUntil(this.destroy$))
.subscribe(pdfInfo => {
this._pdfPageCount.next(pdfInfo.pageCount);
this._pdfOutline.next(pdfInfo.outline);
if (!pdfInfo.outline || pdfInfo.outline.length === 0) {
const pages: CbxPageInfo[] = [];
for (let i = 1; i <= pdfInfo.pageCount; i++) {
pages.push({pageNumber: i, displayName: `Page ${i}`});
}
this._pages.next(pages);
}
});
} else {
this.cbxReaderService.getPageInfo(this.bookId, this.altBookType)
.pipe(takeUntil(this.destroy$))
.subscribe(pages => this._pages.next(pages));
}
this.cbxReaderService.getPageInfo(this.bookId, this.altBookType)
.pipe(takeUntil(this.destroy$))
.subscribe(pages => this._pages.next(pages));
}
private loadBookmarks(): void {
@@ -7,6 +7,7 @@
@if (!isLoading) {
<ngx-extended-pdf-viewer
[src]="bookData"
[authorization]="authorization"
[textLayer]="true"
[showHandToolButton]="true"
[height]="'auto'"
@@ -19,7 +20,8 @@
(pagesLoaded)="onPdfPagesLoaded($event)"
(pageChange)="onPageChange($event)"
(zoomChange)="onZoomChange($event)"
(spreadChange)="onSpreadChange($event)">
(spreadChange)="onSpreadChange($event)"
(annotationEditorEvent)="onAnnotationEditorEvent()">
</ngx-extended-pdf-viewer>
<ng-template #additionalButtons>
@@ -47,6 +49,10 @@
<div class="verticalToolbarSeparator hiddenSmallView"></div>
<pdf-toggle-secondary-toolbar></pdf-toggle-secondary-toolbar>
<div class="verticalToolbarSeparator"></div>
<pdf-highlight-editor></pdf-highlight-editor>
<pdf-text-editor></pdf-text-editor>
<pdf-draw-editor></pdf-draw-editor>
<div class="verticalToolbarSeparator"></div>
<button class="toolbar-btn" [title]="isDarkTheme ? 'Switch to Light Mode' : 'Switch to Dark Mode'" (click)="isDarkTheme = !isDarkTheme">
@if (isDarkTheme) {
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@@ -1,12 +1,15 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {NgxExtendedPdfViewerModule, ZoomType} from 'ngx-extended-pdf-viewer';
import {NgxExtendedPdfViewerModule, NgxExtendedPdfViewerService, pdfDefaultOptions, ZoomType} from 'ngx-extended-pdf-viewer';
import {PageTitleService} from "../../../shared/service/page-title.service";
import {BookService} from '../../book/service/book.service';
import {forkJoin, Subscription} from 'rxjs';
import {map, switchMap} from 'rxjs/operators';
import {forkJoin, Subject, Subscription} from 'rxjs';
import {debounceTime, map, switchMap} from 'rxjs/operators';
import {BookSetting} from '../../book/model/book.model';
import {UserService} from '../../settings/user-management/user.service';
import {AuthService} from '../../../shared/service/auth.service';
import {API_CONFIG} from '../../../core/config/api-config';
import {PdfAnnotationService} from '../../../shared/service/pdf-annotation.service';
import {ProgressSpinner} from 'primeng/progressspinner';
import {MessageService} from 'primeng/api';
@@ -21,47 +24,61 @@ import {Location} from '@angular/common';
styleUrl: './pdf-reader.component.scss',
})
export class PdfReaderComponent implements OnInit, OnDestroy {
constructor() {
pdfDefaultOptions.rangeChunkSize = 512 * 1024;
pdfDefaultOptions.disableAutoFetch = true;
}
isLoading = true;
totalPages: number = 0;
isDarkTheme = true;
rotation: 0 | 90 | 180 | 270 = 0;
authorization = '';
page!: number;
spread!: 'off' | 'even' | 'odd';
zoom!: ZoomType;
bookData!: string | Blob;
bookData!: string;
bookId!: number;
bookFileId?: number;
private appSettingsSubscription!: Subscription;
private annotationSaveSubject = new Subject<void>();
private annotationSaveSubscription!: Subscription;
private annotationsLoaded = false;
private bookService = inject(BookService);
private userService = inject(UserService);
private authService = inject(AuthService);
private messageService = inject(MessageService);
private route = inject(ActivatedRoute);
private pageTitle = inject(PageTitleService);
private readingSessionService = inject(ReadingSessionService);
private location = inject(Location);
private pdfViewerService = inject(NgxExtendedPdfViewerService);
private pdfAnnotationService = inject(PdfAnnotationService);
ngOnInit(): void {
this.annotationSaveSubscription = this.annotationSaveSubject
.pipe(debounceTime(1500))
.subscribe(() => this.persistAnnotations());
this.route.paramMap.subscribe((params) => {
this.isLoading = true;
this.bookId = +params.get('bookId')!;
this.bookService.getBookByIdFromAPI(this.bookId, false).pipe(
switchMap((book) => {
// Set the book file ID for progress tracking
this.bookFileId = book.primaryFile?.id;
return forkJoin([
this.bookService.getBookSetting(this.bookId, this.bookFileId!),
this.bookService.getFileContent(this.bookId),
this.userService.getMyself()
]).pipe(map(([bookSetting, pdfData, myself]) => ({ book, bookSetting, pdfData, myself })));
]).pipe(map(([bookSetting, myself]) => ({book, bookSetting, myself})));
})
).subscribe({
next: ({ book, bookSetting, pdfData, myself }) => {
next: ({book, bookSetting, myself}) => {
const pdfMeta = book;
const pdfPrefs = bookSetting;
@@ -76,7 +93,9 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
this.spread = pdfPrefs.pdfSettings?.spread || myself.userSettings.pdfReaderSetting.pageSpread || 'odd';
}
this.page = pdfMeta.pdfProgress?.page || 1;
this.bookData = pdfData;
this.bookData = `${API_CONFIG.BASE_URL}/api/v1/books/${this.bookId}/content`;
const token = this.authService.getOidcAccessToken() || this.authService.getInternalAccessToken();
this.authorization = token ? `Bearer ${token}` : '';
this.isLoading = false;
},
error: () => {
@@ -130,6 +149,13 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
const percentage = this.totalPages > 0 ? Math.round((this.page / this.totalPages) * 1000) / 10 : 0;
this.readingSessionService.startSession(this.bookId, "PDF", this.page.toString(), percentage);
this.readingSessionService.updateProgress(this.page.toString(), percentage);
this.loadAnnotations();
}
onAnnotationEditorEvent(): void {
if (this.annotationsLoaded) {
this.annotationSaveSubject.next();
}
}
ngOnDestroy(): void {
@@ -138,6 +164,9 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
this.readingSessionService.endSession(this.page.toString(), percentage);
}
this.annotationSaveSubscription?.unsubscribe();
this.persistAnnotations();
if (this.appSettingsSubscription) {
this.appSettingsSubscription.unsubscribe();
}
@@ -151,4 +180,33 @@ export class PdfReaderComponent implements OnInit, OnDestroy {
}
this.location.back();
}
private loadAnnotations(): void {
this.pdfAnnotationService.getAnnotations(this.bookId).subscribe({
next: (response) => {
if (response?.data) {
const annotations = JSON.parse(response.data);
for (const annotation of annotations) {
this.pdfViewerService.addEditorAnnotation(annotation);
}
}
this.annotationsLoaded = true;
},
error: () => {
this.annotationsLoaded = true;
}
});
}
private persistAnnotations(): void {
if (!this.annotationsLoaded || !this.bookId) {
return;
}
const serialized = this.pdfViewerService.getSerializedAnnotations();
if (serialized && serialized.length > 0) {
const cleaned = serialized.map(({id, ...rest}: any) => rest);
const data = JSON.stringify(cleaned);
this.pdfAnnotationService.saveAnnotations(this.bookId, data).subscribe();
}
}
}
@@ -1,125 +0,0 @@
<ng-container *transloco="let t; prefix: 'settingsReader.streamingPdf'">
<div class="pdf-preferences-container">
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">{{ t('pageSpread') }}</label>
<div class="button-group">
@for (spread of pdfSpreads; track spread) {
<button
type="button"
class="option-button"
[class.selected]="selectedPdfSpread === spread.key"
(click)="selectedPdfSpread = spread.key">
<i [class]="spread.icon"></i>
<span class="option-text">{{ t(spread.translationKey) }}</span>
</button>
}
</div>
</div>
<p class="setting-description">
{{ t('pageSpreadDesc') }}
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">{{ t('pageLayout') }}</label>
<div class="button-group">
@for (mode of pdfViewModes; track mode) {
<button
type="button"
class="option-button"
[class.selected]="selectedPdfViewMode === mode.key"
(click)="selectedPdfViewMode = mode.key">
<i [class]="mode.icon"></i>
<span class="option-text">{{ t(mode.translationKey) }}</span>
</button>
}
</div>
</div>
<p class="setting-description">
{{ t('pageLayoutDesc') }}
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">{{ t('fitMode') }}</label>
<div class="button-group">
@for (mode of pdfFitModes; track mode) {
<button
type="button"
class="option-button"
[class.selected]="selectedPdfFitMode === mode.key"
(click)="selectedPdfFitMode = mode.key"
[pTooltip]="t(mode.translationKey)"
tooltipPosition="bottom">
<i [class]="mode.icon"></i>
<span class="option-text">{{ t(mode.translationKey) }}</span>
</button>
}
</div>
</div>
<p class="setting-description">
{{ t('fitModeDesc') }}
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">{{ t('scrollMode') }}</label>
<div class="button-group">
@for (mode of pdfScrollModes; track mode) {
<button
type="button"
class="option-button"
[class.selected]="selectedPdfScrollMode === mode.key"
(click)="selectedPdfScrollMode = mode.key">
<i [class]="mode.icon"></i>
<span class="option-text">{{ t(mode.translationKey) }}</span>
</button>
}
</div>
</div>
<p class="setting-description">
{{ t('scrollModeDesc') }}
</p>
</div>
</div>
<div class="setting-item">
<div class="setting-info">
<div class="setting-label-row">
<label class="setting-label">{{ t('backgroundColor') }}</label>
<div class="theme-selector">
@for (color of pdfBackgroundColors; track color) {
<button
type="button"
class="theme-option"
[class.selected]="selectedPdfBackgroundColor === color.key"
[style.background-color]="color.color"
(click)="selectedPdfBackgroundColor = color.key"
[attr.aria-label]="t(color.translationKey)"
[pTooltip]="t(color.translationKey)"
tooltipPosition="bottom">
@if (selectedPdfBackgroundColor === color.key) {
<i class="pi pi-check"></i>
}
</button>
}
</div>
</div>
<p class="setting-description">
{{ t('backgroundColorDesc') }}
</p>
</div>
</div>
</div>
</ng-container>
@@ -1,98 +0,0 @@
@use '../../../../shared/styles/settings-shared' as settings;
.pdf-preferences-container {
display: flex;
flex-direction: column;
gap: 1rem;
}
.setting-item {
display: flex;
align-items: flex-start;
gap: 2rem;
padding: 0.25rem 0;
&:last-child {
border-bottom: none;
padding-bottom: 0;
}
@media (max-width: 768px) {
flex-direction: column;
gap: 1rem;
}
}
.setting-info {
flex: 1;
min-width: 0;
.setting-label {
display: block;
font-weight: settings.$settings-section-title-weight;
color: var(--p-text-color);
font-size: 1rem;
margin-bottom: 0.5rem;
}
.setting-label-row {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 0.5rem;
flex-wrap: wrap;
.setting-label {
margin-bottom: 0;
flex-shrink: 0;
min-width: 100px;
}
}
.setting-description {
color: var(--p-text-muted-color);
font-size: settings.$settings-section-description-size;
line-height: 1.5;
margin: 0;
}
}
.button-group {
@include settings.settings-button-group;
}
.theme-selector {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
.theme-option {
width: 2.5rem;
height: 2.5rem;
border-radius: 0.375rem;
border: 1.5px solid transparent;
cursor: pointer;
transition: all 0.2s ease;
position: relative;
display: flex;
align-items: center;
justify-content: center;
i {
color: white;
font-size: settings.$settings-section-description-size;
font-weight: bold;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}
&:hover {
transform: scale(1.1);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
&.selected {
border-color: var(--primary-color);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 25%, transparent);
}
}
}
@@ -1,104 +0,0 @@
import {Component, inject, Input} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {TranslocoDirective} from '@jsverse/transloco';
import {PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserSettings} from '../../user-management/user.service';
import {ReaderPreferencesService} from '../reader-preferences.service';
import {TooltipModule} from 'primeng/tooltip';
@Component({
selector: 'app-new-pdf-reader-preferences-component',
imports: [
FormsModule,
TranslocoDirective,
TooltipModule
],
templateUrl: './new-pdf-reader-preferences-component.html',
styleUrl: './new-pdf-reader-preferences-component.scss'
})
export class NewPdfReaderPreferencesComponent {
@Input() userSettings!: UserSettings;
private readonly readerPreferencesService = inject(ReaderPreferencesService);
private static readonly SETTING_ROOT = 'newPdfReaderSetting';
private static readonly PROP_PAGE_SPREAD = 'pageSpread';
private static readonly PROP_PAGE_VIEW_MODE = 'pageViewMode';
private static readonly PROP_FIT_MODE = 'fitMode';
private static readonly PROP_SCROLL_MODE = 'scrollMode';
private static readonly PROP_BACKGROUND_COLOR = 'backgroundColor';
readonly pdfSpreads = [
{name: 'Even', key: PdfPageSpread.EVEN, icon: 'pi pi-align-left', translationKey: 'even'},
{name: 'Odd', key: PdfPageSpread.ODD, icon: 'pi pi-align-right', translationKey: 'odd'}
];
readonly pdfViewModes = [
{name: 'Single Page', key: PdfPageViewMode.SINGLE_PAGE, icon: 'pi pi-book', translationKey: 'singlePage'},
{name: 'Two Page', key: PdfPageViewMode.TWO_PAGE, icon: 'pi pi-copy', translationKey: 'twoPage'},
];
readonly pdfFitModes = [
{name: 'Fit Page', key: PdfFitMode.FIT_PAGE, icon: 'pi pi-window-maximize', translationKey: 'fitPage'},
{name: 'Fit Width', key: PdfFitMode.FIT_WIDTH, icon: 'pi pi-arrows-h', translationKey: 'fitWidth'},
{name: 'Fit Height', key: PdfFitMode.FIT_HEIGHT, icon: 'pi pi-arrows-v', translationKey: 'fitHeight'},
{name: 'Actual Size', key: PdfFitMode.ACTUAL_SIZE, icon: 'pi pi-expand', translationKey: 'actualSize'},
{name: 'Automatic', key: PdfFitMode.AUTO, icon: 'pi pi-sparkles', translationKey: 'automatic'}
];
readonly pdfScrollModes = [
{name: 'Paginated', key: PdfScrollMode.PAGINATED, icon: 'pi pi-book', translationKey: 'paginated'},
{name: 'Infinite', key: PdfScrollMode.INFINITE, icon: 'pi pi-sort-alt', translationKey: 'infinite'}
];
readonly pdfBackgroundColors = [
{name: 'Gray', key: PdfBackgroundColor.GRAY, color: '#808080', translationKey: 'gray'},
{name: 'Black', key: PdfBackgroundColor.BLACK, color: '#000000', translationKey: 'black'},
{name: 'White', key: PdfBackgroundColor.WHITE, color: '#FFFFFF', translationKey: 'white'}
];
get selectedPdfSpread(): PdfPageSpread {
return this.userSettings.newPdfReaderSetting.pageSpread ?? PdfPageSpread.EVEN;
}
set selectedPdfSpread(value: PdfPageSpread) {
this.userSettings.newPdfReaderSetting.pageSpread = value;
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_SPREAD], value);
}
get selectedPdfViewMode(): PdfPageViewMode {
return this.userSettings.newPdfReaderSetting.pageViewMode ?? PdfPageViewMode.SINGLE_PAGE;
}
set selectedPdfViewMode(value: PdfPageViewMode) {
this.userSettings.newPdfReaderSetting.pageViewMode = value;
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_VIEW_MODE], value);
}
get selectedPdfFitMode(): PdfFitMode {
return this.userSettings.newPdfReaderSetting.fitMode ?? PdfFitMode.FIT_PAGE;
}
set selectedPdfFitMode(value: PdfFitMode) {
this.userSettings.newPdfReaderSetting.fitMode = value;
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_FIT_MODE], value);
}
get selectedPdfScrollMode(): PdfScrollMode {
return this.userSettings.newPdfReaderSetting.scrollMode ?? PdfScrollMode.PAGINATED;
}
set selectedPdfScrollMode(value: PdfScrollMode) {
this.userSettings.newPdfReaderSetting.scrollMode = value;
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_SCROLL_MODE], value);
}
get selectedPdfBackgroundColor(): PdfBackgroundColor {
return this.userSettings.newPdfReaderSetting.backgroundColor ?? PdfBackgroundColor.GRAY;
}
set selectedPdfBackgroundColor(value: PdfBackgroundColor) {
this.userSettings.newPdfReaderSetting.backgroundColor = value;
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_BACKGROUND_COLOR], value);
}
}
@@ -67,24 +67,6 @@
</div>
</div>
<div class="preferences-section">
<div class="section-header">
<h3 class="section-title">
<i class="pi pi-file-pdf"></i>
{{ t('streamingPdf.sectionTitle') }}
</h3>
<p class="section-description">
{{ t('streamingPdf.sectionDesc') }}
</p>
</div>
<div class="settings-card">
<app-new-pdf-reader-preferences-component
[userSettings]="userSettings">
</app-new-pdf-reader-preferences-component>
</div>
</div>
@if (hasFontManagementPermission) {
<div class="preferences-section">
<div class="section-header">
@@ -11,7 +11,6 @@ import {EpubReaderPreferencesComponent} from './epub-reader-preferences/epub-rea
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences/pdf-reader-preferences-component';
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences/cbx-reader-preferences-component';
import {CustomFontsComponent} from '../custom-fonts/custom-fonts.component';
import {NewPdfReaderPreferencesComponent} from './new-pdf-reader-preferences/new-pdf-reader-preferences-component';
import {SettingsApplicationModeComponent} from './settings-application-mode/settings-application-mode.component';
@Component({
@@ -19,7 +18,7 @@ import {SettingsApplicationModeComponent} from './settings-application-mode/sett
templateUrl: './reader-preferences.component.html',
standalone: true,
styleUrls: ['./reader-preferences.component.scss'],
imports: [FormsModule, TooltipModule, TranslocoDirective, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, NewPdfReaderPreferencesComponent, SettingsApplicationModeComponent]
imports: [FormsModule, TooltipModule, TranslocoDirective, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, SettingsApplicationModeComponent]
})
export class ReaderPreferences implements OnInit, OnDestroy {
private readonly userService = inject(UserService);
@@ -0,0 +1,25 @@
import {Injectable, inject} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {API_CONFIG} from '../../core/config/api-config';
@Injectable({
providedIn: 'root'
})
export class PdfAnnotationService {
private readonly url = `${API_CONFIG.BASE_URL}/api/v1/pdf-annotations`;
private readonly http = inject(HttpClient);
getAnnotations(bookId: number): Observable<{ data: string }> {
return this.http.get<{ data: string }>(`${this.url}/book/${bookId}`);
}
saveAnnotations(bookId: number, data: string): Observable<void> {
return this.http.put<void>(`${this.url}/book/${bookId}`, {data});
}
deleteAnnotations(bookId: number): Observable<void> {
return this.http.delete<void>(`${this.url}/book/${bookId}`);
}
}