Revamp streaming PDF reader to render pages on demand (#2332)
Co-authored-by: acx10 <acx10@users.noreply.github.com>
This commit is contained in:
+9
-3
@@ -1,5 +1,6 @@
|
|||||||
package com.adityachandel.booklore.controller;
|
package com.adityachandel.booklore.controller;
|
||||||
|
|
||||||
|
import com.adityachandel.booklore.model.dto.response.PdfBookInfo;
|
||||||
import com.adityachandel.booklore.service.reader.PdfReaderService;
|
import com.adityachandel.booklore.service.reader.PdfReaderService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -11,7 +12,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@@ -25,8 +25,14 @@ public class PdfReaderController {
|
|||||||
@Operation(summary = "List pages in a PDF book", description = "Retrieve a list of available page numbers for a PDF book.")
|
@Operation(summary = "List pages in a PDF book", description = "Retrieve a list of available page numbers for a PDF book.")
|
||||||
@ApiResponse(responseCode = "200", description = "Page numbers returned successfully")
|
@ApiResponse(responseCode = "200", description = "Page numbers returned successfully")
|
||||||
@GetMapping("/{bookId}/pages")
|
@GetMapping("/{bookId}/pages")
|
||||||
public List<Integer> listPages(
|
public List<Integer> listPages(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||||
@Parameter(description = "ID of the book") @PathVariable Long bookId) throws IOException {
|
|
||||||
return pdfReaderService.getAvailablePages(bookId);
|
return pdfReaderService.getAvailablePages(bookId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "Get book info for a PDF book", description = "Retrieve book information including page count and hierarchical outline/table of contents.")
|
||||||
|
@ApiResponse(responseCode = "200", description = "Book info returned successfully")
|
||||||
|
@GetMapping("/{bookId}/info")
|
||||||
|
public PdfBookInfo getBookInfo(@Parameter(description = "ID of the book") @PathVariable Long bookId) {
|
||||||
|
return pdfReaderService.getBookInfo(bookId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -195,6 +195,9 @@ public class BookLoreUser {
|
|||||||
public static class NewPdfReaderSetting {
|
public static class NewPdfReaderSetting {
|
||||||
private NewPdfPageSpread pageSpread;
|
private NewPdfPageSpread pageSpread;
|
||||||
private NewPdfPageViewMode pageViewMode;
|
private NewPdfPageViewMode pageViewMode;
|
||||||
|
private NewPdfBackgroundColor backgroundColor;
|
||||||
|
private NewPdfPageFitMode fitMode;
|
||||||
|
private NewPdfPageScrollMode scrollMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
+4
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.adityachandel.booklore.model.dto;
|
package com.adityachandel.booklore.model.dto;
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.enums.NewPdfPageViewMode;
|
import com.adityachandel.booklore.model.enums.*;
|
||||||
import com.adityachandel.booklore.model.enums.NewPdfPageSpread;
|
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -11,4 +10,7 @@ public class NewPdfViewerPreferences {
|
|||||||
private Long bookId;
|
private Long bookId;
|
||||||
private NewPdfPageSpread pageSpread;
|
private NewPdfPageSpread pageSpread;
|
||||||
private NewPdfPageViewMode pageViewMode;
|
private NewPdfPageViewMode pageViewMode;
|
||||||
|
private NewPdfBackgroundColor backgroundColor;
|
||||||
|
private NewPdfPageFitMode fitMode;
|
||||||
|
private NewPdfPageScrollMode scrollMode;
|
||||||
}
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package com.adityachandel.booklore.model.dto.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PdfBookInfo {
|
||||||
|
private int pageCount;
|
||||||
|
private List<PdfOutlineItem> outline;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.adityachandel.booklore.model.dto.response;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PdfOutlineItem {
|
||||||
|
private String title;
|
||||||
|
private Integer pageNumber;
|
||||||
|
private List<PdfOutlineItem> children;
|
||||||
|
}
|
||||||
+13
-2
@@ -1,7 +1,6 @@
|
|||||||
package com.adityachandel.booklore.model.entity;
|
package com.adityachandel.booklore.model.entity;
|
||||||
|
|
||||||
import com.adityachandel.booklore.model.enums.NewPdfPageSpread;
|
import com.adityachandel.booklore.model.enums.*;
|
||||||
import com.adityachandel.booklore.model.enums.NewPdfPageViewMode;
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
@@ -33,4 +32,16 @@ public class NewPdfViewerPreferencesEntity {
|
|||||||
@Column(name = "view_mode")
|
@Column(name = "view_mode")
|
||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private NewPdfPageViewMode pageViewMode;
|
private NewPdfPageViewMode pageViewMode;
|
||||||
|
|
||||||
|
@Column(name = "fit_mode")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private NewPdfPageFitMode fitMode;
|
||||||
|
|
||||||
|
@Column(name = "scroll_mode")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private NewPdfPageScrollMode scrollMode;
|
||||||
|
|
||||||
|
@Column(name = "background_color")
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private NewPdfBackgroundColor backgroundColor;
|
||||||
}
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package com.adityachandel.booklore.model.enums;
|
||||||
|
|
||||||
|
public enum NewPdfBackgroundColor {
|
||||||
|
GRAY,
|
||||||
|
BLACK,
|
||||||
|
WHITE
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package com.adityachandel.booklore.model.enums;
|
||||||
|
|
||||||
|
public enum NewPdfPageFitMode {
|
||||||
|
ACTUAL_SIZE,
|
||||||
|
FIT_PAGE,
|
||||||
|
FIT_WIDTH,
|
||||||
|
FIT_HEIGHT,
|
||||||
|
AUTO
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
package com.adityachandel.booklore.model.enums;
|
||||||
|
|
||||||
|
public enum NewPdfPageScrollMode {
|
||||||
|
PAGINATED,
|
||||||
|
INFINITE
|
||||||
|
}
|
||||||
@@ -3,14 +3,6 @@ package com.adityachandel.booklore.model.enums;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public enum TaskType {
|
public enum TaskType {
|
||||||
CLEAR_PDF_CACHE(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
"Clear PDF Cache",
|
|
||||||
"Clears temporarily generated images used by the streaming PDF reader."
|
|
||||||
),
|
|
||||||
REFRESH_LIBRARY_METADATA(
|
REFRESH_LIBRARY_METADATA(
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
|||||||
@@ -164,6 +164,9 @@ public class BookService {
|
|||||||
.bookId(bookId)
|
.bookId(bookId)
|
||||||
.pageViewMode(pdfPref.getPageViewMode())
|
.pageViewMode(pdfPref.getPageViewMode())
|
||||||
.pageSpread(pdfPref.getPageSpread())
|
.pageSpread(pdfPref.getPageSpread())
|
||||||
|
.fitMode(pdfPref.getFitMode())
|
||||||
|
.scrollMode(pdfPref.getScrollMode())
|
||||||
|
.backgroundColor(pdfPref.getBackgroundColor())
|
||||||
.build()));
|
.build()));
|
||||||
} else if (bookType == BookFileType.CBX) {
|
} else if (bookType == BookFileType.CBX) {
|
||||||
cbxViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
cbxViewerPreferencesRepository.findByBookIdAndUserId(bookId, user.getId())
|
||||||
|
|||||||
+3
@@ -181,6 +181,9 @@ public class BookUpdateService {
|
|||||||
NewPdfViewerPreferences pdfSettings = settings.getNewPdfSettings();
|
NewPdfViewerPreferences pdfSettings = settings.getNewPdfSettings();
|
||||||
prefs.setPageSpread(pdfSettings.getPageSpread());
|
prefs.setPageSpread(pdfSettings.getPageSpread());
|
||||||
prefs.setPageViewMode(pdfSettings.getPageViewMode());
|
prefs.setPageViewMode(pdfSettings.getPageViewMode());
|
||||||
|
prefs.setFitMode(pdfSettings.getFitMode());
|
||||||
|
prefs.setScrollMode(pdfSettings.getScrollMode());
|
||||||
|
prefs.setBackgroundColor(pdfSettings.getBackgroundColor());
|
||||||
newPdfViewerPreferencesRepository.save(prefs);
|
newPdfViewerPreferencesRepository.save(prefs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+171
-82
@@ -1,142 +1,231 @@
|
|||||||
package com.adityachandel.booklore.service.reader;
|
package com.adityachandel.booklore.service.reader;
|
||||||
|
|
||||||
import com.adityachandel.booklore.exception.ApiError;
|
import com.adityachandel.booklore.exception.ApiError;
|
||||||
|
import com.adityachandel.booklore.model.dto.response.PdfBookInfo;
|
||||||
|
import com.adityachandel.booklore.model.dto.response.PdfOutlineItem;
|
||||||
import com.adityachandel.booklore.model.entity.BookEntity;
|
import com.adityachandel.booklore.model.entity.BookEntity;
|
||||||
import com.adityachandel.booklore.repository.BookRepository;
|
import com.adityachandel.booklore.repository.BookRepository;
|
||||||
import com.adityachandel.booklore.service.appsettings.AppSettingService;
|
|
||||||
import com.adityachandel.booklore.util.FileService;
|
|
||||||
import com.adityachandel.booklore.util.FileUtils;
|
import com.adityachandel.booklore.util.FileUtils;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.pdfbox.Loader;
|
import org.apache.pdfbox.Loader;
|
||||||
import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
|
import org.apache.pdfbox.io.RandomAccessReadBufferedFile;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
import org.apache.pdfbox.pdmodel.PDPage;
|
||||||
|
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
|
||||||
|
import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
|
||||||
import org.apache.pdfbox.rendering.ImageType;
|
import org.apache.pdfbox.rendering.ImageType;
|
||||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PdfReaderService {
|
public class PdfReaderService {
|
||||||
|
|
||||||
private static final String CACHE_INFO_FILENAME = ".cache-info";
|
private static final int MAX_CACHE_ENTRIES = 50;
|
||||||
private static final Pattern NON_DIGIT_PATTERN = Pattern.compile("\\D+");
|
private static final float DEFAULT_DPI = 200f;
|
||||||
|
|
||||||
private final BookRepository bookRepository;
|
private final BookRepository bookRepository;
|
||||||
private final AppSettingService appSettingService;
|
private final Map<String, CachedPdfMetadata> metadataCache = new ConcurrentHashMap<>();
|
||||||
private final FileService fileService;
|
|
||||||
|
|
||||||
public List<Integer> getAvailablePages(Long bookId) throws IOException {
|
private static class CachedPdfMetadata {
|
||||||
BookEntity bookEntity = bookRepository.findById(bookId).orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
final int pageCount;
|
||||||
String bookFullPath = FileUtils.getBookFullPath(bookEntity);
|
final long lastModified;
|
||||||
|
final List<PdfOutlineItem> outline;
|
||||||
|
volatile long lastAccessed;
|
||||||
|
|
||||||
Path pdfPath = Path.of(bookFullPath);
|
CachedPdfMetadata(int pageCount, long lastModified, List<PdfOutlineItem> outline) {
|
||||||
Path cacheDir = Path.of(fileService.getPdfCachePath(), String.valueOf(bookId));
|
this.pageCount = pageCount;
|
||||||
Path cacheInfoPath = cacheDir.resolve(CACHE_INFO_FILENAME);
|
this.lastModified = lastModified;
|
||||||
long maxCacheSizeBytes = appSettingService.getAppSettings().getPdfCacheSizeInMb() * 1024L * 1024L;
|
this.outline = outline;
|
||||||
long estimatedSize = Files.size(pdfPath);
|
this.lastAccessed = System.currentTimeMillis();
|
||||||
if (estimatedSize > maxCacheSizeBytes) {
|
}
|
||||||
log.warn("Cache skipped: Estimated PDF size {} exceeds max cache size {}", estimatedSize, maxCacheSizeBytes);
|
|
||||||
throw ApiError.CACHE_TOO_LARGE.createException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Integer> getAvailablePages(Long bookId) {
|
||||||
|
Path pdfPath = getBookPath(bookId);
|
||||||
try {
|
try {
|
||||||
if (needsCacheRefresh(pdfPath, cacheInfoPath)) {
|
CachedPdfMetadata metadata = getCachedMetadata(pdfPath);
|
||||||
log.info("Invalidating cache for PDF book {}", bookId);
|
return IntStream.rangeClosed(1, metadata.pageCount)
|
||||||
if (Files.exists(cacheDir)) FileUtils.deleteDirectoryRecursively(cacheDir);
|
.boxed()
|
||||||
Files.createDirectories(cacheDir);
|
.collect(Collectors.toList());
|
||||||
extractPdfPages(pdfPath, cacheDir);
|
} catch (IOException e) {
|
||||||
writeCacheInfo(pdfPath, cacheInfoPath);
|
log.error("Failed to read PDF for book {}", bookId, e);
|
||||||
|
throw ApiError.FILE_READ_ERROR.createException("Failed to read PDF: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Stream<Path> stream = Files.list(cacheDir)) {
|
public PdfBookInfo getBookInfo(Long bookId) {
|
||||||
return stream
|
Path pdfPath = getBookPath(bookId);
|
||||||
.filter(p -> p.toString().endsWith(".jpg"))
|
try {
|
||||||
.sorted()
|
CachedPdfMetadata metadata = getCachedMetadata(pdfPath);
|
||||||
.map(p -> extractPageNumber(p.getFileName().toString()))
|
return PdfBookInfo.builder()
|
||||||
.filter(p -> p != -1)
|
.pageCount(metadata.pageCount)
|
||||||
.collect(Collectors.toList());
|
.outline(metadata.outline)
|
||||||
}
|
.build();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to extract pages for book {}", bookId, e);
|
log.error("Failed to read PDF for book {}", bookId, e);
|
||||||
throw new UncheckedIOException("Failed to extract pages from PDF for bookId: " + bookId, e);
|
throw ApiError.FILE_READ_ERROR.createException("Failed to read PDF: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void streamPageImage(Long bookId, int page, OutputStream outputStream) throws IOException {
|
public void streamPageImage(Long bookId, int page, OutputStream outputStream) throws IOException {
|
||||||
Path pagePath = Path.of(fileService.getPdfCachePath(), String.valueOf(bookId), String.format("%04d.jpg", page));
|
Path pdfPath = getBookPath(bookId);
|
||||||
if (!Files.exists(pagePath)) throw new FileNotFoundException("Page not found: " + page);
|
CachedPdfMetadata metadata = getCachedMetadata(pdfPath);
|
||||||
try (InputStream in = Files.newInputStream(pagePath)) {
|
validatePageRequest(bookId, page, metadata.pageCount);
|
||||||
try {
|
renderPageToStream(pdfPath, page, outputStream);
|
||||||
in.transferTo(outputStream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Error streaming page {} of book {}", page, bookId, e);
|
|
||||||
throw new UncheckedIOException("Failed to stream PDF page image for bookId: " + bookId, e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Path getBookPath(Long bookId) {
|
||||||
|
BookEntity bookEntity = bookRepository.findById(bookId)
|
||||||
|
.orElseThrow(() -> ApiError.BOOK_NOT_FOUND.createException(bookId));
|
||||||
|
String bookFullPath = FileUtils.getBookFullPath(bookEntity);
|
||||||
|
return Path.of(bookFullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validatePageRequest(Long bookId, int page, int pageCount) throws FileNotFoundException {
|
||||||
|
if (pageCount == 0) {
|
||||||
|
throw new FileNotFoundException("No pages found for book: " + bookId);
|
||||||
|
}
|
||||||
|
if (page < 1 || page > pageCount) {
|
||||||
|
throw new FileNotFoundException("Page " + page + " out of range [1-" + pageCount + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractPdfPages(Path pdfPath, Path targetDir) throws IOException {
|
private CachedPdfMetadata getCachedMetadata(Path pdfPath) throws IOException {
|
||||||
|
String cacheKey = pdfPath.toString();
|
||||||
|
long currentModified = Files.getLastModifiedTime(pdfPath).toMillis();
|
||||||
|
CachedPdfMetadata cached = metadataCache.get(cacheKey);
|
||||||
|
if (cached != null && cached.lastModified == currentModified) {
|
||||||
|
cached.lastAccessed = System.currentTimeMillis();
|
||||||
|
log.debug("Cache hit for PDF: {}", pdfPath.getFileName());
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
log.debug("Cache miss for PDF: {}, scanning...", pdfPath.getFileName());
|
||||||
|
CachedPdfMetadata newMetadata = scanPdfMetadata(pdfPath);
|
||||||
|
metadataCache.put(cacheKey, newMetadata);
|
||||||
|
evictOldestCacheEntries();
|
||||||
|
return newMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CachedPdfMetadata scanPdfMetadata(Path pdfPath) throws IOException {
|
||||||
if (!Files.isReadable(pdfPath)) {
|
if (!Files.isReadable(pdfPath)) {
|
||||||
throw new FileNotFoundException("PDF file is not readable: " + pdfPath);
|
throw new FileNotFoundException("PDF file is not readable: " + pdfPath);
|
||||||
}
|
}
|
||||||
|
long lastModified = Files.getLastModifiedTime(pdfPath).toMillis();
|
||||||
|
try (RandomAccessReadBufferedFile randomAccessRead = new RandomAccessReadBufferedFile(pdfPath.toFile());
|
||||||
|
PDDocument document = Loader.loadPDF(randomAccessRead)) {
|
||||||
|
int pageCount = document.getNumberOfPages();
|
||||||
|
List<PdfOutlineItem> outline = extractOutline(document);
|
||||||
|
return new CachedPdfMetadata(pageCount, lastModified, outline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PdfOutlineItem> extractOutline(PDDocument document) {
|
||||||
|
List<PdfOutlineItem> outline = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PDDocumentOutline documentOutline = document.getDocumentCatalog().getDocumentOutline();
|
||||||
|
if (documentOutline != null) {
|
||||||
|
PDOutlineItem item = documentOutline.getFirstChild();
|
||||||
|
while (item != null) {
|
||||||
|
PdfOutlineItem outlineItem = buildOutlineItem(document, item);
|
||||||
|
if (outlineItem != null) {
|
||||||
|
outline.add(outlineItem);
|
||||||
|
}
|
||||||
|
item = item.getNextSibling();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Failed to extract PDF outline: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
return outline;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PdfOutlineItem buildOutlineItem(PDDocument document, PDOutlineItem item) {
|
||||||
|
try {
|
||||||
|
String title = item.getTitle();
|
||||||
|
if (title == null || title.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer pageNumber = null;
|
||||||
|
try {
|
||||||
|
PDPage page = item.findDestinationPage(document);
|
||||||
|
if (page != null) {
|
||||||
|
int pageIndex = document.getPages().indexOf(page);
|
||||||
|
if (pageIndex >= 0) {
|
||||||
|
pageNumber = pageIndex + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Failed to get page for outline item '{}': {}", title, e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PdfOutlineItem> children = new ArrayList<>();
|
||||||
|
PDOutlineItem child = item.getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
PdfOutlineItem childItem = buildOutlineItem(document, child);
|
||||||
|
if (childItem != null) {
|
||||||
|
children.add(childItem);
|
||||||
|
}
|
||||||
|
child = child.getNextSibling();
|
||||||
|
}
|
||||||
|
|
||||||
|
return PdfOutlineItem.builder()
|
||||||
|
.title(title.trim())
|
||||||
|
.pageNumber(pageNumber)
|
||||||
|
.children(children.isEmpty() ? null : children)
|
||||||
|
.build();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.debug("Failed to process outline item: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void evictOldestCacheEntries() {
|
||||||
|
if (metadataCache.size() <= MAX_CACHE_ENTRIES) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> keysToRemove = metadataCache.entrySet().stream()
|
||||||
|
.sorted(Comparator.comparingLong(e -> e.getValue().lastAccessed))
|
||||||
|
.limit(metadataCache.size() - MAX_CACHE_ENTRIES)
|
||||||
|
.map(Map.Entry::getKey)
|
||||||
|
.toList();
|
||||||
|
keysToRemove.forEach(key -> {
|
||||||
|
metadataCache.remove(key);
|
||||||
|
log.debug("Evicted cache entry: {}", key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderPageToStream(Path pdfPath, int page, OutputStream outputStream) throws IOException {
|
||||||
try (RandomAccessReadBufferedFile randomAccessRead = new RandomAccessReadBufferedFile(pdfPath.toFile());
|
try (RandomAccessReadBufferedFile randomAccessRead = new RandomAccessReadBufferedFile(pdfPath.toFile());
|
||||||
PDDocument document = Loader.loadPDF(randomAccessRead)) {
|
PDDocument document = Loader.loadPDF(randomAccessRead)) {
|
||||||
PDFRenderer renderer = new PDFRenderer(document);
|
PDFRenderer renderer = new PDFRenderer(document);
|
||||||
for (int i = 0; i < document.getNumberOfPages(); i++) {
|
|
||||||
BufferedImage image = null;
|
BufferedImage image = null;
|
||||||
try {
|
try {
|
||||||
image = renderer.renderImageWithDPI(i, 200, ImageType.RGB);
|
image = renderer.renderImageWithDPI(page - 1, DEFAULT_DPI, ImageType.RGB);
|
||||||
Path outputFile = targetDir.resolve(String.format("%04d.jpg", i + 1));
|
ImageIO.write(image, "JPEG", outputStream);
|
||||||
ImageIO.write(image, "JPEG", outputFile.toFile());
|
|
||||||
} finally {
|
} finally {
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
image.flush(); // Release native resources
|
image.flush();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to render PDF pages from {}", pdfPath, e);
|
log.error("Failed to render PDF page {} from {}", page, pdfPath, e);
|
||||||
throw new UncheckedIOException("Error rendering PDF to images", e);
|
throw e;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean needsCacheRefresh(Path pdfPath, Path cacheInfoPath) throws IOException {
|
|
||||||
if (!Files.exists(cacheInfoPath)) return true;
|
|
||||||
|
|
||||||
long currentLastModified = Files.getLastModifiedTime(pdfPath).toMillis();
|
|
||||||
String recordedTimestamp = Files.readString(cacheInfoPath).trim();
|
|
||||||
|
|
||||||
try {
|
|
||||||
long recordedLastModified = Long.parseLong(recordedTimestamp);
|
|
||||||
return recordedLastModified != currentLastModified;
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeCacheInfo(Path pdfPath, Path cacheInfoPath) throws IOException {
|
|
||||||
long lastModified = Files.getLastModifiedTime(pdfPath).toMillis();
|
|
||||||
Files.writeString(cacheInfoPath, String.valueOf(lastModified), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int extractPageNumber(String filename) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(NON_DIGIT_PATTERN.matcher(filename).replaceAll(""));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -107,6 +107,9 @@ public class DefaultUserSettingsProvider {
|
|||||||
return BookLoreUser.UserSettings.NewPdfReaderSetting.builder()
|
return BookLoreUser.UserSettings.NewPdfReaderSetting.builder()
|
||||||
.pageViewMode(NewPdfPageViewMode.SINGLE_PAGE)
|
.pageViewMode(NewPdfPageViewMode.SINGLE_PAGE)
|
||||||
.pageSpread(NewPdfPageSpread.ODD)
|
.pageSpread(NewPdfPageSpread.ODD)
|
||||||
|
.fitMode(NewPdfPageFitMode.FIT_HEIGHT)
|
||||||
|
.scrollMode(NewPdfPageScrollMode.PAGINATED)
|
||||||
|
.backgroundColor(NewPdfBackgroundColor.WHITE)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
package com.adityachandel.booklore.task.tasks;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.exception.ApiError;
|
|
||||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
|
||||||
import com.adityachandel.booklore.model.enums.TaskType;
|
|
||||||
import com.adityachandel.booklore.model.enums.UserPermission;
|
|
||||||
import com.adityachandel.booklore.task.TaskMetadataHelper;
|
|
||||||
import com.adityachandel.booklore.task.TaskStatus;
|
|
||||||
import com.adityachandel.booklore.util.FileService;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Component
|
|
||||||
@Slf4j
|
|
||||||
public class ClearPdfCacheTask implements Task {
|
|
||||||
|
|
||||||
private FileService fileService;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validatePermissions(BookLoreUser user, TaskCreateRequest request) {
|
|
||||||
if (!UserPermission.CAN_ACCESS_TASK_MANAGER.isGranted(user.getPermissions())) {
|
|
||||||
throw ApiError.PERMISSION_DENIED.createException(UserPermission.CAN_ACCESS_TASK_MANAGER);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TaskCreateResponse execute(TaskCreateRequest request) {
|
|
||||||
TaskCreateResponse.TaskCreateResponseBuilder builder = TaskCreateResponse.builder()
|
|
||||||
.taskId(UUID.randomUUID().toString())
|
|
||||||
.taskType(TaskType.CLEAR_PDF_CACHE);
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
log.info("{}: Task started", getTaskType());
|
|
||||||
|
|
||||||
try {
|
|
||||||
fileService.clearCacheDirectory(fileService.getPdfCachePath());
|
|
||||||
log.info("{}: Cache cleared", getTaskType());
|
|
||||||
builder.status(TaskStatus.COMPLETED);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("{}: Error clearing cache", getTaskType(), e);
|
|
||||||
builder.status(TaskStatus.FAILED);
|
|
||||||
throw new RuntimeException("Failed to clear PDF cache", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
long endTime = System.currentTimeMillis();
|
|
||||||
log.info("{}: Task completed. Duration: {} ms", getTaskType(), endTime - startTime);
|
|
||||||
|
|
||||||
return builder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TaskType getTaskType() {
|
|
||||||
return TaskType.CLEAR_PDF_CACHE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMetadata() {
|
|
||||||
return TaskMetadataHelper.getCacheSizeString(fileService.getPdfCachePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE new_pdf_viewer_preference
|
||||||
|
ADD COLUMN fit_mode VARCHAR(16) NULL,
|
||||||
|
ADD COLUMN scroll_mode VARCHAR(16) NULL,
|
||||||
|
ADD COLUMN background_color VARCHAR(16) NULL;
|
||||||
+8
-8
@@ -65,18 +65,18 @@ class TaskCronServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void testGetAllEnabledCronConfigs_returnsList() {
|
void testGetAllEnabledCronConfigs_returnsList() {
|
||||||
List<TaskCronConfigurationEntity> configs = List.of(
|
List<TaskCronConfigurationEntity> configs = List.of(
|
||||||
buildEntity(TaskType.CLEAR_PDF_CACHE, "0 0 1 * * *", true)
|
buildEntity(TaskType.CLEANUP_DELETED_BOOKS, "0 0 1 * * *", true)
|
||||||
);
|
);
|
||||||
when(repository.findByEnabledTrue()).thenReturn(configs);
|
when(repository.findByEnabledTrue()).thenReturn(configs);
|
||||||
|
|
||||||
List<TaskCronConfigurationEntity> result = service.getAllEnabledCronConfigs();
|
List<TaskCronConfigurationEntity> result = service.getAllEnabledCronConfigs();
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
assertEquals(TaskType.CLEAR_PDF_CACHE, result.getFirst().getTaskType());
|
assertEquals(TaskType.CLEANUP_DELETED_BOOKS, result.getFirst().getTaskType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetCronConfigOrDefault_existingConfig() {
|
void testGetCronConfigOrDefault_existingConfig() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
TaskCronConfigurationEntity entity = buildEntity(type, "0 0 1 * * *", true);
|
TaskCronConfigurationEntity entity = buildEntity(type, "0 0 1 * * *", true);
|
||||||
when(repository.findByTaskType(type)).thenReturn(Optional.of(entity));
|
when(repository.findByTaskType(type)).thenReturn(Optional.of(entity));
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ class TaskCronServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testGetCronConfigOrDefault_noConfig_returnsDefault() {
|
void testGetCronConfigOrDefault_noConfig_returnsDefault() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
when(repository.findByTaskType(type)).thenReturn(Optional.empty());
|
when(repository.findByTaskType(type)).thenReturn(Optional.empty());
|
||||||
|
|
||||||
CronConfig config = service.getCronConfigOrDefault(type);
|
CronConfig config = service.getCronConfigOrDefault(type);
|
||||||
@@ -116,7 +116,7 @@ class TaskCronServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPatchCronConfig_updateExisting() {
|
void testPatchCronConfig_updateExisting() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
||||||
TaskCronConfigurationEntity entity = buildEntity(type, "0 0 1 * * *", false);
|
TaskCronConfigurationEntity entity = buildEntity(type, "0 0 1 * * *", false);
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ class TaskCronServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPatchCronConfig_createNew() {
|
void testPatchCronConfig_createNew() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
||||||
|
|
||||||
when(authService.getAuthenticatedUser()).thenReturn(user);
|
when(authService.getAuthenticatedUser()).thenReturn(user);
|
||||||
@@ -154,7 +154,7 @@ class TaskCronServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPatchCronConfig_invalidCronExpression_throws() {
|
void testPatchCronConfig_invalidCronExpression_throws() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
BookLoreUser user = BookLoreUser.builder().id(10L).isDefaultPassword(false).build();
|
||||||
|
|
||||||
when(authService.getAuthenticatedUser()).thenReturn(user);
|
when(authService.getAuthenticatedUser()).thenReturn(user);
|
||||||
@@ -223,7 +223,7 @@ class TaskCronServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testValidateTaskTypeForCron_supported() {
|
void testValidateTaskTypeForCron_supported() {
|
||||||
TaskType type = TaskType.CLEAR_PDF_CACHE;
|
TaskType type = TaskType.CLEANUP_DELETED_BOOKS;
|
||||||
assertDoesNotThrow(() -> {
|
assertDoesNotThrow(() -> {
|
||||||
var method = TaskCronService.class.getDeclaredMethod("validateTaskTypeForCron", TaskType.class);
|
var method = TaskCronService.class.getDeclaredMethod("validateTaskTypeForCron", TaskType.class);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|||||||
+1
-1
@@ -264,7 +264,7 @@ class TaskHistoryServiceTest {
|
|||||||
List<TaskType> hiddenTypes = Arrays.asList(TaskType.values());
|
List<TaskType> hiddenTypes = Arrays.asList(TaskType.values());
|
||||||
TaskHistoryEntity dummyTask = TaskHistoryEntity.builder()
|
TaskHistoryEntity dummyTask = TaskHistoryEntity.builder()
|
||||||
.id("dummy")
|
.id("dummy")
|
||||||
.type(TaskType.CLEAR_PDF_CACHE)
|
.type(TaskType.CLEANUP_DELETED_BOOKS)
|
||||||
.status(TaskStatus.FAILED)
|
.status(TaskStatus.FAILED)
|
||||||
.progressPercentage(0)
|
.progressPercentage(0)
|
||||||
.createdAt(FIXED_TIME)
|
.createdAt(FIXED_TIME)
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ class TaskServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testExecuteTaskThrowsForUnknownTaskType() {
|
void testExecuteTaskThrowsForUnknownTaskType() {
|
||||||
TaskCreateRequest req = TaskCreateRequest.builder().taskType(TaskType.CLEAR_PDF_CACHE).triggeredByCron(false).build();
|
TaskCreateRequest req = TaskCreateRequest.builder().taskType(TaskType.CLEANUP_DELETED_BOOKS).triggeredByCron(false).build();
|
||||||
BookLoreUser user = new BookLoreUser();
|
BookLoreUser user = new BookLoreUser();
|
||||||
user.setId(1L);
|
user.setId(1L);
|
||||||
user.setUsername("user1");
|
user.setUsername("user1");
|
||||||
|
|||||||
-70
@@ -1,70 +0,0 @@
|
|||||||
package com.adityachandel.booklore.task.tasks;
|
|
||||||
|
|
||||||
import com.adityachandel.booklore.exception.APIException;
|
|
||||||
import com.adityachandel.booklore.model.dto.BookLoreUser;
|
|
||||||
import com.adityachandel.booklore.model.dto.request.TaskCreateRequest;
|
|
||||||
import com.adityachandel.booklore.model.dto.response.TaskCreateResponse;
|
|
||||||
import com.adityachandel.booklore.model.enums.TaskType;
|
|
||||||
import com.adityachandel.booklore.task.TaskStatus;
|
|
||||||
import com.adityachandel.booklore.util.FileService;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
|
||||||
import org.mockito.InjectMocks;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
|
||||||
class ClearPdfCacheTaskTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private FileService fileService;
|
|
||||||
|
|
||||||
@InjectMocks
|
|
||||||
private ClearPdfCacheTask clearPdfCacheTask;
|
|
||||||
|
|
||||||
private BookLoreUser user;
|
|
||||||
private TaskCreateRequest request;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void setUp() {
|
|
||||||
user = BookLoreUser.builder()
|
|
||||||
.permissions(new BookLoreUser.UserPermissions())
|
|
||||||
.build();
|
|
||||||
request = new TaskCreateRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void validatePermissions_shouldThrowException_whenUserCannotAccessTaskManager() {
|
|
||||||
user.getPermissions().setCanAccessTaskManager(false);
|
|
||||||
assertThrows(APIException.class, () -> clearPdfCacheTask.validatePermissions(user, request));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void execute_shouldClearCache() {
|
|
||||||
String cachePathStr = "/tmp/pdf-cache";
|
|
||||||
when(fileService.getPdfCachePath()).thenReturn(cachePathStr);
|
|
||||||
doNothing().when(fileService).clearCacheDirectory(cachePathStr);
|
|
||||||
|
|
||||||
TaskCreateResponse response = clearPdfCacheTask.execute(request);
|
|
||||||
|
|
||||||
assertEquals(TaskType.CLEAR_PDF_CACHE, response.getTaskType());
|
|
||||||
assertEquals(TaskStatus.COMPLETED, response.getStatus());
|
|
||||||
|
|
||||||
verify(fileService).getPdfCachePath();
|
|
||||||
verify(fileService).clearCacheDirectory(cachePathStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void execute_shouldHandleException_whenClearCacheFails() {
|
|
||||||
String cachePathStr = "/tmp/pdf-cache";
|
|
||||||
when(fileService.getPdfCachePath()).thenReturn(cachePathStr);
|
|
||||||
doThrow(new RuntimeException("Delete failed")).when(fileService).clearCacheDirectory(cachePathStr);
|
|
||||||
|
|
||||||
assertThrows(RuntimeException.class, () -> clearPdfCacheTask.execute(request));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,22 @@ import {API_CONFIG} from '../../../core/config/api-config';
|
|||||||
import {HttpClient} from '@angular/common/http';
|
import {HttpClient} from '@angular/common/http';
|
||||||
import {AuthService} from '../../../shared/service/auth.service';
|
import {AuthService} from '../../../shared/service/auth.service';
|
||||||
|
|
||||||
|
export interface PdfInfoPage {
|
||||||
|
pageNumber: number;
|
||||||
|
displayName: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PdfOutlineItem {
|
||||||
|
title: string;
|
||||||
|
pageNumber: number;
|
||||||
|
children: PdfOutlineItem[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PdfInfo {
|
||||||
|
pageCount: number;
|
||||||
|
outline: PdfOutlineItem[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
@@ -26,6 +42,10 @@ export class NewPdfReaderService {
|
|||||||
return this.http.get<number[]>(this.appendToken(`${this.pagesUrl}/${bookId}/pages`));
|
return this.http.get<number[]>(this.appendToken(`${this.pagesUrl}/${bookId}/pages`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPageInfo(bookId: number) {
|
||||||
|
return this.http.get<PdfInfo>(this.appendToken(`${this.pagesUrl}/${bookId}/info`));
|
||||||
|
}
|
||||||
|
|
||||||
getPageImageUrl(bookId: number, page: number): string {
|
getPageImageUrl(bookId: number, page: number): string {
|
||||||
return this.appendToken(`${this.imageUrl}/${bookId}/pdf/pages/${page}`);
|
return this.appendToken(`${this.imageUrl}/${bookId}/pdf/pages/${page}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
<div class="comic-reader-container" tabindex="0">
|
<div class="comic-reader-container" tabindex="0">
|
||||||
<!-- Header -->
|
|
||||||
<app-cbx-header [isCurrentPageBookmarked]="isCurrentPageBookmarked" [currentPageHasNotes]="currentPageHasNotes"></app-cbx-header>
|
<app-cbx-header [isCurrentPageBookmarked]="isCurrentPageBookmarked" [currentPageHasNotes]="currentPageHasNotes"></app-cbx-header>
|
||||||
|
|
||||||
<!-- Sidebar -->
|
|
||||||
<app-cbx-sidebar></app-cbx-sidebar>
|
<app-cbx-sidebar></app-cbx-sidebar>
|
||||||
|
|
||||||
<!-- Quick Settings -->
|
|
||||||
@if (showQuickSettings) {
|
@if (showQuickSettings) {
|
||||||
<app-cbx-quick-settings></app-cbx-quick-settings>
|
<app-cbx-quick-settings></app-cbx-quick-settings>
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- Bookmark Indicator -->
|
|
||||||
@if (isCurrentPageBookmarked) {
|
@if (isCurrentPageBookmarked) {
|
||||||
<div class="bookmark-indicator">
|
<div class="bookmark-indicator">
|
||||||
<svg width="48" height="64" viewBox="0 0 48 64">
|
<svg width="48" height="64" viewBox="0 0 48 64">
|
||||||
@@ -19,7 +15,6 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- Note Dialog -->
|
|
||||||
@if (showNoteDialog) {
|
@if (showNoteDialog) {
|
||||||
<app-cbx-note-dialog
|
<app-cbx-note-dialog
|
||||||
[data]="noteDialogData"
|
[data]="noteDialogData"
|
||||||
@@ -28,7 +23,6 @@
|
|||||||
></app-cbx-note-dialog>
|
></app-cbx-note-dialog>
|
||||||
}
|
}
|
||||||
|
|
||||||
<!-- Main content area -->
|
|
||||||
<div class="image-container"
|
<div class="image-container"
|
||||||
[class.two-page-view]="isTwoPageView && scrollMode === CbxScrollMode.PAGINATED"
|
[class.two-page-view]="isTwoPageView && scrollMode === CbxScrollMode.PAGINATED"
|
||||||
[class.infinite-scroll]="scrollMode === CbxScrollMode.INFINITE"
|
[class.infinite-scroll]="scrollMode === CbxScrollMode.INFINITE"
|
||||||
@@ -45,10 +39,19 @@
|
|||||||
@if (pages.length > 0) {
|
@if (pages.length > 0) {
|
||||||
@if (scrollMode === CbxScrollMode.PAGINATED) {
|
@if (scrollMode === CbxScrollMode.PAGINATED) {
|
||||||
<div class="pages-wrapper" (click)="onImageClick()">
|
<div class="pages-wrapper" (click)="onImageClick()">
|
||||||
@for (url of imageUrls; track url) {
|
@if (isPageTransitioning && previousImageUrls.length > 0) {
|
||||||
<img [src]="url" alt="Page Image" class="page-image"/>
|
<div class="previous-page-layer">
|
||||||
|
@for (url of previousImageUrls; track url) {
|
||||||
|
<img [src]="url" alt="Previous Page" class="page-image previous-image"/>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
<div class="current-page-layer" [class.fade-in]="isPageTransitioning && imagesLoaded">
|
||||||
|
@for (url of currentImageUrls; track url) {
|
||||||
|
<img [src]="url" alt="Page Image" class="page-image" (load)="onImageLoad()"/>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@if (isAtLastPage && nextBookInSeries) {
|
@if (isAtLastPage && nextBookInSeries) {
|
||||||
<div class="end-of-comic-action">
|
<div class="end-of-comic-action">
|
||||||
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
<button class="next-book-action-button" (click)="navigateToNextBook()">
|
||||||
@@ -92,6 +95,5 @@
|
|||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Footer -->
|
|
||||||
<app-cbx-footer></app-cbx-footer>
|
<app-cbx-footer></app-cbx-footer>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -13,7 +13,6 @@
|
|||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark indicator
|
|
||||||
.bookmark-indicator {
|
.bookmark-indicator {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -82,6 +81,43 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.previous-page-layer {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.current-page-layer {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
|
|
||||||
|
&.fade-in {
|
||||||
|
animation: fadeIn 0.15s ease-out forwards;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0.7;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.page-image {
|
.page-image {
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
|
||||||
@@ -91,10 +127,18 @@
|
|||||||
&:hover {
|
&:hover {
|
||||||
transform: scale(1.02);
|
transform: scale(1.02);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.previous-image {
|
||||||
|
&:hover {
|
||||||
|
transform: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.fit-width {
|
&.fit-width {
|
||||||
.pages-wrapper {
|
.pages-wrapper,
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
height: auto;
|
height: auto;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
}
|
}
|
||||||
@@ -109,7 +153,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.two-page-view {
|
&.two-page-view {
|
||||||
.pages-wrapper {
|
.pages-wrapper,
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: 1fr 1fr;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
@@ -123,7 +169,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&.fit-height {
|
&.fit-height {
|
||||||
.pages-wrapper {
|
.pages-wrapper,
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
width: auto;
|
width: auto;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
@@ -149,7 +197,9 @@
|
|||||||
&.fit-actual-size {
|
&.fit-actual-size {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
.pages-wrapper {
|
.pages-wrapper,
|
||||||
|
.previous-page-layer,
|
||||||
|
.current-page-layer {
|
||||||
width: max-content;
|
width: max-content;
|
||||||
height: max-content;
|
height: max-content;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import {Component, HostListener, inject, OnDestroy, OnInit} from '@angular/core';
|
import {Component, HostListener, inject, OnDestroy, OnInit} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
import {CommonModule, Location} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import {forkJoin, Subject} from 'rxjs';
|
import {forkJoin, Subject} from 'rxjs';
|
||||||
import {filter, first, takeUntil, timeout} from 'rxjs/operators';
|
import {filter, first, takeUntil, timeout} from 'rxjs/operators';
|
||||||
import {PageTitleService} from "../../../shared/service/page-title.service";
|
import {PageTitleService} from "../../../shared/service/page-title.service";
|
||||||
import {CbxReaderService} from '../../book/service/cbx-reader.service';
|
import {CbxReaderService} from '../../book/service/cbx-reader.service';
|
||||||
import {BookService} from '../../book/service/book.service';
|
import {BookService} from '../../book/service/book.service';
|
||||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, PdfPageSpread, PdfPageViewMode, UserService} from '../../settings/user-management/user.service';
|
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserService} from '../../settings/user-management/user.service';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {Book, BookSetting, BookType} from '../../book/model/book.model';
|
import {Book, BookSetting, BookType} from '../../book/model/book.model';
|
||||||
import {BookState} from '../../book/model/state/book-state.model';
|
import {BookState} from '../../book/model/state/book-state.model';
|
||||||
@@ -14,9 +14,8 @@ import {ProgressSpinner} from 'primeng/progressspinner';
|
|||||||
import {FormsModule} from "@angular/forms";
|
import {FormsModule} from "@angular/forms";
|
||||||
import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
|
import {NewPdfReaderService} from '../../book/service/new-pdf-reader.service';
|
||||||
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
|
import {ReadingSessionService} from '../../../shared/service/reading-session.service';
|
||||||
import {ReaderHeaderFooterVisibilityManager} from '../ebook-reader/shared/visibility.util';
|
import {ReaderHeaderFooterVisibilityManager} from '../ebook-reader';
|
||||||
|
|
||||||
// Layout components
|
|
||||||
import {CbxHeaderComponent} from './layout/header/cbx-header.component';
|
import {CbxHeaderComponent} from './layout/header/cbx-header.component';
|
||||||
import {CbxHeaderService} from './layout/header/cbx-header.service';
|
import {CbxHeaderService} from './layout/header/cbx-header.service';
|
||||||
import {CbxSidebarComponent} from './layout/sidebar/cbx-sidebar.component';
|
import {CbxSidebarComponent} from './layout/sidebar/cbx-sidebar.component';
|
||||||
@@ -62,9 +61,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
|
pageSpread: CbxPageSpread | PdfPageSpread = CbxPageSpread.ODD;
|
||||||
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
pageViewMode: CbxPageViewMode | PdfPageViewMode = CbxPageViewMode.SINGLE_PAGE;
|
||||||
backgroundColor: CbxBackgroundColor = CbxBackgroundColor.GRAY;
|
backgroundColor: CbxBackgroundColor | PdfBackgroundColor = CbxBackgroundColor.GRAY;
|
||||||
fitMode: CbxFitMode = CbxFitMode.FIT_PAGE;
|
fitMode: CbxFitMode | PdfFitMode = CbxFitMode.FIT_PAGE;
|
||||||
scrollMode: CbxScrollMode = CbxScrollMode.PAGINATED;
|
scrollMode: CbxScrollMode | PdfScrollMode = CbxScrollMode.PAGINATED;
|
||||||
|
|
||||||
private touchStartX = 0;
|
private touchStartX = 0;
|
||||||
private touchEndX = 0;
|
private touchEndX = 0;
|
||||||
@@ -77,9 +76,14 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
preloadCount: number = 3;
|
preloadCount: number = 3;
|
||||||
isLoadingMore: boolean = false;
|
isLoadingMore: boolean = false;
|
||||||
|
|
||||||
|
private preloadedImages = new Map<string, HTMLImageElement>();
|
||||||
|
previousImageUrls: string[] = [];
|
||||||
|
currentImageUrls: string[] = [];
|
||||||
|
isPageTransitioning = false;
|
||||||
|
imagesLoaded = false;
|
||||||
|
|
||||||
private visibilityManager!: ReaderHeaderFooterVisibilityManager;
|
private visibilityManager!: ReaderHeaderFooterVisibilityManager;
|
||||||
|
|
||||||
// Bookmark and notes state
|
|
||||||
isCurrentPageBookmarked = false;
|
isCurrentPageBookmarked = false;
|
||||||
currentPageHasNotes = false;
|
currentPageHasNotes = false;
|
||||||
showNoteDialog = false;
|
showNoteDialog = false;
|
||||||
@@ -88,7 +92,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private route = inject(ActivatedRoute);
|
private route = inject(ActivatedRoute);
|
||||||
private router = inject(Router);
|
private router = inject(Router);
|
||||||
private location = inject(Location);
|
|
||||||
private cbxReaderService = inject(CbxReaderService);
|
private cbxReaderService = inject(CbxReaderService);
|
||||||
private pdfReaderService = inject(NewPdfReaderService);
|
private pdfReaderService = inject(NewPdfReaderService);
|
||||||
private bookService = inject(BookService);
|
private bookService = inject(BookService);
|
||||||
@@ -143,7 +146,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.pageTitle.setBookPageTitle(book);
|
this.pageTitle.setBookPageTitle(book);
|
||||||
|
|
||||||
// Initialize header and sidebar services
|
|
||||||
const title = book.metadata?.title || book.fileName;
|
const title = book.metadata?.title || book.fileName;
|
||||||
this.headerService.initialize(this.bookId, title, this.destroy$);
|
this.headerService.initialize(this.bookId, title, this.destroy$);
|
||||||
this.sidebarService.initialize(this.bookId, book, this.destroy$);
|
this.sidebarService.initialize(this.bookId, book, this.destroy$);
|
||||||
@@ -198,6 +200,18 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
? PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD
|
? PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD
|
||||||
: PdfPageSpread[bookSettings.newPdfSettings?.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD;
|
: PdfPageSpread[bookSettings.newPdfSettings?.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread[userSettings.newPdfReaderSetting.pageSpread as keyof typeof PdfPageSpread] || PdfPageSpread.ODD;
|
||||||
|
|
||||||
|
this.fitMode = global
|
||||||
|
? PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE
|
||||||
|
: PdfFitMode[bookSettings.newPdfSettings?.fitMode as keyof typeof PdfFitMode] || PdfFitMode[userSettings.newPdfReaderSetting.fitMode as keyof typeof PdfFitMode] || PdfFitMode.FIT_PAGE;
|
||||||
|
|
||||||
|
this.scrollMode = global
|
||||||
|
? PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED
|
||||||
|
: PdfScrollMode[bookSettings.newPdfSettings?.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode[userSettings.newPdfReaderSetting.scrollMode as keyof typeof PdfScrollMode] || PdfScrollMode.PAGINATED;
|
||||||
|
|
||||||
|
this.backgroundColor = global
|
||||||
|
? PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY
|
||||||
|
: PdfBackgroundColor[bookSettings.newPdfSettings?.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor[userSettings.newPdfReaderSetting.backgroundColor as keyof typeof PdfBackgroundColor] || PdfBackgroundColor.GRAY;
|
||||||
|
|
||||||
this.currentPage = (book.pdfProgress?.page || 1) - 1;
|
this.currentPage = (book.pdfProgress?.page || 1) - 1;
|
||||||
}
|
}
|
||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
@@ -206,6 +220,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.updateNotesState();
|
this.updateNotesState();
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
|
||||||
|
this.updateCurrentImageUrls();
|
||||||
|
this.preloadAdjacentPages();
|
||||||
|
|
||||||
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
|
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
|
||||||
this.readingSessionService.startSession(this.bookId, "CBX", (this.currentPage + 1).toString(), percentage);
|
this.readingSessionService.startSession(this.bookId, "CBX", (this.currentPage + 1).toString(), percentage);
|
||||||
},
|
},
|
||||||
@@ -258,14 +275,12 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.updateBookmarkState();
|
this.updateBookmarkState();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subscribe to bookmarks$ to update state when bookmarks are loaded
|
|
||||||
this.sidebarService.bookmarks$
|
this.sidebarService.bookmarks$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
this.updateBookmarkState();
|
this.updateBookmarkState();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subscribe to notes$ to update state when notes are loaded
|
|
||||||
this.sidebarService.notes$
|
this.sidebarService.notes$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(() => {
|
.subscribe(() => {
|
||||||
@@ -336,7 +351,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateServiceStates(): void {
|
private updateServiceStates(): void {
|
||||||
// Update footer state
|
|
||||||
this.footerService.updateState({
|
this.footerService.updateState({
|
||||||
currentPage: this.currentPage,
|
currentPage: this.currentPage,
|
||||||
totalPages: this.pages.length,
|
totalPages: this.pages.length,
|
||||||
@@ -346,7 +360,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
hasSeries: this.hasSeries
|
hasSeries: this.hasSeries
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update quick settings state
|
|
||||||
this.quickSettingsService.updateState({
|
this.quickSettingsService.updateState({
|
||||||
fitMode: this.fitMode,
|
fitMode: this.fitMode,
|
||||||
scrollMode: this.scrollMode,
|
scrollMode: this.scrollMode,
|
||||||
@@ -355,7 +368,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
backgroundColor: this.backgroundColor
|
backgroundColor: this.backgroundColor
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update sidebar current page
|
|
||||||
this.sidebarService.setCurrentPage(this.currentPage + 1);
|
this.sidebarService.setCurrentPage(this.currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,6 +378,155 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.updateNotesState();
|
this.updateNotesState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateCurrentImageUrls(): void {
|
||||||
|
if (!this.pages.length) {
|
||||||
|
this.currentImageUrls = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const urls: string[] = [];
|
||||||
|
urls.push(this.getPageImageUrl(this.currentPage));
|
||||||
|
|
||||||
|
if (this.isTwoPageView && this.currentPage + 1 < this.pages.length) {
|
||||||
|
urls.push(this.getPageImageUrl(this.currentPage + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentImageUrls = urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private preloadAdjacentPages(): void {
|
||||||
|
if (!this.pages.length || this.scrollMode === CbxScrollMode.INFINITE) return;
|
||||||
|
|
||||||
|
const pagesToPreload: number[] = [];
|
||||||
|
|
||||||
|
const step = this.isTwoPageView ? 2 : 1;
|
||||||
|
for (let i = 1; i <= 2; i++) {
|
||||||
|
const nextPage = this.currentPage + (step * i);
|
||||||
|
if (nextPage < this.pages.length) {
|
||||||
|
pagesToPreload.push(nextPage);
|
||||||
|
if (this.isTwoPageView && nextPage + 1 < this.pages.length) {
|
||||||
|
pagesToPreload.push(nextPage + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 1; i <= 2; i++) {
|
||||||
|
const prevPage = this.currentPage - (step * i);
|
||||||
|
if (prevPage >= 0) {
|
||||||
|
pagesToPreload.push(prevPage);
|
||||||
|
if (this.isTwoPageView && prevPage + 1 < this.pages.length) {
|
||||||
|
pagesToPreload.push(prevPage + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pagesToPreload.forEach(pageIndex => {
|
||||||
|
const url = this.getPageImageUrl(pageIndex);
|
||||||
|
if (!this.preloadedImages.has(url)) {
|
||||||
|
const img = new Image();
|
||||||
|
img.src = url;
|
||||||
|
this.preloadedImages.set(url, img);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.cleanupPreloadedImages(pagesToPreload);
|
||||||
|
}
|
||||||
|
|
||||||
|
private cleanupPreloadedImages(keepPages: number[]): void {
|
||||||
|
const keepUrls = new Set(keepPages.map(p => this.getPageImageUrl(p)));
|
||||||
|
this.currentImageUrls.forEach(url => keepUrls.add(url));
|
||||||
|
|
||||||
|
for (const url of this.preloadedImages.keys()) {
|
||||||
|
if (!keepUrls.has(url)) {
|
||||||
|
this.preloadedImages.delete(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private transitionToNewPage(): void {
|
||||||
|
if (this.scrollMode === CbxScrollMode.INFINITE) {
|
||||||
|
this.updateCurrentImageUrls();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const newUrls = this.getNewImageUrls();
|
||||||
|
|
||||||
|
const allPreloaded = newUrls.every(url => {
|
||||||
|
const img = this.preloadedImages.get(url);
|
||||||
|
return img && img.complete && img.naturalWidth > 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (allPreloaded) {
|
||||||
|
this.previousImageUrls = [...this.currentImageUrls];
|
||||||
|
this.currentImageUrls = newUrls;
|
||||||
|
this.isPageTransitioning = true;
|
||||||
|
this.imagesLoaded = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.isPageTransitioning = false;
|
||||||
|
this.previousImageUrls = [];
|
||||||
|
}, 150);
|
||||||
|
} else {
|
||||||
|
this.isPageTransitioning = true;
|
||||||
|
this.imagesLoaded = false;
|
||||||
|
this.previousImageUrls = [...this.currentImageUrls];
|
||||||
|
|
||||||
|
this.preloadImagesAndTransition(newUrls);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.preloadAdjacentPages();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getNewImageUrls(): string[] {
|
||||||
|
if (!this.pages.length) return [];
|
||||||
|
|
||||||
|
const urls: string[] = [];
|
||||||
|
urls.push(this.getPageImageUrl(this.currentPage));
|
||||||
|
|
||||||
|
if (this.isTwoPageView && this.currentPage + 1 < this.pages.length) {
|
||||||
|
urls.push(this.getPageImageUrl(this.currentPage + 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
private preloadImagesAndTransition(urls: string[]): void {
|
||||||
|
let loadedCount = 0;
|
||||||
|
const totalImages = urls.length;
|
||||||
|
|
||||||
|
urls.forEach(url => {
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = () => {
|
||||||
|
loadedCount++;
|
||||||
|
this.preloadedImages.set(url, img);
|
||||||
|
|
||||||
|
if (loadedCount === totalImages) {
|
||||||
|
this.currentImageUrls = urls;
|
||||||
|
this.imagesLoaded = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
this.isPageTransitioning = false;
|
||||||
|
this.previousImageUrls = [];
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
loadedCount++;
|
||||||
|
if (loadedCount === totalImages) {
|
||||||
|
this.currentImageUrls = urls;
|
||||||
|
this.imagesLoaded = true;
|
||||||
|
this.isPageTransitioning = false;
|
||||||
|
this.previousImageUrls = [];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
img.src = url;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onImageLoad(): void {
|
||||||
|
this.imagesLoaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
get isTwoPageView(): boolean {
|
get isTwoPageView(): boolean {
|
||||||
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
return this.pageViewMode === this.CbxPageViewMode.TWO_PAGE || this.pageViewMode === PdfPageViewMode.TWO_PAGE;
|
||||||
}
|
}
|
||||||
@@ -403,6 +564,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentPage !== previousPage) {
|
if (this.currentPage !== previousPage) {
|
||||||
|
this.transitionToNewPage();
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
this.updateSessionProgress();
|
this.updateSessionProgress();
|
||||||
this.updateFooterPage();
|
this.updateFooterPage();
|
||||||
@@ -410,6 +572,8 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
previousPage() {
|
previousPage() {
|
||||||
|
const previousPage = this.currentPage;
|
||||||
|
|
||||||
if (this.scrollMode === CbxScrollMode.INFINITE) {
|
if (this.scrollMode === CbxScrollMode.INFINITE) {
|
||||||
if (this.currentPage > 0) {
|
if (this.currentPage > 0) {
|
||||||
this.currentPage--;
|
this.currentPage--;
|
||||||
@@ -426,10 +590,14 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
} else {
|
} else {
|
||||||
this.currentPage = Math.max(0, this.currentPage - 1);
|
this.currentPage = Math.max(0, this.currentPage - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.currentPage !== previousPage) {
|
||||||
|
this.transitionToNewPage();
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
this.updateSessionProgress();
|
this.updateSessionProgress();
|
||||||
this.updateFooterPage();
|
this.updateFooterPage();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private alignCurrentPageToParity() {
|
private alignCurrentPageToParity() {
|
||||||
if (!this.pages.length || !this.isTwoPageView) return;
|
if (!this.pages.length || !this.isTwoPageView) return;
|
||||||
@@ -451,7 +619,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quick settings handlers
|
|
||||||
onFitModeChange(mode: CbxFitMode): void {
|
onFitModeChange(mode: CbxFitMode): void {
|
||||||
this.fitMode = mode;
|
this.fitMode = mode;
|
||||||
this.quickSettingsService.setFitMode(mode);
|
this.quickSettingsService.setFitMode(mode);
|
||||||
@@ -466,6 +633,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
if (this.scrollMode === CbxScrollMode.INFINITE) {
|
if (this.scrollMode === CbxScrollMode.INFINITE) {
|
||||||
this.initializeInfiniteScroll();
|
this.initializeInfiniteScroll();
|
||||||
setTimeout(() => this.scrollToPage(this.currentPage), 100);
|
setTimeout(() => this.scrollToPage(this.currentPage), 100);
|
||||||
|
} else {
|
||||||
|
this.updateCurrentImageUrls();
|
||||||
|
this.preloadAdjacentPages();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -474,6 +644,8 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.pageViewMode = mode;
|
this.pageViewMode = mode;
|
||||||
this.quickSettingsService.setPageViewMode(mode);
|
this.quickSettingsService.setPageViewMode(mode);
|
||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
|
this.updateCurrentImageUrls();
|
||||||
|
this.preloadAdjacentPages();
|
||||||
this.footerService.setTwoPageView(this.isTwoPageView);
|
this.footerService.setTwoPageView(this.isTwoPageView);
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
}
|
}
|
||||||
@@ -482,6 +654,8 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.pageSpread = spread;
|
this.pageSpread = spread;
|
||||||
this.quickSettingsService.setPageSpread(spread);
|
this.quickSettingsService.setPageSpread(spread);
|
||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
|
this.updateCurrentImageUrls();
|
||||||
|
this.preloadAdjacentPages();
|
||||||
this.updateViewerSetting();
|
this.updateViewerSetting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,20 +732,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
: this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex]);
|
: this.cbxReaderService.getPageImageUrl(this.bookId, this.pages[pageIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageUrls(): string[] {
|
|
||||||
if (!this.pages.length) return [];
|
|
||||||
|
|
||||||
const urls: string[] = [];
|
|
||||||
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage));
|
|
||||||
|
|
||||||
if (this.isTwoPageView && this.currentPage + 1 < this.pages.length) {
|
|
||||||
urls.push(this.getPageImageUrl(this.currentPage + 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
return urls;
|
|
||||||
}
|
|
||||||
|
|
||||||
get infiniteScrollImageUrls(): string[] {
|
get infiniteScrollImageUrls(): string[] {
|
||||||
return this.infiniteScrollPages.map(pageIndex => this.getPageImageUrl(pageIndex));
|
return this.infiniteScrollPages.map(pageIndex => this.getPageImageUrl(pageIndex));
|
||||||
}
|
}
|
||||||
@@ -591,6 +751,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
newPdfSettings: {
|
newPdfSettings: {
|
||||||
pageSpread: this.pageSpread as PdfPageSpread,
|
pageSpread: this.pageSpread as PdfPageSpread,
|
||||||
pageViewMode: this.pageViewMode as PdfPageViewMode,
|
pageViewMode: this.pageViewMode as PdfPageViewMode,
|
||||||
|
fitMode: this.fitMode as PdfFitMode,
|
||||||
|
scrollMode: this.scrollMode as PdfScrollMode,
|
||||||
|
backgroundColor: this.backgroundColor as PdfBackgroundColor,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
this.bookService.updateViewerSetting(bookSetting, this.bookId).subscribe();
|
||||||
@@ -635,6 +798,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.updateFooterPage();
|
this.updateFooterPage();
|
||||||
} else {
|
} else {
|
||||||
this.alignCurrentPageToParity();
|
this.alignCurrentPageToParity();
|
||||||
|
this.transitionToNewPage();
|
||||||
this.updateProgress();
|
this.updateProgress();
|
||||||
this.updateSessionProgress();
|
this.updateSessionProgress();
|
||||||
this.updateFooterPage();
|
this.updateFooterPage();
|
||||||
@@ -783,7 +947,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.previousBookInSeries = hasPreviousBook ? sortedBySeriesNumber[currentBookIndex - 1] : null;
|
this.previousBookInSeries = hasPreviousBook ? sortedBySeriesNumber[currentBookIndex - 1] : null;
|
||||||
this.nextBookInSeries = hasNextBook ? sortedBySeriesNumber[currentBookIndex + 1] : null;
|
this.nextBookInSeries = hasNextBook ? sortedBySeriesNumber[currentBookIndex + 1] : null;
|
||||||
|
|
||||||
// Update footer service with series info
|
|
||||||
this.footerService.setSeriesBooks(this.previousBookInSeries, this.nextBookInSeries);
|
this.footerService.setSeriesBooks(this.previousBookInSeries, this.nextBookInSeries);
|
||||||
this.footerService.setHasSeries(true);
|
this.footerService.setHasSeries(true);
|
||||||
},
|
},
|
||||||
@@ -803,22 +966,17 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
getBookDisplayTitle(book: Book | null): string {
|
getBookDisplayTitle(book: Book | null): string {
|
||||||
if (!book) return '';
|
if (!book) return '';
|
||||||
|
|
||||||
const parts: string[] = [];
|
const parts: string[] = [];
|
||||||
|
|
||||||
if (book.metadata?.seriesNumber) {
|
if (book.metadata?.seriesNumber) {
|
||||||
parts.push(`#${book.metadata.seriesNumber}`);
|
parts.push(`#${book.metadata.seriesNumber}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = book.metadata?.title || book.fileName;
|
const title = book.metadata?.title || book.fileName;
|
||||||
if (title) {
|
if (title) {
|
||||||
parts.push(title);
|
parts.push(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (book.metadata?.subtitle) {
|
if (book.metadata?.subtitle) {
|
||||||
parts.push(book.metadata.subtitle);
|
parts.push(book.metadata.subtitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
return parts.join(' - ');
|
return parts.join(' - ');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,7 +993,6 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark methods
|
|
||||||
private updateBookmarkState(): void {
|
private updateBookmarkState(): void {
|
||||||
this.isCurrentPageBookmarked = this.sidebarService.isPageBookmarked(this.currentPage + 1);
|
this.isCurrentPageBookmarked = this.sidebarService.isPageBookmarked(this.currentPage + 1);
|
||||||
}
|
}
|
||||||
@@ -844,12 +1001,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
|
|||||||
this.sidebarService.toggleBookmark(this.currentPage + 1);
|
this.sidebarService.toggleBookmark(this.currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes state methods
|
|
||||||
private updateNotesState(): void {
|
private updateNotesState(): void {
|
||||||
this.currentPageHasNotes = this.sidebarService.pageHasNotes(this.currentPage + 1);
|
this.currentPageHasNotes = this.sidebarService.pageHasNotes(this.currentPage + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note dialog methods
|
|
||||||
openNoteDialog(): void {
|
openNoteDialog(): void {
|
||||||
this.editingNote = null;
|
this.editingNote = null;
|
||||||
this.noteDialogData = {
|
this.noteDialogData = {
|
||||||
|
|||||||
+4
-12
@@ -1,21 +1,13 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject, Subject} from 'rxjs';
|
import {BehaviorSubject, Subject} from 'rxjs';
|
||||||
import {
|
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageViewMode, CbxScrollMode, PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode} from '../../../../settings/user-management/user.service';
|
||||||
CbxFitMode,
|
|
||||||
CbxScrollMode,
|
|
||||||
CbxPageViewMode,
|
|
||||||
CbxPageSpread,
|
|
||||||
CbxBackgroundColor,
|
|
||||||
PdfPageViewMode,
|
|
||||||
PdfPageSpread
|
|
||||||
} from '../../../../settings/user-management/user.service';
|
|
||||||
|
|
||||||
export interface CbxQuickSettingsState {
|
export interface CbxQuickSettingsState {
|
||||||
fitMode: CbxFitMode;
|
fitMode: CbxFitMode | PdfFitMode;
|
||||||
scrollMode: CbxScrollMode;
|
scrollMode: CbxScrollMode | PdfScrollMode;
|
||||||
pageViewMode: CbxPageViewMode | PdfPageViewMode;
|
pageViewMode: CbxPageViewMode | PdfPageViewMode;
|
||||||
pageSpread: CbxPageSpread | PdfPageSpread;
|
pageSpread: CbxPageSpread | PdfPageSpread;
|
||||||
backgroundColor: CbxBackgroundColor;
|
backgroundColor: CbxBackgroundColor | PdfBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
+37
-7
@@ -1,7 +1,6 @@
|
|||||||
@if (isOpen) {
|
@if (isOpen) {
|
||||||
<div class="sidebar-overlay" (click)="onOverlayClick()" [class.closing]="closing">
|
<div class="sidebar-overlay" (click)="onOverlayClick()" [class.closing]="closing">
|
||||||
<aside class="sidebar" (click)="$event.stopPropagation()" [class.closing]="closing">
|
<aside class="sidebar" (click)="$event.stopPropagation()" [class.closing]="closing">
|
||||||
<!-- Header with book info -->
|
|
||||||
<header class="sidebar-header">
|
<header class="sidebar-header">
|
||||||
@if (bookInfo.coverUrl) {
|
@if (bookInfo.coverUrl) {
|
||||||
<img
|
<img
|
||||||
@@ -18,14 +17,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- Tab navigation -->
|
|
||||||
<nav class="tabs">
|
<nav class="tabs">
|
||||||
<button
|
<button
|
||||||
class="tab"
|
class="tab"
|
||||||
[class.active]="activeTab === 'pages'"
|
[class.active]="activeTab === 'pages'"
|
||||||
(click)="setActiveTab('pages')">
|
(click)="setActiveTab('pages')">
|
||||||
<app-reader-icon name="book" class="tab-icon"></app-reader-icon>
|
<app-reader-icon name="book" class="tab-icon"></app-reader-icon>
|
||||||
<span>Pages</span>
|
<span>Content</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="tab"
|
class="tab"
|
||||||
@@ -49,10 +47,43 @@
|
|||||||
</button>
|
</button>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!-- Tab content -->
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@switch (activeTab) {
|
@switch (activeTab) {
|
||||||
@case ('pages') {
|
@case ('pages') {
|
||||||
|
@if (isPdf && hasOutline) {
|
||||||
|
<ul class="outline-list">
|
||||||
|
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: pdfOutline, depth: 0 }"></ng-container>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<ng-template #outlineTemplate let-items="items" let-depth="depth">
|
||||||
|
@for (item of items; track item.title + item.pageNumber) {
|
||||||
|
<li class="outline-item">
|
||||||
|
<button
|
||||||
|
class="outline-row"
|
||||||
|
[class.active]="isOutlineItemActive(item, items)"
|
||||||
|
[class.has-children]="item.children && item.children.length > 0"
|
||||||
|
[style.padding-left.px]="16 + depth * 16"
|
||||||
|
(click)="onOutlineItemClick(item)">
|
||||||
|
@if (item.children && item.children.length > 0) {
|
||||||
|
<span
|
||||||
|
class="expand-icon"
|
||||||
|
[class.expanded]="isOutlineItemExpanded(item)"
|
||||||
|
(click)="toggleOutlineItem(item); $event.stopPropagation()">
|
||||||
|
<app-reader-icon name="chevron-right" [size]="14"></app-reader-icon>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
<span class="outline-title">{{ item.title }}</span>
|
||||||
|
<span class="outline-page">{{ item.pageNumber }}</span>
|
||||||
|
</button>
|
||||||
|
@if (item.children && item.children.length > 0 && isOutlineItemExpanded(item)) {
|
||||||
|
<ul class="outline-children">
|
||||||
|
<ng-container *ngTemplateOutlet="outlineTemplate; context: { items: item.children, depth: depth + 1 }"></ng-container>
|
||||||
|
</ul>
|
||||||
|
}
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ng-template>
|
||||||
|
} @else {
|
||||||
<ul class="page-list">
|
<ul class="page-list">
|
||||||
@for (page of pages; track page.pageNumber) {
|
@for (page of pages; track page.pageNumber) {
|
||||||
<li>
|
<li>
|
||||||
@@ -66,14 +97,14 @@
|
|||||||
</li>
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
@if (pages.length === 0) {
|
@if (pages.length === 0 && !hasOutline) {
|
||||||
<div class="empty-state">
|
<div class="empty-state">
|
||||||
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||||
<p>No pages found</p>
|
<p>No pages found</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@case ('bookmarks') {
|
@case ('bookmarks') {
|
||||||
@if (bookmarks.length > 0) {
|
@if (bookmarks.length > 0) {
|
||||||
<ul class="item-list">
|
<ul class="item-list">
|
||||||
@@ -97,7 +128,6 @@
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@case ('notes') {
|
@case ('notes') {
|
||||||
<div class="notes-container">
|
<div class="notes-container">
|
||||||
@if (notes.length > 0) {
|
@if (notes.length > 0) {
|
||||||
|
|||||||
+83
@@ -229,6 +229,89 @@ $transition-normal: 200ms ease;
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PDF Outline list
|
||||||
|
.outline-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outline-item {
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outline-children {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outline-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
padding: 10px 16px;
|
||||||
|
padding-right: 12px;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: $text-primary;
|
||||||
|
font-size: 13px;
|
||||||
|
text-align: left;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background $transition-fast;
|
||||||
|
gap: 8px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: $hover-bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
background: $active-bg;
|
||||||
|
color: $active-color;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.has-children {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.expand-icon {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
color: $text-muted;
|
||||||
|
transition: transform $transition-fast;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
color: $text-primary;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.expanded {
|
||||||
|
transform: rotate(90deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.outline-title {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outline-page {
|
||||||
|
font-size: 11px;
|
||||||
|
color: $text-muted;
|
||||||
|
flex-shrink: 0;
|
||||||
|
min-width: 28px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
// Item list (bookmarks & notes)
|
// Item list (bookmarks & notes)
|
||||||
.item-list {
|
.item-list {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|||||||
+89
-4
@@ -5,9 +5,10 @@ import {Subject} from 'rxjs';
|
|||||||
import {takeUntil} from 'rxjs/operators';
|
import {takeUntil} from 'rxjs/operators';
|
||||||
import {CbxSidebarService, CbxSidebarTab, SidebarBookInfo} from './cbx-sidebar.service';
|
import {CbxSidebarService, CbxSidebarTab, SidebarBookInfo} from './cbx-sidebar.service';
|
||||||
import {CbxPageInfo} from '../../../../book/service/cbx-reader.service';
|
import {CbxPageInfo} from '../../../../book/service/cbx-reader.service';
|
||||||
|
import {PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
|
||||||
import {BookMark} from '../../../../../shared/service/book-mark.service';
|
import {BookMark} from '../../../../../shared/service/book-mark.service';
|
||||||
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
|
import {BookNoteV2} from '../../../../../shared/service/book-note-v2.service';
|
||||||
import {ReaderIconComponent} from '../../../ebook-reader/shared/icon.component';
|
import {ReaderIconComponent} from '../../../ebook-reader';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-cbx-sidebar',
|
selector: 'app-cbx-sidebar',
|
||||||
@@ -25,6 +26,9 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
|||||||
activeTab: CbxSidebarTab = 'pages';
|
activeTab: CbxSidebarTab = 'pages';
|
||||||
bookInfo: SidebarBookInfo = { id: null, title: '', authors: '', coverUrl: null };
|
bookInfo: SidebarBookInfo = { id: null, title: '', authors: '', coverUrl: null };
|
||||||
pages: CbxPageInfo[] = [];
|
pages: CbxPageInfo[] = [];
|
||||||
|
pdfOutline: PdfOutlineItem[] | null = null;
|
||||||
|
pdfPageCount = 0;
|
||||||
|
expandedOutlineItems = new Set<string>();
|
||||||
currentPage = 1;
|
currentPage = 1;
|
||||||
bookmarks: BookMark[] = [];
|
bookmarks: BookMark[] = [];
|
||||||
notes: BookNoteV2[] = [];
|
notes: BookNoteV2[] = [];
|
||||||
@@ -54,9 +58,23 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
|||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(pages => this.pages = pages);
|
.subscribe(pages => this.pages = pages);
|
||||||
|
|
||||||
|
this.sidebarService.pdfOutline$
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe(outline => {
|
||||||
|
this.pdfOutline = outline;
|
||||||
|
this.autoExpandToCurrentPage();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.sidebarService.pdfPageCount$
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe(count => this.pdfPageCount = count);
|
||||||
|
|
||||||
this.sidebarService.currentPage$
|
this.sidebarService.currentPage$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(page => this.currentPage = page);
|
.subscribe(page => {
|
||||||
|
this.currentPage = page;
|
||||||
|
this.autoExpandToCurrentPage();
|
||||||
|
});
|
||||||
|
|
||||||
this.sidebarService.bookmarks$
|
this.sidebarService.bookmarks$
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
@@ -96,7 +114,75 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
|||||||
return this.currentPage === pageNumber;
|
return this.currentPage === pageNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark methods
|
get isPdf(): boolean {
|
||||||
|
return this.sidebarService.isPdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasOutline(): boolean {
|
||||||
|
return this.pdfOutline !== null && this.pdfOutline.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleOutlineItem(item: PdfOutlineItem): void {
|
||||||
|
const key = `${item.title}-${item.pageNumber}`;
|
||||||
|
if (this.expandedOutlineItems.has(key)) {
|
||||||
|
this.expandedOutlineItems.delete(key);
|
||||||
|
} else {
|
||||||
|
this.expandedOutlineItems.add(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isOutlineItemExpanded(item: PdfOutlineItem): boolean {
|
||||||
|
const key = `${item.title}-${item.pageNumber}`;
|
||||||
|
return this.expandedOutlineItems.has(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
onOutlineItemClick(item: PdfOutlineItem): void {
|
||||||
|
this.sidebarService.navigateToPage(item.pageNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
isOutlineItemActive(item: PdfOutlineItem, siblings: PdfOutlineItem[] | null): boolean {
|
||||||
|
if (!siblings) return this.currentPage >= item.pageNumber;
|
||||||
|
|
||||||
|
const itemIndex = siblings.findIndex(s => s.title === item.title && s.pageNumber === item.pageNumber);
|
||||||
|
const nextSibling = siblings[itemIndex + 1];
|
||||||
|
|
||||||
|
if (nextSibling) {
|
||||||
|
return this.currentPage >= item.pageNumber && this.currentPage < nextSibling.pageNumber;
|
||||||
|
} else {
|
||||||
|
return this.currentPage >= item.pageNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hasActiveChild(item: PdfOutlineItem): boolean {
|
||||||
|
if (!item.children || item.children.length === 0) return false;
|
||||||
|
|
||||||
|
return item.children.some((child, index) => {
|
||||||
|
if (this.isOutlineItemActive(child, item.children)) return true;
|
||||||
|
if (this.hasActiveChild(child)) return true;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private autoExpandToCurrentPage(): void {
|
||||||
|
if (!this.pdfOutline) return;
|
||||||
|
|
||||||
|
const expandParents = (items: PdfOutlineItem[] | null): void => {
|
||||||
|
if (!items) return;
|
||||||
|
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.children && item.children.length > 0) {
|
||||||
|
if (this.hasActiveChild(item) || this.isOutlineItemActive(item, items)) {
|
||||||
|
const key = `${item.title}-${item.pageNumber}`;
|
||||||
|
this.expandedOutlineItems.add(key);
|
||||||
|
}
|
||||||
|
expandParents(item.children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
expandParents(this.pdfOutline);
|
||||||
|
}
|
||||||
|
|
||||||
onBookmarkClick(cfi: string): void {
|
onBookmarkClick(cfi: string): void {
|
||||||
this.sidebarService.navigateToBookmark(cfi);
|
this.sidebarService.navigateToBookmark(cfi);
|
||||||
}
|
}
|
||||||
@@ -106,7 +192,6 @@ export class CbxSidebarComponent implements OnInit, OnDestroy {
|
|||||||
this.sidebarService.deleteBookmark(bookmarkId);
|
this.sidebarService.deleteBookmark(bookmarkId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes methods
|
|
||||||
onNoteClick(cfi: string): void {
|
onNoteClick(cfi: string): void {
|
||||||
this.sidebarService.navigateToNote(cfi);
|
this.sidebarService.navigateToNote(cfi);
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-30
@@ -1,9 +1,10 @@
|
|||||||
import {inject, Injectable} from '@angular/core';
|
import {inject, Injectable} from '@angular/core';
|
||||||
import {BehaviorSubject, Subject} from 'rxjs';
|
import {BehaviorSubject, Subject} from 'rxjs';
|
||||||
import {takeUntil} from 'rxjs/operators';
|
import {takeUntil} from 'rxjs/operators';
|
||||||
import {CbxReaderService, CbxPageInfo} from '../../../../book/service/cbx-reader.service';
|
import {CbxPageInfo, CbxReaderService} from '../../../../book/service/cbx-reader.service';
|
||||||
|
import {NewPdfReaderService, PdfOutlineItem} from '../../../../book/service/new-pdf-reader.service';
|
||||||
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
import {UrlHelperService} from '../../../../../shared/service/url-helper.service';
|
||||||
import {Book} from '../../../../book/model/book.model';
|
import {Book, BookType} from '../../../../book/model/book.model';
|
||||||
import {BookMark, BookMarkService, CreateBookMarkRequest} from '../../../../../shared/service/book-mark.service';
|
import {BookMark, BookMarkService, CreateBookMarkRequest} from '../../../../../shared/service/book-mark.service';
|
||||||
import {BookNoteV2, BookNoteV2Service, CreateBookNoteV2Request, UpdateBookNoteV2Request} from '../../../../../shared/service/book-note-v2.service';
|
import {BookNoteV2, BookNoteV2Service, CreateBookNoteV2Request, UpdateBookNoteV2Request} from '../../../../../shared/service/book-note-v2.service';
|
||||||
|
|
||||||
@@ -20,11 +21,13 @@ export type CbxSidebarTab = 'pages' | 'bookmarks' | 'notes';
|
|||||||
export class CbxSidebarService {
|
export class CbxSidebarService {
|
||||||
private urlHelper = inject(UrlHelperService);
|
private urlHelper = inject(UrlHelperService);
|
||||||
private cbxReaderService = inject(CbxReaderService);
|
private cbxReaderService = inject(CbxReaderService);
|
||||||
|
private pdfReaderService = inject(NewPdfReaderService);
|
||||||
private bookMarkService = inject(BookMarkService);
|
private bookMarkService = inject(BookMarkService);
|
||||||
private bookNoteV2Service = inject(BookNoteV2Service);
|
private bookNoteV2Service = inject(BookNoteV2Service);
|
||||||
|
|
||||||
private destroy$ = new Subject<void>();
|
private destroy$ = new Subject<void>();
|
||||||
private bookId!: number;
|
private bookId!: number;
|
||||||
|
private bookType!: BookType;
|
||||||
|
|
||||||
private _isOpen = new BehaviorSubject<boolean>(false);
|
private _isOpen = new BehaviorSubject<boolean>(false);
|
||||||
private _activeTab = new BehaviorSubject<CbxSidebarTab>('pages');
|
private _activeTab = new BehaviorSubject<CbxSidebarTab>('pages');
|
||||||
@@ -35,6 +38,8 @@ export class CbxSidebarService {
|
|||||||
coverUrl: null
|
coverUrl: null
|
||||||
});
|
});
|
||||||
private _pages = new BehaviorSubject<CbxPageInfo[]>([]);
|
private _pages = new BehaviorSubject<CbxPageInfo[]>([]);
|
||||||
|
private _pdfOutline = new BehaviorSubject<PdfOutlineItem[] | null>(null);
|
||||||
|
private _pdfPageCount = new BehaviorSubject<number>(0);
|
||||||
private _currentPage = new BehaviorSubject<number>(1);
|
private _currentPage = new BehaviorSubject<number>(1);
|
||||||
private _bookmarks = new BehaviorSubject<BookMark[]>([]);
|
private _bookmarks = new BehaviorSubject<BookMark[]>([]);
|
||||||
private _notes = new BehaviorSubject<BookNoteV2[]>([]);
|
private _notes = new BehaviorSubject<BookNoteV2[]>([]);
|
||||||
@@ -48,6 +53,8 @@ export class CbxSidebarService {
|
|||||||
activeTab$ = this._activeTab.asObservable();
|
activeTab$ = this._activeTab.asObservable();
|
||||||
bookInfo$ = this._bookInfo.asObservable();
|
bookInfo$ = this._bookInfo.asObservable();
|
||||||
pages$ = this._pages.asObservable();
|
pages$ = this._pages.asObservable();
|
||||||
|
pdfOutline$ = this._pdfOutline.asObservable();
|
||||||
|
pdfPageCount$ = this._pdfPageCount.asObservable();
|
||||||
currentPage$ = this._currentPage.asObservable();
|
currentPage$ = this._currentPage.asObservable();
|
||||||
bookmarks$ = this._bookmarks.asObservable();
|
bookmarks$ = this._bookmarks.asObservable();
|
||||||
notes$ = this._notes.asObservable();
|
notes$ = this._notes.asObservable();
|
||||||
@@ -55,16 +62,13 @@ export class CbxSidebarService {
|
|||||||
editNote$ = this._editNote.asObservable();
|
editNote$ = this._editNote.asObservable();
|
||||||
bookmarksChanged$ = this._bookmarksChanged.asObservable();
|
bookmarksChanged$ = this._bookmarksChanged.asObservable();
|
||||||
|
|
||||||
get currentPage(): number {
|
get isPdf(): boolean {
|
||||||
return this._currentPage.value;
|
return this.bookType === 'PDF';
|
||||||
}
|
|
||||||
|
|
||||||
get activeTab(): CbxSidebarTab {
|
|
||||||
return this._activeTab.value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(bookId: number, book: Book, destroy$: Subject<void>): void {
|
initialize(bookId: number, book: Book, destroy$: Subject<void>): void {
|
||||||
this.bookId = bookId;
|
this.bookId = bookId;
|
||||||
|
this.bookType = book.bookType;
|
||||||
this.destroy$ = destroy$;
|
this.destroy$ = destroy$;
|
||||||
|
|
||||||
this._bookInfo.next({
|
this._bookInfo.next({
|
||||||
@@ -80,10 +84,26 @@ export class CbxSidebarService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private loadPageInfo(): void {
|
private loadPageInfo(): void {
|
||||||
|
if (this.bookType === 'PDF') {
|
||||||
|
this.pdfReaderService.getPageInfo(this.bookId)
|
||||||
|
.pipe(takeUntil(this.destroy$))
|
||||||
|
.subscribe(pdfInfo => {
|
||||||
|
this._pdfPageCount.next(pdfInfo.pageCount);
|
||||||
|
this._pdfOutline.next(pdfInfo.outline);
|
||||||
|
if (!pdfInfo.outline || pdfInfo.outline.length === 0) {
|
||||||
|
const pages: CbxPageInfo[] = [];
|
||||||
|
for (let i = 1; i <= pdfInfo.pageCount; i++) {
|
||||||
|
pages.push({pageNumber: i, displayName: `Page ${i}`});
|
||||||
|
}
|
||||||
|
this._pages.next(pages);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.cbxReaderService.getPageInfo(this.bookId)
|
this.cbxReaderService.getPageInfo(this.bookId)
|
||||||
.pipe(takeUntil(this.destroy$))
|
.pipe(takeUntil(this.destroy$))
|
||||||
.subscribe(pages => this._pages.next(pages));
|
.subscribe(pages => this._pages.next(pages));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private loadBookmarks(): void {
|
private loadBookmarks(): void {
|
||||||
this.bookMarkService.getBookmarksForBook(this.bookId)
|
this.bookMarkService.getBookmarksForBook(this.bookId)
|
||||||
@@ -97,10 +117,6 @@ export class CbxSidebarService {
|
|||||||
.subscribe(notes => this._notes.next(notes));
|
.subscribe(notes => this._notes.next(notes));
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshNotes(): void {
|
|
||||||
this.loadNotes();
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentPage(page: number): void {
|
setCurrentPage(page: number): void {
|
||||||
this._currentPage.next(page);
|
this._currentPage.next(page);
|
||||||
}
|
}
|
||||||
@@ -125,7 +141,6 @@ export class CbxSidebarService {
|
|||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bookmark methods - using page number as the location identifier (stored in cfi field)
|
|
||||||
isPageBookmarked(pageNumber: number): boolean {
|
isPageBookmarked(pageNumber: number): boolean {
|
||||||
const pageStr = pageNumber.toString();
|
const pageStr = pageNumber.toString();
|
||||||
return this._bookmarks.value.some(b => b.cfi === pageStr);
|
return this._bookmarks.value.some(b => b.cfi === pageStr);
|
||||||
@@ -177,17 +192,11 @@ export class CbxSidebarService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notes methods - using page number as the location identifier (stored in cfi field)
|
|
||||||
pageHasNotes(pageNumber: number): boolean {
|
pageHasNotes(pageNumber: number): boolean {
|
||||||
const pageStr = pageNumber.toString();
|
const pageStr = pageNumber.toString();
|
||||||
return this._notes.value.some(n => n.cfi === pageStr);
|
return this._notes.value.some(n => n.cfi === pageStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
getNotesForPage(pageNumber: number): BookNoteV2[] {
|
|
||||||
const pageStr = pageNumber.toString();
|
|
||||||
return this._notes.value.filter(n => n.cfi === pageStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
createNote(pageNumber: number, noteContent: string, color?: string): void {
|
createNote(pageNumber: number, noteContent: string, color?: string): void {
|
||||||
const request: CreateBookNoteV2Request = {
|
const request: CreateBookNoteV2Request = {
|
||||||
bookId: this.bookId,
|
bookId: this.bookId,
|
||||||
@@ -249,15 +258,4 @@ export class CbxSidebarService {
|
|||||||
(note.chapterTitle?.toLowerCase().includes(query))
|
(note.chapterTitle?.toLowerCase().includes(query))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset(): void {
|
|
||||||
this._isOpen.next(false);
|
|
||||||
this._activeTab.next('pages');
|
|
||||||
this._bookInfo.next({ id: null, title: '', authors: '', coverUrl: null });
|
|
||||||
this._pages.next([]);
|
|
||||||
this._currentPage.next(1);
|
|
||||||
this._bookmarks.next([]);
|
|
||||||
this._notes.next([]);
|
|
||||||
this._notesSearchQuery.next('');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,5 @@ export * from './dialogs/metadata-dialog.component';
|
|||||||
export * from './dialogs/note-dialog.component';
|
export * from './dialogs/note-dialog.component';
|
||||||
|
|
||||||
export * from './shared/icon.component';
|
export * from './shared/icon.component';
|
||||||
export * from './shared/selection-popup.component';
|
|
||||||
export * from './shared/visibility.util';
|
export * from './shared/visibility.util';
|
||||||
export * from './shared/header-footer.util';
|
export * from './shared/header-footer.util';
|
||||||
|
|||||||
+123
@@ -0,0 +1,123 @@
|
|||||||
|
<div class="pdf-preferences-container">
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">Page Spread</label>
|
||||||
|
<div class="button-group">
|
||||||
|
@for (spread of pdfSpreads; track spread) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="option-button"
|
||||||
|
[class.selected]="selectedPdfSpread === spread.key"
|
||||||
|
(click)="selectedPdfSpread = spread.key">
|
||||||
|
<i [class]="spread.icon"></i>
|
||||||
|
<span class="option-text">{{ spread.name }}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
Configure how PDF pages are displayed - single page or double page spread.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">Page Layout</label>
|
||||||
|
<div class="button-group">
|
||||||
|
@for (mode of pdfViewModes; track mode) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="option-button"
|
||||||
|
[class.selected]="selectedPdfViewMode === mode.key"
|
||||||
|
(click)="selectedPdfViewMode = mode.key">
|
||||||
|
<i [class]="mode.icon"></i>
|
||||||
|
<span class="option-text">{{ mode.name }}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
Choose how PDF pages are displayed while reading.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">Fit Mode</label>
|
||||||
|
<div class="button-group">
|
||||||
|
@for (mode of pdfFitModes; track mode) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="option-button"
|
||||||
|
[class.selected]="selectedPdfFitMode === mode.key"
|
||||||
|
(click)="selectedPdfFitMode = mode.key"
|
||||||
|
[pTooltip]="mode.name"
|
||||||
|
tooltipPosition="bottom">
|
||||||
|
<i [class]="mode.icon"></i>
|
||||||
|
<span class="option-text">{{ mode.name }}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
Select how pages should be scaled to fit the reader window.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">Scroll Mode</label>
|
||||||
|
<div class="button-group">
|
||||||
|
@for (mode of pdfScrollModes; track mode) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="option-button"
|
||||||
|
[class.selected]="selectedPdfScrollMode === mode.key"
|
||||||
|
(click)="selectedPdfScrollMode = mode.key">
|
||||||
|
<i [class]="mode.icon"></i>
|
||||||
|
<span class="option-text">{{ mode.name }}</span>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
Choose between paginated or infinite scroll reading experience.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="setting-item">
|
||||||
|
<div class="setting-info">
|
||||||
|
<div class="setting-label-row">
|
||||||
|
<label class="setting-label">Background Color</label>
|
||||||
|
<div class="theme-selector">
|
||||||
|
@for (color of pdfBackgroundColors; track color) {
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="theme-option"
|
||||||
|
[class.selected]="selectedPdfBackgroundColor === color.key"
|
||||||
|
[style.background-color]="color.color"
|
||||||
|
(click)="selectedPdfBackgroundColor = color.key"
|
||||||
|
[attr.aria-label]="color.name"
|
||||||
|
[pTooltip]="color.name"
|
||||||
|
tooltipPosition="bottom">
|
||||||
|
@if (selectedPdfBackgroundColor === color.key) {
|
||||||
|
<i class="pi pi-check"></i>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="setting-description">
|
||||||
|
Set the background color for the PDF reader.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
+140
@@ -0,0 +1,140 @@
|
|||||||
|
.pdf-preferences-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 2rem;
|
||||||
|
padding: 0.25rem 0;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-info {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
|
||||||
|
.setting-label {
|
||||||
|
display: block;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--p-text-color);
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-label-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 1rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.setting-label {
|
||||||
|
margin-bottom: 0;
|
||||||
|
flex-shrink: 0;
|
||||||
|
min-width: 100px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.setting-description {
|
||||||
|
color: var(--p-text-muted-color);
|
||||||
|
font-size: 0.875rem;
|
||||||
|
line-height: 1.5;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.option-button {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 0.375rem;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
border: 1.5px solid color-mix(in srgb, var(--text-color) 20%, transparent);
|
||||||
|
background: color-mix(in srgb, var(--text-color) 5%, transparent);
|
||||||
|
color: var(--text-color);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
font-weight: 500;
|
||||||
|
min-width: 4.5rem;
|
||||||
|
|
||||||
|
i {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.option-text {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
||||||
|
border-color: color-mix(in srgb, var(--primary-color) 40%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.selected {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
background: color-mix(in srgb, var(--primary-color) 10%, transparent);
|
||||||
|
color: var(--primary-color);
|
||||||
|
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 15%, transparent);
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.theme-selector {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.theme-option {
|
||||||
|
width: 2.5rem;
|
||||||
|
height: 2.5rem;
|
||||||
|
border-radius: 0.375rem;
|
||||||
|
border: 1.5px solid transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
i {
|
||||||
|
color: white;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
font-weight: bold;
|
||||||
|
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: scale(1.1);
|
||||||
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.selected {
|
||||||
|
border-color: var(--primary-color);
|
||||||
|
box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-color) 25%, transparent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+102
@@ -0,0 +1,102 @@
|
|||||||
|
import {Component, inject, Input} from '@angular/core';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {PdfBackgroundColor, PdfFitMode, PdfPageSpread, PdfPageViewMode, PdfScrollMode, UserSettings} from '../../user-management/user.service';
|
||||||
|
import {ReaderPreferencesService} from '../reader-preferences.service';
|
||||||
|
import {TooltipModule} from 'primeng/tooltip';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-new-pdf-reader-preferences-component',
|
||||||
|
imports: [
|
||||||
|
FormsModule,
|
||||||
|
TooltipModule
|
||||||
|
],
|
||||||
|
templateUrl: './new-pdf-reader-preferences-component.html',
|
||||||
|
styleUrl: './new-pdf-reader-preferences-component.scss'
|
||||||
|
})
|
||||||
|
export class NewPdfReaderPreferencesComponent {
|
||||||
|
|
||||||
|
@Input() userSettings!: UserSettings;
|
||||||
|
|
||||||
|
private readonly readerPreferencesService = inject(ReaderPreferencesService);
|
||||||
|
|
||||||
|
private static readonly SETTING_ROOT = 'newPdfReaderSetting';
|
||||||
|
private static readonly PROP_PAGE_SPREAD = 'pageSpread';
|
||||||
|
private static readonly PROP_PAGE_VIEW_MODE = 'pageViewMode';
|
||||||
|
private static readonly PROP_FIT_MODE = 'fitMode';
|
||||||
|
private static readonly PROP_SCROLL_MODE = 'scrollMode';
|
||||||
|
private static readonly PROP_BACKGROUND_COLOR = 'backgroundColor';
|
||||||
|
|
||||||
|
readonly pdfSpreads = [
|
||||||
|
{name: 'Even', key: PdfPageSpread.EVEN, icon: 'pi pi-align-left'},
|
||||||
|
{name: 'Odd', key: PdfPageSpread.ODD, icon: 'pi pi-align-right'}
|
||||||
|
];
|
||||||
|
|
||||||
|
readonly pdfViewModes = [
|
||||||
|
{name: 'Single Page', key: PdfPageViewMode.SINGLE_PAGE, icon: 'pi pi-book'},
|
||||||
|
{name: 'Two Page', key: PdfPageViewMode.TWO_PAGE, icon: 'pi pi-copy'},
|
||||||
|
];
|
||||||
|
|
||||||
|
readonly pdfFitModes = [
|
||||||
|
{name: 'Fit Page', key: PdfFitMode.FIT_PAGE, icon: 'pi pi-window-maximize'},
|
||||||
|
{name: 'Fit Width', key: PdfFitMode.FIT_WIDTH, icon: 'pi pi-arrows-h'},
|
||||||
|
{name: 'Fit Height', key: PdfFitMode.FIT_HEIGHT, icon: 'pi pi-arrows-v'},
|
||||||
|
{name: 'Actual Size', key: PdfFitMode.ACTUAL_SIZE, icon: 'pi pi-expand'},
|
||||||
|
{name: 'Automatic', key: PdfFitMode.AUTO, icon: 'pi pi-sparkles'}
|
||||||
|
];
|
||||||
|
|
||||||
|
readonly pdfScrollModes = [
|
||||||
|
{name: 'Paginated', key: PdfScrollMode.PAGINATED, icon: 'pi pi-book'},
|
||||||
|
{name: 'Infinite', key: PdfScrollMode.INFINITE, icon: 'pi pi-sort-alt'}
|
||||||
|
];
|
||||||
|
|
||||||
|
readonly pdfBackgroundColors = [
|
||||||
|
{name: 'Gray', key: PdfBackgroundColor.GRAY, color: '#808080'},
|
||||||
|
{name: 'Black', key: PdfBackgroundColor.BLACK, color: '#000000'},
|
||||||
|
{name: 'White', key: PdfBackgroundColor.WHITE, color: '#FFFFFF'}
|
||||||
|
];
|
||||||
|
|
||||||
|
get selectedPdfSpread(): PdfPageSpread {
|
||||||
|
return this.userSettings.newPdfReaderSetting.pageSpread ?? PdfPageSpread.EVEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedPdfSpread(value: PdfPageSpread) {
|
||||||
|
this.userSettings.newPdfReaderSetting.pageSpread = value;
|
||||||
|
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_SPREAD], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectedPdfViewMode(): PdfPageViewMode {
|
||||||
|
return this.userSettings.newPdfReaderSetting.pageViewMode ?? PdfPageViewMode.SINGLE_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedPdfViewMode(value: PdfPageViewMode) {
|
||||||
|
this.userSettings.newPdfReaderSetting.pageViewMode = value;
|
||||||
|
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_PAGE_VIEW_MODE], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectedPdfFitMode(): PdfFitMode {
|
||||||
|
return this.userSettings.newPdfReaderSetting.fitMode ?? PdfFitMode.FIT_PAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedPdfFitMode(value: PdfFitMode) {
|
||||||
|
this.userSettings.newPdfReaderSetting.fitMode = value;
|
||||||
|
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_FIT_MODE], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectedPdfScrollMode(): PdfScrollMode {
|
||||||
|
return this.userSettings.newPdfReaderSetting.scrollMode ?? PdfScrollMode.PAGINATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedPdfScrollMode(value: PdfScrollMode) {
|
||||||
|
this.userSettings.newPdfReaderSetting.scrollMode = value;
|
||||||
|
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_SCROLL_MODE], value);
|
||||||
|
}
|
||||||
|
|
||||||
|
get selectedPdfBackgroundColor(): PdfBackgroundColor {
|
||||||
|
return this.userSettings.newPdfReaderSetting.backgroundColor ?? PdfBackgroundColor.GRAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedPdfBackgroundColor(value: PdfBackgroundColor) {
|
||||||
|
this.userSettings.newPdfReaderSetting.backgroundColor = value;
|
||||||
|
this.readerPreferencesService.updatePreference([NewPdfReaderPreferencesComponent.SETTING_ROOT, NewPdfReaderPreferencesComponent.PROP_BACKGROUND_COLOR], value);
|
||||||
|
}
|
||||||
|
}
|
||||||
+18
@@ -147,6 +147,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="preferences-section">
|
||||||
|
<div class="section-header">
|
||||||
|
<h3 class="section-title">
|
||||||
|
<i class="pi pi-file-pdf"></i>
|
||||||
|
Streaming PDF Reader: Default Settings
|
||||||
|
</h3>
|
||||||
|
<p class="section-description">
|
||||||
|
Configure default preferences for the streaming PDF reader. When "Default Override" mode is enabled, these settings will take precedence over per-file preferences. Adjust page layout, zoom behavior, scrolling mode, and rendering options for an optimal reading experience.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="settings-card">
|
||||||
|
<app-new-pdf-reader-preferences-component
|
||||||
|
[userSettings]="userSettings">
|
||||||
|
</app-new-pdf-reader-preferences-component>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
@if (hasFontManagementPermission) {
|
@if (hasFontManagementPermission) {
|
||||||
<div class="preferences-section">
|
<div class="preferences-section">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
|
|||||||
+2
-1
@@ -10,13 +10,14 @@ import {EpubReaderPreferencesComponent} from './epub-reader-preferences/epub-rea
|
|||||||
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences/pdf-reader-preferences-component';
|
import {PdfReaderPreferencesComponent} from './pdf-reader-preferences/pdf-reader-preferences-component';
|
||||||
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences/cbx-reader-preferences-component';
|
import {CbxReaderPreferencesComponent} from './cbx-reader-preferences/cbx-reader-preferences-component';
|
||||||
import {CustomFontsComponent} from '../custom-fonts/custom-fonts.component';
|
import {CustomFontsComponent} from '../custom-fonts/custom-fonts.component';
|
||||||
|
import {NewPdfReaderPreferencesComponent} from './new-pdf-reader-preferences/new-pdf-reader-preferences-component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-reader-preferences',
|
selector: 'app-reader-preferences',
|
||||||
templateUrl: './reader-preferences.component.html',
|
templateUrl: './reader-preferences.component.html',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
styleUrls: ['./reader-preferences.component.scss'],
|
styleUrls: ['./reader-preferences.component.scss'],
|
||||||
imports: [FormsModule, TooltipModule, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent]
|
imports: [FormsModule, TooltipModule, EpubReaderPreferencesComponent, PdfReaderPreferencesComponent, CbxReaderPreferencesComponent, CustomFontsComponent, NewPdfReaderPreferencesComponent]
|
||||||
})
|
})
|
||||||
export class ReaderPreferences implements OnInit, OnDestroy {
|
export class ReaderPreferences implements OnInit, OnDestroy {
|
||||||
readonly scopeOptions = [
|
readonly scopeOptions = [
|
||||||
|
|||||||
+3
-2
@@ -2,7 +2,7 @@ import {beforeEach, describe, expect, it, vi} from 'vitest';
|
|||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {EnvironmentInjector, runInInjectionContext} from '@angular/core';
|
import {EnvironmentInjector, runInInjectionContext} from '@angular/core';
|
||||||
import {ReaderPreferencesService} from './reader-preferences.service';
|
import {ReaderPreferencesService} from './reader-preferences.service';
|
||||||
import {CbxFitMode, CbxPageSpread, CbxPageViewMode, PdfPageSpread, PdfPageViewMode, User, UserService} from '../user-management/user.service';
|
import {CbxFitMode, CbxPageSpread, CbxPageViewMode, PdfFitMode, PdfPageSpread, PdfPageViewMode, User, UserService} from '../user-management/user.service';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {of, Subject} from 'rxjs';
|
import {of, Subject} from 'rxjs';
|
||||||
|
|
||||||
@@ -65,7 +65,8 @@ const mockUser: User = {
|
|||||||
},
|
},
|
||||||
newPdfReaderSetting: {
|
newPdfReaderSetting: {
|
||||||
pageSpread: PdfPageSpread.EVEN,
|
pageSpread: PdfPageSpread.EVEN,
|
||||||
pageViewMode: PdfPageViewMode.SINGLE_PAGE
|
pageViewMode: PdfPageViewMode.SINGLE_PAGE,
|
||||||
|
fitMode: PdfFitMode.ACTUAL_SIZE
|
||||||
},
|
},
|
||||||
sidebarLibrarySorting: {field: '', order: ''},
|
sidebarLibrarySorting: {field: '', order: ''},
|
||||||
sidebarShelfSorting: {field: '', order: ''},
|
sidebarShelfSorting: {field: '', order: ''},
|
||||||
|
|||||||
@@ -52,17 +52,6 @@ export type PageSpread = 'off' | 'even' | 'odd';
|
|||||||
export type BookFilterMode = 'and' | 'or' | 'single';
|
export type BookFilterMode = 'and' | 'or' | 'single';
|
||||||
export type FilterSortingMode = 'alphabetical' | 'count';
|
export type FilterSortingMode = 'alphabetical' | 'count';
|
||||||
|
|
||||||
export enum CbxBackgroundColor {
|
|
||||||
GRAY = 'GRAY',
|
|
||||||
BLACK = 'BLACK',
|
|
||||||
WHITE = 'WHITE'
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PdfReaderSetting {
|
|
||||||
pageSpread: PageSpread;
|
|
||||||
pageZoom: string;
|
|
||||||
showSidebar: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum CbxPageViewMode {
|
export enum CbxPageViewMode {
|
||||||
SINGLE_PAGE = 'SINGLE_PAGE',
|
SINGLE_PAGE = 'SINGLE_PAGE',
|
||||||
@@ -74,14 +63,10 @@ export enum CbxPageSpread {
|
|||||||
ODD = 'ODD',
|
ODD = 'ODD',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PdfPageViewMode {
|
export enum CbxBackgroundColor {
|
||||||
SINGLE_PAGE = 'SINGLE_PAGE',
|
GRAY = 'GRAY',
|
||||||
TWO_PAGE = 'TWO_PAGE',
|
BLACK = 'BLACK',
|
||||||
}
|
WHITE = 'WHITE'
|
||||||
|
|
||||||
export enum PdfPageSpread {
|
|
||||||
EVEN = 'EVEN',
|
|
||||||
ODD = 'ODD',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CbxFitMode {
|
export enum CbxFitMode {
|
||||||
@@ -97,6 +82,49 @@ export enum CbxScrollMode {
|
|||||||
INFINITE = 'INFINITE'
|
INFINITE = 'INFINITE'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PdfReaderSetting {
|
||||||
|
pageSpread: PageSpread;
|
||||||
|
pageZoom: string;
|
||||||
|
showSidebar: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfPageViewMode {
|
||||||
|
SINGLE_PAGE = 'SINGLE_PAGE',
|
||||||
|
TWO_PAGE = 'TWO_PAGE',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfPageSpread {
|
||||||
|
EVEN = 'EVEN',
|
||||||
|
ODD = 'ODD',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfBackgroundColor {
|
||||||
|
GRAY = 'GRAY',
|
||||||
|
BLACK = 'BLACK',
|
||||||
|
WHITE = 'WHITE'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfFitMode {
|
||||||
|
ACTUAL_SIZE = 'ACTUAL_SIZE',
|
||||||
|
FIT_PAGE = 'FIT_PAGE',
|
||||||
|
FIT_WIDTH = 'FIT_WIDTH',
|
||||||
|
FIT_HEIGHT = 'FIT_HEIGHT',
|
||||||
|
AUTO = 'AUTO'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfScrollMode {
|
||||||
|
PAGINATED = 'PAGINATED',
|
||||||
|
INFINITE = 'INFINITE'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NewPdfReaderSetting {
|
||||||
|
pageSpread: PdfPageSpread;
|
||||||
|
pageViewMode: PdfPageViewMode;
|
||||||
|
fitMode: PdfFitMode;
|
||||||
|
scrollMode?: PdfScrollMode;
|
||||||
|
backgroundColor?: PdfBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EbookReaderSetting {
|
export interface EbookReaderSetting {
|
||||||
lineHeight: number;
|
lineHeight: number;
|
||||||
justify: boolean;
|
justify: boolean;
|
||||||
@@ -132,11 +160,6 @@ export interface CbxReaderSetting {
|
|||||||
backgroundColor?: CbxBackgroundColor;
|
backgroundColor?: CbxBackgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NewPdfReaderSetting {
|
|
||||||
pageSpread: PdfPageSpread;
|
|
||||||
pageViewMode: PdfPageViewMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TableColumnPreference {
|
export interface TableColumnPreference {
|
||||||
field: string;
|
field: string;
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
|||||||
Reference in New Issue
Block a user