From d23e8e91958dbf44899df4de4a60a9a3c7166e6b Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Thu, 30 Jul 2026 09:28:55 +0800 Subject: [PATCH] fix: prettier format --- .../timeline/hooks/usePlayheadDrag.ts | 74 ++++++++++--------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/apps/web/src/pages/editing-planner/components/timeline/hooks/usePlayheadDrag.ts b/apps/web/src/pages/editing-planner/components/timeline/hooks/usePlayheadDrag.ts index fa189d090..cb3a0c60d 100644 --- a/apps/web/src/pages/editing-planner/components/timeline/hooks/usePlayheadDrag.ts +++ b/apps/web/src/pages/editing-planner/components/timeline/hooks/usePlayheadDrag.ts @@ -1,71 +1,75 @@ -import { useState, useCallback, useEffect, useRef } from "react" +import { useState, useCallback, useEffect, useRef } from "react"; interface UsePlayheadDragOptions { /** 当前播放时间(秒) */ - currentTime: number + currentTime: number; /** 缩放:每秒像素数 */ - pps: number + pps: number; /** 总时长(秒) */ - totalDuration: number + totalDuration: number; /** 播放头跳转回调 */ - onSeek?: (time: number) => void + onSeek?: (time: number) => void; } /** * 播放头拖拽 Hook * 封装播放头的 mousedown/mousemove/mouseup 拖拽逻辑 */ -export const usePlayheadDrag = ({ pps, totalDuration, onSeek }: UsePlayheadDragOptions) => { - const [playheadDragging, setPlayheadDragging] = useState(false) - const trackRef = useRef(null) +export const usePlayheadDrag = ({ + pps, + totalDuration, + onSeek, +}: UsePlayheadDragOptions) => { + const [playheadDragging, setPlayheadDragging] = useState(false); + const trackRef = useRef(null); /* ── 播放头拖拽全局 mousemove/mouseup ── */ useEffect(() => { - if (!playheadDragging) return + if (!playheadDragging) return; const handleMouseMove = (e: MouseEvent) => { - const trackEl = trackRef.current - if (!trackEl) return - const rect = trackEl.getBoundingClientRect() - const x = e.clientX - rect.left + trackEl.scrollLeft - const time = Math.max(0, Math.min(x / pps, totalDuration)) - onSeek?.(Math.round(time * 10) / 10) - } + const trackEl = trackRef.current; + if (!trackEl) return; + const rect = trackEl.getBoundingClientRect(); + const x = e.clientX - rect.left + trackEl.scrollLeft; + const time = Math.max(0, Math.min(x / pps, totalDuration)); + onSeek?.(Math.round(time * 10) / 10); + }; const handleMouseUp = () => { - setPlayheadDragging(false) - } + setPlayheadDragging(false); + }; - document.addEventListener("mousemove", handleMouseMove) - document.addEventListener("mouseup", handleMouseUp) + document.addEventListener("mousemove", handleMouseMove); + document.addEventListener("mouseup", handleMouseUp); return () => { - document.removeEventListener("mousemove", handleMouseMove) - document.removeEventListener("mouseup", handleMouseUp) - } - }, [playheadDragging, pps, totalDuration, onSeek]) + document.removeEventListener("mousemove", handleMouseMove); + document.removeEventListener("mouseup", handleMouseUp); + }; + }, [playheadDragging, pps, totalDuration, onSeek]); /* ── 播放头拖拽开始 ── */ const handlePlayheadMouseDown = useCallback((e: React.MouseEvent) => { - e.preventDefault() - e.stopPropagation() - setPlayheadDragging(true) - }, []) + e.preventDefault(); + e.stopPropagation(); + setPlayheadDragging(true); + }, []); /* ── 标尺点击跳转播放头 ── */ const handleRulerClick = useCallback( (e: React.MouseEvent) => { - const rect = e.currentTarget.getBoundingClientRect() - const x = e.clientX - rect.left - const time = Math.max(0, Math.min(x / pps, totalDuration)) - onSeek?.(Math.round(time * 10) / 10) + const rect = e.currentTarget.getBoundingClientRect(); + const x = e.clientX - rect.left; + const time = Math.max(0, Math.min(x / pps, totalDuration)); + onSeek?.(Math.round(time * 10) / 10); }, [pps, totalDuration, onSeek], - ) + ); return { trackRef, playheadDragging, handlePlayheadMouseDown, handleRulerClick, - } -} + }; +}; \ No newline at end of file