Files
grimmory/frontend/src/app/features/readers/pdf-reader/pdf-reader.component.scss
T
brios 68d0b26716 fix(pdf): improve PDF blob handling and improve viewer destruction logic (#506)
* fix(pdf): improve PDF blob handling and improve viewer destruction logic

* fix(pdf):  PDF annotation saving logic and improve responsive design for mobile

* fix(pdf): improve PDF fetching (once again) and caching logic to improve performance and reduce network requests

* fix(pdf): hide footer and notification elements in PDF viewer

* fix(pdf): improve loading behavior and improve annotation persistence logic

* fix(pdf): improve PDF annotation persistence with retry mechanism and logging

* fix(pdf): improve PDF annotation saving with raw fetch and improved error handling

* fix(pdf): cap highlight opacity and adjust rendering for small viewports
2026-04-22 17:27:35 -04:00

928 lines
16 KiB
SCSS

@use 'sass:color';
/* stylelint-disable selector-id-pattern, selector-class-pattern */
// Design tokens matching CBX/E-Book readers
$header-height: 38px;
$footer-height: 52px;
$gradient-bg: linear-gradient(135deg, #2d2d2d 0%, #1f1f1f 100%);
$border-color: #404040;
$text-primary: rgb(255 255 255 / 95%);
$text-secondary: rgb(255 255 255 / 60%);
$active-color: #4a90e2;
$hover-bg: rgb(255 255 255 / 12%);
$transition-fast: 150ms ease;
.v-hidden {
visibility: hidden !important;
}
// --- Loading ---
.loading-container {
position: fixed;
inset: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100dvh;
background: #1a1a1a;
z-index: 1000;
}
// --- Reader container ---
.pdf-reader-container {
position: fixed;
inset: 0;
height: 100dvh;
background: #1a1a1a;
z-index: 900;
overflow: hidden;
box-sizing: border-box;
* {
box-sizing: border-box;
}
}
// --- Trigger zones ---
.header-trigger-zone,
.footer-trigger-zone {
position: fixed;
left: 0;
right: 0;
z-index: 1001;
}
.header-trigger-zone {
top: 0;
height: 20px;
&.inactive {
pointer-events: none;
}
}
.footer-trigger-zone {
bottom: 0;
height: 30px;
&.inactive {
pointer-events: none;
}
}
// --- 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: 1001;
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;
align-items: center;
gap: 2px;
z-index: 1;
flex-shrink: 0;
}
.book-title {
position: absolute;
left: 50%;
transform: translateX(-50%);
max-width: 40%;
padding: 0 12px;
text-align: center;
font-size: 14px;
font-weight: 500;
color: inherit;
pointer-events: none;
user-select: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.separator {
width: 1px;
height: 18px;
background: rgb(255 255 255 / 15%);
margin: 0 4px;
}
}
// --- Icon buttons ---
.icon-btn {
background: none;
border: none;
color: inherit;
cursor: pointer;
padding: 7px;
border-radius: 6px;
transition: background $transition-fast;
display: flex;
align-items: center;
justify-content: center;
&:hover {
background: $hover-bg;
}
&.close-btn:hover {
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;
}
}
// --- Search bar ---
.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;
transition: background $transition-fast;
&:hover {
background: $hover-bg;
}
&.active {
color: $active-color;
font-weight: 600;
}
}
}
// --- Book viewer container ---
.book-viewer-container {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: hidden;
embedpdf-container {
width: 100%;
height: 100%;
display: block;
}
}
// --- Footer ---
.pdf-footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: $footer-height;
padding: 0 16px;
padding-bottom: env(safe-area-inset-bottom);
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
z-index: 1002;
background: $gradient-bg;
border-top: 1px solid $border-color;
box-shadow: 0 -2px 8px rgb(0 0 0 / 30%);
color: $text-primary;
transform: translateY(100%);
opacity: 0;
pointer-events: none;
transition: transform 0.25s ease-out, opacity 0.25s ease-out;
&.visible {
transform: translateY(0);
opacity: 1;
pointer-events: auto;
}
}
.page-nav-left {
display: flex;
align-items: center;
gap: 8px;
flex: 0 0 auto;
}
.nav-btn {
background: rgb(51 51 51 / 90%);
border: 1px solid #555;
color: $text-primary;
padding: 6px 10px;
border-radius: 4px;
cursor: pointer;
transition: all $transition-fast;
display: flex;
align-items: center;
justify-content: center;
&:hover:not(:disabled) {
background: #4a4a4a;
border-color: #666;
}
&:disabled {
background: #2a2a2a;
color: #666;
cursor: not-allowed;
border-color: #333;
}
}
.page-info {
padding: 4px 12px;
background: rgb(255 255 255 / 10%);
border-radius: 4px;
font-size: 13px;
font-weight: 500;
min-width: 90px;
text-align: center;
.current {
color: $active-color;
font-weight: 600;
}
.total {
color: $text-secondary;
}
}
.page-controls {
display: flex;
align-items: center;
gap: 12px;
flex: 1;
justify-content: center;
}
.footer-spacer {
flex: 0 0 auto;
width: 0;
}
.slider-wrapper {
flex: 1;
display: flex;
align-items: center;
position: relative;
.page-slider {
width: 100%;
border-radius: 3px;
outline: none;
appearance: none;
background: none;
cursor: pointer;
&::-webkit-slider-runnable-track {
width: 100%;
height: 6px;
background: rgb(255 255 255 / 12%);
border-radius: 3px;
cursor: pointer;
}
&::-moz-range-track {
width: 100%;
height: 6px;
background: rgb(255 255 255 / 12%);
border-radius: 3px;
cursor: pointer;
}
&::-webkit-slider-thumb {
appearance: none;
width: 18px;
height: 18px;
border-radius: 50%;
background: $active-color;
cursor: pointer;
box-shadow: 0 2px 6px rgb(0 0 0 / 30%);
transition: transform $transition-fast;
margin-top: calc((6px - 18px) / 2);
}
&::-moz-range-thumb {
width: 18px;
height: 18px;
border-radius: 50%;
background: $active-color;
cursor: pointer;
border: none;
box-shadow: 0 2px 6px rgb(0 0 0 / 30%);
transition: transform $transition-fast;
}
}
datalist {
display: flex;
justify-content: space-between;
position: absolute;
width: 100%;
left: 0;
top: 50%;
transform: translateY(-50%);
pointer-events: none;
height: 10px;
option {
width: 0;
position: relative;
padding: 0;
&::before {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
width: 2px;
height: 10px;
background: rgb(255 255 255 / 50%);
top: 0;
}
}
}
}
.viewer-mode-toggle {
display: flex;
align-items: center;
.toggle-btn {
display: inline-flex;
align-items: center;
justify-content: center;
white-space: nowrap;
gap: 6px;
padding: 0 12px;
border: 1px solid var(--surface-border);
background: var(--surface-card);
color: var(--text-color-secondary);
cursor: pointer;
font-size: 0.85rem;
font-weight: 500;
transition: all 0.2s;
height: 30px;
&:hover {
color: var(--text-color);
background: var(--surface-hover);
}
&.active {
background: var(--primary-color);
color: var(--primary-color-text);
border-color: var(--primary-color);
z-index: 1;
}
&.toggle-book {
border-top-left-radius: 6px;
border-bottom-left-radius: 6px;
border-right: none;
}
&.toggle-doc {
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
}
}
}
.embed-pdf-warning {
position: absolute;
bottom: 80px;
left: 24px;
z-index: 1001;
background-color: var(--surface-card);
color: var(--text-color-secondary);
border: 1px solid var(--surface-border);
padding: 8px 16px;
border-radius: 20px;
display: flex;
align-items: center;
gap: 8px;
font-weight: 500;
font-size: 0.85rem;
box-shadow: 0 4px 6px rgb(0 0 0 / 10%);
pointer-events: none;
i {
font-size: 1rem;
color: var(--primary-color);
}
}
.embed-close-btn {
position: fixed;
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 {
position: fixed;
top: 48px;
right: 12px;
z-index: 1010;
background: rgb(45 45 45 / 90%);
color: $text-primary;
padding: 6px 12px;
border-radius: 20px;
display: flex;
align-items: center;
gap: 10px;
font-size: 13px;
font-weight: 500;
border: 1px solid $border-color;
box-shadow: 0 2px 8px rgb(0 0 0 / 30%);
backdrop-filter: blur(4px);
animation: doc-viewer-info-fade-in 0.3s ease-out;
.dismiss-btn {
background: none;
border: none;
color: $text-secondary;
cursor: pointer;
display: flex;
align-items: center;
padding: 2px;
border-radius: 50%;
transition: all 0.2s;
&:hover {
color: #fff;
background: rgb(255 255 255 / 10%);
}
}
}
@keyframes doc-viewer-info-fade-in {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
#embedpdf-viewer {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
display: flex;
iframe {
width: 100%;
height: 100%;
border: none;
}
}
.goto-page {
display: flex;
align-items: center;
gap: 4px;
background: rgb(51 51 51 / 90%);
border-radius: 4px;
padding: 2px;
border: 1px solid #555;
.page-input {
width: 55px;
padding: 4px 6px;
border: none;
border-radius: 3px;
background: #404040;
color: $text-primary;
font-size: 12px;
text-align: center;
&:focus {
outline: none;
background: #4a4a4a;
}
&::placeholder {
color: rgb(255 255 255 / 30%);
}
}
.go-btn {
padding: 4px 8px;
border: none;
border-radius: 3px;
background: $active-color;
color: #fff;
font-size: 11px;
font-weight: 600;
cursor: pointer;
text-transform: uppercase;
transition: background $transition-fast;
&:hover:not(:disabled) {
background: color.adjust($active-color, $lightness: -10%);
}
&:disabled {
opacity: 0.4;
cursor: not-allowed;
}
}
}
// --- Mobile actions (hidden on desktop) ---
.mobile-actions {
display: none;
align-items: center;
gap: 2px;
}
// --- 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;
}
svg,
app-reader-icon {
flex-shrink: 0;
}
}
.overflow-divider {
height: 1px;
background: $border-color;
margin: 4px 0;
}
}
// --- Responsive ---
// Tablet (portrait) switches to mobile toolbar layout
@media (width <= 1024px) {
.pdf-header-toolbar {
height: calc(#{$header-height} + 4px + env(safe-area-inset-top));
padding: 0 8px;
padding-top: env(safe-area-inset-top);
}
.desktop-actions {
display: none;
}
.mobile-actions {
display: flex;
}
.pdf-footer {
height: auto;
padding: 8px 12px;
padding-bottom: calc(8px + env(safe-area-inset-bottom));
flex-wrap: wrap;
gap: 8px;
}
.page-controls {
order: -1;
width: 100%;
}
.goto-page {
display: none;
}
.footer-spacer {
display: none;
}
.page-nav-left {
flex: 1;
justify-content: center;
}
.viewer-mode-toggle {
.toggle-btn span {
display: none;
}
}
.search-bar {
top: calc(#{$header-height} + 4px + env(safe-area-inset-top));
.search-input-wrapper {
max-width: none;
}
}
.doc-viewer-info {
right: 12px;
left: 12px;
top: calc(48px + env(safe-area-inset-top));
justify-content: center;
}
.book-title {
display: none;
}
// Larger touch targets for trigger zones
.header-trigger-zone {
height: 40px;
}
.footer-trigger-zone {
height: 50px;
}
.toolbar-overflow-menu {
top: calc(#{$header-height} + 4px + env(safe-area-inset-top));
right: 4px;
left: 4px;
min-width: unset;
.overflow-item {
padding: 12px 16px;
font-size: 15px;
min-height: 44px;
}
}
.slider-wrapper {
.page-slider {
&::-webkit-slider-thumb {
width: 24px;
height: 24px;
margin-top: calc((6px - 24px) / 2);
}
&::-moz-range-thumb {
width: 24px;
height: 24px;
}
}
}
}
// Small phones
@media (width <= 480px) {
.pdf-header-toolbar {
padding: 0 6px;
padding-top: env(safe-area-inset-top);
}
.pdf-footer {
padding: 6px 8px;
padding-bottom: calc(6px + env(safe-area-inset-bottom));
gap: 6px;
}
.page-nav-left {
gap: 2px;
}
.nav-btn {
padding: 8px;
min-width: 40px;
min-height: 40px;
}
.page-info {
min-width: 60px;
font-size: 12px;
padding: 4px 6px;
}
.slider-wrapper {
.page-slider {
&::-webkit-slider-thumb {
width: 28px;
height: 28px;
margin-top: calc((6px - 28px) / 2);
}
&::-moz-range-thumb {
width: 28px;
height: 28px;
}
}
}
.viewer-mode-toggle .toggle-btn {
padding: 0 8px;
height: 36px;
min-width: 36px;
}
.icon-btn {
padding: 8px;
min-width: 40px;
min-height: 40px;
}
.page-controls {
// Give slider full width on small screens
.slider-wrapper {
flex: 1;
min-width: 0;
}
}
}