Skip to content

An AI skill that turns books into animated, narrated, interactive web experiences

feat(engine): captions that end with their words, and forced subtitles

yzr52bc471b3144
diff --git a/engine/engine.js b/engine/engine.js
index e026ca8..29630e7 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/joke-collection/lib/engine.js b/site/joke-collection/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/joke-collection/lib/engine.js
+++ b/site/joke-collection/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/little-red-riding-hood/lib/engine.js b/site/little-red-riding-hood/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/little-red-riding-hood/lib/engine.js
+++ b/site/little-red-riding-hood/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
index e026ca8..29630e7 100644
--- a/site/three-little-pigs/lib/engine.js
+++ b/site/three-little-pigs/lib/engine.js
@@ -1915,8 +1915,13 @@ function ui() {
if (step !== stepText) { stepText = step; $('stepName').textContent = step; }
const b = BEATS[P.i];
let text = '';
- if (captions && P.started && !b.ask && !P.done) {
- for (const [t, line] of TIMINGS[b.id].cues) { if (t + (b.pre || 0) > P.t + .05) break; text = line; }
+ if (P.started && !b.ask && !P.done) {
+ // a cue is [start, line], [start, line, end] or [start, line, end, 1]: with an end, the caption clears once its
+ // words are over; a 1 marks a line in another language, whose subtitle shows even with captions off
+ for (const [t, line, end, forced] of TIMINGS[b.id].cues) {
+ if (t + (b.pre || 0) > P.t + .05) break;
+ text = (captions || forced) && !(end != null && P.t > end + (b.pre || 0)) ? line : '';
+ }
}
if (text !== capText) { capText = text; $('caption').textContent = text; $('caption').hidden = !text; }
}