{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "linear-core",
  "type": "registry:ui",
  "title": "Isometric Object Core",
  "description": "The hairline isometric engine for the object catalogue: 2:1 projection, rounded extruded volumes, background-filled occlusion, 700 ms depth tween, 45 ms stagger and 260 ms colour fade.",
  "dependencies": [
    "motion"
  ],
  "meta": {
    "style": "linear",
    "timing": {
      "depth": 700,
      "stagger": 45,
      "color": 260,
      "stroke": 0.9
    }
  },
  "files": [
    {
      "path": "components/prequelui/linear/engine.ts",
      "target": "components/prequelui/linear/engine.ts",
      "type": "registry:lib",
      "content": "/*\n * PrequelUI Animate — hairline isometric engine.\n *\n * The geometry is generated every frame from a small set of local footprints.\n * It is deliberately dependency-free so the same file can be published as a\n * shadcn registry dependency and used outside this site.\n *\n * Projection: axonometric 2:1 (azimuth 45°, vertical factor 0.5).\n * Stroke: 0.9 px, non-scaling, round joins.\n * Occlusion: opaque silhouettes filled with the page colour, painted back to\n * front. No masks, no filters, no dash drawing.\n */\n\nexport type Point2 = readonly [number, number];\n\nexport type Foot =\n  | { kind: \"rect\"; x: number; y: number; w: number; d: number; r: number }\n  | { kind: \"circle\"; x: number; y: number; r: number }\n  | { kind: \"poly\"; points: ReadonlyArray<ReadonlyArray<number>> };\n\nexport type DetailTone = \"edge\" | \"hi\" | \"mid\" | \"lo\" | \"active\";\n\nexport type Detail =\n  | {\n      kind: \"bar\";\n      x: number;\n      y: number;\n      w: number;\n      d: number;\n      r?: number;\n      tone?: DetailTone;\n    }\n  | { kind: \"dot\"; x: number; y: number; r: number; tone?: DetailTone }\n  | {\n      kind: \"line\";\n      points: ReadonlyArray<Point2>;\n      tone?: DetailTone;\n      closed?: boolean;\n    }\n  | { kind: \"ring\"; x: number; y: number; r: number; tone?: DetailTone };\n\nexport type FlatBlock = {\n  kind?: \"prism\";\n  id: string;\n  foot: Foot;\n  /** Local z of the bottom face. Defaults to the plate top. */\n  base?: number;\n  /** Resting height of the prism. */\n  height: number;\n  /** Floating blocks move their whole body down instead of shrinking. */\n  float?: boolean;\n  /** Static blocks never react to the pointer. */\n  static?: boolean;\n  details?: Detail[];\n};\n\n/** A flat mark engraved on the vertical face of a sprite. */\nexport type SpriteDetail =\n  | {\n      kind: \"line\";\n      points: ReadonlyArray<Point2>;\n      tone?: DetailTone;\n      closed?: boolean;\n      group?: string;\n    }\n  | { kind: \"dot\"; x: number; y: number; r: number; tone?: DetailTone; group?: string }\n  | { kind: \"ring\"; x: number; y: number; r: number; tone?: DetailTone; group?: string };\n\nexport type SpriteMotionKind =\n  | \"spin\"\n  | \"pulse\"\n  | \"breathe\"\n  | \"blink\"\n  | \"sway\"\n  | \"bob\"\n  | \"flicker\"\n  | \"lift\";\n\nexport type SpriteMotion = {\n  kind: SpriteMotionKind;\n  /** Detail group to animate. Omit to move the whole sprite. */\n  target?: string;\n  /** Duration of one cycle, in milliseconds. */\n  period?: number;\n  /** Degrees, units or scale delta depending on the kind. */\n  amount?: number;\n  /** 0..1 offset inside the cycle. */\n  phase?: number;\n  /** Local pivot for rotations and scales, in sprite units. */\n  pivot?: Point2;\n};\n\n/**\n * A vertical cut-out standing on the plate. The outline lives in the local\n * (u, v) plane: u runs right and v runs up in screen space. The front face is\n * drawn at the projected base anchor; the back contour is shifted by\n * `thickness` along the plate's depth axis, which gives the second rim.\n */\nexport type SceneSprite = {\n  kind: \"sprite\";\n  id: string;\n  /** Local x of the front face centre. */\n  x: number;\n  /** Local y of the front face. The back face sits at y - thickness. */\n  y: number;\n  /** Local z of the bottom edge. Defaults to the plate top. */\n  z?: number;\n  thickness: number;\n  /** Closed loops, same winding. Overlapping loops are unioned. */\n  outline: ReadonlyArray<ReadonlyArray<Point2>>;\n  /** Closed loops with the opposite winding, cut out of the outline. */\n  holes?: ReadonlyArray<ReadonlyArray<Point2>>;\n  details?: SpriteDetail[];\n  motion?: SpriteMotion[];\n  /** Static sprites never react to the pointer. */\n  static?: boolean;\n};\n\nexport type SceneBlock = FlatBlock | SceneSprite;\n\nexport function isSprite(block: SceneBlock): block is SceneSprite {\n  return (block as SceneSprite).kind === \"sprite\";\n}\n\n/**\n * Height of the surface the objects rest on. A scene either declares a plate,\n * an explicit base, or a static sole block that owns its ground. Scenes with\n * no plate still need this value so engraved wells and flat marks sit on the\n * object's own sole instead of disappearing underneath it.\n */\nexport function sceneBase(scene: SceneDefinition): number {\n  if (scene.plate) return scene.plate.h;\n  if (typeof scene.base === \"number\") return scene.base;\n  let base = 0;\n  for (const block of scene.blocks) {\n    if (isSprite(block) || !block.static) continue;\n    base = Math.max(base, (block.base ?? 0) + block.height);\n  }\n  return base;\n}\n\nexport type SceneWell = {\n  foot: Foot;\n  /** Outward padding of the engraved ring. */\n  pad?: number;\n  tone?: \"lo\" | \"mid\";\n  /** Draw the whole groove instead of the camera-facing arc. */\n  full?: boolean;\n};\n\nexport type SceneDefinition = {\n  slug: string;\n  name: string;\n  family: string;\n  collection: string;\n  description: string;\n  /** Full sentence used as the accessible description of the figure. */\n  aria: string;\n  /** Explicit resting surface when there is no plate. */\n  base?: number;\n  plate?: {\n    x: number;\n    y: number;\n    w: number;\n    d: number;\n    r: number;\n    h: number;\n  } | null;\n  wells?: SceneWell[];\n  /** Flat marks engraved on the plate top. */\n  marks?: Detail[];\n  blocks: SceneBlock[];\n  /** Index of the block that is lit at rest. */\n  active?: number;\n};\n\nexport type Camera = {\n  scale: number;\n  ox: number;\n  oy: number;\n};\n\nexport type Projected = { x: number; y: number };\n\nconst C = Math.SQRT1_2;\nconst K = 0.5;\nconst ZH = Math.sqrt(1 - K * K);\nconst ARC_STEPS = 5;\nconst CIRCLE_STEPS = 48;\nconst FIT = { width: 400, height: 320, padX: 55, padY: 42, cy: 161 };\n\nexport const LINEAR_TIMING = {\n  sink: 6.5,\n  floor: 1.4,\n  lift: 2.2,\n  depth: 700,\n  stagger: 45,\n  color: 260,\n  touchLeave: 1400,\n} as const;\n\n/* -------------------------------------------------------------------------- */\n/* Projection                                                                  */\n/* -------------------------------------------------------------------------- */\n\nexport function rawProject(x: number, y: number, z: number): Projected {\n  return {\n    x: (x - y) * C,\n    y: (x + y) * C * K - z * ZH,\n  };\n}\n\nexport function project(\n  camera: Camera,\n  x: number,\n  y: number,\n  z: number,\n): Projected {\n  const p = rawProject(x, y, z);\n  return {\n    x: camera.ox + camera.scale * p.x,\n    y: camera.oy + camera.scale * p.y,\n  };\n}\n\n/**\n * Sprites are billboards: their local (u, v) plane is mapped to screen space,\n * one unit per projected unit. The base anchor still sits on the isometric\n * plate, and the back face is shifted along the plate's depth axis.\n */\nexport function spritePoint(\n  camera: Camera,\n  sprite: SceneSprite,\n  u: number,\n  v: number,\n  z: number,\n  back = false,\n): Projected {\n  const anchor = rawProject(sprite.x, sprite.y, z);\n  const bx =\n    anchor.x + u + (back ? sprite.thickness * C : 0);\n  const by =\n    anchor.y - v - (back ? sprite.thickness * C * K : 0);\n  return {\n    x: camera.ox + camera.scale * bx,\n    y: camera.oy + camera.scale * by,\n  };\n}\n\n/**\n * Inverse of `project` on a horizontal plane at height z. Used for pointer\n * hit-testing: every scene object is a vertical extrusion of its footprint,\n * so testing the footprint at the plate height is enough.\n */\nexport function unproject(\n  camera: Camera,\n  sx: number,\n  sy: number,\n  z: number,\n): Projected {\n  const px = (sx - camera.ox) / camera.scale;\n  const py = (sy - camera.oy) / camera.scale;\n  const dx = px / C;\n  const sum = (py + z * ZH) / (C * K);\n  return { x: (dx + sum) / 2, y: (sum - dx) / 2 };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Footprints                                                                  */\n/* -------------------------------------------------------------------------- */\n\ntype OutlinePoint = { x: number; y: number; nx: number; ny: number };\n\nfunction push(\n  out: OutlinePoint[],\n  x: number,\n  y: number,\n  nx: number,\n  ny: number,\n) {\n  const last = out[out.length - 1];\n  if (\n    last &&\n    Math.abs(last.x - x) < 0.0001 &&\n    Math.abs(last.y - y) < 0.0001\n  ) {\n    return;\n  }\n  out.push({ x, y, nx, ny });\n}\n\nfunction corner(\n  out: OutlinePoint[],\n  cx: number,\n  cy: number,\n  r: number,\n  from: number,\n  to: number,\n) {\n  for (let index = 1; index <= ARC_STEPS; index += 1) {\n    const a = from + ((to - from) * index) / ARC_STEPS;\n    push(out, cx + Math.cos(a) * r, cy + Math.sin(a) * r, Math.cos(a), Math.sin(a));\n  }\n}\n\nexport function outlineFor(foot: Foot): OutlinePoint[] {\n  if (foot.kind === \"rect\") {\n    const { x, y, w, d } = foot;\n    const radius = Math.max(0, Math.min(foot.r, Math.min(w, d) / 2));\n    const out: OutlinePoint[] = [];\n    if (radius <= 0.0001) {\n      push(out, x, y, 0, -1);\n      push(out, x + w, y, 0, -1);\n      push(out, x + w, y + d, 0, 1);\n      push(out, x, y + d, 0, 1);\n      return out;\n    }\n    push(out, x + radius, y, 0, -1);\n    push(out, x + w - radius, y, 0, -1);\n    corner(out, x + w - radius, y + radius, radius, -Math.PI / 2, 0);\n    push(out, x + w, y + d - radius, 1, 0);\n    corner(out, x + w - radius, y + d - radius, radius, 0, Math.PI / 2);\n    push(out, x + radius, y + d, 0, 1);\n    corner(out, x + radius, y + d - radius, radius, Math.PI / 2, Math.PI);\n    push(out, x, y + radius, -1, 0);\n    corner(out, x + radius, y + radius, radius, Math.PI, Math.PI * 1.5);\n    return out;\n  }\n\n  if (foot.kind === \"circle\") {\n    const out: OutlinePoint[] = [];\n    for (let index = 0; index < CIRCLE_STEPS; index += 1) {\n      const a = (index / CIRCLE_STEPS) * Math.PI * 2;\n      const nx = Math.cos(a);\n      const ny = Math.sin(a);\n      out.push({\n        x: foot.x + nx * foot.r,\n        y: foot.y + ny * foot.r,\n        nx,\n        ny,\n      });\n    }\n    return out;\n  }\n\n  const points = foot.points.map(([x, y]) => ({ x, y }));\n  let area = 0;\n  for (let index = 0; index < points.length; index += 1) {\n    const a = points[index];\n    const b = points[(index + 1) % points.length];\n    area += a.x * b.y - b.x * a.y;\n  }\n  if (area < 0) points.reverse();\n\n  const out: OutlinePoint[] = [];\n  for (let index = 0; index < points.length; index += 1) {\n    const a = points[index];\n    const b = points[(index + 1) % points.length];\n    const dx = b.x - a.x;\n    const dy = b.y - a.y;\n    const length = Math.hypot(dx, dy) || 1;\n    const nx = dy / length;\n    const ny = -dx / length;\n    push(out, a.x, a.y, nx, ny);\n  }\n  return out;\n}\n\nexport function expandFoot(foot: Foot, pad: number): Foot {\n  if (foot.kind === \"rect\") {\n    return {\n      kind: \"rect\",\n      x: foot.x - pad,\n      y: foot.y - pad,\n      w: foot.w + pad * 2,\n      d: foot.d + pad * 2,\n      r: foot.r + pad,\n    };\n  }\n  if (foot.kind === \"circle\") {\n    return { kind: \"circle\", x: foot.x, y: foot.y, r: foot.r + pad };\n  }\n  const cx =\n    foot.points.reduce((sum, point) => sum + point[0], 0) / foot.points.length;\n  const cy =\n    foot.points.reduce((sum, point) => sum + point[1], 0) / foot.points.length;\n  return {\n    kind: \"poly\",\n    points: foot.points.map(([x, y]) => {\n      const dx = x - cx;\n      const dy = y - cy;\n      const length = Math.hypot(dx, dy) || 1;\n      return [x + (dx / length) * pad, y + (dy / length) * pad] as const;\n    }),\n  };\n}\n\nexport function footCenter(foot: Foot): Projected {\n  if (foot.kind === \"rect\") {\n    return { x: foot.x + foot.w / 2, y: foot.y + foot.d / 2 };\n  }\n  if (foot.kind === \"circle\") return { x: foot.x, y: foot.y };\n  return {\n    x: foot.points.reduce((sum, point) => sum + point[0], 0) / foot.points.length,\n    y: foot.points.reduce((sum, point) => sum + point[1], 0) / foot.points.length,\n  };\n}\n\n/** Painter order: larger x+y is closer to the camera. */\nexport function footDepth(foot: Foot): number {\n  const center = footCenter(foot);\n  return center.x + center.y;\n}\n\nexport function footContains(foot: Foot, x: number, y: number): boolean {\n  if (foot.kind === \"rect\") {\n    return (\n      x >= foot.x && x <= foot.x + foot.w && y >= foot.y && y <= foot.y + foot.d\n    );\n  }\n  if (foot.kind === \"circle\") {\n    return Math.hypot(x - foot.x, y - foot.y) <= foot.r;\n  }\n  let inside = false;\n  const points = foot.points;\n  for (let i = 0, j = points.length - 1; i < points.length; j = i, i += 1) {\n    const [xi, yi] = points[i];\n    const [xj, yj] = points[j];\n    if (\n      yi > y !== yj > y &&\n      x < ((xj - xi) * (y - yi)) / (yj - yi || 0.000001) + xi\n    ) {\n      inside = !inside;\n    }\n  }\n  return inside;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Paths                                                                       */\n/* -------------------------------------------------------------------------- */\n\nfunction n(value: number) {\n  return Math.round(value * 100) / 100;\n}\n\nexport function pathFrom(points: Projected[], closed = false): string {\n  if (points.length === 0) return \"\";\n  let d = `M${n(points[0].x)} ${n(points[0].y)}`;\n  for (let index = 1; index < points.length; index += 1) {\n    d += `L${n(points[index].x)} ${n(points[index].y)}`;\n  }\n  if (closed) d += \"Z\";\n  return d;\n}\n\nfunction cross(o: Projected, a: Projected, b: Projected) {\n  return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);\n}\n\nexport function convexHull(points: Projected[]): Projected[] {\n  const sorted = points\n    .slice()\n    .sort((a, b) => a.x - b.x || a.y - b.y)\n    .filter(\n      (point, index, list) =>\n        index === 0 ||\n        Math.abs(point.x - list[index - 1].x) > 0.0001 ||\n        Math.abs(point.y - list[index - 1].y) > 0.0001,\n    );\n  if (sorted.length <= 1) return sorted;\n  const lower: Projected[] = [];\n  for (const point of sorted) {\n    while (\n      lower.length >= 2 &&\n      cross(lower[lower.length - 2], lower[lower.length - 1], point) <= 0\n    ) {\n      lower.pop();\n    }\n    lower.push(point);\n  }\n  const upper: Projected[] = [];\n  for (let index = sorted.length - 1; index >= 0; index -= 1) {\n    const point = sorted[index];\n    while (\n      upper.length >= 2 &&\n      cross(upper[upper.length - 2], upper[upper.length - 1], point) <= 0\n    ) {\n      upper.pop();\n    }\n    upper.push(point);\n  }\n  lower.pop();\n  upper.pop();\n  return lower.concat(upper);\n}\n\nfunction projectOutline(\n  camera: Camera,\n  outline: OutlinePoint[],\n  z: number,\n): Projected[] {\n  return outline.map((point) => project(camera, point.x, point.y, z));\n}\n\n/**\n * Closed silhouette of a vertical extrusion: the convex hull of the footprint\n * seen at the bottom and at the top. This is the path that occludes everything\n * behind it when filled with the plate colour.\n */\nexport function prismPath(\n  camera: Camera,\n  foot: Foot,\n  z0: number,\n  z1: number,\n): string {\n  const outline = outlineFor(foot);\n  const points = [\n    ...projectOutline(camera, outline, z0),\n    ...projectOutline(camera, outline, z1),\n  ];\n  return pathFrom(convexHull(points), true);\n}\n\n/**\n * The camera-facing half of the top contour: the lower bevel edge.\n * A segment faces the camera when its local outward normal has a positive\n * x+y component.\n */\nexport function frontArcPath(camera: Camera, foot: Foot, z: number): string {\n  const outline = outlineFor(foot);\n  const count = outline.length;\n  if (count === 0) return \"\";\n  const facing = (point: OutlinePoint) => point.nx + point.ny > 0.0001;\n  let start = -1;\n  for (let index = 0; index < count; index += 1) {\n    const previous = outline[(index - 1 + count) % count];\n    if (facing(outline[index]) && !facing(previous)) {\n      start = index;\n      break;\n    }\n  }\n  if (start < 0) return \"\";\n  const arc: Projected[] = [];\n  for (let step = 0; step < count; step += 1) {\n    const point = outline[(start + step) % count];\n    if (!facing(point)) break;\n    arc.push(project(camera, point.x, point.y, z));\n  }\n  return pathFrom(arc, false);\n}\n\n/** Closed outline of a flat shape lying on a horizontal plane. */\nexport function flatPath(camera: Camera, foot: Foot, z: number): string {\n  return pathFrom(projectOutline(camera, outlineFor(foot), z), true);\n}\n\nexport function isoEllipse(\n  camera: Camera,\n  x: number,\n  y: number,\n  z: number,\n  r: number,\n) {\n  const center = project(camera, x, y, z);\n  return {\n    cx: n(center.x),\n    cy: n(center.y),\n    rx: n(r * camera.scale),\n    ry: n(r * camera.scale * K),\n  };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Camera                                                                      */\n/* -------------------------------------------------------------------------- */\n\nfunction rawEllipsePoints(\n  x: number,\n  y: number,\n  z: number,\n  r: number,\n): Projected[] {\n  const center = rawProject(x, y, z);\n  return [\n    { x: center.x - r, y: center.y - r * K },\n    { x: center.x + r, y: center.y + r * K },\n  ];\n}\n\nexport function circlePoints(\n  x: number,\n  y: number,\n  r: number,\n  steps = 24,\n): Point2[] {\n  return Array.from({ length: steps }, (_, index) => {\n    const angle = (index / steps) * Math.PI * 2;\n    return [x + Math.cos(angle) * r, y + Math.sin(angle) * r] as const;\n  });\n}\n\nexport function spriteDetailPoints(detail: SpriteDetail): Point2[] {\n  if (detail.kind === \"line\") return [...detail.points];\n  return circlePoints(detail.x, detail.y, detail.r, detail.kind === \"dot\" ? 16 : 24);\n}\n\nfunction detailRawPoints(detail: Detail, z: number): Projected[] {\n  if (detail.kind === \"bar\") {\n    return outlineFor({\n      kind: \"rect\",\n      x: detail.x,\n      y: detail.y,\n      w: detail.w,\n      d: detail.d,\n      r: detail.r ?? 0,\n    }).map((point) => rawProject(point.x, point.y, z));\n  }\n  if (detail.kind === \"dot\" || detail.kind === \"ring\") {\n    return rawEllipsePoints(detail.x, detail.y, z, detail.r);\n  }\n  return detail.points.map(([x, y]) => rawProject(x, y, z));\n}\n\nexport function buildCamera(scene: SceneDefinition): Camera {\n  const points: Projected[] = [];\n  const plateTop = sceneBase(scene);\n\n  if (scene.plate) {\n    const outline = outlineFor({\n      kind: \"rect\",\n      x: scene.plate.x,\n      y: scene.plate.y,\n      w: scene.plate.w,\n      d: scene.plate.d,\n      r: scene.plate.r,\n    });\n    points.push(...outline.map((point) => rawProject(point.x, point.y, 0)));\n    points.push(\n      ...outline.map((point) => rawProject(point.x, point.y, scene.plate!.h)),\n    );\n  }\n\n  for (const well of scene.wells ?? []) {\n    const foot = expandFoot(well.foot, well.pad ?? 3);\n    points.push(\n      ...outlineFor(foot).map((point) =>\n        rawProject(point.x, point.y, plateTop),\n      ),\n    );\n  }\n\n  for (const detail of scene.marks ?? []) {\n    points.push(...detailRawPoints(detail, plateTop));\n  }\n\n  for (const block of scene.blocks) {\n    if (isSprite(block)) {\n      const z0 = block.z ?? plateTop;\n      const anchor = rawProject(block.x, block.y, z0);\n      const back = {\n        x: block.thickness * C,\n        y: -block.thickness * C * K,\n      };\n      for (const loop of [...block.outline, ...(block.holes ?? [])]) {\n        for (const [u, v] of loop) {\n          points.push({ x: anchor.x + u, y: anchor.y - v });\n          points.push({ x: anchor.x + u + back.x, y: anchor.y - v + back.y });\n        }\n      }\n      for (const detail of block.details ?? []) {\n        for (const [u, v] of spriteDetailPoints(detail)) {\n          points.push({ x: anchor.x + u, y: anchor.y - v });\n        }\n      }\n      continue;\n    }\n    const base = block.base ?? plateTop;\n    const z0 = block.float ? base : base;\n    const z1 = base + block.height;\n    points.push(\n      ...outlineFor(block.foot).map((point) => rawProject(point.x, point.y, z0)),\n      ...outlineFor(block.foot).map((point) => rawProject(point.x, point.y, z1)),\n    );\n    for (const detail of block.details ?? []) {\n      points.push(...detailRawPoints(detail, z1));\n    }\n  }\n\n  if (points.length === 0) return { scale: 1, ox: 200, oy: 160 };\n\n  let minX = Infinity;\n  let maxX = -Infinity;\n  let minY = Infinity;\n  let maxY = -Infinity;\n  for (const point of points) {\n    minX = Math.min(minX, point.x);\n    maxX = Math.max(maxX, point.x);\n    minY = Math.min(minY, point.y);\n    maxY = Math.max(maxY, point.y);\n  }\n\n  const width = Math.max(1, maxX - minX);\n  const height = Math.max(1, maxY - minY);\n  const scale = Math.min(\n    2.15,\n    (FIT.width - FIT.padX * 2) / width,\n    (FIT.height - FIT.padY * 2) / height,\n  );\n  return {\n    scale,\n    ox: FIT.width / 2 - scale * (minX + maxX) / 2,\n    oy: FIT.cy - scale * (minY + maxY) / 2,\n  };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Easing                                                                      */\n/* -------------------------------------------------------------------------- */\n\nfunction bezierComponent(t: number, p1: number, p2: number) {\n  const mt = 1 - t;\n  return 3 * mt * mt * t * p1 + 3 * mt * t * t * p2 + t * t * t;\n}\n\nfunction bezierDerivative(t: number, p1: number, p2: number) {\n  const mt = 1 - t;\n  return 3 * mt * mt * p1 + 6 * mt * t * (p2 - p1) + 3 * t * t * (1 - p2);\n}\n\n/**\n * Same curve as the reference study: cubic-bezier(0.32, 0.72, 0, 1).\n * Solved on x with Newton, then bisection as a fallback.\n */\nexport function easeDepth(t: number): number {\n  if (t <= 0) return 0;\n  if (t >= 1) return 1;\n  const x1 = 0.32;\n  const y1 = 0.72;\n  const x2 = 0;\n  const y2 = 1;\n  let u = t;\n  for (let index = 0; index < 8; index += 1) {\n    const x = bezierComponent(u, x1, x2) - t;\n    const dx = bezierDerivative(u, x1, x2);\n    if (Math.abs(x) < 0.00001) break;\n    if (Math.abs(dx) < 0.00001) break;\n    u -= x / dx;\n    if (u < 0) u = 0;\n    if (u > 1) u = 1;\n  }\n  if (Math.abs(bezierComponent(u, x1, x2) - t) > 0.001) {\n    let low = 0;\n    let high = 1;\n    for (let index = 0; index < 20; index += 1) {\n      u = (low + high) / 2;\n      const x = bezierComponent(u, x1, x2);\n      if (x < t) low = u;\n      else high = u;\n    }\n    u = (low + high) / 2;\n  }\n  return bezierComponent(u, y1, y2);\n}\n\nexport function sceneBlockDepth(block: SceneBlock) {\n  /* A billboard stands on the front half of its socle: a small bias keeps it\n     painted after the slab it rests on, instead of being clipped by it. */\n  return isSprite(block) ? block.x + block.y + 30 : footDepth(block.foot);\n}\n\nexport function blockBase(block: FlatBlock, plateTop: number) {\n  return block.base ?? plateTop;\n}\n\nexport function blockTop(\n  block: FlatBlock,\n  plateTop: number,\n  delta: number,\n) {\n  const base = blockBase(block, plateTop);\n  if (block.float) return base + delta + block.height;\n  return base + Math.max(LINEAR_TIMING.floor, block.height + delta);\n}\n\nexport function blockBottom(\n  block: FlatBlock,\n  plateTop: number,\n  delta: number,\n) {\n  const base = blockBase(block, plateTop);\n  return block.float ? base + delta : base;\n}\n\nexport function spriteBase(sprite: SceneSprite, plateTop: number, delta = 0) {\n  return (sprite.z ?? plateTop) + delta;\n}\n"
    },
    {
      "path": "components/prequelui/linear/scene.tsx",
      "target": "components/prequelui/linear/scene.tsx",
      "type": "registry:ui",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { useHydratedReducedMotion } from \"@/lib/use-reduced-motion\";\nimport {\n  LINEAR_TIMING,\n  blockBottom,\n  blockTop,\n  buildCamera,\n  circlePoints,\n  easeDepth,\n  expandFoot,\n  flatPath,\n  footContains,\n  frontArcPath,\n  isSprite,\n  isoEllipse,\n  pathFrom,\n  prismPath,\n  project,\n  sceneBase,\n  sceneBlockDepth,\n  spriteBase,\n  spriteDetailPoints,\n  spritePoint,\n  unproject,\n  type Camera,\n  type Detail,\n  type Foot,\n  type Point2,\n  type SceneDefinition,\n  type SceneSprite,\n  type SpriteDetail,\n  type SpriteMotion,\n} from \"./engine\";\n\nexport type LinearSceneProps = {\n  scene: SceneDefinition;\n  className?: string;\n  /** Accessible sentence. Pass an empty string for a decorative tile. */\n  label?: string;\n  /** Increment to replay a short tour of every object. */\n  replay?: number;\n  /** Set to false for a still figure. */\n  interactive?: boolean;\n  /** Set to false to keep the figure still until a pointer or replay wakes it. */\n  idle?: boolean;\n};\n\nconst COLOR_TRANSITION =\n  \"stroke 260ms cubic-bezier(0.5, 0, 0.1, 1), fill 260ms cubic-bezier(0.5, 0, 0.1, 1)\";\n\n/** Engraved lip inside the plate silhouette. */\nconst PLATE_RIM = 3.2;\n/** Second contour on the top face of every key, inside the silhouette. */\nconst BLOCK_RIM = 2.15;\n\n/**\n * Inset contour of a footprint, used for the nested lips. Returns null when the\n * shape is too small to hold a readable rim, so tiny keys stay clean.\n */\nfunction rimPath(camera: Camera, foot: Foot, z: number) {\n  if (foot.kind === \"rect\") {\n    const pad = Math.min(BLOCK_RIM, foot.w / 2 - 1, foot.d / 2 - 1);\n    return pad > 0.4 ? flatPath(camera, expandFoot(foot, -pad), z) : null;\n  }\n  if (foot.kind === \"circle\") {\n    const pad = Math.min(BLOCK_RIM, foot.r - 1);\n    return pad > 0.4 ? flatPath(camera, expandFoot(foot, -pad), z) : null;\n  }\n  if (foot.points.length >= 3) {\n    return flatPath(camera, expandFoot(foot, -BLOCK_RIM), z);\n  }\n  return null;\n}\n\nfunction toneColor(tone: Detail[\"tone\"], active: boolean, fallback: string) {\n  switch (tone) {\n    case \"edge\":\n      return \"var(--ls-edge)\";\n    case \"hi\":\n      return \"var(--ls-hi)\";\n    case \"mid\":\n      return \"var(--ls-mid)\";\n    case \"lo\":\n      return \"var(--ls-lo)\";\n    case \"active\":\n      return active ? \"var(--ls-hi)\" : \"var(--ls-lo)\";\n    default:\n      return fallback;\n  }\n}\n\n\n\nfunction DetailShape({\n  detail,\n  camera,\n  z,\n  active,\n}: {\n  detail: Detail;\n  camera: Camera;\n  z: number;\n  active: boolean;\n}) {\n  if (detail.kind === \"bar\") {\n    return (\n      <path\n        d={flatPath(\n          camera,\n          {\n            kind: \"rect\",\n            x: detail.x,\n            y: detail.y,\n            w: detail.w,\n            d: detail.d,\n            r: detail.r ?? 1.2,\n          },\n          z,\n        )}\n        fill=\"none\"\n        stroke={toneColor(detail.tone, active, \"var(--ls-mid)\")}\n        strokeWidth={0.9}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        vectorEffect=\"non-scaling-stroke\"\n        style={{ transition: COLOR_TRANSITION }}\n      />\n    );\n  }\n\n  if (detail.kind === \"dot\") {\n    const ellipse = isoEllipse(camera, detail.x, detail.y, z, detail.r);\n    return (\n      <g>\n        {active && (\n          <ellipse\n            cx={ellipse.cx}\n            cy={ellipse.cy}\n            rx={ellipse.rx * 1.25}\n            ry={ellipse.ry * 1.25}\n            stroke=\"none\"\n            fill=\"var(--ls-hi)\"\n            opacity={0.1}\n            style={{ transition: COLOR_TRANSITION }}\n          />\n        )}\n        <ellipse\n          cx={ellipse.cx}\n          cy={ellipse.cy}\n          rx={ellipse.rx}\n          ry={ellipse.ry}\n          stroke=\"none\"\n          fill={toneColor(detail.tone, active, active ? \"var(--ls-hi)\" : \"var(--ls-lo)\")}\n          style={{ transition: COLOR_TRANSITION }}\n        />\n      </g>\n    );\n  }\n\n  if (detail.kind === \"ring\") {\n    const ellipse = isoEllipse(camera, detail.x, detail.y, z, detail.r);\n    return (\n      <ellipse\n        cx={ellipse.cx}\n        cy={ellipse.cy}\n        rx={ellipse.rx}\n        ry={ellipse.ry}\n        fill=\"none\"\n        stroke={toneColor(detail.tone, active, \"var(--ls-lo)\")}\n        strokeWidth={0.9}\n        vectorEffect=\"non-scaling-stroke\"\n        style={{ transition: COLOR_TRANSITION }}\n      />\n    );\n  }\n\n  const points = detail.points.map(([x, y]) => project(camera, x, y, z));\n  if (points.length === 0) return null;\n  let d = `M${Math.round(points[0].x * 100) / 100} ${\n    Math.round(points[0].y * 100) / 100\n  }`;\n  for (let index = 1; index < points.length; index += 1) {\n    d += `L${Math.round(points[index].x * 100) / 100} ${\n      Math.round(points[index].y * 100) / 100\n    }`;\n  }\n  if (detail.closed) d += \"Z\";\n  return (\n    <path\n      d={d}\n      fill=\"none\"\n      stroke={toneColor(detail.tone, active, \"var(--ls-mid)\")}\n      strokeWidth={0.9}\n      strokeLinecap=\"round\"\n      strokeLinejoin=\"round\"\n      vectorEffect=\"non-scaling-stroke\"\n      style={{ transition: COLOR_TRANSITION }}\n    />\n  );\n}\n\ntype LocalTransform = (u: number, v: number) => Point2;\n\nconst IDENTITY: LocalTransform = (u, v) => [u, v];\n\nfunction compose(first: LocalTransform, second: LocalTransform): LocalTransform {\n  return (u, v) => {\n    const [x, y] = first(u, v);\n    return second(x, y);\n  };\n}\n\nfunction rotateAbout(pivot: Point2, degrees: number): LocalTransform {\n  const radians = (degrees * Math.PI) / 180;\n  const cos = Math.cos(radians);\n  const sin = Math.sin(radians);\n  return (u, v) => {\n    const x = u - pivot[0];\n    const y = v - pivot[1];\n    return [pivot[0] + x * cos - y * sin, pivot[1] + x * sin + y * cos];\n  };\n}\n\nfunction scaleAbout(pivot: Point2, sx: number, sy: number): LocalTransform {\n  return (u, v) => [\n    pivot[0] + (u - pivot[0]) * sx,\n    pivot[1] + (v - pivot[1]) * sy,\n  ];\n}\n\nfunction moveBy(dx: number, dy: number): LocalTransform {\n  return (u, v) => [u + dx, v + dy];\n}\n\nfunction cycleOf(motion: SpriteMotion, time: number) {\n  const period = Math.max(120, motion.period ?? 2600);\n  const raw = time / period + (motion.phase ?? 0);\n  return raw - Math.floor(raw);\n}\n\nfunction heartBeat(cycle: number) {\n  const bump = (center: number, width: number) =>\n    Math.exp(-Math.pow((cycle - center) / width, 2));\n  return Math.min(1, bump(0.14, 0.055) + 0.6 * bump(0.34, 0.075));\n}\n\nfunction motionTransform(motion: SpriteMotion, time: number, pivot: Point2) {\n  const cycle = cycleOf(motion, time);\n  const amount = motion.amount ?? 0;\n  switch (motion.kind) {\n    case \"spin\":\n      return rotateAbout(pivot, (amount || 360) * cycle);\n    case \"pulse\": {\n      const scale = 1 + (amount || 0.08) * heartBeat(cycle);\n      return scaleAbout(pivot, scale, 1 + (amount || 0.08) * 0.62 * heartBeat(cycle));\n    }\n    case \"breathe\": {\n      const wave = 0.5 + 0.5 * Math.sin(cycle * Math.PI * 2);\n      const scale = 1 + (amount || 0.05) * wave;\n      return scaleAbout(pivot, scale, scale);\n    }\n    case \"blink\": {\n      const wave = 0.5 + 0.5 * Math.sin(cycle * Math.PI * 2);\n      const close = Math.pow(wave, 12);\n      return scaleAbout(pivot, 1, 1 - (amount || 0.9) * close);\n    }\n    case \"sway\":\n      return rotateAbout(pivot, Math.sin(cycle * Math.PI * 2) * (amount || 4));\n    case \"bob\":\n      return moveBy(0, Math.sin(cycle * Math.PI * 2) * (amount || 2));\n    case \"flicker\": {\n      const wave =\n        Math.sin(cycle * Math.PI * 6) * (0.55 + 0.45 * Math.sin(cycle * Math.PI * 2));\n      return scaleAbout(pivot, 1, 1 + (amount || 0.2) * wave);\n    }\n    case \"lift\":\n      return moveBy(0, (amount || 3) * (0.5 - 0.5 * Math.cos(cycle * Math.PI * 2)));\n    default:\n      return IDENTITY;\n  }\n}\n\ntype SpriteFrame = {\n  whole: LocalTransform;\n  groups: Map<string, LocalTransform>;\n};\n\nfunction groupPivots(sprite: SceneSprite) {\n  const boxes = new Map<string, { minU: number; maxU: number; minV: number; maxV: number }>();\n  for (const detail of sprite.details ?? []) {\n    if (!detail.group) continue;\n    const points =\n      detail.kind === \"line\"\n        ? detail.points\n        : (circlePoints(detail.x, detail.y, detail.r, 12) as Point2[]);\n    const box = boxes.get(detail.group) ?? {\n      minU: Infinity,\n      maxU: -Infinity,\n      minV: Infinity,\n      maxV: -Infinity,\n    };\n    for (const [u, v] of points) {\n      box.minU = Math.min(box.minU, u);\n      box.maxU = Math.max(box.maxU, u);\n      box.minV = Math.min(box.minV, v);\n      box.maxV = Math.max(box.maxV, v);\n    }\n    boxes.set(detail.group, box);\n  }\n  const pivots = new Map<string, Point2>();\n  for (const [key, box] of boxes) {\n    pivots.set(key, [(box.minU + box.maxU) / 2, (box.minV + box.maxV) / 2]);\n  }\n  return pivots;\n}\n\nfunction resolveSpriteFrame(\n  sprite: SceneSprite,\n  time: number,\n  pivots: Map<string, Point2>,\n): SpriteFrame {\n  let whole: LocalTransform = IDENTITY;\n  const groups = new Map<string, LocalTransform>();\n  for (const motion of sprite.motion ?? []) {\n    const pivot = motion.pivot ?? (motion.target ? pivots.get(motion.target) : undefined) ?? [0, 0];\n    const transform = motionTransform(motion, time, pivot);\n    if (motion.target) {\n      const previous = groups.get(motion.target) ?? IDENTITY;\n      groups.set(motion.target, compose(previous, transform));\n    } else {\n      whole = compose(whole, transform);\n    }\n  }\n  return { whole, groups };\n}\n\nfunction signedArea(points: ReadonlyArray<Point2>) {\n  let area = 0;\n  for (let index = 0; index < points.length; index += 1) {\n    const [ax, ay] = points[index];\n    const [bx, by] = points[(index + 1) % points.length];\n    area += ax * by - bx * ay;\n  }\n  return area;\n}\n\nfunction wound(points: ReadonlyArray<Point2>, positive: boolean) {\n  const area = signedArea(points);\n  return (area >= 0) === positive ? points : [...points].reverse();\n}\n\nfunction spritePath(\n  camera: Camera,\n  sprite: SceneSprite,\n  z: number,\n  transform: LocalTransform,\n  back = false,\n) {\n  const loops = [\n    ...sprite.outline.map((loop) => wound(loop, true)),\n    ...(sprite.holes ?? []).map((loop) => wound(loop, false)),\n  ];\n  let path = \"\";\n  for (const loop of loops) {\n    const points = loop.map(([u, v]) => {\n      const [tu, tv] = transform(u, v);\n      return spritePoint(camera, sprite, tu, tv, z, back);\n    });\n    path += pathFrom(points, true);\n  }\n  return path;\n}\n\nfunction SpriteDetailShape({\n  detail,\n  camera,\n  sprite,\n  baseZ,\n  frame,\n  active,\n}: {\n  detail: SpriteDetail;\n  camera: Camera;\n  sprite: SceneSprite;\n  baseZ: number;\n  frame: SpriteFrame;\n  active: boolean;\n}) {\n  const group = detail.group ? frame.groups.get(detail.group) ?? IDENTITY : IDENTITY;\n  const transform = compose(group, frame.whole);\n  const stroke = toneColor(detail.tone, active, \"var(--ls-mid)\");\n\n  if (detail.kind === \"line\") {\n    const points = detail.points.map(([u, v]) => {\n      const [tu, tv] = transform(u, v);\n      return spritePoint(camera, sprite, tu, tv, baseZ);\n    });\n    if (points.length === 0) return null;\n    return (\n      <path\n        d={pathFrom(points, detail.closed)}\n        fill=\"none\"\n        stroke={stroke}\n        strokeWidth={0.9}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        vectorEffect=\"non-scaling-stroke\"\n        style={{ transition: COLOR_TRANSITION }}\n      />\n    );\n  }\n\n  const points = (circlePoints(detail.x, detail.y, detail.r, 24) as Point2[]).map(\n    ([u, v]) => {\n      const [tu, tv] = transform(u, v);\n      return spritePoint(camera, sprite, tu, tv, baseZ);\n    },\n  );\n  const path = pathFrom(points, true);\n\n  if (detail.kind === \"ring\") {\n    return (\n      <path\n        d={path}\n        fill=\"none\"\n        stroke={toneColor(detail.tone, active, \"var(--ls-lo)\")}\n        strokeWidth={0.9}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        vectorEffect=\"non-scaling-stroke\"\n        style={{ transition: COLOR_TRANSITION }}\n      />\n    );\n  }\n\n  return (\n    <path\n      d={path}\n      fill={toneColor(detail.tone, active, active ? \"var(--ls-hi)\" : \"var(--ls-lo)\")}\n      stroke=\"none\"\n      style={{ transition: COLOR_TRANSITION }}\n    />\n  );\n}\n\n/**\n * The shared isometric object renderer. Every illustration is a pure\n * `SceneDefinition` handed to this component; it owns the projection, the\n * occlusion, the pointer depth tween and the reduced-motion fallback.\n */\nexport function IsoObject({\n  scene,\n  className,\n  label,\n  replay = 0,\n  interactive = true,\n  idle = true,\n}: LinearSceneProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const reduce = useHydratedReducedMotion();\n  /* The gallery mounts a scene only when it is near the viewport, and the\n     detail view is always open. A local visibility observer would only add a\n     state update per mount, so the scene treats its mounted life as visible. */\n  const visible = true;\n\n  const camera = React.useMemo(() => buildCamera(scene), [scene]);\n  const plateTop = sceneBase(scene);\n  const ordered = React.useMemo(\n    () =>\n      scene.blocks\n        .map((block, index) => ({ block, index }))\n        .sort((a, b) => sceneBlockDepth(a.block) - sceneBlockDepth(b.block)),\n    [scene],\n  );\n\n  const firstInteractive = scene.blocks.findIndex((block) => !block.static);\n  const restingActive =\n    scene.active ?? (firstInteractive >= 0 ? firstInteractive : 0);\n\n  const pivots = React.useMemo(() => {\n    const map = new Map<SceneSprite, Map<string, Point2>>();\n    for (const block of scene.blocks) {\n      if (!isSprite(block)) continue;\n      map.set(block, groupPivots(block));\n    }\n    return map;\n  }, [scene]);\n\n  const hasMotion = React.useMemo(\n    () =>\n      scene.blocks.some(\n        (block) => isSprite(block) && (block.motion?.length ?? 0) > 0,\n      ),\n    [scene],\n  );\n\n  const spriteHits = React.useMemo(\n    () =>\n      scene.blocks.map((block) => {\n        if (!isSprite(block)) return null;\n        const z = block.z ?? plateTop;\n        const points: Array<{ x: number; y: number }> = [];\n        for (const loop of [...block.outline, ...(block.holes ?? [])]) {\n          for (const [u, v] of loop) {\n            points.push(spritePoint(camera, block, u, v, z));\n            points.push(spritePoint(camera, block, u, v, z, true));\n          }\n        }\n        for (const detail of block.details ?? []) {\n          for (const [u, v] of spriteDetailPoints(detail)) {\n            points.push(spritePoint(camera, block, u, v, z));\n          }\n        }\n        let minX = Infinity;\n        let maxX = -Infinity;\n        let minY = Infinity;\n        let maxY = -Infinity;\n        for (const point of points) {\n          minX = Math.min(minX, point.x);\n          maxX = Math.max(maxX, point.x);\n          minY = Math.min(minY, point.y);\n          maxY = Math.max(maxY, point.y);\n        }\n        return { minX: minX - 4, maxX: maxX + 4, minY: minY - 4, maxY: maxY + 4, z };\n      }),\n    [camera, plateTop, scene],\n  );\n\n  const clockRef = React.useRef(0);\n  const paintRef = React.useRef(0);\n  const [hover, setHover] = React.useState<number | null>(null);\n  const [tour, setTour] = React.useState<number | null>(null);\n  const [, force] = React.useReducer((value: number) => value + 1, 0);\n\n  const activeIndex = interactive ? hover ?? tour ?? restingActive : restingActive;\n  const pressed = interactive && (hover !== null || tour !== null);\n\n  const deltas = React.useRef<number[]>(scene.blocks.map(() => 0));\n  const leaveTimer = React.useRef<number | undefined>(undefined);\n  const tourTimers = React.useRef<number[]>([]);\n  const frameRef = React.useRef(0);\n  const hoverRef = React.useRef<number | null>(null);\n  const reduceRef = React.useRef(reduce);\n  const visibleRef = React.useRef(visible);\n  const controlRef = React.useRef({ active: activeIndex, pressed });\n\n  reduceRef.current = reduce;\n  visibleRef.current = visible;\n  controlRef.current = { active: activeIndex, pressed };\n\n  /**\n   * Starts the depth tween from the current values. Called directly from the\n   * pointer handler so the geometry does not wait for React's passive effects.\n   */\n  const animate = React.useCallback(\n    (active: number | null, down: boolean) => {\n      const targets = scene.blocks.map((block, index) => {\n        if (!down || block.static) return 0;\n        if (index === active) return -LINEAR_TIMING.sink;\n        return LINEAR_TIMING.lift;\n      });\n\n      if (frameRef.current) {\n        cancelAnimationFrame(frameRef.current);\n        frameRef.current = 0;\n      }\n\n      if (reduceRef.current || !visibleRef.current || !interactive) {\n        const changed = targets.some(\n          (target, index) => Math.abs((deltas.current[index] ?? 0) - target) > 0.01,\n        );\n        deltas.current = targets;\n        if (changed) force();\n        return;\n      }\n\n      if (!down && targets.every((target, index) => Math.abs((deltas.current[index] ?? 0) - target) < 0.01)) {\n        return;\n      }\n\n      const now = performance.now();\n      const animations = targets.map((to, index) => ({\n        from: deltas.current[index] ?? 0,\n        to,\n        delay: down\n          ? LINEAR_TIMING.stagger * Math.abs(index - (active ?? 0))\n          : 0,\n        start: now,\n      }));\n\n      const step = (time: number) => {\n        let running = false;\n        for (let index = 0; index < animations.length; index += 1) {\n          const animation = animations[index];\n          const elapsed = time - animation.start - animation.delay;\n          if (elapsed <= 0) {\n            running = true;\n            continue;\n          }\n          const progress = Math.min(1, elapsed / LINEAR_TIMING.depth);\n          const eased = easeDepth(progress);\n          deltas.current[index] =\n            animation.from + (animation.to - animation.from) * eased;\n          if (progress < 1) running = true;\n          else deltas.current[index] = animation.to;\n        }\n        if (!running || time - paintRef.current >= 24) {\n          paintRef.current = time;\n          force();\n        }\n        frameRef.current = running ? requestAnimationFrame(step) : 0;\n      };\n\n      frameRef.current = requestAnimationFrame(step);\n    },\n    [force, interactive, scene],\n  );\n\n  React.useEffect(() => {\n    hoverRef.current = null;\n    setHover(null);\n    setTour(null);\n    deltas.current = scene.blocks.map(() => 0);\n    animate(null, false);\n  }, [animate, scene]);\n\n  React.useEffect(() => {\n    animate(controlRef.current.active, controlRef.current.pressed);\n  }, [animate, reduce, visible]);\n\n  React.useEffect(() => {\n    if (!hasMotion || reduce || !visible || !idle) {\n      const wasRunning = clockRef.current !== 0;\n      clockRef.current = 0;\n      if (wasRunning) force();\n      return;\n    }\n    let frame = 0;\n    const start = performance.now();\n    const step = (time: number) => {\n      clockRef.current = time - start;\n      if (time - paintRef.current >= 24) {\n        paintRef.current = time;\n        force();\n      }\n      frame = requestAnimationFrame(step);\n    };\n    frame = requestAnimationFrame(step);\n    return () => cancelAnimationFrame(frame);\n  }, [force, hasMotion, idle, reduce, scene, visible]);\n\n  React.useEffect(\n    () => () => {\n      if (frameRef.current) cancelAnimationFrame(frameRef.current);\n    },\n    [],\n  );\n\n  const clearLeave = React.useCallback(() => {\n    if (leaveTimer.current) {\n      window.clearTimeout(leaveTimer.current);\n      leaveTimer.current = undefined;\n    }\n  }, []);\n\n  const cancelTour = React.useCallback(() => {\n    for (const timer of tourTimers.current) window.clearTimeout(timer);\n    tourTimers.current = [];\n    setTour(null);\n  }, []);\n\n  React.useEffect(() => {\n    for (const timer of tourTimers.current) window.clearTimeout(timer);\n    tourTimers.current = [];\n    if (!replay || !interactive) return;\n    hoverRef.current = null;\n    setHover(null);\n    setTour(null);\n    animate(null, false);\n    const indices = scene.blocks\n      .map((block, index) => (!block.static ? index : -1))\n      .filter((index) => index >= 0);\n    indices.forEach((index, order) => {\n      tourTimers.current.push(\n        window.setTimeout(() => {\n          setTour(index);\n          animate(index, true);\n        }, 140 + order * 880),\n      );\n    });\n    tourTimers.current.push(\n      window.setTimeout(() => {\n        setTour(null);\n        animate(null, false);\n      }, 140 + indices.length * 880),\n    );\n    return () => {\n      for (const timer of tourTimers.current) window.clearTimeout(timer);\n      tourTimers.current = [];\n    };\n  }, [animate, interactive, replay, scene]);\n\n  React.useEffect(\n    () => () => {\n      clearLeave();\n      for (const timer of tourTimers.current) window.clearTimeout(timer);\n    },\n    [clearLeave],\n  );\n\n  const hitAt = React.useCallback(\n    (clientX: number, clientY: number) => {\n      const node = rootRef.current?.querySelector(\"svg\");\n      if (!node) return null;\n      const rect = node.getBoundingClientRect();\n      if (rect.width === 0 || rect.height === 0) return null;\n      const sx = ((clientX - rect.left) / rect.width) * 400;\n      const sy = ((clientY - rect.top) / rect.height) * 320;\n      let best: number | null = null;\n      let bestDepth = -Infinity;\n      scene.blocks.forEach((block, index) => {\n        if (block.static) return;\n        const delta = deltas.current[index] ?? 0;\n        let hit = false;\n\n        if (isSprite(block)) {\n          const bounds = spriteHits[index];\n          if (!bounds) return;\n          const shift =\n            project(camera, 0, 0, bounds.z + delta).y -\n            project(camera, 0, 0, bounds.z).y;\n          hit =\n            sx >= bounds.minX &&\n            sx <= bounds.maxX &&\n            sy >= bounds.minY + shift &&\n            sy <= bounds.maxY + shift;\n        } else {\n          const z0 = blockBottom(block, plateTop, delta);\n          const z1 = blockTop(block, plateTop, delta);\n          /* Test the base, the top face and the middle of the side face, so a\n             floating card and a tall panel are both easy to reach. */\n          hit = [z0, (z0 + z1) / 2, z1].some((z) => {\n            const local = unproject(camera, sx, sy, z);\n            return footContains(block.foot, local.x, local.y);\n          });\n        }\n\n        if (!hit) return;\n        const depth = sceneBlockDepth(block);\n        if (depth > bestDepth) {\n          bestDepth = depth;\n          best = index;\n        }\n      });\n      return best;\n    },\n    [camera, plateTop, scene],\n  );\n\n  const onPointerMove = interactive\n    ? (event: React.PointerEvent<SVGSVGElement>) => {\n        if (event.pointerType === \"touch\") return;\n        clearLeave();\n        if (tour !== null) cancelTour();\n        const next = hitAt(event.clientX, event.clientY);\n        if (next === hoverRef.current) return;\n        hoverRef.current = next;\n        setHover(next);\n        animate(next, next !== null);\n      }\n    : undefined;\n\n  const onPointerLeave = interactive\n    ? (event: React.PointerEvent<SVGSVGElement>) => {\n        if (event.pointerType === \"touch\") {\n          clearLeave();\n          leaveTimer.current = window.setTimeout(() => {\n            hoverRef.current = null;\n            setHover(null);\n            animate(null, false);\n          }, LINEAR_TIMING.touchLeave);\n        } else {\n          clearLeave();\n          hoverRef.current = null;\n          setHover(null);\n          animate(null, false);\n        }\n      }\n    : undefined;\n\n  const onPointerDown = interactive\n    ? (event: React.PointerEvent<SVGSVGElement>) => {\n        clearLeave();\n        if (tour !== null) cancelTour();\n        const next = hitAt(event.clientX, event.clientY);\n        hoverRef.current = next;\n        setHover(next);\n        animate(next, next !== null);\n        if (event.pointerType === \"touch\" && next !== null) {\n          leaveTimer.current = window.setTimeout(() => {\n            hoverRef.current = null;\n            setHover(null);\n            animate(null, false);\n          }, LINEAR_TIMING.touchLeave);\n        }\n      }\n    : undefined;\n\n  const vars = {\n    /* The reference plate is pure white in light and near-black in dark, not\n       the page surface: the slab keeps its own material. */\n    \"--ls-plate\": \"light-dark(#ffffff, #0a0a0a)\",\n    \"--ls-edge\": \"light-dark(oklch(0.43 0 0), oklch(0.79 0 0))\",\n    \"--ls-lo\": \"light-dark(oklch(0.7 0 0), oklch(0.44 0 0))\",\n    \"--ls-mid\": \"light-dark(oklch(0.53 0 0), oklch(0.6 0 0))\",\n    \"--ls-well\": \"light-dark(oklch(0.6 0 0), oklch(0.52 0 0))\",\n    \"--ls-hi\": \"light-dark(oklch(0.13 0 0), oklch(0.995 0 0))\",\n  } as React.CSSProperties;\n\n  const a11y =\n    label === undefined\n      ? { role: \"img\" as const, \"aria-label\": scene.aria }\n      : label\n        ? { role: \"img\" as const, \"aria-label\": label }\n        : { \"aria-hidden\": true as const };\n\n  const platePath = scene.plate\n    ? prismPath(\n        camera,\n        {\n          kind: \"rect\",\n          x: scene.plate.x,\n          y: scene.plate.y,\n          w: scene.plate.w,\n          d: scene.plate.d,\n          r: scene.plate.r,\n        },\n        0,\n        scene.plate.h,\n      )\n    : null;\n\n  const plateBevel = scene.plate\n    ? frontArcPath(\n        camera,\n        {\n          kind: \"rect\",\n          x: scene.plate.x,\n          y: scene.plate.y,\n          w: scene.plate.w,\n          d: scene.plate.d,\n          r: scene.plate.r,\n        },\n        scene.plate.h,\n      )\n    : null;\n\n  const plateRim = scene.plate\n    ? flatPath(\n        camera,\n        expandFoot(\n          {\n            kind: \"rect\",\n            x: scene.plate.x,\n            y: scene.plate.y,\n            w: scene.plate.w,\n            d: scene.plate.d,\n            r: scene.plate.r,\n          },\n          -PLATE_RIM,\n        ),\n        scene.plate.h,\n      )\n    : null;\n\n  return (\n    <div\n      ref={rootRef}\n      className={className}\n      data-linear-scene={scene.slug}\n      data-linear-active={activeIndex}\n      data-linear-pressed={pressed ? \"true\" : \"false\"}\n      style={{ aspectRatio: \"5 / 4\", position: \"relative\", ...vars }}\n      {...a11y}\n    >\n      <svg\n        viewBox=\"0 0 400 320\"\n        width=\"100%\"\n        height=\"100%\"\n        fill=\"none\"\n        preserveAspectRatio=\"xMidYMid meet\"\n        aria-hidden=\"true\"\n        style={{ display: \"block\", touchAction: \"pan-y\", userSelect: \"none\" }}\n        onPointerMove={onPointerMove}\n        onPointerLeave={onPointerLeave}\n        onPointerDown={onPointerDown}\n        onPointerCancel={onPointerLeave}\n      >\n        {platePath && (\n          <g data-linear-part=\"plate\">\n            <path\n              d={platePath}\n              fill=\"var(--ls-plate)\"\n              stroke=\"var(--ls-edge)\"\n              strokeWidth={0.9}\n              strokeLinejoin=\"round\"\n              strokeLinecap=\"round\"\n              vectorEffect=\"non-scaling-stroke\"\n              style={{ transition: COLOR_TRANSITION }}\n            />\n            {plateBevel && (\n              <path\n                d={plateBevel}\n                fill=\"none\"\n                stroke=\"var(--ls-lo)\"\n                strokeWidth={0.9}\n                strokeLinejoin=\"round\"\n                strokeLinecap=\"round\"\n                vectorEffect=\"non-scaling-stroke\"\n                style={{ transition: COLOR_TRANSITION }}\n              />\n            )}\n            {plateRim && (\n              <path\n                d={plateRim}\n                fill=\"none\"\n                stroke=\"var(--ls-mid)\"\n                strokeWidth={0.9}\n                strokeLinejoin=\"round\"\n                strokeLinecap=\"round\"\n                vectorEffect=\"non-scaling-stroke\"\n                style={{ transition: COLOR_TRANSITION }}\n              />\n            )}\n          </g>\n        )}\n\n        {(scene.wells ?? []).map((well, index) => (\n          <path\n            key={`well-${index}`}\n            d={\n              well.full\n                ? flatPath(camera, expandFoot(well.foot, well.pad ?? 3), plateTop)\n                : frontArcPath(\n                    camera,\n                    expandFoot(well.foot, well.pad ?? 3),\n                    plateTop,\n                  )\n            }\n            fill=\"none\"\n            stroke={well.tone === \"mid\" ? \"var(--ls-mid)\" : \"var(--ls-well)\"}\n            strokeWidth={0.9}\n            strokeLinejoin=\"round\"\n            strokeLinecap=\"round\"\n            vectorEffect=\"non-scaling-stroke\"\n            style={{ transition: COLOR_TRANSITION }}\n          />\n        ))}\n\n        {(scene.marks ?? []).map((detail, index) => (\n          <DetailShape\n            key={`mark-${index}`}\n            detail={detail}\n            camera={camera}\n            z={plateTop}\n            active={false}\n          />\n        ))}\n\n        {ordered.map(({ block, index }) => {\n          const delta = deltas.current[index] ?? 0;\n          const isActive = interactive && index === activeIndex;\n\n          if (isSprite(block)) {\n            const z0 = spriteBase(block, plateTop, delta);\n            const frame = resolveSpriteFrame(\n              block,\n              clockRef.current,\n              pivots.get(block) ?? new Map(),\n            );\n            const back =\n              block.thickness > 0.4\n                ? spritePath(camera, block, z0, frame.whole, true)\n                : \"\";\n            const front = spritePath(camera, block, z0, frame.whole);\n            return (\n              <g\n                key={block.id}\n                data-linear-block={block.id}\n                data-linear-index={index}\n                data-linear-kind=\"sprite\"\n                data-linear-top={z0.toFixed(2)}\n              >\n                {back && (\n                  <path\n                    d={back}\n                    fill=\"var(--ls-plate)\"\n                    stroke=\"var(--ls-lo)\"\n                    strokeWidth={0.9}\n                    strokeLinejoin=\"round\"\n                    strokeLinecap=\"round\"\n                    vectorEffect=\"non-scaling-stroke\"\n                    style={{ transition: COLOR_TRANSITION }}\n                  />\n                )}\n                <path\n                  d={front}\n                  fill=\"var(--ls-plate)\"\n                  stroke={isActive ? \"var(--ls-hi)\" : \"var(--ls-edge)\"}\n                  strokeWidth={0.9}\n                  strokeLinejoin=\"round\"\n                  strokeLinecap=\"round\"\n                  vectorEffect=\"non-scaling-stroke\"\n                  style={{ transition: COLOR_TRANSITION }}\n                />\n                {(block.details ?? []).map((detail, detailIndex) => (\n                  <SpriteDetailShape\n                    key={`${block.id}-detail-${detailIndex}`}\n                    detail={detail}\n                    camera={camera}\n                    sprite={block}\n                    baseZ={z0}\n                    frame={frame}\n                    active={isActive}\n                  />\n                ))}\n              </g>\n            );\n          }\n\n          const z0 = blockBottom(block, plateTop, delta);\n          const z1 = blockTop(block, plateTop, delta);\n          const silhouette = prismPath(camera, block.foot, z0, z1);\n          const bevel = z1 - z0 > 0.35 ? frontArcPath(camera, block.foot, z1) : \"\";\n          const rim =\n            z1 - z0 > 0.35 ? rimPath(camera, block.foot, z1) : null;\n          return (\n            <g\n              key={block.id}\n              data-linear-block={block.id}\n              data-linear-index={index}\n              data-linear-top={z1.toFixed(2)}\n            >\n              <path\n                d={silhouette}\n                fill=\"var(--ls-plate)\"\n                stroke={isActive ? \"var(--ls-hi)\" : \"var(--ls-edge)\"}\n                strokeWidth={0.9}\n                strokeLinejoin=\"round\"\n                strokeLinecap=\"round\"\n                vectorEffect=\"non-scaling-stroke\"\n                style={{ transition: COLOR_TRANSITION }}\n              />\n              {bevel && (\n                <path\n                  d={bevel}\n                  fill=\"none\"\n                  stroke=\"var(--ls-lo)\"\n                  strokeWidth={0.9}\n                  strokeLinejoin=\"round\"\n                  strokeLinecap=\"round\"\n                  vectorEffect=\"non-scaling-stroke\"\n                  style={{ transition: COLOR_TRANSITION }}\n                />\n              )}\n              {rim && (\n                <path\n                  d={rim}\n                  fill=\"none\"\n                  stroke={isActive ? \"var(--ls-hi)\" : \"var(--ls-mid)\"}\n                  strokeWidth={0.9}\n                  strokeLinejoin=\"round\"\n                  strokeLinecap=\"round\"\n                  vectorEffect=\"non-scaling-stroke\"\n                  style={{ transition: COLOR_TRANSITION }}\n                />\n              )}\n              {(block.details ?? []).map((detail, detailIndex) => (\n                <DetailShape\n                  key={`${block.id}-detail-${detailIndex}`}\n                  detail={detail}\n                  camera={camera}\n                  z={z1}\n                  active={isActive}\n                />\n              ))}\n            </g>\n          );\n        })}\n      </svg>\n    </div>\n  );\n}\n\n/**\n * Registry-facing alias, kept stable so generated illustrations and published\n * registry items can import `LinearScene` without churn.\n */\nexport const LinearScene = IsoObject;\n\n/** Consumer-facing alias for the shared base. */\nexport type IsoObjectProps = LinearSceneProps;\n"
    }
  ]
}
