MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / clampDurations

Function clampDurations

packages/core/src/compiler/timingCompiler.ts:267–285  ·  view source on GitHub ↗
(html: string, clamps: ResolvedDuration[])

Source from the content-addressed store, hash-verified

265 * and recomputes data-end accordingly.
266 */
267export function clampDurations(html: string, clamps: ResolvedDuration[]): string {
268 for (const { id, duration } of clamps) {
269 const idPattern = new RegExp(`(<[^>]*id=["']${escapeRegex(id)}["'][^>]*>)`, "gi");
270
271 html = html.replace(idPattern, (tag) => {
272 // Replace data-duration value
273 tag = tag.replace(/data-duration=["'][^"']*["']/, `data-duration="${duration}"`);
274
275 // Recompute data-end from data-start + clamped duration
276 const startStr = getAttr(tag, "data-start");
277 const start = startStr ? parseFloat(startStr) : 0;
278 tag = tag.replace(/data-end=["'][^"']*["']/, `data-end="${start + duration}"`);
279
280 return tag;
281 });
282 }
283
284 return html;
285}

Callers 3

compileHtmlFileFunction · 0.90
compileHtmlFunction · 0.90

Calls 2

getAttrFunction · 0.85
escapeRegexFunction · 0.70

Tested by

no test coverage detected