@polycode-projects/the-mechanical-code-talker 5.0.22 → 5.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,12 @@ import { SEED_TAXONOMY } from "../domain/spider-fly-world.mjs";
53
53
  import { loadSlice, loadMap, toFacts, WORDNET_DIR } from "../adapters/corpus/conceptnet.mjs";
54
54
  import { join } from "node:path";
55
55
  import { THEME_TOKENS_CSS, SERIF_STACK, MONO_STACK, escapeHtml, embedJson, embedScriptText, demoEyebrowHtml, EYEBROW_LINKS_CSS } from "./viz-theme.mjs";
56
+ import {
57
+ SPRITE_POSE_REST, SPRITE_POSE_MOVING, isMovingSwatchLabel,
58
+ nextFocusMode, frameAtTick, focusModeFrames, oscillateWalkStep, walkFrameLabelCandidates,
59
+ } from "../domain/sprite-animation.mjs";
60
+ import { sceneVocabulary, randomSceneSentence, roomClassesFromWorldFacts } from "../domain/scene-random.mjs";
61
+ import { splitSceneBackdrop } from "../domain/scene-compose.mjs";
56
62
 
57
63
  const DEFAULT_TITLE = "tmct — the sprite library";
58
64
  const MAX_CHAIN_DISPLAY = 6;
@@ -129,6 +135,24 @@ export async function loadSpriteOntologyFactRows() {
129
135
  return [...seedRows, ...gapfillRows, ...wordnetRows];
130
136
  }
131
137
 
138
+ /** The room classes the adventure page's own scenario worlds declare, for
139
+ * the scene composer's room vocabulary — the same worlds-pack provider read
140
+ * the adventure build step makes, so the rooms a random scene can name are
141
+ * exactly the rooms adventure.html plays in. A missing pack or world reads
142
+ * as no rooms, never a build failure. I/O; the page render itself stays
143
+ * pure given the returned list. */
144
+ export async function loadAdventureSceneRoomClasses(worldNames = ["ashcombe-hall", "lantern-cottage", "greyvale-museum"]) {
145
+ const { getWorldsPackProvider, clearWorldsPackCache } = await import("../adapters/corpus/worlds-pack.mjs");
146
+ clearWorldsPackCache();
147
+ const provider = getWorldsPackProvider({});
148
+ const rooms = new Set();
149
+ for (const name of worldNames) {
150
+ const world = await provider.load(name).catch(() => null);
151
+ for (const room of roomClassesFromWorldFacts(world?.facts || [])) rooms.add(room);
152
+ }
153
+ return [...rooms].sort();
154
+ }
155
+
132
156
  // ---- grouping (presentation only — every class still resolves through the
133
157
  // real resolver above; this only decides which section of the page a
134
158
  // class's card lands in) ----
@@ -646,9 +670,12 @@ export function sceneComposerClassIndex(entries) {
646
670
  // ---- the animated cell (pure) ----
647
671
  //
648
672
  // A card's large tier varies on three axes: mood (mgx:feels), facing
649
- // (mgx:faces) and pose (mgx:pose). One image cell per class shows all three,
650
- // stepping through its display modes on click: static, moving, turning,
651
- // cycle-emotions, back to static. The page builds the frames client-side out
673
+ // (mgx:faces) and pose (mgx:pose). One image cell per class stands where its
674
+ // plain swatch was; each card grid keeps ONE such cell focused (the first,
675
+ // by default), and the focused cell animates — rotating through its turning
676
+ // positions, or cycling its emotions once clicked (sprite-animation.mjs's
677
+ // nextFocusMode holds the toggle; the choice is kept per grid while the
678
+ // visitor stays on the page). The page builds the frames client-side out
652
679
  // of its own already-rendered swatches (see the inline script below — the
653
680
  // same read-the-DOM posture the scene composer's class index takes), but the
654
681
  // frame ORDER and the tempo are real logic worth pinning on their own, so
@@ -710,32 +737,6 @@ export function movingFrameSequence(idleFrame, movingFrame) {
710
737
  return [{ svg: idleFrame.svg, label: "idle" }, { svg: movingFrame.svg, label: "moving" }];
711
738
  }
712
739
 
713
- /** The display modes a card's one image cell steps through, in click order.
714
- * A class only carries the modes it has real art for; static is always
715
- * first, because that is what the cell rests on. */
716
- export const DISPLAY_MODE_ORDER = Object.freeze(["static", "moving", "turning", "emotions"]);
717
-
718
- /** The three axis sequences above, flattened into the ONE click-through
719
- * sequence a card's single image cell walks: the static sprite, its moving
720
- * pose, the whole turntable, then every mood, and round again. Each frame
721
- * carries the mode it belongs to, so the cell can name what it is showing
722
- * and can auto-step within one mode without running off into the next.
723
- *
724
- * The leading frame of `moodFrames` is dropped: moodFrameSequence puts the
725
- * plain sprite there, and that is already this sequence's static frame.
726
- * A class with nothing but its static frame gets an empty sequence and
727
- * keeps its ordinary swatch — there is nothing to cycle.
728
- *
729
- * Pure; self-contained (no outer refs), `.toString()`-splice safe. */
730
- export function displayModeSequence(staticFrame, { movingFrame = null, turnFrames = [], moodFrames = [] } = {}) {
731
- if (!staticFrame) return [];
732
- const frames = [{ mode: "static", svg: staticFrame.svg, label: staticFrame.label }];
733
- if (movingFrame) frames.push({ mode: "moving", svg: movingFrame.svg, label: "moving" });
734
- for (const frame of turnFrames || []) frames.push({ mode: "turning", svg: frame.svg, label: frame.label });
735
- for (const frame of (moodFrames || []).slice(1)) frames.push({ mode: "emotions", svg: frame.svg, label: frame.label });
736
- return frames.length > 1 ? frames : [];
737
- }
738
-
739
740
  // ---- rendering ----
740
741
 
741
742
  /** The DOM id a class's own card carries on whichever full-gallery page
@@ -804,8 +805,9 @@ export function ontologyTreeHtml(tree, options) {
804
805
  const note = tree.truncated
805
806
  ? `<p class="tree-note">Some of these chains run further up than the levels shown. The rest stays on record.</p>`
806
807
  : "";
808
+ const legend = `<span class="ontology-legend" aria-hidden="true"><span class="lg lg-member">in this section</span><span class="lg lg-sibling">shared</span><span class="lg lg-abstract">no sprite yet</span><span class="lg lg-dual">two parents</span></span>`;
807
809
  return `<div class="ontology">
808
- <h3 class="ontology-head">the ontology behind ${escapeHtml(sectionLabel)} <span class="count">${tree.termCount} concepts</span></h3>
810
+ <h3 class="ontology-head"><span class="ontology-lead">the ontology behind</span> <span class="ontology-term">${escapeHtml(sectionLabel)}</span> <span class="count">${tree.termCount} concepts</span>${legend}</h3>
809
811
  <div class="tree-scroll" tabindex="0" role="group" aria-label="ontology tree for ${escapeHtml(sectionLabel)}">
810
812
  <div class="ontology-tree">${branches}${apart}</div>
811
813
  </div>
@@ -838,13 +840,33 @@ function sectionTreeRenderers({ entries, largeTemplates, factRows, spritedClasse
838
840
  return { treeFor, anchorBaseFor };
839
841
  }
840
842
 
843
+ /** A swatch's caption is pose-first everywhere a sprite tile renders:
844
+ * "default / static", "left / static", "happy / static" — the pose half
845
+ * flips to "moving" on hover (the page script owns that), and a tile that
846
+ * IS a moving frame ("moving", "left + moving") renders as its resting
847
+ * variant's name already wearing the moving pose, which is exactly the
848
+ * frame the page folds into that variant's hover flip. */
849
+ export function swatchDisplayParts(s) {
850
+ const moving = isMovingSwatchLabel(s.label);
851
+ const variant = s.kind === "plain"
852
+ ? "default"
853
+ : moving
854
+ ? (s.label === "moving" ? "default" : s.label.replace(/ \+ moving$/, ""))
855
+ : s.label;
856
+ return { variant, pose: moving ? SPRITE_POSE_MOVING : SPRITE_POSE_REST };
857
+ }
858
+
841
859
  function swatchHtml(s) {
842
- const parts = [`<span class="swatch-label">${escapeHtml(s.label)}</span>`];
860
+ const { variant, pose } = swatchDisplayParts(s);
861
+ const parts = [
862
+ `<span class="swatch-label">${escapeHtml(variant)}</span>`,
863
+ `<span class="swatch-pose">${pose}</span>`,
864
+ ];
843
865
  if (s.treatment) parts.push(`<span class="swatch-treat">&rarr; ${escapeHtml(s.treatment)} treatment</span>`);
844
866
  const title = s.property ? `${s.property} = ${s.label}` : s.label;
845
867
  const cls = ["swatch", s.tier, s.kind].filter(Boolean).join(" ");
846
868
  const property = s.property ? ` data-property="${escapeHtml(s.property)}"` : "";
847
- return `<div class="${cls}"${property} title="${escapeHtml(title)}"><div class="swatch-img">${s.svg}</div><div class="swatch-caption">${parts.join("")}</div></div>`;
869
+ return `<div class="${cls}"${property} data-pose="${pose}" title="${escapeHtml(title)}"><div class="swatch-img">${s.svg}</div><div class="swatch-caption">${parts.join("")}</div></div>`;
848
870
  }
849
871
 
850
872
  function tierRowHtml(tierName, swatches) {
@@ -945,7 +967,7 @@ function sectionHtml(group, entries, { clusterBy = null, treeFor, anchorBaseFor
945
967
  * from the WHOLE catalog, never just `groupId`'s own slice — a visitor on
946
968
  * one group's page can still ask about, or compose, any real class from any
947
969
  * other group. */
948
- export function renderSpriteCatalogHtml({ title = DEFAULT_TITLE, iconTemplates = [], largeTemplates = [], factRows = [], spritesBundleAvailable = false, groupId = null, engineBundleJs = "" } = {}) {
970
+ export function renderSpriteCatalogHtml({ title = DEFAULT_TITLE, iconTemplates = [], largeTemplates = [], factRows = [], spritesBundleAvailable = false, groupId = null, engineBundleJs = "", adventureRoomClasses = [] } = {}) {
949
971
  const entries = buildSpriteCatalogEntries({ iconTemplates, largeTemplates, factRows });
950
972
  const spritedClasses = new Set([...iconTemplates, ...largeTemplates].flatMap((t) => t?.classes || []));
951
973
  const clusterBy = {
@@ -971,7 +993,7 @@ export function renderSpriteCatalogHtml({ title = DEFAULT_TITLE, iconTemplates =
971
993
  const footerEntries = groupId ? entries.filter((e) => e.group === groupId) : entries;
972
994
  const footerSwatches = footerEntries.reduce((n, e) => n + e.iconSwatches.length + e.largeSwatches.length, 0);
973
995
  return renderSpriteCatalogPage({
974
- title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable, engineBundleJs,
996
+ title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable, engineBundleJs, adventureRoomClasses,
975
997
  footerClassCount: footerEntries.length, footerSwatchCount: footerSwatches,
976
998
  });
977
999
  }
@@ -1004,17 +1026,24 @@ function crossPageNavHtml(entries, { currentGroupId = null, includeOverviewLink
1004
1026
  * always the WHOLE catalog (never filtered to one group), because the
1005
1027
  * composer's class index and the dock's fact rows must resolve any real
1006
1028
  * catalog class regardless of which cards this particular page shows. */
1007
- function renderSpriteCatalogPage({ title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable, engineBundleJs = "", footerClassCount, footerSwatchCount }) {
1029
+ function renderSpriteCatalogPage({ title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable, engineBundleJs = "", adventureRoomClasses = [], footerClassCount, footerSwatchCount }) {
1008
1030
  const totalSwatches = entries.reduce((n, e) => n + e.iconSwatches.length + e.largeSwatches.length, 0);
1009
1031
  const pageData = embedJson({ classCount: entries.length, swatchCount: totalSwatches });
1010
1032
  const dockRows = spritesBundleAvailable ? spriteFactRows({ iconTemplates, largeTemplates }) : [];
1011
1033
  // The composer's class index, computed here over the WHOLE catalog and
1012
1034
  // embedded once — see sceneComposerClassIndex's own header for why this
1013
1035
  // replaced reading it back off the page's own rendered card markup.
1014
- const classIndexJs = !spritesBundleAvailable ? "{}" : embedJson(sceneComposerClassIndex(entries));
1036
+ const classIndex = spritesBundleAvailable ? sceneComposerClassIndex(entries) : {};
1037
+ const classIndexJs = !spritesBundleAvailable ? "{}" : embedJson(classIndex);
1038
+ // The random-scene vocabulary, derived from the same class index, the
1039
+ // dock's own fact rows and the adventure worlds' rooms — never a word list
1040
+ // of its own (scene-random.mjs).
1041
+ const sceneVocabJs = !spritesBundleAvailable
1042
+ ? "null"
1043
+ : embedJson(sceneVocabulary({ classIndex, spriteFactRows: dockRows, roomClasses: adventureRoomClasses }));
1015
1044
 
1016
1045
  const dockCss = !spritesBundleAvailable ? "" : `
1017
- .dockwrap { margin: .2rem 0 1.3rem; }
1046
+ .dockwrap { margin: .2rem 0 1rem; }
1018
1047
  .dock-note { color: var(--muted); font-size: .8rem; margin: 0 0 .6rem; max-width: 72ch; }
1019
1048
  .docklog { display: flex; flex-direction: column; gap: .4rem; max-height: 240px; overflow-y: auto; margin-bottom: .5rem; }
1020
1049
  .docklog:empty { display: none; margin-bottom: 0; }
@@ -1079,17 +1108,19 @@ function renderSpriteCatalogPage({ title, entries, bodyHtml, navHtml, iconTempla
1079
1108
  aria-label="Continue the sentence: there is a&hellip;">
1080
1109
  </form>
1081
1110
  <div class="pills" id="composePills" role="group" aria-label="quick words to add">
1111
+ <button type="button" class="pill pill-random" id="composeRandom">random scene</button>
1082
1112
  <button type="button" class="pill" data-fill="doctor">doctor</button>
1083
1113
  <button type="button" class="pill" data-fill="hat">hat</button>
1084
1114
  <button type="button" class="pill" data-fill="wood cabinet">wood cabinet</button>
1085
1115
  <button type="button" class="pill" data-fill="glass lamp">glass lamp</button>
1086
- <button type="button" class="pill" data-fill="cat">cat</button>
1116
+ <button type="button" class="pill" data-fill="moving cat">moving cat</button>
1087
1117
  <button type="button" class="pill" data-fill="garden">garden</button>
1088
1118
  </div>
1089
1119
  </section>
1090
1120
  <section class="panel viewer-panel" aria-label="The composed scene">
1091
1121
  <h2>the scene</h2>
1092
1122
  <div class="scene-frame" id="sceneFrame">
1123
+ <div class="scene-backdrop" id="sceneBackdrop" aria-hidden="true"></div>
1093
1124
  <div class="scene-row" id="sceneRow" aria-live="polite"></div>
1094
1125
  <span class="empty-note" id="sceneEmpty">nothing recognized yet. Try &ldquo;a doctor with a hat, and a cabinet&rdquo;.</span>
1095
1126
  </div>
@@ -1205,13 +1236,13 @@ ${THEME_TOKENS_CSS}
1205
1236
  :root[data-theme="light"] { --ai-panel: #EDECE8; --ai-panel-hi: #F4F3F0; --ai-canvas: #DFDEDA; --ai-edge: #C8C6C0; --checker: rgba(0, 0, 0, .07); }
1206
1237
  body { margin: 0; background: var(--ai-canvas); color: var(--ink); font-family: ${SERIF_STACK}; font-size: 16px; line-height: 1.5; }
1207
1238
  .mono { font-family: ${MONO_STACK}; }
1208
- main { max-width: 1240px; margin: 0 auto; padding: 0 1.2rem 3rem; }
1239
+ main { max-width: 1240px; margin: 0 auto; padding: 0 1.2rem 2rem; }
1209
1240
  button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--corpus); outline-offset: 2px; }
1210
1241
  .appbar { display: flex; align-items: flex-end; gap: 1rem; margin: 0 -1.2rem; padding: .6rem 1.2rem 0; background: var(--ai-bar); }
1211
1242
  .appbar h1 { font-family: ${MONO_STACK}; font-size: .84rem; font-weight: 600; letter-spacing: .02em; margin: 0; padding: .32rem .8rem .38rem; background: var(--ai-panel); color: var(--ink); border-radius: 4px 4px 0 0; }
1212
1243
  .appbar .doc-sub { font-family: ${MONO_STACK}; font-size: .66rem; letter-spacing: .07em; text-transform: uppercase; color: color-mix(in srgb, var(--ai-bar-ink) 65%, transparent); padding-bottom: .5rem; }
1213
1244
  ${EYEBROW_LINKS_CSS}
1214
- .topbar { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; background: var(--ai-panel); border-bottom: 1px solid var(--ai-edge); margin: 0 -1.2rem 1.4rem; padding: .5rem 1.2rem; }
1245
+ .topbar { position: sticky; top: 0; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .9rem; background: var(--ai-panel); border-bottom: 1px solid var(--ai-edge); margin: 0 -1.2rem 1rem; padding: .5rem 1.2rem; }
1215
1246
  .jump { font-family: ${MONO_STACK}; font-size: .7rem; padding: .2rem .6rem; border: 1px solid var(--ai-edge); border-radius: 3px; background: transparent; color: var(--ink); text-decoration: none; }
1216
1247
  .jump:hover { border-color: var(--corpus); color: var(--corpus); }
1217
1248
  .jump .count { color: var(--muted); }
@@ -1220,7 +1251,7 @@ ${THEME_TOKENS_CSS}
1220
1251
  .filter { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
1221
1252
  .filter input { font-family: ${MONO_STACK}; font-size: .78rem; background: var(--ai-panel-hi); color: var(--ink); border: 1px solid var(--ai-edge); border-radius: 3px; padding: .3rem .6rem; width: 200px; }
1222
1253
  .filter .n { font-family: ${MONO_STACK}; font-size: .7rem; color: var(--muted); white-space: nowrap; }
1223
- .composer { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1.2rem 0 1.3rem; }
1254
+ .composer { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: .9rem 0 1rem; }
1224
1255
  @media (max-width: 700px) { .composer { grid-template-columns: 1fr; } }
1225
1256
  .composer .panel, .dockwrap .panel { background: var(--ai-panel); border: 1px solid var(--ai-edge); border-radius: 4px; padding: .75rem .85rem; min-width: 0; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
1226
1257
  .composer h2, .dockwrap h2 { font-family: ${MONO_STACK}; font-size: .66rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: -.75rem -.85rem .6rem; padding: .42rem .85rem; background: var(--ai-panel-hi); border-bottom: 1px solid var(--ai-edge); border-radius: 4px 4px 0 0; }
@@ -1230,62 +1261,99 @@ ${THEME_TOKENS_CSS}
1230
1261
  .pills { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; }
1231
1262
  .pill { font-family: ${MONO_STACK}; font-size: .7rem; padding: .22rem .55rem; border: 1px solid var(--ai-edge); border-radius: 999px; background: var(--ai-panel-hi); color: var(--ink); cursor: pointer; }
1232
1263
  .pill:hover { border-color: var(--corpus); color: var(--corpus); }
1233
- .scene-frame { min-height: 5.6rem; display: flex; align-items: center; }
1264
+ .scene-frame { position: relative; min-height: 6.4rem; display: flex; align-items: center; border-radius: 4px; overflow: hidden; }
1265
+ /* A named room takes the whole wall: the backdrop layer sits behind the
1266
+ standing entities and its svg fills the frame edge to edge. */
1267
+ .scene-backdrop { position: absolute; inset: 0; display: none; }
1268
+ .scene-backdrop svg { width: 100%; height: 100%; display: block; }
1269
+ .scene-room-name { position: absolute; top: .3rem; right: .45rem; font-family: ${MONO_STACK}; font-size: .6rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink); background: color-mix(in srgb, var(--ai-panel) 82%, transparent); border: 1px solid var(--ai-edge); border-radius: 3px; padding: .06rem .35rem; }
1270
+ .scene-frame.has-backdrop { min-height: 11rem; align-items: flex-end; }
1271
+ .scene-frame.has-backdrop .scene-backdrop { display: block; }
1272
+ .scene-frame.has-backdrop .scene-row { position: relative; padding: 0 .8rem .5rem; align-items: flex-end; }
1273
+ .scene-frame.has-backdrop .scene-card { width: 92px; }
1274
+ .scene-frame.has-backdrop .scene-sprite { border: 0; background: none; width: 76px; height: 76px; }
1275
+ .scene-frame.has-backdrop .scene-label { background: color-mix(in srgb, var(--ai-panel) 82%, transparent); border-radius: 3px; padding: 0 .25rem; width: max-content; max-width: 100%; }
1234
1276
  .scene-row { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-start; width: 100%; }
1235
1277
  .scene-row:empty { display: none; }
1236
1278
  .scene-card { display: flex; flex-direction: column; align-items: center; width: 74px; }
1237
1279
  .scene-sprite { width: 60px; height: 60px; border-radius: 3px; border: 1px solid var(--ai-edge); display: flex; align-items: center; justify-content: center; padding: 6px; box-sizing: border-box; background-image: linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%), linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%); background-position: 0 0, 5px 5px; background-size: 10px 10px; background-color: var(--card); }
1238
1280
  .scene-sprite svg { width: 100%; height: 100%; display: block; filter: var(--sprite-pop); }
1281
+ @media (prefers-reduced-motion: no-preference) { .scene-walker .scene-sprite { transition: transform .74s linear; } }
1239
1282
  .scene-label { font-size: .7rem; text-align: center; color: var(--ink); margin-top: .3rem; line-height: 1.2; }
1240
1283
  .empty-note { font-family: ${MONO_STACK}; font-size: .78rem; color: var(--muted); }
1241
- .group { margin: 2.2rem 0; content-visibility: auto; contain-intrinsic-size: 800px; }
1284
+ .pill-random { border-color: var(--taught); color: var(--taught); }
1285
+ .pill-random:hover { border-color: var(--corpus); }
1286
+ .group { margin: 1.4rem 0; content-visibility: auto; contain-intrinsic-size: 700px; }
1242
1287
  .group h2 { font-family: ${MONO_STACK}; font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; margin: 0 0 .2rem; display: flex; align-items: baseline; gap: .5rem; }
1243
1288
  .group h2 .count { font-size: .7rem; color: var(--muted); font-weight: 400; }
1244
- .section-note { color: var(--muted); font-size: .82rem; margin: 0 0 .8rem; max-width: 68ch; }
1245
- .landing-sections { display: flex; flex-direction: column; gap: 1.6rem; }
1246
- .landing-section { min-width: 0; }
1247
- .landing-section-name { font-family: ${MONO_STACK}; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .4rem; display: flex; align-items: baseline; gap: .4rem; }
1289
+ .section-note { color: var(--muted); font-size: .82rem; margin: 0 0 .6rem; max-width: 68ch; }
1290
+ .landing-sections { display: flex; flex-direction: column; gap: 1.1rem; }
1291
+ /* A landing section is one row of the chart: the ontology on the left,
1292
+ its example card and "view all" link in a fixed side column — the tree
1293
+ stays first in the DOM, the card just stops paying for a whole band of
1294
+ its own. */
1295
+ .landing-section { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) 258px; gap: .3rem 1rem; align-items: start; }
1296
+ .landing-section-name { grid-column: 1 / -1; font-family: ${MONO_STACK}; font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; display: flex; align-items: baseline; gap: .4rem; }
1248
1297
  .landing-section-name .count { font-weight: 400; opacity: .75; }
1249
- .landing-section .cards { grid-template-columns: minmax(0, 260px); }
1250
- .viewall { display: inline-block; font-family: ${MONO_STACK}; font-size: .7rem; margin-top: .4rem; color: var(--taught); text-decoration: none; }
1298
+ .landing-section .ontology { grid-column: 1; grid-row: span 2; margin: 0; }
1299
+ .landing-section .cards { grid-column: 2; grid-template-columns: minmax(0, 1fr); }
1300
+ .landing-section .viewall { grid-column: 2; }
1301
+ @media (max-width: 860px) { .landing-section { display: block; } .landing-section .ontology { margin: 0 0 .6rem; } }
1302
+ .viewall { display: inline-block; font-family: ${MONO_STACK}; font-size: .7rem; margin-top: .3rem; color: var(--taught); text-decoration: none; }
1251
1303
  .viewall:hover { color: var(--corpus); text-decoration: underline; }
1252
- /* The section ontology trees. Levels run left to right, widest concept
1304
+ /* The section ontology charts. Levels run left to right, widest concept
1253
1305
  first, inside a box that scrolls on its own so a wide graph never widens
1254
- the page. */
1255
- .ontology { margin: .3rem 0 .9rem; }
1256
- .ontology-head { font-family: ${MONO_STACK}; font-size: .64rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .35rem; display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
1257
- .ontology-head .count { font-weight: 400; opacity: .75; }
1258
- .tree-scroll { overflow: auto; max-height: 22rem; border: 1px solid var(--ai-edge); border-radius: 4px; background: var(--ai-panel); padding: .55rem; overscroll-behavior: contain; }
1259
- .ontology-tree { display: flex; flex-direction: column; gap: .9rem; width: max-content; min-width: 100%; }
1306
+ the page. The head sets the reading: a quiet serif lead-in, the term
1307
+ itself, the concept count, and a legend decoding the node treatments —
1308
+ the same border language the nodes below actually wear. */
1309
+ .ontology { margin: .2rem 0 .8rem; }
1310
+ .ontology-head { margin: 0 0 .3rem; display: flex; align-items: baseline; gap: .45rem; flex-wrap: wrap; font-weight: 400; }
1311
+ .ontology-lead { font-family: ${SERIF_STACK}; font-style: italic; font-size: .84rem; color: var(--muted); }
1312
+ .ontology-term { font-family: ${MONO_STACK}; font-size: .7rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink); }
1313
+ .ontology-head .count { font-family: ${MONO_STACK}; font-size: .6rem; color: var(--muted); border: 1px solid var(--ai-edge); border-radius: 999px; padding: .04rem .4rem; }
1314
+ .ontology-legend { margin-left: auto; display: flex; gap: .6rem; font-family: ${MONO_STACK}; font-size: .54rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
1315
+ .ontology-legend .lg { display: inline-flex; align-items: center; gap: .26rem; white-space: nowrap; }
1316
+ .ontology-legend .lg::before { content: ""; width: .6rem; height: .6rem; box-sizing: border-box; border: 1px solid var(--ai-edge); border-radius: 2px; background: var(--card); }
1317
+ .ontology-legend .lg-member::before { border-left: 3px solid var(--taught); }
1318
+ .ontology-legend .lg-sibling::before { opacity: .5; }
1319
+ .ontology-legend .lg-abstract::before { border-style: dashed; }
1320
+ .ontology-legend .lg-dual::before { border-left: 3px solid var(--corpus); }
1321
+ @media (max-width: 700px) { .ontology-legend { display: none; } }
1322
+ .tree-scroll { overflow: auto; max-height: 15.5rem; border: 1px solid var(--ai-edge); border-radius: 4px; background: var(--ai-panel); padding: .5rem .55rem; overscroll-behavior: contain; }
1323
+ .ontology-tree { display: flex; flex-direction: column; gap: .8rem; width: max-content; min-width: 100%; }
1260
1324
  .tree-branch { display: flex; align-items: flex-start; gap: .45rem; }
1261
1325
  .tree-apart { flex-direction: column; }
1262
- .tree-apart-head { font-family: ${MONO_STACK}; font-size: .6rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .3rem; }
1263
- .tree-apart .tree-level { flex-direction: row; flex-wrap: wrap; width: auto; }
1264
- .tree-level { display: flex; flex-direction: column; gap: .4rem; width: 10.5rem; flex: none; }
1265
- .tree-node { display: flex; flex-direction: column; align-items: center; gap: .18rem; text-align: center; padding: .3rem .3rem .35rem; border: 1px solid var(--ai-edge); border-radius: 3px; background: var(--card); width: 10.5rem; box-sizing: border-box; }
1266
- .tree-node.member { border-color: var(--taught); }
1267
- .tree-node.sibling { opacity: .72; }
1268
- .tree-node.dual { border-left-width: 3px; border-left-color: var(--corpus); }
1326
+ .tree-apart-head { font-family: ${MONO_STACK}; font-size: .58rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .3rem; }
1327
+ .tree-apart .tree-level { flex-direction: row; flex-wrap: wrap; width: auto; padding-top: 0; }
1328
+ .tree-level { display: flex; flex-direction: column; gap: .35rem; width: 9.4rem; flex: none; position: relative; }
1329
+ /* The lead branch captions its columns with the real subClassOf depth each
1330
+ one sits at — the number is the walk itself, not decoration. */
1331
+ .tree-branch:first-child:not(.tree-apart) .tree-level { padding-top: .9rem; }
1332
+ .tree-branch:first-child:not(.tree-apart) .tree-level::before { content: "depth " attr(data-level); position: absolute; top: 0; left: .15rem; font-family: ${MONO_STACK}; font-size: .5rem; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); opacity: .8; }
1333
+ .tree-node { display: flex; flex-direction: column; align-items: center; gap: .16rem; text-align: center; padding: .28rem .28rem .32rem; border: 1px solid var(--ai-edge); border-radius: 3px; background: var(--card); width: 9.4rem; box-sizing: border-box; }
1334
+ .tree-node.member { border-left: 3px solid var(--taught); }
1335
+ .tree-node.sibling { opacity: .6; }
1336
+ .tree-node.dual { border-left: 3px solid var(--corpus); }
1269
1337
  .tree-node:target { outline: 2px solid var(--corpus); outline-offset: 2px; }
1270
- .tree-img, .tree-img-placeholder { width: 100%; height: 3.2rem; box-sizing: border-box; border: 1px solid var(--ai-edge); border-radius: 3px; display: flex; align-items: center; justify-content: center; }
1338
+ .tree-img, .tree-img-placeholder { width: 100%; height: 2.7rem; box-sizing: border-box; border: 1px solid var(--ai-edge); border-radius: 3px; display: flex; align-items: center; justify-content: center; }
1271
1339
  .tree-img { padding: 3px; background-image: linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%), linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%); background-position: 0 0, 5px 5px; background-size: 10px 10px; background-color: var(--card); }
1272
1340
  .tree-img svg { height: 100%; width: auto; max-width: 100%; display: block; filter: var(--sprite-pop); }
1273
1341
  .tree-img-placeholder { border-style: dashed; padding: .2rem .25rem; overflow: hidden; font-family: ${MONO_STACK}; font-size: .52rem; line-height: 1.25; color: var(--muted); }
1274
- .tree-term { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--ink); word-break: break-word; }
1342
+ .tree-term { font-family: ${MONO_STACK}; font-size: .64rem; font-weight: 600; color: var(--ink); word-break: break-word; }
1275
1343
  a.tree-term { color: var(--taught); text-decoration: none; }
1276
1344
  a.tree-term:hover { color: var(--corpus); text-decoration: underline; }
1277
1345
  .tree-up { font-family: ${MONO_STACK}; font-size: .55rem; color: var(--muted); line-height: 1.25; word-break: break-word; }
1278
1346
  .tree-up a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--ai-edge); }
1279
1347
  .tree-up a:hover { color: var(--corpus); }
1280
- .tree-note { font-family: ${MONO_STACK}; font-size: .62rem; color: var(--muted); margin: .35rem 0 0; }
1281
- .cluster { margin: 1rem 0 1.5rem; }
1348
+ .tree-note { font-family: ${MONO_STACK}; font-size: .62rem; color: var(--muted); margin: .3rem 0 0; }
1349
+ .cluster { margin: .8rem 0 1.1rem; }
1282
1350
  .cluster-head { display: flex; align-items: center; gap: .45rem; font-family: ${MONO_STACK}; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 0 0 .55rem; }
1283
1351
  .cluster-head .count { font-weight: 400; opacity: .75; }
1284
1352
  .cluster-head::after { content: ""; flex: 1; height: 1px; background: var(--ai-edge); }
1285
1353
  .cluster-chip { width: 26px; height: 26px; display: inline-flex; padding: 2px; box-sizing: border-box; border: 1px solid var(--ai-edge); border-radius: 3px; background-image: linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%), linear-gradient(45deg, var(--checker) 25%, transparent 25% 75%, var(--checker) 75%); background-position: 0 0, 4px 4px; background-size: 8px 8px; background-color: var(--card); }
1286
1354
  .cluster-chip svg { width: 100%; height: 100%; display: block; filter: var(--sprite-pop); }
1287
- .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .7rem; }
1288
- .card { background: var(--card); border: 1px solid var(--ai-edge); border-radius: 4px; padding: .55rem .7rem .7rem; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); content-visibility: auto; contain-intrinsic-size: 220px; }
1355
+ .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: .6rem; }
1356
+ .card { background: var(--card); border: 1px solid var(--ai-edge); border-radius: 4px; padding: .5rem .65rem .6rem; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); content-visibility: auto; contain-intrinsic-size: 220px; }
1289
1357
  .card[hidden] { display: none; }
1290
1358
  .card-name { font-family: ${MONO_STACK}; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .35rem; }
1291
1359
  .chain { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--muted); margin-bottom: .5rem; display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; }
@@ -1307,11 +1375,22 @@ ${THEME_TOKENS_CSS}
1307
1375
  .swatch.fallback { opacity: .55; }
1308
1376
  .swatch.fallback .swatch-img { border-style: dashed; }
1309
1377
  .swatch-caption { font-family: ${MONO_STACK}; font-size: .58rem; color: var(--muted); line-height: 1.25; margin-top: .15rem; word-break: break-word; }
1378
+ /* The pose half of every tile's caption: "left / static" at rest,
1379
+ "left / moving" while hovered — the flip happens on every tile, art or
1380
+ not, so the caption always says which pose you are looking at. */
1381
+ .swatch-pose::before { content: " / "; opacity: .6; }
1382
+ .swatch-pose { color: var(--muted); }
1383
+ .swatch-pose:empty { display: none; }
1384
+ .swatch.hover-moving .swatch-pose { color: var(--corpus); }
1310
1385
  .swatch-treat { display: block; opacity: .8; }
1311
- .swatch.cycle .swatch-img { border-color: var(--taught); cursor: pointer; display: block; }
1386
+ .swatch.cycle .swatch-img { cursor: pointer; display: block; }
1312
1387
  .swatch.cycle .swatch-img:hover { border-color: var(--corpus); }
1313
1388
  .swatch.cycle .swatch-caption { color: var(--taught); }
1314
1389
  .swatch.cycle .swatch-mode { display: block; font-size: .54rem; letter-spacing: .05em; text-transform: uppercase; color: var(--corpus); }
1390
+ .swatch.cycle .swatch-mode:empty { display: none; }
1391
+ /* The one focused sprite per card grid: the outline is the focus itself. */
1392
+ .swatch.cycle.focused .swatch-img { border-color: var(--taught); box-shadow: 0 0 0 1px var(--taught); }
1393
+ .swatch.cycle.focused .swatch-img:hover { border-color: var(--taught); }
1315
1394
  footer.page { max-width: 74ch; margin: 2.5rem 0 0; padding-top: 1rem; border-top: 1px solid var(--ai-edge); font-family: ${MONO_STACK}; font-size: .74rem; color: var(--muted); }
1316
1395
  @media (prefers-reduced-motion: no-preference) { .jump, .swatch, .pill { transition: border-color .12s ease, color .12s ease, opacity .12s ease; } }
1317
1396
  ${dockCss}</style>
@@ -1337,6 +1416,7 @@ ${dockCss}</style>
1337
1416
  <script>
1338
1417
  const SPRITE_CATALOG = ${pageData};
1339
1418
  const SPRITE_CLASS_INDEX = ${classIndexJs};
1419
+ const SPRITE_SCENE_VOCAB = ${sceneVocabJs};
1340
1420
  </script>
1341
1421
  ${spriteBundleScript}
1342
1422
  <script>
@@ -1362,6 +1442,34 @@ ${spriteBundleScript}
1362
1442
  q.addEventListener("input", apply);
1363
1443
  apply();
1364
1444
 
1445
+ const esc = ${escapeHtml.toString()};
1446
+ const reducedMotion = !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
1447
+
1448
+ // One shared clock drives everything that moves on this page — the hover
1449
+ // flip-books, the focused cells, the scene walkers — so no two animations
1450
+ // can drift into different tempos.
1451
+ const CYCLE_FRAME_DELAY_MS = ${CYCLE_FRAME_DELAY_MS};
1452
+ let tick = 0;
1453
+ const tickHandlers = [];
1454
+
1455
+ // The pure machinery, spliced from the same modules the tests pin
1456
+ // (sprite-catalog-viz.mjs's frame sequences, sprite-animation.mjs's tick
1457
+ // machine, scene-compose.mjs's backdrop split, scene-random.mjs's
1458
+ // sentence builder).
1459
+ const FACING_TURN_ORDER = ${embedJson(FACING_TURN_ORDER)};
1460
+ const MOOD_PROPERTY = "mgx:feels";
1461
+ const FACING_PROPERTY = "mgx:faces";
1462
+ const moodFrameSequence = ${moodFrameSequence.toString()};
1463
+ const turnFrameSequence = ${turnFrameSequence.toString()};
1464
+ const movingFrameSequence = ${movingFrameSequence.toString()};
1465
+ const nextFocusMode = ${nextFocusMode.toString()};
1466
+ const frameAtTick = ${frameAtTick.toString()};
1467
+ const focusModeFrames = ${focusModeFrames.toString()};
1468
+ const oscillateWalkStep = ${oscillateWalkStep.toString()};
1469
+ const walkFrameLabelCandidates = ${walkFrameLabelCandidates.toString()};
1470
+ const splitSceneBackdrop = ${splitSceneBackdrop.toString()};
1471
+ const randomSceneSentence = ${randomSceneSentence.toString()};
1472
+
1365
1473
  // ---- the scene composer — reads the class/material index from
1366
1474
  // SPRITE_CLASS_INDEX, computed server-side over the WHOLE catalog
1367
1475
  // (sceneComposerClassIndex) and embedded above, never scoped to whichever
@@ -1369,9 +1477,9 @@ ${spriteBundleScript}
1369
1477
  // section, or a per-group page showing only one group, still composes any
1370
1478
  // real catalog class. Which class a typed word names is the bundle's
1371
1479
  // extractSceneItems, which asks the real resolver — the page never
1372
- // matches a class name itself.
1373
- const esc = ${escapeHtml.toString()};
1374
-
1480
+ // matches a class name itself. A named room becomes the wall behind the
1481
+ // scene, and a "moving" entity walks: static/moving flip while crossing,
1482
+ // the turning frames at each end, driven by the shared clock above.
1375
1483
  function wireSceneComposer() {
1376
1484
  const composeqEl = document.getElementById("composeq");
1377
1485
  if (!composeqEl) return;
@@ -1380,23 +1488,59 @@ ${spriteBundleScript}
1380
1488
  const composePillsEl = document.getElementById("composePills");
1381
1489
  const sceneRowEl = document.getElementById("sceneRow");
1382
1490
  const sceneEmptyEl = document.getElementById("sceneEmpty");
1491
+ const sceneFrameEl = document.getElementById("sceneFrame");
1492
+ const sceneBackdropEl = document.getElementById("sceneBackdrop");
1493
+ const randomEl = document.getElementById("composeRandom");
1383
1494
  const classIndex = SPRITE_CLASS_INDEX;
1495
+ const vocab = SPRITE_SCENE_VOCAB || { rooms: [], emotions: [], classes: [] };
1496
+ const sceneWalkers = [];
1497
+
1498
+ function stepWalkers() {
1499
+ for (const w of sceneWalkers) {
1500
+ const step = oscillateWalkStep(tick + w.phase, {});
1501
+ const candidates = walkFrameLabelCandidates({ facing: step.facing, pose: step.pose, material: w.material });
1502
+ let svg = w.entry.defaultSvg || "";
1503
+ for (const label of candidates) {
1504
+ if (w.entry.materials[label]) { svg = w.entry.materials[label]; break; }
1505
+ }
1506
+ if (w.lastSvg !== svg) { w.spriteEl.innerHTML = svg; w.lastSvg = svg; }
1507
+ w.spriteEl.style.transform = "translateX(" + (step.offsetFraction * 100).toFixed(1) + "%)";
1508
+ }
1509
+ }
1510
+ tickHandlers.push(stepWalkers);
1384
1511
 
1385
1512
  function renderScene(text) {
1386
1513
  const items = extractSceneItems(text, classIndex);
1387
- if (!items.length) {
1514
+ const split = splitSceneBackdrop(items, vocab.rooms);
1515
+ sceneWalkers.length = 0;
1516
+ const roomEntry = split.backdrop ? classIndex[split.backdrop.className] : null;
1517
+ sceneFrameEl.classList.toggle("has-backdrop", !!roomEntry);
1518
+ sceneBackdropEl.innerHTML = roomEntry
1519
+ ? roomEntry.defaultSvg.replace("<svg ", '<svg preserveAspectRatio="xMidYMid slice" ')
1520
+ + '<span class="scene-room-name">' + esc(split.backdrop.className) + "</span>"
1521
+ : "";
1522
+ if (!split.rest.length && !roomEntry) {
1388
1523
  sceneRowEl.innerHTML = "";
1389
1524
  sceneEmptyEl.hidden = false;
1390
1525
  return;
1391
1526
  }
1392
1527
  sceneEmptyEl.hidden = true;
1393
- sceneRowEl.innerHTML = items.map((item) => {
1528
+ sceneRowEl.innerHTML = split.rest.map((item, at) => {
1394
1529
  const entry = classIndex[item.className];
1395
1530
  if (!entry) return "";
1396
1531
  const svg = (item.materialLabel && entry.materials[item.materialLabel]) || entry.defaultSvg || "";
1397
- const label = item.materialLabel ? item.materialLabel + " " + item.className : item.className;
1398
- return '<div class="scene-card"><div class="scene-sprite">' + svg + '</div><div class="scene-label">' + esc(label) + "</div></div>";
1532
+ const label = (item.moving ? "moving " : "") + (item.materialLabel ? item.materialLabel + " " : "") + item.className;
1533
+ return '<div class="scene-card' + (item.moving ? " scene-walker" : "") + '" data-at="' + at + '"><div class="scene-sprite">' + svg + '</div><div class="scene-label">' + esc(label) + "</div></div>";
1399
1534
  }).join("");
1535
+ if (reducedMotion) return;
1536
+ split.rest.forEach((item, at) => {
1537
+ if (!item.moving) return;
1538
+ const entry = classIndex[item.className];
1539
+ const cardEl = sceneRowEl.querySelector('.scene-card[data-at="' + at + '"]');
1540
+ if (!entry || !cardEl) return;
1541
+ sceneWalkers.push({ spriteEl: cardEl.querySelector(".scene-sprite"), entry, material: item.materialLabel, phase: at * 5, lastSvg: null });
1542
+ });
1543
+ stepWalkers();
1400
1544
  }
1401
1545
 
1402
1546
  composeqEl.addEventListener("input", () => renderScene(composeqEl.value));
@@ -1404,136 +1548,216 @@ ${spriteBundleScript}
1404
1548
  composePillsEl.addEventListener("click", (e) => {
1405
1549
  const btn = e.target.closest(".pill");
1406
1550
  if (!btn) return;
1551
+ if (btn.id === "composeRandom") return;
1407
1552
  const phrase = btn.dataset.fill || "";
1408
1553
  const current = composeqEl.value.trim();
1409
1554
  composeqEl.value = current ? current + ", a " + phrase : phrase;
1410
1555
  composeqEl.focus();
1411
1556
  renderScene(composeqEl.value);
1412
1557
  });
1558
+ if (randomEl) {
1559
+ randomEl.addEventListener("click", () => {
1560
+ // Math.random is allowed exactly here — the sentence builder itself
1561
+ // is pure and takes the rng as an argument.
1562
+ const sentence = randomSceneSentence(vocab, Math.random);
1563
+ composeqEl.value = sentence;
1564
+ renderScene(sentence);
1565
+ composeqEl.focus();
1566
+ });
1567
+ }
1413
1568
  renderScene("");
1414
1569
  }
1415
1570
  wireSceneComposer();
1416
1571
 
1417
- // ---- the animated cell — one image per class, standing where its plain
1418
- // swatch was, stepping through the display modes its own templates carry
1419
- // art for: static, moving, turning, cycle-emotions, back to static. Frames
1420
- // are the card's own already-rendered swatches (read straight off the DOM
1421
- // here — unlike the composer's classIndex above, this only ever needs
1422
- // whatever cards THIS page renders, never the whole catalog), ordered by
1423
- // the pure *FrameSequence functions spliced in below and flattened by
1424
- // displayModeSequence.
1425
- //
1426
- // A click always advances one frame, so every mode is reachable by hand.
1427
- // Inside an animated mode one shared interval steps the frames on, looping
1428
- // within that mode rather than running on into the next one; the static
1429
- // frame is the resting state and never auto-steps. Hovering the resting
1430
- // cell shows the moving pose while the pointer is over it.
1572
+ // ---- the sprite tiles — pose-first captions everywhere: every tile reads
1573
+ // "<variant> / static" at rest and "<variant> / moving" under the pointer,
1574
+ // and a tile whose class really has that moving frame flip-books between
1575
+ // the two drawings while hovered. The moving-frame tiles the server
1576
+ // rendered fold into their resting variants here, so the grid shows each
1577
+ // variant once and the motion lives on hover.
1578
+ const movingSvgOf = new Map();
1579
+ const hoverFlips = new Set();
1580
+
1581
+ function swatchEnter(sw) {
1582
+ if (sw.classList.contains("hover-moving")) return;
1583
+ if (sw.classList.contains("cycle") && sw.classList.contains("focused")) return;
1584
+ sw.classList.add("hover-moving");
1585
+ const poseEl = sw.querySelector(".swatch-pose");
1586
+ if (poseEl) poseEl.textContent = "moving";
1587
+ const flip = movingSvgOf.get(sw);
1588
+ if (flip && !reducedMotion) {
1589
+ flip.showMoving = true;
1590
+ sw.querySelector(".swatch-img").innerHTML = flip.moving;
1591
+ hoverFlips.add(sw);
1592
+ }
1593
+ }
1594
+ function swatchLeave(sw) {
1595
+ sw.classList.remove("hover-moving");
1596
+ const poseEl = sw.querySelector(".swatch-pose");
1597
+ if (poseEl) poseEl.textContent = "static";
1598
+ const flip = movingSvgOf.get(sw);
1599
+ if (flip) {
1600
+ hoverFlips.delete(sw);
1601
+ sw.querySelector(".swatch-img").innerHTML = flip.still;
1602
+ }
1603
+ }
1604
+ // Per-tile mouseenter/mouseleave rather than a delegated mouseover: the
1605
+ // flip replaces the svg UNDER the pointer, and a delegated handler would
1606
+ // later see a mouseout whose target is that detached node — with no
1607
+ // .swatch ancestor left to find, the leave would never fire.
1608
+ function wireSwatchHover(sw) {
1609
+ sw.addEventListener("mouseenter", () => swatchEnter(sw));
1610
+ sw.addEventListener("mouseleave", () => swatchLeave(sw));
1611
+ }
1612
+ for (const sw of document.querySelectorAll(".swatch")) wireSwatchHover(sw);
1613
+ tickHandlers.push(() => {
1614
+ for (const sw of hoverFlips) {
1615
+ const flip = movingSvgOf.get(sw);
1616
+ if (!flip) continue;
1617
+ flip.showMoving = !flip.showMoving;
1618
+ sw.querySelector(".swatch-img").innerHTML = flip.showMoving ? flip.moving : flip.still;
1619
+ }
1620
+ });
1621
+
1622
+ // ---- the focused cell — one image cell per class stands where the plain
1623
+ // swatch was, and each card grid keeps exactly one of them focused (the
1624
+ // first, until the visitor clicks another). The focused cell animates:
1625
+ // rotating through its turning positions by default, cycling its emotions
1626
+ // once clicked. Clicking the focused cell is the toggle; clicking any
1627
+ // other cell moves the focus to it. Each grid keeps its own chosen mode
1628
+ // for as long as the visitor stays on the page. Frames come off the
1629
+ // card's own already-rendered swatches — this only ever needs whatever
1630
+ // cards THIS page renders, never the whole catalog.
1431
1631
  //
1432
- // Reduced motion turns off the interval and the hover preview both. Clicks
1433
- // still step frame by frame, which is what keeps the walk deterministic.
1434
- const CYCLE_FRAME_DELAY_MS = ${CYCLE_FRAME_DELAY_MS};
1435
- const FACING_TURN_ORDER = ${embedJson(FACING_TURN_ORDER)};
1436
- const MOOD_PROPERTY = "mgx:feels";
1437
- const FACING_PROPERTY = "mgx:faces";
1438
- const POSE_PROPERTY = "mgx:pose";
1439
- const moodFrameSequence = ${moodFrameSequence.toString()};
1440
- const turnFrameSequence = ${turnFrameSequence.toString()};
1441
- const movingFrameSequence = ${movingFrameSequence.toString()};
1442
- const displayModeSequence = ${displayModeSequence.toString()};
1443
- const reducedMotion = !!(window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches);
1444
- const cycleSteppers = [];
1632
+ // Reduced motion stops the clock: the focused cell then shows one real
1633
+ // frame of its current mode, and clicks still switch focus and mode.
1634
+ function tileOf(el) {
1635
+ const img = el.querySelector(".swatch-img");
1636
+ const labelEl = el.querySelector(".swatch-label");
1637
+ if (!img || !labelEl) return null;
1638
+ return {
1639
+ el,
1640
+ svg: img.innerHTML,
1641
+ label: labelEl.textContent.trim(),
1642
+ pose: el.dataset.pose || "static",
1643
+ property: el.dataset.property || "",
1644
+ kind: el.classList.contains("plain") ? "plain" : el.classList.contains("fallback") ? "fallback" : "",
1645
+ };
1646
+ }
1647
+
1648
+ const grids = new Map();
1445
1649
 
1446
- function frameFromSwatch(swatch) {
1447
- const img = swatch && swatch.querySelector(".swatch-img");
1448
- const label = swatch && swatch.querySelector(".swatch-label");
1449
- if (!img || !label) return null;
1450
- return { svg: img.innerHTML, label: label.textContent.trim() };
1650
+ function restCell(cell) {
1651
+ cell.holder.classList.remove("focused");
1652
+ cell.holder.dataset.mode = "static";
1653
+ cell.imgEl.innerHTML = cell.staticFrame.svg;
1654
+ cell.modeEl.textContent = "";
1655
+ cell.labelEl.textContent = "default";
1656
+ cell.poseEl.textContent = cell.holder.classList.contains("hover-moving") ? "moving" : "static";
1657
+ cell.active = [];
1451
1658
  }
1452
1659
 
1453
- function makeModeCell(frames, cls) {
1454
- const holder = document.createElement("div");
1455
- holder.className = "swatch large cycle cycle-mode";
1456
- holder.innerHTML = '<button type="button" class="swatch-img" aria-label="step the ' + esc(cls)
1457
- + ' sprite through its display modes"></button>'
1458
- + '<div class="swatch-caption"><span class="swatch-mode"></span><span class="swatch-label"></span></div>';
1459
- const frameImgEl = holder.querySelector(".swatch-img");
1460
- const frameModeEl = holder.querySelector(".swatch-mode");
1461
- const frameLabelEl = holder.querySelector(".swatch-label");
1462
- const movingIndex = frames.findIndex((f) => f.mode === "moving");
1463
- let frameIndex = 0;
1464
- let previewIndex = -1;
1465
- // Once the visitor starts clicking, the hover preview stops second-
1466
- // guessing them: it is the same pointer doing both, so without this the
1467
- // preview keeps pulling the cell back to the moving pose between clicks.
1468
- // Leaving the cell arms it again.
1469
- let previewBlocked = false;
1470
- const showFrame = () => {
1471
- const frame = frames[previewIndex >= 0 ? previewIndex : frameIndex];
1472
- frameImgEl.innerHTML = frame.svg;
1473
- frameModeEl.textContent = frame.mode;
1474
- frameLabelEl.textContent = frame.label;
1475
- holder.dataset.mode = frame.mode;
1476
- };
1477
- frameImgEl.addEventListener("click", () => {
1478
- previewIndex = -1;
1479
- previewBlocked = true;
1480
- frameIndex = (frameIndex + 1) % frames.length;
1481
- showFrame();
1482
- });
1483
- if (!reducedMotion && movingIndex > 0) {
1484
- holder.addEventListener("mouseenter", () => {
1485
- if (previewBlocked || previewIndex >= 0 || frames[frameIndex].mode !== "static") return;
1486
- previewIndex = movingIndex;
1487
- showFrame();
1488
- });
1489
- holder.addEventListener("mouseleave", () => {
1490
- previewBlocked = false;
1491
- if (previewIndex < 0) return;
1492
- previewIndex = -1;
1493
- showFrame();
1494
- });
1660
+ function focusCell(cell, mode) {
1661
+ cell.holder.classList.add("focused");
1662
+ cell.holder.dataset.mode = mode;
1663
+ cell.active = focusModeFrames(mode, cell.frames);
1664
+ const frame = frameAtTick(cell.active, tick) || cell.staticFrame;
1665
+ cell.imgEl.innerHTML = frame.svg;
1666
+ cell.modeEl.textContent = mode;
1667
+ cell.labelEl.textContent = frame.label;
1668
+ cell.poseEl.textContent = "";
1669
+ }
1670
+
1671
+ function renderGrid(state) {
1672
+ for (let i = 0; i < state.cells.length; i += 1) {
1673
+ if (i === state.focusedIndex) focusCell(state.cells[i], state.mode);
1674
+ else restCell(state.cells[i]);
1495
1675
  }
1496
- // Auto-stepping stays inside the mode the visitor stopped on, so the cell
1497
- // animates what they asked to see instead of drifting through the rest.
1498
- cycleSteppers.push(() => {
1499
- if (previewIndex >= 0) return;
1500
- const mode = frames[frameIndex].mode;
1501
- if (mode === "static") return;
1502
- const inMode = [];
1503
- for (let i = 0; i < frames.length; i += 1) if (frames[i].mode === mode) inMode.push(i);
1504
- if (inMode.length < 2) return;
1505
- frameIndex = inMode[(inMode.indexOf(frameIndex) + 1) % inMode.length];
1506
- showFrame();
1507
- });
1508
- showFrame();
1509
- return holder;
1510
1676
  }
1511
1677
 
1512
1678
  for (const card of cards) {
1513
1679
  const swatchRow = card.querySelector('.tier-row[data-tier="large"] .swatches');
1514
1680
  if (!swatchRow) continue;
1515
1681
  const cls = card.dataset.cls;
1516
- const rows = Array.from(swatchRow.querySelectorAll(".swatch"))
1517
- .map((el) => ({ el, property: el.dataset.property || "", frame: frameFromSwatch(el) }))
1518
- .filter((r) => r.frame);
1519
- const baseSwatch = swatchRow.querySelector(".swatch.plain, .swatch.fallback");
1520
- const baseFrame = frameFromSwatch(baseSwatch);
1521
- if (!baseSwatch || !baseFrame) continue;
1522
-
1523
- const moodRows = rows.filter((r) => r.property === MOOD_PROPERTY);
1682
+ const tiles = Array.from(swatchRow.querySelectorAll(".swatch")).map(tileOf).filter(Boolean);
1683
+
1684
+ const movingByVariant = {};
1685
+ for (const t of tiles) {
1686
+ if (t.pose !== "moving") continue;
1687
+ movingByVariant[t.label] = t.svg;
1688
+ t.el.remove();
1689
+ }
1690
+ const resting = tiles.filter((t) => t.pose !== "moving");
1691
+ for (const t of resting) {
1692
+ const key = t.kind === "plain" || t.kind === "fallback" ? "default" : t.label;
1693
+ if (movingByVariant[key]) movingSvgOf.set(t.el, { still: t.svg, moving: movingByVariant[key], showMoving: false });
1694
+ }
1695
+
1696
+ const base = resting.find((t) => t.kind === "plain") || resting.find((t) => t.kind === "fallback");
1697
+ if (!base) continue;
1698
+ const staticFrame = { svg: base.svg, label: "default" };
1524
1699
  const facingFrames = {};
1525
- for (const r of rows) { if (r.property === FACING_PROPERTY) facingFrames[r.frame.label] = r.frame; }
1526
- const movingRow = rows.find((r) => r.property === POSE_PROPERTY && r.frame.label === "moving");
1700
+ for (const t of resting) {
1701
+ if (t.property === FACING_PROPERTY && !t.label.includes(" + ")) facingFrames[t.label] = { svg: t.svg, label: t.label };
1702
+ }
1703
+ const moodTiles = resting.filter((t) => t.property === MOOD_PROPERTY && !t.label.includes(" + "));
1704
+ const turnFrames = turnFrameSequence(FACING_TURN_ORDER, { svg: staticFrame.svg, label: "centre" }, facingFrames);
1705
+ const moodFrames = moodFrameSequence({ svg: staticFrame.svg, label: cls }, moodTiles.map((t) => ({ svg: t.svg, label: t.label })));
1706
+ const movingFrames = movingByVariant.default
1707
+ ? movingFrameSequence({ svg: staticFrame.svg, label: "idle" }, { svg: movingByVariant.default, label: "moving" })
1708
+ : [];
1709
+ if (!turnFrames.length && !moodFrames.length && !movingFrames.length) continue;
1527
1710
 
1528
- const modeFrames = displayModeSequence({ svg: baseFrame.svg, label: cls }, {
1529
- movingFrame: movingRow && movingRow.frame,
1530
- turnFrames: turnFrameSequence(FACING_TURN_ORDER, baseFrame, facingFrames),
1531
- moodFrames: moodFrameSequence(baseFrame && { svg: baseFrame.svg, label: cls }, moodRows.map((r) => r.frame)),
1711
+ const holder = document.createElement("div");
1712
+ holder.className = "swatch large cycle cycle-mode";
1713
+ holder.dataset.pose = "static";
1714
+ holder.innerHTML = '<button type="button" class="swatch-img" aria-label="focus the ' + esc(cls)
1715
+ + ' sprite, or switch its animation"></button>'
1716
+ + '<div class="swatch-caption"><span class="swatch-mode"></span><span class="swatch-label"></span><span class="swatch-pose"></span></div>';
1717
+ const cell = {
1718
+ holder,
1719
+ imgEl: holder.querySelector(".swatch-img"),
1720
+ modeEl: holder.querySelector(".swatch-mode"),
1721
+ labelEl: holder.querySelector(".swatch-label"),
1722
+ poseEl: holder.querySelector(".swatch-pose"),
1723
+ staticFrame,
1724
+ frames: { turnFrames, moodFrames, movingFrames },
1725
+ active: [],
1726
+ };
1727
+ if (movingByVariant.default) movingSvgOf.set(holder, { still: staticFrame.svg, moving: movingByVariant.default, showMoving: false });
1728
+ movingSvgOf.delete(base.el);
1729
+ wireSwatchHover(holder);
1730
+ swatchRow.replaceChild(holder, base.el);
1731
+
1732
+ const grid = card.closest(".cards");
1733
+ if (!grid) continue;
1734
+ if (!grids.has(grid)) grids.set(grid, { cells: [], mode: "turning", focusedIndex: 0 });
1735
+ const state = grids.get(grid);
1736
+ const myIndex = state.cells.length;
1737
+ state.cells.push(cell);
1738
+ cell.imgEl.addEventListener("click", () => {
1739
+ if (state.focusedIndex === myIndex) state.mode = nextFocusMode(state.mode);
1740
+ else state.focusedIndex = myIndex;
1741
+ renderGrid(state);
1532
1742
  });
1533
- if (modeFrames.length) swatchRow.replaceChild(makeModeCell(modeFrames, cls), baseSwatch);
1534
1743
  }
1535
- if (cycleSteppers.length && !reducedMotion) {
1536
- setInterval(() => { for (const stepFrame of cycleSteppers) stepFrame(); }, CYCLE_FRAME_DELAY_MS);
1744
+ for (const state of grids.values()) renderGrid(state);
1745
+
1746
+ tickHandlers.push(() => {
1747
+ for (const state of grids.values()) {
1748
+ const cell = state.cells[state.focusedIndex];
1749
+ if (!cell || !cell.active.length) continue;
1750
+ const frame = frameAtTick(cell.active, tick);
1751
+ cell.imgEl.innerHTML = frame.svg;
1752
+ cell.labelEl.textContent = frame.label;
1753
+ }
1754
+ });
1755
+
1756
+ if (!reducedMotion) {
1757
+ setInterval(() => {
1758
+ tick += 1;
1759
+ for (const step of tickHandlers) step();
1760
+ }, CYCLE_FRAME_DELAY_MS);
1537
1761
  }
1538
1762
  })();
1539
1763
  </script>
@@ -1560,7 +1784,7 @@ ${dockScripts}
1560
1784
  * this page. Same chrome, same styling, same scripts as every per-group
1561
1785
  * page — renderSpriteCatalogPage owns all of that; this function only
1562
1786
  * picks which body and nav go in it. */
1563
- export function renderSpriteCatalogLandingHtml({ title = DEFAULT_TITLE, iconTemplates = [], largeTemplates = [], factRows = [], spritesBundleAvailable = false } = {}) {
1787
+ export function renderSpriteCatalogLandingHtml({ title = DEFAULT_TITLE, iconTemplates = [], largeTemplates = [], factRows = [], spritesBundleAvailable = false, adventureRoomClasses = [] } = {}) {
1564
1788
  const entries = buildSpriteCatalogEntries({ iconTemplates, largeTemplates, factRows });
1565
1789
  const spritedClasses = new Set([...iconTemplates, ...largeTemplates].flatMap((t) => t?.classes || []));
1566
1790
  const sections = catalogSections(entries, spritedClasses);
@@ -1596,7 +1820,7 @@ export function renderSpriteCatalogLandingHtml({ title = DEFAULT_TITLE, iconTemp
1596
1820
  const navHtml = crossPageNavHtml(entries, {});
1597
1821
  const totalSwatches = entries.reduce((n, e) => n + e.iconSwatches.length + e.largeSwatches.length, 0);
1598
1822
  return renderSpriteCatalogPage({
1599
- title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable,
1823
+ title, entries, bodyHtml, navHtml, iconTemplates, largeTemplates, spritesBundleAvailable, adventureRoomClasses,
1600
1824
  footerClassCount: entries.length, footerSwatchCount: totalSwatches,
1601
1825
  });
1602
1826
  }