{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "peek-shut",
  "title": "Peek Shut",
  "description": "\"Want a peek?\" is cut off by a shutter: \"That's all you get. The rest, Monday.\".",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/peek-shut/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/FunnelDisplay\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  Img,\n  interpolate,\n  staticFile,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst funnel = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface PeekShutProps {\n  question?: string;\n  refusal?: string;\n  when?: string;\n  src?: string;\n  focusY?: number;\n  pan?: [number, number];\n  zoom?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_PAN: [number, number] = [0.8, 0.57];\n\nconst THEMES = {\n  dark: {\n    bg: \"#0B0B0F\",\n    ink: \"#FFFFFF\",\n    line: \"rgba(255,255,255,0.32)\",\n    accent: \"#B79CFF\",\n  },\n  light: {\n    bg: \"#FAFAFA\",\n    ink: \"#121216\",\n    line: \"rgba(18,18,22,0.3)\",\n    accent: \"#6B4FD8\",\n  },\n} as const;\n\nconst WGHT = 500;\nconst TRACK = -0.03;\nconst PITCH = 1.06;\nconst MEASURE_PX = 100;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_SNAP = Easing.bezier(0.7, 0, 0.9, 0.4);\nconst EASE_DRIFT = Easing.bezier(0.45, 0, 0.55, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst LINE_LEN = 18;\nconst Q_AT = 6;\nconst STAGGER = 3;\nconst WORD_LEN = 14;\nconst OPEN_AT = 30;\nconst OPEN_LEN = 16;\nconst SHUT_AT = 80;\nconst SHUT_LEN = 6;\nconst R_AT = 90;\nconst WHEN_AT = 102;\nconst MIN_HOLD = 34;\n\nlet measureCtx: CanvasRenderingContext2D | null = null;\n\nfunction em(s: string) {\n  if (!measureCtx) {\n    measureCtx = document.createElement(\"canvas\").getContext(\"2d\");\n  }\n  if (!measureCtx) throw new Error(\"peek-shut: no 2d context\");\n  measureCtx.font = `${WGHT} ${MEASURE_PX}px \"${funnel.fontFamily}\"`;\n  return (\n    measureCtx.measureText(s).width / MEASURE_PX + TRACK * Array.from(s).length\n  );\n}\n\nfunction useFontsReady() {\n  const [ready, setReady] = useState(false);\n  const [handle] = useState(() => delayRender(\"peek-shut: fonts\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      funnel.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${funnel.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (live) setReady(true);\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [handle]);\n  return ready;\n}\n\ninterface Row {\n  words: { text: string; x: number }[];\n  w: number;\n}\n\nfunction split(s: string) {\n  return s.split(/\\s+/).filter(Boolean);\n}\n\nfunction toRow(words: string[]): Row {\n  const space = em(\" \");\n  let x = 0;\n  const out = words.map((text) => {\n    const at = x;\n    x += em(text) + space;\n    return { text, x: at };\n  });\n  return { words: out, w: em(words.join(\" \")) };\n}\n\nfunction greedy(words: string[], maxEm: number): string[][] {\n  const rows: string[][] = [];\n  let cur: string[] = [];\n  for (const w of words) {\n    const next = [...cur, w];\n    if (cur.length > 0 && em(next.join(\" \")) > maxEm) {\n      rows.push(cur);\n      cur = [w];\n    } else {\n      cur = next;\n    }\n  }\n  if (cur.length) rows.push(cur);\n  return rows;\n}\n\nfunction wrap(s: string, maxEm: number): Row[] {\n  const words = split(s);\n  let rows = greedy(words, maxEm);\n  let m = maxEm;\n  for (let guard = 0; guard < 30 && rows.length > 1; guard++) {\n    m *= 0.96;\n    const next = greedy(words, m);\n    if (next.length > rows.length) break;\n    rows = next;\n  }\n  return rows.map(toRow);\n}\n\nfunction buildLayout(\n  question: string,\n  refusal: string,\n  when: string,\n  W: number,\n  H: number,\n) {\n  const portrait = H > W * 1.1;\n  const measure = W * (portrait ? 0.84 : 0.66);\n  const hMax = portrait ? H * 0.05 : H * 0.1;\n  let F = Math.min(W, H) * 0.1;\n  let q: Row[] = [];\n  let r: Row[] = [];\n  let wn: Row[] = [];\n  for (let guard = 0; guard < 16; guard++) {\n    q = wrap(question, measure / F);\n    r = wrap(refusal, measure / F);\n    wn = wrap(when, measure / F);\n    const room = H / 2 - hMax / 2 - F * 0.7 - H * (portrait ? 0.1 : 0.08);\n    const tallest = Math.max(q.length, r.length + wn.length);\n    if (((tallest - 1) * PITCH + 1.1) * F <= room) break;\n    F *= 0.93;\n  }\n  return { q, r, wn, F, hMax, portrait };\n}\n\nexport function PeekShut({\n  question = \"Want a peek?\",\n  refusal = \"That’s all you get.\",\n  when = \"The rest, Monday.\",\n  src,\n  focusY = 0.5,\n  pan = DEFAULT_PAN,\n  zoom = 3.2,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: PeekShutProps) {\n  const frame = useCurrentFrame();\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n  const image = src ?? staticFile(\"hero.png\");\n  const ready = useFontsReady();\n\n  const layout = useMemo(\n    () => (ready ? buildLayout(question, refusal, when, W, H) : null),\n    [ready, question, refusal, when, W, H],\n  );\n\n  if (!layout) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const { F, hMax, portrait } = layout;\n  const lastWords = layout.wn.reduce((a, r) => a + r.words.length, 0);\n  const rCount = layout.r.reduce((a, r) => a + r.words.length, 0);\n  const whenAt = Math.max(WHEN_AT, R_AT + rCount * STAGGER + 4);\n  const motionEnd = whenAt + (lastWords - 1) * STAGGER + WORD_LEN;\n  const room = durationInFrames * speed - MIN_HOLD;\n  const k = Math.max(0.6, Math.min(1, room / motionEnd));\n  const t = (frame * speed) / k;\n\n  const mx = W * (portrait ? 0.08 : 0.065);\n  const cy = H / 2;\n  const slotX = mx;\n  const slotW = portrait ? W - 2 * mx : W * 0.56;\n  const gap = F * 0.7;\n  const hair = Math.max(1, Math.round(H / 720));\n\n  const drawn = interpolate(t, [0, LINE_LEN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const opened = interpolate(t, [OPEN_AT, OPEN_AT + OPEN_LEN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const shut = interpolate(t, [SHUT_AT, SHUT_AT + SHUT_LEN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_SNAP,\n  });\n  const h = hMax * opened * (1 - shut);\n  const drift = interpolate(t, [OPEN_AT, SHUT_AT + SHUT_LEN], [0, 1], {\n    ...CLAMP,\n    easing: EASE_DRIFT,\n  });\n\n  const IW = slotW * zoom;\n  const IH = (IW * 9) / 16;\n  const fx = pan[0] + (pan[1] - pan[0]) * drift;\n  const ix = slotW / 2 - fx * IW;\n  const iy = hMax / 2 - focusY * IH;\n  const settle = 1 + 0.04 * (1 - opened);\n\n  const rowH = F * 1.2;\n  const lineTop = cy - hMax / 2 - gap - layout.q.length * PITCH * F;\n  const belowTop = cy + hMax / 2 + gap * 0.9;\n  const edge = (x: number, w: number, y: number, key: string) => (\n    <div\n      key={key}\n      style={{\n        position: \"absolute\",\n        left: x,\n        top: y - hair / 2,\n        width: Math.max(0, w),\n        height: hair,\n        background: c.line,\n      }}\n    />\n  );\n  const reach = W * drawn;\n\n  const block = (\n    rows: Row[],\n    top: number,\n    at: number,\n    color: string,\n    key: string,\n  ) => {\n    let wi = 0;\n    return rows.map((row, li) => (\n      <div\n        key={`${key}-${li}`}\n        style={{\n          position: \"absolute\",\n          left: mx - F * 0.1,\n          top: top + li * PITCH * F,\n          width: row.w * F + F * 0.3,\n          height: rowH,\n          overflow: \"hidden\",\n        }}\n      >\n        {row.words.map((w) => {\n          const i = wi++;\n          const q = interpolate(\n            t,\n            [at + i * STAGGER, at + i * STAGGER + WORD_LEN],\n            [0, 1],\n            { ...CLAMP, easing: EASE_OUT },\n          );\n          return (\n            <div\n              key={`${key}-w-${i}`}\n              style={{\n                position: \"absolute\",\n                left: w.x * F + F * 0.1,\n                top: 0,\n                height: rowH,\n                fontFamily: funnel.fontFamily,\n                fontWeight: WGHT,\n                fontSize: F,\n                lineHeight: `${rowH}px`,\n                letterSpacing: `${TRACK}em`,\n                whiteSpace: \"pre\",\n                color,\n                transform: `translateY(${((1 - q) * rowH).toFixed(2)}px)`,\n              }}\n            >\n              {w.text}\n            </div>\n          );\n        })}\n      </div>\n    ));\n  };\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {block(layout.q, lineTop, Q_AT, c.ink, \"q\")}\n      {edge(0, reach, cy, \"base\")}\n      <div\n        style={{\n          position: \"absolute\",\n          left: slotX,\n          top: cy - h / 2,\n          width: slotW,\n          height: h,\n          overflow: \"hidden\",\n        }}\n      >\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            top: -(hMax - h) / 2,\n            width: slotW,\n            height: hMax,\n          }}\n        >\n          <Img\n            src={image}\n            style={{\n              position: \"absolute\",\n              left: ix,\n              top: iy,\n              width: IW,\n              height: IH,\n              objectFit: \"cover\",\n              transformOrigin: `${fx * 100}% ${focusY * 100}%`,\n              transform: `scale(${settle.toFixed(4)})`,\n            }}\n          />\n        </div>\n      </div>\n      {h > hair * 1.5\n        ? [\n            edge(\n              slotX,\n              Math.min(reach, slotX + slotW) - slotX,\n              cy - h / 2,\n              \"e-t\",\n            ),\n            edge(\n              slotX,\n              Math.min(reach, slotX + slotW) - slotX,\n              cy + h / 2,\n              \"e-b\",\n            ),\n          ]\n        : null}\n      {block(layout.r, belowTop, R_AT, c.ink, \"r\")}\n      {block(\n        layout.wn,\n        belowTop + layout.r.length * PITCH * F,\n        whenAt,\n        hi,\n        \"wn\",\n      )}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/peek-shut.tsx"
    }
  ],
  "type": "registry:component"
}
