"use client"; import { useRef } from "react"; import type { Span } from "./benchMedia"; // --------------------------------------------------------------------------- // THE CUT ON THE WAVEFORM (lane/clip-fixes). A clip's cut (`cutStart`–`cutEnd`) // is what the video plays, inside the extent; gaps lie inside it. It used to be // drawn only on the rail, so a cut narrower than the extent -- a locked clause // cut kept from an earlier pass, under an extent since widened -- was a wall a // gap drag stopped at with nothing on the waveform to say why (operator, 6 Nov: // "I can't add gaps beyond like 9:21"). Here: the seconds of the extent outside // the cut shaded, each cut edge a line in the cut's colour, and a tab on it // that drags the edge (written on release, by the caller, with an Undo). The // line itself never takes a pointer: the waveform's own drag goes on under it. // --------------------------------------------------------------------------- export function CutEdges({ vis, cut, extent, busy, fmt, onDrag, }: { /** What the waveform shows. */ vis: Span; /** The cut, as saved or as being dragged. */ cut: Span; /** The extent the cut lies in (the selection as drafted). */ extent: Span; busy: boolean; fmt: (t: number) => string; /** An edge dragged to `t`; `done` on release. Absent: drawn only (the bench's clip mode), no tabs. */ onDrag?: (side: "start" | "end", t: number, done: boolean) => void; }) { const span = Math.max(1e-6, vis.to - vis.from); const pct = (t: number) => `${((Math.min(vis.to, Math.max(vis.from, t)) - vis.from) / span) * 100}%`; const width = (a: number, b: number) => `calc(${pct(b)} - ${pct(a)})`; const drag = useRef<{ id: number; side: "start" | "end" } | null>(null); const tAt = (el: HTMLElement, clientX: number) => { const box = (el.closest("[data-wave-box]") as HTMLElement | null) ?? el; const r = box.getBoundingClientRect(); return vis.from + Math.min(1, Math.max(0, (clientX - r.left) / Math.max(1, r.width))) * span; }; const outside: Array<{ side: "start" | "end"; from: number; to: number }> = []; if (cut.from > extent.from + 0.01) outside.push({ side: "start", from: extent.from, to: cut.from }); if (cut.to < extent.to - 0.01) outside.push({ side: "end", from: cut.to, to: extent.to }); const inView = (s: { from: number; to: number }) => s.to > vis.from && s.from < vis.to; return ( <> {outside.filter(inView).map((o) => (
))} {(["start", "end"] as const).map((side) => { const t = side === "start" ? cut.from : cut.to; if (t < vis.from || t > vis.to) return null; return (