feat(pdf): move ebook reader to embedpdf, add bookmarks, remove old pdf.js stuff (#393)
* feat(pdf): move ebook reader to embedpdf, add bookmarks, remove old pdf.js stuff * feat(pdf): add page number support for bookmarks and enhance mobile navigation * feat(pdf): implement document ID tracking for search functionality * feat(pdf): add page number column to book marks and update unique index * feat(pdf): enhance annotation handling and improve search result scrolling * feat(pdf): improve layout handling and enhance resize observer functionality * feat(pdf): improve document viewer initialization and improve close button styling * fix(pdf): remove 'form' from disabled categories * feat(pdf): add pan mode functionality and enhance sidebar layout * feat(pdf): improve book viewer initialization with enhanced element detection * feat(pdf): add link handling to text selection and improve popup actions * feat(pdf): enhance link detection and improve selection handling in event service * feat(pdf): improve accessibility and improve resource management in PDF viewer * feat(pdf): add resize observer for improved layout handling * feat(pdf): error handling and improve navigation in PDF reader
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import {Shelf} from './shelf.model';
|
||||
import {CbxBackgroundColor, CbxFitMode, CbxPageSpread, CbxPageSplitOption, CbxPageViewMode, CbxScrollMode, NewPdfReaderSetting} from '../../settings/user-management/user.service';
|
||||
import {BookReview} from '../components/book-reviews/book-review-service';
|
||||
import {ZoomType} from 'ngx-extended-pdf-viewer';
|
||||
|
||||
export type BookType = "PDF" | "EPUB" | "CBX" | "FB2" | "MOBI" | "AZW3" | "AUDIOBOOK";
|
||||
|
||||
@@ -303,8 +302,8 @@ export interface MetadataUpdateWrapper {
|
||||
}
|
||||
|
||||
export interface PdfViewerSetting {
|
||||
zoom: ZoomType;
|
||||
spread: 'off' | 'even' | 'odd';
|
||||
zoom: string;
|
||||
spread: 'none' | 'even' | 'odd';
|
||||
isDarkTheme?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,18 @@ interface TestView extends HTMLDivElement {
|
||||
interface RangeLike {
|
||||
toString: () => string;
|
||||
getBoundingClientRect: () => DOMRect;
|
||||
commonAncestorContainer: Node;
|
||||
startContainer: Node;
|
||||
endContainer: Node;
|
||||
intersectsNode: (node: Node) => boolean;
|
||||
}
|
||||
|
||||
interface TestSelection {
|
||||
isCollapsed: boolean;
|
||||
rangeCount: number;
|
||||
getRangeAt: (index: number) => RangeLike;
|
||||
anchorNode: Node | null;
|
||||
focusNode: Node | null;
|
||||
}
|
||||
|
||||
interface PrivateReaderEventService {
|
||||
@@ -138,7 +144,13 @@ describe('ReaderEventService', () => {
|
||||
getRangeAt: () => ({
|
||||
toString: () => '',
|
||||
getBoundingClientRect: () => new DOMRect(0, 0, 0, 0),
|
||||
commonAncestorContainer: doc.body,
|
||||
startContainer: doc.body,
|
||||
endContainer: doc.body,
|
||||
intersectsNode: () => false,
|
||||
}),
|
||||
anchorNode: null,
|
||||
focusNode: null,
|
||||
};
|
||||
defaultView = {
|
||||
frameElement: iframe,
|
||||
@@ -296,11 +308,17 @@ describe('ReaderEventService', () => {
|
||||
const selectedRange: RangeLike = {
|
||||
toString: () => 'Highlighted text',
|
||||
getBoundingClientRect: () => new DOMRect(20, 15, 80, 20),
|
||||
commonAncestorContainer: doc.body,
|
||||
startContainer: doc.body,
|
||||
endContainer: doc.body,
|
||||
intersectsNode: () => false,
|
||||
};
|
||||
installSelection(doc, {
|
||||
isCollapsed: false,
|
||||
rangeCount: 1,
|
||||
getRangeAt: () => selectedRange,
|
||||
anchorNode: doc.body,
|
||||
focusNode: doc.body,
|
||||
});
|
||||
getContents.mockReturnValue([{index: 7, doc}]);
|
||||
getCFI.mockReturnValue('epubcfi(/6/2!/4/2:0)');
|
||||
@@ -324,11 +342,17 @@ describe('ReaderEventService', () => {
|
||||
const emptyRange: RangeLike = {
|
||||
toString: () => ' ',
|
||||
getBoundingClientRect: () => new DOMRect(0, 0, 0, 0),
|
||||
commonAncestorContainer: doc.body,
|
||||
startContainer: doc.body,
|
||||
endContainer: doc.body,
|
||||
intersectsNode: () => false,
|
||||
};
|
||||
installSelection(doc, {
|
||||
isCollapsed: false,
|
||||
rangeCount: 1,
|
||||
getRangeAt: () => emptyRange,
|
||||
anchorNode: doc.body,
|
||||
focusNode: doc.body,
|
||||
});
|
||||
|
||||
privateService.handleSelectionChange(doc);
|
||||
@@ -338,11 +362,17 @@ describe('ReaderEventService', () => {
|
||||
const visibleRange: RangeLike = {
|
||||
toString: () => 'Visible note',
|
||||
getBoundingClientRect: () => new DOMRect(10, 10, 60, 25),
|
||||
commonAncestorContainer: doc.body,
|
||||
startContainer: doc.body,
|
||||
endContainer: doc.body,
|
||||
intersectsNode: () => false,
|
||||
};
|
||||
installSelection(doc, {
|
||||
isCollapsed: false,
|
||||
rangeCount: 1,
|
||||
getRangeAt: () => visibleRange,
|
||||
anchorNode: doc.body,
|
||||
focusNode: doc.body,
|
||||
});
|
||||
getContents.mockReturnValue([{index: 3, doc}]);
|
||||
getCFI.mockReturnValueOnce(null).mockReturnValueOnce('epubcfi(/6/8!/4/2:0)');
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface TextSelection {
|
||||
cfi: string;
|
||||
range: Range;
|
||||
index: number;
|
||||
linkUrl?: string;
|
||||
}
|
||||
|
||||
interface PopupPosition {
|
||||
@@ -476,15 +477,58 @@ export class ReaderEventService {
|
||||
|
||||
popupX = Math.max(100, Math.min(popupX, window.innerWidth - 150));
|
||||
|
||||
const linkUrl = this.getLinkUrl(range, selection);
|
||||
|
||||
this.eventSubject.next({
|
||||
type: 'text-selected',
|
||||
detail: {text, cfi, range, index},
|
||||
detail: {text, cfi, range, index, linkUrl},
|
||||
popupPosition: {x: popupX, y: popupY, showBelow}
|
||||
});
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
|
||||
private getLinkUrl(range: Range, selection: Selection): string | undefined {
|
||||
const getLinkFromNode = (node: Node | null | undefined): string | undefined => {
|
||||
let current: Node | null | undefined = node;
|
||||
while (current && current.nodeType !== Node.DOCUMENT_NODE) {
|
||||
if (current.nodeType === Node.ELEMENT_NODE) {
|
||||
const element = current as HTMLElement;
|
||||
if (element.tagName?.toLowerCase() === 'a') {
|
||||
return element.getAttribute('href') || undefined;
|
||||
}
|
||||
const closestLink = typeof element.closest === 'function' ? element.closest('a') : null;
|
||||
if (closestLink?.getAttribute('href')) {
|
||||
return closestLink.getAttribute('href')!;
|
||||
}
|
||||
}
|
||||
current = current.parentNode;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
// Check ancestors and self for common ancestor, start, end, anchor and focus nodes
|
||||
let linkUrl = getLinkFromNode(range.commonAncestorContainer) ||
|
||||
getLinkFromNode(range.startContainer) ||
|
||||
getLinkFromNode(range.endContainer) ||
|
||||
getLinkFromNode(selection.anchorNode) ||
|
||||
getLinkFromNode(selection.focusNode);
|
||||
|
||||
// If still not found, check if the range contains any links
|
||||
if (!linkUrl && range.commonAncestorContainer?.nodeType === Node.ELEMENT_NODE) {
|
||||
const containerElement = range.commonAncestorContainer as HTMLElement;
|
||||
// Find all links in the container
|
||||
if (typeof containerElement.querySelectorAll === 'function') {
|
||||
const links = Array.from(containerElement.querySelectorAll('a'));
|
||||
// Find the first link that intersects with the selection range
|
||||
const internalLink = links.find(link => typeof range.intersectsNode === 'function' && range.intersectsNode(link));
|
||||
linkUrl = internalLink?.getAttribute('href') || undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return linkUrl;
|
||||
}
|
||||
|
||||
private handleIframeClickMessage(data: IframeClickMessage): void {
|
||||
if (!this.view) return;
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
[showBelow]="selectionState().showBelow"
|
||||
[overlappingAnnotationId]="selectionState().overlappingAnnotationId"
|
||||
[selectedText]="selectionState().selectedText"
|
||||
[linkUrl]="selectionState().linkUrl"
|
||||
(action)="handleSelectionAction($event)"
|
||||
></app-text-selection-popup>
|
||||
|
||||
|
||||
@@ -345,12 +345,12 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
this.toggleImmersiveMode();
|
||||
break;
|
||||
case 'go-first-section':
|
||||
this.viewManager.goToSection(0).subscribe();
|
||||
this.viewManager.goToSection(0).pipe(catchError(() => of(undefined))).subscribe();
|
||||
break;
|
||||
case 'go-last-section': {
|
||||
const s = this.progressService.currentProgressData?.section;
|
||||
if (s && s.total > 0) {
|
||||
this.viewManager.goToSection(s.total - 1).subscribe();
|
||||
this.viewManager.goToSection(s.total - 1).pipe(catchError(() => of(undefined))).subscribe();
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -429,7 +429,10 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
|
||||
onProgressChange(fraction: number): void {
|
||||
this.viewManager.goToFraction(fraction)
|
||||
.pipe(takeUntil(this.destroy$))
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError(() => of(undefined))
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
@@ -481,6 +484,17 @@ export class EbookReaderComponent implements OnInit, OnDestroy {
|
||||
handleSelectionAction(action: TextSelectionAction): void {
|
||||
if (action.type === 'note') {
|
||||
this.noteService.openNewNoteDialog();
|
||||
} else if (action.type === 'go-to-link') {
|
||||
const linkUrl = this.selectionState().linkUrl;
|
||||
if (linkUrl) {
|
||||
this.viewManager.goTo(linkUrl)
|
||||
.pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError(() => of(undefined))
|
||||
)
|
||||
.subscribe();
|
||||
}
|
||||
this.selectionService.handleAction(action);
|
||||
} else {
|
||||
this.selectionService.handleAction(action);
|
||||
}
|
||||
|
||||
+10
-2
@@ -14,6 +14,7 @@ export interface SelectionState {
|
||||
showBelow: boolean;
|
||||
overlappingAnnotationId: number | null;
|
||||
selectedText: string;
|
||||
linkUrl?: string;
|
||||
}
|
||||
|
||||
export interface SelectionDetail {
|
||||
@@ -21,6 +22,7 @@ export interface SelectionDetail {
|
||||
cfi: string;
|
||||
range: Range;
|
||||
index: number;
|
||||
linkUrl?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -48,7 +50,8 @@ export class ReaderSelectionService {
|
||||
position: {x: 0, y: 0},
|
||||
showBelow: false,
|
||||
overlappingAnnotationId: null,
|
||||
selectedText: ''
|
||||
selectedText: '',
|
||||
linkUrl: undefined
|
||||
};
|
||||
|
||||
private readonly _state = signal<SelectionState>(this.defaultState);
|
||||
@@ -121,6 +124,10 @@ export class ReaderSelectionService {
|
||||
action.color || '#FFFF00',
|
||||
action.style || 'highlight'
|
||||
);
|
||||
} else if (action.type === 'go-to-link' && this.currentSelection?.linkUrl) {
|
||||
// Handled by component, but we clear state here
|
||||
this.clearPreview();
|
||||
this.viewManager.clearSelection();
|
||||
}
|
||||
|
||||
this.currentSelection = null;
|
||||
@@ -283,7 +290,8 @@ export class ReaderSelectionService {
|
||||
position: this._position,
|
||||
showBelow: this._showBelow,
|
||||
overlappingAnnotationId: this._overlappingAnnotationId,
|
||||
selectedText: this.currentSelection?.text || ''
|
||||
selectedText: this.currentSelection?.text || '',
|
||||
linkUrl: this.currentSelection?.linkUrl
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ export type ReaderIconName =
|
||||
| 'long-strip'
|
||||
| 'direction-ltr'
|
||||
| 'direction-rtl'
|
||||
| 'magnifier';
|
||||
| 'magnifier'
|
||||
| 'link';
|
||||
|
||||
interface IconPath {
|
||||
d: string;
|
||||
@@ -199,6 +200,10 @@ const ICONS: Record<ReaderIconName, IconPath[]> = {
|
||||
{d: 'M21 21l-5-5'},
|
||||
{d: 'M7,10 L13,10', type: 'line'},
|
||||
{d: 'M10,7 L10,13', type: 'line'}
|
||||
],
|
||||
'link': [
|
||||
{d: 'M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71'},
|
||||
{d: 'M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
<app-reader-icon name="copy" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
@if (linkUrl) {
|
||||
<div class="divider"></div>
|
||||
<button class="action-btn" (click)="onGoToLink()" [title]="t('goToLink')">
|
||||
<app-reader-icon name="link" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
}
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<button class="action-btn" (click)="onSearch()" [title]="t('searchInBook')">
|
||||
|
||||
@@ -6,7 +6,7 @@ import {ReaderIconComponent} from './icon.component';
|
||||
export type AnnotationStyle = 'highlight' | 'underline' | 'strikethrough' | 'squiggly';
|
||||
|
||||
export interface TextSelectionAction {
|
||||
type: 'select' | 'annotate' | 'delete' | 'dismiss' | 'preview' | 'search' | 'note';
|
||||
type: 'select' | 'annotate' | 'delete' | 'dismiss' | 'preview' | 'search' | 'note' | 'go-to-link';
|
||||
color?: string;
|
||||
style?: AnnotationStyle;
|
||||
annotationId?: number;
|
||||
@@ -37,6 +37,7 @@ export class TextSelectionPopupComponent {
|
||||
@Input() showBelow = false;
|
||||
@Input() overlappingAnnotationId: number | null = null;
|
||||
@Input() selectedText = '';
|
||||
@Input() linkUrl?: string;
|
||||
@Output() action = new EventEmitter<TextSelectionAction>();
|
||||
|
||||
showAnnotationOptions = false;
|
||||
@@ -122,6 +123,12 @@ export class TextSelectionPopupComponent {
|
||||
this.hasPreview = false;
|
||||
}
|
||||
|
||||
onGoToLink(): void {
|
||||
if (this.linkUrl) {
|
||||
this.action.emit({type: 'go-to-link'});
|
||||
}
|
||||
}
|
||||
|
||||
onNote(): void {
|
||||
this.action.emit({type: 'note'});
|
||||
this.showAnnotationOptions = false;
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
<ng-container *transloco="let t; prefix: 'readerPdf.sidebar'">
|
||||
@if (visible()) {
|
||||
<div class="sidebar-overlay" role="button" tabindex="0" (click)="onOverlayClick()" (keydown.enter)="onOverlayClick()" [class.closing]="closing()">
|
||||
<aside class="sidebar" role="button" tabindex="0" (click)="$event.stopPropagation()" (keydown.enter)="$event.stopPropagation()" [class.closing]="closing()">
|
||||
|
||||
<!-- Sidebar Header -->
|
||||
<header class="sidebar-header">
|
||||
<h2 class="sidebar-title">{{ t('title') }}</h2>
|
||||
<button class="sidebar-close-btn" (click)="closed.emit()" [attr.aria-label]="t('close')">
|
||||
<app-reader-icon name="close" [size]="18"></app-reader-icon>
|
||||
</button>
|
||||
</header>
|
||||
|
||||
<!-- Tab navigation -->
|
||||
<nav class="tabs">
|
||||
<button
|
||||
class="tab"
|
||||
[class.active]="activeTab() === 'contents'"
|
||||
(click)="setActiveTab('contents')">
|
||||
<app-reader-icon name="book" class="tab-icon"></app-reader-icon>
|
||||
<span>{{ t('contentsTab') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="tab"
|
||||
[class.active]="activeTab() === 'bookmarks'"
|
||||
(click)="setActiveTab('bookmarks')">
|
||||
<app-reader-icon name="bookmark" class="tab-icon"></app-reader-icon>
|
||||
<span>{{ t('bookmarksTab') }}</span>
|
||||
@if (bookmarks().length > 0) {
|
||||
<span class="badge">{{ bookmarks().length }}</span>
|
||||
}
|
||||
</button>
|
||||
<button
|
||||
class="tab"
|
||||
[class.active]="activeTab() === 'annotations'"
|
||||
(click)="setActiveTab('annotations')">
|
||||
<app-reader-icon name="edit" class="tab-icon"></app-reader-icon>
|
||||
<span>{{ t('annotationsTab') }}</span>
|
||||
@if (annotations().length > 0) {
|
||||
<span class="badge">{{ annotations().length }}</span>
|
||||
}
|
||||
</button>
|
||||
</nav>
|
||||
|
||||
<!-- Tab content -->
|
||||
<div class="content">
|
||||
@switch (activeTab()) {
|
||||
@case ('contents') {
|
||||
@if (outline().length > 0) {
|
||||
<ul class="chapter-list" role="tree">
|
||||
@for (item of outline(); track item.title) {
|
||||
<ng-container *ngTemplateOutlet="outlineItem; context: { $implicit: item, depth: 0 }"/>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<ng-template #outlineItem let-item let-depth="depth">
|
||||
<li role="treeitem" [attr.aria-selected]="false">
|
||||
<button
|
||||
class="chapter-row"
|
||||
[style.--depth]="depth"
|
||||
(click)="onOutlineClick(item)">
|
||||
<span class="chapter-label">{{ item.title }}</span>
|
||||
<span class="chapter-page">{{ t('page') }} {{ item.pageIndex + 1 }}</span>
|
||||
</button>
|
||||
@if (item.children?.length) {
|
||||
<ul class="subchapter-list" role="group">
|
||||
@for (child of item.children; track child.title) {
|
||||
<ng-container *ngTemplateOutlet="outlineItem; context: { $implicit: child, depth: depth + 1 }"/>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
</li>
|
||||
</ng-template>
|
||||
} @else {
|
||||
<div class="empty-state">
|
||||
<app-reader-icon name="book" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||
<p>{{ t('noContents') }}</p>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@case ('bookmarks') {
|
||||
@if (bookmarks().length > 0) {
|
||||
<ul class="item-list">
|
||||
@for (bookmark of bookmarks(); track bookmark.id) {
|
||||
<li class="list-item" role="button" tabindex="0" (click)="onBookmarkClick(bookmark)" (keydown.enter)="onBookmarkClick(bookmark)">
|
||||
<div class="item-content">
|
||||
<span class="item-title">{{ bookmark.title }}</span>
|
||||
<span class="item-meta">{{ t('page') }} {{ bookmark.pageNumber }}</span>
|
||||
</div>
|
||||
<button class="delete-btn" (click)="onDeleteBookmark($event, bookmark.id)" [attr.aria-label]="t('deleteBookmark')">
|
||||
<app-reader-icon name="trash" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
} @else {
|
||||
<div class="empty-state">
|
||||
<app-reader-icon name="bookmark" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||
<p>{{ t('noBookmarks') }}</p>
|
||||
<span class="empty-hint">{{ t('bookmarkHint') }}</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
@case ('annotations') {
|
||||
@if (annotations().length > 0) {
|
||||
<ul class="item-list">
|
||||
@for (annotation of annotations(); track annotation.id) {
|
||||
<li class="list-item highlight-item" role="button" tabindex="0" (click)="onAnnotationClick(annotation)" (keydown.enter)="onAnnotationClick(annotation)">
|
||||
@if (annotation.color) {
|
||||
<div class="highlight-bar" [style.background-color]="annotation.color"></div>
|
||||
}
|
||||
<div class="item-content">
|
||||
<div class="item-header">
|
||||
<span class="item-meta">{{ t('page') }} {{ annotation.pageIndex + 1 }} · {{ annotation.type }}</span>
|
||||
</div>
|
||||
@if (annotation.text) {
|
||||
<p class="highlight-text">"{{ annotation.text }}"</p>
|
||||
}
|
||||
</div>
|
||||
<button class="delete-btn" (click)="onDeleteAnnotation($event, annotation.id)" [attr.aria-label]="t('deleteAnnotation')">
|
||||
<app-reader-icon name="trash" [size]="14"></app-reader-icon>
|
||||
</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
} @else {
|
||||
<div class="empty-state">
|
||||
<app-reader-icon name="edit" class="empty-icon" [size]="48" [strokeWidth]="1.5"></app-reader-icon>
|
||||
<p>{{ t('noAnnotations') }}</p>
|
||||
<span class="empty-hint">{{ t('annotationHint') }}</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
}
|
||||
</ng-container>
|
||||
@@ -0,0 +1,478 @@
|
||||
$sidebar-width: 320px;
|
||||
$sidebar-bg: #141414;
|
||||
$sidebar-bg-light: #fff;
|
||||
$text-primary: #fff;
|
||||
$text-primary-light: #1a1a1a;
|
||||
$text-secondary: rgb(255 255 255 / 70%);
|
||||
$text-secondary-light: rgb(0 0 0 / 60%);
|
||||
$text-muted: rgb(255 255 255 / 45%);
|
||||
$text-muted-light: rgb(0 0 0 / 40%);
|
||||
$border-color: rgb(255 255 255 / 10%);
|
||||
$border-color-light: rgb(0 0 0 / 8%);
|
||||
$hover-bg: rgb(255 255 255 / 6%);
|
||||
$hover-bg-light: rgb(0 0 0 / 4%);
|
||||
$active-bg: #3b82f6;
|
||||
$active-color: #3b82f6;
|
||||
$transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
|
||||
$transition-fast: 150ms ease;
|
||||
|
||||
:host {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.sidebar-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgb(0 0 0 / 60%);
|
||||
z-index: 12000;
|
||||
animation: fade-in 300ms ease;
|
||||
|
||||
&.closing {
|
||||
animation: fade-out 300ms ease forwards;
|
||||
}
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: $sidebar-width;
|
||||
background: $sidebar-bg;
|
||||
color: $text-primary;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 12px 0 32px rgb(0 0 0 / 40%);
|
||||
animation: slide-in $transition-base;
|
||||
overflow: hidden;
|
||||
border-right: 1px solid $border-color;
|
||||
|
||||
&.closing {
|
||||
animation: slide-out $transition-base forwards;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 20px 24px;
|
||||
background: rgb(255 255 255 / 2%);
|
||||
border-bottom: 1px solid $border-color;
|
||||
flex-shrink: 0;
|
||||
|
||||
.sidebar-title {
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: $text-muted;
|
||||
margin: 0;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.12em;
|
||||
}
|
||||
|
||||
.sidebar-close-btn {
|
||||
background: none;
|
||||
border: none;
|
||||
color: $text-muted;
|
||||
cursor: pointer;
|
||||
padding: 6px;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all $transition-fast;
|
||||
|
||||
&:hover {
|
||||
color: $text-primary;
|
||||
background: $hover-bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
padding: 0 12px;
|
||||
background: rgb(255 255 255 / 1%);
|
||||
border-bottom: 1px solid $border-color;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tab {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 4px;
|
||||
padding: 14px 2px;
|
||||
background: none;
|
||||
border: none;
|
||||
position: relative;
|
||||
color: $text-secondary;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all $transition-fast;
|
||||
min-width: 0;
|
||||
|
||||
span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 12px;
|
||||
right: 12px;
|
||||
height: 3px;
|
||||
background: transparent;
|
||||
border-radius: 3px 3px 0 0;
|
||||
transition: all $transition-fast;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: $text-primary;
|
||||
background: rgb(255 255 255 / 3%);
|
||||
}
|
||||
|
||||
&.active {
|
||||
color: $active-color;
|
||||
|
||||
&::after {
|
||||
background: $active-color;
|
||||
box-shadow: 0 -4px 10px rgb(59 130 246 / 40%);
|
||||
}
|
||||
}
|
||||
|
||||
.tab-icon {
|
||||
font-size: 14px;
|
||||
opacity: 0.8;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.badge {
|
||||
background: rgb(59 130 246 / 15%);
|
||||
color: $active-color;
|
||||
font-size: 9px;
|
||||
font-weight: 700;
|
||||
padding: 1px 6px;
|
||||
border-radius: 20px;
|
||||
margin-left: 2px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 12px 0;
|
||||
overscroll-behavior: contain;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgb(255 255 255 / 15%);
|
||||
border-radius: 10px;
|
||||
|
||||
&:hover {
|
||||
background: rgb(255 255 255 / 25%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Outline / Chapter list ---
|
||||
|
||||
.chapter-list,
|
||||
.subchapter-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.chapter-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
padding: 12px 24px 12px calc(24px + var(--depth, 0) * 20px);
|
||||
background: none;
|
||||
border: none;
|
||||
color: $text-secondary;
|
||||
font-size: 13.5px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all $transition-fast;
|
||||
text-align: left;
|
||||
line-height: 1.4;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg;
|
||||
color: $text-primary;
|
||||
}
|
||||
|
||||
.chapter-label {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.chapter-page {
|
||||
flex-shrink: 0;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: $text-muted;
|
||||
margin-left: 12px;
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Item lists (bookmarks, annotations) ---
|
||||
|
||||
.item-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.list-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border-radius: 12px;
|
||||
cursor: pointer;
|
||||
background: rgb(255 255 255 / 1%);
|
||||
border: 1px solid transparent;
|
||||
transition: all $transition-fast;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg;
|
||||
border-color: $border-color;
|
||||
transform: translateY(-1px);
|
||||
|
||||
.delete-btn {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
}
|
||||
|
||||
&.highlight-item {
|
||||
padding-left: 0;
|
||||
overflow: hidden;
|
||||
|
||||
.highlight-bar {
|
||||
width: 4px;
|
||||
margin-right: 12px;
|
||||
flex-shrink: 0;
|
||||
align-self: stretch;
|
||||
}
|
||||
|
||||
.item-content {
|
||||
padding: 2px 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.item-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: $text-primary;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.item-meta {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: $text-muted;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.highlight-text {
|
||||
font-size: 13px;
|
||||
line-height: 1.5;
|
||||
color: $text-secondary;
|
||||
font-style: italic;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
background: rgb(239 68 68 / 10%);
|
||||
border: none;
|
||||
color: #ef4444;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
transform: translateX(8px);
|
||||
transition: all $transition-fast;
|
||||
flex-shrink: 0;
|
||||
|
||||
&:hover {
|
||||
background: #ef4444;
|
||||
color: white;
|
||||
box-shadow: 0 4px 12px rgb(239 68 68 / 30%);
|
||||
}
|
||||
}
|
||||
|
||||
// --- Empty state ---
|
||||
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 64px 32px;
|
||||
text-align: center;
|
||||
|
||||
.empty-icon {
|
||||
color: $text-muted;
|
||||
margin-bottom: 20px;
|
||||
opacity: 0.3;
|
||||
filter: drop-shadow(0 8px 16px rgb(0 0 0 / 20%));
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
color: $text-secondary;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.empty-hint {
|
||||
font-size: 13px;
|
||||
color: $text-muted;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Animations ---
|
||||
|
||||
@keyframes fade-in {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
}
|
||||
|
||||
@keyframes fade-out {
|
||||
from { opacity: 1; }
|
||||
to { opacity: 0; }
|
||||
}
|
||||
|
||||
@keyframes slide-in {
|
||||
from { transform: translateX(-100%); }
|
||||
to { transform: translateX(0); }
|
||||
}
|
||||
|
||||
@keyframes slide-out {
|
||||
from { transform: translateX(0); }
|
||||
to { transform: translateX(-100%); }
|
||||
}
|
||||
|
||||
// --- Light Theme Support ---
|
||||
|
||||
:host-context([data-color-scheme="light"]) {
|
||||
.sidebar-overlay {
|
||||
background: rgb(0 0 0 / 20%);
|
||||
}
|
||||
|
||||
.sidebar {
|
||||
background: $sidebar-bg-light;
|
||||
color: $text-primary-light;
|
||||
border-right-color: $border-color-light;
|
||||
box-shadow: 12px 0 32px rgb(0 0 0 / 10%);
|
||||
|
||||
.sidebar-header {
|
||||
background: rgb(0 0 0 / 1%);
|
||||
border-bottom-color: $border-color-light;
|
||||
|
||||
.sidebar-title {
|
||||
color: $text-muted-light;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tabs {
|
||||
border-bottom-color: $border-color-light;
|
||||
}
|
||||
|
||||
.tab {
|
||||
color: $text-secondary-light;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg-light;
|
||||
color: $text-primary-light;
|
||||
}
|
||||
}
|
||||
|
||||
.tab-item:hover, .chapter-row:hover {
|
||||
background: $hover-bg-light;
|
||||
}
|
||||
|
||||
.chapter-row {
|
||||
color: $text-secondary-light;
|
||||
|
||||
&:hover {
|
||||
color: $text-primary-light;
|
||||
}
|
||||
|
||||
.chapter-page {
|
||||
color: $text-muted-light;
|
||||
}
|
||||
}
|
||||
|
||||
.list-item {
|
||||
background: rgb(0 0 0 / 2%);
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg-light;
|
||||
border-color: $border-color-light;
|
||||
}
|
||||
}
|
||||
|
||||
.item-title {
|
||||
color: $text-primary-light;
|
||||
}
|
||||
|
||||
.item-meta {
|
||||
color: $text-muted-light;
|
||||
}
|
||||
|
||||
.highlight-text {
|
||||
color: $text-secondary-light;
|
||||
}
|
||||
|
||||
.content::-webkit-scrollbar-thumb {
|
||||
background: rgb(0 0 0 / 10%);
|
||||
|
||||
&:hover {
|
||||
background: rgb(0 0 0 / 20%);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import {Component, DestroyRef, inject, input, output, signal, effect} from '@angular/core';
|
||||
import {NgTemplateOutlet} from '@angular/common';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {ReaderIconComponent} from '../../ebook-reader/shared/icon.component';
|
||||
import {BookMark} from '../../../../shared/service/book-mark.service';
|
||||
import {PdfOutlineItem} from '../services/embedpdf-book.service';
|
||||
|
||||
export type PdfSidebarTab = 'contents' | 'bookmarks' | 'annotations';
|
||||
|
||||
export interface PdfAnnotationListItem {
|
||||
id: string;
|
||||
pageIndex: number;
|
||||
type: string;
|
||||
color?: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-pdf-sidebar',
|
||||
standalone: true,
|
||||
imports: [TranslocoDirective, NgTemplateOutlet, ReaderIconComponent],
|
||||
templateUrl: './pdf-sidebar.component.html',
|
||||
styleUrl: './pdf-sidebar.component.scss',
|
||||
})
|
||||
export class PdfSidebarComponent {
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private closeAnimationTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
isOpen = input.required<boolean>();
|
||||
outline = input<PdfOutlineItem[]>([]);
|
||||
bookmarks = input<BookMark[]>([]);
|
||||
annotations = input<PdfAnnotationListItem[]>([]);
|
||||
|
||||
closed = output<void>();
|
||||
navigateToPage = output<number>();
|
||||
deleteBookmark = output<number>();
|
||||
deleteAnnotation = output<string>();
|
||||
|
||||
readonly activeTab = signal<PdfSidebarTab>('contents');
|
||||
readonly visible = signal(false);
|
||||
readonly closing = signal(false);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
if (this.isOpen()) {
|
||||
this.clearCloseAnimation();
|
||||
this.visible.set(true);
|
||||
this.closing.set(false);
|
||||
} else if (this.visible()) {
|
||||
this.closeWithAnimation();
|
||||
}
|
||||
});
|
||||
|
||||
this.destroyRef.onDestroy(() => this.clearCloseAnimation());
|
||||
}
|
||||
|
||||
private closeWithAnimation(): void {
|
||||
this.closing.set(true);
|
||||
this.closeAnimationTimeout = setTimeout(() => {
|
||||
this.visible.set(false);
|
||||
this.closing.set(false);
|
||||
this.closeAnimationTimeout = null;
|
||||
}, 250);
|
||||
}
|
||||
|
||||
private clearCloseAnimation(): void {
|
||||
if (this.closeAnimationTimeout) {
|
||||
clearTimeout(this.closeAnimationTimeout);
|
||||
this.closeAnimationTimeout = null;
|
||||
}
|
||||
}
|
||||
|
||||
onOverlayClick(): void {
|
||||
this.closed.emit();
|
||||
}
|
||||
|
||||
setActiveTab(tab: PdfSidebarTab): void {
|
||||
this.activeTab.set(tab);
|
||||
}
|
||||
|
||||
onOutlineClick(item: PdfOutlineItem): void {
|
||||
this.navigateToPage.emit(item.pageIndex + 1);
|
||||
}
|
||||
|
||||
onBookmarkClick(bookmark: BookMark): void {
|
||||
if (bookmark.pageNumber != null) {
|
||||
this.navigateToPage.emit(bookmark.pageNumber);
|
||||
}
|
||||
}
|
||||
|
||||
onDeleteBookmark(event: MouseEvent, bookmarkId: number): void {
|
||||
event.stopPropagation();
|
||||
this.deleteBookmark.emit(bookmarkId);
|
||||
}
|
||||
|
||||
onAnnotationClick(annotation: PdfAnnotationListItem): void {
|
||||
this.navigateToPage.emit(annotation.pageIndex + 1);
|
||||
}
|
||||
|
||||
onDeleteAnnotation(event: MouseEvent, annotationId: string): void {
|
||||
event.stopPropagation();
|
||||
this.deleteAnnotation.emit(annotationId);
|
||||
}
|
||||
}
|
||||
@@ -16,48 +16,162 @@
|
||||
}
|
||||
|
||||
@if (viewerMode === 'document') {
|
||||
<button class="embed-close-btn icon-btn close-btn" [title]="'readerPdf.toolbar.closePdfReader' | transloco"
|
||||
(click)="closeReader()">
|
||||
<app-reader-icon name="close" [size]="20" />
|
||||
</button>
|
||||
|
||||
@if (isDocViewerInfoVisible) {
|
||||
<div class="doc-viewer-info">
|
||||
<span>{{ 'readerPdf.docViewer.changesSavedInfo' | transloco }}</span>
|
||||
<button class="dismiss-btn" (click)="dismissDocViewerInfo()">
|
||||
<app-reader-icon name="close" [size]="14" />
|
||||
@if (docViewerReady) {
|
||||
<button class="embed-close-btn icon-btn" [title]="'readerPdf.toolbar.closePdfReader' | transloco"
|
||||
(click)="closeReader()">
|
||||
<app-reader-icon name="close" [size]="18" />
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (isDocViewerInfoVisible) {
|
||||
<div class="doc-viewer-info">
|
||||
<span>{{ 'readerPdf.docViewer.changesSavedInfo' | transloco }}</span>
|
||||
<button class="dismiss-btn" [attr.aria-label]="'readerPdf.docViewer.dismiss' | transloco" (click)="dismissDocViewerInfo()">
|
||||
<app-reader-icon name="close" [size]="14" />
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div id="embedpdf-viewer"></div>
|
||||
}
|
||||
|
||||
<div id="embedpdf-viewer"></div>
|
||||
}
|
||||
|
||||
<!-- Book PDF Viewer -->
|
||||
<!-- Book Viewer (direct EmbedPDF) -->
|
||||
@if (viewerMode === 'book') {
|
||||
<ngx-extended-pdf-viewer [src]="bookData" [authorization]="authorization" [textLayer]="true"
|
||||
[showHandToolButton]="true" [height]="'100%'" [theme]="isDarkTheme ? 'dark' : 'light'" [page]="page"
|
||||
[rotation]="rotation" [zoom]="zoom" [spread]="spread" [enablePrint]="canPrint" [customToolbar]="pdfToolbar"
|
||||
(pagesLoaded)="onPdfPagesLoaded($event)" (pageChange)="onPageChange($event)" (zoomChange)="onZoomChange($event)"
|
||||
(spreadChange)="onSpreadChange($event)" (annotationEditorEvent)="onAnnotationEditorEvent()">
|
||||
</ngx-extended-pdf-viewer>
|
||||
}
|
||||
|
||||
<!-- Book header toolbar -->
|
||||
<div class="pdf-header-toolbar" [class.chrome-hidden]="!headerVisible">
|
||||
<div class="header-left">
|
||||
<button class="icon-btn" [title]="'readerPdf.toolbar.sidebar' | transloco" (click)="toggleSidebar()">
|
||||
<!-- sidebar/menu icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<rect width="18" height="18" x="3" y="3" rx="2" /><path d="M9 3v18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<span class="book-title">{{ bookTitle }}</span>
|
||||
|
||||
<div class="header-right">
|
||||
<!-- Desktop toolbar actions (hidden on mobile) -->
|
||||
<div class="desktop-actions">
|
||||
<!-- Search -->
|
||||
<button class="icon-btn" [class.active]="isSearchOpen"
|
||||
[title]="'readerPdf.toolbar.search' | transloco" (click)="toggleSearch()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<ng-template #pdfToolbar>
|
||||
<div id="toolbarViewer" class="pdf-header-toolbar" [class.chrome-hidden]="!headerVisible">
|
||||
<div class="header-left">
|
||||
<pdf-toggle-sidebar></pdf-toggle-sidebar>
|
||||
<pdf-find-button></pdf-find-button>
|
||||
</div>
|
||||
<span class="book-title">{{ bookTitle }}</span>
|
||||
<div class="header-right">
|
||||
<pdf-highlight-editor></pdf-highlight-editor>
|
||||
<pdf-text-editor></pdf-text-editor>
|
||||
<pdf-draw-editor></pdf-draw-editor>
|
||||
<div class="separator"></div>
|
||||
<pdf-zoom-toolbar></pdf-zoom-toolbar>
|
||||
|
||||
<!-- Annotation tools -->
|
||||
<button class="icon-btn annotation-tool-btn" [class.active]="activeAnnotationTool === 'highlight'"
|
||||
[title]="'readerPdf.toolbar.highlight' | transloco" (click)="toggleAnnotationTool('highlight')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m9 11-6 6v3h9l3-3" /><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="icon-btn annotation-tool-btn" [class.active]="activeAnnotationTool === 'freeText'"
|
||||
[title]="'readerPdf.toolbar.freeText' | transloco" (click)="toggleAnnotationTool('freeText')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M17 6.1H3" /><path d="M21 12.1H3" /><path d="M15.1 18H3" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="icon-btn annotation-tool-btn" [class.active]="activeAnnotationTool === 'ink'"
|
||||
[title]="'readerPdf.toolbar.draw' | transloco" (click)="toggleAnnotationTool('ink')">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
|
||||
</svg>
|
||||
</button>
|
||||
<button class="icon-btn annotation-tool-btn" [class.active]="isPanActive"
|
||||
[title]="'readerPdf.toolbar.pan' | transloco" (click)="togglePanMode()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0" /><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v10" />
|
||||
<path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8" />
|
||||
<path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.8-6.6-3.3l-4.7-5.3a2 2 0 0 1 0-2.8l.3-.3a2 2 0 0 1 2.8 0L8 14" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<!-- Bookmark toggle -->
|
||||
<button class="icon-btn bookmark-btn" [class.bookmarked]="isCurrentPageBookmarked"
|
||||
[title]="isCurrentPageBookmarked ? ('readerPdf.toolbar.removeBookmark' | transloco) : ('readerPdf.toolbar.addBookmark' | transloco)"
|
||||
(click)="toggleBookmark()">
|
||||
@if (isCurrentPageBookmarked) {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
|
||||
</svg>
|
||||
} @else {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
|
||||
</svg>
|
||||
}
|
||||
</button>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<!-- Zoom controls -->
|
||||
<button class="icon-btn" [title]="'readerPdf.toolbar.zoomOut' | transloco" (click)="embedPdfBook.zoomOut()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /><path d="M8 11h6" />
|
||||
</svg>
|
||||
</button>
|
||||
<div class="zoom-menu-wrapper">
|
||||
<button class="icon-btn zoom-label-btn" (click)="toggleZoomMenu()">
|
||||
<span class="zoom-label">{{ zoom }}</span>
|
||||
</button>
|
||||
@if (isZoomMenuOpen) {
|
||||
<div class="zoom-dropdown">
|
||||
@for (preset of zoomPresets; track preset.value) {
|
||||
<button class="zoom-option" [class.active]="zoom === preset.value" (click)="setZoomPreset(preset.value)">
|
||||
{{ preset.label }}
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<button class="icon-btn" [title]="'readerPdf.toolbar.zoomIn' | transloco" (click)="embedPdfBook.zoomIn()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /><path d="M11 8v6" /><path d="M8 11h6" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<!-- Spread mode -->
|
||||
<button class="icon-btn" [title]="'readerPdf.toolbar.spreadMode' | transloco" (click)="cycleSpreadMode()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
@if (spreadMode === 'none') {
|
||||
<rect x="3" y="3" width="18" height="18" rx="2" />
|
||||
} @else {
|
||||
<rect x="2" y="3" width="9" height="18" rx="1" /><rect x="13" y="3" width="9" height="18" rx="1" />
|
||||
}
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Rotate -->
|
||||
<button class="icon-btn" [title]="'readerPdf.toolbar.rotatePage' | transloco" (click)="rotateClockwise()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8" /><path d="M21 3v5h-5" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<div class="separator"></div>
|
||||
|
||||
<!-- Theme toggle -->
|
||||
<button class="icon-btn"
|
||||
[title]="isDarkTheme ? ('readerPdf.toolbar.switchToLightMode' | transloco) : ('readerPdf.toolbar.switchToDarkMode' | transloco)"
|
||||
(click)="toggleDarkTheme()">
|
||||
@@ -65,14 +179,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2" />
|
||||
<path d="M12 20v2" />
|
||||
<path d="m4.93 4.93 1.41 1.41" />
|
||||
<path d="m17.66 17.66 1.41 1.41" />
|
||||
<path d="M2 12h2" />
|
||||
<path d="M20 12h2" />
|
||||
<path d="m6.34 17.66-1.41 1.41" />
|
||||
<path d="m19.07 4.93-1.41 1.41" />
|
||||
<path d="M12 2v2" /><path d="M12 20v2" />
|
||||
<path d="m4.93 4.93 1.41 1.41" /><path d="m17.66 17.66 1.41 1.41" />
|
||||
<path d="M2 12h2" /><path d="M20 12h2" />
|
||||
<path d="m6.34 17.66-1.41 1.41" /><path d="m19.07 4.93-1.41 1.41" />
|
||||
</svg>
|
||||
} @else {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
@@ -81,6 +191,8 @@
|
||||
</svg>
|
||||
}
|
||||
</button>
|
||||
|
||||
<!-- Fullscreen -->
|
||||
<button class="icon-btn" (click)="toggleFullscreen()"
|
||||
[title]="isFullscreen ? ('readerPdf.toolbar.exitFullscreen' | transloco) : ('readerPdf.toolbar.fullscreen' | transloco)">
|
||||
@if (isFullscreen) {
|
||||
@@ -89,15 +201,173 @@
|
||||
<app-reader-icon name="fullscreen" [size]="18" />
|
||||
}
|
||||
</button>
|
||||
|
||||
<div class="separator"></div>
|
||||
<pdf-toggle-secondary-toolbar></pdf-toggle-secondary-toolbar>
|
||||
<button class="icon-btn close-btn" [title]="'readerPdf.toolbar.closePdfReader' | transloco"
|
||||
(click)="closeReader()">
|
||||
<app-reader-icon name="close" [size]="20" />
|
||||
</div>
|
||||
|
||||
<!-- Mobile: bookmark + overflow menu (shown on mobile only) -->
|
||||
<div class="mobile-actions">
|
||||
<button class="icon-btn bookmark-btn" [class.bookmarked]="isCurrentPageBookmarked"
|
||||
[attr.aria-label]="isCurrentPageBookmarked ? ('readerPdf.toolbar.removeBookmark' | transloco) : ('readerPdf.toolbar.addBookmark' | transloco)"
|
||||
(click)="toggleBookmark()">
|
||||
@if (isCurrentPageBookmarked) {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"
|
||||
fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
|
||||
</svg>
|
||||
} @else {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"
|
||||
fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m19 21-7-4-7 4V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v16z" />
|
||||
</svg>
|
||||
}
|
||||
</button>
|
||||
|
||||
<button class="icon-btn overflow-btn" [attr.aria-label]="'readerPdf.toolbar.moreOptions' | transloco" (click)="toggleToolbarOverflow()">
|
||||
<!-- More/ellipsis icon -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="1" /><circle cx="19" cy="12" r="1" /><circle cx="5" cy="12" r="1" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Close button (always visible) -->
|
||||
<button class="icon-btn close-btn" [title]="'readerPdf.toolbar.closePdfReader' | transloco"
|
||||
(click)="closeReader()">
|
||||
<app-reader-icon name="close" [size]="20" />
|
||||
</button>
|
||||
</div>
|
||||
</ng-template>
|
||||
</div>
|
||||
|
||||
<!-- Mobile overflow menu -->
|
||||
@if (isToolbarOverflowOpen) {
|
||||
<div class="toolbar-overflow-backdrop" role="presentation" (click)="closeToolbarOverflow()"></div>
|
||||
<div class="toolbar-overflow-menu" tabindex="-1" (keydown.escape)="closeToolbarOverflow()" #overflowMenu>
|
||||
<button class="overflow-item" (click)="toggleSearch(); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.search' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="toggleAnnotationTool('highlight'); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="m9 11-6 6v3h9l3-3" /><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.highlight' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="toggleAnnotationTool('ink'); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.draw' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" [class.active]="isPanActive" (click)="togglePanMode(); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M18 11V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v0" /><path d="M14 10V4a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v10" />
|
||||
<path d="M10 10.5V6a2 2 0 0 0-2-2v0a2 2 0 0 0-2 2v8" />
|
||||
<path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.8-6.6-3.3l-4.7-5.3a2 2 0 0 1 0-2.8l.3-.3a2 2 0 0 1 2.8 0L8 14" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.pan' | transloco }}</span>
|
||||
</button>
|
||||
<div class="overflow-divider"></div>
|
||||
<button class="overflow-item" (click)="toggleDarkTheme(); closeToolbarOverflow()">
|
||||
@if (isDarkTheme) {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="12" cy="12" r="4" />
|
||||
<path d="M12 2v2" /><path d="M12 20v2" />
|
||||
<path d="m4.93 4.93 1.41 1.41" /><path d="m17.66 17.66 1.41 1.41" />
|
||||
<path d="M2 12h2" /><path d="M20 12h2" />
|
||||
<path d="m6.34 17.66-1.41 1.41" /><path d="m19.07 4.93-1.41 1.41" />
|
||||
</svg>
|
||||
} @else {
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" />
|
||||
</svg>
|
||||
}
|
||||
<span>{{ isDarkTheme ? ('readerPdf.toolbar.switchToLightMode' | transloco) : ('readerPdf.toolbar.switchToDarkMode' | transloco) }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="rotateClockwise(); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8" /><path d="M21 3v5h-5" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.rotatePage' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="embedPdfBook.zoomIn(); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /><path d="M11 8v6" /><path d="M8 11h6" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.zoomIn' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="embedPdfBook.zoomOut(); closeToolbarOverflow()">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /><path d="M8 11h6" />
|
||||
</svg>
|
||||
<span>{{ 'readerPdf.toolbar.zoomOut' | transloco }}</span>
|
||||
</button>
|
||||
<button class="overflow-item" (click)="toggleFullscreen(); closeToolbarOverflow()">
|
||||
@if (isFullscreen) {
|
||||
<app-reader-icon name="fullscreen-exit" [size]="18" />
|
||||
} @else {
|
||||
<app-reader-icon name="fullscreen" [size]="18" />
|
||||
}
|
||||
<span>{{ isFullscreen ? ('readerPdf.toolbar.exitFullscreen' | transloco) : ('readerPdf.toolbar.fullscreen' | transloco) }}</span>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Search bar (slides below header) -->
|
||||
@if (isSearchOpen) {
|
||||
<div class="search-bar" [class.chrome-hidden]="!headerVisible">
|
||||
<div class="search-input-wrapper">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 24 24" fill="none"
|
||||
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" />
|
||||
</svg>
|
||||
<input type="text" class="search-input" #searchInput [(ngModel)]="searchQuery"
|
||||
[attr.aria-label]="'readerPdf.toolbar.searchPlaceholder' | transloco"
|
||||
[placeholder]="'readerPdf.toolbar.searchPlaceholder' | transloco"
|
||||
(input)="onSearchInput()"
|
||||
(keyup.enter)="onSearchNext()"
|
||||
(keyup.escape)="closeSearch()" />
|
||||
</div>
|
||||
<button class="icon-btn search-nav-btn" [title]="'readerPdf.toolbar.searchPrevious' | transloco" (click)="onSearchPrevious()">
|
||||
<app-reader-icon name="chevron-left" [size]="14" />
|
||||
</button>
|
||||
<button class="icon-btn search-nav-btn" [title]="'readerPdf.toolbar.searchNext' | transloco" (click)="onSearchNext()">
|
||||
<app-reader-icon name="chevron-right" [size]="14" />
|
||||
</button>
|
||||
<button class="icon-btn search-close" [attr.aria-label]="'readerPdf.toolbar.closeSearch' | transloco" (click)="closeSearch()">
|
||||
<app-reader-icon name="close" [size]="14" />
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- Book viewer container -->
|
||||
<div id="book-viewer" class="book-viewer-container"></div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<app-pdf-sidebar
|
||||
[isOpen]="sidebarOpen"
|
||||
[outline]="outline"
|
||||
[bookmarks]="pdfBookmarks"
|
||||
[annotations]="annotationListItems"
|
||||
(closed)="onSidebarClosed()"
|
||||
(navigateToPage)="onSidebarNavigateToPage($event)"
|
||||
(deleteBookmark)="onDeleteBookmark($event)"
|
||||
(deleteAnnotation)="onDeleteAnnotation($event)"
|
||||
/>
|
||||
|
||||
}
|
||||
|
||||
<!-- Footer (shared across both viewer modes) -->
|
||||
<div class="pdf-footer" [class.visible]="footerVisible">
|
||||
@@ -150,10 +420,10 @@
|
||||
|
||||
<div class="viewer-mode-toggle">
|
||||
<button class="toggle-btn toggle-book" [class.active]="viewerMode === 'book'" (click)="setViewerMode('book')">
|
||||
<i class="pi pi-book"></i><span>Book Viewer</span>
|
||||
<i class="pi pi-book"></i><span>{{ 'readerPdf.footer.bookViewer' | transloco }}</span>
|
||||
</button>
|
||||
<button class="toggle-btn toggle-doc" [class.active]="viewerMode === 'document'" (click)="setViewerMode('document')">
|
||||
<i class="pi pi-file"></i><span>Doc Viewer</span>
|
||||
<i class="pi pi-file"></i><span>{{ 'readerPdf.footer.docViewer' | transloco }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@use 'sass:color';
|
||||
|
||||
/* stylelint-disable selector-id-pattern, selector-class-pattern -- targets ngx-extended-pdf-viewer / pdf.js internals */
|
||||
/* stylelint-disable selector-id-pattern, selector-class-pattern */
|
||||
|
||||
// Design tokens matching CBX/E-Book readers
|
||||
$header-height: 38px;
|
||||
@@ -28,10 +28,15 @@ $transition-fast: 150ms ease;
|
||||
.pdf-reader-container {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100dvh;
|
||||
background: #1a1a1a;
|
||||
z-index: 900;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Trigger zones ---
|
||||
@@ -62,10 +67,35 @@ $transition-fast: 150ms ease;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Header ---
|
||||
// Child element styles for .pdf-header-toolbar (positioning is in ::ng-deep #toolbarViewer)
|
||||
// --- Header toolbar ---
|
||||
|
||||
.pdf-header-toolbar {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: $header-height;
|
||||
box-sizing: border-box;
|
||||
padding: 0 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
z-index: 1002;
|
||||
background: $gradient-bg;
|
||||
border-bottom: 1px solid $border-color;
|
||||
box-shadow: 0 2px 8px rgb(0 0 0 / 30%);
|
||||
color: #fff;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
transform: translateY(0);
|
||||
transition: opacity 0.25s ease-out, transform 0.25s ease-out;
|
||||
|
||||
&.chrome-hidden {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
|
||||
.header-left,
|
||||
.header-right {
|
||||
display: flex;
|
||||
@@ -75,40 +105,6 @@ $transition-fast: 150ms ease;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
// Style zoom toolbar within header
|
||||
::ng-deep {
|
||||
pdf-zoom-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.zoom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
#scaleSelect {
|
||||
background: rgb(255 255 255 / 8%) !important;
|
||||
color: #fff !important;
|
||||
border: 1px solid rgb(255 255 255 / 15%) !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 2px 4px !important;
|
||||
font-size: 12px !important;
|
||||
cursor: pointer;
|
||||
height: 26px !important;
|
||||
max-width: 85px;
|
||||
appearance: none;
|
||||
|
||||
option {
|
||||
background: #2d2d2d;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-title {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
@@ -156,46 +152,140 @@ $transition-fast: 150ms ease;
|
||||
background: rgb(239 68 68 / 20%);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
&.annotation-tool-btn.active {
|
||||
color: $active-color;
|
||||
background: rgb(74 144 226 / 15%);
|
||||
}
|
||||
|
||||
&.bookmark-btn.bookmarked {
|
||||
color: #f59e0b;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Override pdf.js component button styles ---
|
||||
// --- Search bar ---
|
||||
|
||||
::ng-deep .pdf-btn-wrap {
|
||||
button {
|
||||
background: none !important;
|
||||
border: none !important;
|
||||
color: #fff !important;
|
||||
.search-bar {
|
||||
position: fixed;
|
||||
top: $header-height;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 36px;
|
||||
z-index: 1002;
|
||||
background: color.adjust(#2d2d2d, $lightness: -3%);
|
||||
border-bottom: 1px solid $border-color;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 16px;
|
||||
gap: 8px;
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
transition: opacity 0.25s ease-out, transform 0.25s ease-out;
|
||||
|
||||
&.chrome-hidden {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transform: translateY(-100%);
|
||||
}
|
||||
|
||||
.search-input-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex: 1;
|
||||
max-width: 360px;
|
||||
background: #404040;
|
||||
border-radius: 4px;
|
||||
padding: 0 8px;
|
||||
color: $text-secondary;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
flex: 1;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: $text-primary;
|
||||
font-size: 13px;
|
||||
padding: 5px 0;
|
||||
outline: none;
|
||||
|
||||
&::placeholder {
|
||||
color: rgb(255 255 255 / 30%);
|
||||
}
|
||||
}
|
||||
|
||||
.search-close {
|
||||
padding: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Zoom menu ---
|
||||
|
||||
.zoom-menu-wrapper {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.zoom-label-btn {
|
||||
padding: 4px 6px !important;
|
||||
|
||||
.zoom-label {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
min-width: 50px;
|
||||
text-align: center;
|
||||
}
|
||||
}
|
||||
|
||||
.zoom-dropdown {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
margin-top: 4px;
|
||||
background: #333;
|
||||
border: 1px solid $border-color;
|
||||
border-radius: 6px;
|
||||
padding: 4px 0;
|
||||
min-width: 120px;
|
||||
box-shadow: 0 4px 12px rgb(0 0 0 / 40%);
|
||||
z-index: 1010;
|
||||
|
||||
.zoom-option {
|
||||
display: block;
|
||||
width: 100%;
|
||||
padding: 6px 16px;
|
||||
border: none;
|
||||
background: none;
|
||||
color: $text-primary;
|
||||
font-size: 13px;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
width: 30px !important;
|
||||
height: 30px !important;
|
||||
padding: 0 !important;
|
||||
border-radius: 6px !important;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
transition: background $transition-fast !important;
|
||||
margin: 0 !important;
|
||||
box-shadow: none !important;
|
||||
opacity: 1 !important;
|
||||
transition: background $transition-fast;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg !important;
|
||||
background: $hover-bg;
|
||||
}
|
||||
|
||||
&.toggled,
|
||||
&[aria-pressed="true"] {
|
||||
color: $active-color !important;
|
||||
background: rgb(74 144 226 / 15%) !important;
|
||||
&.active {
|
||||
color: $active-color;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
span {
|
||||
display: none !important;
|
||||
}
|
||||
// --- Book viewer container ---
|
||||
|
||||
&::before {
|
||||
color: inherit !important;
|
||||
opacity: 1 !important;
|
||||
}
|
||||
.book-viewer-container {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
embedpdf-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,11 +538,29 @@ $transition-fast: 150ms ease;
|
||||
|
||||
.embed-close-btn {
|
||||
position: fixed;
|
||||
top: 4px;
|
||||
right: 12px;
|
||||
z-index: 1010;
|
||||
color: $text-primary;
|
||||
padding: 7px;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 11000;
|
||||
color: #fff;
|
||||
width: 44px;
|
||||
height: 38px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #2d2d2d;
|
||||
border: none;
|
||||
border-bottom: 1px solid #404040;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
transition: background $transition-fast;
|
||||
|
||||
&:hover {
|
||||
background: #3a3a3a;
|
||||
}
|
||||
|
||||
&:active {
|
||||
background: #444;
|
||||
}
|
||||
}
|
||||
|
||||
.doc-viewer-info {
|
||||
@@ -472,7 +580,7 @@ $transition-fast: 150ms ease;
|
||||
border: 1px solid $border-color;
|
||||
box-shadow: 0 2px 8px rgb(0 0 0 / 30%);
|
||||
backdrop-filter: blur(4px);
|
||||
animation: docViewerInfoFadeIn 0.3s ease-out;
|
||||
animation: doc-viewer-info-fade-in 0.3s ease-out;
|
||||
|
||||
.dismiss-btn {
|
||||
background: none;
|
||||
@@ -492,7 +600,7 @@ $transition-fast: 150ms ease;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes docViewerInfoFadeIn {
|
||||
@keyframes doc-viewer-info-fade-in {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
@@ -505,9 +613,10 @@ $transition-fast: 150ms ease;
|
||||
}
|
||||
|
||||
#embedpdf-viewer {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
|
||||
iframe {
|
||||
@@ -570,331 +679,90 @@ $transition-fast: 150ms ease;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Override pdf.js viewer inner styles ---
|
||||
// --- Mobile actions (hidden on desktop) ---
|
||||
|
||||
::ng-deep {
|
||||
// Make pdf viewer fill container
|
||||
ngx-extended-pdf-viewer {
|
||||
flex: 1;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
.mobile-actions {
|
||||
display: none;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
#mainContainer {
|
||||
background: #1a1a1a !important;
|
||||
// --- Desktop actions ---
|
||||
|
||||
.desktop-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
// --- Toolbar overflow menu (mobile) ---
|
||||
|
||||
.toolbar-overflow-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 1009;
|
||||
background: rgb(0 0 0 / 40%);
|
||||
}
|
||||
|
||||
.toolbar-overflow-menu {
|
||||
position: fixed;
|
||||
top: $header-height;
|
||||
right: 8px;
|
||||
z-index: 1010;
|
||||
background: #2d2d2d;
|
||||
border: 1px solid $border-color;
|
||||
border-radius: 8px;
|
||||
padding: 4px 0;
|
||||
min-width: 200px;
|
||||
box-shadow: 0 8px 24px rgb(0 0 0 / 50%);
|
||||
|
||||
.overflow-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
background: none;
|
||||
color: $text-primary;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: background $transition-fast;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg;
|
||||
}
|
||||
|
||||
// Override pdf.js defaults on #toolbarViewer - our custom fixed header
|
||||
#toolbarViewer {
|
||||
position: fixed !important;
|
||||
top: 0 !important;
|
||||
left: 0 !important;
|
||||
right: 0 !important;
|
||||
height: $header-height !important;
|
||||
min-height: 0 !important;
|
||||
box-sizing: border-box !important;
|
||||
padding: 0 16px !important;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: space-between !important;
|
||||
z-index: 1002 !important;
|
||||
background: $gradient-bg !important;
|
||||
border-bottom: 1px solid $border-color !important;
|
||||
box-shadow: 0 2px 8px rgb(0 0 0 / 30%) !important;
|
||||
color: #fff !important;
|
||||
opacity: 1 !important;
|
||||
pointer-events: auto !important;
|
||||
transform: translateY(0) !important;
|
||||
transition: opacity 0.25s ease-out, transform 0.25s ease-out !important;
|
||||
|
||||
&.chrome-hidden {
|
||||
opacity: 0 !important;
|
||||
pointer-events: none !important;
|
||||
transform: translateY(-100%) !important;
|
||||
}
|
||||
svg,
|
||||
app-reader-icon {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Style the annotation editor params toolbars (color picker, thickness, etc.)
|
||||
.editorParamsToolbar {
|
||||
position: fixed !important;
|
||||
top: $header-height !important;
|
||||
right: 8px !important;
|
||||
left: auto !important;
|
||||
z-index: 1003 !important;
|
||||
background: #2d2d2d !important;
|
||||
border: 1px solid $border-color !important;
|
||||
border-radius: 0 0 8px 8px !important;
|
||||
box-shadow: 0 4px 12px rgb(0 0 0 / 40%) !important;
|
||||
padding: 8px 12px !important;
|
||||
color: #fff !important;
|
||||
min-width: 180px !important;
|
||||
|
||||
.editorParamsToolbarContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.editorParamsLabel {
|
||||
color: $text-secondary !important;
|
||||
font-size: 12px !important;
|
||||
}
|
||||
|
||||
.editorParamsSetter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.editorParamsSlider {
|
||||
flex: 1;
|
||||
accent-color: $active-color;
|
||||
}
|
||||
|
||||
.editorParamsColor {
|
||||
border: 1px solid #555 !important;
|
||||
border-radius: 4px !important;
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
// Highlight color picker dots
|
||||
.colorPicker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
button {
|
||||
width: 24px !important;
|
||||
height: 24px !important;
|
||||
min-width: 24px !important;
|
||||
border-radius: 50% !important;
|
||||
border: 2px solid transparent !important;
|
||||
padding: 0 !important;
|
||||
cursor: pointer !important;
|
||||
|
||||
&[aria-selected="true"],
|
||||
&.selected {
|
||||
border-color: #fff !important;
|
||||
box-shadow: 0 0 4px rgb(255 255 255 / 40%) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Toggle button for "show all highlights"
|
||||
.toggle-button {
|
||||
background: #555 !important;
|
||||
border: none !important;
|
||||
border-radius: 12px !important;
|
||||
width: 36px !important;
|
||||
height: 20px !important;
|
||||
cursor: pointer !important;
|
||||
position: relative !important;
|
||||
|
||||
&[aria-pressed="true"] {
|
||||
background: $active-color !important;
|
||||
}
|
||||
}
|
||||
|
||||
.thicknessPicker {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.toggler {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
height: 1px;
|
||||
background: $border-color;
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
// Generic button styling inside params toolbars
|
||||
button.secondaryToolbarButton,
|
||||
button.toolbarButton {
|
||||
background: none !important;
|
||||
color: #fff !important;
|
||||
border: none !important;
|
||||
border-radius: 6px !important;
|
||||
padding: 6px 10px !important;
|
||||
cursor: pointer !important;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
gap: 6px !important;
|
||||
width: 100% !important;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg !important;
|
||||
}
|
||||
|
||||
span {
|
||||
display: inline !important;
|
||||
color: inherit !important;
|
||||
}
|
||||
}
|
||||
|
||||
// Injected close button wrapper
|
||||
.custom-close-btn-wrapper {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
margin-bottom: 6px;
|
||||
border-bottom: 1px solid rgb(255 255 255 / 10%);
|
||||
padding-bottom: 6px;
|
||||
}
|
||||
|
||||
// Injected close button
|
||||
.custom-close-btn {
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
justify-content: center !important;
|
||||
width: 34px !important;
|
||||
height: 34px !important;
|
||||
padding: 0 !important;
|
||||
background: transparent !important;
|
||||
border: none !important;
|
||||
border-radius: 4px !important;
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: rgb(239 68 68 / 20%) !important;
|
||||
color: #ef4444 !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Style the secondary toolbar dropdown
|
||||
#secondaryToolbar {
|
||||
top: $header-height !important;
|
||||
background: #2d2d2d !important;
|
||||
border: 1px solid $border-color !important;
|
||||
border-radius: 0 0 8px 8px !important;
|
||||
box-shadow: 0 4px 16px rgb(0 0 0 / 40%) !important;
|
||||
padding: 4px !important;
|
||||
|
||||
button {
|
||||
background: none !important;
|
||||
border: none !important;
|
||||
color: #fff !important;
|
||||
border-radius: 6px !important;
|
||||
padding: 8px 12px !important;
|
||||
font-size: 13px !important;
|
||||
width: 100% !important;
|
||||
text-align: left !important;
|
||||
display: flex !important;
|
||||
align-items: center !important;
|
||||
gap: 8px !important;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg !important;
|
||||
}
|
||||
|
||||
&[aria-pressed="true"],
|
||||
&.toggled {
|
||||
color: $active-color !important;
|
||||
background: rgb(74 144 226 / 15%) !important;
|
||||
}
|
||||
|
||||
span {
|
||||
display: inline !important;
|
||||
color: inherit !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Style the find bar
|
||||
#findbar {
|
||||
background: #2d2d2d !important;
|
||||
border: 1px solid $border-color !important;
|
||||
border-radius: 0 0 8px 8px !important;
|
||||
box-shadow: 0 4px 12px rgb(0 0 0 / 30%) !important;
|
||||
padding: 8px !important;
|
||||
top: 0 !important;
|
||||
|
||||
input {
|
||||
background: #404040 !important;
|
||||
color: #fff !important;
|
||||
border: 1px solid #555 !important;
|
||||
border-radius: 4px !important;
|
||||
padding: 4px 8px !important;
|
||||
}
|
||||
|
||||
button {
|
||||
background: none !important;
|
||||
color: #fff !important;
|
||||
border: none !important;
|
||||
border-radius: 4px !important;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg !important;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
color: $text-secondary !important;
|
||||
}
|
||||
}
|
||||
|
||||
// Style the sidebar
|
||||
#sidebarContainer {
|
||||
background: #1f1f1f !important;
|
||||
border-right: 1px solid $border-color !important;
|
||||
|
||||
#toolbarSidebar {
|
||||
background: #2d2d2d !important;
|
||||
border-bottom: 1px solid $border-color !important;
|
||||
|
||||
button {
|
||||
color: #fff !important;
|
||||
|
||||
&.toggled {
|
||||
color: $active-color !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#sidebarContent {
|
||||
background: #1f1f1f !important;
|
||||
}
|
||||
|
||||
.treeItem {
|
||||
color: #fff !important;
|
||||
|
||||
>a {
|
||||
color: #fff !important;
|
||||
|
||||
&:hover {
|
||||
background: $hover-bg !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Hide the default toolbar container chrome completely - our custom toolbar is positioned fixed
|
||||
#toolbarContainer {
|
||||
position: absolute !important;
|
||||
height: 0 !important;
|
||||
min-height: 0 !important;
|
||||
max-height: 0 !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
border: none !important;
|
||||
background: transparent !important;
|
||||
overflow: visible !important;
|
||||
}
|
||||
.overflow-divider {
|
||||
height: 1px;
|
||||
background: $border-color;
|
||||
margin: 4px 0;
|
||||
}
|
||||
}
|
||||
|
||||
// --- Responsive ---
|
||||
|
||||
@media (width <= 768px) {
|
||||
// Tablet (portrait) switches to mobile toolbar layout
|
||||
@media (width <= 1024px) {
|
||||
.pdf-header-toolbar {
|
||||
height: $header-height + 4px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
.desktop-actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mobile-actions {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.pdf-footer {
|
||||
height: auto;
|
||||
padding: 8px 12px;
|
||||
@@ -911,22 +779,25 @@ $transition-fast: 150ms ease;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.zoom-controls {
|
||||
.footer-spacer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.header-right {
|
||||
::ng-deep pdf-zoom-toolbar {
|
||||
display: none !important;
|
||||
.page-nav-left {
|
||||
flex: 1;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.viewer-mode-toggle {
|
||||
.toggle-btn span {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
pdf-highlight-editor,
|
||||
pdf-text-editor,
|
||||
pdf-draw-editor,
|
||||
pdf-find-button,
|
||||
.separator {
|
||||
display: none !important;
|
||||
.search-bar {
|
||||
.search-input-wrapper {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
.doc-viewer-info {
|
||||
@@ -939,4 +810,66 @@ $transition-fast: 150ms ease;
|
||||
.book-title {
|
||||
display: none;
|
||||
}
|
||||
|
||||
// Larger touch targets for trigger zones
|
||||
.header-trigger-zone {
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.footer-trigger-zone {
|
||||
height: 50px;
|
||||
}
|
||||
}
|
||||
|
||||
// Small phones
|
||||
@media (width <= 480px) {
|
||||
.pdf-header-toolbar {
|
||||
padding: 0 6px;
|
||||
}
|
||||
|
||||
.pdf-footer {
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.page-nav-left {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.nav-btn {
|
||||
padding: 8px;
|
||||
min-width: 36px;
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
.page-info {
|
||||
min-width: 70px;
|
||||
font-size: 12px;
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
.slider-wrapper {
|
||||
.page-slider {
|
||||
&::-webkit-slider-thumb {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
margin-top: calc((6px - 22px) / 2);
|
||||
}
|
||||
|
||||
&::-moz-range-thumb {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.viewer-mode-toggle .toggle-btn {
|
||||
padding: 0 8px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.icon-btn {
|
||||
padding: 8px;
|
||||
min-width: 36px;
|
||||
min-height: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,669 @@
|
||||
import {Injectable, NgZone, inject} from '@angular/core';
|
||||
import {ReplaySubject, Subject} from 'rxjs';
|
||||
import type {
|
||||
EmbedPdfContainer,
|
||||
PluginRegistry,
|
||||
ScrollCapability,
|
||||
ZoomCapability,
|
||||
ZoomMode,
|
||||
AnnotationCapability,
|
||||
AnnotationTransferItem,
|
||||
BookmarkCapability,
|
||||
PageChangeEvent,
|
||||
AnnotationEvent,
|
||||
SearchCapability,
|
||||
SpreadCapability,
|
||||
SpreadMode,
|
||||
RotateCapability,
|
||||
PanCapability,
|
||||
} from '@embedpdf/snippet';
|
||||
|
||||
export interface PdfOutlineItem {
|
||||
title: string;
|
||||
pageIndex: number;
|
||||
children: PdfOutlineItem[];
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class EmbedPdfBookService {
|
||||
private zone = inject(NgZone);
|
||||
|
||||
private container: EmbedPdfContainer | null = null;
|
||||
private registry: PluginRegistry | null = null;
|
||||
private scroll: ScrollCapability | null = null;
|
||||
private zoom: ZoomCapability | null = null;
|
||||
private annotation: AnnotationCapability | null = null;
|
||||
private bookmark: BookmarkCapability | null = null;
|
||||
private search: SearchCapability | null = null;
|
||||
private spread: SpreadCapability | null = null;
|
||||
private rotate: RotateCapability | null = null;
|
||||
private pan: PanCapability | null = null;
|
||||
|
||||
private currentDocumentId: string | null = null;
|
||||
|
||||
private pageChangeUnsub?: () => void;
|
||||
|
||||
private annotationEventUnsub?: () => void;
|
||||
private layoutReadyUnsub?: () => void;
|
||||
private documentOpenedUnsub?: () => void;
|
||||
private resizeObserver?: ResizeObserver;
|
||||
|
||||
pageChange$ = new Subject<PageChangeEvent>();
|
||||
annotationEvent$ = new Subject<AnnotationEvent>();
|
||||
documentOpened$ = new ReplaySubject<{pageCount: number}>(1);
|
||||
layoutReady$ = new ReplaySubject<void>(1);
|
||||
|
||||
get currentPage(): number {
|
||||
return this.scroll?.getCurrentPage() ?? 1;
|
||||
}
|
||||
|
||||
get totalPages(): number {
|
||||
return this.scroll?.getTotalPages() ?? 0;
|
||||
}
|
||||
|
||||
async init(target: HTMLElement, pdfUrl: string, theme: 'dark' | 'light'): Promise<void> {
|
||||
// Recreate event streams so the service is reusable after destroy()
|
||||
this.pageChange$ = new Subject<PageChangeEvent>();
|
||||
this.annotationEvent$ = new Subject<AnnotationEvent>();
|
||||
this.documentOpened$ = new ReplaySubject<{pageCount: number}>(1);
|
||||
this.layoutReady$ = new ReplaySubject<void>(1);
|
||||
|
||||
this.applyWorkerShims();
|
||||
this.ensureHighDpiRendering();
|
||||
this.patchReleasePointerCapture();
|
||||
|
||||
const EmbedPDF = (await import('@embedpdf/snippet')).default;
|
||||
|
||||
const wasmUrl = new URL('/assets/pdfium/pdfium.wasm', location.origin).href;
|
||||
|
||||
this.container = EmbedPDF.init({
|
||||
type: 'container',
|
||||
target,
|
||||
src: pdfUrl,
|
||||
wasmUrl,
|
||||
worker: true,
|
||||
log: false,
|
||||
theme: {preference: theme},
|
||||
disabledCategories: [
|
||||
'redaction',
|
||||
'stamp',
|
||||
'document-print',
|
||||
'document-export',
|
||||
'document-open',
|
||||
'document-close',
|
||||
],
|
||||
annotations: {
|
||||
autoCommit: true,
|
||||
autoOpenLinks: false,
|
||||
},
|
||||
zoom: {
|
||||
defaultZoomLevel: 'fit-page' as ZoomMode,
|
||||
},
|
||||
render: {
|
||||
defaultImageQuality: 2,
|
||||
},
|
||||
tiling: {
|
||||
tileSize: 1024,
|
||||
overlapPx: 2,
|
||||
extraRings: 1,
|
||||
},
|
||||
}) ?? null;
|
||||
|
||||
if (!this.container) {
|
||||
throw new Error('EmbedPDF.init() returned undefined');
|
||||
}
|
||||
|
||||
this.zone.runOutsideAngular(() => {
|
||||
this.injectBookModeStyles(target);
|
||||
this.setupResizeObserver(target);
|
||||
});
|
||||
|
||||
this.registry = await this.container.registry;
|
||||
|
||||
const scrollPlugin = this.registry.getPlugin('scroll');
|
||||
this.scroll = scrollPlugin?.provides?.() as ScrollCapability ?? null;
|
||||
|
||||
const zoomPlugin = this.registry.getPlugin('zoom');
|
||||
this.zoom = zoomPlugin?.provides?.() as ZoomCapability ?? null;
|
||||
|
||||
const annotationPlugin = this.registry.getPlugin('annotation');
|
||||
this.annotation = annotationPlugin?.provides?.() as AnnotationCapability ?? null;
|
||||
|
||||
const bookmarkPlugin = this.registry.getPlugin('bookmark');
|
||||
this.bookmark = bookmarkPlugin?.provides?.() as BookmarkCapability ?? null;
|
||||
|
||||
const searchPlugin = this.registry.getPlugin('search');
|
||||
this.search = searchPlugin?.provides?.() as SearchCapability ?? null;
|
||||
|
||||
const spreadPlugin = this.registry.getPlugin('spread');
|
||||
this.spread = spreadPlugin?.provides?.() as SpreadCapability ?? null;
|
||||
|
||||
const rotatePlugin = this.registry.getPlugin('rotate');
|
||||
this.rotate = rotatePlugin?.provides?.() as RotateCapability ?? null;
|
||||
|
||||
const panPlugin = this.registry.getPlugin('pan');
|
||||
this.pan = panPlugin?.provides?.() as PanCapability ?? null;
|
||||
|
||||
// wire events
|
||||
if (this.scroll) {
|
||||
this.pageChangeUnsub = this.scroll.onPageChange((ev: PageChangeEvent) => {
|
||||
this.pageChange$.next(ev);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
if (typeof (this.scroll as any).onLayoutReady === 'function') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.layoutReadyUnsub = (this.scroll as any).onLayoutReady(() => {
|
||||
this.zone.run(() => this.layoutReady$.next());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for document opened via document-manager plugin
|
||||
const dmPlugin = this.registry.getPlugin('document-manager');
|
||||
const dm = dmPlugin?.provides?.() as Record<string, unknown> | null;
|
||||
if (dm && typeof dm['onDocumentOpened'] === 'function') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.documentOpenedUnsub = (dm['onDocumentOpened'] as (cb: (ev: any) => void) => () => void)((ev: {id: string, pageCount?: number}) => {
|
||||
this.zone.run(() => {
|
||||
this.currentDocumentId = ev.id;
|
||||
this.documentOpened$.next({pageCount: ev?.pageCount ?? this.scroll?.getTotalPages() ?? 0});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Fallback: emit after a delay once scroll is ready
|
||||
this.zone.runOutsideAngular(() => {
|
||||
setTimeout(() => {
|
||||
this.zone.run(() => {
|
||||
this.documentOpened$.next({pageCount: this.scroll?.getTotalPages() ?? 0});
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
}
|
||||
|
||||
if (this.annotation) {
|
||||
console.info('[EmbedPDF] Annotation plugin found, hooking events');
|
||||
this.annotationEventUnsub = this.annotation.onAnnotationEvent((ev: AnnotationEvent) => {
|
||||
console.info('[EmbedPDF] Annotation event:', ev.type);
|
||||
this.annotationEvent$.next(ev);
|
||||
});
|
||||
} else {
|
||||
console.warn('[EmbedPDF] Annotation plugin NOT found — events will not fire');
|
||||
}
|
||||
}
|
||||
|
||||
setTheme(theme: 'dark' | 'light'): void {
|
||||
this.container?.setTheme(theme);
|
||||
}
|
||||
|
||||
scrollToPage(pageNumber: number, behavior: 'instant' | 'smooth' = 'smooth'): void {
|
||||
this.scroll?.scrollToPage({pageNumber, behavior});
|
||||
}
|
||||
|
||||
scrollToNextPage(): void {
|
||||
this.scroll?.scrollToNextPage('smooth');
|
||||
}
|
||||
|
||||
scrollToPreviousPage(): void {
|
||||
this.scroll?.scrollToPreviousPage('smooth');
|
||||
}
|
||||
|
||||
zoomIn(): void {
|
||||
this.zoom?.zoomIn();
|
||||
}
|
||||
|
||||
zoomOut(): void {
|
||||
this.zoom?.zoomOut();
|
||||
}
|
||||
|
||||
setZoomLevel(level: string): void {
|
||||
this.zoom?.requestZoom(level as ZoomMode);
|
||||
}
|
||||
|
||||
// --- Search ---
|
||||
|
||||
startSearch(): void {
|
||||
this.search?.startSearch();
|
||||
}
|
||||
|
||||
stopSearch(): void {
|
||||
this.search?.stopSearch();
|
||||
}
|
||||
|
||||
searchAllPages(keyword: string): void {
|
||||
if (!this.search) return;
|
||||
const docId = this.currentDocumentId || undefined;
|
||||
const task = this.search.searchAllPages(keyword, docId);
|
||||
// After search completes, scroll to the first result
|
||||
task.wait(() => {
|
||||
this.scrollToActiveSearchResult();
|
||||
}, () => { /* search failed or cancelled */ });
|
||||
}
|
||||
|
||||
nextSearchResult(): void {
|
||||
if (!this.search) return;
|
||||
const docId = this.currentDocumentId || undefined;
|
||||
this.search.nextResult(docId);
|
||||
this.scrollToActiveSearchResult();
|
||||
}
|
||||
|
||||
previousSearchResult(): void {
|
||||
if (!this.search) return;
|
||||
const docId = this.currentDocumentId || undefined;
|
||||
this.search.previousResult(docId);
|
||||
this.scrollToActiveSearchResult();
|
||||
}
|
||||
|
||||
private scrollToActiveSearchResult(): void {
|
||||
if (!this.search) return;
|
||||
const docId = this.currentDocumentId || undefined;
|
||||
const state = this.search.getState(docId);
|
||||
if (!state || state.results.length === 0 || state.activeResultIndex < 0) return;
|
||||
const result = state.results[state.activeResultIndex];
|
||||
if (result) {
|
||||
this.scrollToPage(result.pageIndex + 1, 'smooth');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Spread/Layout ---
|
||||
|
||||
getSpreadMode(): string {
|
||||
return this.spread?.getSpreadMode?.() ?? 'none';
|
||||
}
|
||||
|
||||
setSpreadMode(mode: string): void {
|
||||
this.spread?.setSpreadMode?.(mode as SpreadMode);
|
||||
}
|
||||
|
||||
// --- Rotation ---
|
||||
|
||||
rotateClockwise(): void {
|
||||
this.rotate?.rotateForward?.();
|
||||
}
|
||||
|
||||
rotateCounterClockwise(): void {
|
||||
this.rotate?.rotateBackward?.();
|
||||
}
|
||||
|
||||
// --- Pan ---
|
||||
|
||||
isPanMode(): boolean {
|
||||
return this.pan?.isPanMode() ?? false;
|
||||
}
|
||||
|
||||
setPanMode(enabled: boolean): void {
|
||||
if (enabled) {
|
||||
this.pan?.enablePan();
|
||||
} else {
|
||||
this.pan?.disablePan();
|
||||
}
|
||||
}
|
||||
|
||||
setActiveTool(toolId: string | null): void {
|
||||
this.annotation?.setActiveTool(toolId);
|
||||
}
|
||||
|
||||
getActiveTool(): string | null {
|
||||
const tool = this.annotation?.getActiveTool();
|
||||
return tool?.id ?? null;
|
||||
}
|
||||
|
||||
async importAnnotations(items: AnnotationTransferItem[]): Promise<void> {
|
||||
if (!this.annotation || items.length === 0) return;
|
||||
const result = this.annotation.importAnnotations(items) as unknown;
|
||||
interface EpdfTask { wait: (res: (v?: unknown) => void, rej: (e?: unknown) => void) => void; }
|
||||
|
||||
if (result && typeof result === 'object' && 'wait' in result) {
|
||||
const task = result as EpdfTask;
|
||||
if (typeof task.wait === 'function') {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
task.wait(() => resolve(), (err) => reject(err));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deleteAnnotation(pageIndex: number, annotationId: string): void {
|
||||
this.annotation?.deleteAnnotation(pageIndex, annotationId);
|
||||
}
|
||||
|
||||
async exportAnnotations(): Promise<AnnotationTransferItem[]> {
|
||||
if (!this.annotation) return [];
|
||||
return this.annotation.exportAnnotations().toPromise();
|
||||
}
|
||||
|
||||
async getOutline(): Promise<PdfOutlineItem[]> {
|
||||
if (!this.bookmark) return [];
|
||||
try {
|
||||
const result = await new Promise<{bookmarks: unknown[]}>((resolve, reject) => {
|
||||
this.bookmark!.getBookmarks().wait(resolve, reject);
|
||||
});
|
||||
return this.convertBookmarks(result.bookmarks);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
this.pageChangeUnsub?.();
|
||||
this.annotationEventUnsub?.();
|
||||
this.layoutReadyUnsub?.();
|
||||
this.documentOpenedUnsub?.();
|
||||
this.resizeObserver?.disconnect();
|
||||
this.resizeObserver = undefined;
|
||||
|
||||
this.pageChange$.complete();
|
||||
this.annotationEvent$.complete();
|
||||
this.documentOpened$.complete();
|
||||
this.layoutReady$.complete();
|
||||
|
||||
if (this.container) {
|
||||
this.container.remove();
|
||||
this.container = null;
|
||||
}
|
||||
|
||||
this.registry = null;
|
||||
this.scroll = null;
|
||||
this.zoom = null;
|
||||
this.annotation = null;
|
||||
this.bookmark = null;
|
||||
this.search = null;
|
||||
this.spread = null;
|
||||
this.rotate = null;
|
||||
this.pan = null;
|
||||
this.currentDocumentId = null;
|
||||
|
||||
this.restoreWorkerShims();
|
||||
this.restoreReleasePointerCapture();
|
||||
this.restoreDevicePixelRatio();
|
||||
}
|
||||
|
||||
private convertBookmarks(items: unknown[]): PdfOutlineItem[] {
|
||||
if (!Array.isArray(items)) return [];
|
||||
|
||||
interface EpdfBookmark {
|
||||
title?: string;
|
||||
target?: {
|
||||
type?: 'destination' | 'action' | string;
|
||||
destination?: {pageIndex?: number};
|
||||
action?: {
|
||||
type?: number;
|
||||
destination?: {pageIndex?: number};
|
||||
};
|
||||
};
|
||||
children?: unknown[];
|
||||
}
|
||||
|
||||
return items.map((item: unknown) => {
|
||||
const entry = item as EpdfBookmark;
|
||||
let pageIndex = 0;
|
||||
|
||||
const target = entry.target;
|
||||
if (target) {
|
||||
if (target.type === 'destination') {
|
||||
pageIndex = target.destination?.pageIndex ?? 0;
|
||||
} else if (target.type === 'action' && target.action?.type === 1) {
|
||||
// Type 1 is PdfActionType.Goto (internal to PDF viewer)
|
||||
pageIndex = target.action.destination?.pageIndex ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: String(entry.title || ''),
|
||||
pageIndex: pageIndex,
|
||||
children: this.convertBookmarks(entry.children || []),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure devicePixelRatio reports at least 2 so that the EmbedPDF tiling
|
||||
* and render layers always produce high-resolution bitmaps.
|
||||
* The library reads window.devicePixelRatio at tile-render time; if the
|
||||
* browser reports 1 (e.g. some WebViews or forced-desktop viewports),
|
||||
* PDF pages appear noticeably pixelated.
|
||||
*/
|
||||
private ensureHighDpiRendering(): void {
|
||||
const MIN_DPR = 2;
|
||||
if (window.devicePixelRatio < MIN_DPR) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
w.__grimmoryOrigDprDescriptor = Object.getOwnPropertyDescriptor(window, 'devicePixelRatio');
|
||||
Object.defineProperty(window, 'devicePixelRatio', {
|
||||
get: () => MIN_DPR,
|
||||
configurable: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the same Worker/Blob shims that embedpdf-frame.html uses.
|
||||
* EmbedPDF creates a blob-URL module Worker for PDFium WASM. Some browsers
|
||||
* (or bundler setups) swallow the "ready" postMessage from the worker.
|
||||
* These shims:
|
||||
* 1) Patch Blob to inject `self.postMessage({type:"ready"})` after `runner.prepare()`.
|
||||
* 2) Patch Worker to inject a fallback synthetic "ready" if the real one never arrives.
|
||||
* Idempotent — safe to call multiple times.
|
||||
*/
|
||||
private applyWorkerShims(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
if (w.__grimmoryShimsApplied) return;
|
||||
w.__grimmoryShimsApplied = true;
|
||||
|
||||
// --- Blob shim ---
|
||||
const OrigBlob = window.Blob;
|
||||
w.__grimmoryOrigBlob = OrigBlob;
|
||||
w.Blob = function PatchedBlob(parts: BlobPart[], opts?: BlobPropertyBag) {
|
||||
if (parts?.length >= 1 && typeof parts[0] === 'string') {
|
||||
const src = parts[0] as string;
|
||||
if (src.includes('wasmInit') && src.includes('runner.prepare()')) {
|
||||
let patched = src;
|
||||
patched = patched.replace(
|
||||
'self.postMessage({ type: "wasmError", error: message });',
|
||||
'console.error("[Worker] WASM init FAILED:", message);\n' +
|
||||
' self.postMessage({ type: "wasmError", error: message });'
|
||||
);
|
||||
patched = patched.replace(
|
||||
'await runner.prepare();',
|
||||
'await runner.prepare();\n' +
|
||||
' console.log("[Worker] prepare() OK, posting ready");\n' +
|
||||
' self.postMessage({ type: "ready" });'
|
||||
);
|
||||
parts = [patched];
|
||||
}
|
||||
}
|
||||
return new OrigBlob(parts, opts);
|
||||
};
|
||||
w.Blob.prototype = OrigBlob.prototype;
|
||||
Object.setPrototypeOf(w.Blob, OrigBlob);
|
||||
|
||||
// --- Worker shim ---
|
||||
const OrigWorker = window.Worker;
|
||||
w.__grimmoryOrigWorker = OrigWorker;
|
||||
w.Worker = function PatchedWorker(url: string | URL, opts?: WorkerOptions) {
|
||||
const worker = new OrigWorker(url, opts);
|
||||
const urlStr = typeof url === 'string' ? url : url.toString();
|
||||
if (urlStr.startsWith('blob:') && opts?.type === 'module') {
|
||||
let readySent = false;
|
||||
let wasmError = false;
|
||||
setTimeout(() => {
|
||||
if (!readySent && !wasmError) {
|
||||
readySent = true;
|
||||
worker.dispatchEvent(new MessageEvent('message', {
|
||||
data: {type: 'ready'}
|
||||
}));
|
||||
}
|
||||
}, 5000);
|
||||
worker.addEventListener('message', (evt: MessageEvent) => {
|
||||
if (evt.data?.type === 'ready') readySent = true;
|
||||
if (evt.data?.type === 'wasmError') wasmError = true;
|
||||
});
|
||||
}
|
||||
return worker;
|
||||
};
|
||||
w.Worker.prototype = OrigWorker.prototype;
|
||||
Object.setPrototypeOf(w.Worker, OrigWorker);
|
||||
}
|
||||
|
||||
private restoreWorkerShims(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
if (!w.__grimmoryShimsApplied) return;
|
||||
if (w.__grimmoryOrigBlob) {
|
||||
window.Blob = w.__grimmoryOrigBlob;
|
||||
delete w.__grimmoryOrigBlob;
|
||||
}
|
||||
if (w.__grimmoryOrigWorker) {
|
||||
window.Worker = w.__grimmoryOrigWorker;
|
||||
delete w.__grimmoryOrigWorker;
|
||||
}
|
||||
delete w.__grimmoryShimsApplied;
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch Element.prototype.releasePointerCapture to swallow "Invalid pointer id"
|
||||
* DOMExceptions thrown by EmbedPDF's internal Svelte rendering during
|
||||
* annotation drag/resize interactions. The error is benign—the pointer has
|
||||
* already been released by the time the cleanup call fires.
|
||||
*/
|
||||
private patchReleasePointerCapture(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
if (w.__grimmoryOrigRelease) return;
|
||||
const orig = Element.prototype.releasePointerCapture;
|
||||
w.__grimmoryOrigRelease = orig;
|
||||
Element.prototype.releasePointerCapture = function (pointerId: number) {
|
||||
try {
|
||||
orig.call(this, pointerId);
|
||||
} catch (e) {
|
||||
if (!(e instanceof DOMException && e.message.includes('pointer'))) throw e;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private restoreReleasePointerCapture(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
if (w.__grimmoryOrigRelease) {
|
||||
Element.prototype.releasePointerCapture = w.__grimmoryOrigRelease;
|
||||
delete w.__grimmoryOrigRelease;
|
||||
}
|
||||
}
|
||||
|
||||
private restoreDevicePixelRatio(): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const w = window as any;
|
||||
if (w.__grimmoryOrigDprDescriptor) {
|
||||
Object.defineProperty(window, 'devicePixelRatio', w.__grimmoryOrigDprDescriptor);
|
||||
delete w.__grimmoryOrigDprDescriptor;
|
||||
} else if (Object.getOwnPropertyDescriptor(window, 'devicePixelRatio')?.configurable) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (window as any)['devicePixelRatio'];
|
||||
}
|
||||
}
|
||||
|
||||
private injectBookModeStyles(target: HTMLElement): void {
|
||||
const waitForShadow = (attempt = 0): void => {
|
||||
const epContainer = target.querySelector('embedpdf-container');
|
||||
const shadow = epContainer?.shadowRoot;
|
||||
if (!shadow) {
|
||||
if (attempt < 25) setTimeout(() => waitForShadow(attempt + 1), 200);
|
||||
return;
|
||||
}
|
||||
if (shadow.querySelector('style[data-grimmory-book]')) return;
|
||||
|
||||
const style = document.createElement('style');
|
||||
style.setAttribute('data-grimmory-book', '');
|
||||
style.textContent = `
|
||||
/* ── Grimmory book-mode overrides ── */
|
||||
|
||||
/* Force high-quality image rendering for PDF tiles */
|
||||
img {
|
||||
image-rendering: high-quality;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
:host {
|
||||
--ep-background-app: #1a1a1a;
|
||||
--ep-background-surface: #2d2d2d;
|
||||
--ep-border-default: #404040;
|
||||
--ep-border-subtle: #333333;
|
||||
--ep-foreground-primary: rgba(255,255,255,0.95);
|
||||
--ep-foreground-secondary: rgba(255,255,255,0.60);
|
||||
--ep-accent-primary: #4a90e2;
|
||||
}
|
||||
|
||||
:host([data-color-scheme="light"]) {
|
||||
--ep-background-app: #f5f5f5;
|
||||
--ep-background-surface: #ffffff;
|
||||
--ep-border-default: #d0d0d0;
|
||||
--ep-border-subtle: #e0e0e0;
|
||||
--ep-foreground-primary: rgba(0,0,0,0.87);
|
||||
--ep-foreground-secondary: rgba(0,0,0,0.54);
|
||||
}
|
||||
|
||||
/* Hide the built-in header toolbar */
|
||||
[class*="border-b"][class*="bg-bg-surface"][class*="px-4"][class*="py-2"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide the built-in footer/status bar */
|
||||
[class*="border-t"][class*="bg-bg-surface"][class*="px-4"][class*="py-1"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide bottom notification / popup bar */
|
||||
[class*="fixed"][class*="bottom-"],
|
||||
[class*="absolute"][class*="bottom-"],
|
||||
[class*="snackbar"],
|
||||
[class*="toast"],
|
||||
[class*="notification"],
|
||||
[class*="bottom-bar"],
|
||||
[class*="status-bar"],
|
||||
[class*="statusbar"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Hide open/close document buttons */
|
||||
[data-epdf-i="open-document"],
|
||||
[data-epdf-i="close-document"],
|
||||
button[title="Open Document"],
|
||||
button[title="Close Document"] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
|
||||
/* Improve annotation layer rendering on touch devices.
|
||||
|
||||
/* Improve annotation layer rendering on touch devices.
|
||||
FreeText annotation overlays can bleed through when the
|
||||
appearance-stream image has not finished loading. Prevent the
|
||||
interactive text span from blocking the rendered image. */
|
||||
[role="textbox"][contenteditable="false"] {
|
||||
pointer-events: none;
|
||||
}
|
||||
`;
|
||||
shadow.appendChild(style);
|
||||
};
|
||||
waitForShadow();
|
||||
}
|
||||
|
||||
private setupResizeObserver(target: HTMLElement): void {
|
||||
if (typeof ResizeObserver === 'undefined') return;
|
||||
|
||||
this.resizeObserver = new ResizeObserver(() => {
|
||||
// When the target container resizes (e.g. mobile chrome change),
|
||||
// some engines might need a nudge to recalculate "fit-page" zoom correctly.
|
||||
if (this.zoom && this.getSpreadMode() === 'none') {
|
||||
const state = this.zoom.getState();
|
||||
if (state.zoomLevel === 'fit-page') {
|
||||
// Re-request same zoom mode to trigger recalculation
|
||||
this.zoom.requestZoom('fit-page' as ZoomMode);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.resizeObserver.observe(target);
|
||||
this.layoutReady$.subscribe(() => this.resizeObserver?.disconnect());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
import {Injectable, inject} from '@angular/core';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {catchError, map, tap} from 'rxjs/operators';
|
||||
import {BookMark, BookMarkService, CreateBookMarkRequest} from '../../../../shared/service/book-mark.service';
|
||||
import {MessageService} from 'primeng/api';
|
||||
import {TranslocoService} from '@jsverse/transloco';
|
||||
|
||||
@Injectable()
|
||||
export class PdfBookmarkService {
|
||||
private bookMarkService = inject(BookMarkService);
|
||||
private messageService = inject(MessageService);
|
||||
private readonly t = inject(TranslocoService);
|
||||
|
||||
private bookmarks = new Map<number, BookMark>();
|
||||
private bookId!: number;
|
||||
|
||||
initialize(bookId: number): void {
|
||||
this.bookId = bookId;
|
||||
this.bookmarks.clear();
|
||||
}
|
||||
|
||||
loadBookmarks(): Observable<BookMark[]> {
|
||||
return this.bookMarkService.getBookmarksForBook(this.bookId).pipe(
|
||||
tap(bookmarks => {
|
||||
this.bookmarks.clear();
|
||||
for (const bm of bookmarks) {
|
||||
if (bm.pageNumber != null) {
|
||||
this.bookmarks.set(bm.pageNumber, bm);
|
||||
}
|
||||
}
|
||||
}),
|
||||
map(bookmarks => bookmarks.filter(bm => bm.pageNumber != null)),
|
||||
catchError(() => {
|
||||
this.bookmarks.clear();
|
||||
return of([]);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
isPageBookmarked(pageNumber: number): boolean {
|
||||
return this.bookmarks.has(pageNumber);
|
||||
}
|
||||
|
||||
getBookmarkForPage(pageNumber: number): BookMark | undefined {
|
||||
return this.bookmarks.get(pageNumber);
|
||||
}
|
||||
|
||||
getAllBookmarks(): BookMark[] {
|
||||
return Array.from(this.bookmarks.values()).sort((a, b) => (a.pageNumber ?? 0) - (b.pageNumber ?? 0));
|
||||
}
|
||||
|
||||
toggleBookmark(pageNumber: number, title?: string): Observable<boolean> {
|
||||
const existing = this.bookmarks.get(pageNumber);
|
||||
if (existing) {
|
||||
return this.deleteBookmark(existing.id);
|
||||
}
|
||||
return this.createBookmark(pageNumber, title);
|
||||
}
|
||||
|
||||
createBookmark(pageNumber: number, title?: string): Observable<boolean> {
|
||||
const request: CreateBookMarkRequest = {
|
||||
bookId: this.bookId,
|
||||
pageNumber,
|
||||
title: title || `Page ${pageNumber}`,
|
||||
};
|
||||
|
||||
return this.bookMarkService.createBookmark(request).pipe(
|
||||
map(bookmark => {
|
||||
this.bookmarks.set(pageNumber, bookmark);
|
||||
this.messageService.add({
|
||||
severity: 'success',
|
||||
summary: this.t.translate('readerPdf.toast.bookmarkAdded'),
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
catchError(error => {
|
||||
const isDuplicate = error?.status === 409;
|
||||
if (isDuplicate) {
|
||||
// Hydrate cache: server already has this bookmark
|
||||
this.loadBookmarks().subscribe();
|
||||
}
|
||||
this.messageService.add(
|
||||
isDuplicate
|
||||
? {severity: 'warn', summary: this.t.translate('readerPdf.toast.bookmarkExists')}
|
||||
: {severity: 'error', summary: this.t.translate('common.error')}
|
||||
);
|
||||
return of(false);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
deleteBookmark(bookmarkId: number): Observable<boolean> {
|
||||
return this.bookMarkService.deleteBookmark(bookmarkId).pipe(
|
||||
map(() => {
|
||||
for (const [page, bm] of this.bookmarks) {
|
||||
if (bm.id === bookmarkId) {
|
||||
this.bookmarks.delete(page);
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.messageService.add({
|
||||
severity: 'info',
|
||||
summary: this.t.translate('readerPdf.toast.bookmarkRemoved'),
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
catchError(() => {
|
||||
this.messageService.add({severity: 'error', summary: this.t.translate('common.error')});
|
||||
return of(false);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this.bookmarks.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
import type {AnnotationTransferItem} from '@embedpdf/snippet';
|
||||
|
||||
/**
|
||||
* Stored annotation wrapper format.
|
||||
* Legacy pdf.js annotations are raw arrays with `annotationType` keys.
|
||||
* New format wraps EmbedPDF AnnotationTransferItem[] in a versioned envelope.
|
||||
*/
|
||||
export interface StoredAnnotations {
|
||||
format: 'embedpdf';
|
||||
version: 1;
|
||||
annotations: AnnotationTransferItem[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect and parse stored annotation data.
|
||||
* Returns EmbedPDF AnnotationTransferItems ready for import, or empty array.
|
||||
*/
|
||||
export function parseStoredAnnotations(jsonString: string | null | undefined): AnnotationTransferItem[] {
|
||||
if (!jsonString) return [];
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(jsonString);
|
||||
|
||||
// New format: { format: 'embedpdf', version: 1, annotations: [...] }
|
||||
if (parsed && parsed.format === 'embedpdf' && Array.isArray(parsed.annotations)) {
|
||||
return parsed.annotations.map(restoreArrayBuffers);
|
||||
}
|
||||
|
||||
// Legacy pdf.js format: raw array of editor annotations
|
||||
if (Array.isArray(parsed)) {
|
||||
return convertLegacyAnnotations(parsed);
|
||||
}
|
||||
|
||||
return [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap EmbedPDF annotations in the versioned envelope for storage.
|
||||
* Handles ArrayBuffer fields (e.g. stamp ctx.data) by encoding to base64.
|
||||
*/
|
||||
export function serializeAnnotations(items: AnnotationTransferItem[]): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const serializable = items.map((item: any) => {
|
||||
if (item.ctx?.data instanceof ArrayBuffer) {
|
||||
return {
|
||||
...item,
|
||||
ctx: {
|
||||
...item.ctx,
|
||||
data: arrayBufferToBase64(item.ctx.data),
|
||||
_dataEncoding: 'base64',
|
||||
},
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
const wrapped = {
|
||||
format: 'embedpdf' as const,
|
||||
version: 1 as const,
|
||||
annotations: serializable as AnnotationTransferItem[],
|
||||
};
|
||||
return JSON.stringify(wrapped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Best-effort conversion of legacy pdf.js editor annotations.
|
||||
* These are the serialized annotations from ngx-extended-pdf-viewer's
|
||||
* getSerializedAnnotations() which outputs pdf.js editor format.
|
||||
*
|
||||
* This is a lossy conversion not all annotation types or properties
|
||||
* can be fully mapped. After the first save in the new format,
|
||||
* legacy data is overwritten.
|
||||
*/
|
||||
function convertLegacyAnnotations(legacyAnnotations: Record<string, unknown>[]): AnnotationTransferItem[] {
|
||||
const items: AnnotationTransferItem[] = [];
|
||||
|
||||
for (const legacy of legacyAnnotations) {
|
||||
try {
|
||||
const item = convertSingleAnnotation(legacy);
|
||||
if (item) {
|
||||
items.push(item);
|
||||
}
|
||||
} catch {
|
||||
// Skip annotations that can't be converted
|
||||
}
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
function convertSingleAnnotation(legacy: Record<string, unknown>): AnnotationTransferItem | null {
|
||||
const annotationType = legacy['annotationType'] as number | undefined;
|
||||
|
||||
// pdf.js annotation editor types:
|
||||
// 3 = freetext, 9 = highlight, 15 = ink
|
||||
switch (annotationType) {
|
||||
case 9: // highlight
|
||||
return convertHighlight(legacy);
|
||||
case 15: // ink
|
||||
return convertInk(legacy);
|
||||
case 3: // freetext
|
||||
return convertFreeText(legacy);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function convertHighlight(legacy: Record<string, unknown>): AnnotationTransferItem | null {
|
||||
const color = legacy['color'] as number[] | undefined;
|
||||
const pageIndex = (legacy['pageIndex'] as number) ?? 0;
|
||||
const rect = legacy['rect'] as number[] | undefined;
|
||||
|
||||
if (!rect || rect.length < 4) return null;
|
||||
|
||||
const hexColor = color ? rgbArrayToHex(color) : '#FFFF00';
|
||||
const x = rect[0];
|
||||
const y = rect[1];
|
||||
const w = rect[2] - rect[0];
|
||||
const h = rect[3] - rect[1];
|
||||
|
||||
return {
|
||||
annotation: {
|
||||
type: 9, // PdfAnnotationSubtype.HIGHLIGHT
|
||||
pageIndex,
|
||||
rect: {origin: {x, y}, size: {width: w, height: h}},
|
||||
segmentRects: [{origin: {x, y}, size: {width: w, height: h}}],
|
||||
color: hexColor,
|
||||
opacity: (legacy['opacity'] as number) ?? 1,
|
||||
id: crypto.randomUUID(),
|
||||
} as never,
|
||||
};
|
||||
}
|
||||
|
||||
function convertInk(legacy: Record<string, unknown>): AnnotationTransferItem | null {
|
||||
const color = legacy['color'] as number[] | undefined;
|
||||
const pageIndex = (legacy['pageIndex'] as number) ?? 0;
|
||||
const paths = legacy['paths'] as {bezier: number[]}[] | number[][][] | undefined;
|
||||
const thickness = (legacy['thickness'] as number) ?? 1;
|
||||
|
||||
if (!paths) return null;
|
||||
|
||||
const hexColor = color ? rgbArrayToHex(color) : '#000000';
|
||||
|
||||
// pdf.js ink paths can be bezier arrays or point arrays
|
||||
const inkList: {points: {x: number; y: number}[]}[] = [];
|
||||
for (const path of paths) {
|
||||
if (Array.isArray(path) && Array.isArray(path[0])) {
|
||||
// Array of point pairs
|
||||
const points = (path as number[][]).map(p => ({x: p[0], y: p[1]}));
|
||||
inkList.push({points});
|
||||
} else if (typeof path === 'object' && 'bezier' in (path as Record<string, unknown>)) {
|
||||
// Bezier curve data - extract control points
|
||||
const bezier = (path as {bezier: number[]}).bezier;
|
||||
const points: {x: number; y: number}[] = [];
|
||||
for (let i = 0; i < bezier.length; i += 2) {
|
||||
points.push({x: bezier[i], y: bezier[i + 1]});
|
||||
}
|
||||
inkList.push({points});
|
||||
}
|
||||
}
|
||||
|
||||
if (inkList.length === 0) return null;
|
||||
|
||||
return {
|
||||
annotation: {
|
||||
type: 15, // PdfAnnotationSubtype.INK
|
||||
pageIndex,
|
||||
rect: {origin: {x: 0, y: 0}, size: {width: 0, height: 0}},
|
||||
color: hexColor,
|
||||
strokeWidth: thickness,
|
||||
opacity: 1,
|
||||
inkList,
|
||||
id: crypto.randomUUID(),
|
||||
} as never,
|
||||
};
|
||||
}
|
||||
|
||||
function convertFreeText(legacy: Record<string, unknown>): AnnotationTransferItem | null {
|
||||
const pageIndex = (legacy['pageIndex'] as number) ?? 0;
|
||||
const rect = legacy['rect'] as number[] | undefined;
|
||||
const value = (legacy['value'] as string) ?? '';
|
||||
const fontSize = (legacy['fontSize'] as number) ?? 12;
|
||||
const color = legacy['color'] as number[] | undefined;
|
||||
|
||||
if (!rect || rect.length < 4) return null;
|
||||
|
||||
const x = rect[0];
|
||||
const y = rect[1];
|
||||
const w = rect[2] - rect[0];
|
||||
const h = rect[3] - rect[1];
|
||||
|
||||
return {
|
||||
annotation: {
|
||||
type: 3, // PdfAnnotationSubtype.FREETEXT
|
||||
pageIndex,
|
||||
rect: {origin: {x, y}, size: {width: w, height: h}},
|
||||
contents: value,
|
||||
fontSize,
|
||||
fontColor: color ? rgbArrayToHex(color) : '#000000',
|
||||
id: crypto.randomUUID(),
|
||||
} as never,
|
||||
};
|
||||
}
|
||||
|
||||
function rgbArrayToHex(rgb: number[]): string {
|
||||
const r = Math.round(Math.min(255, Math.max(0, rgb[0] * 255)));
|
||||
const g = Math.round(Math.min(255, Math.max(0, rgb[1] * 255)));
|
||||
const b = Math.round(Math.min(255, Math.max(0, rgb[2] * 255)));
|
||||
return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}`.toUpperCase();
|
||||
}
|
||||
|
||||
// --- ArrayBuffer <-> base64 helpers ---
|
||||
|
||||
function arrayBufferToBase64(buffer: ArrayBuffer): string {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
let binary = '';
|
||||
for (const byte of bytes) {
|
||||
binary += String.fromCharCode(byte);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
|
||||
function base64ToArrayBuffer(base64: string): ArrayBuffer {
|
||||
const binary = atob(base64);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let i = 0; i < binary.length; i++) {
|
||||
bytes[i] = binary.charCodeAt(i);
|
||||
}
|
||||
return bytes.buffer;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
function restoreArrayBuffers(item: any): AnnotationTransferItem {
|
||||
if (item.ctx?._dataEncoding === 'base64' && typeof item.ctx.data === 'string') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const {_dataEncoding: _, ...rest} = item.ctx;
|
||||
return {
|
||||
...item,
|
||||
ctx: {
|
||||
...rest,
|
||||
data: base64ToArrayBuffer(item.ctx.data),
|
||||
},
|
||||
};
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ export interface BookMark {
|
||||
cfi?: string; // For EPUB bookmarks
|
||||
positionMs?: number; // For audiobook bookmarks
|
||||
trackIndex?: number; // For folder-based audiobooks
|
||||
pageNumber?: number; // For PDF bookmarks
|
||||
title: string;
|
||||
color?: string;
|
||||
notes?: string;
|
||||
@@ -23,12 +24,14 @@ export interface CreateBookMarkRequest {
|
||||
cfi?: string; // For EPUB bookmarks
|
||||
positionMs?: number; // For audiobook bookmarks
|
||||
trackIndex?: number; // For folder-based audiobooks
|
||||
pageNumber?: number; // For PDF bookmarks
|
||||
title?: string;
|
||||
}
|
||||
|
||||
export interface UpdateBookMarkRequest {
|
||||
title?: string;
|
||||
cfi?: string;
|
||||
pageNumber?: number;
|
||||
color?: string;
|
||||
notes?: string;
|
||||
priority?: number;
|
||||
|
||||
Reference in New Issue
Block a user