refactor(frontend): rename booklore-ui to frontend
- Frontend path: - rename the tracked Angular app tree from `booklore-ui/` to `frontend/` - preserve file contents during the move so this commit stays focused on the path change itself - Frontend docs: - update the moved frontend README and contribution guide where they refer to the renamed folder - keep those edits limited to path references introduced by the directory rename
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
export interface PageInfo {
|
||||
percentCompleted: number;
|
||||
sectionTimeText: string;
|
||||
}
|
||||
|
||||
export interface ThemeInfo {
|
||||
fg: string;
|
||||
bg: string;
|
||||
}
|
||||
|
||||
export class PageDecorator {
|
||||
private static readonly DEFAULT_FONT_SIZE = '0.875rem';
|
||||
|
||||
static updateHeadersAndFooters(renderer: any, chapterName: string, pageInfo?: PageInfo, theme?: ThemeInfo, timeRemainingLabel?: string): void {
|
||||
|
||||
if (!renderer) {
|
||||
return;
|
||||
}
|
||||
|
||||
const columnCount = renderer.heads?.length || 0;
|
||||
const isSingleColumn = columnCount === 1;
|
||||
|
||||
this.updateHeaders(renderer, chapterName, isSingleColumn, theme);
|
||||
this.updateFooters(renderer, pageInfo, isSingleColumn, theme, timeRemainingLabel);
|
||||
}
|
||||
|
||||
private static updateHeaders(renderer: any, chapterName: string, isSingleColumn: boolean, theme?: ThemeInfo): void {
|
||||
if (!renderer.heads || !Array.isArray(renderer.heads) || renderer.heads.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const headerStyle = this.buildStyle(theme);
|
||||
|
||||
renderer.heads.forEach((headElement: HTMLElement, index: number) => {
|
||||
if (headElement) {
|
||||
headElement.style.visibility = 'visible';
|
||||
const headerContent = this.createHeaderContent(chapterName, isSingleColumn, index, headerStyle);
|
||||
headElement.replaceChildren(headerContent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static updateFooters(renderer: any, pageInfo: PageInfo | undefined, isSingleColumn: boolean, theme?: ThemeInfo, timeRemainingLabel?: string): void {
|
||||
if (!renderer.feet || !Array.isArray(renderer.feet) || renderer.feet.length === 0 || !pageInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
const footerStyle = this.buildStyle(theme);
|
||||
|
||||
renderer.feet.forEach((footElement: HTMLElement, index: number) => {
|
||||
if (footElement) {
|
||||
const footerContent = this.createFooterContent(pageInfo, isSingleColumn, index, renderer.feet.length, footerStyle, timeRemainingLabel);
|
||||
footElement.replaceChildren(footerContent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static buildStyle(theme?: ThemeInfo): string {
|
||||
const baseStyle = `width: 100%; display: flex; justify-content: space-between; align-items: center; font-size: ${this.DEFAULT_FONT_SIZE}; font-family: inherit;`;
|
||||
if (theme) {
|
||||
return `${baseStyle} color: ${theme.fg};`;
|
||||
}
|
||||
return baseStyle;
|
||||
}
|
||||
|
||||
private static createHeaderContent(chapterName: string, isSingleColumn: boolean, index: number, style: string): HTMLElement {
|
||||
const headerContent = document.createElement('div');
|
||||
headerContent.style.cssText = style;
|
||||
|
||||
if (isSingleColumn) {
|
||||
const spacer = document.createElement('span');
|
||||
const chapterSpan = document.createElement('span');
|
||||
chapterSpan.textContent = chapterName || '';
|
||||
chapterSpan.style.textAlign = 'right';
|
||||
headerContent.style.justifyContent = 'left';
|
||||
|
||||
headerContent.appendChild(spacer);
|
||||
headerContent.appendChild(chapterSpan);
|
||||
} else {
|
||||
if (index === 0) {
|
||||
const chapterSpan = document.createElement('span');
|
||||
chapterSpan.textContent = chapterName || '';
|
||||
chapterSpan.style.textAlign = 'left';
|
||||
headerContent.appendChild(chapterSpan);
|
||||
}
|
||||
}
|
||||
|
||||
return headerContent;
|
||||
}
|
||||
|
||||
private static createFooterContent(pageInfo: PageInfo, isSingleColumn: boolean, index: number, totalColumns: number, style: string, timeRemainingLabel?: string): HTMLElement {
|
||||
const footerContent = document.createElement('div');
|
||||
footerContent.style.cssText = style;
|
||||
|
||||
const text = timeRemainingLabel ?? ('Time remaining in section: ' + (pageInfo.sectionTimeText ?? '0s'));
|
||||
|
||||
if (isSingleColumn) {
|
||||
const timeSpan = document.createElement('span');
|
||||
timeSpan.textContent = text;
|
||||
timeSpan.style.textAlign = 'left';
|
||||
|
||||
const progressSpan = document.createElement('span');
|
||||
progressSpan.textContent = `${pageInfo.percentCompleted}%`;
|
||||
progressSpan.style.textAlign = 'right';
|
||||
|
||||
footerContent.appendChild(timeSpan);
|
||||
footerContent.appendChild(progressSpan);
|
||||
} else {
|
||||
if (index === 0) {
|
||||
const timeSpan = document.createElement('span');
|
||||
timeSpan.textContent = text;
|
||||
timeSpan.style.textAlign = 'left';
|
||||
footerContent.appendChild(timeSpan);
|
||||
|
||||
const spacer = document.createElement('span');
|
||||
footerContent.appendChild(spacer);
|
||||
} else if (index === totalColumns - 1) {
|
||||
const spacer = document.createElement('span');
|
||||
footerContent.appendChild(spacer);
|
||||
|
||||
const progressSpan = document.createElement('span');
|
||||
progressSpan.textContent = `${pageInfo.percentCompleted}%`;
|
||||
progressSpan.style.textAlign = 'right';
|
||||
footerContent.appendChild(progressSpan);
|
||||
}
|
||||
}
|
||||
|
||||
return footerContent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
import {ChangeDetectionStrategy, Component, Input} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
export type ReaderIconName =
|
||||
| 'menu'
|
||||
| 'close'
|
||||
| 'chevron-left'
|
||||
| 'chevron-right'
|
||||
| 'chevron-down'
|
||||
| 'chevron-first'
|
||||
| 'chevron-last'
|
||||
| 'chevron-double-left'
|
||||
| 'chevron-double-right'
|
||||
| 'dots-vertical'
|
||||
| 'bookmark'
|
||||
| 'settings'
|
||||
| 'book'
|
||||
| 'edit'
|
||||
| 'copy'
|
||||
| 'trash'
|
||||
| 'search'
|
||||
| 'note'
|
||||
| 'plus'
|
||||
| 'minus'
|
||||
| 'fit-page'
|
||||
| 'fit-width'
|
||||
| 'fit-height'
|
||||
| 'actual-size'
|
||||
| 'auto-fit'
|
||||
| 'fullscreen'
|
||||
| 'fullscreen-exit'
|
||||
| 'play'
|
||||
| 'pause'
|
||||
| 'help'
|
||||
| 'long-strip'
|
||||
| 'direction-ltr'
|
||||
| 'direction-rtl'
|
||||
| 'magnifier';
|
||||
|
||||
interface IconPath {
|
||||
d: string;
|
||||
type?: 'path' | 'polyline' | 'line' | 'rect' | 'circle';
|
||||
}
|
||||
|
||||
const ICONS: Record<ReaderIconName, IconPath[]> = {
|
||||
// Navigation icons
|
||||
'menu': [
|
||||
{d: 'M3,6 L21,6', type: 'line'},
|
||||
{d: 'M3,12 L21,12', type: 'line'},
|
||||
{d: 'M3,18 L21,18', type: 'line'}
|
||||
],
|
||||
'close': [
|
||||
{d: 'M18,6 L6,18', type: 'line'},
|
||||
{d: 'M6,6 L18,18', type: 'line'}
|
||||
],
|
||||
'chevron-left': [
|
||||
{d: '15,18 9,12 15,6', type: 'polyline'}
|
||||
],
|
||||
'chevron-right': [
|
||||
{d: '9,18 15,12 9,6', type: 'polyline'}
|
||||
],
|
||||
'chevron-down': [
|
||||
{d: '6,9 12,15 18,9', type: 'polyline'}
|
||||
],
|
||||
'chevron-first': [
|
||||
{d: '11,17 6,12 11,7', type: 'polyline'},
|
||||
{d: '18,17 13,12 18,7', type: 'polyline'}
|
||||
],
|
||||
'chevron-last': [
|
||||
{d: '13,17 18,12 13,7', type: 'polyline'},
|
||||
{d: '6,17 11,12 6,7', type: 'polyline'}
|
||||
],
|
||||
'chevron-double-left': [
|
||||
{d: '11,17 6,12 11,7', type: 'polyline'},
|
||||
{d: '18,17 13,12 18,7', type: 'polyline'}
|
||||
],
|
||||
'chevron-double-right': [
|
||||
{d: '13,17 18,12 13,7', type: 'polyline'},
|
||||
{d: '6,17 11,12 6,7', type: 'polyline'}
|
||||
],
|
||||
'dots-vertical': [
|
||||
{d: 'M12,12 m-1,0 a1,1 0 1,0 2,0 a1,1 0 1,0 -2,0', type: 'path'},
|
||||
{d: 'M12,5 m-1,0 a1,1 0 1,0 2,0 a1,1 0 1,0 -2,0', type: 'path'},
|
||||
{d: 'M12,19 m-1,0 a1,1 0 1,0 2,0 a1,1 0 1,0 -2,0', type: 'path'}
|
||||
],
|
||||
|
||||
// Action icons
|
||||
'bookmark': [
|
||||
{d: 'M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z'}
|
||||
],
|
||||
'settings': [
|
||||
{d: 'M12 12m-3 0a3 3 0 1 0 6 0a3 3 0 1 0-6 0', type: 'path'},
|
||||
{d: 'M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z'}
|
||||
],
|
||||
'book': [
|
||||
{d: 'M4 19.5A2.5 2.5 0 0 1 6.5 17H20'},
|
||||
{d: 'M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z'}
|
||||
],
|
||||
'edit': [
|
||||
{d: 'M12 20h9'},
|
||||
{d: 'M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z'}
|
||||
],
|
||||
'copy': [
|
||||
{d: 'M9,9 L22,9 L22,22 L9,22 Z M9,9 Q9,9 9,9', type: 'path'},
|
||||
{d: 'M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'}
|
||||
],
|
||||
'trash': [
|
||||
{d: 'M3 6h18'},
|
||||
{d: 'M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6'},
|
||||
{d: 'M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'}
|
||||
],
|
||||
'search': [
|
||||
{d: 'M11 11m-8 0a8 8 0 1 0 16 0a8 8 0 1 0-16 0', type: 'path'},
|
||||
{d: 'M21 21l-4.35-4.35'}
|
||||
],
|
||||
'note': [
|
||||
{d: 'M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'},
|
||||
{d: '14,2 14,8 20,8', type: 'polyline'},
|
||||
{d: 'M16 13H8'},
|
||||
{d: 'M16 17H8'},
|
||||
{d: 'M10 9H8'}
|
||||
],
|
||||
'plus': [
|
||||
{d: 'M12,5 L12,19', type: 'line'},
|
||||
{d: 'M5,12 L19,12', type: 'line'}
|
||||
],
|
||||
'minus': [
|
||||
{d: 'M5,12 L19,12', type: 'line'}
|
||||
],
|
||||
|
||||
// Fit mode icons
|
||||
'fit-page': [
|
||||
{d: 'M3 3h18v18H3V3z'},
|
||||
{d: 'M7 7h10v10H7V7z'}
|
||||
],
|
||||
'fit-width': [
|
||||
{d: 'M21,12 L17,8', type: 'line'},
|
||||
{d: 'M21,12 L17,16', type: 'line'},
|
||||
{d: 'M3,12 L7,8', type: 'line'},
|
||||
{d: 'M3,12 L7,16', type: 'line'},
|
||||
{d: 'M3,12 L21,12', type: 'line'}
|
||||
],
|
||||
'fit-height': [
|
||||
{d: 'M12,3 L8,7', type: 'line'},
|
||||
{d: 'M12,3 L16,7', type: 'line'},
|
||||
{d: 'M12,21 L8,17', type: 'line'},
|
||||
{d: 'M12,21 L16,17', type: 'line'},
|
||||
{d: 'M12,3 L12,21', type: 'line'}
|
||||
],
|
||||
'actual-size': [
|
||||
{d: 'M5 3h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z'},
|
||||
{d: 'M9,8 L9,16', type: 'line'},
|
||||
{d: 'M12,12 L12,16', type: 'line'},
|
||||
{d: 'M15,8 L15,16', type: 'line'}
|
||||
],
|
||||
'auto-fit': [
|
||||
{d: 'M12 3v3m0 12v3M3 12h3m12 0h3'},
|
||||
{d: 'M12 12m-4 0a4 4 0 1 0 8 0a4 4 0 1 0-8 0', type: 'path'}
|
||||
],
|
||||
'fullscreen': [
|
||||
{d: 'M8 3H5a2 2 0 0 0-2 2v3'},
|
||||
{d: 'M21 8V5a2 2 0 0 0-2-2h-3'},
|
||||
{d: 'M3 16v3a2 2 0 0 0 2 2h3'},
|
||||
{d: 'M16 21h3a2 2 0 0 0 2-2v-3'}
|
||||
],
|
||||
'fullscreen-exit': [
|
||||
{d: 'M8 3v3a2 2 0 0 1-2 2H3'},
|
||||
{d: 'M21 8h-3a2 2 0 0 1-2-2V3'},
|
||||
{d: 'M3 16h3a2 2 0 0 1 2 2v3'},
|
||||
{d: 'M16 21v-3a2 2 0 0 1 2-2h3'}
|
||||
],
|
||||
'play': [
|
||||
{d: 'M5 3l14 9-14 9V3z'}
|
||||
],
|
||||
'pause': [
|
||||
{d: 'M6,4 L6,20', type: 'line'},
|
||||
{d: 'M18,4 L18,20', type: 'line'}
|
||||
],
|
||||
'help': [
|
||||
{d: 'M12 12m-10 0a10 10 0 1 0 20 0a10 10 0 1 0-20 0', type: 'path'},
|
||||
{d: 'M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3'},
|
||||
{d: 'M12 17h.01'}
|
||||
],
|
||||
'long-strip': [
|
||||
{d: 'M4 3h16v6H4z'},
|
||||
{d: 'M4 9h16v6H4z'},
|
||||
{d: 'M4 15h16v6H4z'}
|
||||
],
|
||||
'direction-ltr': [
|
||||
{d: 'M5,12 L19,12', type: 'line'},
|
||||
{d: 'M15,8 L19,12 L15,16', type: 'polyline'}
|
||||
],
|
||||
'direction-rtl': [
|
||||
{d: 'M19,12 L5,12', type: 'line'},
|
||||
{d: 'M9,8 L5,12 L9,16', type: 'polyline'}
|
||||
],
|
||||
'magnifier': [
|
||||
{d: 'M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0-14 0', type: 'path'},
|
||||
{d: 'M21 21l-5-5'},
|
||||
{d: 'M7,10 L13,10', type: 'line'},
|
||||
{d: 'M10,7 L10,13', type: 'line'}
|
||||
]
|
||||
};
|
||||
|
||||
@Component({
|
||||
selector: 'app-reader-icon',
|
||||
standalone: true,
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
imports: [CommonModule],
|
||||
template: `
|
||||
<svg
|
||||
[attr.width]="size"
|
||||
[attr.height]="size"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
[attr.stroke-width]="strokeWidth"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
[class]="className">
|
||||
@for (path of paths; track $index) {
|
||||
@switch (path.type) {
|
||||
@case ('line') {
|
||||
<line
|
||||
[attr.x1]="getLineCoords(path.d, 0)"
|
||||
[attr.y1]="getLineCoords(path.d, 1)"
|
||||
[attr.x2]="getLineCoords(path.d, 2)"
|
||||
[attr.y2]="getLineCoords(path.d, 3)"/>
|
||||
}
|
||||
@case ('polyline') {
|
||||
<polyline [attr.points]="path.d"/>
|
||||
}
|
||||
@default {
|
||||
<path [attr.d]="path.d"/>
|
||||
}
|
||||
}
|
||||
}
|
||||
</svg>
|
||||
`,
|
||||
styles: [`
|
||||
:host {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
svg {
|
||||
display: block;
|
||||
}
|
||||
`]
|
||||
})
|
||||
export class ReaderIconComponent {
|
||||
@Input() name!: ReaderIconName;
|
||||
@Input() size: number | string = 18;
|
||||
@Input() strokeWidth: number | string = 2;
|
||||
@Input() className = '';
|
||||
|
||||
get paths(): IconPath[] {
|
||||
return ICONS[this.name] || [];
|
||||
}
|
||||
|
||||
getLineCoords(d: string, index: number): string {
|
||||
const coords = d.replace(/[ML]/g, ' ').trim().split(/[\s,]+/);
|
||||
return coords[index] || '0';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<ng-container *transloco="let t; prefix: 'readerEbook.selectionPopup'">
|
||||
@if (visible) {
|
||||
<div class="popup-backdrop" (click)="onDismiss($event)"></div>
|
||||
<div class="text-selection-popup"
|
||||
[class.show-below]="showBelow"
|
||||
[style.left.px]="position.x"
|
||||
[style.top.px]="position.y">
|
||||
|
||||
<button class="action-btn" (click)="onSelect()" [title]="t('copyText')">
|
||||
<app-reader-icon name="copy" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<button class="action-btn" (click)="onSearch()" [title]="t('searchInBook')">
|
||||
<app-reader-icon name="search" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<div class="annotation-container">
|
||||
<button class="action-btn" [class.active]="showAnnotationOptions" (click)="toggleAnnotationOptions()" [title]="t('annotate')">
|
||||
<app-reader-icon name="edit" [size]="16"></app-reader-icon>
|
||||
<app-reader-icon name="chevron-down" class="chevron" [class.open]="showAnnotationOptions" [size]="10"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
@if (showAnnotationOptions) {
|
||||
<div class="annotation-options" [class.above]="!showBelow" [class.below]="showBelow">
|
||||
<div class="style-buttons">
|
||||
@for (style of styles; track style.value) {
|
||||
<button
|
||||
class="style-btn"
|
||||
[class.selected]="selectedStyle === style.value"
|
||||
[class.highlight-style]="style.value === 'highlight'"
|
||||
[class.underline-style]="style.value === 'underline'"
|
||||
[class.squiggly-style]="style.value === 'squiggly'"
|
||||
[class.strikethrough-style]="style.value === 'strikethrough'"
|
||||
[title]="style.label"
|
||||
(click)="selectStyle(style.value)">
|
||||
<span class="style-text">{{ style.icon }}</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
<div class="color-buttons">
|
||||
@for (color of colors; track color.value) {
|
||||
<button
|
||||
class="color-btn"
|
||||
[style.--color]="color.value"
|
||||
[class.selected]="selectedColor === color.value"
|
||||
[title]="color.label"
|
||||
(click)="selectColor(color.value)">
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<button class="action-btn" (click)="onNote()" [title]="t('addNote')">
|
||||
<app-reader-icon name="note" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
|
||||
@if (overlappingAnnotationId) {
|
||||
<div class="divider"></div>
|
||||
<button class="action-btn delete-btn" (click)="onDelete()" [title]="t('deleteAnnotation')">
|
||||
<app-reader-icon name="trash" [size]="16"></app-reader-icon>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</ng-container>
|
||||
@@ -0,0 +1,233 @@
|
||||
.popup-backdrop {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 99998;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.text-selection-popup {
|
||||
position: fixed;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 6px 8px;
|
||||
background: linear-gradient(180deg, #2d3139 0%, #252830 100%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 1px rgba(0, 0, 0, 0.2);
|
||||
z-index: 99999;
|
||||
transform: translateX(-50%);
|
||||
animation: popupFadeIn 0.15s ease-out;
|
||||
|
||||
&.show-below {
|
||||
animation: popupFadeInBelow 0.15s ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes popupFadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(4px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes popupFadeInBelow {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(-4px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 2px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
padding: 0;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
background: transparent;
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chevron {
|
||||
margin-left: -2px;
|
||||
transition: transform 0.2s ease;
|
||||
|
||||
&.open {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
&:hover {
|
||||
background: rgba(239, 68, 68, 0.15);
|
||||
color: #ef4444;
|
||||
}
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 1px;
|
||||
height: 20px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
margin: 0 2px;
|
||||
}
|
||||
|
||||
.annotation-container {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.annotation-options {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
padding: 8px;
|
||||
background: linear-gradient(180deg, #2d3139 0%, #252830 100%);
|
||||
border: 1px solid rgba(255, 255, 255, 0.08);
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
|
||||
z-index: 100000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
|
||||
&.above {
|
||||
bottom: calc(100% + 8px);
|
||||
animation: slideUp 0.15s ease-out;
|
||||
}
|
||||
|
||||
&.below {
|
||||
top: calc(100% + 8px);
|
||||
animation: slideDown 0.15s ease-out;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideUp {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes slideDown {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateX(-50%) translateY(-6px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateX(-50%) translateY(0);
|
||||
}
|
||||
}
|
||||
|
||||
.style-buttons {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.style-btn {
|
||||
width: 32px;
|
||||
height: 28px;
|
||||
padding: 0;
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
border-radius: 4px;
|
||||
background: rgba(255, 255, 255, 0.03);
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
.style-text {
|
||||
display: block;
|
||||
}
|
||||
|
||||
&.highlight-style .style-text {
|
||||
background: linear-gradient(180deg, rgba(255, 255, 0, 0.4) 60%, transparent 60%);
|
||||
}
|
||||
|
||||
&.underline-style .style-text {
|
||||
text-decoration: underline;
|
||||
text-decoration-thickness: 2px;
|
||||
}
|
||||
|
||||
&.squiggly-style .style-text {
|
||||
text-decoration: underline wavy;
|
||||
}
|
||||
|
||||
&.strikethrough-style .style-text {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(255, 255, 255, 0.2);
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #3b82f6;
|
||||
background: rgba(59, 130, 246, 0.15);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.color-buttons {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.color-btn {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
padding: 0;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 50%;
|
||||
background: var(--color);
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
|
||||
&:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #fff;
|
||||
box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {TranslocoDirective} from '@jsverse/transloco';
|
||||
import {ReaderIconComponent} from './icon.component';
|
||||
|
||||
export type AnnotationStyle = 'highlight' | 'underline' | 'strikethrough' | 'squiggly';
|
||||
|
||||
export interface TextSelectionAction {
|
||||
type: 'select' | 'annotate' | 'delete' | 'dismiss' | 'preview' | 'search' | 'note';
|
||||
color?: string;
|
||||
style?: AnnotationStyle;
|
||||
annotationId?: number;
|
||||
searchText?: string;
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-text-selection-popup',
|
||||
standalone: true,
|
||||
imports: [CommonModule, TranslocoDirective, ReaderIconComponent],
|
||||
templateUrl: './selection-popup.component.html',
|
||||
styleUrls: ['./selection-popup.component.scss']
|
||||
})
|
||||
export class TextSelectionPopupComponent {
|
||||
@Input() set visible(value: boolean) {
|
||||
this._visible = value;
|
||||
if (value) {
|
||||
this.showAnnotationOptions = false;
|
||||
this.hasPreview = false;
|
||||
}
|
||||
}
|
||||
get visible(): boolean {
|
||||
return this._visible;
|
||||
}
|
||||
private _visible = false;
|
||||
|
||||
@Input() position = {x: 0, y: 0};
|
||||
@Input() showBelow = false;
|
||||
@Input() overlappingAnnotationId: number | null = null;
|
||||
@Input() selectedText = '';
|
||||
@Output() action = new EventEmitter<TextSelectionAction>();
|
||||
|
||||
showAnnotationOptions = false;
|
||||
selectedColor = '#FACC15';
|
||||
selectedStyle: AnnotationStyle = 'highlight';
|
||||
private hasPreview = false;
|
||||
|
||||
highlightColors = [
|
||||
{value: '#FACC15', label: 'Yellow'},
|
||||
{value: '#4ADE80', label: 'Green'},
|
||||
{value: '#38BDF8', label: 'Blue'},
|
||||
{value: '#F472B6', label: 'Pink'},
|
||||
{value: '#FB923C', label: 'Orange'}
|
||||
];
|
||||
|
||||
lineColors = [
|
||||
{value: '#B8860B', label: 'Dark Gold'},
|
||||
{value: '#228B22', label: 'Forest Green'},
|
||||
{value: '#1E90FF', label: 'Dodger Blue'},
|
||||
{value: '#DC143C', label: 'Crimson'},
|
||||
{value: '#FF8C00', label: 'Dark Orange'}
|
||||
];
|
||||
|
||||
get colors() {
|
||||
return this.selectedStyle === 'highlight' ? this.highlightColors : this.lineColors;
|
||||
}
|
||||
|
||||
styles: { value: AnnotationStyle; label: string; icon: string }[] = [
|
||||
{value: 'highlight', label: 'Highlight', icon: 'H'},
|
||||
{value: 'underline', label: 'Underline', icon: 'U'},
|
||||
{value: 'squiggly', label: 'Squiggly', icon: '~'},
|
||||
{value: 'strikethrough', label: 'Strikethrough', icon: 'S'}
|
||||
];
|
||||
|
||||
onSelect(): void {
|
||||
this.action.emit({type: 'select'});
|
||||
this.showAnnotationOptions = false;
|
||||
this.hasPreview = false;
|
||||
}
|
||||
|
||||
toggleAnnotationOptions(): void {
|
||||
this.showAnnotationOptions = !this.showAnnotationOptions;
|
||||
if (this.showAnnotationOptions) {
|
||||
this.emitPreview();
|
||||
}
|
||||
}
|
||||
|
||||
selectColor(color: string): void {
|
||||
this.selectedColor = color;
|
||||
this.emitPreview();
|
||||
}
|
||||
|
||||
selectStyle(style: AnnotationStyle): void {
|
||||
const wasHighlight = this.selectedStyle === 'highlight';
|
||||
const isHighlight = style === 'highlight';
|
||||
|
||||
this.selectedStyle = style;
|
||||
|
||||
if (wasHighlight !== isHighlight) {
|
||||
this.selectedColor = isHighlight ? this.highlightColors[0].value : this.lineColors[0].value;
|
||||
}
|
||||
this.emitPreview();
|
||||
}
|
||||
|
||||
private emitPreview(): void {
|
||||
this.hasPreview = true;
|
||||
this.action.emit({
|
||||
type: 'preview',
|
||||
color: this.selectedColor,
|
||||
style: this.selectedStyle
|
||||
});
|
||||
}
|
||||
|
||||
onDelete(): void {
|
||||
if (this.overlappingAnnotationId) {
|
||||
this.action.emit({type: 'delete', annotationId: this.overlappingAnnotationId});
|
||||
}
|
||||
}
|
||||
|
||||
onSearch(): void {
|
||||
this.action.emit({type: 'search', searchText: this.selectedText});
|
||||
this.showAnnotationOptions = false;
|
||||
this.hasPreview = false;
|
||||
}
|
||||
|
||||
onNote(): void {
|
||||
this.action.emit({type: 'note'});
|
||||
this.showAnnotationOptions = false;
|
||||
this.hasPreview = false;
|
||||
}
|
||||
|
||||
onDismiss(event: MouseEvent): void {
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
if (this.hasPreview) {
|
||||
this.action.emit({
|
||||
type: 'annotate',
|
||||
color: this.selectedColor,
|
||||
style: this.selectedStyle
|
||||
});
|
||||
} else {
|
||||
this.action.emit({type: 'dismiss'});
|
||||
}
|
||||
|
||||
this.showAnnotationOptions = false;
|
||||
this.hasPreview = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
export interface HeaderFooterVisibilityState {
|
||||
headerVisible: boolean;
|
||||
footerVisible: boolean;
|
||||
}
|
||||
|
||||
export class ReaderHeaderFooterVisibilityManager {
|
||||
private isPinned = false;
|
||||
private mouseY: number;
|
||||
|
||||
private readonly HEADER_HEIGHT = 20;
|
||||
private readonly FOOTER_HEIGHT = 40;
|
||||
private readonly HEADER_TRIGGER_ZONE = 20;
|
||||
private readonly FOOTER_TRIGGER_ZONE = 30;
|
||||
|
||||
private headerVisible = false;
|
||||
private footerVisible = false;
|
||||
|
||||
private onStateChangeCallback?: (state: HeaderFooterVisibilityState) => void;
|
||||
|
||||
constructor(private windowHeight: number) {
|
||||
this.mouseY = windowHeight / 2;
|
||||
}
|
||||
|
||||
onStateChange(callback: (state: HeaderFooterVisibilityState) => void): void {
|
||||
this.onStateChangeCallback = callback;
|
||||
}
|
||||
|
||||
updateWindowHeight(height: number): void {
|
||||
this.windowHeight = height;
|
||||
}
|
||||
|
||||
handleMouseMove(mouseY: number): void {
|
||||
this.mouseY = mouseY;
|
||||
this.updateVisibility();
|
||||
}
|
||||
|
||||
handleMouseLeave(): void {
|
||||
if (!this.isPinned) {
|
||||
this.setHeaderVisible(false);
|
||||
this.setFooterVisible(false);
|
||||
this.notifyStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
handleHeaderZoneEnter(): void {
|
||||
if (!this.isPinned) {
|
||||
this.setHeaderVisible(true);
|
||||
this.notifyStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
handleFooterZoneEnter(): void {
|
||||
if (!this.isPinned) {
|
||||
this.setFooterVisible(true);
|
||||
this.notifyStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
togglePinned(): void {
|
||||
this.isPinned = !this.isPinned;
|
||||
this.updateVisibility();
|
||||
}
|
||||
|
||||
getVisibilityState(): HeaderFooterVisibilityState {
|
||||
return {
|
||||
headerVisible: this.headerVisible,
|
||||
footerVisible: this.footerVisible
|
||||
};
|
||||
}
|
||||
|
||||
private updateVisibility(): void {
|
||||
if (
|
||||
this.mouseY <= this.HEADER_TRIGGER_ZONE ||
|
||||
(this.mouseY <= this.HEADER_HEIGHT && this.headerVisible) ||
|
||||
this.isPinned
|
||||
) {
|
||||
this.setHeaderVisible(true);
|
||||
} else if (this.mouseY > this.HEADER_HEIGHT) {
|
||||
this.setHeaderVisible(this.isPinned);
|
||||
}
|
||||
|
||||
const footerTop = this.windowHeight - this.FOOTER_HEIGHT;
|
||||
if (
|
||||
this.mouseY >= this.windowHeight - this.FOOTER_TRIGGER_ZONE ||
|
||||
(this.mouseY >= footerTop && this.footerVisible) ||
|
||||
this.isPinned
|
||||
) {
|
||||
this.setFooterVisible(true);
|
||||
} else if (this.mouseY < footerTop) {
|
||||
this.setFooterVisible(this.isPinned);
|
||||
}
|
||||
|
||||
this.notifyStateChange();
|
||||
}
|
||||
|
||||
private setHeaderVisible(visible: boolean): void {
|
||||
this.headerVisible = visible;
|
||||
}
|
||||
|
||||
private setFooterVisible(visible: boolean): void {
|
||||
this.footerVisible = visible;
|
||||
}
|
||||
|
||||
private notifyStateChange(): void {
|
||||
if (this.onStateChangeCallback) {
|
||||
this.onStateChangeCallback(this.getVisibilityState());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user