Setting the file. One moment.
Caption Skin · Hyperframes Creative · heygen-com/hyperframes · Skills Docs
ContentsBack to the top of the page 22.10
Narration
(opens in a new tab)
frame-presets/capsule/ caption-skin.html
HTML · 224 lines · 8 KB
15
--cap-ink · --cap-canvas · --cap-accent · --cap-accent-2 · --font-display ·
16 --font-body · --cap-band-top · --cap-band-height
17 Hooks (do not rename): .caption-group / .caption-word + states .is-active / .is-spoken,
18 root data-composition-id="captions", timeline at window.__timelines["captions"].
19 State changes use gsap.set({className}) (applied on the engine's frame-by-frame seek);
20 never tl.call() callbacks (seek does not fire them → wrong state on render).
21
22 Visual: a cream caption pill — fully-rounded (9999px), wrapped in capsule's universal
23 2px ink outline, lifted on a soft hard-offset shadow (no blur), Bodoni Moda glyphs in
24 ink, sentence case. Upcoming words sit in faint ink; the current word lights up as a
25 rounded candy highlight — a candy fill plus a box-shadow spread halo that follows the
26 pill radius (a soft candy capsule around the word, no blur, NO layout shift) with ink
27 reading on top; spoken words settle to solid ink, the candy highlight cleared.
28 -->
29 < script src = "https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js" ></ script >
30
31 <!-- captions.mjs injects the project's :root tokens here -->
32 < style data-brand-tokens ></ style >
33
34 < style >
35 #captions-root {
36 position : absolute ;
37 inset : 0 ;
38 pointer-events : none ;
39 }
40 .caption-layer {
41 position : absolute ;
42 inset : 0 ;
43 z-index : 20 ;
44 pointer-events : none ;
45 }
46 /* the keep-out band, from captionBand(H) — frame content stays above it */
47 .caption-stage {
48 position : absolute ;
49 left : 0 ;
50 right : 0 ;
51 top : var ( --cap-band-top , 900 px );
52 height : var ( --cap-band-height , 180 px );
53 display : flex ;
54 align-items : center ;
55 justify-content : center ;
56 }
57 .caption-group {
58 /* every group is absolutely stacked over the SAME band — exactly one shown at a
59 time via opacity. Must be absolute: in-flow groups would lay out side-by-side. */
60 position : absolute ;
61 inset : 0 ;
62 display : flex ;
63 align-items : center ;
64 justify-content : center ;
65 opacity : 0 ;
66 }
67
68 /* THE caption capsule — cream pill, fully-rounded (9999px), capsule's universal 2px
69 ink outline, lifted on a soft hard-offset shadow (no blur, 8% ink) */
70 .caption-pill {
71 max-width : 80 % ;
72 padding : 18 px 46 px 20 px ;
73 background : var ( --cap-canvas , #f5f5f0 );
74 border : 2 px solid var ( --cap-ink , #1a1a1a );
75 border-radius : 9999 px ;
76 box-shadow : 8 px 8 px 0 color-mix ( in srgb , var ( --cap-ink , #1a1a1a ) 8 % , transparent );
77 }
78 .caption-line {
79 display : flex ;
80 flex-wrap : wrap ;
81 justify-content : center ;
82 gap : 0.12 em 0.36 em ;
83 font-family : var ( --font-display , "Bodoni Moda" ), Georgia , serif ;
84 font-weight : 700 ;
85 font-size : clamp ( 38 px , 4.2 vw , 56 px );
86 line-height : 1.16 ;
87 letter-spacing : -0.02 em ;
88 }
89
90 /* upcoming — faint ink, no highlight */
91 .caption-word {
92 display : inline-block ;
93 padding : 0 0.1 em ;
94 border-radius : 9999 px ;
95 color : color-mix ( in srgb , var ( --cap-ink , #1a1a1a ) 42 % , var ( --cap-canvas , #f5f5f0 ));
96 }
97 /* current word — THE rounded candy highlight: a candy fill + a box-shadow spread
98 halo that follows the pill radius (a soft candy capsule around the word, no blur,
99 no layout shift), ink reading on top */
100 .caption-word.is-active {
101 color : var ( --cap-ink , #1a1a1a );
102 background : var ( --cap-accent , #e85d4e );
103 box-shadow : 0 0 0 0.14 em var ( --cap-accent , #e85d4e );
104 }
105 /* already spoken — solid ink, candy highlight cleared */
106 .caption-word.is-spoken {
107 color : var ( --cap-ink , #1a1a1a );
108 background : transparent ;
109 box-shadow : none ;
110 }
111
112 /* optional per-word accents (dormant until a word-classer tags them) */
113 /* brand / key term — Bodoni Moda italic, capsule's display inflection */
114 .caption-word.cap-brand {
115 font-style : italic ;
116 }
117 /* numerals / data — the Space Grotesk voice, slightly recessed */
118 .caption-word.cap-num {
119 font-family : var ( --font-body , "Space Grotesk" ), ui-sans-serif , sans-serif ;
120 color : color-mix ( in srgb , var ( --cap-ink , #1a1a1a ) 72 % , var ( --cap-canvas , #f5f5f0 ));
121 }
122 /* emphasis — a second-candy rounded underline (the counter-accent) */
123 .caption-word.cap-cta {
124 text-decoration : underline ;
125 text-decoration-thickness : 3 px ;
126 text-decoration-color : var ( --cap-accent-2 , #f2d160 );
127 text-underline-offset : 0.12 em ;
128 }
129
130 @media ( max-aspect-ratio : 9 / 16 ) {
131 .caption-pill {
132 max-width : 92 % ;
133 }
134 .caption-line {
135 font-size : clamp ( 34 px , 5.4 vw , 48 px );
136 }
137 }
138 </ style >
139
140 < div
141 id = "captions-root"
142 data-composition-id = "captions"
143 data-timeline-locked
144 data-start = "0"
145 data-duration = "0"
146 data-fps = "30"
147 data-width = "0"
148 data-height = "0"
149 >
150 < div class = "caption-layer" aria-hidden = "true" >
151 < div id = "caption-stage" class = "caption-stage" ></ div >
152 </ div >
153 </ div >
154
155 < script >
156 // captions.mjs injects the engine's scene-aware groups + real duration here.
157 var GROUPS = [];
158 var DURATION = 0 ;
159
160 ( function () {
161 var stage = document. getElementById ( "caption-stage" );
162
163 // build DOM: one .caption-group per group, .caption-word per word
164 GROUPS . forEach ( function ( group , g ) {
165 var groupEl = document. createElement ( "div" );
166 groupEl.className = "caption-group" ;
167 groupEl.id = "caption-group-" + g;
168 var pill = document. createElement ( "div" );
169 pill.className = "caption-pill" ;
170 var line = document. createElement ( "div" );
171 line.className = "caption-line" ;
172 (group.words || []). forEach ( function ( w , i ) {
173 var span = document. createElement ( "span" );
174 span.className = "caption-word" ;
175 span.id = "caption-word-" + g + "-" + i;
176 span.textContent = String (w.text);
177 line. appendChild (span);
178 });
179 pill. appendChild (line);
180 groupEl. appendChild (pill);
181 stage. appendChild (groupEl);
182 });
183
184 window.__timelines = window.__timelines || {};
185 var tl = gsap. timeline ({ paused: true });
186
187 GROUPS . forEach ( function ( group , g ) {
188 var groupEl = document. getElementById ( "caption-group-" + g);
189 var words = group.words || [];
190 var next = GROUPS [g + 1 ];
191 var isLast = g === GROUPS . length - 1 ;
192 var start = Math. max ( 0 , Number (group.start));
193 var end = isLast ? DURATION : Math. min ( Number (next.start), Number (group.end) + 0.3 );
194 if (end <= start) end = start + 0.01 ;
195
196 // group on/off — exactly one group visible at a time
197 tl. set (groupEl, { opacity: 1 }, start);
198 tl. set (groupEl, { opacity: 0 }, end);
199
200 // 3-state karaoke via className SETS — seek-safe (gsap.set applies on the
201 // engine's frame-by-frame seek; .call callbacks would NOT fire).
202 words. forEach ( function ( w , i ) {
203 var el = document. getElementById ( "caption-word-" + g + "-" + i);
204 var at = Math. max (start, Number (w.start));
205 tl. set (el, { className: "caption-word" }, start); // upcoming (also resets on reverse-seek)
206 tl. set (el, { className: "caption-word is-active" }, at); // current
207 tl. fromTo (el, { scale: 0.92 }, { scale: 1 , duration: 0.18 , ease: "back.out(2)" }, at);
208 if (i + 1 < words. length ) {
209 var nextAt = Math. max (start, Number (words[i + 1 ].start));
210 tl. set (el, { className: "caption-word is-spoken" }, nextAt); // demote when next activates
211 }
212 });
213 if (words. length ) {
214 var lastEl = document. getElementById ( "caption-word-" + g + "-" + (words. length - 1 ));
215 var lastSpoken = Math. min (end, Number (words[words. length - 1 ].end) + 0.1 );
216 tl. set (lastEl, { className: "caption-word is-spoken" }, lastSpoken);
217 }
218 });
219
220 // full-span anchor so the sub-comp timeline spans the whole video
221 tl. to ({}, { duration: DURATION }, 0 );
222 window.__timelines[ "captions" ] = tl;
223 })();
224 </ script >