Preserve raw script while resizing shots
This commit is contained in:
@@ -41,6 +41,7 @@ function configure(node) {
|
|||||||
display.options ||= {}; display.options.serialize = false;
|
display.options ||= {}; display.options.serialize = false;
|
||||||
let active = 0;
|
let active = 0;
|
||||||
let state = readState(stateWidget, Number(countWidget.value) || 2, Number(secondsWidget.value) || 4);
|
let state = readState(stateWidget, Number(countWidget.value) || 2, Number(secondsWidget.value) || 4);
|
||||||
|
let promptText = null;
|
||||||
const setState = () => {
|
const setState = () => {
|
||||||
stateWidget.value = JSON.stringify(state);
|
stateWidget.value = JSON.stringify(state);
|
||||||
stateWidget.callback?.(stateWidget.value);
|
stateWidget.callback?.(stateWidget.value);
|
||||||
@@ -74,10 +75,22 @@ function configure(node) {
|
|||||||
const promptFor = (clip) => clip.slots.map((slot, index) =>
|
const promptFor = (clip) => clip.slots.map((slot, index) =>
|
||||||
`[Shot ${index + 1}] At ${formatTime(slot.start)}, ${slot.text || ""}`).join("\n\n");
|
`[Shot ${index + 1}] At ${formatTime(slot.start)}, ${slot.text || ""}`).join("\n\n");
|
||||||
const syncPrompt = (clip, value) => {
|
const syncPrompt = (clip, value) => {
|
||||||
const blocks = String(value || "").split(/\n\s*\n(?=\[Shot\s+\d+\])/i);
|
const text = String(value || "");
|
||||||
blocks.forEach((block, index) => {
|
const marks = [...text.matchAll(/\[Shot\s+(\d+)\][^\n]*(?:\n|$)/gi)];
|
||||||
if (!clip.slots[index]) return;
|
if (!marks.length) { if (clip.slots[0]) clip.slots[0].text = text.trim(); return; }
|
||||||
clip.slots[index].text = block.replace(/^\[Shot\s+\d+\][^\n]*\n?/i, "").trim();
|
marks.forEach((mark, index) => {
|
||||||
|
const slotIndex = Number(mark[1]) - 1;
|
||||||
|
if (!clip.slots[slotIndex]) return;
|
||||||
|
const from = mark.index + mark[0].length;
|
||||||
|
const to = index + 1 < marks.length ? marks[index + 1].index : text.length;
|
||||||
|
clip.slots[slotIndex].text = text.slice(from, to).trim();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const retimePrompt = (text, clip) => {
|
||||||
|
let index = 0;
|
||||||
|
return String(text || "").replace(/(\[Shot\s+\d+\]\s+At\s+)[^,\n]+(,?)/gi, (whole, prefix, suffix) => {
|
||||||
|
const start = clip.slots[index++]?.start ?? 0;
|
||||||
|
return `${prefix}${formatTime(start)}${suffix}`;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const render = () => {
|
const render = () => {
|
||||||
@@ -94,6 +107,7 @@ function configure(node) {
|
|||||||
const duration = chunkDuration;
|
const duration = chunkDuration;
|
||||||
clip.duration = duration;
|
clip.duration = duration;
|
||||||
if (clip.slots.length) clip.slots[clip.slots.length - 1].end = duration;
|
if (clip.slots.length) clip.slots[clip.slots.length - 1].end = duration;
|
||||||
|
promptText = promptFor(clip);
|
||||||
const durationRow = el("div"); durationRow.style.cssText = "display:flex;align-items:center;gap:8px;margin:4px 0;color:#b7d6bf";
|
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);
|
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 = "position:relative;height:44px;margin:8px 0 3px;background:#15251a;border-radius:3px;overflow:hidden;border:1px solid #41634a";
|
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";
|
||||||
@@ -130,12 +144,13 @@ function configure(node) {
|
|||||||
// Textarea edits are intentionally committed on change, but a
|
// Textarea edits are intentionally committed on change, but a
|
||||||
// drag can happen while it still has focus. Capture them before
|
// drag can happen while it still has focus. Capture them before
|
||||||
// the timeline redraws the prompt from state.
|
// the timeline redraws the prompt from state.
|
||||||
if (prompt) syncPrompt(clip, prompt.value);
|
if (prompt) { promptText = prompt.value; syncPrompt(clip, promptText); }
|
||||||
handle.setPointerCapture?.(event.pointerId);
|
handle.setPointerCapture?.(event.pointerId);
|
||||||
handle.onpointermove = move;
|
handle.onpointermove = move;
|
||||||
handle.onpointerup = () => {
|
handle.onpointerup = () => {
|
||||||
handle.onpointermove = null;
|
handle.onpointermove = null;
|
||||||
if (prompt) syncPrompt(clip, prompt.value);
|
promptText = retimePrompt(promptText, clip);
|
||||||
|
if (prompt) { prompt.value = promptText; syncPrompt(clip, promptText); }
|
||||||
setState(); render();
|
setState(); render();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -144,7 +159,8 @@ function configure(node) {
|
|||||||
updateTimeline();
|
updateTimeline();
|
||||||
panel.append(timeline);
|
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);
|
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 = el("textarea"); prompt.rows = 9; prompt.value = promptText; 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.oninput = () => { promptText = prompt.value; };
|
||||||
prompt.onchange = () => { syncPrompt(clip, prompt.value); setState(); render(); };
|
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(); };
|
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);
|
panel.append(prompt);
|
||||||
|
|||||||
Reference in New Issue
Block a user