// The Concept Mill viewer. Reads the manifest embedded by AetheriaConceptMill, // renders the menu (top left), the readout (bottom right) and the corner // readouts, and owns the selection: URL hash #ship or #ship/variant. type Hardpoint = { qty: string; size: string; mount: string } type Variant = { id: string round: string image: string thumb: string prompt: string hypothesis?: string verdict?: string operator?: string pick: boolean } type Ship = { id: string name: string code: string faction: string role: string desig: string crew: string mass: string hardpoints: Hardpoint[] loadout: string[] concept: string notes: string beaten: string status: { kind: "pass" | "new" | "scrap"; stamp: string; verdict: string } variants: Variant[] defaultVariant: string } type Manifest = { sections: { kind: Ship["status"]["kind"]; title: string }[] votes: { enabled: boolean; endpoint?: string | null; bifrostUrl?: string | null } ships: Ship[] } const esc = (s: string) => s.replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]!) const pad = (n: number, w = 2) => String(n).padStart(w, "0") const glyphFor = (kind: Ship["status"]["kind"]) => ({ pass: "◆", new: "◇", scrap: "✕" })[kind] // Hardpoint size to a glyph class: weapons scale with size, gear gets a shape. function hardpointGlyph(size: string) { const s = size.toLowerCase() if (s === "heavy" || s === "oversized") return "w3" if (s === "medium") return "w2" if (s === "small" || s === "light" || s === "cell") return "w1" if (s === "sensor") return "sensor" if (s === "built-in") return "built" return "gear" } // Decorative coordinates: stable per ship, playful, never data. function bearing(id: string) { let h = 2166136261 for (const c of id) h = Math.imul(h ^ c.charCodeAt(0), 16777619) const x = ((h >>> 0) % 2000) / 10 - 100 const y = (((h >>> 11) >>> 0) % 2000) / 10 - 100 return `${x >= 0 ? "+" : ""}${x.toFixed(1)} ${y >= 0 ? "+" : ""}${y.toFixed(1)}` } function setup(root: HTMLElement) { const data: Manifest = JSON.parse(root.querySelector(".cm-data")!.textContent ?? "{}") const ships = data.ships const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches const narrow = window.matchMedia("(max-width: 800px)") const stage = root.querySelector(".cm-stage")! const live = stage.querySelector(".cm-render")! const next = live.cloneNode() as HTMLImageElement next.classList.remove("is-live") next.removeAttribute("src") stage.insertBefore(next, live.nextSibling) const sweep = stage.querySelector(".cm-sweep")! const sectionTitle = (kind: string) => data.sections.find((s) => s.kind === kind)?.title ?? kind const counts = data.sections.map((s) => `${ships.filter((x) => x.status.kind === s.kind).length} ${s.title.toLowerCase()}`) // ---------- menu ---------- let menuHtml = "" for (const section of data.sections) { const inSection = ships.filter((s) => s.status.kind === section.kind) if (!inSection.length) continue menuHtml += `

${esc(section.title)} ${inSection.length}

` for (const faction of [...new Set(inSection.map((s) => s.faction))]) { menuHtml += `

${esc(faction)}

    ` for (const ship of inSection.filter((s) => s.faction === faction)) { const i = ships.indexOf(ship) const v = ship.variants.find((x) => x.id === ship.defaultVariant)! menuHtml += `
  • ` } menuHtml += `
` } menuHtml += `
` } root.insertAdjacentHTML( "beforeend", `
`, ) const menu = root.querySelector(".cm-menu")! const readout = root.querySelector(".cm-readout")! const readoutBody = readout.querySelector(".cm-readout-body")! const readoutTag = readout.querySelector(".cm-readout-tag")! const items = Array.from(menu.querySelectorAll(".cm-item")) const panels = { menu, readout } // Selection state: the ship by index into the menu order, and its render. let shipIndex = 0 let variantId = "" let frame = 0 // ---------- panels ---------- function setOpen(name: keyof typeof panels, open: boolean) { const panel = panels[name] const wasOpen = panel.classList.contains("is-open") panel.classList.toggle("is-open", open) if (open && !wasOpen && name === "menu") revealCurrent() root.querySelectorAll(`[data-toggle="${name}"]`).forEach((b) => b.setAttribute("aria-expanded", String(open))) // On a phone the panels are bottom sheets: one at a time. if (open && narrow.matches) setOpen(name === "menu" ? "readout" : "menu", false) } const isOpen = (name: keyof typeof panels) => panels[name].classList.contains("is-open") setOpen("menu", !narrow.matches) setOpen("readout", !narrow.matches) // Scroll only the menu body: scrollIntoView would also move the fixed root. function revealCurrent() { const b = items.find((x) => Number(x.dataset.ship) === shipIndex) const body = menu.querySelector(".cm-body")! if (!b || !isOpen("menu")) return const top = b.offsetTop - body.offsetTop if (top < body.scrollTop || top + b.offsetHeight > body.scrollTop + body.clientHeight) { body.scrollTop = top - body.clientHeight / 2 } } // ---------- votes slot (hidden until configured) ---------- let tallies: Record | null = null const votesOn = Boolean(data.votes?.enabled && data.votes.endpoint) if (votesOn) { fetch(data.votes.endpoint!, { credentials: "omit" }) .then((r) => (r.ok ? r.json() : null)) .then((t) => { tallies = t render(false) }) .catch(() => {}) } // ---------- selection ---------- function parseHash() { const [shipId, vId] = decodeURIComponent(location.hash.replace(/^#/, "")).split("/") // Old card anchors named the image (e.g. #vasuki2); map them to the ship. const i = ships.findIndex((s) => s.id === shipId || s.variants.some((v) => v.image.endsWith(`/${shipId}.webp`))) return i < 0 ? null : { i, v: ships[i].variants.some((x) => x.id === vId) ? vId : ships[i].defaultVariant } } function select(i: number, vId?: string, writeHash = true) { const changedShip = i !== shipIndex || !variantId shipIndex = (i + ships.length) % ships.length const ship = ships[shipIndex] variantId = vId && ship.variants.some((v) => v.id === vId) ? vId : ship.defaultVariant if (writeHash) { const hash = `#${ship.id}${variantId === ship.defaultVariant ? "" : `/${variantId}`}` if (location.hash !== hash) history.replaceState(history.state, "", hash) } show(changedShip) } function step(delta: number) { select(shipIndex + delta) } function stepVariant(delta: number) { const ship = ships[shipIndex] const at = ship.variants.findIndex((v) => v.id === variantId) const to = at + delta if (to >= 0 && to < ship.variants.length) select(shipIndex, ship.variants[to].id) } let liveRef = live let nextRef = next function swap(variant: Variant, ship: Ship) { if (liveRef.getAttribute("src") === variant.image) { liveRef.classList.add("is-live") return } const target = nextRef target.alt = `Concept render of the ${ship.name}, ${variant.round}` target.src = variant.image const token = (target.dataset.token = String(Date.now())) const done = () => { if (target.dataset.token !== token) return liveRef.classList.remove("is-live") target.classList.add("is-live") nextRef = liveRef liveRef = target } target.decode().then(done, done) if (!reduce) { sweep.classList.remove("is-running") void sweep.offsetWidth sweep.classList.add("is-running") } } function show(changedShip: boolean) { const ship = ships[shipIndex] const variant = ship.variants.find((v) => v.id === variantId)! swap(variant, ship) items.forEach((b) => { const on = Number(b.dataset.ship) === shipIndex b.classList.toggle("is-current", on) b.setAttribute("aria-current", on ? "true" : "false") }) if (changedShip) revealCurrent() root.querySelector(".cm-dock-name")!.textContent = ship.name root.querySelector(".cm-glyph")!.textContent = glyphFor(ship.status.kind) root.querySelector(".cm-bearing")!.textContent = bearing(ship.id) root.querySelector(".cm-round")!.textContent = variant.round readout.dataset.code = ship.code readout.dataset.kind = ship.status.kind readoutTag.textContent = `MILL-${pad(shipIndex + 1)} · ${ship.code}` render(changedShip) // Warm the neighbours so stepping feels instant. for (const d of [1, -1]) { const n = ships[(shipIndex + d + ships.length) % ships.length] new Image().src = n.variants.find((v) => v.id === n.defaultVariant)!.image } } function render(animate: boolean) { const ship = ships[shipIndex] const variant = ship.variants.find((v) => v.id === variantId)! const glyphs = ship.hardpoints .flatMap((h) => { const n = /^\d+$/.test(h.qty) ? Math.min(Number(h.qty), 12) : 1 return Array.from({ length: n }, () => ``) }) .join("") const rows = ship.hardpoints .map((h) => `${esc(h.qty)}${esc(h.size)}${esc(h.mount)}`) .join("") const variantStrip = ship.variants.length > 1 ? `
${ship.variants .map( (v) => ``, ) .join("")}
` : "" const note = variant.hypothesis || variant.verdict || variant.operator ? `
${variant.hypothesis ? `

Hypothesis${esc(variant.hypothesis)}

` : ""}${variant.verdict ? `

Lab verdict${esc(variant.verdict)}

` : ""}${variant.operator ? `

Operator“${esc(variant.operator)}”

` : ""}
` : "" const tally = votesOn && tallies?.[ship.id] const votes = votesOn ? `
Votes${tally ? `▲ ${tally.up}▼ ${tally.down}` : `—`}${data.votes.bifrostUrl ? `Vote on Bifrost ↗` : ""}
` : `` readoutBody.innerHTML = `

${esc(ship.faction)} · ${esc(ship.role)}

${esc(ship.name)}

${esc(ship.status.stamp)}${variant.pick ? `Lab pick` : ""}${esc(variant.round)}

${variantStrip}${note}
Designation
${esc(ship.desig)}
Maker
${esc(ship.faction)}
Class
${esc(ship.role)}
Crew
${esc(ship.crew)}
Mass class
${esc(ship.mass)}
Status
${esc(ship.status.verdict)}

Hardpoints

${rows}
QtySizeMount · arc

Default loadout

    ${ship.loadout.map((x) => `
  • ${esc(x)}
  • `).join("")}

Play concept

${esc(ship.concept)}

Notes

${esc(ship.notes)}

Beaten by

${esc(ship.beaten)}

${votes} ` if (animate && !reduce) { readoutBody.classList.remove("is-revealing") void readoutBody.offsetWidth readoutBody.classList.add("is-revealing") } if (animate) readoutBody.scrollTop = 0 } // ---------- events ---------- function onClick(e: MouseEvent) { const t = e.target as HTMLElement const item = t.closest("[data-ship]") if (item) { select(Number(item.dataset.ship)) if (narrow.matches) setOpen("menu", false) return } const v = t.closest("[data-variant]") if (v) return select(shipIndex, v.dataset.variant) const s = t.closest("[data-step]") if (s) return step(Number(s.dataset.step)) const tog = t.closest("[data-toggle]") if (tog) { const name = tog.dataset.toggle as keyof typeof panels setOpen(name, !isOpen(name)) } } function onKey(e: KeyboardEvent) { if (e.defaultPrevented || e.altKey || e.ctrlKey || e.metaKey) return const t = e.target as HTMLElement if (t.closest("input, textarea, select, [contenteditable], .search")) return const inPanel = Boolean(t.closest(".cm-body")) if (e.key === "ArrowRight") step(1) else if (e.key === "ArrowLeft") step(-1) else if (e.key === "]" || (e.key === "ArrowDown" && !inPanel)) stepVariant(1) else if (e.key === "[" || (e.key === "ArrowUp" && !inPanel)) stepVariant(-1) else if (e.key === "Escape") { setOpen("menu", false) setOpen("readout", false) } else if (e.key === "m" || e.key === "M") setOpen("menu", !isOpen("menu")) else if (e.key === "r" || e.key === "R") setOpen("readout", !isOpen("readout")) else return e.preventDefault() } function onHash() { const h = parseHash() if (h) select(h.i, h.v, false) } // Horizontal swipe on the stage steps through ships. let touch: { x: number; y: number } | null = null const onTouchStart = (e: TouchEvent) => { touch = { x: e.touches[0].clientX, y: e.touches[0].clientY } } const onTouchEnd = (e: TouchEvent) => { if (!touch) return const dx = e.changedTouches[0].clientX - touch.x const dy = e.changedTouches[0].clientY - touch.y touch = null if (Math.abs(dx) > 48 && Math.abs(dx) > Math.abs(dy) * 1.5) step(dx < 0 ? 1 : -1) } // The one ambient element: a frame counter, still under reduced motion. const counter = root.querySelector(".cm-frame-count")! let raf = 0 let last = 0 const tick = (t: number) => { if (t - last > 80) { last = t counter.textContent = pad(++frame % 1000000, 6) } raf = requestAnimationFrame(tick) } if (!reduce) raf = requestAnimationFrame(tick) root.addEventListener("click", onClick) document.addEventListener("keydown", onKey) window.addEventListener("hashchange", onHash) stage.addEventListener("touchstart", onTouchStart, { passive: true }) stage.addEventListener("touchend", onTouchEnd, { passive: true }) // The server-rendered ship stays dark unless it is the one the hash asks // for, so a slow deep link never shows the wrong ship first. live.classList.remove("is-live") const initial = parseHash() select(initial?.i ?? 0, initial?.v, Boolean(initial)) root.classList.add("is-ready") return () => { cancelAnimationFrame(raf) root.removeEventListener("click", onClick) document.removeEventListener("keydown", onKey) window.removeEventListener("hashchange", onHash) } } document.addEventListener("nav", () => { const root = document.querySelector("[data-concept-mill]") if (!root || root.classList.contains("is-ready")) return const cleanup = setup(root) window.addCleanup(cleanup) })