From cc75d91c9dbbac0b42d00a0371e9735279ff2332 Mon Sep 17 00:00:00 2001 From: "aditya.chandel" <> Date: Tue, 14 Jan 2025 18:31:43 -0700 Subject: [PATCH] Add themes. Todo: Fix themes not cycling after applying each once. --- .../component/epub-viewer.component.html | 6 +- .../component/epub-viewer.component.ts | 93 +++++++++++++++++-- 2 files changed, 88 insertions(+), 11 deletions(-) diff --git a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.html b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.html index f6ca29f0c..8789b00ad 100644 --- a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.html +++ b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.html @@ -20,8 +20,10 @@ - - + + + + diff --git a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts index 704180a38..affe9539e 100644 --- a/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts +++ b/booklore-ui/src/app/epub-viewer/component/epub-viewer.component.ts @@ -6,7 +6,7 @@ import {Button} from 'primeng/button'; import {NgForOf} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {Divider} from 'primeng/divider'; -import {DropdownModule} from 'primeng/dropdown'; +import {DropdownChangeEvent, DropdownModule} from 'primeng/dropdown'; import {ActivatedRoute} from '@angular/router'; import {Book} from '../../book/model/book.model'; import {BookService} from '../../book/service/book.service'; @@ -41,6 +41,14 @@ export class EpubViewerComponent implements OnInit, OnDestroy { ]; selectedFontType: string = 'serif'; + selectedTheme: string = 'white'; + themes: any[] = [ + {label: 'White', value: 'white'}, + {label: 'Black', value: 'black'}, + {label: 'Grey', value: 'grey'}, + {label: 'Sepia', value: 'sepia'} + ]; + constructor(private epubService: EpubService, private route: ActivatedRoute, private bookService: BookService) { } @@ -76,6 +84,11 @@ export class EpubViewerComponent implements OnInit, OnDestroy { this.rendition.display(); } + this.themesMap.forEach((theme, name) => { + this.rendition.themes.register(name, theme); + }); + + this.setupKeyListener(); this.updateFontSize(); this.trackProgress(); @@ -86,13 +99,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy { }); } - ngOnDestroy(): void { - if (this.rendition) { - this.rendition.off('keyup', this.keyListener); - } - document.removeEventListener('keyup', this.keyListener); - } - private trackProgress(): void { if (this.rendition) { this.rendition.on('relocated', (location: any) => { @@ -128,12 +134,18 @@ export class EpubViewerComponent implements OnInit, OnDestroy { this.updateFontSize(); } - changeFontType(event: any): void { + changeFontType(event: DropdownChangeEvent): void { if (this.rendition) { this.rendition.themes.font(this.selectedFontType); } } + changeThemes($event: DropdownChangeEvent) { + if (this.rendition) { + this.rendition.themes.select(this.selectedTheme) + } + } + navigateToChapter(chapter: { label: string; href: string }): void { if (this.book && chapter.href) { this.book.rendition.display(chapter.href); @@ -178,4 +190,67 @@ export class EpubViewerComponent implements OnInit, OnDestroy { } document.addEventListener('keyup', this.keyListener); } + + ngOnDestroy(): void { + if (this.rendition) { + this.rendition.off('keyup', this.keyListener); + } + document.removeEventListener('keyup', this.keyListener); + } + + themesMap = new Map([ + [ + 'black', { + "body": {"background-color": "#000000", "color": "#f9f9f9", "font-family": "Arial, sans-serif"}, + "p": {"color": "#f9f9f9"}, + "h1, h2, h3, h4, h5, h6": {"color": "#f9f9f9"}, + "a": {"color": "#f9f9f9", "text-decoration": "underline"}, + "img": { + "-webkit-filter": "invert(1) hue-rotate(180deg)", + "filter": "invert(1) hue-rotate(180deg)" + }, + "code": {"color": "#00ff00", "background-color": "black"} + } + ], + [ + 'sepia', { + "body": {"background-color": "#f4ecd8", "color": "#6e4b3a", "font-family": "Georgia, serif"}, + "p": {"color": "#6e4b3a"}, + "h1, h2, h3, h4, h5, h6": {"color": "#6e4b3a"}, + "a": {"color": "#8b4513", "text-decoration": "underline"}, + "img": { + "-webkit-filter": "sepia(1) contrast(1.5)", + "filter": "sepia(1) contrast(1.5)" + }, + "code": {"color": "#8b0000", "background-color": "#f4ecd8"} + } + ], + [ + 'white', { + "body": {"background-color": "white", "color": "black", "font-family": "Arial, sans-serif"}, + "p": {"color": "black"}, + "h1, h2, h3, h4, h5, h6": {"color": "black"}, + "a": {"color": "#1e90ff", "text-decoration": "underline"}, + "img": { + "-webkit-filter": "none", + "filter": "none" + }, + "code": {"color": "#d14", "background-color": "#f5f5f5"} + } + ], + [ + 'grey', { + "body": {"background-color": "#404040", "color": "#d3d3d3", "font-family": "Arial, sans-serif"}, + "p": {"color": "#d3d3d3"}, + "h1, h2, h3, h4, h5, h6": {"color": "#d3d3d3"}, + "a": {"color": "#1e90ff", "text-decoration": "underline"}, + "img": { + "filter": "none" + }, + "code": {"color": "#d14", "background-color": "#585858"} + } + ] + ]); + + }