Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: keep caption edits from shifting the video timeline

Richie McIlroy6d96fe2e6c62
diff --git a/apps/desktop/src/routes/editor/Timeline/index.tsx b/apps/desktop/src/routes/editor/Timeline/index.tsx
index d990e2af5..8e86f03b0 100644
--- a/apps/desktop/src/routes/editor/Timeline/index.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/index.tsx
@@ -1151,6 +1151,7 @@ export function Timeline(props: {
}
createEventListener(window, "keydown", (e) => {
+ if (e.defaultPrevented) return;
const hasNoModifiers = !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey;
if (
diff --git a/apps/desktop/src/routes/editor/TranscriptPage.tsx b/apps/desktop/src/routes/editor/TranscriptPage.tsx
index 738f64078..de23250e2 100644
--- a/apps/desktop/src/routes/editor/TranscriptPage.tsx
+++ b/apps/desktop/src/routes/editor/TranscriptPage.tsx
@@ -17,9 +17,7 @@ import { defaultCaptionSettings } from "~/store/captions";
import { commands } from "~/utils/tauri";
import {
getCaptionTextFromWords,
- type MappedTimeRange,
mapEditedTimeToSource,
- mapSourceRangeToEdited,
mapSourceTimeToEdited,
syncCaptionWordsWithText,
} from "./captions";
@@ -29,13 +27,13 @@ import {
createCaptionExportCues,
formatCaptionCues,
} from "./captions-export";
-import {
- clipCutPreservesTransitionGeometry,
- rangeIntersectsClipTransition,
-} from "./clip-transitions";
import { FPS, useEditorContext } from "./context";
import { routeEditorPlaybackIntent } from "./playback-intent-routing";
-import { rippleDeleteAllTracks } from "./timeline-utils";
+import {
+ deleteTranscriptWords,
+ type FlatWord,
+ transcriptSeekPosition,
+} from "./transcript-edits";
function formatTimePrecise(secs: number) {
const minutes = Math.floor(secs / 60);
@@ -44,14 +42,6 @@ function formatTimePrecise(secs: number) {
return `${minutes}:${whole.toString().padStart(2, "0")}.${hundredths.toString().padStart(2, "0")}`;
}
-interface FlatWord {
- text: string;
- start: number;
- end: number;
- segmentIndex: number;
- wordIndex: number;
-}
-
interface TranscriptSegmentGroup {
segmentIndex: number;
words: FlatWord[];
@@ -158,16 +148,12 @@ export function TranscriptPanel() {
segment.words.splice(target.wordIndex, 1, ...replacements);
}
- if (!p.captions?.segments) return;
- for (let i = p.captions.segments.length - 1; i >= 0; i--) {
- const seg = p.captions.segments[i];
- if (!seg.words || seg.words.length === 0) {
- p.captions.segments.splice(i, 1);
- } else {
- seg.text = getCaptionTextFromWords(seg.words);
- seg.start = seg.words[0].start;
- seg.end = seg.words[seg.words.length - 1].end;
- }
+ if (segment.words.length === 0) {
+ p.captions?.segments.splice(target.segmentIndex, 1);
+ } else {
+ segment.text = getCaptionTextFromWords(segment.words);
+ segment.start = segment.words[0].start;
+ segment.end = segment.words[segment.words.length - 1].end;
}
}),
);
@@ -320,7 +306,11 @@ export function TranscriptPanel() {
setEditorState("previewTime", null);
setEditorState("playbackTime", outputTime);
editorState.timeline.transform.setPosition(
- outputTime - editorState.timeline.transform.zoom / 2,
+ transcriptSeekPosition(
+ outputTime,
+ editorState.timeline.transform.position,
+ editorState.timeline.transform.zoom,
+ ),
);
});
} catch (error) {
@@ -328,141 +318,47 @@ export function TranscriptPanel() {
}
};
- const applyWordDeletions = (flatIndices: number[]) => {
+ const applyWordDeletions = (
+ flatIndices: number[],
+ mode: "captions" | "video" = "captions",
+ ) => {
const words = allWords();
- const wordsToDelete = flatIndices
+ const wordsToDelete = [...new Set(flatIndices)]
.map((idx) => words[idx])
- .filter((w): w is FlatWord => !!w);
-
- if (wordsToDelete.length === 0) return;
-
- const sorted = [...wordsToDelete].sort((a, b) => {
- if (a.segmentIndex !== b.segmentIndex)
- return b.segmentIndex - a.segmentIndex;
- return b.wordIndex - a.wordIndex;
- });
-
- const sourceRanges = wordsToDelete
- .map((w) => ({ start: w.start, end: w.end }))
- .sort((a, b) => a.start - b.start);
-
- const mergedSourceRanges: { start: number; end: number }[] = [];
- for (const range of sourceRanges) {
- const last = mergedSourceRanges[mergedSourceRanges.length - 1];
- if (last && range.start <= last.end) {
- last.end = Math.max(last.end, range.end);
- } else {
- mergedSourceRanges.push({ ...range });
- }
- }
-
- const outputRanges = mergedSourceRanges
- .flatMap((range) =>
- mapSourceRangeToEdited(
- range.start,
- range.end,
- project.timeline?.segments ?? [],
+ .filter((word): word is FlatWord => !!word);
+ const outcome: { result: ReturnType<typeof deleteTranscriptWords> } = {
+ result: "empty",
+ };
+ setProject(
+ produce((p) => {
+ outcome.result = deleteTranscriptWords(
+ p,
+ wordsToDelete,
recordingSegments(),
- project.timeline?.transitions ?? [],
- ),
- )
- .sort((a, b) => a.start - b.start || a.segmentIndex - b.segmentIndex);
-
- const mergedOutputRanges: MappedTimeRange[] = [];
- for (const range of outputRanges) {
- const last = mergedOutputRanges[mergedOutputRanges.length - 1];
- if (
- last &&
- last.segmentIndex === range.segmentIndex &&
- range.start <= last.end + 0.0001
- ) {
- last.end = Math.max(last.end, range.end);
- } else {
- mergedOutputRanges.push({ ...range });
- }
- }
-
- const timeline = project.timeline;
- if (
- timeline &&
- mergedOutputRanges.some(
- (range) =>
- rangeIntersectsClipTransition(
- timeline.segments,
- timeline.transitions ?? [],
- range.start,
- range.end,
- ) ||
- !clipCutPreservesTransitionGeometry(
- timeline.segments,
- timeline.transitions ?? [],
- range.segmentIndex,
- range.start,
- range.end,
- ),
- )
- ) {
+ mode,
+ );
+ }),
+ );
+ if (outcome.result === "transition") {
toast.error(
- "Remove the nearby transition before deleting this transcript range.",
+ "Remove the nearby transition before cutting this transcript range.",
);
return;
}
-
- setProject(
- produce((p) => {
- if (!p.captions?.segments) return;
-
- for (const word of sorted) {
- const seg = p.captions.segments[word.segmentIndex];
- if (!seg?.words) continue;
- if (word.wordIndex < seg.words.length) {
- seg.words.splice(word.wordIndex, 1);
- }
- }
-
- for (let i = p.captions.segments.length - 1; i >= 0; i--) {
- const seg = p.captions.segments[i];
- if (!seg.words || seg.words.length === 0) {
- p.captions.segments.splice(i, 1);
- } else {
- seg.text = getCaptionTextFromWords(seg.words);
- seg.start = seg.words[0].start;
- seg.end = seg.words[seg.words.length - 1].end;
- }
- }
-
- if (p.timeline) {
- for (const range of [...mergedOutputRanges].reverse()) {
- if (range.end - range.start <= 0.001) continue;
- rippleDeleteAllTracks(
- p.timeline,
- range.start,
- range.end,
- range.segmentIndex,
- );
- }
- }
- }),
- );
- setEditorState("styleEditIndex", null);
- setEditorState("timeline", "selection", null);
-
+ if (outcome.result !== "deleted") return;
+ if (
+ mode === "video" ||
+ editorState.timeline.selection?.type === "caption"
+ ) {
+ setEditorState("styleEditIndex", null);
+ setEditorState("timeline", "selection", null);
+ }
setEditorState("captions", "isStale", false);
-
- const newDuration = totalDuration();
- if (editorState.playbackTime > newDuration) {
- setEditorState("playbackTime", Math.max(newDuration - 0.01, 0));
+ if (mode === "video" && editorState.playbackTime > totalDuration()) {
+ setEditorState("playbackTime", Math.max(totalDuration() - 0.01, 0));
}
};
- const handleDeleteWord = (flatIndex: number) => {
- applyWordDeletions([flatIndex]);
- };
-
- const handleDeleteWords = (flatIndices: number[]) => {
- applyWordDeletions(flatIndices);
- };
-
const isAtEnd = () => {
const total = totalDuration();
return total > 0 && total - editorState.playbackTime <= 0.1;
@@ -517,7 +413,7 @@ export function TranscriptPanel() {
});
createEventListener(window, "keydown", (e) => {
- if (e.code !== "Space") return;
+ if (e.defaultPrevented || e.code !== "Space") return;
const el = document.activeElement;
if (el) {
const tag = el.tagName.toLowerCase();
@@ -592,8 +488,8 @@ export function TranscriptPanel() {
TEXT_SIZES[textSizeIndex()]?.value ?? TEXT_SIZES[1].value
}
onWordClick={handleWordClick}
- onDeleteWord={handleDeleteWord}
- onDeleteWords={handleDeleteWords}
+ onDeleteWords={applyWordDeletions}
+ onCutWords={(indices) => applyWordDeletions(indices, "video")}
onEditWord={updateWordText}
onAddCaption={addCaptionAtPlayhead}
/>
@@ -614,6 +510,7 @@ function TranscriptWord(props: {
onCommitEdit: (text: string) => void;
onCancelEdit: () => void;
onDelete: () => void;
+ onCut: () => void;
}) {
const [hovering, setHovering] = createSignal(false);
let hoverTimer: number | undefined;
@@ -696,6 +593,8 @@ function TranscriptWord(props: {
<button
type="button"
class="flex items-center justify-center size-6 rounded-md bg-red-9 text-white hover:bg-red-10 transition-colors"
+ title="Delete from captions"
+ aria-label="Delete from captions"
onClick={(e) => {
e.stopPropagation();
props.onDelete();
@@ -703,6 +602,17 @@ function TranscriptWord(props: {
>
<IconCapTrash class="size-3.5" />
</button>
+ <button
+ type="button"
+ class="flex items-center justify-center gap-1 h-6 px-1.5 rounded-md bg-gray-11 text-white hover:bg-gray-10 transition-colors text-xs"
+ title="Cut selected words and their video from the timeline"
+ onClick={(e) => {
+ e.stopPropagation();
+ props.onCut();
+ }}
+ >
+ Cut video
+ </button>
</Show>
</span>
</Show>
@@ -739,8 +649,8 @@ function TranscriptEditor(props: {
activeWordIndex: number;
textSizeClass: string;
onWordClick: (word: FlatWord) => void;
- onDeleteWord: (flatIndex: number) => void;
onDeleteWords: (flatIndices: number[]) => void;
+ onCutWords: (flatIndices: number[]) => void;
onEditWord: (flatIndex: number, text: string) => void;
onAddCaption: () => void;
}) {
@@ -791,25 +701,24 @@ function TranscriptEditor(props: {
);
const handleKeyDown = (e: KeyboardEvent) => {
+ if (editingIndex() !== -1) return;
const selected = selectedIndices();
if (selected.size === 0) return;
if (e.key === "Enter" && selected.size === 1 && editingIndex() === -1) {
e.preventDefault();
+ e.stopPropagation();
const word = props.allWords[[...selected][0]];
if (word) startEditing(word);
} else if (e.key === "Backspace" || e.key === "Delete") {
e.preventDefault();
- const indices = [...selected];
- if (indices.length === 1) {
- props.onDeleteWord(indices[0]);
- } else {
- props.onDeleteWords(indices);
- }
+ e.stopPropagation();
+ props.onDeleteWords([...selected]);
setSelectedIndices(new Set<number>());
setAnchorIndex(-1);
} else if (e.key === "ArrowLeft") {
e.preventDefault();
+ e.stopPropagation();
const minIdx = Math.min(...selected);
const prev = Math.max(minIdx - 1, 0);
setSelectedIndices(new Set([prev]));
@@ -818,6 +727,7 @@ function TranscriptEditor(props: {
if (word) props.onWordClick(word);
} else if (e.key === "ArrowRight") {
e.preventDefault();
+ e.stopPropagation();
const maxIdx = Math.max(...selected);
const next = Math.min(maxIdx + 1, props.allWords.length - 1);
setSelectedIndices(new Set([next]));
@@ -835,6 +745,7 @@ function TranscriptEditor(props: {
};
const handleWordSelect = (word: FlatWord, e: MouseEvent) => {
+ scrollContainerRef?.focus({ preventScroll: true });
const idx = flatIndexOf(word);
const isCtrlOrCmd = e.ctrlKey || e.metaKey;
const isShift = e.shiftKey;
@@ -878,13 +789,11 @@ function TranscriptEditor(props: {
props.onWordClick(word);
};
- const handleWordDelete = (word: FlatWord) => {
+ const handleWordRemoval = (word: FlatWord, mode: "captions" | "video") => {
const selected = selectedIndices();
- if (selected.size > 1) {
- props.onDeleteWords([...selected]);
- } else {
- props.onDeleteWord(flatIndexOf(word));
- }
+ const indices = selected.size > 1 ? [...selected] : [flatIndexOf(word)];
+ if (mode === "video") props.onCutWords(indices);
+ else props.onDeleteWords(indices);
setSelectedIndices(new Set<number>());
setAnchorIndex(-1);
};
@@ -961,7 +870,8 @@ function TranscriptEditor(props: {
onStartEdit={() => startEditing(word)}
onCommitEdit={(text: string) => commitEditing(word, text)}
onCancelEdit={cancelEditing}
- onDelete={() => handleWordDelete(word)}
+ onDelete={() => handleWordRemoval(word, "captions")}
+ onCut={() => handleWordRemoval(word, "video")}
/>
);
}}
diff --git a/apps/desktop/src/routes/editor/transcript-edits.test.ts b/apps/desktop/src/routes/editor/transcript-edits.test.ts
new file mode 100644
index 000000000..43eed9834
--- /dev/null
+++ b/apps/desktop/src/routes/editor/transcript-edits.test.ts
@@ -0,0 +1,167 @@
+import { describe, expect, it } from "vitest";
+import { defaultCaptionSettings } from "~/store/captions";
+import type { SegmentRecordings } from "~/utils/tauri";
+import { deriveCaptionTrackSegments } from "./captions";
+import { clipTimelineDuration } from "./clip-transitions";
+import type { EditorProjectConfiguration } from "./context";
+import {
+ deleteTranscriptWords,
+ type FlatWord,
+ transcriptSeekPosition,
+} from "./transcript-edits";
+
+const recordings = [{ display: { duration: 120 } } as SegmentRecordings];
+
+function fixture() {
+ const project = {
+ captions: {
+ settings: { ...defaultCaptionSettings },
+ sourceTimed: true,
+ segments: [
+ {
+ id: "first",
+ start: 19,
+ end: 22,
+ text: "keep this caption",
+ words: [
+ { text: "keep", start: 19, end: 20 },
+ { text: "this", start: 20, end: 21 },
+ { text: "caption", start: 21, end: 22 },
+ ],
+ },
+ {
+ id: "later",
+ start: 26,
+ end: 27,
+ text: "later",
+ words: [{ text: "later", start: 26, end: 27 }],
+ },
+ { id: "manual", start: 28, end: 29, text: "Manual caption", words: [] },
+ ],
+ },
+ timeline: {
+ segments: [
+ { start: 19, end: 23, timescale: 1, recordingSegment: 0 },
+ { start: 25, end: 30, timescale: 1, recordingSegment: 0 },
+ ],
+ transitions: [],
+ zoomSegments: [{ start: 5, end: 7, amount: 2, mode: "auto" }],
+ captionSegments: [],
+ keyboardSegments: [],
+ sceneSegments: [],
+ maskSegments: [],
+ textSegments: [],
+ styleSegments: [],
+ imageSegments: [],
+ camera3dSegments: [],
+ },
+ } satisfies Pick<EditorProjectConfiguration, "captions" | "timeline">;
+ return project;
+}
+
+function word(
+ project: ReturnType<typeof fixture>,
+ segmentIndex: number,
+ wordIndex: number,
+): FlatWord {
+ return {
+ ...project.captions.segments[segmentIndex].words[wordIndex],
+ segmentIndex,
+ wordIndex,
+ };
+}
+
+describe("transcript word deletion", () => {
+ it("deletes caption text without changing cuts, other tracks, duration, or surviving word times", () => {
+ const project = fixture();
+ const timeline = structuredClone(project.timeline);
+ const remaining = [
+ project.captions.segments[0].words[0],
+ project.captions.segments[0].words[2],
+ ];
+ expect(
+ deleteTranscriptWords(project, [word(project, 0, 1)], recordings),
+ ).toBe("deleted");
+ expect(project.timeline).toEqual(timeline);
+ expect(clipTimelineDuration(project.timeline.segments, [])).toBe(9);
+ expect(project.captions.segments[0].text).toBe("keep caption");
+ expect(project.captions.segments[0].words).toEqual(remaining);
+ const projected = deriveCaptionTrackSegments(
+ project.captions.segments,
+ project.timeline.segments,
+ recordings,
+ [],
+ );
+ expect(projected.find((segment) => segment.id === "later")?.start).toBe(5);
+ expect((projected[0].words ?? []).map((value) => value.text)).toEqual([
+ "keep",
+ "caption",
+ ]);
+ });
+
+ it("handles multiple words and removes empty captions without deleting unrelated manual captions", () => {
+ const project = fixture();
+ const timeline = structuredClone(project.timeline);
+ deleteTranscriptWords(
+ project,
+ [word(project, 0, 0), word(project, 1, 0), word(project, 0, 2)],
+ recordings,
+ );
+ expect(project.timeline).toEqual(timeline);
+ expect(project.captions.segments.map((segment) => segment.text)).toEqual([
+ "this",
+ "Manual caption",
+ ]);
+ expect(project.captions.segments[0]).toMatchObject({ start: 20, end: 21 });
+ });
+
+ it("keeps ripple deletion available only through the explicit video action", () => {
+ const project = fixture();
+ deleteTranscriptWords(project, [word(project, 0, 1)], recordings, "video");
+ expect(clipTimelineDuration(project.timeline.segments, [])).toBe(8);
+ expect(project.timeline.segments).toHaveLength(3);
+ expect(project.timeline.zoomSegments[0]).toMatchObject({
+ start: 4,
+ end: 6,
+ });
+ });
+
+ it("allows caption edits near transitions while leaving unsafe video cuts untouched", () => {
+ const project: Pick<EditorProjectConfiguration, "captions" | "timeline"> =
+ fixture();
+ const timeline = project.timeline;
+ if (!timeline) throw new Error("Missing fixture timeline");
+ timeline.transitions = [
+ { segmentIndex: 1, type: "cross-fade", duration: 2 },
+ ];
+ const selected = {
+ text: "caption",
+ start: 21,
+ end: 22,
+ segmentIndex: 0,
+ wordIndex: 2,
+ };
+ const before = structuredClone(project);
+ expect(
+ deleteTranscriptWords(project, [selected], recordings, "video"),
+ ).toBe("transition");
+ expect(project).toEqual(before);
+ expect(deleteTranscriptWords(project, [selected], recordings)).toBe(
+ "deleted",
+ );
+ expect(project.timeline).toEqual(before.timeline);
+ });
+});
+
+describe("transcript seeking", () => {
+ it("keeps the viewport stationary when selecting visible words", () => {
+ for (const time of [48, 49.5, 55, 61]) {
+ expect(transcriptSeekPosition(time, 48, 13)).toBe(48);
+ }
+ });
+
+ it("reveals offscreen words without scrolling before the start", () => {
+ expect(transcriptSeekPosition(70, 48, 13)).toBe(63.5);
+ expect(transcriptSeekPosition(1, 48, 13)).toBe(0);
+ });
+});
diff --git a/apps/desktop/src/routes/editor/transcript-edits.ts b/apps/desktop/src/routes/editor/transcript-edits.ts
new file mode 100644
index 000000000..0e784d8b5
--- /dev/null
+++ b/apps/desktop/src/routes/editor/transcript-edits.ts
@@ -0,0 +1,141 @@
+import type { SegmentRecordings } from "~/utils/tauri";
+import {
+ getCaptionTextFromWords,
+ type MappedTimeRange,
+ mapSourceRangeToEdited,
+} from "./captions";
+import {
+ clipCutPreservesTransitionGeometry,
+ rangeIntersectsClipTransition,
+} from "./clip-transitions";
+import type { EditorProjectConfiguration } from "./context";
+import { rippleDeleteAllTracks } from "./timeline-utils";
+
+export interface FlatWord {
+ text: string;
+ start: number;
+ end: number;
+ segmentIndex: number;
+ wordIndex: number;
+}
+
+export function deleteTranscriptWords(
+ project: Pick<EditorProjectConfiguration, "captions" | "timeline">,
+ wordsToDelete: FlatWord[],
+ recordingSegments: SegmentRecordings[],
+ mode: "captions" | "video" = "captions",
+) {
+ const captions = project.captions;
+ if (!captions || wordsToDelete.length === 0) return "empty";
+ const sorted = [...wordsToDelete].sort((a, b) => {
+ if (a.segmentIndex !== b.segmentIndex)
+ return b.segmentIndex - a.segmentIndex;
+ return b.wordIndex - a.wordIndex;
+ });
+
+ const sourceRanges = (mode === "video" ? wordsToDelete : [])
+ .map((w) => ({ start: w.start, end: w.end }))
+ .sort((a, b) => a.start - b.start);
+
+ const mergedSourceRanges: { start: number; end: number }[] = [];
+ for (const range of sourceRanges) {
+ const last = mergedSourceRanges[mergedSourceRanges.length - 1];
+ if (last && range.start <= last.end) {
+ last.end = Math.max(last.end, range.end);
+ } else {
+ mergedSourceRanges.push({ ...range });
+ }
+ }
+
+ const outputRanges = mergedSourceRanges
+ .flatMap((range) =>
+ mapSourceRangeToEdited(
+ range.start,
+ range.end,
+ project.timeline?.segments ?? [],
+ recordingSegments,
+ project.timeline?.transitions ?? [],
+ ),
+ )
+ .sort((a, b) => a.start - b.start || a.segmentIndex - b.segmentIndex);
+
+ const mergedOutputRanges: MappedTimeRange[] = [];
+ for (const range of outputRanges) {
+ const last = mergedOutputRanges[mergedOutputRanges.length - 1];
+ if (
+ last &&
+ last.segmentIndex === range.segmentIndex &&
+ range.start <= last.end + 0.0001
+ ) {
+ last.end = Math.max(last.end, range.end);
+ } else {
+ mergedOutputRanges.push({ ...range });
+ }
+ }
+
+ const timeline = project.timeline;
+ if (
+ timeline &&
+ mergedOutputRanges.some(
+ (range) =>
+ rangeIntersectsClipTransition(
+ timeline.segments,
+ timeline.transitions ?? [],
+ range.start,
+ range.end,
+ ) ||
+ !clipCutPreservesTransitionGeometry(
+ timeline.segments,
+ timeline.transitions ?? [],
+ range.segmentIndex,
+ range.start,
+ range.end,
+ ),
+ )
+ ) {
+ return "transition";
+ }
+
+ for (const word of sorted) {
+ const seg = captions.segments[word.segmentIndex];
+ if (!seg?.words) continue;
+ if (word.wordIndex >= 0 && word.wordIndex < seg.words.length) {
+ seg.words.splice(word.wordIndex, 1);
+ }
+ }
+
+ for (const i of [...new Set(sorted.map((word) => word.segmentIndex))]) {
+ const seg = captions.segments[i];
+ if (!seg) continue;
+ if (!seg.words || seg.words.length === 0) {
+ captions.segments.splice(i, 1);
+ } else {
+ seg.text = getCaptionTextFromWords(seg.words);
+ seg.start = seg.words[0].start;
+ seg.end = seg.words[seg.words.length - 1].end;
+ }
+ }
+
+ if (project.timeline) {
+ for (const range of [...mergedOutputRanges].reverse()) {
+ if (range.end - range.start <= 0.001) continue;
+ rippleDeleteAllTracks(
+ project.timeline,
+ range.start,
+ range.end,
+ range.segmentIndex,
+ );
+ }
+ }
+ return "deleted";
+}
+
+export function transcriptSeekPosition(
+ time: number,
+ position: number,
+ zoom: number,
+) {
+ return time >= position && time <= position + zoom
+ ? position
+ : Math.max(0, time - zoom / 2);
+}