diff --git a/src/components/CaptureAnnotationWorkbench.tsx b/src/components/CaptureAnnotationWorkbench.tsx index 9572972f..0542c45d 100644 --- a/src/components/CaptureAnnotationWorkbench.tsx +++ b/src/components/CaptureAnnotationWorkbench.tsx @@ -1,4 +1,5 @@ import type { ReactNode } from "react"; +import { createPortal } from "react-dom"; import { ReviewActionList } from "./ReviewActionList"; import { ReviewSliceNavigator } from "./ReviewSliceNavigator"; import type { AnnotationTimelineFailure } from "../lib/annotation-source-validation"; @@ -24,7 +25,7 @@ import { readReviewCaptionPlacement, writeReviewCaptionPlacement } from "../lib/ import { reviewCaptionAtTime } from "../lib/review-captions.js"; import { sliceEditActionsWithDrafts, workbenchDraftsFingerprint } from "../lib/annotation-autosave.js"; import { DiscardReasonFields, type DiscardReasonChoice } from "./DiscardReasonFields"; -import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; +import { Fragment, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react"; import { cancelActionPartition, lastActionFrame, moveActionBoundary } from "../lib/action-frame-boundary.js"; import { actionJudgment, completeActionPartitions } from "../lib/continuous-actions.js"; import { adjacentAnnotation } from "../lib/annotation-list-navigation.js"; @@ -194,6 +195,7 @@ type Props = ReviewViewingProps & { * offset + currentTime over duration — and seeks through the host's slice * navigation instead of only the current clip. */ + mediaTimelineHost?: HTMLDivElement | null; totalProgress?: { offset: number; duration: number; onSeekTotal?: (time: number) => void }; frameBoundaries?: number[]; frameTimelineStatus?: "loading" | "ready" | "error"; @@ -394,6 +396,7 @@ export function CaptureAnnotationWorkbench({ adaptiveLayout = false, focusedLayout = false, viewportSuspended = false, + mediaTimelineHost, totalProgress, frameBoundaries = [], frameTimelineStatus = "ready", @@ -552,6 +555,17 @@ export function CaptureAnnotationWorkbench({ // which is exactly the E′ direct path — fully functional on its own. const [moviVideoReady, setMoviVideoReady] = useState(() => moviElementReady()); const [opinionMarkerOpen, setOpinionMarkerOpen] = useState(null); + const [opinionTrackWidth, setOpinionTrackWidth] = useState(0); + const opinionTrackObserver = useRef(null); + const observeOpinionTrack = useCallback((node: HTMLDivElement | null) => { + opinionTrackObserver.current?.disconnect(); + opinionTrackObserver.current = null; + if (!node) return; + const measure = () => setOpinionTrackWidth(node.clientWidth); + measure(); + opinionTrackObserver.current = new ResizeObserver(measure); + opinionTrackObserver.current.observe(node); + }, []); useEffect(() => { if (browserReadyMedia || moviRuntimeMode() !== "movi") return; if (moviElementReady()) { @@ -3179,39 +3193,47 @@ export function CaptureAnnotationWorkbench({ reviewTimestampOpinions && reviewTimestampOpinions.length > 0 && (
e.stopPropagation()} > {(() => { - // §4.3:点位标记不涂红父切片;近邻聚合,重叠可展开选择。 + // Reserve space for a count badge even when the timeline narrows. const span = Math.max(end - start, 0.001); + const badgeSpacing = Math.max(20, String(reviewTimestampOpinions.length).length * 6 + 12); + const clusterDistance = opinionTrackWidth > 0 ? Math.max(0.8, (badgeSpacing / opinionTrackWidth) * 100) : 0.8; const sorted = [...reviewTimestampOpinions].sort((a, b) => a.atSeconds - b.atSeconds); const clusters: { key: string; opinions: typeof sorted; left: number }[] = []; for (const opinion of sorted) { const left = Math.min(100, Math.max(0, ((opinion.atSeconds + offset - start) / span) * 100)); const last = clusters[clusters.length - 1]; - if (last && Math.abs(last.left - left) < 0.8) last.opinions.push(opinion); + if (last && left - last.left < clusterDistance) last.opinions.push(opinion); else clusters.push({ key: opinion.id, opinions: [opinion], left }); } return clusters.map((cluster) => ( -
- + +
+ +
{cluster.opinions.length > 1 && opinionMarkerOpen === cluster.key && ( -
+
{cluster.opinions.map((o) => (
+ )); })()}
); + const playbackTimeline = ( + <> + {mediaOnly && isReviewViewing && !!reviewTimestampOpinions?.length && ( +
event.stopPropagation()}> + {renderTimestampOpinionMarkers( + totalProgress ? 0 : clipStart, + totalProgress?.duration ?? clipEnd, + totalProgress?.offset ?? 0, + )} +
+ )} + ) => + totalProgress.onSeekTotal?.(Number(event.currentTarget.value)), + } + : {})} + style={ + { + "--played": totalProgress + ? timelinePosition(totalProgress.offset + currentTime, 0, totalProgress.duration) + : timelinePosition(currentTime, clipStart, clipEnd), + } as CSSProperties + } + className={cn("annotation-time-range w-full accent-orange-500", !mediaOnly && "mb-2")} + /> + + ); + return (
+ {mediaTimelineHost && createPortal(playbackTimeline, mediaTimelineHost)}