Revamp the CBX reader layout for improved structure and usability (#2330)

Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
ACX
2026-01-18 18:09:27 -07:00
committed by GitHub
co-authored by acx10
parent 6338ed13fc
commit 1b83ebadce
27 changed files with 3406 additions and 744 deletions
@@ -1,5 +1,6 @@
package com.adityachandel.booklore.controller;
import com.adityachandel.booklore.model.dto.response.CbxPageInfo;
import com.adityachandel.booklore.service.reader.CbxReaderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -27,4 +28,11 @@ public class CbxReaderController {
public List<Integer> listPages(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
return cbxReaderService.getAvailablePages(bookId);
}
@Operation(summary = "Get page info for a CBX book", description = "Retrieve page information including display names for a CBX book.")
@ApiResponse(responseCode = "200", description = "Page info returned successfully")
@GetMapping("/{bookId}/page-info")
public List<CbxPageInfo> getPageInfo(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
return cbxReaderService.getPageInfo(bookId);
}
}
@@ -0,0 +1,15 @@
package com.adityachandel.booklore.model.dto.response;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CbxPageInfo {
private int pageNumber;
private String displayName;
}
@@ -14,6 +14,8 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.pdfbox.io.IOUtils;
import org.springframework.stereotype.Service;
import com.adityachandel.booklore.model.dto.response.CbxPageInfo;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -80,6 +82,35 @@ public class CbxReaderService {
}
}
public List<CbxPageInfo> getPageInfo(Long bookId) {
Path cbxPath = getBookPath(bookId);
try {
List<String> imageEntries = getImageEntriesFromArchiveCached(cbxPath);
List<CbxPageInfo> pageInfoList = new ArrayList<>();
for (int i = 0; i < imageEntries.size(); i++) {
String entryPath = imageEntries.get(i);
String displayName = extractDisplayName(entryPath);
pageInfoList.add(CbxPageInfo.builder()
.pageNumber(i + 1)
.displayName(displayName)
.build());
}
return pageInfoList;
} catch (IOException e) {
log.error("Failed to read archive for book {}", bookId, e);
throw ApiError.FILE_READ_ERROR.createException("Failed to read archive: " + e.getMessage());
}
}
private String extractDisplayName(String entryPath) {
String fileName = baseName(entryPath);
int lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex > 0) {
return fileName.substring(0, lastDotIndex);
}
return fileName;
}
public void streamPageImage(Long bookId, int page, OutputStream outputStream) throws IOException {
Path cbxPath = getBookPath(bookId);
CachedArchiveMetadata metadata = getCachedMetadata(cbxPath);
@@ -3,6 +3,11 @@ import {Injectable, inject} from '@angular/core';
import {API_CONFIG} from '../../../core/config/api-config';
import {AuthService} from '../../../shared/service/auth.service';
export interface CbxPageInfo {
pageNumber: number;
displayName: string;
}
@Injectable({providedIn: 'root'})
export class CbxReaderService {
@@ -24,6 +29,10 @@ export class CbxReaderService {
return this.http.get<number[]>(this.appendToken(`${this.pagesUrl}/${bookId}/pages`));
}
getPageInfo(bookId: number) {
return this.http.get<CbxPageInfo[]>(this.appendToken(`${this.pagesUrl}/${bookId}/page-info`));
}
getPageImageUrl(bookId: number, page: number): string {
return this.appendToken(`${this.imageUrl}/${bookId}/cbx/pages/${page}`);
}
@@ -1,178 +1,34 @@
<div class="comic-reader-container" tabindex="0">
<div class="navigation">
<div class="goto-page-controls">
@if (currentBook?.metadata?.seriesName) {
<button
class="series-nav-button prev-book"
(click)="navigateToPreviousBook()"
[disabled]="!previousBookInSeries"
[title]="getPreviousBookTooltip()">
<span>← Previous Book</span>
</button>
}
<!-- Header -->
<app-cbx-header [isCurrentPageBookmarked]="isCurrentPageBookmarked" [currentPageHasNotes]="currentPageHasNotes"></app-cbx-header>
<div class="input-group">
<input
type="number"
[(ngModel)]="goToPageInput"
[min]="1"
[max]="pages.length"
placeholder="Page"
class="page-input"
/>
<button
class="go-button"
(click)="goToPageInput !== null && goToPage(goToPageInput)"
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > pages.length">
Go
</button>
</div>
<!-- Sidebar -->
<app-cbx-sidebar></app-cbx-sidebar>
@if (currentBook?.metadata?.seriesName) {
<button
class="series-nav-button next-book"
(click)="navigateToNextBook()"
[disabled]="!nextBookInSeries"
[title]="getNextBookTooltip()">
<span>Next Book →</span>
</button>
}
<!-- Quick Settings -->
@if (showQuickSettings) {
<app-cbx-quick-settings></app-cbx-quick-settings>
}
<!-- Bookmark Indicator -->
@if (isCurrentPageBookmarked) {
<div class="bookmark-indicator">
<svg width="48" height="64" viewBox="0 0 48 64">
<polygon points="0,0 48,0 48,64 24,48 0,64" fill="red"/>
</svg>
</div>
}
<div class="page-controls">
<button class="nav-button first-page" (click)="goToPage(1)" [disabled]="currentPage === 0" title="First Page">
<span>⟨⟨</span>
</button>
<button class="nav-button prev-page" (click)="previousPage()" [disabled]="currentPage === 0" title="Previous Page">
<span>⟨</span>
</button>
<div class="page-info">
<span class="current-page">{{ currentPage + 1 }}</span>
<span class="page-separator">{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }}</span>
<span class="total-pages"> of {{ pages.length }}</span>
</div>
<button class="nav-button next-page" (click)="nextPage()" [disabled]="currentPage >= pages.length - 1" title="Next Page">
<span>⟩</span>
</button>
<button class="nav-button last-page" (click)="goToPage(pages.length)" [disabled]="currentPage >= pages.length - 1" title="Last Page">
<span>⟩⟩</span>
</button>
</div>
<div class="spread-controls">
<div class="desktop-controls">
<div class="fit-mode-dropdown">
<button class="view-button fit-mode-toggle"
(click)="toggleFitModeDropdown()"
title="Fit Mode">
<span>{{ displayLabel }}</span>
</button>
@if (showFitModeDropdown) {
<div class="fit-mode-menu">
@for (mode of fitModeOptions; track mode.value) {
<button
class="fit-mode-option"
[class.active]="fitMode === mode.value"
(click)="selectFitMode(mode.value)">
<span class="fit-mode-icon">{{ mode.icon }}</span>
<span class="fit-mode-label">{{ mode.label }}</span>
</button>
}
</div>
}
</div>
<button class="view-button scroll-toggle" (click)="toggleScrollMode()" title="Toggle Scroll Mode">
<span>{{ scrollModeIcon }}</span>
</button>
@if (isTwoPageView && scrollMode === CbxScrollMode.PAGINATED) {
<button class="view-button spread-toggle" (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
<span>{{ pageSpread === CbxPageSpread.ODD ? '⬅️' : '➡️' }}</span>
</button>
}
@if (scrollMode === CbxScrollMode.PAGINATED) {
<button class="view-button layout-toggle" (click)="toggleView()" title="Toggle View">
<span>{{ isTwoPageView ? '📄' : '📖' }}</span>
</button>
}
<button class="view-button background-toggle" (click)="toggleBackground()" title="Toggle Background Color">
<span>{{ backgroundColorIcon }}</span>
</button>
<button class="view-button close-button" (click)="closeReader()" title="Close Reader">
<span>✕</span>
</button>
</div>
<div class="mobile-controls">
<button class="view-button more-options-toggle"
(click)="toggleMobileOptionsDropdown()"
title="More Options">
<span>⋮</span>
</button>
@if (showMobileOptionsDropdown) {
<div class="mobile-options-menu">
@if (currentBook?.metadata?.seriesName) {
<button
class="mobile-option"
(click)="navigateToPreviousBook(); toggleMobileOptionsDropdown()"
[disabled]="!previousBookInSeries">
<span class="option-icon">⬅️</span>
<span class="option-label">Previous Book</span>
</button>
<button
class="mobile-option"
(click)="navigateToNextBook(); toggleMobileOptionsDropdown()"
[disabled]="!nextBookInSeries">
<span class="option-icon">➡️</span>
<span class="option-label">Next Book</span>
</button>
}
<button class="mobile-option" (click)="selectMobileOption('fitMode')">
<span class="option-icon">{{ displayLabel }}</span>
<span class="option-label">Fit Mode</span>
</button>
@if (showFitModeSubmenu) {
<div class="submenu">
@for (mode of fitModeOptions; track mode.value) {
<button
class="submenu-option"
[class.active]="fitMode === mode.value"
(click)="selectFitModeFromMobile(mode.value)">
<span class="fit-mode-icon">{{ mode.icon }}</span>
<span class="fit-mode-label">{{ mode.label }}</span>
</button>
}
</div>
}
<button class="mobile-option" (click)="toggleScrollModeFromMobile()">
<span class="option-icon">{{ scrollModeIcon }}</span>
<span class="option-label">Scroll Mode</span>
</button>
@if (isTwoPageView && scrollMode === CbxScrollMode.PAGINATED) {
<button class="mobile-option" (click)="toggleSpreadDirectionFromMobile()">
<span class="option-icon">{{ pageSpread === CbxPageSpread.ODD ? '⬅️' : '➡️' }}</span>
<span class="option-label">Spread Direction</span>
</button>
}
@if (scrollMode === CbxScrollMode.PAGINATED) {
<button class="mobile-option" (click)="toggleViewFromMobile()">
<span class="option-icon">{{ isTwoPageView ? '📄' : '📖' }}</span>
<span class="option-label">Layout</span>
</button>
}
<button class="mobile-option" (click)="toggleBackgroundFromMobile()">
<span class="option-icon">{{ backgroundColorIcon }}</span>
<span class="option-label">Background</span>
</button>
<button class="mobile-option" (click)="closeReader()">
<span class="option-icon">✕</span>
<span class="option-label">Close Reader</span>
</button>
</div>
}
</div>
</div>
</div>
<!-- Note Dialog -->
@if (showNoteDialog) {
<app-cbx-note-dialog
[data]="noteDialogData"
(save)="onNoteSave($event)"
(cancel)="onNoteCancel()"
></app-cbx-note-dialog>
}
<!-- Main content area -->
<div class="image-container"
[class.two-page-view]="isTwoPageView && scrollMode === CbxScrollMode.PAGINATED"
[class.infinite-scroll]="scrollMode === CbxScrollMode.INFINITE"
@@ -188,7 +44,7 @@
@if (!isLoading) {
@if (pages.length > 0) {
@if (scrollMode === CbxScrollMode.PAGINATED) {
<div class="pages-wrapper">
<div class="pages-wrapper" (click)="onImageClick()">
@for (url of imageUrls; track url) {
<img [src]="url" alt="Page Image" class="page-image"/>
}
@@ -205,7 +61,7 @@
} @else {
<div class="infinite-scroll-wrapper">
@for (url of infiniteScrollImageUrls; track url; let i = $index) {
<img [src]="url" alt="Page {{ infiniteScrollPages[i] + 1 }}" class="page-image"/>
<img [src]="url" alt="Page {{ infiniteScrollPages[i] + 1 }}" class="page-image" (click)="onImageClick()"/>
}
@if (isLoadingMore) {
<div class="loading-more">
@@ -235,4 +91,7 @@
</div>
}
</div>
<!-- Footer -->
<app-cbx-footer></app-cbx-footer>
</div>
@@ -7,390 +7,32 @@
box-sizing: border-box;
background: #1a1a1a;
color: #ffffff;
position: relative;
&:focus {
outline: none;
}
.navigation {
flex-shrink: 0;
width: 100%;
background: linear-gradient(135deg, #2d2d2d 0%, #1f1f1f 100%);
border-bottom: 1px solid #404040;
padding: 0.25rem 0.5rem;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
display: flex;
align-items: center;
justify-content: space-between;
z-index: 1000;
min-width: 0;
// Bookmark indicator
.bookmark-indicator {
position: absolute;
top: 0;
right: 24px;
z-index: 10;
pointer-events: none;
filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
.goto-page-controls {
flex: 1;
order: 1;
min-width: fit-content;
display: flex;
justify-content: flex-start;
gap: 0.5rem;
.input-group {
display: flex;
align-items: center;
gap: 0.125rem;
background: rgba(51, 51, 51, 0.9);
border-radius: 4px;
padding: 1px;
border: 1px solid #555;
.page-input {
width: 55px;
padding: 4px 6px;
border: none;
border-radius: 3px;
background: #404040;
color: #ffffff;
font-size: 12px;
text-align: center;
transition: all 0.2s ease;
&:focus {
outline: none;
background: #4a4a4a;
box-shadow: 0 0 0 1px rgba(74, 144, 226, 0.5);
}
&::placeholder {
color: #999;
}
}
.go-button {
padding: 4px 8px;
background: #4a90e2;
color: white;
border: none;
border-radius: 3px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
&:hover:not(:disabled) {
background: #357abd;
}
&:disabled {
background: #666;
cursor: not-allowed;
opacity: 0.6;
}
}
}
}
.page-controls {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: center;
gap: 0.25rem;
order: 2;
min-width: 0;
.nav-button {
width: 24px;
height: 28px;
border: 1px solid #555;
background: rgba(51, 51, 51, 0.9);
color: #ffffff;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
span {
font-size: 11px;
font-weight: bold;
}
&:hover:not(:disabled) {
background: #4a4a4a;
border-color: #666;
}
&:disabled {
background: #2a2a2a;
color: #666;
cursor: not-allowed;
border-color: #333;
}
}
.page-info {
margin: 0 0.5rem;
padding: 2px 8px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
font-weight: 500;
font-size: 12px;
min-width: 80px;
text-align: center;
.current-page {
color: #4a90e2;
font-weight: 600;
}
.page-separator {
color: #4a90e2;
font-weight: 600;
}
.total-pages {
color: #ccc;
}
}
}
.spread-controls {
flex: 1;
display: flex;
gap: 0.25rem;
order: 3;
min-width: fit-content;
align-items: center;
justify-content: flex-end;
.mobile-controls {
display: none;
}
.desktop-controls {
display: flex;
gap: 0.25rem;
align-items: center;
}
@media (max-width: 768px) {
.desktop-controls {
display: none;
}
.mobile-controls {
display: block;
position: relative;
.more-options-toggle {
width: 32px;
height: 28px;
span {
font-size: 18px;
font-weight: bold;
}
}
.mobile-options-menu {
position: absolute;
top: calc(100% + 4px);
right: 0;
background: #2d2d2d;
border: 1px solid #555;
border-radius: 4px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
z-index: 1001;
min-width: 180px;
overflow: hidden;
.mobile-option {
width: 100%;
padding: 10px 12px;
background: transparent;
border: none;
color: #ffffff;
text-align: left;
cursor: pointer;
transition: background 0.2s ease;
display: flex;
align-items: center;
gap: 10px;
font-size: 13px;
border-bottom: 1px solid #404040;
.option-icon {
width: 24px;
text-align: center;
font-size: 14px;
}
.option-label {
flex: 1;
}
&:last-child {
border-bottom: none;
}
&:hover:not(:disabled) {
background: #3a3a3a;
}
&:disabled {
color: #666;
cursor: not-allowed;
opacity: 0.5;
.option-icon {
opacity: 0.5;
}
}
}
.submenu {
background: #252525;
border-top: 1px solid #404040;
.submenu-option {
width: 100%;
padding: 8px 12px 8px 36px;
background: transparent;
border: none;
color: #ffffff;
text-align: left;
cursor: pointer;
transition: background 0.2s ease;
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
.fit-mode-icon {
width: 20px;
text-align: center;
font-size: 13px;
}
.fit-mode-label {
flex: 1;
}
&:hover {
background: #3a3a3a;
}
&.active {
background: #4a90e2;
color: #ffffff;
}
}
}
}
}
}
.view-button {
width: 28px;
height: 28px;
border: 1px solid #555;
background: rgba(51, 51, 51, 0.9);
color: #ffffff;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s ease;
display: flex;
align-items: center;
justify-content: center;
span {
font-size: 13px;
}
&:hover {
background: #4a4a4a;
border-color: #666;
}
&.close-button {
span {
font-size: 16px;
font-weight: bold;
}
&:hover {
background: rgba(239, 68, 68, 0.2);
border-color: rgba(239, 68, 68, 0.4);
}
}
}
.fit-mode-dropdown {
position: relative;
.fit-mode-toggle {
width: auto;
min-width: 28px;
padding: 0 6px;
span {
font-size: 11px;
white-space: nowrap;
}
}
.fit-mode-menu {
position: absolute;
top: calc(100% + 4px);
right: 0;
background: #2d2d2d;
border: 1px solid #555;
border-radius: 4px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
z-index: 1001;
min-width: 160px;
overflow: hidden;
.fit-mode-option {
width: 100%;
padding: 8px 12px;
background: transparent;
border: none;
color: #ffffff;
text-align: left;
cursor: pointer;
transition: background 0.2s ease;
display: flex;
align-items: center;
gap: 8px;
font-size: 12px;
.fit-mode-icon {
width: 20px;
text-align: center;
font-size: 13px;
}
.fit-mode-label {
flex: 1;
}
&:hover {
background: #3a3a3a;
}
&.active {
background: #4a90e2;
color: #ffffff;
}
}
}
}
svg {
display: block;
}
}
.image-container {
flex: 1;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
justify-content: center;
align-items: center;
@@ -398,7 +40,6 @@
padding: 0.5rem;
background: #0f0f0f;
min-height: 0;
position: relative;
&:not(.two-page-view):not(.infinite-scroll) {
flex-direction: column;
@@ -608,7 +249,7 @@
.page-image {
width: auto;
height: calc(100vh - 60px - 2rem);
height: calc(100vh - 2rem);
max-width: 100%;
}
}
@@ -635,7 +276,7 @@
.page-image {
max-width: 100%;
max-height: calc(100vh - 60px - 2rem);
max-height: calc(100vh - 2rem);
width: auto;
height: auto;
}
@@ -648,7 +289,7 @@
.page-image {
max-width: 100%;
max-height: calc(100vh - 60px - 2rem);
max-height: calc(100vh - 2rem);
width: auto;
height: auto;
}
@@ -690,35 +331,6 @@
height: 40px;
}
.goto-page-controls {
.series-nav-button {
padding: 6px 12px;
background: #4a90e2;
border-radius: 4px;
font-size: 13px;
font-weight: 500;
transition: all 0.2s ease;
&:hover:not(:disabled) {
background: #357abd;
transform: translateY(-1px);
box-shadow: 0 2px 8px rgba(74, 144, 226, 0.4);
}
&:disabled {
background: #555;
cursor: not-allowed;
opacity: 0.5;
color: #999;
}
span {
display: inline-flex;
align-items: center;
}
}
}
.end-of-comic-action {
display: flex;
justify-content: center;
@@ -732,8 +344,11 @@
gap: 0.75rem;
padding: 2rem 3rem;
background: linear-gradient(135deg, #4a90e2 0%, #357abd 100%);
border: none;
border-radius: 12px;
font-weight: 600;
color: #ffffff;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 20px rgba(74, 144, 226, 0.3);
min-width: 280px;
@@ -771,13 +386,9 @@
@media (max-width: 768px) {
.comic-reader-container {
.goto-page-controls {
flex-wrap: wrap;
gap: 4px;
.series-nav-button {
display: none;
}
.image-container {
top: 0;
bottom: 0;
}
.end-of-comic-action {
@@ -1,41 +1,60 @@
import {Component, HostListener, inject, OnInit, OnDestroy} from '@angular/core';
import {Component, HostListener, inject, OnDestroy, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {CommonModule, Location} from '@angular/common';
import {forkJoin, Subject} from 'rxjs';
import {filter, first, 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 {
CbxFitMode,
CbxPageSpread,
CbxPageViewMode,
CbxScrollMode,
PdfPageSpread,
PdfPageViewMode,
UserService,
CbxBackgroundColor
} from '../../settings/user-management/user.service';
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, PdfPageSpread, PdfPageViewMode, UserService} from '../../settings/user-management/user.service';
import {MessageService} from 'primeng/api';
import {forkJoin} from 'rxjs';
import {filter, first, timeout} from 'rxjs/operators';
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/shared/visibility.util';
// Layout components
import {CbxHeaderComponent} from './layout/header/cbx-header.component';
import {CbxHeaderService} from './layout/header/cbx-header.service';
import {CbxSidebarComponent} from './layout/sidebar/cbx-sidebar.component';
import {CbxSidebarService} from './layout/sidebar/cbx-sidebar.service';
import {CbxFooterComponent} from './layout/footer/cbx-footer.component';
import {CbxFooterService} from './layout/footer/cbx-footer.service';
import {CbxQuickSettingsComponent} from './layout/quick-settings/cbx-quick-settings.component';
import {CbxQuickSettingsService} from './layout/quick-settings/cbx-quick-settings.service';
import {CbxNoteDialogComponent, CbxNoteDialogData, CbxNoteDialogResult} from './dialogs/cbx-note-dialog.component';
import {BookNoteV2} from '../../../shared/service/book-note-v2.service';
@Component({
selector: 'app-cbx-reader',
standalone: true,
imports: [ProgressSpinner, FormsModule],
imports: [
CommonModule,
ProgressSpinner,
FormsModule,
CbxHeaderComponent,
CbxSidebarComponent,
CbxFooterComponent,
CbxQuickSettingsComponent,
CbxNoteDialogComponent
],
providers: [
CbxHeaderService,
CbxSidebarService,
CbxFooterService,
CbxQuickSettingsService
],
templateUrl: './cbx-reader.component.html',
styleUrl: './cbx-reader.component.scss'
})
export class CbxReaderComponent implements OnInit, OnDestroy {
bookType!: BookType;
private destroy$ = new Subject<void>();
goToPageInput: number | null = null;
bookType!: BookType;
bookId!: number;
pages: number[] = [];
currentPage = 0;
@@ -45,6 +64,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
backgroundColor: CbxBackgroundColor = CbxBackgroundColor.GRAY;
fitMode: CbxFitMode = CbxFitMode.FIT_PAGE;
scrollMode: CbxScrollMode = CbxScrollMode.PAGINATED;
private touchStartX = 0;
private touchEndX = 0;
@@ -53,6 +73,19 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
nextBookInSeries: Book | null = null;
previousBookInSeries: Book | null = null;
infiniteScrollPages: number[] = [];
preloadCount: number = 3;
isLoadingMore: boolean = false;
private visibilityManager!: ReaderHeaderFooterVisibilityManager;
// Bookmark and notes state
isCurrentPageBookmarked = false;
currentPageHasNotes = false;
showNoteDialog = false;
noteDialogData: CbxNoteDialogData | null = null;
private editingNote: BookNoteV2 | null = null;
private route = inject(ActivatedRoute);
private router = inject(Router);
private location = inject(Location);
@@ -63,25 +96,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private messageService = inject(MessageService);
private pageTitle = inject(PageTitleService);
private readingSessionService = inject(ReadingSessionService);
showFitModeDropdown: boolean = false;
showMobileOptionsDropdown: boolean = false;
showFitModeSubmenu: boolean = false;
fitModeOptions = [
{value: CbxFitMode.FIT_PAGE, label: 'Fit Page', icon: '⬜'},
{value: CbxFitMode.FIT_WIDTH, label: 'Fit Width', icon: '↔️'},
{value: CbxFitMode.FIT_HEIGHT, label: 'Fit Height', icon: '↕️'},
{value: CbxFitMode.ACTUAL_SIZE, label: 'Actual Size', icon: '1:1'},
{value: CbxFitMode.AUTO, label: 'Automatic', icon: '🔄'}
];
scrollMode: CbxScrollMode = CbxScrollMode.PAGINATED;
infiniteScrollPages: number[] = [];
preloadCount: number = 3;
isLoadingMore: boolean = false;
private headerService = inject(CbxHeaderService);
private sidebarService = inject(CbxSidebarService);
private footerService = inject(CbxFooterService);
private quickSettingsService = inject(CbxQuickSettingsService);
protected readonly CbxScrollMode = CbxScrollMode;
protected readonly CbxFitMode = CbxFitMode;
@@ -94,6 +112,17 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private static readonly SETTING_GLOBAL = 'Global';
ngOnInit() {
this.visibilityManager = new ReaderHeaderFooterVisibilityManager(window.innerHeight);
this.visibilityManager.onStateChange((state) => {
this.headerService.setForceVisible(state.headerVisible);
this.footerService.setForceVisible(state.footerVisible);
});
this.subscribeToHeaderEvents();
this.subscribeToSidebarEvents();
this.subscribeToFooterEvents();
this.subscribeToQuickSettingsEvents();
this.route.paramMap.subscribe((params) => {
this.isLoading = true;
this.bookId = +params.get('bookId')!;
@@ -114,6 +143,11 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.pageTitle.setBookPageTitle(book);
// Initialize header and sidebar services
const title = book.metadata?.title || book.fileName;
this.headerService.initialize(this.bookId, title, this.destroy$);
this.sidebarService.initialize(this.bookId, book, this.destroy$);
if (book.metadata?.seriesName) {
this.loadSeriesNavigationAsync(book);
}
@@ -167,6 +201,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.currentPage = (book.pdfProgress?.page || 1) - 1;
}
this.alignCurrentPageToParity();
this.updateServiceStates();
this.updateBookmarkState();
this.updateNotesState();
this.isLoading = false;
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
@@ -188,68 +225,157 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
});
}
private subscribeToHeaderEvents(): void {
this.headerService.showQuickSettings$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.quickSettingsService.show();
});
this.headerService.toggleBookmark$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.toggleBookmark();
});
this.headerService.openNoteDialog$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.openNoteDialog();
});
}
private subscribeToSidebarEvents(): void {
this.sidebarService.navigateToPage$
.pipe(takeUntil(this.destroy$))
.subscribe(page => {
this.goToPage(page);
});
this.sidebarService.bookmarksChanged$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.updateBookmarkState();
});
// Subscribe to bookmarks$ to update state when bookmarks are loaded
this.sidebarService.bookmarks$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.updateBookmarkState();
});
// Subscribe to notes$ to update state when notes are loaded
this.sidebarService.notes$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.updateNotesState();
});
this.sidebarService.editNote$
.pipe(takeUntil(this.destroy$))
.subscribe(note => {
this.openNoteDialogForEdit(note);
});
}
private subscribeToFooterEvents(): void {
this.footerService.previousPage$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.previousPage());
this.footerService.nextPage$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.nextPage());
this.footerService.goToPage$
.pipe(takeUntil(this.destroy$))
.subscribe(page => this.goToPage(page));
this.footerService.firstPage$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.firstPage());
this.footerService.lastPage$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.lastPage());
this.footerService.previousBook$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.navigateToPreviousBook());
this.footerService.nextBook$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.navigateToNextBook());
this.footerService.sliderChange$
.pipe(takeUntil(this.destroy$))
.subscribe(page => this.goToPage(page));
}
private subscribeToQuickSettingsEvents(): void {
this.quickSettingsService.fitModeChange$
.pipe(takeUntil(this.destroy$))
.subscribe(mode => this.onFitModeChange(mode));
this.quickSettingsService.scrollModeChange$
.pipe(takeUntil(this.destroy$))
.subscribe(mode => this.onScrollModeChange(mode));
this.quickSettingsService.pageViewModeChange$
.pipe(takeUntil(this.destroy$))
.subscribe(mode => this.onPageViewModeChange(mode));
this.quickSettingsService.pageSpreadChange$
.pipe(takeUntil(this.destroy$))
.subscribe(spread => this.onPageSpreadChange(spread));
this.quickSettingsService.backgroundColorChange$
.pipe(takeUntil(this.destroy$))
.subscribe(color => this.onBackgroundColorChange(color));
}
private updateServiceStates(): void {
// Update footer state
this.footerService.updateState({
currentPage: this.currentPage,
totalPages: this.pages.length,
isTwoPageView: this.isTwoPageView,
previousBookInSeries: this.previousBookInSeries,
nextBookInSeries: this.nextBookInSeries,
hasSeries: this.hasSeries
});
// Update quick settings state
this.quickSettingsService.updateState({
fitMode: this.fitMode,
scrollMode: this.scrollMode,
pageViewMode: this.pageViewMode,
pageSpread: this.pageSpread,
backgroundColor: this.backgroundColor
});
// Update sidebar current page
this.sidebarService.setCurrentPage(this.currentPage + 1);
}
private updateFooterPage(): void {
this.footerService.setCurrentPage(this.currentPage);
this.sidebarService.setCurrentPage(this.currentPage + 1);
this.updateBookmarkState();
this.updateNotesState();
}
get isTwoPageView(): boolean {
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
}
get backgroundColorIcon(): string {
switch (this.backgroundColor) {
case CbxBackgroundColor.BLACK:
return '⚫';
case CbxBackgroundColor.GRAY:
return '🔘';
case CbxBackgroundColor.WHITE:
return '⚪';
default:
return '🔘';
}
get hasSeries(): boolean {
return !!this.currentBook?.metadata?.seriesName;
}
toggleBackground(): void {
switch (this.backgroundColor) {
case CbxBackgroundColor.BLACK:
this.backgroundColor = CbxBackgroundColor.GRAY;
break;
case CbxBackgroundColor.GRAY:
this.backgroundColor = CbxBackgroundColor.WHITE;
break;
case CbxBackgroundColor.WHITE:
this.backgroundColor = CbxBackgroundColor.BLACK;
break;
}
this.updateViewerSetting();
}
toggleView() {
if (!this.isTwoPageView && this.isPhonePortrait()) return;
this.pageViewMode = this.isTwoPageView
? (this.bookType === CbxReaderComponent.TYPE_CBX ? this.CbxPageViewMode.SINGLE_PAGE : PdfPageViewMode.SINGLE_PAGE)
: (this.bookType === CbxReaderComponent.TYPE_CBX ? this.CbxPageViewMode.TWO_PAGE : PdfPageViewMode.TWO_PAGE);
this.alignCurrentPageToParity();
this.updateViewerSetting();
}
toggleSpreadDirection() {
if (this.pageSpread === this.CbxPageSpread.ODD || this.pageSpread === PdfPageSpread.ODD) {
this.pageSpread = this.bookType === CbxReaderComponent.TYPE_CBX ? this.CbxPageSpread.EVEN : PdfPageSpread.EVEN;
} else {
this.pageSpread = this.bookType === CbxReaderComponent.TYPE_CBX ? this.CbxPageSpread.ODD : PdfPageSpread.ODD;
}
this.alignCurrentPageToParity();
this.updateViewerSetting();
}
toggleScrollMode(): void {
this.scrollMode = this.scrollMode === CbxScrollMode.PAGINATED
? CbxScrollMode.INFINITE
: CbxScrollMode.PAGINATED;
this.updateViewerSetting();
if (this.scrollMode === CbxScrollMode.INFINITE) {
this.initializeInfiniteScroll();
setTimeout(() => this.scrollToPage(this.currentPage), 100);
}
get showQuickSettings(): boolean {
return this.quickSettingsService.isVisible;
}
nextPage() {
@@ -261,6 +387,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.scrollToPage(this.currentPage);
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
return;
}
@@ -278,6 +405,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
if (this.currentPage !== previousPage) {
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
}
@@ -288,6 +416,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.scrollToPage(this.currentPage);
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
return;
}
@@ -299,6 +428,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
private alignCurrentPageToParity() {
@@ -321,61 +451,44 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
}
toggleFitModeDropdown(): void {
this.showFitModeDropdown = !this.showFitModeDropdown;
}
selectFitMode(mode: CbxFitMode): void {
// Quick settings handlers
onFitModeChange(mode: CbxFitMode): void {
this.fitMode = mode;
this.showFitModeDropdown = false;
this.quickSettingsService.setFitMode(mode);
this.updateViewerSetting();
}
toggleMobileOptionsDropdown(): void {
this.showMobileOptionsDropdown = !this.showMobileOptionsDropdown;
this.showFitModeSubmenu = false;
}
onScrollModeChange(mode: CbxScrollMode): void {
this.scrollMode = mode;
this.quickSettingsService.setScrollMode(mode);
this.updateViewerSetting();
selectMobileOption(option: string): void {
if (option === 'fitMode') {
this.showFitModeSubmenu = !this.showFitModeSubmenu;
if (this.scrollMode === CbxScrollMode.INFINITE) {
this.initializeInfiniteScroll();
setTimeout(() => this.scrollToPage(this.currentPage), 100);
}
}
selectFitModeFromMobile(mode: CbxFitMode): void {
this.fitMode = mode;
this.showFitModeSubmenu = false;
this.showMobileOptionsDropdown = false;
onPageViewModeChange(mode: CbxPageViewMode): void {
if (mode === CbxPageViewMode.TWO_PAGE && this.isPhonePortrait()) return;
this.pageViewMode = mode;
this.quickSettingsService.setPageViewMode(mode);
this.alignCurrentPageToParity();
this.footerService.setTwoPageView(this.isTwoPageView);
this.updateViewerSetting();
}
toggleScrollModeFromMobile(): void {
this.toggleScrollMode();
this.showMobileOptionsDropdown = false;
onPageSpreadChange(spread: CbxPageSpread): void {
this.pageSpread = spread;
this.quickSettingsService.setPageSpread(spread);
this.alignCurrentPageToParity();
this.updateViewerSetting();
}
toggleSpreadDirectionFromMobile(): void {
this.toggleSpreadDirection();
this.showMobileOptionsDropdown = false;
}
toggleViewFromMobile(): void {
this.toggleView();
this.showMobileOptionsDropdown = false;
}
toggleBackgroundFromMobile(): void {
this.toggleBackground();
this.showMobileOptionsDropdown = false;
}
get displayLabel(): string {
const option = this.fitModeOptions.find(opt => opt.value === this.fitMode);
return option ? option.icon : '↔️';
}
get scrollModeIcon(): string {
return this.scrollMode === CbxScrollMode.PAGINATED ? '📄' : '📜';
onBackgroundColorChange(color: CbxBackgroundColor): void {
this.backgroundColor = color;
this.quickSettingsService.setBackgroundColor(color);
this.updateViewerSetting();
}
private initializeInfiniteScroll(): void {
@@ -432,6 +545,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.currentPage = newPage;
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
break;
}
@@ -518,13 +632,23 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.scrollToPage(targetIndex);
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
} else {
this.alignCurrentPageToParity();
this.updateProgress();
this.updateSessionProgress();
this.updateFooterPage();
}
}
firstPage(): void {
this.goToPage(1);
}
lastPage(): void {
this.goToPage(this.pages.length);
}
private scrollToPage(pageIndex: number): void {
this.ensurePageLoaded(pageIndex);
@@ -554,6 +678,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
}
onImageClick(): void {
this.visibilityManager.togglePinned();
}
@HostListener('window:keydown', ['$event'])
handleKeyDown(event: KeyboardEvent) {
if (event.key === 'ArrowRight') this.nextPage();
@@ -573,9 +701,20 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
@HostListener('window:resize')
onResize() {
this.visibilityManager.updateWindowHeight(window.innerHeight);
this.enforcePortraitSinglePageView();
}
@HostListener('document:mousemove', ['$event'])
onMouseMove(event: MouseEvent): void {
this.visibilityManager.handleMouseMove(event.clientY);
}
@HostListener('document:mouseleave', ['$event'])
onMouseLeave(event: MouseEvent): void {
this.visibilityManager.handleMouseLeave();
}
private handleSwipeGesture() {
const delta = this.touchEndX - this.touchStartX;
if (Math.abs(delta) >= 50) delta < 0 ? this.nextPage() : this.previousPage();
@@ -584,6 +723,8 @@ 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.quickSettingsService.setPageViewMode(this.pageViewMode);
this.footerService.setTwoPageView(false);
this.updateViewerSetting();
}
}
@@ -592,18 +733,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
return window.innerWidth < 768 && window.innerHeight > window.innerWidth;
}
@HostListener('document:click', ['$event'])
onDocumentClick(event: MouseEvent): void {
const target = event.target as HTMLElement;
if (!target.closest('.fit-mode-dropdown')) {
this.showFitModeDropdown = false;
}
if (!target.closest('.mobile-controls')) {
this.showMobileOptionsDropdown = false;
this.showFitModeSubmenu = false;
}
}
get isAtLastPage(): boolean {
return this.currentPage >= this.pages.length - 1;
}
@@ -653,6 +782,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.previousBookInSeries = hasPreviousBook ? sortedBySeriesNumber[currentBookIndex - 1] : null;
this.nextBookInSeries = hasNextBook ? sortedBySeriesNumber[currentBookIndex + 1] : null;
// Update footer service with series info
this.footerService.setSeriesBooks(this.previousBookInSeries, this.nextBookInSeries);
this.footerService.setHasSeries(true);
},
error: (err) => {
console.error('[SeriesNav] Failed to load series information:', err);
@@ -689,18 +822,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
return parts.join(' - ');
}
getPreviousBookTooltip(): string {
if (!this.previousBookInSeries) return 'No Previous Book';
return `Previous Book: ${this.getBookDisplayTitle(this.previousBookInSeries)}`;
}
getNextBookTooltip(): string {
if (!this.nextBookInSeries) return 'No Next Book';
return `Next Book: ${this.getBookDisplayTitle(this.nextBookInSeries)}`;
}
ngOnDestroy(): void {
this.endReadingSession();
this.destroy$.next();
this.destroy$.complete();
}
private endReadingSession(): void {
@@ -710,8 +835,54 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
}
}
closeReader(): void {
this.endReadingSession();
this.location.back();
// Bookmark methods
private updateBookmarkState(): void {
this.isCurrentPageBookmarked = this.sidebarService.isPageBookmarked(this.currentPage + 1);
}
toggleBookmark(): void {
this.sidebarService.toggleBookmark(this.currentPage + 1);
}
// Notes state methods
private updateNotesState(): void {
this.currentPageHasNotes = this.sidebarService.pageHasNotes(this.currentPage + 1);
}
// Note dialog methods
openNoteDialog(): void {
this.editingNote = null;
this.noteDialogData = {
pageNumber: this.currentPage + 1
};
this.showNoteDialog = true;
}
private openNoteDialogForEdit(note: BookNoteV2): void {
this.editingNote = note;
this.noteDialogData = {
pageNumber: parseInt(note.cfi, 10) || this.currentPage + 1,
noteId: note.id,
noteContent: note.noteContent,
color: note.color
};
this.showNoteDialog = true;
}
onNoteSave(result: CbxNoteDialogResult): void {
if (this.editingNote) {
this.sidebarService.updateNote(this.editingNote.id, result.noteContent, result.color);
} else if (this.noteDialogData) {
this.sidebarService.createNote(this.noteDialogData.pageNumber, result.noteContent, result.color);
}
this.showNoteDialog = false;
this.noteDialogData = null;
this.editingNote = null;
}
onNoteCancel(): void {
this.showNoteDialog = false;
this.noteDialogData = null;
this.editingNote = null;
}
}
@@ -0,0 +1,49 @@
<div class="dialog-overlay" (click)="onOverlayClick($event)">
<div class="dialog">
<div class="dialog-header">
<h2>{{ isEditing ? 'Edit Note' : 'Add Note' }}</h2>
<button class="close-btn" (click)="onCancel()">
<app-reader-icon name="close" [size]="18"></app-reader-icon>
</button>
</div>
<div class="dialog-body">
<div class="page-info-section">
<span class="section-label">Page</span>
<p class="page-info">Page {{ data?.pageNumber }}</p>
</div>
<div class="note-section">
<label class="section-label" for="noteContent">Your Note</label>
<textarea
id="noteContent"
class="note-input"
[(ngModel)]="noteContent"
placeholder="Write your note here..."
rows="6"
autofocus
></textarea>
</div>
<div class="color-section">
<span class="section-label">Note Color</span>
<div class="color-buttons">
@for (color of noteColors; track color.value) {
<button
class="color-btn"
[style.--color]="color.value"
[class.selected]="selectedColor === color.value"
[title]="color.label"
(click)="selectColor(color.value)">
</button>
}
</div>
</div>
</div>
<div class="dialog-footer">
<button class="btn btn-secondary" (click)="onCancel()">Cancel</button>
<button class="btn btn-primary" (click)="onSave()" [disabled]="!noteContent.trim()">{{ isEditing ? 'Update Note' : 'Save Note' }}</button>
</div>
</div>
</div>
@@ -0,0 +1,258 @@
// Variables matching reader styling
$dialog-bg: #1a1a1a;
$text-primary: rgba(255, 255, 255, 0.95);
$text-secondary: rgba(255, 255, 255, 0.6);
$text-muted: rgba(255, 255, 255, 0.4);
$border-color: rgba(255, 255, 255, 0.08);
$hover-bg: rgba(255, 255, 255, 0.08);
$active-color: #4a90e2;
$active-bg: rgba(74, 144, 226, 0.15);
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;
.dialog-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.5);
backdrop-filter: blur(4px);
z-index: 13000;
display: flex;
align-items: center;
justify-content: center;
animation: fadeIn $transition-normal;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.dialog {
background: $dialog-bg;
border: 1px solid $border-color;
border-radius: 12px;
width: 90%;
max-width: 500px;
max-height: 85vh;
display: flex;
flex-direction: column;
overflow: hidden;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
animation: slideUp 250ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slideUp {
from {
transform: translateY(20px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
.dialog-header {
padding: 16px 20px;
border-bottom: 1px solid $border-color;
display: flex;
align-items: center;
justify-content: space-between;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
h2 {
margin: 0;
font-size: 16px;
font-weight: 600;
color: $text-primary;
letter-spacing: -0.3px;
}
}
.close-btn {
background: none;
border: none;
color: $text-muted;
cursor: pointer;
padding: 6px;
border-radius: 6px;
transition: background $transition-fast, color $transition-fast;
line-height: 1;
width: 32px;
height: 32px;
display: flex;
align-items: center;
justify-content: center;
&:hover {
background: $hover-bg;
color: $text-primary;
}
}
.dialog-body {
padding: 20px;
overflow-y: auto;
flex: 1;
display: flex;
flex-direction: column;
gap: 20px;
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.15);
border-radius: 3px;
&:hover {
background: rgba(255, 255, 255, 0.25);
}
}
}
.section-label {
display: block;
color: $text-muted;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 8px;
}
.page-info-section {
.page-info {
margin: 0;
padding: 12px 16px;
background: rgba(255, 255, 255, 0.03);
border-left: 3px solid $active-color;
border-radius: 0 8px 8px 0;
color: $text-secondary;
font-size: 13px;
line-height: 1.6;
}
}
.note-section {
flex: 1;
display: flex;
flex-direction: column;
}
.note-input {
flex: 1;
min-height: 120px;
padding: 12px 16px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid $border-color;
border-radius: 8px;
color: $text-primary;
font-size: 14px;
line-height: 1.6;
resize: vertical;
font-family: inherit;
transition: border-color $transition-fast, box-shadow $transition-fast;
&::placeholder {
color: $text-muted;
}
&:focus {
outline: none;
border-color: $active-color;
box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}
}
.color-section {
.color-buttons {
display: flex;
gap: 10px;
}
}
.color-btn {
width: 32px;
height: 32px;
border-radius: 50%;
border: 2px solid transparent;
background: var(--color);
cursor: pointer;
transition: transform $transition-fast, border-color $transition-fast, box-shadow $transition-fast;
position: relative;
&:hover {
transform: scale(1.1);
}
&.selected {
border-color: $text-primary;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.2);
&::after {
content: '\2713';
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 14px;
font-weight: bold;
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
}
}
.dialog-footer {
padding: 16px 20px;
border-top: 1px solid $border-color;
display: flex;
justify-content: flex-end;
gap: 12px;
background: linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0%, transparent 100%);
}
.btn {
padding: 10px 20px;
border-radius: 8px;
font-size: 14px;
font-weight: 500;
cursor: pointer;
transition: background $transition-fast, transform $transition-fast, opacity $transition-fast;
border: none;
&:active {
transform: scale(0.98);
}
&:disabled {
opacity: 0.5;
cursor: not-allowed;
transform: none;
}
}
.btn-secondary {
background: $hover-bg;
color: $text-primary;
&:hover:not(:disabled) {
background: rgba(255, 255, 255, 0.12);
}
}
.btn-primary {
background: $active-color;
color: white;
&:hover:not(:disabled) {
background: #5a9ee6;
}
}
@@ -0,0 +1,75 @@
import {Component, EventEmitter, Input, Output, OnChanges, SimpleChanges} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {ReaderIconComponent} from '../../ebook-reader/shared/icon.component';
export interface CbxNoteDialogData {
pageNumber: number;
noteId?: number;
noteContent?: string;
color?: string;
}
export interface CbxNoteDialogResult {
noteContent: string;
color: string;
}
@Component({
selector: 'app-cbx-note-dialog',
standalone: true,
imports: [CommonModule, FormsModule, ReaderIconComponent],
templateUrl: './cbx-note-dialog.component.html',
styleUrls: ['./cbx-note-dialog.component.scss']
})
export class CbxNoteDialogComponent implements OnChanges {
@Input() data: CbxNoteDialogData | null = null;
@Output() save = new EventEmitter<CbxNoteDialogResult>();
@Output() cancel = new EventEmitter<void>();
noteContent = '';
selectedColor = '#FFC107';
get isEditing(): boolean {
return !!this.data?.noteId;
}
ngOnChanges(changes: SimpleChanges): void {
if (changes['data'] && this.data) {
this.noteContent = this.data.noteContent || '';
this.selectedColor = this.data.color || '#FFC107';
}
}
noteColors = [
{value: '#FFC107', label: 'Amber'},
{value: '#4CAF50', label: 'Green'},
{value: '#2196F3', label: 'Blue'},
{value: '#E91E63', label: 'Pink'},
{value: '#9C27B0', label: 'Purple'},
{value: '#FF5722', label: 'Deep Orange'}
];
onSave(): void {
if (this.noteContent.trim()) {
this.save.emit({
noteContent: this.noteContent.trim(),
color: this.selectedColor
});
}
}
onCancel(): void {
this.cancel.emit();
}
selectColor(color: string): void {
this.selectedColor = color;
}
onOverlayClick(event: MouseEvent): void {
if ((event.target as HTMLElement).classList.contains('dialog-overlay')) {
this.onCancel();
}
}
}
@@ -0,0 +1,90 @@
<div class="cbx-footer" [class.visible]="isVisible">
@if (state.hasSeries) {
<button
class="nav-btn series-btn"
(click)="onPreviousBook()"
[disabled]="!state.previousBookInSeries"
[title]="getPreviousBookTooltip()">
<app-reader-icon name="chevron-double-left" [size]="14" />
<span class="label hide-on-mobile">Prev Book</span>
</button>
}
<div class="page-nav-left">
<button class="nav-btn" (click)="onFirstPage()" [disabled]="!canGoPrevious" title="First Page">
<app-reader-icon name="chevron-first" [size]="16" />
</button>
<button class="nav-btn" (click)="onPreviousPage()" [disabled]="!canGoPrevious" title="Previous Page">
<app-reader-icon name="chevron-left" [size]="16" />
</button>
<div class="page-info">
<span class="current">{{ displayPage }}</span>
@if (displaySecondPage) {
<span class="separator">-{{ displaySecondPage }}</span>
}
<span class="total"> of {{ state.totalPages }}</span>
</div>
<button class="nav-btn" (click)="onNextPage()" [disabled]="!canGoNext" title="Next Page">
<app-reader-icon name="chevron-right" [size]="16" />
</button>
<button class="nav-btn" (click)="onLastPage()" [disabled]="!canGoNext" title="Last Page">
<app-reader-icon name="chevron-last" [size]="16" />
</button>
</div>
<div class="page-controls">
<div class="slider-wrapper">
<input
type="range"
class="page-slider"
[min]="1"
[max]="state.totalPages"
[value]="sliderValue"
(input)="onSliderChange($event)"
list="page-ticks"
title="Page Slider"/>
<datalist id="page-ticks">
@for (tick of sliderTicks; track tick) {
<option [value]="tick"></option>
}
</datalist>
</div>
<div class="goto-page-wrapper">
<div class="goto-page">
<input
type="number"
[(ngModel)]="goToPageInput"
[min]="1"
[max]="state.totalPages"
placeholder="Page"
class="page-input"
(keyup.enter)="onGoToPage()"
/>
<button
class="go-btn"
(click)="onGoToPage()"
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > state.totalPages">
Go
</button>
</div>
</div>
</div>
<div class="page-nav-right">
</div>
@if (state.hasSeries) {
<button
class="nav-btn series-btn"
(click)="onNextBook()"
[disabled]="!state.nextBookInSeries"
[title]="getNextBookTooltip()">
<span class="label hide-on-mobile">Next Book</span>
<app-reader-icon name="chevron-double-right" [size]="14" />
</button>
}
</div>
@@ -0,0 +1,342 @@
// Variables
$footer-bg: #1a1a1a;
$text-primary: rgba(255, 255, 255, 0.95);
$text-secondary: rgba(255, 255, 255, 0.6);
$text-muted: rgba(255, 255, 255, 0.4);
$border-color: rgba(255, 255, 255, 0.08);
$hover-bg: rgba(255, 255, 255, 0.08);
$active-color: #4a90e2;
$transition-fast: 150ms ease;
.cbx-footer {
position: absolute;
bottom: 0;
left: 0;
right: 0;
height: 52px;
padding: 0 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
z-index: 1000;
background: linear-gradient(135deg, #2d2d2d 0%, #1f1f1f 100%);
border-top: 1px solid #404040;
box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
color: $text-primary;
transform: translateY(100%);
opacity: 0;
transition: transform 0.3s ease, opacity 0.3s ease;
pointer-events: none;
&.visible {
transform: translateY(0);
opacity: 1;
pointer-events: auto;
}
}
.page-nav-left,
.page-nav-right {
display: flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
}
.series-nav {
flex: 0 0 auto;
min-width: 110px;
}
.page-nav {
display: flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
}
.nav-btn {
background: rgba(51, 51, 51, 0.9);
border: 1px solid #555;
color: $text-primary;
padding: 6px 10px;
border-radius: 4px;
cursor: pointer;
transition: all $transition-fast;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
font-size: 14px;
font-weight: bold;
&:hover:not(:disabled) {
background: #4a4a4a;
border-color: #666;
}
&:disabled {
background: #2a2a2a;
color: #666;
cursor: not-allowed;
border-color: #333;
}
&.series-btn {
gap: 6px;
padding: 6px 12px;
background: $active-color;
border-color: $active-color;
.label {
font-size: 12px;
font-weight: 500;
}
&:hover:not(:disabled) {
background: darken($active-color, 10%);
}
&:disabled {
background: #555;
border-color: #555;
opacity: 0.5;
}
}
}
.page-info {
padding: 4px 12px;
background: rgba(255, 255, 255, 0.1);
border-radius: 4px;
font-size: 13px;
font-weight: 500;
min-width: 90px;
text-align: center;
.current {
color: $active-color;
font-weight: 600;
}
.separator {
color: $active-color;
font-weight: 600;
}
.total {
color: $text-secondary;
}
}
.page-controls {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
justify-content: center;
max-width: none;
}
.slider-wrapper {
flex: 1;
display: flex;
align-items: center;
position: relative;
.page-slider {
width: 100%;
border-radius: 3px;
outline: none;
-webkit-appearance: none;
appearance: none;
background: none;
cursor: pointer;
/* ===== Track ===== */
&::-webkit-slider-runnable-track {
width: 100%;
height: 6px;
background: rgba(255, 255, 255, 0.12);
border-radius: 3px;
cursor: pointer;
}
&::-moz-range-track {
width: 100%;
height: 6px;
background: rgba(255, 255, 255, 0.12);
border-radius: 3px;
cursor: pointer;
}
&::-ms-fill-lower,
&::-ms-fill-upper {
background: rgba(255, 255, 255, 0.12);
border-radius: 3px;
}
/* ===== Thumb ===== */
&::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: $active-color;
cursor: pointer;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
transition: transform $transition-fast, box-shadow $transition-fast;
margin-top: calc((6px - 18px) / 2); /* center thumb on track */
}
&::-moz-range-thumb {
width: 18px;
height: 18px;
border-radius: 50%;
background: $active-color;
cursor: pointer;
border: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
transition: transform $transition-fast, box-shadow $transition-fast;
margin-top: calc((6px - 18px) / 2);
}
&::-ms-thumb {
width: 18px;
height: 18px;
border-radius: 50%;
background: $active-color;
cursor: pointer;
border: none;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
}
/* ===== Tick marks ===== */
datalist {
display: flex;
justify-content: space-between;
position: absolute;
width: 100%;
left: 0;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
height: 10px;
box-sizing: border-box;
option {
width: 0;
position: relative;
padding: 0;
&::before {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 2px;
height: 10px;
background: rgba(255, 255, 255, 0.5);
top: 0;
}
}
}
}
.goto-page {
display: flex;
align-items: center;
gap: 4px;
background: rgba(51, 51, 51, 0.9);
border-radius: 4px;
padding: 2px;
border: 1px solid #555;
.page-input {
width: 55px;
padding: 4px 6px;
border: none;
border-radius: 3px;
background: #404040;
color: $text-primary;
font-size: 12px;
text-align: center;
transition: all 0.2s ease;
&:focus {
outline: none;
background: #4a4a4a;
box-shadow: 0 0 0 1px rgba(74, 144, 226, 0.5);
}
&::placeholder {
color: #999;
}
}
.go-btn {
padding: 4px 10px;
background: $active-color;
color: white;
border: none;
border-radius: 3px;
font-size: 12px;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
&:hover:not(:disabled) {
background: darken($active-color, 10%);
}
&:disabled {
background: #666;
cursor: not-allowed;
opacity: 0.6;
}
}
}
@media (max-width: 768px) {
.cbx-footer {
height: 48px;
padding: 0 8px;
gap: 8px;
justify-content: center;
}
.page-nav-left .series-btn,
.page-nav-right .series-btn {
display: none;
}
.page-nav-left,
.page-nav-right {
gap: 4px;
}
.page-nav-left {
margin: 0 auto;
justify-content: center;
flex: 1;
}
.page-controls {
display: none;
}
.slider-wrapper {
display: none;
}
.goto-page-wrapper {
display: none;
}
.hide-on-mobile {
display: none !important;
}
}
@@ -0,0 +1,167 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {Book} from '../../../../book/model/book.model';
import {ReaderIconComponent} from '../../../ebook-reader/shared/icon.component';
import {CbxFooterService, CbxFooterState} from './cbx-footer.service';
@Component({
selector: 'app-cbx-footer',
standalone: true,
imports: [CommonModule, FormsModule, ReaderIconComponent],
templateUrl: './cbx-footer.component.html',
styleUrls: ['./cbx-footer.component.scss']
})
export class CbxFooterComponent implements OnInit, OnDestroy {
private footerService = inject(CbxFooterService);
private destroy$ = new Subject<void>();
isVisible = false;
state: CbxFooterState = {
currentPage: 0,
totalPages: 0,
isTwoPageView: false,
previousBookInSeries: null,
nextBookInSeries: null,
hasSeries: false
};
goToPageInput: number | null = null;
ngOnInit(): void {
this.footerService.state$
.pipe(takeUntil(this.destroy$))
.subscribe(state => this.state = state);
this.footerService.forceVisible$
.pipe(takeUntil(this.destroy$))
.subscribe(visible => this.isVisible = visible);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
get displayPage(): number {
return this.state.currentPage + 1;
}
get displaySecondPage(): number | null {
if (this.state.isTwoPageView && this.state.currentPage + 1 < this.state.totalPages) {
return this.state.currentPage + 2;
}
return null;
}
get sliderValue(): number {
return this.displayPage;
}
get canGoPrevious(): boolean {
return this.state.currentPage > 0;
}
get canGoNext(): boolean {
return this.state.currentPage < this.state.totalPages - 1;
}
get sliderTicks(): number[] {
const totalPages = this.state.totalPages;
if (totalPages <= 10) {
return Array.from({length: totalPages}, (_, i) => i + 1);
} else if (totalPages <= 20) {
return Array.from({length: totalPages}, (_, i) => i + 1);
} else if (totalPages <= 50) {
const ticks: number[] = [];
for (let i = 1; i <= totalPages; i += 2) {
ticks.push(i);
}
if (!ticks.includes(totalPages)) {
ticks.push(totalPages);
}
return ticks;
} else if (totalPages <= 100) {
const ticks: number[] = [];
const step = 5;
for (let i = 1; i <= totalPages; i += step) {
ticks.push(i);
}
if (!ticks.includes(totalPages)) {
ticks.push(totalPages);
}
return ticks;
} else {
const ticks: number[] = [];
const step = Math.ceil(totalPages / 20);
for (let i = 1; i <= totalPages; i += step) {
ticks.push(i);
}
if (!ticks.includes(totalPages)) {
ticks.push(totalPages);
}
return ticks;
}
}
onPreviousPage(): void {
this.footerService.emitPreviousPage();
}
onNextPage(): void {
this.footerService.emitNextPage();
}
onFirstPage(): void {
this.footerService.emitFirstPage();
}
onLastPage(): void {
this.footerService.emitLastPage();
}
onGoToPage(): void {
if (this.goToPageInput !== null && this.goToPageInput >= 1 && this.goToPageInput <= this.state.totalPages) {
this.footerService.emitGoToPage(this.goToPageInput);
this.goToPageInput = null;
}
}
onSliderChange(event: Event): void {
const target = event.target as HTMLInputElement;
const page = parseInt(target.value, 10);
this.footerService.emitSliderChange(page);
}
onPreviousBook(): void {
this.footerService.emitPreviousBook();
}
onNextBook(): void {
this.footerService.emitNextBook();
}
getPreviousBookTooltip(): string {
if (!this.state.previousBookInSeries) return 'No Previous Book';
return `Previous: ${this.getBookDisplayTitle(this.state.previousBookInSeries)}`;
}
getNextBookTooltip(): string {
if (!this.state.nextBookInSeries) return 'No Next Book';
return `Next: ${this.getBookDisplayTitle(this.state.nextBookInSeries)}`;
}
private getBookDisplayTitle(book: Book): string {
const parts: string[] = [];
if (book.metadata?.seriesNumber) {
parts.push(`#${book.metadata.seriesNumber}`);
}
const title = book.metadata?.title || book.fileName;
if (title) {
parts.push(title);
}
return parts.join(' - ');
}
}
@@ -0,0 +1,136 @@
import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {Book} from '../../../../book/model/book.model';
export interface CbxFooterState {
currentPage: number;
totalPages: number;
isTwoPageView: boolean;
previousBookInSeries: Book | null;
nextBookInSeries: Book | null;
hasSeries: boolean;
}
@Injectable()
export class CbxFooterService {
private _state = new BehaviorSubject<CbxFooterState>({
currentPage: 0,
totalPages: 0,
isTwoPageView: false,
previousBookInSeries: null,
nextBookInSeries: null,
hasSeries: false
});
state$ = this._state.asObservable();
private _forceVisible = new BehaviorSubject<boolean>(false);
forceVisible$ = this._forceVisible.asObservable();
private _previousPage = new Subject<void>();
previousPage$ = this._previousPage.asObservable();
private _nextPage = new Subject<void>();
nextPage$ = this._nextPage.asObservable();
private _goToPage = new Subject<number>();
goToPage$ = this._goToPage.asObservable();
private _firstPage = new Subject<void>();
firstPage$ = this._firstPage.asObservable();
private _lastPage = new Subject<void>();
lastPage$ = this._lastPage.asObservable();
private _previousBook = new Subject<void>();
previousBook$ = this._previousBook.asObservable();
private _nextBook = new Subject<void>();
nextBook$ = this._nextBook.asObservable();
private _sliderChange = new Subject<number>();
sliderChange$ = this._sliderChange.asObservable();
get state(): CbxFooterState {
return this._state.value;
}
get isVisible(): boolean {
return this._forceVisible.value;
}
setForceVisible(visible: boolean): void {
this._forceVisible.next(visible);
}
updateState(partial: Partial<CbxFooterState>): void {
this._state.next({...this._state.value, ...partial});
}
setCurrentPage(page: number): void {
this.updateState({currentPage: page});
}
setTotalPages(total: number): void {
this.updateState({totalPages: total});
}
setTwoPageView(isTwoPage: boolean): void {
this.updateState({isTwoPageView: isTwoPage});
}
setSeriesBooks(previous: Book | null, next: Book | null): void {
this.updateState({
previousBookInSeries: previous,
nextBookInSeries: next
});
}
setHasSeries(hasSeries: boolean): void {
this.updateState({hasSeries});
}
// Navigation actions (called from footer component)
emitPreviousPage(): void {
this._previousPage.next();
}
emitNextPage(): void {
this._nextPage.next();
}
emitGoToPage(page: number): void {
this._goToPage.next(page);
}
emitFirstPage(): void {
this._firstPage.next();
}
emitLastPage(): void {
this._lastPage.next();
}
emitPreviousBook(): void {
this._previousBook.next();
}
emitNextBook(): void {
this._nextBook.next();
}
emitSliderChange(page: number): void {
this._sliderChange.next(page);
}
reset(): void {
this._state.next({
currentPage: 0,
totalPages: 0,
isTwoPageView: false,
previousBookInSeries: null,
nextBookInSeries: null,
hasSeries: false
});
this._forceVisible.next(false);
}
}
@@ -0,0 +1,21 @@
<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>
<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>
@@ -0,0 +1,116 @@
.cbx-header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 38px;
padding: 0 12px;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 14px;
z-index: 1000;
background: linear-gradient(135deg, #2d2d2d 0%, #1f1f1f 100%);
border-bottom: 1px solid #404040;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
color: #ffffff;
opacity: 1;
pointer-events: auto;
transform: translateY(0);
transition: opacity 0.25s ease-out, transform 0.25s ease-out;
&:not(.visible) {
opacity: 0;
pointer-events: none;
transform: translateY(-100%);
}
.icon-btn {
background: none;
border: none;
color: inherit;
cursor: pointer;
padding: 8px;
border-radius: 6px;
transition: background 0.15s, box-shadow 0.15s;
display: flex;
align-items: center;
justify-content: center;
margin-right: 8px;
.icon {
font-size: 18px;
line-height: 1;
}
&:hover {
background: rgba(255, 255, 255, 0.12);
}
&:last-of-type {
margin-right: 0;
}
&.close-btn {
.icon {
font-size: 22px;
font-weight: bold;
}
&:hover {
background: rgba(239, 68, 68, 0.2);
}
}
&.active {
color: #ef4444;
background: rgba(239, 68, 68, 0.15);
}
&.has-notes {
color: #ffc107;
position: relative;
}
.indicator-dot {
position: absolute;
top: 4px;
right: 4px;
width: 8px;
height: 8px;
background: #ffc107;
border-radius: 50%;
border: 1px solid #1f1f1f;
}
}
.book-title {
flex: 1;
text-align: center;
font-size: 14px;
font-weight: 500;
color: inherit;
pointer-events: none;
user-select: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
min-height: 1.2em;
padding: 0 16px;
}
}
@media (max-width: 600px) {
.cbx-header {
padding: 0 8px;
.icon-btn {
padding: 10px;
}
.book-title {
font-size: 13px;
padding: 0 8px;
}
}
}
@@ -0,0 +1,58 @@
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 {CommonModule} from '@angular/common';
@Component({
selector: 'app-cbx-header',
standalone: true,
imports: [CommonModule, ReaderIconComponent],
templateUrl: './cbx-header.component.html',
styleUrls: ['./cbx-header.component.scss']
})
export class CbxHeaderComponent implements OnInit, OnDestroy {
private headerService = inject(CbxHeaderService);
private destroy$ = new Subject<void>();
@Input() isCurrentPageBookmarked = false;
@Input() currentPageHasNotes = false;
isVisible = true;
get bookTitle(): string {
return this.headerService.title;
}
ngOnInit(): void {
this.headerService.forceVisible$
.pipe(takeUntil(this.destroy$))
.subscribe(visible => this.isVisible = visible);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
onOpenSidebar(): void {
this.headerService.openSidebar();
}
onOpenSettings(): void {
this.headerService.openQuickSettings();
}
onToggleBookmark(): void {
this.headerService.toggleBookmark();
}
onOpenNoteDialog(): void {
this.headerService.openNoteDialog();
}
onClose(): void {
this.headerService.close();
}
}
@@ -0,0 +1,69 @@
import {inject, Injectable} from '@angular/core';
import {Location} from '@angular/common';
import {BehaviorSubject, Subject} from 'rxjs';
import {CbxSidebarService} from '../sidebar/cbx-sidebar.service';
@Injectable()
export class CbxHeaderService {
private sidebarService = inject(CbxSidebarService);
private location = inject(Location);
private destroy$ = new Subject<void>();
private bookId!: number;
private bookTitle = '';
private _forceVisible = new BehaviorSubject<boolean>(true);
forceVisible$ = this._forceVisible.asObservable();
private _showQuickSettings = new Subject<void>();
showQuickSettings$ = this._showQuickSettings.asObservable();
private _toggleBookmark = new Subject<void>();
toggleBookmark$ = this._toggleBookmark.asObservable();
private _openNoteDialog = new Subject<void>();
openNoteDialog$ = this._openNoteDialog.asObservable();
get title(): string {
return this.bookTitle;
}
get isVisible(): boolean {
return this._forceVisible.value;
}
initialize(bookId: number, title: string | undefined, destroy$: Subject<void>): void {
this.bookId = bookId;
this.bookTitle = title || '';
this.destroy$ = destroy$;
}
setForceVisible(visible: boolean): void {
this._forceVisible.next(visible);
}
openSidebar(): void {
this.sidebarService.open();
}
openQuickSettings(): void {
this._showQuickSettings.next();
}
toggleBookmark(): void {
this._toggleBookmark.next();
}
openNoteDialog(): void {
this._openNoteDialog.next();
}
close(): void {
this.location.back();
}
reset(): void {
this._forceVisible.next(true);
this.bookTitle = '';
}
}
@@ -0,0 +1,79 @@
<div class="quick-settings-overlay" (click)="onOverlayClick()">
<div class="quick-settings-panel" (click)="$event.stopPropagation()">
<div class="pointer"></div>
<div class="panel-body">
<!-- Fit Mode -->
<div class="control">
<label>Fit Mode</label>
<div class="control-right">
<div class="button-group">
@for (option of fitModeOptions; track option.value) {
<button
class="option-btn"
[class.active]="state.fitMode === option.value"
(click)="onFitModeSelect(option.value)"
[title]="option.label">
<app-reader-icon [name]="option.icon" [size]="16" />
</button>
}
</div>
</div>
</div>
<!-- Scroll Mode -->
<div class="control">
<label>Scroll Mode</label>
<div class="control-right">
<span class="mode-label">{{ state.scrollMode === CbxScrollMode.PAGINATED ? 'Paginated' : 'Infinite' }}</span>
<button class="switch" [class.active]="state.scrollMode === CbxScrollMode.INFINITE" (click)="onScrollModeToggle()">
<span class="slider"></span>
</button>
</div>
</div>
<!-- Page View (only in paginated mode) -->
@if (isPaginated) {
<div class="control">
<label>Page View</label>
<div class="control-right">
<span class="mode-label">{{ isTwoPageView ? 'Two-Page' : 'Single' }}</span>
<button class="switch" [class.active]="isTwoPageView" (click)="onPageViewToggle()">
<span class="slider"></span>
</button>
</div>
</div>
}
<!-- Page Spread (only in two-page mode) -->
@if (isPaginated && isTwoPageView) {
<div class="control">
<label>Page Spread</label>
<div class="control-right">
<span class="mode-label">{{ state.pageSpread === CbxPageSpread.ODD ? 'Odd First' : 'Even First' }}</span>
<button class="switch" [class.active]="state.pageSpread === CbxPageSpread.EVEN" (click)="onPageSpreadToggle()">
<span class="slider"></span>
</button>
</div>
</div>
}
<!-- Background Color -->
<div class="control">
<label>Background</label>
<div class="control-right">
<div class="button-group">
@for (option of backgroundOptions; track option.value) {
<button
class="option-btn color-btn"
[class.active]="state.backgroundColor === option.value"
(click)="onBackgroundSelect(option.value)"
[title]="option.label">
<span class="color-swatch" [style.background]="option.color"></span>
</button>
}
</div>
</div>
</div>
</div>
</div>
</div>
@@ -0,0 +1,204 @@
// Variables
$panel-bg: #1a1a1a;
$text-primary: rgba(255, 255, 255, 0.95);
$text-secondary: rgba(255, 255, 255, 0.6);
$text-muted: rgba(255, 255, 255, 0.4);
$border-color: rgba(255, 255, 255, 0.08);
$hover-bg: rgba(255, 255, 255, 0.08);
$active-color: #4a90e2;
$active-bg: rgba(74, 144, 226, 0.15);
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;
.quick-settings-overlay {
position: fixed;
inset: 0;
z-index: 12000;
background: rgba(0, 0, 0, 0.3);
animation: fadeIn $transition-normal;
cursor: pointer;
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.quick-settings-panel {
position: absolute;
top: 52px;
right: 60px;
width: 320px;
background: $panel-bg;
border: 1px solid $border-color;
border-radius: 12px;
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
animation: slideDown 200ms cubic-bezier(0.4, 0, 0.2, 1);
overflow: visible;
cursor: default;
}
@keyframes slideDown {
from {
transform: translateY(-8px);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
// Pointer arrow
.pointer {
position: absolute;
top: -8px;
right: 18px;
width: 16px;
height: 16px;
background: $panel-bg;
border-left: 1px solid $border-color;
border-top: 1px solid $border-color;
transform: rotate(45deg);
border-radius: 3px 0 0 0;
}
.panel-body {
padding: 16px;
}
.control {
display: flex;
align-items: center;
justify-content: space-between;
padding: 12px 0;
&:not(:last-child) {
border-bottom: 1px solid $border-color;
}
> label {
color: $text-primary;
font-size: 13px;
font-weight: 500;
flex-shrink: 0;
}
}
.control-right {
display: flex;
align-items: center;
gap: 10px;
}
.mode-label {
font-size: 12px;
color: $text-secondary;
min-width: 60px;
text-align: right;
}
// Toggle switch
.switch {
position: relative;
width: 40px;
height: 22px;
background: rgba(255, 255, 255, 0.15);
border: none;
border-radius: 11px;
cursor: pointer;
transition: background 300ms ease;
padding: 0;
&.active {
background: $active-color;
.slider {
transform: translateX(18px);
}
}
.slider {
position: absolute;
top: 2px;
left: 2px;
width: 18px;
height: 18px;
background: #ffffff;
border-radius: 50%;
transition: transform 300ms ease;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
&:hover {
background: rgba(255, 255, 255, 0.2);
&.active {
background: lighten($active-color, 5%);
}
}
}
// Button group
.button-group {
display: flex;
gap: 4px;
background: rgba(255, 255, 255, 0.03);
padding: 3px;
border-radius: 6px;
border: 1px solid $border-color;
}
.option-btn {
width: 32px;
height: 28px;
background: transparent;
color: $text-secondary;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 14px;
display: flex;
align-items: center;
justify-content: center;
transition: all $transition-fast;
&:hover {
background: $hover-bg;
color: $text-primary;
}
&.active {
background: $active-color;
color: white;
}
&.color-btn {
padding: 4px;
&.active {
background: transparent;
box-shadow: 0 0 0 2px $active-color;
}
}
.color-swatch {
width: 20px;
height: 20px;
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.3);
}
}
@media (max-width: 600px) {
.quick-settings-panel {
right: 16px;
left: 16px;
width: auto;
top: 56px;
}
.pointer {
right: 30px;
}
}
@@ -0,0 +1,107 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {
CbxFitMode,
CbxScrollMode,
CbxPageViewMode,
CbxPageSpread,
CbxBackgroundColor,
PdfPageViewMode,
PdfPageSpread
} from '../../../../settings/user-management/user.service';
import {ReaderIconComponent, ReaderIconName} from '../../../ebook-reader/shared/icon.component';
import {CbxQuickSettingsService, CbxQuickSettingsState} from './cbx-quick-settings.service';
@Component({
selector: 'app-cbx-quick-settings',
standalone: true,
imports: [CommonModule, ReaderIconComponent],
templateUrl: './cbx-quick-settings.component.html',
styleUrls: ['./cbx-quick-settings.component.scss']
})
export class CbxQuickSettingsComponent implements OnInit, OnDestroy {
private quickSettingsService = inject(CbxQuickSettingsService);
private destroy$ = new Subject<void>();
state: CbxQuickSettingsState = {
fitMode: CbxFitMode.FIT_PAGE,
scrollMode: CbxScrollMode.PAGINATED,
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
pageSpread: CbxPageSpread.ODD,
backgroundColor: CbxBackgroundColor.GRAY
};
protected readonly CbxFitMode = CbxFitMode;
protected readonly CbxScrollMode = CbxScrollMode;
protected readonly CbxPageViewMode = CbxPageViewMode;
protected readonly CbxPageSpread = CbxPageSpread;
protected readonly CbxBackgroundColor = CbxBackgroundColor;
fitModeOptions: {value: CbxFitMode, label: string, icon: ReaderIconName}[] = [
{value: CbxFitMode.FIT_PAGE, label: 'Fit Page', icon: 'fit-page'},
{value: CbxFitMode.FIT_WIDTH, label: 'Fit Width', icon: 'fit-width'},
{value: CbxFitMode.FIT_HEIGHT, label: 'Fit Height', icon: 'fit-height'},
{value: CbxFitMode.ACTUAL_SIZE, label: 'Actual Size', icon: 'actual-size'},
{value: CbxFitMode.AUTO, label: 'Automatic', icon: 'auto-fit'}
];
backgroundOptions = [
{value: CbxBackgroundColor.BLACK, label: 'Black', color: '#000000'},
{value: CbxBackgroundColor.GRAY, label: 'Gray', color: '#808080'},
{value: CbxBackgroundColor.WHITE, label: 'White', color: '#ffffff'}
];
ngOnInit(): void {
this.quickSettingsService.state$
.pipe(takeUntil(this.destroy$))
.subscribe(state => this.state = state);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
get isTwoPageView(): boolean {
return this.state.pageViewMode === CbxPageViewMode.TWO_PAGE || this.state.pageViewMode === PdfPageViewMode.TWO_PAGE;
}
get isPaginated(): boolean {
return this.state.scrollMode === CbxScrollMode.PAGINATED;
}
onFitModeSelect(mode: CbxFitMode): void {
this.quickSettingsService.emitFitModeChange(mode);
}
onScrollModeToggle(): void {
const newMode = this.state.scrollMode === CbxScrollMode.PAGINATED
? CbxScrollMode.INFINITE
: CbxScrollMode.PAGINATED;
this.quickSettingsService.emitScrollModeChange(newMode);
}
onPageViewToggle(): void {
const newMode = this.state.pageViewMode === CbxPageViewMode.SINGLE_PAGE
? CbxPageViewMode.TWO_PAGE
: CbxPageViewMode.SINGLE_PAGE;
this.quickSettingsService.emitPageViewModeChange(newMode);
}
onPageSpreadToggle(): void {
const newSpread = this.state.pageSpread === CbxPageSpread.ODD
? CbxPageSpread.EVEN
: CbxPageSpread.ODD;
this.quickSettingsService.emitPageSpreadChange(newSpread);
}
onBackgroundSelect(color: CbxBackgroundColor): void {
this.quickSettingsService.emitBackgroundColorChange(color);
}
onOverlayClick(): void {
this.quickSettingsService.close();
}
}
@@ -0,0 +1,121 @@
import {Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {
CbxFitMode,
CbxScrollMode,
CbxPageViewMode,
CbxPageSpread,
CbxBackgroundColor,
PdfPageViewMode,
PdfPageSpread
} from '../../../../settings/user-management/user.service';
export interface CbxQuickSettingsState {
fitMode: CbxFitMode;
scrollMode: CbxScrollMode;
pageViewMode: CbxPageViewMode | PdfPageViewMode;
pageSpread: CbxPageSpread | PdfPageSpread;
backgroundColor: CbxBackgroundColor;
}
@Injectable()
export class CbxQuickSettingsService {
private _state = new BehaviorSubject<CbxQuickSettingsState>({
fitMode: CbxFitMode.FIT_PAGE,
scrollMode: CbxScrollMode.PAGINATED,
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
pageSpread: CbxPageSpread.ODD,
backgroundColor: CbxBackgroundColor.GRAY
});
state$ = this._state.asObservable();
private _visible = new BehaviorSubject<boolean>(false);
visible$ = this._visible.asObservable();
private _fitModeChange = new Subject<CbxFitMode>();
fitModeChange$ = this._fitModeChange.asObservable();
private _scrollModeChange = new Subject<CbxScrollMode>();
scrollModeChange$ = this._scrollModeChange.asObservable();
private _pageViewModeChange = new Subject<CbxPageViewMode>();
pageViewModeChange$ = this._pageViewModeChange.asObservable();
private _pageSpreadChange = new Subject<CbxPageSpread>();
pageSpreadChange$ = this._pageSpreadChange.asObservable();
private _backgroundColorChange = new Subject<CbxBackgroundColor>();
backgroundColorChange$ = this._backgroundColorChange.asObservable();
get state(): CbxQuickSettingsState {
return this._state.value;
}
get isVisible(): boolean {
return this._visible.value;
}
show(): void {
this._visible.next(true);
}
close(): void {
this._visible.next(false);
}
updateState(partial: Partial<CbxQuickSettingsState>): void {
this._state.next({...this._state.value, ...partial});
}
setFitMode(mode: CbxFitMode): void {
this.updateState({fitMode: mode});
}
setScrollMode(mode: CbxScrollMode): void {
this.updateState({scrollMode: mode});
}
setPageViewMode(mode: CbxPageViewMode | PdfPageViewMode): void {
this.updateState({pageViewMode: mode});
}
setPageSpread(spread: CbxPageSpread | PdfPageSpread): void {
this.updateState({pageSpread: spread});
}
setBackgroundColor(color: CbxBackgroundColor): void {
this.updateState({backgroundColor: color});
}
// Actions emitted from component
emitFitModeChange(mode: CbxFitMode): void {
this._fitModeChange.next(mode);
}
emitScrollModeChange(mode: CbxScrollMode): void {
this._scrollModeChange.next(mode);
}
emitPageViewModeChange(mode: CbxPageViewMode): void {
this._pageViewModeChange.next(mode);
}
emitPageSpreadChange(spread: CbxPageSpread): void {
this._pageSpreadChange.next(spread);
}
emitBackgroundColorChange(color: CbxBackgroundColor): void {
this._backgroundColorChange.next(color);
}
reset(): void {
this._state.next({
fitMode: CbxFitMode.FIT_PAGE,
scrollMode: CbxScrollMode.PAGINATED,
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
pageSpread: CbxPageSpread.ODD,
backgroundColor: CbxBackgroundColor.GRAY
});
this._visible.next(false);
}
}
@@ -0,0 +1,163 @@
@if (isOpen) {
<div class="sidebar-overlay" (click)="onOverlayClick()" [class.closing]="closing">
<aside class="sidebar" (click)="$event.stopPropagation()" [class.closing]="closing">
<!-- Header with book info -->
<header class="sidebar-header">
@if (bookInfo.coverUrl) {
<img
[src]="bookInfo.coverUrl"
alt="Book cover"
class="book-cover"
/>
}
<div class="book-meta">
<h2 class="book-title">{{ bookInfo.title }}</h2>
@if (bookInfo.authors) {
<p class="book-authors">{{ bookInfo.authors }}</p>
}
</div>
</header>
<!-- Tab navigation -->
<nav class="tabs">
<button
class="tab"
[class.active]="activeTab === 'pages'"
(click)="setActiveTab('pages')">
<app-reader-icon name="book" class="tab-icon"></app-reader-icon>
<span>Pages</span>
</button>
<button
class="tab"
[class.active]="activeTab === 'bookmarks'"
(click)="setActiveTab('bookmarks')">
<app-reader-icon name="bookmark" class="tab-icon"></app-reader-icon>
<span>Bookmarks</span>
@if (bookmarks.length > 0) {
<span class="badge">{{ bookmarks.length }}</span>
}
</button>
<button
class="tab"
[class.active]="activeTab === 'notes'"
(click)="setActiveTab('notes')">
<app-reader-icon name="note" class="tab-icon"></app-reader-icon>
<span>Notes</span>
@if (notes.length > 0) {
<span class="badge">{{ notes.length }}</span>
}
</button>
</nav>
<!-- Tab content -->
<div class="content">
@switch (activeTab) {
@case ('pages') {
<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') {
@if (bookmarks.length > 0) {
<ul class="item-list">
@for (bookmark of bookmarks; track bookmark.id) {
<li class="list-item" (click)="onBookmarkClick(bookmark.cfi)">
<div class="item-content">
<span class="item-title">{{ bookmark.title }}</span>
<span class="item-meta">{{ bookmark.createdAt | date: 'MMM d, y' }}</span>
</div>
<button class="delete-btn" (click)="onDeleteBookmark($event, bookmark.id)" aria-label="Delete bookmark">
<app-reader-icon name="trash" [size]="16"></app-reader-icon>
</button>
</li>
}
</ul>
} @else {
<div class="empty-state">
<app-reader-icon name="bookmark" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
<p>No bookmarks yet</p>
<span class="empty-hint">Tap the bookmark icon to save your place</span>
</div>
}
}
@case ('notes') {
<div class="notes-container">
@if (notes.length > 0) {
<div class="notes-search-wrapper">
<app-reader-icon name="search" class="search-icon" [size]="16"></app-reader-icon>
<input
type="text"
class="search-input"
placeholder="Search notes..."
[(ngModel)]="notesSearchQuery"
(ngModelChange)="onNotesSearchInput($event)"
/>
@if (notesSearchQuery) {
<button class="clear-btn" (click)="clearNotesSearch()" aria-label="Clear search">
<app-reader-icon name="close" [size]="14"></app-reader-icon>
</button>
}
</div>
}
@if (filteredNotes.length > 0) {
<ul class="item-list">
@for (note of filteredNotes; track note.id) {
<li class="list-item note-item" (click)="onNoteClick(note.cfi)">
<div class="note-bar" [style.background-color]="note.color"></div>
<div class="item-content">
<span class="note-text">{{ note.noteContent }}</span>
@if (note.chapterTitle) {
<span class="item-chapter">{{ note.chapterTitle }}</span>
}
<span class="item-meta">{{ note.createdAt | date: 'MMM d, y' }}</span>
</div>
<div class="action-buttons">
<button class="edit-btn" (click)="onEditNote($event, note)" aria-label="Edit note">
<app-reader-icon name="edit" [size]="16"></app-reader-icon>
</button>
<button class="delete-btn" (click)="onDeleteNote($event, note.id)" aria-label="Delete note">
<app-reader-icon name="trash" [size]="16"></app-reader-icon>
</button>
</div>
</li>
}
</ul>
} @else if (notes.length > 0 && notesSearchQuery) {
<div class="empty-state">
<app-reader-icon name="search" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
<p>No matching notes</p>
<span class="empty-hint">Try different search terms</span>
</div>
} @else {
<div class="empty-state">
<app-reader-icon name="note" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
<p>No notes yet</p>
<span class="empty-hint">Tap the notes icon to add a note for the current page</span>
</div>
}
</div>
}
}
</div>
</aside>
</div>
}
@@ -0,0 +1,458 @@
// Variables
$sidebar-width: 300px;
$sidebar-bg: #1a1a1a;
$text-primary: rgba(255, 255, 255, 0.95);
$text-secondary: rgba(255, 255, 255, 0.6);
$text-muted: rgba(255, 255, 255, 0.4);
$border-color: rgba(255, 255, 255, 0.08);
$hover-bg: rgba(255, 255, 255, 0.06);
$active-bg: rgba(74, 144, 226, 0.15);
$active-color: #4a90e2;
$transition-fast: 150ms ease;
$transition-normal: 200ms ease;
// Overlay
.sidebar-overlay {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.4);
backdrop-filter: blur(2px);
z-index: 12000;
animation: fadeIn $transition-normal;
&.closing {
animation: fadeOut $transition-normal forwards;
}
}
// Sidebar container
.sidebar {
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: $sidebar-width;
background: $sidebar-bg;
display: flex;
flex-direction: column;
color: $text-primary;
box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
animation: slideIn 250ms cubic-bezier(0.4, 0, 0.2, 1);
z-index: 12001;
&.closing {
animation: slideOut 200ms cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
}
// Header
.sidebar-header {
display: flex;
gap: 14px;
padding: 20px 16px;
border-bottom: 1px solid $border-color;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0%, transparent 100%);
}
.book-cover {
width: 60px;
height: 90px;
object-fit: cover;
border-radius: 4px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
flex-shrink: 0;
}
.book-meta {
display: flex;
flex-direction: column;
justify-content: center;
min-width: 0;
gap: 6px;
}
.book-title {
font-size: 14px;
font-weight: 600;
line-height: 1.3;
margin: 0;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.book-authors {
font-size: 12px;
color: $text-secondary;
margin: 0;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 1;
overflow: hidden;
}
// Tabs
.tabs {
display: flex;
border-bottom: 1px solid $border-color;
background: rgba(0, 0, 0, 0.2);
}
.tab {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
padding: 12px 8px;
background: none;
border: none;
color: $text-secondary;
font-size: 11px;
font-weight: 500;
cursor: pointer;
transition: color $transition-fast, background $transition-fast;
position: relative;
&:hover {
color: $text-primary;
background: $hover-bg;
}
&.active {
color: $active-color;
&::after {
content: '';
position: absolute;
bottom: 0;
left: 16px;
right: 16px;
height: 2px;
background: $active-color;
border-radius: 1px 1px 0 0;
}
}
}
.tab-icon {
width: 18px;
height: 18px;
}
.badge {
position: absolute;
top: 6px;
right: calc(50% - 20px);
min-width: 16px;
height: 16px;
padding: 0 4px;
background: $active-color;
color: white;
font-size: 10px;
font-weight: 600;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
}
// Content area
.content {
flex: 1;
overflow-y: auto;
overscroll-behavior: contain;
&::-webkit-scrollbar {
width: 6px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.15);
border-radius: 3px;
&:hover {
background: rgba(255, 255, 255, 0.25);
}
}
}
// Page list
.page-list {
list-style: none;
margin: 0;
padding: 8px 0;
}
.page-row {
display: flex;
align-items: center;
width: 100%;
padding: 12px 16px;
background: none;
border: none;
color: $text-primary;
font-size: 13px;
text-align: left;
cursor: pointer;
transition: background $transition-fast;
gap: 12px;
&:hover {
background: $hover-bg;
}
&.active {
background: $active-bg;
color: $active-color;
font-weight: 500;
}
}
.page-number {
min-width: 32px;
text-align: right;
font-size: 12px;
font-weight: 600;
opacity: 0.7;
}
.page-label {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
// Item list (bookmarks & notes)
.item-list {
list-style: none;
margin: 0;
padding: 8px 0;
}
.list-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 16px;
cursor: pointer;
transition: background $transition-fast;
&:hover {
background: $hover-bg;
.delete-btn,
.action-buttons {
opacity: 1;
}
}
}
.note-item {
align-items: flex-start;
}
.note-bar {
width: 3px;
align-self: stretch;
border-radius: 2px;
flex-shrink: 0;
}
.item-content {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 4px;
}
.item-title {
font-size: 13px;
font-weight: 500;
color: $text-primary;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.note-text {
font-size: 13px;
color: $text-primary;
line-height: 1.4;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
}
.item-chapter {
font-size: 11px;
color: $text-secondary;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.item-meta {
font-size: 11px;
color: $text-muted;
}
.action-buttons {
display: flex;
flex-direction: column;
gap: 4px;
opacity: 0;
transition: opacity $transition-fast;
flex-shrink: 0;
}
.edit-btn,
.delete-btn {
width: 28px;
height: 28px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: none;
border: none;
border-radius: 6px;
color: $text-muted;
cursor: pointer;
transition: background $transition-fast, color $transition-fast;
flex-shrink: 0;
opacity: 0;
svg {
width: 16px;
height: 16px;
}
}
.list-item:hover .edit-btn,
.list-item:hover .delete-btn {
opacity: 1;
}
.edit-btn:hover {
background: rgba(74, 144, 226, 0.15);
color: $active-color;
}
.delete-btn:hover {
background: rgba(239, 68, 68, 0.15);
color: #ef4444;
}
// Notes container
.notes-container {
display: flex;
flex-direction: column;
height: 100%;
}
.notes-search-wrapper {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
background: rgba(0, 0, 0, 0.2);
border-bottom: 1px solid $border-color;
.search-icon {
color: $text-muted;
flex-shrink: 0;
}
.search-input {
flex: 1;
background: none;
border: none;
color: $text-primary;
font-size: 14px;
outline: none;
&::placeholder {
color: $text-muted;
}
}
.clear-btn {
width: 24px;
height: 24px;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: rgba(255, 255, 255, 0.1);
border: none;
border-radius: 50%;
color: $text-secondary;
cursor: pointer;
transition: background $transition-fast, color $transition-fast;
flex-shrink: 0;
&:hover {
background: rgba(255, 255, 255, 0.15);
color: $text-primary;
}
}
}
// Empty state
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 48px 24px;
text-align: center;
color: $text-secondary;
.empty-icon {
width: 48px;
height: 48px;
margin-bottom: 16px;
opacity: 0.4;
}
p {
margin: 0 0 8px;
font-size: 14px;
font-weight: 500;
}
}
.empty-hint {
font-size: 12px;
color: $text-muted;
}
// Animations
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes fadeOut {
from { opacity: 1; }
to { opacity: 0; }
}
@keyframes slideIn {
from { transform: translateX(-100%); }
to { transform: translateX(0); }
}
@keyframes slideOut {
from { transform: translateX(0); }
to { transform: translateX(-100%); }
}
@@ -0,0 +1,137 @@
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {CommonModule, DatePipe} from '@angular/common';
import {FormsModule} from '@angular/forms';
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 {BookMark} from '../../../../../shared/service/book-mark.service';
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
import {ReaderIconComponent} from '../../../ebook-reader/shared/icon.component';
@Component({
selector: 'app-cbx-sidebar',
standalone: true,
templateUrl: './cbx-sidebar.component.html',
styleUrls: ['./cbx-sidebar.component.scss'],
imports: [CommonModule, FormsModule, ReaderIconComponent, DatePipe]
})
export class CbxSidebarComponent implements OnInit, OnDestroy {
private sidebarService = inject(CbxSidebarService);
private destroy$ = new Subject<void>();
isOpen = false;
closing = false;
activeTab: CbxSidebarTab = 'pages';
bookInfo: SidebarBookInfo = { id: null, title: '', authors: '', coverUrl: null };
pages: CbxPageInfo[] = [];
currentPage = 1;
bookmarks: BookMark[] = [];
notes: BookNoteV2[] = [];
notesSearchQuery = '';
ngOnInit(): void {
this.sidebarService.isOpen$
.pipe(takeUntil(this.destroy$))
.subscribe(isOpen => {
if (isOpen) {
this.isOpen = true;
this.closing = false;
} else if (this.isOpen) {
this.closeWithAnimation();
}
});
this.sidebarService.activeTab$
.pipe(takeUntil(this.destroy$))
.subscribe(tab => this.activeTab = tab);
this.sidebarService.bookInfo$
.pipe(takeUntil(this.destroy$))
.subscribe(info => this.bookInfo = info);
this.sidebarService.pages$
.pipe(takeUntil(this.destroy$))
.subscribe(pages => this.pages = pages);
this.sidebarService.currentPage$
.pipe(takeUntil(this.destroy$))
.subscribe(page => this.currentPage = page);
this.sidebarService.bookmarks$
.pipe(takeUntil(this.destroy$))
.subscribe(bookmarks => this.bookmarks = bookmarks);
this.sidebarService.notes$
.pipe(takeUntil(this.destroy$))
.subscribe(notes => this.notes = notes);
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
private closeWithAnimation(): void {
this.closing = true;
setTimeout(() => {
this.isOpen = false;
this.closing = false;
}, 250);
}
onOverlayClick(): void {
this.sidebarService.close();
}
setActiveTab(tab: CbxSidebarTab): void {
this.sidebarService.setActiveTab(tab);
}
onPageClick(pageNumber: number): void {
this.sidebarService.navigateToPage(pageNumber);
}
isPageActive(pageNumber: number): boolean {
return this.currentPage === pageNumber;
}
// Bookmark methods
onBookmarkClick(cfi: string): void {
this.sidebarService.navigateToBookmark(cfi);
}
onDeleteBookmark(event: MouseEvent, bookmarkId: number): void {
event.stopPropagation();
this.sidebarService.deleteBookmark(bookmarkId);
}
// Notes methods
onNoteClick(cfi: string): void {
this.sidebarService.navigateToNote(cfi);
}
onEditNote(event: MouseEvent, note: BookNoteV2): void {
event.stopPropagation();
this.sidebarService.editNote(note);
}
onDeleteNote(event: MouseEvent, noteId: number): void {
event.stopPropagation();
this.sidebarService.deleteNote(noteId);
}
onNotesSearchInput(query: string): void {
this.notesSearchQuery = query;
this.sidebarService.setNotesSearchQuery(query);
}
clearNotesSearch(): void {
this.notesSearchQuery = '';
this.sidebarService.setNotesSearchQuery('');
}
get filteredNotes(): BookNoteV2[] {
return this.sidebarService.getFilteredNotes();
}
}
@@ -0,0 +1,263 @@
import {inject, Injectable} from '@angular/core';
import {BehaviorSubject, Subject} from 'rxjs';
import {takeUntil} from 'rxjs/operators';
import {CbxReaderService, CbxPageInfo} from '../../../../book/service/cbx-reader.service';
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
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';
export interface SidebarBookInfo {
id: number | null;
title: string;
authors: string;
coverUrl: string | null;
}
export type CbxSidebarTab = 'pages' | 'bookmarks' | 'notes';
@Injectable()
export class CbxSidebarService {
private urlHelper = inject(UrlHelperService);
private cbxReaderService = inject(CbxReaderService);
private bookMarkService = inject(BookMarkService);
private bookNoteV2Service = inject(BookNoteV2Service);
private destroy$ = new Subject<void>();
private bookId!: number;
private _isOpen = new BehaviorSubject<boolean>(false);
private _activeTab = new BehaviorSubject<CbxSidebarTab>('pages');
private _bookInfo = new BehaviorSubject<SidebarBookInfo>({
id: null,
title: '',
authors: '',
coverUrl: null
});
private _pages = new BehaviorSubject<CbxPageInfo[]>([]);
private _currentPage = new BehaviorSubject<number>(1);
private _bookmarks = new BehaviorSubject<BookMark[]>([]);
private _notes = new BehaviorSubject<BookNoteV2[]>([]);
private _notesSearchQuery = new BehaviorSubject<string>('');
private _navigateToPage = new Subject<number>();
private _editNote = new Subject<BookNoteV2>();
private _bookmarksChanged = new Subject<void>();
isOpen$ = this._isOpen.asObservable();
activeTab$ = this._activeTab.asObservable();
bookInfo$ = this._bookInfo.asObservable();
pages$ = this._pages.asObservable();
currentPage$ = this._currentPage.asObservable();
bookmarks$ = this._bookmarks.asObservable();
notes$ = this._notes.asObservable();
navigateToPage$ = this._navigateToPage.asObservable();
editNote$ = this._editNote.asObservable();
bookmarksChanged$ = this._bookmarksChanged.asObservable();
get currentPage(): number {
return this._currentPage.value;
}
get activeTab(): CbxSidebarTab {
return this._activeTab.value;
}
initialize(bookId: number, book: Book, destroy$: Subject<void>): void {
this.bookId = bookId;
this.destroy$ = destroy$;
this._bookInfo.next({
id: book.id,
title: book.metadata?.title || book.fileName || 'Untitled',
authors: (book.metadata?.authors || []).join(', '),
coverUrl: this.urlHelper.getThumbnailUrl(book.id, book.metadata?.coverUpdatedOn)
});
this.loadPageInfo();
this.loadBookmarks();
this.loadNotes();
}
private loadPageInfo(): void {
this.cbxReaderService.getPageInfo(this.bookId)
.pipe(takeUntil(this.destroy$))
.subscribe(pages => this._pages.next(pages));
}
private loadBookmarks(): void {
this.bookMarkService.getBookmarksForBook(this.bookId)
.pipe(takeUntil(this.destroy$))
.subscribe(bookmarks => this._bookmarks.next(bookmarks));
}
private loadNotes(): void {
this.bookNoteV2Service.getNotesForBook(this.bookId)
.pipe(takeUntil(this.destroy$))
.subscribe(notes => this._notes.next(notes));
}
refreshNotes(): void {
this.loadNotes();
}
setCurrentPage(page: number): void {
this._currentPage.next(page);
}
setActiveTab(tab: CbxSidebarTab): void {
this._activeTab.next(tab);
}
open(tab?: CbxSidebarTab): void {
if (tab) {
this._activeTab.next(tab);
}
this._isOpen.next(true);
}
close(): void {
this._isOpen.next(false);
}
navigateToPage(pageNumber: number): void {
this._navigateToPage.next(pageNumber);
this.close();
}
// Bookmark methods - using page number as the location identifier (stored in cfi field)
isPageBookmarked(pageNumber: number): boolean {
const pageStr = pageNumber.toString();
return this._bookmarks.value.some(b => b.cfi === pageStr);
}
getBookmarkForPage(pageNumber: number): BookMark | undefined {
const pageStr = pageNumber.toString();
return this._bookmarks.value.find(b => b.cfi === pageStr);
}
createBookmark(pageNumber: number, title?: string): void {
const request: CreateBookMarkRequest = {
bookId: this.bookId,
cfi: pageNumber.toString(),
title: title || `Page ${pageNumber}`
};
this.bookMarkService.createBookmark(request)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.loadBookmarks();
this._bookmarksChanged.next();
});
}
deleteBookmark(bookmarkId: number): void {
this.bookMarkService.deleteBookmark(bookmarkId)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.loadBookmarks();
this._bookmarksChanged.next();
});
}
toggleBookmark(pageNumber: number): void {
const existingBookmark = this.getBookmarkForPage(pageNumber);
if (existingBookmark) {
this.deleteBookmark(existingBookmark.id);
} else {
this.createBookmark(pageNumber);
}
}
navigateToBookmark(pageNumber: string): void {
const page = parseInt(pageNumber, 10);
if (!isNaN(page)) {
this._navigateToPage.next(page);
this.close();
}
}
// Notes methods - using page number as the location identifier (stored in cfi field)
pageHasNotes(pageNumber: number): boolean {
const pageStr = pageNumber.toString();
return this._notes.value.some(n => n.cfi === pageStr);
}
getNotesForPage(pageNumber: number): BookNoteV2[] {
const pageStr = pageNumber.toString();
return this._notes.value.filter(n => n.cfi === pageStr);
}
createNote(pageNumber: number, noteContent: string, color?: string): void {
const request: CreateBookNoteV2Request = {
bookId: this.bookId,
cfi: pageNumber.toString(),
noteContent,
color: color || '#FFC107',
chapterTitle: `Page ${pageNumber}`
};
this.bookNoteV2Service.createNote(request)
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.loadNotes());
}
updateNote(noteId: number, noteContent: string, color?: string): void {
const request: UpdateBookNoteV2Request = {
noteContent,
color
};
this.bookNoteV2Service.updateNote(noteId, request)
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.loadNotes());
}
deleteNote(noteId: number): void {
this.bookNoteV2Service.deleteNote(noteId)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
const updatedNotes = this._notes.value.filter(n => n.id !== noteId);
this._notes.next(updatedNotes);
});
}
editNote(note: BookNoteV2): void {
this.close();
this._editNote.next(note);
}
navigateToNote(pageNumber: string): void {
const page = parseInt(pageNumber, 10);
if (!isNaN(page)) {
this._navigateToPage.next(page);
this.close();
}
}
setNotesSearchQuery(query: string): void {
this._notesSearchQuery.next(query);
}
getFilteredNotes(): BookNoteV2[] {
const query = this._notesSearchQuery.value.toLowerCase().trim();
if (!query) {
return this._notes.value;
}
return this._notes.value.filter(note =>
note.noteContent.toLowerCase().includes(query) ||
(note.chapterTitle?.toLowerCase().includes(query))
);
}
reset(): void {
this._isOpen.next(false);
this._activeTab.next('pages');
this._bookInfo.next({ id: null, title: '', authors: '', coverUrl: null });
this._pages.next([]);
this._currentPage.next(1);
this._bookmarks.next([]);
this._notes.next([]);
this._notesSearchQuery.next('');
}
}
@@ -9,6 +9,8 @@ export type ReaderIconName =
| 'chevron-down'
| 'chevron-first'
| 'chevron-last'
| 'chevron-double-left'
| 'chevron-double-right'
| 'dots-vertical'
| 'bookmark'
| 'settings'
@@ -19,7 +21,12 @@ export type ReaderIconName =
| 'search'
| 'note'
| 'plus'
| 'minus';
| 'minus'
| 'fit-page'
| 'fit-width'
| 'fit-height'
| 'actual-size'
| 'auto-fit';
interface IconPath {
d: string;
@@ -54,6 +61,14 @@ const ICONS: Record<ReaderIconName, IconPath[]> = {
{d: '13,17 18,12 13,7', type: 'polyline'},
{d: '6,17 11,12 6,7', type: 'polyline'}
],
'chevron-double-left': [
{d: '11,17 6,12 11,7', type: 'polyline'},
{d: '18,17 13,12 18,7', type: 'polyline'}
],
'chevron-double-right': [
{d: '13,17 18,12 13,7', type: 'polyline'},
{d: '6,17 11,12 6,7', type: 'polyline'}
],
'dots-vertical': [
{d: 'M12,12 m-1,0 a1,1 0 1,0 2,0 a1,1 0 1,0 -2,0', type: 'path'},
{d: 'M12,5 m-1,0 a1,1 0 1,0 2,0 a1,1 0 1,0 -2,0', type: 'path'},
@@ -102,6 +117,36 @@ const ICONS: Record<ReaderIconName, IconPath[]> = {
],
'minus': [
{d: 'M5,12 L19,12', type: 'line'}
],
// Fit mode icons
'fit-page': [
{d: 'M3 3h18v18H3V3z'},
{d: 'M7 7h10v10H7V7z'}
],
'fit-width': [
{d: 'M21,12 L17,8', type: 'line'},
{d: 'M21,12 L17,16', type: 'line'},
{d: 'M3,12 L7,8', type: 'line'},
{d: 'M3,12 L7,16', type: 'line'},
{d: 'M3,12 L21,12', type: 'line'}
],
'fit-height': [
{d: 'M12,3 L8,7', type: 'line'},
{d: 'M12,3 L16,7', type: 'line'},
{d: 'M12,21 L8,17', type: 'line'},
{d: 'M12,21 L16,17', type: 'line'},
{d: 'M12,3 L12,21', type: 'line'}
],
'actual-size': [
{d: 'M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z'},
{d: 'M9,8 L9,16', type: 'line'},
{d: 'M12,12 L12,16', type: 'line'},
{d: 'M15,8 L15,16', type: 'line'}
],
'auto-fit': [
{d: 'M12 3v3m0 12v3M3 12h3m12 0h3'},
{d: 'M12 12m-4 0a4 4 0 1 0 8 0a4 4 0 1 0-8 0', type: 'path'}
]
};