{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flip-sting",
  "title": "Flip Sting",
  "description": "The logo flips into place with a small tracked line settling under it.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/flip-sting/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport { type ReactNode, useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst manrope = loadManrope(\"normal\", {\n  weights: [\"400\", \"600\"],\n  subsets: [\"latin\"],\n});\nconst mono = loadMono(\"normal\", { weights: [\"400\"], subsets: [\"latin\"] });\n\nexport interface FlipStingProps {\n  /** Small line under the logo once the flip settles. Pass \"\" to hide. */\n  line?: string;\n  accent?: string;\n  /** Playback multiplier. */\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\n// A studio-ident sting in the manner of the Marvel Studios flip-book: the\n// logo is a stencil, a flip-book of flat graphic frames riffles inside it.\n//\n// Beat sheet (30fps, speed 1):\n//  0–68    the camera pulls out of the R to the whole logo (fast, then\n//          settling); inside the letters, flat frames flip every 2 frames\n//  28–64   the flip slows: 3, 3, 3, 4, 4, 5, 6, 8 frames a page\n//  64      the last page lands: the logo fills with the gradient and holds\n//  74–88   the line rises in under the logo; slow push, poster hold to 130\nconst PULL_END = 68;\nconst LINE_AT = 74;\n/** Frames the demo needs: the flip plus a long poster hold. */\nexport const FLIP_STING_DURATION = 130;\n\n/** Page lengths: a fast riffle that slows into the final fill. */\nconst PAGES = [\n  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 6, 8,\n];\nconst SETTLE_AT = PAGES.reduce((a, b) => a + b, 0);\n\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\nconst PULL = Easing.bezier(0.25, 0.4, 0.1, 1);\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\n\n/** gradients.sh \"limb\" palette: the fill the flip settles on. */\nconst LIMB = [\"#e9ecff\", \"#8a8bff\", \"#4b2bd6\", \"#160c3a\"] as const;\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    /** The flat ink that pages are printed on, opposite the stage. */\n    ink: \"#F5F4F0\",\n    muted: \"#9A9893\",\n    fill: [LIMB[0], LIMB[1], LIMB[2]],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    ink: \"#0A0A0B\",\n    muted: \"#6E6C67\",\n    fill: [LIMB[1], LIMB[2], LIMB[3]],\n  },\n} as const;\n\ntype Colors = (typeof THEMES)[keyof typeof THEMES];\n\nconst REMOCN_R_PATH =\n  \"M 0.01 0.81 C 0.01 1.73, 0.36 2.79, 1.09 4.13 C 4.91 11.04, 13.45 17.16, 21.7 18.9 C 22.94 19.16, 23.18 19.16, 51.39 19.27 C 76.07 19.36, 80.02 19.4, 81.32 19.57 C 89.89 20.69, 96.2 24.68, 99.38 31.01 C 103.19 38.56, 102.53 50.1, 97.91 57.07 C 94.66 61.96, 89.68 64.99, 83.26 66 C 82.81 66.07, 70.18 66.83, 55.2 67.69 C 24.82 69.43, 27.03 69.23, 24.18 70.4 C 19.9 72.15, 14.84 75.7, 10.65 79.89 C 4.86 85.68, 1.3 91.91, 0.25 98.13 C 0.12 98.85, 0.08 103.13, 0.04 116.66 L 0 134.26 9.5 134.26 L 19 134.26 19.05 119.41 C 19.1 103.27, 19.08 103.82, 19.82 101.04 C 21.79 93.65, 27.86 88.75, 36.45 87.63 C 37.23 87.53, 39.41 87.5, 43.57 87.53 C 50.12 87.59, 50.75 87.65, 53.22 88.45 C 56.61 89.56, 59.67 91.86, 62.02 95.07 C 62.52 95.76, 69.35 103.85, 77.2 113.07 C 85.04 122.28, 91.63 130.04, 91.85 130.32 C 92.07 130.59, 92.5 131.34, 92.82 131.97 C 93.52 133.35, 94.11 133.93, 95.06 134.13 C 95.5 134.23, 98.97 134.26, 106.36 134.23 L 117.01 134.19 100.82 113.07 C 91.91 101.45, 84.52 91.78, 84.39 91.57 C 83.36 89.89, 83.66 87.53, 85.09 86 C 85.79 85.25, 86.36 84.94, 88.07 84.38 C 96.18 81.72, 104.15 76.62, 109.97 70.36 C 120.59 58.93, 124.06 44.32, 119.44 30.43 C 114.59 15.81, 101.93 4.02, 87.64 0.83 C 83.93 0.01, 88.09 0.08, 41.85 0.04 L 0.01 0 0.01 0.81 Z\";\nconst R_W = 124.06;\nconst R_H = 134.26;\n\n/**\n * The remocn.dev logo in em: the R is 0.76em tall on the baseline, then a\n * 0.04em gap and \"emocn\" in Manrope 600 at -0.025em (harfbuzz width 3.25em).\n */\nconst R_HEIGHT = 0.76;\nconst R_WIDTH = (R_HEIGHT * R_W) / R_H;\nconst GAP = 0.04;\nconst WORD_TRACK = -0.025;\nconst WORD_WIDTH = 3.25 + WORD_TRACK * 4;\nconst LOGO_WIDTH = R_WIDTH + GAP + WORD_WIDTH;\n\nfunction hash(i: number, salt: number) {\n  const s = Math.sin(i * 127.1 + salt * 311.7) * 43758.5453;\n  return s - Math.floor(s);\n}\n\n/**\n * The logo as clip geometry, its visual centre on the origin of `camera`.\n * A clipPath can't hold a <g>, so the camera goes on every shape.\n */\nfunction LogoShape({ size, camera }: { size: number; camera: string }) {\n  const left = (-LOGO_WIDTH * size) / 2;\n  const baseline = (R_HEIGHT * size) / 2;\n  const k = (R_HEIGHT * size) / R_H;\n  return (\n    <>\n      <path\n        d={REMOCN_R_PATH}\n        transform={`${camera} translate(${left} ${baseline - R_HEIGHT * size}) scale(${k})`}\n      />\n      <text\n        x={left + (R_WIDTH + GAP) * size}\n        y={baseline}\n        fontFamily={manrope.fontFamily}\n        fontWeight={600}\n        fontSize={size}\n        letterSpacing={WORD_TRACK * size}\n        transform={camera}\n      >\n        emocn\n      </text>\n    </>\n  );\n}\n\n/**\n * One flat frame of the flip-book, drawn in screen space. Pages are printed\n * on the ink or the accent, never on the stage colour, so the letters always\n * read as a silhouette.\n */\nfunction Page({\n  index,\n  W,\n  H,\n  c,\n  accent,\n}: {\n  index: number;\n  W: number;\n  H: number;\n  c: Colors;\n  accent: string;\n}) {\n  const design = (index * 7 + 3) % 9;\n  const jx = (hash(index, 1) - 0.5) * W * 0.3;\n  const jy = (hash(index, 2) - 0.5) * H * 0.3;\n  const onAccent = index % 2 === 0;\n  const field = onAccent ? accent : c.ink;\n  // The big shape is the other printing ink; the small mark comes from the\n  // limb palette. Neither is ever the stage colour, so no page can punch a\n  // hole in the logo.\n  const dark = onAccent ? c.ink : accent;\n  const mark = LIMB[1];\n  const els: ReactNode[] = [];\n  switch (design) {\n    case 0: {\n      // A giant page number.\n      els.push(\n        <text\n          key=\"n\"\n          x={W * 0.5 + jx}\n          y={H * 0.82 + jy * 0.4}\n          textAnchor=\"middle\"\n          fontFamily={manrope.fontFamily}\n          fontWeight={400}\n          fontSize={H * 1.05}\n          letterSpacing={-0.04 * H}\n          fill={dark}\n        >\n          {String((index % 9) + 1).padStart(2, \"0\")}\n        </text>,\n      );\n      break;\n    }\n    case 1: {\n      els.push(\n        <circle\n          key=\"c\"\n          cx={W * 0.58 + jx}\n          cy={H * 0.5 + jy}\n          r={H * 0.42}\n          fill={dark}\n        />,\n        <circle\n          key=\"d\"\n          cx={W * 0.58 + jx + H * 0.3}\n          cy={H * 0.5 + jy - H * 0.3}\n          r={H * 0.09}\n          fill={mark}\n        />,\n      );\n      break;\n    }\n    case 2: {\n      const band = H / 9;\n      for (let b = 0; b < 9; b += 2) {\n        els.push(\n          <rect\n            key={b}\n            x={0}\n            y={b * band + (jy % band)}\n            width={W}\n            height={band}\n            fill={dark}\n          />,\n        );\n      }\n      break;\n    }\n    case 3: {\n      const x = W * 0.45 + jx;\n      els.push(\n        <polygon\n          key=\"s\"\n          points={`${x - H * 0.2},${H} ${x + H * 0.25},${H} ${x + H * 0.95},0 ${x + H * 0.5},0`}\n          fill={mark}\n        />,\n        <polygon\n          key=\"t\"\n          points={`${x - H * 0.9},${H} ${x - H * 0.45},${H} ${x + H * 0.25},0 ${x - H * 0.2},0`}\n          fill={dark}\n        />,\n      );\n      break;\n    }\n    case 4: {\n      const step = H / 6;\n      const r = step * 0.28;\n      for (let gy = 0; gy < 7; gy++) {\n        for (let gx = 0; gx < Math.ceil(W / step) + 1; gx++) {\n          els.push(\n            <circle\n              key={`${gx}-${gy}`}\n              cx={gx * step + (jx % step)}\n              cy={gy * step + step / 2}\n              r={r}\n              fill={dark}\n            />,\n          );\n        }\n      }\n      break;\n    }\n    case 5: {\n      let x = (jx % (W * 0.1)) - W * 0.1;\n      let b = 0;\n      while (x < W) {\n        const w = W * (0.025 + hash(index * 13 + b, 4) * 0.07);\n        if (b % 2 === 0) {\n          els.push(\n            <rect\n              key={b}\n              x={x}\n              y={0}\n              width={w}\n              height={H}\n              fill={b % 4 === 0 ? dark : mark}\n            />,\n          );\n        }\n        x += w;\n        b++;\n      }\n      break;\n    }\n    case 6: {\n      els.push(\n        <circle\n          key=\"r\"\n          cx={W * 0.5 + jx}\n          cy={H * 0.5 + jy}\n          r={H * 0.36}\n          fill=\"none\"\n          stroke={dark}\n          strokeWidth={H * 0.16}\n        />,\n      );\n      break;\n    }\n    case 7: {\n      // The R itself, huge and cropped.\n      const h = H * 1.5;\n      els.push(\n        <path\n          key=\"R\"\n          d={REMOCN_R_PATH}\n          fill={dark}\n          transform={`translate(${W * 0.3 + jx} ${-H * 0.2 + jy}) scale(${h / R_H})`}\n        />,\n      );\n      break;\n    }\n    default: {\n      const s = H * 0.24;\n      for (let k = 3; k >= 0; k--) {\n        els.push(\n          <rect\n            key={k}\n            x={W * 0.5 + jx - s * (k + 1)}\n            y={H * 0.5 + jy - s * (k + 1)}\n            width={s * 2 * (k + 1)}\n            height={s * 2 * (k + 1)}\n            fill={k % 2 === 0 ? dark : field}\n          />,\n        );\n      }\n    }\n  }\n  return (\n    <>\n      <rect width={W} height={H} fill={field} />\n      {els}\n    </>\n  );\n}\n\nexport function FlipSting({\n  line = \"LAUNCH FILMS\",\n  accent = \"#3B5BFD\",\n  speed = 1,\n  theme = \"dark\",\n}: FlipStingProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n\n  const size = Math.min((W * 0.62) / LOGO_WIDTH, (H * 0.3) / R_HEIGHT);\n  const showLine = line !== \"\";\n  const centerY = showLine ? H * 0.46 : H * 0.5;\n\n  // Camera: out of the R, settling on the whole logo, then a slow push.\n  const pull = interpolate(t, [0, PULL_END], [0, 1], {\n    ...CLAMP,\n    easing: PULL,\n  });\n  const push = interpolate(t, [PULL_END, FLIP_STING_DURATION], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const s0 = 3.6;\n  const scale = Math.exp(Math.log(s0) * (1 - pull)) * (1 + push * 0.025);\n  const focusX =\n    ((-LOGO_WIDTH * size) / 2 + R_WIDTH * size * 0.42) * (1 - pull);\n  const focusY = -R_HEIGHT * size * 0.1 * (1 - pull);\n\n  // Which page of the flip-book is up.\n  let page = -1;\n  let acc = 0;\n  for (let i = 0; i < PAGES.length; i++) {\n    if (t < acc + PAGES[i]) {\n      page = i;\n      break;\n    }\n    acc += PAGES[i];\n  }\n  const settled = page === -1 || t >= SETTLE_AT;\n  const drift = interpolate(t, [SETTLE_AT, FLIP_STING_DURATION], [0, 1], CLAMP);\n\n  const lineIn = interpolate(t, [LINE_AT, LINE_AT + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n  const logoBottom = centerY + (R_HEIGHT * size * scale) / 2;\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <svg\n        width={W}\n        height={H}\n        viewBox={`0 0 ${W} ${H}`}\n        style={{ position: \"absolute\", inset: 0 }}\n        aria-hidden\n      >\n        <defs>\n          <clipPath id={`${uid}-logo`}>\n            <LogoShape\n              size={size}\n              camera={`translate(${W / 2} ${centerY}) scale(${scale}) translate(${-focusX} ${-focusY})`}\n            />\n          </clipPath>\n          <linearGradient\n            id={`${uid}-fill`}\n            gradientUnits=\"userSpaceOnUse\"\n            x1={W * (0.2 + drift * 0.06)}\n            y1={centerY - size * 0.6}\n            x2={W * (0.8 + drift * 0.06)}\n            y2={centerY + size * 0.6}\n          >\n            <stop offset=\"0\" stopColor={c.fill[0]} />\n            <stop offset=\"0.5\" stopColor={c.fill[1]} />\n            <stop offset=\"1\" stopColor={c.fill[2]} />\n          </linearGradient>\n        </defs>\n        <g clipPath={`url(#${uid}-logo)`}>\n          {settled ? (\n            <rect width={W} height={H} fill={`url(#${uid}-fill)`} />\n          ) : (\n            <Page index={page} W={W} H={H} c={c} accent={accent} />\n          )}\n        </g>\n      </svg>\n      {showLine ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            right: 0,\n            top: logoBottom + H * 0.075,\n            textAlign: \"center\",\n            fontFamily: mono.fontFamily,\n            fontWeight: 400,\n            fontSize: H * 0.03,\n            lineHeight: 1,\n            letterSpacing: \"0.42em\",\n            paddingLeft: \"0.42em\",\n            color: c.muted,\n            opacity: lineIn,\n            transform: `translateY(${(1 - lineIn) * H * 0.015}px)`,\n          }}\n        >\n          {line}\n        </div>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/flip-sting.tsx"
    }
  ],
  "type": "registry:component"
}
