Improve EPUB Reader: UI Enhancements (Line Height, Letter Spacing, Flow, Fonts)
This commit is contained in:
committed by
Aditya Chandel
parent
fc328a7711
commit
df5ebbe7c4
@@ -93,7 +93,9 @@ public class BookLoreUser {
|
||||
public static class EpubReaderSetting {
|
||||
private String theme;
|
||||
private String font;
|
||||
private int fontSize;
|
||||
private Integer fontSize;
|
||||
private Float letterSpacing;
|
||||
private Float lineHeight;
|
||||
private String flow;
|
||||
}
|
||||
|
||||
|
||||
+2
@@ -11,4 +11,6 @@ public class EpubViewerPreferences {
|
||||
private String font;
|
||||
private String flow;
|
||||
private Integer fontSize;
|
||||
private Float letterSpacing;
|
||||
private Float lineHeight;
|
||||
}
|
||||
+6
@@ -33,6 +33,12 @@ public class EpubViewerPreferencesEntity {
|
||||
@Column(name = "font_size")
|
||||
private Integer fontSize;
|
||||
|
||||
@Column(name = "letter_spacing")
|
||||
private Float letterSpacing;
|
||||
|
||||
@Column(name = "line_height")
|
||||
private Float lineHeight;
|
||||
|
||||
@Column(name = "flow")
|
||||
private String flow;
|
||||
}
|
||||
@@ -138,6 +138,8 @@ public class BookService {
|
||||
.fontSize(epubPref.getFontSize())
|
||||
.theme(epubPref.getTheme())
|
||||
.flow(epubPref.getFlow())
|
||||
.letterSpacing(epubPref.getLetterSpacing())
|
||||
.lineHeight(epubPref.getLineHeight())
|
||||
.build()));
|
||||
} else if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||
pdfViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
||||
@@ -215,6 +217,8 @@ public class BookService {
|
||||
epubPrefs.setFontSize(epubSettings.getFontSize());
|
||||
epubPrefs.setTheme(epubSettings.getTheme());
|
||||
epubPrefs.setFlow(epubSettings.getFlow());
|
||||
epubPrefs.setLetterSpacing(epubSettings.getLetterSpacing());
|
||||
epubPrefs.setLineHeight(epubSettings.getLineHeight());
|
||||
epubViewerPreferencesRepository.save(epubPrefs);
|
||||
|
||||
} else if (bookEntity.getBookType() == BookFileType.CBX) {
|
||||
|
||||
+4
-2
@@ -62,8 +62,10 @@ public class DefaultUserSettingsProvider {
|
||||
private BookLoreUser.UserSettings.EpubReaderSetting buildDefaultEpubReaderSetting() {
|
||||
return BookLoreUser.UserSettings.EpubReaderSetting.builder()
|
||||
.theme("white")
|
||||
.font("serif")
|
||||
.fontSize(150)
|
||||
.font(null)
|
||||
.fontSize(100)
|
||||
.letterSpacing(null)
|
||||
.lineHeight(null)
|
||||
.flow("paginated")
|
||||
.build();
|
||||
}
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE epub_viewer_preference
|
||||
ADD COLUMN letter_spacing FLOAT NULL,
|
||||
ADD COLUMN line_height FLOAT NULL;
|
||||
@@ -131,9 +131,9 @@
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 2px;
|
||||
height: 5px;
|
||||
z-index: 1;
|
||||
opacity: 0.8;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.series-number-overlay {
|
||||
|
||||
+98
-15
@@ -30,23 +30,106 @@
|
||||
<div>
|
||||
<p-button size="small" class="settings-toggle-button" (click)="toggleSettingsDrawer()" icon="pi pi-cog" severity="secondary"></p-button>
|
||||
<p-drawer [(visible)]="isSettingsDrawerVisible" [modal]="false" [position]="'right'" header="Settings">
|
||||
<div class="flex flex-col">
|
||||
<div class="settings-content">
|
||||
<p>Font Size: {{ fontSize }}%</p>
|
||||
<div class="flex flex-row gap-4">
|
||||
<p-button icon="pi pi-minus" (click)="decreaseFontSize()" severity="info"></p-button>
|
||||
<p-button icon="pi pi-plus" (click)="increaseFontSize()" severity="info"></p-button>
|
||||
<div class="flex flex-col gap-4 max-w-md mx-auto">
|
||||
|
||||
<div class="flex items-center gap-4">
|
||||
<span class="font-semibold text-gray-700 dark:text-gray-200">Font Size:</span>
|
||||
<div class="flex items-center gap-2">
|
||||
<p-button size="small" icon="pi pi-minus" (click)="decreaseFontSize()" severity="info"></p-button>
|
||||
<span class="text-gray-800 dark:text-gray-100">{{ fontSize }}%</span>
|
||||
<p-button size="small" icon="pi pi-plus" (click)="increaseFontSize()" severity="info"></p-button>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
<label for="font-type">Font Type:</label>
|
||||
<p-select id="font-type" [options]="fontTypes" [(ngModel)]="selectedFontType" (onChange)="changeFontType()"></p-select>
|
||||
<p-divider></p-divider>
|
||||
<label for="theme">Theme:</label>
|
||||
<p-select id="theme" [options]="themes" [(ngModel)]="selectedTheme" (onChange)="changeThemes()"></p-select>
|
||||
<p-divider></p-divider>
|
||||
<label for="flow">Flow:</label>
|
||||
<p-select id="flow" [options]="flows" [(ngModel)]="selectedFlow" (onChange)="changeScrollMode()"></p-select>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<label for="font-type" class="block font-semibold text-gray-700 dark:text-gray-200">Font:</label>
|
||||
<p-select
|
||||
id="font-type"
|
||||
[options]="fontTypes"
|
||||
[(ngModel)]="selectedFontType"
|
||||
(onChange)="changeFontType()"
|
||||
class="w-full"
|
||||
placeholder="Select font type">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="flex gap-2 items-center">
|
||||
<label class="block font-semibold text-gray-700 dark:text-gray-200">Theme:</label>
|
||||
<div class="flex gap-3 mt-1" role="radiogroup" aria-label="Theme selection">
|
||||
@for (theme of themes; track theme) {
|
||||
<button
|
||||
type="button"
|
||||
class="w-8 h-8 rounded-full border-2 transition-all"
|
||||
[class.border-blue-600]="selectedTheme === theme.value"
|
||||
[style.background-color]="getThemeColor(theme.value)"
|
||||
(click)="selectTheme(theme.value)"
|
||||
[attr.aria-pressed]="selectedTheme === theme.value"
|
||||
[attr.aria-label]="theme.label">
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<label id="flow-label" class="block font-semibold text-gray-700 dark:text-gray-200">Flow:</label>
|
||||
<div class="flex gap-4" role="radiogroup" aria-labelledby="flow-label">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<p-radioButton
|
||||
name="flow"
|
||||
[value]="'paginated'"
|
||||
[(ngModel)]="selectedFlow"
|
||||
(onClick)="changeScrollMode()"
|
||||
inputId="flow-paginated">
|
||||
</p-radioButton>
|
||||
<label for="flow-paginated" class="cursor-pointer select-none text-gray-700 dark:text-gray-200">Paginated</label>
|
||||
</div>
|
||||
<div class="flex items-center gap-1.5">
|
||||
<p-radioButton
|
||||
name="flow"
|
||||
[value]="'scrolled'"
|
||||
[(ngModel)]="selectedFlow"
|
||||
(onClick)="changeScrollMode()"
|
||||
inputId="flow-scrolled">
|
||||
</p-radioButton>
|
||||
<label for="flow-scrolled" class="cursor-pointer select-none text-gray-700 dark:text-gray-200">Scrolled</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div>
|
||||
<label class="block mb-1 font-semibold text-gray-700 dark:text-gray-200 pb-2">Line Height: {{ lineHeight }}</label>
|
||||
<p-slider
|
||||
[(ngModel)]="lineHeight"
|
||||
[min]="1"
|
||||
[max]="2.5"
|
||||
[step]="0.1"
|
||||
(onSlideEnd)="updateThemeStyle()"
|
||||
class="w-full"
|
||||
aria-label="Line Height">
|
||||
</p-slider>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block mb-1 font-semibold text-gray-700 dark:text-gray-200 pb-2 pt-2">Letter Spacing: {{ letterSpacing }}em</label>
|
||||
<p-slider
|
||||
[(ngModel)]="letterSpacing"
|
||||
[min]="0"
|
||||
[max]="0.2"
|
||||
[step]="0.01"
|
||||
(onSlideEnd)="updateThemeStyle()"
|
||||
class="w-full"
|
||||
aria-label="Letter Spacing">
|
||||
</p-slider>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</p-drawer>
|
||||
</div>
|
||||
|
||||
+5
-16
@@ -95,26 +95,11 @@
|
||||
background-color: var(--card-background);
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
padding: 10px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.settings-content label {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.settings-content input[type="range"] {
|
||||
width: 100%;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
.location-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-left: 0.5rem;
|
||||
|
||||
.dot {
|
||||
height: 10px;
|
||||
width: 10px;
|
||||
@@ -136,3 +121,7 @@
|
||||
left: 0;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
::ng-deep .p-divider.p-divider-horizontal {
|
||||
margin: 0.25rem 0 0.5rem 0 !important;
|
||||
}
|
||||
|
||||
+113
-163
@@ -1,10 +1,9 @@
|
||||
import {Component, ElementRef, inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
||||
import ePub, {EpubCFI} from 'epubjs';
|
||||
import ePub from 'epubjs';
|
||||
import {Drawer} from 'primeng/drawer';
|
||||
import {Button} from 'primeng/button';
|
||||
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {Book, BookSetting} from '../../../model/book.model';
|
||||
import {BookService} from '../../../service/book.service';
|
||||
@@ -14,59 +13,17 @@ import {UserService} from '../../../../settings/user-management/user.service';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
|
||||
const FALLBACK_EPUB_SETTINGS = {
|
||||
fontSize: 150,
|
||||
fontType: 'serif',
|
||||
theme: 'white',
|
||||
flow: 'paginated',
|
||||
maxFontSize: 300,
|
||||
minFontSize: 50,
|
||||
};
|
||||
|
||||
function flatten(chapters: any) {
|
||||
return [].concat.apply([], chapters.map((chapter: any) => [].concat.apply([chapter], flatten(chapter.subitems))));
|
||||
}
|
||||
|
||||
export function getCfiFromHref(book: any, href: string): string | null {
|
||||
const [_, id] = href.split('#');
|
||||
const section = book.spine.get(href);
|
||||
|
||||
if (!section || !section.document) {
|
||||
console.warn('Section or section.document is undefined for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
const el = id ? section.document.getElementById(id) : section.document.body;
|
||||
if (!el) {
|
||||
console.warn('Element not found in section.document for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
return section.cfiFromElement(el);
|
||||
}
|
||||
|
||||
export function getChapter(book: any, location: any) {
|
||||
const locationHref = location.start.href;
|
||||
return flatten(book.navigation.toc)
|
||||
.filter((chapter: any) => {
|
||||
return book.canonical(chapter.href).includes(book.canonical(locationHref));
|
||||
})
|
||||
.reduce((result: any | null, chapter: any) => {
|
||||
const chapterCfi = getCfiFromHref(book, chapter.href);
|
||||
if (!chapterCfi) {
|
||||
return result;
|
||||
}
|
||||
const locationAfterChapter = EpubCFI.prototype.compare(location.start.cfi, chapterCfi) > 0;
|
||||
return locationAfterChapter ? chapter : result;
|
||||
}, null);
|
||||
}
|
||||
import {Slider} from 'primeng/slider';
|
||||
import {FALLBACK_EPUB_SETTINGS, getChapter} from '../epub-reader-helper';
|
||||
import {EpubThemeUtil} from '../epub-theme-util';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-viewer',
|
||||
templateUrl: './epub-viewer.component.html',
|
||||
styleUrls: ['./epub-viewer.component.scss'],
|
||||
imports: [Drawer, Button, FormsModule, Divider, Select, ProgressSpinner, Tooltip],
|
||||
imports: [Drawer, Button, FormsModule, Select, ProgressSpinner, Tooltip, Slider, RadioButton, Divider],
|
||||
standalone: true
|
||||
})
|
||||
export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
@@ -87,10 +44,15 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
private keyListener: (e: KeyboardEvent) => void = () => {
|
||||
};
|
||||
|
||||
fontSize = FALLBACK_EPUB_SETTINGS.fontSize;
|
||||
fontSize?: number = 100;
|
||||
selectedFlow?: string = 'paginated';
|
||||
selectedTheme?: string = 'white';
|
||||
selectedFontType?: string | null = null;
|
||||
lineHeight?: number;
|
||||
letterSpacing?: number;
|
||||
|
||||
selectedFontType = FALLBACK_EPUB_SETTINGS.fontType;
|
||||
fontTypes: any[] = [
|
||||
{label: "Book's Internal", value: null},
|
||||
{label: 'Serif', value: 'serif'},
|
||||
{label: 'Sans Serif', value: 'sans-serif'},
|
||||
{label: 'Roboto', value: 'roboto'},
|
||||
@@ -98,7 +60,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
{label: 'Monospace', value: 'monospace'},
|
||||
];
|
||||
|
||||
selectedTheme = FALLBACK_EPUB_SETTINGS.theme;
|
||||
themes: any[] = [
|
||||
{label: 'White', value: 'white'},
|
||||
{label: 'Black', value: 'black'},
|
||||
@@ -106,12 +67,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
{label: 'Sepia', value: 'sepia'},
|
||||
];
|
||||
|
||||
selectedFlow = FALLBACK_EPUB_SETTINGS.flow;
|
||||
flows: any[] = [
|
||||
{label: 'Scrolled', value: 'scrolled'},
|
||||
{label: 'Paginated', value: 'paginated'}
|
||||
];
|
||||
|
||||
private route = inject(ActivatedRoute);
|
||||
private userService = inject(UserService);
|
||||
private bookService = inject(BookService);
|
||||
@@ -130,13 +85,9 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
const bookSetting$ = this.bookService.getBookSetting(bookId);
|
||||
|
||||
forkJoin([myself$, epub$, epubData$, bookSetting$]).subscribe({
|
||||
next: (results) => {
|
||||
const myself = results[0];
|
||||
const epub = results[1];
|
||||
const epubData = results[2];
|
||||
const individualSetting = results[3]?.epubSettings;
|
||||
|
||||
next: ([myself, epub, epubData, bookSetting]) => {
|
||||
this.epub = epub;
|
||||
const individualSetting = bookSetting?.epubSettings;
|
||||
const fileReader = new FileReader();
|
||||
|
||||
fileReader.onload = () => {
|
||||
@@ -149,44 +100,55 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
}));
|
||||
});
|
||||
|
||||
let globalOrIndividual = myself.userSettings.perBookSetting.epub;
|
||||
const settingScope = myself.userSettings.perBookSetting.epub;
|
||||
const globalSettings = myself.userSettings.epubReaderSetting;
|
||||
|
||||
const flow = globalOrIndividual === 'Global'
|
||||
? myself.userSettings.epubReaderSetting.flow || 'paginated'
|
||||
: individualSetting?.flow || myself.userSettings.epubReaderSetting.flow || 'paginated';
|
||||
const resolvedFlow = settingScope === 'Global' ? globalSettings.flow : individualSetting?.flow;
|
||||
const resolvedFontSize = settingScope === 'Global' ? globalSettings.fontSize : individualSetting?.fontSize;
|
||||
const resolvedFontFamily = settingScope === 'Global' ? globalSettings.font : individualSetting?.font;
|
||||
const resolvedTheme = settingScope === 'Global' ? globalSettings.theme : individualSetting?.theme;
|
||||
const resolvedLineHeight = settingScope === 'Global' ? globalSettings.lineHeight : individualSetting?.lineHeight;
|
||||
const resolvedLetterSpacing = settingScope === 'Global' ? globalSettings.letterSpacing : individualSetting?.letterSpacing;
|
||||
|
||||
if (resolvedTheme != null) this.selectedTheme = resolvedTheme;
|
||||
if (resolvedFontFamily != null) this.selectedFontType = resolvedFontFamily;
|
||||
if (resolvedFontSize != null) this.fontSize = resolvedFontSize;
|
||||
if (resolvedLineHeight != null) this.lineHeight = resolvedLineHeight;
|
||||
if (resolvedLetterSpacing != null) this.letterSpacing = resolvedLetterSpacing;
|
||||
if (resolvedFlow != null) this.selectedFlow = resolvedFlow;
|
||||
|
||||
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, {
|
||||
flow,
|
||||
manager: flow === 'scrolled' ? 'continuous' : 'default',
|
||||
flow: this.selectedFlow ?? 'paginated',
|
||||
manager: this.selectedFlow === 'scrolled' ? 'continuous' : 'default',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
allowScriptedContent: true,
|
||||
});
|
||||
|
||||
const baseTheme = EpubThemeUtil.themesMap.get(this.selectedTheme ?? 'black') || {};
|
||||
const combinedTheme = {
|
||||
...baseTheme,
|
||||
body: {
|
||||
...baseTheme.body,
|
||||
...(this.selectedFontType ? {'font-family': this.selectedFontType} : {}),
|
||||
...(this.fontSize != null ? {'font-size': `${this.fontSize}%`} : {}),
|
||||
...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}),
|
||||
...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}),
|
||||
},
|
||||
'*': {
|
||||
...baseTheme['*'],
|
||||
...(this.lineHeight != null ? {'line-height': this.lineHeight} : {}),
|
||||
...(this.letterSpacing != null ? {'letter-spacing': `${this.letterSpacing}em`} : {}),
|
||||
},
|
||||
};
|
||||
|
||||
this.rendition.themes.register('custom', combinedTheme);
|
||||
this.rendition.themes.select('custom');
|
||||
|
||||
const displayPromise = this.epub?.epubProgress?.cfi
|
||||
? this.rendition.display(this.epub.epubProgress.cfi)
|
||||
: this.rendition.display();
|
||||
|
||||
this.themesMap.forEach((theme, name) => {
|
||||
this.rendition.themes.register(name, theme);
|
||||
});
|
||||
|
||||
if (globalOrIndividual === 'Global') {
|
||||
this.selectedTheme = myself.userSettings.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
|
||||
this.selectedFontType = myself.userSettings.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
|
||||
this.fontSize = myself.userSettings.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
||||
this.selectedFlow = myself.userSettings.epubReaderSetting.flow || FALLBACK_EPUB_SETTINGS.flow;
|
||||
} else {
|
||||
this.selectedTheme = individualSetting?.theme || myself.userSettings.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
|
||||
this.selectedFontType = individualSetting?.font || myself.userSettings.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
|
||||
this.fontSize = individualSetting?.fontSize || myself.userSettings.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
||||
this.selectedFlow = individualSetting?.flow || myself.userSettings.epubReaderSetting.flow || FALLBACK_EPUB_SETTINGS.flow;
|
||||
}
|
||||
|
||||
this.rendition.themes.select(this.selectedTheme);
|
||||
this.rendition.themes.fontSize(`${this.fontSize}%`);
|
||||
this.rendition.themes.font(this.selectedFontType);
|
||||
|
||||
displayPromise.then(() => {
|
||||
this.setupKeyListener();
|
||||
this.trackProgress();
|
||||
@@ -197,13 +159,22 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
fileReader.readAsArrayBuffer(epubData);
|
||||
},
|
||||
error: () => {
|
||||
this.messageService.add({severity: 'error', summary: 'Error', detail: 'Failed to load the book'});
|
||||
this.messageService.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: 'Failed to load the book',
|
||||
});
|
||||
this.isLoading = false;
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
updateThemeStyle(): void {
|
||||
this.applyCombinedTheme();
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
|
||||
changeScrollMode(): void {
|
||||
if (!this.rendition || !this.book) return;
|
||||
|
||||
@@ -218,10 +189,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
allowScriptedContent: true,
|
||||
});
|
||||
|
||||
this.themesMap.forEach((theme, name) => this.rendition.themes.register(name, theme));
|
||||
this.rendition.themes.select(this.selectedTheme);
|
||||
this.rendition.themes.font(this.selectedFontType);
|
||||
this.rendition.themes.fontSize(`${this.fontSize}%`);
|
||||
this.applyCombinedTheme();
|
||||
|
||||
this.setupKeyListener();
|
||||
this.rendition.display(cfi || undefined);
|
||||
@@ -229,12 +197,19 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
changeThemes(): void {
|
||||
if (this.rendition) {
|
||||
this.rendition.themes.select(this.selectedTheme);
|
||||
this.rendition.clear();
|
||||
this.rendition.start();
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
this.applyCombinedTheme();
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
|
||||
private applyCombinedTheme(): void {
|
||||
EpubThemeUtil.applyTheme(
|
||||
this.rendition,
|
||||
this.selectedTheme ?? 'white',
|
||||
this.selectedFontType ?? undefined,
|
||||
this.fontSize,
|
||||
this.lineHeight,
|
||||
this.letterSpacing
|
||||
);
|
||||
}
|
||||
|
||||
updateFontSize(): void {
|
||||
@@ -246,7 +221,11 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
|
||||
changeFontType(): void {
|
||||
if (this.rendition) {
|
||||
this.rendition.themes.font(this.selectedFontType);
|
||||
if (this.selectedFontType) {
|
||||
this.rendition.themes.font(this.selectedFontType);
|
||||
} else {
|
||||
this.rendition.themes.font('');
|
||||
}
|
||||
this.updateViewerSetting();
|
||||
}
|
||||
}
|
||||
@@ -262,14 +241,19 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
private updateViewerSetting(): void {
|
||||
const epubSettings: any = {};
|
||||
|
||||
if (this.selectedTheme) epubSettings.theme = this.selectedTheme;
|
||||
if (this.selectedFontType) epubSettings.font = this.selectedFontType;
|
||||
if (this.fontSize) epubSettings.fontSize = this.fontSize;
|
||||
if (this.selectedFlow) epubSettings.flow = this.selectedFlow;
|
||||
if (this.lineHeight) epubSettings.lineHeight = this.lineHeight;
|
||||
if (this.letterSpacing) epubSettings.letterSpacing = this.letterSpacing;
|
||||
|
||||
const bookSetting: BookSetting = {
|
||||
epubSettings: {
|
||||
theme: this.selectedTheme,
|
||||
font: this.selectedFontType,
|
||||
fontSize: this.fontSize,
|
||||
flow: this.selectedFlow
|
||||
}
|
||||
}
|
||||
epubSettings: epubSettings
|
||||
};
|
||||
|
||||
this.bookService.updateViewerSetting(bookSetting, this.epub.id).subscribe();
|
||||
}
|
||||
|
||||
@@ -351,57 +335,23 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
||||
document.removeEventListener('keyup', this.keyListener);
|
||||
}
|
||||
|
||||
themesMap = new Map<string, any>([
|
||||
[
|
||||
'black', {
|
||||
"body": {"background-color": "#000000", "color": "#f9f9f9"},
|
||||
"p": {"color": "#f9f9f9"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#f9f9f9"},
|
||||
"a": {"color": "#f9f9f9"},
|
||||
"img": {
|
||||
"-webkit-filter": "invert(1) hue-rotate(180deg)",
|
||||
"filter": "invert(1) hue-rotate(180deg)"
|
||||
},
|
||||
"code": {"color": "#00ff00", "background-color": "black"}
|
||||
getThemeColor(themeKey: string | undefined): string {
|
||||
switch (themeKey) {
|
||||
case 'white':
|
||||
return '#ffffff';
|
||||
case 'black':
|
||||
return '#000000';
|
||||
case 'grey':
|
||||
return '#808080';
|
||||
case 'sepia':
|
||||
return '#704214';
|
||||
default:
|
||||
return '#ffffff';
|
||||
}
|
||||
],
|
||||
[
|
||||
'sepia', {
|
||||
"body": {"background-color": "#f4ecd8", "color": "#6e4b3a"},
|
||||
"p": {"color": "#6e4b3a"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#6e4b3a"},
|
||||
"a": {"color": "#8b4513"},
|
||||
"img": {
|
||||
"-webkit-filter": "sepia(1) contrast(1.5)",
|
||||
"filter": "sepia(1) contrast(1.5)"
|
||||
},
|
||||
"code": {"color": "#8b0000", "background-color": "#f4ecd8"}
|
||||
}
|
||||
],
|
||||
[
|
||||
'white', {
|
||||
"body": {"background-color": "#ffffff", "color": "#000000"},
|
||||
"p": {"color": "#000000"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#000000"},
|
||||
"a": {"color": "#000000"},
|
||||
"img": {
|
||||
"-webkit-filter": "none",
|
||||
"filter": "none"
|
||||
},
|
||||
"code": {"color": "#d14", "background-color": "#f5f5f5"}
|
||||
}
|
||||
],
|
||||
[
|
||||
'grey', {
|
||||
"body": {"background-color": "#404040", "color": "#d3d3d3"},
|
||||
"p": {"color": "#d3d3d3"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#d3d3d3"},
|
||||
"a": {"color": "#1e90ff"},
|
||||
"img": {
|
||||
"filter": "none"
|
||||
},
|
||||
"code": {"color": "#d14", "background-color": "#585858"}
|
||||
}
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
selectTheme(themeKey: string): void {
|
||||
this.selectedTheme = themeKey;
|
||||
this.changeThemes();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import {EpubCFI} from 'epubjs';
|
||||
|
||||
export const FALLBACK_EPUB_SETTINGS = {
|
||||
maxFontSize: 300,
|
||||
minFontSize: 50
|
||||
};
|
||||
|
||||
export function flatten(chapters: any) {
|
||||
return [].concat.apply([], chapters.map((chapter: any) => [].concat.apply([chapter], flatten(chapter.subitems))));
|
||||
}
|
||||
|
||||
export function getCfiFromHref(book: any, href: string): string | null {
|
||||
const [_, id] = href.split('#');
|
||||
const section = book.spine.get(href);
|
||||
|
||||
if (!section || !section.document) {
|
||||
console.warn('Section or section.document is undefined for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
const el = id ? section.document.getElementById(id) : section.document.body;
|
||||
if (!el) {
|
||||
console.warn('Element not found in section.document for href:', href);
|
||||
return null;
|
||||
}
|
||||
|
||||
return section.cfiFromElement(el);
|
||||
}
|
||||
|
||||
export function getChapter(book: any, location: any) {
|
||||
const locationHref = location.start.href;
|
||||
return flatten(book.navigation.toc)
|
||||
.filter((chapter: any) => {
|
||||
return book.canonical(chapter.href).includes(book.canonical(locationHref));
|
||||
})
|
||||
.reduce((result: any | null, chapter: any) => {
|
||||
const chapterCfi = getCfiFromHref(book, chapter.href);
|
||||
if (!chapterCfi) {
|
||||
return result;
|
||||
}
|
||||
const locationAfterChapter = EpubCFI.prototype.compare(location.start.cfi, chapterCfi) > 0;
|
||||
return locationAfterChapter ? chapter : result;
|
||||
}, null);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
export class EpubThemeUtil {
|
||||
static readonly themesMap = new Map<string, any>([
|
||||
['black', {
|
||||
"body": {"background-color": "#000000", "color": "#f9f9f9"},
|
||||
"p": {"color": "#f9f9f9"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#f9f9f9"},
|
||||
"a": {"color": "#f9f9f9"},
|
||||
"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"},
|
||||
"p": {"color": "#6e4b3a"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#6e4b3a"},
|
||||
"a": {"color": "#8b4513"},
|
||||
"img": {"-webkit-filter": "sepia(1) contrast(1.5)", "filter": "sepia(1) contrast(1.5)"},
|
||||
"code": {"color": "#8b0000", "background-color": "#f4ecd8"}
|
||||
}],
|
||||
['white', {
|
||||
"body": {"background-color": "#ffffff", "color": "#000000"},
|
||||
"p": {"color": "#000000"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#000000"},
|
||||
"a": {"color": "#000000"},
|
||||
"img": {"-webkit-filter": "none", "filter": "none"},
|
||||
"code": {"color": "#d14", "background-color": "#f5f5f5"}
|
||||
}],
|
||||
['grey', {
|
||||
"body": {"background-color": "#404040", "color": "#d3d3d3"},
|
||||
"p": {"color": "#d3d3d3"},
|
||||
"h1, h2, h3, h4, h5, h6": {"color": "#d3d3d3"},
|
||||
"a": {"color": "#1e90ff"},
|
||||
"img": {"filter": "none"},
|
||||
"code": {"color": "#d14", "background-color": "#585858"}
|
||||
}]
|
||||
]);
|
||||
|
||||
static applyTheme(rendition: any, themeKey: string, fontFamily?: string, fontSize?: number, lineHeight?: number, letterSpacing?: number): void {
|
||||
if (!rendition) return;
|
||||
|
||||
const baseTheme = this.themesMap.get(themeKey ?? 'black') ?? {};
|
||||
const combined = {
|
||||
...baseTheme,
|
||||
body: {
|
||||
...baseTheme.body,
|
||||
'font-family': fontFamily,
|
||||
'font-size': `${fontSize ?? 100}%`,
|
||||
'line-height': lineHeight,
|
||||
'letter-spacing': `${letterSpacing}em`
|
||||
},
|
||||
'*': {
|
||||
...baseTheme['*'],
|
||||
'line-height': lineHeight,
|
||||
'letter-spacing': `${letterSpacing}em`
|
||||
}
|
||||
};
|
||||
|
||||
rendition.themes.register('custom', combined);
|
||||
rendition.themes.select('custom');
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,8 @@ export interface EpubViewerSetting {
|
||||
font: string;
|
||||
fontSize: number;
|
||||
flow: string;
|
||||
lineHeight: number;
|
||||
letterSpacing: number;
|
||||
}
|
||||
|
||||
export interface CbxViewerSetting {
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<div class="p-4 pb-12">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
CBX Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of cbxSpreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedCbxSpread">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (mode of cbxViewModes; track mode) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="mode.key"
|
||||
name="zoom"
|
||||
[value]="mode.key"
|
||||
[(ngModel)]="selectedCbxViewMode">
|
||||
</p-radiobutton>
|
||||
<label [for]="mode.key">{{ mode.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {CbxPageSpread, CbxPageViewMode} from '../../../book/model/book.model';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-cbx-reader-preferences-component',
|
||||
imports: [
|
||||
RadioButton,
|
||||
Tooltip,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './cbx-reader-preferences-component.html',
|
||||
styleUrl: './cbx-reader-preferences-component.scss'
|
||||
})
|
||||
export class CbxReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
readonly cbxSpreads = [
|
||||
{ name: 'Even', key: 'EVEN' },
|
||||
{ name: 'Odd', key: 'ODD' }
|
||||
];
|
||||
|
||||
readonly cbxViewModes = [
|
||||
{ name: 'Single Page', key: 'SINGLE_PAGE' },
|
||||
{ name: 'Two Page', key: 'TWO_PAGE' },
|
||||
];
|
||||
|
||||
get selectedCbxSpread(): CbxPageSpread {
|
||||
return this.userSettings.cbxReaderSetting.pageSpread;
|
||||
}
|
||||
set selectedCbxSpread(value: CbxPageSpread) {
|
||||
this.userSettings.cbxReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference(['cbxReaderSetting', 'pageSpread'], value);
|
||||
}
|
||||
|
||||
get selectedCbxViewMode(): CbxPageViewMode {
|
||||
return this.userSettings.cbxReaderSetting.pageViewMode;
|
||||
}
|
||||
set selectedCbxViewMode(value: CbxPageViewMode) {
|
||||
this.userSettings.cbxReaderSetting.pageViewMode = value;
|
||||
this.readerPreferencesService.updatePreference(['cbxReaderSetting', 'pageViewMode'], value);
|
||||
}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4">
|
||||
Epub Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Set global EPUB reader options such as themes, font families, font sizes, and spacing applied to all EPUBs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
|
||||
<p>Theme:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="themes"
|
||||
[(ngModel)]="selectedTheme"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Theme"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Font:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="fonts"
|
||||
[(ngModel)]="selectedFont"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Font"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Flow:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="flowOptions"
|
||||
[(ngModel)]="selectedFlow"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Flow"
|
||||
class="w-full md:w-44">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="py-1">Font Size:</p>
|
||||
<div class="flex gap-4 justify-start items-center">
|
||||
<p-button icon="pi pi-minus" size="small" (click)="decreaseFontSize()"></p-button>
|
||||
<p>{{ fontSize }}%</p>
|
||||
<p-button icon="pi pi-plus" size="small" (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-epub-reader-preferences-component',
|
||||
imports: [
|
||||
Button,
|
||||
Select,
|
||||
Tooltip,
|
||||
FormsModule
|
||||
],
|
||||
templateUrl: './epub-reader-preferences-component.html',
|
||||
styleUrl: './epub-reader-preferences-component.scss'
|
||||
})
|
||||
export class EpubReaderPreferencesComponent {
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
readonly fonts = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
readonly flowOptions = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'Paginated', key: 'paginated'},
|
||||
{name: 'Scrolled', key: 'scrolled'}
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{name: 'Book Default', key: null},
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
|
||||
get selectedTheme(): string | null {
|
||||
return this.userSettings.epubReaderSetting.theme;
|
||||
}
|
||||
|
||||
set selectedTheme(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.theme = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'theme'], value);
|
||||
}
|
||||
|
||||
get selectedFont(): string | null {
|
||||
return this.userSettings.epubReaderSetting.font;
|
||||
}
|
||||
|
||||
set selectedFont(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.font = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'font'], value);
|
||||
}
|
||||
|
||||
get selectedFlow(): string | null {
|
||||
return this.userSettings.epubReaderSetting.flow;
|
||||
}
|
||||
|
||||
set selectedFlow(value: string | null) {
|
||||
if (typeof value === "string") {
|
||||
this.userSettings.epubReaderSetting.flow = value;
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'flow'], value);
|
||||
}
|
||||
|
||||
get fontSize(): number {
|
||||
return this.userSettings.epubReaderSetting.fontSize;
|
||||
}
|
||||
|
||||
set fontSize(value: number) {
|
||||
this.userSettings.epubReaderSetting.fontSize = value;
|
||||
this.readerPreferencesService.updatePreference(['epubReaderSetting', 'fontSize'], value);
|
||||
}
|
||||
|
||||
increaseFontSize() {
|
||||
if (this.fontSize < 250) {
|
||||
this.fontSize += 10;
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize() {
|
||||
if (this.fontSize > 50) {
|
||||
this.fontSize -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
PDF Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of spreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedSpread">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (zoom of zooms; track zoom) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="zoom.key"
|
||||
name="zoom"
|
||||
[value]="zoom.key"
|
||||
[(ngModel)]="selectedZoom">
|
||||
</p-radiobutton>
|
||||
<label [for]="zoom.key">{{ zoom.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import {Component, inject, Input} from '@angular/core';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {ReaderPreferencesService} from '../reader-preferences-service';
|
||||
import {UserSettings} from '../../user-management/user.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-reader-preferences-component',
|
||||
imports: [
|
||||
RadioButton,
|
||||
FormsModule,
|
||||
Tooltip
|
||||
],
|
||||
templateUrl: './pdf-reader-preferences-component.html',
|
||||
styleUrl: './pdf-reader-preferences-component.scss'
|
||||
})
|
||||
export class PdfReaderPreferencesComponent {
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
@Input() userSettings!: UserSettings;
|
||||
|
||||
readonly spreads = [
|
||||
{name: 'Even', key: 'even'},
|
||||
{name: 'Odd', key: 'odd'},
|
||||
{name: 'None', key: 'off'}
|
||||
];
|
||||
|
||||
readonly zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto'},
|
||||
{name: 'Page Fit', key: 'page-fit'},
|
||||
{name: 'Page Width', key: 'page-width'},
|
||||
{name: 'Actual Size', key: 'page-actual'}
|
||||
];
|
||||
|
||||
get selectedSpread(): 'even' | 'odd' | 'off' {
|
||||
return this.userSettings.pdfReaderSetting.pageSpread;
|
||||
}
|
||||
|
||||
set selectedSpread(value: 'even' | 'odd' | 'off') {
|
||||
this.userSettings.pdfReaderSetting.pageSpread = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageSpread'], value);
|
||||
}
|
||||
|
||||
get selectedZoom(): string {
|
||||
return this.userSettings.pdfReaderSetting.pageZoom;
|
||||
}
|
||||
|
||||
set selectedZoom(value: string) {
|
||||
this.userSettings.pdfReaderSetting.pageZoom = value;
|
||||
this.readerPreferencesService.updatePreference(['pdfReaderSetting', 'pageZoom'], value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import {inject, Injectable} from '@angular/core';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ReaderPreferencesService {
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private currentUser: User | null = null;
|
||||
|
||||
constructor() {
|
||||
this.userService.userState$.subscribe(user => this.currentUser = user);
|
||||
}
|
||||
|
||||
updatePreference(path: string[], value: any): void {
|
||||
if (!this.currentUser) return;
|
||||
|
||||
let target: any = this.currentUser.userSettings;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
target = target[path[i]] ||= {};
|
||||
}
|
||||
target[path.at(-1)!] = value;
|
||||
|
||||
const [rootKey] = path;
|
||||
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||
|
||||
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preferences Updated',
|
||||
detail: 'Your preferences have been saved successfully.',
|
||||
life: 2000
|
||||
});
|
||||
}
|
||||
}
|
||||
+15
-156
@@ -1,13 +1,11 @@
|
||||
<div class="w-full h-[calc(100vh-12.1rem)] overflow-y-auto border rounded-lg enclosing-container">
|
||||
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-4 pt-4 ">
|
||||
Book Reader Settings: Global or Per-Book
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Select whether to apply the same reader settings (font, theme, spread, zoom, etc.) globally for all books or individually per book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
pTooltip="Select whether to apply the same reader settings (font, theme, spread, zoom, etc.) globally for all books or individually per book."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;">
|
||||
</i>
|
||||
</p>
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
@@ -26,7 +24,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Epub:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (item of scopeOptions; track item) {
|
||||
@@ -42,7 +39,6 @@
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">CBX:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (item of scopeOptions; track item) {
|
||||
@@ -60,159 +56,22 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p-divider></p-divider>
|
||||
|
||||
<app-epub-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-epub-reader-preferences-component>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
PDF Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of spreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedSpread"
|
||||
(ngModelChange)="onSpreadChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (zoom of zooms; track zoom) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="zoom.key"
|
||||
name="zoom"
|
||||
[value]="zoom.key"
|
||||
[(ngModel)]="selectedZoom"
|
||||
(ngModelChange)="onZoomChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="zoom.key">{{ zoom.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<app-pdf-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-pdf-reader-preferences-component>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
Epub Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Set global EPUB reader options such as themes, font families, and font sizes applied to all EPUBs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i></p>
|
||||
<app-cbx-reader-preferences-component
|
||||
[userSettings]="userSettings">
|
||||
</app-cbx-reader-preferences-component>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p>Theme:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="themes"
|
||||
[(ngModel)]="selectedTheme"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Theme"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onThemeChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Font:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="fonts"
|
||||
[(ngModel)]="selectedFont"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Font"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onFontChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p>Flow:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
<p-select
|
||||
size="small"
|
||||
[options]="flowOptions"
|
||||
[(ngModel)]="selectedFlow"
|
||||
optionLabel="name"
|
||||
optionValue="key"
|
||||
placeholder="Select a Flow"
|
||||
class="w-full md:w-32"
|
||||
(ngModelChange)="onFlowChange()">
|
||||
</p-select>
|
||||
</div>
|
||||
|
||||
<p class="py-1">Font Size:</p>
|
||||
<div class="flex gap-4 justify-start items-center">
|
||||
<p-button icon="pi pi-minus" size="small" (click)="decreaseFontSize()"></p-button>
|
||||
<p>{{ fontSize }}%</p>
|
||||
<p-button icon="pi pi-plus" size="small" (click)="increaseFontSize()"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p-divider></p-divider>
|
||||
|
||||
<div class="p-4">
|
||||
<p class="text-lg pb-6 pt-4 ">
|
||||
CBX Reader: Global Preferences
|
||||
<i class="pi pi-info-circle text-sky-600"
|
||||
pTooltip="Configure global PDF reading options such as page spread, zoom level, and sidebar visibility that apply to all PDFs."
|
||||
tooltipPosition="right"
|
||||
style="cursor: pointer;"></i>
|
||||
</p>
|
||||
|
||||
<div class="grid grid-cols-[auto,1fr] pl-6 gap-y-4 gap-x-4 items-center">
|
||||
<p class="py-1">Page Spread:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (spread of cbxSpreads; track spread) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="spread.key"
|
||||
name="spread"
|
||||
[value]="spread.key"
|
||||
[(ngModel)]="selectedCbxSpread"
|
||||
(ngModelChange)="onCbxSpreadChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="spread.key">{{ spread.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<p class="py-1">Page Zoom:</p>
|
||||
<div class="flex gap-4 justify-start">
|
||||
@for (mode of cbxViewModes; track mode) {
|
||||
<div class="flex items-center gap-2">
|
||||
<p-radiobutton
|
||||
[inputId]="mode.key"
|
||||
name="zoom"
|
||||
[value]="mode.key"
|
||||
[(ngModel)]="selectedCbxViewMode"
|
||||
(ngModelChange)="onCbxViewModeChange()">
|
||||
</p-radiobutton>
|
||||
<label [for]="mode.key">{{ mode.name }}</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,96 +2,40 @@ import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
|
||||
import {Observable, Subscription} from 'rxjs';
|
||||
import {Select} from 'primeng/select';
|
||||
import {RadioButton} from 'primeng/radiobutton';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {Button} from 'primeng/button';
|
||||
import {Tooltip} from 'primeng/tooltip';
|
||||
import {User, UserService, UserSettings} from '../user-management/user.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {CbxPageSpread, CbxPageViewMode} from '../../book/model/book.model';
|
||||
import {EpubReaderPreferencesComponent} from './epub-reader-preferences-component/epub-reader-preferences-component';
|
||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences-component/pdf-reader-preferences-component';
|
||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences-component/cbx-reader-preferences-component';
|
||||
import {ReaderPreferencesService} from './reader-preferences-service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-preferences',
|
||||
templateUrl: './reader-preferences.component.html',
|
||||
standalone: true,
|
||||
styleUrls: ['./reader-preferences.component.scss'],
|
||||
imports: [Select, FormsModule, RadioButton, Divider, Button, Tooltip]
|
||||
imports: [FormsModule, RadioButton, Divider, Tooltip, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent]
|
||||
})
|
||||
export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
|
||||
readonly cbxSpreads = [
|
||||
{name: 'Even', key: 'EVEN'},
|
||||
{name: 'Odd', key: 'ODD'}
|
||||
];
|
||||
|
||||
readonly cbxViewModes = [
|
||||
{name: 'Single Page', key: 'SINGLE_PAGE'},
|
||||
{name: 'Two Page', key: 'TWO_PAGE'},
|
||||
];
|
||||
|
||||
|
||||
readonly spreads = [
|
||||
{name: 'Even', key: 'even'},
|
||||
{name: 'Odd', key: 'odd'},
|
||||
{name: 'None', key: 'off'}
|
||||
];
|
||||
|
||||
readonly zooms = [
|
||||
{name: 'Auto Zoom', key: 'auto'},
|
||||
{name: 'Page Fit', key: 'page-fit'},
|
||||
{name: 'Page Width', key: 'page-width'},
|
||||
{name: 'Actual Size', key: 'page-actual'}
|
||||
];
|
||||
|
||||
readonly themes = [
|
||||
{name: 'White', key: 'white'},
|
||||
{name: 'Black', key: 'black'},
|
||||
{name: 'Grey', key: 'grey'},
|
||||
{name: 'Sepia', key: 'sepia'}
|
||||
];
|
||||
|
||||
readonly fonts = [
|
||||
{name: 'Serif', key: 'serif'},
|
||||
{name: 'Sans Serif', key: 'sans-serif'},
|
||||
{name: 'Roboto', key: 'roboto'},
|
||||
{name: 'Cursive', key: 'cursive'},
|
||||
{name: 'Monospace', key: 'monospace'}
|
||||
];
|
||||
|
||||
readonly flowOptions = [
|
||||
{name: 'Paginated', key: 'paginated'},
|
||||
{name: 'Scrolled', key: 'scrolled'}
|
||||
];
|
||||
|
||||
readonly scopeOptions = ['Global', 'Individual'];
|
||||
|
||||
selectedCbxSpread!: CbxPageSpread;
|
||||
selectedCbxViewMode!: CbxPageViewMode;
|
||||
|
||||
selectedSpread!: 'even' | 'odd' | 'off';
|
||||
selectedZoom!: string;
|
||||
selectedTheme!: string;
|
||||
selectedFont!: string;
|
||||
selectedFlow!: string;
|
||||
fontSize = 100;
|
||||
showSidebar = false;
|
||||
|
||||
selectedPdfScope!: string;
|
||||
selectedEpubScope!: string;
|
||||
selectedCbxScope!: string;
|
||||
|
||||
private readonly userService = inject(UserService);
|
||||
private readonly messageService = inject(MessageService);
|
||||
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||
|
||||
userData$: Observable<User | null> = this.userService.userState$;
|
||||
private subscription?: Subscription;
|
||||
private currentUser: User | null = null;
|
||||
userSettings!: UserSettings;
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscription = this.userData$.subscribe(user => {
|
||||
if (user) {
|
||||
this.currentUser = user;
|
||||
this.userSettings = user.userSettings;
|
||||
this.loadPreferences(user.userSettings);
|
||||
}
|
||||
});
|
||||
@@ -105,94 +49,17 @@ export class ReaderPreferences implements OnInit, OnDestroy {
|
||||
this.selectedPdfScope = settings.perBookSetting.pdf;
|
||||
this.selectedEpubScope = settings.perBookSetting.epub;
|
||||
this.selectedCbxScope = settings.perBookSetting.cbx;
|
||||
|
||||
this.selectedSpread = settings.pdfReaderSetting.pageSpread;
|
||||
this.selectedZoom = settings.pdfReaderSetting.pageZoom;
|
||||
this.showSidebar = settings.pdfReaderSetting.showSidebar;
|
||||
|
||||
this.selectedTheme = settings.epubReaderSetting.theme;
|
||||
this.selectedFlow = settings.epubReaderSetting.flow;
|
||||
this.fontSize = settings.epubReaderSetting.fontSize;
|
||||
this.selectedFont = settings.epubReaderSetting.font;
|
||||
|
||||
this.selectedCbxSpread = settings.cbxReaderSetting.pageSpread;
|
||||
this.selectedCbxViewMode = settings.cbxReaderSetting.pageViewMode;
|
||||
}
|
||||
|
||||
private updatePreference(path: string[], value: any): void {
|
||||
if (!this.currentUser) return;
|
||||
let target: any = this.currentUser.userSettings;
|
||||
for (let i = 0; i < path.length - 1; i++) {
|
||||
target = target[path[i]] ||= {};
|
||||
}
|
||||
target[path.at(-1)!] = value;
|
||||
|
||||
const [rootKey] = path;
|
||||
const updatedValue = this.currentUser.userSettings[rootKey as keyof UserSettings];
|
||||
this.userService.updateUserSetting(this.currentUser.id, rootKey, updatedValue);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: 'Preferences Updated',
|
||||
detail: 'Your preferences have been saved successfully.',
|
||||
life: 2000
|
||||
});
|
||||
}
|
||||
|
||||
onThemeChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'theme'], this.selectedTheme);
|
||||
}
|
||||
|
||||
onFontChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'font'], this.selectedFont);
|
||||
}
|
||||
|
||||
onFlowChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'flow'], this.selectedFlow);
|
||||
}
|
||||
|
||||
onFontSizeChange() {
|
||||
this.updatePreference(['epubReaderSetting', 'fontSize'], this.fontSize);
|
||||
}
|
||||
|
||||
onSpreadChange() {
|
||||
this.updatePreference(['pdfReaderSetting', 'pageSpread'], this.selectedSpread);
|
||||
}
|
||||
|
||||
onCbxSpreadChange() {
|
||||
this.updatePreference(['cbxReaderSetting', 'pageSpread'], this.selectedCbxSpread);
|
||||
}
|
||||
|
||||
onCbxViewModeChange() {
|
||||
this.updatePreference(['cbxReaderSetting', 'pageViewMode'], this.selectedCbxViewMode);
|
||||
}
|
||||
|
||||
onZoomChange() {
|
||||
this.updatePreference(['pdfReaderSetting', 'pageZoom'], this.selectedZoom);
|
||||
}
|
||||
|
||||
onPdfScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'pdf'], this.selectedPdfScope);
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'pdf'], this.selectedPdfScope);
|
||||
}
|
||||
|
||||
onEpubScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'epub'], this.selectedEpubScope);
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'epub'], this.selectedEpubScope);
|
||||
}
|
||||
|
||||
onCbxScopeChange() {
|
||||
this.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||
}
|
||||
|
||||
increaseFontSize() {
|
||||
if (this.fontSize < 250) {
|
||||
this.fontSize += 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
}
|
||||
|
||||
decreaseFontSize() {
|
||||
if (this.fontSize > 50) {
|
||||
this.fontSize -= 10;
|
||||
this.onFontSizeChange();
|
||||
}
|
||||
this.readerPreferencesService.updatePreference(['perBookSetting', 'cbx'], this.selectedCbxScope);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ export interface EpubReaderSetting {
|
||||
font: string;
|
||||
fontSize: number;
|
||||
flow: string;
|
||||
lineHeight: number;
|
||||
margin: number;
|
||||
letterSpacing: number;
|
||||
}
|
||||
|
||||
export interface CbxReaderSetting {
|
||||
|
||||
@@ -19,6 +19,11 @@ import {initializeAuthFactory} from './app/auth-initializer';
|
||||
|
||||
bootstrapApplication(AppComponent, {
|
||||
providers: [
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: themeInitializer,
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: APP_INITIALIZER,
|
||||
useFactory: websocketInitializer,
|
||||
@@ -52,3 +57,10 @@ bootstrapApplication(AppComponent, {
|
||||
})
|
||||
]
|
||||
}).catch(err => console.error(err));
|
||||
|
||||
export function themeInitializer(): () => void {
|
||||
return () => {
|
||||
document.documentElement.classList.add('p-dark');
|
||||
document.body.classList.add('p-dark');
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user