Skip to content

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

fix(site): wrap long unit titles and share unit headers via engine (#7)

TedKaczynskiaa532a4086f6
diff --git a/.claude/skills/papermorph/assets/templates/book.html b/.claude/skills/papermorph/assets/templates/book.html
index f186c35..9b34669 100644
--- a/.claude/skills/papermorph/assets/templates/book.html
+++ b/.claude/skills/papermorph/assets/templates/book.html
@@ -10,6 +10,8 @@ addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
<title>BOOK TITLE</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">
+<link rel="stylesheet" href="lib/units.css">
+<script src="lib/units.js"></script>
<script src="unit-art.js"></script>
<link rel="expect" href="#ch01" blocking="render">
<style>
@@ -89,63 +91,6 @@ h1 i { color: var(--task); font-style: italic; }
.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);
@@ -173,18 +118,11 @@ main#contents { padding-bottom: 80px; }
@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>
@@ -272,15 +210,14 @@ const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger
let n = START.chapter - 1, total = 0, i = 0; // i staggers the entrance, in reading order
const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
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>${translate('unit', { n: u + START.unit })}</span>${esc(name)}</h2><div class="grid">` +
+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}">${Units.header(u, translate('unit', { n: u + START.unit }), name)}<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>${translate('minutes', { n: 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));
+Units.watch();
const finished = [...done].filter(k => k >= START.chapter && k <= n).length;
document.getElementById('prog').innerHTML = finished ? translate('finished', { done: `<b>${finished}</b>`, n: total }) : translate('chapterCount', { n: total });
document.getElementById('meta').textContent = translate('meta', {
diff --git a/.claude/skills/papermorph/assets/templates/unit-art.js b/.claude/skills/papermorph/assets/templates/unit-art.js
index 67f3507..7a9038e 100644
--- a/.claude/skills/papermorph/assets/templates/unit-art.js
+++ b/.claude/skills/papermorph/assets/templates/unit-art.js
@@ -1,6 +1,6 @@
// 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:
+// on narrow screens). Classes, styled in lib/units.css:
// 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
diff --git a/.claude/skills/papermorph/references/site.md b/.claude/skills/papermorph/references/site.md
index 2f72892..5ab4959 100644
--- a/.claude/skills/papermorph/references/site.md
+++ b/.claude/skills/papermorph/references/site.md
@@ -40,7 +40,7 @@ One page: no hash or `#book` shows the cover, `#contents` or `#chNN` the content
## Unit sketches (`unit-art.js`)
-Give each unit a small sketch of its own ideas, drawn in the unit colour, with one gentle topic-related loop. Use the agreed asset approach. Keep the left third light for the title on phones; check the finished contents at 1440 px and 390 px once. The template handles reduced motion; classes and loop examples are in `unit-art.js` and the `.unit-art` CSS.
+Give each unit a small sketch of its own ideas, drawn in the unit colour, with one gentle topic-related loop. Use the agreed asset approach. Keep the left third light for the title on phones; check the finished contents at 1440 px and 390 px once. Classes and loop examples are in `unit-art.js`; the shared header styles, off-screen pausing and reduced motion live in the engine's `lib/units.css` and `lib/units.js` (`Units.header`, `Units.watch`).
## Guide character
diff --git a/engine/units.css b/engine/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/engine/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.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; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: 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; }
+}
diff --git a/engine/units.js b/engine/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/engine/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/elementary-algebra/index.html b/site/elementary-algebra/index.html
index 6f2fa59..5f04a01 100644
--- a/site/elementary-algebra/index.html
+++ b/site/elementary-algebra/index.html
@@ -10,6 +10,8 @@ addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
<title>Elementary Algebra — Papermorph</title>
<meta name="description" content="Animated pre-algebra and algebra, with narrated lessons, interactive quick checks, and chapter practice.">
<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">
+<link rel="stylesheet" href="lib/units.css">
+<script src="lib/units.js"></script>
<script src="lib/unit-art.js"></script>
<link rel="expect" href="#ch01" blocking="render">
<style>
@@ -92,63 +94,6 @@ h1 i { color: var(--task); font-style: italic; }
.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);
@@ -180,18 +125,11 @@ main#contents { padding-bottom: 80px; }
::view-transition-old(lesson) { animation-duration: .18s; }
@media (max-width: 560px) {
.home strong { font-size: 18px; }
- .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>
@@ -266,7 +204,7 @@ const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger
let n = 0, total = 0, i = 0; // i staggers the entrance, in reading order
const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
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 + 1}</span>${esc(name)}</h2><div class="grid">` +
+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}">${Units.header(u, `Unit ${u + 1}`, name)}<div class="grid">` +
chs.map(([t, min]) => { n++;
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>`;
@@ -274,8 +212,7 @@ document.getElementById('units').innerHTML = UNITS.map(([name, chs], u) => {
}).join('');
total = n;
// 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));
+Units.watch();
const finished = [...done].filter(k => k <= total).length;
document.getElementById('prog').innerHTML = finished ? `<b>${finished}</b> of ${total} finished` : `${total} chapters`;
document.getElementById('meta').textContent = `${total} chapters · ${UNITS.length} units · with sound`;
diff --git a/site/elementary-algebra/lib/units.css b/site/elementary-algebra/lib/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/site/elementary-algebra/lib/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.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; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: 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; }
+}
diff --git a/site/elementary-algebra/lib/units.js b/site/elementary-algebra/lib/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/site/elementary-algebra/lib/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/math-notebook/index.html b/site/math-notebook/index.html
index 273be98..ad6af8d 100644
--- a/site/math-notebook/index.html
+++ b/site/math-notebook/index.html
@@ -10,6 +10,8 @@ addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
<title>Elementary Mathematics — Papermorph</title>
<meta name="description" content="Animated middle-school mathematics, with narrated lessons, interactive quick checks, and chapter practice.">
<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">
+<link rel="stylesheet" href="lib/units.css">
+<script src="lib/units.js"></script>
<script src="unit-art.js"></script>
<link rel="expect" href="#ch01" blocking="render">
<style>
@@ -92,63 +94,6 @@ h1 i { color: var(--task); font-style: italic; }
.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);
@@ -182,18 +127,11 @@ main#contents { padding-bottom: 80px; }
.home strong { font-size: 18px; }
.contents-back { margin-left: 0; font-size: 11px; }
#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>
@@ -249,7 +187,7 @@ const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger
let n = 0, total = 0, i = 0; // i staggers the entrance, in reading order
const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
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 + 1}</span>${esc(name)}</h2><div class="grid">` +
+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}">${Units.header(u, `Unit ${u + 1}`, name)}<div class="grid">` +
chs.map(([t, min]) => { n++;
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>`;
@@ -257,8 +195,7 @@ document.getElementById('units').innerHTML = UNITS.map(([name, chs], u) => {
}).join('');
total = n;
// 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));
+Units.watch();
const finished = [...done].filter(k => k <= total).length;
document.getElementById('prog').innerHTML = finished ? `<b>${finished}</b> of ${total} finished` : `${total} chapter${total === 1 ? '' : 's'}`;
const plural = (n, w) => `${n} ${w}${n === 1 ? '' : 's'}`;
diff --git a/site/math-notebook/lib/units.css b/site/math-notebook/lib/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/site/math-notebook/lib/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.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; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: 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; }
+}
diff --git a/site/math-notebook/lib/units.js b/site/math-notebook/lib/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/site/math-notebook/lib/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/math-notebook/unit-art.js b/site/math-notebook/unit-art.js
index 848111b..e63901a 100644
--- a/site/math-notebook/unit-art.js
+++ b/site/math-notebook/unit-art.js
@@ -1,6 +1,6 @@
// 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:
+// on narrow screens). Classes, styled in lib/units.css:
// 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
diff --git a/site/physics-notebook/index.html b/site/physics-notebook/index.html
index d7ff260..66f2997 100644
--- a/site/physics-notebook/index.html
+++ b/site/physics-notebook/index.html
@@ -10,6 +10,8 @@ addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
<title>Energy &amp; Change</title>
<meta name="description" content="An animated notebook about energy: Blip, a little bundle of energy, changes form but never disappears.">
<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">
+<link rel="stylesheet" href="lib/units.css">
+<script src="lib/units.js"></script>
<script src="unit-art.js"></script>
<link rel="expect" href="#ch13" blocking="render">
<style>
@@ -92,63 +94,6 @@ h1 i { color: var(--task); font-style: normal; }
.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);
@@ -182,18 +127,11 @@ main#contents { padding-bottom: 80px; }
@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>
@@ -249,15 +187,14 @@ const done = new Set(Array.isArray(P.done) ? P.done.filter(n => Number.isInteger
let n = START.chapter - 1, total = 0, i = 0; // i staggers the entrance, in reading order
const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
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">` +
+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}">${Units.header(u, `Unit ${u + START.unit}`, name)}<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));
+Units.watch();
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'}`;
diff --git a/site/physics-notebook/lib/units.css b/site/physics-notebook/lib/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/site/physics-notebook/lib/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.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; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: 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; }
+}
diff --git a/site/physics-notebook/lib/units.js b/site/physics-notebook/lib/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/site/physics-notebook/lib/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/physics-notebook/unit-art.js b/site/physics-notebook/unit-art.js
index 9fbf224..5b37818 100644
--- a/site/physics-notebook/unit-art.js
+++ b/site/physics-notebook/unit-art.js
@@ -1,6 +1,6 @@
// 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:
+// on narrow screens). Classes, styled in lib/units.css:
// 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
diff --git a/site/science/index.html b/site/science/index.html
index 9083a5c..59ff964 100644
--- a/site/science/index.html
+++ b/site/science/index.html
@@ -10,6 +10,8 @@ addEventListener('pagereveal', e => e.viewTransition?.ready.catch(() => {}));
<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">
+<link rel="stylesheet" href="lib/units.css">
+<script src="lib/units.js"></script>
<script src="unit-art.js"></script>
<link rel="expect" href="#ch01" blocking="render">
<style>
@@ -89,65 +91,6 @@ h1 i { color: var(--task); font-style: italic; }
.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; }
-.unit-art .orbit { offset-rotate: 0deg; }
-.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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);
@@ -181,18 +124,11 @@ main#contents { padding-bottom: 80px; }
.home strong { font-size: 18px; }
.contents-back { margin-left: 0; font-size: 11px; }
#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>
@@ -231,7 +167,7 @@ main#contents { padding-bottom: 80px; }
// 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.
// A unit's optional third entry { unit, chapter, sample } numbers it from elsewhere in the book; a sample chapter, made
-// to show another look, is labelled as one and not counted with the book's chapters.
+// to show another look, is not counted with the book's chapters.
const START = { unit: 3, chapter: 9 };
const UNITS = [ // [unit title, [[chapter title, minutes], ...]]
['Motion, Forces, and Work', [['Motion', 18], ['Force and Newton’s Laws of Motion', 13], ['Gravity, Friction, and More Forces in Everyday Life', 15], ['Work and Machines', 14]]],
@@ -253,15 +189,14 @@ const esc = s => s.replace(/&/g, '&amp;').replace(/</g, '&lt;');
const samples = new Set();
document.getElementById('units').innerHTML = UNITS.map(([name, chs, o = {}], u) => {
if (o.chapter) n = o.chapter - 1;
- 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 ${o.unit ?? u + START.unit}${o.sample ? ' · Sample chapter, another look' : ''}</span>${esc(name)}</h2><div class="grid">` +
+ return `<section class="unit" style="--c:${HUES[u % HUES.length]};--i:${i++}">${Units.header(u, `Unit ${o.unit ?? u + START.unit}`, name)}<div class="grid">` +
chs.map(([t, min]) => { n++; if (o.sample) samples.add(n); else 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));
+Units.watch();
const finished = [...done].filter(k => k >= START.chapter && k <= n && !samples.has(k)).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'}`;
diff --git a/site/science/lib/units.css b/site/science/lib/units.css
new file mode 100644
index 0000000..e9c62cb
--- /dev/null
+++ b/site/science/lib/units.css
@@ -0,0 +1,79 @@
+/* The unit headers of a book's contents page, the same in every book: a strip of chalkboard per unit, with the unit's
+ label and title and a sketch of its ideas (UNIT_ART, from the book's own unit-art.js) drawn in the unit colour --c.
+ Markup and the scroll observer are in units.js. Uses the contents page's --book, --ui, --chalk and --ease. */
+.unit { position: relative; max-width: 1212px; margin: 0 auto; padding: 28px 16px 0; }
+.unit h2 { position: relative; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; min-height: 168px; margin: 0 0 16px; padding-top: 130px; font: 500 28px/1.2 var(--book); }
+.unit .grid { position: relative; }
+.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; }
+.unit-art .orbit { offset-rotate: 0deg; }
+.seen .unit-art .orbit { animation: art-fade .4s ease-out 2s forwards, along 9s 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); } }
+/* The label and the title share a line when they fit; a long title wraps below the label instead of running off. */
+.unit h2 .title { min-width: 0; text-wrap: balance; }
+.unit h2 .label { font: 600 14px var(--ui); letter-spacing: .14em; text-transform: uppercase; color: var(--c); white-space: nowrap; }
+/* Keep the sketches cheap: each is its own layer, so its loop repaints only itself, and loops pause while their unit is
+ off screen or under the sticky bar (units.js toggles .live), so the bar's blur is not redrawn every frame. */
+.unit-art { will-change: transform; contain: layout style; }
+.unit:not(.live) .unit-art, .unit:not(.live) .unit-art * { animation-play-state: paused; }
+@media (max-width: 560px) {
+ .unit-art { width: calc(100% - 32px); right: 16px; opacity: .32; }
+ .unit h2 { min-height: 0; padding-top: 104px; font-size: 24px; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .unit-art * { animation: 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; }
+}
diff --git a/site/science/lib/units.js b/site/science/lib/units.js
new file mode 100644
index 0000000..e9e8c27
--- /dev/null
+++ b/site/science/lib/units.js
@@ -0,0 +1,26 @@
+// The unit headers of a book's contents page, the same in every book; styled by units.css. The sketches come from
+// the book's own unit-art.js (window.UNIT_ART, one SVG body per unit, viewBox 0 0 600 180).
+// Units.header(u, label, title) the sketch and heading for unit u, as HTML to put first in its <section class="unit">
+// Units.watch() draw each sketch the first time its unit scrolls into view, and run its loop only
+// while the unit is on screen
+'use strict';
+(() => {
+ const esc = s => String(s).replace(/&/g, '&amp;').replace(/</g, '&lt;');
+ const header = (u, label, title) =>
+ `<svg class="unit-art" viewBox="0 0 600 180" aria-hidden="true">${window.UNIT_ART?.[u] || ''}</svg>` +
+ `<h2><span class="label">${esc(label)}</span><span class="title">${esc(title)}</span></h2>`;
+
+ function watch(root = document) {
+ const units = root.querySelectorAll('.unit');
+ if (!('IntersectionObserver' in window)) return units.forEach(u => u.classList.add('seen', 'live'));
+ // The first sight draws the sketch; leaving the screen (or sliding under the sticky bar) pauses it.
+ const first = new IntersectionObserver(es => es.forEach(e => {
+ if (e.isIntersecting) { e.target.classList.add('seen'); first.unobserve(e.target); }
+ }), { threshold: .25 });
+ const live = new IntersectionObserver(es => es.forEach(e => e.target.classList.toggle('live', e.isIntersecting)),
+ { rootMargin: '-64px 0px 0px 0px' });
+ units.forEach(u => { first.observe(u); live.observe(u); });
+ }
+
+ window.Units = { header, watch };
+})();
diff --git a/site/science/unit-art.js b/site/science/unit-art.js
index 99d0291..c0598d2 100644
--- a/site/science/unit-art.js
+++ b/site/science/unit-art.js
@@ -1,6 +1,6 @@
// 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:
+// on narrow screens). Classes, styled in lib/units.css:
// 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