Style reference chips with thumbnails
This commit is contained in:
@@ -31,9 +31,10 @@ widget, making saved workflows portable even when the optional browser panel
|
|||||||
is unavailable.
|
is unavailable.
|
||||||
|
|
||||||
The node can also accept up to nine optional reference-image inputs. Each
|
The node can also accept up to nine optional reference-image inputs. Each
|
||||||
input has a fixed identity (`Reference Image 1` is always `@R1`, through
|
input has a fixed identity (`Reference Image 1` is always `@image1`, through
|
||||||
`@R9`); when an image is connected, the editor shows a button for inserting
|
`@image9`; the backend also accepts the equivalent `@R1`–`@R9` tags). When an
|
||||||
that tag at the current caret position. The fourth output is the same typed
|
image is connected, the editor shows a CSGlide-style pill with a thumbnail and
|
||||||
|
inserts that tag at the current caret position. The fourth output is the same typed
|
||||||
`H3_CONTINUUM_REFERENCE_IMAGES_V39` bundle used by the V3.9 sampler. It is
|
`H3_CONTINUUM_REFERENCE_IMAGES_V39` bundle used by the V3.9 sampler. It is
|
||||||
automatically set to `Per chunk`, and only references explicitly mentioned in
|
automatically set to `Per chunk`, and only references explicitly mentioned in
|
||||||
each chunk's prompt are assigned to that chunk. References that are connected
|
each chunk's prompt are assigned to that chunk. References that are connected
|
||||||
|
|||||||
+3
-2
@@ -182,12 +182,13 @@ class DumasH3SequencePromptBuilder:
|
|||||||
)
|
)
|
||||||
selectors = []
|
selectors = []
|
||||||
for reference_index in range(1, 10):
|
for reference_index in range(1, 10):
|
||||||
tag = f"R{reference_index}"
|
|
||||||
chunks = []
|
chunks = []
|
||||||
for chunk_index, clip in enumerate(sequence["clips"], start=1):
|
for chunk_index, clip in enumerate(sequence["clips"], start=1):
|
||||||
text = "\n".join(str(slot.get("text", "")) for slot in clip["slots"])
|
text = "\n".join(str(slot.get("text", "")) for slot in clip["slots"])
|
||||||
if kwargs.get(f"reference_image_{reference_index}") is not None and re.search(
|
if kwargs.get(f"reference_image_{reference_index}") is not None and re.search(
|
||||||
rf"@{tag}(?![A-Za-z0-9_])", text, re.IGNORECASE
|
rf"@(R{reference_index}|image{reference_index})(?![A-Za-z0-9_])",
|
||||||
|
text,
|
||||||
|
re.IGNORECASE,
|
||||||
):
|
):
|
||||||
chunks.append(chunk_index)
|
chunks.append(chunk_index)
|
||||||
selectors.append(",".join(map(str, chunks)) or "off")
|
selectors.append(",".join(map(str, chunks)) or "off")
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ def test_builder_routes_connected_references_only_to_mentioning_chunks():
|
|||||||
value = {
|
value = {
|
||||||
"clips": [
|
"clips": [
|
||||||
{"slots": [{"start": 0, "end": 4, "text": "@R1 walks toward @R2."}]},
|
{"slots": [{"start": 0, "end": 4, "text": "@R1 walks toward @R2."}]},
|
||||||
{"slots": [{"start": 0, "end": 4, "text": "The camera follows @r2."}]},
|
{"slots": [{"start": 0, "end": 4, "text": "The camera follows @image2."}]},
|
||||||
{"slots": [{"start": 0, "end": 4, "text": "A wide shot with no reference."}]},
|
{"slots": [{"start": 0, "end": 4, "text": "A wide shot with no reference."}]},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,21 +241,39 @@ function configure(node) {
|
|||||||
shotChips.append(chip);
|
shotChips.append(chip);
|
||||||
});
|
});
|
||||||
panel.append(shotChips);
|
panel.append(shotChips);
|
||||||
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:4px;overflow:hidden;margin:4px 0 7px;align-items:center";
|
const referenceRow = el("div"); referenceRow.style.cssText = "display:flex;gap:8px;overflow:hidden;margin:7px 0 8px;align-items:center;flex-wrap:wrap";
|
||||||
const connectedReferences = Array.from({ length: 9 }, (_, offset) => offset + 1)
|
const connectedReferences = Array.from({ length: 9 }, (_, offset) => offset + 1)
|
||||||
.filter((index) => node.inputs?.some((input) => input.name === `reference_image_${index}` && input.link != null));
|
.filter((index) => node.inputs?.some((input) => input.name === `reference_image_${index}` && input.link != null));
|
||||||
if (connectedReferences.length) {
|
if (connectedReferences.length) {
|
||||||
const referenceLabel = el("span", "Refs:"); referenceLabel.style.cssText = "color:#8fa898;font:10px monospace;margin-right:2px"; referenceRow.append(referenceLabel);
|
|
||||||
connectedReferences.forEach((index) => {
|
connectedReferences.forEach((index) => {
|
||||||
const button = el("button", `@R${index}`); button.type = "button";
|
const button = el("button"); button.type = "button";
|
||||||
button.title = `Insert reference image ${index} as @R${index}`;
|
button.title = `Insert reference image ${index} as @image${index}`;
|
||||||
button.style.cssText = "padding:3px 8px;border:1px solid #4f9bb0;border-radius:4px;background:#172d33;color:#8bd5e7;font:11px monospace;cursor:pointer";
|
button.style.cssText = "display:inline-flex;align-items:center;gap:7px;height:31px;padding:2px 11px 2px 3px;border:2px solid #49c9f5;border-radius:18px;background:#202b31;color:#70d8ff;font:16px monospace;cursor:pointer;white-space:nowrap";
|
||||||
|
const thumbnail = document.createElement("img");
|
||||||
|
thumbnail.alt = ""; thumbnail.draggable = false;
|
||||||
|
thumbnail.style.cssText = "width:25px;height:25px;object-fit:cover;border-radius:50%;background:#68727a;display:block";
|
||||||
|
const linkId = node.inputs?.find((input) => input.name === `reference_image_${index}`)?.link;
|
||||||
|
const link = linkId == null ? null : (app.graph?.links?.get?.(linkId) ?? app.graph?.links?.[linkId]);
|
||||||
|
const source = link?.origin_id == null ? null : app.graph?.getNodeById?.(link.origin_id);
|
||||||
|
const imageWidget = source?.widgets?.find((widget) => ["image", "filename", "file"].includes(widget.name));
|
||||||
|
const imageValue = imageWidget?.value;
|
||||||
|
if (imageValue && typeof imageValue === "object" && imageValue.filename) {
|
||||||
|
const params = new URLSearchParams({ filename: imageValue.filename, type: imageValue.type || "input", subfolder: imageValue.subfolder || "" });
|
||||||
|
thumbnail.src = `/view?${params.toString()}`;
|
||||||
|
} else if (typeof imageValue === "string" && imageValue) {
|
||||||
|
const params = new URLSearchParams({ filename: imageValue, type: "input", subfolder: "" });
|
||||||
|
thumbnail.src = `/view?${params.toString()}`;
|
||||||
|
} else {
|
||||||
|
thumbnail.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='25' height='25' viewBox='0 0 25 25'%3E%3Crect width='25' height='25' fill='%2368727a'/%3E%3Cpath d='M4 19l5-6 3 3 3-4 6 7' fill='none' stroke='%23dce8ed' stroke-width='2'/%3E%3Ccircle cx='17' cy='8' r='2' fill='%23dce8ed'/%3E%3C/svg%3E";
|
||||||
|
}
|
||||||
|
thumbnail.onerror = () => { thumbnail.style.opacity = "0.35"; };
|
||||||
|
button.append(thumbnail, el("span", `@image${index}`));
|
||||||
button.onclick = (event) => {
|
button.onclick = (event) => {
|
||||||
event.preventDefault(); event.stopPropagation();
|
event.preventDefault(); event.stopPropagation();
|
||||||
if (!prompt) return;
|
if (!prompt) return;
|
||||||
const start = prompt.selectionStart ?? prompt.value.length;
|
const start = prompt.selectionStart ?? prompt.value.length;
|
||||||
const end = prompt.selectionEnd ?? start;
|
const end = prompt.selectionEnd ?? start;
|
||||||
const token = `@R${index} `;
|
const token = `@image${index} `;
|
||||||
prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end);
|
prompt.value = prompt.value.slice(0, start) + token + prompt.value.slice(end);
|
||||||
const caret = start + token.length;
|
const caret = start + token.length;
|
||||||
prompt.focus(); prompt.setSelectionRange(caret, caret);
|
prompt.focus(); prompt.setSelectionRange(caret, caret);
|
||||||
|
|||||||
Reference in New Issue
Block a user