Skip to content

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

feat(engine): tapWords side option puts a word above, below, left or right

yzre70a57ab2a46
diff --git a/.claude/skills/papermorph/references/picture-books/stories.md b/.claude/skills/papermorph/references/picture-books/stories.md
index c1097d3..f9761b5 100644
--- a/.claude/skills/papermorph/references/picture-books/stories.md
+++ b/.claude/skills/papermorph/references/picture-books/stories.md
@@ -122,7 +122,7 @@ function scene4w(p, D) {
['scene4w', 'In the woods', (m, D) => scene4w(panel(0), D), { lead: false, pre: PRE4W, ask: done => tapWords(WOODS, done) }],
```
-Once the prompt's narration is over the things turn tappable, each with a hit box at least 120 px square (a child's finger on a phone; smaller boxes lie on top of bigger ones) that follows its thing every frame, so a target may be a puppet that walks about or a bird that flies. A tap hops the thing (the hop adds to the transform the scene sets every frame, so a prop or puppet posed every frame hops in place), shows its word beside it, above where there is room, and says the word with the music ducked; tapping again says it again. A counter and Continue (Enter) wait in the corner, and Continue lights up with a short praise once every thing has been heard; the child can go on at any time. ← and → move between the things and Enter or Space taps, and each thing is named by its word for a screen reader. While the page waits, the scene's `stopClock` runs on past the beat's end, so pose the puppets as a function of `q` that keeps living there: a breath, a blink every few seconds, a glance. A book with its own early-reader typeface sets `--word-font` in `lib/book.css`.
+Once the prompt's narration is over the things turn tappable, each with a hit box at least 120 px square (a child's finger on a phone; smaller boxes lie on top of bigger ones) that follows its thing every frame, so a target may be a puppet that walks about or a bird that flies. A tap hops the thing (the hop adds to the transform the scene sets every frame, so a prop or puppet posed every frame hops in place), shows its word beside it, above where there is room, and says the word with the music ducked; tapping again says it again. Where the word would cover something the child should see, a face above the basket Red holds, give the thing a side: `{ g: basket, word: 'basket', side: 'below' }` (or `'left'`, `'right'`, `'above'`), and the word goes there, kept on the stage. A counter and Continue (Enter) wait in the corner, and Continue lights up with a short praise once every thing has been heard; the child can go on at any time. ← and → move between the things and Enter or Space taps, and each thing is named by its word for a screen reader. While the page waits, the scene's `stopClock` runs on past the beat's end, so pose the puppets as a function of `q` that keeps living there: a breath, a blink every few seconds, a glance. A book with its own early-reader typeface sets `--word-font` in `lib/book.css`.
**The word clips** are plain narration entries, voiced by `tts.py` with the rest and in the same voice: `"w-basket": "basket"` in `narration.<lang>.json` makes `audio/<lang>/w-basket.mp3`. A thing's clip is `'w-' + its word` (lower case, spaces as hyphens: *ice cream* says `w-ice-cream`); `clip: 'w-red'` names another. They stay out of `join.py`'s list, since each plays alone; run `level.py` on them with the other clips.
diff --git a/engine/check_tapwords.py b/engine/check_tapwords.py
index ec6fbe9..30236a6 100644
--- a/engine/check_tapwords.py
+++ b/engine/check_tapwords.py
@@ -39,7 +39,7 @@ function picture(p, D) {
mk('rect', { width: 80, height: 60, fill: '#86c9e8' }, cup);
clockRun(t => cup.setAttribute('transform', `translate(${(1300 + t * 20).toFixed(1)} 40)`), D, { tail: true });
const box = mk('rect', { x: 1380, y: 795, width: 40, height: 20, fill: '#9aaba3' }, p); // under the counter's card
- THINGS = [{ g: ball, word: 'ball' }, { g: tree, word: 'tree' }, { g: bee, word: 'bee', clip: 'w-bee-2' }, { g: cup, word: 'Ice cream' },
+ THINGS = [{ g: ball, word: 'ball', side: 'right' }, { g: tree, word: 'tree' }, { g: bee, word: 'bee', clip: 'w-bee-2', side: 'top' }, { g: cup, word: 'Ice cream' },
{ g: box, word: 'box' }, { g: tree, word: '' }, { g: document.createElementNS(NS, 'g'), word: 'ghost' }];
}
music('audio/bgm/m.mp3', ['q', 'after', 'end'], .5);
@@ -121,7 +121,7 @@ async def main():
assert "w-ball.mp3" in await js("PLAYED"), "the word was not said"
assert await js("THINGS[0].g.getAnimations().length") > 0, "the thing did not hop"
assert await js("""(() => { const a = document.querySelector('#ui .card.word').getBoundingClientRect(), b = THINGS[0].g.getBoundingClientRect();
- return a.right <= b.left || a.left >= b.right || a.bottom <= b.top || a.top >= b.bottom; })()"""), "the word covers the thing"
+ return a.left >= b.right; })()"""), "the word is not right of the thing (side: 'right')"
await page.wait_for_timeout(250)
assert await js("SND.duck") < .5, "the music did not duck under the word"
await tap_at("THINGS[2].g") # the bee, in front of the tree: the smaller box is on top
@@ -132,7 +132,7 @@ async def main():
return a.top >= b.bottom; })()"""), "a thing at the top did not get its word below"
await tap_at("THINGS[0].g") # again: says it again, counts once
assert await js("PLAYED.at(-1)") == "w-ball.mp3" and await js(count) == "3 / 5"
- print("PASS taps: motion runs on while waiting, hit boxes follow, word beside the thing, clip played, music ducked, hop, smaller thing on top, a second tap says it again")
+ print("PASS taps: motion runs on while waiting, hit boxes follow, word on its side of the thing, clip played, music ducked, hop, smaller thing on top, a second tap says it again")
await page.keyboard.press("ArrowRight") # left to right: ball, tree, bee, ice cream, box
await page.keyboard.press("ArrowRight")
@@ -159,9 +159,9 @@ async def main():
await page.wait_for_timeout(300)
for w in ('a thing has no word', '"ghost" is not an element on the stage', '"Ice cream" has no clip at audio/en/w-ice-cream.mp3',
- '"box" cannot be tapped: <'):
+ '"box" cannot be tapped: <', '"bee" has side "top"'):
assert any(w in x for x in warnings), f"no warning: {w}\n{warnings}"
- print("PASS warnings: no word, not on the stage, missing clip, covered by the counter")
+ print("PASS warnings: no word, not on the stage, missing clip, covered by the counter, unknown side")
await js("seek(1, false)")
await page.wait_for_timeout(100)
diff --git a/engine/engine.js b/engine/engine.js
index 692629b..f36ec13 100644
--- a/engine/engine.js
+++ b/engine/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/elementary-algebra/lib/engine.js b/site/elementary-algebra/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/elementary-algebra/lib/engine.js
+++ b/site/elementary-algebra/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/joke-collection/lib/engine.js b/site/joke-collection/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/joke-collection/lib/engine.js
+++ b/site/joke-collection/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/little-red-riding-hood/lib/engine.js b/site/little-red-riding-hood/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/little-red-riding-hood/lib/engine.js
+++ b/site/little-red-riding-hood/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/madness-shorts/lib/engine.js b/site/madness-shorts/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/madness-shorts/lib/engine.js
+++ b/site/madness-shorts/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/madness/lib/engine.js b/site/madness/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/madness/lib/engine.js
+++ b/site/madness/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/math-notebook/lib/engine.js b/site/math-notebook/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/math-notebook/lib/engine.js
+++ b/site/math-notebook/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/pandemic-shorts/lib/engine.js b/site/pandemic-shorts/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/pandemic-shorts/lib/engine.js
+++ b/site/pandemic-shorts/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/pandemic/lib/engine.js b/site/pandemic/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/pandemic/lib/engine.js
+++ b/site/pandemic/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/physics-notebook/lib/engine.js b/site/physics-notebook/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/physics-notebook/lib/engine.js
+++ b/site/physics-notebook/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/science/lib/engine.js b/site/science/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/science/lib/engine.js
+++ b/site/science/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/shooting-an-elephant/lib/engine.js b/site/shooting-an-elephant/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/shooting-an-elephant/lib/engine.js
+++ b/site/shooting-an-elephant/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();
diff --git a/site/three-little-pigs/lib/engine.js b/site/three-little-pigs/lib/engine.js
index 692629b..f36ec13 100644
--- a/site/three-little-pigs/lib/engine.js
+++ b/site/three-little-pigs/lib/engine.js
@@ -1028,9 +1028,10 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
};
/* ---------- point and read ---------- */
// A picture book's point-and-read moment, for young children learning words: a film's ask beat (CHAPTER.film),
-// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket' }]
+// ask: done => tapWords(THINGS, done) THINGS = [{ g, word: 'basket', clip: 'w-basket', side: 'below' }]
// which the scene fills as it builds the picture; g is what the reader taps (a puppet, a prop, or a transparent shape
-// over part of a baked set) and clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default. Once the narration is
+// over part of a baked set), clip names audio/<lang>/<clip>.mp3, 'w-' + the word by default, and side puts the word
+// 'above', 'below', 'left' or 'right' of its thing (kept on the stage); without it the word goes above, or wherever fits. Once the narration is
// over (P.waiting) every thing turns tappable: a tap hops it, shows its word in large letters beside it and says it, on
// wall time at the player volume with the music ducked under it; tapping again says it again. A counter and Continue
// (Enter) wait in the corner; Continue lights up once every thing has been heard. Seeking or replaying clears it all.
@@ -1038,6 +1039,7 @@ const pickEls = (items, right, yes, no, onRight) => (body, api) => {
// end on wall time, so puppets posed as a function of time keep breathing and blinking.
// The video (export.py) cannot tap: P.tapDemo.at(s) shows the words one by one, DEMO_STEP s apart, while it holds.
const TAP_MIN = 120, DEMO_STEP = 2; // TAP_MIN: the smallest hit box in stage px, a child's finger on a phone
+const SIDES = { above: 0, below: 1, right: 2, left: 3 }; // where a word goes, in the order tried
const wordClip = word => 'w-' + word.toLowerCase().trim().replace(/[^\p{L}\p{N}]+/gu, '-').replace(/^-+|-+$/g, '');
function tapWords(things, done) {
const gen = P.gen, stage = $('stage'), lang = CHAPTER.language || 'en';
@@ -1050,7 +1052,8 @@ function tapWords(things, done) {
const clip = t.clip || wordClip(t.word), a = new Audio(`audio/${lang}/${clip}.mp3`);
a.preload = 'auto';
a.onerror = () => console.warn(`tapWords: "${t.word}" has no clip at audio/${lang}/${clip}.mp3`);
- return { g: t.g, word: t.word, clip, a, heard: false };
+ if (t.side && !Object.hasOwn(SIDES, t.side)) console.warn(`tapWords: "${t.word}" has side "${t.side}": use above, below, left or right; its word goes where it fits`);
+ return { g: t.g, word: t.word, clip, a, side: Object.hasOwn(SIDES, t.side ?? '') ? t.side : null, heard: false };
});
const L = mk('g', { class: 'tapw' }, stage); // the hit boxes, over the whole picture
let on = false, alive = true, finished = false, word = null, shown = -1, bar, count, go;
@@ -1075,8 +1078,8 @@ function tapWords(things, done) {
const n = list.filter(x => x.heard).length, all = n === list.length;
count.textContent = all ? translate('allWordsHeard') : translate('wordsHeard', { k: n, n: list.length });
if (all && !go.classList.contains('go')) { go.className = 'btn go'; bar.classList.add('lit'); }
- // the word beside the thing: above it, else below, right or left, wherever it fits on the stage (slid along that
- // side to stay on it)
+ // the word beside the thing: on its side, or above it, else below, right or left, wherever it fits on the stage
+ // (slid along that side to stay on it)
word?.remove();
word = h('div', 'card word', t.word);
word.setAttribute('aria-hidden', 'true'); // the thing's own label already says the word
@@ -1084,7 +1087,7 @@ function tapWords(things, done) {
// gap: clear of the thing's hop; m: the stage's margin
const b = box(t), w = word.offsetWidth, hh = word.offsetHeight, gap = 30, m = 16, cx = b.x + (b.w - w) / 2, cy = b.y + (b.h - hh) / 2;
const spots = [[cx, b.y - hh - gap], [cx, b.y + b.h + gap], [b.x + b.w + gap, cy], [b.x - w - gap, cy]];
- const [x, y] = spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
+ const [x, y] = t.side ? spots[SIDES[t.side]] : spots.find(([x, y], k) => k < 2 ? y >= m && y + hh <= SH - m : x >= m && x + w <= SW - m) || spots[0];
Object.assign(word.style, { left: Math.max(m, Math.min(SW - m - w, x)) + 'px', top: Math.max(m, Math.min(SH - m - hh, y)) + 'px' });
if (quiet) { word.style.animation = go.style.animation = 'none'; return; } // a video's frame shows it at rest
for (const x of list) if (x !== t) x.a.pause();