55 lines
1.8 KiB
JavaScript
55 lines
1.8 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
// Reader settings
|
||
|
|
let readerSettings = { fontSize: 16, lineHeight: 1.8, maxWidth: 65, theme: 'dark',
|
||
|
|
fontFamily: 'serif', noBold: false, fontWeight: null,
|
||
|
|
pdfZoom: 100, pdfInverted: false, pdfPaginated: false, pdfSpread: false };
|
||
|
|
let readerSettingsPanelOpen = false;
|
||
|
|
let currentPdfDoc = null;
|
||
|
|
let currentPdfBuffer = null;
|
||
|
|
|
||
|
|
// Bookmarks
|
||
|
|
let currentBookmarks = [];
|
||
|
|
let bookmarksDirty = false;
|
||
|
|
|
||
|
|
// Highlights
|
||
|
|
let currentHighlights = [];
|
||
|
|
let highlightsDirty = false;
|
||
|
|
let currentHighlightPopover = null;
|
||
|
|
|
||
|
|
// Search
|
||
|
|
let searchMatches = [];
|
||
|
|
let searchMatchIndex = -1;
|
||
|
|
let searchOriginalContent = null;
|
||
|
|
let readerSearchOpen = false;
|
||
|
|
|
||
|
|
// PDF paginated
|
||
|
|
let pdfCurrentPage = 1;
|
||
|
|
let pdfTotalPages = 0;
|
||
|
|
let _pdfPageTextBoxCache = {};
|
||
|
|
let _pdfRenderGen = 0;
|
||
|
|
let _touchStartX = 0;
|
||
|
|
let _readerScrollInterval = null;
|
||
|
|
let _readerScrollDir = 0;
|
||
|
|
let _readerScrollLastTs = 0;
|
||
|
|
const READER_SCROLL_SPEED = 1200; // constant px/s, no ramp-up
|
||
|
|
const READER_SCROLL_TICK_MS = 20; // fixed cadence, independent of the
|
||
|
|
// display's refresh rate — rAF runs at
|
||
|
|
// that rate (120/144/165Hz on plenty of
|
||
|
|
// laptops), which was driving 2-3x more
|
||
|
|
// scrollBy + scroll-listener work per
|
||
|
|
// second than intended and read as lag.
|
||
|
|
function _readerScrollTick() {
|
||
|
|
const now = performance.now();
|
||
|
|
const dt = now - _readerScrollLastTs;
|
||
|
|
_readerScrollLastTs = now;
|
||
|
|
$('reader-content')?.scrollBy({top: Math.round(_readerScrollDir * READER_SCROLL_SPEED * dt / 1000)});
|
||
|
|
}
|
||
|
|
let _pinchStartDist = 0;
|
||
|
|
let _pinchStartZoom = 100;
|
||
|
|
let _isPinching = false;
|
||
|
|
|
||
|
|
if (typeof pdfjsLib !== 'undefined') {
|
||
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = '/static/js/pdf.worker.min.js';
|
||
|
|
}
|