An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
feat(science): ch09 chapter practice, finish card and contents page
yzrd20116e91a8b
diff --git a/site/science/ch09/audio/en/final1.mp3 b/site/science/ch09/audio/en/final1.mp3new file mode 100644index 0000000..5da0bf4Binary files /dev/null and b/site/science/ch09/audio/en/final1.mp3 differdiff --git a/site/science/ch09/audio/en/final2.mp3 b/site/science/ch09/audio/en/final2.mp3new file mode 100644index 0000000..2124b3fBinary files /dev/null and b/site/science/ch09/audio/en/final2.mp3 differdiff --git a/site/science/ch09/audio/en/finish.mp3 b/site/science/ch09/audio/en/finish.mp3new file mode 100644index 0000000..cb6a7f2Binary files /dev/null and b/site/science/ch09/audio/en/finish.mp3 differdiff --git a/site/science/ch09/index.html b/site/science/ch09/index.htmlindex 049b2ab..f4fae9a 100644--- a/site/science/ch09/index.html+++ b/site/science/ch09/index.html@@ -871,6 +871,36 @@ const BEATS = [});txt(p, 'Next: the chapter practice.', 800, 780, m('w4', 5), { size: 32, fill: COL.dim, weight: 500 });}],+/* ---------- chapter practice and finish (after the last section) ---------- */+['final1', 'Chapter practice: motion and speed', () => { panel(0); }, { ask: done => quiz(SCREEN, [+ { id: 'p-formula', prompt: ['What is the formula for ', h('b', '', 'speed'), '?'],+ build: choice([['distance ÷ time'], ['time ÷ distance'], ['distance × time']], 0,+ 'Speed is the distance traveled in a certain amount of time: distance ÷ time.',+ [null, 'That would give seconds per meter, not meters per second.', 'Speed divides the distance by the time; it does not multiply them.']) },+ { id: 'p-relative', prompt: ['Why is motion ', h('b', '', 'relative'), '?'],+ build: choice([['It is always described from a reference point.'], ['Everything moves at the same speed.'], ['Only things on Earth can move.']], 0,+ 'Motion is measured from a reference point, and different reference points can give different answers.',+ [null, 'Things move at many speeds; the point is that each speed is measured from something.', 'Earth itself moves. Motion is described from a reference point.']) },+ { id: 'p-bus', prompt: ['Sam sits on a bus driving at 40 kilometers per hour. Measured from the ', h('b', '', 'bus driver'), ', how fast is Sam moving?'],+ build: choice([['0 kilometers per hour'], ['40 kilometers per hour'], ['80 kilometers per hour']], 0,+ 'Sam and the driver ride together, so from the driver Sam stays put. From the road, Sam moves 40 kilometers per hour.',+ [null, 'That is Sam’s speed measured from the road, not from the driver.', 'Nothing adds up to 80 here. Sam rides along with the driver.']) },+ { id: 'p-cyclist', prompt: ['A cyclist rides 90 meters in 15 seconds. What is her speed?'],+ build: blanks([{ parts: ['speed = 90 ÷ 15 = ', { box: '6' }, ' meters per second'], why: '90 ÷ 15 = 6.', hint: 'Divide the distance by the time.' }]) },+], done, 'Chapter practice, set 1 of 2 · question') }], // the engine appends "k of n"+['final2', 'Chapter practice: velocity and acceleration', () => { panel(0); }, { ask: done => quiz(SCREEN, [+ { id: 'p-jog', prompt: ['A jogger runs at +3 meters per second, then turns around and jogs at the same pace. What is her new velocity?'],+ build: blanks([{ parts: ['velocity = ', { box: '-3' }, ' meters per second'], why: 'Same speed, opposite direction: the sign flips.', hint: 'The speed stays 3; the direction is opposite, so the sign changes.' }]) },+ { id: 'p-corner', prompt: ['A car drives around a corner at a steady 15 meters per second. Which is true?'],+ build: choice([['its speed changes'], ['its velocity changes'], ['neither changes']], 1,+ 'Its direction changes, so its velocity changes; the speed stays 15 meters per second.',+ ['It keeps a steady 15 meters per second.', null, 'Turning changes the direction, and velocity includes direction.']) },+ { id: 'p-acc', prompt: ['A car speeds up from 4 to 16 meters per second in 3 seconds. What is its acceleration?'],+ build: blanks([{ parts: ['acceleration = (16 − 4) ÷ 3 = ', { box: '4' }, ' meters per second squared'], why: '16 − 4 = 12, and 12 ÷ 3 = 4.', hint: 'Final velocity minus starting velocity, then divide by the time.' }]) },+ { id: 'p-dec', prompt: ['A bike slows down from 8 to 2 meters per second in 3 seconds. What is its acceleration?'],+ build: blanks([{ parts: ['acceleration = (2 − 8) ÷ 3 = ', { box: '-2' }, ' meters per second squared'], why: '2 − 8 = −6, and −6 ÷ 3 = −2: negative, because it slows down.', hint: 'Final minus starting velocity is negative here. Divide it by the time.' }]) },+], done, 'Chapter practice, set 2 of 2 · question') }],+['finish', 'Finished', () => { panel(0); }, { ask: finishCard }],].map(([id, title, run, extra]) => ({ id, title, run, ...extra }));boot();diff --git a/site/science/index.html b/site/science/index.htmlnew file mode 100644index 0000000..2a315b2--- /dev/null+++ b/site/science/index.html@@ -0,0 +1,320 @@+<!doctype html>+<html lang="en">+<head>+<meta charset="utf-8">+<meta name="viewport" content="width=device-width, initial-scale=1">+<script>+// Observe aborted incoming transitions before the first rendering opportunity.+addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));+</script>+<title>Ace Science · Physics</title>+<meta name="description" content="ONE SENTENCE ABOUT THE BOOK.">+<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='14' fill='%231d2b27'/%3E%3Ctext x='32' y='45' text-anchor='middle' font-size='48' fill='%23f0b45a'%3E∞%3C/text%3E%3C/svg%3E">+<script src="unit-art.js"></script>+<link rel="expect" href="#ch01" blocking="render">+<style>+:root {+ --page: #0f1613; --board: #1d2b27; --panel: #22322d; --edge: #3a5047;+ --chalk: #ece8dc; --dim: #9aaba3; --faint: #5d7068; --task: #f0b45a; --quiz: #86c9e8; --good: #8fd6b0;+ --ui: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;+ --book: "Iowan Old Style", Palatino, Georgia, serif;+ --ease: cubic-bezier(.2, .8, .2, 1);+ color-scheme: dark;+}+* { box-sizing: border-box; }+html { scroll-padding-top: 90px; }+body { margin: 0; min-height: 100svh; background: var(--board); color: var(--chalk); font: 18px/1.5 var(--ui); }+/* Chalkboard: the same grain and vignette as the lesson stage. */+body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;+ background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(0, 0, 0, .38)),+ url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 .92 0 0 0 0 .95 0 0 0 0 .9 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23g)'/%3E%3C/svg%3E"); }+a { color: inherit; }+a:focus-visible { outline: 3px solid var(--task); outline-offset: 3px; }+.kicker { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--quiz); }++/* ---------- cover ---------- */+#cover { position: relative; min-height: 100svh; display: flex; flex-direction: column; align-items: center; justify-content: center;+ padding: 48px 16px 64px; text-align: center; overflow: hidden; }+.open #cover, body:not(.open) #contents { display: none; }+#cover > * { animation: rise .8s var(--ease) backwards; }+#cover .mascot { animation: none; margin-bottom: 26px; view-transition-name: guide; }+#cover .kicker { animation-delay: .9s; }+#cover h1 { animation-delay: 1s; }+#cover .lede { animation-delay: 1.12s; }+#cover .acts { animation-delay: 1.24s; }+#cover .meta { animation-delay: 1.36s; }+h1 { margin: 14px 0 18px; font: 500 clamp(44px, 8.4vw, 92px)/1.02 var(--book); letter-spacing: -.01em; view-transition-name: book; }+h1 i { color: var(--task); font-style: italic; }+.lede { max-width: 34em; margin: 0 0 34px; color: var(--dim); font-size: clamp(17px, 2.2vw, 20px); text-wrap: balance; }+.acts { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }+.btn { display: inline-flex; align-items: center; gap: 12px; padding: 14px 30px; border-radius: 999px; font-weight: 600; font-size: 19px; text-decoration: none;+ transition: transform .25s var(--ease), background-color .25s, border-color .25s; }+.btn[hidden] { display: none; }+.btn:hover { transform: translateY(-2px); }+.btn.go { background: var(--chalk); color: var(--board); }+.btn.quiet { border: 1.5px solid var(--edge); color: var(--chalk); }+.btn.quiet:hover { border-color: var(--dim); }+.btn svg { width: 15px; height: 15px; fill: currentColor; }+.meta { margin: 30px 0 0; color: var(--faint); font-size: 15px; letter-spacing: .04em; }+/* Faint chalk notes around the edges of the board. */+.chalk { position: absolute; inset: 0; z-index: -1; pointer-events: none; animation: none !important; }+.chalk span { position: absolute; font: italic 400 clamp(22px, 3vw, 38px) var(--book); color: var(--chalk); opacity: 0; white-space: nowrap;+ animation: chalk 1.6s ease-out forwards, drift 14s ease-in-out infinite alternate; animation-delay: calc(var(--d) * 1s), calc(var(--d) * 1s); }+@keyframes chalk { to { opacity: .075; } }+@keyframes drift { to { translate: 0 -10px; } }+@keyframes rise { from { opacity: 0; transform: translateY(16px); } }++/* ---------- the guide: an infinity sign whose loops are its eyes ---------- */+.mascot { display: block; overflow: visible; }+.mascot .mbody { transform-box: view-box; transform-origin: 60px 46px; animation: bob 3.4s ease-in-out infinite; }+.mascot .pupil { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }+.mascot .joy { display: none; }+#cover:has(.go:hover, .go:focus-visible) .pupil { display: none; }+#cover:has(.go:hover, .go:focus-visible) .joy { display: inline; }+.draw .loop { stroke-dasharray: 1 1; animation: draw 1.3s cubic-bezier(.6, 0, .3, 1) .15s backwards; }+.draw .face { animation: pop .45s var(--ease) 1.25s backwards; }+@keyframes draw { from { stroke-dashoffset: 1; } }+@keyframes pop { from { opacity: 0; transform: scale(.6); } }+.draw .face { transform-box: view-box; transform-origin: 60px 44px; }+@keyframes bob { 50% { transform: translateY(-3px) rotate(-2deg); } }+@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }++/* ---------- contents ---------- */+.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 14px; padding: 12px max(16px, calc(50% - 590px));+ background: rgba(22, 33, 29, .86); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid #2a3b35; }+.home { display: flex; align-items: center; gap: 12px; text-decoration: none; border-radius: 10px; }+.home .mascot { view-transition-name: guide; }+.home strong { font: 500 22px/1.1 var(--book); view-transition-name: book; }+.home strong i { color: var(--task); }+.prog { margin-left: auto; color: var(--dim); font-size: 15px; white-space: nowrap; }+.prog b { color: var(--good); font-weight: 600; }+main#contents { padding-bottom: 80px; }+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }+.unit h2 { position: relative; display: flex; align-items: baseline; gap: 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }+.unit .grid { position: relative; }+/* Each unit header is a strip of chalkboard with a sketch of its mathematics, drawn in the unit colour. */+.unit::before { content: ""; position: absolute; inset: 0 16px auto; height: 208px; border-radius: 22px; pointer-events: none;+ background: radial-gradient(ellipse 46% 90% at 74% 55%, color-mix(in srgb, var(--c) 11%, transparent), transparent 70%); }+.unit-art { position: absolute; top: 20px; right: 28px; width: min(580px, 56%); height: auto; overflow: visible; pointer-events: none;+ color: var(--c); fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: .78; }+.unit-art text { fill: currentColor; stroke: none; font-family: var(--book); font-style: italic; }+.unit-art .a { color: var(--chalk); opacity: .55; }+.unit-art .faint { opacity: .22; }+.unit-art .d { stroke-dasharray: 1 1; stroke-dashoffset: 1; }+.unit-art .t { opacity: 0; }+.seen .unit-art .d { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards; animation-delay: calc(var(--k) * 55ms + 120ms); }+.seen .unit-art .t { animation: art-fade .6s ease-out forwards; animation-delay: calc(var(--k) * 55ms + 300ms); }+.seen .unit-art .a.t { animation-name: art-fade-a; }+@keyframes art-draw { to { stroke-dashoffset: 0; } }+@keyframes art-fade { to { opacity: 1; } }+@keyframes art-fade-a { to { opacity: .55; } }+/* After the drawing, each sketch keeps one small motion that belongs to its topic. */+.unit-art g { transform-box: fill-box; }+.seen .unit-art .swap-a { animation: swap-a 6s var(--ease) 2.4s infinite; }+.seen .unit-art .swap-b { animation: swap-b 6s var(--ease) 2.4s infinite; }+@keyframes swap-a { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(80px, 0); } 37% { transform: translate(40px, -30px); } 88% { transform: translate(40px, 30px); } }+@keyframes swap-b { 0%, 30%, 100% { transform: none; } 45%, 80% { transform: translate(-80px, 0); } 37% { transform: translate(-40px, 30px); } 88% { transform: translate(-40px, -30px); } }+.seen .unit-art .step { animation: art-fade .6s ease-out forwards, step 4s ease-in-out infinite; animation-delay: calc(var(--k) * 55ms + 300ms), calc(var(--k) * 300ms + 2s); }+@keyframes step { 0%, 20%, 100% { fill-opacity: 1; } 10% { fill-opacity: .3; } }+.unit-art .hop, .unit-art .ride { offset-rotate: 0deg; }+.seen .unit-art .hop { animation: art-fade .4s ease-out 2s forwards, along 3.4s linear 2s infinite; }+.seen .unit-art .ride { animation: art-fade .4s ease-out 2s forwards, along 4s ease-in-out 2s infinite alternate; }+@keyframes along { from { offset-distance: 0%; } to { offset-distance: 100%; } }+.unit-art .pie { stroke: currentColor; stroke-linecap: butt; stroke-dasharray: 0 100; }+.seen .unit-art .pie { animation: art-fade .4s ease-out 1.6s forwards, pie 5s var(--ease) 1.6s infinite; }+@keyframes pie { 0% { stroke-dasharray: 0 100; } 35%, 85% { stroke-dasharray: 25 100; } 100% { stroke-dasharray: 0 100; } }+.seen .unit-art .tilt { transform-box: view-box; transform-origin: 300px 72px; animation: tilt 4.8s ease-in-out 2s infinite; }+@keyframes tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-4deg); } 60% { transform: rotate(2deg); } }+.seen .unit-art .spin { transform-box: view-box; transform-origin: 320px 95px; animation: spin 5s cubic-bezier(.2, .7, .2, 1) 2s infinite; }+@keyframes spin { from { transform: rotate(0); } 70%, to { transform: rotate(1530deg); } }+.seen .unit-art .feed-in { animation: feed-in 4s ease-in-out 2s infinite; }+.seen .unit-art .feed-out { opacity: 0; animation: feed-out 4s ease-in-out 2s infinite; }+@keyframes feed-in { 0% { transform: none; opacity: 1; } 40% { transform: translate(100px, 0); opacity: 0; } 41%, 100% { transform: none; opacity: 0; } 95% { opacity: 1; } }+@keyframes feed-out { 0%, 45% { transform: translate(-40px, 0); opacity: 0; } 70%, 90% { transform: none; opacity: 1; } 100% { opacity: 0; } }+.unit-art .cell { opacity: .25; }+.seen .unit-art .cell { animation: cell 5s ease-in-out infinite; animation-delay: calc(var(--j) * .5s + 2s); }+@keyframes cell { 0%, 100% { opacity: .25; } 15%, 60% { opacity: 1; } }+.unit-art .cut, .unit-art .shade { opacity: 0; }+.seen .unit-art .cut { animation: cut 4s ease-in-out 2s infinite; }+@keyframes cut { 0%, 100% { opacity: 0; } 30%, 70% { opacity: .5; } }+.seen .unit-art .shade { animation: shade 1s ease-out 1.6s forwards; }+@keyframes shade { to { opacity: .14; } }+.seen .unit-art .diag { animation: art-draw 1.1s cubic-bezier(.5, 0, .3, 1) forwards, redraw 4s ease-in-out 2.5s infinite; }+@keyframes redraw { 0%, 15% { stroke-dashoffset: 1; } 50%, 100% { stroke-dashoffset: 0; } }+.seen .unit-art .root { animation: art-fade .4s ease-out 1.8s forwards, root 2.4s ease-in-out 2.2s infinite; }+@keyframes root { 0%, 100% { r: 7px; } 50% { r: 11px; } }+.seen .unit-art .breathe { transform-box: view-box; transform-origin: 380px 140px; animation: breathe 4s ease-in-out 2s infinite alternate; }+@keyframes breathe { from { transform: scaleY(1); } to { transform: scaleY(.35); } }+.unit h2 span { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }+.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); gap: 12px; }+.ch { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: 1fr auto; column-gap: 16px; row-gap: 8px; min-height: 112px;+ padding: 16px 18px 14px 16px; border-radius: 16px; background: var(--panel); border: 1.5px solid var(--edge); border-left: 6px solid var(--c);+ text-decoration: none; transition: transform .3s var(--ease), border-color .3s, box-shadow .3s; }+.ch:hover { transform: translateY(-3px); border-color: var(--c); box-shadow: 0 14px 34px rgba(0, 0, 0, .3); }+.ch b { grid-row: span 2; min-width: 1.15em; font: 500 42px/1 var(--book); color: var(--c); font-variant-numeric: lining-nums tabular-nums; }+.ch span { font-size: 18px; line-height: 1.3; }+.ch small { color: var(--dim); font-size: 14px; }+.ch.done small::before { content: "✓ Finished · "; color: var(--good); font-weight: 600; }+.ch.last small::after { content: " · Last opened"; color: var(--quiz); }+.ch.here:focus-visible { outline-color: var(--c); }+.ch.here { animation: here 1.8s ease-out .3s; }+@keyframes here { 0% { box-shadow: 0 0 0 0 var(--c); } 25% { box-shadow: 0 0 0 5px var(--c); } 100% { box-shadow: 0 0 0 14px transparent; } }+.stagger .top { animation: rise .6s var(--ease) backwards; }+.stagger .unit h2, .stagger .ch { animation: rise .6s var(--ease) backwards; animation-delay: calc(min(var(--i), 14) * 32ms + 80ms); }++/* ---------- page-to-page motion ---------- */+@view-transition { navigation: auto; }+::view-transition-group(*) { animation-duration: .5s; animation-timing-function: var(--ease); }+::view-transition-old(lesson), ::view-transition-new(lesson) { height: 100%; object-fit: cover; }+::view-transition-old(lesson) { animation-duration: .18s; }+@media (max-width: 560px) {+ .home strong { font-size: 18px; }+ #contents .top { flex-wrap: wrap; gap: 8px 12px; }+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }+ .unit h2 { min-height: 0; padding-top: 104px; }+ .ch { min-height: 0; }+ .chalk span:not(:nth-child(3), :nth-child(4), :nth-child(7)) { display: none; }+}+@media (prefers-reduced-motion: reduce) {+ *, *::before, ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; transition: none !important; }+ .unit-art .d { stroke-dashoffset: 0; }+ .unit-art .t, .unit-art .cell { opacity: 1; }+ .unit-art .a.t { opacity: .55; }+ .unit-art .shade { opacity: .14; }+ .unit-art .pie { stroke-dasharray: 25 100; }+ .chalk span { opacity: .075; }+}+</style>+</head>+<body>+<section id="cover">+ <div class="chalk" aria-hidden="true"><!-- a few faint formulas or phrases from the book, drawn in chalk -->+ <span style="left:7%;top:13%;--d:1.6">speed = distance ÷ time</span>+ <span style="right:8%;top:17%;--d:1.9">motion is relative</span>+ <span style="left:5%;bottom:20%;--d:2.2">+2 m/s → −2 m/s</span>+ <span style="right:6%;bottom:15%;--d:2.5">5 m/s²</span>+ </div>+ <svg class="mascot draw" id="guide" width="210" height="147"></svg>+ <p class="kicker">An animated science book · physics</p>+ <h1>Motion <i>&</i> Forces</h1>+ <p class="lede">The physics chapters of a middle-school science notebook, as short narrated animations with quick checks. Chapter 9, Motion, is ready.</p>+ <div class="acts">+ <a class="btn go" href="#contents">Open the book<svg viewBox="0 0 16 16"><path d="M6 2.5 11.5 8 6 13.5 4.6 12.1 8.7 8 4.6 3.9z"/></svg></a>+ <a class="btn quiet" id="resume" hidden></a>+ </div>+ <p class="meta" id="meta"></p>+</section>++<main id="contents">+ <header class="top">+ <a class="home" href="#book" aria-label="Back to the cover"><svg class="mascot" id="guideSmall" width="52" height="36"></svg><strong>Motion <i>&</i> Forces</strong></a>+ <span class="prog" id="prog"></span>+ </header>+ <div id="units"></div>+</main>++<script>+'use strict';+// Physics only: the book's chapters 9–17 (units 3–4) keep their original numbers. START gives the first unit and+// chapter numbers; chapters are numbered in order from there. Add a chapter here when its lesson is ready.+const START = { unit: 3, chapter: 9 };+const UNITS = [ // [unit title, [[chapter title, minutes], ...]]+ ['Motion, Forces, and Work', [['Motion', 18]]],+];+const HUES = ['#f4a48c', '#86c9e8', '#f3c95c', '#e8a0c8', '#8fd6b0', '#bba8ee', '#f0b45a'];+const id = n => 'ch' + String(n).padStart(2, '0');+let P = {};+const BOOK_PROGRESS_KEY = 'animebook:progress:' + new URL('.', location.href).pathname;+try {+ const saved = JSON.parse(localStorage.getItem(BOOK_PROGRESS_KEY) || '{}');+ if (saved && typeof saved === 'object' && !Array.isArray(saved)) P = saved;+} catch {}+const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger(n) && n > 0) : []);++// Contents.+let n = START.chapter - 1, total = 0, i = 0; // i staggers the entrance, in reading order+const esc = s => s.replace(/&/g, '&').replace(/</g, '<');+document.getElementById('units').innerHTML = UNITS.map(([name, chs], u) => {+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}"><svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${UNIT_ART[u] || ''}</svg><h2><span>Unit ${u + START.unit}</span>${esc(name)}</h2><div class="grid">` ++ chs.map(([t, min]) => { n++; total++;+ const cls = 'ch' + (done.has(n) ? ' done' : '') + (P.last === n ? ' last' : '');+ return `<a class="${cls}" id="${id(n)}" href="${id(n)}/" style="--i:${i++}"><b>${n}</b><span>${esc(t)}</span><small>${min} min</small></a>`;+ }).join('') + '</div></section>';+}).join('');+// A unit's sketch draws itself the first time the unit scrolls into view.+const seen = new IntersectionObserver(es => es.forEach(e => { if (e.isIntersecting) { e.target.classList.add('seen'); seen.unobserve(e.target); } }), { threshold: .25 });+document.querySelectorAll('.unit').forEach(u => seen.observe(u));+const finished = [...done].filter(k => k >= START.chapter && k <= n).length;+document.getElementById('prog').innerHTML = finished ? `<b>${finished}</b> of ${total} finished` : `${total} chapter${total === 1 ? '' : 's'}`;+const pl = (k, w) => `${k} ${w}${k === 1 ? '' : 's'}`;+document.getElementById('meta').textContent = `${pl(total, 'chapter')} · ${pl(UNITS.length, 'unit')} · with sound`;+const last = Number.isInteger(P.last) && document.getElementById(id(P.last));+if (last) {+ const r = document.getElementById('resume');+ r.hidden = false;+ r.href = last.getAttribute('href');+ r.textContent = `Continue · Chapter ${P.last}`;+}++// The guide, drawn the same way as in the lessons.+function lemniscate(cx, cy, a, k) {+ let d = '';+ for (let i = 0; i <= 96; i++) {+ const t = i / 96 * 2 * Math.PI, sn = Math.sin(t), q = 1 + sn * sn;+ d += (i ? 'L' : 'M') + (cx + a * Math.cos(t) / q).toFixed(1) + ' ' + (cy + k * a * sn * Math.cos(t) / q).toFixed(1);+ }+ return d + 'Z';+}+for (const svg of document.querySelectorAll('svg.mascot')) {+ svg.setAttribute('viewBox', '0 0 120 84');+ svg.setAttribute('aria-hidden', 'true');+ const ln = 'fill="none" stroke="#ece8dc" stroke-linecap="round" stroke-linejoin="round"';+ svg.innerHTML = `<g class="mbody"><path class="loop" pathLength="1" d="${lemniscate(60, 40, 52, 1.5)}" ${ln} stroke-width="6"/><g class="face">` ++ [33, 87].map(x => `<circle class="pupil" cx="${x}" cy="40" r="6.5" fill="#ece8dc"/><path class="joy" d="M${x - 7} 43Q${x} 32 ${x + 7} 43" ${ln} stroke-width="4"/>`).join('') ++ `<path d="M55 62Q60 67 65 62" ${ln} stroke-width="3.5"/></g></g>`;+}++// The cover and the contents share this page: no hash or #book shows the cover, #contents or #chNN the contents.+// Lessons link back with #chNN, so the reader lands on the chapter they just left.+const reduced = matchMedia('(prefers-reduced-motion: reduce)').matches;+function show(animate) {+ const open = location.hash.length > 1 && location.hash !== '#book';+ const apply = () => {+ document.body.classList.toggle('open', open);+ document.body.classList.toggle('stagger', animate && open);+ const here = open ? document.getElementById(location.hash.slice(1)) : null;+ document.querySelectorAll('.here').forEach(e => e.classList.remove('here'));+ if (here?.classList.contains('ch')) { here.scrollIntoView({ block: 'center' }); here.classList.add('here'); }+ else scrollTo(0, 0);+ if (animate) {+ const heading = document.querySelector(open ? '#contents .home' : '#cover h1');+ heading?.setAttribute('tabindex', '-1');+ heading?.focus({ preventScroll: true });+ }+ };+ if (animate && document.startViewTransition && !reduced) {+ const transition = document.startViewTransition(apply);+ // Navigation can interrupt either promise; the new view is already applied.+ transition.ready.catch(() => {});+ transition.finished.catch(() => {});+ } else apply();+}+addEventListener('hashchange', () => show(true));+show(false);++// Between pages, the chosen card grows into the lesson frame and the frame shrinks back into its card.+let named = null;+const name = el => {+ if (named) named.style.viewTransitionName = '';+ named = el;+ if (el) el.style.viewTransitionName = 'lesson';+};+document.addEventListener('click', e => { const a = e.target.closest('a[href^="ch"]'); if (a) name(a); });+addEventListener('pagereveal', e => {+ const target = (location.hash.length > 1 && document.getElementById(location.hash.slice(1))?.closest('.ch')) || (named?.offsetParent && named);+ name(e.viewTransition && target ? target : null);+ e.viewTransition?.finished.then(() => name(null), () => name(null));+});+</script>+</body>+</html>diff --git a/site/science/unit-art.js b/site/science/unit-art.jsnew file mode 100644index 0000000..a4cebf0--- /dev/null+++ b/site/science/unit-art.js@@ -0,0 +1,23 @@+// Chalk sketches for the unit headers on the contents page, one per unit, drawn in the unit's colour.+// Each entry is the inside of an SVG with viewBox 0 0 600 180; keep the left ~200 px light (the unit title sits there+// on narrow screens). Classes, styled in book.html:+// d a stroke that draws itself in when the unit scrolls into view (--k orders the strokes)+// t text or a filled shape that fades in+// a faint chalk white instead of the unit colour; faint even fainter+// A sketch may add one looping motion after it is drawn: give an element a class and add a .seen .unit-art .NAME+// rule with its keyframes in book.html (see the examples there: swap-a, hop, spin, tilt, breathe, ...).+'use strict';+(() => {+ let k = 0;+ const P = (d, cls = '', extra = '') => `<path class="d ${cls}" pathLength="1" style="--k:${k++}" d="${d}" ${extra}/>`;+ const Tx = (x, y, s, size = 24, cls = '', anchor = 'start') => `<text class="t ${cls}" style="--k:${k++}" x="${x}" y="${y}" font-size="${size}" text-anchor="${anchor}">${s}</text>`;+ const C = (cx, cy, r, cls = '') => `<circle class="d ${cls}" pathLength="1" style="--k:${k++}" cx="${cx}" cy="${cy}" r="${r}"/>`;+ const reset = s => { k = 0; return s; };++ window.UNIT_ART = [+ // Unit 3 (motion, forces, work): a road with a car-dot speeding along it, and speed = distance ÷ time.+ reset(P('M228 130H572') + Array.from({ length: 7 }, (_, i) => P(`M${250 + i * 50} 122v16`, 'a')).join('') ++ `<circle class="t hop" r="8" fill="currentColor" stroke="none" style="--k:${k++};offset-path:path('M250 116Q275 84 300 116Q325 84 350 116Q375 84 400 116')"/>` ++ Tx(250, 60, 'speed = distance ÷ time', 26) + P('M480 70h70m-14 -10l14 10l-14 10', 'a')),+ ];+})();