{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "week-shipped",
  "title": "Week Shipped",
  "description": "A week-recap line, \"Sunday, we rested.\", in heavy type on orange.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/week-shipped/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Unbounded\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst unbounded = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface WeekShippedEntry {\n  day: string;\n  item: string;\n}\n\nexport interface WeekShippedProps {\n  entries?: WeekShippedEntry[];\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_ENTRIES: WeekShippedEntry[] = [\n  { day: \"Monday,\", item: \"captions that keep up.\" },\n  { day: \"Tuesday,\", item: \"shaders you can scrub.\" },\n  { day: \"Wednesday,\", item: \"icons that draw themselves.\" },\n  { day: \"Thursday,\", item: \"vertical, from the same file.\" },\n  { day: \"Friday,\", item: \"renders on your own server.\" },\n  { day: \"Saturday,\", item: \"one tiny fix.\" },\n  { day: \"Sunday,\", item: \"we rested.\" },\n];\n\nconst FONT_PX = 200;\nconst TRACK = -0.03;\nconst DAY_SCALE = 0.42;\n\nconst EASE_ROLL = Easing.bezier(0.6, 0, 0.1, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst FIRST = 24;\nconst BEAT = 13;\nconst BREATH = 26;\nconst ROLL = 7;\nconst LAST_ROLL = 13;\nconst STAGGER = 1;\nconst HOLD_MIN = 36;\n\ninterface Metrics {\n  days: number[];\n  words: number[][];\n  itemWords: string[][];\n  space: number;\n  asc: number;\n  desc: number;\n  tall: number;\n  deep: number;\n}\n\nfunction measure(entries: WeekShippedEntry[]): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"week-shipped: no 2d context\");\n  const em = (s: string, w: number) => {\n    ctx.font = `${w} ${FONT_PX}px \"${unbounded.fontFamily}\"`;\n    return (\n      ctx.measureText(s).width / FONT_PX +\n      TRACK * Math.max(0, Array.from(s).length - 1)\n    );\n  };\n  const itemWords = entries.map((e) => e.item.trim().split(/\\s+/));\n  ctx.font = `500 ${FONT_PX}px \"${unbounded.fontFamily}\"`;\n  const fm = ctx.measureText(\"Hgy\");\n  return {\n    days: entries.map((e) => em(e.day, 400)),\n    words: itemWords.map((ws) => ws.map((w) => em(w, 500))),\n    itemWords,\n    space: em(\" \", 500) - TRACK,\n    asc: fm.fontBoundingBoxAscent / FONT_PX,\n    desc: fm.fontBoundingBoxDescent / FONT_PX,\n    tall: ctx.measureText(\"dlkhfH\").actualBoundingBoxAscent / FONT_PX,\n    deep: ctx.measureText(\"gjpqy,\").actualBoundingBoxDescent / FONT_PX,\n  };\n}\n\nfunction useMetrics(entries: WeekShippedEntry[]) {\n  const key = entries.map((e) => `${e.day}\\u0001${e.item}`).join(\"\\u0002\");\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"week-shipped: measuring\"));\n  const released = useRef(false);\n  const input = useRef(entries);\n  input.current = entries;\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      unbounded.waitUntilDone(),\n      document.fonts.load(`500 100px \"${unbounded.fontFamily}\"`),\n      document.fonts.load(`400 100px \"${unbounded.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measure(input.current) });\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [key, handle]);\n  return state && state.key === key ? state.m : null;\n}\n\nfunction wrap(words: string[], widths: number[], space: number, max: number) {\n  const run = (limit: number) => {\n    const lines: string[][] = [];\n    let line: string[] = [];\n    let w = 0;\n    words.forEach((word, i) => {\n      const add = line.length === 0 ? widths[i] : w + space + widths[i];\n      if (line.length > 0 && add > limit) {\n        lines.push(line);\n        line = [word];\n        w = widths[i];\n      } else {\n        line.push(word);\n        w = add;\n      }\n    });\n    if (line.length) lines.push(line);\n    return lines;\n  };\n  const first = run(max);\n  let best = first;\n  for (let k = 1; k <= 20; k++) {\n    const next = run(max * (1 - k * 0.025));\n    if (next.length !== first.length) break;\n    best = next;\n  }\n  return best.map((l) => l.join(\" \"));\n}\n\nexport function WeekShipped({\n  entries = DEFAULT_ENTRIES,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: WeekShippedProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const dark = theme === \"dark\";\n  const field = dark ? (accent ?? \"#FF5A1F\") : \"#FFFFFF\";\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? field);\n  const ink = \"#000000\";\n  const dayInk = dark ? \"#000000\" : (accent ?? \"#E8480F\");\n\n  const list = entries.length > 0 ? entries : DEFAULT_ENTRIES;\n  const m = useMetrics(list);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const n = list.length;\n  const total = durationInFrames * speed;\n  const natural = Array.from({ length: n - 1 }, (_, k) =>\n    k === 0 ? FIRST : k === n - 2 && n > 2 ? BREATH : BEAT,\n  );\n  const sum = natural.reduce((s, d) => s + d, 0);\n  const fit = sum > 0 ? Math.min(1, (total - HOLD_MIN - LAST_ROLL) / sum) : 1;\n  const starts: number[] = [0];\n  for (let k = 0; k < n - 1; k++)\n    starts.push(starts[k] + Math.max(8, Math.round(natural[k] * fit)));\n\n  const portrait = H > W * 1.1;\n  const marginX = W * (portrait ? 0.09 : 0.075);\n  const maxW = W - marginX * 2;\n  const lead = Math.max(1.04, m.tall + m.deep + 0.1);\n  const longest = Math.max(\n    ...m.words.map(\n      (ws) => ws.reduce((s, w) => s + w, 0) + m.space * (ws.length - 1),\n    ),\n  );\n  const widestWord = Math.max(...m.words.flat());\n  const F = Math.min(\n    portrait ? W * 0.11 : H * 0.17,\n    maxW / Math.max(widestWord, 0.1),\n    (maxW * 3) / Math.max(longest * 1.15, 0.1),\n  );\n  const Fd = F * DAY_SCALE;\n  const wrapped = list.map((_, k) =>\n    wrap(m.itemWords[k], m.words[k], m.space, maxW / F),\n  );\n  const lineH = lead * F;\n  const dayGap = F * 0.3;\n  const layoutOf = (k: number) => {\n    const rows = wrapped[k].length;\n    const dayBox = Fd * (m.tall + m.deep);\n    const blockH = dayBox + dayGap + F * (m.tall + m.deep) + (rows - 1) * lineH;\n    const top = H / 2 - blockH / 2;\n    return {\n      dayBase: top + Fd * m.tall,\n      itemBase: top + dayBox + dayGap + F * m.tall,\n    };\n  };\n\n  let cur = 0;\n  for (let k = 0; k < n; k++) if (t >= starts[k]) cur = k;\n  const last = cur === n - 1 && n > 1;\n  const roll = last ? LAST_ROLL : ROLL;\n  const s0 = starts[cur];\n\n  const outP =\n    cur === 0\n      ? 1\n      : interpolate(t, [s0, s0 + roll * 0.5], [0, 1], {\n          ...CLAMP,\n          easing: Easing.bezier(0.55, 0, 1, 0.45),\n        });\n  const inP = (order: number) =>\n    cur === 0\n      ? interpolate(t, [order * STAGGER - 3, order * STAGGER + 11], [0, 1], {\n          ...CLAMP,\n          easing: EASE_OUT,\n        })\n      : interpolate(t, [s0 + roll * 0.35 + order, s0 + roll + order], [0, 1], {\n          ...CLAMP,\n          easing: last ? EASE_OUT : EASE_ROLL,\n        });\n\n  const line = (\n    key: string,\n    text: string,\n    base: number,\n    size: number,\n    weight: number,\n    color: string,\n    shift: number,\n  ) => {\n    const winTop = base - size * (m.tall + 0.05);\n    const winH = size * (m.tall + m.deep + 0.1);\n    const lineBox = size * (m.asc + m.desc);\n    return (\n      <div\n        key={key}\n        style={{\n          position: \"absolute\",\n          left: marginX,\n          right: 0,\n          top: winTop,\n          height: winH,\n          overflow: \"hidden\",\n        }}\n      >\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            top: base - size * m.asc - winTop + shift * winH * 1.04,\n            height: lineBox,\n            lineHeight: `${lineBox}px`,\n            fontFamily: unbounded.fontFamily,\n            fontWeight: weight,\n            fontSize: size,\n            letterSpacing: `${TRACK}em`,\n            whiteSpace: \"pre\",\n            color,\n          }}\n        >\n          {text}\n        </div>\n      </div>\n    );\n  };\n\n  const entryNodes = (\n    k: number,\n    shiftOf: (order: number) => number,\n    tag: string,\n  ) => {\n    const L = layoutOf(k);\n    const out: React.ReactNode[] = [];\n    const d = shiftOf(0);\n    if (Math.abs(d) < 1) {\n      out.push(line(`${tag}d`, list[k].day, L.dayBase, Fd, 400, dayInk, d));\n    }\n    wrapped[k].forEach((tx, i) => {\n      const sh = shiftOf(i + 1);\n      if (Math.abs(sh) < 1) {\n        out.push(\n          line(`${tag}${i}`, tx, L.itemBase + i * lineH, F, 500, ink, sh),\n        );\n      }\n    });\n    return out;\n  };\n\n  const nodes: React.ReactNode[] = [];\n  if (cur > 0 && outP < 1) nodes.push(...entryNodes(cur - 1, () => -outP, \"o\"));\n  nodes.push(...entryNodes(cur, (order) => 1 - inP(order), \"i\"));\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {nodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/week-shipped.tsx"
    }
  ],
  "type": "registry:component"
}
