Enable free positioning for timeline clips (#9)

* Add comprehensive GEO search foundation

* Enable free positioning for timeline clips

---------

Co-authored-by: haixin.yang <haixin.yang@weimob.com>
This commit is contained in:
Martin Delophyandhaixin.yang authored and GitHub committed 2026-07-16 12:39:18 +08:00
1 parent b261b47008
commit bacf0804b1
17 files changed
+297 -64

No files matched your search

+33 -6
View File
@@ -1,4 +1,4 @@
import { getSegmentStartTime, getVisualSegmentTimeline, reorderTimelineItems } from "./timeline.js";
import { getVisualSegmentTimeline, materializeCaptionTimings, moveTimedCaptionSegment, reorderTimelineItems } from "./timeline.js";
export function createTimelineReorderControls(d) {
const getTimelineReorderIndex = (track, x, y) => {
@@ -21,17 +21,44 @@ export function createTimelineReorderControls(d) {
const next = reorderTimelineItems(source, fromIndex, toIndex);
d.commitVisualSegments(next, "已调整视觉片段顺序", toIndex); d.seekTo(getVisualSegmentTimeline(next)[toIndex]?.start ?? 0); return;
}
if (track === "caption" && d.captionSegments.length >= 2) {
const next = reorderTimelineItems(d.captionSegments, fromIndex, toIndex);
d.commitCaptionSegments(next, "已调整字幕片段顺序", toIndex);
d.seekTo(getSegmentStartTime(next, toIndex, d.captionTargetDuration));
}
};
const startTimelineClipDrag = (event, track, segmentId, index) => {
if (event.button !== 0 || event.target.closest(".image-resize-handle")) return;
if (d.trackLocks[track]) return void d.notify(track === "image" ? "图片轨已锁定,无法拖动片段" : "字幕轨已锁定,无法拖动片段");
if (track === "image") { d.setSelectedTrack("image"); d.setSelectedVisualSegmentId(segmentId); }
else { d.setSelectedTrack("caption"); d.setSelectedSegmentId(segmentId); }
const materializedCaptions = track === "caption" ? materializeCaptionTimings(d.captionSegments, d.captionTargetDuration) : [];
const caption = materializedCaptions[index];
if (caption) {
event.preventDefault(); event.stopPropagation();
const duration = Math.max(0.2, caption.end - caption.start);
const initial = { track, mode: "move", segmentId, fromIndex: index, startX: event.clientX, startY: event.clientY,
originalStart: caption.start, originalEnd: caption.end, previewStart: caption.start, previewEnd: caption.end,
previewSegments: materializedCaptions, dragging: false };
d.timelineClipDragRef.current = initial; d.setTimelineClipDrag(initial);
const move = (e) => {
const state = d.timelineClipDragRef.current; if (!state || state.segmentId !== segmentId) return;
if (!state.dragging && Math.hypot(e.clientX - state.startX, e.clientY - state.startY) < 4) return;
const trackElement = document.querySelector('[data-timeline-reorder-track="caption"]');
const width = Math.max(1, trackElement?.getBoundingClientRect().width || 1);
const delta = ((e.clientX - state.startX) / width) * d.timelineDuration;
const previewStart = Math.max(0, Math.min(d.timelineDuration - duration, state.originalStart + delta));
const previewEnd = previewStart + duration;
const previewSegments = moveTimedCaptionSegment(materializedCaptions, segmentId, previewStart, previewEnd);
const next = { ...state, previewStart, previewEnd, previewSegments, dragging: true };
d.timelineClipDragRef.current = next; d.setTimelineClipDrag(next);
};
const up = () => {
removeEventListener("pointermove", move); removeEventListener("pointerup", up);
const state = d.timelineClipDragRef.current; d.timelineClipDragRef.current = null; d.setTimelineClipDrag(null);
if (!state?.dragging) return;
d.suppressTimelineClipClickRef.current = segmentId;
setTimeout(() => { if (d.suppressTimelineClipClickRef.current === segmentId) d.suppressTimelineClipClickRef.current = ""; }, 120);
d.commitCaptionSegments(state.previewSegments, "已移动字幕片段", index); d.seekTo(state.previewStart);
};
addEventListener("pointermove", move); addEventListener("pointerup", up, { once: true });
return;
}
const count = track === "image" ? d.renderedVisualSegments.length : d.captionSegments.length;
if (count < 2) return;
event.preventDefault(); event.stopPropagation();