Add WebGL page cache and runtime checks

This commit is contained in:
2026-06-08 14:39:42 +02:00
parent 119cefd4bd
commit a73dc5725f
11 changed files with 891 additions and 32 deletions
+43 -2
View File
@@ -70,6 +70,7 @@ class UIDisplayHandlerModule extends BaseModule {
'renderSentence',
'isWebGLMode',
'prepareWebGLBookReveal',
'waitForWebGLPageFlip',
'renderStoryBlock',
'prepareRenderableBlock',
'prepareTextRenderable',
@@ -1054,8 +1055,22 @@ class UIDisplayHandlerModule extends BaseModule {
|| { wordTimings: [], cueTimings: [], totalDuration: 0 };
}
let preparedSpread = null;
if (typeof bookPagination.preparePendingBlock === 'function') {
await bookPagination.preparePendingBlock(sentence);
const currentSpreadIndex = Math.max(0, Number(bookPagination.currentSpreadIndex || 0));
const previewSpread = sentence.webglBookPresentation?.spread || await bookPagination.preparePendingBlock(sentence, {
activate: false,
publish: false,
includeUnrenderedHistory: true
});
if (Number(previewSpread?.index || 0) > currentSpreadIndex) {
await this.waitForWebGLPageFlip({
direction: 1,
reason: 'pending-block-overflow',
targetSpread: previewSpread.index
});
}
preparedSpread = await bookPagination.preparePendingBlock(sentence);
} else {
document.dispatchEvent(new CustomEvent('book-pagination:prepare-block', {
detail: {
@@ -1069,7 +1084,8 @@ class UIDisplayHandlerModule extends BaseModule {
blockId: sentence.blockId,
wordTimings: sentence.animation?.wordTimings || [],
cueTimings: sentence.animation?.cueTimings || [],
totalDuration: sentence.animation?.totalDuration || 0
totalDuration: sentence.animation?.totalDuration || 0,
spread: preparedSpread
};
if (typeof bookTextureRenderer.prepareRevealBlock === 'function') {
bookTextureRenderer.prepareRevealBlock(revealDetail);
@@ -1080,6 +1096,31 @@ class UIDisplayHandlerModule extends BaseModule {
}
}
waitForWebGLPageFlip(detail = {}) {
return new Promise((resolve) => {
let resolved = false;
const finish = () => {
if (resolved) return;
resolved = true;
window.clearTimeout(timeout);
document.removeEventListener('webgl-book:page-flip-finished', finish);
resolve(true);
};
const timeout = window.setTimeout(finish, 1400);
document.addEventListener('webgl-book:page-flip-finished', finish, { once: true });
document.dispatchEvent(new CustomEvent('webgl-book:request-page-flip', {
detail: {
direction: Math.sign(Number(detail.direction || 1)) || 1,
reason: detail.reason || 'pending-block-overflow',
force: true,
targetSpread: Number.isFinite(Number(detail.targetSpread))
? Math.max(0, Math.round(Number(detail.targetSpread)))
: null
}
}));
});
}
async rerenderStory() {
if (!this.paragraphContainer || this.renderedItems.length === 0) return;
console.log('UIDisplayHandler: Re-typesetting story after page resize');