Update js/sequence_prompt_builder.js

This commit is contained in:
2026-11-12 11:50:37 +00:00
parent d52db16c74
commit 8a121f66a4
+174 -36
View File
@@ -3,7 +3,7 @@ import { api } from "../../scripts/api.js";
const CLASS = "DumasH3SequencePromptBuilder";
// Check the browser console for this line to confirm the patched file loaded.
console.info("[DUMAS H3] Prompt Builder v6 (Get/Set reference thumbnails) loaded");
console.info("[DUMAS H3] Prompt Builder v7 (compact clip editor) loaded");
const MAX_CLIPS = 16;
const FIXED_TEXT_WIDGETS = [
["shared_directive", 84],
@@ -46,7 +46,7 @@ function ensureTimelineStyles() {
margin: 9px 0 10px;
padding: 10px;
border: 1px solid #404b4b;
border-radius: 8px;
border-radius:4px;
background: #222829;
color: #e5ebea;
font: 11px/1.35 Arial, sans-serif;
@@ -81,7 +81,7 @@ function ensureTimelineStyles() {
.dumas-h3-shot-timeline__track {
position: relative; height: 62px; margin: 7px 6px 0;
background: var(--h3-track-bg); border: 1px solid #3a4548;
border-radius: 6px; overflow: visible;
border-radius:4px; overflow: visible;
}
.dumas-h3-shot-timeline__segment {
position: absolute; display: flex; flex-direction: column;
@@ -126,7 +126,7 @@ function ensureTimelineStyles() {
.dumas-h3-shot-timeline__handle::before {
content: ""; position: absolute; top: 3px; bottom: 3px;
width: 9px; left: 50%; transform: translateX(-50%);
border: 1px solid #879b9b; border-radius: 5px;
border: 1px solid #879b9b; border-radius:4px;
background: #d3dfdc; box-shadow: 0 1px 5px #0009;
}
.dumas-h3-shot-timeline__handle::after {
@@ -160,11 +160,11 @@ function ensureTimelineStyles() {
}
.dumas-h3-shot-timeline__selection {
padding: 4px 7px; border: 1px solid #435053;
border-radius: 5px; background: #1b2223; white-space: nowrap;
border-radius:4px; background: #1b2223; white-space: nowrap;
font: 10px ui-monospace, Consolas, monospace;
}
.dumas-h3-shot-timeline__selected-dot {
flex: 0 0 7px; width: 7px; height: 7px; border-radius: 50%;
flex: 0 0 7px; width: 7px; height: 7px; border-radius:4px;
background: var(--selected-color, #7aaea2);
}
.dumas-h3-shot-timeline__selection strong { color: #e5ebea; }
@@ -174,6 +174,92 @@ function ensureTimelineStyles() {
display: flex; align-items: center; justify-content: center;
height: 100%; color: #95a4a5; font-size: 11px;
}
/* Clip editor: scoped to the DUMAS node DOM widget, not ComfyUI itself. */
.dumas-h3-clip-tabs {
display:flex; flex-wrap:wrap; align-items:center; gap:4px;
border-bottom:1px solid #48504d; padding:0 0 6px;
margin:0 0 9px;
}
.dumas-h3-clip-tab {
padding:5px 11px; min-height:26px;
border:1px solid #525b56; border-radius:3px;
background:#303332; color:#bec8c1;
font:600 11px Arial,sans-serif; text-align:center;
cursor:pointer;
}
.dumas-h3-clip-tab:hover:not(:disabled) {
background:#3c4640; color:#eef5ef; border-color:#718a79;
}
.dumas-h3-clip-tab.is-active {
border-color:#78bd8c; background:#355643;
color:#f3fff5; cursor:default;
}
.dumas-h3-clip-tab.is-disabled {
color:#a9a2a2; border-color:#625253;
background:#312d2e;
}
.dumas-h3-clip-tab.is-active.is-disabled {
color:#f3dddd; border-color:#a47777; background:#513a3c;
}
.dumas-h3-chunk-duration {
display:flex; align-items:center; gap:8px;
margin:0 0 7px;
}
.dumas-h3-chunk-duration__label {
flex:none; color:#c9d6cf; font:600 11px Arial,sans-serif;
white-space:nowrap;
}
.dumas-h3-chunk-duration__select {
flex:1; min-width:0; height:27px; padding:4px 24px 4px 7px;
border:1px solid #52635a; border-radius:3px;
background:#1c1f1d; color:#e7eee9;
font:11px ui-monospace,Consolas,monospace;
}
.dumas-h3-chunk-duration__select:focus-visible {
outline:2px solid #87c89a; outline-offset:1px;
}
.dumas-h3-clip-status {
display:flex; flex-wrap:wrap; align-items:center;
gap:5px 7px; min-height:30px;
padding:1px 0 6px; color:#b6c8bd;
font:11px Arial,sans-serif;
}
.dumas-h3-clip-status__title { font-weight:700; color:#dbe7df; }
.dumas-h3-clip-status__meta { color:#a9b9af; min-width:0; }
.dumas-h3-clip-enable {
margin-left:auto; display:inline-flex; align-items:center; gap:8px;
flex:none; min-height:27px; padding:4px 9px;
border:1px solid #5ca976; border-radius:3px;
color:#d9f3df; background:#23402d;
font:700 11px Arial,sans-serif; cursor:pointer;
user-select:none;
}
.dumas-h3-clip-enable.is-off {
border-color:#9b6868; color:#f1d0d0; background:#4b3435;
}
.dumas-h3-clip-enable:focus-within {
outline:2px solid #cce9d6; outline-offset:1px;
}
.dumas-h3-clip-enable__input {
appearance:none; -webkit-appearance:none;
position:relative; flex:none; width:30px; height:16px; margin:0;
border:1px solid #659472; border-radius:4px;
background:#152b1f; cursor:pointer; box-sizing:border-box;
}
.dumas-h3-clip-enable__input::before {
content:""; position:absolute; left:2px; top:2px;
width:10px; height:10px; border-radius:2px;
background:#b9c3bf; transition:transform .12s ease;
}
.dumas-h3-clip-enable__input:checked { background:#2c9b4f; border-color:#8add9a; }
.dumas-h3-clip-enable__input:checked::before {
transform:translateX(14px); background:#fff;
}
.dumas-h3-clip-enable__input:focus-visible { outline:2px solid #e8f7e9; outline-offset:2px; }
@media (max-width:510px) {
.dumas-h3-chunk-duration { flex-wrap:wrap; }
.dumas-h3-chunk-duration__select { flex-basis:100%; }
}
`;
document.head.append(style);
}
@@ -562,11 +648,11 @@ function configure(node) {
if (!binding.url || binding.failed) return;
const bubble = el("div");
bubble.className = "dumas-h3-reference-hover-preview";
bubble.style.cssText = "position:fixed;z-index:2147483645;width:210px;padding:6px;border:1px solid #9a77c9;border-radius:10px;background:#20212a;box-shadow:0 12px 30px #000d;pointer-events:none;box-sizing:border-box";
bubble.style.cssText = "position:fixed;z-index:2147483645;width:210px;padding:6px;border:1px solid #9a77c9;border-radius:4px;background:#20212a;box-shadow:0 12px 30px #000d;pointer-events:none;box-sizing:border-box";
const image = el("img");
image.src = binding.url;
image.alt = `Reference image ${binding.slot}`;
image.style.cssText = "display:block;width:100%;height:198px;object-fit:contain;background:#111318;border-radius:6px";
image.style.cssText = "display:block;width:100%;height:198px;object-fit:contain;background:#111318;border-radius:4px";
bubble.append(image);
document.body.append(bubble);
const bounds = element.getBoundingClientRect();
@@ -621,7 +707,7 @@ function configure(node) {
const referenceThumbnail = (slot, size = 52) => {
const holder = el("span");
holder.className = "dumas-h3-reference-thumbnail";
holder.style.cssText = `display:inline-grid;box-sizing:border-box;place-items:center;position:relative;flex:none;width:${size}px;height:${size}px;overflow:hidden;background:#201b2b;border:1px solid #7952a8;border-radius:6px;vertical-align:middle`;
holder.style.cssText = `display:inline-grid;box-sizing:border-box;place-items:center;position:relative;flex:none;width:${size}px;height:${size}px;overflow:hidden;background:#201b2b;border:1px solid #7952a8;border-radius:4px;vertical-align:middle`;
const fallback = el("span", "R");
fallback.style.cssText = "display:grid;place-items:center;width:100%;height:100%;font:700 14px ui-monospace,Consolas,monospace;color:#d9c2ff";
const image = el("img");
@@ -760,8 +846,13 @@ function configure(node) {
// across the existing chunk duration.
const markerPattern = /(?:^|\n)\s*(?:\[\s*)?Shot\s+(\d+)(?:\s*\])?(?:\s+(?:At\s+)?((?:\d+(?::\d+){1,2}(?:\.\d+)?|\d+(?:\.\d+)?)))?\s*(?:[,\-:]\s*|\s+)/gim;
const markers = [...text.matchAll(markerPattern)];
if (!markers.length) return false;
const duration = Math.max(0.1, Number(clip.duration) || 0.1);
if (!markers.length) {
// A script with no [Shot N] markers is a single-shot script. This
// lets users remove their last extra shot by deleting its block.
clip.slots = [{ start: 0, end: duration, text: text.trim() }];
return true;
}
const hasTimestamps = markers.some((marker) => marker[2]);
const slots = markers.map((marker, index) => {
const rawStart = marker[2] ? parseTime(marker[2]) : NaN;
@@ -782,6 +873,7 @@ function configure(node) {
if (index > 0) slot.start = slots[index - 1].end;
if (slot.end <= slot.start) slot.end = Math.min(duration, slot.start + 0.1);
});
slots[0].start = 0;
slots[slots.length - 1].end = duration;
clip.slots = slots;
return true;
@@ -840,12 +932,21 @@ function configure(node) {
state.clips = state.clips.slice(0, count); active = Math.min(active, count - 1);
node.__dumasCloseAutocomplete?.();
panel.replaceChildren();
const tabs = el("div"); tabs.style.cssText = "display:flex;flex-wrap:wrap;gap:4px;margin-bottom:8px;border-bottom:1px solid #444;padding-bottom:6px";
const tabs = el("div");
tabs.className = "dumas-h3-clip-tabs";
tabs.setAttribute("role", "tablist");
tabs.setAttribute("aria-label", "Clips");
state.clips.forEach((clip, index) => {
const enabled = clip.enabled !== false;
const button = el("button", `${enabled ? "" : "× "}Clip ${index + 1}`); button.type = "button"; button.disabled = index === active;
button.style.cssText = `padding:3px 10px;border:1px solid ${index === active ? (enabled ? "#8bc99b" : "#c98b8b") : "#555"};border-radius:3px;background:${index === active ? (enabled ? "#4b6f55" : "#6f4b4b") : "#333"};color:${index === active ? "#fff" : (enabled ? "#bbb" : "#888")};cursor:pointer`;
button.onclick = () => { active = index; render(); }; tabs.append(button);
const button = el("button", `${enabled ? "" : "× "}Clip ${index + 1}`);
button.type = "button";
button.className = `dumas-h3-clip-tab${index === active ? " is-active" : ""}${enabled ? "" : " is-disabled"}`;
button.setAttribute("role", "tab");
button.setAttribute("aria-selected", String(index === active));
button.title = enabled ? `Edit Clip ${index + 1}` : `Clip ${index + 1} is disabled`;
button.disabled = index === active;
button.onclick = () => { active = index; render(); };
tabs.append(button);
});
panel.append(tabs);
const clip = state.clips[active];
@@ -855,31 +956,49 @@ function configure(node) {
if (clip.slots.length) clip.slots[clip.slots.length - 1].end = duration;
promptText = promptFor(clip);
const durationControl = el("div");
durationControl.style.cssText = "display:flex;align-items:center;gap:8px;margin:0 0 8px;color:#b7d6bf";
durationControl.className = "dumas-h3-chunk-duration";
const durationLabel = el("span", "Chunk duration / frame choice");
durationLabel.style.cssText = "font-weight:bold;white-space:nowrap";
durationLabel.className = "dumas-h3-chunk-duration__label";
const durationSelect = document.createElement("select");
durationSelect.style.cssText = "flex:1;min-width:0;box-sizing:border-box;padding:4px 6px;color:#e8e8e8;background:#171717;border:1px solid #596b60;border-radius:4px;font:11px monospace";
durationSelect.className = "dumas-h3-chunk-duration__select";
durationSelect.setAttribute("aria-label", "Shared chunk duration and H3 frame choice");
DURATION_OPTIONS.forEach((option) => {
const item = document.createElement("option");
item.value = String(option.seconds);
item.textContent = `${option.actual} Real Frames - ${option.latent} Latent Frames - ${option.labelSeconds.toFixed(2)}s`;
item.textContent = `${option.actual} real · ${option.latent} latent · ${option.labelSeconds.toFixed(2)}s`;
item.selected = option === selectedDuration;
durationSelect.append(item);
});
durationSelect.title = "Choose a native H3 frame length; actual frames are encoded from the latent-frame choice.";
durationSelect.title = "Choose a native H3 frame length. This duration is shared by every clip.";
durationSelect.onchange = () => {
secondsWidget.value = Number(durationSelect.value);
secondsWidget.callback?.(secondsWidget.value);
};
durationControl.append(durationLabel, durationSelect);
panel.append(durationControl);
const durationRow = el("div"); durationRow.style.cssText = "display:flex;align-items:center;gap:8px;margin:4px 0 6px;color:#b7d6bf";
const enabledLabel = el("label"); enabledLabel.style.cssText = "display:inline-flex;align-items:center;gap:4px;margin-left:auto;color:#c7d8cb;font-weight:normal;cursor:pointer";
const enabledToggle = document.createElement("input"); enabledToggle.type = "checkbox"; enabledToggle.checked = clip.enabled !== false; enabledToggle.title = "Include this chunk in the output sockets";
enabledToggle.onchange = () => { clip.enabled = enabledToggle.checked; persistState(); render(); };
enabledLabel.append(enabledToggle, el("span", "Enabled"));
durationRow.append(el("strong", `Clip ${active + 1}`), el("span", `· ${selectedDuration.actual} actual frames · ${selectedDuration.latent} latent frames · ${selectedDuration.labelSeconds.toFixed(2)}s shared chunk duration`), enabledLabel); panel.append(durationRow);
const durationRow = el("div");
durationRow.className = "dumas-h3-clip-status";
const clipName = el("strong", `Clip ${active + 1}`);
clipName.className = "dumas-h3-clip-status__title";
const clipMeta = el("span", `· ${selectedDuration.labelSeconds.toFixed(2)}s · shared across clips`);
clipMeta.className = "dumas-h3-clip-status__meta";
const enabledLabel = el("label");
enabledLabel.className = `dumas-h3-clip-enable${clip.enabled === false ? " is-off" : ""}`;
enabledLabel.title = "Include this clip in the output sequence";
const enabledToggle = document.createElement("input");
enabledToggle.type = "checkbox";
enabledToggle.className = "dumas-h3-clip-enable__input";
enabledToggle.checked = clip.enabled !== false;
enabledToggle.setAttribute("aria-label", `Enable Clip ${active + 1}`);
const enabledText = el("span", enabledToggle.checked ? "Enabled" : "Disabled");
enabledToggle.onchange = () => {
clip.enabled = enabledToggle.checked;
persistState();
render();
};
enabledLabel.append(enabledToggle, enabledText);
durationRow.append(clipName, clipMeta, enabledLabel);
panel.append(durationRow);
if (clip.enabled === false) {
const disabledNote = el("div", "This chunk is disabled and will not be sent to the output sockets.");
disabledNote.style.cssText = "padding:5px 7px;margin:0 0 6px;background:#3a2525;border:1px solid #704848;border-radius:4px;color:#e2b4b4;font:11px monospace";
@@ -1111,7 +1230,7 @@ function configure(node) {
panel.append(timelinePanel);
const referenceLabel = el("div", "REFERENCE IMAGE SLOTS"); referenceLabel.style.cssText = "color:#8fa898;font-size:10px;letter-spacing:.08em;margin:7px 0 3px"; panel.append(referenceLabel);
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:7px;overflow:hidden;margin:3px 0 8px;padding:5px;background:#202020;border:1px solid #3f4742;border-radius:5px;align-items:center;flex-wrap:wrap;min-height:70px;box-sizing:border-box";
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:7px;overflow:hidden;margin:3px 0 8px;padding:5px;background:#202020;border:1px solid #3f4742;border-radius:4px;align-items:center;flex-wrap:wrap;min-height:70px;box-sizing:border-box";
const connectedReferenceSlots = Array.from({ length: 9 }, (_, offset) => offset + 1)
.filter((index) => node.inputs?.some((input) => input.name === `reference_image_${index}` && input.link != null));
const insertReferenceToken = (slot) => {
@@ -1129,7 +1248,7 @@ function configure(node) {
connectedReferenceSlots.forEach((slot) => {
const button = el("button"); button.type = "button";
button.title = `Insert Reference Image ${slot} as @R${slot}`;
button.style.cssText = "display:inline-flex;align-items:center;gap:9px;height:62px;min-width:180px;padding:3px 12px 3px 4px;border:1px solid #946bbe;border-radius:8px;background:#2a2138;color:#e5d4ff;font:12px ui-monospace,Consolas,monospace;cursor:pointer;white-space:nowrap;max-width:270px;overflow:hidden;text-overflow:ellipsis";
button.style.cssText = "display:inline-flex;align-items:center;gap:9px;height:62px;min-width:180px;padding:3px 12px 3px 4px;border:1px solid #946bbe;border-radius:4px;background:#2a2138;color:#e5d4ff;font:12px ui-monospace,Consolas,monospace;cursor:pointer;white-space:nowrap;max-width:270px;overflow:hidden;text-overflow:ellipsis";
const labels = el("span"); labels.style.cssText = "display:flex;flex-direction:column;align-items:flex-start;gap:3px;min-width:0";
const refName = el("strong", `@R${slot}`); refName.style.cssText = "color:#f0e5ff;font-size:12px";
const refDescription = el("span", `Reference Image ${slot}`); refDescription.style.cssText = "color:#baa8d6;font-size:11px";
@@ -1215,7 +1334,7 @@ function configure(node) {
menu.id = `dumas-h3-autocomplete-${node.id ?? "editor"}-${active}`;
menu.setAttribute("role", "listbox");
menu.setAttribute("aria-label", "Insert reference image or new shot");
menu.style.cssText = "position:fixed;z-index:2147483646;min-width:220px;width:max-content;max-width:min(310px,calc(100vw - 16px));max-height:min(360px,calc(100vh - 16px));overflow-y:auto;box-sizing:border-box;padding:5px;background:#252b30;border:1px solid #58646c;border-radius:8px;box-shadow:0 12px 30px #000c;color:#e7edf0;pointer-events:auto";
menu.style.cssText = "position:fixed;z-index:2147483646;min-width:220px;width:max-content;max-width:min(310px,calc(100vw - 16px));max-height:min(360px,calc(100vh - 16px));overflow-y:auto;box-sizing:border-box;padding:5px;background:#252b30;border:1px solid #58646c;border-radius:4px;box-shadow:0 12px 30px #000c;color:#e7edf0;pointer-events:auto";
const addOption = (content, title, action) => {
const option = el("button");
option.type = "button";
@@ -1223,7 +1342,7 @@ function configure(node) {
option.id = `${menu.id}-option-${autocompleteOptions.length}`;
option.setAttribute("role", "option");
option.setAttribute("aria-selected", "false");
option.style.cssText = "display:flex;align-items:center;gap:9px;width:100%;padding:7px 8px;border:0;border-radius:5px;background:transparent;color:#e7edf0;text-align:left;font:12px monospace;cursor:pointer";
option.style.cssText = "display:flex;align-items:center;gap:9px;width:100%;padding:7px 8px;border:0;border-radius:4px;background:transparent;color:#e7edf0;text-align:left;font:12px monospace;cursor:pointer";
// Keep focus in the textarea: Enter/arrow selection must work.
option.onpointerdown = (event) => { event.preventDefault(); event.stopPropagation(); };
option.onmouseenter = () => selectAutocompleteOption(autocompleteOptions.findIndex((entry) => entry.option === option));
@@ -1252,7 +1371,7 @@ function configure(node) {
});
});
addOption([
(() => { const icon = el("span", "S"); icon.style.cssText = "display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:#397a91;color:#dff7ff;font-weight:bold;flex:none"; return icon; })(),
(() => { const icon = el("span", "S"); icon.style.cssText = "display:grid;place-items:center;width:24px;height:24px;border-radius:4px;background:#397a91;color:#dff7ff;font-weight:bold;flex:none"; return icon; })(),
el("span", `[Shot ${clip.slots.length + 1}]`),
(() => { const hint = el("span", "New shot"); hint.style.cssText = "margin-left:auto;color:#a5b7bf;font-size:10px"; return hint; })(),
], "Create the next timed shot", () => {
@@ -1362,9 +1481,29 @@ function configure(node) {
closeAutocomplete();
rememberPromptSelection();
clip.prompt = prompt.value;
const priorShotCount = segments.length;
syncPrompt(clip, clip.prompt);
persistState();
if (clip.slots.length === segments.length) updateTimeline();
if (clip.slots.length !== priorShotCount) {
// A deleted [Shot N] line must remove the timeline segment,
// and any remaining marker numbers/times must stay in sync.
let nextIndex = 0;
clip.prompt = clip.prompt.replace(
/(\[Shot\s+)\d+(\]\s+At\s+)[^,\n]+(?=,)/gi,
(match, prefix, middle) => {
const slot = clip.slots[nextIndex];
if (!slot) return match;
nextIndex += 1;
return `${prefix}${nextIndex}${middle}${formatTime(slot.start)}`;
},
);
prompt.value = clip.prompt;
syncPrompt(clip, clip.prompt);
persistState();
render();
} else {
persistState();
updateTimeline();
}
};
prompt.onchange = () => { commitPrompt(clip, prompt.value); };
prompt.onpointerdown = (event) => event.stopPropagation();
@@ -1433,10 +1572,9 @@ function configure(node) {
const check = el("div", `${clip.slots.length} shot${clip.slots.length === 1 ? "" : "s"} · ${duration.toFixed(1)}s chunk · @ references preserved`); check.style.cssText = "padding:6px 8px;background:#171717;border:1px solid #444;border-radius:4px;color:#9bd0a8;font:11px monospace"; panel.append(check);
const encoderLabel = el("div", "SENT TO ENCODER AS"); encoderLabel.style.cssText = "color:#8fa898;font-size:10px;letter-spacing:.08em;margin:7px 0 3px"; panel.append(encoderLabel);
encoder = el("div", clip.slots.map((slot, index) => `Shot ${index + 1} ${formatTime(slot.start)}`).join(" ")); encoder.style.cssText = "padding:6px 8px;background:#171717;border:1px solid #444;border-radius:4px;color:#7cc4d5;font:11px monospace;white-space:nowrap;overflow:hidden;text-overflow:ellipsis"; panel.append(encoder);
const actions = el("div"); actions.style.cssText = "display:flex;gap:5px;margin-top:5px";
const add = el("button", "@ Add shot"); add.type = "button"; add.onclick = () => { clip.prompt = prompt.value; syncPrompt(clip, clip.prompt); addSlot(clip); rebuildPromptAfterStructureChange(clip); setState(); render(); }; actions.append(add);
if (clip.slots.length > 1) { const remove = el("button", "Remove last shot"); remove.type = "button"; remove.onclick = () => { clip.prompt = prompt.value; syncPrompt(clip, clip.prompt); clip.slots.pop(); clip.slots.at(-1).end = clip.duration; rebuildPromptAfterStructureChange(clip); setState(); render(); }; actions.append(remove); }
panel.append(actions);
// Adding a shot is available in the working @ autocomplete menu.
// Deleting a complete [Shot N] block from the script removes that shot.
// No duplicate add/remove actions at the bottom of the node.
// The editor now contains chips, the prompt check and encoder summary;
// the old slot-count estimate left a large blank tail in the node.
// Measure the actual DOM panel instead of guessing from slot count.