-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: cursor follow crop with text cursor focus mode #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -174,6 +174,7 @@ import { | |||||||||
| type ClipRegion, | ||||||||||
| type CropRegion, | ||||||||||
| type CursorClickEffectStyle, | ||||||||||
| type CursorFollowCropSettings, | ||||||||||
| type CursorStyle, | ||||||||||
| type CursorTelemetryPoint, | ||||||||||
| clampFocusToDepth, | ||||||||||
|
|
@@ -187,6 +188,7 @@ import { | |||||||||
| DEFAULT_CONNECTED_ZOOM_EASING, | ||||||||||
| DEFAULT_CONNECTED_ZOOM_GAP_MS, | ||||||||||
| DEFAULT_CROP_REGION, | ||||||||||
| DEFAULT_CURSOR_FOLLOW_CROP, | ||||||||||
| DEFAULT_CURSOR_STYLE, | ||||||||||
| DEFAULT_FIGURE_DATA, | ||||||||||
| DEFAULT_WEBCAM_OVERLAY, | ||||||||||
|
|
@@ -489,6 +491,9 @@ export default function VideoEditor() { | |||||||||
| const [padding, setPadding] = useState(initialEditorPreferences.padding); | ||||||||||
| const [frame, setFrame] = useState<string | null>(initialEditorPreferences.frame); | ||||||||||
| const [cropRegion, setCropRegion] = useState<CropRegion>(DEFAULT_CROP_REGION); | ||||||||||
| const [cursorFollowCrop, setCursorFollowCrop] = useState<CursorFollowCropSettings>( | ||||||||||
| DEFAULT_CURSOR_FOLLOW_CROP, | ||||||||||
| ); | ||||||||||
| const [webcam, setWebcam] = useState<WebcamOverlaySettings>( | ||||||||||
| initialEditorPreferences.webcam ?? DEFAULT_WEBCAM_OVERLAY, | ||||||||||
| ); | ||||||||||
|
|
@@ -1095,6 +1100,7 @@ export default function VideoEditor() { | |||||||||
| borderRadius, | ||||||||||
| padding, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| webcamUrl: | ||||||||||
| resolvedWebcamVideoUrl ?? | ||||||||||
|
|
@@ -1629,6 +1635,7 @@ export default function VideoEditor() { | |||||||||
| padding: Padding; | ||||||||||
| frame: string | null; | ||||||||||
| cropRegion: CropRegion; | ||||||||||
| cursorFollowCrop: CursorFollowCropSettings; | ||||||||||
| webcam: WebcamOverlaySettings; | ||||||||||
| zoomRegions: ZoomRegion[]; | ||||||||||
| trimRegions: TrimRegion[]; | ||||||||||
|
|
@@ -1737,6 +1744,7 @@ export default function VideoEditor() { | |||||||||
| padding, | ||||||||||
| frame, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| zoomRegions, | ||||||||||
| trimRegions, | ||||||||||
|
|
@@ -1803,6 +1811,7 @@ export default function VideoEditor() { | |||||||||
| borderRadius, | ||||||||||
| padding, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| zoomRegions, | ||||||||||
| trimRegions, | ||||||||||
|
|
@@ -1993,6 +2002,7 @@ export default function VideoEditor() { | |||||||||
| setPadding(normalizedEditor.padding); | ||||||||||
| setFrame(normalizedEditor.frame); | ||||||||||
| setCropRegion(normalizedEditor.cropRegion); | ||||||||||
| setCursorFollowCrop(normalizedEditor.cursorFollowCrop); | ||||||||||
| setWebcam(normalizedEditor.webcam); | ||||||||||
| setZoomRegions(normalizedEditor.zoomRegions); | ||||||||||
| setTrimRegions(normalizedEditor.trimRegions); | ||||||||||
|
|
@@ -4220,6 +4230,7 @@ export default function VideoEditor() { | |||||||||
| padding, | ||||||||||
| videoPadding: padding, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| webcamUrl: | ||||||||||
| resolvedWebcamVideoUrl ?? | ||||||||||
|
|
@@ -4403,6 +4414,7 @@ export default function VideoEditor() { | |||||||||
| borderRadius, | ||||||||||
| padding, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| webcamUrl: | ||||||||||
| resolvedWebcamVideoUrl ?? | ||||||||||
|
|
@@ -4704,6 +4716,7 @@ export default function VideoEditor() { | |||||||||
| borderRadius, | ||||||||||
| padding, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| resolvedWebcamVideoUrl, | ||||||||||
| annotationRegions, | ||||||||||
|
|
@@ -5118,6 +5131,7 @@ export default function VideoEditor() { | |||||||||
| padding={padding} | ||||||||||
| frame={frame} | ||||||||||
| cropRegion={cropRegion} | ||||||||||
| cursorFollowCrop={cursorFollowCrop} | ||||||||||
| webcam={webcam} | ||||||||||
| webcamVideoPath={webcam.sourcePath ? resolvedWebcamVideoUrl : null} | ||||||||||
| trimRegions={trimRegions} | ||||||||||
|
|
@@ -6338,6 +6352,10 @@ export default function VideoEditor() { | |||||||||
| cropRegion={cropRegion} | ||||||||||
| onCropChange={setCropRegion} | ||||||||||
| aspectRatio={aspectRatio} | ||||||||||
| cursorFollow={cursorFollowCrop} | ||||||||||
| onCursorFollowChange={setCursorFollowCrop} | ||||||||||
| cursorTelemetry={cursorTelemetry} | ||||||||||
| currentTimeMs={currentTime * 1000} | ||||||||||
|
Comment on lines
+6357
to
+6358
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the same telemetry variant as preview/export. The crop modal gets raw 💡 Minimal fix- cursorTelemetry={cursorTelemetry}
+ cursorTelemetry={effectiveCursorTelemetry}
currentTimeMs={currentTime * 1000}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| /> | ||||||||||
| <div className="mt-6 flex justify-end"> | ||||||||||
| <Button | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -165,6 +165,12 @@ import { | |||||||||
| resetCursorFollowCamera, | ||||||||||
| SNAP_TO_EDGES_RATIO_AUTO, | ||||||||||
| } from "./videoPlayback/cursorFollowCamera"; | ||||||||||
| import { | ||||||||||
| type CursorFollowCropState, | ||||||||||
| computeCursorFollowCrop, | ||||||||||
| createCursorFollowCropState, | ||||||||||
| resetCursorFollowCropState, | ||||||||||
| } from "./videoPlayback/cursorFollowCrop"; | ||||||||||
| import { clampFocusToStage as clampFocusToStageUtil } from "./videoPlayback/focusUtils"; | ||||||||||
| import { layoutVideoContent as layoutVideoContentUtil } from "./videoPlayback/layoutUtils"; | ||||||||||
| import { updateOverlayIndicator } from "./videoPlayback/overlayUtils"; | ||||||||||
|
|
@@ -350,6 +356,7 @@ interface VideoPlaybackProps { | |||||||||
| padding?: Padding | number; | ||||||||||
| frame?: string | null; | ||||||||||
| cropRegion?: import("./types").CropRegion; | ||||||||||
| cursorFollowCrop?: import("./types").CursorFollowCropSettings; | ||||||||||
| webcam?: WebcamOverlaySettings; | ||||||||||
| webcamVideoPath?: string | null; | ||||||||||
| trimRegions?: TrimRegion[]; | ||||||||||
|
|
@@ -433,6 +440,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |||||||||
| padding = DEFAULT_PADDING, | ||||||||||
| frame = null, | ||||||||||
| cropRegion, | ||||||||||
| cursorFollowCrop, | ||||||||||
| webcam, | ||||||||||
| webcamVideoPath, | ||||||||||
| trimRegions = [], | ||||||||||
|
|
@@ -611,6 +619,12 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |||||||||
| const cursorFollowCameraRef = useRef<CursorFollowCameraState>( | ||||||||||
| createCursorFollowCameraState(), | ||||||||||
| ); | ||||||||||
| const cursorFollowCropRef = useRef(cursorFollowCrop); | ||||||||||
| const cursorFollowCropStateRef = useRef<CursorFollowCropState>( | ||||||||||
| createCursorFollowCropState(), | ||||||||||
| ); | ||||||||||
| const baseCropRegionRef = useRef(cropRegion); | ||||||||||
| const effectiveCropRegionRef = useRef(cropRegion); | ||||||||||
|
|
||||||||||
| const initializePixiRenderer = useCallback( | ||||||||||
| async ( | ||||||||||
|
|
@@ -1534,6 +1548,17 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |||||||||
| connectedZoomEasingRef.current = connectedZoomEasing; | ||||||||||
| }, [connectedZoomEasing]); | ||||||||||
|
|
||||||||||
| useEffect(() => { | ||||||||||
| cursorFollowCropRef.current = cursorFollowCrop; | ||||||||||
| resetCursorFollowCropState(cursorFollowCropStateRef.current); | ||||||||||
| }, [cursorFollowCrop?.enabled, cursorFollowCrop?.safeZoneRatio, cursorFollowCrop?.smoothness, cursorFollowCrop?.trackTextCursor]); | ||||||||||
|
|
||||||||||
| useEffect(() => { | ||||||||||
| baseCropRegionRef.current = cropRegion ?? { x: 0, y: 0, width: 1, height: 1 }; | ||||||||||
| effectiveCropRegionRef.current = baseCropRegionRef.current; | ||||||||||
| resetCursorFollowCropState(cursorFollowCropStateRef.current); | ||||||||||
| }, [cropRegion]); | ||||||||||
|
|
||||||||||
| useEffect(() => { | ||||||||||
| cursorTelemetryRef.current = cursorTelemetry; | ||||||||||
| // Push to extension host for query APIs | ||||||||||
|
|
@@ -2194,6 +2219,44 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>( | |||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Cursor-follow crop: per-frame viewport pan within the source video. | ||||||||||
| // When enabled, recompute the effective crop top-left from cursor | ||||||||||
| // telemetry and shift the video sprite to keep the cursor framed. | ||||||||||
| const followSettings = cursorFollowCropRef.current; | ||||||||||
| const baseCrop = baseCropRegionRef.current; | ||||||||||
| const sprite = videoSpriteRef.current; | ||||||||||
| const lockedDims = lockedVideoDimensionsRef.current; | ||||||||||
| if (followSettings?.enabled && sprite && lockedDims && baseCrop) { | ||||||||||
| const effectiveCrop = computeCursorFollowCrop( | ||||||||||
| cursorFollowCropStateRef.current, | ||||||||||
| cursorTelemetryRef.current, | ||||||||||
| currentTimeRef.current, | ||||||||||
| baseCrop, | ||||||||||
| followSettings, | ||||||||||
| ); | ||||||||||
| effectiveCropRegionRef.current = effectiveCrop; | ||||||||||
| const fullVideoDisplayWidth = lockedDims.width * baseScaleRef.current; | ||||||||||
| const fullVideoDisplayHeight = lockedDims.height * baseScaleRef.current; | ||||||||||
| const dx = (effectiveCrop.x - baseCrop.x) * fullVideoDisplayWidth; | ||||||||||
| const dy = (effectiveCrop.y - baseCrop.y) * fullVideoDisplayHeight; | ||||||||||
| sprite.position.set( | ||||||||||
| baseOffsetRef.current.x - dx, | ||||||||||
| baseOffsetRef.current.y - dy, | ||||||||||
| ); | ||||||||||
| cropBoundsRef.current = { | ||||||||||
| startX: effectiveCrop.x * lockedDims.width, | ||||||||||
| endX: effectiveCrop.x * lockedDims.width + effectiveCrop.width * lockedDims.width, | ||||||||||
| startY: effectiveCrop.y * lockedDims.height, | ||||||||||
| endY: effectiveCrop.y * lockedDims.height + effectiveCrop.height * lockedDims.height, | ||||||||||
| }; | ||||||||||
| if (baseMaskRef.current.sourceCrop) { | ||||||||||
| baseMaskRef.current.sourceCrop = { ...effectiveCrop }; | ||||||||||
| } | ||||||||||
|
Comment on lines
+2135
to
+2137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The code only mutates Consider initializing 🐛 Proposed fix- if (baseMaskRef.current.sourceCrop) {
- baseMaskRef.current.sourceCrop = { ...effectiveCrop };
- }
+ baseMaskRef.current.sourceCrop = { ...effectiveCrop };📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| } else if (sprite) { | ||||||||||
| effectiveCropRegionRef.current = baseCrop; | ||||||||||
| sprite.position.set(baseOffsetRef.current.x, baseOffsetRef.current.y); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const { region, strength, blendedScale, transition } = findDominantRegion( | ||||||||||
| zoomRegionsRef.current, | ||||||||||
| currentTimeRef.current, | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cancel should roll back cursor-follow edits too.
These props let the crop modal mutate
cursorFollowCropimmediately, buthandleCancelCropEditor()only restorescropRegion. If the user toggles Track cursor or changes safe zone/smoothness and then cancels, those edits still stick.💡 Minimal fix
🤖 Prompt for AI Agents