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.7 KB
Raw Blame
<template id="captions-template">
  <div
    data-composition-id="captions"
    data-start="0"
    data-width="1920"
    data-height="1080"
    data-duration="19.5"
  >
    <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: 96px;
        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 80px;
        opacity: 0;
        visibility: hidden;
      }
      [data-composition-id="captions"] .cap-line {
        display: inline-block;
        max-width: 1700px;
        background: transparent;
        padding: 0 16px;
        text-align: center;
        font-family: "Montserrat", sans-serif;
        font-weight: 900;
        font-size: 64px;
        line-height: 1.12;
        letter-spacing: -0.01em;
        word-spacing: 0.12em;
        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 18px rgba(0, 0, 0, 0.6);
        white-space: normal;
      }
      [data-composition-id="captions"] .cap-word {
        display: inline-block;
        transform-origin: center center;
        will-change: transform, color;
        padding: 0 0.04em;
      }
    </style>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>
    <script>
      (function () {
        // Word-level transcript regrouped into punchy caption lines (3–6 words each,
        // ≤2.5s) from assets/may_shorts_6.json.
        // Per-word `accent` overrides the active highlight to AIS warn (#f09025)
        // for hot-emphasis words (500, boring, money, 500W) — the color carries
        // the meaning per MOTION_PHILOSOPHY § 2.3.
        const SEGMENTS = [
          {
            words: [
              { word: "I've", start: 0.0, end: 0.36 },
              { word: "built", start: 0.36, end: 0.4 },
              { word: "over", start: 0.4, end: 0.68 },
              { word: "500", start: 0.68, end: 1.08, accent: "warn" },
              { word: "AI", start: 1.08, end: 1.32 },
              { word: "workflows", start: 1.32, end: 1.66 },
            ],
          },
          {
            words: [
              { word: "and", start: 2.06, end: 2.22 },
              { word: "most", start: 2.22, end: 2.38 },
              { word: "of", start: 2.38, end: 2.52 },
              { word: "them", start: 2.52, end: 2.7 },
            ],
          },
          {
            words: [
              { word: "businesses", start: 3.42, end: 3.55 },
              { word: "don't", start: 3.55, end: 3.68 },
              { word: "need", start: 3.68, end: 3.96 },
            ],
          },
          {
            words: [
              { word: "they", start: 4.02, end: 4.2 },
              { word: "don't", start: 4.2, end: 4.36 },
              { word: "need", start: 4.36, end: 4.6 },
              { word: "flashy", start: 4.6, end: 4.84 },
              { word: "automations", start: 4.84, end: 5.34 },
            ],
          },
          {
            words: [
              { word: "or", start: 5.34, end: 5.68 },
              { word: "cool", start: 5.68, end: 5.94 },
              { word: "AI", start: 5.94, end: 6.18 },
              { word: "demos", start: 6.18, end: 6.44 },
            ],
          },
          {
            words: [
              { word: "they", start: 6.62, end: 6.94 },
              { word: "want", start: 6.94, end: 7.14 },
              { word: "simple", start: 7.14, end: 7.4 },
              { word: "things", start: 7.4, end: 7.56 },
            ],
          },
          {
            words: [
              { word: "that", start: 7.56, end: 7.78 },
              { word: "save", start: 7.78, end: 7.96 },
              { word: "time", start: 7.96, end: 8.26 },
              { word: "or", start: 8.26, end: 8.42 },
              { word: "make", start: 8.42, end: 8.6 },
              { word: "money", start: 8.6, end: 8.8, accent: "warn" },
            ],
          },
          {
            words: [
              { word: "That's", start: 9.18, end: 9.44 },
              { word: "it.", start: 9.44, end: 9.76 },
            ],
          },
          {
            words: [
              { word: "The", start: 10.14, end: 10.34 },
              { word: "workflows", start: 10.34, end: 10.52 },
              { word: "that", start: 10.52, end: 10.74 },
              { word: "actually", start: 10.74, end: 11.12 },
              { word: "work", start: 11.12, end: 11.26 },
            ],
          },
          {
            words: [
              { word: "are", start: 11.26, end: 11.55 },
              { word: "boring", start: 11.55, end: 11.95, accent: "warn" },
            ],
          },
          {
            words: [
              { word: "stuff", start: 12.22, end: 12.32 },
              { word: "that", start: 12.32, end: 12.52 },
              { word: "replaces", start: 12.52, end: 12.76 },
              { word: "real", start: 12.76, end: 13.12 },
              { word: "work", start: 13.12, end: 13.34 },
            ],
          },
          {
            words: [
              { word: "That's", start: 13.7, end: 13.84 },
              { word: "what", start: 13.84, end: 14.0 },
              { word: "businesses", start: 14.0, end: 14.26 },
              { word: "pay", start: 14.26, end: 14.54, accent: "warn" },
              { word: "for.", start: 14.54, end: 14.8 },
            ],
          },
          {
            words: [
              { word: "Comment", start: 15.36, end: 15.84 },
              { word: "500W", start: 15.84, end: 16.32, accent: "warn" },
            ],
          },
          {
            words: [
              { word: "and", start: 16.32, end: 16.98 },
              { word: "I'll", start: 16.98, end: 17.12 },
              { word: "send", start: 17.12, end: 17.28 },
              { word: "you", start: 17.28, end: 17.38 },
              { word: "the", start: 17.38, end: 17.52 },
              { word: "full", start: 17.52, end: 17.72 },
              { word: "breakdown.", start: 17.72, end: 17.92 },
            ],
          },
        ];

        const COMP_DURATION = 19.5;
        const DIM = "rgba(255,255,255,0.7)";
        const ACTIVE = "#37bdf8";
        const ACTIVE_WARN = "#f09025";
        const SPOKEN = "#ffffff";
        const ACTIVE_SCALE = 1.06;

        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.16;
        const FADE_OUT = 0.12;
        const PRE_ROLL = 0.10;
        const POST_HOLD = 0.18;
        // Minimum gap to keep between an outgoing line's end-of-fade and the
        // incoming line's start-of-fade. Anything tighter and back-to-back
        // segments visually stack — see scene 6 "boring" + scene 8 "and I'll".
        const SWAP_GAP = 0.06;

        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 next = SEGMENTS[segIdx + 1];

          // Clamp fade-in so it never starts while previous segment is still
          // visible. (Previous segment's calculation already accounts for this
          // when we look ahead, so PRE_ROLL only kicks in when there's room.)
          const naiveFadeIn = Math.max(segStart - PRE_ROLL, 0);
          const fadeInAt = naiveFadeIn;

          // Clamp fade-out to the next segment's fade-in minus a small gap, so
          // the outgoing line is fully gone before the incoming line lands.
          const naiveFadeOut = segEnd + POST_HOLD;
          const fadeOutAt = next
            ? Math.min(
                naiveFadeOut,
                Math.max(next.words[0].start - PRE_ROLL, 0) - FADE_OUT - SWAP_GAP,
              )
            : naiveFadeOut;
          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: 12 },
            { 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;
            const activeColor = w.accent === "warn" ? ACTIVE_WARN : ACTIVE;
            tl.to(
              wordSel,
              {
                color: activeColor,
                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>