Compare commits

..

3 commits

4 changed files with 105 additions and 55 deletions

View file

@ -373,11 +373,14 @@ def collate(args):
collation_staging_area = args.destdir / 'site' / 'images-staging' collation_staging_area = args.destdir / 'site' / 'images-staging'
collation_staging_area.mkdir(parents=True) collation_staging_area.mkdir(parents=True)
collation_area = args.destdir / 'site' / 'images'
collation_area.mkdir(parents=True, exist_ok=True)
for work_path in extraction_dir.iterdir(): for work_path in extraction_dir.iterdir():
work_id = work_path.name work_id = work_path.name
collation_dir = args.destdir / 'site' / 'images' / work_id work_collation_dir = collation_area / work_id
if collation_dir.exists(): if work_collation_dir.exists():
continue continue
virtual = cur.execute("SELECT virtual FROM works WHERE id = ?", (work_id,)).fetchone() virtual = cur.execute("SELECT virtual FROM works WHERE id = ?", (work_id,)).fetchone()
@ -389,7 +392,7 @@ def collate(args):
pages_collated = collate_from_paths([hint_map.get(work_id, work_path)], work_staging_dir, 0, []) pages_collated = collate_from_paths([hint_map.get(work_id, work_path)], work_staging_dir, 0, [])
if pages_collated: if pages_collated:
print(f'Collated {pages_collated} pages for {work_id}') print(f'Collated {pages_collated} pages for {work_id}')
work_staging_dir.rename(collation_dir) work_staging_dir.rename(work_collation_dir)
else: else:
if work_staging_dir.is_dir(): if work_staging_dir.is_dir():
for f in work_staging_dir.iterdir(): for f in work_staging_dir.iterdir():
@ -603,13 +606,16 @@ def manual_collate(args):
else: else:
groups = [[extraction_dir / work_id]] groups = [[extraction_dir / work_id]]
collation_dir = args.destdir / 'site' / 'images' / work_id collation_area = args.destdir / 'site' / 'images'
if collation_dir.exists(): collation_area.mkdir(parents=True, exist_ok=True)
if len(list(collation_dir.iterdir())) > 0:
work_collation_dir = collation_area / work_id
if work_collation_dir.exists():
if len(list(work_collation_dir.iterdir())) > 0:
print(f'Collation directory already exists!') print(f'Collation directory already exists!')
return return
else: else:
collation_dir.rmdir() work_collation_dir.rmdir()
nonexistent = [path for group in (groups + [exclusions]) for path in group if not path.exists()] nonexistent = [path for group in (groups + [exclusions]) for path in group if not path.exists()]
if len(nonexistent) > 0: if len(nonexistent) > 0:
@ -637,7 +643,7 @@ def manual_collate(args):
if pages_collated: if pages_collated:
print(f'Collated {pages_collated} pages for {work_id}') print(f'Collated {pages_collated} pages for {work_id}')
work_staging_dir.rename(collation_dir) work_staging_dir.rename(work_collation_dir)
else: else:
for f in work_staging_dir.iterdir(): for f in work_staging_dir.iterdir():
f.unlink() f.unlink()

View file

@ -8,6 +8,8 @@ html, body {
#controls { #controls {
opacity: 0.8; opacity: 0.8;
animation: 2s linear forwards fade; animation: 2s linear forwards fade;
position: relative;
z-index: 300;
} }
@keyframes fade { @keyframes fade {
@ -62,20 +64,28 @@ html, body {
bottom: 0px; bottom: 0px;
} }
#viewer-images { .image-container img {
display: none; position: fixed;
} left: 0;
top: 0;
#image-container {
height: 100vh; height: 100vh;
width: 100vw; width: 100vw;
background-size: contain; object-fit: contain;
background-repeat: no-repeat; object-position: 50% 50%;
background-position: center; background-color: #111;
}
#current-image img {
z-index: 100;
}
#preload-images img {
z-index: 0;
} }
#page-num, #duration { #page-num, #duration {
position: fixed; position: fixed;
z-index: 200;
font-size: 14pt; font-size: 14pt;
top: 10px; top: 10px;
font-weight: bold; font-weight: bold;
@ -110,4 +120,5 @@ html, body {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
z-index: 400;
} }

View file

@ -1,31 +1,43 @@
const PROGRESS_UPDATE_INTERVAL = 50; const PRELOAD_BACKWARD = 2;
const PRELOAD_FORWARD = 8;
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const pages = Array.from(document.querySelectorAll('img.viewer-image')); const currentImage = document.getElementById('current-image');
const preloadImages = document.getElementById('preload-images');
let currentPage = parseInt(localStorage.getItem(`${WORK_ID}-currentPage`)) || 0; let currentPage = parseInt(localStorage.getItem(`${WORK_ID}-currentPage`)) || 0;
let duration = parseInt(localStorage.getItem(`${WORK_ID}-duration`)) || 10; let duration = parseInt(localStorage.getItem(`${WORK_ID}-duration`)) || 10;
let paused = true;
let interval;
let elapsed = 0;
let rtl = (localStorage.getItem(`${WORK_ID}-rtl`) !== "false"); let rtl = (localStorage.getItem(`${WORK_ID}-rtl`) !== "false");
let paused = true;
function startTimer() { let elapsed = 0;
if (interval) { let timerLastRun = null;
clearInterval(interval); let timerAnimationRequestID = null;
function requestTimer() {
timerAnimationRequestID = window.requestAnimationFrame(runTimer);
} }
interval = setInterval(
function () { function runTimer(now) {
if (paused) { if (paused) {
return; return;
} }
elapsed += PROGRESS_UPDATE_INTERVAL;
if (timerLastRun === null) {
elapsed = 0;
} else {
elapsed += now - timerLastRun;
}
timerLastRun = now;
if (elapsed >= duration*1000) { if (elapsed >= duration*1000) {
changePage(currentPage + 1); changePage(currentPage + 1);
elapsed = 0;
} }
updateBar(); updateBar();
},
PROGRESS_UPDATE_INTERVAL, requestTimer();
);
} }
const progressBar = document.getElementById('progress'); const progressBar = document.getElementById('progress');
@ -34,34 +46,54 @@ document.addEventListener('DOMContentLoaded', () => {
} }
function stopTimer() { function stopTimer() {
if (interval) { if (timerAnimationRequestID) {
clearInterval(interval); window.cancelAnimationFrame(timerAnimationRequestID);
interval = null; timerAnimationRequestID = null;
} }
timerLastRun = null;
elapsed = 0; elapsed = 0;
updateBar(); updateBar();
} }
function imageSrc(s) {
const img = new Image();
img.src = s;
return img;
}
function preload() {
if (!currentImage.getElementsByTagName('img')[0].complete) {
setTimeout(preload, 50);
return;
}
preloadImages.replaceChildren(...(
IMAGES.slice(
Math.max(currentPage - PRELOAD_BACKWARD, 0),
currentPage + PRELOAD_FORWARD + 1,
).map(imageSrc)
));
}
function changePage(pageNum) { function changePage(pageNum) {
elapsed = 0; elapsed = 0;
updateBar();
const previous = pages[currentPage]; const previous = IMAGES[currentPage];
const current = pages[pageNum]; const current = IMAGES[pageNum];
if (current == null) { if (current == null) {
return; return;
} }
previous.classList.remove('current');
current.classList.add('current');
currentPage = pageNum; currentPage = pageNum;
localStorage.setItem(`${WORK_ID}-currentPage`, currentPage); localStorage.setItem(`${WORK_ID}-currentPage`, currentPage);
const display = document.getElementById('image-container'); currentImage.replaceChildren(imageSrc(current));
display.style.backgroundImage = `url("${current.src}")`;
document.getElementById('current-page').innerText = (pageNum + 1).toLocaleString(); document.getElementById('current-page').innerText = (pageNum + 1).toLocaleString();
setTimeout(preload, 1);
} }
const durationDisplay = document.getElementById('duration'); const durationDisplay = document.getElementById('duration');
@ -76,7 +108,7 @@ document.addEventListener('DOMContentLoaded', () => {
stopTimer(); stopTimer();
} else { } else {
durationDisplay.style.textDecoration = ""; durationDisplay.style.textDecoration = "";
startTimer(); requestTimer();
} }
} }
@ -102,7 +134,7 @@ document.addEventListener('DOMContentLoaded', () => {
function exitToWork() { function exitToWork() {
changeDuration(duration, true); changeDuration(duration, true);
if (currentPage === pages.length - 1) { if (currentPage === IMAGES.length - 1) {
localStorage.removeItem(`${WORK_ID}-currentPage`); localStorage.removeItem(`${WORK_ID}-currentPage`);
} }
window.location.href = `../${INDEX}`; window.location.href = `../${INDEX}`;

View file

@ -5,15 +5,15 @@
<script> <script>
const WORK_ID = "{{ work['id'] }}"; const WORK_ID = "{{ work['id'] }}";
const INDEX = "{{ index() }}"; const INDEX = "{{ index() }}";
const IMAGES = [
{% for filename in images %}
"{{ root() }}/images/{{ work['id'] }}/{{ filename }}",
{% endfor %}
];
</script> </script>
<script src="{{ root() }}/static/viewer.js"></script> <script src="{{ root() }}/static/viewer.js"></script>
{% endblock %} {% endblock %}
{% block body %} {% block body %}
<div id="viewer-images">
{% for filename in images %}
<img src="{{ root() }}/images/{{ work['id'] }}/{{ filename }}" class="viewer-image">
{% endfor %}
</div>
<div id="progress"></div> <div id="progress"></div>
<div id="page-num"> <div id="page-num">
<table> <table>
@ -46,5 +46,6 @@
</svg> </svg>
</div> </div>
</div> </div>
<div id="image-container"></div> <div class="image-container" id="current-image"></div>
<div class="image-container" id="preload-images"></div>
{% endblock %} {% endblock %}