mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-25 07:16:02 +00:00
normalizeRegionSpan can return end > totalMs in a valid input path. File: src/components/video-editor/timeline/core/spans.ts:15-20
This commit is contained in:
@@ -20,7 +20,7 @@ describe("timeline core/spans", () => {
|
||||
it("clamps start when requested end exceeds total", () => {
|
||||
expect(
|
||||
normalizeRegionSpan({ startMs: 980, endMs: 1200, totalMs: 1000, minDurationMs: 100 }),
|
||||
).toEqual({ start: 900, end: 1080 });
|
||||
).toEqual({ start: 900, end: 1000 });
|
||||
});
|
||||
|
||||
it("keeps already valid spans unchanged", () => {
|
||||
@@ -28,4 +28,10 @@ describe("timeline core/spans", () => {
|
||||
normalizeRegionSpan({ startMs: 100, endMs: 300, totalMs: 1000, minDurationMs: 50 }),
|
||||
).toEqual({ start: 100, end: 300 });
|
||||
});
|
||||
|
||||
it("never exceeds total when min duration is larger than total", () => {
|
||||
expect(
|
||||
normalizeRegionSpan({ startMs: 100, endMs: 300, totalMs: 80, minDurationMs: 100 }),
|
||||
).toEqual({ start: 0, end: 80 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,11 +11,14 @@ export function normalizeRegionSpan(params: {
|
||||
minDurationMs: number;
|
||||
}) {
|
||||
const { startMs, endMs, totalMs, minDurationMs } = params;
|
||||
const clampedStart = Math.max(0, Math.min(startMs, totalMs));
|
||||
const minEnd = clampedStart + minDurationMs;
|
||||
const clampedEnd = Math.min(totalMs, Math.max(minEnd, endMs));
|
||||
const normalizedStart = Math.max(0, Math.min(clampedStart, totalMs - minDurationMs));
|
||||
const normalizedEnd = Math.max(minEnd, Math.min(clampedEnd, totalMs));
|
||||
const safeTotalMs = Math.max(0, totalMs);
|
||||
const safeMinDurationMs = Math.max(0, Math.min(minDurationMs, safeTotalMs));
|
||||
const clampedStart = Math.max(0, Math.min(startMs, safeTotalMs));
|
||||
const normalizedStart = Math.max(0, Math.min(clampedStart, safeTotalMs - safeMinDurationMs));
|
||||
const normalizedEnd = Math.min(
|
||||
safeTotalMs,
|
||||
Math.max(endMs, normalizedStart + safeMinDurationMs),
|
||||
);
|
||||
|
||||
return { start: normalizedStart, end: normalizedEnd };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user