| 1 | <template id="captions-template"> |
| 2 | <div |
| 3 | data-composition-id="captions" |
| 4 | data-width="1920" |
| 5 | data-height="1080" |
| 6 | data-duration="__VIDEO_DURATION__" |
| 7 | > |
| 8 | <div class="captions-container"> |
| 9 | <div id="caption-box" class="caption-box"> |
| 10 | <span id="caption-text" class="caption-text"></span> |
| 11 | </div> |
| 12 | </div> |
| 13 | |
| 14 | <style> |
| 15 | [data-composition-id="captions"] .captions-container { |
| 16 | width: 100%; |
| 17 | height: 100%; |
| 18 | display: flex; |
| 19 | justify-content: center; |
| 20 | align-items: flex-end; |
| 21 | padding-bottom: 230px; /* Position at y: 850 (1080 - 230 = 850) */ |
| 22 | pointer-events: none; |
| 23 | } |
| 24 | |
| 25 | [data-composition-id="captions"] .caption-box { |
| 26 | background-color: #7a6248; |
| 27 | padding: 12px 32px; |
| 28 | border-radius: 24px; |
| 29 | display: flex; |
| 30 | justify-content: center; |
| 31 | align-items: center; |
| 32 | min-width: 100px; |
| 33 | max-width: 80%; |
| 34 | opacity: 0; |
| 35 | box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); |
| 36 | } |
| 37 | |
| 38 | [data-composition-id="captions"] .caption-text { |
| 39 | color: #f5f0e0; |
| 40 | font-family: "Outfit", sans-serif; |
| 41 | font-size: 48px; |
| 42 | font-weight: 700; |
| 43 | text-align: center; |
| 44 | line-height: 1.2; |
| 45 | white-space: nowrap; |
| 46 | max-width: 1600px; |
| 47 | overflow: hidden; |
| 48 | } |
| 49 | </style> |
| 50 | |
| 51 | <script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script> |
| 52 | <script> |
| 53 | (function () { |
| 54 | const script = [ |
| 55 | { text: "We", start: 0.119, end: 0.259 }, |
| 56 | { text: "asked", start: 0.319, end: 0.479 }, |
| 57 | { text: "what", start: 0.519, end: 0.659 }, |
| 58 | { text: "you", start: 0.699, end: 0.819 }, |
| 59 | { text: "needed.", start: 0.859, end: 1.819 }, |
| 60 | { text: "Forty-seven", start: 1.86, end: 2.299 }, |
| 61 | { text: "percent", start: 2.399, end: 2.679 }, |
| 62 | { text: "of", start: 2.7, end: 2.799 }, |
| 63 | { text: "you", start: 2.839, end: 2.939 }, |
| 64 | { text: "said", start: 3.039, end: 3.179 }, |
| 65 | { text: "motion", start: 3.24, end: 3.559 }, |
| 66 | { text: "graphics,", start: 3.579, end: 4.599 }, |
| 67 | { text: "sixty-two", start: 4.679, end: 5.179 }, |
| 68 | { text: "percent", start: 5.299, end: 5.759 }, |
| 69 | { text: "said", start: 5.859, end: 5.98 }, |
| 70 | { text: "static", start: 6.079, end: 6.399 }, |
| 71 | { text: "content", start: 6.46, end: 6.879 }, |
| 72 | { text: "was", start: 6.92, end: 7.079 }, |
| 73 | { text: "costing", start: 7.099, end: 7.48 }, |
| 74 | { text: "you", start: 7.5, end: 7.579 }, |
| 75 | { text: "attention,", start: 7.679, end: 8.659 }, |
| 76 | { text: "and", start: 8.699, end: 8.86 }, |
| 77 | { text: "three", start: 8.88, end: 9.06 }, |
| 78 | { text: "out", start: 9.079, end: 9.18 }, |
| 79 | { text: "of", start: 9.199, end: 9.34 }, |
| 80 | { text: "four", start: 9.38, end: 9.799 }, |
| 81 | { text: "said", start: 9.84, end: 10.0 }, |
| 82 | { text: "you", start: 10.019, end: 10.159 }, |
| 83 | { text: "know", start: 10.179, end: 10.36 }, |
| 84 | { text: "the", start: 10.38, end: 10.42 }, |
| 85 | { text: "look", start: 10.519, end: 10.699 }, |
| 86 | { text: "you", start: 10.739, end: 10.859 }, |
| 87 | { text: "want", start: 10.98, end: 11.34 }, |
| 88 | { text: "but", start: 11.359, end: 11.52 }, |
| 89 | { text: "don't", start: 11.56, end: 11.779 }, |
| 90 | { text: "have", start: 11.819, end: 11.94 }, |
| 91 | { text: "the", start: 11.96, end: 12.06 }, |
| 92 | { text: "editing", start: 12.079, end: 12.4 }, |
| 93 | { text: "skills", start: 12.52, end: 12.86 }, |
| 94 | { text: "to", start: 12.88, end: 13.0 }, |
| 95 | { text: "get", start: 13.019, end: 13.18 }, |
| 96 | { text: "there.", start: 13.22, end: 14.22 }, |
| 97 | { text: "So", start: 14.239, end: 14.399 }, |
| 98 | { text: "we", start: 14.42, end: 14.52 }, |
| 99 | { text: "built", start: 14.619, end: 14.88 }, |
| 100 | { text: "Hyperframes.", start: 15.079, end: 16.02 }, |
| 101 | ]; |
| 102 | |
| 103 | // Group words into lines (max 5 words per line) |
| 104 | const lines = []; |
| 105 | for (let i = 0; i < script.length; i += 5) { |
| 106 | const lineWords = script.slice(i, i + 5); |
| 107 | lines.push({ |
| 108 | text: lineWords.map((w) => w.text).join(" "), |
| 109 | start: lineWords[0].start, |
| 110 | end: lineWords[lineWords.length - 1].end, |
| 111 | }); |
| 112 | } |
| 113 | |
| 114 | const tl = gsap.timeline({ paused: true }); |
| 115 | const box = document.querySelector('[data-composition-id="captions"] #caption-box'); |
| 116 | const textEl = document.querySelector('[data-composition-id="captions"] #caption-text'); |
| 117 | |
| 118 | lines.forEach((line, index) => { |
| 119 | // Fade in and set text |
| 120 | tl.set(box, { visibility: "visible" }, line.start); |
| 121 | tl.to( |
| 122 | box, |
| 123 | { |
| 124 | opacity: 1, |
| 125 | duration: 0.1, |
| 126 | ease: "power2.out", |
| 127 | onStart: () => { |
| 128 | textEl.textContent = line.text; |
| 129 | }, |
| 130 | }, |
| 131 | line.start, |
| 132 | ); |
| 133 | |
| 134 | // Fade out at the end of the line |
| 135 | tl.to( |
| 136 | box, |
| 137 | { |
| 138 | opacity: 0, |
| 139 | duration: 0.1, |
| 140 | ease: "power2.in", |
| 141 | }, |
| 142 | line.end, |
| 143 | ); |
| 144 | |
| 145 | // Hard kill to ensure caption is hidden |
| 146 | tl.set(box, { opacity: 0, visibility: "hidden" }, line.end + 0.1); |
| 147 | }); |
| 148 | |
| 149 | window.__timelines = window.__timelines || {}; |
| 150 | window.__timelines["captions"] = tl; |
| 151 | })(); |
| 152 | </script> |
| 153 | </div> |
| 154 | </template> |
| 155 |