Add themes.
Todo: Fix themes not cycling after applying each once.
This commit is contained in:
@@ -20,8 +20,10 @@
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
<label for="font-type">Font Type:</label>
|
||||
<p-dropdown id="font-type" [options]="fontTypes" [(ngModel)]="selectedFontType" (onChange)="changeFontType($event)">
|
||||
</p-dropdown>
|
||||
<p-dropdown id="font-type" [options]="fontTypes" [(ngModel)]="selectedFontType" (onChange)="changeFontType($event)"></p-dropdown>
|
||||
<p-divider></p-divider>
|
||||
<label for="theme">Font Type:</label>
|
||||
<p-dropdown id="theme" [options]="themes" [(ngModel)]="selectedTheme" (onChange)="changeThemes($event)"></p-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
</p-drawer>
|
||||
|
||||
@@ -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<string, any>([
|
||||
[
|
||||
'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"}
|
||||
}
|
||||
]
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user