chore(ui): clear reader state any bucket

Replace remaining reader-side any usages outside the core managers with concrete relocate, annotation, renderer, timer, and EPUB metadata types.

This leaves the final no-explicit-any cleanup isolated to event.service and view-manager.service.

Validation: just ui lint
This commit is contained in:
James Cox
2026-04-22 17:26:51 -04:00
committed by Zach Yale
parent e12f4ea827
commit af9a53dd4e
5 changed files with 50 additions and 13 deletions
@@ -31,7 +31,7 @@ export interface EpubBookInfo {
spine: EpubSpineItem[];
manifest: EpubManifestItem[];
toc: EpubTocItem;
metadata: Record<string, any>;
metadata: Record<string, unknown>;
coverPath?: string;
}
@@ -2,6 +2,12 @@ import {inject, Injectable} from '@angular/core';
import {ReaderState} from '../state/reader-state.service';
import {EpubCustomFontService} from '../features/fonts/custom-font.service';
interface ReaderRenderer {
setAttribute(name: string, value: string | number): void;
removeAttribute(name: string): void;
setStyles?(css: string): void;
}
@Injectable({
providedIn: 'root'
})
@@ -175,7 +181,7 @@ export class ReaderStyleService {
return !isNaN(id) && id.toString() === fontFamily ? id : null;
}
applyStylesToRenderer(renderer: any, state: ReaderState): void {
applyStylesToRenderer(renderer: ReaderRenderer | null | undefined, state: ReaderState): void {
if (!renderer) return;
renderer.setAttribute('max-column-count', state.maxColumnCount);
@@ -32,6 +32,7 @@ import {TextSelectionAction, TextSelectionPopupComponent} from './shared/selecti
import {NoteDialogResult, ReaderNoteDialogComponent} from './dialogs/note-dialog.component';
import {EbookShortcutsHelpComponent} from './dialogs/shortcuts-help.component';
import {TranslocoPipe} from '@jsverse/transloco';
import {RelocateProgressData} from './state/progress.service';
@Component({
selector: 'app-ebook-reader',
@@ -94,8 +95,8 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
private hasLoadedOnce = false;
private _fileUrl: string | null = null;
private visibilityManager!: ReaderHeaderFooterVisibilityManager;
private relocateTimeout: any;
private sectionFractionsTimeout: any;
private relocateTimeout?: ReturnType<typeof setTimeout>;
private sectionFractionsTimeout?: ReturnType<typeof setTimeout>;
isLoading = true;
showQuickSettings = false;
@@ -128,7 +129,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
);
}
get currentProgressData(): any {
get currentProgressData(): RelocateProgressData | null {
return this.progressService.currentProgressData;
}
@@ -10,6 +10,12 @@ export interface Annotation {
style?: AnnotationStyle;
}
interface AnnotationView {
addAnnotation(annotation: { value: string }): Promise<{ index: number; label: string } | undefined>;
deleteAnnotation(annotation: { value: string }): Promise<void>;
showAnnotation(annotation: { value: string }): Promise<void>;
}
@Injectable({
providedIn: 'root'
})
@@ -17,7 +23,7 @@ export class ReaderAnnotationService {
private annotationStyles = new Map<string, { color: string; style: AnnotationStyle }>();
private allAnnotations: Annotation[] = [];
addAnnotation(view: any, annotation: Annotation): Observable<{ index: number; label: string } | undefined> {
addAnnotation(view: AnnotationView | null | undefined, annotation: Annotation): Observable<{ index: number; label: string } | undefined> {
if (!view) return of(undefined);
const style = annotation.style || 'highlight';
@@ -35,7 +41,7 @@ export class ReaderAnnotationService {
return defer(() => from(view.addAnnotation({value: annotation.value}) as Promise<{ index: number; label: string } | undefined>));
}
deleteAnnotation(view: any, cfi: string): Observable<void> {
deleteAnnotation(view: AnnotationView | null | undefined, cfi: string): Observable<void> {
if (!view) return of(undefined);
this.annotationStyles.delete(cfi);
@@ -44,13 +50,13 @@ export class ReaderAnnotationService {
return defer(() => from(view.deleteAnnotation({value: cfi}) as Promise<void>));
}
showAnnotation(view: any, cfi: string): Observable<void> {
showAnnotation(view: AnnotationView | null | undefined, cfi: string): Observable<void> {
if (!view) return of(undefined);
return defer(() => from(view.showAnnotation({value: cfi}) as Promise<void>));
}
addAnnotations(view: any, annotations: Annotation[]): void {
addAnnotations(view: AnnotationView | null | undefined, annotations: Annotation[]): void {
annotations.forEach(annotation => {
const style = annotation.style || 'highlight';
const color = annotation.color || '#FACC15';
@@ -17,7 +17,31 @@ export interface ProgressState {
chapterHref: string | null;
fraction: number;
pageInfo: PageInfo | undefined;
progressData: any;
progressData: RelocateProgressData | null;
}
interface ProgressNavigationItem {
href?: string;
label?: string;
}
interface ProgressSection {
current: number;
total: number;
}
interface ProgressTime {
section?: number;
total?: number;
}
export interface RelocateProgressData {
cfi?: string | null;
pageItem?: ProgressNavigationItem;
tocItem?: ProgressNavigationItem;
fraction?: number;
section?: ProgressSection;
time?: ProgressTime;
}
@Injectable()
@@ -39,7 +63,7 @@ export class ReaderProgressService {
private _currentChapterName: string | null = null;
private _currentChapterHref: string | null = null;
private _currentPageInfo: PageInfo | undefined;
private _currentProgressData: any = null;
private _currentProgressData: RelocateProgressData | null = null;
private progressSubject = new Subject<ProgressState>();
public progress$ = this.progressSubject.asObservable();
@@ -56,7 +80,7 @@ export class ReaderProgressService {
return this._currentChapterHref;
}
get currentProgressData(): any {
get currentProgressData(): RelocateProgressData | null {
return this._currentProgressData;
}
@@ -71,7 +95,7 @@ export class ReaderProgressService {
this.hasStartedSession = false;
}
handleRelocateEvent(detail: any): void {
handleRelocateEvent(detail: RelocateProgressData): void {
this._currentProgressData = detail;
const cfi = detail?.cfi ?? null;