From af9a53dd4e589117924ab1e7fb1bc1471dcf4ffb Mon Sep 17 00:00:00 2001 From: James Cox Date: Wed, 25 Mar 2026 22:20:58 -0500 Subject: [PATCH] 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 --- .../core/epub-streaming.service.ts | 2 +- .../ebook-reader/core/style.service.ts | 8 ++++- .../ebook-reader/ebook-reader.component.ts | 7 ++-- .../annotation-renderer.service.ts | 14 +++++--- .../ebook-reader/state/progress.service.ts | 32 ++++++++++++++++--- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/features/readers/ebook-reader/core/epub-streaming.service.ts b/frontend/src/app/features/readers/ebook-reader/core/epub-streaming.service.ts index aa522459a..b81448820 100644 --- a/frontend/src/app/features/readers/ebook-reader/core/epub-streaming.service.ts +++ b/frontend/src/app/features/readers/ebook-reader/core/epub-streaming.service.ts @@ -31,7 +31,7 @@ export interface EpubBookInfo { spine: EpubSpineItem[]; manifest: EpubManifestItem[]; toc: EpubTocItem; - metadata: Record; + metadata: Record; coverPath?: string; } diff --git a/frontend/src/app/features/readers/ebook-reader/core/style.service.ts b/frontend/src/app/features/readers/ebook-reader/core/style.service.ts index 3d4fe4e4c..22d1fbf3e 100644 --- a/frontend/src/app/features/readers/ebook-reader/core/style.service.ts +++ b/frontend/src/app/features/readers/ebook-reader/core/style.service.ts @@ -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); diff --git a/frontend/src/app/features/readers/ebook-reader/ebook-reader.component.ts b/frontend/src/app/features/readers/ebook-reader/ebook-reader.component.ts index 60f6c9726..ec8aca19a 100644 --- a/frontend/src/app/features/readers/ebook-reader/ebook-reader.component.ts +++ b/frontend/src/app/features/readers/ebook-reader/ebook-reader.component.ts @@ -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; + private sectionFractionsTimeout?: ReturnType; 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; } diff --git a/frontend/src/app/features/readers/ebook-reader/features/annotations/annotation-renderer.service.ts b/frontend/src/app/features/readers/ebook-reader/features/annotations/annotation-renderer.service.ts index 78f365298..f17859b89 100644 --- a/frontend/src/app/features/readers/ebook-reader/features/annotations/annotation-renderer.service.ts +++ b/frontend/src/app/features/readers/ebook-reader/features/annotations/annotation-renderer.service.ts @@ -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; + showAnnotation(annotation: { value: string }): Promise; +} + @Injectable({ providedIn: 'root' }) @@ -17,7 +23,7 @@ export class ReaderAnnotationService { private annotationStyles = new Map(); 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 { + deleteAnnotation(view: AnnotationView | null | undefined, cfi: string): Observable { 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)); } - showAnnotation(view: any, cfi: string): Observable { + showAnnotation(view: AnnotationView | null | undefined, cfi: string): Observable { if (!view) return of(undefined); return defer(() => from(view.showAnnotation({value: cfi}) as Promise)); } - 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'; diff --git a/frontend/src/app/features/readers/ebook-reader/state/progress.service.ts b/frontend/src/app/features/readers/ebook-reader/state/progress.service.ts index 4cb449099..5eb1b2272 100644 --- a/frontend/src/app/features/readers/ebook-reader/state/progress.service.ts +++ b/frontend/src/app/features/readers/ebook-reader/state/progress.service.ts @@ -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(); 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;