Files
ausboss-ComfyUI-AusBoss/js/shared/core_preview.mjs
T
ausboss 0e4749db6b Preview each node's own result, and rework Save Video
Five things surfaced by release testing.

Node search: ComfyUI's search dialog cuts at 64 results and ranks by
[match tier, global popularity, name length], where tier 1 needs the name
to START with what was typed. Popularity is a fixed global table in which
every node from a new pack scores zero, so tier is the only lever. As
"Refine Mask" this node came 121st for "mask" and was never on screen.
Renamed to Mask Refine, which is 15th, and kept "refine mask" as an alias.
The mapping key is untouched, so saved workflows are unaffected. Aliases
alone cannot fix this: the frontend indexes them but drops them from the
tier scoring because they are a list rather than a string, so they decide
whether a node is findable, not where it lands.

Previews: Mask Refine, LaMa Inpaint and Select Frame showed whatever fed
their input, which is nothing when a segmentation node is upstream - Mask
Refine's panel was blank however the mask turned out. Each now returns its
result as a preview and the panel shows that, falling back to the input
before the first run. A node does not need to be an OUTPUT_NODE for this;
returning a ui payload is enough. ComfyUI's own preview for these nodes is
stood down so the picture appears once, in the panel, rather than also
underneath the node. That also fixes LaMa finishing a single image with an
empty panel: frame previews were only attached for batches over one frame,
on the assumption that one image would preview through the output path,
which a non-output node does not have.

Mask Refine opens on expand and blur with the other five behind MORE.
Hidden widgets keep their values and their saved positions. AUTO sets both
from the mask's size, scaled off the 8/4 hand-tuned for the watermark
workflow at 576px, because a feather is a fraction of the picture rather
than a fixed pixel count.

Save Video gains nvenc h264/h265, webm av1, ProRes mov, lossless ffv1 mkv,
gif and webp, plus pingpong and save_metadata. Every format is encoded and
read back in the tests rather than trusted from its table row. fps steps in
whole frames but stays FLOAT: an INT would refuse Load Video's fps link and
round 29.97 to 30, drifting picture off audio. mov files now carry the
embedded workflow, which they silently did not. The reload button is gone -
it only re-fetched what was already on screen.

Not done: Select Frame's preview updates on a run, not as the number
changes. Seeking to a frame needs the source fps, which the browser never
learns, so live scrubbing needs a server route - the surface Frame Chooser
was just demoted for.
2026-08-18 16:31:44 -05:00

71 lines
2.6 KiB
JavaScript

// Stand ComfyUI's own in-node previews down on nodes that draw their own.
//
// A node that returns a ui payload — or streams progress previews — gets a
// preview from the frontend automatically: an image one as the canvas widget
// named $$canvas-image-preview, a video one as the DOM widget named
// video-preview. Every AusBoss node here already presents that same result
// inside its own panel, so left alone the node shows it twice, once in the
// panel and once again underneath.
//
// The widgets are hidden rather than removed. The frontend re-adds a preview
// whenever it finds none and the node has images, so removing one just brings
// it back on the next frame; a hidden widget is still found by name and left
// alone. Its value is untouched either way, and neither serializes.
export const CORE_VIDEO_PREVIEW_WIDGET = "video-preview";
export const CORE_IMAGE_PREVIEW_WIDGET = "$$canvas-image-preview";
export function hideCanvasWidget(widget, element = null) {
if (!widget || widget.__ausbossHidden) return;
widget.__ausbossHidden = true;
widget.hidden = true;
widget._hidden = true;
widget.computeSize = () => [0, -4];
widget.computeLayoutSize = () => ({ minWidth: 0, minHeight: 0 });
widget.draw = () => {};
widget.mouse = () => false;
if (element) element.style.display = "none";
}
// Wrap one of the node's own add*Widget methods so the named widget is hidden
// the moment the frontend creates it, and sweep any copy already present.
function suppressWidget(node, flag, method, targetName, elementOf) {
if (!node || node[flag]) return;
node[flag] = true;
const prior = node[method];
if (typeof prior === "function") {
node[method] = function (...args) {
const widget = prior.apply(this, args);
if (widget?.name === targetName || args[0] === targetName) {
hideCanvasWidget(widget, elementOf(widget, args));
}
return widget;
};
}
for (const widget of node.widgets || []) {
if (widget?.name === targetName) hideCanvasWidget(widget, elementOf(widget, []));
}
}
export function suppressCoreVideoPreview(node) {
suppressWidget(
node,
"__ausbossCorePreviewSuppressed",
"addDOMWidget",
CORE_VIDEO_PREVIEW_WIDGET,
(widget, args) => args[2] || widget?.element || node.videoContainer,
);
}
export function suppressCoreImagePreview(node) {
// The image preview arrives through addCustomWidget, not addDOMWidget: it
// is painted straight onto the graph canvas and owns no element.
suppressWidget(
node,
"__ausbossCoreImagePreviewSuppressed",
"addCustomWidget",
CORE_IMAGE_PREVIEW_WIDGET,
() => null,
);
}