diff --git a/js/sequence_prompt_builder.js b/js/sequence_prompt_builder.js index 94c4078..d3eb2be 100644 --- a/js/sequence_prompt_builder.js +++ b/js/sequence_prompt_builder.js @@ -224,18 +224,28 @@ function configure(node) { }; const parsePromptSlots = (clip, value) => { const text = String(value || ""); - const markerPattern = /\[Shot\s+\d+\]\s+At\s+((?:\d+(?::\d+){1,2}(?:\.\d+)?|\d+(?:\.\d+)?))\s*,\s*/gi; + // Accept the formats users commonly paste from notes and scripts: + // [Shot 1] At 00:00.000, ... + // Shot 1: ... + // SHOT 2 - ... + // Timestamps are optional; when absent, shots are divided evenly + // 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); + const hasTimestamps = markers.some((marker) => marker[2]); const slots = markers.map((marker, index) => { - const rawStart = parseTime(marker[1]); - const start = Number.isFinite(rawStart) + const rawStart = marker[2] ? parseTime(marker[2]) : NaN; + const start = hasTimestamps && Number.isFinite(rawStart) ? Math.min(Math.max(0, rawStart), Math.max(0, duration - 0.1)) - : 0; + : (duration * index / markers.length); const next = markers[index + 1]; - const rawEnd = next ? parseTime(next[1]) : duration; - const end = Math.min(duration, Math.max(start + 0.1, Number.isFinite(rawEnd) ? rawEnd : duration)); + const rawEnd = next?.[2] ? parseTime(next[2]) : duration; + const fallbackEnd = hasTimestamps && Number.isFinite(rawEnd) + ? rawEnd + : (duration * (index + 1) / markers.length); + const end = Math.min(duration, Math.max(start + 0.1, fallbackEnd)); const from = marker.index + marker[0].length; const to = next ? next.index : text.length; return { start, end, text: text.slice(from, to).trim() }; @@ -453,12 +463,10 @@ function configure(node) { shotChips.append(chip); }); panel.append(shotChips); - const referenceLabel = el("div", "REFMOD SLOTS"); referenceLabel.style.cssText = "color:#8fa898;font-size:10px;letter-spacing:.08em;margin:7px 0 3px"; panel.append(referenceLabel); + 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:38px;box-sizing:border-box"; - const connectedRefModSlots = Array.from({ length: 9 }, (_, offset) => offset + 1) - .filter((index) => node.inputs?.some((input) => input.name === `ref_mod_${index}` && input.link != null)); - const refModDescriptors = connectedRefModSlots.flatMap((index) => refModDescriptorsForNode(node, `ref_mod_${index}`)); - const refModsConnected = connectedRefModSlots.length > 0; + 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) => { if (!prompt) return; const start = Math.min(promptSelectionStart, prompt.value.length); @@ -471,13 +479,12 @@ function configure(node) { promptText = prompt.value; clip.prompt = prompt.value; syncPrompt(clip, clip.prompt); persistState(); }; - refModDescriptors.forEach((descriptor, offset) => { - const slot = offset + 1; + connectedReferenceSlots.forEach((slot) => { const button = el("button"); button.type = "button"; - button.title = `Insert ${descriptor.name} as @R${slot}`; + button.title = `Insert Reference Image ${slot} as @R${slot}`; button.style.cssText = "display:inline-flex;align-items:center;gap:7px;height:31px;padding:2px 11px 2px 3px;border:2px solid #b78cff;border-radius:18px;background:#2a2138;color:#d9c2ff;font:14px monospace;cursor:pointer;white-space:nowrap;max-width:260px;overflow:hidden;text-overflow:ellipsis"; const icon = el("span", "R"); icon.style.cssText = "display:grid;place-items:center;width:25px;height:25px;border-radius:50%;background:#7952a8;color:#fff;font-weight:bold;font-size:12px;flex:none"; - button.append(icon, el("span", `@R${slot} ${descriptor.name}`)); + button.append(icon, el("span", `@R${slot} Reference Image ${slot}`)); const rememberPromptSelection = () => { if (!prompt) return; promptSelectionStart = prompt.selectionStart ?? prompt.value.length; @@ -488,8 +495,8 @@ function configure(node) { button.onclick = (event) => { event.preventDefault(); event.stopPropagation(); insertReferenceToken(slot); }; referenceRow.append(button); }); - if (!refModsConnected) { - const empty = el("span", "Connect RefMod sockets to populate this row."); empty.style.cssText = "color:#77817a;font:11px Arial;padding:3px 2px"; referenceRow.append(empty); + if (!connectedReferenceSlots.length) { + const empty = el("span", "Connect reference image sockets to populate this row."); empty.style.cssText = "color:#77817a;font:11px Arial;padding:3px 2px"; referenceRow.append(empty); } panel.append(referenceRow); const promptLabel = el("div", "PROMPT SCRIPT"); promptLabel.style.cssText = "color:#8fa898;font-size:10px;letter-spacing:.08em;margin:4px 0 3px"; panel.append(promptLabel); @@ -518,13 +525,12 @@ function configure(node) { option.onclick = (event) => { event.preventDefault(); event.stopPropagation(); action(); }; option.append(...content); menu.append(option); }; - refModDescriptors.forEach((descriptor, offset) => { - const slot = offset + 1; + connectedReferenceSlots.forEach((slot) => { addOption([ (() => { const icon = el("span", "R"); icon.style.cssText = "display:grid;place-items:center;width:24px;height:24px;border-radius:50%;background:#7952a8;color:#fff;font-weight:bold"; return icon; })(), - el("span", `@R${slot} ${descriptor.name}`), - (() => { const hint = el("span", ""); hint.style.cssText = "margin-left:auto;color:#c9a9f3;font-size:10px"; return hint; })(), - ], `Insert ${descriptor.name} as @R${slot}`, () => { + el("span", `@R${slot} Reference Image ${slot}`), + (() => { const hint = el("span", ""); hint.style.cssText = "margin-left:auto;color:#9bd0a8;font-size:10px"; return hint; })(), + ], `Insert Reference Image ${slot} as @R${slot}`, () => { const start = autocompleteRange?.start ?? prompt.value.length; const end = autocompleteRange?.end ?? start; const token = `@R${slot} `; diff --git a/tests/test_dumas_h3_nodes.py b/tests/test_dumas_h3_nodes.py index 32f384d..3e3367d 100644 --- a/tests/test_dumas_h3_nodes.py +++ b/tests/test_dumas_h3_nodes.py @@ -183,6 +183,23 @@ class H3NodeTests(unittest.TestCase): finally: sys.modules.pop(reference_module.__name__, None) + def test_two_shot_script_is_preserved_as_two_slots(self): + reference_module = types.ModuleType("upstream.v3.reference_images_v39") + reference_module.ReferenceImagesV39Bundle = FakeReferenceBundle + sys.modules[reference_module.__name__] = reference_module + try: + result = PROMPT.DumasH3SequencePromptBuilder().build( + 1, 4, "", '{"clips":[{"slots":[' + '{"start":0,"end":2,"text":"Shot 1: the subject walks."},' + '{"start":2,"end":4,"text":"Shot 2: the subject turns."}]}]}', + "", "", + ) + self.assertEqual(result[1], 1) + self.assertIn("Shot 1: the subject walks.", result[0]) + self.assertIn("Shot 2: the subject turns.", result[0]) + finally: + sys.modules.pop(reference_module.__name__, None) + def test_per_clip_upscale_uses_connected_sigmas(self): original = UPSCALE._native_node original_helper = UPSCALE._continuum_helper