Add support for paginated and scrolled modes in EPUB reader
This commit is contained in:
committed by
Aditya Chandel
parent
98a4272abf
commit
9675820052
@@ -47,6 +47,7 @@ public class BookLoreUser {
|
|||||||
private String theme;
|
private String theme;
|
||||||
private String font;
|
private String font;
|
||||||
private int fontSize;
|
private int fontSize;
|
||||||
|
private String flow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
@@ -9,5 +9,6 @@ public class EpubViewerPreferences {
|
|||||||
private Long bookId;
|
private Long bookId;
|
||||||
private String theme;
|
private String theme;
|
||||||
private String font;
|
private String font;
|
||||||
|
private String flow;
|
||||||
private Integer fontSize;
|
private Integer fontSize;
|
||||||
}
|
}
|
||||||
+3
@@ -32,4 +32,7 @@ public class EpubViewerPreferencesEntity {
|
|||||||
|
|
||||||
@Column(name = "font_size")
|
@Column(name = "font_size")
|
||||||
private Integer fontSize;
|
private Integer fontSize;
|
||||||
|
|
||||||
|
@Column(name = "flow")
|
||||||
|
private String flow;
|
||||||
}
|
}
|
||||||
@@ -58,6 +58,7 @@ public class BooksService {
|
|||||||
.font(epubPref.getFont())
|
.font(epubPref.getFont())
|
||||||
.fontSize(epubPref.getFontSize())
|
.fontSize(epubPref.getFontSize())
|
||||||
.theme(epubPref.getTheme())
|
.theme(epubPref.getTheme())
|
||||||
|
.flow(epubPref.getFlow())
|
||||||
.build()));
|
.build()));
|
||||||
} else if (bookEntity.getBookType() == BookFileType.PDF) {
|
} else if (bookEntity.getBookType() == BookFileType.PDF) {
|
||||||
pdfViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
pdfViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
||||||
@@ -107,6 +108,7 @@ public class BooksService {
|
|||||||
epubPrefs.setFont(epubSettings.getFont());
|
epubPrefs.setFont(epubSettings.getFont());
|
||||||
epubPrefs.setFontSize(epubSettings.getFontSize());
|
epubPrefs.setFontSize(epubSettings.getFontSize());
|
||||||
epubPrefs.setTheme(epubSettings.getTheme());
|
epubPrefs.setTheme(epubSettings.getTheme());
|
||||||
|
epubPrefs.setFlow(epubSettings.getFlow());
|
||||||
epubViewerPreferencesRepository.save(epubPrefs);
|
epubViewerPreferencesRepository.save(epubPrefs);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+1
@@ -218,6 +218,7 @@ public class UserProvisioningService {
|
|||||||
.theme("white")
|
.theme("white")
|
||||||
.font("serif")
|
.font("serif")
|
||||||
.fontSize(150)
|
.fontSize(150)
|
||||||
|
.flow("paginated")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE epub_viewer_preference
|
||||||
|
ADD COLUMN flow VARCHAR(32) NULL;
|
||||||
+5
-2
@@ -33,6 +33,9 @@
|
|||||||
<p-divider></p-divider>
|
<p-divider></p-divider>
|
||||||
<label for="theme">Theme:</label>
|
<label for="theme">Theme:</label>
|
||||||
<p-select id="theme" [options]="themes" [(ngModel)]="selectedTheme" (onChange)="changeThemes()"></p-select>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</p-drawer>
|
</p-drawer>
|
||||||
@@ -42,7 +45,7 @@
|
|||||||
|
|
||||||
<div id="epubContainer" #epubContainer></div>
|
<div id="epubContainer" #epubContainer></div>
|
||||||
|
|
||||||
<button *ngIf="!isMobile" class="epub-controls-left" (click)="prevPage()">←</button>
|
<button *ngIf="selectedFlow !== 'scrolled'" class="epub-controls-left" (click)="prevPage()">←</button>
|
||||||
<button *ngIf="!isMobile" class="epub-controls-right" (click)="nextPage()">→</button>
|
<button *ngIf="selectedFlow !== 'scrolled'" class="epub-controls-right" (click)="nextPage()">→</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ const FALLBACK_EPUB_SETTINGS = {
|
|||||||
fontSize: 150,
|
fontSize: 150,
|
||||||
fontType: 'serif',
|
fontType: 'serif',
|
||||||
theme: 'white',
|
theme: 'white',
|
||||||
|
flow: 'paginated',
|
||||||
maxFontSize: 300,
|
maxFontSize: 300,
|
||||||
minFontSize: 50,
|
minFontSize: 50,
|
||||||
};
|
};
|
||||||
@@ -60,16 +61,15 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
currentChapter = '';
|
currentChapter = '';
|
||||||
isDrawerVisible = false;
|
isDrawerVisible = false;
|
||||||
isSettingsDrawerVisible = false;
|
isSettingsDrawerVisible = false;
|
||||||
isMobile = false;
|
|
||||||
private book: any;
|
private book: any;
|
||||||
private rendition: any;
|
private rendition: any;
|
||||||
private keyListener: (e: KeyboardEvent) => void = () => {
|
private keyListener: (e: KeyboardEvent) => void = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
fontSize = FALLBACK_EPUB_SETTINGS.fontSize;
|
fontSize = FALLBACK_EPUB_SETTINGS.fontSize;
|
||||||
selectedFontType = FALLBACK_EPUB_SETTINGS.fontType;
|
|
||||||
selectedTheme = FALLBACK_EPUB_SETTINGS.theme;
|
|
||||||
|
|
||||||
|
selectedFontType = FALLBACK_EPUB_SETTINGS.fontType;
|
||||||
fontTypes: any[] = [
|
fontTypes: any[] = [
|
||||||
{label: 'Serif', value: 'serif'},
|
{label: 'Serif', value: 'serif'},
|
||||||
{label: 'Sans Serif', value: 'sans-serif'},
|
{label: 'Sans Serif', value: 'sans-serif'},
|
||||||
@@ -78,6 +78,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
{label: 'Monospace', value: 'monospace'},
|
{label: 'Monospace', value: 'monospace'},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
selectedTheme = FALLBACK_EPUB_SETTINGS.theme;
|
||||||
themes: any[] = [
|
themes: any[] = [
|
||||||
{label: 'White', value: 'white'},
|
{label: 'White', value: 'white'},
|
||||||
{label: 'Black', value: 'black'},
|
{label: 'Black', value: 'black'},
|
||||||
@@ -85,6 +86,12 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
{label: 'Sepia', value: 'sepia'},
|
{label: 'Sepia', value: 'sepia'},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
selectedFlow = FALLBACK_EPUB_SETTINGS.flow;
|
||||||
|
flows: any[] = [
|
||||||
|
{label: 'Scrolled', value: 'scrolled'},
|
||||||
|
{label: 'Paginated', value: 'paginated'}
|
||||||
|
];
|
||||||
|
|
||||||
private route = inject(ActivatedRoute);
|
private route = inject(ActivatedRoute);
|
||||||
private userService = inject(UserService);
|
private userService = inject(UserService);
|
||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
@@ -115,8 +122,6 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
fileReader.onload = () => {
|
fileReader.onload = () => {
|
||||||
this.book = ePub(fileReader.result as ArrayBuffer);
|
this.book = ePub(fileReader.result as ArrayBuffer);
|
||||||
|
|
||||||
this.isMobile = window.innerWidth <= 768;
|
|
||||||
|
|
||||||
this.book.loaded.navigation.then((nav: any) => {
|
this.book.loaded.navigation.then((nav: any) => {
|
||||||
this.chapters = nav.toc.map((chapter: any) => ({
|
this.chapters = nav.toc.map((chapter: any) => ({
|
||||||
label: chapter.label,
|
label: chapter.label,
|
||||||
@@ -124,9 +129,15 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let globalOrIndividual = myself.userSettings.perBookSetting.epub;
|
||||||
|
|
||||||
|
const flow = globalOrIndividual === 'Global'
|
||||||
|
? myself.userSettings.epubReaderSetting.flow || 'paginated'
|
||||||
|
: individualSetting?.flow || myself.userSettings.epubReaderSetting.flow || 'paginated';
|
||||||
|
|
||||||
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, {
|
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, {
|
||||||
flow: this.isMobile ? 'scrolled' : 'paginated',
|
flow,
|
||||||
manager: this.isMobile ? 'continuous' : 'default',
|
manager: flow === 'scrolled' ? 'continuous' : 'default',
|
||||||
width: '100%',
|
width: '100%',
|
||||||
height: '100%',
|
height: '100%',
|
||||||
allowScriptedContent: true,
|
allowScriptedContent: true,
|
||||||
@@ -142,15 +153,16 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
this.rendition.themes.register(name, theme);
|
this.rendition.themes.register(name, theme);
|
||||||
});
|
});
|
||||||
|
|
||||||
let globalOrIndividual = myself.userSettings.perBookSetting.epub;
|
|
||||||
if (globalOrIndividual === 'Global') {
|
if (globalOrIndividual === 'Global') {
|
||||||
this.selectedTheme = myself.userSettings.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
|
this.selectedTheme = myself.userSettings.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
|
||||||
this.selectedFontType = myself.userSettings.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
|
this.selectedFontType = myself.userSettings.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
|
||||||
this.fontSize = myself.userSettings.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
this.fontSize = myself.userSettings.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
||||||
|
this.selectedFlow = myself.userSettings.epubReaderSetting.flow || FALLBACK_EPUB_SETTINGS.flow;
|
||||||
} else {
|
} else {
|
||||||
this.selectedTheme = individualSetting?.theme || myself.userSettings.epubReaderSetting.theme || FALLBACK_EPUB_SETTINGS.theme;
|
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.selectedFontType = individualSetting?.font || myself.userSettings.epubReaderSetting.font || FALLBACK_EPUB_SETTINGS.fontType;
|
||||||
this.fontSize = individualSetting?.fontSize || myself.userSettings.epubReaderSetting.fontSize || FALLBACK_EPUB_SETTINGS.fontSize;
|
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.select(this.selectedTheme);
|
||||||
@@ -172,6 +184,31 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeScrollMode(): void {
|
||||||
|
if (!this.rendition || !this.book) return;
|
||||||
|
|
||||||
|
const cfi = this.rendition.currentLocation()?.start?.cfi;
|
||||||
|
this.rendition.destroy();
|
||||||
|
|
||||||
|
this.rendition = this.book.renderTo(this.epubContainer.nativeElement, {
|
||||||
|
flow: this.selectedFlow,
|
||||||
|
manager: this.selectedFlow === 'scrolled' ? 'continuous' : 'default',
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
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.setupKeyListener();
|
||||||
|
this.trackProgress();
|
||||||
|
this.rendition.display(cfi || undefined);
|
||||||
|
this.updateViewerSetting();
|
||||||
|
}
|
||||||
|
|
||||||
changeThemes(): void {
|
changeThemes(): void {
|
||||||
if (this.rendition) {
|
if (this.rendition) {
|
||||||
this.rendition.themes.select(this.selectedTheme);
|
this.rendition.themes.select(this.selectedTheme);
|
||||||
@@ -211,6 +248,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
theme: this.selectedTheme,
|
theme: this.selectedTheme,
|
||||||
font: this.selectedFontType,
|
font: this.selectedFontType,
|
||||||
fontSize: this.fontSize,
|
fontSize: this.fontSize,
|
||||||
|
flow: this.selectedFlow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.bookService.updateViewerSetting(bookSetting, this.epub.id).subscribe();
|
this.bookService.updateViewerSetting(bookSetting, this.epub.id).subscribe();
|
||||||
@@ -333,5 +371,4 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ export interface EpubViewerSetting {
|
|||||||
theme: string;
|
theme: string;
|
||||||
font: string;
|
font: string;
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
|
flow: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BookSetting {
|
export interface BookSetting {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ export interface EpubReaderSetting {
|
|||||||
theme: string;
|
theme: string;
|
||||||
font: string;
|
font: string;
|
||||||
fontSize: number;
|
fontSize: number;
|
||||||
|
flow: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UserSettings {
|
export interface UserSettings {
|
||||||
|
|||||||
@@ -120,6 +120,19 @@
|
|||||||
</p-select>
|
</p-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>Flow:</p>
|
||||||
|
<div class="flex gap-4 justify-start">
|
||||||
|
<p-select
|
||||||
|
[options]="flowOptions"
|
||||||
|
[(ngModel)]="selectedFlow"
|
||||||
|
optionLabel="name"
|
||||||
|
optionValue="key"
|
||||||
|
placeholder="Select a Flow"
|
||||||
|
class="w-full md:w-56"
|
||||||
|
(ngModelChange)="onFlowChange()">
|
||||||
|
</p-select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p class="py-1">Font Size:</p>
|
<p class="py-1">Font Size:</p>
|
||||||
<div class="flex gap-4 justify-start items-center">
|
<div class="flex gap-4 justify-start items-center">
|
||||||
<p-button icon="pi pi-minus" rounded="true" size="small" (click)="decreaseFontSize()"></p-button>
|
<p-button icon="pi pi-minus" rounded="true" size="small" (click)="decreaseFontSize()"></p-button>
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
{name: 'Monospace', key: 'monospace'}
|
{name: 'Monospace', key: 'monospace'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
flowOptions = [
|
||||||
|
{name: 'Paginated', key: 'paginated'},
|
||||||
|
{name: 'Scrolled', key: 'scrolled'}
|
||||||
|
];
|
||||||
|
|
||||||
readonly sortingOptions = [
|
readonly sortingOptions = [
|
||||||
{label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
|
{label: 'Name | Ascending', value: {field: 'name', order: 'asc'}},
|
||||||
{label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
|
{label: 'Name | Descending', value: {field: 'name', order: 'desc'}},
|
||||||
@@ -59,6 +64,7 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
selectedZoom!: string;
|
selectedZoom!: string;
|
||||||
selectedTheme!: string;
|
selectedTheme!: string;
|
||||||
selectedFont!: string;
|
selectedFont!: string;
|
||||||
|
selectedFlow!: string;
|
||||||
fontSize = 100;
|
fontSize = 100;
|
||||||
showSidebar = false;
|
showSidebar = false;
|
||||||
selectedPdfScope!: string;
|
selectedPdfScope!: string;
|
||||||
@@ -93,6 +99,7 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
this.selectedZoom = settings.pdfReaderSetting.pageZoom;
|
this.selectedZoom = settings.pdfReaderSetting.pageZoom;
|
||||||
this.showSidebar = settings.pdfReaderSetting.showSidebar;
|
this.showSidebar = settings.pdfReaderSetting.showSidebar;
|
||||||
this.selectedTheme = settings.epubReaderSetting.theme;
|
this.selectedTheme = settings.epubReaderSetting.theme;
|
||||||
|
this.selectedFlow = settings.epubReaderSetting.flow;
|
||||||
this.fontSize = settings.epubReaderSetting.fontSize;
|
this.fontSize = settings.epubReaderSetting.fontSize;
|
||||||
this.selectedFont = settings.epubReaderSetting.font;
|
this.selectedFont = settings.epubReaderSetting.font;
|
||||||
this.selectedLibrarySorting = settings.sidebarLibrarySorting;
|
this.selectedLibrarySorting = settings.sidebarLibrarySorting;
|
||||||
@@ -126,6 +133,10 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
this.updatePreference(['epubReaderSetting', 'font'], this.selectedFont);
|
this.updatePreference(['epubReaderSetting', 'font'], this.selectedFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFlowChange() {
|
||||||
|
this.updatePreference(['epubReaderSetting', 'flow'], this.selectedFlow);
|
||||||
|
}
|
||||||
|
|
||||||
onFontSizeChange() {
|
onFontSizeChange() {
|
||||||
this.updatePreference(['epubReaderSetting', 'fontSize'], this.fontSize);
|
this.updatePreference(['epubReaderSetting', 'fontSize'], this.fontSize);
|
||||||
}
|
}
|
||||||
@@ -167,5 +178,4 @@ export class UserPreferences implements OnInit, OnDestroy {
|
|||||||
this.onFontSizeChange();
|
this.onFontSizeChange();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user