fix(cbx-reader): fix two-page layout + navigation (#1030)
This commit is contained in:
@@ -67,13 +67,14 @@
|
|||||||
<div class="pages-wrapper" role="button" tabindex="0" (click)="onImageClick()" (keydown.enter)="onImageClick()"
|
<div class="pages-wrapper" role="button" tabindex="0" (click)="onImageClick()" (keydown.enter)="onImageClick()"
|
||||||
(dblclick)="onImageDoubleClick()">
|
(dblclick)="onImageDoubleClick()">
|
||||||
@if (isPageTransitioning() && previousImageUrls().length > 0) {
|
@if (isPageTransitioning() && previousImageUrls().length > 0) {
|
||||||
<div class="previous-page-layer">
|
<div class="previous-page-layer" [class.single-page-layer]="isPreviousSinglePageLayer()">
|
||||||
@for (url of previousImageUrls(); track url) {
|
@for (url of previousImageUrls(); track url) {
|
||||||
<img [src]="url" alt="Previous Page" class="page-image previous-image" />
|
<img [src]="url" alt="Previous Page" class="page-image previous-image" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
<div class="current-page-layer" [class.fade-in]="isPageTransitioning() && imagesLoaded()">
|
<div class="current-page-layer" [class.fade-in]="isPageTransitioning() && imagesLoaded()"
|
||||||
|
[class.single-page-layer]="isSinglePageLayer()">
|
||||||
@if (shouldUseCanvasRenderer()) {
|
@if (shouldUseCanvasRenderer()) {
|
||||||
<app-canvas-renderer [imageUrl]="currentImageUrls()[0]" [splitState]="canvasSplitState()"
|
<app-canvas-renderer [imageUrl]="currentImageUrls()[0]" [splitState]="canvasSplitState()"
|
||||||
[splitOption]="pageSplitOption()">
|
[splitOption]="pageSplitOption()">
|
||||||
|
|||||||
@@ -274,16 +274,8 @@
|
|||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
box-shadow: 0 8px 32px rgb(0 0 0 / 60%);
|
box-shadow: 0 8px 32px rgb(0 0 0 / 60%);
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
transition: transform 0.2s ease;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.02);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.previous-image {
|
&.previous-image {
|
||||||
&:hover {
|
|
||||||
transform: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,22 +291,30 @@
|
|||||||
max-height: none;
|
max-height: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pages-wrapper {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-page-layer {
|
||||||
|
margin-block: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.02);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
.pages-wrapper,
|
|
||||||
.previous-page-layer,
|
.previous-page-layer,
|
||||||
.current-page-layer {
|
.current-page-layer {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.single-page-layer {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
@@ -325,27 +325,55 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.fit-height {
|
&.fit-height {
|
||||||
.pages-wrapper,
|
overflow: auto;
|
||||||
.previous-page-layer,
|
align-items: stretch;
|
||||||
|
touch-action: pan-x pan-y;
|
||||||
|
|
||||||
|
.pages-wrapper {
|
||||||
|
width: max-content;
|
||||||
|
min-width: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.current-page-layer {
|
.current-page-layer {
|
||||||
width: auto;
|
width: max-content;
|
||||||
max-width: 100%;
|
height: auto;
|
||||||
|
margin-inline: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
width: auto;
|
width: auto;
|
||||||
height: 100%;
|
height: calc(100dvh - 1rem);
|
||||||
|
max-width: none;
|
||||||
&:hover {
|
|
||||||
transform: scale(1.02);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
|
.pages-wrapper {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, max-content);
|
||||||
|
width: max-content;
|
||||||
|
height: auto;
|
||||||
|
margin-inline: auto;
|
||||||
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
width: auto;
|
width: auto;
|
||||||
height: 100%;
|
height: calc(100dvh - 1rem);
|
||||||
max-width: calc(50% - 0.5rem);
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.single-page-layer {
|
||||||
|
grid-template-columns: max-content;
|
||||||
|
|
||||||
|
.page-image {
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,14 +392,35 @@
|
|||||||
min-height: 0;
|
min-height: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pages-wrapper {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
max-width: none;
|
max-width: none;
|
||||||
max-height: none;
|
max-height: none;
|
||||||
|
}
|
||||||
|
|
||||||
&:hover {
|
&.two-page-view {
|
||||||
transform: none;
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, max-content);
|
||||||
|
width: max-content;
|
||||||
|
height: max-content;
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.single-page-layer {
|
||||||
|
grid-template-columns: max-content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -382,10 +431,6 @@
|
|||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.02);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
@@ -395,6 +440,12 @@
|
|||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.single-page-layer {
|
||||||
|
.page-image {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,10 +455,6 @@
|
|||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
|
||||||
&:hover {
|
|
||||||
transform: scale(1.02);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
@@ -417,6 +464,12 @@
|
|||||||
width: auto;
|
width: auto;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.single-page-layer {
|
||||||
|
.page-image {
|
||||||
|
max-width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { PageTitleService } from "../../../shared/service/page-title.service";
|
|||||||
import { CbxReaderService } from '../../book/service/cbx-reader.service';
|
import { CbxReaderService } from '../../book/service/cbx-reader.service';
|
||||||
import { BookService } from '../../book/service/book.service';
|
import { BookService } from '../../book/service/book.service';
|
||||||
import { CbxBackgroundColor, CbxFitMode, CbxMagnifierLensSize, CbxMagnifierZoom, CbxPageSpread, CbxPageSplitOption, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, UserService } from '../../settings/user-management/user.service';
|
import { CbxBackgroundColor, CbxFitMode, CbxMagnifierLensSize, CbxMagnifierZoom, CbxPageSpread, CbxPageSplitOption, CbxPageViewMode, CbxScrollMode, CbxReadingDirection, CbxSlideshowInterval, UserService } from '../../settings/user-management/user.service';
|
||||||
import { CbxPageDimensionService, DoublePairs } from './core/cbx-page-dimension.service';
|
import { CbxPageDimensionService } from './core/cbx-page-dimension.service';
|
||||||
import { CbxPageDimension } from './models/cbx-page-dimension.model';
|
import { CbxPageDimension } from './models/cbx-page-dimension.model';
|
||||||
import { MessageService } from 'primeng/api';
|
import { MessageService } from 'primeng/api';
|
||||||
import { TranslocoService, TranslocoPipe } from '@jsverse/transloco';
|
import { TranslocoService, TranslocoPipe } from '@jsverse/transloco';
|
||||||
@@ -39,6 +39,7 @@ import {
|
|||||||
shouldOfferWebtoonHint,
|
shouldOfferWebtoonHint,
|
||||||
writeStripWidthPercentPerBook
|
writeStripWidthPercentPerBook
|
||||||
} from './core/cbx-reader-storage';
|
} from './core/cbx-reader-storage';
|
||||||
|
import {computeCbxSpreads, findCbxSpreadForPage} from './core/cbx-spread.util';
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -91,7 +92,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
currentPage = signal(0);
|
currentPage = signal(0);
|
||||||
isLoading = signal(true);
|
isLoading = signal(true);
|
||||||
|
|
||||||
pageSpread = signal<CbxPageSpread>(CbxPageSpread.ODD);
|
pageSpread = signal<CbxPageSpread>(CbxPageSpread.EVEN);
|
||||||
pageViewMode = signal<CbxPageViewMode>(CbxPageViewMode.SINGLE_PAGE);
|
pageViewMode = signal<CbxPageViewMode>(CbxPageViewMode.SINGLE_PAGE);
|
||||||
backgroundColor = signal<CbxBackgroundColor>(CbxBackgroundColor.GRAY);
|
backgroundColor = signal<CbxBackgroundColor>(CbxBackgroundColor.GRAY);
|
||||||
fitMode = signal<CbxFitMode>(CbxFitMode.FIT_PAGE);
|
fitMode = signal<CbxFitMode>(CbxFitMode.FIT_PAGE);
|
||||||
@@ -198,8 +199,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
// Page dimensions from backend
|
// Page dimensions from backend
|
||||||
pageDimensions = signal<CbxPageDimension[]>([]);
|
pageDimensions = signal<CbxPageDimension[]>([]);
|
||||||
doublePairs = signal<DoublePairs>({});
|
|
||||||
|
|
||||||
// Double page detection (fallback cache for pages without backend dims)
|
// Double page detection (fallback cache for pages without backend dims)
|
||||||
private pageDimensionsCache = new Map<number, { width: number, height: number }>();
|
private pageDimensionsCache = new Map<number, { width: number, height: number }>();
|
||||||
|
|
||||||
@@ -390,8 +389,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.pages.set(pages);
|
this.pages.set(pages);
|
||||||
this.pageDimensions.set(dimensions);
|
this.pageDimensions.set(dimensions);
|
||||||
this.doublePairs.set(this.pageDimensionService.computeDoublePairs(dimensions));
|
|
||||||
|
|
||||||
if (this.bookType() === CbxReaderComponent.TYPE_CBX) {
|
if (this.bookType() === CbxReaderComponent.TYPE_CBX) {
|
||||||
const global = userSettings.perBookSetting.cbx === CbxReaderComponent.SETTING_GLOBAL;
|
const global = userSettings.perBookSetting.cbx === CbxReaderComponent.SETTING_GLOBAL;
|
||||||
this.cbxSettingsUsesGlobal.set(global);
|
this.cbxSettingsUsesGlobal.set(global);
|
||||||
@@ -406,8 +403,8 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
: this.CbxPageViewMode[bookSettings.cbxSettings?.pageViewMode as keyof typeof CbxPageViewMode] || this.CbxPageViewMode[userSettings.cbxReaderSetting.pageViewMode as keyof typeof CbxPageViewMode] || this.CbxPageViewMode.SINGLE_PAGE);
|
: this.CbxPageViewMode[bookSettings.cbxSettings?.pageViewMode as keyof typeof CbxPageViewMode] || this.CbxPageViewMode[userSettings.cbxReaderSetting.pageViewMode as keyof typeof CbxPageViewMode] || this.CbxPageViewMode.SINGLE_PAGE);
|
||||||
|
|
||||||
this.pageSpread.set(global
|
this.pageSpread.set(global
|
||||||
? this.CbxPageSpread[userSettings.cbxReaderSetting.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread.ODD
|
? this.CbxPageSpread[userSettings.cbxReaderSetting.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread.EVEN
|
||||||
: this.CbxPageSpread[bookSettings.cbxSettings?.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread[userSettings.cbxReaderSetting.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread.ODD);
|
: this.CbxPageSpread[bookSettings.cbxSettings?.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread[userSettings.cbxReaderSetting.pageSpread as keyof typeof CbxPageSpread] || this.CbxPageSpread.EVEN);
|
||||||
|
|
||||||
this.fitMode.set(global
|
this.fitMode.set(global
|
||||||
? this.CbxFitMode[userSettings.cbxReaderSetting.fitMode as keyof typeof CbxFitMode] || this.CbxFitMode.FIT_PAGE
|
? this.CbxFitMode[userSettings.cbxReaderSetting.fitMode as keyof typeof CbxFitMode] || this.CbxFitMode.FIT_PAGE
|
||||||
@@ -653,7 +650,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.footerService.updateState({
|
this.footerService.updateState({
|
||||||
currentPage: this.currentPage(),
|
currentPage: this.currentPage(),
|
||||||
totalPages: this.pages().length,
|
totalPages: this.pages().length,
|
||||||
isTwoPageView: this.isTwoPageView(),
|
isTwoPageView: this.hasVisibleTwoPageSpread(),
|
||||||
previousBookInSeries: this.previousBookInSeries(),
|
previousBookInSeries: this.previousBookInSeries(),
|
||||||
nextBookInSeries: this.nextBookInSeries(),
|
nextBookInSeries: this.nextBookInSeries(),
|
||||||
hasSeries: this.hasSeries()
|
hasSeries: this.hasSeries()
|
||||||
@@ -758,41 +755,50 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
private updateFooterPage(): void {
|
private updateFooterPage(): void {
|
||||||
this.resetSwipeBoundaryHits();
|
this.resetSwipeBoundaryHits();
|
||||||
this.footerService.setCurrentPage(this.currentPage());
|
this.footerService.setCurrentPage(this.currentPage());
|
||||||
|
this.footerService.setTwoPageView(this.hasVisibleTwoPageSpread());
|
||||||
this.sidebarService.setCurrentPage(this.currentPage() + 1);
|
this.sidebarService.setCurrentPage(this.currentPage() + 1);
|
||||||
this.updateBookmarkState();
|
this.updateBookmarkState();
|
||||||
this.updateNotesState();
|
this.updateNotesState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getRightPageForLeftPage(leftPage: number): number | undefined {
|
private getCbxSpreads(): number[][] {
|
||||||
const pair = Object.entries(this.doublePairs()).find(([, pairedLeft]) => pairedLeft === leftPage);
|
return computeCbxSpreads(this.pages(), this.pageDimensions(), this.pageSpread())
|
||||||
if (!pair) return undefined;
|
.map(spread => spread.pages);
|
||||||
|
}
|
||||||
|
|
||||||
const rightPage = Number(pair[0]);
|
private getCurrentSpreadPages(): number[] {
|
||||||
return Number.isFinite(rightPage) ? rightPage : undefined;
|
if (!this.isTwoPageView()) {
|
||||||
|
return [this.currentPage()];
|
||||||
|
}
|
||||||
|
return findCbxSpreadForPage(
|
||||||
|
computeCbxSpreads(this.pages(), this.pageDimensions(), this.pageSpread()),
|
||||||
|
this.currentPage()
|
||||||
|
)?.pages ?? [this.currentPage()];
|
||||||
|
}
|
||||||
|
|
||||||
|
private isPaginatedTwoPageView(): boolean {
|
||||||
|
return this.scrollMode() === CbxScrollMode.PAGINATED && this.isTwoPageView();
|
||||||
|
}
|
||||||
|
|
||||||
|
private hasVisibleTwoPageSpread(): boolean {
|
||||||
|
return this.isPaginatedTwoPageView() && this.getCurrentSpreadPages().length > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
isPreviousSinglePageLayer(): boolean {
|
||||||
|
return this.isPaginatedTwoPageView() && this.previousImageUrls().length === 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
isSinglePageLayer(): boolean {
|
||||||
|
return this.isPaginatedTwoPageView() && !this.hasVisibleTwoPageSpread();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getImageUrlsForCurrentPage(): string[] {
|
||||||
|
if (!this.pages().length) return [];
|
||||||
|
return this.getCurrentSpreadPages().map(pageIndex => this.getPageImageUrl(pageIndex));
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateCurrentImageUrls(): void {
|
private updateCurrentImageUrls(): void {
|
||||||
if (!this.pages().length) {
|
this.currentImageUrls.set(this.getImageUrlsForCurrentPage());
|
||||||
this.currentImageUrls.set([]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const urls: string[] = [];
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage()));
|
|
||||||
|
|
||||||
if (this.isTwoPageView()) {
|
|
||||||
// Use doublePairs for dimension-aware pairing
|
|
||||||
if (Object.keys(this.doublePairs()).length > 0) {
|
|
||||||
const pairedWith = this.getRightPageForLeftPage(this.currentPage());
|
|
||||||
if (pairedWith !== undefined && pairedWith < this.pages().length) {
|
|
||||||
urls.push(this.getPageImageUrl(pairedWith));
|
|
||||||
}
|
|
||||||
} else if (this.currentPage() + 1 < this.pages().length) {
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage() + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.currentImageUrls.set(urls);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private preloadAdjacentPages(): void {
|
private preloadAdjacentPages(): void {
|
||||||
@@ -854,7 +860,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.resetPaginatedScroll();
|
this.resetPaginatedScroll();
|
||||||
|
|
||||||
const newUrls = this.getNewImageUrls();
|
const newUrls = this.getImageUrlsForCurrentPage();
|
||||||
|
|
||||||
const allPreloaded = newUrls.every(url => {
|
const allPreloaded = newUrls.every(url => {
|
||||||
const img = this.preloadedImages.get(url);
|
const img = this.preloadedImages.get(url);
|
||||||
@@ -882,26 +888,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.preloadAdjacentPages();
|
this.preloadAdjacentPages();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getNewImageUrls(): string[] {
|
|
||||||
if (!this.pages().length) return [];
|
|
||||||
|
|
||||||
const urls: string[] = [];
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage()));
|
|
||||||
|
|
||||||
if (this.isTwoPageView()) {
|
|
||||||
if (Object.keys(this.doublePairs()).length > 0) {
|
|
||||||
const pairedWith = this.getRightPageForLeftPage(this.currentPage());
|
|
||||||
if (pairedWith !== undefined && pairedWith < this.pages().length) {
|
|
||||||
urls.push(this.getPageImageUrl(pairedWith));
|
|
||||||
}
|
|
||||||
} else if (this.currentPage() + 1 < this.pages().length) {
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage() + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
private preloadImagesAndTransition(urls: string[]): void {
|
private preloadImagesAndTransition(urls: string[]): void {
|
||||||
let loadedCount = 0;
|
let loadedCount = 0;
|
||||||
const totalImages = urls.length;
|
const totalImages = urls.length;
|
||||||
@@ -951,8 +937,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private advancePage(direction: 1 | -1): void {
|
private advancePage(direction: 1 | -1): void {
|
||||||
const previousPage = this.currentPage();
|
const previousPage = this.currentPage();
|
||||||
const step = this.getPageStep();
|
|
||||||
|
|
||||||
if (this.scrollMode() === CbxScrollMode.LONG_STRIP) {
|
if (this.scrollMode() === CbxScrollMode.LONG_STRIP) {
|
||||||
const newPage = this.currentPage() + direction;
|
const newPage = this.currentPage() + direction;
|
||||||
if (newPage >= 0 && newPage < this.pages().length) {
|
if (newPage >= 0 && newPage < this.pages().length) {
|
||||||
@@ -980,29 +964,11 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
if (direction > 0) {
|
if (direction > 0) {
|
||||||
// Forward navigation
|
// Forward navigation
|
||||||
if (this.isTwoPageView()) {
|
if (this.isTwoPageView()) {
|
||||||
// Use doublePairs for dimension-aware stepping
|
const spreads = this.getCbxSpreads();
|
||||||
if (Object.keys(this.doublePairs()).length > 0) {
|
const spreadIndex = spreads.findIndex(spread => spread.includes(this.currentPage()));
|
||||||
const pairedWith = this.getRightPageForLeftPage(this.currentPage());
|
const nextSpread = spreadIndex >= 0 ? spreads[spreadIndex + 1] : undefined;
|
||||||
if (pairedWith !== undefined) {
|
if (nextSpread) {
|
||||||
// Current page is paired — skip past its partner
|
this.currentPage.set(nextSpread[0]);
|
||||||
const nextPage = Math.max(this.currentPage(), pairedWith) + 1;
|
|
||||||
if (nextPage < this.pages().length) {
|
|
||||||
this.currentPage.set(nextPage);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Current page is solo (wide or cover) — advance by 1
|
|
||||||
if (this.currentPage() + 1 < this.pages().length) {
|
|
||||||
this.currentPage.set(this.currentPage() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback: use old heuristic
|
|
||||||
const effectiveStep = this.shouldShowSinglePage(this.currentPage()) ? 1 : step;
|
|
||||||
if (this.currentPage() + effectiveStep < this.pages().length) {
|
|
||||||
this.currentPage.set(this.currentPage() + effectiveStep);
|
|
||||||
} else if (this.currentPage() + 1 < this.pages().length) {
|
|
||||||
this.currentPage.set(this.currentPage() + 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (this.currentPage() < this.pages().length - 1) {
|
} else if (this.currentPage() < this.pages().length - 1) {
|
||||||
// Single-page mode: handle canvas split state for wide pages
|
// Single-page mode: handle canvas split state for wide pages
|
||||||
@@ -1022,21 +988,11 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
// Backward navigation
|
// Backward navigation
|
||||||
if (this.isTwoPageView()) {
|
if (this.isTwoPageView()) {
|
||||||
if (Object.keys(this.doublePairs()).length > 0) {
|
const spreads = this.getCbxSpreads();
|
||||||
// Find the page that starts the previous spread
|
const spreadIndex = spreads.findIndex(spread => spread.includes(this.currentPage()));
|
||||||
const targetPage = this.currentPage() - 1;
|
const previousSpread = spreadIndex > 0 ? spreads[spreadIndex - 1] : undefined;
|
||||||
if (targetPage >= 0) {
|
if (previousSpread) {
|
||||||
const pairedWith = this.doublePairs()[targetPage];
|
this.currentPage.set(previousSpread[0]);
|
||||||
if (pairedWith !== undefined) {
|
|
||||||
// Land on the lower-indexed page of the pair
|
|
||||||
this.currentPage.set(Math.min(targetPage, pairedWith));
|
|
||||||
} else {
|
|
||||||
// Previous page is solo — just go there
|
|
||||||
this.currentPage.set(targetPage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.currentPage.set(Math.max(0, this.currentPage() - step));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Single-page backward: handle canvas split for wide pages
|
// Single-page backward: handle canvas split for wide pages
|
||||||
@@ -1072,27 +1028,13 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getPageStep(): number {
|
|
||||||
return this.isTwoPageView() ? 2 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private alignCurrentPageToParity() {
|
private alignCurrentPageToParity() {
|
||||||
if (!this.pages().length || !this.isTwoPageView()) return;
|
if (!this.pages().length || !this.isTwoPageView()) return;
|
||||||
|
|
||||||
const desiredOdd = this.pageSpread() === CbxPageSpread.ODD;
|
const spread = this.getCurrentSpreadPages();
|
||||||
for (let i = this.currentPage(); i >= 0; i--) {
|
if (spread.length && this.currentPage() !== spread[0]) {
|
||||||
if ((this.pages()[i] % 2 === 1) === desiredOdd) {
|
this.currentPage.set(spread[0]);
|
||||||
this.currentPage.set(i);
|
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let i = 0; i < this.pages().length; i++) {
|
|
||||||
if ((this.pages()[i] % 2 === 1) === desiredOdd) {
|
|
||||||
this.currentPage.set(i);
|
|
||||||
this.updateProgress();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1142,7 +1084,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
this.updateCurrentImageUrls();
|
this.updateCurrentImageUrls();
|
||||||
this.preloadAdjacentPages();
|
this.preloadAdjacentPages();
|
||||||
this.footerService.setTwoPageView(this.isTwoPageView());
|
this.footerService.setTwoPageView(this.hasVisibleTwoPageSpread());
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1152,6 +1094,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
this.updateCurrentImageUrls();
|
this.updateCurrentImageUrls();
|
||||||
this.preloadAdjacentPages();
|
this.preloadAdjacentPages();
|
||||||
|
this.footerService.setTwoPageView(this.hasVisibleTwoPageSpread());
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import {describe, expect, it} from 'vitest';
|
||||||
|
import {CbxPageSpread} from '../../../settings/user-management/user.service';
|
||||||
|
import {computeCbxSpreads, findCbxSpreadForPage} from './cbx-spread.util';
|
||||||
|
import {CbxPageDimension} from '../models/cbx-page-dimension.model';
|
||||||
|
|
||||||
|
function dimensions(widePages: number[] = []): CbxPageDimension[] {
|
||||||
|
return Array.from({length: 6}, (_, index) => ({
|
||||||
|
pageNumber: index + 1,
|
||||||
|
width: widePages.includes(index) ? 1800 : 900,
|
||||||
|
height: 1200,
|
||||||
|
wide: widePages.includes(index)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('cbx spread utilities', () => {
|
||||||
|
const pages = [1, 2, 3, 4, 5, 6];
|
||||||
|
|
||||||
|
it('returns no spreads for an empty page list', () => {
|
||||||
|
const spreads = computeCbxSpreads([], [], CbxPageSpread.EVEN);
|
||||||
|
|
||||||
|
expect(spreads).toEqual([]);
|
||||||
|
expect(findCbxSpreadForPage(spreads, 0)).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the cover solo and pairs even-starting spreads for LTR comics', () => {
|
||||||
|
const spreads = computeCbxSpreads(pages, dimensions(), CbxPageSpread.EVEN);
|
||||||
|
|
||||||
|
expect(spreads.map(spread => spread.pages)).toEqual([
|
||||||
|
[0],
|
||||||
|
[1, 2],
|
||||||
|
[3, 4],
|
||||||
|
[5],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps alignment pages solo until the configured spread parity starts', () => {
|
||||||
|
const spreads = computeCbxSpreads(pages, dimensions(), CbxPageSpread.ODD);
|
||||||
|
|
||||||
|
expect(spreads.map(spread => spread.pages)).toEqual([
|
||||||
|
[0],
|
||||||
|
[1],
|
||||||
|
[2, 3],
|
||||||
|
[4, 5],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps wide pages solo and resumes pairing after them', () => {
|
||||||
|
const spreads = computeCbxSpreads(pages, dimensions([3]), CbxPageSpread.EVEN);
|
||||||
|
|
||||||
|
expect(spreads.map(spread => spread.pages)).toEqual([
|
||||||
|
[0],
|
||||||
|
[1, 2],
|
||||||
|
[3],
|
||||||
|
[4],
|
||||||
|
[5],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('finds the spread for either page in a pair', () => {
|
||||||
|
const spreads = computeCbxSpreads(pages, dimensions(), CbxPageSpread.EVEN);
|
||||||
|
|
||||||
|
expect(findCbxSpreadForPage(spreads, 1)?.pages).toEqual([1, 2]);
|
||||||
|
expect(findCbxSpreadForPage(spreads, 2)?.pages).toEqual([1, 2]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import {CbxPageSpread} from '../../../settings/user-management/user.service';
|
||||||
|
import {CbxPageDimension} from '../models/cbx-page-dimension.model';
|
||||||
|
|
||||||
|
export interface CbxSpread {
|
||||||
|
readonly pages: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function isWidePage(dimensions: CbxPageDimension[], pageIndex: number): boolean {
|
||||||
|
return dimensions[pageIndex]?.wide === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function pageMatchesSpreadStart(pageNumber: number, pageSpread: CbxPageSpread): boolean {
|
||||||
|
const startsOdd = pageSpread === CbxPageSpread.ODD;
|
||||||
|
return (pageNumber % 2 === 1) === startsOdd;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function computeCbxSpreads(
|
||||||
|
pages: number[],
|
||||||
|
dimensions: CbxPageDimension[],
|
||||||
|
pageSpread: CbxPageSpread
|
||||||
|
): CbxSpread[] {
|
||||||
|
if (!pages.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const spreads: CbxSpread[] = [{pages: [0]}];
|
||||||
|
let pageIndex = 1;
|
||||||
|
|
||||||
|
while (pageIndex < pages.length) {
|
||||||
|
const nextIndex = pageIndex + 1;
|
||||||
|
|
||||||
|
if (
|
||||||
|
isWidePage(dimensions, pageIndex) ||
|
||||||
|
!pageMatchesSpreadStart(pages[pageIndex], pageSpread) ||
|
||||||
|
nextIndex >= pages.length ||
|
||||||
|
isWidePage(dimensions, nextIndex)
|
||||||
|
) {
|
||||||
|
spreads.push({pages: [pageIndex]});
|
||||||
|
pageIndex++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
spreads.push({pages: [pageIndex, nextIndex]});
|
||||||
|
pageIndex += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
return spreads;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findCbxSpreadForPage(spreads: CbxSpread[], pageIndex: number): CbxSpread | undefined {
|
||||||
|
return spreads.find(spread => spread.pages.includes(pageIndex));
|
||||||
|
}
|
||||||
+1
-1
@@ -60,7 +60,7 @@ describe('CbxQuickSettingsService', () => {
|
|||||||
fitMode: CbxFitMode.FIT_PAGE,
|
fitMode: CbxFitMode.FIT_PAGE,
|
||||||
scrollMode: CbxScrollMode.PAGINATED,
|
scrollMode: CbxScrollMode.PAGINATED,
|
||||||
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
|
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
|
||||||
pageSpread: CbxPageSpread.ODD,
|
pageSpread: CbxPageSpread.EVEN,
|
||||||
backgroundColor: CbxBackgroundColor.GRAY,
|
backgroundColor: CbxBackgroundColor.GRAY,
|
||||||
readingDirection: CbxReadingDirection.LTR,
|
readingDirection: CbxReadingDirection.LTR,
|
||||||
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ export class CbxQuickSettingsService {
|
|||||||
fitMode: CbxFitMode.FIT_PAGE,
|
fitMode: CbxFitMode.FIT_PAGE,
|
||||||
scrollMode: CbxScrollMode.PAGINATED,
|
scrollMode: CbxScrollMode.PAGINATED,
|
||||||
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
|
pageViewMode: CbxPageViewMode.SINGLE_PAGE,
|
||||||
pageSpread: CbxPageSpread.ODD,
|
pageSpread: CbxPageSpread.EVEN,
|
||||||
backgroundColor: CbxBackgroundColor.GRAY,
|
backgroundColor: CbxBackgroundColor.GRAY,
|
||||||
readingDirection: CbxReadingDirection.LTR,
|
readingDirection: CbxReadingDirection.LTR,
|
||||||
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
slideshowInterval: CbxSlideshowInterval.FIVE_SECONDS,
|
||||||
|
|||||||
Reference in New Issue
Block a user