feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer (#306)
* feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer * feat(reader): improve reader settings with brightness, emulate book mode, and click-to-paginate options * feat(reader): add long strip scroll mode and update related settings
This commit is contained in:
@@ -1,133 +1,154 @@
|
||||
<div class="comic-reader-container" tabindex="0"
|
||||
[class.rtl-reading]="readingDirection === CbxReadingDirection.RTL"
|
||||
[class.fullscreen-mode]="isFullscreen"
|
||||
[class.slideshow-active]="isSlideshowActive">
|
||||
<app-cbx-header [isCurrentPageBookmarked]="isCurrentPageBookmarked" [currentPageHasNotes]="currentPageHasNotes"></app-cbx-header>
|
||||
<div class="comic-reader-container" tabindex="0" [class.rtl-reading]="readingDirection === CbxReadingDirection.RTL"
|
||||
[class.fullscreen-mode]="isFullscreen" [class.slideshow-active]="isSlideshowActive">
|
||||
<app-cbx-header [isCurrentPageBookmarked]="isCurrentPageBookmarked"
|
||||
[currentPageHasNotes]="currentPageHasNotes"></app-cbx-header>
|
||||
|
||||
<app-cbx-sidebar></app-cbx-sidebar>
|
||||
|
||||
@if (showQuickSettings) {
|
||||
<app-cbx-quick-settings></app-cbx-quick-settings>
|
||||
<app-cbx-quick-settings></app-cbx-quick-settings>
|
||||
}
|
||||
|
||||
@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="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>
|
||||
}
|
||||
|
||||
@if (showNoteDialog) {
|
||||
<app-cbx-note-dialog
|
||||
[data]="noteDialogData"
|
||||
(saved)="onNoteSave($event)"
|
||||
(cancelled)="onNoteCancel()"
|
||||
></app-cbx-note-dialog>
|
||||
<app-cbx-note-dialog [data]="noteDialogData" (saved)="onNoteSave($event)"
|
||||
(cancelled)="onNoteCancel()"></app-cbx-note-dialog>
|
||||
}
|
||||
|
||||
@if (showShortcutsHelp) {
|
||||
<app-cbx-shortcuts-help
|
||||
(closed)="onShortcutsHelpClose()"
|
||||
></app-cbx-shortcuts-help>
|
||||
<app-cbx-shortcuts-help (closed)="onShortcutsHelpClose()"></app-cbx-shortcuts-help>
|
||||
}
|
||||
|
||||
@if (isSlideshowActive) {
|
||||
<div class="slideshow-progress" [class.above-footer]="isFooterVisible" [style.animation-duration.ms]="slideshowInterval"></div>
|
||||
<div class="slideshow-progress" [class.above-footer]="isFooterVisible"
|
||||
[style.animation-duration.ms]="slideshowInterval"></div>
|
||||
}
|
||||
|
||||
<div #magnifierLens class="magnifier-lens"></div>
|
||||
|
||||
<div class="image-container"
|
||||
[class.magnifier-active]="isMagnifierActive"
|
||||
<div class="image-container" [class.magnifier-active]="isMagnifierActive"
|
||||
[class.two-page-view]="isTwoPageView && scrollMode === CbxScrollMode.PAGINATED"
|
||||
[class.infinite-scroll]="scrollMode === CbxScrollMode.INFINITE"
|
||||
[class.long-strip]="scrollMode === CbxScrollMode.LONG_STRIP"
|
||||
[class.fit-actual-size]="fitMode === CbxFitMode.ACTUAL_SIZE"
|
||||
[class.fit-page]="fitMode === CbxFitMode.FIT_PAGE"
|
||||
[class.fit-width]="fitMode === CbxFitMode.FIT_WIDTH"
|
||||
[class.fit-height]="fitMode === CbxFitMode.FIT_HEIGHT"
|
||||
[class.fit-auto]="fitMode === CbxFitMode.AUTO"
|
||||
[class.bg-black]="backgroundColor === CbxBackgroundColor.BLACK"
|
||||
[class.fit-actual-size]="fitMode === CbxFitMode.ACTUAL_SIZE" [class.fit-page]="fitMode === CbxFitMode.FIT_PAGE"
|
||||
[class.fit-width]="fitMode === CbxFitMode.FIT_WIDTH" [class.fit-height]="fitMode === CbxFitMode.FIT_HEIGHT"
|
||||
[class.fit-auto]="fitMode === CbxFitMode.AUTO" [class.bg-black]="backgroundColor === CbxBackgroundColor.BLACK"
|
||||
[class.bg-gray]="backgroundColor === CbxBackgroundColor.GRAY"
|
||||
[class.bg-white]="backgroundColor === CbxBackgroundColor.WHITE"
|
||||
(scroll)="onScroll($event)">
|
||||
[class.bg-white]="backgroundColor === CbxBackgroundColor.WHITE" [class.emulate-book]="emulateBook && isTwoPageView"
|
||||
[style.filter]="brightness < 100 ? 'brightness(' + brightness + '%)' : null" (scroll)="onScroll($event)">
|
||||
@if (!isLoading) {
|
||||
@if (pages.length > 0) {
|
||||
@if (scrollMode === CbxScrollMode.PAGINATED) {
|
||||
<div
|
||||
class="pages-wrapper"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="onImageClick()"
|
||||
(keydown.enter)="onImageClick()"
|
||||
(dblclick)="onImageDoubleClick()">
|
||||
@if (isPageTransitioning && previousImageUrls.length > 0) {
|
||||
<div class="previous-page-layer">
|
||||
@for (url of previousImageUrls; track url) {
|
||||
<img [src]="url" alt="Previous Page" class="page-image previous-image"/>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<div class="current-page-layer" [class.fade-in]="isPageTransitioning && imagesLoaded">
|
||||
@for (url of currentImageUrls; track url; let i = $index) {
|
||||
<img [src]="url" alt="Page Image" class="page-image" (load)="onPageImageLoad($event, currentPage + i)"/>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (isAtLastPage && nextBookInSeries) {
|
||||
<div class="end-of-comic-action">
|
||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||
<span class="action-icon">📖</span>
|
||||
<span class="action-text">{{ 'readerCbx.reader.continueToNextBook' | transloco }}</span>
|
||||
<span class="book-title">{{ getBookDisplayTitle(nextBookInSeries) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="infinite-scroll-wrapper" [class.long-strip-wrapper]="scrollMode === CbxScrollMode.LONG_STRIP">
|
||||
@for (pageIdx of infiniteScrollPages; track pageIdx; let i = $index) {
|
||||
<img
|
||||
[src]="getPageImageUrl(pageIdx)"
|
||||
alt="Page {{ pageIdx + 1 }}"
|
||||
class="page-image"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
(click)="onImageClick()"
|
||||
(keydown.enter)="onImageClick()"
|
||||
(dblclick)="onImageDoubleClick()"
|
||||
(load)="onPageImageLoad($event, pageIdx)"/>
|
||||
}
|
||||
@if (isLoadingMore) {
|
||||
<div class="loading-more">
|
||||
<p-progressSpinner class="small-spinner"></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
@if (infiniteScrollPages.length > 0 && infiniteScrollPages[infiniteScrollPages.length - 1] >= pages.length - 1 && nextBookInSeries) {
|
||||
<div class="end-of-comic-action">
|
||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||
<span class="action-icon">📖</span>
|
||||
<span class="action-text">{{ 'readerCbx.reader.continueToNextBook' | transloco }}</span>
|
||||
<span class="book-title">{{ getBookDisplayTitle(nextBookInSeries) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (pages.length > 0) {
|
||||
@if (scrollMode === CbxScrollMode.PAGINATED) {
|
||||
<div class="pages-wrapper" role="button" tabindex="0" (click)="onImageClick()" (keydown.enter)="onImageClick()"
|
||||
(dblclick)="onImageDoubleClick()">
|
||||
@if (isPageTransitioning && previousImageUrls.length > 0) {
|
||||
<div class="previous-page-layer">
|
||||
@for (url of previousImageUrls; track url) {
|
||||
<img [src]="url" alt="Previous Page" class="page-image previous-image" />
|
||||
}
|
||||
} @else {
|
||||
<div class="no-pages">
|
||||
<p>{{ 'readerCbx.reader.noPagesAvailable' | transloco }}</p>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="loader-overlay">
|
||||
<div class="loader-content">
|
||||
<div class="spinner"></div>
|
||||
<p class="loader-text">{{ 'readerCbx.reader.loadingBook' | transloco }}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="current-page-layer" [class.fade-in]="isPageTransitioning && imagesLoaded">
|
||||
@if (shouldUseCanvasRenderer()) {
|
||||
<app-canvas-renderer [imageUrl]="currentImageUrls[0]" [splitState]="canvasSplitState"
|
||||
[splitOption]="pageSplitOption">
|
||||
</app-canvas-renderer>
|
||||
} @else {
|
||||
@for (url of currentImageUrls; track url; let i = $index) {
|
||||
<img [src]="url" alt="Page Image" class="page-image" (load)="onPageImageLoad($event, currentPage + i)" />
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@if (isAtLastPage && nextBookInSeries) {
|
||||
<div class="end-of-comic-action">
|
||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||
<span class="action-icon">📖</span>
|
||||
<span class="action-text">{{ 'readerCbx.reader.continueToNextBook' | transloco }}</span>
|
||||
<span class="book-title">{{ getBookDisplayTitle(nextBookInSeries) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
} @else if (scrollMode === CbxScrollMode.LONG_STRIP) {
|
||||
<div class="long-strip-wrapper" role="button" tabindex="0" (click)="onImageClick()"
|
||||
(keydown.enter)="onImageClick()">
|
||||
@for (item of longStripImages; track item.page) {
|
||||
<img [src]="item.src" alt="Page {{ item.page + 1 }}" class="long-strip-image" [attr.data-page]="item.page"
|
||||
(load)="onLongStripImageLoad($event, item.page)" />
|
||||
}
|
||||
@if (longStripImages.length > 0 && longStripImages[longStripImages.length - 1].page >= pages.length - 1 &&
|
||||
nextBookInSeries) {
|
||||
<div class="end-of-comic-action">
|
||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||
<span class="action-icon">📖</span>
|
||||
<span class="action-text">{{ 'readerCbx.reader.continueToNextBook' | transloco }}</span>
|
||||
<span class="book-title">{{ getBookDisplayTitle(nextBookInSeries) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
} @else {
|
||||
<div class="infinite-scroll-wrapper">
|
||||
@for (pageIdx of infiniteScrollPages; track pageIdx; let i = $index) {
|
||||
<img [src]="getPageImageUrl(pageIdx)" alt="Page {{ pageIdx + 1 }}" class="page-image" role="button" tabindex="0"
|
||||
(click)="onImageClick()" (keydown.enter)="onImageClick()" (dblclick)="onImageDoubleClick()"
|
||||
(load)="onPageImageLoad($event, pageIdx)" />
|
||||
}
|
||||
@if (isLoadingMore) {
|
||||
<div class="loading-more">
|
||||
<p-progressSpinner class="small-spinner"></p-progressSpinner>
|
||||
</div>
|
||||
}
|
||||
@if (infiniteScrollPages.length > 0 && infiniteScrollPages[infiniteScrollPages.length - 1] >= pages.length - 1 &&
|
||||
nextBookInSeries) {
|
||||
<div class="end-of-comic-action">
|
||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||
<span class="action-icon">📖</span>
|
||||
<span class="action-text">{{ 'readerCbx.reader.continueToNextBook' | transloco }}</span>
|
||||
<span class="book-title">{{ getBookDisplayTitle(nextBookInSeries) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (clickToPaginate) {
|
||||
<div class="click-overlay visible" [class.rtl-overlay]="readingDirection === CbxReadingDirection.RTL"
|
||||
[class.magnifier-disabled]="isMagnifierActive">
|
||||
<div class="click-zone click-zone-prev" role="button" tabindex="0" (click)="onClickZonePrev($event)"
|
||||
(keydown.enter)="onClickZonePrev($event)">
|
||||
<span class="zone-arrow">◀</span>
|
||||
</div>
|
||||
<div class="click-zone click-zone-menu" role="button" tabindex="0" (click)="onClickZoneMenu($event)"
|
||||
(keydown.enter)="onClickZoneMenu($event)">
|
||||
</div>
|
||||
<div class="click-zone click-zone-next" role="button" tabindex="0" (click)="onClickZoneNext($event)"
|
||||
(keydown.enter)="onClickZoneNext($event)">
|
||||
<span class="zone-arrow">▶</span>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="no-pages">
|
||||
<p>{{ 'readerCbx.reader.noPagesAvailable' | transloco }}</p>
|
||||
</div>
|
||||
}
|
||||
} @else {
|
||||
<div class="loader-overlay">
|
||||
<div class="loader-content">
|
||||
<div class="spinner"></div>
|
||||
<p class="loader-text">{{ 'readerCbx.reader.loadingBook' | transloco }}</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<app-cbx-footer></app-cbx-footer>
|
||||
</div>
|
||||
</div>
|
||||
@@ -19,6 +19,7 @@
|
||||
// RTL reading mode - reverse page order in two-page view
|
||||
&.rtl-reading {
|
||||
.two-page-view {
|
||||
|
||||
.pages-wrapper,
|
||||
.previous-page-layer,
|
||||
.current-page-layer {
|
||||
@@ -45,8 +46,13 @@
|
||||
}
|
||||
|
||||
@keyframes slideshow-fill {
|
||||
from { width: 0; }
|
||||
to { width: 100%; }
|
||||
from {
|
||||
width: 0;
|
||||
}
|
||||
|
||||
to {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.magnifier-lens {
|
||||
@@ -184,6 +190,7 @@
|
||||
}
|
||||
|
||||
&.fit-width {
|
||||
|
||||
.pages-wrapper,
|
||||
.previous-page-layer,
|
||||
.current-page-layer {
|
||||
@@ -201,6 +208,7 @@
|
||||
}
|
||||
|
||||
&.two-page-view {
|
||||
|
||||
.pages-wrapper,
|
||||
.previous-page-layer,
|
||||
.current-page-layer {
|
||||
@@ -217,6 +225,7 @@
|
||||
}
|
||||
|
||||
&.fit-height {
|
||||
|
||||
.pages-wrapper,
|
||||
.previous-page-layer,
|
||||
.current-page-layer {
|
||||
@@ -401,70 +410,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Long Strip / Webtoon mode - no gaps between pages
|
||||
// Long-strip (webtoon) mode — gapless vertical strip, always fit-width
|
||||
&.long-strip {
|
||||
overflow: hidden auto;
|
||||
align-items: flex-start;
|
||||
touch-action: pan-y;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
overscroll-behavior: contain;
|
||||
|
||||
.long-strip-wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 0;
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
|
||||
// No gap, no padding — gapless vertical strip
|
||||
}
|
||||
|
||||
.page-image {
|
||||
box-shadow: none;
|
||||
border-radius: 0;
|
||||
transition: none;
|
||||
.long-strip-image {
|
||||
display: block;
|
||||
|
||||
&:hover {
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.fit-width .page-image {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
&.fit-height .page-image {
|
||||
width: auto;
|
||||
height: auto;
|
||||
max-width: 100%;
|
||||
}
|
||||
border: 0;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
&.fit-actual-size {
|
||||
overflow-x: auto;
|
||||
|
||||
.long-strip-wrapper {
|
||||
width: max-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.page-image {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
}
|
||||
|
||||
&.fit-page .page-image,
|
||||
&.fit-auto .page-image {
|
||||
max-width: 100%;
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.loading-more {
|
||||
padding: 2rem;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
// Hardware acceleration (Kavita pattern)
|
||||
transform: translate3d(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -550,7 +522,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 768px) {
|
||||
@media (width <=768px) {
|
||||
.comic-reader-container {
|
||||
.slideshow-progress.above-footer {
|
||||
bottom: 48px;
|
||||
@@ -568,8 +540,13 @@
|
||||
min-width: 240px;
|
||||
padding: 1.5rem 2rem;
|
||||
|
||||
.action-icon { font-size: 2rem; }
|
||||
.action-text { font-size: 1rem; }
|
||||
.action-icon {
|
||||
font-size: 2rem;
|
||||
}
|
||||
|
||||
.action-text {
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.book-title {
|
||||
font-size: 0.85rem;
|
||||
@@ -618,3 +595,90 @@
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
// Click-to-paginate overlay
|
||||
.click-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 5;
|
||||
display: flex;
|
||||
pointer-events: none;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
|
||||
&.visible {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.click-zone {
|
||||
pointer-events: auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.click-zone-prev {
|
||||
width: 40%;
|
||||
background: rgb(255 255 255 / 3%);
|
||||
}
|
||||
|
||||
.click-zone-menu {
|
||||
width: 20%;
|
||||
}
|
||||
|
||||
.click-zone-next {
|
||||
width: 40%;
|
||||
background: rgb(255 255 255 / 3%);
|
||||
}
|
||||
|
||||
.zone-arrow {
|
||||
font-size: 2rem;
|
||||
color: rgb(255 255 255 / 30%);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
&.visible .zone-arrow {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
// RTL: swap prev/next zones visually
|
||||
&.rtl-overlay {
|
||||
flex-direction: row-reverse;
|
||||
}
|
||||
|
||||
// Disable pointer events when magnifier is active so elementFromPoint can reach images
|
||||
&.magnifier-disabled {
|
||||
pointer-events: none;
|
||||
|
||||
.click-zone {
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Emulate book mode spine shadow in two-page view
|
||||
.image-container.emulate-book {
|
||||
|
||||
.pages-wrapper,
|
||||
.current-page-layer {
|
||||
position: relative;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
width: 0;
|
||||
z-index: 2;
|
||||
pointer-events: none;
|
||||
box-shadow:
|
||||
-4px 0 12px rgb(0 0 0 / 40%),
|
||||
4px 0 12px rgb(0 0 0 / 40%),
|
||||
-2px 0 6px rgb(0 0 0 / 20%),
|
||||
2px 0 6px rgb(0 0 0 / 20%);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,188 @@
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {Observable, of, tap} from 'rxjs';
|
||||
import {API_CONFIG} from '../../../../core/config/api-config';
|
||||
import {AuthService} from '../../../../shared/service/auth.service';
|
||||
import {CbxPageDimension} from '../models/cbx-page-dimension.model';
|
||||
|
||||
export type DoublePairs = Record<number, number>;
|
||||
|
||||
export interface WebtoonDetectionResult {
|
||||
isWebtoon: boolean;
|
||||
score: number;
|
||||
}
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class CbxPageDimensionService {
|
||||
|
||||
private readonly baseUrl = `${API_CONFIG.BASE_URL}/api/v1/cbx`;
|
||||
private http = inject(HttpClient);
|
||||
private authService = inject(AuthService);
|
||||
|
||||
private dimensionCache = new Map<string, CbxPageDimension[]>();
|
||||
|
||||
private getToken(): string | null {
|
||||
return this.authService.getInternalAccessToken();
|
||||
}
|
||||
|
||||
private appendToken(url: string): string {
|
||||
const token = this.getToken();
|
||||
return token ? `${url}${url.includes('?') ? '&' : '?'}token=${token}` : url;
|
||||
}
|
||||
|
||||
getPageDimensions(bookId: number, bookType?: string): Observable<CbxPageDimension[]> {
|
||||
const cacheKey = `${bookId}-${bookType ?? 'default'}`;
|
||||
const cached = this.dimensionCache.get(cacheKey);
|
||||
if (cached) {
|
||||
return of(cached);
|
||||
}
|
||||
let url = `${this.baseUrl}/${bookId}/page-dimensions`;
|
||||
if (bookType) {
|
||||
url += `?bookType=${bookType}`;
|
||||
}
|
||||
return this.http.get<CbxPageDimension[]>(this.appendToken(url)).pipe(
|
||||
tap(dims => this.dimensionCache.set(cacheKey, dims))
|
||||
);
|
||||
}
|
||||
|
||||
clearCache(bookId?: number): void {
|
||||
if (bookId !== undefined) {
|
||||
for (const key of this.dimensionCache.keys()) {
|
||||
if (key.startsWith(`${bookId}-`)) {
|
||||
this.dimensionCache.delete(key);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.dimensionCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute double-page pair map from dimensions.
|
||||
* Cover (page index 0) is always solo. Wide pages are always solo.
|
||||
* Returns a map of pageIndex → paired pageIndex for the right-hand page.
|
||||
*/
|
||||
computeDoublePairs(dimensions: CbxPageDimension[]): DoublePairs {
|
||||
const pairs: DoublePairs = {};
|
||||
let i = 1; // Skip cover (index 0), it's always solo
|
||||
while (i < dimensions.length) {
|
||||
const current = dimensions[i];
|
||||
const next = i + 1 < dimensions.length ? dimensions[i + 1] : null;
|
||||
|
||||
if (current.wide) {
|
||||
// Wide page is always solo
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (next && !next.wide) {
|
||||
// Pair these two non-wide pages
|
||||
pairs[i] = i + 1;
|
||||
i += 2;
|
||||
} else {
|
||||
// Next is wide or doesn't exist — current is solo
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if the content is webtoon-style (long vertical strips).
|
||||
*
|
||||
* Scoring per page:
|
||||
* - Aspect ratio (h/w) ≥ 2.2: +1.0 (strong webtoon indicator)
|
||||
* - Aspect ratio 1.8–2.2: +0.5
|
||||
* - Aspect ratio 1.5–1.8: +0.2
|
||||
* - Aspect ratio < 1.2: −0.5 (penalize square/landscape)
|
||||
* - Width ≤ 750px: +0.2
|
||||
* - Height > 2000px: +0.5 (or > 1500px: +0.3)
|
||||
* - Area > 1,500,000 px²: +0.3
|
||||
*
|
||||
* Final decision: avgScore ≥ 0.7 AND one of:
|
||||
* - 40%+ pages have ratio ≥ 2.2
|
||||
* - Average ratio ≥ 2.0
|
||||
* - Width variation < 15% AND average ratio > 1.8
|
||||
*/
|
||||
detectWebtoon(dimensions: CbxPageDimension[]): WebtoonDetectionResult {
|
||||
if (dimensions.length < 3) {
|
||||
return {isWebtoon: false, score: 0};
|
||||
}
|
||||
|
||||
let totalScore = 0;
|
||||
let highRatioCount = 0;
|
||||
let totalRatio = 0;
|
||||
const widths: number[] = [];
|
||||
|
||||
for (const dim of dimensions) {
|
||||
if (dim.width === 0 || dim.height === 0) continue;
|
||||
|
||||
const ratio = dim.height / dim.width;
|
||||
totalRatio += ratio;
|
||||
widths.push(dim.width);
|
||||
|
||||
let pageScore = 0;
|
||||
|
||||
// Aspect ratio scoring
|
||||
if (ratio >= 2.2) {
|
||||
pageScore += 1.0;
|
||||
highRatioCount++;
|
||||
} else if (ratio >= 1.8) {
|
||||
pageScore += 0.5;
|
||||
} else if (ratio >= 1.5) {
|
||||
pageScore += 0.2;
|
||||
} else if (ratio < 1.2) {
|
||||
pageScore -= 0.5;
|
||||
}
|
||||
|
||||
// Narrow width bonus
|
||||
if (dim.width <= 750) {
|
||||
pageScore += 0.2;
|
||||
}
|
||||
|
||||
// Tall page bonus
|
||||
if (dim.height > 2000) {
|
||||
pageScore += 0.5;
|
||||
} else if (dim.height > 1500) {
|
||||
pageScore += 0.3;
|
||||
}
|
||||
|
||||
// Large area bonus
|
||||
if (dim.width * dim.height > 1_500_000) {
|
||||
pageScore += 0.3;
|
||||
}
|
||||
|
||||
totalScore += pageScore;
|
||||
}
|
||||
|
||||
const validCount = widths.length;
|
||||
if (validCount < 3) {
|
||||
return {isWebtoon: false, score: 0};
|
||||
}
|
||||
|
||||
const avgScore = totalScore / validCount;
|
||||
const avgRatio = totalRatio / validCount;
|
||||
const avgWidth = widths.reduce((a, b) => a + b, 0) / validCount;
|
||||
const widthStdDev = Math.sqrt(
|
||||
widths.reduce((sum, w) => sum + Math.pow(w - avgWidth, 2), 0) / validCount
|
||||
);
|
||||
const widthVariation = avgWidth > 0 ? widthStdDev / avgWidth : 1;
|
||||
|
||||
// Reject traditional comics with small, square-ish pages
|
||||
const avgHeight = dimensions
|
||||
.filter(d => d.height > 0)
|
||||
.reduce((sum, d) => sum + d.height, 0) / validCount;
|
||||
if (avgHeight < 1200 && avgRatio < 1.7 && avgWidth < 700) {
|
||||
return {isWebtoon: false, score: avgScore};
|
||||
}
|
||||
|
||||
const highRatioPercent = highRatioCount / validCount;
|
||||
const isWebtoon = avgScore >= 0.7 && (
|
||||
highRatioPercent >= 0.4 ||
|
||||
avgRatio >= 2.0 ||
|
||||
(widthVariation < 0.15 && avgRatio > 1.8)
|
||||
);
|
||||
|
||||
return {isWebtoon, score: avgScore};
|
||||
}
|
||||
}
|
||||
+99
-63
@@ -1,5 +1,7 @@
|
||||
<div class="quick-settings-overlay" role="button" tabindex="0" (click)="onOverlayClick()" (keydown.enter)="onOverlayClick()">
|
||||
<div class="quick-settings-panel" tabindex="0" (click)="$event.stopPropagation()" (keydown.enter)="$event.stopPropagation()">
|
||||
<div class="quick-settings-overlay" role="button" tabindex="0" (click)="onOverlayClick()"
|
||||
(keydown.enter)="onOverlayClick()">
|
||||
<div class="quick-settings-panel" tabindex="0" (click)="$event.stopPropagation()"
|
||||
(keydown.enter)="$event.stopPropagation()">
|
||||
<div class="pointer"></div>
|
||||
<div class="panel-body">
|
||||
<!-- Fit Mode -->
|
||||
@@ -8,13 +10,10 @@
|
||||
<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>
|
||||
<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>
|
||||
@@ -26,13 +25,10 @@
|
||||
<div class="control-right">
|
||||
<div class="button-group text-btns">
|
||||
@for (option of scrollModeOptions; track option.value) {
|
||||
<button
|
||||
class="option-btn text-btn"
|
||||
[class.active]="state().scrollMode === option.value"
|
||||
(click)="onScrollModeSelect(option.value)"
|
||||
[title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
<button class="option-btn text-btn" [class.active]="state().scrollMode === option.value"
|
||||
(click)="onScrollModeSelect(option.value)" [title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -40,36 +36,42 @@
|
||||
|
||||
<!-- Page View (only in paginated mode) -->
|
||||
@if (isPaginated && !isPhonePortrait) {
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.pageView' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ isTwoPageView ? ('readerCbx.quickSettings.twoPage' | transloco) : ('readerCbx.quickSettings.single' | transloco) }}</span>
|
||||
<button class="switch" [class.active]="isTwoPageView" (click)="onPageViewToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.pageView' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ isTwoPageView ? ('readerCbx.quickSettings.twoPage' | transloco) :
|
||||
('readerCbx.quickSettings.single' | transloco) }}</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">
|
||||
<span>{{ 'readerCbx.quickSettings.pageSpread' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().pageSpread === CbxPageSpread.ODD ? ('readerCbx.quickSettings.oddFirst' | transloco) : ('readerCbx.quickSettings.evenFirst' | transloco) }}</span>
|
||||
<button class="switch" [class.active]="state().pageSpread === CbxPageSpread.EVEN" (click)="onPageSpreadToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.pageSpread' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().pageSpread === CbxPageSpread.ODD ? ('readerCbx.quickSettings.oddFirst' |
|
||||
transloco) : ('readerCbx.quickSettings.evenFirst' | transloco) }}</span>
|
||||
<button class="switch" [class.active]="state().pageSpread === CbxPageSpread.EVEN"
|
||||
(click)="onPageSpreadToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Reading Direction -->
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.readingDirection' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().readingDirection === CbxReadingDirection.LTR ? ('readerCbx.quickSettings.leftToRight' | transloco) : ('readerCbx.quickSettings.rightToLeft' | transloco) }}</span>
|
||||
<button class="switch" [class.active]="state().readingDirection === CbxReadingDirection.RTL" (click)="onReadingDirectionToggle()">
|
||||
<span class="mode-label">{{ state().readingDirection === CbxReadingDirection.LTR ?
|
||||
('readerCbx.quickSettings.leftToRight' | transloco) : ('readerCbx.quickSettings.rightToLeft' | transloco)
|
||||
}}</span>
|
||||
<button class="switch" [class.active]="state().readingDirection === CbxReadingDirection.RTL"
|
||||
(click)="onReadingDirectionToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
@@ -81,13 +83,10 @@
|
||||
<div class="control-right">
|
||||
<div class="button-group text-btns">
|
||||
@for (option of slideshowIntervalOptions; track option.value) {
|
||||
<button
|
||||
class="option-btn text-btn small"
|
||||
[class.active]="state().slideshowInterval === option.value"
|
||||
(click)="onSlideshowIntervalSelect(option.value)"
|
||||
[title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
<button class="option-btn text-btn small" [class.active]="state().slideshowInterval === option.value"
|
||||
(click)="onSlideshowIntervalSelect(option.value)" [title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -99,13 +98,10 @@
|
||||
<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>
|
||||
<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>
|
||||
@@ -117,13 +113,10 @@
|
||||
<div class="control-right">
|
||||
<div class="button-group text-btns">
|
||||
@for (option of magnifierLensSizeOptions; track option.value) {
|
||||
<button
|
||||
class="option-btn text-btn small"
|
||||
[class.active]="state().magnifierLensSize === option.value"
|
||||
(click)="onMagnifierLensSizeSelect(option.value)"
|
||||
[title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
<button class="option-btn text-btn small" [class.active]="state().magnifierLensSize === option.value"
|
||||
(click)="onMagnifierLensSizeSelect(option.value)" [title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
@@ -135,17 +128,60 @@
|
||||
<div class="control-right">
|
||||
<div class="button-group text-btns">
|
||||
@for (option of magnifierZoomOptions; track option.value) {
|
||||
<button
|
||||
class="option-btn text-btn small"
|
||||
[class.active]="state().magnifierZoom === option.value"
|
||||
(click)="onMagnifierZoomSelect(option.value)"
|
||||
[title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
<button class="option-btn text-btn small" [class.active]="state().magnifierZoom === option.value"
|
||||
(click)="onMagnifierZoomSelect(option.value)" [title]="option.label">
|
||||
{{ option.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Brightness -->
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.brightness' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<input type="range" min="10" max="100" step="5" [value]="state().brightness"
|
||||
(input)="onBrightnessChange($event)" class="brightness-slider" />
|
||||
<span class="brightness-value">{{ state().brightness }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Emulate Book -->
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.emulateBook' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().emulateBook ? ('common.on' | transloco) : ('common.off' | transloco)
|
||||
}}</span>
|
||||
<button class="switch" [class.active]="state().emulateBook" (click)="onEmulateBookToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Click to Paginate -->
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.clickToPaginate' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().clickToPaginate ? ('common.on' | transloco) : ('common.off' | transloco)
|
||||
}}</span>
|
||||
<button class="switch" [class.active]="state().clickToPaginate" (click)="onClickToPaginateToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auto Close Menu -->
|
||||
<div class="control">
|
||||
<span>{{ 'readerCbx.quickSettings.autoCloseMenu' | transloco }}</span>
|
||||
<div class="control-right">
|
||||
<span class="mode-label">{{ state().autoCloseMenu ? ('common.on' | transloco) : ('common.off' | transloco)
|
||||
}}</span>
|
||||
<button class="switch" [class.active]="state().autoCloseMenu" (click)="onAutoCloseMenuToggle()">
|
||||
<span class="slider"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+52
-39
@@ -1,6 +1,6 @@
|
||||
import {Component, inject} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {TranslocoService, TranslocoPipe} from '@jsverse/transloco';
|
||||
import { Component, inject } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TranslocoService, TranslocoPipe } from '@jsverse/transloco';
|
||||
import {
|
||||
CbxFitMode,
|
||||
CbxScrollMode,
|
||||
@@ -12,8 +12,8 @@ import {
|
||||
CbxMagnifierZoom,
|
||||
CbxMagnifierLensSize
|
||||
} from '../../../../settings/user-management/user.service';
|
||||
import {ReaderIconComponent, ReaderIconName} from '../../../ebook-reader/shared/icon.component';
|
||||
import {CbxQuickSettingsService} from './cbx-quick-settings.service';
|
||||
import { ReaderIconComponent, ReaderIconName } from '../../../ebook-reader/shared/icon.component';
|
||||
import { CbxQuickSettingsService } from './cbx-quick-settings.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-quick-settings',
|
||||
@@ -38,52 +38,52 @@ export class CbxQuickSettingsComponent {
|
||||
protected readonly CbxMagnifierZoom = CbxMagnifierZoom;
|
||||
protected readonly CbxMagnifierLensSize = CbxMagnifierLensSize;
|
||||
|
||||
get fitModeOptions(): {value: CbxFitMode, label: string, icon: ReaderIconName}[] {
|
||||
get fitModeOptions(): { value: CbxFitMode, label: string, icon: ReaderIconName }[] {
|
||||
return [
|
||||
{value: CbxFitMode.FIT_PAGE, label: this.t.translate('readerCbx.quickSettings.fitPage'), icon: 'fit-page'},
|
||||
{value: CbxFitMode.FIT_WIDTH, label: this.t.translate('readerCbx.quickSettings.fitWidth'), icon: 'fit-width'},
|
||||
{value: CbxFitMode.FIT_HEIGHT, label: this.t.translate('readerCbx.quickSettings.fitHeight'), icon: 'fit-height'},
|
||||
{value: CbxFitMode.ACTUAL_SIZE, label: this.t.translate('readerCbx.quickSettings.actualSize'), icon: 'actual-size'},
|
||||
{value: CbxFitMode.AUTO, label: this.t.translate('readerCbx.quickSettings.automatic'), icon: 'auto-fit'}
|
||||
{ value: CbxFitMode.FIT_PAGE, label: this.t.translate('readerCbx.quickSettings.fitPage'), icon: 'fit-page' },
|
||||
{ value: CbxFitMode.FIT_WIDTH, label: this.t.translate('readerCbx.quickSettings.fitWidth'), icon: 'fit-width' },
|
||||
{ value: CbxFitMode.FIT_HEIGHT, label: this.t.translate('readerCbx.quickSettings.fitHeight'), icon: 'fit-height' },
|
||||
{ value: CbxFitMode.ACTUAL_SIZE, label: this.t.translate('readerCbx.quickSettings.actualSize'), icon: 'actual-size' },
|
||||
{ value: CbxFitMode.AUTO, label: this.t.translate('readerCbx.quickSettings.automatic'), icon: 'auto-fit' }
|
||||
];
|
||||
}
|
||||
|
||||
get scrollModeOptions(): {value: CbxScrollMode, label: string}[] {
|
||||
get scrollModeOptions(): { value: CbxScrollMode, label: string }[] {
|
||||
return [
|
||||
{value: CbxScrollMode.PAGINATED, label: this.t.translate('readerCbx.quickSettings.paginated')},
|
||||
{value: CbxScrollMode.INFINITE, label: this.t.translate('readerCbx.quickSettings.infinite')},
|
||||
{value: CbxScrollMode.LONG_STRIP, label: this.t.translate('readerCbx.quickSettings.longStrip')}
|
||||
{ value: CbxScrollMode.PAGINATED, label: this.t.translate('readerCbx.quickSettings.paginated') },
|
||||
{ value: CbxScrollMode.INFINITE, label: this.t.translate('readerCbx.quickSettings.infinite') }
|
||||
// { value: CbxScrollMode.LONG_STRIP, label: this.t.translate('readerCbx.quickSettings.longStrip') }
|
||||
];
|
||||
}
|
||||
|
||||
slideshowIntervalOptions: {value: CbxSlideshowInterval, label: string}[] = [
|
||||
{value: CbxSlideshowInterval.THREE_SECONDS, label: '3s'},
|
||||
{value: CbxSlideshowInterval.FIVE_SECONDS, label: '5s'},
|
||||
{value: CbxSlideshowInterval.TEN_SECONDS, label: '10s'},
|
||||
{value: CbxSlideshowInterval.FIFTEEN_SECONDS, label: '15s'},
|
||||
{value: CbxSlideshowInterval.THIRTY_SECONDS, label: '30s'}
|
||||
slideshowIntervalOptions: { value: CbxSlideshowInterval, label: string }[] = [
|
||||
{ value: CbxSlideshowInterval.THREE_SECONDS, label: '3s' },
|
||||
{ value: CbxSlideshowInterval.FIVE_SECONDS, label: '5s' },
|
||||
{ value: CbxSlideshowInterval.TEN_SECONDS, label: '10s' },
|
||||
{ value: CbxSlideshowInterval.FIFTEEN_SECONDS, label: '15s' },
|
||||
{ value: CbxSlideshowInterval.THIRTY_SECONDS, label: '30s' }
|
||||
];
|
||||
|
||||
magnifierZoomOptions: {value: CbxMagnifierZoom, label: string}[] = [
|
||||
{value: CbxMagnifierZoom.ZOOM_1_5X, label: '1.5×'},
|
||||
{value: CbxMagnifierZoom.ZOOM_2X, label: '2×'},
|
||||
{value: CbxMagnifierZoom.ZOOM_2_5X, label: '2.5×'},
|
||||
{value: CbxMagnifierZoom.ZOOM_3X, label: '3×'},
|
||||
{value: CbxMagnifierZoom.ZOOM_4X, label: '4×'}
|
||||
magnifierZoomOptions: { value: CbxMagnifierZoom, label: string }[] = [
|
||||
{ value: CbxMagnifierZoom.ZOOM_1_5X, label: '1.5×' },
|
||||
{ value: CbxMagnifierZoom.ZOOM_2X, label: '2×' },
|
||||
{ value: CbxMagnifierZoom.ZOOM_2_5X, label: '2.5×' },
|
||||
{ value: CbxMagnifierZoom.ZOOM_3X, label: '3×' },
|
||||
{ value: CbxMagnifierZoom.ZOOM_4X, label: '4×' }
|
||||
];
|
||||
|
||||
magnifierLensSizeOptions: {value: CbxMagnifierLensSize, label: string}[] = [
|
||||
{value: CbxMagnifierLensSize.SMALL, label: 'S'},
|
||||
{value: CbxMagnifierLensSize.MEDIUM, label: 'M'},
|
||||
{value: CbxMagnifierLensSize.LARGE, label: 'L'},
|
||||
{value: CbxMagnifierLensSize.EXTRA_LARGE, label: 'XL'}
|
||||
magnifierLensSizeOptions: { value: CbxMagnifierLensSize, label: string }[] = [
|
||||
{ value: CbxMagnifierLensSize.SMALL, label: 'S' },
|
||||
{ value: CbxMagnifierLensSize.MEDIUM, label: 'M' },
|
||||
{ value: CbxMagnifierLensSize.LARGE, label: 'L' },
|
||||
{ value: CbxMagnifierLensSize.EXTRA_LARGE, label: 'XL' }
|
||||
];
|
||||
|
||||
get backgroundOptions() {
|
||||
return [
|
||||
{value: CbxBackgroundColor.BLACK, label: this.t.translate('readerCbx.quickSettings.black'), color: '#000000'},
|
||||
{value: CbxBackgroundColor.GRAY, label: this.t.translate('readerCbx.quickSettings.gray'), color: '#808080'},
|
||||
{value: CbxBackgroundColor.WHITE, label: this.t.translate('readerCbx.quickSettings.white'), color: '#ffffff'}
|
||||
{ value: CbxBackgroundColor.BLACK, label: this.t.translate('readerCbx.quickSettings.black'), color: '#000000' },
|
||||
{ value: CbxBackgroundColor.GRAY, label: this.t.translate('readerCbx.quickSettings.gray'), color: '#808080' },
|
||||
{ value: CbxBackgroundColor.WHITE, label: this.t.translate('readerCbx.quickSettings.white'), color: '#ffffff' }
|
||||
];
|
||||
}
|
||||
|
||||
@@ -95,10 +95,6 @@ export class CbxQuickSettingsComponent {
|
||||
return this.state().scrollMode === CbxScrollMode.PAGINATED;
|
||||
}
|
||||
|
||||
get isLongStrip(): boolean {
|
||||
return this.state().scrollMode === CbxScrollMode.LONG_STRIP;
|
||||
}
|
||||
|
||||
get isPhonePortrait(): boolean {
|
||||
return window.innerWidth < 768 && window.innerHeight > window.innerWidth;
|
||||
}
|
||||
@@ -156,6 +152,23 @@ export class CbxQuickSettingsComponent {
|
||||
this.quickSettingsService.emitMagnifierLensSizeChange(size);
|
||||
}
|
||||
|
||||
onBrightnessChange(event: Event): void {
|
||||
const value = +(event.target as HTMLInputElement).value;
|
||||
this.quickSettingsService.emitBrightnessChange(value);
|
||||
}
|
||||
|
||||
onEmulateBookToggle(): void {
|
||||
this.quickSettingsService.emitEmulateBookChange(!this.state().emulateBook);
|
||||
}
|
||||
|
||||
onClickToPaginateToggle(): void {
|
||||
this.quickSettingsService.emitClickToPaginateChange(!this.state().clickToPaginate);
|
||||
}
|
||||
|
||||
onAutoCloseMenuToggle(): void {
|
||||
this.quickSettingsService.emitAutoCloseMenuChange(!this.state().autoCloseMenu);
|
||||
}
|
||||
|
||||
onOverlayClick(): void {
|
||||
this.quickSettingsService.close();
|
||||
}
|
||||
|
||||
+18
-6
@@ -1,4 +1,4 @@
|
||||
import {describe, expect, it} from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import {
|
||||
CbxBackgroundColor,
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
CbxScrollMode,
|
||||
CbxSlideshowInterval,
|
||||
} from '../../../../settings/user-management/user.service';
|
||||
import {CbxQuickSettingsService} from './cbx-quick-settings.service';
|
||||
import { CbxQuickSettingsService } from './cbx-quick-settings.service';
|
||||
|
||||
describe('CbxQuickSettingsService', () => {
|
||||
it('tracks visibility and settings state and resets cleanly', () => {
|
||||
@@ -27,6 +27,10 @@ describe('CbxQuickSettingsService', () => {
|
||||
service.setSlideshowInterval(CbxSlideshowInterval.TEN_SECONDS);
|
||||
service.setMagnifierZoom(CbxMagnifierZoom.ZOOM_4X);
|
||||
service.setMagnifierLensSize(CbxMagnifierLensSize.EXTRA_LARGE);
|
||||
service.setBrightness(50);
|
||||
service.setEmulateBook(true);
|
||||
service.setClickToPaginate(true);
|
||||
service.setAutoCloseMenu(true);
|
||||
|
||||
expect(service.visible()).toBe(true);
|
||||
expect(service.state()).toEqual({
|
||||
@@ -38,7 +42,11 @@ describe('CbxQuickSettingsService', () => {
|
||||
readingDirection: CbxReadingDirection.RTL,
|
||||
slideshowInterval: CbxSlideshowInterval.TEN_SECONDS,
|
||||
magnifierZoom: CbxMagnifierZoom.ZOOM_4X,
|
||||
magnifierLensSize: CbxMagnifierLensSize.EXTRA_LARGE
|
||||
magnifierLensSize: CbxMagnifierLensSize.EXTRA_LARGE,
|
||||
brightness: 50,
|
||||
emulateBook: true,
|
||||
clickToPaginate: true,
|
||||
autoCloseMenu: true
|
||||
});
|
||||
|
||||
service.close();
|
||||
@@ -55,7 +63,11 @@ describe('CbxQuickSettingsService', () => {
|
||||
readingDirection: CbxReadingDirection.LTR,
|
||||
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
||||
magnifierZoom: CbxMagnifierZoom.ZOOM_3X,
|
||||
magnifierLensSize: CbxMagnifierLensSize.MEDIUM
|
||||
magnifierLensSize: CbxMagnifierLensSize.MEDIUM,
|
||||
brightness: 100,
|
||||
emulateBook: false,
|
||||
clickToPaginate: false,
|
||||
autoCloseMenu: false
|
||||
});
|
||||
});
|
||||
|
||||
@@ -82,7 +94,7 @@ describe('CbxQuickSettingsService', () => {
|
||||
service.magnifierLensSizeChange$.subscribe(value => lensSizeEvents.push(value));
|
||||
|
||||
service.emitFitModeChange(CbxFitMode.ACTUAL_SIZE);
|
||||
service.emitScrollModeChange(CbxScrollMode.LONG_STRIP);
|
||||
service.emitScrollModeChange(CbxScrollMode.INFINITE);
|
||||
service.emitPageViewModeChange(CbxPageViewMode.TWO_PAGE);
|
||||
service.emitPageSpreadChange(CbxPageSpread.EVEN);
|
||||
service.emitBackgroundColorChange(CbxBackgroundColor.WHITE);
|
||||
@@ -92,7 +104,7 @@ describe('CbxQuickSettingsService', () => {
|
||||
service.emitMagnifierLensSizeChange(CbxMagnifierLensSize.LARGE);
|
||||
|
||||
expect(fitModeEvents).toEqual([CbxFitMode.ACTUAL_SIZE]);
|
||||
expect(scrollModeEvents).toEqual([CbxScrollMode.LONG_STRIP]);
|
||||
expect(scrollModeEvents).toEqual([CbxScrollMode.INFINITE]);
|
||||
expect(pageViewEvents).toEqual([CbxPageViewMode.TWO_PAGE]);
|
||||
expect(pageSpreadEvents).toEqual([CbxPageSpread.EVEN]);
|
||||
expect(backgroundEvents).toEqual([CbxBackgroundColor.WHITE]);
|
||||
|
||||
+53
-1
@@ -12,6 +12,10 @@ export interface CbxQuickSettingsState {
|
||||
slideshowInterval: CbxSlideshowInterval;
|
||||
magnifierZoom: CbxMagnifierZoom;
|
||||
magnifierLensSize: CbxMagnifierLensSize;
|
||||
brightness: number;
|
||||
emulateBook: boolean;
|
||||
clickToPaginate: boolean;
|
||||
autoCloseMenu: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -25,7 +29,11 @@ export class CbxQuickSettingsService {
|
||||
readingDirection: CbxReadingDirection.LTR,
|
||||
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
||||
magnifierZoom: CbxMagnifierZoom.ZOOM_3X,
|
||||
magnifierLensSize: CbxMagnifierLensSize.MEDIUM
|
||||
magnifierLensSize: CbxMagnifierLensSize.MEDIUM,
|
||||
brightness: 100,
|
||||
emulateBook: false,
|
||||
clickToPaginate: false,
|
||||
autoCloseMenu: false
|
||||
};
|
||||
|
||||
private readonly _state = signal<CbxQuickSettingsState>(this.defaultState);
|
||||
@@ -61,6 +69,18 @@ export class CbxQuickSettingsService {
|
||||
private _magnifierLensSizeChange = new Subject<CbxMagnifierLensSize>();
|
||||
magnifierLensSizeChange$ = this._magnifierLensSizeChange.asObservable();
|
||||
|
||||
private _brightnessChange = new Subject<number>();
|
||||
brightnessChange$ = this._brightnessChange.asObservable();
|
||||
|
||||
private _emulateBookChange = new Subject<boolean>();
|
||||
emulateBookChange$ = this._emulateBookChange.asObservable();
|
||||
|
||||
private _clickToPaginateChange = new Subject<boolean>();
|
||||
clickToPaginateChange$ = this._clickToPaginateChange.asObservable();
|
||||
|
||||
private _autoCloseMenuChange = new Subject<boolean>();
|
||||
autoCloseMenuChange$ = this._autoCloseMenuChange.asObservable();
|
||||
|
||||
show(): void {
|
||||
this._visible.set(true);
|
||||
}
|
||||
@@ -109,6 +129,22 @@ export class CbxQuickSettingsService {
|
||||
this.updateState({magnifierLensSize: size});
|
||||
}
|
||||
|
||||
setBrightness(value: number): void {
|
||||
this.updateState({brightness: value});
|
||||
}
|
||||
|
||||
setEmulateBook(value: boolean): void {
|
||||
this.updateState({emulateBook: value});
|
||||
}
|
||||
|
||||
setClickToPaginate(value: boolean): void {
|
||||
this.updateState({clickToPaginate: value});
|
||||
}
|
||||
|
||||
setAutoCloseMenu(value: boolean): void {
|
||||
this.updateState({autoCloseMenu: value});
|
||||
}
|
||||
|
||||
// Actions emitted from component
|
||||
emitFitModeChange(mode: CbxFitMode): void {
|
||||
this._fitModeChange.next(mode);
|
||||
@@ -146,6 +182,22 @@ export class CbxQuickSettingsService {
|
||||
this._magnifierLensSizeChange.next(size);
|
||||
}
|
||||
|
||||
emitBrightnessChange(value: number): void {
|
||||
this._brightnessChange.next(value);
|
||||
}
|
||||
|
||||
emitEmulateBookChange(value: boolean): void {
|
||||
this._emulateBookChange.next(value);
|
||||
}
|
||||
|
||||
emitClickToPaginateChange(value: boolean): void {
|
||||
this._clickToPaginateChange.next(value);
|
||||
}
|
||||
|
||||
emitAutoCloseMenuChange(value: boolean): void {
|
||||
this._autoCloseMenuChange.next(value);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._state.set(this.defaultState);
|
||||
this._visible.set(false);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export interface CbxPageDimension {
|
||||
pageNumber: number;
|
||||
width: number;
|
||||
height: number;
|
||||
wide: boolean;
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
import {Component, Input, OnChanges, SimpleChanges, ViewChild, ElementRef, AfterViewInit} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {CbxPageSplitOption} from '../../../settings/user-management/user.service';
|
||||
|
||||
export type CanvasSplitState = 'NO_SPLIT' | 'LEFT_PART' | 'RIGHT_PART';
|
||||
|
||||
/**
|
||||
* Renders a wide page image on a <canvas>, optionally showing only
|
||||
* the left or right half depending on the split state.
|
||||
*
|
||||
* Browser canvas limits respected:
|
||||
* Safari: 4096×4096 Others: 16384×16384
|
||||
*/
|
||||
@Component({
|
||||
selector: 'app-canvas-renderer',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
template: `
|
||||
<canvas
|
||||
#canvas
|
||||
class="canvas-page"
|
||||
[class.canvas-hidden]="!imageLoaded"
|
||||
[style.max-width.%]="100"
|
||||
[style.max-height.%]="100">
|
||||
</canvas>
|
||||
`,
|
||||
styles: [`
|
||||
:host {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
.canvas-page {
|
||||
object-fit: contain;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
}
|
||||
.canvas-hidden {
|
||||
visibility: hidden;
|
||||
}
|
||||
`]
|
||||
})
|
||||
export class CanvasRendererComponent implements OnChanges, AfterViewInit {
|
||||
@Input() imageUrl = '';
|
||||
@Input() splitState: CanvasSplitState = 'NO_SPLIT';
|
||||
@Input() splitOption: CbxPageSplitOption = CbxPageSplitOption.NO_SPLIT;
|
||||
|
||||
@ViewChild('canvas', {static: true}) canvasRef!: ElementRef<HTMLCanvasElement>;
|
||||
|
||||
imageLoaded = false;
|
||||
private currentImage: HTMLImageElement | null = null;
|
||||
|
||||
private static readonly MAX_CANVAS_SAFARI = 4096;
|
||||
private static readonly MAX_CANVAS_OTHER = 16384;
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
if (this.imageUrl) {
|
||||
this.loadAndDraw();
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
if (changes['imageUrl'] || changes['splitState'] || changes['splitOption']) {
|
||||
if (changes['imageUrl'] && this.currentImage?.src !== this.imageUrl) {
|
||||
this.loadAndDraw();
|
||||
} else if (this.currentImage) {
|
||||
this.drawImage(this.currentImage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private loadAndDraw(): void {
|
||||
if (!this.imageUrl) return;
|
||||
|
||||
this.imageLoaded = false;
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.onload = () => {
|
||||
this.currentImage = img;
|
||||
this.drawImage(img);
|
||||
this.imageLoaded = true;
|
||||
};
|
||||
img.src = this.imageUrl;
|
||||
}
|
||||
|
||||
private drawImage(img: HTMLImageElement): void {
|
||||
const canvas = this.canvasRef?.nativeElement;
|
||||
if (!canvas) return;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
const maxDim = this.getMaxCanvasSize();
|
||||
const srcW = img.naturalWidth;
|
||||
const srcH = img.naturalHeight;
|
||||
|
||||
if (this.splitState === 'NO_SPLIT' || this.splitOption === CbxPageSplitOption.NO_SPLIT) {
|
||||
// Draw full image
|
||||
const w = Math.min(srcW, maxDim);
|
||||
const h = Math.min(srcH, maxDim);
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
ctx.drawImage(img, 0, 0, srcW, srcH, 0, 0, w, h);
|
||||
return;
|
||||
}
|
||||
|
||||
// Split: draw only left or right half
|
||||
const halfW = Math.floor(srcW / 2);
|
||||
const outW = Math.min(halfW, maxDim);
|
||||
const outH = Math.min(srcH, maxDim);
|
||||
canvas.width = outW;
|
||||
canvas.height = outH;
|
||||
|
||||
const isLeftToRight = this.splitOption === CbxPageSplitOption.SPLIT_LEFT_TO_RIGHT
|
||||
|| this.splitOption === CbxPageSplitOption.FIT_SPLIT;
|
||||
const showLeft = isLeftToRight
|
||||
? this.splitState === 'LEFT_PART'
|
||||
: this.splitState === 'RIGHT_PART';
|
||||
|
||||
const srcX = showLeft ? 0 : halfW;
|
||||
ctx.drawImage(img, srcX, 0, halfW, srcH, 0, 0, outW, outH);
|
||||
}
|
||||
|
||||
private getMaxCanvasSize(): number {
|
||||
const ua = navigator.userAgent;
|
||||
if (/Safari/.test(ua) && !/Chrome/.test(ua)) {
|
||||
return CanvasRendererComponent.MAX_CANVAS_SAFARI;
|
||||
}
|
||||
return CanvasRendererComponent.MAX_CANVAS_OTHER;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user