{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dot-field-morph",
  "title": "Dot Field Morph",
  "description": "A drifting field of dots swirls into icon shapes, then gathers into the logo.",
  "dependencies": ["remotion", "@remotion/google-fonts", "@remotion/paths"],
  "files": [
    {
      "path": "registry/remocn/dot-field-morph/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport { getLength, getPointAtLength, getSubpaths } from \"@remotion/paths\";\nimport { useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: MANROPE } = loadManrope(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\n/**\n * Beat sheet (30fps, speed 1):\n * 0–14     a calm field of dots drifts across the frame.\n * 14–44    dots swirl in, centre first, into shape 1; label rises. Hold to 66.\n * 66–96    shape 2, hold to 118.  118–148 shape 3, hold to 170.\n * 170–206  the field gathers into the remocn.dev logo (R mark + \"emocn\").\n *          Hold to 250.\n * Dots take their colour from a slowly drifting gradients.sh \"mesh\" palette.\n */\n\nexport interface DotShapePart {\n  /** SVG path data, any units. All parts of a shape share one coordinate space. */\n  d: string;\n  /** Sample along the outline with this width instead of filling (icon-style paths). */\n  stroke?: number;\n  /** Dots inside this part take the accent colour. */\n  accent?: boolean;\n  /** Fill rule for filled parts. Font outlines with overlapping contours need \"nonzero\". */\n  fillRule?: \"evenodd\" | \"nonzero\";\n}\n\n/** A path string (filled, even-odd), one part, or several parts. */\nexport type DotShape = string | DotShapePart | DotShapePart[];\n\nexport interface DotFieldMorphProps {\n  /** Shapes in order after the scattered field; the last one holds. */\n  shapes?: DotShape[];\n  /** Optional caption under each shape (same order). Empty string = none. */\n  labels?: string[];\n  /** 1,500–2,500 reads as a field; more costs render time. */\n  count?: number;\n  accent?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\n// ── Built-in shapes (100-unit icons, line style) ────────────────────────────\n\nconst ICON_MOTION: DotShapePart[] = [\n  { d: \"M60 50 m-21 0 a21 21 0 1 0 42 0 a21 21 0 1 0 -42 0\" },\n  { d: \"M8 38 L30 38 M14 50 L32 50 M8 62 L30 62\", stroke: 6.5 },\n];\n\nconst ICON_TRANSITIONS: DotShapePart[] = [\n  {\n    // The back frame stops short of the front card, so it reads as behind it.\n    d: \"M27 68 H18 A8 8 0 0 1 10 60 V28 A8 8 0 0 1 18 20 H58 A8 8 0 0 1 66 28 V29\",\n    stroke: 6.5,\n  },\n  {\n    d: \"M42 36 H82 A8 8 0 0 1 90 44 V76 A8 8 0 0 1 82 84 H42 A8 8 0 0 1 34 76 V44 A8 8 0 0 1 42 36 Z\",\n  },\n];\n\nconst ICON_CAPTIONS: DotShapePart[] = [\n  {\n    d: \"M16 18 H84 A10 10 0 0 1 94 28 V64 A10 10 0 0 1 84 74 H40 L24 86 V74 H16 A10 10 0 0 1 6 64 V28 A10 10 0 0 1 16 18 Z\",\n    stroke: 6.5,\n  },\n  { d: \"M26 40 H74 M26 54 H56\", stroke: 6.5 },\n];\n\n// The remocn.dev logo: the R mark (0.76em, on the baseline) + \"emocn\" in\n// Manrope 600 at -0.025em, outlined at 100 units per em. Glyph contours\n// overlap (m, n, e's bar), so they fill nonzero.\nconst LOGO_R =\n  \"M 0.01 -75.54 C 0.01 -75.02 0.2 -74.42 0.62 -73.66 C 2.78 -69.75 7.61 -66.29 12.28 -65.3 C 12.99 -65.15 13.12 -65.15 29.09 -65.09 C 43.06 -65.04 45.3 -65.02 46.03 -64.92 C 50.88 -64.29 54.46 -62.03 56.26 -58.45 C 58.41 -54.17 58.04 -47.64 55.42 -43.69 C 53.58 -40.93 50.76 -39.21 47.13 -38.64 C 46.88 -38.6 39.73 -38.17 31.25 -37.68 C 14.05 -36.7 15.3 -36.81 13.69 -36.15 C 11.26 -35.16 8.4 -33.15 6.03 -30.78 C 2.75 -27.5 0.74 -23.97 0.14 -20.45 C 0.07 -20.04 0.05 -17.62 0.02 -9.96 L 0 0 5.38 0 L 10.76 0 10.78 -8.41 C 10.81 -17.54 10.8 -17.23 11.22 -18.8 C 12.33 -22.99 15.77 -25.76 20.63 -26.4 C 21.07 -26.45 22.31 -26.47 24.66 -26.45 C 28.37 -26.42 28.73 -26.38 30.13 -25.93 C 32.04 -25.3 33.78 -24 35.11 -22.18 C 35.39 -21.79 39.26 -17.21 43.7 -11.99 C 48.14 -6.78 51.87 -2.39 51.99 -2.23 C 52.12 -2.08 52.36 -1.65 52.54 -1.3 C 52.94 -0.52 53.27 -0.19 53.81 -0.07 C 54.06 -0.02 56.02 0 60.21 -0.02 L 66.24 -0.04 57.07 -11.99 C 52.03 -18.57 47.84 -24.05 47.77 -24.17 C 47.19 -25.12 47.36 -26.45 48.17 -27.32 C 48.56 -27.74 48.89 -27.92 49.85 -28.24 C 54.44 -29.74 58.96 -32.63 62.25 -36.17 C 68.26 -42.64 70.23 -50.91 67.61 -58.77 C 64.87 -67.05 57.7 -73.72 49.61 -75.53 C 47.51 -75.99 49.86 -75.95 23.69 -75.98 L 0.01 -76 0.01 -75.54 Z\";\n\nconst LOGO_EMOCN = [\n  // e\n  \"M105.2 1.5L105.2 1.5Q97.1 1.5 91 -2Q85 -5.6 81.6 -11.9Q78.2 -18.2 78.2 -26.6L78.2 -26.6Q78.2 -35.4 81.5 -41.9Q84.9 -48.4 90.8 -52Q96.8 -55.5 104.7 -55.5L104.7 -55.5Q112.9 -55.5 118.7 -51.7Q124.5 -47.9 127.4 -40.8Q130.3 -33.8 129.7 -24.1L129.7 -24.1L119.2 -24.1L119.2 -27.9Q119.1 -37.3 115.6 -41.8Q112.2 -46.3 105.1 -46.3L105.1 -46.3Q97.2 -46.3 93.3 -41.3Q89.3 -36.4 89.3 -27L89.3 -27Q89.3 -18.1 93.3 -13.2Q97.2 -8.3 104.7 -8.3L104.7 -8.3Q109.6 -8.3 113.1 -10.6Q116.7 -12.8 118.7 -16.9L118.7 -16.9L128.9 -13.7Q125.8 -6.5 119.4 -2.5Q113 1.5 105.2 1.5ZM124.5 -24.1L85.9 -24.1L85.9 -32.2L124.5 -32.2L124.5 -24.1Z\",\n  // m\n  \"M212 0L201.6 0L201.6 -33.6Q201.6 -39.5 198.6 -42.8Q195.6 -46.1 190.7 -46.1L190.7 -46.1Q187.7 -46.1 185.2 -44.7Q182.8 -43.3 181.2 -40.6Q179.7 -37.9 179.7 -33.8L179.7 -33.8L174.7 -36.3Q174.6 -42 177.1 -46.3Q179.6 -50.6 183.9 -53Q188.3 -55.4 193.7 -55.4L193.7 -55.4Q202.4 -55.4 207.3 -50.1Q212.1 -44.9 212.1 -36.1L212.1 -36.1L212 0ZM147.3 0L136.8 0L136.8 -54L146.1 -54L146.1 -38.4L147.3 -38.4L147.3 0ZM179.7 0L169.2 0L169.3 -33.5Q169.3 -39.4 166.3 -42.7Q163.3 -46.1 158.3 -46.1L158.3 -46.1Q153.3 -46.1 150.3 -42.7Q147.3 -39.3 147.3 -33.8L147.3 -33.8L142.3 -37Q142.3 -42.3 144.8 -46.4Q147.4 -50.6 151.8 -53Q156.1 -55.4 161.6 -55.4L161.6 -55.4Q167.3 -55.4 171.4 -52.9Q175.4 -50.5 177.6 -46.2Q179.7 -41.8 179.7 -36.1L179.7 -36.1L179.7 0Z\",\n  // o\n  \"M245.3 1.5L245.3 1.5Q237.2 1.5 231.3 -2.1Q225.3 -5.8 222.1 -12.2Q218.9 -18.7 218.9 -27.1L218.9 -27.1Q218.9 -35.5 222.2 -41.9Q225.5 -48.4 231.4 -51.9Q237.4 -55.5 245.3 -55.5L245.3 -55.5Q253.4 -55.5 259.4 -51.9Q265.3 -48.2 268.6 -41.8Q271.8 -35.4 271.8 -27.1L271.8 -27.1Q271.8 -18.6 268.6 -12.2Q265.3 -5.8 259.3 -2.1Q253.4 1.5 245.3 1.5ZM245.3 -8.3L245.3 -8.3Q253.1 -8.3 256.9 -13.6Q260.8 -18.8 260.8 -27.1L260.8 -27.1Q260.8 -35.5 256.9 -40.6Q253 -45.7 245.3 -45.7L245.3 -45.7Q240.1 -45.7 236.7 -43.3Q233.3 -40.9 231.6 -36.7Q230 -32.6 230 -27.1L230 -27.1Q230 -18.6 233.9 -13.5Q237.8 -8.3 245.3 -8.3Z\",\n  // c\n  \"M303.4 1.5L303.4 1.5Q295.1 1.5 289.3 -2.2Q283.5 -5.9 280.5 -12.4Q277.4 -18.8 277.3 -27L277.3 -27Q277.4 -35.4 280.5 -41.8Q283.7 -48.2 289.5 -51.9Q295.4 -55.5 303.6 -55.5L303.6 -55.5Q312.4 -55.5 318.7 -51.1Q325 -46.7 327 -39.1L327 -39.1L316.6 -36.1Q315 -40.6 311.5 -43.1Q308 -45.7 303.4 -45.7L303.4 -45.7Q298.3 -45.7 295 -43.2Q291.7 -40.8 290.1 -36.6Q288.5 -32.4 288.4 -27L288.4 -27Q288.5 -18.7 292.3 -13.5Q296 -8.3 303.4 -8.3L303.4 -8.3Q308.5 -8.3 311.6 -10.7Q314.8 -13 316.4 -17.4L316.4 -17.4L327 -14.9Q324.3 -7 318.3 -2.7Q312.1 1.5 303.4 1.5Z\",\n  // n\n  \"M383.2 0L372.6 0L372.6 -26.6Q372.6 -29.7 372.1 -33Q371.6 -36.4 370.1 -39.2Q368.6 -42.1 365.9 -43.8Q363.3 -45.6 358.9 -45.6L358.9 -45.6Q356.1 -45.6 353.6 -44.6Q351.1 -43.7 349.3 -41.7Q347.4 -39.6 346.3 -36.3Q345.3 -32.9 345.3 -28.1L345.3 -28.1L338.8 -30.6Q338.8 -37.9 341.5 -43.5Q344.3 -49.2 349.4 -52.3Q354.6 -55.5 361.8 -55.5L361.8 -55.5Q367.4 -55.5 371.3 -53.7Q375.1 -51.9 377.4 -48.9Q379.8 -46 381.1 -42.6Q382.3 -39.1 382.8 -35.8Q383.2 -32.5 383.2 -30L383.2 -30L383.2 0ZM345.3 0L334.6 0L334.6 -54L344 -54L344 -38.4L345.3 -38.4L345.3 0Z\",\n];\n\nconst WORDMARK: DotShapePart[] = [\n  { d: LOGO_R, accent: true },\n  ...LOGO_EMOCN.map((d) => ({ d, fillRule: \"nonzero\" as const })),\n];\n\nconst DEFAULT_SHAPES: DotShape[] = [\n  ICON_MOTION,\n  ICON_TRANSITIONS,\n  ICON_CAPTIONS,\n  WORDMARK,\n];\nconst DEFAULT_LABELS = [\"Animations\", \"Transitions\", \"Captions\", \"\"];\n\n// ── Timing ──────────────────────────────────────────────────────────────────\n\nconst FIELD = 14;\nconst MORPH = 30;\nconst HOLD = 22;\nconst LAST_MORPH = 36;\n/** Per-dot flight; the rest of the morph window is stagger. */\nconst FLIGHT = 0.62;\n\nconst INOUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst OUT = Easing.bezier(0.22, 1, 0.36, 1);\n\nfunction morphStarts(shapeCount: number): number[] {\n  const starts: number[] = [];\n  let t = FIELD;\n  for (let i = 0; i < shapeCount; i++) {\n    starts.push(t);\n    t += (i === shapeCount - 1 ? LAST_MORPH : MORPH) + HOLD;\n  }\n  return starts;\n}\n\nexport const dotFieldMorphLength = (shapeCount = DEFAULT_SHAPES.length) =>\n  morphStarts(shapeCount)[shapeCount - 1] + LAST_MORPH;\n\n// ── Deterministic noise ─────────────────────────────────────────────────────\n\nfunction hash(n: number): number {\n  const s = Math.sin(n * 127.1 + 311.7) * 43758.5453;\n  return s - Math.floor(s);\n}\n\nfunction valueNoise(x: number, y: number): number {\n  const xi = Math.floor(x);\n  const yi = Math.floor(y);\n  const xf = x - xi;\n  const yf = y - yi;\n  const h = (a: number, b: number) => hash(a * 57.3 + b * 131.9);\n  const u = xf * xf * (3 - 2 * xf);\n  const v = yf * yf * (3 - 2 * yf);\n  const top = h(xi, yi) * (1 - u) + h(xi + 1, yi) * u;\n  const bot = h(xi, yi + 1) * (1 - u) + h(xi + 1, yi + 1) * u;\n  return top * (1 - v) + bot * v;\n}\n\n// ── Shape sampling ──────────────────────────────────────────────────────────\n\ninterface Pt {\n  x: number;\n  y: number;\n  /** 0–1 brightness, encoded as dot size. */\n  b: number;\n  accent: boolean;\n}\n\ninterface FlatPart {\n  polys: [number, number][][];\n  stroke?: number;\n  accent: boolean;\n  nonzero: boolean;\n}\n\nfunction normalizeShape(shape: DotShape): DotShapePart[] {\n  if (typeof shape === \"string\") return [{ d: shape }];\n  return Array.isArray(shape) ? shape : [shape];\n}\n\nfunction flatten(part: DotShapePart): FlatPart {\n  const polys: [number, number][][] = [];\n  for (const sub of getSubpaths(part.d)) {\n    const len = getLength(sub);\n    if (len <= 0) continue;\n    const n = Math.max(8, Math.min(400, Math.ceil(len / 1.2)));\n    const poly: [number, number][] = [];\n    for (let i = 0; i <= n; i++) {\n      const p = getPointAtLength(sub, (len * i) / n);\n      if (p) poly.push([p.x, p.y]);\n    }\n    polys.push(poly);\n  }\n  return {\n    polys,\n    stroke: part.stroke,\n    accent: Boolean(part.accent),\n    nonzero: part.fillRule === \"nonzero\",\n  };\n}\n\nfunction segDist(px: number, py: number, poly: [number, number][]): number {\n  let best = Number.POSITIVE_INFINITY;\n  for (let i = 0; i < poly.length - 1; i++) {\n    const [ax, ay] = poly[i];\n    const [bx, by] = poly[i + 1];\n    const dx = bx - ax;\n    const dy = by - ay;\n    const l2 = dx * dx + dy * dy || 1;\n    const t = Math.max(0, Math.min(1, ((px - ax) * dx + (py - ay) * dy) / l2));\n    const ex = ax + dx * t - px;\n    const ey = ay + dy * t - py;\n    const d = ex * ex + ey * ey;\n    if (d < best) best = d;\n  }\n  return Math.sqrt(best);\n}\n\nfunction insideNonzero(px: number, py: number, polys: [number, number][][]) {\n  let wind = 0;\n  for (const poly of polys) {\n    for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {\n      const [xi, yi] = poly[i];\n      const [xj, yj] = poly[j];\n      if (yi > py === yj > py) continue;\n      const xc = ((xj - xi) * (py - yi)) / (yj - yi) + xi;\n      if (px < xc) wind += yj > yi ? 1 : -1;\n    }\n  }\n  return wind !== 0;\n}\n\nfunction insideEvenOdd(px: number, py: number, polys: [number, number][][]) {\n  let inside = false;\n  for (const poly of polys) {\n    for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {\n      const [xi, yi] = poly[i];\n      const [xj, yj] = poly[j];\n      if (\n        yi > py !== yj > py &&\n        px < ((xj - xi) * (py - yi)) / (yj - yi) + xi\n      ) {\n        inside = !inside;\n      }\n    }\n  }\n  return inside;\n}\n\n/** Returns brightness 0–1 if (x, y) is inside the part, else -1. */\nfunction probe(part: FlatPart, x: number, y: number): number {\n  if (part.stroke) {\n    const hw = part.stroke / 2;\n    let d = Number.POSITIVE_INFINITY;\n    for (const poly of part.polys) d = Math.min(d, segDist(x, y, poly));\n    if (d > hw) return -1;\n    // Tube shading: bright along the centre-line, falling off to the edges.\n    return 1 - (d / hw) ** 2 * 0.55;\n  }\n  const inside = part.nonzero\n    ? insideNonzero(x, y, part.polys)\n    : insideEvenOdd(x, y, part.polys);\n  if (!inside) return -1;\n  let d = Number.POSITIVE_INFINITY;\n  for (const poly of part.polys) d = Math.min(d, segDist(x, y, poly));\n  // Rim light on filled shapes: edges catch more light than the interior.\n  return 0.7 + 0.3 * Math.max(0, 1 - d / 4);\n}\n\nfunction sampleShape(\n  shape: DotShape,\n  count: number,\n  box: { cx: number; cy: number; w: number; h: number },\n): Pt[] {\n  const parts = normalizeShape(shape).map(flatten);\n  let minX = Number.POSITIVE_INFINITY;\n  let minY = Number.POSITIVE_INFINITY;\n  let maxX = Number.NEGATIVE_INFINITY;\n  let maxY = Number.NEGATIVE_INFINITY;\n  for (const part of parts) {\n    const pad = (part.stroke ?? 0) / 2;\n    for (const poly of part.polys) {\n      for (const [x, y] of poly) {\n        minX = Math.min(minX, x - pad);\n        minY = Math.min(minY, y - pad);\n        maxX = Math.max(maxX, x + pad);\n        maxY = Math.max(maxY, y + pad);\n      }\n    }\n  }\n  const bw = maxX - minX || 1;\n  const bh = maxY - minY || 1;\n  const scale = Math.min(box.w / bw, box.h / bh);\n\n  const test = (\n    x: number,\n    y: number,\n  ): { b: number; accent: boolean } | null => {\n    let best = -1;\n    let accent = false;\n    for (const part of parts) {\n      const b = probe(part, x, y);\n      if (b > best) {\n        best = b;\n        accent = part.accent;\n      }\n    }\n    return best < 0 ? null : { b: best, accent };\n  };\n\n  // Estimate filled area, then pick a hex-grid spacing that yields ~count dots.\n  const coarse = 70;\n  let hits = 0;\n  for (let i = 0; i < coarse; i++) {\n    for (let j = 0; j < coarse; j++) {\n      if (\n        test(minX + ((i + 0.5) / coarse) * bw, minY + ((j + 0.5) / coarse) * bh)\n      )\n        hits++;\n    }\n  }\n  const area = Math.max(1, (hits / (coarse * coarse)) * bw * bh);\n  let spacing = Math.sqrt(area / (count * 0.866));\n  let pts: Pt[] = [];\n  for (let attempt = 0; attempt < 4; attempt++) {\n    pts = [];\n    const rowH = spacing * 0.866;\n    let row = 0;\n    for (let y = minY + rowH / 2; y < maxY; y += rowH, row++) {\n      const off = row % 2 ? spacing / 2 : 0;\n      for (let x = minX + off + spacing / 2; x < maxX; x += spacing) {\n        const k = pts.length + row * 7919;\n        const jx = x + (hash(k * 1.7) - 0.5) * spacing * 0.35;\n        const jy = y + (hash(k * 2.3) - 0.5) * spacing * 0.35;\n        const hit = test(jx, jy);\n        if (hit) pts.push({ x: jx, y: jy, b: hit.b, accent: hit.accent });\n      }\n    }\n    if (pts.length >= count && pts.length < count * 1.2) break;\n    spacing *= Math.sqrt(pts.length / count) * (pts.length < count ? 0.98 : 1);\n  }\n  // Exactly `count` dots: thin evenly, or double up with a small offset.\n  const out: Pt[] = [];\n  for (let i = 0; i < count; i++) {\n    const src = pts[Math.floor((i * pts.length) / count)] ?? pts[0];\n    out.push(src);\n  }\n  const ox = box.cx - (minX + bw / 2) * scale;\n  const oy = box.cy - (minY + bh / 2) * scale;\n  // Key light from the upper left.\n  return out.map((p, i) => {\n    const nx = (p.x - minX) / bw;\n    const ny = (p.y - minY) / bh;\n    const light = 0.66 + 0.34 * (1 - (nx * 0.6 + ny * 0.4));\n    const dup = i > 0 && out[i - 1] === p ? 1 : 0;\n    return {\n      x: p.x * scale + ox + dup * spacing * scale * 0.3,\n      y: p.y * scale + oy + dup * spacing * scale * 0.3,\n      b: Math.min(1, p.b * light),\n      accent: p.accent,\n    };\n  });\n}\n\nfunction scatter(count: number, W: number, H: number): Pt[] {\n  const cols = Math.round(Math.sqrt((count * W) / H));\n  const rows = Math.ceil(count / cols);\n  const pts: Pt[] = [];\n  for (let i = 0; i < count; i++) {\n    const c = i % cols;\n    const r = Math.floor(i / cols);\n    const x = ((c + 0.15 + hash(i * 3.1) * 0.7) / cols) * W * 1.08 - W * 0.04;\n    const y = ((r + 0.15 + hash(i * 5.7) * 0.7) / rows) * H * 1.08 - H * 0.04;\n    const b = valueNoise(x / (W * 0.12), y / (H * 0.18)) ** 1.6;\n    pts.push({ x, y, b: 0.12 + b * 0.75, accent: false });\n  }\n  return pts;\n}\n\nfunction hilbert(x: number, y: number, order = 128): number {\n  let d = 0;\n  let px = x;\n  let py = y;\n  for (let s = order / 2; s >= 1; s = Math.floor(s / 2)) {\n    const rx = (px & s) > 0 ? 1 : 0;\n    const ry = (py & s) > 0 ? 1 : 0;\n    d += s * s * ((3 * rx) ^ ry);\n    if (ry === 0) {\n      if (rx === 1) {\n        px = s - 1 - px;\n        py = s - 1 - py;\n      }\n      const t = px;\n      px = py;\n      py = t;\n    }\n  }\n  return d;\n}\n\n/**\n * Order points along a Hilbert curve over their own bounds, so dot i sits in\n * the same region of every shape: morphs read as one form reshaping, not a\n * swap.\n */\nfunction bySpace(pts: Pt[]): Pt[] {\n  let minX = Number.POSITIVE_INFINITY;\n  let minY = Number.POSITIVE_INFINITY;\n  let maxX = Number.NEGATIVE_INFINITY;\n  let maxY = Number.NEGATIVE_INFINITY;\n  for (const p of pts) {\n    minX = Math.min(minX, p.x);\n    minY = Math.min(minY, p.y);\n    maxX = Math.max(maxX, p.x);\n    maxY = Math.max(maxY, p.y);\n  }\n  const span = Math.max(maxX - minX, maxY - minY) || 1;\n  const ox = minX - (span - (maxX - minX)) / 2;\n  const oy = minY - (span - (maxY - minY)) / 2;\n  return pts\n    .map((p) => ({\n      p,\n      h: hilbert(\n        Math.min(127, Math.floor(((p.x - ox) / span) * 128)),\n        Math.min(127, Math.floor(((p.y - oy) / span) * 128)),\n      ),\n    }))\n    .sort((m, n) => m.h - n.h)\n    .map((m) => m.p);\n}\n\n// ── Component ───────────────────────────────────────────────────────────────\n\nexport function DotFieldMorph({\n  shapes = DEFAULT_SHAPES,\n  labels = DEFAULT_LABELS,\n  count = 2000,\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: DotFieldMorphProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const isLight = theme === \"light\";\n  const bg = isLight ? \"#F5F4F0\" : \"#0A0A0B\";\n  const ink = isLight ? \"#141416\" : \"#EEEEF0\";\n  const n = Math.max(200, Math.round(count));\n  const list = shapes.length ? shapes : DEFAULT_SHAPES;\n\n  const states = useMemo(() => {\n    const out: Pt[][] = [bySpace(scatter(n, W, H))];\n    list.forEach((shape, i) => {\n      const last = i === list.length - 1;\n      const box = last\n        ? { cx: W / 2, cy: H * 0.5, w: W * 0.64, h: H * 0.3 }\n        : { cx: W / 2, cy: H * 0.45, w: H * 0.56, h: H * 0.5 };\n      out.push(bySpace(sampleShape(shape, n, box)));\n    });\n    return out;\n  }, [list, n, W, H]);\n\n  const starts = morphStarts(list.length);\n  // Which transition we are in (0 = still the field).\n  let k = 0;\n  for (let i = 0; i < starts.length; i++) if (frame >= starts[i]) k = i + 1;\n  const from = states[k - 1] ?? states[0];\n  const to = states[k] ?? states[0];\n  const winLen = k === list.length ? LAST_MORPH : MORPH;\n  const local = k === 0 ? 0 : (frame - starts[k - 1]) / winLen;\n\n  const unit = Math.min(W, H) / 720;\n  // Dark dots on a light stage read thinner, so they get a touch more size.\n  const rMax = (isLight ? 2.05 : 1.85) * unit * Math.sqrt(2000 / n);\n  const cx = W / 2;\n  const cy = H * 0.47;\n  const maxD = Math.hypot(W, H) / 2;\n\n  // Paths bucketed by brightness and colour: a handful of <path>s, not 2,000 nodes.\n  const BUCKETS = 5;\n  const neutral: string[][] = Array.from({ length: BUCKETS }, () => []);\n  const accented: string[][] = Array.from({ length: BUCKETS }, () => []);\n\n  // The highlight that sweeps across a settled shape during each hold.\n  const holdT = k === 0 ? -1 : (frame - starts[k - 1] - winLen) / HOLD;\n\n  for (let i = 0; i < n; i++) {\n    const a = from[i];\n    const b = to[i];\n    let x: number;\n    let y: number;\n    let bright: number;\n    let acc: boolean;\n    if (k === 0) {\n      x = a.x + Math.sin(frame * 0.03 + i) * 1.5 - frame * 0.4;\n      y = a.y + Math.cos(frame * 0.025 + i * 1.3) * 1.5;\n      bright = a.b;\n      acc = false;\n    } else {\n      // Stagger by distance: dots nearest the centre leave first.\n      const d = Math.hypot(a.x - cx, a.y - cy) / maxD;\n      const delay = Math.min(1, d * 0.75 + hash(i * 9.1) * 0.25) * (1 - FLIGHT);\n      const t = Math.max(0, Math.min(1, (local - delay) / FLIGHT));\n      const e = INOUT(t);\n      const dx = b.x - a.x;\n      const dy = b.y - a.y;\n      // Curved flight: a consistent swirl, a little varied per dot.\n      const curl = (0.16 + hash(i * 4.3) * 0.12) * Math.sin(Math.PI * e);\n      x = a.x + dx * e - dy * curl;\n      y = a.y + dy * e + dx * curl;\n      bright = a.b + (b.b - a.b) * e;\n      acc = e > 0.5 ? b.accent : a.accent;\n      if (k === 1) x -= (FIELD + 0) * 0.4 * (1 - e);\n    }\n    // Idle shimmer + a soft diagonal sweep once a shape has settled.\n    bright *= 0.9 + 0.1 * Math.sin(frame * 0.18 + hash(i * 1.9) * 6.28);\n    if (holdT > -0.2 && holdT < 1.4) {\n      const diag = (x / W) * 0.7 + (y / H) * 0.3;\n      bright += 0.3 * Math.exp(-(((diag - (holdT * 1.2 - 0.1)) / 0.08) ** 2));\n    }\n    bright = Math.max(0, Math.min(1, bright));\n    const r = rMax * (0.28 + 0.72 * bright);\n    const bucket = Math.min(BUCKETS - 1, Math.floor(bright * BUCKETS));\n    const seg = `M${(x - r).toFixed(1)} ${y.toFixed(1)}a${r.toFixed(2)} ${r.toFixed(2)} 0 1 0 ${(2 * r).toFixed(2)} 0a${r.toFixed(2)} ${r.toFixed(2)} 0 1 0 ${(-2 * r).toFixed(2)} 0`;\n    (acc ? accented : neutral)[bucket].push(seg);\n  }\n\n  // Slow push-in over the whole shot.\n  const end = dotFieldMorphLength(list.length);\n  const push = interpolate(frame, [0, end + 40], [1, 1.06], {\n    easing: INOUT,\n    extrapolateRight: \"clamp\",\n  });\n\n  // Caption under each settled shape.\n  const label = k > 0 ? (labels[k - 1] ?? \"\") : \"\";\n  const labelIn = interpolate(local, [0.72, 1.05], [0, 1], {\n    easing: OUT,\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n  const nextStart = starts[k] ?? 1e6;\n  const labelOut = interpolate(frame, [nextStart, nextStart + 8], [1, 0], {\n    extrapolateLeft: \"clamp\",\n    extrapolateRight: \"clamp\",\n  });\n  const labelOp = labelIn * labelOut;\n\n  // gradients.sh \"mesh\" palette: bg #0a0d24, [#ecdcf2, #8796ee, #2e45b7, #0e1645].\n  // It lives in the dots (a user-space gradient across the frame) and as a faint\n  // navy pool in the ground. It drifts a few percent over the shot, never more.\n  const drift = interpolate(frame, [0, end + 40], [0, 1], {\n    extrapolateRight: \"clamp\",\n  });\n  const gx = W * (0.08 + drift * 0.06);\n  const gy = H * (0.04 - drift * 0.04);\n  const fieldStops = isLight\n    ? [\"#0B0B10\", \"#0e1645\", \"#1f3398\", \"#2e45b7\"]\n    : [\"#FBF7FD\", \"#ecdcf2\", \"#aeb6f3\", \"#8796ee\"];\n  const markStops = isLight\n    ? [\"#2e45b7\", accent, \"#6f86ff\"]\n    : [\"#c9d0ff\", \"#8796ee\", accent];\n  const ground = isLight\n    ? `radial-gradient(70% 55% at ${46 + drift * 8}% 58%, rgba(236,220,242,0.55) 0%, rgba(236,220,242,0) 72%), radial-gradient(90% 80% at 50% 40%, #FBFAF7 0%, ${bg} 70%)`\n    : `radial-gradient(55% 60% at ${62 - drift * 8}% 92%, rgba(46,69,183,0.16) 0%, rgba(46,69,183,0) 70%), radial-gradient(80% 75% at 50% 44%, #0d1130 0%, ${bg} 72%)`;\n\n  return (\n    <AbsoluteFill style={{ background: ground, overflow: \"hidden\" }}>\n      <svg\n        width={W}\n        height={H}\n        viewBox={`0 0 ${W} ${H}`}\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          transform: `scale(${push})`,\n          transformOrigin: `${cx}px ${cy}px`,\n        }}\n        aria-hidden\n      >\n        <defs>\n          <linearGradient\n            id={`${uid}-field`}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={gx}\n            y1={gy}\n            x2={W - gx * 0.5}\n            y2={H - gy}\n          >\n            {fieldStops.map((c, i) => (\n              <stop\n                key={c + String(i)}\n                offset={i / (fieldStops.length - 1)}\n                stopColor={c}\n              />\n            ))}\n          </linearGradient>\n          <linearGradient\n            id={`${uid}-mark`}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={0}\n            y1={H * 0.36}\n            x2={0}\n            y2={H * 0.64}\n          >\n            {markStops.map((c, i) => (\n              <stop\n                key={c + String(i)}\n                offset={i / (markStops.length - 1)}\n                stopColor={c}\n              />\n            ))}\n          </linearGradient>\n        </defs>\n        {neutral.map((segs, i) =>\n          segs.length ? (\n            <path\n              key={`n${i}`}\n              d={segs.join(\"\")}\n              fill={`url(#${uid}-field)`}\n              opacity={0.28 + (i / (BUCKETS - 1)) * 0.72}\n            />\n          ) : null,\n        )}\n        {accented.map((segs, i) =>\n          segs.length ? (\n            <path\n              key={`a${i}`}\n              d={segs.join(\"\")}\n              fill={`url(#${uid}-mark)`}\n              opacity={0.6 + (i / (BUCKETS - 1)) * 0.4}\n            />\n          ) : null,\n        )}\n      </svg>\n      {label ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            right: 0,\n            top: H * 0.79,\n            display: \"flex\",\n            justifyContent: \"center\",\n            alignItems: \"baseline\",\n            gap: H * 0.018,\n            fontFamily: MANROPE,\n            color: ink,\n            opacity: labelOp,\n            transform: `translateY(${(1 - labelIn) * H * 0.012}px)`,\n            filter: `blur(${(1 - labelOp) * 4}px)`,\n          }}\n        >\n          <span\n            style={{\n              fontWeight: 500,\n              fontSize: H * 0.022,\n              letterSpacing: \"0.04em\",\n              fontVariantNumeric: \"tabular-nums\",\n              color: isLight ? \"#2e45b7\" : \"#8796ee\",\n            }}\n          >\n            {String(k).padStart(2, \"0\")}\n          </span>\n          <span\n            style={{\n              fontWeight: 400,\n              fontSize: H * 0.042,\n              letterSpacing: \"-0.025em\",\n              opacity: 0.92,\n            }}\n          >\n            {label}\n          </span>\n        </div>\n      ) : null}\n      <svg\n        width={W}\n        height={H}\n        style={{ position: \"absolute\", inset: 0, pointerEvents: \"none\" }}\n        aria-hidden\n      >\n        <filter id={`${uid}-grain`}>\n          <feTurbulence\n            type=\"fractalNoise\"\n            baseFrequency={0.85}\n            numOctaves={2}\n            seed={3}\n          />\n          <feColorMatrix\n            type=\"matrix\"\n            values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 1 0\"\n          />\n        </filter>\n        <rect\n          width={W}\n          height={H}\n          filter={`url(#${uid}-grain)`}\n          opacity={isLight ? 0.05 : 0.06}\n          style={{ mixBlendMode: isLight ? \"multiply\" : \"screen\" }}\n        />\n      </svg>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/dot-field-morph.tsx"
    }
  ],
  "type": "registry:component"
}
