Manual
Almnck.
Price: 50ⓐ

Almanack Interactive Figures Framework

Design document for interactive illustrations in Almanack articles, with “Regolith with Latitude” as the inaugural implementation.

Overview

A minimal framework for self-contained, interconnected interactive figures. Figures communicate via capability-based pub/sub (forward-compatible with Spritely Goblins OCapN). Progressive enhancement ensures static fallbacks for all browsers.

Architecture Decisions

Decision Choice Rationale
Figure location Referenced (per-article assets/figures/) Self-contained, no shared state between articles
Communication Capability-based pub/sub OCapN-compatible, explicit grants, no ambient authority
Figure format Single JS module Simple, one file per figure, metadata as exports
Web workers Optional optimization Not mandated; figures use if needed
Fallback strategy Progressive enhancement Static first, upgrade to WebGL when ready
Embedding syntax HTML <figure data-interactive> Explicit, works with existing md_in_html
Wiring Manifest file Figure-level concern, not article prose
Moon data Preprocessed JSON Authoritative NASA data, works offline

File Structure

editorial/articles/regolith-with-latitude/
├── article.md
└── assets/
    └── figures/
        ├── Makefile            # make sync, make clean
        ├── sync.sh             # fetches NASA data + fallback frames
        ├── manifest.json       # figure definitions + pub/sub wiring
        ├── runtime.js          # shared loader + pub/sub factory
        ├── moon-renderer.js    # shared moon display component
        ├── three-moons.js      # figure 1
        ├── latitude-picker.js  # figure 2
        ├── moon-timeline.js    # figure 3
        ├── data/
        │   └── moon-2026.json  # preprocessed NASA ephemeris
        ├── textures/
        │   ├── moon-color.jpg
        │   └── moon-displacement.jpg
        └── fallback/
            └── frames/         # NASA SVS static frames
                ├── 001.jpg
                └── ...

Pub/Sub Interface

Mirrors Spritely Goblins’ ^pubsub for future OCapN bridging:

const topic = pubsub();

topic.subscribe(handler);     // add subscriber
topic.unsubscribe(handler);   // remove subscriber
topic.publish(value);         // invoke all subscribers
topic.subscribers();          // introspection

Figures receive capabilities via injection, not lookup:

export function setup(container, { publish, subscribe, assets }) {
  // publish.latitude - capability to publish
  // subscribe.date - capability to subscribe
  // Can only access topics explicitly granted
}

Manifest Format

{
  "figures": {
    "three-moons": {
      "module": "./three-moons.js",
      "publishes": [],
      "subscribes": []
    },
    "latitude-picker": {
      "module": "./latitude-picker.js",
      "publishes": ["latitude"],
      "subscribes": []
    },
    "moon-timeline": {
      "module": "./moon-timeline.js",
      "publishes": ["date"],
      "subscribes": ["latitude"]
    }
  }
}

HTML can override manifest with data-publishes and data-subscribes attributes.

Figure Module Interface

// Metadata for documentation and tooling
export const meta = {
  name: 'figure-name',
  description: 'What this figure shows',
  version: '1.0.0',
};

// Called by runtime after capability injection
export function setup(container, { publish, subscribe, assets }) {
  // Initialize visualization
  // Subscribe to topics
  // Return cleanup function (optional)
  return () => { /* teardown */ };
}

Moon Renderer Component

Shared component returning a capability object:

import { createMoon } from './moon-renderer.js';

const moon = createMoon(container, { assets });

// The returned object IS the capability
moon.render({ size, brightness, latitude, date });
moon.destroy();

Parameters: - size: pixel diameter - brightness: 0-1 intensity - latitude: viewer’s Earth latitude (-90 to 90) - date: ISO date string or day-of-year

Handles progressive enhancement internally: shows static NASA frame immediately, upgrades to WebGL sphere with displacement mapping when textures load.

The Three Figures

Figure 1: three-moons.js

Static comparison of three moons at different sizes. Uses moon-renderer three times with fixed parameters. No pub/sub.

Figure 2: latitude-picker.js

Mercator Earth projection with draggable latitude line. Includes moon preview using moon-renderer. Publishes latitude on drag.

Figure 3: moon-timeline.js

Timeline slider spanning 2026. Shows moon at selected date using moon-renderer. Subscribes to latitude from figure 2. Publishes date for potential future use.

Data flow:

latitude-picker --[latitude]--> moon-timeline
                                     |
                                     v
                               moon-renderer

Article Integration

In article.md:

<figure data-interactive="latitude-picker" class="figure">
  <div class="earth-map"></div>
  <div class="moon-preview"></div>
  <figcaption>Drag to select your latitude</figcaption>
</figure>

<script type="module">
  import { initFigures } from './assets/figures/runtime.js';
  initFigures();
</script>

The runtime: 1. Finds [data-interactive] elements 2. Loads manifest for wiring defaults 3. Creates pub/sub topics 4. Dynamically imports figure modules 5. Calls setup() with container and capabilities

Data Pipeline

NASA SVS 5587 provides daily moon parameters: phase, libration, position angle, distance.

sync.sh fetches: 1. Ephemeris data → data/moon-2026.json 2. Fallback frames → fallback/frames/

JSON format:

{
  "year": 2026,
  "epoch": "2026-01-01",
  "days": [
    { "phase": 0.43, "libLat": 4.2, "libLon": -5.1, "posAngle": 23.4 },
    ...
  ]
}

~365 entries, ~5KB gzipped.

Fallback frames: Subset of NASA pre-rendered frames (every 3rd day). Moon-renderer selects closest frame when WebGL unavailable.

Progressive Enhancement Strategy

  1. HTML contains static fallback (image or <noscript> message)
  2. Runtime loads, imports figure modules
  3. Figure calls createMoon() which:
  4. Immediately renders closest NASA fallback frame
  5. Begins loading WebGL textures
  6. Swaps to WebGL sphere when ready
  7. User sees content fast, gets interactivity progressively

What This Is Not

Not React: No virtual DOM, no build step, no reactive re-renders. Direct canvas/WebGL rendering with imperative .render() calls.

Not HTMX territory: Figures are entirely client-side. No server round-trips. HTMX solves different problems (forms, server-rendered partials).

Closer to: Minimal event bus + Web Components philosophy + actor model patterns.

Scalability Decisions

Decisions made with long-term scaling in mind (many articles, many figures).

Runtime Duplication

Decision: Keep runtime duplicated per-article.

The runtime is ~100-150 lines of stable glue code. Duplication is acceptable; grep/sed handles bulk updates if ever needed. No shared infrastructure until proven necessary.

Component Reuse

Decision: Stay duplicated, symlink if genuine need arises.

Most figures are bespoke to their article. If true reuse emerges (e.g., three articles need moon-renderer), symlink to a shared location. Don’t build infrastructure speculatively.

Testing Strategy

Decision: Two-level testing.

  1. Fast local tests (Node/Deno/Bun) — Syntax, module imports, pub/sub wiring. Runs in milliseconds. Add make test to figures Makefile.

  2. Headless browser tests (Playwright) — Load article, verify figures initialize without JS errors. Slower, for CI or manual runs.

  3. Manual — Visual correctness, interaction feel.

Documentation

Decision: Central catalog + per-article README.

  • /doc/figures.md — Central catalog listing all articles with figures, components used, links
  • assets/figures/README.md — Per-article docs: how to run, modify, test these figures

Lazy Loading

Decision: Explicit opt-in via data-lazy attribute.

<!-- Loads immediately (default) -->
<figure data-interactive="latitude-picker">...</figure>

<!-- Loads when scrolled into view -->
<figure data-interactive="moon-timeline" data-lazy>...</figure>

Runtime uses IntersectionObserver only for flagged figures.

Mobile and Touch

Decision: Pointer Events API + responsive containers.

  • Use pointerdown/pointermove/pointerup for unified mouse/touch/stylus handling
  • Figures observe container size via ResizeObserver, adapt internally
  • No hardcoded pixel dimensions
export function setup(container, { publish, subscribe, assets }) {
  const resize = () => {
    const { width, height } = container.getBoundingClientRect();
    // Adapt canvas, layout, etc.
  };

  const ro = new ResizeObserver(resize);
  ro.observe(container);
  resize();

  return () => ro.disconnect();
}

Accessibility

Decision: Baked in from the start, not retrofitted.

Required for all figures: - ARIA labels — Announce purpose and current state - Keyboard controls — Arrow keys adjust values, Tab for focus, Enter to activate - Reduced motion — Respect prefers-reduced-motion media query

const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

Data Sync Fragility

Decision: Accept per-article fragility.

External data dependencies are rare. Each article’s sync.sh is independent. Fix when it breaks rather than building coordination infrastructure.

Initialization Order

Decision: Sticky last value on topics.

Topics remember their most recent published value. New subscribers receive it immediately on subscribe, eliminating timing bugs from async initialization.

const topic = pubsub();
topic.publish(45);  // Stored

// Later subscriber still receives the value
topic.subscribe((lat) => console.log(lat));  // Immediately logs 45

Future Considerations

  • OCapN bridging: Replace local pub/sub topics with remote Goblins stubs
  • Figure gallery: Tooling to preview figures standalone during development

Implementation Sequence

  1. Create assets/figures/ structure with Makefile
  2. Implement runtime.js (pub/sub + figure loader)
  3. Implement moon-renderer.js (static fallback first, then WebGL)
  4. Write sync.sh + data fetching scripts
  5. Implement three figures in order: three-moons, latitude-picker, moon-timeline
  6. Integrate into article markdown
  7. Test progressive enhancement across browsers