Add draggable shot boundary handles
This commit is contained in:
@@ -88,17 +88,47 @@ function configure(node) {
|
||||
clip.duration = duration;
|
||||
const durationRow = el("div"); durationRow.style.cssText = "display:flex;align-items:center;gap:8px;margin:4px 0;color:#b7d6bf";
|
||||
durationRow.append(el("strong", `Clip ${active + 1}`), el("span", `· ${duration.toFixed(1)}s shared chunk duration`)); panel.append(durationRow);
|
||||
const timeline = el("div"); timeline.style.cssText = "display:flex;height:38px;gap:2px;margin:8px 0 3px;background:#15251a;border-radius:3px;overflow:hidden";
|
||||
const timeline = el("div"); timeline.style.cssText = "position:relative;height:44px;margin:8px 0 3px;background:#15251a;border-radius:3px;overflow:hidden;border:1px solid #41634a";
|
||||
const palette = ["#4b9b67", "#4d7fb1", "#a87945", "#8c5aa8", "#a44f5d", "#3f8e8a"];
|
||||
clip.slots.forEach((slot, index) => { const segment = el("button", `Shot ${index + 1}\n${(slot.text || "unscripted").slice(0, 18)}`); segment.type = "button"; segment.title = `${slot.start.toFixed(1)}s–${slot.end.toFixed(1)}s`; segment.style.cssText = `flex:${Math.max(0.1, slot.end - slot.start)};border:0;color:white;background:${palette[index % palette.length]};white-space:pre-wrap;font-size:10px;overflow:hidden`; segment.onclick = () => { prompt.focus(); }; timeline.append(segment); });
|
||||
panel.append(timeline);
|
||||
const sliderHint = el("div", "Drag shot boundaries to retime the prompt. Grey areas are unscripted."); sliderHint.style.cssText = "color:#b7d6bf;margin-bottom:4px"; panel.append(sliderHint);
|
||||
clip.slots.slice(0, -1).forEach((slot, index) => {
|
||||
const next = clip.slots[index + 1]; const boundary = input("range", slot.end, (value) => { const point = Math.min(Number(clip.duration) - 0.1, Math.max(0.1, Number(value))); slot.end = point; next.start = point; setState(); render(); });
|
||||
boundary.min = 0.1; boundary.max = Math.max(0.1, Number(clip.duration) - 0.1); boundary.step = 0.1;
|
||||
const row = el("label", `Shot ${index + 1} / ${index + 2} · ${Number(slot.end).toFixed(1)}s`); row.style.cssText = "display:block;color:#d9f0dc"; row.append(boundary); panel.append(row);
|
||||
let prompt = null;
|
||||
const segments = [];
|
||||
const handles = [];
|
||||
const updateTimeline = () => {
|
||||
clip.slots.forEach((slot, index) => {
|
||||
const left = Math.max(0, Number(slot.start) / duration * 100);
|
||||
const width = Math.max(0.1, (Number(slot.end) - Number(slot.start)) / duration * 100);
|
||||
segments[index].style.left = `${left}%`;
|
||||
segments[index].style.width = `${width}%`;
|
||||
segments[index].title = `${Number(slot.start).toFixed(1)}s–${Number(slot.end).toFixed(1)}s`;
|
||||
});
|
||||
handles.forEach(({ handle, slot }) => { handle.style.left = `${Number(slot.end) / duration * 100}%`; });
|
||||
if (prompt) prompt.value = promptFor(clip);
|
||||
};
|
||||
clip.slots.forEach((slot, index) => {
|
||||
const segment = el("button", `Shot ${index + 1}\n${(slot.text || "unscripted").slice(0, 18)}`); segment.type = "button";
|
||||
segment.style.cssText = `position:absolute;top:0;height:100%;border:0;border-right:2px solid #203827;color:white;background:${palette[index % palette.length]};white-space:pre-wrap;font-size:10px;overflow:hidden;padding:2px`;
|
||||
segment.onclick = () => { prompt.focus(); }; segments.push(segment); timeline.append(segment);
|
||||
});
|
||||
const prompt = el("textarea"); prompt.rows = 9; prompt.value = promptFor(clip); prompt.placeholder = "[Shot 1] At 00:00.000, describe the opening action...\n\nType @ at the start of a new line to add the next shot."; prompt.style.cssText = "width:100%;box-sizing:border-box;color:#111;font:12px monospace;margin-top:6px";
|
||||
clip.slots.slice(0, -1).forEach((slot, index) => {
|
||||
const next = clip.slots[index + 1];
|
||||
const handle = el("div"); handle.title = `Resize boundary between Shot ${index + 1} and Shot ${index + 2}`;
|
||||
handle.style.cssText = "position:absolute;top:0;width:12px;height:100%;transform:translateX(-50%);background:#f1f7f2;border:2px solid #18261c;border-radius:3px;cursor:ew-resize;z-index:5;box-sizing:border-box";
|
||||
const move = (event) => {
|
||||
const rect = timeline.getBoundingClientRect();
|
||||
const point = Math.min(duration - 0.1, Math.max(0.1, ((event.clientX - rect.left) / rect.width) * duration));
|
||||
slot.end = point; next.start = point; updateTimeline();
|
||||
};
|
||||
handle.onpointerdown = (event) => {
|
||||
event.preventDefault(); handle.setPointerCapture?.(event.pointerId);
|
||||
handle.onpointermove = move;
|
||||
handle.onpointerup = () => { handle.onpointermove = null; setState(); render(); };
|
||||
};
|
||||
handles.push({ handle, slot }); timeline.append(handle);
|
||||
});
|
||||
updateTimeline();
|
||||
panel.append(timeline);
|
||||
const sliderHint = el("div", "Drag the white handles on the bar to resize shots. The bar always represents the complete chunk duration."); sliderHint.style.cssText = "color:#b7d6bf;margin-bottom:4px"; panel.append(sliderHint);
|
||||
prompt = el("textarea"); prompt.rows = 9; prompt.value = promptFor(clip); prompt.placeholder = "[Shot 1] At 00:00.000, describe the opening action...\n\nType @ at the start of a new line to add the next shot."; prompt.style.cssText = "width:100%;box-sizing:border-box;color:#111;font:12px monospace;margin-top:6px";
|
||||
prompt.onchange = () => { syncPrompt(clip, prompt.value); setState(); render(); };
|
||||
prompt.onkeydown = (event) => { if (event.key !== "@") return; const cursor = prompt.selectionStart || 0; if (cursor !== 0 && prompt.value[cursor - 1] !== "\n") return; event.preventDefault(); addSlot(clip); setState(); render(); };
|
||||
panel.append(prompt);
|
||||
|
||||
Reference in New Issue
Block a user