@polycode-projects/the-mechanical-code-talker 5.0.25 → 5.0.27
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.
- package/README.md +74 -11
- package/bin/tmct.mjs +81 -0
- package/package.json +6 -1
- package/src/adapters/corpus/courtesy.mjs +91 -28
- package/src/adapters/corpus/dbpedia-lookup-live.mjs +116 -0
- package/src/adapters/corpus/news-sources.mjs +436 -0
- package/src/adapters/corpus/research-source.mjs +16 -3
- package/src/adapters/corpus/wiktionary-live.mjs +158 -0
- package/src/adapters/news-store.mjs +87 -0
- package/src/adapters/toml-config.mjs +18 -0
- package/src/domain/ask.mjs +19 -6
- package/src/domain/choice-question.mjs +275 -0
- package/src/domain/cli-verbs.mjs +20 -0
- package/src/domain/codegraph.mjs +8 -1
- package/src/domain/dialogue-acts.mjs +1 -0
- package/src/domain/el-classify.mjs +569 -0
- package/src/domain/fact-phrase.mjs +70 -0
- package/src/domain/feed-normalize.mjs +224 -0
- package/src/domain/grammar/ace.mjs +223 -7
- package/src/domain/grammar/lexicon-core.json +2 -0
- package/src/domain/memory/trust.mjs +15 -0
- package/src/domain/news-feed.mjs +219 -0
- package/src/domain/reasoning-config.mjs +56 -0
- package/src/domain/sprite-animation.mjs +20 -2
- package/src/domain/tableau.mjs +1225 -0
- package/src/domain/term-ledger.mjs +118 -0
- package/src/services/chat.mjs +523 -20
- package/src/services/extract-facts.mjs +91 -1
- package/src/services/index.mjs +12 -0
- package/src/services/init.mjs +33 -0
- package/src/services/news-viz.mjs +489 -0
- package/src/services/news.mjs +918 -0
- package/src/services/sprite-catalog-viz.mjs +148 -78
- package/src/surfaces/web/memory-ask-browser.bundle.js +132 -132
- package/src/surfaces/web/news-browser-entry.mjs +384 -0
- package/src/surfaces/web/sprites-browser-entry.mjs +4 -4
|
@@ -55,7 +55,8 @@ 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
56
|
import {
|
|
57
57
|
SPRITE_POSE_REST, SPRITE_POSE_MOVING, isMovingSwatchLabel,
|
|
58
|
-
|
|
58
|
+
initialCardAnimation, cardAnimationClick,
|
|
59
|
+
frameAtTick, focusModeFrames, oscillateWalkStep, walkFrameLabelCandidates,
|
|
59
60
|
} from "../domain/sprite-animation.mjs";
|
|
60
61
|
import { sceneVocabulary, randomSceneSentence, roomClassesFromWorldFacts } from "../domain/scene-random.mjs";
|
|
61
62
|
import { splitSceneBackdrop } from "../domain/scene-compose.mjs";
|
|
@@ -278,10 +279,11 @@ export function catalogSections(entries, spritedClasses) {
|
|
|
278
279
|
|
|
279
280
|
// ---- the section ontology trees ----
|
|
280
281
|
//
|
|
281
|
-
// Above each
|
|
282
|
-
// classes live in, drawn from the
|
|
283
|
-
// print — so a pill and a tree node
|
|
284
|
-
// parents are. A tree carries three
|
|
282
|
+
// Above each catalog section — on the landing page and on every group page —
|
|
283
|
+
// sits the real rdfs:subClassOf graph its own classes live in, drawn from the
|
|
284
|
+
// SAME fact rows the cards' ancestry pills print — so a pill and a tree node
|
|
285
|
+
// can never disagree about who a class's parents are. A tree carries three
|
|
286
|
+
// kinds of node:
|
|
285
287
|
// - the section's own classes ("member"),
|
|
286
288
|
// - every term their own chains walk through ("ancestor"), and
|
|
287
289
|
// - any OTHER catalog class that hangs off one of those ancestors
|
|
@@ -340,6 +342,21 @@ export function ontologyTreeNodeId(sectionSlug, term) {
|
|
|
340
342
|
return `tree-${sectionSlug}-${slugify(term)}`;
|
|
341
343
|
}
|
|
342
344
|
|
|
345
|
+
/** The svg path a tree connector follows from a parent node's right edge to
|
|
346
|
+
* its child's left edge — a curve that leaves and arrives on a horizontal
|
|
347
|
+
* tangent, so every line meets its box flat instead of slashing through a
|
|
348
|
+
* neighbour. Points are `{x, y}` in the tree's own pixel space; the floor
|
|
349
|
+
* on the bend keeps a short or backward edge (a recorded subClassOf loop)
|
|
350
|
+
* visibly curved rather than collapsing to a spike. Pure; self-contained,
|
|
351
|
+
* `.toString()`-splice safe. */
|
|
352
|
+
export function treeEdgePath(from, to) {
|
|
353
|
+
const bend = Math.max(10, Math.abs(to.x - from.x) / 2);
|
|
354
|
+
return "M" + from.x + " " + from.y
|
|
355
|
+
+ "C" + (from.x + bend) + " " + from.y
|
|
356
|
+
+ " " + (to.x - bend) + " " + to.y
|
|
357
|
+
+ " " + to.x + " " + to.y;
|
|
358
|
+
}
|
|
359
|
+
|
|
343
360
|
/** The stand-in text a tree node shows when its term carries no sprite of its
|
|
344
361
|
* own, written from the term's own place in the graph and nothing else. The
|
|
345
362
|
* node prints its name alongside, so this says only what the name doesn't. A
|
|
@@ -671,17 +688,18 @@ export function sceneComposerClassIndex(entries) {
|
|
|
671
688
|
//
|
|
672
689
|
// A card's large tier varies on three axes: mood (mgx:feels), facing
|
|
673
690
|
// (mgx:faces) and pose (mgx:pose). One image cell per class stands where its
|
|
674
|
-
// plain swatch was
|
|
675
|
-
//
|
|
676
|
-
//
|
|
677
|
-
//
|
|
678
|
-
//
|
|
679
|
-
//
|
|
680
|
-
//
|
|
681
|
-
//
|
|
682
|
-
//
|
|
683
|
-
//
|
|
684
|
-
//
|
|
691
|
+
// plain swatch was, and every one of them is clickable: a click on a resting
|
|
692
|
+
// cell starts it animating (turning rotation first, with the focus outline),
|
|
693
|
+
// a click on an animating cell toggles it between turning and
|
|
694
|
+
// emotion-cycling (sprite-animation.mjs's cardAnimationClick). Each cell
|
|
695
|
+
// owns its own state, so any number of cells can run at once on the shared
|
|
696
|
+
// tick, each keeping its state while the visitor moves around the page. The
|
|
697
|
+
// page builds the frames client-side out of its own already-rendered
|
|
698
|
+
// swatches (see the inline script below — the same read-the-DOM posture the
|
|
699
|
+
// scene composer's class index takes), but the frame ORDER and the tempo are
|
|
700
|
+
// real logic worth pinning on their own, so they live here as pure functions
|
|
701
|
+
// the page splices in by `.toString()`. One delay constant serves every
|
|
702
|
+
// axis, so they can't drift into three tempos.
|
|
685
703
|
//
|
|
686
704
|
// A `frame` is `{svg, label}`. An empty return means there is nothing worth
|
|
687
705
|
// animating for that class, and the page leaves its static swatch alone.
|
|
@@ -748,11 +766,10 @@ export function classAnchorId(className) {
|
|
|
748
766
|
return `card-${slugify(className)}`;
|
|
749
767
|
}
|
|
750
768
|
|
|
751
|
-
/** A card's ancestry pills. With a `treeAnchorBase` (the href prefix for
|
|
752
|
-
* card's own section tree
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
* tree node. Without one the pills stay plain text. */
|
|
769
|
+
/** A card's ancestry pills. With a `treeAnchorBase` (the href prefix for
|
|
770
|
+
* this card's own section tree, `#tree-<section>-`) each pill is a real
|
|
771
|
+
* in-page link to that term's own tree node. Without one the pills stay
|
|
772
|
+
* plain text. */
|
|
756
773
|
function chainHtml(chain, treeAnchorBase = null) {
|
|
757
774
|
const shown = chain.slice(0, MAX_CHAIN_DISPLAY);
|
|
758
775
|
const rest = chain.length - shown.length;
|
|
@@ -791,7 +808,12 @@ function treeNodeHtml(node, { sectionSlug, entriesByClass, resolveNodeSprite })
|
|
|
791
808
|
}
|
|
792
809
|
|
|
793
810
|
/** One section's tree, in its own scrolling box so a wide graph never widens
|
|
794
|
-
* the page itself. Levels run left to right, widest concept first.
|
|
811
|
+
* the page itself. Levels run left to right, widest concept first. The
|
|
812
|
+
* `.tree-edges` svg is the connector layer: the page script draws one line
|
|
813
|
+
* per parent link after layout (node heights depend on wrapped text, so the
|
|
814
|
+
* geometry can only be measured in the browser), reading the same
|
|
815
|
+
* `.tree-up` links the nodes print — a line and an "under x" label can
|
|
816
|
+
* never disagree. */
|
|
795
817
|
export function ontologyTreeHtml(tree, options) {
|
|
796
818
|
const { sectionLabel } = options;
|
|
797
819
|
const levelHtml = (nodes, level) =>
|
|
@@ -809,22 +831,21 @@ export function ontologyTreeHtml(tree, options) {
|
|
|
809
831
|
return `<div class="ontology">
|
|
810
832
|
<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>
|
|
811
833
|
<div class="tree-scroll" tabindex="0" role="group" aria-label="ontology tree for ${escapeHtml(sectionLabel)}">
|
|
812
|
-
<div class="ontology-tree">${branches}${apart}</div>
|
|
834
|
+
<div class="ontology-tree"><svg class="tree-edges" aria-hidden="true"></svg>${branches}${apart}</div>
|
|
813
835
|
</div>
|
|
814
836
|
${note}
|
|
815
837
|
</div>`;
|
|
816
838
|
}
|
|
817
839
|
|
|
818
840
|
/** The two per-section functions every page-body builder below needs: the
|
|
819
|
-
* tree to draw above a section
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
function sectionTreeRenderers({ entries, largeTemplates, factRows, spritedClasses
|
|
841
|
+
* tree to draw above a section and the href prefix that section's ancestry
|
|
842
|
+
* pills point at. Every sprite page draws its own sections' trees — the
|
|
843
|
+
* landing page one per section, a group page one per cluster — so a pill is
|
|
844
|
+
* always an in-page anchor. Pure given already-loaded inputs. */
|
|
845
|
+
function sectionTreeRenderers({ entries, largeTemplates, factRows, spritedClasses }) {
|
|
824
846
|
const entriesByClass = new Map(entries.map((e) => [e.className, e]));
|
|
825
847
|
const index = subClassIndex(factRows);
|
|
826
848
|
const treeFor = (section) => {
|
|
827
|
-
if (!drawsTrees) return "";
|
|
828
849
|
const sectionSlug = sectionSlugFor(section);
|
|
829
850
|
const tree = buildOntologyTree(section, { index, spritedClasses, entriesByClass });
|
|
830
851
|
return ontologyTreeHtml(tree, {
|
|
@@ -835,8 +856,7 @@ function sectionTreeRenderers({ entries, largeTemplates, factRows, spritedClasse
|
|
|
835
856
|
resolveSpriteAsset(term, [], [], largeTemplates, SPRITE_REGISTRY, { instanceKey: `tree-${sectionSlug}-${term}` }),
|
|
836
857
|
});
|
|
837
858
|
};
|
|
838
|
-
const anchorBaseFor = (section) =>
|
|
839
|
-
`${drawsTrees ? "" : "./sprites.html"}#tree-${sectionSlugFor(section)}-`;
|
|
859
|
+
const anchorBaseFor = (section) => `#tree-${sectionSlugFor(section)}-`;
|
|
840
860
|
return { treeFor, anchorBaseFor };
|
|
841
861
|
}
|
|
842
862
|
|
|
@@ -975,11 +995,8 @@ export function renderSpriteCatalogHtml({ title = DEFAULT_TITLE, iconTemplates =
|
|
|
975
995
|
resolveChip: (ancestor) =>
|
|
976
996
|
resolveSpriteAsset(ancestor, [], [], largeTemplates, SPRITE_REGISTRY, { instanceKey: `cluster-${ancestor}` }),
|
|
977
997
|
};
|
|
978
|
-
// A per-group page leaves the trees to sprites.html, which holds every
|
|
979
|
-
// section's, and points its own pills there. The full single-page render
|
|
980
|
-
// holds every section itself, so it draws and anchors its own.
|
|
981
998
|
const { treeFor, anchorBaseFor } = sectionTreeRenderers({
|
|
982
|
-
entries, largeTemplates, factRows, spritedClasses,
|
|
999
|
+
entries, largeTemplates, factRows, spritedClasses,
|
|
983
1000
|
});
|
|
984
1001
|
const groupsToRender = groupId ? CATALOG_GROUPS.filter((g) => g.id === groupId) : CATALOG_GROUPS;
|
|
985
1002
|
const bodyHtml = groupsToRender
|
|
@@ -1229,11 +1246,11 @@ ${THEME_TOKENS_CSS}
|
|
|
1229
1246
|
:root {
|
|
1230
1247
|
--ai-bar: #26272B; --ai-bar-ink: #E7E5DF;
|
|
1231
1248
|
--ai-panel: #EDECE8; --ai-panel-hi: #F4F3F0; --ai-canvas: #DFDEDA; --ai-edge: #C8C6C0;
|
|
1232
|
-
--checker: rgba(0, 0, 0, .07);
|
|
1249
|
+
--checker: rgba(0, 0, 0, .07); --tree-edge: #9B9990;
|
|
1233
1250
|
}
|
|
1234
|
-
@media (prefers-color-scheme: dark) { :root { --ai-panel: #26272B; --ai-panel-hi: #2D2E33; --ai-canvas: #1A1B1F; --ai-edge: #34363C; --checker: rgba(255, 255, 255, .055); } }
|
|
1235
|
-
:root[data-theme="dark"] { --ai-panel: #26272B; --ai-panel-hi: #2D2E33; --ai-canvas: #1A1B1F; --ai-edge: #34363C; --checker: rgba(255, 255, 255, .055); }
|
|
1236
|
-
:root[data-theme="light"] { --ai-panel: #EDECE8; --ai-panel-hi: #F4F3F0; --ai-canvas: #DFDEDA; --ai-edge: #C8C6C0; --checker: rgba(0, 0, 0, .07); }
|
|
1251
|
+
@media (prefers-color-scheme: dark) { :root { --ai-panel: #26272B; --ai-panel-hi: #2D2E33; --ai-canvas: #1A1B1F; --ai-edge: #34363C; --checker: rgba(255, 255, 255, .055); --tree-edge: #5A5D66; } }
|
|
1252
|
+
:root[data-theme="dark"] { --ai-panel: #26272B; --ai-panel-hi: #2D2E33; --ai-canvas: #1A1B1F; --ai-edge: #34363C; --checker: rgba(255, 255, 255, .055); --tree-edge: #5A5D66; }
|
|
1253
|
+
:root[data-theme="light"] { --ai-panel: #EDECE8; --ai-panel-hi: #F4F3F0; --ai-canvas: #DFDEDA; --ai-edge: #C8C6C0; --checker: rgba(0, 0, 0, .07); --tree-edge: #9B9990; }
|
|
1237
1254
|
body { margin: 0; background: var(--ai-canvas); color: var(--ink); font-family: ${SERIF_STACK}; font-size: 16px; line-height: 1.5; }
|
|
1238
1255
|
.mono { font-family: ${MONO_STACK}; }
|
|
1239
1256
|
main { max-width: 1240px; margin: 0 auto; padding: 0 1.2rem 2rem; }
|
|
@@ -1320,16 +1337,27 @@ ${THEME_TOKENS_CSS}
|
|
|
1320
1337
|
.ontology-legend .lg-dual::before { border-left: 3px solid var(--corpus); }
|
|
1321
1338
|
@media (max-width: 700px) { .ontology-legend { display: none; } }
|
|
1322
1339
|
.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%; }
|
|
1324
|
-
|
|
1340
|
+
.ontology-tree { position: relative; display: flex; flex-direction: column; gap: .8rem; width: max-content; min-width: 100%; }
|
|
1341
|
+
/* The connector layer: one drawn line per recorded parent link, painted
|
|
1342
|
+
under the node columns. The dual-parent accent matches the legend's own
|
|
1343
|
+
"two parents" border, so both edges into such a node read as one story. */
|
|
1344
|
+
.tree-edges { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
|
|
1345
|
+
.tree-edges path { fill: none; stroke: var(--tree-edge); stroke-width: 2; }
|
|
1346
|
+
.tree-edges path.edge-dual { stroke: var(--corpus); opacity: .7; }
|
|
1347
|
+
.tree-branch { display: flex; align-items: flex-start; gap: 1.15rem; }
|
|
1325
1348
|
.tree-apart { flex-direction: column; }
|
|
1326
1349
|
.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
1350
|
.tree-apart .tree-level { flex-direction: row; flex-wrap: wrap; width: auto; padding-top: 0; }
|
|
1328
|
-
|
|
1351
|
+
/* z-index 1 keeps the node columns painting over the connector layer, so
|
|
1352
|
+
a long edge dips behind the boxes it crosses instead of striking
|
|
1353
|
+
through their art. */
|
|
1354
|
+
.tree-level { display: flex; flex-direction: column; gap: .35rem; width: 9.4rem; flex: none; position: relative; z-index: 1; }
|
|
1329
1355
|
/* 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
|
-
|
|
1332
|
-
|
|
1356
|
+
one sits at — the number is the walk itself, not decoration.
|
|
1357
|
+
first-of-type, not first-child: the connector svg sits first in the
|
|
1358
|
+
tree. */
|
|
1359
|
+
.tree-branch:first-of-type:not(.tree-apart) .tree-level { padding-top: .9rem; }
|
|
1360
|
+
.tree-branch:first-of-type: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
1361
|
.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
1362
|
.tree-node.member { border-left: 3px solid var(--taught); }
|
|
1335
1363
|
.tree-node.sibling { opacity: .6; }
|
|
@@ -1462,7 +1490,9 @@ ${spriteBundleScript}
|
|
|
1462
1490
|
const moodFrameSequence = ${moodFrameSequence.toString()};
|
|
1463
1491
|
const turnFrameSequence = ${turnFrameSequence.toString()};
|
|
1464
1492
|
const movingFrameSequence = ${movingFrameSequence.toString()};
|
|
1465
|
-
const
|
|
1493
|
+
const initialCardAnimation = ${initialCardAnimation.toString()};
|
|
1494
|
+
const cardAnimationClick = ${cardAnimationClick.toString()};
|
|
1495
|
+
const treeEdgePath = ${treeEdgePath.toString()};
|
|
1466
1496
|
const frameAtTick = ${frameAtTick.toString()};
|
|
1467
1497
|
const focusModeFrames = ${focusModeFrames.toString()};
|
|
1468
1498
|
const oscillateWalkStep = ${oscillateWalkStep.toString()};
|
|
@@ -1569,6 +1599,42 @@ ${spriteBundleScript}
|
|
|
1569
1599
|
}
|
|
1570
1600
|
wireSceneComposer();
|
|
1571
1601
|
|
|
1602
|
+
// ---- the ontology connectors — one drawn line per recorded parent link,
|
|
1603
|
+
// read off the same in-tree ".tree-up" links the nodes print, so a line
|
|
1604
|
+
// and an "under x" label can never disagree. The geometry is measured
|
|
1605
|
+
// after layout (node heights depend on wrapped text), and redrawn whenever
|
|
1606
|
+
// a tree's own box changes size: its first real layout under
|
|
1607
|
+
// content-visibility, a viewport resize, a font swap.
|
|
1608
|
+
function drawTreeEdges(treeEl) {
|
|
1609
|
+
const edgesSvg = treeEl.querySelector(":scope > .tree-edges");
|
|
1610
|
+
if (!edgesSvg) return;
|
|
1611
|
+
const base = treeEl.getBoundingClientRect();
|
|
1612
|
+
if (!base.width) return;
|
|
1613
|
+
const edges = [];
|
|
1614
|
+
for (const node of treeEl.querySelectorAll(".tree-node")) {
|
|
1615
|
+
const parentLinks = node.querySelectorAll(".tree-up a");
|
|
1616
|
+
for (const link of parentLinks) {
|
|
1617
|
+
const parentId = decodeURIComponent((link.getAttribute("href") || "").slice(1));
|
|
1618
|
+
const parentEl = document.getElementById(parentId);
|
|
1619
|
+
if (!parentEl || !treeEl.contains(parentEl)) continue;
|
|
1620
|
+
const p = parentEl.getBoundingClientRect();
|
|
1621
|
+
const c = node.getBoundingClientRect();
|
|
1622
|
+
const d = treeEdgePath(
|
|
1623
|
+
{ x: Math.round(p.right - base.left), y: Math.round(p.top + p.height / 2 - base.top) },
|
|
1624
|
+
{ x: Math.round(c.left - base.left), y: Math.round(c.top + c.height / 2 - base.top) },
|
|
1625
|
+
);
|
|
1626
|
+
edges.push('<path class="edge' + (parentLinks.length > 1 ? " edge-dual" : "") + '" d="' + d + '"></path>');
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
edgesSvg.innerHTML = edges.join("");
|
|
1630
|
+
}
|
|
1631
|
+
const treeEls = Array.from(document.querySelectorAll(".ontology-tree"));
|
|
1632
|
+
for (const treeEl of treeEls) drawTreeEdges(treeEl);
|
|
1633
|
+
if (treeEls.length && typeof ResizeObserver === "function") {
|
|
1634
|
+
const treeRedraw = new ResizeObserver((entries) => { for (const entry of entries) drawTreeEdges(entry.target); });
|
|
1635
|
+
for (const treeEl of treeEls) treeRedraw.observe(treeEl);
|
|
1636
|
+
}
|
|
1637
|
+
|
|
1572
1638
|
// ---- the sprite tiles — pose-first captions everywhere: every tile reads
|
|
1573
1639
|
// "<variant> / static" at rest and "<variant> / moving" under the pointer,
|
|
1574
1640
|
// and a tile whose class really has that moving frame flip-books between
|
|
@@ -1619,18 +1685,21 @@ ${spriteBundleScript}
|
|
|
1619
1685
|
}
|
|
1620
1686
|
});
|
|
1621
1687
|
|
|
1622
|
-
// ---- the
|
|
1623
|
-
// swatch was, and
|
|
1624
|
-
//
|
|
1625
|
-
//
|
|
1626
|
-
//
|
|
1627
|
-
//
|
|
1628
|
-
//
|
|
1629
|
-
//
|
|
1630
|
-
//
|
|
1688
|
+
// ---- the animated cells — one image cell per class stands where the
|
|
1689
|
+
// plain swatch was, and every one of them is clickable. A click on a
|
|
1690
|
+
// resting cell starts it animating (turning rotation first) and gives it
|
|
1691
|
+
// the focus outline; a click on an animating cell toggles it between
|
|
1692
|
+
// turning and emotion-cycling (cardAnimationClick, spliced above). Each
|
|
1693
|
+
// cell owns its own state, so starting one never stops another — any
|
|
1694
|
+
// number can run at once on the shared tick, and each keeps its state
|
|
1695
|
+
// while the visitor moves around the page. The first cell of each card
|
|
1696
|
+
// grid starts on load, so the page moves before the first click. Frames
|
|
1697
|
+
// come off the card's own already-rendered swatches — this only ever
|
|
1698
|
+
// needs whatever cards THIS page renders, never the whole catalog.
|
|
1631
1699
|
//
|
|
1632
|
-
// Reduced motion stops the clock:
|
|
1633
|
-
// frame of its current mode, and clicks still switch focus
|
|
1700
|
+
// Reduced motion stops the clock: an animating cell then shows one real
|
|
1701
|
+
// frame of its current mode, and clicks still switch the focus treatment
|
|
1702
|
+
// and the mode as static frame changes.
|
|
1634
1703
|
function tileOf(el) {
|
|
1635
1704
|
const img = el.querySelector(".swatch-img");
|
|
1636
1705
|
const labelEl = el.querySelector(".swatch-label");
|
|
@@ -1645,7 +1714,8 @@ ${spriteBundleScript}
|
|
|
1645
1714
|
};
|
|
1646
1715
|
}
|
|
1647
1716
|
|
|
1648
|
-
const
|
|
1717
|
+
const animatedCells = [];
|
|
1718
|
+
const startedGrids = new Set();
|
|
1649
1719
|
|
|
1650
1720
|
function restCell(cell) {
|
|
1651
1721
|
cell.holder.classList.remove("focused");
|
|
@@ -1657,7 +1727,8 @@ ${spriteBundleScript}
|
|
|
1657
1727
|
cell.active = [];
|
|
1658
1728
|
}
|
|
1659
1729
|
|
|
1660
|
-
function
|
|
1730
|
+
function animateCell(cell) {
|
|
1731
|
+
const mode = cell.state.mode;
|
|
1661
1732
|
cell.holder.classList.add("focused");
|
|
1662
1733
|
cell.holder.dataset.mode = mode;
|
|
1663
1734
|
cell.active = focusModeFrames(mode, cell.frames);
|
|
@@ -1668,11 +1739,9 @@ ${spriteBundleScript}
|
|
|
1668
1739
|
cell.poseEl.textContent = "";
|
|
1669
1740
|
}
|
|
1670
1741
|
|
|
1671
|
-
function
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
else restCell(state.cells[i]);
|
|
1675
|
-
}
|
|
1742
|
+
function renderCell(cell) {
|
|
1743
|
+
if (cell.state.animating) animateCell(cell);
|
|
1744
|
+
else restCell(cell);
|
|
1676
1745
|
}
|
|
1677
1746
|
|
|
1678
1747
|
for (const card of cards) {
|
|
@@ -1711,7 +1780,7 @@ ${spriteBundleScript}
|
|
|
1711
1780
|
const holder = document.createElement("div");
|
|
1712
1781
|
holder.className = "swatch large cycle cycle-mode";
|
|
1713
1782
|
holder.dataset.pose = "static";
|
|
1714
|
-
holder.innerHTML = '<button type="button" class="swatch-img" aria-label="
|
|
1783
|
+
holder.innerHTML = '<button type="button" class="swatch-img" aria-label="animate the ' + esc(cls)
|
|
1715
1784
|
+ ' sprite, or switch its animation"></button>'
|
|
1716
1785
|
+ '<div class="swatch-caption"><span class="swatch-mode"></span><span class="swatch-label"></span><span class="swatch-pose"></span></div>';
|
|
1717
1786
|
const cell = {
|
|
@@ -1723,30 +1792,31 @@ ${spriteBundleScript}
|
|
|
1723
1792
|
staticFrame,
|
|
1724
1793
|
frames: { turnFrames, moodFrames, movingFrames },
|
|
1725
1794
|
active: [],
|
|
1795
|
+
state: initialCardAnimation(),
|
|
1726
1796
|
};
|
|
1727
1797
|
if (movingByVariant.default) movingSvgOf.set(holder, { still: staticFrame.svg, moving: movingByVariant.default, showMoving: false });
|
|
1728
1798
|
movingSvgOf.delete(base.el);
|
|
1729
1799
|
wireSwatchHover(holder);
|
|
1730
1800
|
swatchRow.replaceChild(holder, base.el);
|
|
1731
1801
|
|
|
1802
|
+
// The first cell of each card grid starts on load; the rest wait for
|
|
1803
|
+
// their own click.
|
|
1732
1804
|
const grid = card.closest(".cards");
|
|
1733
|
-
if (!grid)
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1805
|
+
if (grid && !startedGrids.has(grid)) {
|
|
1806
|
+
startedGrids.add(grid);
|
|
1807
|
+
cell.state = cardAnimationClick(cell.state);
|
|
1808
|
+
}
|
|
1809
|
+
animatedCells.push(cell);
|
|
1738
1810
|
cell.imgEl.addEventListener("click", () => {
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
renderGrid(state);
|
|
1811
|
+
cell.state = cardAnimationClick(cell.state);
|
|
1812
|
+
renderCell(cell);
|
|
1742
1813
|
});
|
|
1743
1814
|
}
|
|
1744
|
-
for (const
|
|
1815
|
+
for (const cell of animatedCells) renderCell(cell);
|
|
1745
1816
|
|
|
1746
1817
|
tickHandlers.push(() => {
|
|
1747
|
-
for (const
|
|
1748
|
-
|
|
1749
|
-
if (!cell || !cell.active.length) continue;
|
|
1818
|
+
for (const cell of animatedCells) {
|
|
1819
|
+
if (!cell.state.animating || !cell.active.length) continue;
|
|
1750
1820
|
const frame = frameAtTick(cell.active, tick);
|
|
1751
1821
|
cell.imgEl.innerHTML = frame.svg;
|
|
1752
1822
|
cell.labelEl.textContent = frame.label;
|
|
@@ -1789,7 +1859,7 @@ export function renderSpriteCatalogLandingHtml({ title = DEFAULT_TITLE, iconTemp
|
|
|
1789
1859
|
const spritedClasses = new Set([...iconTemplates, ...largeTemplates].flatMap((t) => t?.classes || []));
|
|
1790
1860
|
const sections = catalogSections(entries, spritedClasses);
|
|
1791
1861
|
const { treeFor, anchorBaseFor } = sectionTreeRenderers({
|
|
1792
|
-
entries, largeTemplates, factRows, spritedClasses,
|
|
1862
|
+
entries, largeTemplates, factRows, spritedClasses,
|
|
1793
1863
|
});
|
|
1794
1864
|
const bodyHtml = CATALOG_GROUPS.map((g) => {
|
|
1795
1865
|
const groupEntries = entries.filter((e) => e.group === g.id);
|