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[]; spine: EpubSpineItem[];
manifest: EpubManifestItem[]; manifest: EpubManifestItem[];
toc: EpubTocItem; toc: EpubTocItem;
metadata: Record<string, any>; metadata: Record<string, unknown>;
coverPath?: string; coverPath?: string;
} }
@@ -2,6 +2,12 @@ import {inject, Injectable} from '@angular/core';
import {ReaderState} from '../state/reader-state.service'; import {ReaderState} from '../state/reader-state.service';
import {EpubCustomFontService} from '../features/fonts/custom-font.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({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@@ -175,7 +181,7 @@ export class ReaderStyleService {
return !isNaN(id) && id.toString() === fontFamily ? id : null; 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; if (!renderer) return;
renderer.setAttribute('max-column-count', state.maxColumnCount); 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 {NoteDialogResult, ReaderNoteDialogComponent} from './dialogs/note-dialog.component';
import {EbookShortcutsHelpComponent} from './dialogs/shortcuts-help.component'; import {EbookShortcutsHelpComponent} from './dialogs/shortcuts-help.component';
import {TranslocoPipe} from '@jsverse/transloco'; import {TranslocoPipe} from '@jsverse/transloco';
import {RelocateProgressData} from './state/progress.service';
@Component({ @Component({
selector: 'app-ebook-reader', selector: 'app-ebook-reader',
@@ -94,8 +95,8 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
private hasLoadedOnce = false; private hasLoadedOnce = false;
private _fileUrl: string | null = null; private _fileUrl: string | null = null;
private visibilityManager!: ReaderHeaderFooterVisibilityManager; private visibilityManager!: ReaderHeaderFooterVisibilityManager;
private relocateTimeout: any; private relocateTimeout?: ReturnType<typeof setTimeout>;
private sectionFractionsTimeout: any; private sectionFractionsTimeout?: ReturnType<typeof setTimeout>;
isLoading = true; isLoading = true;
showQuickSettings = false; showQuickSettings = false;
@@ -128,7 +129,7 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
); );
} }
get currentProgressData(): any { get currentProgressData(): RelocateProgressData | null {
return this.progressService.currentProgressData; return this.progressService.currentProgressData;
} }
@@ -10,6 +10,12 @@ export interface Annotation {
style?: AnnotationStyle; 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({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@@ -17,7 +23,7 @@ export class ReaderAnnotationService {
private annotationStyles = new Map<string, { color: string; style: AnnotationStyle }>(); private annotationStyles = new Map<string, { color: string; style: AnnotationStyle }>();
private allAnnotations: Annotation[] = []; 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); if (!view) return of(undefined);
const style = annotation.style || 'highlight'; 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>)); 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); if (!view) return of(undefined);
this.annotationStyles.delete(cfi); this.annotationStyles.delete(cfi);
@@ -44,13 +50,13 @@ export class ReaderAnnotationService {
return defer(() => from(view.deleteAnnotation({value: cfi}) as Promise<void>)); 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); if (!view) return of(undefined);
return defer(() => from(view.showAnnotation({value: cfi}) as Promise<void>)); 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 => { annotations.forEach(annotation => {
const style = annotation.style || 'highlight'; const style = annotation.style || 'highlight';
const color = annotation.color || '#FACC15'; const color = annotation.color || '#FACC15';
@@ -17,7 +17,31 @@ export interface ProgressState {
chapterHref: string | null; chapterHref: string | null;
fraction: number; fraction: number;
pageInfo: PageInfo | undefined; 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() @Injectable()
@@ -39,7 +63,7 @@ export class ReaderProgressService {
private _currentChapterName: string | null = null; private _currentChapterName: string | null = null;
private _currentChapterHref: string | null = null; private _currentChapterHref: string | null = null;
private _currentPageInfo: PageInfo | undefined; private _currentPageInfo: PageInfo | undefined;
private _currentProgressData: any = null; private _currentProgressData: RelocateProgressData | null = null;
private progressSubject = new Subject<ProgressState>(); private progressSubject = new Subject<ProgressState>();
public progress$ = this.progressSubject.asObservable(); public progress$ = this.progressSubject.asObservable();
@@ -56,7 +80,7 @@ export class ReaderProgressService {
return this._currentChapterHref; return this._currentChapterHref;
} }
get currentProgressData(): any { get currentProgressData(): RelocateProgressData | null {
return this._currentProgressData; return this._currentProgressData;
} }
@@ -71,7 +95,7 @@ export class ReaderProgressService {
this.hasStartedSession = false; this.hasStartedSession = false;
} }
handleRelocateEvent(detail: any): void { handleRelocateEvent(detail: RelocateProgressData): void {
this._currentProgressData = detail; this._currentProgressData = detail;
const cfi = detail?.cfi ?? null; const cfi = detail?.cfi ?? null;