Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AIScientists Dev WorldSeed overlay layout

From Leeroopedia
Knowledge Sources
Domains Frontend, Layout
Last Updated 2026-10-26 18:00 GMT

Overview

Concrete pure-math layout engine for subtitle bubble positioning with agent-anchor computation, dodge, and clamp against canvas bounds, provided by the WorldSeed frontend.

Description

The overlay-layout module computes where speech/action bubbles appear on the map. `computeAgentAnchors` calculates agent dot center positions from zone layout (including zone rotation via trigonometric transform). `bubbleSize` derives bubble dimensions from pretext-measured text plus chrome constants (avatar, padding, gap). `computeOverlayLayout` groups cues by agent, stacks them vertically above each anchor, and applies dodge (try right, then left, then push up) and clamp (keep within canvas bounds) to avoid overlaps. The dodge algorithm processes agents sorted by anchor x for deterministic results. Same input always produces same output — zero DOM queries.

Usage

Import this module from the overlay component that renders subtitle bubbles. It receives pretext-measured cues and agent anchors, and returns pixel positions per cue ID.

Code Reference

Source Location

  • Repository: WorldSeed
  • File: frontend/src/lib/overlay-layout.ts

Signature

export function computeAgentAnchors(mapData: MapData, layout: Record<string, any>): AgentAnchor[];
export function bubbleSize(cue: MeasuredCue): { w: number; h: number };
export function computeOverlayLayout(
  cues: Array<{ cue: MeasuredCue; status: 'current' | 'fading' }>,
  anchors: AgentAnchor[],
  canvasBounds: { w: number; h: number },
): Map<string, { x: number; y: number }>;

Import

import { computeAgentAnchors, computeOverlayLayout, bubbleSize } from '@/lib/overlay-layout';

I/O Contract

Inputs

Name Type Required Description
mapData MapData Yes (anchors) │ Zone + agent data from map-layout
layout Record<string, any> Yes (anchors) │ UI config layout entries
cues Array Yes │ Measured cues with agentId + status
anchors AgentAnchor[] Yes │ Agent dot positions
canvasBounds { w, h } Yes │ Canvas pixel dimensions

Outputs

Name Type Description
computeAgentAnchors returns AgentAnchor[] │ Agent dot center + top positions
computeOverlayLayout returns Map<string, {x, y}> │ Cue ID → pixel position

Usage Examples

import { computeAgentAnchors, computeOverlayLayout } from '@/lib/overlay-layout';

// Compute agent positions from map data
const anchors = computeAgentAnchors(mapData, uiConfig.layout);

// Position active subtitle bubbles
const positions = computeOverlayLayout(
  activeCues,  // [{ cue: MeasuredCue, status: 'current' }]
  anchors,
  { w: canvasWidth, h: canvasHeight },
);
// positions.get(cueId) = { x: 120, y: 340 }

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment