feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer (#306)

* feat(reader): add document mode to the PDF viewer, overhaul PDF viewer, add different modes to CBX viewer

* feat(reader): improve reader settings with brightness, emulate book mode, and click-to-paginate options

* feat(reader): add long strip scroll mode and update related settings
This commit is contained in:
brios
2026-04-22 17:26:57 -04:00
committed by Zach Yale
parent a3add5ded9
commit 61b9b53a60
47 changed files with 4458 additions and 874 deletions
@@ -1,46 +1,878 @@
@use 'sass:color';
/* stylelint-disable selector-id-pattern, selector-class-pattern -- targets ngx-extended-pdf-viewer / pdf.js internals */
// 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;
// --- Loading ---
.loading-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
position: relative;
height: 100dvh;
background: #1a1a1a;
}
::ng-deep .toolbar-btn,
::ng-deep .close-reader-btn {
// --- Reader container ---
.pdf-reader-container {
position: fixed;
inset: 0;
display: flex;
flex-direction: column;
background: #1a1a1a;
z-index: 900;
}
// --- 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 ---
// Child element styles for .pdf-header-toolbar (positioning is in ::ng-deep #toolbarViewer)
.pdf-header-toolbar {
.header-left,
.header-right {
display: flex;
align-items: center;
gap: 2px;
z-index: 1;
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%;
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;
width: 28px;
height: 28px;
border: none;
border-radius: 6px;
background: transparent;
color: #2a2a2a;
&:hover {
background: $hover-bg;
}
&.close-btn:hover {
background: rgb(239 68 68 / 20%);
color: #ef4444;
}
}
// --- Override pdf.js component button styles ---
::ng-deep .pdf-btn-wrap {
button {
background: none !important;
border: none !important;
color: #fff !important;
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;
&:hover {
background: $hover-bg !important;
}
&.toggled,
&[aria-pressed="true"] {
color: $active-color !important;
background: rgb(74 144 226 / 15%) !important;
}
span {
display: none !important;
}
&::before {
color: inherit !important;
opacity: 1 !important;
}
}
}
// --- Footer ---
.pdf-footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: $footer-height;
padding: 0 16px;
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;
margin-left: 4px;
margin-right: 2px;
transition: background-color 0.2s ease, color 0.2s ease;
transition: all $transition-fast;
display: flex;
align-items: center;
justify-content: center;
&:hover {
background: rgb(0 0 0 / 10%);
&:hover:not(:disabled) {
background: #4a4a4a;
border-color: #666;
}
svg {
flex-shrink: 0;
&:disabled {
background: #2a2a2a;
color: #666;
cursor: not-allowed;
border-color: #333;
}
}
::ng-deep .pdf-dark .toolbar-btn,
::ng-deep .pdf-dark .close-reader-btn {
color: #e8e8e8;
.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;
&:hover {
background: rgb(255 255 255 / 15%);
.current {
color: $active-color;
font-weight: 600;
}
.total {
color: $text-secondary;
}
}
::ng-deep .close-reader-btn:hover {
color: #ff6b6b;
.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: 4px;
right: 12px;
z-index: 1010;
color: $text-primary;
padding: 7px;
}
#embedpdf-viewer {
width: 100%;
height: 100%;
flex: 1;
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;
}
}
}
// --- Override pdf.js viewer inner styles ---
::ng-deep {
// Make pdf viewer fill container
ngx-extended-pdf-viewer {
flex: 1;
display: block;
overflow: hidden;
#mainContainer {
background: #1a1a1a !important;
}
// 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;
}
}
// 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;
}
}
}
// --- Responsive ---
@media (width <= 768px) {
.pdf-footer {
height: auto;
padding: 8px 12px;
flex-wrap: wrap;
gap: 8px;
}
.page-controls {
order: -1;
width: 100%;
}
.goto-page {
display: none;
}
.zoom-controls {
display: none;
}
.header-right {
::ng-deep pdf-zoom-toolbar {
display: none !important;
}
}
.book-title {
display: none;
}
}