Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: add cursor style and ripple controls to the desktop editor

Richie McIlroybe6a59f9e741
diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
index 59f0fb9c9..037114aa9 100644
--- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx
+++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx
@@ -70,7 +70,6 @@ import {
type CaptionTrackSegment,
type ClipOffsets,
type CursorAnimationStyle,
- type CursorType,
commands,
type KeyboardTrackSegment,
type NotchConfiguration,
@@ -121,6 +120,11 @@ import {
} from "./audio";
import { BrandColorsDropdown } from "./BrandColorsDropdown";
import { ColorCorrectionSection } from "./ColorCorrectionSection";
+import {
+ CursorRippleSection,
+ CursorStylePicker,
+ isExplicitCursorFamily,
+} from "./CursorStylePicker";
import { syncCaptionWordsWithText } from "./captions";
import { type ClipTransition, clipSourceTimeAt } from "./clip-transitions";
import { getColorPreviewBorderColor, hexToRgb, RgbInput } from "./color-utils";
@@ -428,19 +432,6 @@ type CursorPresetValues = {
const DEFAULT_MOTION_BLUR = 1.0;
-const CURSOR_TYPE_OPTIONS = [
- {
- value: "auto" as CursorType,
- label: "Auto",
- description: "Uses the actual cursor from your recording.",
- },
- {
- value: "circle" as CursorType,
- label: "Circle",
- description: "A touch-style circle cursor like mobile simulators.",
- },
-];
-
const CURSOR_ANIMATION_STYLE_OPTIONS = [
{
value: "slow",
@@ -841,35 +832,7 @@ export function ConfigSidebar() {
}
/>
<Show when={!project.cursor.hide}>
- <Field name="Cursor Type" icon={<IconCapCursor />}>
- <RadioGroup
- class="flex flex-col gap-2"
- value={project.cursor.type}
- onChange={(value) =>
- setProject("cursor", "type", value as CursorType)
- }
- >
- {CURSOR_TYPE_OPTIONS.map((option) => (
- <RadioGroup.Item
- value={option.value}
- class="rounded-lg border border-gray-3 transition-colors data-checked:border-blue-8 data-checked:bg-blue-3/40"
- >
- <RadioGroup.ItemInput class="sr-only" />
- <RadioGroup.ItemLabel class="flex items-start gap-3 p-3">
- <RadioGroup.ItemControl class="mt-1 size-4 rounded-full border border-gray-7 data-checked:border-blue-9 data-checked:bg-blue-9" />
- <div class="flex flex-col text-left">
- <span class="text-sm font-medium text-gray-12">
- {option.label}
- </span>
- <span class="text-xs text-gray-11">
- {option.description}
- </span>
- </div>
- </RadioGroup.ItemLabel>
- </RadioGroup.Item>
- ))}
- </RadioGroup>
- </Field>
+ <CursorStylePicker />
<Field name="Size" icon={<IconCapEnlarge />}>
<Slider
value={[project.cursor.size]}
@@ -889,6 +852,7 @@ export function ConfigSidebar() {
formatTooltip={(value) => `${Math.round(value * 100)}%`}
/>
</Field>
+ <CursorRippleSection />
<Field
name="Hide When Idle"
icon={<IconLucideTimer class="size-4" />}
@@ -1000,18 +964,20 @@ export function ConfigSidebar() {
</div>
</KCollapsible.Content>
</KCollapsible>
- <Field
- name="High Quality SVG Cursors"
- icon={<IconLucideSparkles />}
- value={
- <Toggle
- checked={project.cursor.useSvg ?? true}
- onChange={(value) => {
- setProject("cursor", "useSvg", value);
- }}
- />
- }
- />
+ <Show when={!isExplicitCursorFamily(project.cursor.type)}>
+ <Field
+ name="High Quality SVG Cursors"
+ icon={<IconLucideSparkles />}
+ value={
+ <Toggle
+ checked={project.cursor.useSvg ?? true}
+ onChange={(value) => {
+ setProject("cursor", "useSvg", value);
+ }}
+ />
+ }
+ />
+ </Show>
</Show>
{/* <Field name="Animation Style" icon={<IconLucideRabbit />}>
diff --git a/apps/desktop/src/routes/editor/CursorStylePicker.tsx b/apps/desktop/src/routes/editor/CursorStylePicker.tsx
new file mode 100644
index 000000000..90fef4d8b
--- /dev/null
+++ b/apps/desktop/src/routes/editor/CursorStylePicker.tsx
@@ -0,0 +1,213 @@
+import { Collapsible as KCollapsible } from "@kobalte/core/collapsible";
+import { RadioGroup as KRadioGroup } from "@kobalte/core/radio-group";
+import { type as ostype } from "@tauri-apps/plugin-os";
+import { createMemo, For, Show } from "solid-js";
+import { Toggle } from "~/components/Toggle";
+import Tooltip from "~/components/Tooltip";
+import type { CursorRippleConfig, CursorType } from "~/utils/tauri";
+import IconLucideMousePointerClick from "~icons/lucide/mouse-pointer-click";
+import macArrow from "../../../../../crates/cursor-info/assets/mac/arrow.svg?raw";
+import tahoeArrow from "../../../../../crates/cursor-info/assets/mac/tahoe/default.svg?raw";
+import windowsArrow from "../../../../../crates/cursor-info/assets/windows/arrow.svg?raw";
+import { RgbInput } from "./color-utils";
+import { type TransformedMeta, useEditorContext } from "./context";
+import { Field, Slider } from "./ui";
+
+export type CursorFamily = "macos" | "tahoe" | "windows";
+type CursorStyle = CursorFamily | "circle";
+
+// One arrow per family: the arrow is what makes a cursor family recognisable
+// at a glance, and the tile only has to say "this one", not exhibit the set.
+const CURSOR_FAMILIES = {
+ macos: { label: "macOS", arrow: macArrow },
+ tahoe: { label: "macOS Tahoe", arrow: tahoeArrow },
+ windows: { label: "Windows", arrow: windowsArrow },
+} satisfies Record<CursorFamily, { label: string; arrow: string }>;
+
+export const DEFAULT_CURSOR_RIPPLE: CursorRippleConfig = {
+ enabled: false,
+ color: [71, 133, 255],
+ strength: 0.7,
+ size: 1,
+ duration: 0.6,
+};
+
+export function cursorFamilyFromShape(
+ shape: string | null | undefined,
+): CursorFamily | undefined {
+ if (!shape) return undefined;
+ const [namespace, name] = shape.split("|");
+ if (namespace === "Windows") return "windows";
+ if (namespace === "MacOS")
+ return name?.startsWith("Tahoe") ? "tahoe" : "macos";
+ return undefined;
+}
+
+export function recordedCursorFamily(
+ meta: TransformedMeta,
+): CursorFamily | undefined {
+ if (meta.type !== "multiple") return undefined;
+ for (const cursor of Object.values(meta.cursors)) {
+ if (typeof cursor === "string") continue;
+ const family = cursorFamilyFromShape(cursor.shape);
+ if (family) return family;
+ }
+ return undefined;
+}
+
+export function isExplicitCursorFamily(type: CursorType): type is CursorFamily {
+ return type === "macos" || type === "tahoe" || type === "windows";
+}
+
+function hostCursorFamily(): CursorFamily {
+ return ostype() === "windows" ? "windows" : "macos";
+}
+
+function cursorStyleOrder(): CursorStyle[] {
+ return ostype() === "windows"
+ ? ["windows", "macos", "tahoe", "circle"]
+ : ["macos", "tahoe", "windows", "circle"];
+}
+
+function CursorArrow(props: { svg: string }) {
+ // The assets carry their own black-on-white edge and a soft drop shadow,
+ // so they read on the plain tile in both themes, the same way a real
+ // cursor reads over a light or dark window.
+ return (
+ <div class="h-[34px] [&>svg]:h-full [&>svg]:w-auto" innerHTML={props.svg} />
+ );
+}
+
+// The renderer's touch circle (`create_circle_cursor`): a translucent disc
+// with a dark outer ring, a light inner ring and a faint shadow.
+function CircleCursor() {
+ return (
+ <div class="size-7 rounded-full bg-white/15 shadow-[0_0_0_1px_rgba(0,0,0,0.38),inset_0_0_0_1px_rgba(255,255,255,0.42),0_0_5px_rgba(0,0,0,0.16)]" />
+ );
+}
+
+function CursorStyleCard(props: { style: CursorStyle; recorded: boolean }) {
+ const label = () =>
+ props.style === "circle" ? "Circle" : CURSOR_FAMILIES[props.style].label;
+
+ const tile = () => (
+ <div class="flex h-[60px] w-full items-center justify-center rounded-[10px] border border-gray-3 bg-gray-2 transition-colors group-hover:border-gray-5 group-data-checked:border-blue-8 group-data-checked:bg-blue-3/40 group-data-checked:ring-1 group-data-checked:ring-blue-8 group-has-[input:focus-visible]:ring-2 group-has-[input:focus-visible]:ring-blue-8">
+ <Show
+ when={props.style !== "circle" && props.style}
+ fallback={<CircleCursor />}
+ >
+ {(family) => <CursorArrow svg={CURSOR_FAMILIES[family()].arrow} />}
+ </Show>
+ </div>
+ );
+
+ return (
+ <KRadioGroup.Item value={props.style} class="group min-w-0">
+ <KRadioGroup.ItemInput class="sr-only" />
+ <KRadioGroup.ItemLabel class="flex cursor-pointer flex-col items-center gap-1.5">
+ <Show when={props.recorded} fallback={tile()}>
+ <Tooltip content="Recorded with this cursor" childClass="w-full">
+ {tile()}
+ </Tooltip>
+ </Show>
+ <span class="max-w-full truncate text-[11px] font-medium leading-none text-gray-11 transition-colors group-hover:text-gray-12 group-data-checked:text-gray-12">
+ {label()}
+ </span>
+ </KRadioGroup.ItemLabel>
+ </KRadioGroup.Item>
+ );
+}
+
+export function CursorStylePicker() {
+ const { project, setProject, meta } = useEditorContext();
+
+ const recorded = createMemo(() => recordedCursorFamily(meta()));
+
+ // `auto` draws the recording's own family (or, without shape info, this
+ // host's), so that is the tile that reads as selected. Clicking always
+ // writes an explicit family; `auto` is never written back.
+ const selected = createMemo<CursorStyle>(() => {
+ const type = project.cursor.type;
+ if (type === "circle" || isExplicitCursorFamily(type)) return type;
+ return recorded() ?? hostCursorFamily();
+ });
+
+ return (
+ <Field name="Cursor Style" icon={<IconCapCursor />}>
+ <KRadioGroup
+ class="grid grid-cols-4 gap-2"
+ value={selected()}
+ onChange={(value) => setProject("cursor", "type", value as CursorType)}
+ >
+ <For each={cursorStyleOrder()}>
+ {(style) => (
+ <CursorStyleCard style={style} recorded={recorded() === style} />
+ )}
+ </For>
+ </KRadioGroup>
+ </Field>
+ );
+}
+
+export function CursorRippleSection() {
+ const { project, setProject } = useEditorContext();
+
+ const ripple = () => project.cursor.ripple ?? DEFAULT_CURSOR_RIPPLE;
+ const updateRipple = (patch: Partial<CursorRippleConfig>) =>
+ setProject("cursor", "ripple", { ...ripple(), ...patch });
+
+ return (
+ <KCollapsible open={ripple().enabled}>
+ <Field
+ name="Click Ripple"
+ icon={<IconLucideMousePointerClick class="size-4" />}
+ value={
+ <Toggle
+ checked={ripple().enabled}
+ onChange={(value) => updateRipple({ enabled: value })}
+ />
+ }
+ />
+ <KCollapsible.Content class="overflow-hidden border-b opacity-0 transition-opacity border-gray-3 animate-collapsible-up data-expanded:animate-collapsible-down data-expanded:opacity-100">
+ <div class="flex flex-col gap-4 pt-4 pb-6">
+ <Field name="Color">
+ <RgbInput
+ value={ripple().color}
+ onChange={(color) => updateRipple({ color })}
+ />
+ </Field>
+ <Field name="Strength">
+ <Slider
+ value={[Math.round(ripple().strength * 100)]}
+ onChange={(v) => updateRipple({ strength: v[0] / 100 })}
+ minValue={0}
+ maxValue={100}
+ step={1}
+ formatTooltip={(v) => `${Math.round(v)}%`}
+ />
+ </Field>
+ <Field name="Size">
+ <Slider
+ value={[Math.round(ripple().size * 100)]}
+ onChange={(v) => updateRipple({ size: v[0] / 100 })}
+ minValue={25}
+ maxValue={300}
+ step={1}
+ formatTooltip={(v) => `${Math.round(v)}%`}
+ />
+ </Field>
+ <Field name="Duration">
+ <Slider
+ value={[ripple().duration]}
+ onChange={(v) => updateRipple({ duration: v[0] })}
+ minValue={0.2}
+ maxValue={1.5}
+ step={0.05}
+ formatTooltip={(v) => `${v.toFixed(2)}s`}
+ />
+ </Field>
+ </div>
+ </KCollapsible.Content>
+ </KCollapsible>
+ );
+}