Skip to content

armgit / hypit

Public Imported from GitHub
0

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.

fix(caption): preserve timed units and question-led skill reading

kashorin3cc3a46b7585
diff --git a/packages/caption-fine/README.md b/packages/caption-fine/README.md
index e63bc230..57330b64 100644
--- a/packages/caption-fine/README.md
+++ b/packages/caption-fine/README.md
@@ -84,9 +84,7 @@ caption.primary {
The same Caption pipeline serves English and Chinese. Script emits English lexical words and
individual Han characters as Display Words; punctuation stays with its display word. Fine uses
-those units for timing, while authored Cues remain complete reading phrases. Step highlighting groups
-adjacent units that form a word in the displayed Cue, using `Intl.Segmenter`; the underlying Script
-units and measured times stay intact. This grouping affects emphasis, not authored Cue boundaries.
+those units for timing and active Paint, while authored Cues remain complete reading phrases.
Dual Text retains its complete alignment unit even when it displays or speaks several words.
`word-gap` applies between Latin words and at Chinese/Latin boundaries. Adjacent Han characters and
@@ -103,18 +101,18 @@ font fallbacks supply the required glyphs; the layout does not select a font by
Both count limits are omitted above so the example flows by available width. For a compact
single-line treatment, author coherent Cues and choose a font, size and width that fit those Cues.
-`karaoke: off` keeps a complete Cue steady; `current` and `trail` follow speech timing, with step
-emphasis sharing one activation window across each detected word's units.
+`karaoke: off` keeps a complete Cue steady; `current` and `trail` follow its timed units, which are
+normally individual characters in Chinese.
| Effect | Recipe | Visible behavior |
| --- | --- | --- |
-| Whole-word emphasis | `karaoke: current; karaoke-transition: step` | The complete current word takes the active Paint at its first unit's start, returning to base Paint at the group's end. |
-| Accumulating emphasis | `karaoke: trail; karaoke-transition: step` | Each complete word takes the active Paint at its first unit's start and keeps it for the rest of the Cue. |
+| Whole-character emphasis | `karaoke: current; karaoke-transition: step` | The complete current unit takes the active Paint at its start, returning to base Paint at its end. |
+| Accumulating emphasis | `karaoke: trail; karaoke-transition: step` | Each complete unit takes the active Paint at its start and keeps it for the rest of the Cue. |
| Sweeping fill | `karaoke: trail; karaoke-transition: wipe` | Paint sweeps inside each unit's glyphs during that unit's own time window. |
| Spoken-unit appearance | `atom-reveal: on-start` | Each complete unit appears at its start. |
| Typing appearance | `atom-reveal: typewriter` | Whole graphemes appear in sequence within each unit, starting with its first grapheme at the unit's start. A normal Han unit appears as a complete character. |
-`step` is the default Karaoke transition. Choose it for ordinary whole-word highlighting;
+`step` is the default Karaoke transition. Choose it for ordinary Chinese character highlighting;
`wipe` deliberately produces partial glyph fills. Cue width and duration do not supply a substitute
clock for either mode. `atom-reveal` controls text appearing, independently of Karaoke recoloring
already visible text. A Dual Text span shares one timing unit, so its display words activate together
diff --git a/packages/caption-fine/src/karaoke.ts b/packages/caption-fine/src/karaoke.ts
deleted file mode 100644
index 7b4c9323..00000000
--- a/packages/caption-fine/src/karaoke.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import type { CaptionAlignmentUnit } from "@hypit/narrative";
-
-import { wordGaps } from "./spacing.js";
-
-type ActivationFrames = ReadonlyMap<string, { readonly start: number; readonly end: number }>;
-
-/**
- * Karaoke repaints one Alignment Unit at a time. A Unit is one lexical unit, and in Han, Hiragana
- * and Katakana that unit is a single character, so the highlight crawls character by character
- * across a word the reader takes in at once.
- *
- * Reading the Cue as prose recovers its words. `wordGaps` says which boundaries carry a space, so
- * the surfaces join back into exactly the prose the renderer draws, and the runtime's word
- * segmenter returns the words inside it. A word that covers several Units gives them one shared
- * activation window, so the whole word lights together.
- *
- * Only the window is shared. Layout, spacing, per-Unit motion and the CaptionDocument are the same
- * values they were, so speech tokens, authored markers and measured timing are untouched.
- *
- * Segmentation is advisory here: it decides which characters light together and nothing else. A
- * word the segmenter splits differently changes how the highlight steps, never the timing beneath
- * it. Scripts written without spaces that arrive as one Unit, such as Thai, Khmer and Lao, keep the
- * highlight they have, because a Unit is the smallest thing that carries a measured window and this
- * pass can join Units but cannot divide one.
- */
-const segmenter = new Intl.Segmenter(undefined, { granularity: "word" });
-
-export function karaokeWordActivation(
- atoms: readonly CaptionAlignmentUnit[],
- wordText: ReadonlyMap<string, string>,
- activation: ActivationFrames,
-): ActivationFrames {
- if (atoms.length < 2) return activation;
-
- const surfaces = atoms.map((atom) => atom.wordIds.map((wordId) => wordText.get(wordId) ?? "").join(""));
- const gaps = wordGaps(surfaces);
-
- let prose = "";
- const spans = surfaces.map((surface, index) => {
- if (gaps[index]) prose += " ";
- const start = prose.length;
- prose += surface;
- return { start, end: prose.length };
- });
-
- const merged = new Map(activation);
- for (const word of segmenter.segment(prose)) {
- if (!word.isWordLike) continue;
- const wordEnd = word.index + word.segment.length;
- const members = spans
- .map((span, index) => ({ span, index }))
- .filter(({ span }) => span.start < wordEnd && span.end > word.index)
- .map(({ index }) => index);
- if (members.length < 2) continue;
-
- let start = Number.POSITIVE_INFINITY;
- let end = Number.NEGATIVE_INFINITY;
- for (const member of members) {
- // The exclusive window already ends each Unit where the next one starts, so the run's own
- // bounds are the shared window. Read them from the incoming map: a Unit that two words touch
- // must not compound the widening.
- const timing = activation.get(atoms[member]!.id);
- if (timing === undefined) return activation;
- start = Math.min(start, timing.start);
- end = Math.max(end, timing.end);
- }
- for (const member of members) merged.set(atoms[member]!.id, { start, end });
- }
- return merged;
-}
diff --git a/packages/caption-fine/src/render.ts b/packages/caption-fine/src/render.ts
index 54106494..02ce6f02 100644
--- a/packages/caption-fine/src/render.ts
+++ b/packages/caption-fine/src/render.ts
@@ -20,7 +20,6 @@ import type { CanvasSpace, SpatialFrame, SpatialRegionTimeline } from "@hypit/sp
import { assertFineCaptionParameters, FINE_CAPTION_FAMILY } from "./style.js";
import { assertFineCaptionSchedule } from "./schedule.js";
-import { karaokeWordActivation } from "./karaoke.js";
import { joinSurfaces, uniformGap, wordGapBetween, wordGaps } from "./spacing.js";
import type {
FineCaptionActiveUnderline,
@@ -693,8 +692,7 @@ function cueElements(
})();
const cueMotion = cueAnimation(parameters, durationFrames);
const cueLoop = parameters.motion.loopTarget === "cue" ? loopAnimation(parameters, durationFrames) : undefined;
- const exclusiveFrames = exclusiveActivationFrames(atoms, atomFrames);
- const activationFrames = karaokeWordActivation(atoms, wordText, exclusiveFrames);
+ const activationFrames = exclusiveActivationFrames(atoms, atomFrames);
const gapPx = `${compactNumber(parameters.layout.wordGapPx)}px`;
const atomSurfaces = atoms.map((atom) => atom.wordIds.map((wordId) => wordText.get(wordId) ?? ""));
// A Cue whose boundaries all agree carries one `column-gap`, which is also what keeps a row that
@@ -846,8 +844,6 @@ function cueElements(
if (timing === undefined) throw new Error(`Fine Caption is missing timing for Atom ${atom.id}`);
const activationTiming = activationFrames.get(atom.id);
if (activationTiming === undefined) throw new Error(`Fine Caption is missing activation timing for Atom ${atom.id}`);
- const exclusiveTiming = exclusiveFrames.get(atom.id);
- if (exclusiveTiming === undefined) throw new Error(`Fine Caption is missing exclusive timing for Atom ${atom.id}`);
const atomId = `atom-${atomIndex + 1}`;
const surfaces = atomSurfaces[atomIndex] ?? [];
// The base glyphs and the activated copy stacked over them are laid out from this one list, so
@@ -949,9 +945,8 @@ function cueElements(
],
animation: activeBoxAnimation(
parameters,
- // The capsule marks the word being read, so it follows the word-grouped window.
- activationTiming.start,
- activationTiming.end,
+ parameters.activeBox.mode === "current" ? activationTiming.start : timing.start,
+ parameters.activeBox.mode === "current" ? activationTiming.end : timing.end,
durationFrames,
),
attributes: [{ name: "data-caption-active-box", value: "isolated" }],
@@ -1022,11 +1017,7 @@ function cueElements(
kind: "glyph" | "underline",
): void => {
const activeId = `${atomId}-${suffix}`;
- // The step paints one whole word, so it follows the word-grouped window in both modes. The
- // wipe travels across the letterforms of one Unit and keeps that Unit's own interval, with
- // `current` still owning its span exclusively.
- const wipes = kind === "glyph" && parameters.karaoke.transition === "wipe";
- const activeTiming = wipes ? (mode === "current" ? exclusiveTiming : timing) : activationTiming;
+ const activeTiming = mode === "current" ? activationTiming : timing;
push({
id: activeId,
parent: atomId,
@@ -1040,7 +1031,7 @@ function cueElements(
// clip has opened and this was still cutting the outline off at the glyph advance.
{ name: "position", value: "absolute" },
],
- animation: wipes
+ animation: kind === "glyph" && parameters.karaoke.transition === "wipe"
? karaokeWipeAnimation(parameters, mode, activeTiming.start, activeTiming.end, durationFrames)
: activationStepAnimation(mode, activeTiming.start, activeTiming.end, durationFrames),
attributes: [{ name: kind === "glyph" ? "data-caption-karaoke" : "data-caption-active-underline", value: mode }],
diff --git a/packages/caption-fine/test/caption-fine.test.ts b/packages/caption-fine/test/caption-fine.test.ts
index c0b2960b..75b3614b 100644
--- a/packages/caption-fine/test/caption-fine.test.ts
+++ b/packages/caption-fine/test/caption-fine.test.ts
@@ -329,15 +329,12 @@ function numericStyleAt(element: import("@hypit/composition").VisualElement, fra
}
for (const mode of ["current", "trail"] as const) {
- test(`Chinese ${mode} karaoke, underline and boxes light whole words across unequal times and pauses`, () => {
- const { track } = unevenChineseCaption({
+ test(`Chinese ${mode} karaoke, underline and boxes follow unequal character times and pauses`, () => {
+ const { track, windows } = unevenChineseCaption({
karaoke: mode, "active-underline": mode, "active-box": mode,
});
const present = track.presents[0]!;
- // `你真好看` reads as 你 / 真好 / 看, so the two characters of 真好 share one window covering
- // both of their measured intervals and the pause between them.
- const activations = [[10, 13], [13, 42], [13, 42], [42, 55]] as const;
- for (const [index, [start, end]] of activations.entries()) {
+ for (const [index, [start, end]] of windows.entries()) {
for (const suffix of ["active", "underline", "box"]) {
const element = present.elements.find((item) => item.id === `atom-${index + 1}-${suffix}`)!;
assert.ok(element);
diff --git a/skills/hypit/SKILL.md b/skills/hypit/SKILL.md
index 6c6fc7b6..bb53e900 100644
--- a/skills/hypit/SKILL.md
+++ b/skills/hypit/SKILL.md
@@ -235,9 +235,6 @@ practical, revisit that choice and carry the improvement into the work and its n
## Where the current question is answered
-Read the selected reference page in full so its judgment, usage and boundaries stay connected; follow
-additional routes as the current question requires.
-
| When the question is about | Read |
| --- | --- |
| how to express a work through materials, components and authored relationships, and how execution realizes it | `references/production/system.md` |
diff --git a/skills/hypit/references/playbooks/craft/captions.md b/skills/hypit/references/playbooks/craft/captions.md
index 78134988..8055821e 100644
--- a/skills/hypit/references/playbooks/craft/captions.md
+++ b/skills/hypit/references/playbooks/craft/captions.md
@@ -114,7 +114,7 @@ or quantity and unit together when separating them would make either screen stat
### Language changes the reading unit
English commonly uses a word as its smallest timed display unit; Chinese uses individual Han
-characters. That gives Chinese precise character timing, while a Cue still holds a meaningful
+characters. That gives Chinese precise character highlighting, while a Cue still holds a meaningful
phrase. A Chinese Cue can comfortably contain more characters than an English Cue contains words.
Choose its length from meaning, reading time and the space the actual font occupies. A fixed word
or character count cannot make that choice. Count the display side of Dual Text when judging fit.
@@ -127,16 +127,15 @@ or character count cannot make that choice. Count the display side of Dual Text
Fine already leaves adjacent Han characters together without English word gaps. Its `word-gap`
controls spaced boundaries, including Chinese/Latin transitions; `letter-spacing` adjusts tracking.
-The same timing supports a stable complete Cue, current-word color or a trail. For flowing
+The same timing supports a stable complete Cue, current-character color or a trail. For flowing
Chinese speech, a readable phrase with restrained emphasis often works better than a separate bounce
or reveal on every character. Choose the response for the performance's energy.
-For whole-word highlighting, use `karaoke: current` with `karaoke-transition: step`.
-Fine groups adjacent display units into words and lights their complete glyphs together from the
-first unit's time. Choose `trail` when already spoken words should stay highlighted. The grouping is
-a presentation choice; Script keeps its individual character times. `wipe` instead sweeps inside
-each unit's glyphs over that unit's speech window. Both use speech timing, including uneven delivery
-and pauses. Making a Cue longer changes its reading group, not the underlying character timing.
+For whole-character highlighting, use `karaoke: current` with `karaoke-transition: step`.
+Choose `trail` instead of `current` when the already spoken characters should stay highlighted.
+`step` activates the complete timed unit at its start; `wipe` is a different visual choice that
+sweeps inside its glyphs. Both follow each unit's own speech time, including uneven delivery and
+pauses. Making a Cue longer changes its reading group, not its character timing.
Text appearing and text changing color are separate choices. `atom-reveal: all` keeps the complete
Cue available to read while Karaoke supplies emphasis; `on-start` reveals whole spoken units, and