Skip to content

Write HTML. Render video. Built for agents.

fix(studio): keep a clip in sync when its head is trimmed at non-1x speed (#4581)

Miguel Ángelb3ab28aa443e
diff --git a/packages/studio-server/src/helpers/sourceMutation.ts b/packages/studio-server/src/helpers/sourceMutation.ts
index 2fc8240a2f..bd7a5f9a2b 100644
--- a/packages/studio-server/src/helpers/sourceMutation.ts
+++ b/packages/studio-server/src/helpers/sourceMutation.ts
@@ -402,12 +402,13 @@ export function splitElementInHtml(
? "data-media-start"
: null;
if (playbackStartAttr) {
- const currentTrim =
- parseFloat(el.getAttribute(playbackStartAttr) ?? "") || fallbackTiming?.playbackStart || 0;
+ const authoredTrim = parseFloat(el.getAttribute(playbackStartAttr) ?? "");
+ const currentTrim = authoredTrim || fallbackTiming?.playbackStart || 0;
const rateRaw = parseFloat(el.getAttribute("data-playback-rate") ?? "");
const rate =
Number.isFinite(rateRaw) && rateRaw > 0 ? rateRaw : (fallbackTiming?.playbackRate ?? 1);
- el.setAttribute(playbackStartAttr, String(Math.round(currentTrim * 1000) / 1000));
+ if (authoredTrim !== currentTrim)
+ el.setAttribute(playbackStartAttr, String(Math.round(currentTrim * 1000) / 1000));
clone.setAttribute(
playbackStartAttr,
String(Math.round((currentTrim + firstDuration * rate) * 1000) / 1000),
diff --git a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
index 967d9f1be2..639f63c505 100644
--- a/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
+++ b/packages/studio-server/src/helpers/sourceMutationSplitAndGroup.test.ts
@@ -161,6 +161,15 @@ describe("splitElementInHtml", () => {
expect(document.getElementById("media-split")?.getAttribute("data-media-start")).toBe("4");
});
+ it("leaves the first half's authored in-point exactly as written", () => {
+ const mediaSource = `<!DOCTYPE html><html><body><div data-composition-id="root"><video id="media" class="clip" src="asset.mp4" data-start="1" data-duration="6" data-media-start="3.296375" data-playback-rate="0.25"></video></div></body></html>`;
+
+ const result = splitElementInHtml(mediaSource, { id: "media" }, 3, "media-split");
+ const { document } = parseHTML(result.html);
+
+ expect(document.getElementById("media")?.getAttribute("data-media-start")).toBe("3.296375");
+ });
+
it("does not add a media in-point to non-media elements", () => {
const result = splitElementInHtml(source, { id: "box" }, 3, "box-split");
diff --git a/packages/studio/src/hooks/timelineEditingHelpers.test.ts b/packages/studio/src/hooks/timelineEditingHelpers.test.ts
index a579a28d19..085469d83d 100644
--- a/packages/studio/src/hooks/timelineEditingHelpers.test.ts
+++ b/packages/studio/src/hooks/timelineEditingHelpers.test.ts
@@ -3,6 +3,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import {
applyTimelineStackingReorder,
buildTimelineMoveTimingPatch,
+ buildTimelineResizeTimingPatch,
deleteSelectedKeyframes,
extendRootDurationIfNeeded,
patchIframeDomTiming,
@@ -230,6 +231,19 @@ describe("extendRootDurationIfNeeded", () => {
});
});
+describe("buildTimelineResizeTimingPatch", () => {
+ it("moves a source-only in-point by the caller's own start change", () => {
+ const source = `<div id="root"><video id="a" class="clip" data-start="5" data-duration="3" data-media-start="0.337"></video></div>`;
+ const element = el({ id: "a", tag: "video", domId: "a", start: 5, duration: 3 });
+ const patched = buildTimelineResizeTimingPatch(source, { id: "a" }, element, {
+ start: 3,
+ duration: 5,
+ playbackStart: undefined,
+ });
+ expect(patched).toContain('data-media-start="0"');
+ });
+});
+
describe("persistTimelineBatchEdit", () => {
const SOURCE = `<div id="root"><video id="a" class="clip" data-start="1" data-track-index="0"></video><video id="b" class="clip" data-start="2" data-track-index="1"></video></div>`;
diff --git a/packages/studio/src/hooks/timelineEditingHelpers.ts b/packages/studio/src/hooks/timelineEditingHelpers.ts
index 328f7bc996..69e2d9294a 100644
--- a/packages/studio/src/hooks/timelineEditingHelpers.ts
+++ b/packages/studio/src/hooks/timelineEditingHelpers.ts
@@ -8,6 +8,7 @@ import {
} from "../utils/sourcePatcher";
import {
formatTimelineAttributeNumber,
+ formatTimelineMediaOffset,
type TimelineStackingReorderIntent,
} from "../player/components/timelineEditing";
import { getElementZIndex } from "../player/lib/layerOrdering";
@@ -284,7 +285,7 @@ export function buildTimelineResizeTimingPatch(
patched = applyPatchByTarget(patched, target, {
type: "attribute",
property: pbs.attrName,
- value: formatTimelineAttributeNumber(pbs.value),
+ value: formatTimelineMediaOffset(pbs.value),
});
}
// Content-driven duration from the PATCHED SOURCE (raw data-duration) —
@@ -426,7 +427,7 @@ export function readTargetAttribute(
return readAttributeByTarget(html, patchTarget, attr) ?? null;
}
-export { applyPatchByTarget, formatTimelineAttributeNumber };
+export { applyPatchByTarget, formatTimelineAttributeNumber, formatTimelineMediaOffset };
export { patchDocumentRootDuration } from "./timelineEditingGsap";
diff --git a/packages/studio/src/hooks/useTimelineEditing.ts b/packages/studio/src/hooks/useTimelineEditing.ts
index e15cae8ce8..245ea62534 100644
--- a/packages/studio/src/hooks/useTimelineEditing.ts
+++ b/packages/studio/src/hooks/useTimelineEditing.ts
@@ -11,6 +11,7 @@ import {
playbackStartAttributeForElement,
persistTimelineEdit,
formatTimelineAttributeNumber,
+ formatTimelineMediaOffset,
extendRootDurationIfNeeded,
buildTimelineMoveTimingPatch,
buildTimelineResizeTimingPatch,
@@ -313,7 +314,7 @@ export function useTimelineEditing({
];
if (updates.playbackStart != null) {
const liveAttr = playbackStartAttributeForElement(element);
- liveAttrs.push([liveAttr, formatTimelineAttributeNumber(updates.playbackStart)]);
+ liveAttrs.push([liveAttr, formatTimelineMediaOffset(updates.playbackStart)]);
}
patchIframeDomTiming(previewIframeRef.current, element, liveAttrs, activeCompPath);
// Snapshot the duration BEFORE the optimistic updates below so a failed
diff --git a/packages/studio/src/hooks/useTimelineGroupEditing.ts b/packages/studio/src/hooks/useTimelineGroupEditing.ts
index 17da428e3c..5b1a051277 100644
--- a/packages/studio/src/hooks/useTimelineGroupEditing.ts
+++ b/packages/studio/src/hooks/useTimelineGroupEditing.ts
@@ -13,6 +13,7 @@ import {
buildTimelineResizeTimingPatch,
extendRootDurationIfNeeded,
formatTimelineAttributeNumber,
+ formatTimelineMediaOffset,
patchIframeDomTiming,
playbackStartAttributeForElement,
persistTimelineBatchEdit,
@@ -377,7 +378,7 @@ export function useTimelineGroupEditing({
];
if (change.playbackStart != null) {
const liveAttr = playbackStartAttributeForElement(change.element);
- liveAttrs.push([liveAttr, formatTimelineAttributeNumber(change.playbackStart)]);
+ liveAttrs.push([liveAttr, formatTimelineMediaOffset(change.playbackStart)]);
}
patchIframeDomTiming(previewIframeRef.current, change.element, liveAttrs, activeCompPath);
}
diff --git a/packages/studio/src/player/components/timelineClipDragPreview.test.ts b/packages/studio/src/player/components/timelineClipDragPreview.test.ts
index 346770f9d0..6285510c3a 100644
--- a/packages/studio/src/player/components/timelineClipDragPreview.test.ts
+++ b/packages/studio/src/player/components/timelineClipDragPreview.test.ts
@@ -291,6 +291,47 @@ describe("computeResizePreview — composition source continuity", () => {
previewPlaybackStart: 2,
});
});
+
+ it("does not let a tail snap shrink a clip below the drag's minimum duration", () => {
+ const result = computeResizePreview(
+ {
+ element: clip("vo", 0, 2, 1, 0),
+ edge: "end",
+ originClientX: 0,
+ previewStart: 2,
+ previewDuration: 1,
+ started: true,
+ },
+ -95,
+ { scroll: fakeScroll(), pps: 100, buildSnapTargets: () => [{ time: 2.07, type: "beat" }] },
+ );
+
+ expect(result).toMatchObject({ previewDuration: 0.1, snapTime: null });
+ });
+
+ it("keeps a slowed clip's media clock when its head snaps to a beat", () => {
+ const element = { ...clip("vo", 0, 2, 4, 0), playbackStart: 3, playbackRate: 0.8 };
+ const result = computeResizePreview(
+ {
+ element,
+ edge: "start",
+ originClientX: 0,
+ previewStart: 2,
+ previewDuration: 4,
+ started: true,
+ },
+ 30,
+ {
+ scroll: fakeScroll(),
+ pps: 100,
+ buildSnapTargets: () => [{ time: 2.3456, type: "beat" }],
+ },
+ );
+
+ expect(result.snapTime).toBe(2.3456);
+ const clock = result.previewStart - result.previewPlaybackStart! / 0.8;
+ expect(clock).toBeCloseTo(2 - 3 / 0.8, 9);
+ });
});
describe("getTimelineDragOverlayPosition", () => {
diff --git a/packages/studio/src/player/components/timelineClipDragPreview.ts b/packages/studio/src/player/components/timelineClipDragPreview.ts
index a53f7e8764..61a7dd85fd 100644
--- a/packages/studio/src/player/components/timelineClipDragPreview.ts
+++ b/packages/studio/src/player/components/timelineClipDragPreview.ts
@@ -1,4 +1,9 @@
import { resolveTimelineMove, resolveTimelineResize } from "./timelineEditing";
+import {
+ applyClipStartTrimDelta,
+ clipStartTrimDeltaBounds,
+ resolveTimelineMinDuration,
+} from "./timelineGroupEditing";
import type { TimelineElement } from "../store/playerStore";
import {
getTimelineInsertBoundaryBand,
@@ -275,7 +280,6 @@ export function computeResizePreview(
const normalizedTag = resize.element.tag.toLowerCase();
const canSeedPlaybackStart =
resize.element.kind === "composition" || normalizedTag === "audio" || normalizedTag === "video";
- const playbackRate = Math.max(resize.element.playbackRate ?? 1, 0.1);
// Trim limit = available source media only — NOT the composition length.
// Duration is content-driven (the comp grows/shrinks to fit on commit), so
// capping a trim at the current comp end both blocked extending the last clip
@@ -319,35 +323,22 @@ export function computeResizePreview(
// Stay within [start+minDuration, maxEnd] so the snap can't create a
// degenerate clip or run past the source/composition limit.
const snappedDuration = Math.round((snapped - nextResize.start) * 1000) / 1000;
- if (target && snapped <= maxEnd + 1e-6 && snappedDuration >= 0.05) {
+ if (
+ target &&
+ snapped <= maxEnd + 1e-6 &&
+ snappedDuration >= resolveTimelineMinDuration() - 1e-6
+ ) {
// An edge already on the target still owns the guide; only move it when off.
if (snapped !== edgeTime) nextResize = { ...nextResize, duration: snappedDuration };
snap = target;
}
} else {
const { time: snapped, target } = snapTimelineTime(nextResize.start, trimTargets, snapSecs);
- const delta = nextResize.start - snapped; // >0 when snapping left
- // Leftward snap reveals more source; cap so playbackStart can't go < 0.
- const maxLeftDelta =
- nextResize.playbackStart != null
- ? nextResize.playbackStart / playbackRate
- : Number.POSITIVE_INFINITY;
- // Also require the resulting duration to stay >= minDuration so a rightward
- // snap (delta < 0) can't collapse the clip to zero/negative.
- const snappedDuration = Math.round((nextResize.duration + delta) * 1000) / 1000;
- if (target && snapped >= 0 && delta <= maxLeftDelta + 1e-6 && snappedDuration >= 0.05) {
- if (snapped !== nextResize.start) {
- nextResize = {
- ...nextResize,
- start: snapped,
- duration: snappedDuration,
- playbackStart:
- nextResize.playbackStart != null
- ? Math.round(Math.max(0, nextResize.playbackStart - delta * playbackRate) * 1000) /
- 1000
- : undefined,
- };
- }
+ const clip = { ...nextResize, playbackRate: resize.element.playbackRate };
+ const delta = snapped - nextResize.start;
+ const bounds = clipStartTrimDeltaBounds(clip, 0, resolveTimelineMinDuration());
+ if (target && delta >= bounds.minDelta - 1e-6 && delta <= bounds.maxDelta + 1e-6) {
+ if (snapped !== nextResize.start) nextResize = applyClipStartTrimDelta(clip, delta);
snap = target;
}
}
diff --git a/packages/studio/src/player/components/timelineEditing.test.ts b/packages/studio/src/player/components/timelineEditing.test.ts
index 49757c2eb9..c0fed7ffb7 100644
--- a/packages/studio/src/player/components/timelineEditing.test.ts
+++ b/packages/studio/src/player/components/timelineEditing.test.ts
@@ -5,6 +5,8 @@ import {
buildTimelineElementAgentPrompt,
buildTimelineAgentPrompt,
clampTimelineGroupResizeDelta,
+ formatTimelineAttributeNumber,
+ formatTimelineMediaOffset,
getTimelineEditCapabilities,
hasPatchableTimelineTarget,
resolveBlockedTimelineEditIntent,
@@ -366,6 +368,15 @@ describe("resolveTimelineGroupResize", () => {
],
});
});
+
+ it("derives a slowed member's playback start from its rounded start", () => {
+ const [member] = resolveTimelineGroupResize(
+ [{ start: 2, duration: 3, playbackStart: 1, playbackRate: 0.8 }],
+ "start",
+ 0.373,
+ ).members;
+ expect(member!.start - member!.playbackStart! / 0.8).toBeCloseTo(2 - 1 / 0.8, 9);
+ });
});
describe("hasPatchableTimelineTarget", () => {
@@ -795,7 +806,7 @@ describe("resolveTimelineResize", () => {
"start",
0,
),
- ).toEqual({ start: 0.8, duration: 3.2, playbackStart: 0 });
+ ).toEqual({ start: 0.8, duration: 3.2, playbackStart: expect.closeTo(0, 9) });
});
it("trims generic element start without media offset", () => {
@@ -831,6 +842,93 @@ describe("resolveTimelineResize", () => {
),
).toEqual({ start: 0, duration: 4, playbackStart: undefined });
});
+
+ it("rounds a fully-left head trim inward so the in-point is never clamped off the media clock", () => {
+ const next = resolveTimelineResize(
+ {
+ start: 2,
+ duration: 3,
+ originClientX: 0,
+ pixelsPerSecond: 100,
+ minStart: 0,
+ maxEnd: 10,
+ playbackStart: 1,
+ playbackRate: 1.5,
+ },
+ "start",
+ -1000,
+ );
+ expect(next.start).toBe(1.34);
+ expect(next.start - next.playbackStart! / 1.5).toBeCloseTo(2 - 1 / 1.5, 9);
+ });
+
+ it("lets a fully-left head trim reach a reloaded in-point's media start at a 5-decimal speed", () => {
+ const next = resolveTimelineResize(
+ {
+ start: 2.37,
+ duration: 2.63,
+ originClientX: 0,
+ pixelsPerSecond: 100,
+ minStart: 0,
+ maxEnd: 10,
+ playbackStart: Number(formatTimelineMediaOffset(0.37 * 0.33333)),
+ playbackRate: 0.33333,
+ },
+ "start",
+ -1000,
+ );
+ expect(next.start).toBe(2);
+ });
+
+ it("moves every group member by the same amount when one reaches its media start", () => {
+ const members = [
+ { start: 2, duration: 3, playbackStart: 1, playbackRate: 1.5 },
+ { start: 5, duration: 3, playbackStart: 4, playbackRate: 1 },
+ ];
+ const result = resolveTimelineGroupResize(members, "start", -10);
+ for (const [i, member] of members.entries()) {
+ const next = result.members[i]!;
+ expect(next.start - member.start).toBeCloseTo(result.delta, 9);
+ expect(next.start - next.playbackStart! / member.playbackRate).toBeCloseTo(
+ member.start - member.playbackStart / member.playbackRate,
+ 9,
+ );
+ }
+ });
+
+ it("keeps a clip's media clock and end fixed across repeated head trims at any speed", () => {
+ const dragsPx = [37.3, -12.9, 81.7, -5.3];
+ for (const playbackRate of [0.25, 0.5, 0.8, 1, 1.25, 2]) {
+ let clip = { start: 2, duration: 6, playbackStart: 3 };
+ const clock = clip.start - clip.playbackStart / playbackRate;
+ const end = clip.start + clip.duration;
+ for (const clientX of dragsPx) {
+ const next = resolveTimelineResize(
+ {
+ ...clip,
+ originClientX: 0,
+ pixelsPerSecond: 100,
+ minStart: 0,
+ maxEnd: 20,
+ playbackRate,
+ },
+ "start",
+ clientX,
+ );
+ // Round-trip through the saved attributes, as a reload would.
+ const savedInPoint = formatTimelineMediaOffset(next.playbackStart!);
+ if (playbackRate === 1)
+ expect(savedInPoint).toBe(formatTimelineAttributeNumber(next.playbackStart!));
+ clip = {
+ start: Number(formatTimelineAttributeNumber(next.start)),
+ duration: Number(formatTimelineAttributeNumber(next.duration)),
+ playbackStart: Number(savedInPoint),
+ };
+ expect(clip.start - clip.playbackStart / playbackRate).toBeCloseTo(clock, 9);
+ expect(clip.start + clip.duration).toBeCloseTo(end, 9);
+ }
+ }
+ });
});
describe("buildPromptCopyText", () => {
diff --git a/packages/studio/src/player/components/timelineEditing.ts b/packages/studio/src/player/components/timelineEditing.ts
index 5ceb30c2bc..b46dfca590 100644
--- a/packages/studio/src/player/components/timelineEditing.ts
+++ b/packages/studio/src/player/components/timelineEditing.ts
@@ -236,14 +236,7 @@ export function resolveTimelineResize(
const { minDelta, maxDelta } = clipStartTrimDeltaBounds(input, input.minStart, minDuration);
const clampedDelta = clamp(deltaTime, minDelta, maxDelta);
- const trimmed = applyClipStartTrimDelta(input, clampedDelta);
-
- return {
- start: roundToCentiseconds(trimmed.start),
- duration: roundToCentiseconds(trimmed.duration),
- playbackStart:
- trimmed.playbackStart != null ? roundToCentiseconds(trimmed.playbackStart) : undefined,
- };
+ return applyClipStartTrimDelta(input, clampedDelta);
}
export interface TimelinePromptElement {
@@ -476,6 +469,10 @@ export function formatTimelineAttributeNumber(value: number): string {
return Number(roundToCentiseconds(value).toFixed(2)).toString();
}
+export function formatTimelineMediaOffset(value: number): string {
+ return Number(value.toFixed(6)).toString();
+}
+
/**
* Apply one edge auto-scroll step: scroll `scroll` toward the edge zone the
* pointer is in, clamped to the scrollable range. Returns true when the
diff --git a/packages/studio/src/player/components/timelineGroupEditing.test.ts b/packages/studio/src/player/components/timelineGroupEditing.test.ts
index 71437e14cf..64c4fde4ef 100644
--- a/packages/studio/src/player/components/timelineGroupEditing.test.ts
+++ b/packages/studio/src/player/components/timelineGroupEditing.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import type { TimelineElement } from "../store/playerStore";
import {
+ applyTimelineGroupResizePreview,
buildTimelineGroupResizeMembers,
resolveTimelineGroupResize,
resolveTimelineGroupResizeChanges,
@@ -132,3 +133,29 @@ describe("resolveTimelineGroupResizeChanges (rigid group patch set)", () => {
).toEqual(raw.members);
});
});
+
+describe("applyTimelineGroupResizePreview", () => {
+ it("keeps each slowed member's media clock through the group preview", () => {
+ const a = el("a", { start: 2, duration: 3, playbackStart: 1, playbackRate: 0.8 });
+ const b = el("b", { start: 6, duration: 3, playbackStart: 2, playbackRate: 1.25 });
+ const members = buildTimelineGroupResizeMembers([a, b], keys("a", "b"), "a", "start")!;
+ const session = {
+ grabbedKey: "a",
+ edge: "start" as const,
+ members,
+ changes: [],
+ hasChanged: false,
+ };
+
+ applyTimelineGroupResizePreview(session, { previewStart: 2.373, previewDuration: 2.627 });
+
+ for (const [i, member] of [a, b].entries()) {
+ const change = session.changes[i]!;
+ const rate = member.playbackRate!;
+ expect(change.start - change.playbackStart! / rate).toBeCloseTo(
+ member.start - member.playbackStart! / rate,
+ 9,
+ );
+ }
+ });
+});
diff --git a/packages/studio/src/player/components/timelineGroupEditing.ts b/packages/studio/src/player/components/timelineGroupEditing.ts
index e5ec36d7ca..1da7ae5779 100644
--- a/packages/studio/src/player/components/timelineGroupEditing.ts
+++ b/packages/studio/src/player/components/timelineGroupEditing.ts
@@ -13,6 +13,12 @@ function roundTimelineTime(value: number): number {
return roundToCenti(value);
}
+const SAVED_MEDIA_OFFSET_TOLERANCE = 1e-5;
+
+function ceilTimelineTime(value: number): number {
+ return Math.ceil((value - SAVED_MEDIA_OFFSET_TOLERANCE) * 100) / 100;
+}
+
export function resolveTimelineMinDuration(minDuration?: number): number {
return Math.max(ABSOLUTE_TIMELINE_MIN_DURATION, minDuration ?? DEFAULT_TIMELINE_MIN_DURATION);
}
@@ -33,7 +39,7 @@ interface TimelineStartTrimClip {
* Delta bounds for trimming a clip's START edge (shared by single-clip and group
* resize). Left-bounded by how far the start can move toward `minStart` and by the
* media in-point (`playbackStart / playbackRate`); right-bounded by `minDuration`.
- * Returned deltas are unrounded — callers round with their own centisecond helper.
+ * Returned deltas are unrounded; applyClipStartTrimDelta does the rounding.
*/
export function clipStartTrimDeltaBounds(
clip: TimelineStartTrimClip,
@@ -50,21 +56,24 @@ export function clipStartTrimDeltaBounds(
}
/**
- * Apply a start-edge delta to one clip (unrounded): moves the start, shrinks the
- * duration by the same amount, and shifts the media in-point by the delta scaled to
- * the playback rate (clamped at 0).
+ * Apply a start-edge delta to one clip: rounds the start once, keeps the end fixed,
+ * and derives the media in-point from the rounded start (clamped at 0), so the media
+ * clock `start - playbackStart / playbackRate` survives any number of head trims.
*/
export function applyClipStartTrimDelta(
clip: TimelineStartTrimClip,
delta: number,
): { start: number; duration: number; playbackStart?: number } {
const playbackRate = resolveTimelinePlaybackRate(clip.playbackRate);
+ const mediaZero =
+ clip.playbackStart != null ? clip.start - clip.playbackStart / playbackRate : -Infinity;
+ const start = Math.max(roundTimelineTime(clip.start + delta), ceilTimelineTime(mediaZero));
return {
- start: clip.start + delta,
- duration: clip.duration - delta,
+ start,
+ duration: roundTimelineTime(clip.start + clip.duration - start),
playbackStart:
clip.playbackStart != null
- ? Math.max(0, clip.playbackStart + delta * playbackRate)
+ ? Math.max(0, clip.playbackStart + (start - clip.start) * playbackRate)
: undefined,
};
}
@@ -126,7 +135,7 @@ export function clampTimelineGroupResizeDelta(
// Rigid group: the applied delta is bounded by the most-constrained member.
const bounds = members.map((member) => clipStartTrimDeltaBounds(member, 0, minDuration));
- const minDelta = Math.max(...bounds.map((b) => b.minDelta));
+ const minDelta = ceilTimelineTime(Math.max(...bounds.map((b) => b.minDelta)));
const maxDelta = Math.min(...bounds.map((b) => b.maxDelta));
return roundTimelineTime(clamp(rawDelta, minDelta, maxDelta));
}
@@ -149,13 +158,7 @@ export function resolveTimelineGroupResize(
};
}
- const trimmed = applyClipStartTrimDelta(member, delta);
- return {
- start: roundTimelineTime(trimmed.start),
- duration: roundTimelineTime(trimmed.duration),
- playbackStart:
- trimmed.playbackStart != null ? roundTimelineTime(trimmed.playbackStart) : undefined,
- };
+ return applyClipStartTrimDelta(member, delta);
}),
};
}
diff --git a/packages/studio/src/player/lib/timelineDOM.test.ts b/packages/studio/src/player/lib/timelineDOM.test.ts
index ebb9ba2b6e..7bba705d81 100644
--- a/packages/studio/src/player/lib/timelineDOM.test.ts
+++ b/packages/studio/src/player/lib/timelineDOM.test.ts
@@ -20,6 +20,32 @@ function makeDoc(html: string): Document {
return d;
}
+describe("parseTimelineFromDOM — media in-point", () => {
+ it("reads a negative in-point as 0, as the runtime does, so a head trim keeps the clip", () => {
+ const doc = makeDoc(`
+ <div data-composition-id="root">
+ <video id="v" class="clip" data-start="2" data-duration="1" data-media-start="-1"></video>
+ </div>
+ `);
+ const element = parseTimelineFromDOM(doc, 10).find((e) => e.domId === "v")!;
+ expect(element.playbackStart).toBe(0);
+
+ const preview = computeResizePreview(
+ {
+ element,
+ edge: "start",
+ originClientX: 0,
+ previewStart: 2,
+ previewDuration: 1,
+ started: true,
+ },
+ 10,
+ { scroll: null, pps: 100, buildSnapTargets: () => [] },
+ );
+ expect(preview.previewDuration).toBe(0.9);
+ });
+});
+
describe("parseTimelineFromDOM — hfId from data-hf-id", () => {
it("bridges a real GSAP transition marker onto both named clips", () => {
document.body.innerHTML = `
diff --git a/packages/studio/src/player/lib/timelineElementHelpers.ts b/packages/studio/src/player/lib/timelineElementHelpers.ts
index 2589b11768..a83ade9874 100644
--- a/packages/studio/src/player/lib/timelineElementHelpers.ts
+++ b/packages/studio/src/player/lib/timelineElementHelpers.ts
@@ -13,6 +13,7 @@ import { isFinitePositive } from "./playbackAdapter";
import { getSourceScopedSelectorIndex } from "../../utils/sourceScopedSelectorIndex";
import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
import { readElementFades } from "@hyperframes/core/audio-fade";
+import { readMediaOffsetSeconds } from "@hyperframes/parsers/media-duration";
// ---------------------------------------------------------------------------
// Layer-reveal lift transparency
@@ -171,10 +172,8 @@ function applyPlaybackMetadataFromElement(entry: TimelineElement, el: Element):
const playbackStartValue = el.getAttribute("data-playback-start");
const legacyMediaStartValue = el.getAttribute("data-media-start");
const mediaStartValue = playbackStartValue ?? legacyMediaStartValue;
- if (mediaStartValue != null) {
- const playbackStart = parseFloat(mediaStartValue);
- if (Number.isFinite(playbackStart)) entry.playbackStart = playbackStart;
- }
+ if (mediaStartValue != null)
+ entry.playbackStart = readMediaOffsetSeconds((n) => el.getAttribute(n));
if (playbackStartValue != null) entry.playbackStartAttr = "playback-start";
else if (legacyMediaStartValue != null) entry.playbackStartAttr = "media-start";