Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
fix(docs): cap word cue gap filling
rponeb736746bd325
diff --git a/docs/.vitepress/theme/components/SemanticVideoDemo.vue b/docs/.vitepress/theme/components/SemanticVideoDemo.vueindex b664a2a3..da94a0e7 100644--- a/docs/.vitepress/theme/components/SemanticVideoDemo.vue+++ b/docs/.vitepress/theme/components/SemanticVideoDemo.vue@@ -8,6 +8,7 @@ import {} from "./demo-audio";import { goodBetterBestMedia, resolveDemoMedia } from "./demo-media";import { demoPointerIsInside } from "./demo-pointer";+import { wordAtTime } from "./demo-word-timing";import {semanticVideoDemos,type DemoId,@@ -116,12 +117,7 @@ function setOverlayVideo(element: unknown, index: number) {}function wordAt(time: number) {- for (const [index, cue] of config.words.entries()) {- if (time >= cue.start && time < cue.end) return cue;- const nextStart = config.words[index + 1]?.start ?? config.duration;- if (time >= cue.end && time < Math.min(nextStart, cue.end + .09)) return cue;- }- return null;+ return wordAtTime(config.words, time);}const activeCaptionWords = computed(() => {diff --git a/docs/.vitepress/theme/components/SvmlPlayground.vue b/docs/.vitepress/theme/components/SvmlPlayground.vueindex 687ba8d0..5f2246de 100644--- a/docs/.vitepress/theme/components/SvmlPlayground.vue+++ b/docs/.vitepress/theme/components/SvmlPlayground.vue@@ -9,6 +9,7 @@ import {import { rankingMedia, resolveDemoMedia } from "./demo-media";import { demoPointerIsInside } from "./demo-pointer";import { createDemoTimeline } from "./demo-timeline";+import { wordAtTime } from "./demo-word-timing";import { wordCues as rawWordCues, type WordCue } from "./regen-ranking-cues";import {buildFoldedSourceView,@@ -271,12 +272,7 @@ const displayedLines = computed<DisplayedSourceLine[]>(() => {});function wordAt(time: number): WordCue | null {- for (const [index, cue] of wordCues.entries()) {- if (time >= cue.start && time < cue.end) return cue;- const nextStart = wordCues[index + 1]?.start ?? TOTAL_DURATION;- if (time >= cue.end && time < Math.min(nextStart, cue.end + .08)) return cue;- }- return null;+ return wordAtTime(wordCues, time);}const activeCaptionWords = computed(() => {diff --git a/docs/.vitepress/theme/components/demo-word-timing.ts b/docs/.vitepress/theme/components/demo-word-timing.tsnew file mode 100644index 00000000..b17b1b63--- /dev/null+++ b/docs/.vitepress/theme/components/demo-word-timing.ts@@ -0,0 +1,19 @@+export type TimedWordCue = {+ start: number;+ end: number;+};++export const MAX_WORD_GAP_FILL = .5;++export function wordAtTime<T extends TimedWordCue>(words: readonly T[], time: number): T | null {+ for (const [index, cue] of words.entries()) {+ const nextStart = words[index + 1]?.start;+ const effectiveEnd = nextStart !== undefined && nextStart > cue.end+ ? Math.min(nextStart, cue.end + MAX_WORD_GAP_FILL)+ : cue.end;++ if (time >= cue.start && time < effectiveEnd) return cue;+ }++ return null;+}diff --git a/test/docs-demo-word-timing.test.ts b/test/docs-demo-word-timing.test.tsnew file mode 100644index 00000000..8fddb12c--- /dev/null+++ b/test/docs-demo-word-timing.test.ts@@ -0,0 +1,32 @@+import assert from "node:assert/strict";+import test from "node:test";+import {+ MAX_WORD_GAP_FILL,+ wordAtTime,+} from "../docs/.vitepress/theme/components/demo-word-timing";++const words = [+ { text: "previous", start: 0, end: 1 },+ { text: "next", start: 1.4, end: 2 },+];++test("keeps the previous docs demo word active until the next word starts", () => {+ assert.equal(wordAtTime(words, 1.2)?.text, "previous");+ assert.equal(wordAtTime(words, 1.399)?.text, "previous");+ assert.equal(wordAtTime(words, 1.4)?.text, "next");+});++test("does not extend the final word without a following word", () => {+ assert.equal(wordAtTime(words, 2.01), null);+});++test("caps gap filling during a real pause", () => {+ const wordsWithPause = [+ { text: "before", start: 0, end: 1 },+ { text: "after", start: 2, end: 2.5 },+ ];++ assert.equal(wordAtTime(wordsWithPause, 1 + MAX_WORD_GAP_FILL - .001)?.text, "before");+ assert.equal(wordAtTime(wordsWithPause, 1 + MAX_WORD_GAP_FILL), null);+ assert.equal(wordAtTime(wordsWithPause, 2)?.text, "after");+});