An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
fix(skill): resume SCORM progress on books with their own progressKey
yzrd9f26e684f54
diff --git a/.claude/skills/papermorph/assets/scorm/scorm-bridge.js b/.claude/skills/papermorph/assets/scorm/scorm-bridge.jsindex cad8342..61919bd 100644--- a/.claude/skills/papermorph/assets/scorm/scorm-bridge.js+++ b/.claude/skills/papermorph/assets/scorm/scorm-bridge.js@@ -9,9 +9,10 @@// 1. Seed the book's own progress store from the LMS, so the contents page and the chapter// see the learner's saved checkmarks. This file sits in the book folder, the same folder the default key names;- // in a chapter, the engine's own key (BOOK_PROGRESS_KEY, which honours lib/book.css --progress-key) wins.+ // in a chapter, the engine's own key (BOOK_PROGRESS_KEY, which honours lib/book.css --progress-key) wins;+ // on the contents page, the progressKey the page passes to Contents.book(), which scorm.py reads at build time.const KEY = typeof BOOK_PROGRESS_KEY === 'string' ? BOOK_PROGRESS_KEY- : 'animebook:progress:' + new URL('.', document.currentScript.src).pathname;+ : host.progressKey || 'animebook:progress:' + new URL('.', document.currentScript.src).pathname;try { localStorage.setItem(KEY, JSON.stringify(host.progress())); } catch {}// 2. In a chapter, every progress change and every finish goes to the host as well.diff --git a/.claude/skills/papermorph/assets/scorm/scorm-host.js b/.claude/skills/papermorph/assets/scorm/scorm-host.jsindex bd00d9d..7ed36ed 100644--- a/.claude/skills/papermorph/assets/scorm/scorm-host.js+++ b/.claude/skills/papermorph/assets/scorm/scorm-host.js@@ -128,6 +128,7 @@/* ---------- the interface book pages use ---------- */window.PapermorphSCORM = {live,+ progressKey: CFG.progressKey, // the contents page's own key, when the book sets one// A copy of {done, last}, in the shape the book's own progress() works on.progress: () => ({ done: S.done.slice(), last: S.last }),// The book changed its progress (opened or finished a chapter).diff --git a/.claude/skills/papermorph/assets/scorm/test/check_scorm.py b/.claude/skills/papermorph/assets/scorm/test/check_scorm.pyindex e7241d1..5c72621 100644--- a/.claude/skills/papermorph/assets/scorm/test/check_scorm.py+++ b/.claude/skills/papermorph/assets/scorm/test/check_scorm.py@@ -6,8 +6,8 @@No server is needed: the check answers every request itself from the zip and mock-lms.html, and, as many LMS fileservers do, returns 404 for folder URLs. It checks that the session opens, that a chapter card opens its lesson-(folder links rewritten), that reaching the finish card reports the chapter to the LMS, and that a reload resumes-with the chapter's checkmark. No files are generated.+(folder links rewritten), that reaching the finish card reports the chapter to the LMS, and that a reload with+the book's localStorage cleared resumes with the chapter's checkmark. No files are generated."""import asyncioimport json@@ -77,6 +77,8 @@ async def main(zpath):assert cmi.get(status) == "completed", f"objective 0: {cmi.get(status)!r}"print(f"PASS finish card reported: suspend_data {cmi['cmi.suspend_data']}, objective 0 completed")+ # Resume must come from the LMS alone, as on another device: clear the book's localStorage first.+ await page.evaluate("document.getElementById('sco').contentWindow.document.getElementById('book').contentWindow.localStorage.clear()")await page.goto(f"{ORIGIN}/mock-lms.html?pkg=pkg&v={version}")await book().locator(f"#ch{first:02d}.done").wait_for(state="attached", timeout=10000)print("PASS resume: the chapter's checkmark is back after a reload")diff --git a/.claude/skills/papermorph/scripts/scorm.py b/.claude/skills/papermorph/scripts/scorm.pyindex 5e5bbdb..36ce6f4 100644--- a/.claude/skills/papermorph/scripts/scorm.py+++ b/.claude/skills/papermorph/scripts/scorm.py@@ -67,6 +67,12 @@ def outside(site: Path, rel: str, html: str):return out+def progress_key(site: Path):+ """The progressKey the contents page passes to Contents.book(), if any (an older book's own localStorage key)."""+ m = re.search(r'progressKey:\s*(["\'])(.*?)\1', (site / 'index.html').read_text(encoding='utf-8'))+ return m.group(2) if m else None++def book_title(site: Path):m = re.search(r'<title>(.*?)</title>', (site / 'index.html').read_text(encoding='utf-8'), re.S)return m.group(1).strip() if m else site.name@@ -192,7 +198,8 @@ def main():files['book/' + rel] = datafiles['book/' + BRIDGE] = (RUNTIME / BRIDGE).read_bytes()files['scorm-host.js'] = (RUNTIME / 'scorm-host.js').read_bytes()- cfg = {'book': slug, 'title': title, 'version': a.version, 'mastery': a.mastery, 'chapters': chs}+ cfg = {'book': slug, 'title': title, 'version': a.version, 'mastery': a.mastery, 'chapters': chs,+ 'progressKey': progress_key(site)}launch = (RUNTIME / 'launch.html').read_text(encoding='utf-8')config = json.dumps(cfg, ensure_ascii=False).replace('<', chr(92) + 'u003c') # no '</script>' inside the scriptlaunch = launch.replace('__TITLE__', escape(title)).replace('__CONFIG__', config)