mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 18:26:17 +00:00
* fix(ci): allowlist the build-script consolidation in the no-main-deletions guard build-audio-fx-runtime.ts and build-position-edits-render.ts were merged into build-inline-artifact.ts to kill a fallow duplication finding; the deletion guard flagged that as an accidental loss since main still has both originals. * fix(core): dedupe the wet/dry mix math between delayFeedback and chorusLfo Both effect builders set wet.gain to the mix and dry.gain to its complement in identical two-line blocks; fallow kept re-flagging it as a 10-line clone on every unrelated change. Extracted setWetDryMix. * fix(core): remove the build-audio-fx-runtime.ts stray resurrected by a main merge An earlier merge with main brought this deleted file back (git's merge/delete handling on an unchanged-on-one-side file); package.json already points at build-inline-artifact.ts, so it sat unreachable and duplicating that file's config, both of which fallow flagged. * fix(studio): pull TimelineLanes under the 600-line cap TimelineLanes.tsx hit 620 lines. Extracted the three per-clip pointer gestures (resize-start, pointer-down move-arm, click/razor-split) into createClipGestureHandlers — one factory call per rendered clip instead of ~120 lines of inline handler bodies in the render loop. 529 lines now. * fix(studio): split the extracted pointerdown handler under the CRAP threshold Moving the ~120-line gesture logic into timelineClipGestureHandlers.ts concentrated it into two functions fallow flagged (onPointerDown at CRAP 63.6, onResizeStart at 31.6). Split the decision logic (which gesture a pointerdown implies) into a pure resolvePointerDownAction, then split its own intent-blocking check into isIntentBlocked. onResizeStart's guard moved into canStartResize. Every function now scores under 30. * fix(studio): drop the unused DomEditSelection import in PropertyPanelFlat CI caught it on PR #3026 (wa-12-panel-params); a later refactor in the stack removed the last use of the type here without removing the import. * fix(studio): close the typecheck and fallow gaps wa-18b-reschedule opened useAutomationLanes.ts's write() assumed gesture-scoped coalescing and a preview-only commit that useDomEditAttributeCommits.ts never grew — backported that option support from its own later commit so the two sides of the API agree. The paste path and its tests were missing the box selection's v0/v1 bounds a sibling commit added to AutomationSelection. The FX panel's carve controls still edited the six mechanism numbers (maxCutDb, bands, intelligibilityBias) after carveProfile() collapsed authoring to one Strength knob, so those fields no longer existed on HfCarveSettings; UI now edits strength, and analyseCarveBands is called with carveProfile(strength). Also closes fallow's complexity, dead-code and duplication findings on this PR's diff: extracted automationLaneDragMath.ts (pure group/point-move math) and useAutomationRangeDrag.ts (the marquee-select gesture) out of useAutomationLaneGestures.ts, pulled a couple of render-loop ternaries and a resolver into named functions, dropped an export nothing outside its file used, and shared a step-simplifier between audioCarve's two envelope builders. The edge-stretch vs. box-select priority test in TimelineAutomationLane.test was still pinning the pre-box-select rule (edge wins over a point sitting on it) that a sibling commit deliberately reversed — a point inside the box is now selected content, so grabbing it drags the group instead. Updated the test to the shipped rule instead of the old one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(core): cap the via conic's weight so an edge-clamped via point can't NaN A via point pulled out past the segment (viaX: 5, viaY: -3) clamps to (0.999, 0.001) — exactly on the steady region's edge, where edge - viaX is 0. viaConic divided by that zero to get an infinite weight, and shapeVia turned Infinity into NaN a few steps later (Infinity - Infinity in the quadratic coefficient). NaN reaching setValueCurveAtTime silences the automated parameter for the rest of the render. Capped the weight at 1e6 instead of leaving it unbounded — past that point the arc already reads as touching the via point, so nothing visible is lost. Also hardened shapeVia's existing denominator guard (`<= 0`) to `!(> 0)`, since NaN fails the original comparison and fell through it. Review by Miga (PR #3208). * fix(studio-server): fingerprint the proactive waveform cache key too The route already keys the waveform cache on the asset's size and mtime as well as its path, so a rebuilt-in-place file gets fresh peaks instead of stale ones. generateWaveformCache — the proactive path that runs on upload — still called buildWaveformCacheKey with the path alone, so it wrote to a different key than the route reads from (making the pre-generated cache never found) and kept the exact collision bug this fingerprint exists to fix on its own path. Review by Miga (PR #3211). * style(docs): run oxfmt on the /hyperframes-audio skill docs Table column widths had drifted out of alignment with oxfmt's own rules, failing format:check and blocking the Preflight gate every downstream branch inherits. Whitespace only, no content change. * fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration \b treats `_` as a word character, so \bbed\b never matched bed_01, music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap — an underscore-separated bed classified as "unknown" and could end up offered as its own carve source. Replaced the short hints with a boundary that actually excludes letters and digits on both sides. clipsOverlap computed end = start + duration without guarding sign, so a negative duration put end before start — an interval that does not describe anything, and one specific case showed it silently dropping a real overlap (a shorter, earlier broken end rejected a clip that genuinely contained the point). Duration clamps to zero instead: a clip cannot un-play time, and a zero-length clip at its start is the sane reading of "duration nobody wrote down as positive." Review by Miga (PR #3212). * fix(studio): widen PropertyPanel's resetModules render timeout again The 20s margin (already once widened for the same reason) is timing out in CI's full-monorepo Test run — the resetModules()+fresh-import render this test needs is uncached and competes with every other package's test suite for the same worker pool, and the same test passes in well under 2s standalone. Went to 45s rather than re-tuning to whatever number happens to clear the current CI load, since that number moves every time CI gains a package. * fix(studio): stop the single-candidate auto-apply carve firing twice Two auto-apply effects both fire when sourceOptions.length === 1: the multi-candidate effect only guards length === 0, so a single candidate passes it too, and the single-candidate effect passes its own guard right after — both compute the same sources list and both call setCarve, so the common case (one narrator, one bed) triggered two decodes, two FFT runs, and two concurrent attribute writes for one decision. The multi-candidate effect now defers to its sibling for exactly one candidate, which already has its own detailed handling for that case. Review by Miga (PR #3213). * feat(core): carve against every voice over a bed, always (#3212) * feat(core): carve against every voice over a bed, always dynamically A bed usually runs under a whole sequence — a narrator, an interview answer, a second presenter — and carving against one of them left the others fighting it. `source` becomes `sources`, and `mixCarveSources` sums every voice onto the BED's clock before anything is measured. That is what keeps one analysis sufficient: the chain is fixed, so there is no per-voice filter to switch between, and bands drawn from all the speech there is with envelopes that rise wherever any of it happens answer the actual question — where and when is speech masking this bed. Summed rather than averaged: two people talking at once mask more than either alone. Audio before the bed starts is dropped rather than folded in at zero, since it plays over nothing and shifting it would put a cut where there is no voice. `dynamic` is gone. A fixed depth thins the bed through every pause, and once both have been heard there is no reason to want it, so every carve follows the speech. Two helpers the panel and the headless script now share instead of each carrying a copy — two definitions of "what does this name suggest" drift, and then the two disagree about which track is the voice: - `classifyAudioName` reads a track's kind from its id and filename together. `unknown` is deliberately common: treating an unrecognised name as "not a voice" would hide the one track somebody needs to pick. - `clipsOverlap` keeps out a voice that never plays while the bed does. An unwritten duration counts as unbounded, not zero — refusing a clip whose length the composition leaves to the media would drop the commonest case there is. Files written before this still load: a single `source` reads as a one-voice list, a stored `dynamic` is ignored, and an absent attribute means the defaults whole. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(core): stop \b from missing underscore-separated names, guard clipsOverlap's negative duration \b treats `_` as a word character, so \bbed\b never matched bed_01, music_bed_loop, or theme_song, and \bvo\b/\bvox\b/\btts\b had the same gap — an underscore-separated bed classified as "unknown" and could end up offered as its own carve source. Replaced the short hints with a boundary that actually excludes letters and digits on both sides. clipsOverlap computed end = start + duration without guarding sign, so a negative duration put end before start — an interval that does not describe anything, and one specific case showed it silently dropping a real overlap (a shorter, earlier broken end rejected a clip that genuinely contained the point). Duration clamps to zero instead: a clip cannot un-play time, and a zero-length clip at its start is the sane reading of "duration nobody wrote down as positive." Review by Miga (PR #3212). --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(studio): port the carve UI off the removed source/dynamic fields #3212 (accidentally squash-merged into this branch instead of main) changed HfCarveSettings from a single `source` + `dynamic` toggle to a `sources` list with dynamic mode removed outright — the multi-voice UI consumer that goes with that shape lands in the very next PR, so this branch was left with a type that no longer matched its own code. Minimal port, not the multi-voice redesign that PR does properly: the "Listen to" picker and analyse() treat sources[0] as the one voice this UI still understands, and every dynamic-mode branch (the automated envelope lanes, the toggle, the checkbox) is gone along with the field — a carve is now always the static value the analysis computes, matching what the type change made permanent. Test suite trimmed the same way: the automation-lane and toggle tests covered behavior that no longer exists. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
629 lines
23 KiB
TypeScript
629 lines
23 KiB
TypeScript
// @vitest-environment happy-dom
|
|
|
|
import React, { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import type { GsapAnimation, PropertyGroupName } from "@hyperframes/core/gsap-parser";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { TimelinePropertyLanes } from "./TimelinePropertyLanes";
|
|
import { TimelineTrackHeader } from "./TimelineTrackHeader";
|
|
import { defaultTimelineTheme } from "./timelineTheme";
|
|
import type { TimelineElement } from "../store/playerStore";
|
|
import type { TimelineEditCallbacks } from "./timelineCallbacks";
|
|
import { getTimelineLaneTop, LABEL_COL_W } from "./timelineLayout";
|
|
import { AUTOMATION_LANE_H } from "./automationLaneHeight";
|
|
|
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = "";
|
|
});
|
|
|
|
const ELEMENT: TimelineElement = {
|
|
id: "clip-1",
|
|
label: "Hero card",
|
|
tag: "div",
|
|
start: 0,
|
|
duration: 2,
|
|
track: 0,
|
|
};
|
|
|
|
function animation(
|
|
id: string,
|
|
propertyGroup: PropertyGroupName,
|
|
keyframes: Array<{
|
|
percentage: number;
|
|
properties: Record<string, number | string>;
|
|
ease?: string;
|
|
}>,
|
|
): GsapAnimation {
|
|
return {
|
|
id,
|
|
targetSelector: "#clip-1",
|
|
method: "to",
|
|
position: 0,
|
|
duration: 2,
|
|
properties: {},
|
|
propertyGroup,
|
|
keyframes: { format: "percentage", keyframes },
|
|
};
|
|
}
|
|
|
|
const POSITION = animation("position-tween", "position", [
|
|
{ percentage: 0, properties: { x: 0, y: 0 } },
|
|
{ percentage: 50, properties: { x: 100, y: 50 } },
|
|
{ percentage: 100, properties: { x: 200, y: 100 } },
|
|
]);
|
|
|
|
const OPACITY = animation("opacity-tween", "visual", [
|
|
{ percentage: 0, properties: { opacity: 0 } },
|
|
{ percentage: 50, properties: { opacity: 0.5 } },
|
|
{ percentage: 100, properties: { opacity: 1 } },
|
|
]);
|
|
|
|
interface RenderHeaderOptions {
|
|
keyframeClip?: TimelineElement;
|
|
/** Every clip on the track; defaults to just the keyframe clip. */
|
|
trackElements?: readonly TimelineElement[];
|
|
animations?: GsapAnimation[];
|
|
clipCount?: number;
|
|
currentTime?: number;
|
|
expanded?: boolean;
|
|
onSeek?: (time: number) => void;
|
|
onTogglePropertyGroupKeyframe?: TimelineEditCallbacks["onTogglePropertyGroupKeyframe"];
|
|
onToggleTrackHidden?: TimelineEditCallbacks["onToggleTrackHidden"];
|
|
onRemoveAutomationLane?: (target: string) => void;
|
|
}
|
|
|
|
function renderHeader(options: RenderHeaderOptions = {}): {
|
|
host: HTMLDivElement;
|
|
root: Root;
|
|
rerender: (next: RenderHeaderOptions) => void;
|
|
} {
|
|
const host = document.createElement("div");
|
|
document.body.append(host);
|
|
const root = createRoot(host);
|
|
const render = (next: RenderHeaderOptions) => {
|
|
act(() => {
|
|
root.render(
|
|
<TimelineTrackHeader
|
|
// A real fractional z-order sort key, so a label built from it would
|
|
// read out "track 0.16666666666666666".
|
|
trackNumber={1 / 6}
|
|
trackDisplayNumber={1}
|
|
trackLabel="Hero card"
|
|
lanesId="timeline-lanes-track-0"
|
|
contentOrigin={LABEL_COL_W}
|
|
keyframeClip={next.keyframeClip ?? ELEMENT}
|
|
trackElements={next.trackElements ?? [next.keyframeClip ?? ELEMENT]}
|
|
clipCount={next.clipCount ?? 1}
|
|
isExpanded={next.expanded !== false}
|
|
animations={next.animations ?? [POSITION, OPACITY]}
|
|
currentTime={next.currentTime ?? 0}
|
|
isTrackHidden={false}
|
|
isAudioTrack={false}
|
|
theme={defaultTimelineTheme}
|
|
onToggleClipExpanded={vi.fn()}
|
|
onToggleTrackHidden={next.onToggleTrackHidden ?? vi.fn()}
|
|
onTogglePropertyGroupKeyframe={next.onTogglePropertyGroupKeyframe}
|
|
onRemoveAutomationLane={next.onRemoveAutomationLane}
|
|
onSeek={next.onSeek}
|
|
/>,
|
|
);
|
|
});
|
|
};
|
|
render(options);
|
|
return { host, root, rerender: render };
|
|
}
|
|
|
|
function click(host: HTMLElement, label: string) {
|
|
const button = host.querySelector<HTMLButtonElement>(`button[aria-label="${label}"]`);
|
|
expect(button).not.toBeNull();
|
|
act(() => button?.click());
|
|
}
|
|
|
|
describe("TimelineTrackHeader", () => {
|
|
// An expanded sub-composition child sits on the MASTER timeline at a
|
|
// host-absolute start, but its tweens are parsed from its own file and are
|
|
// local to it. Feeding the raw start straight into the clip-% math put every
|
|
// lane keyframe far outside the clip.
|
|
it("keeps an expanded sub-comp child's lane percentages inside the clip", () => {
|
|
const child: TimelineElement = {
|
|
id: "pill",
|
|
tag: "div",
|
|
start: 16.5,
|
|
duration: 2,
|
|
track: 0,
|
|
expandedParentStart: 16,
|
|
sourceFile: "scene.html",
|
|
};
|
|
const local: GsapAnimation = {
|
|
id: "pill-tween",
|
|
targetSelector: "#pill",
|
|
method: "to",
|
|
position: 0.5,
|
|
resolvedStart: 0.5,
|
|
duration: 2,
|
|
properties: {},
|
|
propertyGroup: "position",
|
|
keyframes: {
|
|
format: "percentage",
|
|
keyframes: [
|
|
{ percentage: 0, properties: { x: 0 } },
|
|
{ percentage: 100, properties: { x: 100 } },
|
|
],
|
|
},
|
|
};
|
|
// Playhead at the clip's midpoint (master time), so the 100% keyframe is
|
|
// ahead of it. On the raw host-absolute basis every keyframe rebased to a
|
|
// large negative percentage and nothing was ever ahead of the playhead.
|
|
const view = renderHeader({
|
|
keyframeClip: child,
|
|
animations: [local],
|
|
currentTime: 17.5,
|
|
});
|
|
|
|
expect(
|
|
view.host.querySelector<HTMLButtonElement>('button[aria-label="Next Position keyframe"]')
|
|
?.disabled,
|
|
).toBe(false);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
// The header shows one clip's lanes, so how many clips the track holds is
|
|
// otherwise invisible from the label column. A single-clip track stays silent.
|
|
it("shows the track's clip count only once the track holds more than one clip", () => {
|
|
const view = renderHeader({ clipCount: 1 });
|
|
expect(view.host.querySelector('[aria-label="1 clips"]')).toBeNull();
|
|
|
|
view.rerender({ clipCount: 3 });
|
|
expect(view.host.querySelector('[aria-label="3 clips"]')?.textContent).toBe("3");
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
// The eye acts on the layer, so it has to be reachable without a pointer and
|
|
// in every disclosure state — a hover-gated eye is unusable by keyboard.
|
|
it("keeps the visibility eye mounted whether the layer is expanded or collapsed", () => {
|
|
const view = renderHeader({ expanded: true });
|
|
expect(view.host.querySelector('button[aria-label="Hide track 1"]')).not.toBeNull();
|
|
|
|
view.rerender({ expanded: false });
|
|
expect(view.host.querySelector('button[aria-label="Hide track 1"]')).not.toBeNull();
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
// trackNumber is a fractional z-order sort key, so building the label from it
|
|
// made screen readers announce "Hide track 0.16666666666666666". The display
|
|
// number is label-only; the toggle still routes by the real key.
|
|
it("announces the display track number but toggles with the real fractional key", () => {
|
|
const onToggleTrackHidden = vi.fn();
|
|
const view = renderHeader({ onToggleTrackHidden });
|
|
const eye = view.host.querySelector<HTMLButtonElement>('button[aria-label="Hide track 1"]');
|
|
|
|
expect(eye).not.toBeNull();
|
|
expect(eye?.title).toBe("Hide track 1");
|
|
expect(view.host.innerHTML).not.toContain("0.16666666666666666");
|
|
|
|
act(() => eye?.click());
|
|
expect(onToggleTrackHidden).toHaveBeenCalledWith(1 / 6, true);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("adds and removes a keyframe on the explicitly targeted property-group tween", () => {
|
|
const onTogglePropertyGroupKeyframe = vi.fn();
|
|
const view = renderHeader({ currentTime: 0.5, onTogglePropertyGroupKeyframe });
|
|
|
|
click(view.host, "Add Opacity keyframe");
|
|
expect(onTogglePropertyGroupKeyframe).toHaveBeenLastCalledWith(
|
|
ELEMENT,
|
|
expect.objectContaining({
|
|
animationId: "opacity-tween",
|
|
propertyGroup: "visual",
|
|
tweenPercentage: 25,
|
|
properties: { opacity: 0.25 },
|
|
remove: false,
|
|
}),
|
|
);
|
|
|
|
view.rerender({ currentTime: 1, onTogglePropertyGroupKeyframe });
|
|
click(view.host, "Remove Opacity keyframe");
|
|
expect(onTogglePropertyGroupKeyframe).toHaveBeenLastCalledWith(
|
|
ELEMENT,
|
|
expect.objectContaining({
|
|
animationId: "opacity-tween",
|
|
propertyGroup: "visual",
|
|
tweenPercentage: 50,
|
|
properties: { opacity: 0.5 },
|
|
remove: true,
|
|
}),
|
|
);
|
|
expect(onTogglePropertyGroupKeyframe).not.toHaveBeenCalledWith(
|
|
ELEMENT,
|
|
expect.objectContaining({ animationId: "position-tween" }),
|
|
);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("seeks only to the selected group's adjacent keyframes", () => {
|
|
const onSeek = vi.fn();
|
|
const view = renderHeader({
|
|
currentTime: 1,
|
|
animations: [
|
|
POSITION,
|
|
animation("opacity-tween", "visual", [
|
|
{ percentage: 25, properties: { opacity: 0.25 } },
|
|
{ percentage: 50, properties: { opacity: 0.5 } },
|
|
{ percentage: 75, properties: { opacity: 0.75 } },
|
|
]),
|
|
],
|
|
onSeek,
|
|
});
|
|
|
|
click(view.host, "Next Position keyframe");
|
|
expect(onSeek).toHaveBeenLastCalledWith(2);
|
|
click(view.host, "Previous Position keyframe");
|
|
expect(onSeek).toHaveBeenLastCalledWith(0);
|
|
expect(onSeek).not.toHaveBeenCalledWith(1.5);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
// The lane header sits inside the track row, whose own click handler selects
|
|
// the track. Every control in the label column has to own its click, or
|
|
// seeking to a keyframe also reselects whatever is behind the header.
|
|
it("keeps lane-header control clicks off the ancestor track row", () => {
|
|
const onAncestorClick = vi.fn();
|
|
const view = renderHeader({
|
|
currentTime: 1,
|
|
onSeek: vi.fn(),
|
|
onTogglePropertyGroupKeyframe: vi.fn(),
|
|
});
|
|
// React 18 delegates from the root container, so an ancestor of it is where
|
|
// a leaked click actually shows up.
|
|
document.body.addEventListener("click", onAncestorClick);
|
|
|
|
// Every control in the lane's label column, found by row rather than by
|
|
// label, so a wording change to one button can't silently drop it here.
|
|
const controls = view.host.querySelectorAll<HTMLButtonElement>(
|
|
'[data-property-group="position"] button',
|
|
);
|
|
expect(controls.length).toBeGreaterThanOrEqual(3);
|
|
for (const button of controls) {
|
|
act(() => {
|
|
button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
});
|
|
}
|
|
|
|
document.body.removeEventListener("click", onAncestorClick);
|
|
expect(onAncestorClick).not.toHaveBeenCalled();
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("fills the toggle diamond exactly at that group's keyframe", () => {
|
|
const view = renderHeader({ currentTime: 0.5 });
|
|
const positionToggle = view.host.querySelector<HTMLButtonElement>(
|
|
'button[aria-label="Add Position keyframe"]',
|
|
);
|
|
expect(positionToggle?.textContent).toBe("◇");
|
|
|
|
view.rerender({ currentTime: 1 });
|
|
expect(
|
|
view.host.querySelector<HTMLButtonElement>('button[aria-label="Remove Position keyframe"]')
|
|
?.textContent,
|
|
).toBe("◆");
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("updates formatted group values when the playhead moves", () => {
|
|
const view = renderHeader({ currentTime: 0.5 });
|
|
expect(view.host.querySelector('[data-property-group="position"]')?.textContent).toContain(
|
|
"50, 25",
|
|
);
|
|
expect(view.host.querySelector('[data-property-group="visual"]')?.textContent).toContain("25%");
|
|
|
|
view.rerender({ currentTime: 1.5 });
|
|
expect(view.host.querySelector('[data-property-group="position"]')?.textContent).toContain(
|
|
"150, 75",
|
|
);
|
|
expect(view.host.querySelector('[data-property-group="visual"]')?.textContent).toContain("75%");
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("samples mid-segment values along the segment's ease, not linearly", () => {
|
|
// GSAP hangs a segment's ease on the keyframe it arrives at, so 0% -> 50%
|
|
// runs power2.in. Half way through that segment power2.in(0.5) = 0.125, so
|
|
// the readout is 12.5/6.25 and NOT the linear 50/25.
|
|
const eased = animation("eased-position", "position", [
|
|
{ percentage: 0, properties: { x: 0, y: 0 } },
|
|
{ percentage: 50, properties: { x: 100, y: 50 }, ease: "power2.in" },
|
|
{ percentage: 100, properties: { x: 200, y: 100 }, ease: "power2.in" },
|
|
]);
|
|
const onTogglePropertyGroupKeyframe = vi.fn();
|
|
const view = renderHeader({
|
|
animations: [eased],
|
|
currentTime: 0.5,
|
|
onTogglePropertyGroupKeyframe,
|
|
});
|
|
|
|
expect(view.host.querySelector('[data-property-group="position"]')?.textContent).toContain(
|
|
"12.5, 6.25",
|
|
);
|
|
|
|
// The same sampled value is what an added keyframe gets stamped with, so a
|
|
// header insert lands on the existing curve instead of deforming it.
|
|
click(view.host, "Add Position keyframe");
|
|
expect(onTogglePropertyGroupKeyframe).toHaveBeenCalledOnce();
|
|
expect(onTogglePropertyGroupKeyframe.mock.calls[0][1]).toMatchObject({
|
|
properties: { x: 12.5, y: 6.25 },
|
|
});
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("disables the previous chevron at or before the group's first keyframe", () => {
|
|
const view = renderHeader({ currentTime: 0 });
|
|
const prevAt0 = view.host.querySelector<HTMLButtonElement>(
|
|
'button[aria-label="Previous Position keyframe"]',
|
|
);
|
|
expect(prevAt0).not.toBeNull();
|
|
expect(prevAt0?.disabled).toBe(true);
|
|
|
|
view.rerender({ currentTime: 1 });
|
|
const prevAt1 = view.host.querySelector<HTMLButtonElement>(
|
|
'button[aria-label="Previous Position keyframe"]',
|
|
);
|
|
expect(prevAt1?.disabled).toBe(false);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
it("uses the same lane row offsets when collapsed, expanded once, and expanded multiple times", () => {
|
|
const view = renderHeader({ expanded: false });
|
|
expect(view.host.querySelectorAll("[data-timeline-lane-top]")).toHaveLength(0);
|
|
|
|
const assertAligned = (animations: GsapAnimation[]) => {
|
|
view.rerender({ animations });
|
|
const lanesHost = document.createElement("div");
|
|
document.body.append(lanesHost);
|
|
const lanesRoot = createRoot(lanesHost);
|
|
act(() => {
|
|
lanesRoot.render(
|
|
<TimelinePropertyLanes
|
|
id="timeline-property-lanes-alignment-test"
|
|
animations={animations}
|
|
clipStart={0}
|
|
clipDuration={2}
|
|
clipLeftPx={120}
|
|
clipWidthPx={200}
|
|
accentColor="#3CE6AC"
|
|
isSelected
|
|
currentPercentage={0}
|
|
elementId="clip-1"
|
|
selectedKeyframes={new Set()}
|
|
/>,
|
|
);
|
|
});
|
|
expect(
|
|
Array.from(view.host.querySelectorAll<HTMLElement>("[data-timeline-lane-top]")).map(
|
|
(row) => row.style.top,
|
|
),
|
|
).toEqual(
|
|
Array.from(lanesHost.querySelectorAll<HTMLElement>("[data-timeline-lane-top]")).map(
|
|
(row) => row.style.top,
|
|
),
|
|
);
|
|
expect(
|
|
Array.from(lanesHost.querySelectorAll<HTMLElement>("[data-timeline-property-lane]")).map(
|
|
(row) => row.style.left,
|
|
),
|
|
).toEqual(animations.map(() => "120px"));
|
|
act(() => lanesRoot.unmount());
|
|
};
|
|
|
|
assertAligned([POSITION]);
|
|
assertAligned([POSITION, OPACITY]);
|
|
act(() => view.root.unmount());
|
|
});
|
|
|
|
/**
|
|
* Automation lanes are named in the label column, on the same tree as the
|
|
* keyframe rows — not painted inside the lane, where the name sat on top of
|
|
* the envelope it belonged to and scrolled away from its own row.
|
|
*/
|
|
describe("audio automation rows", () => {
|
|
const BED: TimelineElement = {
|
|
id: "bed",
|
|
label: "Music Bed",
|
|
tag: "audio",
|
|
start: 0,
|
|
duration: 10,
|
|
track: 0,
|
|
fxChain: JSON.stringify({
|
|
version: 1,
|
|
nodes: [{ type: "peaking", id: "n1", params: { frequency: 1600, gain: -6, q: 1.4 } }],
|
|
}),
|
|
automation: JSON.stringify({
|
|
version: 1,
|
|
lanes: [
|
|
{
|
|
target: "volume",
|
|
points: [
|
|
{ t: 0, v: 1 },
|
|
{ t: 5, v: 0.4 },
|
|
],
|
|
},
|
|
{
|
|
target: "fx.n1.gain",
|
|
points: [
|
|
{ t: 0, v: 0 },
|
|
{ t: 5, v: -6 },
|
|
],
|
|
},
|
|
],
|
|
}),
|
|
} as TimelineElement;
|
|
|
|
it("names every envelope in the label column", () => {
|
|
const { host, root } = renderHeader({ keyframeClip: BED, animations: [] });
|
|
const rows = Array.from(host.querySelectorAll<HTMLElement>("[data-automation-lane-label]"));
|
|
// The attribute is the ROW's identity, which is the label: a row can hold
|
|
// several clips' envelopes, whose lane targets differ from each other.
|
|
expect(rows.map((r) => r.getAttribute("data-automation-lane-label"))).toEqual([
|
|
"Peaking EQ 1.6 kHz · Gain",
|
|
"Volume",
|
|
]);
|
|
// A band is named by its frequency: with several of them, "Peaking EQ" says
|
|
// nothing about which is which. Bands sit above the level lanes.
|
|
// Two lines per row: what the effect is, then which knob the envelope
|
|
// drives. One line truncated mid-word in a column this narrow.
|
|
expect(rows.map((r) => r.querySelector("[data-automation-lane-name]")?.textContent)).toEqual([
|
|
"Peaking EQ 1.6 kHz",
|
|
"Volume",
|
|
]);
|
|
expect(rows.map((r) => r.querySelector("[data-automation-lane-param]")?.textContent)).toEqual(
|
|
[
|
|
"Gain",
|
|
// Volume has no effect behind it, so it has no second line at all.
|
|
undefined,
|
|
],
|
|
);
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("hides them when the track is collapsed", () => {
|
|
const { host, root } = renderHeader({
|
|
keyframeClip: BED,
|
|
animations: [],
|
|
expanded: false,
|
|
});
|
|
expect(host.querySelectorAll("[data-automation-lane-label]")).toHaveLength(0);
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("removes just that envelope from the label column", () => {
|
|
// The panel's automate toggle can only reach a parameter it still shows; a
|
|
// carve's own lanes are not in it at all, so without this an envelope could
|
|
// be created and never deleted.
|
|
const onRemoveAutomationLane = vi.fn();
|
|
const { host, root } = renderHeader({
|
|
keyframeClip: BED,
|
|
animations: [],
|
|
onRemoveAutomationLane,
|
|
});
|
|
const button = host.querySelector<HTMLButtonElement>(
|
|
'button[aria-label="Remove Peaking EQ 1.6 kHz · Gain automation"]',
|
|
);
|
|
expect(button).not.toBeNull();
|
|
act(() => button?.click());
|
|
expect(onRemoveAutomationLane).toHaveBeenCalledWith("fx.n1.gain");
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("offers no remove button when the lanes are read-only", () => {
|
|
const { host, root } = renderHeader({ keyframeClip: BED, animations: [] });
|
|
expect(host.querySelectorAll('button[aria-label$="automation"]')).toHaveLength(0);
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("stacks each envelope's row where its lane is drawn", () => {
|
|
// Same rhythm the canvas uses: automation begins below the keyframe lanes
|
|
// and steps by its own taller row height.
|
|
const { host, root } = renderHeader({ keyframeClip: BED, animations: [OPACITY] });
|
|
const tops = Array.from(
|
|
host.querySelectorAll<HTMLElement>("[data-automation-lane-label]"),
|
|
).map((r) => r.style.top);
|
|
const base = getTimelineLaneTop(1);
|
|
expect(tops).toEqual([`${base}px`, `${base + AUTOMATION_LANE_H}px`]);
|
|
act(() => root.unmount());
|
|
});
|
|
});
|
|
|
|
/**
|
|
* Several clips on one row share a lane row per property, so the label column
|
|
* has to name the row for the property and the header for the track — not for
|
|
* whichever clip happens to be selected.
|
|
*/
|
|
describe("a track several clips share", () => {
|
|
const clip = (id: string, over: Partial<TimelineElement>): TimelineElement =>
|
|
({
|
|
id,
|
|
key: id,
|
|
label: id,
|
|
tag: "audio",
|
|
start: 0,
|
|
duration: 4,
|
|
track: 0,
|
|
...over,
|
|
}) as TimelineElement;
|
|
const PEAKING = (gain: number) =>
|
|
JSON.stringify({
|
|
version: 1,
|
|
nodes: [{ type: "peaking", id: "n1", params: { frequency: 1000, gain, q: 1.4 } }],
|
|
});
|
|
const NARRATION_1 = clip("narration-1", {
|
|
fxChain: PEAKING(-3),
|
|
automation: JSON.stringify({
|
|
version: 1,
|
|
lanes: [{ target: "fx.n1.gain", points: [{ t: 0, v: -3 }] }],
|
|
}),
|
|
});
|
|
const NARRATION_2 = clip("narration-2", {
|
|
start: 4,
|
|
fxChain: PEAKING(-6),
|
|
automation: JSON.stringify({
|
|
version: 1,
|
|
lanes: [
|
|
{ target: "fx.n1.gain", points: [{ t: 0, v: -6 }] },
|
|
{ target: "volume", points: [{ t: 0, v: 1 }] },
|
|
],
|
|
}),
|
|
});
|
|
const ROW = { trackElements: [NARRATION_1, NARRATION_2], clipCount: 2, animations: [] };
|
|
|
|
it("lists every clip's envelopes, whichever clip is selected", () => {
|
|
const labels = (host: HTMLElement) =>
|
|
Array.from(host.querySelectorAll("[data-automation-lane-label]")).map((r) =>
|
|
r.getAttribute("data-automation-lane-label"),
|
|
);
|
|
const first = renderHeader({ ...ROW, keyframeClip: NARRATION_1 });
|
|
const second = renderHeader({ ...ROW, keyframeClip: NARRATION_2 });
|
|
// narration-1 has no volume envelope, but the row is still there — it is
|
|
// the track's, and it was its sibling's before the selection moved.
|
|
expect(labels(first.host)).toEqual(["Peaking EQ 1 kHz · Gain", "Volume"]);
|
|
expect(labels(second.host)).toEqual(labels(first.host));
|
|
act(() => first.root.unmount());
|
|
act(() => second.root.unmount());
|
|
});
|
|
|
|
it("removes only from the clip it is showing, and offers nothing where it has no lane", () => {
|
|
// A write can only reach the selected clip, so a button on a row that clip
|
|
// is absent from could only remove nothing, or somebody else's envelope.
|
|
const onRemoveAutomationLane = vi.fn();
|
|
const { host, root } = renderHeader({
|
|
...ROW,
|
|
keyframeClip: NARRATION_1,
|
|
onRemoveAutomationLane,
|
|
});
|
|
expect(
|
|
Array.from(host.querySelectorAll('button[aria-label$="automation"]')).map((b) =>
|
|
b.getAttribute("aria-label"),
|
|
),
|
|
).toEqual(["Remove Peaking EQ 1 kHz · Gain automation"]);
|
|
act(() => host.querySelector<HTMLButtonElement>('button[aria-label$="automation"]')?.click());
|
|
expect(onRemoveAutomationLane).toHaveBeenCalledWith("fx.n1.gain");
|
|
act(() => root.unmount());
|
|
});
|
|
|
|
it("names the header for the track, not for one of the clips on it", () => {
|
|
const view = renderHeader({ ...ROW, keyframeClip: NARRATION_2 });
|
|
expect(view.host.textContent).not.toContain("narration-2");
|
|
expect(view.host.querySelector('[title="Track 1"]')?.textContent).toBe("Track 1");
|
|
// Alone on the track it is still named for itself.
|
|
view.rerender({
|
|
...ROW,
|
|
keyframeClip: NARRATION_2,
|
|
trackElements: [NARRATION_2],
|
|
clipCount: 1,
|
|
});
|
|
expect(view.host.querySelector('[title="narration-2"]')?.textContent).toBe("narration-2");
|
|
act(() => view.root.unmount());
|
|
});
|
|
});
|
|
});
|