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.

10.0 KB
Raw Blame
<template id="captions-template">
  <div
    data-composition-id="captions"
    data-start="0"
    data-width="1080"
    data-height="1920"
    data-duration="18.84"
  >
    <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;
        /* Layered text-shadow stack creates a uniform 4px black stroke that
           renders reliably in Chromium render (unlike -webkit-text-stroke). */
        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 from assets/may_shorts_19.json (ORIGINAL timeline).
        // The edited video had 1.12s removed in the 2.88s–4.00s window of the original.
        // Shift rule: t <= 2.88 unchanged; 2.88 < t < 4.00 clamps to 2.88; t >= 4.00 -> t - 1.12.
        const SEGMENTS = [
          {
            words: [
              { word: "I", start: 0.0, end: 0.14 },
              { word: "tested", start: 0.14, end: 0.38 },
              { word: "100", start: 0.38, end: 0.72 },
              { word: "plus", start: 0.72, end: 0.98 },
              { word: "Claude", start: 0.98, end: 1.24 },
              { word: "Code", start: 1.24, end: 1.5 },
              { word: "skills.", start: 1.5, end: 1.8 },
            ],
          },
          {
            words: [
              { word: "Most", start: 2.36, end: 2.42 },
              { word: "of", start: 2.42, end: 2.6 },
              { word: "them,", start: 2.6, end: 2.78 },
              { word: "no", start: 4.0, end: 4.58 },
              { word: "business", start: 4.58, end: 4.82 },
              { word: "actually", start: 4.82, end: 5.18 },
              { word: "needs.", start: 5.18, end: 5.5 },
            ],
          },
          {
            words: [
              { word: "They\u2019re", start: 5.92, end: 6.04 },
              { word: "cool,", start: 6.04, end: 6.28 },
              { word: "but", start: 6.44, end: 6.58 },
              { word: "pointless.", start: 6.58, end: 6.9 },
            ],
          },
          {
            words: [
              { word: "But", start: 7.38, end: 7.5 },
              { word: "there", start: 7.5, end: 7.62 },
              { word: "are", start: 7.62, end: 7.76 },
              { word: "six", start: 7.76, end: 7.98 },
              { word: "that", start: 7.98, end: 8.22 },
              { word: "businesses", start: 8.22, end: 8.48 },
              { word: "actually", start: 8.48, end: 8.96 },
              { word: "want.", start: 8.96, end: 9.3 },
            ],
          },
          {
            words: [
              { word: "The", start: 9.62, end: 9.76 },
              { word: "kind", start: 9.76, end: 9.9 },
              { word: "that", start: 9.9, end: 10.06 },
              { word: "save", start: 10.06, end: 10.2 },
              { word: "time,", start: 10.2, end: 10.62 },
              { word: "fix", start: 10.9, end: 11.02 },
              { word: "mistakes,", start: 11.02, end: 11.44 },
              { word: "and", start: 11.84, end: 11.98 },
              { word: "make", start: 11.98, end: 12.16 },
              { word: "Claude", start: 12.16, end: 12.38 },
              { word: "useful", start: 12.38, end: 12.64 },
              { word: "for", start: 12.64, end: 12.88 },
              { word: "real", start: 12.88, end: 13.02 },
              { word: "work.", start: 13.02, end: 13.3 },
            ],
          },
          {
            words: [
              { word: "If", start: 13.7, end: 13.82 },
              { word: "you\u2019re", start: 13.82, end: 13.96 },
              { word: "building", start: 13.96, end: 14.18 },
              { word: "with", start: 14.18, end: 14.38 },
              { word: "Claude", start: 14.38, end: 14.6 },
              { word: "Code,", start: 14.6, end: 14.88 },
              { word: "these", start: 15.16, end: 15.32 },
              { word: "are", start: 15.32, end: 15.44 },
              { word: "the", start: 15.44, end: 15.54 },
              { word: "only", start: 15.54, end: 15.74 },
              { word: "ones", start: 15.74, end: 15.98 },
              { word: "that", start: 15.98, end: 16.12 },
              { word: "matter.", start: 16.12, end: 16.38 },
            ],
          },
          {
            // NOTE: whisper hallucinated "send you the video breaking it all down"
            // for this segment. Actual audio says "DM you the breakdown." Words
            // below are hand-timed in original-time coordinates so the same shift()
            // function maps them correctly into the edited timeline.
            words: [
              { word: "Comment", start: 17.08, end: 17.24 },
              { word: "skills", start: 17.24, end: 17.9 },
              { word: "and", start: 17.95, end: 18.12 },
              { word: "I\u2019ll", start: 18.12, end: 18.3 },
              { word: "DM", start: 18.3, end: 18.57 },
              { word: "you", start: 18.57, end: 18.82 },
              { word: "the", start: 18.82, end: 19.07 },
              { word: "breakdown.", start: 19.07, end: 19.8 },
            ],
          },
        ];

        // Edit-shift function for the 1.12s cut.
        function shift(t) {
          if (t <= 2.88) return t;
          if (t < 4.0) return 2.88;
          return t - 1.12;
        }

        const COMP_DURATION = 18.84;
        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;

        // Build the DOM synchronously: one wrapper per segment, with word spans inside.
        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 = shift(seg.words[0].start);
          const segEnd = shift(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;

          // Reset every word in this segment to dim/rest before the line appears.
          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,
          );

          // Per-word karaoke pops — scale up as word lands, snap back once spoken.
          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)",
              },
              shift(w.start),
            );
            tl.to(
              wordSel,
              {
                color: SPOKEN,
                scale: 1.0,
                duration: 0.12,
                ease: "power2.out",
              },
              shift(w.end),
            );
          });

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

        // Pad timeline to composition duration.
        tl.set({}, {}, COMP_DURATION);

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