Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

refactor(desktop): extend timeline segment styling primitives

Richie McIlroy826b30c6e52c
diff --git a/apps/desktop/src/routes/editor/Timeline/Track.tsx b/apps/desktop/src/routes/editor/Timeline/Track.tsx
index 001d5eadf..c1778ae2a 100644
--- a/apps/desktop/src/routes/editor/Timeline/Track.tsx
+++ b/apps/desktop/src/routes/editor/Timeline/Track.tsx
@@ -1,6 +1,12 @@
import { mergeRefs } from "@solid-primitives/refs";
import { cx } from "cva";
-import { type ComponentProps, createMemo, createSignal, Show } from "solid-js";
+import {
+ type ComponentProps,
+ createMemo,
+ createSignal,
+ Show,
+ splitProps,
+} from "solid-js";
import { useEditorContext } from "../context";
import {
SegmentContextProvider,
@@ -10,6 +16,8 @@ import {
useTrackContext,
} from "./context";
+export const CAP_TRACK_FILL_CLASS = "cap-track-fill";
+
export function TrackRoot(props: ComponentProps<"div">) {
const [ref, setRef] = createSignal<HTMLDivElement>();
const height = "var(--track-height, 3.25rem)";
@@ -56,48 +64,68 @@ export function useSegmentWidth(segment: () => { start: number; end: number }) {
export function SegmentRoot(
props: ComponentProps<"div"> & {
innerClass: string;
+ segColor?: string;
segment: { start: number; end: number };
+ forceVisible?: boolean;
onMouseDown?: (
e: MouseEvent & { currentTarget: HTMLDivElement; target: Element },
) => void;
},
) {
+ const [local, rest] = splitProps(props, [
+ "innerClass",
+ "segColor",
+ "segment",
+ "forceVisible",
+ "onMouseDown",
+ "class",
+ "style",
+ "ref",
+ "children",
+ ]);
const { editorState } = useEditorContext();
const { isSegmentVisible } = useTimelineContext();
- const translateX = useSegmentTranslateX(() => props.segment);
- const width = useSegmentWidth(() => props.segment);
- // Virtualize off-screen segments: Solid memos are lazy, so gating the
- // rendered element behind visibility means translateX/width never recompute
- // for segments outside the timeline viewport during scroll/zoom.
- const visible = createMemo(() =>
- isSegmentVisible(props.segment.start, props.segment.end),
+ const translateX = useSegmentTranslateX(() => local.segment);
+ const width = useSegmentWidth(() => local.segment);
+ const visible = createMemo(
+ () =>
+ local.forceVisible ||
+ isSegmentVisible(local.segment.start, local.segment.end),
);
return (
<Show when={visible()}>
<SegmentContextProvider width={width}>
<div
- {...props}
+ {...rest}
class={cx(
"absolute overflow-visible border rounded-xl inset-y-0",
editorState.timeline.interactMode === "split" &&
"timeline-scissors-cursor",
- props.class,
+ local.class,
)}
style={{
"--segment-x": `${translateX()}px`,
transform: "translateX(var(--segment-x))",
width: `${width()}px`,
+ ...(typeof local.style === "object" ? local.style : {}),
}}
- ref={props.ref}
+ onMouseDown={local.onMouseDown}
+ ref={local.ref}
>
<div
class={cx(
+ CAP_TRACK_FILL_CLASS,
"relative h-full flex flex-row rounded-xl overflow-hidden group",
- props.innerClass,
+ local.innerClass,
)}
+ style={
+ local.segColor
+ ? ({ "--seg-color": local.segColor } as Record<string, string>)
+ : undefined
+ }
>
- {props.children}
+ {local.children}
</div>
</div>
</SegmentContextProvider>
diff --git a/apps/desktop/src/routes/editor/Timeline/styles.css b/apps/desktop/src/routes/editor/Timeline/styles.css
index 12084fda3..43dc511ad 100644
--- a/apps/desktop/src/routes/editor/Timeline/styles.css
+++ b/apps/desktop/src/routes/editor/Timeline/styles.css
@@ -8,3 +8,19 @@
.timeline-scissors-cursor * {
cursor: inherit;
}
+
+.timeline-fade-cursor {
+ cursor:
+ url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='26' height='20' viewBox='0 0 26 20' shape-rendering='geometricPrecision'%3E%3Crect x='1' y='1' width='24' height='18' rx='1.5' fill='%23ffffff' stroke='%23222222' stroke-width='1'/%3E%3Cpath d='M4.5 14.5C4.5 10 5.2 7 8.2 5.2' fill='none' stroke='%23111111' stroke-width='1.35' stroke-linecap='round'/%3E%3Cpath d='M14.5 10h7.5M14.5 10H7' stroke='%23111111' stroke-width='1.55' stroke-linecap='round'/%3E%3Cpath d='M20.5 7.4l2.4 2.6-2.4 2.6M7.5 7.4L5.1 10l2.4 2.6' fill='none' stroke='%23111111' stroke-width='1.25' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
+ 13 10,
+ ew-resize;
+}
+
+.timeline-fade-cursor * {
+ cursor: inherit;
+}
+
+.cap-track-fill {
+ background: var(--seg-color);
+ border: 1px solid color-mix(in srgb, var(--seg-color) 58%, black);
+}