Reduce memory footprint during comic cover parsing

This commit is contained in:
aditya.chandel
2025-05-27 07:30:19 -07:00
committed by Aditya Chandel
parent a7b665e0ba
commit e559efc2f7
7 changed files with 219 additions and 99 deletions
@@ -1,13 +1,25 @@
<div class="comic-reader-container">
<div class="navigation">
<div class="page-controls">
<button (click)="previousPage()" [disabled]="currentPage === 0">&#8592;</button>
<div class="goto-page-controls" style="display: flex; align-items: center; margin-right: auto;">
<input type="number" [(ngModel)]="goToPageInput" [min]="1" [max]="pages.length" placeholder="Page">
<button
(click)="goToPageInput !== null && goToPage(goToPageInput)"
[disabled]="goToPageInput === null || goToPageInput < 1 || goToPageInput > pages.length">
Go
</button>
</div>
<div class="page-controls" style="display: flex; align-items: center; justify-content: center; flex-grow: 1;">
<button class="mr-2" (click)="goToPage(1)" [disabled]="currentPage === 0">&lt;&lt;</button>
<button (click)="previousPage()" [disabled]="currentPage === 0">&lt;</button>
<span>
Page {{ currentPage + 1 }}{{ isTwoPageView && imageUrls.length > 1 ? '-' + (currentPage + 2) : '' }} of {{ pages.length }}
</span>
<button (click)="nextPage()" [disabled]="currentPage >= pages.length - 1">&#8594;</button>
<button (click)="nextPage()" [disabled]="currentPage >= pages.length - 1">&gt;</button>
<button class="ml-2" (click)="goToPage(pages.length)" [disabled]="currentPage >= pages.length - 1">&gt;&gt;</button>
</div>
<div class="spread-controls">
<div class="spread-controls" style="display: flex; align-items: center; margin-left: auto;">
<button *ngIf="isTwoPageView" (click)="toggleSpreadDirection()" title="Toggle Spread Direction">
{{ pageSpread === 'ODD' ? '⬅️' : '➡️' }}
</button>
@@ -18,7 +18,6 @@
top: 50%;
transform: translate(-50%, -50%);
display: flex;
gap: 1rem;
align-items: center;
white-space: nowrap;
@@ -26,12 +25,10 @@
min-width: 8rem;
display: inline-block;
text-align: center;
font-variant-numeric: tabular-nums;
}
button {
min-width: 3rem;
padding: 0 0.5rem;
padding: 0 0.25rem;
text-align: center;
white-space: nowrap;
cursor: pointer;
@@ -93,4 +90,26 @@
display: block;
}
}
.goto-page-controls {
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
display: flex;
gap: 0.5rem;
align-items: center;
padding-left: 6px;
}
.goto-page-controls input[type="number"] {
width: 40px;
border-radius: 0.25rem;
font-size: 0.875rem;
}
.goto-page-controls button:disabled {
cursor: default;
color: #999;
}
}
@@ -8,15 +8,17 @@ import {MessageService} from 'primeng/api';
import {forkJoin} from 'rxjs';
import {BookSetting, CbxPageSpread, CbxPageViewMode} from '../../model/book.model';
import {ProgressSpinner} from 'primeng/progressspinner';
import {FormsModule} from "@angular/forms";
@Component({
selector: 'app-cbx-reader',
standalone: true,
imports: [NgIf, NgFor, ProgressSpinner],
imports: [NgIf, NgFor, ProgressSpinner, FormsModule],
templateUrl: './cbx-reader.component.html',
styleUrl: './cbx-reader.component.scss'
})
export class CbxReaderComponent implements OnInit {
goToPageInput: number | null = null;
bookId!: number;
pages: number[] = [];
currentPage = 0;
@@ -89,12 +91,21 @@ export class CbxReaderComponent implements OnInit {
}
nextPage() {
const previousPage = this.currentPage;
if (this.isTwoPageView) {
this.currentPage += (this.currentPage < this.pages.length - 2) ? 2 : 1;
if (this.currentPage + 2 < this.pages.length) {
this.currentPage += 2;
} else if (this.currentPage + 1 < this.pages.length) {
this.currentPage += 1;
}
} else if (this.currentPage < this.pages.length - 1) {
this.currentPage++;
}
this.updateProgress();
if (this.currentPage !== previousPage) {
this.updateProgress();
}
}
previousPage() {
@@ -192,4 +203,14 @@ export class CbxReaderComponent implements OnInit {
this.bookService.saveCbxProgress(this.bookId, this.currentPage + 1, percentage).subscribe();
}
goToPage(page: number): void {
if (page < 1 || page > this.pages.length) return;
const targetIndex = page - 1;
if (targetIndex === this.currentPage) return;
this.currentPage = targetIndex;
this.alignCurrentPageToParity();
this.updateProgress();
}
}