Skip to content

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

fix(safe): rolling numbers count; SKILL.md scripts table names check.py and each package

yzrb07f9e53d73b
diff --git a/.claude/skills/papermorph/SKILL.md b/.claude/skills/papermorph/SKILL.md
index ebffd6f..2e9cbdd 100644
--- a/.claude/skills/papermorph/SKILL.md
+++ b/.claude/skills/papermorph/SKILL.md
@@ -96,17 +96,17 @@ Start with the questions in [shorts.md](references/shorts.md#questions-for-the-u
## Scripts
-All in `SKILL/scripts/`; each prints its usage with `--help` (run it with the `uv run --with …` its docstring names).
+All in `SKILL/scripts/`; each prints its usage with `--help`, run with the `uv run --with …` its docstring names (its first lines; without its packages even `--help` stops on the import). Packages: playwright for every script that opens a page (shot, strip, still, check, perf, safe, export, music, playlog, overlap, check_blank, bake_sets, bake_puppets), pillow for the ones that write pictures (shot, strip, still, playlog, bake_*, prep, frames, painted, sprites, trace), numpy for strip, export, `music.py gaps`, prep, frames, sfx and eleven, faster-whisper for eleven, pymupdf for outline and split_pages, scikit-image for trace, edge-tts or kokoro for tts; the rest need only Python and ffmpeg.
| For | Scripts |
|---|---|
-| Every book | `serve.py` preview without caching · `engine.py` sync the engine into books · `tts.py` narration and word times · `lint.py` static checks · `shot.py` beat screenshots · `strip.py` storyboard sheets and motion strips · `still.py` stretches where nothing moves · `perf.py` Firefox frame times · `export.py` MP4 and `.srt` · `level.py` even loudness |
+| Every book | `serve.py` preview without caching · `engine.py` sync the engine into books · `tts.py` narration and word times · `lint.py` static checks · `check.py` page errors, console warnings and beat lengths in Chromium and Firefox · `shot.py` beat screenshots · `strip.py` storyboard sheets and motion strips · `still.py` stretches where nothing moves · `perf.py` Firefox frame times, with the machine's load and a reference moment · `export.py` MP4 and `.srt` · `level.py` even loudness |
| Lessons | `outline.py` and `split_pages.py` page map and chapter text · `check_blank.py` empty openings · `overlap.py` arrows through text · `sprites.py` image processing steps |
| Picture books | `mouths.py` mouth shapes · `join.py` one clip per scene · `sfx.py` synthesized effects · `playlog.py` sounds and captions against the picture · `bake_sets.py` set layers · `bake_puppets.py` puppet bitmaps · `paint.py` / `paint_openai.py` image-model pictures · `painted.py` place them in the book |
-| Documentaries | `commons.py` public-domain pictures and recordings with their licences · `prep.py` print and line treatments · `trace.py` drawings that draw themselves on · `video.py` a clip from a still · `frames.py` a clip as treated frames · `eleven.py` ElevenLabs narration with word times · `music.py` a music track cut to the film, and the bed in the voice's gaps · `safe.py` words outside an upright film's safe area |
+| Documentaries | `commons.py` public-domain pictures and recordings with their licences · `prep.py` print and line treatments · `trace.py` drawings that draw themselves on · `video.py` a clip from a still · `frames.py` a clip as treated frames · `eleven.py` ElevenLabs narration with word times and `--tempo` · `music.py` a music track cut to the film, and the bed in the voice's gaps and at the end · `safe.py` words outside an upright film's safe area |
| Course options | `refs.py` verified citations · `items.py` question bank · `scorm.py` LMS package |
-`silence.py`, `ledger.py` and `browsers.py` are helpers the others import.
+`silence.py`, `ledger.py` (the one cost ledger: date, chapter, file, model, what, cost) and `browsers.py` are helpers the others import.
## Context
diff --git a/.claude/skills/papermorph/scripts/safe.py b/.claude/skills/papermorph/scripts/safe.py
index 2829ed5..71de697 100644
--- a/.claude/skills/papermorph/scripts/safe.py
+++ b/.claude/skills/papermorph/scripts/safe.py
@@ -5,7 +5,8 @@
Samples every beat every --step s on the beat clock (as strip.py sets it) and lists each text seen outside x 50-810,
y 130-1290 of the 900 x 1600 stage in two samples running (a word sliding through the edge in one frame is not
-listed), once per beat with the first time it was out and its box. The box is the text's outline without its stroke,
+listed; a number rolling in place, counter() or a rolled figure, is, though its text changes from sample to sample),
+once per text per beat with the first time it was out and its box. The beat's last frame is always sampled. The box is the text's outline without its stroke,
with the top and bottom 20 % of its height trimmed (capitals fill about the middle 60 % of a font's height); a text
counts when its opacity, with all its parents', is over 0.5. --query adds to the page's query (tags: the source and
AI tags shown, as export.py shows them on an upright film). Exits 1 when any word is out, so a script can rely on it.
@@ -16,12 +17,14 @@ from browsers import answers, exe
BOX = (50, 810, 130, 1290) # x0, x1, y0, y1 on the 900 x 1600 stage
JS = """([x0, x1, y0, y1]) => { const st = document.getElementById('stage'), r = st.getBoundingClientRect(), k = SW / r.width, out = [];
+ const ids = window.__safeIds = window.__safeIds || new WeakMap(); // each text element's number, to follow it across samples
for (const e of st.querySelectorAll('text')) {
+ if (!ids.has(e)) ids.set(e, ids.size = (ids.size || 0) + 1);
let o = 1; for (let n = e; n && n !== st; n = n.parentElement) o *= +getComputedStyle(n).opacity;
if (o < .5 || !e.textContent.trim()) continue;
const b = e.getBoundingClientRect(); if (b.width < 1) continue; // in a panel not shown
const l = (b.left - r.left) * k, rt = (b.right - r.left) * k, t = (b.top - r.top) * k, bt = (b.bottom - r.top) * k, h = bt - t;
- if (l < x0 || rt > x1 || t + .2 * h < y0 || bt - .2 * h > y1) out.push(`${e.textContent.trim()} [${l|0}-${rt|0}, ${t|0}-${bt|0}]`);
+ if (l < x0 || rt > x1 || t + .2 * h < y0 || bt - .2 * h > y1) out.push([ids.get(e), e.textContent.trim(), `[${l|0}-${rt|0}, ${t|0}-${bt|0}]`]);
} return out; }"""
@@ -39,12 +42,13 @@ async def main(a):
for i in range(n):
await pg.goto(f"{url}?{q}beat={i}&t=0"); await pg.wait_for_timeout(300)
bid, end = await pg.evaluate("[BEATS[P.i].id, P.end]")
- prev, seen, t = set(), {}, 0.0
- while t < end:
+ prev, seen = {}, {}
+ for t in [k * a.step for k in range(int((end - .05) / a.step) + 1)] + [end - .05]:
await pg.evaluate(f"P.t = {t}; evalTo({t})")
- cur = set(await pg.evaluate(JS, BOX))
- for s in cur & prev: seen.setdefault(s.split(" [")[0], (round(t, 2), s))
- prev, t = cur, t + a.step
+ cur = {i: (text, box) for i, text, box in await pg.evaluate(JS, BOX)}
+ for i, (text, box) in cur.items(): # out twice running: still in place, or a number rolling in place
+ if i in prev and (prev[i][1] == box or prev[i][0] != text): seen.setdefault(i, (round(t, 2), f"{text} {box}"))
+ prev = cur
for t, s in seen.values(): print(f"{bid:10s} t={t:5.2f} {s}"); bad += 1
await b.close()
print(bad, "words outside the safe box x %d-%d, y %d-%d" % BOX)