Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

improved cursor smoothing

Siddharthe49cc02d75fa
diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsx
index 22a11ec23..dc965d9b2 100644
--- a/src/components/video-editor/VideoPlayback.tsx
+++ b/src/components/video-editor/VideoPlayback.tsx
@@ -26,9 +26,9 @@ import {
type WebcamLayoutPreset,
type WebcamSizePreset,
} from "@/lib/compositeLayout";
+import { getSmoothedCursorPath } from "@/lib/cursor/cursorPathSmoothing";
import {
createNativeCursorMotionBlurState,
- createNativeCursorSmoothingState,
getNativeCursorClickBounceProgress,
getNativeCursorClickBounceScale,
getNativeCursorMotionBlurPx,
@@ -36,10 +36,8 @@ import {
projectNativeCursorToLocal,
projectNativeCursorToStage,
resetNativeCursorMotionBlurState,
- resetNativeCursorSmoothingState,
resolveInterpolatedNativeCursorFrame,
resolveNativeCursorRenderAsset,
- smoothNativeCursorSample,
} from "@/lib/cursor/nativeCursor";
import { classifyWallpaper, DEFAULT_WALLPAPER, resolveImageWallpaperUrl } from "@/lib/wallpaper";
import { getCssClipPath } from "@/lib/webcamMaskShapes";
@@ -375,7 +373,6 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
const nativeCursorTextureIdRef = useRef<string | null>(null);
const nativeCursorImageRef = useRef<HTMLImageElement | null>(null);
const nativeCursorImageIdRef = useRef<string | null>(null);
- const nativeCursorSmoothingStateRef = useRef(createNativeCursorSmoothingState());
const nativeCursorMotionBlurStateRef = useRef(createNativeCursorMotionBlurState());
const nativeCursorClipRef = useRef<HTMLDivElement | null>(null);
const borderRadiusRef = useRef<number>(0);
@@ -833,7 +830,6 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
useEffect(() => {
cursorRecordingDataRef.current = cursorRecordingData;
- resetNativeCursorSmoothingState(nativeCursorSmoothingStateRef.current);
resetNativeCursorMotionBlurState(nativeCursorMotionBlurStateRef.current);
}, [cursorRecordingData]);
@@ -1565,7 +1561,6 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
if (nativeCursorClipRef.current) {
nativeCursorClipRef.current.style.clipPath = "";
}
- resetNativeCursorSmoothingState(nativeCursorSmoothingStateRef.current);
resetNativeCursorMotionBlurState(nativeCursorMotionBlurStateRef.current);
};
if (nativeCursorImage) {
@@ -1576,13 +1571,15 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
timeMs,
);
if (frame) {
- const displaySample = smoothNativeCursorSample({
- forceSnap: !isPlayingRef.current || isSeekingRef.current,
- sample: frame.sample,
- smoothing: cursorSmoothingRef.current,
- state: nativeCursorSmoothingStateRef.current,
- timeMs,
- });
+ // Position comes from the precomputed offline-smoothed path; the frame still
+ // supplies the cursor image, type, and click timing.
+ const smoothedPos = getSmoothedCursorPath(
+ cursorRecordingDataRef.current,
+ cursorSmoothingRef.current,
+ )?.sampleAt(timeMs);
+ const displaySample = smoothedPos
+ ? { ...frame.sample, cx: smoothedPos.cx, cy: smoothedPos.cy }
+ : frame.sample;
const cameraContainer = cameraContainerRef.current;
const videoContainer = videoContainerRef.current;
const cropRegionValue = cropRegionRef.current ?? { x: 0, y: 0, width: 1, height: 1 };
diff --git a/src/lib/cursor/cursorPathSmoothing.test.ts b/src/lib/cursor/cursorPathSmoothing.test.ts
new file mode 100644
index 000000000..deea614ea
--- /dev/null
+++ b/src/lib/cursor/cursorPathSmoothing.test.ts
@@ -0,0 +1,110 @@
+import { describe, expect, it } from "vitest";
+import type { CursorRecordingData, CursorRecordingSample } from "@/native/contracts";
+import { getSmoothedCursorPath } from "./cursorPathSmoothing";
+
+function makeRecording(samples: CursorRecordingSample[]): CursorRecordingData {
+ return { version: 2, provider: "native", assets: [], samples };
+}
+
+/** Sum of squared second differences of x sampled on a uniform grid — a roughness proxy. */
+function roughness(
+ sampleAt: (t: number) => { cx: number; cy: number } | null,
+ t0: number,
+ t1: number,
+) {
+ const xs: number[] = [];
+ for (let t = t0; t <= t1; t += 5) {
+ const p = sampleAt(t);
+ if (p) xs.push(p.cx);
+ }
+ let acc = 0;
+ for (let i = 2; i < xs.length; i++) {
+ const d2 = xs[i] - 2 * xs[i - 1] + xs[i - 2];
+ acc += d2 * d2;
+ }
+ return acc;
+}
+
+describe("cursor path smoothing", () => {
+ it("removes high-frequency jitter while tracking the overall path", () => {
+ // A rightward drift with alternating zig-zag noise on cy, then a dwell at the end.
+ const samples: CursorRecordingSample[] = [];
+ for (let i = 0; i <= 40; i++) {
+ samples.push({
+ timeMs: i * 33,
+ cx: 0.2 + (i / 40) * 0.6,
+ cy: 0.5 + (i % 2 === 0 ? 0.05 : -0.05),
+ visible: true,
+ });
+ }
+ const driftEnd = samples[samples.length - 1].timeMs;
+ for (let i = 1; i <= 60; i++) {
+ samples.push({ timeMs: driftEnd + i * 33, cx: 0.8, cy: 0.5, visible: true });
+ }
+ const data = makeRecording(samples);
+ const smoothed = getSmoothedCursorPath(data, 0.7)!;
+ const raw = getSmoothedCursorPath(makeRecording(samples), 0)!;
+
+ // Compare jitter on the cy channel (where the zig-zag lives) over the moving portion.
+ const cyAt = (path: typeof smoothed) => (t: number) => {
+ const p = path.sampleAt(t);
+ return p ? { cx: p.cy, cy: p.cx } : null;
+ };
+ const smoothRough = roughness(cyAt(smoothed), 0, driftEnd);
+ const rawRough = roughness(cyAt(raw), 0, driftEnd);
+ expect(smoothRough).toBeLessThan(rawRough * 0.25);
+
+ // After the cursor rests, the spring settles onto the true target (click accuracy).
+ const end = samples[samples.length - 1].timeMs;
+ const last = smoothed.sampleAt(end)!;
+ expect(last.cx).toBeCloseTo(0.8, 2);
+ expect(last.cy).toBeCloseTo(0.5, 2);
+ });
+
+ it("is a passthrough at smoothing 0", () => {
+ const samples: CursorRecordingSample[] = [
+ { timeMs: 0, cx: 0.1, cy: 0.1, visible: true },
+ { timeMs: 100, cx: 0.9, cy: 0.4, visible: true },
+ ];
+ const path = getSmoothedCursorPath(makeRecording(samples), 0)!;
+ expect(path.sampleAt(0)).toEqual({ cx: 0.1, cy: 0.1 });
+ expect(path.sampleAt(50)!.cx).toBeCloseTo(0.5, 5);
+ expect(path.sampleAt(100)).toEqual({ cx: 0.9, cy: 0.4 });
+ });
+
+ it("respects visibility gaps and never smooths across them", () => {
+ const samples: CursorRecordingSample[] = [
+ { timeMs: 0, cx: 0.2, cy: 0.2, visible: true },
+ { timeMs: 100, cx: 0.3, cy: 0.3, visible: true },
+ { timeMs: 150, cx: 0.3, cy: 0.3, visible: false },
+ { timeMs: 200, cx: 0.8, cy: 0.8, visible: true },
+ { timeMs: 300, cx: 0.9, cy: 0.9, visible: true },
+ ];
+ const path = getSmoothedCursorPath(makeRecording(samples), 0.6)!;
+ expect(path.sampleAt(50)).not.toBeNull();
+ expect(path.sampleAt(160)).toBeNull(); // inside the hidden gap
+ expect(path.sampleAt(250)).not.toBeNull();
+ });
+
+ it("is deterministic for identical inputs", () => {
+ const build = () =>
+ getSmoothedCursorPath(
+ makeRecording([
+ { timeMs: 0, cx: 0.1, cy: 0.5, visible: true },
+ { timeMs: 50, cx: 0.4, cy: 0.55, visible: true },
+ { timeMs: 120, cx: 0.7, cy: 0.45, visible: true },
+ ]),
+ 0.65,
+ )!;
+ const a = build();
+ const b = build();
+ for (const t of [0, 25, 60, 90, 120]) {
+ expect(a.sampleAt(t)).toEqual(b.sampleAt(t));
+ }
+ });
+
+ it("returns null when there is no cursor data", () => {
+ expect(getSmoothedCursorPath(null, 0.5)).toBeNull();
+ expect(getSmoothedCursorPath(makeRecording([]), 0.5)).toBeNull();
+ });
+});
diff --git a/src/lib/cursor/cursorPathSmoothing.ts b/src/lib/cursor/cursorPathSmoothing.ts
new file mode 100644
index 000000000..cc59cc7fd
--- /dev/null
+++ b/src/lib/cursor/cursorPathSmoothing.ts
@@ -0,0 +1,272 @@
+import { getCursorSpringConfig } from "@/components/video-editor/videoPlayback/motionSmoothing";
+import type { CursorRecordingData, CursorRecordingSample } from "@/native/contracts";
+
+/**
+ * Offline cursor-path smoothing for native recordings.
+ *
+ * Live preview/export used to run a per-frame exponential filter over the cursor — causal,
+ * framerate-dependent, and momentum-free. Because post-processing has the entire path up front, we
+ * instead precompute a smoothed path once: resample to a fixed high rate, lightly denoise away
+ * capture tremor, then drive a spring-damper (mass/stiffness/damping) over the result. The spring
+ * gives the motion natural inertia — it trails the real cursor like a weight on a string — which
+ * reads as a professional glide. The result is deterministic, so preview and export match exactly.
+ */
+
+export interface SmoothedCursorPosition {
+ cx: number;
+ cy: number;
+}
+
+export interface SmoothedCursorPath {
+ /** Smoothed normalized position at a time, or null when the cursor is hidden there. */
+ sampleAt(timeMs: number): SmoothedCursorPosition | null;
+}
+
+/** Integration grid: 240 steps/sec keeps the spring stable and the output crisp at any playback fps. */
+const STEP_MS = 1000 / 240;
+const STEP_S = STEP_MS / 1000;
+
+interface SmoothedRun {
+ start: number;
+ end: number;
+ times: Float32Array;
+ xs: Float32Array;
+ ys: Float32Array;
+}
+
+function clamp(value: number, min: number, max: number) {
+ return Math.min(max, Math.max(min, value));
+}
+
+function binarySearchAtOrBefore(
+ times: Float32Array | number[],
+ timeMs: number,
+ hi: number,
+): number {
+ let low = 0;
+ let high = hi;
+ let result = -1;
+ while (low <= high) {
+ const mid = low + ((high - low) >> 1);
+ if (times[mid] <= timeMs) {
+ result = mid;
+ low = mid + 1;
+ } else {
+ high = mid - 1;
+ }
+ }
+ return result;
+}
+
+/** Linear interpolation of a sample run's position at an arbitrary time. */
+function interpolateRun(samples: CursorRecordingSample[], timeMs: number): SmoothedCursorPosition {
+ const last = samples.length - 1;
+ if (timeMs <= samples[0].timeMs) return { cx: samples[0].cx, cy: samples[0].cy };
+ if (timeMs >= samples[last].timeMs) return { cx: samples[last].cx, cy: samples[last].cy };
+ const i = binarySearchAtOrBefore(
+ samples.map((s) => s.timeMs),
+ timeMs,
+ last,
+ );
+ const a = samples[i];
+ const b = samples[i + 1] ?? a;
+ const span = b.timeMs - a.timeMs;
+ if (span <= 0) return { cx: a.cx, cy: a.cy };
+ const t = (timeMs - a.timeMs) / span;
+ return { cx: a.cx + (b.cx - a.cx) * t, cy: a.cy + (b.cy - a.cy) * t };
+}
+
+/** In-place 1D Gaussian blur with reflected edges. radius and weights derived from sigma (in steps). */
+function gaussianSmooth(values: Float32Array, sigmaSteps: number): Float32Array {
+ if (sigmaSteps <= 0 || values.length < 3) return values;
+ const radius = Math.max(1, Math.ceil(sigmaSteps * 3));
+ const kernel = new Float32Array(radius * 2 + 1);
+ const denom = 2 * sigmaSteps * sigmaSteps;
+ let sum = 0;
+ for (let k = -radius; k <= radius; k++) {
+ const w = Math.exp(-(k * k) / denom);
+ kernel[k + radius] = w;
+ sum += w;
+ }
+ for (let k = 0; k < kernel.length; k++) kernel[k] /= sum;
+
+ const out = new Float32Array(values.length);
+ const n = values.length;
+ for (let i = 0; i < n; i++) {
+ let acc = 0;
+ for (let k = -radius; k <= radius; k++) {
+ let idx = i + k;
+ // Reflect at the boundaries so the ends aren't pulled toward zero.
+ if (idx < 0) idx = -idx;
+ else if (idx >= n) idx = 2 * n - 2 - idx;
+ idx = clamp(idx, 0, n - 1);
+ acc += values[idx] * kernel[k + radius];
+ }
+ out[i] = acc;
+ }
+ return out;
+}
+
+/**
+ * Drive a critically-tunable spring across `targets`, returning the smoothed series. Semi-implicit
+ * (symplectic) Euler in seconds — stable for these stiffness values at the 240Hz grid.
+ */
+function springSmooth(
+ targets: Float32Array,
+ stiffness: number,
+ damping: number,
+ mass: number,
+): Float32Array {
+ const out = new Float32Array(targets.length);
+ if (targets.length === 0) return out;
+ let x = targets[0];
+ let v = 0;
+ out[0] = x;
+ for (let i = 1; i < targets.length; i++) {
+ const accel = (-stiffness * (x - targets[i]) - damping * v) / mass;
+ v += accel * STEP_S;
+ x += v * STEP_S;
+ out[i] = x;
+ }
+ return out;
+}
+
+/** Maximal sequences of visible samples — we never smooth across a hidden gap. */
+function splitVisibleRuns(samples: CursorRecordingSample[]): CursorRecordingSample[][] {
+ const runs: CursorRecordingSample[][] = [];
+ let current: CursorRecordingSample[] = [];
+ for (const sample of samples) {
+ if (sample.visible === false) {
+ if (current.length) runs.push(current);
+ current = [];
+ continue;
+ }
+ current.push(sample);
+ }
+ if (current.length) runs.push(current);
+ return runs;
+}
+
+function buildSmoothedRun(
+ samples: CursorRecordingSample[],
+ sigmaSteps: number,
+ stiffness: number,
+ damping: number,
+ mass: number,
+): SmoothedRun {
+ const start = samples[0].timeMs;
+ const end = samples[samples.length - 1].timeMs;
+ const stepCount = Math.max(1, Math.round((end - start) / STEP_MS));
+ const n = stepCount + 1;
+ const times = new Float32Array(n);
+ const rawX = new Float32Array(n);
+ const rawY = new Float32Array(n);
+ for (let i = 0; i < n; i++) {
+ const t = i === n - 1 ? end : start + i * STEP_MS;
+ times[i] = t;
+ const p = interpolateRun(samples, t);
+ rawX[i] = p.cx;
+ rawY[i] = p.cy;
+ }
+ const denoisedX = gaussianSmooth(rawX, sigmaSteps);
+ const denoisedY = gaussianSmooth(rawY, sigmaSteps);
+ return {
+ start,
+ end,
+ times,
+ xs: springSmooth(denoisedX, stiffness, damping, mass),
+ ys: springSmooth(denoisedY, stiffness, damping, mass),
+ };
+}
+
+function sampleRun(run: SmoothedRun, timeMs: number): SmoothedCursorPosition {
+ const last = run.times.length - 1;
+ if (timeMs <= run.times[0]) return { cx: run.xs[0], cy: run.ys[0] };
+ if (timeMs >= run.times[last]) return { cx: run.xs[last], cy: run.ys[last] };
+ const i = binarySearchAtOrBefore(run.times, timeMs, last);
+ const span = run.times[i + 1] - run.times[i];
+ if (span <= 0) return { cx: run.xs[i], cy: run.ys[i] };
+ const t = (timeMs - run.times[i]) / span;
+ return {
+ cx: run.xs[i] + (run.xs[i + 1] - run.xs[i]) * t,
+ cy: run.ys[i] + (run.ys[i + 1] - run.ys[i]) * t,
+ };
+}
+
+/** Passthrough path (smoothing 0): raw linear interpolation, still respecting visibility gaps. */
+function buildRawPath(runs: CursorRecordingSample[][]): SmoothedCursorPath {
+ return {
+ sampleAt(timeMs) {
+ for (const run of runs) {
+ if (timeMs >= run[0].timeMs && timeMs <= run[run.length - 1].timeMs) {
+ return interpolateRun(run, timeMs);
+ }
+ }
+ return null;
+ },
+ };
+}
+
+function buildSmoothedPath(
+ recordingData: CursorRecordingData,
+ smoothing01: number,
+): SmoothedCursorPath {
+ const runs = splitVisibleRuns(recordingData.samples).filter((run) => run.length > 0);
+ if (runs.length === 0) {
+ return { sampleAt: () => null };
+ }
+ if (smoothing01 <= 0) {
+ return buildRawPath(runs);
+ }
+
+ // Map the 0–1 UI strength onto the shared spring config (its useful domain is 0–2).
+ const config = getCursorSpringConfig(clamp(smoothing01, 0, 1) * 2);
+ // Light denoise that grows slightly with strength (~12–28ms sigma), expressed in grid steps.
+ const sigmaSteps = (12 + smoothing01 * 16) / STEP_MS;
+
+ const smoothedRuns = runs.map((run) =>
+ run.length < 2
+ ? {
+ start: run[0].timeMs,
+ end: run[0].timeMs,
+ times: new Float32Array([run[0].timeMs]),
+ xs: new Float32Array([run[0].cx]),
+ ys: new Float32Array([run[0].cy]),
+ }
+ : buildSmoothedRun(run, sigmaSteps, config.stiffness, config.damping, config.mass),
+ );
+
+ return {
+ sampleAt(timeMs) {
+ for (const run of smoothedRuns) {
+ if (timeMs >= run.start && timeMs <= run.end) return sampleRun(run, timeMs);
+ }
+ return null;
+ },
+ };
+}
+
+const pathCache = new WeakMap<CursorRecordingData, Map<string, SmoothedCursorPath>>();
+
+/**
+ * Returns the smoothed cursor path for a recording at a given strength, memoized per
+ * (recordingData, strength) so it's built once and shared by preview and export.
+ */
+export function getSmoothedCursorPath(
+ recordingData: CursorRecordingData | null | undefined,
+ smoothing01: number,
+): SmoothedCursorPath | null {
+ if (!recordingData || recordingData.samples.length === 0) return null;
+ const key = (Number.isFinite(smoothing01) ? clamp(smoothing01, 0, 1) : 0).toFixed(2);
+ let byStrength = pathCache.get(recordingData);
+ if (!byStrength) {
+ byStrength = new Map();
+ pathCache.set(recordingData, byStrength);
+ }
+ let path = byStrength.get(key);
+ if (!path) {
+ path = buildSmoothedPath(recordingData, Number.parseFloat(key));
+ byStrength.set(key, path);
+ }
+ return path;
+}
diff --git a/src/lib/cursor/nativeCursor.ts b/src/lib/cursor/nativeCursor.ts
index c2afacd1f..11dabe3af 100644
--- a/src/lib/cursor/nativeCursor.ts
+++ b/src/lib/cursor/nativeCursor.ts
@@ -30,13 +30,6 @@ export interface ActiveNativeCursorFrame {
sample: CursorRecordingSample;
}
-export interface NativeCursorSmoothingState {
- cx: number;
- cy: number;
- lastTimeMs: number | null;
- initialized: boolean;
-}
-
export interface NativeCursorMotionBlurState {
x: number;
y: number;
@@ -278,22 +271,6 @@ export function hasNativeCursorRecordingData(
);
}
-export function createNativeCursorSmoothingState(): NativeCursorSmoothingState {
- return {
- cx: 0,
- cy: 0,
- lastTimeMs: null,
- initialized: false,
- };
-}
-
-export function resetNativeCursorSmoothingState(state: NativeCursorSmoothingState) {
- state.cx = 0;
- state.cy = 0;
- state.lastTimeMs = null;
- state.initialized = false;
-}
-
export function createNativeCursorMotionBlurState(): NativeCursorMotionBlurState {
return {
x: 0,
@@ -310,49 +287,6 @@ export function resetNativeCursorMotionBlurState(state: NativeCursorMotionBlurSt
state.initialized = false;
}
-export function smoothNativeCursorSample({
- forceSnap = false,
- sample,
- smoothing,
- state,
- timeMs,
-}: {
- forceSnap?: boolean;
- sample: CursorRecordingSample;
- smoothing: number;
- state: NativeCursorSmoothingState;
- timeMs: number;
-}): CursorRecordingSample {
- const clampedSmoothing = clamp(Number.isFinite(smoothing) ? smoothing : 0, 0, 0.98);
- const previousTimeMs = state.lastTimeMs;
- const shouldSnap =
- forceSnap ||
- clampedSmoothing <= 0 ||
- !state.initialized ||
- previousTimeMs === null ||
- timeMs <= previousTimeMs;
-
- if (shouldSnap) {
- state.cx = sample.cx;
- state.cy = sample.cy;
- state.lastTimeMs = timeMs;
- state.initialized = true;
- return sample;
- }
-
- const frameCount = Math.max(1, (timeMs - previousTimeMs) / (1000 / 60));
- const alpha = 1 - Math.pow(clampedSmoothing, frameCount);
- state.cx += (sample.cx - state.cx) * alpha;
- state.cy += (sample.cy - state.cy) * alpha;
- state.lastTimeMs = timeMs;
-
- return {
- ...sample,
- cx: state.cx,
- cy: state.cy,
- };
-}
-
export function getNativeCursorClickBounceProgress(
recordingData: CursorRecordingData | null | undefined,
timeMs: number,
diff --git a/src/lib/exporter/frameRenderer.ts b/src/lib/exporter/frameRenderer.ts
index 5379890bc..2e19b35e3 100644
--- a/src/lib/exporter/frameRenderer.ts
+++ b/src/lib/exporter/frameRenderer.ts
@@ -51,18 +51,16 @@ import {
type Size,
type StyledRenderRect,
} from "@/lib/compositeLayout";
+import { getSmoothedCursorPath } from "@/lib/cursor/cursorPathSmoothing";
import {
createNativeCursorMotionBlurState,
- createNativeCursorSmoothingState,
getNativeCursorClickBounceProgress,
getNativeCursorClickBounceScale,
getNativeCursorMotionBlurPx,
projectNativeCursorToLocal,
resetNativeCursorMotionBlurState,
- resetNativeCursorSmoothingState,
resolveInterpolatedNativeCursorFrame,
resolveNativeCursorRenderAsset,
- smoothNativeCursorSample,
} from "@/lib/cursor/nativeCursor";
import { BackgroundLoadError, classifyWallpaper, resolveImageWallpaperUrl } from "@/lib/wallpaper";
import { drawCanvasClipPath } from "@/lib/webcamMaskShapes";
@@ -162,7 +160,6 @@ export class FrameRenderer {
private layoutCache: LayoutCache | null = null;
private currentVideoTime = 0;
private motionBlurState: MotionBlurState = createMotionBlurState();
- private nativeCursorSmoothingState = createNativeCursorSmoothingState();
private nativeCursorMotionBlurState = createNativeCursorMotionBlurState();
private smoothedAutoFocus: { cx: number; cy: number } | null = null;
private prevAnimationTimeMs: number | null = null;
@@ -555,7 +552,6 @@ export class FrameRenderer {
}
if ((this.config.cursorScale ?? 1) <= 0) {
- resetNativeCursorSmoothingState(this.nativeCursorSmoothingState);
resetNativeCursorMotionBlurState(this.nativeCursorMotionBlurState);
return;
}
@@ -565,16 +561,18 @@ export class FrameRenderer {
timeMs,
);
if (!activeNativeCursor) {
- resetNativeCursorSmoothingState(this.nativeCursorSmoothingState);
resetNativeCursorMotionBlurState(this.nativeCursorMotionBlurState);
return;
}
- const displaySample = smoothNativeCursorSample({
- sample: activeNativeCursor.sample,
- smoothing: this.config.cursorSmoothing ?? 0,
- state: this.nativeCursorSmoothingState,
- timeMs,
- });
+ // Position comes from the precomputed offline-smoothed path (deterministic, matches preview);
+ // the frame still supplies the cursor image, type, and click timing.
+ const smoothedPos = getSmoothedCursorPath(
+ this.config.cursorRecordingData,
+ this.config.cursorSmoothing ?? 0,
+ )?.sampleAt(timeMs);
+ const displaySample = smoothedPos
+ ? { ...activeNativeCursor.sample, cx: smoothedPos.cx, cy: smoothedPos.cy }
+ : activeNativeCursor.sample;
const projectedPoint = projectNativeCursorToLocal({
cropRegion: this.config.cropRegion,
@@ -582,7 +580,6 @@ export class FrameRenderer {
sample: displaySample,
});
if (!projectedPoint) {
- resetNativeCursorSmoothingState(this.nativeCursorSmoothingState);
resetNativeCursorMotionBlurState(this.nativeCursorMotionBlurState);
return;
}