Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Merge branch 'main' into pr/1372

Richie McIlroy30222ce766cc
diff --cc apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
index 1e34facc9,eb8f223a8..d48cb9239
--- a/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/ZoomTrack.tsx
@@@ -266,8 -278,8 +266,8 @@@ export function ZoomTrack(props:
});
}}
>
- <For
- each={project.timeline?.zoomSegments}
+ <Show
- when={(project.timeline?.zoomSegments ?? []).length > 0}
++ when={project.timeline?.zoomSegments}
fallback={
<div class="text-center text-sm text-[--text-tertiary] flex flex-col justify-center items-center inset-0 w-full bg-gray-3/20 dark:bg-gray-3/10 hover:bg-gray-3/30 dark:hover:bg-gray-3/20 transition-colors rounded-xl pointer-events-none">
<div>Click to add zoom segment</div>
@@@ -277,329 -289,352 +277,333 @@@
</div>
}
>
- {(segment, i) => {
- const { setTrackState } = useTrackContext();
-
- const zoomPercentage = () => {
- const amount = segment.amount;
- return `${amount.toFixed(1)}x`;
- };
- <Index each={visibleZoomIndices()}>
- {(segmentIndex) => {
- const i = segmentIndex;
- const segment = () => (project.timeline?.zoomSegments ?? [])[i()];
++ <Index each={project.timeline?.zoomSegments}>
++ {(segment, i) => {
+ const { setTrackState } = useTrackContext();
- const zoomSegments = () => project.timeline?.zoomSegments ?? [];
+ const zoomPercentage = () => {
- const seg = segment();
- if (!seg) return "1.0x";
- const amount = seg.amount;
++ const amount = segment().amount;
+ return `${amount.toFixed(1)}x`;
+ };
- function createMouseDownDrag<T>(
- setup: () => T,
- _update: (e: MouseEvent, v: T, initialMouseX: number) => void,
- ) {
- return (downEvent: MouseEvent) => {
- if (editorState.timeline.interactMode !== "seek") return;
+ const zoomSegments = () => project.timeline?.zoomSegments ?? [];
- downEvent.stopPropagation();
+ function createMouseDownDrag<T>(
+ setup: () => T,
+ _update: (e: MouseEvent, v: T, initialMouseX: number) => void,
+ ) {
+ return (downEvent: MouseEvent) => {
+ if (editorState.timeline.interactMode !== "seek") return;
- const initial = setup();
+ downEvent.stopPropagation();
- let moved = false;
- let initialMouseX: null | number = null;
+ const initial = setup();
- setTrackState("draggingSegment", true);
+ let moved = false;
+ let initialMouseX: null | number = null;
- const resumeHistory = projectHistory.pause();
+ setTrackState("draggingSegment", true);
- props.onDragStateChanged({ type: "movePending" });
+ const resumeHistory = projectHistory.pause();
- function finish(e: MouseEvent) {
- resumeHistory();
- if (!moved) {
- e.stopPropagation();
+ props.onDragStateChanged({ type: "movePending" });
- const currentSelection = editorState.timeline.selection;
- const segmentIndex = i();
- const isMultiSelect = e.ctrlKey || e.metaKey;
- const isRangeSelect = e.shiftKey;
-
- if (isRangeSelect && currentSelection?.type === "zoom") {
- // Range selection: select from last selected to current
- const existingIndices = currentSelection.indices;
- const lastIndex =
- existingIndices[existingIndices.length - 1];
- const start = Math.min(lastIndex, segmentIndex);
- const end = Math.max(lastIndex, segmentIndex);
- const rangeIndices: number[] = [];
- for (let idx = start; idx <= end; idx++) {
- rangeIndices.push(idx);
- }
+ function finish(e: MouseEvent) {
+ resumeHistory();
+ if (!moved) {
+ e.stopPropagation();
+
+ const currentSelection = editorState.timeline.selection;
- const segmentIndex = i();
++ const segmentIndex = i;
+ const isMultiSelect = e.ctrlKey || e.metaKey;
+ const isRangeSelect = e.shiftKey;
+
+ if (isRangeSelect && currentSelection?.type === "zoom") {
+ // Range selection: select from last selected to current
+ const existingIndices = currentSelection.indices;
+ const lastIndex =
+ existingIndices[existingIndices.length - 1];
+ const start = Math.min(lastIndex, segmentIndex);
+ const end = Math.max(lastIndex, segmentIndex);
+ const rangeIndices: number[] = [];
+ for (let idx = start; idx <= end; idx++) {
+ rangeIndices.push(idx);
+ }
- setEditorState("timeline", "selection", {
- type: "zoom",
- indices: rangeIndices,
- });
- } else if (isMultiSelect) {
- // Handle multi-selection with Ctrl/Cmd+click
- if (currentSelection?.type === "zoom") {
- const baseIndices = currentSelection.indices;
- const exists = baseIndices.includes(segmentIndex);
- const newIndices = exists
- ? baseIndices.filter((idx) => idx !== segmentIndex)
- : [...baseIndices, segmentIndex];
-
- if (newIndices.length > 0) {
+ setEditorState("timeline", "selection", {
+ type: "zoom",
+ indices: rangeIndices,
+ });
+ } else if (isMultiSelect) {
+ // Handle multi-selection with Ctrl/Cmd+click
+ if (currentSelection?.type === "zoom") {
+ const baseIndices = currentSelection.indices;
+ const exists = baseIndices.includes(segmentIndex);
+ const newIndices = exists
+ ? baseIndices.filter((idx) => idx !== segmentIndex)
+ : [...baseIndices, segmentIndex];
+
+ if (newIndices.length > 0) {
+ setEditorState("timeline", "selection", {
+ type: "zoom",
+ indices: newIndices,
+ });
+ } else {
+ setEditorState("timeline", "selection", null);
+ }
+ } else {
+ // Start new multi-selection
setEditorState("timeline", "selection", {
type: "zoom",
- indices: newIndices,
+ indices: [segmentIndex],
});
- } else {
- setEditorState("timeline", "selection", null);
}
} else {
- // Start new multi-selection
+ // Normal single selection
setEditorState("timeline", "selection", {
type: "zoom",
indices: [segmentIndex],
});
}
- } else {
- // Normal single selection
- setEditorState("timeline", "selection", {
- type: "zoom",
- indices: [segmentIndex],
- });
+ props.handleUpdatePlayhead(e);
}
- props.handleUpdatePlayhead(e);
+ props.onDragStateChanged({ type: "idle" });
+ setTrackState("draggingSegment", false);
}
- props.onDragStateChanged({ type: "idle" });
- setTrackState("draggingSegment", false);
- }
- function update(event: MouseEvent) {
- if (Math.abs(event.clientX - downEvent.clientX) > 2) {
- if (!moved) {
- moved = true;
- initialMouseX = event.clientX;
- props.onDragStateChanged({
- type: "moving",
- });
+ function update(event: MouseEvent) {
+ if (Math.abs(event.clientX - downEvent.clientX) > 2) {
+ if (!moved) {
+ moved = true;
+ initialMouseX = event.clientX;
+ props.onDragStateChanged({
+ type: "moving",
+ });
+ }
}
+
+ if (initialMouseX === null) return;
+
+ _update(event, initial, initialMouseX);
}
- if (initialMouseX === null) return;
-
- _update(event, initial, initialMouseX);
- }
-
- createRoot((dispose) => {
- createEventListenerMap(window, {
- mousemove: (e) => {
- update(e);
- },
- mouseup: (e) => {
- update(e);
- finish(e);
- dispose();
- },
+ createRoot((dispose) => {
+ createEventListenerMap(window, {
+ mousemove: (e) => {
+ update(e);
+ },
+ mouseup: (e) => {
+ update(e);
+ finish(e);
+ dispose();
+ },
+ });
});
- });
- };
- }
+ };
+ }
- const isSelected = createMemo(() => {
- const selection = editorState.timeline.selection;
- if (!selection || selection.type !== "zoom") return false;
+ const isSelected = createMemo(() => {
+ const selection = editorState.timeline.selection;
+ if (!selection || selection.type !== "zoom") return false;
- const seg = segment();
- if (!seg) return false;
- const segmentIndex = project.timeline?.zoomSegments?.findIndex(
- (s) => s.start === segment.start && s.end === segment.end,
- );
+ const segmentIndex = project.timeline?.zoomSegments?.findIndex(
- (s) => s.start === seg.start && s.end === seg.end,
++ (s) => s.start === segment().start && s.end === segment().end,
+ );
- // Support both single selection (index) and multi-selection (indices)
- if (segmentIndex === undefined || segmentIndex === -1) return false;
+ if (segmentIndex === undefined || segmentIndex === -1)
+ return false;
- return selection.indices.includes(segmentIndex);
- });
+ return selection.indices.includes(segmentIndex);
+ });
- return (
- <SegmentRoot
- class={cx(
- "border duration-200 hover:border-gray-12 transition-colors group",
- "bg-gradient-to-r from-[#292929] via-[#434343] to-[#292929] shadow-[inset_0_8px_12px_3px_rgba(255,255,255,0.2)]",
- isSelected() ? "border-gray-12" : "border-transparent",
- )}
- innerClass="ring-red-5"
- segment={segment}
- onMouseDown={(e) => {
- e.stopPropagation();
-
- if (editorState.timeline.interactMode === "split") {
- const rect = e.currentTarget.getBoundingClientRect();
- const fraction = (e.clientX - rect.left) / rect.width;
-
- const splitTime = fraction * (segment.end - segment.start);
-
- projectActions.splitZoomSegment(i(), splitTime);
- }
- }}
- >
- <SegmentHandle
- position="start"
- onMouseDown={createMouseDownDrag(
- () => {
- const start = segment.start;
-
- let minValue = 0;
-
- const maxValue = segment.end - 1;
-
- for (let i = zoomSegments().length - 1; i >= 0; i--) {
- const segment = zoomSegments()[i]!;
- if (segment.end <= start) {
- minValue = segment.end;
- break;
- }
- }
+ return (
- <Show when={segment()}>
- {(seg) => (
- <SegmentRoot
- class={cx(
- "border duration-200 hover:border-gray-12 transition-colors group",
- "bg-gradient-to-r from-[#292929] via-[#434343] to-[#292929] shadow-[inset_0_8px_12px_3px_rgba(255,255,255,0.2)]",
- isSelected()
- ? "wobble-wrapper border-gray-12"
- : "border-transparent",
- )}
- innerClass="ring-red-5"
- segment={seg()}
- onMouseDown={(e) => {
- e.stopPropagation();
-
- if (editorState.timeline.interactMode === "split") {
- const rect = e.currentTarget.getBoundingClientRect();
- const fraction = (e.clientX - rect.left) / rect.width;
-
- const splitTime = fraction * (seg().end - seg().start);
-
- projectActions.splitZoomSegment(i(), splitTime);
- }
- }}
- >
- <SegmentHandle
- position="start"
- onMouseDown={createMouseDownDrag(
- () => {
- const start = seg().start;
-
- let minValue = 0;
-
- const maxValue = seg().end - 1;
-
- for (
- let idx = zoomSegments().length - 1;
- idx >= 0;
- idx--
- ) {
- const zs = zoomSegments()[idx]!;
- if (zs.end <= start) {
- minValue = zs.end;
- break;
- }
- }
-
- return { start, minValue, maxValue };
- },
- (e, value, initialMouseX) => {
- const newStart =
- value.start +
- (e.clientX - initialMouseX) * secsPerPixel();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "start",
- Math.min(
- value.maxValue,
- Math.max(value.minValue, newStart),
- ),
- );
-
- setProject(
- "timeline",
- "zoomSegments",
- produce((s) => {
- s.sort((a, b) => a.start - b.start);
- }),
- );
- },
- )}
- />
- <SegmentContent
- class="flex justify-center items-center cursor-grab"
- onMouseDown={createMouseDownDrag(
- () => {
- const original = { ...seg() };
-
- const prevSegment = zoomSegments()[i() - 1];
- const nextSegment = zoomSegments()[i() + 1];
-
- const minStart = prevSegment?.end ?? 0;
- const maxEnd = nextSegment?.start ?? duration();
-
- return {
- original,
- minStart,
- maxEnd,
- };
- },
- (e, value, initialMouseX) => {
- const rawDelta =
- (e.clientX - initialMouseX) * secsPerPixel();
-
- const newStart = value.original.start + rawDelta;
- const newEnd = value.original.end + rawDelta;
-
- let delta = rawDelta;
-
- if (newStart < value.minStart)
- delta = value.minStart - value.original.start;
- else if (newEnd > value.maxEnd)
- delta = value.maxEnd - value.original.end;
-
- setProject("timeline", "zoomSegments", i(), {
- start: value.original.start + delta,
- end: value.original.end + delta,
- });
- },
- )}
- >
- {(() => {
- const ctx = useSegmentContext();
-
- return (
- <Switch>
- <Match when={ctx.width() < 40}>
- <div class="flex justify-center items-center">
- <IconLucideSearch class="size-3.5 text-gray-1 dark:text-gray-12" />
- </div>
- </Match>
- <Match when={ctx.width() < 100}>
- <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
- <IconLucideSearch class="size-3" />
- <span>{zoomPercentage()}</span>
- </div>
- </Match>
- <Match when={true}>
- <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
- <span class="opacity-70">Zoom</span>
- <div class="flex gap-1 items-center text-md">
- <IconLucideSearch class="size-3.5" />
- {zoomPercentage()}
- </div>
- </div>
- </Match>
- </Switch>
- );
- })()}
- </SegmentContent>
- <SegmentHandle
- position="end"
- onMouseDown={createMouseDownDrag(
- () => {
- const end = seg().end;
-
- const minValue = seg().start + 1;
-
- let maxValue = duration();
-
- for (
- let idx = 0;
- idx < zoomSegments().length;
- idx++
- ) {
- const zs = zoomSegments()[idx]!;
- if (zs.start > end) {
- maxValue = zs.start;
- break;
- }
- }
-
- return { end, minValue, maxValue };
- },
- (e, value, initialMouseX) => {
- const newEnd =
- value.end +
- (e.clientX - initialMouseX) * secsPerPixel();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "end",
- Math.min(
- value.maxValue,
- Math.max(value.minValue, newEnd),
- ),
- );
-
- setProject(
- "timeline",
- "zoomSegments",
- produce((s) => {
- s.sort((a, b) => a.start - b.start);
- }),
- );
- },
- )}
- />
- </SegmentRoot>
++ <SegmentRoot
++ class={cx(
++ "border duration-200 hover:border-gray-12 transition-colors group",
++ "bg-gradient-to-r from-[#292929] via-[#434343] to-[#292929] shadow-[inset_0_8px_12px_3px_rgba(255,255,255,0.2)]",
++ isSelected() ? "border-gray-12" : "border-transparent",
+ )}
- </Show>
++ innerClass="ring-red-5"
++ segment={segment()}
++ onMouseDown={(e) => {
++ e.stopPropagation();
+
- return { start, minValue, maxValue };
- },
- (e, value, initialMouseX) => {
- const newStart =
- value.start +
- (e.clientX - initialMouseX) * secsPerPixel();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "start",
- Math.min(
- value.maxValue,
- Math.max(value.minValue, newStart),
- ),
- );
++ if (editorState.timeline.interactMode === "split") {
++ const rect = e.currentTarget.getBoundingClientRect();
++ const fraction = (e.clientX - rect.left) / rect.width;
+
- setProject(
- "timeline",
- "zoomSegments",
- produce((s) => {
- s.sort((a, b) => a.start - b.start);
- }),
- );
- },
- )}
- />
- <SegmentContent
- class="flex justify-center items-center cursor-grab"
- onMouseDown={createMouseDownDrag(
- () => {
- const original = { ...segment };
-
- const prevSegment = zoomSegments()[i() - 1];
- const nextSegment = zoomSegments()[i() + 1];
-
- const minStart = prevSegment?.end ?? 0;
- const maxEnd = nextSegment?.start ?? duration();
-
- return {
- original,
- minStart,
- maxEnd,
- };
- },
- (e, value, initialMouseX) => {
- const rawDelta =
- (e.clientX - initialMouseX) * secsPerPixel();
-
- const newStart = value.original.start + rawDelta;
- const newEnd = value.original.end + rawDelta;
-
- let delta = rawDelta;
-
- if (newStart < value.minStart)
- delta = value.minStart - value.original.start;
- else if (newEnd > value.maxEnd)
- delta = value.maxEnd - value.original.end;
-
- setProject("timeline", "zoomSegments", i(), {
- start: value.original.start + delta,
- end: value.original.end + delta,
- });
- },
- )}
++ const splitTime =
++ fraction * (segment().end - segment().start);
++
++ projectActions.splitZoomSegment(i, splitTime);
++ }
++ }}
+ >
- {(() => {
- const ctx = useSegmentContext();
-
- return (
- <Switch>
- <Match when={ctx.width() < 40}>
- <div class="flex justify-center items-center">
- <IconLucideSearch class="size-3.5 text-gray-1 dark:text-gray-12" />
- </div>
- </Match>
- <Match when={ctx.width() < 100}>
- <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
- <IconLucideSearch class="size-3" />
- <span>{zoomPercentage()}</span>
- </div>
- </Match>
- <Match when={true}>
- <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
- <span class="opacity-70">Zoom</span>
- <div class="flex gap-1 items-center text-md">
- <IconLucideSearch class="size-3.5" />
- {zoomPercentage()}
- </div>
- </div>
- </Match>
- </Switch>
- );
- })()}
- </SegmentContent>
- <SegmentHandle
- position="end"
- onMouseDown={createMouseDownDrag(
- () => {
- const end = segment.end;
-
- const minValue = segment.start + 1;
-
- let maxValue = duration();
-
- for (let i = 0; i < zoomSegments().length; i++) {
- const segment = zoomSegments()[i]!;
- if (segment.start > end) {
- maxValue = segment.start;
- break;
++ <SegmentHandle
++ position="start"
++ onMouseDown={createMouseDownDrag(
++ () => {
++ const start = segment().start;
++
++ let minValue = 0;
++
++ const maxValue = segment().end - 1;
++
++ for (let i = zoomSegments().length - 1; i >= 0; i--) {
++ const segment = zoomSegments()[i]!;
++ if (segment.end <= start) {
++ minValue = segment.end;
++ break;
++ }
+ }
- }
+
- return { end, minValue, maxValue };
- },
- (e, value, initialMouseX) => {
- const newEnd =
- value.end + (e.clientX - initialMouseX) * secsPerPixel();
-
- setProject(
- "timeline",
- "zoomSegments",
- i(),
- "end",
- Math.min(
- value.maxValue,
- Math.max(value.minValue, newEnd),
- ),
- );
++ return { start, minValue, maxValue };
++ },
++ (e, value, initialMouseX) => {
++ const newStart =
++ value.start +
++ (e.clientX - initialMouseX) * secsPerPixel();
++
++ setProject(
++ "timeline",
++ "zoomSegments",
++ i,
++ "start",
++ Math.min(
++ value.maxValue,
++ Math.max(value.minValue, newStart),
++ ),
++ );
++
++ setProject(
++ "timeline",
++ "zoomSegments",
++ produce((s) => {
++ s.sort((a, b) => a.start - b.start);
++ }),
++ );
++ },
++ )}
++ />
++ <SegmentContent
++ class="flex justify-center items-center cursor-grab"
++ onMouseDown={createMouseDownDrag(
++ () => {
++ const original = { ...segment() };
++
++ const prevSegment = zoomSegments()[i - 1];
++ const nextSegment = zoomSegments()[i + 1];
++
++ const minStart = prevSegment?.end ?? 0;
++ const maxEnd = nextSegment?.start ?? duration();
++
++ return {
++ original,
++ minStart,
++ maxEnd,
++ };
++ },
++ (e, value, initialMouseX) => {
++ const rawDelta =
++ (e.clientX - initialMouseX) * secsPerPixel();
++
++ const newStart = value.original.start + rawDelta;
++ const newEnd = value.original.end + rawDelta;
+
- setProject(
- "timeline",
- "zoomSegments",
- produce((s) => {
- s.sort((a, b) => a.start - b.start);
- }),
++ let delta = rawDelta;
++
++ if (newStart < value.minStart)
++ delta = value.minStart - value.original.start;
++ else if (newEnd > value.maxEnd)
++ delta = value.maxEnd - value.original.end;
++
++ setProject("timeline", "zoomSegments", i, {
++ start: value.original.start + delta,
++ end: value.original.end + delta,
++ });
++ },
++ )}
++ >
++ {(() => {
++ const ctx = useSegmentContext();
++
++ return (
++ <Switch>
++ <Match when={ctx.width() < 40}>
++ <div class="flex justify-center items-center">
++ <IconLucideSearch class="size-3.5 text-gray-1 dark:text-gray-12" />
++ </div>
++ </Match>
++ <Match when={ctx.width() < 100}>
++ <div class="flex gap-1 items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12">
++ <IconLucideSearch class="size-3" />
++ <span>{zoomPercentage()}</span>
++ </div>
++ </Match>
++ <Match when={true}>
++ <div class="flex flex-col gap-1 justify-center items-center text-xs whitespace-nowrap text-gray-1 dark:text-gray-12 animate-in fade-in">
++ <span class="opacity-70">Zoom</span>
++ <div class="flex gap-1 items-center text-md">
++ <IconLucideSearch class="size-3.5" />
++ {zoomPercentage()}
++ </div>
++ </div>
++ </Match>
++ </Switch>
+ );
- },
- )}
- />
- </SegmentRoot>
- );
- }}
- </For>
++ })()}
++ </SegmentContent>
++ <SegmentHandle
++ position="end"
++ onMouseDown={createMouseDownDrag(
++ () => {
++ const end = segment().end;
++
++ const minValue = segment().start + 1;
++
++ let maxValue = duration();
++
++ for (let i = 0; i < zoomSegments().length; i++) {
++ const segment = zoomSegments()[i]!;
++ if (segment.start > end) {
++ maxValue = segment.start;
++ break;
++ }
++ }
++
++ return { end, minValue, maxValue };
++ },
++ (e, value, initialMouseX) => {
++ const newEnd =
++ value.end +
++ (e.clientX - initialMouseX) * secsPerPixel();
++
++ setProject(
++ "timeline",
++ "zoomSegments",
++ i,
++ "end",
++ Math.min(
++ value.maxValue,
++ Math.max(value.minValue, newEnd),
++ ),
++ );
++
++ setProject(
++ "timeline",
++ "zoomSegments",
++ produce((s) => {
++ s.sort((a, b) => a.start - b.start);
++ }),
++ );
++ },
++ )}
++ />
++ </SegmentRoot>
+ );
+ }}
+ </Index>
+ </Show>
<Show
when={
!useTrackContext().trackState.draggingSegment && newSegmentDetails()