Skip to content

Herk Edit Kit by Nate Herk: edit videos, reels, and YouTube Shorts with Codex or Claude Code. 15 skills, transcript-driven cuts, storytelling, 406 motion-graphics cards, and HyperFrames templates.

9.0 KB
Raw Blame
<template id="captions-template">
  <div
    data-composition-id="captions"
    data-start="0"
    data-width="1080"
    data-height="1920"
    data-duration="19.82"
  >
    <div class="cap-stage" id="cap-stage"></div>

    <style>
      [data-composition-id="captions"] {
        position: absolute;
        inset: 0;
        pointer-events: none;
      }
      [data-composition-id="captions"] .cap-stage {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 220px;
        height: 0;
        pointer-events: none;
      }
      [data-composition-id="captions"] .cap-line-wrap {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        display: flex;
        justify-content: center;
        padding: 0 60px;
        opacity: 0;
        visibility: hidden;
      }
      [data-composition-id="captions"] .cap-line {
        display: inline-block;
        max-width: 940px;
        background: transparent;
        padding: 0 12px;
        text-align: center;
        font-family: "Montserrat", sans-serif;
        font-weight: 900;
        font-size: 54px;
        line-height: 1.14;
        letter-spacing: -0.01em;
        color: #ffffff;
        text-shadow:
          -3px -3px 0 #07121c,
          3px -3px 0 #07121c,
          -3px 3px 0 #07121c,
          3px 3px 0 #07121c,
          -4px 0 0 #07121c,
          4px 0 0 #07121c,
          0 -4px 0 #07121c,
          0 4px 0 #07121c,
          0 6px 14px rgba(0, 0, 0, 0.55);
        white-space: normal;
      }
      [data-composition-id="captions"] .cap-word {
        display: inline-block;
        transform-origin: center center;
        will-change: transform, color;
      }
    </style>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
    <script>
      (function () {
        // Word-level transcript direct from assets/may_shorts_18.json.
        // Audio is unedited — no shift() needed, timestamps pass through.
        const SEGMENTS = [
          {
            // "Claude just killed chat GPT"
            words: [
              { word: "Claude", start: 0.00, end: 0.28 },
              { word: "just", start: 0.28, end: 0.48 },
              { word: "killed", start: 0.48, end: 0.68 },
              { word: "chat", start: 0.68, end: 0.88 },
              { word: "GPT.", start: 0.88, end: 1.32 },
            ],
          },
          {
            // "Not in hype, but in actual use."
            words: [
              { word: "Not", start: 1.76, end: 1.84 },
              { word: "in", start: 1.84, end: 1.98 },
              { word: "hype,", start: 1.98, end: 2.18 },
              { word: "but", start: 2.48, end: 2.54 },
              { word: "in", start: 2.54, end: 2.70 },
              { word: "actual", start: 2.70, end: 2.98 },
              { word: "use.", start: 2.98, end: 3.30 },
            ],
          },
          {
            // "Better outputs, more reliable, less babysitting."
            words: [
              { word: "Better", start: 3.86, end: 3.92 },
              { word: "outputs,", start: 3.92, end: 4.32 },
              { word: "more", start: 4.82, end: 4.92 },
              { word: "reliable,", start: 4.92, end: 5.32 },
              { word: "less", start: 5.90, end: 6.02 },
              { word: "babysitting.", start: 6.02, end: 6.54 },
            ],
          },
          {
            // "If you're building with AI,"
            words: [
              { word: "If", start: 7.38, end: 7.56 },
              { word: "you\u2019re", start: 7.56, end: 7.68 },
              { word: "building", start: 7.68, end: 7.94 },
              { word: "with", start: 7.94, end: 8.14 },
              { word: "AI,", start: 8.14, end: 8.38 },
            ],
          },
          {
            // "You've probably already felt it."
            words: [
              { word: "you\u2019ve", start: 8.62, end: 8.74 },
              { word: "probably", start: 8.74, end: 9.00 },
              { word: "already", start: 9.00, end: 9.40 },
              { word: "felt", start: 9.40, end: 9.64 },
              { word: "it.", start: 9.64, end: 9.88 },
            ],
          },
          {
            // "And if you haven't,"
            words: [
              { word: "And", start: 10.32, end: 10.42 },
              { word: "if", start: 10.42, end: 10.52 },
              { word: "you", start: 10.52, end: 10.66 },
              { word: "haven\u2019t,", start: 10.66, end: 11.12 },
            ],
          },
          {
            // "Then you need to switch before it's too late."
            words: [
              { word: "then", start: 11.32, end: 11.48 },
              { word: "you", start: 11.48, end: 11.64 },
              { word: "need", start: 11.64, end: 11.82 },
              { word: "to", start: 11.82, end: 12.00 },
              { word: "switch", start: 12.00, end: 12.22 },
              { word: "before", start: 12.22, end: 12.62 },
              { word: "it\u2019s", start: 12.62, end: 12.80 },
              { word: "too", start: 12.80, end: 12.94 },
              { word: "late.", start: 12.94, end: 13.22 },
            ],
          },
          {
            // "Comment [dead], and I'll send the video explaining why."
            // NOTE: whisper heard "dead" with ~0.59 confidence — swap the word
            // below if the actual audio says something else (e.g. "Claude").
            words: [
              { word: "Comment", start: 13.82, end: 14.02 },
              { word: "dead,", start: 14.02, end: 14.38 },
              { word: "and", start: 14.76, end: 14.88 },
              { word: "I\u2019ll", start: 14.88, end: 15.04 },
              { word: "send", start: 15.04, end: 15.24 },
              { word: "the", start: 15.24, end: 15.42 },
              { word: "video", start: 15.42, end: 15.72 },
              { word: "explaining", start: 15.72, end: 16.26 },
              { word: "why.", start: 16.26, end: 16.70 },
            ],
          },
        ];

        const COMP_DURATION = 19.82;
        const DIM = "rgba(255,255,255,0.65)";
        const ACTIVE = "#37bdf8";
        const SPOKEN = "#ffffff";
        const ACTIVE_SCALE = 1.14;

        const stage = document.querySelector('[data-composition-id="captions"] #cap-stage');
        if (!stage) return;

        SEGMENTS.forEach(function (seg, segIdx) {
          const wrap = document.createElement("div");
          wrap.className = "cap-line-wrap";
          wrap.id = "cap-seg-" + segIdx;

          const line = document.createElement("div");
          line.className = "cap-line";

          seg.words.forEach(function (w, wIdx) {
            const span = document.createElement("span");
            span.className = "cap-word";
            span.id = "cap-w-" + segIdx + "-" + wIdx;
            span.textContent = w.word;
            line.appendChild(span);
            if (wIdx < seg.words.length - 1) {
              line.appendChild(document.createTextNode(" "));
            }
          });

          wrap.appendChild(line);
          stage.appendChild(wrap);
        });

        const tl = gsap.timeline({ paused: true });
        const FADE_IN = 0.18;
        const FADE_OUT = 0.18;
        const PRE_ROLL = 0.12;
        const POST_HOLD = 0.12;

        SEGMENTS.forEach(function (seg, segIdx) {
          const wrapSel = '[data-composition-id="captions"] #cap-seg-' + segIdx;
          const segStart = seg.words[0].start;
          const segEnd = seg.words[seg.words.length - 1].end;

          const fadeInAt = Math.max(segStart - PRE_ROLL, 0);
          const fadeOutAt = segEnd + POST_HOLD;
          const hideAt = fadeOutAt + FADE_OUT + 0.05;

          seg.words.forEach(function (w, wIdx) {
            const wordSel = '[data-composition-id="captions"] #cap-w-' + segIdx + "-" + wIdx;
            tl.set(wordSel, { color: DIM, scale: 1.0 }, fadeInAt);
          });

          tl.set(wrapSel, { visibility: "visible" }, fadeInAt);
          tl.fromTo(
            wrapSel,
            { opacity: 0, y: 8 },
            { opacity: 1, y: 0, duration: FADE_IN, ease: "power2.out" },
            fadeInAt,
          );

          seg.words.forEach(function (w, wIdx) {
            const wordSel = '[data-composition-id="captions"] #cap-w-' + segIdx + "-" + wIdx;
            tl.to(
              wordSel,
              {
                color: ACTIVE,
                scale: ACTIVE_SCALE,
                duration: 0.08,
                ease: "back.out(3)",
              },
              w.start,
            );
            tl.to(
              wordSel,
              {
                color: SPOKEN,
                scale: 1.0,
                duration: 0.12,
                ease: "power2.out",
              },
              w.end,
            );
          });

          tl.to(
            wrapSel,
            { opacity: 0, duration: FADE_OUT, ease: "power2.in" },
            fadeOutAt,
          );
          tl.set(wrapSel, { visibility: "hidden" }, hideAt);
        });

        tl.set({}, {}, COMP_DURATION);

        window.__timelines = window.__timelines || {};
        window.__timelines["captions"] = tl;
      })();
    </script>
  </div>
</template>