diff --git a/assets/favicons/android-chrome-192x192.png b/assets/favicons/android-chrome-192x192.png new file mode 100644 index 000000000..fa240f271 Binary files /dev/null and b/assets/favicons/android-chrome-192x192.png differ diff --git a/assets/favicons/android-chrome-512x512.png b/assets/favicons/android-chrome-512x512.png new file mode 100644 index 000000000..a80c070a9 Binary files /dev/null and b/assets/favicons/android-chrome-512x512.png differ diff --git a/assets/favicons/apple-touch-icon-114x114.png b/assets/favicons/apple-touch-icon-114x114.png new file mode 100644 index 000000000..bf014839f Binary files /dev/null and b/assets/favicons/apple-touch-icon-114x114.png differ diff --git a/assets/favicons/apple-touch-icon-120x120.png b/assets/favicons/apple-touch-icon-120x120.png new file mode 100644 index 000000000..858c51567 Binary files /dev/null and b/assets/favicons/apple-touch-icon-120x120.png differ diff --git a/assets/favicons/apple-touch-icon-144x144.png b/assets/favicons/apple-touch-icon-144x144.png new file mode 100644 index 000000000..761fe8a9c Binary files /dev/null and b/assets/favicons/apple-touch-icon-144x144.png differ diff --git a/assets/favicons/apple-touch-icon-152x152.png b/assets/favicons/apple-touch-icon-152x152.png new file mode 100644 index 000000000..88537b5c6 Binary files /dev/null and b/assets/favicons/apple-touch-icon-152x152.png differ diff --git a/assets/favicons/apple-touch-icon-167x167.png b/assets/favicons/apple-touch-icon-167x167.png new file mode 100644 index 000000000..2171d5184 Binary files /dev/null and b/assets/favicons/apple-touch-icon-167x167.png differ diff --git a/assets/favicons/apple-touch-icon-180x180.png b/assets/favicons/apple-touch-icon-180x180.png new file mode 100644 index 000000000..b7ddcb12a Binary files /dev/null and b/assets/favicons/apple-touch-icon-180x180.png differ diff --git a/assets/favicons/apple-touch-icon-57x57.png b/assets/favicons/apple-touch-icon-57x57.png new file mode 100644 index 000000000..bacb8e20b Binary files /dev/null and b/assets/favicons/apple-touch-icon-57x57.png differ diff --git a/assets/favicons/apple-touch-icon-60x60.png b/assets/favicons/apple-touch-icon-60x60.png new file mode 100644 index 000000000..9d75ba987 Binary files /dev/null and b/assets/favicons/apple-touch-icon-60x60.png differ diff --git a/assets/favicons/apple-touch-icon-72x72.png b/assets/favicons/apple-touch-icon-72x72.png new file mode 100644 index 000000000..c71fcc9eb Binary files /dev/null and b/assets/favicons/apple-touch-icon-72x72.png differ diff --git a/assets/favicons/apple-touch-icon-76x76.png b/assets/favicons/apple-touch-icon-76x76.png new file mode 100644 index 000000000..7b2654289 Binary files /dev/null and b/assets/favicons/apple-touch-icon-76x76.png differ diff --git a/assets/favicons/favicon-128x128.png b/assets/favicons/favicon-128x128.png new file mode 100644 index 000000000..492fef2f2 Binary files /dev/null and b/assets/favicons/favicon-128x128.png differ diff --git a/assets/favicons/favicon-16x16.png b/assets/favicons/favicon-16x16.png new file mode 100644 index 000000000..f9b88af57 Binary files /dev/null and b/assets/favicons/favicon-16x16.png differ diff --git a/assets/favicons/favicon-196x196.png b/assets/favicons/favicon-196x196.png new file mode 100644 index 000000000..4e76409eb Binary files /dev/null and b/assets/favicons/favicon-196x196.png differ diff --git a/assets/favicons/favicon-32x32.png b/assets/favicons/favicon-32x32.png new file mode 100644 index 000000000..fd56b6cfd Binary files /dev/null and b/assets/favicons/favicon-32x32.png differ diff --git a/assets/favicons/favicon-96x96.png b/assets/favicons/favicon-96x96.png new file mode 100644 index 000000000..3198eea09 Binary files /dev/null and b/assets/favicons/favicon-96x96.png differ diff --git a/assets/favicons/mstile-144x144.png b/assets/favicons/mstile-144x144.png new file mode 100644 index 000000000..761fe8a9c Binary files /dev/null and b/assets/favicons/mstile-144x144.png differ diff --git a/assets/favicons/mstile-150x150.png b/assets/favicons/mstile-150x150.png new file mode 100644 index 000000000..9490be72d Binary files /dev/null and b/assets/favicons/mstile-150x150.png differ diff --git a/assets/favicons/mstile-310x150.png b/assets/favicons/mstile-310x150.png new file mode 100644 index 000000000..0893071d8 Binary files /dev/null and b/assets/favicons/mstile-310x150.png differ diff --git a/assets/favicons/mstile-310x310.png b/assets/favicons/mstile-310x310.png new file mode 100644 index 000000000..944871ba2 Binary files /dev/null and b/assets/favicons/mstile-310x310.png differ diff --git a/assets/favicons/mstile-70x70.png b/assets/favicons/mstile-70x70.png new file mode 100644 index 000000000..82cf7b115 Binary files /dev/null and b/assets/favicons/mstile-70x70.png differ diff --git a/assets/logo with text.svg b/assets/logo with text.svg new file mode 100644 index 000000000..1f13f6179 --- /dev/null +++ b/assets/logo with text.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/assets/logo.svg b/assets/logo.svg new file mode 100644 index 000000000..cd8230fa2 --- /dev/null +++ b/assets/logo.svg @@ -0,0 +1,4 @@ + + + + diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java index c827fde4d..64e8c2930 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/BookLoreUser.java @@ -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; } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/EpubViewerPreferences.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/EpubViewerPreferences.java index 1c8382f86..f6360a2e1 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/EpubViewerPreferences.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/dto/EpubViewerPreferences.java @@ -11,4 +11,6 @@ public class EpubViewerPreferences { private String font; private String flow; private Integer fontSize; + private Float letterSpacing; + private Float lineHeight; } \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/EpubViewerPreferencesEntity.java b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/EpubViewerPreferencesEntity.java index b961dfa3e..412c987a2 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/EpubViewerPreferencesEntity.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/model/entity/EpubViewerPreferencesEntity.java @@ -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; } \ No newline at end of file diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/BookService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/BookService.java index 4ae60f683..fe703c043 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/BookService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/BookService.java @@ -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) { diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java index a2cd0e2f5..56db0a6d5 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/user/DefaultUserSettingsProvider.java @@ -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(); } diff --git a/booklore-api/src/main/resources/db/migration/V34__Add_letter_spacing_and_line_height_for_epub_settings.sql b/booklore-api/src/main/resources/db/migration/V34__Add_letter_spacing_and_line_height_for_epub_settings.sql new file mode 100644 index 000000000..09edadb6d --- /dev/null +++ b/booklore-api/src/main/resources/db/migration/V34__Add_letter_spacing_and_line_height_for_epub_settings.sql @@ -0,0 +1,3 @@ +ALTER TABLE epub_viewer_preference + ADD COLUMN letter_spacing FLOAT NULL, + ADD COLUMN line_height FLOAT NULL; \ No newline at end of file diff --git a/booklore-ui/angular.json b/booklore-ui/angular.json index 2a1d08f05..e2fa177ea 100644 --- a/booklore-ui/angular.json +++ b/booklore-ui/angular.json @@ -33,7 +33,6 @@ "tsConfig": "tsconfig.app.json", "inlineStyleLanguage": "scss", "assets": [ - "src/favicon.ico", "src/assets", { "glob": "**/*", diff --git a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html index f6ccbd4ff..9537388ca 100644 --- a/booklore-ui/src/app/book/components/book-browser/book-browser.component.html +++ b/booklore-ui/src/app/book/components/book-browser/book-browser.component.html @@ -146,7 +146,6 @@ +
Filter Mode -
-
-

Font Size: {{ fontSize }}%

-
- - +
+ +
+ Font Size: +
+ + {{ fontSize }}% +
- - - - - - - - -
+ + + +
+ + + +
+ + + +
+ +
+ @for (theme of themes; track theme) { + + } +
+
+ + + +
+ +
+
+ + + +
+
+ + + +
+
+
+ + + +
+ + + +
+ +
+ + + +
+
diff --git a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.scss b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.scss index 48616752d..0d72d1af3 100644 --- a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.scss +++ b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.scss @@ -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; +} diff --git a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts index 79f9acf2f..b73deb188 100644 --- a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts +++ b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts @@ -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([ - [ - '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(); + } } diff --git a/booklore-ui/src/app/book/components/epub-viewer/epub-reader-helper.ts b/booklore-ui/src/app/book/components/epub-viewer/epub-reader-helper.ts new file mode 100644 index 000000000..a81cd3431 --- /dev/null +++ b/booklore-ui/src/app/book/components/epub-viewer/epub-reader-helper.ts @@ -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); +} diff --git a/booklore-ui/src/app/book/components/epub-viewer/epub-theme-util.ts b/booklore-ui/src/app/book/components/epub-viewer/epub-theme-util.ts new file mode 100644 index 000000000..9ce619ae7 --- /dev/null +++ b/booklore-ui/src/app/book/components/epub-viewer/epub-theme-util.ts @@ -0,0 +1,60 @@ +export class EpubThemeUtil { + static readonly themesMap = new Map([ + ['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'); + } +} diff --git a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html index de03693ad..45c431bee 100644 --- a/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html +++ b/booklore-ui/src/app/book/metadata/book-metadata-center/metadata-editor/metadata-editor.component.html @@ -1,5 +1,5 @@ @if (book$ | async; as book) { -
+ @if (isLoading) {
} diff --git a/booklore-ui/src/app/book/model/book.model.ts b/booklore-ui/src/app/book/model/book.model.ts index 72321d3e8..849e21faa 100644 --- a/booklore-ui/src/app/book/model/book.model.ts +++ b/booklore-ui/src/app/book/model/book.model.ts @@ -110,6 +110,8 @@ export interface EpubViewerSetting { font: string; fontSize: number; flow: string; + lineHeight: number; + letterSpacing: number; } export interface CbxViewerSetting { diff --git a/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html b/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html index 1604b2658..fff06bcb9 100644 --- a/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html +++ b/booklore-ui/src/app/layout/component/layout-topbar/app.topbar.component.html @@ -1,7 +1,11 @@
-