{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "illustration-12",
  "title": "Hello in every script",
  "description": "A dotted globe with greetings standing where they are written, each in its own script: pick a language and the globe turns there, its greeting lights up in the brand ink and comes up large beside it.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/motion-dotted-map-points.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/toggle-group.json",
    "https://ui.ndekocode.dev/r/use-agent-run.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/illustration/illustration-12.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useEffect, useRef, useState } from 'react';\n\nimport {\n  DOTTED_MAP_BOUNDS,\n  DOTTED_MAP_HEIGHT,\n  DOTTED_MAP_PATH,\n  DOTTED_MAP_WIDTH,\n} from '@/components/core/dotted-map-points';\nimport {\n  useAutoplay,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { risePresenceOf } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ToggleGroup, ToggleGroupItem } from '@/registry/ndeko/ui/toggle-group';\n\nimport { penOf, tokenOf, watchTheme } from './_parts/canvas';\nimport { degreesOf, nearestAngleOf, radiansOf } from './_parts/geometry';\nimport { useScenePlay } from './_parts/use-scene-play';\n\nexport type HelloLanguage = {\n  /** The language tag, also set on the greeting: `ru`. */\n  tag: string;\n  name: string;\n  endonym: string;\n  script: string;\n  greeting: string;\n  isRightToLeft?: boolean;\n  /** Where its greeting stands on the globe, and where the globe turns to when it is picked. */\n  centre: [latitude: number, longitude: number];\n};\n\n/** Another place of the globe, with the greeting written there. */\nexport type HelloPlace = {\n  greeting: string;\n  location: [latitude: number, longitude: number];\n};\n\n/** A run of points on one line of the map, in the units of its grid. */\ntype MapRun = {\n  column: number;\n  line: number;\n  length: number;\n};\n\n/** A place on a sphere of radius one: towards the east, towards the north pole, towards longitude zero. */\ntype Vector = {\n  east: number;\n  north: number;\n  front: number;\n};\n\n/** Every point of land as a place on the sphere. */\ntype Land = {\n  count: number;\n  east: Float32Array;\n  north: Float32Array;\n  front: Float32Array;\n};\n\n/** A greeting where it is written. `language` is its row in the list, or none for another place. */\ntype Word = {\n  text: string;\n  place: Vector;\n  language: number;\n};\n\n/** How far the ink of a word reaches from its centre and from its baseline, at the reference size. */\ntype Ink = {\n  left: number;\n  right: number;\n  ascent: number;\n  descent: number;\n};\n\ntype Box = {\n  left: number;\n  top: number;\n  right: number;\n  bottom: number;\n};\n\n/** Where a word stands in the frame being drawn. */\ntype WordFrame = {\n  x: number;\n  y: number;\n  /** How much it faces the viewer: 0 near the rim and behind, 1 towards the middle. */\n  facing: number;\n  /** How much it is the picked greeting, from 0 to 1. */\n  emphasis: number;\n  size: number;\n  box: Box;\n  isPlaced: boolean;\n};\n\ntype Turn = {\n  fromLongitude: number;\n  fromLatitude: number;\n  toLongitude: number;\n  toLatitude: number;\n  startedAt: number;\n};\n\n/** How the globe is turned, as the sines and cosines a frame needs for every point. */\ntype Facing = {\n  sinLongitude: number;\n  cosLongitude: number;\n  sinLatitude: number;\n  cosLatitude: number;\n};\n\n/** Where a point of the sphere lands on the picture: across and up from its centre, and how far it faces the viewer. */\ntype Seen = {\n  across: number;\n  up: number;\n  depth: number;\n};\n\ntype GlobeState = {\n  canvas: HTMLCanvasElement;\n  pen: CanvasRenderingContext2D | null;\n  width: number;\n  height: number;\n  centreX: number;\n  centreY: number;\n  radius: number;\n  land: Land;\n  words: Word[];\n  frames: WordFrame[];\n  /** How far each word has faded in, from 0 to 1. */\n  shown: Float32Array;\n  areWordsSettled: boolean;\n  inks: Map<string, Ink>;\n  centres: HelloLanguage['centre'][];\n  family: string;\n  dotColor: string;\n  wordColor: string;\n  litColor: string;\n  longitude: number;\n  latitude: number;\n  turn: Turn | null;\n  lit: number;\n  fading: number;\n  /** How much of the light has passed from the language that fades to the one that is lit, from 0 to 1. */\n  glow: number;\n  spinLongitude: number;\n  spinLatitude: number;\n  grabbedBy: number | null;\n  lastX: number;\n  lastY: number;\n  lastMoveAt: number;\n  isLive: boolean;\n  frame: number;\n  lastTick: number;\n  lastDrawAt: number;\n};\n\ntype WordGlobe = {\n  turnTo: (index: number) => void;\n  setLive: (isLive: boolean) => void;\n  grab: (event: PointerEvent) => void;\n  drag: (event: PointerEvent) => void;\n  release: (event: PointerEvent) => void;\n  dispose: () => void;\n};\n\nconst NO_LANGUAGE = -1;\n\nconst TAU = Math.PI * 2;\n\nconst LONGITUDE_SPAN = DOTTED_MAP_BOUNDS.lngMax - DOTTED_MAP_BOUNDS.lngMin;\n\nconst LATITUDE_SPAN = DOTTED_MAP_BOUNDS.latMax - DOTTED_MAP_BOUNDS.latMin;\n\n/** The globe stops this short of the canvas edge, so the dots on its rim are drawn whole. */\nconst RIM_PX = 2;\n\nconst BODY_ALPHA = 0.04;\n\n/** Dots are sorted into a few steps by how much they face the viewer, and each step is filled at once. */\nconst DOT_STEPS = 5;\n\nconst DOT_RIM_PX = 0.7;\n\nconst DOT_FRONT_PX = 1.2;\n\nconst DOT_RIM_ALPHA = 0.1;\n\nconst DOT_FRONT_ALPHA = 0.34;\n\n/** More greetings than this at once and the globe reads as a page of text. */\nconst MAX_WORDS = 8;\n\nconst WORD_PX = 13;\n\nconst PICKED_WORD_PX = 15;\n\nconst WORD_WEIGHT = 500;\n\nconst WORD_PAD_PX = 3;\n\nconst WORD_GAP_PX = 4;\n\n/** A word fades in as it turns from the rim towards the viewer, between these depths. */\nconst WORD_FADE_FROM = 0.3;\n\nconst WORD_FADE_TO = 0.6;\n\nconst WORD_FADE_MS = 220;\n\nconst MIN_ALPHA = 0.01;\n\n/** The picked greeting claims its room first, then the words already shown, so a word stays put while it can. */\nconst PICKED_PASS = 0;\n\nconst SHOWN_PASS = 1;\n\nconst NEW_PASS = 2;\n\nconst PASSES = [PICKED_PASS, SHOWN_PASS, NEW_PASS];\n\nconst NO_INK: Ink = { left: 0, right: 0, ascent: 0, descent: 0 };\n\nconst TURN_MS = 950;\n\n/** A turn shorter than this, in degrees, is not worth a frame. */\nconst ALREADY_THERE = 0.01;\n\nconst MAX_LATITUDE = 70;\n\nconst MOMENTUM_DECAY_MS = 420;\n\nconst HELD_STILL_MS = 80;\n\n/** Degrees per millisecond under which a spin counts as over. */\nconst MIN_SPIN = 0.002;\n\nconst MAX_SPIN = 0.6;\n\n/** A frame that comes late, after a hidden tab, turns the globe no further than this long would. */\nconst MAX_STEP_MS = 50;\n\nfunction shareOfStep(step: number) {\n  return (step + 0.5) / DOT_STEPS;\n}\n\nfunction dotRadiusOf(step: number) {\n  const share = shareOfStep(step);\n  return DOT_RIM_PX + (DOT_FRONT_PX - DOT_RIM_PX) * share;\n}\n\nfunction dotAlphaOf(step: number) {\n  const share = shareOfStep(step);\n  return DOT_RIM_ALPHA + (DOT_FRONT_ALPHA - DOT_RIM_ALPHA) * share;\n}\n\nconst DOT_STEP_INDEXES = Array.from({ length: DOT_STEPS }, (_, step) => step);\n\nconst DOT_RADII = DOT_STEP_INDEXES.map(dotRadiusOf);\n\nconst DOT_ALPHAS = DOT_STEP_INDEXES.map(dotAlphaOf);\n\nfunction mapRunsOf() {\n  const matches = DOTTED_MAP_PATH.matchAll(/M([\\d.]+) ([\\d.]+)h(\\d+)/g);\n  const runs: MapRun[] = [];\n  for (const match of matches) {\n    runs.push({\n      column: Number(match[1]),\n      line: Number(match[2]),\n      length: Number(match[3]),\n    });\n  }\n  return runs;\n}\n\nfunction longitudeOf(column: number) {\n  const share = column / DOTTED_MAP_WIDTH;\n  return DOTTED_MAP_BOUNDS.lngMin + share * LONGITUDE_SPAN;\n}\n\nfunction latitudeOf(line: number) {\n  const share = line / DOTTED_MAP_HEIGHT;\n  return DOTTED_MAP_BOUNDS.latMax - share * LATITUDE_SPAN;\n}\n\nfunction vectorOf(latitudeDeg: number, longitudeDeg: number): Vector {\n  const latitude = radiansOf(latitudeDeg);\n  const longitude = radiansOf(longitudeDeg);\n  const ring = Math.cos(latitude);\n  return {\n    east: ring * Math.sin(longitude),\n    north: Math.sin(latitude),\n    front: ring * Math.cos(longitude),\n  };\n}\n\n/** The points of the map as places of the sphere, line by line from north to south. */\nfunction landOf(): Land {\n  const vectors: Vector[] = [];\n  for (const run of mapRunsOf()) {\n    const latitude = latitudeOf(run.line);\n    for (let step = 0; step <= run.length; step += 1) {\n      const longitude = longitudeOf(run.column + step);\n      vectors.push(vectorOf(latitude, longitude));\n    }\n  }\n  const count = vectors.length;\n  const land: Land = {\n    count,\n    east: new Float32Array(count),\n    north: new Float32Array(count),\n    front: new Float32Array(count),\n  };\n  vectors.forEach((vector, index) => {\n    land.east[index] = vector.east;\n    land.north[index] = vector.north;\n    land.front[index] = vector.front;\n  });\n  return land;\n}\n\n/** The greetings of the list first, each at its centre, then the other places. */\nfunction wordsOf(languages: HelloLanguage[], places: HelloPlace[]): Word[] {\n  const spoken = languages.map((language, index) => ({\n    text: language.greeting,\n    place: vectorOf(language.centre[0], language.centre[1]),\n    language: index,\n  }));\n  const written = places.map((place) => ({\n    text: place.greeting,\n    place: vectorOf(place.location[0], place.location[1]),\n    language: NO_LANGUAGE,\n  }));\n  return [...spoken, ...written];\n}\n\nfunction blankFrameOf(): WordFrame {\n  return {\n    x: 0,\n    y: 0,\n    facing: 0,\n    emphasis: 0,\n    size: WORD_PX,\n    box: { left: 0, top: 0, right: 0, bottom: 0 },\n    isPlaced: false,\n  };\n}\n\nfunction fontOf(sizePx: number, family: string) {\n  return `${WORD_WEIGHT} ${sizePx}px ${family}`;\n}\n\n/** A word is measured once, at the reference size, from its real ink: scripts reach above and below the line differently. */\nfunction inkOf(state: GlobeState, text: string) {\n  const known = state.inks.get(text);\n  if (known) {\n    return known;\n  }\n  const { pen } = state;\n  if (!pen) {\n    return NO_INK;\n  }\n  pen.font = fontOf(WORD_PX, state.family);\n  pen.textAlign = 'center';\n  pen.textBaseline = 'alphabetic';\n  const metrics = pen.measureText(text);\n  const ink: Ink = {\n    left: metrics.actualBoundingBoxLeft,\n    right: metrics.actualBoundingBoxRight,\n    ascent: metrics.actualBoundingBoxAscent,\n    descent: metrics.actualBoundingBoxDescent,\n  };\n  state.inks.set(text, ink);\n  return ink;\n}\n\nfunction ink(state: GlobeState) {\n  const { canvas } = state;\n  state.family = getComputedStyle(canvas).fontFamily;\n  state.dotColor = tokenOf(canvas, '--foreground');\n  state.wordColor = tokenOf(canvas, '--muted-foreground');\n  state.litColor = tokenOf(canvas, '--primary-ink');\n  state.inks.clear();\n}\n\n/** The dots and the words share this one centre and radius, so the globe sits in its disk whatever the box. */\nfunction measure(state: GlobeState) {\n  const { canvas } = state;\n  const width = canvas.clientWidth;\n  const height = canvas.clientHeight;\n  const shortSide = Math.min(width, height);\n  const radius = shortSide / 2 - RIM_PX;\n  state.width = width;\n  state.height = height;\n  state.centreX = width / 2;\n  state.centreY = height / 2;\n  state.radius = Math.max(radius, 0);\n  state.pen = penOf(canvas, width, height);\n}\n\nfunction facingOf(state: GlobeState): Facing {\n  const longitude = radiansOf(state.longitude);\n  const latitude = radiansOf(state.latitude);\n  return {\n    sinLongitude: Math.sin(longitude),\n    cosLongitude: Math.cos(longitude),\n    sinLatitude: Math.sin(latitude),\n    cosLatitude: Math.cos(latitude),\n  };\n}\n\n/** Turns a point of the sphere to where the viewer sees it. The result is written into `seen`, so a frame makes no garbage. */\nfunction see(\n  facing: Facing,\n  east: number,\n  north: number,\n  front: number,\n  seen: Seen\n) {\n  const turnedFront = east * facing.sinLongitude + front * facing.cosLongitude;\n  seen.across = east * facing.cosLongitude - front * facing.sinLongitude;\n  seen.up = north * facing.cosLatitude - turnedFront * facing.sinLatitude;\n  seen.depth = north * facing.sinLatitude + turnedFront * facing.cosLatitude;\n}\n\nfunction lightOf(state: GlobeState, language: number) {\n  if (language === NO_LANGUAGE) {\n    return 0;\n  }\n  if (language === state.lit) {\n    return state.glow;\n  }\n  if (language === state.fading) {\n    return 1 - state.glow;\n  }\n  return 0;\n}\n\nfunction rampOf(from: number, to: number, value: number) {\n  const progress = (value - from) / (to - from);\n  const atLeast = Math.max(0, progress);\n  const bounded = Math.min(1, atLeast);\n  const squared = bounded * bounded;\n  const easing = 3 - 2 * bounded;\n  return squared * easing;\n}\n\nfunction frameWord(\n  state: GlobeState,\n  index: number,\n  facing: Facing,\n  seen: Seen\n) {\n  const word = state.words[index];\n  const frame = state.frames[index];\n  const { place } = word;\n  see(facing, place.east, place.north, place.front, seen);\n  const emphasis = lightOf(state, word.language);\n  const sizeGap = PICKED_WORD_PX - WORD_PX;\n  const size = WORD_PX + sizeGap * emphasis;\n  const scale = size / WORD_PX;\n  const wordInk = inkOf(state, word.text);\n  const halfHeight = ((wordInk.ascent + wordInk.descent) * scale) / 2;\n  const reachLeft = wordInk.left * scale + WORD_PAD_PX;\n  const reachRight = wordInk.right * scale + WORD_PAD_PX;\n  const reachUp = halfHeight + WORD_PAD_PX;\n  const x = state.centreX + seen.across * state.radius;\n  const y = state.centreY - seen.up * state.radius;\n  frame.x = x;\n  frame.y = y;\n  frame.facing = rampOf(WORD_FADE_FROM, WORD_FADE_TO, seen.depth);\n  frame.emphasis = emphasis;\n  frame.size = size;\n  frame.isPlaced = false;\n  frame.box.left = x - reachLeft;\n  frame.box.right = x + reachRight;\n  frame.box.top = y - reachUp;\n  frame.box.bottom = y + reachUp;\n}\n\nfunction isWithinDisk(state: GlobeState, x: number, y: number) {\n  const across = x - state.centreX;\n  const down = y - state.centreY;\n  const reach = state.radius - 1;\n  const distanceSquared = across * across + down * down;\n  return distanceSquared <= reach * reach;\n}\n\nfunction isInsideDisk(state: GlobeState, box: Box) {\n  const isTopLeftIn = isWithinDisk(state, box.left, box.top);\n  const isTopRightIn = isWithinDisk(state, box.right, box.top);\n  const isBottomLeftIn = isWithinDisk(state, box.left, box.bottom);\n  const isBottomRightIn = isWithinDisk(state, box.right, box.bottom);\n  const isTopIn = isTopLeftIn && isTopRightIn;\n  const isBottomIn = isBottomLeftIn && isBottomRightIn;\n  return isTopIn && isBottomIn;\n}\n\nfunction boxesOverlap(first: Box, second: Box) {\n  const isLeftOf = first.right + WORD_GAP_PX <= second.left;\n  const isRightOf = second.right + WORD_GAP_PX <= first.left;\n  const isAbove = first.bottom + WORD_GAP_PX <= second.top;\n  const isBelow = second.bottom + WORD_GAP_PX <= first.top;\n  const isApartAcross = isLeftOf || isRightOf;\n  const isApartDown = isAbove || isBelow;\n  return !isApartAcross && !isApartDown;\n}\n\nfunction passOf(state: GlobeState, index: number) {\n  const word = state.words[index];\n  const isPicked = word.language === state.lit;\n  if (isPicked) {\n    return PICKED_PASS;\n  }\n  const isShown = state.shown[index] > 0.5;\n  if (isShown) {\n    return SHOWN_PASS;\n  }\n  return NEW_PASS;\n}\n\n/** A placed word is in the way of every other one. A word still fading out is in the way of a newcomer only, so two never cross. */\nfunction isInTheWay(\n  state: GlobeState,\n  otherIndex: number,\n  isNewcomer: boolean\n) {\n  const other = state.frames[otherIndex];\n  const isVisible = state.shown[otherIndex] > MIN_ALPHA;\n  const isLeaving = isNewcomer && isVisible;\n  return other.isPlaced || isLeaving;\n}\n\nfunction collides(state: GlobeState, index: number, isNewcomer: boolean) {\n  const { box } = state.frames[index];\n  return state.frames.some((other, otherIndex) => {\n    if (otherIndex === index) {\n      return false;\n    }\n    if (!isInTheWay(state, otherIndex, isNewcomer)) {\n      return false;\n    }\n    return boxesOverlap(other.box, box);\n  });\n}\n\nfunction fits(state: GlobeState, index: number, placedCount: number) {\n  const frame = state.frames[index];\n  const hasRoom = placedCount < MAX_WORDS;\n  const isFacing = frame.facing > 0;\n  if (!hasRoom || !isFacing) {\n    return false;\n  }\n  if (!isInsideDisk(state, frame.box)) {\n    return false;\n  }\n  const isNewcomer = passOf(state, index) === NEW_PASS;\n  return !collides(state, index, isNewcomer);\n}\n\n/** Words claim their room in turn: a word that would cover one already placed, or leave the disk, is left out. */\nfunction placeWords(state: GlobeState) {\n  let placedCount = 0;\n  for (const pass of PASSES) {\n    state.frames.forEach((frame, index) => {\n      const isItsPass = passOf(state, index) === pass;\n      if (!isItsPass) {\n        return;\n      }\n      if (fits(state, index, placedCount)) {\n        frame.isPlaced = true;\n        placedCount += 1;\n      }\n    });\n  }\n}\n\nfunction movedTowards(current: number, target: number, step: number) {\n  if (current < target) {\n    const raised = current + step;\n    return Math.min(target, raised);\n  }\n  const lowered = current - step;\n  return Math.max(target, lowered);\n}\n\n/** Words fade in and out over a few frames while the globe plays. Without motion they are where they belong at once. */\nfunction fadeWords(state: GlobeState, elapsed: number) {\n  const step = elapsed / WORD_FADE_MS;\n  let isSettled = true;\n  state.frames.forEach((frame, index) => {\n    const target = Number(frame.isPlaced);\n    let next = target;\n    if (state.isLive) {\n      next = movedTowards(state.shown[index], target, step);\n    }\n    state.shown[index] = next;\n    if (next !== target) {\n      isSettled = false;\n    }\n  });\n  return isSettled;\n}\n\nfunction wordAlphaOf(state: GlobeState, index: number) {\n  const frame = state.frames[index];\n  return state.shown[index] * frame.facing;\n}\n\nfunction stepOfDepth(depth: number) {\n  const step = Math.floor(depth * DOT_STEPS);\n  return Math.min(DOT_STEPS - 1, step);\n}\n\nfunction drawDots(\n  state: GlobeState,\n  pen: CanvasRenderingContext2D,\n  facing: Facing,\n  seen: Seen\n) {\n  const { land } = state;\n  const layers = DOT_STEP_INDEXES.map(() => new Path2D());\n  for (let index = 0; index < land.count; index += 1) {\n    see(facing, land.east[index], land.north[index], land.front[index], seen);\n    if (seen.depth <= 0) {\n      continue;\n    }\n    const step = stepOfDepth(seen.depth);\n    const dotRadius = DOT_RADII[step];\n    const x = state.centreX + seen.across * state.radius;\n    const y = state.centreY - seen.up * state.radius;\n    const layer = layers[step];\n    layer.moveTo(x + dotRadius, y);\n    layer.arc(x, y, dotRadius, 0, TAU);\n  }\n  pen.fillStyle = state.dotColor;\n  layers.forEach((layer, step) => {\n    pen.globalAlpha = DOT_ALPHAS[step];\n    pen.fill(layer);\n  });\n}\n\n/** Each word sits on a clear patch: the dots under it fade out as the word fades in. */\nfunction clearUnderWords(state: GlobeState, pen: CanvasRenderingContext2D) {\n  pen.globalCompositeOperation = 'destination-out';\n  pen.fillStyle = state.dotColor;\n  state.frames.forEach((frame, index) => {\n    const alpha = wordAlphaOf(state, index);\n    if (alpha < MIN_ALPHA) {\n      return;\n    }\n    const { box } = frame;\n    const width = box.right - box.left;\n    const height = box.bottom - box.top;\n    pen.globalAlpha = alpha;\n    pen.fillRect(box.left, box.top, width, height);\n  });\n  pen.globalCompositeOperation = 'source-over';\n}\n\n/** The body goes under what is drawn, so the patches cleared for the words keep its tint. */\nfunction drawBody(state: GlobeState, pen: CanvasRenderingContext2D) {\n  pen.globalCompositeOperation = 'destination-over';\n  pen.globalAlpha = BODY_ALPHA;\n  pen.fillStyle = state.dotColor;\n  pen.beginPath();\n  pen.arc(state.centreX, state.centreY, state.radius, 0, TAU);\n  pen.fill();\n  pen.globalCompositeOperation = 'source-over';\n}\n\nfunction writeWord(\n  pen: CanvasRenderingContext2D,\n  text: string,\n  x: number,\n  y: number,\n  color: string,\n  alpha: number\n) {\n  if (alpha < MIN_ALPHA) {\n    return;\n  }\n  pen.globalAlpha = alpha;\n  pen.fillStyle = color;\n  pen.fillText(text, x, y);\n}\n\n/** The picked greeting passes from the quiet ink to the brand ink on the same letters, so its colour changes without a jump. */\nfunction drawWords(state: GlobeState, pen: CanvasRenderingContext2D) {\n  pen.textAlign = 'center';\n  pen.textBaseline = 'alphabetic';\n  state.frames.forEach((frame, index) => {\n    const alpha = wordAlphaOf(state, index);\n    if (alpha < MIN_ALPHA) {\n      return;\n    }\n    const { text } = state.words[index];\n    const wordInk = inkOf(state, text);\n    const scale = frame.size / WORD_PX;\n    const lift = ((wordInk.ascent - wordInk.descent) * scale) / 2;\n    const baseline = frame.y + lift;\n    const quietAlpha = alpha * (1 - frame.emphasis);\n    const litAlpha = alpha * frame.emphasis;\n    pen.font = fontOf(frame.size, state.family);\n    writeWord(pen, text, frame.x, baseline, state.wordColor, quietAlpha);\n    writeWord(pen, text, frame.x, baseline, state.litColor, litAlpha);\n  });\n}\n\nfunction paint(\n  state: GlobeState,\n  pen: CanvasRenderingContext2D,\n  facing: Facing,\n  seen: Seen\n) {\n  pen.clearRect(0, 0, state.width, state.height);\n  drawDots(state, pen, facing, seen);\n  clearUnderWords(state, pen);\n  drawBody(state, pen);\n  drawWords(state, pen);\n  pen.globalAlpha = 1;\n}\n\nfunction render(state: GlobeState) {\n  const { pen } = state;\n  const hasRoom = state.radius > 0;\n  if (!pen || !hasRoom) {\n    return;\n  }\n  const now = performance.now();\n  const sinceLast = now - state.lastDrawAt;\n  const elapsed = Math.min(sinceLast, MAX_STEP_MS);\n  const facing = facingOf(state);\n  const seen: Seen = { across: 0, up: 0, depth: 0 };\n  state.lastDrawAt = now;\n  state.frames.forEach((_, index) => frameWord(state, index, facing, seen));\n  placeWords(state);\n  state.areWordsSettled = fadeWords(state, elapsed);\n  paint(state, pen, facing, seen);\n}\n\nfunction easedOf(progress: number) {\n  if (progress < 0.5) {\n    return 4 * progress ** 3;\n  }\n  const left = 2 - 2 * progress;\n  return 1 - left ** 3 / 2;\n}\n\nfunction boundedLatitudeOf(latitude: number) {\n  const atLeast = Math.max(-MAX_LATITUDE, latitude);\n  return Math.min(MAX_LATITUDE, atLeast);\n}\n\nfunction boundedSpinOf(spin: number) {\n  const atLeast = Math.max(-MAX_SPIN, spin);\n  return Math.min(MAX_SPIN, atLeast);\n}\n\nfunction isSpinning(state: GlobeState) {\n  const speed = Math.hypot(state.spinLongitude, state.spinLatitude);\n  return speed > MIN_SPIN;\n}\n\nfunction stopSpin(state: GlobeState) {\n  state.spinLongitude = 0;\n  state.spinLatitude = 0;\n}\n\n/** The light is on its new language for good, wherever the globe is. */\nfunction endLight(state: GlobeState) {\n  state.glow = 1;\n  state.fading = NO_LANGUAGE;\n}\n\nfunction arrive(state: GlobeState, turn: Turn) {\n  state.longitude = turn.toLongitude;\n  state.latitude = turn.toLatitude;\n  state.turn = null;\n  endLight(state);\n}\n\nfunction stepTurn(state: GlobeState, turn: Turn, now: number) {\n  const progress = (now - turn.startedAt) / TURN_MS;\n  if (progress >= 1) {\n    arrive(state, turn);\n    return;\n  }\n  const eased = easedOf(progress);\n  const longitudeGap = turn.toLongitude - turn.fromLongitude;\n  const latitudeGap = turn.toLatitude - turn.fromLatitude;\n  state.longitude = turn.fromLongitude + longitudeGap * eased;\n  state.latitude = turn.fromLatitude + latitudeGap * eased;\n  state.glow = eased;\n}\n\nfunction stepSpin(state: GlobeState, elapsed: number) {\n  const decay = Math.exp(-elapsed / MOMENTUM_DECAY_MS);\n  const latitude = state.latitude + state.spinLatitude * elapsed;\n  state.longitude += state.spinLongitude * elapsed;\n  state.latitude = boundedLatitudeOf(latitude);\n  state.spinLongitude *= decay;\n  state.spinLatitude *= decay;\n}\n\nfunction step(state: GlobeState, now: number, elapsed: number) {\n  if (state.turn) {\n    stepTurn(state, state.turn, now);\n    return;\n  }\n  stepSpin(state, elapsed);\n}\n\nfunction isAtRest(state: GlobeState) {\n  const isTurning = state.turn !== null;\n  const isHeld = state.grabbedBy !== null;\n  const isCoasting = !isHeld && isSpinning(state);\n  const isMoving = isTurning || isCoasting;\n  return !isMoving && state.areWordsSettled;\n}\n\n/** Frames are asked for only while the globe turns or coasts, or a word fades. At rest it is a still picture. */\nfunction tick(state: GlobeState, now: number) {\n  const sinceLast = now - state.lastTick;\n  const elapsed = Math.min(sinceLast, MAX_STEP_MS);\n  const isHeld = state.grabbedBy !== null;\n  state.lastTick = now;\n  if (!isHeld) {\n    step(state, now, elapsed);\n  }\n  render(state);\n  if (!isAtRest(state)) {\n    state.frame = requestAnimationFrame((next) => tick(state, next));\n    return;\n  }\n  state.frame = 0;\n  if (!isHeld) {\n    stopSpin(state);\n  }\n}\n\nfunction wake(state: GlobeState) {\n  const isAwake = state.frame !== 0;\n  if (!state.isLive || isAwake) {\n    return;\n  }\n  state.lastTick = performance.now();\n  state.frame = requestAnimationFrame((now) => tick(state, now));\n}\n\nfunction sleep(state: GlobeState) {\n  cancelAnimationFrame(state.frame);\n  state.frame = 0;\n}\n\n/** Draws the picture again, and asks for frames while something on it still has to move. */\nfunction renderAndFollow(state: GlobeState) {\n  render(state);\n  if (!isAtRest(state)) {\n    wake(state);\n  }\n}\n\n/** Without motion, a turn that was on its way lands at once and a spin stops where it is. */\nfunction settle(state: GlobeState) {\n  sleep(state);\n  if (state.turn) {\n    arrive(state, state.turn);\n  }\n  stopSpin(state);\n  render(state);\n}\n\nfunction turnTo(state: GlobeState, index: number) {\n  const place = state.centres[index];\n  if (!place) {\n    return;\n  }\n  const toLongitude = nearestAngleOf(place[1], state.longitude);\n  const toLatitude = boundedLatitudeOf(place[0]);\n  const longitudeGap = Math.abs(toLongitude - state.longitude);\n  const latitudeGap = Math.abs(toLatitude - state.latitude);\n  const isThere = longitudeGap + latitudeGap < ALREADY_THERE;\n  const isSameLanguage = index === state.lit;\n  if (isSameLanguage && isThere) {\n    return;\n  }\n  if (!isSameLanguage) {\n    state.fading = state.lit;\n    state.lit = index;\n    state.glow = 0;\n  }\n  stopSpin(state);\n  state.turn = {\n    fromLongitude: state.longitude,\n    fromLatitude: state.latitude,\n    toLongitude,\n    toLatitude,\n    startedAt: performance.now(),\n  };\n  if (!state.isLive) {\n    settle(state);\n    return;\n  }\n  wake(state);\n}\n\nfunction grab(state: GlobeState, event: PointerEvent) {\n  const isMainButton = event.button === 0;\n  const isFree = state.grabbedBy === null;\n  if (!isMainButton || !isFree) {\n    return;\n  }\n  sleep(state);\n  stopSpin(state);\n  endLight(state);\n  state.turn = null;\n  state.grabbedBy = event.pointerId;\n  state.lastX = event.clientX;\n  state.lastY = event.clientY;\n  state.lastMoveAt = event.timeStamp;\n  state.canvas.setPointerCapture(event.pointerId);\n  renderAndFollow(state);\n}\n\nfunction drag(state: GlobeState, event: PointerEvent) {\n  if (event.pointerId !== state.grabbedBy) {\n    return;\n  }\n  const radius = Math.max(state.radius, 1);\n  const degreesPerPixel = degreesOf(1 / radius);\n  const sinceLast = event.timeStamp - state.lastMoveAt;\n  const elapsed = Math.max(sinceLast, 1);\n  const turned = (state.lastX - event.clientX) * degreesPerPixel;\n  const tilted = (event.clientY - state.lastY) * degreesPerPixel;\n  const spinLongitude = boundedSpinOf(turned / elapsed);\n  const spinLatitude = boundedSpinOf(tilted / elapsed);\n  state.longitude += turned;\n  state.latitude = boundedLatitudeOf(state.latitude + tilted);\n  state.spinLongitude = state.spinLongitude * 0.5 + spinLongitude * 0.5;\n  state.spinLatitude = state.spinLatitude * 0.5 + spinLatitude * 0.5;\n  state.lastX = event.clientX;\n  state.lastY = event.clientY;\n  state.lastMoveAt = event.timeStamp;\n  renderAndFollow(state);\n}\n\nfunction release(state: GlobeState, event: PointerEvent) {\n  if (event.pointerId !== state.grabbedBy) {\n    return;\n  }\n  const stillFor = event.timeStamp - state.lastMoveAt;\n  const wasHeldStill = stillFor > HELD_STILL_MS;\n  state.grabbedBy = null;\n  if (wasHeldStill || !state.isLive) {\n    stopSpin(state);\n    renderAndFollow(state);\n    return;\n  }\n  wake(state);\n}\n\nfunction setLive(state: GlobeState, isLive: boolean) {\n  state.isLive = isLive;\n  if (isLive) {\n    return;\n  }\n  settle(state);\n}\n\nfunction refit(state: GlobeState) {\n  measure(state);\n  renderAndFollow(state);\n}\n\nfunction reink(state: GlobeState) {\n  ink(state);\n  renderAndFollow(state);\n}\n\n/**\n * One canvas for the whole globe. It is drawn again only when something changes what it shows: a\n * turn, a drag, a spin, a word that fades, a new size or a new theme.\n */\nfunction createWordGlobe(\n  canvas: HTMLCanvasElement,\n  languages: HelloLanguage[],\n  places: HelloPlace[],\n  startIndex: number\n): WordGlobe {\n  const centres = languages.map((language) => language.centre);\n  const start = centres[startIndex] ?? [0, 0];\n  const words = wordsOf(languages, places);\n  const state: GlobeState = {\n    canvas,\n    pen: null,\n    width: 0,\n    height: 0,\n    centreX: 0,\n    centreY: 0,\n    radius: 0,\n    land: landOf(),\n    words,\n    frames: words.map(() => blankFrameOf()),\n    shown: new Float32Array(words.length),\n    areWordsSettled: true,\n    inks: new Map(),\n    centres,\n    family: '',\n    dotColor: '',\n    wordColor: '',\n    litColor: '',\n    longitude: start[1],\n    latitude: boundedLatitudeOf(start[0]),\n    turn: null,\n    lit: startIndex,\n    fading: NO_LANGUAGE,\n    glow: 1,\n    spinLongitude: 0,\n    spinLatitude: 0,\n    grabbedBy: null,\n    lastX: 0,\n    lastY: 0,\n    lastMoveAt: 0,\n    isLive: false,\n    frame: 0,\n    lastTick: 0,\n    lastDrawAt: 0,\n  };\n\n  ink(state);\n  refit(state);\n  const sizeObserver = new ResizeObserver(() => refit(state));\n  sizeObserver.observe(canvas);\n  const stopWatching = watchTheme(() => reink(state));\n\n  return {\n    turnTo: (index) => turnTo(state, index),\n    setLive: (isLive) => setLive(state, isLive),\n    grab: (event) => grab(state, event),\n    drag: (event) => drag(state, event),\n    release: (event) => release(state, event),\n    dispose() {\n      sleep(state);\n      sizeObserver.disconnect();\n      stopWatching();\n    },\n  };\n}\n\nfunction directionOf(language: HelloLanguage) {\n  if (language.isRightToLeft) {\n    return 'rtl';\n  }\n  return 'ltr';\n}\n\nconst NO_PLACES: HelloPlace[] = [];\n\nexport type HelloGlobeProps = {\n  /**\n   * Each language stands on the globe with its greeting. Keep the list stable, a constant or a\n   * memo: a new list builds the globe again.\n   */\n  languages: HelloLanguage[];\n  /** More greetings for the globe, each where it is written. Keep it stable too. */\n  places?: HelloPlace[];\n  /** The tag of the language that is picked. */\n  tag: string;\n  onTagChange: (tag: string) => void;\n  className?: string;\n};\n\nexport function HelloGlobe({\n  languages,\n  places = NO_PLACES,\n  tag,\n  onTagChange,\n  className,\n}: HelloGlobeProps) {\n  const { ref, isPlaying, isStill } = useScenePlay();\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const globeRef = useRef<WordGlobe | null>(null);\n  const found = languages.findIndex((language) => language.tag === tag);\n  const index = Math.max(found, 0);\n  const [startIndex] = useState(index);\n  const language = languages[index];\n  const presence = risePresenceOf(isStill);\n\n  useEffect(() => {\n    const canvas = canvasRef.current;\n    if (!canvas) {\n      return;\n    }\n    const globe = createWordGlobe(canvas, languages, places, startIndex);\n    globeRef.current = globe;\n    return () => {\n      globe.dispose();\n      globeRef.current = null;\n    };\n  }, [languages, places, startIndex]);\n\n  useEffect(() => {\n    globeRef.current?.setLive(isPlaying);\n  }, [isPlaying, languages, places]);\n\n  useEffect(() => {\n    globeRef.current?.turnTo(index);\n  }, [index, languages, places]);\n\n  if (!language) {\n    return null;\n  }\n\n  function pick(pressed: unknown[]) {\n    const [next] = pressed;\n    if (typeof next === 'string') {\n      onTagChange(next);\n    }\n  }\n\n  return (\n    <div ref={ref} className={cn('@container w-full max-w-[36rem]', className)}>\n      <div className='flex flex-col items-center gap-4 @lg:flex-row @lg:gap-6'>\n        <div className='relative aspect-square w-full max-w-72 shrink-0 @lg:w-60'>\n          <canvas\n            ref={canvasRef}\n            aria-hidden='true'\n            onPointerDown={(event) => globeRef.current?.grab(event.nativeEvent)}\n            onPointerMove={(event) => globeRef.current?.drag(event.nativeEvent)}\n            onPointerUp={(event) =>\n              globeRef.current?.release(event.nativeEvent)\n            }\n            onPointerCancel={(event) =>\n              globeRef.current?.release(event.nativeEvent)\n            }\n            className='absolute inset-0 size-full cursor-grab touch-pan-y active:cursor-grabbing'\n          />\n        </div>\n        <div className='flex w-full min-w-0 flex-1 flex-col gap-3'>\n          <div className='flex min-h-[4.75rem] flex-col justify-end gap-1'>\n            <AnimatePresence mode='wait' initial={false}>\n              <motion.p\n                key={language.tag}\n                lang={language.tag}\n                dir={directionOf(language)}\n                className='text-left text-4xl leading-[1.4] font-semibold'\n                {...presence}\n              >\n                {language.greeting}\n              </motion.p>\n            </AnimatePresence>\n            <p className='text-muted-foreground text-xs'>\n              {language.name}, {language.script} script\n            </p>\n          </div>\n          <ToggleGroup\n            aria-label='Language'\n            value={[language.tag]}\n            onValueChange={pick}\n            travel\n            size='sm'\n            className='grid w-full grid-cols-2 gap-0.5'\n          >\n            {languages.map((item) => (\n              <ToggleGroupItem\n                key={item.tag}\n                value={item.tag}\n                className='min-w-0 justify-start gap-1.5 px-2 text-xs'\n              >\n                <span lang={item.tag}>{item.endonym}</span>\n                <span className='text-muted-foreground truncate font-normal'>\n                  {item.name}\n                </span>\n              </ToggleGroupItem>\n            ))}\n          </ToggleGroup>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nconst LANGUAGES: HelloLanguage[] = [\n  {\n    tag: 'en',\n    name: 'English',\n    endonym: 'English',\n    script: 'Latin',\n    greeting: 'Hello',\n    centre: [39, -98],\n  },\n  {\n    tag: 'ru',\n    name: 'Russian',\n    endonym: 'Русский',\n    script: 'Cyrillic',\n    greeting: 'Привет',\n    centre: [58, 70],\n  },\n  {\n    tag: 'ar',\n    name: 'Arabic',\n    endonym: 'العربية',\n    script: 'Arabic',\n    greeting: 'مرحبا',\n    isRightToLeft: true,\n    centre: [26, 38],\n  },\n  {\n    tag: 'hi',\n    name: 'Hindi',\n    endonym: 'हिन्दी',\n    script: 'Devanagari',\n    greeting: 'नमस्ते',\n    centre: [22, 79],\n  },\n  {\n    tag: 'zh',\n    name: 'Chinese',\n    endonym: '中文',\n    script: 'Han',\n    greeting: '你好',\n    centre: [34, 105],\n  },\n  {\n    tag: 'ja',\n    name: 'Japanese',\n    endonym: '日本語',\n    script: 'Kana',\n    greeting: 'こんにちは',\n    centre: [37, 138],\n  },\n  {\n    tag: 'ko',\n    name: 'Korean',\n    endonym: '한국어',\n    script: 'Hangul',\n    greeting: '안녕하세요',\n    centre: [37, 127.5],\n  },\n  {\n    tag: 'el',\n    name: 'Greek',\n    endonym: 'Ελληνικά',\n    script: 'Greek',\n    greeting: 'Γεια σου',\n    centre: [38.5, 23.5],\n  },\n  {\n    tag: 'he',\n    name: 'Hebrew',\n    endonym: 'עברית',\n    script: 'Hebrew',\n    greeting: 'שלום',\n    isRightToLeft: true,\n    centre: [31.5, 35],\n  },\n  {\n    tag: 'th',\n    name: 'Thai',\n    endonym: 'ไทย',\n    script: 'Thai',\n    greeting: 'สวัสดี',\n    centre: [15, 101],\n  },\n];\n\nconst PLACES: HelloPlace[] = [\n  { greeting: 'Hola', location: [23.6, -102.5] },\n  { greeting: 'Bonjour', location: [50, -72] },\n  { greeting: 'Hola', location: [4.5, -74] },\n  { greeting: 'Hola', location: [-34, -64] },\n  { greeting: 'Olá', location: [-10, -52] },\n  { greeting: 'Aloha', location: [20.8, -156.3] },\n  { greeting: 'Hola', location: [40, -3.7] },\n  { greeting: 'Bonjour', location: [46.6, 2.4] },\n  { greeting: 'Hallo', location: [51.2, 10.4] },\n  { greeting: 'Hej', location: [62, 15] },\n  { greeting: 'Привіт', location: [49, 31.5] },\n  { greeting: 'Merhaba', location: [39, 35] },\n  { greeting: 'مرحبا', location: [31.8, -7] },\n  { greeting: 'Sannu', location: [12, 8.5] },\n  { greeting: 'Habari', location: [-3.4, 36] },\n  { greeting: 'Sawubona', location: [-28.5, 30.5] },\n  { greeting: 'سلام', location: [32.5, 54] },\n  { greeting: 'Привет', location: [62, 125] },\n  { greeting: 'Xin chào', location: [16, 107.8] },\n  { greeting: 'Kumusta', location: [12.9, 122] },\n  { greeting: 'Halo', location: [-2.5, 118] },\n  { greeting: 'Hello', location: [-25, 134] },\n  { greeting: 'Kia ora', location: [-41, 174] },\n];\n\nconst START_TAG = 'en';\n\nconst TOUR = ['ja', 'ar', 'hi', 'ru', 'el'];\n\nconst TOUR_HOLD_MS = 3200;\n\nfunction announcementOf(tag: string) {\n  const language = LANGUAGES.find((item) => item.tag === tag);\n  if (!language) {\n    return '';\n  }\n  return `${language.name}: ${language.greeting}`;\n}\n\nexport default function Illustration12() {\n  const [tag, setTag] = useState(START_TAG);\n  const steps: AutoplayStep[] = TOUR.map((stop) => ({\n    after: TOUR_HOLD_MS,\n    run: () => setTag(stop),\n  }));\n  const { ref, isAutoplaying } = useAutoplay(steps, {\n    loopAfter: TOUR_HOLD_MS,\n    onReset: () => setTag(START_TAG),\n  });\n  const announcement = announcementOf(tag);\n\n  return (\n    <div ref={ref} className='flex w-full justify-center'>\n      <HelloGlobe\n        languages={LANGUAGES}\n        places={PLACES}\n        tag={tag}\n        onTagChange={setTag}\n      />\n      <LiveRegion message={spokenUnless(isAutoplaying, announcement)} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/illustration/illustration-12.tsx"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/canvas.ts",
      "content": "/** A backing store above two device pixels a point costs four times the fill for a picture nobody sees sharper. */\nconst MAX_PIXEL_RATIO = 2;\n\nexport function pixelRatioOf() {\n  const screenRatio = window.devicePixelRatio || 1;\n  return Math.min(screenRatio, MAX_PIXEL_RATIO);\n}\n\n/** Sizes the backing store of a canvas for the screen and hands back a pen that draws in CSS pixels. */\nexport function penOf(\n  canvas: HTMLCanvasElement,\n  width: number,\n  height: number\n) {\n  const ratio = pixelRatioOf();\n  const pixelWidth = Math.round(width * ratio);\n  const pixelHeight = Math.round(height * ratio);\n  if (canvas.width !== pixelWidth) {\n    canvas.width = pixelWidth;\n  }\n  if (canvas.height !== pixelHeight) {\n    canvas.height = pixelHeight;\n  }\n  const pen = canvas.getContext('2d');\n  pen?.setTransform(ratio, 0, 0, ratio, 0, 0);\n  return pen;\n}\n\n/** The value of a theme token where the element stands, or its text colour when the token is not set. */\nexport function tokenOf(element: Element, token: string) {\n  const styles = getComputedStyle(element);\n  const value = styles.getPropertyValue(token).trim();\n  return value || styles.color;\n}\n\n/** A canvas holds the colours it was drawn with: it is told when the theme of the page changes. */\nexport function watchTheme(onChange: () => void) {\n  const observer = new MutationObserver(onChange);\n  observer.observe(document.documentElement, {\n    attributes: true,\n    attributeFilter: ['class', 'style', 'data-theme'],\n  });\n  return () => observer.disconnect();\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/canvas.ts"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/geometry.ts",
      "content": "export type ScenePoint = {\n  /** Share of the stage width, from 0 to 1. */\n  x: number;\n  /** Share of the stage height, from 0 to 1. */\n  y: number;\n};\n\nexport type SceneSpan = {\n  /** Length of the line as a percentage of the stage width. */\n  lengthPercent: number;\n  /** Angle of the line in degrees, clockwise from the right, as CSS turns it. */\n  angleDeg: number;\n};\n\nconst HALF_TURN_DEG = 180;\n\nconst FULL_TURN_DEG = 360;\n\n/**\n * Two engines can disagree on the last digit of a sine. A value written into a style is rounded, so\n * the server and the browser print the same text.\n */\nexport function rounded(value: number) {\n  const hundredths = Math.round(value * 100);\n  return hundredths / 100;\n}\n\nexport function percentOf(share: number) {\n  const percent = rounded(share * 100);\n  return `${percent}%`;\n}\n\nexport function degreesOf(radians: number) {\n  return (radians * HALF_TURN_DEG) / Math.PI;\n}\n\nexport function radiansOf(degrees: number) {\n  return (degrees * Math.PI) / HALF_TURN_DEG;\n}\n\n/** The angle equal to `target` that is closest to `current`, so a turn towards it goes the short way round. */\nexport function nearestAngleOf(target: number, current: number) {\n  const difference = target - current;\n  const turns = Math.round(difference / FULL_TURN_DEG);\n  const wrapped = difference - FULL_TURN_DEG * turns;\n  return current + wrapped;\n}\n\n/** The line between two points of a stage that is `aspect` times wider than it is tall. */\nexport function spanBetween(\n  from: ScenePoint,\n  to: ScenePoint,\n  aspect: number\n): SceneSpan {\n  const acrossShare = to.x - from.x;\n  const downShare = to.y - from.y;\n  const downInWidths = downShare / aspect;\n  const lengthInWidths = Math.hypot(acrossShare, downInWidths);\n  const angle = Math.atan2(downInWidths, acrossShare);\n  const degrees = degreesOf(angle);\n  return {\n    lengthPercent: rounded(lengthInWidths * 100),\n    angleDeg: rounded(degrees),\n  };\n}\n\n/** Where a tile centred on a point of the stage goes: its `left` and `top`. */\nexport function placeOf(point: ScenePoint) {\n  return { left: percentOf(point.x), top: percentOf(point.y) };\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/geometry.ts"
    },
    {
      "path": "registry/ndeko/components/illustration/_parts/use-scene-play.ts",
      "content": "'use client';\n\nimport { useInView } from 'motion/react';\nimport { useRef } from 'react';\n\nimport { useDocumentVisible } from '@/registry/ndeko/hooks/use-agent-run';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\n\nconst IN_VIEW_SHARE = 0.3;\n\nexport type ScenePlay = {\n  /** True while a visitor can see the scene move: on screen, in a visible tab, without reduced motion. */\n  isPlaying: boolean;\n  /** True under reduced motion: the scene rests on its still frame. */\n  isStill: boolean;\n};\n\n/**\n * An illustration moves only while someone can see it. Everything that loops in a scene hangs on\n * `isPlaying`, so nothing runs off screen, in a hidden tab or under reduced motion.\n */\nexport function useScenePlay<Element extends HTMLElement = HTMLDivElement>() {\n  const ref = useRef<Element>(null);\n  const isInView = useInView(ref, { amount: IN_VIEW_SHARE });\n  const isTabVisible = useDocumentVisible();\n  const isStill = usePrefersReducedMotion();\n  const isOnScreen = isInView && isTabVisible;\n  const isPlaying = isOnScreen && !isStill;\n\n  return { ref, isPlaying, isStill };\n}\n",
      "type": "registry:component",
      "target": "components/illustration/_parts/use-scene-play.ts"
    }
  ],
  "categories": [
    "components",
    "illustration"
  ],
  "type": "registry:component"
}